package com.mortals.xhx.module.perform.service.impl;
import com.mortals.xhx.common.code.EnabledEnum;
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.perform.dao.PerformDeptConfDetailDao;
import com.mortals.xhx.module.perform.model.PerformDeptConfDetailEntity;
import com.mortals.xhx.module.perform.service.PerformDeptConfDetailService;
import lombok.extern.slf4j.Slf4j;

import java.util.Date;

/**
* PerformDeptConfDetailService
* 部门考核内容详细信息 service实现
*
* @author zxfei
* @date 2023-05-16
*/
@Service("performDeptConfDetailService")
@Slf4j
public class PerformDeptConfDetailServiceImpl extends AbstractCRUDServiceImpl<PerformDeptConfDetailDao, PerformDeptConfDetailEntity, Long> implements PerformDeptConfDetailService {

    @Override
    public int enable(Long id, Context context) throws AppException {
        if(id == null){
            throw new AppException("考核内容详细Id不能为空");
        }
        PerformDeptConfDetailEntity temp = this.get(id);
        if(temp == null){
            throw new AppException("考核内容详细Id不正确");
        }
        PerformDeptConfDetailEntity entity = new PerformDeptConfDetailEntity();
        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);
    }
}