mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-12 21:02:08 +08:00
取消板件自动写入,bug1255,1225
This commit is contained in:
+15
-1
@@ -71,10 +71,24 @@ public class ErrorCodeConstants {
|
||||
public static final ErrorCode CHANGE_DETAILS_ITEM_ERROR = new ErrorCode(1_002_032_001, "明细转换失败");
|
||||
public static final ErrorCode ORDER_MATCH_NOT = new ErrorCode(1_002_033_001, "板材库缺少相关板材,请在板材库中进行添加之后再进行导入");
|
||||
|
||||
// ========== 自定义板编号生成 ==========
|
||||
// ========== 自定义板编号生成 1_002_030_ ==========
|
||||
public static final ErrorCode CUSTOM_PLATENO_GENERATE_ORDERNO_RULE_NOT_SUPPORT_RESETMODE = new ErrorCode(1_002_030_001, "自定义版编号生产单序号规则中存在不支持的复位类型:{}");
|
||||
public static final ErrorCode CUSTOM_PLATENO_GENERATE_BODY_RULE_NOT_SUPPORT_RESETMODE = new ErrorCode(1_002_030_002, "自定义版编号柜体序号规则中存在不支持的复位类型:{}");
|
||||
public static final ErrorCode CUSTOM_PLATENO_GENERATE_PROCESSGROUP_RULE_NOT_SUPPORT_RESETMODE = new ErrorCode(1_002_030_003, "自定义版编号加工组序号规则中存在不支持的复位类型:{}");
|
||||
public static final ErrorCode CUSTOM_PLATENO_GENERATE_PLATE_RULE_NOT_SUPPORT_RESETMODE = new ErrorCode(1_002_030_004, "自定义版编号板件序号规则中存在不支持的复位类型:{}");
|
||||
public static final ErrorCode CUSTOM_PLATENO_GENERATE_ORG_CUSTOM_PLATENO_SEQ_MODIFY_ERROR = new ErrorCode(1_002_030_005, "保存组织下自定义板编号序号配置失败,请联系客服处理");
|
||||
|
||||
// ========== 生产单导入 1_002_031 ==========
|
||||
public static final ErrorCode ORDER_IMPORT_TYPE_NOT_SUPPORT = new ErrorCode(1_002_031_001, "不支持的生产单导入类型:{}");
|
||||
public static final ErrorCode ORDER_IMPORT_ORGAN_LOCK_ERROR = new ErrorCode(1_002_031_002, "组织下存在正在导入的生产单,请稍后再试");
|
||||
public static final ErrorCode ORDER_IMPORT_FILE_ANALYZE_ERROR = new ErrorCode(1_002_031_003, "生产单导入文件解析失败,请检查文件类型和格式");
|
||||
public static final ErrorCode ORDER_IMPORT_ORDER_FIELD_EMPTY = new ErrorCode(1_002_031_004, "生产单信息【{}】不能为空");
|
||||
public static final ErrorCode ORDER_IMPORT_ORDER_FIELD_LENGTH_ERROR = new ErrorCode(1_002_031_005, "生产单信息【{}】长度不能超过【{}】个字符");
|
||||
public static final ErrorCode ORDER_IMPORT_ORDER_FIELD_MOBILE_FORMAT_ERROR = new ErrorCode(1_002_031_006, "生产单信息【{}】手机号格式错误");
|
||||
public static final ErrorCode ORDER_IMPORT_ORDER_FIELD_DATE_FORMAT_ERROR = new ErrorCode(1_002_031_007, "生产单信息【{}】日期格式错误");
|
||||
public static final ErrorCode ORDER_IMPORT_ORDER_NOT_EXISTS = new ErrorCode(1_002_031_008, "生产单【{}】不存在");
|
||||
public static final ErrorCode ORDER_IMPORT_ORDER_CUSTOMERNO_EXISTS = new ErrorCode(1_002_031_009, "{}【{}】已存在");
|
||||
public static final ErrorCode ORDER_IMPORT_DETAIL_FIELD_EMPTY = new ErrorCode(1_002_031_010, "导入校验异常:第{}行,导入明细【{}】不能为空");
|
||||
public static final ErrorCode ORDER_IMPORT_DETAIL_FIELD_LENGTH_ERROR = new ErrorCode(1_002_031_011, "导入校验异常:第{}行,导入明细【{}】长度不能超过【{}】个字符");
|
||||
public static final ErrorCode ORDER_IMPORT_DETAIL_VALID_ERROR = new ErrorCode(1_002_031_012, "导入校验异常:{}");
|
||||
}
|
||||
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package com.cf.imes.module.executor.enums;
|
||||
|
||||
/**
|
||||
* 生产单导入常量
|
||||
*
|
||||
* @author Gqr
|
||||
* @since 2025/1/14 16:18
|
||||
*/
|
||||
public class OrderImportConstants {
|
||||
/**
|
||||
* 导入商品缺省goodsid
|
||||
*/
|
||||
public static final String DEFAULT_GOODS_ID = "no_code_1132589&";
|
||||
|
||||
/**
|
||||
* 房间、柜体缺省name
|
||||
*/
|
||||
public static final String NOT_ASSIGNED = "未命名";
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
package com.cf.imes.module.executor.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 生产单导入状态枚举
|
||||
*
|
||||
* @author Gqr
|
||||
* @since 2025/1/8 16:20
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum OrderImportStatusEnum {
|
||||
/**
|
||||
* 未导入
|
||||
*/
|
||||
IMPORT_NOT_YET(0),
|
||||
|
||||
/**
|
||||
* 导入成功
|
||||
*/
|
||||
IMPORT_SUCCESS(10),
|
||||
|
||||
/**
|
||||
* 导入失败
|
||||
*/
|
||||
IMPORT_FAIL(2);
|
||||
|
||||
private int status;
|
||||
|
||||
/**
|
||||
* 是否匹配
|
||||
*
|
||||
* @param status
|
||||
* @return
|
||||
*/
|
||||
public static OrderImportStatusEnum match(int status) {
|
||||
for (OrderImportStatusEnum statusEnum : OrderImportStatusEnum.values()) {
|
||||
if (statusEnum.status == status) {
|
||||
return statusEnum;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
package com.cf.imes.module.executor.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 生产单导入任务状态枚举
|
||||
*
|
||||
* @author Gqr
|
||||
* @since 2025/1/8 16:20
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum OrderImportTaskStatusEnum {
|
||||
/**
|
||||
* 创建未消费
|
||||
*/
|
||||
CREATE_NOT_CONSUME(0),
|
||||
|
||||
/**
|
||||
* 创建已接收
|
||||
*/
|
||||
CREATE_RECEIVE(10),
|
||||
|
||||
/**
|
||||
* 消费成功
|
||||
*/
|
||||
CONSUME_SUCCESS(20),
|
||||
|
||||
/**
|
||||
* 消费失败
|
||||
*/
|
||||
CONSUME_FAIL(30);
|
||||
|
||||
private int status;
|
||||
|
||||
/**
|
||||
* 是否匹配
|
||||
*
|
||||
* @param status
|
||||
* @return
|
||||
*/
|
||||
public static OrderImportTaskStatusEnum match(int status) {
|
||||
for (OrderImportTaskStatusEnum statusEnum : OrderImportTaskStatusEnum.values()) {
|
||||
if (statusEnum.status == status) {
|
||||
return statusEnum;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package com.cf.imes.module.executor.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 生产单导入临时表类型枚举
|
||||
*
|
||||
* @author Gqr
|
||||
* @since 2025/1/8 16:20
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum OrderImportTmpDataTypeEnum {
|
||||
ORDER(0),
|
||||
PLATE(1),
|
||||
PART(2);
|
||||
|
||||
private int type;
|
||||
|
||||
/**
|
||||
* 是否匹配
|
||||
*
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
public static OrderImportTmpDataTypeEnum match(int type) {
|
||||
for (OrderImportTmpDataTypeEnum typeEnum : OrderImportTmpDataTypeEnum.values()) {
|
||||
if (typeEnum.type == type) {
|
||||
return typeEnum;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package com.cf.imes.module.executor.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 生产单导入类型枚举
|
||||
* @author Gqr
|
||||
* @since 2025/1/8 16:20
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum OrderImportTypeEnum {
|
||||
EXCEL(0),
|
||||
JSON(1),
|
||||
XML(2),
|
||||
API(3);
|
||||
|
||||
private int type;
|
||||
|
||||
/**
|
||||
* 是否匹配
|
||||
*
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
public static OrderImportTypeEnum match(int type) {
|
||||
for (OrderImportTypeEnum typeEnum : OrderImportTypeEnum.values()) {
|
||||
if (typeEnum.type == type) {
|
||||
return typeEnum;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -182,6 +182,15 @@
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.cf.imes</groupId>
|
||||
<artifactId>cf-spring-boot-starter-mq</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.cf.imes</groupId>
|
||||
<artifactId>cf-spring-boot-starter-biz-id</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
<build>
|
||||
@@ -272,6 +281,14 @@
|
||||
<groupId>com.cf.imes</groupId>
|
||||
<artifactId>cf-spring-boot-starter-web</artifactId>
|
||||
</include>
|
||||
<include>
|
||||
<groupId>com.cf.imes</groupId>
|
||||
<artifactId>cf-spring-boot-starter-mq</artifactId>
|
||||
</include>
|
||||
<include>
|
||||
<groupId>com.cf.imes</groupId>
|
||||
<artifactId>cf-spring-boot-starter-biz-id</artifactId>
|
||||
</include>
|
||||
</includes>
|
||||
</configuration>
|
||||
<executions>
|
||||
|
||||
+16
@@ -393,6 +393,22 @@ public class OrderController {
|
||||
|
||||
}
|
||||
|
||||
@PostMapping("/import")
|
||||
@Operation(summary = "生产单导入新增")
|
||||
@Parameters({
|
||||
@Parameter(name = "file", description = "文件", required = true),
|
||||
@Parameter(name = "type", description = "文件类型", required = true),
|
||||
@Parameter(name = "id", description = "生产单id")
|
||||
})
|
||||
@OperateLog(type = IMPORT)
|
||||
@PreAuthorize("@ss.hasPermission('production:manager-list:create')")
|
||||
public void orderImport(@RequestPart("file") MultipartFile file,
|
||||
@RequestParam(value = "type") Integer type,
|
||||
@RequestParam(value = "id", required = false) Long orderId) {
|
||||
OrderImportAsyncReqVO orderImportAsyncReqVO = new OrderImportAsyncReqVO(orderId, type, null);
|
||||
orderService.orderImportAsync(orderImportAsyncReqVO, file);
|
||||
}
|
||||
|
||||
|
||||
// 生产单详情
|
||||
@GetMapping("/get-room")
|
||||
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package com.cf.imes.module.executor.controller.admin.order.vo.order;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 生产单异步导入 reqVO
|
||||
*
|
||||
* @author Gqr
|
||||
* @since 2025/1/8 17:05
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class OrderImportAsyncReqVO implements Serializable {
|
||||
@Serial
|
||||
private static final long serialVersionUID = -1237291692917676281L;
|
||||
|
||||
/**
|
||||
* 生产单id
|
||||
*/
|
||||
Long orderId;
|
||||
|
||||
/**
|
||||
* 导入类型,参考OrderImportTypeEnum
|
||||
*/
|
||||
Integer type;
|
||||
|
||||
/**
|
||||
* 外部订单号:api导入用
|
||||
*/
|
||||
String orderNo;
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
package com.cf.imes.module.executor.dal.dataobject.orderImport;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.cf.imes.framework.mybatis.core.dataobject.BaseDO;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
/**
|
||||
* 生产单导入任务
|
||||
*
|
||||
* @author Gqr
|
||||
* @since 2025/1/9 11:30
|
||||
*/
|
||||
@TableName("order_import_task")
|
||||
@KeySequence("order_import_task_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class OrderImportTaskDO extends BaseDO {
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 组织id
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
private Long organId;
|
||||
|
||||
/**
|
||||
* 导入类型,参考OrderImportTypeEnum
|
||||
*/
|
||||
private Integer type;
|
||||
|
||||
/**
|
||||
* 导入状态
|
||||
*/
|
||||
private Integer importStatus;
|
||||
|
||||
/**
|
||||
* 消费状态
|
||||
*/
|
||||
private Integer status;
|
||||
}
|
||||
+188
@@ -0,0 +1,188 @@
|
||||
package com.cf.imes.module.executor.dal.dataobject.orderImport;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 生产单导入临时表
|
||||
*
|
||||
* @author Gqr
|
||||
* @since 2025/1/9 11:36
|
||||
*/
|
||||
@TableName("order_import_temp_data")
|
||||
@KeySequence("order_import_temp_data_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class OrderImportTempDataDO {
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 组织id
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||
private Long organId;
|
||||
|
||||
/**
|
||||
* 导入任务id
|
||||
*/
|
||||
private Long taskId;
|
||||
|
||||
/**
|
||||
* 生产单id(补板用)
|
||||
*/
|
||||
private Long orderId;
|
||||
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
private Integer type;
|
||||
|
||||
/**
|
||||
* 物料编码
|
||||
*/
|
||||
private String outerGoodsId;
|
||||
|
||||
/**
|
||||
* imes商品id
|
||||
*/
|
||||
private String innerGoodsId;
|
||||
|
||||
/**
|
||||
* 商品名称
|
||||
*/
|
||||
private String goodsName;
|
||||
|
||||
/**
|
||||
* 材料
|
||||
*/
|
||||
private String material;
|
||||
|
||||
/**
|
||||
* 颜色
|
||||
*/
|
||||
private String color;
|
||||
|
||||
/**
|
||||
* 纹路
|
||||
*/
|
||||
private String wave;
|
||||
|
||||
/**
|
||||
* 宽度
|
||||
*/
|
||||
private String width;
|
||||
|
||||
/**
|
||||
* 长度
|
||||
*/
|
||||
private String height;
|
||||
|
||||
/**
|
||||
* 厚度
|
||||
*/
|
||||
private String thickness;
|
||||
|
||||
/**
|
||||
* 品牌
|
||||
*/
|
||||
private String brand;
|
||||
|
||||
/**
|
||||
* 是否复合部件
|
||||
*/
|
||||
@TableField("is_composite")
|
||||
private String isComposite;
|
||||
|
||||
/**
|
||||
* 配件主类
|
||||
*/
|
||||
private String category;
|
||||
|
||||
/**
|
||||
* 配件子类型
|
||||
*/
|
||||
private String subType;
|
||||
|
||||
/**
|
||||
* 厂家
|
||||
*/
|
||||
private String factory;
|
||||
|
||||
/**
|
||||
* 规格
|
||||
*/
|
||||
private String spec;
|
||||
|
||||
/**
|
||||
* 型号
|
||||
*/
|
||||
private String model;
|
||||
|
||||
/**
|
||||
* 单位
|
||||
*/
|
||||
private String unit;
|
||||
|
||||
/**
|
||||
* 房间名称
|
||||
*/
|
||||
private String roomName;
|
||||
|
||||
/**
|
||||
* 柜体名称
|
||||
*/
|
||||
private String bodyName;
|
||||
|
||||
/**
|
||||
* 加工组类型
|
||||
*/
|
||||
private String groupTypeName;
|
||||
|
||||
/**
|
||||
* 模块名称
|
||||
*/
|
||||
private String groupName;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private String creater;
|
||||
|
||||
/**
|
||||
* 导入数据明细
|
||||
*/
|
||||
private String detail;
|
||||
|
||||
/**
|
||||
* 数量
|
||||
*/
|
||||
private Double num;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 排序号
|
||||
*/
|
||||
private int sort;
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package com.cf.imes.module.executor.dal.mysql.orderImport;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.cf.imes.module.executor.dal.dataobject.orderImport.OrderImportTaskDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 生产单导入任务 Mapper
|
||||
*
|
||||
* @author Gqr
|
||||
* @since 2025/1/9 11:42
|
||||
*/
|
||||
@Mapper
|
||||
public interface OrderImportTaskMapper extends BaseMapper<OrderImportTaskDO> {
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package com.cf.imes.module.executor.dal.mysql.orderImport;
|
||||
|
||||
import com.cf.imes.framework.mybatis.core.injector.BaseBatchMapper;
|
||||
import com.cf.imes.module.executor.dal.dataobject.orderImport.OrderImportTempDataDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 生产单导入临时表 Mapper
|
||||
*
|
||||
* @author Gqr
|
||||
* @since 2025/1/9 11:42
|
||||
*/
|
||||
@Mapper
|
||||
public interface OrderImportTempDataMapper extends BaseBatchMapper<OrderImportTempDataDO> {
|
||||
}
|
||||
+2
-2
@@ -98,12 +98,12 @@ public class BodyNoGenerateRuleServiceImpl implements CustomPlateNoGenerateRuleS
|
||||
OrderCustomPlateNoSeqVO orderCustomPlateNoSeqVO = JSON.parseObject(orderDO.getCustomPlatenoSeq(), OrderCustomPlateNoSeqVO.class);
|
||||
if (ObjectUtil.isNotNull(orderCustomPlateNoSeqVO)) {
|
||||
if (ObjectUtil.equal(ResetModeEnum.ORDER, resetModeEnum)) {
|
||||
orderCustomPlateNoSeqVO.setBodyNoSeq(ruleDTO.getInitValue());
|
||||
orderCustomPlateNoSeqVO.setBodyNoSeq(null);
|
||||
} else if (ObjectUtil.equal(ResetModeEnum.ROOM, resetModeEnum)) {
|
||||
List<OrderCustomPlateNoSeqRoomVO> rooms = orderCustomPlateNoSeqVO.getRooms();
|
||||
if (CollUtil.isNotEmpty(rooms)) {
|
||||
for (OrderCustomPlateNoSeqRoomVO roomVO : rooms) {
|
||||
roomVO.setBodyNoSeq(ruleDTO.getInitValue());
|
||||
roomVO.setBodyNoSeq(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -105,7 +105,7 @@ public class OrderNoGenerateRuleServiceImpl implements CustomPlateNoGenerateRule
|
||||
for (OrderDO orderDO : orderDOS) {
|
||||
OrderCustomPlateNoSeqVO orderCustomPlateNoSeqVO = JSON.parseObject(orderDO.getCustomPlatenoSeq(), OrderCustomPlateNoSeqVO.class);
|
||||
if (ObjectUtil.isNotNull(orderCustomPlateNoSeqVO)) {
|
||||
orderCustomPlateNoSeqVO.setOrderNoSeq(ruleDTO.getInitValue());
|
||||
orderCustomPlateNoSeqVO.setOrderNoSeq(null);
|
||||
orderMapper.update(new LambdaUpdateWrapper<OrderDO>().eq(OrderDO::getId, orderDO.getId()).set(OrderDO::getCustomPlatenoSeq, JsonUtils.zipString(JSON.toJSONString(orderCustomPlateNoSeqVO))));
|
||||
}
|
||||
}
|
||||
|
||||
+7
-10
@@ -93,18 +93,17 @@ public class PlateNoGenerateRuleServiceImpl implements CustomPlateNoGenerateRule
|
||||
List<OrderDO> orderDOS = orderMapper.selectList(
|
||||
new LambdaQueryWrapper<OrderDO>().eq(OrderDO::getCustomPlatenoConfigId, configId).eq(OrderDO::getOrganId, OrganContextHolder.getOrganId()));
|
||||
|
||||
Integer initValue = ruleDTO.getInitValue();
|
||||
ResetModeEnum resetModeEnum = ResetModeEnum.getByMode(ruleDTO.getResetMode());
|
||||
// 根据复位模式更新生产单的序号
|
||||
for (OrderDO orderDO : orderDOS) {
|
||||
OrderCustomPlateNoSeqVO orderCustomPlateNoSeqVO = JSON.parseObject(orderDO.getCustomPlatenoSeq(), OrderCustomPlateNoSeqVO.class);
|
||||
if (ObjectUtil.isNotNull(orderCustomPlateNoSeqVO)) {
|
||||
if (ObjectUtil.equal(ResetModeEnum.ORDER, resetModeEnum)) {
|
||||
orderCustomPlateNoSeqVO.setPlateNoSeq(initValue);
|
||||
orderCustomPlateNoSeqVO.setPlateNoSeq(null);
|
||||
} else if (ObjectUtil.equal(ResetModeEnum.ROOM, resetModeEnum)) {
|
||||
resetRoomPlateSeq(orderCustomPlateNoSeqVO.getRooms(), initValue);
|
||||
resetRoomPlateSeq(orderCustomPlateNoSeqVO.getRooms());
|
||||
} else if (ObjectUtil.equal(ResetModeEnum.BODY, resetModeEnum)) {
|
||||
resetBodyPlateSeq(orderCustomPlateNoSeqVO.getRooms(), initValue);
|
||||
resetBodyPlateSeq(orderCustomPlateNoSeqVO.getRooms());
|
||||
}
|
||||
orderMapper.update(new LambdaUpdateWrapper<OrderDO>().eq(OrderDO::getId, orderDO.getId()).set(OrderDO::getCustomPlatenoSeq, JsonUtils.zipString(JSON.toJSONString(orderCustomPlateNoSeqVO))));
|
||||
}
|
||||
@@ -115,12 +114,11 @@ public class PlateNoGenerateRuleServiceImpl implements CustomPlateNoGenerateRule
|
||||
* 复位生产单下房间中的板件序号
|
||||
*
|
||||
* @param rooms
|
||||
* @param initValue
|
||||
*/
|
||||
private void resetRoomPlateSeq(List<OrderCustomPlateNoSeqRoomVO> rooms, Integer initValue) {
|
||||
private void resetRoomPlateSeq(List<OrderCustomPlateNoSeqRoomVO> rooms) {
|
||||
if (CollUtil.isNotEmpty(rooms)) {
|
||||
for (OrderCustomPlateNoSeqRoomVO roomVO : rooms) {
|
||||
roomVO.setPlateNoSeq(initValue);
|
||||
roomVO.setPlateNoSeq(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -129,15 +127,14 @@ public class PlateNoGenerateRuleServiceImpl implements CustomPlateNoGenerateRule
|
||||
* 复位生产单下柜体中的板件序号
|
||||
*
|
||||
* @param rooms
|
||||
* @param initValue
|
||||
*/
|
||||
private void resetBodyPlateSeq(List<OrderCustomPlateNoSeqRoomVO> rooms, Integer initValue) {
|
||||
private void resetBodyPlateSeq(List<OrderCustomPlateNoSeqRoomVO> rooms) {
|
||||
if (CollUtil.isNotEmpty(rooms)) {
|
||||
for (OrderCustomPlateNoSeqRoomVO roomVO : rooms) {
|
||||
List<OrderCustomPlateNoSeqBodyVO> bodys = roomVO.getBodys();
|
||||
if (CollUtil.isNotEmpty(bodys)) {
|
||||
for (OrderCustomPlateNoSeqBodyVO bodyVO : bodys) {
|
||||
bodyVO.setPlateNoSeq(initValue);
|
||||
bodyVO.setPlateNoSeq(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -123,7 +123,7 @@ public class RoomNoGenerateRuleServiceImpl implements CustomPlateNoGenerateRuleS
|
||||
for (OrderDO orderDO : orderDOS) {
|
||||
OrderCustomPlateNoSeqVO orderCustomPlateNoSeqVO = JSON.parseObject(orderDO.getCustomPlatenoSeq(), OrderCustomPlateNoSeqVO.class);
|
||||
if (ObjectUtil.isNotNull(orderCustomPlateNoSeqVO)) {
|
||||
orderCustomPlateNoSeqVO.setRoomNoSeq(ruleDTO.getInitValue());
|
||||
orderCustomPlateNoSeqVO.setRoomNoSeq(null);
|
||||
orderMapper.update(new LambdaUpdateWrapper<OrderDO>().eq(OrderDO::getId, orderDO.getId()).set(OrderDO::getCustomPlatenoSeq, JsonUtils.zipString(JSON.toJSONString(orderCustomPlateNoSeqVO))));
|
||||
}
|
||||
}
|
||||
|
||||
+26
-18
@@ -10,6 +10,7 @@ import com.cf.imes.module.executor.controller.admin.orderParts.vo.OrderPartsResp
|
||||
import com.cf.imes.module.executor.dal.dataobject.order.OrderDO;
|
||||
import com.cf.imes.module.executor.util.fileConversion.admin.api.webcad.ApiDataTypeVo;
|
||||
import org.springframework.boot.system.ApplicationHome;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
@@ -39,7 +40,7 @@ public interface OrderService {
|
||||
* @param id 编号
|
||||
* @return 生产单表 order_{N}
|
||||
*/
|
||||
OrderDO getOrder(Long id );
|
||||
OrderDO getOrder(Long id);
|
||||
|
||||
/**
|
||||
* 获得生产单表 order_{N}分页
|
||||
@@ -63,44 +64,45 @@ public interface OrderService {
|
||||
* @param orderId: 生产单Id
|
||||
* @return Map<String, Object>
|
||||
*/
|
||||
Map<String,Object> getModule(Long orderId, Integer deleted);
|
||||
Map<String, Object> getModule(Long orderId, Integer deleted);
|
||||
|
||||
/**
|
||||
* @param orderId: 生产单id
|
||||
* @param roomId: 房间id
|
||||
* @param bodyId: 柜体id
|
||||
* @param roomId: 房间id
|
||||
* @param bodyId: 柜体id
|
||||
* @return List<OrderPlatesDetailReqVO>
|
||||
* 需要修改返回值
|
||||
* 需要修改返回值
|
||||
*/
|
||||
PageResult<OrderPlatesDetailReqVO> getPlatesDetail(Long orderId, Set<Long> roomId, Set<Long> bodyId, Set<Long> groupId, String groupName, Integer pageNo, Integer pageSize, Integer deleted);
|
||||
|
||||
/**
|
||||
* @param orderId: 生产单id
|
||||
* @param roomId: 房间id
|
||||
* @param bodyId: 柜体id
|
||||
* @param roomId: 房间id
|
||||
* @param bodyId: 柜体id
|
||||
* @return List<OrderPartsRespVO>
|
||||
* 需要修改返回值
|
||||
* 需要修改返回值
|
||||
*/
|
||||
PageResult<OrderPartsRespVO> getPartsDetail(Long orderId, Set<Long> roomId , Set<Long> bodyId, Set<Long> groupId, String name, Integer pageNo, Integer pageSize, Integer deleted, Set<String> types);
|
||||
PageResult<OrderPartsRespVO> getPartsDetail(Long orderId, Set<Long> roomId, Set<Long> bodyId, Set<Long> groupId, String name, Integer pageNo, Integer pageSize, Integer deleted, Set<String> types);
|
||||
|
||||
/**
|
||||
* @param orderId: 生产单id
|
||||
* @param roomId: 房间id
|
||||
* @param bodyId: 柜体id
|
||||
* @param roomId: 房间id
|
||||
* @param bodyId: 柜体id
|
||||
* @return List<OrderGoodsDetailRespVO>
|
||||
* 需要修改返回值
|
||||
* 需要修改返回值
|
||||
*/
|
||||
PageResult<OrderGoodsDetailRespVO> getGoodsDetail(Long orderId, Set<Long> roomId , Set<Long> bodyId, Set<Long> groupId, Set<Long> goodsId, Integer pageNo, Integer pageSize, Integer deleted);
|
||||
PageResult<OrderGoodsDetailRespVO> getGoodsDetail(Long orderId, Set<Long> roomId, Set<Long> bodyId, Set<Long> groupId, Set<Long> goodsId, Integer pageNo, Integer pageSize, Integer deleted);
|
||||
|
||||
/**
|
||||
* 删除柜体/柜体还原
|
||||
*
|
||||
* @param orderId: 生产单id
|
||||
* @param roomId: 房间id
|
||||
* @param bodyId: 柜体id
|
||||
* @param roomId: 房间id
|
||||
* @param bodyId: 柜体id
|
||||
*/
|
||||
void updateDeleteBody(Long orderId , Set<Long> roomId, Long bodyId, Integer status);
|
||||
void updateDeleteBody(Long orderId, Set<Long> roomId, Long bodyId, Integer status);
|
||||
|
||||
void updateRestoreBody(Long orderId , Set<Long> roomId, Long bodyId, Integer status);
|
||||
void updateRestoreBody(Long orderId, Set<Long> roomId, Long bodyId, Integer status);
|
||||
|
||||
/**
|
||||
* @param apiDataTypeVo:生产单号
|
||||
@@ -121,7 +123,7 @@ public interface OrderService {
|
||||
/**
|
||||
* 打印/导出数据获取 (单文件)
|
||||
*/
|
||||
Map<String, Object> getPrintDataMap(Long orderId, String type,HttpServletResponse response) ;
|
||||
Map<String, Object> getPrintDataMap(Long orderId, String type, HttpServletResponse response);
|
||||
|
||||
default String getSavePath() {
|
||||
ApplicationHome applicationHome = new ApplicationHome(this.getClass());
|
||||
@@ -164,4 +166,10 @@ public interface OrderService {
|
||||
*/
|
||||
void realDeletedOrder(Long orderId);
|
||||
|
||||
/**
|
||||
* 生产单异步导入
|
||||
*
|
||||
* @param importAsyncReqVO
|
||||
*/
|
||||
void orderImportAsync(OrderImportAsyncReqVO importAsyncReqVO, MultipartFile file);
|
||||
}
|
||||
+28
-1
@@ -1,6 +1,7 @@
|
||||
package com.cf.imes.module.executor.service.order;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
@@ -10,10 +11,12 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
|
||||
import com.cf.imes.framework.common.enums.DeletedCodeEnum;
|
||||
import com.cf.imes.framework.common.enums.OrderPackageStatusEnum;
|
||||
import com.cf.imes.framework.common.exception.util.ServiceExceptionUtil;
|
||||
import com.cf.imes.framework.common.pojo.PageParam;
|
||||
import com.cf.imes.framework.common.pojo.PageResult;
|
||||
import com.cf.imes.framework.common.util.Assert.AssertUtils;
|
||||
import com.cf.imes.framework.common.util.object.BeanUtils;
|
||||
import com.cf.imes.framework.id.core.util.SnowflakeIdWorker3rd;
|
||||
import com.cf.imes.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import com.cf.imes.framework.organ.core.context.OrganContextHolder;
|
||||
import com.cf.imes.framework.security.core.util.SecurityFrameworkUtils;
|
||||
@@ -62,13 +65,17 @@ import com.cf.imes.module.executor.enums.OrderStatusEnum;
|
||||
import com.cf.imes.module.executor.service.customplateno.CustomPlateNoGenerateService;
|
||||
import com.cf.imes.module.executor.util.deviseData.structure.FieldConstants;
|
||||
import com.cf.imes.module.executor.util.deviseData.structure.PlateDetail;
|
||||
import com.cf.imes.module.executor.util.fileConversion.admin.SnowflakeIdWorker3rd;
|
||||
import com.cf.imes.module.executor.service.orderImport.OrderImportHandler;
|
||||
import com.cf.imes.module.executor.service.orderImport.factory.OrderImportHandlerFactory;
|
||||
import com.cf.imes.module.executor.service.plan.PlanService;
|
||||
import com.cf.imes.module.executor.util.fileConversion.admin.api.webcad.ApiDataTypeVo;
|
||||
import org.springframework.aop.framework.AopContext;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@@ -162,6 +169,13 @@ public class OrderServiceImpl implements OrderService {
|
||||
String ORDER_REMAIN_PLATE_MODEL = "imes_order_optimize_plate_model";
|
||||
|
||||
|
||||
|
||||
@Resource
|
||||
private PlanService planService;
|
||||
|
||||
@Autowired
|
||||
private OrderImportHandlerFactory orderImportHandlerFactory;
|
||||
|
||||
@Override
|
||||
public void updateOrder(OrderSaveReqVO updateReqVO) {
|
||||
// 校验存在, 生产单未删除
|
||||
@@ -1377,5 +1391,18 @@ public class OrderServiceImpl implements OrderService {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void orderImportAsync(OrderImportAsyncReqVO importAsyncReqVO, MultipartFile file) {
|
||||
// 根据导入类型和工厂(预留)获取处理类
|
||||
OrderImportHandler orderImportHandler = orderImportHandlerFactory.getOrderImportHandler(importAsyncReqVO.getType(), null);
|
||||
// 如果是补板校验生产单存在
|
||||
Long orderId = importAsyncReqVO.getOrderId();
|
||||
if (ObjectUtil.isNotNull(orderId)) {
|
||||
Optional.ofNullable(getOrder(orderId)).orElseThrow(() -> ServiceExceptionUtil.exception(ORDER_IMPORT_ORDER_NOT_EXISTS, orderId));
|
||||
}
|
||||
// 准备前置数据,准备完成发送消息消费解析临时表
|
||||
orderImportHandler.prepareAndConvert(importAsyncReqVO, file);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package com.cf.imes.module.executor.service.orderImport;
|
||||
|
||||
import com.cf.imes.module.executor.controller.admin.order.vo.order.OrderImportAsyncReqVO;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* 生产单导入处理器抽象类
|
||||
*
|
||||
* @author Gqr
|
||||
* @since 2024/11/8 16:45
|
||||
*/
|
||||
public interface OrderImportHandler {
|
||||
/**
|
||||
* 获取工厂名,默认走default
|
||||
* @return
|
||||
*/
|
||||
String getFactoryName();
|
||||
|
||||
/**
|
||||
* 准备、转换前置数据
|
||||
*
|
||||
*/
|
||||
void prepareAndConvert(OrderImportAsyncReqVO importAsyncReqVO, MultipartFile file);
|
||||
}
|
||||
+126
@@ -0,0 +1,126 @@
|
||||
package com.cf.imes.module.executor.service.orderImport.factory;
|
||||
|
||||
import com.cf.imes.framework.common.exception.ServiceException;
|
||||
import com.cf.imes.framework.common.exception.util.ServiceExceptionUtil;
|
||||
import com.cf.imes.module.executor.enums.ErrorCodeConstants;
|
||||
import com.cf.imes.module.executor.enums.OrderImportTypeEnum;
|
||||
import com.cf.imes.module.executor.service.orderImport.OrderImportHandler;
|
||||
import com.cf.imes.module.executor.service.orderImport.handler.api.AbstractApiOrderImportHandler;
|
||||
import com.cf.imes.module.executor.service.orderImport.handler.excel.AbstractExcelOrderImportHandler;
|
||||
import com.cf.imes.module.executor.service.orderImport.handler.json.AbstractJsonOrderImportHandler;
|
||||
import com.cf.imes.module.executor.service.orderImport.handler.xml.AbstractXmlOrderImportHandler;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 生产单导入处理器工厂类
|
||||
*
|
||||
* @author Gqr
|
||||
* @since 2024/11/28 16:21
|
||||
*/
|
||||
@Component
|
||||
public class OrderImportHandlerFactory {
|
||||
private final ApplicationContext applicationContext;
|
||||
|
||||
@Autowired
|
||||
public OrderImportHandlerFactory(ApplicationContext applicationContext) {
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据导入类型获取对应的处理器
|
||||
*
|
||||
* @param type 导入类型
|
||||
* @param factoryName 工厂名称预留
|
||||
* @return
|
||||
*/
|
||||
public OrderImportHandler getOrderImportHandler(int type, String factoryName) {
|
||||
OrderImportTypeEnum importTypeEnum = OrderImportTypeEnum.match(type);
|
||||
// 没有传入工厂/厂商用default
|
||||
if (StringUtils.isEmpty(factoryName)) {
|
||||
factoryName = "default";
|
||||
}
|
||||
ServiceException typeNotSupportException = ServiceExceptionUtil.exception(ErrorCodeConstants.ORDER_IMPORT_TYPE_NOT_SUPPORT, type);
|
||||
switch (importTypeEnum) {
|
||||
case EXCEL:
|
||||
return Optional.ofNullable(getExcelHandler(factoryName)).orElseThrow(() -> typeNotSupportException);
|
||||
case JSON:
|
||||
return Optional.ofNullable(getJsonHandler(factoryName)).orElseThrow(() -> typeNotSupportException);
|
||||
case XML:
|
||||
return Optional.ofNullable(getXmlHandler(factoryName)).orElseThrow(() -> typeNotSupportException);
|
||||
case API:
|
||||
return Optional.ofNullable(getApiHandler(factoryName)).orElseThrow(() -> typeNotSupportException);
|
||||
default:
|
||||
throw typeNotSupportException;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取excel处理类
|
||||
*
|
||||
* @param factoryName
|
||||
* @return
|
||||
*/
|
||||
private OrderImportHandler getExcelHandler(String factoryName) {
|
||||
for (Map.Entry<String, AbstractExcelOrderImportHandler> entry : applicationContext.getBeansOfType(AbstractExcelOrderImportHandler.class).entrySet()) {
|
||||
AbstractExcelOrderImportHandler entryValue = entry.getValue();
|
||||
if (factoryName.equals(entryValue.getFactoryName())) {
|
||||
return entryValue;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取json处理类
|
||||
*
|
||||
* @param factoryName
|
||||
* @return
|
||||
*/
|
||||
private OrderImportHandler getJsonHandler(String factoryName) {
|
||||
for (Map.Entry<String, AbstractJsonOrderImportHandler> entry : applicationContext.getBeansOfType(AbstractJsonOrderImportHandler.class).entrySet()) {
|
||||
AbstractJsonOrderImportHandler entryValue = entry.getValue();
|
||||
if (factoryName.equals(entryValue.getFactoryName())) {
|
||||
return entryValue;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取xml处理类
|
||||
*
|
||||
* @param factoryName
|
||||
* @return
|
||||
*/
|
||||
private OrderImportHandler getXmlHandler(String factoryName) {
|
||||
for (Map.Entry<String, AbstractXmlOrderImportHandler> entry : applicationContext.getBeansOfType(AbstractXmlOrderImportHandler.class).entrySet()) {
|
||||
AbstractXmlOrderImportHandler entryValue = entry.getValue();
|
||||
if (factoryName.equals(entryValue.getFactoryName())) {
|
||||
return entryValue;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取api处理类
|
||||
*
|
||||
* @param factoryName
|
||||
* @return
|
||||
*/
|
||||
private OrderImportHandler getApiHandler(String factoryName) {
|
||||
for (Map.Entry<String, AbstractApiOrderImportHandler> entry : applicationContext.getBeansOfType(AbstractApiOrderImportHandler.class).entrySet()) {
|
||||
AbstractApiOrderImportHandler entryValue = entry.getValue();
|
||||
if (factoryName.equals(entryValue.getFactoryName())) {
|
||||
return entryValue;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package com.cf.imes.module.executor.service.orderImport.handler.api;
|
||||
|
||||
import com.cf.imes.module.executor.service.orderImport.OrderImportHandler;
|
||||
|
||||
/**
|
||||
* 生产单api导入处理器抽象类
|
||||
*
|
||||
* @author Gqr
|
||||
* @since 2025/1/8 16:35
|
||||
*/
|
||||
public interface AbstractApiOrderImportHandler extends OrderImportHandler {
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package com.cf.imes.module.executor.service.orderImport.handler.api;
|
||||
|
||||
import com.cf.imes.module.executor.controller.admin.order.vo.order.OrderImportAsyncReqVO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* 默认api生产单导入处理器
|
||||
*
|
||||
* @author Gqr
|
||||
* @since 2025/1/9 9:21
|
||||
*/
|
||||
@Service("defaultApiOrderImportHandler")
|
||||
@Slf4j
|
||||
public class DefaultApiOrderImportHandler implements AbstractApiOrderImportHandler {
|
||||
@Override
|
||||
public String getFactoryName() {
|
||||
return "default";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareAndConvert(OrderImportAsyncReqVO importAsyncReqVO, MultipartFile file) {
|
||||
// todo api 准备、转换前置数据
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package com.cf.imes.module.executor.service.orderImport.handler.excel;
|
||||
|
||||
import com.cf.imes.module.executor.service.orderImport.OrderImportHandler;
|
||||
|
||||
/**
|
||||
* 生产单excel导入处理器抽象类
|
||||
*
|
||||
* @author Gqr
|
||||
* @since 2025/1/8 16:35
|
||||
*/
|
||||
public interface AbstractExcelOrderImportHandler extends OrderImportHandler {
|
||||
}
|
||||
+139
@@ -0,0 +1,139 @@
|
||||
package com.cf.imes.module.executor.service.orderImport.handler.excel;
|
||||
|
||||
import com.alibaba.excel.EasyExcelFactory;
|
||||
import com.cf.imes.framework.common.exception.ServiceException;
|
||||
import com.cf.imes.framework.mq.rabbitmq.constant.RabbitMqConstants;
|
||||
import com.cf.imes.framework.mybatis.core.generator.SnowFlakeGenerator;
|
||||
import com.cf.imes.framework.redis.config.ChenfengCacheProperties;
|
||||
import com.cf.imes.framework.redis.constants.RedisKeyConstants;
|
||||
import com.cf.imes.framework.redis.util.RedisLockUtil;
|
||||
import com.cf.imes.module.executor.controller.admin.order.vo.order.OrderImportAsyncReqVO;
|
||||
import com.cf.imes.module.executor.dal.dataobject.orderImport.OrderImportTaskDO;
|
||||
import com.cf.imes.module.executor.dal.mysql.orderImport.OrderImportTaskMapper;
|
||||
import com.cf.imes.module.executor.dal.mysql.orderImport.OrderImportTempDataMapper;
|
||||
import com.cf.imes.module.executor.enums.OrderImportStatusEnum;
|
||||
import com.cf.imes.module.executor.enums.OrderImportTaskStatusEnum;
|
||||
import com.cf.imes.module.executor.enums.OrderImportTypeEnum;
|
||||
import com.cf.imes.module.executor.service.order.OrderService;
|
||||
import com.cf.imes.module.executor.util.fileConversion.admin.files.excel.DefaultOrderImportExcelListener;
|
||||
import com.cf.imes.module.system.api.dict.DictDataApi;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.amqp.core.Message;
|
||||
import org.springframework.amqp.core.MessageBuilder;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.transaction.support.TransactionSynchronization;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.InputStream;
|
||||
|
||||
import static com.cf.imes.framework.security.core.util.SecurityFrameworkUtils.getUserOrganId;
|
||||
import static com.cf.imes.module.executor.enums.ErrorCodeConstants.ORDER_IMPORT_FILE_ANALYZE_ERROR;
|
||||
import static com.cf.imes.module.executor.enums.ErrorCodeConstants.ORDER_IMPORT_ORGAN_LOCK_ERROR;
|
||||
|
||||
/**
|
||||
* 默认excel生产单导入处理器
|
||||
* @author Gqr
|
||||
* @since 2025/1/9 9:21
|
||||
*/
|
||||
@Service("defaultExcelOrderImportHandler")
|
||||
@Slf4j
|
||||
public class DefaultExcelOrderImportHandler implements AbstractExcelOrderImportHandler {
|
||||
|
||||
@Resource
|
||||
private OrderImportTempDataMapper orderImportTempDataMapper;
|
||||
|
||||
@Resource
|
||||
private OrderService orderService;
|
||||
|
||||
@Resource
|
||||
private SnowFlakeGenerator snowFlakeGenerator;
|
||||
|
||||
@Resource
|
||||
private OrderImportTaskMapper orderImportTaskMapper;
|
||||
|
||||
@Resource
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
|
||||
@Resource
|
||||
private DictDataApi dictDataApi;
|
||||
|
||||
@Resource
|
||||
private RedisLockUtil redisLockUtil;
|
||||
|
||||
@Resource
|
||||
private ChenfengCacheProperties chenfengCacheProperties;
|
||||
|
||||
@Override
|
||||
public String getFactoryName() {
|
||||
return "default";
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void prepareAndConvert(OrderImportAsyncReqVO importAsyncReqVO, MultipartFile file) {
|
||||
// 创建任务
|
||||
Long taskId = createImportTask();
|
||||
String importLockKey = String.format(RedisKeyConstants.ORDER_IMPORT_LOCK_KEY, getUserOrganId());
|
||||
// 检查机构导入锁
|
||||
boolean lockResult = redisLockUtil.lock(importLockKey, String.valueOf(taskId), chenfengCacheProperties.getLockTimeout());
|
||||
if (!lockResult) {
|
||||
throw new ServiceException(ORDER_IMPORT_ORGAN_LOCK_ERROR);
|
||||
}
|
||||
DefaultOrderImportExcelListener excelListener =
|
||||
new DefaultOrderImportExcelListener(orderImportTempDataMapper, orderService, dictDataApi, snowFlakeGenerator, importAsyncReqVO.getOrderId(), taskId);
|
||||
|
||||
try (InputStream inputStream = file.getInputStream()) {
|
||||
// 读取excel
|
||||
EasyExcelFactory.read(inputStream, excelListener).headRowNumber(-1).sheet().doRead();
|
||||
} catch (ServiceException sev) {
|
||||
// 导入锁解锁
|
||||
redisLockUtil.unlock(importLockKey, taskId.toString());
|
||||
throw sev;
|
||||
} catch (Exception e) {
|
||||
log.error(ORDER_IMPORT_FILE_ANALYZE_ERROR.getMsg(), e);
|
||||
// 导入锁解锁
|
||||
redisLockUtil.unlock(importLockKey, taskId.toString());
|
||||
throw new ServiceException(ORDER_IMPORT_FILE_ANALYZE_ERROR);
|
||||
}
|
||||
|
||||
Message message = MessageBuilder
|
||||
.withBody(taskId.toString().getBytes())
|
||||
.setHeader("x-message-ttl", 60000) // 设置 TTL 为 60000 毫秒(60 秒)
|
||||
.build();
|
||||
//如果处于事务中,待事务提交成功了再执行后续操作,防止事务未提交完成导致消费端查不到数据
|
||||
if (TransactionSynchronizationManager.isActualTransactionActive()) {
|
||||
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
|
||||
@Override
|
||||
public void afterCommit() {
|
||||
// 数据库操作全部完成发送消息
|
||||
rabbitTemplate.convertAndSend(RabbitMqConstants.ORDER_IMPORT_DEFAULT_EXCEL_EXCHANGE, null, message);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// 数据库操作全部完成发送消息
|
||||
rabbitTemplate.convertAndSend(RabbitMqConstants.ORDER_IMPORT_DEFAULT_EXCEL_EXCHANGE, null, message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建导入任务
|
||||
*
|
||||
* @return taskId
|
||||
*/
|
||||
private Long createImportTask() {
|
||||
// 创建导入任务
|
||||
OrderImportTaskDO orderImportTaskDO = OrderImportTaskDO.builder()
|
||||
.id((Long) snowFlakeGenerator.nextId(null))
|
||||
.type(OrderImportTypeEnum.EXCEL.getType())
|
||||
.importStatus(OrderImportStatusEnum.IMPORT_NOT_YET.getStatus())
|
||||
.status(OrderImportTaskStatusEnum.CREATE_NOT_CONSUME.getStatus())
|
||||
.build();
|
||||
orderImportTaskMapper.insert(orderImportTaskDO);
|
||||
return orderImportTaskDO.getId();
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package com.cf.imes.module.executor.service.orderImport.handler.json;
|
||||
|
||||
|
||||
import com.cf.imes.module.executor.service.orderImport.OrderImportHandler;
|
||||
|
||||
/**
|
||||
* 生产单json导入处理器抽象类
|
||||
*
|
||||
* @author Gqr
|
||||
* @since 2025/1/8 16:35
|
||||
*/
|
||||
public interface AbstractJsonOrderImportHandler extends OrderImportHandler {
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package com.cf.imes.module.executor.service.orderImport.handler.json;
|
||||
|
||||
import com.cf.imes.module.executor.controller.admin.order.vo.order.OrderImportAsyncReqVO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* 默认json生产单导入处理器
|
||||
*
|
||||
* @author Gqr
|
||||
* @since 2025/1/9 9:21
|
||||
*/
|
||||
@Service("defaultJsonOrderImportHandler")
|
||||
@Slf4j
|
||||
public class DefaultJsonOrderImportHandler implements AbstractJsonOrderImportHandler {
|
||||
@Override
|
||||
public String getFactoryName() {
|
||||
return "default";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareAndConvert(OrderImportAsyncReqVO importAsyncReqVO, MultipartFile file) {
|
||||
// todo json 准备、转换前置数据
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package com.cf.imes.module.executor.service.orderImport.handler.xml;
|
||||
|
||||
import com.cf.imes.module.executor.service.orderImport.OrderImportHandler;
|
||||
|
||||
/**
|
||||
* 生产单xml导入处理器抽象类
|
||||
*
|
||||
* @author Gqr
|
||||
* @since 2025/1/8 16:35
|
||||
*/
|
||||
public interface AbstractXmlOrderImportHandler extends OrderImportHandler {
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package com.cf.imes.module.executor.service.orderImport.handler.xml;
|
||||
|
||||
import com.cf.imes.module.executor.controller.admin.order.vo.order.OrderImportAsyncReqVO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/**
|
||||
* @author Gqr
|
||||
* @since 2025/1/9 9:21
|
||||
*/
|
||||
@Service("defaultXmlOrderImportHandler")
|
||||
@Slf4j
|
||||
public class DefaultXmlOrderImportHandler implements AbstractXmlOrderImportHandler {
|
||||
@Override
|
||||
public String getFactoryName() {
|
||||
return "default";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepareAndConvert(OrderImportAsyncReqVO importAsyncReqVO, MultipartFile file) {
|
||||
// todo xml 准备、转换前置数据
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -20,6 +20,7 @@ import com.cf.imes.framework.common.pojo.PageResult;
|
||||
import com.cf.imes.framework.common.util.Assert.AssertUtils;
|
||||
import com.cf.imes.framework.common.util.object.BeanUtils;
|
||||
import com.cf.imes.framework.es.core.service.ESDocumentService;
|
||||
import com.cf.imes.framework.id.core.util.SnowflakeIdWorker3rd;
|
||||
import com.cf.imes.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import com.cf.imes.framework.mybatis.core.query.MPJLambdaWrapperX;
|
||||
import com.cf.imes.framework.mybatis.core.query.QueryWrapperX;
|
||||
@@ -49,7 +50,6 @@ import com.cf.imes.module.executor.enums.OrderItemType;
|
||||
import com.cf.imes.module.executor.enums.OrderStatusEnum;
|
||||
import com.cf.imes.module.executor.service.plan.PlanService;
|
||||
import com.cf.imes.module.executor.util.elasticsearch.EsUtils;
|
||||
import com.cf.imes.module.executor.util.fileConversion.admin.SnowflakeIdWorker3rd;
|
||||
import com.cf.imes.module.system.enums.ErrorCodeConstants;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
-25
@@ -1,25 +0,0 @@
|
||||
package com.cf.imes.module.executor.util;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class MinuteCounter {
|
||||
private static final int MASK = 0x7FFFFFFF;
|
||||
private final AtomicInteger atom;
|
||||
|
||||
public MinuteCounter() {
|
||||
atom = new AtomicInteger(0);
|
||||
}
|
||||
|
||||
public final int incrementAndGet() {
|
||||
return atom.incrementAndGet() & MASK;
|
||||
}
|
||||
|
||||
public int get() {
|
||||
return atom.get() & MASK;
|
||||
}
|
||||
|
||||
public void set(int newValue) {
|
||||
atom.set(newValue & MASK);
|
||||
}
|
||||
|
||||
}
|
||||
-133
@@ -1,133 +0,0 @@
|
||||
package com.cf.imes.module.executor.util.fileConversion.admin;
|
||||
|
||||
|
||||
import com.cf.imes.module.executor.util.MinuteCounter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
/**
|
||||
* @ClassName: SnowflakeIdWorker3rd
|
||||
* @Description:snowflake算法改进
|
||||
* @author: yonnie
|
||||
* @date: 2024/06/18 14:10:47
|
||||
* @version V1.0
|
||||
*
|
||||
* 将产生的Id类型更改为Integer 32bit <br>
|
||||
* 把时间戳的单位改为分钟,使用25bit的时间戳
|
||||
* 7bit作为自增值即 2^7 = 128
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class SnowflakeIdWorker3rd {
|
||||
/** 初始时间 (2024-01-01: 1704038400) */
|
||||
// private final int twepoch = 28400640;// 1704038400000L/1000/60;
|
||||
private final int twepoch = 1704038400;
|
||||
/** 序列在id中占位数 */
|
||||
private final long sequenceBits = 7L;
|
||||
/** 时间截向左移7bit */
|
||||
private final long timestampLeftShift = sequenceBits;
|
||||
/** 生成序列的MASK (0x7F) */
|
||||
private final int sequenceMask = -1 ^ (-1 << sequenceBits);
|
||||
/** 分钟内序 (0~127) */
|
||||
private int sequence = 0;
|
||||
private int laterSequence = 0;
|
||||
/** 上次生成ID的时间戳 */
|
||||
private int lastTimestamp = -1;
|
||||
private final MinuteCounter counter = new MinuteCounter();
|
||||
/** 预支时间标志 */
|
||||
boolean isAdvance = false;
|
||||
|
||||
// ==============================Constructors=====================================
|
||||
|
||||
public SnowflakeIdWorker3rd() {
|
||||
// No Args Constructors
|
||||
}
|
||||
|
||||
// ==============================Test=============================================
|
||||
|
||||
/** 测试 */
|
||||
public static void main(String[] args) {
|
||||
SnowflakeIdWorker3rd idWorker = new SnowflakeIdWorker3rd();
|
||||
long obtainingTime = idWorker.obtainingTime();
|
||||
for (int i = 0; i < 10001; i++) {
|
||||
long id = idWorker.nextId();
|
||||
System.out.println(i + ": " + id + " " + obtainingTime + Long.toString(id).substring(2));
|
||||
}
|
||||
// long id = idWorker.nextId();
|
||||
// System.out.println(id);
|
||||
}
|
||||
|
||||
// ==============================Methods==========================================
|
||||
/**
|
||||
* 获取当前年月
|
||||
* @return null
|
||||
*/
|
||||
public static int obtainingTime() {
|
||||
LocalDate now = LocalDate.now();
|
||||
int year = now.getYear();
|
||||
String year_last_two_digits = String.valueOf(year).substring(2);
|
||||
int month = now.getMonthValue();
|
||||
String formatted_date = year_last_two_digits + String.format("%02d", month);
|
||||
return Integer.parseInt(formatted_date);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得下一个ID (该方法是线程安全)
|
||||
*
|
||||
* @return SnowflakeId
|
||||
*/
|
||||
public synchronized int nextId() {
|
||||
int timestamp = timeGen();
|
||||
// 如果当前时间小于上一次ID生成的时间戳,说明系统时钟修改过
|
||||
if (timestamp < lastTimestamp) {
|
||||
throw new RuntimeException(String.format(
|
||||
"Clock moved backwards. Refusing to generate id for %d milliseconds", lastTimestamp - timestamp));
|
||||
}
|
||||
|
||||
if (timestamp > counter.get()) {
|
||||
counter.set(timestamp);
|
||||
isAdvance = false;
|
||||
}
|
||||
|
||||
// 如果是同时间生成的,则进行分钟内序列
|
||||
if (lastTimestamp == timestamp || isAdvance) {
|
||||
if (!isAdvance) {
|
||||
sequence = (sequence + 1) & sequenceMask;
|
||||
}
|
||||
|
||||
// 分钟内自增列溢出
|
||||
if (sequence == 0) {
|
||||
// 预支下一分获得新的时间戳
|
||||
isAdvance = true;
|
||||
int laterTimestamp = counter.get();
|
||||
if (laterSequence == 0) {
|
||||
laterTimestamp = counter.incrementAndGet();
|
||||
}
|
||||
int nextId = ((laterTimestamp - twepoch) << timestampLeftShift) | laterSequence;
|
||||
laterSequence = (laterSequence + 1) & sequenceMask;
|
||||
return nextId;
|
||||
}
|
||||
} else { // 时间戳改变,分钟内序列置0
|
||||
sequence = 0;
|
||||
laterSequence = 0;
|
||||
}
|
||||
// 上次生成ID的时间截
|
||||
lastTimestamp = timestamp;
|
||||
// 移位并或运算拼成32位的ID
|
||||
return ((timestamp - twepoch) << timestampLeftShift) | sequence;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回以分钟为单位的当前时
|
||||
*
|
||||
* @return 当前时间(分钟)
|
||||
*/
|
||||
protected int timeGen() {
|
||||
// String timestamp = String.valueOf(System.currentTimeMillis() / 1000 / 60);
|
||||
String timestamp = String.valueOf(System.currentTimeMillis() / 1000);
|
||||
return Integer.valueOf(timestamp);
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -3,6 +3,7 @@ package com.cf.imes.module.executor.util.fileConversion.admin.api.webcad;//packa
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
|
||||
import com.cf.imes.framework.id.core.util.SnowflakeIdWorker3rd;
|
||||
import com.cf.imes.module.executor.controller.admin.orderParts.vo.OrderPartsRemark;
|
||||
import com.cf.imes.module.executor.controller.admin.plan.dto.Point;
|
||||
import com.cf.imes.module.executor.dal.dataobject.goods.GoodsDO;
|
||||
@@ -14,7 +15,6 @@ import com.cf.imes.module.executor.dal.dataobject.orderParts.OrderPartsDO;
|
||||
import com.cf.imes.module.executor.dal.dataobject.plate.PlateDO;
|
||||
import com.cf.imes.module.executor.dal.dataobject.rawgoods.RawGoodsDO;
|
||||
import com.cf.imes.module.executor.enums.*;
|
||||
import com.cf.imes.module.executor.util.fileConversion.admin.SnowflakeIdWorker3rd;
|
||||
import com.cf.imes.module.executor.util.deviseData.structure.*;
|
||||
import com.cf.imes.module.system.api.dict.DictDataApi;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
+721
@@ -0,0 +1,721 @@
|
||||
package com.cf.imes.module.executor.util.fileConversion.admin.files.excel;
|
||||
|
||||
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.excel.context.AnalysisContext;
|
||||
import com.alibaba.excel.event.AnalysisEventListener;
|
||||
import com.alibaba.excel.read.metadata.holder.ReadRowHolder;
|
||||
import com.alibaba.excel.util.ListUtils;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.cf.imes.framework.common.exception.ServiceException;
|
||||
import com.cf.imes.framework.common.exception.util.ServiceExceptionUtil;
|
||||
import com.cf.imes.framework.common.util.json.JsonUtils;
|
||||
import com.cf.imes.framework.mybatis.core.generator.SnowFlakeGenerator;
|
||||
import com.cf.imes.framework.organ.core.context.OrganContextHolder;
|
||||
import com.cf.imes.framework.web.core.util.WebFrameworkUtils;
|
||||
import com.cf.imes.module.executor.dal.dataobject.order.OrderDO;
|
||||
import com.cf.imes.module.executor.dal.dataobject.orderImport.OrderImportTempDataDO;
|
||||
import com.cf.imes.module.executor.dal.mysql.orderImport.OrderImportTempDataMapper;
|
||||
import com.cf.imes.module.executor.enums.CategoryEnum;
|
||||
import com.cf.imes.module.executor.enums.DataTypeEnum;
|
||||
import com.cf.imes.module.executor.enums.DictTypeConstants;
|
||||
import com.cf.imes.module.executor.enums.IsHavaeEnum;
|
||||
import com.cf.imes.module.executor.enums.OrderImportConstants;
|
||||
import com.cf.imes.module.executor.enums.OrderImportTmpDataTypeEnum;
|
||||
import com.cf.imes.module.executor.enums.OrderStatusEnum;
|
||||
import com.cf.imes.module.executor.enums.QuarrelEnum;
|
||||
import com.cf.imes.module.executor.service.order.OrderService;
|
||||
import com.cf.imes.module.executor.util.fileConversion.admin.ToolUtil;
|
||||
import com.cf.imes.module.system.api.dict.DictDataApi;
|
||||
import com.cf.imes.module.system.api.dict.dto.DictDataRespDTO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.cf.imes.module.executor.enums.ErrorCodeConstants.ORDER_IMPORT_DETAIL_VALID_ERROR;
|
||||
import static com.cf.imes.module.executor.enums.ErrorCodeConstants.ORDER_IMPORT_ORDER_CUSTOMERNO_EXISTS;
|
||||
import static com.cf.imes.module.executor.enums.ErrorCodeConstants.ORDER_IMPORT_ORDER_FIELD_DATE_FORMAT_ERROR;
|
||||
import static com.cf.imes.module.executor.enums.ErrorCodeConstants.ORDER_IMPORT_ORDER_FIELD_EMPTY;
|
||||
import static com.cf.imes.module.executor.enums.ErrorCodeConstants.ORDER_IMPORT_ORDER_FIELD_LENGTH_ERROR;
|
||||
import static com.cf.imes.module.executor.enums.ErrorCodeConstants.ORDER_IMPORT_ORDER_FIELD_MOBILE_FORMAT_ERROR;
|
||||
|
||||
/**
|
||||
* 默认生产单excel导入监听器
|
||||
*
|
||||
* @author Gqr
|
||||
* @since 2025/1/9 11:14
|
||||
*/
|
||||
@Slf4j
|
||||
public final class DefaultOrderImportExcelListener extends AnalysisEventListener<Map<Integer, String>> {
|
||||
/**
|
||||
* 每500条操作入库一次
|
||||
*/
|
||||
private static final int BATCH_COUNT = 500;
|
||||
private List<OrderImportTempDataDO> cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
|
||||
|
||||
/**
|
||||
* 存放生产单orders信息
|
||||
*/
|
||||
private OrderDO orderDO = OrderDO.builder().build();
|
||||
|
||||
/**
|
||||
* 停止解析标志
|
||||
*/
|
||||
private boolean stopParsing = false;
|
||||
|
||||
private OrderImportTempDataMapper orderImportTempDataMapper;
|
||||
|
||||
private OrderService orderService;
|
||||
|
||||
private DictDataApi dictDataApi;
|
||||
|
||||
private SnowFlakeGenerator snowFlakeGenerator;
|
||||
|
||||
/**
|
||||
* 补板用
|
||||
*/
|
||||
private Long orderId;
|
||||
|
||||
/**
|
||||
* 是否补板
|
||||
*/
|
||||
boolean addToExistsOrder;
|
||||
|
||||
/**
|
||||
* 导入任务id
|
||||
*/
|
||||
private Long taskId;
|
||||
|
||||
private int sort = 1;
|
||||
|
||||
private static final String NUMBER_TYPE_ERR = "数量类型错误";
|
||||
private static final String NOT_EMPTY = "不可为空";
|
||||
private static final String ACCORD_ENUM = "请按照提示词语选择填入";
|
||||
private static final String POSITIVE_ERR = "数据需为正数";
|
||||
private static final String NUMBER_LENGTH_ERR = "数据长度过长";
|
||||
|
||||
public DefaultOrderImportExcelListener(OrderImportTempDataMapper orderImportTempDataMapper, OrderService orderService, DictDataApi dictDataApi, SnowFlakeGenerator snowFlakeGenerator, Long orderId, Long taskId) {
|
||||
this.orderImportTempDataMapper = orderImportTempDataMapper;
|
||||
this.orderService = orderService;
|
||||
this.dictDataApi = dictDataApi;
|
||||
this.snowFlakeGenerator = snowFlakeGenerator;
|
||||
this.orderId = orderId;
|
||||
this.taskId = taskId;
|
||||
// 是否补板
|
||||
addToExistsOrder = ObjectUtil.isNotNull(orderId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(Map<Integer, String> data, AnalysisContext context) {
|
||||
log.info("解析到一条数据: {}", JSON.toJSONString(data));
|
||||
|
||||
// 获取行号
|
||||
ReadRowHolder readRowHolder = context.readRowHolder();
|
||||
Integer rowIndex = readRowHolder.getRowIndex();
|
||||
|
||||
// 生产单信息在1-5行间
|
||||
boolean isOrderInfo = (rowIndex >= 0 && rowIndex <= 4);
|
||||
// 板材/配件数据从第8行开始
|
||||
boolean isPlate = rowIndex > 6;
|
||||
|
||||
// 标记结束,后续数据不再记录
|
||||
if (data.get(0) != null && data.get(0).equals("***")) {
|
||||
log.info("解析到结束标记 ***, 停止写入!");
|
||||
stopParsing = true;
|
||||
}
|
||||
|
||||
// 缓存生产单数据
|
||||
// 补板的时候不更新生产单数据也就不缓存excel上的基础信息
|
||||
if (!stopParsing && isOrderInfo && !addToExistsOrder) {
|
||||
// 校验生产单数据
|
||||
validOrderInfo(data, rowIndex);
|
||||
}
|
||||
|
||||
// 缓存板材/配件数据
|
||||
if (!stopParsing && isPlate) {
|
||||
data.entrySet().removeIf(entry -> Objects.isNull(entry.getValue()));
|
||||
cachedDataList.add(checkData(setOrderPlateProperty(data)));
|
||||
}
|
||||
// 达到BATCH_COUNT了,需要去存储一次数据库,防止数据几万条数据在内存,容易OOM
|
||||
if (cachedDataList.size() >= BATCH_COUNT) {
|
||||
saveData();
|
||||
// 存储完成清理 list
|
||||
cachedDataList = ListUtils.newArrayListWithExpectedSize(BATCH_COUNT);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doAfterAllAnalysed(AnalysisContext context) {
|
||||
// 这里也要保存数据,确保最后遗留的数据也存储到数据库
|
||||
saveData();
|
||||
// 保存生产单数据
|
||||
saveOrderTempData();
|
||||
log.info("所有数据解析完成!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 板材数据保存临时表
|
||||
*/
|
||||
private void saveData() {
|
||||
log.info("{}条数据,开始保存临时板材数据!", cachedDataList.size());
|
||||
orderImportTempDataMapper.insertBatchSomeColumn(cachedDataList);
|
||||
log.info("excel导入临时板材数据保存成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 生产单数据保存临时表
|
||||
*/
|
||||
private void saveOrderTempData() {
|
||||
OrderImportTempDataDO orderInfoTempDataDO = OrderImportTempDataDO.builder()
|
||||
.id((Long) snowFlakeGenerator.nextId(null))
|
||||
.orderId(orderId)
|
||||
.taskId(taskId)
|
||||
.type(OrderImportTmpDataTypeEnum.ORDER.getType())
|
||||
.createTime(LocalDateTime.now())
|
||||
.sort(0)
|
||||
.build();
|
||||
// 非补板即新增生成单,记录基础信息
|
||||
if (!addToExistsOrder) {
|
||||
orderDO.setId(orderId);
|
||||
orderDO.setStatus(NumberUtil.compare(sort, 1) > 0 ? OrderStatusEnum.NEW_ORDER.getStatus() : OrderStatusEnum.EMPTY.getStatus());
|
||||
orderInfoTempDataDO.setDetail(JsonUtils.zipString(JSON.toJSONString(orderDO)));
|
||||
}
|
||||
orderImportTempDataMapper.insert(orderInfoTempDataDO);
|
||||
log.info("excel导入临时生产单数据保存成功!");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 生产单信息校验
|
||||
*
|
||||
* @param data 行数据
|
||||
* @param rowIndex 行号
|
||||
*/
|
||||
public void validOrderInfo(Map<Integer, String> data, Integer rowIndex) {
|
||||
// 左key
|
||||
String leftKey = data.get(0);
|
||||
// 左值
|
||||
String leftVal = data.get(1);
|
||||
// 右key
|
||||
String rightKey = data.get(19);
|
||||
// 右值
|
||||
String rightVal = data.get(20);
|
||||
// 左:自定义单号(非必填)、右:客户
|
||||
if (0 == rowIndex) {
|
||||
validOrderInfoLength(leftKey, leftVal, 32);
|
||||
validCustomOrderNo(leftKey, leftVal);
|
||||
validOrderInfoEmpty(rightKey, rightVal);
|
||||
validOrderInfoLength(rightKey, rightVal, 255);
|
||||
orderDO.setCustomOrderNo(leftVal);
|
||||
orderDO.setCustomer(rightVal);
|
||||
}
|
||||
// 左:经销商、右:客户地址
|
||||
if (1 == rowIndex) {
|
||||
validOrderInfoEmpty(rightKey, rightVal);
|
||||
validOrderInfoLength(rightKey, rightVal, 255);
|
||||
validOrderInfoEmpty(leftKey, leftVal);
|
||||
validOrderInfoLength(leftKey, leftVal, 255);
|
||||
orderDO.setDealer(leftVal);
|
||||
orderDO.setAddress(rightVal);
|
||||
}
|
||||
// 左:经销商电话(非必填)、右:客户电话
|
||||
if (2 == rowIndex) {
|
||||
validOrderInfoPhone(leftKey, leftVal);
|
||||
validOrderInfoEmpty(rightKey, rightVal);
|
||||
validOrderInfoPhone(rightKey, rightVal);
|
||||
orderDO.setDealerPhoneNumber(leftVal);
|
||||
orderDO.setPhoneNumber(rightVal);
|
||||
}
|
||||
// 左:业务员(非必填)、右:出货日期
|
||||
if (3 == rowIndex) {
|
||||
validOrderInfoLength(leftKey, leftVal, 64);
|
||||
validOrderInfoEmpty(rightKey, rightVal);
|
||||
LocalDate deliverDate = validOrderInfoDate(rightKey, rightVal);
|
||||
// 出货时间早于导入时间,自动延长30天
|
||||
if (deliverDate.isBefore(LocalDate.now())) {
|
||||
deliverDate = LocalDate.now().plus(30, ChronoUnit.DAYS);
|
||||
}
|
||||
orderDO.setSalesman(leftVal);
|
||||
orderDO.setDeliveryDate(deliverDate.atStartOfDay());
|
||||
}
|
||||
// 左:拆单员(非必填)、右:备注(非必填)
|
||||
if (4 == rowIndex) {
|
||||
validOrderInfoLength(leftKey, leftVal, 64);
|
||||
validOrderInfoLength(rightKey, rightVal, 255);
|
||||
orderDO.setSplitter(leftVal);
|
||||
orderDO.setRemark(rightVal);
|
||||
}
|
||||
orderDO.setDataType(DataTypeEnum.FILE_IMPORT.getStatus());
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
orderDO.setOrderDate(now);
|
||||
orderDO.setOrganId(OrganContextHolder.getOrganId());
|
||||
String loginUserName = WebFrameworkUtils.getLoginUserName();
|
||||
orderDO.setCreator(loginUserName);
|
||||
orderDO.setUpdater(loginUserName);
|
||||
orderDO.setCreateTime(now);
|
||||
orderDO.setUpdateTime(now);
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义单号校验
|
||||
*
|
||||
* @param key
|
||||
* @param val
|
||||
*/
|
||||
private void validCustomOrderNo(String key, String val) {
|
||||
if (StringUtils.isNotEmpty(val) && orderService.customOrderNoIsExists(val)) {
|
||||
throw ServiceExceptionUtil.exception(ORDER_IMPORT_ORDER_CUSTOMERNO_EXISTS, key, val);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验空
|
||||
*
|
||||
* @param key
|
||||
* @param val
|
||||
*/
|
||||
private void validOrderInfoEmpty(String key, String val) {
|
||||
if (StringUtils.isEmpty(val)) {
|
||||
throw ServiceExceptionUtil.exception(ORDER_IMPORT_ORDER_FIELD_EMPTY, key);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验长度
|
||||
*
|
||||
* @param key
|
||||
* @param val
|
||||
* @param length
|
||||
*/
|
||||
private void validOrderInfoLength(String key, String val, int length) {
|
||||
if (StringUtils.isNotEmpty(val) && length < val.length()) {
|
||||
throw ServiceExceptionUtil.exception(ORDER_IMPORT_ORDER_FIELD_LENGTH_ERROR, key, length);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验手机号格式
|
||||
*
|
||||
* @param key
|
||||
* @param val
|
||||
*/
|
||||
private void validOrderInfoPhone(String key, String val) {
|
||||
if (StringUtils.isNotEmpty(val) && Boolean.FALSE.equals(ToolUtil.validatePhoneNumber(val))) {
|
||||
throw ServiceExceptionUtil.exception(ORDER_IMPORT_ORDER_FIELD_MOBILE_FORMAT_ERROR, key);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验时间格式
|
||||
*
|
||||
* @param key
|
||||
* @param val
|
||||
*/
|
||||
private LocalDate validOrderInfoDate(String key, String val) {
|
||||
try {
|
||||
return LocalDateTimeUtil.parseDate(val, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
||||
} catch (Exception e) {
|
||||
throw ServiceExceptionUtil.exception(ORDER_IMPORT_ORDER_FIELD_DATE_FORMAT_ERROR, key);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* excel解析成importvo
|
||||
*
|
||||
* @param data
|
||||
*/
|
||||
private OrderPlateImportExcelVO setOrderPlateProperty(Map<Integer, String> data) {
|
||||
OrderPlateImportExcelVO vo = new OrderPlateImportExcelVO();
|
||||
for (Map.Entry<Integer, String> entry : data.entrySet()) {
|
||||
Integer index = entry.getKey();
|
||||
String value = entry.getValue();
|
||||
switch (index) {
|
||||
case 0:
|
||||
vo.setOrdinal(value);
|
||||
break;
|
||||
case 1:// 类型
|
||||
vo.setGoodType(value);
|
||||
break;
|
||||
case 2:// 物料编码
|
||||
vo.setGoodsId(value);
|
||||
break;
|
||||
case 3:// 商品名称
|
||||
vo.setGoodsName(value);
|
||||
break;
|
||||
case 4:// 材质
|
||||
vo.setMaterial(value);
|
||||
break;
|
||||
case 5:// 纹理
|
||||
vo.setWave(value);
|
||||
break;
|
||||
case 6:// 颜色
|
||||
vo.setColor(value);
|
||||
break;
|
||||
case 7:// 复合部件
|
||||
vo.setIsComposite(value);
|
||||
break;
|
||||
case 8:// 配件类型
|
||||
vo.setCategory(value);
|
||||
break;
|
||||
case 9:// 子类
|
||||
vo.setType(value);
|
||||
break;
|
||||
case 10:// 厂家
|
||||
vo.setFactory(value);
|
||||
break;
|
||||
case 11:// 品牌
|
||||
vo.setBrand(value);
|
||||
break;
|
||||
case 12:// 型号
|
||||
vo.setModel(value);
|
||||
break;
|
||||
case 13:// 板材/配件长
|
||||
vo.setGoodsHeight(value);
|
||||
break;
|
||||
case 14:// 板材/配件宽
|
||||
vo.setGoodsWidth(value);
|
||||
break;
|
||||
case 15:// 板材/配件厚
|
||||
vo.setGoodsThickness(value);
|
||||
break;
|
||||
case 16:// 规格
|
||||
vo.setSpec(value);
|
||||
break;
|
||||
case 17:// 单位
|
||||
vo.setUnit(value);
|
||||
break;
|
||||
case 18:// 数量
|
||||
vo.setGoodsNumber(value);
|
||||
break;
|
||||
case 19:// 房间
|
||||
vo.setRoomsName(value);
|
||||
break;
|
||||
case 20:// 柜体
|
||||
vo.setCabinetsName(value);
|
||||
break;
|
||||
case 21:// 加工组类型
|
||||
vo.setSynthesisTypeName(value);
|
||||
break;
|
||||
case 22:// 加工组名称
|
||||
vo.setCombinationName(value);
|
||||
break;
|
||||
case 23://板名称
|
||||
vo.setName(value);
|
||||
break;
|
||||
case 24:// 自定义板编号
|
||||
vo.setPlateNo(value);
|
||||
break;
|
||||
case 25:// 成品长
|
||||
vo.setHeight(value);
|
||||
break;
|
||||
case 26:// 成品宽
|
||||
vo.setWidth(value);
|
||||
break;
|
||||
case 27:// 拆单长
|
||||
vo.setSplitHeight(value);
|
||||
break;
|
||||
case 28:// 拆单宽
|
||||
vo.setSplitWidth(value);
|
||||
break;
|
||||
case 29:// 厚
|
||||
vo.setThickness(value);
|
||||
break;
|
||||
case 30:// 左封边
|
||||
vo.setSealLeft(value);
|
||||
break;
|
||||
case 31:// 右封边
|
||||
vo.setSealRight(value);
|
||||
break;
|
||||
case 32:// 上封边
|
||||
vo.setSealUp(value);
|
||||
break;
|
||||
case 33:// 下封边
|
||||
vo.setSealDown(value);
|
||||
break;
|
||||
case 34:// 排版面
|
||||
vo.setTypographicFace(value);
|
||||
break;
|
||||
case 35:// 纹路
|
||||
vo.setTexture(value);
|
||||
break;
|
||||
case 36:// 开门方向
|
||||
vo.setOpenDoorType(value);
|
||||
break;
|
||||
case 37://备注1
|
||||
vo.setRemark1(value);
|
||||
break;
|
||||
case 38://备注2
|
||||
vo.setRemark2(value);
|
||||
break;
|
||||
case 39://备注3
|
||||
vo.setRemark3(value);
|
||||
break;
|
||||
case 40://备注4
|
||||
vo.setRemark4(value);
|
||||
break;
|
||||
case 41://备注5
|
||||
vo.setRemark5(value);
|
||||
break;
|
||||
case 42://备注6
|
||||
vo.setRemark6(value);
|
||||
break;
|
||||
case 43://备注7
|
||||
vo.setRemark7(value);
|
||||
break;
|
||||
case 44://备注8
|
||||
vo.setRemark8(value);
|
||||
break;
|
||||
case 45://备注9
|
||||
vo.setRemark9(value);
|
||||
break;
|
||||
case 46://备注10
|
||||
vo.setRemark10(value);
|
||||
break;
|
||||
default:
|
||||
// 处理默认情况,可以选择忽略或者做其他处理
|
||||
break;
|
||||
}
|
||||
}
|
||||
return vo;
|
||||
}
|
||||
|
||||
private OrderImportTempDataDO checkData(OrderPlateImportExcelVO vo) {
|
||||
// 全部需要值的字段
|
||||
// 检查非空 类型、数量
|
||||
isEmpty(vo.getGoodType(), "类型", 32);
|
||||
isEmpty(vo.getGoodsNumber(), "数量", 10000000);
|
||||
|
||||
// 检查商品物料编码或是商品名称、规格、材质、颜色不可全为空
|
||||
if (StringUtils.isEmpty(vo.getGoodsName()) || StringUtils.isEmpty(vo.getSpec())
|
||||
|| StringUtils.isEmpty(vo.getMaterial()) || StringUtils.isEmpty(vo.getColor()) || StringUtils.isEmpty(vo.getUnit())) {
|
||||
throw new ServiceException(10000, "商品商品名称、规格、材质、颜色、单位不可为空");
|
||||
}
|
||||
|
||||
|
||||
if (StringUtils.equals(vo.getGoodType(), "配件")) {
|
||||
// 复合部件必填
|
||||
isNotEmptyAndBack(vo.getIsComposite(), QuarrelEnum.class, "是否复合部件", 1); // 判断传入的值,是否符合字典中的枚举类
|
||||
// 配件类型必填
|
||||
isNotEmptyAndBack(vo.getCategory(), CategoryEnum.class, "配件类型", 32);
|
||||
// 配件长宽厚,存在判断是否可以转义
|
||||
isEmptyAndPositiveNumberSize(vo.getGoodsWidth(), Double.class, 5, 3, "配件宽");
|
||||
isEmptyAndPositiveNumberSize(vo.getGoodsHeight(), Double.class, 5, 3, "配件高");
|
||||
isEmptyAndPositiveNumberSize(vo.getGoodsThickness(), Double.class, 5, 3, "配件厚");
|
||||
// 配件类型为封边条的时候,需要填写配件宽厚
|
||||
if (StringUtils.equals(vo.getCategory(), CategoryEnum.EDGING.getValue())) { // 封边条必须有宽高
|
||||
isNotEmptyAndBack(vo.getGoodsWidth(), "封边条宽");
|
||||
isNotEmptyAndBack(vo.getGoodsThickness(), "封边条厚");
|
||||
}
|
||||
// 配件数量判断
|
||||
isEmptyAndPositiveNumber(vo.getGoodsNumber(), Double.class, "配件数量");
|
||||
}
|
||||
// 若商品类型为板材,需检查房间、柜体、板名称、成品长、成品宽、拆单长、拆单宽、厚、左封边、右封边、上封边、下封边、排版面、纹路、开门方向不能为空
|
||||
boolean isPlate = StringUtils.equals(vo.getGoodType(), "板材");
|
||||
if (isPlate) {
|
||||
checkPlate(vo);
|
||||
}
|
||||
|
||||
// 校验通过生成临时表实体
|
||||
OrderImportTempDataDO orderImportTempDataDO = OrderImportTempDataDO.builder()
|
||||
.id((Long) snowFlakeGenerator.nextId(null))
|
||||
.taskId(taskId)
|
||||
.orderId(orderId)
|
||||
.type(isPlate ? OrderImportTmpDataTypeEnum.PLATE.getType() : OrderImportTmpDataTypeEnum.PART.getType())
|
||||
.outerGoodsId(StringUtils.isNotEmpty(vo.getGoodsId()) ? vo.getGoodsId() : OrderImportConstants.DEFAULT_GOODS_ID)
|
||||
.goodsName(vo.getGoodsName())
|
||||
.material(vo.getMaterial())
|
||||
.color(vo.getColor())
|
||||
.wave(StringUtils.equals("有", vo.getWave()) ? "true" : "false")
|
||||
.width(vo.getGoodsWidth())
|
||||
.height(vo.getGoodsHeight())
|
||||
.thickness(vo.getGoodsThickness())
|
||||
.brand(vo.getBrand())
|
||||
.isComposite(vo.getIsComposite())
|
||||
.category(vo.getCategory())
|
||||
.subType(vo.getType())
|
||||
.factory(vo.getFactory())
|
||||
.spec(vo.getSpec())
|
||||
.model(vo.getModel())
|
||||
.unit(vo.getUnit())
|
||||
.roomName(StringUtils.isNotEmpty(vo.getRoomsName()) ? vo.getRoomsName() : OrderImportConstants.NOT_ASSIGNED)
|
||||
.bodyName(StringUtils.isNotEmpty(vo.getCabinetsName()) ? vo.getCabinetsName() : OrderImportConstants.NOT_ASSIGNED)
|
||||
.groupTypeName(vo.getSynthesisTypeName())
|
||||
.groupName(vo.getCombinationName())
|
||||
.detail(JsonUtils.zipString(JSON.toJSONString(vo)))
|
||||
.num(Double.parseDouble(vo.getGoodsNumber()))
|
||||
.createTime(LocalDateTime.now())
|
||||
.sort(sort++)
|
||||
.build();
|
||||
return orderImportTempDataDO;
|
||||
}
|
||||
|
||||
// 板材的数据以及长度的检验
|
||||
public void checkPlate(OrderPlateImportExcelVO vo) {
|
||||
// 数量类型判断
|
||||
isEmptyAndPositiveNumber(vo.getGoodsNumber(), Integer.class, "板材数量");
|
||||
// 板材纹理
|
||||
isNotEmptyAndBack(vo.getWave(), IsHavaeEnum.class, "板材纹理", 4);
|
||||
// 大板的长宽厚存在以及是否符合数个
|
||||
isNotEmptyAndBack(vo.getGoodsWidth(), "板材长度");
|
||||
isEmptyAndPositiveNumberSize(vo.getGoodsWidth(), Double.class, 5, 3, "板材长度");
|
||||
isNotEmptyAndBack(vo.getGoodsHeight(), "板材宽度");
|
||||
isEmptyAndPositiveNumberSize(vo.getGoodsHeight(), Double.class, 5, 3, "板材宽度");
|
||||
isNotEmptyAndBack(vo.getGoodsThickness(), "板材厚度");
|
||||
isEmptyAndPositiveNumberSize(vo.getGoodsThickness(), Double.class, 5, 3, "板材厚度");
|
||||
// 房间、柜体、板名称 不可以为空
|
||||
isEmpty(vo.getRoomsName(), "房间名称", 64);
|
||||
isEmpty(vo.getCabinetsName(), "柜体名称", 64);
|
||||
isEmpty(vo.getName(), "板材名称", 64);
|
||||
//成品长、成品宽、拆单长、拆单宽、厚、左封边、右封边、上封边、下封边 不能为空
|
||||
isNotEmptyAndBack(vo.getHeight(), "成品长度");
|
||||
isEmptyAndPositiveNumberSize(vo.getHeight(), Double.class, 5, 3, "成品长度");
|
||||
isNotEmptyAndBack(vo.getWidth(), "成品宽度");
|
||||
isEmptyAndPositiveNumberSize(vo.getWidth(), Double.class, 5, 3, "成品宽度");
|
||||
isNotEmptyAndBack(vo.getSplitHeight(), "拆单长度");
|
||||
isEmptyAndPositiveNumberSize(vo.getSplitHeight(), Double.class, 5, 3, "拆单长度");
|
||||
isNotEmptyAndBack(vo.getSplitWidth(), "拆单宽度");
|
||||
isEmptyAndPositiveNumberSize(vo.getSplitWidth(), Double.class, 5, 3, "拆单宽度");
|
||||
isNotEmptyAndBack(vo.getThickness(), "厚度");
|
||||
isEmptyAndPositiveNumberSize(vo.getThickness(), Double.class, 5, 3, "厚度");
|
||||
isNotEmptyAndBack(vo.getSealLeft(), "左封边");
|
||||
isEmptyAndPositiveNumberSize(vo.getSealLeft(), Double.class, 5, 3, "左封边");
|
||||
isNotEmptyAndBack(vo.getSealRight(), "右封边");
|
||||
isEmptyAndPositiveNumberSize(vo.getSealRight(), Double.class, 5, 3, "右封边");
|
||||
isNotEmptyAndBack(vo.getSealUp(), "上封边");
|
||||
isEmptyAndPositiveNumberSize(vo.getSealUp(), Double.class, 5, 3, "上封边");
|
||||
isNotEmptyAndBack(vo.getSealDown(), "下封边");
|
||||
isEmptyAndPositiveNumberSize(vo.getSealDown(), Double.class, 5, 3, "下封边");
|
||||
// 排版面、纹路、开门方向
|
||||
isNotEmptyAndDict(vo.getTypographicFace(), DictTypeConstants.TYPOGRAPHY_TYPE, "排版面");
|
||||
isNotEmptyAndDict(vo.getTexture(), DictTypeConstants.GRAIN_TYPE, "纹路");
|
||||
isNotEmptyAndDict(vo.getOpenDoorType(), DictTypeConstants.DOOR_OPENING_DIRECTIONS, "开门方向");
|
||||
|
||||
}
|
||||
|
||||
// 判断非空,字典值判断
|
||||
public void isNotEmptyAndDict(String value, String dictType, String errValue) {
|
||||
if (StringUtils.isEmpty(value)) {
|
||||
throw ServiceExceptionUtil.exception(ORDER_IMPORT_DETAIL_VALID_ERROR, errValue + NOT_EMPTY);
|
||||
} else {
|
||||
DictDataRespDTO dictDataRespDTO = dictDataApi.parseDictData(dictType, value).getData();
|
||||
if (dictDataRespDTO == null) {
|
||||
throw ServiceExceptionUtil.exception(ORDER_IMPORT_DETAIL_VALID_ERROR, errValue + ACCORD_ENUM);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 非空判断,错误填入
|
||||
private void isEmpty(String value, String errValue, int length) {
|
||||
if (StringUtils.isEmpty(value)) {
|
||||
throw ServiceExceptionUtil.exception(ORDER_IMPORT_DETAIL_VALID_ERROR, errValue + NOT_EMPTY);
|
||||
} else {
|
||||
// 字符串长度检查
|
||||
int size = value.length();
|
||||
if (size > length) {
|
||||
throw ServiceExceptionUtil.exception(ORDER_IMPORT_DETAIL_VALID_ERROR, errValue + NUMBER_LENGTH_ERR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 错误判断通用方法
|
||||
// 判断非零,错误返回;不为空时,判断是否符合枚举类
|
||||
private void isNotEmptyAndBack(String value, Class<? extends Enum<?>> enumClass, String errValue, int length) {
|
||||
if (StringUtils.isEmpty(value)) {
|
||||
throw ServiceExceptionUtil.exception(ORDER_IMPORT_DETAIL_VALID_ERROR, errValue + NOT_EMPTY);
|
||||
} else {
|
||||
isEmptyAndSize(value, length, errValue);
|
||||
try {
|
||||
// 获取枚举类的所有值
|
||||
Enum<?>[] enums = enumClass.getEnumConstants();
|
||||
boolean isValid = false;
|
||||
for (Enum<?> enumValue : enums) {
|
||||
Field valueField = enumValue.getClass().getDeclaredField("value");
|
||||
valueField.setAccessible(true);
|
||||
String enumValueStr = (String) valueField.get(enumValue);
|
||||
if (enumValueStr.equals(value)) {
|
||||
isValid = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!isValid) {
|
||||
throw ServiceExceptionUtil.exception(ORDER_IMPORT_DETAIL_VALID_ERROR, errValue + ACCORD_ENUM);
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw ServiceExceptionUtil.exception(ORDER_IMPORT_DETAIL_VALID_ERROR, errValue + ACCORD_ENUM);
|
||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 非零判断,有值判断---判断数值类型,数值长度
|
||||
private void isEmptyAndPositiveNumberSize(String value, Class<?> targetType, Integer length, Integer decimalLength, String errValue) {
|
||||
if (StringUtils.isNotEmpty(value)) {
|
||||
if (Boolean.TRUE.equals(ToolUtil.convertToType(value, targetType))) {
|
||||
if (Boolean.TRUE.equals(ToolUtil.checkNumber(value))) {
|
||||
if (!ToolUtil.checkPrecision(value, length, decimalLength)) {
|
||||
throw ServiceExceptionUtil.exception(ORDER_IMPORT_DETAIL_VALID_ERROR, errValue + NUMBER_LENGTH_ERR);
|
||||
}
|
||||
} else {
|
||||
throw ServiceExceptionUtil.exception(ORDER_IMPORT_DETAIL_VALID_ERROR, errValue + POSITIVE_ERR);
|
||||
}
|
||||
} else {
|
||||
throw ServiceExceptionUtil.exception(ORDER_IMPORT_DETAIL_VALID_ERROR, errValue + NUMBER_TYPE_ERR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 判断非零,错误返回
|
||||
private void isNotEmptyAndBack(String value, String errValue) {
|
||||
if (StringUtils.isEmpty(value)) {
|
||||
throw ServiceExceptionUtil.exception(ORDER_IMPORT_DETAIL_VALID_ERROR, errValue + NOT_EMPTY);
|
||||
}
|
||||
}
|
||||
|
||||
// 判断非空,有值判断字符串的长度
|
||||
private void isEmptyAndSize(String value, Integer length, String errValue) {
|
||||
if (StringUtils.isNotEmpty(value)) {
|
||||
int size = value.length();
|
||||
if (size > length) {
|
||||
throw ServiceExceptionUtil.exception(ORDER_IMPORT_DETAIL_VALID_ERROR, errValue + NUMBER_LENGTH_ERR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 判断非空,大于零判断
|
||||
public void isEmptyAndPositiveNumber(String value, Class<?> targetType, String errValue) {
|
||||
if (StringUtils.isNotEmpty(value)) {
|
||||
if (Boolean.FALSE.equals(ToolUtil.convertToType(value, targetType))) {
|
||||
throw ServiceExceptionUtil.exception(ORDER_IMPORT_DETAIL_VALID_ERROR, errValue + NUMBER_TYPE_ERR);
|
||||
} else {
|
||||
if (Boolean.FALSE.equals(checkNumber(value))) {
|
||||
throw ServiceExceptionUtil.exception(ORDER_IMPORT_DETAIL_VALID_ERROR, errValue + "数量不能为0");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 数值正负判断
|
||||
public static Boolean checkNumber(String numberStr) {
|
||||
try {
|
||||
double number = Double.parseDouble(numberStr);
|
||||
// 进行正负判断
|
||||
if (number >= 0) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-5
@@ -2,6 +2,7 @@ package com.cf.imes.module.executor.util.fileConversion.admin.files.excel;
|
||||
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.alibaba.nacos.common.utils.StringUtils;
|
||||
import com.cf.imes.framework.id.core.util.SnowflakeIdWorker3rd;
|
||||
import com.cf.imes.framework.mybatis.core.generator.SnowFlakeGenerator;
|
||||
import com.cf.imes.framework.organ.core.context.OrganContextHolder;
|
||||
import com.cf.imes.module.executor.controller.admin.orderParts.vo.OrderPartsRemark;
|
||||
@@ -9,17 +10,12 @@ import com.cf.imes.module.executor.dal.dataobject.goods.GoodsDO;
|
||||
import com.cf.imes.module.executor.dal.dataobject.orderBody.OrderBodyDO;
|
||||
import com.cf.imes.module.executor.dal.dataobject.orderGroup.OrderGroupDO;
|
||||
import com.cf.imes.module.executor.dal.dataobject.orderItem.OrderItemDO;
|
||||
import com.cf.imes.module.executor.dal.dataobject.orderModuleExtra.OrderModuleExtraDO;
|
||||
import com.cf.imes.module.executor.dal.dataobject.orderParts.OrderPartsDO;
|
||||
import com.cf.imes.module.executor.dal.dataobject.ordermodel.OrderModelDO;
|
||||
import com.cf.imes.module.executor.dal.dataobject.plate.PlateDO;
|
||||
import com.cf.imes.module.executor.dal.dataobject.plate.PlateGoodDO;
|
||||
import com.cf.imes.module.executor.dal.dataobject.rawgoods.RawGoodsDO;
|
||||
import com.cf.imes.module.executor.enums.OrderItemTypeEnum;
|
||||
import com.cf.imes.module.executor.service.customplateno.CustomPlateNoGenerateService;
|
||||
import com.cf.imes.module.executor.util.deviseData.structure.FieldConstants;
|
||||
import com.cf.imes.module.executor.util.deviseData.structure.PlateDetail;
|
||||
import com.cf.imes.module.executor.util.fileConversion.admin.SnowflakeIdWorker3rd;
|
||||
import com.cf.imes.module.system.api.dict.DictDataApi;
|
||||
import com.cf.imes.module.system.api.dict.dto.DictDataRespDTO;
|
||||
import com.cf.imes.module.executor.enums.DictTypeConstants;
|
||||
|
||||
+1
-1
@@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.nacos.common.utils.StringUtils;
|
||||
import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
|
||||
import com.cf.imes.framework.id.core.util.SnowflakeIdWorker3rd;
|
||||
import com.cf.imes.framework.mybatis.core.generator.SnowFlakeGenerator;
|
||||
import com.cf.imes.module.executor.controller.admin.orderParts.vo.OrderPartsRemark;
|
||||
import com.cf.imes.module.executor.controller.admin.plan.dto.Point;
|
||||
@@ -17,7 +18,6 @@ import com.cf.imes.module.executor.dal.dataobject.orderParts.OrderPartsDO;
|
||||
import com.cf.imes.module.executor.dal.dataobject.plate.PlateDO;
|
||||
import com.cf.imes.module.executor.dal.dataobject.rawgoods.RawGoodsDO;
|
||||
import com.cf.imes.module.executor.util.deviseData.structure.*;
|
||||
import com.cf.imes.module.executor.util.fileConversion.admin.SnowflakeIdWorker3rd;
|
||||
import com.cf.imes.module.executor.util.fileConversion.admin.files.xml.VO.*;
|
||||
import com.cf.imes.module.system.api.dict.DictDataApi;
|
||||
import com.cf.imes.module.system.api.dict.dto.DictDataRespDTO;
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
<?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="com.cf.imes.module.executor.dal.mysql.orderImport.OrderImportTempDataMapper">
|
||||
<!-- <insert id="insertBatch" parameterType="java.util.List">-->
|
||||
<!-- INSERT INTO order_import_temp_data-->
|
||||
<!-- (id, organ_id, task_id, order_id, type, material, color, texture, width, length,thickness, brand,-->
|
||||
<!-- is_composite, category, sub_type, factory, spec, model, unit,creater, detail, create_time)-->
|
||||
<!-- VALUES-->
|
||||
<!-- <foreach collection="list" item="item" separator=",">-->
|
||||
<!-- (#{item.id}, #{item.organId}, #{item.taskId}, #{item.orderId}, #{item.type},#{item.material}, #{item.color}, #{item.texture}, #{item.width}, #{item.length},#{item.thickness}, #{item.brand},-->
|
||||
<!-- #{item.isComposite}, #{item.category},#{item.subType}, #{item.factory}, #{item.spec}, #{item.model}, #{item.unit},#{item.creater}, #{item.detail}, #{item.createTime})-->
|
||||
<!-- </foreach>-->
|
||||
<!-- </insert>-->
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user