|
@@ -1,16 +1,35 @@
|
|
|
package com.zkqy.amichi.scheduling;
|
|
|
|
|
|
+import com.alibaba.fastjson2.JSON;
|
|
|
+import com.kingdee.bos.webapi.sdk.K3CloudApi;
|
|
|
import com.zkqy.amichi.domain.MaterialBaseInfo;
|
|
|
+import com.zkqy.amichi.domain.PlanTaskDetails;
|
|
|
+import com.zkqy.amichi.domain.ProductionPlanningManagement;
|
|
|
+import com.zkqy.amichi.jd.domain.JdMaterialBaseInfoVo;
|
|
|
+import com.zkqy.amichi.jd.domain.JdProductionOrder;
|
|
|
+import com.zkqy.amichi.jd.domain.ProductionCardFlowVo;
|
|
|
+import com.zkqy.amichi.jd.mapper.JdProductionOrderMapper;
|
|
|
import com.zkqy.amichi.jd.service.impl.JdMaterialInfoServiceImpl;
|
|
|
import com.zkqy.amichi.jd.service.impl.JdProductionOrderServiceImpl;
|
|
|
import com.zkqy.amichi.mapper.MaterialBaseInfoMapper;
|
|
|
+import com.zkqy.amichi.mapper.PlanTaskDetailsMapper;
|
|
|
+import com.zkqy.amichi.mapper.ProductionCardFlowMapper;
|
|
|
+import com.zkqy.amichi.mapper.ProductionPlanningManagementMapper;
|
|
|
+import com.zkqy.amichi.utils.AmichiCommissionNumberGenerator;
|
|
|
import com.zkqy.common.core.domain.AjaxResult;
|
|
|
+import com.zkqy.common.utils.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
@@ -26,18 +45,444 @@ public class ScheduledBean {
|
|
|
@Autowired
|
|
|
JdProductionOrderServiceImpl productionOrderService;
|
|
|
|
|
|
- @Scheduled(cron = "0 0/1 0/1 * * ?")
|
|
|
- public void printLog(){
|
|
|
-// //物料基本信息--防止流转卡信息缺失
|
|
|
-// AjaxResult ajaxResult = materialInfoService.pullMaterialBaseInfo();
|
|
|
-// System.out.println(ajaxResult);
|
|
|
-// //流转卡序列号信息
|
|
|
-// AjaxResult ajaxResult1 = productionOrderService.jdProductionOrderPull();
|
|
|
-// System.out.println(ajaxResult1);
|
|
|
-// //焊接单数据信息
|
|
|
-// AjaxResult ajaxResult2 = productionOrderService.pullWeldProductionOrder();
|
|
|
-// System.out.println(ajaxResult2);
|
|
|
-// System.out.println(Thread.currentThread().getName()+":run...");
|
|
|
+ @Autowired
|
|
|
+ private JdProductionOrderMapper jdProductionOrderMapper;
|
|
|
+ @Autowired
|
|
|
+ private ProductionPlanningManagementMapper productionPlanningManagementMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PlanTaskDetailsMapper planTaskDetailsMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private AmichiCommissionNumberGenerator generator;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ProductionCardFlowMapper productionCardFlowMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private JdMaterialInfoServiceImpl jdMaterialInfoService;
|
|
|
+
|
|
|
+ //============================正常计划数据定时拉取============================
|
|
|
+ /**
|
|
|
+ * // //物料基本信息--防止流转卡信息缺失
|
|
|
+ * // AjaxResult ajaxResult = materialInfoService.pullMaterialBaseInfo();
|
|
|
+ * // System.out.println(ajaxResult);
|
|
|
+ * // //流转卡序列号信息
|
|
|
+ * // AjaxResult ajaxResult1 = productionOrderService.jdProductionOrderPull();
|
|
|
+ * // System.out.println(ajaxResult1);
|
|
|
+ * // //焊接单数据信息
|
|
|
+ * // AjaxResult ajaxResult2 = productionOrderService.pullWeldProductionOrder();
|
|
|
+ * // System.out.println(ajaxResult2);
|
|
|
+ * // System.out.println(Thread.currentThread().getName()+":run...");
|
|
|
+ */
|
|
|
+ @Scheduled(cron = "0 0/5 * * * ?", zone = "Asia/Shanghai")
|
|
|
+ public void printLog1(){
|
|
|
+ //物料基本数据
|
|
|
+ AjaxResult ajaxResult = this.pullMaterialBaseInfo();
|
|
|
+ //金蝶工具key
|
|
|
+ K3CloudApi api = new K3CloudApi();
|
|
|
+ //定义查询条件
|
|
|
+ String query="{\n" +
|
|
|
+ " \"FormId\": \"PRD_MO\",\n" +
|
|
|
+ " \"FieldKeys\": \"FDescription,F_PONP_teshuyaoqiu,FBillNo,FBillType,FDate,FDocumentStatus," +
|
|
|
+ "FProductType,FMaterialId,FWorkShopID0,FQty,FStatus,FSaleOrderNo,FPickMtrlStatus," +
|
|
|
+ "FMaterialId.FNumber,FMaterialName,F_PONP_BaseProperty,FSpecification,FUnitId.FName,F_PONP_yanse,F_PONP_mingpai,F_PONP_hegezheng.FDataValue," +
|
|
|
+ "F_PONP_shuomingshu.FDataValue,F_PONP_KaiGuanXiang,F_PONP_baozhuangxiang,F_PONP_GongLv,FPlanFinishDate,FPlanStartDate,F_PONP_XQRQ,FPlanStartDate,FPlanFinishDate\",\n" +
|
|
|
+ " \"FilterString\": [{\"Left\":\"\",\"FieldName\":\"FMaterialId.FNumber\",\"Compare\":\"34\",\"Value\":\"焊\",\"Right\":\"\",\"Logic\":0},{\"Left\":\"\",\"FieldName\":\"FStatus\",\"Compare\":\"105\",\"Value\":\"4\",\"Right\":\"\",\"Logic\":0},{\"Left\":\"\",\"FieldName\":\"FCreateDate\",\"Compare\":\"13\",\"Value\":\"\",\"Right\":\"\",\"Logic\":0}],\n" +
|
|
|
+ " \"OrderString\": \"\",\n" +
|
|
|
+ " \"TopRowCount\": 0,\n" +
|
|
|
+ " \"StartRow\": 0,\n" +
|
|
|
+ " \"Limit\": 5000,\n" +
|
|
|
+ " \"SubSystemId\": \"\"\n" +
|
|
|
+ "}";
|
|
|
+//
|
|
|
+ try {
|
|
|
+ //查询结果
|
|
|
+ String resultJson = api.billQuery(query);
|
|
|
+ //生产信息
|
|
|
+ List<JdProductionOrder> jdProductionOrders = JSON.parseArray(resultJson, JdProductionOrder.class);
|
|
|
+ //查询系统中的订单信息
|
|
|
+ ProductionPlanningManagement productionPlanningManagement1=new ProductionPlanningManagement();
|
|
|
+ productionPlanningManagement1.setIsWeldSheet("1");
|
|
|
+ List<ProductionPlanningManagement> productionPlanningManagements = productionPlanningManagementMapper.selectProductionPlanningManagementList(productionPlanningManagement1);
|
|
|
+ List<String> collectTwo = productionPlanningManagements.stream().map(ProductionPlanningManagement::getOrderNumber).collect(Collectors.toSet())
|
|
|
+ .stream().collect(Collectors.toList());
|
|
|
+
|
|
|
+
|
|
|
+ Map<String, List<JdProductionOrder>> groupedByDemandDocument = jdProductionOrders.stream()
|
|
|
+ .filter(item -> !collectTwo.contains(item.getDemandDocument()))
|
|
|
+ .collect(Collectors.groupingBy(JdProductionOrder::getDemandDocument));
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+ if(groupedByDemandDocument.size()>0){
|
|
|
+ //订单循环
|
|
|
+ groupedByDemandDocument.forEach((k,v)->{
|
|
|
+ ProductionPlanningManagement productionPlanningManagement=new ProductionPlanningManagement();
|
|
|
+ //编号订单号
|
|
|
+ productionPlanningManagement.setOrderNumber(k);
|
|
|
+ //计划编号
|
|
|
+ String planNumnber = generator.generateCommissionNumber();
|
|
|
+ productionPlanningManagement.setPlanNumber(planNumnber);
|
|
|
+ productionPlanningManagement.setPlanType("0"); //待生产
|
|
|
+ productionPlanningManagement.setTaskStatus("4");//待排产
|
|
|
+ productionPlanningManagement.setIsWeldSheet("1");//焊接订单
|
|
|
+ if(StringUtils.isNotNull(v.get(0).getCompletionTime())){
|
|
|
+ productionPlanningManagement.setCompletionTime(v.get(0).getCompletionTime());//完成时间
|
|
|
+ }
|
|
|
+ //备注
|
|
|
+ if(StringUtils.isNotNull(v.get(0).getRemark())){
|
|
|
+ productionPlanningManagement.setRemark(v.get(0).getRemark()); //备注
|
|
|
+ }
|
|
|
+ //单据类型
|
|
|
+ if(StringUtils.isNotNull(v.get(0).getDocumentTyep())){
|
|
|
+ productionPlanningManagement.setOrderType(v.get(0).getDocumentTyep()); //单据类型
|
|
|
+ }
|
|
|
+ //订单的创建时间
|
|
|
+ productionPlanningManagement.setCreationtimeString(v.get(0).getCreationtimeString());//单据的创建时间
|
|
|
+ //特殊要求
|
|
|
+ if(StringUtils.isNotNull(v.get(0).getTsyq())){
|
|
|
+ productionPlanningManagement.setSpecialRequirements(v.get(0).getTsyq());//特殊要求
|
|
|
+ }
|
|
|
+
|
|
|
+ //编号订单号
|
|
|
+ List<Map> mapList = this.jdSalesOrderInfoS(k);//订单详情信息
|
|
|
+ String fDeliveryDate;
|
|
|
+ if(mapList.size()>0){
|
|
|
+ fDeliveryDate = mapList.get(0).get("FDeliveryDate").toString();
|
|
|
+ } else {
|
|
|
+ fDeliveryDate = "";
|
|
|
+ }
|
|
|
+ //拿到了关于这个订单的销售订单
|
|
|
+ if(mapList.size()>0){
|
|
|
+ if(StringUtils.isNotNull(mapList.get(0).get("F.PONP.Text"))){
|
|
|
+ productionPlanningManagement.setContractNumber(mapList.get(0).get("F.PONP.Text").toString());
|
|
|
+ }
|
|
|
+ productionPlanningManagement.setCompletionTime(fDeliveryDate);
|
|
|
+ //======处理基本的订单信息
|
|
|
+ productionPlanningManagementMapper.insertProductionPlanningManagement(productionPlanningManagement);
|
|
|
+ v.forEach(a->{
|
|
|
+ PlanTaskDetails planTaskDetails=new PlanTaskDetails();
|
|
|
+ planTaskDetails.setDemandDocument(a.getDocumentNumber());//需求单据号
|
|
|
+ planTaskDetails.setPlanId(productionPlanningManagement.getId());//计划id
|
|
|
+ planTaskDetails.setMaterialId(a.getMaterialCode());//原材料编码
|
|
|
+ planTaskDetails.setMaterialName(a.getMaterialName());//名称
|
|
|
+ planTaskDetails.setQuantity(a.getQuantity());//数量
|
|
|
+// planTaskDetails.setTimeOfRequest(a.getCompletionTime());//要货时间
|
|
|
+ planTaskDetails.setModelNumber(a.getModelNumber());//型号
|
|
|
+ planTaskDetails.setSpecification(a.getSpecification());//规格
|
|
|
+ planTaskDetails.setMaterialUnit(a.getUnit());//单位
|
|
|
+ planTaskDetails.setPower(a.getGl());//功率
|
|
|
+ planTaskDetails.setVoltage(a.getDianYaPinLv());//电压频率
|
|
|
+ planTaskDetails.setColour(a.getYanse());//颜色
|
|
|
+ planTaskDetails.setMingpai(a.getMingpai());//铭牌
|
|
|
+ planTaskDetails.setShuomingshu(a.getShuomingshu());//说明书
|
|
|
+ planTaskDetails.setHegezheng(a.getHegezheng());//合格证
|
|
|
+ planTaskDetails.setBaozhuangxiang(a.getBaozhuangxiang());//包装箱
|
|
|
+ planTaskDetails.setSwitchBox(a.getKaiguanxiang());//开关箱
|
|
|
+ planTaskDetails.setScheduledCommencement(a.getFPlanStartDate()); //计划开始时间
|
|
|
+ planTaskDetails.setScheduledCompletion(a.getFPlanFinishDate()); //计划完工时间
|
|
|
+ planTaskDetails.setRemark(a.getRemark());
|
|
|
+ if(StringUtils.isNotNull(a.getDocumentDate())){
|
|
|
+ SimpleDateFormat formatter1= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ String formattedDate = formatter1.format(a.getDocumentDate());
|
|
|
+ planTaskDetails.setTimeOfRequest(formattedDate);
|
|
|
+ }
|
|
|
+
|
|
|
+ planTaskDetailsMapper.insertPlanTaskDetails(planTaskDetails);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ //处理订单序列号问题
|
|
|
+ groupedByDemandDocument.forEach((k,v)->{
|
|
|
+ String stringQuery="{\n" +
|
|
|
+ " \"FormId\": \"PRD_MO\",\n" +
|
|
|
+ " \"FieldKeys\": \"FBillNo,FSNQty1,FSaleOrderNo,FSerialNo\",\n" +
|
|
|
+ " \"FilterString\": [{\"Left\":\"\",\"FieldName\":\"FMaterialId.FNumber\",\"Compare\":\"34\",\"Value\":\"焊\",\"Right\":\"\",\"Logic\":0},{\"Left\":\"\",\"FieldName\":\"FStatus\",\"Compare\":\"105\",\"Value\":\"4\",\"Right\":\"\",\"Logic\":0},{\"Left\":\"\",\"FieldName\":\"FSaleOrderNo\",\"Compare\":\"67\",\"Value\":\""+k+"\",\"Right\":\"\",\"Logic\":0}],\n" +
|
|
|
+ " \"OrderString\": \"\",\n" +
|
|
|
+ " \"TopRowCount\": 0,\n" +
|
|
|
+ " \"StartRow\": 0,\n" +
|
|
|
+ " \"Limit\": 2000,\n" +
|
|
|
+ " \"SubSystemId\": \"\"\n" +
|
|
|
+ "}";
|
|
|
+ try {
|
|
|
+ String xlhString = api.billQuery(stringQuery);
|
|
|
+ if(!xlhString.equals("[]")){
|
|
|
+ List<ProductionCardFlowVo> mapList1 = JSON.parseArray(xlhString, ProductionCardFlowVo.class);
|
|
|
+ int i = productionCardFlowMapper.insertProductionCardFlowBatchVo(mapList1);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //基础物料信息添加
|
|
|
+ public AjaxResult pullMaterialBaseInfo() {
|
|
|
+ String queryString ="{\n" +
|
|
|
+ " \"FormId\": \"BD_MATERIAL\",\n" +
|
|
|
+ " \"FieldKeys\": \"FNumber,FName,FSpecification,FDescription,F_PONP_model,F_PONP_TieXinChangDu,F_PONP_JiKeDuanGai,F_PONP_ShuJu,F_PONP_xiangshu,F_PONP_YanSe,F_PONP_ShuoMingShu,F_PONP_HeGeZheng,F_PONP_PanPianJieKou,F_PONP_GongLv,F_PONP_ChengPinMa,F_PONP_MingPai,F_PONP_DianYaPinLv,F_PONP_KaiGuanXiang,F_PONP_TeShuYaoQiu,F_PONP_TeShuYaoQiu,F_PONP_BaoZhuangXiang\",\n" +
|
|
|
+ " \"FilterString\": [{\"Left\":\"\",\"FieldName\":\"FCreateDate\",\"Compare\":\"13\",\"Value\":\"\",\"Right\":\"\",\"Logic\":0}],\n" +
|
|
|
+ " \"OrderString\": \"\",\n" +
|
|
|
+ " \"TopRowCount\": 0,\n" +
|
|
|
+ " \"StartRow\": 0,\n" +
|
|
|
+ " \"Limit\": 3000,\n" +
|
|
|
+ " \"SubSystemId\": \"\"\n" +
|
|
|
+ "}";
|
|
|
+ //查询条件
|
|
|
+ Map map = JSON.parseObject(queryString, Map.class);
|
|
|
+ K3CloudApi api = new K3CloudApi();
|
|
|
+ int startRow = 0; // 起始行号
|
|
|
+ int limit = 3000; // 每次查询的数量
|
|
|
+ List<JdMaterialBaseInfoVo> mapList;
|
|
|
+ boolean flag = true;
|
|
|
+ //验证重复
|
|
|
+ MaterialBaseInfo materialBaseInfo=new MaterialBaseInfo();
|
|
|
+ List<MaterialBaseInfo> materialBaseInfos = materialBaseInfoMapper.selectMaterialBaseInfoListCode(materialBaseInfo);
|
|
|
+ List<String> collect = materialBaseInfos.parallelStream().map(MaterialBaseInfo::getMaterialCode).collect(Collectors.toList());
|
|
|
+ try {
|
|
|
+ do {
|
|
|
+ // 更新查询条件中的起始行号
|
|
|
+ map.put("StartRow", String.valueOf(startRow));
|
|
|
+ // 查询数据
|
|
|
+ String resultJson = api.billQuery(JSON.toJSONString(map));
|
|
|
+
|
|
|
+ if (resultJson.isEmpty()||resultJson.equals("[]")) {
|
|
|
+ // 处理空结果的情况
|
|
|
+ flag = false;
|
|
|
+ }else {
|
|
|
+ mapList = JSON.parseArray(resultJson, JdMaterialBaseInfoVo.class);
|
|
|
+ List<JdMaterialBaseInfoVo> collect1 = mapList.stream().filter(item -> !collect.contains(item.getMaterialCode())).collect(Collectors.toList());
|
|
|
+ // 处理数据(例如插入到数据库)
|
|
|
+ if(collect1.size()>0){
|
|
|
+ int i = materialBaseInfoMapper.batchInsertMaterialBaseInfo(collect1);
|
|
|
+ }
|
|
|
+ if (mapList.size() < 3000) {
|
|
|
+ flag = false;
|
|
|
+ }
|
|
|
+ // 更新起始行号
|
|
|
+ startRow += limit;
|
|
|
+ // 如果返回的数据量小于5000,说明已经没有更多的数据,结束循环
|
|
|
+ }
|
|
|
+ } while (flag);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ //abc
|
|
|
+ return AjaxResult.success("基础物料信息拉取成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ //查询销售明细
|
|
|
+ public List<Map> jdSalesOrderInfoS(String orderNumber){
|
|
|
+ K3CloudApi api = new K3CloudApi();
|
|
|
+ //查询内容
|
|
|
+ HashMap queryNR=new HashMap();
|
|
|
+ queryNR.put("FormId","SAL_SaleOrder");
|
|
|
+ List<String> fieldKeysList=new ArrayList<>();
|
|
|
+ fieldKeysList.add("FBillNo"); //单据号
|
|
|
+ fieldKeysList.add("F_PONP_Text"); //合同号
|
|
|
+ fieldKeysList.add("FCreateDate"); //创建时间
|
|
|
+ fieldKeysList.add("FNote"); //备注
|
|
|
+ fieldKeysList.add("F_PONP_Remarks1");//特殊要求
|
|
|
+ fieldKeysList.add("F_PONP_DATETIME");//要货日期
|
|
|
+ fieldKeysList.add("FDeliveryDate");//要货日期
|
|
|
+ fieldKeysList.add("FMaterialId.FNumber");//物料编码
|
|
|
+ fieldKeysList.add("FMaterialName");//物料编码
|
|
|
+ fieldKeysList.add("F_PONP_BaseProperty");//属性
|
|
|
+ fieldKeysList.add("FMaterialModel");//规格
|
|
|
+ fieldKeysList.add("FQty");//数量
|
|
|
+ fieldKeysList.add("F_PONP_Text1");//客户型号
|
|
|
+ fieldKeysList.add("F_PONP_Text2");//容量
|
|
|
+ fieldKeysList.add("F_PONP_GongLv");//功率
|
|
|
+ fieldKeysList.add("F_PONP_DianYaPinLv");//规格
|
|
|
+ fieldKeysList.add("F_PONP_MS");//描述
|
|
|
+// fieldKeysList.add("F_PONP_yanse");//颜色
|
|
|
+// fieldKeysList.add("F_PONP_mingpai");//铭牌
|
|
|
+// fieldKeysList.add("F_PONP_hegezheng.FDataValue");//合格证
|
|
|
+// fieldKeysList.add("F_PONP_shuomingshu.FDataValue");//说明书
|
|
|
+// fieldKeysList.add("F_PONP_baozhuangxiang");//包装箱
|
|
|
+// fieldKeysList.add("F_PONP_Text5");//开关箱
|
|
|
+ fieldKeysList.add("FUnitID.FName");//销售单位
|
|
|
+ fieldKeysList.add("FEntryNote");//备注
|
|
|
+ fieldKeysList.add("FNote");
|
|
|
+
|
|
|
+ queryNR.put("FieldKeys",fieldKeysList.stream().collect(Collectors.joining(",")));
|
|
|
+ //过滤条件组装
|
|
|
+ List<Map> conditionsList=new ArrayList<>();
|
|
|
+ HashMap conditions=new HashMap();
|
|
|
+ conditions.put("FieldName","FBillNo");
|
|
|
+ conditions.put("Compare","67");
|
|
|
+ conditions.put("Value",orderNumber);
|
|
|
+ conditions.put("Left","");
|
|
|
+ conditions.put("Right","");
|
|
|
+ conditions.put("Logic",1);
|
|
|
+ conditionsList.add(conditions);
|
|
|
+ queryNR.put("FilterString",conditionsList);
|
|
|
+ queryNR.put("OrderString","FBillNo DESC");
|
|
|
+ queryNR.put("TopRowCount",0);
|
|
|
+ queryNR.put("StartRow",0);
|
|
|
+ queryNR.put("Limit",2000);
|
|
|
+ queryNR.put("SubSystemId","");
|
|
|
+ try {
|
|
|
+ String jsonString = JSON.toJSONString(queryNR);
|
|
|
+ String resultJson = String.valueOf(api.billQuery(jsonString));
|
|
|
+ //查询返回结果json
|
|
|
+ List<Map> mapList = JSON.parseArray(resultJson, Map.class);
|
|
|
+ return mapList;
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //============================焊接计划数据定时拉取============================
|
|
|
+ @Scheduled(cron = "0 0/10 * * * ?", zone = "Asia/Shanghai")
|
|
|
+ public void printLog2() {
|
|
|
+ //金蝶工具key
|
|
|
+ K3CloudApi api = new K3CloudApi();
|
|
|
+ //定义查询条件
|
|
|
+ String query = "{\n" +
|
|
|
+ " \"FormId\": \"PRD_MO\",\n" +
|
|
|
+ " \"FieldKeys\": \"FDescription,F_PONP_teshuyaoqiu,FBillNo,FBillType,FDate,FDocumentStatus," +
|
|
|
+ "FProductType,FMaterialId,FWorkShopID0,FQty,FStatus,,FSaleOrderNo,FPickMtrlStatus," +
|
|
|
+ "FMaterialId.FNumber,FMaterialName,F_PONP_BaseProperty,FSpecification,FUnitId.FName,F_PONP_yanse,F_PONP_mingpai,F_PONP_hegezheng.FDataValue," +
|
|
|
+ "F_PONP_shuomingshu.FDataValue,F_PONP_KaiGuanXiang,F_PONP_baozhuangxiang,F_PONP_GongLv,F_PONP_XQRQ,FDate,FPlanStartDate,FPlanFinishDate\",\n" +
|
|
|
+ " \"FilterString\": [{\"Left\":\"\",\"FieldName\":\"FMaterialId.FNumber\",\"Compare\":\"17\",\"Value\":\"焊\",\"Right\":\"\",\"Logic\":0}," +
|
|
|
+ "{\"Left\":\"\",\"FieldName\":\"FCreateDate\",\"Compare\":\"13\",\"Value\":\"\",\"Right\":\"\",\"Logic\":0}],\n" +
|
|
|
+ " \"OrderString\": \"\",\n" +
|
|
|
+ " \"TopRowCount\": 0,\n" +
|
|
|
+ " \"StartRow\": 0,\n" +
|
|
|
+ " \"Limit\": 5000,\n" +
|
|
|
+ " \"SubSystemId\": \"\"\n" +
|
|
|
+ "}";
|
|
|
+ int startRow = 0; // 起始行号
|
|
|
+ int limit = 5000; // 每次查询的数量
|
|
|
+ // 更新查询条件中的起始行号
|
|
|
+ //查询条件
|
|
|
+ Map<String, Object> map = JSON.parseObject(query, Map.class);
|
|
|
+ List<JdProductionOrder> jdProductionOrders;
|
|
|
+ boolean flag = true;
|
|
|
+ try {
|
|
|
+ do {
|
|
|
+ // 更新查询条件中的起始行号
|
|
|
+ map.put("StartRow", startRow);
|
|
|
+ //查询结果
|
|
|
+ String resultJson = api.billQuery(JSON.toJSONString(map));
|
|
|
+ if (resultJson.isEmpty() || resultJson.equals("[]")) {
|
|
|
+ // 处理空结果的情况
|
|
|
+ flag = false;
|
|
|
+ } else {
|
|
|
+ //生产信息
|
|
|
+ jdProductionOrders = JSON.parseArray(resultJson, JdProductionOrder.class);
|
|
|
+ //查询系统中的订单信息
|
|
|
+ ProductionPlanningManagement productionPlanningManagement1 = new ProductionPlanningManagement();
|
|
|
+ productionPlanningManagement1.setIsWeldSheet("2");
|
|
|
+ List<ProductionPlanningManagement> productionPlanningManagements = productionPlanningManagementMapper.selectProductionPlanningManagementList(productionPlanningManagement1);
|
|
|
+
|
|
|
+ List<String> collectTwo = productionPlanningManagements.stream().map(ProductionPlanningManagement::getOrderNumber).collect(Collectors.toSet())
|
|
|
+ .stream().collect(Collectors.toList());
|
|
|
+ // 过滤掉 collectTwo 中包含的需求文档编号,并按 demandDocument 分组
|
|
|
+ Map<String, List<JdProductionOrder>> groupedByDemandDocument = jdProductionOrders.stream()
|
|
|
+ .filter(item -> !collectTwo.contains(item.getDemandDocument()))
|
|
|
+ .collect(Collectors.groupingBy(JdProductionOrder::getDemandDocument));
|
|
|
+ if (groupedByDemandDocument.size() > 0) {
|
|
|
+ //订单循环
|
|
|
+ groupedByDemandDocument.forEach((k, v) -> {
|
|
|
+ //计划编号
|
|
|
+ String planNumnber = generator.generateCommissionNumber();
|
|
|
+ //订单号
|
|
|
+ ProductionPlanningManagement productionPlanningManagement = new ProductionPlanningManagement();
|
|
|
+ productionPlanningManagement.setOrderNumber(k); //订单编号
|
|
|
+ productionPlanningManagement.setPlanNumber(planNumnber);//计划号
|
|
|
+ productionPlanningManagement.setPlanType("0"); //待生产
|
|
|
+ productionPlanningManagement.setTaskStatus("4");//待排产
|
|
|
+ productionPlanningManagement.setIsWeldSheet("2");//焊接订单
|
|
|
+// //计算订单的最大完成时间
|
|
|
+// Optional<LocalDateTime> maxCompletionTime = v.stream()
|
|
|
+// .map(item -> LocalDateTime.parse(item.getCompletionTime(), DateTimeFormatter.ISO_LOCAL_DATE_TIME))
|
|
|
+// .max(Comparator.naturalOrder());
|
|
|
+// maxCompletionTime.ifPresent(maxTime ->{
|
|
|
+// System.out.println("最大的时间: " + maxTime);
|
|
|
+// String format1 = maxTime.format(formatter);
|
|
|
+// productionPlanningManagement.setCompletionTime(format1);//订单的最大完成时间
|
|
|
+// });
|
|
|
+ //备注
|
|
|
+ if (StringUtils.isNotNull(v.get(0).getRemark())) {
|
|
|
+ productionPlanningManagement.setRemark(v.get(0).getRemark()); //备注
|
|
|
+ }
|
|
|
+ //订单的创建时间
|
|
|
+ productionPlanningManagement.setCreationtimeString(v.get(0).getCreationtimeString());//单据的创建时间
|
|
|
+ //特殊要求
|
|
|
+ if (StringUtils.isNotNull(v.get(0).getTsyq())) {
|
|
|
+ productionPlanningManagement.setSpecialRequirements(v.get(0).getTsyq());//特殊要求
|
|
|
+ }
|
|
|
+ //单据类型
|
|
|
+ if (StringUtils.isNotNull(v.get(0).getDocumentTyep())) {
|
|
|
+ productionPlanningManagement.setOrderType(v.get(0).getDocumentTyep()); //单据类型
|
|
|
+ }
|
|
|
+
|
|
|
+ //编号订单号
|
|
|
+ List<Map> mapList = this.jdSalesOrderInfoS(k);//订单详情信息
|
|
|
+ String fDeliveryDate;
|
|
|
+ if (mapList.size() > 0) {
|
|
|
+ fDeliveryDate = mapList.get(0).get("FDeliveryDate").toString();
|
|
|
+ } else {
|
|
|
+ fDeliveryDate = "";
|
|
|
+ }
|
|
|
+ //拿到了关于这个订单的销售订单
|
|
|
+ if (mapList.size() > 0) {
|
|
|
+ if (StringUtils.isNotNull(mapList.get(0).get("F.PONP.Text"))) {
|
|
|
+ productionPlanningManagement.setContractNumber(mapList.get(0).get("F.PONP.Text").toString());
|
|
|
+ }
|
|
|
+ productionPlanningManagement.setCompletionTime(fDeliveryDate);
|
|
|
+ //======处理基本的订单信息
|
|
|
+ productionPlanningManagementMapper.insertProductionPlanningManagement(productionPlanningManagement);
|
|
|
+ v.forEach(a -> {
|
|
|
+ PlanTaskDetails planTaskDetails = new PlanTaskDetails();
|
|
|
+ planTaskDetails.setDemandDocument(a.getDocumentNumber());//需求单据号
|
|
|
+ planTaskDetails.setPlanId(productionPlanningManagement.getId());//计划id
|
|
|
+ planTaskDetails.setMaterialId(a.getMaterialCode());//原材料编码
|
|
|
+ planTaskDetails.setMaterialName(a.getMaterialName());//名称
|
|
|
+ planTaskDetails.setQuantity(a.getQuantity());//数量
|
|
|
+// planTaskDetails.setTimeOfRequest(a.getCompletionTime());//要货时间
|
|
|
+ planTaskDetails.setModelNumber(a.getModelNumber());//型号
|
|
|
+ planTaskDetails.setSpecification(a.getSpecification());//规格
|
|
|
+ planTaskDetails.setMaterialUnit(a.getUnit());//单位
|
|
|
+ planTaskDetails.setPower(a.getGl());//功率
|
|
|
+ planTaskDetails.setVoltage(a.getDianYaPinLv());//电压频率
|
|
|
+ planTaskDetails.setColour(a.getYanse());//颜色
|
|
|
+ planTaskDetails.setMingpai(a.getMingpai());//铭牌
|
|
|
+ planTaskDetails.setShuomingshu(a.getShuomingshu());//说明书
|
|
|
+ planTaskDetails.setHegezheng(a.getHegezheng());//合格证
|
|
|
+ planTaskDetails.setBaozhuangxiang(a.getBaozhuangxiang());//包装箱
|
|
|
+ planTaskDetails.setSwitchBox(a.getKaiguanxiang());//开关箱
|
|
|
+ planTaskDetails.setScheduledCommencement(a.getFPlanStartDate()); //计划开始时间
|
|
|
+ planTaskDetails.setScheduledCompletion(a.getFPlanFinishDate()); //计划完工时间
|
|
|
+ planTaskDetails.setRemark(a.getRemark());
|
|
|
+ if (StringUtils.isNotNull(a.getDocumentDate())) {
|
|
|
+ SimpleDateFormat formatter1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ String formattedDate = formatter1.format(a.getDocumentDate());
|
|
|
+ planTaskDetails.setTimeOfRequest(formattedDate);//单据日期
|
|
|
+ }
|
|
|
+ planTaskDetailsMapper.insertPlanTaskDetails(planTaskDetails);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ System.out.println(1);
|
|
|
+ if (jdProductionOrders.size() < 5000) {
|
|
|
+ flag = false;
|
|
|
+ }
|
|
|
+ // 更新起始行号
|
|
|
+ startRow += limit;
|
|
|
+ // 如果返回的数据量小于5000,说明已经没有更多的数据,结束循环
|
|
|
+ }
|
|
|
+ } while (flag);
|
|
|
+ }catch (Exception e){
|
|
|
+ System.out.println("出现了异常");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|