1449 MPM同步物料图片及钢构包管理的接口开发
This commit is contained in:
parent
2fb3d6642d
commit
f6191d655f
|
|
@ -1,6 +1,7 @@
|
||||||
package com.nflg.wms.admin.controller;
|
package com.nflg.wms.admin.controller;
|
||||||
|
|
||||||
import com.nflg.wms.admin.service.MaterialControllerService;
|
import com.nflg.wms.admin.service.MaterialControllerService;
|
||||||
|
import com.nflg.wms.common.constant.STATE;
|
||||||
import com.nflg.wms.common.constant.UserType;
|
import com.nflg.wms.common.constant.UserType;
|
||||||
import com.nflg.wms.common.pojo.ApiResult;
|
import com.nflg.wms.common.pojo.ApiResult;
|
||||||
import com.nflg.wms.common.pojo.PageData;
|
import com.nflg.wms.common.pojo.PageData;
|
||||||
|
|
@ -19,6 +20,7 @@ import jakarta.validation.Valid;
|
||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
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;
|
||||||
|
|
@ -31,6 +33,7 @@ import java.util.Set;
|
||||||
/**
|
/**
|
||||||
* 图纸管理
|
* 图纸管理
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/material")
|
@RequestMapping("/material")
|
||||||
public class MaterialController extends BaseController {
|
public class MaterialController extends BaseController {
|
||||||
|
|
@ -182,7 +185,28 @@ public class MaterialController extends BaseController {
|
||||||
*/
|
*/
|
||||||
@PostMapping("/mpm/syncFromMpmBatch")
|
@PostMapping("/mpm/syncFromMpmBatch")
|
||||||
public ApiResult<Void> syncFromMpmBatch(/*@Valid */@RequestBody @NotEmpty List<MaterialAddQO> requests) {
|
public ApiResult<Void> syncFromMpmBatch(/*@Valid */@RequestBody @NotEmpty List<MaterialAddQO> requests) {
|
||||||
materialControllerService.syncFromMpmBatch(requests);
|
StringBuilder errorMessages = new StringBuilder();
|
||||||
return ApiResult.success();
|
int successCount = 0;
|
||||||
|
int failCount = 0;
|
||||||
|
|
||||||
|
for (MaterialAddQO request : requests) {
|
||||||
|
try {
|
||||||
|
materialControllerService.syncFromMpm(request);
|
||||||
|
successCount++;
|
||||||
|
} catch (Exception e) {
|
||||||
|
failCount++;
|
||||||
|
String errorMsg = String.format("[%s] %s; ", request.getNo(), e.getMessage());
|
||||||
|
errorMessages.append(errorMsg);
|
||||||
|
log.error("同步图纸失败: {}, 错误: {}", request.getNo(), e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (failCount > 0) {
|
||||||
|
String resultMsg = String.format("批量同步完成,成功%d条,失败%d条。失败详情: %s",
|
||||||
|
successCount, failCount, errorMessages.toString());
|
||||||
|
return ApiResult.error(STATE.BusinessError, resultMsg);
|
||||||
|
} else {
|
||||||
|
return ApiResult.success();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.nflg.wms.admin.controller;
|
package com.nflg.wms.admin.controller;
|
||||||
|
|
||||||
import com.nflg.wms.admin.service.StructuralPackageControllerService;
|
import com.nflg.wms.admin.service.StructuralPackageControllerService;
|
||||||
|
import com.nflg.wms.common.constant.STATE;
|
||||||
import com.nflg.wms.common.pojo.ApiResult;
|
import com.nflg.wms.common.pojo.ApiResult;
|
||||||
import com.nflg.wms.common.pojo.PageData;
|
import com.nflg.wms.common.pojo.PageData;
|
||||||
import com.nflg.wms.common.pojo.dto.PackageMaterialDTO;
|
import com.nflg.wms.common.pojo.dto.PackageMaterialDTO;
|
||||||
|
|
@ -13,6 +14,7 @@ import jakarta.validation.Valid;
|
||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
import jakarta.validation.constraints.NotEmpty;
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
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;
|
||||||
|
|
@ -23,6 +25,7 @@ import java.util.List;
|
||||||
/**
|
/**
|
||||||
* 钢构包管理
|
* 钢构包管理
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/package")
|
@RequestMapping("/package")
|
||||||
public class StructuralPackageController extends BaseController {
|
public class StructuralPackageController extends BaseController {
|
||||||
|
|
@ -144,8 +147,13 @@ public class StructuralPackageController extends BaseController {
|
||||||
*/
|
*/
|
||||||
@PostMapping("/mpm/syncFromMpm")
|
@PostMapping("/mpm/syncFromMpm")
|
||||||
public ApiResult<Void> syncFromMpm(/*@Valid */@RequestBody PackageAddQO request) {
|
public ApiResult<Void> syncFromMpm(/*@Valid */@RequestBody PackageAddQO request) {
|
||||||
packageControllerService.syncFromMpm(request);
|
try {
|
||||||
return ApiResult.success();
|
packageControllerService.syncFromMpm(request);
|
||||||
|
return ApiResult.success();
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("从MPM系统同步钢构包数据失败: {}, 错误: {}", request.getNo(), e.getMessage(), e);
|
||||||
|
return ApiResult.error(STATE.BusinessError, "同步失败: " + e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -153,8 +161,29 @@ public class StructuralPackageController extends BaseController {
|
||||||
*/
|
*/
|
||||||
@PostMapping("/mpm/syncFromMpmBatch")
|
@PostMapping("/mpm/syncFromMpmBatch")
|
||||||
public ApiResult<Void> syncFromMpmBatch(/*@Valid */@RequestBody @NotEmpty List<PackageAddQO> requests) {
|
public ApiResult<Void> syncFromMpmBatch(/*@Valid */@RequestBody @NotEmpty List<PackageAddQO> requests) {
|
||||||
packageControllerService.syncFromMpmBatch(requests);
|
StringBuilder errorMessages = new StringBuilder();
|
||||||
return ApiResult.success();
|
int successCount = 0;
|
||||||
|
int failCount = 0;
|
||||||
|
|
||||||
|
for (PackageAddQO request : requests) {
|
||||||
|
try {
|
||||||
|
packageControllerService.syncFromMpm(request);
|
||||||
|
successCount++;
|
||||||
|
} catch (Exception e) {
|
||||||
|
failCount++;
|
||||||
|
String errorMsg = String.format("[%s] %s; ", request.getNo(), e.getMessage());
|
||||||
|
errorMessages.append(errorMsg);
|
||||||
|
log.error("同步钢构包失败: {}, 错误: {}", request.getNo(), e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (failCount > 0) {
|
||||||
|
String resultMsg = String.format("批量同步完成,成功%d条,失败%d条。失败详情: %s",
|
||||||
|
successCount, failCount, errorMessages.toString());
|
||||||
|
return ApiResult.error(STATE.BusinessError, resultMsg);
|
||||||
|
} else {
|
||||||
|
return ApiResult.success();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
// /**
|
// /**
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ import org.apache.commons.lang3.math.NumberUtils;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.transaction.annotation.Propagation;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
import org.ttzero.excel.entity.ListSheet;
|
import org.ttzero.excel.entity.ListSheet;
|
||||||
|
|
@ -415,33 +416,21 @@ public class MaterialControllerService {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量从MPM系统同步图纸数据
|
* 从MPM系统同步图纸数据(单个)
|
||||||
* 每次推送都是新版本,直接新增
|
* 每次推送都是新版本,直接新增
|
||||||
*/
|
*/
|
||||||
@Transactional
|
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
||||||
public void syncFromMpmBatch(@Valid @NotEmpty List<MaterialAddQO> requests) {
|
public void syncFromMpm(@Valid MaterialAddQO request) {
|
||||||
log.info("开始批量从MPM系统同步图纸数据,共{}条", requests.size());
|
log.info("开始从MPM系统同步图纸数据: {}", request.getNo());
|
||||||
|
|
||||||
for (MaterialAddQO request : requests) {
|
WmsMaterial wmsMaterial = Convert.convert(WmsMaterial.class, request);
|
||||||
try {
|
wmsMaterial.setCreateBy("MPM_SYNC");
|
||||||
log.info("开始从MPM系统同步图纸数据: {}", request.getNo());
|
wmsMaterial.setCreateTime(LocalDateTime.now());
|
||||||
|
wmsMaterial.setFromMpm(true); // 标记为来自MPM
|
||||||
WmsMaterial wmsMaterial = Convert.convert(WmsMaterial.class, request);
|
|
||||||
|
|
||||||
wmsMaterial.setCreateBy("MPM_SYNC");
|
|
||||||
wmsMaterial.setCreateTime(LocalDateTime.now());
|
|
||||||
wmsMaterial.setFromMpm(true); // 标记为来自MPM
|
|
||||||
|
|
||||||
materialService.add(wmsMaterial);
|
|
||||||
|
|
||||||
log.info("成功从MPM系统同步图纸数据: {}, 版本: {}", request.getNo(), wmsMaterial.getVersion());
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("同步图纸失败: {}, 错误: {}", request.getNo(), e.getMessage(), e);
|
|
||||||
// 继续处理下一条,不中断整个批量同步
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
log.info("批量从MPM系统同步图纸数据完成");
|
materialService.add(wmsMaterial);
|
||||||
|
|
||||||
|
log.info("成功从MPM系统同步图纸数据: {}, 版本: {}", request.getNo(), wmsMaterial.getVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -76,4 +76,8 @@ public class MaterialAddQO {
|
||||||
* 版本号
|
* 版本号
|
||||||
*/
|
*/
|
||||||
private String version;
|
private String version;
|
||||||
|
|
||||||
|
private String filename;
|
||||||
|
|
||||||
|
private String fileindex;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue