|
|
@@ -179,10 +179,10 @@ public class AitableServiceImpl implements AitableService {
|
|
|
||"潜C".equals(customerLevel)
|
|
|
||"D".equals(customerLevel)
|
|
|
||"潜D".equals(customerLevel)
|
|
|
+ ||"E".equals(customerLevel)
|
|
|
+ ||"保稳E".equals(customerLevel)
|
|
|
){
|
|
|
//不变
|
|
|
- }else if("E".equals(customerLevel)){
|
|
|
- customerLevel = "保稳E";
|
|
|
}else{
|
|
|
customerLevel = "";
|
|
|
}
|
|
|
@@ -265,6 +265,166 @@ public class AitableServiceImpl implements AitableService {
|
|
|
return customerDataDeduplicate;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<Map> querySys1AllSaleData() 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","Parent Record");
|
|
|
+ condition1.put("operator","empty");
|
|
|
+ conditions.add(condition1);
|
|
|
+ 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);
|
|
|
+ saleData.add(saleRecord);
|
|
|
+ }
|
|
|
+
|
|
|
+ return saleData;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public List<Map> querySys1SaleData() throws Exception {
|
|
|
/*
|
|
|
@@ -429,7 +589,7 @@ public class AitableServiceImpl implements AitableService {
|
|
|
saleRecord.put("expectedCloseDate",expectedCloseDate);
|
|
|
saleRecord.put("actualCloseDate",actualCloseDate);
|
|
|
saleRecord.put("unionId",unionId);
|
|
|
- System.out.println(JSONObject.toJSONString(saleRecord));
|
|
|
+// System.out.println(JSONObject.toJSONString(saleRecord));
|
|
|
saleData.add(saleRecord);
|
|
|
}
|
|
|
|
|
|
@@ -811,5 +971,49 @@ public class AitableServiceImpl implements AitableService {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public String addCustomerABDevData(Map<String, Object> fields) throws Exception {
|
|
|
+ /*
|
|
|
+ 参数定义
|
|
|
+ */
|
|
|
+ String baseId; //AI表格文档ID
|
|
|
+ String sheetIdOrName; //数据表ID或数据表名称
|
|
|
+ Map<String,Object> param = new HashMap<>(); //HTTP请求参数
|
|
|
+ JSONObject insertData = new JSONObject(); //HTTP请求体
|
|
|
+ JSONArray insertRecords = new JSONArray(); //新增记录集合
|
|
|
+ JSONObject insertRecord = new JSONObject(); //新增记录行数据
|
|
|
+ String result; //返回结果
|
|
|
+ JSONObject resultJSONObject;
|
|
|
+ JSONArray aitableIdJSONArray;
|
|
|
+ String aitableId = ""; //AI表格记录ID
|
|
|
+
|
|
|
+ /*
|
|
|
+ 项目总表
|
|
|
+ */
|
|
|
+ baseId = "G53mjyd80pEr5grBfpjmMX6586zbX04v";
|
|
|
+ sheetIdOrName = "S4bMyJU";
|
|
|
+
|
|
|
+ /*
|
|
|
+ 初始化参数值
|
|
|
+ */
|
|
|
+ param.put("operatorId","aj1wcWqKLXITiPDwbMIjUbAiEiE"); //操作人(Jason)的unionId
|
|
|
+ insertRecord.put("fields",fields);
|
|
|
+ insertRecords.add(insertRecord);
|
|
|
+ insertData.put("records",insertRecords);
|
|
|
+
|
|
|
+ /*
|
|
|
+ 新增数据
|
|
|
+ */
|
|
|
+ log.info(JSONObject.toJSONString(insertData));
|
|
|
+ result = mdTableClient.createMultiRecords(baseId,sheetIdOrName,param,insertData);
|
|
|
+ log.info(result);
|
|
|
+ resultJSONObject = JSONObject.parseObject(result);
|
|
|
+ aitableIdJSONArray = resultJSONObject.getJSONArray("value");
|
|
|
+ if(aitableIdJSONArray!=null || !aitableIdJSONArray.isEmpty()){
|
|
|
+ aitableId = aitableIdJSONArray.getJSONObject(0).getString("id");
|
|
|
+ }
|
|
|
+ return aitableId;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|