From f1654486503d3771ff6041b061398acbae4215f7 Mon Sep 17 00:00:00 2001 From: mashuai Date: Sun, 3 Aug 2025 16:25:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E5=85=AC=E5=8F=B8=E7=8F=AD=E7=BB=84?= =?UTF-8?q?=E9=A2=86=E6=96=99=E5=90=8C=E6=AD=A5=E6=9D=90=E6=96=99=E7=AB=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../clz/mapper/MaterialLeaseInfoMapper.java | 42 ++++ .../impl/LeaseOutDetailsServiceImpl.java | 232 +++++++++++++++++- .../material/task/mapper/TmTaskMapper.java | 16 ++ .../material/clz/MaterialLeaseInfoMapper.xml | 71 +++++- .../mapper/material/task/TmTaskMapper.xml | 16 ++ 5 files changed, 368 insertions(+), 9 deletions(-) diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/clz/mapper/MaterialLeaseInfoMapper.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/clz/mapper/MaterialLeaseInfoMapper.java index e73609cd..6ee47c6f 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/clz/mapper/MaterialLeaseInfoMapper.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/clz/mapper/MaterialLeaseInfoMapper.java @@ -307,4 +307,46 @@ public interface MaterialLeaseInfoMapper { * @return */ List getInfoByQrcodeClz(BmQrcodeInfo bmQrcodeInfo); + + /** + * 添加站点领料出库数据 + * @param record + * @return + */ + int insertLeaseApplyDetails(LeaseOutDetails record); + + /** + * 根据任务id查询领料任务信息 + * @param taskId + * @return + */ + MaterialLeaseApplyInfo selectId(Long taskId); + + /** + * 根据任务id查询领料任务详情信息 + * @param info + * @return + */ + MaterialLeaseApplyDetails selectDetailsById(MaterialLeaseApplyInfo info); + + /** + * 修改站点领料详情数据 + * @param details + * @return + */ + int updateLeaseApplyDetails(@Param("record") MaterialLeaseApplyDetails details); + + /** + * 根据工器具id查询工器具领料详情数据 + * @param record + * @return + */ + LeaseOutDetails selectInfoByTypeId(LeaseOutDetails record); + + /** + * 修改站点领料详情数据 + * @param leaseOutDetails + * @return + */ + int updateLeaseOutDetails(@Param("record") LeaseOutDetails leaseOutDetails); } 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 31682729..5214d5c0 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 @@ -1,23 +1,30 @@ package com.bonus.material.lease.service.impl; import java.math.BigDecimal; +import java.text.SimpleDateFormat; import java.time.LocalDate; +import java.util.Date; import java.util.List; import java.util.Objects; import com.bonus.common.biz.constant.MaterialConstants; import com.bonus.common.biz.domain.lease.LeaseApplyInfo; -import com.bonus.common.biz.enums.InputOutEnum; -import com.bonus.common.biz.enums.LeaseTaskStatusEnum; -import com.bonus.common.biz.enums.MaMachineStatusEnum; -import com.bonus.common.biz.enums.MaTypeManageTypeEnum; +import com.bonus.common.biz.enums.*; import com.bonus.common.core.exception.ServiceException; import com.bonus.common.core.utils.DateUtils; import com.bonus.common.core.utils.StringUtils; import com.bonus.common.core.web.domain.AjaxResult; import com.bonus.common.security.utils.SecurityUtils; +import com.bonus.material.basic.domain.BmAgreementInfo; import com.bonus.material.basic.domain.BmQrBoxInfo; +import com.bonus.material.basic.domain.BmUnit; import com.bonus.material.basic.mapper.BmAgreementInfoMapper; import com.bonus.material.basic.mapper.BmQrBoxMapper; +import com.bonus.material.clz.domain.BmTeam; +import com.bonus.material.clz.domain.lease.MaterialLeaseApplyDetails; +import com.bonus.material.clz.domain.lease.MaterialLeaseApplyInfo; +import com.bonus.material.clz.domain.vo.MaterialSltAgreementInfo; +import com.bonus.material.clz.mapper.BmTeamMapper; +import com.bonus.material.clz.mapper.MaterialLeaseInfoMapper; import com.bonus.material.lease.domain.LeaseApplyDetails; import com.bonus.material.lease.mapper.LeaseApplyDetailsMapper; import com.bonus.material.lease.mapper.LeaseApplyInfoMapper; @@ -27,6 +34,7 @@ import com.bonus.material.ma.mapper.TypeMapper; 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 lombok.extern.slf4j.Slf4j; @@ -78,6 +86,12 @@ public class LeaseOutDetailsServiceImpl implements ILeaseOutDetailsService { @Resource private BmQrBoxMapper bmQrBoxMapper; + + @Resource + private BmTeamMapper bmTeamMapper; + + @Resource + private MaterialLeaseInfoMapper materialLeaseInfoMapper; /** * 查询领料出库详细 * @@ -206,6 +220,135 @@ public class LeaseOutDetailsServiceImpl implements ILeaseOutDetailsService { } } } + // 7.将班组领料数据同步至材料站 + //7.1 根据单位id判读是否为班组领料出库 + BmUnit unit = tmTaskMapper.selectBmUnitById(record); + if (unit != null && unit.getTypeId() == 1731L) { + // 先根据taskId去tm_task中查询,看数据是否存在 + String createBy = SecurityUtils.getLoginUser().getSysUser().getNickName(); + TmTask task = tmTaskMapper.selectTmTaskByPreTaskId(Long.parseLong(record.getTaskId())); + if (task == null) { + int thisMonthMaxOrder = tmTaskMapper.getMonthMaxOrderByDate(DateUtils.getCurrentYear(), DateUtils.getCurrentMonth(), TmTaskTypeEnum.TM_TASK_MATERIAL_LEASE.getTaskTypeId()); + String taskCode = genderTaskCode(thisMonthMaxOrder); + TmTask tmTask = new TmTask(); + tmTask = new TmTask(null, TmTaskTypeEnum.TM_TASK_MATERIAL_LEASE.getTaskTypeId(), + LeaseTaskStatusEnum.LEASE_TASK_FINISHED.getStatus(), + null, thisMonthMaxOrder + 1, taskCode); + tmTask.setCreateTime(DateUtils.getNowDate()); + tmTask.setCreateBy(createBy); + tmTask.setPreTaskId(Long.parseLong(record.getTaskId())); + tmTaskMapper.insertTmTask(tmTask); + BmAgreementInfo bmAgreementInfo = new BmAgreementInfo(); + bmAgreementInfo.setProjectId(Long.valueOf(record.getLeaseProjectId())); + bmAgreementInfo.setCreateTime(DateUtils.getNowDate()); + bmAgreementInfo.setCreateBy(createBy); + bmAgreementInfo.setSignTime(DateUtils.getNowDate()); + bmAgreementInfo.setAgreementCode(getAgreementCode()); + // 先根据班组名称查询此班组是否存在 + BmTeam tbTeam = new BmTeam(); + tbTeam.setTeamName(record.getLeaseUnit()); + tbTeam.setProjectId(record.getLeaseProjectId().toString()); + // 班组类型固定传值 + tbTeam.setTypeId(1731L); + BmTeam bmTeam = bmTeamMapper.selectByName(tbTeam); + if (bmTeam == null) { + // 新增班组 + tbTeam.setCreateUser(SecurityUtils.getLoginUser().getUserid().toString()); + int result = bmTeamMapper.insert(tbTeam); + if (result <= 0) { + return AjaxResult.error(HttpCodeEnum.UPDATE_TO_DATABASE.getCode(), HttpCodeEnum.UPDATE_TO_DATABASE.getMsg()); + } + bmAgreementInfo.setUnitId(tbTeam.getId()); + } else { + bmAgreementInfo.setUnitId(bmTeam.getId()); + bmTeamMapper.update(tbTeam); + } + // 先根据班组和工程id查询,若存在则直接返回,不存在则新增 + BmAgreementInfo info = bmAgreementInfoMapper.queryByTeamIdAndProjectIdCl(bmAgreementInfo); + if (info != null) { + record.setAgreementId(info.getAgreementId()); + } else { + int count = bmAgreementInfoMapper.insertBmAgreementInfoClz(bmAgreementInfo); + if (count > 0) { + record.setAgreementId(bmAgreementInfo.getAgreementId()); + } else { + return AjaxResult.error("新增bm_agreement_info表失败"); + } + } + TmTaskAgreement tmTaskAgreement = new TmTaskAgreement(tmTask.getTaskId(), record.getAgreementId()); + tmTaskAgreement.setCreateTime(DateUtils.getNowDate()); + tmTaskAgreement.setCreateBy(createBy); + tmTaskAgreementMapper.insertTmTaskAgreement(tmTaskAgreement); + // 领料任务类型为2 数据同步 + MaterialLeaseApplyInfo materialLeaseApplyInfo = new MaterialLeaseApplyInfo(); + materialLeaseApplyInfo.setCode(taskCode); + materialLeaseApplyInfo.setTaskId(tmTask.getTaskId()); + materialLeaseApplyInfo.setLeaseStyle("2"); + materialLeaseApplyInfo.setTeamId(bmAgreementInfo.getUnitId().toString()); + materialLeaseApplyInfo.setProjectId(record.getLeaseProjectId().toString()); + int count = materialLeaseInfoMapper.insertLeaseApplyInfo(materialLeaseApplyInfo); + if (count > 0) { + return insertPurchaseCheckDetails(record, createBy, tmTask.getTaskId(), materialLeaseApplyInfo.getId()); + } else { + return AjaxResult.error("新增任务失败,lease_apply_info表插入0条"); + } + } else { + // 根据taskId查询领料任务 + MaterialLeaseApplyInfo info = materialLeaseInfoMapper.selectId(task.getTaskId()); + // 根据id查询clz_lease_apply_details表中数据是否存在 + if (info != null) { + info.setTypeId(record.getTypeId().toString()); + record.setParentId(info.getId()); + record.setCreateTime(DateUtils.getNowDate()); + record.setCreateBy(createBy); + record.setIsFinished(1); + MaterialLeaseApplyDetails details = materialLeaseInfoMapper.selectDetailsById(info); + if (details != null) { + // 走编辑 + details.setOutNum(record.getOutNum()); + details.setParentId(info.getId()); + details.setTypeId(record.getTypeId()); + int count = materialLeaseInfoMapper.updateLeaseApplyDetails(details); + if (count < 0) { + throw new Exception("更新clz_lease_apply_details表数据失败"); + } + } else { + record.setPreNum(record.getOutNum()); + record.setAlNum(record.getOutNum()); + res = materialLeaseInfoMapper.insertLeaseApplyDetails(record); + if (res <= 0) { + throw new Exception("新增clz_lease_apply_details表数据失败"); + } + } + // 根据类型查询clz_lease_out_details表数据是否存在 + if (record.getMaId() != null) { + // 编码直接走新增 + res = materialLeaseInfoMapper.insertLeaseOutDetails(record); + if (res <= 0) { + throw new Exception("新增clz_lease_out_details表数据失败"); + } + res = insSltInfoClz(task.getTaskId(), record); + } else { + record.setTypeId(record.getTypeId()); + // 数量先判断是否存在,存在则进行数量追加,否则新增 + LeaseOutDetails leaseOutDetails = materialLeaseInfoMapper.selectInfoByTypeId(record); + if (leaseOutDetails != null) { + leaseOutDetails.setOutNum(record.getOutNum()); + res = materialLeaseInfoMapper.updateLeaseOutDetails(leaseOutDetails); + if (res <= 0) { + throw new Exception("更新clz_lease_out_details表数据失败"); + } + } else { + res = materialLeaseInfoMapper.insertLeaseOutDetails(record); + if (res <= 0) { + throw new Exception("新增clz_lease_out_details表数据失败"); + } + } + res = insSltInfoClz(task.getTaskId(), record); + } + } + } + } } else { return AjaxResult.error("领料出库失败,机具库存不足"); } @@ -219,6 +362,87 @@ public class LeaseOutDetailsServiceImpl implements ILeaseOutDetailsService { return AjaxResult.success("出库成功"); } + /** + * 出库同步材料站 + * @param record + * @param createBy + * @param taskId + * @param id + * @return + */ + private AjaxResult insertPurchaseCheckDetails(LeaseOutDetails record, String createBy, Long taskId, Long id) { + record.setCreateTime(DateUtils.getNowDate()); + record.setCreateBy(createBy); + record.setParentId(id); + record.setIsFinished(1); + int res = materialLeaseInfoMapper.insertLeaseOutDetails(record); + if (res == 0) { + throw new RuntimeException("出库失败,插入结算记录失败"); + } + record.setPreNum(record.getOutNum()); + record.setAlNum(record.getOutNum()); + res = materialLeaseInfoMapper.insertLeaseApplyDetails(record); + if (res == 0) { + throw new RuntimeException("出库失败,插入结算记录失败"); + } + res = insSltInfoClz(taskId, record); + if (res == 0) { + throw new RuntimeException("出库失败,插入结算记录失败"); + } + return AjaxResult.success("出库成功"); + } + + /** + * 插入结算记录 + * @param taskId + * @param record + * @return + */ + private int insSltInfoClz(Long taskId, LeaseOutDetails record) { + int res = 0; + MaterialSltAgreementInfo sltAgreementInfo = materialLeaseInfoMapper.getSltAgreementInfo(record); + if (sltAgreementInfo != null) { + BigDecimal num = sltAgreementInfo.getNum(); + BigDecimal outNum = record.getOutNum(); + sltAgreementInfo.setNum(num.add(outNum)); + res = materialLeaseInfoMapper.updSltInfo(sltAgreementInfo); + record.setAgreementId(sltAgreementInfo.getAgreementId()); + } else { + String agreementId = tmTaskAgreementMapper.getAgreementId(taskId.toString()); + Type maType = typeMapper.getMaType(record.getTypeId()); + maType.setFinalPrice(maType.getLeasePrice()); + res = materialLeaseInfoMapper.insSltInfo(record, agreementId, maType); + } + return res; + } + + /** + * 生成任务编号 + * @param thisMonthMaxOrder + * @return + */ + private static String genderTaskCode(Integer thisMonthMaxOrder) { + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + Date nowDate = DateUtils.getNowDate(); + String format = dateFormat.format(nowDate); + String result = format.replace("-", ""); + return MaterialConstants.MATERIAL_LEASE_TASK_TYPE_LABEL + result + String.format("-%03d", thisMonthMaxOrder + 1); + } + + /** + * 获取协议编号 + * + * @return + */ + private String getAgreementCode() { + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + Date nowDate = DateUtils.getNowDate(); + String format = dateFormat.format(nowDate); + String result = format.replace("-", ""); + int num = bmAgreementInfoMapper.selectNumByMonthClz(nowDate); + return MaterialConstants.AGREEMENT_PREFIX + result + String.format("-%03d", num + 1); + } + /** * app领料出库退回 * diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/task/mapper/TmTaskMapper.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/task/mapper/TmTaskMapper.java index 4dbe1153..fa3bdaa4 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/task/mapper/TmTaskMapper.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/task/mapper/TmTaskMapper.java @@ -3,6 +3,8 @@ package com.bonus.material.task.mapper; import java.util.Date; import java.util.List; +import com.bonus.common.biz.domain.lease.LeaseOutDetails; +import com.bonus.material.basic.domain.BmUnit; import com.bonus.material.settlement.domain.SltAgreementInfo; import com.bonus.material.task.domain.TmTask; import org.apache.ibatis.annotations.Param; @@ -113,4 +115,18 @@ public interface TmTaskMapper { * @return */ TmTask selectTaskByIdByCl(Long agreementId); + + /** + * 根据协议id查询单位 + * @param record + * @return + */ + BmUnit selectBmUnitById(LeaseOutDetails record); + + /** + * 查询材料站领料数据 + * @param parseLong + * @return + */ + TmTask selectTmTaskByPreTaskId(long parseLong); } diff --git a/bonus-modules/bonus-material/src/main/resources/mapper/material/clz/MaterialLeaseInfoMapper.xml b/bonus-modules/bonus-material/src/main/resources/mapper/material/clz/MaterialLeaseInfoMapper.xml index 7f3dce19..05a092f0 100644 --- a/bonus-modules/bonus-material/src/main/resources/mapper/material/clz/MaterialLeaseInfoMapper.xml +++ b/bonus-modules/bonus-material/src/main/resources/mapper/material/clz/MaterialLeaseInfoMapper.xml @@ -284,6 +284,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" values (#{agreementId},#{record.typeId},#{record.maId},#{record.outNum},now(),0,#{record.parentId},#{ma.finalPrice},#{ma.buyPrice},'0',#{record.companyId},#{record.leaseType},now(),#{record.publishTask}); + + insert into clz_lease_apply_details + (parent_id, type_id, pre_num, al_num, `status`, create_by, create_time, update_by, + update_time, remark, company_id) + values (#{parentId}, #{typeId}, #{preNum},#{alNum}, #{status}, #{createBy},NOW(), #{updateBy}, NOW(), + #{remark}, #{companyId}) + + update clz_lease_apply_info @@ -333,6 +341,27 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where id = #{id} + + UPDATE + clz_lease_apply_details + SET + pre_num = pre_num + #{record.outNum}, + al_num = al_num + #{record.outNum}, + update_time = now() + WHERE + parent_id = #{record.parentId} and type_id = #{record.typeId} + + + + UPDATE + clz_lease_out_details + SET + out_num = out_num + #{record.outNum}, + update_time = now() + WHERE + parent_id = #{record.parentId} and type_id = #{record.typeId} + + delete from clz_lease_apply_details where parent_id in @@ -986,16 +1015,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" mt.type_name AS typeName, mt2.type_name AS materialType FROM - clz_lease_out_details lod - LEFT JOIN ma_machine mm ON lod.ma_id = mm.ma_id - LEFT JOIN ma_type mt ON lod.type_id = mt.type_id + clz_slt_agreement_info sai + LEFT JOIN ma_machine mm ON sai.ma_id = mm.ma_id + LEFT JOIN ma_type mt ON sai.type_id = mt.type_id AND mt.del_flag = '0' LEFT JOIN ma_type mt1 ON mt.parent_id = mt1.type_id AND mt1.del_flag = '0' LEFT JOIN ma_type mt2 ON mt1.parent_id = mt2.type_id AND mt2.del_flag = '0' - LEFT JOIN clz_slt_agreement_info sai on lod.type_id = sai.type_id - and sai.ma_id = lod.ma_id LEFT JOIN clz_bm_agreement_info ba ON sai.agreement_id = ba.agreement_id WHERE sai.status = '0' @@ -1119,4 +1146,38 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and mt.type_id = #{typeId} + + + + \ 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 491cfc5c..7a2ef505 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 @@ -188,4 +188,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and agreement_id = #{agreementId} + + + + \ No newline at end of file