|
|
@@ -1,16 +1,24 @@
|
|
|
package com.malk.jinlun.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.google.common.base.Strings;
|
|
|
import com.kingdee.bos.webapi.entity.IdentifyInfo;
|
|
|
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.service.JinlunService;
|
|
|
+import com.malk.server.common.McR;
|
|
|
+import com.malk.utils.UtilHttp;
|
|
|
import com.malk.utils.UtilMap;
|
|
|
+import com.malk.utils.UtilToken;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
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;
|
|
|
|
|
|
@@ -19,52 +27,31 @@ public class JinlunServiceImpl implements JinlunService {
|
|
|
@Autowired
|
|
|
private KDWebApiConf kdWebApiConf;
|
|
|
|
|
|
- @Override
|
|
|
- public void test() throws Exception {
|
|
|
- K3CloudApi client = new K3CloudApi(initIden());
|
|
|
-
|
|
|
- List<Map> result = new ArrayList<>();
|
|
|
- List<Map> customerList = new ArrayList<>();
|
|
|
-
|
|
|
- int startRow = 0;
|
|
|
- int limit = 100;
|
|
|
-
|
|
|
- BillQuery billQuery = new BillQuery();
|
|
|
- billQuery.setFormId("BD_MATERIAL");
|
|
|
- billQuery.setFieldKeys("FNumber,FName");
|
|
|
- /*List<Map> filterString = new ArrayList<>();
|
|
|
- //修改时间为昨天到今天
|
|
|
- filterString.add(UtilMap.map("FieldName, Compare, Value, Left, Right, Logic","FModifyDate","265","1","","","0"));
|
|
|
-// filterString.add(UtilMap.map("FieldName, Compare, Value, Left, Right, Logic","FModifyDate","39","2025-03-06 00:00:00","","","0"));
|
|
|
- billQuery.setFilterString(filterString);*/
|
|
|
- billQuery.setLimit(limit);
|
|
|
- billQuery.setStartRow(startRow);
|
|
|
-
|
|
|
- String s = client.billQuery(JSONObject.toJSONString(billQuery));
|
|
|
- result = (List<Map>)JSONObject.parse(s);
|
|
|
-
|
|
|
- System.out.println("111");
|
|
|
- }
|
|
|
+ @Autowired
|
|
|
+ private CloudpivotConfig cloudpivotConfig;
|
|
|
|
|
|
@Override
|
|
|
public void syncMaterial() {
|
|
|
K3CloudApi client = new K3CloudApi(initIden());
|
|
|
|
|
|
List<Map> result = new ArrayList<>();
|
|
|
+ List<Map> materialList = new ArrayList<>();
|
|
|
|
|
|
int startRow = 0;
|
|
|
int limit = 2000;
|
|
|
|
|
|
BillQuery billQuery = new BillQuery();
|
|
|
billQuery.setFormId("BD_MATERIAL");
|
|
|
- billQuery.setFieldKeys("FNumber,FName,F_Sl_xingnengid,F_Sl_cihuaid,FErpClsID,F_Sl_xingzhuangid,F_Sl_ducengid,F_Sl_ischongciid,F_Sl_chihuaguige,F_Sl_midu,F_Sl_guige,F_Sl_weight,F_Sl_ischeck,F_Sl_qianguige,F_Sl_cixiangchang,F_NLD_gongyi,F_Sl_biaomianji,FMaterialGroup,FCategoryID,FVOLUME,FBaseUnitId");
|
|
|
+ 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<>();
|
|
|
- //
|
|
|
- filterString.add(UtilMap.map("FieldName, Compare, Value, Left, Right, Logic","FCreateDate","93","2025-09-15 00:00:00","","","0"));//创建时间等于XX
|
|
|
+
|
|
|
+ //审核日期为昨天至今天
|
|
|
+ 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
|
|
|
+
|
|
|
|
|
|
billQuery.setFilterString(filterString);
|
|
|
billQuery.setLimit(limit);
|
|
|
- billQuery.setStartRow(startRow);
|
|
|
|
|
|
do {
|
|
|
billQuery.setStartRow(startRow);
|
|
|
@@ -75,13 +62,76 @@ public class JinlunServiceImpl implements JinlunService {
|
|
|
} catch (Exception e) {
|
|
|
throw new RuntimeException(e);
|
|
|
}
|
|
|
-
|
|
|
- result.addAll((List<Map>)JSONObject.parse(s));
|
|
|
+ result = (List<Map>)JSONObject.parse(s);
|
|
|
+ materialList.addAll(result);
|
|
|
|
|
|
startRow += limit;
|
|
|
}while (result.size() == limit);
|
|
|
|
|
|
- System.out.println("111");
|
|
|
+ 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;
|
|
|
+
|
|
|
+ }
|
|
|
+ data.put("ShortText1757933048314",wlsx);//物料属性
|
|
|
+
|
|
|
+ data.put("Number1757933060744",UtilMap.getDouble(map,"FVOLUME"));//体积
|
|
|
+ data.put("ShortText1757933079170",UtilMap.getString(map,"FBaseUnitId.FName"));//基本单位
|
|
|
+
|
|
|
+ String schemaCode = "WL";
|
|
|
+
|
|
|
+ Map body = new HashMap();
|
|
|
+
|
|
|
+ body.put("data",data);
|
|
|
+ body.put("schemaCode",schemaCode);
|
|
|
+ body.put("userId",cloudpivotConfig.getOperatorUserId());
|
|
|
+
|
|
|
+ //云枢新增物料
|
|
|
+ Map result2 = createCpBo(schemaCode, body,null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public McR addCustomer(@RequestBody Map map) {
|
|
|
+ //查询云枢客户单据详情
|
|
|
+ String objectId = UtilMap.getString(map, "objectId");
|
|
|
+
|
|
|
+ Map customer = getCpBo("ZLKHLC", objectId, null);
|
|
|
+
|
|
|
+ return McR.success();
|
|
|
}
|
|
|
|
|
|
private IdentifyInfo initIden(){
|
|
|
@@ -98,4 +148,94 @@ public class JinlunServiceImpl implements JinlunService {
|
|
|
return iden;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 云枢获取token
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String getCpAccessToken(){
|
|
|
+ String accessToken = UtilToken.get("invalid-token-cloudpivot");
|
|
|
+
|
|
|
+ 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());
|
|
|
+
|
|
|
+ String s = UtilHttp.doPost(cloudpivotConfig.getRedirectUri()+"oauth/token", null, params, new HashMap());
|
|
|
+
|
|
|
+ Map result = (Map) JSONObject.parse(s);
|
|
|
+
|
|
|
+ accessToken = "bearer" + UtilMap.getString(result, "access_token");
|
|
|
+
|
|
|
+ long expiresIn = UtilMap.getLong(result, "expires_in") * 1000;
|
|
|
+
|
|
|
+ UtilToken.put("invalid-token-cloudpivot", accessToken, expiresIn);
|
|
|
+
|
|
|
+ return accessToken;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 云枢新增表单
|
|
|
+ * @param schemaCode
|
|
|
+ * @param data
|
|
|
+ * @param userId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private Map createCpBo(String schemaCode, Map data, String userId){
|
|
|
+ Map body = new HashMap();
|
|
|
+
|
|
|
+ body.put("data",data);
|
|
|
+ body.put("schemaCode",schemaCode);
|
|
|
+ if (Strings.isNullOrEmpty(userId)){
|
|
|
+ body.put("userId",cloudpivotConfig.getOperatorUserId());
|
|
|
+ }else {
|
|
|
+ body.put("userId",userId);
|
|
|
+ }
|
|
|
+
|
|
|
+ String s = UtilHttp.doPost(cloudpivotConfig.getRedirectUri() + "openapi/v3/bo/create", CloudpivotConfig.initTokenHeader(getCpAccessToken()), null, body);
|
|
|
+
|
|
|
+ Map result = (Map) JSONObject.parse(s);
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 云枢获取表单详情
|
|
|
+ * @param schemaCode
|
|
|
+ * @param objectId
|
|
|
+ * @param userId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private Map getCpBo(String schemaCode, String objectId, String userId){
|
|
|
+ Map body = new HashMap();
|
|
|
+
|
|
|
+ body.put("objectId",objectId);
|
|
|
+ body.put("schemaCode",schemaCode);
|
|
|
+ if (Strings.isNullOrEmpty(userId)){
|
|
|
+ body.put("userId",cloudpivotConfig.getOperatorUserId());
|
|
|
+ }else {
|
|
|
+ body.put("userId",userId);
|
|
|
+ }
|
|
|
+
|
|
|
+ String s = UtilHttp.doPost(cloudpivotConfig.getRedirectUri() + "openapi/v3/bo/get", CloudpivotConfig.initTokenHeader(getCpAccessToken()), null, body);
|
|
|
+
|
|
|
+ Map result = (Map) JSONObject.parse(s);
|
|
|
+
|
|
|
+ isSuccess(result);
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void isSuccess(Map result){
|
|
|
+ int errcode = UtilMap.getInt(result, "errcode");
|
|
|
+ String errmsg = UtilMap.getString(result, "errmsg");
|
|
|
+
|
|
|
+ if (errcode != 0){
|
|
|
+ throw new RuntimeException("云枢接口调用失败:" + errmsg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|