Browse Source

2026-02-03

定时任务ifsShopOrderTask优化
master
fengyuan_yang 4 weeks ago
parent
commit
d5367e1c0d
  1. 28
      src/main/java/com/alteams/modules/job/task/IfsShopOrderTask.java
  2. 2
      src/main/java/com/alteams/modules/shoporder/entity/ShopOrderEntity.java
  3. 59
      src/main/java/com/alteams/modules/shoporder/service/impl/ShopOrderServiceImpl.java

28
src/main/java/com/alteams/modules/job/task/IfsShopOrderTask.java

@ -7,6 +7,7 @@ import com.alteams.modules.ifsapp.service.IfsShopOrderService;
import com.alteams.modules.ifsapp.vo.IfsShopOrderVo;
import com.alteams.modules.shoporder.entity.ShopOrderEntity;
import com.alteams.modules.shoporder.service.ShopOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@ -15,10 +16,11 @@ import java.util.stream.Collectors;
/**
* @Classname IfsShopOrderTask
* @Description TODO
* @Description Sync shop order data from IFS
* @Date 2022/9/29 9:25
* @Created by sxm
*/
@Slf4j
@Component("ifsShopOrderTask")
public class IfsShopOrderTask implements ITask {
@Autowired
@ -29,16 +31,30 @@ public class IfsShopOrderTask implements ITask {
@Override
public String run(String params) {
IfsShopOrderVo ifsShopOrderVo = JSONUtil.toBean(params,IfsShopOrderVo.class);
log.info("=== IfsShopOrderTask START === params: {}", params);
IfsShopOrderVo ifsShopOrderVo = JSONUtil.toBean(params, IfsShopOrderVo.class);
log.info("Query condition: contract={}, dateEntered={}", ifsShopOrderVo.getContract(), ifsShopOrderVo.getDateEntered());
List<IfsShopOrderVo> shopOrderOperationList = ifsShopOrderService.getTaskShopOrderOperationList(ifsShopOrderVo);
if (CollectionUtil.isNotEmpty(shopOrderOperationList)){
log.info("Query from IFS completed, total {} records", shopOrderOperationList != null ? shopOrderOperationList.size() : 0);
if (CollectionUtil.isNotEmpty(shopOrderOperationList)) {
List<ShopOrderEntity> shopOrderEntities = shopOrderOperationList.stream().map(item -> {
ShopOrderEntity shopOrderEntity = new ShopOrderEntity();
BeanUtil.copyProperties(item,shopOrderEntity);
BeanUtil.copyProperties(item, shopOrderEntity);
// Handle field name case mismatch manually (objState -> objstate)
shopOrderEntity.setObjstate(item.getObjState());
return shopOrderEntity;
}).collect(Collectors.toList());
shopOrderService.removeAll(shopOrderEntities,ifsShopOrderVo);
log.info("Start sync {} records to local database", shopOrderEntities.size());
shopOrderService.removeAll(shopOrderEntities, ifsShopOrderVo);
log.info("=== IfsShopOrderTask END === Sync completed successfully");
} else {
log.info("=== IfsShopOrderTask END === No data to sync");
}
return "执行成功";
return "Sync completed successfully";
}
}

2
src/main/java/com/alteams/modules/shoporder/entity/ShopOrderEntity.java

@ -37,7 +37,7 @@ public class ShopOrderEntity implements Serializable {
/**
* 工序号
*/
private String operationNo;
private Integer operationNo;
/**
* 工序描述
*/

59
src/main/java/com/alteams/modules/shoporder/service/impl/ShopOrderServiceImpl.java

@ -1,7 +1,9 @@
package com.alteams.modules.shoporder.service.impl;
import cn.hutool.core.util.StrUtil;
import com.alteams.common.utils.PageUtils;
import com.alteams.common.utils.Query;
import java.nio.charset.Charset;
import com.alteams.datasource.annotation.DataSource;
import com.alteams.modules.ifsapp.vo.IfsShopOrderVo;
import com.alteams.modules.shoporder.dao.ShopOrderDao;
@ -12,7 +14,6 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.jdbc.UncategorizedSQLException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -36,14 +37,58 @@ public class ShopOrderServiceImpl extends ServiceImpl<ShopOrderDao, ShopOrderEnt
}
@Override
@Transactional
@Transactional(rollbackFor = Exception.class)
public void removeAll(List<ShopOrderEntity> shopOrderEntities, IfsShopOrderVo ifsShopOrderVo) {
log.info("Step 1: Delete old data, contract={}, dateEntered={}", ifsShopOrderVo.getContract(), ifsShopOrderVo.getDateEntered());
this.baseMapper.removeAll(ifsShopOrderVo);
try{
this.saveBatch(shopOrderEntities,1000);
log.info("同步数据成功");
}catch (UncategorizedSQLException e){
log.info(e.getMessage());
log.info("Step 1: Delete old data completed");
// Validate field lengths before insert to identify which field causes the error
// Field lengths based on dbo.shop_order table structure
log.info("Step 2: Validate field lengths for {} records", shopOrderEntities.size());
int index = 0;
for (ShopOrderEntity entity : shopOrderEntities) {
index++;
// Field lengths based on dbo.shop_order table structure (must match exactly!)
validateFieldLength("contract", entity.getContract(), 20, entity, index);
validateFieldLength("orderNo", entity.getOrderNo(), 50, entity, index);
validateFieldLength("releaseNo", entity.getReleaseNo(), 20, entity, index);
validateFieldLength("sequenceNo", entity.getSequenceNo(), 20, entity, index);
validateFieldLength("operationDescription", entity.getOperationDescription(), 100, entity, index);
validateFieldLength("workCenterNo", entity.getWorkCenterNo(), 50, entity, index);
validateFieldLength("workCenterDesc", entity.getWorkCenterDesc(), 100, entity, index);
validateFieldLength("objstate", entity.getObjstate(), 50, entity, index);
validateFieldLength("orderCodeDb", entity.getOrderCodeDb(), 50, entity, index);
validateFieldLength("partNo", entity.getPartNo(), 50, entity, index);
validateFieldLength("partDesc", entity.getPartDesc(), 400, entity, index);
validateFieldLength("manufEngineer", entity.getManufEngineer(), 50, entity, index);
validateFieldLength("typeDesignation", entity.getTypeDesignation(), 50, entity, index);
}
log.info("Step 2: Validate field lengths completed, all {} records passed", shopOrderEntities.size());
log.info("Step 3: Start batch insert {} records", shopOrderEntities.size());
this.saveBatch(shopOrderEntities, 500);
log.info("Step 3: Batch insert completed successfully, total {} records", shopOrderEntities.size());
}
/**
* Validate field length, throw exception if exceeds max length
* SQL Server varchar with Chinese_PRC_CI_AS uses GBK encoding (bytes, not characters)
*/
private void validateFieldLength(String fieldName, String value, int maxLength, ShopOrderEntity entity, int rowIndex) {
if (StrUtil.isNotBlank(value)) {
int charLength = value.length();
// SQL Server varchar uses GBK encoding for Chinese_PRC_CI_AS collation
int byteLength = value.getBytes(Charset.forName("GBK")).length;
if (byteLength > maxLength) {
String errorMsg = String.format(
"Field BYTE length exceeded! rowIndex=%d, field=[%s], maxBytes=%d, actualBytes=%d, charLength=%d, value=[%s], orderNo=%s, releaseNo=%s, sequenceNo=%s, operationNo=%s, partNo=%s",
rowIndex, fieldName, maxLength, byteLength, charLength, value,
entity.getOrderNo(), entity.getReleaseNo(), entity.getSequenceNo(), entity.getOperationNo(), entity.getPartNo());
log.error(errorMsg);
throw new RuntimeException(errorMsg);
}
}
}

Loading…
Cancel
Save