feat: 实现ERP子卷同步接口
This commit is contained in:
@@ -3,6 +3,8 @@ package cn.code.nl.module.lms.controller.erp;
|
||||
import cn.code.nl.framework.tenant.core.aop.TenantIgnore;
|
||||
import cn.code.nl.module.lms.controller.erp.vo.ErpDailyPlanPushReqVO;
|
||||
import cn.code.nl.module.lms.controller.erp.vo.ErpRawFoilRollPushReqVO;
|
||||
import cn.code.nl.module.lms.controller.erp.vo.ErpSubRollQualityReqVO;
|
||||
import cn.code.nl.module.lms.controller.erp.vo.ErpSubRollSyncReqVO;
|
||||
import cn.code.nl.module.lms.service.erp.ErpAccessService;
|
||||
import cn.code.nl.module.lms.service.erp.ErpInboundService;
|
||||
import jakarta.annotation.Resource;
|
||||
@@ -35,4 +37,20 @@ public class ErpInboundController {
|
||||
return ErpResult.success(erpAccessService.execute(authorization,
|
||||
() -> erpInboundService.pushDailyPlan(reqVO)));
|
||||
}
|
||||
|
||||
/** 同步 ERP 子卷号到点位当前内部子卷。 */
|
||||
@PostMapping("/erp/sub-roll/sync")
|
||||
public ErpResult<String> syncSubRoll(@RequestHeader("Authorization") String authorization,
|
||||
@Valid @RequestBody ErpSubRollSyncReqVO reqVO) {
|
||||
return ErpResult.success(erpAccessService.execute(authorization,
|
||||
() -> erpInboundService.syncSubRoll(reqVO)));
|
||||
}
|
||||
|
||||
/** 同步 ERP 子卷质检结果。 */
|
||||
@PostMapping("/erp/sub-roll/quality-result")
|
||||
public ErpResult<String> syncSubRollQuality(@RequestHeader("Authorization") String authorization,
|
||||
@Valid @RequestBody ErpSubRollQualityReqVO reqVO) {
|
||||
return ErpResult.success(erpAccessService.execute(authorization,
|
||||
() -> erpInboundService.syncSubRollQuality(reqVO)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package cn.code.nl.module.lms.controller.erp.vo;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Data;
|
||||
|
||||
/** ERP 子卷质检结果请求。 */
|
||||
@Data
|
||||
public class ErpSubRollQualityReqVO {
|
||||
/** ERP 子卷号。 */
|
||||
@NotBlank(message = "子卷号不能为空")
|
||||
@Size(max = 64, message = "子卷号长度不能超过64个字符")
|
||||
private String subRollNo;
|
||||
/** ERP 质检结果,不做码值转换。 */
|
||||
@NotBlank(message = "质检结果不能为空")
|
||||
@Size(max = 64, message = "质检结果长度不能超过64个字符")
|
||||
private String qualified;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package cn.code.nl.module.lms.controller.erp.vo;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Data;
|
||||
|
||||
/** ERP 子卷号同步请求。 */
|
||||
@Data
|
||||
public class ErpSubRollSyncReqVO {
|
||||
/** ERP 子卷号。 */
|
||||
@NotBlank(message = "子卷号不能为空")
|
||||
@Size(max = 64, message = "子卷号长度不能超过64个字符")
|
||||
private String subRollNo;
|
||||
/** 当前点位编码。 */
|
||||
@NotBlank(message = "点位编码不能为空")
|
||||
@Size(max = 64, message = "点位编码长度不能超过64个字符")
|
||||
private String pointCode;
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import cn.code.nl.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.code.nl.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.code.nl.module.lms.controller.admin.packagepoint.vo.PackagePointPageReqVO;
|
||||
import cn.code.nl.module.lms.dal.dataobject.packagepoint.PackagePointDO;
|
||||
import cn.code.nl.module.lms.dal.dataobject.slittingproductionplan.SlittingproductionplanDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -19,6 +20,9 @@ import java.util.List;
|
||||
@Mapper
|
||||
public interface PackagePointMapper extends BaseMapperX<PackagePointDO> {
|
||||
|
||||
/** 锁定点位并查询其当前内部子卷记录。 */
|
||||
List<SlittingproductionplanDO> selectCurrentSubRollListForUpdate(@Param("pointCode") String pointCode);
|
||||
|
||||
/**
|
||||
* 根据点位编码查询点位
|
||||
*
|
||||
|
||||
@@ -58,6 +58,10 @@ public interface SlittingproductionplanMapper extends BaseMapperX<Slittingproduc
|
||||
SlittingproductionplanDO selectByExtContainerName(
|
||||
@Param("extContainerName") String extContainerName);
|
||||
|
||||
/** 根据 ERP 子卷号查询全部匹配记录,用于识别历史歧义数据。 */
|
||||
List<SlittingproductionplanDO> selectListByExtContainerName(
|
||||
@Param("extContainerName") String extContainerName);
|
||||
|
||||
/**
|
||||
* 根据内部子卷号查询分切生产计划
|
||||
*
|
||||
@@ -67,5 +71,15 @@ public interface SlittingproductionplanMapper extends BaseMapperX<Slittingproduc
|
||||
SlittingproductionplanDO selectByInnerContainerName(
|
||||
@Param("containerName") String containerName);
|
||||
|
||||
/** 条件绑定 ERP 子卷号,避免并发覆盖。 */
|
||||
int bindExtContainerName(@Param("workorderId") String workorderId,
|
||||
@Param("extContainerName") String extContainerName,
|
||||
@Param("updater") String updater);
|
||||
|
||||
/** 原样更新 ERP 质检结果。 */
|
||||
int updateErpQualityResult(@Param("workorderId") String workorderId,
|
||||
@Param("erpQualityResult") String erpQualityResult,
|
||||
@Param("updater") String updater);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -2,9 +2,13 @@ package cn.code.nl.module.lms.service.erp;
|
||||
|
||||
import cn.code.nl.module.lms.controller.erp.vo.ErpDailyPlanPushReqVO;
|
||||
import cn.code.nl.module.lms.controller.erp.vo.ErpRawFoilRollPushReqVO;
|
||||
import cn.code.nl.module.lms.controller.erp.vo.ErpSubRollQualityReqVO;
|
||||
import cn.code.nl.module.lms.controller.erp.vo.ErpSubRollSyncReqVO;
|
||||
|
||||
/** ERP 入站业务服务。 */
|
||||
public interface ErpInboundService {
|
||||
String pushRawFoilRoll(ErpRawFoilRollPushReqVO reqVO);
|
||||
String pushDailyPlan(ErpDailyPlanPushReqVO reqVO);
|
||||
String syncSubRoll(ErpSubRollSyncReqVO reqVO);
|
||||
String syncSubRollQuality(ErpSubRollQualityReqVO reqVO);
|
||||
}
|
||||
|
||||
@@ -7,10 +7,15 @@ import cn.code.nl.module.base.api.materialbase.MaterialBaseApi;
|
||||
import cn.code.nl.module.base.api.materialbase.dto.MaterialBaseRespDTO;
|
||||
import cn.code.nl.module.lms.controller.erp.vo.ErpDailyPlanPushReqVO;
|
||||
import cn.code.nl.module.lms.controller.erp.vo.ErpRawFoilRollPushReqVO;
|
||||
import cn.code.nl.module.lms.controller.erp.vo.ErpSubRollQualityReqVO;
|
||||
import cn.code.nl.module.lms.controller.erp.vo.ErpSubRollSyncReqVO;
|
||||
import cn.code.nl.module.lms.dal.dataobject.dailyplan.DailyPlanDO;
|
||||
import cn.code.nl.module.lms.dal.dataobject.rawfoilworkorder.RawFoilWorkOrderDO;
|
||||
import cn.code.nl.module.lms.dal.dataobject.slittingproductionplan.SlittingproductionplanDO;
|
||||
import cn.code.nl.module.lms.dal.mysql.dailyplan.DailyPlanMapper;
|
||||
import cn.code.nl.module.lms.dal.mysql.rawfoilworkorder.RawFoilWorkOrderMapper;
|
||||
import cn.code.nl.module.lms.dal.mysql.packagepoint.PackagePointMapper;
|
||||
import cn.code.nl.module.lms.dal.mysql.slittingproductionplan.SlittingproductionplanMapper;
|
||||
import cn.code.nl.module.lms.enums.DailyPlanOrderStatusEnum;
|
||||
import cn.code.nl.module.lms.enums.DailyPlanSourceTypeEnum;
|
||||
import cn.code.nl.module.lms.enums.RawFoilWorkOrderStatusEnum;
|
||||
@@ -22,9 +27,11 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.TransactionDefinition;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.List;
|
||||
|
||||
/** ERP 入站业务服务实现。 */
|
||||
@Service
|
||||
@@ -36,6 +43,8 @@ public class ErpInboundServiceImpl implements ErpInboundService {
|
||||
@Resource private MaterialBaseApi materialBaseApi;
|
||||
@Resource private CodeGenApi codeGenApi;
|
||||
@Resource private PlatformTransactionManager transactionManager;
|
||||
@Resource private PackagePointMapper packagePointMapper;
|
||||
@Resource private SlittingproductionplanMapper slittingproductionplanMapper;
|
||||
|
||||
@Override
|
||||
public String pushRawFoilRoll(ErpRawFoilRollPushReqVO reqVO) {
|
||||
@@ -110,6 +119,60 @@ public class ErpInboundServiceImpl implements ErpInboundService {
|
||||
return plan.getPlanCode();
|
||||
}
|
||||
|
||||
/** 将 ERP 子卷号绑定到点位当前唯一内部子卷。 */
|
||||
@Override
|
||||
public String syncSubRoll(ErpSubRollSyncReqVO reqVO) {
|
||||
return newTransaction().execute(status -> {
|
||||
List<SlittingproductionplanDO> pointPlans = packagePointMapper
|
||||
.selectCurrentSubRollListForUpdate(reqVO.getPointCode());
|
||||
if (CollectionUtils.isEmpty(pointPlans)) {
|
||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "点位不存在或当前没有子卷");
|
||||
}
|
||||
if (pointPlans.size() != 1) {
|
||||
throw badRequest("点位匹配到多条子卷记录");
|
||||
}
|
||||
SlittingproductionplanDO pointPlan = pointPlans.get(0);
|
||||
List<SlittingproductionplanDO> boundPlans = slittingproductionplanMapper
|
||||
.selectListByExtContainerName(reqVO.getSubRollNo());
|
||||
if (boundPlans.size() > 1 || boundPlans.size() == 1
|
||||
&& !Objects.equals(boundPlans.get(0).getWorkorderId(), pointPlan.getWorkorderId())) {
|
||||
throw badRequest("ERP子卷号已绑定其他内部子卷");
|
||||
}
|
||||
if (Objects.equals(pointPlan.getExtContainerName(), reqVO.getSubRollNo())) {
|
||||
return reqVO.getSubRollNo();
|
||||
}
|
||||
if (slittingproductionplanMapper.bindExtContainerName(pointPlan.getWorkorderId(),
|
||||
reqVO.getSubRollNo(), ERP_OPERATOR) != 1) {
|
||||
throw badRequest("子卷号绑定冲突");
|
||||
}
|
||||
return reqVO.getSubRollNo();
|
||||
});
|
||||
}
|
||||
|
||||
/** 原样同步 ERP 子卷质检结果。 */
|
||||
@Override
|
||||
public String syncSubRollQuality(ErpSubRollQualityReqVO reqVO) {
|
||||
return newTransaction().execute(status -> {
|
||||
List<SlittingproductionplanDO> plans = slittingproductionplanMapper
|
||||
.selectListByExtContainerName(reqVO.getSubRollNo());
|
||||
if (CollectionUtils.isEmpty(plans)) {
|
||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "子卷不存在");
|
||||
}
|
||||
if (plans.size() != 1) {
|
||||
throw badRequest("ERP子卷号匹配到多条记录");
|
||||
}
|
||||
SlittingproductionplanDO plan = plans.get(0);
|
||||
if (Objects.equals(plan.getErpQualityResult(), reqVO.getQualified())) {
|
||||
return reqVO.getSubRollNo();
|
||||
}
|
||||
if (slittingproductionplanMapper.updateErpQualityResult(plan.getWorkorderId(),
|
||||
reqVO.getQualified(), ERP_OPERATOR) != 1) {
|
||||
throw badRequest("子卷质检结果更新冲突");
|
||||
}
|
||||
return reqVO.getSubRollNo();
|
||||
});
|
||||
}
|
||||
|
||||
/** 重读冲突计划并按最新状态做一次有界处理。 */
|
||||
private String resolveDailyPlanConflict(ErpDailyPlanPushReqVO reqVO) {
|
||||
DailyPlanDO current = dailyPlanMapper.selectByErpPlanNo(reqVO.getPlanNo());
|
||||
|
||||
@@ -2,6 +2,20 @@
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="cn.code.nl.module.lms.dal.mysql.packagepoint.PackagePointMapper">
|
||||
|
||||
<select id="selectCurrentSubRollListForUpdate"
|
||||
resultType="cn.code.nl.module.lms.dal.dataobject.slittingproductionplan.SlittingproductionplanDO">
|
||||
SELECT plan.*
|
||||
FROM lms_package_point point
|
||||
INNER JOIN lms_slittingproductionplan plan
|
||||
ON plan.container_name = point.container_name
|
||||
AND plan.deleted = b'0'
|
||||
WHERE point.point_code = #{pointCode}
|
||||
AND point.container_name IS NOT NULL
|
||||
AND point.deleted = b'0'
|
||||
ORDER BY plan.workorder_id
|
||||
FOR UPDATE
|
||||
</select>
|
||||
|
||||
<select id="selectAvailablePointList"
|
||||
resultType="cn.code.nl.module.lms.dal.dataobject.packagepoint.PackagePointDO">
|
||||
SELECT *
|
||||
|
||||
@@ -37,6 +37,16 @@
|
||||
LIMIT 1
|
||||
</select>
|
||||
|
||||
<select id="selectListByExtContainerName"
|
||||
resultType="cn.code.nl.module.lms.dal.dataobject.slittingproductionplan.SlittingproductionplanDO">
|
||||
SELECT *
|
||||
FROM lms_slittingproductionplan
|
||||
WHERE ext_container_name = #{extContainerName}
|
||||
AND deleted = b'0'
|
||||
ORDER BY workorder_id
|
||||
FOR UPDATE
|
||||
</select>
|
||||
|
||||
<select id="selectByInnerContainerName"
|
||||
resultType="cn.code.nl.module.lms.dal.dataobject.slittingproductionplan.SlittingproductionplanDO">
|
||||
SELECT *
|
||||
@@ -47,4 +57,21 @@
|
||||
LIMIT 1
|
||||
</select>
|
||||
|
||||
<update id="bindExtContainerName">
|
||||
UPDATE lms_slittingproductionplan
|
||||
SET ext_container_name = #{extContainerName},
|
||||
updater = #{updater}
|
||||
WHERE workorder_id = #{workorderId}
|
||||
AND deleted = b'0'
|
||||
AND (ext_container_name IS NULL OR ext_container_name = #{extContainerName})
|
||||
</update>
|
||||
|
||||
<update id="updateErpQualityResult">
|
||||
UPDATE lms_slittingproductionplan
|
||||
SET erp_quality_result = #{erpQualityResult},
|
||||
updater = #{updater}
|
||||
WHERE workorder_id = #{workorderId}
|
||||
AND deleted = b'0'
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
|
||||
@@ -6,10 +6,15 @@ import cn.code.nl.module.base.api.materialbase.MaterialBaseApi;
|
||||
import cn.code.nl.module.base.api.materialbase.dto.MaterialBaseRespDTO;
|
||||
import cn.code.nl.module.lms.controller.erp.vo.ErpDailyPlanPushReqVO;
|
||||
import cn.code.nl.module.lms.controller.erp.vo.ErpRawFoilRollPushReqVO;
|
||||
import cn.code.nl.module.lms.controller.erp.vo.ErpSubRollQualityReqVO;
|
||||
import cn.code.nl.module.lms.controller.erp.vo.ErpSubRollSyncReqVO;
|
||||
import cn.code.nl.module.lms.dal.dataobject.dailyplan.DailyPlanDO;
|
||||
import cn.code.nl.module.lms.dal.dataobject.rawfoilworkorder.RawFoilWorkOrderDO;
|
||||
import cn.code.nl.module.lms.dal.dataobject.slittingproductionplan.SlittingproductionplanDO;
|
||||
import cn.code.nl.module.lms.dal.mysql.dailyplan.DailyPlanMapper;
|
||||
import cn.code.nl.module.lms.dal.mysql.packagepoint.PackagePointMapper;
|
||||
import cn.code.nl.module.lms.dal.mysql.rawfoilworkorder.RawFoilWorkOrderMapper;
|
||||
import cn.code.nl.module.lms.dal.mysql.slittingproductionplan.SlittingproductionplanMapper;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -27,6 +32,8 @@ import java.lang.reflect.Proxy;
|
||||
import java.time.LocalDate;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
@@ -125,6 +132,49 @@ class ErpInboundServiceLocalSpringTest {
|
||||
assertEquals("O1", store.daily.get("P1").getErpOrderCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void subRollShouldBindOnceAndRepeatIdempotently() {
|
||||
store.addPointPlan("POINT1", "INNER1", null);
|
||||
assertEquals("ERP1", service.syncSubRoll(sync("ERP1", "POINT1")));
|
||||
assertEquals("ERP1", store.pointPlans.get("POINT1").get(0).getExtContainerName());
|
||||
assertEquals("ERP1", service.syncSubRoll(sync("ERP1", "POINT1")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void subRollShouldRejectOtherRecordAndAmbiguousPoint() {
|
||||
store.addPointPlan("POINT1", "INNER1", "ERP1");
|
||||
store.addPointPlan("POINT2", "INNER2", null);
|
||||
assertEquals(400, assertThrows(ResponseStatusException.class,
|
||||
() -> service.syncSubRoll(sync("ERP1", "POINT2"))).getStatusCode().value());
|
||||
store.addPointPlan("POINT2", "INNER3", null);
|
||||
assertEquals(400, assertThrows(ResponseStatusException.class,
|
||||
() -> service.syncSubRoll(sync("ERP2", "POINT2"))).getStatusCode().value());
|
||||
}
|
||||
|
||||
@Test
|
||||
void subRollShouldReportMissingPoint() {
|
||||
assertEquals(404, assertThrows(ResponseStatusException.class,
|
||||
() -> service.syncSubRoll(sync("ERP1", "NONE"))).getStatusCode().value());
|
||||
}
|
||||
|
||||
@Test
|
||||
void qualityResultShouldPreserveOriginalStringAndOverwriteChangedValue() {
|
||||
store.addPointPlan("POINT1", "INNER1", "ERP1");
|
||||
assertEquals("ERP1", service.syncSubRollQuality(quality("ERP1", "ERP原始码-A")));
|
||||
assertEquals("ERP原始码-A", store.pointPlans.get("POINT1").get(0).getErpQualityResult());
|
||||
int updates = store.qualityUpdates;
|
||||
service.syncSubRollQuality(quality("ERP1", "ERP原始码-A"));
|
||||
assertEquals(updates, store.qualityUpdates);
|
||||
service.syncSubRollQuality(quality("ERP1", "ERP原始码-B"));
|
||||
assertEquals("ERP原始码-B", store.pointPlans.get("POINT1").get(0).getErpQualityResult());
|
||||
}
|
||||
|
||||
@Test
|
||||
void qualityResultShouldReportUnknownSubRoll() {
|
||||
assertEquals(404, assertThrows(ResponseStatusException.class,
|
||||
() -> service.syncSubRollQuality(quality("NONE", "任意结果"))).getStatusCode().value());
|
||||
}
|
||||
|
||||
private static ErpRawFoilRollPushReqVO raw(String rollNo, String deviceCode) {
|
||||
ErpRawFoilRollPushReqVO request = new ErpRawFoilRollPushReqVO();
|
||||
request.setRollNo(rollNo);
|
||||
@@ -148,12 +198,26 @@ class ErpInboundServiceLocalSpringTest {
|
||||
return request;
|
||||
}
|
||||
|
||||
private static ErpSubRollSyncReqVO sync(String subRollNo, String pointCode) {
|
||||
ErpSubRollSyncReqVO request = new ErpSubRollSyncReqVO();
|
||||
request.setSubRollNo(subRollNo); request.setPointCode(pointCode); return request;
|
||||
}
|
||||
|
||||
private static ErpSubRollQualityReqVO quality(String subRollNo, String qualified) {
|
||||
ErpSubRollQualityReqVO request = new ErpSubRollQualityReqVO();
|
||||
request.setSubRollNo(subRollNo); request.setQualified(qualified); return request;
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
static class Config {
|
||||
@Bean Store store() { return new Store(); }
|
||||
@Bean ErpInboundService service() { return new ErpInboundServiceImpl(); }
|
||||
@Bean RawFoilWorkOrderMapper rawMapper(Store store) { return store.proxy(RawFoilWorkOrderMapper.class); }
|
||||
@Bean DailyPlanMapper dailyMapper(Store store) { return store.proxy(DailyPlanMapper.class); }
|
||||
@Bean PackagePointMapper packagePointMapper(Store store) { return store.proxy(PackagePointMapper.class); }
|
||||
@Bean SlittingproductionplanMapper slittingMapper(Store store) {
|
||||
return store.proxy(SlittingproductionplanMapper.class);
|
||||
}
|
||||
@Bean MaterialBaseApi materialApi() {
|
||||
return (MaterialBaseApi) Proxy.newProxyInstance(MaterialBaseApi.class.getClassLoader(),
|
||||
new Class<?>[]{MaterialBaseApi.class}, (proxy, method, args) -> {
|
||||
@@ -179,25 +243,54 @@ class ErpInboundServiceLocalSpringTest {
|
||||
static class Store {
|
||||
final Map<String, RawFoilWorkOrderDO> raw = new LinkedHashMap<>();
|
||||
final Map<String, DailyPlanDO> daily = new LinkedHashMap<>();
|
||||
final Map<String, List<SlittingproductionplanDO>> pointPlans = new LinkedHashMap<>();
|
||||
boolean rawDuplicateOnce;
|
||||
int updateZeros;
|
||||
int updateCalls;
|
||||
int code;
|
||||
boolean startWhenUpdateFails;
|
||||
int qualityUpdates;
|
||||
|
||||
void reset() {
|
||||
raw.clear(); daily.clear(); rawDuplicateOnce = false; updateZeros = 0;
|
||||
updateCalls = 0; code = 0; startWhenUpdateFails = false;
|
||||
pointPlans.clear(); updateCalls = 0; code = 0; startWhenUpdateFails = false; qualityUpdates = 0;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
<T> T proxy(Class<T> type) {
|
||||
return (T) Proxy.newProxyInstance(type.getClassLoader(), new Class<?>[]{type}, (proxy, method, args) -> {
|
||||
if (method.getDeclaringClass() == Object.class) return method.invoke(this, args);
|
||||
return type == RawFoilWorkOrderMapper.class ? raw(method.getName(), args) : daily(method.getName(), args);
|
||||
if (type == RawFoilWorkOrderMapper.class) return raw(method.getName(), args);
|
||||
if (type == DailyPlanMapper.class) return daily(method.getName(), args);
|
||||
if (type == PackagePointMapper.class) return pointPlans.getOrDefault(args[0], List.of());
|
||||
return slitting(method.getName(), args);
|
||||
});
|
||||
}
|
||||
|
||||
void addPointPlan(String pointCode, String innerNo, String extNo) {
|
||||
SlittingproductionplanDO plan = new SlittingproductionplanDO();
|
||||
plan.setWorkorderId(innerNo); plan.setContainerName(innerNo); plan.setExtContainerName(extNo);
|
||||
pointPlans.computeIfAbsent(pointCode, key -> new ArrayList<>()).add(plan);
|
||||
}
|
||||
|
||||
private Object slitting(String method, Object[] args) {
|
||||
if ("selectListByExtContainerName".equals(method)) {
|
||||
return pointPlans.values().stream().flatMap(List::stream)
|
||||
.filter(plan -> Objects.equals(plan.getExtContainerName(), args[0])).toList();
|
||||
}
|
||||
SlittingproductionplanDO plan = pointPlans.values().stream().flatMap(List::stream)
|
||||
.filter(value -> Objects.equals(value.getWorkorderId(), args[0])).findFirst().orElse(null);
|
||||
if ("bindExtContainerName".equals(method)) {
|
||||
if (plan == null || plan.getExtContainerName() != null && !Objects.equals(plan.getExtContainerName(), args[1])) return 0;
|
||||
plan.setExtContainerName((String) args[1]); return 1;
|
||||
}
|
||||
if ("updateErpQualityResult".equals(method)) {
|
||||
if (plan == null) return 0;
|
||||
qualityUpdates++; plan.setErpQualityResult((String) args[1]); return 1;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Object raw(String method, Object[] args) {
|
||||
if ("selectByContainerName".equals(method)) return raw.get(args[0]);
|
||||
if ("insert".equals(method)) {
|
||||
|
||||
Reference in New Issue
Block a user