Yansen 2 years ago
parent
commit
3da23ffb6d

+ 68
- 52
src/main/java/com/example/civilizedcity/controller/SysLoginController.java View File

@@ -3,8 +3,9 @@ package com.example.civilizedcity.controller;
3 3
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4 4
 import com.baomidou.mybatisplus.core.metadata.IPage;
5 5
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6
-import com.example.civilizedcity.common.BaseController;
7
-import com.example.civilizedcity.common.ResponseBean;
6
+import com.example.civilizedcity.common.*;
7
+
8
+import java.time.LocalDateTime;
8 9
 import java.util.List;
9 10
 import io.swagger.annotations.Api;
10 11
 import io.swagger.annotations.ApiOperation;
@@ -27,36 +28,34 @@ public class SysLoginController extends BaseController {
27 28
     @Autowired
28 29
     private SysLoginService sysLoginService;
29 30
     
30
-    /** 
31
-     * 通过ID查询单条数据 
32
-     *
33
-     * @param loginId 主键
34
-     * @return 实例对象
35
-     */
36
-    @ApiOperation("通过ID查询单条数据")
37
-    @GetMapping("/sysLogin/{id}")
38
-    public ResponseBean queryById(@ApiParam("对象ID") @PathVariable Integer id) throws Exception {
39
-        return ResponseBean.success(sysLoginService.getById(id));
40
-    }
31
+//    /**
32
+//     * 通过ID查询单条数据
33
+//     *
34
+//     * @param loginId 主键
35
+//     * @return 实例对象
36
+//     */
37
+//    @ApiOperation("通过ID查询单条数据")
38
+//    @GetMapping("/sysLogin/{id}")
39
+//    public ResponseBean queryById(@ApiParam("对象ID") @PathVariable Integer id) throws Exception {
40
+//        return ResponseBean.success(sysLoginService.getById(id));
41
+//    }
41 42
     
42 43
     /** 
43 44
      * 分页查询
44 45
      *
45
-     * @param pageNum 当前页码
46
-     * @param pageSize 每页条数
46
+     * @param userId 当前页码
47 47
      * @return 查询结果
48 48
      */
49
-    @ApiOperation("分页查询")
49
+    @ApiOperation("查询人员登录信息")
50 50
     @GetMapping("/sysLogin")
51
-    public ResponseBean list(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
52
-                            @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize) throws Exception {
53
-        
54
-        IPage<SysLogin> pg = new Page<>(pageNum, pageSize);
55
-        // QueryWrapper<SysLogin> queryWrapper = new QueryWrapper<>();
56
-        // queryWrapper.orderByDesc("create_date");
57
-        IPage<SysLogin> result = sysLoginService.page(pg);
58
-        
59
-        return ResponseBean.success(result);
51
+    public ResponseBean list(@ApiParam("用户ID") @RequestParam(value ="userId") String userId) throws Exception {
52
+
53
+        SysLogin sysLogin = sysLoginService.getExistBy("user_id", userId, false, true);
54
+        if (null != sysLogin) {
55
+            sysLogin.setPassword(null);
56
+        }
57
+
58
+        return ResponseBean.success(sysLogin);
60 59
     }
61 60
     
62 61
     /** 
@@ -68,34 +67,51 @@ public class SysLoginController extends BaseController {
68 67
     @ApiOperation("新增数据")
69 68
     @PostMapping("/sysLogin")
70 69
     public ResponseBean add(@ApiParam("对象实体") @RequestBody SysLogin sysLogin) throws Exception {
71
-        sysLoginService.save(sysLogin);
72
-        return ResponseBean.success(sysLogin);
73
-    }
74
-    
75
-    /** 
76
-     * 更新数据
77
-     *
78
-     * @param sysLogin 实例对象
79
-     * @return 实例对象
80
-     */
81
-    @ApiOperation("更新数据")
82
-    @PutMapping("/sysLogin/{id}")
83
-    public ResponseBean edit(@ApiParam("对象实体") @RequestBody SysLogin sysLogin,
84
-                            @ApiParam("对象ID") @PathVariable Integer id ) throws Exception {
85
-        sysLoginService.updateById(sysLogin);
70
+
71
+        if (null == sysLogin.getLoginId()) {
72
+            // 新增
73
+            String password = EncryptUtils.md5(sysLogin.getPassword(), sysLogin.getUserId());
74
+            sysLogin.setPassword(password);
75
+            sysLogin.setStatus(Constants.STATUS_NORMAL);
76
+            sysLogin.setCreateDate(LocalDateTime.now());
77
+            sysLoginService.save(sysLogin);
78
+        } else {
79
+            // 更新
80
+            if (!StringUtils.isEmpty(sysLogin.getPassword())) {
81
+                String password = EncryptUtils.md5(sysLogin.getPassword(), sysLogin.getUserId());
82
+                sysLogin.setPassword(password);
83
+            }
84
+            sysLoginService.updateById(sysLogin);
85
+        }
86
+
87
+        sysLogin.setPassword(null);
86 88
         return ResponseBean.success(sysLogin);
87 89
     }
88 90
     
89
-    /** 
90
-     * 通过主键删除数据
91
-     *
92
-     * @param loginId 主键
93
-     * @return 是否成功
94
-     */
95
-    @ApiOperation("通过主键删除数据")
96
-    @DeleteMapping("/sysLogin/{id}")
97
-    public ResponseBean deleteById(@ApiParam("对象ID") @PathVariable Integer id){
98
-        sysLoginService.removeLogicById(id);
99
-        return ResponseBean.success("success");
100
-    }
91
+//    /**
92
+//     * 更新数据
93
+//     *
94
+//     * @param sysLogin 实例对象
95
+//     * @return 实例对象
96
+//     */
97
+//    @ApiOperation("更新数据")
98
+//    @PutMapping("/sysLogin/{id}")
99
+//    public ResponseBean edit(@ApiParam("对象实体") @RequestBody SysLogin sysLogin,
100
+//                            @ApiParam("对象ID") @PathVariable Integer id ) throws Exception {
101
+//        sysLoginService.updateById(sysLogin);
102
+//        return ResponseBean.success(sysLogin);
103
+//    }
104
+//
105
+//    /**
106
+//     * 通过主键删除数据
107
+//     *
108
+//     * @param loginId 主键
109
+//     * @return 是否成功
110
+//     */
111
+//    @ApiOperation("通过主键删除数据")
112
+//    @DeleteMapping("/sysLogin/{id}")
113
+//    public ResponseBean deleteById(@ApiParam("对象ID") @PathVariable Integer id){
114
+//        sysLoginService.removeLogicById(id);
115
+//        return ResponseBean.success("success");
116
+//    }
101 117
 }

+ 1
- 1
src/main/java/com/example/civilizedcity/entity/SysLogin.java View File

@@ -25,7 +25,7 @@ import lombok.experimental.Accessors;
25 25
 public class SysLogin implements Serializable,Cloneable{
26 26
     /** 登录ID */
27 27
     @ApiModelProperty(name = "登录ID",notes = "")
28
-    @TableId(value = "login_id", type = IdType.INPUT)
28
+    @TableId(value = "login_id", type = IdType.AUTO)
29 29
     private Integer loginId ;
30 30
     /** 机构ID */
31 31
     @ApiModelProperty(name = "机构ID",notes = "")