生产单excel/xml异步导入提前计算板件数量/面积逻辑补充

This commit is contained in:
gaoqr
2025-10-31 17:04:34 +08:00
parent ad1f5ea45c
commit f66a96a468
17 changed files with 330 additions and 138 deletions
@@ -70,4 +70,9 @@ public class OrderImportTaskDO extends BaseDO {
* 导入文件名称
*/
private String fileName;
/**
* 重试次数
*/
private int retryCount;
}
@@ -12,6 +12,7 @@ import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import java.math.BigDecimal;
import java.time.LocalDateTime;
/**
@@ -209,6 +210,11 @@ public class OrderImportTempDataDO {
*/
private Double num;
/**
* 面积
*/
private BigDecimal area;
@TableField(exist = false)
private int plateNum;
@@ -131,4 +131,14 @@ public class OrderImportTempDataGoodsGroupDO implements Serializable {
* 统计总数
*/
private int count;
/**
* 板材板件数量
*/
private int goodsPlateNum;
/**
* 板材板件面积
*/
private Double goodsPlateArea;
}
@@ -233,11 +233,13 @@ public class PlateDO extends BaseDO {
/**
* 是否二维刀路
*/
@TableField(value = "is_2v")
private Boolean is2v;
/**
* 是否侧面二维刀路
*/
@TableField(value = "is_side_2v")
private Boolean isSide2v;
/**
* 是否造型
@@ -1,5 +1,7 @@
package com.cf.imes.module.plan.service.orderImport;
import com.cf.imes.module.plan.dal.dataobject.orderImport.OrderImportTaskDO;
/**
* @author Gqr
* @since 2025/5/13 16:41
@@ -21,4 +23,12 @@ public interface OrderImportTaskService {
* @param organId
*/
void updateExceptionTaskStatus(Long taskId, Long organId);
/**
* 确认导入任务,更新任务状态
*
* @param taskId
* @return
*/
OrderImportTaskDO confirmOrderImport(Long taskId);
}
@@ -1,10 +1,12 @@
package com.cf.imes.module.plan.service.orderImport;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.cf.imes.module.executor.enums.OrderImportStatusEnum;
import com.cf.imes.module.executor.enums.OrderImportTaskStatusEnum;
import com.cf.imes.module.plan.dal.dataobject.orderImport.OrderImportTaskDO;
import com.cf.imes.module.plan.dal.mysql.orderImport.OrderImportTaskMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
@@ -18,6 +20,7 @@ import static com.cf.imes.module.plan.enums.ErrorCodeConstants.ORDER_IMPORT_FAIL
* @since 2025/5/13 16:41
*/
@Service
@Slf4j
public class OrderImportTaskServiceImpl implements OrderImportTaskService {
@Resource
private OrderImportTaskMapper orderImportTaskMapper;
@@ -41,4 +44,27 @@ public class OrderImportTaskServiceImpl implements OrderImportTaskService {
.set(OrderImportTaskDO::getOrganId, organId)
.set(OrderImportTaskDO::getResult, ORDER_IMPORT_FAIL.getMsg()));
}
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public OrderImportTaskDO confirmOrderImport(Long taskId) {
OrderImportTaskDO orderImportTaskDO = orderImportTaskMapper.selectById(taskId);
if (ObjectUtil.isNotNull(orderImportTaskDO)) {
// 更新状态为消创建接收成功
orderImportTaskMapper.update(new LambdaUpdateWrapper<OrderImportTaskDO>().eq(OrderImportTaskDO::getId, taskId).set(OrderImportTaskDO::getStatus, OrderImportTaskStatusEnum.CREATE_RECEIVE.getStatus()));
} else {
String taskNotExistNotify = String.format("%s不存在的导入任务,消费中止", taskId);
// 更新状态为消费成功,导入失败
orderImportTaskMapper.update(
new LambdaUpdateWrapper<OrderImportTaskDO>()
.eq(OrderImportTaskDO::getId, taskId)
.set(OrderImportTaskDO::getStatus, OrderImportTaskStatusEnum.CREATE_RECEIVE.getStatus())
.set(OrderImportTaskDO::getImportStatus, OrderImportStatusEnum.IMPORT_FAIL.getStatus())
.set(OrderImportTaskDO::getResult, taskNotExistNotify)
.set(OrderImportTaskDO::getRetryCount, orderImportTaskDO.getRetryCount() + 1)
);
log.error(String.format("====================【%s】====================", taskNotExistNotify));
}
return orderImportTaskDO;
}
}
@@ -6,14 +6,16 @@ import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.cf.imes.framework.common.enums.OrderPackageStatusEnum;
import com.cf.imes.framework.common.exception.util.ServiceExceptionUtil;
import com.cf.imes.framework.common.exception.ServiceException;
import com.cf.imes.framework.common.util.json.JsonUtils;
import com.cf.imes.framework.id.core.util.SnowflakeIdWorker3rd;
import com.cf.imes.framework.redis.config.ChenfengCacheProperties;
import com.cf.imes.module.executor.enums.OrderStatusEnum;
import com.cf.imes.module.plan.dal.mysql.orderParts.PartsMapper;
import com.cf.imes.module.plan.dal.mysql.plate.PlateGoodMapper;
import com.cf.imes.module.plan.service.customplateno.CustomPlateNoGenerateService;
import com.cf.imes.module.plan.service.order.OrderInputProcessor;
import com.cf.imes.module.plan.service.orderImport.OrderImportTaskService;
import com.cf.imes.module.plan.service.orderImport.factory.DefaultExcelOrderImportFactory;
import com.cf.imes.framework.mq.rabbitmq.constant.RabbitMqConstants;
import com.cf.imes.framework.mybatis.core.generator.SnowFlakeGenerator;
@@ -46,11 +48,14 @@ import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import jakarta.annotation.Resource;
import java.time.LocalDate;
import java.util.Objects;
import java.util.Optional;
import static com.cf.imes.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.cf.imes.module.executor.enums.ErrorCodeConstants.ORDER_IMPORT_ORDER_NOT_EXISTS;
import static com.cf.imes.module.executor.enums.ErrorCodeConstants.ORDER_IMPORT_ORGAN_LOCK_ERROR;
import static com.cf.imes.module.plan.enums.ErrorCodeConstants.ORDER_IMPORT_FAIL;
import static com.cf.imes.module.plan.enums.ErrorCodeConstants.ORDER_IMPORT_ORGANID_NOT_EXISTS;
@@ -63,6 +68,8 @@ import static com.cf.imes.module.plan.enums.ErrorCodeConstants.ORDER_IMPORT_ORGA
@Component
@Slf4j
public class DefaultExcelOrderImportConsumer {
@Resource
private OrderImportTaskService orderImportTaskService;
@Resource
private OrderImportTaskMapper orderImportTaskMapper;
@@ -118,6 +125,9 @@ public class DefaultExcelOrderImportConsumer {
@Resource
private CustomPlateNoGenerateService customPlateNoGenerateService;
@Resource
private ChenfengCacheProperties chenfengCacheProperties;
@RabbitListener(queues = RabbitMqConstants.ORDER_IMPORT_DEFAULT_EXCEL_QUEUE)
@DS("imes_prod")
@Transactional(rollbackFor = Exception.class)
@@ -125,13 +135,27 @@ public class DefaultExcelOrderImportConsumer {
log.info("====================【生产单默认excel导入收到消息:{}】====================", message);
Long organId = null;
Long taskId = Long.parseLong(message);
boolean lockResult = true;
OrderImportTaskDO orderImportTaskDO = null;
try {
// 手动确认消息接收
channel.basicAck(deliveryTag, false);
organId = OrganContextHolder.getOrganId();
if (ObjectUtil.isNull(organId)) {
throw ServiceExceptionUtil.exception(ORDER_IMPORT_ORGANID_NOT_EXISTS);
throw exception(ORDER_IMPORT_ORGANID_NOT_EXISTS);
}
// 检查机构导入锁
String importLockKey = String.format(RedisKeyConstants.ORDER_IMPORT_LOCK_KEY, organId);
lockResult = redisLockUtil.acquireLock(importLockKey, String.valueOf(taskId), chenfengCacheProperties.getLockTimeout());
if (!lockResult) {
throw exception(ORDER_IMPORT_ORGAN_LOCK_ERROR);
}
// 确认任务,更新状态为消费成功,没有找到任务中断后续消费
OrderImportTaskDO orderImportTaskDO = confirmOrderImport(taskId);
orderImportTaskDO = orderImportTaskService.confirmOrderImport(taskId);
if (ObjectUtil.isNull(orderImportTaskDO)) {
return;
}
@@ -140,62 +164,47 @@ public class DefaultExcelOrderImportConsumer {
// 创建工厂
log.info("====================【生产单默认excel导入处理临时数据开始】====================");
DefaultExcelOrderImportFactory defaultExcelOrderImportFactory = new DefaultExcelOrderImportFactory(taskId, orderDO, organId, orderImportTaskDO.getCreator(),
snowFlakeGenerator, idWorker, orderImportTaskMapper, orderImportTempDataMapper, dictDataApi, goodsMapper, rawGoodsMapper, orderPartsMapper,
snowFlakeGenerator, idWorker, orderImportTaskMapper, orderImportTempDataMapper, dictDataApi, orderMapper, goodsMapper, rawGoodsMapper, orderPartsMapper,
orderBodyMapper, orderGroupMapper, plateMapper, orderItemMapper, plateGoodMapper, orderInputProcessor, partsMapper, customPlateNoGenerateService);
// 解析临时表数据
defaultExcelOrderImportFactory.analyzeTempData();
log.info("====================【生产单默认excel导入处理临时数据结束】====================");
} catch (Exception e) {
// 确认消息进入死信队列
channel.basicNack(deliveryTag, false, false);
log.error(ORDER_IMPORT_FAIL.getMsg(), e);
updateImportTaskFail(orderImportTaskDO, e);
throw e;
} finally {
// 手动确认消息接收
channel.basicAck(deliveryTag, false);
// 导入锁解锁
redisLockUtil.releaseLock(String.format(RedisKeyConstants.ORDER_IMPORT_LOCK_KEY, organId), message);
if (lockResult) {
// 导入锁解锁
redisLockUtil.releaseLock(String.format(RedisKeyConstants.ORDER_IMPORT_LOCK_KEY, organId), message);
}
}
}
/**
* 确认导入任务,更新任务状态
* 更新导入任务为失败
*
* @param taskId
* @param orderImportTaskDO
* @param ex
*/
private OrderImportTaskDO confirmOrderImport(Long taskId) {
boolean taskExist = false;
OrderImportTaskDO orderImportTaskDO = null;
// 线程每1s查询一次,查三次没有就提示任务不存在
for (int i = 0; i < 3; i++) {
orderImportTaskDO = orderImportTaskMapper.selectById(taskId);
if (ObjectUtil.isNotNull(orderImportTaskDO)) {
taskExist = true;
break;
} else {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
log.error("====================【线程中断异常】====================");
}
}
public void updateImportTaskFail(OrderImportTaskDO orderImportTaskDO, Exception ex) {
if (orderImportTaskDO == null) {
return;
}
if (taskExist) {
// 更新状态为消费成功
orderImportTaskMapper.update(new LambdaUpdateWrapper<OrderImportTaskDO>().eq(OrderImportTaskDO::getId, taskId).set(OrderImportTaskDO::getStatus, OrderImportTaskStatusEnum.CONSUME_SUCCESS.getStatus()));
String msg;
if (ex instanceof ServiceException) {
msg = ex.getMessage();
} else {
String taskNotExistNotify = String.format("%s不存在的导入任务,消费中止", taskId);
// 更新状态为消费成功,导入失败
orderImportTaskMapper.update(
new LambdaUpdateWrapper<OrderImportTaskDO>()
.eq(OrderImportTaskDO::getId, taskId)
.set(OrderImportTaskDO::getStatus, OrderImportTaskStatusEnum.CONSUME_SUCCESS.getStatus())
.set(OrderImportTaskDO::getImportStatus, OrderImportStatusEnum.IMPORT_FAIL.getStatus())
.set(OrderImportTaskDO::getResult, taskNotExistNotify)
);
log.error(String.format("====================【%s】====================", taskNotExistNotify));
msg = ORDER_IMPORT_FAIL.getMsg();
}
return orderImportTaskDO;
orderImportTaskMapper.update(
new LambdaUpdateWrapper<OrderImportTaskDO>()
.eq(OrderImportTaskDO::getId, orderImportTaskDO.getId())
.set(OrderImportTaskDO::getStatus, OrderImportTaskStatusEnum.CREATE_RECEIVE.getStatus())
.set(OrderImportTaskDO::getImportStatus, OrderImportStatusEnum.IMPORT_FAIL.getStatus())
.set(OrderImportTaskDO::getResult, msg)
.set(OrderImportTaskDO::getRetryCount, orderImportTaskDO.getRetryCount() + 1)
);
}
/**
@@ -216,7 +225,7 @@ public class DefaultExcelOrderImportConsumer {
Long existOrderId = orderImportTempDataDO.getOrderId();
// 校验生产单id
OrderDO orderDO = orderMapper.selectById(existOrderId);
Optional.ofNullable(orderDO).orElseThrow(() -> ServiceExceptionUtil.exception(ORDER_IMPORT_ORDER_NOT_EXISTS, existOrderId));
Optional.ofNullable(orderDO).orElseThrow(() -> exception(ORDER_IMPORT_ORDER_NOT_EXISTS, existOrderId));
// 更新补板生产单属性
updateOrder(orderDO);
return orderDO;
@@ -6,12 +6,14 @@ import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.cf.imes.framework.common.enums.OrderPackageStatusEnum;
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.id.core.util.SnowflakeIdWorker3rd;
import com.cf.imes.framework.mq.rabbitmq.constant.RabbitMqConstants;
import com.cf.imes.framework.mybatis.core.generator.SnowFlakeGenerator;
import com.cf.imes.framework.organ.core.context.OrganContextHolder;
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.enums.OrderImportStatusEnum;
@@ -35,6 +37,7 @@ import com.cf.imes.module.plan.dal.mysql.plate.PlateMapper;
import com.cf.imes.module.plan.dal.mysql.rawgoods.RawGoodsMapper;
import com.cf.imes.module.plan.service.customplateno.CustomPlateNoGenerateService;
import com.cf.imes.module.plan.service.order.OrderInputProcessor;
import com.cf.imes.module.plan.service.orderImport.OrderImportTaskService;
import com.cf.imes.module.plan.service.orderImport.factory.DefaultXmlOrderImportFactory;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
@@ -50,7 +53,9 @@ import java.time.LocalDate;
import java.util.Objects;
import java.util.Optional;
import static com.cf.imes.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.cf.imes.module.executor.enums.ErrorCodeConstants.ORDER_IMPORT_ORDER_NOT_EXISTS;
import static com.cf.imes.module.executor.enums.ErrorCodeConstants.ORDER_IMPORT_ORGAN_LOCK_ERROR;
import static com.cf.imes.module.plan.enums.ErrorCodeConstants.ORDER_IMPORT_FAIL;
import static com.cf.imes.module.plan.enums.ErrorCodeConstants.ORDER_IMPORT_ORGANID_NOT_EXISTS;
@@ -63,6 +68,9 @@ import static com.cf.imes.module.plan.enums.ErrorCodeConstants.ORDER_IMPORT_ORGA
@Component
@Slf4j
public class DefaultXmlOrderImportConsumer {
@Resource
private OrderImportTaskService orderImportTaskService;
@Resource
private OrderImportTaskMapper orderImportTaskMapper;
@@ -114,6 +122,9 @@ public class DefaultXmlOrderImportConsumer {
@Resource
private CustomPlateNoGenerateService customPlateNoGenerateService;
@Resource
private ChenfengCacheProperties chenfengCacheProperties;
@RabbitListener(queues = RabbitMqConstants.ORDER_IMPORT_DEFAULT_XML_QUEUE)
@DS("imes_prod")
@Transactional(rollbackFor = Exception.class)
@@ -121,13 +132,27 @@ public class DefaultXmlOrderImportConsumer {
log.info("====================【生产单默认xml导入收到消息:{}】====================", message);
Long organId = null;
Long taskId = Long.parseLong(message);
boolean lockResult = true;
OrderImportTaskDO orderImportTaskDO = null;
try {
// 手动确认消息接收
channel.basicAck(deliveryTag, false);
organId = OrganContextHolder.getOrganId();
if (ObjectUtil.isNull(organId)) {
throw ServiceExceptionUtil.exception(ORDER_IMPORT_ORGANID_NOT_EXISTS);
}
// 检查机构导入锁
String importLockKey = String.format(RedisKeyConstants.ORDER_IMPORT_LOCK_KEY, organId);
lockResult = redisLockUtil.acquireLock(importLockKey, String.valueOf(taskId), chenfengCacheProperties.getLockTimeout());
if (!lockResult) {
throw exception(ORDER_IMPORT_ORGAN_LOCK_ERROR);
}
// 确认任务,更新状态为消费成功,没有找到任务中断后续消费
OrderImportTaskDO orderImportTaskDO = confirmOrderImport(taskId);
orderImportTaskDO = orderImportTaskService.confirmOrderImport(taskId);
if (ObjectUtil.isNull(orderImportTaskDO)) {
return;
}
@@ -136,62 +161,47 @@ public class DefaultXmlOrderImportConsumer {
log.info("====================【生产单默认xml导入处理临时数据开始】====================");
// 创建工厂
DefaultXmlOrderImportFactory defaultExcelOrderImportFactory = new DefaultXmlOrderImportFactory(taskId, orderDO, organId, orderImportTaskDO.getCreator(),
snowFlakeGenerator, idWorker, orderImportTaskMapper, orderImportTempDataMapper, goodsMapper, rawGoodsMapper, orderPartsMapper,
snowFlakeGenerator, idWorker, orderImportTaskMapper, orderImportTempDataMapper, orderMapper, goodsMapper, rawGoodsMapper, orderPartsMapper,
orderBodyMapper, orderGroupMapper, plateMapper, orderItemMapper, plateGoodMapper, orderInputProcessor, partsMapper, customPlateNoGenerateService);
// 解析临时表数据
defaultExcelOrderImportFactory.analyzeTempData();
log.info("====================【生产单默认xml导入处理临时数据结束】====================");
} catch (Exception e) {
// 确认消息进入死信队列
channel.basicNack(deliveryTag, false, false);
log.error( ORDER_IMPORT_FAIL.getMsg(), e);
updateImportTaskFail(orderImportTaskDO, e);
throw e;
} finally {
// 手动确认消息接收
channel.basicAck(deliveryTag, false);
// 导入锁解锁
redisLockUtil.releaseLock(String.format(RedisKeyConstants.ORDER_IMPORT_LOCK_KEY, organId), message);
if (lockResult) {
// 导入锁解锁
redisLockUtil.releaseLock(String.format(RedisKeyConstants.ORDER_IMPORT_LOCK_KEY, organId), message);
}
}
}
/**
* 确认导入任务,更新任务状态
* 更新导入任务为失败
*
* @param taskId
* @param orderImportTaskDO
* @param ex
*/
private OrderImportTaskDO confirmOrderImport(Long taskId) {
boolean taskExist = false;
OrderImportTaskDO orderImportTaskDO = null;
// 线程每1s查询一次,查三次没有就提示任务不存在
for (int i = 0; i < 3; i++) {
orderImportTaskDO = orderImportTaskMapper.selectById(taskId);
if (ObjectUtil.isNotNull(orderImportTaskDO)) {
taskExist = true;
break;
} else {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
log.error("====================【线程中断异常】====================");
}
}
public void updateImportTaskFail(OrderImportTaskDO orderImportTaskDO, Exception ex) {
if (orderImportTaskDO == null) {
return;
}
if (taskExist) {
// 更新状态为消费成功
orderImportTaskMapper.update(new LambdaUpdateWrapper<OrderImportTaskDO>().eq(OrderImportTaskDO::getId, taskId).set(OrderImportTaskDO::getStatus, OrderImportTaskStatusEnum.CONSUME_SUCCESS.getStatus()));
String msg;
if (ex instanceof ServiceException) {
msg = ex.getMessage();
} else {
String taskNotExistNotify = String.format("%s不存在的导入任务,消费中止", taskId);
// 更新状态为消费成功,导入失败
orderImportTaskMapper.update(
new LambdaUpdateWrapper<OrderImportTaskDO>()
.eq(OrderImportTaskDO::getId, taskId)
.set(OrderImportTaskDO::getStatus, OrderImportTaskStatusEnum.CONSUME_SUCCESS.getStatus())
.set(OrderImportTaskDO::getImportStatus, OrderImportStatusEnum.IMPORT_FAIL.getStatus())
.set(OrderImportTaskDO::getResult, taskNotExistNotify)
);
log.error(String.format("====================【%s】====================", taskNotExistNotify));
msg = ORDER_IMPORT_FAIL.getMsg();
}
return orderImportTaskDO;
orderImportTaskMapper.update(
new LambdaUpdateWrapper<OrderImportTaskDO>()
.eq(OrderImportTaskDO::getId, orderImportTaskDO.getId())
.set(OrderImportTaskDO::getStatus, OrderImportTaskStatusEnum.CREATE_RECEIVE.getStatus())
.set(OrderImportTaskDO::getImportStatus, OrderImportStatusEnum.IMPORT_FAIL.getStatus())
.set(OrderImportTaskDO::getResult, msg)
.set(OrderImportTaskDO::getRetryCount, orderImportTaskDO.getRetryCount() + 1)
);
}
/**
@@ -42,6 +42,7 @@ import com.cf.imes.module.plan.dal.dataobject.plate.PlateGoodDO;
import com.cf.imes.module.plan.dal.dataobject.rawgoods.RawGoodsDO;
import com.cf.imes.module.plan.dal.elasticsearch.OrderPartsRemark;
import com.cf.imes.module.plan.dal.mysql.goods.GoodsMapper;
import com.cf.imes.module.plan.dal.mysql.order.OrderMapper;
import com.cf.imes.module.plan.dal.mysql.orderBody.OrderBodyMapper;
import com.cf.imes.module.plan.dal.mysql.orderGroup.OrderGroupMapper;
import com.cf.imes.module.plan.dal.mysql.orderImport.OrderImportTaskMapper;
@@ -52,6 +53,7 @@ import com.cf.imes.module.plan.dal.mysql.orderParts.PartsMapper;
import com.cf.imes.module.plan.dal.mysql.plate.PlateGoodMapper;
import com.cf.imes.module.plan.dal.mysql.plate.PlateMapper;
import com.cf.imes.module.plan.dal.mysql.rawgoods.RawGoodsMapper;
import com.cf.imes.module.plan.enums.ErrorCodeConstants;
import com.cf.imes.module.plan.service.customplateno.CustomPlateNoGenerateService;
import com.cf.imes.module.plan.service.customplateno.vo.CustomPlateNoGenerateConfigVO;
import com.cf.imes.module.plan.service.order.OrderInputProcessor;
@@ -119,6 +121,12 @@ public class DefaultExcelOrderImportFactory {
private static final int PLATE_TYPE = OrderImportTmpDataTypeEnum.PLATE.getType();
private static final int PART_TYPE = OrderImportTmpDataTypeEnum.PART.getType();
// 当前导入的板件数量
private int currentPlateNum;
// 当前导入的板件面积
private BigDecimal currentPlateArea = new BigDecimal(0);
private SnowFlakeGenerator snowFlakeGenerator;
private SnowflakeIdWorker3rd idWorker;
@@ -129,6 +137,8 @@ public class DefaultExcelOrderImportFactory {
private DictDataApi dictDataApi;
private OrderMapper orderMapper;
private GoodsMapper goodsMapper;
private RawGoodsMapper rawGoodsMapper;
@@ -162,6 +172,7 @@ public class DefaultExcelOrderImportFactory {
OrderImportTaskMapper orderImportTaskMapper,
OrderImportTempDataMapper orderImportTempDataMapper,
DictDataApi dictDataApi,
OrderMapper orderMapper,
GoodsMapper goodsMapper,
RawGoodsMapper rawGoodsMapper,
OrderPartsMapper orderPartsMapper,
@@ -183,6 +194,7 @@ public class DefaultExcelOrderImportFactory {
this.orderImportTaskMapper = orderImportTaskMapper;
this.orderImportTempDataMapper = orderImportTempDataMapper;
this.dictDataApi = dictDataApi;
this.orderMapper = orderMapper;
this.goodsMapper = goodsMapper;
this.rawGoodsMapper = rawGoodsMapper;
this.orderPartsMapper = orderPartsMapper;
@@ -224,6 +236,10 @@ public class DefaultExcelOrderImportFactory {
// 删除临时数据
deleteTempData();
// 更新生产单板件数量
updateOrderPlateNum();
// 完成所有流程后更新任务为导入成功
updateTaskSuccess();
} catch (Exception e) {
@@ -696,11 +712,7 @@ public class DefaultExcelOrderImportFactory {
String width = combination.getWidth();
// 成品长
String height = combination.getHeight();
// 计算面积
BigDecimal area = BigDecimal.valueOf(Double.parseDouble(width))
.multiply(BigDecimal.valueOf(Double.parseDouble(height)))
.movePointLeft(6)
.setScale(2, RoundingMode.HALF_UP);
Long plateId = (Long) snowFlakeGenerator.nextId(null);
// 排版面 纹路 开门方向转换
DictDataRespDTO typographyDTO = dictDataApi.parseDictData(DictTypeConstants.TYPOGRAPHY_TYPE, combination.getTypographicFace()).getData();// 排版面
@@ -727,10 +739,12 @@ public class DefaultExcelOrderImportFactory {
.sealDown(BigDecimal.valueOf(Double.parseDouble(combination.getSealDown())))
.holeFace(Integer.valueOf(typographyDTO.getValue()))
.texture(Integer.valueOf(grainDTO.getValue()))
.area(area)
.area(tempDataDO.getArea())
.openDoorType(Integer.valueOf(doorDTO.getValue()))
.isSpecialShaped(false)
.isSculpt(false)
.is2v(false)
.isSide2v(false)
.remark(remarkExtract(combination.remarkJSON()))
.roomName(roomName)
.bodyName(bodyName)
@@ -755,6 +769,7 @@ public class DefaultExcelOrderImportFactory {
.isCancel(false)
.filterType(EMPTY_STRING)
.deleted(false)
.planId(0L)
.build();
plateDO.setCreator(operatorName);
plateDO.setUpdater(operatorName);
@@ -762,6 +777,9 @@ public class DefaultExcelOrderImportFactory {
plateDO.setCreateTime(now);
plateDO.setUpdateTime(now);
currentPlateNum += 1;
currentPlateArea = currentPlateArea.add(tempDataDO.getArea());
// 生成自定义板编号
generateCustomPlateNo(plateDO);
@@ -1175,6 +1193,12 @@ public class DefaultExcelOrderImportFactory {
.price(0.00)
.remark(EMPTY_STRING)
.deleted(false)
.exist(false)
.plateNum(groupDO.getGoodsPlateNum())
.plannedPlateNum(0)
.area(groupDO.getGoodsPlateArea())
.plannedPlateArea(0.00)
.version(0)
.build();
goodsDO.setCreator(operatorName);
goodsDO.setUpdater(operatorName);
@@ -1362,6 +1386,24 @@ public class DefaultExcelOrderImportFactory {
// partsDOS.clear();
}
/**
* 更新生产单的板件总数
*/
private void updateOrderPlateNum() {
int version = orderDO.getVersion();
Long orderId = orderDO.getId();
int updated = orderMapper.update(new LambdaUpdateWrapper<OrderDO>()
.eq(OrderDO::getId, orderId)
.eq(OrderDO::getOrganId, organId)
.eq(OrderDO::getVersion, version)
.set(OrderDO::getPlateNum, currentPlateNum)
.set(OrderDO::getArea, currentPlateArea)
.set(OrderDO::getVersion, version + 1));
if (updated == 0) {
throw ServiceExceptionUtil.exception(ErrorCodeConstants.WEBCAD_ORDER_IMPORT_ORDER_UPDATE_CONCURRENCY_ERROR, orderId);
}
}
/**
* 移除taskId下所有临时数据
*/
@@ -74,6 +74,7 @@ import com.cf.imes.module.plan.dal.elasticsearch.Point;
import com.cf.imes.module.plan.dal.elasticsearch.PointDetail;
import com.cf.imes.module.plan.dal.elasticsearch.PointList;
import com.cf.imes.module.plan.dal.mysql.goods.GoodsMapper;
import com.cf.imes.module.plan.dal.mysql.order.OrderMapper;
import com.cf.imes.module.plan.dal.mysql.orderBody.OrderBodyMapper;
import com.cf.imes.module.plan.dal.mysql.orderGroup.OrderGroupMapper;
import com.cf.imes.module.plan.dal.mysql.orderImport.OrderImportTaskMapper;
@@ -84,6 +85,7 @@ import com.cf.imes.module.plan.dal.mysql.orderParts.PartsMapper;
import com.cf.imes.module.plan.dal.mysql.plate.PlateGoodMapper;
import com.cf.imes.module.plan.dal.mysql.plate.PlateMapper;
import com.cf.imes.module.plan.dal.mysql.rawgoods.RawGoodsMapper;
import com.cf.imes.module.plan.enums.ErrorCodeConstants;
import com.cf.imes.module.plan.service.customplateno.CustomPlateNoGenerateService;
import com.cf.imes.module.plan.service.customplateno.vo.CustomPlateNoGenerateConfigVO;
import com.cf.imes.module.plan.service.order.OrderInputProcessor;
@@ -160,6 +162,12 @@ public class DefaultXmlOrderImportFactory {
private static final int PART_HARDWARE_TYPE = OrderImportTmpDataTypeEnum.PART_HARDWARE.getType();
private static final int PART_ASSEMBLY_TYPE = OrderImportTmpDataTypeEnum.PART_ASSEMBLY.getType();
// 当前导入的板件数量
private int currentPlateNum;
// 当前导入的板件面积
private BigDecimal currentPlateArea = new BigDecimal(0);
private SnowFlakeGenerator snowFlakeGenerator;
private SnowflakeIdWorker3rd idWorker;
@@ -168,6 +176,8 @@ public class DefaultXmlOrderImportFactory {
private OrderImportTempDataMapper orderImportTempDataMapper;
private OrderMapper orderMapper;
private GoodsMapper goodsMapper;
private RawGoodsMapper rawGoodsMapper;
@@ -200,6 +210,7 @@ public class DefaultXmlOrderImportFactory {
SnowflakeIdWorker3rd idWorker,
OrderImportTaskMapper orderImportTaskMapper,
OrderImportTempDataMapper orderImportTempDataMapper,
OrderMapper orderMapper,
GoodsMapper goodsMapper,
RawGoodsMapper rawGoodsMapper,
OrderPartsMapper orderPartsMapper,
@@ -220,6 +231,7 @@ public class DefaultXmlOrderImportFactory {
this.idWorker = idWorker;
this.orderImportTaskMapper = orderImportTaskMapper;
this.orderImportTempDataMapper = orderImportTempDataMapper;
this.orderMapper = orderMapper;
this.goodsMapper = goodsMapper;
this.rawGoodsMapper = rawGoodsMapper;
this.orderPartsMapper = orderPartsMapper;
@@ -280,6 +292,10 @@ public class DefaultXmlOrderImportFactory {
// 删除临时数据
deleteTempData();
// 更新生产单板件数量
updateOrderPlateNum();
// 完成所有流程后更新任务为导入成功
updateTaskSuccess();
} catch (Exception e) {
@@ -395,6 +411,11 @@ public class DefaultXmlOrderImportFactory {
.brand(plateXmlVO.getBrand())
.spec(plateXmlVO.getSpecs())
.remark(plateXmlVO.getMemo())
.plateNum(goodsTempData.getNum().intValue())
.plannedPlateNum(0)
.area(goodsTempData.getArea().doubleValue())
.plannedPlateArea(0.0)
.version(0)
.planId(0L)
.price(0.00)
.deleted(false)
@@ -525,6 +546,8 @@ public class DefaultXmlOrderImportFactory {
.openDoorType(doorType)
.isSculpt(false)
.isSpecialShaped(convertToBoolean(blockXmlVO.getUnregular()))
.is2v(false)
.isSide2v(false)
.customPlateNoBuilder(new StringBuilder())
.organId(organId)
.holeArrange(0)
@@ -551,6 +574,7 @@ public class DefaultXmlOrderImportFactory {
.sealDown(BigDecimal.ZERO)
.remark(EMPTY_STRING)
.deleted(false)
.planId(0L)
.build();
plateDO.setCreator(operatorName);
plateDO.setUpdater(operatorName);
@@ -558,6 +582,9 @@ public class DefaultXmlOrderImportFactory {
plateDO.setCreateTime(now);
plateDO.setUpdateTime(now);
currentPlateNum += 1;
currentPlateArea = currentPlateArea.add(plateDO.getArea());
// 生成自定义板编号
generateCustomPlateNo(plateDO);
@@ -1915,6 +1942,24 @@ public class DefaultXmlOrderImportFactory {
orderImportTempDataMapper.delete(new LambdaQueryWrapper<OrderImportTempDataDO>().eq(OrderImportTempDataDO::getTaskId, taskId));
}
/**
* 更新生产单的板件总数
*/
private void updateOrderPlateNum() {
int version = orderDO.getVersion();
Long orderId = orderDO.getId();
int updated = orderMapper.update(new LambdaUpdateWrapper<OrderDO>()
.eq(OrderDO::getId, orderId)
.eq(OrderDO::getOrganId, organId)
.eq(OrderDO::getVersion, version)
.set(OrderDO::getPlateNum, currentPlateNum)
.set(OrderDO::getArea, currentPlateArea)
.set(OrderDO::getVersion, version + 1));
if (updated == 0) {
throw ServiceExceptionUtil.exception(ErrorCodeConstants.WEBCAD_ORDER_IMPORT_ORDER_UPDATE_CONCURRENCY_ERROR, orderId);
}
}
/**
* 更新为导入成功
*/
@@ -59,7 +59,9 @@
material,
color,
thickness,
brand
brand,
sum(num) as goodsPlateNum,
sum(area) as goodsPlateArea
<if test="reqVO.doPaging">
,min(sort) as sortn
</if>