亳州移动警务新对接

ds-bozhou
luyya 2026-03-26 17:48:50 +08:00
parent d667538721
commit 7aca2c9649
12 changed files with 266 additions and 33 deletions

View File

@ -0,0 +1,85 @@
package org.dromara.extract.domain;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.dromara.common.tenant.core.TenantEntity;
import java.io.Serial;
/**
* sys_dept
*
* @author Lion Li
*/
@Data
@TableName("sys_dept")
public class Dept {
@Serial
private static final long serialVersionUID = 1L;
/**
* ID
*/
@TableId(value = "dept_id")
private String deptId;
/**
* ID
*/
private String parentId;
/**
*
*/
private String deptName;
private String shortName;
/**
*
*/
private Integer orderNum;
/**
*
*/
private Long leader;
/**
*
*/
private String phone;
/**
*
*/
private String email;
/**
* :0,1
*/
private String status;
/**
* 0 2
*/
@TableLogic
private String delFlag;
/**
*
*/
private String ancestors;
private String fullName;
private String isVisible;
}

View File

@ -24,6 +24,9 @@ public class Device implements Serializable {
private String carNum; private String carNum;
private String remark1; private String remark1;
private String remark2; private String remark2;
private String cardNum;
private int valid; private int valid;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date createTime; private Date createTime;
@ -141,4 +144,12 @@ public class Device implements Serializable {
public void setUpdateTime(Date updateTime) { public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime; this.updateTime = updateTime;
} }
public String getCardNum() {
return cardNum;
}
public void setCardNum(String cardNum) {
this.cardNum = cardNum;
}
} }

View File

@ -0,0 +1,19 @@
package org.dromara.extract.mapper;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
import org.dromara.extract.domain.Dept;
import java.util.List;
/**
*
*
* @author Lion Li
*/
@DS("wzhj")
public interface DeptMapper extends BaseMapper<Dept> {
}

View File

@ -2,6 +2,7 @@ package org.dromara.extract.mapper;
import com.baomidou.dynamic.datasource.annotation.DS;
import org.dromara.extract.domain.EsGpsInfo; import org.dromara.extract.domain.EsGpsInfo;
import java.util.List; import java.util.List;
@ -10,6 +11,7 @@ public interface DeviceGpsMapper {
List<EsGpsInfo> selectPDTGPS(EsGpsInfo esGpsInfo); List<EsGpsInfo> selectPDTGPS(EsGpsInfo esGpsInfo);
@DS("ydjw")
List<EsGpsInfo> selectYDJWGPS(EsGpsInfo esGpsInfo); List<EsGpsInfo> selectYDJWGPS(EsGpsInfo esGpsInfo);
List<EsGpsInfo> selectBDGCGPS(EsGpsInfo esGpsInfo); List<EsGpsInfo> selectBDGCGPS(EsGpsInfo esGpsInfo);

View File

@ -1,6 +1,7 @@
package org.dromara.extract.mapper; package org.dromara.extract.mapper;
import com.baomidou.dynamic.datasource.annotation.DS;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.dromara.extract.domain.Device; import org.dromara.extract.domain.Device;
@ -19,4 +20,7 @@ public interface DeviceMapper {
Device deviceByCode(String deviceCode); Device deviceByCode(String deviceCode);
@DS("wzhj")
int insertOrUpdateByCodeAndType(Device device);
} }

View File

@ -0,0 +1,92 @@
package org.dromara.extract.schedule;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.dromara.data2es.api.RemoteDataToEsService;
import org.dromara.data2es.api.domain.RemoteGpsInfo;
import org.dromara.extract.domain.Device;
import org.dromara.extract.domain.EsGpsInfo;
import org.dromara.extract.mapper.DeviceGpsMapper;
import org.dromara.extract.mapper.DeviceMapper;
import org.dromara.extract.service.IDeviceService;
import org.dromara.system.api.RemoteDeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Scheduled;
import java.util.*;
import java.util.stream.Collectors;
/*
* @Author: luya
* @Date: 2023/3/20 15:43
*
* */
@Slf4j
@Configuration
public class JwtDeviceSchedule {
@Autowired
IDeviceService deviceService;
@Autowired
DeviceGpsMapper gpsMapper;
@DubboReference
RemoteDataToEsService dataToEsService;
@Value("${ruansi.jwt-gps-update-time}")
private String gpsUpdateTime;
@Value("${ruansi.jwt-base-update-time}")
private String baseUpdateTime;
/*
* 10S
* */
@Scheduled(cron = "0/10 * * * * ?")
public void jwtGpsSchedule(){
EsGpsInfo gpsInfo = new EsGpsInfo();
gpsInfo.setGpsTime(DateUtil.parse(gpsUpdateTime));
log.info("警务通GPS更新时间:"+gpsUpdateTime);
List<EsGpsInfo> list = gpsMapper.selectYDJWGPS(gpsInfo);
for (int i = 0; i < list.size(); i++) {
EsGpsInfo info = list.get(i);
if(i == 0){
gpsUpdateTime = DateUtil.format(info.getGpsTime(),"yyyy-MM-dd HH:mm:ss") ;
}
if (DateUtil.between(new Date(),info.getGpsTime(), DateUnit.MINUTE) > 5){
info.setOnline("0");
}else {
info.setOnline("1");
}
}
ArrayList<EsGpsInfo> collect = list.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() ->
new TreeSet<>(Comparator.comparing(EsGpsInfo::getDeviceCode))), ArrayList::new));
dataToEsService.saveDataBatch(BeanUtil.copyToList(collect, RemoteGpsInfo.class));
}
/*
*
* */
@Scheduled(cron = "0 0/10 * * * ?")
public void jwtDeviceSchedule(){
Device d = new Device();
d.setUpdateTime(DateUtil.parse(baseUpdateTime));
List<Device> list = deviceService.selectYDJW(d);
for (int i = 0; i < list.size(); i++) {
Device device = list.get(i);
if(i == 0)
baseUpdateTime = DateUtil.format(device.getUpdateTime(),"yyyy-MM-dd HH:mm:ss") ;
}
deviceService.batchSaveOrUpdate(list);
}
}

View File

@ -19,5 +19,7 @@ public interface IDeviceService {
Device deviceByCode(String deviceCode); Device deviceByCode(String deviceCode);
Boolean batchSaveOrUpdate(List<Device> list);
} }

View File

@ -2,7 +2,10 @@ package org.dromara.extract.service.impl;
import com.baomidou.dynamic.datasource.annotation.DS;
import org.dromara.extract.domain.Dept;
import org.dromara.extract.domain.Device; import org.dromara.extract.domain.Device;
import org.dromara.extract.mapper.DeptMapper;
import org.dromara.extract.mapper.DeviceMapper; import org.dromara.extract.mapper.DeviceMapper;
import org.dromara.extract.service.IDeviceService; import org.dromara.extract.service.IDeviceService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -16,6 +19,9 @@ public class DeviceServiceImpl implements IDeviceService {
@Autowired @Autowired
DeviceMapper deviceMapper; DeviceMapper deviceMapper;
@Autowired
DeptMapper deptMapper;
@Override @Override
public List<Device> selectPDT(Device device) { public List<Device> selectPDT(Device device) {
List<Device> list = deviceMapper.selectPDT(device); List<Device> list = deviceMapper.selectPDT(device);
@ -23,6 +29,7 @@ public class DeviceServiceImpl implements IDeviceService {
} }
@Override @Override
@DS("ydjw")
public List<Device> selectYDJW(Device tDevice) { public List<Device> selectYDJW(Device tDevice) {
return deviceMapper.selectYDJW(tDevice); return deviceMapper.selectYDJW(tDevice);
} }
@ -41,4 +48,17 @@ public class DeviceServiceImpl implements IDeviceService {
public Device deviceByCode(String deviceCode) { public Device deviceByCode(String deviceCode) {
return deviceMapper.deviceByCode(deviceCode); return deviceMapper.deviceByCode(deviceCode);
} }
@Override
public Boolean batchSaveOrUpdate(List<Device> list) {
for (Device entity : list) {
Dept dept = deptMapper.selectById(entity.getZzjgdm());
if (dept != null) {
entity.setZzjgmc(dept.getShortName());
}
deviceMapper.insertOrUpdateByCodeAndType(entity);
}
return true;
}
} }

View File

@ -0,0 +1,10 @@
<?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="org.dromara.extract.mapper.DeptMapper">
<resultMap type="org.dromara.extract.domain.Dept" id="SysDeptResult">
</resultMap>
</mapper>

View File

@ -29,10 +29,11 @@
</select> </select>
<select id="selectYDJWGPS" parameterType="org.dromara.extract.domain.EsGpsInfo" resultMap="DeviceResult"> <select id="selectYDJWGPS" parameterType="org.dromara.extract.domain.EsGpsInfo" resultMap="DeviceResult">
select userid deviceCode,'4' deviceType, lng lng, lat lat, gpstime gpsTime from v_device_status select zdid deviceCode,'4' deviceType, jd lng, wd lat, gxsj gpsTime from v_jwt
<where> <where>
<if test="gpsTime != null "> and to_date(gpstime,'yyyy-mm-dd,hh24:mi:ss') >= #{gpsTime}</if> <if test="gpsTime != null "> and gxsj > #{gpsTime}</if>
</where> </where>
order by gxsj desc
</select> </select>
<select id="selectBDGCGPS" parameterType="org.dromara.extract.domain.EsGpsInfo" resultMap="DeviceResult"> <select id="selectBDGCGPS" parameterType="org.dromara.extract.domain.EsGpsInfo" resultMap="DeviceResult">

View File

@ -8,9 +8,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="id" column="id" /> <result property="id" column="id" />
<result property="deviceCode" column="device_code" /> <result property="deviceCode" column="device_code" />
<result property="deviceType" column="device_type" /> <result property="deviceType" column="device_type" />
<result property="policeNo" column="policeNo" /> <result property="policeNo" column="police_no" />
<result property="policeName" column="policeName" /> <result property="policeName" column="police_name" />
<result property="phoneNum" column="phoneNum" /> <result property="phoneNum" column="phone_num" />
<result property="carNum" column="car_num" /> <result property="carNum" column="car_num" />
<result property="zzjgdm" column="zzjgdm" /> <result property="zzjgdm" column="zzjgdm" />
<result property="zzjgmc" column="zzjgmc" /> <result property="zzjgmc" column="zzjgmc" />
@ -30,11 +30,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select> </select>
<select id="selectYDJW" parameterType="org.dromara.extract.domain.Device" resultMap="DeviceRes"> <select id="selectYDJW" parameterType="org.dromara.extract.domain.Device" resultMap="DeviceRes">
select pnum device_code,'4' device_type, dept_code zzjgdm, department_detail zzjgmc, zhgxsj create_time, pname policeName, select zdid device_code,'4' device_type, ssdw zzjgdm, to_timestamp(zdcjsj / 1000)::timestamp create_time,
pnum policeNo, phonenum phoneNum from v_user jyxm police_name, jyjh police_no, jylxfs phone_num,to_char(gxsj,'yyyy-MM-dd HH24:mi:ss') update_time,sfyx as valid from v_jwt
<where> <where>
<if test="createTime != null "> and zhgxsj >= #{createTime}</if> ssdw != '' and ssdw != '341600000000'
<if test="updateTime != null "> and gxsj > #{updateTime}</if>
</where> </where>
order by gxsj desc
</select> </select>
<select id="selectBDGC" parameterType="org.dromara.extract.domain.Device" resultMap="DeviceRes"> <select id="selectBDGC" parameterType="org.dromara.extract.domain.Device" resultMap="DeviceRes">
@ -57,5 +59,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select * from t_device where device_code = #{deviceCode} select * from t_device where device_code = #{deviceCode}
</select> </select>
<insert id="insertOrUpdateByCodeAndType">
insert into t_device (device_code, device_type, zzjgdm, zzjgmc, police_no, police_name, phone_num, car_num, valid,
remark1, remark2, card_num, create_time, update_time)
values (#{deviceCode},#{deviceType},#{zzjgdm},#{zzjgmc},#{policeNo},#{policeName},#{phoneNum},#{carNum},#{valid},
#{remark1},#{remark2},#{cardNum},#{createTime},#{updateTime})
ON DUPLICATE KEY UPDATE
police_no = values(police_no),police_name = values(police_name),phone_num = values(phone_num),
car_num = values(car_num),valid = values(valid),remark1 = values(remark1),remark2 = values(remark2),card_num = values(card_num),
update_time = values(update_time)
</insert>
</mapper> </mapper>

View File

@ -290,11 +290,6 @@ public class TDeviceServiceImpl implements ITDeviceService {
@Override @Override
public Boolean batchSaveOrUpdate(List<TDevice> list) { public Boolean batchSaveOrUpdate(List<TDevice> list) {
boolean flag = true; boolean flag = true;
// 先根据 field1 和 field2 查询出已存在的记录
/*List<TDevice> existingEntities = baseMapper.selectList(new QueryWrapper<TDevice>()
.in("device_code", list.stream().map(TDevice::getDeviceCode).collect(Collectors.toList()))
.in("device_type", list.stream().map(TDevice::getDeviceType).collect(Collectors.toList())));
*/
// 找到需要更新的记录 // 找到需要更新的记录
List<TDevice> toUpdate = new ArrayList<>(); List<TDevice> toUpdate = new ArrayList<>();
// 找到需要插入的记录 // 找到需要插入的记录
@ -302,28 +297,8 @@ public class TDeviceServiceImpl implements ITDeviceService {
for (TDevice entity : list) { for (TDevice entity : list) {
baseMapper.insertOrUpdateByCodeAndType(entity); baseMapper.insertOrUpdateByCodeAndType(entity);
/*for (TDevice existingEntity : existingEntities) {
if (entity.getDeviceCode().equals(existingEntity.getDeviceCode()) && entity.getDeviceType().equals(existingEntity.getDeviceType())) {
entity.setId(existingEntity.getId()); // 设置 ID 以便更新
toUpdate.add(entity);
exists = true;
break;
}
}
if (!exists) {
toInsert.add(entity);
}*/
}
// 批量更新
/*if (!toUpdate.isEmpty()) {
flag = baseMapper.updateBatchById(toUpdate);
} }
// 批量插入
if (!toInsert.isEmpty()) {
flag = baseMapper.insertBatch(toInsert); // insertBatchSomeColumn 是 MyBatis-Plus 提供的批量插入方法
}*/
return flag; return flag;
// return baseMapper.insertOrUpdateBatch(List); // return baseMapper.insertOrUpdateBatch(List);
} }