Jelajahi Sumber

采购订单,委外订单

zengtx 3 tahun lalu
induk
melakukan
483f8b1e94

+ 177 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/openApi/controller/MOMainController.java

@@ -0,0 +1,177 @@
+package org.jeecg.modules.openApi.controller;
+
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import lombok.extern.log4j.Log4j2;
+import org.jeecg.common.system.query.QueryGenerator;
+import org.jeecg.common.util.DateUtils;
+import org.jeecg.modules.openApi.entity.DxpDataPlan;
+import org.jeecg.modules.openApi.service.IDxpDataPlanService;
+import org.jeecg.modules.openApi.service.ISenYuDataSourceOne;
+import org.jeecg.modules.system.util.InterfaceConnUtils;
+import org.jeecg.modules.system.util.JsonChangeUtils;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.stereotype.Component;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+
+/**
+ * 委外订单查询
+ */
+@Log4j2
+@RestController
+@RequestMapping("/openApi/moMain")
+@Component
+public class MOMainController implements ApplicationContextAware {
+
+    private static IDxpDataPlanService dxpDataPlanService;
+    //数据源one
+    private static ISenYuDataSourceOne senYuDataSourceOne;
+
+
+    @PostMapping(value = "/QueryMoMain")
+    public JSONObject QueryMoMain(String time) {
+        //传出JSON
+        JSONObject result = new JSONObject();
+        //定义集合
+        List<Map<String, Object>> sumlist = new ArrayList<>();
+        //记录定时任务开始时间
+        String beginTime = time;
+
+        try {
+
+            //查询IP及账套信息、时间戳
+            QueryWrapper<DxpDataPlan> queryWrapper = new QueryWrapper<>();
+            queryWrapper.eq("code", "senYu_moMain");
+            Page<DxpDataPlan> page = new Page<DxpDataPlan>(1, 100);
+            IPage<DxpDataPlan> pageList = dxpDataPlanService.page(page, queryWrapper);
+            List<DxpDataPlan> resultList = pageList.getRecords();
+
+            String pkorg = resultList.get(0).getPkOrg();
+            String pkorgSplit[] = pkorg.split(",");
+            Date lastTiem = resultList.get(0).getLastTime();
+            SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+            //委外订单调用时间
+            String lasttimeSf = sf.format(lastTiem);
+             //mo.cVenCode,ven.cVenName
+            String sql = "select top 1 mo.MOID as 'headerAttributeString6','903' as accId,mo.cState as 'poStatus',mo.cCode as 'poNum'," +
+                    "'SUBCONTRACTOR_PO' as 'poType','0085' as 'supplierNumber'" +
+                    ",'森鑫' as 'supplierName',ven.cVenPerson as 'supplierContacts',ven.cVenBranchPhone as 'supplierContactsPhone'" +
+                    ",mo.cMaker as 'buyerCode',mo.cVenPerson as 'customerContacts','' as 'customerContactsPhone','0.00' as 'totalAmount'," +
+                    "'0.00' as 'exTaxAmount', mo.cexch_name as 'currencyCode',mo.iTaxRate as 'headerTaxRate'," +
+                    "mo.dDate as 'customerDemandDate','' as 'supplierPromiseDate', mo.cMemo as 'remark','' as 'sourceDocNum'," +
+                    "'' as 'buyerCode',mo.cMaker as 'buyerName',mo.dCreateTime  as 'publishDate',0 as 'tenantId',0 as 'totalAmount','' as 'headerAttributeString1', '' as 'headerAttributeString2','' as 'headerAttributeString3','' as 'headerAttributeString4' " +
+                    " from OM_MOMain mo left join Vendor ven on mo.cVenCode = ven.cVenCode " +
+                    "where ( mo.iVerifyStateNew = 2 or mo.cState = 2) and mo.cCode = 'SYM713-森鑫'  order by mo.dCreateTime desc";
+
+//            String sql1 = "select top 2 '903' as accId,MOID as MOID,cPersonCode as buyerCode,cexch_name as currencyCode,cVenPerson as customerContacts,'联系人电话' as customerContactsPhone,'123' as customerNumber,cVenAccount as headerAttributeString1," +
+//                    "'合同号' as headerAttributeString2,'0097' as headerAttributeString3,'' as headerAttributeString4,'3' as headerTaxRate,cCode as poNum,'01' as poType,'0085' as supplierNumber " +
+//                    " from OM_MOMain where iVerifyStateNew = 2 or cState = 2 order by dCreateTime desc";
+
+            List<Map<String, Object>> list = senYuDataSourceOne.queryForList(sql);
+            sumlist.addAll(list);
+            //转JSON且赋值
+            Gson userGson=new GsonBuilder().create();
+            result.put("payload", userGson.toJson(JsonChangeUtils.toMoMainJson(sumlist)));
+            log.info("查询到的数据:" + result);
+
+            //获取当前接口同步信息,对方接口地址
+            //拼接url
+            String url = resultList.get(0).getItemIp() + resultList.get(0).getItemUrl();
+            //调用doPost
+            InterfaceConnUtils interfaceConnUtils = new InterfaceConnUtils();
+            //处理返回信息
+            JSONObject informationJson = interfaceConnUtils.doPostToBearer(result, url, "委外订单接口-");
+
+//            JSONArray jsonArray = informationJson.getJSONArray("head");
+//            if (jsonArray.size() != 0) {
+//                //获取4个账套值
+//                String yi = "";
+//                String er = "";
+//                String san = "";
+//                String si = "";
+//                for (String str : pkorgSplit) {
+//                    String pkorgStr = str;
+//                    String pkorgValue[] = pkorgStr.split(":");
+//                    if (pkorgValue[0].equals("one")) {
+//                        yi = pkorgValue[1];
+//                    }
+//                    if (pkorgValue[0].equals("two")) {
+//                        er = pkorgValue[1];
+//                    }
+//                    if (pkorgValue[0].equals("three")) {
+//                        san = pkorgValue[1];
+//                    }
+//                    if (pkorgValue[0].equals("four")) {
+//                        si = pkorgValue[1];
+//                    }
+//                }
+//                //回写U8物料信息表是否同步成功字段
+//                Iterator<Object> it = jsonArray.iterator();
+//                while (it.hasNext()) {
+//                    JSONObject jo = (JSONObject) it.next();
+//                    //获取是否成功
+//                    String code = jo.getString("code");
+//                    //获取返回消息
+//                    String message = jo.getString("message");
+//                    //获取businessCode
+//                    String businessCode = jo.getString("businessCode");
+//                    String busSplit[] = businessCode.split("#");
+//                    //账套666
+//                    if (busSplit[1].equals(yi)) {
+//                        if (code.equals("S")) {
+//                            //普通采购回写
+//                            String sql = "update PO_Pomain set cDefine12 = ? where cPOID = ?";
+//                            sixdxpDataSourceOne.updatePomain(sql, "true," + message, busSplit[0]);
+//                            //订单委外
+//                            String sql1 = "update HY_MOMain set cDefine10 = ? where cCode = ?";
+//                            sixdxpDataSourceOne.updateMomain(sql1, "true," + message, busSplit[0]);
+//                        } else {
+//                            //普通采购回写
+//                            String sql = "update PO_Pomain set cDefine12 = ? where cPOID = ?";
+//                            sixdxpDataSourceOne.updatePomain(sql, "false," + message, busSplit[0]);
+//                            //订单委外
+//                            String sql1 = "update HY_MOMain set cDefine10 = ? where cCode = ?";
+//                            sixdxpDataSourceOne.updateMomain(sql1, "false," + message, busSplit[0]);
+//                        }
+//                    }
+//                    //账套012
+//
+//                }
+//            }
+
+            //回写委外订单接口最后时间
+            Date datetome = sf.parse(beginTime);
+            dxpDataPlanService.updateLastTime(datetome,"senYu_moMain");
+
+        } catch (Exception e) {
+            log.error(e.getMessage());
+        }
+
+        return result;
+    }
+
+
+    @Override
+    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
+        this.dxpDataPlanService = applicationContext.getBean(IDxpDataPlanService.class);
+        this.senYuDataSourceOne = applicationContext.getBean(ISenYuDataSourceOne.class);
+    }
+}

+ 177 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/openApi/controller/POPomainController.java

@@ -0,0 +1,177 @@
+package org.jeecg.modules.openApi.controller;
+
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import lombok.extern.log4j.Log4j;
+import lombok.extern.log4j.Log4j2;
+import org.jeecg.modules.openApi.entity.DxpDataPlan;
+import org.jeecg.modules.openApi.service.IDxpDataPlanService;
+import org.jeecg.modules.openApi.service.ISenYuDataSourceOne;
+import org.jeecg.modules.system.util.InterfaceConnUtils;
+import org.jeecg.modules.system.util.JsonChangeUtils;
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.stereotype.Component;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+
+
+@RestController
+@Component
+@Log4j2
+@RequestMapping("/openApi/poMain")
+public class POPomainController implements ApplicationContextAware {
+
+    private static IDxpDataPlanService dxpDataPlanService;
+    //数据源one
+    private static ISenYuDataSourceOne senYuDataSourceOne;
+
+
+    @PostMapping(value = "/QueryPoMain")
+    public JSONObject QueryPoMain(String time) {
+        //传出JSON
+        JSONObject result = new JSONObject();
+        //定义集合
+        List<Map<String, Object>> sumlist = new ArrayList<>();
+        //记录定时任务开始时间
+        String beginTime = time;
+
+        try {
+
+            //查询IP及账套信息、时间戳
+            QueryWrapper<DxpDataPlan> queryWrapper = new QueryWrapper<>();
+            queryWrapper.eq("code", "senYu_poMain");
+            Page<DxpDataPlan> page = new Page<DxpDataPlan>(1, 100);
+            IPage<DxpDataPlan> pageList = dxpDataPlanService.page(page, queryWrapper);
+            List<DxpDataPlan> resultList = pageList.getRecords();
+
+            String pkorg = resultList.get(0).getPkOrg();
+            String pkorgSplit[] = pkorg.split(",");
+            Date lastTiem = resultList.get(0).getLastTime();
+            SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+            //委外订单调用时间
+            String lasttimeSf = sf.format(lastTiem);
+
+//            String sql = "select top 1 '666' as cAccId,POID as 'POID',cPOID as cCode,cBusType as iOrderType,cVenCode,'1' as cVenName,'1' as cVenPerson,'1' as cVenTelephone," +
+//                    "cMaker,'1' as cPersonName,'1' as cPersonPhone,'1' as totalPurchasePrice,'1' as totalNetPrice," +
+//                    "cexch_name as cexchName,iTaxRate,dPODate as demandDate,'2022-01-01' as promiseDate,cMemo,'' as sourceDocNo," +
+//                    "'1' as createByCode,'' as createByCode,cmaketime as createTime,cVenAccount as itemNumber,cPOID as contractNo," +
+//                    "'' as upstreamSupplier,'' as downstreamSupplier  from PO_Pomain where iverifystateex = 2  order by dCreateTime desc";
+//ven.cVenName,mo.cVenCode
+//cAuditTime>'"+lasttimeSf+"' and mo.iverifystateex = 2
+             String sql = "select top 1 mo.POID as 'MOID','903' as accId,mo.cState as 'poStatus',mo.cPOID as 'poNum'," +
+                     "'STANDARD_PO' as 'poType', '0085' as 'supplierNumber'," +
+                     "'森鑫' as 'supplierName',ven.cVenPerson as 'supplierContacts',ven.cVenBranchPhone as 'supplierContactsPhone'," +
+                     "mo.cMaker as 'buyerCode',mo.cVenPerson as 'customerContacts','' as 'customerContactsPhone','0.00' as 'totalAmount'," +
+                     "'0.00' as 'exTotalAmount', mo.cexch_name as 'currencyCode',mo.iTaxRate as 'headerTaxRate'," +
+                     "mo.dPODate as 'customerDemandDate','' as 'supplierPromiseDate', mo.cMemo as 'remark','' as 'sourceDocNum'," +
+                     "'' as 'buyerCode',mo.cMaker as 'buyerName',mo.cmaketime  as 'publishDate','' as 'headerAttributeString1', '' as 'headerAttributeString2','' as 'headerAttributeString3','' as 'headerAttributeString4'  " +
+                     "from PO_Pomain mo " +
+                     "left join Vendor ven " +
+                     "on mo.cVenCode = ven.cVenCode where cPOID = 'SYE小周样1' order by mo.cAuditTime desc";
+            List<Map<String, Object>> list = senYuDataSourceOne.queryForList(sql);
+            sumlist.addAll(list);
+            //转JSON且赋值
+            //转JSON且赋值
+            Gson userGson=new GsonBuilder().create();
+            result.put("payload", userGson.toJson(JsonChangeUtils.toPoMainJson(sumlist)));
+
+            log.info("查询到的数据:" + result);
+
+            //获取当前接口同步信息,对方接口地址
+            //拼接url
+            String url = resultList.get(0).getItemIp() + resultList.get(0).getItemUrl();
+            //调用doPost
+            InterfaceConnUtils interfaceConnUtils = new InterfaceConnUtils();
+            //处理返回信息
+            JSONObject informationJson = interfaceConnUtils.doPostToBearer(result, url, "采购订单接口-");
+
+//            JSONArray jsonArray = informationJson.getJSONArray("head");
+//            if (jsonArray.size() != 0) {
+//                //获取4个账套值
+//                String yi = "";
+//                String er = "";
+//                String san = "";
+//                String si = "";
+//                for (String str : pkorgSplit) {
+//                    String pkorgStr = str;
+//                    String pkorgValue[] = pkorgStr.split(":");
+//                    if (pkorgValue[0].equals("one")) {
+//                        yi = pkorgValue[1];
+//                    }
+//                    if (pkorgValue[0].equals("two")) {
+//                        er = pkorgValue[1];
+//                    }
+//                    if (pkorgValue[0].equals("three")) {
+//                        san = pkorgValue[1];
+//                    }
+//                    if (pkorgValue[0].equals("four")) {
+//                        si = pkorgValue[1];
+//                    }
+//                }
+//                //回写U8物料信息表是否同步成功字段
+//                Iterator<Object> it = jsonArray.iterator();
+//                while (it.hasNext()) {
+//                    JSONObject jo = (JSONObject) it.next();
+//                    //获取是否成功
+//                    String code = jo.getString("code");
+//                    //获取返回消息
+//                    String message = jo.getString("message");
+//                    //获取businessCode
+//                    String businessCode = jo.getString("businessCode");
+//                    String busSplit[] = businessCode.split("#");
+//                    //账套666
+//                    if (busSplit[1].equals(yi)) {
+//                        if (code.equals("S")) {
+//                            //普通采购回写
+//                            String sql = "update PO_Pomain set cDefine12 = ? where cPOID = ?";
+//                            sixdxpDataSourceOne.updatePomain(sql, "true," + message, busSplit[0]);
+//                            //订单委外
+//                            String sql1 = "update HY_MOMain set cDefine10 = ? where cCode = ?";
+//                            sixdxpDataSourceOne.updateMomain(sql1, "true," + message, busSplit[0]);
+//                        } else {
+//                            //普通采购回写
+//                            String sql = "update PO_Pomain set cDefine12 = ? where cPOID = ?";
+//                            sixdxpDataSourceOne.updatePomain(sql, "false," + message, busSplit[0]);
+//                            //订单委外
+//                            String sql1 = "update HY_MOMain set cDefine10 = ? where cCode = ?";
+//                            sixdxpDataSourceOne.updateMomain(sql1, "false," + message, busSplit[0]);
+//                        }
+//                    }
+//                    //账套012
+//
+//                }
+//            }
+
+            //回写委外订单接口最后时间
+            Date datetome = sf.parse(beginTime);
+            dxpDataPlanService.updateLastTime(datetome,"senYu_poMain");
+
+        } catch (Exception e) {
+            log.error(e.getMessage());
+        }
+
+        return result;
+    }
+
+
+    @Override
+    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
+        this.dxpDataPlanService = applicationContext.getBean(IDxpDataPlanService.class);
+        this.senYuDataSourceOne = applicationContext.getBean(ISenYuDataSourceOne.class);
+    }
+}

+ 3 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/openApi/mapper/DxpDataPlanMapper.java

@@ -1,5 +1,6 @@
 package org.jeecg.modules.openApi.mapper;
 
+import java.util.Date;
 import java.util.List;
 
 import org.apache.ibatis.annotations.Param;
@@ -14,4 +15,6 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
  */
 public interface DxpDataPlanMapper extends BaseMapper<DxpDataPlan> {
 
+    //回写调用时间
+    public void updateLastTime(@Param("time") Date time, @Param("code") String code);
 }

+ 5 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/openApi/mapper/xml/DxpDataPlanMapper.xml

@@ -2,4 +2,9 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="org.jeecg.modules.openApi.mapper.DxpDataPlanMapper">
 
+
+    <update id="updateLastTime">
+        update dxp_data_plan set last_time = #{time} where code = #{code}
+    </update>
+
 </mapper>

+ 5 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/openApi/service/IDxpDataPlanService.java

@@ -3,6 +3,8 @@ package org.jeecg.modules.openApi.service;
 import org.jeecg.modules.openApi.entity.DxpDataPlan;
 import com.baomidou.mybatisplus.extension.service.IService;
 
+import java.util.Date;
+
 /**
  * @Description: 项目推单接口信息
  * @Author: jeecg-boot
@@ -11,4 +13,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface IDxpDataPlanService extends IService<DxpDataPlan> {
 
+    //回写调用时间
+    public void updateLastTime(Date time, String code);
+
 }

+ 6 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/openApi/service/ISenYuDataSourceOne.java

@@ -13,4 +13,10 @@ public interface ISenYuDataSourceOne {
 
     public boolean update(String sql);//执行更新或删除语句
 
+    //修改采购订单是否同步成功!
+    public boolean updateMOMain(String sql,String cDefine10,String moId);
+
+    //修改委外订单是否同步成功!
+    public boolean updatePOMain(String sql,String cDefine10,String moId);
+
 }

+ 16 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/openApi/service/impl/DxpDataPlanServiceImpl.java

@@ -7,6 +7,9 @@ import org.springframework.stereotype.Service;
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 
+import javax.annotation.Resource;
+import java.util.Date;
+
 /**
  * @Description: 项目推单接口信息
  * @Author: jeecg-boot
@@ -16,4 +19,17 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 @Service
 public class DxpDataPlanServiceImpl extends ServiceImpl<DxpDataPlanMapper, DxpDataPlan> implements IDxpDataPlanService {
 
+    @Resource
+    private DxpDataPlanMapper dxpDataPlanMapper;
+
+
+    /**
+     * 调用最后时间
+     * @param time
+     * @param code
+     */
+    @Override
+    public void updateLastTime(Date time, String code) {
+        dxpDataPlanMapper.updateLastTime(time,code);
+    }
 }

+ 47 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/openApi/service/impl/SenYuDataSourceOneServiceImpl.java

@@ -32,4 +32,51 @@ public class SenYuDataSourceOneServiceImpl implements ISenYuDataSourceOne {
         return flag;
     }
 
+    /**
+     * 修改委外订单是否同步成功
+     * @param sql
+     * @param cDefine10
+     * @param moId
+     * @return
+     */
+    @Override
+    public boolean updateMOMain(String sql, String cDefine10, String moId) {
+        // 定义返回结果
+        boolean flag = false;
+        try {
+            int i = jdbcTemplate.update(sql, cDefine10, moId);
+            if (i > 0) {
+                flag = true;
+            }
+
+        } catch (Exception exception) {
+            exception.printStackTrace();
+        }
+        return flag;
+    }
+
+
+    /**
+     * 修改采购订单是否同步成功
+     * @param sql
+     * @param cDefine10
+     * @param moId
+     * @return
+     */
+    @Override
+    public boolean updatePOMain(String sql, String cDefine10, String moId) {
+        // 定义返回结果
+        boolean flag = false;
+        try {
+            int i = jdbcTemplate.update(sql, cDefine10, moId);
+            if (i > 0) {
+                flag = true;
+            }
+
+        } catch (Exception exception) {
+            exception.printStackTrace();
+        }
+        return flag;
+    }
+
 }

+ 43 - 4
jeecg-boot-module-system/src/main/java/org/jeecg/modules/quartz/job/AsyncJob.java

@@ -1,8 +1,18 @@
 package org.jeecg.modules.quartz.job;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import lombok.extern.slf4j.Slf4j;
 import org.jeecg.common.util.DateUtils;
+import org.jeecg.modules.openApi.controller.MOMainController;
+import org.jeecg.modules.openApi.controller.POPomainController;
+import org.jeecg.modules.openApi.entity.DxpDataPlan;
+import org.jeecg.modules.openApi.service.IDxpDataPlanService;
 import org.quartz.*;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.util.List;
 
 /**
  * @Description: 同步定时任务测试
@@ -19,16 +29,45 @@ import org.quartz.*;
 @Slf4j
 public class AsyncJob implements Job {
 
+    @Autowired
+    private IDxpDataPlanService dxpDataPlanService;
+
     @Override
     public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
         log.info(" --- 同步任务调度开始 --- ");
         try {
-            //此处模拟任务执行时间 5秒  任务表达式配置为每秒执行一次:0/1 * * * * ? *
-            Thread.sleep(5000);
-        } catch (InterruptedException e) {
+
+            String time = DateUtils.now();
+
+            //委外订单
+            QueryWrapper<DxpDataPlan> queryWrapperMoMain = new QueryWrapper<>();
+            queryWrapperMoMain.eq("code", "senYu_moMain");
+            Page<DxpDataPlan> page = new Page<DxpDataPlan>(1, 100);
+            IPage<DxpDataPlan> pageList = dxpDataPlanService.page(page, queryWrapperMoMain);
+            List<DxpDataPlan> resultList = pageList.getRecords();
+            if(resultList.get(0).getIsauto() == 0){
+                MOMainController momain = new MOMainController();
+                momain.QueryMoMain(time);
+            }else{
+                System.out.println("委外订单接口未开启同步!");
+            }
+
+            //采购订单
+            QueryWrapper<DxpDataPlan> queryWrapperPoMain = new QueryWrapper<>();
+            queryWrapperPoMain.eq("code", "senYu_poMain");
+            Page<DxpDataPlan> pagePoMain = new Page<DxpDataPlan>(1, 100);
+            IPage<DxpDataPlan> pageListPoMain = dxpDataPlanService.page(pagePoMain, queryWrapperPoMain);
+            List<DxpDataPlan> resultListPoMain = pageListPoMain.getRecords();
+            if(resultListPoMain.get(0).getIsauto() == 0){
+                POPomainController momain = new POPomainController();
+                momain.QueryPoMain(time);
+            }else{
+                System.out.println("采购订单接口未开启同步!");
+            }
+        } catch (Exception e) {
             e.printStackTrace();
         }
-        //测试发现 每5秒执行一次
+
         log.info(" --- 执行完毕,时间:"+DateUtils.now()+"---");
     }
 

+ 3 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/util/InterfaceConnUtils.java

@@ -64,7 +64,7 @@ public class InterfaceConnUtils {
      * post请求-推数据,Token认证:Bearer Token
      * @throws Exception
      */
-    public static JSONObject doPostToBearer(JSONObject json, String url) throws Exception {
+    public static JSONObject doPostToBearer(JSONObject json, String url,String type) throws Exception {
         //定义返回JSON
         JSONObject onejb = new JSONObject();
         String token=null;
@@ -79,6 +79,7 @@ public class InterfaceConnUtils {
             String resultTokenStr = EntityUtils.toString(response.getEntity());
             JSONObject tokenjb=JSONObject.parseObject(resultTokenStr);
             token=tokenjb.getString("access_token");
+           // System.out.println("token:"+token);
         } catch (Exception e) {
             e.printStackTrace();
         }
@@ -97,6 +98,7 @@ public class InterfaceConnUtils {
             //返回信息
             String resultStr = EntityUtils.toString(response.getEntity());
             onejb=JSONObject.parseObject(resultStr);
+            System.out.println(type+"返回信息:"+onejb);
 
         } catch (Exception e) {
             e.printStackTrace();

+ 233 - 5
jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/util/JsonChangeUtils.java

@@ -1,18 +1,194 @@
 package org.jeecg.modules.system.util;
 
 import com.alibaba.fastjson.JSONObject;
+import com.fasterxml.jackson.core.io.JsonStringEncoder;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import org.apache.commons.lang.StringEscapeUtils;
+import org.jeecg.modules.openApi.service.ISenYuDataSourceOne;
+import org.jeecg.modules.openApi.service.impl.SenYuDataSourceOneServiceImpl;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
 import org.springframework.stereotype.Component;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.text.SimpleDateFormat;
+import java.util.*;
 
 /***
  * json转换类
  * 赵万发
  */
-public class JsonChangeUtils{
+@Component
+public class JsonChangeUtils implements ApplicationContextAware{
+
+    private static ISenYuDataSourceOne senYuDataSourceOne;
+
+
+
+
+    /**
+     * 委外订单转JSON
+     * @param result
+     * @return
+     */
+    public static List<JSONObject> toMoMainJson(List<Map<String, Object>> result) {
+        List<JSONObject> pljf = new ArrayList<JSONObject>();// 表数据json集合
+        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
+       // String lasttimeSf = sf.format(lastTiem);
+        JSONObject jf = new JSONObject();
+        for (int i = 0; i < result.size(); i++) {
+            Map<String, Object> map = result.get(i);
+            Set<String> keys = map.keySet();
+            jf = new JSONObject();
+            for (String key : keys) {
+                if(null==map.get(key)){
+                    jf.put(key, "");
+                }else{
+                    jf.put(key, map.get(key));
+
+                }
+            }
+            String customerDemandDate = sf.format(map.get("customerDemandDate"));
+            jf.put("customerDemandDate",customerDemandDate+" 00:00:00");
+            String publishDate = sf.format(map.get("publishDate"));
+            jf.put("publishDate",publishDate+" 00:00:00");
+            //查询子表信息
+            if(map.get("accId").equals("903")){
+//                String sql = "select MODetailsID as MODetailsID,"+map.get("accId")+" as cAccId,"+map.get("MOID")+" as MOID,'' as cCode," +
+//                        "'N0201001237' as customerItemCode,'门幅120  颜色 为深色' as cInvName,'lineStatus' as lineStatus," +
+//                        "'' as attributeCode1,'' as attributeCode2,'' as attributeCode3,'' as attributeCode4,'' as attributeValue1,'' as attributeValue2," +
+//                        "'' as attributeValue3,'' as attributeValue4," +
+//                        "'materialKeyAttribute' as materialKeyAttribute,iQuantity as customerDemandQty,cUnitID as customerUomCode,'demandDate' as customerDemandDate," +
+//                        "iTaxPrice as customerPrice,(iPerTaxRate/100) as lineTaxRate,iMoney as amount,'12' as lineAttributeString1,'34' as lineAttributeString2," +
+//                        "'56' as lineAttributeString3,'78' as lineAttributeString4,cbMemo as lineAttributeString5 " +
+//                        "from OM_MODetails where MOID = "+map.get("MOID");
+                //mo.cInvCode,inv.cInvName
+                String sql = "select mo.iVouchRowNo as 'poLineNum',mo.MODetailsID as MODetailsID,mo.MODetailsID as ' moDetailId','"+map.get("headerAttributeString6")+"' as MOID,'"+map.get("accId")+"' as 'accId'" +
+                        ",'"+map.get("poNum")+"' as poNum,'N0201002142' as 'customerItemCode','35%棉65%涤 平纹汗布' as 'itemName','' as 'poLineStatus', " +
+                        "mo.cFree1 as 'attributeValue1',mo.cFree2 as 'attributeValue2',mo.cFree3 as 'attributeValue3'," +
+                        "mo.cFree4 as 'attributeValue4','cfree1' as 'attributeCode1','cfree2'  as 'attributeCode2'," +
+                        "'cfree3'  as 'attributeCode3','cfree4'  as 'attributeCode4'," +
+                        "mo.iQuantity as 'customerDemandQty',mo.cUnitID as 'customerUomCode','"+map.get("customerDemandDate")+"' as 'customerDemandDate'," +
+                        "mo.iUnitPrice as 'customerPrice',(mo.iPerTaxRate/100) as 'lineTaxRate',mo.iMoney as 'amount'," +
+                        "mo.cDefine28 as 'lineAttributeString1',mo.cDefine32 as 'lineAttributeString2',mo.cDefine29 as 'lineAttributeString3'," +
+                        "mo.cDefine30 as 'lineAttributeString4',mo.cbMemo as 'lineAttributeString5',cFree1 as 'color','' as 'customerNumber','' as externalLineNum," +
+                        "'' as itemAttrId,'"+map.get("headerAttributeString6")+"' as poId " +
+                        " from OM_MODetails mo " +
+                        " left join Inventory inv " +
+                        " on mo.cInvCode = inv.cInvCode " +
+                        " where mo.MOID = "+map.get("headerAttributeString6");
+                List<Map<String, Object>> list = senYuDataSourceOne.queryForList(sql);
+                //子表转JSON
+                List<JSONObject> json = toMOListJson(list);
+                jf.put("poLineList",json);
+            }
+
+            jf.remove("MODetailsID");
+            jf.remove("MOID");
+            pljf.add(jf);
+        }
+        return pljf;
+    }
+
+    /**
+     * 普通采购订单转JSON
+     * @param result
+     * @return
+     */
+    public static List<JSONObject> toPoMainJson(List<Map<String, Object>> result) {
+        List<JSONObject> pljf = new ArrayList<JSONObject>();// 表数据json集合
+        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
+        JSONObject jf = new JSONObject();
+        for (int i = 0; i < result.size(); i++) {
+            Map<String, Object> map = result.get(i);
+            Set<String> keys = map.keySet();
+            jf = new JSONObject();
+            for (String key : keys) {
+                if(null==map.get(key)){
+                    jf.put(key, "");
+                }else{
+                    jf.put(key, map.get(key));
+                }
+            }
+            String customerDemandDate = sf.format(map.get("customerDemandDate"));
+            jf.put("customerDemandDate",customerDemandDate+" 00:00:00");
+            String publishDate = sf.format(map.get("publishDate"));
+            jf.put("publishDate",publishDate+" 00:00:00");
+            //查询子表信息
+            if(map.get("accId").equals("903")){
+//                String sql = "select '666' as cAccId,cPOID as cCode,cInvCode,'' as cInvName,'1' as lineStatus,'' as materialKeyAttribute," +
+//                        " iQuantity as purchaseQuantity,cUnitID as cUnitID,'' as demandDate,iTaxPrice as iTaxPrice,iPerTaxRate as iPerTaxRate," +
+//                        "iSum as lineTotalPrice,'' as smallPo,'' as packId,'' as distributionPoint,'' as dyeFactoryCode,cbMemo as cbMemo " +
+//                        "from PO_Podetails  where POID = '"+map.get("POID")+"'";
+
+                String sql ="select '903' as 'accId',mo.iVouchRowNo as 'poLineNum',ID as 'moDetailId','"+map.get("poNum")+"' as poNum,mo.cInvCode as 'customerItemCode',inv.cInvName as 'itemName'," +
+                        "'' as 'poLineStatus',mo.cFree1 as 'attributeValue1',mo.cFree2 as 'attributeValue2'," +
+                        "mo.cFree3 as 'attributeValue3',mo.cFree4 as 'attributeValue4','cfree1' as 'attributeCode1'," +
+                        "'cfree2'  as 'attributeCode2','cfree3'  as 'attributeCode3','cfree4'  as 'attributeCode4'," +
+                        "mo.iQuantity as 'customerDemandQty',mo.cUnitID as 'customerUomCode','"+map.get("customerDemandDate")+"' as 'customerDemandDate'," +
+                        "mo.iUnitPrice as 'customerPrice',(mo.iPerTaxRate/100) as 'lineTaxRate',mo.iMoney as 'amount'," +
+                        "'' as 'lineAttributeString1','' as 'lineAttributeString2','' as 'lineAttributeString3','' as 'attributeString1'," +
+                        "'' as 'lineAttributeString4','' as 'color','' as 'externalLineNum',0 as 'itemAttrId' " +
+                        "from PO_Podetails mo " +
+                        "left join Inventory inv " +
+                        "on mo.cInvCode = inv.cInvCode "+
+                        "where mo.POID = '"+map.get("MOID")+"'";
+                List<Map<String, Object>> list = senYuDataSourceOne.queryForList(sql);
+                //子表转JSON
+                List<JSONObject> json = toListJson(list);
+                jf.put("poLineList",json);
+            }
+
+            pljf.add(jf);
+        }
+        return pljf;
+    }
+
+
+    /**
+     * 材料出库单转JSON
+     * @param result
+     * @return
+     */
+    public static List<JSONObject> toRdrecordJson(List<Map<String, Object>> result) {
+        List<JSONObject> pljf = new ArrayList<JSONObject>();// 表数据json集合
+        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
+        JSONObject jf = new JSONObject();
+        for (int i = 0; i < result.size(); i++) {
+            Map<String, Object> map = result.get(i);
+            Set<String> keys = map.keySet();
+            jf = new JSONObject();
+            for (String key : keys) {
+                if(null==map.get(key)){
+                    jf.put(key, "");
+                }else{
+                    jf.put(key, map.get(key));
+                }
+            }
+            String customerDemandDate = sf.format(map.get("customerDemandDate"));
+            jf.put("customerDemandDate",customerDemandDate+" 00:00:00");
+            String publishDate = sf.format(map.get("publishDate"));
+            jf.put("publishDate",publishDate+" 00:00:00");
+            //查询子表信息
+            if(map.get("accId").equals("903")){
+                String sql = "select '903' as cAccId,'' as '发货单号',AutoID as '发货单行ID',ID as '发货单ID', irowno as '发货单行号'," +
+                        "'' as '发货单行状态',cInVoucherType as '发货单来源类型','' as '来源单据ID','' as '来源单据编号'," +
+                        "'' as '来源单据行ID',cInvCode as '供应商物料编码',cBVencode as '供应商单位ID','' as '单位'," +
+                        "iQuantity as '采购数量',iSOutQuantity as '出库数量',cBatch as '批号' from rdrecords11 " +
+                        "where ID = '"+map.get("ID")+"'";
+
+                List<Map<String, Object>> list = senYuDataSourceOne.queryForList(sql);
+                //子表转JSON
+                List<JSONObject> json = toListJson(list);
+                jf.put("poLineList",json);
+            }
+
+            pljf.add(jf);
+        }
+        return pljf;
+    }
 
     /**
      * 数据库查询返回集合转换为json对象集合
@@ -37,4 +213,56 @@ public class JsonChangeUtils{
         }
         return pljf;
     }
+
+    /**
+     * 委外专用JSON
+     * @param result
+     * @return
+     */
+    public static List<JSONObject> toMOListJson(List<Map<String, Object>> result) {
+        List<JSONObject> pljf = new ArrayList<JSONObject>();// 表数据json集合
+        JSONObject jf = new JSONObject();
+        for (int i = 0; i < result.size(); i++) {
+            Map<String, Object> map = result.get(i);
+            Set<String> keys = map.keySet();
+            jf = new JSONObject();
+            for (String key : keys) {
+                if(null==map.get(key)){
+                    jf.put(key, "");
+                }else{
+                    jf.put(key, map.get(key));
+                }
+            }
+            //查询委外用料子表数据
+            if(map.get("accId").equals("903")){
+//                String sql = "select '' as poOutsourceNum,''as poNum,'903' as cAccId,"+map.get("MOID")+" as MOID,'YU-02' as customerItemCode,'' as itemAttrId," +
+//                        "'' as attributeCode1,'' as attributeCode2,'' as attributeCode3,'' as attributeCode4,'' as attributeValue1,'' as attributeValue2," +
+//                        "'' as attributeValue3,'' as attributeValue4," +
+//                        "'' as customerUnitID,'' as customerUnit,'' as customerPromiseQty,'' as outsourceAttributeString1,'' as outsourceAttributeString2," +
+//                        "'' as outsourceAttributeString3,'' as iUnitQuantity " +
+//                        " from OM_MOMaterials where MOMaterialsID = "+map.get("MODetailsID");
+
+                String sql1 = "select '903' as accId,'"+map.get("MOID")+"' as poId,'"+map.get("poNum")+"' as poNum,'N0201002142' as 'customerItemCode','' as 'itemAttrId','cfree1' as attributeCode1," +
+                        "'cfree2' as attributeCode2,'cfree3' as attributeCode3,'cfree4' as attributeCode4,cFree1 as attributeValue1,cFree2 as attributeValue2," +
+                        "cFree3 as attributeValue3,cFree4 as attributeValue4,'' as 'customerUomId','' as customerUomCode,0 as customerPromiseQty," +
+                        " cDefine25 as outsourceAttributeString1,cDefine24 as 'outsourceAttributeString2'," +
+                        "cDefine27 as 'outsourceAttributeString3' from OM_MOMaterials " +
+                        "where MODetailsID = '"+map.get("MODetailsID")+"'";
+                List<Map<String, Object>> list = senYuDataSourceOne.queryForList(sql1);
+                //子表转JSON
+                List<JSONObject> json = toListJson(list);
+                jf.put("outSourceList",json);
+            }
+
+            pljf.add(jf);
+        }
+        return pljf;
+    }
+
+
+    @Override
+    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
+
+        this.senYuDataSourceOne = applicationContext.getBean(ISenYuDataSourceOne.class);
+    }
 }