KabeiyiServiceImpl.java 95 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048
  1. package com.malk.kabeiyi.service.impl;
  2. import cn.hutool.core.date.DateTime;
  3. import cn.hutool.core.date.DateUtil;
  4. import cn.hutool.http.HttpRequest;
  5. import cn.hutool.http.HttpResponse;
  6. import cn.hutool.http.HttpUtil;
  7. import cn.hutool.json.JSONUtil;
  8. import com.alibaba.fastjson.JSON;
  9. import com.alibaba.fastjson.JSONObject;
  10. import com.fasterxml.jackson.core.JsonProcessingException;
  11. import com.fasterxml.jackson.core.type.TypeReference;
  12. import com.fasterxml.jackson.databind.ObjectMapper;
  13. import com.malk.core.McProject;
  14. import com.malk.kabeiyi.service.KabeiyiService;
  15. import com.malk.kabeiyi.util.RecognizeAllText;
  16. import com.malk.server.aliwork.YDConf;
  17. import com.malk.server.aliwork.YDParam;
  18. import com.malk.server.common.McException;
  19. import com.malk.server.common.McR;
  20. import com.malk.server.dingtalk.DDConf;
  21. import com.malk.server.dingtalk.DDR;
  22. import com.malk.server.dingtalk.DDR_New;
  23. import com.malk.service.aliwork.YDClient;
  24. import com.malk.service.aliwork.YDService;
  25. import com.malk.service.dingtalk.DDClient;
  26. import com.malk.service.dingtalk.DDClient_Workflow;
  27. import com.malk.utils.UtilHttp;
  28. import com.malk.utils.UtilMap;
  29. import com.malk.utils.UtilToken;
  30. import lombok.extern.slf4j.Slf4j;
  31. import org.apache.commons.lang3.StringUtils;
  32. import org.apache.commons.lang3.time.DateUtils;
  33. import org.slf4j.MDC;
  34. import org.springframework.beans.factory.annotation.Autowired;
  35. import org.springframework.beans.factory.annotation.Value;
  36. import org.springframework.scheduling.annotation.Async;
  37. import org.springframework.stereotype.Service;
  38. import java.io.FileOutputStream;
  39. import java.io.IOException;
  40. import java.io.InputStream;
  41. import java.math.BigDecimal;
  42. import java.net.HttpURLConnection;
  43. import java.net.URL;
  44. import java.time.*;
  45. import java.time.format.DateTimeFormatter;
  46. import java.time.temporal.TemporalAdjusters;
  47. import java.util.*;
  48. import java.util.concurrent.atomic.AtomicReference;
  49. import java.util.stream.Collectors;
  50. @Slf4j
  51. @Service
  52. public class KabeiyiServiceImpl implements KabeiyiService {
  53. @Autowired
  54. private DDClient_Workflow ddClient_workflow;
  55. @Autowired
  56. private DDClient ddClient;
  57. @Autowired
  58. private YDService ydService;
  59. @Autowired
  60. private YDClient ydClient;
  61. @Autowired
  62. private YDConf ydConf;
  63. @Autowired
  64. private DDConf ddConf;
  65. @Value("${tcdingtalk.appKey}")
  66. private String appKey;
  67. @Value("${tcdingtalk.appSecret}")
  68. private String appSecret;
  69. @Value("${aliwork.accessKeyId}")
  70. private String accessKeyId;
  71. @Value("${aliwork.accessKeySecret}")
  72. private String accessKeySecret;
  73. @Value("${ocr.filePath}")
  74. private String filePath;
  75. @Value("${u8.fromAccount}")
  76. private String fromAccount;
  77. @Value("${u8.toAccount}")
  78. private String toAccount;
  79. @Value("${u8.appKey}")
  80. private String u8AppKey;
  81. @Value("${u8.appSecret}")
  82. private String u8AppSecret;
  83. //结算方式
  84. public final static String PAY_TYPE = "JSFS001";
  85. //审批实例url前缀(卡倍亿)
  86. private static final String PROC_INST_PREFIX_URL = "https://aflow.dingtalk.com/dingtalk/web/query/pchomepage.htm?from=oflow&op=true&corpid=dingc3a744cb591a7346f2c783f7214b6d69#/plainapproval?procInstId=";
  87. //宜搭-关联数据(卡倍亿)
  88. private static final String RELATION = "FORM-230C40137ED94524B4D4C94F8B23A8D2F8PF";
  89. //审批实例url前缀(特充)
  90. private static final String PROC_INST_PREFIX_URL2 = "https://aflow.dingtalk.com/dingtalk/web/query/pchomepage.htm?from=oflow&op=true&corpid=ding3ea249a3b5b466d0f2c783f7214b6d69#/plainapproval?procInstId=";
  91. //宜搭-关联数据(特充)
  92. private static final String RELATION2 = "FORM-51E17EFB52C14C9CB9E00168FED2BC18LQ6H";
  93. //问题整改表
  94. private static final String QUESTION = "FORM-89F515967FF94C62A9031F28EF6000B1YV5Q";
  95. //问题整改表流程code
  96. private static final String QUESTION_PROC_CODE = "TPROC--DP5660A1LEXNP1S37P7KU9GCHD5U3HB6C360M5";
  97. //审核表
  98. private static final String CHECK = "FORM-F4ED246EADD8427381BC13C4F0FEF7FDYMKJ";
  99. //审核表流程code
  100. private static final String CHECK_PROC_CODE = "TPROC--4XC66Y61XWWNZNJKBZD4VAB5BQAJ2YANX160M5";
  101. //审核计划
  102. private static final String CHECK_PLAN = "FORM-A9A7991EEB7D41FDAADADB9B1E1750FE0K5K";
  103. //产品实发
  104. private static final String PRODUCT_REAL = "FORM-809458EB6D524CF5AE1A91A3492D8B1BZIMN";
  105. //内部交易客户
  106. private static final String INTERNAL_CUSTOMER = "FORM-14782CE27EA54D2C94CC5BEF90554E5ALYP7";
  107. //内部工厂
  108. private static final String INTERNAL_FACTORY = "FORM-6CD7A1EDE1134AC8B2EE833769595C2EIWQ6";
  109. //关联表单(卡倍亿)
  110. private static final Map<String,String> SCHEMA_MAP = new HashMap<>();
  111. static{
  112. SCHEMA_MAP.put("工厂用章流程","1.1、工厂用章流程(除采购营销人事)");
  113. SCHEMA_MAP.put("中心用章流程","1.2、中心用章流程(除采购营销人事)");
  114. SCHEMA_MAP.put("人事专用用章审批流程","1.3、人事专用用章审批流程");
  115. SCHEMA_MAP.put("商务部用章申请流程","1.4、商务部用章申请流程");
  116. SCHEMA_MAP.put("办公用品采购申请流程","4.3、办公用品采购申请流程");
  117. //需传其他值
  118. //对方单位名称 收入或支出 金额 备注
  119. SCHEMA_MAP.put("信息化建设用章流程","1.7、信息化建设用章流程");
  120. //合同说明 采购物品类型
  121. SCHEMA_MAP.put("技术中心请购审批流程","4.10、技术中心请购审批流程");
  122. //合同总金额 合同说明
  123. SCHEMA_MAP.put("设备备品备件采购合同审批流程","4.1b、设备备品备件采购合同审批流程");
  124. SCHEMA_MAP.put("其他物品采购合同流程","4.2b、其他物品采购合同流程");
  125. SCHEMA_MAP.put("设备采购合同审批流程","4.5c、设备采购合同审批流程");
  126. SCHEMA_MAP.put("原材料采购合同审批流程","4.9b、原材料采购合同审批流程");
  127. SCHEMA_MAP.put("墨西哥采购合同审批流程","4.13b、墨西哥采购合同审批流程");
  128. }
  129. //关联表单(特充)
  130. private static final Map<String,String> SCHEMA_MAP2 = new HashMap<>();
  131. static{
  132. //需传其他值
  133. //对方单位名称 收入或支出 金额 备注
  134. SCHEMA_MAP2.put("特充用章流程","1.2、特充用章流程(除采购营销人事)");
  135. //合同总金额 合同说明
  136. SCHEMA_MAP2.put("设备备品备件采购合同审批流程","4.1b、设备备品备件采购合同审批流程");
  137. SCHEMA_MAP2.put("其他物品采购合同流程","4.2b、其他物品采购合同流程");
  138. SCHEMA_MAP2.put("母排设备采购合同审批流程","4.5c、母排设备采购合同审批流程");
  139. SCHEMA_MAP2.put("双铝设备采购合同审批流程","4.6c、双铝设备采购合同审批流程");
  140. //合同总金额
  141. SCHEMA_MAP2.put("原材料采购合同审批流程","4.9b、原材料采购合同审批流程");
  142. //文件类别 对方单位名称 收入或支出 金额 用印文件名称 文件份数 加盖何种印章 备注
  143. SCHEMA_MAP2.put("信息化建设用章流程","1.7、信息化建设用章流程");
  144. }
  145. @Override
  146. public McR pushProcInstToYD(Map map) {
  147. MDC.put("MDC_KEY_PID","1002");
  148. //审批实例
  149. String procInstId = String.valueOf(map.get("procInstId"));
  150. //获取审批实例信息
  151. Map processInstance = ddClient_workflow.getProcessInstanceId(ddClient.getAccessToken(), procInstId);
  152. if (Objects.nonNull(processInstance)){
  153. Map formData = new HashMap<>();
  154. String title = String.valueOf(processInstance.get("title"));
  155. String type = "";
  156. List<Map> formComponentValues = (List<Map>) processInstance.get("formComponentValues");
  157. for (String key : SCHEMA_MAP.keySet()) {
  158. if (title.contains(key)){
  159. type = SCHEMA_MAP.get(key);
  160. switch (type){
  161. case "1.7、信息化建设用章流程" :
  162. for (Map formComponentValue : formComponentValues) {
  163. String name = String.valueOf(formComponentValue.get("name"));
  164. String value = String.valueOf(formComponentValue.get("value")).equals("null") ? "" : String.valueOf(formComponentValue.get("value"));
  165. switch (name){
  166. case "对方单位名称" : formData.put("textField_lygzlf3j",value);break;
  167. case "收入或支出" : formData.put("textField_lygzlf3k",value);break;
  168. case "金额" : formData.put("textField_lygzlf3l",value);break;
  169. case "备注" : formData.put("textField_lygzlf3m",value);break;
  170. }
  171. }
  172. break;
  173. case "4.1b、设备备品备件采购合同审批流程" :
  174. case "4.2b、其他物品采购合同流程" :
  175. case "4.5c、设备采购合同审批流程" :
  176. case "4.9b、原材料采购合同审批流程" :
  177. case "4.13b、墨西哥采购合同审批流程" :
  178. for (Map formComponentValue : formComponentValues) {
  179. String name = String.valueOf(formComponentValue.get("name"));
  180. switch (name){
  181. case "合同总金额" : formData.put("numberField_lyf81587",formComponentValue.get("value"));break;
  182. case "合同说明" :
  183. if (Objects.nonNull(formComponentValue.get("value"))){
  184. formData.put("textField_lyf81588",formComponentValue.get("value"));
  185. }
  186. break;
  187. }
  188. }
  189. break;
  190. case "4.10、技术中心请购审批流程" :
  191. for (Map formComponentValue : formComponentValues) {
  192. String name = String.valueOf(formComponentValue.get("name"));
  193. switch (name){
  194. case "采购物品类型" : formData.put("textField_lyibvb98",formComponentValue.get("value"));break;
  195. case "合同说明" :
  196. if (Objects.nonNull(formComponentValue.get("value"))){
  197. formData.put("textField_lyf81588",formComponentValue.get("value"));
  198. }
  199. break;
  200. }
  201. }
  202. break;
  203. default:
  204. break;
  205. }
  206. formData.put("textField_lyf8157x",title);
  207. formData.put("selectField_lyf81580",type);
  208. Map condition = new HashMap<>();
  209. condition.put("textField_lyf81581",PROC_INST_PREFIX_URL + procInstId);
  210. //同步到宜搭
  211. ydService.upsertFormData(RELATION,condition,formData,null);
  212. break;
  213. }
  214. }
  215. return McR.success();
  216. }
  217. return McR.errorParam("审批实例不存在!");
  218. }
  219. @Override
  220. public McR pushProcInstToYD2(Map map) {
  221. MDC.put("MDC_KEY_PID","1003");
  222. //审批实例
  223. String procInstId = String.valueOf(map.get("procInstId"));
  224. //获取审批实例信息
  225. Map processInstance = ddClient_workflow.getProcessInstanceId(getTcAccessToken(), procInstId);
  226. if (Objects.nonNull(processInstance)){
  227. Map formData = new HashMap<>();
  228. String title = String.valueOf(processInstance.get("title"));
  229. String type = "";
  230. List<Map> formComponentValues = (List<Map>) processInstance.get("formComponentValues");
  231. for (String key : SCHEMA_MAP2.keySet()) {
  232. if (title.contains(key)){
  233. type = SCHEMA_MAP2.get(key);
  234. switch (type){
  235. case "1.7、信息化建设用章流程" :
  236. for (Map formComponentValue : formComponentValues) {
  237. String name = String.valueOf(formComponentValue.get("name"));
  238. Object value = formComponentValue.get("value");
  239. switch (name){
  240. case "文件类别" : formData.put("textField_lymfq9oa",value);break;
  241. case "对方单位名称" : formData.put("textField_lygzlf3j",value);break;
  242. case "收入或支出" : formData.put("textField_lygzlf3k",value);break;
  243. case "金额(元)" : formData.put("textField_lygzlf3l",value);break;
  244. case "用印文件名称" : formData.put("textField_lymfq9oc",value);break;
  245. case "文件份数" : formData.put("numberField_lymfq9od",value);break;
  246. case "加盖何种印章" : formData.put("textField_lymfq9oe",value);break;
  247. case "备注" : formData.put("textField_lygzlf3m",value);break;
  248. }
  249. }
  250. break;
  251. case "4.1b、设备备品备件采购合同审批流程" :
  252. case "4.2b、其他物品采购合同流程" :
  253. case "4.5c、母排设备采购合同审批流程" :
  254. case "4.6c、双铝设备采购合同审批流程" :
  255. case "4.9b、原材料采购合同审批流程" :
  256. for (Map formComponentValue : formComponentValues) {
  257. String name = String.valueOf(formComponentValue.get("name"));
  258. switch (name){
  259. case "合同总金额(元)":
  260. case "合同总金额" : formData.put("numberField_lyf81587",formComponentValue.get("value"));break;
  261. case "合同说明" :
  262. if (Objects.nonNull(formComponentValue.get("value"))){
  263. formData.put("textField_lyf81588",formComponentValue.get("value"));
  264. }
  265. break;
  266. }
  267. }
  268. break;
  269. case "1.2、特充用章流程(除采购营销人事)" :
  270. for (Map formComponentValue : formComponentValues) {
  271. String name = String.valueOf(formComponentValue.get("name"));
  272. String value = String.valueOf(formComponentValue.get("value")).equals("null") ? "" : String.valueOf(formComponentValue.get("value"));
  273. switch (name){
  274. case "对方单位名称" : formData.put("textField_lygzlf3j",value);break;
  275. case "收入或支出" : formData.put("textField_lygzlf3k",value);break;
  276. case "金额(元)" : formData.put("textField_lygzlf3l",value);break;
  277. case "备注" : formData.put("textField_lygzlf3m",value);break;
  278. }
  279. }
  280. break;
  281. default:
  282. break;
  283. }
  284. formData.put("textField_lyf8157x",title);
  285. formData.put("selectField_lyf81580",type);
  286. Map condition = new HashMap<>();
  287. condition.put("textField_lyf81581",PROC_INST_PREFIX_URL2 + procInstId);
  288. //同步到宜搭
  289. ydService.upsertFormData(RELATION2,condition,formData,null);
  290. break;
  291. }
  292. }
  293. return McR.success();
  294. }
  295. return McR.errorParam("审批实例不存在!");
  296. }
  297. @Override
  298. public McR addQuestionApproval(Map map) {
  299. MDC.put("MDC_KEY_PID","1009");
  300. if (Objects.isNull(map.get("formInstId"))){
  301. return McR.errorParam("formInstId不能为空!");
  302. }
  303. String formInstId = map.get("formInstId").toString();
  304. DDR_New ddrNew = ydClient.queryData(YDParam.builder()
  305. .formInstId(formInstId)
  306. .build(), YDConf.FORM_QUERY.retrieve_id);
  307. Map formData = ddrNew.getFormData();
  308. List<String> reviewerUserIds = (List<String>) formData.get("employeeField_m061zye5_id");//审核人
  309. String area = formData.get("selectField_m0w4kilf").toString();
  310. String factory = getString(formData.get("selectField_m3mmsbyd"));
  311. List<Map> details = (List<Map>) formData.get("tableField_m0kqtqoy");
  312. String[] yida = McProject.getYida("1009");
  313. for (Map detail : details) {
  314. String result = detail.get("radioField_m0nm3des").toString();
  315. if ("NG".equals(result)){
  316. //发起问题整改审批
  317. Map question = new HashMap();
  318. question.put("textField_m061zye8",detail.get("textField_m0on13ob"));//审核项目
  319. question.put("textareaField_m061zye9",detail.get("textField_m0kqtqoz"));//审核方法和标准
  320. question.put("attachmentField_m061zyep",detail.get("attachmentField_m061zyep"));//问题证据
  321. question.put("textareaField_m063drgz",detail.get("textareaField_m063drgz"));//问题描述
  322. question.put("dateField_m061zyev",detail.get("dateField_m061zyev"));//整改截止时间
  323. question.put("employeeField_m10dns9c",detail.get("employeeField_m10d5uqj_id"));//部门经理
  324. question.put("selectField_m0w4kilf",area);//审核区域
  325. question.put("selectField_m3mmsbyd",factory);//工厂
  326. Map<String,Object> body = new HashMap<>();
  327. body.put("appType",yida[0]);
  328. body.put("systemToken",yida[1]);
  329. body.put("userId",reviewerUserIds.get(0));
  330. body.put("formUuid",QUESTION);
  331. body.put("processCode",QUESTION_PROC_CODE);
  332. body.put("formDataJson", JSONObject.toJSONString(question));
  333. UtilHttp.doPost("https://api.dingtalk.com/v1.0/yida/processes/instances/start", ddClient.initTokenHeader(), null, body, DDR_New.class);
  334. }
  335. }
  336. return McR.success();
  337. }
  338. @Override
  339. public McR ocr(String downloadUrl,String name,String type) {
  340. MDC.put("MDC_KEY_PID","1020");
  341. //下载宜搭附件
  342. try {
  343. String[] yida = McProject.getYida("1020");
  344. downloadFile(downloadUrl,filePath + name,yida[0],yida[1]);
  345. log.info("文件下载成功!");
  346. } catch (IOException e) {
  347. e.printStackTrace();
  348. log.info("文件下载失败:{}" + e.getMessage());
  349. }
  350. //ocr识别
  351. try {
  352. String content = RecognizeAllText.recognizeText(filePath + name, type, accessKeyId, accessKeySecret);
  353. return McR.success(content);
  354. }catch (Exception e) {
  355. e.printStackTrace();
  356. log.info("识别失败:{}" + e.getMessage());
  357. }
  358. return McR.errorUnknown("识别失败!");
  359. }
  360. public void downloadFile(String fileURL, String savePath,String appType,String systemToken) throws IOException {
  361. //若是宜搭附件url 则需获得附件临时免登地址
  362. Map<String,Object> param = new HashMap<>();
  363. param.put("systemToken",systemToken);
  364. param.put("userId",ddConf.getOperator());
  365. param.put("fileUrl",fileURL);
  366. fileURL = ((DDR_New) UtilHttp.doGet("https://api.dingtalk.com/v1.0/yida/apps/temporaryUrls/" + appType, ddClient.initTokenHeader(), param, DDR_New.class)).getResult().toString();
  367. URL url = new URL(fileURL);
  368. HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
  369. int responseCode = httpConn.getResponseCode();
  370. // 检查HTTP响应代码是否为200
  371. if (responseCode == HttpURLConnection.HTTP_OK) {
  372. InputStream inputStream = httpConn.getInputStream();
  373. FileOutputStream outputStream = new FileOutputStream(savePath);
  374. byte[] buffer = new byte[4096];
  375. int bytesRead = -1;
  376. while ((bytesRead = inputStream.read(buffer)) != -1) {
  377. outputStream.write(buffer, 0, bytesRead);
  378. }
  379. outputStream.close();
  380. inputStream.close();
  381. } else {
  382. System.out.println("无法下载文件。HTTP响应代码: " + responseCode);
  383. }
  384. httpConn.disconnect();
  385. }
  386. @Override
  387. public McR addPlanApproval(Map map) {
  388. MDC.put("MDC_KEY_PID","1009");
  389. if (Objects.isNull(map.get("formInstId"))){
  390. return McR.errorParam("formInstId不能为空!");
  391. }
  392. String formInstId = map.get("formInstId").toString();
  393. DDR_New ddrNew = ydClient.queryData(YDParam.builder()
  394. .formInstId(formInstId)
  395. .build(), YDConf.FORM_QUERY.retrieve_id);
  396. //计划制定人
  397. Map originator = ddrNew.getOriginator();
  398. String planUserId = originator.get("userId").toString();
  399. Map formData = ddrNew.getFormData();
  400. //审核人
  401. List<String> reviewerUserIds = (List<String>) formData.get("employeeField_m061zye5_id");
  402. //频次
  403. String frequency = formData.get("selectField_m0koxj7g").toString();
  404. //下次自动发起审核日期
  405. long nextTime = (long) formData.get("dateField_m0nbpasq");
  406. Date nextDate = new Date(nextTime);
  407. //上次自动发起审核日期
  408. Date lastTime = nextDate;
  409. //审核截至日期
  410. Date endDate = new Date();
  411. switch (frequency){
  412. case "每周":
  413. endDate = DateUtils.addDays(nextDate, 6);
  414. nextDate = DateUtils.addDays(nextDate, 7);
  415. break;
  416. case "每两周":
  417. endDate = DateUtils.addDays(nextDate, 13);
  418. nextDate = DateUtils.addDays(nextDate, 14);
  419. break;
  420. case "每月":
  421. endDate = DateUtils.addDays(DateUtils.addMonths(nextDate, 1), -1);
  422. nextDate = DateUtils.addMonths(nextDate, 1);
  423. break;
  424. case "每季度":
  425. endDate = DateUtils.addDays(DateUtils.addMonths(nextDate, 3),-1);
  426. nextDate = DateUtils.addMonths(nextDate, 3);
  427. break;
  428. case "一次":
  429. endDate = new Date((long)formData.get("dateField_m0oqbh48"));
  430. nextDate = null;
  431. break;
  432. default:break;
  433. }
  434. //获取所有子表明细(大于50条)
  435. List<Map> details = getInnerTable(CHECK_PLAN,formInstId,"tableField_m0kqtqoy",1,50);
  436. formData.put("tableField_m0kqtqoy",details);
  437. //每个审批人发起审批
  438. for (String reviewerUserId : reviewerUserIds) {
  439. //根据userId获取部门id
  440. Map body = new HashMap<>();
  441. body.put("userid", reviewerUserId);
  442. DDR_New ddrNew1 = (DDR_New) UtilHttp.doPost("https://oapi.dingtalk.com/topapi/v2/department/listparentbyuser", null, ddClient.initTokenParams(), body, DDR_New.class);
  443. Map result = (Map) ddrNew1.getResult();
  444. List<Map> parentList = (List<Map>) result.get("parent_list");
  445. List<Long> parentDeptIdList = (List<Long>) parentList.get(0).get("parent_dept_id_list");
  446. String deptId = parentDeptIdList.get(0) + "";
  447. formData.put("departmentSelectField_m0c3qbjn", new String[]{deptId});
  448. formData.put("dateField_m061zye7", endDate.getTime());
  449. formData.put("employeeField_m061zye5",new String[]{reviewerUserId});
  450. //发起审批
  451. String[] yida = McProject.getYida("1009");
  452. Map<String,Object> body2 = new HashMap<>();
  453. body2.put("appType",yida[0]);
  454. body2.put("systemToken",yida[1]);
  455. body2.put("userId",planUserId);
  456. body2.put("formUuid",CHECK);
  457. body2.put("processCode",CHECK_PROC_CODE);
  458. body2.put("formDataJson", JSONObject.toJSONString(formData));
  459. UtilHttp.doPost("https://api.dingtalk.com/v1.0/yida/processes/instances/start", ddClient.initTokenHeader(), null, body2, DDR_New.class);
  460. }
  461. //更新审核计划下次发起审批时间及上次发起审批时间
  462. formData.put("dateField_m0nbpasw", lastTime);
  463. formData.put("dateField_m0nbpasq", nextDate);
  464. formData.put("employeeField_m061zye5",reviewerUserIds);
  465. ydClient.operateData(YDParam.builder()
  466. .formInstId(formInstId)
  467. .updateFormDataJson(JSON.toJSONString(formData))
  468. .build(), YDConf.FORM_OPERATION.update);
  469. return McR.success();
  470. }
  471. private List<Map> getInnerTable(String formUuid, String formInstId, String tableField, int pageNumber, int pageSize) {
  472. List<Map> details = new ArrayList<>();
  473. DDR_New ddrNew = new DDR_New();
  474. do {
  475. ddrNew = ydClient.queryData(YDParam.builder()
  476. .formUuid(formUuid)
  477. .formInstId(formInstId)
  478. .tableFieldId(tableField)
  479. .pageNumber(pageNumber)
  480. .pageSize(pageSize)
  481. .build(), YDConf.FORM_QUERY.retrieve_details);
  482. details.addAll((List<Map>)ddrNew.getData());
  483. pageNumber++;
  484. }while (ddrNew.getTotalCount() > pageSize * ddrNew.getPageNumber());
  485. return details;
  486. }
  487. @Override
  488. @Async
  489. public McR getSaleoutInfo() {
  490. //现在时间戳
  491. long beginTime = System.currentTimeMillis();
  492. MDC.put("MDC_KEY_PID","1019");
  493. //内部交易客户
  494. DDR_New ddrNew = ydClient.queryData(YDParam.builder()
  495. .formUuid(INTERNAL_CUSTOMER)
  496. .build(), YDConf.FORM_QUERY.retrieve_list);
  497. List<Map> data = (List<Map>) ddrNew.getData();
  498. Set<String> cusCodes = new HashSet<>();
  499. for (Map map : data) {
  500. Map formData = (Map) map.get("formData");
  501. cusCodes.add(getString(formData.get("textField_m1g1tp7i")));
  502. }
  503. //数据源对应工厂
  504. Map<Integer,String> factory = new HashMap<>();
  505. DDR_New ddrNew2 = ydClient.queryData(YDParam.builder()
  506. .formUuid(INTERNAL_FACTORY)
  507. .build(), YDConf.FORM_QUERY.retrieve_list);
  508. List<Map> data2 = (List<Map>) ddrNew2.getData();
  509. for (Map map : data2) {
  510. Map formData = (Map) map.get("formData");
  511. int dqNumber = (int) formData.get("numberField_m1fvucmc");//数据源序号
  512. String factoryName = getString(formData.get("textField_m1fvucmd"));//工厂名称
  513. factory.put(dqNumber,factoryName);
  514. }
  515. List<Map> errorList = new ArrayList<>();
  516. //同步当月内的数据 upsert
  517. DateTime dateTime = DateUtil.offsetDay(new Date(), -1);
  518. String yesterday = dateTime.toString("yyyy-MM-dd");
  519. DateTime beginOfMonth = DateUtil.beginOfMonth(DateUtil.lastMonth());
  520. String beginOfMonthString = beginOfMonth.toString("yyyy-MM-dd");
  521. /*String beginOfMonthString = "2025-06-25";
  522. String yesterday = "2025-06-25";*/
  523. for (Integer dsSequence : factory.keySet()) {
  524. /*if (dsSequence != 8){
  525. continue;
  526. }*/
  527. List<String> errorCodes = new ArrayList<>();
  528. //存放存货名称、编码
  529. Map<String,String> inventory = new HashMap<>();
  530. Map<String,Object> param = new HashMap<>();
  531. param.put("from_account",fromAccount);
  532. param.put("to_account",toAccount);
  533. param.put("app_key", u8AppKey);
  534. param.put("token", getU8Token());
  535. param.put("page_index", 1);
  536. param.put("rows_per_page", 50);
  537. param.put("ds_sequence", dsSequence);
  538. param.put("date_begin", beginOfMonthString);
  539. param.put("date_end", yesterday);
  540. Map<String, Object> map = get("https://api.yonyouup.com/api/saleoutlist/batch_get", param, null);
  541. if (!getString(map.get("errcode")).equals("0")){
  542. log.error("获取销售出库单列表失败:{}",map.get("errmsg"));
  543. continue;
  544. }
  545. if (!map.get("page_count").equals("1")){
  546. Integer rowCount = Integer.valueOf(map.get("row_count").toString());
  547. param.put("rows_per_page",rowCount);
  548. map = get("https://api.yonyouup.com/api/saleoutlist/batch_get", param, null);
  549. }
  550. List<Map> saleoutList = (List<Map>) map.get("saleoutlist");
  551. for (Map saleout : saleoutList) {
  552. //查询单个出库单详情
  553. String id = getString(saleout.get("code"));
  554. /*if (!id.equals("0000009439")){
  555. continue;
  556. }*/
  557. Map<String, Object> param2 = new HashMap<>();
  558. param2.put("from_account", fromAccount);
  559. param2.put("to_account", fromAccount);
  560. param2.put("app_key", u8AppKey);
  561. param2.put("token", getU8Token());
  562. param2.put("id", id);
  563. param2.put("ds_sequence", dsSequence);
  564. Map<String, Object> map2 = new HashMap<>();
  565. int i1 =1 ;
  566. boolean flag1 = false;
  567. while (i1<=5 && !flag1) {
  568. try {
  569. map2 = get("https://api.yonyouup.com/api/saleout/get", param2, null);
  570. flag1 = true;
  571. } catch (Exception e) {
  572. log.error("获取出库单详情失败:{}, 重试次数:{}",e.getMessage(),i1);
  573. try {
  574. Thread.sleep(3000);
  575. } catch (InterruptedException ex) {
  576. throw new RuntimeException(ex);
  577. }
  578. i1++;
  579. }
  580. }
  581. if (i1 > 5){
  582. log.error("获取出库单详情失败");
  583. errorCodes.add(id);
  584. continue;
  585. }
  586. Map saleout2 = (Map) map2.get("saleout");
  587. Map formData = new HashMap();
  588. //若为内部交易客户,则不同步
  589. String cusCode = getString(saleout2.get("customercode"));
  590. if (cusCodes.contains(cusCode)){
  591. continue;
  592. }
  593. if (!getString(saleout2.get("warehousename")).contains("成品") || getString(saleout2.get("warehousename")).contains("外购")){
  594. continue;
  595. }
  596. formData.put("textField_m18nvp87",getString(saleout2.get("code")));//出库单号
  597. formData.put("textField_m18qfuj0",getString(saleout2.get("saletypename")));//销售类型
  598. formData.put("textField_m18nvp8c",getString(saleout2.get("businesscode")));//业务单号
  599. formData.put("textField_m5nnwiv1", getString(saleout2.get("warehousename")));//仓库名称
  600. formData.put("dateField_m18nvp7x",DateUtil.parseDate(getString(saleout2.get("date"))).getTime());//单据日期
  601. formData.put("textField_mbu5nao3",getWeekRange(getString(saleout2.get("date"))));//发货周
  602. formData.put("textField_mbu5nao5",saleout2.get("date").toString().substring(0,4));//年份
  603. formData.put("dateField_m5nnwiuw",Objects.nonNull(saleout2.get("auditdate")) ? DateUtil.parseDate(getString(saleout2.get("auditdate"))).getTime() : null);//审核日期
  604. formData.put("textField_m18nvp7y",getString(saleout2.get("customername")));//客户名称
  605. formData.put("textField_m18nvp7z",getString(saleout2.get("departmentname")));//部门
  606. formData.put("textField_m1er3scl",factory.get(dsSequence));//工厂名称
  607. formData.put("textField_m18nvp81",getString(saleout2.get("maker")));//制单人
  608. formData.put("textField_m18nvp80",getString(saleout2.get("handler")));//审核人
  609. formData.put("textareaField_m5nnwiur",getString(saleout2.get("memory")));//备注
  610. formData.put("numberField_m18wkih7",dsSequence);//数据源序号
  611. formData.put("selectField_m7b8j9uj","实发");//类型
  612. AtomicReference<Double> totalQuantity = new AtomicReference<>(0d);
  613. AtomicReference<Double> totalCost = new AtomicReference<>(0d);
  614. List<Map> entry = (List<Map>) saleout2.get("entry");
  615. //collect拆分成五个list 每个list长度为500
  616. List<List<Map>> collectList = new ArrayList<>();
  617. for (int i = 0; i < entry.size(); i += 500) {
  618. collectList.add(entry.subList(i, Math.min(i + 500, entry.size())));
  619. }
  620. if (collectList.size() > 5){
  621. log.error("出库单:{} 出库明细超过2500个, 请检查",id);
  622. errorCodes.add(id + "出库明细超过2500");
  623. }
  624. //是否退线
  625. boolean isReject = false;
  626. Map<String,String> inventoryPrice = new HashMap<>();
  627. //出库明细
  628. List<Map> list1 = new ArrayList();
  629. for (Map item : collectList.get(0)) {
  630. if (Objects.isNull(formData.get("textField_m219zpzf"))){
  631. formData.put("textField_m219zpzf",getString(item.get("free1")));//客户码 出库主表没有客户码,取明细的客户码
  632. }
  633. if (Objects.isNull(formData.get("textField_m5nnwiv7"))){
  634. formData.put("textField_m5nnwiv7",getString(item.get("ordercode")));//销售订单号
  635. }
  636. Map detail = new HashMap();
  637. detail.put("textField_m22mkwzk", getString(item.get("define29")));//客户存货码
  638. detail.put("textField_mbu5naoj", getString(item.get("inventorycode")));//存货编码
  639. detail.put("textField_mc1emzfr",getInventoryName(getString(item.get("inventorycode")),dsSequence,inventory));//存货名称
  640. detail.put("textField_m21b1bhg", getString(item.get("free2")));//产品颜色
  641. detail.put("textField_mbu5naoa", getString(item.get("define28")));//条码
  642. detail.put("textField_m18nvp8f", getString(item.get("cmassunitname")));//单位
  643. if (Objects.nonNull(item.get("quantity")) && isNumber(getString(item.get("quantity")))){
  644. if (getString((item.get("quantity"))).contains("-")){
  645. isReject = true;
  646. break;
  647. }else {
  648. detail.put("numberField_m18nvp8h", getString(item.get("quantity")));//发货数量
  649. }
  650. }else {
  651. continue;
  652. }
  653. totalQuantity.updateAndGet(v -> new Double((double) (v + Double.parseDouble(getString(item.get("quantity"))))));
  654. String price = getString(item.get("price"));
  655. String cost = getString(item.get("cost"));
  656. try {
  657. double numericValue = Double.parseDouble(price);
  658. //单价为0时查询存货价目表
  659. if (numericValue == 0d){
  660. String inventorycode = getString(item.get("inventorycode"));
  661. if (inventoryPrice.containsKey(inventorycode)){
  662. price = inventoryPrice.get(inventorycode);
  663. }else {
  664. price = getInventoryPrice(factory.get(dsSequence), getString(item.get("free1")), getString(saleout2.get("date")), getString(item.get("inventorycode")));
  665. inventoryPrice.put(getString(item.get("inventorycode")),price);
  666. }
  667. if (!"0".equals(price)){
  668. cost = Double.parseDouble(price) * Double.parseDouble(getString(item.get("quantity"))) + "";
  669. detail.put("numberField_m18nvp8k", price);//单价
  670. detail.put("numberField_m18nvp8m", cost);//金额
  671. }
  672. }else {
  673. detail.put("numberField_m18nvp8k", price);//单价
  674. detail.put("numberField_m18nvp8m", cost);//金额
  675. }
  676. String finalCost = cost;
  677. totalCost.updateAndGet(v -> new Double((double) (v + Double.parseDouble(finalCost))));
  678. } catch (NumberFormatException e) {
  679. System.out.println("字符串不是有效的数值: " + price);
  680. }
  681. /* if (Objects.nonNull(item.get("price")) && isNumber(getString(item.get("price")))){
  682. detail.put("numberField_m18nvp8k", getString(item.get("price")));//单价
  683. }
  684. if (Objects.nonNull(item.get("cost")) && isNumber(getString(item.get("cost")))){
  685. detail.put("numberField_m18nvp8m", getString(item.get("cost")));//金额
  686. totalCost.updateAndGet(v -> new Double((double) (v + Double.parseDouble(getString(item.get("cost"))))));
  687. }*/
  688. list1.add(detail);
  689. }
  690. List<Map> list2 = new ArrayList<>();
  691. if (collectList.size() > 1){
  692. for (Map item : collectList.get(1)) {
  693. Map detail = new HashMap();
  694. detail.put("textField_m2j0wj8o", getString(item.get("define29")));//客户存货码
  695. detail.put("textField_mbu5naol", getString(item.get("inventorycode")));//存货编码
  696. detail.put("textField_mc1emzft",getInventoryName(getString(item.get("inventorycode")),dsSequence,inventory));//存货名称
  697. detail.put("textField_m2j0wj8q", getString(item.get("free2")));//产品颜色
  698. detail.put("textField_mbu5naoc", getString(item.get("define28")));//条码
  699. detail.put("textField_m2j0wj8r", getString(item.get("cinvm_unit")));//单位
  700. if (Objects.nonNull(item.get("quantity")) && isNumber(getString(item.get("quantity")))){
  701. if (getString((item.get("quantity"))).contains("-")){
  702. isReject = true;
  703. break;
  704. }else {
  705. detail.put("numberField_m2j0wj8s", getString(item.get("quantity")));//发货数量
  706. }
  707. }else {
  708. continue;
  709. }
  710. totalQuantity.updateAndGet(v -> new Double((double) (v + Double.parseDouble(getString(item.get("quantity"))))));
  711. String price = getString(item.get("price"));
  712. String cost = getString(item.get("cost"));
  713. try {
  714. double numericValue = Double.parseDouble(price);
  715. //单价为0时查询存货价目表
  716. if (numericValue == 0d){
  717. String inventorycode = getString(item.get("inventorycode"));
  718. if (inventoryPrice.containsKey(inventorycode)){
  719. price = inventoryPrice.get(inventorycode);
  720. }else {
  721. price = getInventoryPrice(factory.get(dsSequence), getString(item.get("free1")), getString(saleout2.get("date")), getString(item.get("inventorycode")));
  722. inventoryPrice.put(getString(item.get("inventorycode")),price);
  723. }
  724. if (!"0".equals(price)){
  725. cost = Double.parseDouble(price) * Double.parseDouble(getString(item.get("quantity"))) + "";
  726. detail.put("numberField_m2j0wj8v", price);//单价
  727. detail.put("numberField_m2j0wj8w", cost);//金额
  728. }
  729. }else {
  730. detail.put("numberField_m2j0wj8v", price);//单价
  731. detail.put("numberField_m2j0wj8w", cost);//金额
  732. }
  733. String finalCost = cost;
  734. totalCost.updateAndGet(v -> new Double((double) (v + Double.parseDouble(finalCost))));
  735. } catch (NumberFormatException e) {
  736. System.out.println("字符串不是有效的数值: " + price);
  737. }
  738. /*if (Objects.nonNull(item.get("price")) && isNumber(getString(item.get("price")))){
  739. detail.put("numberField_m2j0wj8v", getString(item.get("price")));//单价
  740. }
  741. if (Objects.nonNull(item.get("cost")) && isNumber(getString(item.get("cost")))){
  742. detail.put("numberField_m2j0wj8w", getString(item.get("cost")));//金额
  743. totalCost.updateAndGet(v -> new Double((double) (v + Double.parseDouble(getString(item.get("cost"))))));
  744. }*/
  745. list2.add(detail);
  746. }
  747. }
  748. List<Map> list3 = new ArrayList<>();
  749. if (collectList.size() > 2){
  750. for (Map item : collectList.get(2)) {
  751. Map detail = new HashMap();
  752. detail.put("textField_m2j0wj93", getString(item.get("define29")));//客户存货码
  753. detail.put("textField_mbu5naon", getString(item.get("inventorycode")));//存货编码
  754. detail.put("textField_mc1emzfv",getInventoryName(getString(item.get("inventorycode")),dsSequence,inventory));//存货名称
  755. detail.put("textField_m2j0wj95", getString(item.get("free2")));//产品颜色
  756. detail.put("textField_mbu5naoe", getString(item.get("define28")));//条码
  757. detail.put("textField_m2j0wj96", getString(item.get("cinvm_unit")));//单位
  758. if (Objects.nonNull(item.get("quantity")) && isNumber(getString(item.get("quantity")))){
  759. if (getString((item.get("quantity"))).contains("-")){
  760. isReject = true;
  761. break;
  762. }else {
  763. detail.put("numberField_m2j0wj97", getString(item.get("quantity")));//发货数量
  764. }
  765. }else {
  766. continue;
  767. }
  768. totalQuantity.updateAndGet(v -> new Double((double) (v + Double.parseDouble(getString(item.get("quantity"))))));
  769. String price = getString(item.get("price"));
  770. String cost = getString(item.get("cost"));
  771. try {
  772. double numericValue = Double.parseDouble(price);
  773. //单价为0时查询存货价目表
  774. if (numericValue == 0d){
  775. String inventorycode = getString(item.get("inventorycode"));
  776. if (inventoryPrice.containsKey(inventorycode)){
  777. price = inventoryPrice.get(inventorycode);
  778. }else {
  779. price = getInventoryPrice(factory.get(dsSequence), getString(item.get("free1")), getString(saleout2.get("date")), getString(item.get("inventorycode")));
  780. inventoryPrice.put(getString(item.get("inventorycode")),price);
  781. }
  782. if (!"0".equals(price)){
  783. cost = Double.parseDouble(price) * Double.parseDouble(getString(item.get("quantity"))) + "";
  784. detail.put("numberField_m2j0wj9a", price);//单价
  785. detail.put("numberField_m2j0wj9b", cost);//金额
  786. }
  787. }else {
  788. detail.put("numberField_m2j0wj9a", price);//单价
  789. detail.put("numberField_m2j0wj9b", cost);//金额
  790. }
  791. String finalCost = cost;
  792. totalCost.updateAndGet(v -> new Double((double) (v + Double.parseDouble(finalCost))));
  793. } catch (NumberFormatException e) {
  794. System.out.println("字符串不是有效的数值: " + price);
  795. }
  796. /*if (Objects.nonNull(item.get("price")) && isNumber(getString(item.get("price")))){
  797. detail.put("numberField_m2j0wj9a", getString(item.get("price")));//单价
  798. }
  799. if (Objects.nonNull(item.get("cost")) && isNumber(getString(item.get("cost")))){
  800. detail.put("numberField_m2j0wj9b", getString(item.get("cost")));//金额
  801. totalCost.updateAndGet(v -> new Double((double) (v + Double.parseDouble(getString(item.get("cost"))))));
  802. }*/
  803. list3.add(detail);
  804. }
  805. }
  806. List<Map> list4 = new ArrayList<>();
  807. if (collectList.size() > 3){
  808. for (Map item : collectList.get(3)) {
  809. Map detail = new HashMap();
  810. detail.put("textField_m4cfhc70", getString(item.get("define29")));//客户存货码
  811. detail.put("textField_mbu5naop", getString(item.get("inventorycode")));//存货编码
  812. detail.put("textField_mc1emzfx",getInventoryName(getString(item.get("inventorycode")),dsSequence,inventory));//存货名称
  813. detail.put("textField_m4cfhc72", getString(item.get("free2")));//产品颜色
  814. detail.put("textField_mbu5naog", getString(item.get("define28")));//条码
  815. detail.put("textField_m4cfhc73", getString(item.get("cinvm_unit")));//单位
  816. if (Objects.nonNull(item.get("quantity")) && isNumber(getString(item.get("quantity")))){
  817. if (getString((item.get("quantity"))).contains("-")){
  818. isReject = true;
  819. break;
  820. }else {
  821. detail.put("numberField_m4cfhc74", getString(item.get("quantity")));//发货数量
  822. }
  823. }else {
  824. continue;
  825. }
  826. totalQuantity.updateAndGet(v -> new Double((double) (v + Double.parseDouble(getString(item.get("quantity"))))));
  827. String price = getString(item.get("price"));
  828. String cost = getString(item.get("cost"));
  829. try {
  830. double numericValue = Double.parseDouble(price);
  831. //单价为0时查询存货价目表
  832. if (numericValue == 0d){
  833. String inventorycode = getString(item.get("inventorycode"));
  834. if (inventoryPrice.containsKey(inventorycode)){
  835. price = inventoryPrice.get(inventorycode);
  836. }else {
  837. price = getInventoryPrice(factory.get(dsSequence), getString(item.get("free1")), getString(saleout2.get("date")), getString(item.get("inventorycode")));
  838. inventoryPrice.put(getString(item.get("inventorycode")),price);
  839. }
  840. if (!"0".equals(price)){
  841. cost = Double.parseDouble(price) * Double.parseDouble(getString(item.get("quantity"))) + "";
  842. detail.put("numberField_m4cfhc77", price);//单价
  843. detail.put("numberField_m4cfhc78", cost);//金额
  844. }
  845. }else {
  846. detail.put("numberField_m4cfhc77", price);//单价
  847. detail.put("numberField_m4cfhc78", cost);//金额
  848. }
  849. String finalCost = cost;
  850. totalCost.updateAndGet(v -> new Double((double) (v + Double.parseDouble(finalCost))));
  851. } catch (NumberFormatException e) {
  852. System.out.println("字符串不是有效的数值: " + price);
  853. }
  854. /*if (Objects.nonNull(item.get("price")) && isNumber(getString(item.get("price")))){
  855. detail.put("numberField_m4cfhc77", getString(item.get("price")));//单价
  856. }
  857. if (Objects.nonNull(item.get("cost")) && isNumber(getString(item.get("cost")))){
  858. detail.put("numberField_m4cfhc78", getString(item.get("cost")));//金额
  859. totalCost.updateAndGet(v -> new Double((double) (v + Double.parseDouble(getString(item.get("cost"))))));
  860. }*/
  861. list4.add(detail);
  862. }
  863. }
  864. List<Map> list5 = new ArrayList<>();
  865. if (collectList.size() > 4){
  866. for (Map item : collectList.get(4)) {
  867. Map detail = new HashMap();
  868. detail.put("textField_m4cfhc7f", getString(item.get("define29")));//客户存货码
  869. detail.put("textField_mbu5naor", getString(item.get("inventorycode")));//存货编码
  870. detail.put("textField_mc1emzfz",getInventoryName(getString(item.get("inventorycode")),dsSequence,inventory));//存货名称
  871. detail.put("textField_m4cfhc7h", getString(item.get("free2")));//产品颜色
  872. detail.put("textField_mbu5naoi", getString(item.get("define28")));//条码
  873. detail.put("textField_m4cfhc7i", getString(item.get("cinvm_unit")));//单位
  874. if (Objects.nonNull(item.get("quantity")) && isNumber(getString(item.get("quantity")))){
  875. if (getString((item.get("quantity"))).contains("-")){
  876. isReject = true;
  877. break;
  878. }else {
  879. detail.put("numberField_m4cfhc7j", getString(item.get("quantity")));//发货数量
  880. }
  881. }else {
  882. continue;
  883. }
  884. totalQuantity.updateAndGet(v -> new Double((double) (v + Double.parseDouble(getString(item.get("quantity"))))));
  885. String price = getString(item.get("price"));
  886. String cost = getString(item.get("cost"));
  887. try {
  888. double numericValue = Double.parseDouble(price);
  889. //单价为0时查询存货价目表
  890. if (numericValue == 0d){
  891. String inventorycode = getString(item.get("inventorycode"));
  892. if (inventoryPrice.containsKey(inventorycode)){
  893. price = inventoryPrice.get(inventorycode);
  894. }else {
  895. price = getInventoryPrice(factory.get(dsSequence), getString(item.get("free1")), getString(saleout2.get("date")), getString(item.get("inventorycode")));
  896. inventoryPrice.put(getString(item.get("inventorycode")),price);
  897. }
  898. if (!"0".equals(price)){
  899. cost = Double.parseDouble(price) * Double.parseDouble(getString(item.get("quantity"))) + "";
  900. detail.put("numberField_m4cfhc7m", price);//单价
  901. detail.put("numberField_m4cfhc7n", cost);//金额
  902. }
  903. }else {
  904. detail.put("numberField_m4cfhc7m", price);//单价
  905. detail.put("numberField_m4cfhc7n", cost);//金额
  906. }
  907. String finalCost = cost;
  908. totalCost.updateAndGet(v -> new Double((double) (v + Double.parseDouble(finalCost))));
  909. } catch (NumberFormatException e) {
  910. System.out.println("字符串不是有效的数值: " + price);
  911. }
  912. /*if (Objects.nonNull(item.get("price")) && isNumber(getString(item.get("price")))){
  913. detail.put("numberField_m4cfhc7m", getString(item.get("price")));//单价
  914. }
  915. if (Objects.nonNull(item.get("cost")) && isNumber(getString(item.get("cost")))){
  916. detail.put("numberField_m4cfhc7n", getString(item.get("cost")));//金额
  917. totalCost.updateAndGet(v -> new Double((double) (v + Double.parseDouble(getString(item.get("cost"))))));
  918. }*/
  919. list5.add(detail);
  920. }
  921. }
  922. if (isReject){
  923. continue;
  924. }
  925. formData.put("tableField_m18nvp82",list1);
  926. formData.put("tableField_m2j0wj90",list2);
  927. formData.put("tableField_m2j0wj9f",list3);
  928. formData.put("tableField_m4cfhc7c",list4);
  929. formData.put("tableField_m4cfhc7r",list5);
  930. formData.put("numberField_mbu92ncy",totalQuantity.get());//发货数量合计
  931. formData.put("numberField_mbu92nd0",totalCost.get());//发货金额合计
  932. //精准匹配
  933. List<Map> jsonString = new ArrayList<>();
  934. jsonString.add(UtilMap.map("key, value, type, operator, componentName", "textField_m18nvp87",getString(saleout2.get("code")),"TEXT","eq","TextField"));
  935. jsonString.add(UtilMap.map("key, value, type, operator, componentName", "numberField_m18wkih7",new int[]{dsSequence,dsSequence},"DOUBLE","between","NumberField"));
  936. String searchCondition = JSONObject.toJSONString(jsonString);
  937. int i=1;
  938. boolean flag = false;
  939. while (i<=5 && !flag){
  940. try{
  941. ydClient.operateData(YDParam.builder()
  942. .formUuid(PRODUCT_REAL)
  943. // .searchCondition(JSON.toJSONString(UtilMap.map("textField_m18nvp87, numberField_m18wkih7",getString(consignment2.get("code")),dsSequence)))//模糊查询
  944. .searchCondition(searchCondition)//精准查询
  945. .formDataJson(JSON.toJSONString(formData))
  946. .build(), YDConf.FORM_OPERATION.upsert);
  947. flag = true;
  948. }catch (McException e){
  949. if (e.getMessage().contains("The request has failed due to a temporary failure of the server.")){
  950. log.error("upsert失败,尝试次数:{}",i);
  951. i++;
  952. try {
  953. Thread.sleep(3000);
  954. } catch (InterruptedException ex) {
  955. throw new RuntimeException(ex);
  956. }
  957. }else {
  958. log.error("upsert,失败原因:{}" , e.getMessage());
  959. errorCodes.add(id);
  960. flag = true;
  961. }
  962. }catch (Exception e){
  963. log.error("出库单:{} 同步失败 失败原因:{}",getString(saleout2.get("code")) , e.getMessage());
  964. errorCodes.add(id);
  965. flag = true;
  966. }
  967. }
  968. if (i>5){
  969. errorCodes.add(id);
  970. log.error("出库单:{} 同步失败 失败原因:{}",getString(saleout2.get("code")) , "重试次数过多");
  971. }
  972. }
  973. Map error = new HashMap();
  974. error.put("ds_sequence",dsSequence);
  975. error.put("error_count",errorCodes.size());
  976. //errorCodes逗号分隔
  977. error.put("errcodes",errorCodes.stream().collect(Collectors.joining(",")));
  978. errorList.add(error);
  979. }
  980. long endTime = System.currentTimeMillis();
  981. double time = (endTime - beginTime) / 1000.0;
  982. log.info("同步完成,耗时:{}秒", time);
  983. log.info("同步失败列表: {}", errorList);
  984. //记录失败日志
  985. Map<String,Object> formData = new HashMap<>();
  986. formData.put("dateField_m21oifwi",beginTime);
  987. formData.put("dateField_m21oifwp",endTime);
  988. formData.put("numberField_m21oifwo",time);
  989. //换行分隔errorList
  990. String errorStr = errorList.stream().map(item -> {
  991. String s = "数据源序号:" + item.get("ds_sequence") + ",错误数量:" + item.get("error_count") + ",发货单codes:" + item.get("errcodes");
  992. return s;
  993. }).collect(Collectors.joining("\n"));
  994. formData.put("textareaField_m21oifwj",errorStr);
  995. ydClient.operateData(YDParam.builder()
  996. .formUuid("FORM-F297D439FFF747ACB26DEA940850CD9B13LM")
  997. .formDataJson(JSON.toJSONString(formData))
  998. .build(), YDConf.FORM_OPERATION.create);
  999. return McR.success();
  1000. }
  1001. public String getInventoryPrice(String factory,String customerCode,String dateStr,String inventoryCode){
  1002. String price = "0";
  1003. List<Map> searchCondition = new ArrayList<>();
  1004. searchCondition.add(UtilMap.map("key, value, type, operator, componentName","selectField_mc36onxf",factory,"TEXT","eq","TextField"));//工厂
  1005. searchCondition.add(UtilMap.map("key, value, type, operator, componentName","selectField_mc36onxg",customerCode,"TEXT","eq","TextField"));//客户码
  1006. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
  1007. // 解析日期字符串为 LocalDate
  1008. LocalDate date = LocalDate.parse(dateStr, formatter);
  1009. // 获取当天的起始时间(00:00:00)
  1010. LocalDateTime startOfDay = date.atStartOfDay();
  1011. // 获取当天的结束时间(23:59:59)
  1012. LocalDateTime endOfDay = date.atTime(23, 59, 59);
  1013. // 转换为时间戳(假设使用系统默认时区)
  1014. ZoneId zoneId = ZoneId.systemDefault();
  1015. ZonedDateTime startZonedDateTime = startOfDay.atZone(zoneId);
  1016. ZonedDateTime endZonedDateTime = endOfDay.atZone(zoneId);
  1017. long startTimestamp = startZonedDateTime.toInstant().toEpochMilli();
  1018. long endTimestamp = endZonedDateTime.toInstant().toEpochMilli();
  1019. searchCondition.add(UtilMap.map("key, value, type, operator, componentName","dateField_mc36onxh",Arrays.asList(startTimestamp,endTimestamp),"DOUBLE","between","DateField"));//出库时间
  1020. searchCondition.add(UtilMap.map("key, value, type, operator, componentName","textField_mc36onxm",inventoryCode,"TEXT","eq","TextField"));//存货编码
  1021. List<Map> priceData = (List<Map>) ydClient.queryData(YDParam.builder()
  1022. .formUuid("FORM-934F1DF0B6C34535B81102F0CEFB6C1FR55N")
  1023. .searchCondition(JSONObject.toJSONString(searchCondition))
  1024. .pageSize(1)
  1025. .build(), YDConf.FORM_QUERY.retrieve_list).getData();
  1026. if (priceData.size() == 1){
  1027. price = getString(((Map)priceData.get(0).get("formData")).get("numberField_mc36onxj"));
  1028. }
  1029. return price;
  1030. }
  1031. public String getInventoryName(String inventoryCode,int dsSequence,Map<String,String> inventory){
  1032. if (inventory.containsKey(inventoryCode)){
  1033. return inventory.get(inventoryCode);
  1034. }
  1035. Map<String, Object> param3 = new HashMap<>();
  1036. param3.put("from_account", fromAccount);
  1037. param3.put("to_account", fromAccount);
  1038. param3.put("app_key", u8AppKey);
  1039. param3.put("token", getU8Token());
  1040. param3.put("id", inventoryCode);
  1041. param3.put("ds_sequence", dsSequence);
  1042. Map<String,Object> map3 = get("https://api.yonyouup.com/api/inventory/get", param3, null);
  1043. Map inventoryInfo = (Map) map3.get("inventory");
  1044. String inventoryName = getString(inventoryInfo.get("name"));
  1045. inventory.put(inventoryCode,inventoryName);
  1046. return inventoryName;
  1047. }
  1048. @Override
  1049. public McR testInnerTable() {
  1050. MDC.put("MDC_KEY_PID","1019");
  1051. Map updateFormData = new HashMap();
  1052. List<Map> details = new ArrayList<>();
  1053. for (int i = 0; i < 1000; i++) {
  1054. Map detail = new HashMap();
  1055. detail.put("textField_m2b95sh3", i+"");
  1056. details.add(detail);
  1057. }
  1058. updateFormData.put("tableField_m2b95sh2",details);
  1059. updateFormData.put("textField_m2b95sh5","4");
  1060. List<Map> jsonString = new ArrayList<>();
  1061. jsonString.add(UtilMap.map("key, value, type, operator, componentName", "textField_m2b95sh5","1","TEXT","eq","TextField"));
  1062. String searchCondition = JSONObject.toJSONString(jsonString);
  1063. ydClient.operateData(YDParam.builder()
  1064. .searchCondition(searchCondition)
  1065. .formUuid("FORM-05AFA58A7DC4495C82AD23717C90A608JQ1F")
  1066. .formDataJson(JSON.toJSONString(updateFormData))
  1067. // .updateFormDataJson(JSON.toJSONString(updateFormData))
  1068. .build(), YDConf.FORM_OPERATION.upsert);
  1069. return null;
  1070. }
  1071. @Override
  1072. public void addVoucher(Map map) {
  1073. MDC.put("MDC_KEY_PID","1002");
  1074. if (Objects.isNull(map.get("formInstId"))){
  1075. log.info("formInstId不能为空!");
  1076. return;
  1077. }
  1078. String formInstId = map.get("formInstId").toString();
  1079. DDR_New ddrNew = ydClient.queryData(YDParam.builder()
  1080. .formInstId(formInstId)
  1081. .build(), YDConf.FORM_QUERY.retrieve_id);
  1082. Map formData = ddrNew.getFormData();
  1083. String type = formData.get("selectField_m2sdpe2p").toString();
  1084. int dsSequence = (int) formData.get("numberField_m2o5b8sh");
  1085. String createUser = ((Map)ddrNew.getOriginator().get("name")).get("nameInChinese").toString();
  1086. Map data = new HashMap();
  1087. switch (type){
  1088. case "资金审批流程":data = process131(formData,dsSequence,createUser);break;
  1089. case "采购部专用资金审批":data = process136(formData,dsSequence,createUser);break;
  1090. // case "信息化建设专用资金审批":data = process138(formData,dsSequence,createUser);break;//20241112 暂时不推送13.8
  1091. default:break;
  1092. }
  1093. //获取交易号
  1094. Map tradeParam = new HashMap();
  1095. tradeParam.put("from_account",fromAccount);
  1096. tradeParam.put("app_key", u8AppKey);
  1097. tradeParam.put("token", getU8Token());
  1098. Map<String, Object> tradeMap = get("https://api.yonyouup.com/system/tradeid", tradeParam, null);
  1099. Map trade = (Map) tradeMap.get("trade");
  1100. String tradeId = getString(trade.get("id"));
  1101. //推送凭证
  1102. Map<String, Object> pushParam = new HashMap<>();
  1103. pushParam.put("from_account", fromAccount);
  1104. pushParam.put("to_account", toAccount);
  1105. pushParam.put("app_key", u8AppKey);
  1106. pushParam.put("token", getU8Token());
  1107. pushParam.put("tradeid", tradeId);
  1108. pushParam.put("sync", 1);
  1109. pushParam.put("ds_sequence",dsSequence);
  1110. Map result = post("https://api.yonyouup.com/api/voucher/add", pushParam, null, data);
  1111. if (!"0".equals(result.get("errcode").toString())){
  1112. log.info("推送凭证失败:{}",result.get("errmsg").toString());
  1113. throw new RuntimeException("推送凭证失败:"+result.get("errmsg").toString());
  1114. }
  1115. }
  1116. private Map process138(Map formData, int dsSequence, String createUser) {
  1117. String schPayAccount = getString(formData.get("selectField_lxydz0ub"));//付款方账号
  1118. String revName = getString(formData.get("textField_lxwwvggc"));//收款人名称
  1119. String company = getString(formData.get("selectField_lxwwvggb"));//公司抬头
  1120. String purpose = getString(formData.get("textField_lxwwvggy"));//付款理由
  1121. String summary = revName + "/" + purpose;//摘要
  1122. String deptName = getString(formData.get("textField_m2sekyf7"));//部门
  1123. String currency = getString(formData.get("textField_m2sekyfi"));//币种
  1124. List<String> sepVoucherCompany = Arrays.asList("宁波卡倍亿电气技术股份有限公司", "宁波卡倍亿新材料科技有限公司", "宁波卡倍亿铜线有限公司", "湖北卡倍亿电气技术有限公司");
  1125. String voucherType =sepVoucherCompany.contains(company) ? "付" : "记";//凭证类型
  1126. String applyAmount = getString(formData.get("numberField_lxwwvggi"));//本次支付金额(元)
  1127. String producer = createUser;//制单人
  1128. //获取供应商信息
  1129. Map<String,Object> supplierParam = new HashMap<>();
  1130. supplierParam.put("from_account",fromAccount);
  1131. supplierParam.put("to_account",toAccount);
  1132. supplierParam.put("app_key", u8AppKey);
  1133. supplierParam.put("token", getU8Token());
  1134. supplierParam.put("page_index", 1);
  1135. supplierParam.put("rows_per_page", 50);
  1136. supplierParam.put("ds_sequence", dsSequence);
  1137. supplierParam.put("name", revName);
  1138. Map<String, Object> supplierMap = get("https://api.yonyouup.com/api/vendor/batch_get", supplierParam, null);
  1139. if (!"0".equals(supplierMap.get("errcode").toString())){
  1140. log.info("获取供应商信息失败:{},{}",supplierMap.get("errmsg").toString(),revName);
  1141. throw new RuntimeException("获取供应商信息失败:"+supplierMap.get("errmsg").toString()+","+revName);
  1142. }
  1143. List<Map> vendorList = (List<Map>) supplierMap.get("vendor");
  1144. String supplierCode = getString(vendorList.get(0).get("code"));
  1145. //获取部门信息
  1146. Map<String,Object> deptParam = new HashMap<>();
  1147. deptParam.put("from_account",fromAccount);
  1148. deptParam.put("to_account",toAccount);
  1149. deptParam.put("app_key", u8AppKey);
  1150. deptParam.put("token", getU8Token());
  1151. deptParam.put("page_index", 1);
  1152. deptParam.put("rows_per_page", 50);
  1153. deptParam.put("ds_sequence", dsSequence);
  1154. deptParam.put("name", deptName);
  1155. Map<String, Object> deptMap = get("https://api.yonyouup.com/api/department/batch_get", deptParam, null);
  1156. if (!"0".equals(deptMap.get("errcode").toString())){
  1157. log.info("获取部门信息失败:{},{}",deptMap.get("errmsg").toString(),deptName);
  1158. throw new RuntimeException("获取部门信息失败:"+deptMap.get("errmsg").toString()+","+deptName);
  1159. }
  1160. List<Map> deptList = (List<Map>) deptMap.get("department");
  1161. String deptCode = getString(deptList.get(0).get("code"));
  1162. Map resultMap = new HashMap();
  1163. Map topInfoMap = new HashMap();
  1164. //记账类型
  1165. topInfoMap.put("voucher_type",voucherType);
  1166. topInfoMap.put("enter",producer); //制单人
  1167. //credit entry信息 贷方
  1168. Map infoMap = new HashMap();
  1169. Map<String,Object> subjectParam = new HashMap<>();
  1170. subjectParam.put("from_account",fromAccount);
  1171. subjectParam.put("to_account",toAccount);
  1172. subjectParam.put("app_key", u8AppKey);
  1173. subjectParam.put("token", getU8Token());
  1174. subjectParam.put("page_index", 1);
  1175. subjectParam.put("rows_per_page", 50);
  1176. subjectParam.put("ds_sequence", dsSequence);
  1177. subjectParam.put("name", schPayAccount);
  1178. Map<String, Object> subjectMap = get("https://api.yonyouup.com/api/code/batch_get", subjectParam, null);
  1179. if (!"0".equals(subjectMap.get("errcode").toString())){
  1180. log.info("获取科目信息失败:{},{}",supplierMap.get("errmsg").toString(),schPayAccount);
  1181. throw new RuntimeException("获取科目信息失败:"+supplierMap.get("errmsg").toString()+","+schPayAccount);
  1182. }
  1183. List<Map> subjectList = (List<Map>) subjectMap.get("code");
  1184. String subjectCode = getString(subjectList.get(0).get("code"));
  1185. //贷方科目编码
  1186. infoMap.put("account_code", subjectCode);
  1187. //摘要
  1188. infoMap.put("abstract", summary);
  1189. //币种
  1190. infoMap.put("currency", currency);
  1191. //本币借方发生额*与本币贷方发生额不能同时为空
  1192. infoMap.put("natural_credit_currency", applyAmount);
  1193. List<Map> creditCashFlowList = new ArrayList<>();
  1194. Map creditCashFlow = new HashMap();
  1195. //币种
  1196. creditCashFlow.put("cexch_name", currency);
  1197. //本币借方发生额*与本币贷方发生额不能同时为空
  1198. creditCashFlow.put("natural_credit_currency", applyAmount);
  1199. //凭证类别字
  1200. creditCashFlow.put("csign", voucherType);
  1201. //科目编码 - 根据CBS 方,实际打款账户和公司来确定
  1202. creditCashFlow.put("ccode", subjectCode);
  1203. //贷方金额
  1204. creditCashFlow.put("mc", applyAmount);
  1205. /* //现金项目
  1206. creditCashFlow.put("cCashItem", cashItem);
  1207. //现金项目
  1208. creditCashFlow.put("cash_item", cashItem);*/
  1209. creditCashFlow.put("iyear", LocalDate.now().getYear());
  1210. creditCashFlow.put("RowGuid", UUID.randomUUID().toString());
  1211. creditCashFlowList.add(creditCashFlow);
  1212. infoMap.put("cash_flow", creditCashFlowList);
  1213. Map credit = new HashMap();
  1214. credit.put("entry", infoMap);
  1215. log.info("贷方credit:{}", credit);
  1216. //debit entry信息 借方
  1217. Map debit = new HashMap();
  1218. List<Map> entryMapList = new ArrayList<>();
  1219. List<Map> details = (List<Map>) formData.get("tableField_lyiffepf");
  1220. String taxesSummary = ""; // 税金摘要
  1221. for (Map detail : details) {
  1222. String remark = getString(detail.get("textField_lyiffepn"));//备注
  1223. String payType = "其他";//支付类型
  1224. taxesSummary = revName + "/" + remark;
  1225. BigDecimal taxesAmount = new BigDecimal(getString(detail.get("numberField_m38g47en")));//金额
  1226. Map entryMap = new HashMap();
  1227. //科目编号
  1228. entryMap.put("account_code", "110110");//科目:其他 类型:资产
  1229. //摘要
  1230. entryMap.put("abstract", taxesSummary);
  1231. //本币贷方发生额*与本币借方发生额不能同时为空
  1232. entryMap.put("natural_debit_currency", taxesAmount);
  1233. Map auxiliaryMap = new HashMap();
  1234. auxiliaryMap.put("dept_id", deptCode);//部门
  1235. auxiliaryMap.put("supplier_id", supplierCode);//供应商
  1236. entryMap.put("auxiliary", auxiliaryMap);
  1237. entryMapList.add(entryMap);
  1238. }
  1239. debit.put("entry", entryMapList);
  1240. log.info("借方debit:{}", debit);
  1241. topInfoMap.put("debit",debit);
  1242. topInfoMap.put("credit",credit);
  1243. resultMap.put("voucher", topInfoMap);
  1244. log.info("voucher:{}", resultMap);
  1245. return resultMap;
  1246. }
  1247. private Map process136(Map formData, int dsSequence, String createUser) {
  1248. String schPayAccount = getString(formData.get("selectField_lxydz0ub"));//付款方账号
  1249. String revName = getString(formData.get("textField_lxwwvggc"));//收款人名称
  1250. String company = getString(formData.get("selectField_lxwwvggb"));//公司抬头
  1251. String purpose = getString(formData.get("textField_lxwwvggy"));//付款理由
  1252. String summary = revName + "/" + purpose;//摘要
  1253. String deptName = getString(formData.get("textField_m2sekyf7"));//部门
  1254. String currency = getString(formData.get("textField_m2sekyfi"));//币种
  1255. List<String> sepVoucherCompany = Arrays.asList("宁波卡倍亿电气技术股份有限公司", "宁波卡倍亿新材料科技有限公司", "宁波卡倍亿铜线有限公司", "湖北卡倍亿电气技术有限公司");
  1256. String voucherType =sepVoucherCompany.contains(company) ? "付" : "记";//凭证类型
  1257. String applyAmount = getString(formData.get("numberField_lxwwvggi"));//本次支付金额(元)
  1258. String producer = createUser;//制单人
  1259. String cashItem = getString(formData.get("textField_m2sekyfg"));//现金项目
  1260. //获取供应商信息
  1261. Map<String,Object> supplierParam = new HashMap<>();
  1262. supplierParam.put("from_account",fromAccount);
  1263. supplierParam.put("to_account",toAccount);
  1264. supplierParam.put("app_key", u8AppKey);
  1265. supplierParam.put("token", getU8Token());
  1266. supplierParam.put("page_index", 1);
  1267. supplierParam.put("rows_per_page", 50);
  1268. supplierParam.put("ds_sequence", dsSequence);
  1269. supplierParam.put("name", revName);
  1270. Map<String, Object> supplierMap = get("https://api.yonyouup.com/api/vendor/batch_get", supplierParam, null);
  1271. if (!"0".equals(supplierMap.get("errcode").toString())){
  1272. log.info("获取供应商信息失败:{},{}",supplierMap.get("errmsg").toString(),revName);
  1273. throw new RuntimeException("获取供应商信息失败:"+supplierMap.get("errmsg").toString()+","+revName);
  1274. }
  1275. List<Map> vendorList = (List<Map>) supplierMap.get("vendor");
  1276. String supplierCode = getString(vendorList.get(0).get("code"));
  1277. //获取部门信息
  1278. Map<String,Object> deptParam = new HashMap<>();
  1279. deptParam.put("from_account",fromAccount);
  1280. deptParam.put("to_account",toAccount);
  1281. deptParam.put("app_key", u8AppKey);
  1282. deptParam.put("token", getU8Token());
  1283. deptParam.put("page_index", 1);
  1284. deptParam.put("rows_per_page", 50);
  1285. deptParam.put("ds_sequence", dsSequence);
  1286. deptParam.put("name", deptName);
  1287. Map<String, Object> deptMap = get("https://api.yonyouup.com/api/department/batch_get", deptParam, null);
  1288. if (!"0".equals(deptMap.get("errcode").toString())){
  1289. log.info("获取部门信息失败:{},{}",deptMap.get("errmsg").toString(),deptName);
  1290. throw new RuntimeException("获取部门信息失败:"+deptMap.get("errmsg").toString()+","+deptName);
  1291. }
  1292. List<Map> deptList = (List<Map>) deptMap.get("department");
  1293. String deptCode = getString(deptList.get(0).get("code"));
  1294. Map resultMap = new HashMap();
  1295. Map topInfoMap = new HashMap();
  1296. //记账类型
  1297. topInfoMap.put("voucher_type",voucherType);
  1298. topInfoMap.put("enter",producer); //制单人
  1299. //credit entry信息 贷方
  1300. Map infoMap = new HashMap();
  1301. Map<String,Object> subjectParam = new HashMap<>();
  1302. subjectParam.put("from_account",fromAccount);
  1303. subjectParam.put("to_account",toAccount);
  1304. subjectParam.put("app_key", u8AppKey);
  1305. subjectParam.put("token", getU8Token());
  1306. subjectParam.put("page_index", 1);
  1307. subjectParam.put("rows_per_page", 50);
  1308. subjectParam.put("ds_sequence", dsSequence);
  1309. subjectParam.put("name", schPayAccount);
  1310. Map<String, Object> subjectMap = get("https://api.yonyouup.com/api/code/batch_get", subjectParam, null);
  1311. if (!"0".equals(subjectMap.get("errcode").toString())){
  1312. log.info("获取科目信息失败:{},{}",supplierMap.get("errmsg").toString(),schPayAccount);
  1313. throw new RuntimeException("获取科目信息失败:"+supplierMap.get("errmsg").toString()+","+schPayAccount);
  1314. }
  1315. List<Map> subjectList = (List<Map>) subjectMap.get("code");
  1316. String subjectCode = getString(subjectList.get(0).get("code"));
  1317. //贷方科目编码
  1318. infoMap.put("account_code", subjectCode);
  1319. //摘要
  1320. infoMap.put("abstract", summary);
  1321. //币种
  1322. infoMap.put("currency", currency);
  1323. //本币借方发生额*与本币贷方发生额不能同时为空
  1324. infoMap.put("natural_credit_currency", applyAmount);
  1325. List<Map> creditCashFlowList = new ArrayList<>();
  1326. Map creditCashFlow = new HashMap();
  1327. //币种
  1328. creditCashFlow.put("cexch_name", currency);
  1329. //本币借方发生额*与本币贷方发生额不能同时为空
  1330. creditCashFlow.put("natural_credit_currency", applyAmount);
  1331. //凭证类别字
  1332. creditCashFlow.put("csign", voucherType);
  1333. //科目编码 - 根据CBS 方,实际打款账户和公司来确定
  1334. creditCashFlow.put("ccode", subjectCode);
  1335. //贷方金额
  1336. creditCashFlow.put("mc", applyAmount);
  1337. //现金项目
  1338. creditCashFlow.put("cCashItem", cashItem);
  1339. //现金项目
  1340. creditCashFlow.put("cash_item", cashItem);
  1341. creditCashFlow.put("iyear", LocalDate.now().getYear());
  1342. creditCashFlow.put("RowGuid", UUID.randomUUID().toString());
  1343. creditCashFlowList.add(creditCashFlow);
  1344. infoMap.put("cash_flow", creditCashFlowList);
  1345. Map credit = new HashMap();
  1346. credit.put("entry", infoMap);
  1347. log.info("贷方credit:{}", credit);
  1348. //debit entry信息 借方
  1349. Map debit = new HashMap();
  1350. List<Map> entryMapList = new ArrayList<>();
  1351. List<Map> details = (List<Map>) formData.get("tableField_lxwwvggl");
  1352. String taxesSummary = ""; // 税金摘要
  1353. for (Map detail : details) {
  1354. String productName = getString(detail.get("textField_lxwwvggm"));//货物或劳务名称
  1355. String payType = getString(detail.get("selectField_m2sekyfa")).split("-")[0].split("\\(")[0];//支付类型
  1356. taxesSummary = revName + "/" + productName;
  1357. BigDecimal taxesAmount = new BigDecimal(getString(detail.get("numberField_lxwwvggo")));//金额
  1358. Map entryMap = new HashMap();
  1359. //科目编号
  1360. subjectParam.put("name",payType);
  1361. subjectMap = get("https://api.yonyouup.com/api/code/batch_get", subjectParam, null);
  1362. if (!"0".equals(subjectMap.get("errcode").toString())){
  1363. log.info("获取科目信息失败:{},{}",supplierMap.get("errmsg").toString(),productName);
  1364. throw new RuntimeException("获取科目信息失败:"+supplierMap.get("errmsg").toString()+","+productName);
  1365. }
  1366. subjectList = (List<Map>) subjectMap.get("code");
  1367. subjectCode = getString(subjectList.get(0).get("code"));
  1368. //科目编号
  1369. entryMap.put("account_code", subjectCode);
  1370. //摘要
  1371. entryMap.put("abstract", taxesSummary);
  1372. //本币贷方发生额*与本币借方发生额不能同时为空
  1373. entryMap.put("natural_debit_currency", taxesAmount);
  1374. Map auxiliaryMap = new HashMap();
  1375. auxiliaryMap.put("dept_id", deptCode);//部门
  1376. auxiliaryMap.put("supplier_id", supplierCode);//供应商
  1377. entryMap.put("auxiliary", auxiliaryMap);
  1378. entryMapList.add(entryMap);
  1379. }
  1380. debit.put("entry", entryMapList);
  1381. log.info("借方debit:{}", debit);
  1382. topInfoMap.put("debit",debit);
  1383. topInfoMap.put("credit",credit);
  1384. resultMap.put("voucher", topInfoMap);
  1385. log.info("voucher:{}", resultMap);
  1386. return resultMap;
  1387. }
  1388. private Map process131(Map formData,int dsSequence,String createUser) {
  1389. String schPayAccount = getString(formData.get("selectField_lxydz0ub"));//付款方账号
  1390. String revName = getString(formData.get("textField_lxwwvggc"));//收款人名称
  1391. String company = getString(formData.get("selectField_lxwwvggb"));//公司抬头
  1392. String purpose = getString(formData.get("textField_lxydz0ug"));//用途
  1393. String summary = revName + "/" + purpose;//摘要
  1394. String deptName = getString(formData.get("textField_m2sekyf7"));//部门
  1395. String currency = getString(formData.get("textField_m2sekyfi"));//币种
  1396. List<String> sepVoucherCompany = Arrays.asList("宁波卡倍亿电气技术股份有限公司", "宁波卡倍亿新材料科技有限公司", "宁波卡倍亿铜线有限公司", "湖北卡倍亿电气技术有限公司");
  1397. String voucherType =sepVoucherCompany.contains(company) ? "付" : "记";//凭证类型
  1398. String applyAmount = getString(formData.get("numberField_lxwwvggi"));//本次支付金额(元)
  1399. String producer = createUser;//制单人
  1400. String cashItem = getString(formData.get("textField_m2sekyfg"));//现金项目
  1401. //获取供应商信息
  1402. Map<String,Object> supplierParam = new HashMap<>();
  1403. supplierParam.put("from_account",fromAccount);
  1404. supplierParam.put("to_account",toAccount);
  1405. supplierParam.put("app_key", u8AppKey);
  1406. supplierParam.put("token", getU8Token());
  1407. supplierParam.put("page_index", 1);
  1408. supplierParam.put("rows_per_page", 50);
  1409. supplierParam.put("ds_sequence", dsSequence);
  1410. supplierParam.put("name", revName);
  1411. Map<String, Object> supplierMap = get("https://api.yonyouup.com/api/vendor/batch_get", supplierParam, null);
  1412. if (!"0".equals(supplierMap.get("errcode").toString())){
  1413. log.info("获取供应商信息失败:{},{}",supplierMap.get("errmsg").toString(),revName);
  1414. throw new RuntimeException("获取供应商信息失败:"+supplierMap.get("errmsg").toString()+","+revName);
  1415. }
  1416. List<Map> vendorList = (List<Map>) supplierMap.get("vendor");
  1417. String supplierCode = getString(vendorList.get(0).get("code"));
  1418. //获取部门信息
  1419. Map<String,Object> deptParam = new HashMap<>();
  1420. deptParam.put("from_account",fromAccount);
  1421. deptParam.put("to_account",toAccount);
  1422. deptParam.put("app_key", u8AppKey);
  1423. deptParam.put("token", getU8Token());
  1424. deptParam.put("page_index", 1);
  1425. deptParam.put("rows_per_page", 50);
  1426. deptParam.put("ds_sequence", dsSequence);
  1427. deptParam.put("name", deptName);
  1428. Map<String, Object> deptMap = get("https://api.yonyouup.com/api/department/batch_get", deptParam, null);
  1429. if (!"0".equals(deptMap.get("errcode").toString())){
  1430. log.info("获取部门信息失败:{},{}",deptMap.get("errmsg").toString(),deptName);
  1431. throw new RuntimeException("获取部门信息失败:"+deptMap.get("errmsg").toString()+","+deptName);
  1432. }
  1433. List<Map> deptList = (List<Map>) deptMap.get("department");
  1434. String deptCode = getString(deptList.get(0).get("code"));
  1435. Map resultMap = new HashMap();
  1436. Map topInfoMap = new HashMap();
  1437. //记账类型
  1438. topInfoMap.put("voucher_type",voucherType);
  1439. topInfoMap.put("enter",producer); //制单人
  1440. //credit entry信息 贷方
  1441. Map infoMap = new HashMap();
  1442. Map<String,Object> subjectParam = new HashMap<>();
  1443. subjectParam.put("from_account",fromAccount);
  1444. subjectParam.put("to_account",toAccount);
  1445. subjectParam.put("app_key", u8AppKey);
  1446. subjectParam.put("token", getU8Token());
  1447. subjectParam.put("page_index", 1);
  1448. subjectParam.put("rows_per_page", 50);
  1449. subjectParam.put("ds_sequence", dsSequence);
  1450. subjectParam.put("name", schPayAccount);
  1451. Map<String, Object> subjectMap = get("https://api.yonyouup.com/api/code/batch_get", subjectParam, null);
  1452. if (!"0".equals(subjectMap.get("errcode").toString())){
  1453. log.info("获取科目信息失败:{},{}",supplierMap.get("errmsg").toString(),schPayAccount);
  1454. throw new RuntimeException("获取科目信息失败:"+supplierMap.get("errmsg").toString()+","+schPayAccount);
  1455. }
  1456. List<Map> subjectList = (List<Map>) subjectMap.get("code");
  1457. String subjectCode = getString(subjectList.get(0).get("code"));
  1458. //贷方科目编码
  1459. infoMap.put("account_code", subjectCode);
  1460. //摘要
  1461. infoMap.put("abstract", summary);
  1462. //币种
  1463. infoMap.put("currency", currency);
  1464. //本币借方发生额*与本币贷方发生额不能同时为空
  1465. infoMap.put("natural_credit_currency", applyAmount);
  1466. Map auxiliary = new HashMap();
  1467. // //项目档案-现流编号
  1468. auxiliary.put("item_class", "05");
  1469. infoMap.put("auxiliary", auxiliary);
  1470. List<Map> creditCashFlowList = new ArrayList<>();
  1471. Map creditCashFlow = new HashMap();
  1472. //币种
  1473. creditCashFlow.put("cexch_name", currency);
  1474. //本币借方发生额*与本币贷方发生额不能同时为空
  1475. creditCashFlow.put("natural_credit_currency", applyAmount);
  1476. //凭证类别字
  1477. creditCashFlow.put("csign", voucherType);
  1478. creditCashFlow.put("ccode", subjectCode);
  1479. //贷方金额
  1480. creditCashFlow.put("mc", applyAmount);
  1481. //现金项目
  1482. creditCashFlow.put("cCashItem", cashItem);
  1483. //现金项目
  1484. creditCashFlow.put("cash_item", cashItem);
  1485. creditCashFlow.put("iyear", LocalDate.now().getYear());
  1486. creditCashFlow.put("RowGuid", UUID.randomUUID().toString());
  1487. creditCashFlowList.add(creditCashFlow);
  1488. infoMap.put("cash_flow", creditCashFlowList);
  1489. Map credit = new HashMap();
  1490. credit.put("entry", infoMap);
  1491. log.info("贷方credit:{}", credit);
  1492. //debit entry信息 借方
  1493. Map debit = new HashMap();
  1494. List<Map> entryMapList = new ArrayList<>();
  1495. List<Map> details = (List<Map>) formData.get("tableField_lxwwvggl");
  1496. BigDecimal taxesSum = BigDecimal.ZERO; // 税金总计
  1497. String taxesSummary = ""; // 税金摘要
  1498. for (Map detail : details) {
  1499. String productName = getString(detail.get("textField_lxwwvggm"));//货物或劳务名称
  1500. String payType = getString(detail.get("selectField_m2sekyfa")).split("-")[0].split("\\(")[0];//支付类型
  1501. taxesSummary = revName + "/" + productName;
  1502. BigDecimal taxesAmount = new BigDecimal(getString(detail.get("numberField_lxwwvggo")));//金额
  1503. BigDecimal taxes = new BigDecimal(getString(detail.get("numberField_m2sekyf8")));//税金金额
  1504. taxesSum = taxesSum.add(taxes);
  1505. Map entryMap = new HashMap();
  1506. //科目编号
  1507. subjectParam.put("name",payType);
  1508. subjectMap = get("https://api.yonyouup.com/api/code/batch_get", subjectParam, null);
  1509. if (!"0".equals(subjectMap.get("errcode").toString())){
  1510. log.info("获取科目信息失败:{},{}",supplierMap.get("errmsg").toString(),productName);
  1511. throw new RuntimeException("获取科目信息失败:"+supplierMap.get("errmsg").toString()+","+productName);
  1512. }
  1513. subjectList = (List<Map>) subjectMap.get("code");
  1514. subjectCode = getString(subjectList.get(0).get("code"));
  1515. entryMap.put("account_code", subjectCode);
  1516. //摘要
  1517. entryMap.put("abstract", revName + "/" + productName);
  1518. //本币贷方发生额*与本币借方发生额不能同时为空
  1519. entryMap.put("natural_debit_currency", taxesAmount.subtract(taxes).toPlainString());
  1520. Map auxiliaryMap = new HashMap();
  1521. auxiliaryMap.put("dept_id", deptCode);//部门
  1522. auxiliaryMap.put("supplier_id", supplierCode);//供应商
  1523. entryMap.put("auxiliary", auxiliaryMap);
  1524. entryMapList.add(entryMap);
  1525. }
  1526. // 添加税金科目
  1527. if (taxesSum.compareTo(BigDecimal.ZERO) == 1) { // 税金总和大于0
  1528. Map entryMap = new HashMap();
  1529. subjectParam.put("name","进项税额");
  1530. subjectMap = get("https://api.yonyouup.com/api/code/batch_get", subjectParam, null);
  1531. if (!"0".equals(subjectMap.get("errcode").toString())){
  1532. log.info("获取科目信息失败:{},{}",supplierMap.get("errmsg").toString(),"进项税额");
  1533. throw new RuntimeException("获取科目信息失败:"+supplierMap.get("errmsg").toString()+","+"进项税额");
  1534. }
  1535. subjectList = (List<Map>) subjectMap.get("code");
  1536. subjectCode = getString(subjectList.get(0).get("code"));
  1537. //科目编号
  1538. entryMap.put("account_code", subjectCode); // 税金
  1539. //摘要
  1540. entryMap.put("abstract", taxesSummary);
  1541. //本币贷方发生额*与本币借方发生额不能同时为空
  1542. entryMap.put("natural_debit_currency", taxesSum.toPlainString());
  1543. Map auxiliaryMap = new HashMap();
  1544. auxiliaryMap.put("dept_id", deptCode);//部门
  1545. auxiliaryMap.put("supplier_id", supplierCode);//供应商
  1546. entryMap.put("auxiliary", auxiliaryMap);
  1547. entryMapList.add(entryMap);
  1548. }
  1549. debit.put("entry", entryMapList);
  1550. log.info("借方debit:{}", debit);
  1551. topInfoMap.put("debit",debit);
  1552. topInfoMap.put("credit",credit);
  1553. resultMap.put("voucher", topInfoMap);
  1554. log.info("voucher:{}", resultMap);
  1555. return resultMap;
  1556. }
  1557. /**
  1558. * 封装GET请求
  1559. *
  1560. * @param url 请求的URL
  1561. * @param params 请求参数
  1562. * @param headers 请求头
  1563. * @return 响应内容
  1564. */
  1565. public static Map<String, Object> get(String url, Map<String, Object> params, Map<String, String> headers) {
  1566. log.info("GET 请求url:{}, 请求参数:{}, 请求头:{}", url, params, headers);
  1567. HttpRequest get = HttpUtil.createGet(url);
  1568. if (params!= null){
  1569. get.form(params);
  1570. }
  1571. if (headers!= null){
  1572. get.addHeaders(headers);
  1573. }
  1574. HttpResponse response = get.execute();
  1575. Map<String, Object> result = null;
  1576. try {
  1577. ObjectMapper objectMapper = new ObjectMapper();
  1578. result = objectMapper.readValue(response.body(), new TypeReference<Map<String, Object>>() {});
  1579. } catch (JsonProcessingException e) {
  1580. throw new RuntimeException(e);
  1581. }
  1582. log.info("响应结果: {}", result);
  1583. return result;
  1584. }
  1585. /**
  1586. * 封装POST请求
  1587. *
  1588. * @param url 请求的URL
  1589. * @param params 请求参数
  1590. * @param headers 请求头
  1591. * @param body 请求体
  1592. * @return 响应内容
  1593. */
  1594. public static Map<String, Object> post(String url, Map<String, Object> params, Map<String, String> headers, Map<String, Object> body) {
  1595. log.info("POST 请求url:{}, 请求参数:{}, 请求头:{}, 请求体:{}", url, params, headers, body);
  1596. String newUrl = url;
  1597. StringBuffer param = new StringBuffer();
  1598. for (String key : params.keySet()) {
  1599. param.append(key + "=" + params.get(key).toString() + "&");
  1600. }
  1601. String paramStr = param.toString();
  1602. paramStr = paramStr.substring(0, paramStr.length() - 1);
  1603. if (newUrl.indexOf("?") >= 0) {
  1604. newUrl += "&" + paramStr;
  1605. } else {
  1606. newUrl += "?" + paramStr;
  1607. }
  1608. HttpRequest request = HttpUtil.createPost(newUrl);
  1609. /*if (params != null) {
  1610. request.form(params);
  1611. }*/
  1612. if (headers != null) {
  1613. request.addHeaders(headers);
  1614. }
  1615. if (body != null) {
  1616. request.body(JSONUtil.toJsonStr(body), "application/json");
  1617. }
  1618. HttpResponse response = request.execute();
  1619. // Map<String,Object> result = JSONUtil.toBean(response.body(), Map.class);
  1620. Map<String, Object> result = null;
  1621. try {
  1622. ObjectMapper objectMapper = new ObjectMapper();
  1623. result = objectMapper.readValue(response.body(), new TypeReference<Map<String, Object>>() {});
  1624. } catch (JsonProcessingException e) {
  1625. throw new RuntimeException(e);
  1626. }
  1627. log.info("响应结果: {}", result);
  1628. return result;
  1629. }
  1630. private String getU8Token(){
  1631. String accessToken = UtilToken.get("u8-token");
  1632. if (StringUtils.isNotBlank(accessToken)) {
  1633. return accessToken;
  1634. } else {
  1635. Map<String,Object> param = new HashMap<>();
  1636. param.put("from_account", fromAccount);
  1637. param.put("app_key", u8AppKey);
  1638. param.put("app_secret", u8AppSecret);
  1639. Map<String, Object> result = get("https://api.yonyouup.com/system/token", param, null);
  1640. Map token = (Map) result.get("token");
  1641. String id = token.get("id").toString();
  1642. log.info("u响应token, {}", id);
  1643. UtilToken.put("u8-token", id, (int) token.get("expiresIn") * 1000L);
  1644. return id;
  1645. }
  1646. }
  1647. private String getString(Object obj){
  1648. return obj == null ? "" : obj.toString();
  1649. }
  1650. public String getTcAccessToken() {
  1651. String accessToken = UtilToken.get("tc-invalid-token-dingtalk");
  1652. if (StringUtils.isNotBlank(accessToken)) {
  1653. return accessToken;
  1654. } else {
  1655. Map param = new HashMap();
  1656. param.put("appkey", appKey);
  1657. param.put("appsecret", appSecret);
  1658. DDR r = (DDR)UtilHttp.doGet("https://oapi.dingtalk.com/gettoken", param, DDR.class);
  1659. log.info("特充响应token, {}", r.getAccessToken());
  1660. accessToken = r.getAccessToken();
  1661. UtilToken.put("tc-invalid-token-dingtalk", accessToken, (long)r.getExpiresIn() * 1000L);
  1662. return accessToken;
  1663. }
  1664. }
  1665. @Override
  1666. public String getWeekRange(String dateStr) {
  1667. //获取所属周(每周六-下周五)
  1668. DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
  1669. LocalDate date = LocalDate.parse(dateStr, inputFormatter);
  1670. LocalDate startOfWeek;
  1671. // 获取该周的周六(开始日期)
  1672. startOfWeek = date.with(TemporalAdjusters.previousOrSame(DayOfWeek.SATURDAY));
  1673. // 获取该周的周五(结束日期)
  1674. LocalDate endOfWeek = startOfWeek.plusDays(6);
  1675. DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern("MM.dd");
  1676. return startOfWeek.format(outputFormatter) + "-" + endOfWeek.format(outputFormatter);
  1677. }
  1678. public boolean isNumber(String str) {
  1679. try {
  1680. Double.parseDouble(str);
  1681. return true;
  1682. } catch (NumberFormatException e) {
  1683. return false;
  1684. }
  1685. }
  1686. }