package com.jiayue.center.controller; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.jiayue.center.annotation.OperateLog; import com.jiayue.center.annotation.PreventReplay; import com.jiayue.center.backenum.AuditType; import com.jiayue.center.backenum.BusinessType; import com.jiayue.center.constant.CustomException; import com.jiayue.center.entity.ElectricField; import com.jiayue.center.service.ElectricFieldService; import com.jiayue.center.util.ResponseVO; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; /** * 场站接口 * * @author xsl * @since 2023/03/13 */ @RestController @RequestMapping("/electricField") @Slf4j public class ElectricFieldController { @Autowired ElectricFieldService electricFieldService; /** * 获取场站信息 * * @return 场站信息 */ @GetMapping(value = "/getAll") @PreAuthorize("@ss.hasPermi('biz:electric:getAll')") @OperateLog(title = "场站管理", businessType = BusinessType.QUERY, auditType = AuditType.BIZ,operdesc = "查询场站信息") @PreventReplay public ResponseVO getAll() throws CustomException { try { ElectricField electricField = electricFieldService.getOne(new QueryWrapper<>()); return ResponseVO.success(electricField); } catch (Exception e) { throw new CustomException("获取场站信息异常", e); } } /** * 保存场站 */ @PostMapping @OperateLog(title = "场站信息", businessType = BusinessType.UPDATE, auditType = AuditType.BIZ,operdesc = "保存场站信息") @PreAuthorize("@ss.hasPermi('biz:electric:update')") @PreventReplay public ResponseVO update(@RequestBody ElectricField electricField) throws CustomException { try { if (StringUtils.isEmpty(electricField.getStationCode())) { return ResponseVO.fail("场站编号不能为空!"); } else if (electricField.getStationCode().length() > 6) { return ResponseVO.fail(electricField.getStationCode() + "场站编号长度不能超过6个字符!"); } if (StringUtils.isEmpty(electricField.getName())) { return ResponseVO.fail("场站名称不能为空!"); } else if (electricField.getName().length() > 50) { return ResponseVO.fail(electricField.getName() + "场站名称长度不能超过50个字符!"); } if (StringUtils.isEmpty(electricField.getSign())) { return ResponseVO.fail("场站标识不能为空!"); } else if (electricField.getSign().length() > 10) { return ResponseVO.fail(electricField.getSign() + "场站标识长度不能超过10个字符!"); } String pattern = "^[0-9]{1,8}+\\.{0,1}[0-9]{0,2}$"; if (electricField.getCapacity() == null) { return ResponseVO.fail("装机容量不能为空!"); } else if (!electricField.getCapacity().toString().matches(pattern)) { return ResponseVO.fail("装机容量整数位不能超过8位,小数位不能超过2位!"); } if (electricField.getGridce() == null) { return ResponseVO.fail("并网设备数不能为空!"); } else if (!String.valueOf(electricField.getGridce()).matches("^([0-9][0-9]{0,1}|100)$")) { return ResponseVO.fail("并网设备数请输入0-100整数"); } if (StringUtils.isEmpty(electricField.getFieldType())) { return ResponseVO.fail("场站类型不能为空!"); } else if (electricField.getFieldType().length() > 1) { return ResponseVO.fail("场站类型长度不能超过1个字符!"); } if (StringUtils.isEmpty(electricField.getCompany())) { return ResponseVO.fail("所属公司不能为空!"); } else if (electricField.getCompany().length() > 100) { return ResponseVO.fail("所属公司长度不能超过100个字符!"); } if (StringUtils.isEmpty(electricField.getLocation())) { return ResponseVO.fail("场站位置不能为空!"); } else if (electricField.getLocation().length() > 100) { return ResponseVO.fail("场站位置长度不能超过100个字符!"); } ElectricField oldElectricField = electricFieldService.getById(electricField.getId()); if (electricField.getVersion().intValue() != oldElectricField.getVersion().intValue()){ return ResponseVO.fail("此数据被操作过,自动刷新列表后请重试操作!"); } boolean bo = electricFieldService.saveOrUpdate(electricField); if (bo) { return ResponseVO.success("场站信息保存成功"); } else { return ResponseVO.fail("场站信息保存失败"); } } catch (Exception e) { throw new CustomException("场站信息保存异常", e); } } }