xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/controller/CarLocationController.java
New file @@ -0,0 +1,77 @@ package cn.exrick.xboot.your.controller; import cn.exrick.xboot.core.common.utils.PageUtil; 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.CarLocation; import cn.exrick.xboot.your.service.ICarLocationService; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import org.springframework.transaction.annotation.Transactional; import java.util.List; /** * @author whj */ @Slf4j @RestController @Api(tags = "车辆定位表管理接口") @RequestMapping("/xboot/carLocation") @Transactional public class CarLocationController { @Autowired private ICarLocationService iCarLocationService; @RequestMapping(value = "/get/{id}", method = RequestMethod.GET) @ApiOperation(value = "通过id获取") public Result<CarLocation> get(@PathVariable String id) { CarLocation carLocation = iCarLocationService.getById(id); return new ResultUtil<CarLocation>().setData(carLocation); } @RequestMapping(value = "/getAll", method = RequestMethod.GET) @ApiOperation(value = "获取全部数据") public Result<List<CarLocation>> getAll() { List<CarLocation> list = iCarLocationService.list(); return new ResultUtil<List<CarLocation>>().setData(list); } @RequestMapping(value = "/getByPage", method = RequestMethod.GET) @ApiOperation(value = "分页获取") public Result<IPage<CarLocation>> getByPage(PageVo page) { IPage<CarLocation> data = iCarLocationService.page(PageUtil.initMpPage(page)); return new ResultUtil<IPage<CarLocation>>().setData(data); } @RequestMapping(value = "/insertOrUpdate", method = RequestMethod.POST) @ApiOperation(value = "编辑或更新数据") public Result<CarLocation> saveOrUpdate(CarLocation carLocation) { if (iCarLocationService.saveOrUpdate(carLocation)) { return new ResultUtil<CarLocation>().setData(carLocation); } return new ResultUtil<CarLocation>().setErrorMsg("操作失败"); } @RequestMapping(value = "/delByIds", method = RequestMethod.POST) @ApiOperation(value = "批量通过id删除") public Result<Object> delAllByIds(@RequestParam String[] ids) { for (String id : ids) { iCarLocationService.removeById(id); } return ResultUtil.success("批量通过id删除数据成功"); } } xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/controller/DrivingRecordController.java
@@ -97,6 +97,7 @@ DrivingRecord drivingRecord = iDrivingRecordService.getOne(wrapper); if(drivingRecord==null){ drivingRecord = new DrivingRecord(); drivingRecord.setCarId(carId); } drivingRecord.setMileage(mileage); drivingRecord.setInTime(DateUtil.parseDate(inDate)); xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/controller/face/FaceImgController.java
@@ -86,9 +86,13 @@ return; } String format = DateUtil.format(new Date(),"yyyy-MM-dd HH:mm"); Date date1 = new Date(); long time = date1.getTime()-2*60*1000; Date date = new Date(time); String format1 = DateUtil.format(date,"yyyy-MM-dd HH:mm:ss"); String format2 = DateUtil.format(date1,"yyyy-MM-dd HH:mm:ss"); QueryWrapper<Alarm> awrapper = new QueryWrapper<>(); awrapper.between("create_time",format+"00",format+"59"); awrapper.between("create_time",format1,format2); awrapper.eq("car_no",one.getCarNo()); awrapper.eq("type",5); List<Alarm> list = iAlarmService.list(awrapper); xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/entity/CarLocation.java
New file @@ -0,0 +1,52 @@ package cn.exrick.xboot.your.entity; import cn.exrick.xboot.core.base.XbootBaseEntity; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import org.hibernate.annotations.DynamicInsert; import org.hibernate.annotations.DynamicUpdate; import org.springframework.format.annotation.DateTimeFormat; import javax.persistence.Entity; import javax.persistence.Table; import javax.persistence.Transient; import java.util.Date; /** * @author Exrick */ @Data @Entity @DynamicInsert @DynamicUpdate @Table(name = "t_car_location") @TableName("t_car_location") @ApiModel(value = "车辆定位表") public class CarLocation extends XbootBaseEntity { private static final long serialVersionUID = 1L; @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss") @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @ApiModelProperty(value = "定位时间") private Date locationTime; @ApiModelProperty(value = "牌照") private String carNo; @ApiModelProperty(value = "code") private String code; @ApiModelProperty(value = "经度") private String lng; @ApiModelProperty(value = "纬度") private String lat; @ApiModelProperty(value = "速度") private int speed; } xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/mapper/CarLocationMapper.java
New file @@ -0,0 +1,14 @@ package cn.exrick.xboot.your.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import cn.exrick.xboot.your.entity.CarLocation; import java.util.List; /** * 车辆定位表数据处理层 * @author whj */ public interface CarLocationMapper extends BaseMapper<CarLocation> { } xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/schedulings/CarLocationScheduleImpl.java
New file @@ -0,0 +1,74 @@ //package cn.exrick.xboot.your.schedulings; //import cn.exrick.xboot.your.entity.Car; //import cn.exrick.xboot.your.entity.CarLocation; //import cn.exrick.xboot.your.service.*; //import cn.exrick.xboot.your.util.HaiKangPost; //import cn.hutool.core.date.DateUtil; //import cn.hutool.core.util.StrUtil; //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.springframework.beans.factory.annotation.Autowired; //import org.springframework.scheduling.annotation.Scheduled; //import org.springframework.stereotype.Component; // //import java.util.ArrayList; //import java.util.List; // ////车辆定位统计 //@Component //public class CarLocationScheduleImpl { // // @Autowired // private ICarService iCarService; // @Autowired // private HaiKangPost haiKangPost; // @Autowired // private ICarLocationService iCarLocationService; // // @Scheduled(cron="0 0/10 5,20 * * ? ")//十分钟一次 // public void execute(){ // List<Car> list = iCarService.list(); // List<String> list2 = new ArrayList<>(); // // for(int i=0;i<list.size();i++){ // if(!StrUtil.isEmpty(list.get(i).getCode())){ // list2.add(list.get(i).getCode()); // } // } // // String codes[] = new String[list2.size()]; // for(int i=0;i<list2.size();i++){ // codes[i] = list2.get(i); // } // String latestGps = haiKangPost.findLatestGps(codes); // JSONArray objects = JSONUtil.parseArray(latestGps); // for(int i=0;i<objects.size();i++){ // String s = objects.get(i).toString(); // JSONObject jsonObject = JSONUtil.parseObj(s); // String time = jsonObject.getStr("time"); // String time2 = time.substring(0,10)+" "+time.substring(11,16)+":00"; // String carNo = jsonObject.getStr("carNo"); // QueryWrapper<CarLocation> wrapper = new QueryWrapper<>(); // wrapper.eq("location_time",time2); // wrapper.eq("car_no",carNo); // int count = iCarLocationService.count(wrapper); // if(count>0){ // continue; // } // Integer speed = jsonObject.getInt("speed")/10000; // String lng = String.valueOf(jsonObject.getInt("longitude")/360000); // String lat = String.valueOf(jsonObject.getInt("latitude")/360000); // String code = jsonObject.getStr("vehicleIndexCode"); // CarLocation obj = new CarLocation(); // obj.setCarNo(carNo); // obj.setCode(code); // obj.setLat(lat); // obj.setLng(lng); // obj.setLocationTime(DateUtil.parse(time2,"yyyy-MM-dd HH:mm:ss")); // obj.setSpeed(speed); // iCarLocationService.save(obj); // } // } //} xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/schedulings/OrderDealScheduleImpl.java
@@ -1,71 +1,71 @@ //package cn.exrick.xboot.your.schedulings; //import cn.exrick.xboot.your.entity.*; //import cn.exrick.xboot.your.service.*; //import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; //import org.springframework.beans.factory.annotation.Autowired; //import org.springframework.scheduling.annotation.Scheduled; //import org.springframework.stereotype.Component; // //import java.text.SimpleDateFormat; //import java.util.Calendar; //import java.util.Date; //import java.util.List; // ////删除历史数据 //@Component //public class OrderDealScheduleImpl { // // @Autowired // private IOrderTaskOriginalService iOrderTaskOriginalService; // // @Autowired // private IOrderDetailOriginalService iOrderDetailOriginalService; // // @Autowired // private IOrderTaskService iOrderTaskService; // // @Autowired // private IOrderDetailService iOrderDetailService; // // @Autowired // private IDuoZhengService iDuoZhengService; // // @Scheduled(cron="0 0 21 * * ?")//每晚下午9点执行 // //@Scheduled(cron="0 33 17 * * ?")//测试 // public void execute(){ // String day = getDay(-15); // QueryWrapper<OrderTask> wrapper = new QueryWrapper<>(); // wrapper.lt("send_Date",day); // iOrderTaskService.remove(wrapper); // // QueryWrapper<OrderDetail> wrapper2 = new QueryWrapper<>(); // wrapper2.lt("create_time",day+" 00:00:00"); // iOrderDetailService.remove(wrapper2); // // String day2 = getDay(-30); // QueryWrapper<OrderTaskOriginal> wrapper3 = new QueryWrapper<>(); // wrapper3.lt("create_time",day2+" 00:00:00"); // iOrderTaskOriginalService.remove(wrapper3); // // QueryWrapper<OrderDetailOriginal> wrapper4 = new QueryWrapper<>(); // wrapper4.lt("create_time",day2+" 00:00:00"); // iOrderDetailOriginalService.remove(wrapper4); // // QueryWrapper<DuoZheng> wrapper5 = new QueryWrapper<>(); // iDuoZhengService.remove(wrapper5); // // List<DuoZheng> list = iDuoZhengService.getYiHuDuoZheng(); // iDuoZhengService.saveBatch(list); // } // // private String getDay(int day){ // Date dNow = new Date(); //当前时间 // Calendar calendar = Calendar.getInstance(); //得到日历 // calendar.setTime(dNow);//把当前时间赋给日历 // calendar.add(Calendar.DAY_OF_MONTH, day); //设置为前n天 // Date dBefore = calendar.getTime(); //得到前一天的时间 // SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); //设置时间格式 // String defaultStartDate = sdf.format(dBefore); // return defaultStartDate; // } //} package cn.exrick.xboot.your.schedulings; import cn.exrick.xboot.your.entity.*; import cn.exrick.xboot.your.service.*; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.List; //删除历史数据 @Component public class OrderDealScheduleImpl { @Autowired private IOrderTaskOriginalService iOrderTaskOriginalService; @Autowired private IOrderDetailOriginalService iOrderDetailOriginalService; @Autowired private IOrderTaskService iOrderTaskService; @Autowired private IOrderDetailService iOrderDetailService; @Autowired private IDuoZhengService iDuoZhengService; @Scheduled(cron="0 0 21 * * ?")//每晚下午9点执行 //@Scheduled(cron="0 33 17 * * ?")//测试 public void execute(){ String day = getDay(-14); QueryWrapper<OrderTask> wrapper = new QueryWrapper<>(); wrapper.lt("send_Date",day); iOrderTaskService.remove(wrapper); QueryWrapper<OrderDetail> wrapper2 = new QueryWrapper<>(); wrapper2.lt("create_time",day+" 00:00:00"); iOrderDetailService.remove(wrapper2); String day2 = getDay(-30); QueryWrapper<OrderTaskOriginal> wrapper3 = new QueryWrapper<>(); wrapper3.lt("create_time",day2+" 00:00:00"); iOrderTaskOriginalService.remove(wrapper3); QueryWrapper<OrderDetailOriginal> wrapper4 = new QueryWrapper<>(); wrapper4.lt("create_time",day2+" 00:00:00"); iOrderDetailOriginalService.remove(wrapper4); QueryWrapper<DuoZheng> wrapper5 = new QueryWrapper<>(); iDuoZhengService.remove(wrapper5); List<DuoZheng> list = iDuoZhengService.getYiHuDuoZheng(); iDuoZhengService.saveBatch(list); } private String getDay(int day){ Date dNow = new Date(); //当前时间 Calendar calendar = Calendar.getInstance(); //得到日历 calendar.setTime(dNow);//把当前时间赋给日历 calendar.add(Calendar.DAY_OF_MONTH, day); //设置为前n天 Date dBefore = calendar.getTime(); //得到前一天的时间 SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd"); //设置时间格式 String defaultStartDate = sdf.format(dBefore); return defaultStartDate; } } xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/service/ICarLocationService.java
New file @@ -0,0 +1,14 @@ package cn.exrick.xboot.your.service; import com.baomidou.mybatisplus.extension.service.IService; import cn.exrick.xboot.your.entity.CarLocation; import java.util.List; /** * 车辆定位表接口 * @author whj */ public interface ICarLocationService extends IService<CarLocation> { } xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/serviceimpl/ICarLocationServiceImpl.java
New file @@ -0,0 +1,26 @@ package cn.exrick.xboot.your.serviceimpl; import cn.exrick.xboot.your.mapper.CarLocationMapper; import cn.exrick.xboot.your.entity.CarLocation; import cn.exrick.xboot.your.service.ICarLocationService; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; import java.util.List; /** * 车辆定位表接口实现 * @author whj */ @Slf4j @Service @Transactional public class ICarLocationServiceImpl extends ServiceImpl<CarLocationMapper, CarLocation> implements ICarLocationService { @Autowired private CarLocationMapper carLocationMapper; } xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/util/MQTT.java
@@ -6,6 +6,7 @@ import cn.exrick.xboot.your.service.IAlarmService; import cn.exrick.xboot.your.service.ICarService; import cn.exrick.xboot.your.service.IEventLogService; import cn.hutool.core.date.DateUtil; import cn.hutool.json.JSONArray; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; @@ -15,6 +16,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.Date; import java.util.List; @@ -110,16 +112,6 @@ return; } String format = alarmTime.substring(0,17); QueryWrapper<Alarm> awrapper = new QueryWrapper<>(); awrapper.between("create_time",format+"00",format+"59"); awrapper.eq("car_no",car.getCarNo()); awrapper.eq("type",1); List<Alarm> list = iAlarmService.list(awrapper); if(list.size()>0){ return; } Alarm alarm = new Alarm(); if(eventType.equals("132371")){ alarm.setType(1); @@ -140,6 +132,20 @@ return; } Date date1 = new Date(); long time = date1.getTime()-2*60*1000; Date date = new Date(time); String format1 = DateUtil.format(date,"yyyy-MM-dd HH:mm:ss"); String format2 = DateUtil.format(date1,"yyyy-MM-dd HH:mm:ss"); QueryWrapper<Alarm> awrapper = new QueryWrapper<>(); awrapper.between("create_time",format1,format2); awrapper.eq("car_no",car.getCarNo()); awrapper.eq("type",alarm.getType()); List<Alarm> list = iAlarmService.list(awrapper); if(list.size()>0){ return; } alarm.setAlarmId(alarmId); alarm.setCarId(car.getId()); alarm.setCarNo(car.getCarNo()); xboot-modules/xboot-your/src/main/resources/mapper/CarLocationMapper.xml
New file @@ -0,0 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="cn.exrick.xboot.your.mapper.CarLocationMapper"> </mapper>