<?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.ruoyi.rocketmq.mapper.RmDeploymentPolicyMapper">

    <resultMap type="RmDeploymentPolicy" id="RmDeploymentPolicyResult">
        <result property="id"    column="id"    />
        <result property="policyName"    column="policy_name"    />
        <result property="description"    column="description"    />
        <result property="resourceGroupId"    column="resource_group_id"    />
        <result property="includedDevicesId"    column="included_devices_id"    />
        <result property="sourceFilePathType"    column="source_file_path_type"    />
        <result property="sourceFilePath"    column="source_file_path"    />
        <result property="targetDirectory"    column="target_directory"    />
        <result property="commandContent"    column="command_content"    />
        <result property="executionMethod"    column="execution_method"    />
        <result property="scheduledTime"    column="scheduled_time"    />
        <result property="policyStatus"    column="policy_status"    />
        <result property="deployTime"    column="deploy_time"    />
        <result property="scriptType"    column="script_type"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
        <result property="deployDevice"    column="deploy_device"    />
        <result property="scriptName"    column="script_name"    />
        <result property="scriptPath"    column="script_path"    />
        <result property="defaultParams"    column="default_params"    />
        <result property="taskName"    column="task_name"    />
    </resultMap>

    <sql id="selectRmDeploymentPolicyVo">
        select id, policy_name, description, resource_group_id, included_devices_id, source_file_path_type, source_file_path, target_directory, command_content, execution_method, scheduled_time, policy_status, deploy_time, script_type, create_time, update_time, create_by, update_by, deploy_device, script_name, script_path, default_params, task_name from rm_deployment_policy
    </sql>

    <select id="selectRmDeploymentPolicyList" parameterType="RmDeploymentPolicy" resultMap="RmDeploymentPolicyResult">
        <include refid="selectRmDeploymentPolicyVo"/>
        <where>
            <if test="policyName != null  and policyName != ''"> and policy_name like concat('%', #{policyName}, '%')</if>
            <if test="description != null  and description != ''"> and description = #{description}</if>
            <if test="resourceGroupId != null "> and resource_group_id = #{resourceGroupId}</if>
            <if test="includedDevicesId != null  and includedDevicesId != ''"> and included_devices_id = #{includedDevicesId}</if>
            <if test="sourceFilePathType != null  and sourceFilePathType != ''"> and source_file_path_type = #{sourceFilePathType}</if>
            <if test="sourceFilePath != null  and sourceFilePath != ''"> and source_file_path = #{sourceFilePath}</if>
            <if test="targetDirectory != null  and targetDirectory != ''"> and target_directory = #{targetDirectory}</if>
            <if test="commandContent != null  and commandContent != ''"> and command_content = #{commandContent}</if>
            <if test="executionMethod != null "> and execution_method = #{executionMethod}</if>
            <if test="scheduledTime != null "> and scheduled_time = #{scheduledTime}</if>
            <if test="policyStatus != null  and policyStatus != ''"> and policy_status = #{policyStatus}</if>
            <if test="deployTime != null "> and deploy_time = #{deployTime}</if>
            <if test="scriptType != null  and scriptType != ''"> and script_type = #{scriptType}</if>
            <if test="deployDevice != null  and deployDevice != ''"> and deploy_device = #{deployDevice}</if>
            <if test="scriptName != null  and scriptName != ''"> and script_name like concat('%', #{scriptName}, '%')</if>
            <if test="scriptPath != null  and scriptPath != ''"> and script_path = #{scriptPath}</if>
            <if test="defaultParams != null  and defaultParams != ''"> and default_params = #{defaultParams}</if>
            <if test="taskName != null  and taskName != ''"> and task_name like concat('%', #{taskName}, '%')</if>
        </where>
        order by create_time desc
    </select>

    <select id="selectRmDeploymentPolicyById" parameterType="Long" resultMap="RmDeploymentPolicyResult">
        <include refid="selectRmDeploymentPolicyVo"/>
        where id = #{id}
    </select>

    <insert id="insertRmDeploymentPolicy" parameterType="RmDeploymentPolicy" useGeneratedKeys="true" keyProperty="id">
        insert into rm_deployment_policy
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="policyName != null and policyName != ''">policy_name,</if>
            <if test="description != null">description,</if>
            <if test="resourceGroupId != null">resource_group_id,</if>
            <if test="includedDevicesId != null">included_devices_id,</if>
            <if test="sourceFilePathType != null">source_file_path_type,</if>
            <if test="sourceFilePath != null and sourceFilePath != ''">source_file_path,</if>
            <if test="targetDirectory != null and targetDirectory != ''">target_directory,</if>
            <if test="commandContent != null">command_content,</if>
            <if test="executionMethod != null">execution_method,</if>
            <if test="scheduledTime != null">scheduled_time,</if>
            <if test="policyStatus != null and policyStatus != ''">policy_status,</if>
            <if test="deployTime != null">deploy_time,</if>
            <if test="scriptType != null">script_type,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="deployDevice != null">deploy_device,</if>
            <if test="scriptName != null">script_name,</if>
            <if test="scriptPath != null">script_path,</if>
            <if test="defaultParams != null">default_params,</if>
            <if test="taskName != null">task_name,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="policyName != null and policyName != ''">#{policyName},</if>
            <if test="description != null">#{description},</if>
            <if test="resourceGroupId != null">#{resourceGroupId},</if>
            <if test="includedDevicesId != null">#{includedDevicesId},</if>
            <if test="sourceFilePathType != null">#{sourceFilePathType},</if>
            <if test="sourceFilePath != null and sourceFilePath != ''">#{sourceFilePath},</if>
            <if test="targetDirectory != null and targetDirectory != ''">#{targetDirectory},</if>
            <if test="commandContent != null">#{commandContent},</if>
            <if test="executionMethod != null">#{executionMethod},</if>
            <if test="scheduledTime != null">#{scheduledTime},</if>
            <if test="policyStatus != null and policyStatus != ''">#{policyStatus},</if>
            <if test="deployTime != null">#{deployTime},</if>
            <if test="scriptType != null">#{scriptType},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="deployDevice != null">#{deployDevice},</if>
            <if test="scriptName != null">#{scriptName},</if>
            <if test="scriptPath != null">#{scriptPath},</if>
            <if test="defaultParams != null">#{defaultParams},</if>
            <if test="taskName != null">#{taskName},</if>
        </trim>
    </insert>

    <update id="updateRmDeploymentPolicy" parameterType="RmDeploymentPolicy">
        update rm_deployment_policy
        <trim prefix="SET" suffixOverrides=",">
            <if test="policyName != null and policyName != ''">policy_name = #{policyName},</if>
            <if test="description != null">description = #{description},</if>
            <if test="resourceGroupId != null">resource_group_id = #{resourceGroupId},</if>
            <if test="includedDevicesId != null">included_devices_id = #{includedDevicesId},</if>
            <if test="sourceFilePathType != null">source_file_path_type = #{sourceFilePathType},</if>
            <if test="sourceFilePath != null and sourceFilePath != ''">source_file_path = #{sourceFilePath},</if>
            <if test="targetDirectory != null and targetDirectory != ''">target_directory = #{targetDirectory},</if>
            <if test="commandContent != null">command_content = #{commandContent},</if>
            <if test="executionMethod != null">execution_method = #{executionMethod},</if>
            <if test="scheduledTime != null">scheduled_time = #{scheduledTime},</if>
            <if test="policyStatus != null and policyStatus != ''">policy_status = #{policyStatus},</if>
            <if test="deployTime != null">deploy_time = #{deployTime},</if>
            <if test="scriptType != null">script_type = #{scriptType},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="deployDevice != null">deploy_device = #{deployDevice},</if>
            <if test="scriptName != null">script_name = #{scriptName},</if>
            <if test="scriptPath != null">script_path = #{scriptPath},</if>
            <if test="defaultParams != null">default_params = #{defaultParams},</if>
            <if test="taskName != null">task_name = #{taskName},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteRmDeploymentPolicyById" parameterType="Long">
        delete from rm_deployment_policy where id = #{id}
    </delete>

    <delete id="deleteRmDeploymentPolicyByIds" parameterType="String">
        delete from rm_deployment_policy where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <select id="selectRmDeploymentPolicyByClientId" parameterType="RmDeploymentPolicy" resultMap="RmDeploymentPolicyResult">
        <include refid="selectRmDeploymentPolicyVo"/>
        <where>
            <if test="policyStatus != null  and policyStatus != ''"> and policy_status = #{policyStatus}</if>
            <if test="deployDevice != null ">
                and FIND_IN_SET(#{deployDevice}, REPLACE(deploy_device, '\n', ',')) > 0
            </if>
        </where>
    </select>
</mapper>