<?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.jljc.mapper.GovTargetMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.nantian.cloud.jljc.entity.GovTarget">
        <id column="id" property="id" />
        <result column="target_name" property="targetName" />
        <result column="target_unit" property="targetUnit" />
        <result column="child_unit" property="childUnit" />
        <result column="parent_unit" property="parentUnit" />
        <result column="ratio" property="ratio" />
        <result column="industry_code" property="industryCode" />
        <result column="industry_name" property="industryName" />
        <result column="astrict" property="astrict" />
        <result column="admit" property="admit" />
        <result column="advanced" property="advanced" />
        <result column="product_code" property="productCode" />
        <result column="product_name" property="productName" />
        <result column="userid" property="userid"/>
        <result column="update_time" property="updateTime"/>
        <result column="del_flag" property="delFlag"/>
        <result column="dept_id" property="deptId"/>
    </resultMap>

    <sql id="base_sql">
        id, target_name, target_unit, child_unit, parent_unit, ratio, industry_code, industry_name, astrict, admit, advanced
        ,product_code, product_name, userid, update_time, del_flag, dept_id
    </sql>

    <select id="getPageScope" resultType="com.nantian.cloud.jljc.entity.GovTarget">
        select  g.id, g.target_name, g.target_unit, g.child_unit, g.parent_unit, g.ratio, g.astrict, g.admit, g.advanced,
        g.industry_code, k.name industry_name, g.product_code, p.product_name product_name,
        g.userid, g.update_time, g.del_flag, g.dept_id
        from gov_target g
        left join trade_kind k on g.industry_code = k.code
        left join product_info p on g.product_code = p.product_num
        <trim prefix="where" prefixOverrides="and">
            <if test="query.targetName != null  and query.targetName != ''">
                and g.target_name like concat("%",#{query.targetName},"%")
            </if>
            <if test="query.industryCode != null  and query.industryCode != ''">
                and g.industry_code = #{query.industryCode}
            </if>
            <if test="query.industryName != null and query.industryName != ''">
                and k.name = #{query.industryName}
            </if>
            <if test="query.productCode != null  and query.productCode != ''">
                and g.product_code = #{query.productCode}
            </if>
            <if test="query.productName != null  and query.productName != ''">
                and p.product_name = #{query.productName}
            </if>
            <if test="query.delFlag != null  and query.delFlag != ''">
                and g.del_flag = #{query.delFlag}
            </if>
        </trim>
        order by g.astrict desc
    </select>

    <select id="getByTypeName" resultType="com.nantian.cloud.jljc.entity.GovTarget">
        select  g.id, g.target_name, g.target_unit, g.child_unit, g.parent_unit, g.ratio, g.industry_code, g.industry_name,
        g.astrict, g.admit, g.advanced, g.product_code, g.product_name, g.userid, g.update_time, g.del_flag, g.dept_id, t.id tid
        from gov_target g left join t_supervision_unit_energy_type t on g.id=t.gov_target_id
        where g.del_flag='1' and t.del_flag='1' and g.target_name like concat("%",#{name},"%")
    </select>

</mapper>
