From 8d9b7ccfa3028d4fd3122cec245c116ec8a1124c Mon Sep 17 00:00:00 2001 From: hayu <1604366271@qq.com> Date: Tue, 26 Aug 2025 22:33:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/DirectRotationController.java | 9 + .../ma/service/DirectRotationService.java | 6 + .../ma/service/impl/DirectRotationImpl.java | 369 ++++++++++++++++++ 3 files changed, 384 insertions(+) diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/controller/DirectRotationController.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/controller/DirectRotationController.java index fe75b2e9..3878c003 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/controller/DirectRotationController.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/controller/DirectRotationController.java @@ -73,6 +73,15 @@ public class DirectRotationController extends BaseController { } } + /** + * 直转提交 + */ + @ApiOperation(value = "直转提交") + @PostMapping("/submitNew") + public AjaxResult submitNew(@RequestBody DirectApplyInfoDetails directApplyInfoDetails) { + return service.submitNew(directApplyInfoDetails); + } + /** * 修改直转申请 */ diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/service/DirectRotationService.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/service/DirectRotationService.java index 2b2c8345..72cf6d18 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/service/DirectRotationService.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/service/DirectRotationService.java @@ -73,4 +73,10 @@ public interface DirectRotationService { */ AjaxResult getTypeNameList(SltAgreementInfo bean); + /** + * 直转提交 + * @param directApplyInfoDetails + * @return + */ + AjaxResult submitNew(DirectApplyInfoDetails directApplyInfoDetails); } diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/service/impl/DirectRotationImpl.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/service/impl/DirectRotationImpl.java index f7af8fb6..5d2cf44b 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/service/impl/DirectRotationImpl.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/service/impl/DirectRotationImpl.java @@ -1,13 +1,35 @@ package com.bonus.material.ma.service.impl; +import cn.hutool.core.collection.CollectionUtil; +import com.alibaba.nacos.common.utils.CollectionUtils; +import com.bonus.common.biz.constant.MaterialConstants; +import com.bonus.common.biz.domain.lease.LeaseApplyInfo; +import com.bonus.common.biz.domain.lease.LeaseOutDetails; +import com.bonus.common.biz.enums.BackTaskStatusEnum; +import com.bonus.common.biz.enums.LeaseTaskStatusEnum; +import com.bonus.common.biz.enums.TmTaskTypeEnum; +import com.bonus.common.core.utils.DateUtils; import com.bonus.common.core.web.domain.AjaxResult; import com.bonus.common.security.utils.SecurityUtils; +import com.bonus.material.back.domain.BackApplyDetails; +import com.bonus.material.back.domain.BackApplyInfo; +import com.bonus.material.back.mapper.BackApplyInfoMapper; import com.bonus.material.event.InsertWorkflowEvent; +import com.bonus.material.lease.domain.LeaseApplyDetails; +import com.bonus.material.lease.mapper.LeaseApplyDetailsMapper; +import com.bonus.material.lease.mapper.LeaseApplyInfoMapper; +import com.bonus.material.lease.mapper.LeaseOutDetailsMapper; import com.bonus.material.ma.domain.*; import com.bonus.material.ma.mapper.DirectRotationMapper; +import com.bonus.material.ma.mapper.TypeMapper; import com.bonus.material.ma.service.DirectRotationService; import com.bonus.material.ma.service.WorkSiteDirectManageService; import com.bonus.material.settlement.domain.SltAgreementInfo; +import com.bonus.material.settlement.mapper.SltAgreementInfoMapper; +import com.bonus.material.task.domain.TmTask; +import com.bonus.material.task.domain.TmTaskAgreement; +import com.bonus.material.task.mapper.TmTaskAgreementMapper; +import com.bonus.material.task.mapper.TmTaskMapper; import com.bonus.material.work.domain.SysWorkflowRecord; import com.bonus.material.work.domain.SysWorkflowRecordHistory; import com.bonus.material.work.mapper.SysWorkflowRecordHistoryMapper; @@ -19,14 +41,17 @@ import org.springframework.context.ApplicationEventPublisher; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; +import org.springframework.transaction.interceptor.TransactionAspectSupport; import org.springframework.transaction.support.TransactionSynchronization; import org.springframework.transaction.support.TransactionSynchronizationAdapter; import org.springframework.transaction.support.TransactionSynchronizationManager; import javax.annotation.Resource; import javax.sql.DataSource; +import java.math.BigDecimal; import java.sql.Connection; import java.sql.SQLException; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -60,6 +85,33 @@ public class DirectRotationImpl implements DirectRotationService { @Resource private DataSource dataSource; + @Resource + private TypeMapper typeMapper; + + @Resource + private TmTaskMapper taskMapper; + + @Resource + private TmTaskMapper tmTaskMapper; + + @Resource + private TmTaskAgreementMapper taskAgreementMapper; + + @Resource + private LeaseApplyInfoMapper leaseApplyInfoMapper; + + @Resource + private LeaseApplyDetailsMapper leaseApplyDetailsMapper; + + @Resource + private BackApplyInfoMapper backApplyInfoMapper; + + @Resource + private LeaseOutDetailsMapper leaseOutDetailsMapper; + + @Resource + private SltAgreementInfoMapper sltAgreementInfoMapper; + @Resource private ApplicationEventPublisher applicationEventPublisher; @@ -261,4 +313,321 @@ public class DirectRotationImpl implements DirectRotationService { return AjaxResult.success(list); } + @Override + @Transactional(rollbackFor = Exception.class) + public AjaxResult submitNew(DirectApplyInfoDetails directApplyInfoDetails) { + try { + if (directApplyInfoDetails != null && directApplyInfoDetails.getDirectApplyInfo() != null && directApplyInfoDetails.getDirectApplyInfoDetails() != null) { + DirectApplyInfo directApplyInfos = directApplyInfoDetails.getDirectApplyInfo(); + if (directApplyInfos.getBackAgreementId()==directApplyInfos.getLeaseAgreementId()){ + return AjaxResult.error("直转失败,不能转入同单位同工程"); + } + String code = workSiteDirectManageService.genderLeaseCode(); + directApplyInfos.setCode(code); + directApplyInfos.setCreateTime(new Date()); + List urls = new ArrayList<>(); + if (directApplyInfoDetails.getDirectApplyInfo().getDirUrls() != null) { + List dirUrls = directApplyInfoDetails.getDirectApplyInfo().getDirUrls(); + for (DirectApplyUrl dirUrl : dirUrls){ + urls.add(dirUrl.getUrl()); + } + //将urls所有内容用逗号拼接 + directApplyInfos.setDirUrl(String.join(",", urls)); + } + directApplyInfos.setCreateBy(SecurityUtils.getLoginUser().getUserid().toString()); + //将数据插入直转表direct_apply_info + int res = workSiteDirectManageService.saveDirectApplyInfo(directApplyInfos); + int id =directApplyInfos.getId(); + List directApplyDetails = directApplyInfoDetails.getDirectApplyInfoDetails(); + //插入直转详情表direct_apply_details + for (DirectApplyDetails directApplyDetail : directApplyDetails) { + directApplyDetail.setDirectId(id); + int i = workSiteDirectManageService.saveDirectApplyDetails(directApplyDetail); + } + + + //以下走退料、领料方法 + SltAgreementInfo sltAgreementInfo = new SltAgreementInfo(); + sltAgreementInfo.setId(Long.valueOf(id)); + DirectApplyInfo info = mapper.getInfoById(sltAgreementInfo); + BackApplyInfo backApplyInfo = new BackApplyInfo(); + if (info != null) { + backApplyInfo.setAgreementId(Long.valueOf(info.getBackAgreementId())); + backApplyInfo.setBackPerson(info.getBackMan()); + backApplyInfo.setPhone(info.getBackPhone()); + } + List detailById = mapper.getDetailById(sltAgreementInfo); + List list = mapper.selectDetails(sltAgreementInfo); + int thisMonthMaxOrder = taskMapper.getMonthMaxOrderByDate(DateUtils.getCurrentYear(), DateUtils.getCurrentMonth(), TmTaskTypeEnum.TM_TASK_BACK.getTaskTypeId()); + String codes = genderTaskCode(thisMonthMaxOrder); + TmTask task = new TmTask(null, TmTaskTypeEnum.TM_TASK_BACK.getTaskTypeId(), + BackTaskStatusEnum.BACK_TASK_IN_FINISHED.getStatus(), + null,thisMonthMaxOrder + 1, codes); + task.setCreateTime(DateUtils.getNowDate()); + task.setCreateBy(SecurityUtils.getUsername()); + backApplyInfo.setCode(codes); + backApplyInfo.setCreateBy(SecurityUtils.getUsername()); + backApplyInfo.setCreateTime(DateUtils.getNowDate()); + // 保存退料信息到 tm_task 表中 + int result = 0; + result = taskMapper.insertTmTask(task); + // 新增退料表back_apply_info信息 + result = getBackInfoResult(info, backApplyInfo, task, result); + if (result > 0) { + // 保存退料详情数据 back_apply_details + result = getBackDetailsResult(backApplyInfo, list, result); + // 保存退料详情数据 back_check_details + extractedCheckDetails(backApplyInfo, detailById, result); + } + // 审核通过,处理转入单位领料逻辑 + int maxOrderByDate = tmTaskMapper.getMonthMaxOrderByDate(DateUtils.getCurrentYear(), DateUtils.getCurrentMonth(), TmTaskTypeEnum.TM_TASK_LEASE.getTaskTypeId()); + String taskCode = genderLeaseTaskCode(maxOrderByDate); + TmTask tmTask1 = new TmTask(null, TmTaskTypeEnum.TM_TASK_LEASE.getTaskTypeId(), + LeaseTaskStatusEnum.LEASE_TASK_FINISHED.getStatus(),null + ,maxOrderByDate + 1, taskCode); + tmTask1.setCreateTime(DateUtils.getNowDate()); + tmTask1.setCreateBy(SecurityUtils.getUsername()); + tmTaskMapper.insertTmTask(tmTask1); + TmTaskAgreement tmTaskAgreement = new TmTaskAgreement(tmTask1.getTaskId(), Long.valueOf(info.getLeaseAgreementId())); + tmTaskAgreement.setCreateTime(DateUtils.getNowDate()); + tmTaskAgreement.setCreateBy(SecurityUtils.getUsername()); + taskAgreementMapper.insertTmTaskAgreement(tmTaskAgreement); + /** 设置审批人为默认的董班长 --防止代码冲突 **/ + Long peopleId = leaseApplyInfoMapper.getDirectAuditBy(); + LeaseApplyInfo applyInfo = new LeaseApplyInfo(); + applyInfo.setDirectAuditBy(peopleId); + applyInfo.setCode(taskCode); + applyInfo.setTaskId(tmTask1.getTaskId()); + applyInfo.setLeasePerson(info.getLeaseMan()); + applyInfo.setPhone(info.getLeasePhone()); + applyInfo.setCreateBy(SecurityUtils.getUsername()); + applyInfo.setCreateTime(DateUtils.getNowDate()); + /** 设置审批人为默认的董班长 --防止代码冲突 **/ + int count = leaseApplyInfoMapper.insertLeaseApplyInfo(applyInfo); + if (count > 0) { + // 新增lease_apply_details表数据 + count = getLeaseApplyCount(list, applyInfo, count); + // 插入 lease_out_details表数据 + if (count > 0) { + extracted(sltAgreementInfo, info, detailById, applyInfo); + } + } + + return AjaxResult.success("直转成功"); + + } else { + return AjaxResult.error("直转失败,数据为空"); + } + } catch (Exception e) { + e.printStackTrace(); + log.error("直转失败:" + e.getMessage()); + TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); + return AjaxResult.error("直转失败"); + } + } + + + /** + * 生成退料单号 + * @param thisMonthMaxOrder 当前月份最大单号 + * @return + */ + private String genderTaskCode(int thisMonthMaxOrder) { + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + Date nowDate = DateUtils.getNowDate(); + String format = dateFormat.format(nowDate); + String result = format.replace("-", ""); + return MaterialConstants.BACK_TASK_TYPE_LABEL + result + String.format("-%03d", thisMonthMaxOrder + 1); + } + + /** + * 新增退料信息 + * @param info + * @param backApplyInfo + * @param task + * @param result + * @return + */ + private int getBackInfoResult(DirectApplyInfo info, BackApplyInfo backApplyInfo, TmTask task, int result) { + if (result > 0) { + TmTaskAgreement tmTaskAgreement = new TmTaskAgreement(task.getTaskId(), Long.valueOf(info.getBackAgreementId())); + tmTaskAgreement.setCreateTime(DateUtils.getNowDate()); + tmTaskAgreement.setCreateBy(SecurityUtils.getLoginUser().getSysUser().getNickName()); + taskAgreementMapper.insertTmTaskAgreement(tmTaskAgreement); + backApplyInfo.setTaskId(task.getTaskId()); + /** 设置审批人为默认的李勇 --防止代码冲突 **/ + Long peopleId = backApplyInfoMapper.getDirectAuditBy(); + backApplyInfo.setDirectAuditBy(peopleId); + /** 设置审批人为默认的李勇 --防止代码冲突 **/ + result += backApplyInfoMapper.insertBackApplyInfo(backApplyInfo); + } + return result; + } + + /** + * 新增退料详情back_apply_details表信息 + * @param backApplyInfo + * @param list + * @param result + * @return + */ + private int getBackDetailsResult(BackApplyInfo backApplyInfo, List list, int result) { + if (CollectionUtil.isNotEmpty(list)) { + for (DirectApplyDetails directApplyDetails : list) { + BackApplyDetails details = new BackApplyDetails(); + details.setCode(backApplyInfo.getCode()); + details.setParentId(backApplyInfo.getId()); + details.setPreNum(directApplyDetails.getDirectNum()); + details.setAuditNum(directApplyDetails.getDirectNum()); + details.setNum(directApplyDetails.getUseNum() == null ? + BigDecimal.ZERO : BigDecimal.valueOf(directApplyDetails.getUseNum())); + details.setStatus(String.valueOf(BackTaskStatusEnum.BACK_TASK_IN_FINISHED.getStatus())); + details.setCreateBy(SecurityUtils.getLoginUser().getSysUser().getNickName()); + details.setCreateTime(DateUtils.getNowDate()); + details.setTypeId(Long.valueOf(directApplyDetails.getTypeId())); + // 保存退料详情 + result += backApplyInfoMapper.insertBackApplyDetails(details); + } + } + return result; + } + + /** + * 保存退料详情数据 back_check_details + * @param backApplyInfo + * @param detailById + * @param result + */ + private void extractedCheckDetails(BackApplyInfo backApplyInfo, List detailById, int result) { + if (CollectionUtil.isNotEmpty(detailById)) { + for (DirectApplyDetails directApplyDetails : detailById) { + BackApplyDetails details = new BackApplyDetails(); + details.setParentId(backApplyInfo.getId()); + details.setTypeId(Long.valueOf(directApplyDetails.getTypeId())); + details.setCreateBy(SecurityUtils.getLoginUser().getSysUser().getNickName()); + details.setCreateTime(DateUtils.getNowDate()); + details.setPreNum(directApplyDetails.getDirectNum()); + details.setMaId(directApplyDetails.getMaId() == null ? + null : Long.valueOf(directApplyDetails.getMaId())); + details.setBackStatus("0"); + details.setStatus("2"); + details.setIsFinished(1); + // 插入 CheckDetails + result += backApplyInfoMapper.insertCheckDetails(details); + // 更新结算表信息 + BackApplyInfo bean = new BackApplyInfo(); + bean.setAgreementId(directApplyDetails.getBackAgreementId()); + bean.setTypeId(directApplyDetails.getTypeId().toString()); + bean.setMaId(directApplyDetails.getMaId() == null ? + null : Long.valueOf(directApplyDetails.getMaId())); + List infoList = backApplyInfoMapper.getStlInfo(bean); + BigDecimal backNum = directApplyDetails.getDirectNum(); + if (CollectionUtils.isNotEmpty(infoList)) { + for (SltAgreementInfo agreementInfo : infoList) { + BigDecimal num = agreementInfo.getBackNum(); + if (backNum.compareTo(num) == 0) { + backApplyInfoMapper.updateStlInfo(agreementInfo, backApplyInfo); + break; + } else if (backNum.compareTo(num) > 0) { + backNum = backNum.subtract(num); + backApplyInfoMapper.updateStlInfo(agreementInfo, backApplyInfo); + } else { + BigDecimal many = num.subtract(backNum); + backApplyInfoMapper.updateStlInfoTwo(agreementInfo, backApplyInfo, backNum); + backApplyInfoMapper.insStlInfoTwo(agreementInfo, many); + break; + } + } + } + } + } + } + + /** + * 生成领料任务单号 + * @param thisMonthMaxOrder 当前月份最大单号 + * @return 领料单号,例:L202101xxxxxx + */ + private static String genderLeaseTaskCode(Integer thisMonthMaxOrder) { + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + Date nowDate = DateUtils.getNowDate(); + String format = dateFormat.format(nowDate); + String result = format.replace("-", ""); + return MaterialConstants.LEASE_TASK_TYPE_LABEL + result + String.format("-%03d", thisMonthMaxOrder + 1); + } + + /** + * 新增lease_apply_details表数据 + * @param list + * @param applyInfo + * @param count + * @return + */ + private int getLeaseApplyCount(List list, LeaseApplyInfo applyInfo, int count) { + if (CollectionUtil.isNotEmpty(list)) { + List leaseApplyDetails = new ArrayList<>(); + for (DirectApplyDetails directApplyDetails : list) { + LeaseApplyDetails details = new LeaseApplyDetails(); + details.setParentId(applyInfo.getId()); + details.setCreateTime(DateUtils.getNowDate()); + details.setCreateBy(SecurityUtils.getLoginUser().getSysUser().getNickName()); + details.setTypeId(Long.valueOf(directApplyDetails.getTypeId())); + details.setPreNum(directApplyDetails.getDirectNum()); + details.setAlNum(directApplyDetails.getDirectNum()); + details.setStatus("2"); + leaseApplyDetails.add(details); + } + // 批量插入详情数据 + if (CollectionUtil.isNotEmpty(leaseApplyDetails)) { + count = leaseApplyDetailsMapper.insertLeaseApplyDetailsList(leaseApplyDetails); + } + } + return count; + } + + /** + * 插入(领料出库详情表) lease_out_details表数据 + * @param sltAgreementInfo + * @param info + * @param detailById + * @param applyInfo + */ + private void extracted(SltAgreementInfo sltAgreementInfo, DirectApplyInfo info, List detailById, LeaseApplyInfo applyInfo) { + int count; + if (CollectionUtils.isNotEmpty(detailById)) { + for (DirectApplyDetails directApplyDetails : detailById) { + LeaseOutDetails record = new LeaseOutDetails(); + record.setParentId(applyInfo.getId()); + record.setTypeId(Long.valueOf(directApplyDetails.getTypeId())); + record.setMaId(directApplyDetails.getMaId() == null ? + null : Long.valueOf(directApplyDetails.getMaId())); + record.setOutNum(directApplyDetails.getDirectNum()); + record.setOutType("1".equals(directApplyDetails.getManageType()) ? + 1 : 0); + record.setCreateBy(SecurityUtils.getLoginUser().getSysUser().getNickName()); + record.setCreateTime(DateUtils.getNowDate()); + count = leaseOutDetailsMapper.insertLeaseOutDetails(record); + // 插入结算表 + if (count > 0) { + SltAgreementInfo dto = sltAgreementInfoMapper.getSltAgreementInfo(record); + if (dto != null) { + BigDecimal num = dto.getNum(); + BigDecimal outNum = record.getOutNum(); + dto.setNum(num.add(outNum)); + count = sltAgreementInfoMapper.updSltInfo(dto); + record.setAgreementId(sltAgreementInfo.getAgreementId()); + }else { + Type maType = typeMapper.getMaType(record.getTypeId()); + maType.setFinalPrice(maType.getLeasePrice()); + count = sltAgreementInfoMapper.insSltInfo(record, String.valueOf(info.getLeaseAgreementId()), maType); + } + if (count <= 0) { + throw new RuntimeException("领料结算表插入失败"); + } + } + } + } + } + + }