package com.engine.organization.service.impl; import com.engine.common.util.ServiceUtil; import com.engine.core.impl.Service; import com.engine.hrm.entity.RuleCodeType; import com.engine.organization.entity.codesetting.bo.CodeSettingBO; import com.engine.organization.entity.codesetting.param.CodeSaveParam; import com.engine.organization.entity.codesetting.po.CodeRuleDetailPO; import com.engine.organization.entity.codesetting.po.CodeRulePO; import com.engine.organization.mapper.codesetting.CodeRuleDetailMapper; import com.engine.organization.mapper.codesetting.CodeRuleMapper; import com.engine.organization.service.CodeSettingService; import com.engine.organization.util.OrganizationAssert; import com.engine.organization.util.db.MapperProxyFactory; import com.engine.organization.util.response.ReturnResult; import weaver.hrm.HrmUserVarify; import weaver.hrm.User; import java.util.HashMap; import java.util.List; import java.util.Map; /** * @Author weaver_cl * @Description: TODO * @Date 2022/5/30 * @Version V1.0 **/ public class CodeSettingServiceImpl extends Service implements CodeSettingService { public CodeSettingService getCodeSettingService(User user) { return ServiceUtil.getService(CodeSettingServiceImpl.class,user); } @Override public ReturnResult getHasRight(String serialtype) { boolean hasRight = false; Map retmap = new HashMap<>(); switch (RuleCodeType.getByValue(serialtype)) { case SUBCOMPANY: hasRight = HrmUserVarify.checkUserRight("HrmCodeRuleSubcompany:All", user); break; case DEPARTMENT: hasRight = HrmUserVarify.checkUserRight("HrmCodeRuleDepartment:All", user); break; case JOBTITLES: hasRight = HrmUserVarify.checkUserRight("HrmCodeRuleJobtitles:All", user); break; case USER: hasRight = HrmUserVarify.checkUserRight("HrmCodeRuleUser:All", user); break; } retmap.put("hasRight", hasRight); return ReturnResult.successed(retmap); } @Override public void saveOrUpdateCodeSetting(CodeSaveParam params) { OrganizationAssert.notNull(params,"参数不能为空"); Long codeRuleId = getCodeSettingService(user).getCodeRuleId(params.getSerialType()); CodeRulePO codeRulePO = CodeSettingBO.buildCodeRule(params,(long)user.getUID(),codeRuleId); //1.新增或更新主表 if (codeRulePO != null) { MapperProxyFactory.getProxy(CodeRuleMapper.class).updateCodeRule(codeRulePO); }else { MapperProxyFactory.getProxy(CodeRuleMapper.class).insertCodeRule(codeRulePO); } //2.插入明细表 codeRuleId = getCodeSettingService(user).getCodeRuleId(params.getSerialType()); MapperProxyFactory.getProxy(CodeRuleDetailMapper.class).delete(codeRuleId); List codeRuleDetailPO = CodeSettingBO.bulidCodeDetailList(params.getCodeSaveDetailParams(),(long)user.getUID(),codeRuleId); } @Override public Long getCodeRuleId(String serialType) { return MapperProxyFactory.getProxy(CodeRuleMapper.class).getCodeRuleId(serialType); } }