xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/controller/pc/StatisticController.java
@@ -5,10 +5,7 @@ import cn.exrick.xboot.core.common.utils.ResultUtil; import cn.exrick.xboot.core.common.vo.PageVo; import cn.exrick.xboot.core.common.vo.Result; import cn.exrick.xboot.your.entity.Area; import cn.exrick.xboot.your.entity.Car; import cn.exrick.xboot.your.entity.EventLog; import cn.exrick.xboot.your.entity.OrderTask; import cn.exrick.xboot.your.entity.*; import cn.exrick.xboot.your.service.*; import cn.exrick.xboot.your.util.HaiKangPost; import cn.hutool.core.date.DateUtil; @@ -106,7 +103,23 @@ @RequestMapping(value = "/getAnalysis", method = RequestMethod.GET) @ApiOperation(value = "获取配送分析") public Result<Object> getAnalysis() { List<Area> list = iAreaService.list(); List<Area> list = iAreaService.list2(); for(Area area:list){ double sum = 0; int flag = 0; for(AreaSection areaSection: area.getChildren()){ sum+=areaSection.getStability(); flag++; } if(flag>0){ double v = sum / flag; area.setVariance(trans2(v)); } } return new ResultUtil<Object>().setData(list); } public double trans2(double v2){ return (double) Math.round(v2 * 100) / 100; } } xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/entity/Alarm.java
@@ -51,4 +51,6 @@ @ApiModelProperty(value = "是否被调用 0:否 1:是") private int flag; @ApiModelProperty(value = "车机报警id") private String alarmId; } xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/entity/Area.java
@@ -15,6 +15,7 @@ import javax.persistence.Table; import javax.persistence.Transient; import java.util.Date; import java.util.List; /** * @author Exrick @@ -50,7 +51,12 @@ @Transient @TableField(exist = false) @ApiModelProperty(value = "总体方差") private int variance; private double variance; @Transient @TableField(exist = false) @ApiModelProperty(value = "分段对象") private List<AreaSection> children; @Transient @TableField(exist = false) xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/entity/AreaSection.java
@@ -50,6 +50,6 @@ private double maxTime; @ApiModelProperty(value = "稳定性分析") private int stability; private double stability; } xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/mapper/AreaMapper.java
@@ -7,10 +7,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.Constants; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Result; import org.apache.ibatis.annotations.Results; import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.*; import org.apache.ibatis.type.JdbcType; import java.util.List; @@ -24,4 +21,8 @@ @Select("SELECT a.*,b.nickname as temp FROM t_area a LEFT JOIN t_user b ON a.user_id=b.id ${ew.customSqlSegment} ") @Results({@Result(column="temp", property="nickName", jdbcType = JdbcType.VARCHAR)}) IPage<Area> page2(Page initMpPage, @Param(Constants.WRAPPER) QueryWrapper<Area> wrapper); @Select("SELECT * FROM t_area") @Results({@Result(column="id", property="children", many = @Many(select = "cn.exrick.xboot.your.mapper.AreaSectionMapper.getListByParentId"))}) List<Area> list2(); } xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/mapper/AreaSectionMapper.java
@@ -2,6 +2,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import cn.exrick.xboot.your.entity.AreaSection; import org.apache.ibatis.annotations.Select; import java.util.List; @@ -11,4 +12,6 @@ */ public interface AreaSectionMapper extends BaseMapper<AreaSection> { @Select("select * from t_area_ection where area_id=#{id}") List<AreaSection> getListByParentId(String id); } xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/schedulings/StatisticPc2ScheduleImpl.java
@@ -14,6 +14,8 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; //大屏配送分析 @@ -32,7 +34,7 @@ @Autowired private IOrderTaskService iOrderTaskService; @Scheduled(cron="0 0 * * * ?")//每小时执行一次 @Scheduled(cron="0 * * * * ?")//每小时执行一次 public void execute(){ List<Area> list = iAreaService.list(); for(Area area:list){ @@ -59,12 +61,50 @@ listTime.add(orderTask.getTime()); } Collections.sort(listTime); double v = (sum * 1.0) / (1000 * 60 * 60) / listTime.size(); areaSection.setAvgTime((double) Math.round(v * 10) / 10); if(listTime.size()>0){ double v1 = (listTime.get(0) * 1.0) / (1000 * 60 * 60); areaSection.setMinTime((double) Math.round(v1 * 10) / 10); double v2 = (listTime.get(listTime.size()-1) * 1.0) / (1000 * 60 * 60); areaSection.setMaxTime((double) Math.round(v2 * 10) / 10); } double variance = Variance(listTime); areaSection.setStability(variance); iAreaSectionService.saveOrUpdate(areaSection); } } public double Variance(List<Integer> x) { List<Double> y = new ArrayList<>(); for(Integer s:x){ y.add(trans((s*1.0)/(3600*1000))); } int m = x.size(); double sum = 0; for (int i = 0; i < m; i++) { sum += y.get(i); } double dAve = sum / m; double dVar = 0; for (int i = 0; i < m; i++) { dVar += (y.get(i) - dAve) * (y.get(i) - dAve); } double v = dVar / m; return trans2(v); } public double trans(double v2){ return (double) Math.round(v2 * 10) / 10; } public double trans2(double v2){ return (double) Math.round(v2 * 100) / 100; } } xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/service/IAreaSectionService.java
@@ -11,4 +11,6 @@ */ public interface IAreaSectionService extends IService<AreaSection> { List<AreaSection> getListByParentId(String id); } xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/service/IAreaService.java
@@ -14,4 +14,6 @@ */ public interface IAreaService extends IService<Area> { IPage<Area> page2(Page initMpPage, QueryWrapper<Area> wrapper); List<Area> list2(); } xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/serviceimpl/IAreaSectionServiceImpl.java
@@ -23,4 +23,9 @@ @Autowired private AreaSectionMapper areaSectionMapper; @Override public List<AreaSection> getListByParentId(String areaId) { return areaSectionMapper.getListByParentId(areaId); } } xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/serviceimpl/IAreaServiceImpl.java
@@ -31,4 +31,9 @@ public IPage<Area> page2(Page initMpPage, QueryWrapper<Area> wrapper) { return areaMapper.page2(initMpPage,wrapper); } @Override public List<Area> list2() { return areaMapper.list2(); } } xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/util/ApplicationRunnerImpl.java
New file @@ -0,0 +1,32 @@ package cn.exrick.xboot.your.util; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; import org.springframework.stereotype.Component; @Component public class ApplicationRunnerImpl implements ApplicationRunner { @Autowired private HaiKangPost haiKangPost; @Autowired private MQTT mqtt; @Override public void run(ApplicationArguments args) throws Exception { String topicInfo = haiKangPost.getTopicInfo(); JSONObject jsonObject = JSONUtil.parseObj(topicInfo); if(jsonObject.get("data")!=null){ String data = jsonObject.get("data").toString(); JSONObject jsonObject2 = JSONUtil.parseObj(data); String clientId = jsonObject2.get("clientId").toString(); String userName = jsonObject2.get("userName").toString(); String password = jsonObject2.get("password").toString(); mqtt.event(clientId,userName,password); } } } xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/util/ClientMQTT.java
File was deleted xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/util/HaiKangPost.java
@@ -164,16 +164,17 @@ public static void main(String[] args) { //getTopicInfo(); FindHistoryGpsRequest findHistoryGpsRequest = new FindHistoryGpsRequest(); findHistoryGpsRequest.setVehicleIndexCode("b279d865eabe497db465eb2f4d2cc87d"); findHistoryGpsRequest.setPageNo(1); findHistoryGpsRequest.setPageSize(20); findHistoryGpsRequest.setBeginTime("2021-11-25T03:10:01.000+08:00"); findHistoryGpsRequest.setEndTime("2021-11-25T12:10:01.000+08:00"); HaiKangPost haiKangPost = new HaiKangPost(); System.out.println(haiKangPost.findHistoryGps(findHistoryGpsRequest)); haiKangPost.getTopicInfo(); // FindHistoryGpsRequest findHistoryGpsRequest = new FindHistoryGpsRequest(); // findHistoryGpsRequest.setVehicleIndexCode("b279d865eabe497db465eb2f4d2cc87d"); // findHistoryGpsRequest.setPageNo(1); // findHistoryGpsRequest.setPageSize(20); // findHistoryGpsRequest.setBeginTime("2021-11-25T03:10:01.000+08:00"); // findHistoryGpsRequest.setEndTime("2021-11-25T12:10:01.000+08:00"); // HaiKangPost haiKangPost = new HaiKangPost(); // System.out.println(haiKangPost.findHistoryGps(findHistoryGpsRequest)); // String code[] = {"b279d865eabe497db465eb2f4d2cc87d"}; // System.out.println(findLatestGps(code)); xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/util/MQTT.java
New file @@ -0,0 +1,137 @@ package cn.exrick.xboot.your.util; import cn.exrick.xboot.your.entity.Alarm; import cn.exrick.xboot.your.entity.Car; import cn.exrick.xboot.your.service.IAlarmService; import cn.exrick.xboot.your.service.ICarService; import cn.hutool.json.JSONArray; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import org.eclipse.paho.client.mqttv3.*; import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @Component public class MQTT { @Autowired private IAlarmService iAlarmService; @Autowired private ICarService iCarService; public static void main(String[] args) { MQTT mqtt = new MQTT(); mqtt.event("28156526","artemis_28156526_AQ4ZLCRT","X34YB59A"); } public void event(String clientid,String userName,String passWord){ String HOST = "tcp://111.63.178.115:1883"; String TOPIC = "artemis/event_msa_alarm/5201154049/admin"; int qos = 1; // String clientid = "28156526"; // String userName = "artemis_28156526_PSDARORD"; // String passWord = "T48B7XI6"; try { // host为主机名,test为clientid即连接MQTT的客户端ID,一般以客户端唯一标识符表示,MemoryPersistence设置clientid的保存形式,默认为以内存保存 MqttClient client = new MqttClient(HOST, clientid, new MemoryPersistence()); // MQTT的连接设置 MqttConnectOptions options = new MqttConnectOptions(); // 设置是否清空session,这里如果设置为false表示服务器会保留客户端的连接记录,这里设置为true表示每次连接到服务器都以新的身份连接 options.setCleanSession(true); // 设置连接的用户名 options.setUserName(userName); // 设置连接的密码 options.setPassword(passWord.toCharArray()); // 设置超时时间 单位为秒 options.setConnectionTimeout(10); // 设置会话心跳时间 单位为秒 服务器会每隔1.5*20秒的时间向客户端发送个消息判断客户端是否在线,但这个方法并没有重连的机制 options.setKeepAliveInterval(20); // 设置回调函数 client.setCallback(new MqttCallback() { public void connectionLost(Throwable cause) { System.out.println("connectionLost"); } public void deliveryComplete(IMqttDeliveryToken token) { System.out.println("deliveryComplete---------"+ token.isComplete()); } public void messageArrived(String topic, MqttMessage message) throws Exception { // System.out.println("topic:"+topic); // System.out.println("Qos:"+message.getQos()); // System.out.println("message content:"+new String(message.getPayload())); String s = new String(message.getPayload()); if(!s.equals("close")){ JSONObject jsonObject = JSONUtil.parseObj(s); if(jsonObject.get("params")!=null){ String params = jsonObject.get("params").toString(); if(JSONUtil.parseObj(params)!=null){ String events = JSONUtil.parseObj(params).get("events").toString(); JSONArray objects = JSONUtil.parseArray(events); for(int i=0;i<objects.size();i++){ String s1 = objects.get(i).toString(); JSONObject jsonObject1 = JSONUtil.parseObj(s1); String data = jsonObject1.get("data").toString(); JSONObject jsonObject2 = JSONUtil.parseObj(data); System.out.println(jsonObject2.get("alarmId"));//报警id System.out.println(jsonObject2.get("vehicleIndexCode"));//车辆code System.out.println(jsonObject2.get("eventType"));//报警类型 //未系安全带:132376 //抽烟:132375 //接打电话:132374 //疲劳驾驶:132371 String eventType = jsonObject2.get("eventType").toString(); String vehicleIndexCode = jsonObject2.get("vehicleIndexCode").toString(); String alarmId = jsonObject2.get("alarmId").toString(); Alarm alarm = new Alarm(); if(eventType.equals("132371")){ alarm.setType(1); alarm.setValue("疲劳驾驶"); }else if(eventType.equals("132374")){ alarm.setType(2); alarm.setValue("接打电话"); }else if(eventType.equals("132376")){ alarm.setType(3); alarm.setValue("未系安全带"); }else if(eventType.equals("132375")){ alarm.setType(4); alarm.setValue("抽烟"); }else{ return; } QueryWrapper<Car> wrapper = new QueryWrapper<Car>(); wrapper.eq("code",vehicleIndexCode); Car car = iCarService.getOne(wrapper); if(car==null){ return; } alarm.setAlarmId(alarmId); alarm.setCarId(car.getId()); alarm.setCarNo(car.getCarNo()); alarm.setCarUserId(car.getUserId()); alarm.setFollowUserId(car.getFollowUserId()); iAlarmService.saveOrUpdate(alarm); } } } } } }); client.connect(options); //订阅消息 client.subscribe(TOPIC, qos); } catch (Exception e) { e.printStackTrace(); } } } xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/util/PushCallback.java
File was deleted xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/util/Recv.java
File was deleted