<?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.jeeplus.modules.sg.managementcenter.activiti.mapper.DiscloseMapper">

    <sql id="constructionColumns">
		a.id AS "id",
		a.proc_ins_id AS "procInsId",
		conId,
		channel,
		capacity,
		sceneSize,
		capacitySize,
		hiddenDanger,
		influenceConstruction,
		projectRepetition,
		implemented,
		transformer,
		lineName,
		quantities,
		rodNumber,
		administrationType,
		precondition,
		placementMode,
		productionDate,
		IntegrateModule,
		needReplace,
		overallTransformation,
		otherProblem,
		explanationOfNecessity AS "explanationOfNecessity",
		inconsistentDescription AS "inconsistentDescription",
		policyHandlingInstructions AS "policyHandlingInstructions",
		a.create_by AS "createBy.id",
		a.create_date AS "createDate",
		a.update_by AS "updateBy.id",
		a.update_date AS "updateDate",
		a.remarks AS "remarks",
		a.del_flag AS "delFlag"

	</sql>

    <sql id="constructionJoins">
		LEFT JOIN sys_user updateBy ON updateBy.id = a.update_by
	</sql>

    <resultMap type="Disclose" id="ConstructionResult" autoMapping="true">
        <result column="reason" property="reason" typeHandler="com.jeeplus.core.mapper.ConvertBlobTypeHandler"/>
    </resultMap>

    <select id="get" resultMap="ConstructionResult">
        SELECT
        *
        FROM xm_disclose_conclusion a
        <include refid="constructionJoins"/>
        WHERE a.proc_ins_id = #{procInsId}
    </select>

    <select id="findList" resultMap="ConstructionResult">
        SELECT
        *
        FROM xm_disclose_conclusion a
        <include refid="constructionJoins"/>
        <where>
            a.del_flag = #{DEL_FLAG_NORMAL}
            ${dataScope}
        </where>
        <choose>
            <when test="page !=null and page.orderBy != null and page.orderBy != ''">
                ORDER BY ${page.orderBy}
            </when>
            <otherwise>
                ORDER BY a.update_date DESC
            </otherwise>
        </choose>
    </select>

    <select id="findAllList" resultMap="ConstructionResult">
        SELECT
        *
        FROM xm_disclose_conclusion a
        <include refid="constructionJoins"/>
        <where>
            a.del_flag = #{DEL_FLAG_NORMAL}
            ${dataScope}
        </where>
        <choose>
            <when test="page !=null and page.orderBy != null and page.orderBy != ''">
                ORDER BY ${page.orderBy}
            </when>
            <otherwise>
                ORDER BY a.update_date DESC
            </otherwise>
        </choose>
    </select>

    <insert id="insert">
		INSERT INTO xm_disclose_conclusion(
			id,
			proc_ins_id,
			conId,
			channel,
			capacity,
			sceneSize,
			capacitySize,
			hiddenDanger,
			influenceConstruction,
			projectRepetition,
			implemented,
			transformer,
			lineName,
			quantities,
			rodNumber,
			administrationType,
			precondition,
			placementMode,
			productionDate,
			IntegrateModule,
			needReplace,
			overallTransformation,
			explanationOfNecessity,
			inconsistentDescription,
			policyHandlingInstructions,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag
		) VALUES (
			#{id},
			#{procInsId},
			#{conId},
			#{channel},
			#{capacity},
			#{sceneSize},
			#{capacitySize},
			#{hiddenDanger},
			#{influenceConstruction},
			#{projectRepetition},
			#{implemented},
			#{transformer},
			#{lineName},
			#{quantities},
			#{rodNumber},
			#{administrationType},
			#{precondition},
			#{placementMode},
			#{productionDate},
			#{IntegrateModule},
			#{needReplace},
			#{overallTransformation},
			#{explanationOfNecessity},
			#{inconsistentDescription},
			#{policyHandlingInstructions},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag}
		)
	</insert>

    <update id="update">
		UPDATE xm_disclose_conclusion SET
			proc_ins_id = #{procInsId},
			conId=#{conId},
			channel = #{channel},
			capacity = #{capacity},
			sceneSize = #{sceneSize},
			capacitySize = #{capacitySize},
			hiddenDanger = #{hiddenDanger},
			influenceConstruction = #{influenceConstruction},
			projectRepetition = #{projectRepetition},
			implemented = #{implemented},
			transformer = #{transformer},
			lineName = #{lineName},
			quantities = #{quantities},
			rodNumber = #{rodNumber},
			administrationType = #{administrationType},
			precondition = #{precondition},
			placementMode = #{placementMode},
			productionDate = #{productionDate},
			IntegrateModule = #{IntegrateModule},
			needReplace = #{needReplace},
			overallTransformation = #{overallTransformation},
			explanationOfNecessity = #{explanationOfNecessity},
			inconsistentDescription = #{inconsistentDescription},
			policyHandlingInstructions = #{policyHandlingInstructions},
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			remarks = #{remarks}
		WHERE proc_ins_id = #{procInsId}
	</update>
    <update id="updateById">
		UPDATE xm_disclose_conclusion SET
			proc_ins_id = #{procInsId},
			conId = #{conId},
			projectNumber= #{projectNumber},
			projectName= #{projectName},
			projectId= #{projectId},
			channel= #{channel},
			capacity = #{capacity},
			sceneSize = #{sceneSize},
			capacitySize = #{capacitySize},
			hiddenDanger = #{hiddenDanger},
			influenceConstruction = #{influenceConstruction},
			projectRepetition = #{projectRepetition},
			implemented = #{implemented},
			transformer = #{transformer},
			explanationOfNecessity = #{explanationOfNecessity},
			lineName = #{lineName},
			quantities = #{quantities},
			rodNumber = #{rodNumber},
			inconsistentDescription = #{inconsistentDescription},
			administrationType = #{administrationType},
			precondition = #{precondition},
			policyHandlingInstructions = #{policyHandlingInstructions},
			placementMode = #{placementMode},
			productionDate = #{productionDate},
			IntegrateModule = #{IntegrateModule},
			needReplace = #{needReplace},
			overallTransformation = #{overallTransformation},
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			remarks = #{remarks},
			otherProblem=#{otherProblem}
		WHERE proc_ins_id = #{procInsId};
	</update>


    <!--物理删除-->
    <update id="delete">
		DELETE FROM xm_disclose_conclusion
		WHERE id = #{id}
	</update>

    <!--逻辑删除-->
    <update id="deleteByLogic">
		UPDATE xm_disclose_conclusion SET
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>


    <!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
    <select id="findUniqueByProperty" resultType="OALeave" statementType="STATEMENT">
		select * FROM xm_disclose_conclusion  where ${propertyName} = '${value}'
	</select>


    <insert id="newInsert" parameterType="java.util.List">
        replace into xm_disclose_conclusion(
        id,
        proc_ins_id,
        conId,
        requireName,
        projectNumber,
        projectName,
        projectId,
        channel,
        capacity,
        sceneSize,
        capacitySize,
        hiddenDanger,
        influenceConstruction,
        projectRepetition,
        implemented,
        transformer,
        explanationOfNecessity,
        lineName,
        quantities,
        rodNumber,
        inconsistentDescription,
        administrationType,
        precondition,
        policyHandlingInstructions,
        placementMode,
        productionDate,
        IntegrateModule,
        needReplace,
        overallTransformation,
		otherProblem,
		implementedContent,
        create_by,
        create_date,
        update_by,
        update_date,
        remarks,
        del_flag
        ) VALUES
        <foreach collection="disclose" item="item" index="index" separator=",">
            (
            #{item.id},
            #{item.procInsId},
            #{item.conId},
            #{item.requireName},
            #{item.projectNumber},
            #{item.projectName},
            #{item.projectId},
            #{item.channel},
            #{item.capacity},
            #{item.sceneSize},
            #{item.capacitySize},
            #{item.hiddenDanger},
            #{item.influenceConstruction},
            #{item.projectRepetition},
            #{item.implemented},
            #{item.transformer},
            #{item.explanationOfNecessity},
            #{item.lineName},
            #{item.quantities},
            #{item.rodNumber},
            #{item.inconsistentDescription},
            #{item.administrationType},
            #{item.precondition},
            #{item.policyHandlingInstructions},
            #{item.placementMode},
            #{item.productionDate},
            #{item.IntegrateModule},
            #{item.needReplace},
            #{item.overallTransformation},
            #{item.otherProblem},
            '',
            #{item.createBy.id},
            #{item.createDate},
            #{item.updateBy.id},
            #{item.updateDate},
            #{item.remarks},
            #{item.delFlag}
            )
        </foreach>

    </insert>
	<select id="findByProcInsId" resultType="java.lang.Integer">
		select count(*) from xm_disclose_conclusion where proc_ins_id = #{procInsId};
	</select>

	<update id="updateDiscloseByProcInsId">
		update xm_disclose_conclusion set
			otherProblem = #{disclose.otherProblem},
			inconsistentDescription = #{disclose.inconsistentDescription},
			policyHandlingInstructions = #{disclose.policyHandlingInstructions},
			implementedContent = #{disclose.implementedContent},
			administrationType = #{administrationType}
		where proc_ins_id = #{procInsId};
	</update>

	<insert id="insertDiscloseRole">
		insert into xm_disclose_conclusion
		(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag,
			proc_ins_id,
			otherProblem,
			inconsistentDescription,
			policyHandlingInstructions,
			implementedContent,
			administrationType
		)
		values
		(
			#{id},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag},
			#{procInsId},
			#{disclose.otherProblem},
			#{disclose.inconsistentDescription},
			#{disclose.policyHandlingInstructions},
			#{disclose.implementedContent},
			#{administrationType}
		);
	</insert>

</mapper>