|
@@ -1,6 +1,7 @@
|
|
|
package com.malk.zhiwei.service.impl;
|
|
package com.malk.zhiwei.service.impl;
|
|
|
|
|
|
|
|
import cn.hutool.http.HttpUtil;
|
|
import cn.hutool.http.HttpUtil;
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
@@ -12,9 +13,13 @@ import com.kingdee.bos.webapi.sdk.K3CloudApi;
|
|
|
import com.malk.server.aliwork.YDConf;
|
|
import com.malk.server.aliwork.YDConf;
|
|
|
import com.malk.server.aliwork.YDParam;
|
|
import com.malk.server.aliwork.YDParam;
|
|
|
import com.malk.server.common.McR;
|
|
import com.malk.server.common.McR;
|
|
|
|
|
+import com.malk.server.common.VenR;
|
|
|
import com.malk.server.dingtalk.DDConf;
|
|
import com.malk.server.dingtalk.DDConf;
|
|
|
|
|
+import com.malk.server.dingtalk.DDR;
|
|
|
import com.malk.service.aliwork.YDClient;
|
|
import com.malk.service.aliwork.YDClient;
|
|
|
|
|
+import com.malk.service.dingtalk.DDClient;
|
|
|
import com.malk.utils.PublicUtil;
|
|
import com.malk.utils.PublicUtil;
|
|
|
|
|
+import com.malk.utils.UtilHttp;
|
|
|
import com.malk.utils.UtilMap;
|
|
import com.malk.utils.UtilMap;
|
|
|
import com.malk.zhiwei.config.KDWebApiConf;
|
|
import com.malk.zhiwei.config.KDWebApiConf;
|
|
|
import com.malk.zhiwei.entity.BillQuery;
|
|
import com.malk.zhiwei.entity.BillQuery;
|
|
@@ -27,6 +32,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
@Service
|
|
@Service
|
|
|
@Slf4j
|
|
@Slf4j
|
|
@@ -38,6 +44,8 @@ public class ZwServiceImpl implements ZwService {
|
|
|
private YDConf ydConf;
|
|
private YDConf ydConf;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private DDConf ddConf;
|
|
private DDConf ddConf;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private DDClient ddClient;
|
|
|
|
|
|
|
|
private static String ERP_URL="http://10.0.0.208:80";
|
|
private static String ERP_URL="http://10.0.0.208:80";
|
|
|
private static String ERP_NAME="064";
|
|
private static String ERP_NAME="064";
|
|
@@ -248,9 +256,10 @@ public class ZwServiceImpl implements ZwService {
|
|
|
BillQuery billQuery = new BillQuery();
|
|
BillQuery billQuery = new BillQuery();
|
|
|
billQuery.setFormId("BD_MATERIAL");//产品信息
|
|
billQuery.setFormId("BD_MATERIAL");//产品信息
|
|
|
//编码 名称 规格型号 旧物料编码 物料分组 物料属性 基本单位 长 宽 高 体积 面积 密度 标准工时
|
|
//编码 名称 规格型号 旧物料编码 物料分组 物料属性 基本单位 长 宽 高 体积 面积 密度 标准工时
|
|
|
- billQuery.setFieldKeys("FNumber,FName,FSpecification,FOldNumber,FMaterialGroup,FErpClsID,FBaseUnitId,FLENGTH,FWIDTH,FHEIGHT,FVOLUME,F_UNW_Qty_r03,F_UNW_Qty_6yt,FPerUnitStandHour");
|
|
|
|
|
|
|
+ billQuery.setFieldKeys("FCreateOrgId.FNumber,FApproveDate,FNumber,FName,FSpecification,FOldNumber,FMaterialGroup,FErpClsID,FBaseUnitId,FLENGTH,FWIDTH,FHEIGHT,FVOLUME,F_UNW_Qty_r03,F_UNW_Qty_6yt,FPerUnitStandHour");
|
|
|
List<Map> filterString = new ArrayList<>();
|
|
List<Map> filterString = new ArrayList<>();
|
|
|
- filterString.add(UtilMap.map("FieldName, Compare, Value, Left, Right, Logic","FApproveDate","265",1,"","","0"));//审核日期在今天之前N天以后
|
|
|
|
|
|
|
+ filterString.add(UtilMap.map("FieldName, Compare, Value, Left, Right, Logic","FApproveDate","265",3,"","","0"));//审核日期在今天之前N天以后
|
|
|
|
|
+ filterString.add(UtilMap.map("FieldName, Compare, Value, Left, Right, Logic","FCreateOrgId.FNumber","67","101","","","0"));//创建组织为101 研发中心
|
|
|
billQuery.setFilterString(filterString);
|
|
billQuery.setFilterString(filterString);
|
|
|
billQuery.setLimit(limit);
|
|
billQuery.setLimit(limit);
|
|
|
billQuery.setStartRow(startRow);
|
|
billQuery.setStartRow(startRow);
|
|
@@ -472,7 +481,7 @@ public class ZwServiceImpl implements ZwService {
|
|
|
//[明细表] FMapId客户物料编码 FMapName客户物料名称 FMaterialId物料编码 FMaterialName物料名称 FMaterialModel型号规格 FF100001厚度 FSalUnitID销售单位 FSalUnitQty销售数量 FIsFree是否赠品 FDeliveryDate退货日期 FReturnType退货类型 FPrice单价 FTaxPrice含税单价 FNote备注
|
|
//[明细表] FMapId客户物料编码 FMapName客户物料名称 FMaterialId物料编码 FMaterialName物料名称 FMaterialModel型号规格 FF100001厚度 FSalUnitID销售单位 FSalUnitQty销售数量 FIsFree是否赠品 FDeliveryDate退货日期 FReturnType退货类型 FPrice单价 FTaxPrice含税单价 FNote备注
|
|
|
billQuery.setFieldKeys("FBillNo,FDate,FRetcustId.FName,FSettleCurrId.FName,FSaleOrgId.FName,FSaledeptid.FName,FSalesManId.FName,FMapId.FNumber,FMapName,FMaterialId.FNumber,FMaterialName,FMaterialModel,FAuxpropId.FF100001,FSalUnitID.FName,FSalUnitQty,FIsFree,FDeliveryDate,FReturnType.FDataValue,FPrice,FTaxPrice,FNote");
|
|
billQuery.setFieldKeys("FBillNo,FDate,FRetcustId.FName,FSettleCurrId.FName,FSaleOrgId.FName,FSaledeptid.FName,FSalesManId.FName,FMapId.FNumber,FMapName,FMaterialId.FNumber,FMaterialName,FMaterialModel,FAuxpropId.FF100001,FSalUnitID.FName,FSalUnitQty,FIsFree,FDeliveryDate,FReturnType.FDataValue,FPrice,FTaxPrice,FNote");
|
|
|
List<Map> filterString = new ArrayList<>();
|
|
List<Map> filterString = new ArrayList<>();
|
|
|
- filterString.add(UtilMap.map("FieldName, Compare, Value, Left, Right, Logic","FApproveDate","265",1,"","","0"));//审核日期在今天之前N天以后
|
|
|
|
|
|
|
+ filterString.add(UtilMap.map("FieldName, Compare, Value, Left, Right, Logic","FApproveDate","265",30,"","","0"));//审核日期在今天之前N天以后
|
|
|
billQuery.setFilterString(filterString);
|
|
billQuery.setFilterString(filterString);
|
|
|
billQuery.setLimit(limit);
|
|
billQuery.setLimit(limit);
|
|
|
billQuery.setStartRow(startRow);
|
|
billQuery.setStartRow(startRow);
|
|
@@ -876,6 +885,79 @@ public class ZwServiceImpl implements ZwService {
|
|
|
log.info("应收单(无发票号)已同步,共处理 {} 张单据", orderList.size());
|
|
log.info("应收单(无发票号)已同步,共处理 {} 张单据", orderList.size());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @SneakyThrows
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void customer() throws JsonProcessingException {
|
|
|
|
|
+ K3CloudApi client = new K3CloudApi(initIden());
|
|
|
|
|
+ int startRow = 0;
|
|
|
|
|
+ int limit = 2000;
|
|
|
|
|
+ BillQuery billQuery = new BillQuery();
|
|
|
|
|
+ billQuery.setFormId("BD_Customer");//客户
|
|
|
|
|
+ //客户编码 客户名称 业务员 销售员 销售部门 收款条件 行业 事业部 终端 纳税人登记号
|
|
|
|
|
+ billQuery.setFieldKeys("FNumber,FName,F_UNW_Text_6mb,FSELLER.FName,FSALDEPTID.FName,FRECCONDITIONID.FName,F_UNW_Assistant_mo2.FDataValue,F_UNW_Assistant_9zp.FNumber,F_UNW_Assistant_qov.FNumber,FTAXREGISTERCODE");
|
|
|
|
|
+ List<Map> filterString = new ArrayList<>();
|
|
|
|
|
+// filterString.add(UtilMap.map("FieldName, Compare, Value, Left, Right, Logic","FApproveDate","265",3,"","","0"));//审核日期在今天之前N天以后
|
|
|
|
|
+ filterString.add(UtilMap.map("FieldName, Compare, Value, Left, Right, Logic","FCreateOrgId.FNumber","67","100","","","0"));//创建组织为100 宁波致微新材料科技有限公司
|
|
|
|
|
+ billQuery.setFilterString(filterString);
|
|
|
|
|
+ billQuery.setLimit(limit);
|
|
|
|
|
+ billQuery.setStartRow(startRow);
|
|
|
|
|
+ String result=client.billQuery(JSONObject.toJSONString(billQuery));
|
|
|
|
|
+ JSONArray jsonArray = JSONArray.parseArray(result);
|
|
|
|
|
+ // 遍历每条物料记录
|
|
|
|
|
+ for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
|
|
+ JSONObject item = jsonArray.getJSONObject(i);
|
|
|
|
|
+
|
|
|
|
|
+ // 取出各个字段(注意类型转换)
|
|
|
|
|
+ String bm = item.getString("FNumber");//客户编码
|
|
|
|
|
+ String khmc = item.getString("FName");//客户名称
|
|
|
|
|
+
|
|
|
|
|
+ String ywy = item.getString("F_UNW_Text_6mb");//业务员
|
|
|
|
|
+ Map body = new HashMap();
|
|
|
|
|
+ body.put("queryWord",ywy);
|
|
|
|
|
+ body.put("offset",0);
|
|
|
|
|
+ body.put("size",10);
|
|
|
|
|
+ body.put("fullMatchField",1);
|
|
|
|
|
+ String doPost = UtilHttp.doPost("https://api.dingtalk.com/v1.0/contact/users/search", ddClient.initTokenHeader(), null, body);
|
|
|
|
|
+ JSONObject resp = JSON.parseObject(doPost);
|
|
|
|
|
+ JSONArray ywy_array = resp != null ? resp.getJSONArray("list") : null;
|
|
|
|
|
+
|
|
|
|
|
+ String xsbm = item.getString("FSALDEPTID.FName");//销售部门
|
|
|
|
|
+ Map body_A = new HashMap();
|
|
|
|
|
+ body_A.put("queryWord",xsbm);
|
|
|
|
|
+ body_A.put("offset",0);
|
|
|
|
|
+ body_A.put("size",10);
|
|
|
|
|
+ // 获取部门搜索结果
|
|
|
|
|
+ String doPost_A = UtilHttp.doPost("https://api.dingtalk.com/v1.0/contact/departments/search", ddClient.initTokenHeader(), null, body_A);
|
|
|
|
|
+ JSONObject respA = JSON.parseObject(doPost_A);
|
|
|
|
|
+ JSONArray aaary = respA != null ? respA.getJSONArray("list") : null;
|
|
|
|
|
+ List<String> xsbm_array = new ArrayList<>();
|
|
|
|
|
+ if (aaary != null && !aaary.isEmpty()) {
|
|
|
|
|
+ xsbm_array = aaary.stream()
|
|
|
|
|
+ .map(Object::toString)
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ }
|
|
|
|
|
+// 如果未查到部门,xsbm_array 保持为空列表
|
|
|
|
|
+
|
|
|
|
|
+ String sktj = item.getString("FRECCONDITIONID.FName");//收款条件
|
|
|
|
|
+ String hy = item.getString("F_UNW_Assistant_mo2.FDataValue");//行业
|
|
|
|
|
+ String syb = item.getString("F_UNW_Assistant_9zp.FNumber");//事业部
|
|
|
|
|
+ String zd = item.getString("F_UNW_Assistant_qov.FNumber");//终端
|
|
|
|
|
+ String sh = item.getString("FTAXREGISTERCODE");//纳税登记号
|
|
|
|
|
+ //TODO:向宜搭插入数据
|
|
|
|
|
+// String sc = "textField_mnr290ot, employeeField_lqanqe6n_id, employeeField_lqanqe6n_id, departmentSelectField_lympbaya, selectField_mnft99uc, selectField_lqanqe6t, selectField_mnft99ud, selectField_mnft99ue,textField_mn2k7pjl,textField_llujklkq";
|
|
|
|
|
+ String sc = "textField_mnr290ot, textField_lqanqe6j, employeeField_lqanqe6n, departmentSelectField_lympbaya, selectField_lqanqe6t, selectField_mnft99uc, selectField_mnft99ud, selectField_mnft99ue, textField_mn2k7pjl, textField_llujklkq";
|
|
|
|
|
+ List<Map> conditions = Arrays.asList( YDConf.searchCondition_TextFiled("textField_lqanqe6j", khmc, "eq"));//根据客户名称
|
|
|
|
|
+ Map formData = UtilMap.map(sc,bm,khmc,ywy_array,xsbm_array,hy,sktj,syb,zd,sh,sh);
|
|
|
|
|
+ ydClient.operateData(YDParam.builder()
|
|
|
|
|
+ .formUuid("FORM-A4C9F5F35B48419A9C607D3408ECAB02A7FL")
|
|
|
|
|
+ .searchCondition(JSONObject.toJSONString(conditions))
|
|
|
|
|
+ .formDataJson(JSONObject.toJSONString(formData))
|
|
|
|
|
+ .build(),YDConf.FORM_OPERATION.upsert);
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ log.info("客户已同步");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
|
|
|
private McR saveToAudit(String formid, Object object) throws Exception {
|
|
private McR saveToAudit(String formid, Object object) throws Exception {
|
|
|
JSONObject resultObj = new JSONObject();
|
|
JSONObject resultObj = new JSONObject();
|
|
@@ -918,4 +1000,18 @@ public class ZwServiceImpl implements ZwService {
|
|
|
|
|
|
|
|
return iden;
|
|
return iden;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /*TODO:钉钉获取应用token*/
|
|
|
|
|
+ public McR Accesstoken() throws JsonProcessingException{
|
|
|
|
|
+ HashMap body = new HashMap();
|
|
|
|
|
+ body.put("appKey","dinga81qkwb0sqxqnviw");
|
|
|
|
|
+ body.put("appSecret","IvePeLbMMxAzIr228RaGcOxgSSOuJ0trbenX3BbahjeLFA2YeaFv0W9F_6Ar5G0P");
|
|
|
|
|
+ String doGet = UtilHttp.doPost("https://oapi.dingtalk.com/v1.0/oauth2/accessToken", null, null,body);
|
|
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(doGet);
|
|
|
|
|
+ String accessToken = jsonObject.getString("access_token");
|
|
|
|
|
+ log.info("accessToken:{}",accessToken);
|
|
|
|
|
+ return McR.success(accessToken);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|