<?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; }

最新文章

  1. FragmentTabHost + Fragment 使用小记
  2. cnentos中进行bond网卡配置,一切配置无问题,就是ping不通宿主机
  3. 【进展】LL谱面存储方式的改善
  4. jQuery学习总结
  5. Github注册账户
  6. 100114D
  7. Unity3D 中 用quaternion 来对一个坐标点进行旋转的初步体会
  8. 22个值得收藏的Android开源代码-UI篇
  9. git的使用(3) 多分支情况下的pull
  10. Qt之界面出现、消失动画效果(简单好用)
  11. (转载)OC学习篇之---第一个程序HelloWorld
  12. 设计模式 - Abstract Factory模式(abstract factory pattern) 详细说明
  13. django中通过model名字获取model
  14. Ext js Grid
  15. unbuntu系统( PC机 )中安装360wifi步骤
  16. 1.1开篇一:C语言编译器的选择---Dev C++
  17. [c++]base64编解码 and image
  18. day28-面相对象的特殊成员、内置函数
  19. python中计算程序用时的方法
  20. hdu-1892-二维BIT

热门文章

  1. Spring5-IOC容器实现方式
  2. LinkedList实现
  3. 2021.08.09 P7238 迷失森林(树的直径)
  4. JMeter配置Oauth2.0授权接口访问
  5. 如何使用 pyqt 实现 Groove 音乐播放器
  6. R 数据可视化: PCA 主成分分析图
  7. 2003031121-浦娟-python数据分析五一假期作业
  8. 踩到一个关于分布式锁的非比寻常的BUG!
  9. Water 2.6.3 发布,一站式服务治理平台
  10. 用上这个 Mock 神器,让你的开发爽上天!