作者 朱兆平

角色、权限、日志

package com.tianbo.warehouse.controller;
import com.tianbo.warehouse.model.PERMISSION;
import com.tianbo.warehouse.model.USERS;
import com.tianbo.warehouse.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
@Controller
public class ImfLog {
@Autowired
UserService userService;
@RequestMapping("/log/imf")
public String IMFlog(){
return "log/imf";
}
@RequestMapping("/home")
public String Home(Model model){
PERMISSION msg = new PERMISSION();
msg.setDescription("权限描述");
msg.setName("权限名称");
msg.setPermissionOrder("权限路径");
model.addAttribute("msg", msg);
return "home";
}
@RequestMapping("/logs")
@ResponseBody
... ...
package com.tianbo.warehouse.controller;
import com.github.pagehelper.PageInfo;
import com.tianbo.warehouse.model.LOGWithBLOBs;
import com.tianbo.warehouse.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class LogController {
@Autowired
private LogService logService;
@GetMapping("/system/log/list")
public PageInfo<LOGWithBLOBs> systemLog(@RequestParam(value = "pageNum",required = false,defaultValue = "1")
int pageNum,
@RequestParam(value = "pageSize",required = false,defaultValue = "5")
int pageSize){
return logService.selectAll(pageNum,pageSize);
}
}
... ...
package com.tianbo.warehouse.controller;
import com.github.pagehelper.PageInfo;
import com.tianbo.warehouse.annotation.LogAnnotation;
import com.tianbo.warehouse.controller.response.ResultJson;
import com.tianbo.warehouse.dao.PERMISSIONMapper;
import com.tianbo.warehouse.model.PERMISSION;
... ... @@ -32,6 +33,7 @@ public class PermssionController {
}
@LogAnnotation(moduleName = "权限管理",operate = "权限添加")
@PostMapping("/perm/add")
public ResultJson add(@RequestBody PERMISSION permission){
int i =permissionService.insertSelective(permission);
... ...
package com.tianbo.warehouse.controller;
import com.github.pagehelper.PageInfo;
import com.tianbo.warehouse.annotation.LogAnnotation;
import com.tianbo.warehouse.controller.response.ResultJson;
import com.tianbo.warehouse.model.ROLE;
import com.tianbo.warehouse.model.RolePermission;
import com.tianbo.warehouse.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
... ... @@ -21,17 +23,22 @@ public class RoleController {
return roleService.findAll(pageNum,pageSize);
}
@LogAnnotation(moduleName = "角色管理",operate = "角色添加")
@PostMapping("/role/add")
public ResultJson add(@RequestBody ROLE role){
int i =roleService.insertSelective(role);
return i==1 ? new ResultJson("200","添加权限成功") :new ResultJson("500","insert faild");
ResultJson resultJson = new ResultJson();
if (1==i){
resultJson = new ResultJson("200","添加账户成功");
}else {
resultJson = new ResultJson("500","insert faild");
}
return resultJson;
}
/**
* 设置角色的权限
* @return
*/
@LogAnnotation(moduleName = "角色管理",operate = "权限设置")
@PutMapping("/role/permSet")
public ResultJson permissionSet(@RequestBody RolePermission rolePermission){
int i = roleService.setRolePermissoin(rolePermission);
return i==1 ? new ResultJson("200","设置权限成功") :new ResultJson("500","设置权限失败");
}
}
... ...
... ... @@ -78,7 +78,7 @@ public class UserController {
int i = userService.setUserRole(userRole);
return i==1 ? new ResultJson("200","设置权限成功") :new ResultJson("500","设置权限失败");
return i==1 ? new ResultJson("200","设置角色成功") :new ResultJson("500","设置角色失败");
}
... ...
... ... @@ -3,6 +3,8 @@ package com.tianbo.warehouse.dao;
import com.tianbo.warehouse.model.LOG;
import com.tianbo.warehouse.model.LOGWithBLOBs;
import java.util.List;
public interface LOGMapper {
int deleteByPrimaryKey(Integer logid);
... ... @@ -12,6 +14,8 @@ public interface LOGMapper {
LOGWithBLOBs selectByPrimaryKey(Integer logid);
List<LOGWithBLOBs> selectAll();
int updateByPrimaryKeySelective(LOGWithBLOBs record);
int updateByPrimaryKeyWithBLOBs(LOGWithBLOBs record);
... ...
... ... @@ -25,4 +25,6 @@ public interface PERMISSIONMapper {
List<PERMISSION> findByUserId(Integer userId);
List<String> findRoleListByUrl(String permissionUrl);
List<PERMISSION> getRolePermisson(Integer roleId);
}
\ No newline at end of file
... ...
package com.tianbo.warehouse.dao;
import com.tianbo.warehouse.model.PERMISSION;
import com.tianbo.warehouse.model.ROLE;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public interface ROLEMapper {
int deleteByPrimaryKey(Integer roleId);
... ... @@ -21,4 +24,6 @@ public interface ROLEMapper {
List<ROLE> findRolesByUserId(Integer userId);
List<ROLE> findAll();
}
\ No newline at end of file
... ...
package com.tianbo.warehouse.dao;
import com.tianbo.warehouse.model.RolePermission;
import java.util.Map;
public interface RolePermissionMapper {
int deleteByPrimaryKey(Integer id);
int insert(RolePermission record);
int insertSelective(RolePermission record);
RolePermission selectByPrimaryKey(Integer id);
int updateByPrimaryKeySelective(RolePermission record);
int updateByPrimaryKey(RolePermission record);
int insertRolePerm(RolePermission record);
int delPermByRoleId(Integer roleId);
}
\ No newline at end of file
... ...
... ... @@ -2,6 +2,8 @@ package com.tianbo.warehouse.model;
import org.springframework.security.core.GrantedAuthority;
import java.util.List;
public class ROLE implements GrantedAuthority {
private static final long serialVersionUID = 1L;
... ... @@ -13,6 +15,8 @@ public class ROLE implements GrantedAuthority {
private String description;
private List<PERMISSION> permissions;
public Integer getRoleId() {
return roleId;
}
... ... @@ -45,6 +49,14 @@ public class ROLE implements GrantedAuthority {
this.description = description == null ? null : description.trim();
}
public List<PERMISSION> getPermissions() {
return permissions;
}
public void setPermissions(List<PERMISSION> permissions) {
this.permissions = permissions;
}
@Override
public String getAuthority(){
return this.getRoleName();
... ...
package com.tianbo.warehouse.model;
import java.util.List;
public class RolePermission {
private Integer id;
private Integer roleId;
private Integer permissionId;
//处理前端提交过来的权限ID列表
private List<Integer> permissionIds;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getRoleId() {
return roleId;
}
public void setRoleId(Integer roleId) {
this.roleId = roleId;
}
public Integer getPermissionId() {
return permissionId;
}
public void setPermissionId(Integer permissionId) {
this.permissionId = permissionId;
}
public List<Integer> getPermissionIds() {
return permissionIds;
}
public void setPermissionIds(List<Integer> permissionIds) {
this.permissionIds = permissionIds;
}
}
\ No newline at end of file
... ...
... ... @@ -2,15 +2,19 @@ package com.tianbo.warehouse.model;
import lombok.Data;
import javax.validation.constraints.DecimalMin;
import java.util.List;
@Data
public class UserRole {
@DecimalMin("1")
private Integer id;
@DecimalMin("1")
private Integer userId;
@DecimalMin("1")
private Integer roleId;
private List<Integer> roleIds;
... ...
package com.tianbo.warehouse.service;
import com.github.pagehelper.PageInfo;
import com.tianbo.warehouse.model.LOG;
import com.tianbo.warehouse.model.LOGWithBLOBs;
public interface LogService {
int insertSelective(LOGWithBLOBs record);
PageInfo<LOGWithBLOBs> selectAll(int pageNum, int pageSize);
}
... ...
... ... @@ -2,9 +2,12 @@ package com.tianbo.warehouse.service;
import com.github.pagehelper.PageInfo;
import com.tianbo.warehouse.model.ROLE;
import com.tianbo.warehouse.model.RolePermission;
public interface RoleService {
PageInfo<ROLE> findAll(int pageNum, int pageSize);
int insertSelective(ROLE record);
int setRolePermissoin(RolePermission record);
}
... ...
package com.tianbo.warehouse.service.imp;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tianbo.warehouse.dao.LOGMapper;
import com.tianbo.warehouse.model.LOG;
import com.tianbo.warehouse.model.LOGWithBLOBs;
import com.tianbo.warehouse.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service("webLog")
public class LogServiceImp implements LogService{
... ... @@ -18,4 +22,12 @@ public class LogServiceImp implements LogService{
public int insertSelective(LOGWithBLOBs record){
return logMapper.insertSelective(record);
}
@Override
public PageInfo<LOGWithBLOBs> selectAll(int pageNum,int pageSize){
Page<LOGWithBLOBs> page = PageHelper.startPage(pageNum,pageSize);
List<LOGWithBLOBs> list = logMapper.selectAll();
PageInfo<LOGWithBLOBs> result = new PageInfo<LOGWithBLOBs>(list);
return result;
}
}
... ...
... ... @@ -4,12 +4,13 @@ import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tianbo.warehouse.dao.ROLEMapper;
import com.tianbo.warehouse.model.PERMISSION;
import com.tianbo.warehouse.dao.RolePermissionMapper;
import com.tianbo.warehouse.model.ROLE;
import com.tianbo.warehouse.model.USERS;
import com.tianbo.warehouse.model.RolePermission;
import com.tianbo.warehouse.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
... ... @@ -17,7 +18,10 @@ import java.util.List;
public class RoleServiceImp implements RoleService{
@Autowired
ROLEMapper roleMapper;
private ROLEMapper roleMapper;
@Autowired
private RolePermissionMapper rolePermissionMapper;
@Override
public PageInfo<ROLE> findAll(int pageNum, int pageSize){
... ... @@ -31,4 +35,22 @@ public class RoleServiceImp implements RoleService{
public int insertSelective(ROLE record){
return roleMapper.insertSelective(record);
}
@Transactional(rollbackFor = Exception.class)
@Override
public int setRolePermissoin(RolePermission record){
try{
Integer roleId = record.getRoleId();
List<Integer> permissions = record.getPermissionIds();
//这里加个判定,如果前端提交的权限列表是空的,代表清空这个角色的所有权限,防止SQL出错
if (null!=permissions && !permissions.isEmpty()){
rolePermissionMapper.delPermByRoleId(roleId);
rolePermissionMapper.insertRolePerm(record);
}
return 1;
}catch (Exception e){
e.printStackTrace();
return 0;
}
}
}
... ...
... ... @@ -97,7 +97,7 @@ public class UserServiceImpl implements UserService{
}
}
/**重置用户的权限
/**重置用户的权限,每次设置用户权限关系前,先删除用户所有权限,再重新分配用户权限
*这里需要开启事务,删除 或者插入不生效就回滚
* @param userRole
* @return
... ...
... ... @@ -45,6 +45,6 @@
<property name="enableSubPackages" value="true"/>
</javaClientGenerator>
<!-- 要生成的表 tableName是数据库中的表名或视图名 domainObjectName是实体类名-->
<table tableName="user_role" domainObjectName="UserRole" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
<table tableName="log" domainObjectName="LOG" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
</context>
</generatorConfiguration>
\ No newline at end of file
... ...
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.tianbo.warehouse.dao.LOGMapper" >
<resultMap id="BaseResultMap" type="com.tianbo.warehouse.model.LOG" >
<id column="logId" property="logid" jdbcType="INTEGER" />
<result column="userName" property="username" jdbcType="VARCHAR" />
<result column="ip" property="ip" jdbcType="VARCHAR" />
<result column="logCreatTime" property="logcreattime" jdbcType="TIMESTAMP" />
<result column="methodName" property="methodname" jdbcType="VARCHAR" />
<result column="modelNameCN" property="modelnamecn" jdbcType="VARCHAR" />
<result column="operateNameCN" property="operatenamecn" jdbcType="VARCHAR" />
<result column="className" property="classname" jdbcType="VARCHAR" />
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.tianbo.warehouse.dao.LOGMapper">
<resultMap id="BaseResultMap" type="com.tianbo.warehouse.model.LOG">
<id column="logId" jdbcType="INTEGER" property="logid" />
<result column="userName" jdbcType="VARCHAR" property="username" />
<result column="ip" jdbcType="VARCHAR" property="ip" />
<result column="logCreatTime" jdbcType="TIMESTAMP" property="logcreattime" />
<result column="methodName" jdbcType="VARCHAR" property="methodname" />
<result column="modelNameCN" jdbcType="VARCHAR" property="modelnamecn" />
<result column="operateNameCN" jdbcType="VARCHAR" property="operatenamecn" />
<result column="className" jdbcType="VARCHAR" property="classname" />
</resultMap>
<resultMap id="ResultMapWithBLOBs" type="com.tianbo.warehouse.model.LOGWithBLOBs" extends="BaseResultMap" >
<result column="parameters" property="parameters" jdbcType="LONGVARCHAR" />
<result column="result" property="result" jdbcType="LONGVARCHAR" />
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="com.tianbo.warehouse.model.LOGWithBLOBs">
<result column="parameters" jdbcType="LONGVARCHAR" property="parameters" />
<result column="result" jdbcType="LONGVARCHAR" property="result" />
</resultMap>
<sql id="Base_Column_List" >
<sql id="Base_Column_List">
logId, userName, ip, logCreatTime, methodName, modelNameCN, operateNameCN, className
</sql>
<sql id="Blob_Column_List" >
<sql id="Blob_Column_List">
parameters, result
</sql>
<select id="selectByPrimaryKey" resultMap="ResultMapWithBLOBs" parameterType="java.lang.Integer" >
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="ResultMapWithBLOBs">
select
<include refid="Base_Column_List" />
,
... ... @@ -29,11 +29,18 @@
from log
where logId = #{logid,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
<select id="selectAll" resultMap="ResultMapWithBLOBs">
select
<include refid="Base_Column_List" />
,
<include refid="Blob_Column_List" />
from log
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from log
where logId = #{logid,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.tianbo.warehouse.model.LOGWithBLOBs" >
<insert id="insert" parameterType="com.tianbo.warehouse.model.LOGWithBLOBs">
insert into log (logId, userName, ip,
logCreatTime, methodName, modelNameCN,
operateNameCN, className, parameters,
... ... @@ -43,107 +50,107 @@
#{operatenamecn,jdbcType=VARCHAR}, #{classname,jdbcType=VARCHAR}, #{parameters,jdbcType=LONGVARCHAR},
#{result,jdbcType=LONGVARCHAR})
</insert>
<insert id="insertSelective" parameterType="com.tianbo.warehouse.model.LOGWithBLOBs" >
<insert id="insertSelective" parameterType="com.tianbo.warehouse.model.LOGWithBLOBs">
insert into log
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="logid != null" >
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="logid != null">
logId,
</if>
<if test="username != null" >
<if test="username != null">
userName,
</if>
<if test="ip != null" >
<if test="ip != null">
ip,
</if>
<if test="logcreattime != null" >
<if test="logcreattime != null">
logCreatTime,
</if>
<if test="methodname != null" >
<if test="methodname != null">
methodName,
</if>
<if test="modelnamecn != null" >
<if test="modelnamecn != null">
modelNameCN,
</if>
<if test="operatenamecn != null" >
<if test="operatenamecn != null">
operateNameCN,
</if>
<if test="classname != null" >
<if test="classname != null">
className,
</if>
<if test="parameters != null" >
<if test="parameters != null">
parameters,
</if>
<if test="result != null" >
<if test="result != null">
result,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="logid != null" >
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="logid != null">
#{logid,jdbcType=INTEGER},
</if>
<if test="username != null" >
<if test="username != null">
#{username,jdbcType=VARCHAR},
</if>
<if test="ip != null" >
<if test="ip != null">
#{ip,jdbcType=VARCHAR},
</if>
<if test="logcreattime != null" >
<if test="logcreattime != null">
#{logcreattime,jdbcType=TIMESTAMP},
</if>
<if test="methodname != null" >
<if test="methodname != null">
#{methodname,jdbcType=VARCHAR},
</if>
<if test="modelnamecn != null" >
<if test="modelnamecn != null">
#{modelnamecn,jdbcType=VARCHAR},
</if>
<if test="operatenamecn != null" >
<if test="operatenamecn != null">
#{operatenamecn,jdbcType=VARCHAR},
</if>
<if test="classname != null" >
<if test="classname != null">
#{classname,jdbcType=VARCHAR},
</if>
<if test="parameters != null" >
<if test="parameters != null">
#{parameters,jdbcType=LONGVARCHAR},
</if>
<if test="result != null" >
<if test="result != null">
#{result,jdbcType=LONGVARCHAR},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.tianbo.warehouse.model.LOGWithBLOBs" >
<update id="updateByPrimaryKeySelective" parameterType="com.tianbo.warehouse.model.LOGWithBLOBs">
update log
<set >
<if test="username != null" >
<set>
<if test="username != null">
userName = #{username,jdbcType=VARCHAR},
</if>
<if test="ip != null" >
<if test="ip != null">
ip = #{ip,jdbcType=VARCHAR},
</if>
<if test="logcreattime != null" >
<if test="logcreattime != null">
logCreatTime = #{logcreattime,jdbcType=TIMESTAMP},
</if>
<if test="methodname != null" >
<if test="methodname != null">
methodName = #{methodname,jdbcType=VARCHAR},
</if>
<if test="modelnamecn != null" >
<if test="modelnamecn != null">
modelNameCN = #{modelnamecn,jdbcType=VARCHAR},
</if>
<if test="operatenamecn != null" >
<if test="operatenamecn != null">
operateNameCN = #{operatenamecn,jdbcType=VARCHAR},
</if>
<if test="classname != null" >
<if test="classname != null">
className = #{classname,jdbcType=VARCHAR},
</if>
<if test="parameters != null" >
<if test="parameters != null">
parameters = #{parameters,jdbcType=LONGVARCHAR},
</if>
<if test="result != null" >
<if test="result != null">
result = #{result,jdbcType=LONGVARCHAR},
</if>
</set>
where logId = #{logid,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKeyWithBLOBs" parameterType="com.tianbo.warehouse.model.LOGWithBLOBs" >
<update id="updateByPrimaryKeyWithBLOBs" parameterType="com.tianbo.warehouse.model.LOGWithBLOBs">
update log
set userName = #{username,jdbcType=VARCHAR},
ip = #{ip,jdbcType=VARCHAR},
... ... @@ -156,7 +163,7 @@
result = #{result,jdbcType=LONGVARCHAR}
where logId = #{logid,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.tianbo.warehouse.model.LOG" >
<update id="updateByPrimaryKey" parameterType="com.tianbo.warehouse.model.LOG">
update log
set userName = #{username,jdbcType=VARCHAR},
ip = #{ip,jdbcType=VARCHAR},
... ...
... ... @@ -28,9 +28,16 @@
<select id="findAll" resultMap="BaseResultMap" >
select
<include refid="Base_Column_List" />
from permission ORDER BY permission_order
from permission ORDER BY ismenu,parent_id,permission_order
</select>
<select id="getRolePermisson" resultMap="BaseResultMap" parameterType="java.lang.Integer">
SELECT P.*
FROM role R
LEFT JOIN role_permission RP ON R.role_id = RP.role_id
LEFT JOIN permission P ON RP.permission_id = P.permission_id
WHERE r.role_id=#{roleId,jdbcType=INTEGER}
ORDER BY P.ismenu,P.name,p.permission_order DESC
</select>
<select id="getAllMenus" resultMap="BaseResultMap" >
SELECT
P .*
... ...
... ... @@ -6,6 +6,7 @@
<result column="role_name" jdbcType="VARCHAR" property="roleName" />
<result column="role_sign" jdbcType="VARCHAR" property="roleSign" />
<result column="description" jdbcType="VARCHAR" property="description" />
<collection property="permissions" ofType="PERMISSION" javaType="java.util.ArrayList" select="com.tianbo.warehouse.dao.PERMISSIONMapper.getRolePermisson" column="role_id"></collection>
</resultMap>
<sql id="Base_Column_List">
role_id, role_name, role_sign, description
... ... @@ -17,9 +18,9 @@
where role_id = #{roleId,jdbcType=INTEGER}
</select>
<select id="findAll" resultMap="BaseResultMap" >
select
SELECT
<include refid="Base_Column_List" />
from role
FROM role
</select>
<select id="findRolesByUserId" parameterType="java.lang.Integer" resultMap="BaseResultMap">
SELECT
... ... @@ -40,7 +41,8 @@
values (#{roleId,jdbcType=INTEGER}, #{roleName,jdbcType=VARCHAR}, #{roleSign,jdbcType=VARCHAR},
#{description,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="com.tianbo.warehouse.model.ROLE">
<insert id="insertSelective" parameterType="Integer">
insert into role
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="roleId != null">
... ...
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.tianbo.warehouse.dao.RolePermissionMapper" >
<resultMap id="BaseResultMap" type="com.tianbo.warehouse.model.RolePermission" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="role_id" property="roleId" jdbcType="INTEGER" />
<result column="permission_id" property="permissionId" jdbcType="INTEGER" />
</resultMap>
<sql id="Base_Column_List" >
id, role_id, permission_id
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
from role_permission
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from role_permission
where id = #{id,jdbcType=INTEGER}
</delete>
<delete id="delPermByRoleId" parameterType="java.lang.Integer">
delete from role_permission
where role_id = #{roleId,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.tianbo.warehouse.model.RolePermission" >
insert into role_permission (id, role_id, permission_id
)
values (#{id,jdbcType=INTEGER}, #{roleId,jdbcType=INTEGER}, #{permissionId,jdbcType=INTEGER}
)
</insert>
<insert id="insertRolePerm" parameterType="RolePermission">
insert into role_permission(role_id, permission_id)
values
<foreach collection="permissionIds" item="rolePem" index="index" separator=",">
(#{roleId,jdbcType=INTEGER},#{rolePem,jdbcType=INTEGER})
</foreach>
</insert>
<insert id="insertSelective" parameterType="com.tianbo.warehouse.model.RolePermission" >
insert into role_permission
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
id,
</if>
<if test="roleId != null" >
role_id,
</if>
<if test="permissionId != null" >
permission_id,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="id != null" >
#{id,jdbcType=INTEGER},
</if>
<if test="roleId != null" >
#{roleId,jdbcType=INTEGER},
</if>
<if test="permissionId != null" >
#{permissionId,jdbcType=INTEGER},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.tianbo.warehouse.model.RolePermission" >
update role_permission
<set >
<if test="roleId != null" >
role_id = #{roleId,jdbcType=INTEGER},
</if>
<if test="permissionId != null" >
permission_id = #{permissionId,jdbcType=INTEGER},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.tianbo.warehouse.model.RolePermission" >
update role_permission
set role_id = #{roleId,jdbcType=INTEGER},
permission_id = #{permissionId,jdbcType=INTEGER}
where id = #{id,jdbcType=INTEGER}
</update>
</mapper>
\ No newline at end of file
... ...
... ... @@ -24,17 +24,14 @@
where user_id = #{userId,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.tianbo.warehouse.model.UserRole" >
insert into user_role (id, user_id, role_id
insert into user_role (user_id, role_id
)
values (#{id,jdbcType=INTEGER}, #{userId,jdbcType=INTEGER}, #{roleId,jdbcType=INTEGER}
values (#{userId,jdbcType=INTEGER}, #{roleId,jdbcType=INTEGER}
)
</insert>
<insert id="insertSelective" parameterType="com.tianbo.warehouse.model.UserRole" >
insert into user_role
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
id,
</if>
<if test="userId != null" >
user_id,
</if>
... ... @@ -43,9 +40,6 @@
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="id != null" >
#{id,jdbcType=INTEGER},
</if>
<if test="userId != null" >
#{userId,jdbcType=INTEGER},
</if>
... ...