<?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.AnalysisCommentTypeRelationMapper">
    <resultMap id="BaseResultMap" type="com.energy.manage.common.po.analysis.AnalysisCommentTypeRelationPo">
        <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_type_name" property="commentTypeName" jdbcType="VARCHAR"/>
        <result column="is_defined" property="isDefined" jdbcType="INTEGER"/>
        <result column="is_delete" property="isDelete" jdbcType="INTEGER"/>
        <result column="create_by" property="createBy" jdbcType="INTEGER"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
    </resultMap>

    <select id="selectByAnalysisTypeCode" parameterType="java.lang.String" resultType="com.energy.manage.service.domain.vo.analysis.AnalysisCommentTypeRelationVo">
        select
            comment_type_code,
            comment_type_name,
            is_defined
        from analysis_comment_type_relation
        where is_delete = 0
          and ((batch_code = #{batchCode,jdbcType=VARCHAR}
                and analysis_type_code = #{analysisTypeCode,jdbcType=VARCHAR})
                or is_defined = 0
              )
    </select>

    <select id="selectByTypeCode" parameterType="java.lang.String" resultType="com.energy.manage.service.domain.vo.analysis.AnalysisCommentTypeRelationVo">
        select
            comment_type_code,
            comment_type_name,
            is_defined
        from analysis_comment_type_relation
        where is_delete = 0
        and is_defined = 1
        and comment_type_code = #{commentTypeCode,jdbcType=VARCHAR}
    </select>

    <insert id="insertPoSelective" parameterType="com.energy.manage.service.domain.dto.analysis.AnalysisCommentTypeRelationDto">
        insert into analysis_comment_type_relation
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="batchCode != null and batchCode != ''">
                batch_code,
            </if>
            <if test="analysisTypeCode != null and analysisTypeCode != ''">
                analysis_type_code,
            </if>
            <if test="commentTypeCode != null and commentTypeCode != ''">
                comment_type_code,
            </if>
            <if test="commentTypeName != null and commentTypeName != ''">
                comment_type_name,
            </if>
            <if test="createBy != null">
                create_by
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="batchCode != null and batchCode != ''">
                #{batchCode,jdbcType=VARCHAR},
            </if>
            <if test="analysisTypeCode != null and analysisTypeCode != ''">
                #{analysisTypeCode,jdbcType=VARCHAR},
            </if>
            <if test="commentTypeCode != null and commentTypeCode != ''">
                #{commentTypeCode,jdbcType=VARCHAR},
            </if>
            <if test="commentTypeName != null and commentTypeName != ''">
                #{commentTypeName,jdbcType=VARCHAR},
            </if>
           <if test="createBy != null">
                #{createBy,jdbcType=INTEGER}
            </if>
        </trim>
    </insert>

    <update id="deleteByTypeCode" parameterType="java.lang.String">
        update analysis_comment_type_relation
        set is_delete = 1
        where comment_type_code = #{commentTypeCode,jdbcType=VARCHAR}
    </update>
</mapper>
