This commit is contained in:
hongchao 2025-09-22 19:28:29 +08:00
commit 69f46d8a1a
9 changed files with 63 additions and 39 deletions

View File

@ -15,7 +15,7 @@ import java.util.List;
/** /**
* 退料任务对象 back_apply_info * 退料任务对象 back_apply_info
* *
* @author xsheng * @author xsheng
* @date 2024-10-16 * @date 2024-10-16
*/ */
@ -211,4 +211,9 @@ public class MaterialBackApplyInfo implements Serializable {
@Excel(name = "项目部",sort = 4) @Excel(name = "项目部",sort = 4)
private String departName; private String departName;
/**
* 协议id集合
*/
private List<String> agreementIds;
} }

View File

@ -299,7 +299,7 @@ public interface MaterialLeaseInfoMapper {
* @param bean * @param bean
* @return * @return
*/ */
BmAgreementInfo getAgreeId(MaterialLeaseApplyInfo bean); List<BmAgreementInfo> getAgreeId(MaterialLeaseApplyInfo bean);
/** /**
* 二维码出库根据qrcode查询在库机具信息 * 二维码出库根据qrcode查询在库机具信息

View File

@ -1410,7 +1410,7 @@ public class MaterialLeaseInfoServiceImpl implements MaterialLeaseInfoService {
if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(listL5)) { if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(listL5)) {
// 优化预先查询班组和协议信息避免在循环中重复查询 // 优化预先查询班组和协议信息避免在循环中重复查询
BmTeam team = null; BmTeam team = null;
BmAgreementInfo agreementInfo = null; List<BmAgreementInfo> agreementInfo = null;
if (StringUtils.isNotBlank(bean.getTeamName())) { if (StringUtils.isNotBlank(bean.getTeamName())) {
team = getTeamByNameCached(bean.getTeamName()); team = getTeamByNameCached(bean.getTeamName());
@ -1423,14 +1423,19 @@ public class MaterialLeaseInfoServiceImpl implements MaterialLeaseInfoService {
// 优化如果有协议信息批量查询所有类型的使用数量 // 优化如果有协议信息批量查询所有类型的使用数量
Map<Long, BigDecimal> useNumMap = new HashMap<>(); Map<Long, BigDecimal> useNumMap = new HashMap<>();
if (agreementInfo != null && !listL5.isEmpty()) { if (!CollectionUtils.isEmpty(agreementInfo) && !listL5.isEmpty()) {
// 收集所有需要查询的typeId // 收集所有需要查询的typeId
List<Long> typeIds = listL5.stream() List<Long> typeIds = listL5.stream()
.map(TypeTreeNode::getTypeId) .map(TypeTreeNode::getTypeId)
.collect(Collectors.toList()); .collect(Collectors.toList());
// 获取agreementInfo中的协议id
List<Long> agreementIds = agreementInfo.stream()
.map(BmAgreementInfo::getAgreementId)
.distinct()
.collect(Collectors.toList());
// 批量查询使用数量 - 性能优化关键点 // 批量查询使用数量 - 性能优化关键点
List<Type> batchResults = typeMapper.getNumListBatch(agreementInfo.getAgreementId(), typeIds); List<Type> batchResults = typeMapper.getNumListBatch(agreementIds, typeIds);
// 转换为Map // 转换为Map
if (!CollectionUtils.isEmpty(batchResults)) { if (!CollectionUtils.isEmpty(batchResults)) {
@ -1488,7 +1493,7 @@ public class MaterialLeaseInfoServiceImpl implements MaterialLeaseInfoService {
* @param bean 查询参数 * @param bean 查询参数
* @return 协议信息 * @return 协议信息
*/ */
private BmAgreementInfo getAgreementInfoCached(MaterialLeaseApplyInfo bean) { private List<BmAgreementInfo> getAgreementInfoCached(MaterialLeaseApplyInfo bean) {
return materialLeaseInfoMapper.getAgreeId(bean); return materialLeaseInfoMapper.getAgreeId(bean);
} }

View File

@ -53,9 +53,9 @@ public class SelectServiceImpl implements SelectService {
// 性能监控开始 // 性能监控开始
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
Map<String, Long> stepTimes = new LinkedHashMap<>(); Map<String, Long> stepTimes = new LinkedHashMap<>();
log.info("=== getUnitList开始执行参数: {}", bmUnit); log.info("=== getUnitList开始执行参数: {}", bmUnit);
// 步骤1: 获取登陆用户的组织ID // 步骤1: 获取登陆用户的组织ID
long step1Start = System.currentTimeMillis(); long step1Start = System.currentTimeMillis();
Long thisLoginUserDeptId = SecurityUtils.getLoginUser().getSysUser().getDeptId(); Long thisLoginUserDeptId = SecurityUtils.getLoginUser().getSysUser().getDeptId();
@ -66,25 +66,25 @@ public class SelectServiceImpl implements SelectService {
log.info("用户组织ID为空直接返回空列表总耗时: {}ms", totalTime); log.info("用户组织ID为空直接返回空列表总耗时: {}ms", totalTime);
return AjaxResult.success(Collections.emptyList()); return AjaxResult.success(Collections.emptyList());
} }
// 步骤2: 判断是否开启过滤 // 步骤2: 判断是否开启过滤
long step2Start = System.currentTimeMillis(); long step2Start = System.currentTimeMillis();
if (Objects.nonNull(bmUnit) && Objects.nonNull(bmUnit.getEnableFilter()) && bmUnit.getEnableFilter()) { if (Objects.nonNull(bmUnit) && Objects.nonNull(bmUnit.getEnableFilter()) && bmUnit.getEnableFilter()) {
bmUnit.setDeptId(thisLoginUserDeptId); bmUnit.setDeptId(thisLoginUserDeptId);
} }
stepTimes.put("过滤判断", System.currentTimeMillis() - step2Start); stepTimes.put("过滤判断", System.currentTimeMillis() - step2Start);
// 步骤3: 判断是否是app模式 // 步骤3: 判断是否是app模式
if (bmUnit.getIsApp() != null && bmUnit.getIsApp()) { if (bmUnit.getIsApp() != null && bmUnit.getIsApp()) {
long appStart = System.currentTimeMillis(); long appStart = System.currentTimeMillis();
List<BmUnit> list = mapper.getUnitListApp(bmUnit); List<BmUnit> list = mapper.getUnitListApp(bmUnit);
stepTimes.put("App模式查询", System.currentTimeMillis() - appStart); stepTimes.put("App模式查询", System.currentTimeMillis() - appStart);
long totalTime = System.currentTimeMillis() - startTime; long totalTime = System.currentTimeMillis() - startTime;
DateTimeHelper.logPerformanceAnalysis("getUnitList(App模式)", totalTime, stepTimes); DateTimeHelper.logPerformanceAnalysis("getUnitList(App模式)", totalTime, stepTimes);
return AjaxResult.success(list); return AjaxResult.success(list);
} }
List<ProjectTreeNode> groupList = new ArrayList<>(); List<ProjectTreeNode> groupList = new ArrayList<>();
List<ProjectTreeNode> list; List<ProjectTreeNode> list;
try { try {
@ -92,7 +92,7 @@ public class SelectServiceImpl implements SelectService {
long dbStart = System.currentTimeMillis(); long dbStart = System.currentTimeMillis();
list = mapper.getUnitList(bmUnit); list = mapper.getUnitList(bmUnit);
stepTimes.put("数据库查询", System.currentTimeMillis() - dbStart); stepTimes.put("数据库查询", System.currentTimeMillis() - dbStart);
// 步骤5: 数据过滤 // 步骤5: 数据过滤
long filterStart = System.currentTimeMillis(); long filterStart = System.currentTimeMillis();
if (list != null) { if (list != null) {
@ -128,11 +128,11 @@ public class SelectServiceImpl implements SelectService {
} catch (Exception e) { } catch (Exception e) {
log.error("单位类型树-查询失败", e); log.error("单位类型树-查询失败", e);
} }
// 性能分析总结 // 性能分析总结
long totalTime = System.currentTimeMillis() - startTime; long totalTime = System.currentTimeMillis() - startTime;
DateTimeHelper.logPerformanceAnalysis("getUnitList", totalTime, stepTimes); DateTimeHelper.logPerformanceAnalysis("getUnitList", totalTime, stepTimes);
return AjaxResult.success(groupList); return AjaxResult.success(groupList);
} }
@ -414,19 +414,17 @@ public class SelectServiceImpl implements SelectService {
*/ */
@Override @Override
public AjaxResult getAgreementInfoByIdBack(SelectDto dto) { public AjaxResult getAgreementInfoByIdBack(SelectDto dto) {
AgreementVo vo = new AgreementVo(); List<AgreementVo> list = new ArrayList<>();
try { try {
if (dto != null && dto.getTeamId() != null) { if (dto != null && dto.getTeamId() != null) {
dto.setUnitId(Integer.parseInt(dto.getTeamId())); dto.setUnitId(Integer.parseInt(dto.getTeamId()));
} }
List<AgreementVo> list = mapper.getAgreementInfoByIdBack(dto); list = mapper.getAgreementInfoByIdBack(dto);
if (CollectionUtils.isNotEmpty(list)) {
vo = list.get(0);
}
} catch (Exception e) { } catch (Exception e) {
log.error("往来单位id和标段工程id获取协议信息", e); log.error("往来单位id和标段工程id获取协议信息", e);
} }
return AjaxResult.success(vo); return AjaxResult.success(list);
} }
/** /**
@ -817,19 +815,19 @@ public class SelectServiceImpl implements SelectService {
if (CollectionUtils.isEmpty(nodes)) { if (CollectionUtils.isEmpty(nodes)) {
return new ArrayList<>(); return new ArrayList<>();
} }
// 使用Map来存储节点提高查找效率 // 使用Map来存储节点提高查找效率
Map<String, ProjectTreeNode> nodeMap = new HashMap<>(); Map<String, ProjectTreeNode> nodeMap = new HashMap<>();
Map<String, List<ProjectTreeNode>> childrenMap = new HashMap<>(); Map<String, List<ProjectTreeNode>> childrenMap = new HashMap<>();
// 第一遍遍历建立Map索引 // 第一遍遍历建立Map索引
for (ProjectTreeNode node : nodes) { for (ProjectTreeNode node : nodes) {
nodeMap.put(node.getId(), node); nodeMap.put(node.getId(), node);
childrenMap.put(node.getId(), new ArrayList<>()); childrenMap.put(node.getId(), new ArrayList<>());
} }
List<ProjectTreeNode> rootNodes = new ArrayList<>(); List<ProjectTreeNode> rootNodes = new ArrayList<>();
// 第二遍遍历建立父子关系 // 第二遍遍历建立父子关系
for (ProjectTreeNode node : nodes) { for (ProjectTreeNode node : nodes) {
String parentId = node.getParentId(); String parentId = node.getParentId();
@ -844,13 +842,13 @@ public class SelectServiceImpl implements SelectService {
} }
} }
} }
// 第三遍遍历设置children // 第三遍遍历设置children
for (ProjectTreeNode node : nodes) { for (ProjectTreeNode node : nodes) {
List<ProjectTreeNode> children = childrenMap.get(node.getId()); List<ProjectTreeNode> children = childrenMap.get(node.getId());
node.setChildren(children); node.setChildren(children);
} }
return rootNodes; return rootNodes;
} }

View File

@ -214,11 +214,11 @@ public interface TypeMapper {
/** /**
* 批量查询数量 - 性能优化 * 批量查询数量 - 性能优化
* @param agreementId 协议ID * @param agreementIds 协议ID
* @param typeIds 类型ID列表 * @param typeIds 类型ID列表
* @return 类型使用数量列表 * @return 类型使用数量列表
*/ */
List<Type> getNumListBatch(@Param("agreementId") Long agreementId, @Param("typeIds") List<Long> typeIds); List<Type> getNumListBatch(@Param("agreementIds") List<Long> agreementIds, @Param("typeIds") List<Long> typeIds);
/** /**
* 查询物资类型管理绑定的用户列表 * 查询物资类型管理绑定的用户列表

View File

@ -61,7 +61,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</if> </if>
ORDER BY bai.agreement_id DESC ORDER BY bai.agreement_id DESC
</select> </select>
<select id="selectBmAgreementInfoByAgreementId" parameterType="Long" resultMap="BmAgreementInfoResult"> <select id="selectBmAgreementInfoByAgreementId" parameterType="Long" resultMap="BmAgreementInfoResult">
SELECT bai.agreement_id, bai.agreement_code , contract_code,sign_time, SELECT bai.agreement_id, bai.agreement_code , contract_code,sign_time,
bu.unit_id, bai.project_unit_id, bu.unit_name , bp.pro_id as projectId , bp.pro_name as projectName, bu.unit_id, bai.project_unit_id, bu.unit_name , bp.pro_id as projectId , bp.pro_name as projectName,
@ -73,7 +73,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where agreement_id = #{agreementId}) tta on bai.agreement_id = tta.agreement_id where agreement_id = #{agreementId}) tta on bai.agreement_id = tta.agreement_id
where bai.status = '1' and bai.agreement_id = #{agreementId} where bai.status = '1' and bai.agreement_id = #{agreementId}
</select> </select>
<insert id="insertBmAgreementInfo" parameterType="com.bonus.material.basic.domain.BmAgreementInfo" useGeneratedKeys="true" keyProperty="agreementId"> <insert id="insertBmAgreementInfo" parameterType="com.bonus.material.basic.domain.BmAgreementInfo" useGeneratedKeys="true" keyProperty="agreementId">
insert into bm_agreement_info (agreement_code, sign_time, unit_id, project_unit_id, insert into bm_agreement_info (agreement_code, sign_time, unit_id, project_unit_id,
project_id, create_by, lease_day, project_id, create_by, lease_day,
@ -140,7 +140,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</delete> </delete>
<delete id="deleteBmAgreementInfoByAgreementIds" parameterType="String"> <delete id="deleteBmAgreementInfoByAgreementIds" parameterType="String">
delete from bm_agreement_info where agreement_id in delete from bm_agreement_info where agreement_id in
<foreach item="agreementId" collection="array" open="(" separator="," close=")"> <foreach item="agreementId" collection="array" open="(" separator="," close=")">
#{agreementId} #{agreementId}
</foreach> </foreach>
@ -195,9 +195,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
WHERE WHERE
unit_id = #{unitId} unit_id = #{unitId}
and project_id = #{projectId} and project_id = #{projectId}
limit 1
</select> </select>
<select id="selectNumByMonthClz" resultType="java.lang.Integer"> <select id="selectNumByMonthClz" resultType="java.lang.Integer">
select count(*) from clz_bm_agreement_info where DATE_FORMAT(create_time,'%y%m') = DATE_FORMAT(#{date},'%y%m') select count(*) from clz_bm_agreement_info where DATE_FORMAT(create_time,'%y%m') = DATE_FORMAT(#{date},'%y%m')
</select> </select>
</mapper> </mapper>

View File

@ -731,7 +731,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
LEFT JOIN ma_type mt1 ON mt.parent_id = mt1.type_id and mt1.del_flag = '0' LEFT JOIN ma_type mt1 ON mt.parent_id = mt1.type_id and mt1.del_flag = '0'
LEFT JOIN clz_lease_apply_info clai ON sai.lease_id = clai.id LEFT JOIN clz_lease_apply_info clai ON sai.lease_id = clai.id
WHERE WHERE
sai.STATUS = '0' and sai.agreement_id = #{agreementId} sai.STATUS = '0'
<if test="agreementIds != null ">
and sai.agreement_id in
<foreach item="item" collection="agreementIds" open="(" separator="," close=")">
#{item}
</foreach>
</if>
GROUP BY GROUP BY
mt.type_id mt.type_id
</select> </select>
@ -853,4 +861,4 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</if> </if>
</select> </select>
</mapper> </mapper>

View File

@ -1128,19 +1128,24 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="getNumListBatch" resultType="com.bonus.material.ma.domain.Type"> <select id="getNumListBatch" resultType="com.bonus.material.ma.domain.Type">
SELECT SELECT
mt.type_id as typeId, mt.type_id as typeId,
SUM( CASE WHEN sai.agreement_id = #{agreementId} AND sai.STATUS = '0' THEN sai.num ELSE 0 END ) AS useNum SUM(sai.num) AS useNum
FROM FROM
ma_type mt ma_type mt
LEFT JOIN clz_slt_agreement_info sai ON mt.type_id = sai.type_id LEFT JOIN clz_slt_agreement_info sai ON mt.type_id = sai.type_id
WHERE WHERE
mt.type_id IN sai.STATUS = '0'
AND mt.type_id IN
<foreach collection="typeIds" item="typeId" open="(" separator="," close=")"> <foreach collection="typeIds" item="typeId" open="(" separator="," close=")">
#{typeId} #{typeId}
</foreach> </foreach>
AND EXISTS ( SELECT 1 FROM clz_slt_agreement_info sai2 WHERE sai2.type_id = mt.type_id AND sai2.agreement_id = #{agreementId} AND sai.agreement_id in
AND sai2.STATUS = '0' and sai2.num > 0) <foreach item="id" collection="agreementIds" open="(" separator="," close=")">
#{id}
</foreach>
GROUP BY GROUP BY
mt.type_id mt.type_id
HAVING
useNum > 0
</select> </select>
<select id="getUserList" resultType="com.bonus.material.ma.domain.vo.MaTypeVo"> <select id="getUserList" resultType="com.bonus.material.ma.domain.vo.MaTypeVo">

View File

@ -367,6 +367,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{task.taskId} #{task.taskId}
</foreach> </foreach>
</if> </if>
having costs > 0
</select> </select>
<select id="getScrapDetailsList" resultType="com.bonus.material.settlement.domain.SltAgreementInfo"> <select id="getScrapDetailsList" resultType="com.bonus.material.settlement.domain.SltAgreementInfo">
@ -403,6 +404,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{task.taskId} #{task.taskId}
</foreach> </foreach>
</if> </if>
having costs > 0
</select> </select>
<select id="getLoseList" resultType="com.bonus.material.settlement.domain.SltAgreementInfo"> <select id="getLoseList" resultType="com.bonus.material.settlement.domain.SltAgreementInfo">