Commit d644307a by 杨林龙

1.50.0 开发保存预测家庭地址和预测工作地址的接口

1 parent 68b453bc
package cn.com.glsx.stdinterface.modules.controller;
import cn.com.glsx.stdinterface.api.StayOftenClient;
import cn.com.glsx.stdinterface.dto.DeviceStayOftenDTO;
import cn.com.glsx.stdinterface.modules.service.StayOftenService;
import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONUtil;
import com.glsx.plat.common.annotation.SysLog;
import com.glsx.plat.common.enums.OperateType;
import com.glsx.plat.core.web.R;
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 java.util.Date;
/**
* 预测家庭地址和预测工作地址模块 controller
*
* @author Yanglinlong
* @date 2023/7/19 16:20
*/
@Slf4j
@RestController
@RequestMapping(value = "/stayOften")
@Api(value = "预测家庭地址和预测工作地址模块", tags = {"预测家庭地址和预测工作地址模块"})
public class StayOftenController implements StayOftenClient {
private final static String MODULE = "预测家庭地址和预测工作地址模块";
@Autowired
private StayOftenService stayOftenService;
@Override
@GetMapping(value = "/searchBySnAndPredictDate")
@SysLog(module = MODULE, value = "通过设备号和预测时间查询预测家庭地址和预测工作地址", action = OperateType.QUERY, saveLog = false)
@ApiOperation(value = "通过设备号和预测时间查询预测家庭地址和预测工作地址")
public R<DeviceStayOftenDTO> searchBySnAndPredictDate(@RequestParam String sn, @RequestParam String predictDate) {
log.info("通过设备号查询预测家庭地址和预测工作地址===sn:" + sn + ";predictDate:" + predictDate);
DeviceStayOftenDTO deviceStayOftenDTO = stayOftenService.searchBySnAndPredictDate(sn, predictDate);
return R.ok().data(deviceStayOftenDTO);
}
@Override
@PostMapping(value = "/saveStayOften")
@SysLog(module = MODULE, value = "保存预测家庭地址和预测工作地址", action = OperateType.ADD)
@ApiOperation(value = "保存预测家庭地址和预测工作地址")
public R saveStayOften(@RequestBody DeviceStayOftenDTO deviceStayOftenDTO) {
try {
log.info("保存预测家庭地址和预测工作地址===" + JSONUtil.toJsonStr(deviceStayOftenDTO));
stayOftenService.saveStayOften(deviceStayOftenDTO);
} catch (Exception e) {
return R.error();
}
return R.ok();
}
@Override
@GetMapping(value = "/deleteStayOftenByPredictDate")
@SysLog(module = MODULE, value = "删除一年以前的预测家庭地址和预测工作地址", action = OperateType.DELETE, saveLog = false)
@ApiOperation(value = "删除一年以前的预测家庭地址和预测工作地址")
public R deleteStayOftenByPredictDate() {
log.info("开始删除删除一年以前的预测家庭地址和预测工作地址:时间" + DateUtil.formatDateTime(new Date()));
stayOftenService.deleteStayOftenByPredictDate();
log.info("开始删除删除一年以前的预测家庭地址和预测工作地址" + DateUtil.formatDateTime(new Date()));
return R.ok();
}
}
package cn.com.glsx.stdinterface.modules.converter;
import cn.com.glsx.stdinterface.dto.DeviceStayOftenDTO;
import cn.com.glsx.stdinterface.dto.WorkOrderVehicleDeviceDTO;
import cn.com.glsx.stdinterface.modules.entity.DeviceStayOften;
import cn.com.glsx.stdinterface.modules.entity.WorkOrderVehicleDevice;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;
/**
* 设备停留often转换器
*/
@Mapper
public interface DeviceStayOftenConverter {
DeviceStayOftenConverter INSTANCE = Mappers.getMapper(DeviceStayOftenConverter.class);
DeviceStayOftenDTO do2dto(DeviceStayOften item);
DeviceStayOften dto2do(DeviceStayOftenDTO item);
}
package cn.com.glsx.stdinterface.modules.entity;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.*;
@Data
@Table(name = "t_device_stay_often")
public class DeviceStayOften implements Serializable {
/**
* 里程主键ID
*/
@Id
private Integer id;
/**
* 设备号
*/
private String sn;
/**
* 车辆、设备关系id
*/
@Column(name = "vd_id")
private Integer vdId;
/**
* 预测家庭地址
*/
@Column(name = "home_address")
private String homeAddress;
/**
* 家庭地址经度
*/
@Column(name = "home_lng")
private String homeLng;
/**
* 家庭地址纬度
*/
@Column(name = "home_lat")
private String homeLat;
/**
* 预测工作地址
*/
@Column(name = "work_address")
private String workAddress;
/**
* 工作地址经度
*/
@Column(name = "work_lng")
private String workLng;
/**
* 工作地址纬度
*/
@Column(name = "work_lat")
private String workLat;
/**
* 预测时间
*/
@Column(name = "predict_date")
private Date predictDate;
/**
* 是否删除 0=正常 -1=删除
*/
@Column(name = "del_flag")
private Byte delFlag;
/**
* 创建时间|入库时间
*/
@Column(name = "created_date")
private Date createdDate;
/**
* 创建人用户id
*/
@Column(name = "created_by")
private Integer createdBy;
/**
* 更新时间
*/
@Column(name = "updated_date")
private Date updatedDate;
/**
* 更新人用户id
*/
@Column(name = "updated_by")
private Integer updatedBy;
private static final long serialVersionUID = 1L;
}
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.stdinterface.modules.mapper;
import cn.com.glsx.stdinterface.dto.DeviceStayOftenDTO;
import cn.com.glsx.stdinterface.modules.entity.DeviceStayOften;
import cn.hutool.core.date.DateTime;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@Mapper
public interface DeviceStayOftenMapper extends CommonBaseMapper<DeviceStayOften> {
/**
* 根据设备号和预测时间查询预测家庭地址和预测工作地址
*
* @param sn 设备号
* @param predictDate 预测时间
* @return
*/
DeviceStayOften searchBySnAndPredictDate(@Param("sn") String sn, @Param("predictDate") String predictDate);
/**
* 开始删除一年以前的预测家庭地址和预测工作地址
*
* @param dateTime 时间
*/
void deleteStayOftenByPredictDate(String dateTime);
}
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.stdinterface.modules.service;
import cn.com.glsx.stdinterface.dto.DeviceStayOftenDTO;
import cn.com.glsx.stdinterface.modules.converter.DeviceStayOftenConverter;
import cn.com.glsx.stdinterface.modules.entity.DeviceStayOften;
import cn.com.glsx.stdinterface.modules.mapper.DeviceStayOftenMapper;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* 设备分离报警 service
*
* @author Yanglinlong
* @date 2023/7/19 16:21
*/
@Slf4j
@Service
public class StayOftenService {
@Autowired
private DeviceStayOftenMapper deviceStayOftenMapper;
public DeviceStayOftenDTO searchBySnAndPredictDate(String sn, String predictDate) {
DeviceStayOften deviceStayOften = deviceStayOftenMapper.searchBySnAndPredictDate(sn, predictDate);
return DeviceStayOftenConverter.INSTANCE.do2dto(deviceStayOften);
}
public void saveStayOften(DeviceStayOftenDTO deviceStayOftenDTO) {
deviceStayOftenMapper.insertSelective(DeviceStayOftenConverter.INSTANCE.dto2do(deviceStayOftenDTO));
}
public void deleteStayOftenByPredictDate() {
// 获取六个月之前的时间
DateTime dateTime = DateUtil.offsetMonth(DateUtil.date(), -12);
//删除六个月之前的数据
deviceStayOftenMapper.deleteStayOftenByPredictDate(DateUtil.formatDateTime(dateTime));
}
}
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
</commentGenerator> </commentGenerator>
<!-- jdbc连接--> <!-- jdbc连接-->
<jdbcConnection driverClass="com.mysql.cj.jdbc.Driver" <jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
connectionURL="jdbc:mysql://192.168.3.190:3306/neshield?serverTimeZone=Shanghai&amp;useUnicode=true&amp;characterEncoding=utf8&amp;useSSL=false" connectionURL="jdbc:mysql://192.168.3.227:3306/neshield?serverTimeZone=Shanghai&amp;useUnicode=true&amp;characterEncoding=utf8&amp;useSSL=false"
userId="dev_user" userId="dev_user"
password="df234fl"> password="df234fl">
<!--防止生成其他库同名表--> <!--防止生成其他库同名表-->
...@@ -76,6 +76,7 @@ ...@@ -76,6 +76,7 @@
<!-- <table tableName="t_alarm_second_data_near_rel" domainObjectName="AlarmSecondDataNearRel" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>--> <!-- <table tableName="t_alarm_second_data_near_rel" domainObjectName="AlarmSecondDataNearRel" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>-->
<!-- <table tableName="t_alarm_warn_analyse" domainObjectName="AlarmWarnAnalyse" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>--> <!-- <table tableName="t_alarm_warn_analyse" domainObjectName="AlarmWarnAnalyse" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>-->
<!-- <table tableName="t_fake_offline_change_frequently" domainObjectName="FakeOfflineChangeFrequently" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>--> <!-- <table tableName="t_fake_offline_change_frequently" domainObjectName="FakeOfflineChangeFrequently" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>-->
<table tableName="t_dev_split" domainObjectName="DevSplit" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/> <!-- <table tableName="t_dev_split" domainObjectName="DevSplit" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>-->
<table tableName="t_device_stay_often" domainObjectName="DeviceStayOften" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>
</context> </context>
</generatorConfiguration> </generatorConfiguration>
\ No newline at end of file \ No newline at end of file
<?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.com.glsx.stdinterface.modules.mapper.DeviceStayOftenMapper">
<resultMap id="BaseResultMap" type="cn.com.glsx.stdinterface.modules.entity.DeviceStayOften">
<!--
WARNING - @mbg.generated
-->
<id column="id" jdbcType="INTEGER" property="id"/>
<result column="sn" jdbcType="VARCHAR" property="sn"/>
<result column="vd_id" jdbcType="INTEGER" property="vdId"/>
<result column="home_address" jdbcType="VARCHAR" property="homeAddress"/>
<result column="home_lng" jdbcType="VARCHAR" property="homeLng"/>
<result column="home_lat" jdbcType="VARCHAR" property="homeLat"/>
<result column="work_address" jdbcType="VARCHAR" property="workAddress"/>
<result column="work_lng" jdbcType="VARCHAR" property="workLng"/>
<result column="work_lat" jdbcType="VARCHAR" property="workLat"/>
<result column="predict_date" jdbcType="TIMESTAMP" property="predictDate"/>
<result column="del_flag" jdbcType="TINYINT" property="delFlag"/>
<result column="created_date" jdbcType="TIMESTAMP" property="createdDate"/>
<result column="created_by" jdbcType="INTEGER" property="createdBy"/>
<result column="updated_date" jdbcType="TIMESTAMP" property="updatedDate"/>
<result column="updated_by" jdbcType="INTEGER" property="updatedBy"/>
</resultMap>
<sql id="Base_Column_List">
<!--
WARNING - @mbg.generated
-->
id, sn, vd_id, home_address, home_lng, home_lat, work_address, work_lng, work_lat,
predict_date, del_flag, created_date, created_by, updated_date, updated_by
</sql>
<select id="searchBySnAndPredictDate" resultMap="BaseResultMap">
SELECT
<include refid="Base_Column_List"/>
FROM t_device_stay_often
WHERE sn = #{sn}
AND DATE_FORMAT(predict_date, '%Y-%m-%d %H:%i:%s')= #{predictDate}
AND del_flag = 0
</select>
<delete id="deleteStayOftenByPredictDate">
delete
from t_device_stay_often
where DATE_FORMAT(predict_date, '%Y-%m-%d %H:%i:%s') &lt; #{dateTime}
</delete>
</mapper>
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!