|
|
@@ -1,240 +1,581 @@
|
|
|
package com.malk.jinlun.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.google.common.base.Strings;
|
|
|
+import com.auth0.jwt.JWT;
|
|
|
+import com.auth0.jwt.algorithms.Algorithm;
|
|
|
+import com.google.gson.Gson;
|
|
|
import com.kingdee.bos.webapi.entity.IdentifyInfo;
|
|
|
+import com.kingdee.bos.webapi.entity.RepoRet;
|
|
|
import com.kingdee.bos.webapi.sdk.K3CloudApi;
|
|
|
-import com.malk.jinlun.config.CloudpivotConfig;
|
|
|
import com.malk.jinlun.config.KDWebApiConf;
|
|
|
-import com.malk.jinlun.entity.BillQuery;
|
|
|
+import com.malk.jinlun.entity.*;
|
|
|
+import com.malk.jinlun.service.CpClient;
|
|
|
import com.malk.jinlun.service.JinlunService;
|
|
|
import com.malk.server.common.McR;
|
|
|
+import com.malk.server.teambition.TBConf;
|
|
|
+import com.malk.server.teambition.TBR;
|
|
|
import com.malk.utils.UtilHttp;
|
|
|
import com.malk.utils.UtilMap;
|
|
|
import com.malk.utils.UtilToken;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
|
|
|
+import static org.junit.Assert.fail;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class JinlunServiceImpl implements JinlunService {
|
|
|
@Autowired
|
|
|
private KDWebApiConf kdWebApiConf;
|
|
|
|
|
|
@Autowired
|
|
|
- private CloudpivotConfig cloudpivotConfig;
|
|
|
-
|
|
|
- @Override
|
|
|
- public void syncMaterial() {
|
|
|
- K3CloudApi client = new K3CloudApi(initIden());
|
|
|
+ private CpClient cpClient;
|
|
|
|
|
|
- List<Map> result = new ArrayList<>();
|
|
|
- List<Map> materialList = new ArrayList<>();
|
|
|
-
|
|
|
- int startRow = 0;
|
|
|
- int limit = 2000;
|
|
|
+ @Autowired
|
|
|
+ private TBConf tbConf;
|
|
|
|
|
|
- BillQuery billQuery = new BillQuery();
|
|
|
- billQuery.setFormId("BD_MATERIAL");
|
|
|
- billQuery.setFieldKeys("FNumber,FName,F_Sl_xingnengid.FName,F_Sl_cihuaid.FName,FErpClsID,F_Sl_xingzhuangid.FName,F_Sl_ducengid.FName,F_Sl_ischongciid.FName,F_Sl_chihuaguige,F_Sl_midu,F_Sl_guige,F_Sl_weight,F_Sl_ischeck,F_Sl_qianguige,F_Sl_cixiangchang,F_NLD_gongyi.FName,F_Sl_biaomianji,FMaterialGroup.FName,FCategoryID.FName,FVOLUME,FBaseUnitId.FName");
|
|
|
- List<Map> filterString = new ArrayList<>();
|
|
|
+ private final Object $lock = new Object[0];
|
|
|
|
|
|
- //审核日期为昨天至今天
|
|
|
- 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","FNumber","67","35","","","0"));//物料编码等于XX
|
|
|
+ private static final Long EXPIRES_IN = 7200000L;
|
|
|
|
|
|
+ @Override
|
|
|
+ public McR addCustomer(@RequestBody Map map) {
|
|
|
+ //查询云枢客户单据详情
|
|
|
+ String objectId = UtilMap.getString(map, "objectId");
|
|
|
|
|
|
- billQuery.setFilterString(filterString);
|
|
|
- billQuery.setLimit(limit);
|
|
|
+ Map customer = cpClient.getCpBo("ZLKHLC", objectId, null);
|
|
|
+
|
|
|
+ Map data = UtilMap.getMap(customer, "data");
|
|
|
+
|
|
|
+ Map bizObject = UtilMap.getMap(data, "bizObject");
|
|
|
+
|
|
|
+ Map customerData = UtilMap.getMap(bizObject, "data");
|
|
|
+
|
|
|
+ //请求参数,要求为json字符串
|
|
|
+ Save save = new Save();
|
|
|
+ CustomerModel customerModel = new CustomerModel();
|
|
|
+
|
|
|
+ //基本信息
|
|
|
+ String FName = UtilMap.getString(customerData,"ShortText1758195928433");//客户名称
|
|
|
+ String FShortName = UtilMap.getString(customerData,"ShortText1758195937324");//客户简称
|
|
|
+ FNumber FCOUNTRY = new FNumber(UtilMap.getString(customerData,"ShortText1760000048047"));//国家
|
|
|
+ FNumber FGroup = new FNumber(UtilMap.getString(customerData,"Dropdown1758198564777_key"));//客户分组
|
|
|
+ String F_VMKV_Combo = UtilMap.getString(customerData,"Dropdown1758198576644_key");//客户等级
|
|
|
+ FNumber FCustTypeId = new FNumber(UtilMap.getString(customerData,"Dropdown1758196678786_key"));//客户类别
|
|
|
+ String FDescription = UtilMap.getString(customerData,"LongText1758198621716");//备注
|
|
|
+
|
|
|
+ //商务信息
|
|
|
+ FNumber FSELLER = new FNumber(UtilMap.getString(customerData,"ShortText1759997501370"));//销售员
|
|
|
+ FNumber FRECCONDITIONID = new FNumber(UtilMap.getString(customerData,"Dropdown1758199217950_key"));//收款条件
|
|
|
+ FNumber FTRADINGCURRID = new FNumber(UtilMap.getString(customerData,"Dropdown1758199184443_key"));//结算币别
|
|
|
+ FNumber FSETTLETYPEID = new FNumber(UtilMap.getString(customerData,"Dropdown1758199160962_key"));//结算方式
|
|
|
+ FNumber FTaxRate = new FNumber(UtilMap.getString(customerData,"Dropdown1758199231927_key"));//税率
|
|
|
+ FNumber FTaxType = new FNumber(UtilMap.getString(customerData,"Dropdown1758199263660_key"));//税分类
|
|
|
+ String FInvoiceType = UtilMap.getString(customerData,"Dropdown1758199247249_key");//发票类型
|
|
|
+ Boolean FISCREDITCHECK = UtilMap.getBoolean(customerData,"Logic1758199516570");//启用信用管理
|
|
|
+
|
|
|
+ //开票信息
|
|
|
+ String FINVOICEBANKACCOUNT = UtilMap.getString(customerData,"ShortText1758199605057");//银行账号
|
|
|
+ String FINVOICETITLE = UtilMap.getString(customerData,"ShortText1758199610851");//发票抬头
|
|
|
+ String FTAXREGISTERCODE = UtilMap.getString(customerData,"ShortText1758199617057");//纳税登记号
|
|
|
+ String FINVOICEBANKNAME = UtilMap.getString(customerData,"Text1758199624533");//开户银行
|
|
|
+ String FSOCIALCRECODE = UtilMap.getString(customerData,"Text1758199630373");//统一社会信用代码
|
|
|
+ String FINVOICETEL = UtilMap.getString(customerData,"Text1758199637444");//开票联系电话
|
|
|
+ String FINVOICEADDRESS = UtilMap.getString(customerData,"LongText1758199679685");//开票通讯地址
|
|
|
+
|
|
|
+ //地址信息
|
|
|
+ List<Map> addressList = UtilMap.getList(customerData, "Sheet1758199794948");
|
|
|
+ List<CustomerContactEntry> FT_BD_CUSTCONTACT = new ArrayList<>();
|
|
|
+
|
|
|
+ for (Map address : addressList) {
|
|
|
+ CustomerContactEntry customerContactEntry = new CustomerContactEntry();
|
|
|
+ customerContactEntry.setFNUMBER1(UtilMap.getString(address,"ShortText1758199808715"));//地点编码
|
|
|
+ customerContactEntry.setFNAME1(UtilMap.getString(address,"ShortText1758199824395"));//地点名称
|
|
|
+
|
|
|
+ FT_BD_CUSTCONTACT.add(customerContactEntry);
|
|
|
+ }
|
|
|
|
|
|
- do {
|
|
|
- billQuery.setStartRow(startRow);
|
|
|
- String s = null;
|
|
|
+ customerModel.setFName(FName);
|
|
|
+ customerModel.setFShortName(FShortName);
|
|
|
+ customerModel.setFCOUNTRY(FCOUNTRY);
|
|
|
+ customerModel.setFGroup(FGroup);
|
|
|
+ customerModel.setF_VMKV_Combo(F_VMKV_Combo);
|
|
|
+ customerModel.setFCustTypeId(FCustTypeId);
|
|
|
+ customerModel.setFDescription(FDescription);
|
|
|
+ customerModel.setFSELLER(FSELLER);
|
|
|
+ customerModel.setFRECCONDITIONID(FRECCONDITIONID);
|
|
|
+ customerModel.setFTRADINGCURRID(FTRADINGCURRID);
|
|
|
+ customerModel.setFSETTLETYPEID(FSETTLETYPEID);
|
|
|
+ customerModel.setFTaxRate(FTaxRate);
|
|
|
+ customerModel.setFTaxType(FTaxType);
|
|
|
+ customerModel.setFInvoiceType(FInvoiceType);
|
|
|
+ customerModel.setFISCREDITCHECK(FISCREDITCHECK);
|
|
|
+ customerModel.setFINVOICEBANKACCOUNT(FINVOICEBANKACCOUNT);
|
|
|
+ customerModel.setFINVOICETITLE(FINVOICETITLE);
|
|
|
+ customerModel.setFTAXREGISTERCODE(FTAXREGISTERCODE);
|
|
|
+ customerModel.setFINVOICEBANKNAME(FINVOICEBANKNAME);
|
|
|
+ customerModel.setFSOCIALCRECODE(FSOCIALCRECODE);
|
|
|
+ customerModel.setFINVOICETEL(FINVOICETEL);
|
|
|
+ customerModel.setFINVOICEADDRESS(FINVOICEADDRESS);
|
|
|
+ customerModel.setFT_BD_CUSTCONTACT(FT_BD_CUSTCONTACT);
|
|
|
+
|
|
|
+ save.setModel(customerModel);
|
|
|
+ Gson gson2 = new Gson();
|
|
|
+ String jsonData = gson2.toJson(save);
|
|
|
+
|
|
|
+ log.info(jsonData);
|
|
|
|
|
|
+ K3CloudApi client = new K3CloudApi(initIden());
|
|
|
+ //业务对象标识
|
|
|
+ String formId = "BD_Customer";
|
|
|
+ //调用接口
|
|
|
+ String resultJson = "";
|
|
|
+ try {
|
|
|
+ resultJson = client.save(formId,jsonData);
|
|
|
+ }catch (Exception e){
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ //用于记录结果
|
|
|
+ Gson gson = new Gson();
|
|
|
+ //对返回结果进行解析和校验
|
|
|
+ RepoRet repoRet = gson.fromJson(resultJson, RepoRet.class);
|
|
|
+
|
|
|
+ String customerCode = "";
|
|
|
+
|
|
|
+ if (isTrue(repoRet)){
|
|
|
+ String id = repoRet.getResult().getId();
|
|
|
+ Submit submit = new Submit();
|
|
|
+ submit.setIds(id);
|
|
|
+ //提交客户
|
|
|
+ String resultJson2 = "";
|
|
|
try {
|
|
|
- s = client.billQuery(JSONObject.toJSONString(billQuery));
|
|
|
- } catch (Exception e) {
|
|
|
+ resultJson2 = client.submit(formId, JSONObject.toJSONString(submit));
|
|
|
+ }catch (Exception e){
|
|
|
throw new RuntimeException(e);
|
|
|
}
|
|
|
- result = (List<Map>)JSONObject.parse(s);
|
|
|
- materialList.addAll(result);
|
|
|
-
|
|
|
- startRow += limit;
|
|
|
- }while (result.size() == limit);
|
|
|
-
|
|
|
- for (Map map : result) {
|
|
|
- Map data = new HashMap();
|
|
|
- data.put("ShortText1757932581400",UtilMap.getString(map,"FName"));//物料名称
|
|
|
- data.put("ShortText1757932557449",UtilMap.getString(map,"FNumber"));//物料编码
|
|
|
- data.put("ShortText1757932601205",UtilMap.getString(map,"F_Sl_xingnengid.FName"));//性能
|
|
|
- data.put("ShortText1757932616477",UtilMap.getString(map,"F_Sl_cihuaid.FName"));//磁化方向
|
|
|
- data.put("ShortText1757932652570",UtilMap.getString(map,"F_Sl_xingzhuangid.FName"));//形状
|
|
|
- data.put("ShortText1757932660567",UtilMap.getString(map,"F_Sl_ducengid.FName"));//镀层
|
|
|
- data.put("Dropdown1757932715739",UtilMap.getString(map,"F_Sl_ischongciid.FName"));//是否充磁
|
|
|
- data.put("ShortText1757932699628",UtilMap.getString(map,"F_Sl_chihuaguige"));//磁化规格
|
|
|
- data.put("Number1757932755471",UtilMap.getDouble(map,"F_Sl_midu"));//密度(g/mm³)
|
|
|
- data.put("ShortText1757932739089",UtilMap.getString(map,"F_Sl_guige"));//尺寸规格
|
|
|
- data.put("Number1757932746124",UtilMap.getDouble(map,"F_Sl_weight"));//单重(kg)
|
|
|
- data.put("Logic1757932804393",UtilMap.getBoolean(map,"F_Sl_ischeck"));//是否需要检验
|
|
|
- data.put("ShortText1757932821074",UtilMap.getString(map,"F_Sl_qianguige"));//带前后缀规格
|
|
|
- data.put("Number1757932837126",UtilMap.getDouble(map,"F_Sl_cixiangchang"));//磁向长
|
|
|
- data.put("ShortText1757932874077",UtilMap.getString(map,"F_NLD_gongyi.FName"));//工序
|
|
|
- data.put("Number1757932881710",UtilMap.getDouble(map,"F_Sl_biaomianji"));//表面积
|
|
|
- data.put("ShortText1757933029016",UtilMap.getString(map,"FMaterialGroup.FName"));//物料分组
|
|
|
- data.put("ShortText1757933017962",UtilMap.getString(map,"FCategoryID.FName"));//存货类别
|
|
|
-
|
|
|
- String fErpClsID = UtilMap.getString(map, "FErpClsID");
|
|
|
- String wlsx = "";
|
|
|
- switch (fErpClsID){
|
|
|
- case "10":wlsx = "资产";break;
|
|
|
- case "9":wlsx = "配置";break;
|
|
|
- case "2":wlsx = "自制";break;
|
|
|
- case "11":wlsx = "费用";break;
|
|
|
- case "12":wlsx = "模型";break;
|
|
|
- case "5":wlsx = "虚拟";break;
|
|
|
- case "7":wlsx = "一次性";break;
|
|
|
- case "13":wlsx = "产品系列";break;
|
|
|
- case "3":wlsx = "委外";break;
|
|
|
- case "4":wlsx = "特征";break;
|
|
|
- case "6":wlsx = "服务";break;
|
|
|
- case "1":wlsx = "原材料";break;
|
|
|
-
|
|
|
+ RepoRet repoRet2 = gson.fromJson(resultJson2, RepoRet.class);
|
|
|
+ isTrue(repoRet2);
|
|
|
+ customerCode = repoRet2.getResult().getResponseStatus().getSuccessEntitys().get(0).getNumber();
|
|
|
+ //回写云枢客户编号
|
|
|
+ cpClient.updateCpBo("ZLKHLC",UtilMap.map("id, ShortText1758195840127",objectId,customerCode),null);
|
|
|
+
|
|
|
+ if (isTrue(repoRet2)){
|
|
|
+ Audit audit = new Audit();
|
|
|
+ audit.setNumbers(Arrays.asList(customerCode));
|
|
|
+ //审核客户
|
|
|
+ String resultJson3 = "";
|
|
|
+ try {
|
|
|
+ resultJson3 = client.audit(formId,JSONObject.toJSONString(audit));
|
|
|
+ }catch (Exception e){
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+
|
|
|
+ RepoRet repoRet3 = gson.fromJson(resultJson3, RepoRet.class);
|
|
|
+ isTrue(repoRet3);
|
|
|
}
|
|
|
- data.put("ShortText1757933048314",wlsx);//物料属性
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return McR.success(customerCode);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Async
|
|
|
+ @Override
|
|
|
+ public void addCustomerContact(Map map) {
|
|
|
+ try {
|
|
|
+ Thread.sleep(3000);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+
|
|
|
+ //请求参数,要求为json字符串
|
|
|
+ Save save = new Save();
|
|
|
+ ContactModel contactModel = new ContactModel();
|
|
|
+
|
|
|
+ String objectId = UtilMap.getString(map, "objectId");
|
|
|
+
|
|
|
+ Map contact = cpClient.getCpBo("JL002", objectId, null);
|
|
|
+
|
|
|
+ Map cpBoResultData = cpClient.getCpBoResultData(contact);
|
|
|
|
|
|
- data.put("Number1757933060744",UtilMap.getDouble(map,"FVOLUME"));//体积
|
|
|
- data.put("ShortText1757933079170",UtilMap.getString(map,"FBaseUnitId.FName"));//基本单位
|
|
|
+ String FName = UtilMap.getString(cpBoResultData, "ShortText1757918028530");//联系人姓名
|
|
|
+ String FMobile = UtilMap.getString(cpBoResultData, "ShortText1760076219303");//移动电话
|
|
|
+ FNumber Fex = new FNumber(UtilMap.getString(cpBoResultData, "Radio1757922932185_key"));//性别
|
|
|
+ String FPost = UtilMap.getString(cpBoResultData, "ShortText1757918203180");//职务
|
|
|
+ String FCompanyType = "BD_Customer";//类型:客户
|
|
|
+ String FTel = UtilMap.getString(cpBoResultData, "ShortText1757922962403");//固定电话
|
|
|
+ String FFax = UtilMap.getString(cpBoResultData, "ShortText1757918148867");//传真
|
|
|
+ String FEmail = UtilMap.getString(cpBoResultData, "ShortText1757918154124");//邮箱
|
|
|
+ FNumber FCustId = new FNumber(UtilMap.getString(cpBoResultData, "ShortText1758159321906"));//客户编码
|
|
|
|
|
|
- String schemaCode = "WL";
|
|
|
+ contactModel.setFName(FName);
|
|
|
+ contactModel.setFMobile(FMobile);
|
|
|
+ contactModel.setFex(Fex);
|
|
|
+ contactModel.setFPost(FPost);
|
|
|
+ contactModel.setFCompanyType(FCompanyType);
|
|
|
+ contactModel.setFTel(FTel);
|
|
|
+ contactModel.setFFax(FFax);
|
|
|
+ contactModel.setFEmail(FEmail);
|
|
|
+ contactModel.setFCustId(FCustId);
|
|
|
|
|
|
- Map body = new HashMap();
|
|
|
+ save.setModel(contactModel);
|
|
|
|
|
|
- body.put("data",data);
|
|
|
- body.put("schemaCode",schemaCode);
|
|
|
- body.put("userId",cloudpivotConfig.getOperatorUserId());
|
|
|
+ Gson gson2 = new Gson();
|
|
|
+ String jsonData = gson2.toJson(save);
|
|
|
|
|
|
- //云枢新增物料
|
|
|
- Map result2 = createCpBo(schemaCode, body,null);
|
|
|
+ log.info(jsonData);
|
|
|
+
|
|
|
+ K3CloudApi client = new K3CloudApi(initIden());
|
|
|
+ //业务对象标识
|
|
|
+ String formId = "BD_CommonContact";
|
|
|
+ //调用接口
|
|
|
+ String resultJson = "";
|
|
|
+ try {
|
|
|
+ resultJson = client.save(formId,jsonData);
|
|
|
+ }catch (Exception e){
|
|
|
+ throw new RuntimeException(e);
|
|
|
}
|
|
|
+ //用于记录结果
|
|
|
+ Gson gson = new Gson();
|
|
|
+ //对返回结果进行解析和校验
|
|
|
+ RepoRet repoRet = gson.fromJson(resultJson, RepoRet.class);
|
|
|
+
|
|
|
+ isTrue(repoRet);
|
|
|
+
|
|
|
+ String contactCode = repoRet.getResult().getResponseStatus().getSuccessEntitys().get(0).getNumber();
|
|
|
+
|
|
|
+ cpClient.updateCpBo("JL002",UtilMap.map("id, ShortText1760075793733",objectId,contactCode),null);
|
|
|
}
|
|
|
|
|
|
+ @Async
|
|
|
@Override
|
|
|
- public McR addCustomer(@RequestBody Map map) {
|
|
|
- //查询云枢客户单据详情
|
|
|
+ public void updateCustomer(Map map) {
|
|
|
+ K3CloudApi client = new K3CloudApi(initIden());
|
|
|
+ //业务对象标识
|
|
|
+ String formId = "BD_Customer";
|
|
|
+
|
|
|
+ //查询云枢客户详情
|
|
|
String objectId = UtilMap.getString(map, "objectId");
|
|
|
+ Map customer = cpClient.getCpBo("KHDA", objectId, null);
|
|
|
+ Map customerData = cpClient.getCpBoResultData(customer);
|
|
|
|
|
|
- Map customer = getCpBo("ZLKHLC", objectId, null);
|
|
|
+ String custFNumber = UtilMap.getString(customerData, "ShortText1758195840127");//客户编码
|
|
|
+ FNumber FSELLER = new FNumber(UtilMap.getString(customerData, "ShortText1759998244839"));//销售负责人
|
|
|
|
|
|
- return McR.success();
|
|
|
- }
|
|
|
+ //反审核
|
|
|
+ UnAudit unAudit = new UnAudit();
|
|
|
+ unAudit.setNumbers(Arrays.asList(custFNumber));//客户编码
|
|
|
|
|
|
- private IdentifyInfo initIden(){
|
|
|
- //注意 1:此处不再使用参数形式传入用户名及密码等敏感信息,改为在登录配置文件中设置。
|
|
|
- //注意 2:必须先配置第三方系统登录授权信息后,再进行业务操作,详情参考各语言版本SDK介绍中的登录配置文件说明。
|
|
|
- //读取配置,初始化SDK
|
|
|
- IdentifyInfo iden = new IdentifyInfo();
|
|
|
- iden.setUserName(kdWebApiConf.getXKDApiUserName());
|
|
|
- iden.setAppId(kdWebApiConf.getXKDApiAppID());
|
|
|
- iden.setdCID(kdWebApiConf.getXKDApiAcctID());
|
|
|
- iden.setAppSecret(kdWebApiConf.getXKDApiAppSec());
|
|
|
- iden.setServerUrl(kdWebApiConf.getXKDApiServerUrl());
|
|
|
+ RepoRet repoRet = new RepoRet();
|
|
|
|
|
|
- return iden;
|
|
|
- }
|
|
|
+ try {
|
|
|
+ String resultJson = client.unAudit(formId,new Gson().toJson(unAudit));
|
|
|
+ repoRet = new Gson().fromJson(resultJson, RepoRet.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
|
|
|
- /**
|
|
|
- * 云枢获取token
|
|
|
- * @return
|
|
|
- */
|
|
|
- private String getCpAccessToken(){
|
|
|
- String accessToken = UtilToken.get("invalid-token-cloudpivot");
|
|
|
+ isTrue(repoRet);
|
|
|
|
|
|
- if (StringUtils.isNotBlank(accessToken)) {
|
|
|
- return accessToken;
|
|
|
- } else {
|
|
|
- Map<String,Object> params = new HashMap();
|
|
|
- params.put("grant_type",cloudpivotConfig.getGrantType());
|
|
|
- params.put("client_id",cloudpivotConfig.getClientId());
|
|
|
- params.put("client_secret",cloudpivotConfig.getClientSecret());
|
|
|
+ //查询客户内码
|
|
|
+ View view = new View();
|
|
|
+ view.setNumber(custFNumber);//客户编码
|
|
|
+
|
|
|
+ RepoRet repoRet2 = new RepoRet();
|
|
|
+
|
|
|
+ try {
|
|
|
+ String resultJson = client.view(formId,new Gson().toJson(view));
|
|
|
+ repoRet2 = new Gson().fromJson(resultJson, RepoRet.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+
|
|
|
+ isTrue(repoRet2);
|
|
|
|
|
|
- String s = UtilHttp.doPost(cloudpivotConfig.getRedirectUri()+"oauth/token", null, params, new HashMap());
|
|
|
+ int FCUSTID = UtilMap.getDouble((Map) repoRet2.getResult().getResult(), "Id").intValue();
|
|
|
|
|
|
- Map result = (Map) JSONObject.parse(s);
|
|
|
+ //保存
|
|
|
+ Save save = new Save();
|
|
|
+ CustomerModel customerModel = new CustomerModel();
|
|
|
+ customerModel.setFCUSTID(FCUSTID);//客户内码
|
|
|
+ customerModel.setFSELLER(FSELLER);//销售员
|
|
|
+ save.setModel(customerModel);
|
|
|
+ save.setNeedUpDateFields(Arrays.asList("FSELLER"));
|
|
|
|
|
|
- accessToken = "bearer" + UtilMap.getString(result, "access_token");
|
|
|
+ RepoRet repoRet3 = new RepoRet();
|
|
|
+
|
|
|
+ try {
|
|
|
+ String resultJson = client.save(formId,new Gson().toJson(save));
|
|
|
+ repoRet3 = new Gson().fromJson(resultJson, RepoRet.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
|
|
|
- long expiresIn = UtilMap.getLong(result, "expires_in") * 1000;
|
|
|
+ isTrue(repoRet3);
|
|
|
|
|
|
- UtilToken.put("invalid-token-cloudpivot", accessToken, expiresIn);
|
|
|
+ //提交
|
|
|
+ Submit submit = new Submit();
|
|
|
+ submit.setNumbers(Arrays.asList(custFNumber));//客户编码
|
|
|
|
|
|
- return accessToken;
|
|
|
+ RepoRet repoRet4 = new RepoRet();
|
|
|
+
|
|
|
+ try {
|
|
|
+ String resultJson = client.submit(formId, JSONObject.toJSONString(submit));
|
|
|
+ repoRet4 = new Gson().fromJson(resultJson, RepoRet.class);
|
|
|
+ }catch (Exception e){
|
|
|
+ throw new RuntimeException(e);
|
|
|
}
|
|
|
+
|
|
|
+ isTrue(repoRet4);
|
|
|
+
|
|
|
+ //审核
|
|
|
+ Audit audit = new Audit();
|
|
|
+ audit.setNumbers(Arrays.asList(custFNumber));
|
|
|
+
|
|
|
+ RepoRet repoRet5 = new RepoRet();
|
|
|
+
|
|
|
+ try {
|
|
|
+ String resultJson = client.audit(formId,JSONObject.toJSONString(audit));
|
|
|
+ repoRet5 = new Gson().fromJson(resultJson, RepoRet.class);
|
|
|
+ }catch (Exception e){
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+
|
|
|
+ isTrue(repoRet5);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 云枢新增表单
|
|
|
- * @param schemaCode
|
|
|
- * @param data
|
|
|
- * @param userId
|
|
|
- * @return
|
|
|
- */
|
|
|
- private Map createCpBo(String schemaCode, Map data, String userId){
|
|
|
- Map body = new HashMap();
|
|
|
+ @Override
|
|
|
+ public McR addSaleOrder(Map map) {
|
|
|
+ //查询云枢客户单据详情
|
|
|
+ String objectId = UtilMap.getString(map, "objectId");
|
|
|
|
|
|
- body.put("data",data);
|
|
|
- body.put("schemaCode",schemaCode);
|
|
|
- if (Strings.isNullOrEmpty(userId)){
|
|
|
- body.put("userId",cloudpivotConfig.getOperatorUserId());
|
|
|
- }else {
|
|
|
- body.put("userId",userId);
|
|
|
+ Map saleOrder = cpClient.getCpBo("XSDD", objectId, null);
|
|
|
+
|
|
|
+ Map saleOrderData = cpClient.getCpBoResultData(saleOrder);
|
|
|
+
|
|
|
+ //请求参数,要求为json字符串
|
|
|
+ Save save = new Save();
|
|
|
+ SaleOrderModel saleOrderModel = new SaleOrderModel();
|
|
|
+
|
|
|
+ //基本信息
|
|
|
+ FNumber FBillTypeID = new FNumber(UtilMap.getString(saleOrderData, "Dropdown1758339062589_key"));//单据类型
|
|
|
+ String FDate = UtilMap.getString(saleOrderData, "Date1758339215935");//日期
|
|
|
+ FNumber FCustId = new FNumber(UtilMap.getString(saleOrderData, "ShortText1760426148831"));//客户
|
|
|
+ String F_NLD_DDTYPE = UtilMap.getString(saleOrderData, "Dropdown1758340059699_key");//订单类型
|
|
|
+ FNumber FSalerId = new FNumber(UtilMap.getString(saleOrderData, "ShortText1760421121913"));//销售员
|
|
|
+ FSTAFFNUMBER F_Sl_gendanyuan = new FSTAFFNUMBER(UtilMap.getString(saleOrderData, "Text1760421147555"));//跟单员
|
|
|
+ String FBusinessType = UtilMap.getString(saleOrderData,"Dropdown1758339265813_key");//业务类型
|
|
|
+ String F_WGR_Combo_re5 = UtilMap.getString(saleOrderData,"Dropdown1758340112723_key");//订单要求
|
|
|
+ FNumber FHEADLOCID = new FNumber(UtilMap.getString(saleOrderData, "ShortText1760507577966"));//交货地点
|
|
|
+ String FNote = UtilMap.getString(saleOrderData,"LongText1758339516625");//备注
|
|
|
+ String F_Sl_customerbillno = UtilMap.getString(saleOrderData,"ShortText1758340044946");//客户订单号
|
|
|
+
|
|
|
+ saleOrderModel.setFBillTypeID(FBillTypeID);
|
|
|
+ saleOrderModel.setFDate(FDate);
|
|
|
+ saleOrderModel.setFCustId(FCustId);
|
|
|
+ saleOrderModel.setF_NLD_DDTYPE(F_NLD_DDTYPE);
|
|
|
+ saleOrderModel.setFSalerId(FSalerId);
|
|
|
+ saleOrderModel.setF_Sl_gendanyuan(F_Sl_gendanyuan);
|
|
|
+ saleOrderModel.setFBusinessType(FBusinessType);
|
|
|
+ saleOrderModel.setF_WGR_Combo_re5(F_WGR_Combo_re5);
|
|
|
+ saleOrderModel.setFHEADLOCID(FHEADLOCID);
|
|
|
+ saleOrderModel.setFNote(FNote);
|
|
|
+ saleOrderModel.setF_Sl_customerbillno(F_Sl_customerbillno);
|
|
|
+
|
|
|
+ //财务信息
|
|
|
+ SaleOrderFinance saleOrderFinance = new SaleOrderFinance();
|
|
|
+ FNumber FSettleCurrId = new FNumber(UtilMap.getString(saleOrderData, "Dropdown1758339227503_key"));//结算币别
|
|
|
+ FNumber FRecConditionId = new FNumber(UtilMap.getString(saleOrderData, "Dropdown1758339314401_key"));//收款条件
|
|
|
+ FNumber FSettleModeId = new FNumber(UtilMap.getString(saleOrderData, "Dropdown1758340854092_key"));//结算方式
|
|
|
+ boolean FIsIncludedTax = UtilMap.getBoolean(saleOrderData,"Logic1758340099868");//是否含税
|
|
|
+ boolean FIsPriceExcludeTax = UtilMap.getBoolean(saleOrderData,"Logic1758340955492");//价外税
|
|
|
+
|
|
|
+ saleOrderFinance.setFSettleCurrId(FSettleCurrId);
|
|
|
+ saleOrderFinance.setFRecConditionId(FRecConditionId);
|
|
|
+ saleOrderFinance.setFSettleModeId(FSettleModeId);
|
|
|
+ saleOrderFinance.setFIsIncludedTax(FIsIncludedTax);
|
|
|
+ saleOrderFinance.setFIsPriceExcludeTax(FIsPriceExcludeTax);
|
|
|
+
|
|
|
+ saleOrderModel.setFSaleOrderFinance(saleOrderFinance);
|
|
|
+
|
|
|
+ //明细信息
|
|
|
+ List<Map> saleDetailList = UtilMap.getList(saleOrderData, "Sheet1758341252878");
|
|
|
+ List<SaleOrderEntry> saleOrderEntryList = new ArrayList<>();
|
|
|
+
|
|
|
+ for (Map saleDetail : saleDetailList) {
|
|
|
+ FNumber FMaterialId = new FNumber(UtilMap.getString(saleDetail, "ShortText1758341332222"));//物料编码
|
|
|
+ String F_Sl_XSTYPE = UtilMap.getString(saleDetail, "Dropdown1758341293022_key");//产品类别
|
|
|
+ Double FQty = UtilMap.getDouble(saleDetail, "Number1758341381523");//销售数量
|
|
|
+ Double FTaxPrice = UtilMap.getDouble(saleDetail, "Number1758341424993");//含税单价
|
|
|
+ boolean FIsFree = UtilMap.getBoolean(saleDetail,"Logic1758341430353");//是否赠品
|
|
|
+ Double FEntryTaxRate = UtilMap.getDouble(saleDetail, "Number1758349078527");//税率
|
|
|
+ String FDeliveryDate = UtilMap.getString(saleDetail,"Date1758341499356");//客户交期
|
|
|
+ String FEntryNote = UtilMap.getString(saleDetail,"Date1758341499356");//备注
|
|
|
+ Double F_VMKV_MPPRICE = UtilMap.getDouble(saleDetail, "Number1758341576099");//报价价格
|
|
|
+ String F_VMKV_SCCQ1 = UtilMap.getString(saleDetail,"Dropdown1760425152219_key");//生产厂区
|
|
|
+
|
|
|
+ SaleOrderEntry saleOrderEntry = new SaleOrderEntry();
|
|
|
+ saleOrderEntry.setFMaterialId(FMaterialId);
|
|
|
+ saleOrderEntry.setF_Sl_XSTYPE(F_Sl_XSTYPE);
|
|
|
+ saleOrderEntry.setFQty(FQty);
|
|
|
+ saleOrderEntry.setFTaxPrice(FTaxPrice);
|
|
|
+ saleOrderEntry.setFIsFree(FIsFree);
|
|
|
+ saleOrderEntry.setFEntryTaxRate(FEntryTaxRate);
|
|
|
+ saleOrderEntry.setFDeliveryDate(FDeliveryDate);
|
|
|
+ saleOrderEntry.setFEntryNote(FEntryNote);
|
|
|
+ saleOrderEntry.setF_VMKV_MPPRICE(F_VMKV_MPPRICE);
|
|
|
+ saleOrderEntry.setF_VMKV_SCCQ1(F_VMKV_SCCQ1);
|
|
|
+
|
|
|
+ saleOrderEntryList.add(saleOrderEntry);
|
|
|
}
|
|
|
|
|
|
- String s = UtilHttp.doPost(cloudpivotConfig.getRedirectUri() + "openapi/v3/bo/create", CloudpivotConfig.initTokenHeader(getCpAccessToken()), null, body);
|
|
|
+ saleOrderModel.setFSaleOrderEntry(saleOrderEntryList);
|
|
|
|
|
|
- Map result = (Map) JSONObject.parse(s);
|
|
|
+ save.setModel(saleOrderModel);
|
|
|
+ Gson gson2 = new Gson();
|
|
|
+ String jsonData = gson2.toJson(save);
|
|
|
|
|
|
- return result;
|
|
|
+ log.info(jsonData);
|
|
|
+
|
|
|
+ K3CloudApi client = new K3CloudApi(initIden());
|
|
|
+ //业务对象标识
|
|
|
+ String formId = "SAL_SaleOrder";
|
|
|
+ //调用接口
|
|
|
+ String resultJson = "";
|
|
|
+ try {
|
|
|
+ resultJson = client.save(formId,jsonData);
|
|
|
+ }catch (Exception e){
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ //用于记录结果
|
|
|
+ Gson gson = new Gson();
|
|
|
+ //对返回结果进行解析和校验
|
|
|
+ RepoRet repoRet = gson.fromJson(resultJson, RepoRet.class);
|
|
|
+
|
|
|
+ String saleOrderCode = "";
|
|
|
+
|
|
|
+ if (isTrue(repoRet)){
|
|
|
+ String id = repoRet.getResult().getId();
|
|
|
+ Submit submit = new Submit();
|
|
|
+ submit.setIds(id);
|
|
|
+ //提交客户
|
|
|
+ String resultJson2 = "";
|
|
|
+ try {
|
|
|
+ resultJson2 = client.submit(formId, JSONObject.toJSONString(submit));
|
|
|
+ }catch (Exception e){
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ RepoRet repoRet2 = gson.fromJson(resultJson2, RepoRet.class);
|
|
|
+ isTrue(repoRet2);
|
|
|
+ saleOrderCode = repoRet2.getResult().getResponseStatus().getSuccessEntitys().get(0).getNumber();
|
|
|
+ //回写云枢销售订单编号
|
|
|
+ cpClient.updateCpBo("XSDD",UtilMap.map("id, ShortText1758339123133",objectId,saleOrderCode),null);
|
|
|
+
|
|
|
+ if (isTrue(repoRet2)){
|
|
|
+ Audit audit = new Audit();
|
|
|
+ audit.setNumbers(Arrays.asList(saleOrderCode));
|
|
|
+ //审核销售订单
|
|
|
+ String resultJson3 = "";
|
|
|
+ try {
|
|
|
+ resultJson3 = client.audit(formId,JSONObject.toJSONString(audit));
|
|
|
+ }catch (Exception e){
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+
|
|
|
+ RepoRet repoRet3 = gson.fromJson(resultJson3, RepoRet.class);
|
|
|
+ isTrue(repoRet3);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return McR.success(saleOrderCode);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 云枢获取表单详情
|
|
|
- * @param schemaCode
|
|
|
- * @param objectId
|
|
|
- * @param userId
|
|
|
- * @return
|
|
|
- */
|
|
|
- private Map getCpBo(String schemaCode, String objectId, String userId){
|
|
|
+ @Async
|
|
|
+ @Override
|
|
|
+ public McR createTbProject(Map map) {
|
|
|
+ //查询云枢重要样品打样申请详情
|
|
|
+ String objectId = UtilMap.getString(map, "objectId");
|
|
|
+
|
|
|
+ Map proofing = cpClient.getCpBo("ZYYPDYSQ", objectId, null);
|
|
|
+
|
|
|
+ Map proofingData = cpClient.getCpBoResultData(proofing);
|
|
|
+
|
|
|
+ String projectName = UtilMap.getString(proofingData, "ShortText1758525084919");
|
|
|
+ String templateId = UtilMap.getString(proofingData, "Dropdown1760517115491_key");
|
|
|
+
|
|
|
Map body = new HashMap();
|
|
|
+ body.put("name",projectName);
|
|
|
+ body.put("templateId",templateId);
|
|
|
|
|
|
- body.put("objectId",objectId);
|
|
|
- body.put("schemaCode",schemaCode);
|
|
|
- if (Strings.isNullOrEmpty(userId)){
|
|
|
- body.put("userId",cloudpivotConfig.getOperatorUserId());
|
|
|
- }else {
|
|
|
- body.put("userId",userId);
|
|
|
- }
|
|
|
+ TBR tbr = (TBR) UtilHttp.doPost("https://open.teambition.com/api/v3/project/create-from-template", initTbHeaderToken(), null,body, TBR.class);
|
|
|
+ Map result = (Map) tbr.getResult();
|
|
|
+ String id = result.get("id").toString();
|
|
|
+
|
|
|
+ //更新云枢打样申请项目id
|
|
|
+ cpClient.updateCpBo("ZYYPDYSQ",UtilMap.map("id, ShortText1760517617788",objectId,id),null);
|
|
|
+
|
|
|
+ return McR.success(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ private IdentifyInfo initIden(){
|
|
|
+ //注意 1:此处不再使用参数形式传入用户名及密码等敏感信息,改为在登录配置文件中设置。
|
|
|
+ //注意 2:必须先配置第三方系统登录授权信息后,再进行业务操作,详情参考各语言版本SDK介绍中的登录配置文件说明。
|
|
|
+ //读取配置,初始化SDK
|
|
|
+ IdentifyInfo iden = new IdentifyInfo();
|
|
|
+ iden.setUserName(kdWebApiConf.getXKDApiUserName());
|
|
|
+ iden.setAppId(kdWebApiConf.getXKDApiAppID());
|
|
|
+ iden.setdCID(kdWebApiConf.getXKDApiAcctID());
|
|
|
+ iden.setAppSecret(kdWebApiConf.getXKDApiAppSec());
|
|
|
+ iden.setServerUrl(kdWebApiConf.getXKDApiServerUrl());
|
|
|
|
|
|
- String s = UtilHttp.doPost(cloudpivotConfig.getRedirectUri() + "openapi/v3/bo/get", CloudpivotConfig.initTokenHeader(getCpAccessToken()), null, body);
|
|
|
+ return iden;
|
|
|
+ }
|
|
|
|
|
|
- Map result = (Map) JSONObject.parse(s);
|
|
|
|
|
|
- isSuccess(result);
|
|
|
+ private boolean isTrue(RepoRet repoRet){
|
|
|
+ Gson gson = new Gson();
|
|
|
|
|
|
- return result;
|
|
|
+ if (repoRet.getResult().getResponseStatus().isIsSuccess()) {
|
|
|
+ System.out.printf("接口返回结果: %s%n", gson.toJson(repoRet.getResult()));
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ fail("接口返回结果: " + gson.toJson(repoRet.getResult().getResponseStatus()));
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- private void isSuccess(Map result){
|
|
|
- int errcode = UtilMap.getInt(result, "errcode");
|
|
|
- String errmsg = UtilMap.getString(result, "errmsg");
|
|
|
+ private Map<String, String> initTbHeaderToken() {
|
|
|
+ Map header = new HashMap();
|
|
|
+ header.put("Authorization", getTbAccessToken());
|
|
|
+ header.put("X-Tenant-Id", tbConf.getTenantId());
|
|
|
+ header.put("X-Tenant-Type", "organization");
|
|
|
+ header.put("x-operator-id", tbConf.getOperatorId());
|
|
|
+ return header;
|
|
|
+ }
|
|
|
|
|
|
- if (errcode != 0){
|
|
|
- throw new RuntimeException("云枢接口调用失败:" + errmsg);
|
|
|
+ private String getTbAccessToken() {
|
|
|
+ synchronized(this.$lock) {
|
|
|
+ String accessToken = UtilToken.get("invalid-token-teambition");
|
|
|
+ if (StringUtils.isNotBlank(accessToken)) {
|
|
|
+ return accessToken;
|
|
|
+ } else {
|
|
|
+ Algorithm algorithm = Algorithm.HMAC256(tbConf.getAppSecret());
|
|
|
+ long timestamp = System.currentTimeMillis();
|
|
|
+ Date issuedAt = new Date(timestamp);
|
|
|
+ Date expiresAt = new Date(timestamp + EXPIRES_IN);
|
|
|
+ accessToken = JWT.create().withClaim("_appId", tbConf.getAppID()).withIssuedAt(issuedAt).withExpiresAt(expiresAt).sign(algorithm);
|
|
|
+ log.info("响应token, {}", accessToken);
|
|
|
+ UtilToken.put("invalid-token-teambition", accessToken, EXPIRES_IN);
|
|
|
+ return accessToken;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|