|
@@ -0,0 +1,215 @@
|
|
|
|
|
+package com.malk.huagao.service.impl;
|
|
|
|
|
+
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
+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.huagao.KdEntity.BillQuery;
|
|
|
|
|
+import com.malk.huagao.KdEntity.View;
|
|
|
|
|
+import com.malk.huagao.config.KDWebApiConf;
|
|
|
|
|
+import com.malk.huagao.service.KdHuaGaoService;
|
|
|
|
|
+import com.malk.server.aliwork.YDConf;
|
|
|
|
|
+import com.malk.server.aliwork.YDParam;
|
|
|
|
|
+import com.malk.server.aliwork.YDSearch;
|
|
|
|
|
+import com.malk.server.common.McR;
|
|
|
|
|
+import com.malk.service.aliwork.YDClient;
|
|
|
|
|
+import com.malk.utils.UtilMap;
|
|
|
|
|
+import org.slf4j.MDC;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
+
|
|
|
|
|
+import java.time.LocalDate;
|
|
|
|
|
+import java.time.temporal.WeekFields;
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
+
|
|
|
|
|
+import static org.junit.Assert.fail;
|
|
|
|
|
+
|
|
|
|
|
+@Service
|
|
|
|
|
+public class KdHuaGaoServiceImpl implements KdHuaGaoService {
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private KDWebApiConf kdWebApiConf;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private YDClient ydClient;
|
|
|
|
|
+
|
|
|
|
|
+ //在库状态
|
|
|
|
|
+ private static final Map<String,String> STOCK_STATUS = new HashMap<>();
|
|
|
|
|
+ static{
|
|
|
|
|
+ STOCK_STATUS.put("0","待入库");
|
|
|
|
|
+ STOCK_STATUS.put("1","在库");
|
|
|
|
|
+ STOCK_STATUS.put("2","待出库");
|
|
|
|
|
+ STOCK_STATUS.put("3","出库");
|
|
|
|
|
+ STOCK_STATUS.put("4","待售出");
|
|
|
|
|
+ STOCK_STATUS.put("5","售出");
|
|
|
|
|
+ STOCK_STATUS.put("6","待退料");
|
|
|
|
|
+ STOCK_STATUS.put("7","退料");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void syncBDSerialMainFile() {
|
|
|
|
|
+ MDC.put("MDC_KEY_PID","1002");
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ K3CloudApi client = new K3CloudApi(initIden());
|
|
|
|
|
+
|
|
|
|
|
+ int startRow = 0;
|
|
|
|
|
+ int limit = 2000;
|
|
|
|
|
+
|
|
|
|
|
+ BillQuery billQuery = new BillQuery();
|
|
|
|
|
+
|
|
|
|
|
+ billQuery.setLimit(limit);
|
|
|
|
|
+ billQuery.setFormId("BD_SerialMainFile");
|
|
|
|
|
+ billQuery.setFieldKeys("FNumber");
|
|
|
|
|
+ List<Map> filterString = new ArrayList<>();
|
|
|
|
|
+ //仓库等于成品仓 仓位等于默认仓位或样机仓位 在库状态等于待入库或在库
|
|
|
|
|
+ filterString.add(UtilMap.map("FieldName, Compare, Value, Left, Right, Logic","FStockId.FName","67","成品仓","","","0"));//仓库名称等于XX
|
|
|
|
|
+ filterString.add(UtilMap.map("FieldName, Compare, Value, Left, Right, Logic","FStockLocId.FF100001.FName","67","默认仓位","(","","1"));//仓位等于XX
|
|
|
|
|
+ filterString.add(UtilMap.map("FieldName, Compare, Value, Left, Right, Logic","FStockLocId.FF100001.FName","67","样机仓位","",")","0"));//仓位等于XX
|
|
|
|
|
+ filterString.add(UtilMap.map("FieldName, Compare, Value, Left, Right, Logic","FStockStatus","29","0","(","","1"));//在库状态等于XX
|
|
|
|
|
+ filterString.add(UtilMap.map("FieldName, Compare, Value, Left, Right, Logic","FStockStatus","29","1","",")","0"));//在库状态等于XX
|
|
|
|
|
+
|
|
|
|
|
+ billQuery.setFilterString(filterString);
|
|
|
|
|
+
|
|
|
|
|
+ List<Map> result = new ArrayList<>();
|
|
|
|
|
+ List<Map> list = new ArrayList<>();
|
|
|
|
|
+
|
|
|
|
|
+ do {
|
|
|
|
|
+ billQuery.setStartRow(startRow);
|
|
|
|
|
+ String s = client.billQuery(JSONObject.toJSONString(billQuery));
|
|
|
|
|
+ result = (List<Map>)JSONObject.parse(s);
|
|
|
|
|
+ list.addAll(result);
|
|
|
|
|
+
|
|
|
|
|
+ startRow += limit;
|
|
|
|
|
+ }while (result.size() == limit);
|
|
|
|
|
+
|
|
|
|
|
+ for (Map map : list) {
|
|
|
|
|
+ String FNumber = UtilMap.getString(map,"FNumber");
|
|
|
|
|
+
|
|
|
|
|
+ //查找序列号主档具体信息
|
|
|
|
|
+ View view = new View();
|
|
|
|
|
+ view.setNumber(FNumber);
|
|
|
|
|
+ String resultJson = client.view("BD_SerialMainFile", JSONObject.toJSONString(view));
|
|
|
|
|
+ Gson gson = new Gson();
|
|
|
|
|
+ RepoRet repoRet = gson.fromJson(resultJson, RepoRet.class);
|
|
|
|
|
+ if (isTrue(repoRet)){
|
|
|
|
|
+ Map formData = new HashMap();
|
|
|
|
|
+
|
|
|
|
|
+ Map serialMainFileInfo = (Map) repoRet.getResult().getResult();
|
|
|
|
|
+
|
|
|
|
|
+ formData.put("textField_mev1n46z",UtilMap.getString(serialMainFileInfo, "Number"));//序列号
|
|
|
|
|
+ formData.put("textField_mev1n470",getNumber(UtilMap.getMap(serialMainFileInfo,"MaterialID")));//物料编码
|
|
|
|
|
+ formData.put("textField_mev1n471",getMultiLanguageTextName(UtilMap.getMap(serialMainFileInfo,"MaterialID")));//物料名称
|
|
|
|
|
+ formData.put("textField_mev1n472",getMultiLanguageTextSpecification(UtilMap.getMap(serialMainFileInfo,"MaterialID")));//规格型号
|
|
|
|
|
+ formData.put("textField_mev1n477",getMultiLanguageTextName(UtilMap.getMap(UtilMap.getMap(serialMainFileInfo,"MaterialID"),"F_QUXZ_Assistant")));//所属系列
|
|
|
|
|
+ double zkts = UtilMap.getDouble(serialMainFileInfo, "FZKTS") == 0.0 ? 1.0 : UtilMap.getDouble(serialMainFileInfo, "FZKTS");
|
|
|
|
|
+ formData.put("numberField_mev1n478", zkts);//在库天数
|
|
|
|
|
+
|
|
|
|
|
+ List<Map> bdSerialmasterorg = UtilMap.getList(serialMainFileInfo, "BD_SERIALMASTERORG");
|
|
|
|
|
+ String stockStatus = STOCK_STATUS.get(UtilMap.getString(bdSerialmasterorg.get(0), "StockStatus"));
|
|
|
|
|
+ formData.put("textField_mev1n476", stockStatus);//在库状态
|
|
|
|
|
+
|
|
|
|
|
+ List<Map> bdSerialmasterother = UtilMap.getList(serialMainFileInfo, "BD_SERIALMASTEROTHER");
|
|
|
|
|
+ formData.put("textField_mev1n473",getMultiLanguageTextName(UtilMap.getMap((bdSerialmasterother).get(0),"StockId")));//仓库
|
|
|
|
|
+ formData.put("textField_mev1n474",getMultiLanguageTextName(UtilMap.getMap(UtilMap.getMap((bdSerialmasterother).get(0),"StockLocId"),"F100001")));//仓库
|
|
|
|
|
+ formData.put("textField_mev1n475",getMultiLanguageTextName(UtilMap.getMap((bdSerialmasterother).get(0),"CustId")));//客户
|
|
|
|
|
+
|
|
|
|
|
+ //在库天数分类
|
|
|
|
|
+ int zktsfl = 1;
|
|
|
|
|
+ if ("待入库".equals(stockStatus)){
|
|
|
|
|
+ zktsfl = 1;
|
|
|
|
|
+ }else {
|
|
|
|
|
+ if (zkts <= 30){
|
|
|
|
|
+ zktsfl = 2;
|
|
|
|
|
+ }else if (zkts <= 60){
|
|
|
|
|
+ zktsfl = 3;
|
|
|
|
|
+ }else if (zkts <= 90){
|
|
|
|
|
+ zktsfl = 4;
|
|
|
|
|
+ }else {
|
|
|
|
|
+ zktsfl = 5;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ formData.put("selectField_mf205zr0",zktsfl);
|
|
|
|
|
+
|
|
|
|
|
+ // 获取当前日期
|
|
|
|
|
+ LocalDate today = LocalDate.now();
|
|
|
|
|
+ int year = today.getYear();//获取当前年份
|
|
|
|
|
+ int month = today.getMonthValue();//当前月份
|
|
|
|
|
+ WeekFields weekFields = WeekFields.of(Locale.getDefault());
|
|
|
|
|
+ int weekOfMonth = today.get(weekFields.weekOfMonth());//当前日期是当月的第几周
|
|
|
|
|
+
|
|
|
|
|
+ formData.put("numberField_mev270x6",year);
|
|
|
|
|
+ formData.put("numberField_mev270x5",month);
|
|
|
|
|
+ formData.put("textField_mev2ers5",weekOfMonth);
|
|
|
|
|
+
|
|
|
|
|
+ ydClient.operateData(YDParam.builder()
|
|
|
|
|
+ .formUuid("FORM-3B2E5C93D7E6494B9AD920B48A90159F7DZ4")
|
|
|
|
|
+ .formDataJson(JSONObject.toJSONString(formData))
|
|
|
|
|
+ .build(), YDConf.FORM_OPERATION.create);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }catch (Exception e){
|
|
|
|
|
+ fail(e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ 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());
|
|
|
|
|
+
|
|
|
|
|
+ return iden;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private boolean isTrue(RepoRet repoRet){
|
|
|
|
|
+ Gson gson = new Gson();
|
|
|
|
|
+
|
|
|
|
|
+ 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 String getMultiLanguageTextName(Object object){
|
|
|
|
|
+ if (Objects.nonNull(object)){
|
|
|
|
|
+ Map map = (Map) object;
|
|
|
|
|
+ List<Map> multiLanguageText = (List<Map>) map.get("MultiLanguageText");
|
|
|
|
|
+ String value = UtilMap.getString(multiLanguageText.get(0),"Name");
|
|
|
|
|
+
|
|
|
|
|
+ return value;
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String getMultiLanguageTextSpecification(Object object){
|
|
|
|
|
+ if (Objects.nonNull(object)){
|
|
|
|
|
+ Map map = (Map) object;
|
|
|
|
|
+ List<Map> multiLanguageText = (List<Map>) map.get("MultiLanguageText");
|
|
|
|
|
+ String value = UtilMap.getString(multiLanguageText.get(0),"Specification");
|
|
|
|
|
+
|
|
|
|
|
+ return value;
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String getNumber(Object object){
|
|
|
|
|
+ if (Objects.nonNull(object)){
|
|
|
|
|
+ Map map = (Map) object;
|
|
|
|
|
+
|
|
|
|
|
+ String value = UtilMap.getString(map,"Number");
|
|
|
|
|
+
|
|
|
|
|
+ return value;
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|