<?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.energy.manage.service.mappers.analysis.AnalysisCommentDescriptionMapper">
    <resultMap id="BaseResultMap" type="com.energy.manage.common.po.analysis.AnalysisCommentDescriptionPo">
        <id column="id" property="id" jdbcType="BIGINT"/>
        <result column="batch_code" property="batchCode" jdbcType="VARCHAR"/>
        <result column="analysis_type_code" property="analysisTypeCode" jdbcType="VARCHAR"/>
        <result column="comment_type_code" property="commentTypeCode" jdbcType="VARCHAR"/>
        <result column="comment" property="comment" jdbcType="VARCHAR"/>
        <result column="create_by" property="createBy" jdbcType="INTEGER"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
        <result column="update_by" property="updateBy" jdbcType="INTEGER"/>
        <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
    </resultMap>

    <select id="selectCountByAllCode" parameterType="java.lang.String" resultType="int">
        select count(*)
        from analysis_comment_description
        where
              batch_code = #{batchCode,jdbcType=VARCHAR}
        and   analysis_type_code = #{analysisTypeCode,jdbcType=VARCHAR}
        and   comment_type_code = #{commentTypeCode,jdbcType=VARCHAR}
    </select>

    <select id="selecByBatchCodeAndAnalysisTypeCode" parameterType="java.lang.String" resultType="com.energy.manage.service.domain.vo.analysis.AnalysisCommentDescriptionVo">
        select acd.batch_code,
               ar.analysis_name,
               acd.analysis_type_code,
               acd.comment_type_code,
               actr.comment_type_name,
               acd.comment,
               acd.create_time
        from analysis_comment_description as acd
        left join analysis_comment_type_relation as actr
        on acd.comment_type_code = actr.comment_type_code
        left join analysis_result ar
        on acd.batch_code = ar.batch_code
        <where>
            <if test="batchCode != null and batchCode != ''">
                acd.batch_code = #{batchCode,jdbcType=VARCHAR}
            </if>
            <if test="analysisTypeCode != null and analysisTypeCode != ''">
                and acd.analysis_type_code = #{analysisTypeCode,jdbcType=VARCHAR}
            </if>
        </where>
        order by acd.update_time , acd.batch_code desc
    </select>

    <insert id="insertPoSelective" parameterType="com.energy.manage.common.po.analysis.AnalysisCommentDescriptionPo">
        insert into analysis_comment_description
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="batchCode != null">
                batch_code,
            </if>
            <if test="analysisTypeCode != null">
                analysis_type_code,
            </if>
            <if test="commentTypeCode != null">
                comment_type_code,
            </if>
            <if test="comment != null">
                comment,
            </if>
            <if test="createBy != null">
                create_by,
            </if>
            <if test="updateBy != null">
                update_by
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="batchCode != null">
                #{batchCode,jdbcType=VARCHAR},
            </if>
            <if test="analysisTypeCode != null">
                #{analysisTypeCode,jdbcType=VARCHAR},
            </if>
            <if test="commentTypeCode != null">
                #{commentTypeCode,jdbcType=VARCHAR},
            </if>
            <if test="comment !=null">
                #{comment,jdbcType=VARCHAR},
            </if>
            <if test="createBy != null">
                #{createBy,jdbcType=INTEGER},
            </if>
            <if test="updateBy != null">
                #{updateBy,jdbcType=INTEGER}
            </if>
        </trim>
    </insert>
    <update id="updatePoSelective" parameterType="com.energy.manage.common.po.analysis.AnalysisCommentDescriptionPo">
        update analysis_comment_description
        <set>
            <if test="comment != null">
                comment = #{comment,jdbcType=VARCHAR},
            </if>
            <if test="updateBy != null">
                update_by = #{updateBy,jdbcType=INTEGER}
            </if>
        </set>
        where batch_code = #{batchCode,jdbcType=VARCHAR}
        and   analysis_type_code = #{analysisTypeCode,jdbcType=VARCHAR}
        and   comment_type_code = #{commentTypeCode,jdbcType=VARCHAR}
    </update>
</mapper>
