Commit 6681df08 by 陶光胜

Merge branch 'developer' of…

Merge branch 'developer' of http://115.159.76.241/base_platform_enterprise/gic-platform-auth into developer
parents 3d200240 fcc3879a
package com.gic.auth.dto;
import com.gic.enterprise.base.UserInfo;
import java.io.Serializable;
import java.util.Date;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.io.Serializable;
import java.util.Date;
import com.gic.enterprise.base.UserInfo;
/**
* @author guojx
......@@ -49,7 +50,7 @@ public class UserDTO implements UserInfo,Serializable{
/**
* 密码
*/
@NotBlank(message = "密码不能为空", groups = {SaveUserValid.class, EditUserValid.class})
@NotBlank(message = "密码不能为空", groups = {SaveUserValid.class})
private String password;
/**
......@@ -107,13 +108,15 @@ public class UserDTO implements UserInfo,Serializable{
/**
* 用户角色,可以多选,用英文逗号隔开
*/
@NotBlank(message = "用户角色不能为空", groups = {SaveUserValid.class, EditUserValid.class, UserQoValid.class})
private String userRoleIds;
/**
* 用户资源组授权,可以多选,用英文逗号隔开
*/
@NotBlank(message = "用户资源组不能为空", groups = {SaveUserValid.class, EditUserValid.class, UserQoValid.class})
private String userResourceIds;
/**
* 1:是编辑操作,并且没修改过密码 2:与1相反
*/
private Integer operPasswordType;
public Integer getUserId() {
return userId;
......@@ -242,4 +245,12 @@ public class UserDTO implements UserInfo,Serializable{
public void setUserResourceIds(String userResourceIds) {
this.userResourceIds = userResourceIds;
}
public Integer getOperPasswordType() {
return operPasswordType;
}
public void setOperPasswordType(Integer operPasswordType) {
this.operPasswordType = operPasswordType;
}
}
......@@ -77,4 +77,16 @@ public interface TabSysRoleMapper {
int deleteByRoleId(@Param("roleId") Integer roleId);
List<TabSysRole> listRoleNoPage(@Param("enterpriseId") Integer enterpriseId);
/**
* 查询数量根据名称
* @Title: countRepeatRoleName

* @Description:

 * @author guojuxing
* @param enterpriseId
* @param roleId
* @param roleName

* @return int


 */
int countRepeatRoleName(@Param("enterpriseId") Integer enterpriseId, @Param("roleId") Integer roleId, @Param("roleName") String roleName);
}
\ No newline at end of file
......@@ -61,9 +61,10 @@ public interface TabSysUserMapper {
* 手机号码查询个数
* @param phone
* @param userId
* @param enterpriseId
* @return
*/
int countByPhone(@Param("phone") String phone, @Param("userId") Integer userId);
int countByPhone(@Param("phone") String phone, @Param("userId") Integer userId, @Param("enterpriseId") Integer enterpriseId);
TabSysUser selectByEnterpriseId(@Param("enterpriseId") Integer enterpriseId);
......
......@@ -68,4 +68,16 @@ public interface RoleService {
* @return java.util.List<com.gic.auth.entity.TabSysRole>


 */
List<TabSysRole> listRole(Integer enterpriseId);
/**
* 权限名称是否重复
* @Title: isRepeatRoleName

* @Description:

 * @author guojuxing
* @param enterpriseId
* @param roleId
* @param roleName

* @return boolean


 */
boolean isRepeatRoleName(Integer enterpriseId, Integer roleId, String roleName);
}
......@@ -34,9 +34,10 @@ public interface UserService {
* 手机号码是否重复
* @param userId
* @param phone
* @param enterpriseId
* @return
*/
boolean isPhoneRepeat(Integer userId, String phone);
boolean isPhoneRepeat(Integer userId, String phone, Integer enterpriseId);
TabSysUser getUserByEnterpriseId(Integer enterpriseId);
......
......@@ -58,4 +58,13 @@ public class RoleServiceImpl implements RoleService{
public List<TabSysRole> listRole(Integer enterpriseId) {
return tabSysRoleMapper.listRoleNoPage(enterpriseId);
}
@Override
public boolean isRepeatRoleName(Integer enterpriseId, Integer roleId, String roleName) {
int count = tabSysRoleMapper.countRepeatRoleName(enterpriseId, roleId, roleName);
if (count > 0) {
return true;
}
return false;
}
}
......@@ -46,8 +46,8 @@ public class UserServiceImpl implements UserService {
}
@Override
public boolean isPhoneRepeat(Integer userId, String phone) {
int count = tabSysUserMapper.countByPhone(phone, userId);
public boolean isPhoneRepeat(Integer userId, String phone, Integer enterpriseId) {
int count = tabSysUserMapper.countByPhone(phone, userId, enterpriseId);
if (count > 0) {
return true;
}
......
......@@ -48,6 +48,11 @@ public class RoleApiServiceImpl implements RoleApiService{
dto.setCreateTime(new Date());
dto.setStatus(1);
//验证名称不能重复
if (roleService.isRepeatRoleName(dto.getEnterpriseId(), null, dto.getRoleName())) {
return ServiceResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "权限名称重复");
}
Integer roleId = roleService.save(dto);
//删除之前的角色菜单数据
......@@ -72,6 +77,11 @@ public class RoleApiServiceImpl implements RoleApiService{
return paramValid;
}
//验证名称不能重复
if (roleService.isRepeatRoleName(record.getEnterpriseId(), dto.getRoleId(), dto.getRoleName())) {
return ServiceResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "权限名称重复");
}
roleService.update(dto);
//删除之前的角色菜单数据
menuRoleService.deleteByRoleId(dto.getRoleId());
......
......@@ -56,10 +56,37 @@ public class UserApiServiceImpl implements UserApiService {
if (!paramResult.isSuccess()) {
return paramResult;
}
if (userService.isPhoneRepeat(null, userDTO.getPhoneNumber())) {
if (userService.isPhoneRepeat(null, userDTO.getPhoneNumber(), userDTO.getEnterpriseId())) {
return ServiceResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "手机号码不能重复");
}
//如果是普通管理员,则需要验证角色权限和资源权限
if (userDTO.getSuperAdmin().intValue() == 0) {
if (StringUtils.isBlank(userDTO.getUserRoleIds())) {
return ServiceResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "角色权限不能为空");
}
if (StringUtils.isBlank(userDTO.getUserResourceIds())) {
return ServiceResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "资源权限不能为空");
}
}
if (userDTO.getSuperAdmin() == null) {
//默认是普通管理员
userDTO.setSuperAdmin(0);
}
if (userDTO.getSuperAdmin().intValue() == 1) {
//超级官员
TabSysUser adminUser = userService.getUserByEnterpriseId(userDTO.getEnterpriseId());
if (adminUser != null) {
return ServiceResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "已存在超级管理员,重复创建");
}
}
if (userDTO.getPasswordType() == null) {
//默认自定义创建密码类型
userDTO.setPasswordType(2);
}
if (StringUtils.isBlank(userDTO.getPhoneAreaCode())) {
userDTO.setPhoneAreaCode("86");
}
......@@ -94,9 +121,18 @@ public class UserApiServiceImpl implements UserApiService {
if (tabUser == null) {
return ServiceResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "用户ID输入有误");
}
if (userService.isPhoneRepeat(userDTO.getUserId(), userDTO.getPhoneNumber())) {
if (userService.isPhoneRepeat(userDTO.getUserId(), userDTO.getPhoneNumber(), tabUser.getEnterpriseId())) {
return ServiceResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "手机号码不能重复");
}
if (userDTO.getSuperAdmin() != null && userDTO.getSuperAdmin().intValue() == 1) {
//超级官员
TabSysUser adminUser = userService.getUserByEnterpriseId(userDTO.getEnterpriseId());
if (adminUser != null && adminUser.getUserId().intValue() != tabUser.getUserId().intValue()) {
return ServiceResponse.failure(ErrorCode.PARAMETER_ERROR.getCode(), "已存在超级管理员,参数有误");
}
}
if (StringUtils.isBlank(userDTO.getPhoneAreaCode())) {
userDTO.setPhoneAreaCode("86");
}
......
......@@ -130,4 +130,15 @@
where status = 1
and enterprise_id = #{enterpriseId}
</select>
<select id="countRepeatRoleName" resultType="int">
select count(1) from tab_sys_role
where status = 1
<if test="roleId != null">
and role_id <![CDATA[ <> ]]> #{roleId}
</if>
and enterprise_id = #{enterpriseId}
and role_name = #{roleName}
</select>
</mapper>
\ No newline at end of file
......@@ -191,8 +191,9 @@
select count(1) from tab_sys_user
where status = 1
<if test="userId != null">
user_id <![CDATA[ <> ]]> #{userId}
and user_id <![CDATA[ <> ]]> #{userId}
</if>
and enterprise_id = #{enterpriseId}
and phone_number = #{phone}
</select>
......@@ -231,8 +232,8 @@
a.user_name userName,
a.phone_number phoneNumber,
a.phone_area_code phoneAreaCode,
(select GROUP_CONCAT(role_name separator '/') from tab_sys_role where role_id in (GROUP_CONCAT(b.role_id))) userRoleNames,
(select GROUP_CONCAT(d.resource_name separator '/') from tab_sys_resource d WHERE find_in_set( d.resource_Id , GROUP_CONCAT(c.resource_id)) ) userResourceNames
(select GROUP_CONCAT(role_name separator '/') from tab_sys_role where find_in_set( role_id , GROUP_CONCAT(b.role_id)) ) userRoleNames,
(select GROUP_CONCAT(d.resource_name separator '/') from tab_sys_resource d WHERE find_in_set( d.resource_id , GROUP_CONCAT(c.resource_id)) ) userResourceNames
from tab_sys_user a
left join tab_sys_user_role b on a.user_id = b.user_id
left join tab_sys_user_resource c on a.user_id = c.user_id
......@@ -251,6 +252,8 @@
</if>
GROUP BY a.user_id
order by a.create_time desc
</select>
......
......@@ -125,6 +125,7 @@
<if test="enterpriseId != null ">
and enterprise_id = #{enterpriseId}
</if>
limit 1
</select>
<!--List<Map<String,Integer>> countByResourceIds(List<Integer> resourceIds);-->
<select id="countByResourceIds" resultType="java.util.HashMap">
......@@ -136,6 +137,7 @@
#{item}
</foreach>
</if>
group by resource_id
</select>
......
......@@ -134,7 +134,7 @@
select
<include refid="Base_Column_List" />
from tab_sys_user_role
where role_id = #{userId}
where role_id = #{roleId}
and status = 1
</select>
</mapper>
\ No newline at end of file
......@@ -29,9 +29,15 @@ public class UserController {
@RequestMapping("/save-or-update-user")
public RestResponse editUser(@Validated({ UserDTO.UserQoValid.class }) UserDTO userDTO) {
Integer operationPassword = userDTO.getOperPasswordType();
userDTO.setEnterpriseId(UserDetailUtils.getUserDetail().getEnterpriseId());
String password = UserPasswordUtils.validPassword(userDTO.getPasswordType(), userDTO.getPassword());
userDTO.setPassword(UserPasswordUtils.getEncryptPassword(password));
if (operationPassword != null && operationPassword.intValue() == 1) {
//如果是1,则不用验证密码
} else {
String password = UserPasswordUtils.validPassword(userDTO.getPasswordType(), userDTO.getPassword());
userDTO.setPassword(UserPasswordUtils.getEncryptPassword(password));
}
ServiceResponse userResult;
//普通用户
userDTO.setSuperAdmin(0);
......
......@@ -3,9 +3,9 @@ package com.gic.auth.web.utils;
import org.apache.commons.lang3.StringUtils;
import com.gic.auth.constant.UserConstants;
import com.gic.auth.exception.AuthException;
import com.gic.commons.util.Md5Util;
import com.gic.enterprise.error.ErrorCode;
import com.gic.enterprise.exception.CommonException;
import com.gic.enterprise.utils.CreateRandomUtils;
/**
* 用户密码生成
......@@ -54,7 +54,7 @@ public class UserPasswordUtils {
if (StringUtils.isNotBlank(password)) {
return password;
} else {
throw new CommonException(ErrorCode.PARAMETER_ERROR.getCode(), "密码不能为空");
throw new AuthException(ErrorCode.PARAMETER_ERROR.getCode(), "密码不能为空");
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment