McOperationLogMapper.xml 9.67 KB
<?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.chinagas.modules.schsf.mapper.McOperationLogMapper">
    <resultMap type="com.chinagas.modules.schsf.domain.McOperationLog" id="McOperationLogResult">
        <result property="id" column="id"/>
        <result property="dataForm" column="data_form"/>
        <result property="dataId" column="data_id"/>
        <result property="procRole" column="proc_role"/>
        <result property="procUser" column="proc_user"/>
        <result property="procTime" column="proc_time"/>
        <result property="procAccount" column="proc_account"/>
        <result property="opName" column="op_name"/>
        <result property="opType" column="op_type"/>
        <result property="opRemark" column="op_remark"/>
        <result property="beforeDataJson" column="before_data_json"/>
        <result property="afterDataJson" column="after_data_json"/>
        <result property="procId" column="proc_id"/>
    </resultMap>

    <sql id="selectMcOperationLogVo">
        select id,
               data_form,
               data_id,
               proc_role,
               proc_user,
               proc_time,
               proc_account,
               op_name,
               op_type,
               op_remark,
               before_data_json,
               after_data_json,
               proc_id
        from mc_operation_log
    </sql>

    <select id="selectMcOperationLogList" parameterType="com.chinagas.modules.schsf.domain.McOperationLog"
            resultMap="McOperationLogResult">
        <include refid="selectMcOperationLogVo"/>
        <where>
            <if test="dataForm != null  and dataForm != ''">
                and data_form = #{dataForm}
            </if>
            <if test="dataId != null">
                and data_id = #{dataId}
            </if>
            <if test="procRole != null  and procRole != ''">
                and proc_role = #{procRole}
            </if>
            <if test="procUser != null  and procUser != ''">
                and proc_user = #{procUser}
            </if>
            <if test="procTime != null">
                and proc_time = #{procTime}
            </if>
            <if test="procAccount != null  and procAccount != ''">
                and proc_account = #{procAccount}
            </if>
            <if test="opName != null  and opName != ''">
                and op_name like concat('%', #{opName}, '%')
            </if>
            <if test="opType != null  and opType != ''">
                and op_type = #{opType}
            </if>
            <if test="opRemark != null  and opRemark != ''">
                and op_remark = #{opRemark}
            </if>
            <if test="beforeDataJson != null  and beforeDataJson != ''">
                and before_data_json = #{beforeDataJson}
            </if>
            <if test="afterDataJson != null  and afterDataJson != ''">
                and after_data_json = #{afterDataJson}
            </if>
            <if test="procId != null  and procId != ''">
                and proc_id = #{procId}
            </if>
        </where>
        order by proc_time desc
    </select>

    <insert id="insertMcOperationLog" parameterType="com.chinagas.modules.schsf.domain.McOperationLog">
        insert into mc_operation_log
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">
                id,
            </if>
            <if test="dataForm != null and dataForm != ''">
                data_form,
            </if>
            <if test="dataId != null">
                data_id,
            </if>
            <if test="procRole != null">
                proc_role,
            </if>
            <if test="procUser != null and procUser != ''">
                proc_user,
            </if>
            <if test="procTime != null">
                proc_time,
            </if>
            <if test="procAccount != null and procAccount != ''">
                proc_account,
            </if>
            <if test="opName != null">
                op_name,
            </if>
            <if test="opType != null">
                op_type,
            </if>
            <if test="opRemark != null">
                op_remark,
            </if>
            <if test="beforeDataJson != null">
                before_data_json,
            </if>
            <if test="afterDataJson != null">
                after_data_json,
            </if>
            <if test="procId != null">
                proc_id,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">
                #{id},
            </if>
            <if test="dataForm != null and dataForm != ''">
                #{dataForm},
            </if>
            <if test="dataId != null">
                #{dataId},
            </if>
            <if test="procRole != null">
                #{procRole},
            </if>
            <if test="procUser != null and procUser != ''">
                #{procUser},
            </if>
            <if test="procTime != null">
                #{procTime},
            </if>
            <if test="procAccount != null and procAccount != ''">
                #{procAccount},
            </if>
            <if test="opName != null">
                #{opName},
            </if>
            <if test="opType != null">
                #{opType},
            </if>
            <if test="opRemark != null">
                #{opRemark},
            </if>
            <if test="beforeDataJson != null">
                #{beforeDataJson},
            </if>
            <if test="afterDataJson != null">
                #{afterDataJson},
            </if>
            <if test="procId != null">
                #{procId},
            </if>
        </trim>
    </insert>

    <select id="getUserMenuPermsByRoles" resultType="String" parameterType="String">
        SELECT DISTINCT r.role_name as roleName
        FROM (SELECT role.role_name
              FROM sys_menu menu
                       INNER JOIN sys_role_menu roleMenu on roleMenu.menu_id = menu.menu_id
                       INNER JOIN sys_role role on role.role_id = roleMenu.role_id
                       INNER JOIN sys_user_role userRole on userRole.role_id = role.role_id
                       INNER JOIN sys_user us on us.user_id = userRole.user_id
              WHERE role.data_scope = '1'
                and menu.perms = #{menuPerms}
                AND us.user_id = #{userId}
              UNION
              SELECT role.role_name
              FROM sys_menu menu
                       INNER JOIN sys_role_menu roleMenu on roleMenu.menu_id = menu.menu_id
                       INNER JOIN sys_role role on role.role_id = roleMenu.role_id
                       INNER JOIN sys_user_role userRole on userRole.role_id = role.role_id
                       INNER JOIN sys_user us on us.user_id = userRole.user_id
                       INNER JOIN sys_user_dept userDept on userDept.user_id = us.user_id and userDept.dept_id =
                                                                                              (SELECT company_code FROM mc_visit WHERE id = #{dataId})
                       INNER JOIN mc_visit visit on visit.company_code = userDept.dept_id
              WHERE role.data_scope = '3'
                and menu.perms = #{menuPerms}
                AND us.user_id = #{userId}
              UNION
              SELECT role.role_name
              FROM sys_menu menu
                       INNER JOIN sys_role_menu roleMenu on roleMenu.menu_id = menu.menu_id
                       INNER JOIN sys_role role on role.role_id = roleMenu.role_id
                       INNER JOIN sys_user_role userRole on userRole.role_id = role.role_id
                       INNER JOIN sys_user us on us.user_id = userRole.user_id
                       INNER JOIN sys_user_dept userDept on userDept.user_id = us.user_id
                       INNER JOIN sys_dept dept on dept.dept_id = userDept.dept_id
                       INNER JOIN sys_dept dept2 on dept2.dept_id in (SELECT a.dept_id
                                                                      FROM sys_dept a
                                                                      WHERE a.dept_id = dept.dept_id
                                                                         or find_in_set(dept.parent_id, ancestors))
                  and dept2.dept_id = (SELECT company_code FROM mc_visit WHERE id = #{dataId})
              WHERE role.data_scope = '4'
                and menu.perms = #{menuPerms}
                AND us.user_id = #{userId}
              UNION
              SELECT role.role_name
              FROM sys_menu menu
                       INNER JOIN sys_role_menu roleMenu on roleMenu.menu_id = menu.menu_id
                       INNER JOIN sys_role role on role.role_id = roleMenu.role_id
                       INNER JOIN sys_user_role userRole on userRole.role_id = role.role_id and userRole.user_id =
                                                                                                (SELECT create_by FROM mc_visit WHERE id = #{dataId})
              WHERE role.data_scope = '5'
                and menu.perms = #{menuPerms}
                AND userRole.user_id = #{userId}) r
    </select>

    <select id="selectMcOperationLogNewYdById" parameterType="com.chinagas.modules.schsf.domain.McOperationLog"
            resultMap="McOperationLogResult">
        <include refid="selectMcOperationLogVo"/>
        WHERE 1=1
        and id =(
        SELECT max(a.id)
        FROM mc_operation_log a
        WHERE a.op_type = #{opType}and a.data_id=#{dataId} and a.op_name= #{opName}
        )
    </select>
</mapper>