|
|
@@ -5,12 +5,14 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.malk.server.aliwork.YDConf;
|
|
|
import com.malk.server.aliwork.YDParam;
|
|
|
+import com.malk.server.common.McException;
|
|
|
import com.malk.server.dingtalk.DDR_New;
|
|
|
import com.malk.service.aliwork.YDClient;
|
|
|
import com.malk.service.aliwork.YDService;
|
|
|
import com.malk.taisen.service.RtrServer;
|
|
|
import com.malk.taisen.util.CusutUtil;
|
|
|
import com.malk.taisen.util.HttpUtil;
|
|
|
+import com.malk.utils.UtilDateTime;
|
|
|
import com.malk.utils.UtilMap;
|
|
|
import com.malk.utils.UtilNumber;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
@@ -38,6 +40,9 @@ public class RtrServerImpl implements RtrServer {
|
|
|
@Value(value = "${sap.QA_sapUrl_Poc}")
|
|
|
private String QA_sapUrl ;
|
|
|
|
|
|
+ @Value(value = "${sap.JT_sapUrl_Poc}")
|
|
|
+ private String JT_sapUrl ;
|
|
|
+
|
|
|
@Override
|
|
|
public void RtrInsetSAP0005(String type,String formUuid, String InstanceId) {
|
|
|
DDR_New ddr = ydClient.queryData(YDParam.builder().formInstId(InstanceId).build(), YDConf.FORM_QUERY.retrieve_id);
|
|
|
@@ -215,4 +220,101 @@ public class RtrServerImpl implements RtrServer {
|
|
|
public static YDParam _getYDTokenZXXZ(String searchFieldJson) {
|
|
|
return YDParam.builder().formUuid("FORM-4J7669A10FO250UJ9C6Q7CM00PC62YPW8DD6LT").searchFieldJson(searchFieldJson).build();
|
|
|
}
|
|
|
+
|
|
|
+ // 销售计提
|
|
|
+ @Override
|
|
|
+ public void RtrInsetSAP0020(String type, String formUuid, String InstanceId) {
|
|
|
+
|
|
|
+ DDR_New ddr = ydClient.queryData(YDParam.builder().formInstId(InstanceId).build(), YDConf.FORM_QUERY.retrieve_id);
|
|
|
+ Map dataForm = ddr.getFormData();
|
|
|
+
|
|
|
+ /// 主表字段: 公司代码, 凭证类型, 货币码, 钉钉单据号, 发起人
|
|
|
+ Map body = UtilMap.map( "BUKRS, BLART, WAERS, XBLNR, USNAM",
|
|
|
+ "textField_mejfj9iw, selectField_mejkjsb5, selectField_mejfoong, serialNumberField_mjc4e95b, textField_mjihy3sl",
|
|
|
+ dataForm);
|
|
|
+ /// 主表字段: 凭证日期, 过账日期, 会计期间
|
|
|
+ body.put("BLDAT", UtilDateTime.format(new Date(UtilMap.getLong(dataForm, "dateField_mipgl0vv")), "yyyyMMdd"));
|
|
|
+ body.put("BUDAT", UtilDateTime.format(new Date(UtilMap.getLong(dataForm, "dateField_mjc39hdc")), "yyyyMMdd"));
|
|
|
+ if (UtilMap.getString(dataForm, "textField_mipmks2t").contains("-")) {
|
|
|
+ body.put("MONAT", UtilMap.getString(dataForm, "textField_mipmks2t").split("-")[1]);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Map> details = UtilMap.getList(dataForm, "tableField_mipgl0vx");
|
|
|
+ if (details.size() == 50) {
|
|
|
+ details = ydService.queryDetails(YDParam.builder().formInstanceId(InstanceId).formUuid(formUuid).tableFieldId("tableField_mipgl0vx").build());
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("销售计提行项目, {}, {}", InstanceId, details.size());
|
|
|
+ int total = details.size(), succ = 0, fail = 0;
|
|
|
+ // 批量推送Sap凭证: 兼容重试场景
|
|
|
+ for (Map detail : details) {
|
|
|
+
|
|
|
+ if ("成功".equals(UtilMap.getString(detail, "selectField_mjihy3si"))) {
|
|
|
+ succ += 1;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// 主表字段: 上传编号, 抬头文本
|
|
|
+ String referCode = UtilMap.getString(dataForm, "serialNumberField_mjc4e95b") + UtilMap.getString(detail, "textField_mjif9kha");
|
|
|
+ body.put("ZUPDNR", referCode);
|
|
|
+ body.put("BKTXT", UtilMap.getString(detail, "textField_mipgl0w4"));
|
|
|
+
|
|
|
+ /// 明细字段: 凭证货币金额, 成本中心, 项目文本, 利润中心, 分配, 参考码1, 参考码2, 产品号, 销售组织, 分销渠道, 产品组, 客户定义, 物料组包装物料, 销售地区, 客户简称
|
|
|
+ Map row = UtilMap.map("WRBTR, KOSTL, SGTXT, PRCTR, ZUONR, XREF1, XREF2, ARTNR, VKORG, VTWEG, SPART, KDKG4, MAGRV, BZIRK, WWKCG",
|
|
|
+ "numberField_mipgl0w2, textField_mipgl0w3, textField_mipgl0w4, textField_mjihy3sn, textField_mipgl0w5, textField_mipgl0w6, textField_mipgl0w7, textField_mipgl0w9, textField_mipgl0wa, textField_mipgl0wb, textField_mipgl0wc, textField_mipgl0wd, textField_mipgl0we, textField_mipgl0wf, textField_mipgl0wg",
|
|
|
+ detail);
|
|
|
+
|
|
|
+ try {
|
|
|
+
|
|
|
+ Map result = this._pushSap(detail, body, row);
|
|
|
+ if ("S".equals(result.get("E_SYSMSGTYPE"))) {
|
|
|
+ detail.put("selectField_mjihy3si", "成功");
|
|
|
+ detail.put("textField_mejezfwk", result.get("E_BELNR"));
|
|
|
+ detail.put("textField_l9nsavm2", result.get("E_GJAHR"));
|
|
|
+ succ += 1;
|
|
|
+ } else {
|
|
|
+ detail.put("selectField_mjihy3si", "失败");
|
|
|
+ fail += 1;
|
|
|
+ }
|
|
|
+ detail.put("textareaField_mi5kjmxb", result.get("E_MESSAGE"));
|
|
|
+
|
|
|
+ } catch (McException mc) {
|
|
|
+ detail.put("selectField_mjihy3si", "失败");
|
|
|
+ detail.put("textareaField_mi5kjmxb", mc.getMessage());
|
|
|
+ fail +=1;
|
|
|
+ }
|
|
|
+ /// 子表回写: 行项目-凭证号
|
|
|
+ detail.put("textField_mjihy3sm", referCode);
|
|
|
+ }
|
|
|
+ String state = "已完成";
|
|
|
+ if (fail > 0) {
|
|
|
+ state = "部分失败";
|
|
|
+ }
|
|
|
+ if (fail == total) {
|
|
|
+ state = "全部失败";
|
|
|
+ }
|
|
|
+ Map formData = UtilMap.map("tableField_mipgl0vx, numberField_mjc39hdi, numberField_mjc39hdj, numberField_mjc39hdk, selectField_mi72r4s6", details, total, succ, fail, state);
|
|
|
+ log.info("销售计提执行, {}", formData);
|
|
|
+ ydClient.operateData(YDParam.builder().formInstanceId(InstanceId).updateFormDataJson(JSON.toJSONString(formData)).build(), YDConf.FORM_OPERATION.update);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// 推送Sap
|
|
|
+ private Map _pushSap(Map detail, Map body, Map row) {
|
|
|
+
|
|
|
+ /// 借贷处理: 行项目号; 记账代码, 借方-40, 贷方-50; 总账科目;
|
|
|
+ List<Map> items = new ArrayList<>();
|
|
|
+ Map jf = UtilMap.map("ITMNR, BSCHL, HKONT", "001", "40", UtilMap.getString(detail, "textField_mipgl0vy"));
|
|
|
+ jf.putAll(row);
|
|
|
+ items.add(jf);
|
|
|
+ Map df = UtilMap.map("ITMNR, BSCHL, HKONT", "002", "50", UtilMap.getString(detail, "textField_mipgl0w1"));
|
|
|
+ df.putAll(row);
|
|
|
+ items.add(df);
|
|
|
+ body.put("ITEMS", items);
|
|
|
+ log.info("销售计提推送 SAP, {}", JSON.toJSONString(body));
|
|
|
+ String rsp = HttpUtil.post(JT_sapUrl, null, JSON.toJSONString(body), null);
|
|
|
+ log.info("销售计提 SAP 响应, {}", rsp);
|
|
|
+ List<Map> result = JSON.parseArray(rsp, Map.class);
|
|
|
+ McException.assertAccessException(result.isEmpty(), "Sap接口请求异常, 返回空集合, 需重新推送.");
|
|
|
+ return result.get(0);
|
|
|
+ }
|
|
|
}
|