package com.mortals.xhx.module.check.service.impl;
import com.mortals.framework.service.IUser;
import com.mortals.xhx.module.perform.service.PerformAttendRecordService;
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.CheckAttendRecordDao;
import com.mortals.xhx.module.check.model.CheckAttendRecordEntity;
import com.mortals.xhx.module.check.service.CheckAttendRecordService;
import lombok.extern.slf4j.Slf4j;

import java.util.Date;

/**
* CheckAttendRecordService
* 考勤绩效记录核查信息 service实现
*
* @author zxfei
* @date 2023-05-18
*/
@Service("checkAttendRecordService")
@Slf4j
public class CheckAttendRecordServiceImpl extends AbstractCRUDServiceImpl<CheckAttendRecordDao, CheckAttendRecordEntity, Long> implements CheckAttendRecordService {

    @Autowired
    private PerformAttendRecordService performAttendRecordService;

    @Override
    public void examine(CheckAttendRecordEntity 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 {
            performAttendRecordService.updateProcessStatus(entity.getRecordId(),2);
        }catch (Exception e){
            log.error(e.getMessage());
        }
    }
}