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

Loading…
Cancel
Save