feat(material): 添加主物料系统同步功能

- 修改BomMaterialService#getList返回MaterialMainDTO列表
- 新增MaterialMainDTO的drawingNoVer字段及其getter方法
- 在QmsQcMaterialController添加同步主物料接口syncFromMain
- 实现QmsQcMaterialControllerService的syncFromMain方法,用于同步主物料信息
- 同步时根据物料编号和图号版本号匹配更新质检物料详细信息
- 添加方法参数有效性校验以及日志打印优化
This commit is contained in:
曹鹏飞 2026-04-20 13:54:02 +08:00
parent 6f231f1a60
commit 0d84c188ac
4 changed files with 60 additions and 5 deletions

View File

@ -13,12 +13,14 @@ import com.nflg.wms.starter.BaseController;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid; import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.io.IOException; import java.io.IOException;
import java.util.List;
/** /**
* 质检物料管理 * 质检物料管理
@ -97,4 +99,13 @@ public class QmsQcMaterialController extends BaseController {
public ApiResult<PageData<MaterialMainDTO>> searchBomMaterial(@Valid @RequestBody BomMaterialListQO request){ public ApiResult<PageData<MaterialMainDTO>> searchBomMaterial(@Valid @RequestBody BomMaterialListQO request){
return ApiResult.success(qcMaterialControllerService.searchBomMaterial(request)); return ApiResult.success(qcMaterialControllerService.searchBomMaterial(request));
} }
/**
* 从主物料系统同步物料信息
*/
@PostMapping("syncFromMain")
public ApiResult<Void> syncFromMain(@RequestBody @NotEmpty List<Long> ids){
qcMaterialControllerService.syncFromMain(ids);
return ApiResult.success();
}
} }

View File

@ -31,6 +31,7 @@ import com.nflg.wms.starter.service.FileUploadService;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid; import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
@ -45,6 +46,8 @@ import java.time.LocalDateTime;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
/** /**
* 质检物料业务逻辑 * 质检物料业务逻辑
@ -349,7 +352,7 @@ public class QmsQcMaterialControllerService {
private QmsQcMaterial findByCompositeKey(String materialNo, String drawingNoVer) { private QmsQcMaterial findByCompositeKey(String materialNo, String drawingNoVer) {
return qcMaterialService.lambdaQuery() return qcMaterialService.lambdaQuery()
.eq(QmsQcMaterial::getMaterialNo, materialNo) .eq(QmsQcMaterial::getMaterialNo, materialNo)
.and(StrUtil.isBlank(drawingNoVer), .and(StrUtil.isBlank(drawingNoVer),
q -> q.isNull(QmsQcMaterial::getDrawingNoVer) q -> q.isNull(QmsQcMaterial::getDrawingNoVer)
.or() .or()
.eq(QmsQcMaterial::getDrawingNoVer, "")) .eq(QmsQcMaterial::getDrawingNoVer, ""))
@ -441,4 +444,32 @@ public class QmsQcMaterialControllerService {
.setTotal((int) bomPageResultDTO.getTotal()) .setTotal((int) bomPageResultDTO.getTotal())
.setItems(bomPageResultDTO.getRecords()); .setItems(bomPageResultDTO.getRecords());
} }
public void syncFromMain(@NotEmpty List<Long> ids) {
List<QmsQcMaterial> list = qcMaterialService.listByIds(ids);
if (CollectionUtil.isNotEmpty(list)) {
List<MaterialMainDTO> datas = bomMaterialService.getList(list.stream().map(QmsQcMaterial::getMaterialNo).collect(Collectors.toList()));
datas.forEach(data -> {
QmsQcMaterial qcMaterial = list.stream()
.filter(item -> item.getMaterialNo().equals(data.getMaterialNo())
&& StrUtil.equals(item.getDrawingNoVer(), data.getDrawingNoVer())
)
.findFirst()
.orElse(null);
if (Objects.nonNull(qcMaterial)) {
qcMaterial.setMaterialDescIsUpgrade(!StrUtil.equals(qcMaterial.getMaterialDesc(), data.getMaterialDesc()));
qcMaterial.setMaterialName(data.getMaterialName());
qcMaterial.setMaterialDesc(data.getMaterialDesc());
qcMaterial.setMaterialSpecifications(data.getMaterialSpecifications());
qcMaterial.setDrawingNo(data.getDrawingNo());
qcMaterial.setMaterialCategoryCode(data.getSecondMaterialCategoryCode());
qcMaterial.setMaterialCategoryCodePathName(data.getOldCategoryNameTree());
qcMaterial.setUpdateBy(UserUtil.getUserId());
qcMaterial.setUpdateByName(UserUtil.getUserName());
qcMaterial.setUpdateTime(LocalDateTime.now());
}
});
qcMaterialService.updateBatchById(list);
}
}
} }

View File

@ -1,5 +1,6 @@
package com.nflg.wms.common.pojo.dto; package com.nflg.wms.common.pojo.dto;
import cn.hutool.core.util.StrUtil;
import lombok.Data; import lombok.Data;
@Data @Data
@ -51,4 +52,13 @@ public class MaterialMainDTO {
* 物料规格 * 物料规格
*/ */
private String materialSpecifications; private String materialSpecifications;
/**
* 图号版本号
*/
private String drawingNoVer;
public String getDrawingNoVer() {
return StrUtil.isBlank(drawingNoVer) ? "" : drawingNoVer;
}
} }

View File

@ -82,7 +82,7 @@ public class BomMaterialService {
return resultDTO.getData(); return resultDTO.getData();
} }
public List<BomMaterialDTO> getList(Collection<String> nos) { public List<MaterialMainDTO> getList(Collection<String> nos) {
log.info("查询主物料系统参数:" + JSONUtil.toJsonStr(nos)); log.info("查询主物料系统参数:" + JSONUtil.toJsonStr(nos));
if (CollectionUtil.isEmpty(nos)) { if (CollectionUtil.isEmpty(nos)) {
return Collections.emptyList(); return Collections.emptyList();
@ -91,7 +91,7 @@ public class BomMaterialService {
headers.setContentType(MediaType.APPLICATION_JSON); headers.setContentType(MediaType.APPLICATION_JSON);
headers.add("authorization", getToken()); headers.add("authorization", getToken());
HttpEntity<Collection<String>> requestEntity = new HttpEntity<>(nos, headers); HttpEntity<Collection<String>> requestEntity = new HttpEntity<>(nos, headers);
ResponseEntity<BomResultDTO<List<BomMaterialDTO>>> response = restTemplate.exchange( ResponseEntity<BomResultDTO<List<MaterialMainDTO>>> response = restTemplate.exchange(
baseUrl + materialListUrl, baseUrl + materialListUrl,
HttpMethod.POST, HttpMethod.POST,
requestEntity, requestEntity,
@ -101,8 +101,11 @@ public class BomMaterialService {
log.info("查询主物料系统返回状态码:" + response.getStatusCode().value()); log.info("查询主物料系统返回状态码:" + response.getStatusCode().value());
VUtil.trueThrowBusinessError(!response.getStatusCode().is2xxSuccessful()) VUtil.trueThrowBusinessError(!response.getStatusCode().is2xxSuccessful())
.throwMessage("查询主物料系统失败"); .throwMessage("查询主物料系统失败");
BomResultDTO<List<BomMaterialDTO>> resultDTO = response.getBody(); BomResultDTO<List<MaterialMainDTO>> resultDTO = response.getBody();
log.info("查询主物料系统返回数据:" + (Objects.nonNull(resultDTO.getData())&&resultDTO.getData().size()>1000?"数据超过1000条不打印":JSONUtil.toJsonStr(resultDTO))); log.info("查询主物料系统返回数据:" + (Objects.nonNull(resultDTO.getData()) && resultDTO.getData().size() > 1000
? "数据超过1000条不打印"
: JSONUtil.toJsonStr(resultDTO
)));
return Optional.ofNullable(resultDTO.getData()).orElse(Collections.emptyList()); return Optional.ofNullable(resultDTO.getData()).orElse(Collections.emptyList());
} }