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