|
|
|
|
@ -13,8 +13,11 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import org.springframework.transaction.support.TransactionTemplate;
|
|
|
|
|
import com.aucma.production.mapper.MrpComponentWeeklyReqMapper;
|
|
|
|
|
import com.aucma.production.mapper.MrpProdWeeklyPlanMapper;
|
|
|
|
|
import com.aucma.production.domain.MrpComponentWeeklyReq;
|
|
|
|
|
import com.aucma.production.domain.MrpProdWeeklyPlan;
|
|
|
|
|
import com.aucma.production.service.IMrpComponentWeeklyReqService;
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 子件物料周需求Service业务层处理
|
|
|
|
|
@ -28,6 +31,9 @@ public class MrpComponentWeeklyReqServiceImpl implements IMrpComponentWeeklyReqS
|
|
|
|
|
@Autowired
|
|
|
|
|
private MrpComponentWeeklyReqMapper mrpComponentWeeklyReqMapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private MrpProdWeeklyPlanMapper mrpProdWeeklyPlanMapper;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private TransactionTemplate transactionTemplate;
|
|
|
|
|
|
|
|
|
|
@ -163,12 +169,43 @@ public class MrpComponentWeeklyReqServiceImpl implements IMrpComponentWeeklyReqS
|
|
|
|
|
throw new ServiceException("没有有效的数据可导入!所有行的物料编码都为空。");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 新增:收集需要同步到周排产计划的数据
|
|
|
|
|
List<MrpProdWeeklyPlan> planListToInsert = new ArrayList<>();
|
|
|
|
|
for (MrpComponentWeeklyReq item : validList)
|
|
|
|
|
{
|
|
|
|
|
// 检查周排产计划表中是否已存在该itemCode + weekStartDate
|
|
|
|
|
MrpProdWeeklyPlan query = new MrpProdWeeklyPlan();
|
|
|
|
|
query.setItemCode(item.getItemCode());
|
|
|
|
|
query.setWeekStartDate(mondayDate);
|
|
|
|
|
List<MrpProdWeeklyPlan> existingPlans = mrpProdWeeklyPlanMapper.selectMrpProdWeeklyPlanList(query);
|
|
|
|
|
|
|
|
|
|
if (existingPlans == null || existingPlans.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
// 不存在则创建
|
|
|
|
|
MrpProdWeeklyPlan plan = convertToProdPlan(item);
|
|
|
|
|
planListToInsert.add(plan);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 逐条插入(Oracle INSERT ALL不支持SEQUENCE.NEXTVAL)
|
|
|
|
|
int total = validList.size();
|
|
|
|
|
int count = 0;
|
|
|
|
|
long startTime = System.currentTimeMillis();
|
|
|
|
|
System.out.println("开始导入子件物料周需求,共 " + total + " 条数据");
|
|
|
|
|
|
|
|
|
|
// 先插入周排产计划
|
|
|
|
|
int planInsertCount = 0;
|
|
|
|
|
for (MrpProdWeeklyPlan plan : planListToInsert)
|
|
|
|
|
{
|
|
|
|
|
mrpProdWeeklyPlanMapper.insertMrpProdWeeklyPlan(plan);
|
|
|
|
|
planInsertCount++;
|
|
|
|
|
}
|
|
|
|
|
if (planInsertCount > 0)
|
|
|
|
|
{
|
|
|
|
|
System.out.println("同步导入周排产计划 " + planInsertCount + " 条");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 再插入子件物料周需求
|
|
|
|
|
for (MrpComponentWeeklyReq item : validList)
|
|
|
|
|
{
|
|
|
|
|
mrpComponentWeeklyReqMapper.insertMrpComponentWeeklyReq(item);
|
|
|
|
|
@ -184,7 +221,11 @@ public class MrpComponentWeeklyReqServiceImpl implements IMrpComponentWeeklyReqS
|
|
|
|
|
long totalTime = (System.currentTimeMillis() - startTime) / 1000;
|
|
|
|
|
System.out.println("导入完成,共 " + total + " 条,总耗时 " + totalTime + " 秒");
|
|
|
|
|
|
|
|
|
|
String msg = "数据导入成功!共导入 " + total + " 条";
|
|
|
|
|
String msg = "数据导入成功!共导入 " + total + " 条子件物料需求";
|
|
|
|
|
if (planInsertCount > 0)
|
|
|
|
|
{
|
|
|
|
|
msg += ",同步导入周排产计划 " + planInsertCount + " 条";
|
|
|
|
|
}
|
|
|
|
|
if (skipNum > 0)
|
|
|
|
|
{
|
|
|
|
|
msg += ",跳过空行 " + skipNum + " 条";
|
|
|
|
|
@ -244,13 +285,53 @@ public class MrpComponentWeeklyReqServiceImpl implements IMrpComponentWeeklyReqS
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 新增:收集需要同步到周排产计划的数据
|
|
|
|
|
final Date finalMondayDate = mondayDate;
|
|
|
|
|
List<MrpProdWeeklyPlan> planListToInsert = new ArrayList<>();
|
|
|
|
|
for (MrpComponentWeeklyReq item : validList)
|
|
|
|
|
{
|
|
|
|
|
// 检查周排产计划表中是否已存在该itemCode + weekStartDate
|
|
|
|
|
MrpProdWeeklyPlan query = new MrpProdWeeklyPlan();
|
|
|
|
|
query.setItemCode(item.getItemCode());
|
|
|
|
|
query.setWeekStartDate(finalMondayDate);
|
|
|
|
|
List<MrpProdWeeklyPlan> existingPlans = mrpProdWeeklyPlanMapper.selectMrpProdWeeklyPlanList(query);
|
|
|
|
|
|
|
|
|
|
if (existingPlans == null || existingPlans.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
MrpProdWeeklyPlan plan = convertToProdPlan(item);
|
|
|
|
|
planListToInsert.add(plan);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 先插入周排产计划
|
|
|
|
|
int planInsertCount = 0;
|
|
|
|
|
if (!planListToInsert.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
transactionTemplate.execute(status -> {
|
|
|
|
|
for (MrpProdWeeklyPlan plan : planListToInsert)
|
|
|
|
|
{
|
|
|
|
|
mrpProdWeeklyPlanMapper.insertMrpProdWeeklyPlan(plan);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
});
|
|
|
|
|
planInsertCount = planListToInsert.size();
|
|
|
|
|
System.out.println("同步导入周排产计划 " + planInsertCount + " 条");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
System.out.println("同步周排产计划失败: " + e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int total = validList.size();
|
|
|
|
|
int batchSize = 500; // 每批500条提交一次事务
|
|
|
|
|
int successCount = 0;
|
|
|
|
|
int failCount = 0;
|
|
|
|
|
long startTime = System.currentTimeMillis();
|
|
|
|
|
|
|
|
|
|
System.out.println("开始分批导入,共 " + total + " 条,每批 " + batchSize + " 条");
|
|
|
|
|
System.out.println("开始分批导入子件物料需求,共 " + total + " 条,每批 " + batchSize + " 条");
|
|
|
|
|
|
|
|
|
|
// 分批处理,每批独立事务
|
|
|
|
|
for (int i = 0; i < total; i += batchSize)
|
|
|
|
|
@ -283,6 +364,33 @@ public class MrpComponentWeeklyReqServiceImpl implements IMrpComponentWeeklyReqS
|
|
|
|
|
|
|
|
|
|
long totalTime = (System.currentTimeMillis() - startTime) / 1000;
|
|
|
|
|
System.out.println("========== 异步导入完成 ==========");
|
|
|
|
|
System.out.println("总计: " + total + " 条,成功: " + successCount + ",失败: " + failCount + ",总耗时: " + totalTime + " 秒");
|
|
|
|
|
System.out.println("总计: " + total + " 条子件物料需求,成功: " + successCount + ",失败: " + failCount + ",同步周排产计划: " + planInsertCount + " 条,总耗时: " + totalTime + " 秒");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 将子件物料周需求转换为周排产计划
|
|
|
|
|
*/
|
|
|
|
|
private MrpProdWeeklyPlan convertToProdPlan(MrpComponentWeeklyReq req)
|
|
|
|
|
{
|
|
|
|
|
MrpProdWeeklyPlan plan = new MrpProdWeeklyPlan();
|
|
|
|
|
plan.setYearWeek(req.getYearWeek());
|
|
|
|
|
plan.setWeekStartDate(req.getWeekStartDate());
|
|
|
|
|
plan.setItemCode(req.getItemCode());
|
|
|
|
|
plan.setItemDesc(req.getItemDesc());
|
|
|
|
|
|
|
|
|
|
// 每日需求量映射
|
|
|
|
|
plan.setPlanD1(req.getReqMon());
|
|
|
|
|
plan.setPlanD2(req.getReqTue());
|
|
|
|
|
plan.setPlanD3(req.getReqWed());
|
|
|
|
|
plan.setPlanD4(req.getReqThu());
|
|
|
|
|
plan.setPlanD5(req.getReqFri());
|
|
|
|
|
plan.setPlanD6(req.getReqSat());
|
|
|
|
|
plan.setPlanD7(req.getReqSun());
|
|
|
|
|
|
|
|
|
|
// 默认值
|
|
|
|
|
plan.setSeqNo(new BigDecimal("1"));
|
|
|
|
|
plan.setCreatedAt(new Date());
|
|
|
|
|
|
|
|
|
|
return plan;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|