<?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.ConfigureGaugeVerifyMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.nantian.cloud.jly.entity.ConfigureGaugeVerify">
        <id column="id" property="id" />
        <result column="enterprise_code" property="enterpriseCode" />
        <result column="ser_no" property="serNo" />
        <result column="manage_no" property="manageNo" />
        <result column="bar_code" property="barCode" />
        <result column="verify_org" property="verifyOrg" />
        <result column="verify_time" property="verifyTime" />
        <result column="state" property="state" />
        <result column="remark" property="remark" />
        <result column="userid" property="userid" />
        <result column="update_time" property="updateTime" />
        <result column="del_flag" property="delFlag" />
        <result column="dept_id" property="deptId" />
    </resultMap>

    <resultMap id="BaseResultMapVo" type="com.nantian.cloud.jly.vo.ConfigureGaugeVerifyVo">
        <id column="id" property="id" />
        <result column="enterprise_code" property="enterpriseCode" />
        <result column="ser_no" property="serNo" />
        <result column="manage_no" property="manageNo" />
        <result column="bar_code" property="barCode" />
        <result column="verify_org" property="verifyOrg" />
        <result column="verify_time" property="verifyTime" />
        <result column="state" property="state" />
        <result column="remark" property="remark" />
        <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="cmpName" property="cmpName" />
        <result column="regionCode" property="regionCode" />
        <result column="countyId" property="countyId" />
        <result column="countyName" property="countyName" />
        <result column="cityId" property="cityId" />
        <result column="cityName" property="cityName" />
        <result column="provinceId" property="provinceId" />
        <result column="provinceName" property="provinceName" />
    </resultMap>

    <update id="updateGaugeVerify">
        update configure_gauge_verify
        set ser_no = #{o.serNo}, manage_no = #{o.manageNo}, bar_code=#{o.barCode},
        verify_org=#{o.verifyOrg}, verify_time=#{o.verifyTime}, state=#{o.state},
        remark=#{o.remark},userid=#{o.userid},update_time=#{o.updateTime},del_flag=#{o.delFlag},dept_id=#{o.deptId}
        where id = #{o.id}
    </update>

    <select id="getPageData" resultType="com.nantian.cloud.jly.vo.ConfigureGaugeVerifyVo">
        SELECT o.*,i.cmp_name as cmpName,i.region_code as regionCode,r.id AS countyId,r.meaning AS countyName,
        dr.id AS cityId,dr.meaning AS cityName,dir.id AS provinceId,dir.meaning AS provinceName FROM configure_gauge_verify o
        LEFT JOIN enterprise_info i ON o.enterprise_code = i.enterprise_code
        LEFT JOIN dict_region r ON r.id = i.region_code
        LEFT JOIN dict_region dr ON dr.id = r.pid
        LEFT JOIN dict_region dir ON dir.id = dr.pid and o.del_flag = "1"
        <trim prefix="where"  prefixOverrides="and">
            <if test="flag == 3 and code != null and code != ''">
                AND i.region_code = #{code}
            </if>
            <if test="flag == 2 and code != null and code != ''">
                AND dr.id = #{code}
            </if>
            <if test="flag == 1 and code != null and code != ''">
                AND dir.id = #{code}
            </if>
            <if test="industryCode != null and industryCode != ''">
                AND i.t_id = #{industryCode}
            </if>
            <if test="cmpName != null and cmpName != ''">
                AND i.cmp_name LIKE CONCAT('%',#{cmpName},'%')
            </if>
            <if test="cmp != null and cmp != ''">
                AND o.enterprise_code = #{cmp}
            </if>
        </trim>
    </select>

    <select id="pageCmp" resultType="com.nantian.cloud.jly.entity.ConfigureGaugeVerify">
        select * from configure_gauge_verify
        <trim prefix="where"  prefixOverrides="and">
            <if test="query.verifyOrg != null and query.verifyOrg != ''">
                AND verify_org LIKE CONCAT('%',#{query.verifyOrg},'%')
            </if>
            <if test="query.manageNo != null and query.manageNo != ''">
                AND manage_no LIKE CONCAT('%',#{query.manageNo},'%')
            </if>
            <if test="query.enterpriseCode != null and query.enterpriseCode != ''">
                AND enterprise_code = #{query.enterpriseCode}
            </if>
            <if test="query.delFlag != null and query.delFlag != ''">
                AND del_flag = #{query.delFlag}
            </if>
        </trim>
    </select>

</mapper>
