refactor(bonus-material): 优化退料申请和租赁相关功能- 增加单位类型判断逻辑,针对班组类型添加特殊处理

- 改进协议 ID 查询逻辑,支持通过不同方式获取协议信息
- 优化 SQL 查询语句,提高数据查询效率
- 重构部分代码结构,提升可读性和可维护性
This commit is contained in:
syruan 2025-08-14 18:36:09 +08:00
parent e72f810b2a
commit 9f602eb078
8 changed files with 98 additions and 13 deletions

View File

@ -114,6 +114,9 @@ public class LeaseOutDetails extends BaseEntity {
@ApiModelProperty(value = "项目部协议id")
private Long projectUnitAgreementId;
@ApiModelProperty(value = "项目部单位id")
private Long projectUnitId;
@ApiModelProperty(value = "是否完成 (0:未完成 1:已完成)")
private Integer isFinished;

View File

@ -23,6 +23,7 @@ import com.bonus.material.basic.domain.BmAgreementInfo;
import com.bonus.material.basic.domain.BmUnit;
import com.bonus.material.basic.mapper.BmAgreementInfoMapper;
import com.bonus.material.basic.mapper.BmFileInfoMapper;
import com.bonus.material.basic.mapper.BmUnitMapper;
import com.bonus.material.clz.domain.back.MaterialBackApplyDetails;
import com.bonus.material.clz.domain.back.MaterialBackApplyInfo;
import com.bonus.material.clz.mapper.MaterialBackInfoMapper;
@ -45,6 +46,7 @@ import com.bonus.material.back.service.IBackApplyInfoService;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
/**
* 退料任务Service业务层处理
@ -89,6 +91,9 @@ public class BackApplyInfoServiceImpl implements IBackApplyInfoService {
@Resource
private BmAgreementInfoMapper bmAgreementInfoMapper;
@Resource
private BmUnitMapper bmUnitMapper;
/**
* 查询退料任务 - 性能优化版
*
@ -923,7 +928,30 @@ public class BackApplyInfoServiceImpl implements IBackApplyInfoService {
*/
@Override
@Transactional(rollbackFor = Exception.class)
public AjaxResult submitBackApply(BackApplyInfo backApplyInfo) {
public AjaxResult submitBackApply(@NotNull(message = "参数不能为空") BackApplyInfo backApplyInfo) {
if (backApplyInfo.getUnitId() == null || backApplyInfo.getProId() == null) {
return AjaxResult.error(HttpCodeEnum.FAIL.getCode(), "参数不能为空");
}
BmUnit queryUnitInfo = bmUnitMapper.selectBmUnitByUnitId(backApplyInfo.getUnitId());
if (queryUnitInfo.getTypeId() == null) {
throw new ServiceException("单位类型为空");
}
// 如果单位类型为班组则查询该班在机具签署的协议ID
LeaseOutDetails leaseOutDetail = new LeaseOutDetails();
if (queryUnitInfo.getTypeId() == 1731L) {
// 查询班组挂靠的项目部协议信息
leaseOutDetail = leaseApplyInfoMapper.selectProjectUnitAgreementIdByTeamAndProject(
Math.toIntExact(backApplyInfo.getUnitId()),
Math.toIntExact(backApplyInfo.getProId())
);
if (leaseOutDetail == null) {
throw new ServiceException("项目部协议信息查询为空");
}
// 把后续流程设置为项目部的协议进行处理
backApplyInfo.setAgreementId(leaseOutDetail.getProjectUnitAgreementId());
backApplyInfo.setUnitId(leaseOutDetail.getProjectUnitAgreementId());
}
List<BackApplyInfo> codeList = new ArrayList<>();
// 根据传入的id查询退料申请信息
List<BackApplyInfo> applyInfoList = backApplyInfoMapper.selectBackDetails(backApplyInfo);
@ -958,6 +986,14 @@ public class BackApplyInfoServiceImpl implements IBackApplyInfoService {
Long agreementId = backApplyInfoMapper.selectAgreementId(backApplyInfo);
// 先查第四层类型
backApplyInfo.setAgreementId(agreementId);
// 如果单位类型为班组则查询该班在机具签署的协议ID
if (queryUnitInfo.getTypeId() == 1731L) {
// 把后续流程设置为项目部的协议进行处理
if (leaseOutDetail.getProjectUnitAgreementId() != null) {
backApplyInfo.setAgreementId(leaseOutDetail.getProjectUnitAgreementId());
backApplyInfo.setUnitId(leaseOutDetail.getProjectUnitAgreementId());
}
}
List<TypeTreeNode> listL4 = mapper.getUseTypeTreeL4(backApplyInfo);
if (CollectionUtils.isNotEmpty(applyDetails)) {
for (BackApplyDetails applyDetail : applyDetails) {
@ -2202,7 +2238,15 @@ public class BackApplyInfoServiceImpl implements IBackApplyInfoService {
// 查询是否存在班组数据
List<SltAgreementInfo> tbList = backApplyInfoMapper.getTbList(bean);
if (CollectionUtils.isEmpty(infoList)) {
return 0;
// 退料单位的协议ID如果查不到就通过别的协议查例如班组的协议查不到可能是项目部去领用的
if (!Objects.equals(record.getAgreementId(), bean.getAgreementId())) {
infoList = backApplyInfoMapper.getStlInfo(bean.setAgreementId(record.getAgreementId()));
if (CollectionUtils.isEmpty(infoList)) {
return 0;
}
} else {
return 0;
}
}
BigDecimal backNum = bean.getBackNum();
// 遍历每个typeId

View File

@ -263,6 +263,8 @@ public interface SelectMapper {
*/
List<AgreementVo> getAgreementInfoByIdBack(SelectDto dto);
List<AgreementVo> getMaterialAgreementInfoByIdBack(SelectDto dto);
/**
* 获取无需授权的项目部和后勤单位
* @param bmUnit

View File

@ -3,11 +3,15 @@ package com.bonus.material.common.service.impl;
import com.alibaba.nacos.common.utils.StringUtils;
import com.bonus.common.biz.config.DateTimeHelper;
import com.bonus.common.biz.domain.*;
import com.bonus.common.core.exception.ServiceException;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.security.utils.SecurityUtils;
import com.bonus.material.back.domain.BackApplyInfo;
import com.bonus.material.basic.domain.BmProject;
import com.bonus.material.basic.domain.BmUnit;
import com.bonus.material.basic.mapper.BmUnitMapper;
import com.bonus.material.clz.domain.lease.MaterialLeaseApplyInfo;
import com.bonus.material.clz.service.MaterialLeaseInfoService;
import com.bonus.material.common.domain.dto.SelectDto;
import com.bonus.material.common.domain.vo.AgreementVo;
import com.bonus.material.common.domain.vo.SelectVo;
@ -18,6 +22,7 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.*;
import java.util.stream.Collectors;
@ -32,6 +37,12 @@ public class SelectServiceImpl implements SelectService {
@Resource(name = "SelectMapper")
private SelectMapper mapper;
@Resource
private BmUnitMapper bmUnitMapper;
@Resource
private MaterialLeaseInfoService materialLeaseInfoService;
/**
* 单位下拉类型树
* @param bmUnit
@ -264,7 +275,7 @@ public class SelectServiceImpl implements SelectService {
* @return
*/
@Override
public AjaxResult getUnitListLease(BmUnit bmUnit) {
public AjaxResult getUnitListLease(@NotNull(message = "参数不能为空") BmUnit bmUnit) {
// 获取登陆用户的组织ID
Long thisLoginUserDeptId = SecurityUtils.getLoginUser().getSysUser().getDeptId();
if (null == thisLoginUserDeptId || 0 == thisLoginUserDeptId) {
@ -509,11 +520,27 @@ public class SelectServiceImpl implements SelectService {
try {
// 判断单位是否为班组如果为班组的话把材料站的领用数据也查询出来
if (bean.getUnitId() != null && bean.getProId() != null) {
List<AgreementVo> clzAgreementInfos = mapper.getAgreementInfoByIdBack(new SelectDto().setProId(bean.getProId()).setUnitId(Math.toIntExact(bean.getUnitId())));
// 如果在材料站该单位有签署协议说明该单位是班组
if (CollectionUtils.isNotEmpty(clzAgreementInfos)) {
bean.setClzAgreementId(Long.valueOf(clzAgreementInfos.get(0).getAgreementId()));
BmUnit queryUnitInfo = bmUnitMapper.selectBmUnitByUnitId(bean.getUnitId());
if (queryUnitInfo.getTypeId() == null) {
throw new ServiceException("单位类型为空");
}
// 如果单位类型为班组则查询该班在机具签署的协议ID
if (queryUnitInfo.getTypeId() == 1731L) {
// List<AgreementVo> agreementInfos = mapper.getMaterialAgreementInfoByIdBack(new SelectDto().setProId(bean.getProId()).setUnitId(Math.toIntExact(queryUnitInfo.getUnitId())));
// if (CollectionUtils.isNotEmpty(agreementInfos)) {
// bean.setClzAgreementId(Long.valueOf(agreementInfos.get(0).getAgreementId()));
// } else {
// throw new ServiceException("该班组没有在机具签署✍️的协议");
// }
List<AgreementVo> clzAgreementInfos = mapper.getAgreementInfoByIdBack(new SelectDto().setProId(bean.getProId()).setUnitId(Math.toIntExact(bean.getUnitId())));
// 如果在材料站该单位有签署协议
if (CollectionUtils.isNotEmpty(clzAgreementInfos)) {
bean.setClzAgreementId(Long.valueOf(clzAgreementInfos.get(0).getAgreementId()));
} else {
throw new ServiceException("该班组没有在机具签署✍️的协议");
}
}
}
// 先查第四层类型
listL4 = mapper.getUseTypeTreeL4(bean);

View File

@ -3,6 +3,7 @@ package com.bonus.material.lease.mapper;
import java.util.List;
import com.bonus.common.biz.domain.lease.LeaseApplyInfo;
import com.bonus.common.biz.domain.lease.LeaseConfirmSign;
import com.bonus.common.biz.domain.lease.LeaseOutDetails;
import com.bonus.common.biz.domain.lease.LeaseOutSign;
import com.bonus.material.lease.domain.LeaseApplyDetails;
import org.apache.ibatis.annotations.Param;
@ -99,7 +100,7 @@ public interface LeaseApplyInfoMapper {
* @param projectId 工程id
* @return 挂靠的项目部协议id
*/
Long selectProjectUnitAgreementIdByTeamAndProject(@Param("teamId") Integer teamId, @Param("projectId") Integer projectId);
LeaseOutDetails selectProjectUnitAgreementIdByTeamAndProject(@Param("teamId") Integer teamId, @Param("projectId") Integer projectId);
String getTaskId(Long parentId);

View File

@ -222,7 +222,7 @@ public class LeaseOutDetailsServiceImpl implements ILeaseOutDetailsService {
// 暂存现在出库的班组单位ID
Integer thisOutId = record.getLeaseUnitId();
// 查询班组挂靠的项目部协议ID
Long projectUnitAgreementId = leaseApplyInfoMapper.selectProjectUnitAgreementIdByTeamAndProject(record.getLeaseUnitId(), record.getLeaseProjectId());
Long projectUnitAgreementId = leaseApplyInfoMapper.selectProjectUnitAgreementIdByTeamAndProject(record.getLeaseUnitId(), record.getLeaseProjectId()).getProjectUnitAgreementId();
if (projectUnitAgreementId != null && projectUnitAgreementId > GlobalConstants.INT_0) {
record.setProjectUnitAgreementId(projectUnitAgreementId);
} else {

View File

@ -613,7 +613,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
agreement_code AS agreementCode,
is_slt AS isSlt
FROM clz_bm_agreement_info
WHERE unit_id = #{unitId} AND project_id = #{projectId} AND status = '1'
WHERE unit_id = #{unitId} AND project_id = #{proId} AND status = '1'
</select>
<select id="getMaterialAgreementInfoByIdBack" resultType="com.bonus.material.common.domain.vo.AgreementVo">
SELECT agreement_id AS agreementId,
agreement_code AS agreementCode,
is_slt AS isSlt
FROM bm_agreement_info
WHERE unit_id = #{unitId} AND project_id = #{proId} AND status = '1'
</select>
<select id="getUnitListXm" resultType="com.bonus.common.biz.domain.ProjectTreeNode">
@ -844,7 +852,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
LEFT JOIN `micro-tool`.bzgl_bz bzgl_bz ON bzgl_bz.bzmc = bu.unit_name
LEFT JOIN `uni_org`.org_user org_user ON bzgl_bz.bzz_idcard = org_user.id_card
WHERE bu.del_flag = '0'
and bzgl_bz.project_id = #{externalId}
<!-- and bzgl_bz.project_id = #{externalId}-->
</select>
<select id="getUseTypeClzTree" resultType="com.bonus.common.biz.domain.TypeTreeNode">

View File

@ -850,9 +850,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where unit_id = #{unitId}
</select>
<select id="selectProjectUnitAgreementIdByTeamAndProject" resultType="java.lang.Long">
<select id="selectProjectUnitAgreementIdByTeamAndProject" resultType="com.bonus.common.biz.domain.lease.LeaseOutDetails">
SELECT
baii.agreement_id AS projectUnitAgreementId
baii.agreement_id AS projectUnitAgreementId, bai.project_unit_id AS projectUnitId
FROM
bm_agreement_info bai
LEFT JOIN bm_agreement_info baii ON baii.unit_id = bai.project_unit_id AND baii.project_id = #{projectId}