张延森 il y a 4 ans
Parent
révision
58bc068989

+ 3
- 0
src/main/java/com/yunzhi/demo/common/Constants.java Voir le fichier

@@ -17,6 +17,9 @@ public class Constants {
17 17
     public final static String SUPER_ADMIN_ID = "1";
18 18
     public final static Integer SUPER_ADMIN_ROLE = 1;
19 19
 
20
+    // 默认用户密码
21
+    public final static String DEFAULT_PASSWORD = "abc@123";
22
+
20 23
     // 系统参数
21 24
     // 阅读文章可获取的积分
22 25
     public final static String SYS_PARAM_POST_POINTS = "POINTS_OF_PER_POST";

+ 14
- 5
src/main/java/com/yunzhi/demo/controller/LoginController.java Voir le fichier

@@ -12,10 +12,7 @@ import io.swagger.annotations.Api;
12 12
 import io.swagger.annotations.ApiOperation;
13 13
 import io.swagger.annotations.ApiParam;
14 14
 import org.springframework.beans.factory.annotation.Autowired;
15
-import org.springframework.web.bind.annotation.PostMapping;
16
-import org.springframework.web.bind.annotation.PutMapping;
17
-import org.springframework.web.bind.annotation.RequestBody;
18
-import org.springframework.web.bind.annotation.RestController;
15
+import org.springframework.web.bind.annotation.*;
19 16
 
20 17
 import java.util.HashMap;
21 18
 import java.util.Map;
@@ -89,7 +86,7 @@ public class LoginController extends BaseController {
89 86
         SysUser currentUser = getCurrentUser();
90 87
         SysLogin sysLogin = iSysLoginService.getByUser(currentUser.getUserId());
91 88
 
92
-        if (!checkPassword(param.getOriginPassword(), currentUser.getUserId(), sysLogin.getPassword())) {
89
+        if (!checkPassword(param.getOriginPassword(), sysLogin.getPassword(), currentUser.getUserId())) {
93 90
             return ResponseBean.error("原始密码不正确", ResponseBean.ERROR_ILLEGAL_PARAMS);
94 91
         }
95 92
 
@@ -99,6 +96,18 @@ public class LoginController extends BaseController {
99 96
         return ResponseBean.success("密码修改成功");
100 97
     }
101 98
 
99
+    @PutMapping("/admin/reset-password/{userId}")
100
+    @ApiOperation(value="重置密码", notes = "重置密码", httpMethod = "PUT", response = ResponseBean.class)
101
+    public ResponseBean resetPassword(@ApiParam("用户ID") @PathVariable String userId) throws Exception {
102
+        SysLogin sysLogin = iSysLoginService.getByUser(userId);
103
+
104
+        String newPassword = EncryptUtils.md5(EncryptUtils.md5(Constants.DEFAULT_PASSWORD), userId);
105
+        sysLogin.setPassword(newPassword);
106
+        iSysLoginService.updateById(sysLogin);
107
+
108
+        return ResponseBean.success("重置密码成功");
109
+    }
110
+
102 111
     private boolean checkPassword(String src, String targ, String salt) {
103 112
         return EncryptUtils.md5(src, salt).equals(targ);
104 113
     }

+ 1
- 1
src/main/java/com/yunzhi/demo/controller/SysUserController.java Voir le fichier

@@ -108,7 +108,7 @@ public class SysUserController extends BaseController {
108 108
             SysLogin newLogin = new SysLogin();
109 109
             newLogin.setUserId(sysUser.getUserId());
110 110
             newLogin.setLoginName(sysUser.getLoginName());
111
-            newLogin.setPassword(EncryptUtils.md5(EncryptUtils.md5("abc@123"), sysUser.getUserId()));
111
+            newLogin.setPassword(EncryptUtils.md5(EncryptUtils.md5(Constants.DEFAULT_PASSWORD), sysUser.getUserId()));
112 112
 
113 113
             iSysLoginService.save(newLogin);
114 114
 

+ 28
- 9
src/main/java/com/yunzhi/demo/controller/TdPostTypeController.java Voir le fichier

@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6 6
 import com.yunzhi.demo.common.BaseController;
7 7
 import com.yunzhi.demo.common.Constants;
8 8
 import com.yunzhi.demo.common.ResponseBean;
9
+import com.yunzhi.demo.common.StringUtils;
9 10
 import io.swagger.annotations.Api;
10 11
 import io.swagger.annotations.ApiOperation;
11 12
 import io.swagger.annotations.ApiParam;
@@ -70,9 +71,12 @@ public class TdPostTypeController extends BaseController {
70 71
      * @param tdPostType 实体对象
71 72
      * @return
72 73
      */
73
-    @RequestMapping(value="/tdPostType",method= RequestMethod.POST)
74
+    @RequestMapping(value="/admin/post-type",method= RequestMethod.POST)
74 75
     @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
75 76
     public ResponseBean tdPostTypeAdd(@ApiParam("保存内容") @RequestBody TdPostType tdPostType) throws Exception{
77
+        if (StringUtils.isEmpty(tdPostType.getName())) {
78
+            return ResponseBean.error("类型名称不能为空", ResponseBean.ERROR_ILLEGAL_PARAMS);
79
+        }
76 80
 
77 81
         if (iTdPostTypeService.save(tdPostType)){
78 82
             return ResponseBean.success(tdPostType);
@@ -85,10 +89,17 @@ public class TdPostTypeController extends BaseController {
85 89
      * 根据id删除对象
86 90
      * @param id  实体ID
87 91
      */
88
-    @RequestMapping(value="/tdPostType/{id}", method= RequestMethod.DELETE)
92
+    @RequestMapping(value="/post-type/{id}", method= RequestMethod.DELETE)
89 93
     @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
90
-    public ResponseBean tdPostTypeDelete(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
91
-        if(iTdPostTypeService.removeById(id)){
94
+    public ResponseBean tdPostTypeDelete(@ApiParam("对象ID") @PathVariable String id) throws Exception{
95
+        TdPostType tdPostType = iTdPostTypeService.getById(id);
96
+        if (null == tdPostType || Constants.STATUS_DELETED.equals(tdPostType.getStatus())) {
97
+            return ResponseBean.success("success");
98
+        }
99
+
100
+        tdPostType.setStatus(Constants.STATUS_DELETED);
101
+
102
+        if(iTdPostTypeService.updateById(tdPostType)){
92 103
             return ResponseBean.success("success");
93 104
         }else {
94 105
             return ResponseBean.error("删除失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
@@ -101,10 +112,13 @@ public class TdPostTypeController extends BaseController {
101 112
      * @param tdPostType 实体对象
102 113
      * @return
103 114
      */
104
-    @RequestMapping(value="/tdPostType/{id}",method= RequestMethod.PUT)
115
+    @RequestMapping(value="/post-type/{id}",method= RequestMethod.PUT)
105 116
     @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
106
-    public ResponseBean tdPostTypeUpdate(@ApiParam("对象ID") @PathVariable Integer id,
107
-                                        @ApiParam("更新内容") @RequestBody TdPostType tdPostType) throws Exception{
117
+    public ResponseBean tdPostTypeUpdate(@ApiParam("对象ID") @PathVariable String id,
118
+                                         @ApiParam("更新内容") @RequestBody TdPostType tdPostType) throws Exception {
119
+        if (StringUtils.isEmpty(tdPostType.getName())) {
120
+            return ResponseBean.error("类型名称不能为空", ResponseBean.ERROR_ILLEGAL_PARAMS);
121
+        }
108 122
 
109 123
         if (iTdPostTypeService.updateById(tdPostType)){
110 124
             return ResponseBean.success(iTdPostTypeService.getById(id));
@@ -117,9 +131,14 @@ public class TdPostTypeController extends BaseController {
117 131
      * 根据id查询对象
118 132
      * @param id  实体ID
119 133
      */
120
-    @RequestMapping(value="/tdPostType/{id}",method= RequestMethod.GET)
134
+    @RequestMapping(value="/post-type/{id}",method= RequestMethod.GET)
121 135
     @ApiOperation(value="详情", notes = "详情", httpMethod = "GET", response = ResponseBean.class)
122 136
     public ResponseBean tdPostTypeGet(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
123
-        return ResponseBean.success(iTdPostTypeService.getById(id));
137
+        TdPostType tdPostType = iTdPostTypeService.getById(id);
138
+        if (null == tdPostType || Constants.STATUS_DELETED.equals(tdPostType.getStatus())) {
139
+            return ResponseBean.error("没有找到对应的信息", ResponseBean.ERROR_ILLEGAL_PARAMS);
140
+        }
141
+
142
+        return ResponseBean.success(tdPostType);
124 143
     }
125 144
 }

+ 1
- 1
src/main/java/com/yunzhi/demo/entity/TdPostType.java Voir le fichier

@@ -27,7 +27,7 @@ public class TdPostType implements Serializable {
27 27
     private static final long serialVersionUID = 1L;
28 28
 
29 29
     @ApiModelProperty(value = "分类主键")
30
-    @TableId(value = "type_id", type = IdType.INPUT)
30
+    @TableId(value = "type_id", type = IdType.UUID)
31 31
     private String typeId;
32 32
 
33 33
     @ApiModelProperty(value = "名称")