HSImplService.java 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. package com.malk.hangshi.service.impl;
  2. import cn.hutool.core.util.ObjectUtil;
  3. import com.alibaba.fastjson.JSON;
  4. import com.malk.hangshi.service.HSService;
  5. import com.malk.server.aliwork.YDConf;
  6. import com.malk.server.aliwork.YDParam;
  7. import com.malk.server.dingtalk.DDConf;
  8. import com.malk.service.aliwork.YDClient;
  9. import com.malk.service.dingtalk.DDClient;
  10. import com.malk.service.dingtalk.DDClient_Contacts;
  11. import com.malk.utils.UtilDateTime;
  12. import com.malk.utils.UtilHttp;
  13. import com.malk.utils.UtilMap;
  14. import lombok.Synchronized;
  15. import lombok.extern.slf4j.Slf4j;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import org.springframework.stereotype.Service;
  18. import java.text.DecimalFormat;
  19. import java.time.LocalDate;
  20. import java.util.Arrays;
  21. import java.util.HashMap;
  22. import java.util.List;
  23. import java.util.Map;
  24. @Service
  25. @Slf4j
  26. public class HSImplService implements HSService {
  27. @Autowired
  28. private DDClient ddClient;
  29. @Autowired
  30. private DDClient_Contacts ddClient_contacts;
  31. private Map DEPT_INFO;
  32. @Override
  33. @Synchronized
  34. public Map getDeptInfo(boolean isClear) {
  35. if (isClear) {
  36. DEPT_INFO = null;
  37. }
  38. if (ObjectUtil.isNull(DEPT_INFO)) {
  39. int total = 0;
  40. Map deptInfo = UtilMap.map("东方航空食品投资有限公司", ddClient_contacts.getUserCount(ddClient.getAccessToken(), true));
  41. // 一级部门累计
  42. List<Map> deptInfos = ddClient_contacts.listSubDepartmentDetail(ddClient.getAccessToken(), DDConf.TOP_DEPARTMENT);
  43. for (Map dept : deptInfos) {
  44. String deptName = String.valueOf(dept.get("name"));
  45. if (!deptName.contains("航食")) {
  46. continue;
  47. }
  48. long deptId = UtilMap.getLong(dept, "dept_id");
  49. int count = 0;
  50. for (long sub : ddClient_contacts.getDepartmentId_all(ddClient.getAccessToken(), true, deptId)) {
  51. count += ddClient_contacts.listDepartmentUserId(ddClient.getAccessToken(), sub).size();
  52. }
  53. total += count;
  54. deptInfo.put(dept.get("name"), count);
  55. // 上海航食处理
  56. if (deptName.equals("上海航食")) {
  57. List<Map> subDeptInfos = ddClient_contacts.listSubDepartmentDetail(ddClient.getAccessToken(), deptId);
  58. for (Map subDept : subDeptInfos) {
  59. if (Arrays.asList("虹桥中心", "浦东中心").contains(subDept.get("name"))) {
  60. int num = 0;
  61. for (long sub : ddClient_contacts.getDepartmentId_all(ddClient.getAccessToken(), true, UtilMap.getLong(subDept, "dept_id"))) {
  62. num += ddClient_contacts.listDepartmentUserId(ddClient.getAccessToken(), sub).size();
  63. }
  64. deptInfo.put(subDept.get("name"), num);
  65. }
  66. }
  67. deptInfo.put("各职能业务部门及事业部", UtilMap.getInt(deptInfo, "上海航食") - UtilMap.getInt(deptInfo, "虹桥中心") - UtilMap.getInt(deptInfo, "浦东中心"));
  68. }
  69. }
  70. // deptInfo.put("航食", total);
  71. DEPT_INFO = deptInfo;
  72. }
  73. return DEPT_INFO;
  74. }
  75. @Override
  76. public int getCorpCount() {
  77. return ddClient_contacts.getUserCount(ddClient.getAccessToken(), true);
  78. }
  79. @Autowired
  80. private YDClient ydClient;
  81. //进出口
  82. private final static String OUTINURL = "https://eacconsole.ceair.com/api/WBPM1-eaccart/statistical/asis/list";
  83. //餐车数
  84. private final static String CARURL = "https://eacconsole.ceair.com/api/WBPM1-eaccart/cartAbnormal/abnormal";
  85. @Override
  86. public void syncHangShiInfo() {
  87. YDParam ydParam = YDParam.builder()
  88. .appType("APP_RNU2SVHDBJX8KIFTWVYZ")
  89. .systemToken("H7966HA1OP38AMWZAHPAB6GZSTR134F87IWDLH")
  90. .formUuid("FORM-YU966T91NP38DWF5FKBBK6G90HWP3BRBQIWDL1") //获取所有航食列表
  91. .build();
  92. List<Map> dataList = (List<Map>) ydClient.queryData(ydParam, YDConf.FORM_QUERY.retrieve_search_form).getData();
  93. //遍历航食数据
  94. dataList.forEach(dataItem -> {
  95. Map map = (Map) dataItem.get("formData");
  96. String hsName = map.get("textField_ldwirsz3").toString();
  97. String hsId = map.get("textField_lvxkvjcw").toString();
  98. LocalDate currentDate = LocalDate.now();
  99. LocalDate previousDay = currentDate.minusDays(1);
  100. //获取库存
  101. String rsp = getOutInInfo(getToken(), hsId, previousDay.toString(), OUTINURL);
  102. Map result = (Map) JSON.parse(rsp);
  103. Map hashMap = new HashMap();
  104. Map maps = (Map) result.get("osisList");
  105. List<Map> mapList = (List<Map>) maps.get("data");
  106. DecimalFormat df = new DecimalFormat("#.##");
  107. mapList.forEach(mapItem -> {
  108. Map map1 = (Map) mapItem.get("dynamicInventoryStatistical");
  109. hashMap.put("numberField_ldwi9du2", map1.get("longNumber")); //昨日库存长
  110. hashMap.put("numberField_ldwi9du3", map1.get("shortNumber")); //昨日库存长
  111. hashMap.put("numberField_ldwi9du4", map1.get("total")); //昨日总库存
  112. Map map2 = (Map) mapItem.get("inputCartStatistical");
  113. hashMap.put("numberField_ldwi9dua", map2.get("total")); //昨日进港量
  114. Map map3 = (Map) mapItem.get("outputCartStatistical");
  115. hashMap.put("numberField_ldwi9du9", map3.get("total")); //昨日出港量
  116. });
  117. //获取开口餐车数 token 航食ID 日期 接口路径
  118. String rsp2 = getOutInInfo(getToken(), hsId, previousDay.toString(), CARURL);
  119. Map result2 = (Map) JSON.parse(rsp2);
  120. Map maps2 = (Map) result2.get("stationAbnormal");
  121. List<Map> mapList2 = (List<Map>) maps2.get("data");
  122. mapList2.forEach(mapItem2 -> {
  123. hashMap.put("numberField_ldwi9dug", mapItem2.get("openingCart")); //昨日开口餐车数
  124. });
  125. hashMap.put("selectField_ldwi9dtr", hsName); //航食名称
  126. hashMap.put("textField_lwhbjcoh", hsName); //航食名称
  127. hashMap.put("dateField_ldwi9dtt", UtilDateTime.parse(String.valueOf(currentDate), "yyyy-MM-dd"));
  128. hashMap.put("dateField_le2jibxo", UtilDateTime.parse(String.valueOf(previousDay), "yyyy-MM-dd"));
  129. try {
  130. ydClient.operateData(YDParam.builder()
  131. .appType("APP_RNU2SVHDBJX8KIFTWVYZ")
  132. .systemToken("H7966HA1OP38AMWZAHPAB6GZSTR134F87IWDLH")
  133. .formUuid("FORM-A3217B8D9A124DE48A1522D47C19C131M4QK")
  134. .formDataJson(JSON.toJSONString(hashMap))
  135. .build(), YDConf.FORM_OPERATION.create);
  136. } catch (Exception e) {
  137. log.info("异常数据 hashMap:{}", hashMap);
  138. }
  139. });
  140. }
  141. /**
  142. * 获取token
  143. */
  144. public String getToken() {
  145. Map<String, String> body = new HashMap<>();
  146. body.put("account", "7859121209872651");
  147. body.put("password", "efc736bbE@09054c");
  148. String str = UtilHttp.doPost("https://eacconsole.ceair.com/api/WBPM1-eacorg/external/access", null, null, body);
  149. String token = String.valueOf(((Map) JSON.parse(str)).get("accessToken"));
  150. return token;
  151. }
  152. /**
  153. * 进出港数据 开口餐车数
  154. *
  155. * @param token
  156. * @param id
  157. * @param dataTime
  158. * @return
  159. */
  160. public String getOutInInfo(String token, String id, String dataTime, String url) {
  161. Map<String, String> headers = new HashMap<>();
  162. headers.put("Content-Type", "application/json;charset=UTF-8");
  163. headers.put("X-GL-ACCESS-TOKEN", token);
  164. headers.put("X-GL-AGENT", "EAFORG-SERVICE");
  165. headers.put("X-GL-CLIENT", "OPERATION");
  166. Map<String, String> params = new HashMap<>();
  167. params.put("pageStart", "0");
  168. params.put("pageSize", "10");
  169. params.put("id", id);
  170. params.put("paramType", "ORGANIZATION");
  171. params.put("startTime", dataTime);
  172. params.put("endTime", dataTime);
  173. String rsp = UtilHttp.doGet(url, headers, params);
  174. return rsp;
  175. }
  176. }