解决设备修改报错,设备导出报错等问题,设备按照创建时间排序

master
yangxiaozhong 2 weeks ago
parent c67d28ce7d
commit 712821ebd8

@ -2,7 +2,6 @@ package org.dromara.hazard.controller;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
@ -57,7 +56,6 @@ public class IotDeviceController extends BaseController {
List<IotDeviceVo> list = iotDeviceService.queryList(bo); List<IotDeviceVo> list = iotDeviceService.queryList(bo);
ExcelUtil.exportExcel(list, "设备", IotDeviceVo.class, response); ExcelUtil.exportExcel(list, "设备", IotDeviceVo.class, response);
} }
/** /**
* *
* *
@ -108,7 +106,8 @@ public class IotDeviceController extends BaseController {
public R<Void> edit(@Validated(EditGroup.class) @RequestBody IotDeviceBo bo) { public R<Void> edit(@Validated(EditGroup.class) @RequestBody IotDeviceBo bo) {
String deviceCode = bo.getDeviceCode(); String deviceCode = bo.getDeviceCode();
IotDeviceVo deviceVo = iotDeviceService.queryByDeviceCode(deviceCode); IotDeviceVo deviceVo = iotDeviceService.queryByDeviceCode(deviceCode);
if (deviceVo!=null && deviceVo.getDeviceCode() != null){ String deviceCode1 = iotDeviceService.queryById(bo.getId()).getDeviceCode();
if (!deviceCode1.equals(deviceCode) && deviceVo!=null && deviceVo.getDeviceCode() != null){
return R.fail("设备编号已存在"); return R.fail("设备编号已存在");
} }
return toAjax(iotDeviceService.updateByBo(bo)); return toAjax(iotDeviceService.updateByBo(bo));

@ -116,12 +116,14 @@ public class IotSensorController extends BaseController {
public R<Void> edit(@Validated(EditGroup.class) @RequestBody IotSensorBo bo) { public R<Void> edit(@Validated(EditGroup.class) @RequestBody IotSensorBo bo) {
String code = bo.getCode(); String code = bo.getCode();
String name = bo.getName(); String name = bo.getName();
String orginName = iotSensorService.queryById(bo.getId()).getName();
String orginCode = iotSensorService.queryById(bo.getId()).getCode();
IotSensorVo iotSensorVo = iotSensorService.queryByCode(code); IotSensorVo iotSensorVo = iotSensorService.queryByCode(code);
IotSensorVo iotSensorVo1 = iotSensorService.queryByName(name); IotSensorVo iotSensorVo1 = iotSensorService.queryByName(name);
if (iotSensorVo!=null && iotSensorVo.getCode()!=null){ if (iotSensorVo!=null && iotSensorVo.getCode()!=null && !iotSensorVo.getCode().equals(orginCode)){
return R.fail("传感器已存在"); return R.fail("传感器已存在");
} }
if (iotSensorVo1!=null && iotSensorVo1.getName()!=null){ if (iotSensorVo1!=null && iotSensorVo1.getName()!=null && !iotSensorVo1.getName().equals(orginName)){
return R.fail("传感器已存在"); return R.fail("传感器已存在");
} }
return toAjax(iotSensorService.updateByBo(bo)); return toAjax(iotSensorService.updateByBo(bo));

@ -45,6 +45,7 @@ public class IotDeviceVo implements Serializable {
*/ */
@ExcelProperty(value = "拥有传感器(多个逗号分割)") @ExcelProperty(value = "拥有传感器(多个逗号分割)")
private String sensorCode; private String sensorCode;
private List<String> sensorCodes; private List<String> sensorCodes;
/** /**
* (线/线) * (线/线)
@ -68,8 +69,8 @@ public class IotDeviceVo implements Serializable {
/** /**
* $column.columnComment * $column.columnComment
*/ */
@ExcelProperty(value = "${comment}", converter = ExcelDictConvert.class) @ExcelProperty(value = "备注")
@ExcelDictFormat(readConverterExp = "$column.readConverterExp()") // @ExcelDictFormat(readConverterExp = "$column.readConverterExp()")
private String remark; private String remark;
/** /**
@ -99,6 +100,7 @@ public class IotDeviceVo implements Serializable {
/** /**
* id * id
*/ */
@ExcelProperty(value = "租户id")
private String tenantId; private String tenantId;
} }

@ -82,7 +82,7 @@ public class IotDeviceServiceImpl implements IIotDeviceService {
private LambdaQueryWrapper<IotDevice> buildQueryWrapper(IotDeviceBo bo) { private LambdaQueryWrapper<IotDevice> buildQueryWrapper(IotDeviceBo bo) {
Map<String, Object> params = bo.getParams(); Map<String, Object> params = bo.getParams();
LambdaQueryWrapper<IotDevice> lqw = Wrappers.lambdaQuery(); LambdaQueryWrapper<IotDevice> lqw = Wrappers.lambdaQuery();
lqw.orderByAsc(IotDevice::getId); lqw.orderByAsc(IotDevice::getCreateTime);
lqw.like(StringUtils.isNotBlank(bo.getName()), IotDevice::getName, bo.getName()); lqw.like(StringUtils.isNotBlank(bo.getName()), IotDevice::getName, bo.getName());
lqw.eq(StringUtils.isNotBlank(bo.getSensorCode()), IotDevice::getSensorCode, bo.getSensorCode()); lqw.eq(StringUtils.isNotBlank(bo.getSensorCode()), IotDevice::getSensorCode, bo.getSensorCode());
lqw.eq(StringUtils.isNotBlank(bo.getStatus()), IotDevice::getStatus, bo.getStatus()); lqw.eq(StringUtils.isNotBlank(bo.getStatus()), IotDevice::getStatus, bo.getStatus());
@ -92,6 +92,7 @@ public class IotDeviceServiceImpl implements IIotDeviceService {
lqw.eq(StringUtils.isNotBlank(bo.getTxt1()), IotDevice::getTxt1, bo.getTxt1()); lqw.eq(StringUtils.isNotBlank(bo.getTxt1()), IotDevice::getTxt1, bo.getTxt1());
lqw.eq(StringUtils.isNotBlank(bo.getTxt2()), IotDevice::getTxt2, bo.getTxt2()); lqw.eq(StringUtils.isNotBlank(bo.getTxt2()), IotDevice::getTxt2, bo.getTxt2());
lqw.eq(StringUtils.isNotBlank(bo.getTxt3()), IotDevice::getTxt3, bo.getTxt3()); lqw.eq(StringUtils.isNotBlank(bo.getTxt3()), IotDevice::getTxt3, bo.getTxt3());
return lqw; return lqw;
} }
@ -106,15 +107,19 @@ public class IotDeviceServiceImpl implements IIotDeviceService {
public Boolean insertByBo(IotDeviceBo bo) { public Boolean insertByBo(IotDeviceBo bo) {
IotDevice add = MapstructUtils.convert(bo, IotDevice.class); IotDevice add = MapstructUtils.convert(bo, IotDevice.class);
validEntityBeforeSave(add); validEntityBeforeSave(add);
if (bo.getSensorCodes()!=null && bo.getSensorCodes().length>0){
String join = String.join(",", bo.getSensorCodes()); String join = String.join(",", bo.getSensorCodes());
if (add != null) { if (add != null) {
add.setStatus("0"); add.setStatus("0");
add.setSensorCode(join); add.setSensorCode(join);
} }
}
boolean flag = baseMapper.insert(add) > 0; boolean flag = baseMapper.insert(add) > 0;
if (flag) { if (flag) {
bo.setId(add.getId()); bo.setId(add.getId());
//将设备id保存到传感器的绑定设备字段中去device_bound //将设备id保存到传感器的绑定设备字段中去device_bound
if (bo.getSensorCodes()!=null && bo.getSensorCodes().length>0){
List<String> list = Arrays.stream(bo.getSensorCodes()).toList(); List<String> list = Arrays.stream(bo.getSensorCodes()).toList();
for (String s : list) { for (String s : list) {
IotSensorVo iotSensorVo = iotSensorService.queryById(Long.valueOf(s)); IotSensorVo iotSensorVo = iotSensorService.queryById(Long.valueOf(s));
@ -124,6 +129,8 @@ public class IotDeviceServiceImpl implements IIotDeviceService {
iotSensorService.updateByBo(iotSensorBo); iotSensorService.updateByBo(iotSensorBo);
} }
} }
}
return flag; return flag;
} }

Loading…
Cancel
Save