BinSectionController.java 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. package com.ims.eval.controller;
  2. import com.ims.common.utils.StringUtils;
  3. import com.ims.eval.cache.CacheContext;
  4. import com.ims.eval.config.CustomException;
  5. import com.ims.eval.entity.BinSection;
  6. import com.ims.eval.entity.dto.result.R;
  7. import com.ims.eval.service.IBinSectionService;
  8. import io.swagger.annotations.ApiOperation;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.web.bind.annotation.*;
  11. import java.util.Arrays;
  12. import java.util.List;
  13. import java.util.stream.Collectors;
  14. /**
  15. * <p>
  16. * 生产经营业务分类 前端控制器
  17. * </p>
  18. *
  19. * @author wang
  20. * @since 2023-03-12
  21. */
  22. @RestController
  23. @RequestMapping("//bin-section")
  24. public class BinSectionController {
  25. @Autowired
  26. private IBinSectionService binSectionService;
  27. @Autowired
  28. private CacheContext cache;
  29. /**
  30. * 查询
  31. *
  32. * @param id 主键ID
  33. * @param sectionName name
  34. * @param sectionCode code
  35. * @return
  36. */
  37. //@ImsPreAuth("eval:binSection:view")
  38. @GetMapping(value = "list")
  39. public R list(@RequestParam(value = "id", required = false) String id,
  40. @RequestParam(value = "sectionName", required = false) String sectionName,
  41. @RequestParam(value = "sectionCode", required = false) String sectionCode,
  42. @RequestParam(value = "type", required = false) String type) {
  43. List<BinSection> list =CacheContext.bsnList;
  44. if(StringUtils.isNotEmpty(type)){
  45. list = list.stream().filter(s -> !s.getType().equals(type)).collect(Collectors.toList());
  46. }
  47. return R.ok().data(list);
  48. }
  49. /**
  50. * 添加
  51. *
  52. * @param binSection
  53. * @return
  54. */
  55. //@ImsPreAuth("eval:binSection:edit")
  56. @PostMapping(value = "/save")
  57. @ApiOperation(value = "新增(修改)", notes = "新增(修改)")
  58. public R addAll(@RequestBody BinSection binSection) {
  59. try {
  60. boolean b = binSectionService.saveOrUpdate(binSection);
  61. if (b) {
  62. cache.initBinSection();
  63. return R.ok().data(b);
  64. } else {
  65. return R.error().data("保存失败!");
  66. }
  67. } catch (CustomException e){
  68. return R.customError(e.getMessage()).data("失败!");
  69. }
  70. }
  71. /**
  72. * 批量删除
  73. *
  74. * @param ids
  75. * @return
  76. */
  77. //@ImsPreAuth("eval:binSection:remove")
  78. @PostMapping(value = "/remove/{ids}")
  79. @ApiOperation(value = "删除", notes = "删除")
  80. public R deleteAll(@PathVariable("ids") String ids) {
  81. String[] strings = ids.split(",");
  82. boolean b = binSectionService.removeByIds(Arrays.asList(strings));
  83. if (b) {
  84. cache.initBinSection();
  85. return R.ok().data(b);
  86. } else {
  87. return R.error().data("删除失败!");
  88. }
  89. }
  90. }