From 186da5e29b1d0188498a36ad5664824b74039701 Mon Sep 17 00:00:00 2001 From: maochaoying <925670706@qq.com> Date: Wed, 28 Jun 2023 19:54:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9F=BA=E6=9C=AC=E4=BF=A1=E6=81=AF=E5=A2=9E?= =?UTF-8?q?=E5=88=A0=E6=9F=A5=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nuclear/controller/NuclearCoreController.java | 72 +++++++++++++++++++++ .../controller/NuclearStationController.java | 75 ++++++++++++++++++++++ .../nuclear/service/NuclearCoreService.java | 1 + .../nuclear/service/NuclearStationService.java | 1 + .../service/impl/NuclearCoreServiceImpl.java | 9 +++ .../service/impl/NuclearStationServiceImpl.java | 9 +++ src/main/resources/application.yml | 4 +- 7 files changed, 170 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/iflytop/nuclear/controller/NuclearCoreController.java create mode 100644 src/main/java/com/iflytop/nuclear/controller/NuclearStationController.java diff --git a/src/main/java/com/iflytop/nuclear/controller/NuclearCoreController.java b/src/main/java/com/iflytop/nuclear/controller/NuclearCoreController.java new file mode 100644 index 0000000..81ea1cc --- /dev/null +++ b/src/main/java/com/iflytop/nuclear/controller/NuclearCoreController.java @@ -0,0 +1,72 @@ +package com.iflytop.nuclear.controller; + +import com.alibaba.fastjson2.JSONObject; +import com.iflytop.nuclear.model.NuclearCore; +import com.iflytop.nuclear.model.NuclearStation; +import com.iflytop.nuclear.service.NuclearCoreService; +import com.iflytop.nuclear.utils.ResponseData; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; +import java.util.Map; + +/** + * @author cool + * @date 2023/6/28 19:28 + */ +@Slf4j +@RestController +@CrossOrigin +@RequestMapping("/core") +public class NuclearCoreController { + + @Autowired + NuclearCoreService nuclearCoreService; + + @GetMapping("/list") + public ResponseData list() { + List list = nuclearCoreService.list(); + JSONObject res = new JSONObject(); + res.put("list", list); + return ResponseData.success(res); + } + + @PostMapping("/add") + public ResponseData add(@RequestBody Map coreInfo) { + JSONObject res = new JSONObject(); + NuclearCore ns = nuclearCoreService.queryCoreByName(coreInfo.get("name")); + if (ns != null) { + return ResponseData.fail("已经存在该名称的反应堆"); + } + NuclearCore nuclearCore = NuclearCore.builder() + .name(coreInfo.get("name")) + .serialNumber(coreInfo.get("serialNumber")) + .build(); + boolean save = nuclearCoreService.save(nuclearCore); + res.put("result", save); + return ResponseData.success(res); + } + + @PostMapping("/delete/{id}") + public ResponseData delete(@PathVariable(name="id") String coreId) { + boolean b = nuclearCoreService.removeById(coreId); + JSONObject res = new JSONObject(); + res.put("result", b); + return ResponseData.success(res); + } + + @PostMapping("/update/{id}") + public ResponseData update(@PathVariable(name="id") Long coreId, @RequestBody Map coreInfo) { + NuclearCore nuclearCore = NuclearCore.builder() + .name(coreInfo.get("name")) + .serialNumber(coreInfo.get("serialNumber")) + .id(coreId) + .build(); + boolean b = nuclearCoreService.updateById(nuclearCore); + JSONObject res = new JSONObject(); + res.put("result", b); + return ResponseData.success(res); + } +} diff --git a/src/main/java/com/iflytop/nuclear/controller/NuclearStationController.java b/src/main/java/com/iflytop/nuclear/controller/NuclearStationController.java new file mode 100644 index 0000000..8daad26 --- /dev/null +++ b/src/main/java/com/iflytop/nuclear/controller/NuclearStationController.java @@ -0,0 +1,75 @@ +package com.iflytop.nuclear.controller; + +import com.alibaba.fastjson2.JSONObject; +import com.iflytop.nuclear.model.Account; +import com.iflytop.nuclear.model.NuclearStation; +import com.iflytop.nuclear.service.NuclearStationService; +import com.iflytop.nuclear.utils.ResponseData; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import java.util.List; +import java.util.Map; + +/** + * @author cool + * @date 2023/6/28 19:23 + */ +@Slf4j +@RestController +@CrossOrigin +@RequestMapping("/station") +@PreAuthorize("hasRole('ADMIN')") +public class NuclearStationController { + + @Autowired + NuclearStationService nuclearStationService; + + @GetMapping("/list") + public ResponseData list() { + List list = nuclearStationService.list(); + JSONObject res = new JSONObject(); + res.put("list", list); + return ResponseData.success(res); + } + + @PostMapping("/add") + public ResponseData add(@RequestBody Map stationInfo) { + JSONObject res = new JSONObject(); + NuclearStation ns = nuclearStationService.queryStationByName(stationInfo.get("name")); + if (ns != null) { + return ResponseData.fail("已经存在该名称的核电站"); + } + NuclearStation nuclearStation = NuclearStation.builder() + .name(stationInfo.get("name")) + .address(stationInfo.get("address")) + .build(); + boolean save = nuclearStationService.save(nuclearStation); + res.put("result", save); + return ResponseData.success(res); + } + + @PostMapping("/delete/{id}") + public ResponseData delete(@PathVariable(name="id") String stationId) { + boolean b = nuclearStationService.removeById(stationId); + JSONObject res = new JSONObject(); + res.put("result", b); + return ResponseData.success(res); + } + + @PostMapping("/update/{id}") + public ResponseData update(@PathVariable(name="id") Long stationId, @RequestBody Map stationInfo) { + NuclearStation nuclearStation = NuclearStation.builder() + .name(stationInfo.get("name")) + .address(stationInfo.get("address")) + .id(stationId) + .build(); + boolean b = nuclearStationService.updateById(nuclearStation); + JSONObject res = new JSONObject(); + res.put("result", b); + return ResponseData.success(res); + } + +} diff --git a/src/main/java/com/iflytop/nuclear/service/NuclearCoreService.java b/src/main/java/com/iflytop/nuclear/service/NuclearCoreService.java index 1400885..5f21a6b 100644 --- a/src/main/java/com/iflytop/nuclear/service/NuclearCoreService.java +++ b/src/main/java/com/iflytop/nuclear/service/NuclearCoreService.java @@ -14,4 +14,5 @@ import java.util.List; @Transactional public interface NuclearCoreService extends IService { + NuclearCore queryCoreByName(String name); } diff --git a/src/main/java/com/iflytop/nuclear/service/NuclearStationService.java b/src/main/java/com/iflytop/nuclear/service/NuclearStationService.java index 6d5502a..928a8d7 100644 --- a/src/main/java/com/iflytop/nuclear/service/NuclearStationService.java +++ b/src/main/java/com/iflytop/nuclear/service/NuclearStationService.java @@ -10,4 +10,5 @@ import org.springframework.transaction.annotation.Transactional; */ @Transactional public interface NuclearStationService extends IService { + NuclearStation queryStationByName(String name); } diff --git a/src/main/java/com/iflytop/nuclear/service/impl/NuclearCoreServiceImpl.java b/src/main/java/com/iflytop/nuclear/service/impl/NuclearCoreServiceImpl.java index 484a3c8..863bc2f 100644 --- a/src/main/java/com/iflytop/nuclear/service/impl/NuclearCoreServiceImpl.java +++ b/src/main/java/com/iflytop/nuclear/service/impl/NuclearCoreServiceImpl.java @@ -1,9 +1,11 @@ package com.iflytop.nuclear.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.iflytop.nuclear.mapper.NuclearCoreMapper; import com.iflytop.nuclear.model.NuclearCore; import com.iflytop.nuclear.model.NuclearCoreConfig; +import com.iflytop.nuclear.model.NuclearStation; import com.iflytop.nuclear.service.NuclearCoreService; import org.springframework.stereotype.Service; @@ -16,4 +18,11 @@ import java.util.List; @Service public class NuclearCoreServiceImpl extends ServiceImpl implements NuclearCoreService { + @Override + public NuclearCore queryCoreByName(String name) { + QueryWrapper nuclearCoreQueryWrapper = new QueryWrapper<>(); + nuclearCoreQueryWrapper.eq("name", name); + NuclearCore nuclearCore = this.getOne(nuclearCoreQueryWrapper); + return nuclearCore; + } } diff --git a/src/main/java/com/iflytop/nuclear/service/impl/NuclearStationServiceImpl.java b/src/main/java/com/iflytop/nuclear/service/impl/NuclearStationServiceImpl.java index c4ed7ef..77a9568 100644 --- a/src/main/java/com/iflytop/nuclear/service/impl/NuclearStationServiceImpl.java +++ b/src/main/java/com/iflytop/nuclear/service/impl/NuclearStationServiceImpl.java @@ -1,7 +1,9 @@ package com.iflytop.nuclear.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.iflytop.nuclear.mapper.NuclearStationMapper; +import com.iflytop.nuclear.model.Account; import com.iflytop.nuclear.model.NuclearStation; import com.iflytop.nuclear.service.NuclearStationService; import org.springframework.stereotype.Service; @@ -12,4 +14,11 @@ import org.springframework.stereotype.Service; */ @Service public class NuclearStationServiceImpl extends ServiceImpl implements NuclearStationService { + @Override + public NuclearStation queryStationByName(String name) { + QueryWrapper nuclearStationQueryWrapper = new QueryWrapper<>(); + nuclearStationQueryWrapper.eq("name", name); + NuclearStation nuclearStation = this.getOne(nuclearStationQueryWrapper); + return nuclearStation; + } } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index ad61253..3a6e005 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -6,4 +6,6 @@ spring: enabled: true include: "**.java" profiles: - active: dev \ No newline at end of file + active: dev +# resources: +# static-locations: file:/Users/cool/Desktop/code/nuclear/uploadfiles/xlsx \ No newline at end of file