7 changed files with 170 additions and 1 deletions
-
72src/main/java/com/iflytop/nuclear/controller/NuclearCoreController.java
-
75src/main/java/com/iflytop/nuclear/controller/NuclearStationController.java
-
1src/main/java/com/iflytop/nuclear/service/NuclearCoreService.java
-
1src/main/java/com/iflytop/nuclear/service/NuclearStationService.java
-
9src/main/java/com/iflytop/nuclear/service/impl/NuclearCoreServiceImpl.java
-
9src/main/java/com/iflytop/nuclear/service/impl/NuclearStationServiceImpl.java
-
4src/main/resources/application.yml
@ -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<NuclearCore> list = nuclearCoreService.list(); |
|||
JSONObject res = new JSONObject(); |
|||
res.put("list", list); |
|||
return ResponseData.success(res); |
|||
} |
|||
|
|||
@PostMapping("/add") |
|||
public ResponseData add(@RequestBody Map<String,String> 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<String,String> 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); |
|||
} |
|||
} |
@ -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<NuclearStation> list = nuclearStationService.list(); |
|||
JSONObject res = new JSONObject(); |
|||
res.put("list", list); |
|||
return ResponseData.success(res); |
|||
} |
|||
|
|||
@PostMapping("/add") |
|||
public ResponseData add(@RequestBody Map<String,String> 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<String,String> 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); |
|||
} |
|||
|
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue