Commit a9c87a4f by 王欣伟

Merge branch 'v1.6.0' of http://192.168.3.233:8090/eshiled-new/ne-shield-standar…

…d-interfaces into v1.6.0
2 parents 33b22142 1d7812d1
Showing 21 changed files with 495 additions and 47 deletions
package cn.com.glsx.stdinterface.common.constants;
/**
* 设备相关常量
* @author xiangyanlin
* @date 2022/4/13
*/
public final class DeviceConstants {
/**
* 有源
*/
public final static int SOURCE = 1;
/**
* 无源
*/
public final static int NO_SOURCE = 0;
}
......@@ -28,4 +28,10 @@ public class BatteryController implements BatteryClient {
batteryService.saveBatteryInfo(devicePowerDTO);
return R.ok();
}
@PostMapping("/initDataFromOld")
public R moveDataFromOldDatabase() {
batteryService.initDataFromOld();
return R.ok();
}
}
package cn.com.glsx.stdinterface.modules.entity;
import lombok.Data;
import javax.persistence.Column;
import java.io.Serializable;
/**
* 车辆操作人
* @author xiangyanlin
* @date 2022/4/13
*/
@Data
public class VehicleDeviceOperator implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 设备号
*/
private String sn;
/**
* 创建人
*/
private Long createdBy;
/**
* 操作者
*/
private Long updatedBy;
}
......@@ -3,6 +3,7 @@ package cn.com.glsx.stdinterface.modules.mapper;
import cn.com.glsx.stdinterface.modules.entity.DeviceJourneyOverview;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/**
* 新e盾|里程表总览
......@@ -14,9 +15,10 @@ import org.apache.ibatis.annotations.Mapper;
public interface DeviceJourneyOverviewMapper extends CommonBaseMapper<DeviceJourneyOverview> {
/**
*
* 如果不存在就新增。 如果存在则累加总行程 总次数
* @param deviceJourneyOverview 传入新的行程值
* 根据sn和vdId获取唯一 的 设备 统计里程
* @param sn 设备号
* @param vdId 关联id
* @return 统计里程
*/
void insertOrSumDistanceAndCount(DeviceJourneyOverview deviceJourneyOverview);
DeviceJourneyOverview selectBySnAndVdId(@Param("sn") String sn, @Param("vdId") Long vdId);
}
\ No newline at end of file
package cn.com.glsx.stdinterface.modules.mapper;
import cn.com.glsx.stdinterface.modules.entity.Device;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface DeviceMapper extends CommonBaseMapper<Device> {
/**
* 根据 source 类型获取sn集合
* @param source 1有源 0无源
* @return sn集合
*/
List<String> listSnBySource(Integer source);
}
\ No newline at end of file
......@@ -4,6 +4,8 @@ import cn.com.glsx.stdinterface.modules.entity.DevicePower;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface DevicePowerMapper extends CommonBaseMapper<DevicePower> {
......@@ -15,4 +17,11 @@ public interface DevicePowerMapper extends CommonBaseMapper<DevicePower> {
*/
DevicePower selectBySn(String sn);
/**
* 批量插入或修改
* @param entities
* @return
*/
int insertOrUpdateBatch(List<DevicePower> entities);
}
\ No newline at end of file
......@@ -17,6 +17,9 @@ import java.util.List;
@Mapper
public interface VehicleDeviceMapper extends CommonBaseMapper<VehicleDevice> {
/**
* 取解绑状态设备
*/
VehicleDevice getVdIdbySn(@Param("sn") String sn);
VehicleDevice selectBindingDeviceBySn(@Param("sn") String sn);
......@@ -25,5 +28,8 @@ public interface VehicleDeviceMapper extends CommonBaseMapper<VehicleDevice> {
List<VehicleDevice> selectBindingDevicesByVehicleId(@Param("vehicleId") Long vehicleId);
/**
* 取绑定状态设备
*/
VehicleDevice selectVehicleDevcieBySn(@Param("sn") String sn);
}
......@@ -2,6 +2,7 @@ package cn.com.glsx.stdinterface.modules.mapper;
import cn.com.glsx.stdinterface.modules.entity.Vehicle;
import cn.com.glsx.stdinterface.modules.entity.VehicleDeviceOperator;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
......@@ -29,4 +30,11 @@ public interface VehicleMapper extends CommonBaseMapper<Vehicle> {
Vehicle selectByWorkOrderIdAndVin(@Param("workOrderId") Long workOrderId, @Param("vin") String vin);
Vehicle getVehicleByVdId(@Param("vdId") Long vdId);
/**
* 根据sn获取
* @param sn 设备序列号
* @return 车辆列表
*/
List<VehicleDeviceOperator> listVehicleBySn(@Param("sn") Collection<String> sn);
}
\ No newline at end of file
package cn.com.glsx.stdinterface.modules.remote;
import cn.com.glsx.alarm.api.DevicePowerFeignClient;
import cn.com.glsx.alarm.services.model.DevicePowerDto;
import cn.com.glsx.devicemonitor.api.dto.response.DeviceStatusModel;
import com.alibaba.fastjson.JSON;
import com.glsx.plat.core.web.R;
import com.google.common.collect.Lists;
import com.google.gson.reflect.TypeToken;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
/**
* 调用电量远程服务
* @author xiangyanlin
* @date 2022/4/13
*/
@Slf4j
@Service
public class RemoteFeignDevicePowerService {
@Autowired
private DevicePowerFeignClient devicePowerFeignClient;
public List<DevicePowerDto> getDevicePowerListBySn(List<String> sn) {
R<List<DevicePowerDto>> result = devicePowerFeignClient.getDevicePowerListBySn(sn);
return result.getDataList(new TypeToken<List<DevicePowerDto>>() {}.getType());
}
}
package cn.com.glsx.stdinterface.modules.service;
import cn.com.glsx.alarm.services.model.DevicePowerDto;
import cn.com.glsx.stdinterface.common.constants.DeviceConstants;
import cn.com.glsx.stdinterface.dto.DevicePowerDTO;
import cn.com.glsx.stdinterface.modules.entity.DevicePower;
import cn.com.glsx.stdinterface.modules.entity.Vehicle;
import cn.com.glsx.stdinterface.modules.entity.VehicleDeviceOperator;
import cn.com.glsx.stdinterface.modules.mapper.DeviceMapper;
import cn.com.glsx.stdinterface.modules.mapper.DevicePowerMapper;
import cn.com.glsx.stdinterface.modules.mapper.VehicleDeviceMapper;
import cn.com.glsx.stdinterface.modules.mapper.VehicleMapper;
import cn.com.glsx.stdinterface.modules.remote.RemoteFeignDevicePowerService;
import com.glsx.plat.common.multithread.ListSplitIterator;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* 电量
......@@ -30,18 +44,21 @@ public class BatteryService {
@Resource
private VehicleService vehicleService;
@Resource
private DeviceMapper deviceMapper;
@Resource
private RemoteFeignDevicePowerService remoteFeignDevicePowerService;
/**
* 保存电量信息
*/
public void saveBatteryInfo(DevicePowerDTO devicePowerDTO) {
//从车辆信息中获取创建人信息
Vehicle vehicle = vehicleMapper.getVehicleBySn(devicePowerDTO.getSn());
Long createdBy = null;
Long updatedBy = null;
if(Objects.nonNull(vehicle)) {
createdBy = vehicle.getCreatedBy();
updatedBy = vehicle.getUpdatedBy();
} else {
Long createdBy = Optional.ofNullable(vehicle).map(Vehicle::getCreatedBy).orElse(null);
Long updatedBy = Optional.ofNullable(vehicle).map(Vehicle::getUpdatedBy).orElse(null);
if(Objects.isNull(vehicle)) {
log.warn("该设备没有绑定车辆" + devicePowerDTO.getSn());
}
//从关联表从获取关联id
......@@ -70,4 +87,85 @@ public class BatteryService {
return devicePower;
}
public DevicePower convert(DevicePowerDto devicePowerDTO, Long createBy, Long updateBy, Long vnId) {
DevicePower devicePower = new DevicePower();
devicePower.setSn(devicePowerDTO.getSn());
devicePower.setVdId(vnId);
devicePower.setAlarmTime(devicePowerDTO.getAlarmtime());
devicePower.setSoc(devicePowerDTO.getSoc());
devicePower.setCreatedBy(createBy);
devicePower.setUpdatedBy(updateBy);
devicePower.setCreatedDate(devicePowerDTO.getCreatetime());
devicePower.setUpdatedDate(devicePowerDTO.getUpdatetime());
return devicePower;
}
/**
* 迁移老表数据
*/
@Async("threadPoolTaskExecutor")
public void initDataFromOld() {
long startTime = System.currentTimeMillis();
//获取所有无源设备
List<String> snList = deviceMapper.listSnBySource(DeviceConstants.NO_SOURCE);
if (CollectionUtils.isEmpty(snList)) {
log.info("新e盾平台的无线设备数量:{}", 0);
return;
}
log.info("新e盾平台的无线设备数量:{}", snList.size());
ListSplitIterator<String> listSplitIterator = new ListSplitIterator<>(snList, 1000);
int times = 1;
while (listSplitIterator.hasNext()) {
List<String> subSnList = listSplitIterator.next();
log.info("分批同步老电量表数据--批次:{}", times);
initDataTask(subSnList);
times ++;
}
long endTime = System.currentTimeMillis();
log.info("分批同步老电量表数据完成 总耗时(毫秒):{}", endTime - startTime);
}
/**
* 组装数据并写库
*/
public void initDataTask(List<String> snList) {
List<DevicePowerDto> devicePowerDtoList = getOldDevicePowerList(snList);
if (CollectionUtils.isEmpty(devicePowerDtoList)) {
log.info("分批同步老电量表数据--数量:{}", 0);
return;
}
//从车辆里面获取创建人信息
Map<String, VehicleDeviceOperator> vehicleDeviceOperatorMap = vehicleService.getVehicleDeviceOperatorMap(snList);
//从设备车辆关联获取 关联id
Map<String, Long> snVdIdMap = vehicleService.getSnVdIdMap(snList);
//构建DO
List<DevicePower> devicePowers = devicePowerDtoList.stream()
.map(e -> convert(e,
Optional.ofNullable(vehicleDeviceOperatorMap.get(e.getSn()))
.map(VehicleDeviceOperator::getCreatedBy)
.orElse(null),
Optional.ofNullable(vehicleDeviceOperatorMap
.get(e.getSn())).map(VehicleDeviceOperator::getUpdatedBy)
.orElse(null),
snVdIdMap.get(e.getSn())))
.collect(Collectors.toList());
//写入新的数据库
log.info("分批同步老电量表数据--数量:{}", devicePowers.size());
devicePowerMapper.insertOrUpdateBatch(devicePowers);
}
private List<DevicePowerDto> getOldDevicePowerList(List<String> snList) {
//从旧警情中心获取设备电量数据
List<DevicePowerDto> devicePowerDTOList = remoteFeignDevicePowerService.getDevicePowerListBySn(snList);
if(CollectionUtils.isEmpty(devicePowerDTOList)) {
return Lists.newArrayList();
}
//去重
return new ArrayList<>(devicePowerDTOList.stream()
.collect(Collectors.toMap(DevicePowerDto::getSn, Function.identity(), (o1, o2) -> o1)).values());
}
}
......@@ -18,6 +18,7 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.Date;
import java.util.Objects;
import java.util.Optional;
/**
* 新e盾|里程服务实现类
......@@ -46,10 +47,13 @@ public class JourneyService {
*/
@Transactional(rollbackFor = Exception.class)
public void saveDeviceJourney(DeviceJourneyDTO deviceJourneyDTO) {
long t1 = System.currentTimeMillis();
if (Objects.isNull(deviceJourneyDTO)) {
return;
}
DeviceJourney journey = deviceJourneyMapper.selectBySnAndBeginTime(deviceJourneyDTO.getSn(), deviceJourneyDTO.getBeginTime());
long t2 = System.currentTimeMillis();
log.info("重复校验时间{}", t2 - t1);
if(Objects.nonNull(journey)) {
log.warn("该设备同样的开始时间行程数据已经存在" +
"sn: " + deviceJourneyDTO.getSn() + "beginTime:" + DateUtils.formatNormal(deviceJourneyDTO.getBeginTime()));
......@@ -58,23 +62,44 @@ public class JourneyService {
//从车辆信息中获取创建人信息
Vehicle vehicle = getVehicleBySn(deviceJourneyDTO.getSn());
Long createdBy = null;
Long updatedBy = null;
if (Objects.nonNull(vehicle)) {
createdBy = vehicle.getCreatedBy();
updatedBy = vehicle.getUpdatedBy();
} else {
log.warn("该设备没有绑定车辆" + deviceJourneyDTO.getSn());
}
Long createdBy = Optional.ofNullable(vehicle).map(Vehicle::getCreatedBy).orElse(null);
Long updatedBy = Optional.ofNullable(vehicle).map(Vehicle::getUpdatedBy).orElse(null);
long t3 = System.currentTimeMillis();
log.info("获取创建人时间{}", t3 - t2);
//从关联表从获取关联id
Long vnId = vehicleService.getVdId(deviceJourneyDTO.getSn());
Long vdId = vehicleService.getVdId(deviceJourneyDTO.getSn());
long t4 = System.currentTimeMillis();
log.info("获取创建人时间{}", t4 - t3);
//行程信息入库
DeviceJourney deviceJourney = convertTo(deviceJourneyDTO, vnId, createdBy, updatedBy);
DeviceJourney deviceJourney = convertTo(deviceJourneyDTO, vdId, createdBy, updatedBy);
deviceJourneyMapper.insert(deviceJourney);
//如果行程数据的设备未关联车辆 不计入从次数和总信息
if(Objects.isNull(vdId)) {
log.warn("该设备没有绑定车辆" + deviceJourneyDTO.getSn());
log.info("同步里程总耗时{}", t4 - t1);
return;
}
//更新总行程次数 总里程
DeviceJourneyOverview overview = buildOverviewWitheJourney(deviceJourneyDTO, vnId, createdBy, updatedBy);
deviceJourneyOverviewMapper.insertOrSumDistanceAndCount(overview);
DeviceJourneyOverview overviewDO = buildOverviewWitheJourney(deviceJourneyDTO, vdId, createdBy, updatedBy);
DeviceJourneyOverview overview = deviceJourneyOverviewMapper.selectBySnAndVdId(deviceJourneyDTO.getSn(), vdId);
long t5 = System.currentTimeMillis();
log.info("行程入库时间{}", t5 - t4);
if (Objects.isNull(overview)) {
//本设备的第一条里程数据
deviceJourneyOverviewMapper.insert(overviewDO);
log.info("同步里程总耗时{}", t5 - t1);
return;
}
overview.setDistance(overview.getDistance() + overviewDO.getDistance());
overview.setDistance(overview.getTotalJourneyCount() + 1);
overview.setUpdatedDate(new Date());
deviceJourneyOverviewMapper.updateByPrimaryKeySelective(overview);
long t6 = System.currentTimeMillis();
log.info("同步里程和总里程总耗时{}", t6 - t1);
}
......@@ -86,7 +111,6 @@ public class JourneyService {
//每条数据加一
deviceJourneyOverview.setTotalJourneyCount(1);
deviceJourneyOverview.setDistance(deviceJourneyDTO.getMileage());
deviceJourneyOverview.setId(deviceJourneyDTO.getId());
deviceJourneyOverview.setCreatedBy(deviceJourneyDTO.getCreatedBy());
deviceJourneyOverview.setUpdatedBy(deviceJourneyDTO.getUpdatedBy());
deviceJourneyOverview.setCreatedDate(new Date());
......@@ -110,7 +134,6 @@ public class JourneyService {
deviceJourney.setBeginAddress(deviceJourneyDTO.getBeginAddress());
deviceJourney.setEndAddress(deviceJourneyDTO.getEndAddress());
deviceJourney.setMileage(deviceJourneyDTO.getMileage());
deviceJourney.setId(deviceJourneyDTO.getId());
deviceJourney.setCreatedBy(createdBy);
deviceJourney.setUpdatedBy(updatedBy);
deviceJourney.setCreatedDate(new Date());
......
......@@ -3,17 +3,25 @@ package cn.com.glsx.stdinterface.modules.service;
import cn.com.glsx.stdinterface.dto.DeviceJourneyDTO;
import cn.com.glsx.stdinterface.modules.entity.Vehicle;
import cn.com.glsx.stdinterface.modules.entity.VehicleDevice;
import cn.com.glsx.stdinterface.modules.entity.VehicleDeviceOperator;
import cn.com.glsx.stdinterface.modules.entity.WorkOrder;
import cn.com.glsx.stdinterface.modules.mapper.VehicleDeviceMapper;
import cn.com.glsx.stdinterface.modules.mapper.VehicleMapper;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* 车辆服务
......@@ -32,14 +40,40 @@ public class VehicleService {
Vehicle vehicle = vehicleMapper.getVehicleBySn(sn);
return vehicle;
}
public List<VehicleDeviceOperator> getVehicleListBySn(Collection<String> sn) {
return vehicleMapper.listVehicleBySn(sn);
}
/**
* key:sn value:VehicleDeviceOperator
*/
public Map<String, VehicleDeviceOperator> getVehicleDeviceOperatorMap(List<String> snList) {
List<VehicleDeviceOperator> vehicleList = getVehicleListBySn(snList);
if(CollectionUtils.isEmpty(vehicleList)) {
return Maps.newHashMap();
}
return vehicleList.stream()
.filter(Objects::nonNull)
.collect(Collectors.toMap(VehicleDeviceOperator::getSn, Function.identity(), (o1, o2) -> o2));
}
public Long getVdId(String sn) {
VehicleDevice vehicleDevice = vehicleDeviceMapper.getVdIdbySn(sn);
Long vnId = null;
if(Objects.nonNull(vehicleDevice)) {
vnId = vehicleDevice.getId();
VehicleDevice vehicleDevice = vehicleDeviceMapper.selectVehicleDevcieBySn(sn);
return Optional.ofNullable(vehicleDevice)
.map(VehicleDevice::getId)
.orElse(null);
}
/**
* key:sn value:vdId
*/
public Map<String, Long> getSnVdIdMap(Collection<String> sn) {
List<VehicleDevice> vehicleDevice = vehicleDeviceMapper.selectBindingDevices(sn);
if (CollectionUtils.isEmpty(vehicleDevice)) {
return Maps.newHashMap();
}
return vnId;
return vehicleDevice.stream()
.collect(Collectors.toMap(VehicleDevice::getSn,VehicleDevice::getId, (o1, o2) -> o2));
}
public Vehicle getVehicleInfoByWorkOrderIdAndVin(Long workOrderId, String vin) {
......
......@@ -891,13 +891,10 @@ public class WorkOrderService {
locationRequest.setBsBackfillGps(true);
// V1.6.0需求
// 包活干请求新E盾平台,激活车辆档案时效,更新为3小时
// 新E盾审核工单时效,更新为24小时。
// 时效开始时间,以设备最新定位时间为准。
if (isApiCall) {
locationRequest.setGpsValidMinute(3 * 60);
locationRequest.setBsValidMinute(24 * 60);
} else {
// 包活干请求新E盾平台,激活车辆档案时效,GPS有效上点30分钟,基站有效上点24小时
// 新E盾审核工单时效,有效位置上点都更新为24小时
// 时效开始时间,以设备最新定位时间为准
if (!isApiCall) {
locationRequest.setGpsValidMinute(24 * 60);
locationRequest.setBsValidMinute(24 * 60);
}
......
package cn.com.glsx.stdinterface.modules.util;
/**
* @author xiangyanlin
* @date 2022/4/14
*/
public class ThreadPoolManager {
/**
* 服务器线程数
*/
private static final int N = Runtime.getRuntime().availableProcessors();
/**
* Io密集型任务线程数
*/
private static final int NUM_IO_CORE = 2 * N;
/**
* 计算密集型任务
*/
private final int NUM_COMPUTE_CORE = N + 1;
public static int getIoTaskThreadNum() {
return NUM_IO_CORE;
}
}
......@@ -70,7 +70,7 @@
<!-- table可以有多个,每个数据库中的表都可以写一个table,tableName表示要匹配的数据库表,也可以在tableName属性中通过使用%通配符来匹配所有数据库表,只有匹配的表才会自动生成文件 enableSelectByPrimaryKey相应的配置表示是否生成相应的接口 -->
<!-- <table tableName="t_workorder_insurance" domainObjectName="WorkOrderInsurance" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>-->
<table tableName="t_alarm_electric_fence" domainObjectName="AlarmElectricFence" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>
<table tableName="t_electric_fence" domainObjectName="ElectricFence" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>
<!-- <table tableName="t_alarm_electric_fence" domainObjectName="AlarmElectricFence" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>-->
<table tableName="t_device" domainObjectName="Device" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>
</context>
</generatorConfiguration>
\ No newline at end of file
......@@ -24,13 +24,17 @@
updated_date, updated_by
</sql>
<insert id="insertOrSumDistanceAndCount" parameterType="cn.com.glsx.stdinterface.modules.entity.DeviceJourneyOverview">
insert into t_device_journey_overview (sn, vd_id, total_journey_count, distance, created_date, created_by, updated_date, updated_by)
values (#{sn}, #{vdId}, #{totalJourneyCount},#{distance}, #{createdDate},#{createdBy}, #{updatedDate}, #{updatedBy})
ON DUPLICATE key
update
total_journey_count =total_journey_count + #{totalJourneyCount},
distance = distance + #{distance}
</insert>
<select id="selectBySnAndVdId" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_device_journey_overview
<where>
and sn = #{sn}
and vd_id = #{vdId}
</where>
limit 1
</select>
</mapper>
\ 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.DeviceMapper">
<resultMap id="BaseResultMap" type="cn.com.glsx.stdinterface.modules.entity.Device">
<!--
WARNING - @mbg.generated
-->
<id column="id" jdbcType="INTEGER" property="id" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="sn" jdbcType="VARCHAR" property="sn" />
<result column="imsi" jdbcType="VARCHAR" property="imsi" />
<result column="iccid" jdbcType="VARCHAR" property="iccid" />
<result column="imei" jdbcType="VARCHAR" property="imei" />
<result column="sim" jdbcType="VARCHAR" property="sim" />
<result column="check_code" jdbcType="VARCHAR" property="checkCode" />
<result column="device_type" jdbcType="INTEGER" property="deviceType" />
<result column="manufacturer" jdbcType="VARCHAR" property="manufacturer" />
<result column="model_id" jdbcType="INTEGER" property="modelId" />
<result column="model_name" jdbcType="VARCHAR" property="modelName" />
<result column="soft_version" jdbcType="VARCHAR" property="softVersion" />
<result column="source" jdbcType="TINYINT" property="source" />
<result column="activate_status" jdbcType="TINYINT" property="activateStatus" />
<result column="activate_time" jdbcType="TIMESTAMP" property="activateTime" />
<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, `name`, sn, imsi, iccid, imei, sim, check_code, device_type, manufacturer, model_id,
model_name, soft_version, `source`, activate_status, activate_time, del_flag, created_date,
created_by, updated_date, updated_by
</sql>
<select id="listSnBySource" resultType="String">
select sn
from t_device
<where>
and `source` = #{source}
and del_flag = 0
</where>
</select>
</mapper>
\ No newline at end of file
......@@ -38,4 +38,22 @@
limit 1
</select>
<insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
insert into t_device_power(sn, vd_id, alarm_time, soc, del_flag, created_date, created_by, updated_date, updated_by)
values
<foreach collection="entities" item="entity" separator=",">
(#{entity.sn}, #{entity.vdId}, #{entity.alarmTime}, #{entity.soc}, #{entity.delFlag}, #{entity.createdDate}, #{entity.createdBy}, #{entity.updatedDate}, #{entity.updatedBy})
</foreach>
on duplicate key update
sn = values(sn),
vd_id = values(vd_id),
alarm_time = values(alarm_time),
soc = values(soc),
del_flag = values(del_flag),
created_date = values(created_date),
created_by = values(created_by),
updated_date = values(updated_date),
updated_by = values(updated_by)
</insert>
</mapper>
\ No newline at end of file
......@@ -53,6 +53,12 @@
<result column="buy_type" jdbcType="DATE" property="buyType"/>
</resultMap>
<resultMap id="VehicleDeviceOperatorResultMap" type="cn.com.glsx.stdinterface.modules.entity.VehicleDeviceOperator">
<result column="sn" jdbcType="INTEGER" property="sn"/>
<result column="created_by" jdbcType="VARCHAR" property="createdBy"/>
<result column="updated_by" jdbcType="VARCHAR" property="updatedBy"/>
</resultMap>
<sql id="Base_Column_List">
<!--
WARNING - @mbg.generated
......@@ -153,4 +159,22 @@
and tv.del_flag = 0
and tvd.bind_status = 1
</select>
<select id="listVehicleBySn" resultMap="VehicleDeviceOperatorResultMap">
select
tvd.sn,
tv.created_by,
tv.updated_by
from t_vehicle tv
left join t_vehicle_device tvd on tv.id = tvd.vehicle_id
<where>
and tvd.del_flag = 0
and tv.del_flag = 0
and tvd.bind_status = 1
and tvd.sn in
<foreach collection="sn" separator="," open="(" close=")" item="item">
#{item}
</foreach>
</where>
</select>
</mapper>
\ No newline at end of file
package cn.com.glsx.stdinterface.modules.mapper;
import cn.com.glsx.Application;
import cn.com.glsx.stdinterface.modules.entity.DevicePower;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.Date;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
/**
* @author xiangyanlin
* @date 2022/4/15
*/
@Slf4j
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class DevicePowerMapperTest {
@Autowired
private DevicePowerMapper devicePowerMapper;
@Test
public void testInsertOrUpdateBatch(){
DevicePower devicePower = new DevicePower();
devicePower.setAlarmTime(new Date());
devicePower.setSn("1610507001");
devicePower.setSoc(99);
devicePower.setUpdatedDate(new Date());
List<DevicePower> list =Lists.newArrayList(devicePower);
devicePowerMapper.insertOrUpdateBatch(list);
}
}
\ 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!