mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-12 21:02:08 +08:00
1、system rabbitmq队列声明暂注释;2、cad异步拆单锁调整;
This commit is contained in:
+2
-1
@@ -14,6 +14,7 @@ public interface WebCadOrderImportService {
|
||||
* webcad生产单导入
|
||||
*
|
||||
* @param file
|
||||
* @return true:同步导入、false:异步导入
|
||||
*/
|
||||
void webCadOrderImport(MultipartFile file);
|
||||
boolean webCadOrderImport(MultipartFile file);
|
||||
}
|
||||
|
||||
+48
-11
@@ -55,6 +55,7 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
import static com.cf.imes.framework.security.core.util.SecurityFrameworkUtils.getUserOrganId;
|
||||
import static com.cf.imes.module.executor.enums.ErrorCodeConstants.ORDER_IMPORT_ORGAN_LOCK_ERROR;
|
||||
import static com.cf.imes.module.plan.enums.ErrorCodeConstants.WEBCAD_ORDER_IMPORT_FAILED;
|
||||
import static com.cf.imes.module.plan.enums.ErrorCodeConstants.WEBCAD_ORDER_IMPORT_ORGANID_EMPTY_ERROR;
|
||||
@@ -138,18 +139,20 @@ public class WebCadOrderImportServiceImpl implements WebCadOrderImportService {
|
||||
private static final String REDIS_UNIQUEKEY = "webcad";
|
||||
|
||||
@Override
|
||||
public void webCadOrderImport(MultipartFile file) {
|
||||
public boolean webCadOrderImport(MultipartFile file) {
|
||||
Long organId = OrganContextHolder.getOrganId();
|
||||
|
||||
if (ObjectUtil.isNull(organId)) {
|
||||
throw new ServiceException(WEBCAD_ORDER_IMPORT_ORGANID_EMPTY_ERROR);
|
||||
}
|
||||
// 上锁
|
||||
addLock(organId);
|
||||
|
||||
TransactionStatus transactionStatus = transactionManager.getTransaction(TransactionDefinition.withDefaults());
|
||||
// 是否同步处理
|
||||
boolean sync = true;
|
||||
|
||||
// 异步发送是否成功,没有成功需要把锁解开
|
||||
boolean initAsyncSuccess = false;
|
||||
|
||||
Long taskId = null;
|
||||
JsonFactory factory = new JsonFactory();
|
||||
try (GZIPInputStream gzipInputStream = new GZIPInputStream(file.getInputStream());
|
||||
@@ -172,6 +175,8 @@ public class WebCadOrderImportServiceImpl implements WebCadOrderImportService {
|
||||
fileName = parser.getText();
|
||||
} else if ("blockData".equals(fieldName)) {
|
||||
if (plateCount < webcadAsyncPlateThreshold) {
|
||||
// 上锁
|
||||
addSyncLock(organId);
|
||||
|
||||
// 在异步阈值范围内,直接解析整个对象
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
@@ -193,8 +198,13 @@ public class WebCadOrderImportServiceImpl implements WebCadOrderImportService {
|
||||
// 缓存请求,创建导入任务
|
||||
taskId = initiateTask(node, organId, fileName);
|
||||
|
||||
// 上锁
|
||||
addAsyncLock(taskId);
|
||||
|
||||
// 发送异步消息
|
||||
sendMessage(taskId, organId);
|
||||
sendMessage(taskId);
|
||||
|
||||
initAsyncSuccess = true;
|
||||
|
||||
// 跳过当前 blockData 解析步骤
|
||||
parser.skipChildren(); // 忽略 blockData
|
||||
@@ -222,11 +232,9 @@ public class WebCadOrderImportServiceImpl implements WebCadOrderImportService {
|
||||
log.error(webcadOrderImportFailed.getMsg(), e);
|
||||
throw new ServiceException(webcadOrderImportFailed);
|
||||
} finally {
|
||||
if (sync) {
|
||||
// 导入锁解锁
|
||||
redisLockUtil.unlock(String.format(RedisKeyConstants.ORDER_IMPORT_LOCK_KEY, organId), REDIS_UNIQUEKEY);
|
||||
}
|
||||
unlock(sync, initAsyncSuccess, organId, taskId);
|
||||
}
|
||||
return sync;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -253,7 +261,7 @@ public class WebCadOrderImportServiceImpl implements WebCadOrderImportService {
|
||||
*
|
||||
* @param taskId
|
||||
*/
|
||||
private void sendMessage(Long taskId, Long organId) {
|
||||
private void sendMessage(Long taskId) {
|
||||
Message message = MessageBuilder
|
||||
.withBody(taskId.toString().getBytes())
|
||||
.setHeader("peek", DynamicDataSourceContextHolder.peek())
|
||||
@@ -275,11 +283,11 @@ public class WebCadOrderImportServiceImpl implements WebCadOrderImportService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 加导入锁
|
||||
* 加同步导入锁
|
||||
*
|
||||
* @param organId
|
||||
*/
|
||||
private void addLock(Long organId) {
|
||||
private void addSyncLock(Long organId) {
|
||||
String importLockKey = String.format(RedisKeyConstants.ORDER_IMPORT_LOCK_KEY, organId);
|
||||
// 检查机构导入锁
|
||||
boolean lockResult = redisLockUtil.lock(importLockKey, REDIS_UNIQUEKEY, chenfengCacheProperties.getLockTimeout());
|
||||
@@ -288,6 +296,35 @@ public class WebCadOrderImportServiceImpl implements WebCadOrderImportService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 加异步导入锁
|
||||
*
|
||||
* @param taskId
|
||||
*/
|
||||
private void addAsyncLock(Long taskId) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解锁
|
||||
*/
|
||||
private void unlock(boolean sync, boolean initAsyncSuccess, Long organId, Long taskId) {
|
||||
if(sync) {
|
||||
// 解同步锁
|
||||
redisLockUtil.unlock(String.format(RedisKeyConstants.ORDER_IMPORT_LOCK_KEY, organId), REDIS_UNIQUEKEY);
|
||||
} else {
|
||||
// 异步发送消息失败了,解开异步锁
|
||||
if (!initAsyncSuccess && ObjectUtil.isNotNull(taskId)) {
|
||||
redisLockUtil.unlock(String.format(RedisKeyConstants.ORDER_IMPORT_LOCK_KEY, organId), String.valueOf(taskId));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 异常时移除临时文件
|
||||
|
||||
+1
-3
@@ -104,8 +104,6 @@ public class WebCadOrderImportConsumer {
|
||||
@Value("${chenfeng.plan.webcad.import.temp-file-path}")
|
||||
private String webcadJsonCachePath;
|
||||
|
||||
private static final String REDIS_UNIQUEKEY = "webcad";
|
||||
|
||||
@Resource
|
||||
private DataSourceTransactionManager transactionManager;
|
||||
|
||||
@@ -169,7 +167,7 @@ public class WebCadOrderImportConsumer {
|
||||
channel.basicAck(deliveryTag, false);
|
||||
}
|
||||
// 导入锁解锁
|
||||
redisLockUtil.unlock(String.format(RedisKeyConstants.ORDER_IMPORT_LOCK_KEY, organId), REDIS_UNIQUEKEY);
|
||||
redisLockUtil.unlock(String.format(RedisKeyConstants.ORDER_IMPORT_LOCK_KEY, organId), message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+186
-185
@@ -1268,7 +1268,7 @@ public class WebCadOrderImportFactory {
|
||||
* @param roomNameKey
|
||||
* @param listBody
|
||||
*/
|
||||
private void multipleCreateProcessGroup(Integer count , String roomNameKey, List<WebCadDataPartsReqVO.BlockObjectListDTO> listBody) {
|
||||
private void multipleCreateProcessGroup(Integer count, String roomNameKey, List<WebCadDataPartsReqVO.BlockObjectListDTO> listBody) {
|
||||
// 成倍数量
|
||||
for (int j = 0; j < count; j++) {
|
||||
// 获取板材已经创建的柜体,缓存key:房间名+柜体名+成倍序号
|
||||
@@ -1419,84 +1419,85 @@ public class WebCadOrderImportFactory {
|
||||
* @param part
|
||||
*/
|
||||
private void analyzeOrderPart(WebCadDataPartsReqVO.BlockObjectListDTO part) {
|
||||
boolean composite = part.getIsComposite();
|
||||
String partType = part.getType();
|
||||
String factory = part.getFactory();
|
||||
String model = part.getModel();
|
||||
String spec = part.getSpec();
|
||||
String height = part.getHeight();
|
||||
String width = part.getWidth();
|
||||
String thickness = part.getThickness();
|
||||
String unit = part.getUnit();
|
||||
String brand = part.getBrand();
|
||||
boolean composite = part.getIsComposite();
|
||||
String partType = part.getType();
|
||||
String factory = part.getFactory();
|
||||
String model = part.getModel();
|
||||
String spec = part.getSpec();
|
||||
String height = part.getHeight();
|
||||
String width = part.getWidth();
|
||||
String thickness = part.getThickness();
|
||||
String unit = part.getUnit();
|
||||
String brand = part.getBrand();
|
||||
|
||||
// 分类配件的键组合
|
||||
String groupKey = composite + partType + factory + model + spec + height + width + thickness + unit + brand;
|
||||
// 分类配件的键组合
|
||||
String groupKey = composite + partType + factory + model + spec + height + width + thickness + unit + brand;
|
||||
|
||||
Long orderPartId = orderPartMap.get(groupKey);
|
||||
if(ObjectUtil.isNull(orderPartId)) {
|
||||
Long partId = (Long) snowFlakeGenerator.nextId(null);
|
||||
Long orderPartId = orderPartMap.get(groupKey);
|
||||
if (ObjectUtil.isNull(orderPartId)) {
|
||||
Long partId = (Long) snowFlakeGenerator.nextId(null);
|
||||
|
||||
String color = null;
|
||||
String material = null;
|
||||
if (PART_CATEGORY_ONE.equals(partType)) {
|
||||
WebCadDataPartsReqVO.BlockObjectListDTO.GroupDataDTO partGroupData = part.getGroupData();
|
||||
color = partGroupData.getColor();
|
||||
material = partGroupData.getMaterial();
|
||||
// 封边条宽度从系统配置中获取宽度对应
|
||||
sealEdgeWidthMatch(part);
|
||||
// 规格可能修改,再获取一次
|
||||
spec = part.getSpec();
|
||||
} else if (PART_CATEGORY_THREE.equals(partType)) {
|
||||
color = getFieldFromSpec(part.getSpec(), 2);
|
||||
material = getFieldFromSpec(part.getSpec(), 1);
|
||||
}
|
||||
String color = null;
|
||||
String material = null;
|
||||
if (PART_CATEGORY_ONE.equals(partType)) {
|
||||
WebCadDataPartsReqVO.BlockObjectListDTO.GroupDataDTO partGroupData = part.getGroupData();
|
||||
color = partGroupData.getColor();
|
||||
material = partGroupData.getMaterial();
|
||||
// 封边条宽度从系统配置中获取宽度对应
|
||||
sealEdgeWidthMatch(part);
|
||||
// 规格可能修改,再获取一次
|
||||
spec = part.getSpec();
|
||||
} else if (PART_CATEGORY_THREE.equals(partType)) {
|
||||
color = getFieldFromSpec(part.getSpec(), 2);
|
||||
material = getFieldFromSpec(part.getSpec(), 1);
|
||||
}
|
||||
|
||||
String type = changePartType(partType, part.getIsComposite());
|
||||
// todo remark、备注信息到es
|
||||
OrderPartsDO orderPartsDO = OrderPartsDO.builder()
|
||||
.id(partId)
|
||||
.orderId(orderId)
|
||||
.color(getEmpty(color))
|
||||
.category(type)
|
||||
.type(type)
|
||||
.goodsId(EMPTY_STRING)
|
||||
.length(NumberUtil.parseDouble(part.getHeight()))
|
||||
.width(NumberUtil.parseDouble(part.getWidth()))
|
||||
.thickness(NumberUtil.parseDouble(part.getThickness()))
|
||||
.isComposite(part.getIsComposite())
|
||||
.name(part.getName())
|
||||
.material(getEmpty(material))
|
||||
.model(getEmpty(model))
|
||||
.spec(getEmpty(spec))
|
||||
.brand(getEmpty(brand))
|
||||
.factory(getEmpty(factory))
|
||||
.unit(part.getUnit())
|
||||
.price(0.0)
|
||||
.subparts(EMPTY_STRING)
|
||||
.remark(getEmpty(part.getRemark()))
|
||||
.organId(organId)
|
||||
.deleted(false)
|
||||
.build();
|
||||
orderPartsDO.setCreator(operatorName);
|
||||
orderPartsDO.setUpdater(operatorName);
|
||||
orderPartsDO.setCreateTime(now);
|
||||
orderPartsDO.setUpdateTime(now);
|
||||
orderPartsDOS.add(orderPartsDO);
|
||||
String type = changePartType(partType, part.getIsComposite());
|
||||
// todo remark、备注信息到es
|
||||
OrderPartsDO orderPartsDO = OrderPartsDO.builder()
|
||||
.id(partId)
|
||||
.orderId(orderId)
|
||||
.color(getEmpty(color))
|
||||
.category(type)
|
||||
.type(type)
|
||||
.goodsId(EMPTY_STRING)
|
||||
.length(NumberUtil.parseDouble(part.getHeight()))
|
||||
.width(NumberUtil.parseDouble(part.getWidth()))
|
||||
.thickness(NumberUtil.parseDouble(part.getThickness()))
|
||||
.isComposite(part.getIsComposite())
|
||||
.name(part.getName())
|
||||
.material(getEmpty(material))
|
||||
.model(getEmpty(model))
|
||||
.spec(getEmpty(spec))
|
||||
.brand(getEmpty(brand))
|
||||
.factory(getEmpty(factory))
|
||||
.unit(part.getUnit())
|
||||
.price(0.0)
|
||||
.subparts(EMPTY_STRING)
|
||||
.remark(getEmpty(part.getRemark()))
|
||||
.organId(organId)
|
||||
.deleted(false)
|
||||
.build();
|
||||
orderPartsDO.setCreator(operatorName);
|
||||
orderPartsDO.setUpdater(operatorName);
|
||||
orderPartsDO.setCreateTime(now);
|
||||
orderPartsDO.setUpdateTime(now);
|
||||
orderPartsDOS.add(orderPartsDO);
|
||||
orderPartBatchInsertWithinThreshold(orderPartsDOS, false);
|
||||
|
||||
// orderpart id回显到配件
|
||||
part.setImesPartsId(partId);
|
||||
// orderpart id回显到配件
|
||||
part.setImesPartsId(partId);
|
||||
|
||||
orderPartMap.put(groupKey, partId);
|
||||
} else {
|
||||
// orderpart id回显到配件
|
||||
part.setImesPartsId(orderPartId);
|
||||
}
|
||||
orderPartMap.put(groupKey, partId);
|
||||
} else {
|
||||
// orderpart id回显到配件
|
||||
part.setImesPartsId(orderPartId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从规格中获取属性,例:material、color
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private String getFieldFromSpec(String spec, int index) {
|
||||
@@ -1636,65 +1637,65 @@ public class WebCadOrderImportFactory {
|
||||
private void orderPlateBatchInsertWithinThreshold(List<PlateDO> list, boolean isLast) {
|
||||
// 达到批量的阈值就做一次插入
|
||||
if (CollUtil.isNotEmpty(list) && (list.size() >= BATCH_THRESHOLD_NUMBER || isLast)) {
|
||||
String sql = "INSERT INTO order_plate (id,organ_id,order_id,name,plate_no,type,goods_id,width,height,thickness,split_width,split_height,split_thickness,seal_left,seal_right,seal_up,seal_down,area,texture,hole_face,hole_arrange,unregular_point_count,front_hole_count,back_hole_count,side_hole_count,front_model_count,back_model_count,is_door,open_door_type,offset_x,offset_y,is_arc_across,module_type_id,is_special_shaped,is_sculpt,is_row_hole,is_optimized,is_cutted,filter_type,remark,is_cancel,deleted,custom_plate_no,create_time,update_time,creator,updater) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
|
||||
jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {
|
||||
@Override
|
||||
public void setValues(PreparedStatement ps, int index) throws SQLException {
|
||||
PlateDO item = list.get(index);
|
||||
ps.setLong(1, item.getId());
|
||||
ps.setLong(2, item.getOrganId());
|
||||
ps.setLong(3, item.getOrderId());
|
||||
ps.setString(4, item.getName());
|
||||
ps.setString(5, item.getPlateNo());
|
||||
ps.setInt(6, item.getType());
|
||||
ps.setLong(7, item.getGoodsId());
|
||||
ps.setBigDecimal(8, item.getWidth());
|
||||
ps.setBigDecimal(9, item.getHeight());
|
||||
ps.setBigDecimal(10, item.getThickness());
|
||||
ps.setBigDecimal(11, item.getSplitWidth());
|
||||
ps.setBigDecimal(12, item.getSplitHeight());
|
||||
ps.setBigDecimal(13, item.getSplitThickness());
|
||||
ps.setBigDecimal(14, item.getSealLeft());
|
||||
ps.setBigDecimal(15, item.getSealRight());
|
||||
ps.setBigDecimal(16, item.getSealUp());
|
||||
ps.setBigDecimal(17, item.getSealDown());
|
||||
ps.setBigDecimal(18, item.getArea());
|
||||
ps.setInt(19, item.getTexture());
|
||||
ps.setInt(20, item.getHoleFace());
|
||||
ps.setInt(21, item.getHoleArrange());
|
||||
ps.setInt(22, item.getUnregularPointCount());
|
||||
ps.setInt(23, item.getFrontHoleCount());
|
||||
ps.setInt(24, item.getBackHoleCount());
|
||||
ps.setInt(25, item.getSideHoleCount());
|
||||
ps.setInt(26, item.getFrontModelCount());
|
||||
ps.setInt(27, item.getBackModelCount());
|
||||
ps.setBoolean(28, item.getIsDoor());
|
||||
ps.setInt(29, item.getOpenDoorType());
|
||||
ps.setBigDecimal(30, item.getOffsetX());
|
||||
ps.setBigDecimal(31, item.getOffsetY());
|
||||
ps.setBoolean(32, item.getIsArcAcross());
|
||||
ps.setLong(33, item.getModuleTypeId());
|
||||
ps.setBoolean(34, item.getIsSpecialShaped());
|
||||
ps.setBoolean(35, item.getIsSculpt());
|
||||
ps.setBoolean(36, item.getIsRowHole());
|
||||
ps.setBoolean(37, item.getIsOptimized());
|
||||
ps.setInt(38, item.getIsCutted());
|
||||
ps.setString(39, item.getFilterType());
|
||||
ps.setString(40, item.getRemark());
|
||||
ps.setBoolean(41, item.getIsCancel());
|
||||
ps.setBoolean(42, item.getDeleted());
|
||||
ps.setString(43, item.getCustomPlateNo());
|
||||
ps.setTimestamp(44, Timestamp.valueOf(item.getCreateTime()));
|
||||
ps.setTimestamp(45, Timestamp.valueOf(item.getUpdateTime()));
|
||||
ps.setString(46, item.getCreator());
|
||||
ps.setString(47, item.getUpdater());
|
||||
}
|
||||
String sql = "INSERT INTO order_plate (id,organ_id,order_id,name,plate_no,type,goods_id,width,height,thickness,split_width,split_height,split_thickness,seal_left,seal_right,seal_up,seal_down,area,texture,hole_face,hole_arrange,unregular_point_count,front_hole_count,back_hole_count,side_hole_count,front_model_count,back_model_count,is_door,open_door_type,offset_x,offset_y,is_arc_across,module_type_id,is_special_shaped,is_sculpt,is_row_hole,is_optimized,is_cutted,filter_type,remark,is_cancel,deleted,custom_plate_no,create_time,update_time,creator,updater) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
|
||||
jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {
|
||||
@Override
|
||||
public void setValues(PreparedStatement ps, int index) throws SQLException {
|
||||
PlateDO item = list.get(index);
|
||||
ps.setLong(1, item.getId());
|
||||
ps.setLong(2, item.getOrganId());
|
||||
ps.setLong(3, item.getOrderId());
|
||||
ps.setString(4, item.getName());
|
||||
ps.setString(5, item.getPlateNo());
|
||||
ps.setInt(6, item.getType());
|
||||
ps.setLong(7, item.getGoodsId());
|
||||
ps.setBigDecimal(8, item.getWidth());
|
||||
ps.setBigDecimal(9, item.getHeight());
|
||||
ps.setBigDecimal(10, item.getThickness());
|
||||
ps.setBigDecimal(11, item.getSplitWidth());
|
||||
ps.setBigDecimal(12, item.getSplitHeight());
|
||||
ps.setBigDecimal(13, item.getSplitThickness());
|
||||
ps.setBigDecimal(14, item.getSealLeft());
|
||||
ps.setBigDecimal(15, item.getSealRight());
|
||||
ps.setBigDecimal(16, item.getSealUp());
|
||||
ps.setBigDecimal(17, item.getSealDown());
|
||||
ps.setBigDecimal(18, item.getArea());
|
||||
ps.setInt(19, item.getTexture());
|
||||
ps.setInt(20, item.getHoleFace());
|
||||
ps.setInt(21, item.getHoleArrange());
|
||||
ps.setInt(22, item.getUnregularPointCount());
|
||||
ps.setInt(23, item.getFrontHoleCount());
|
||||
ps.setInt(24, item.getBackHoleCount());
|
||||
ps.setInt(25, item.getSideHoleCount());
|
||||
ps.setInt(26, item.getFrontModelCount());
|
||||
ps.setInt(27, item.getBackModelCount());
|
||||
ps.setBoolean(28, item.getIsDoor());
|
||||
ps.setInt(29, item.getOpenDoorType());
|
||||
ps.setBigDecimal(30, item.getOffsetX());
|
||||
ps.setBigDecimal(31, item.getOffsetY());
|
||||
ps.setBoolean(32, item.getIsArcAcross());
|
||||
ps.setLong(33, item.getModuleTypeId());
|
||||
ps.setBoolean(34, item.getIsSpecialShaped());
|
||||
ps.setBoolean(35, item.getIsSculpt());
|
||||
ps.setBoolean(36, item.getIsRowHole());
|
||||
ps.setBoolean(37, item.getIsOptimized());
|
||||
ps.setInt(38, item.getIsCutted());
|
||||
ps.setString(39, item.getFilterType());
|
||||
ps.setString(40, item.getRemark());
|
||||
ps.setBoolean(41, item.getIsCancel());
|
||||
ps.setBoolean(42, item.getDeleted());
|
||||
ps.setString(43, item.getCustomPlateNo());
|
||||
ps.setTimestamp(44, Timestamp.valueOf(item.getCreateTime()));
|
||||
ps.setTimestamp(45, Timestamp.valueOf(item.getUpdateTime()));
|
||||
ps.setString(46, item.getCreator());
|
||||
ps.setString(47, item.getUpdater());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBatchSize() {
|
||||
return list.size();
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public int getBatchSize() {
|
||||
return list.size();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
if (!isLast) {
|
||||
@@ -1708,29 +1709,29 @@ public class WebCadOrderImportFactory {
|
||||
// 达到批量的阈值就做一次插入
|
||||
if (CollUtil.isNotEmpty(list) && (list.size() >= BATCH_THRESHOLD_NUMBER || isLast)) {
|
||||
|
||||
String sql = "INSERT INTO order_item (id,order_id,type,room_id,body_id,package_id,group_id,plate_id,parts_id,num,organ_id) VALUES (?,?,?,?,?,?,?,?,?,?,?)";
|
||||
jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {
|
||||
@Override
|
||||
public void setValues(PreparedStatement ps, int index) throws SQLException {
|
||||
OrderItemDO item = list.get(index);
|
||||
ps.setLong(1, item.getId());
|
||||
ps.setLong(2, item.getOrderId());
|
||||
ps.setInt(3, item.getType());
|
||||
ps.setLong(4, item.getRoomId());
|
||||
ps.setLong(5, item.getBodyId());
|
||||
ps.setLong(6, item.getPackageId());
|
||||
ps.setLong(7, item.getGroupId());
|
||||
ps.setLong(8, item.getPlateId());
|
||||
ps.setLong(9, item.getPartsId());
|
||||
ps.setDouble(10, item.getNum());
|
||||
ps.setLong(11, item.getOrganId());
|
||||
}
|
||||
String sql = "INSERT INTO order_item (id,order_id,type,room_id,body_id,package_id,group_id,plate_id,parts_id,num,organ_id) VALUES (?,?,?,?,?,?,?,?,?,?,?)";
|
||||
jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {
|
||||
@Override
|
||||
public void setValues(PreparedStatement ps, int index) throws SQLException {
|
||||
OrderItemDO item = list.get(index);
|
||||
ps.setLong(1, item.getId());
|
||||
ps.setLong(2, item.getOrderId());
|
||||
ps.setInt(3, item.getType());
|
||||
ps.setLong(4, item.getRoomId());
|
||||
ps.setLong(5, item.getBodyId());
|
||||
ps.setLong(6, item.getPackageId());
|
||||
ps.setLong(7, item.getGroupId());
|
||||
ps.setLong(8, item.getPlateId());
|
||||
ps.setLong(9, item.getPartsId());
|
||||
ps.setDouble(10, item.getNum());
|
||||
ps.setLong(11, item.getOrganId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBatchSize() {
|
||||
return list.size();
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public int getBatchSize() {
|
||||
return list.size();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
if (!isLast) {
|
||||
@@ -1744,44 +1745,44 @@ public class WebCadOrderImportFactory {
|
||||
// 达到批量的阈值就做一次插入
|
||||
if (CollUtil.isNotEmpty(list) && (list.size() >= BATCH_THRESHOLD_NUMBER || isLast)) {
|
||||
|
||||
String sql = "INSERT INTO order_parts (id,organ_id,order_id,goods_id,name,color,material,category,type,width,length,thickness,model,spec,brand,factory,unit,price,is_composite,subparts,remark,deleted,create_time,update_time,creator,updater) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
|
||||
jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {
|
||||
@Override
|
||||
public void setValues(PreparedStatement ps, int index) throws SQLException {
|
||||
OrderPartsDO item = list.get(index);
|
||||
ps.setLong(1, item.getId());
|
||||
ps.setLong(2, item.getOrganId());
|
||||
ps.setLong(3, item.getOrderId());
|
||||
ps.setString(4, item.getGoodsId());
|
||||
ps.setString(5, item.getName());
|
||||
ps.setString(6, item.getColor());
|
||||
ps.setString(7, item.getMaterial());
|
||||
ps.setString(8, item.getCategory());
|
||||
ps.setString(9, item.getType());
|
||||
ps.setDouble(10, item.getWidth());
|
||||
ps.setDouble(11, item.getLength());
|
||||
ps.setDouble(12, item.getThickness());
|
||||
ps.setString(13, item.getModel());
|
||||
ps.setString(14, item.getSpec());
|
||||
ps.setString(15, item.getBrand());
|
||||
ps.setString(16, item.getFactory());
|
||||
ps.setString(17, item.getUnit());
|
||||
ps.setDouble(18, item.getPrice());
|
||||
ps.setBoolean(19, item.getIsComposite());
|
||||
ps.setString(20, item.getSubparts());
|
||||
ps.setString(21, item.getRemark());
|
||||
ps.setBoolean(22, item.getDeleted());
|
||||
ps.setTimestamp(23, Timestamp.valueOf(item.getCreateTime()));
|
||||
ps.setTimestamp(24, Timestamp.valueOf(item.getUpdateTime()));
|
||||
ps.setString(25, item.getCreator());
|
||||
ps.setString(26, item.getUpdater());
|
||||
}
|
||||
String sql = "INSERT INTO order_parts (id,organ_id,order_id,goods_id,name,color,material,category,type,width,length,thickness,model,spec,brand,factory,unit,price,is_composite,subparts,remark,deleted,create_time,update_time,creator,updater) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
|
||||
jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {
|
||||
@Override
|
||||
public void setValues(PreparedStatement ps, int index) throws SQLException {
|
||||
OrderPartsDO item = list.get(index);
|
||||
ps.setLong(1, item.getId());
|
||||
ps.setLong(2, item.getOrganId());
|
||||
ps.setLong(3, item.getOrderId());
|
||||
ps.setString(4, item.getGoodsId());
|
||||
ps.setString(5, item.getName());
|
||||
ps.setString(6, item.getColor());
|
||||
ps.setString(7, item.getMaterial());
|
||||
ps.setString(8, item.getCategory());
|
||||
ps.setString(9, item.getType());
|
||||
ps.setDouble(10, item.getWidth());
|
||||
ps.setDouble(11, item.getLength());
|
||||
ps.setDouble(12, item.getThickness());
|
||||
ps.setString(13, item.getModel());
|
||||
ps.setString(14, item.getSpec());
|
||||
ps.setString(15, item.getBrand());
|
||||
ps.setString(16, item.getFactory());
|
||||
ps.setString(17, item.getUnit());
|
||||
ps.setDouble(18, item.getPrice());
|
||||
ps.setBoolean(19, item.getIsComposite());
|
||||
ps.setString(20, item.getSubparts());
|
||||
ps.setString(21, item.getRemark());
|
||||
ps.setBoolean(22, item.getDeleted());
|
||||
ps.setTimestamp(23, Timestamp.valueOf(item.getCreateTime()));
|
||||
ps.setTimestamp(24, Timestamp.valueOf(item.getUpdateTime()));
|
||||
ps.setString(25, item.getCreator());
|
||||
ps.setString(26, item.getUpdater());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBatchSize() {
|
||||
return list.size();
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public int getBatchSize() {
|
||||
return list.size();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
if (!isLast) {
|
||||
|
||||
+71
-71
@@ -1,71 +1,71 @@
|
||||
package com.cf.imes.module.system.mq.consumer.advertisement;
|
||||
|
||||
import com.cf.imes.framework.mq.rabbitmq.constant.RabbitMqConstants;
|
||||
import com.cf.imes.module.system.dal.dataobject.advertisement.AdvertisementDO;
|
||||
import com.cf.imes.module.system.dal.dataobject.advertisement.AdvertisementTaskDO;
|
||||
import com.cf.imes.module.system.dal.mysql.advertisement.AdvertisementMapper;
|
||||
import com.cf.imes.module.system.dal.mysql.advertisement.AdvertisementTaskMapper;
|
||||
import com.cf.imes.module.system.enums.advertisement.AdvertisementStatusEnum;
|
||||
import com.cf.imes.module.system.enums.advertisement.MessageStatusEnum;
|
||||
import com.cf.imes.module.system.mq.message.advertisement.AdvertisementSendMessage;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
/**
|
||||
* 针对 {@link AdvertisementSendMessage} 的消费者
|
||||
*
|
||||
* @author 晨丰科技
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class AdvertisementSendConsumer {
|
||||
|
||||
@Resource
|
||||
private AdvertisementMapper advertisementMapper;
|
||||
|
||||
@Resource
|
||||
private AdvertisementTaskMapper advertisementTaskMapper;
|
||||
|
||||
@RabbitListener(queues = RabbitMqConstants.SYSTEM_ADVERTISEMENT_UPDATE_DELAYED_QUEUE)
|
||||
public void onMessage(AdvertisementSendMessage message){
|
||||
// 1. 获取广告数据
|
||||
AdvertisementDO ad = advertisementMapper.selectById(message.getAdId());
|
||||
if (ad == null || ad.getDeleted())
|
||||
return;
|
||||
|
||||
// 2. 检查消息有效性
|
||||
AdvertisementTaskDO messageRecord = advertisementTaskMapper.selectByMessageId(message.getMessageId());
|
||||
if (messageRecord == null ||
|
||||
Objects.equals(messageRecord.getMessageStatus(), MessageStatusEnum.CANCELLED.getStatus())) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 3. 处理状态变更
|
||||
if (AdvertisementStatusEnum.PUBLISHED.getName().equals(message.getAction())) { // 待发布
|
||||
if (ad.getStatus() == AdvertisementStatusEnum.UNPUBLISHED.getStatus() &&
|
||||
LocalDateTime.now().isAfter(ad.getStartTime())) {
|
||||
updateAdStatus(ad, messageRecord.getAdvertisementStatus());
|
||||
}
|
||||
} else if (AdvertisementStatusEnum.ENDED.getName().equals(message.getAction())) { // 待结束
|
||||
if (ad.getStatus() == AdvertisementStatusEnum.PUBLISHED.getStatus() &&
|
||||
LocalDateTime.now().isAfter(ad.getEndTime())) {
|
||||
updateAdStatus(ad, messageRecord.getAdvertisementStatus());
|
||||
}
|
||||
}
|
||||
|
||||
// 4. 标记消息为已处理
|
||||
messageRecord.setMessageStatus(MessageStatusEnum.PROCESSED.getStatus());
|
||||
advertisementTaskMapper.updateMessageStateByMessageId(message.getMessageId(),false, MessageStatusEnum.PROCESSED.getStatus());
|
||||
}
|
||||
|
||||
private void updateAdStatus(AdvertisementDO ad, Integer newStatus) {
|
||||
advertisementMapper.updateAdStatus(ad.getId(), newStatus);
|
||||
}
|
||||
|
||||
}
|
||||
//package com.cf.imes.module.system.mq.consumer.advertisement;
|
||||
//
|
||||
//import com.cf.imes.framework.mq.rabbitmq.constant.RabbitMqConstants;
|
||||
//import com.cf.imes.module.system.dal.dataobject.advertisement.AdvertisementDO;
|
||||
//import com.cf.imes.module.system.dal.dataobject.advertisement.AdvertisementTaskDO;
|
||||
//import com.cf.imes.module.system.dal.mysql.advertisement.AdvertisementMapper;
|
||||
//import com.cf.imes.module.system.dal.mysql.advertisement.AdvertisementTaskMapper;
|
||||
//import com.cf.imes.module.system.enums.advertisement.AdvertisementStatusEnum;
|
||||
//import com.cf.imes.module.system.enums.advertisement.MessageStatusEnum;
|
||||
//import com.cf.imes.module.system.mq.message.advertisement.AdvertisementSendMessage;
|
||||
//import lombok.extern.slf4j.Slf4j;
|
||||
//import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//
|
||||
//import javax.annotation.Resource;
|
||||
//import java.time.LocalDateTime;
|
||||
//import java.util.Objects;
|
||||
//
|
||||
//
|
||||
///**
|
||||
// * 针对 {@link AdvertisementSendMessage} 的消费者
|
||||
// *
|
||||
// * @author 晨丰科技
|
||||
// */
|
||||
//@Component
|
||||
//@Slf4j
|
||||
//public class AdvertisementSendConsumer {
|
||||
//
|
||||
// @Resource
|
||||
// private AdvertisementMapper advertisementMapper;
|
||||
//
|
||||
// @Resource
|
||||
// private AdvertisementTaskMapper advertisementTaskMapper;
|
||||
//
|
||||
// @RabbitListener(queues = RabbitMqConstants.SYSTEM_ADVERTISEMENT_UPDATE_DELAYED_QUEUE)
|
||||
// public void onMessage(AdvertisementSendMessage message){
|
||||
// // 1. 获取广告数据
|
||||
// AdvertisementDO ad = advertisementMapper.selectById(message.getAdId());
|
||||
// if (ad == null || ad.getDeleted())
|
||||
// return;
|
||||
//
|
||||
// // 2. 检查消息有效性
|
||||
// AdvertisementTaskDO messageRecord = advertisementTaskMapper.selectByMessageId(message.getMessageId());
|
||||
// if (messageRecord == null ||
|
||||
// Objects.equals(messageRecord.getMessageStatus(), MessageStatusEnum.CANCELLED.getStatus())) {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// // 3. 处理状态变更
|
||||
// if (AdvertisementStatusEnum.PUBLISHED.getName().equals(message.getAction())) { // 待发布
|
||||
// if (ad.getStatus() == AdvertisementStatusEnum.UNPUBLISHED.getStatus() &&
|
||||
// LocalDateTime.now().isAfter(ad.getStartTime())) {
|
||||
// updateAdStatus(ad, messageRecord.getAdvertisementStatus());
|
||||
// }
|
||||
// } else if (AdvertisementStatusEnum.ENDED.getName().equals(message.getAction())) { // 待结束
|
||||
// if (ad.getStatus() == AdvertisementStatusEnum.PUBLISHED.getStatus() &&
|
||||
// LocalDateTime.now().isAfter(ad.getEndTime())) {
|
||||
// updateAdStatus(ad, messageRecord.getAdvertisementStatus());
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // 4. 标记消息为已处理
|
||||
// messageRecord.setMessageStatus(MessageStatusEnum.PROCESSED.getStatus());
|
||||
// advertisementTaskMapper.updateMessageStateByMessageId(message.getMessageId(),false, MessageStatusEnum.PROCESSED.getStatus());
|
||||
// }
|
||||
//
|
||||
// private void updateAdStatus(AdvertisementDO ad, Integer newStatus) {
|
||||
// advertisementMapper.updateAdStatus(ad.getId(), newStatus);
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
||||
Reference in New Issue
Block a user