Browse Source

推送srm调整

fenghaifu 1 week ago
parent
commit
651f5927f2

+ 8 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/documents/shippingDetails/entity/SyShippingDetailsItem.java

@@ -406,6 +406,14 @@ public class SyShippingDetailsItem {
 
 	public SyShippingDetailsItem(){}
 
+	/**srm推送状态*/
+	@Excel(name = "srm推送状态", width = 15)
+	@ApiModelProperty(value = "srm推送状态")
+	private String pushSrmState;
+	/**srm推送信息*/
+	@Excel(name = "srm推送信息", width = 15)
+	@ApiModelProperty(value = "srm推送信息")
+	private String pushSrmMessage;
 
 	//将销售订单数据转换成发运明细数据
 	public SyShippingDetailsItem(OrderDataVo orderDataVo){

+ 2 - 2
jeecg-boot-module-system/src/main/java/org/jeecg/modules/documents/shippingDetails/entity/VO/PurchasePreDeliverDetailSizeVo.java

@@ -16,6 +16,6 @@ public class PurchasePreDeliverDetailSizeVo {
     private String size;
     /**发货数量*/
     private java.math.BigDecimal quantity;
-    /**委外订单子表id*/
-    private String purchaseId;
+
+    private String orderDetailId;
 }

+ 9 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/documents/shippingDetails/entity/VO/PurchasePreDeliverDetailVo.java

@@ -70,4 +70,13 @@ public class PurchasePreDeliverDetailVo {
     private String declarationUnit;
     //明细对象
     private List<PurchasePreDeliverDetailSizeVo> purchasePreDeliverDetailSizeList;
+    // 存货分类编号
+    private String invccode;
+    // 委外订单主表id
+    private String ompoid;
+
+    // 面辅料合并时主键:采购委外主表ID+发货日期+存货编码
+    public String toFabricUnicId(){
+        return ompoid+"-"+arriveDate+"-"+invCode;
+    }
 }

+ 9 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/documents/shippingDetails/mapper/SyShippingDetailsMapper.java

@@ -81,4 +81,13 @@ public interface SyShippingDetailsMapper extends BaseMapper<SyShippingDetails> {
     public List<PurchasePreDeliverDetailSizeVo> getPurchasePreDeliverDetailSizeVo(@Param("id") List<String> shippingDetailId);
 
     public List<SyShippingDetails> getStrings(@Param("id")List<String> idsList);
+
+    // 获取待推送SRM的主表信息
+    List<String> getPushSrmIds();
+
+    // 回写SRM推送结果
+    void setPurshInfo(@Param("groupIdList") List<String> groupIdList,
+                     @Param("status") String status,
+                     @Param("message") String message);
+
 }

+ 24 - 6
jeecg-boot-module-system/src/main/java/org/jeecg/modules/documents/shippingDetails/mapper/xml/SyShippingDetailsMapper.xml

@@ -340,7 +340,7 @@ ${ew.customSqlSegment}
         WHERE sy_declaration_elements_id = #{id} AND del_flag = 0 ORDER BY CAST(sort AS SIGNED) ASC
 
     </select>
-
+    <!-- 没用到 -->
     <select id="getPurchasePreDeliverVo" resultType="org.jeecg.modules.documents.shippingDetails.entity.VO.PurchasePreDeliverVo">
         select
         -- 	'businessType', 'consigner', 'acceptor','orderType',
@@ -368,14 +368,15 @@ ${ew.customSqlSegment}
         b.guangpei_gate_width 'guangpeiGateWidth',b.small_Po 'smallPo',
         b.distribution_Point 'distributionPoint',b.pack_id 'packId',
         b.material_composition 'composition',b.box_number 'boxNumber',
-       --b.d_arrive_date 'arriveDate',sum(b.shipment_quantity) 'deliveryQuantity',
+        b.pre_delivery_date 'arriveDate',
         b.ompo_Id_Item 'purchaseId',
-        c.declaration_name,c.declaration_unit
+        c.declaration_name,c.declaration_unit,
+        b.inventory_ccode as invccode,b.ompo_id as ompoid
         from sy_shipping_details a
         left join sy_shipping_details_item b
         on a.id=b.shipping_details_id
         left join sy_declaration_elements c on b.elements_id=c.id
-        where a.id  in
+        where (b.push_srm_state=0 or b.push_srm_state is null) and a.id  in
         <foreach collection="id" item="item"  open="(" separator="," close=")">
             #{item}
         </foreach>
@@ -385,13 +386,13 @@ ${ew.customSqlSegment}
 
     <select id="getPurchasePreDeliverDetailSizeVo" resultType="org.jeecg.modules.documents.shippingDetails.entity.VO.PurchasePreDeliverDetailSizeVo">
         select b.size 'size',c.num,b.id 'syShippingDetailsId',
-               --b.ompo_Id_Item 'purchaseId',
+               b.ompo_id_item 'orderDetailId',
                 b.shipment_quantity 'quantity',
                b.group_Id 'syShippingDetailGroupId'
         from sy_shipping_details a
         left join sy_shipping_details_item b on a.id=b.shipping_details_id
 		LEFT JOIN sizetable c ON b.`size`=c.`size`
-        where a.id  in
+        where (b.push_srm_state=0 or b.push_srm_state is null) and a.id  in
         <foreach collection="id" item="item"  open="(" separator="," close=")">
             #{item}
         </foreach>
@@ -429,5 +430,22 @@ ${ew.customSqlSegment}
         </if>
 
 
+    </update>
+    <!-- 获取待推送SRM的主表信息 -->
+    <select id="getPushSrmIds" resultType="String">
+        select shipping_details_id from sy_shipping_details_item
+            where del_flag=0 and submit_status=1
+              and (push_srm_state=0 or push_srm_state is null)
+    </select>
+    <!-- 回写SRM推送结果 -->
+    <update id="setPurshInfo">
+
+        update sy_shipping_details_item
+        set push_srm_state = #{status},push_srm_message=#{message}
+        where group_id in
+        <foreach collection="groupIdList" item="item"  open="(" separator="," close=")">
+            #{item}
+        </foreach>
+
     </update>
 </mapper>

+ 99 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/documents/shippingDetails/service/impl/SyShippingDetailsServiceImpl.java

@@ -5,7 +5,9 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import org.apache.logging.log4j.util.Strings;
 import org.jeecg.common.exception.JeecgBootException;
+import org.jeecg.common.util.DateUtils;
 import org.jeecg.common.util.oConvertUtils;
 import org.jeecg.modules.documents.orderData.entity.SyOrderDataItem;
 import org.jeecg.modules.documents.orderData.service.impl.SyOrderDataItemServiceImpl;
@@ -399,6 +401,89 @@ public class SyShippingDetailsServiceImpl extends ServiceImpl<SyShippingDetailsM
         });
         return purchasePreDeliverVos;
     }
+    /**
+     * 传入出运明细主表ID,返货根据订单、出运日期、group_id分组的多个预发货单
+     * @param id
+     * @return
+     */
+    @Override
+    public List<PurchasePreDeliverVo> getPurchasePreDeliverVoList(String id){
+        SyShippingDetails shippingDetails = syShippingDetailsMapper.selectById(id);
+        List<String> idList = new ArrayList<>();
+        idList.add(id);
+        List<PurchasePreDeliverVo> deliverVoList = new ArrayList<>();
+        List<PurchasePreDeliverDetailVo> deliverDetailVoList=syShippingDetailsMapper.getPurchasePreDeliverDetailVo(idList);
+        List<PurchasePreDeliverDetailSizeVo> deliverDetailSizeVoList=syShippingDetailsMapper.getPurchasePreDeliverDetailSizeVo(idList);
+
+        String invccode = deliverDetailVoList.get(0).getInvccode();
+        // 判断是否成衣
+        boolean isCloth = invccode.startsWith("19");
+        // 如果是成衣,根据已提交的group_id单个提交
+        // 如果是面辅料,判断同一订单、同一发货日期、同一物料、是否有不同尺码的还未提交;如果有,先不推送
+        if (isCloth){
+            List<String> groupIdList = deliverDetailVoList.stream().filter(e->"1".equals(e.getSubmitStatus())).map(PurchasePreDeliverDetailVo::getSyShippingDetailGroupId).distinct().collect(Collectors.toList());
+            for (String groupId : groupIdList){
+                List<PurchasePreDeliverDetailVo> findDetailVoList = deliverDetailVoList.stream().filter(p->p.getSyShippingDetailGroupId().equals(groupId)).collect(Collectors.toList());
+                PurchasePreDeliverDetailVo findDetailVo = findDetailVoList.get(0);
+                PurchasePreDeliverVo deliverVo = new PurchasePreDeliverVo();
+                deliverVo.setSyShippingId(shippingDetails.getId());
+                deliverVo.setVbilldate(DateUtils.date2Str(shippingDetails.getDocumentDate(), DateUtils.date_sdf.get()));
+                deliverVo.setSendDate(findDetailVo.getArriveDate());
+                deliverVo.setQuantity(findDetailVo.getQuantity());
+                deliverVo.setPurchasePreDeliverDetailList(findDetailVoList);
+                List<PurchasePreDeliverDetailSizeVo> findDetailSizeVoList = deliverDetailSizeVoList.stream().filter(p1->p1.getSyShippingDetailGroupId().equals(findDetailVo.getSyShippingDetailGroupId())).collect(Collectors.toList());
+                findDetailVo.setPurchasePreDeliverDetailSizeList(findDetailSizeVoList);
+                deliverVoList.add(deliverVo);
+            }
+        }else{
+            // 排除的订单id+存货编码
+            List<String> excludeList = new ArrayList<>();
+            deliverDetailVoList.forEach(e->{
+                if ("0".equals(e.getSubmitStatus())){
+                    excludeList.add(e.toFabricUnicId());
+                }
+            });
+            List<PurchasePreDeliverDetailVo> includeDetailVoList = deliverDetailVoList.stream().filter(e->!excludeList.contains(e.toFabricUnicId())).collect(Collectors.toList());
+            List<String> includeUnicIdList = new ArrayList<>();
+            includeDetailVoList.forEach(e->{
+                if (!includeUnicIdList.contains(e.toFabricUnicId())){
+                    includeUnicIdList.add(e.toFabricUnicId());
+                }
+            });
+            for (String unicId : includeUnicIdList){
+
+                List<PurchasePreDeliverDetailVo> findDetailVoList = deliverDetailVoList.stream().filter(p->p.toFabricUnicId().equals(unicId)).collect(Collectors.toList());
+                // 多个分组号逗号分隔
+                List<String> groupIdList = findDetailVoList.stream().map(PurchasePreDeliverDetailVo::getSyShippingDetailGroupId).distinct().collect(Collectors.toList());
+                String strGroupIds = String.join(",",groupIdList);
+                // 查找匹配的尺码
+                List<PurchasePreDeliverDetailSizeVo> findDetailSizeVoList = deliverDetailSizeVoList.stream().filter(p1->groupIdList.contains(p1.getSyShippingDetailGroupId())).collect(Collectors.toList());
+                // 多个尺码数量相加
+                PurchasePreDeliverDetailVo findDetailVo = findDetailVoList.get(0);
+                for (int i=1; i<findDetailVoList.size(); i++){
+                    findDetailVo.setQuantity(findDetailVo.getQuantity().add(findDetailVoList.get(i).getQuantity()));
+                }
+                // 设置分组id
+                findDetailVo.setSyShippingDetailGroupId(strGroupIds);
+                // 设置尺码
+                findDetailVo.setPurchasePreDeliverDetailSizeList(findDetailSizeVoList);
+                // 清空集合,只保留一个
+                findDetailVoList.clear();
+                findDetailVoList.add(findDetailVo);
+
+                PurchasePreDeliverVo deliverVo = new PurchasePreDeliverVo();
+                deliverVo.setSyShippingId(shippingDetails.getId());
+                deliverVo.setVbilldate(DateUtils.date2Str(shippingDetails.getDocumentDate(), DateUtils.date_sdf.get()));
+                deliverVo.setSendDate(findDetailVo.getArriveDate());
+                deliverVo.setPurchasePreDeliverDetailList(findDetailVoList);
+                deliverVo.setQuantity(findDetailVo.getQuantity());
+                deliverVoList.add(deliverVo);
+
+            }
+        }
+        return deliverVoList;
+    }
+
 
     @Override
     public void getStrings(List<String> idsList) {
@@ -563,4 +648,18 @@ public class SyShippingDetailsServiceImpl extends ServiceImpl<SyShippingDetailsM
         return i;
     }
 
+    // 获取待推送SRM的主表信息
+    @Override
+    public List<String> getPushSrmIds(){
+        return syShippingDetailsMapper.getPushSrmIds();
+    }
+
+    // 回写SRM推送结果
+    @Override
+    public void setPurshInfo(List<String> groupIdList,
+                      String status,
+                      String message){
+        syShippingDetailsMapper.setPurshInfo(groupIdList,status,message);
+    }
+
 }

+ 60 - 39
jeecg-boot-module-system/src/main/java/org/jeecg/modules/quartz/job/PushShippingDetailsJob.java

@@ -18,6 +18,7 @@ import org.jeecg.modules.openApi.entity.DxpDataPlan;
 import org.jeecg.modules.openApi.service.IDxpDataPlanService;
 import org.jeecg.modules.system.util.HttpHelper;
 import org.jeecg.modules.system.util.InterfaceConnUtils;
+import org.jeecg.modules.system.util.oConvertUtils;
 import org.quartz.Job;
 import org.quartz.JobExecutionContext;
 import org.quartz.JobExecutionException;
@@ -26,7 +27,9 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
+import java.util.stream.Collectors;
 
 @Component
 @Slf4j
@@ -43,17 +46,68 @@ public class PushShippingDetailsJob implements Job {
     private String srmAccessToken;
 
 
+    boolean isRunning = false;
     @Override
     public void execute(JobExecutionContext context) throws JobExecutionException {
+        if (isRunning){
+            return;
+        }
+        isRunning = true;
+        try {
+            //查询IP及账套信息、时间戳
+            QueryWrapper<DxpDataPlan> dxpDataPlanQueryWrapper = new QueryWrapper<>();
+            dxpDataPlanQueryWrapper.eq("code", "senYu_Srm_Yfh");
+            List<DxpDataPlan> dxpDataPlans = iDxpDataPlanService.list(dxpDataPlanQueryWrapper);
+
+            List<String> shippingDetailIdList = syShippingDetailsService.getPushSrmIds();
+            shippingDetailIdList = shippingDetailIdList.stream().distinct().collect(Collectors.toList());
+            for (String id : shippingDetailIdList){
+                List<PurchasePreDeliverVo> purchasePreDeliverVoList=syShippingDetailsService.getPurchasePreDeliverVoList(id);
+                if (purchasePreDeliverVoList.size()>0){
+                    ReqPurchasePreDeliverVo reqPurchasePreDeliverVo = new ReqPurchasePreDeliverVo();
+                    reqPurchasePreDeliverVo.setVerifyToken(srmAccessToken);
+                    reqPurchasePreDeliverVo.setBillList(purchasePreDeliverVoList);
+                    String reqString = JSONObject.toJSONString(reqPurchasePreDeliverVo);
+                    log.info("查看请求信息\t"+reqString);
+                    //获取url
+                    String url = dxpDataPlans.get(0).getItemIp();
+                    //处理返回信息
+                    String respStr = HttpHelper.httpJsonPost(url, reqString, null);
+                    log.info("查看返回信息\t"+respStr);
+                    JSONObject informationJson = JSONObject.parseObject(respStr);
+                    JSONArray jsonArray=informationJson.getJSONArray("result");
+                    log.info("jsonArray\t"+jsonArray);
+                    for (int i=0;i<jsonArray.size();i++){
+                        JSONObject jsonObject=jsonArray.getJSONObject(i);
+                        String syShippingId=jsonObject.getString("syShippingId");
+                        boolean success=jsonObject.getBoolean("success");
+                        String message= oConvertUtils.getString(jsonObject.getString("message"));
+                        String status = success?"1":"2";
+                        syShippingDetailsService.setPurshInfo(
+                                Arrays.asList(syShippingId.split(",")),
+                                status, message);
+                    }
+                }
+
+            }
+        }catch (Exception ex){
+            log.error("推送失败:{}", ex);
+        }finally {
+            isRunning = false;
+        }
+
+
+        /*
         //查询IP及账套信息、时间戳
-        QueryWrapper<DxpDataPlan> dxpDataPlanQueryWrapper = new QueryWrapper<>();
-        dxpDataPlanQueryWrapper.eq("code", "senYu_Srm_Yfh");
-        List<DxpDataPlan>  dxpDataPlans = iDxpDataPlanService.list(dxpDataPlanQueryWrapper);
+            QueryWrapper<DxpDataPlan> dxpDataPlanQueryWrapper = new QueryWrapper<>();
+            dxpDataPlanQueryWrapper.eq("code", "senYu_Srm_Yfh");
+            List<DxpDataPlan> dxpDataPlans = iDxpDataPlanService.list(dxpDataPlanQueryWrapper);
 
         //获取10条符合条件的数据
         LambdaQueryWrapper<SyShippingDetails> detailsLambdaQueryWrapper=new LambdaQueryWrapper();
-        detailsLambdaQueryWrapper.eq(SyShippingDetails::getState, "1");//提交状态=1
-        detailsLambdaQueryWrapper.eq(SyShippingDetails::getPushState, "0");//推送srm状态=0
+        //detailsLambdaQueryWrapper.eq(SyShippingDetails::getState, "1");//提交状态=1
+        // 提交状态在子表
+        detailsLambdaQueryWrapper.eq(SyShippingDetails::getPushSrmState, "0");//推送srm状态=0
         detailsLambdaQueryWrapper.eq(SyShippingDetails::getDelFlag, "0");//删除状态=0
         detailsLambdaQueryWrapper.last("limit 10");//一次最多同步10条数据
         List<SyShippingDetails> list=syShippingDetailsService.list(detailsLambdaQueryWrapper);
@@ -95,39 +149,6 @@ public class PushShippingDetailsJob implements Job {
             syShippingDetailsService.updateBatchById(list1);
         }catch (Exception e){
             e.printStackTrace();
-        }
-        //转JSON
-//        Gson userGson = new GsonBuilder().create();
-//        result.put("payload", userGson.toJson(JSONObject.toJSON(purchasePreDeliverVos)));
-//        System.out.println("查看推送信息\t"+result);
-//        //获取url
-//        String url = dxpDataPlans.get(0).getItemIp();
-//        //调用doPost
-//        InterfaceConnUtils interfaceConnUtils = new InterfaceConnUtils();
-//        List<SyShippingDetails> list1=new ArrayList<>();
-//        try {
-//            //处理返回信息
-//            JSONObject informationJson = interfaceConnUtils.doPostToBasicAuth(result, url);
-//            System.out.println("查看返回信息\t"+informationJson);
-//            JSONArray jsonArray=informationJson.getJSONArray("result");
-//            System.out.println("jsonArray\t"+jsonArray);
-//            for (int i=0;i<jsonArray.size();i++){
-//                JSONObject jsonObject=jsonArray.getJSONObject(i);
-//                SyShippingDetails syShippingDetails=new SyShippingDetails();
-//                String syShippingId=jsonObject.getString("syShippingId");
-//                boolean success=jsonObject.getBoolean("success");
-//                String message=jsonObject.getString("message");
-//                syShippingDetails.setPushSrmState("2");
-//                if (success){
-//                    syShippingDetails.setPushSrmState("1");
-//                }
-//                syShippingDetails.setPushSrmMessage(message);
-//                syShippingDetails.setId(syShippingId);
-//                list1.add(syShippingDetails);
-//            }
-//            syShippingDetailsService.updateBatchById(list1);
-//        }catch (Exception e){
-//            e.printStackTrace();
-//        }
+        }*/
     }
 }