package com.engine.salary.wrapper; import com.cloudstore.eccom.constant.WeaBoolAttr; import com.cloudstore.eccom.pc.table.WeaTable; import com.cloudstore.eccom.pc.table.WeaTableCheckboxpopedom; import com.cloudstore.eccom.pc.table.WeaTableColumn; import com.cloudstore.eccom.result.WeaResultMsg; import com.engine.common.util.ServiceUtil; import com.engine.core.impl.Service; import com.engine.salary.constant.SalaryItemConstant; import com.engine.salary.entity.salaryBill.dto.*; import com.engine.salary.entity.salaryBill.param.*; import com.engine.salary.entity.salaryBill.po.SalarySendPO; import com.engine.salary.entity.salaryBill.po.SalaryTemplatePO; import com.engine.salary.entity.salaryarchive.bo.SalaryArchiveBO; import com.engine.salary.entity.salaryarchive.dto.TaxAgentListDTO; import com.engine.salary.enums.salarybill.SalarySendStatusEnum; import com.engine.salary.enums.sicategory.WelfareTypeEnum; import com.engine.salary.exception.SalaryRunTimeException; import com.engine.salary.mapper.salarybill.SalarySendMapper; import com.engine.salary.service.SalarySendService; import com.engine.salary.service.SalaryTemplateService; import com.engine.salary.service.TaxAgentService; import com.engine.salary.service.impl.SalarySendServiceImpl; import com.engine.salary.service.impl.SalaryTemplateServiceImpl; import com.engine.salary.service.impl.TaxAgentServiceImpl; import com.engine.salary.util.SalaryI18nUtil; import com.engine.salary.util.page.PageInfo; import com.engine.salary.util.page.PageUtil; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.ibatis.session.SqlSession; import org.springframework.stereotype.Component; import weaver.conn.mybatis.MyBatisFactory; import weaver.hrm.User; import java.util.*; import java.util.concurrent.ExecutorService; import java.util.stream.Collectors; /** * @Description: 工资单发放 * @Author: wangxiangzhong * @Date: 2022/3/16 13:57 */ @Component public class SalarySendWrapper extends Service { private TaxAgentService getTaxAgentService(User user) { return ServiceUtil.getService(TaxAgentServiceImpl.class, user); } private SalarySendService getSalarySendService(User user) { return ServiceUtil.getService(SalarySendServiceImpl.class, user); } private SalaryTemplateService getSalaryTemplateService(User user) { return ServiceUtil.getService(SalaryTemplateServiceImpl.class, user); } // @Resource // private SalaryBatchService salaryBatchService; // @Autowired // private ExecutorService taskExecutor; /** * 工资单发放列表 * * @param queryParam * @return */ public Map list(SalarySendQueryParam queryParam) { SqlSession sqlSession = MyBatisFactory.sqlSessionFactory.openSession(); Map datas = new HashMap<>(16); try { queryParam.setSalaryMonth( queryParam.getSalaryYearMonth().stream().map(m -> m.atDay(1)).collect(Collectors.toList())); SalarySendMapper salarySendMapper = sqlSession.getMapper(SalarySendMapper.class); PageUtil.start(queryParam.getCurrent(), queryParam.getPageSize()); List list = salarySendMapper.list(queryParam); PageInfo pageInfo = new PageInfo<>(list, SalarySendListDTO.class); List pageList = pageInfo.getList(); List salarySobIds = pageList.stream().map(SalarySendListDTO::getSalarySobId).distinct().collect(Collectors.toList()); // 获取默认模板 List salaryTemplates = getSalaryTemplateService(user).getDefaultTemplates(salarySobIds); pageList.forEach(e -> { // 已发放 e.setSendSituation(e.getSendNum() + "/" + e.getSendTotal()); // 工资单模板 Optional optional = salaryTemplates.stream().filter(s -> s.getSalarySobId().equals(e.getSalarySobId())).findFirst(); if (optional.isPresent()) { e.setTemplate(optional.get().getName()); e.setTemplateId(optional.get().getId()); } }); List columns = buildWeaTableColumns(); WeaTable table = new WeaTable(); table.setColumns(columns); //设置check是否可用 List checkboxpopedomList = new ArrayList<>(); WeaTableCheckboxpopedom checkboxpopedom = new WeaTableCheckboxpopedom(); checkboxpopedom.setPopedompara("column:system_type"); checkboxpopedom.setShowmethod("com.engine.salary.transmethod.TaxRateTransMethod.getCheckBoxPopedom"); checkboxpopedomList.add(checkboxpopedom); table.setCheckboxList(checkboxpopedomList); table.setCheckboxpopedom(null); WeaResultMsg result = new WeaResultMsg(false); result.putAll(table.makeDataResult()); result.success(); datas.put("pageInfo", pageInfo); datas.put("datas", pageList); datas.put("columns", columns); datas.put("dataKey",result.getResultMap()); return datas; }finally { sqlSession.close(); } } /** * 创建表展示字段 * @return */ private List buildWeaTableColumns() { List list = new ArrayList<>(); WeaTableColumn idColumn = new WeaTableColumn("0px", "id", "id"); idColumn.setDisplay(WeaBoolAttr.FALSE); list.add(new WeaTableColumn("10%","薪资所属月", "salaryYearMonth")); list.add(new WeaTableColumn("35%","薪资账套", "salarySob")); list.add(new WeaTableColumn("25%","工资单模板", "template")); list.add(new WeaTableColumn("15%","已发放", "sendSituation")); list.add(new WeaTableColumn("15%","最后发送时间", "lastSendTime")); return list; } /** * 工资单发放基本信息 * * @param id * @return */ public SalarySendBaseInfoDTO getBaseInfo(Long id) { return getSalarySendService(user).getBaseInfo(id); } /** * 工资单发放信息列表的高级搜索 * * @return */ // public Map getInfoSearchCondition() { // List taxAgentList = new ArrayList<>(); // // 获取所有个税扣缴义务人 // Collection taxAgentLists = taxAgentService.findAll(tenantKey); // taxAgentLists.forEach(e -> taxAgentList.add(new WeaSearchConditionOption(e.getId().toString(), e.getName()))); // // WeaSearchCondition weaSearchCondition = SalaryFormatUtil.getInstance() // .buildCondition(SalarySendInfoSearchConditionDTO.class, // SalarySendInfoSearchConditionDTO.builder().taxAgentOptions(taxAgentList).build(), // "salarySendInfo"); // // 入职日期-添加范围 // SalaryArchiveBO.addDatePickerRangeOtherParams(weaSearchCondition, "hiredate", employeeId, tenantKey); // // 只保留常用条件 // weaSearchCondition.setGroups(weaSearchCondition.getGroups().stream().filter(e -> "commonGroup".equals(e.getId())).collect(Collectors.toList())); // // return weaSearchCondition; // } /** * 工资单发放信息列表 * * @param queryParam * @return */ public Map infoList(SalarySendInfoQueryParam queryParam) { Map datas = new HashMap<>(16); SalarySendInfoQueryParam.checkParam(queryParam); // 发送状态 if (queryParam.getSendStatus() != null) { queryParam.setSendStatusVal(queryParam.getSendStatus().getValue()); } PageInfo pageInfo = getSalarySendService(user).salarySendInfoListPage(queryParam); List list = pageInfo.getList(); list.forEach(e -> { // 发放状态 int sendStatus = Integer.parseInt(e.getSendStatus()); e.setSendStatus(SalarySendStatusEnum.getDefaultLabelByValue(sendStatus)); e.setOperation(SalarySendStatusEnum.getNameByValue(sendStatus)); }); List columns = buildInfoListWeaTableColumns(); WeaTable table = new WeaTable(); table.setColumns(columns); //设置check是否可用 List checkboxpopedomList = new ArrayList<>(); WeaTableCheckboxpopedom checkboxpopedom = new WeaTableCheckboxpopedom(); checkboxpopedom.setPopedompara("column:system_type"); checkboxpopedom.setShowmethod("com.engine.salary.transmethod.TaxRateTransMethod.getCheckBoxPopedom"); checkboxpopedomList.add(checkboxpopedom); table.setCheckboxList(checkboxpopedomList); table.setCheckboxpopedom(null); WeaResultMsg result = new WeaResultMsg(false); result.putAll(table.makeDataResult()); result.success(); datas.put("pageInfo", pageInfo); datas.put("datas",list); datas.put("columns",columns); datas.put("dataKey",result.getResultMap()); return datas; } /** * 工资单信息列表 * @return */ private List buildInfoListWeaTableColumns() { List list = new ArrayList<>(); WeaTableColumn idColumn = new WeaTableColumn("0px", "id", "id"); idColumn.setDisplay(WeaBoolAttr.TRUE); list.add(new WeaTableColumn("20%","姓名", "username")); list.add(new WeaTableColumn("20%","个税扣缴义务人", "taxAgent")); list.add(new WeaTableColumn("20%","部门", "department")); list.add(new WeaTableColumn("20%","手机号", "mobile")); list.add(new WeaTableColumn("20%","工号", "jobNum")); list.add(new WeaTableColumn("20%","发送状态", "sendStatus")); list.add(new WeaTableColumn("20%","操作", "operation")); return list; } /** * 导出-工资单发放信息列表 * * @param queryParam * @return */ // public Map exportInfoList(SalarySendInfoQueryParam queryParam) { // // 构建异步导出参数 // Map map = salaryBatchService.buildeExportParam("exportSalarySendInfo"); // // String username = UserContext.getCurrentUser().getUsername(); // String eteamsId = TenantRpcContext.getEteamsId(); // taskExecutor.execute(() -> { // try { // DSTenantKeyThreadVar.tenantKey.set(tenantKey); // salarySendService.exportInfoList(map, username, eteamsId, queryParam, employeeId, tenantKey); // } finally { // DSTenantKeyThreadVar.tenantKey.remove(); // } // }); // return map; // // TODO // return null; // } /** * 工资单发放 * * @param queryParam * @return */ public String grant(SalarySendGrantParam queryParam) { return getSalarySendService(user).grant(queryParam); } /** * 工资单撤回 * * @param queryParam * @return */ public String withdraw(SalarySendWithdrawParam queryParam) { return getSalarySendService(user).withdraw(queryParam); } /** * 工资单发放详情列表的高级搜索 * * @return */ // public Map getDetailSearchCondition() { // List taxAgentList = new ArrayList<>(); // // 获取所有个税扣缴义务人 // Collection taxAgentLists = taxAgentService.findAll(tenantKey); // taxAgentLists.forEach(e -> taxAgentList.add(new WeaSearchConditionOption(e.getId().toString(), e.getName()))); // // WeaSearchCondition weaSearchCondition = SalaryFormatUtil.getInstance() // .buildCondition(SalarySendDetailSearchConditionDTO.class, // SalarySendDetailSearchConditionDTO.builder().taxAgentOptions(taxAgentList).build(), // "salarySendDetail"); // // 入职日期-添加范围 // SalaryArchiveBO.addDatePickerRangeOtherParams(weaSearchCondition, "hiredate", employeeId, tenantKey); // // 只保留常用条件 // weaSearchCondition.setGroups(weaSearchCondition.getGroups().stream().filter(e -> "commonGroup".equals(e.getId())).collect(Collectors.toList())); // // return weaSearchCondition; // } /** * 工资单发放详情列表 * * @param queryParam * @return */ public Map detailList(SalarySendDetailQueryParam queryParam) { Map datas = new HashMap<>(); SalarySendDetailQueryParam.checkParam(queryParam); SalarySendPO salarySend = getSalarySendService(user).getById(queryParam.getSalarySendId()); if (salarySend == null) { throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(100510, "工资发放不存在")); } // 1.根据模板获取薪资项目设置 List salaryTemplates = getSalaryTemplateService(user).getDefaultTemplates(Collections.singletonList(salarySend.getSalarySobId())); List salaryItems = getSalarySendService(user).getSalaryItemsSetting(CollectionUtils.isNotEmpty(salaryTemplates) ? salaryTemplates.get(0) : null); // 2.获取基本数据 PageInfo pageInfo = getSalarySendService(user).salarySendInfoDetailListPage(queryParam); List records = pageInfo.getList(); // 3.组装详情数据 List> listMaps = getSalarySendService(user).buildDetailList(salaryItems, records, salarySend.getSalaryAccountingId()); List employeeIds = records.stream().map(SalarySendDetailListDTO::getEmployeeId).collect(Collectors.toList()); // 是否合并计税 // TODO: 1/25/22 判断是否合并计税 // Page> listPage = new Page<>(page.getCurrent(), page.getSize(), page.getTotal(), page.isSearchCount()); // listPage.setRecords(listMaps); List columns = buildDetailListWeaTableColumns(); WeaTable table = new WeaTable(); table.setColumns(columns); //设置check是否可用 List checkboxpopedomList = new ArrayList<>(); WeaTableCheckboxpopedom checkboxpopedom = new WeaTableCheckboxpopedom(); checkboxpopedom.setPopedompara("column:system_type"); checkboxpopedom.setShowmethod("com.engine.salary.transmethod.TaxRateTransMethod.getCheckBoxPopedom"); checkboxpopedomList.add(checkboxpopedom); table.setCheckboxList(checkboxpopedomList); table.setCheckboxpopedom(null); WeaResultMsg result = new WeaResultMsg(false); result.putAll(table.makeDataResult()); result.success(); datas.put("pageInfo", pageInfo); datas.put("datas", records); datas.put("columns",columns); datas.put("dataKey",result.getResultMap()); return datas; } private List buildDetailListWeaTableColumns() { List list = new ArrayList<>(); WeaTableColumn idColumn = new WeaTableColumn("0px", "id", "id"); idColumn.setDisplay(WeaBoolAttr.TRUE); list.add(new WeaTableColumn("20%","姓名", "username")); list.add(new WeaTableColumn("20%","个税扣缴义务人", "taxAgent")); list.add(new WeaTableColumn("20%","部门", "department")); list.add(new WeaTableColumn("20%","手机号", "mobile")); list.add(new WeaTableColumn("20%","工号", "jobNum")); return list; } /** * 导出-工资单发放详情列表 * * @param queryParam * @return */ public Map exportDetailList(SalarySendDetailQueryParam queryParam) { // 获取发放详情 // WeaResult checkResult = SalarySendDetailQueryParam.checkParam(queryParam, employeeId, tenantKey); // if (checkResult.getCode() == WeaResultCodeEnum.ERROR.getCode()) { // throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 84026, "参数错误")); // } // SalarySendPO salarySend = salarySendService.getById(queryParam.getSalarySendId(), tenantKey); // if (salarySend == null) { // throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(tenantKey, employeeId, 100512, "工资单发放不存在")); // } // // // 构建异步导出参数 // Map map = salaryBatchService.buildeExportParam("exportSalarySendDetail"); // // String username = UserContext.getCurrentUser().getUsername(); // String eteamsId = TenantRpcContext.getEteamsId(); // taskExecutor.execute(() -> { // try { // DSTenantKeyThreadVar.tenantKey.set(tenantKey); // salarySendService.exportDetailList(map, username, eteamsId, salarySend, queryParam, employeeId, tenantKey); // } finally { // DSTenantKeyThreadVar.tenantKey.remove(); // } // }); // return map; return null; } /** * 我的工资单列表 * * @param queryParam * @return */ public Map mySalaryBillList(SalaryBillQueryParam queryParam) { Map datas = new HashMap<>(); queryParam.setEmployeeId((long)user.getUID()); queryParam.setSalaryMonth( queryParam.getSalaryYearMonth().stream().map(m -> m.atDay(1)).collect(Collectors.toList())); PageInfo pageInfo = getSalarySendService(user).mySalaryBillListPage(queryParam); List records = pageInfo.getList(); records.forEach(e -> { e.setTaxAgent(StringUtils.isEmpty(e.getTaxAgent()) ? "" : e.getTaxAgent()); e.setAcctTimes(e.getAcctTimes()); }); List columns = buildMySalaryBillListColumns(); WeaTable table = new WeaTable(); table.setColumns(columns); //设置check是否可用 List checkboxpopedomList = new ArrayList<>(); WeaTableCheckboxpopedom checkboxpopedom = new WeaTableCheckboxpopedom(); checkboxpopedom.setPopedompara("column:system_type"); checkboxpopedom.setShowmethod("com.engine.salary.transmethod.TaxRateTransMethod.getCheckBoxPopedom"); checkboxpopedomList.add(checkboxpopedom); table.setCheckboxList(checkboxpopedomList); table.setCheckboxpopedom(null); WeaResultMsg result = new WeaResultMsg(false); result.putAll(table.makeDataResult()); result.success(); datas.put("pageInfo", pageInfo); datas.put("datas", records); datas.put("columns",columns); datas.put("dataKey",result.getResultMap()); return datas; } private List buildMySalaryBillListColumns() { List list = new ArrayList<>(); WeaTableColumn idColumn = new WeaTableColumn("0px", "id", "id"); idColumn.setDisplay(WeaBoolAttr.TRUE); list.add(new WeaTableColumn("20%","薪资所属月", "salaryYearMonth")); list.add(new WeaTableColumn("40%","个税扣缴义务人", "taxAgent")); list.add(new WeaTableColumn("40%","发放时间", "sendTime")); return list; } /** * 我的工资单 * * @param salaryInfoId * @return */ public Map mySalaryBill(Long salaryInfoId) { return getSalarySendService(user).mySalaryBill(salaryInfoId, (long) user.getUID()); } }