Kaynağa Gözat

从旧系统中同步销售项目

lvjs 5 saat önce
ebeveyn
işleme
b64137659b

+ 2 - 0
src/main/java/com/malk/eastar/conf/EastarParam.java

@@ -25,6 +25,8 @@ public class EastarParam {
     public static String YD_FORMUUID_ALERT_DETAIL = "FORM-AAA9AD76E53246B89356B09DEE5262552ZA0";    //私海客户流出风险提示,add by Jason 20260522
     public static String YD_FORMUUID_PSS_SERIES = "FORM-3598FDFC625D44CD929675B32228BFC7ES87";    //PSS系列,add by Jason 20260529
 
+    public static String YD_FORMUUID_SALE_PROJECT = "FORM-98FAA0EE0B324C11AD2EAB517368EB1EM1EG";    //销售项目,add by Jason 20260622
+
     static {
         CUSTFIELD_ACCE.put("配件名","textField_me2f7tvo");
         CUSTFIELD_ACCE.put("系列名称","selectField_me2f7tw4");

+ 1 - 1
src/main/java/com/malk/eastar/schedule/ScheduleTask.java

@@ -35,7 +35,7 @@ import java.util.*;
 @Configuration
 @EnableScheduling
 @ConditionalOnProperty(name = {"enable.scheduling"})
-public class ScheduleTask {
+public class ScheduleTask1 {
 
     @Autowired
     private YDClient ydClient;

+ 1 - 1
src/main/java/com/malk/eastar/schedule/ScheduleTaskNew.java

@@ -22,7 +22,7 @@ import java.util.*;
 @Configuration
 @EnableScheduling
 @ConditionalOnProperty(name = {"enable.scheduling"})
-public class ScheduleTaskNew {
+public class ScheduleTask2 {
 
     @Autowired
     private DDCoreClient ddCoreClient;

+ 200 - 0
src/main/java/com/malk/eastar/schedule/ScheduleTask3.java

@@ -0,0 +1,200 @@
+package com.malk.eastar.schedule;
+
+import com.alibaba.fastjson.JSONObject;
+import com.malk.eastar.service.AitableService;
+import com.malk.eastar.service.DDCoreClient;
+import com.malk.eastar.service.YidaService;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 新的定时任务
+ */
+@Slf4j
+@Configuration
+@EnableScheduling
+@ConditionalOnProperty(name = {"enable.scheduling"})
+public class ScheduleTask3 {
+
+    @Autowired
+    private AitableService aitableService;
+
+    @Autowired
+    private YidaService yidaService;
+
+    @Autowired
+    private DDCoreClient ddCoreClient;
+
+    /**
+     * 同步销售项目数据
+     */
+//    @Scheduled(cron = "0 0 11 * * ?")
+    public void syncSaleProjectData20260622() {
+        //查询所有AI表格已成单【表1】售前台账数据
+        List<Map> saleData = null;
+        try {
+            log.info("查询已成单【表1】售前台账记录");
+            saleData = aitableService.querySys1SaleData();
+        } catch (Exception e) {
+            log.error("查询售前台账数据异常",e);
+        }
+
+        //查询所有宜搭客户数据
+        List<Map> ltcCustomerData = new ArrayList<>();
+        try {
+            log.info("查询客户名册所有记录");
+            ltcCustomerData = yidaService.queryLtcAllCustomerData();
+        } catch (Exception e) {
+            log.error("查询客户名册异常",e);
+        }
+
+        if(saleData != null && !saleData.isEmpty()){
+            //查询所有宜搭销售项目数据
+            List<Map> ltcSaleProjectData = new ArrayList<>();
+            try {
+                log.info("查询销售台账所有记录");
+                ltcSaleProjectData = yidaService.queryLtcAllSaleProjectData();
+            } catch (Exception e) {
+                log.error("查询销售台账异常",e);
+            }
+            if(ltcSaleProjectData != null && !ltcSaleProjectData.isEmpty()){
+                boolean isExist = false;
+                boolean isFindCustomer = false;
+                String businessUserId = null;  //业务员userId
+                String customerName = null; //客户名称
+                String customerCode = null; //客户编号
+                for(Map saleRecord : saleData){ //遍历售前台账数据
+                    isExist = false;
+                    for (int i = 0; i < saleData.size(); i++) {
+                        if (saleRecord.get("piCode").equals(ltcSaleProjectData.get(i).get("piCode"))
+                            || saleRecord.get("aiTableId").equals(ltcSaleProjectData.get(i).get("aiTableId"))){
+                            isExist = true;
+                            break;
+                        }
+                    }
+                    if(!isExist){
+                        //获取关联客户信息
+                        isFindCustomer = false;
+                        businessUserId = null;
+                        customerName = null;
+                        customerCode = null;
+                        for (int i = 0; i < ltcCustomerData.size(); i++) {
+                            if(saleRecord.get("customerId").equals(ltcCustomerData.get(i).get("aiTableId"))){
+//                                System.out.println(JSONObject.toJSONString(ltcCustomerData.get(i)));
+                                businessUserId = ltcCustomerData.get(i).get("userId").toString();
+                                customerName = ltcCustomerData.get(i).get("customerName").toString();
+                                customerCode = ltcCustomerData.get(i).get("customerCode").toString();
+                                isFindCustomer = true;
+                                break;
+                            }
+                        }
+                        if(!isFindCustomer){
+                            System.err.println("未找到关联客户信息:"+saleRecord.get("piCode"));
+                        }else{
+                            if(StringUtils.isEmpty(businessUserId)){
+                                try {
+                                    System.err.println("未找到业务员信息:"+saleRecord.get("piCode"));
+                                    System.out.println("根据unionId获取userId:"+saleRecord.get("unionId"));
+                                    businessUserId = ddCoreClient.getUserIdByUnionId(saleRecord.get("unionId").toString());
+                                } catch (Exception e) {
+                                    log.error("根据unionId获取userId异常",e);
+                                }
+                            }
+                            saleRecord.put("businessUserId",businessUserId);
+                            saleRecord.put("customerName",customerName);
+                            saleRecord.put("customerCode",customerCode);
+                            try {
+                                log.info("{}开始同步",saleRecord.get("piCode"));
+//                                System.out.println(JSONObject.toJSONString(saleRecord));
+                                yidaService.insertSaleProjectData(saleRecord);
+                            } catch (Exception e) {
+                                log.error("同步销售台账异常",e);
+                            }
+                        }
+                    }else{
+                        log.info("{}已存在",saleRecord.get("projectName"));
+                    }
+
+
+                }
+            }
+
+
+
+        }
+
+
+
+    }
+
+    /**
+     * 同步销售项目数据(回写)
+     */
+//    @Scheduled(cron = "0 30 13 * * ?")
+    public void syncSaleProjectData20260623() {
+        //查询有原系统PI号的宜搭销售项目数据
+        List<Map> ltcSaleProjectData = new ArrayList<>();
+        try {
+            log.info("查询销售台账记录");
+            Map params = new HashMap<>();
+            params.put("piCodePrefix","Eastar");
+            ltcSaleProjectData = yidaService.queryLtcSaleProjectData(params);
+        } catch (Exception e) {
+            log.error("查询销售台账记录异常",e);
+        }
+        //查询所有AI表格已成单【表1】售前台账数据
+        List<Map> saleData = null;
+        try {
+            log.info("查询已成单【表1】售前台账记录");
+            saleData = aitableService.querySys1SaleData();
+        } catch (Exception e) {
+            log.error("查询售前台账数据异常",e);
+        }
+        //更新AI表格项目编码和原系统PI号
+        if(ltcSaleProjectData != null && !ltcSaleProjectData.isEmpty()){
+            boolean isUpdate;
+            String aitableId;
+            Map<String,Object> fields;
+            for(Map saleProjectRecord : ltcSaleProjectData){
+                isUpdate = false;
+                for (int i = 0; i < saleData.size(); i++) {
+                    if(saleProjectRecord.get("projectCode").equals(saleData.get(i).get("piCode"))){
+                        isUpdate = true;
+                        break;
+                    }
+                }
+                if(!isUpdate){  //未更新
+                    aitableId = saleProjectRecord.get("aiTableId").toString();
+                    fields = new HashMap<>();
+                    fields.put("zP1nHJs",saleProjectRecord.get("projectCode").toString());   //项目编号 - S1【基础】
+                    fields.put("gCc8jRg",saleProjectRecord.get("piCode").toString());   //原PI号
+                    try {
+                        log.info("更新销售台账记录");
+                        System.out.println("aitableId="+aitableId);
+                        System.out.println(JSONObject.toJSONString(fields));
+                        aitableService.updateSys1SaleData(aitableId,fields);
+                        Thread.sleep(3000);
+                    } catch (Exception e) {
+                        log.error("更新销售台账记录异常",e);
+                    }
+                }else{
+                    log.info("{}已更新过",saleProjectRecord.get("projectName"));
+                }
+
+            }
+
+        }
+    }
+
+
+}

+ 6 - 0
src/main/java/com/malk/eastar/service/AitableService.java

@@ -14,6 +14,12 @@ public interface AitableService {
      */
     List<Map> querySys1CustomerData() throws Exception;
 
+    /**
+     * 获取项目总表中的多行记录(售前台账)
+     * @return
+     */
+    List<Map> querySys1SaleData() throws Exception;
+
     /**
      * 根据客户名获取客户ID(客户名册)
      * @param customerName

+ 15 - 0
src/main/java/com/malk/eastar/service/YidaService.java

@@ -40,6 +40,16 @@ public interface YidaService {
      */
     List<Map> queryLtcAllCustomerData() throws Exception;
 
+    /**
+     * 获取易思达系统中的所有记录(销售台账)
+     */
+    List<Map> queryLtcAllSaleProjectData() throws Exception;
+
+    /**
+     * 筛选易思达系统中的记录(销售台账)
+     */
+    List<Map> queryLtcSaleProjectData(Map params) throws Exception;
+
     /**
      * 获取易思达系统中的未跟进客户
      */
@@ -121,6 +131,11 @@ public interface YidaService {
      */
     void insertCustomerData(Map row) throws Exception;
 
+    /**
+     * 插入易思达系统中的一行记录(销售台账)
+     */
+    void insertSaleProjectData(Map row) throws Exception;
+
     /**
      * 插入易思达系统中的一行记录(私海客户流出风险提示)
      */

+ 173 - 0
src/main/java/com/malk/eastar/service/impl/AitableServiceImpl.java

@@ -12,6 +12,8 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.util.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 /**
  * 专用于AI表格复杂逻辑处理的接口服务
@@ -263,6 +265,177 @@ public class AitableServiceImpl implements AitableService {
         return customerDataDeduplicate;
     }
 
+    @Override
+    public List<Map> querySys1SaleData() throws Exception {
+        /*
+            参数定义
+         */
+        List<Map> saleData = new ArrayList<>(); //售前台账数据
+        String baseId; //AI表格文档ID
+        String sheetIdOrName;   //数据表ID或数据表名称
+        Map<String,Object> param = new HashMap<>(); //HTTP请求参数
+        AITableParam aiTableParam = new AITableParam(); //HTTP请求体
+        boolean hasMore; //是否还有下一页
+        int pageNo; //当前页码
+        int pageSize;   //每页获取的数据量(上限100)
+        AITableResult aiTableResult;    //请求返回内容
+        JSONArray records;  //每页记录数据
+        JSONArray allRecords = new JSONArray();  //所有记录数据
+        String aiTableId;   //AI表格ID
+        JSONObject fields;  //字段数据
+        Map<String,Object> saleRecord;  //售前台账记录
+        String piCode;  //原PI号
+        String projectName;  //项目名称
+        String projectEnName;  //项目英文名
+        String pName;  //项目名称缩写
+        Double projectAmount;   //预计销售项目金额
+        JSONArray linkedRecordIds;  //客户公司名 - S1【基础】
+        String customerId;  //客户ID
+        Long expectedCloseDate; //预计成单日期
+        Long actualCloseDate;   //实际成单日期
+        JSONArray unionIdJSONArray;  //业务 - S1【人事】
+        String unionId;  //业务员ID
+
+
+
+        /*
+            项目总表 - 【表1】售前台账
+         */
+        baseId = "G53mjyd80pEr5grBfpjmMX6586zbX04v";
+        sheetIdOrName = "C1mtX34";
+
+        /*
+            初始化参数值
+         */
+        hasMore = true; //第一页默认有数据
+        pageNo = 1;
+        pageSize = 100;
+        param.put("operatorId","aj1wcWqKLXITiPDwbMIjUbAiEiE");  //操作人(Jason)的unionId
+        aiTableParam.setMaxResults(pageSize);
+        JSONObject filter = new JSONObject();
+        filter.put("combination","and");
+        JSONArray conditions = new JSONArray();
+        JSONObject condition1 = new JSONObject();
+        condition1.put("field","商机阶段 - S1~3【商机进度】");
+        condition1.put("operator","equal");
+        condition1.put("value",new String[]{"已成单"});
+        conditions.add(condition1);
+        JSONObject condition2 = new JSONObject();
+        condition2.put("field","项目编号 - S1【基础】");
+        condition2.put("operator","notEmpty");
+        conditions.add(condition2);
+        filter.put("conditions",conditions);
+        JSONObject condition3 = new JSONObject();
+        condition3.put("field","Parent Record");
+        condition3.put("operator","empty");
+        conditions.add(condition3);
+        filter.put("conditions",conditions);
+        aiTableParam.setFilter(filter);
+
+        /*
+            翻页获取数据
+         */
+        while(hasMore){
+            aiTableResult = mdTableClient.queryMultiRecords(baseId,sheetIdOrName,param,aiTableParam);
+            hasMore = aiTableResult.getHasMore();
+            log.info("当前第"+pageNo+"页");
+            log.info("记录数="+aiTableResult.getRecords().size());
+            records = aiTableResult.getRecords();
+            for(int i=0;i<records.size();i++){
+                allRecords.add(records.getJSONObject(i));
+            }
+            log.info("是否有更多数据:"+hasMore);
+            pageNo++;
+            aiTableParam.setNextToken(aiTableResult.getNextToken());
+        }
+
+        /*
+            请求记录数据处理
+         */
+        log.info("所有记录数量="+allRecords.size());
+        for(int i=0;i<allRecords.size();i++){
+            //重置变量
+            piCode = "";
+            projectName = "";
+            projectEnName = "";
+            pName = "";
+            projectAmount = null;
+            customerId = "";
+            expectedCloseDate = null;
+            actualCloseDate = null;
+            unionId = "";
+
+            //获取AI表格ID
+            aiTableId = allRecords.getJSONObject(i).getString("id");
+
+            //解析字段数据
+            fields = allRecords.getJSONObject(i).getJSONObject("fields");
+
+            if(fields.get("项目编号 - S1【基础】") != null){
+                piCode = fields.getString("项目编号 - S1【基础】");
+                piCode = piCode.replace("\n",""); //去除换行符
+                piCode = piCode.trim(); //去除空格
+                Matcher matcher = Pattern.compile("Eastar-?([A-Za-z]+)").matcher(piCode);
+                if (matcher.find()) {
+                    pName = matcher.group(1);
+                    if(pName != null && pName.length()>0){
+                        pName = pName.toUpperCase();    //转大写
+                        if(pName.length()>5){
+                            pName = pName.substring(0,5);   //最大5个字符
+                        }
+                    }
+                }
+            }
+            if(fields.get("项目名称 - S1【基础】") != null){
+                projectName = fields.getString("项目名称 - S1【基础】");
+                projectName = projectName.replace("\n",""); //去除换行符
+                projectName = projectName.trim(); //去除空格
+            }
+            if(fields.get("项目英文名 - S1【基础") != null){
+                projectEnName = fields.getString("项目英文名 - S1【基础");
+                projectEnName = projectEnName.replace("\n",""); //去除换行符
+                projectEnName = projectEnName.trim(); //去除空格
+            }
+            if(fields.get("订单金额 - S2~3【销售数据】") != null){
+                projectAmount = fields.getDouble("订单金额 - S2~3【销售数据】");
+            }
+            if(fields.get("客户公司名 - S1【基础】") != null){
+                linkedRecordIds = fields.getJSONObject("客户公司名 - S1【基础】").getJSONArray("linkedRecordIds");
+                if(linkedRecordIds!=null && !linkedRecordIds.isEmpty()){
+                    customerId = linkedRecordIds.getString(0);
+                }
+            }
+            if(fields.get("预计成单日期 - S1~2【商机进度】") != null){
+                expectedCloseDate = fields.getLong("预计成单日期 - S1~2【商机进度】");
+            }
+            if(fields.get("实际成单日期 - S3【销售数据】") != null){
+                actualCloseDate = fields.getLong("实际成单日期 - S3【销售数据】");
+            }
+            if(fields.get("业务 - S1【人事】") != null){
+                unionIdJSONArray = fields.getJSONArray("业务 - S1【人事】");
+                if(unionIdJSONArray!=null && !unionIdJSONArray.isEmpty()){
+                    unionId = unionIdJSONArray.getJSONObject(0).getString("unionId");
+                }
+            }
+
+            saleRecord = new HashMap<>();
+            saleRecord.put("aiTableId",aiTableId);
+            saleRecord.put("piCode",piCode);
+            saleRecord.put("projectName",projectName);
+            saleRecord.put("projectEnName",projectEnName);
+            saleRecord.put("pName",pName);
+            saleRecord.put("projectAmount",projectAmount);
+            saleRecord.put("customerId",customerId);
+            saleRecord.put("expectedCloseDate",expectedCloseDate);
+            saleRecord.put("actualCloseDate",actualCloseDate);
+            saleRecord.put("unionId",unionId);
+            System.out.println(JSONObject.toJSONString(saleRecord));
+            saleData.add(saleRecord);
+        }
+
+        return saleData;
+    }
+
     @Override
     public String querySys1CustomerIdByName(String customerName) throws Exception {
         /*

+ 245 - 1
src/main/java/com/malk/eastar/service/impl/YidaServiceImpl.java

@@ -967,6 +967,7 @@ public class YidaServiceImpl implements YidaService {
         String formInstId;  //表单实例ID
         Map customerRecord;  //客户记录
         String customerName;
+        String customerCode;
         JSONArray businessUserIdJSONArray;  //业务员userId
         String userId;  //用户userId
         String userIdText;
@@ -1010,6 +1011,7 @@ public class YidaServiceImpl implements YidaService {
         for (Map ltcCustomerRecord : allRecords){
             userId = "";
             customerName = "";
+            customerCode = "";
             //获取表单实例ID
             formInstId = String.valueOf(ltcCustomerRecord.get("formInstanceId"));
             //解析字段数据
@@ -1027,12 +1029,14 @@ public class YidaServiceImpl implements YidaService {
             userIdText = String.valueOf(ltcCustomerRecord.get("textField_mnchujji"));
 
             customerName = fields.getString("textField_lqanqe6j");
+            customerCode = fields.getString("serialNumberField_lqanqe6i");
 
             //生成客户数据
             customerRecord = UtilMap.map(
-                    "formInstId, customerName, userId, userIdText, customerLevel, customerPotentialLevel, newOrOld, testUseFlag, aiTableId",
+                    "formInstId, customerName, customerCode, userId, userIdText, customerLevel, customerPotentialLevel, newOrOld, testUseFlag, aiTableId",
                     formInstId, //表单实例ID
                     customerName, //客户公司名(英文名)
+                    customerCode,   //客户编号
                     userId,  //业务
                     userIdText,
                     fields.getString("selectField_mcsoft5i"),    //客户当前分级
@@ -1047,6 +1051,174 @@ public class YidaServiceImpl implements YidaService {
         return ltcCustomerData;
     }
 
+    @Override
+    public List<Map> queryLtcAllSaleProjectData() throws Exception {
+        /*
+            参数定义
+         */
+        List<Map> saleProjectData = new ArrayList<>();
+        YDParam yidaParam;  //HTTP请求体
+        YDParam.YDParamBuilder ydParamBuilder; //宜搭参数构建
+        DDR_New yidaResult; //请求返回内容
+        List<Map> records;  //每页记录数据
+        List<Map> allRecords = new ArrayList<>();  //所有记录数据
+        boolean hasMore; //是否还有下一页
+        int pageNo; //当前页码
+        int pageSize;   //每页获取的数据量(上限100)
+        JSONObject fields;  //字段数据
+        String formInstId;  //表单实例ID
+        Map saleProjectRecord;  //销售项目记录
+
+        /*
+            初始化参数值
+         */
+        hasMore = true; //第一页默认有数据
+        pageNo = 1;
+        pageSize = 100;
+        ydParamBuilder = YDParam.builder();
+        ydParamBuilder = ydParamBuilder.formUuid(EastarParam.YD_FORMUUID_SALE_PROJECT);
+
+        /*
+            翻页获取数据
+         */
+        while(hasMore){
+            ydParamBuilder = ydParamBuilder.pageNumber(pageNo);
+            ydParamBuilder = ydParamBuilder.pageSize(pageSize);
+            yidaParam = ydParamBuilder.build();
+            yidaResult = ydClient.queryData(yidaParam,YDConf.FORM_QUERY.retrieve_list);
+            log.info("当前第"+pageNo+"页");
+            records = (List<Map>) yidaResult.getData();
+            log.info("记录数="+records.size());
+            for (Map record : records){
+                allRecords.add(record);
+            }
+            if((pageNo*pageSize) < yidaResult.getTotalCount()){
+                pageNo++;
+            }else{
+                hasMore = false;
+            }
+            log.info("是否有更多数据:"+hasMore);
+            Thread.sleep(3000);
+        }
+
+        /*
+            请求记录数据处理
+         */
+        log.info("所有记录数量="+allRecords.size());
+        for (Map ltcSaleProjectRecord : allRecords){
+            //获取表单实例ID
+            formInstId = String.valueOf(ltcSaleProjectRecord.get("formInstanceId"));
+            //解析字段数据
+            fields = JSONObject.parseObject(JSONObject.toJSONString(ltcSaleProjectRecord.get("formData")));
+
+            saleProjectRecord = UtilMap.map(
+                    "formInstId, projectCode, projectName, piCode, aiTableId",
+                    formInstId, //表单实例ID
+                    fields.getString("serialNumberField_mdf997w0"), //项目编号
+                    fields.getString("textField_mdf997vz"), //项目名称
+                    fields.getString("textField_mhlrjdz2"), //原系统PI号
+                    fields.getString("textField_mno9p0lf")  //AI表格映射ID
+            );
+
+            saleProjectData.add(saleProjectRecord);
+
+        }
+
+        return saleProjectData;
+    }
+
+    @Override
+    public List<Map> queryLtcSaleProjectData(Map params) throws Exception {
+        /*
+            参数定义
+         */
+        List<Map> saleProjectData = new ArrayList<>();
+        List<YDSearch> ydSearchList = new ArrayList<>(); //检索条件(多个)
+        YDSearch ydSearch; //检索条件(单个)
+        String searchCondition; //检索条件
+        YDParam yidaParam;  //HTTP请求体
+        YDParam.YDParamBuilder ydParamBuilder; //宜搭参数构建
+        DDR_New yidaResult; //请求返回内容
+        List<Map> records;  //每页记录数据
+        List<Map> allRecords = new ArrayList<>();  //所有记录数据
+        boolean hasMore; //是否还有下一页
+        int pageNo; //当前页码
+        int pageSize;   //每页获取的数据量(上限100)
+        JSONObject fields;  //字段数据
+        String formInstId;  //表单实例ID
+        Map saleProjectRecord;  //销售项目记录
+
+        /*
+            初始化参数值
+         */
+        if(params.containsKey("piCodePrefix")){
+            ydSearch = new YDSearch(
+                    "textField_mhlrjdz2",
+                    params.get("piCodePrefix").toString(),
+                    "原系统PI号",
+                    YDSearch.Type.TEXT_FIELD,
+                    YDSearch.Operator.LIKE
+            );
+            ydSearchList.add(ydSearch);
+        }
+        searchCondition = JSONObject.toJSONString(ydSearchList);
+        hasMore = true; //第一页默认有数据
+        pageNo = 1;
+        pageSize = 100;
+        ydParamBuilder = YDParam.builder();
+        ydParamBuilder = ydParamBuilder.formUuid(EastarParam.YD_FORMUUID_SALE_PROJECT);
+        ydParamBuilder = ydParamBuilder.searchCondition(searchCondition);
+
+        /*
+            翻页获取数据
+         */
+        while(hasMore){
+            ydParamBuilder = ydParamBuilder.pageNumber(pageNo);
+            ydParamBuilder = ydParamBuilder.pageSize(pageSize);
+            yidaParam = ydParamBuilder.build();
+            yidaResult = ydClient.queryData(yidaParam,YDConf.FORM_QUERY.retrieve_list);
+            log.info("当前第"+pageNo+"页");
+            records = (List<Map>) yidaResult.getData();
+            log.info("记录数="+records.size());
+            for (Map record : records){
+                allRecords.add(record);
+            }
+            if((pageNo*pageSize) < yidaResult.getTotalCount()){
+                pageNo++;
+            }else{
+                hasMore = false;
+            }
+            log.info("是否有更多数据:"+hasMore);
+            Thread.sleep(3000);
+        }
+
+
+
+        /*
+            请求记录数据处理
+         */
+        log.info("所有记录数量="+allRecords.size());
+        for (Map ltcSaleProjectRecord : allRecords){
+            //获取表单实例ID
+            formInstId = String.valueOf(ltcSaleProjectRecord.get("formInstanceId"));
+            //解析字段数据
+            fields = JSONObject.parseObject(JSONObject.toJSONString(ltcSaleProjectRecord.get("formData")));
+
+            saleProjectRecord = UtilMap.map(
+                    "formInstId, projectCode, projectName, piCode, aiTableId",
+                    formInstId, //表单实例ID
+                    fields.getString("serialNumberField_mdf997w0"), //项目编号
+                    fields.getString("textField_mdf997vz"), //项目名称
+                    fields.getString("textField_mhlrjdz2"), //原系统PI号
+                    fields.getString("textField_mno9p0lf")  //AI表格映射ID
+            );
+            saleProjectData.add(saleProjectRecord);
+
+        }
+
+        return saleProjectData;
+    }
+
     @Override
     public List<Map> queryLtcNotFollowedCustomerData(List ydFilters) throws Exception {
         /*
@@ -1645,6 +1817,78 @@ public class YidaServiceImpl implements YidaService {
         System.out.println("新增一条客户记录");
     }
 
+    @Override
+    public void insertSaleProjectData(Map row) throws Exception {
+        YDParam yidaParam;  //HTTP请求体
+        YDParam.YDParamBuilder ydParamBuilder; //宜搭参数构建
+
+        String businessUserId = "";
+        String[] businessUserIdArr = new String[]{};
+        if(row.get("businessUserId")!=null){
+            businessUserId = row.get("businessUserId").toString();
+            businessUserIdArr = new String[]{row.get("businessUserId").toString()};
+        }
+
+        List customerField = new ArrayList();
+        Map customerFieldVal = new HashMap();
+        customerFieldVal.put("appType","APP_GM7D1NW6XCD0ZJBPVH51");
+        customerFieldVal.put("formUuid","FORM-9261FABA687B4D1D917617F53B4A5DB7UN16"); //客户
+        customerFieldVal.put("formType","receipt");
+        customerFieldVal.put("instanceId",row.get("customerId"));
+        customerFieldVal.put("title",row.get("customerName"));
+        customerFieldVal.put("subTitle",row.get("customerCode"));
+        customerField.add(customerFieldVal);
+
+        Map saleProjectRecord = UtilMap.map(
+                "textField_mdf997vz, "  //项目名称
+                +"textField_mdf997wb, " //项目英文名
+                +"textField_mgrg3348, " //项目名称缩写
+                +"associationFormField_mdf997wc, " //客户
+                +"textField_mn48rz8y, " //客户公司名(英文名)
+                +"textField_mdpb1gh1, " //客户编号
+                +"employeeField_mdf997x2, " //业务员
+                +"textField_mnctph7f, " //业务员userId
+                +"selectField_mdf997ws, " //销售项目状态
+                +"selectField_mdf997wp, " //整体项目阶段
+                +"selectField_mfkv8ou2, " //成单情况
+                +"numberField_mdf997x6, " //预计销售项目金额(美元)
+                +"dateField_mdf997x7, " //预计成单日期
+                +"dateField_mfm5x6cl, " //实际成单日期
+                +"textField_mgykaadz, " //全局汇率单位
+                +"textField_mhlrjdz2, " //原系统PI号
+                +"textField_mno9p0lf, " //AI表格映射ID
+                +"radioField_mo0xt19d, " //是否特殊客户
+                +"radioField_mnppbub6", //测试使用
+                row.get("projectName"),
+                row.get("projectEnName"),
+                row.get("pName"),
+                customerField,
+                row.get("customerName"),
+                row.get("customerCode"),
+                businessUserIdArr,
+                businessUserId,
+                "已完成",
+                "S3:已签单",
+                "已成单",
+                row.get("projectAmount"),
+                row.get("expectedCloseDate"),
+                row.get("actualCloseDate"),
+                "美元/人民币",
+                row.get("piCode"),
+                row.get("aiTableId"),
+                "否",
+                "否"
+        );
+        String insertFormDataJson = JSONObject.toJSONString(saleProjectRecord);
+        System.out.println(insertFormDataJson);
+        ydParamBuilder = YDParam.builder();
+        ydParamBuilder = ydParamBuilder.formUuid(EastarParam.YD_FORMUUID_SALE_PROJECT);
+        ydParamBuilder = ydParamBuilder.formDataJson(insertFormDataJson);
+        yidaParam = ydParamBuilder.build();
+        ydClient.operateData(yidaParam,YDConf.FORM_OPERATION.create);
+        System.out.println("新增一条销售项目记录");
+    }
+
     @Override
     public void addAlertDetail(Map row) throws Exception {
         YDParam yidaParam;  //HTTP请求体