作者 王勇

为userinfo表添加了字段

... ... @@ -3,10 +3,7 @@ package com.sunyo.wlpt.message.bus.service.controller;
import com.sunyo.wlpt.message.bus.service.domain.UserInfo;
import com.sunyo.wlpt.message.bus.service.response.ResultJson;
import com.sunyo.wlpt.message.bus.service.service.UserInfoService;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
... ... @@ -35,4 +32,47 @@ public class UserInfoController {
? new ResultJson<>("200", "查询用户信息列表,成功", userInfos)
: new ResultJson<>("500", "查询用户信息列表,失败");
}
/**
* 增加用户
*
* @param userInfo 用户信息
* @return {@link ResultJson}
*/
@PostMapping("/insert")
public ResultJson insertUserByEntity(UserInfo userInfo)
{
return userInfoService.insertSelective(userInfo);
}
/**
* @param description 描述
* @param username 用户名称
* @param password 密码
* @return {@link ResultJson}
*/
@PostMapping("/insertByParam")
public ResultJson insertUserByParam(@RequestParam(value = "description", required = false) String description,
String username, String password)
{
// 接收参数
UserInfo userInfo = UserInfo.builder().username(username)
.password(password)
.description(description)
.build();
return userInfoService.insertSelective(userInfo);
}
/**
* 编辑用户信息
*
* @param userInfo {@link UserInfo}
* @return
*/
@PostMapping("/update")
public ResultJson updateUser(UserInfo userInfo)
{
return userInfoService.updateByPrimaryKeySelective(userInfo);
}
}
... ...
package com.sunyo.wlpt.message.bus.service.domain;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
... ... @@ -13,15 +11,15 @@ import java.util.Date;
/**
* @author 子诚
* Description:MQ账户信息表
* 时间:2020/7/23 15:59
* 时间:2020/8/10 17:44
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class UserInfo implements Serializable {
private static final long serialVersionUID = 8510385519421924997L;
/**
* 用户的ID
*/
... ... @@ -38,6 +36,31 @@ public class UserInfo implements Serializable {
private String password;
/**
* 所属服务器id
*/
private String serverId;
/**
* 所属服务器名称
*/
private String serverName;
/**
* 对应虚拟主机的id
*/
private String virtualHostId;
/**
* 对应虚拟主机的名称
*/
private String virtualHostName;
/**
* 用户的姓名(备用字段)
*/
private String realName;
/**
* 用户相关描述
*/
private String description;
... ...
package com.sunyo.wlpt.message.bus.service.mapper;
import com.sunyo.wlpt.message.bus.service.domain.UserInfo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;import org.apache.ibatis.annotations.Param;import java.util.List;
/**
* @author 子诚
* Description:
* 时间:2020/7/23 15:59
* 时间:2020/8/10 17:44
*/
@Mapper
public interface UserInfoMapper {
... ... @@ -46,14 +43,6 @@ public interface UserInfoMapper {
UserInfo selectByPrimaryKey(String id);
/**
* 查询,根据用户名称
*
* @param username 用户登录名称
* @return {@link UserInfo}
*/
UserInfo selectByUsername(String username);
/**
* update record selective
*
* @param record the updated record
... ... @@ -70,6 +59,14 @@ public interface UserInfoMapper {
int updateByPrimaryKey(UserInfo record);
/**
* 查询,根据用户名称
*
* @param username 用户登录名称
* @return {@link UserInfo}
*/
UserInfo selectByUsername(String username);
/**
* 仅,查询用户列表
*
* @return 用户信息集合
... ...
package com.sunyo.wlpt.message.bus.service.service;
import com.sunyo.wlpt.message.bus.service.domain.UserInfo;
import com.sunyo.wlpt.message.bus.service.response.ResultJson;
import java.util.List;
... ... @@ -33,7 +34,7 @@ public interface UserInfoService {
* @param record the record
* @return insert count
*/
int insertSelective(UserInfo record);
ResultJson insertSelective(UserInfo record);
/**
* 查询,根据主键
... ... @@ -57,7 +58,7 @@ public interface UserInfoService {
* @param record the updated record
* @return update count
*/
int updateByPrimaryKeySelective(UserInfo record);
ResultJson updateByPrimaryKeySelective(UserInfo record);
/**
* 更新,根据主键
... ... @@ -87,3 +88,4 @@ public interface UserInfoService {
... ...
... ... @@ -2,7 +2,11 @@ package com.sunyo.wlpt.message.bus.service.service.impl;
import com.sunyo.wlpt.message.bus.service.domain.UserInfo;
import com.sunyo.wlpt.message.bus.service.mapper.UserInfoMapper;
import com.sunyo.wlpt.message.bus.service.response.ResultJson;
import com.sunyo.wlpt.message.bus.service.service.UserInfoService;
import com.sunyo.wlpt.message.bus.service.utils.IdUtils;
import io.netty.util.internal.StringUtil;
import org.springframework.util.DigestUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
... ... @@ -32,11 +36,22 @@ public class UserInfoServiceImpl implements UserInfoService {
}
@Override
public int insertSelective(UserInfo record)
public ResultJson insertSelective(UserInfo userInfo)
{
return userInfoMapper.insertSelective(record);
ResultJson validateResult = validateUser(userInfo);
if (!"200".equals(validateUser(userInfo).getCode())) {
return validateResult;
}
if (StringUtil.isNullOrEmpty(userInfo.getId())) {
userInfo.setId(IdUtils.generateId());
}
userInfo.setPassword(DigestUtils.md5DigestAsHex(userInfo.getPassword().getBytes()));
return userInfoMapper.insertSelective(userInfo) > 0
? new ResultJson<>("200", "添加用户信息,成功")
: new ResultJson<>("500", "添加用户信息,失败");
}
@Override
public UserInfo selectByPrimaryKey(String id)
{
... ... @@ -50,9 +65,39 @@ public class UserInfoServiceImpl implements UserInfoService {
}
@Override
public int updateByPrimaryKeySelective(UserInfo record)
public ResultJson updateByPrimaryKeySelective(UserInfo userInfo)
{
return userInfoMapper.updateByPrimaryKeySelective(record);
if (StringUtil.isNullOrEmpty(userInfo.getId())) {
return new ResultJson<>("400", "该用户不存在");
}
return userInfoMapper.updateByPrimaryKeySelective(userInfo) > 0
? new ResultJson<>("200", "修改用户信息,成功")
: new ResultJson<>("500", "修改用户信息,失败");
}
/**
* 校验用户名称是否已经存在
*/
public ResultJson validateUser(UserInfo userInfo)
{
if (StringUtil.isNullOrEmpty(userInfo.getUsername()) || StringUtil.isNullOrEmpty(userInfo.getPassword())) {
return new ResultJson<>("400", "用户名称和密码,不能为空");
}
String userId = userInfo.getId();
if (!StringUtil.isNullOrEmpty(userId)) {
UserInfo oldUserInfo = userInfoMapper.selectByPrimaryKey(userId);
if (!userInfo.getUsername().equals(oldUserInfo.getUsername())) {
return new ResultJson<>("400", "用户名称,不可修改");
}
return ResultJson.success("通过校验");
} else {
List<UserInfo> userInfos = userInfoMapper.selectUserExist(userInfo.getUsername());
return userInfos.size() > 0
? new ResultJson<>("400", "该用户,已存在")
: ResultJson.success("通过校验");
}
}
@Override
... ... @@ -68,7 +113,7 @@ public class UserInfoServiceImpl implements UserInfoService {
}
@Override
public List<UserInfo> selectUserExist(String username)
public List<UserInfo> selectUserExist(String username)
{
return userInfoMapper.selectUserExist(username);
}
... ... @@ -77,3 +122,4 @@ public class UserInfoServiceImpl implements UserInfoService {
... ...
... ... @@ -8,13 +8,19 @@
<id column="id" jdbcType="VARCHAR" property="id"/>
<result column="username" jdbcType="VARCHAR" property="username"/>
<result column="password" jdbcType="VARCHAR" property="password"/>
<result column="server_id" jdbcType="VARCHAR" property="serverId"/>
<result column="server_name" jdbcType="VARCHAR" property="serverName"/>
<result column="virtual_host_id" jdbcType="VARCHAR" property="virtualHostId"/>
<result column="virtual_host_name" jdbcType="VARCHAR" property="virtualHostName"/>
<result column="real_name" jdbcType="VARCHAR" property="realName"/>
<result column="description" jdbcType="VARCHAR" property="description"/>
<result column="gmt_create" jdbcType="TIMESTAMP" property="gmtCreate"/>
<result column="gmt_modified" jdbcType="TIMESTAMP" property="gmtModified"/>
</resultMap>
<sql id="Base_Column_List">
<!--@mbg.generated-->
id, username, `password`, description, gmt_create, gmt_modified
id, username, `password`, server_id, `server_name`, virtual_host_id, virtual_host_name,
real_name, description, gmt_create, gmt_modified
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
<!--@mbg.generated-->
... ... @@ -23,25 +29,6 @@
from user_info
where id = #{id,jdbcType=VARCHAR}
</select>
<select id="selectByUsername" parameterType="java.lang.String" resultMap="BaseResultMap">
<!--@mbg.generated-->
select
<include refid="Base_Column_List"/>
from user_info
where username = #{username,jdbcType=VARCHAR}
</select>
<select id="getUserInfoList" resultMap="BaseResultMap">
<!--@mbg.generated-->
select id,
username,
description,
gmt_create,
gmt_modified
from user_info
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.String">
<!--@mbg.generated-->
delete
... ... @@ -51,9 +38,13 @@
<insert id="insert" parameterType="com.sunyo.wlpt.message.bus.service.domain.UserInfo">
<!--@mbg.generated-->
insert into user_info (id, username, `password`,
description, gmt_create, gmt_modified)
server_id, `server_name`, virtual_host_id,
virtual_host_name, real_name, description,
gmt_create, gmt_modified)
values (#{id,jdbcType=VARCHAR}, #{username,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR},
#{description,jdbcType=VARCHAR}, #{gmtCreate,jdbcType=TIMESTAMP}, #{gmtModified,jdbcType=TIMESTAMP})
#{serverId,jdbcType=VARCHAR}, #{serverName,jdbcType=VARCHAR}, #{virtualHostId,jdbcType=VARCHAR},
#{virtualHostName,jdbcType=VARCHAR}, #{realName,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR},
#{gmtCreate,jdbcType=TIMESTAMP}, #{gmtModified,jdbcType=TIMESTAMP})
</insert>
<insert id="insertSelective" parameterType="com.sunyo.wlpt.message.bus.service.domain.UserInfo">
<!--@mbg.generated-->
... ... @@ -68,6 +59,21 @@
<if test="password != null">
`password`,
</if>
<if test="serverId != null">
server_id,
</if>
<if test="serverName != null">
`server_name`,
</if>
<if test="virtualHostId != null">
virtual_host_id,
</if>
<if test="virtualHostName != null">
virtual_host_name,
</if>
<if test="realName != null">
real_name,
</if>
<if test="description != null">
description,
</if>
... ... @@ -88,6 +94,21 @@
<if test="password != null">
#{password,jdbcType=VARCHAR},
</if>
<if test="serverId != null">
#{serverId,jdbcType=VARCHAR},
</if>
<if test="serverName != null">
#{serverName,jdbcType=VARCHAR},
</if>
<if test="virtualHostId != null">
#{virtualHostId,jdbcType=VARCHAR},
</if>
<if test="virtualHostName != null">
#{virtualHostName,jdbcType=VARCHAR},
</if>
<if test="realName != null">
#{realName,jdbcType=VARCHAR},
</if>
<if test="description != null">
#{description,jdbcType=VARCHAR},
</if>
... ... @@ -109,6 +130,21 @@
<if test="password != null">
`password` = #{password,jdbcType=VARCHAR},
</if>
<if test="serverId != null">
server_id = #{serverId,jdbcType=VARCHAR},
</if>
<if test="serverName != null">
`server_name` = #{serverName,jdbcType=VARCHAR},
</if>
<if test="virtualHostId != null">
virtual_host_id = #{virtualHostId,jdbcType=VARCHAR},
</if>
<if test="virtualHostName != null">
virtual_host_name = #{virtualHostName,jdbcType=VARCHAR},
</if>
<if test="realName != null">
real_name = #{realName,jdbcType=VARCHAR},
</if>
<if test="description != null">
description = #{description,jdbcType=VARCHAR},
</if>
... ... @@ -124,14 +160,43 @@
<update id="updateByPrimaryKey" parameterType="com.sunyo.wlpt.message.bus.service.domain.UserInfo">
<!--@mbg.generated-->
update user_info
set username = #{username,jdbcType=VARCHAR},
`password` = #{password,jdbcType=VARCHAR},
description = #{description,jdbcType=VARCHAR},
gmt_create = #{gmtCreate,jdbcType=TIMESTAMP},
gmt_modified = #{gmtModified,jdbcType=TIMESTAMP}
set username = #{username,jdbcType=VARCHAR},
`password` = #{password,jdbcType=VARCHAR},
server_id = #{serverId,jdbcType=VARCHAR},
`server_name` = #{serverName,jdbcType=VARCHAR},
virtual_host_id = #{virtualHostId,jdbcType=VARCHAR},
virtual_host_name = #{virtualHostName,jdbcType=VARCHAR},
real_name = #{realName,jdbcType=VARCHAR},
description = #{description,jdbcType=VARCHAR},
gmt_create = #{gmtCreate,jdbcType=TIMESTAMP},
gmt_modified = #{gmtModified,jdbcType=TIMESTAMP}
where id = #{id,jdbcType=VARCHAR}
</update>
<select id="selectByUsername" parameterType="java.lang.String" resultMap="BaseResultMap">
<!--@mbg.generated-->
select
<include refid="Base_Column_List"/>
from user_info
where username = #{username,jdbcType=VARCHAR}
</select>
<select id="getUserInfoList" resultMap="BaseResultMap">
<!--@mbg.generated-->
select id,
username,
`password`,
server_id,
`server_name`,
virtual_host_id,
virtual_host_name,
real_name,
description,
gmt_create,
gmt_modified
from user_info
</select>
<select id="selectUserExist" parameterType="java.lang.String" resultMap="BaseResultMap">
<!--@mbg.generated-->
select
... ...