diff --git a/bonus-common-biz/src/main/java/com/bonus/common/biz/domain/ProjectTreeNode.java b/bonus-common-biz/src/main/java/com/bonus/common/biz/domain/ProjectTreeNode.java index 106df49b..31c4887d 100644 --- a/bonus-common-biz/src/main/java/com/bonus/common/biz/domain/ProjectTreeNode.java +++ b/bonus-common-biz/src/main/java/com/bonus/common/biz/domain/ProjectTreeNode.java @@ -24,6 +24,26 @@ public class ProjectTreeNode { private String typeKey; + /** + * 班组长id + */ + private String teamLeaderIdCard; + + /** + * 班组长姓名 + */ + private String relName; + + /** + * 班组长手机号 + */ + private String relPhone; + + /** + * 工程id + */ + private String projectId; + @JsonInclude(JsonInclude.Include.NON_EMPTY) private List children = new ArrayList<>(); } diff --git a/bonus-common-biz/src/main/java/com/bonus/common/biz/utils/HttpHelper.java b/bonus-common-biz/src/main/java/com/bonus/common/biz/utils/HttpHelper.java index ca95c135..e2f29c90 100644 --- a/bonus-common-biz/src/main/java/com/bonus/common/biz/utils/HttpHelper.java +++ b/bonus-common-biz/src/main/java/com/bonus/common/biz/utils/HttpHelper.java @@ -191,7 +191,8 @@ public class HttpHelper { */ private static String getToken() { // String tokenUrl = "http://10.138.55.113:8036/micro-server/zygqj/generatcorToekn"; - String tokenUrl = "http://10.138.55.113:8036/micro-server/zygqj/generatcorToekn"; + // String tokenUrl = "http://10.138.55.113:8036/micro-server/zygqj/generatcorToekn"; + String tokenUrl = "http://10.99.30.251:8036/micro-server/zygqj/generatcorToekn"; try { String loginName= SecurityUtils.getLoginUser().getSysUser().getUserName(); diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/common/mapper/SelectMapper.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/common/mapper/SelectMapper.java index 59cc6a3a..acd8b4b1 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/common/mapper/SelectMapper.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/common/mapper/SelectMapper.java @@ -413,4 +413,11 @@ public interface SelectMapper { * @return */ List getClzAgreementId(MaterialRetainedEquipmentInfo info); + + /** + * 根据领料id查询i8工程id + * @param bean + * @return + */ + ProAuthorizeInfo selectProAuthorizeInfo(ProAuthorizeInfo bean); } 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 ce5d2202..15d075dd 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 @@ -12,14 +12,13 @@ import com.bonus.material.ma.service.DirectRotationService; import com.bonus.material.settlement.domain.SltAgreementInfo; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; +import java.util.*; /** @@ -30,6 +29,7 @@ import java.util.List; @Api(tags = " 直转申请") @RestController @RequestMapping("/directRotation") +@Slf4j public class DirectRotationController extends BaseController { @Resource(name = "directRotationService") @@ -45,42 +45,74 @@ public class DirectRotationController extends BaseController { List datas = new ArrayList<>(); List useringData = service.getUseringData(sltAgreementInfo); Integer projectId = service.getprojectId(sltAgreementInfo); - // 根据项目获取材料站在用机具 List useringDataClz = service.getUseringDataByClz(projectId); - Iterator iterator = useringData.iterator(); - while (iterator.hasNext()) { - SltAgreementInfo useringDatum = iterator.next(); + // 1. 构建typeId -> 材料站数据的映射(同之前) + Map> clzMap = new HashMap<>(); + for (SltAgreementInfo clzInfo : useringDataClz) { + Long typeId = clzInfo.getTypeId(); + clzMap.computeIfAbsent(typeId, k -> new ArrayList<>()).add(clzInfo); + } + // 2. 批量查询待审核数量:收集所有必要参数,一次查库 + Set 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 pairs = new ArrayList<>(pairSet); + // 批量查询待转数量 + List batchInfoList = service.getBatchInfo(sltAgreementInfo.getAgreementId(),pairs); + // 构建infoMap:key = "typeId:maId",value = 对应的SltAgreementInfo(含waitTransNum) + Map 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; - for (SltAgreementInfo agreementInfo : useringDataClz) { - if (useringDatum.getTypeId().equals(agreementInfo.getTypeId())) { - if (useringDatum.getMaId() == null && agreementInfo.getMaId() == null) { - if (useringDatum.getUseNum().compareTo(agreementInfo.getUseNum()) > 0) { - useringDatum.setUseNum(useringDatum.getUseNum().subtract(agreementInfo.getUseNum())); + Long dataTypeId = data.getTypeId(); + List matchedClzList = clzMap.get(dataTypeId); + if (matchedClzList != null && !matchedClzList.isEmpty()) { + for (SltAgreementInfo clzInfo : matchedClzList) { + 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 { shouldAdd = false; break; } - } else if (useringDatum.getMaId() != null && useringDatum.getMaId().equals(agreementInfo.getMaId())) { + } else if (Objects.equals(data.getMaId(), clzInfo.getMaId())) { shouldAdd = false; break; } } } - // 根据协议以及类型id查询待审核数量 - SltAgreementInfo info = service.getInfo(useringDatum); + // 4. 从批量查询结果中获取数据(O(1)查询) + String infoKey = data.getTypeId() + ":" + (data.getMaId() == null ? "null" : data.getMaId()); + SltAgreementInfo info = infoMap.get(infoKey); if (info != null) { - useringDatum.setWaitTransNum(info.getWaitTransNum()); - useringDatum.setTransNum(useringDatum.getUseNum().subtract(useringDatum.getWaitTransNum())); + data.setWaitTransNum(info.getWaitTransNum()); + data.setTransNum(data.getUseNum().subtract(info.getWaitTransNum())); } else { - useringDatum.setWaitTransNum(BigDecimal.ZERO); - useringDatum.setTransNum(useringDatum.getUseNum()); + data.setWaitTransNum(BigDecimal.ZERO); + data.setTransNum(data.getUseNum()); } if (shouldAdd) { - datas.add(useringDatum); + datas.add(data); } } return AjaxResult.success(datas); } catch (Exception e) { + log.error("查询失败", e); return AjaxResult.success(new ArrayList<>()); } } diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/mapper/DirectRotationMapper.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/mapper/DirectRotationMapper.java index b706f614..04639b85 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/mapper/DirectRotationMapper.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/ma/mapper/DirectRotationMapper.java @@ -108,4 +108,12 @@ public interface DirectRotationMapper { * @return */ SltAgreementInfo getInfo(SltAgreementInfo useringDatum); + + /** + * 批量查询 + * @param agreementId + * @param list + * @return + */ + List getBatchInfo(@Param("agreementId") Long agreementId, @Param("pairs")List list); } 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 7234d655..af66b1f7 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 @@ -106,4 +106,12 @@ public interface DirectRotationService { * @return */ SltAgreementInfo getInfo(SltAgreementInfo useringDatum); + + /** + * 批量查询待转数量 + * @param agreementId + * @param list + * @return + */ + List getBatchInfo(Long agreementId, List list); } 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 b7846023..6769fb14 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 @@ -550,6 +550,17 @@ public class DirectRotationImpl implements DirectRotationService { return mapper.getInfo(useringDatum); } + /** + * 批量查询协议信息 + * @param agreementId + * @param list + * @return + */ + @Override + public List getBatchInfo(Long agreementId, List list) { + return mapper.getBatchInfo(agreementId, list); + } + // 将签名分类的逻辑提取到一个单独的方法 private void classifySignature(ClzDirectApplyInfo clzDirectApplyInfo, LeaseOutSign leaseOutSign, List list1, List list2, List list3) { diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/materialStation/domain/ProAuthorizeInfo.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/materialStation/domain/ProAuthorizeInfo.java index 7a0638eb..3db7c535 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/materialStation/domain/ProAuthorizeInfo.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/materialStation/domain/ProAuthorizeInfo.java @@ -28,7 +28,7 @@ public class ProAuthorizeInfo { /** * 班组id */ - private Long teamId; + private String teamId; /** * 班组名称 diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/materialStation/service/impl/ProAuthorizeServiceImpl.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/materialStation/service/impl/ProAuthorizeServiceImpl.java index 4a1c094c..0962ac16 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/materialStation/service/impl/ProAuthorizeServiceImpl.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/materialStation/service/impl/ProAuthorizeServiceImpl.java @@ -1,18 +1,24 @@ package com.bonus.material.materialStation.service.impl; 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.LeasePublishInfo; +import com.bonus.common.biz.enums.HttpCodeEnum; import com.bonus.common.core.domain.R; 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.clz.domain.BmTeam; 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.materialStation.domain.ProAuthorizeDetails; import com.bonus.material.materialStation.domain.ProAuthorizeInfo; import com.bonus.material.materialStation.mapper.ProAuthorizeMapper; import com.bonus.material.materialStation.service.ProAuthorizeService; +import com.google.common.net.MediaType; import lombok.extern.slf4j.Slf4j; import okhttp3.*; import org.apache.commons.io.IOUtils; @@ -60,6 +66,9 @@ public class ProAuthorizeServiceImpl implements ProAuthorizeService { @Resource(name = "SelectMapper") private SelectMapper selectMapper; + @Resource + private BmTeamMapper bmTeamMapper; + @Override public List getPublishList(LeaseApplyInfo leaseApplyInfo) { @@ -162,8 +171,8 @@ public class ProAuthorizeServiceImpl implements ProAuthorizeService { public AjaxResult authorizeSubmit(ProAuthorizeInfo bean) { try { String userId = SecurityUtils.getLoginUser().getUserid().toString(); - bean.setCreateBy(userId); if (bean != null) { + bean.setCreateBy(userId); if (bean.getAuthId() != null) { //修改 //删除详情数据 @@ -175,6 +184,37 @@ public class ProAuthorizeServiceImpl implements ProAuthorizeService { } else { for (Long lesaeId : bean.getLeaseIds()){ bean.setLeaseId(lesaeId); + // 根据领料id查询i8工程id + ProAuthorizeInfo info = selectMapper.selectProAuthorizeInfo(bean); + // 根据i8工程id以及班组名称查询班组信息 + if (info != null) { + bean.setExternalId(info.getExternalId()); + } + List 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); if (res > 0 && bean.getId() != null) { diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/service/impl/IwsCostPushServiceImpl.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/service/impl/IwsCostPushServiceImpl.java index 2a75c3b9..003017a9 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/service/impl/IwsCostPushServiceImpl.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/service/impl/IwsCostPushServiceImpl.java @@ -786,7 +786,8 @@ public class IwsCostPushServiceImpl implements IwsCostPushService { map.put("body", encrypt); String body = JSONObject.toJSONString(map); // String url = "http://10.138.55.113:8036/micro-server/zygqj/syncProjectCostsData"; - String url = "http://10.138.55.113:8036/micro-server/zygqj/syncProjectCostsData"; + //String url = "http://10.138.55.113:8036/micro-server/zygqj/syncProjectCostsData"; + String url = "http://10.99.30.251:8036/micro-server/zygqj/syncProjectCostsData"; String data = HttpHelper.sendHttpPostPushCost(url, body); System.err.println("dataString-=========:" + data); diff --git a/bonus-modules/bonus-material/src/main/resources/mapper/material/clz/BmTeamMapper.xml b/bonus-modules/bonus-material/src/main/resources/mapper/material/clz/BmTeamMapper.xml index dbfc18cc..5b4f117c 100644 --- a/bonus-modules/bonus-material/src/main/resources/mapper/material/clz/BmTeamMapper.xml +++ b/bonus-modules/bonus-material/src/main/resources/mapper/material/clz/BmTeamMapper.xml @@ -103,6 +103,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and unit_name = #{teamName} + + and bzz_idcard = #{idCard} + Limit 1 diff --git a/bonus-modules/bonus-material/src/main/resources/mapper/material/common/SelectMapper.xml b/bonus-modules/bonus-material/src/main/resources/mapper/material/common/SelectMapper.xml index 9b29b178..0b551412 100644 --- a/bonus-modules/bonus-material/src/main/resources/mapper/material/common/SelectMapper.xml +++ b/bonus-modules/bonus-material/src/main/resources/mapper/material/common/SelectMapper.xml @@ -1166,16 +1166,24 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + diff --git a/bonus-modules/bonus-material/src/main/resources/mapper/material/ma/DirectRotationMapper.xml b/bonus-modules/bonus-material/src/main/resources/mapper/material/ma/DirectRotationMapper.xml index 429ded46..52709431 100644 --- a/bonus-modules/bonus-material/src/main/resources/mapper/material/ma/DirectRotationMapper.xml +++ b/bonus-modules/bonus-material/src/main/resources/mapper/material/ma/DirectRotationMapper.xml @@ -379,4 +379,32 @@ HAVING waitTransNum > 0 + diff --git a/bonus-modules/bonus-material/src/main/resources/mapper/material/ma/TypeMapper.xml b/bonus-modules/bonus-material/src/main/resources/mapper/material/ma/TypeMapper.xml index e3d14879..ccb33f69 100644 --- a/bonus-modules/bonus-material/src/main/resources/mapper/material/ma/TypeMapper.xml +++ b/bonus-modules/bonus-material/src/main/resources/mapper/material/ma/TypeMapper.xml @@ -1056,29 +1056,58 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" select lease_price from ma_type where type_id = #{typeId}