<?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="auditSqlMapper">
	
	<sql id="base_column">
		t_advertiser.id as id,
		t_industry.id as industryId,
		t_advertiser.name as name,
		t_advertiser.reg_name as regName,
		t_advertiser.homepage as homePage,
		t_advertiser.contacts,
		t_advertiser.tel as tel,
		t_advertiser.email as email,
		t_advertiser.updated as updated,
		t_advertiser.cpi_path as cpiPath,
		t_advertiser.licence_path as licencePath,
		t_advertiser.id_path as idPath,
		t_advertiser.org_path as orgPath,
		t_advertiser.check_account as checkAccount,
		t_advertiser.check_status as checkStatus,
		t_advertiser.check_memo as checkMemo
	</sql>
	
	
	
	
			
	<select id="selectByParamsBack"  parameterType="map" resultType="com.cloudcross.ssp.model.Audit">
		select 
		<include refid="base_column" />
		,t_adv_agent.name as agentName,t_industry.name as industryName
		from t_adv_agent,t_industry,t_advertiser 
		where t_adv_agent.id=t_advertiser.agent_id 
		
		 <if test="key!=null and value!=null">
			<choose>
				<when test="key=='name'">
					and t_advertiser.name like #{value}
				</when>
			</choose>	
		</if>
		 <if test="checkStatus!=null">	
			and t_advertiser.check_status = #{checkStatus}
		</if>
		 <if test="industryId!=null">	
			and t_advertiser.industry_id = #{industryId}
		</if>
		 and t_advertiser.status != -1
		 and t_advertiser.industry_id = t_industry.id 
		
		order by t_advertiser.id   desc
		limit #{pager.offset}, #{pager.limit}
		
	</select>
	
	<select id="selectByParamsoperator"  parameterType="map" resultType="com.cloudcross.ssp.model.Audit">
		select 
		<include refid="base_column" />
		,b.name as industryName, count(c.advertiser_id) as orderNum from t_industry b,t_advertiser left join t_order c
		 on t_advertiser.id = c.advertiser_id 
		 where 1 = 1 
		 <if test="key!=null and value!=null">
			<choose>
				<when test="key=='name'">
					and t_advertiser.name like #{value}
				</when>
			</choose>	
		</if>
		 <if test="checkStatus!=null">	
			and t_advertiser.check_status = #{checkStatus}
		</if>
		 <if test="industryId!=null">	
			and t_advertiser.industry_id = #{industryId}
		</if>
		 and t_advertiser.status != -1
		 and t_advertiser.industry_id = b.id 
		group by t_advertiser.id
		order by t_advertiser.id   desc
		limit #{pager.offset}, #{pager.limit}
	</select>
	
	
	
	<select id="countByParamsBack" parameterType="map" resultType="int">
		select count(a.id)
		from t_advertiser a,t_adv_agent b 
		where b.id=a.agent_id 
		and a.status != -1
		<if test="key!=null and value!=null">
			<choose>
				<when test="key=='name'">
					and a.name like #{value}
				</when>
			</choose>	
		</if>
		 <if test="checkStatus!=null">	
			and a.check_status = #{checkStatus}
		</if>
		 <if test="industryId!=null">	
			and a.industry_id = #{industryId}
		</if>
		
		
	</select>
	
	<select id="countByParamsoperator" parameterType="map" resultType="int">
		select count(a.id)
		from t_advertiser a where status != -1
		<if test="key!=null and value!=null">
			<choose>
				<when test="key=='name'">
					and a.name like #{value}
				</when>
			</choose>	
		</if>
		 <if test="checkStatus!=null">	
			and a.check_status = #{checkStatus}
		</if>
		 <if test="industryId!=null">	
			and a.industry_id = #{industryId}
		</if>
	</select>
<!-- 
from t_advertiser a,t_adv_agent b 
		where b.id=a.agent_id 
		and a.status != -1

<select id="selectByStatus"  parameterType="map" resultType="audit">
		select 
		<include refid="base_column" />
		,b.name as industryName, count(c.advertiser_id) as orderNum from t_industry b,t_advertiser left join t_order c
		 on t_advertiser.id = c.advertiser_id 
		 where 1 = 1 
		 and t_advertiser.check_status = #{checkStatus}
		 and t_advertiser.industry_id = b.id 
		group by t_advertiser.id
		order by t_advertiser.id   desc
		limit #{pager.offset}, #{pager.limit}
	</select>
 -->
	<select id="selectByIdBack" parameterType="int" resultType="com.cloudcross.ssp.model.Audit">
		select 
		<include refid="base_column" />
		
		,t_industry.name as industryName                       
        from t_advertiser,t_industry
        where t_industry.id = t_advertiser.industry_id and t_advertiser.id = #{id}
        
	<!--	from t_advertiser 
		<where>
			id = #{id}
		</where> -->
	</select>
	
	<select id="selectByIdoperator" parameterType="int" resultType="com.cloudcross.ssp.model.Audit">
		select 
		<include refid="base_column" />
		from t_advertiser
		<where>
			id = #{id}
		</where>
	</select>
	
	<select id="selectByStatus"  parameterType="map" resultType="com.cloudcross.ssp.model.Audit">
		select 
		<include refid="base_column" />
		,b.name as industryName, count(c.advertiser_id) as orderNum from t_industry b,t_advertiser left join t_order c
		 on t_advertiser.id = c.advertiser_id 
		 where 1 = 1 
		 and t_advertiser.check_status = #{checkStatus}
		 and t_advertiser.industry_id = b.id 
		group by t_advertiser.id
		order by t_advertiser.id   desc
		limit #{pager.offset}, #{pager.limit}
	</select>
	
	<select id="countByStatus" parameterType="map" resultType="int">
		select count(a.id)
		from t_advertiser a where check_status = #{checkStatus}
		
	</select>
<!-- 	<update id="updateStatus" parameterType="HashMap">
		update t_advertiser 
			set check_status = #{checkStatus},updated = #{modifyDate}
			where t_advertiser.id in
			<foreach item="advertiserId" collection="advertiserIdList"
		      open="(" separator="," close=")">
		        #{auditId}
			</foreach>
	</update>
 -->	
 	<update id="updateCheckStatus" parameterType="HashMap">
		update t_advertiser 
			set check_status = #{checkStatus},updated = NOW(),check_memo = #{checkMemo}
			where t_advertiser.id =#{auditId}			
	</update>
	
		<update id="updateStatus" parameterType="HashMap">
		update t_advertiser 
			set check_status = #{checkStatus},updated = #{modifyDate}
			where t_advertiser.id in
			<foreach item="advertiserId" collection="advertiserIdList"
		      open="(" separator="," close=")">
		        #{advertiserId}
			</foreach>
	</update>
	
	<!-- 导出Excel用 -->
	<select id="findDeliverEffectAnalysis" parameterType="map" resultType="com.cloudcross.ssp.model.Audit">		
		
		select 
		<include refid="base_column" />
		,t_adv_agent.name as agentName,t_industry.name as industryName
		from t_adv_agent,t_industry,t_advertiser 
		where t_adv_agent.id=t_advertiser.agent_id 
		
		 <if test="key!=null and value!=null">
			<choose>
				<when test="key=='name'">
					and t_advertiser.name like #{value}
				</when>
			</choose>	
		</if>
		 <if test="checkStatus!=null">	
			and t_advertiser.check_status = #{checkStatus}
		</if>
		 <if test="industryId!=null">	
			and t_advertiser.industry_id = #{industryId}
		</if>
		 and t_advertiser.status != -1
		 and t_advertiser.industry_id = t_industry.id 
		
		order by t_advertiser.id   desc
		
	</select>
	
</mapper>