Blame view

src/main/java/com/example/demo/controller/SNController.java 2.51 KB
9f87bede   岑健浩   SNManage init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
  package com.example.demo.controller;
  
  import com.example.demo.exception.SNRepetitiveException;
  import com.example.demo.service.SNService;
  import com.example.demo.util.HttpResult;
  import io.swagger.annotations.Api;
  import io.swagger.annotations.ApiOperation;
  import org.apache.logging.log4j.LogManager;
  import org.apache.logging.log4j.Logger;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Controller;
  import org.springframework.web.bind.annotation.*;
  
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import java.io.IOException;
  
  @Api(tags = "SN操作")
  @Controller
  public class SNController {
      static Logger logger = LogManager.getLogger(SNController.class);
  
      @Autowired
      SNService snService;
  
      @ApiOperation("首页")
      @GetMapping("/index.html")
      public String index() {
          return "Index";
      }
  
      @ApiOperation("添加SN")
      @PostMapping("/add_SN")
      @ResponseBody
      public HttpResult addSN(@RequestBody String SNDto) {
  
          try {
              snService.addSN(SNDto);
              return HttpResult.success("添加成功");
          } catch (SNRepetitiveException e) {
              return HttpResult.fail("SN已存在,请勿重复添加!");
          } catch (Exception e) {
              logger.error(e.getMessage());
              return HttpResult.fail();
          }
  
      }
  
  
  //    @ApiOperation("获取全部SN")
  //    @GetMapping("/get_SNs")
  //    @ResponseBody
  //    public void getSNs(HttpServletRequest request, HttpServletResponse response) {
  //        try {
  //            snService.downloadSNFile(request, response);
  //        } catch (Exception e) {
  //            response.setStatus(500);
  //        }
  //
  //    }
  
      @ApiOperation("获取全部base64加密后的SN")
      @GetMapping("/get_SNs")
      @ResponseBody
      public HttpResult<String> getBase64SNs() throws IOException {
          try {
              return HttpResult.success("",snService.getEncryptSNs());
          } catch (Exception e) {
              logger.error(e.getMessage());
              return HttpResult.fail("服务器异常");
          }
  
      }
  
      @ApiOperation("删除指定SN")
      @PostMapping("/delete_SN")
      @ResponseBody
      public HttpResult deleteSN(@RequestBody String SN) {
          try {
              snService.deleteSN(SN);
              return HttpResult.success("SN已删除或不存在!");
          }
          catch (Exception e) {
              logger.error(e.getMessage());
              return HttpResult.fail("服务器异常!");
          }
      }
  
  
  }