CabinetUtil.java 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. package org.dromara.util;
  2. import cn.hutool.core.date.DateField;
  3. import cn.hutool.core.date.DatePattern;
  4. import cn.hutool.core.date.DateUtil;
  5. import cn.hutool.core.thread.ThreadUtil;
  6. import cn.hutool.core.util.StrUtil;
  7. import cn.hutool.http.HttpRequest;
  8. import cn.hutool.json.JSONArray;
  9. import cn.hutool.json.JSONObject;
  10. import cn.hutool.json.JSONUtil;
  11. import com.alibaba.fastjson.JSON;
  12. import org.apache.xmlbeans.impl.xb.xsdschema.Public;
  13. import org.dromara.common.core.domain.R;
  14. import org.dromara.common.core.utils.SpringUtils;
  15. import org.dromara.common.core.utils.StringUtils;
  16. import org.dromara.common.mybatis.core.page.PageQuery;
  17. import org.dromara.common.redis.utils.CacheUtils;
  18. import org.dromara.common.redis.utils.RedisUtils;
  19. import org.dromara.system.domain.GpsData;
  20. import org.dromara.system.domain.TblCarInfo;
  21. import org.dromara.system.domain.bo.*;
  22. import org.dromara.system.domain.vo.*;
  23. import org.dromara.system.service.ISysDictDataService;
  24. import org.dromara.system.service.ISysUserService;
  25. import org.dromara.system.service.ITblBagService;
  26. import org.dromara.system.service.ITblExpressStaticsService;
  27. import org.dromara.system.service.impl.TblCarInfoServiceImpl;
  28. import org.dromara.system.service.impl.TblCarScheduleServiceImpl;
  29. import org.slf4j.Logger;
  30. import org.slf4j.LoggerFactory;
  31. import org.springframework.beans.BeanUtils;
  32. import org.springframework.beans.factory.annotation.Autowired;
  33. import org.springframework.scheduling.annotation.Scheduled;
  34. import org.springframework.stereotype.Component;
  35. import tech.powerjob.worker.core.processor.ProcessResult;
  36. import tech.powerjob.worker.core.processor.TaskContext;
  37. import tech.powerjob.worker.core.processor.sdk.BasicProcessor;
  38. import javax.crypto.Cipher;
  39. import java.io.UnsupportedEncodingException;
  40. import java.security.Key;
  41. import java.text.DateFormat;
  42. import java.text.SimpleDateFormat;
  43. import java.time.format.DateTimeFormatter;
  44. import java.util.*;
  45. @Component
  46. public class CabinetUtil implements BasicProcessor {
  47. private final static String appid = "bw_open_express_A8C848769E5C04E0";
  48. private final static String appkey = "5AFC6E07CFCF4A359B775D1416A9799A";
  49. private final static String hosts = "https://open.bestwond.com";
  50. public final static String CABINET_INFO = "cabinet_info";
  51. public final static String CABINET_BOXS = "cabinet_boxs";
  52. private static final Logger log = LoggerFactory.getLogger(CabinetUtil.class);
  53. private static String byteArr2HexStr(byte[] arrB) throws Exception {
  54. int iLen = arrB.length;
  55. // 每个byte用两个字符才能表示,所以字符串的长度是数组长度的两倍
  56. StringBuffer sb = new StringBuffer(iLen * 2);
  57. for (int i = 0; i < iLen; i++) {
  58. int intTmp = arrB[i];
  59. // 把负数转换为正数
  60. while (intTmp < 0) {
  61. intTmp = intTmp + 256;
  62. }
  63. // 小于0F的数需要在前面补0
  64. if (intTmp < 16) {
  65. sb.append("0");
  66. }
  67. sb.append(Integer.toString(intTmp, 16));
  68. }
  69. return sb.toString();
  70. }
  71. private static String encrypt(String strIn) throws Exception {
  72. return byteArr2HexStr(encrypt(strIn.getBytes("UTF-8")));
  73. }
  74. private static byte[] encrypt(byte[] arrB) throws Exception {
  75. Key key = getKey(appkey.getBytes("UTF-8"));
  76. Cipher encryptCipher = Cipher.getInstance("DES");
  77. encryptCipher.init(Cipher.ENCRYPT_MODE, key);
  78. return encryptCipher.doFinal(arrB);
  79. }
  80. private static Key getKey(byte[] arrBTmp) throws Exception {
  81. // 创建一个空的8位字节数组(默认值为0)
  82. byte[] arrB = new byte[8];
  83. // 将原始字节数组转换为8位
  84. for (int i = 0; i < arrBTmp.length && i < arrB.length; i++) {
  85. arrB[i] = arrBTmp[i];
  86. }
  87. // 生成密钥
  88. Key key = new javax.crypto.spec.SecretKeySpec(arrB, "DES");
  89. return key;
  90. }
  91. // private static String getQJM(String phone) throws Exception {
  92. // String text = SpringUtils.getBean(ISysConfigService.class).selectConfigByKey("sys.cabinet.account");
  93. //
  94. // }
  95. @Scheduled(cron = "0 10 0 ? * ? ")
  96. // @Scheduled(cron = "0/10 * * * * * ")
  97. private void getExpressStatic() {
  98. SysUserBo sysUserBo = new SysUserBo();
  99. sysUserBo.setRoleId(1763484881548447746L);
  100. List<SysUserVo> userlist = SpringUtils.getBean(ISysUserService.class).getUserList(sysUserBo);
  101. log.info(String.valueOf(userlist.size()));
  102. for(SysUserVo vo:userlist){
  103. if(vo!=null && vo.getPhonenumber()!=null && !vo.getPhonenumber().isEmpty() && vo.getPhonenumber() != null){
  104. log.info("----------------------快递员{}开始同步----------------------",vo.getNickName());
  105. try{
  106. String month = getLastMonth();
  107. TblExpressStaticsBo bo = new TblExpressStaticsBo();
  108. bo.setMonth(month);
  109. bo.setUserId(vo.getUserId());
  110. bo.setData(CabinetUtil.getExpressDeliveryStatistics(vo.getPhonenumber(),month));
  111. Thread.sleep(10000);
  112. TblExpressStaticsBo query = new TblExpressStaticsBo();
  113. query.setMonth(month);
  114. query.setUserId(vo.getUserId());
  115. List<TblExpressStaticsVo> list = SpringUtils.getBean(ITblExpressStaticsService.class).queryList(query);
  116. if(list.size() > 0){
  117. bo.setId(list.get(0).getId());
  118. SpringUtils.getBean(ITblExpressStaticsService.class).updateByBo(bo);
  119. }else{
  120. SpringUtils.getBean(ITblExpressStaticsService.class).insertByBo(bo);
  121. }
  122. log.info("----------------------快递员{}结束同步----------------------",vo.getNickName());
  123. }catch (Exception e){
  124. }
  125. }
  126. }
  127. }
  128. @Scheduled(fixedRate = 5*60*1000)
  129. private void genScheduleList(){
  130. TblCarScheduleBo bo =new TblCarScheduleBo();
  131. bo.getParams().put("scheduleDate",DateUtil.format(DateUtil.date(),"yyyy-MM-dd"));
  132. List<TblCarScheduleVo> scheduleVos = SpringUtils.getBean(TblCarScheduleServiceImpl.class).queryList(bo);
  133. TblCarScheduleBo bo2 =new TblCarScheduleBo();
  134. bo2.getParams().put("scheduleDate",DateUtil.format(DateUtil.date().offset(DateField.DAY_OF_MONTH,1),"yyyy-MM-dd"));
  135. List<TblCarScheduleVo> scheduleVos2 = SpringUtils.getBean(TblCarScheduleServiceImpl.class).queryList(bo2);
  136. Map<String,Object> map=new HashMap<>();
  137. scheduleVos2.forEach(scheduleVo2->{
  138. map.put(scheduleVo2.getCarNum()+DateUtil.format(scheduleVo2.getScheduleDate(),DatePattern.NORM_DATETIME_PATTERN),scheduleVo2);
  139. });
  140. for (TblCarScheduleVo scheduleVo : scheduleVos) {
  141. if(StrUtil.isNotEmpty(scheduleVo.getExt2())){
  142. try{
  143. if(JSONUtil.parseObj(scheduleVo.getExt2()).getBool("isauto") && map.get(scheduleVo.getCarNum()+DateUtil.format( DateUtil.date(scheduleVo.getScheduleDate()).offset(DateField.DAY_OF_MONTH,1),DatePattern.NORM_DATETIME_PATTERN))==null){
  144. //copy
  145. TblCarScheduleBo bo1 =new TblCarScheduleBo();
  146. bo1.setCarNum(scheduleVo.getCarNum());
  147. bo1.setScheduleDate(DateUtil.offset(scheduleVo.getScheduleDate(),DateField.DAY_OF_MONTH,1));
  148. bo1.setPathInfo(scheduleVo.getPathInfo());
  149. bo1.setCreateTime(DateUtil.date());
  150. bo1.setExt2(scheduleVo.getExt2());
  151. bo1.setCreateDept(103100L);
  152. SpringUtils.getBean(TblCarScheduleServiceImpl.class).insertByBo(bo1);
  153. }
  154. }catch (Exception e){
  155. }
  156. }
  157. }
  158. }
  159. @Scheduled(fixedRate = 5*60*1000)
  160. private void getGpsList(){
  161. List<TblCarInfoVo> carInfoVos = SpringUtils.getBean(TblCarInfoServiceImpl.class).queryList(new TblCarInfoBo());
  162. for (TblCarInfoVo car : carInfoVos) {
  163. if(StrUtil.isNotEmpty(car.getDeviceInfos())){
  164. JSONUtil.parseArray(car.getDeviceInfos()).forEach(item->{
  165. JSONObject c = (JSONObject)item;
  166. try {
  167. if (c.getStr("type").equals("gps")) {
  168. GpsData gpsData = RedisUtils.getCacheObject(StringUtils.format("gps_{}", c.getStr("code")));
  169. //1小时就离线
  170. Map<String, Object> map = new HashMap<>();
  171. if (gpsData.getTs() == null) {
  172. gpsData.setTs(DateUtil.date());
  173. }
  174. if (DateUtil.current() - gpsData.getTs().getTime() > 1000 * 60 * 60) {
  175. map.put("code", c.getStr("code"));
  176. map.put("time", DatePattern.NORM_DATETIME_FORMAT.format(gpsData.getTs()));
  177. map.put("station", car.getCarNum());
  178. CacheUtils.put("offline", c.getStr("code"), map);
  179. } else {
  180. CacheUtils.put("offline", c.getStr("code"), map);
  181. }
  182. }
  183. }catch (Exception e){}
  184. });
  185. }
  186. }
  187. }
  188. @Scheduled(fixedRate = 5*60*1000)
  189. private void getList(){
  190. //获取所有gps 判断是否离线
  191. List<List<String>> cabinetList = new ArrayList<>();
  192. SysDictDataBo bo =new SysDictDataBo();
  193. bo.setDictType("tbl_sites");
  194. List<SysDictDataVo> list = SpringUtils.getBean(ISysDictDataService.class).selectDictDataList(bo);
  195. try {
  196. list.forEach(item->{
  197. if(StrUtil.isNotEmpty(item.getRemark())){
  198. JSONArray jsonArray = JSONUtil.parseArray(item.getRemark());
  199. jsonArray.forEach(item2->{
  200. if(((JSONObject)item2).getStr("type").equals("cabinet")){
  201. cabinetList.add( List.of(item.getDictLabel(),((JSONObject)item2).getStr("code")));
  202. }
  203. });
  204. }
  205. });
  206. }catch (Exception e){
  207. }
  208. if(cabinetList!=null && cabinetList.size()>0){
  209. cabinetList.forEach(item->{
  210. try {
  211. Thread.sleep(1000);
  212. String details= CabinetUtil.getCabinetInfo(item.get(1));
  213. CacheUtils.put(CABINET_INFO,item.get(1),details);
  214. // log.info(StrUtil.format("获取到柜子信息:{},{}",item.get(1),details));
  215. Thread.sleep(1000);
  216. //获取柜子状态
  217. String boxs= CabinetUtil.getCabinetBoxs(item.get(1));
  218. CacheUtils.put(CABINET_BOXS,item.get(1),boxs);
  219. // log.info(StrUtil.format("获取到柜子箱子信息:{},{}",item.get(1),boxs));
  220. try{
  221. Integer obline = JSONUtil.parseObj(details).getJSONObject("data").getInt("device_line");
  222. Map<String,Object> map=new HashMap<>();
  223. if(obline==0){
  224. map.put("code",item.get(1));
  225. map.put("time",DateUtil.now());
  226. map.put("station",item.get(0));
  227. //离线告警
  228. CacheUtils.put("offline",item.get(1),map);
  229. }else{
  230. CacheUtils.put("offline",item.get(1),map);
  231. }
  232. }catch(Exception e){
  233. log.error("快递柜信息解析错误");
  234. }
  235. try{
  236. Map<String,Integer> map=new HashMap<>();
  237. map.put("total",JSONUtil.parseObj(boxs).getJSONObject("data").getJSONObject("page").getInt("total_count"));
  238. JSONUtil.parseObj(boxs).getJSONObject("data").getJSONArray("list").forEach(item2->{
  239. if(((JSONObject)item2).getInt("box_use_status")==1){
  240. map.put("used",map.get("used")==null?1:map.get("used")+1);
  241. }else{
  242. map.put("unuse",map.get("unuse")==null?1:map.get("unuse")+1);
  243. }
  244. });
  245. if(map.get("used")==null) map.put("used",0);
  246. if(map.get("unuse")==null) map.put("unuse",0);
  247. CacheUtils.put(CABINET_INFO,item.get(1)+"_box",map);
  248. }catch(Exception e){
  249. log.error("快递柜box解析错误");
  250. }
  251. } catch (Exception e) {
  252. throw new RuntimeException(e);
  253. }
  254. });
  255. }
  256. }
  257. // @Scheduled(fixedRate = 2*60*60*1000)
  258. public void getExpressHistory() throws UnsupportedEncodingException {
  259. Map<String, JSONObject> cabinetMap2 = new HashMap<>();
  260. //获取所有快递柜的快递信息
  261. Map<String, JSONObject> cabinetMap = new HashMap<>();
  262. SysDictDataBo bo =new SysDictDataBo();
  263. bo.setDictType("tbl_sites");
  264. List<SysDictDataVo> list = SpringUtils.getBean(ISysDictDataService.class).selectDictDataList(bo);
  265. try {
  266. list.forEach(item->{
  267. if(StrUtil.isNotEmpty(item.getRemark())){
  268. JSONArray jsonArray = JSONUtil.parseArray(item.getRemark());
  269. jsonArray.forEach(item2->{
  270. if(((JSONObject)item2).getStr("type").equals("cabinet")){
  271. ((JSONObject) item2).put("location",item.getDictValue());
  272. cabinetMap.put( item.getDictLabel(),(JSONObject)item2);
  273. cabinetMap2.put(((JSONObject) item2).getStr("cabinetType"),(JSONObject)item2);
  274. }
  275. });
  276. }
  277. });
  278. }catch (Exception e){
  279. }
  280. //获取历史
  281. try {
  282. // TblBagBo bo1 =new TblBagBo();
  283. // bo1.getParams().put("remark","");
  284. // List<TblBagVo> bagList = SpringUtils.getBean(ITblBagService.class).queryList(bo1);
  285. // List<JSONObject> jsonObjectList1 = new ArrayList<>();
  286. // List<TblBagVo> sysd = new ArrayList<>();
  287. // if(bagList!=null && bagList.size()>0) {
  288. // bagList.forEach(item->{
  289. // if(cabinetMap2.containsKey(item.getDeviceId().toString())){
  290. // JSONObject json = new JSONObject();
  291. // json.put("deviceId",item.getDeviceId());
  292. // json.put("cpCode",item.getCpCode());
  293. // json.put("waybillNo",item.getWaybillNo());
  294. // json.put("scTime",item.getScTime());
  295. // json.put("scType",item.getScType());
  296. // jsonObjectList1.add(json);
  297. // sysd.add(item);
  298. // }
  299. //
  300. // });
  301. //
  302. // SPlatUtils.pushExpressInfo(jsonObjectList1);
  303. // if(sysd!=null && sysd.size()>0) {
  304. // sysd.forEach(item -> {
  305. // item.setRemark("已同步");
  306. // TblBagBo item1 = new TblBagBo();
  307. // BeanUtils.copyProperties(item, item1);
  308. // SpringUtils.getBean(ITblBagService.class).updateByBo(item1);
  309. // });
  310. // }
  311. // }
  312. Map<String,String> map = new HashMap<>();
  313. map.put("start_ctime ", DateUtil.format( DateUtil.offsetHour(DateUtil.date(),-2), "yyyy-MM-dd HH:mm:ss"));
  314. map.put("end_ctime ", DateUtil.format( DateUtil.date(), "yyyy-MM-dd HH:mm:ss"));
  315. map.put("page_size", "10000");
  316. String data = CabinetUtil.getExpressHistory(map);
  317. List<JSONObject> jsonObjectList = new ArrayList<>();
  318. JSONArray jsonArray = JSONUtil.parseObj(data).getJSONObject("data").getJSONArray("list");
  319. for (JSONObject jsonObject1 : jsonArray.toList(JSONObject.class)) {
  320. JSONObject json = new JSONObject();
  321. json.put("deviceId",jsonObject1.getStr("device_number"));
  322. json.put("cpCode",jsonObject1.getStr("product_type"));
  323. json.put("waybillNo",jsonObject1.getStr("order_number"));
  324. if(jsonObject1.getInt("used_status")==3||jsonObject1.getInt("used_status")==4){
  325. if(jsonObject1.getInt("used_status")==3){
  326. json.put("scTime",jsonObject1.getStr("save_end_time"));
  327. json.put("scType",1);
  328. }
  329. if(jsonObject1.getInt("used_status")==4){
  330. json.put("scType",2);
  331. json.put("scTime",jsonObject1.getStr("get_end_time"));
  332. }
  333. }
  334. jsonObjectList.add(json);
  335. }
  336. SPlatUtils.pushExpressInfo(jsonObjectList);
  337. }catch (Exception e){
  338. }
  339. if(cabinetMap!=null && cabinetMap.size()>0) {
  340. try {
  341. List<JSONObject> cabinetList = new ArrayList<>();
  342. cabinetMap.keySet().forEach(i->{
  343. JSONObject c = cabinetMap.get(i);
  344. if(c.getStr("location")!=null&&c.getStr("wdcode")!=null){
  345. c.put("deviceId", c.getStr("code"));
  346. c.put("stationId", c.getStr("wdcode"));
  347. c.put("deviceType", "cabinet");
  348. cabinetList.add(c);
  349. }
  350. } );
  351. SPlatUtils.SysDevice(cabinetList);
  352. }catch (Exception e){
  353. }
  354. }
  355. }
  356. @Scheduled(fixedRate = 5*60*1000)
  357. private void resetStationLed() throws UnsupportedEncodingException {
  358. //获取所有站点led
  359. SysDictDataBo bo =new SysDictDataBo();
  360. bo.setDictType("tbl_sites");
  361. List<SysDictDataVo> allstations = SpringUtils.getBean(ISysDictDataService.class).selectDictDataList(bo);
  362. for (SysDictDataVo station:allstations) {
  363. //获取led
  364. if(StringUtils.isNotEmpty(station.getRemark())) {
  365. List<JSONObject> devicedatas = JSONUtil.parseArray(station.getRemark()).toList(JSONObject.class);
  366. for (JSONObject i :devicedatas) {
  367. if(i.getStr("type").equals("led")){
  368. //查询缓存是否播放过
  369. Object time = RedisUtils.getCacheMapValue("station_led",station.getDictLabel());
  370. try {
  371. if (time != null && DateUtil.current() - Long.parseLong(time.toString()) < 1000 *60* 5) {
  372. continue;
  373. }
  374. }catch (Exception e){}
  375. MessageUtils.sendLed(i.getStr("code"),StringUtils.isNotEmpty( station.getCssClass())? station.getCssClass(): StringUtils.format("{}快梯柜",station.getDictLabel()));
  376. }
  377. }
  378. }
  379. }
  380. }
  381. @Scheduled(fixedRate = 60*60*1000)
  382. public R<TblExpressStaticsBo> getData() {
  383. try{
  384. String month = getLastMonth();
  385. TblExpressStaticsBo bo = new TblExpressStaticsBo();
  386. bo.setMonth(month);
  387. bo.setUserId(1L);
  388. bo.setData(getExpressDeliveryStatistics("19559316717",month));
  389. TblExpressStaticsBo query = new TblExpressStaticsBo();
  390. query.setMonth(month);
  391. query.setUserId(1L);
  392. List<TblExpressStaticsVo> list = SpringUtils.getBean(ITblExpressStaticsService.class).queryList(query);
  393. if(list.size() > 0){
  394. bo.setId(list.get(0).getId());
  395. SpringUtils.getBean(ITblExpressStaticsService.class).updateByBo(bo);
  396. }else{
  397. SpringUtils.getBean(ITblExpressStaticsService.class).insertByBo(bo);
  398. }
  399. return R.ok(bo);
  400. }catch (Exception e){
  401. return R.fail(e.toString());
  402. }
  403. }
  404. // 获取柜子信息
  405. public static String getCabinetInfo(String cabinetCode) throws Exception {
  406. int times = (int) (DateUtil.date().getTime()/1000);
  407. String str_sign = appid + "=" + times + "=" + appid;
  408. str_sign = encrypt(str_sign);
  409. String result3= HttpRequest.post(hosts+"/kd/api/v2/action/device_info/").body(JSON.toJSONString(Map.of("device_number",cabinetCode)))
  410. .addHeaders(Map.of("timestamp",times+"","Content-Type","application/json","appid",appid,"sign",str_sign))
  411. .execute().body();
  412. return result3;
  413. }
  414. // 获取柜子统计
  415. public static String getCabinetStatistics(String cabinetCode,String startTime,String endTime) throws Exception {
  416. int times = (int) (DateUtil.date().getTime()/1000);
  417. String str_sign = appid + "=" + times + "=" + appid;
  418. str_sign = encrypt(str_sign);
  419. String result3= HttpRequest.post(hosts + "/kd/api/v2/action/deliver_statistics/").body(JSON.toJSONString(Map.of("device_number",cabinetCode,"strat_time",startTime,"end_time",endTime)))
  420. .addHeaders(Map.of("timestamp",times+"","Content-Type","application/json","appid",appid,"sign",str_sign))
  421. .execute().body();
  422. return result3;
  423. }
  424. //或者快递柜子使用情况
  425. // public static String getBoxUs(String courierMobile,String month) throws Exception {
  426. // int times = (int) (DateUtil.date().getTime()/1000);
  427. // String str_sign = appid + "=" + times + "=" + appid;
  428. // str_sign = encrypt(str_sign);
  429. // String result3= HttpRequest.post(hosts + "/api/v2/search/express_delivery_statistics/").body(JSON.toJSONString(Map.of("courier_mobile",courierMobile,"market_id","2638","search_month",month)))
  430. // .addHeaders(Map.of("timestamp",times+"","Content-Type","application/json","appid",appid,"sign",str_sign))
  431. // .execute().body();
  432. // return result3;
  433. // }
  434. //或者快递柜使用情况
  435. public static String getExpressDeliveryStatistics(String courierMobile,String month) throws Exception {
  436. int times = (int) (DateUtil.date().getTime()/1000);
  437. String str_sign = appid + "=" + times + "=" + appid;
  438. str_sign = encrypt(str_sign);
  439. log.info(JSON.toJSONString(Map.of("timestamp",times+"","Content-Type","application/json","appid",appid,"sign",str_sign)));
  440. log.info(JSON.toJSONString(Map.of("courier_mobile",courierMobile,"market_id",3219,"search_month",month)));
  441. String result3= HttpRequest.post(hosts + "/kd/api/v2/search/express_delivery_statistics/").body(JSON.toJSONString(Map.of("courier_mobile",courierMobile,"market_id",3219,"search_month",month)))
  442. .addHeaders(Map.of("timestamp",times+"","Content-Type","application/json","appid",appid,"sign",str_sign))
  443. .execute().body();
  444. return result3;
  445. }
  446. public static String getLastMonth() {
  447. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM");
  448. Date date = new Date();
  449. Calendar calendar = Calendar.getInstance();
  450. // 设置为当前时间
  451. calendar.setTime(date);
  452. calendar.add(Calendar.DAY_OF_MONTH,-1);
  453. // 设置为上一个月
  454. //calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - 1);
  455. date = calendar.getTime();
  456. return format.format(date);
  457. }
  458. // public static void main(String args[]) throws Exception {
  459. // log.info(getExpressDeliveryStatistics("19559316717","2025-01"));
  460. // }
  461. // 获取柜子盒子
  462. public static String getCabinetBoxs(String cabinetCode) throws Exception {
  463. int times = (int) (DateUtil.date().getTime()/1000);
  464. String str_sign = appid + "=" + times + "=" + appid;
  465. str_sign = encrypt(str_sign);
  466. String result3= HttpRequest.post(hosts + "/kd/api/v2/action/box_info_list/").body(JSON.toJSONString(Map.of("device_number",cabinetCode,"page_size",1000)))
  467. .addHeaders(Map.of("timestamp",times+"","Content-Type","application/json","appid",appid,"sign",str_sign))
  468. .execute().body();
  469. return result3;
  470. }
  471. // 开柜
  472. public static String openCabinetBoxs(String cabinetCode,String lookAddr) throws Exception {
  473. int times = (int) (DateUtil.date().getTime()/1000);
  474. String str_sign = appid + "=" + times + "=" + appid;
  475. str_sign = encrypt(str_sign);
  476. String result3= HttpRequest.post(hosts + "/kd/api/v2/action/open_box/").body(JSON.toJSONString(Map.of("device_number",cabinetCode,"lock_address",lookAddr)))
  477. .addHeaders(Map.of("timestamp",times+"","Content-Type","application/json","appid",appid,"sign",str_sign))
  478. .execute().body();
  479. return result3;
  480. }
  481. // 开所有柜
  482. public static String openCabinetBoxAll(String cabinetCode) throws Exception {
  483. int times = (int) (DateUtil.date().getTime()/1000);
  484. String str_sign = appid + "=" + times + "=" + appid;
  485. str_sign = encrypt(str_sign);
  486. String result3= HttpRequest.post(hosts + "/kd/api/v2/action/open_box_all/").body(JSON.toJSONString(Map.of("device_number",cabinetCode)))
  487. .addHeaders(Map.of("timestamp",times+"","Content-Type","application/json","appid",appid,"sign",str_sign))
  488. .execute().body();
  489. return result3;
  490. }
  491. //清理格子(不开启)
  492. public static String clearCabinetBox(String cabinetCode,String boxUUId) throws Exception {
  493. int times = (int) (DateUtil.date().getTime()/1000);
  494. String str_sign = appid + "=" + times + "=" + appid;
  495. str_sign = encrypt(str_sign);
  496. String result3= HttpRequest.post(hosts + "/kd/api/v2/action/clear_box/").body(JSON.toJSONString(Map.of("device_number",cabinetCode,"box_uid",boxUUId)))
  497. .addHeaders(Map.of("timestamp",times+"","Content-Type","application/json","appid",appid,"sign",str_sign))
  498. .execute().body();
  499. return result3;
  500. }
  501. //清理格子(开启)
  502. public static String clearCabinetBoxOpen(String cabinetCode,String boxUUId) throws Exception {
  503. int times = (int) (DateUtil.date().getTime()/1000);
  504. String str_sign = appid + "=" + times + "=" + appid;
  505. str_sign = encrypt(str_sign);
  506. String result3= HttpRequest.post(hosts + "/kd/api/v2/action/clear_box_open/").body(JSON.toJSONString(Map.of("device_number",cabinetCode,"box_uid",boxUUId)))
  507. .addHeaders(Map.of("timestamp",times+"","Content-Type","application/json","appid",appid,"sign",str_sign))
  508. .execute().body();
  509. return result3;
  510. }
  511. // 获取取件码
  512. public static String getQJM(String phone) throws Exception {
  513. int times = (int) (DateUtil.date().getTime()/1000);
  514. String str_sign = appid + "=" + times + "=" + appid;
  515. str_sign = encrypt(str_sign);
  516. String result3= HttpRequest.post(hosts + "/kd/api/v2/query/pick_code_by_user_mobile/").body(JSON.toJSONString(Map.of("get_user_mobile",phone)))
  517. .addHeaders(Map.of("timestamp",times+"","Content-Type","application/json","appid",appid,"sign",str_sign))
  518. .execute().body();
  519. return result3;
  520. }
  521. //获取快递历史信息
  522. public static String getExpressHistory(Map<String,String> body) throws Exception{
  523. int times = (int) (DateUtil.date().getTime()/1000);
  524. String str_sign = appid + "=" + times + "=" + appid;
  525. str_sign = encrypt(str_sign);
  526. String result3= HttpRequest.post(hosts + "/kd/api/v2/search/record_query/").body(JSON.toJSONString(body))
  527. .addHeaders(Map.of("timestamp",times+"","Content-Type","application/json","appid",appid,"sign",str_sign)).execute().body();
  528. return result3;
  529. }
  530. @Override
  531. public ProcessResult process(TaskContext taskContext) throws Exception {
  532. getExpressHistory();
  533. return new ProcessResult(true, "定时任务执行成功");
  534. }
  535. }