This commit is contained in:
mashuai 2025-10-18 22:02:43 +08:00
parent 4f1d529512
commit 2aa6920c88
12 changed files with 257 additions and 53 deletions

View File

@ -24,6 +24,26 @@ public class ProjectTreeNode {
private String typeKey; private String typeKey;
/**
* 班组长id
*/
private String teamLeaderIdCard;
/**
* 班组长姓名
*/
private String relName;
/**
* 班组长手机号
*/
private String relPhone;
/**
* 工程id
*/
private String projectId;
@JsonInclude(JsonInclude.Include.NON_EMPTY) @JsonInclude(JsonInclude.Include.NON_EMPTY)
private List<ProjectTreeNode> children = new ArrayList<>(); private List<ProjectTreeNode> children = new ArrayList<>();
} }

View File

@ -413,4 +413,11 @@ public interface SelectMapper {
* @return * @return
*/ */
List<MaterialRetainedEquipmentInfo> getClzAgreementId(MaterialRetainedEquipmentInfo info); List<MaterialRetainedEquipmentInfo> getClzAgreementId(MaterialRetainedEquipmentInfo info);
/**
* 根据领料id查询i8工程id
* @param bean
* @return
*/
ProAuthorizeInfo selectProAuthorizeInfo(ProAuthorizeInfo bean);
} }

View File

@ -12,14 +12,13 @@ import com.bonus.material.ma.service.DirectRotationService;
import com.bonus.material.settlement.domain.SltAgreementInfo; import com.bonus.material.settlement.domain.SltAgreementInfo;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.ArrayList; import java.util.*;
import java.util.Iterator;
import java.util.List;
/** /**
@ -30,6 +29,7 @@ import java.util.List;
@Api(tags = " 直转申请") @Api(tags = " 直转申请")
@RestController @RestController
@RequestMapping("/directRotation") @RequestMapping("/directRotation")
@Slf4j
public class DirectRotationController extends BaseController { public class DirectRotationController extends BaseController {
@Resource(name = "directRotationService") @Resource(name = "directRotationService")
@ -45,42 +45,74 @@ public class DirectRotationController extends BaseController {
List<SltAgreementInfo> datas = new ArrayList<>(); List<SltAgreementInfo> datas = new ArrayList<>();
List<SltAgreementInfo> useringData = service.getUseringData(sltAgreementInfo); List<SltAgreementInfo> useringData = service.getUseringData(sltAgreementInfo);
Integer projectId = service.getprojectId(sltAgreementInfo); Integer projectId = service.getprojectId(sltAgreementInfo);
// 根据项目获取材料站在用机具
List<SltAgreementInfo> useringDataClz = service.getUseringDataByClz(projectId); List<SltAgreementInfo> useringDataClz = service.getUseringDataByClz(projectId);
Iterator<SltAgreementInfo> iterator = useringData.iterator(); // 1. 构建typeId -> 材料站数据的映射同之前
while (iterator.hasNext()) { Map<Long, List<SltAgreementInfo>> clzMap = new HashMap<>();
SltAgreementInfo useringDatum = iterator.next(); for (SltAgreementInfo clzInfo : useringDataClz) {
Long typeId = clzInfo.getTypeId();
clzMap.computeIfAbsent(typeId, k -> new ArrayList<>()).add(clzInfo);
}
// 2. 批量查询待审核数量收集所有必要参数一次查库
Set<SltAgreementInfo> pairSet = new HashSet<>();
for (SltAgreementInfo data : useringData) {
Long typeId = data.getTypeId();
Long maId = data.getMaId();
SltAgreementInfo info = new SltAgreementInfo();
info.setTypeId(typeId);
info.setMaId(maId);
pairSet.add(info); // 去重相同组合
}
List<SltAgreementInfo> pairs = new ArrayList<>(pairSet);
// 批量查询待转数量
List<SltAgreementInfo> batchInfoList = service.getBatchInfo(sltAgreementInfo.getAgreementId(),pairs);
// 构建infoMapkey = "typeId:maId"value = 对应的SltAgreementInfo含waitTransNum
Map<String, SltAgreementInfo> infoMap = new HashMap<>();
for (SltAgreementInfo info : batchInfoList) {
Long typeId = info.getTypeId();
Long maId = info.getMaId();
// 生成唯一key处理maId为null的情况
String key = typeId + ":" + (maId == null ? "null" : maId);
infoMap.put(key, info);
}
// 3. 遍历useringData处理逻辑用批量结果替代循环查库
for (SltAgreementInfo data : useringData) {
boolean shouldAdd = true; boolean shouldAdd = true;
for (SltAgreementInfo agreementInfo : useringDataClz) { Long dataTypeId = data.getTypeId();
if (useringDatum.getTypeId().equals(agreementInfo.getTypeId())) { List<SltAgreementInfo> matchedClzList = clzMap.get(dataTypeId);
if (useringDatum.getMaId() == null && agreementInfo.getMaId() == null) { if (matchedClzList != null && !matchedClzList.isEmpty()) {
if (useringDatum.getUseNum().compareTo(agreementInfo.getUseNum()) > 0) { for (SltAgreementInfo clzInfo : matchedClzList) {
useringDatum.setUseNum(useringDatum.getUseNum().subtract(agreementInfo.getUseNum())); if (data.getMaId() == null && clzInfo.getMaId() == null) {
// 优化先计算结果最后一次set减少BigDecimal创建
BigDecimal subtractResult = data.getUseNum().subtract(clzInfo.getUseNum());
if (subtractResult.compareTo(BigDecimal.ZERO) > 0) {
data.setUseNum(subtractResult);
} else { } else {
shouldAdd = false; shouldAdd = false;
break; break;
} }
} else if (useringDatum.getMaId() != null && useringDatum.getMaId().equals(agreementInfo.getMaId())) { } else if (Objects.equals(data.getMaId(), clzInfo.getMaId())) {
shouldAdd = false; shouldAdd = false;
break; break;
} }
} }
} }
// 根据协议以及类型id查询待审核数量 // 4. 从批量查询结果中获取数据O(1)查询
SltAgreementInfo info = service.getInfo(useringDatum); String infoKey = data.getTypeId() + ":" + (data.getMaId() == null ? "null" : data.getMaId());
SltAgreementInfo info = infoMap.get(infoKey);
if (info != null) { if (info != null) {
useringDatum.setWaitTransNum(info.getWaitTransNum()); data.setWaitTransNum(info.getWaitTransNum());
useringDatum.setTransNum(useringDatum.getUseNum().subtract(useringDatum.getWaitTransNum())); data.setTransNum(data.getUseNum().subtract(info.getWaitTransNum()));
} else { } else {
useringDatum.setWaitTransNum(BigDecimal.ZERO); data.setWaitTransNum(BigDecimal.ZERO);
useringDatum.setTransNum(useringDatum.getUseNum()); data.setTransNum(data.getUseNum());
} }
if (shouldAdd) { if (shouldAdd) {
datas.add(useringDatum); datas.add(data);
} }
} }
return AjaxResult.success(datas); return AjaxResult.success(datas);
} catch (Exception e) { } catch (Exception e) {
log.error("查询失败", e);
return AjaxResult.success(new ArrayList<>()); return AjaxResult.success(new ArrayList<>());
} }
} }

View File

@ -108,4 +108,12 @@ public interface DirectRotationMapper {
* @return * @return
*/ */
SltAgreementInfo getInfo(SltAgreementInfo useringDatum); SltAgreementInfo getInfo(SltAgreementInfo useringDatum);
/**
* 批量查询
* @param agreementId
* @param list
* @return
*/
List<SltAgreementInfo> getBatchInfo(@Param("agreementId") Long agreementId, @Param("pairs")List<SltAgreementInfo> list);
} }

View File

@ -106,4 +106,12 @@ public interface DirectRotationService {
* @return * @return
*/ */
SltAgreementInfo getInfo(SltAgreementInfo useringDatum); SltAgreementInfo getInfo(SltAgreementInfo useringDatum);
/**
* 批量查询待转数量
* @param agreementId
* @param list
* @return
*/
List<SltAgreementInfo> getBatchInfo(Long agreementId, List<SltAgreementInfo> list);
} }

View File

@ -550,6 +550,17 @@ public class DirectRotationImpl implements DirectRotationService {
return mapper.getInfo(useringDatum); return mapper.getInfo(useringDatum);
} }
/**
* 批量查询协议信息
* @param agreementId
* @param list
* @return
*/
@Override
public List<SltAgreementInfo> getBatchInfo(Long agreementId, List<SltAgreementInfo> list) {
return mapper.getBatchInfo(agreementId, list);
}
// 将签名分类的逻辑提取到一个单独的方法 // 将签名分类的逻辑提取到一个单独的方法
private void classifySignature(ClzDirectApplyInfo clzDirectApplyInfo, LeaseOutSign leaseOutSign, private void classifySignature(ClzDirectApplyInfo clzDirectApplyInfo, LeaseOutSign leaseOutSign,
List<LeaseOutSign> list1, List<LeaseOutSign> list2, List<LeaseOutSign> list3) { List<LeaseOutSign> list1, List<LeaseOutSign> list2, List<LeaseOutSign> list3) {

View File

@ -28,7 +28,7 @@ public class ProAuthorizeInfo {
/** /**
* 班组id * 班组id
*/ */
private Long teamId; private String teamId;
/** /**
* 班组名称 * 班组名称

View File

@ -1,18 +1,24 @@
package com.bonus.material.materialStation.service.impl; package com.bonus.material.materialStation.service.impl;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.bonus.common.biz.constant.GlobalConstants;
import com.bonus.common.biz.domain.ProjectTreeNode;
import com.bonus.common.biz.domain.lease.LeaseApplyInfo; import com.bonus.common.biz.domain.lease.LeaseApplyInfo;
import com.bonus.common.biz.domain.lease.LeasePublishInfo; import com.bonus.common.biz.domain.lease.LeasePublishInfo;
import com.bonus.common.biz.enums.HttpCodeEnum;
import com.bonus.common.core.domain.R; import com.bonus.common.core.domain.R;
import com.bonus.common.core.utils.StringUtils; import com.bonus.common.core.utils.StringUtils;
import com.bonus.common.core.web.domain.AjaxResult; import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.security.utils.SecurityUtils; import com.bonus.common.security.utils.SecurityUtils;
import com.bonus.material.clz.domain.BmTeam;
import com.bonus.material.clz.domain.vo.MaterialRetainedEquipmentInfo; import com.bonus.material.clz.domain.vo.MaterialRetainedEquipmentInfo;
import com.bonus.material.clz.mapper.BmTeamMapper;
import com.bonus.material.common.mapper.SelectMapper; import com.bonus.material.common.mapper.SelectMapper;
import com.bonus.material.materialStation.domain.ProAuthorizeDetails; import com.bonus.material.materialStation.domain.ProAuthorizeDetails;
import com.bonus.material.materialStation.domain.ProAuthorizeInfo; import com.bonus.material.materialStation.domain.ProAuthorizeInfo;
import com.bonus.material.materialStation.mapper.ProAuthorizeMapper; import com.bonus.material.materialStation.mapper.ProAuthorizeMapper;
import com.bonus.material.materialStation.service.ProAuthorizeService; import com.bonus.material.materialStation.service.ProAuthorizeService;
import com.google.common.net.MediaType;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import okhttp3.*; import okhttp3.*;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
@ -60,6 +66,9 @@ public class ProAuthorizeServiceImpl implements ProAuthorizeService {
@Resource(name = "SelectMapper") @Resource(name = "SelectMapper")
private SelectMapper selectMapper; private SelectMapper selectMapper;
@Resource
private BmTeamMapper bmTeamMapper;
@Override @Override
public List<LeasePublishInfo> getPublishList(LeaseApplyInfo leaseApplyInfo) { public List<LeasePublishInfo> getPublishList(LeaseApplyInfo leaseApplyInfo) {
@ -162,8 +171,8 @@ public class ProAuthorizeServiceImpl implements ProAuthorizeService {
public AjaxResult authorizeSubmit(ProAuthorizeInfo bean) { public AjaxResult authorizeSubmit(ProAuthorizeInfo bean) {
try { try {
String userId = SecurityUtils.getLoginUser().getUserid().toString(); String userId = SecurityUtils.getLoginUser().getUserid().toString();
bean.setCreateBy(userId);
if (bean != null) { if (bean != null) {
bean.setCreateBy(userId);
if (bean.getAuthId() != null) { if (bean.getAuthId() != null) {
//修改 //修改
//删除详情数据 //删除详情数据
@ -175,6 +184,37 @@ public class ProAuthorizeServiceImpl implements ProAuthorizeService {
} else { } else {
for (Long lesaeId : bean.getLeaseIds()){ for (Long lesaeId : bean.getLeaseIds()){
bean.setLeaseId(lesaeId); bean.setLeaseId(lesaeId);
// 根据领料id查询i8工程id
ProAuthorizeInfo info = selectMapper.selectProAuthorizeInfo(bean);
// 根据i8工程id以及班组名称查询班组信息
if (info != null) {
bean.setExternalId(info.getExternalId());
}
List<ProjectTreeNode> newList = selectMapper.getTeamNewList(bean);
if (!CollectionUtils.isEmpty(newList)) {
ProjectTreeNode projectTreeNode = newList.get(0);
// 先根据班组名称查询此班组是否存在
BmTeam tbTeam = new BmTeam();
tbTeam.setTeamName(projectTreeNode.getName());
tbTeam.setProjectId(projectTreeNode.getProjectId());
// 班组类型固定传值
tbTeam.setTypeId(1731L);
tbTeam.setIdCard(projectTreeNode.getTeamLeaderIdCard());
BmTeam bmTeam = bmTeamMapper.selectByName(tbTeam);
if (bmTeam == null) {
// 新增班组
tbTeam.setCreateUser(SecurityUtils.getLoginUser().getUserid().toString());
tbTeam.setRelName(projectTreeNode.getRelName());
tbTeam.setRelPhone(projectTreeNode.getRelPhone());
int result = bmTeamMapper.insert(tbTeam);
if (result <= GlobalConstants.INT_0) {
return AjaxResult.error(HttpCodeEnum.UPDATE_TO_DATABASE.getCode(), HttpCodeEnum.UPDATE_TO_DATABASE.getMsg());
}
bean.setTeamId(tbTeam.getId().toString());
} else {
bean.setTeamId(bmTeam.getId().toString());
}
}
//新增 //新增
int res = mapper.insertProAuthorizeInfo(bean); int res = mapper.insertProAuthorizeInfo(bean);
if (res > 0 && bean.getId() != null) { if (res > 0 && bean.getId() != null) {

View File

@ -103,6 +103,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="teamName != null and teamName != ''"> <if test="teamName != null and teamName != ''">
and unit_name = #{teamName} and unit_name = #{teamName}
</if> </if>
<if test="idCard != null and idCard != ''">
and bzz_idcard = #{idCard}
</if>
Limit 1 Limit 1
</select> </select>

View File

@ -1166,16 +1166,24 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select> </select>
<select id="getTeamNewList" resultType="com.bonus.common.biz.domain.ProjectTreeNode"> <select id="getTeamNewList" resultType="com.bonus.common.biz.domain.ProjectTreeNode">
SELECT DISTINCT SELECT
unit_id AS id, DISTINCT
unit_name AS NAME bz.id as id,
FROM bz.bzmc as name, bz.bzz_name as relName,
bm_unit bz.bzz_idcard as teamLeaderIdCard,
bz.project_id as projectId,
ou.mobile as relPhone
from
`micro-tool`.bzgl_bz bz
left join `uni_org`.org_user ou on bz.bzz_idcard = ou.id_card
WHERE WHERE
del_flag = '0' bz.bz_status = 3
AND project_id = #{externalId} AND bz.sfjs = 0
GROUP BY AND bz.project_id = #{externalId}
unit_id <if test="teamName != null and teamName != ''">
AND bz.bzmc = #{teamName}
</if>
GROUP BY bz.bzmc
</select> </select>
<select id="getUnsettledProId" resultType="java.lang.String"> <select id="getUnsettledProId" resultType="java.lang.String">
<!-- 数据量小的时候用上面的SQL数据量大的时候用下面的sql --> <!-- 数据量小的时候用上面的SQL数据量大的时候用下面的sql -->
@ -1279,4 +1287,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
AND bu.project_id = #{externalId} AND bu.project_id = #{externalId}
</if> </if>
</select> </select>
<select id="selectProAuthorizeInfo" resultType="com.bonus.material.materialStation.domain.ProAuthorizeInfo">
SELECT
bp.pro_id AS proId,
bp.external_id AS externalId
FROM
bm_project bp
LEFT JOIN lease_apply_info lai ON bp.pro_id = lai.project_id
WHERE
lai.id = #{leaseId}
</select>
</mapper> </mapper>

View File

@ -379,4 +379,32 @@
HAVING HAVING
waitTransNum > 0 waitTransNum > 0
</select> </select>
<select id="getBatchInfo" resultType="com.bonus.material.settlement.domain.SltAgreementInfo">
SELECT
da.back_agreement_id AS agreementId,
dad.type_id AS typeId,
dad.ma_id AS maId,
da.id AS id,
SUM(IFNULL(dad.direct_num, 0)) AS waitTransNum -- 待转数量
FROM
direct_apply_info da
INNER JOIN direct_apply_details dad ON da.id = dad.direct_id
WHERE
da.`status` = '0'
AND EXISTS (
SELECT 1 FROM sys_workflow_record swr
WHERE swr.task_id = da.id
)
AND da.back_agreement_id = #{agreementId}
AND (
<foreach collection="pairs" item="pair" separator="OR">
(dad.type_id = #{pair.typeId}
<if test="pair.maId != null">AND dad.ma_id = #{pair.maId}</if>
<if test="pair.maId == null">AND dad.ma_id IS NULL</if>)
</foreach>
)
AND IFNULL(dad.direct_num, 0) > 0 -- 提前过滤0值减少计算
GROUP BY
da.back_agreement_id, dad.type_id, dad.ma_id, da.id;
</select>
</mapper> </mapper>

View File

@ -1056,29 +1056,58 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select lease_price from ma_type where type_id = #{typeId} select lease_price from ma_type where type_id = #{typeId}
</select> </select>
<select id="selectMaTypeThreeLists" resultMap="TypeResult"> <select id="selectMaTypeThreeLists" resultMap="TypeResult">
SELECT m.type_id, SELECT
m.type_name, m.type_id,
m.parent_id, m.type_name,
m.manage_type, m.parent_id,
m.LEVEL, m.manage_type,
m.type_id AS id, m.`LEVEL`,
m.type_name AS label m.type_id AS id,
m.type_name AS label
FROM ma_type m FROM ma_type m
WHERE m.type_id IN (SELECT DISTINCT mt_parent.parent_id WHERE m.type_id IN (
FROM slt_agreement_info sai -- 对三级节点去重
INNER JOIN ma_type mt ON mt.type_id = sai.type_id SELECT DISTINCT node_id
LEFT JOIN ma_type mt_parent ON ( FROM (
mt_parent.type_id = mt.type_id OR -- 三级父节点
mt_parent.type_id = mt.parent_id OR SELECT
EXISTS( mt.parent_id AS node_id
SELECT 1 FROM (
FROM ma_type mt2 SELECT DISTINCT sai.type_id
WHERE mt2.type_id = mt.parent_id FROM slt_agreement_info sai
AND mt_parent.type_id = mt2.parent_id WHERE sai.agreement_id = #{agreementId} AND sai.STATUS = '0'
) ) AS sai_filtered
) INNER JOIN ma_type mt ON mt.type_id = sai_filtered.type_id
WHERE sai.agreement_id = #{agreementId} WHERE mt.parent_id IS NOT NULL
AND sai.STATUS = '0')
UNION ALL -- 二级父节点
SELECT
mt2.parent_id AS node_id
FROM (
SELECT DISTINCT sai.type_id
FROM slt_agreement_info sai
WHERE sai.agreement_id = #{agreementId} AND sai.STATUS = '0'
) AS sai_filtered
INNER JOIN ma_type mt ON mt.type_id = sai_filtered.type_id
INNER JOIN ma_type mt2 ON mt2.type_id = mt.parent_id
WHERE mt2.parent_id IS NOT NULL
UNION ALL -- 一级父节点
SELECT
mt3.parent_id AS node_id
FROM (
SELECT DISTINCT sai.type_id
FROM slt_agreement_info sai
WHERE sai.agreement_id = #{agreementId} AND sai.STATUS = '0'
) AS sai_filtered
INNER JOIN ma_type mt ON mt.type_id = sai_filtered.type_id
INNER JOIN ma_type mt2 ON mt2.type_id = mt.parent_id
INNER JOIN ma_type mt3 ON mt3.type_id = mt2.parent_id
WHERE mt3.parent_id IS NOT NULL
) AS all_nodes
);
</select> </select>
<select id="getListLevel" resultType="com.bonus.material.ma.domain.vo.MaTypeVo"> <select id="getListLevel" resultType="com.bonus.material.ma.domain.vo.MaTypeVo">