From 92b64bf0d8b5519ca3ff33a1019eb76a537136f4 Mon Sep 17 00:00:00 2001 From: aikai Date: Tue, 8 Apr 2025 15:50:11 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat(smartfactory):=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=90=AC=E8=BF=90=E7=BB=84=E5=B7=A5=E8=B5=84=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E6=8C=89=E6=9C=88=E6=90=9C=E7=B4=A2=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 HandlingGroupUserAmountController 中添加 type 参数,用于指定搜索类型 - 在 HandlingGroupUserAmountService 接口中增加 type 参数 - 在 HandlingGroupUserAmountServiceImpl 中实现按类型搜索的逻辑- 更新 HandlingGroupUserAmountMapper.xml 中的 SQL 语句,修正工厂 ID 的查询条件 --- .../HandlingGroupUserAmountController.java | 6 ++++-- .../HandlingGroupUserAmountService.java | 2 +- .../HandlingGroupUserAmountServiceImpl.java | 16 +++++++++++----- .../HandlingGroupUserAmountMapper.xml | 2 +- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/zn-module-smartfactory/zn-module-smartfactory-biz/src/main/java/cn/iocoder/yudao/module/smartfactory/controller/admin/handlinggroupuseramount/HandlingGroupUserAmountController.java b/zn-module-smartfactory/zn-module-smartfactory-biz/src/main/java/cn/iocoder/yudao/module/smartfactory/controller/admin/handlinggroupuseramount/HandlingGroupUserAmountController.java index 88ac1e6c..62ed18d3 100644 --- a/zn-module-smartfactory/zn-module-smartfactory-biz/src/main/java/cn/iocoder/yudao/module/smartfactory/controller/admin/handlinggroupuseramount/HandlingGroupUserAmountController.java +++ b/zn-module-smartfactory/zn-module-smartfactory-biz/src/main/java/cn/iocoder/yudao/module/smartfactory/controller/admin/handlinggroupuseramount/HandlingGroupUserAmountController.java @@ -68,11 +68,13 @@ public class HandlingGroupUserAmountController { @GetMapping("/getListByMonth") @Operation(summary = "获得搬运组工资记录 按月搜索") @Parameter(name = "time", description = "日期 格式(yyyy-MM) 默认当前月", required = true, example = "1024") + @Parameter(name = "type", description = "类型 1按本月初到本月底 2按上月26号到本月25号 默认1", required = true, example = "1024") public CommonResult getListByMonth(@RequestParam(value = "id", required = false) Long id, + @RequestParam(value = "type", defaultValue = "1") Integer type, @RequestParam(value = "name", required = false) String name, - @RequestParam(value = "time", required = true) String time, + @RequestParam(value = "time") String time, @RequestParam(value = "factoryId", required = false) Long factoryId) { - HandlingGroupUserAmountMonthVO vo = handlingGroupUserAmountService.getListByMonth(id, factoryId, time, name); + HandlingGroupUserAmountMonthVO vo = handlingGroupUserAmountService.getListByMonth(id, factoryId, type, time, name); return success(vo); } diff --git a/zn-module-smartfactory/zn-module-smartfactory-biz/src/main/java/cn/iocoder/yudao/module/smartfactory/service/handlinggroupuseramount/HandlingGroupUserAmountService.java b/zn-module-smartfactory/zn-module-smartfactory-biz/src/main/java/cn/iocoder/yudao/module/smartfactory/service/handlinggroupuseramount/HandlingGroupUserAmountService.java index 750a2961..9c6b5ecf 100644 --- a/zn-module-smartfactory/zn-module-smartfactory-biz/src/main/java/cn/iocoder/yudao/module/smartfactory/service/handlinggroupuseramount/HandlingGroupUserAmountService.java +++ b/zn-module-smartfactory/zn-module-smartfactory-biz/src/main/java/cn/iocoder/yudao/module/smartfactory/service/handlinggroupuseramount/HandlingGroupUserAmountService.java @@ -78,5 +78,5 @@ public interface HandlingGroupUserAmountService { * @param name * @return */ - HandlingGroupUserAmountMonthVO getListByMonth(Long id, Long factoryId, String time, String name); + HandlingGroupUserAmountMonthVO getListByMonth(Long id, Long factoryId, Integer type, String time, String name); } diff --git a/zn-module-smartfactory/zn-module-smartfactory-biz/src/main/java/cn/iocoder/yudao/module/smartfactory/service/handlinggroupuseramount/HandlingGroupUserAmountServiceImpl.java b/zn-module-smartfactory/zn-module-smartfactory-biz/src/main/java/cn/iocoder/yudao/module/smartfactory/service/handlinggroupuseramount/HandlingGroupUserAmountServiceImpl.java index c0de196b..f1a50f3e 100644 --- a/zn-module-smartfactory/zn-module-smartfactory-biz/src/main/java/cn/iocoder/yudao/module/smartfactory/service/handlinggroupuseramount/HandlingGroupUserAmountServiceImpl.java +++ b/zn-module-smartfactory/zn-module-smartfactory-biz/src/main/java/cn/iocoder/yudao/module/smartfactory/service/handlinggroupuseramount/HandlingGroupUserAmountServiceImpl.java @@ -88,14 +88,21 @@ public class HandlingGroupUserAmountServiceImpl implements HandlingGroupUserAmou } @Override - public HandlingGroupUserAmountMonthVO getListByMonth(Long id, Long factoryId, String time, String name) { + public HandlingGroupUserAmountMonthVO getListByMonth(Long id, Long factoryId, Integer type, String time, String name) { HandlingGroupUserAmountMonthVO vo = new HandlingGroupUserAmountMonthVO(); Map headers = new HashMap<>(); // -- 根据yyyy-MM获取到该月第一天时间 - 再获取到最后一天 - 完了后组装表头 String[] times = time.split("-"); - LocalDateTime startTime = LocalDateTime.of(Integer.parseInt(times[0]), Integer.parseInt(times[1]), 1, 0, 0, 0); - LocalDateTime endTime = startTime.plusMonths(1).minusDays(1); - List dateList = DateUtils.betweenDayList(startTime, endTime); + List dateList; + if (type == 1) { + LocalDateTime startTime = LocalDateTime.of(Integer.parseInt(times[0]), Integer.parseInt(times[1]), 1, 0, 0, 0); + LocalDateTime endTime = startTime.plusMonths(1).minusDays(1); + dateList = DateUtils.betweenDayList(startTime, endTime); + } else { + LocalDateTime startTime = LocalDateTime.of(Integer.parseInt(times[0]), Integer.parseInt(times[1]), 26, 0, 0, 0).minusMonths(1); + LocalDateTime endTime = LocalDateTime.of(Integer.parseInt(times[0]), Integer.parseInt(times[1]), 25, 0, 0, 0); + dateList = DateUtils.betweenDayList(startTime, endTime); + } headers.put(1, NAME); int num = 1; for (String date : dateList) { @@ -105,7 +112,6 @@ public class HandlingGroupUserAmountServiceImpl implements HandlingGroupUserAmou headers.put(num + 1, TOTAL_AMOUNT); // - 插入表头 vo.setHeaders(headers); - List> map = handlingGroupUserAmountMapper.getListByMonth(id, factoryId, dateList, name); List list = new ArrayList<>(); for (Map item : map) { diff --git a/zn-module-smartfactory/zn-module-smartfactory-biz/src/main/resources/mapper/handlinggroupuseramount/HandlingGroupUserAmountMapper.xml b/zn-module-smartfactory/zn-module-smartfactory-biz/src/main/resources/mapper/handlinggroupuseramount/HandlingGroupUserAmountMapper.xml index 7ec601fb..6e109881 100644 --- a/zn-module-smartfactory/zn-module-smartfactory-biz/src/main/resources/mapper/handlinggroupuseramount/HandlingGroupUserAmountMapper.xml +++ b/zn-module-smartfactory/zn-module-smartfactory-biz/src/main/resources/mapper/handlinggroupuseramount/HandlingGroupUserAmountMapper.xml @@ -89,7 +89,7 @@ and b.id = #{id} - and a.factory_id = #{factoryId} + and b.factory_id = #{factoryId} and b.nick_name like concat('%', #{name}, '%') From ac246bd6c2a7b6ef4897d1185853cf75bb2e01bf Mon Sep 17 00:00:00 2001 From: aikai Date: Tue, 8 Apr 2025 16:27:05 +0800 Subject: [PATCH 2/2] =?UTF-8?q?refactor(zn-module-smartfactory):=20?= =?UTF-8?q?=E9=87=8D=E6=9E=84=20HandlingGroupUserAmountServiceImpl=20?= =?UTF-8?q?=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 提取常量:将 userId、nickName 和 totalAmount 提取为类常量 - 优化代码可读性:使用常量替换硬编码字符串 --- .../HandlingGroupUserAmountServiceImpl.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/zn-module-smartfactory/zn-module-smartfactory-biz/src/main/java/cn/iocoder/yudao/module/smartfactory/service/handlinggroupuseramount/HandlingGroupUserAmountServiceImpl.java b/zn-module-smartfactory/zn-module-smartfactory-biz/src/main/java/cn/iocoder/yudao/module/smartfactory/service/handlinggroupuseramount/HandlingGroupUserAmountServiceImpl.java index f1a50f3e..7ef6de3e 100644 --- a/zn-module-smartfactory/zn-module-smartfactory-biz/src/main/java/cn/iocoder/yudao/module/smartfactory/service/handlinggroupuseramount/HandlingGroupUserAmountServiceImpl.java +++ b/zn-module-smartfactory/zn-module-smartfactory-biz/src/main/java/cn/iocoder/yudao/module/smartfactory/service/handlinggroupuseramount/HandlingGroupUserAmountServiceImpl.java @@ -37,6 +37,10 @@ public class HandlingGroupUserAmountServiceImpl implements HandlingGroupUserAmou private HandlingGroupAmountSpecificationsMapper handlingGroupAmountSpecificationsMapper; private static final String NAME = "姓名"; private static final String TOTAL_AMOUNT = "总金额"; + // 提取常量 + private static final String USER_ID = "userId"; + private static final String NICK_NAME = "nickName"; + private static final String TOTAL_AMOUNT_EN = "totalAmount"; @Override public Long createHandlingGroupUserAmount(HandlingGroupUserAmountSaveReqVO createReqVO) { @@ -116,15 +120,15 @@ public class HandlingGroupUserAmountServiceImpl implements HandlingGroupUserAmou List list = new ArrayList<>(); for (Map item : map) { HandlingGroupUserAmountMonthItemVO itemVO = new HandlingGroupUserAmountMonthItemVO(); - itemVO.setUserId((Long) item.get("userId")); + itemVO.setUserId((Long) item.get(USER_ID)); Map itemMap = new HashMap<>(); - itemMap.put(1, item.get("nickName").toString()); + itemMap.put(1, item.get(NICK_NAME).toString()); num = 1; for (String date : dateList) { num++; itemMap.put(num, item.get(date).toString()); } - itemMap.put(num + 1, item.get("totalAmount").toString()); + itemMap.put(num + 1, item.get(TOTAL_AMOUNT_EN).toString()); itemVO.setContentList(itemMap); list.add(itemVO); }