|
|
@ -1,7 +1,9 @@ |
|
|
package com.alteams.modules.shoporder.service.impl; |
|
|
package com.alteams.modules.shoporder.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
import com.alteams.common.utils.PageUtils; |
|
|
import com.alteams.common.utils.PageUtils; |
|
|
import com.alteams.common.utils.Query; |
|
|
import com.alteams.common.utils.Query; |
|
|
|
|
|
import java.nio.charset.Charset; |
|
|
import com.alteams.datasource.annotation.DataSource; |
|
|
import com.alteams.datasource.annotation.DataSource; |
|
|
import com.alteams.modules.ifsapp.vo.IfsShopOrderVo; |
|
|
import com.alteams.modules.ifsapp.vo.IfsShopOrderVo; |
|
|
import com.alteams.modules.shoporder.dao.ShopOrderDao; |
|
|
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.core.metadata.IPage; |
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import org.springframework.jdbc.UncategorizedSQLException; |
|
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
@ -36,14 +37,58 @@ public class ShopOrderServiceImpl extends ServiceImpl<ShopOrderDao, ShopOrderEnt |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
@Transactional |
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
public void removeAll(List<ShopOrderEntity> shopOrderEntities, IfsShopOrderVo ifsShopOrderVo) { |
|
|
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); |
|
|
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); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|