张延森 4 years ago
parent
commit
58bc068989

+ 3
- 0
src/main/java/com/yunzhi/demo/common/Constants.java View File

17
     public final static String SUPER_ADMIN_ID = "1";
17
     public final static String SUPER_ADMIN_ID = "1";
18
     public final static Integer SUPER_ADMIN_ROLE = 1;
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
     public final static String SYS_PARAM_POST_POINTS = "POINTS_OF_PER_POST";
25
     public final static String SYS_PARAM_POST_POINTS = "POINTS_OF_PER_POST";

+ 14
- 5
src/main/java/com/yunzhi/demo/controller/LoginController.java View File

12
 import io.swagger.annotations.ApiOperation;
12
 import io.swagger.annotations.ApiOperation;
13
 import io.swagger.annotations.ApiParam;
13
 import io.swagger.annotations.ApiParam;
14
 import org.springframework.beans.factory.annotation.Autowired;
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
 import java.util.HashMap;
17
 import java.util.HashMap;
21
 import java.util.Map;
18
 import java.util.Map;
89
         SysUser currentUser = getCurrentUser();
86
         SysUser currentUser = getCurrentUser();
90
         SysLogin sysLogin = iSysLoginService.getByUser(currentUser.getUserId());
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
             return ResponseBean.error("原始密码不正确", ResponseBean.ERROR_ILLEGAL_PARAMS);
90
             return ResponseBean.error("原始密码不正确", ResponseBean.ERROR_ILLEGAL_PARAMS);
94
         }
91
         }
95
 
92
 
99
         return ResponseBean.success("密码修改成功");
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
     private boolean checkPassword(String src, String targ, String salt) {
111
     private boolean checkPassword(String src, String targ, String salt) {
103
         return EncryptUtils.md5(src, salt).equals(targ);
112
         return EncryptUtils.md5(src, salt).equals(targ);
104
     }
113
     }

+ 1
- 1
src/main/java/com/yunzhi/demo/controller/SysUserController.java View File

108
             SysLogin newLogin = new SysLogin();
108
             SysLogin newLogin = new SysLogin();
109
             newLogin.setUserId(sysUser.getUserId());
109
             newLogin.setUserId(sysUser.getUserId());
110
             newLogin.setLoginName(sysUser.getLoginName());
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
             iSysLoginService.save(newLogin);
113
             iSysLoginService.save(newLogin);
114
 
114
 

+ 28
- 9
src/main/java/com/yunzhi/demo/controller/TdPostTypeController.java View File

6
 import com.yunzhi.demo.common.BaseController;
6
 import com.yunzhi.demo.common.BaseController;
7
 import com.yunzhi.demo.common.Constants;
7
 import com.yunzhi.demo.common.Constants;
8
 import com.yunzhi.demo.common.ResponseBean;
8
 import com.yunzhi.demo.common.ResponseBean;
9
+import com.yunzhi.demo.common.StringUtils;
9
 import io.swagger.annotations.Api;
10
 import io.swagger.annotations.Api;
10
 import io.swagger.annotations.ApiOperation;
11
 import io.swagger.annotations.ApiOperation;
11
 import io.swagger.annotations.ApiParam;
12
 import io.swagger.annotations.ApiParam;
70
      * @param tdPostType 实体对象
71
      * @param tdPostType 实体对象
71
      * @return
72
      * @return
72
      */
73
      */
73
-    @RequestMapping(value="/tdPostType",method= RequestMethod.POST)
74
+    @RequestMapping(value="/admin/post-type",method= RequestMethod.POST)
74
     @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
75
     @ApiOperation(value="保存", notes = "保存", httpMethod = "POST", response = ResponseBean.class)
75
     public ResponseBean tdPostTypeAdd(@ApiParam("保存内容") @RequestBody TdPostType tdPostType) throws Exception{
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
         if (iTdPostTypeService.save(tdPostType)){
81
         if (iTdPostTypeService.save(tdPostType)){
78
             return ResponseBean.success(tdPostType);
82
             return ResponseBean.success(tdPostType);
85
      * 根据id删除对象
89
      * 根据id删除对象
86
      * @param id  实体ID
90
      * @param id  实体ID
87
      */
91
      */
88
-    @RequestMapping(value="/tdPostType/{id}", method= RequestMethod.DELETE)
92
+    @RequestMapping(value="/post-type/{id}", method= RequestMethod.DELETE)
89
     @ApiOperation(value="删除", notes = "删除", httpMethod = "DELETE", response = ResponseBean.class)
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
             return ResponseBean.success("success");
103
             return ResponseBean.success("success");
93
         }else {
104
         }else {
94
             return ResponseBean.error("删除失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
105
             return ResponseBean.error("删除失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
101
      * @param tdPostType 实体对象
112
      * @param tdPostType 实体对象
102
      * @return
113
      * @return
103
      */
114
      */
104
-    @RequestMapping(value="/tdPostType/{id}",method= RequestMethod.PUT)
115
+    @RequestMapping(value="/post-type/{id}",method= RequestMethod.PUT)
105
     @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
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
         if (iTdPostTypeService.updateById(tdPostType)){
123
         if (iTdPostTypeService.updateById(tdPostType)){
110
             return ResponseBean.success(iTdPostTypeService.getById(id));
124
             return ResponseBean.success(iTdPostTypeService.getById(id));
117
      * 根据id查询对象
131
      * 根据id查询对象
118
      * @param id  实体ID
132
      * @param id  实体ID
119
      */
133
      */
120
-    @RequestMapping(value="/tdPostType/{id}",method= RequestMethod.GET)
134
+    @RequestMapping(value="/post-type/{id}",method= RequestMethod.GET)
121
     @ApiOperation(value="详情", notes = "详情", httpMethod = "GET", response = ResponseBean.class)
135
     @ApiOperation(value="详情", notes = "详情", httpMethod = "GET", response = ResponseBean.class)
122
     public ResponseBean tdPostTypeGet(@ApiParam("对象ID") @PathVariable Integer id) throws Exception{
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 View File

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