作者 王勇

为userinfo表添加了字段

@@ -3,10 +3,7 @@ package com.sunyo.wlpt.message.bus.service.controller; @@ -3,10 +3,7 @@ package com.sunyo.wlpt.message.bus.service.controller;
3 import com.sunyo.wlpt.message.bus.service.domain.UserInfo; 3 import com.sunyo.wlpt.message.bus.service.domain.UserInfo;
4 import com.sunyo.wlpt.message.bus.service.response.ResultJson; 4 import com.sunyo.wlpt.message.bus.service.response.ResultJson;
5 import com.sunyo.wlpt.message.bus.service.service.UserInfoService; 5 import com.sunyo.wlpt.message.bus.service.service.UserInfoService;
6 -import org.springframework.web.bind.annotation.CrossOrigin;  
7 -import org.springframework.web.bind.annotation.GetMapping;  
8 -import org.springframework.web.bind.annotation.RequestMapping;  
9 -import org.springframework.web.bind.annotation.RestController; 6 +import org.springframework.web.bind.annotation.*;
10 7
11 import javax.annotation.Resource; 8 import javax.annotation.Resource;
12 import java.util.List; 9 import java.util.List;
@@ -35,4 +32,47 @@ public class UserInfoController { @@ -35,4 +32,47 @@ public class UserInfoController {
35 ? new ResultJson<>("200", "查询用户信息列表,成功", userInfos) 32 ? new ResultJson<>("200", "查询用户信息列表,成功", userInfos)
36 : new ResultJson<>("500", "查询用户信息列表,失败"); 33 : new ResultJson<>("500", "查询用户信息列表,失败");
37 } 34 }
  35 +
  36 + /**
  37 + * 增加用户
  38 + *
  39 + * @param userInfo 用户信息
  40 + * @return {@link ResultJson}
  41 + */
  42 + @PostMapping("/insert")
  43 + public ResultJson insertUserByEntity(UserInfo userInfo)
  44 + {
  45 + return userInfoService.insertSelective(userInfo);
  46 + }
  47 +
  48 + /**
  49 + * @param description 描述
  50 + * @param username 用户名称
  51 + * @param password 密码
  52 + * @return {@link ResultJson}
  53 + */
  54 + @PostMapping("/insertByParam")
  55 + public ResultJson insertUserByParam(@RequestParam(value = "description", required = false) String description,
  56 + String username, String password)
  57 + {
  58 + // 接收参数
  59 + UserInfo userInfo = UserInfo.builder().username(username)
  60 + .password(password)
  61 + .description(description)
  62 + .build();
  63 + return userInfoService.insertSelective(userInfo);
  64 + }
  65 +
  66 + /**
  67 + * 编辑用户信息
  68 + *
  69 + * @param userInfo {@link UserInfo}
  70 + * @return
  71 + */
  72 + @PostMapping("/update")
  73 + public ResultJson updateUser(UserInfo userInfo)
  74 + {
  75 + return userInfoService.updateByPrimaryKeySelective(userInfo);
  76 + }
  77 +
38 } 78 }
1 package com.sunyo.wlpt.message.bus.service.domain; 1 package com.sunyo.wlpt.message.bus.service.domain;
2 2
3 -import io.swagger.annotations.ApiModel;  
4 -import io.swagger.annotations.ApiModelProperty;  
5 import lombok.AllArgsConstructor; 3 import lombok.AllArgsConstructor;
6 import lombok.Builder; 4 import lombok.Builder;
7 import lombok.Data; 5 import lombok.Data;
@@ -13,15 +11,15 @@ import java.util.Date; @@ -13,15 +11,15 @@ import java.util.Date;
13 /** 11 /**
14 * @author 子诚 12 * @author 子诚
15 * Description:MQ账户信息表 13 * Description:MQ账户信息表
16 - * 时间:2020/7/23 15:59 14 + * 时间:2020/8/10 17:44
17 */ 15 */
18 -  
19 @Data 16 @Data
20 @Builder 17 @Builder
21 @AllArgsConstructor 18 @AllArgsConstructor
22 @NoArgsConstructor 19 @NoArgsConstructor
23 public class UserInfo implements Serializable { 20 public class UserInfo implements Serializable {
24 private static final long serialVersionUID = 8510385519421924997L; 21 private static final long serialVersionUID = 8510385519421924997L;
  22 +
25 /** 23 /**
26 * 用户的ID 24 * 用户的ID
27 */ 25 */
@@ -38,6 +36,31 @@ public class UserInfo implements Serializable { @@ -38,6 +36,31 @@ public class UserInfo implements Serializable {
38 private String password; 36 private String password;
39 37
40 /** 38 /**
  39 + * 所属服务器id
  40 + */
  41 + private String serverId;
  42 +
  43 + /**
  44 + * 所属服务器名称
  45 + */
  46 + private String serverName;
  47 +
  48 + /**
  49 + * 对应虚拟主机的id
  50 + */
  51 + private String virtualHostId;
  52 +
  53 + /**
  54 + * 对应虚拟主机的名称
  55 + */
  56 + private String virtualHostName;
  57 +
  58 + /**
  59 + * 用户的姓名(备用字段)
  60 + */
  61 + private String realName;
  62 +
  63 + /**
41 * 用户相关描述 64 * 用户相关描述
42 */ 65 */
43 private String description; 66 private String description;
1 package com.sunyo.wlpt.message.bus.service.mapper; 1 package com.sunyo.wlpt.message.bus.service.mapper;
2 2
3 import com.sunyo.wlpt.message.bus.service.domain.UserInfo; 3 import com.sunyo.wlpt.message.bus.service.domain.UserInfo;
4 -import org.apache.ibatis.annotations.Mapper;  
5 -import org.apache.ibatis.annotations.Param;  
6 -  
7 -import java.util.List; 4 +import org.apache.ibatis.annotations.Mapper;import org.apache.ibatis.annotations.Param;import java.util.List;
8 5
9 /** 6 /**
10 * @author 子诚 7 * @author 子诚
11 * Description: 8 * Description:
12 - * 时间:2020/7/23 15:59 9 + * 时间:2020/8/10 17:44
13 */ 10 */
14 @Mapper 11 @Mapper
15 public interface UserInfoMapper { 12 public interface UserInfoMapper {
@@ -46,14 +43,6 @@ public interface UserInfoMapper { @@ -46,14 +43,6 @@ public interface UserInfoMapper {
46 UserInfo selectByPrimaryKey(String id); 43 UserInfo selectByPrimaryKey(String id);
47 44
48 /** 45 /**
49 - * 查询,根据用户名称  
50 - *  
51 - * @param username 用户登录名称  
52 - * @return {@link UserInfo}  
53 - */  
54 - UserInfo selectByUsername(String username);  
55 -  
56 - /**  
57 * update record selective 46 * update record selective
58 * 47 *
59 * @param record the updated record 48 * @param record the updated record
@@ -70,6 +59,14 @@ public interface UserInfoMapper { @@ -70,6 +59,14 @@ public interface UserInfoMapper {
70 int updateByPrimaryKey(UserInfo record); 59 int updateByPrimaryKey(UserInfo record);
71 60
72 /** 61 /**
  62 + * 查询,根据用户名称
  63 + *
  64 + * @param username 用户登录名称
  65 + * @return {@link UserInfo}
  66 + */
  67 + UserInfo selectByUsername(String username);
  68 +
  69 + /**
73 * 仅,查询用户列表 70 * 仅,查询用户列表
74 * 71 *
75 * @return 用户信息集合 72 * @return 用户信息集合
1 package com.sunyo.wlpt.message.bus.service.service; 1 package com.sunyo.wlpt.message.bus.service.service;
2 2
3 import com.sunyo.wlpt.message.bus.service.domain.UserInfo; 3 import com.sunyo.wlpt.message.bus.service.domain.UserInfo;
  4 +import com.sunyo.wlpt.message.bus.service.response.ResultJson;
4 5
5 import java.util.List; 6 import java.util.List;
6 7
@@ -33,7 +34,7 @@ public interface UserInfoService { @@ -33,7 +34,7 @@ public interface UserInfoService {
33 * @param record the record 34 * @param record the record
34 * @return insert count 35 * @return insert count
35 */ 36 */
36 - int insertSelective(UserInfo record); 37 + ResultJson insertSelective(UserInfo record);
37 38
38 /** 39 /**
39 * 查询,根据主键 40 * 查询,根据主键
@@ -57,7 +58,7 @@ public interface UserInfoService { @@ -57,7 +58,7 @@ public interface UserInfoService {
57 * @param record the updated record 58 * @param record the updated record
58 * @return update count 59 * @return update count
59 */ 60 */
60 - int updateByPrimaryKeySelective(UserInfo record); 61 + ResultJson updateByPrimaryKeySelective(UserInfo record);
61 62
62 /** 63 /**
63 * 更新,根据主键 64 * 更新,根据主键
@@ -87,3 +88,4 @@ public interface UserInfoService { @@ -87,3 +88,4 @@ public interface UserInfoService {
87 88
88 89
89 90
  91 +
@@ -2,7 +2,11 @@ package com.sunyo.wlpt.message.bus.service.service.impl; @@ -2,7 +2,11 @@ package com.sunyo.wlpt.message.bus.service.service.impl;
2 2
3 import com.sunyo.wlpt.message.bus.service.domain.UserInfo; 3 import com.sunyo.wlpt.message.bus.service.domain.UserInfo;
4 import com.sunyo.wlpt.message.bus.service.mapper.UserInfoMapper; 4 import com.sunyo.wlpt.message.bus.service.mapper.UserInfoMapper;
  5 +import com.sunyo.wlpt.message.bus.service.response.ResultJson;
5 import com.sunyo.wlpt.message.bus.service.service.UserInfoService; 6 import com.sunyo.wlpt.message.bus.service.service.UserInfoService;
  7 +import com.sunyo.wlpt.message.bus.service.utils.IdUtils;
  8 +import io.netty.util.internal.StringUtil;
  9 +import org.springframework.util.DigestUtils;
6 import org.springframework.stereotype.Service; 10 import org.springframework.stereotype.Service;
7 11
8 import javax.annotation.Resource; 12 import javax.annotation.Resource;
@@ -32,11 +36,22 @@ public class UserInfoServiceImpl implements UserInfoService { @@ -32,11 +36,22 @@ public class UserInfoServiceImpl implements UserInfoService {
32 } 36 }
33 37
34 @Override 38 @Override
35 - public int insertSelective(UserInfo record) 39 + public ResultJson insertSelective(UserInfo userInfo)
36 { 40 {
37 - return userInfoMapper.insertSelective(record); 41 + ResultJson validateResult = validateUser(userInfo);
  42 + if (!"200".equals(validateUser(userInfo).getCode())) {
  43 + return validateResult;
  44 + }
  45 + if (StringUtil.isNullOrEmpty(userInfo.getId())) {
  46 + userInfo.setId(IdUtils.generateId());
  47 + }
  48 + userInfo.setPassword(DigestUtils.md5DigestAsHex(userInfo.getPassword().getBytes()));
  49 + return userInfoMapper.insertSelective(userInfo) > 0
  50 + ? new ResultJson<>("200", "添加用户信息,成功")
  51 + : new ResultJson<>("500", "添加用户信息,失败");
38 } 52 }
39 53
  54 +
40 @Override 55 @Override
41 public UserInfo selectByPrimaryKey(String id) 56 public UserInfo selectByPrimaryKey(String id)
42 { 57 {
@@ -50,9 +65,39 @@ public class UserInfoServiceImpl implements UserInfoService { @@ -50,9 +65,39 @@ public class UserInfoServiceImpl implements UserInfoService {
50 } 65 }
51 66
52 @Override 67 @Override
53 - public int updateByPrimaryKeySelective(UserInfo record) 68 + public ResultJson updateByPrimaryKeySelective(UserInfo userInfo)
54 { 69 {
55 - return userInfoMapper.updateByPrimaryKeySelective(record); 70 + if (StringUtil.isNullOrEmpty(userInfo.getId())) {
  71 + return new ResultJson<>("400", "该用户不存在");
  72 + }
  73 +
  74 +
  75 + return userInfoMapper.updateByPrimaryKeySelective(userInfo) > 0
  76 + ? new ResultJson<>("200", "修改用户信息,成功")
  77 + : new ResultJson<>("500", "修改用户信息,失败");
  78 + }
  79 +
  80 + /**
  81 + * 校验用户名称是否已经存在
  82 + */
  83 + public ResultJson validateUser(UserInfo userInfo)
  84 + {
  85 + if (StringUtil.isNullOrEmpty(userInfo.getUsername()) || StringUtil.isNullOrEmpty(userInfo.getPassword())) {
  86 + return new ResultJson<>("400", "用户名称和密码,不能为空");
  87 + }
  88 + String userId = userInfo.getId();
  89 + if (!StringUtil.isNullOrEmpty(userId)) {
  90 + UserInfo oldUserInfo = userInfoMapper.selectByPrimaryKey(userId);
  91 + if (!userInfo.getUsername().equals(oldUserInfo.getUsername())) {
  92 + return new ResultJson<>("400", "用户名称,不可修改");
  93 + }
  94 + return ResultJson.success("通过校验");
  95 + } else {
  96 + List<UserInfo> userInfos = userInfoMapper.selectUserExist(userInfo.getUsername());
  97 + return userInfos.size() > 0
  98 + ? new ResultJson<>("400", "该用户,已存在")
  99 + : ResultJson.success("通过校验");
  100 + }
56 } 101 }
57 102
58 @Override 103 @Override
@@ -68,7 +113,7 @@ public class UserInfoServiceImpl implements UserInfoService { @@ -68,7 +113,7 @@ public class UserInfoServiceImpl implements UserInfoService {
68 } 113 }
69 114
70 @Override 115 @Override
71 - public List<UserInfo> selectUserExist(String username) 116 + public List<UserInfo> selectUserExist(String username)
72 { 117 {
73 return userInfoMapper.selectUserExist(username); 118 return userInfoMapper.selectUserExist(username);
74 } 119 }
@@ -77,3 +122,4 @@ public class UserInfoServiceImpl implements UserInfoService { @@ -77,3 +122,4 @@ public class UserInfoServiceImpl implements UserInfoService {
77 122
78 123
79 124
  125 +
@@ -8,13 +8,19 @@ @@ -8,13 +8,19 @@
8 <id column="id" jdbcType="VARCHAR" property="id"/> 8 <id column="id" jdbcType="VARCHAR" property="id"/>
9 <result column="username" jdbcType="VARCHAR" property="username"/> 9 <result column="username" jdbcType="VARCHAR" property="username"/>
10 <result column="password" jdbcType="VARCHAR" property="password"/> 10 <result column="password" jdbcType="VARCHAR" property="password"/>
  11 + <result column="server_id" jdbcType="VARCHAR" property="serverId"/>
  12 + <result column="server_name" jdbcType="VARCHAR" property="serverName"/>
  13 + <result column="virtual_host_id" jdbcType="VARCHAR" property="virtualHostId"/>
  14 + <result column="virtual_host_name" jdbcType="VARCHAR" property="virtualHostName"/>
  15 + <result column="real_name" jdbcType="VARCHAR" property="realName"/>
11 <result column="description" jdbcType="VARCHAR" property="description"/> 16 <result column="description" jdbcType="VARCHAR" property="description"/>
12 <result column="gmt_create" jdbcType="TIMESTAMP" property="gmtCreate"/> 17 <result column="gmt_create" jdbcType="TIMESTAMP" property="gmtCreate"/>
13 <result column="gmt_modified" jdbcType="TIMESTAMP" property="gmtModified"/> 18 <result column="gmt_modified" jdbcType="TIMESTAMP" property="gmtModified"/>
14 </resultMap> 19 </resultMap>
15 <sql id="Base_Column_List"> 20 <sql id="Base_Column_List">
16 <!--@mbg.generated--> 21 <!--@mbg.generated-->
17 - id, username, `password`, description, gmt_create, gmt_modified 22 + id, username, `password`, server_id, `server_name`, virtual_host_id, virtual_host_name,
  23 + real_name, description, gmt_create, gmt_modified
18 </sql> 24 </sql>
19 <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap"> 25 <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
20 <!--@mbg.generated--> 26 <!--@mbg.generated-->
@@ -23,25 +29,6 @@ @@ -23,25 +29,6 @@
23 from user_info 29 from user_info
24 where id = #{id,jdbcType=VARCHAR} 30 where id = #{id,jdbcType=VARCHAR}
25 </select> 31 </select>
26 -  
27 - <select id="selectByUsername" parameterType="java.lang.String" resultMap="BaseResultMap">  
28 - <!--@mbg.generated-->  
29 - select  
30 - <include refid="Base_Column_List"/>  
31 - from user_info  
32 - where username = #{username,jdbcType=VARCHAR}  
33 - </select>  
34 -  
35 - <select id="getUserInfoList" resultMap="BaseResultMap">  
36 - <!--@mbg.generated-->  
37 - select id,  
38 - username,  
39 - description,  
40 - gmt_create,  
41 - gmt_modified  
42 - from user_info  
43 - </select>  
44 -  
45 <delete id="deleteByPrimaryKey" parameterType="java.lang.String"> 32 <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
46 <!--@mbg.generated--> 33 <!--@mbg.generated-->
47 delete 34 delete
@@ -51,9 +38,13 @@ @@ -51,9 +38,13 @@
51 <insert id="insert" parameterType="com.sunyo.wlpt.message.bus.service.domain.UserInfo"> 38 <insert id="insert" parameterType="com.sunyo.wlpt.message.bus.service.domain.UserInfo">
52 <!--@mbg.generated--> 39 <!--@mbg.generated-->
53 insert into user_info (id, username, `password`, 40 insert into user_info (id, username, `password`,
54 - description, gmt_create, gmt_modified) 41 + server_id, `server_name`, virtual_host_id,
  42 + virtual_host_name, real_name, description,
  43 + gmt_create, gmt_modified)
55 values (#{id,jdbcType=VARCHAR}, #{username,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR}, 44 values (#{id,jdbcType=VARCHAR}, #{username,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR},
56 - #{description,jdbcType=VARCHAR}, #{gmtCreate,jdbcType=TIMESTAMP}, #{gmtModified,jdbcType=TIMESTAMP}) 45 + #{serverId,jdbcType=VARCHAR}, #{serverName,jdbcType=VARCHAR}, #{virtualHostId,jdbcType=VARCHAR},
  46 + #{virtualHostName,jdbcType=VARCHAR}, #{realName,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR},
  47 + #{gmtCreate,jdbcType=TIMESTAMP}, #{gmtModified,jdbcType=TIMESTAMP})
57 </insert> 48 </insert>
58 <insert id="insertSelective" parameterType="com.sunyo.wlpt.message.bus.service.domain.UserInfo"> 49 <insert id="insertSelective" parameterType="com.sunyo.wlpt.message.bus.service.domain.UserInfo">
59 <!--@mbg.generated--> 50 <!--@mbg.generated-->
@@ -68,6 +59,21 @@ @@ -68,6 +59,21 @@
68 <if test="password != null"> 59 <if test="password != null">
69 `password`, 60 `password`,
70 </if> 61 </if>
  62 + <if test="serverId != null">
  63 + server_id,
  64 + </if>
  65 + <if test="serverName != null">
  66 + `server_name`,
  67 + </if>
  68 + <if test="virtualHostId != null">
  69 + virtual_host_id,
  70 + </if>
  71 + <if test="virtualHostName != null">
  72 + virtual_host_name,
  73 + </if>
  74 + <if test="realName != null">
  75 + real_name,
  76 + </if>
71 <if test="description != null"> 77 <if test="description != null">
72 description, 78 description,
73 </if> 79 </if>
@@ -88,6 +94,21 @@ @@ -88,6 +94,21 @@
88 <if test="password != null"> 94 <if test="password != null">
89 #{password,jdbcType=VARCHAR}, 95 #{password,jdbcType=VARCHAR},
90 </if> 96 </if>
  97 + <if test="serverId != null">
  98 + #{serverId,jdbcType=VARCHAR},
  99 + </if>
  100 + <if test="serverName != null">
  101 + #{serverName,jdbcType=VARCHAR},
  102 + </if>
  103 + <if test="virtualHostId != null">
  104 + #{virtualHostId,jdbcType=VARCHAR},
  105 + </if>
  106 + <if test="virtualHostName != null">
  107 + #{virtualHostName,jdbcType=VARCHAR},
  108 + </if>
  109 + <if test="realName != null">
  110 + #{realName,jdbcType=VARCHAR},
  111 + </if>
91 <if test="description != null"> 112 <if test="description != null">
92 #{description,jdbcType=VARCHAR}, 113 #{description,jdbcType=VARCHAR},
93 </if> 114 </if>
@@ -109,6 +130,21 @@ @@ -109,6 +130,21 @@
109 <if test="password != null"> 130 <if test="password != null">
110 `password` = #{password,jdbcType=VARCHAR}, 131 `password` = #{password,jdbcType=VARCHAR},
111 </if> 132 </if>
  133 + <if test="serverId != null">
  134 + server_id = #{serverId,jdbcType=VARCHAR},
  135 + </if>
  136 + <if test="serverName != null">
  137 + `server_name` = #{serverName,jdbcType=VARCHAR},
  138 + </if>
  139 + <if test="virtualHostId != null">
  140 + virtual_host_id = #{virtualHostId,jdbcType=VARCHAR},
  141 + </if>
  142 + <if test="virtualHostName != null">
  143 + virtual_host_name = #{virtualHostName,jdbcType=VARCHAR},
  144 + </if>
  145 + <if test="realName != null">
  146 + real_name = #{realName,jdbcType=VARCHAR},
  147 + </if>
112 <if test="description != null"> 148 <if test="description != null">
113 description = #{description,jdbcType=VARCHAR}, 149 description = #{description,jdbcType=VARCHAR},
114 </if> 150 </if>
@@ -124,14 +160,43 @@ @@ -124,14 +160,43 @@
124 <update id="updateByPrimaryKey" parameterType="com.sunyo.wlpt.message.bus.service.domain.UserInfo"> 160 <update id="updateByPrimaryKey" parameterType="com.sunyo.wlpt.message.bus.service.domain.UserInfo">
125 <!--@mbg.generated--> 161 <!--@mbg.generated-->
126 update user_info 162 update user_info
127 - set username = #{username,jdbcType=VARCHAR},  
128 - `password` = #{password,jdbcType=VARCHAR},  
129 - description = #{description,jdbcType=VARCHAR},  
130 - gmt_create = #{gmtCreate,jdbcType=TIMESTAMP},  
131 - gmt_modified = #{gmtModified,jdbcType=TIMESTAMP} 163 + set username = #{username,jdbcType=VARCHAR},
  164 + `password` = #{password,jdbcType=VARCHAR},
  165 + server_id = #{serverId,jdbcType=VARCHAR},
  166 + `server_name` = #{serverName,jdbcType=VARCHAR},
  167 + virtual_host_id = #{virtualHostId,jdbcType=VARCHAR},
  168 + virtual_host_name = #{virtualHostName,jdbcType=VARCHAR},
  169 + real_name = #{realName,jdbcType=VARCHAR},
  170 + description = #{description,jdbcType=VARCHAR},
  171 + gmt_create = #{gmtCreate,jdbcType=TIMESTAMP},
  172 + gmt_modified = #{gmtModified,jdbcType=TIMESTAMP}
132 where id = #{id,jdbcType=VARCHAR} 173 where id = #{id,jdbcType=VARCHAR}
133 </update> 174 </update>
134 175
  176 + <select id="selectByUsername" parameterType="java.lang.String" resultMap="BaseResultMap">
  177 + <!--@mbg.generated-->
  178 + select
  179 + <include refid="Base_Column_List"/>
  180 + from user_info
  181 + where username = #{username,jdbcType=VARCHAR}
  182 + </select>
  183 +
  184 + <select id="getUserInfoList" resultMap="BaseResultMap">
  185 + <!--@mbg.generated-->
  186 + select id,
  187 + username,
  188 + `password`,
  189 + server_id,
  190 + `server_name`,
  191 + virtual_host_id,
  192 + virtual_host_name,
  193 + real_name,
  194 + description,
  195 + gmt_create,
  196 + gmt_modified
  197 + from user_info
  198 + </select>
  199 +
135 <select id="selectUserExist" parameterType="java.lang.String" resultMap="BaseResultMap"> 200 <select id="selectUserExist" parameterType="java.lang.String" resultMap="BaseResultMap">
136 <!--@mbg.generated--> 201 <!--@mbg.generated-->
137 select 202 select