Browse Source

接口优化

main
maochaoying 2 years ago
parent
commit
b4eda22bdc
  1. 14
      src/main/java/com/iflytop/nuclear/controller/AccountController.java
  2. 12
      src/main/java/com/iflytop/nuclear/controller/NuclearCoreController.java
  3. 4
      src/main/java/com/iflytop/nuclear/model/NuclearCore.java
  4. BIN
      uploadfiles/xlsx/20230630/堆芯模版.xlsx

14
src/main/java/com/iflytop/nuclear/controller/AccountController.java

@ -4,12 +4,15 @@ import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.iflytop.nuclear.model.Account; import com.iflytop.nuclear.model.Account;
import com.iflytop.nuclear.service.AccountService; import com.iflytop.nuclear.service.AccountService;
import com.iflytop.nuclear.utils.JwtTokenUtils;
import com.iflytop.nuclear.utils.ResponseData; import com.iflytop.nuclear.utils.ResponseData;
import com.iflytop.nuclear.vo.TaskVO;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -26,6 +29,8 @@ public class AccountController {
@Autowired @Autowired
AccountService accountService; AccountService accountService;
@Autowired
HttpServletRequest request;
/** /**
* 查询用户列表 * 查询用户列表
@ -75,6 +80,15 @@ public class AccountController {
@PostMapping("/delete") @PostMapping("/delete")
public ResponseData delete(@RequestBody Map<String,String> userInfo){ public ResponseData delete(@RequestBody Map<String,String> userInfo){
// 不能删除当前登陆的账号
String token = request.getHeader("Authorization");
if (token.length() > 0){
String[] s = token.split(" ");
String username = JwtTokenUtils.getUsername(s[1]);
if (username.equals(userInfo.get("username"))) {
return ResponseData.fail("不能删除当前登陆的账号");
}
}
boolean b = accountService.deleteByUsername(userInfo.get("username")); boolean b = accountService.deleteByUsername(userInfo.get("username"));
JSONObject res = new JSONObject(); JSONObject res = new JSONObject();
res.put("result", b); res.put("result", b);

12
src/main/java/com/iflytop/nuclear/controller/NuclearCoreController.java

@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.iflytop.nuclear.model.NuclearCore; import com.iflytop.nuclear.model.NuclearCore;
import com.iflytop.nuclear.model.NuclearStation; import com.iflytop.nuclear.model.NuclearStation;
import com.iflytop.nuclear.service.NuclearCoreService; import com.iflytop.nuclear.service.NuclearCoreService;
import com.iflytop.nuclear.service.NuclearStationService;
import com.iflytop.nuclear.utils.ResponseData; import com.iflytop.nuclear.utils.ResponseData;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -27,10 +28,21 @@ public class NuclearCoreController {
@Autowired @Autowired
NuclearCoreService nuclearCoreService; NuclearCoreService nuclearCoreService;
@Autowired
NuclearStationService nuclearStationService;
@GetMapping("/list") @GetMapping("/list")
public ResponseData list() { public ResponseData list() {
// 将数据中stationid转换为名称
List<NuclearCore> list = nuclearCoreService.list(); List<NuclearCore> list = nuclearCoreService.list();
if (list.size() > 0){
for (NuclearCore l : list) {
NuclearStation nuclearStation = nuclearStationService.getById(l.getStationId());
if(nuclearStation != null) {
l.setStationName(nuclearStation.getName());
}
}
}
JSONObject res = new JSONObject(); JSONObject res = new JSONObject();
res.put("list", list); res.put("list", list);
return ResponseData.success(res); return ResponseData.success(res);

4
src/main/java/com/iflytop/nuclear/model/NuclearCore.java

@ -8,6 +8,8 @@ import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import java.beans.Transient;
/** /**
* @author cool * @author cool
* @date 2023/6/28 11:29 * @date 2023/6/28 11:29
@ -28,4 +30,6 @@ public class NuclearCore {
@TableField("station_id") @TableField("station_id")
private int stationId; private int stationId;
@TableField(exist = false)
private String stationName;
} }

BIN
uploadfiles/xlsx/20230630/堆芯模版.xlsx

Loading…
Cancel
Save