| @@ -1,6 +1,7 @@ | |||||
| package com.simple.controller; | package com.simple.controller; | ||||
| import com.github.pagehelper.PageInfo; | import com.github.pagehelper.PageInfo; | ||||
| import com.simple.common.ErrorCode; | |||||
| import com.simple.common.ResultData; | import com.simple.common.ResultData; | ||||
| import com.simple.domain.po.*; | import com.simple.domain.po.*; | ||||
| import com.simple.service.*; | import com.simple.service.*; | ||||
| @@ -78,8 +79,13 @@ public class MallUserInfoController extends BaseController { | |||||
| @ApiOperation(value = "创建用户接口", response = String.class) | @ApiOperation(value = "创建用户接口", response = String.class) | ||||
| @PostMapping("add") | @PostMapping("add") | ||||
| public ResultData createUser(@RequestBody MallUserInfo userInfo) { | public ResultData createUser(@RequestBody MallUserInfo userInfo) { | ||||
| Assert.notNull(userInfo.getUsername(), "用户名不能为空"); | |||||
| Assert.isTrue(checkUnique(userInfo.getUsername(), 0), "重复的用户名"); | |||||
| if(checkUniqueName(userInfo.getUsername(), null)){ | |||||
| return new ResultData(ErrorCode.USER_NAME_IS_FOUND,"用户名已存在"); | |||||
| } | |||||
| if(checkUniquePhone(userInfo.getPhone(), null)){ | |||||
| return new ResultData(ErrorCode.USER_PHONE_IS_FOUND,"手机号已存在"); | |||||
| } | |||||
| Assert.notNull(userInfo.getPassword(), "密码不能为空"); | Assert.notNull(userInfo.getPassword(), "密码不能为空"); | ||||
| PasswordHelper passwordHelper = new PasswordHelper(); | PasswordHelper passwordHelper = new PasswordHelper(); | ||||
| passwordHelper.encryptPassword(userInfo); | passwordHelper.encryptPassword(userInfo); | ||||
| @@ -97,8 +103,13 @@ public class MallUserInfoController extends BaseController { | |||||
| @ApiOperation(value = "修改用户接口", response = String.class) | @ApiOperation(value = "修改用户接口", response = String.class) | ||||
| @PostMapping("update") | @PostMapping("update") | ||||
| public ResultData updateUser(@RequestBody MallUserInfo userInfo) { | public ResultData updateUser(@RequestBody MallUserInfo userInfo) { | ||||
| Assert.notNull(userInfo.getUsername(), "用户名不能为空"); | |||||
| Assert.isTrue(checkUnique(userInfo.getUsername(), 1), "重复的用户名"); | |||||
| //Assert.notNull(userInfo.getUsername(), "用户名不能为空"); | |||||
| if(checkUniqueName(userInfo.getUsername(), userInfo.getId())){ | |||||
| return new ResultData(ErrorCode.USER_NAME_IS_FOUND,"用户名已存在"); | |||||
| } | |||||
| if(checkUniquePhone(userInfo.getPhone(), userInfo.getId())){ | |||||
| return new ResultData(ErrorCode.USER_PHONE_IS_FOUND,"手机号已存在"); | |||||
| } | |||||
| // Assert.notNull(userInfo.getPassword(), "密码不能为空"); | // Assert.notNull(userInfo.getPassword(), "密码不能为空"); | ||||
| // PasswordHelper passwordHelper = new PasswordHelper(); | // PasswordHelper passwordHelper = new PasswordHelper(); | ||||
| // passwordHelper.encryptPassword(userInfo); | // passwordHelper.encryptPassword(userInfo); | ||||
| @@ -155,18 +166,12 @@ public class MallUserInfoController extends BaseController { | |||||
| return new ResultData(); | return new ResultData(); | ||||
| } | } | ||||
| private boolean checkUnique(String username, Integer type) { | |||||
| if (type == 0) { | |||||
| if (userInfoService.cntByUserName(username) > 0) { | |||||
| return false; | |||||
| } | |||||
| } | |||||
| if (type == 1) { | |||||
| if (userInfoService.cntByUserName(username) > 1) { | |||||
| return false; | |||||
| } | |||||
| } | |||||
| return true; | |||||
| private boolean checkUniqueName(String username, Long id) { | |||||
| return userInfoService.cntByUserName(username,id); | |||||
| } | |||||
| private boolean checkUniquePhone(String phone, Long id) { | |||||
| return userInfoService.cntByUserPhone(phone,id); | |||||
| } | } | ||||
| @@ -56,6 +56,8 @@ public enum ErrorCode{ | |||||
| BUSER_NOT_IN_APP(2005, "用户不是此app用户"), | BUSER_NOT_IN_APP(2005, "用户不是此app用户"), | ||||
| KAPCHA_NOT_VALID(2006, "验证码已失效"), | KAPCHA_NOT_VALID(2006, "验证码已失效"), | ||||
| KAPCHA_NOT_EQUAL(2007, "验证码不正确"), | KAPCHA_NOT_EQUAL(2007, "验证码不正确"), | ||||
| USER_NAME_IS_FOUND(2008,"用户名已存在"), | |||||
| USER_PHONE_IS_FOUND(2009,"手机号已存在"), | |||||
| /** | /** | ||||
| * 商场/商户 | * 商场/商户 | ||||
| @@ -67,7 +67,10 @@ public class MallUserInfo implements Serializable { | |||||
| private Integer isAdmin; | private Integer isAdmin; | ||||
| @io.swagger.annotations.ApiModelProperty(value="昵称",name="nickName") | @io.swagger.annotations.ApiModelProperty(value="昵称",name="nickName") | ||||
| private String nickName; | private String nickName; | ||||
| @io.swagger.annotations.ApiModelProperty(value="手机",name="phone") | |||||
| private String phone; | |||||
| @Transient | @Transient | ||||
| private Long roleId; | private Long roleId; | ||||
| @@ -187,7 +190,15 @@ public class MallUserInfo implements Serializable { | |||||
| } | } | ||||
| public void setCaptcha(String captcha) { | public void setCaptcha(String captcha) { | ||||
| this.captcha = captcha; | |||||
| this.captcha = captcha; | |||||
| } | |||||
| public String getPhone() { | |||||
| return phone; | |||||
| } | |||||
| public void setPhone(String phone) { | |||||
| this.phone = phone; | |||||
| } | } | ||||
| public static enum Field | public static enum Field | ||||
| @@ -5,6 +5,7 @@ import com.simple.domain.po.MallUserInfo; | |||||
| import org.apache.ibatis.annotations.Param; | import org.apache.ibatis.annotations.Param; | ||||
| import java.util.List; | import java.util.List; | ||||
| import java.util.Map; | |||||
| public interface MallUserInfoMapper extends CommonMapper<MallUserInfo, String> { | public interface MallUserInfoMapper extends CommonMapper<MallUserInfo, String> { | ||||
| @@ -14,6 +15,8 @@ public interface MallUserInfoMapper extends CommonMapper<MallUserInfo, String> { | |||||
| Integer hasButtonPermission(@Param("userId") Long userId, @Param("permission") String permission); | Integer hasButtonPermission(@Param("userId") Long userId, @Param("permission") String permission); | ||||
| long cntByUserName(Map<String,Object> params); | |||||
| } | } | ||||
| @@ -67,7 +67,10 @@ public interface MallUserInfoService { | |||||
| * @return 是否有权限(true: 有| false: 没有) | * @return 是否有权限(true: 有| false: 没有) | ||||
| */ | */ | ||||
| boolean hasButtonPermission(Long userId, String permission); | boolean hasButtonPermission(Long userId, String permission); | ||||
| boolean cntByUserName(String username, Long id); | |||||
| boolean cntByUserPhone(String phone, Long id); | |||||
| } | } | ||||
| @@ -12,6 +12,9 @@ import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.stereotype.Service; | import org.springframework.stereotype.Service; | ||||
| import org.springframework.transaction.annotation.Transactional; | import org.springframework.transaction.annotation.Transactional; | ||||
| import java.util.HashMap; | |||||
| import java.util.Map; | |||||
| @Service | @Service | ||||
| public class MallUserInfoServiceImpl implements MallUserInfoService { | public class MallUserInfoServiceImpl implements MallUserInfoService { | ||||
| @@ -79,7 +82,21 @@ public class MallUserInfoServiceImpl implements MallUserInfoService { | |||||
| public boolean hasButtonPermission(Long userId, String permission) { | public boolean hasButtonPermission(Long userId, String permission) { | ||||
| return mallUserInfoMapper.hasButtonPermission(userId, permission) == null ? false : true; | return mallUserInfoMapper.hasButtonPermission(userId, permission) == null ? false : true; | ||||
| } | } | ||||
| @Override | |||||
| public boolean cntByUserName(String username, Long id) { | |||||
| Map<String,Object> params=new HashMap<>(); | |||||
| params.put("username",username); | |||||
| params.put("id",id); | |||||
| return mallUserInfoMapper.cntByUserName(params)>0?true:false; | |||||
| } | |||||
| @Override | |||||
| public boolean cntByUserPhone(String phone, Long id) { | |||||
| Map<String,Object> params=new HashMap<>(); | |||||
| params.put("phone",phone); | |||||
| params.put("id",id); | |||||
| return mallUserInfoMapper.cntByUserName(params)>0?true:false; | |||||
| } | |||||
| } | } | ||||
| @@ -12,10 +12,12 @@ | |||||
| <result column="status" jdbcType="INTEGER" property="status" /> | <result column="status" jdbcType="INTEGER" property="status" /> | ||||
| <result column="is_admin" jdbcType="INTEGER" property="isAdmin" /> | <result column="is_admin" jdbcType="INTEGER" property="isAdmin" /> | ||||
| <result column="nick_name" jdbcType="VARCHAR" property="nickName" /> | <result column="nick_name" jdbcType="VARCHAR" property="nickName" /> | ||||
| <result column="phone" jdbcType="VARCHAR" property="phone" /> | |||||
| </resultMap> | </resultMap> | ||||
| <sql id="allColumns"> | <sql id="allColumns"> | ||||
| `id`,`tenant_id`,`username`,`name`,`password`,`create_time`,`last_login_time`,`status`,`is_admin`,`nick_name` | |||||
| `id`,`tenant_id`,`username`,`name`,`password`,`create_time`,`last_login_time`,`status`,`is_admin`,`nick_name`,`phone` | |||||
| </sql> | </sql> | ||||
| <sql id="dynamicWhereConditions"> | <sql id="dynamicWhereConditions"> | ||||
| @@ -69,7 +71,10 @@ | |||||
| <if test=" null != isAdmin "> | <if test=" null != isAdmin "> | ||||
| and `is_admin` = #{isAdmin} | and `is_admin` = #{isAdmin} | ||||
| </if> | |||||
| </if> | |||||
| <if test=" null != phone "> | |||||
| and `phone` = #{phone} | |||||
| </if> | |||||
| <if test=" null != ids "> | <if test=" null != ids "> | ||||
| and id in | and id in | ||||
| @@ -98,5 +103,17 @@ | |||||
| AND p.permission = #{permission} | AND p.permission = #{permission} | ||||
| </select> | </select> | ||||
| <select id="cntByUserName" resultType="java.lang.Long"> | |||||
| select count(*) from mall_user_info where 1=1 | |||||
| <if test=" null != username "> | |||||
| and username=#{username} | |||||
| </if> | |||||
| <if test=" null != phone "> | |||||
| and `phone` = #{phone} | |||||
| </if> | |||||
| <if test=" null != id "> | |||||
| and `id` = #{id} | |||||
| </if> | |||||
| </select> | |||||
| </mapper> | </mapper> | ||||