<?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.koukay.mapper.AppPackageMapper" > <select id="getAllApps" resultType="com.koukay.entity.AppPackModel" >
SELECT
<include refid="base_app_sql"/>,
3 AS authLevel
FROM
h_app_package h
</select>
<select id="getAppsAuth" resultType="com.koukay.entity.PermissionAppRoleUserDepartmentModel" >
SELECT
<include refid="base_app_sql"/>,
authLevel
FROM
h_app_dept_role_user h
</select>
<sql id="base_app_sql">
h.agentId,
h.appKey,
h.appSecret,
h.CODE,
h.creater,
h.createdTime,
h.deleted,
h.enabled,
h.id,
h.logoUrl,
h.logoUrlId,
h.modifier,
h.modifiedTime,
h.NAME,
h.name_i18n,
h.remarks,
h.sortKey
</sql>
<!--入参为多个集合参数-->
<select id="getApps" resultType="com.koukay.entity.AppPackModel" >
SELECT
<include refid="base_app_sql"/>,
h1.authLevel
FROM
h_app_dept_role_user h1
INNER JOIN h_app_package h ON h1.appCode = h.`code`
WHERE
h1.userId = #{userId}
<if test="rolesIds !=null and rolesIds.size()>0">
OR h1.roleId IN
<foreach collection="rolesIds" item="params" index="index" open="(" close=")" separator=",">
#{params.roleId}
</foreach>
</if>
<if test="deptsIds !=null and deptsIds.size()>0">
OR h1.deptId IN
<foreach collection="deptsIds" item="params" index="index" open="(" close=")" separator=",">
#{params.deptId}
</foreach>
</if>

UNION ALL
SELECT
<include refid="base_app_sql"/>,
3 AS authLevel
FROM
h_app_package h
WHERE
h.creater = #{userId}
</select>
<!-- 应用授权 1:给组织授权,2:给角色授权,3:给用户授权-->
<insert id="grantApp" parameterType="com.koukay.entity.PermissionAppRoleUserDepartmentModel">
INSERT INTO h_app_dept_role_user
( id, creater, createdTime, appCode,authLevel,authType,
        <!--插入时对字段做动态选择-->
<if test="authType=='1'.toString() ">
deptId
</if>
<if test="authType=='2'.toString() ">
roleId
</if>
<if test="authType=='3'.toString() ">
userId
</if>

)
VALUES
<foreach collection ="authList" item="param" index= "index" separator ="," >
(
(SELECT REPLACE(UUID(), '-', '') AS id),<!--生成UUID-->
#{createdBy,jdbcType=VARCHAR},
#{createdTime,jdbcType=TIMESTAMP},
#{appCode,jdbcType=VARCHAR},
#{param.authLevel,jdbcType=VARCHAR},
#{authType,jdbcType=VARCHAR},
#{param.id,jdbcType=VARCHAR}
)
</foreach>
</insert>
<delete id="deleteAuth">
delete from h_app_dept_role_user
<where>
<if test="id != null and id != ''">
id = #{id,jdbcType=VARCHAR}
</if>
<if test="appCode != null and appCode != ''">
and appCode = #{appCode,jdbcType=VARCHAR}
</if>
<if test="authType != null and authType != ''">
and authType = #{authType,jdbcType=VARCHAR}
</if>
</where>
</delete>
</mapper>
@Mapper
public interface AppPackageMapper { void grantApp(PermissionAppRoleUserDepartmentModel permissionAppRoleUserDepartmentModel); List<AppPackModel> getApps(Map params); List<AppPackModel> getAllApps(); void deleteAuth(Map<String, Object> param); List<PermissionAppRoleUserDepartmentModel> getAppsAuth();
}
@ApiModel(
description = "应用角色,应用组织,应用用户 关联对象"
)
@Data
public class PermissionAppRoleUserDepartmentModel extends BaseModel {
@ApiModelProperty("权限组名称")
private String name; @ApiModelProperty("关联的应用编码")
private String appCode; @ApiModelProperty(value = "授权集合")
private List<KeyValueModel> authList; @ApiModelProperty("权限级别,1:查看权限,2:操作权限,3:授权权限")
private String authLevel; @ApiModelProperty("权限类型,1:给组织授权,2:给角色授权,3:给用户授权")
private String authType; }

mybatis踩过的坑的更多相关文章

  1. 项目中踩过的坑之-sessionStorage

    总想写点什么,却不知道从何写起,那就从项目中踩过的坑开始吧,希望能给可能碰到相同问题的小伙伴一点帮助. 项目情景: 有一个id,要求通过当前网页打开一个新页面(不是当前页面),并把id传给打开的新页面 ...

  2. web开发实战--弹出式富文本编辑器的实现思路和踩过的坑

    前言: 和弟弟合作, 一起整了个智慧屋的小web站点, 里面包含了很多经典的智力和推理题. 其实该站点从技术层面来分析的话, 也算一个信息发布站点. 因此在该网站的后台运营中, 富文本的编辑器显得尤为 ...

  3. "开发路上踩过的坑要一个个填起来————持续更新······(7月30日)"

    欢迎转载,请注明出处! https://gii16.github.io/learnmore/2016/07/29/problem.html 踩过的坑及解决方案记录在此篇博文中! 个人理解,如有偏颇,欢 ...

  4. 【转载】Fragment 全解析(1):那些年踩过的坑

    http://www.jianshu.com/p/d9143a92ad94 Fragment系列文章:1.Fragment全解析系列(一):那些年踩过的坑2.Fragment全解析系列(二):正确的使 ...

  5. Redis Cluster踩过的坑

    Redis Cluster踩过的坑请参考如下链接:http://www.iteye.com/blogs/subjects/Redis_Cluster_Devops

  6. 第八篇:web之前端踩的一些坑

    前端踩的一些坑   前端踩的一些坑 本节内容 事件代理 清除标签的所有事件 bootstrap的模态框自定义方法 ajax在django里面实现post提交 ajax提交数据嵌套 1.事件代理 之前写 ...

  7. 使用ffmpeg视频编码过程中踩的一个坑

           今天说说使用ffmpeg在写视频编码程序中踩的一个坑,这个坑让我花了好多时间,回头想想,非常多时候一旦思维定势真的挺难突破的.以下是不对的编码结果:                   ...

  8. 那些年踩过的坑之:first-child伪类选择器

    原文:那些年踩过的坑之:first-child伪类选择器 :first-child 选择器用于选取属于其父元素的首个子元素的指定选择器.——w3school 嗯,乍一看好像说的不是很明白,因此这个选择 ...

  9. 《C++之那些年踩过的坑(二)》

    C++之那些年踩过的坑(二) 作者:刘俊延(Alinshans) 本系列文章针对我在写C++代码的过程中,尤其是做自己的项目时,踩过的各种坑.以此作为给自己的警惕. 今天讲一个小点,虽然小,但如果没有 ...

随机推荐

  1. LC-844

    给定 s 和 t 两个字符串,当它们分别被输入到空白的文本编辑器后,如果两者相等,返回 true .# 代表退格字符. 注意:如果对空文本输入退格字符,文本继续为空. 示例 1: 输入:s = &qu ...

  2. [翻译] Cassandra 分布式结构化存储系统

    Cassandra 分布式结构化存储系统 摘要 Cassandra 是一个分布式存储系统,用于管理分布在许多商品服务器上的大量结构化数据,同时提供无单点故障(no single point of fa ...

  3. uniapp中添加vant组件

    首先是npm i vant@2 -S 下载vant包 接下来就是找到main.js引入vant 然后就是在页面中直接使用 会发现没有样式 最后再找到app.vue再style里面全局引入vant的样式 ...

  4. gin框架使用【3.路由参数】

    GET url: http://127.0.0.1:8080/users/{id} http://127.0.0.1:8080/users/1   对于id值的获取 package main impo ...

  5. Java 线程池四种拒绝策略

    jdk1.5版本新增了 JUC 并发包,其中一个包含线程池. 四种拒绝策略: 拒绝策略类型 说明 1 ThreadPoolExecutor.AbortPolicy 默认拒绝策略,拒绝任务并抛出任务 2 ...

  6. [STL] vector 可变数组

    点击查看代码 #include<iostream> #include<vector> using namespace std; int main() { // 初始化 a 为 ...

  7. 如何改变函数内部 this 的指向

    一.函数内 this 的指向 1. this 的指向是当调用函数时确定的,调用的方式不同,this 的指向也就不同. 1.1 this 一般是指向调用者. 函数类型 this 的指向 普通函数 Win ...

  8. 服务器安全加固 - Linux

    一.账号和口令 1.1 禁用或删除无用账号 查看 /etc/passwd 文件查看是否有无用的账号,如果存在则删除,降低安全风险. 操作步骤: 使用命令 userdel <用户名> 删除不 ...

  9. C++基础-6-继承

    6. 继承 1 #include<iostream> 2 using namespace std; 3 4 5 class Base { 6 public: 7 Base() { 8 m_ ...

  10. 【面试普通人VS高手系列】讲一下wait和notify这个为什么要在synchronized代码块中?

    一个工作七年的小伙伴,竟然不知道"wait"和"notify"为什么要在Synchronized代码块里面. 好吧,如果屏幕前的你也不知道,请在评论区打上&qu ...