编写同步出库计划代码

This commit is contained in:
刘名喜 2024-11-28 16:45:01 +08:00
parent 9705df6be2
commit ada2cb73ac

View File

@ -9,10 +9,13 @@ import com.ktg.mes.md.mapper.*;
import com.ktg.mes.md.service.IWmsOutPlanService;
import com.ktg.mes.wm.domain.WmStorageArea;
import com.ktg.mes.wm.mapper.WmStorageAreaMapper;
import com.ktg.mes.wm.mapper.WmStorageLocationMapper;
import com.ktg.mes.wm.mapper.WmWarehouseMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
@ -44,10 +47,16 @@ public class WmsOutPlanServiceImpl implements IWmsOutPlanService {
private MdItemMapper mdItemMapper;
@Autowired
private WmStorageAreaMapper wmStorageAreaMapper;
private AP0AEMapper ap0AEMapper;
@Autowired
private AP0AEMapper ap0AEMapper;
private WmWarehouseMapper wmWarehouseMapper;
@Autowired
private WmStorageLocationMapper wmStorageLocationMapper;
@Autowired
private WmStorageAreaMapper wmStorageAreaMapper;
/**
* 查询出库计划管理
@ -266,19 +275,134 @@ public class WmsOutPlanServiceImpl implements IWmsOutPlanService {
return hashMapList;
}
@Transactional
@Override
public int synchronizationMiniBox(String username) {
// 获得全部未记录的小货柜出库数据
HashMap<String, List<AP0AE>> ap0aeDateMap = new HashMap<>();
List<AP0AE> ap0AEList = ap0AEMapper.selectOutNewData();
System.out.println("=========================================");
System.out.println(JSON.toJSONString(ap0AEList));
System.out.println("=========================================");
ap0AEList.forEach(ap0AE -> {
String dateKey = new SimpleDateFormat("yyyy-MM-dd").format(ap0AE.getDATE01());
ap0aeDateMap.computeIfAbsent(dateKey, k -> new ArrayList<>());
ap0aeDateMap.get(dateKey).add(ap0AE);
});
List<WmsOutPlan> wmsOutPlanList = wmsOutPlanMapper.selectWmsOutPlanList(new WmsOutPlan());
System.out.println("=========================================");
System.out.println(JSON.toJSONString(wmsOutPlanList));
System.out.println("=========================================");
// 根据日期进行分组遍历
ap0aeDateMap.keySet().forEach(dateKey -> {
Date itemDate = new Date();
try {
itemDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(dateKey + " 00:00:00");
} catch (ParseException ignored) {
}
return 0;
// 构建出库计划
WmsOutPlan wmsOutPlan = new WmsOutPlan();
wmsOutPlan.setPlanCode(Long.toString(System.currentTimeMillis(), 32).toUpperCase(Locale.ROOT));
wmsOutPlan.setWmsBusinessTypeId(this.wmsBusinessTypeMapper.selectWmsBusinessTypeByCode("DPCK").getTypeId() != null ? Long.parseLong(this.wmsBusinessTypeMapper.selectWmsBusinessTypeByCode("DPCK").getTypeId()) : 11L);
wmsOutPlan.setPlanState("1");
wmsOutPlan.setPlanType("XTTB");
wmsOutPlan.setRemark("同步小型刀具库数据");
wmsOutPlan.setCreateBy(username);
wmsOutPlan.setCreateTime(itemDate);
wmsOutPlanMapper.insertWmsOutPlan(wmsOutPlan);
// 构建出库计划明细
ap0aeDateMap.get(dateKey).forEach(ap0AE -> {
// 获得物料对象
MdItem mdItem = mdItemMapper.selectMdItemByCode(ap0AE.getAE014());
if (mdItem == null) return;
// 获得库位对象
WmStorageArea wmStorageArea = wmStorageAreaMapper.selectWmStorageAreaByAreaCode(ap0AE.getAE020());
if (wmStorageArea == null) return;
// 构建出库计划明细
WmsOutPlanDetail wmsOutPlanDetail = new WmsOutPlanDetail();
wmsOutPlanDetail.setWmsOutPlanId(wmsOutPlan.getWmsOutPlanId());
wmsOutPlanDetail.setMdItemId(mdItem.getItemId());
wmsOutPlanDetail.setMdItemCode(mdItem.getItemCode());
wmsOutPlanDetail.setMdItemName(mdItem.getItemName());
wmsOutPlanDetail.setMdItemUnit(mdItem.getUnitName());
wmsOutPlanDetail.setPlannedQuantity((int) ap0AE.getAE017().doubleValue());
wmsOutPlanDetail.setRealQuantity((int) ap0AE.getAE017().doubleValue());
wmsOutPlanDetail.setDetailBatchNum("1");
wmsOutPlanDetail.setWmStorageAreaId(wmStorageArea.getAreaId());
wmsOutPlanDetail.setWmStorageAreaCode(wmStorageArea.getAreaCode());
wmsOutPlanDetail.setWmStorageAreaName(wmStorageArea.getAreaName());
wmsOutPlanDetail.setDetailState("1");
wmsOutPlanDetail.setRemark("同步小型刀具库数据");
wmsOutPlanDetail.setCreateBy(username);
wmsOutPlanDetail.setCreateTime(ap0AE.getDATE01());
wmsOutPlanMapper.insertWmsOutPlanDetail(wmsOutPlanDetail);
// 获得该出库计划子项对应的工具台账实体
List<BaseKnife> baseKnifeList = this.baseKnifeMapper.selectBaseKnifeListByMbbBdMrlIdAndAreaCodeAndKnifeFineStateAndIsLocked(
wmsOutPlanDetail.getMdItemId(),
wmsOutPlanDetail.getWmStorageAreaCode(),
0
);
// 校验库中数量是否足够
if (baseKnifeList.size() < wmsOutPlanDetail.getPlannedQuantity()) {
throw new RuntimeException("库存数量不足以支持本次出库");
}
// 开始遍历出库计划子项
baseKnifeList.subList(0, wmsOutPlanDetail.getPlannedQuantity()).forEach(baseKnife -> {
// 构建出库计划明细实体
WmsOutPlanDetailEntity wmsOutPlanDetailEntity = new WmsOutPlanDetailEntity();
wmsOutPlanDetailEntity.setWmsOutPlanDetailId(wmsOutPlanDetail.getWmsOutPlanDetailId());
wmsOutPlanDetailEntity.setBaseKnifeId(baseKnife.getBaseKnifeId());
wmsOutPlanDetailEntity.setAreaCode(baseKnife.getAreaCode());
wmsOutPlanDetailEntity.setItemOrProduct(baseKnife.getItemOrProduct());
wmsOutPlanDetailEntity.setKnifeCode(baseKnife.getKnifeCode());
wmsOutPlanDetailEntity.setKnifeName(baseKnife.getKnifeName());
wmsOutPlanDetailEntity.setPlanSheet(baseKnife.getPlanSheet());
wmsOutPlanDetailEntity.setKnifeLife(baseKnife.getKnifeLife());
wmsOutPlanDetailEntity.setResetCount(baseKnife.getResetCount());
wmsOutPlanDetailEntity.setKnifeUnit(baseKnife.getKnifeUnit());
wmsOutPlanDetailEntity.setSafeStock(baseKnife.getKnifeType());
wmsOutPlanDetailEntity.setStandardQuantity(baseKnife.getStandardQuantity());
// 插入出库计划明细实体
this.wmsOutPlanDetailEntityMapper.insertWmsOutPlanDetailEntity(wmsOutPlanDetailEntity);
// 锁定工具台账中的物料实体
this.baseKnifeMapper.updateBaseKnifeIsLockedByBaseKnifeId(baseKnife.getBaseKnifeId(), 1);
// 锁定并出库台账明细实体
this.baseKnifeMapper.updateBaseKnifeKnifeFineStateAndIsLockedByBaseKnifeId(
wmsOutPlanDetailEntity.getBaseKnifeId(),
2,
1
);
});
// 构建出库任务
WmsOutTask wmsOutTask = new WmsOutTask();
wmsOutTask.setWmsOutPlanId(wmsOutPlan.getWmsOutPlanId());
wmsOutTask.setWmsOutPlanCode(wmsOutPlan.getPlanCode());
wmsOutTask.setWmsOutPlanDetailId(wmsOutPlanDetail.getWmsOutPlanDetailId());
wmsOutTask.setWmsBusinessTypeId(wmsOutPlan.getWmsBusinessTypeId());
wmsOutTask.setTaskCode(new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date()));
wmsOutTask.setTaskNumber(wmsOutPlanDetail.getPlannedQuantity());
wmsOutTask.setOutNumber(wmsOutPlanDetail.getPlannedQuantity());
wmsOutTask.setWmStorageAreaId(wmsOutPlanDetail.getWmStorageAreaId());
wmsOutTask.setBatchNum(wmsOutPlanDetail.getDetailBatchNum());
wmsOutTask.setMdItemId(wmsOutPlanDetail.getMdItemId());
wmsOutTask.setMdItemCode(wmsOutPlanDetail.getMdItemCode());
wmsOutTask.setMdItemName(wmsOutPlanDetail.getMdItemName());
wmsOutTask.setMdItemUnit(wmsOutPlanDetail.getMdItemUnit());
wmsOutTask.setTaskState("1");
wmsOutTask.setRecipientUsername(wmsOutPlan.getRecipientUsername());
wmsOutTask.setCreateTime(new Date());
// 插入出库任务
this.wmsOutTaskMapper.insertWmsOutTask(wmsOutTask);
});
});
return 1;
}
@Transactional