micro-fast-IIDWC 用户角色管理
This commit is contained in:
@@ -2,65 +2,42 @@ package com.micro.fast.upms.controller;
|
||||
|
||||
import com.micro.fast.boot.starter.common.response.BaseConst;
|
||||
import com.micro.fast.boot.starter.common.response.ServerResponse;
|
||||
import com.micro.fast.upms.pojo.UpmsUserRole;
|
||||
import com.micro.fast.upms.service.UpmsUserRoleService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.hibernate.validator.constraints.NotBlank;
|
||||
import org.hibernate.validator.constraints.NotEmpty;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.BindException;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author lsy
|
||||
*/
|
||||
@Api("upmsUserRole")
|
||||
@Api("用户和角色关系维护")
|
||||
@RestController
|
||||
@RequestMapping("/upmsUserRole")
|
||||
public class UpmsUserRoleController {
|
||||
|
||||
@Autowired
|
||||
private UpmsUserRoleService<UpmsUserRole,Integer> upmsUserRoleService;
|
||||
private UpmsUserRoleService upmsUserRoleService;
|
||||
|
||||
@ApiOperation("添加信息")
|
||||
@PostMapping
|
||||
public ServerResponse addUpmsUserRole(@Valid UpmsUserRole upmsUserRole) throws BindException {
|
||||
return upmsUserRoleService.add(upmsUserRole);
|
||||
|
||||
@ApiOperation("用户添加角色")
|
||||
@PostMapping("/userAddRoles")
|
||||
public ServerResponse userAddRoles(@RequestParam("userId") @NotNull(message = BaseConst.BASEMSG_PREFIX+"请传入用户的id") Integer userId,
|
||||
@RequestParam("roleIds")
|
||||
@NotEmpty(message = BaseConst.BASEMSG_PREFIX+"请传入的角色的id") ArrayList<Integer> roleIds){
|
||||
return upmsUserRoleService.batchInsert(userId,roleIds);
|
||||
}
|
||||
|
||||
@ApiOperation("根据id查询详细信息")
|
||||
@GetMapping("/{id}")
|
||||
public ServerResponse getUpmsUserRoleById(
|
||||
@PathVariable(value = "id") @NotBlank(message = BaseConst.BASEMSG_PREFIX+"请传入id") String id){
|
||||
return upmsUserRoleService.getById(Integer.valueOf(id));
|
||||
}
|
||||
|
||||
@ApiOperation("根据条件分页查询")
|
||||
@GetMapping
|
||||
public ServerResponse getUpmsUserRoleByCondition(UpmsUserRole upmsUserRole,
|
||||
@RequestParam(defaultValue = "1",required = false) int pageNum,
|
||||
@RequestParam(defaultValue = "10",required = false)int pageSize,
|
||||
@RequestParam(required = false) String orderBy){
|
||||
return upmsUserRoleService.getByCondition(upmsUserRole,pageNum,pageSize,orderBy);
|
||||
}
|
||||
|
||||
@ApiOperation("修改信息")
|
||||
@PutMapping("/{id}")
|
||||
public ServerResponse updateUpmsUserRole(UpmsUserRole upmsUserRole,
|
||||
@NotBlank(message = BaseConst.BASEMSG_PREFIX+"请传入id") String id){
|
||||
upmsUserRole.setId(Integer.valueOf(id));
|
||||
return upmsUserRoleService.update(upmsUserRole);
|
||||
}
|
||||
|
||||
@ApiOperation("根据id删除,传入数组")
|
||||
@DeleteMapping
|
||||
public ServerResponse deleteUpmsUserRole(@NotEmpty(message = BaseConst.BASEMSG_PREFIX+"请传入ids") @RequestParam("ids") ArrayList<Integer> ids){
|
||||
return upmsUserRoleService.deleteByIds(ids);
|
||||
@ApiOperation("用户删除角色")
|
||||
@DeleteMapping("/userDeleteRoles")
|
||||
public ServerResponse userDeleteRoles(@RequestParam("userId") @NotNull(message = BaseConst.BASEMSG_PREFIX+"请传入用户的id") Integer userId,
|
||||
@RequestParam("roleIds")
|
||||
@NotEmpty(message = BaseConst.BASEMSG_PREFIX+"请传入的角色的id") ArrayList<Integer> roleIds){
|
||||
return upmsUserRoleService.batchDelete(userId,roleIds);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,5 +14,11 @@ public interface UpmsUserOrganizationMapper {
|
||||
*/
|
||||
int batchInsertOneUserWithManyOrg(@Param("userId") Integer userId, @Param("orgIds") List<Integer> orgIds);
|
||||
|
||||
/**
|
||||
* 批量删除一个用户和多个组织的关系
|
||||
* @param userId
|
||||
* @param orgs
|
||||
* @return
|
||||
*/
|
||||
int batchDeleteByUserIdOrganizationId(@Param("userId")Integer userId,@Param("orgIds")List<Integer> orgs);
|
||||
}
|
||||
@@ -1,18 +1,24 @@
|
||||
package com.micro.fast.upms.dao;
|
||||
|
||||
import com.micro.fast.common.dao.SsmMapper;
|
||||
import com.micro.fast.upms.pojo.UpmsUserRole;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
public interface UpmsUserRoleMapper extends SsmMapper<UpmsUserRole,Integer> {
|
||||
int deleteByPrimaryKey(Integer id);
|
||||
import java.util.List;
|
||||
|
||||
int insert(UpmsUserRole record);
|
||||
public interface UpmsUserRoleMapper {
|
||||
|
||||
int insertSelective(UpmsUserRole record);
|
||||
/**
|
||||
* 批量建立用户和角色的关系
|
||||
* @param userId 用户的id
|
||||
* @param roleIds 角色的id集合
|
||||
* @return
|
||||
*/
|
||||
int batchInsert(@Param("userId") Integer userId,@Param("roleIds") List<Integer> roleIds);
|
||||
|
||||
UpmsUserRole selectByPrimaryKey(Integer userRoleId);
|
||||
|
||||
int updateByPrimaryKeySelective(UpmsUserRole record);
|
||||
|
||||
int updateByPrimaryKey(UpmsUserRole record);
|
||||
/**
|
||||
* 批量删除用户和角色的关系
|
||||
* @param userId 用户的id
|
||||
* @param roleIds 角色的id集合
|
||||
* @return
|
||||
*/
|
||||
int batchDelete(@Param("userId") Integer userId,@Param("roleIds") List<Integer> roleIds);
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.micro.fast.upms.service;
|
||||
|
||||
import com.micro.fast.common.service.SsmService;
|
||||
|
||||
/**
|
||||
* @author lsy
|
||||
*/
|
||||
|
||||
@@ -7,6 +7,11 @@ import com.micro.fast.common.service.SsmService;
|
||||
* @author lsy
|
||||
*/
|
||||
public interface UpmsRoleService<T,ID> extends SsmService<T,ID>{
|
||||
/**
|
||||
* 查询用户已拥有的角色
|
||||
* @param useId
|
||||
* @return
|
||||
*/
|
||||
ServerResponse getRolesByUserId(Integer useId);
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,10 +1,27 @@
|
||||
package com.micro.fast.upms.service;
|
||||
|
||||
import com.micro.fast.common.service.SsmService;
|
||||
import com.micro.fast.boot.starter.common.response.ServerResponse;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author lsy
|
||||
*/
|
||||
public interface UpmsUserRoleService<T,ID> extends SsmService<T,ID>{
|
||||
public interface UpmsUserRoleService{
|
||||
|
||||
/**
|
||||
* 批量建立用户和角色的关系
|
||||
* @param userId 用户id
|
||||
* @param roleIds 角色id的集合
|
||||
* @return
|
||||
*/
|
||||
ServerResponse batchInsert(Integer userId, List<Integer> roleIds);
|
||||
|
||||
/**
|
||||
* 批量解除用户和角色的关系
|
||||
* @param userId 用户id
|
||||
* @param roleIds 角色id的集合
|
||||
* @return
|
||||
*/
|
||||
ServerResponse batchDelete(Integer userId, List<Integer> roleIds);
|
||||
}
|
||||
+32
-7
@@ -1,28 +1,53 @@
|
||||
package com.micro.fast.upms.service.impl;
|
||||
|
||||
import com.micro.fast.boot.starter.common.response.ServerResponse;
|
||||
import com.micro.fast.common.service.impl.SsmServiceImpl;
|
||||
import com.micro.fast.upms.dao.UpmsUserMapper;
|
||||
import com.micro.fast.upms.dao.UpmsUserRoleMapper;
|
||||
import com.micro.fast.upms.pojo.UpmsUser;
|
||||
import com.micro.fast.upms.pojo.UpmsUserRole;
|
||||
import com.micro.fast.upms.service.UpmsUserRoleService;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author lsy
|
||||
*/
|
||||
@Service
|
||||
public class UpmsUserRoleServiceImpl extends SsmServiceImpl<UpmsUserRole,Integer,UpmsUserRoleMapper>
|
||||
implements UpmsUserRoleService<UpmsUserRole,Integer>,InitializingBean {
|
||||
public class UpmsUserRoleServiceImpl implements UpmsUserRoleService{
|
||||
|
||||
@Autowired
|
||||
private UpmsUserRoleMapper mapper;
|
||||
|
||||
/**
|
||||
* 在这个bean初始化完成后覆盖父类的mapper
|
||||
*/
|
||||
@Autowired
|
||||
private UpmsUserMapper upmsUserMapper;
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
super.setMapper(this.mapper);
|
||||
public ServerResponse batchInsert(Integer userId, List<Integer> roleIds) {
|
||||
UpmsUser upmsUser = upmsUserMapper.selectByPrimaryKey(userId);
|
||||
if (upmsUser == null){
|
||||
return ServerResponse.errorMsg("用户不存在");
|
||||
}
|
||||
int i = mapper.batchInsert(userId, roleIds);
|
||||
if (i == roleIds.size()){
|
||||
return ServerResponse.errorMsg("建立关系失败");
|
||||
}
|
||||
return ServerResponse.successMsg("用户添加角色成功");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerResponse batchDelete(Integer userId, List<Integer> roleIds) {
|
||||
UpmsUser upmsUser = upmsUserMapper.selectByPrimaryKey(userId);
|
||||
if (upmsUser == null){
|
||||
return ServerResponse.errorMsg("用户不存在");
|
||||
}
|
||||
int i = mapper.batchDelete(userId, roleIds);
|
||||
if (i == roleIds.size()){
|
||||
return ServerResponse.errorMsg("用户删除角色失败");
|
||||
}
|
||||
return ServerResponse.successMsg("用户删除角色成功");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,95 +14,16 @@
|
||||
<sql id="Base_Column_List" >
|
||||
id, user_id, role_id, ctime, uptime, version
|
||||
</sql>
|
||||
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
|
||||
select
|
||||
<include refid="Base_Column_List" />
|
||||
from upms_user_role
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
</select>
|
||||
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
|
||||
delete from upms_user_role
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
<insert id="batchInsert">
|
||||
INSERT INTO upms_user_role (user_id,role_id,ctime,version) VALUES
|
||||
<foreach collection="roleIds" open="" close="" item="roleId" separator="," >
|
||||
(#{userId},#{roleId},unix_timestamp(now()),0)
|
||||
</foreach>
|
||||
</insert>
|
||||
<delete id="batchDelete">
|
||||
DELETE FROM upms_user_role WHERE user_id = #{userId} and role_id in
|
||||
<foreach collection="roleIds" separator="," open="(" close=")" item="roleId" >
|
||||
#{roleId}
|
||||
</foreach>
|
||||
</delete>
|
||||
<insert id="insert" parameterType="com.micro.fast.upms.pojo.UpmsUserRole" >
|
||||
insert into upms_user_role (id, user_id, role_id,
|
||||
ctime, uptime, version
|
||||
)
|
||||
values (#{id,jdbcType=INTEGER}, #{userId,jdbcType=INTEGER}, #{roleId,jdbcType=INTEGER},
|
||||
#{ctime,jdbcType=BIGINT}, #{uptime,jdbcType=BIGINT}, #{version,jdbcType=INTEGER}
|
||||
)
|
||||
</insert>
|
||||
<insert id="insertSelective" parameterType="com.micro.fast.upms.pojo.UpmsUserRole" >
|
||||
insert into upms_user_role
|
||||
<trim prefix="(" suffix=")" suffixOverrides="," >
|
||||
<if test="id != null" >
|
||||
id,
|
||||
</if>
|
||||
<if test="userId != null" >
|
||||
user_id,
|
||||
</if>
|
||||
<if test="roleId != null" >
|
||||
role_id,
|
||||
</if>
|
||||
<if test="ctime != null" >
|
||||
ctime,
|
||||
</if>
|
||||
<if test="uptime != null" >
|
||||
uptime,
|
||||
</if>
|
||||
<if test="version != null" >
|
||||
version,
|
||||
</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides="," >
|
||||
<if test="id != null" >
|
||||
#{id,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="userId != null" >
|
||||
#{userId,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="roleId != null" >
|
||||
#{roleId,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="ctime != null" >
|
||||
#{ctime,jdbcType=BIGINT},
|
||||
</if>
|
||||
<if test="uptime != null" >
|
||||
#{uptime,jdbcType=BIGINT},
|
||||
</if>
|
||||
<if test="version != null" >
|
||||
#{version,jdbcType=INTEGER},
|
||||
</if>
|
||||
</trim>
|
||||
</insert>
|
||||
<update id="updateByPrimaryKeySelective" parameterType="com.micro.fast.upms.pojo.UpmsUserRole" >
|
||||
update upms_user_role
|
||||
<set >
|
||||
<if test="userId != null" >
|
||||
user_id = #{userId,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="roleId != null" >
|
||||
role_id = #{roleId,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="ctime != null" >
|
||||
ctime = #{ctime,jdbcType=BIGINT},
|
||||
</if>
|
||||
<if test="uptime != null" >
|
||||
uptime = #{uptime,jdbcType=BIGINT},
|
||||
</if>
|
||||
<if test="version != null" >
|
||||
version = #{version,jdbcType=INTEGER},
|
||||
</if>
|
||||
</set>
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
</update>
|
||||
<update id="updateByPrimaryKey" parameterType="com.micro.fast.upms.pojo.UpmsUserRole" >
|
||||
update upms_user_role
|
||||
set user_id = #{userId,jdbcType=INTEGER},
|
||||
role_id = #{roleId,jdbcType=INTEGER},
|
||||
ctime = #{ctime,jdbcType=BIGINT},
|
||||
uptime = #{uptime,jdbcType=BIGINT},
|
||||
version = #{version,jdbcType=INTEGER}
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
</update>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user