HeShuController.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. package com.malk.heshu.controller;
  2. import cn.hutool.core.bean.BeanUtil;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.google.gson.Gson;
  5. import com.google.gson.JsonObject;
  6. import com.kingdee.bos.webapi.entity.IdentifyInfo;
  7. import com.kingdee.bos.webapi.entity.RepoRet;
  8. import com.kingdee.bos.webapi.sdk.K3CloudApi;
  9. import com.malk.heshu.entity.*;
  10. import com.malk.server.aliwork.YDConf;
  11. import com.malk.server.aliwork.YDParam;
  12. import com.malk.server.common.McR;
  13. import com.malk.service.aliwork.YDClient;
  14. import com.malk.utils.PublicUtil;
  15. import com.malk.utils.UtilMap;
  16. import com.malk.heshu.config.KDWebApiConf;
  17. import lombok.extern.slf4j.Slf4j;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.web.bind.annotation.GetMapping;
  20. import org.springframework.web.bind.annotation.PostMapping;
  21. import org.springframework.web.bind.annotation.RequestBody;
  22. import org.springframework.web.bind.annotation.RestController;
  23. import java.util.ArrayList;
  24. import java.util.List;
  25. import java.util.Map;
  26. import static org.junit.Assert.fail;
  27. @RestController
  28. @Slf4j
  29. public class HeShuController {
  30. @Autowired
  31. private KDWebApiConf kdWebApiConf;
  32. @Autowired
  33. private YDClient ydClient;
  34. private IdentifyInfo initIden(){
  35. //注意 1:此处不再使用参数形式传入用户名及密码等敏感信息,改为在登录配置文件中设置。
  36. //注意 2:必须先配置第三方系统登录授权信息后,再进行业务操作,详情参考各语言版本SDK介绍中的登录配置文件说明。
  37. //读取配置,初始化SDK
  38. IdentifyInfo iden = new IdentifyInfo();
  39. iden.setUserName(kdWebApiConf.getXKDApiUserName());
  40. iden.setAppId(kdWebApiConf.getXKDApiAppID());
  41. iden.setdCID(kdWebApiConf.getXKDApiAcctID());
  42. iden.setAppSecret(kdWebApiConf.getXKDApiAppSec());
  43. iden.setServerUrl(kdWebApiConf.getXKDApiServerUrl());
  44. return iden;
  45. }
  46. @GetMapping("/test")
  47. public McR test(){
  48. return McR.success("111");
  49. }
  50. @PostMapping("/saveSupplier")
  51. public McR saveSupplier(@RequestBody JSONObject params){
  52. log.info("saveSupplier:{}",params);
  53. if(PublicUtil.isNull(params,"fid")){
  54. return McR.error("201","缺少参数!");
  55. }
  56. try {
  57. Thread.sleep(500);// 休眠5s避免同时更新一条数据
  58. Map formData= (Map) ydClient.queryData(YDParam.builder().formInstId(params.getString("fid")).build(), YDConf.FORM_QUERY.retrieve_id).getFormData();
  59. if(formData==null){
  60. return McR.error("201","未查询到数据!");
  61. }
  62. List<String> types=UtilMap.getList(formData,"checkboxField_mma72l0x");
  63. String gysType;
  64. if(types.contains("供应商")){
  65. gysType="01";
  66. }else {
  67. gysType="03";
  68. }
  69. SupplierEntity supplierEntity = BeanUtil.toBean(formData, SupplierEntity.class);
  70. SupplierEntity.FBaseInfo fBaseInfo = BeanUtil.toBean(formData, SupplierEntity.FBaseInfo.class);
  71. SupplierEntity.FFinanceInfo fFinanceInfo = BeanUtil.toBean(formData, SupplierEntity.FFinanceInfo.class);
  72. List<Map> list=UtilMap.getList(formData,"tableField_mma72l0q");
  73. List<SupplierEntity.FBankInfo> bkList=new ArrayList<>();
  74. for(Map map:list){
  75. SupplierEntity.FBankInfo fBankInfo = BeanUtil.toBean(map, SupplierEntity.FBankInfo.class);
  76. bkList.add(fBankInfo);
  77. }
  78. fBaseInfo.setFDeptId(new IdObject(UtilMap.getString(formData,"textField_mogukmdd")));// 业务部门
  79. supplierEntity.setFBaseInfo(fBaseInfo);
  80. supplierEntity.setFFinanceInfo(fFinanceInfo);
  81. supplierEntity.setFBankInfo(bkList);
  82. List<Map> list2=UtilMap.getList(formData,"tableField_mma72kx1");
  83. List<SupplierEntity.FSupplierContact> lxrList=new ArrayList<>();
  84. for(Map map:list2){
  85. SupplierEntity.FSupplierContact lxrInfo = BeanUtil.toBean(map, SupplierEntity.FSupplierContact.class);
  86. lxrList.add(lxrInfo);
  87. }
  88. supplierEntity.setFSupplierContact(lxrList);
  89. supplierEntity.setFGroup(new IdObject(gysType));
  90. supplierEntity.setF_UNW_yida("https://garktl.aliwork.com/APP_QM42OEGLMNNGBLIJELJI/processDetail?formUuid=FORM-9C0EC03227CC49738447A27B4563779F0WLW&procInsId="+params.getString("fid"));
  91. String operator=UtilMap.getString(formData,"radioField_mma72l0t");// 操作类型 客商准入 客商更新
  92. if(operator.equals("客商更新")){
  93. String fId=UtilMap.getString(formData,params.getString("textField_moi1ejl2"));
  94. if(!PublicUtil.isNull(fId)){
  95. // 反审核
  96. unAudit("BD_Supplier",fId);
  97. supplierEntity.setFSupplierId(Integer.parseInt(fId));
  98. }
  99. }
  100. return saveToAudit("BD_Supplier",supplierEntity,params.getString("fid"),params.getString("key"),"selectField_mogukmd9","textareaField_mogukmdb","textField_moi1ejl2");
  101. }catch (Exception e){
  102. return McR.error("201",e.getMessage());
  103. }
  104. }
  105. @PostMapping("/saveCust")
  106. public McR saveCust(@RequestBody JSONObject params){
  107. log.info("saveCust:{}",params);
  108. if(PublicUtil.isNull(params,"fid")){
  109. return McR.error("201","缺少参数!");
  110. }
  111. try {
  112. Map formData= (Map) ydClient.queryData(YDParam.builder().formInstId(params.getString("fid")).build(), YDConf.FORM_QUERY.retrieve_id).getFormData();
  113. if(formData==null){
  114. return McR.error("201","未查询到数据!");
  115. }
  116. CustomerInfo customerInfo = BeanUtil.toBean(formData, CustomerInfo.class);
  117. List<Map> list=UtilMap.getList(formData,"tableField_mma72l0q");
  118. List<CustomerInfo.CustBank> bkList=new ArrayList<>();
  119. for(Map map:list){
  120. CustomerInfo.CustBank fBankInfo = BeanUtil.toBean(map, CustomerInfo.CustBank.class);
  121. bkList.add(fBankInfo);
  122. }
  123. customerInfo.setFT_BD_CUSTBANK(bkList);
  124. List<Map> list2=UtilMap.getList(formData,"tableField_mogukmdh");
  125. List<CustomerInfo.CustContact> dzList=new ArrayList<>();
  126. for(Map map:list2){
  127. CustomerInfo.CustContact custContact = BeanUtil.toBean(map, CustomerInfo.CustContact.class);
  128. dzList.add(custContact);
  129. }
  130. customerInfo.setFT_BD_CUSTCONTACT(dzList);
  131. customerInfo.setFSALDEPTID(new FNumber(UtilMap.getString(formData,"textField_mogukmdd")));// 业务部门
  132. String custTypeValue=UtilMap.getString(formData,"radioField_mma72kxi");
  133. String custType;
  134. if(custTypeValue.equals("贸易商")){
  135. custType="02";
  136. }else if(custTypeValue.equals("工厂")){
  137. custType="01";
  138. }else {
  139. custType="05";
  140. }
  141. customerInfo.setFGroup(new FNumber(custType));
  142. String operator=UtilMap.getString(formData,"radioField_mma72l0t");// 操作类型 客商准入 客商更新
  143. if(operator.equals("客商更新")){
  144. String fId=UtilMap.getString(formData,"textField_moi1ejl1");
  145. if(!PublicUtil.isNull(fId)){
  146. // 反审核
  147. unAudit("BD_Customer",fId);
  148. customerInfo.setFCUSTID(Integer.parseInt(fId));
  149. }
  150. }
  151. return saveToAudit("BD_Customer",customerInfo,params.getString("fid"),params.getString("key"),"selectField_mogukmd8","textareaField_mogukmda","textField_moi1ejl1");
  152. }catch (Exception e){
  153. return McR.error("201",e.getMessage());
  154. }
  155. }
  156. private McR saveToAudit(String formid, Object object,String fid,String codeKey,String statusKey,String msgKey,String idKey) throws Exception {
  157. JSONObject resultObj = new JSONObject();
  158. K3CloudApi client = new K3CloudApi(initIden());
  159. String result=client.save(formid,JSONObject.toJSONString(UtilMap.map("Model",object)));
  160. resultObj.put("save",result);
  161. Gson gson = new Gson();
  162. RepoRet sRet = gson.fromJson(result, RepoRet.class);
  163. if (sRet.isSuccessfully()) {
  164. if(!PublicUtil.isNull(codeKey)){
  165. // 回写信息
  166. JSONObject reObj = JSONObject.parseObject(result,JSONObject.class);
  167. Map updateMap=UtilMap.map(codeKey,reObj.getJSONObject("Result").getString("Number"));
  168. updateMap.put(statusKey,"成功");
  169. updateMap.put(idKey,reObj.getJSONObject("Result").getString("Id"));// ID 内码
  170. ydClient.operateData(YDParam.builder().formInstId(fid).updateFormDataJson(
  171. JSONObject.toJSONString(updateMap)
  172. ).build(), YDConf.FORM_OPERATION.update);
  173. }
  174. JsonObject jsonData = new JsonObject();
  175. jsonData.addProperty("Ids", sRet.getResult().getId());
  176. String result2=client.submit(formid, jsonData.toString());
  177. resultObj.put("submit",result2);
  178. RepoRet sRet2 = gson.fromJson(result, RepoRet.class);
  179. if (sRet2.isSuccessfully()) {
  180. JsonObject jsonData3 = new JsonObject();
  181. jsonData3.addProperty("Ids", sRet2.getResult().getId());
  182. String result3 = client.audit(formid, jsonData3.toString());
  183. resultObj.put("audit",result3);
  184. RepoRet repoRet3 = gson.fromJson(result3, RepoRet.class);
  185. if (repoRet3.getResult().getResponseStatus().isIsSuccess()) {
  186. log.info("审批通过,新增完成");
  187. return McR.success(resultObj);
  188. // Map map=UtilMap.map("PkIds, TOrgIds",sRet.getResult().getId(),"1,105818,105822,127834,127835,127838,127843,127846,127847,127848,127850,127862,1370321,1325841,1327202,1646858");
  189. // String result4=client.allocate("formid",JSONObject.toJSONString(map));
  190. // resultObj.put("allocate",result4);
  191. // RepoRet repoRet4 = gson.fromJson(result4, RepoRet.class);
  192. // if (repoRet4.getResult().getResponseStatus().isIsSuccess()) {
  193. // log.info("分配完成");
  194. // return McR.success(resultObj);
  195. // }
  196. }
  197. }
  198. }else {
  199. log.info("保存失败:{}",result);
  200. Map updateMap=UtilMap.map(statusKey,"失败");
  201. updateMap.put(msgKey,result);
  202. ydClient.operateData(YDParam.builder().formInstId(fid).updateFormDataJson(
  203. JSONObject.toJSONString(updateMap)
  204. ).build(), YDConf.FORM_OPERATION.update);
  205. }
  206. return McR.error("203",JSONObject.toJSONString(resultObj));
  207. }
  208. private void unAudit(String formid,String fNumber) throws Exception {
  209. K3CloudApi client = new K3CloudApi(initIden());
  210. Gson gson = new Gson();
  211. JsonObject jsonData = new JsonObject();
  212. jsonData.addProperty("Ids", fNumber);
  213. String result=client.unAudit(formid, jsonData.toString());
  214. RepoRet sRet2 = gson.fromJson(result, RepoRet.class);
  215. if (!sRet2.isSuccessfully()) {
  216. log.info("反审核失败:{}",result);
  217. }
  218. }
  219. }