<?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="cn.timer.api.dao.qyzx.QyzxEntInfoMMapper">

    <resultMap id="BaseResultMap" type="cn.timer.api.bean.qyzx.QyzxEntInfoM" >
                <id column="id" property="id" />
                <result column="name" property="name" />
                <result column="intro" property="intro" />
                <result column="oper_name" property="operName" />
                <result column="size" property="size" />
                <result column="phone" property="phone" />
                <result column="work_address" property="workAddress" />
                <result column="codes" property="codes" />
                <result column="logo_url" property="logoUrl" />
                <result column="industry_type" property="industryType" />
                <result column="open_channel" property="openChannel" />
                <result column="link_man" property="linkMan" />
                <result column="link_man_phone" property="linkManPhone" />
                <result column="credit_code" property="creditCode" />
                <result column="is_on_stock" property="isOnStock" />
                <result column="level" property="level" />
                <result column="register_time" property="registerTime" />
                <result column="license_url" property="licenseUrl" />
                <result column="area" property="area" />
                <result column="attest_name" property="attestName" />
                <result column="attest_status" property="attestStatus" />
                <result column="attest_time" property="attestTime" />
    </resultMap>

    <sql id="Base_Column_List">
                id,
                name,
                intro,
                oper_name,
                size,
                phone,
                work_address,
                codes,
                logo_url,
                industry_type,
                open_channel,
                link_man,
                link_man_phone,
                credit_code,
                is_on_stock,
                level,
                register_time,
                license_url,
                area,
                attest_name,
                attest_status,
                attest_time
    </sql>

	<!--

    <insert id="insert" useGeneratedKeys="true" keyColumn="id" parameterType="cn.timer.api.bean.qyzx.QyzxEntInfoM">
        INSERT INTO qyzx_ent_info_m
        <trim prefix="(" suffix=")" suffixOverrides=",">
                        <if test ='null != name'>
                        name,
                        </if>
                        <if test ='null != intro'>
                        intro,
                        </if>
                        <if test ='null != operName'>
                        oper_name,
                        </if>
                        <if test ='null != size'>
                        size,
                        </if>
                        <if test ='null != phone'>
                        phone,
                        </if>
                        <if test ='null != workAddress'>
                        work_address,
                        </if>
                        <if test ='null != codes'>
                        codes,
                        </if>
                        <if test ='null != logoUrl'>
                        logo_url,
                        </if>
                        <if test ='null != industryType'>
                        industry_type,
                        </if>
                        <if test ='null != openChannel'>
                        open_channel,
                        </if>
                        <if test ='null != linkMan'>
                        link_man,
                        </if>
                        <if test ='null != linkManPhone'>
                        link_man_phone,
                        </if>
                        <if test ='null != creditCode'>
                        credit_code,
                        </if>
                        <if test ='null != isOnStock'>
                        is_on_stock,
                        </if>
                        <if test ='null != registerTime'>
                        register_time
                        </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                        <if test ='null != name'>
                        #{name},
                        </if>
                        <if test ='null != intro'>
                        #{intro},
                        </if>
                        <if test ='null != operName'>
                        #{operName},
                        </if>
                        <if test ='null != size'>
                        #{size},
                        </if>
                        <if test ='null != phone'>
                        #{phone},
                        </if>
                        <if test ='null != workAddress'>
                        #{workAddress},
                        </if>
                        <if test ='null != codes'>
                        #{codes},
                        </if>
                        <if test ='null != logoUrl'>
                        #{logoUrl},
                        </if>
                        <if test ='null != industryType'>
                        #{industryType},
                        </if>
                        <if test ='null != openChannel'>
                        #{openChannel},
                        </if>
                        <if test ='null != linkMan'>
                        #{linkMan},
                        </if>
                        <if test ='null != linkManPhone'>
                        #{linkManPhone},
                        </if>
                        <if test ='null != creditCode'>
                        #{creditCode},
                        </if>
                        <if test ='null != isOnStock'>
                        #{isOnStock},
                        </if>
                        <if test ='null != registerTime'>
                        #{registerTime}
                        </if>
        </trim>
    </insert>

    <delete id="delete" >
        DELETE FROM qyzx_ent_info_m
        WHERE id = #{id}
    </delete>

    <update id="update" parameterType="cn.timer.api.bean.qyzx.QyzxEntInfoM">
        UPDATE qyzx_ent_info_m
        <set>
                    <if test ='null != name'>name = #{name},</if>
                    <if test ='null != intro'>intro = #{intro},</if>
                    <if test ='null != operName'>oper_name = #{operName},</if>
                    <if test ='null != size'>size = #{size},</if>
                    <if test ='null != phone'>phone = #{phone},</if>
                    <if test ='null != workAddress'>work_address = #{workAddress},</if>
                    <if test ='null != codes'>codes = #{codes},</if>
                    <if test ='null != logoUrl'>logo_url = #{logoUrl},</if>
                    <if test ='null != industryType'>industry_type = #{industryType},</if>
                    <if test ='null != openChannel'>open_channel = #{openChannel},</if>
                    <if test ='null != linkMan'>link_man = #{linkMan},</if>
                    <if test ='null != linkManPhone'>link_man_phone = #{linkManPhone},</if>
                    <if test ='null != creditCode'>credit_code = #{creditCode},</if>
                    <if test ='null != isOnStock'>is_on_stock = #{isOnStock},</if>
                    <if test ='null != registerTime'>register_time = #{registerTime}</if>
        </set>
        WHERE id = #{id}
    </update>


    <select id="load" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List" />
        FROM qyzx_ent_info_m
        WHERE id = #{id}
    </select>

    <select id="pageList" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List" />
        FROM qyzx_ent_info_m
        LIMIT #{offset}, #{pageSize}
    </select>

    <select id="pageListCount" resultType="java.lang.Integer">
        SELECT count(1)
        FROM qyzx_ent_info_m
    </select>

	 -->
    <select id="companyAdminList" resultType="cn.timer.api.dto.qyzx.EntInfoDto">
        SELECT
        qeim.id AS id,
        qeim.logo_url AS logoUrl,
        qeim.NAME AS NAME,
        qeim.link_man AS linkMan,
        qeim.phone AS linkManPhone,
        qeim.area_name AS areaName,
        count( yme.id ) AS totalNum,
        qeim.register_time AS registerTime,
        qeim.end_time AS endTime,
        IFNULL(a.totlaSpmk,0) as totlaSpmk,
        IFNULL(b.totlaCc,0) as totlaCc
        FROM
        qyzx_ent_info_m qeim
        LEFT JOIN yggl_main_emp yme ON yme.org_code = qeim.id
        LEFT JOIN ( SELECT sas.org_code AS oid, count( sas.id ) AS totlaSpmk FROM spmk_approve_summary sas GROUP BY sas.org_code ) AS a ON a.oid = qeim.id
        LEFT JOIN ( SELECT cc.organization_id AS oid, count( cc.id ) AS totlaCc FROM cms_content cc GROUP BY cc.organization_id ) AS b ON b.oid = qeim.id
        <where>
            <if test="param.name != null and param.name !=''">
                and qeim.NAME like CONCAT('%',#{param.name},'%')
            </if>
            <if test="param.linkMan != null and param.linkMan !=''">
                and qeim.link_man like CONCAT('%',#{param.linkMan},'%')
            </if>
            <if test="param.linkManPhone != null and param.linkManPhone !=''">
                and qeim.phone like CONCAT('%',#{param.linkManPhone},'%')
            </if>
        </where>
        GROUP BY
        qeim.id
        <if test="param.page.currentPage != null and param.page.totalPage !=null">
            limit #{param.page.offset},#{param.page.totalPage}
        </if>
    </select>

    <select id="companyAdminCount" resultType="java.lang.Integer">
        select count(qeim.id) from qyzx_ent_info_m qeim
        <where>
            <if test="param.name != null and param.name !=''">
                and qeim.NAME like CONCAT('%',#{param.name},'%')
            </if>
            <if test="param.linkMan != null and param.linkMan !=''">
                and qeim.link_man like CONCAT('%',#{param.linkMan},'%')
            </if>
            <if test="param.linkManPhone != null and param.linkManPhone !=''">
                and qeim.phone like CONCAT('%',#{param.linkManPhone},'%')
            </if>
        </where>
    </select>

    <select id ="getCompanyList" resultType="java.util.HashMap">
        select id as value , name as label from qyzx_ent_info_m
    </select>

</mapper>