| <?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.matrix.system.common.dao.SysRoleDao"> | 
|     <!-- 定义SysRole 的复杂关联map --> | 
|     <resultMap type="com.matrix.system.common.bean.SysRole" id="SysRoleMap"> | 
|         <id property="roleId" column="role_id" /> | 
|         <result property="isDefault" column="is_default" /> | 
|         <result property="roleName" column="role_name" /> | 
|         <result property="roleRemark" column="role_remark" /> | 
|         <result property="companyId" column="company_id" /> | 
|         <result property="plates" column="plates" /> | 
|         <result property="shopAble" column="shop_able" /> | 
|     </resultMap> | 
|   | 
|   | 
|   | 
|   | 
|     <!-- 插入方法 --> | 
|     <insert id="insert" parameterType="com.matrix.system.common.bean.SysRole" | 
|         useGeneratedKeys="true" keyProperty="roleId"> | 
|         INSERT INTO sys_role ( | 
|         create_by, | 
|         create_time, | 
|         update_by, | 
|         update_time, | 
|         role_id, | 
|         role_name, | 
|         role_remark, | 
|         company_id, | 
|         plates, | 
|         is_default, | 
|         shop_able | 
|         ) | 
|         VALUES ( | 
|         #{createBy}, | 
|         now(), | 
|         #{updateBy}, | 
|         now(), | 
|         #{roleId}, | 
|         #{roleName}, | 
|         #{roleRemark}, | 
|         #{companyId}, | 
|         #{plates}, | 
|         #{isDefault}, | 
|         #{shopAble} | 
|         ) | 
|     </insert> | 
|   | 
|   | 
|   | 
|     <!-- 批量插入 --> | 
|     <insert id="batchInsert" parameterType="java.util.List"> | 
|         INSERT INTO sys_role ( | 
|         create_by, | 
|         create_time, | 
|         update_by, | 
|         update_time, | 
|         role_id, | 
|         role_name, | 
|         role_remark, | 
|         company_id, | 
|         plates, | 
|         is_default, | 
|         shop_able | 
|         ) | 
|         VALUES | 
|         <foreach collection="list" item="item" index="index" | 
|             separator=",">( | 
|             #{item.createBy}, | 
|             now(), | 
|             #{item.updateBy}, | 
|             now(), | 
|             #{item.roleId}, | 
|             #{item.roleName}, | 
|             #{item.roleRemark}, | 
|             #{item.companyId}, | 
|             #{item.plates}, | 
|             #{item.isDefault}, | 
|             #{item.shopAble} | 
|             ) | 
|         </foreach> | 
|     </insert> | 
|   | 
|   | 
|   | 
|   | 
|   | 
|     <!-- 根据Map更新 部分更新 --> | 
|     <update id="updateByMap" parameterType="java.util.HashMap"> | 
|         UPDATE sys_role | 
|         <set> | 
|             update_time=now(), | 
|             <if test="_parameter.containsKey('updateBy')"> | 
|                 update_by=#{updateBy}, | 
|             </if> | 
|             <if test="_parameter.containsKey('roleName')"> | 
|                 role_name = #{roleName}, | 
|             </if> | 
|             <if test="_parameter.containsKey('roleRemark')"> | 
|                 role_remark = #{roleRemark}, | 
|             </if> | 
|             <if test="_parameter.containsKey('companyId')"> | 
|                 company_id = #{companyId}, | 
|             </if> | 
|             <if test="_parameter.containsKey('plates')"> | 
|                 plates = #{plates}, | 
|             </if> | 
|             <if test="_parameter.containsKey('shopAble')"> | 
|                 shop_able = #{shopAble}, | 
|             </if> | 
|         </set> | 
|         WHERE role_id=#{roleId} | 
|     </update> | 
|   | 
|   | 
|   | 
|     <!-- 根据对象更新 部分更新 --> | 
|     <update id="updateByModel" parameterType="Long"> | 
|         UPDATE sys_role | 
|         <set> | 
|             update_time=now(), | 
|             <if test="updateBy!=null"> | 
|                 update_by = #{btnKey}, | 
|             </if> | 
|             <if | 
|                 test="(roleName!=null and roleName!='') or (roleName!='' and roleName==0)"> | 
|                 role_name = #{roleName}, | 
|             </if> | 
|             <if | 
|                 test="(roleRemark!=null and roleRemark!='') or (roleRemark!='' and roleRemark==0)"> | 
|                 role_remark = #{roleRemark}, | 
|             </if> | 
|             <if | 
|                 test="(companyId!=null and companyId!='') or (companyId!='' and companyId==0)"> | 
|                 company_id = #{companyId}, | 
|             </if> | 
|             <if test="(plates!=null and plates!='') or (plates!='' and plates==0)"> | 
|                 plates = #{plates}, | 
|             </if> | 
|             <if test="(shopAble!=null and shopAble!='') or (shopAble!='' and shopAble==0)"> | 
|                 shop_able = #{shopAble}, | 
|             </if> | 
|         </set> | 
|         WHERE role_id=#{roleId} | 
|     </update> | 
|   | 
|   | 
|     <!-- 批量删除 --> | 
|     <delete id="deleteByIds" parameterType="java.util.List"> | 
|         delete from sys_role where is_default =2 and  role_id in | 
|         <foreach collection="list" index="index" item="item" open="(" | 
|             separator="," close=")"> | 
|             #{item} | 
|         </foreach> | 
|     </delete> | 
|   | 
|     <!-- 根据id删除 --> | 
|     <delete id="deleteById" parameterType="Long"> | 
|         DELETE FROM sys_role | 
|         where | 
|          is_default =2 and | 
|         role_id=#{roleId} | 
|     </delete> | 
|   | 
|     <!-- 根据对象删除 --> | 
|     <delete id="deleteByModel" parameterType="Long"> | 
|         DELETE FROM sys_role | 
|         <where> | 
|   | 
|             <if test="record!=null"> | 
|                 <if | 
|                     test="(record.roleId!=null and record.roleId!='') or (record.roleId!='' and record.roleId==0)"> | 
|                     and role_id = #{record.roleId} | 
|                 </if> | 
|                 <if | 
|                     test="(record.roleName!=null and record.roleName!='') or (record.roleName!='' and record.roleName==0)"> | 
|                     and role_name = #{record.roleName} | 
|                 </if> | 
|                 <if | 
|                     test="(record.roleRemark!=null and record.roleRemark!='') or (record.roleRemark!='' and record.roleRemark==0)"> | 
|                     and role_remark = #{record.roleRemark} | 
|                 </if> | 
|                 <if | 
|                     test="(record.companyId!=null and record.companyId!='') or (record.companyId!='' and record.companyId==0)"> | 
|                     and company_id = #{record.companyId} | 
|                 </if> | 
|                 <if | 
|                     test="(record.plates!=null and record.plates!='') or (record.plates!='' and record.plates==0)"> | 
|                     and plates = #{record.plates} | 
|                 </if> | 
|                 and is_default=2 | 
|             </if> | 
|         </where> | 
|     </delete> | 
|   | 
|   | 
|   | 
|     <!-- 分页查询 --> | 
|     <select id="selectInPage" resultMap="SysRoleMap"> | 
|         select | 
|         role_id, | 
|         role_name, | 
|         role_remark, | 
|         company_id, | 
|         plates, | 
|         is_default, | 
|         shop_able | 
|         from sys_role | 
|         <where> | 
|             <if test="record!=null"> | 
|                 <if | 
|                     test="(record.roleId!=null and record.roleId!='') or (record.roleId!='' and record.roleId==0)"> | 
|                     and role_id = #{record.roleId} | 
|                 </if> | 
|                 <if | 
|                     test="(record.roleName!=null and record.roleName!='') or (record.roleName!='' and record.roleName==0)"> | 
|                     and role_name like concat ('%',#{record.roleName},'%') | 
|                 </if> | 
|                 <if | 
|                     test="(record.roleRemark!=null and record.roleRemark!='') or (record.roleRemark!='' and record.roleRemark==0)"> | 
|                     and role_remark = #{record.roleRemark} | 
|                 </if> | 
|                 <if  | 
|                     test="(record.companyId!=null and record.companyId!='') or (record.companyId!='' and record.companyId==0)"> | 
|                     and company_id = #{record.companyId} | 
|                 </if> | 
|                 <if | 
|                     test="(record.shopAble!=null and record.shopAble!='') or (record.shopAble!='' and record.shopAble==0)"> | 
|                     and shop_able = #{record.shopAble} | 
|                 </if> | 
|                 <if  | 
|                     test="(record.plates!=null and record.plates!='') or (record.plates!='' and record.plates==0)" > | 
|                     and plates = #{record.plates} | 
|                 </if> | 
|             </if> | 
|         </where> | 
|         <if test="pageVo !=null"><!-- 判断pageVo对象是否为空 --> | 
|             <if test="pageVo.sort !=null and pageVo.sort !='' "> | 
|                 order by | 
|                 ${pageVo.sort} ${pageVo.order} | 
|             </if> | 
|             <if test="pageVo.offset >=0  and pageVo.limit >0"> | 
|                 limit | 
|                 #{pageVo.offset},#{pageVo.limit} | 
|             </if> | 
|         </if> | 
|     </select> | 
|   | 
|     <!-- 查询总条数 --> | 
|     <select id="selectTotalRecord" parameterType="long" resultType="java.lang.Integer"> | 
|         select count(*) | 
|         from sys_role | 
|         <where> | 
|             <if test="record!=null"> | 
|                 <if | 
|                     test="(record.roleId!=null and record.roleId!='') or (record.roleId!='' and record.roleId==0)"> | 
|                     and role_id = #{record.roleId} | 
|                 </if> | 
|                 <if | 
|                     test="(record.roleName!=null and record.roleName!='') or (record.roleName!='' and record.roleName==0)"> | 
|                     and role_name like concat ('%',#{record.roleName},'%') | 
|                 </if> | 
|                 <if | 
|                         test="(record.shopAble!=null and record.shopAble!='') or (record.shopAble!='' and record.shopAble==0)"> | 
|                     and shop_able = #{record.shopAble} | 
|                 </if> | 
|                 <if | 
|                     test="(record.roleRemark!=null and record.roleRemark!='') or (record.roleRemark!='' and record.roleRemark==0)"> | 
|                     and role_remark = #{record.roleRemark} | 
|                 </if> | 
|                 <if | 
|                     test="(record.companyId!=null and record.companyId!='') or (record.companyId!='' and record.companyId==0)"> | 
|                     and company_id = #{record.companyId} | 
|                 </if> | 
|                 <if | 
|                     test="(record.plates!=null and record.plates!='') or (record.plates!='' and record.plates==0)"> | 
|                     and plates = #{record.plates} | 
|                 </if> | 
|             </if> | 
|         </where> | 
|     </select> | 
|   | 
|     <!-- 根据id查询 --> | 
|     <select id="selectById" resultMap="SysRoleMap"> | 
|         select | 
|         role_id, | 
|         role_name, | 
|         role_remark, | 
|         company_id, | 
|         plates, | 
|         is_default, | 
|         shop_able | 
|         from sys_role | 
|         where role_id=#{roleId} | 
|     </select> | 
|   | 
|   | 
|     <!-- 根据id 锁表查询 --> | 
|     <select id="selectForUpdate" resultMap="SysRoleMap"> | 
|         select | 
|         role_id, | 
|         role_name, | 
|         role_remark, | 
|         company_id, | 
|         plates, | 
|         is_default, | 
|         shop_able | 
|         from sys_role | 
|         where role_id=#{role_id} | 
|         for update | 
|     </select> | 
|   | 
|   | 
|   | 
|     <!-- 根据对象查询 --> | 
|     <select id="selectByModel" resultMap="SysRoleMap"> | 
|         select | 
|         role_id, | 
|         role_name, | 
|         role_remark, | 
|         company_id, | 
|         plates, | 
|         is_default, | 
|         shop_able | 
|         from sys_role | 
|         <where> | 
|             <if test="record!=null"> | 
|                 <if | 
|                     test="(record.roleId!=null and record.roleId!='') or (record.roleId!='' and record.roleId==0)"> | 
|                     and role_id = #{record.roleId} | 
|                 </if> | 
|                 <if | 
|                     test="(record.roleName!=null and record.roleName!='') or (record.roleName!='' and record.roleName==0)"> | 
|                     and role_name like concat ('%',#{record.roleName},'%') | 
|                 </if> | 
|                 <if | 
|                     test="(record.roleRemark!=null and record.roleRemark!='') or (record.roleRemark!='' and record.roleRemark==0)"> | 
|                     and role_remark = #{record.roleRemark} | 
|                 </if> | 
|                 <if | 
|                     test="(record.companyId!=null and record.companyId!='') or (record.companyId!='' and record.companyId==0)"> | 
|                     and company_id = #{record.companyId} | 
|                 </if> | 
|                 <if | 
|                     test="(record.plates!=null and record.plates!='') or (record.plates!='' and record.plates==0)"> | 
|                     and plates = #{record.plates} | 
|                 </if> | 
|                 <if | 
|                         test="(record.shopAble!=null and record.shopAble!='') or (record.shopAble!='' and record.shopAble==0)"> | 
|                     and shop_able = #{record.shopAble} | 
|                 </if> | 
|             </if> | 
|         </where> | 
|     </select> | 
| </mapper> |