From bf75c3831f3bd247ef2de7628aa3f93174e14c58 Mon Sep 17 00:00:00 2001 From: fcli Date: Wed, 9 Nov 2022 15:39:00 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20=E4=B8=80=E9=94=AE=E7=B4=AF=E8=AE=A1?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=97=A5=E6=9C=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../param/AddDeductionAutoAddParam.java | 17 ++++++++++++++ .../salary/service/AddUpDeductionService.java | 2 +- .../impl/AddUpDeductionServiceImpl.java | 10 ++++---- .../salary/web/AddUpDeductionController.java | 23 ++++++++++++++----- .../salary/wrapper/AddUpDeductionWrapper.java | 10 ++++---- 5 files changed, 46 insertions(+), 16 deletions(-) create mode 100644 src/com/engine/salary/entity/datacollection/param/AddDeductionAutoAddParam.java diff --git a/src/com/engine/salary/entity/datacollection/param/AddDeductionAutoAddParam.java b/src/com/engine/salary/entity/datacollection/param/AddDeductionAutoAddParam.java new file mode 100644 index 000000000..ba14a6f02 --- /dev/null +++ b/src/com/engine/salary/entity/datacollection/param/AddDeductionAutoAddParam.java @@ -0,0 +1,17 @@ +package com.engine.salary.entity.datacollection.param; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @description 数据采集-专项附加扣除一键累计参数 + **/ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class AddDeductionAutoAddParam { + String yearMonth = ""; +} diff --git a/src/com/engine/salary/service/AddUpDeductionService.java b/src/com/engine/salary/service/AddUpDeductionService.java index 523495ba5..4876bf723 100644 --- a/src/com/engine/salary/service/AddUpDeductionService.java +++ b/src/com/engine/salary/service/AddUpDeductionService.java @@ -154,5 +154,5 @@ public interface AddUpDeductionService { * @return void * @author lfc */ - void autoAddAll(Date operateTime); + void autoAddAll(Date yearMonth); } diff --git a/src/com/engine/salary/service/impl/AddUpDeductionServiceImpl.java b/src/com/engine/salary/service/impl/AddUpDeductionServiceImpl.java index b29cf4b8e..51f7398ce 100644 --- a/src/com/engine/salary/service/impl/AddUpDeductionServiceImpl.java +++ b/src/com/engine/salary/service/impl/AddUpDeductionServiceImpl.java @@ -641,7 +641,7 @@ public class AddUpDeductionServiceImpl extends Service implements AddUpDeduction } @Override - public void autoAddAll(Date operateTime) { + public void autoAddAll(Date yearMonth) { int uid = user.getUID(); Boolean isChief = getTaxAgentService(user).isChief((long) uid); Collection taxAgents; @@ -677,7 +677,7 @@ public class AddUpDeductionServiceImpl extends Service implements AddUpDeduction addUpDeduction.setEmployeeId(employeeId); addUpDeduction.setTaxAgentId(taxAgent.getId()); - addUpDeduction.setDeclareMonth(DateUtil.beginOfMonth(operateTime)); + addUpDeduction.setDeclareMonth(DateUtil.beginOfMonth(yearMonth)); addUpDeduction.setCreator((long) user.getUID()); addUpDeduction.setTenantKey(DEFAULT_TENANT_KEY); @@ -686,13 +686,13 @@ public class AddUpDeductionServiceImpl extends Service implements AddUpDeduction .flatMap(c -> c.stream().findFirst()) .orElse(null); if (oldInfo == null) { - addUpDeduction.setCreateTime(operateTime); - addUpDeduction.setUpdateTime(operateTime); + addUpDeduction.setCreateTime(yearMonth); + addUpDeduction.setUpdateTime(yearMonth); insertList.add(AddUpDeductionEncrypt.encryptAddUpDeduction(addUpDeduction)); } else { addUpDeduction.setId(oldInfo.getId()); addUpDeduction.setCreateTime(oldInfo.getCreateTime()); - addUpDeduction.setUpdateTime(operateTime); + addUpDeduction.setUpdateTime(yearMonth); updateList.add(AddUpDeductionEncrypt.encryptAddUpDeduction(addUpDeduction)); } }); diff --git a/src/com/engine/salary/web/AddUpDeductionController.java b/src/com/engine/salary/web/AddUpDeductionController.java index d97aaaed3..6cda46630 100644 --- a/src/com/engine/salary/web/AddUpDeductionController.java +++ b/src/com/engine/salary/web/AddUpDeductionController.java @@ -1,13 +1,13 @@ package com.engine.salary.web; +import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.StrUtil; import com.engine.common.util.ParamUtil; import com.engine.common.util.ServiceUtil; import com.engine.salary.entity.datacollection.dto.AddUpDeductionDTO; import com.engine.salary.entity.datacollection.dto.AddUpDeductionRecordDTO; -import com.engine.salary.entity.datacollection.param.AddUpDeductionImportParam; -import com.engine.salary.entity.datacollection.param.AddUpDeductionQueryParam; -import com.engine.salary.entity.datacollection.param.AddUpDeductionRecordDeleteParam; -import com.engine.salary.entity.datacollection.param.AddUpDeductionRecordParam; +import com.engine.salary.entity.datacollection.param.*; import com.engine.salary.util.ResponseResult; import com.engine.salary.util.page.PageInfo; import com.engine.salary.wrapper.AddUpDeductionWrapper; @@ -347,8 +347,19 @@ public class AddUpDeductionController { @POST @Path("/autoAddAll") @Produces(MediaType.APPLICATION_JSON) - public String autoAddAll(@Context HttpServletRequest request, @Context HttpServletResponse response) { + public String autoAddAll(@Context HttpServletRequest request, @Context HttpServletResponse response, + @RequestBody AddDeductionAutoAddParam param) { + DateTime date = null; + if (StrUtil.isNotEmpty(param.getYearMonth())) { + try { + date = DateUtil.parse(param.getYearMonth(), "yyyy-MM"); + } catch (Exception e) { + //ignore 放在service中处理,这里处理了页面上收不到 + } + } else { + date = DateUtil.beginOfMonth(new Date()); + } User user = HrmUserVarify.getUser(request, response); - return new ResponseResult(user).run(getAddUpDeductionWrapper(user)::autoAddAll, user); + return new ResponseResult(user).run(getAddUpDeductionWrapper(user)::autoAddAll, date); } } diff --git a/src/com/engine/salary/wrapper/AddUpDeductionWrapper.java b/src/com/engine/salary/wrapper/AddUpDeductionWrapper.java index b0f57c860..162291cb1 100644 --- a/src/com/engine/salary/wrapper/AddUpDeductionWrapper.java +++ b/src/com/engine/salary/wrapper/AddUpDeductionWrapper.java @@ -25,7 +25,6 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook; import weaver.general.BaseBean; import weaver.hrm.User; -import java.time.LocalDateTime; import java.util.Date; import java.util.List; import java.util.Map; @@ -171,10 +170,13 @@ public class AddUpDeductionWrapper extends Service { return getAddUpDeductionService(user).getAddUpDeduction(param); } - public void autoAddAll(User opt) { + public void autoAddAll(Date yearMonth) { if (isLog) { - log.info("一键累计, 操作人 「{}」", opt.getUsername()); + log.info("一键累计, 操作人 「{}」", user.getUsername()); } - getAddUpDeductionService(user).autoAddAll(new Date()); + if (yearMonth == null) { + throw new SalaryRunTimeException("一键累计传入日期格式错误"); + } + getAddUpDeductionService(user).autoAddAll(yearMonth); } } From 815e37e50ba8cfe2497a3a49ed579458919f6b51 Mon Sep 17 00:00:00 2001 From: fcli Date: Wed, 9 Nov 2022 16:55:00 +0800 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20=E4=B8=80=E9=94=AE=E7=B4=AF=E8=AE=A1?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=97=A5=E6=9C=9F=E4=B8=8E=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../datacollection/AddUpDeductionMapper.java | 7 ++ .../datacollection/AddUpDeductionMapper.xml | 105 +++++++++++++++++- .../service/SpecialAddDeductionService.java | 1 + .../impl/AddUpDeductionServiceImpl.java | 26 +++-- 4 files changed, 131 insertions(+), 8 deletions(-) diff --git a/src/com/engine/salary/mapper/datacollection/AddUpDeductionMapper.java b/src/com/engine/salary/mapper/datacollection/AddUpDeductionMapper.java index 15c1953af..6aedf838c 100644 --- a/src/com/engine/salary/mapper/datacollection/AddUpDeductionMapper.java +++ b/src/com/engine/salary/mapper/datacollection/AddUpDeductionMapper.java @@ -1,4 +1,5 @@ package com.engine.salary.mapper.datacollection; +import java.util.Date; import com.engine.salary.entity.datacollection.AddUpDeduction; import com.engine.salary.entity.datacollection.DataCollectionEmployee; @@ -61,6 +62,8 @@ public interface AddUpDeductionMapper { */ void updateData(@Param("collection") List updateList); + void updateDataAndDeclareMonth(@Param("collection") List updateList); + List recordList(@Param("param") AddUpDeductionQueryParam param); @@ -71,4 +74,8 @@ public interface AddUpDeductionMapper { * @date 2022/10/27 9:54 */ void deleteData(@Param("collection")List longs); + + int countByDeclareAfter(@Param("minDeclareMonth") Date minDeclareMonth, + @Param("maxDeclareMonth") Date maxDeclareMonth, + @Param("taxAgentIds") List taxAgentIds); } \ No newline at end of file diff --git a/src/com/engine/salary/mapper/datacollection/AddUpDeductionMapper.xml b/src/com/engine/salary/mapper/datacollection/AddUpDeductionMapper.xml index e90fdc37a..ebd2b723f 100644 --- a/src/com/engine/salary/mapper/datacollection/AddUpDeductionMapper.xml +++ b/src/com/engine/salary/mapper/datacollection/AddUpDeductionMapper.xml @@ -1,6 +1,24 @@ + + add_up_child_education, + add_up_continuing_education, + add_up_housing_loan_interest, + add_up_housing_rent, + add_up_support_elderly, + create_time, + creator, + declare_month, + delete_type, + employee_id, + id, + tax_agent_id, + tenant_key, + update_time, + add_up_illness_medical, + add_up_infant_care + @@ -553,6 +571,73 @@ + + update hrsa_add_up_deduction + + + + + when id=#{item.id} then #{item.addUpChildEducation} + + + + + + + when id=#{item.id} then #{item.addUpContinuingEducation} + + + + + + + when id=#{item.id} then #{item.addUpHousingLoanInterest} + + + + + + + when id=#{item.id} then #{item.addUpHousingRent} + + + + + + + when id=#{item.id} then #{item.addUpSupportElderly} + + + + + + + when id=#{item.id} then #{item.addUpIllnessMedical} + + + + + + + when id=#{item.id} then #{item.addUpInfantCare} + + + + + + + when id=#{item.id} then #{item.declareMonth} + + + + + where + id in + + #{item.id} + + + - + \ No newline at end of file diff --git a/src/com/engine/salary/service/SpecialAddDeductionService.java b/src/com/engine/salary/service/SpecialAddDeductionService.java index 89ea40b4a..d2f893323 100644 --- a/src/com/engine/salary/service/SpecialAddDeductionService.java +++ b/src/com/engine/salary/service/SpecialAddDeductionService.java @@ -8,6 +8,7 @@ import com.engine.salary.util.page.PageInfo; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import java.time.YearMonth; +import java.util.Date; import java.util.List; import java.util.Map; diff --git a/src/com/engine/salary/service/impl/AddUpDeductionServiceImpl.java b/src/com/engine/salary/service/impl/AddUpDeductionServiceImpl.java index 51f7398ce..6f419efbe 100644 --- a/src/com/engine/salary/service/impl/AddUpDeductionServiceImpl.java +++ b/src/com/engine/salary/service/impl/AddUpDeductionServiceImpl.java @@ -63,9 +63,7 @@ import weaver.hrm.User; import java.io.InputStream; import java.math.BigDecimal; import java.text.SimpleDateFormat; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.YearMonth; +import java.time.*; import java.util.*; import java.util.stream.Collectors; @@ -650,22 +648,36 @@ public class AddUpDeductionServiceImpl extends Service implements AddUpDeduction } else { taxAgents = getTaxAgentService(user).listAllTaxAgentsAsAdmin((long) uid); } + LocalDateTime yearMonthTime = DateUtil.toLocalDateTime(yearMonth); + //设置时间到下一年1月1号 + Instant instant = yearMonthTime.plusYears(1L) + .withMonth(1).withDayOfMonth(1) + .atZone(ZoneOffset.systemDefault()).toInstant(); + Date nextYearStart = Date.from(instant); + int countByDeclareAfter = getAddUpDeductionMapper() + .countByDeclareAfter(yearMonth, nextYearStart, + taxAgents.stream().map(TaxAgentPO::getId).collect(Collectors.toList()) + ); + if (countByDeclareAfter > 0) { + throw new SalaryRunTimeException("无法累计,请检查当前累计年度内该月后是否有累计专项附加扣除记录!"); + } List updateList = new ArrayList<>(); List insertList = new ArrayList<>(); + List errorMessages = new ArrayList<>(); for (TaxAgentPO taxAgent : taxAgents) { Collection employeeIds = getTaxAgentService(user) .listEmployeeIdsInTaxAgent(taxAgent.getId()); List employeePOs = getSpecialAddDeductionService(user) .getSpecialAddDeductionPOByEmployee(null, taxAgent.getId()); + //获取上月员工数据,用于累加 - LocalDateTime lastMonthDateTime = LocalDateTime.now().minusMonths(1); + LocalDateTime lastMonthDateTime = yearMonthTime.minusMonths(1); YearMonth lastMonth = YearMonth.of(lastMonthDateTime.getYear(), lastMonthDateTime.getMonth()); Map> lastEmpInfo = getEmpInfoByYearMonth(taxAgent, employeePOs, lastMonth); //获取当月员工数据,用于更新 - LocalDateTime currentMonthDateTime = LocalDateTime.now(); - YearMonth currentMonth = YearMonth.of(currentMonthDateTime.getYear(), currentMonthDateTime.getMonth()); + YearMonth currentMonth = YearMonth.of(yearMonthTime.getYear(), yearMonthTime.getMonth()); Map> currentEmpInfo = getEmpInfoByYearMonth(taxAgent, employeePOs, currentMonth); employeePOs.forEach(employeePO -> { @@ -700,7 +712,7 @@ public class AddUpDeductionServiceImpl extends Service implements AddUpDeduction Lists.partition(insertList, 100) .forEach(l -> getAddUpDeductionMapper().insertData((List) l)); Lists.partition(updateList, 100) - .forEach(l -> getAddUpDeductionMapper().updateData((List) l)); + .forEach(l -> getAddUpDeductionMapper().updateDataAndDeclareMonth((List) l)); } /** From 63ee9c9b8e02d72794d79f726aeb3f55fee5a59a Mon Sep 17 00:00:00 2001 From: fcli Date: Wed, 9 Nov 2022 18:57:28 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20=E4=B8=80=E9=94=AE=E7=B4=AF=E8=AE=A1?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=97=A5=E6=9C=9F=E4=B8=8E=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../salary/service/AddUpDeductionService.java | 2 +- .../impl/AddUpDeductionServiceImpl.java | 24 +++++++++++++++++-- .../salary/web/AddUpDeductionController.java | 5 ++-- .../salary/wrapper/AddUpDeductionWrapper.java | 4 ++-- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/com/engine/salary/service/AddUpDeductionService.java b/src/com/engine/salary/service/AddUpDeductionService.java index 4876bf723..d65082de7 100644 --- a/src/com/engine/salary/service/AddUpDeductionService.java +++ b/src/com/engine/salary/service/AddUpDeductionService.java @@ -154,5 +154,5 @@ public interface AddUpDeductionService { * @return void * @author lfc */ - void autoAddAll(Date yearMonth); + String autoAddAll(Date yearMonth); } diff --git a/src/com/engine/salary/service/impl/AddUpDeductionServiceImpl.java b/src/com/engine/salary/service/impl/AddUpDeductionServiceImpl.java index 6f419efbe..5311cd699 100644 --- a/src/com/engine/salary/service/impl/AddUpDeductionServiceImpl.java +++ b/src/com/engine/salary/service/impl/AddUpDeductionServiceImpl.java @@ -639,7 +639,7 @@ public class AddUpDeductionServiceImpl extends Service implements AddUpDeduction } @Override - public void autoAddAll(Date yearMonth) { + public String autoAddAll(Date yearMonth) { int uid = user.getUID(); Boolean isChief = getTaxAgentService(user).isChief((long) uid); Collection taxAgents; @@ -663,7 +663,9 @@ public class AddUpDeductionServiceImpl extends Service implements AddUpDeduction } List updateList = new ArrayList<>(); List insertList = new ArrayList<>(); - List errorMessages = new ArrayList<>(); + List errorMessages = new ArrayList<>(); + List accountedEmployeeData = + getAccountedEmployeeData(DateUtil.format(yearMonth, "yyyy-MM")); for (TaxAgentPO taxAgent : taxAgents) { Collection employeeIds = getTaxAgentService(user) .listEmployeeIdsInTaxAgent(taxAgent.getId()); @@ -682,6 +684,15 @@ public class AddUpDeductionServiceImpl extends Service implements AddUpDeduction employeePOs.forEach(employeePO -> { Long employeeId = employeePO.getEmployeeId(); + // 如果该员工当前月份已经核算,不做累计 + SalaryAcctEmployeePO anyAccountedEmployee = accountedEmployeeData.stream() + .filter(e -> e.getEmployeeId().equals(employeeId)) + .filter(e -> e.getTaxAgentId().equals(taxAgent.getId())) + .findAny().orElse(null); + if (anyAccountedEmployee != null) { + errorMessages.add(employeeId); + return; + } AddUpDeduction addUpDeduction = Optional.ofNullable(lastEmpInfo.get(employeeId)) .flatMap(list -> list.stream().findFirst()) .orElseGet(AddUpDeduction::new); @@ -713,6 +724,15 @@ public class AddUpDeductionServiceImpl extends Service implements AddUpDeduction .forEach(l -> getAddUpDeductionMapper().insertData((List) l)); Lists.partition(updateList, 100) .forEach(l -> getAddUpDeductionMapper().updateDataAndDeclareMonth((List) l)); + if (!errorMessages.isEmpty()) { + String userNames = getSalaryEmployeeService(user) + .listByIds(errorMessages) + .stream() + .map(DataCollectionEmployee::getUsername) + .collect(Collectors.joining(",")); + return "一键累计完成!员工" + userNames + "在该年月已核算归档,跳过本次累计"; + } + return "一键累计完成!"; } /** diff --git a/src/com/engine/salary/web/AddUpDeductionController.java b/src/com/engine/salary/web/AddUpDeductionController.java index 6cda46630..5d421153e 100644 --- a/src/com/engine/salary/web/AddUpDeductionController.java +++ b/src/com/engine/salary/web/AddUpDeductionController.java @@ -354,12 +354,13 @@ public class AddUpDeductionController { try { date = DateUtil.parse(param.getYearMonth(), "yyyy-MM"); } catch (Exception e) { - //ignore 放在service中处理,这里处理了页面上收不到 + //ignore + // 放在service中处理,这里处理了页面上收不到 } } else { date = DateUtil.beginOfMonth(new Date()); } User user = HrmUserVarify.getUser(request, response); - return new ResponseResult(user).run(getAddUpDeductionWrapper(user)::autoAddAll, date); + return new ResponseResult(user).run(getAddUpDeductionWrapper(user)::autoAddAll, date); } } diff --git a/src/com/engine/salary/wrapper/AddUpDeductionWrapper.java b/src/com/engine/salary/wrapper/AddUpDeductionWrapper.java index 162291cb1..84c45384e 100644 --- a/src/com/engine/salary/wrapper/AddUpDeductionWrapper.java +++ b/src/com/engine/salary/wrapper/AddUpDeductionWrapper.java @@ -170,13 +170,13 @@ public class AddUpDeductionWrapper extends Service { return getAddUpDeductionService(user).getAddUpDeduction(param); } - public void autoAddAll(Date yearMonth) { + public String autoAddAll(Date yearMonth) { if (isLog) { log.info("一键累计, 操作人 「{}」", user.getUsername()); } if (yearMonth == null) { throw new SalaryRunTimeException("一键累计传入日期格式错误"); } - getAddUpDeductionService(user).autoAddAll(yearMonth); + return getAddUpDeductionService(user).autoAddAll(yearMonth); } }