package com.mortals.xhx.module.check.service.impl;
import com.mortals.framework.service.IUser;
import com.mortals.xhx.common.code.CheckStatusEnum;
import com.mortals.xhx.module.check.model.CheckWindowPerformEntity;
import org.springframework.stereotype.Service;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.xhx.module.check.dao.CheckWindowWorkmanPerformDao;
import com.mortals.xhx.module.check.model.CheckWindowWorkmanPerformEntity;
import com.mortals.xhx.module.check.service.CheckWindowWorkmanPerformService;
import lombok.extern.slf4j.Slf4j;

import java.util.Date;

/**
* CheckWindowWorkmanPerformService
* 窗口人员考核汇总核查 service实现
*
* @author zxfei
* @date 2024-01-17
*/
@Service("checkWindowWorkmanPerformService")
@Slf4j
public class CheckWindowWorkmanPerformServiceImpl extends AbstractCRUDServiceImpl<CheckWindowWorkmanPerformDao, CheckWindowWorkmanPerformEntity, Long> implements CheckWindowWorkmanPerformService {

    @Override
    public void examine(CheckWindowWorkmanPerformEntity entity, Context context) throws AppException {
        if (entity.getId() == null) {
            throw new AppException("核查记录ID不能为空");
        }
        CheckWindowWorkmanPerformEntity temp = this.get(entity.getId());
        if (temp == null) {
            throw new AppException("核查记录ID不正确");
        }
        if (context != null && context.getUser() != null) {
            IUser user = context.getUser();
            entity.setUpdateUserId(user.getId());
            entity.setManageCheckPerson(user.getRealName());
        }

        entity.setManageCheckTime(new Date());
        entity.setUpdateTime(new Date());
        entity.setCheckStatus(CheckStatusEnum.已处理.getValue()); //处理状态(1.未处理,2.已处理)
        dao.update(entity);
    }
}