ElectricFieldController.java 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. package com.jiayue.center.controller;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import com.jiayue.center.annotation.OperateLog;
  4. import com.jiayue.center.annotation.PreventReplay;
  5. import com.jiayue.center.backenum.AuditType;
  6. import com.jiayue.center.backenum.BusinessType;
  7. import com.jiayue.center.constant.CustomException;
  8. import com.jiayue.center.entity.ElectricField;
  9. import com.jiayue.center.service.ElectricFieldService;
  10. import com.jiayue.center.util.ResponseVO;
  11. import lombok.extern.slf4j.Slf4j;
  12. import org.apache.commons.lang3.StringUtils;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.security.access.prepost.PreAuthorize;
  15. import org.springframework.web.bind.annotation.*;
  16. /**
  17. * 场站接口
  18. *
  19. * @author xsl
  20. * @since 2023/03/13
  21. */
  22. @RestController
  23. @RequestMapping("/electricField")
  24. @Slf4j
  25. public class ElectricFieldController {
  26. @Autowired
  27. ElectricFieldService electricFieldService;
  28. /**
  29. * 获取场站信息
  30. *
  31. * @return 场站信息
  32. */
  33. @GetMapping(value = "/getAll")
  34. @PreAuthorize("@ss.hasPermi('biz:electric:getAll')")
  35. @OperateLog(title = "场站管理", businessType = BusinessType.QUERY, auditType = AuditType.BIZ,operdesc = "查询场站信息")
  36. @PreventReplay
  37. public ResponseVO getAll() throws CustomException {
  38. try {
  39. ElectricField electricField = electricFieldService.getOne(new QueryWrapper<>());
  40. return ResponseVO.success(electricField);
  41. } catch (Exception e) {
  42. throw new CustomException("获取场站信息异常", e);
  43. }
  44. }
  45. /**
  46. * 保存场站
  47. */
  48. @PostMapping
  49. @OperateLog(title = "场站信息", businessType = BusinessType.UPDATE, auditType = AuditType.BIZ,operdesc = "保存场站信息")
  50. @PreAuthorize("@ss.hasPermi('biz:electric:update')")
  51. @PreventReplay
  52. public ResponseVO update(@RequestBody ElectricField electricField) throws CustomException {
  53. try {
  54. if (StringUtils.isEmpty(electricField.getStationCode())) {
  55. return ResponseVO.fail("场站编号不能为空!");
  56. } else if (electricField.getStationCode().length() > 6) {
  57. return ResponseVO.fail(electricField.getStationCode() + "场站编号长度不能超过6个字符!");
  58. }
  59. if (StringUtils.isEmpty(electricField.getName())) {
  60. return ResponseVO.fail("场站名称不能为空!");
  61. } else if (electricField.getName().length() > 50) {
  62. return ResponseVO.fail(electricField.getName() + "场站名称长度不能超过50个字符!");
  63. }
  64. if (StringUtils.isEmpty(electricField.getSign())) {
  65. return ResponseVO.fail("场站标识不能为空!");
  66. } else if (electricField.getSign().length() > 10) {
  67. return ResponseVO.fail(electricField.getSign() + "场站标识长度不能超过10个字符!");
  68. }
  69. String pattern = "^[0-9]{1,8}+\\.{0,1}[0-9]{0,2}$";
  70. if (electricField.getCapacity() == null) {
  71. return ResponseVO.fail("装机容量不能为空!");
  72. } else if (!electricField.getCapacity().toString().matches(pattern)) {
  73. return ResponseVO.fail("装机容量整数位不能超过8位,小数位不能超过2位!");
  74. }
  75. if (electricField.getGridce() == null) {
  76. return ResponseVO.fail("并网设备数不能为空!");
  77. } else if (!String.valueOf(electricField.getGridce()).matches("^([0-9][0-9]{0,1}|100)$")) {
  78. return ResponseVO.fail("并网设备数请输入0-100整数");
  79. }
  80. if (StringUtils.isEmpty(electricField.getFieldType())) {
  81. return ResponseVO.fail("场站类型不能为空!");
  82. } else if (electricField.getFieldType().length() > 1) {
  83. return ResponseVO.fail("场站类型长度不能超过1个字符!");
  84. }
  85. if (StringUtils.isEmpty(electricField.getCompany())) {
  86. return ResponseVO.fail("所属公司不能为空!");
  87. } else if (electricField.getCompany().length() > 100) {
  88. return ResponseVO.fail("所属公司长度不能超过100个字符!");
  89. }
  90. if (StringUtils.isEmpty(electricField.getLocation())) {
  91. return ResponseVO.fail("场站位置不能为空!");
  92. } else if (electricField.getLocation().length() > 100) {
  93. return ResponseVO.fail("场站位置长度不能超过100个字符!");
  94. }
  95. ElectricField oldElectricField = electricFieldService.getById(electricField.getId());
  96. if (electricField.getVersion().intValue() != oldElectricField.getVersion().intValue()){
  97. return ResponseVO.fail("此数据被操作过,自动刷新列表后请重试操作!");
  98. }
  99. boolean bo = electricFieldService.saveOrUpdate(electricField);
  100. if (bo) {
  101. return ResponseVO.success("场站信息保存成功");
  102. } else {
  103. return ResponseVO.fail("场站信息保存失败");
  104. }
  105. } catch (Exception e) {
  106. throw new CustomException("场站信息保存异常", e);
  107. }
  108. }
  109. }