From fd0808bb0c62ae12cbfed651341d6de394b3f94e Mon Sep 17 00:00:00 2001 From: Harryxzy Date: Wed, 6 Aug 2025 18:09:19 +0800 Subject: [PATCH] =?UTF-8?q?=E8=81=94=E7=89=B9=20=E6=8A=A5=E8=A1=A8?= =?UTF-8?q?=EF=BC=884=E5=BC=A0=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Mysql/sql202508060103WHLTKJGFYXGS.sql | 1 + .../DataCollectionEmployee.java | 2 + .../po/VariableArchiveItemPO.java | 1 + .../salary/entity/hrm/po/HrmSnapshotPO.java | 5 + .../dto/LtSalaryReportConfigDTO.java | 26 + .../mapper/datacollection/EmployMapper.java | 2 + .../mapper/datacollection/EmployMapper.xml | 18 + .../VariableArchiveItemMapper.xml | 6 + .../salary/mapper/hrm/HrmSnapshotMapper.xml | 8 + .../service/SalaryAcctResultService.java | 25 + .../service/SalaryArchiveItemService.java | 3 + .../salary/service/SalaryEmployeeService.java | 2 + .../service/VariableArchiveItemService.java | 2 + .../service/VariableArchiveService.java | 2 + .../impl/SalaryAcctResultServiceImpl.java | 636 +++++++++++++++++- .../impl/SalaryArchiveItemServiceImpl.java | 21 + .../impl/SalaryEmployeeServiceImpl.java | 11 + .../impl/VariableArchiveItemServiceImpl.java | 15 + .../impl/VariableArchiveServiceImpl.java | 61 ++ .../engine/salary/timer/HrmSnapshotJob.java | 16 + .../salary/web/SalaryAcctController.java | 77 +++ .../wrapper/SalaryAcctResultWrapper.java | 33 + 22 files changed, 971 insertions(+), 2 deletions(-) create mode 100644 resource/sqlupgrade/Mysql/sql202508060103WHLTKJGFYXGS.sql create mode 100644 src/com/engine/salary/entity/salaryacct/dto/LtSalaryReportConfigDTO.java diff --git a/resource/sqlupgrade/Mysql/sql202508060103WHLTKJGFYXGS.sql b/resource/sqlupgrade/Mysql/sql202508060103WHLTKJGFYXGS.sql new file mode 100644 index 000000000..3c8361c00 --- /dev/null +++ b/resource/sqlupgrade/Mysql/sql202508060103WHLTKJGFYXGS.sql @@ -0,0 +1 @@ +alter table hrsa_hrm_snapshot add column lt_cbzx varchar(255); \ No newline at end of file diff --git a/src/com/engine/salary/entity/datacollection/DataCollectionEmployee.java b/src/com/engine/salary/entity/datacollection/DataCollectionEmployee.java index 9203785c0..4843aca13 100644 --- a/src/com/engine/salary/entity/datacollection/DataCollectionEmployee.java +++ b/src/com/engine/salary/entity/datacollection/DataCollectionEmployee.java @@ -125,6 +125,8 @@ public class DataCollectionEmployee { @SalaryFormulaVar(defaultLabel = "账号类型编码", labelId = 98622, dataType = "string") private Integer accountType; + private String ltCbzx; + //是否是系统管理员 private Boolean isAdmin; diff --git a/src/com/engine/salary/entity/datacollection/po/VariableArchiveItemPO.java b/src/com/engine/salary/entity/datacollection/po/VariableArchiveItemPO.java index cd211f2d3..dd00d04cc 100644 --- a/src/com/engine/salary/entity/datacollection/po/VariableArchiveItemPO.java +++ b/src/com/engine/salary/entity/datacollection/po/VariableArchiveItemPO.java @@ -74,5 +74,6 @@ public class VariableArchiveItemPO { //主键id集合 private Collection ids; private Collection variableArchiveIds; + private Collection variableItemIds; } diff --git a/src/com/engine/salary/entity/hrm/po/HrmSnapshotPO.java b/src/com/engine/salary/entity/hrm/po/HrmSnapshotPO.java index 48411733a..1d2e4981a 100644 --- a/src/com/engine/salary/entity/hrm/po/HrmSnapshotPO.java +++ b/src/com/engine/salary/entity/hrm/po/HrmSnapshotPO.java @@ -427,6 +427,11 @@ public class HrmSnapshotPO { @ElogTransform(name = "工作年限") private BigDecimal workyear; + /** + * 联特 成本中心 + */ + private String ltCbzx; + //主键id集合 private Collection ids; diff --git a/src/com/engine/salary/entity/salaryacct/dto/LtSalaryReportConfigDTO.java b/src/com/engine/salary/entity/salaryacct/dto/LtSalaryReportConfigDTO.java new file mode 100644 index 000000000..c69cb4e3a --- /dev/null +++ b/src/com/engine/salary/entity/salaryacct/dto/LtSalaryReportConfigDTO.java @@ -0,0 +1,26 @@ +package com.engine.salary.entity.salaryacct.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @ClassName LtSalaryReportConfigDTO + * @author Harryxzy + * @date 2025/7/30 17:45 + * @description + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class LtSalaryReportConfigDTO { + + // variable_id + private Long item; + + // 数据库字段名 + private String field; + +} diff --git a/src/com/engine/salary/mapper/datacollection/EmployMapper.java b/src/com/engine/salary/mapper/datacollection/EmployMapper.java index 73cb03b9d..d3fa69cf5 100644 --- a/src/com/engine/salary/mapper/datacollection/EmployMapper.java +++ b/src/com/engine/salary/mapper/datacollection/EmployMapper.java @@ -188,4 +188,6 @@ public interface EmployMapper { * @return */ List listByKeyword(@Param("keyword") String keyword); + + List listByWorkCodes(@Param("workCodes") List workCodes); } \ No newline at end of file diff --git a/src/com/engine/salary/mapper/datacollection/EmployMapper.xml b/src/com/engine/salary/mapper/datacollection/EmployMapper.xml index cfb6a45de..2c553acc5 100644 --- a/src/com/engine/salary/mapper/datacollection/EmployMapper.xml +++ b/src/com/engine/salary/mapper/datacollection/EmployMapper.xml @@ -721,4 +721,22 @@ from hrmjobcall job where job.id = #{jobCallId} + \ No newline at end of file diff --git a/src/com/engine/salary/mapper/datacollection/VariableArchiveItemMapper.xml b/src/com/engine/salary/mapper/datacollection/VariableArchiveItemMapper.xml index 365c21579..f7918f0c6 100644 --- a/src/com/engine/salary/mapper/datacollection/VariableArchiveItemMapper.xml +++ b/src/com/engine/salary/mapper/datacollection/VariableArchiveItemMapper.xml @@ -92,6 +92,12 @@ #{varArchId} + + AND variable_item_id IN + + #{variableItemId} + + ORDER BY id DESC diff --git a/src/com/engine/salary/mapper/hrm/HrmSnapshotMapper.xml b/src/com/engine/salary/mapper/hrm/HrmSnapshotMapper.xml index d56a738ea..4cdd38266 100644 --- a/src/com/engine/salary/mapper/hrm/HrmSnapshotMapper.xml +++ b/src/com/engine/salary/mapper/hrm/HrmSnapshotMapper.xml @@ -70,6 +70,7 @@ + @@ -144,6 +145,7 @@ , t.WORKROOM , t.workstartdate , t.workyear + , t.lt_cbzx @@ -600,6 +602,9 @@ workyear, + + lt_cbzx, + @@ -806,6 +811,9 @@ #{workyear}, + + #{ltCbzx}, + diff --git a/src/com/engine/salary/service/SalaryAcctResultService.java b/src/com/engine/salary/service/SalaryAcctResultService.java index 18d0ff00b..d02e0b2be 100644 --- a/src/com/engine/salary/service/SalaryAcctResultService.java +++ b/src/com/engine/salary/service/SalaryAcctResultService.java @@ -253,4 +253,29 @@ public interface SalaryAcctResultService { Map newResultValueMap, SalaryLogOperateTypeEnum operateType); + /** + * 联特 - 生成部门社保明细表 + * @param salaryMonth + * @return + */ + String ltGenBmsbmxb(String salaryMonth); + + /** + * 联特 - 生成部门公积金明细表 + * @param salaryMonth + * @return + */ + String ltGenBmgjjmxb(String salaryMonth); + + /** + * 联特 - 生成部门工资&奖金明细表-计提 + * @param salaryMonth + */ + String ltGenBmgzjjmxJt(String salaryMonth); + + /** + * 联特 - 生成部门工资&奖金明细表-实发 + * @param salaryMonth + */ + String ltGenBmgzjjmxSf(String salaryMonth); } diff --git a/src/com/engine/salary/service/SalaryArchiveItemService.java b/src/com/engine/salary/service/SalaryArchiveItemService.java index 6e22d49ba..103c315ba 100644 --- a/src/com/engine/salary/service/SalaryArchiveItemService.java +++ b/src/com/engine/salary/service/SalaryArchiveItemService.java @@ -13,6 +13,7 @@ import com.engine.salary.util.page.PageInfo; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import java.util.Collection; +import java.util.Date; import java.util.List; import java.util.Map; @@ -121,6 +122,8 @@ public interface SalaryArchiveItemService { */ List getCurrentEffectiveItemList(Collection salaryArchivesIds, Collection salaryItemIds); + List getEffectiveItemListBySalaryMonth(Collection salaryArchivesIds, Collection salaryItemIds, Date SalaryMonth); + /** * 获取薪资档案对应的当前生效的薪资项目忽略值 diff --git a/src/com/engine/salary/service/SalaryEmployeeService.java b/src/com/engine/salary/service/SalaryEmployeeService.java index 571073eee..abe64e820 100644 --- a/src/com/engine/salary/service/SalaryEmployeeService.java +++ b/src/com/engine/salary/service/SalaryEmployeeService.java @@ -210,4 +210,6 @@ public interface SalaryEmployeeService { JobCallInfo getJobCallInfoById(Long jobCallId); List snapshot(List employeeIds, Date snapshotTime); + + List listByWorkCodes(List workcodes); } diff --git a/src/com/engine/salary/service/VariableArchiveItemService.java b/src/com/engine/salary/service/VariableArchiveItemService.java index e5dd8644a..cfac30fc3 100644 --- a/src/com/engine/salary/service/VariableArchiveItemService.java +++ b/src/com/engine/salary/service/VariableArchiveItemService.java @@ -33,4 +33,6 @@ public interface VariableArchiveItemService { void deleteByIds(List variableArchiveItemIds); void deleteByArchiveIds(List variableArchiveIds); + + List listByVariableArchiveIdsAndItemIds(List variableArchiveIds, List variableItemIds); } diff --git a/src/com/engine/salary/service/VariableArchiveService.java b/src/com/engine/salary/service/VariableArchiveService.java index 735c03a96..743e0bdf7 100644 --- a/src/com/engine/salary/service/VariableArchiveService.java +++ b/src/com/engine/salary/service/VariableArchiveService.java @@ -71,5 +71,7 @@ public interface VariableArchiveService { List> listBySalaryMonthAndEmployeeIds(YearMonth salaryMonth, List employeeIds, List taxAgentIds); + List> listBySalaryMonthAndItems(YearMonth salaryMonth, List variableItemIds); + void updateData(VariableArchiveSaveParam updateParam); } diff --git a/src/com/engine/salary/service/impl/SalaryAcctResultServiceImpl.java b/src/com/engine/salary/service/impl/SalaryAcctResultServiceImpl.java index e8e12df20..d6031785c 100644 --- a/src/com/engine/salary/service/impl/SalaryAcctResultServiceImpl.java +++ b/src/com/engine/salary/service/impl/SalaryAcctResultServiceImpl.java @@ -20,10 +20,13 @@ import com.engine.salary.entity.progress.ProgressDTO; import com.engine.salary.entity.report.po.SalaryAcctResultReportPO; import com.engine.salary.entity.salaryacct.bo.*; import com.engine.salary.entity.salaryacct.dto.ConsolidatedTaxDetailDTO; +import com.engine.salary.entity.salaryacct.dto.LtSalaryReportConfigDTO; import com.engine.salary.entity.salaryacct.dto.SalaryAcctResultDetailDTO; import com.engine.salary.entity.salaryacct.dto.SalaryAcctResultListColumnDTO; import com.engine.salary.entity.salaryacct.param.*; import com.engine.salary.entity.salaryacct.po.*; +import com.engine.salary.entity.salaryarchive.po.SalaryArchiveItemPO; +import com.engine.salary.entity.salaryarchive.po.SalaryArchivePO; import com.engine.salary.entity.salaryformula.ExpressFormula; import com.engine.salary.entity.salaryformula.po.FormulaVar; import com.engine.salary.entity.salaryitem.po.SalaryItemPO; @@ -51,6 +54,7 @@ import com.engine.salary.sys.entity.po.SalarySysConfPO; import com.engine.salary.sys.enums.TaxDeclarationFunctionEnum; import com.engine.salary.sys.service.SalarySysConfService; import com.engine.salary.sys.service.impl.SalarySysConfServiceImpl; +import com.engine.salary.util.JsonUtil; import com.engine.salary.util.SalaryDateUtil; import com.engine.salary.util.SalaryEntityUtil; import com.engine.salary.util.SalaryI18nUtil; @@ -72,10 +76,18 @@ import org.jetbrains.annotations.NotNull; import org.springframework.beans.BeanUtils; import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.util.StopWatch; +import weaver.conn.RecordSet; +import weaver.conn.RecordSetDataSource; +import weaver.formmode.setup.ModeRightInfo; import weaver.general.BaseBean; +import weaver.general.TimeUtil; import weaver.hrm.User; +import weaver.wechat.util.Utils; import java.math.BigDecimal; +import java.math.RoundingMode; +import java.text.SimpleDateFormat; +import java.time.YearMonth; import java.util.*; import java.util.concurrent.BlockingDeque; import java.util.concurrent.CountDownLatch; @@ -83,9 +95,8 @@ import java.util.concurrent.LinkedBlockingDeque; import java.util.regex.Matcher; import java.util.stream.Collectors; -import static com.engine.salary.sys.constant.SalarySysConstant.SALARY_ACCT_SYNC_TYPE; - import static com.engine.salary.constant.SalaryFormulaFieldConstant.SALARY_PATTERN; +import static com.engine.salary.sys.constant.SalarySysConstant.SALARY_ACCT_SYNC_TYPE; /** * 薪资核算结果 @@ -220,6 +231,23 @@ public class SalaryAcctResultServiceImpl extends Service implements SalaryAcctRe return ServiceUtil.getService(SalarySobTaxRuleServiceImpl.class, user); } + + private VariableArchiveService getVariableArchiveService(User user) { + return ServiceUtil.getService(VariableArchiveServiceImpl.class, user); + } + + private VariableArchiveItemService getVariableArchiveItemService(User user) { + return ServiceUtil.getService(VariableArchiveItemServiceImpl.class, user); + } + + private SalaryArchiveService getSalaryArchiveService(User user) { + return ServiceUtil.getService(SalaryArchiveServiceImpl.class, user); + } + + private SalaryArchiveItemService getSalaryArchiveItemService(User user) { + return ServiceUtil.getService(SalaryArchiveItemServiceImpl.class, user); + } + @Override public List listBySalaryAcctRecordIds(Collection salaryAcctRecordIds) { if (CollectionUtils.isEmpty(salaryAcctRecordIds)) { @@ -1547,4 +1575,608 @@ public class SalaryAcctResultServiceImpl extends Service implements SalaryAcctRe context.setNewValues(newResultValueMap); SalaryElogConfig.salaryAcctRecordLoggerTemplate.write(context); } + + /** + * 联特 - 生成部门社保明细表 + * @param salaryMonth + * @return + */ + @Override + public String ltGenBmsbmxb(String salaryMonth) { + if (!SalaryDateUtil.checkYearMonth(salaryMonth)) { + throw new SalaryRunTimeException("年月错误"); + } + YearMonth yearMonth = SalaryDateUtil.String2YearMonth(salaryMonth); + // 查询需要生成哪些浮动薪资项目 + BaseBean baseBean = new BaseBean(); + String configStr = baseBean.getPropValue("ltSalaryReport", "bmsbmxb_ys_config"); + List configs = JsonUtil.parseList(configStr, LtSalaryReportConfigDTO.class); + List variableItemIds = configs.stream().map(LtSalaryReportConfigDTO::getItem).collect(Collectors.toList()); + // 获取浮动档案 + List> variableMapList = getVariableArchiveService(user).listBySalaryMonthAndItems(yearMonth, variableItemIds); + // 过滤数据,不能所有值为0或空 + List keyList = configs.stream().map(dto -> dto.getItem() + "_variableItem").collect(Collectors.toList()); + variableMapList = variableMapList.stream().filter(map -> { + for (String key : keyList) { + String val = Utils.null2String(map.get(key)); + if (StringUtils.isNotBlank(val) && NumberUtils.isCreatable(val) && new BigDecimal(val).compareTo(BigDecimal.ZERO) != 0 ) { + return true; + } + } + return false; + }).collect(Collectors.toList()); + if (CollectionUtils.isEmpty(variableMapList)) { + return null; + } + log.info("部门社保明细表size{} ",variableMapList.size()); + // 获取人员信息 + List empIds = variableMapList.stream().map(map -> Utils.null2String(map.get("employeeId"))).filter(NumberUtils::isCreatable).map(Long::valueOf).collect(Collectors.toList()); + // Map employeeMap = SalaryEntityUtil.convert2Map(getSalaryEmployeeService(user).listByIds(empIds), DataCollectionEmployee::getEmployeeId); + // 查询快照表中人员信息 + Map employeeMap = SalaryEntityUtil.convert2Map(getSalaryEmployeeService(user).snapshot(empIds, SalaryDateUtil.localDateToDate(yearMonth.atDay(1))), DataCollectionEmployee::getEmployeeId); + // 删除建模数据 + RecordSet rs = new RecordSet(); + rs.execute("delete from uf_bmsbmxb where xzszy = '" + salaryMonth+ "'"); + // 插入建模 + String currDate = String.format("'%s'", TimeUtil.getCurrentDateString()); + SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); + String currTime = String.format("'%s'", sdf.format(new Date())); + // 获取建模模块id + String modeId = baseBean.getPropValue("ltSalaryReport", "bmsbmxb_mode_id"); + // 先插入一条数据 + Map firstData = variableMapList.get(0); + StringBuilder firstSb = new StringBuilder(); + String fieldStr = configs.stream().map(LtSalaryReportConfigDTO::getField).collect(Collectors.joining(",")); + DataCollectionEmployee employee = employeeMap.getOrDefault(firstData.get("employeeId"), DataCollectionEmployee.builder().build()); + firstSb.append("insert into uf_bmsbmxb(formmodeid,modedatacreater,modedatacreatertype,modedatacreatedate,modedatacreatetime,gh,xm,bm,gw,xzszy,cbzx,"+fieldStr+") values ("); + firstSb.append(modeId).append(",1,0,").append(currDate).append(",").append(currTime).append(",'") + .append(employee.getWorkcode()).append("',") + .append(employee.getEmployeeId()).append(",") + .append(employee.getDepartmentId()).append(",") + .append(employee.getJobtitleId()).append(",'") + .append(salaryMonth).append("','") + .append(Utils.null2String(employee.getLtCbzx())).append("'"); + + for (LtSalaryReportConfigDTO dto : configs) { + String val = Utils.null2String(firstData.get(Utils.null2String(dto.getItem()) + "_variableItem" )); + firstSb.append(",").append(NumberUtils.isCreatable(val) ? val : 0); + } + firstSb.append(")"); + rs.execute(firstSb.toString()); + variableMapList.remove(0); + // 获取最大值 作为权限重构的起始id + rs.execute("select max(id) from uf_bmsbmxb"); + int minId = 0; + if (rs.next()) { + minId = rs.getInt(1); + } + int maxId = minId + variableMapList.size(); + + + + List>> partition = Lists.partition(variableMapList, 500); + partition.forEach(part -> { + StringBuilder sb = new StringBuilder(); + sb.append("insert into uf_bmsbmxb(formmodeid,modedatacreater,modedatacreatertype,modedatacreatedate,modedatacreatetime,gh,xm,bm,gw,xzszy,cbzx,"+fieldStr+") values "); + for (Map data : part) { + DataCollectionEmployee employeePo = employeeMap.getOrDefault(data.get("employeeId"), DataCollectionEmployee.builder().build()); + sb.append("(") + .append(modeId).append(",1,0,").append(currDate).append(",").append(currTime).append(",'") + .append(employeePo.getWorkcode()).append("',") + .append(employeePo.getEmployeeId()).append(",") + .append(employeePo.getDepartmentId()).append(",") + .append(employeePo.getJobtitleId()).append(",'") + .append(salaryMonth).append("','") + .append(Utils.null2String(employeePo.getLtCbzx())).append("'"); + for (LtSalaryReportConfigDTO dto : configs) { + String val = Utils.null2String(data.getOrDefault(Utils.null2String(dto.getItem()) + "_variableItem", "")); + sb.append(",").append(NumberUtils.isCreatable(val) ? val : 0); + } + sb.append("),"); + } + rs.execute(sb.substring(0,sb.length()-1).toString()); + }); + // 权限重构 + log.info("部门社保明细表min{} max{} ",minId,maxId); + if (modeId != null && NumberUtils.isCreatable(modeId)) { + Integer modeIdValue = Integer.valueOf(modeId); + for (int i = minId; i <= maxId; i++) { + ModeRightInfo ModeRightInfo = new ModeRightInfo(); + ModeRightInfo.setNewRight(true); + ModeRightInfo.editModeDataShare(1, modeIdValue, i); + } + } + + return "success"; + } + + @Override + public String ltGenBmgjjmxb(String salaryMonth) { + if (!SalaryDateUtil.checkYearMonth(salaryMonth)) { + throw new SalaryRunTimeException("年月错误"); + } + YearMonth yearMonth = SalaryDateUtil.String2YearMonth(salaryMonth); + // 查询需要生成哪些浮动薪资项目 + BaseBean baseBean = new BaseBean(); + String configStr = baseBean.getPropValue("ltSalaryReport", "bmgjjmxb_ys_config"); + List configs = JsonUtil.parseList(configStr, LtSalaryReportConfigDTO.class); + List variableItemIds = configs.stream().map(LtSalaryReportConfigDTO::getItem).collect(Collectors.toList()); + // 获取浮动档案 + List> variableMapList = getVariableArchiveService(user).listBySalaryMonthAndItems(yearMonth, variableItemIds); + // 过滤数据,不能所有值为0或空 + List keyList = configs.stream().map(dto -> dto.getItem() + "_variableItem").collect(Collectors.toList()); + variableMapList = variableMapList.stream().filter(map -> { + for (String key : keyList) { + String val = Utils.null2String(map.get(key)); + if (StringUtils.isNotBlank(val) && NumberUtils.isCreatable(val) && new BigDecimal(val).compareTo(BigDecimal.ZERO) != 0 ) { + return true; + } + } + return false; + }).collect(Collectors.toList()); + if (CollectionUtils.isEmpty(variableMapList)) { + return null; + } + log.info("部门公积金明细size{} ",variableMapList.size()); + // 获取人员信息 + List empIds = variableMapList.stream().map(map -> Utils.null2String(map.get("employeeId"))).filter(NumberUtils::isCreatable).map(Long::valueOf).collect(Collectors.toList()); + // Map employeeMap = SalaryEntityUtil.convert2Map(getSalaryEmployeeService(user).listByIds(empIds), DataCollectionEmployee::getEmployeeId); + // 查询快照表中人员信息 + Map employeeMap = SalaryEntityUtil.convert2Map(getSalaryEmployeeService(user).snapshot(empIds, SalaryDateUtil.localDateToDate(yearMonth.atDay(1))), DataCollectionEmployee::getEmployeeId); + // 删除建模数据 + RecordSet rs = new RecordSet(); + rs.execute("delete from uf_bmgjjmxb where xzszy = '" + salaryMonth+ "'"); + // 插入建模 + String currDate = String.format("'%s'", TimeUtil.getCurrentDateString()); + SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); + String currTime = String.format("'%s'", sdf.format(new Date())); + // 获取建模模块id + String modeId = baseBean.getPropValue("ltSalaryReport", "bmgjjmxb_mode_id"); + // 先插入一条数据 + Map firstData = variableMapList.get(0); + StringBuilder firstSb = new StringBuilder(); + String fieldStr = configs.stream().map(LtSalaryReportConfigDTO::getField).collect(Collectors.joining(",")); + DataCollectionEmployee employee = employeeMap.getOrDefault(firstData.get("employeeId"), DataCollectionEmployee.builder().build()); + firstSb.append("insert into uf_bmgjjmxb(formmodeid,modedatacreater,modedatacreatertype,modedatacreatedate,modedatacreatetime,gh,xm,bm,gw,xzszy,cbzx,"+fieldStr+") values ("); + firstSb.append(modeId).append(",1,0,").append(currDate).append(",").append(currTime).append(",'") + .append(employee.getWorkcode()).append("',") + .append(employee.getEmployeeId()).append(",") + .append(employee.getDepartmentId()).append(",") + .append(employee.getJobtitleId()).append(",'") + .append(salaryMonth).append("','") + .append(Utils.null2String(employee.getLtCbzx())).append("'"); + + for (LtSalaryReportConfigDTO dto : configs) { + String val = Utils.null2String(firstData.getOrDefault(Utils.null2String(dto.getItem()) + "_variableItem", "")); + firstSb.append(",").append(NumberUtils.isCreatable(val) ? val : 0); + } + firstSb.append(")"); + rs.execute(firstSb.toString()); + variableMapList.remove(0); + // 获取最大值 作为权限重构的起始id + rs.execute("select max(id) from uf_bmgjjmxb"); + int minId = 0; + if (rs.next()) { + minId = rs.getInt(1); + } + int maxId = minId + variableMapList.size(); + + + + List>> partition = Lists.partition(variableMapList, 500); + partition.forEach(part -> { + StringBuilder sb = new StringBuilder(); + sb.append("insert into uf_bmgjjmxb(formmodeid,modedatacreater,modedatacreatertype,modedatacreatedate,modedatacreatetime,gh,xm,bm,gw,xzszy,cbzx,"+fieldStr+") values "); + for (Map data : part) { + DataCollectionEmployee employeePo = employeeMap.getOrDefault(data.get("employeeId"), DataCollectionEmployee.builder().build()); + sb.append("(") + .append(modeId).append(",1,0,").append(currDate).append(",").append(currTime).append(",'") + .append(employeePo.getWorkcode()).append("',") + .append(employeePo.getEmployeeId()).append(",") + .append(employeePo.getDepartmentId()).append(",") + .append(employeePo.getJobtitleId()).append(",'") + .append(salaryMonth).append("','") + .append(Utils.null2String(employeePo.getLtCbzx())).append("'"); + for (LtSalaryReportConfigDTO dto : configs) { + String val = Utils.null2String(data.getOrDefault(Utils.null2String(dto.getItem()) + "_variableItem", "")); + sb.append(",").append(NumberUtils.isCreatable(val) ? val : 0); + } + sb.append("),"); + } + rs.execute(sb.substring(0,sb.length()-1).toString()); + }); + // 权限重构 + log.info("部门公积金明细min{} max{} ",minId,maxId); + if (modeId != null && NumberUtils.isCreatable(modeId)) { + Integer modeIdValue = Integer.valueOf(modeId); + for (int i = minId; i <= maxId; i++) { + ModeRightInfo ModeRightInfo = new ModeRightInfo(); + ModeRightInfo.setNewRight(true); + ModeRightInfo.editModeDataShare(1, modeIdValue, i); + } + } + + return "success"; + } + + @Override + public String ltGenBmgzjjmxJt(String salaryMonth) { + if (!SalaryDateUtil.checkYearMonth(salaryMonth)) { + throw new SalaryRunTimeException("年月错误"); + } + YearMonth yearMonth = SalaryDateUtil.String2YearMonth(salaryMonth); + // 查询需要生成哪些浮动薪资项目 + BaseBean baseBean = new BaseBean(); + String configStr = baseBean.getPropValue("ltSalaryReport", "bmsbmxb_ys_config"); + List configs = JsonUtil.parseList(configStr, LtSalaryReportConfigDTO.class); + String gjjConfigStr = baseBean.getPropValue("ltSalaryReport", "bmgjjmxb_ys_config"); + configs.addAll(JsonUtil.parseList(gjjConfigStr, LtSalaryReportConfigDTO.class)); + List variableItemIds = configs.stream().map(LtSalaryReportConfigDTO::getItem).collect(Collectors.toList()); + // 获取浮动档案 + List> variableMapList = getVariableArchiveService(user).listBySalaryMonthAndItems(yearMonth, variableItemIds); + log.info("部门工资奖金明细表计提size{} ",variableMapList == null ? 0 :variableMapList.size()); + // 获取直接人工工资分摊表的人 + String dataSourceId = baseBean.getPropValue("ltSalaryReport", "zjrycqgsft_data_source_id"); + RecordSetDataSource extRs = new RecordSetDataSource(dataSourceId); + extRs.execute(" select month, user_code from dws_oa.work_hour_apportion_report where month='"+salaryMonth+"'"); + List needExcludeWorkCodeList = new ArrayList<>(); + while (extRs.next()) { + needExcludeWorkCodeList.add(extRs.getString("user_code")); + } + if (CollectionUtils.isNotEmpty(needExcludeWorkCodeList)) { + // 获取需要去除的人员id + List excludeEmpIds = getSalaryEmployeeService(user).listByWorkCodes(needExcludeWorkCodeList).stream().map(emp -> Utils.null2String(emp.getEmployeeId())).collect(Collectors.toList()); + variableMapList = variableMapList.stream().filter(map -> !excludeEmpIds.contains(Utils.null2String(map.get("employeeId")))).collect(Collectors.toList()); + } + log.info("部门工资奖金明细表计提size afterexclude{} ", variableMapList == null ? 0 : variableMapList.size()); + + // 过滤数据,不能所有值为0或空 + List keyList = configs.stream().map(dto -> dto.getItem() + "_variableItem").collect(Collectors.toList()); + variableMapList = variableMapList.stream().filter(map -> { + for (String key : keyList) { + String val = Utils.null2String(map.get(key)); + if (StringUtils.isNotBlank(val) && NumberUtils.isCreatable(val) && new BigDecimal(val).compareTo(BigDecimal.ZERO) != 0) { + return true; + } + } + return false; + }).collect(Collectors.toList()); + if (CollectionUtils.isEmpty(variableMapList)) { + return null; + } + log.info("部门工资奖金明细表实发size afterexclude2{} ",variableMapList.size()); + List employeeIdList = variableMapList.stream().map(m -> Utils.null2String(m.get("employeeId"))) + .filter(NumberUtils::isCreatable).map(Long::valueOf).collect(Collectors.toList()); + + + // 查询生成的报表映射关系 + String reportConfigStr = baseBean.getPropValue("ltSalaryReport", "bmgzjjmxbjt_ys_config"); + List reportConfigs = JsonUtil.parseList(reportConfigStr, LtSalaryReportConfigDTO.class); + List salaryItemIds = reportConfigs.stream().map(LtSalaryReportConfigDTO::getItem).collect(Collectors.toList()); + List salaryItemList = getSalaryItemService(user).listByIds(salaryItemIds); + // 查询薪资核算结果(包含未归档) + Date salaryMonthDate = SalaryDateUtil.localDateToDate(yearMonth.atDay(1)); + List salaryAcctRecordList = getSalaryAcctRecordService(user).listBySalaryMonth(LocalDateRange.builder().fromDate(salaryMonthDate).endDate(salaryMonthDate).build()); + // 账套范围 + List sobIds = Arrays.stream(baseBean.getPropValue("ltSalaryReport", "bmgzjjmxbjt_sob_ids").split(",")).filter(NumberUtils::isCreatable).map(Long::valueOf).collect(Collectors.toList()); + salaryAcctRecordList = salaryAcctRecordList.stream().filter(sobId -> sobIds.contains(sobId)).collect(Collectors.toList()); + if (CollectionUtils.isEmpty(salaryAcctRecordList)) { + return "success"; + } + List salaryAcctRecordIds = salaryAcctRecordList.stream().map(SalaryAcctRecordPO::getId).collect(Collectors.toList()); + List salaryAcctEmployeeList = getSalaryAcctEmployeeService(user).listBySalaryAcctRecordIdsAndEmployeeIds(salaryAcctRecordIds, employeeIdList); + List employeeList = getSalaryEmployeeService(user).listByIds(employeeIdList); + // 查询薪资核算结果 + List salaryAcctEmpIds = salaryAcctEmployeeList.stream().map(SalaryAcctEmployeePO::getId).collect(Collectors.toList()); + List acctResultList = getSalaryAcctResultService(user).listByAcctEmployeeIdsAndSalaryItemIds(salaryAcctEmpIds, salaryItemIds); + List taxAgentPOS = getTaxAgentService(user).listAll(); + List> acctResultMap = SalaryAcctResultBO.buildTableData(salaryItemList, Collections.emptyList(), employeeList, salaryAcctEmployeeList, + acctResultList, taxAgentPOS, Collections.emptySet(), Collections.emptyMap(), Collections.emptyMap(), false); + Map> acctResultMapByEmpId = SalaryEntityUtil.convert2Map(acctResultMap, m -> Utils.null2String(m.get("employeeId"))); + + // 查询员工薪资档案 + List salaryArchiveList = getSalaryArchiveService(user).listSome(SalaryArchivePO.builder().employeeIds(employeeIdList).build()); + Map archiveIdMap = SalaryEntityUtil.convert2Map(salaryArchiveList, archive -> archive.getTaxAgentId() + "_" + archive.getEmployeeId(), archive -> archive.getId()); + List salaryArchiveIds = salaryArchiveList.stream().map(SalaryArchivePO::getId).collect(Collectors.toList()); + // 查询档案中对应的绩效工资 + Long jdjxItemId = NumberUtils.isCreatable(baseBean.getPropValue("ltSalaryReport", "jdjx_item_id")) ? Long.valueOf(baseBean.getPropValue("ltSalaryReport", "jdjx_item_id")) : 0L; + Date lastDayOfMonth = SalaryDateUtil.getLastDayOfMonth(salaryMonthDate); + List salaryArchiveItemCurrentList = getSalaryArchiveItemService(user).getEffectiveItemListBySalaryMonth(salaryArchiveIds, Collections.singletonList(jdjxItemId), lastDayOfMonth); + Map archiveItemByArchiveId = SalaryEntityUtil.convert2Map(salaryArchiveItemCurrentList, archive -> archive.getSalaryArchiveId()); + + // 查询快照表中人员信息 + Map employeeMap = SalaryEntityUtil.convert2Map(getSalaryEmployeeService(user).snapshot(employeeIdList, SalaryDateUtil.localDateToDate(yearMonth.atDay(1))), DataCollectionEmployee::getEmployeeId); + + // 入库 + // 删除建模数据 + RecordSet rs = new RecordSet(); + rs.execute("delete from uf_bmjjjt where xzszy = '" + salaryMonth+ "'"); + // 插入建模 + String currDate = String.format("'%s'", TimeUtil.getCurrentDateString()); + SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); + String currTime = String.format("'%s'", sdf.format(new Date())); + // 获取建模模块id + String modeId = baseBean.getPropValue("ltSalaryReport", "bmgzjjmxbjt_mode_id"); + // 先插入一条数据 + Map firstData = variableMapList.get(0); + StringBuilder firstSb = new StringBuilder(); + String fieldStr = reportConfigs.stream().map(LtSalaryReportConfigDTO::getField).collect(Collectors.joining(",")); + DataCollectionEmployee employee = employeeMap.getOrDefault(firstData.get("employeeId"), DataCollectionEmployee.builder().build()); + // 获取员工档案绩效工资 + Long archiveId = archiveIdMap.get(Utils.null2String(firstData.get("taxAgentId")) + "_" + employee.getEmployeeId()); + SalaryArchiveItemPO salaryArchiveItemPO = archiveItemByArchiveId.get(archiveId == null ? 0L : archiveId); + String jxgz = (salaryArchiveItemPO == null || !NumberUtils.isCreatable(salaryArchiveItemPO.getItemValue())) ? "0" : new BigDecimal(salaryArchiveItemPO.getItemValue()).divide(new BigDecimal("3"), 2, RoundingMode.HALF_UP).toString(); + // 获取薪资核算结果 + Map singleAcctResultMap = acctResultMapByEmpId.get(Utils.null2String(employee.getEmployeeId())); + firstSb.append("insert into uf_bmjjjt(formmodeid,modedatacreater,modedatacreatertype,modedatacreatedate,modedatacreatetime,gh,xm,bm,gw,xzszy,cbzx,jdjxgzbz3,"+fieldStr+") values ("); + firstSb.append(modeId).append(",1,0,").append(currDate).append(",").append(currTime).append(",'") + .append(employee.getWorkcode()).append("',") + .append(employee.getEmployeeId()).append(",") + .append(employee.getDepartmentId()).append(",") + .append(employee.getJobtitleId()).append(",'") + .append(salaryMonth).append("','") + .append(Utils.null2String(employee.getLtCbzx())).append("',") + .append(jxgz); + + for (LtSalaryReportConfigDTO dto : reportConfigs) { + BigDecimal val = new BigDecimal("0"); + if (singleAcctResultMap != null) { + String valStr = Utils.null2String(singleAcctResultMap.getOrDefault(Utils.null2String(dto.getItem()), "0")); + if (NumberUtils.isCreatable(valStr)) { + val = new BigDecimal(valStr); + } + } + firstSb.append(",").append(val.toPlainString()); + } + firstSb.append(")"); + rs.execute(firstSb.toString()); + variableMapList.remove(0); + // 获取最大值 作为权限重构的起始id + rs.execute("select max(id) from uf_bmjjjt"); + int minId = 0; + if (rs.next()) { + minId = rs.getInt(1); + } + int maxId = minId + variableMapList.size(); + + + List>> partition = Lists.partition(variableMapList, 500); + for (List> part : partition) { + StringBuilder sb = new StringBuilder(); + sb.append("insert into uf_bmjjjt(formmodeid,modedatacreater,modedatacreatertype,modedatacreatedate,modedatacreatetime,gh,xm,bm,gw,xzszy,cbzx,jdjxgzbz3,"+fieldStr+") values "); + for (Map data : part) { + employee = employeeMap.getOrDefault(data.get("employeeId"), DataCollectionEmployee.builder().build()); + // 获取员工档案绩效工资 + // 获取员工档案绩效工资 + archiveId = archiveIdMap.get(Utils.null2String(data.get("taxAgentId")) + "_" + employee.getEmployeeId()); + salaryArchiveItemPO = archiveItemByArchiveId.get(archiveId == null ? 0L : archiveId); + jxgz = (salaryArchiveItemPO == null || !NumberUtils.isCreatable(salaryArchiveItemPO.getItemValue())) ? "0" : new BigDecimal(salaryArchiveItemPO.getItemValue()).divide(new BigDecimal("3"), 2, RoundingMode.HALF_UP).toString(); + // 获取薪资核算结果 + singleAcctResultMap = acctResultMapByEmpId.get(Utils.null2String(employee.getEmployeeId())); + + sb.append("(") + .append(modeId).append(",1,0,").append(currDate).append(",").append(currTime).append(",'") + .append(employee.getWorkcode()).append("',") + .append(employee.getEmployeeId()).append(",") + .append(employee.getDepartmentId()).append(",") + .append(employee.getJobtitleId()).append(",'") + .append(salaryMonth).append("','") + .append(Utils.null2String(employee.getLtCbzx())).append("',") + .append(jxgz); + for (LtSalaryReportConfigDTO dto : reportConfigs) { + BigDecimal val = new BigDecimal("0"); + if (singleAcctResultMap != null) { + String valStr = Utils.null2String(singleAcctResultMap.getOrDefault(Utils.null2String(dto.getItem()), "0")); + if (NumberUtils.isCreatable(valStr)) { + val = new BigDecimal(valStr); + } + } + sb.append(",").append(val.toPlainString()); + } + sb.append("),"); + } + rs.execute(sb.substring(0,sb.length()-1).toString()); + } + // 权限重构 + log.info("部门工资奖金明细表计提min{} max{} ",minId,maxId); + if (modeId != null && NumberUtils.isCreatable(modeId)) { + Integer modeIdValue = Integer.valueOf(modeId); + for (int i = minId; i <= maxId; i++) { + ModeRightInfo ModeRightInfo = new ModeRightInfo(); + ModeRightInfo.setNewRight(true); + ModeRightInfo.editModeDataShare(1, modeIdValue, i); + } + } + return "success"; + } + + @Override + public String ltGenBmgzjjmxSf(String salaryMonth) { + if (!SalaryDateUtil.checkYearMonth(salaryMonth)) { + throw new SalaryRunTimeException("年月错误"); + } + YearMonth yearMonth = SalaryDateUtil.String2YearMonth(salaryMonth); + // 查询需要生成哪些浮动薪资项目 + BaseBean baseBean = new BaseBean(); + String configStr = baseBean.getPropValue("ltSalaryReport", "bmsbmxb_ys_config"); + List configs = JsonUtil.parseList(configStr, LtSalaryReportConfigDTO.class); + String gjjConfigStr = baseBean.getPropValue("ltSalaryReport", "bmgjjmxb_ys_config"); + configs.addAll(JsonUtil.parseList(gjjConfigStr, LtSalaryReportConfigDTO.class)); + List variableItemIds = configs.stream().map(LtSalaryReportConfigDTO::getItem).collect(Collectors.toList()); + // 获取浮动档案 + List> variableMapList = getVariableArchiveService(user).listBySalaryMonthAndItems(yearMonth, variableItemIds); + log.info("部门工资奖金明细表实发size{} ",variableMapList == null ? 0 : variableMapList.size()); + // 获取直接人工工资分摊表的人 + String dataSourceId = baseBean.getPropValue("ltSalaryReport", "zjrycqgsft_data_source_id"); + RecordSetDataSource extRs = new RecordSetDataSource(dataSourceId); + extRs.execute(" select month, user_code from dws_oa.work_hour_apportion_report where month='"+salaryMonth+"'"); + List needExcludeWorkCodeList = new ArrayList<>(); + while (extRs.next()) { + needExcludeWorkCodeList.add(extRs.getString("user_code")); + } + if (CollectionUtils.isNotEmpty(needExcludeWorkCodeList)) { + // 获取需要去除的人员id + List excludeEmpIds = getSalaryEmployeeService(user).listByWorkCodes(needExcludeWorkCodeList).stream().map(emp -> Utils.null2String(emp.getEmployeeId())).collect(Collectors.toList()); + variableMapList = variableMapList.stream().filter(map -> !excludeEmpIds.contains(Utils.null2String(map.get("employeeId")))).collect(Collectors.toList()); + } + log.info("部门工资奖金明细表实发size afterexclude{} ",variableMapList == null ? 0 : variableMapList.size()); + + // 过滤数据,不能所有值为0或空 + List keyList = configs.stream().map(dto -> dto.getItem() + "_variableItem").collect(Collectors.toList()); + variableMapList = variableMapList.stream().filter(map -> { + for (String key : keyList) { + String val = Utils.null2String(map.get(key)); + if (StringUtils.isNotBlank(val) && NumberUtils.isCreatable(val) && new BigDecimal(val).compareTo(BigDecimal.ZERO) != 0) { + return true; + } + } + return false; + }).collect(Collectors.toList()); + if (CollectionUtils.isEmpty(variableMapList)) { + return null; + } + log.info("部门工资奖金明细表实发size afterexclude2{} ",variableMapList.size()); + List employeeIdList = variableMapList.stream().map(m -> Utils.null2String(m.get("employeeId"))) + .filter(NumberUtils::isCreatable).map(Long::valueOf).collect(Collectors.toList()); + + + // 查询生成的报表映射关系 + String reportConfigStr = baseBean.getPropValue("ltSalaryReport", "bmgzjjmxbsf_ys_config"); + List reportConfigs = JsonUtil.parseList(reportConfigStr, LtSalaryReportConfigDTO.class); + List salaryItemIds = reportConfigs.stream().map(LtSalaryReportConfigDTO::getItem).collect(Collectors.toList()); + List salaryItemList = getSalaryItemService(user).listByIds(salaryItemIds); + // 查询薪资核算结果(包含未归档) + Date salaryMonthDate = SalaryDateUtil.localDateToDate(yearMonth.atDay(1)); + List salaryAcctRecordList = getSalaryAcctRecordService(user).listBySalaryMonth(LocalDateRange.builder().fromDate(salaryMonthDate).endDate(salaryMonthDate).build()); + // 账套范围 + List sobIds = Arrays.stream(baseBean.getPropValue("ltSalaryReport", "bmgzjjmxbsf_sob_ids").split(",")).filter(NumberUtils::isCreatable).map(Long::valueOf).collect(Collectors.toList()); + salaryAcctRecordList = salaryAcctRecordList.stream().filter(sobId -> sobIds.contains(sobId)).collect(Collectors.toList()); + if (CollectionUtils.isEmpty(salaryAcctRecordList)) { + return "success"; + } + List salaryAcctRecordIds = salaryAcctRecordList.stream().map(SalaryAcctRecordPO::getId).collect(Collectors.toList()); + List salaryAcctEmployeeList = getSalaryAcctEmployeeService(user).listBySalaryAcctRecordIdsAndEmployeeIds(salaryAcctRecordIds, employeeIdList); + List employeeList = getSalaryEmployeeService(user).listByIds(employeeIdList); + // 查询薪资核算结果 + List salaryAcctEmpIds = salaryAcctEmployeeList.stream().map(SalaryAcctEmployeePO::getId).collect(Collectors.toList()); + List acctResultList = getSalaryAcctResultService(user).listByAcctEmployeeIdsAndSalaryItemIds(salaryAcctEmpIds, salaryItemIds); + List taxAgentPOS = getTaxAgentService(user).listAll(); + List> acctResultMap = SalaryAcctResultBO.buildTableData(salaryItemList, Collections.emptyList(), employeeList, salaryAcctEmployeeList, + acctResultList, taxAgentPOS, Collections.emptySet(), Collections.emptyMap(), Collections.emptyMap(), false); + Map> acctResultMapByEmpId = SalaryEntityUtil.convert2Map(acctResultMap, m -> Utils.null2String(m.get("employeeId"))); + + // 查询员工薪资档案 + List salaryArchiveList = getSalaryArchiveService(user).listSome(SalaryArchivePO.builder().employeeIds(employeeIdList).build()); + Map archiveIdMap = SalaryEntityUtil.convert2Map(salaryArchiveList, archive -> archive.getTaxAgentId() + "_" + archive.getEmployeeId(), archive -> archive.getId()); + List salaryArchiveIds = salaryArchiveList.stream().map(SalaryArchivePO::getId).collect(Collectors.toList()); + // 查询档案中对应的绩效工资 + Long jdjxItemId = NumberUtils.isCreatable(baseBean.getPropValue("ltSalaryReport", "jdjx_item_id")) ? Long.valueOf(baseBean.getPropValue("ltSalaryReport", "jdjx_item_id")) : 0L; + Date lastDayOfMonth = SalaryDateUtil.getLastDayOfMonth(salaryMonthDate); + List salaryArchiveItemCurrentList = getSalaryArchiveItemService(user).getEffectiveItemListBySalaryMonth(salaryArchiveIds, Collections.singletonList(jdjxItemId), lastDayOfMonth); + Map archiveItemByArchiveId = SalaryEntityUtil.convert2Map(salaryArchiveItemCurrentList, archive -> archive.getSalaryArchiveId()); + + // 查询快照表中人员信息 + Map employeeMap = SalaryEntityUtil.convert2Map(getSalaryEmployeeService(user).snapshot(employeeIdList, SalaryDateUtil.localDateToDate(yearMonth.atDay(1))), DataCollectionEmployee::getEmployeeId); + + // 入库 + // 删除建模数据 + RecordSet rs = new RecordSet(); + rs.execute("delete from uf_bmjjjt where xzszy = '" + salaryMonth+ "'"); + // 插入建模 + String currDate = String.format("'%s'", TimeUtil.getCurrentDateString()); + SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); + String currTime = String.format("'%s'", sdf.format(new Date())); + // 获取建模模块id + String modeId = baseBean.getPropValue("ltSalaryReport", "bmgzjjmxbsf_mode_id"); + // 先插入一条数据 + Map firstData = variableMapList.get(0); + StringBuilder firstSb = new StringBuilder(); + String fieldStr = reportConfigs.stream().map(LtSalaryReportConfigDTO::getField).collect(Collectors.joining(",")); + DataCollectionEmployee employee = employeeMap.getOrDefault(firstData.get("employeeId"), DataCollectionEmployee.builder().build()); + // 获取员工档案绩效工资 + Long archiveId = archiveIdMap.get(Utils.null2String(firstData.get("taxAgentId")) + "_" + employee.getEmployeeId()); + SalaryArchiveItemPO salaryArchiveItemPO = archiveItemByArchiveId.get(archiveId == null ? 0L : archiveId); + String jxgz = (salaryArchiveItemPO == null || !NumberUtils.isCreatable(salaryArchiveItemPO.getItemValue())) ? "0" : new BigDecimal(salaryArchiveItemPO.getItemValue()).divide(new BigDecimal("3"), 2, RoundingMode.HALF_UP).toString(); + // 获取薪资核算结果 + Map singleAcctResultMap = acctResultMapByEmpId.get(Utils.null2String(employee.getEmployeeId())); + firstSb.append("insert into uf_bmjjsf(formmodeid,modedatacreater,modedatacreatertype,modedatacreatedate,modedatacreatetime,gh,xm,bm,gw,xzszy,cbzx,jdjxgzbz3,"+fieldStr+") values ("); + firstSb.append(modeId).append(",1,0,").append(currDate).append(",").append(currTime).append(",'") + .append(employee.getWorkcode()).append("',") + .append(employee.getEmployeeId()).append(",") + .append(employee.getDepartmentId()).append(",") + .append(employee.getJobtitleId()).append(",'") + .append(salaryMonth).append("','") + .append(Utils.null2String(employee.getLtCbzx())).append("',") + .append(jxgz); + + for (LtSalaryReportConfigDTO dto : reportConfigs) { + BigDecimal val = new BigDecimal("0"); + if (singleAcctResultMap != null) { + String valStr = Utils.null2String(singleAcctResultMap.getOrDefault(Utils.null2String(dto.getItem()), "0")); + if (NumberUtils.isCreatable(valStr)) { + val = new BigDecimal(valStr); + } + } + firstSb.append(",").append(val.toPlainString()); + } + firstSb.append(")"); + rs.execute(firstSb.toString()); + variableMapList.remove(0); + // 获取最大值 作为权限重构的起始id + rs.execute("select max(id) from uf_bmjjsf"); + int minId = 0; + if (rs.next()) { + minId = rs.getInt(1); + } + int maxId = minId + variableMapList.size(); + + + List>> partition = Lists.partition(variableMapList, 500); + for (List> part : partition) { + StringBuilder sb = new StringBuilder(); + sb.append("insert into uf_bmjjsf(formmodeid,modedatacreater,modedatacreatertype,modedatacreatedate,modedatacreatetime,gh,xm,bm,gw,xzszy,cbzx,jdjxgzbz3,"+fieldStr+") values "); + for (Map data : part) { + employee = employeeMap.getOrDefault(data.get("employeeId"), DataCollectionEmployee.builder().build()); + // 获取员工档案绩效工资 + archiveId = archiveIdMap.get(Utils.null2String(data.get("taxAgentId")) + "_" + employee.getEmployeeId()); + salaryArchiveItemPO = archiveItemByArchiveId.get(archiveId == null ? 0L : archiveId); + jxgz = (salaryArchiveItemPO == null || !NumberUtils.isCreatable(salaryArchiveItemPO.getItemValue())) ? "0" : new BigDecimal(salaryArchiveItemPO.getItemValue()).divide(new BigDecimal("3"), 2, RoundingMode.HALF_UP).toString(); + // 获取薪资核算结果 + singleAcctResultMap = acctResultMapByEmpId.get(Utils.null2String(employee.getEmployeeId())); + + sb.append("(") + .append(modeId).append(",1,0,").append(currDate).append(",").append(currTime).append(",'") + .append(employee.getWorkcode()).append("',") + .append(employee.getEmployeeId()).append(",") + .append(employee.getDepartmentId()).append(",") + .append(employee.getJobtitleId()).append(",'") + .append(salaryMonth).append("','") + .append(Utils.null2String(employee.getLtCbzx())).append("',") + .append(jxgz); + for (LtSalaryReportConfigDTO dto : reportConfigs) { + BigDecimal val = new BigDecimal("0"); + if (singleAcctResultMap != null) { + String valStr = Utils.null2String(singleAcctResultMap.getOrDefault(Utils.null2String(dto.getItem()), "0")); + if (NumberUtils.isCreatable(valStr)) { + val = new BigDecimal(valStr); + } + } + sb.append(",").append(val.toPlainString()); + } + sb.append("),"); + } + rs.execute(sb.substring(0,sb.length()-1).toString()); + } + // 权限重构 + log.info("部门工资奖金明细表实发min{} max{} ",minId,maxId); + if (modeId != null && NumberUtils.isCreatable(modeId)) { + Integer modeIdValue = Integer.valueOf(modeId); + for (int i = minId; i <= maxId; i++) { + ModeRightInfo ModeRightInfo = new ModeRightInfo(); + ModeRightInfo.setNewRight(true); + ModeRightInfo.editModeDataShare(1, modeIdValue, i); + } + } + return "success"; + } } \ No newline at end of file diff --git a/src/com/engine/salary/service/impl/SalaryArchiveItemServiceImpl.java b/src/com/engine/salary/service/impl/SalaryArchiveItemServiceImpl.java index c5c9879e8..31216c921 100644 --- a/src/com/engine/salary/service/impl/SalaryArchiveItemServiceImpl.java +++ b/src/com/engine/salary/service/impl/SalaryArchiveItemServiceImpl.java @@ -178,6 +178,27 @@ public class SalaryArchiveItemServiceImpl extends Service implements SalaryArchi .collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(f -> f.getSalaryArchiveId() + "-" + f.getSalaryItemId()))), ArrayList::new)); } + @Override + public List getEffectiveItemListBySalaryMonth(Collection salaryArchivesIds, Collection salaryItemIds, Date SalaryMonth) { + // 没有薪资项目时,给个不存在的,否则加载所有不合理 + salaryItemIds = CollectionUtils.isEmpty(salaryItemIds) ? Collections.singletonList(0L) : salaryItemIds; + // 薪资档案id + List salaryArchiveIds = CollectionUtils.isEmpty(salaryArchivesIds) ? Collections.singletonList(0L) : (List) salaryArchivesIds; + + List salaryArchiveItems = Lists.newArrayList(); + List> partition = Lists.partition(Lists.newArrayList(salaryArchiveIds), 999); + Collection finalSalaryItemIds = salaryItemIds; + partition.forEach(part -> salaryArchiveItems.addAll( + salaryArchiveItemMapper.getEffectiveSalaryItems(SalaryArchiveItemQueryParam.builder() + .salaryArchivesIds(part) + .salaryItemIds(finalSalaryItemIds) + .effectiveTime(SalaryMonth).build())) + ); + return salaryArchiveItems.stream() + .collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(f -> f.getSalaryArchiveId() + "-" + f.getSalaryItemId()))), ArrayList::new)); + + } + /** * 获取当前已生效列表 * diff --git a/src/com/engine/salary/service/impl/SalaryEmployeeServiceImpl.java b/src/com/engine/salary/service/impl/SalaryEmployeeServiceImpl.java index 6695dff06..eb4adc1a0 100644 --- a/src/com/engine/salary/service/impl/SalaryEmployeeServiceImpl.java +++ b/src/com/engine/salary/service/impl/SalaryEmployeeServiceImpl.java @@ -697,10 +697,21 @@ public class SalaryEmployeeServiceImpl extends Service implements SalaryEmployee .idNo(hrmSnapshotPO.getCertificatenum()) .accountTypeName(AccountTypeEnum.getDefaultLabelByValue(hrmSnapshotPO.getAccounttype())) .accountType(hrmSnapshotPO.getAccounttype()) + .ltCbzx(hrmSnapshotPO.getLtCbzx()) .build()) .orElse(currentEmployeeMap.get(employeeId)); }).collect(Collectors.toList()); return SalaryI18nUtil.i18nList(employees); } + + @Override + public List listByWorkCodes(List workCodes) { + List empList = new ArrayList<>(); + List> partition = Lists.partition(workCodes, 500); + partition.forEach(part -> { + empList.addAll(getEmployMapper().listByWorkCodes(part)); + }); + return SalaryI18nUtil.i18nList(empList); + } } diff --git a/src/com/engine/salary/service/impl/VariableArchiveItemServiceImpl.java b/src/com/engine/salary/service/impl/VariableArchiveItemServiceImpl.java index b7aff7cae..b613650d5 100644 --- a/src/com/engine/salary/service/impl/VariableArchiveItemServiceImpl.java +++ b/src/com/engine/salary/service/impl/VariableArchiveItemServiceImpl.java @@ -9,6 +9,7 @@ import com.engine.salary.util.db.MapperProxyFactory; import com.google.common.collect.Lists; import org.apache.commons.collections4.CollectionUtils; +import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -84,4 +85,18 @@ public class VariableArchiveItemServiceImpl extends Service implements VariableA partition.forEach(part -> getVariableArchiveItemMapper().deleteByIds(part)); } + + @Override + public List listByVariableArchiveIdsAndItemIds(List variableArchiveIds, List variableItemIds) { + if (CollectionUtils.isEmpty(variableArchiveIds) || CollectionUtils.isEmpty(variableItemIds)) { + return Collections.emptyList(); + } + List> partition = Lists.partition(variableArchiveIds, 200); + List resultList = new ArrayList<>(); + partition.forEach(part -> { + resultList.addAll(getVariableArchiveItemMapper().listSome(VariableArchiveItemPO.builder().variableArchiveIds(part).variableItemIds(variableItemIds).build())); + }); + + return encryptUtil.decryptList(resultList, VariableArchiveItemPO.class); + } } diff --git a/src/com/engine/salary/service/impl/VariableArchiveServiceImpl.java b/src/com/engine/salary/service/impl/VariableArchiveServiceImpl.java index d06b252f1..e362e0afd 100644 --- a/src/com/engine/salary/service/impl/VariableArchiveServiceImpl.java +++ b/src/com/engine/salary/service/impl/VariableArchiveServiceImpl.java @@ -186,6 +186,50 @@ public class VariableArchiveServiceImpl extends Service implements VariableArchi return listMaps; } + public List> buildVariableArchiveData(List variableArchives ,List variableItemIds) { + List variableArchiveIds = variableArchives.stream().map(VariableArchiveListDTO::getId).collect(Collectors.toList()); + // 获取浮动薪资档案所对应的浮动薪资项目数据 + List variableArchiveItemList = getVariableArchiveItemService(user).listByVariableArchiveIdsAndItemIds(variableArchiveIds,variableItemIds); + Map> variableArchiveItemMap = SalaryEntityUtil.group2Map(variableArchiveItemList, VariableArchiveItemPO::getVariableArchiveId); + List> variableArchiveItemData = variableArchives.stream().map(m -> { + Map map = Maps.newHashMap(); + map.put("variableArchiveId", m.getId()); + List variableArchiveItemValuelList = variableArchiveItemMap.getOrDefault(m.getId(), Collections.emptyList()); + variableArchiveItemValuelList.forEach(i -> { + map.put(i.getVariableItemId() + SalaryItemConstant.VARIABLE_ITEM_DYNAMIC_SUFFIX, i.getItemValue()); + }); + return map; + }).collect(Collectors.toList()); + + + // 组装数据 + List> listMaps = new ArrayList<>(); + variableArchives.forEach(e -> { + Map map = new LinkedHashMap<>(); + map.put("id", e.getId()); + map.put("taxAgentName", e.getTaxAgentName()); + map.put("taxAgentId", e.getTaxAgentId()); + map.put("username", e.getUsername()); + map.put("salaryMonth", SalaryDateUtil.getFormatYearMonth(e.getSalaryMonth())); + map.put("employeeId", e.getEmployeeId()); + map.put("subcompanyName", e.getSubcompanyName()); + map.put("departmentName", e.getDepartmentName()); + map.put("mobile", e.getMobile()); + map.put("workcode", e.getWorkcode()); + map.put("idNo", e.getIdNo()); + map.put("companystartdate", e.getCompanystartdate()); + map.put("dismissdate", e.getDismissdate()); + map.put("opts", e.getOpts()); + + // 浮动薪资项目动态 + Optional> optionalItem = variableArchiveItemData.stream().filter(f -> f.get("variableArchiveId").toString().equals(e.getId().toString())).findFirst(); + optionalItem.ifPresent(map::putAll); + + listMaps.add(map); + }); + return listMaps; + } + /** * 创建浮动薪酬档案 * @@ -594,6 +638,23 @@ public class VariableArchiveServiceImpl extends Service implements VariableArchi return buildVariableArchiveData(variableArchiveListDTO); } + @Override + public List> listBySalaryMonthAndItems(YearMonth salaryMonth, List variableItemIds) { + VariableArchiveQueryParam queryParam = VariableArchiveQueryParam.builder() + .salaryMonth(SalaryDateUtil.getFormatYearMonth(salaryMonth)) + .build(); + ValidUtil.doValidator(queryParam); + // 浮动薪酬档案列表 + if (Objects.nonNull(queryParam.getSalaryMonth())) { + queryParam.setSalaryMonthDate(SalaryDateUtil.dateStrToLocalYearMonth(queryParam.getSalaryMonth())); + } + //排序配置 + OrderRuleVO orderRule = getSalarySysConfService(user).orderRule(); + queryParam.setOrderRule(orderRule); + List list = listDTO(queryParam); + return buildVariableArchiveData(list, variableItemIds); + } + @Override public void updateData(VariableArchiveSaveParam updateParam) { if (updateParam.getId() == null) { diff --git a/src/com/engine/salary/timer/HrmSnapshotJob.java b/src/com/engine/salary/timer/HrmSnapshotJob.java index ac0a7a091..7db334222 100644 --- a/src/com/engine/salary/timer/HrmSnapshotJob.java +++ b/src/com/engine/salary/timer/HrmSnapshotJob.java @@ -7,11 +7,15 @@ import com.engine.salary.util.SalaryDateUtil; import com.engine.salary.util.db.IdGenerator; import com.engine.salary.util.db.MapperProxyFactory; import lombok.extern.slf4j.Slf4j; +import weaver.conn.RecordSet; +import weaver.general.BaseBean; import weaver.hrm.User; import weaver.interfaces.schedule.BaseCronJob; +import weaver.wechat.util.Utils; import java.time.LocalDate; import java.util.Date; +import java.util.HashMap; import java.util.List; @Slf4j @@ -32,6 +36,18 @@ public class HrmSnapshotJob extends BaseCronJob { try { List hrmSnapshotPOS = getHrmSnapshotMapper().currentEmpData(); + // 获取联特成本中心数据 + BaseBean baseBean = new BaseBean(); + String cbzxField = baseBean.getPropValue("ltSalaryReport", "cbzx_field_name"); + RecordSet rs = new RecordSet(); + rs.execute("select id,"+cbzxField+" from cus_fielddata where scopeid=3 and "+cbzxField+" != '' "); + HashMap ltCbzxMap = new HashMap<>(); + while (rs.next()) { + ltCbzxMap.put(Long.valueOf(rs.getInt("id")), rs.getString(cbzxField)); + } + hrmSnapshotPOS.stream().forEach(po -> { + po.setLtCbzx(Utils.null2String(ltCbzxMap.get(po.getEmployeeId()))); + }); Date snapshotTime = StrUtil.isNotBlank(appointSnapshotTime) && SalaryDateUtil.checkDay(appointSnapshotTime) ? SalaryDateUtil.dateStrToLocalDate(appointSnapshotTime) : SalaryDateUtil.localDateToDate(LocalDate.now()); diff --git a/src/com/engine/salary/web/SalaryAcctController.java b/src/com/engine/salary/web/SalaryAcctController.java index 9654bafff..a0b854bc5 100644 --- a/src/com/engine/salary/web/SalaryAcctController.java +++ b/src/com/engine/salary/web/SalaryAcctController.java @@ -985,4 +985,81 @@ public class SalaryAcctController { } /**********************************线下对比 end*********************************/ + /**********************************联特 报表start*********************************/ + + /** + * 联特 - 生成部门社保明细表 + * @param request + * @param response + * @param salaryMonth + * @return + */ + @GET + @Path("/ltSalaryReport/genBmsbmxb") + @Produces(MediaType.APPLICATION_JSON) + public String ltGenBmsbmxb(@Context HttpServletRequest request, @Context HttpServletResponse response, @QueryParam(value = "salaryMonth") String salaryMonth) { + User user = HrmUserVarify.getUser(request, response); + return new ResponseResult(user).run(getSalaryAcctResultWrapper(user)::ltGenBmsbmxb, salaryMonth); + } + + /** + * 联特 - 生成部门公积金明细表 + * @param request + * @param response + * @param salaryMonth + * @return + */ + @GET + @Path("/ltSalaryReport/genBmgjjmxb") + @Produces(MediaType.APPLICATION_JSON) + public String ltGenBmgjjmxb(@Context HttpServletRequest request, @Context HttpServletResponse response, @QueryParam(value = "salaryMonth") String salaryMonth) { + User user = HrmUserVarify.getUser(request, response); + return new ResponseResult(user).run(getSalaryAcctResultWrapper(user)::ltGenBmgjjmxb, salaryMonth); + } + + /** + * 联特 - 生成部门工资&奖金明细表-计提 + * @param request + * @param response + * @param salaryMonth + * @return + */ + @GET + @Path("/ltSalaryReport/genBmgzjjmxJt") + @Produces(MediaType.APPLICATION_JSON) + public String ltGenBmgzjjmxJt(@Context HttpServletRequest request, @Context HttpServletResponse response, @QueryParam(value = "salaryMonth") String salaryMonth) { + User user = HrmUserVarify.getUser(request, response); + return new ResponseResult(user).run(getSalaryAcctResultWrapper(user)::ltGenBmgzjjmxJt, salaryMonth); + } + + /** + * 联特 - 生成部门工资&奖金明细表-实发 + * @param request + * @param response + * @param salaryMonth + * @return + */ + @GET + @Path("/ltSalaryReport/genBmgzjjmxSf") + @Produces(MediaType.APPLICATION_JSON) + public String ltGenBmgzjjmxSf(@Context HttpServletRequest request, @Context HttpServletResponse response, @QueryParam(value = "salaryMonth") String salaryMonth) { + User user = HrmUserVarify.getUser(request, response); + return new ResponseResult(user).run(getSalaryAcctResultWrapper(user)::ltGenBmgzjjmxSf, salaryMonth); + } + + // /** + // * 联特表5 - 生成人员明细工资计提表 + // * @param request + // * @param response + // * @param salaryMonth + // * @return + // */ + // @GET + // @Path("/ltSalaryReport/genRymxgzjt") + // @Produces(MediaType.APPLICATION_JSON) + // public String ltGenRymxgzjt(@Context HttpServletRequest request, @Context HttpServletResponse response, @QueryParam(value = "salaryMonth") String salaryMonth) { + // User user = HrmUserVarify.getUser(request, response); + // return new ResponseResult(user).run(getSalaryAcctResultWrapper(user)::ltGenRymxgzjt, salaryMonth); + // } + /**********************************联特 报表end*********************************/ } diff --git a/src/com/engine/salary/wrapper/SalaryAcctResultWrapper.java b/src/com/engine/salary/wrapper/SalaryAcctResultWrapper.java index c2a3d45eb..d66bbf653 100644 --- a/src/com/engine/salary/wrapper/SalaryAcctResultWrapper.java +++ b/src/com/engine/salary/wrapper/SalaryAcctResultWrapper.java @@ -371,4 +371,37 @@ public class SalaryAcctResultWrapper extends Service implements SalaryAcctResult public void calcTaxFeedback(SalaryCalcTaxParam salaryCalcTaxParam) { getSalaryCalcTaxService(user).calcTaxFeedback(salaryCalcTaxParam); } + + /** + * 联特 - 生成部门社保明细表 + * @param salaryMonth + * @return + */ + public String ltGenBmsbmxb(String salaryMonth) { + return getSalaryAcctResultService(user).ltGenBmsbmxb(salaryMonth); + } + + /** + * 联特 - 生成部门公积金明细表 + * @param salaryMonth + */ + public String ltGenBmgjjmxb(String salaryMonth) { + return getSalaryAcctResultService(user).ltGenBmgjjmxb(salaryMonth); + } + + /** + * 联特 - 生成部门工资&奖金明细表-计提 + * @param salaryMonth + */ + public String ltGenBmgzjjmxJt(String salaryMonth) { + return getSalaryAcctResultService(user).ltGenBmgzjjmxJt(salaryMonth); + } + + /** + * 联特 - 生成部门工资&奖金明细表-实发 + * @param salaryMonth + */ + public String ltGenBmgzjjmxSf(String salaryMonth) { + return getSalaryAcctResultService(user).ltGenBmgzjjmxSf(salaryMonth); + } }