package com.mortals.xhx.module.perform.service.impl;
import com.mortals.xhx.common.utils.BeanUtil;
import com.mortals.xhx.module.check.model.CheckReviewRecordEntity;
import com.mortals.xhx.module.check.service.CheckReviewRecordService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
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.perform.dao.PerformReviewRecordDao;
import com.mortals.xhx.module.perform.model.PerformReviewRecordEntity;
import com.mortals.xhx.module.perform.service.PerformReviewRecordService;
import lombok.extern.slf4j.Slf4j;

import java.util.Date;

/**
* PerformReviewRecordService
* 评价差评绩效记录信息 service实现
*
* @author zxfei
* @date 2023-05-18
*/
@Service("performReviewRecordService")
@Slf4j
public class PerformReviewRecordServiceImpl extends AbstractCRUDServiceImpl<PerformReviewRecordDao, PerformReviewRecordEntity, Long> implements PerformReviewRecordService {

    @Autowired
    private CheckReviewRecordService checkReviewRecordService;

    @Override
    protected void saveAfter(PerformReviewRecordEntity entity, Context context) throws AppException {
        CheckReviewRecordEntity checkReviewRecordEntity = new CheckReviewRecordEntity();
        BeanUtils.copyProperties(entity,checkReviewRecordEntity, BeanUtil.getNullPropertyNames(entity));
        checkReviewRecordEntity.setRecordId(entity.getId());
        if(entity.getSubMethod()==1){
            checkReviewRecordEntity.setCheckStatus(2);     //自动扣分相设置为已处理
        }else {
            checkReviewRecordEntity.setCheckStatus(1);      //非自动扣分相设置为未处理
        }
        checkReviewRecordService.save(checkReviewRecordEntity,context);
    }

    @Override
    public void updateProcessStatus(Long id, Integer status) throws AppException {
        if(id==null){
            throw new AppException("评价差评绩效记录Id不能为空");
        }
        PerformReviewRecordEntity entity = this.get(id);
        if(entity==null){
            throw new AppException("无效的评价差评绩效记录Id");
        }
        if(status==null){
            status=1; //处理状态(1.未核查,2.已核查)
        }
        PerformReviewRecordEntity update = new PerformReviewRecordEntity();
        update.setId(id);
        update.setProcessStatus(status);
        update.setUpdateTime(new Date());
        dao.update(update);
    }
}