# update 更新导入 设备属性的功能
This commit is contained in:
@@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.annotation.IdType;
|
|||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
|
||||||
|
import com.maibu.annotation.Excel;
|
||||||
import com.maibu.constant.CommandConstant;
|
import com.maibu.constant.CommandConstant;
|
||||||
import com.maibu.core.domain.BaseDO;
|
import com.maibu.core.domain.BaseDO;
|
||||||
|
|
||||||
@@ -13,6 +15,7 @@ import lombok.EqualsAndHashCode;
|
|||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@Data
|
@Data
|
||||||
@@ -22,7 +25,7 @@ public class DeviceRunParam extends BaseDO {
|
|||||||
@TableId(type = IdType.AUTO)
|
@TableId(type = IdType.AUTO)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
private String deviceId;
|
// private String deviceId;
|
||||||
|
|
||||||
private Long siteId;
|
private Long siteId;
|
||||||
|
|
||||||
@@ -30,6 +33,40 @@ public class DeviceRunParam extends BaseDO {
|
|||||||
|
|
||||||
private Integer runSpeed; //不下发到设备自己用
|
private Integer runSpeed; //不下发到设备自己用
|
||||||
|
|
||||||
|
@Excel(name = "设备序列号", cellType = Excel.ColumnType.STRING, prompt = "设备序列号")
|
||||||
|
private String deviceId;//设备序列号
|
||||||
|
|
||||||
|
@Excel(name = "产品型号", cellType = Excel.ColumnType.STRING, prompt = "产品型号")
|
||||||
|
private String productModel;//产品型号
|
||||||
|
|
||||||
|
@Excel(name = "设备类型", cellType = Excel.ColumnType.STRING, prompt = "设备类型")
|
||||||
|
private String deviceType;//设备类型:mower-割草机器人
|
||||||
|
|
||||||
|
@Excel(name = "RTK模式", cellType = Excel.ColumnType.STRING, prompt = "RTK模式")
|
||||||
|
private String rtkMode;//RTK模式:network-4G网络差分
|
||||||
|
|
||||||
|
@Excel(name = "摄像头数量", cellType = Excel.ColumnType.STRING, prompt = "摄像头数量")
|
||||||
|
private Integer cameraNum;//摄像头数量
|
||||||
|
|
||||||
|
@Excel(name = "动力类型", cellType = Excel.ColumnType.STRING, prompt = "动力类型")
|
||||||
|
private String powerType;//动力类型:hybrid-混动
|
||||||
|
|
||||||
|
@Excel(name = "车轮类型", cellType = Excel.ColumnType.STRING, prompt = "车轮类型")
|
||||||
|
private String wheelType;//车轮类型:track-履带式
|
||||||
|
|
||||||
|
@Excel(name = "发动机类型", cellType = Excel.ColumnType.STRING, prompt = "发动机类型")
|
||||||
|
private String engineType;//发动机类型:honda-本田发动机
|
||||||
|
|
||||||
|
@Excel(name = "是否搭载上位机",cellType = Excel.ColumnType.NUMERIC)
|
||||||
|
private Integer hasHost;//是否搭载上位机
|
||||||
|
|
||||||
|
@Excel(name = "设备能力列表")
|
||||||
|
@TableField(exist = false)
|
||||||
|
private String capabilities;
|
||||||
|
|
||||||
|
@TableField(typeHandler = JacksonTypeHandler.class)
|
||||||
|
private List<String> capabilityList;//设备能力列表:heartbeat-上报心跳/location-上报位置/vehicle_status-上报整机状态/task_control-任务控制/single_point-单点作业/coverage-全覆盖割草作业/path_upload-作业路径上传
|
||||||
|
|
||||||
|
|
||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
public byte header1;
|
public byte header1;
|
||||||
@@ -117,112 +154,6 @@ public class DeviceRunParam extends BaseDO {
|
|||||||
return buffer.array();
|
return buffer.array();
|
||||||
}
|
}
|
||||||
|
|
||||||
// public static byte[] toWriteBytes(DeviceRunParam p) {
|
|
||||||
//
|
|
||||||
// ByteBuffer buffer = ByteBuffer.allocate(178);
|
|
||||||
// buffer.order(ByteOrder.LITTLE_ENDIAN);
|
|
||||||
//
|
|
||||||
// // 包头
|
|
||||||
// buffer.put((byte) 0xAB);
|
|
||||||
// buffer.put((byte) 0xAA);
|
|
||||||
//
|
|
||||||
// // 指令
|
|
||||||
// buffer.put(CommandConstant.writeConfig);
|
|
||||||
//
|
|
||||||
// // UID固化标志
|
|
||||||
// buffer.put(p.getChipUidSign());
|
|
||||||
//
|
|
||||||
// // UID
|
|
||||||
// putFixedString(buffer, p.getChipUid(), 45);
|
|
||||||
//
|
|
||||||
// // Byte68
|
|
||||||
// byte remote = 0;
|
|
||||||
// remote |= (p.getKnifeMotorMode() & 0x03);
|
|
||||||
// remote |= (p.getWalkMotorMode() & 0x03) << 2;
|
|
||||||
// remote |= (p.getLeftMotorReverse() & 0x01) << 4;
|
|
||||||
// remote |= (p.getRightMotorReverse() & 0x01) << 5;
|
|
||||||
// remote |= (p.getSwapChannel() & 0x01) << 6;
|
|
||||||
// remote |= (p.getUse4G() & 0x01) << 7;
|
|
||||||
// buffer.put(remote);
|
|
||||||
//
|
|
||||||
// // 69~72
|
|
||||||
// buffer.putShort((short) p.getForwardSpeedLimit());
|
|
||||||
// buffer.putShort((short) p.getTurnSpeedLimit());
|
|
||||||
//
|
|
||||||
// //73
|
|
||||||
// byte b73 = 0;
|
|
||||||
// b73 |= (p.getKnifePolarity() & 1);
|
|
||||||
// b73 |= (p.getFanPolarity() & 1) << 1;
|
|
||||||
// b73 |= (p.getThrottlePolarity() & 1) << 2;
|
|
||||||
// b73 |= (p.getLiftProtectTime() & 0x0F) << 3;
|
|
||||||
// b73 |= (p.getDualRtk() & 1) << 7;
|
|
||||||
// buffer.put(b73);
|
|
||||||
//
|
|
||||||
// //74
|
|
||||||
// byte b74 = 0;
|
|
||||||
// b74 |= (p.getKnifeChannel() & 0x0F);
|
|
||||||
// b74 |= (p.getFanChannel() & 0x0F) << 4;
|
|
||||||
// buffer.put(b74);
|
|
||||||
//
|
|
||||||
// //75
|
|
||||||
// byte b75 = 0;
|
|
||||||
// b75 |= (p.getThrottleChannel() & 0x0F);
|
|
||||||
// b75 |= (p.getRemoteType() & 0x07) << 4;
|
|
||||||
// if (p.isRelayBoard()) {
|
|
||||||
// b75 |= 1 << 7;
|
|
||||||
// }
|
|
||||||
// buffer.put(b75);
|
|
||||||
//
|
|
||||||
// //76
|
|
||||||
// byte b76 = 0;
|
|
||||||
// b76 |= (p.getLiftChannel() & 0x0F);
|
|
||||||
// b76 |= (p.getChassisChannel() & 0x0F) << 4;
|
|
||||||
// buffer.put(b76);
|
|
||||||
//
|
|
||||||
// //77
|
|
||||||
// byte b77 = 0;
|
|
||||||
// b77 |= (p.getArmChannel() & 0x0F);
|
|
||||||
// b77 |= (p.getFuelPumpChannel() & 0x0F) << 4;
|
|
||||||
// buffer.put(b77);
|
|
||||||
//
|
|
||||||
// //wifi
|
|
||||||
// putFixedString(buffer, p.getWifiName(), 20);
|
|
||||||
// putFixedString(buffer, p.getWifiPassword(), 20);
|
|
||||||
//
|
|
||||||
// //118
|
|
||||||
// byte b118 = 0;
|
|
||||||
// b118 |= (p.getBatteryType() & 0x03);
|
|
||||||
// b118 |= (p.getDriveType() & 0x03) << 2;
|
|
||||||
// buffer.put(b118);
|
|
||||||
//
|
|
||||||
// //119~158 float
|
|
||||||
// buffer.putFloat(p.getGearRatio());
|
|
||||||
// buffer.putFloat(p.getRobotLength());
|
|
||||||
// buffer.putFloat(p.getRobotWidth());
|
|
||||||
// buffer.putFloat(p.getRobotHeight());
|
|
||||||
// buffer.putFloat(p.getKnifeWidth());
|
|
||||||
// buffer.putFloat(p.getTyreSize());
|
|
||||||
// buffer.putFloat(p.getLeftForwardGain());
|
|
||||||
// buffer.putFloat(p.getLeftBackwardGain());
|
|
||||||
// buffer.putFloat(p.getRightForwardGain());
|
|
||||||
// buffer.putFloat(p.getRightBackwardGain());
|
|
||||||
//
|
|
||||||
// //159~173
|
|
||||||
// putFixedString(buffer, p.getFirmwareVersion(), 15);
|
|
||||||
//
|
|
||||||
// //CRC
|
|
||||||
//
|
|
||||||
// / / byte[] bytes = buffer.array();
|
|
||||||
// / / int crc = CRC16Util.crc16(bytes, 0, 174);
|
|
||||||
// buffer.putShort((short) 0);
|
|
||||||
//
|
|
||||||
// //Tail
|
|
||||||
// buffer.put((byte) 0xAA);
|
|
||||||
// buffer.put((byte) 0xAB);
|
|
||||||
//
|
|
||||||
// return buffer.array();
|
|
||||||
// }
|
|
||||||
|
|
||||||
public byte[] toWriteBytes() {
|
public byte[] toWriteBytes() {
|
||||||
// 如果没有原始数据,使用静态方法重新构建
|
// 如果没有原始数据,使用静态方法重新构建
|
||||||
if (originalData == null || originalData.length < 178) {
|
if (originalData == null || originalData.length < 178) {
|
||||||
|
|||||||
@@ -4,6 +4,11 @@ import java.util.List;
|
|||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
|
import com.maibu.annotation.Log;
|
||||||
|
import com.maibu.core.domain.entity.SysUser;
|
||||||
|
import com.maibu.enums.BusinessType;
|
||||||
|
import com.maibu.utils.poi.ExcelUtil;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
@@ -18,6 +23,7 @@ import com.maibu.core.domain.AjaxResult;
|
|||||||
import com.maibu.core.page.TableDataInfo;
|
import com.maibu.core.page.TableDataInfo;
|
||||||
import com.maibu.dto.BaseQueryDTO;
|
import com.maibu.dto.BaseQueryDTO;
|
||||||
import com.maibu.service.impl.DeviceRunParamService;
|
import com.maibu.service.impl.DeviceRunParamService;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/iot/deviceRunParam")
|
@RequestMapping("/iot/deviceRunParam")
|
||||||
@@ -47,5 +53,12 @@ public class DeviceRunParamController extends BaseController {
|
|||||||
public AjaxResult delete(@RequestBody List<Long> ids) {
|
public AjaxResult delete(@RequestBody List<Long> ids) {
|
||||||
return AjaxResult.success(service.delete(ids));
|
return AjaxResult.success(service.delete(ids));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/importData")
|
||||||
|
public AjaxResult importData(MultipartFile file) throws Exception {
|
||||||
|
ExcelUtil<DeviceRunParam> util = new ExcelUtil<DeviceRunParam>(DeviceRunParam.class);
|
||||||
|
List<DeviceRunParam> paramList = util.importExcel(file.getInputStream());
|
||||||
|
boolean message = service.importParam(paramList);
|
||||||
|
return success(message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.maibu.service.impl;
|
package com.maibu.service.impl;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.maibu.annotation.Excel;
|
||||||
import com.maibu.constant.Constant;
|
import com.maibu.constant.Constant;
|
||||||
import com.maibu.core.business.DeviceRunParam;
|
import com.maibu.core.business.DeviceRunParam;
|
||||||
import com.maibu.core.business.device.NettyDevice;
|
import com.maibu.core.business.device.NettyDevice;
|
||||||
@@ -16,11 +17,16 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -130,5 +136,56 @@ public class DeviceRunParamService {
|
|||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean importParam(List<DeviceRunParam> params) {
|
||||||
|
try {
|
||||||
|
if (!CollectionUtils.isEmpty(params)) {
|
||||||
|
|
||||||
|
List<String> snList = params.stream().map(DeviceRunParam::getDeviceId).collect(Collectors.toList());
|
||||||
|
|
||||||
|
if (!CollectionUtils.isEmpty(snList)) {
|
||||||
|
LambdaQueryWrapper<DeviceRunParam> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
queryWrapper.in(DeviceRunParam::getDeviceId, snList);
|
||||||
|
List<DeviceRunParam> oldList = deviceRunParamMapper.selectList(queryWrapper);
|
||||||
|
Map<String, DeviceRunParam> map = oldList.stream()
|
||||||
|
.collect(Collectors.toMap(
|
||||||
|
DeviceRunParam::getDeviceId,
|
||||||
|
Function.identity()
|
||||||
|
));
|
||||||
|
List<DeviceRunParam> saveList = new ArrayList<>();
|
||||||
|
params.forEach(x -> {
|
||||||
|
DeviceRunParam deviceRunParam = null;
|
||||||
|
if (!CollectionUtils.isEmpty(map)) {
|
||||||
|
deviceRunParam = map.get(x.getDeviceId());
|
||||||
|
}
|
||||||
|
if (!StringUtils.isEmpty(x.getCapabilities())) {
|
||||||
|
List<String> list = Arrays.stream(x.getCapabilities().split(","))
|
||||||
|
.map(String::trim)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
x.setCapabilityList(list);
|
||||||
|
}
|
||||||
|
if (deviceRunParam != null) {
|
||||||
|
deviceRunParam.setCapabilityList(x.getCapabilityList());
|
||||||
|
deviceRunParam.setProductModel(x.getProductModel());
|
||||||
|
deviceRunParam.setRtkMode(x.getRtkMode());
|
||||||
|
deviceRunParam.setDeviceType(x.getDeviceType());
|
||||||
|
deviceRunParam.setPowerType(x.getPowerType());
|
||||||
|
deviceRunParam.setCameraNum(x.getCameraNum());
|
||||||
|
deviceRunParam.setWheelType(x.getWheelType());
|
||||||
|
deviceRunParam.setEngineType(x.getEngineType());
|
||||||
|
deviceRunParam.setHasHost(x.getHasHost());
|
||||||
|
saveList.add(deviceRunParam);
|
||||||
|
} else {
|
||||||
|
saveList.add(x);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return deviceRunParamMapper.saveOrUpdateBatch(saveList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user