From c67af6e590c080e0bf0b2e5184a2cdb6e361fa60 Mon Sep 17 00:00:00 2001 From: mashuai Date: Thu, 6 Mar 2025 10:26:16 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A2=86=E6=96=99=E5=87=BA=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/LeaseApplyInfoController.java | 5 +- .../lease/mapper/LeaseApplyDetailsMapper.java | 8 + .../lease/mapper/LeaseApplyInfoMapper.java | 7 + .../lease/service/ILeaseApplyInfoService.java | 3 +- .../impl/LeaseApplyInfoServiceImpl.java | 201 +++++++++++++++++- .../impl/LeaseOutDetailsServiceImpl.java | 20 ++ .../lease/LeaseApplyDetailsMapper.xml | 26 +++ .../material/lease/LeaseApplyInfoMapper.xml | 44 ++++ .../mapper/material/task/TmTaskMapper.xml | 3 + 9 files changed, 310 insertions(+), 7 deletions(-) diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/lease/controller/LeaseApplyInfoController.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/lease/controller/LeaseApplyInfoController.java index b934e9c2..6678296a 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/lease/controller/LeaseApplyInfoController.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/lease/controller/LeaseApplyInfoController.java @@ -73,8 +73,9 @@ public class LeaseApplyInfoController extends BaseController { //@RequiresPermissions("lease:info:query") @GetMapping(value = "/{id}") public AjaxResult getInfo(@NotNull(message = "领料任务ID不能为空") @PathVariable("id") Long id, - @RequestParam(value = "keyWord", required = false) String keyWord) { - return success(leaseApplyInfoService.selectLeaseApplyInfoById(id, keyWord)); + @RequestParam(value = "keyWord", required = false) String keyWord, + @RequestParam(value = "publishTask", required = false) String publishTask) { + return success(leaseApplyInfoService.selectLeaseApplyInfoById(id, keyWord, publishTask)); } /** diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/lease/mapper/LeaseApplyDetailsMapper.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/lease/mapper/LeaseApplyDetailsMapper.java index 78440da0..3dfc236a 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/lease/mapper/LeaseApplyDetailsMapper.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/lease/mapper/LeaseApplyDetailsMapper.java @@ -133,4 +133,12 @@ public interface LeaseApplyDetailsMapper { * @return */ List selectByMaId(Long maId); + + /** + * 根据领料任务id查询领料任务详细 + * @param publishTask + * @return + */ + List getDetailsPublish(String publishTask); + } diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/lease/mapper/LeaseApplyInfoMapper.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/lease/mapper/LeaseApplyInfoMapper.java index bcb23871..92a54f0f 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/lease/mapper/LeaseApplyInfoMapper.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/lease/mapper/LeaseApplyInfoMapper.java @@ -73,4 +73,11 @@ public interface LeaseApplyInfoMapper { /** 设置发料单位 防止代码冲突 **/ String getSendUnit(LeaseApplyInfo leaseApplyInfo); + + /** + * 查询领用出库数据 + * @param leaseApplyInfo + * @return + */ + List selectPublishList(LeaseApplyInfo leaseApplyInfo); } diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/lease/service/ILeaseApplyInfoService.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/lease/service/ILeaseApplyInfoService.java index 149ba088..d60f1e7f 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/lease/service/ILeaseApplyInfoService.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/lease/service/ILeaseApplyInfoService.java @@ -24,9 +24,10 @@ public interface ILeaseApplyInfoService { * * @param id 领料任务主键 * @param keyword keyword 关键字 + * @param publishTask 发布批次 * @return 领料任务 */ - LeaseApplyRequestVo selectLeaseApplyInfoById(Long id, String keyword); + LeaseApplyRequestVo selectLeaseApplyInfoById(Long id, String keyword, String publishTask); /** * 查询领料任务列表 diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/lease/service/impl/LeaseApplyInfoServiceImpl.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/lease/service/impl/LeaseApplyInfoServiceImpl.java index 91d8d122..e9cf8e72 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/lease/service/impl/LeaseApplyInfoServiceImpl.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/lease/service/impl/LeaseApplyInfoServiceImpl.java @@ -80,7 +80,7 @@ public class LeaseApplyInfoServiceImpl implements ILeaseApplyInfoService { * @return 领料任务 */ @Override - public LeaseApplyRequestVo selectLeaseApplyInfoById(Long id, String keyword) { + public LeaseApplyRequestVo selectLeaseApplyInfoById(Long id, String keyword, String publishTask) { try { LeaseApplyInfo leaseApplyInfo = new LeaseApplyInfo(); leaseApplyInfo.setId(id); @@ -125,6 +125,23 @@ public class LeaseApplyInfoServiceImpl implements ILeaseApplyInfoService { } }); + // 走单独的领用详情查询 + if (StringUtils.isNotBlank(publishTask)) { + LeaseApplyRequestVo info = new LeaseApplyRequestVo(); + // 根据领用批次查询领用详情 + List details = leaseApplyDetailsMapper.getDetailsPublish(publishTask); + if (!CollectionUtils.isEmpty(details)) { + for (LeaseApplyDetails detail : details) { + if (detail.getOutNum().compareTo(detail.getAlNum()) == 0) { + detail.setStatus("1"); + } else { + detail.setStatus("0"); + } + } + info.setLeaseApplyDetailsList(details); + } + return info; + } return leaseApplyRequestVo; } catch (Exception e) { @@ -145,16 +162,29 @@ public class LeaseApplyInfoServiceImpl implements ILeaseApplyInfoService { public List selectLeaseApplyInfoList(LeaseApplyInfo leaseApplyInfo) { leaseApplyInfo.setUserId(SecurityUtils.getUserId()); List list = leaseApplyInfoMapper.selectLeaseApplyInfoList(leaseApplyInfo); - if (!CollectionUtils.isEmpty(list)) { + // 如果statusList包含3、4、5,则为领料出库查询,需查询领用出库数据,进行拼接 + if (leaseApplyInfo.getStatusList() != null && leaseApplyInfo.getStatusList().contains(3) + && leaseApplyInfo.getStatusList().contains(4) && leaseApplyInfo.getStatusList().contains(5)) { + // 查询领用出库数据 + List leaseApplyOutList = leaseApplyInfoMapper.selectPublishList(leaseApplyInfo); + if (!CollectionUtils.isEmpty(leaseApplyOutList)) { + list.addAll(leaseApplyOutList); + } + } + // 使用 Stream API 进行降序排序 + List sortedList = list.stream() + .sorted(Comparator.comparing(LeaseApplyInfo::getCreateTime).reversed()) + .collect(Collectors.toList()); + if (!CollectionUtils.isEmpty(sortedList)) { String keyWord = leaseApplyInfo.getKeyWord(); // 如果关键字不为空,进行过滤 if (!StringUtils.isBlank(keyWord)) { - list = list.stream() + sortedList = sortedList.stream() .filter(item -> containsKeyword(item, keyWord)) .collect(Collectors.toList()); } } - return list; + return sortedList; } /** @@ -183,6 +213,59 @@ public class LeaseApplyInfoServiceImpl implements ILeaseApplyInfoService { */ @Override public AjaxResult insertLeaseApplyInfo(LeaseApplyRequestVo leaseApplyRequestVo) { + /*int result = 0; + if (null == leaseApplyRequestVo.getLeaseApplyInfo()) { + return AjaxResult.error("请先填写领料任务信息"); + } + if (CollectionUtil.isEmpty(leaseApplyRequestVo.getLeaseApplyDetailsList())) { + return AjaxResult.error("请先添加领料任务物资明细"); + } + leaseApplyRequestVo.getLeaseApplyInfo().setCreateTime(DateUtils.getNowDate()); + leaseApplyRequestVo.getLeaseApplyInfo().setCreateBy(SecurityUtils.getUsername()); + try { + // 获取 LeaseApplyDetails 列表 + List leaseApplyDetailsList = leaseApplyRequestVo.getLeaseApplyDetailsList(); + for (LeaseApplyDetails applyDetails : leaseApplyDetailsList) { + if (applyDetails.getCompanyId() == null) { + throw new RuntimeException("未知所属公司领料任务,无法操作!"); + } + } + // 按 companyId 进行分组 + Map> groupedByCompanyId = leaseApplyDetailsList.stream() + .collect(Collectors.groupingBy(LeaseApplyDetails::getCompanyId)); + for (Map.Entry> entry : groupedByCompanyId.entrySet()) { + Long key = entry.getKey(); + List details = entry.getValue(); + TmTaskTypeEnum splitType = null; + String taskTypeLabel = null; + // 机具领料任务 + if (key == 101) { + splitType = TmTaskTypeEnum.TM_TASK_JJ_LEASE; + taskTypeLabel = MaterialConstants.JJ_LEASE_TASK_TYPE_LABEL; + // 安全工器具领料任务 + } else if (key == 102) { + splitType = TmTaskTypeEnum.TM_TASK_SAFE_LEASE; + taskTypeLabel = MaterialConstants.AQ_LEASE_TASK_TYPE_LABEL; + // 宏源领料任务 + } else if (key == 309) { + splitType = TmTaskTypeEnum.TM_TASK_HY_LEASE; + taskTypeLabel = MaterialConstants.HY_LEASE_TASK_TYPE_LABEL; + } else { + throw new RuntimeException("未知所属公司领料任务,无法操作!"); + } + result += processLeaseTask(leaseApplyRequestVo, splitType, taskTypeLabel); + if (result > 0) { + return insertPurchaseCheckDetails(details, leaseApplyRequestVo.getLeaseApplyInfo().getId()); + } else { + return AjaxResult.error("新增任务失败,lease_apply_info表插入0条"); + } + } + } catch (DataAccessException e) { + throw new RuntimeException("数据库操作失败:" + e.getMessage()); + } catch (Exception e) { + throw new RuntimeException("新增任务失败:" + e.getMessage()); + } + return AjaxResult.error("新增任务失败");*/ if (null == leaseApplyRequestVo.getLeaseApplyInfo()) { return AjaxResult.error("请先填写领料任务信息"); } @@ -236,6 +319,54 @@ public class LeaseApplyInfoServiceImpl implements ILeaseApplyInfoService { } } + /** + * 处理任务 + * @param leaseApplyRequestVo + * @param splitType + * @param taskTypeLabel + * @return + */ + /*private int processLeaseTask(LeaseApplyRequestVo leaseApplyRequestVo, TmTaskTypeEnum splitType, String taskTypeLabel) { + int thisMonthMaxOrder = tmTaskMapper.getMonthMaxOrderByDate(DateUtils.getCurrentYear(), DateUtils.getCurrentMonth(), + TmTaskTypeEnum.TM_TASK_LEASE.getTaskTypeId()); + String taskCode = genderTaskCode(thisMonthMaxOrder, taskTypeLabel); + + TmTask tmTask = new TmTask(null, TmTaskTypeEnum.TM_TASK_LEASE.getTaskTypeId(), + LeaseTaskStatusEnum.LEASE_TASK_TO_PUBLISHED.getStatus(), + leaseApplyRequestVo.getLeaseApplyInfo().getCompanyId(), thisMonthMaxOrder + 1, taskCode); + tmTask.setCreateTime(DateUtils.getNowDate()); + tmTask.setCreateBy(SecurityUtils.getUsername()); + tmTask.setSplitType(splitType.getTaskTypeId()); + tmTaskMapper.insertTmTask(tmTask); + + TmTaskAgreement tmTaskAgreement = new TmTaskAgreement(tmTask.getTaskId(), leaseApplyRequestVo.getLeaseApplyInfo().getAgreementId()); + tmTaskAgreement.setCreateTime(DateUtils.getNowDate()); + tmTaskAgreement.setCreateBy(SecurityUtils.getUsername()); + tmTaskAgreementMapper.insertTmTaskAgreement(tmTaskAgreement); + + leaseApplyRequestVo.getLeaseApplyInfo().setTaskId(tmTask.getTaskId()); + leaseApplyRequestVo.getLeaseApplyInfo().setCode(taskCode); + + // 设置审批人为默认的董班长 --防止代码冲突 + Long peopleId = leaseApplyInfoMapper.getDirectAuditBy(); + leaseApplyRequestVo.getLeaseApplyInfo().setDirectAuditBy(peopleId); + + int count = leaseApplyInfoMapper.insertLeaseApplyInfo(leaseApplyRequestVo.getLeaseApplyInfo()); + + if (!CollectionUtils.isEmpty(leaseApplyRequestVo.getLeaseApplyInfo().getBmFileInfos())) { + leaseApplyRequestVo.getLeaseApplyInfo().getBmFileInfos().forEach(bmFileInfo -> { + bmFileInfo.setTaskType(2); + bmFileInfo.setTaskId(tmTask.getTaskId()); + bmFileInfo.setModelId(leaseApplyRequestVo.getLeaseApplyInfo().getId()); + bmFileInfo.setFileType(5L); + bmFileInfo.setCreateBy(SecurityUtils.getUsername()); + bmFileInfo.setCreateTime(DateUtils.getNowDate()); + bmFileInfoMapper.insertBmFileInfo(bmFileInfo); + }); + } + return count; + }*/ + /** * 发布任务 * @@ -301,6 +432,12 @@ public class LeaseApplyInfoServiceImpl implements ILeaseApplyInfoService { } } + /** + * 插入领料任务详情数据 + * @param leaseApplyDetailsList + * @param parentId + * @return + */ private AjaxResult insertPurchaseCheckDetails(List leaseApplyDetailsList, Long parentId) { if (!CollectionUtils.isEmpty(leaseApplyDetailsList)) { for (LeaseApplyDetails details : leaseApplyDetailsList) { @@ -325,6 +462,13 @@ public class LeaseApplyInfoServiceImpl implements ILeaseApplyInfoService { * @param thisMonthMaxOrder 当月最大单号 * @return 任务对象 */ + /*private static String genderTaskCode(Integer thisMonthMaxOrder, String taskType) { + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + Date nowDate = DateUtils.getNowDate(); + String format = dateFormat.format(nowDate); + String result = format.replace("-", ""); + return taskType + result + String.format("-%03d", thisMonthMaxOrder + 1); + }*/ private static String genderTaskCode(Integer thisMonthMaxOrder) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date nowDate = DateUtils.getNowDate(); @@ -340,6 +484,7 @@ public class LeaseApplyInfoServiceImpl implements ILeaseApplyInfoService { * @return 结果 */ @Override + @Transactional(rollbackFor = Exception.class) public boolean updateLeaseApplyInfo(LeaseApplyRequestVo leaseApplyRequestVo) { try { // 提取到局部变量中,减少重复代码 @@ -385,6 +530,54 @@ public class LeaseApplyInfoServiceImpl implements ILeaseApplyInfoService { } catch (Exception e) { throw new ServiceException("未知异常: " + e.getMessage()); } + /*try { + int result = 0; + // 提取到局部变量中,减少重复代码 + LeaseApplyInfo leaseApplyInfo = leaseApplyRequestVo.getLeaseApplyInfo(); + if (leaseApplyInfo != null && leaseApplyInfo.getId() != null) { + // 去除创建一个新的数组对象,直接复用 + Long[] ids = {leaseApplyInfo.getId()}; + result = leaseApplyInfoMapper.deleteLeaseApplyInfoByIds(ids); + if (result == 0) { + throw new RuntimeException("删除主要任务失败"); + } + if (CollectionUtil.isNotEmpty(leaseApplyRequestVo.getLeaseApplyDetailsList())) { + // 业务逻辑代码 + result = leaseApplyDetailsMapper.deleteLeaseApplyDetailsByParentIds(ids); + if (result == 0) { + throw new RuntimeException("删除详情任务失败"); + } + } + // 查询是否存在文件 + BmFileInfo fileInfo = new BmFileInfo(); + fileInfo.setTaskId(leaseApplyInfo.getTaskId()); + fileInfo.setModelId(leaseApplyInfo.getId()); + fileInfo.setTaskType(2); + fileInfo.setFileType(5L); + List bmFileInfos = bmFileInfoMapper.selectBmFileInfoList(fileInfo); + // 删除原有数据 + if (!CollectionUtils.isEmpty(bmFileInfos)) { + result = bmFileInfoMapper.deleteBmFileInfoByBizInfo(fileInfo); + if (result == 0) { + throw new RuntimeException("删除文件失败"); + } + } + // 重新走新增逻辑 + AjaxResult ajaxResult = insertLeaseApplyInfo(leaseApplyRequestVo); + if (!ajaxResult.isSuccess()) { + System.err.println(ajaxResult.get("msg")); + throw new RuntimeException("修改新增数据异常"); + } + return true; + } + return false; + } catch (DataAccessException dae) { + throw new ServiceException("数据访问异常: " + dae.getMessage()); + } catch (IllegalArgumentException iae) { + throw new ServiceException("非法参数异常: " + iae.getMessage()); + } catch (Exception e) { + throw new ServiceException("未知异常: " + e.getMessage()); + }*/ } /** diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/lease/service/impl/LeaseOutDetailsServiceImpl.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/lease/service/impl/LeaseOutDetailsServiceImpl.java index 8993fa7d..09ff3a82 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/lease/service/impl/LeaseOutDetailsServiceImpl.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/lease/service/impl/LeaseOutDetailsServiceImpl.java @@ -347,6 +347,26 @@ public class LeaseOutDetailsServiceImpl implements ILeaseOutDetailsService { private int updateTaskStatus(LeaseOutDetails record) { int res = 0; + // 领用任务单独判断 + if (StringUtils.isNotBlank(record.getPublishTask())) { + // 根据领用批次查询领用详情 + boolean isFinished = true; + List details = leaseApplyDetailsMapper.getDetailsPublish(record.getPublishTask()); + if (!CollectionUtils.isEmpty(details)) { + for (LeaseApplyDetails bean : details) { + if (bean.getAlNum().compareTo(bean.getNum()) != 0) { + isFinished = false; + break; + } + } + } + if (isFinished) { + String taskId = leaseApplyInfoMapper.getTaskId(record.getParentId()); + // 领用任务状态改为已完成 + res = tmTaskMapper.updateTaskStatus(taskId, LeaseTaskStatusEnum.LEASE_TASK_FINISHED.getStatus()); + } + return res; + } // 进行状态判断 List leaseApplyDetailsList = leaseApplyDetailsMapper.getByParentId(record.getParentId()); int i = 0; diff --git a/bonus-modules/bonus-material/src/main/resources/mapper/material/lease/LeaseApplyDetailsMapper.xml b/bonus-modules/bonus-material/src/main/resources/mapper/material/lease/LeaseApplyDetailsMapper.xml index 1bf0d718..6c477b35 100644 --- a/bonus-modules/bonus-material/src/main/resources/mapper/material/lease/LeaseApplyDetailsMapper.xml +++ b/bonus-modules/bonus-material/src/main/resources/mapper/material/lease/LeaseApplyDetailsMapper.xml @@ -413,4 +413,30 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" GROUP BY lod.type_id, mm.ma_code ORDER BY lod.create_time DESC + + + diff --git a/bonus-modules/bonus-material/src/main/resources/mapper/material/lease/LeaseApplyInfoMapper.xml b/bonus-modules/bonus-material/src/main/resources/mapper/material/lease/LeaseApplyInfoMapper.xml index 9c9584be..b416c282 100644 --- a/bonus-modules/bonus-material/src/main/resources/mapper/material/lease/LeaseApplyInfoMapper.xml +++ b/bonus-modules/bonus-material/src/main/resources/mapper/material/lease/LeaseApplyInfoMapper.xml @@ -247,4 +247,48 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" left join sys_dept sd on su.dept_id = sd.dept_id and sd.del_flag = 0 where su.user_id = #{directAuditBy} and su.del_flag = 0 + + \ No newline at end of file diff --git a/bonus-modules/bonus-material/src/main/resources/mapper/material/task/TmTaskMapper.xml b/bonus-modules/bonus-material/src/main/resources/mapper/material/task/TmTaskMapper.xml index c83910f6..b044eba1 100644 --- a/bonus-modules/bonus-material/src/main/resources/mapper/material/task/TmTaskMapper.xml +++ b/bonus-modules/bonus-material/src/main/resources/mapper/material/task/TmTaskMapper.xml @@ -16,6 +16,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + @@ -46,6 +47,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" pre_task_id, task_type, + split_type, task_status, `code`, month_order, @@ -59,6 +61,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{preTaskId}, #{taskType}, + #{splitType}, #{taskStatus}, #{code}, #{monthOrder},