<?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.nantian.cloud.jly.mapper.CheckEnterpriceMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.nantian.cloud.jly.entity.CheckEnterprice">
        <id column="id" property="id"/>
        <result column="check_plan_id" property="checkPlanId"/>
        <result column="com_name" property="comName"/>
        <result column="epc" property="epc"/>
        <result column="check_status" property="checkStatus"/>
        <result column="check_result" property="checkResult"/>
        <result column="check_comment" property="checkComment"/>
        <result column="comment" property="comment"/>
        <result column="part1" property="part1"/>
        <result column="part2" property="part2"/>
        <result column="part3" property="part3"/>
        <result column="part4" property="part4"/>
        <result column="part5" property="part5"/>
        <result column="check_verdict" property="checkVerdict"/>
        <result column="start_time" property="startTime"/>
        <result column="end_time" property="endTime"/>
        <result column="userid" property="userid"/>
        <result column="update_time" property="updateTime"/>
        <result column="del_flag" property="delFlag"/>
        <result column="dept_id" property="deptId"/>
        <result column="check_non_status" property="checkNonStatus"/>
        <result column="check_non_remain" property="checkNonRemain"/>
    </resultMap>

    <sql id="Base_Column_List">
        id, check_plan_id, epc, check_status, check_result, check_comment, comment,
        part1, part2, part3, part4, part5, userid, update_time, del_flag, dept_id,check_non_status,check_non_remain
    </sql>

    <resultMap id="BaseResultMapVo" type="com.nantian.cloud.jly.vo.CheckEnterpriceVo">
        <id column="id" property="id"/>
        <result column="check_plan_id" property="checkPlanId"/>
        <result column="epc" property="epc"/>
        <result column="check_status" property="checkStatus"/>
        <result column="check_result" property="checkResult"/>
        <result column="check_comment" property="checkComment"/>
        <result column="comment" property="comment"/>
        <result column="cmp_name" property="cmpName"/>
    </resultMap>

    <select id="getCheckEnterpriceByCheckPlanId" resultType="com.nantian.cloud.jly.entity.CheckEnterprice">
        SELECT o.*,i.cmp_name FROM check_enterprice o LEFT JOIN enterprise_info i ON o.epc = i.enterprise_code WHERE o.check_plan_id = #{checkPlanId} and o.del_flag = "1"
    </select>

    <select id="getCheckEnterpricePageDataByCheckPlanId" resultType="com.nantian.cloud.jly.entity.CheckEnterprice">
        SELECT o.id, o.check_plan_id, o.epc, o.com_name, o.check_type, o.check_status, o.check_result, o.check_comment, o.comment, o.part1, o.part2, o.part3, o.part4, o.part5,
        o.check_verdict, o.start_time, o.end_time, o.check_non_num, o.check_file, o.check_non_file, o.check_mend_file, o.num, o.userid, o.update_time, o.del_flag,
        o.check_non_status,o.check_non_remain,
        i.region_code dept_id, i.cmp_name, i.region_code FROM check_enterprice o
        LEFT JOIN enterprise_info i ON o.epc = i.enterprise_code WHERE o.check_plan_id = #{checkPlanId} and o.del_flag = "1"
        <if test="cmp_name != null and cmp_name!=''">
            and i.cmp_name like concat("%",#{cmp_name},"%")
        </if>
        <if test="epc != null and epc!=''">
            and o.epc =#{epc}
        </if>
        <if test="checkStatus != null and checkStatus!=''">
            and o.check_status =#{checkStatus}
        </if>
        order by o.num
    </select>

    <select id="getPageScope" resultType="com.nantian.cloud.jly.entity.CheckEnterprice">
        select
        <include refid="Base_Column_List"></include>
        from check_enterprice
        <trim prefix="where" prefixOverrides="and">
            <if test="query.checkPlanId != null">
                and check_plan_id = #{query.checkPlanId}
            </if>
            <if test="query.epc != null">
                and epc = #{query.epc}
            </if>
            <if test="query.checkStatus != null">
                and check_status = #{query.checkStatus}
            </if>
            <if test="query.checkResult != null">
                and check_result = #{query.checkResult}
            </if>
            <if test="query.checkComment != null">
                and check_comment = #{query.checkComment}
            </if>
            <if test="query.comment != null">
                and comment = #{query.comment}
            </if>
            <if test="query.part1 != null">
                and part1 = #{query.part1}
            </if>
            <if test="query.part2 != null">
                and part2 = #{query.part2}
            </if>
            <if test="query.part3 != null">
                and part3 = #{query.part3}
            </if>
            <if test="query.part4 != null">
                and part4 = #{query.part4}
            </if>
            <if test="query.part5 != null">
                and part5 = #{query.part5}
            </if>
            <if test="query.userid != null">
                and userid = #{query.userid}
            </if>
            <if test="query.delFlag != null">
                and del_flag = #{query.delFlag}
            </if>
            <if test="query.deptId != null">
                and dept_id = #{query.deptId}
            </if>
            <if test="query.checkNonStatus != null">
                and check_non_status = #{query.checkNonStatus}
            </if>
        </trim>
    </select>

    <select id="queryListByCmp" resultType="java.util.LinkedHashMap">
        SELECT e.*, i.cmp_name,i.id cmp_id,
        p.num ,
        p.report_id as planNum,
        p.name,
        p.year,
        p.check_purpose,
        p.check_method,
        p.check_type,
        p.begin_time,
        p.end_time endTime,
        o.basis_file,
        o.table_file
        FROM check_enterprice e
        LEFT JOIN enterprise_info i ON e.epc = i.enterprise_code and i.del_flag='1'
        LEFT JOIN check_plan p ON e.check_plan_id = p.id and i.del_flag='1'
        LEFT JOIN check_basis_file o ON o.check_plan_id = p.id
        WHERE e.del_flag = '1' and p.send_flag ='2'
        <if test="query.deptId != null">
            and e.dept_id = #{query.deptId}
        </if>
        <if test="query.epc != null">
            and e.epc = #{query.epc}
        </if>
        <if test="query.comment != null">
            and p.name like concat("%",#{query.comment},"%")
        </if>
    </select>

    <update id="updatecCheckStatus">
        update check_enterprice
        set check_status = #{checkStatus}
        where check_plan_id = #{checkPlanId} and epc = #{epc}
    </update>


</mapper>
