package com.mortals.xhx.module.check.service.impl;
import com.mortals.framework.service.IUser;
import com.mortals.xhx.module.perform.service.PerformGoworkRecordService;
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.check.dao.CheckGoworkRecordDao;
import com.mortals.xhx.module.check.model.CheckGoworkRecordEntity;
import com.mortals.xhx.module.check.service.CheckGoworkRecordService;
import lombok.extern.slf4j.Slf4j;

import java.util.Date;

/**
* CheckGoworkRecordService
* 办件绩效核查信息 service实现
*
* @author zxfei
* @date 2023-05-18
*/
@Service("checkGoworkRecordService")
@Slf4j
public class CheckGoworkRecordServiceImpl extends AbstractCRUDServiceImpl<CheckGoworkRecordDao, CheckGoworkRecordEntity, Long> implements CheckGoworkRecordService {

    @Autowired
    private PerformGoworkRecordService performGoworkRecordService;

    @Override
    public void examine(CheckGoworkRecordEntity entity, Context context) throws AppException {
        if(entity.getId()==null){
            throw new AppException("核查记录ID不能为空");
        }
        if (context != null && context.getUser()!=null) {
            IUser user = context.getUser();
            entity.setUpdateUserId(user.getId());
            entity.setCheckPerson(user.getRealName());
        }
        entity.setCheckTime(new Date());
        entity.setUpdateTime(entity.getCheckTime());
        entity.setCheckStatus(2); //处理状态(1.未处理,2.已处理)
        dao.update(entity);
        try {
            performGoworkRecordService.updateProcessStatus(entity.getRecordId(),2);
        }catch (Exception e){
            log.error(e.getMessage());
        }
    }
}