package com.mortals.xhx.module.perform.service.impl;

import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;
import com.mortals.xhx.module.perform.dao.PerformErrorMessageDao;
import com.mortals.xhx.module.perform.model.PerformErrorMessageEntity;
import com.mortals.xhx.module.perform.service.PerformErrorMessageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
* PerformErrorMessageService
* 绩效异常信息 service实现
*
* @author zxfei
* @date 2024-04-28
*/
@Service("performErrorMessageService")
@Slf4j
public class PerformErrorMessageServiceImpl extends AbstractCRUDServiceImpl<PerformErrorMessageDao, PerformErrorMessageEntity, Long> implements PerformErrorMessageService {

    public PerformErrorMessageEntity get(Long key, Context context) throws AppException {
        PerformErrorMessageEntity entity = this.dao.get(key);
        if(context!=null && context.getUser()!=null && entity!=null){
            Long staffId = context.getUser().getCustomerId();
            if(staffId!=null && staffId.longValue() == entity.getStaffId().longValue()){
                PerformErrorMessageEntity update = new PerformErrorMessageEntity();
                update.setId(entity.getId());
                update.setUpdateTime(new Date());
                update.setReadStatus(1);
                this.dao.update(update);
            }
        }
        return entity;
    }
}