package com.engine.salary.wrapper; import com.cloudstore.eccom.result.WeaResultMsg; import com.engine.common.util.ServiceUtil; import com.engine.core.impl.Service; import com.engine.salary.component.SalaryWeaTable; import com.engine.salary.entity.salaryBill.dto.*; import com.engine.salary.entity.salaryBill.param.*; import com.engine.salary.entity.salaryBill.po.SalaryTemplatePO; import com.engine.salary.entity.salaryitem.po.SalaryItemPO; import com.engine.salary.entity.salarysob.po.SalarySobBackItemPO; import com.engine.salary.entity.salarysob.po.SalarySobPO; import com.engine.salary.enums.salarybill.SalaryTemplateReplenishRuleEnum; import com.engine.salary.enums.salarybill.SalaryTemplateVarEnum; import com.engine.salary.enums.salarybill.SalaryTemplateWhetherEnum; import com.engine.salary.exception.SalaryRunTimeException; import com.engine.salary.service.*; import com.engine.salary.service.impl.*; import com.engine.salary.util.SalaryEntityUtil; import com.engine.salary.util.SalaryI18nUtil; import com.engine.salary.util.db.DBType; import com.mzlion.core.json.fastjson.JsonUtil; import com.mzlion.core.utils.BeanUtils; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.math.NumberUtils; import weaver.conn.RecordSet; import weaver.hrm.User; import java.util.*; import java.util.stream.Collectors; /** * @Description: 工资单模板 * @Author: wangxiangzhong * @Date: 2022/3/16 13:56 */ public class SalaryTemplateWrapper extends Service { private SalaryTemplateService getSalaryTemplateService(User user) { return ServiceUtil.getService(SalaryTemplateServiceImpl.class, user); } // @RpcReference // private MailBaseService mailBaseService; private SalarySobService getSalarySobService(User user) { return ServiceUtil.getService(SalarySobServiceImpl.class, user); } private SalarySobBackItemService getSalarySobBackItemService(User user) { return ServiceUtil.getService(SalarySobBackItemServiceImpl.class, user); } private SalaryItemService getSalaryItemService(User user) { return ServiceUtil.getService(SalaryItemServiceImpl.class, user); } private TaxAgentService getTaxAgentService(User user) { return ServiceUtil.getService(TaxAgentServiceImpl.class, user); } /** * 工资单模板列表 * * @param queryParam * @return */ public Map list(SalaryTemplateQueryParam queryParam) { SalaryWeaTable table = new SalaryWeaTable(user, SalaryTemplateListDTO.class); String fields = " t.id" + " , t.name" + " , t.replenish_name as replenishName" + " , s.name as salarySob" + " , t.use_type as useType" + " , t.description"; String from = " from hrsa_salary_template t left join hrsa_salary_sob s on t.salary_sob_id = s.id "; table.setBackfields(fields); table.setSqlform(from); table.setSqlwhere(makeSqlWhere(queryParam)); table.setSqlorderby("t.id DESC"); table.setSqlprimarykey("t.id"); table.setSqlisdistinct("false"); WeaResultMsg result = new WeaResultMsg(false); result.putAll(table.makeDataResult()); result.success(); return result.getResultMap(); } private String makeSqlWhere(SalaryTemplateQueryParam queryParam) { DBType dbType = DBType.get(new RecordSet().getDBType()); String sqlWhere = " t.delete_type = 0 "; String name = queryParam.getName(); if (StringUtils.isNotBlank(name)) { sqlWhere += " AND t.name " + dbType.like(name); } Collection ids = queryParam.getIds(); if (ids != null && ids.size() > 0) { sqlWhere += " AND t.id in (" + ids.stream().map(Object::toString).collect(Collectors.joining(",")) + ") "; } Long salarySobId = queryParam.getSalarySobId(); if (salarySobId != null) { sqlWhere += " AND t.salary_sob_id = " + salarySobId; } long currentEmployeeId = user.getUID(); Boolean needAuth = getTaxAgentService(user).isNeedAuth(currentEmployeeId); if (needAuth) { List salarySobPOS = getSalarySobService(user).listByDisable(NumberUtils.INTEGER_ZERO); Set salarySobIds = SalaryEntityUtil.properties(salarySobPOS, SalarySobPO::getId); if (CollectionUtils.isNotEmpty(salarySobIds)) { sqlWhere += " AND t.salary_sob_id in (" + salarySobIds.stream().map(Object::toString).collect(Collectors.joining(",")) + ") "; } else { sqlWhere += " AND 1=2 "; } } return sqlWhere; } /** * 获取工资单模板基础设置表单 * * @param id * @return */ public SalaryTemplateBaseFormDTO getBaseForm(Long id) { SalaryTemplateBaseSetDTO salaryTemplateBaseSetDTO = new SalaryTemplateBaseSetDTO(); List> replenishRuleSetOptionList = Collections.emptyList(); if (id != null) { SalaryTemplatePO po = getSalaryTemplateService(user).getById(id); if (po == null) { throw new SalaryRunTimeException("工资单模板不存在"); } BeanUtils.copyProperties(po, salaryTemplateBaseSetDTO); salaryTemplateBaseSetDTO.setSendEmail(po.getSendEmailId()); salaryTemplateBaseSetDTO.setEmailStatus(po.getEmailStatus().equals(SalaryTemplateWhetherEnum.TRUE.getValue())); salaryTemplateBaseSetDTO.setMsgStatus(po.getMsgStatus().equals(SalaryTemplateWhetherEnum.TRUE.getValue())); salaryTemplateBaseSetDTO.setSalarySob(po.getSalarySobId()); salaryTemplateBaseSetDTO.setSendEmail(po.getSendEmailId()); // 规则赋值 如果为ALL传“” 如果为byRule传薪资项目ID salaryTemplateBaseSetDTO.setReplenishRule(SalaryTemplateReplenishRuleEnum.ALL.getValue().equals(po.getReplenishRule()) ? "" : po.getReplenishRule()); // 规则设置赋值 // salaryTemplateBaseSetDTO.setReplenishRuleSet(po.getReplenishRule()); // 修改时获取补规则设置下拉列表 replenishRuleSetOptionList = getReplenishRuleSetOptions(po.getSalarySobId()); } // 查询所有启用的薪资账套 List salarySobs = getSalarySobService(user).listByDisable(NumberUtils.INTEGER_ZERO); List> salarySobOptions = salarySobs.stream() .map(salarySobPO -> { Map item = new HashMap<>(); item.put("id", salarySobPO.getId()); item.put("name", salarySobPO.getName()); return item; }) .collect(Collectors.toList()); // 邮箱下拉 // List sendEmailOptions = Lists.newArrayList(); // MailPublicAccountListObj mailPublicAccountListObj = mailBaseService.getMailPublicAccountList(employeeId, tenantKey); // List mailPublicAccountBos = mailPublicAccountListObj.getMailPublicAccountList(); // mailPublicAccountBos.forEach(e->sendEmailOptions.add(new WeaFormOption(String.valueOf(e.getId()), e.getMailAddress()))); // WeaForm salaryTemplateBase = SalaryFormatUtil.getInstance().buildForm(SalaryTemplateBaseSetDTO.class, SalaryTemplateBaseSetDTO.builder().salarySobOptions(salarySobOptions).sendEmailOptions(sendEmailOptions).build()); Map salaryTemplateBase = new HashMap<>(); salaryTemplateBase.put("data", salaryTemplateBaseSetDTO); salaryTemplateBase.put("salarySobOptions", salarySobOptions); // 编辑时禁止修改薪资账套 前端实现 // 分组 前端实现 return SalaryTemplateBaseFormDTO.builder() .id(id) .salaryTemplateBaseSet(salaryTemplateBase) .replenishRuleSetOption(replenishRuleSetOptionList) .build(); } /** * 获取工资单模板显示设置表单 * * @param id * @return */ public SalaryTemplateShowFormDTO getShowForm(Long id) { SalaryTemplateShowSetDTO salaryTemplateShowSetDTO = new SalaryTemplateShowSetDTO(); SalaryTemplatePO po = new SalaryTemplatePO(); if (id != null) { po = getSalaryTemplateService(user).getById(id); if (po == null) { throw new SalaryRunTimeException("工资单模板不存在"); } BeanUtils.copyProperties(po, salaryTemplateShowSetDTO); salaryTemplateShowSetDTO.setTextContentPosition(po.getTextContentPosition().toString()); salaryTemplateShowSetDTO.setSalaryItemNullStatus(po.getSalaryItemNullStatus().equals(SalaryTemplateWhetherEnum.TRUE.getValue())); salaryTemplateShowSetDTO.setSalaryItemZeroStatus(po.getSalaryItemZeroStatus().equals(SalaryTemplateWhetherEnum.TRUE.getValue())); } // 主题及其他设置 // WeaForm salaryTemplateShowSet = SalaryFormatUtil.getInstance().buildForm(SalaryTemplateShowSetDTO.class, new SalaryTemplateShowSetDTO()); // // WeaFormItem textContentItem = salaryTemplateShowSet.getItems().get("textContent"); // Map otherParams = Maps.newHashMap(); // otherParams.put("showCount", true); // otherParams.put("placeholder", SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 85987, "请输入")); // textContentItem.setOtherParams(otherParams); // salaryTemplateShowSet.getItems().put("textContent", textContentItem); // // salaryTemplateShowSet.setData(JsonUtil.parseMap(salaryTemplateShowSetDTO, Object.class)); Map salaryTemplateShowSet = new HashMap<>(); salaryTemplateShowSet.put("data", salaryTemplateShowSetDTO); // 薪资项目设置 List salaryTemplateShowSetData = new ArrayList<>(); if (StringUtils.isNotEmpty(po.getSalaryItemSetting())) { salaryTemplateShowSetData = JsonUtil.fromJson(po.getSalaryItemSetting(), List.class); } return SalaryTemplateShowFormDTO.builder() .id(id) .vars(Arrays.stream(SalaryTemplateVarEnum.values()).map(SalaryTemplateVarEnum::getValue).collect(Collectors.toList())) .salaryTemplateShowSet(salaryTemplateShowSet) .salaryTemplateSalaryItemSet(salaryTemplateShowSetData) .build(); } /** * 获取薪资项目设置 * * @param salarySobId * @return */ public List getSalaryItemSet(Long salarySobId) { return getSalaryTemplateService(user).getSalaryItemSet(salarySobId, false); } public List getReplenishSalaryItemSet(Long salarySobId) { return getSalaryTemplateService(user).getSalaryItemSet(salarySobId, true); } /** * 工资单模板默认使用 * * @param defaultUseParam * @return */ public String defaultUse(SalaryTemplateDefaultUseParam defaultUseParam) { return getSalaryTemplateService(user).defaultUse(defaultUseParam); } /** * 新建工资单模板 * * @param saveParam * @return */ public String save(SalaryTemplateSaveParam saveParam) { return getSalaryTemplateService(user).save(saveParam); } /** * 编辑工资单模板 * * @param saveParam * @return */ public String update(SalaryTemplateSaveParam saveParam) { return getSalaryTemplateService(user).update(saveParam); } /** * 复制工资单模板 * * @param copyParam * @return */ public String copy(SalaryTemplateCopyParam copyParam) { return getSalaryTemplateService(user).copy(copyParam); } /** * 删除工资单模板 * * @param ids * @return */ public String delete(Collection ids) { return getSalaryTemplateService(user).delete(ids); } /** * 获取薪资账套下拉列表 * * @return */ public List> selectSalarySobList() { return getSalaryTemplateService(user).selectSalarySobList(); } /** * 获取补发规则设置下拉列表 * * @param salarySobId * @return */ public List> getReplenishRuleSetOptions(Long salarySobId) { if (salarySobId == null) { return Collections.emptyList(); } SalarySobPO salarySob = getSalarySobService(user).getById(salarySobId); if (salarySob == null) { return Collections.emptyList(); } // 查询薪资账套的回算薪资项目 List salarySobBackItems = getSalarySobBackItemService(user).listBySalarySobId(salarySobId); if (CollectionUtils.isEmpty(salarySobBackItems)) { salarySobBackItems = getSalarySobBackItemService(user).listBySalarySobId(salarySob.getId()); } List salaryItemPOS = getSalaryItemService(user).listByIds(salarySobBackItems.stream().map(SalarySobBackItemPO::getSalaryItemId).collect(Collectors.toList())); String ruleTip = "(" + SalaryI18nUtil.getI18nLabel( 140142, "不等于0")+")"; List> result = salaryItemPOS.stream().map(m -> { Map map = new HashMap<>(2); map.put("id", String.valueOf(m.getId())); map.put("content", m.getName() + ruleTip); return map; }).collect(Collectors.toList()); return result; // if(result!= null && result.size()>0){ // return result.get(0); // } // return Collections.emptyMap(); } /** * 获取工资单模板补发设置表单 * * @param replenishFormQueryParam * @return */ public SalaryTemplateReplenishFormDTO getReplenishForm(ReplenishFormQueryParam replenishFormQueryParam) { Long id = replenishFormQueryParam.getId(); SalaryTemplateReplenishFormDTO salaryTemplateReplenishSetDTO = new SalaryTemplateReplenishFormDTO(); // 补发薪资项目设置 List replenishSalaryItemSetting; if (id != null) { SalaryTemplatePO po = getSalaryTemplateService(user).getById(id); if (po == null) { throw new SalaryRunTimeException(String.format(SalaryI18nUtil.getI18nLabel(100533, "工资单模板不存在")+"[id:%s]", id)); } BeanUtils.copyProperties(po, salaryTemplateReplenishSetDTO); if (StringUtils.isNotEmpty(po.getReplenishSalaryItemSetting())) { replenishSalaryItemSetting = JsonUtil.fromJson(po.getReplenishSalaryItemSetting(), List.class); } else { replenishSalaryItemSetting = getReplenishSalaryItemSet(replenishFormQueryParam.getSalarySobId()); } } else { replenishSalaryItemSetting = getReplenishSalaryItemSet(replenishFormQueryParam.getSalarySobId()); } return SalaryTemplateReplenishFormDTO.builder() .id(id) .replenishSalaryTemplateSalaryItemSet(replenishSalaryItemSetting) .build(); } }