feat: 增加ERP母卷与日计划入站接口
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
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.service.erp.ErpAccessService;
|
||||
import cn.code.nl.module.lms.service.erp.ErpInboundService;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/** ERP 入站统一入口。 */
|
||||
@ErpApi
|
||||
@TenantIgnore
|
||||
@RestController
|
||||
@RequestMapping("/lms")
|
||||
public class ErpInboundController {
|
||||
@Resource private ErpAccessService erpAccessService;
|
||||
@Resource private ErpInboundService erpInboundService;
|
||||
|
||||
@PostMapping("/erp/raw-foil-roll/push")
|
||||
public ErpResult<String> pushRawFoilRoll(@RequestHeader("Authorization") String authorization,
|
||||
@Valid @RequestBody ErpRawFoilRollPushReqVO reqVO) {
|
||||
return ErpResult.success(erpAccessService.execute(authorization,
|
||||
() -> erpInboundService.pushRawFoilRoll(reqVO)));
|
||||
}
|
||||
|
||||
@PostMapping("/daily-plan/erpPush")
|
||||
public ErpResult<String> pushDailyPlan(@RequestHeader("Authorization") String authorization,
|
||||
@Valid @RequestBody ErpDailyPlanPushReqVO reqVO) {
|
||||
return ErpResult.success(erpAccessService.execute(authorization,
|
||||
() -> erpInboundService.pushDailyPlan(reqVO)));
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
package cn.code.nl.module.lms.controller.erp.dailyplan;
|
||||
|
||||
import cn.code.nl.framework.common.pojo.CommonResult;
|
||||
import cn.code.nl.module.lms.controller.erp.dailyplan.vo.ErpDailyPlanPushReqVO;
|
||||
import cn.code.nl.module.lms.service.dailyplan.DailyPlanService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
|
||||
import static cn.code.nl.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.code.nl.module.lms.enums.ErrorCodeConstants.DAILY_PLAN_ERP_TOKEN_ERROR;
|
||||
import static cn.code.nl.module.lms.enums.ErrorCodeConstants.DAILY_PLAN_ERP_TOKEN_NOT_CONFIGURED;
|
||||
|
||||
/** ERP 日计划对接接口。 */
|
||||
@Tag(name = "ERP - 日计划")
|
||||
@RestController
|
||||
@RequestMapping("/lms/daily-plan")
|
||||
@Validated
|
||||
public class ErpDailyPlanController {
|
||||
|
||||
/** ERP 日计划接口令牌。 */
|
||||
@Value("${erp.daily-plan.token:}")
|
||||
private String erpDailyPlanToken;
|
||||
|
||||
/** 日计划服务。 */
|
||||
@Resource
|
||||
private DailyPlanService dailyPlanService;
|
||||
|
||||
/** 接收 ERP 日计划;调用方还必须携带标准 tenant-id 请求头。 */
|
||||
@PostMapping("/erpPush")
|
||||
@Operation(summary = "ERP 推送日计划", description = "除 X-ERP-Token 外,还必须携带项目标准 tenant-id 请求头,数据按租户隔离")
|
||||
public CommonResult<String> erpPush(
|
||||
@Parameter(description = "ERP 接口令牌", required = true)
|
||||
@RequestHeader("X-ERP-Token") @NotBlank(message = "ERP接口令牌不能为空") String token,
|
||||
@Valid @RequestBody ErpDailyPlanPushReqVO reqVO) {
|
||||
if (erpDailyPlanToken.isBlank()) {
|
||||
throw exception(DAILY_PLAN_ERP_TOKEN_NOT_CONFIGURED);
|
||||
}
|
||||
if (!MessageDigest.isEqual(token.getBytes(StandardCharsets.UTF_8),
|
||||
erpDailyPlanToken.getBytes(StandardCharsets.UTF_8))) {
|
||||
throw exception(DAILY_PLAN_ERP_TOKEN_ERROR);
|
||||
}
|
||||
return CommonResult.success(dailyPlanService.pushErpDailyPlan(reqVO));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package cn.code.nl.module.lms.controller.erp.vo;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
/** ERP 日计划推送请求。 */
|
||||
@Data
|
||||
public class ErpDailyPlanPushReqVO {
|
||||
@NotBlank(message = "计划号不能为空") @Size(max = 64) private String planNo;
|
||||
@NotNull(message = "计划日期不能为空") private LocalDate planDate;
|
||||
@NotBlank(message = "车间编码不能为空") @Size(max = 64) private String shopCode;
|
||||
@NotBlank(message = "子卷物料编码不能为空") @Size(max = 64) private String subRollMaterialCode;
|
||||
@NotBlank(message = "子卷物料名称不能为空") @Size(max = 255) private String subRollMaterialName;
|
||||
@NotBlank(message = "管芯物料编码不能为空") @Size(max = 64) private String coreTubeMaterialCode;
|
||||
@NotBlank(message = "木箱物料编码不能为空") @Size(max = 64) private String boxMaterialCode;
|
||||
@NotBlank(message = "木箱物料名称不能为空") @Size(max = 128) private String boxMaterialName;
|
||||
@NotBlank(message = "订单号不能为空") @Size(max = 64) private String orderNo;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
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 ErpRawFoilRollPushReqVO {
|
||||
@NotBlank(message = "母卷号不能为空") @Size(max = 64) private String rollNo;
|
||||
@NotBlank(message = "设备编码不能为空") @Size(max = 64) private String deviceCode;
|
||||
@NotBlank(message = "物料编码不能为空") @Size(max = 64) private String materialCode;
|
||||
@NotBlank(message = "物料名称不能为空") @Size(max = 128) private String materialName;
|
||||
}
|
||||
@@ -62,6 +62,9 @@ public interface DailyPlanMapper extends BaseMapperX<DailyPlanDO> {
|
||||
*/
|
||||
DailyPlanDO selectByErpOrderCode(@Param("erpOrderCode") String erpOrderCode);
|
||||
|
||||
/** 根据 ERP 计划号查询当前租户日计划。 */
|
||||
DailyPlanDO selectByErpPlanNo(@Param("erpPlanNo") String erpPlanNo);
|
||||
|
||||
/**
|
||||
* 查询当前租户下一个日计划排序序号。
|
||||
*/
|
||||
@@ -87,6 +90,9 @@ public interface DailyPlanMapper extends BaseMapperX<DailyPlanDO> {
|
||||
*/
|
||||
int updateNotStartedPlan(@Param("plan") DailyPlanDO plan);
|
||||
|
||||
/** 仅更新未开始日计划的 ERP 管理字段。 */
|
||||
int updateNotStartedErpFields(@Param("plan") DailyPlanDO plan);
|
||||
|
||||
/**
|
||||
* 乐观锁更新日计划状态。
|
||||
*
|
||||
|
||||
@@ -70,10 +70,6 @@ public interface RawFoilWorkOrderMapper extends BaseMapperX<RawFoilWorkOrderDO>
|
||||
* @param containerName
|
||||
* @return RawFoilWorkOrderDO
|
||||
*/
|
||||
default RawFoilWorkOrderDO selectByContainerName(String containerName){
|
||||
return selectOne(new LambdaQueryWrapperX<RawFoilWorkOrderDO>()
|
||||
.eq(RawFoilWorkOrderDO::getContainerName,containerName)
|
||||
);
|
||||
}
|
||||
RawFoilWorkOrderDO selectByContainerName(String containerName);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
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;
|
||||
|
||||
/** ERP 入站业务服务。 */
|
||||
public interface ErpInboundService {
|
||||
String pushRawFoilRoll(ErpRawFoilRollPushReqVO reqVO);
|
||||
String pushDailyPlan(ErpDailyPlanPushReqVO reqVO);
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
package cn.code.nl.module.lms.service.erp;
|
||||
|
||||
import cn.code.nl.framework.common.pojo.CommonResult;
|
||||
import cn.code.nl.module.base.api.codegen.CodeGenApi;
|
||||
import cn.code.nl.module.base.api.codegen.dto.CodeGenerateReqDTO;
|
||||
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.dal.dataobject.dailyplan.DailyPlanDO;
|
||||
import cn.code.nl.module.lms.dal.dataobject.rawfoilworkorder.RawFoilWorkOrderDO;
|
||||
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.enums.DailyPlanOrderStatusEnum;
|
||||
import cn.code.nl.module.lms.enums.DailyPlanSourceTypeEnum;
|
||||
import cn.code.nl.module.lms.enums.RawFoilWorkOrderStatusEnum;
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.dao.DuplicateKeyException;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.TransactionDefinition;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
/** ERP 入站业务服务实现。 */
|
||||
@Service
|
||||
public class ErpInboundServiceImpl implements ErpInboundService {
|
||||
private static final String ERP_OPERATOR = "user4";
|
||||
|
||||
@Resource private RawFoilWorkOrderMapper rawFoilWorkOrderMapper;
|
||||
@Resource private DailyPlanMapper dailyPlanMapper;
|
||||
@Resource private MaterialBaseApi materialBaseApi;
|
||||
@Resource private CodeGenApi codeGenApi;
|
||||
@Resource private PlatformTransactionManager transactionManager;
|
||||
|
||||
@Override
|
||||
public String pushRawFoilRoll(ErpRawFoilRollPushReqVO reqVO) {
|
||||
try {
|
||||
return newTransaction().execute(status -> createRawFoilRollIfAbsent(reqVO));
|
||||
} catch (DuplicateKeyException exception) {
|
||||
return newTransaction().execute(status -> {
|
||||
RawFoilWorkOrderDO concurrent = rawFoilWorkOrderMapper.selectByContainerName(reqVO.getRollNo());
|
||||
if (concurrent == null) {
|
||||
throw exception;
|
||||
}
|
||||
return concurrent.getContainerName();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private String createRawFoilRollIfAbsent(ErpRawFoilRollPushReqVO reqVO) {
|
||||
RawFoilWorkOrderDO current = rawFoilWorkOrderMapper.selectByContainerName(reqVO.getRollNo());
|
||||
if (current != null) {
|
||||
return current.getContainerName();
|
||||
}
|
||||
RawFoilWorkOrderDO workOrder = new RawFoilWorkOrderDO();
|
||||
workOrder.setContainerName(reqVO.getRollNo());
|
||||
workOrder.setPointCode(reqVO.getDeviceCode());
|
||||
workOrder.setProductCode(reqVO.getMaterialCode());
|
||||
workOrder.setProductName(reqVO.getMaterialName());
|
||||
workOrder.setStatus(RawFoilWorkOrderStatusEnum.START.getCode());
|
||||
workOrder.setCreator(ERP_OPERATOR);
|
||||
workOrder.setUpdater(ERP_OPERATOR);
|
||||
rawFoilWorkOrderMapper.insert(workOrder);
|
||||
return reqVO.getRollNo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String pushDailyPlan(ErpDailyPlanPushReqVO reqVO) {
|
||||
try {
|
||||
return newTransaction().execute(status -> createOrUpdateDailyPlan(reqVO));
|
||||
} catch (DuplicateKeyException exception) {
|
||||
return newTransaction().execute(status -> {
|
||||
DailyPlanDO concurrent = dailyPlanMapper.selectByErpPlanNo(reqVO.getPlanNo());
|
||||
if (concurrent == null) {
|
||||
throw exception;
|
||||
}
|
||||
return concurrent.getPlanCode();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private String createOrUpdateDailyPlan(ErpDailyPlanPushReqVO reqVO) {
|
||||
DailyPlanDO current = dailyPlanMapper.selectByErpPlanNo(reqVO.getPlanNo());
|
||||
if (current != null) {
|
||||
if (DailyPlanOrderStatusEnum.NOT_STARTED.getCode().equals(current.getOrderStatus())) {
|
||||
DailyPlanDO update = buildErpPlan(reqVO);
|
||||
update.setDailyPlanId(current.getDailyPlanId());
|
||||
update.setVersion(current.getVersion());
|
||||
dailyPlanMapper.updateNotStartedErpFields(update);
|
||||
}
|
||||
return current.getPlanCode();
|
||||
}
|
||||
DailyPlanDO plan = buildErpPlan(reqVO);
|
||||
plan.setDailyPlanId(IdWorker.getId());
|
||||
plan.setPlanCode(generatePlanCode());
|
||||
plan.setSourceType(DailyPlanSourceTypeEnum.ERP.getCode());
|
||||
plan.setPlanQty(0);
|
||||
plan.setSortSeq(dailyPlanMapper.selectNextSortSeq());
|
||||
plan.setWeight(1);
|
||||
dailyPlanMapper.insertDailyPlan(plan);
|
||||
return plan.getPlanCode();
|
||||
}
|
||||
|
||||
private DailyPlanDO buildErpPlan(ErpDailyPlanPushReqVO reqVO) {
|
||||
MaterialBaseRespDTO material = getCoreTubeMaterial(reqVO.getCoreTubeMaterialCode());
|
||||
DailyPlanDO plan = new DailyPlanDO();
|
||||
plan.setErpPlanNo(reqVO.getPlanNo());
|
||||
plan.setErpOrderCode(reqVO.getOrderNo());
|
||||
plan.setPlanDate(reqVO.getPlanDate());
|
||||
plan.setShopCode(reqVO.getShopCode());
|
||||
plan.setMaterialId(material.getMaterialId());
|
||||
plan.setMaterialCode(material.getMaterialCode());
|
||||
plan.setMaterialName(material.getMaterialName());
|
||||
plan.setMaterialSpec(material.getMaterialSpec());
|
||||
plan.setSubRollMaterialCode(reqVO.getSubRollMaterialCode());
|
||||
plan.setSubRollMaterialDescription(reqVO.getSubRollMaterialName());
|
||||
plan.setBoxMaterialCode(reqVO.getBoxMaterialCode());
|
||||
plan.setBoxMaterialName(reqVO.getBoxMaterialName());
|
||||
plan.setCreator(ERP_OPERATOR);
|
||||
plan.setUpdater(ERP_OPERATOR);
|
||||
return plan;
|
||||
}
|
||||
|
||||
private MaterialBaseRespDTO getCoreTubeMaterial(String code) {
|
||||
CommonResult<MaterialBaseRespDTO> result = materialBaseApi.getMaterialBaseByCode(code);
|
||||
if (result == null || !result.isSuccess() || result.getData() == null) {
|
||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "管芯物料不存在");
|
||||
}
|
||||
return result.getData();
|
||||
}
|
||||
|
||||
private String generatePlanCode() {
|
||||
CodeGenerateReqDTO request = new CodeGenerateReqDTO();
|
||||
request.setRuleCode("LMS_DAILY_PLAN_CODE");
|
||||
CommonResult<String> result = codeGenApi.generate(request);
|
||||
if (result == null || !result.isSuccess() || result.getData() == null || result.getData().isBlank()) {
|
||||
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "日计划编码生成失败");
|
||||
}
|
||||
return result.getData();
|
||||
}
|
||||
|
||||
private TransactionTemplate newTransaction() {
|
||||
TransactionTemplate template = new TransactionTemplate(transactionManager);
|
||||
template.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
|
||||
return template;
|
||||
}
|
||||
}
|
||||
@@ -3,9 +3,10 @@
|
||||
<mapper namespace="cn.code.nl.module.lms.dal.mysql.dailyplan.DailyPlanMapper">
|
||||
|
||||
<sql id="dailyPlanColumns">
|
||||
daily_plan_id, plan_code, source_type, erp_order_code, manual_order_code,
|
||||
plan_date, material_id, material_code, material_name, material_spec,
|
||||
daily_plan_id, plan_code, source_type, erp_plan_no, erp_order_code, manual_order_code,
|
||||
plan_date, shop_code, material_id, material_code, material_name, material_spec,
|
||||
sub_roll_material_code, sub_roll_material_description,
|
||||
box_material_code, box_material_name,
|
||||
plan_qty, append_qty, stocked_qty, sleeved_qty, packing_info, sort_seq, weight,
|
||||
order_status, stocking_status, sleeving_status,
|
||||
previous_order_status, previous_stocking_status, previous_sleeving_status,
|
||||
@@ -108,6 +109,13 @@
|
||||
AND deleted = b'0'
|
||||
</select>
|
||||
|
||||
<select id="selectByErpPlanNo" resultType="cn.code.nl.module.lms.dal.dataobject.dailyplan.DailyPlanDO">
|
||||
SELECT <include refid="dailyPlanColumns"/>
|
||||
FROM lms_daily_plan
|
||||
WHERE erp_plan_no = #{erpPlanNo}
|
||||
AND deleted = b'0'
|
||||
</select>
|
||||
|
||||
<select id="selectNextSortSeq" resultType="java.lang.Integer">
|
||||
SELECT COALESCE(MAX(sort_seq), 0) + 1
|
||||
FROM lms_daily_plan
|
||||
@@ -154,16 +162,18 @@
|
||||
|
||||
<insert id="insertDailyPlan">
|
||||
INSERT INTO lms_daily_plan
|
||||
(daily_plan_id, plan_code, source_type, erp_order_code, manual_order_code,
|
||||
plan_date, material_id, material_code, material_name, material_spec,
|
||||
(daily_plan_id, plan_code, source_type, erp_plan_no, erp_order_code, manual_order_code,
|
||||
plan_date, shop_code, material_id, material_code, material_name, material_spec,
|
||||
sub_roll_material_code, sub_roll_material_description,
|
||||
box_material_code, box_material_name,
|
||||
plan_qty, append_qty, stocked_qty, sleeved_qty, packing_info, sort_seq, weight,
|
||||
order_status, stocking_status, sleeving_status,
|
||||
version, creator, updater)
|
||||
VALUES
|
||||
(#{plan.dailyPlanId}, #{plan.planCode}, #{plan.sourceType}, #{plan.erpOrderCode}, #{plan.manualOrderCode},
|
||||
#{plan.planDate}, #{plan.materialId}, #{plan.materialCode}, #{plan.materialName}, #{plan.materialSpec},
|
||||
(#{plan.dailyPlanId}, #{plan.planCode}, #{plan.sourceType}, #{plan.erpPlanNo}, #{plan.erpOrderCode}, #{plan.manualOrderCode},
|
||||
#{plan.planDate}, #{plan.shopCode}, #{plan.materialId}, #{plan.materialCode}, #{plan.materialName}, #{plan.materialSpec},
|
||||
#{plan.subRollMaterialCode}, #{plan.subRollMaterialDescription},
|
||||
#{plan.boxMaterialCode}, #{plan.boxMaterialName},
|
||||
#{plan.planQty}, 0, 0, 0, #{plan.packingInfo}, #{plan.sortSeq}, #{plan.weight},
|
||||
0, 0, 0, 0, #{plan.creator}, #{plan.updater})
|
||||
</insert>
|
||||
@@ -191,6 +201,27 @@
|
||||
AND order_status = 0
|
||||
</update>
|
||||
|
||||
<update id="updateNotStartedErpFields">
|
||||
UPDATE lms_daily_plan
|
||||
SET erp_order_code = #{plan.erpOrderCode},
|
||||
plan_date = #{plan.planDate},
|
||||
shop_code = #{plan.shopCode},
|
||||
material_id = #{plan.materialId},
|
||||
material_code = #{plan.materialCode},
|
||||
material_name = #{plan.materialName},
|
||||
material_spec = #{plan.materialSpec},
|
||||
sub_roll_material_code = #{plan.subRollMaterialCode},
|
||||
sub_roll_material_description = #{plan.subRollMaterialDescription},
|
||||
box_material_code = #{plan.boxMaterialCode},
|
||||
box_material_name = #{plan.boxMaterialName},
|
||||
updater = #{plan.updater},
|
||||
version = version + 1
|
||||
WHERE daily_plan_id = #{plan.dailyPlanId}
|
||||
AND version = #{plan.version}
|
||||
AND deleted = b'0'
|
||||
AND order_status = 0
|
||||
</update>
|
||||
|
||||
<update id="restoreOrderWithVersion">
|
||||
UPDATE lms_daily_plan
|
||||
SET order_status = previous_order_status,
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!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.rawfoilworkorder.RawFoilWorkOrderMapper">
|
||||
<select id="selectByContainerName" resultType="cn.code.nl.module.lms.dal.dataobject.rawfoilworkorder.RawFoilWorkOrderDO">
|
||||
SELECT *
|
||||
FROM lms_rawfoil_workorder
|
||||
WHERE container_name = #{containerName}
|
||||
AND deleted = b'0'
|
||||
LIMIT 1
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,57 @@
|
||||
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 jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
/** ERP 入站接口契约测试。 */
|
||||
class ErpInboundContractTest {
|
||||
|
||||
@Test
|
||||
void shouldExposeOnlyDocumentedRawFoilFields() {
|
||||
assertEquals(Set.of("rollNo", "deviceCode", "materialCode", "materialName"), fields(ErpRawFoilRollPushReqVO.class));
|
||||
assertRequired(ErpRawFoilRollPushReqVO.class, "rollNo");
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldExposeOnlyDocumentedDailyPlanFieldsWithoutQuantity() {
|
||||
assertEquals(Set.of("planNo", "planDate", "shopCode", "subRollMaterialCode", "subRollMaterialName",
|
||||
"coreTubeMaterialCode", "boxMaterialCode", "boxMaterialName", "orderNo"),
|
||||
fields(ErpDailyPlanPushReqVO.class));
|
||||
assertRequired(ErpDailyPlanPushReqVO.class, "planNo");
|
||||
assertNotNull(field(ErpDailyPlanPushReqVO.class, "planDate").getAnnotation(NotNull.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void controllerShouldUseErpContractAndIgnoreRequestTenant() {
|
||||
assertNotNull(ErpInboundController.class.getAnnotation(ErpApi.class));
|
||||
assertNotNull(ErpInboundController.class.getAnnotation(TenantIgnore.class));
|
||||
}
|
||||
|
||||
private static Set<String> fields(Class<?> type) {
|
||||
return Stream.of(type.getDeclaredFields()).map(Field::getName).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
private static void assertRequired(Class<?> type, String name) {
|
||||
assertNotNull(field(type, name).getAnnotation(NotBlank.class));
|
||||
}
|
||||
|
||||
private static Field field(Class<?> type, String name) {
|
||||
try {
|
||||
return type.getDeclaredField(name);
|
||||
} catch (NoSuchFieldException ex) {
|
||||
throw new AssertionError(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user