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 1026 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 { ...@@ -28,4 +28,10 @@ public class BatteryController implements BatteryClient {
batteryService.saveBatteryInfo(devicePowerDTO); batteryService.saveBatteryInfo(devicePowerDTO);
return R.ok(); return R.ok();
} }
@PostMapping("/initDataFromOld")
public R moveDataFromOldDatabase() {
batteryService.initDataFromOld();
return R.ok();
}
} }
package cn.com.glsx.stdinterface.modules.entity;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.*;
@Table(name = "t_device")
public class Device implements Serializable {
@Id
private Integer id;
/**
* 设备名称
*/
private String name;
/**
* 设备序列号
*/
private String sn;
/**
* 国际移动用户识别码
*/
private String imsi;
/**
* 集成电路卡识别码
*/
private String iccid;
/**
* 国际移动设备识别码
*/
private String imei;
/**
* 用户识别卡
*/
private String sim;
/**
* 校验码
*/
@Column(name = "check_code")
private String checkCode;
/**
* 设备类型
*/
@Column(name = "device_type")
private Integer deviceType;
/**
* 设备厂商
*/
private String manufacturer;
/**
* 型号id
*/
@Column(name = "model_id")
private Integer modelId;
/**
* 型号名称
*/
@Column(name = "model_name")
private String modelName;
/**
* 固件版本
*/
@Column(name = "soft_version")
private String softVersion;
/**
* 1有源 0无源
*/
private Byte source;
/**
* 激活状态:0未激活,1激活
*/
@Column(name = "activate_status")
private Byte activateStatus;
/**
* 激活时间
*/
@Column(name = "activate_time")
private Date activateTime;
/**
* 是否删除 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;
/**
* @return id
*/
public Integer getId() {
return id;
}
/**
* @param id
*/
public void setId(Integer id) {
this.id = id;
}
/**
* 获取设备名称
*
* @return name - 设备名称
*/
public String getName() {
return name;
}
/**
* 设置设备名称
*
* @param name 设备名称
*/
public void setName(String name) {
this.name = name == null ? null : name.trim();
}
/**
* 获取设备序列号
*
* @return sn - 设备序列号
*/
public String getSn() {
return sn;
}
/**
* 设置设备序列号
*
* @param sn 设备序列号
*/
public void setSn(String sn) {
this.sn = sn == null ? null : sn.trim();
}
/**
* 获取国际移动用户识别码
*
* @return imsi - 国际移动用户识别码
*/
public String getImsi() {
return imsi;
}
/**
* 设置国际移动用户识别码
*
* @param imsi 国际移动用户识别码
*/
public void setImsi(String imsi) {
this.imsi = imsi == null ? null : imsi.trim();
}
/**
* 获取集成电路卡识别码
*
* @return iccid - 集成电路卡识别码
*/
public String getIccid() {
return iccid;
}
/**
* 设置集成电路卡识别码
*
* @param iccid 集成电路卡识别码
*/
public void setIccid(String iccid) {
this.iccid = iccid == null ? null : iccid.trim();
}
/**
* 获取国际移动设备识别码
*
* @return imei - 国际移动设备识别码
*/
public String getImei() {
return imei;
}
/**
* 设置国际移动设备识别码
*
* @param imei 国际移动设备识别码
*/
public void setImei(String imei) {
this.imei = imei == null ? null : imei.trim();
}
/**
* 获取用户识别卡
*
* @return sim - 用户识别卡
*/
public String getSim() {
return sim;
}
/**
* 设置用户识别卡
*
* @param sim 用户识别卡
*/
public void setSim(String sim) {
this.sim = sim == null ? null : sim.trim();
}
/**
* 获取校验码
*
* @return check_code - 校验码
*/
public String getCheckCode() {
return checkCode;
}
/**
* 设置校验码
*
* @param checkCode 校验码
*/
public void setCheckCode(String checkCode) {
this.checkCode = checkCode == null ? null : checkCode.trim();
}
/**
* 获取设备类型
*
* @return device_type - 设备类型
*/
public Integer getDeviceType() {
return deviceType;
}
/**
* 设置设备类型
*
* @param deviceType 设备类型
*/
public void setDeviceType(Integer deviceType) {
this.deviceType = deviceType;
}
/**
* 获取设备厂商
*
* @return manufacturer - 设备厂商
*/
public String getManufacturer() {
return manufacturer;
}
/**
* 设置设备厂商
*
* @param manufacturer 设备厂商
*/
public void setManufacturer(String manufacturer) {
this.manufacturer = manufacturer == null ? null : manufacturer.trim();
}
/**
* 获取型号id
*
* @return model_id - 型号id
*/
public Integer getModelId() {
return modelId;
}
/**
* 设置型号id
*
* @param modelId 型号id
*/
public void setModelId(Integer modelId) {
this.modelId = modelId;
}
/**
* 获取型号名称
*
* @return model_name - 型号名称
*/
public String getModelName() {
return modelName;
}
/**
* 设置型号名称
*
* @param modelName 型号名称
*/
public void setModelName(String modelName) {
this.modelName = modelName == null ? null : modelName.trim();
}
/**
* 获取固件版本
*
* @return soft_version - 固件版本
*/
public String getSoftVersion() {
return softVersion;
}
/**
* 设置固件版本
*
* @param softVersion 固件版本
*/
public void setSoftVersion(String softVersion) {
this.softVersion = softVersion == null ? null : softVersion.trim();
}
/**
* 获取1有源 0无源
*
* @return source - 1有源 0无源
*/
public Byte getSource() {
return source;
}
/**
* 设置1有源 0无源
*
* @param source 1有源 0无源
*/
public void setSource(Byte source) {
this.source = source;
}
/**
* 获取激活状态:0未激活,1激活
*
* @return activate_status - 激活状态:0未激活,1激活
*/
public Byte getActivateStatus() {
return activateStatus;
}
/**
* 设置激活状态:0未激活,1激活
*
* @param activateStatus 激活状态:0未激活,1激活
*/
public void setActivateStatus(Byte activateStatus) {
this.activateStatus = activateStatus;
}
/**
* 获取激活时间
*
* @return activate_time - 激活时间
*/
public Date getActivateTime() {
return activateTime;
}
/**
* 设置激活时间
*
* @param activateTime 激活时间
*/
public void setActivateTime(Date activateTime) {
this.activateTime = activateTime;
}
/**
* 获取是否删除 0=正常 -1=删除
*
* @return del_flag - 是否删除 0=正常 -1=删除
*/
public Byte getDelFlag() {
return delFlag;
}
/**
* 设置是否删除 0=正常 -1=删除
*
* @param delFlag 是否删除 0=正常 -1=删除
*/
public void setDelFlag(Byte delFlag) {
this.delFlag = delFlag;
}
/**
* 获取创建时间|入库时间
*
* @return created_date - 创建时间|入库时间
*/
public Date getCreatedDate() {
return createdDate;
}
/**
* 设置创建时间|入库时间
*
* @param createdDate 创建时间|入库时间
*/
public void setCreatedDate(Date createdDate) {
this.createdDate = createdDate;
}
/**
* 获取创建人用户id
*
* @return created_by - 创建人用户id
*/
public Integer getCreatedBy() {
return createdBy;
}
/**
* 设置创建人用户id
*
* @param createdBy 创建人用户id
*/
public void setCreatedBy(Integer createdBy) {
this.createdBy = createdBy;
}
/**
* 获取更新时间
*
* @return updated_date - 更新时间
*/
public Date getUpdatedDate() {
return updatedDate;
}
/**
* 设置更新时间
*
* @param updatedDate 更新时间
*/
public void setUpdatedDate(Date updatedDate) {
this.updatedDate = updatedDate;
}
/**
* 获取更新人用户id
*
* @return updated_by - 更新人用户id
*/
public Integer getUpdatedBy() {
return updatedBy;
}
/**
* 设置更新人用户id
*
* @param updatedBy 更新人用户id
*/
public void setUpdatedBy(Integer updatedBy) {
this.updatedBy = updatedBy;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", id=").append(id);
sb.append(", name=").append(name);
sb.append(", sn=").append(sn);
sb.append(", imsi=").append(imsi);
sb.append(", iccid=").append(iccid);
sb.append(", imei=").append(imei);
sb.append(", sim=").append(sim);
sb.append(", checkCode=").append(checkCode);
sb.append(", deviceType=").append(deviceType);
sb.append(", manufacturer=").append(manufacturer);
sb.append(", modelId=").append(modelId);
sb.append(", modelName=").append(modelName);
sb.append(", softVersion=").append(softVersion);
sb.append(", source=").append(source);
sb.append(", activateStatus=").append(activateStatus);
sb.append(", activateTime=").append(activateTime);
sb.append(", delFlag=").append(delFlag);
sb.append(", createdDate=").append(createdDate);
sb.append(", createdBy=").append(createdBy);
sb.append(", updatedDate=").append(updatedDate);
sb.append(", updatedBy=").append(updatedBy);
sb.append(", serialVersionUID=").append(serialVersionUID);
sb.append("]");
return sb.toString();
}
}
\ No newline at end of file \ No newline at end of file
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; ...@@ -3,6 +3,7 @@ package cn.com.glsx.stdinterface.modules.mapper;
import cn.com.glsx.stdinterface.modules.entity.DeviceJourneyOverview; import cn.com.glsx.stdinterface.modules.entity.DeviceJourneyOverview;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper; import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/** /**
* 新e盾|里程表总览 * 新e盾|里程表总览
...@@ -14,9 +15,10 @@ import org.apache.ibatis.annotations.Mapper; ...@@ -14,9 +15,10 @@ import org.apache.ibatis.annotations.Mapper;
public interface DeviceJourneyOverviewMapper extends CommonBaseMapper<DeviceJourneyOverview> { public interface DeviceJourneyOverviewMapper extends CommonBaseMapper<DeviceJourneyOverview> {
/** /**
* * 根据sn和vdId获取唯一 的 设备 统计里程
* 如果不存在就新增。 如果存在则累加总行程 总次数 * @param sn 设备号
* @param deviceJourneyOverview 传入新的行程值 * @param vdId 关联id
* @return 统计里程
*/ */
void insertOrSumDistanceAndCount(DeviceJourneyOverview deviceJourneyOverview); DeviceJourneyOverview selectBySnAndVdId(@Param("sn") String sn, @Param("vdId") Long vdId);
} }
\ No newline at end of file \ 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 \ No newline at end of file
...@@ -4,6 +4,8 @@ import cn.com.glsx.stdinterface.modules.entity.DevicePower; ...@@ -4,6 +4,8 @@ import cn.com.glsx.stdinterface.modules.entity.DevicePower;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper; import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper @Mapper
public interface DevicePowerMapper extends CommonBaseMapper<DevicePower> { public interface DevicePowerMapper extends CommonBaseMapper<DevicePower> {
...@@ -15,4 +17,11 @@ public interface DevicePowerMapper extends CommonBaseMapper<DevicePower> { ...@@ -15,4 +17,11 @@ public interface DevicePowerMapper extends CommonBaseMapper<DevicePower> {
*/ */
DevicePower selectBySn(String sn); DevicePower selectBySn(String sn);
/**
* 批量插入或修改
* @param entities
* @return
*/
int insertOrUpdateBatch(List<DevicePower> entities);
} }
\ No newline at end of file \ No newline at end of file
...@@ -17,6 +17,9 @@ import java.util.List; ...@@ -17,6 +17,9 @@ import java.util.List;
@Mapper @Mapper
public interface VehicleDeviceMapper extends CommonBaseMapper<VehicleDevice> { public interface VehicleDeviceMapper extends CommonBaseMapper<VehicleDevice> {
/**
* 取解绑状态设备
*/
VehicleDevice getVdIdbySn(@Param("sn") String sn); VehicleDevice getVdIdbySn(@Param("sn") String sn);
VehicleDevice selectBindingDeviceBySn(@Param("sn") String sn); VehicleDevice selectBindingDeviceBySn(@Param("sn") String sn);
...@@ -25,5 +28,8 @@ public interface VehicleDeviceMapper extends CommonBaseMapper<VehicleDevice> { ...@@ -25,5 +28,8 @@ public interface VehicleDeviceMapper extends CommonBaseMapper<VehicleDevice> {
List<VehicleDevice> selectBindingDevicesByVehicleId(@Param("vehicleId") Long vehicleId); List<VehicleDevice> selectBindingDevicesByVehicleId(@Param("vehicleId") Long vehicleId);
/**
* 取绑定状态设备
*/
VehicleDevice selectVehicleDevcieBySn(@Param("sn") String sn); VehicleDevice selectVehicleDevcieBySn(@Param("sn") String sn);
} }
...@@ -2,6 +2,7 @@ package cn.com.glsx.stdinterface.modules.mapper; ...@@ -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.Vehicle;
import cn.com.glsx.stdinterface.modules.entity.VehicleDeviceOperator;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper; import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
...@@ -29,4 +30,11 @@ public interface VehicleMapper extends CommonBaseMapper<Vehicle> { ...@@ -29,4 +30,11 @@ public interface VehicleMapper extends CommonBaseMapper<Vehicle> {
Vehicle selectByWorkOrderIdAndVin(@Param("workOrderId") Long workOrderId, @Param("vin") String vin); Vehicle selectByWorkOrderIdAndVin(@Param("workOrderId") Long workOrderId, @Param("vin") String vin);
Vehicle getVehicleByVdId(@Param("vdId") Long vdId); Vehicle getVehicleByVdId(@Param("vdId") Long vdId);
/**
* 根据sn获取
* @param sn 设备序列号
* @return 车辆列表
*/
List<VehicleDeviceOperator> listVehicleBySn(@Param("sn") Collection<String> sn);
} }
\ No newline at end of file \ 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; 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.dto.DevicePowerDTO;
import cn.com.glsx.stdinterface.modules.entity.DevicePower; import cn.com.glsx.stdinterface.modules.entity.DevicePower;
import cn.com.glsx.stdinterface.modules.entity.Vehicle; 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.DevicePowerMapper;
import cn.com.glsx.stdinterface.modules.mapper.VehicleDeviceMapper;
import cn.com.glsx.stdinterface.modules.mapper.VehicleMapper; 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 lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects; 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 { ...@@ -30,18 +44,21 @@ public class BatteryService {
@Resource @Resource
private VehicleService vehicleService; private VehicleService vehicleService;
@Resource
private DeviceMapper deviceMapper;
@Resource
private RemoteFeignDevicePowerService remoteFeignDevicePowerService;
/** /**
* 保存电量信息 * 保存电量信息
*/ */
public void saveBatteryInfo(DevicePowerDTO devicePowerDTO) { public void saveBatteryInfo(DevicePowerDTO devicePowerDTO) {
//从车辆信息中获取创建人信息 //从车辆信息中获取创建人信息
Vehicle vehicle = vehicleMapper.getVehicleBySn(devicePowerDTO.getSn()); Vehicle vehicle = vehicleMapper.getVehicleBySn(devicePowerDTO.getSn());
Long createdBy = null; Long createdBy = Optional.ofNullable(vehicle).map(Vehicle::getCreatedBy).orElse(null);
Long updatedBy = null; Long updatedBy = Optional.ofNullable(vehicle).map(Vehicle::getUpdatedBy).orElse(null);
if(Objects.nonNull(vehicle)) { if(Objects.isNull(vehicle)) {
createdBy = vehicle.getCreatedBy();
updatedBy = vehicle.getUpdatedBy();
} else {
log.warn("该设备没有绑定车辆" + devicePowerDTO.getSn()); log.warn("该设备没有绑定车辆" + devicePowerDTO.getSn());
} }
//从关联表从获取关联id //从关联表从获取关联id
...@@ -70,4 +87,85 @@ public class BatteryService { ...@@ -70,4 +87,85 @@ public class BatteryService {
return devicePower; 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; ...@@ -18,6 +18,7 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Date; import java.util.Date;
import java.util.Objects; import java.util.Objects;
import java.util.Optional;
/** /**
* 新e盾|里程服务实现类 * 新e盾|里程服务实现类
...@@ -46,10 +47,13 @@ public class JourneyService { ...@@ -46,10 +47,13 @@ public class JourneyService {
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void saveDeviceJourney(DeviceJourneyDTO deviceJourneyDTO) { public void saveDeviceJourney(DeviceJourneyDTO deviceJourneyDTO) {
long t1 = System.currentTimeMillis();
if (Objects.isNull(deviceJourneyDTO)) { if (Objects.isNull(deviceJourneyDTO)) {
return; return;
} }
DeviceJourney journey = deviceJourneyMapper.selectBySnAndBeginTime(deviceJourneyDTO.getSn(), deviceJourneyDTO.getBeginTime()); DeviceJourney journey = deviceJourneyMapper.selectBySnAndBeginTime(deviceJourneyDTO.getSn(), deviceJourneyDTO.getBeginTime());
long t2 = System.currentTimeMillis();
log.info("重复校验时间{}", t2 - t1);
if(Objects.nonNull(journey)) { if(Objects.nonNull(journey)) {
log.warn("该设备同样的开始时间行程数据已经存在" + log.warn("该设备同样的开始时间行程数据已经存在" +
"sn: " + deviceJourneyDTO.getSn() + "beginTime:" + DateUtils.formatNormal(deviceJourneyDTO.getBeginTime())); "sn: " + deviceJourneyDTO.getSn() + "beginTime:" + DateUtils.formatNormal(deviceJourneyDTO.getBeginTime()));
...@@ -58,23 +62,44 @@ public class JourneyService { ...@@ -58,23 +62,44 @@ public class JourneyService {
//从车辆信息中获取创建人信息 //从车辆信息中获取创建人信息
Vehicle vehicle = getVehicleBySn(deviceJourneyDTO.getSn()); Vehicle vehicle = getVehicleBySn(deviceJourneyDTO.getSn());
Long createdBy = null; Long createdBy = Optional.ofNullable(vehicle).map(Vehicle::getCreatedBy).orElse(null);
Long updatedBy = null; Long updatedBy = Optional.ofNullable(vehicle).map(Vehicle::getUpdatedBy).orElse(null);
if (Objects.nonNull(vehicle)) { long t3 = System.currentTimeMillis();
createdBy = vehicle.getCreatedBy(); log.info("获取创建人时间{}", t3 - t2);
updatedBy = vehicle.getUpdatedBy();
} else {
log.warn("该设备没有绑定车辆" + deviceJourneyDTO.getSn());
}
//从关联表从获取关联id //从关联表从获取关联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); deviceJourneyMapper.insert(deviceJourney);
//如果行程数据的设备未关联车辆 不计入从次数和总信息
if(Objects.isNull(vdId)) {
log.warn("该设备没有绑定车辆" + deviceJourneyDTO.getSn());
log.info("同步里程总耗时{}", t4 - t1);
return;
}
//更新总行程次数 总里程 //更新总行程次数 总里程
DeviceJourneyOverview overview = buildOverviewWitheJourney(deviceJourneyDTO, vnId, createdBy, updatedBy); DeviceJourneyOverview overviewDO = buildOverviewWitheJourney(deviceJourneyDTO, vdId, createdBy, updatedBy);
deviceJourneyOverviewMapper.insertOrSumDistanceAndCount(overview); 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 { ...@@ -86,7 +111,6 @@ public class JourneyService {
//每条数据加一 //每条数据加一
deviceJourneyOverview.setTotalJourneyCount(1); deviceJourneyOverview.setTotalJourneyCount(1);
deviceJourneyOverview.setDistance(deviceJourneyDTO.getMileage()); deviceJourneyOverview.setDistance(deviceJourneyDTO.getMileage());
deviceJourneyOverview.setId(deviceJourneyDTO.getId());
deviceJourneyOverview.setCreatedBy(deviceJourneyDTO.getCreatedBy()); deviceJourneyOverview.setCreatedBy(deviceJourneyDTO.getCreatedBy());
deviceJourneyOverview.setUpdatedBy(deviceJourneyDTO.getUpdatedBy()); deviceJourneyOverview.setUpdatedBy(deviceJourneyDTO.getUpdatedBy());
deviceJourneyOverview.setCreatedDate(new Date()); deviceJourneyOverview.setCreatedDate(new Date());
...@@ -110,7 +134,6 @@ public class JourneyService { ...@@ -110,7 +134,6 @@ public class JourneyService {
deviceJourney.setBeginAddress(deviceJourneyDTO.getBeginAddress()); deviceJourney.setBeginAddress(deviceJourneyDTO.getBeginAddress());
deviceJourney.setEndAddress(deviceJourneyDTO.getEndAddress()); deviceJourney.setEndAddress(deviceJourneyDTO.getEndAddress());
deviceJourney.setMileage(deviceJourneyDTO.getMileage()); deviceJourney.setMileage(deviceJourneyDTO.getMileage());
deviceJourney.setId(deviceJourneyDTO.getId());
deviceJourney.setCreatedBy(createdBy); deviceJourney.setCreatedBy(createdBy);
deviceJourney.setUpdatedBy(updatedBy); deviceJourney.setUpdatedBy(updatedBy);
deviceJourney.setCreatedDate(new Date()); deviceJourney.setCreatedDate(new Date());
......
...@@ -3,17 +3,25 @@ package cn.com.glsx.stdinterface.modules.service; ...@@ -3,17 +3,25 @@ package cn.com.glsx.stdinterface.modules.service;
import cn.com.glsx.stdinterface.dto.DeviceJourneyDTO; import cn.com.glsx.stdinterface.dto.DeviceJourneyDTO;
import cn.com.glsx.stdinterface.modules.entity.Vehicle; import cn.com.glsx.stdinterface.modules.entity.Vehicle;
import cn.com.glsx.stdinterface.modules.entity.VehicleDevice; 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.entity.WorkOrder;
import cn.com.glsx.stdinterface.modules.mapper.VehicleDeviceMapper; import cn.com.glsx.stdinterface.modules.mapper.VehicleDeviceMapper;
import cn.com.glsx.stdinterface.modules.mapper.VehicleMapper; import cn.com.glsx.stdinterface.modules.mapper.VehicleMapper;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Objects; 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 { ...@@ -32,14 +40,40 @@ public class VehicleService {
Vehicle vehicle = vehicleMapper.getVehicleBySn(sn); Vehicle vehicle = vehicleMapper.getVehicleBySn(sn);
return vehicle; 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) { public Long getVdId(String sn) {
VehicleDevice vehicleDevice = vehicleDeviceMapper.getVdIdbySn(sn); VehicleDevice vehicleDevice = vehicleDeviceMapper.selectVehicleDevcieBySn(sn);
Long vnId = null; return Optional.ofNullable(vehicleDevice)
if(Objects.nonNull(vehicleDevice)) { .map(VehicleDevice::getId)
vnId = 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) { public Vehicle getVehicleInfoByWorkOrderIdAndVin(Long workOrderId, String vin) {
......
...@@ -891,13 +891,10 @@ public class WorkOrderService { ...@@ -891,13 +891,10 @@ public class WorkOrderService {
locationRequest.setBsBackfillGps(true); locationRequest.setBsBackfillGps(true);
// V1.6.0需求 // V1.6.0需求
// 包活干请求新E盾平台,激活车辆档案时效,更新为3小时 // 包活干请求新E盾平台,激活车辆档案时效,GPS有效上点30分钟,基站有效上点24小时
// 新E盾审核工单时效,更新为24小时。 // 新E盾审核工单时效,有效位置上点都更新为24小时
// 时效开始时间,以设备最新定位时间为准。 // 时效开始时间,以设备最新定位时间为准
if (isApiCall) { if (!isApiCall) {
locationRequest.setGpsValidMinute(3 * 60);
locationRequest.setBsValidMinute(24 * 60);
} else {
locationRequest.setGpsValidMinute(24 * 60); locationRequest.setGpsValidMinute(24 * 60);
locationRequest.setBsValidMinute(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 @@ ...@@ -70,7 +70,7 @@
<!-- table可以有多个,每个数据库中的表都可以写一个table,tableName表示要匹配的数据库表,也可以在tableName属性中通过使用%通配符来匹配所有数据库表,只有匹配的表才会自动生成文件 enableSelectByPrimaryKey相应的配置表示是否生成相应的接口 --> <!-- 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_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_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_device" domainObjectName="Device" 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
...@@ -24,13 +24,17 @@ ...@@ -24,13 +24,17 @@
updated_date, updated_by updated_date, updated_by
</sql> </sql>
<insert id="insertOrSumDistanceAndCount" parameterType="cn.com.glsx.stdinterface.modules.entity.DeviceJourneyOverview"> <select id="selectBySnAndVdId" resultMap="BaseResultMap">
insert into t_device_journey_overview (sn, vd_id, total_journey_count, distance, created_date, created_by, updated_date, updated_by) select
values (#{sn}, #{vdId}, #{totalJourneyCount},#{distance}, #{createdDate},#{createdBy}, #{updatedDate}, #{updatedBy}) <include refid="Base_Column_List"/>
ON DUPLICATE key from t_device_journey_overview
update <where>
total_journey_count =total_journey_count + #{totalJourneyCount}, and sn = #{sn}
distance = distance + #{distance} and vd_id = #{vdId}
</insert> </where>
limit 1
</select>
</mapper> </mapper>
\ 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.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 \ No newline at end of file
...@@ -38,4 +38,22 @@ ...@@ -38,4 +38,22 @@
limit 1 limit 1
</select> </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> </mapper>
\ No newline at end of file \ No newline at end of file
...@@ -53,6 +53,12 @@ ...@@ -53,6 +53,12 @@
<result column="buy_type" jdbcType="DATE" property="buyType"/> <result column="buy_type" jdbcType="DATE" property="buyType"/>
</resultMap> </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"> <sql id="Base_Column_List">
<!-- <!--
WARNING - @mbg.generated WARNING - @mbg.generated
...@@ -153,4 +159,22 @@ ...@@ -153,4 +159,22 @@
and tv.del_flag = 0 and tv.del_flag = 0
and tvd.bind_status = 1 and tvd.bind_status = 1
</select> </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> </mapper>
\ No newline at end of file \ 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 \ 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!