|
@@ -3,10 +3,13 @@ package org.jeecg.modules.deviceManage.controller;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
import org.jeecg.common.api.vo.Result;
|
|
|
import org.jeecg.common.system.query.QueryGenerator;
|
|
|
|
|
@@ -24,6 +27,7 @@ import org.jeecg.common.system.base.controller.JeecgController;
|
|
|
import org.jeecg.modules.deviceManage.service.IDeviceSparePartsService;
|
|
|
import org.jeecg.modules.deviceManage.vo.DeviceSparePartsParam;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
|
import io.swagger.annotations.Api;
|
|
@@ -67,7 +71,7 @@ public class DeviceBaseInfoController extends JeecgController<DeviceBaseInfo, ID
|
|
|
IPage<DeviceBaseInfo> pageList = deviceBaseInfoService.page(page, queryWrapper);
|
|
|
return Result.OK(pageList);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 添加
|
|
|
*
|
|
@@ -104,15 +108,41 @@ public class DeviceBaseInfoController extends JeecgController<DeviceBaseInfo, ID
|
|
|
* @param id
|
|
|
* @return
|
|
|
*/
|
|
|
- @AutoLog(value = "设备基本信息-通过id删除")
|
|
|
- @ApiOperation(value="设备基本信息-通过id删除", notes="设备基本信息-通过id删除")
|
|
|
+ @AutoLog(value = "设备台账基本信息-通过id删除")
|
|
|
+ @ApiOperation(value="设备台账基本信息-通过id删除", notes="设备基本信息-通过id删除")
|
|
|
@RequiresPermissions("deviceInfo:device_base_info:delete")
|
|
|
@DeleteMapping(value = "/delete")
|
|
|
- public Result<String> delete(@RequestParam(name="id",required=true) String id) {
|
|
|
- deviceBaseInfoService.removeById(id);
|
|
|
- return Result.OK("删除成功!");
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Result<String> delete(@RequestParam(name = "id", required = true) String id) {
|
|
|
+ try {
|
|
|
+ // 根据设备的主键ID查询设备基础信息
|
|
|
+ DeviceBaseInfo device = deviceBaseInfoService.getById(id);
|
|
|
+ if (device == null) {
|
|
|
+ return Result.error("设备基础信息不存在,删除设备失败!");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理父设备
|
|
|
+ LambdaUpdateWrapper<DeviceBaseInfo> updateExistingWrapper = new LambdaUpdateWrapper<>();
|
|
|
+ updateExistingWrapper.set(DeviceBaseInfo::getSubDeviceIds, null)
|
|
|
+ .eq(DeviceBaseInfo::getSubDeviceIds, device.getId());
|
|
|
+ deviceBaseInfoService.update(null, updateExistingWrapper);
|
|
|
+
|
|
|
+ // 处理子设备
|
|
|
+ LambdaUpdateWrapper<DeviceBaseInfo> updateExistingWrapper1 = new LambdaUpdateWrapper<>();
|
|
|
+ updateExistingWrapper1.set(DeviceBaseInfo::getParentDeviceIds, null)
|
|
|
+ .eq(DeviceBaseInfo::getParentDeviceIds, device.getId());
|
|
|
+ deviceBaseInfoService.update(null, updateExistingWrapper1);
|
|
|
+
|
|
|
+ // 物理删除该设备信息
|
|
|
+ deviceBaseInfoService.removeById(id);
|
|
|
+
|
|
|
+ return Result.OK("设备台账删除成功!");
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 出现异常,事务会回滚
|
|
|
+ return Result.error("删除设备台账时出现异常: " + e.getMessage());
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 批量删除
|
|
|
*
|
|
@@ -198,16 +228,38 @@ public class DeviceBaseInfoController extends JeecgController<DeviceBaseInfo, ID
|
|
|
@ApiOperation(value="子设备基本信息-添加", notes="子设备基本信息-添加")
|
|
|
@RequiresPermissions("deviceInfo:sub_device_info:add")
|
|
|
@PostMapping(value = "/subAdd")
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public Result<String> subAdd(@RequestParam(name="id", required=true) String id,
|
|
|
@RequestParam(name="subDeviceIds", required=true) String subDeviceIds) {
|
|
|
- // 通过设备编号查询设备基础信息是否存在
|
|
|
- DeviceBaseInfo deviceBaseInfo = deviceBaseInfoService.getById(id);
|
|
|
- if (deviceBaseInfo == null) {
|
|
|
- return Result.error("设备基础信息不存在,添加子设备失败!");
|
|
|
+ try {
|
|
|
+ // 根据设备A的主键ID查询设备基础信息
|
|
|
+ DeviceBaseInfo deviceA = deviceBaseInfoService.getById(id);
|
|
|
+ if (deviceA == null) {
|
|
|
+ return Result.error("设备基础信息不存在,添加子设备失败!");
|
|
|
+ }
|
|
|
+ // 批量更新 sub_device_ids 等于设备A的ID的设备的 sub_device_ids 为 null
|
|
|
+ LambdaUpdateWrapper<DeviceBaseInfo> updateExistingWrapper = new LambdaUpdateWrapper<>();
|
|
|
+ updateExistingWrapper.set(DeviceBaseInfo::getParentDeviceIds, null)
|
|
|
+ .eq(DeviceBaseInfo::getParentDeviceIds, deviceA.getId());
|
|
|
+ deviceBaseInfoService.update(null, updateExistingWrapper);
|
|
|
+
|
|
|
+ if (subDeviceIds.contains(",")) {
|
|
|
+ List<String> subDeviceIdList = Arrays.asList(subDeviceIds.split(","));
|
|
|
+ LambdaUpdateWrapper<DeviceBaseInfo> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
+ updateWrapper.set(DeviceBaseInfo::getParentDeviceIds, deviceA.getId())
|
|
|
+ .in(DeviceBaseInfo::getId, subDeviceIdList);
|
|
|
+ deviceBaseInfoService.update(updateWrapper);
|
|
|
+ } else {
|
|
|
+ LambdaUpdateWrapper<DeviceBaseInfo> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
+ updateWrapper.set(DeviceBaseInfo::getParentDeviceIds, deviceA.getId())
|
|
|
+ .eq(DeviceBaseInfo::getId, subDeviceIds);
|
|
|
+ deviceBaseInfoService.update(updateWrapper);
|
|
|
+ }
|
|
|
+ return Result.OK("子设备添加成功!");
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 出现异常,事务会回滚
|
|
|
+ return Result.error("添加子设备时出现异常: " + e.getMessage());
|
|
|
}
|
|
|
- deviceBaseInfo.setSubDeviceIds(subDeviceIds);
|
|
|
- deviceBaseInfoService.save(deviceBaseInfo);
|
|
|
- return Result.OK("子设备添加成功!");
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -220,16 +272,39 @@ public class DeviceBaseInfoController extends JeecgController<DeviceBaseInfo, ID
|
|
|
@ApiOperation(value="父设备基本信息-添加", notes="父设备基本信息-添加")
|
|
|
@RequiresPermissions("deviceInfo:parent_device_info:add")
|
|
|
@PostMapping(value = "/parentAdd")
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public Result<String> parentAdd(@RequestParam(name="id", required=true) String id,
|
|
|
@RequestParam(name="parentDeviceIds", required=true) String parentDeviceIds) {
|
|
|
- // 通过设备编号查询设备基础信息是否存在
|
|
|
- DeviceBaseInfo deviceBaseInfo = deviceBaseInfoService.getById(id);
|
|
|
- if (deviceBaseInfo == null) {
|
|
|
- return Result.error("设备基础信息不存在,添加父设备失败!");
|
|
|
+ try {
|
|
|
+ // 根据设备A的主键ID查询设备基础信息
|
|
|
+ DeviceBaseInfo deviceA = deviceBaseInfoService.getById(id);
|
|
|
+ if (deviceA == null) {
|
|
|
+ return Result.error("设备基础信息不存在,添加父设备失败!");
|
|
|
+ }
|
|
|
+ // 批量更新 sub_device_ids 等于设备A的ID的设备的 sub_device_ids 为 null
|
|
|
+ LambdaUpdateWrapper<DeviceBaseInfo> updateExistingWrapper = new LambdaUpdateWrapper<>();
|
|
|
+ updateExistingWrapper.set(DeviceBaseInfo::getSubDeviceIds, null)
|
|
|
+ .eq(DeviceBaseInfo::getSubDeviceIds, deviceA.getId());
|
|
|
+ deviceBaseInfoService.update(null, updateExistingWrapper);
|
|
|
+
|
|
|
+ // 解析父设备的主键ID集合
|
|
|
+ if (parentDeviceIds.contains(",")) {
|
|
|
+ List<String> parentDeviceIdList = Arrays.asList(parentDeviceIds.split(","));
|
|
|
+ LambdaUpdateWrapper<DeviceBaseInfo> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
+ updateWrapper.set(DeviceBaseInfo::getSubDeviceIds, deviceA.getId())
|
|
|
+ .in(DeviceBaseInfo::getId, parentDeviceIdList);
|
|
|
+ deviceBaseInfoService.update(updateWrapper);
|
|
|
+ } else {
|
|
|
+ LambdaUpdateWrapper<DeviceBaseInfo> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
+ updateWrapper.set(DeviceBaseInfo::getSubDeviceIds, deviceA.getId())
|
|
|
+ .eq(DeviceBaseInfo::getId, parentDeviceIds);
|
|
|
+ deviceBaseInfoService.update(updateWrapper);
|
|
|
+ }
|
|
|
+ return Result.OK("父设备添加成功!");
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 出现异常,事务会回滚
|
|
|
+ return Result.error("添加父设备时出现异常: " + e.getMessage());
|
|
|
}
|
|
|
- deviceBaseInfo.setParentDeviceIds(parentDeviceIds);
|
|
|
- deviceBaseInfoService.save(deviceBaseInfo);
|
|
|
- return Result.OK("父设备添加成功!");
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -270,43 +345,30 @@ public class DeviceBaseInfoController extends JeecgController<DeviceBaseInfo, ID
|
|
|
return Result.OK("设备备件添加成功!");
|
|
|
}
|
|
|
|
|
|
- @ApiOperation(value="子设备基本信息-分页列表查询", notes="子设备基本信息-分页列表查询")
|
|
|
- @GetMapping(value = "/subList")
|
|
|
- public Result<IPage<DeviceBaseInfo>> queryPageSubList(DeviceBaseInfo deviceBaseInfo,
|
|
|
- @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
|
|
- @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
|
|
|
- HttpServletRequest req) {
|
|
|
- //通过设备中的subDeviceIds,分页查询设备信息
|
|
|
- String subDeviceIds = deviceBaseInfo.getSubDeviceIds();
|
|
|
- if (oConvertUtils.isEmpty(subDeviceIds)){
|
|
|
- return Result.OK(null);
|
|
|
- }
|
|
|
- QueryWrapper<DeviceBaseInfo> queryWrapper = QueryGenerator.initQueryWrapper(deviceBaseInfo, req.getParameterMap());
|
|
|
- String[] deviceIdArray = subDeviceIds.split(",");
|
|
|
- // 使用in方法进行筛选
|
|
|
- queryWrapper.in("id", Arrays.asList(deviceIdArray));
|
|
|
- Page<DeviceBaseInfo> page = new Page<DeviceBaseInfo>(pageNo, pageSize);
|
|
|
- IPage<DeviceBaseInfo> pageList = deviceBaseInfoService.page(page, queryWrapper);
|
|
|
- return Result.OK(pageList);
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value="父设备基本信息-分页列表查询", notes="父设备基本信息-分页列表查询")
|
|
|
- @GetMapping(value = "/parentList")
|
|
|
- public Result<IPage<DeviceBaseInfo>> queryPageParentList(DeviceBaseInfo deviceBaseInfo,
|
|
|
- @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
|
|
- @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
|
|
|
- HttpServletRequest req) {
|
|
|
- String parentDeviceIds = deviceBaseInfo.getParentDeviceIds();
|
|
|
- if (oConvertUtils.isEmpty(parentDeviceIds)){
|
|
|
- return Result.OK(null);
|
|
|
+ /**
|
|
|
+ * 已绑定的父、子设备信息
|
|
|
+ * @param queryType
|
|
|
+ * @param deviceId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(value="已绑定的父、子设备信息-列表查询", notes="已绑定的父、子设备信息-列表查询")
|
|
|
+ @GetMapping(value = "/parentOrSubDeviceList")
|
|
|
+ public Result<List<DeviceBaseInfo>> queryPageParentList(@RequestParam(name="queryType", required = true) String queryType,
|
|
|
+ @RequestParam(name="deviceId", required = true) String deviceId) {
|
|
|
+ List<DeviceBaseInfo> pageList = new ArrayList<>();
|
|
|
+ if ("1".equals(queryType)){
|
|
|
+ // 查询父设备信息
|
|
|
+ LambdaQueryWrapper<DeviceBaseInfo> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(DeviceBaseInfo::getSubDeviceIds, deviceId)
|
|
|
+ .orderByDesc(DeviceBaseInfo::getCreateTime);
|
|
|
+ pageList = deviceBaseInfoService.list(queryWrapper);
|
|
|
+ }else if ("2".equals(queryType)){
|
|
|
+ // 查询子设备信息
|
|
|
+ LambdaQueryWrapper<DeviceBaseInfo> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(DeviceBaseInfo::getParentDeviceIds, deviceId)
|
|
|
+ .orderByDesc(DeviceBaseInfo::getCreateTime);
|
|
|
+ pageList = deviceBaseInfoService.list(queryWrapper);
|
|
|
}
|
|
|
- QueryWrapper<DeviceBaseInfo> queryWrapper = QueryGenerator.initQueryWrapper(deviceBaseInfo, req.getParameterMap());
|
|
|
- // 将parentDeviceIds字符串拆分成数组
|
|
|
- String[] deviceIdArray = parentDeviceIds.split(",");
|
|
|
- // 使用in方法进行筛选
|
|
|
- queryWrapper.in("id", Arrays.asList(deviceIdArray));
|
|
|
- Page<DeviceBaseInfo> page = new Page<DeviceBaseInfo>(pageNo, pageSize);
|
|
|
- IPage<DeviceBaseInfo> pageList = deviceBaseInfoService.page(page, queryWrapper);
|
|
|
return Result.OK(pageList);
|
|
|
}
|
|
|
}
|