|
|
@@ -1,13 +1,39 @@
|
|
|
package org.dromara.util;
|
|
|
|
|
|
+import cn.hutool.core.date.DatePattern;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.http.HttpRequest;
|
|
|
+import cn.hutool.json.JSONArray;
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import org.apache.xmlbeans.impl.xb.xsdschema.Public;
|
|
|
+import org.dromara.common.core.utils.SpringUtils;
|
|
|
+import org.dromara.common.core.utils.StringUtils;
|
|
|
+import org.dromara.common.redis.utils.CacheUtils;
|
|
|
+import org.dromara.common.redis.utils.RedisUtils;
|
|
|
+import org.dromara.system.domain.GpsData;
|
|
|
+import org.dromara.system.domain.TblCarInfo;
|
|
|
+import org.dromara.system.domain.bo.SysDictDataBo;
|
|
|
+import org.dromara.system.domain.bo.TblCarInfoBo;
|
|
|
+import org.dromara.system.domain.vo.SysDictDataVo;
|
|
|
+import org.dromara.system.domain.vo.TblCarInfoVo;
|
|
|
+import org.dromara.system.service.ISysDictDataService;
|
|
|
+import org.dromara.system.service.impl.TblCarInfoServiceImpl;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.crypto.Cipher;
|
|
|
import java.security.Key;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
+@Component
|
|
|
public class CabinetUtil {
|
|
|
|
|
|
private final static String appid = "bw_open_express_A8C848769E5C04E0";
|
|
|
@@ -15,6 +41,9 @@ public class CabinetUtil {
|
|
|
|
|
|
private final static String hosts = "https://open.bestwond.com";
|
|
|
|
|
|
+ public final static String CABINET_INFO = "cabinet_info";
|
|
|
+ public final static String CABINET_BOXS = "cabinet_boxs";
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(CabinetUtil.class);
|
|
|
|
|
|
private static String byteArr2HexStr(byte[] arrB) throws Exception {
|
|
|
int iLen = arrB.length;
|
|
|
@@ -62,6 +91,119 @@ public class CabinetUtil {
|
|
|
// String text = SpringUtils.getBean(ISysConfigService.class).selectConfigByKey("sys.cabinet.account");
|
|
|
//
|
|
|
// }
|
|
|
+ @Scheduled(fixedRate = 5*60*1000)
|
|
|
+ private void getGpsList(){
|
|
|
+ List<TblCarInfoVo> carInfoVos = SpringUtils.getBean(TblCarInfoServiceImpl.class).queryList(new TblCarInfoBo());
|
|
|
+ for (TblCarInfoVo car : carInfoVos) {
|
|
|
+ if(StrUtil.isNotEmpty(car.getDeviceInfos())){
|
|
|
+ JSONUtil.parseArray(car.getDeviceInfos()).forEach(item->{
|
|
|
+ JSONObject c = (JSONObject)item;
|
|
|
+ if(c.getStr("type").equals("gps")){
|
|
|
+ GpsData gpsData = RedisUtils.getCacheObject(StringUtils.format("gps_{}", c.getStr("code")));
|
|
|
+ //1小时就离线
|
|
|
+ Map<String,Object> map=new HashMap<>();
|
|
|
+ if(gpsData.getTs()==null){
|
|
|
+ gpsData.setTs(DateUtil.date());
|
|
|
+ }
|
|
|
+
|
|
|
+ if(DateUtil.current() - gpsData.getTs().getTime()> 1000*60*60){
|
|
|
+ map.put("code",c.getStr("code"));
|
|
|
+ map.put("time", DatePattern.NORM_DATETIME_FORMAT.format(gpsData.getTs()));
|
|
|
+ map.put("station",car.getCarNum());
|
|
|
+ CacheUtils.put("offline",c.getStr("code"),map);
|
|
|
+ }else{
|
|
|
+ CacheUtils.put("offline",c.getStr("code"),map);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Scheduled(fixedRate = 5*60*1000)
|
|
|
+ private void getList(){
|
|
|
+ //获取所有gps 判断是否离线
|
|
|
+ List<List<String>> cabinetList = new ArrayList<>();
|
|
|
+ SysDictDataBo bo =new SysDictDataBo();
|
|
|
+ bo.setDictType("tbl_sites");
|
|
|
+ List<SysDictDataVo> list = SpringUtils.getBean(ISysDictDataService.class).selectDictDataList(bo);
|
|
|
+ try {
|
|
|
+ list.forEach(item->{
|
|
|
+ if(StrUtil.isNotEmpty(item.getRemark())){
|
|
|
+ JSONArray jsonArray = JSONUtil.parseArray(item.getRemark());
|
|
|
+ jsonArray.forEach(item2->{
|
|
|
+ if(((JSONObject)item2).getStr("type").equals("cabinet")){
|
|
|
+ cabinetList.add( List.of(item.getDictLabel(),((JSONObject)item2).getStr("code")));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }catch (Exception e){
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if(cabinetList.size()>0){
|
|
|
+ cabinetList.forEach(item->{
|
|
|
+ try {
|
|
|
+ Thread.sleep(1000);
|
|
|
+ String details= CabinetUtil.getCabinetInfo(item.get(1));
|
|
|
+ CacheUtils.put(CABINET_INFO,item.get(1),details);
|
|
|
+ log.info(StrUtil.format("获取到柜子信息:{},{}",item.get(1),details));
|
|
|
+ Thread.sleep(1000);
|
|
|
+ //获取柜子状态
|
|
|
+ String boxs= CabinetUtil.getCabinetBoxs(item.get(1));
|
|
|
+ CacheUtils.put(CABINET_BOXS,item.get(1),boxs);
|
|
|
+ log.info(StrUtil.format("获取到柜子箱子信息:{},{}",item.get(1),boxs));
|
|
|
+
|
|
|
+
|
|
|
+ try{
|
|
|
+ Integer obline = JSONUtil.parseObj(details).getJSONObject("data").getInt("device_line");
|
|
|
+ Map<String,Object> map=new HashMap<>();
|
|
|
+ if(obline==0){
|
|
|
+ map.put("code",item.get(1));
|
|
|
+ map.put("time",DateUtil.now());
|
|
|
+ map.put("station",item.get(0));
|
|
|
+ //离线告警
|
|
|
+ CacheUtils.put("offline",item.get(1),map);
|
|
|
+ }else{
|
|
|
+ CacheUtils.put("offline",item.get(1),map);
|
|
|
+ }
|
|
|
+ }catch(Exception e){
|
|
|
+ log.error("快递柜信息解析错误");
|
|
|
+ }
|
|
|
+
|
|
|
+ try{
|
|
|
+ Map<String,Integer> map=new HashMap<>();
|
|
|
+ map.put("total",JSONUtil.parseObj(boxs).getJSONObject("data").getJSONObject("page").getInt("total_count"));
|
|
|
+ JSONUtil.parseObj(boxs).getJSONObject("data").getJSONArray("list").forEach(item2->{
|
|
|
+ if(((JSONObject)item2).getInt("box_use_status")==1){
|
|
|
+ map.put("used",map.get("used")==null?1:map.get("used")+1);
|
|
|
+ }else{
|
|
|
+ map.put("unuse",map.get("unuse")==null?1:map.get("unuse")+1);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if(map.get("used")==null) map.put("used",0);
|
|
|
+ if(map.get("unuse")==null) map.put("unuse",0);
|
|
|
+ CacheUtils.put(CABINET_INFO,item.get(1)+"_box",map);
|
|
|
+ }catch(Exception e){
|
|
|
+ log.error("快递柜box解析错误");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
// 获取柜子信息
|
|
|
public static String getCabinetInfo(String cabinetCode) throws Exception {
|