package com.mortals.xhx.module.check.service.impl;
import com.mortals.framework.service.IUser;
import com.mortals.xhx.module.perform.service.PerformComplainRecordService;
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.CheckComplainRecordDao;
import com.mortals.xhx.module.check.model.CheckComplainRecordEntity;
import com.mortals.xhx.module.check.service.CheckComplainRecordService;
import lombok.extern.slf4j.Slf4j;

import java.util.Date;

/**
* CheckComplainRecordService
* 评价绩效投诉核查信息 service实现
*
* @author zxfei
* @date 2023-05-18
*/
@Service("checkComplainRecordService")
@Slf4j
public class CheckComplainRecordServiceImpl extends AbstractCRUDServiceImpl<CheckComplainRecordDao, CheckComplainRecordEntity, Long> implements CheckComplainRecordService {

    @Autowired
    private PerformComplainRecordService performComplainRecordService;

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