Browse Source

mapper的整合

Signed-off-by: you.chen <you.chen@cloudcross.com>
you.chen 9 years ago
parent
commit
a3d31485d6
48 changed files with 8055 additions and 23 deletions
  1. 499 0
      src/main/java/com/cloudcross/ssp/model/mapper/account.sql.xml
  2. 47 0
      src/main/java/com/cloudcross/ssp/model/mapper/acls.sql.xml
  3. 477 0
      src/main/java/com/cloudcross/ssp/model/mapper/ad-group.sql.xml
  4. 41 0
      src/main/java/com/cloudcross/ssp/model/mapper/adgroup-place.sql.xml
  5. 27 0
      src/main/java/com/cloudcross/ssp/model/mapper/adgroup-schedule.sql.xml
  6. 20 0
      src/main/java/com/cloudcross/ssp/model/mapper/adgroup-zone.sql.xml
  7. 231 0
      src/main/java/com/cloudcross/ssp/model/mapper/adv-balance.sql.xml
  8. 100 0
      src/main/java/com/cloudcross/ssp/model/mapper/advAgent.sql.xml
  9. 306 0
      src/main/java/com/cloudcross/ssp/model/mapper/advertiser.sql.xml
  10. 143 0
      src/main/java/com/cloudcross/ssp/model/mapper/audit-banner.sql.xml
  11. 237 0
      src/main/java/com/cloudcross/ssp/model/mapper/audit.sql.xml
  12. 343 0
      src/main/java/com/cloudcross/ssp/model/mapper/banner-template.sql.xml
  13. 473 0
      src/main/java/com/cloudcross/ssp/model/mapper/banner.sql.xml
  14. 317 0
      src/main/java/com/cloudcross/ssp/model/mapper/campaign.sql.xml
  15. 51 0
      src/main/java/com/cloudcross/ssp/model/mapper/clientAccount.sql.xml
  16. 160 0
      src/main/java/com/cloudcross/ssp/model/mapper/codeClass.sql.xml
  17. 164 0
      src/main/java/com/cloudcross/ssp/model/mapper/codeConvert.sql.xml
  18. 67 0
      src/main/java/com/cloudcross/ssp/model/mapper/codeSite.sql.xml
  19. 42 0
      src/main/java/com/cloudcross/ssp/model/mapper/direct.sql.xml
  20. 96 0
      src/main/java/com/cloudcross/ssp/model/mapper/finance.sql.xml
  21. 35 0
      src/main/java/com/cloudcross/ssp/model/mapper/industry.sql.xml
  22. 52 0
      src/main/java/com/cloudcross/ssp/model/mapper/location.sql.xml
  23. 96 0
      src/main/java/com/cloudcross/ssp/model/mapper/log.sql.xml
  24. 82 0
      src/main/java/com/cloudcross/ssp/model/mapper/message.sql.xml
  25. 57 0
      src/main/java/com/cloudcross/ssp/model/mapper/messageRead.sql.xml
  26. 94 0
      src/main/java/com/cloudcross/ssp/model/mapper/operator-balance.sql.xml
  27. 418 0
      src/main/java/com/cloudcross/ssp/model/mapper/operator-report.sql.xml
  28. 115 0
      src/main/java/com/cloudcross/ssp/model/mapper/operator.sql.xml
  29. 273 0
      src/main/java/com/cloudcross/ssp/model/mapper/order.sql.xml
  30. 45 0
      src/main/java/com/cloudcross/ssp/model/mapper/place-operator.sql.xml
  31. 21 0
      src/main/java/com/cloudcross/ssp/model/mapper/place.sql.xml
  32. 1752 0
      src/main/java/com/cloudcross/ssp/model/mapper/report.sql.xml
  33. 170 0
      src/main/java/com/cloudcross/ssp/model/mapper/resources.sql.xml
  34. 92 0
      src/main/java/com/cloudcross/ssp/model/mapper/roles.sql.xml
  35. 23 0
      src/main/java/com/cloudcross/ssp/model/mapper/rpt-advertiser-hour.sql.xml
  36. 28 0
      src/main/java/com/cloudcross/ssp/model/mapper/rpt-zone-hour.sql.xml
  37. 56 0
      src/main/java/com/cloudcross/ssp/model/mapper/rpt-zone.sql.xml
  38. 23 0
      src/main/java/com/cloudcross/ssp/model/mapper/size.sql.xml
  39. 48 0
      src/main/java/com/cloudcross/ssp/model/mapper/systemreport.sql.xml
  40. 48 0
      src/main/java/com/cloudcross/ssp/model/mapper/typereport.sql.xml
  41. 25 0
      src/main/java/com/cloudcross/ssp/model/mapper/user-group.sql.xml
  42. 123 0
      src/main/java/com/cloudcross/ssp/model/mapper/user.sql.xml
  43. 46 0
      src/main/java/com/cloudcross/ssp/model/mapper/userLogin.sql.xml
  44. 213 0
      src/main/java/com/cloudcross/ssp/model/mapper/wifi.sql.xml
  45. 34 0
      src/main/java/com/cloudcross/ssp/model/mapper/zone-domain.sql.xml
  46. 29 0
      src/main/java/com/cloudcross/ssp/model/mapper/zone-industry.sql.xml
  47. 216 0
      src/main/java/com/cloudcross/ssp/model/mapper/zone.sql.xml
  48. 0 23
      src/test/java/com/cloudcross/ssp/service/IOperatorBalanceServiceTest.java

+ 499 - 0
src/main/java/com/cloudcross/ssp/model/mapper/account.sql.xml

@@ -0,0 +1,499 @@
+<?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="accountSqlMapper">
+
+	<!--mybatis ehcache缓存配置 -->
+	<!-- 以下两个<cache>标签二选一,第一个可以输出日志,第二个不输出日志 <cache type="org.mybatis.caches.ehcache.LoggingEhcache" 
+		/> -->
+	<!-- <cache type="org.mybatis.caches.ehcache.EhcacheCache"/> -->
+	<!-- 以下与实体类的中字段一致 -->
+	<sql id="selectId">
+		id,
+		name as accountName,
+		(select group_concat(name) from t_ly_role
+		where t_ly_role.id
+		in (SELECT role_id FROM t_acc_role WHERE
+		acc_id=t_account.id) ) roleName,
+		password,
+		description,
+		state,
+		create_time as createTime,
+		real_name as realName,
+		tel,
+		type,
+		operator_id as operatorId,
+		agent_id as agentId,
+		advertiser_id as advertiserId,
+		sys_type as sysType
+	</sql>
+
+	<!--resultType="Account" 每返回一条结果封装到Account里 -->
+	<select id="queryAll" resultType="com.cloudcross.ssp.model.Account" parameterType="com.cloudcross.ssp.model.Account">
+		select
+		<include refid="selectId" />
+		from t_account
+		<where>
+			<if test="accountName != null and accountName != ''">
+				name like '%${accountName}%'
+			</if>
+		</where>
+	</select>
+	
+	<select id="selectByParams"  parameterType="map" resultType="com.cloudcross.ssp.model.Account">
+		select id,
+		name as accountName,
+		real_name as realName,tel,state,create_time as createTime
+		from t_account
+		where deletestatus != -1 
+		and operator_id = 0
+		and agent_id = 0
+		and advertiser_id = 0
+		<if test="value!=null">
+			and ( t_account.name like #{value}
+			or t_account.real_name like #{value} )
+		</if>
+		and id != #{loginAccount.id}
+		and sys_type = #{loginAccount.sysType}
+		order by id   desc
+		limit #{pager.offset}, #{pager.limit}
+	</select>
+
+
+		<select id="selectByParams.operator"  parameterType="map" resultType="com.cloudcross.ssp.model.Account">
+		select id,
+		name as accountName,
+		real_name as realName,tel,state,create_time as createTime
+		from t_account
+		where deletestatus != -1 
+		and operator_id = #{loginAccount.operatorId}
+		and id != #{loginAccount.id}
+		<if test="value!=null">
+			and ( t_account.name like #{value}
+			or t_account.real_name like #{value} )
+		</if>
+		and sys_type = #{loginAccount.sysType}
+		order by id   desc
+		limit #{pager.offset}, #{pager.limit}
+	</select>
+
+
+<select id="selectByParams.advertiser"  parameterType="map" resultType="com.cloudcross.ssp.model.Account">
+		select id,
+		name as accountName,
+		real_name as realName,tel,state,create_time as createTime
+		from t_account
+		where deletestatus != -1 
+		and agent_id = #{loginAccount.agentId}
+		<if test="value!=null">
+			and ( t_account.name like #{value}
+			or t_account.real_name like #{value} )
+		</if>
+		and id != #{loginAccount.id}
+		and sys_type = #{loginAccount.sysType}
+		<if test="loginAccount.advertiserId != 0 ">
+		and advertiser_id = #{loginAccount.advertiserId}
+		</if>
+		order by id   desc
+		limit #{pager.offset}, #{pager.limit}
+	</select>
+	<select id="countByParams" parameterType="map" resultType="int">
+		select count(id) 
+		from t_account
+		where deletestatus != -1 
+		and operator_id = 0
+		and agent_id = 0
+		and advertiser_id = 0
+		<if test="value!=null">
+			and ( t_account.name like #{value}
+			or t_account.real_name like #{value} )
+		</if>
+		and id != #{loginAccount.id}
+		and sys_type = #{loginAccount.sysType}
+	</select>
+	
+<select id="countByParams.operator" parameterType="map" resultType="int">
+		select count(id) 
+		from t_account
+		where deletestatus != -1 
+		and operator_id = #{loginAccount.operatorId}
+		<if test="value!=null">
+			and ( t_account.name like #{value}
+			or t_account.real_name like #{value} )
+		</if>
+		and id != #{loginAccount.id}
+		and sys_type = #{loginAccount.sysType}
+	</select>
+
+<select id="countByParams.advertiser" parameterType="map" resultType="int">
+		select count(id) 
+		from t_account
+		where deletestatus != -1 
+		and agent_id = #{loginAccount.agentId}
+		<if test="value!=null">
+			and ( t_account.name like #{value}
+			or t_account.real_name like #{value} )
+		</if>
+		and id != #{loginAccount.id}
+		and sys_type = #{loginAccount.sysType}
+		<if test="loginAccount.advertiserId != 0 ">
+		and advertiser_id = #{loginAccount.advertiserId}
+			</if>
+	</select>
+	<select id="isExist" resultType="com.cloudcross.ssp.model.Account" parameterType="String">
+		select
+		<include refid="selectId" />
+		from t_account
+		where name = #{accountName}
+	</select>
+
+	<!--resultType="Account" 每返回一条结果封装到Account里 -->
+	<select id="query" resultType="com.cloudcross.ssp.model.Account" parameterType="java.util.HashMap">
+		select
+		<include refid="selectId" />
+		from t_account
+		<where>
+			<if test="t.accountName != null and t.accountName != ''">
+				name like '%${t.accountName}%'
+			</if>
+		</where>
+	</select>
+
+	<select id="queryNoMatch" resultType="com.cloudcross.ssp.model.Account" parameterType="java.util.HashMap">
+		select
+		a.id,
+		a.name,
+		a.password,
+		a.accountType,
+		a.description,
+		a.state,
+		a.createTime,
+		(SELECT dp.name from department dp where dp.id =
+		d.subdep_id) depName
+		from account a LEFT JOIN dep_account d on
+		a.id=d.account_id
+		<where>
+			<if test="t.accountName != null and t.accountName != ''">
+				name like '%${t.accountName}%'
+			</if>
+		</where>
+	</select>
+	
+		<!-- 增加用户 -->
+	<insert id="add" parameterType="com.cloudcross.ssp.model.Account">
+		insert into t_account (
+		name,
+		password,
+		description,
+		state )
+		values (#{accountName},
+		#{password}, #{description},
+		#{state})
+	</insert>
+	<!-- 增加用户 -->
+	<insert id="addAccount" parameterType="com.cloudcross.ssp.model.Account" useGeneratedKeys="true" keyProperty="id">
+		insert into t_account
+		 (name,
+		 password,
+		 real_name,
+		 tel,
+		 description, 
+		 state,
+		 sys_type ) values (#{accountName}, #{password},#{realName}, 
+    	#{tel},#{description},#{state},#{sysType}) 
+	</insert>
+
+
+	<!-- 增加用户 -->
+	<insert id="addAccount.operator" parameterType="com.cloudcross.ssp.model.Account">
+		insert into t_account
+		 (name,
+		 password,
+		 real_name,
+		 tel,
+		 operator_id,
+		 description, 
+		 state,
+		 sys_type ) values (#{accountName}, #{password},#{realName}, 
+    	#{tel},#{operatorId},#{description},#{state},#{sysType}) 
+	</insert>
+
+
+<!-- 增加用户 -->
+	<insert id="addAccount.advertiser" parameterType="com.cloudcross.ssp.model.Account" useGeneratedKeys="true" keyProperty="id">
+		insert into t_account
+		 (name,
+		 password,
+		 real_name,
+		 tel,
+		 agent_id,
+		 advertiser_id,
+		 description, 
+		 state,
+		 sys_type ) values (#{accountName}, #{password},#{realName}, 
+    	#{tel},#{agentId},#{advertiserId},#{description},#{state},#{sysType}) 
+	</insert>
+
+	<delete id="delete" parameterType="String">
+		delete from t_account where
+		id=#{id}
+	</delete>
+
+	<select id="getById" parameterType="String" resultType="com.cloudcross.ssp.model.Account">
+		select
+		id,
+		name as accountName,
+		(select group_concat(name) from t_ly_role
+		where t_ly_role.id
+		in (SELECT role_id FROM t_acc_role WHERE
+		acc_id=t_account.id) ) roleName,
+		password,
+		real_name as realName,
+		tel,
+		description,
+		state,
+		create_time as createTime,
+		type,
+		operator_id as operatorId,
+		agent_id as agentId,
+		advertiser_id as advertiserId,
+		sys_type as sysType
+		from t_account where id=#{id}
+	</select>
+
+	<update id="updateAccountStatus" parameterType="HashMap">
+		update t_account
+				set state=#{state}
+		where t_account.id in
+			<foreach item="accountId" collection="accountIdList"
+		      open="(" separator="," close=")">
+		        #{accountId}
+			</foreach>
+	</update>
+	
+	<update id="editAccount" parameterType="com.cloudcross.ssp.model.Account">
+		update t_account
+		<set>
+			<if test="accountName != null and accountName != ''">
+				name=#{accountName},
+			</if>
+			<if test="password != null and password != ''">
+				password=#{password},
+			</if>
+			<if test="description != null and description != ''">
+				description=#{description},
+			</if>
+			<if test="state != null and state != ''">
+				state=#{state},
+			</if>
+			<if test="createTime != null and createTime != ''">
+				create_time=#{createTime},
+			</if>
+			<if test="realName != null and realName != ''">
+				real_name=#{realName},
+			</if>
+			<if test="tel != null and tel != ''">
+				tel=#{tel},
+			</if>
+			<if test="operatorId != null and operatorId != 0">
+				operator_id=#{operatorId},
+			</if>
+			<if test="agentId != null and agentId !=0">
+				agent_id=#{agentId},
+			</if>
+			<if test="advertiserId != null and advertiserId !=0">
+				advertiser_id=#{advertiserId},
+			</if>
+		</set>
+		where id=#{id}
+	</update>
+	
+	
+	<update id="editAccount.operator" parameterType="com.cloudcross.ssp.model.Account">
+		update t_account
+		<set>
+			<if test="accountName != null and accountName != ''">
+				name=#{accountName},
+			</if>
+			<if test="password != null and password != ''">
+				password=#{password},
+			</if>
+			<if test="description != null and description != ''">
+				description=#{description},
+			</if>
+			<if test="state != null and state != ''">
+				state=#{state},
+			</if>
+			<if test="createTime != null and createTime != ''">
+				createTime=#{createTime},
+			</if>
+			<if test="realName != null and realName != ''">
+				real_name=#{realName},
+			</if>
+			<if test="tel != null and tel != ''">
+				tel=#{tel}
+			</if>
+		</set>
+		where id=#{id}
+	</update>
+	
+		<update id="editAccount.advertiser" parameterType="com.cloudcross.ssp.model.Account">
+		update t_account
+		<set>
+			<if test="accountName != null and accountName != ''">
+				name=#{accountName},
+			</if>
+			<if test="password != null and password != ''">
+				password=#{password},
+			</if>
+			<if test="description != null and description != ''">
+				description=#{description},
+			</if>
+			<if test="state != null and state != ''">
+				state=#{state},
+			</if>
+			<if test="createTime != null and createTime != ''">
+				createTime=#{createTime},
+			</if>
+			<if test="realName != null and realName != ''">
+				real_name=#{realName},
+			</if>
+			<if test="tel != null and tel != ''">
+				tel=#{tel},
+			</if>
+			<if test="advertiserId != null">
+				advertiser_id=#{advertiserId}
+			</if>
+		</set>
+		where id=#{id}
+	</update>
+	
+	
+	<update id="update" parameterType="com.cloudcross.ssp.model.Account">
+		update t_account
+		<set>
+			<if test="accountName != null and accountName != ''">
+				name=#{accountName},
+			</if>
+			<if test="password != null and password != ''">
+				password=#{password},
+			</if>
+			<if test="description != null and description != ''">
+				description=#{description},
+			</if>
+			<if test="state != null and state != ''">
+				state=#{state},
+			</if>
+			<if test="createTime != null and createTime != ''">
+				createTime=#{createTime},
+			</if>
+			<if test="realName != null and realName != ''">
+				real_name=#{realName},
+			</if>
+			<if test="tel != null and tel != ''">
+				tel=#{tel}
+			</if>
+		</set>
+		where id=#{id}
+	</update>
+
+
+	<update id="update.operator" parameterType="com.cloudcross.ssp.model.Account">
+		update t_account
+		<set>
+			<if test="accountName != null and accountName != ''">
+				name=#{accountName},
+			</if>
+			<if test="password != null and password != ''">
+				password=#{password},
+			</if>
+			<if test="description != null and description != ''">
+				description=#{description},
+			</if>
+			<if test="state != null and state != ''">
+				state=#{state},
+			</if>
+			<if test="createTime != null and createTime != ''">
+				createTime=#{createTime}
+			</if>
+			<if test="realName != null and tel != ''">
+				real_name=#{realName}
+			</if>
+			<if test="tel != null and tel != ''">
+				tel=#{tel}
+			</if>
+		</set>
+		where id=#{id}
+	</update>
+
+	<!-- 验证用户登陆 -->
+	<select id="countAccount" parameterType="com.cloudcross.ssp.model.Account" resultType="com.cloudcross.ssp.model.Account">
+		select
+		<include refid="selectId" />
+		from t_account where
+		name=#{accountName} and password=#{password}
+	</select>
+
+	<!-- 根据用户名查出id -->
+	<select id="querySingleAccount" parameterType="String"
+		resultType="com.cloudcross.ssp.model.Account">
+		select
+		<include refid="selectId" />
+		from t_account where name=#{accountName}
+	</select>
+	
+	<select id="findExcelAccount"  parameterType="map" resultType="com.cloudcross.ssp.model.Account">
+		select id,
+		name as accountName,
+		real_name as realName,tel,state,create_time as createTime
+		from t_account
+		where deletestatus != -1 
+		and operator_id = 0
+		and agent_id = 0
+		and advertiser_id = 0
+		<if test="value!=null">
+			and ( t_account.name like #{value}
+			or t_account.real_name like #{value} )
+		</if>
+		and id != #{loginAccount.id}
+		and sys_type = #{loginAccount.sysType}
+		order by id   desc
+	</select>
+	
+	
+		<select id="findExcelAccount.operator"  parameterType="map" resultType="com.cloudcross.ssp.model.Account">
+		select id,
+		name as accountName,
+		real_name as realName,tel,state,create_time as createTime
+		from t_account
+		where deletestatus != -1 
+		and operator_id = #{loginAccount.operatorId}
+		and id != #{loginAccount.id}
+		<if test="value!=null">
+			and ( t_account.name like #{value}
+			or t_account.real_name like #{value} )
+		</if>
+		and sys_type = #{loginAccount.sysType}
+		order by id   desc
+	</select>
+	
+	
+	<select id="findExcelAccount.advertiser"  parameterType="map" resultType="com.cloudcross.ssp.model.Account">
+		select id,
+		name as accountName,
+		real_name as realName,tel,state,create_time as createTime
+		from t_account
+		where deletestatus != -1 
+		and agent_id = #{loginAccount.agentId}
+		and id != #{loginAccount.id}
+		<if test="value!=null">
+			and ( t_account.name like #{value}
+			or t_account.real_name like #{value} )
+		</if>
+		and sys_type = #{loginAccount.sysType}
+		<if test="loginAccount.advertiserId != 0 ">
+			and advertiser_id = #{loginAccount.advertiserId}
+		</if>
+		order by id   desc
+	</select>
+</mapper>

+ 47 - 0
src/main/java/com/cloudcross/ssp/model/mapper/acls.sql.xml

@@ -0,0 +1,47 @@
+<?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="aclsSqlMapper">
+	<sql id="base_column">
+		banner_id as bannerId,
+		logical ,
+		type,
+		comparison,
+		data,
+		executionorder as executionOrder,
+		adgroup_id as adGroupId
+	</sql>
+	<insert id="addAcls" parameterType="com.cloudcross.ssp.model.Acls">
+		insert into  	t_acls(banner_id,logical,type,comparison,data,<if test="null!=executionOrder" >executionorder,</if>adgroup_id)
+		values (#{bannerId},#{logical},#{type},#{comparison},#{data},<if test="null!=executionOrder" >#{executionOrder},</if>#{adGroupId})
+	</insert>
+	<update id="editAcls" parameterType="com.cloudcross.ssp.model.Acls">
+		update t_acls
+		set logical=
+		#{logical},comparison = #{comparison},data=#{data}
+		where type=#{type} and adgroup_id=#{adGroupId}
+	</update>
+	
+	<select id="findById" parameterType="long"  resultType="com.cloudcross.ssp.model.Acls">
+		select  <include refid="base_column"/>  from t_acls  where  banner_id  =  #{bannerId}
+	</select>
+	
+	<delete id="deleteAcls" parameterType="long">
+		delete from t_acls where  banner_id = #{id} 
+	</delete>
+	
+	<delete id="deleteAclsBatch" parameterType="map">
+			delete from t_acls where  type=#{type} and banner_id in
+				<foreach item="id" collection="idList" open="("  separator="," close=")">
+				#{id}
+				</foreach>
+	</delete>
+	
+	<insert  id="addAclsBatch" parameterType="map">
+	    insert into t_acls  (banner_id,logical,type,comparison,data,
+						<if test="null!=acls.executionOrder" >executionorder,</if>adgroup_id)
+          values    <foreach collection="idList" item="item" index="index" separator=",">
+    					(#{item},#{acls.logical},#{acls.type},#{acls.comparison},#{acls.data},
+    					<if test="null!=acls.executionOrder" >#{acls.executionOrder},</if>#{adGroupId})
+    			    </foreach> 
+	</insert>
+</mapper>

+ 477 - 0
src/main/java/com/cloudcross/ssp/model/mapper/ad-group.sql.xml

@@ -0,0 +1,477 @@
+<?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="adGroupSqlMapper">
+	<sql id="base_column">
+		t_adgroup.id,
+		t_adgroup.agent_id as agentId,
+		t_adgroup.advertiser_id as advertiserId,
+		t_adgroup.order_id as orderId,
+		t_adgroup.campaign_id as campaignId,
+		name as adGroupName,
+		active_time as startDate,
+		expire_time as endDate,
+		totalbudget as totalBudget,
+		mode,
+		price,
+		dailybudget as dailyBudget,
+		impression as maxImpression,
+		click as maxClick,
+		conversion as maxConversion,
+		daily_impression as dailyMaxImpression,
+		daily_click as dailyMaxClick,
+		daily_conversion as dailyMaxConversion,
+		per_impression_type as perImpressionType,
+		per_impression as perImpression,
+		per_click_type as perClickType,
+		per_click as perClick,
+		position,
+		site,
+		retarget,
+		period,
+		t_adgroup.status,
+		t_adgroup.updated as updated
+	</sql>
+	
+	
+	<select id="countByParams" parameterType="map" resultType="int">
+		select count(id) 
+		from t_adgroup
+		where status != -1
+		<if test="agentId!=null">
+			 and agent_id = #{agentId}
+		</if>
+		<if test="agentId == null">
+			and advertiser_id = #{advertiserId}
+		</if>
+		<if test="orderMark == null">
+			and order_id = #{orderId}
+		</if>
+		<if test="campaignMark == null">
+			and campaign_id = #{campaignId}
+		</if>
+		<if test="adGroupName != null">
+			and name like #{adGroupName}
+		</if>
+			<if test="selectedStatus1!=null">
+			and now()>active_time and expire_time>now() and status=0
+			</if>
+			<if test="selectedStatus2!=null">
+			and active_time>now()
+			</if>
+			<if test="selectedStatus3!=null">
+			and now()>expire_time and status=1
+			</if>
+			<if test="selectedStatus4!=null">
+			and status=1
+			</if>
+	</select>
+	
+	
+	<select id="countByParams.back" parameterType="map" resultType="int">
+		select count(id) 
+		from t_adgroup
+		where status != -1
+		<if test="agentId!=null">
+			 and agent_id = #{agentId}
+		</if>
+		<if test="agentId == null">
+			and advertiser_id = #{advertiserId}
+		</if>
+		<if test="orderMark != null">
+			and order_id = #{orderId}
+		</if>
+		<if test="campaignMark != null">
+			and campaign_id = #{campaignId}
+		</if>
+		<if test="adGroupName != null">
+			and name like #{adGroupName}
+			</if>
+			<if test="selectedStatus1!=null">
+			and now()>active_time and expire_time>now() and status=0
+			</if>
+			<if test="selectedStatus2!=null">
+			and active_time>now()
+			</if>
+			<if test="selectedStatus3!=null">
+			and now()>expire_time and status=1
+			</if>
+			<if test="selectedStatus4!=null">
+			and status=1
+			</if>
+	</select>
+	
+		<select id="findAreas.back" parameterType="Long" resultType="map">
+		select *from t_target_show 
+		where adgroup_id = #{adGroupId} and targettype = "deliveryLimitations:Geo:City"
+	</select>
+	
+	<select id="findByParams" parameterType="map" resultType="com.cloudcross.ssp.model.AdGroup">
+		select
+		<include refid="base_column"/>, (select count(t_banner.id) from t_banner where t_banner.adgroup_id = t_adgroup.id and t_banner.status !=-1
+		) as bannerNumber
+		from t_adgroup 
+		<where>
+			 t_adgroup.status!=-1
+			<if test="agentId!=null">
+			 and t_adgroup.agent_id = #{agentId}
+		</if>
+		<if test="agentId == null">
+			and t_adgroup.advertiser_id = #{advertiserId}
+		</if>
+		<if test="orderMark == null">
+			and t_adgroup.order_id = #{orderId}
+		</if>
+		<if test="campaignMark == null">
+			and t_adgroup.campaign_id = #{campaignId}
+		</if>
+		<if test="adGroupName != null">
+			and name like #{adGroupName}
+			</if>
+			<if test="selectedStatus1!=null">
+			and now()>active_time and expire_time>now() and t_adgroup.status=0
+			</if>
+			<if test="selectedStatus2!=null">
+			and active_time>now()
+			</if>
+			<if test="selectedStatus3!=null">
+			and now()>expire_time and t_adgroup.status=1
+			</if>
+			<if test="selectedStatus4!=null">
+			and t_adgroup.status=1
+			</if>
+		</where>
+		group by t_adgroup.id
+		order by t_adgroup.id desc
+		limit #{pager.offset}, #{pager.limit}
+	</select>
+	
+		<select id="findByParams.back" parameterType="map" resultType="com.cloudcross.ssp.model.AdGroup">
+		select
+		<include refid="base_column"/>, count(banner_template_id) as bannerNumber
+		from t_adgroup left join t_banner
+		on t_adgroup.id=t_banner.adgroup_id
+		<where>
+			t_adgroup.campaign_id=#{campaignId} and status!=-1
+			<if test="agentId!=null">
+			 and agent_id = #{agentId}
+		</if>
+		<if test="agentId == null">
+			and advertiser_id = #{advertiserId}
+		</if>
+		<if test="orderMark != null">
+			and order_id = #{orderId}
+		</if>
+		<if test="campaignMark != null">
+			and campaign_id = #{campaignId}
+		</if>
+		<if test="adGroupName != null">
+			and name like #{adGroupName}
+			</if>
+			<if test="selectedStatus1!=null">
+			and now()>active_time and expire_time>now() and status=0
+			</if>
+			<if test="selectedStatus2!=null">
+			and active_time>now()
+			</if>
+			<if test="selectedStatus3!=null">
+			and now()>expire_time and status=1
+			</if>
+			<if test="selectedStatus4!=null">
+			and status=1
+			</if>
+		</where>
+		group by t_adgroup.id
+		order by t_adgroup.id desc
+		limit #{pager.offset}, #{pager.limit}
+	</select>
+	
+	
+	<select id="findByParams1" parameterType="map" resultType="com.cloudcross.ssp.model.AdGroup">
+		select
+		<include refid="base_column"/>, count(banner_template_id) as bannerNumber
+		from t_adgroup left join t_banner
+		on t_adgroup.id=t_banner.adgroup_id
+		<where>
+			 t_adgroup.status!=-1
+			<if test="agentId!=null">
+			 and t_adgroup.agent_id = #{agentId}
+		</if>
+		<if test="agentId == null">
+			and t_adgroup.advertiser_id = #{advertiserId}
+		</if>
+		<if test="orderMark == null">
+			and t_adgroup.order_id = #{orderId}
+		</if>
+		<if test="campaignMark == null">
+			and t_adgroup.campaign_id = #{campaignId}
+		</if>
+		<if test="adGroupName != null">
+			and name like #{adGroupName}
+			</if>
+			<if test="selectedStatus1!=null">
+			and now()>active_time and expire_time>now() and t_adgroup.status=0
+			</if>
+			<if test="selectedStatus2!=null">
+			and active_time>now()
+			</if>
+			<if test="selectedStatus3!=null">
+			and now()>expire_time and t_adgroup.status=1
+			</if>
+			<if test="selectedStatus4!=null">
+			and t_adgroup.status=1
+			</if>
+		</where>
+		group by t_adgroup.id
+		order by t_adgroup.id desc
+	</select>
+	
+	
+	
+	<update id="updateAdGroupStatus" parameterType="HashMap">
+		update t_adgroup 
+		set status=#{status},updated = #{updated}
+		where id in
+		<foreach item="id" collection="idList" open="(" separator=","
+			close=")">
+			#{id}
+		</foreach>
+	</update>
+	
+	<update id="updatedSupdated" parameterType="Long">
+		update t_adgroup 
+		set supdated=NOW()
+		where id = #{adGroupId}
+	</update>
+	
+	<select id="findByCampaignId" parameterType="long" resultType="com.cloudcross.ssp.model.AdGroup">
+	    select
+		<include refid="base_column"/>
+		from t_adgroup 
+		where campaign_id=#{campaignId} and status!=-1
+	</select>
+	
+	<insert id="addAdGroup" parameterType="com.cloudcross.ssp.model.AdGroup"  useGeneratedKeys="true"
+		keyProperty="id">
+		insert into t_adgroup
+			(name,campaign_id,order_id,agent_id,advertiser_id,active_time,expire_time,totalbudget,mode,
+			price,
+			<if test="dailyBudget !=null">dailybudget,</if>
+			<if test="maxImpression !=null">impression,</if>
+			<if test="maxClick !=null">	click,</if>
+			<if test="maxConversion !=null"> conversion,</if>
+			<if test="dailyMaxImpression !=null">daily_impression,</if>
+			<if test="dailyMaxClick !=null">daily_click,</if>
+			<if test="dailyMaxConversion !=null">daily_conversion,</if>
+			<if test="perImpressionType !=null">per_impression_type,</if>
+			<if test="perImpression !=null">per_impression,</if>
+			<if test="perClickType !=null">per_click_type,</if>
+			<if test="perClick !=null">per_click,</if>			
+			<if test="retarget !=null">retarget,</if>
+			<if test="period !=null">period,</if>
+			<if test="site !=null">site,</if>
+			<if test="position !=null">position,</if>
+			status,updated,supdated)
+		values
+			(#{adGroupName},#{campaignId},#{orderId},#{agentId},#{advertiserId},#{startDate},#{endDate},#{totalBudget},#{mode},
+			#{price},
+			<if test="dailyBudget !=null">#{dailyBudget},</if>
+			<if test="maxImpression !=null">#{maxImpression},</if>
+			<if test="maxClick !=null">#{maxClick},</if>
+			<if test="maxConversion !=null">#{maxConversion},</if>
+			<if test="dailyMaxImpression !=null">#{dailyMaxImpression},</if>
+			<if test="dailyMaxClick !=null">#{dailyMaxClick},</if>
+			<if test="dailyMaxConversion !=null">#{dailyMaxConversion},</if>
+			<if test="perImpressionType !=null">#{perImpressionType},</if>
+			<if test="perImpression !=null">#{perImpression},</if>
+			<if test="perClickType !=null">#{perClickType},</if>
+			<if test="perClick !=null">#{perClick},</if>			
+			<if test="retarget !=null">#{retarget},</if>
+			<if test="period !=null">#{period},</if>
+			<if test="site !=null">#{site},</if>
+			<if test="position !=null">#{position},</if>
+			#{status},NOW(),NOW())
+	</insert>
+	
+	<insert id="addAdGroup.back" parameterType="com.cloudcross.ssp.model.AdGroup"  useGeneratedKeys="true"
+		keyProperty="id">
+		insert into t_adgroup
+			(name,campaign_id,order_id,activate_time,expire_time,totalbudget,
+			<if test="price !=null">price,</if>
+			<if test="dailyBudget !=null">dailybudget,</if>
+			<if test="maxImpression !=null">impression,</if>
+			<if test="maxClick !=null">	click,</if>
+			<if test="maxConversion !=null"> conversion,</if>
+			<if test="dailyMaxImpression !=null">daily_impression,</if>
+			<if test="dailyMaxClick !=null">daily_click,</if>
+			<if test="dailyMaxConversion !=null">daily_conversion,</if>
+			<if test="perImpressionType !=null">per_impression_type,</if>
+			<if test="perImpression !=null">per_impression,</if>
+			<if test="perClickType !=null">per_click_type,</if>
+			<if test="perClick !=null">per_click,</if>			
+			<if test="retarget !=null">retarget,</if>
+			<if test="period !=null">period,</if>
+			<if test="site !=null">site,</if>
+			<if test="position !=null">position,</if>
+			status,updated,supdated)
+		values
+			(#{adGroupName},#{campaignId},#{orderId},#{startDate},#{endDate},#{totalBudget},
+			<if test="price !=null">#{price},</if>
+			<if test="dailyBudget !=null">#{dailyBudget},</if>
+			<if test="maxImpression !=null">#{maxImpression},</if>
+			<if test="maxClick !=null">#{maxClick},</if>
+			<if test="maxConversion !=null">#{maxConversion},</if>
+			<if test="dailyMaxImpression !=null">#{dailyMaxImpression},</if>
+			<if test="dailyMaxClick !=null">#{dailyMaxClick},</if>
+			<if test="dailyMaxConversion !=null">#{dailyMaxConversion},</if>
+			<if test="perImpressionType !=null">#{perImpressionType},</if>
+			<if test="perImpression !=null">#{perImpression},</if>
+			<if test="perClickType !=null">#{perClickType},</if>
+			<if test="perClick !=null">#{perClick},</if>			
+			<if test="retarget !=null">#{retarget},</if>
+			<if test="period !=null">#{period},</if>
+			<if test="site !=null">#{site},</if>
+			<if test="position !=null">#{position},</if>
+			#{status},NOW(),NOW())
+	</insert>
+	
+	
+	
+	<select id="findById" parameterType="long" resultType="com.cloudcross.ssp.model.AdGroup">
+		select
+		<include refid="base_column"/>
+		from t_adgroup
+		<where>
+		id = #{id}
+		</where>
+	</select>
+	
+	<update id="editAdGroup" parameterType="com.cloudcross.ssp.model.AdGroup">
+		update t_adgroup
+		set name = #{adGroupName},
+		active_time = #{startDate},
+		expire_time = #{endDate},		
+		totalbudget = #{totalBudget},
+		price = #{price},		
+		dailybudget = IFNULL(#{dailyBudget},default(dailybudget)),
+		impression = IFNULL(#{maxImpression},default(impression)),
+		click =IFNULL( #{maxClick},default(click)),
+		conversion=IFNULL( #{maxConversion},default(conversion)),
+		daily_impression = IFNULL(#{dailyMaxImpression},default(daily_impression)),
+		daily_click =IFNULL( #{dailyMaxClick},default(daily_click)),
+		daily_conversion = IFNULL(#{dailyMaxConversion},default(daily_conversion)),
+		per_impression_type = IFNULL(#{perImpressionType},default(per_impression_type)),
+		per_impression = IFNULL( #{perImpression},default(per_impression)),
+		per_click_type =IFNULL( #{perClickType},default(per_click_type)),
+		per_click = IFNULL( #{perClick},default(per_click)),
+		retarget = IFNULL( #{retarget},default(retarget)),
+		period = IFNULL( #{period},default(period)),
+		site = IFNULL( #{site},default(site)),		
+		position =IFNULL( #{position},default(position)),		
+		status = #{status},
+		updated = NOW()
+		<where>
+			id = #{id}
+		</where>
+	</update>
+	
+		<update id="editAdGroup.back" parameterType="com.cloudcross.ssp.model.AdGroup">
+		update t_adgroup
+		set name = #{adGroupName},
+		activate_time = #{startDate},
+		expire_time = #{endDate},		
+		totalbudget = #{totalBudget},
+		price = #{price},		
+		dailybudget = IFNULL(#{dailyBudget},default(dailybudget)),
+		impression = IFNULL(#{maxImpression},default(impression)),
+		click =IFNULL( #{maxClick},default(click)),
+		conversion=IFNULL( #{maxConversion},default(conversion)),
+		daily_impression = IFNULL(#{dailyMaxImpression},default(daily_impression)),
+		daily_click =IFNULL( #{dailyMaxClick},default(daily_click)),
+		daily_conversion = IFNULL(#{dailyMaxConversion},default(daily_conversion)),
+		per_impression_type = IFNULL(#{perImpressionType},default(per_impression_type)),
+		per_impression = IFNULL( #{perImpression},default(per_impression)),
+		per_click_type =IFNULL( #{perClickType},default(per_click_type)),
+		per_click = IFNULL( #{perClick},default(per_click)),
+		retarget = IFNULL( #{retarget},default(retarget)),
+		period = IFNULL( #{period},default(period)),
+		site = IFNULL( #{site},default(site)),		
+		position =IFNULL( #{position},default(position)),		
+		status = #{status},
+		updated = NOW()
+		<where>
+			id = #{id}
+		</where>
+	</update>
+	
+	
+	<select id="findAdgroupByAdvertiserId_Dashboard" parameterType="long" resultType="map">  
+    select g.id as adGroupId, g.name as adGroupName
+    from t_order o, t_adgroup g
+    where o.id = g.order_id and o.advertiser_id = #{advertiserId} and  date(g.active_time) &lt;=date(date_add(now(), interval -1 day)) and date(g.expire_time)>=date(date_add(now(), interval -1 day))
+    </select>
+	
+	<!-- ************************************************** -->
+	<!-- 根据广告主ID查询投放ID -->
+	<select id="findAllAdGroudByAdvertiserId" parameterType = "long" resultType = "long">
+		select id from t_adgroup where t_adgroup.advertiser_id = #{advertiserId}
+	</select>
+	<!-- 根据advertiser_id修改ad_group的supdated -->
+	<update id="updateSupdatedByAdvertiserID" parameterType="HashMap">
+		update t_adgroup
+			set t_adgroup.supdated= #{modifyDate}
+			where  t_adgroup.advertiser_id in
+			<foreach item="advertiserId" collection="advertiserIdList"
+		      open="(" separator="," close=")">
+		        #{advertiserId}
+			</foreach>
+	</update>
+	
+	<update id="updateSupdatedByOrderId" parameterType="HashMap">
+		update t_adgroup
+			set t_adgroup.supdated= #{modifyDate}
+			where  t_adgroup.order_id in
+			<foreach item="orderId" collection="orderIdList"
+		      open="(" separator="," close=")">
+		        #{orderId}
+			</foreach>
+	</update>
+	
+	<!-- 根据campaignid修改adgroup的supdated -->
+	<update id="updateSupdatedByCampaignId" parameterType="HashMap">
+		update t_adgroup
+			set t_adgroup.supdated= #{modifyDate}
+			where  t_adgroup.campaign_id in
+			<foreach item="campaignId" collection="campaignIdList"
+		      open="(" separator="," close=")">
+		        #{campaignId}
+			</foreach>
+	</update>
+	
+	<update id="updateStatusByAdvertiserId" parameterType="HashMap">
+		update t_adgroup
+			set status = #{status},updated = NOW()
+			where t_adgroup.advertiser_id in
+			<foreach item="advertiserId" collection="advertiserIdList"
+		      open="(" separator="," close=")">
+		        #{advertiserId}
+			</foreach>
+	</update>
+	
+	<update id="updateStatusByOrderId" parameterType="HashMap">
+		update t_adgroup 
+		set status=#{status},updated = #{modifyDate}
+		where t_adgroup.order_id in
+		<foreach item="orderId" collection="orderIdList" open="(" separator="," close=")">
+			#{orderId}
+		</foreach>
+	</update>
+	
+	<update id="updateStatusByCampaignId" parameterType="HashMap">
+		update t_adgroup 
+		set status=#{status},updated = #{modifyDate}
+		where t_adgroup.campaign_id in
+		<foreach item="campaignId" collection="campaignIdList" open="(" separator="," close=")">
+			#{campaignId}
+		</foreach>
+	</update>
+</mapper>

+ 41 - 0
src/main/java/com/cloudcross/ssp/model/mapper/adgroup-place.sql.xml

@@ -0,0 +1,41 @@
+<?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="adGroupPlaceSqlMapper">
+	<sql id="base_column">
+		id,
+		adgroup_id  as adGroupId,
+		place_id as placeId
+	</sql>
+
+	<insert id="addPlace" parameterType="com.cloudcross.ssp.model.AdGroupPlace">
+		insert into
+		t_adgroup_place (adgroup_id,place_id,supdated)
+		values (#{adGroupId},#{placeId},NOW())
+	</insert>
+
+	<select id="findAll" parameterType="long" resultType="com.cloudcross.ssp.model.AdGroupPlace">
+		select
+		<include refid="base_column"/>
+		from t_adgroup_place
+		<where>
+		adgroup_id = #{adGroupId}
+		</where>
+	</select>
+	
+	<delete id="delete" parameterType="long"> 
+	delete from t_adgroup_place where adgroup_id = #{adGroupId} 
+	</delete>
+	
+	<update id="updatedSupdate" parameterType="long">
+	update t_adgroup_place 
+	set supdated=NOW()
+	where adgroup_id= #{adGroupId}
+	</update>
+	
+	<select id="findAllByAdGroupId" parameterType="long" resultType="com.cloudcross.ssp.model.AdGroupPlace">
+		select
+		<include refid="base_column"/>
+		from t_adgroup_place
+		where adgroup_id = #{adGroupId}
+	</select>
+</mapper>

+ 27 - 0
src/main/java/com/cloudcross/ssp/model/mapper/adgroup-schedule.sql.xml

@@ -0,0 +1,27 @@
+<?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="adGroupScheduleSqlMapper">
+	<sql id="base_column">
+		id ,
+		adgroup_id as adGroupId ,
+		startdate as beginDate,
+		enddate as sEndDate,
+		dehours,
+		daily_impression as dailyImpression,
+		daily_click as dailyClick,
+		updated 
+	</sql>
+	
+	<insert  id="batchAdd" parameterType="map">
+	    insert into t_adgroup_schedule  (adgroup_id,startdate,enddate,dehours,updated)
+          values    <foreach collection="scheduleList" item="schedule" index="index" separator=",">
+    					(#{schedule.adGroupId},#{schedule.beginDate},#{schedule.sEndDate},#{schedule.dehours},
+    					#{schedule.updated})
+    			    </foreach> 
+	</insert>
+	
+	<delete id="deleteByAdGroupId" parameterType="long">
+		delete from t_adgroup_schedule where adgroup_id = #{adGroupId}
+	</delete>
+	
+</mapper>

+ 20 - 0
src/main/java/com/cloudcross/ssp/model/mapper/adgroup-zone.sql.xml

@@ -0,0 +1,20 @@
+<?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="adGroupZoneSqlMapper">
+
+
+	<insert id="addAdGroupZone" parameterType="com.cloudcross.ssp.model.AdGroupZone">
+		insert into t_adgroup_zone(adgroup_id,zone_id) values(#{adGroupId},#{zoneId})
+	</insert>
+	
+	<delete id="deleteByAdGroupId" parameterType="long">
+		delete from t_adgroup_zone where adgroup_id = #{adGroupId}
+	</delete>
+	
+	<select id="findAllByAdGroupId" parameterType="long" resultType="com.cloudcross.ssp.model.AdGroupZone">
+		select id, adgroup_id as adGroupId, zone_id as zoneId
+		from t_adgroup_zone
+		where adgroup_id = #{adGroupId}
+		order by zone_id asc
+ 	</select>
+</mapper>

+ 231 - 0
src/main/java/com/cloudcross/ssp/model/mapper/adv-balance.sql.xml

@@ -0,0 +1,231 @@
+<?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="advBalanceSqlMapper">
+	
+	<sql id="base_column">
+		id,
+		account_id as accountId,
+		t_agent_id as agentId, 
+		advertiser_id as advertiserId,
+		act_time as actTime,
+		num,
+		type,
+		charge,
+		allocate,
+		consume,
+	    t_advertiser.name as advertiserName,
+	    t_agent.name as agentName,                     
+		balance,
+		memo
+	</sql>
+	
+	<select id="findAdvBalance" parameterType="int" resultType="com.cloudcross.ssp.model.AdvBalance">
+		select * from 	t_adv_balance where id=#{advBalanceId}
+	</select>
+		
+	<select id="selectByParams"  parameterType="map" resultType="com.cloudcross.ssp.model.AdvBalance">
+		select 
+		a.act_time as actTime,
+		<if test="type != 'charge'">
+		 b.name as advertiserName,
+		</if>
+		<if test="type == 'charge'">
+		 d.name as agentName,
+		</if>
+		a.num,a.charge,a.allocate,a.consume,a.balance
+		from t_adv_balance a,
+		<if test="type != 'charge'">
+		 t_advertiser b
+		</if>
+		<if test="type == 'charge'">
+		 t_adv_agent d
+		</if>
+        where 
+     <!--     a.account_id=#{accountId} -->
+        a.agent_id=#{agentId}
+        <if test="adverId !=null ">
+		and a.advertiser_id = #{adverId} 
+		</if>
+        <if test="type == 'charge'">
+		and a.agent_id=d.id 
+		</if>
+        <if test="startDate!=null and endDate!=null"> 
+            and a.act_time &gt;= #{startDate} and #{endDate} &gt;=a.act_time
+		</if> 
+	    <if test="advertiserId !=null ">
+		and a.advertiser_id = #{advertiserId} 
+		</if>	
+		<if test="type != 'charge'">
+		 and  b.id= a.advertiser_id
+		 </if>	
+		 <if test="type!=null and type == 'charge'">
+		 and a.charge > 0
+		 and a.advertiser_id=0
+		 </if>
+		 <if test="type!=null and type == 'consume'">
+		 and a.consume > 0 
+		 </if>
+		 <if test="type!=null and type == 'allocate'">
+		 and a.allocate > 0 
+		 </if>
+		order by  a.act_time  desc
+		limit #{pager.offset}, #{pager.limit}
+	</select>	
+	
+    <select id="selectByParams2"  parameterType="map" resultType="com.cloudcross.ssp.model.AdvBalance">
+		select 
+		a.act_time as actTime,b.name as advertiserName,num,charge,allocate,consume,a.balance,d.name as agentName
+		from t_adv_balance a,t_advertiser b,t_account c,t_adv_agent d
+        where b.id= a.advertiser_id 
+        and a.account_id=c.id
+        and a.agent_id=b.agent_id=c.agent_id=d.id
+        and a.allocate != 0
+       <!--     a.account_id=#{accountId} -->
+        and a.agent_id=#{agentId}
+        <if test="adverId !=null ">
+		and a.advertiser_id = #{adverId} 
+		</if>
+        <if test="startDate!=null and endDate!=null"> 
+            and a.act_time &gt;= #{startDate} and #{endDate} &gt;=a.act_time
+		</if>  
+	    <if test="advertiserId !=null ">
+		and a.advertiser_id = #{advertiserId} 
+		</if>	
+		order by  a.id   desc
+		limit #{pager.offset}, #{pager.limit}
+	</select>
+	
+	
+	<select id="countByParams" parameterType="map" resultType="int">
+		select count(a.id)
+		from t_adv_balance a,
+		<if test="type != 'charge'">
+		 t_advertiser b
+		</if>
+		<if test="type == 'charge'">
+		 t_adv_agent d
+		</if>
+        where 
+      <!--     a.account_id=#{accountId} -->
+        a.agent_id=#{agentId}
+        <if test="adverId !=null ">
+		and a.advertiser_id = #{adverId} 
+		</if>
+        <if test="type == 'charge'">
+		and a.agent_id=d.id 
+		</if>
+        <if test="startDate!=null and endDate!=null"> 
+            and a.act_time &gt;= #{startDate} and #{endDate} &gt;=a.act_time
+		</if> 
+	    <if test="advertiserId !=null ">
+		and a.advertiser_id = #{advertiserId} 
+		</if>	
+		<if test="type != 'charge'">
+		 and  b.id= a.advertiser_id
+		 </if>	
+		 <if test="type!=null and type == 'charge'">
+		 and a.charge > 0
+		 and a.advertiser_id=0
+		 </if>
+		 <if test="type!=null and type == 'consume'">
+		 and a.consume > 0 
+		 </if>
+		 <if test="type!=null and type == 'allocate'">
+		 and a.allocate > 0 
+		 </if>
+	</select>
+	
+	<select id="countByParams2" parameterType="map" resultType="int">
+		select count(a.id)
+		from t_adv_balance a,t_advertiser b,t_account c,t_adv_agent d
+        where b.id= a.advertiser_id 
+        and a.account_id=c.id
+        and a.agent_id=b.agent_id=c.agent_id=d.id
+        and a.allocate != 0
+        <!--     a.account_id=#{accountId} -->
+        and a.agent_id=#{agentId}
+        <if test="adverId !=null ">
+		and a.advertiser_id = #{adverId} 
+		</if>
+		<if test="startDate!=null and endDate!=null"> 
+            and a.act_time &gt;= #{startDate} and #{endDate} &gt;=a.act_time
+		</if>  
+	
+      <!--  <if test="advertiserName!=null"> 
+            and b.name = #{advertiserName}
+	    </if>	 -->
+	    <if test="advertiserId !=null ">
+		and a.advertiser_id = #{advertiserId} 
+		</if>	
+	</select>
+	
+	<select id="selectById" parameterType="int" resultType="com.cloudcross.ssp.model.AdvBalance">
+		select 
+		<include refid="base_column" />
+		from t_adv_balance
+		<where>
+			id = #{id} 
+		</where>
+	</select>
+
+
+	<select id="countByParams.back" parameterType="map" resultType="int">
+		select count(id) from t_adv_balance
+		<where> 
+		advertiser_id = 0 and agent_id != 0 and status != -1
+		<if test="actTime != null">
+			and act_time like #{actTime}
+		</if>
+		</where>
+	</select>
+	
+	<select id="findByParams.back" parameterType="map" resultType="com.cloudcross.ssp.model.AdvBalance">
+		select <include refid="base_column"/>, name as agentName from t_adv_balance left join
+		t_adv_agent on t_adv_balance.agent_id = t_adv_agent.id
+		<where> 
+		t_adv_balance.advertiser_id = 0 and t_adv_balance.agent_id != 0 and t_adv_balance.status != -1
+		<if test="actTime != null">
+			and act_time like #{actTime}
+		</if>
+		</where>
+		order by act_time desc
+		limit #{pager.offset}, #{pager.limit} 
+	</select>
+	
+	<select id="findByParams1.back" parameterType="map" resultType="com.cloudcross.ssp.model.AdvBalance">
+	select <include refid="base_column"/>, name as agentName from t_adv_balance left join
+		t_adv_agent on t_adv_balance.agent_id = t_adv_agent.id
+		<where> 
+		t_adv_balance.advertiser_id = 0 and t_adv_balance.agent_id != 0 and t_adv_balance.status != -1
+		<if test="actTime != null">
+			and act_time like #{actTime}
+		</if>
+		</where>
+		order by act_time desc
+	</select>
+	
+	<select id="findBalanceByAgentId.back" parameterType="long" resultType="float">
+		select balance from t_adv_balance where agent_id = #{agentId} and status != -1 order by id desc limit 1
+	</select>
+	
+	
+	<insert id="add.back" parameterType="com.cloudcross.ssp.model.AdvBalance">
+		insert into t_adv_balance(account_id,agent_id,act_time,num,charge,balance) 
+		values(#{accountId},#{agentId},#{actTime},#{num},#{charge},#{balance})
+	</insert>
+	
+	<select id="findById.back" parameterType="long" resultType="com.cloudcross.ssp.model.AdvBalance">
+		select <include refid="base_column"/> from t_adv_balance
+		where id = #{id} and status != -1
+	</select>
+	
+	<update id="updateBalanceByAgentId.back" parameterType="map">
+		  update t_adv_balance set balance = #{balance}
+    	  where id in (select * from (select id from t_adv_balance where agent_id = #{agentId} and status != -1 order by id desc limit 1) as a)
+	</update>
+	
+	<delete id="deleteAdvBalanceById.back" parameterType="long">
+		delete from t_adv_balance where id = #{id}
+	</delete>
+
+</mapper>

+ 100 - 0
src/main/java/com/cloudcross/ssp/model/mapper/advAgent.sql.xml

@@ -0,0 +1,100 @@
+<?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="advAgentSqlMapper">
+
+	<sql id="base_column">
+		id,
+		name,
+		contacts,
+		tel,
+		mobile,
+		homepage as homePage,
+		address,
+		zip,
+		email,
+		title,
+		admin_id as adminId,
+		status
+	</sql>
+	
+	<select id="findById" parameterType="int" resultType="com.cloudcross.ssp.model.AdvAgent">
+		select 
+		<include refid="base_column" />
+		from t_adv_agent
+		<where>
+			id = #{id} and
+			status != -1
+		</where>
+	</select>
+	
+	<select id="findAll" resultType="com.cloudcross.ssp.model.AdvAgent">
+		select 
+		<include refid="base_column" />
+		from t_adv_agent
+		<where>
+			status != -1
+		</where>
+	</select>
+	
+	<select id="countByParams" parameterType="map" resultType="int">
+		select count(id)
+		from t_adv_agent where status != -1
+		<if test="value!=null">
+			and name like #{value}
+		</if>
+	</select>
+	
+	
+	<select id="findByParams" parameterType="map" resultType="int">
+		select 
+		<include refid="base_column" />
+		from t_adv_agent where status != -1
+		<if test="value!=null">
+			and name like #{value}
+		</if>
+		order by  id   desc
+	limit #{pager.offset}, #{pager.limit}
+	</select>
+	<select id="getNew" parameterType="com.cloudcross.ssp.model.AdvAgent" resultType="com.cloudcross.ssp.model.AdvAgent">
+		select 
+		<include refid="base_column" />
+		from t_adv_agent
+		<where>
+			status != -1 
+			and admin_id = #{adminId} 
+			and name = #{name}  
+		</where>
+	</select>
+	
+	<insert id="addAdvAgent" parameterType="com.cloudcross.ssp.model.AdvAgent">
+		insert into t_adv_agent(name,contacts,tel,mobile,homepage,address,zip,email,title,admin_id,status)
+		values(#{name},#{contacts},#{tel},#{mobile},#{homePage},#{address},#{zip},#{email},#{title},#{adminId},#{status})
+	</insert>
+	
+	<update id="editAdvAgent" parameterType="com.cloudcross.ssp.model.AdvAgent">
+		update t_adv_agent
+		set name=#{name},
+			contacts=#{contacts},
+			tel=#{tel},
+			mobile=#{mobile},
+			homepage=#{homePage},
+			address=#{address},
+			zip=#{zip},
+			email=#{email},
+			title=#{title},
+			admin_id=#{adminId},
+			status=#{status}
+		where id=#{id}
+	</update>
+	
+	<update id="updateAdvAgentStatus" parameterType="HashMap">
+		update t_adv_agent
+			set status = #{status}
+			where id in
+			<foreach item="advAgentId" collection="advAgentIdList"
+		      open="(" separator="," close=")">
+		        #{advAgentId}
+			</foreach>
+	</update>
+	
+</mapper>

+ 306 - 0
src/main/java/com/cloudcross/ssp/model/mapper/advertiser.sql.xml

@@ -0,0 +1,306 @@
+<?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="advertiserSqlMapper">
+	
+	<sql id="base_column">
+		t_advertiser.id as id,
+		t_advertiser.agent_id as agentId,
+		industry_id as industryId,
+		t_advertiser.name as name,
+		reg_name as regName,
+		homepage as homePage,
+		t_advertiser.contacts,
+		t_advertiser.tel as tel,
+		t_advertiser.email as email,
+		t_advertiser.balance as balance,
+		t_advertiser.status as status,
+		t_advertiser.memo as memo,
+		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,
+		t_advertiser.admin_id as adminId,
+		t_advertiser.updated as updated
+	</sql>
+	
+	<select id="selectById" parameterType="int" resultType="com.cloudcross.ssp.model.Advertiser">
+		select 
+		<include refid="base_column" />
+		from t_advertiser
+		<where>
+			id = #{id} and
+			status != -1
+		</where>
+	</select>
+	
+	<select id="selectByAgentId" parameterType="int" resultType="com.cloudcross.ssp.model.Advertiser">
+		select 
+		<include refid="base_column" />
+		from t_advertiser
+		<where>
+			agent_id = #{id} and
+			status != -1
+		</where>
+	</select>
+	
+	<select id="selectByName" parameterType="String" resultType="long">
+		select 
+		max(id)
+		from t_advertiser
+		<where>
+		name = #{name} and
+			status != -1
+		</where>
+	</select>
+		
+	<select id="selectByOperatoradvertiser" parameterType="int" resultType="com.cloudcross.ssp.model.Advertiser">
+		select 
+		<include refid="base_column" />
+		from t_advertiser
+		<where>
+			agent_id = #{operatorId} and
+			status != -1.
+		</where>
+	</select>
+	
+	<select id="selectByOperatoroperator" parameterType="int" resultType="com.cloudcross.ssp.model.Advertiser">
+		select 
+		<include refid="base_column" />
+		from t_advertiser
+		<where>
+			operator_id = #{operatorId} and
+			status != -1.
+		</where>
+	</select>
+		
+	<select id="selectByParamsadvertiser"  parameterType="map" resultType="com.cloudcross.ssp.model.Advertiser">
+		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 and c.status != -1
+		 where 1 = 1 
+		 <if test="value!=null">
+			and t_advertiser.name like #{value}
+		</if>
+		 <if test="status!=null">	
+			and t_advertiser.status = #{status}
+		</if>
+		 <if test="industryId!=null">	
+			and t_advertiser.industry_id = #{industryId}
+		</if>
+		 <if test="agentId!=null">	
+			and t_advertiser.agent_id = #{agentId}
+		</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="selectByParamsback"  parameterType="map" resultType="com.cloudcross.ssp.model.Advertiser">
+	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="value!=null">
+		and t_advertiser.name like #{value}
+	</if>
+	 <if test="status!=null">	
+		and t_advertiser.status = #{status}
+	</if>
+	 <if test="industryId!=null">	
+		and t_advertiser.industry_id = #{industryId}
+	</if>
+	 <if test="agentId!=null">	
+		and t_advertiser.agent_id = #{agentId}
+	</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="selectByParamsoperator"  parameterType="map" resultType="com.cloudcross.ssp.model.Advertiser">
+		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="status!=null">	
+			and t_advertiser.status = #{status}
+		</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="selectByStatus"  parameterType="map" resultType="com.cloudcross.ssp.model.Advertiser">
+		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.status = #{status}
+		 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 status = #{status}
+	</select>
+	
+	<select id="countByParamsadvertiser" parameterType="map" resultType="int">
+		select count(a.id)
+		from t_advertiser a where status != -1
+		<if test="value!=null">
+			and a.name like #{value}
+		</if>
+		 <if test="status!=null">	
+			and a.status = #{status}
+		</if>
+		 <if test="industryId!=null">	
+			and a.industry_id = #{industryId}
+		</if>
+		 <if test="agentId!=null">	
+			and a.agent_id = #{agentId}
+		</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="status!=null">	
+			and a.status = #{status}
+		</if>
+		 <if test="industryId!=null">	
+			and a.industry_id = #{industryId}
+		</if>
+	</select>
+	
+	<insert id="addAdvertiseradvertiser" parameterType="com.cloudcross.ssp.model.Advertiser">
+		insert into t_advertiser(industry_id,agent_id,name,reg_name,homepage,contacts,tel,email,memo
+		,cpi_path,licence_path,id_path,org_path,check_memo,updated)
+		values(#{industryId},#{agentId},#{name},#{regName},#{homePage},#{contacts},#{tel}, #{email},#{memo}
+		,#{cpiPath},#{licencePath},#{idPath}, #{orgPath},#{checkMemo},NOW())
+	</insert>
+	
+	<insert id="addAdvertiserback" parameterType="com.cloudcross.ssp.model.Advertiser">
+		insert into t_advertiser(industry_id,name,reg_name,homepage,contacts,tel,email,memo
+		,cpi_path,licence_path,id_path,org_path,check_memo,updated)
+		values(#{industryId},#{name},#{regName},#{homePage},#{contacts},#{tel}, #{email},#{memo}
+		,#{cpiPath},#{licencePath},#{idPath}, #{orgPath},#{checkMemo},NOW())
+	</insert>
+	
+	<insert id="addAdvertiseroperator" parameterType="com.cloudcross.ssp.model.Advertiser">
+		insert into t_advertiser(industry_id,name,reg_name,homepage,contacts,tel,email,updated,memo)
+		values(#{industryId},#{name},#{regName},#{homePage},#{contacts},#{tel}, #{email},#{updated},#{memo})
+	</insert>
+	
+	<update id="editAdvertiseradvertiser" parameterType="com.cloudcross.ssp.model.Advertiser">
+		update t_advertiser 
+		set industry_id = #{industryId},name = #{name},reg_name = #{regName},homepage = #{homePage},contacts = #{contacts},tel=#{tel}
+		,email = #{email},memo = #{memo},updated = NOW(),admin_id = #{adminId}
+		,cpi_path = #{cpiPath},licence_path = #{licencePath},id_path = #{idPath},org_path = #{orgPath},check_memo = #{checkMemo}
+		where t_advertiser.id=#{id}
+	</update>
+	
+	<update id="editAdvertiserback" parameterType="com.cloudcross.ssp.model.Advertiser">
+		update t_advertiser 
+		set industry_id = #{industryId},name = #{name},reg_name = #{regName},homepage = #{homePage},contacts = #{contacts},tel=#{tel}
+		,email = #{email},memo = #{memo},updated = NOW()
+		,cpi_path = #{cpiPath},licence_path = #{licencePath},id_path = #{idPath},org_path = #{orgPath},check_memo = #{checkMemo}
+		where t_advertiser.id=#{id}
+	</update>
+	
+	<update id="editAdvertiseroperator" parameterType="com.cloudcross.ssp.model.Advertiser">
+	update t_advertiser 
+	set industry_id = #{industryId},name = #{name},reg_name = #{regName},homepage = #{homePage},contacts = #{contacts},tel=#{tel}
+	,email = #{email},updated = #{updated},memo = #{memo}
+	where t_advertiser.id=#{id}
+	</update>
+	
+	<update id="updateAdvertiserStatus" parameterType="HashMap">
+		update t_advertiser 
+			set status = #{status},updated = #{modifyDate}
+			where t_advertiser.id in
+			<foreach item="advertiserId" collection="advertiserIdList"
+		      open="(" separator="," close=")">
+		        #{advertiserId}
+			</foreach>
+	</update>
+	<update id="updateSupdated" parameterType="HashMap">
+		update t_adgroup
+			set t_adgroup.supdated= NOW()
+			where  t_adgroup.advertiser_id in
+			<foreach item="advertiserId" collection="advertiserIdList"
+		      open="(" separator="," close=")">
+		        #{advertiserId}
+			</foreach>
+	</update>
+	
+	<select id="sumBalanceById" parameterType="map" resultType="double">
+		 select sum(ad.balance) from t_advertiser ad
+		 where status != -1
+		<if test="agentId != null">		    
+		  and ad.agent_id=#{agentId} 
+	   </if>  
+	</select>
+	
+	<!-- 导出Excel用 -->
+	<select id="findDeliverEffectAnalysis" parameterType="map" resultType="com.cloudcross.ssp.model.Advertiser">
+		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="status!=null">	
+			and t_advertiser.status = #{status}
+		</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
+	</select>
+	
+	<select id="selectAdvertiserNameById" parameterType="int" resultType="String">
+		select name from t_advertiser where id = #{id}
+	</select>
+</mapper>

+ 143 - 0
src/main/java/com/cloudcross/ssp/model/mapper/audit-banner.sql.xml

@@ -0,0 +1,143 @@
+<?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="auditBannerSqlMapper">
+	<sql id="base_column">
+		id,
+		banner_template_id as bannerTemplateId,
+		order_id as orderId,
+		campaign_id as campaignId,
+		adgroup_id as adGroupId,
+		visit_address as visitAddress,
+		click_address as clickAddress,
+		impression_address as impressionAddress
+		checked,
+		updated,
+		memo
+	</sql>
+	
+	<select id="countByParams" parameterType="map" resultType="int">
+	select count(a.id) from t_banner a ,t_banner_template b 
+		<where>
+		b.status != -1
+				and a.banner_template_id = b.id 
+				<if test="key!=null and value!=null">
+					<choose>
+						<when test="key=='name'">
+							and b.name like #{value}
+						</when>
+					</choose>
+				</if>
+				<if test="checked !=null">
+					and a.checked like #{checked}
+				</if>
+		</where>
+	</select>
+	
+	<select id="findByParams" parameterType="map" resultMap="AuditBanner">  
+	
+	select a.id as id,a.banner_template_id as bannerTemplateId,a.order_id as orderId,a.campaign_id as campaignId,a.adgroup_id as adGroupId,a.visit_address as visitAddress,a.click_address as clickAddress,a.impression_address as impressionAddress,
+	a.checked as checked,a.updated as updated,a.memo as memo,
+	b.id as bannerTemplateId,b.advertiser_id as advertiserId,b.name as name,b.path as path,b.path_small as pathSmall,b.type as type,b.width as width,b.height as height,b.status as status,b.updated as updated ,
+(select	name from t_advertiser where id=b.advertiser_id) as advertiserName,(select name from t_industry where id = (select industry_id from t_advertiser where id=b.advertiser_id)) as industryName from t_banner a
+    left join t_banner_template b on a.banner_template_id=b.id
+	left join t_order c on a.order_id= c.id
+	left JOIN t_advertiser d on c.advertiser_id = d.id
+	left join t_industry e on d.industry_id = e.id
+	<where>
+	b.status != -1
+			<if test="key!=null and value!=null">
+					<choose>
+						<when test="key=='name'">
+							and b.name like #{value}
+						</when>
+					</choose>
+			</if>
+			<if test="checked !=null">
+				and a.checked like #{checked}
+			</if>
+	</where>
+	order by a.id   desc
+	limit #{pager.offset}, #{pager.limit}
+	</select>
+	
+	<select id="findAudit" parameterType="map" resultMap="AuditBanner">  
+	
+	select a.id as id,a.banner_template_id as bannerTemplateId,a.order_id as orderId,a.campaign_id as campaignId,a.adgroup_id as adGroupId,a.visit_address as visitAddress,a.click_address as clickAddress,a.impression_address as impressionAddress,
+	a.checked as checked,a.updated as updated,a.memo as memo,
+	b.id as bannerTemplateId,b.advertiser_id as advertiserId,b.name as name,b.path as path,b.path_small as pathSmall,b.type as type,b.width as width,b.height as height,b.status as status,b.updated as updated ,
+	(select	name from t_advertiser where id=b.advertiser_id) as advertiserName,(select name from t_industry where id = (select industry_id from t_advertiser where id=b.advertiser_id)) as industryName from t_banner a
+    left join t_banner_template b on a.banner_template_id=b.id
+	left join t_order c on a.order_id= c.id
+	left JOIN t_advertiser d on c.advertiser_id = d.id
+	left join t_industry e on d.industry_id = e.id
+	<where>
+	b.status != -1
+			<if test="key!=null and value!=null">
+					<choose>
+						<when test="key=='name'">
+							and b.name like #{value}
+						</when>
+					</choose>
+			</if>
+			<if test="checked !=null">
+				and a.checked like #{checked}
+			</if>
+	</where>
+	order by a.id   desc
+	</select>
+	
+	<resultMap type="com.cloudcross.ssp.model.AuditBanner" id="AuditBanner">
+	<id property="id" column="id"/>
+	  <result property="bannerTemplateId" column="bannerTemplateId"/> 
+	<result property="orderId" column="orderId"/>
+	<result property="campaignId" column="campaignId"/> 
+  	<result property="adGroupId" column="adGroupId"/>   
+    <result property="visitAddress" column="visitAddress"/> 
+    <result property="clickAddress" column="clickAddress"/> 
+    <result property="impressionAddress" column="impressionAddress"/>
+    <result property="checked" column="checked"/>
+    <result property="updated" column="updated"/> 
+     <result property="memo" column="memo"/>
+     <result property="industryName" column="industryName"/>
+     <result property="advertiserName" column="advertiserName"/>
+    <association property="bannerTemplate" javaType="com.cloudcross.ssp.model.BannerTemplate" resultMap="bannerTemplate"/>
+</resultMap>  
+<resultMap type="com.cloudcross.ssp.back.model.BannerTemplate" id="bannerTemplate">  
+   <id property="id" column="bannerTemplateId"/>  
+   <result property="advertiserId" column="advertiserId"/> 
+   <result property="name" column="name"/>
+    <result property="path" column="path"/>
+    <result property="pathSmall" column="pathSmall"/>  
+   <result property="type" column="type"/>
+   <result property="width" column="width"/> 
+   <result property="height" column="height"/> 
+   <result property="status" column="status"/>   
+   <result property="updated" column="updated"/>     
+</resultMap>  
+	
+	<update id="updateBannerStatus" parameterType="HashMap">
+		update t_banner a,t_banner_template b
+		set a.checked=#{checked},b.updated = #{updated},a.updated = #{updated}
+		<if test="memo != null">
+		,a.memo = #{memo}
+		</if>
+		where
+		a.banner_template_id = b.id and
+		a.id in
+		<foreach item="id" collection="auditBannerIdList" open="(" separator=","
+			close=")">
+			#{id}
+		</foreach>
+	</update>
+	
+	<update id="updateOperatorBannerTime" parameterType="HashMap">
+		update t_banner_operator
+		set supdated = #{supdated}
+		where banner_id in
+		<foreach item="id" collection="auditBannerIdList" open="(" separator=","
+			close=")">
+			#{id}
+		</foreach>
+	</update>
+	
+</mapper>

+ 237 - 0
src/main/java/com/cloudcross/ssp/model/mapper/audit.sql.xml

@@ -0,0 +1,237 @@
+<?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>

+ 343 - 0
src/main/java/com/cloudcross/ssp/model/mapper/banner-template.sql.xml

@@ -0,0 +1,343 @@
+<?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="bannerTemplateSqlMapper">
+	<sql id="base_columnadvertiser">
+		t_banner_template.id,
+		agent_id as agentId,
+		advertiser_id as advertiserId,
+		name,
+		path,
+		path_small as smallPath,
+		type,
+		width,
+		height,
+		t_banner_template.status,
+		t_banner_template.updated
+	</sql>
+	
+	<sql id="base_columnoperator">
+		id,
+		advertiser_id as advertiserId,
+		name,
+		path,
+		type,
+		width,
+		height,
+		status,
+		updated
+	</sql>
+	<select id="countByParamsoperator" parameterType="map" resultType="int">
+		select count(id) 
+		from t_banner_template
+		<where>
+			id in (select banner_template_id from t_banner where adgroup_id=#{adGroupId})
+			and status!=-1
+			<if test="key!=null and value!=null">
+				<choose>
+					<when test="key=='name'">
+					and name like #{value}
+					</when>
+				</choose>
+			</if>
+		</where>
+	</select>
+	
+	<select id="countByParams3" parameterType="map" resultType="int">
+		select count(id)
+		from t_banner_template
+		<where>
+		id not in (select banner_template_id from t_banner where adgroup_id=#{adGroupId})
+			and status != -1
+			<if test="advertiserId != null">
+				and advertiser_id=#{advertiserId}
+			</if>
+		</where>
+	</select>
+	
+	<select id="findByParams" parameterType="map" resultType="com.cloudcross.ssp.model.BannerTemplate">
+		select t_banner_template.id as id, t_banner_template.advertiser_id as advertiser_id,t_banner_template.name as name,
+        t_banner_template.path as path,t_banner_template.type as type,t_banner_template.width as width,t_banner_template.height as height,
+        t_banner_template.status as status,t_banner_template.updated as updated,t_banner.id as TBannerId from t_banner_template left join t_banner on t_banner_template.id = t_banner.banner_template_id
+        <where> 
+        t_banner.adgroup_id = #{adGroupId} 
+			and status!=-1
+			<if test="key!=null and value!=null">
+				<choose>
+					<when test="key=='name'">
+					and name like #{value}
+					</when>
+				</choose>
+			</if>
+		</where>
+		order by id desc
+		limit #{pager.offset}, #{pager.limit}
+	</select>
+	<select id="findById" parameterType="long" resultType="com.cloudcross.ssp.model.BannerTemplate">
+		select
+		<include refid="base_column"/>
+		from t_banner_template
+		<where>
+		id = #{id}
+		</where>
+	</select>
+	
+	<update id="updateBannerTemplateStatus" parameterType="HashMap">
+		update t_banner_template
+		set status=#{status},updated = #{updated}
+		where id in
+		<foreach item="id" collection="idList" open="(" separator=","
+			close=")">
+			#{id}
+		</foreach>
+	</update>
+	
+	<update id="updateBannerTime" parameterType="HashMap">
+		update t_banner 
+		set supdated=#{updataTime}
+		where banner_template_id in 
+		<foreach item="id" collection="idList" open="(" separator=","
+			close=")">
+			#{id}
+		</foreach>
+	</update>
+	
+	<!-- 模板状态改变,更形t_banner_operator时间 -->
+	<update id="updateBannerOperatorTime" parameterType="HashMap">
+		update t_banner_operator 
+		set supdated=#{updataTime}
+		where banner_id in (select id from t_banner 
+		where t_banner.banner_template_id in
+		<foreach item="id" collection="idList" open="(" separator=","
+			close=")">
+			#{id}
+		</foreach>)
+	</update>
+	
+<update id="updataDeleteBannerTemplateStatus" parameterType="HashMap">
+update t_banner_template a,t_banner b 
+set a.status=#{status},b.status=#{status},a.updated = #{updated}, b.updated = #{updated},b.supdated = #{updated} 
+where b.banner_template_id = a.id and a.id in 
+<foreach close=")" separator="," open="(" collection="idList" item="id"> #{id} </foreach>
+
+</update>
+	
+	<select id="findByCampaignId" parameterType="long" resultType="com.cloudcross.ssp.model.AdGroup">
+	    select
+		<include refid="base_column"/>
+		from t_adgroup 
+		where campaign_id=#{campaignId} and t_adgroup.status!=-1
+	</select>
+	
+		
+	<update id="alterName" parameterType="map">
+		update t_banner_template set name = #{name} , updated = now() where id = #{id}
+	</update>
+	
+	<update id="editadvertiser" parameterType="com.cloudcross.ssp.model.BannerTemplate">
+		update t_banner_template 
+		set name = #{name},
+		path = #{path},
+		path_small = #{pathSmall},
+		width = #{width},
+		height = #{height},
+		type = ${type},
+		updated = #{updated}
+		WHERE id = #{id}
+	</update>
+	
+	<!-- 替换素材对应创意审核状态更新 -->
+	<update id="updataBannerReplace" parameterType="map">
+	update t_banner 
+	set checked = 0,
+		updated = #{supdated},
+		supdated = #{supdated}	
+	where banner_template_id = #{id}
+	</update>
+	<update id="updataBannerOperatorReplace" parameterType="map">
+	update t_banner_operator 
+	set checked = 0,
+		supdated = #{supdated}	
+	where banner_id in (select id from t_banner where banner_template_id =#{id})
+	</update>
+	<update id="updataIds" parameterType="com.cloudcross.ssp.model.BannerTemplate">
+		update t_banner_template a
+		set a.advertiser_id = #{advertiserId},
+		a.agent_id = #{agentId}	
+		WHERE a.id = #{id}
+	</update>
+		<update id="editoperator" parameterType="com.cloudcross.ssp.model.BannerTemplate">
+		update t_banner_template a,t_banner b
+		set a.name = #{name},
+		a.updated = #{updated},
+		b.visit_address = #{banner.visitAddress},
+		b.click_address = #{banner.clickAddress},
+		b.impression_address = #{banner.impressionAddress}
+		WHERE a.id = b.banner_template_id and a.id = #{id}
+	</update>
+	<select id="countByParams2advertiser" parameterType="map" resultType="int">
+		select count(t_banner_template.id)
+		from t_banner_template
+		<where>
+			<if test="status != null">
+			t_banner_template.status=#{status}
+			</if>
+			<if test="status == null">
+				t_banner_template.status in (0,1)
+			</if>
+			<if test="agentId != null">
+				and agent_id = #{agentId} 
+			</if>
+			<if test="type != null">
+				and type=#{type}
+			</if>
+			<if test="height != null">
+				and height=#{height}
+			</if>
+			<if test="width != null">
+				and width=#{width}
+			</if>
+			<if test="advertiserId != null">
+				and advertiser_id = #{advertiserId}
+			</if>
+			<if test="value != null">
+				and name like #{value}
+			</if>
+		</where>
+
+	</select>
+	
+	<select id="countByParams2operator" parameterType="map" resultType="int">
+		select count(id)
+		from t_banner_template
+		<where>
+			<if test="status != null">
+				status=#{status}
+			</if>
+			<if test="status == null">
+				status in (0,1)
+			</if>
+			<!-- <if test="advertiserId != null"> and advertiser_id=#{advertiserId} 
+				</if> -->
+			<if test="type != null">
+				and type=#{type}
+			</if>
+			<if test="height != null">
+				and height=#{height}
+			</if>
+			<if test="width != null">
+				and width=#{width}
+			</if>
+			<if test="value != null">
+				and name like #{value}
+			</if>
+		</where>
+
+	</select>
+
+	<select id="findByParams2advertiser" parameterType="map" resultType="com.cloudcross.ssp.model.BannerTemplate">
+		select <include refid="base_column"/>
+		from t_banner_template
+		<where>
+			<if test="status != null">
+				t_banner_template.status=#{status}
+			</if>
+			<if test="status == null">
+				t_banner_template.status in (0,1)
+			</if>
+			<if test="agentId != null">
+				and agent_id = #{agentId} 
+			</if>
+			<if test="type != null">
+				and type=#{type}
+			</if>
+			<if test="height != null">
+				and height=#{height}
+			</if>
+			<if test="width != null">
+				and width=#{width}
+			</if>
+			<if test="advertiserId != null">
+				and advertiser_id = #{advertiserId}
+			</if>
+			<if test="value != null">
+				and name like #{value}
+			</if>
+		</where>
+		order by t_banner_template.id desc
+		limit #{pager.offset}, #{pager.limit}
+	</select>
+	
+	<select id="countByParams3" parameterType="map" resultType="int">
+		select count(id)
+		from t_banner_template
+		<where>
+		id not in (select banner_template_id from t_banner where adgroup_id=#{adGroupId})
+			and t_banner_template.status != -1
+			<if test="advertiserId != null">
+				and advertiser_id=#{advertiserId}
+			</if>
+			<if test="type != null">
+				and type=#{type}
+			</if>
+			<if test="height != null">
+				and height=#{height}
+			</if>
+			<if test="width != null">
+				and width=#{width}
+			</if>
+			<if test="value != null">
+				and name like #{value}
+			</if>
+			
+		</where>
+	</select>
+		
+	<select id="findByParams4advertiser" parameterType="map" resultType="com.cloudcross.ssp.model.BannerTemplate">
+		select
+		<include refid="base_column"/>
+		from t_banner_template
+		<where>
+		id not in (select banner_template_id from t_banner where adgroup_id=#{adGroupId})
+		and t_banner_template.status != -1
+			<if test="advertiserId != null">
+				and advertiser_id=#{advertiserId}
+			</if>
+			<if test="type != null">
+				and type = #{type}
+			</if>
+			<if test="height != null">
+				and height = #{height}
+			</if>
+			<if test="width != null">
+				and width = #{width}
+			</if>
+			<if test="value != null">
+				and name like #{value}
+			</if>
+		</where>
+		order by  id  desc
+		limit #{pager.offset}, #{pager.limit}
+	</select>
+
+<select id="findByParams4operator" parameterType="map" resultType="com.cloudcross.ssp.model.BannerTemplate">
+		select
+		<include refid="base_column"/>
+		from t_banner_template
+		<where>
+		id not in (select banner_template_id from t_banner where adgroup_id=#{adGroupId})
+		and	status != -1
+			<if test="advertiserId != null">
+				and advertiser_id=#{advertiserId}
+			</if>
+		</where>
+		order by  id  desc
+		limit #{pager.offset}, #{pager.limit}
+	</select>
+	<insert id="addBannerTemplate" parameterType="com.cloudcross.ssp.model.BannerTemplate" useGeneratedKeys="true"
+        keyProperty="id">
+insert into t_banner_template (agent_id,advertiser_id,name,path,path_small,type,width,height,status,updated) 
+values(#{agentId},#{advertiserId},#{name},#{path},#{pathSmall},#{type},#{width},#{height},#{status},#{updated})	
+
+</insert>
+	
+</mapper>

+ 473 - 0
src/main/java/com/cloudcross/ssp/model/mapper/banner.sql.xml

@@ -0,0 +1,473 @@
+<?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="bannerSqlMapper">
+	<sql id="base_column_advertiser">
+		id,
+		banner_template_id as bannerTemplateId,
+		order_id as orderId,
+		campaign_id as campaignId,
+		adgroup_id as adGroupId,
+		visit_address as visitAddress,
+		click_address as clickAddress,
+		impression_address as impressionAddress
+		status,
+		checked,
+		updated,
+		supdated
+	</sql>
+	
+	<sql id="base_column_operator">
+		b.id as bannerId,
+		banner_template_id as bannerTemplateId,
+		order_id as orderId,
+		campaign_id as campaignId,
+		adgroup_id as adGroupId,
+		visit_address as visitAddress,
+		click_address as clickAddress,
+		impression_address as impressionAddress,
+		b.checked as checked,
+		IFNULL(bo.checked,-1) as operatorChecked,
+		b.updated as updated,
+		memo
+	</sql>
+	
+	<sql id="banner_template_base_column">
+		bt.id as banner_templateId,
+		advertiser_id as advertiserId,
+		name,
+		path,
+		path_small as pathSmall,
+		type,
+		width,
+		height,
+		bt.status as status,
+		bt.updated as bannerTemplateUpdated
+	</sql>
+	
+	<delete id="deleteBanner" parameterType="HashMap">
+		delete from t_banner where
+		id in
+		<foreach item="id" collection="idList" open="(" separator=","
+			close=")">
+			#{id}
+		</foreach>
+	</delete>
+	
+	<update id="updateBannerStatus" parameterType="HashMap">
+		update t_banner 
+		set status=#{status},updated = #{updated},supdated = #{supdated} 
+		where id in
+		<foreach item="id" collection="idList" open="(" separator=","
+			close=")">
+			#{id}
+		</foreach>
+		
+	</update>
+	
+	<select id="countByParams" parameterType="map" resultType="int">
+	select count(a.id) from t_banner a ,t_banner_template b 
+		<where>
+				a.banner_template_id = b.id and a.adgroup_id=#{adGroupId}
+				<if test="value !=null">
+				and name like #{value}
+				</if>
+		</where>
+		and  a.status != -1
+	</select>
+	
+	<select id="countByAdGroupId" parameterType="long" resultType="int">
+	select count(id) from t_banner
+	where adgroup_id = #{adGroupId}
+	</select>
+	
+	<select id="findById1" parameterType="long" resultType="com.cloudcross.ssp.model.Banner">
+		select
+		<include refid="base_column"/>
+		from t_banner
+		<where>
+		adgroup_id = #{adGroupId}
+		</where>
+	</select>
+	
+	<select id="findById" parameterType="long" resultMap="Banner">
+		select a.id as id,a.banner_template_id as bannerTemplateId,a.order_id as orderId,a.campaign_id as campaignId,a.adgroup_id as adGroupId,a.visit_address as visitAddress,
+	a.click_address as clickAddress,a.impression_address as impressionAddress,a.status as status1,a.checked as checked,a.updated as updated, b.id as bannerTemplateId,b.agent_id as agentId,b.advertiser_id as advertiserId,b.name as name,b.path as path,b.path_small as pathSmall,b.type as type,b.width as width,b.height as height,b.status as status,b.updated as updated from t_banner a LEFT JOIN t_banner_template b on a.banner_template_id=b.id   
+		<where>
+				a.id=#{id}
+		</where>
+	</select>
+	
+	<select id="findById" parameterType="int" resultMap="banner">  
+		select <include refid="base_column"/> ,<include refid="banner_template_base_column"/>
+		from t_banner b inner join t_banner_template bt on b.banner_template_id = bt.id left join t_banner_operator bo
+on b.id=bo.banner_id where b.id=#{id}
+	</select>
+	
+	<select id="findByParams" parameterType="map" resultMap="Banner">  
+		select a.id as id,a.banner_template_id as bannerTemplateId,a.order_id as orderId,a.campaign_id as campaignId,a.adgroup_id as adGroupId,a.visit_address as visitAddress,
+	a.click_address as clickAddress,a.impression_address as impressionAddress,a.status as status1,a.checked as checked,a.updated as updated,a.supdated as supdated,b.id as bannerTemplateId,b.agent_id as agentId,b.advertiser_id as advertiserId,b.agent_id as agentId,b.name as name,b.path as path,b.path_small as pathSmall,b.type as type,b.width as width,b.height as height,b.status as status,b.updated as updated from t_banner a LEFT JOIN t_banner_template b on a.banner_template_id=b.id   
+		<where>
+				a.adgroup_id=#{adGroupId}
+				<if test="value !=null">
+				and name like #{value}
+				
+				</if>
+		</where>
+		and  a.status != -1
+		order by a.id   desc
+		limit #{pager.offset}, #{pager.limit}
+	</select>
+	
+	<select id="countByZoneSize" parameterType="HashMap" resultType="int">
+		select count(*) from t_banner b inner join t_banner_template bt on b.banner_template_id = bt.id 
+		where bt.status != -1 and checked != 2 and checked !=0
+	   	<if test="zoneList.size()>0">
+			and
+		   	<foreach item="zone" collection="zoneList"
+		   		 open="(" separator="or" close=")" >
+			      bt.width &lt;= #{zone.width} and bt.height &lt;= #{zone.height}
+			</foreach>	
+	</if>
+		<if test="searchKey!=null and searchValue!=null">
+			and bt.name like #{searchValue}
+		</if>
+		<if test="checked!=null">
+			and b.checked like #{checked}
+		</if>
+	</select>
+	
+	<select id="findByZoneSize" parameterType="HashMap" resultMap="banner">  
+		select <include refid="base_column_operator"/> ,<include refid="banner_template_base_column"/>
+		from t_banner b inner join t_banner_template bt on b.banner_template_id = bt.id
+		where bt.status != -1 and checked != 2 and checked !=0
+		<if test="zoneList.size()>0">
+			and
+		   	<foreach item="zone" collection="zoneList"
+		   		 open="(" separator="or" close=")" >
+			      bt.width &lt;= #{zone.width} and bt.height &lt;= #{zone.height}
+			</foreach>
+		</if>
+	   	<if test="searchKey!=null and searchValue!=null">
+			and bt.name like #{searchValue}
+		</if>
+		<if test="checked!=null">
+			and b.checked like #{checked}
+		</if>
+	    order by  b.id   desc
+	    <if test="pager!=null">
+		limit #{pager.offset}, #{pager.limit}
+		</if>
+	</select>
+
+<resultMap type="com.cloudcross.ssp.model.Banner" id="Banner">
+	<id property="id" column="id"/>
+	  <result property="bannerTemplateId" column="bannerTemplateId"/> 
+	   <result property="status" column="status1"/>   
+	<result property="orderId" column="orderId"/>
+	<result property="campaignId" column="campaignId"/> 
+  	<result property="adGroupId" column="adGroupId"/>   
+    <result property="visitAddress" column="visitAddress"/> 
+    <result property="clickAddress" column="clickAddress"/> 
+    <result property="impressionAddress" column="impressionAddress"/>
+    <result property="checked" column="checked"/>
+    <result property="updated" column="updated"/>
+    <result property="supdated" column="supdated"/>  
+    <association property="bannerTemplate" javaType="com.cloudcross.ssp.model.BannerTemplate" resultMap="bannerTemplate"/>
+</resultMap>  
+<resultMap type="com.cloudcross.ssp.model.BannerTemplate" id="bannerTemplate">  
+   <id property="id" column="bannerTemplateId"/>  
+   <result property="advertiserId" column="advertiserId"/>
+   <result property="agentId" column="agentId"/>  
+   <result property="name" column="name"/>
+    <result property="path" column="path"/> 
+    <result property="pathSmall" column="pathSmall"/>
+   <result property="type" column="type"/>
+   <result property="width" column="width"/> 
+   <result property="height" column="height"/> 
+   <result property="status" column="status"/>   
+   <result property="updated" column="updated"/>     
+</resultMap>  
+
+<resultMap type="com.cloudcross.ssp.model.Banner" id="banneroperator">
+		<id property="id" column="bannerId"/>
+		<result property="bannerTemplateId" column="bannerTemplateId"/> 
+		<result property="orderId" column="orderId"/>
+		<result property="campaignId" column="campaignId"/> 
+	  	<result property="adGroupId" column="adgroupId"/>   
+	    <result property="visitAddress" column="visitAddress"/> 
+	    <result property="clickAddress" column="clickAddress"/> 
+	    <result property="impressionAddress" column="impressionAddress"/> 
+	    <result property="checked" column="checked"/> 
+	    <result property="operatorChecked" column="operatorChecked"/>
+	    <result property="updated" column="updated"/> 
+	    <result property="memo" column="memo"/> 
+	    <association property="bannerTemplate" resultMap="com.cloudcross.ssp.model.BannerTemplate"/>
+	</resultMap>  
+	<resultMap type="com.cloudcross.ssp.operator.model.BannerTemplate" id="bannerTemplate">  
+	   <id property="id" column="banner_templateId"/>  
+	   <result property="advertiserId" column="advertiserId"/> 
+	   <result property="name" column="name"/>
+	    <result property="path" column="path"/> 
+	     <result property="pathSmall" column="pathSmall"/>
+	   <result property="type" column="type"/>
+	   <result property="width" column="width"/> 
+	   <result property="height" column="height"/> 
+	   <result property="status" column="status"/>   
+	   <result property="updated" column="bannerTemplateUpdated"/>     
+	</resultMap>
+	
+	<insert id="addBanner" parameterType="com.cloudcross.ssp.model.Banner" useGeneratedKeys="true"
+		keyProperty="id">
+		insert into
+		t_banner(banner_template_id,order_id,campaign_id,adgroup_id,visit_address,click_address,impression_address,checked,memo,updated,supdated
+		)
+		values (
+		#{bannerTemplateId},#{orderId},#{campaignId},#{adGroupId},#{visitAddress},#{clickAddress},#{impressionAddress},#{checked},#{memo},#{updated},#{supdated}
+		)
+	</insert>
+	
+	<update id="editBanner" parameterType="com.cloudcross.ssp.model.Banner">		 
+		update t_banner a,t_banner_template b
+		set b.name = #{bannerTemplate.name},
+		b.updated = #{bannerTemplate.updated},
+		a.visit_address = #{visitAddress},
+		a.click_address = #{clickAddress},
+		a.impression_address = #{impressionAddress},
+		a.checked = 0,
+		a.updated = #{updated},
+		a.supdated = #{supdated}
+		WHERE b.id = a.banner_template_id and a.id = #{id}
+	</update>
+	
+	<update id="updataBanner" parameterType="com.cloudcross.ssp.model.Banner">		 
+		update t_banner a,t_banner_template b
+		set a.banner_template_id = #{bannerTemplateId},	
+		b.name = #{bannerTemplate.name},
+		b.updated = #{bannerTemplate.updated},
+		a.visit_address = #{visitAddress},
+		a.click_address = #{clickAddress},
+		a.impression_address = #{impressionAddress},
+		a.checked = 0,
+		a.updated = #{updated},
+		a.supdated = #{supdated}
+		WHERE b.id = #{bannerTemplate.id} and a.id = #{id}
+	</update>
+	
+	<update id="updataOperatorBanner" parameterType="HashMap">		 
+		update t_banner_operator
+		set checked = 0,supdated = #{supdated}
+		WHERE banner_id in
+		<foreach item="id" collection="idList" open="(" separator=","
+			close=")">
+			#{id}
+		</foreach>
+	</update>
+<!-- 根据adgroupId修改banner的supdated -->
+	<update id="updateBannerSupdated" parameterType="HashMap">
+		update t_banner
+			set t_banner.supdated= #{modifyDate}
+			where  t_banner.adgroup_id in
+			<foreach item="adgroupId" collection="adGroupIdList"
+		      open="(" separator="," close=")">
+		        #{adgroupId}
+			</foreach>
+	</update>
+	
+	<!-- 根据orderId修改banner的supdated -->
+	<update id="updateBannerSupdatedByOrderId" parameterType="HashMap">
+		update t_banner
+			set t_banner.supdated=#{modifyDate}
+			where  t_banner.order_id in
+			<foreach item="orderId" collection="orderIdList"
+		      open="(" separator="," close=")">
+		        #{orderId}
+			</foreach>
+	</update>
+	
+	<!-- 根据campaignid修改banner的supdated -->
+	<update id="updateBannerSupdatedByCampaignId" parameterType="HashMap">
+		update t_banner
+			set t_banner.supdated=#{modifyDate}
+			where  t_banner.campaign_id in
+			<foreach item="campaignId" collection="campaignIdList"
+		      open="(" separator="," close=")">
+		        #{campaignId}
+			</foreach>
+	</update>
+	
+	
+	<update id="updateStatusByOrderId" parameterType="HashMap">
+		update t_banner a,t_banner_template b
+		set b.status=#{status},b.updated = #{modifyDate},a.updated = #{modifyDate} 
+		where
+		a.banner_template_id = b.id and
+		a.order_id in
+		<foreach item="orderId" collection="orderIdList" open="(" separator="," close=")">
+			#{orderId}
+		</foreach>
+	</update>
+	
+	<update id="updateStatusByCampaignId" parameterType="HashMap">
+		update t_banner a,t_banner_template b
+		set b.status=#{status},b.updated = #{modifyDate},a.updated = #{modifyDate} 
+		where
+		a.banner_template_id = b.id and
+		a.campaign_id in
+		<foreach item="campaignId" collection="campaignIdList" open="(" separator="," close=")">
+			#{campaignId}
+		</foreach>
+	</update>
+	
+	<update id="updateStatusByAdGroupId" parameterType="HashMap">
+		update t_banner a,t_banner_template b
+		set b.status=#{status},b.updated = #{modifyDate},a.updated = #{modifyDate} 
+		where
+		a.banner_template_id = b.id and
+		a.adgroup_id in
+		<foreach item="adGroupId" collection="adGroupIdList" open="(" separator="," close=")">
+			#{adGroupId}
+		</foreach>
+	</update>
+	
+	
+	<select id="countByParams1" parameterType="map" resultType="int">
+		select count(a.id)
+	 from t_banner a LEFT JOIN t_banner_template b on a.banner_template_id=b.id   
+					<where>
+					 a.status != -1 and b.status != -1
+					<if test="orderMark == null">
+					and a.order_id = #{orderId}
+					</if>
+					<if test="campaignMark == null">
+					and a.campaign_id = #{campaignId}
+					</if>
+					<if test="adGroupMark == null">
+					and a.adgroup_id = #{adGroupId}
+					</if>
+					<if test="status!=null">
+					 and a.status = #{status} and b.status = #{status}
+					</if>
+		<if test="bannerTemplateName != null">
+			and b.name like #{bannerTemplateName}
+		</if>
+		<if test="agentId!=null">
+			 and b.agent_id = #{agentId}
+		</if>
+		<if test="agentId == null">
+			and b.advertiser_id = #{advertiserId}
+		</if>
+					</where>
+	</select>
+	
+	<select id="findByParams1" parameterType="map" resultMap="Banner">  
+		select a.status as status1,a.id as id,a.banner_template_id as bannerTemplateId,a.order_id as orderId,a.campaign_id as campaignId,a.adgroup_id as adGroupId,a.visit_address as visitAddress,
+	a.click_address as clickAddress,a.impression_address as impressionAddress, a.checked as checked,a.updated as updated,b.id as bannerTemplateId,b.agent_id as agentId,b.advertiser_id as advertiserId,b.agent_id as agentId,b.name as name,b.path as path,b.path_small as pathSmall,b.type as type,b.width as width,b.height as height,b.status as status,b.updated as updated from t_banner a LEFT JOIN t_banner_template b on a.banner_template_id=b.id   
+					<where>
+					 a.status != -1 and b.status != -1
+					<if test="orderMark == null">
+					and a.order_id = #{orderId}
+					</if>
+					<if test="campaignMark == null">
+					and a.campaign_id = #{campaignId}
+					</if>
+					<if test="adGroupMark == null">
+					and a.adgroup_id = #{adGroupId}
+					</if>
+					<if test="status!=null">
+					 and a.status = #{status} and b.status = #{status}
+					</if>
+		<if test="bannerTemplateName != null">
+			and b.name like #{bannerTemplateName}
+		</if>
+		<if test="agentId!=null">
+			 and b.agent_id = #{agentId}
+		</if>
+		<if test="agentId == null">
+			and b.advertiser_id = #{advertiserId}
+		</if>
+					</where>
+		order by a.id   desc
+		limit #{pager.offset}, #{pager.limit}
+	</select>
+	
+	
+	<select id="findByParams2" parameterType="map" resultMap="Banner">  
+		select a.status as status1,a.id as id,a.banner_template_id as bannerTemplateId,a.order_id as orderId,a.campaign_id as campaignId,a.adgroup_id as adGroupId,a.visit_address as visitAddress,
+	a.click_address as clickAddress,a.impression_address as impressionAddress, a.checked as checked,a.updated as updated,b.id as bannerTemplateId,b.agent_id as agentId,b.advertiser_id as advertiserId,b.agent_id as agentId,b.name as name,b.path as path,b.path_small as pathSmall,b.type as type,b.width as width,b.height as height,b.status as status,b.updated as updated from t_banner a LEFT JOIN t_banner_template b on a.banner_template_id=b.id   
+					<where>
+					 a.status != -1 and b.status != -1
+					<if test="orderMark == null">
+					and a.order_id = #{orderId}
+					</if>
+					<if test="campaignMark == null">
+					and a.campaign_id = #{campaignId}
+					</if>
+					<if test="adGroupMark == null">
+					and a.adgroup_id = #{adGroupId}
+					</if>
+					<if test="status!=null">
+					 and a.status = #{status} and b.status = #{status}
+					</if>
+		<if test="bannerTemplateName != null">
+			and b.name like #{bannerTemplateName}
+		</if>
+		<if test="agentId!=null">
+			 and b.agent_id = #{agentId}
+		</if>
+		<if test="agentId == null">
+			and b.advertiser_id = #{advertiserId}
+		</if>
+					</where>
+		order by a.id   desc
+	</select>
+	<update id="updateOperatorBannerTime" parameterType="HashMap">
+			update t_banner_operator 
+			set supdated = #{supdated}
+			where banner_id in 
+			<foreach item="id" collection="idList" open="(" separator=","
+			close=")">
+			#{id}
+			</foreach>
+	
+	</update>
+	<update id="updateBannerStatus" parameterType="HashMap">
+		update t_banner 
+			set checked = #{checked},updated = #{updated}
+			where id in
+			<foreach item="bannerId" collection="bannerIdList"
+		      open="(" separator="," close=")">
+		        #{bannerId}
+			</foreach>
+	</update>
+	
+	<update id="updateOperatorBanner" parameterType="HashMap">
+		update t_banner_operator 
+			set operator_id=#{operatorId},checked = #{operatorChecked},supdated = #{supdated}
+			where banner_id = #{bannerId}
+	</update>
+	<select id="countByOperator" parameterType="HashMap" resultType="int">
+		select count(*) from t_banner b inner join t_banner_template bt on b.banner_template_id = bt.id left join t_banner_operator bo
+on b.id=bo.banner_id and bo.operator_id=#{operatorId}  
+where b.status = 0 and bt.status = 0 and b.checked = 1 
+	   	<if test="zoneList.size()>0">
+			and
+		   	<foreach item="zone" collection="zoneList"
+		   		 open="(" separator="or" close=")" >
+			      bt.width &lt;= #{zone.width} and bt.height &lt;= #{zone.height}
+			</foreach>
+		</if>
+		<if test="searchKey!=null and searchValue!=null">
+			and bt.name like #{searchValue}
+		</if>
+		<if test="operatorChecked!=null">
+		<choose>
+			<when test="operatorChecked == 0">
+				and ISNULL(bo.checked) or bo.checked =0
+			</when>
+			<otherwise>
+				and bo.checked=#{operatorChecked}
+			</otherwise>	
+		</choose>
+		</if>
+	</select>
+</mapper>

+ 317 - 0
src/main/java/com/cloudcross/ssp/model/mapper/campaign.sql.xml

@@ -0,0 +1,317 @@
+<?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="campaignSqlMapper">
+	<sql id="base_column">
+	    t_campaign.id as id,
+	    t_campaign.order_id as orderId,
+	    t_campaign.name as name,
+	    t_campaign.activate_time as activeTime,
+	    t_campaign.expire_time as expireTime,
+	    t_campaign.totalbudget as totalBudget,
+	    t_campaign.dailybudget as dailyBudget,
+	    t_campaign.impression as impression,
+	    t_campaign.click as click,
+	    t_campaign.conversion as conversion,
+	    t_campaign.daily_impression as dailyImpression,
+	    t_campaign.daily_click as dailyClick,
+	    t_campaign.daily_conversion as dailyConversion,
+	    t_campaign.memo as memo,
+	    t_campaign.status as status,
+	    t_campaign.updated as upDated
+	</sql>
+	
+	<insert id="addCampaignadvertiser" parameterType="com.cloudcross.ssp.model.Campaign">
+		insert into t_campaign
+			(name,agent_id,advertiser_id,
+			order_id,activate_time,expire_time,totalbudget,
+			<if test="dailyBudget !=null">dailybudget,</if>
+			<if test="impression!=null">impression,</if>
+			<if test="click !=null">click,</if>
+			<if test="conversion !=null">conversion,</if>
+			<if test="dailyImpression !=null">daily_impression,</if>
+			<if test="dailyClick !=null">daily_click,</if>
+			<if test="dailyConversion !=null">daily_conversion,</if>
+			<if test="memo !=null">memo,</if>
+			 updated)
+		values
+			(#{name},#{agentId},#{advertiserId},
+			#{orderId},#{activeTime},#{expireTime},#{totalBudget},
+			<if test="dailyBudget !=null">#{dailyBudget},</if>
+			<if test="impression!=null">#{impression},</if>
+			<if test="click !=null">#{click},</if>
+			<if test="conversion !=null">#{conversion},</if>
+			<if test="dailyImpression !=null">#{dailyImpression},</if>
+			<if test="dailyClick !=null">#{dailyClick},</if>
+			<if test="dailyConversion !=null">#{dailyConversion},</if>
+			<if test="memo !=null">#{memo},</if>
+			NOW())
+	</insert>
+	
+	<insert id="addCampaignbackoroperator" parameterType="com.cloudcross.ssp.model.Campaign">
+		insert into t_campaign
+			(name,order_id,activate_time,expire_time,
+			totalbudget,dailybudget,impression,click,conversion,daily_impression,
+			daily_click,daily_conversion,memo,updated)
+		values
+			(#{name},#{orderId},#{activeTime},#{expireTime},#{totalBudget},
+			#{dailyBudget},#{impression},#{click},#{conversion},#{dailyImpression},
+			#{dailyClick},#{dailyConversion},#{memo},NOW())
+	</insert>
+	<update id="editCampaignadvertiser" parameterType="com.cloudcross.ssp.model.Campaign">
+		update t_campaign set
+		name = #{name},
+		activate_time = #{activeTime},
+		expire_time = #{expireTime},
+		totalbudget = #{totalBudget},
+		dailybudget = IFNULL(#{dailyBudget},default(dailybudget)),
+		conversion =IFNULL(#{conversion},default(conversion)),
+		click = IFNULL(#{click},default(click)),
+		impression =IFNULL(#{impression},default(impression)),
+		daily_click = IFNULL(#{dailyClick},default(daily_click)),
+		daily_conversion = #{dailyConversion},
+		daily_impression = IFNULL(#{dailyImpression},default(daily_impression)),
+		memo = IFNULL(#{memo},default(memo)),
+		updated = NOW()
+		where t_campaign.id = #{id}
+	</update>
+	<update id="editCampaignbackoroperator" parameterType="com.cloudcross.ssp.model.Campaign">
+		update t_campaign set
+		name = #{name},
+		activate_time = #{activeTime},
+		expire_time = #{expireTime},
+		totalbudget = #{totalBudget},
+		dailybudget = IFNULL(#{dailyBudget},default(dailybudget)),
+		conversion =IFNULL(#{conversion},default(conversion)),
+		click = IFNULL(#{click},default(click)),
+		impression =IFNULL(#{impression},default(impression)),
+		daily_click = IFNULL(#{dailyClick},default(daily_click)),
+		daily_conversion = 0,
+		daily_impression = IFNULL(#{dailyImpression},default(daily_impression)),
+		memo = IFNULL(#{memo},default(memo)),
+		updated = NOW()
+		where t_campaign.id = #{id}
+	</update>	
+	
+	<select id="findByParamsadvertiser" parameterType="map" resultType="com.cloudcross.ssp.model.Campaign">
+		select
+		<include refid="base_column" />
+		,count(t_adgroup.campaign_id) as groupNumber from t_campaign left join t_adgroup
+		    on t_campaign.id = t_adgroup.campaign_id and t_adgroup.status != -1
+		    where 1=1
+		<if test="advMark!=null">
+			and t_campaign.agent_id = #{agentId}
+		</if> 
+		<if test="advMark==null">
+			and t_campaign.advertiser_id = #{advertiserId}
+		</if> 
+		<if test="orderMark==null">
+			and t_campaign.order_id = #{orderId}
+		</if> 
+	 
+		 and t_campaign.status != -1
+		 	<if test="value!=null">
+				and t_campaign.name like #{value}
+			</if>			
+		<if test="status!=null">	
+			and t_campaign.status = #{status}
+		</if>						
+			  group by t_campaign.id
+		order by t_campaign.id desc
+		limit #{pager.offset}, #{pager.limit}
+	</select>
+	<select id="findByParamsback" parameterType="map" resultType="com.cloudcross.ssp.model.Campaign">
+		select
+		<include refid="base_column" />
+		,count(t_adgroup.campaign_id) as groupNumber from t_campaign left join t_adgroup
+		    on t_campaign.id = t_adgroup.campaign_id 
+		    where t_campaign.order_id = #{orderId} and t_campaign.status != -1
+		 	<if test="value!=null">
+				and t_campaign.name like #{value}
+			</if>			
+		<if test="status!=null">	
+			and t_campaign.status = #{status}
+		</if>						
+			  group by t_campaign.id
+		order by t_campaign.id desc
+		limit #{pager.offset}, #{pager.limit}
+	</select>
+	
+	<select id="findByParamsoperator" parameterType="map" resultType="com.cloudcross.ssp.model.Campaign">
+		select
+		<include refid="base_column" />
+		,count(t_adgroup.campaign_id) as groupNumber from t_campaign left join t_adgroup
+		    on t_campaign.id = t_adgroup.campaign_id 
+		    where t_campaign.order_id = #{orderId} and t_campaign.status != -1
+		 	<if test="key!=null and value!=null">
+	            <choose>
+					<when test="key=='name'">
+						and t_campaign.name like #{value}
+					</when>				
+				</choose>
+			</if>			
+		<if test="status!=null">	
+			and t_campaign.status = #{status}
+		</if>						
+			  group by t_campaign.id
+		order by t_campaign.id desc
+		limit #{pager.offset}, #{pager.limit}
+	</select>
+
+	<select id="countByParamsadvertiser" parameterType="map" resultType="int">
+		select count(id) from t_campaign
+		where 1=1
+		<if test="advMark!=null">
+			and t_campaign.agent_id = #{agentId}
+		</if> 
+		<if test="advMark==null">
+			and t_campaign.advertiser_id = #{advertiserId}
+		</if> 
+		<if test="orderMark==null">
+			and t_campaign.order_id = #{orderId}
+		</if> 
+		and status != -1
+			<if test="value!=null">
+				and name like #{value}
+			</if>
+						
+		<if test="status!=null">	
+			and t_campaign.status = #{status}
+		</if>
+	</select>
+<select id="countByParamsback" parameterType="map" resultType="int">
+		select count(id) from t_campaign
+		<where>
+			order_id = #{orderId} and status != -1
+			<if test="value!=null">
+				and name like #{value}
+			</if>
+						
+		<if test="status!=null">	
+			and t_campaign.status = #{status}
+		</if>
+		</where>
+	</select>
+	<select id="countByParamsoperator" parameterType="map" resultType="int">
+		select count(id) from t_campaign
+		<where>
+			order_id = #{orderId} and status != -1
+			<if test="key!=null and value!=null">
+				<choose>
+					<when test="key=='name'">
+						and name like #{value}
+					</when>
+				</choose>
+			</if>
+						
+		<if test="status!=null">	
+			and t_campaign.status = #{status}
+		</if>
+		</where>
+	</select>
+	<update id="updateCampaignStatus" parameterType="HashMap">
+		update t_campaign 
+		set status=#{status},
+			updated = #{upDated}
+		where
+		id in
+		<foreach item="id" collection="idList" open="(" separator=","
+			close=")">
+			#{id}
+		</foreach>
+	</update>
+	
+	<update id="updateSupdated" parameterType="HashMap">
+		update t_adgroup
+			set t_adgroup.supdated= NOW()
+			where  t_adgroup.campaign_id in
+			<foreach item="id" collection="idList" open="(" separator=","
+			close=")">
+			#{id}
+		</foreach>
+	</update>
+	
+	<select id="findById" parameterType="long" resultType="com.cloudcross.ssp.model.Campaign">
+		select
+		<include refid="base_column" />
+		from t_campaign 
+		where id = #{id}
+	</select>
+	
+	<select id="findByName" parameterType="String" resultType="long">
+		select
+		max(id)
+		from t_campaign 
+		where name = #{name}
+	</select>
+	
+
+	<delete id="deleteByID" parameterType="int">
+	delete from t_campaign where id=#{id}
+	</delete>
+	
+	
+	<select id="findByOrderId" parameterType="long" resultType="com.cloudcross.ssp.model.Campaign">
+		select
+		<include refid="base_column" />
+		from t_campaign
+		<where>
+			order_id = #{orderId} and status != -1
+		</where>
+	</select>
+
+	
+	<select id="selectByStatus"  parameterType="map" resultType="com.cloudcross.ssp.model.Campaign">
+		select 
+		<include refid="base_column" />
+		,count(t_adgroup.campaign_id) as groupNumber from t_campaign left join t_adgroup
+		 on t_campaign.id = t_adgroup.campaign_id 
+		 where 1 = 1 
+		 and t_campaign.status = #{status}
+		 and t_campaign.order_id = #{orderId}  
+		group by t_campaign.id
+		order by t_campaign.id   desc
+		limit #{pager.offset}, #{pager.limit}
+	</select>	
+	
+	<!-- 导出Excel用 -->
+	<select id="findDeliverEffectAnalysis" parameterType="map" resultType="com.cloudcross.ssp.model.Campaign">
+		select
+		<include refid="base_column" />
+		,count(t_adgroup.campaign_id) as groupNumber from t_campaign left join t_adgroup
+		    on t_campaign.id = t_adgroup.campaign_id 
+		    where t_campaign.order_id = #{orderId} and t_campaign.status != -1
+		 	<if test="key!=null and value!=null">
+	            <choose>
+					<when test="key=='name'">
+						and t_campaign.name like #{value}
+					</when>				
+				</choose>
+			</if>			
+		<if test="status!=null">	
+			and t_campaign.status = #{status}
+		</if>						
+			  group by t_campaign.id
+		order by t_campaign.id desc
+	</select>
+	
+	<update id="updateStatusByAdvertiserId" parameterType="HashMap">
+		update t_campaign
+			set status = #{status},updated = NOW()
+			where t_campaign.advertiser_id in
+			<foreach item="advertiserId" collection="advertiserIdList"
+		      open="(" separator="," close=")">
+		        #{advertiserId}
+			</foreach>
+	</update>
+	
+	<update id="updateStatusByOrderId" parameterType="HashMap">
+		update t_campaign 
+			set status = #{status},updated = #{modifyDate}
+			where t_campaign.order_id in
+			<foreach item="orderId" collection="orderIdList"
+		      open="(" separator="," close=")">
+		        #{orderId}
+			</foreach>
+	</update>
+
+</mapper>

+ 51 - 0
src/main/java/com/cloudcross/ssp/model/mapper/clientAccount.sql.xml

@@ -0,0 +1,51 @@
+<?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="clientAccountSqlMapper">
+
+	<select id="findOperatorByParams"  parameterType="map" resultType="com.cloudcross.ssp.model.ClientAccount">
+		 select t_account.id as id,t_account.name as accountName,
+    t_operator.company_name as companyName, t_operator.link_man as linkMan,
+    t_operator.tel as mobilePhone,t_account.tel as tel,t_account.state as status,t_account.sys_type as sysType from
+    t_operator,t_account where t_account.id = t_operator.admin_id and t_account.state != -1 and t_operator.status != -1 and t_account.sys_type = 2  
+		<if test="value!=null">
+			and (t_account.name like #{value}
+			or t_operator.company_name like #{value})
+		</if>
+		order by  t_account.id   desc
+	</select>
+	
+	<select id="countOperatorByParams" parameterType="map" resultType="int">
+		select count(t_account.id) 
+    	 from
+    	t_operator,t_account where t_account.id = t_operator.admin_id 
+    	and t_account.state != -1 
+    	and t_operator.status != -1 and t_account.sys_type = 2
+		<if test="value!=null">
+			and (t_account.name like #{value}
+			or t_operator.company_name like #{value})
+		</if>
+	</select>
+	
+	<select id="findAgentByParams"  parameterType="map" resultType="com.cloudcross.ssp.model.ClientAccount">
+		 select t_account.id as id,t_account.name as accountName,
+    t_adv_agent.name as companyName, t_adv_agent.contacts as linkMan,
+    t_adv_agent.mobile as mobilePhone,t_adv_agent.tel as tel,t_account.state as status,t_account.sys_type as sysType from
+    t_adv_agent,t_account where t_account.id = t_adv_agent.admin_id and t_account.state != -1 and t_adv_agent.status != -1 and t_account.sys_type = 3
+		<if test="value!=null">
+			and (t_account.name like #{value}
+			or t_adv_agent.name like #{value})
+		</if>
+		order by  t_account.id   desc
+	</select>
+	
+	<select id="countAgentByParams" parameterType="map" resultType="int">
+		 select count(t_account.id) from
+     t_adv_agent,t_account where t_account.id = t_adv_agent.admin_id 
+     and t_account.state != -1 and t_adv_agent.status != -1 and t_account.sys_type = 3
+		<if test="value!=null">
+			and (t_account.name like #{value}
+			or t_adv_agent.name like #{value})
+		</if>
+	</select>
+
+</mapper>

+ 160 - 0
src/main/java/com/cloudcross/ssp/model/mapper/codeClass.sql.xml

@@ -0,0 +1,160 @@
+<?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="codeClassSqlMapper">
+	
+	<sql id="base_column">
+		          id,
+	advertiser_id as advertiserId,
+	          name as codeName,
+	          para as codePara,
+	   script_code as script,
+	      pic_code as picture,
+	            updated
+	            	
+	</sql>
+	
+	<select id="selectByName"  parameterType="string" resultType="com.cloudcross.ssp.model.CodeClass">
+		select 
+		<include refid="base_column" />
+		from t_code_class
+		<where>
+			name = #{codeName}
+		</where>
+		order by id  desc
+	</select>
+	
+		<!--  根据id从数据库中查询代码分类对象-->
+	 <select id="selectById" parameterType="int" resultType="com.cloudcross.ssp.model.CodeClass">
+		select 
+		<include refid="base_column" />
+		from t_code_class
+		<where>
+			id = #{id} 			
+		</where>
+	</select>  
+	
+	<!--  搜索 -->
+	<select id="selectByParamsadvertiser"  parameterType="map" resultType="com.cloudcross.ssp.model.CodeClass">
+		select 
+		<include refid="base_column" />
+		from t_code_class 
+		<where>
+		<if test="advertiserId!=null and advertiserId != '' and advertiserId!=-1 ">
+		advertiser_id=#{advertiserId}
+		</if>	
+		
+	    <if test="codeName!=null">
+		and name like #{codeName}
+		</if>
+		
+		
+		
+		<!--  
+		<if test="key!=null and value!=null">
+			<choose>
+				<when test="key=='codeName'">
+					and name like #{value}
+				</when>
+				<when test="key=='id'">
+					and id like #{value}
+				</when>
+			</choose>	
+		</if>-->
+		</where>
+		
+		limit #{pager.offset}, #{pager.limit}
+	</select>
+	
+	<select id="selectByParamsoperator"  parameterType="map" resultType="com.cloudcross.ssp.model.CodeClass">
+		select 
+		<include refid="base_column" />
+		from t_code_class where id>0	
+		<if test="key!=null and value!=null">
+			<choose>
+				<when test="key=='codeName'">
+					and name like #{value}
+				</when>
+				<when test="key=='id'">
+					and id like #{value}
+				</when>
+			</choose>	
+		</if>
+		
+		order by id  desc
+		limit #{pager.offset}, #{pager.limit}
+	</select>
+	
+	
+	<!--  计算总行数获取列表 -->
+	
+	<select id="countByParamsadvertiser" parameterType="map" resultType="int">
+		select count(id)
+		from t_code_class 
+		<where>
+			1=1
+			<if test="advertiserId != null and advertiserId != '' and advertiserId!=-1 ">
+				and advertiser_Id = #{advertiserId}
+			</if>
+			
+			<if test="codeName != null and codeName != ''">
+				and name like #{codeName}
+			</if>
+		</where>	
+	</select>
+	
+		<select id="countByParamsoperator" parameterType="map" resultType="int">
+		select count(id)
+		from t_code_class where id>0	
+			<if test="key!=null and value!=null">
+			<choose>
+				<when test="key=='id'">
+					and id like #{value}
+				</when>
+				<when test="key=='codeName'">
+					and name like #{value}
+				</when>
+			</choose>	
+		</if>
+	</select>
+	  <insert id="addCodeClassoperator" parameterType="com.cloudcross.ssp.model.CodeClass">
+		insert into t_code_class(name, para, updated )
+		values(#{codeName},#{codePara},#{updated})
+	</insert>
+	
+	
+	<update id="editCodeClassoperator" parameterType="com.cloudcross.ssp.model.CodeClass">
+		update t_code_class 
+		set name=#{codeName}, para=#{codePara}, updated=#{updated} , script_code=#{script}, pic_code=#{picture}
+		
+		
+		
+		where id = #{id}
+	</update>
+	
+	  <insert id="addCodeClassadvertiser" parameterType="com.cloudcross.ssp.model.CodeClass">
+		insert into t_code_class(advertiser_id, name, para, updated )
+		values(#{advertiserId},#{codeName},#{codePara},#{updated})
+	</insert>
+	
+	
+	<update id="editCodeClassadvertiser" parameterType="com.cloudcross.ssp.model.CodeClass">
+		update t_code_class 
+		set name=#{codeName}, para=#{codePara}, updated=#{updated}
+		<!--  set name=#{codeName}, para=#{codePara}, updated=#{updated} , script_code=#{script}, pic_code=#{picture}-->
+		where id = #{id}
+	</update>
+	
+	<!-- 根据id查询代码值 -->
+	<select id="getScriptById"  parameterType="int" resultType="String">
+		select 
+		script_code
+		from t_code_class where id = #{id}
+	</select>
+	<!-- 根据id查询图片值 -->
+	<select id="getPicyureById"  parameterType="int" resultType="String">
+		select 
+		pic_code
+		from t_code_class where id = #{id}
+	</select>
+	
+</mapper>

+ 164 - 0
src/main/java/com/cloudcross/ssp/model/mapper/codeConvert.sql.xml

@@ -0,0 +1,164 @@
+<?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="codeConvertSqlMapper">
+	
+	<sql id="base_column">
+		          id,
+	advertiser_id as advertiserId,
+	          name as convertName,
+	          type as convertType,
+	   script_code as script,
+	      pic_code as picture,
+	            updated
+	            	
+	</sql>
+	
+	<select id="selectByName"  parameterType="string" resultType="com.cloudcross.ssp.model.CodeConvert">
+		select 
+		<include refid="base_column" />
+		from t_code_convert
+		<where>
+			name = #{convertName}
+		</where>
+		order by id  desc
+	</select>
+	
+	
+	 <select id="selectById" parameterType="int" resultType="com.cloudcross.ssp.model.CodeConvert">
+		select 
+		<include refid="base_column" />
+		from t_code_convert
+		<where>
+			id = #{id} 			
+		</where>
+	</select>  
+	
+	<!--  搜索用-->
+	<select id="selectByParamsadvertiser"  parameterType="map" resultType="com.cloudcross.ssp.model.CodeConvert">
+		select 
+		<include refid="base_column" />
+		from t_code_convert 
+		<where>
+		<if test="advertiserId!=null and advertiserId != '' and advertiserId!=-1 ">
+		advertiser_id=#{advertiserId}
+		</if>	
+		
+		<if test="convertName!=null">
+		and name like #{convertName}
+		</if>	
+			<!--  
+		<if test="key!=null and value!=null">
+			<choose>
+				<when test="key=='convertName'">
+					and name like #{convertName}
+				</when>
+				
+			</choose>	
+		</if>
+		-->
+		</where>
+		
+		limit #{pager.offset}, #{pager.limit}
+		
+	</select>
+			<select id="selectByParamsoperator"  parameterType="map" resultType="com.cloudcross.ssp.model.CodeConvert">
+		select 
+		<include refid="base_column" />
+		from t_code_convert where id>0	
+		<if test="key!=null and value!=null">
+			<choose>
+				<when test="key=='convertName'">
+					and name like #{value}
+				</when>
+				<when test="key=='id'">
+					and id like #{value}
+				</when>
+			</choose>	
+		</if>
+		
+		order by id  desc
+		limit #{pager.offset}, #{pager.limit}
+	</select>
+		
+	
+
+	<select id="countByParamsadvertiser" parameterType="map" resultType="int">
+		select count(id)
+		from t_code_convert 	
+		<where>
+		<if test="advertiserId!=null and advertiserId != '' and advertiserId!=-1 ">
+		advertiser_id=#{advertiserId}
+		</if>	
+		
+		<if test="convertName!=null">
+		and name like #{convertName}
+		</if>
+		</where>
+		<!--	<if test="key!=null and value!=null">
+			<choose>
+				<when test="key=='id'">
+					and id like #{value}
+				</when>
+				<when test="key=='convertName'">
+					and name like #{value}
+				</when>
+			</choose>	
+		</if>
+		  -->
+	</select>
+	
+	<select id="countByParamsoperator" parameterType="map" resultType="int">
+		select count(id)
+		from t_code_convert where id>0	
+			<if test="key!=null and value!=null">
+			<choose>
+				<when test="key=='id'">
+					and id like #{value}
+				</when>
+				<when test="key=='convertName'">
+					and name like #{value}
+				</when>
+			</choose>	
+		</if>
+	</select>
+	
+	
+	  <insert id="addCodeConvertadvertiser" parameterType="com.cloudcross.ssp.model.CodeConvert">
+		insert into t_code_convert(advertiser_Id, name, type, updated )
+		values(#{advertiserId},#{convertName},#{convertType},#{updated})
+	</insert>
+	
+	
+	<update id="editCodeConvertadvertiser" parameterType="com.cloudcross.ssp.model.CodeConvert">
+		update t_code_convert 
+		set name=#{convertName}, type=#{convertType}, updated=#{updated}
+		<!-- set name=#{convertName}, type=#{convertType}, updated=#{updated}, script_code=#{script}, pic_code=#{picture}  -->
+		where id = #{id}
+	</update>
+	
+	  <insert id="addCodeConvertoperator" parameterType="com.cloudcross.ssp.model.CodeConvert">
+		insert into t_code_convert(name, type, updated )
+		values(#{convertName},#{convertType},#{updated})
+	</insert>
+	
+	
+	<update id="editCodeConvertoperator" parameterType="com.cloudcross.ssp.model.CodeConvert">
+		update t_code_convert 
+		set name=#{convertName}, type=#{convertType}, updated=#{updated}, script_code=#{script}, pic_code=#{picture}
+		where id = #{id}
+	</update>
+	
+	<!-- 根据id查询代码值 -->
+	<select id="getScriptById"  parameterType="int" resultType="String">
+		select 
+		script_code
+		from t_code_convert where id = #{id}
+	</select>
+	<!-- 根据id查询图片值 -->
+	<select id="getPicyureById"  parameterType="int" resultType="String">
+		select 
+		pic_code
+		from t_code_convert where id = #{id}
+	</select>
+	
+</mapper>

+ 67 - 0
src/main/java/com/cloudcross/ssp/model/mapper/codeSite.sql.xml

@@ -0,0 +1,67 @@
+<?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="codeSiteSqlMapper">
+	
+	<sql id="base_column">
+		 id,
+		 advertiser_id as advertiserId,      
+	     script_code as script,
+	     pic_code as picture	            	
+	</sql>
+	
+	<select id="findAllAdvertiserId"  parameterType="int" resultType="com.cloudcross.ssp.model.CodeSite">
+		select 
+		<include refid="base_column" />
+		from t_code_site where advertiser_id = #{advertiserId}
+	</select>
+	
+	
+	
+	 <select id="selectById" parameterType="int" resultType="com.cloudcross.ssp.model.CodeSite">
+		select 
+		<include refid="base_column" />
+		from t_code_site
+		<where>
+			id = #{id} 			
+		</where>
+	</select>  
+	
+	 
+	 
+	 	<select id="selectByAdvertiserIdadvertiser"  parameterType="int" resultType="com.cloudcross.ssp.model.CodeSite">
+		select 
+		 script_code as script
+	    	
+		 from t_code_site 
+		
+		<where>
+		
+		 <if test="advertiserId!=null">
+			 advertiser_id = #{advertiserId}
+		</if>
+		 
+         </where>		
+		</select>
+	
+	<select id="selectByAdvertiserIdoperator"  parameterType="int" resultType="com.cloudcross.ssp.model.CodeSite">
+		select 
+		<include refid="base_column" />
+		from t_code_site where advertiser_id = 	#{AdvertiserId}
+	</select>
+	
+	 <!-- select script_code , pic_code from t_code_site where advertiser_id=1
+	  -->
+	<select id="getScriptByAdId"  parameterType="int" resultType="String">
+		select 
+		script_code
+		from t_code_site where advertiser_id = #{advertiserId}
+	</select>
+	
+	<select id="getPicyureByAdId"  parameterType="int" resultType="String">
+		select 
+		pic_code
+		from t_code_site where advertiser_id = #{advertiserId}
+	</select>
+	
+	
+</mapper>

+ 42 - 0
src/main/java/com/cloudcross/ssp/model/mapper/direct.sql.xml

@@ -0,0 +1,42 @@
+<?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="directSqlMapper">
+	<sql id="base_column">
+		id ,
+		adgroup_id  as adGroupId,
+		targettype as directType,
+		targetshow as backShow,
+		targetdata as data,
+		updated
+	</sql>
+
+	<insert id="addDirect" parameterType="com.cloudcross.ssp.model.Direct">
+		insert into
+		t_target_show (adgroup_id,targettype,targetshow,targetdata,updated)
+		values (#{adGroupId},#{directType},#{backShow},#{data},NOW())
+	</insert>
+
+	<select id="findByAdGroupId" parameterType="map"  resultType="com.cloudcross.ssp.model.Direct">
+		select
+		<include refid="base_column" />
+		from t_target_show
+		where adgroup_id=#{adGroupId}  
+			<if test="directType!=null">
+				and  targettype=#{directType} 
+			</if>
+	</select>
+
+	<update id="editDirect" parameterType="com.cloudcross.ssp.model.Direct">
+		UPDATE t_target_show
+		SET
+		targetshow =#{backShow},
+		targetdata = #{data},
+		updated = NOW()
+		WHERE adgroup_id=#{adGroupId}  and targettype = #{directType}
+	</update>
+
+	<delete id="deleteDirect" parameterType="map" >
+	    delete from t_target_show where adgroup_id=#{adGroupId}  and targettype = #{directType}
+	</delete>
+
+</mapper>

+ 96 - 0
src/main/java/com/cloudcross/ssp/model/mapper/finance.sql.xml

@@ -0,0 +1,96 @@
+<?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="financeSqlMapper">
+	
+	<sql id="base_column">
+		id,
+		account_id as accountId,
+		act_time as actTime,
+		num,
+	    t_advertiser.name as advertiserName,                    
+		memo,
+		agent_id as agentId,
+		advertiser_id as advertiserId,
+		charge,
+		allocate,
+		consume,
+		balance
+	</sql>
+	
+	<!-- 此时加入了帐号管理,只有该帐号下的广告主显示 -->
+	<select id="findByParams"  parameterType="map" resultType="com.cloudcross.ssp.advertiser.model.Finance">
+	    select a.id,b.name as advertiserName,(sum(a.allocate)-sum(a.consume)) as adBalance,sum(a.allocate) as sumAllocation,max(a.act_time) as upDated from t_adv_balance a,t_advertiser b 
+        where a.advertiser_id=b.id and a.agent_id=b.agent_id
+        and a.agent_id=#{agentId}
+     <!--     and a.account_id=#{accountId} -->
+        <if test="advertiserId !=null ">
+		and a.advertiser_id = #{advertiserId} 
+		</if>		
+		<if test="adverId !=null ">
+		and a.advertiser_id = #{adverId} 
+		</if>	
+     <!--     <if test="advertiserName !=null ">
+		and b.name = #{advertiserName} 
+		</if> 
+     -->
+        group by a.advertiser_id		
+		order by  b.name   desc
+	limit #{pager.offset}, #{pager.limit}
+	</select>
+	
+	<select id="countByParams" parameterType="map" resultType="int">
+		select count(1)
+		from (( select distinct a.advertiser_id from  t_adv_balance a,t_advertiser b  
+        where a.advertiser_id=b.id and a.agent_id=b.agent_id
+        and a.agent_id=#{agentId}
+     <!--  and a.account_id=#{accountId}  -->
+        <if test="advertiserId !=null ">
+		and a.advertiser_id = #{advertiserId} 
+		</if>	
+		<if test="adverId !=null ">
+		and a.advertiser_id = #{adverId} 
+		</if>
+   	 group by a.advertiser_id ) c)
+		
+	</select>
+	
+	<!-- 最主要的是下面的balance,此时的balance对应为广告主的余额 -->
+	<select id="findById" parameterType="long" resultType="com.cloudcross.ssp.advertiser.model.Finance">
+		select 
+		id,
+		account_id as accountId,
+		act_time as actTime,
+		num,                  
+		memo,
+		agent_id as agentId,
+		advertiser_id as advertiserId,
+		charge,
+		allocate,
+		consume,
+		balance
+		from t_adv_balance
+		where id = #{id}
+	</select>
+	
+	<insert id="editFinance"  parameterType="com.cloudcross.ssp.advertiser.model.Finance">
+          insert into t_adv_balance
+          (account_id,agent_id,advertiser_id,charge,allocate,consume,memo,num,balance,act_time)
+          values
+          (#{accountId},#{agentId},#{advertiserId},0,#{allocate},0,#{memo},#{num},#{balance}+#{allocate},NOW())                    
+	</insert>
+	
+	<insert id="addFinance"  parameterType="com.cloudcross.ssp.advertiser.model.Finance">
+	      insert into t_adv_balance
+          (account_id,agent_id,advertiser_id,allocate,balance,act_time)
+          values
+          (#{accountId},#{agentId},0,#{allocate},#{agentBalance}-#{allocate},NOW())    	
+	</insert>
+	
+	<select id="findByBalance"  parameterType="map" resultType="com.cloudcross.ssp.advertiser.model.Finance" >
+	     select a.balance as agentBalance from t_adv_balance a 
+	     where a.agent_id = #{agentId} and a.advertiser_id = 0
+	     and a.account_id = #{accountId}
+	     order by a.act_time desc limit 1
+	</select>
+
+</mapper>

+ 35 - 0
src/main/java/com/cloudcross/ssp/model/mapper/industry.sql.xml

@@ -0,0 +1,35 @@
+<?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="industrySqlMapper">
+
+<sql id="base_column">
+	id,
+	name
+</sql>
+
+	<select id="findAllIndustry"  resultType="com.cloudcross.ssp.model.Industry">
+		    select
+	    <include refid="base_column" />
+	    from t_industry
+	</select>
+	
+	<select id="findByIndustryId" parameterType="int" resultType="com.cloudcross.ssp.advertiser.model.Industry">
+		select 
+		 <include refid="base_column" />
+		from t_industry
+		<where>
+			id = #{id}
+		</where>
+	</select>
+	
+	<select id="findAllIndustryByZoneIdOperator"  resultType="com.cloudcross.ssp.model.Industry">
+	    select
+	    <include refid="base_column" />
+	    from t_industry 
+	    <where>
+		id not in( select industry_id from t_zone_industry where zone_id = #{zoneId} and
+		 t_zone_industry.status != -1)
+		</where>
+	</select>
+	
+</mapper>

+ 52 - 0
src/main/java/com/cloudcross/ssp/model/mapper/location.sql.xml

@@ -0,0 +1,52 @@
+<?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="locationSqlMapper">
+	<sql id="base_column">
+		id,
+		location,
+		location_t as locationT,
+		location1,
+		location2,
+		location3,
+		country,
+		cn,
+		cn_city as cnCity,
+		cn_district as cnDistrict,
+		py,
+		en_city as enCity,
+		en_district as enDistrict,
+		en
+	</sql>
+	
+	<select id="findAll" resultType="com.cloudcross.ssp.model.Location">
+		select
+		<include refid="base_column" />
+		from t_location where country = #{country}  
+	</select>
+	
+	<select id="findByProvince" resultType="com.cloudcross.ssp.model.Location">
+		select
+		<include refid="base_column" />
+		from t_location where location1 = #{location1}
+		and location2 = #{location2}
+	</select>
+	
+	
+	<select id="findByLocationT" parameterType="String" resultType="com.cloudcross.ssp.model.Location">
+		select <include refid="base_column" /> 
+		from t_location
+		where location_t = #{locationT}
+	</select>
+	<select id="findByCnAndCnCity" parameterType="map" resultType="com.cloudcross.ssp.model.Location">
+		select <include refid="base_column" />
+		from t_location where cn = #{cn} and cn_city =#{cnCity} 
+	</select>
+	
+	<select id="findCityByProvince" parameterType="String" resultType="String">
+		 select cn_city from t_location where cn=#{province}
+	</select>
+	
+	<select id="findAllProvince" resultType="String">
+		select cn from t_location where location1='CN' group by cn order by location2 asc
+	</select>
+</mapper>

+ 96 - 0
src/main/java/com/cloudcross/ssp/model/mapper/log.sql.xml

@@ -0,0 +1,96 @@
+<?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="logSqlMapper">
+	
+	<sql id="base_column">
+		id,
+		table_name as tableName,
+		record_id as recordId,
+		account_id as accountId,
+		account_name as accountName,
+		module,
+		action_type as actionType,
+		action,
+		action_time as actionTime,
+		user_ip as userIp,
+		oper_time as operTime
+	</sql>
+	
+	<insert id="addLog" parameterType="com.cloudcross.ssp.model.Log">
+		insert into t_log(table_name,record_id,account_id,account_name,module,action_type,action,action_time,user_ip,oper_time)
+		values(#{tableName},#{recordId},#{accountId},#{accountName},#{module},#{actionType},#{action},#{actionTime},#{userIp},#{operTime})
+	</insert>
+	
+	<select id="selectByParams"  parameterType="map" resultType="com.cloudcross.ssp.model.Log">
+		select 
+		<include refid="base_column" />
+		from t_log where 1 = 1
+		and table_name=#{tableName}
+		and record_id=#{recordId}
+		order by id   desc
+		limit #{pager.offset}, #{pager.limit}
+	</select>
+	<select id="selectByParams1"  parameterType="map" resultType="com.cloudcross.ssp.operator.model.Log">
+		select 
+		oper_time as operTime,
+		account_name as accountName,
+		user_ip as userIp,
+		action_type as actionType,
+		action
+		from t_log where 
+		table_name=#{tableName}
+	 	and record_id=#{recordId}
+	</select>
+	
+	<select id="countByParams" parameterType="map" resultType="int">
+		select count(id)
+		from t_log where 1 = 1
+		and table_name=#{tableName}
+		and record_id=#{recordId}
+	</select>
+	
+	<select id="selectByModule"  parameterType="String" resultType="com.cloudcross.ssp.model.Log">
+		select 
+		<include refid="base_column" />
+		from t_log where
+		module = #{module} 
+		order by id   desc
+		limit #{pager.offset}, #{pager.limit}
+	</select>
+	
+	<select id="findByModule" parameterType="String" resultType="com.cloudcross.ssp.model.Log">
+		select 
+		<include refid="base_column" />
+		from t_log where
+		module = #{module}
+	</select>
+	
+	<select id="selectById" parameterType="int" resultType="com.cloudcross.ssp.model.Log">
+		select 
+		<include refid="base_column" />
+		from t_log
+		<where>
+			id = #{id}
+		</where>
+	</select>
+	
+	<update id="editLog" parameterType="com.cloudcross.ssp.model.Log">
+		update t_log set account_id=#{accountId},account_name=#{accountName},
+		action_type=#{actionType},user_ip=#{userIp},
+		<if test="module !=null">
+			module=#{module},
+		</if>
+			oper_time=#{operTime} 
+		 	where id=#{id}
+	</update>	
+	<!-- 导出Excel用 -->
+	<select id="findDeliverEffectAnalysis" parameterType="map" resultType="com.cloudcross.ssp.advertiser.model.Log">
+		select 
+		<include refid="base_column" />
+		from t_log 	where 
+		 table_name=#{tableName}
+		and record_id=#{recordId}
+		order by id   desc
+	</select>
+</mapper>
+	

+ 82 - 0
src/main/java/com/cloudcross/ssp/model/mapper/message.sql.xml

@@ -0,0 +1,82 @@
+<?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="messageSqlMapper">
+	
+	<sql id="base_column">
+		t_message.id,
+		t_message.content,	
+		t_message.send_time as sendTime,
+		t_message.type
+	</sql>
+	
+	<insert id="addMessage" parameterType="com.cloudcross.ssp.model.Message">
+		insert into t_message(content,send_time,type)
+		values(#{content},#{sendTime},#{type})
+	</insert>
+	
+	<select id="selectByParams"  parameterType="map" resultType="com.cloudcross.ssp.model.Message">
+		select 
+		<include refid="base_column" />
+		from t_message
+		<where>
+			<if test="type!=null">	
+				and type = #{type}
+			</if>
+			<if test="value!=null">	
+				and content like #{value}
+			</if>
+		</where>	
+		
+		order by id   desc
+		limit #{pager.offset}, #{pager.limit}
+	</select>
+	
+	<select id="countByParams" parameterType="map" resultType="int">
+		select count(id) from t_message
+		<where>
+			<if test="type!=null">	
+				and type = #{type}
+			</if>
+			<if test="value!=null">	
+				and content like #{value}
+			</if>
+		</where>	
+	</select>
+
+	
+<select id="selectByType" parameterType="int" resultType="com.cloudcross.ssp.model.Message">
+		select 
+		<include refid="base_column" />
+		from t_message
+		<where>
+		<if test="type!=null">	
+			and type = #{type}
+		</if>
+			
+		</where>
+	</select>
+<!-- 	
+	<select id="selectByRead"  parameterType="int"  resultType="Message">
+		select t_message.*,t_message_read.account_id 
+	 from t_message left join t_message_read on t_message.id=t_message_read.message_id  	
+	</select>	
+	
+<select id="selectByParams"  parameterType="map" resultType="Message">
+		select 
+		<include refid="base_column" />
+		from t_message where 1 = 1
+			
+		<if test="type!=null">	
+			and type = #{type}
+		</if>
+		
+		order by id   desc
+		limit #{pager.offset}, #{pager.limit}
+	</select>
+
+
+  -->	
+
+	
+</mapper>
+	

+ 57 - 0
src/main/java/com/cloudcross/ssp/model/mapper/messageRead.sql.xml

@@ -0,0 +1,57 @@
+<?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="messageReadSqlMapper">
+	
+	<sql id="base_column">
+		id,
+		message_id as messageId,
+		account_id as accountId,
+	</sql>
+	
+	<insert id="addMessageRead" parameterType="com.cloudcross.ssp.back.model.MessageRead">
+		insert into t_message_read (message_id,account_id)
+		values(#{messageId},#{accountId})
+	</insert>
+	
+<!-- 	<select id="selectByParams"  parameterType="map" resultType="Message">
+		select 
+		<include refid="base_column" />
+		from t_message where 1 = 1
+	
+		<if test="type!=null">	
+			and t_message.type = #{type}
+		</if>
+		
+		order by id   desc
+		limit #{pager.offset}, #{pager.limit}
+	</select>
+	
+	<select id="countByParams" parameterType="map" resultType="int">
+		select count(id)
+		from t_message where 1 = 1	
+	</select>
+	
+	<update id="updateRead" parameterType="HashMap">
+	update t_order 
+		set t_message.read = #{read},send_time = #{modifyDate}
+		where t_message.id in
+		<foreach item="messageId" collection="messageIdList"
+	      open="(" separator="," close=")">
+	        #{messageId}
+		</foreach>
+	</update>
+
+	 -->
+	<select id="selectByAccountId" parameterType="java.lang.Long" resultType="long">
+		select message_id from t_message_read where 1=1
+		
+		<if test="_parameter!=null">	
+		 and t_message_read.account_id = #{_parameter,jdbcType=VARCHAR}
+		</if>
+		
+	</select>
+	
+
+	
+</mapper>
+	

+ 94 - 0
src/main/java/com/cloudcross/ssp/model/mapper/operator-balance.sql.xml

@@ -0,0 +1,94 @@
+<?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="operatorBalanceSqlMapper">
+	<sql id="base_column">
+		id,
+		operator_id as operatorId,
+		act_time as actTime,
+		num,
+		amount,
+		state,
+		balance,
+		income
+	</sql>
+	
+	<insert id="addOperatorBalance" parameterType="com.cloudcross.ssp.model.OperatorBalance"  useGeneratedKeys="true"
+		keyProperty="id">
+		insert into t_operator_balance(operator_id,act_time,num,amount,state,balance)
+		values(#{operatorId},#{actTime},#{num},#{amount},#{state},#{balance})	
+	</insert>
+	<select id="findSumAmountByOperatorId" parameterType="long" resultType="float">
+		select sum(amount) from t_operator_balance where
+		operator_id = #{operatorId} and state != 2
+	</select>
+	
+	<select id="countByParams" parameterType="map" resultType="int">
+		select count(id) from t_operator_balance
+		<where> 
+		amount > 0
+		<if test="num != null">
+			and num like #{num}
+		</if>
+		</where>
+	</select>
+	<!--从operatorsql中copy  countByParams -> countByParamsOperator  -->
+	<select id="countByParamsOperator" parameterType="map" resultType="int">
+		select count(id) from t_operator_balance
+		where operator_id = #{operatorId} and amount > 0
+	</select>
+	<!--从operatorsql中copy  findFinancial -> findFinancial  -->
+	<select id="findFinancial" parameterType="map" resultType="com.cloudcross.ssp.model.OperatorBalance">
+		select 
+		impression,click,ecpm,income
+		from t_rpt_zone
+	</select>
+	
+	<select id="findByParams" parameterType="map" resultType="com.cloudcross.ssp.model.OperatorBalance">
+		select <include refid="base_column"/> from t_operator_balance
+		<where> 
+		amount > 0
+		<if test="num != null">
+			and num like #{num}
+		</if>
+		</where>
+		order by act_time desc
+		limit #{pager.offset}, #{pager.limit} 
+	</select>
+	<!--从operatorsql中copy  findByParams -> findByParamsOperator  -->
+	<select id="findByParamsOperator" parameterType="map" resultType="com.cloudcross.ssp.model.OperatorBalance">
+		select <include refid="base_column"/> from t_operator_balance
+		where operator_id = #{operatorId} and amount > 0
+		order by act_time desc
+		limit #{pager.offset}, #{pager.limit} 
+	</select>
+	<!--从operatorsql中copy  findByParams1 -> findByParams1 -->
+	<select id="findByParams1" parameterType="map" resultType="com.cloudcross.ssp.model.OperatorBalance">
+		select <include refid="base_column"/> from t_operator_balance
+		where operator_id = #{operatorId}  and amount > 0
+		order by act_time desc
+	</select>
+	<!--从operatorsql中copy  findAvailableMoney -> findAvailableMoney -->
+	<select id="findAvailableMoney" parameterType="long" resultType="float">
+		select balance from t_operator_balance where operator_id = #{operatorId}
+        order by id desc limit 1
+	</select>
+	
+	<update id="updateOperatorBalanceStatus" parameterType="HashMap">
+		update t_operator_balance 
+		set state=#{state}
+		<if test="reason != null">
+			  ,memo=#{reason}
+		</if>
+		where id in
+		<foreach item="id" collection="idList" open="(" separator=","
+			close=")">
+			#{id}
+		</foreach>
+	</update>
+	
+	<update id="moneyBackToOperator" parameterType="long">
+		update t_operator_balance  set balance = balance + (select amount from (select amount from t_operator_balance where id = #{id}) as a) where id = (select id from 
+(select id from t_operator_balance where operator_id = (select operator_id from t_operator_balance where id = #{id}) order by id desc limit 1) as foo )
+	</update>
+	
+</mapper>

+ 418 - 0
src/main/java/com/cloudcross/ssp/model/mapper/operator-report.sql.xml

@@ -0,0 +1,418 @@
+<?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="operatorReportSqlMapper">
+	
+	<select id="findCountForDeliverEffectAnalysis" parameterType="map" resultType="int">
+		select count(date) from ((
+		select distinct date 
+		from t_rpt_zone  
+		<where>
+		date &gt;= #{startDate} and #{endDate} &gt;=date
+		<if test="zoneId != null">
+		and zone_id=#{zoneId}
+		</if>
+		<if test="operatorId != null">
+		and operator_id=#{operatorId}
+		</if>
+		</where>
+		) as a)
+	</select>
+	
+	
+	<select id="findDeliverEffectAnalysis" parameterType="map" resultType="com.cloudcross.ssp.back.model.OperatorReport">
+		select 
+		zone_id as zoneId,date as reportDate,sum(pv) as pv,sum(uv) as uv,sum(impression) as impression,
+		sum(uimpression) as uImpression, sum(uclick) as uClick,
+		100*sum(impression)/sum(pv) as fillRate,
+        sum(click) as click,100* sum(click)/sum(impression) as clickRate,sum(ecpm) as eCpm,sum(income) as income
+		from t_rpt_zone 
+		<where>
+		date &gt;= #{startDate} and #{endDate} &gt;=date
+		<if test="zoneId!=null">
+		and zone_id=#{zoneId}
+		</if>
+		<if test="operatorId != null">
+		and operator_id=#{operatorId}
+		</if>
+		</where>
+		group by date
+		limit #{pager.offset}, #{pager.limit}
+	</select>
+	
+	<select id="findSum" parameterType="map" resultType="com.cloudcross.ssp.back.model.OperatorReport">
+		select sum(pv) as pv, sum(uv) as uv, sum(impression) as impression, sum(click) as click, sum(income) as income
+		from t_rpt_zone where date &gt;= #{startDate} and #{endDate} &gt;=date
+		<if test="zoneId!=null">
+		and zone_id=#{zoneId}
+		</if>
+		<if test="operatorId != null">
+		and operator_id=#{operatorId}
+		</if>
+	</select>
+	
+	
+	<select id="findDeliverEffectAnalysis1" parameterType="map" resultType="com.cloudcross.ssp.back.model.OperatorReport">
+		select 
+		zone_id as zoneId,date as reportDate,sum(pv) as pv,sum(uv) as uv,sum(impression) as impression,
+		sum(uimpression) as uImpression, sum(uclick) as uClick,
+		100*sum(impression)/sum(pv) as fillRate,
+        sum(click) as click,100* sum(click)/sum(impression) as clickRate,sum(ecpm) as eCpm,sum(income) as income
+		from t_rpt_zone 
+		<where>
+		date &gt;= #{startDate} and #{endDate} &gt;=date
+		<if test="zoneId!=null">
+		and zone_id=#{zoneId}
+		</if>
+		<if test="operatorId != null">
+		and operator_id=#{operatorId}
+		</if>
+		</where>
+		group by date
+	</select>
+	
+	<select id="countBySize" parameterType="map" resultType="int">
+		 select count(height) from ((select distinct width,height from t_rpt_zone_size where 
+		  date &gt;= #{startDate} and #{endDate} &gt;=date
+		  <if test="operatorId!=null">
+		    and operator_id=#{operatorId}
+		 </if>
+		 ) as a )
+	</select>
+	
+	<select id="findBySize" parameterType="map" resultType="com.cloudcross.ssp.back.model.OperatorReport">
+		select 
+	    id,date as reportDate,width ,height,100*sum(pv)/(select sum(pv) from t_rpt_zone_size 
+	    where
+            date &gt;= #{startDate} and #{endDate} &gt;=date
+		  <if test="operatorId!=null">
+		    and operator_id=#{operatorId}
+		 </if>
+		) as viewRate,sum(pv) as pv,sum(uv) as uv,sum(impression) as impression,
+		sum(uimpression) as uImpression, sum(uclick) as uClick,
+		100*impression/pv as fillRate,sum(click) as click,100*sum(click)/sum(impression) as clickRate,sum(ecpm) as eCpm,sum(income) as income
+		from t_rpt_zone_size 
+		where
+            date &gt;= #{startDate} and #{endDate} &gt;=date
+		  <if test="operatorId!=null">
+		    and operator_id=#{operatorId}
+		 </if>
+		group by width,height
+		order by impression desc
+		limit #{pager.offset}, #{pager.limit}
+	</select>
+	
+	<select id="findBySize1" parameterType="map" resultType="com.cloudcross.ssp.back.model.OperatorReport">
+		select 
+	    id,date as reportDate,width ,height,100*sum(pv)/(select sum(pv) from t_rpt_zone_size 
+	    where
+            date &gt;= #{startDate} and #{endDate} &gt;=date
+		  <if test="operatorId!=null">
+		    and operator_id=#{operatorId}
+		 </if>
+		) as viewRate,sum(pv) as pv,sum(uv) as uv,sum(impression) as impression,
+		sum(uimpression) as uImpression, sum(uclick) as uClick,
+		100*sum(impression)/sum(pv) as fillRate,sum(click) as click,100*sum(click)/sum(impression) as clickRate,sum(ecpm) as eCpm,sum(income) as income
+		from t_rpt_zone_size 
+		where
+            date &gt;= #{startDate} and #{endDate} &gt;=date
+		  <if test="operatorId!=null">
+		    and operator_id=#{operatorId}
+		 </if>
+		group by width,height
+		order by impression desc
+	</select>
+	
+	
+	<select id="countByPosition" parameterType="map" resultType="int">
+		select count(position) from ((select distinct position from t_rpt_zone_position where 
+		 date &gt;= #{startDate} and #{endDate} &gt;=date
+		  <if test="operatorId!=null">
+		    and operator_id=#{operatorId}
+		 </if>
+		 ) as a )
+	</select>
+	
+	<select id="findByPosition" parameterType="map" resultType="com.cloudcross.ssp.back.model.OperatorReport">
+		select 
+	    id,date as reportDate,position,100*sum(pv)/(select sum(pv) from t_rpt_zone_position where 
+		 date &gt;= #{startDate} and #{endDate} &gt;=date
+		  <if test="operatorId!=null">
+		    and operator_id=#{operatorId}
+		 </if>
+		 ) as viewRate,sum(pv) as pv,sum(uv) as uv,sum(impression) as impression ,
+		 sum(uimpression) as uImpression, sum(uclick) as uClick,
+		 100*sum(impression)/sum(pv) as fillRate,sum(click) as click ,100*sum(click)/sum(impression) as clickRate,sum(eCpm) as eCpm,sum(income) as income 
+		from t_rpt_zone_position
+		where 
+		 date &gt;= #{startDate} and #{endDate} &gt;=date
+		  <if test="operatorId!=null">
+		    and operator_id=#{operatorId}
+		 </if>
+		group by position 
+		order by impression desc 
+      	limit #{pager.offset}, #{pager.limit}
+	</select>
+	
+	<select id="findByPosition1" parameterType="map" resultType="com.cloudcross.ssp.back.model.OperatorReport">
+		select 
+	    id,date as reportDate,position,100*sum(pv)/(select sum(pv) from t_rpt_zone_position where 
+		 date &gt;= #{startDate} and #{endDate} &gt;=date
+		  <if test="operatorId!=null">
+		    and operator_id=#{operatorId}
+		 </if>
+		 ) as viewRate,sum(pv) as pv,sum(uv) as uv,sum(impression) as impression ,
+		 sum(uimpression) as uImpression, sum(uclick) as uClick,
+		 100*sum(impression)/sum(pv) as fillRate,sum(click) as click ,100*sum(click)/sum(impression) as clickRate,sum(eCpm) as eCpm,sum(income) as income 
+		from t_rpt_zone_position
+		where 
+		 date &gt;= #{startDate} and #{endDate} &gt;=date
+		  <if test="operatorId!=null">
+		    and operator_id=#{operatorId}
+		 </if>
+		group by position  
+		order by impression desc
+	</select>
+	
+	<select id="countBySystem" parameterType="map" resultType="int">
+		  select count(os) from ((select distinct os from t_rpt_zone_os where 
+		  date &gt;= #{startDate} and #{endDate} &gt;=date
+		  <if test="operatorId!=null">
+		    and operator_id=#{operatorId}
+		 </if>
+		  ) as a)
+	</select>
+	<select id="findBySystem" parameterType="map" resultType="com.cloudcross.ssp.back.model.OperatorReport">
+		select 
+	    os as system,100*(sum(pv)/(select sum(pv) from t_rpt_zone_os
+		where date &gt;= #{startDate} and #{endDate} &gt;=date
+		<if test="operatorId!=null">
+		    and operator_id=#{operatorId}
+		</if> 
+		   )) as viewRate,
+		sum(pv) as pv,sum(uv) as uv,sum(impression) as impression,
+		sum(uimpression) as uImpression, sum(uclick) as uClick,
+		100*(sum(impression)/sum(pv)) as fillRate,
+        sum(click) as click,100*(sum(click)/sum(impression)) as clickRate,sum(ecpm) as eCpm,sum(income) as income
+		from t_rpt_zone_os 
+		where date &gt;= #{startDate} and #{endDate} &gt;=date
+		<if test="operatorId!=null">
+		    and operator_id=#{operatorId}
+		</if>
+		group by os
+		order by impression desc
+		limit #{pager.offset}, #{pager.limit}
+	</select>
+	
+	
+	<select id="findBySystem1" parameterType="map" resultType="com.cloudcross.ssp.back.model.OperatorReport">
+		select 
+	    os as system,100*(sum(pv)/(select sum(pv) from t_rpt_zone_os
+		where date &gt;= #{startDate} and #{endDate} &gt;=date
+		<if test="operatorId!=null">
+		    and operator_id=#{operatorId}
+		</if> 
+		   )) as viewRate,
+		sum(pv) as pv,sum(uv) as uv,sum(impression) as impression,
+		sum(uimpression) as uImpression, sum(uclick) as uClick,
+		100*(sum(impression)/sum(pv)) as fillRate,
+        sum(click) as click,100*(sum(click)/sum(impression)) as clickRate,sum(ecpm) as eCpm,sum(income) as income
+		from t_rpt_zone_os 
+		where date &gt;= #{startDate} and #{endDate} &gt;=date
+		<if test="operatorId!=null">
+		    and operator_id=#{operatorId}
+		</if>
+		group by os
+		order by impression desc
+	</select>
+	
+	
+	<select id="findByDevice" parameterType="map" resultType="com.cloudcross.ssp.back.model.OperatorReport">
+		select 
+	    id,date as reportDate,device,100*sum(pv)/
+	    (select sum(pv) from t_rpt_zone_device where date &gt;= #{startDate} and #{endDate} &gt;=date
+		<if test="operatorId!=null">
+		    and operator_id=#{operatorId}
+		</if> ) as viewRate,
+	    sum(pv) as pv,sum(uv) as uv,sum(impression) as impression ,
+	    sum(uimpression) as uImpression, sum(uclick) as uClick,
+	    100*sum(impression)/sum(pv) as fillRate,sum(click) as click ,100*sum(click)/sum(impression) as clickRate,sum(eCpm) as eCpm,sum(income) as income
+        from t_rpt_zone_device
+		where date &gt;= #{startDate} and #{endDate} &gt;=date
+		<if test="operatorId!=null">
+		    and operator_id=#{operatorId}
+		</if> 
+		group by device 
+		order by impression desc
+	</select>
+	
+	<select id="countByAllAreal" parameterType="map" resultType="int">
+		select count(cn) from ((select distinct cn from t_rpt_zone_location a,t_location b 
+  		where
+		a.location = b.location and date &gt;= #{startDate} and #{endDate} &gt;=date
+		<if test="operatorId!=null">
+		    and operator_id=#{operatorId}
+		</if> ) as t)
+	</select>
+	
+	<select id="findByAllAreal" parameterType="map" resultType="com.cloudcross.ssp.back.model.OperatorReport">
+		  select 
+	    a.id,a.date as reportDate,b.cn,b.cn_city,100*sum(a.pv)/(select sum(pv) from t_rpt_zone_location where date &gt;= #{startDate} and #{endDate} &gt;=date
+		<if test="operatorId!=null">
+		    and operator_id=#{operatorId}
+		</if>) as viewRate,
+	    sum(a.pv) as pv,sum(a.uv) as uv,sum(a.impression) as impression,
+	    sum(uimpression) as uImpression, sum(uclick) as uClick,100*sum(a.impression)/sum(a.pv) as fillRate,sum(a.click) as click,100*sum(a.click)/sum(a.impression) as clickRate,sum(a.eCpm) as eCpm,sum(a.income) as income
+		from t_rpt_zone_location a,t_location b
+	 	where
+		a.location = b.location  and a.date &gt;= #{startDate} and #{endDate} &gt;=a.date
+		<if test="operatorId!=null">
+		    and operator_id=#{operatorId}
+		</if>
+		group by b.cn 
+		 order by cn
+		limit #{pager.offset}, #{pager.limit}
+	</select>
+	
+	<select id="findByAreal" parameterType="map" resultType="com.cloudcross.ssp.back.model.OperatorReport">
+		select 
+	    b.cn,b.cn_city,100*sum(a.pv)/(select sum(pv) from t_rpt_zone_location where date &gt;= #{startDate} and #{endDate} &gt;=date
+		<if test="operatorId!=null">
+		    and operator_id=#{operatorId}
+		</if>) as viewRate,
+	    sum(a.pv) as pv,sum(a.uv) as uv,sum(a.impression),
+	    sum(uimpression) as uImpression, sum(uclick) as uClick,
+	    100*sum(a.impression)/sum(a.pv) as fillRate,sum(a.click),100*sum(a.click)/sum(a.impression) as clickRate,sum(a.eCpm) as eCpm,sum(a.income) as income
+		from t_rpt_zone_location a,t_location b
+		where
+		a.location=b.location and b.cn=#{cn} and date &gt;= #{startDate} and #{endDate} &gt;=date
+		<if test="operatorId!=null">
+		    and operator_id=#{operatorId}
+		</if>
+       group by b.cn_city
+	</select>
+	
+	<select id="findAllArea" parameterType="map" resultType="com.cloudcross.ssp.back.model.OperatorReport">
+		select 
+	    a.id,a.date as reportDate,b.cn,b.cn_city,100*sum(a.pv)/(select sum(pv) from t_rpt_zone_location where date &gt;= #{startDate} and #{endDate} &gt;=date
+		<if test="operatorId!=null">
+		    and operator_id=#{operatorId}
+		</if>) as viewRate,
+	    sum(a.pv) as pv,sum(a.uv) as uv,sum(a.impression) as impression,
+	    sum(uimpression) as uImpression, sum(uclick) as uClick,
+	    100*sum(a.impression)/sum(a.pv) as fillRate,sum(a.click) as click,100*sum(a.click)/sum(a.impression) as clickRate,sum(a.eCpm) as eCpm,sum(a.income) as income
+		from t_rpt_zone_location a,t_location b
+	 	where
+		a.location = b.location  and a.date &gt;= #{startDate} and #{endDate} &gt;=a.date
+		<if test="operatorId!=null">
+		    and operator_id=#{operatorId}
+		</if>
+		group by b.cn 
+		order by b.cn
+	</select>
+	
+	
+	<select id="countByPlace" parameterType="map" resultType="int">
+		select count(place_id) from ((select distinct place_id from t_rpt_zone_place where 
+		date &gt;= #{startDate} and #{endDate} &gt;=date
+		<if test="operatorId!=null">
+		    and operator_id=#{operatorId}
+		</if>) as a) 
+	</select>
+	
+	<select id="findByPlace" parameterType="map" resultType="com.cloudcross.ssp.back.model.OperatorReport">
+		select t_place.name as place,sum(p.pv) as pv, sum(p.uv) as uv, sum(p.impression) as impression,
+		sum(uimpression) as uImpression, sum(uclick) as uClick,
+		 sum(p.click) as click, sum(p.ecpm) as eCpm,
+    sum(p.income) as income, 100 * sum(p.pv) / (select sum(pv) from t_rpt_zone_place where date &gt;= #{startDate} and #{endDate} &gt;=date
+		<if test="operatorId!=null">
+		    and operator_id=#{operatorId}
+		</if> ) as viewRate, 
+    100 * sum(p.impression) / sum(p.pv) as fillRate, 100 * sum(p.click) / sum(p.impression) as clickRate
+    from ((select distinct place_id from t_rpt_zone_place where date &gt;= #{startDate} and #{endDate} &gt;=date
+		<if test="operatorId!=null">
+		    and operator_id=#{operatorId}
+		</if> ) as a ), 
+    t_rpt_zone_place as p, t_place where a.place_id = p.place_id and a.place_id = t_place.id
+    and date &gt;= #{startDate} and #{endDate} &gt;=date
+		<if test="operatorId!=null">
+		    and operator_id=#{operatorId}
+		</if> 
+    group by p.place_id
+    order by p.impression desc
+	limit #{pager.offset}, #{pager.limit}
+	</select>
+	
+	
+	<select id="findByPlace1" parameterType="map" resultType="com.cloudcross.ssp.back.model.OperatorReport">
+		select t_place.name as place,sum(p.pv) as pv, sum(p.uv) as uv, sum(p.impression) as impression, 
+		sum(uimpression) as uImpression, sum(uclick) as uClick,
+		sum(p.click) as click, sum(p.ecpm) as eCpm,
+    sum(p.income) as income, 100 * sum(p.pv) / (select sum(pv) from t_rpt_zone_place where date &gt;= #{startDate} and #{endDate} &gt;=date
+		<if test="operatorId!=null">
+		    and operator_id=#{operatorId}
+		</if> ) as viewRate, 
+    100 * sum(p.impression) / sum(p.pv) as fillRate, 100 * sum(p.click) / sum(p.impression) as clickRate
+    from ((select distinct place_id from t_rpt_zone_place where date &gt;= #{startDate} and #{endDate} &gt;=date
+		<if test="operatorId!=null">
+		    and operator_id=#{operatorId}
+		</if> ) as a ), 
+    t_rpt_zone_place as p, t_place where a.place_id = p.place_id and a.place_id = t_place.id
+    and date &gt;= #{startDate} and #{endDate} &gt;=date
+		<if test="operatorId!=null">
+		    and operator_id=#{operatorId}
+		</if> 
+    group by p.place_id
+    order by p.impression desc
+	</select>
+	
+	<select id="countByApmac" parameterType="map" resultType="int">
+			select count(apmac) from ((select distinct apmac from t_rpt_zone_ap where 
+		 date &gt;= #{startDate} and date &lt;= #{endDate}
+		 <if test="operatorId!=null">
+		    and operator_id=#{operatorId}
+		</if>
+		 ) as a) 
+	</select>
+	
+	<select id="findByApmac" parameterType="map" resultType="com.cloudcross.ssp.back.model.OperatorReport">
+		select apmac, sum(pv) as pv, sum(uv) as uv, sum(impression) as impression, 
+		sum(uimpression) as uImpression,
+		sum(uclick) as uClick,sum(click) as click, sum(ecpm) as eCpm,
+    sum(income) as income, 100 * sum(pv) / (select sum(pv) from t_rpt_zone_ap where date &gt;= #{startDate} and date &lt;= #{endDate}
+    <if test="operatorId!=null">
+		    and operator_id=#{operatorId}
+	</if>
+    ) as viewRate, 
+    100 * sum(impression) / sum(pv) as fillRate, 100 * sum(click) / sum(impression) as clickRate
+    from  t_rpt_zone_ap  where 
+    date &gt;= #{startDate} and date &lt;= #{endDate}
+    <if test="operatorId!=null">
+		    and operator_id=#{operatorId}
+	</if>
+    group by apmac
+    order by impression desc
+	limit #{pager.offset}, #{pager.limit}
+	</select>
+	
+	<select id="findByApmac1" parameterType="map" resultType="com.cloudcross.ssp.back.model.OperatorReport">
+			select apmac, sum(pv) as pv, sum(uv) as uv, sum(impression) as impression, 
+		sum(uimpression) as uImpression,
+		sum(uclick) as uClick,sum(click) as click, sum(ecpm) as eCpm,
+    sum(income) as income, 100 * sum(pv) / (select sum(pv) from t_rpt_zone_ap where date &gt;= #{startDate} and date &lt;= #{endDate}
+    <if test="operatorId!=null">
+		    and operator_id=#{operatorId}
+	</if>
+    ) as viewRate, 
+    100 * sum(impression) / sum(pv) as fillRate, 100 * sum(click) / sum(impression) as clickRate
+    from  t_rpt_zone_ap  where 
+    date &gt;= #{startDate} and date &lt;= #{endDate}
+    <if test="operatorId!=null">
+		    and operator_id=#{operatorId}
+	</if>
+    group by apmac
+    order by impression desc
+	</select>
+	
+	
+	
+</mapper>

+ 115 - 0
src/main/java/com/cloudcross/ssp/model/mapper/operator.sql.xml

@@ -0,0 +1,115 @@
+<?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="operatorSqlMapper">
+	
+	<sql id="base_column">
+	id,
+	company_name as companyName,
+	link_man as linkMan,
+	tel,
+	account,
+	mobile,
+	homepage as homePage,
+	account_name as accountName,
+	bank,
+	status,
+	admin_id as adminId,
+	address,
+	zip,
+	email
+	</sql>
+	<select id="findById" parameterType="long" resultType="com.cloudcross.ssp.model.Operator">
+		select 
+		<include refid="base_column" />
+		from t_operator
+		<where>
+			id = #{id} and status !=-1
+		</where>
+	</select>
+	
+	<select id="getNew" parameterType="com.cloudcross.ssp.back.model.Operator" resultType="com.cloudcross.ssp.back.model.Operator">
+		select 
+		<include refid="base_column" />
+		from t_operator
+		<where>
+			status !=-1 and admin_id = #{adminId} and account_name = #{accountName}  and company_name = #{companyName}
+		</where>
+	</select>
+	
+	<select id="findAllOperator" resultType="com.cloudcross.ssp.model.Operator">
+		select 
+		<include refid="base_column" />
+		from t_operator
+		<where>
+			 status !=-1
+		</where>
+	</select>
+	
+	<update id="editOperator" parameterType="com.cloudcross.ssp.model.Operator">
+		update t_operator
+		<set>
+			<if test="accountName != null and accountName != ''">
+				account_name=#{accountName},
+			</if>
+			<if test="account != null and account != ''">
+				account=#{account},
+			</if>
+			<if test="companyName != null and companyName != ''">
+				company_name=#{companyName},
+			</if>
+			<if test="status != null and status != ''">
+				status=#{status},
+			</if>
+			<if test="linkMan != null and linkMan != ''">
+				link_man=#{linkMan},
+			</if>
+			<if test="tel != null and tel != ''">
+				tel=#{tel},
+			</if>
+			<if test="bank != null and bank != ''">
+				bank=#{bank},
+			</if>
+			<if test="mobile != null and mobile != ''">
+				mobile=#{mobile},
+			</if>
+			<if test="homePage != null and homePage != ''">
+				homepage=#{homePage},
+			</if>
+			<if test="address != null and address != ''">
+				address=#{address},
+			</if>
+			<if test="zip != null and zip != ''">
+				zip=#{zip},
+			</if>
+			<if test="email != null and email != ''">
+				email=#{email}
+			</if>
+		</set>
+		where id=#{id}
+	</update>
+	
+	<insert id="add" parameterType="com.cloudcross.ssp.back.model.Operator">
+		insert into t_operator(company_name,link_man,tel,mobile,account,homepage,account_name,bank,status,admin_id,address,zip,email)
+		values(#{companyName},#{linkMan},#{tel},#{mobile},#{account},#{homePage},#{accountName},#{bank}, #{status},#{adminId},#{address},#{zip},#{email})
+	</insert>
+	
+	<select id="selectById" parameterType="int" resultType="com.cloudcross.ssp.back.model.Operator">
+		select 
+		<include refid="base_column" />
+		from t_operator
+		<where>
+			id = #{id} and status !=-1
+		</where>
+	</select>
+	
+	<update id="updateOperatorStatus" parameterType="HashMap">
+		update t_operator
+			set status = #{status},supdated = NOW()
+			where id in
+			<foreach item="operatorId" collection="operatorList"
+		      open="(" separator="," close=")">
+		        #{operatorId}
+			</foreach>
+	</update>
+	
+</mapper>

+ 273 - 0
src/main/java/com/cloudcross/ssp/model/mapper/order.sql.xml

@@ -0,0 +1,273 @@
+<?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="orderSqlMapper">
+	
+	<sql id="base_column">
+		t_order.id as id,
+		t_order.advertiser_id as advertiserId,
+		t_order.name as name,
+		t_order.budget as budget,
+		t_order.comment as comment,
+		t_order.status as status,
+		t_order.updated as updated
+		
+	</sql>
+	
+	<select id="selectByParamsAdvertiser"  parameterType="map" resultType="com.cloudcross.ssp.model.Order">
+		select 
+		<include refid="base_column" />
+	,count(t_campaign.order_id) as campaignNumber from t_order left join t_campaign on t_order.id = t_campaign.order_id 
+        and t_campaign.status != -1 and t_campaign.advertiser_id = #{advertiserId}
+		where 1=1
+		<if test="advMark!=null">
+			and t_order.agent_id = #{agentId}
+		</if> 
+		<if test="advMark==null">
+			and t_order.advertiser_id = #{advertiserId}
+		</if> 
+		and t_order.status != -1
+		<if test="value!=null">
+			and t_order.name like #{value}
+		</if>
+		
+		<if test="status!=null">	
+			and t_order.status = #{status}
+		</if>
+		group by t_order.id	
+		order by t_order.id   desc
+		limit #{pager.offset}, #{pager.limit}
+	</select>
+	
+	  <select id="countByParamsAdvertiser" parameterType="map" resultType="int">
+		select count(t_order.id)
+		from t_order where status != -1
+		<if test="advMark!=null">
+			and t_order.agent_id = #{agentId}
+		</if> 
+		<if test="advMark==null">
+			and t_order.advertiser_id = #{advertiserId}
+		</if> 
+		<if test="value!=null">
+			and t_order.name like #{value}
+		</if>
+		<if test="status!=null">	
+			and t_order.status = #{status}
+		</if>
+	</select>
+	
+	
+	
+		<select id="selectByParamsOperator"  parameterType="map" resultType="com.cloudcross.ssp.model.Order">
+		select 
+		<include refid="base_column" />
+	,count(t_campaign.order_id) as campaignNumber from t_order left join t_campaign on t_order.id = t_campaign.order_id 
+		where
+		t_order.advertiser_id = #{advertiserId} 
+		and t_order.status != -1
+		<if test="key!=null and value!=null">
+			<choose>
+				<when test="key=='name'">
+					and t_order.name like #{value}
+				</when>
+			</choose>	
+		</if>
+		
+		<if test="status!=null">	
+			and t_order.status = #{status}
+		</if>
+		group by t_order.id	
+		order by t_order.id   desc
+		limit #{pager.offset}, #{pager.limit}
+	</select>
+	
+		<select id="countByParamsOperator" parameterType="map" resultType="int">
+		select count(t_order.id)
+		from t_order where status != -1
+		and t_order.advertiser_id = #{advertiserId} 
+		<if test="key!=null and value!=null">
+			<choose>
+				<when test="key=='name'">
+					and t_order.name like #{value}
+				</when>
+			</choose>	
+		</if>
+		
+		<if test="status!=null">	
+			and t_order.status = #{status}
+		</if>
+		
+		 <if test="status!=null">	
+			and t_order.status = #{status}
+		</if>	
+	</select>
+	
+	<select id="selectByParamsBack"  parameterType="map" resultType="com.cloudcross.ssp.model.Order">
+		select 
+		<include refid="base_column" />
+	,count(t_campaign.order_id) as campaignNumber from t_order left join t_campaign on t_order.id = t_campaign.order_id 
+		where
+		t_order.advertiser_id = #{advertiserId} 
+		and t_order.status != -1
+		<if test="value!=null">
+			and t_order.name like #{value}
+		</if>
+		
+		<if test="status!=null">	
+			and t_order.status = #{status}
+		</if>
+		group by t_order.id	
+		order by t_order.id   desc
+		limit #{pager.offset}, #{pager.limit}
+	</select>
+	
+	 <select id="countByParamsBack" parameterType="map" resultType="int">
+		select count(t_order.id)
+		from t_order where status != -1
+		and t_order.advertiser_id = #{advertiserId} 
+		<if test="value!=null">
+			and t_order.name like #{value}
+		</if>
+		
+		<if test="status!=null">	
+			and t_order.status = #{status}
+		</if>
+		
+		 <if test="status!=null">	
+			and t_order.status = #{status}
+		</if>	
+	</select>
+	
+
+	
+	 
+	
+	  <select id="selectByAdvertiserType" parameterType="string" resultType="com.cloudcross.ssp.model.Order">
+		select
+		<include refid="base_column" />
+		from t_order where advertiser_id=#{advertiserType} 
+		and status != -1
+	</select>
+	
+	
+	<select id="selectByStatus"  parameterType="map" resultType="com.cloudcross.ssp.model.Advertiser">
+		select 
+		<include refid="base_column" />
+		,count(t_campaign.order_id) as campaignNumber from t_order left join t_campaign on t_order.id = t_campaign.order_id 
+		 where 1 = 1 
+		 and t_order.status = #{status}
+		 and t_order.advertiser_id = #{advertiserId}  
+		group by t_order.id
+		order by t_order.id   desc
+		limit #{pager.offset}, #{pager.limit}
+	</select>
+	
+
+	
+	<select id="selectById" parameterType="int" resultType="com.cloudcross.ssp.model.Order">
+		select 
+		<include refid="base_column" />
+		from t_order
+		<where>
+			id = #{id} and
+			status != -1
+		</where>
+	</select>
+	
+	<select id="findByAdvertiserId" parameterType="int" resultType="com.cloudcross.ssp.model.Order">
+		select 
+		<include refid="base_column" />
+		from t_order
+		<where>
+			advertiser_id = #{advertiserId}
+			and
+			status != -1
+		</where>
+	</select>
+	
+	<select id="selectByName" parameterType="String" resultType="long">
+		select
+		max(id)
+		from t_order
+		<where>
+			t_order.name = #{name} and
+			status != -1
+		</where>
+	</select>
+	
+	
+	<insert id="addOrder" parameterType="com.cloudcross.ssp.model.Order">
+		insert into t_order(name,budget,comment,updated,advertiser_id,agent_id)
+		values(#{name},#{budget},#{comment},#{updated},#{advertiserId},#{agentId})
+	</insert>
+	
+	<insert id="addOrderBack" parameterType="com.cloudcross.ssp.model.Order">
+		insert into t_order(name,budget,comment,updated,advertiser_id)
+		values(#{name},#{budget},#{comment},#{updated},#{advertiserId})
+	</insert>
+	
+	<update id="editOrder" parameterType="com.cloudcross.ssp.model.Order">
+		update t_order set t_order.name=#{name},t_order.budget=#{budget},t_order.comment=#{comment},
+		<if test="status !=null">
+			status=#{status},
+			</if>
+			updated=#{updated} 
+		 where t_order.id=#{id}
+	</update>
+	
+	<update id="updateOrderStatus" parameterType="HashMap">
+		update t_order 
+			set status = #{status},updated = #{modifyDate}
+			where t_order.id in
+			<foreach item="orderId" collection="orderIdList"
+		      open="(" separator="," close=")">
+		        #{orderId}
+			</foreach>
+	</update>
+	
+	<update id="updateSupdated" parameterType="HashMap">
+		update t_adgroup
+			set t_adgroup.supdated= NOW()
+			where  t_adgroup.order_id in
+			<foreach item="orderId" collection="orderIdList"
+		      open="(" separator="," close=")">
+		        #{orderId}
+			</foreach>
+	</update>
+	
+	<!-- 导出Excel用 -->
+	<select id="findDeliverEffectAnalysis" parameterType="map" resultType="com.cloudcross.ssp.model.Order">
+		select 
+		<include refid="base_column" />
+	,count(t_campaign.order_id) as campaignNumber from t_order left join t_campaign on t_order.id = t_campaign.order_id 
+		where
+		t_order.advertiser_id = #{advertiserId} 
+		and t_order.status != -1
+		<if test="key!=null and value!=null">
+			<choose>
+				<when test="key=='name'">
+					and t_order.name like #{value}
+				</when>
+			</choose>	
+		</if>
+		
+		<if test="status!=null">	
+			and t_order.status = #{status}
+		</if>
+		group by t_order.id	
+		order by t_order.id   desc
+	</select>
+	
+	<select id="selectOrderNameById" parameterType="int" resultType="String">
+		select name from t_order where id = #{id}
+	</select>
+	<update id="updateStatusByAdvertiserId" parameterType="HashMap">
+		update t_order
+			set status = #{status},updated = NOW()
+			where t_order.advertiser_id in
+			<foreach item="advertiserId" collection="advertiserIdList"
+		      open="(" separator="," close=")">
+		        #{advertiserId}
+			</foreach>
+	</update>
+</mapper>
+	

+ 45 - 0
src/main/java/com/cloudcross/ssp/model/mapper/place-operator.sql.xml

@@ -0,0 +1,45 @@
+<?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="placeOperatorSqlMapper">
+	
+	<select id="findByNameAndOperatorId" parameterType="String" resultType="long">
+		select place_id from t_place_operator
+		where name = #{name} and operator_id= #{operatorId}
+	</select>
+	
+	<select id="findPlaceByOperator" parameterType="long" resultType="String">
+		select name from t_place_operator where operator_id = #{operatorId} 
+	</select>
+	
+	<select id="findPlace" parameterType="long" resultType="map">
+		select o.place_id,p.name from t_place_operator o, t_place p where o.place_id = p.id and o.operator_id = #{operatorId}
+	</select>
+	
+	<select id="countByParams" parameterType="map" resultType="int">
+		select count(o.id)
+		from t_place_operator o, t_place p
+		where o.place_id = p.id and o.operator_id = #{operatorId}
+		<if test="searchValue != null">
+		and (o.name like #{searchValue} or p.name like #{searchValue})
+		</if>
+	</select>
+	
+	<select id="findByParams" parameterType="map" resultType="com.cloudcross.ssp.model.PlaceOperator">
+		select o.id as id, o.operator_id as operatorId, o.name as name, p.name as placeName, p.id as placeId
+		from t_place_operator o, t_place p
+		where o.place_id = p.id and o.operator_id = #{operatorId}
+		<if test="searchValue != null">
+		and (o.name like #{searchValue} or p.name like #{searchValue})
+		</if>
+		limit #{pager.offset}, #{pager.limit}
+	</select>
+	
+	<select id="findByParams1" parameterType="map" resultType="com.cloudcross.ssp.model.PlaceOperator">
+		select o.id as id, o.operator_id as operatorId, o.name as name, p.name as placeName, p.id as placeId
+		from t_place_operator o, t_place p
+		where o.place_id = p.id and o.operator_id = #{operatorId}
+		<if test="searchValue != null">
+		and (o.name like #{searchValue} or p.name like #{searchValue})
+		</if>
+	</select>
+</mapper>

+ 21 - 0
src/main/java/com/cloudcross/ssp/model/mapper/place.sql.xml

@@ -0,0 +1,21 @@
+<?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="placeSqlMapper">
+	<sql id="base_column">
+		id,
+		name
+	</sql>
+	
+	<select id="findAll" parameterType="long" resultType="com.cloudcross.ssp.model.Place">
+		select
+		<include refid="base_column"/>
+		from t_place
+	</select>
+	
+	<select id="findById" parameterType="long" resultType="com.cloudcross.ssp.model.Place">
+		select
+		<include refid="base_column"/>
+		from t_place
+		where id = #{id}
+	</select>
+</mapper>

+ 1752 - 0
src/main/java/com/cloudcross/ssp/model/mapper/report.sql.xml

@@ -0,0 +1,1752 @@
+<?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="adReportSqlMapper">
+	
+	<sql id="base_column">
+		id, 
+		advertiser_id as advertiserId,
+		order_id as orderId,
+		campaign_id as campaignId,
+		adgroup_id  as adGroupId,
+		 banner.id as bannerId,
+		t_banner.banner_template_id as bannerTemplateId,
+		t_advertiser.name as advertiserName,
+		t_order.name as orderName,
+		t_campaign.name as campaignName,
+		t_adgroup.name  as adGroupName,
+		t_banner_template.name as bannerName,
+		date as reportDate,
+		request,
+		impression,
+		impressionRate,
+		click,
+		visit,
+		conversion,
+		conversionRate,
+		clickRate,
+		visitRate,
+		conversionRate,
+		ecmp as eCmp,
+		consume,
+		os,
+		location,
+		impressionSum,
+		clickSum,
+		visitSum,
+		conversionSum,
+		eCmpSum,
+		consumeSum,
+		clickRatesum,
+		visitRatesum,
+		conversionRatesum
+		
+	</sql>
+	<sql id="base_column2">
+		id,
+		zone_id as zoneId,
+		pv,
+		uv,
+		width,
+		height,
+		position,
+		os,
+		device,
+		impression,
+		place,
+		click,
+		clickRate,
+		eCpm,
+		income,
+		t_rpt_zone.date as reportDate
+	</sql>
+	
+	<select id="findCountForDeliverEffectAnalysisAdvertiser" parameterType="map" resultType="int">
+		select count(1) from (
+		select b.name advertiserName,c.name orderName,d.name campaignName,e.name adgroupName,g.name bannerName,a.date reportDate,sum(a.impression) as impression,sum(a.click) as click,100*sum(a.click)/sum(a.impression) as clickRate,sum(a.visit) as visit,100*sum(a.visit)/sum(a.click) as visitRate,sum(a.conversion) as conversion,100*sum(a.conversion)/sum(a.visit) as conversionRate,sum(a.ecmp) as ecmp,sum(a.consume) as consume 
+		from t_rpt_advertiser a,t_advertiser b,t_order c,t_campaign d,t_adgroup e,t_banner f,t_banner_template g
+		where a.advertiser_id=b.id and a.order_id=c.id and a.campaign_id=d.id and a.adgroup_id=e.id and a.banner_id=f.id and f.banner_template_id=g.id
+		<if test="advertiserId != null and advertiserId ">
+			and a.advertiser_id = #{advertiserId}
+		</if>
+		<if test="orderId != null and orderId != ''">
+			and a.order_id = #{orderId}
+		</if>
+		<if test="campaginId != null and campaginId != ''">
+			and a.campagin_id = #{campaginId}
+		</if>
+		<if test="adgroupId != null and adgroupId != ''">
+			and a.adgroup_id = #{adgroupId}
+		</if>
+		<if test="startDate != null and startDate != ''and endDate != nul and endDate != ''">
+			and a.date &gt;=#{startDate} and a.date &lt;=#{endDate}
+		</if>
+		<choose>
+			<when test="dimensionStr != null and dimensionStr != ''">
+				GROUP BY ${dimensionStr}
+			</when>
+			<otherwise>
+				group by reportDate order by reportDate desc
+			</otherwise>
+		</choose>
+		) t	
+	</select>
+	<select id="findCountForDeliverEffectAnalysisBack" parameterType="map" resultType="int">
+		select count(1) 
+		from t_rpt_advertiser ad,t_advertiser,t_order, t_campaign, t_banner, t_adgroup, t_banner_template
+           
+        <where>
+	 	    ad.advertiser_id=t_advertiser.id  and  ad.order_id = t_order.id  and ad.campaign_id= t_campaign.id   
+	 	    and  ad.adgroup_id=t_adgroup.id
+            and  ad.banner_id=t_banner.id 
+            and  t_banner.banner_template_id = t_banner_template.id
+	 	   
+			<if test="advertiserId !=null">
+			 and ad.advertiser_id=#{advertiserId}
+			</if>
+			
+			<if test="orderId !=null">
+			 and ad.order_id=#{orderId}
+			</if>
+			  
+		     <if test="campaignId !=null">
+			 and ad.campaign_id=#{campaignId}
+			</if>
+			
+			<if test="adGroupId !=null">
+			 and ad.adgroup_id=#{adGroupId}
+			</if>
+		 
+			<if test="startDate!=null and endDate!=null"> 
+	            and ad.date &gt;= #{startDate} and #{endDate} &gt;=ad.date
+			</if>
+		
+		</where>
+	</select>
+		<select id="findCountForDeliverEffectAnalysisOperator" parameterType="map" resultType="int">
+		select count(date) from ((
+		select distinct date 
+		from t_rpt_zone  
+		<where>
+		operator_id = #{operatorId} and date &gt;= #{startDate} and #{endDate} &gt;=date
+		<if test="zoneId!=null">
+		and zone_id=#{zoneId}
+		</if>
+		</where>
+		) as a)
+	</select>
+	
+	
+	
+	
+		<select id="findCountForLocationAdvertiser" parameterType="map" resultType="int">
+		select count(location) from ( select location
+		from t_rpt_adv_location a, t_advertiser b
+       	<where>	
+       	a.advertiser_id = b.id and a.date &gt;= #{startDate} and #{endDate} &gt;=a.date
+			<if test="advertiserId ==null">
+			 and b.agent_id=#{agentId}
+			</if>
+			<if test="advertiserId != null">
+			and a.advertiser_id = #{advertiserId}	
+			</if>
+			<if test="orderId !=null">
+			 and a.order_id=#{orderId}
+			</if>
+		     <if test="campaignId !=null">
+			 and a.campaign_id=#{campaignId}
+			</if>
+			<if test="adGroupId !=null">
+			 and a.adgroup_id=#{adGroupId}
+			</if>
+		</where>
+		group by a.location
+		) as c
+	</select>
+	
+		<select id="findCountForLocationBack" parameterType="map" resultType="int">
+		select count(1) 
+		from t_rpt_adv_location rl, t_advertiser, t_order, t_campaign, t_adgroup
+        
+       	<where>	
+            rl.advertiser_id = t_advertiser.id  and  rl.order_id =  t_order.id and rl.campaign_id = t_campaign.id  and rl.adgroup_id =  t_adgroup.id
+	 	   	
+			<if test="advertiserId !=null">
+			 and rl.advertiser_id=#{advertiserId}
+			</if>
+			
+			<if test="orderId !=null">
+			 and rl.order_id=#{orderId}
+			</if>
+			  
+		     <if test="campaignId !=null">
+			 and rl.campaign_id=#{campaignId}
+			</if>
+			
+			<if test="adGroupId !=null">
+			 and rl.adgroup_id=#{adGroupId}
+			</if>
+		 
+			<if test="startDate!=null and endDate!=null"> 
+	            and rl.date &gt;= #{startDate} and #{endDate} &gt;=rl.date
+			</if>
+		
+		</where>
+	</select>
+	
+<select id="findDeliverEffectAnalysis" parameterType="map" resultType="com.cloudcross.ssp.model.DeliverAnalysis">
+		select 
+		zone_id as zoneId,date as reportDate,sum(pv) as pv,sum(uv) as uv,sum(impression) as impression,sum(uimpression) as uImpression,
+		sum(uclick) as uClick,
+		100*sum(impression)/sum(pv) as fillRate,
+        sum(click) as click,100* sum(click)/sum(impression) as clickRate,sum(ecpm) as eCpm,sum(income) as income
+		from t_rpt_zone 
+		<where>
+		operator_id = #{operatorId} and date &gt;= #{startDate} and #{endDate} &gt;=date
+		<if test="zoneId!=null">
+		and zone_id=#{zoneId}
+		</if>
+		</where>
+		group by date
+		limit #{pager.offset}, #{pager.limit}
+	</select>
+	
+	<select id="findSum" parameterType="map" resultType="com.cloudcross.ssp.model.DeliverAnalysis">
+		select sum(pv) as pv, sum(uv) as uv, sum(impression) as impression, sum(click) as click, sum(income) as income
+		from t_rpt_zone 
+		<where>
+		operator_id = #{operatorId}
+		<if test="zoneId!=null">
+		and zone_id=#{zoneId}
+		</if>
+		
+		<if test="startDate!=null and endDate!=null"> 
+            and date &gt;= #{startDate} and #{endDate} &gt;=date
+		</if>
+		</where>
+	</select>
+	
+    <select id="findCountForOs" parameterType="map" resultType="int">
+		select count(1) 
+		from t_rpt_adv_os ros, t_advertiser, t_order, t_campaign, t_adgroup        
+        <where>	          
+           ros.advertiser_id = t_advertiser.id  and  ros.order_id =  t_order.id and ros.campaign_id = t_campaign.id  and ros.adgroup_id =  t_adgroup.id
+	 	   
+			<if test="advertiserId !=null">
+			 and ros.advertiser_id=#{advertiserId}
+			</if>
+			
+			<if test="orderId !=null">
+			 and ros.order_id=#{orderId}
+			</if>
+			  
+		     <if test="campaignId !=null">
+			 and ros.campaign_id=#{campaignId}
+			</if>
+			
+			<if test="adGroupId !=null">
+			 and ros.adgroup_id=#{adGroupId}
+			</if>
+		 
+			<if test="startDate!=null and endDate!=null"> 
+	            and ros.date &gt;= #{startDate} and #{endDate} &gt;=ros.date
+			</if>
+		
+		</where>
+	</select>
+	
+		<select id="findDeliverEffectAnalysis1" parameterType="map" resultType="com.cloudcross.ssp.model.DeliverAnalysis">
+		select 
+		zone_id as zoneId,date as reportDate,sum(pv) as pv,sum(uv) as uv,sum(impression) as impression,
+		sum(uimpression) as uImpression,
+		sum(uclick) as uClick,100*sum(impression)/sum(pv) as fillRate,
+        sum(click) as click,100* sum(click)/sum(impression) as clickRate,sum(ecpm) as eCpm,sum(income) as income
+		from t_rpt_zone 
+		<where>
+		operator_id = #{operatorId} and date &gt;= #{startDate} and #{endDate} &gt;=date
+		<if test="zoneId!=null">
+		and zone_id=#{zoneId}
+		</if>
+		</where>
+		group by date
+	</select>
+	
+    <select id="findCountForScene" parameterType="map" resultType="int">
+		select count(1) 
+		from t_rpt_adv_place rp, t_advertiser, t_order, t_campaign, t_adgroup , t_place      
+
+        <where>      
+            rp.place_id = t_place.id and  rp.advertiser_id = t_advertiser.id  
+            and  rp.order_id = t_order.id and rp.campaign_id = t_campaign.id  and rp.adgroup_id =  t_adgroup.id
+			<if test="advertiserId !=null">
+			 and rp.advertiser_id=#{advertiserId}
+			</if>
+			
+			<if test="orderId !=null">
+			 and rp.order_id=#{orderId}
+			</if>
+			  
+		     <if test="campaignId !=null">
+			 and rp.campaign_id=#{campaignId}
+			</if>
+			
+			<if test="adGroupId !=null">
+			 and rp.adgroup_id=#{adGroupId}
+			</if>
+		 
+			<if test="startDate!=null and endDate!=null"> 
+	         and rp.date &gt;= #{startDate} and rp.date &lt;= #{endDate}
+			</if>
+		
+		</where>
+	</select>
+	
+	<select id="countBySize" parameterType="map" resultType="int">
+		 select count(height) from ((select distinct width,height from t_rpt_zone_size where 
+		  date &gt;= #{startDate} and #{endDate} &gt;=date
+		    and operator_id=#{operatorId}
+		 ) as a )
+	</select>
+	
+	 <select id="findByTotalReportAdvertiser" parameterType="map" resultType="com.cloudcross.ssp.model.DeliverAnalysis">
+		select b.name advertiserName,c.name orderName,d.name campaignName,e.name adgroupName,g.name bannerName,a.date reportDate,sum(a.impression) as impression,sum(a.click) as click,100*sum(a.click)/sum(a.impression) as clickRate,sum(a.visit) as visit,100*sum(a.visit)/sum(a.click) as visitRate,sum(a.conversion) conversion,100*sum(a.conversion)/sum(a.visit) as conversionRate,sum(a.ecmp) ecmp,sum(a.consume) as consume 
+		from t_rpt_advertiser a,t_advertiser b,t_order c,t_campaign d,t_adgroup e,t_banner f,t_banner_template g
+		where a.advertiser_id=b.id and a.order_id=c.id and a.campaign_id=d.id and a.adgroup_id=e.id and a.banner_id=f.id and f.banner_template_id=g.id
+		<if test="advertiserId != null and advertiserId ">
+			and a.advertiser_id = #{advertiserId}
+		</if>
+		<if test="orderId != null and orderId != ''">
+			and a.order_id = #{orderId}
+		</if>
+		<if test="campaginId != null and campaginId != ''">
+			and a.campagin_id = #{campaginId}
+		</if>
+		<if test="adgroupId != null and adgroupId != ''">
+			and a.adgroup_id = #{adgroupId}
+		</if>
+		<if test="startDate != null and startDate != ''and endDate != nul and endDate != ''">
+			and a.date &gt;=#{startDate} and a.date &lt;=#{endDate}
+		</if>
+		<choose>
+			<when test="dimensionStr != null and dimensionStr != ''">
+				GROUP BY ${dimensionStr}
+			</when>
+			<otherwise>
+				group by reportDate
+			</otherwise>
+		</choose>		
+		limit #{pager.offset}, #{pager.limit}
+	</select>
+	
+<select id="findBySize" parameterType="map" resultType="com.cloudcross.ssp.model.DeliverAnalysis">
+		select 
+	    id,date as reportDate,width ,height,100*sum(pv)/(select sum(pv) from t_rpt_zone_size 
+	    where
+            date &gt;= #{startDate} and #{endDate} &gt;=date
+		    and operator_id=#{operatorId}
+		) as viewRate,sum(pv) as pv,sum(uv) as uv,sum(impression) as impression,
+		sum(uimpression) as uImpression, sum(uclick) as uClick,
+		100*impression/pv as fillRate,sum(click) as click,100*sum(click)/sum(impression) as clickRate,sum(ecpm) as eCpm,sum(income) as income
+		from t_rpt_zone_size 
+		where
+            date &gt;= #{startDate} and #{endDate} &gt;=date
+		    and operator_id=#{operatorId}
+		group by width,height
+		order by impression desc
+		limit #{pager.offset}, #{pager.limit}
+	</select>
+	
+	 <select id="findByTotalReportBack" parameterType="map" resultType="com.cloudcross.ssp.model.DeliverAnalysis">
+		select 
+		t_advertiser.name as advertiserName,  t_order.name as orderName, t_campaign.name as campaignName, t_adgroup.name  as adGroupName, t_banner_template.name as bannerName, 
+        
+         ad.date as reportDate,     
+        (select sum(t_rpt_advertiser.impression) from  t_rpt_advertiser ,t_advertiser,t_order, t_campaign, t_banner, t_adgroup, t_banner_template where  t_rpt_advertiser.advertiser_id=t_advertiser.id  and  t_rpt_advertiser.order_id = t_order.id  and t_rpt_advertiser.campaign_id= t_campaign.id   
+	 	    and  t_rpt_advertiser.adgroup_id=t_adgroup.id
+            and  t_rpt_advertiser.banner_id=t_banner.id 
+            and  t_banner.banner_template_id = t_banner_template.id 
+
+			<if test="advertiserId !=null">
+			 and t_rpt_advertiser.advertiser_id=#{advertiserId}
+			</if>
+			<if test="orderId !=null">
+			 and t_rpt_advertiser.order_id=#{orderId}
+			</if>
+			  
+		     <if test="campaignId !=null">
+			 and t_rpt_advertiser.campaign_id=#{campaignId}
+			</if>
+			
+			<if test="adGroupId !=null">
+			 and t_rpt_advertiser.adgroup_id=#{adGroupId}
+			</if>
+		 
+	    <if test="startDate!=null and endDate!=null"> 
+            and date &gt;= #{startDate} and #{endDate} &gt;=date
+	    </if>) as impressionSum,ad.impression,ad.click,visit,ad.conversion, 
+        100*ad.click/ad.impression as clickRate ,100*visit/ad.click as visitRate ,100*ad.conversion/visit as conversionRate ,ecmp as eCmp,ad.consume,
+		(select sum(t_rpt_advertiser.click) from t_rpt_advertiser ,t_advertiser,t_order, t_campaign, t_banner, t_adgroup, t_banner_template where  t_rpt_advertiser.advertiser_id=t_advertiser.id  and  t_rpt_advertiser.order_id = t_order.id  and t_rpt_advertiser.campaign_id= t_campaign.id   
+	 	    and  t_rpt_advertiser.adgroup_id=t_adgroup.id
+            and  t_rpt_advertiser.banner_id=t_banner.id 
+            and  t_banner.banner_template_id = t_banner_template.id 
+
+			<if test="advertiserId !=null">
+			 and t_rpt_advertiser.advertiser_id=#{advertiserId}
+			</if>
+			<if test="orderId !=null">
+			 and t_rpt_advertiser.order_id=#{orderId}
+			</if>
+			  
+		     <if test="campaignId !=null">
+			 and t_rpt_advertiser.campaign_id=#{campaignId}
+			</if>
+			
+			<if test="adGroupId !=null">
+			 and t_rpt_advertiser.adgroup_id=#{adGroupId}
+			</if>
+		 
+	    <if test="startDate!=null and endDate!=null"> 
+            and date &gt;= #{startDate} and #{endDate} &gt;=date
+	    </if>) as clickSum, (select sum(t_rpt_advertiser.visit) from t_rpt_advertiser ,t_advertiser,t_order, t_campaign, t_banner, t_adgroup, t_banner_template where  t_rpt_advertiser.advertiser_id=t_advertiser.id  and  t_rpt_advertiser.order_id = t_order.id  and t_rpt_advertiser.campaign_id= t_campaign.id   
+	 	    and  t_rpt_advertiser.adgroup_id=t_adgroup.id
+            and  t_rpt_advertiser.banner_id=t_banner.id 
+            and  t_banner.banner_template_id = t_banner_template.id 
+
+			<if test="advertiserId !=null">
+			 and t_rpt_advertiser.advertiser_id=#{advertiserId}
+			</if>
+			<if test="orderId !=null">
+			 and t_rpt_advertiser.order_id=#{orderId}
+			</if>
+			  
+		     <if test="campaignId !=null">
+			 and t_rpt_advertiser.campaign_id=#{campaignId}
+			</if>
+			
+			<if test="adGroupId !=null">
+			 and t_rpt_advertiser.adgroup_id=#{adGroupId}
+			</if>
+		 
+	    <if test="startDate!=null and endDate!=null"> 
+            and date &gt;= #{startDate} and #{endDate} &gt;=date
+	    </if>) as visitSum,
+        (select sum(t_rpt_advertiser.conversion) from t_rpt_advertiser ,t_advertiser,t_order, t_campaign, t_banner, t_adgroup, t_banner_template where  t_rpt_advertiser.advertiser_id=t_advertiser.id  and  t_rpt_advertiser.order_id = t_order.id  and t_rpt_advertiser.campaign_id= t_campaign.id   
+	 	    and  t_rpt_advertiser.adgroup_id=t_adgroup.id
+            and  t_rpt_advertiser.banner_id=t_banner.id 
+            and  t_banner.banner_template_id = t_banner_template.id 
+
+			<if test="advertiserId !=null">
+			 and t_rpt_advertiser.advertiser_id=#{advertiserId}
+			</if>
+			<if test="orderId !=null">
+			 and t_rpt_advertiser.order_id=#{orderId}
+			</if>
+			  
+		     <if test="campaignId !=null">
+			 and t_rpt_advertiser.campaign_id=#{campaignId}
+			</if>
+			
+			<if test="adGroupId !=null">
+			 and t_rpt_advertiser.adgroup_id=#{adGroupId}
+			</if>
+		 
+	    <if test="startDate!=null and endDate!=null"> 
+            and date &gt;= #{startDate} and #{endDate} &gt;=date
+	    </if>) as conversionSum, 
+		(select sum(t_rpt_advertiser.ecmp) from t_rpt_advertiser ,t_advertiser,t_order, t_campaign, t_banner, t_adgroup, t_banner_template where  t_rpt_advertiser.advertiser_id=t_advertiser.id  and  t_rpt_advertiser.order_id = t_order.id  and t_rpt_advertiser.campaign_id= t_campaign.id   
+	 	    and  t_rpt_advertiser.adgroup_id=t_adgroup.id
+            and  t_rpt_advertiser.banner_id=t_banner.id 
+            and  t_banner.banner_template_id = t_banner_template.id 
+
+			<if test="advertiserId !=null">
+			 and t_rpt_advertiser.advertiser_id=#{advertiserId}
+			</if>
+			<if test="orderId !=null">
+			 and t_rpt_advertiser.order_id=#{orderId}
+			</if>
+			  
+		     <if test="campaignId !=null">
+			 and t_rpt_advertiser.campaign_id=#{campaignId}
+			</if>
+			
+			<if test="adGroupId !=null">
+			 and t_rpt_advertiser.adgroup_id=#{adGroupId}
+			</if>
+		 
+	    <if test="startDate!=null and endDate!=null"> 
+            and date &gt;= #{startDate} and #{endDate} &gt;=date
+	    </if>) as eCmpSum, (select sum(t_rpt_advertiser.consume) from t_rpt_advertiser ,t_advertiser,t_order, t_campaign, t_banner, t_adgroup, t_banner_template where  t_rpt_advertiser.advertiser_id=t_advertiser.id  and  t_rpt_advertiser.order_id = t_order.id  and t_rpt_advertiser.campaign_id= t_campaign.id   
+	 	    and  t_rpt_advertiser.adgroup_id=t_adgroup.id
+            and  t_rpt_advertiser.banner_id=t_banner.id 
+            and  t_banner.banner_template_id = t_banner_template.id 
+
+			<if test="advertiserId !=null">
+			 and t_rpt_advertiser.advertiser_id=#{advertiserId}
+			</if>
+			<if test="orderId !=null">
+			 and t_rpt_advertiser.order_id=#{orderId}
+			</if>
+			  
+		     <if test="campaignId !=null">
+			 and t_rpt_advertiser.campaign_id=#{campaignId}
+			</if>
+			
+			<if test="adGroupId !=null">
+			 and t_rpt_advertiser.adgroup_id=#{adGroupId}
+			</if>
+		 
+	    <if test="startDate!=null and endDate!=null"> 
+            and date &gt;= #{startDate} and #{endDate} &gt;=date
+	    </if>) as consumeSum, 
+        100*(select sum(t_rpt_advertiser.click) from t_rpt_advertiser ,t_advertiser,t_order, t_campaign, t_banner, t_adgroup, t_banner_template where  t_rpt_advertiser.advertiser_id=t_advertiser.id  and  t_rpt_advertiser.order_id = t_order.id  and t_rpt_advertiser.campaign_id= t_campaign.id   
+	 	    and  t_rpt_advertiser.adgroup_id=t_adgroup.id
+            and  t_rpt_advertiser.banner_id=t_banner.id 
+            and  t_banner.banner_template_id = t_banner_template.id 
+
+			<if test="advertiserId !=null">
+			 and t_rpt_advertiser.advertiser_id=#{advertiserId}
+			</if>
+			<if test="orderId !=null">
+			 and t_rpt_advertiser.order_id=#{orderId}
+			</if>
+			  
+		     <if test="campaignId !=null">
+			 and t_rpt_advertiser.campaign_id=#{campaignId}
+			</if>
+			
+			<if test="adGroupId !=null">
+			 and t_rpt_advertiser.adgroup_id=#{adGroupId}
+			</if>
+		 
+	    <if test="startDate!=null and endDate!=null"> 
+            and date &gt;= #{startDate} and #{endDate} &gt;=date
+	    </if>)/(select sum(t_rpt_advertiser.impression) from t_rpt_advertiser ,t_advertiser,t_order, t_campaign, t_banner, t_adgroup, t_banner_template where  t_rpt_advertiser.advertiser_id=t_advertiser.id  and  t_rpt_advertiser.order_id = t_order.id  and t_rpt_advertiser.campaign_id= t_campaign.id   
+	 	    and  t_rpt_advertiser.adgroup_id=t_adgroup.id
+            and  t_rpt_advertiser.banner_id=t_banner.id 
+            and  t_banner.banner_template_id = t_banner_template.id 
+
+			<if test="advertiserId !=null">
+			 and t_rpt_advertiser.advertiser_id=#{advertiserId}
+			</if>
+			<if test="orderId !=null">
+			 and t_rpt_advertiser.order_id=#{orderId}
+			</if>
+			  
+		     <if test="campaignId !=null">
+			 and t_rpt_advertiser.campaign_id=#{campaignId}
+			</if>
+			
+			<if test="adGroupId !=null">
+			 and t_rpt_advertiser.adgroup_id=#{adGroupId}
+			</if>
+		 
+	    <if test="startDate!=null and endDate!=null"> 
+            and date &gt;= #{startDate} and #{endDate} &gt;=date
+	    </if>) as clickRatesum, 
+		100*(select sum(t_rpt_advertiser.visit) from t_rpt_advertiser ,t_advertiser,t_order, t_campaign, t_banner, t_adgroup, t_banner_template where  t_rpt_advertiser.advertiser_id=t_advertiser.id  and  t_rpt_advertiser.order_id = t_order.id  and t_rpt_advertiser.campaign_id= t_campaign.id   
+	 	    and  t_rpt_advertiser.adgroup_id=t_adgroup.id
+            and  t_rpt_advertiser.banner_id=t_banner.id 
+            and  t_banner.banner_template_id = t_banner_template.id 
+
+			<if test="advertiserId !=null">
+			 and t_rpt_advertiser.advertiser_id=#{advertiserId}
+			</if>
+			<if test="orderId !=null">
+			 and t_rpt_advertiser.order_id=#{orderId}
+			</if>
+			  
+		     <if test="campaignId !=null">
+			 and t_rpt_advertiser.campaign_id=#{campaignId}
+			</if>
+			
+			<if test="adGroupId !=null">
+			 and t_rpt_advertiser.adgroup_id=#{adGroupId}
+			</if>
+		 
+	    <if test="startDate!=null and endDate!=null"> 
+            and date &gt;= #{startDate} and #{endDate} &gt;=date
+	    </if>)/(select sum(t_rpt_advertiser.click) from t_rpt_advertiser ,t_advertiser,t_order, t_campaign, t_banner, t_adgroup, t_banner_template where  t_rpt_advertiser.advertiser_id=t_advertiser.id  and  t_rpt_advertiser.order_id = t_order.id  and t_rpt_advertiser.campaign_id= t_campaign.id   
+	 	    and  t_rpt_advertiser.adgroup_id=t_adgroup.id
+            and  t_rpt_advertiser.banner_id=t_banner.id 
+            and  t_banner.banner_template_id = t_banner_template.id 
+
+			<if test="advertiserId !=null">
+			 and t_rpt_advertiser.advertiser_id=#{advertiserId}
+			</if>
+			<if test="orderId !=null">
+			 and t_rpt_advertiser.order_id=#{orderId}
+			</if>
+			  
+		     <if test="campaignId !=null">
+			 and t_rpt_advertiser.campaign_id=#{campaignId}
+			</if>
+			
+			<if test="adGroupId !=null">
+			 and t_rpt_advertiser.adgroup_id=#{adGroupId}
+			</if>
+		 
+	    <if test="startDate!=null and endDate!=null"> 
+            and date &gt;= #{startDate} and #{endDate} &gt;=date
+	    </if>) as visitRatesum,
+		100*(select sum(t_rpt_advertiser.conversion) from t_rpt_advertiser ,t_advertiser,t_order, t_campaign, t_banner, t_adgroup, t_banner_template where  t_rpt_advertiser.advertiser_id=t_advertiser.id  and  t_rpt_advertiser.order_id = t_order.id  and t_rpt_advertiser.campaign_id= t_campaign.id   
+	 	    and  t_rpt_advertiser.adgroup_id=t_adgroup.id
+            and  t_rpt_advertiser.banner_id=t_banner.id 
+            and  t_banner.banner_template_id = t_banner_template.id 
+
+			<if test="advertiserId !=null">
+			 and t_rpt_advertiser.advertiser_id=#{advertiserId}
+			</if>
+			<if test="orderId !=null">
+			 and t_rpt_advertiser.order_id=#{orderId}
+			</if>
+			  
+		     <if test="campaignId !=null">
+			 and t_rpt_advertiser.campaign_id=#{campaignId}
+			</if>
+			
+			<if test="adGroupId !=null">
+			 and t_rpt_advertiser.adgroup_id=#{adGroupId}
+			</if>
+		 
+	    <if test="startDate!=null and endDate!=null"> 
+            and date &gt;= #{startDate} and #{endDate} &gt;=date
+	    </if>)/(select sum(t_rpt_advertiser.visit) from t_rpt_advertiser ,t_advertiser,t_order, t_campaign, t_banner, t_adgroup, t_banner_template where  t_rpt_advertiser.advertiser_id=t_advertiser.id  and  t_rpt_advertiser.order_id = t_order.id  and t_rpt_advertiser.campaign_id= t_campaign.id   
+	 	    and  t_rpt_advertiser.adgroup_id=t_adgroup.id
+            and  t_rpt_advertiser.banner_id=t_banner.id 
+            and  t_banner.banner_template_id = t_banner_template.id 
+
+			<if test="advertiserId !=null">
+			 and t_rpt_advertiser.advertiser_id=#{advertiserId}
+			</if>
+			<if test="orderId !=null">
+			 and t_rpt_advertiser.order_id=#{orderId}
+			</if>
+			  
+		     <if test="campaignId !=null">
+			 and t_rpt_advertiser.campaign_id=#{campaignId}
+			</if>
+			
+			<if test="adGroupId !=null">
+			 and t_rpt_advertiser.adgroup_id=#{adGroupId}
+			</if>
+		 
+	    <if test="startDate!=null and endDate!=null"> 
+            and date &gt;= #{startDate} and #{endDate} &gt;=date
+	    </if>) as conversionRatesum
+		
+		from t_rpt_advertiser ad,t_advertiser,t_order, t_campaign, t_banner, t_adgroup, t_banner_template
+           
+           
+           <where>
+	 	    ad.advertiser_id=t_advertiser.id  and  ad.order_id = t_order.id  and ad.campaign_id= t_campaign.id   
+	 	    and  ad.adgroup_id=t_adgroup.id
+            and  ad.banner_id=t_banner.id 
+            and  t_banner.banner_template_id = t_banner_template.id
+
+			<if test="advertiserId !=null">
+			 and ad.advertiser_id=#{advertiserId}
+			</if>
+			
+			<if test="orderId !=null">
+			 and ad.order_id=#{orderId}
+			</if>
+			  
+		     <if test="campaignId !=null">
+			 and ad.campaign_id=#{campaignId}
+			</if>
+			
+			<if test="adGroupId !=null">
+			 and ad.adgroup_id=#{adGroupId}
+			</if>
+		 
+	
+	    <if test="startDate!=null and endDate!=null"> 
+            and date &gt;= #{startDate} and #{endDate} &gt;=date
+	    </if>
+	  
+		  </where> 
+		
+		  limit #{pager.offset}, #{pager.limit}
+	</select>
+	
+	<!-- 系统报表 -->
+	<select id="countBySystem" parameterType="map" resultType="int">
+         select count(os) from ((select distinct os from t_rpt_zone_os where 
+		  date &gt;= #{startDate} and #{endDate} &gt;=date
+		    and operator_id=#{operatorId}
+		  ) as a)
+	</select>
+	
+		<select id="findByPosition" parameterType="map" resultType="com.cloudcross.ssp.model.DeliverAnalysis">
+		select 
+	    id,date as reportDate,position,100*sum(pv)/(select sum(pv) from t_rpt_zone_position where 
+		 date &gt;= #{startDate} and #{endDate} &gt;=date
+		    and operator_id=#{operatorId}
+		 ) as viewRate,sum(pv) as pv,sum(uv) as uv,sum(impression) as impression ,
+		 sum(uimpression) as uImpression, sum(uclick) as uClick,
+		 100*sum(impression)/sum(pv) as fillRate,sum(click) as click ,100*sum(click)/sum(impression) as clickRate,sum(eCpm) as eCpm,sum(income) as income 
+		from t_rpt_zone_position
+		where 
+		 date &gt;= #{startDate} and #{endDate} &gt;=date
+		    and operator_id=#{operatorId}
+		group by position 
+		order by impression desc 
+	</select>
+	
+	<select id="findBySize1" parameterType="map" resultType="com.cloudcross.ssp.model.DeliverAnalysis">
+		select 
+	    id,date as reportDate,width ,height,100*sum(pv)/(select sum(pv) from t_rpt_zone_size 
+	    where
+            date &gt;= #{startDate} and #{endDate} &gt;=date
+		    and operator_id=#{operatorId}
+		) as viewRate,sum(pv) as pv,sum(uv) as uv,sum(impression) as impression,
+		sum(uimpression) as uImpression, sum(uclick) as uClick,
+		100*impression/pv as fillRate,sum(click) as click,100*sum(click)/sum(impression) as clickRate,sum(ecpm) as eCpm,sum(income) as income
+		from t_rpt_zone_size 
+		where
+            date &gt;= #{startDate} and #{endDate} &gt;=date
+		    and operator_id=#{operatorId}
+		group by width,height
+		order by impression desc
+	</select>
+	
+	<select id="findByTotalReport2" parameterType="map" resultType="com.cloudcross.ssp.model.DeliverAnalysis">
+		select 
+		t_advertiser.name as advertiserName,  t_order.name as orderName, t_campaign.name as campaignName, t_adgroup.name  as adGroupName, t_banner_template.name as bannerName, 
+        
+         ad.date as reportDate,   ad.hour as hour,  
+        (select sum(impression) from t_rpt_advertiser_hour) as impressionSum,ad.impression,ad.click,visit,ad.conversion, 
+        100*ad.click/ad.impression as clickRate ,100*visit/ad.click as visitRate ,100*ad.conversion/visit as conversionRate ,ecmp as eCmp,ad.consume,
+		(select sum(click) from t_rpt_advertiser_hour) as clickSum, (select sum(visit) from t_rpt_advertiser_hour) as visitSum,
+        (select sum(conversion) from t_rpt_advertiser_hour) as conversionSum, 
+		(select sum(ecmp) from t_rpt_advertiser_hour) as eCmpSum, (select sum(consume) from t_rpt_advertiser_hour) as consumeSum, 
+        100*(select sum(click) from t_rpt_advertiser_hour)/(select sum(impression) from t_rpt_advertiser_hour) as clickRatesum, 
+		100*(select sum(visit) from t_rpt_advertiser_hour)/(select sum(click) from t_rpt_advertiser_hour) as visitRatesum,
+		100*(select sum(conversion) from t_rpt_advertiser_hour)/(select sum(visit) from t_rpt_advertiser_hour) as conversionRatesum
+		
+		from t_rpt_advertiser_hour ad,t_advertiser,t_order, t_campaign, t_banner, t_adgroup, t_banner_template
+           
+           
+           <where>
+	 	    ad.advertiser_id=t_advertiser.id  and  ad.order_id = t_order.id  and ad.campaign_id= t_campaign.id   
+	 	    and  ad.adgroup_id=t_adgroup.id
+            and  ad.banner_id=t_banner.id 
+            and  t_banner.banner_template_id = t_banner_template.id
+
+			<if test="advertiserId !=null">
+			 and ad.advertiser_id=#{advertiserId}
+			</if>
+			
+			<if test="orderId !=null">
+			 and ad.order_id=#{orderId}
+			</if>
+			  
+		     <if test="campaignId !=null">
+			 and ad.campaign_id=#{campaignId}
+			</if>
+			
+			<if test="adGroupId !=null">
+			 and ad.adgroup_id=#{adGroupId}
+			</if>
+		 
+		 <if test="startDate!=null and endDate!=null"> 
+            and date &gt;= #{startDate} and #{endDate} &gt;=date
+		</if>
+		 
+		  </where> 
+		
+		  limit #{pager.offset}, #{pager.limit}
+	</select>
+	
+		<select id="findBySystem" parameterType="map" resultType="com.cloudcross.ssp.model.DeliverAnalysis">
+	   select 
+	    os as system,100*(sum(pv)/(select sum(pv) from t_rpt_zone_os
+		where date &gt;= #{startDate} and #{endDate} &gt;=date
+		    and operator_id=#{operatorId}
+		   )) as viewRate,
+		sum(pv) as pv,sum(uv) as uv,sum(impression) as impression,
+		sum(uimpression) as uImpression, sum(uclick) as uClick,
+		100*(sum(impression)/sum(pv)) as fillRate,
+        sum(click) as click,100*(sum(click)/sum(impression)) as clickRate,sum(ecpm) as eCpm,sum(income) as income
+		from t_rpt_zone_os 
+		where date &gt;= #{startDate} and #{endDate} &gt;=date
+		    and operator_id=#{operatorId}
+		group by os
+		order by impression desc
+	</select>
+	
+	<select id="findByLocationAdvertiser" parameterType="map" resultType="com.cloudcross.ssp.model.DeliverAnalysis">
+		select t_location.cn_city as location, 100 * sum(impression) /(select sum(impression) from t_rpt_adv_location a1,t_advertiser b1	
+		<where>	
+       	a1.advertiser_id = b1.id and a1.date &gt;= #{startDate} and #{endDate} &gt;=a1.date
+			<if test="advertiserId ==null">
+			 and b1.agent_id=#{agentId}
+			</if>
+			<if test="advertiserId != null">
+			and a1.advertiser_id = #{advertiserId}	
+			</if>
+			<if test="orderId !=null">
+			 and a1.order_id=#{orderId}
+			</if>
+		     <if test="campaignId !=null">
+			 and a1.campaign_id=#{campaignId}
+			</if>
+			<if test="adGroupId !=null">
+			 and a1.adgroup_id=#{adGroupId}
+			</if>
+		</where>
+		) as impressionRate, sum(impression) as impression, sum(click) as click, 100 * sum(click) / sum(impression) as clickRate,
+		sum(visit) as visit, 100 * sum(visit) / sum(click) as visitRate, 100 * sum(conversion) / sum(visit) as conversionRate,
+		sum(conversion) as conversion, sum(ecmp) as eCmp, sum(consume) as consume from t_rpt_adv_location a, t_advertiser b,t_location
+		 	<where>	
+       	a.advertiser_id = b.id and a.location = t_location.location and a.date &gt;= #{startDate} and #{endDate} &gt;=a.date
+			<if test="advertiserId ==null">
+			 and b.agent_id=#{agentId}
+			</if>
+			<if test="advertiserId != null">
+			and a.advertiser_id = #{advertiserId}	
+			</if>
+			<if test="orderId !=null">
+			 and a.order_id=#{orderId}
+			</if>
+		     <if test="campaignId !=null">
+			 and a.campaign_id=#{campaignId}
+			</if>
+			<if test="adGroupId !=null">
+			 and a.adgroup_id=#{adGroupId}
+			</if>
+		</where>
+		group by a.location
+		limit #{pager.offset}, #{pager.limit}
+	   </select>
+	   
+		<select id="findBySystem1" parameterType="map" resultType="com.cloudcross.ssp.model.DeliverAnalysis">
+	    select 
+	    os as system,100*(sum(pv)/(select sum(pv) from t_rpt_zone_os
+		where date &gt;= #{startDate} and #{endDate} &gt;=date
+		    and operator_id=#{operatorId}
+		   )) as viewRate,
+		sum(pv) as pv,sum(uv) as uv,sum(impression) as impression,
+		sum(uimpression) as uImpression, sum(uclick) as uClick,
+		100*(sum(impression)/sum(pv)) as fillRate,
+        sum(click) as click,100*(sum(click)/sum(impression)) as clickRate,sum(ecpm) as eCpm,sum(income) as income
+		from t_rpt_zone_os 
+		where date &gt;= #{startDate} and #{endDate} &gt;=date
+		    and operator_id=#{operatorId}
+		group by os
+		order by impression desc
+	</select>
+	
+	<select id="findByLocationBack" parameterType="map" resultType="com.cloudcross.ssp.model.DeliverAnalysis">
+		select 
+		t_advertiser.name as advertiserName,  t_order.name as orderName, t_campaign.name as campaignName, t_adgroup.name  as adGroupName,
+
+               rl.date as reportDate,
+        rl.impression,rl.click,visit,rl.conversion,location,
+        100*rl.impression/(select sum(t_rpt_adv_location.impression) from t_rpt_adv_location , t_advertiser, t_order, t_campaign, t_adgroup
+        
+           where	
+            t_rpt_adv_location.advertiser_id = t_advertiser.id  and  t_rpt_adv_location.order_id =  t_order.id and t_rpt_adv_location.campaign_id = t_campaign.id  and t_rpt_adv_location.adgroup_id =  t_adgroup.id
+         	   
+			<if test="advertiserId !=null">
+			 and t_rpt_adv_location.advertiser_id=#{advertiserId}
+			</if> 
+			
+			<if test="orderId !=null">
+			 and t_rpt_adv_location.order_id=#{orderId}
+			</if>
+		     
+		     <if test="campaignId !=null">
+			 and t_rpt_adv_location.campaign_id=#{campaignId}
+			</if>
+			
+			<if test="adGroupId !=null">
+			 and t_rpt_adv_location.adgroup_id=#{adGroupId}
+			</if>
+		
+	  	 <if test="startDate!=null and endDate!=null"> 
+            and t_rpt_adv_location.date &gt;= #{startDate} and #{endDate} &gt;=t_rpt_adv_location.date
+		 </if>) as impressionRate,100*rl.click/rl.impression as clickRate ,
+        100*visit/rl.click as visitRate ,100*rl.conversion/visit as conversionRate,ecmp as eCmp,consume   
+        from t_rpt_adv_location rl, t_advertiser, t_order, t_campaign, t_adgroup
+        
+           <where>	
+            rl.advertiser_id = t_advertiser.id  and  rl.order_id =  t_order.id and rl.campaign_id = t_campaign.id  and rl.adgroup_id =  t_adgroup.id
+         	   
+			<if test="advertiserId !=null">
+			 and rl.advertiser_id=#{advertiserId}
+			</if> 
+			
+			<if test="orderId !=null">
+			 and rl.order_id=#{orderId}
+			</if>
+		     
+		     <if test="campaignId !=null">
+			 and rl.campaign_id=#{campaignId}
+			</if>
+			
+			<if test="adGroupId !=null">
+			 and rl.adgroup_id=#{adGroupId}
+			</if>
+		
+	  	 <if test="startDate!=null and endDate!=null"> 
+            and rl.date &gt;= #{startDate} and #{endDate} &gt;=rl.date
+		      </if>
+	    
+		    </where> 
+		    
+		limit #{pager.offset}, #{pager.limit}
+	   </select>
+	
+	<select id="findByOs" parameterType="map" resultType="com.cloudcross.ssp.model.DeliverAnalysis">
+		select 
+		t_advertiser.name as advertiserName,  t_order.name as orderName, t_campaign.name as campaignName, t_adgroup.name  as adGroupName,
+
+              ros.date as reportDate,
+        ros.impression,ros.click,visit,ros.conversion,os,
+        100*ros.impression/(select sum(t_rpt_adv_os.impression) from t_rpt_adv_os, t_advertiser, t_order, t_campaign, t_adgroup        
+
+
+            where	          
+         
+           t_rpt_adv_os.advertiser_id = t_advertiser.id  and  t_rpt_adv_os.order_id =  t_order.id and t_rpt_adv_os.campaign_id = t_campaign.id  and t_rpt_adv_os.adgroup_id =  t_adgroup.id
+		     	   
+			<if test="advertiserId !=null">
+			 and t_rpt_adv_os.advertiser_id=#{advertiserId}
+			</if> 
+			
+			<if test="orderId !=null">
+			 and t_rpt_adv_os.order_id=#{orderId}
+			</if>
+		     
+		     <if test="campaignId !=null">
+			 and t_rpt_adv_os.campaign_id=#{campaignId}
+			</if>
+			
+			<if test="adGroupId !=null">
+			 and t_rpt_adv_os.adgroup_id=#{adGroupId}
+			</if>
+			
+	 		<if test="startDate!=null and endDate!=null"> 
+            and t_rpt_adv_os.date &gt;= #{startDate} and #{endDate} &gt;=t_rpt_adv_os.date
+		     </if>
+	) as impressionRate,100*ros.click/ros.impression as clickRate ,
+        100*visit/ros.click as visitRate ,100*ros.conversion/visit as conversionRate,ecmp as eCmp,consume   
+        from t_rpt_adv_os ros, t_advertiser, t_order, t_campaign, t_adgroup        
+
+
+            <where>	          
+         
+           ros.advertiser_id = t_advertiser.id  and  ros.order_id =  t_order.id and ros.campaign_id = t_campaign.id  and ros.adgroup_id =  t_adgroup.id
+		     	   
+			<if test="advertiserId !=null">
+			 and ros.advertiser_id=#{advertiserId}
+			</if> 
+			
+			<if test="orderId !=null">
+			 and ros.order_id=#{orderId}
+			</if>
+		     
+		     <if test="campaignId !=null">
+			 and ros.campaign_id=#{campaignId}
+			</if>
+			
+			<if test="adGroupId !=null">
+			 and ros.adgroup_id=#{adGroupId}
+			</if>
+			
+	 		<if test="startDate!=null and endDate!=null"> 
+            and ros.date &gt;= #{startDate} and #{endDate} &gt;=ros.date
+		     </if>
+	
+		   </where> 
+
+		limit #{pager.offset}, #{pager.limit}
+	</select>
+	
+		<select id="countByAllAreal" parameterType="map" resultType="int">
+		select count(cn) from ((select distinct cn from t_rpt_zone_location a,t_location b 
+  		where
+		a.location = b.location and date &gt;= #{startDate} and #{endDate} &gt;=date
+		    and operator_id=#{operatorId}
+		) as t)
+		
+	</select>
+	
+		<select id="findByAllAreal" parameterType="map" resultType="com.cloudcross.ssp.model.DeliverAnalysis">
+		 select 
+	    a.id,a.date as reportDate,b.cn,b.cn_city,100*sum(a.pv)/(select sum(pv) from t_rpt_zone_location where date &gt;= #{startDate} and #{endDate} &gt;=date
+		    and operator_id=#{operatorId}
+		) as viewRate,
+	    sum(a.pv) as pv,sum(a.uv) as uv,sum(a.impression) as impression,
+	    sum(uimpression) as uImpression, sum(uclick) as uClick,100*sum(a.impression)/sum(a.pv) as fillRate,sum(a.click) as click,100*sum(a.click)/sum(a.impression) as clickRate,sum(a.eCpm) as eCpm,sum(a.income) as income
+		from t_rpt_zone_location a,t_location b
+	 	where
+		a.location = b.location  and a.date &gt;= #{startDate} and #{endDate} &gt;=a.date
+		    and operator_id=#{operatorId}
+		group by b.cn 
+		order by b.cn 
+		limit #{pager.offset}, #{pager.limit}
+	</select>
+	
+<select id="findByDevice" parameterType="map" resultType="com.cloudcross.ssp.model.DeliverAnalysis">
+		
+		select 
+	    id,date as reportDate,device,100*sum(pv)/
+	    (select sum(pv) from t_rpt_zone_device where operator_id = #{operatorId} and date &gt;= #{startDate} and #{endDate} &gt;=date) as viewRate,
+	    sum(pv) as pv,sum(uv) as uv,sum(impression) as impression ,
+	    sum(uimpression) as uImpression,
+		sum(uclick) as uClick,100*sum(impression)/sum(pv) as fillRate,sum(click) as click ,100*sum(click)/sum(impression) as clickRate,sum(eCpm) as eCpm,sum(income) as income
+        from t_rpt_zone_device
+		where operator_id = #{operatorId} and date &gt;= #{startDate} and #{endDate} &gt;=date
+		group by device 
+		order by impression desc
+	</select>
+	
+	
+	 <select id="findByPlaceName" parameterType="map" resultType="com.cloudcross.ssp.model.DeliverAnalysis">
+		select 
+	             t_place.name as placeName,	t_advertiser.name as advertiserName,  t_order.name as orderName, 
+	             t_campaign.name as campaignName, t_adgroup.name as adGroupName,
+	             
+	              rp.date as reportDate,
+                  rp.impression,rp.click,visit,rp.conversion,
+              100*rp.impression/(select sum(t_rpt_adv_place.impression) from t_rpt_adv_place , t_advertiser, t_order, t_campaign, t_adgroup , t_place      
+
+
+             where      
+            t_rpt_adv_place.place_id = t_place.id and  t_rpt_adv_place.advertiser_id = t_advertiser.id  
+            and  t_rpt_adv_place.order_id = t_order.id and t_rpt_adv_place.campaign_id = t_campaign.id  and t_rpt_adv_place.adgroup_id =  t_adgroup.id
+	   
+			<if test="advertiserId !=null">
+			 and t_rpt_adv_place.advertiser_id=#{advertiserId}
+			</if> 
+			
+			<if test="orderId !=null">
+			 and t_rpt_adv_place.order_id=#{orderId}
+			</if>
+		     
+		     <if test="campaignId !=null">
+			 and t_rpt_adv_place.campaign_id=#{campaignId}
+			</if>
+			
+			<if test="adGroupId !=null">
+			 and t_rpt_adv_place.adgroup_id=#{adGroupId}
+			</if>
+		 
+	  		 <if test="startDate!=null and endDate!=null"> 
+            and t_rpt_adv_place.date &gt;= #{startDate} and #{endDate} &gt;=t_rpt_adv_place.date
+		        </if>) as impressionRate,100*rp.click/rp.impression as clickRate ,
+              100*visit/rp.click as visitRate ,100*rp.conversion/visit as conversionRate,ecmp as eCmp,consume   
+            from t_rpt_adv_place rp, t_advertiser, t_order, t_campaign, t_adgroup , t_place      
+
+
+              <where>      
+            rp.place_id = t_place.id and  rp.advertiser_id = t_advertiser.id  
+            and  rp.order_id = t_order.id and rp.campaign_id = t_campaign.id  and rp.adgroup_id =  t_adgroup.id
+	   
+			<if test="advertiserId !=null">
+			 and rp.advertiser_id=#{advertiserId}
+			</if> 
+			
+			<if test="orderId !=null">
+			 and rp.order_id=#{orderId}
+			</if>
+		     
+		     <if test="campaignId !=null">
+			 and rp.campaign_id=#{campaignId}
+			</if>
+			
+			<if test="adGroupId !=null">
+			 and rp.adgroup_id=#{adGroupId}
+			</if>
+		 
+	  		 <if test="startDate!=null and endDate!=null"> 
+            and rp.date &gt;= #{startDate} and #{endDate} &gt;=rp.date
+		        </if>
+		     
+		  </where> 
+		limit #{pager.offset}, #{pager.limit}
+	</select>
+	
+
+		<select id="findByArealCity" parameterType="map" resultType="com.cloudcross.ssp.model.DeliverAnalysis">
+		 select 
+	    b.cn,b.cn_city,100*sum(a.pv)/(select sum(pv) from t_rpt_zone_location where date &gt;= #{startDate} and #{endDate} &gt;=date
+		    and operator_id=#{operatorId}
+		) as viewRate,
+	    sum(a.pv) as pv,sum(a.uv) as uv,sum(a.impression),
+	    sum(uimpression) as uImpression, sum(uclick) as uClick,
+	    100*sum(a.impression)/sum(a.pv) as fillRate,sum(a.click),100*sum(a.click)/sum(a.impression) as clickRate,sum(a.eCpm) as eCpm,sum(a.income) as income
+		from t_rpt_zone_location a,t_location b
+		where
+		a.location=b.location and b.cn=#{cn} and date &gt;= #{startDate} and #{endDate} &gt;=date
+		    and operator_id=#{operatorId}
+       group by b.cn_city
+	</select>
+	
+	<!--<select id="findByOrderName" parameterType="map" resultType="DeliverAnalysis">
+		select 
+		t_order.name as orderName,impression,click,visit,conversion,click/impression as clickRate ,visit/click as visitRate ,conversion/visit as conversionRate,eCmp,income
+		from t_rpt_daily
+		left join t_order
+		ON t_rpt_daily.order_id=t_order.id
+		order by order_id desc
+		limit #{pager.offset}, #{pager.limit}
+	</select>
+	
+	<select id="findByCampaignName" parameterType="map" resultType="DeliverAnalysis">
+		select 
+		t_campaign.name as campaignName,impression,click,visit,conversion,click/impression as clickRate ,visit/click as visitRate ,conversion/visit as conversionRate ,eCmp,income
+		from t_rpt_daily
+		left join t_campaign
+		ON t_rpt_daily.campaign_id=t_campaign.id
+		order by campaign_id desc
+		limit #{pager.offset}, #{pager.limit}
+	</select>
+	
+	<select id="findByAdGroupName" parameterType="map" resultType="DeliverAnalysis">
+		select 
+		t_adgroup.name as adGroupName,impression,click,visit,conversion,click/impression as clickRate ,visit/click as visitRate ,conversion/visit as conversionRate ,eCmp,income
+		from t_rpt_daily
+		left join t_adgroup
+		ON t_rpt_daily.adgroup_id=t_adgroup.id
+		order by adgroup_id desc
+		limit #{pager.offset}, #{pager.limit}
+	</select>
+	
+	<select id="findByBannerName" parameterType="map" resultType="DeliverAnalysis">
+		select 
+		t_banner.name as bannerName,impression,click,visit,conversion,click/impression as clickRate ,visit/click as visitRate ,conversion/visit as conversionRate ,eCmp,income
+		from t_rpt_daily
+		left join t_banner
+		ON t_rpt_daily.banner_id=t_banner.id
+		order by banner_id desc
+		limit #{pager.offset}, #{pager.limit}
+	</select>  -->
+	
+	
+	
+	
+	<select id="findByAdvertiser" parameterType="map" resultType="map">
+		select ad.name as advertiserName,date as reportDate,sum(a.consume) as totalConsume,sum(a.impression) as totalImpression,
+sum(click) as totalClick, if(sum(a.impression) > 0,sum(a.click)/sum(a.impression),0)
+		as clickRate from t_rpt_advertiser as a left join t_advertiser ad on a.advertiser_id=ad.id
+		where a.advertiser_id=#{advertiserId}
+		and a.date >= #{startDate} and a.date &lt;=#{endDate}
+		group by date(a.date)
+	</select>
+	
+	<select id="findByAdvertiser3" parameterType="map" resultType="map">
+		select ad.name as advertiserName,date as reportDate,sum(a.consume) as totalConsume,sum(a.impression) as totalImpression,
+sum(click) as totalClick, if(sum(a.impression) > 0,sum(a.click)/sum(a.impression),0)
+		as clickRate from t_rpt_advertiser as a left join t_advertiser ad on a.advertiser_id=ad.id
+		where a.advertiser_id=#{advertiserId}
+		and a.date >= #{startDate} and a.date &lt;=#{endDate}
+		group by date(a.date)
+		limit #{pager.offset}, #{pager.limit} 
+	</select>
+	
+	<select id="findByAreal" parameterType="map" resultType="com.cloudcross.ssp.model.DeliverAnalysis">
+		select 
+	    b.cn,b.cn_city,100*sum(a.pv)/(select sum(pv) from t_rpt_zone_location where date &gt;= #{startDate} and #{endDate} &gt;=date
+		    and operator_id=#{operatorId}
+		) as viewRate,
+	    sum(a.pv) as pv,sum(a.uv) as uv,sum(a.impression),
+	    sum(uimpression) as uImpression, sum(uclick) as uClick,
+	    100*sum(a.impression)/sum(a.pv) as fillRate,sum(a.click),100*sum(a.click)/sum(a.impression) as clickRate,sum(a.eCpm) as eCpm,sum(a.income) as income
+		from t_rpt_zone_location a,t_location b
+		where
+		a.location=b.location and b.cn=#{cn} and date &gt;= #{startDate} and #{endDate} &gt;=date
+		    and operator_id=#{operatorId}
+       group by b.cn_city
+	</select>
+	
+	<select id="findByAdvertiser1" parameterType="map" resultType="map">
+		select ad.name as advertiserName,date as reportDate, a.hour as hour,sum(a.consume) as totalConsume,sum(a.impression) as totalImpression,
+sum(click) as totalClick, if(sum(a.impression) > 0,sum(a.click)/sum(a.impression),0)
+		as clickRate from t_rpt_advertiser_hour as a left join t_advertiser ad on a.advertiser_id=ad.id
+		where a.advertiser_id=#{advertiserId} and a.date = #{startDate}
+		group by a.hour
+	</select>
+	
+	<select id="countByPlace" parameterType="map" resultType="int">
+		select count(place_id) from ((select distinct place_id from t_rpt_zone_place where 
+		operator_id = #{operatorId} and date &gt;= #{startDate} and date &lt;= #{endDate}) as a) 
+	</select>
+	
+	
+	<select id="findByAdvertiser2" parameterType="map" resultType="map">
+		select ad.name as advertiserName,date as reportDate, a.hour as hour,sum(a.consume) as totalConsume,sum(a.impression) as totalImpression,
+sum(click) as totalClick, if(sum(a.impression) > 0,sum(a.click)/sum(a.impression),0)
+		as clickRate from t_rpt_advertiser_hour as a left join t_advertiser ad on a.advertiser_id=ad.id
+		where a.advertiser_id=#{advertiserId} and a.date = #{startDate}
+		group by a.hour
+		limit #{pager.offset}, #{pager.limit} 
+	</select>
+	
+	
+		<select id="findByPlace" parameterType="map" resultType="com.cloudcross.ssp.model.DeliverAnalysis">
+		select t_place.name as place,sum(p.pv) as pv, sum(p.uv) as uv, sum(p.impression) as impression, 
+		sum(uimpression) as uImpression,
+		sum(uclick) as uClick,sum(p.click) as click, sum(p.ecpm) as eCpm,
+    sum(p.income) as income, 100 * sum(p.pv) / (select sum(pv) from t_rpt_zone_place where operator_id = #{operatorId} and date &gt;= #{startDate} and date &lt;= #{endDate}) as viewRate, 
+    100 * sum(p.impression) / sum(p.pv) as fillRate, 100 * sum(p.click) / sum(p.impression) as clickRate
+    from ((select distinct place_id from t_rpt_zone_place where operator_id = #{operatorId} and date &gt;= #{startDate} and date &lt;= #{endDate}) as a ), 
+    t_rpt_zone_place as p, t_place where a.place_id = p.place_id and a.place_id = t_place.id
+    and operator_id = #{operatorId} and date &gt;= #{startDate} and date &lt;= #{endDate}
+    group by p.place_id
+    order by p.impression desc
+	limit #{pager.offset}, #{pager.limit}
+	</select>
+	
+	<select id="findCountForChart" parameterType="map" resultType="int">
+	select count(date) from((select distinct date from t_rpt_advertiser where advertiser_id=#{advertiserId}
+		and date >= #{startDate} and date &lt;=#{endDate}) as a)
+	</select>
+	
+		<select id="findByPlace1" parameterType="map" resultType="com.cloudcross.ssp.model.DeliverAnalysis">
+		select t_place.name as place,sum(p.pv) as pv, sum(p.uv) as uv, sum(p.impression) as impression, 
+		sum(uimpression) as uImpression,
+		sum(uclick) as uClick,sum(p.click) as click, sum(p.ecpm) as eCpm,
+    sum(p.income) as income, 100 * sum(p.pv) / (select sum(pv) from t_rpt_zone_place where operator_id = #{operatorId} and date &gt;= #{startDate} and date &lt;= #{endDate}) as viewRate, 
+    100 * sum(p.impression) / sum(p.pv) as fillRate, 100 * sum(p.click) / sum(p.impression) as clickRate
+    from ((select distinct place_id from t_rpt_zone_place where operator_id = #{operatorId} and date &gt;= #{startDate} and date &lt;= #{endDate}) as a ), 
+    t_rpt_zone_place as p, t_place where a.place_id = p.place_id and a.place_id = t_place.id
+    and operator_id = #{operatorId} and date &gt;= #{startDate} and date &lt;= #{endDate}
+    group by p.place_id
+     order by p.impression desc
+	</select>
+	
+	<select id="findCountForChart1" parameterType="map" resultType="int">
+		select count(hour) from ((select distinct hour from t_rpt_advertiser_hour where advertiser_id=#{advertiserId} and date = #{startDate}) as a) 
+	</select>
+	
+	<select id="findTotalImpressionAndClickByAdvertiserId" parameterType="map" resultType="map">
+		select sum(impression) as totalImpression, sum(click) as totalClick
+		from t_rpt_advertiser 
+		where advertiser_id = #{advertiserId} and date = #{date}
+	</select>
+	
+	<select id="countByApmac" parameterType="map" resultType="int">
+			select count(apmac) from ((select distinct apmac from t_rpt_zone_ap where 
+		operator_id = #{operatorId} and date &gt;= #{startDate} and date &lt;= #{endDate}) as a) 
+	</select>
+	
+	<select id="findTotalImpressionAndClickByAgentId" parameterType="map" resultType="map">
+		select sum(a.impression) as totalImpression, sum(a.click) as totalClick
+		from t_rpt_advertiser  a,t_advertiser b
+		where b.id = a.advertiser_id and b.agent_id = #{agentId}
+		and a.date = #{date}
+	
+	</select>
+	
+	<!--数据报表 导出excel -->
+	<select id="findByTotalForExcelAdvertiser" parameterType="map" resultType="com.cloudcross.ssp.model.DeliverAnalysis">
+		select b.name advertiserName,c.name orderName,d.name campaignName,e.name adgroupName,g.name bannerName,a.date reportDate,sum(a.impression) as impression,sum(a.click) as click,100*sum(a.click)/sum(a.impression) as clickRate,sum(a.visit) as visit,100*sum(a.visit)/sum(a.click) as visitRate,sum(a.conversion) conversion,100*sum(a.conversion)/sum(a.visit) as conversionRate,sum(a.ecmp) ecmp,sum(a.consume) as consume 
+		from t_rpt_advertiser a,t_advertiser b,t_order c,t_campaign d,t_adgroup e,t_banner f,t_banner_template g
+		where a.advertiser_id=b.id and a.order_id=c.id and a.campaign_id=d.id and a.adgroup_id=e.id and a.banner_id=f.id and f.banner_template_id=g.id
+		<if test="advertiserId != null and advertiserId ">
+			and a.advertiser_id = #{advertiserId}
+		</if>
+		<if test="orderId != null and orderId != ''">
+			and a.order_id = #{orderId}
+		</if>
+		<if test="campaginId != null and campaginId != ''">
+			and a.campagin_id = #{campaginId}
+		</if>
+		<if test="adgroupId != null and adgroupId != ''">
+			and a.adgroup_id = #{adgroupId}
+		</if>
+		<if test="startDate != null and startDate != ''and endDate != nul and endDate != ''">
+			and a.date &gt;=#{startDate} and a.date &lt;=#{endDate}
+		</if>
+		<choose>
+			<when test="dimensionStr != null and dimensionStr != ''">
+				GROUP BY ${dimensionStr}
+			</when>
+			<otherwise>
+				group by reportDate 
+			</otherwise>
+		</choose>		
+	</select>
+	
+	<select id="findByApmac" parameterType="map" resultType="com.cloudcross.ssp.model.DeliverAnalysis">
+		select apmac, sum(pv) as pv, sum(uv) as uv, sum(impression) as impression, 
+		sum(uimpression) as uImpression,
+		sum(uclick) as uClick,sum(click) as click, sum(ecpm) as eCpm,
+    sum(income) as income, 100 * sum(pv) / (select sum(pv) from t_rpt_zone_ap where operator_id = #{operatorId} and date &gt;= #{startDate} and date &lt;= #{endDate}) as viewRate, 
+    100 * sum(impression) / sum(pv) as fillRate, 100 * sum(click) / sum(impression) as clickRate
+    from  t_rpt_zone_ap  where 
+    operator_id = #{operatorId} and date &gt;= #{startDate} and date &lt;= #{endDate}
+    group by apmac
+    order by impression desc
+	limit #{pager.offset}, #{pager.limit}
+	</select>
+	
+	<select id="findByLocationForExcel" parameterType="map" resultType="com.cloudcross.ssp.model.DeliverAnalysis">
+		select t_location.cn_city as location, 100 * sum(impression) /(select sum(impression) from t_rpt_adv_location a1,t_advertiser b1	
+		<where>	
+       	a1.advertiser_id = b1.id and a1.date &gt;= #{startDate} and #{endDate} &gt;=a1.date
+			<if test="advertiserId ==null">
+			 and b1.agent_id=#{agentId}
+			</if>
+			<if test="advertiserId != null">
+			and a1.advertiser_id = #{advertiserId}	
+			</if>
+			<if test="orderId !=null">
+			 and a1.order_id=#{orderId}
+			</if>
+		     <if test="campaignId !=null">
+			 and a1.campaign_id=#{campaignId}
+			</if>
+			<if test="adGroupId !=null">
+			 and a1.adgroup_id=#{adGroupId}
+			</if>
+		</where>
+		) as impressionRate, sum(impression) as impression, sum(click) as click, 100 * sum(click) / sum(impression) as clickRate,
+		sum(visit) as visit, 100 * sum(visit) / sum(click) as visitRate, 100 * sum(conversion) / sum(visit) as conversionRate,
+		sum(conversion) as conversion, sum(ecmp) as eCmp, sum(consume) as consume from t_rpt_adv_location a, t_advertiser b,t_location
+		 	<where>	
+       	a.advertiser_id = b.id and a.location = t_location.location and a.date &gt;= #{startDate} and #{endDate} &gt;=a.date
+			<if test="advertiserId ==null">
+			 and b.agent_id=#{agentId}
+			</if>
+			<if test="advertiserId != null">
+			and a.advertiser_id = #{advertiserId}	
+			</if>
+			<if test="orderId !=null">
+			 and a.order_id=#{orderId}
+			</if>
+		     <if test="campaignId !=null">
+			 and a.campaign_id=#{campaignId}
+			</if>
+			<if test="adGroupId !=null">
+			 and a.adgroup_id=#{adGroupId}
+			</if>
+		</where>
+		group by a.location
+	   </select>
+	
+		<select id="findByApmac1" parameterType="map" resultType="com.cloudcross.ssp.model.DeliverAnalysis">
+			select apmac, sum(pv) as pv, sum(uv) as uv, sum(impression) as impression, 
+		sum(uimpression) as uImpression,
+		sum(uclick) as uClick,sum(click) as click, sum(ecpm) as eCpm,
+    sum(income) as income, 100 * sum(pv) / (select sum(pv) from t_rpt_zone_ap where operator_id = #{operatorId} and date &gt;= #{startDate} and date &lt;= #{endDate}) as viewRate, 
+    100 * sum(impression) / sum(pv) as fillRate, 100 * sum(click) / sum(impression) as clickRate
+    from  t_rpt_zone_ap  where 
+    operator_id = #{operatorId} and date &gt;= #{startDate} and date &lt;= #{endDate}
+    group by apmac
+    order by impression desc
+	</select>
+	
+	<!-- 导出excel -->
+	<select id="findByTotalForExcelBack" parameterType="map" resultType="com.cloudcross.ssp.model.DeliverAnalysis">
+		select 
+		t_advertiser.name as advertiserName,  t_order.name as orderName, t_campaign.name as campaignName, t_adgroup.name  as adGroupName, t_banner_template.name as bannerName, 
+        
+         ad.date as reportDate,     
+        (select sum(t_rpt_advertiser.impression) from  t_rpt_advertiser ,t_advertiser,t_order, t_campaign, t_banner, t_adgroup, t_banner_template where  t_rpt_advertiser.advertiser_id=t_advertiser.id  and  t_rpt_advertiser.order_id = t_order.id  and t_rpt_advertiser.campaign_id= t_campaign.id   
+	 	    and  t_rpt_advertiser.adgroup_id=t_adgroup.id
+            and  t_rpt_advertiser.banner_id=t_banner.id 
+            and  t_banner.banner_template_id = t_banner_template.id 
+
+			<if test="advertiserId !=null">
+			 and t_rpt_advertiser.advertiser_id=#{advertiserId}
+			</if>
+			<if test="orderId !=null">
+			 and t_rpt_advertiser.order_id=#{orderId}
+			</if>
+			  
+		     <if test="campaignId !=null">
+			 and t_rpt_advertiser.campaign_id=#{campaignId}
+			</if>
+			
+			<if test="adGroupId !=null">
+			 and t_rpt_advertiser.adgroup_id=#{adGroupId}
+			</if>
+		 
+	    <if test="startDate!=null and endDate!=null"> 
+            and date &gt;= #{startDate} and #{endDate} &gt;=date
+	    </if>) as impressionSum,ad.impression,ad.click,visit,ad.conversion, 
+        100*ad.click/ad.impression as clickRate ,100*visit/ad.click as visitRate ,100*ad.conversion/visit as conversionRate ,ecmp as eCmp,ad.consume,
+		(select sum(t_rpt_advertiser.click) from t_rpt_advertiser ,t_advertiser,t_order, t_campaign, t_banner, t_adgroup, t_banner_template where  t_rpt_advertiser.advertiser_id=t_advertiser.id  and  t_rpt_advertiser.order_id = t_order.id  and t_rpt_advertiser.campaign_id= t_campaign.id   
+	 	    and  t_rpt_advertiser.adgroup_id=t_adgroup.id
+            and  t_rpt_advertiser.banner_id=t_banner.id 
+            and  t_banner.banner_template_id = t_banner_template.id 
+
+			<if test="advertiserId !=null">
+			 and t_rpt_advertiser.advertiser_id=#{advertiserId}
+			</if>
+			<if test="orderId !=null">
+			 and t_rpt_advertiser.order_id=#{orderId}
+			</if>
+			  
+		     <if test="campaignId !=null">
+			 and t_rpt_advertiser.campaign_id=#{campaignId}
+			</if>
+			
+			<if test="adGroupId !=null">
+			 and t_rpt_advertiser.adgroup_id=#{adGroupId}
+			</if>
+		 
+	    <if test="startDate!=null and endDate!=null"> 
+            and date &gt;= #{startDate} and #{endDate} &gt;=date
+	    </if>) as clickSum, (select sum(t_rpt_advertiser.visit) from t_rpt_advertiser ,t_advertiser,t_order, t_campaign, t_banner, t_adgroup, t_banner_template where  t_rpt_advertiser.advertiser_id=t_advertiser.id  and  t_rpt_advertiser.order_id = t_order.id  and t_rpt_advertiser.campaign_id= t_campaign.id   
+	 	    and  t_rpt_advertiser.adgroup_id=t_adgroup.id
+            and  t_rpt_advertiser.banner_id=t_banner.id 
+            and  t_banner.banner_template_id = t_banner_template.id 
+
+			<if test="advertiserId !=null">
+			 and t_rpt_advertiser.advertiser_id=#{advertiserId}
+			</if>
+			<if test="orderId !=null">
+			 and t_rpt_advertiser.order_id=#{orderId}
+			</if>
+			  
+		     <if test="campaignId !=null">
+			 and t_rpt_advertiser.campaign_id=#{campaignId}
+			</if>
+			
+			<if test="adGroupId !=null">
+			 and t_rpt_advertiser.adgroup_id=#{adGroupId}
+			</if>
+		 
+	    <if test="startDate!=null and endDate!=null"> 
+            and date &gt;= #{startDate} and #{endDate} &gt;=date
+	    </if>) as visitSum,
+        (select sum(t_rpt_advertiser.conversion) from t_rpt_advertiser ,t_advertiser,t_order, t_campaign, t_banner, t_adgroup, t_banner_template where  t_rpt_advertiser.advertiser_id=t_advertiser.id  and  t_rpt_advertiser.order_id = t_order.id  and t_rpt_advertiser.campaign_id= t_campaign.id   
+	 	    and  t_rpt_advertiser.adgroup_id=t_adgroup.id
+            and  t_rpt_advertiser.banner_id=t_banner.id 
+            and  t_banner.banner_template_id = t_banner_template.id 
+
+			<if test="advertiserId !=null">
+			 and t_rpt_advertiser.advertiser_id=#{advertiserId}
+			</if>
+			<if test="orderId !=null">
+			 and t_rpt_advertiser.order_id=#{orderId}
+			</if>
+			  
+		     <if test="campaignId !=null">
+			 and t_rpt_advertiser.campaign_id=#{campaignId}
+			</if>
+			
+			<if test="adGroupId !=null">
+			 and t_rpt_advertiser.adgroup_id=#{adGroupId}
+			</if>
+		 
+	    <if test="startDate!=null and endDate!=null"> 
+            and date &gt;= #{startDate} and #{endDate} &gt;=date
+	    </if>) as conversionSum, 
+		(select sum(t_rpt_advertiser.ecmp) from t_rpt_advertiser ,t_advertiser,t_order, t_campaign, t_banner, t_adgroup, t_banner_template where  t_rpt_advertiser.advertiser_id=t_advertiser.id  and  t_rpt_advertiser.order_id = t_order.id  and t_rpt_advertiser.campaign_id= t_campaign.id   
+	 	    and  t_rpt_advertiser.adgroup_id=t_adgroup.id
+            and  t_rpt_advertiser.banner_id=t_banner.id 
+            and  t_banner.banner_template_id = t_banner_template.id 
+
+			<if test="advertiserId !=null">
+			 and t_rpt_advertiser.advertiser_id=#{advertiserId}
+			</if>
+			<if test="orderId !=null">
+			 and t_rpt_advertiser.order_id=#{orderId}
+			</if>
+			  
+		     <if test="campaignId !=null">
+			 and t_rpt_advertiser.campaign_id=#{campaignId}
+			</if>
+			
+			<if test="adGroupId !=null">
+			 and t_rpt_advertiser.adgroup_id=#{adGroupId}
+			</if>
+		 
+	    <if test="startDate!=null and endDate!=null"> 
+            and date &gt;= #{startDate} and #{endDate} &gt;=date
+	    </if>) as eCmpSum, (select sum(t_rpt_advertiser.consume) from t_rpt_advertiser ,t_advertiser,t_order, t_campaign, t_banner, t_adgroup, t_banner_template where  t_rpt_advertiser.advertiser_id=t_advertiser.id  and  t_rpt_advertiser.order_id = t_order.id  and t_rpt_advertiser.campaign_id= t_campaign.id   
+	 	    and  t_rpt_advertiser.adgroup_id=t_adgroup.id
+            and  t_rpt_advertiser.banner_id=t_banner.id 
+            and  t_banner.banner_template_id = t_banner_template.id 
+
+			<if test="advertiserId !=null">
+			 and t_rpt_advertiser.advertiser_id=#{advertiserId}
+			</if>
+			<if test="orderId !=null">
+			 and t_rpt_advertiser.order_id=#{orderId}
+			</if>
+			  
+		     <if test="campaignId !=null">
+			 and t_rpt_advertiser.campaign_id=#{campaignId}
+			</if>
+			
+			<if test="adGroupId !=null">
+			 and t_rpt_advertiser.adgroup_id=#{adGroupId}
+			</if>
+		 
+	    <if test="startDate!=null and endDate!=null"> 
+            and date &gt;= #{startDate} and #{endDate} &gt;=date
+	    </if>) as consumeSum, 
+        100*(select sum(t_rpt_advertiser.click) from t_rpt_advertiser ,t_advertiser,t_order, t_campaign, t_banner, t_adgroup, t_banner_template where  t_rpt_advertiser.advertiser_id=t_advertiser.id  and  t_rpt_advertiser.order_id = t_order.id  and t_rpt_advertiser.campaign_id= t_campaign.id   
+	 	    and  t_rpt_advertiser.adgroup_id=t_adgroup.id
+            and  t_rpt_advertiser.banner_id=t_banner.id 
+            and  t_banner.banner_template_id = t_banner_template.id 
+
+			<if test="advertiserId !=null">
+			 and t_rpt_advertiser.advertiser_id=#{advertiserId}
+			</if>
+			<if test="orderId !=null">
+			 and t_rpt_advertiser.order_id=#{orderId}
+			</if>
+			  
+		     <if test="campaignId !=null">
+			 and t_rpt_advertiser.campaign_id=#{campaignId}
+			</if>
+			
+			<if test="adGroupId !=null">
+			 and t_rpt_advertiser.adgroup_id=#{adGroupId}
+			</if>
+		 
+	    <if test="startDate!=null and endDate!=null"> 
+            and date &gt;= #{startDate} and #{endDate} &gt;=date
+	    </if>)/(select sum(t_rpt_advertiser.impression) from t_rpt_advertiser ,t_advertiser,t_order, t_campaign, t_banner, t_adgroup, t_banner_template where  t_rpt_advertiser.advertiser_id=t_advertiser.id  and  t_rpt_advertiser.order_id = t_order.id  and t_rpt_advertiser.campaign_id= t_campaign.id   
+	 	    and  t_rpt_advertiser.adgroup_id=t_adgroup.id
+            and  t_rpt_advertiser.banner_id=t_banner.id 
+            and  t_banner.banner_template_id = t_banner_template.id 
+
+			<if test="advertiserId !=null">
+			 and t_rpt_advertiser.advertiser_id=#{advertiserId}
+			</if>
+			<if test="orderId !=null">
+			 and t_rpt_advertiser.order_id=#{orderId}
+			</if>
+			  
+		     <if test="campaignId !=null">
+			 and t_rpt_advertiser.campaign_id=#{campaignId}
+			</if>
+			
+			<if test="adGroupId !=null">
+			 and t_rpt_advertiser.adgroup_id=#{adGroupId}
+			</if>
+		 
+	    <if test="startDate!=null and endDate!=null"> 
+            and date &gt;= #{startDate} and #{endDate} &gt;=date
+	    </if>) as clickRatesum, 
+		100*(select sum(t_rpt_advertiser.visit) from t_rpt_advertiser ,t_advertiser,t_order, t_campaign, t_banner, t_adgroup, t_banner_template where  t_rpt_advertiser.advertiser_id=t_advertiser.id  and  t_rpt_advertiser.order_id = t_order.id  and t_rpt_advertiser.campaign_id= t_campaign.id   
+	 	    and  t_rpt_advertiser.adgroup_id=t_adgroup.id
+            and  t_rpt_advertiser.banner_id=t_banner.id 
+            and  t_banner.banner_template_id = t_banner_template.id 
+
+			<if test="advertiserId !=null">
+			 and t_rpt_advertiser.advertiser_id=#{advertiserId}
+			</if>
+			<if test="orderId !=null">
+			 and t_rpt_advertiser.order_id=#{orderId}
+			</if>
+			  
+		     <if test="campaignId !=null">
+			 and t_rpt_advertiser.campaign_id=#{campaignId}
+			</if>
+			
+			<if test="adGroupId !=null">
+			 and t_rpt_advertiser.adgroup_id=#{adGroupId}
+			</if>
+		 
+	    <if test="startDate!=null and endDate!=null"> 
+            and date &gt;= #{startDate} and #{endDate} &gt;=date
+	    </if>)/(select sum(t_rpt_advertiser.click) from t_rpt_advertiser ,t_advertiser,t_order, t_campaign, t_banner, t_adgroup, t_banner_template where  t_rpt_advertiser.advertiser_id=t_advertiser.id  and  t_rpt_advertiser.order_id = t_order.id  and t_rpt_advertiser.campaign_id= t_campaign.id   
+	 	    and  t_rpt_advertiser.adgroup_id=t_adgroup.id
+            and  t_rpt_advertiser.banner_id=t_banner.id 
+            and  t_banner.banner_template_id = t_banner_template.id 
+
+			<if test="advertiserId !=null">
+			 and t_rpt_advertiser.advertiser_id=#{advertiserId}
+			</if>
+			<if test="orderId !=null">
+			 and t_rpt_advertiser.order_id=#{orderId}
+			</if>
+			  
+		     <if test="campaignId !=null">
+			 and t_rpt_advertiser.campaign_id=#{campaignId}
+			</if>
+			
+			<if test="adGroupId !=null">
+			 and t_rpt_advertiser.adgroup_id=#{adGroupId}
+			</if>
+		 
+	    <if test="startDate!=null and endDate!=null"> 
+            and date &gt;= #{startDate} and #{endDate} &gt;=date
+	    </if>) as visitRatesum,
+		100*(select sum(t_rpt_advertiser.conversion) from t_rpt_advertiser ,t_advertiser,t_order, t_campaign, t_banner, t_adgroup, t_banner_template where  t_rpt_advertiser.advertiser_id=t_advertiser.id  and  t_rpt_advertiser.order_id = t_order.id  and t_rpt_advertiser.campaign_id= t_campaign.id   
+	 	    and  t_rpt_advertiser.adgroup_id=t_adgroup.id
+            and  t_rpt_advertiser.banner_id=t_banner.id 
+            and  t_banner.banner_template_id = t_banner_template.id 
+
+			<if test="advertiserId !=null">
+			 and t_rpt_advertiser.advertiser_id=#{advertiserId}
+			</if>
+			<if test="orderId !=null">
+			 and t_rpt_advertiser.order_id=#{orderId}
+			</if>
+			  
+		     <if test="campaignId !=null">
+			 and t_rpt_advertiser.campaign_id=#{campaignId}
+			</if>
+			
+			<if test="adGroupId !=null">
+			 and t_rpt_advertiser.adgroup_id=#{adGroupId}
+			</if>
+		 
+	    <if test="startDate!=null and endDate!=null"> 
+            and date &gt;= #{startDate} and #{endDate} &gt;=date
+	    </if>)/(select sum(t_rpt_advertiser.visit) from t_rpt_advertiser ,t_advertiser,t_order, t_campaign, t_banner, t_adgroup, t_banner_template where  t_rpt_advertiser.advertiser_id=t_advertiser.id  and  t_rpt_advertiser.order_id = t_order.id  and t_rpt_advertiser.campaign_id= t_campaign.id   
+	 	    and  t_rpt_advertiser.adgroup_id=t_adgroup.id
+            and  t_rpt_advertiser.banner_id=t_banner.id 
+            and  t_banner.banner_template_id = t_banner_template.id 
+
+			<if test="advertiserId !=null">
+			 and t_rpt_advertiser.advertiser_id=#{advertiserId}
+			</if>
+			<if test="orderId !=null">
+			 and t_rpt_advertiser.order_id=#{orderId}
+			</if>
+			  
+		     <if test="campaignId !=null">
+			 and t_rpt_advertiser.campaign_id=#{campaignId}
+			</if>
+			
+			<if test="adGroupId !=null">
+			 and t_rpt_advertiser.adgroup_id=#{adGroupId}
+			</if>
+		 
+	    <if test="startDate!=null and endDate!=null"> 
+            and date &gt;= #{startDate} and #{endDate} &gt;=date
+	    </if>) as conversionRatesum
+		
+		from t_rpt_advertiser ad,t_advertiser,t_order, t_campaign, t_banner, t_adgroup, t_banner_template
+           
+           
+           <where>
+	 	    ad.advertiser_id=t_advertiser.id  and  ad.order_id = t_order.id  and ad.campaign_id= t_campaign.id   
+	 	    and  ad.adgroup_id=t_adgroup.id
+            and  ad.banner_id=t_banner.id 
+            and  t_banner.banner_template_id = t_banner_template.id
+
+			<if test="advertiserId !=null">
+			 and ad.advertiser_id=#{advertiserId}
+			</if>
+			
+			<if test="orderId !=null">
+			 and ad.order_id=#{orderId}
+			</if>
+			  
+		     <if test="campaignId !=null">
+			 and ad.campaign_id=#{campaignId}
+			</if>
+			
+			<if test="adGroupId !=null">
+			 and ad.adgroup_id=#{adGroupId}
+			</if>
+		 
+	
+	    <if test="startDate!=null and endDate!=null"> 
+            and date &gt;= #{startDate} and #{endDate} &gt;=date
+	    </if>
+	  
+		  </where> 
+		
+	</select>
+	
+	<select id="findAllArea" parameterType="map" resultType="com.cloudcross.ssp.model.DeliverAnalysis">
+		select 
+	    a.id,a.date as reportDate,b.cn,b.cn_city,100*sum(a.pv)/(select sum(pv) from t_rpt_zone_location where date &gt;= #{startDate} and #{endDate} &gt;=date
+		<if test="operatorId!=null">
+		    and operator_id=#{operatorId}
+		</if>) as viewRate,
+	    sum(a.pv) as pv,sum(a.uv) as uv,sum(a.impression) as impression,
+	    sum(uimpression) as uImpression, sum(uclick) as uClick,
+	    100*sum(a.impression)/sum(a.pv) as fillRate,sum(a.click) as click,100*sum(a.click)/sum(a.impression) as clickRate,sum(a.eCpm) as eCpm,sum(a.income) as income
+		from t_rpt_zone_location a,t_location b
+	 	where
+		a.location = b.location  and a.date &gt;= #{startDate} and #{endDate} &gt;=a.date
+		<if test="operatorId!=null">
+		    and operator_id=#{operatorId}
+		</if>
+		group by b.cn 
+		order by b.cn
+	</select>
+	
+	<select id="findByOsForExcel" parameterType="map" resultType="com.cloudcross.ssp.model.DeliverAnalysis">
+		select 
+		t_advertiser.name as advertiserName,  t_order.name as orderName, t_campaign.name as campaignName, t_adgroup.name  as adGroupName,
+
+              ros.date as reportDate,
+        ros.impression,ros.click,visit,ros.conversion,os,
+        100*ros.impression/(select sum(impression) from t_rpt_adv_os) as impressionRate,100*ros.click/ros.impression as clickRate ,
+        100*visit/ros.click as visitRate ,100*ros.conversion/visit as conversionRate,ecmp as eCmp,consume   
+        from t_rpt_adv_os ros, t_advertiser, t_order, t_campaign, t_adgroup        
+
+
+            <where>	          
+         
+           ros.advertiser_id = t_advertiser.id  and  ros.order_id =  t_order.id and ros.campaign_id = t_campaign.id  and ros.adgroup_id =  t_adgroup.id
+		     	   
+			<if test="advertiserId !=null">
+			 and ros.advertiser_id=#{advertiserId}
+			</if> 
+			
+			<if test="orderId !=null">
+			 and ros.order_id=#{orderId}
+			</if>
+		     
+		     <if test="campaignId !=null">
+			 and ros.campaign_id=#{campaignId}
+			</if>
+			
+			<if test="adGroupId !=null">
+			 and ros.adgroup_id=#{adGroupId}
+			</if>
+			
+	 		<if test="startDate!=null and endDate!=null"> 
+            and ros.date &gt;= #{startDate} and #{endDate} &gt;=ros.date
+		     </if>
+	
+		   </where> 
+
+	</select>
+	
+	 <select id="findByPlaceNameForExcel" parameterType="map" resultType="com.cloudcross.ssp.model.DeliverAnalysis">
+		select 
+	             t_place.name as placeName,	t_advertiser.name as advertiserName,  t_order.name as orderName, 
+	             t_campaign.name as campaignName, t_adgroup.name as adGroupName,
+	             
+	              rp.date as reportDate,
+                  rp.impression,rp.click,visit,rp.conversion,
+              100*rp.impression/(select sum(impression) from t_rpt_adv_place) as impressionRate,100*rp.click/rp.impression as clickRate ,
+              100*visit/rp.click as visitRate ,100*rp.conversion/visit as conversionRate,ecmp as eCmp,consume   
+            from t_rpt_adv_place rp, t_advertiser, t_order, t_campaign, t_adgroup , t_place      
+
+
+              <where>      
+            rp.place_id = t_place.id and  rp.advertiser_id = t_advertiser.id  
+            and  rp.order_id = t_order.id and rp.campaign_id = t_campaign.id  and rp.adgroup_id =  t_adgroup.id
+	   
+			<if test="advertiserId !=null">
+			 and rp.advertiser_id=#{advertiserId}
+			</if> 
+			
+			<if test="orderId !=null">
+			 and rp.order_id=#{orderId}
+			</if>
+		     
+		     <if test="campaignId !=null">
+			 and rp.campaign_id=#{campaignId}
+			</if>
+			
+			<if test="adGroupId !=null">
+			 and rp.adgroup_id=#{adGroupId}
+			</if>
+		 
+	  		 <if test="startDate!=null and endDate!=null"> 
+            and rp.date &gt;= #{startDate} and #{endDate} &gt;=rp.date
+		        </if>
+		     
+		  </where> 
+	</select>
+	
+</mapper>

+ 170 - 0
src/main/java/com/cloudcross/ssp/model/mapper/resources.sql.xml

@@ -0,0 +1,170 @@
+<?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="resourcesSqlMapper">
+<!--mybatis ehcache缓存配置  -->
+<!-- 以下两个<cache>标签二选一,第一个可以输出日志,第二个不输出日志
+<cache type="org.mybatis.caches.ehcache.LoggingEhcache" /> -->
+<!-- <cache type="org.mybatis.caches.ehcache.EhcacheCache"/> -->
+
+	<!-- 以下与实体类的中字段一致 -->
+	<sql id="selectId">
+	id,
+	name,
+	parentId,
+	(select r.name from t_resources r where r.id = t_resources.parentId ) parentName,
+	resKey,
+	type,
+	resUrl,
+	level,
+	description
+	</sql>
+	
+	<select id="queryAll" resultType="com.cloudcross.ssp.model.Resources" parameterType="com.cloudcross.ssp.model.Resources">
+		select
+		<include refid="selectId" />
+		from t_resources 
+		where 1+1
+		<if test="name != null and name != ''">
+				and name like '%${name}%'
+				</if>
+		<if test="parentId != null">
+				and parentId =#{parentId}
+		</if>
+		order By level asc
+	</select>
+	<!-- -->
+	<select id="getMaxLevel" resultType="int">
+		select max(level)+1  from t_resources
+	</select>
+	<!--resultType="Resources" 每返回一条结果封装到Resources里 -->
+	<select id="query" resultType="com.cloudcross.ssp.model.Resources" parameterType="java.util.HashMap">
+		select
+		<include refid="selectId" />
+		from t_resources
+		<where>
+			<if test="t.name != null and t.name != ''">
+				name like '%${t.name}%'
+				</if>
+		</where>
+		order By level asc
+	</select>
+	
+	<!--查找菜单名称是否是否存在-->
+		<select id="isExist" resultType="com.cloudcross.ssp.model.Resources" parameterType="String">
+		select
+		<include refid="selectId" />
+		from t_resources
+		where name = #{accountName}
+	</select>
+	<!-- 新增 -->
+	<insert id="add" parameterType="com.cloudcross.ssp.model.Resources">
+		insert into t_resources (
+					name,
+					parentId,
+					resKey,
+					type,
+					resUrl,
+					level,
+					description
+								) 
+		values (
+				#{name},
+				#{parentId},
+				#{resKey},
+				#{type},
+				#{resUrl},
+				#{level},
+				#{description}
+				)
+	</insert>
+	
+	<!-- 删 -->
+	<delete id="delete" parameterType="String">
+		delete from t_resources
+		where id=#{id}
+	</delete>
+	
+	<select id="getById" parameterType="String" resultType="com.cloudcross.ssp.model.Resources">
+		SELECT 
+		<include refid="selectId" />
+		 from t_resources where id=#{id}
+	</select>
+	
+	<select id="queryByParentId" parameterType="java.util.HashMap" resultType="com.cloudcross.ssp.model.Resources">
+		SELECT 
+		<include refid="selectId" />
+		 from t_resources where  type =  convert(#{type},SIGNED) - 1
+	</select>
+	
+	
+	<!-- 更新 -->
+	<update id="update" parameterType="com.cloudcross.ssp.model.Resources">
+	    update t_resources
+	    set
+	    	name = #{name},
+	    	parentId = #{parentId},
+			resKey = #{resKey},
+			type = #{type},
+			resUrl = #{resUrl},
+			level = #{level},
+			description = #{description}
+	   where id = #{id}
+	</update>
+	
+	<!-- 更新 -->
+	<update id="updateSortOrder" parameterType="com.cloudcross.ssp.model.Resources">
+	    update t_resources
+	    set level = #{level}
+	   where id = #{id}
+	</update>
+	<!-- 根据部门Id获取该用户的权限-->
+	<select id="findRoleRes" parameterType="String" resultType="com.cloudcross.ssp.model.Resources">
+		SELECT 
+		<include refid="selectId" />
+		FROM t_resources WHERE id in(
+		SELECT resc_id FROM
+		t_res_roles WHERE role_id = #{roleId})
+		order By level asc
+	</select>
+	
+    
+  	<select id="findResourcesByAccount" parameterType="int" resultType="com.cloudcross.ssp.model.Resources">
+		select
+		<include refid="selectId" /> 
+ 		from t_resources where t_resources.id in 
+    	(select res_id from t_res_accounts where t_res_accounts.account_id = #{id})
+		order By level asc
+	</select>
+	
+	<!-- 根据账号Id获取该用户的权限-->
+	<select id="findAccountResourcess" parameterType="String" resultType="com.cloudcross.ssp.model.Resources">
+		SELECT 
+		<include refid="selectId" />
+		FROM t_resources WHERE id in(
+		SELECT resc_id FROM
+		t_res_roles WHERE role_id in(
+		SELECT role_id FROM t_acc_role
+		WHERE acc_id=#{id}))
+		order By level asc
+	</select>
+	<!-- 删 -->
+	<delete id="deleteResourcesRole" parameterType="String">
+		delete from t_res_roles
+		where role_id=#{id}
+	</delete>
+	
+	<insert id="addRoleRes" parameterType="com.cloudcross.ssp.model.ResourcesRole">
+	insert into t_res_roles (role_id,resc_id) value (#{roleId},#{resId})
+	</insert>
+	
+	<delete id="deleteAccountResources" parameterType="long">
+		delete from t_res_accounts
+		where account_id=#{accountId}
+	</delete>
+	
+	
+	<insert id="addAccountResourcess" parameterType="com.cloudcross.ssp.model.AccountResources">
+	insert into t_res_accounts (account_id,res_id) value (#{accountId},#{resourceId})
+	</insert>
+</mapper>

+ 92 - 0
src/main/java/com/cloudcross/ssp/model/mapper/roles.sql.xml

@@ -0,0 +1,92 @@
+<?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="rolesSqlMapper">
+
+<!--mybatis ehcache缓存配置  -->
+<!-- 以下两个<cache>标签二选一,第一个可以输出日志,第二个不输出日志 
+<cache type="org.mybatis.caches.ehcache.LoggingEhcache" />-->
+<!-- <cache type="org.mybatis.caches.ehcache.EhcacheCache"/> -->
+	<!-- 以下与实体类的中字段一致 -->
+	<sql id="selectId">
+		id,
+		enable,
+		name,
+		roleKey,
+		description
+	</sql>
+	
+	<!--resultType="Roles" 每返回一条结果封装到Account里 -->
+	<select id="query" resultType="com.cloudcross.ssp.model.Roles" parameterType="java.util.HashMap">
+		select
+		<include refid="selectId" />
+		from t_ly_role
+		<where>
+			<if test="t.name != null and t.name != ''">
+				name like '%${t.name}%'
+			</if>
+		</where>
+	</select>
+	<select id="queryAll" resultType="com.cloudcross.ssp.model.Roles" parameterType="com.cloudcross.ssp.model.Roles">
+		select
+		<include refid="selectId" />
+		from t_ly_role
+		<where>
+			<if test="name != null and name != ''">
+				name like '%${name}%'
+			</if>
+		</where>
+	</select>
+	<select id="isExist" resultType="com.cloudcross.ssp.model.Roles" parameterType="String">
+		select
+		<include refid="selectId" />
+		from t_ly_role
+		where name = #{name}
+	</select>
+	
+	<insert id="add" parameterType="com.cloudcross.ssp.model.Roles">
+		insert into t_ly_role ( enable,name,roleKey,description)
+		values (#{enable},
+		#{name}, #{roleKey},
+		#{description})
+	</insert>
+	<delete id="delete" parameterType="String">
+		delete from t_ly_role where
+		id=#{id}
+	</delete>
+	<select id="getById" parameterType="String" resultType="com.cloudcross.ssp.model.Roles">
+		select
+		<include refid="selectId" />
+		from t_ly_role where id=#{id}
+	</select>
+	<update id="update" parameterType="com.cloudcross.ssp.model.Roles">
+		update t_ly_role
+		<set>
+			<if test="name != null and name != ''">
+				name=#{name},
+			</if>
+			<if test="enable != null and enable != ''">
+				enable=#{enable},
+			</if>
+			<if test="description != null and description != ''">
+				description=#{description},
+			</if>
+			<if test="roleKey != null and roleKey != ''">
+				roleKey=#{roleKey}
+			</if>
+		</set>
+		where id=#{id}
+	</update>
+	<select id="findbyAccountRole" parameterType="String" resultType="com.cloudcross.ssp.model.Roles">
+  select 
+  <include refid="selectId" /> 
+  from t_ly_role where id in (SELECT role_id FROM t_acc_role WHERE acc_id=#{accountId}) 
+  </select>
+  <delete id="deleteAccountRole" parameterType="String">
+		delete from t_acc_role
+		where acc_id=#{accountId}
+	</delete>
+  <insert id="addAccRole" parameterType="com.cloudcross.ssp.model.RoleAccount">
+	insert into t_acc_role (acc_id,role_id) value (#{accountId},#{roleId})
+	</insert>
+</mapper>

+ 23 - 0
src/main/java/com/cloudcross/ssp/model/mapper/rpt-advertiser-hour.sql.xml

@@ -0,0 +1,23 @@
+<?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="rptAdvertiserHourSqlMapper">
+	
+	<select id="findEveryHourData" parameterType="map" resultType="com.cloudcross.ssp.model.RptAdvertiserHour">
+		select hour,sum(impression) as impression,sum(click) as click,sum(visit) as visit, sum(conversion) as conversion, sum(ecmp) as ecmp,sum(consume) as consume
+		from t_rpt_advertiser_hour where  date = #{startDate}
+		<if test="advertiserId!=null">
+        	and advertiser_id = #{advertiserId}
+        </if>   
+        <if test="campaignId!=null">
+        	and campaign_id = #{campaignId}
+        </if>     
+        <if test="adgroupId!=null">
+        	and adgroup_id = #{adgroupId}
+        </if>    
+        <if test="bannerId!=null">
+        	and banner_id = #{bannerId}
+        </if>    
+		group by hour
+	</select>
+
+</mapper>

+ 28 - 0
src/main/java/com/cloudcross/ssp/model/mapper/rpt-zone-hour.sql.xml

@@ -0,0 +1,28 @@
+<?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="rptZoneHourSqlMapper">
+	
+	<select id="findEveryHourData" parameterType="map" resultType="com.cloudcross.ssp.model.RptZoneHour">
+		select hour,sum(pv) as pv,sum(uv) as uv, sum(impression) as impression, 
+		sum(uimpression) as uImpression,sum(uclick) as uClick,
+		sum(click) as click, sum(income) as income
+		from t_rpt_zone_hour where date = #{startDate}
+		<if test="zoneId!=null">
+        	and zone_id = #{zoneId}
+        </if>      
+        <if test="operatorId!=null">
+        	and operator_id = #{operatorId}
+        </if>
+		group by hour
+	</select>
+		
+		<select id="findEveryHourDataOperator" parameterType="map" resultType="com.cloudcross.ssp.model.RptZoneHour">
+		select hour,sum(pv) as pv,sum(uv) as uv, sum(impression) as impression, sum(click) as click,sum(uimpression) as uImpression,
+		sum(uclick) as uClick, sum(income) as income
+		from t_rpt_zone_hour where operator_id = #{operatorId} and date = #{startDate}
+		<if test="zoneId!=null">
+        	and zone_id = #{zoneId}
+        </if>      
+		group by hour
+		</select>
+</mapper>

+ 56 - 0
src/main/java/com/cloudcross/ssp/model/mapper/rpt-zone.sql.xml

@@ -0,0 +1,56 @@
+<?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="rptZoneSqlMapper">
+
+	<select id="findByOperatorIdAndDatAdvertiser" parameterType="map" resultType="com.cloudcross.ssp.model.RptZone">
+		select operator_id as operatorId, date, sum(pv) as totalPv, sum(uv) as totalUv,
+        sum(impression) as totalImpression, sum(click) as totalClick,sum(income) as totalIncome from t_rpt_zone
+        where  operator_id = #{operatorId} and date=#{date}
+	</select>
+	
+<!-- 导出excel用 -->
+	<select id="findByParams1" parameterType="map" resultType="com.cloudcross.ssp.model.RptZone">
+		select date, sum(impression) as impression, sum(click) as click, sum(ecpm) as ecpm,
+        sum(income) as income from t_rpt_zone
+        where  operator_id = #{operatorId} and date >= #{startDate} and date &lt;= #{endDate}
+        <if test="zoneId!=null">
+        	and zone_id = #{zoneId}
+        </if>
+		group by date
+	</select>
+		<select id="findByDate" parameterType="map" resultType="com.cloudcross.ssp.model.RptZone">
+		select operator_id as operatorId, date, sum(pv) as pv, sum(uv) as uv,
+        sum(impression) as impression, sum(click) as click,sum(income) as income from t_rpt_zone
+        where date=#{date}
+	
+	
+	</select>
+	
+	<select id="countByParams" parameterType="map" resultType="int">
+		select count(id) from t_rpt_zone
+        where id in ( select id from t_rpt_zone
+        where  operator_id = #{operatorId} and date >= #{startDate} and date &lt;= #{endDate}  
+        <if test="zoneId!=null">
+        	and zone_id = #{zoneId}
+        </if>      
+		group by date
+       		)  
+	</select>
+	
+		<select id="findByOperatorIdAndDateOperator" parameterType="map" resultType="com.cloudcross.ssp.model.RptZone">
+		select operator_id as operatorId, date, sum(pv) as pv, sum(uv) as uv,
+        sum(impression) as impression, sum(click) as click,sum(income) as income from t_rpt_zone
+        where  operator_id = #{operatorId} and date=#{date}
+	</select>
+	
+		<select id="findByParams" parameterType="map" resultType="com.cloudcross.ssp.model.RptZone">
+		select date, sum(impression) as impression, sum(click) as click, sum(ecpm) as ecpm,
+        sum(income) as income from t_rpt_zone
+        where  operator_id = #{operatorId} and date >= #{startDate} and date &lt;= #{endDate}
+        <if test="zoneId!=null">
+        	and zone_id = #{zoneId}
+        </if>
+		group by date
+		limit #{pager.offset}, #{pager.limit}
+	</select>
+</mapper>

+ 23 - 0
src/main/java/com/cloudcross/ssp/model/mapper/size.sql.xml

@@ -0,0 +1,23 @@
+<?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="sizeSqlMapper">
+	<sql id="base_column">
+		id,width,height
+	</sql>
+
+	<select id="findAllSize"  resultType="com.cloudcross.ssp.model.Size">
+		select <include refid="base_column"/> 
+		from t_size order by id desc
+	</select>
+
+	<select id="findSize" parameterType="int" resultType="com.cloudcross.ssp.model.Size">
+		select <include refid="base_column"/>  
+		from t_size where id = #{id} 
+	</select>
+	
+	<select id="findSizeId" parameterType = "map" resultType="com.cloudcross.ssp.model.Size">
+		select <include refid="base_column"/> 
+		from t_size 
+		where width = #{width} and height = #{height}
+	</select>
+</mapper>

+ 48 - 0
src/main/java/com/cloudcross/ssp/model/mapper/systemreport.sql.xml

@@ -0,0 +1,48 @@
+<?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="systemReportSqlMapper">
+	
+	<sql id="base_column">
+	   id,
+	   operator_id as operatatorId,
+	   date,
+	   os,
+	   pv,
+	   uv,
+	   impression,
+	   click,
+	   ecpm,
+	   income
+	</sql>
+	
+	<select id="findByParams"  parameterType="map" resultType="com.cloudcross.ssp.model.SystemReport">
+	    select 
+	    a.id,os,100*(sum(impression)/(select sum(impression) from t_rpt_zone_os a, t_operator b
+		where a.operator_id=b.id 
+		<if test="operatorId!=null">
+		    and a.operator_id=#{operatorId}
+		</if> 
+		   )) as pageviewsPercent,
+		sum(pv) as pv,sum(uv) as uv,sum(impression) as impression,100*(sum(impression)/sum(pv)) as fillRate,
+        sum(click) as click,100*(sum(click)/sum(impression)) as clickRate,sum(ecpm) as ecpm,sum(income) as income
+		from t_rpt_zone_os a, t_operator b
+		where a.operator_id=b.id 
+		<if test="operatorId!=null">
+		    and a.operator_id=#{operatorId}
+		</if>
+		group by os
+		order by id asc 
+		limit #{pager.offset}, #{pager.limit}    
+	</select>
+	
+	<select id="countByParams" parameterType="map" resultType="int">
+	    select count(a.id)
+	    from t_rpt_zone_os a, t_operator b
+		where a.operator_id=b.id 
+		<if test="operatorId!=null">
+		    and a.operator_id=#{operatorId}
+		</if>
+	</select>
+	
+
+</mapper>

+ 48 - 0
src/main/java/com/cloudcross/ssp/model/mapper/typereport.sql.xml

@@ -0,0 +1,48 @@
+<?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="typereportSqlMapper">
+	
+	<sql id="base_column">
+	   id,
+	   operator_id as operatatorId,
+	   date,
+	   device,
+	   pv,
+	   uv,
+	   impression,
+	   click,
+	   ecpm,
+	   income
+	</sql>
+	
+	<select id="findByParams"  parameterType="map" resultType="com.cloudcross.ssp.model.TypeReport">
+	    select 
+	    a.id,device,100*(sum(impression)/(select sum(impression) from t_rpt_zone_device a, t_operator b
+		where a.operator_id=b.id 
+		<if test="operatorId!=null">
+		    and a.operator_id=#{operatorId}
+		</if> 
+		   )) as pageviewsPercent,
+		sum(pv) as pv,sum(uv) as uv,sum(impression) as impression,100*(sum(impression)/sum(pv)) as fillRate,
+        sum(click) as click,100*(sum(click)/sum(impression)) as clickRate,sum(ecpm) as ecpm,sum(income) as income
+		from t_rpt_zone_device a, t_operator b
+		where a.operator_id=b.id 
+		<if test="operatorId!=null">
+		    and a.operator_id=#{operatorId}
+		</if>
+		group by device
+		order by id asc 
+		limit #{pager.offset}, #{pager.limit}    
+	</select>
+	
+	<select id="countByParams" parameterType="map" resultType="int">
+	    select count(a.id)
+	    from t_rpt_zone_device a, t_operator b
+		where a.operator_id=b.id 
+		<if test="operatorId!=null">
+		    and a.operator_id=#{operatorId}
+		</if>
+	</select>
+	
+
+</mapper>

+ 25 - 0
src/main/java/com/cloudcross/ssp/model/mapper/user-group.sql.xml

@@ -0,0 +1,25 @@
+<?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="userGroupSqlMapper">
+	
+	<sql id="base_column">
+		account_id as id,
+		account_type as userGroupType,
+		account_name as userGroup,
+		active as status
+	</sql>
+	
+	<insert id="addUserGroup" parameterType="com.cloudcross.ssp.model.UserGroup" useGeneratedKeys="true"
+		keyProperty="id">
+		insert into rv_accounts(account_type,account_name) values(#{userGroupType},#{userGroup});
+	</insert>
+	
+	<select id="findUserGroupById" parameterType="long" resultType="com.cloudcross.ssp.model.UserGroup">
+	    select
+	    <include refid="base_column" />
+	    from rv_accounts
+	    <where>
+	    	account_id = #{id}
+	    </where>
+	</select>
+</mapper>

+ 123 - 0
src/main/java/com/cloudcross/ssp/model/mapper/user.sql.xml

@@ -0,0 +1,123 @@
+<?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="userSqlMapper">
+	
+	<sql id="base_column">
+		user_id as id,
+		email_address as email,
+		username,
+		password,
+		default_account_id as userGroupId,
+		contact_name as contactName,
+		contact_phone as phone,
+		active as status,
+		date_created as createDate,
+		updated as modifyDate
+	</sql>
+	
+	<select id="selectByUsername"  parameterType="string" resultType="com.cloudcross.ssp.model.User">
+		select 
+		<include refid="base_column" />
+		from rv_users
+		<where>
+			username = #{username}
+		</where>
+		order by user_id  desc
+	</select>
+	
+	<select id="selectById" parameterType="int" resultType="com.cloudcross.ssp.model.User">
+		select 
+		<include refid="base_column" />
+		from rv_users
+		<where>
+			user_id = #{id} and
+			active != -1
+		</where>
+	</select>
+	
+	<select id="selectByUserGroupType" parameterType="string" resultType="com.cloudcross.ssp.model.User">
+		select
+		<include refid="base_column" />
+		from rv_users
+		<where>
+			exists(select account_id from rv_accounts where account_type=#{userGroupType} and
+			account_id=default_account_id) and
+			active != -1
+		</where>
+	</select>
+	
+	<select id="selectByParams"  parameterType="map" resultType="com.cloudcross.ssp.model.User">
+		select 
+		<include refid="base_column" />
+		from rv_users where active != -1
+		<if test="key!=null and value!=null">
+			<choose>
+				<when test="key=='username'">
+					and username like #{value}
+				</when>
+				<when test="key=='contactName'">
+					and contact_name like #{value}
+				</when>
+			</choose>	
+		</if>
+		<if test="userGroupType!=null">
+			and exists(
+				select account_id from rv_accounts 
+					where account_id=default_account_id and 
+					account_type=#{userGroupType})
+		</if>
+		order by  user_id   desc
+		limit #{pager.offset}, #{pager.limit}
+	</select>
+	
+	<select id="countByParams" parameterType="map" resultType="int">
+		select count(user_id)
+		from rv_users where active != -1
+		<if test="key!=null and value!=null">
+			<choose>
+				<when test="key=='username'">
+					and username like #{value}
+				</when>
+				<when test="key=='contactName'">
+					and contact_name like #{value}
+				</when>
+			</choose>	
+		</if>
+		<if test="userGroupType!=null">
+			and exists(
+				select account_id from rv_accounts 
+					where account_id=default_account_id and 
+					account_type=#{userGroupType})
+		</if>
+	</select>
+	
+	<insert id="addUser" parameterType="com.cloudcross.ssp.model.User">
+		insert into rv_users(username,password,contact_name,contact_phone,active,default_account_id,updated,date_created)
+		values(#{username},#{password},#{contactName},#{phone},#{status},#{userGroupId}, #{createDate},#{createDate})
+	</insert>
+	
+	<update id="editUser" parameterType="com.cloudcross.ssp.model.User">
+		update rv_users 
+		set username=#{username},
+		<if test="password !=null ">
+			password=#{password},
+		</if>
+			contact_name=IFNULL(#{contactName},default(contact_name)),
+			contact_phone=IFNULL(#{phone},default(contact_phone)),
+		  <if test="status !=null">
+			active=#{status},
+			</if>
+			updated=#{modifyDate} 
+		where user_id=#{id}
+	</update>
+	
+	<update id="updateUserStatus" parameterType="HashMap">
+		update rv_users 
+			set active = #{status},updated = #{modifyDate}
+			where user_id in
+			<foreach item="userId" collection="userIdList"
+		      open="(" separator="," close=")">
+		        #{userId}
+			</foreach>
+	</update>
+</mapper>

+ 46 - 0
src/main/java/com/cloudcross/ssp/model/mapper/userLogin.sql.xml

@@ -0,0 +1,46 @@
+<?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="userLoginSqlMapper">
+
+<!--mybatis ehcache缓存配置  -->
+<!-- 以下两个<cache>标签二选一,第一个可以输出日志,第二个不输出日志 
+<cache type="org.mybatis.caches.ehcache.LoggingEhcache" />-->
+<!-- <cache type="org.mybatis.caches.ehcache.EhcacheCache"/> -->
+	<!-- 以下与实体类的中字段一致 -->
+	<sql id="selectId">
+		loginId,
+		userId,
+		userName,
+		loginTime,
+		loginIP
+	</sql>
+	
+	<!--resultType="Account" 每返回一条结果封装到Account里 -->
+	<select id="query" resultType="com.cloudcross.ssp.model.UserLogin" parameterType="java.util.HashMap">
+		select
+		<include refid="selectId" />
+		from t_userloginlist where 1=1
+		
+	</select>
+	
+	<select id="getById" resultType="com.cloudcross.ssp.model.UserLogin" parameterType="String">
+		select
+		loginId,
+		userId,
+		userName,
+		max(loginTime) as loginTime,
+		loginIP
+		from t_userloginlist where 1=1
+		and t_userloginlist.userId = #{id}
+	</select>
+	<!-- 增加用户 -->
+	<insert id="add" parameterType="com.cloudcross.ssp.model.UserLogin">
+		insert into t_userloginlist ( userId,userName,
+		loginIP)
+		values (#{userId},#{userName},
+		#{loginIP})
+	</insert>
+
+	
+</mapper>

+ 213 - 0
src/main/java/com/cloudcross/ssp/model/mapper/wifi.sql.xml

@@ -0,0 +1,213 @@
+<?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="wifiSqlMapper">
+	<sql id="base_column">
+		t_wifi.id as id,
+		t_wifi.name as name,
+		t_wifi.SSID as SSID,
+		t_wifi.location as location,
+		t_wifi.apmac as apmac,
+		t_wifi.address as address,
+		t_wifi.longitude as longitude,
+		t_wifi.latitude as latitude,
+		t_wifi.place as place,
+		t_wifi.place_id as placeId,
+		t_wifi.operator_id as operatorId,
+		t_wifi.status as status,
+		t_wifi.updated as updated
+	</sql>
+	
+	<sql id="base_column2">
+		id,
+		location,
+		address,
+		longitude,
+		latitude
+	</sql>
+	
+	<select id="countByParams" parameterType="map" resultType="int">
+		select count(w.id) from t_wifi w, t_location l
+		<where>
+			w.location = l.location and w.status != -1 and w.operator_id = #{operatorId}
+			<if test="cn != null">
+				and l.cn = #{cn}
+			</if> 
+			<if test="cnCity != null">
+				and l.cn_city = #{cnCity}
+			</if>
+			<if test="placeId != null">
+				and w.place_id = #{placeId}
+			</if>
+			<if test="place != null">
+				and w.place = #{place}
+			</if>
+			<if test="searchValue != null">
+				and (w.address like #{searchValue} or w.name like #{searchValue})
+			</if>
+		</where> 
+	</select>
+	
+	<select id="findByParams" parameterType="map" resultType="com.cloudcross.ssp.model.Wifi">
+		select 
+		<include refid="base_column" />, t_location.cn as cn, t_location.cn_city as cnCity, t_place.name as placeName
+		from t_wifi, t_location, t_place
+		<where>
+			t_wifi.location = t_location.location and t_wifi.place_id = t_place.id
+			and t_wifi.status != -1 and t_wifi.operator_id = #{operatorId}
+			<if test="cn != null">
+				and t_location.cn = #{cn}
+			</if> 
+			<if test="cnCity != null">
+				and t_location.cn_city = #{cnCity}
+			</if>
+			<if test="placeId != null">
+				and t_wifi.place_id = #{placeId}
+			</if>
+			<if test="place != null">
+				and t_wifi.place = #{place}
+			</if>
+			<if test="searchValue != null">
+				and (t_wifi.address like #{searchValue} or t_wifi.name like #{searchValue})
+			</if>
+		</where> 
+		limit #{pager.offset}, #{pager.limit}
+	</select>
+	
+	<select id="findByParams1" parameterType="map" resultType="com.cloudcross.ssp.model.Wifi">
+		select 
+		<include refid="base_column" />, t_location.cn as cn, t_location.cn_city as cnCity, t_place.name as placeName
+		from t_wifi, t_location, t_place
+		<where>
+			t_wifi.location = t_location.location and t_wifi.place_id = t_place.id
+			and t_wifi.status != -1 and t_wifi.operator_id = #{operatorId}
+			<if test="cn != null">
+				and t_location.cn = #{cn}
+			</if> 
+			<if test="cnCity != null">
+				and t_location.cn_city = #{cnCity}
+			</if>
+			<if test="placeId != null">
+				and t_wifi.place_id = #{placeId}
+			</if>
+			<if test="place != null">
+				and t_wifi.place = #{place}
+			</if>
+			<if test="searchValue != null">
+				and (t_wifi.address like #{searchValue} or t_wifi.name like #{searchValue})
+			</if>
+		</where> 
+	</select>
+	
+	
+	<select id="findById" parameterType="long" resultType="com.cloudcross.ssp.model.Wifi">
+		select 
+		<include refid="base_column" />, t_location.cn as cn, t_location.cn_city as cnCity, t_place.name as placeName
+		from t_wifi, t_location, t_place
+		<where>
+			t_wifi.location = t_location.location and t_wifi.place_id = t_place.id
+			and t_wifi.status != -1 and t_wifi.id = #{id}
+		</where>
+	</select>
+	
+	<update id="updateWifiStatus" parameterType="HashMap">
+		update t_wifi
+		set status=#{status},updated = #{updated}
+		where id in
+		<foreach item="id" collection="idList" open="(" separator=","
+			close=")">
+			#{id}
+		</foreach>
+	</update>
+	
+	<update id="editWifi" parameterType="com.cloudcross.ssp.model.Wifi">
+		update t_wifi set name = #{name},
+		location = #{location},
+		address = #{address},
+		longitude = #{longitude},
+		latitude = #{latitude},
+		apmac = #{apmac},
+		place = #{place},
+		place_id = #{placeId}
+		where id = #{id}
+	</update>
+	
+	<insert id="add" parameterType="com.cloudcross.ssp.model.Wifi" useGeneratedKeys="true" keyProperty="id">
+		insert into t_wifi(name, SSID, location, apmac, address, longitude, latitude, place, place_id, operator_id, updated)
+		values(#{name}, #{SSID}, #{location}, #{apmac}, #{address}, #{longitude}, #{latitude}, #{place}, #{placeId}, #{operatorId}, #{updated})
+	</insert>
+	
+
+	<select id="findAddressAdvertiser" parameterType="map" resultType="com.cloudcross.ssp.advertiser.model.Wifi">
+       select 
+		<include refid="base_column2" />
+		from t_wifi where 1 = 1
+		<if test="key!=null and value!=null">
+			<choose>
+				<when test="key=='address'">
+					and address like #{value}
+				</when>
+			</choose>	
+		</if>
+		order by  id				
+	</select>
+	
+  	<select id="findWifiAdvertiser" parameterType="map" resultType="com.cloudcross.ssp.advertiser.model.Wifi">
+       select 
+       <include refid="base_column2" />
+       from t_wifi where location in (select location from t_wifi where location = #{location})
+       and latitude &lt;= #{maxlat} and latitude &gt;= #{minlat} 
+       and longitude &lt;= #{maxlng}	and longitude &gt;= #{minlng}			
+	</select>
+	
+	<select id="findLocationAdvertiser" parameterType="String" resultType="com.cloudcross.ssp.advertiser.model.Wifi">
+       select 
+       <include refid="base_column2" />
+       from t_wifi where location = #{location}			
+	</select>
+	
+	<select id="findAllAdgroupWifiAdvertiser" parameterType="Long" resultType="com.cloudcross.ssp.advertiser.model.Wifi">
+       select 
+       <include refid="base_column2" />
+       from t_wifi where id in (select wifi_id from t_adgroup_wifi where adgroup_id = #{adGroupId})
+       order by id		
+	</select>
+	
+	
+	<insert id="addAdgroupWifiAdvertiser" parameterType="map">
+		insert into
+		t_adgroup_wifi (adgroup_id,wifi_id)
+		values (#{adGroupId},#{wifiId})
+	</insert>
+	
+	<delete id="deleteAdgroupWifiAdvertiser" parameterType="long"> 
+	delete from t_adgroup_wifi where adgroup_id = #{adGroupId} 
+	</delete>
+	
+	<select id="selectByParamsAdvertiser"  parameterType="map" resultType="com.cloudcross.ssp.advertiser.model.Wifi">
+		select 
+		<include refid="base_column2" />
+		from t_wifi where 1 = 1
+		<if test="key!=null and value!=null">
+			<choose>
+				<when test="key=='address'">
+					and address like #{value}
+				</when>
+			</choose>	
+		</if>
+		order by  id
+		limit #{pager.offset}, #{pager.limit}
+	</select>
+	
+	<select id="countByParamsAdvertiser" parameterType="map" resultType="int">
+		select count(id)
+		from t_wifi where 1 = 1
+		<if test="key!=null and value!=null">
+			<choose>
+				<when test="key=='address'">
+					and address like #{value}
+				</when>
+			</choose>	
+		</if>
+	</select>
+	
+</mapper>

+ 34 - 0
src/main/java/com/cloudcross/ssp/model/mapper/zone-domain.sql.xml

@@ -0,0 +1,34 @@
+<?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="zoneDomainSqlMapper">
+	<sql id="base_column">
+		id,zone_id as zoneId,domain,status
+	</sql>
+
+	<insert id="addZoneDomain" parameterType="com.cloudcross.ssp.model.ZoneDomain" >
+		insert into t_zone_domain(zone_id ,domain,supdated,status)
+		values(#{zoneId},#{domain},#{supdated},#{status})
+	</insert>
+	
+	
+	<select id="findAllDomain" parameterType="long" resultType="com.cloudcross.ssp.model.ZoneDomain">
+		select <include refid="base_column"/> from t_zone_domain where zone_id = #{zoneId} and t_zone_domain.status = 0
+	</select>
+	
+	<update id="deleteZoneDomain" parameterType="com.cloudcross.ssp.operator.model.Zone">
+		update t_zone_domain set status=-1,supdated=#{supdated} where zone_id = #{id}
+	</update>
+	
+	<update id="editZoneDomain" parameterType="com.cloudcross.ssp.model.ZoneDomain">
+		update t_zone_domain set  domain=#{domain} where zone_id = #{zone_id}
+	</update>
+	
+	<select id="selectById"  parameterType="int" resultType="com.cloudcross.ssp.model.ZoneDomain">
+		select <include refid="base_column" /> from t_zone_domain 
+	<where> zone_id = #{id} 
+		and
+		t_zone_domain.status = 0
+	</where>
+	</select>
+	
+</mapper>

+ 29 - 0
src/main/java/com/cloudcross/ssp/model/mapper/zone-industry.sql.xml

@@ -0,0 +1,29 @@
+<?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="zoneIndustrySqlMapper">
+	<sql id="base_column">
+		id,zone_id as zoneId,industry_id as industryId,status,supdated
+	</sql>
+
+	<insert id="addZoneIndustry" parameterType="com.cloudcross.ssp.model.ZoneIndustry">
+		insert into t_zone_industry (zone_id,industry_id,supdated,status)
+		values (#{zoneId},#{industryId},#{supdated},#{status})
+	</insert>
+	
+	<select id="findAll" parameterType="long" resultType="com.cloudcross.ssp.model.ZoneIndustry">
+		select <include refid="base_column"/> from t_zone_industry where zone_id = #{zoneId} and t_zone_industry.status = 0
+	</select>
+	
+	<update id="editZoneIndustry" parameterType="com.cloudcross.ssp.model.ZoneIndustry">
+		update t_zone_industry
+		set  zone_id=#{zoneId},industry_id=#{industryId},status=0;
+		where zone_id = #{zoneId}
+			
+	</update>
+	<update id="deleteZoneIndustry" parameterType="com.cloudcross.ssp.model.Zone">
+		
+		update t_zone_industry
+		set status=-1,supdated=#{supdated} 
+		where zone_id = #{id}
+	</update>	
+</mapper>

+ 216 - 0
src/main/java/com/cloudcross/ssp/model/mapper/zone.sql.xml

@@ -0,0 +1,216 @@
+<?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="zoneSqlMapper">
+	
+	<sql id="base_column">
+		t_zone.id as id,
+		operator_id ,
+		t_zone.name as name,
+		width,
+		height,
+		device,
+		position,
+		status,
+		updated,
+		supdated,
+		default_path,
+		default_url,
+		recheck,
+		default_path_small
+	</sql>	
+	<select id="findZone" parameterType="int" resultType="com.cloudcross.ssp.model.Zone">
+		select * from t_zone where id=#{zoneId}
+	</select>
+	
+	 <select id="selectById"  parameterType="int" resultType="com.cloudcross.ssp.model.Zone">
+		select *
+		from t_zone 
+		<where>
+			t_zone.id = #{id}
+		</where>
+		order by t_zone.id  desc
+	</select> 		
+	<select id="findByName"  parameterType="string" resultType="long">
+		select t_zone.id from t_zone 
+	<where> name = #{name} </where>
+	</select>
+	<resultMap id="zoneResult" type="com.cloudcross.ssp.model.Zone">
+		<id property="id" column="id" />
+		<result property="operator_id" column="operator_id" />
+		<result property="name" column="name" />
+		<result property="width" column="width" />
+		<result property="height" column="height" />
+		<result property="device" column="device" />
+		<result property="position" column="position" />
+		<result property="status" column="status" />
+		<result property="updated" column="updated" />
+		<result property="supdated" column="supdated" />
+	</resultMap> 
+	
+	<select id="selectByParams"  parameterType="map" resultMap="zoneResult">
+		select 
+		<include refid="base_column" />
+		from t_zone 
+		where t_zone.status != -1
+		
+		<if test="key!=null and value!=null">
+			<choose>
+				<when test="key=='name'">
+					and t_zone.name like #{value}
+				</when>
+				<when test="key=='id'">
+					and t_zone.id like #{value}
+				</when>
+			</choose>	
+		</if>
+		<if test="status != null">
+				and status like #{status}
+		</if>		
+		<if test="device != null">
+				and device like #{device}
+		</if>
+		<if test="position != null">
+				and position like #{position}
+		</if>	
+		<if test="height != null">
+				and height like #{height}
+		</if>
+		<if test="width != null">
+				and width like #{width}
+		</if>
+		<if test="operatorId != null">
+				and operator_id = #{operatorId}
+		</if>	
+		
+		order by  t_zone.id   desc
+		limit #{pager.offset}, #{pager.limit}
+	</select>		
+	<select id="countByParams" parameterType="map" resultType="int">
+		select count(t_zone.id)
+		from t_zone 
+		where t_zone.status != -1	
+		
+			 <if test="key!=null and value!=null">
+			<choose>
+				<when test="key=='id'">
+					and t_zone.id like #{value}
+				</when>
+				<when test="key=='name'">
+					and t_zone.name = #{value}
+				</when>
+			</choose>	
+		</if>
+		<if test="status != null">
+				and status like #{status}
+		</if>		
+		<if test="device != null">
+				and device like #{device}
+		</if>	
+		<if test="position != null">
+				and position like #{position}
+		</if>
+		<if test="height != null">
+				and height like #{height}
+		</if>
+		<if test="width != null">
+				and width like #{width}
+		</if>
+		<if test="operatorId != null">
+				and operator_id = #{operatorId}
+		</if>	
+	</select>
+		
+	<insert id="addZone" parameterType="com.cloudcross.ssp.model.Zone" useGeneratedKeys="true"
+		keyProperty="id">
+		insert into t_zone(operator_id,name,device,position,width,height,recheck,updated,supdated,default_path,default_url,default_path_small)
+		values(#{operator_id},#{name},#{device},#{position},#{width},#{height},#{recheck},#{updated},#{supdated},#{default_path},#{default_url},#{default_path_small})
+		
+	
+	</insert>
+	
+	<update id="editZone" parameterType="com.cloudcross.ssp.model.Zone">
+		update t_zone 
+		set  name=#{name},device=#{device},position=#{position}, width=#{width}, height=#{height},default_path=#{default_path},default_path_small=#{default_path_small},default_url=#{default_url},recheck=#{recheck},updated=#{updated},supdated=#{supdated}
+		where id = #{id}
+			
+	</update>
+	
+	<update id="updateZoneStatus" parameterType="HashMap">
+		update t_zone
+			set status = #{status},updated = #{updated}
+			where id in
+			<foreach item="id" collection="zoneIdList"
+		      open="(" separator="," close=")">
+		        #{id}
+			</foreach>
+	</update>
+
+	<delete id="deleteById" parameterType="int">
+		delete 
+		from t_zone
+		<where>
+		id = #{id} 
+		</where>
+	</delete>
+	
+	
+	
+	
+	<!-- 
+	<select id="findByDeviceAndPlaceId" parameterType="map" resultType="zone">
+		select t_zone.id,t_zone.name
+		 from t_zone 
+		 <where>
+		 	<if test="zoneDevice != null">
+		 		1=1 and t_zone.device = #{zoneDevice}
+		 	</if>
+		 	<if test="zonePlaceIdList != null">
+		 		and t_zone.id in (
+		 		select t_zone_place.zone_id from t_zone_place where place_id in
+		 		<foreach item="placeId" collection="zonePlaceIdList"  open="(" separator="," close=")">
+		 			#{placeId}
+		 		</foreach>
+		 		)
+		 	</if>
+		 </where>
+	</select>
+	 -->
+	<!-- 广告位排期按在投广告位ID和日期查找 -->
+	
+     <select id="findAdgroupNameByZoneIdAndSchedule" resultType="string" parameterType="map">
+       select t.name from t_adgroup t 
+       where 
+       t.id in (select az.adgroup_id from t_adgroup_zone az where az.zone_id = #{zoneId}) 
+       and
+       t.id in (select ac.adgroup_id from t_adgroup_schedule ac where ac.startdate &lt;= #{date}  and #{date} &lt;= ac.enddate)
+     </select>
+	
+	<!-- 首页中查找设备,暂时只有PC和MoBile -->
+     <select id="findByDevice" resultType="com.cloudcross.ssp.model.Zone" parameterType="int">
+           select id,name from t_zone
+         <where> device = #{device} </where>
+           order by t_zone.id desc 
+      </select>
+      
+      <!-- add by Wanfu for banner-audit -->
+      <select id="findByOperatorId" resultType="com.cloudcross.ssp.model.Zone" parameterType="int">
+           select * from t_zone where operator_id = #{operatorId} and recheck = 1 and status=0
+      </select>
+      
+	
+ <select id="selectByIdBack"  parameterType="long" resultType="com.cloudcross.ssp.model.Zone">
+		select <include refid="base_column" />
+		from t_zone 
+		<where>
+			t_zone.id = #{id}
+		</where>
+		order by t_zone.id  desc
+	</select> 	
+	
+	<select id="findByOperatorIdBack" resultType="com.cloudcross.ssp.model.Zone" parameterType="long">
+           select <include refid="base_column" /> 
+           from t_zone where operator_id = #{operatorId}
+      </select>
+      
+      
+</mapper>

+ 0 - 23
src/test/java/com/cloudcross/ssp/service/IOperatorBalanceServiceTest.java

@@ -1,23 +0,0 @@
-package com.cloudcross.ssp.service;
-
-import static org.junit.Assert.*;
-
-import org.junit.Test;
-import org.springframework.beans.factory.annotation.Autowired;
-
-import com.cloudcross.ssp.SpringTestCase;
-import com.cloudcross.ssp.common.utils.LangUtil;
-
-
-public class IOperatorBalanceServiceTest extends SpringTestCase {
-	
-	@Autowired
-	private IOperatorBalanceService operatorBalanceService;
-	@Test
-	public void test() {
-		Long[] id = new Long[]{1l,2l,3l};
-		String reason = "审核不通过原因";
-		operatorBalanceService.moneyBackToOperator(12l);
-	}
-
-}