Browse Source

fix:对象取消和停用报错信息不符

master
luyie 10 hours ago
parent
commit
7e0d30a044
  1. 377
      HZInfo-RIS-PXHD/hzinfo-ris-pxhd-service/hzinfo-inspect-service/src/main/java/org/springblade/hzinfo_inspect/obj/web/ObjectController.java

377
HZInfo-RIS-PXHD/hzinfo-ris-pxhd-service/hzinfo-inspect-service/src/main/java/org/springblade/hzinfo_inspect/obj/web/ObjectController.java

@ -47,7 +47,8 @@ import java.util.stream.Collectors;
/** /**
* 巡检对象控制器 * 巡检对象控制器
*
* @author ninglong * @author ninglong
*/ */
@RestController @RestController
@ -56,208 +57,210 @@ import java.util.stream.Collectors;
@Api(value = "巡检对象", tags = "巡检对象") @Api(value = "巡检对象", tags = "巡检对象")
public class ObjectController extends BladeController { public class ObjectController extends BladeController {
private final ObjectService objectService; private final ObjectService objectService;
private final OtherObjectService otherObjectService; private final OtherObjectService otherObjectService;
private final IPlanObjectTemplateService planObjectTemplateService; private final IPlanObjectTemplateService planObjectTemplateService;
private final ObjectTemplateService objectTemplateService; private final ObjectTemplateService objectTemplateService;
private static final int MAX_SIZE = 1024 * 1024 * 200; private static final int MAX_SIZE = 1024 * 1024 * 200;
private final IObjectDangerService objectDangerService; private final IObjectDangerService objectDangerService;
@GetMapping("/detail") @GetMapping("/detail")
@ApiOperationSupport(order = 1) @ApiOperationSupport(order = 1)
@ApiOperation(value = "查看", notes = "传入id") @ApiOperation(value = "查看", notes = "传入id")
public R<ObjectEntity> detail(Long id) { public R<ObjectEntity> detail(Long id) {
ObjectEntity detail = objectService.getDetail(id); ObjectEntity detail = objectService.getDetail(id);
detail.setDangerSources(objectDangerService.getDangerDetailByObjectId(id)); detail.setDangerSources(objectDangerService.getDangerDetailByObjectId(id));
return R.data(detail); return R.data(detail);
} }
@GetMapping("/list") @GetMapping("/list")
@ApiOperationSupport(order = 2) @ApiOperationSupport(order = 2)
@ApiOperation(value = "巡检对象列表", notes = "巡检对象列表") @ApiOperation(value = "巡检对象列表", notes = "巡检对象列表")
public R<IPage<ObjectEntity>> list(ObjectListQueryVO object, Query query, BladeUser bladeUser) { public R<IPage<ObjectEntity>> list(ObjectListQueryVO object, Query query, BladeUser bladeUser) {
IPage<ObjectEntity> pages = Condition.getPage(query); IPage<ObjectEntity> pages = Condition.getPage(query);
ObjectEntity entity = new ObjectEntity(); ObjectEntity entity = new ObjectEntity();
entity.setCreateDept(Long.valueOf(bladeUser.getDeptId())); entity.setCreateDept(Long.valueOf(bladeUser.getDeptId()));
entity.setCode(object.getCode()); entity.setCode(object.getCode());
entity.setName(object.getName()); entity.setName(object.getName());
entity.setStatus(object.getStatus()); entity.setStatus(object.getStatus());
entity.setSupportAutoVideo(object.getSupportAutoVideo()); entity.setSupportAutoVideo(object.getSupportAutoVideo());
pages.setRecords(objectService.getListPage(pages,entity)); pages.setRecords(objectService.getListPage(pages, entity));
return R.data(pages); return R.data(pages);
} }
@GetMapping("/other_list_page") @GetMapping("/other_list_page")
@ApiOperationSupport(order = 2) @ApiOperationSupport(order = 2)
@ApiOperation(value = "其他巡检对象列表-分页", notes = "其他巡检对象列表,分页") @ApiOperation(value = "其他巡检对象列表-分页", notes = "其他巡检对象列表,分页")
public R<IPage<OtherObjectEntity>> otherListPage(OtherObjectListQueryVO object, Query query, BladeUser bladeUser) { public R<IPage<OtherObjectEntity>> otherListPage(OtherObjectListQueryVO object, Query query, BladeUser bladeUser) {
LambdaQueryWrapper<OtherObjectEntity> queryWrapper = Condition.getQueryWrapper(new OtherObjectEntity(),object); LambdaQueryWrapper<OtherObjectEntity> queryWrapper = Condition.getQueryWrapper(new OtherObjectEntity(), object);
queryWrapper.eq(OtherObjectEntity::getCreateDept,bladeUser.getDeptId()); queryWrapper.eq(OtherObjectEntity::getCreateDept, bladeUser.getDeptId());
queryWrapper.orderByDesc(OtherObjectEntity::getRealId); queryWrapper.orderByDesc(OtherObjectEntity::getRealId);
IPage<OtherObjectEntity> pages = otherObjectService.page(Condition.getPage(query), queryWrapper); IPage<OtherObjectEntity> pages = otherObjectService.page(Condition.getPage(query), queryWrapper);
return R.data(pages); return R.data(pages);
} }
@GetMapping("/other_list") @GetMapping("/other_list")
@ApiOperationSupport(order = 2) @ApiOperationSupport(order = 2)
@ApiOperation(value = "其他巡检对象列表", notes = "其他巡检对象列表,不分页") @ApiOperation(value = "其他巡检对象列表", notes = "其他巡检对象列表,不分页")
public R<List<OtherObjectEntity>> otherList(OtherObjectListQueryVO object, BladeUser bladeUser) { public R<List<OtherObjectEntity>> otherList(OtherObjectListQueryVO object, BladeUser bladeUser) {
LambdaQueryWrapper<OtherObjectEntity> queryWrapper = Condition.getQueryWrapper(new OtherObjectEntity(),object); LambdaQueryWrapper<OtherObjectEntity> queryWrapper = Condition.getQueryWrapper(new OtherObjectEntity(), object);
queryWrapper.eq(OtherObjectEntity::getCreateDept,bladeUser.getDeptId()); queryWrapper.eq(OtherObjectEntity::getCreateDept, bladeUser.getDeptId());
queryWrapper.orderByDesc(OtherObjectEntity::getRealId); queryWrapper.orderByDesc(OtherObjectEntity::getRealId);
//List<OtherObjectEntity> list = otherObjectService.list((!bladeUser.getTenantId().equals(BladeConstant.ADMIN_TENANT_ID)) ? queryWrapper.eq(OtherObjectEntity::getTenantId, bladeUser.getTenantId()) : queryWrapper); //List<OtherObjectEntity> list = otherObjectService.list((!bladeUser.getTenantId().equals(BladeConstant.ADMIN_TENANT_ID)) ? queryWrapper.eq(OtherObjectEntity::getTenantId, bladeUser.getTenantId()) : queryWrapper);
List<OtherObjectEntity> list = otherObjectService.list(queryWrapper); List<OtherObjectEntity> list = otherObjectService.list(queryWrapper);
return R.data(list); return R.data(list);
} }
@GetMapping("/other_unbind_list") @GetMapping("/other_unbind_list")
@ApiOperationSupport(order = 2) @ApiOperationSupport(order = 2)
@ApiOperation(value = "获获取未绑定的其他来源对象", notes = "获获取未绑定的其他来源对象,分页") @ApiOperation(value = "获获取未绑定的其他来源对象", notes = "获获取未绑定的其他来源对象,分页")
public R<IPage<OtherObjectEntity>> otherUnbindList(OtherObjectListQueryVO obj, Query query, BladeUser bladeUser) { public R<IPage<OtherObjectEntity>> otherUnbindList(OtherObjectListQueryVO obj, Query query, BladeUser bladeUser) {
IPage<OtherObjectEntity> pages = Condition.getPage(query); IPage<OtherObjectEntity> pages = Condition.getPage(query);
OtherObjectEntity object = new OtherObjectEntity(); OtherObjectEntity object = new OtherObjectEntity();
object.setName(obj.getName()); object.setName(obj.getName());
object.setCode(obj.getCode()); object.setCode(obj.getCode());
object.setType(obj.getType()); object.setType(obj.getType());
object.setRealId(obj.getRealId()); object.setRealId(obj.getRealId());
object.setCreateDept(Long.valueOf(bladeUser.getDeptId())); object.setCreateDept(Long.valueOf(bladeUser.getDeptId()));
pages.setRecords(otherObjectService.getUnbindListPage(pages,object)); pages.setRecords(otherObjectService.getUnbindListPage(pages, object));
return R.data(pages); return R.data(pages);
} }
@PostMapping("/submit") @PostMapping("/submit")
@ApiOperationSupport(order = 3) @ApiOperationSupport(order = 3)
@ApiOperation(value = "新增或修改", notes = "传入object") @ApiOperation(value = "新增或修改", notes = "传入object")
public R submit(@Valid @RequestBody ObjectEntity object) { public R submit(@Valid @RequestBody ObjectEntity object) {
if(object.getId()==null && Func.isBlank(object.getCode())){ if (object.getId() == null && Func.isBlank(object.getCode())) {
object.setCode(CodeUtils.randomCode()); object.setCode(CodeUtils.randomCode());
} }
if(object.getSupportAutoVideo().equals(PlanContants.InspectTypeEnum.COMMON.getVal()) && (Func.isEmpty(object.getObjectDangers()) || object.getObjectDangers().size() == 0)){ if (object.getSupportAutoVideo().equals(PlanContants.InspectTypeEnum.COMMON.getVal()) && (Func.isEmpty(object.getObjectDangers()) || object.getObjectDangers().size() == 0)) {
throw new ServiceException("对象告警list为空"); throw new ServiceException("对象告警list为空");
} }
objectService.saveOrUpdate(object); objectService.saveOrUpdate(object);
objectDangerService.remove(Wrappers.<ObjectDangerEntity>lambdaQuery().eq(ObjectDangerEntity::getObjectId, object.getId())); objectDangerService.remove(Wrappers.<ObjectDangerEntity>lambdaQuery().eq(ObjectDangerEntity::getObjectId, object.getId()));
List<ObjectDangerEntity> objectDangers = object.getObjectDangers(); List<ObjectDangerEntity> objectDangers = object.getObjectDangers();
if(CollectionUtil.isNotEmpty(objectDangers)){ if (CollectionUtil.isNotEmpty(objectDangers)) {
objectDangers.stream().forEach(e -> { objectDangers.stream().forEach(e -> {
e.setObjectId(object.getId()); e.setObjectId(object.getId());
}); });
objectDangerService.saveBatch(objectDangers); objectDangerService.saveBatch(objectDangers);
} }
return R.data(object.getId()); return R.data(object.getId());
} }
@PostMapping("/saveBatch") @PostMapping("/saveBatch")
@ApiOperationSupport(order = 3) @ApiOperationSupport(order = 3)
@ApiOperation(value = "批量新增", notes = "传入object") @ApiOperation(value = "批量新增", notes = "传入object")
public R<Boolean> submit(@Valid @RequestBody ObjectBatchVo batchVo) { public R<Boolean> submit(@Valid @RequestBody ObjectBatchVo batchVo) {
return R.status(objectService.saveBatch(batchVo.getObjects())); return R.status(objectService.saveBatch(batchVo.getObjects()));
} }
@PostMapping("/remove") @PostMapping("/remove")
@ApiOperationSupport(order = 4) @ApiOperationSupport(order = 4)
@ApiOperation(value = "逻辑删除", notes = "传入ids") @ApiOperation(value = "逻辑删除", notes = "传入ids")
public R<Boolean> remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) { public R<Boolean> remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
List<Long> delIdList = Func.toLongList(ids); List<Long> delIdList = Func.toLongList(ids);
QueryWrapper<PlanObjectTemplateEntity> qw = new QueryWrapper<>(); QueryWrapper<PlanObjectTemplateEntity> qw = new QueryWrapper<>();
qw.lambda().in(PlanObjectTemplateEntity::getObjectId,delIdList); qw.lambda().in(PlanObjectTemplateEntity::getObjectId, delIdList);
int count = planObjectTemplateService.count(qw); int count = planObjectTemplateService.count(qw);
if(count>0) { if (count > 0) {
return R.fail("该巡检对象已被巡检计划引用,无法删除"); return R.fail("该巡检对象已关联模板,请先取消关联");
} }
for (Long aLong : delIdList) { for (Long aLong : delIdList) {
objectTemplateService.remove(new QueryWrapper<ObjectTemplateEntity>(){{ objectTemplateService.remove(new QueryWrapper<ObjectTemplateEntity>() {{
eq("OBJECT_ID",aLong); eq("OBJECT_ID", aLong);
}}); }});
} }
return R.status(objectService.deleteLogic(delIdList)); return R.status(objectService.deleteLogic(delIdList));
} }
@GetMapping("/disableOrEnable") @GetMapping("/disableOrEnable")
@ApiOperationSupport(order = 5) @ApiOperationSupport(order = 5)
@ApiOperation(value = "启用/停用", notes = "传入id,以及目标状态0-启用,1-停用") @ApiOperation(value = "启用/停用", notes = "传入id,以及目标状态0-启用,1-停用")
public R<Boolean> disableOrEnable(@RequestParam Long id,@RequestParam Integer status) { public R<Boolean> disableOrEnable(@RequestParam Long id, @RequestParam Integer status) {
QueryWrapper<PlanObjectTemplateEntity> qw = new QueryWrapper<>(); QueryWrapper<PlanObjectTemplateEntity> qw = new QueryWrapper<>();
qw.lambda().eq(PlanObjectTemplateEntity::getObjectId,id); qw.lambda().eq(PlanObjectTemplateEntity::getObjectId, id);
int count = planObjectTemplateService.count(qw); if (status == 1) {
if(count>0) { int count = planObjectTemplateService.count(qw);
return R.fail("该巡检对象已被巡检计划引用,无法停用"); if (count > 0) {
} return R.fail("该巡检对象已关联模板,请先取消关联");
UpdateWrapper<ObjectEntity> ew = new UpdateWrapper<>(); }
ew.lambda().set(ObjectEntity::getStatus,status).eq(ObjectEntity::getId, id); }
return R.status(objectService.update(ew)); UpdateWrapper<ObjectEntity> ew = new UpdateWrapper<>();
} ew.lambda().set(ObjectEntity::getStatus, status).eq(ObjectEntity::getId, id);
return R.status(objectService.update(ew));
}
@GetMapping("/getAllEnableOfObject") @GetMapping("/getAllEnableOfObject")
@ApiOperationSupport(order = 6) @ApiOperationSupport(order = 6)
@ApiOperation(value = "获取所有启用状态的对象(不分页)", notes = "获取所有启用状态的对象(不分页") @ApiOperation(value = "获取所有启用状态的对象(不分页)", notes = "获取所有启用状态的对象(不分页")
public R<List<ObjectEntity>> getAllEnableOfObject(){ public R<List<ObjectEntity>> getAllEnableOfObject() {
List<ObjectEntity> list = objectService.list(Wrappers.<ObjectEntity>lambdaQuery().eq(ObjectEntity::getStatus,0)); List<ObjectEntity> list = objectService.list(Wrappers.<ObjectEntity>lambdaQuery().eq(ObjectEntity::getStatus, 0));
return R.data(list); return R.data(list);
} }
@GetMapping("/getObjectList") @GetMapping("/getObjectList")
@ApiOperationSupport(order = 11) @ApiOperationSupport(order = 11)
@ApiOperation(value = "获获取未绑定的其他来源对象", notes = "获获取未绑定的其他来源对象,分页") @ApiOperation(value = "获获取未绑定的其他来源对象", notes = "获获取未绑定的其他来源对象,分页")
public R<List<ObjectEntity>> getObjectList(ObjectEntity object){ public R<List<ObjectEntity>> getObjectList(ObjectEntity object) {
List<ObjectEntity> list = objectService.list(org.springblade.core.mp.support.Condition.getQueryWrapper(new ObjectEntity(),object)); List<ObjectEntity> list = objectService.list(org.springblade.core.mp.support.Condition.getQueryWrapper(new ObjectEntity(), object));
return R.data(list); return R.data(list);
} }
@GetMapping("/getOtherType") @GetMapping("/getOtherType")
@ApiOperationSupport(order = 7) @ApiOperationSupport(order = 7)
@ApiOperation(value = "获取其他对象来源类型", notes = "获取其他对象来源类型") @ApiOperation(value = "获取其他对象来源类型", notes = "获取其他对象来源类型")
public R<List<String>> getOtherType(){ public R<List<String>> getOtherType() {
List<String> list = otherObjectService.getOtherType(); List<String> list = otherObjectService.getOtherType();
return R.data(list); return R.data(list);
} }
/** /**
* Excel导入巡检对象含项目和内容 * Excel导入巡检对象含项目和内容
*/ */
@PostMapping("/importObjectByExcel") @PostMapping("/importObjectByExcel")
@ApiOperationSupport(order = 8) @ApiOperationSupport(order = 8)
@ApiOperation(value = "Excel导入巡检对象(含项目和内容)", notes = "Excel导入巡检对象(含项目和内容)") @ApiOperation(value = "Excel导入巡检对象(含项目和内容)", notes = "Excel导入巡检对象(含项目和内容)")
public R<Boolean> importObjectByExcel(@ApiParam(value = "excel文件,巡检对象导入模板", required = true) @RequestParam(value="file") MultipartFile file) throws IOException { public R<Boolean> importObjectByExcel(@ApiParam(value = "excel文件,巡检对象导入模板", required = true) @RequestParam(value = "file") MultipartFile file) throws IOException {
if (file.getSize() > MAX_SIZE) { if (file.getSize() > MAX_SIZE) {
throw new ServiceException( "上传文件大小不能超过200M"); throw new ServiceException("上传文件大小不能超过200M");
} }
EasyExcel.read(file.getInputStream(), ObjectExcelInputData.class, new ObjectExcelInputListener(objectService)).sheet().doRead(); EasyExcel.read(file.getInputStream(), ObjectExcelInputData.class, new ObjectExcelInputListener(objectService)).sheet().doRead();
return R.status(true); return R.status(true);
} }
@ApiOperationSupport(order = 9) @ApiOperationSupport(order = 9)
@ApiOperation(value = "巡检对象标签导出,下载pdf", notes = "巡检对象标签导出,下载pdf") @ApiOperation(value = "巡检对象标签导出,下载pdf", notes = "巡检对象标签导出,下载pdf")
@RequestMapping(value = "/objectPdfDownload", method = {RequestMethod.GET, RequestMethod.POST}) @RequestMapping(value = "/objectPdfDownload", method = {RequestMethod.GET, RequestMethod.POST})
public void objectPdfDownload(HttpServletResponse response,@ApiParam(value = "导出对象的ids, 通过,隔开。 不传则返回全部对象", required = false) @RequestParam String ids) { public void objectPdfDownload(HttpServletResponse response, @ApiParam(value = "导出对象的ids, 通过,隔开。 不传则返回全部对象", required = false) @RequestParam String ids) {
List idList = null; List idList = null;
if(Func.isNotEmpty(ids)){ if (Func.isNotEmpty(ids)) {
idList = Arrays.asList(ids.split(",")); idList = Arrays.asList(ids.split(","));
} }
String pdfPath = objectService.exportObjectPdf(idList); String pdfPath = objectService.exportObjectPdf(idList);
File file = new File(pdfPath); File file = new File(pdfPath);
OutputStream out = null; OutputStream out = null;
try { try {
response.reset(); response.reset();
response.setContentType("application/octet-stream; charset=utf-8"); response.setContentType("application/octet-stream; charset=utf-8");
response.setHeader("Content-Disposition", "attachment; filename=" + file.getName()); response.setHeader("Content-Disposition", "attachment; filename=" + file.getName());
out = response.getOutputStream(); out = response.getOutputStream();
out.write(FileUtils.readFileToByteArray(file)); out.write(FileUtils.readFileToByteArray(file));
out.flush(); out.flush();
} catch (IOException e) { } catch (IOException e) {
throw new ServiceException("导出PDF发生异常 :" + e.toString()); throw new ServiceException("导出PDF发生异常 :" + e.toString());
} finally { } finally {
if (out != null) { if (out != null) {
try { try {
out.close(); out.close();
} catch (IOException e) { } catch (IOException e) {
throw new ServiceException("导出PDF,关闭流发生异常"); throw new ServiceException("导出PDF,关闭流发生异常");
} }
} }
} }
} }
} }

Loading…
Cancel
Save