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.common.code.EnabledEnum;
import com.mortals.xhx.module.perform.dao.PerformStaffConfDetailDao;
import com.mortals.xhx.module.perform.model.PerformStaffConfDetailEntity;
import com.mortals.xhx.module.perform.service.PerformStaffConfDetailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
* PerformStaffConfDetailService
* 人员考核内容详细信息 service实现
*
* @author zxfei
* @date 2023-05-16
*/
@Service("performStaffConfDetailService")
@Slf4j
public class PerformStaffConfDetailServiceImpl extends AbstractCRUDServiceImpl<PerformStaffConfDetailDao, PerformStaffConfDetailEntity, Long> implements PerformStaffConfDetailService {

    @Override
    public int enable(Long id, Context context) throws AppException {
        if(id == null){
            throw new AppException("考核内容详细Id不能为空");
        }
        PerformStaffConfDetailEntity temp = this.get(id);
        if(temp == null){
            throw new AppException("考核内容详细Id不正确");
        }
        PerformStaffConfDetailEntity entity = new PerformStaffConfDetailEntity();
        entity.setId(id);
        if(temp.getEnable() == EnabledEnum.停用.getValue()){
            entity.setEnable(EnabledEnum.启用.getValue());
        }else {
            entity.setEnable(EnabledEnum.停用.getValue());
        }
        if(context!=null && context.getUser()!=null){
            entity.setUpdateTime(new Date());
            entity.setUpdateUserId(context.getUser().getId());
        }
        return this.dao.update(entity);
    }
}