Browse Source

增加type字段

fan.yang@cloudcross.com 9 years ago
parent
commit
d6cf3f2437

+ 471 - 470
src/main/java/com/cloudcross/ssp/model/mapper/account.sql.xml

@@ -1,471 +1,472 @@
-<?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="selectByParamsOperator"  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="selectByParamsAdvertiser"  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="countByParamsOperator" 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="countByParamsAdvertiser" 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="addAccountOperator" 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="addAccountAdvertiser" parameterType="com.cloudcross.ssp.model.Account" useGeneratedKeys="true" keyProperty="id">
-		insert into t_account
-		 (name,
-		 password,
-		 real_name,
-		 tel,
-		 agent_id,
-		 advertiser_id,
-		 operator_id,
-		 description, 
-		 state,
-		 sys_type ) values (#{accountName}, #{password},#{realName}, 
-    	#{tel},#{agentId},#{advertiserId},#{operatorId},#{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="editAccountOperator" 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="editAccountAdvertiser" 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 != ''">
-				create_time=#{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>
-
-	<!-- 验证用户登陆 -->
-	<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="findExcelAccountsOperator"  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="findExcelAccountsAdvertiser"  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>
+<?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="selectByParamsOperator"  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="selectByParamsAdvertiser"  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="countByParamsOperator" 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="countByParamsAdvertiser" 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,
+		 type) values (#{accountName}, #{password},#{realName}, 
+    	#{tel},#{description},#{state},#{sysType},#{type}) 
+	</insert>
+
+
+	<!-- 增加用户 -->
+	<insert id="addAccountOperator" 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="addAccountAdvertiser" parameterType="com.cloudcross.ssp.model.Account" useGeneratedKeys="true" keyProperty="id">
+		insert into t_account
+		 (name,
+		 password,
+		 real_name,
+		 tel,
+		 agent_id,
+		 advertiser_id,
+		 operator_id,
+		 description, 
+		 state,
+		 sys_type ) values (#{accountName}, #{password},#{realName}, 
+    	#{tel},#{agentId},#{advertiserId},#{operatorId},#{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="editAccountOperator" 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="editAccountAdvertiser" 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 != ''">
+				create_time=#{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>
+
+	<!-- 验证用户登陆 -->
+	<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="findExcelAccountsOperator"  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="findExcelAccountsAdvertiser"  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>

+ 538 - 538
src/main/java/com/cloudcross/ssp/web/back/main/ClientAccountController.java

@@ -1,538 +1,538 @@
-package com.cloudcross.ssp.web.back.main;
-
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.commons.lang.ArrayUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Controller;
-import org.springframework.ui.Model;
-import org.springframework.web.bind.annotation.ModelAttribute;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.ResponseBody;
-
-import com.cloudcross.ssp.model.Account;
-import com.cloudcross.ssp.model.AdvAgent;
-import com.cloudcross.ssp.model.ClientAccount;
-import com.cloudcross.ssp.model.Correlation;
-import com.cloudcross.ssp.model.Operator;
-import com.cloudcross.ssp.model.RoleAccount;
-import com.cloudcross.ssp.model.UserLogin;
-import com.cloudcross.ssp.service.IAccountService;
-import com.cloudcross.ssp.service.IAdvAgentService;
-import com.cloudcross.ssp.service.IClientAccountService;
-import com.cloudcross.ssp.service.ICorrelationService;
-import com.cloudcross.ssp.service.IOperatorService;
-import com.cloudcross.ssp.service.IRolesService;
-import com.cloudcross.ssp.service.IUserLoginService;
-import com.cloudcross.ssp.base.utils.freemarker.FreemarkerTemplateProcessor;
-import com.cloudcross.ssp.base.web.SimpleController;
-import com.cloudcross.ssp.common.consts.Status;
-import com.cloudcross.ssp.common.utils.LangUtil;
-import com.cloudcross.ssp.common.utils.Md5Tool;
-import com.cloudcross.ssp.common.utils.Pager;
-@Controller
-@RequestMapping("/back/main/client-account")
-public class ClientAccountController extends SimpleController{
-	
-	@Autowired
-	protected IClientAccountService clientAccountService;
-	@Autowired
-	protected IAccountService accountService;
-	@Autowired
-	protected IUserLoginService userLogin;
-	@Autowired
-	protected IOperatorService operatorService;
-	@Autowired
-	protected IAdvAgentService advAgentService;
-	@Autowired
-	private FreemarkerTemplateProcessor templateProcessor;
-	@Autowired
-	protected IRolesService roleService;
-	@Autowired
-	protected ICorrelationService correlationService;
-	@RequestMapping()
-	public String index(){
-		return redirect(page("list"));
-	}
-	
-	@RequestMapping("list")
-	public String list(Model model,
-				@RequestParam HashMap<String, Object> paramMap,
-				@RequestParam(defaultValue="1") int page,
-				@RequestParam(defaultValue="0") Long sysType){
-		
-		if (sysType!=null && sysType!=0) {
-			paramMap.put("sysType", sysType);
-		}
-		int totalRow = clientAccountService.countByParams(paramMap);
-//		System.out.println("黑喂狗"+totalRow);
-		Pager pager = new Pager();
-		pager.setPage(page);
-		pager.setTotalRow(totalRow);
-		List<ClientAccount> clientAccountsList = clientAccountService.findByParams(paramMap, pager);
-		//循环得到每个客户账号的最后登录时间!
-		for (ClientAccount ca : clientAccountsList)
-		{
-			 Long userId = ca.getId();
-			 UserLogin ul = userLogin.getById(userId.toString());
-			 if (ul == null) {//要防止创建的账号从未登录过系统
-				 Account account = accountService.getById(userId.toString());
-				 ca.setLoginTime(account.getCreateTime());
-				 continue;
-			}
-			 ca.setLoginTime(ul.getLoginTime());
-		}
-		model.addAttribute("pager",pager);
-		model.addAttribute("sysType",sysType);
-		model.addAllAttributes(paramMap);
-		model.addAttribute("clientAccountsList", clientAccountsList);
-		return page("list");
-	}
-	
-	@RequestMapping("/create")
-	public String create(){
-		
-		return page("create");
-	}
-	
-	@RequestMapping("/edit")
-	public String edit(Model model,
-				@RequestParam Long accountId){
-		ClientAccount clientAccount = null;
-		Account account = accountService.getById(accountId.toString());
-		if(account.getAgentId()!=0 && account.getSysType()==3){
-			//是代理商账号的编辑
-			AdvAgent advAgent = advAgentService.findById(account.getAgentId());
-			//把accout 和 advAgent封装成clientAccount对象
-			clientAccount = new ClientAccount();
-			clientAccount.setId(new Long(account.getId()));
-			clientAccount.setAccountName(account.getAccountName());
-			clientAccount.setPassword(account.getPassword());
-			clientAccount.setLinkMan(advAgent.getContacts());
-			clientAccount.setMobilePhone(advAgent.getMobile());
-			clientAccount.setTel(advAgent.getTel());
-			clientAccount.setCompanyName(advAgent.getName());
-			clientAccount.setHomePage(advAgent.getHomePage());
-			clientAccount.setAddress(advAgent.getAddress());
-			clientAccount.setZip(advAgent.getZip());
-			clientAccount.setEmail(advAgent.getEmail());
-			clientAccount.setTitle(advAgent.getTitle());
-			clientAccount.setStatus(Integer.parseInt(account.getState()));
-			clientAccount.setSysType(account.getSysType());
-			clientAccount.setBank("");
-			clientAccount.setBankAccount("");
-			clientAccount.setBankAccountName("");
-			clientAccount.setAgentId(account.getAgentId());
-			clientAccount.setOperatorId(account.getOperatorId());
-		}
-		if(account.getOperatorId()!=0 && account.getSysType()==2){
-			//是媒体账号的编辑
-			Operator operator = operatorService.findById(account.getOperatorId());
-			//把accout 和 operator封装成clientAccount对象
-			clientAccount = new ClientAccount();
-			clientAccount.setId(new Long(account.getId()));
-			clientAccount.setAccountName(account.getAccountName());
-			clientAccount.setPassword(account.getPassword());
-			clientAccount.setLinkMan(operator.getLinkMan());
-			clientAccount.setMobilePhone(operator.getMobile());
-			clientAccount.setTel(operator.getTel());
-			clientAccount.setCompanyName(operator.getCompanyName());
-			clientAccount.setHomePage(operator.getHomePage());
-			clientAccount.setAddress(operator.getAddress());
-			clientAccount.setEmail(operator.getEmail());
-			clientAccount.setZip(operator.getZip());
-			clientAccount.setBank(operator.getBank());
-			clientAccount.setBankAccount(operator.getAccount());
-			clientAccount.setBankAccountName(operator.getAccountName());
-			clientAccount.setStatus(Integer.parseInt(account.getState()));
-			clientAccount.setSysType(account.getSysType());
-			clientAccount.setTitle("");
-			clientAccount.setAgentId(account.getAgentId());
-			clientAccount.setOperatorId(account.getOperatorId());
-		}
-		System.out.println("ggggg"+clientAccount);
-		model.addAttribute("clientAccount",clientAccount);
-		return page("edit");
-	}
-	/**
-	 * 
-	 * @param ca
-	 * @param ensueensurePassword
-	 * @return
-	 */
-	@RequestMapping("/save")
-	public String save(@ModelAttribute("form") ClientAccount ca,
-			@RequestParam(value = "ensurePassword", defaultValue = "") String ensueensurePassword){
-		String password = ca.getPassword();
-		if(ca.getId()==null){//新增客户账号
-			//要先判断一下是插入的是operator还是agent
-			//要分两部分来做,一部分是t_account账号的插入,另一部分的插入是operator或者是agent的插入
-			//一个先插入,然后在插入另一个,查好了后还要编辑先插好的那个~~~~~好麻烦~!!
-			ca.setPassword(Md5Tool.getMd5(password));
-			//clientAccountService.add(ca);
-			if (ca.getSysType()==2) {
-				//2表示是媒体,3表示是代理商。
-				Operator o = new Operator();
-				o.setAccount(ca.getBankAccount());
-				o.setBank(ca.getBank());
-				o.setAccountName(ca.getBankAccountName());
-				o.setCompanyName(ca.getCompanyName());
-				o.setLinkMan(ca.getLinkMan());
-				o.setStatus(new Integer(0));
-				o.setTel(ca.getTel());
-				o.setMobile(ca.getMobilePhone());
-				o.setZip(ca.getZip());
-				o.setEmail(ca.getEmail());
-				o.setHomePage(ca.getHomePage());
-				o.setAddress(ca.getAddress());
-				
-				Account account = new Account();
-				account.setAccountName(ca.getAccountName());
-				account.setPassword(ca.getPassword());
-				account.setSysType(ca.getSysType());
-				account.setTel(ca.getTel());
-				account.setCreateTime(new Date());
-				account.setState(ca.getStatus().toString());
-				account.setRealName(ca.getLinkMan());
-				account.setType(new Integer(2));
-				account.setDescription(ca.getCompanyName());
-				accountService.addAccount(account);
-				Account account2 = accountService.querySingleAccount(account.getAccountName());
-				RoleAccount ra = new RoleAccount();//给客户账号分配媒体角色  角色ID=9
-				ra.setAccountId(account2.getId());
-				ra.setRoleId(9);
-				roleService.addAccRole(ra);
-				
-				o.setAdminId(new Long(account2.getId()));
-				operatorService.add(o);
-				Operator operatorNew = operatorService.getNew(o);
-				account2.setOperatorId(operatorNew.getId());
-				accountService.editAccount(account2);
-			}
-			if (ca.getSysType()==3) {
-				//插入的是代理商账号。
-				AdvAgent advAgent = new AdvAgent();
-				advAgent.setAddress(ca.getAddress());
-				advAgent.setContacts(ca.getLinkMan());
-				advAgent.setEmail(ca.getEmail());
-				advAgent.setHomePage(ca.getHomePage());
-				advAgent.setMobile(ca.getMobilePhone());
-				advAgent.setName(ca.getCompanyName());
-				advAgent.setStatus(new Integer(0));
-				advAgent.setTel(ca.getTel());
-				advAgent.setTitle(ca.getTitle());
-				advAgent.setZip(ca.getZip());
-				advAgent.setUpdated(new Date());
-				
-				Account account = new Account();
-				account.setAccountName(ca.getAccountName());
-				account.setPassword(ca.getPassword());
-				account.setSysType(ca.getSysType());
-				account.setTel(ca.getTel());
-				account.setCreateTime(new Date());
-				account.setState(ca.getStatus().toString());
-				account.setRealName(ca.getLinkMan());
-				account.setType(new Integer(2));
-				account.setDescription(ca.getCompanyName());
-				accountService.addAccount(account);
-				Account account2 = accountService.querySingleAccount(account.getAccountName());
-				RoleAccount ra = new RoleAccount();//给客户账号分配代理商角色 角色ID=7
-				ra.setAccountId(account2.getId());
-				ra.setRoleId(7);
-				roleService.addAccRole(ra);
-				
-				advAgent.setAdminId(new Long(account2.getId()));
-				advAgentService.add(advAgent);
-				AdvAgent advAgentNew = advAgentService.getNew(advAgent);
-				account2.setAgentId(advAgentNew.getId());
-				accountService.editAccount(account2);
-			}
-		}else{//x修改信息
-			//要先判断一下是插入的是operator还是agent
-			//要分两部分来做,一部分是t_account账号的插入,另一部分的插入是operator或者是agent的插入
-			//一个先插入,然后在插入另一个,查好了后还要编辑先插好的那个~~~~~好麻烦~!!
-			if(password != null){
-				ca.setPassword(Md5Tool.getMd5(password));
-			}
-			//clientAccountService.add(ca);
-			if (ca.getSysType()==2) {
-				//2表示是媒体,3表示是代理商。
-				Operator o = new Operator();
-				o.setId(ca.getOperatorId());
-				o.setAccount(ca.getBankAccount());
-				o.setBank(ca.getBank());
-				o.setAccountName(ca.getBankAccountName());
-				o.setCompanyName(ca.getCompanyName());
-				o.setLinkMan(ca.getLinkMan());
-				o.setStatus(new Integer(0));
-				o.setTel(ca.getTel());
-				o.setMobile(ca.getMobilePhone());
-				o.setZip(ca.getZip());
-				o.setEmail(ca.getEmail());
-				o.setHomePage(ca.getHomePage());
-				o.setAddress(ca.getAddress());
-				o.setAdminId(ca.getId());
-				
-				Account account = new Account();
-				account.setId(ca.getId().intValue());
-				account.setAccountName(ca.getAccountName());
-				if(password != null){
-					account.setPassword(ca.getPassword());
-				}
-//				account.setSysType(ca.getSysType());
-//				account.setTel(ca.getTel());
-//				account.setCreateTime(new Date());
-				account.setState(ca.getStatus().toString());
-//				account.setRealName(ca.getLinkMan());
-//				account.setType(new Integer(2));
-//				account.setOperatorId(ca.getOperatorId());
-				accountService.editAccount(account);
-				operatorService.edit(o);
-			}
-			if (ca.getSysType()==3) {
-				//插入的是代理商账号。
-				AdvAgent advAgent = new AdvAgent();
-				advAgent.setId(ca.getAgentId());
-				advAgent.setAddress(ca.getAddress());
-				advAgent.setContacts(ca.getLinkMan());
-				advAgent.setEmail(ca.getEmail());
-				advAgent.setHomePage(ca.getHomePage());
-				advAgent.setMobile(ca.getMobilePhone());
-				advAgent.setName(ca.getCompanyName());
-				advAgent.setStatus(ca.getStatus());
-				advAgent.setTel(ca.getTel());
-				advAgent.setTitle(ca.getTitle());
-				advAgent.setZip(ca.getZip());
-				advAgent.setUpdated(new Date());
-				advAgent.setAdminId(ca.getId());
-				Account account = new Account();
-				account.setId(ca.getId().intValue());
-				account.setAccountName(ca.getAccountName());
-				if(password != null){
-					account.setPassword(ca.getPassword());
-				}
-//				account.setSysType(ca.getSysType());
-//				account.setTel(ca.getTel());
-//				account.setCreateTime(new Date());
-				account.setState(ca.getStatus().toString());
-//				account.setRealName(ca.getLinkMan());
-//				account.setType(new Integer(2));
-//				account.setAgentId(ca.getAgentId());
-				accountService.editAccount(account);
-				advAgentService.edit(advAgent);
-			}
-		}
-		return redirect(page("list"));
-	}
-	
-	/**
-	 * 单个或者批量启用功能。
-	 * 后面要做登录检验的,如果是主账号登录直接检查是否被停用。
-	 * 
-	 * @return 成功则返回"ok"
-	 */
-	@RequestMapping("enable")
-	public @ResponseBody String enable(Long[] id) {
-//		LOG.debug("Args's value: id=" + Arrays.toString(id));
-		if (ArrayUtils.isNotEmpty(id)) {
-			for(int i = 0;i < id.length;i++){//依次找到对应客户端账号的更改对应的agent或者operator的状态!
-				Account account = accountService.getById(id[i].toString());
-				if(account.getAgentId()!=0 && account.getSysType()==3){
-					List<Long> l = new ArrayList<Long>();
-					l.add(account.getAgentId());
-					advAgentService.updateStatus(l, Status.enable.value);
-				}
-				if (account.getOperatorId()!=0 && account.getSysType()==2) {
-					List<Long> l = new ArrayList<Long>();
-					l.add(account.getOperatorId());
-					operatorService.updateStatusBack(l, Status.enable.value);
-				}
-			}
-		}
-		if (ArrayUtils.isNotEmpty(id)) {
-			accountService.updateState(LangUtil.array2List(id),
-					Status.disable.value);
-		}
-		return OK;
-	}
-
-	/**
-	 * 单个或者批量禁用功能。 
-	 * 
-	 * @return 成功则返回"ok"
-	 */
-	@RequestMapping("disable")
-	public @ResponseBody String disable(Long[] id) {
-//		LOG.debug("Args's value: id=" + Arrays.toString(id));\
-		if (ArrayUtils.isNotEmpty(id)) {
-			for(int i = 0;i < id.length;i++){//依次找到对应客户端账号的更改对应的agent或者operator的状态!
-				Account account = accountService.getById(id[i].toString());
-				if(account.getAgentId()!=0 && account.getSysType()==3){
-					List<Long> l = new ArrayList<Long>();
-					l.add(account.getAgentId());
-					advAgentService.updateStatus(l, Status.disable.value);
-				}
-				if (account.getOperatorId()!=0 && account.getSysType()==2) {
-					List<Long> l = new ArrayList<Long>();
-					l.add(account.getOperatorId());
-					operatorService.updateStatusBack(l, Status.disable.value);
-				}
-			}
-		}
-		if (ArrayUtils.isNotEmpty(id)) {
-			accountService.updateState(LangUtil.array2List(id),
-					Status.enable.value);
-		}
-		// 将来会被改updateState
-		return OK;
-	}
-	
-	@RequestMapping("isExist")
-	public @ResponseBody String isExist(Model model,
-			@RequestParam(defaultValue = "") String clientAccountName
-			) {
-		String success = "";
-		Account account = accountService.querySingleAccount(clientAccountName);
-//		System.err.println(account);
-		if(account!=null){
-			model.addAttribute("isExist", new Long(1));
-			success = "YES";
-//			System.out.println("yuanzhiq11111111");
-		}else {
-			model.addAttribute("isExist", new Long(0));
-			success = "NO";
-//			System.out.println("yuanzhiq0000000");
-		}
-		return success;
-	}
-	/**
-	 * 打开关联列表页
-	 * @param model
-	 * @return
-	 */
-	@RequestMapping("/correlation")
-	public String correlation(Model model,
-			@RequestParam(defaultValue="1") int page){
-		int totalRow = correlationService.countAllCorrelation();
-		Pager pager = new Pager();
-		pager.setPage(page);
-		pager.setTotalRow(totalRow);
-		List<Correlation> correlations = correlationService.findAllCorrelation(pager);
-		model.addAttribute("pager",pager);
-		model.addAttribute("correlations",correlations);
-		return page("correlation");
-	}
-	/**
-	 * 创建关联
-	 * @return
-	 */
-	@RequestMapping("createcorrelation")
-	public String createCorrelation(){
-		return page("createcorrelation");
-	}
-	/**
-	 * 取消关联
-	 * @return
-	 */
-	@RequestMapping("cancelcorrelation")
-	public String cancelCorrelation(@RequestParam Long agentId,
-			@RequestParam Long operatorId){
-		Correlation ca = new Correlation();
-		ca.setAgentId(agentId);
-		ca.setOperatorId(operatorId);
-		correlationService.deleteCorrelation(ca);
-		return redirect(page("correlation"));
-	}
-	/**
-	 * 保存关联
-	 * @return
-	 */
-	@RequestMapping("savecorrelation")
-	public String saveCorrelation(@ModelAttribute("form")Correlation ca){
-		correlationService.addCorrelation(ca);
-		return redirect(page("correlation"));
-	}
-	/**
-	 * 
-	 * 查询是否 存在关联
-	 * 
-	 * @author CloudCross
-	 */
-	@RequestMapping("is_exit")
-	public @ResponseBody String isExitCorrelation(@RequestParam Long operatorId){
-		List<Correlation>  co = correlationService.findCorrelationByOperatorId(operatorId);
-		if(co.size()>0){
-			return "YES";
-		}else {
-			return "NO";
-		}
-	}
-	
-	@RequestMapping("/exportDataReportExcel")
-	public void exportDataReportExcel(HttpServletRequest request,
-			HttpServletResponse response,
-			@RequestParam HashMap<String, Object> paramMap) {
-		/**
-		 * 参数和list里要一样
-		 */
-		if(paramMap.get("sysType")!=null){
-			Long sysType = Long.parseLong((String)paramMap.get("sysType"));
-			if (sysType!=0) {
-				paramMap.put("sysType", sysType);
-			}else {
-				paramMap.put("sysType",new Long(0));
-			}
-		}
-		Account loginAccount = getLoginUser();
-		paramMap.put("loginAccount", loginAccount);
-		List<ClientAccount> accountList = clientAccountService.findExcelAccounts(paramMap);
-		for (ClientAccount ca : accountList)
-		{
-			 Long userId = ca.getId();
-			 UserLogin ul = userLogin.getById(userId.toString());
-			 if (ul == null) {//要防止创建的账号从未登录过系统
-				 Account account = accountService.getById(userId.toString());
-				 ca.setLoginTime(account.getCreateTime());
-				 continue;
-			}
-			 ca.setLoginTime(ul.getLoginTime());
-		}
-		paramMap.put("dataList", accountList);
-		
-		response.reset();
-		// Content-Type:application/vnd.ms-excel;charset=utf8或者text/xml;charset=utf8
-		response.setContentType("application/vnd.ms-excel;charset=utf8");
-		// 设置excel文件名称
-		SimpleDateFormat df2 = new SimpleDateFormat("yyyyMMddHHmmss");
-		String fileName = "account" + df2.format(new Date());
-		response.setHeader("Content-Disposition", "attachment;filename="
-				+ fileName + ".xls");
-		// 需要对excel的列和行的总数进行指定
-		int column = 9;
-		paramMap.put("dataSize", (accountList.size() + 100));
-		paramMap.put("column", column);
-	
-		paramMap.put("accountList", "客户账号列表");
-		String excelTemplate = templateProcessor.processTemplate(
-				"excel/dataClientAccount.ftl", paramMap);
-		try {
-			PrintWriter out = response.getWriter();
-			out.write(excelTemplate);
-			out.flush();
-			out.close();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-	}
-}
+package com.cloudcross.ssp.web.back.main;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.lang.ArrayUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.ModelAttribute;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseBody;
+
+import com.cloudcross.ssp.model.Account;
+import com.cloudcross.ssp.model.AdvAgent;
+import com.cloudcross.ssp.model.ClientAccount;
+import com.cloudcross.ssp.model.Correlation;
+import com.cloudcross.ssp.model.Operator;
+import com.cloudcross.ssp.model.RoleAccount;
+import com.cloudcross.ssp.model.UserLogin;
+import com.cloudcross.ssp.service.IAccountService;
+import com.cloudcross.ssp.service.IAdvAgentService;
+import com.cloudcross.ssp.service.IClientAccountService;
+import com.cloudcross.ssp.service.ICorrelationService;
+import com.cloudcross.ssp.service.IOperatorService;
+import com.cloudcross.ssp.service.IRolesService;
+import com.cloudcross.ssp.service.IUserLoginService;
+import com.cloudcross.ssp.base.utils.freemarker.FreemarkerTemplateProcessor;
+import com.cloudcross.ssp.base.web.SimpleController;
+import com.cloudcross.ssp.common.consts.Status;
+import com.cloudcross.ssp.common.utils.LangUtil;
+import com.cloudcross.ssp.common.utils.Md5Tool;
+import com.cloudcross.ssp.common.utils.Pager;
+@Controller
+@RequestMapping("/back/main/client-account")
+public class ClientAccountController extends SimpleController{
+	
+	@Autowired
+	protected IClientAccountService clientAccountService;
+	@Autowired
+	protected IAccountService accountService;
+	@Autowired
+	protected IUserLoginService userLogin;
+	@Autowired
+	protected IOperatorService operatorService;
+	@Autowired
+	protected IAdvAgentService advAgentService;
+	@Autowired
+	private FreemarkerTemplateProcessor templateProcessor;
+	@Autowired
+	protected IRolesService roleService;
+	@Autowired
+	protected ICorrelationService correlationService;
+	@RequestMapping()
+	public String index(){
+		return redirect(page("list"));
+	}
+	
+	@RequestMapping("list")
+	public String list(Model model,
+				@RequestParam HashMap<String, Object> paramMap,
+				@RequestParam(defaultValue="1") int page,
+				@RequestParam(defaultValue="0") Long sysType){
+		
+		if (sysType!=null && sysType!=0) {
+			paramMap.put("sysType", sysType);
+		}
+		int totalRow = clientAccountService.countByParams(paramMap);
+//		System.out.println("黑喂狗"+totalRow);
+		Pager pager = new Pager();
+		pager.setPage(page);
+		pager.setTotalRow(totalRow);
+		List<ClientAccount> clientAccountsList = clientAccountService.findByParams(paramMap, pager);
+		//循环得到每个客户账号的最后登录时间!
+		for (ClientAccount ca : clientAccountsList)
+		{
+			 Long userId = ca.getId();
+			 UserLogin ul = userLogin.getById(userId.toString());
+			 if (ul == null) {//要防止创建的账号从未登录过系统
+				 Account account = accountService.getById(userId.toString());
+				 ca.setLoginTime(account.getCreateTime());
+				 continue;
+			}
+			 ca.setLoginTime(ul.getLoginTime());
+		}
+		model.addAttribute("pager",pager);
+		model.addAttribute("sysType",sysType);
+		model.addAllAttributes(paramMap);
+		model.addAttribute("clientAccountsList", clientAccountsList);
+		return page("list");
+	}
+	
+	@RequestMapping("/create")
+	public String create(){
+		
+		return page("create");
+	}
+	
+	@RequestMapping("/edit")
+	public String edit(Model model,
+				@RequestParam Long accountId){
+		ClientAccount clientAccount = null;
+		Account account = accountService.getById(accountId.toString());
+		if(account.getAgentId()!=0 && account.getSysType()==3){
+			//是代理商账号的编辑
+			AdvAgent advAgent = advAgentService.findById(account.getAgentId());
+			//把accout 和 advAgent封装成clientAccount对象
+			clientAccount = new ClientAccount();
+			clientAccount.setId(new Long(account.getId()));
+			clientAccount.setAccountName(account.getAccountName());
+			clientAccount.setPassword(account.getPassword());
+			clientAccount.setLinkMan(advAgent.getContacts());
+			clientAccount.setMobilePhone(advAgent.getMobile());
+			clientAccount.setTel(advAgent.getTel());
+			clientAccount.setCompanyName(advAgent.getName());
+			clientAccount.setHomePage(advAgent.getHomePage());
+			clientAccount.setAddress(advAgent.getAddress());
+			clientAccount.setZip(advAgent.getZip());
+			clientAccount.setEmail(advAgent.getEmail());
+			clientAccount.setTitle(advAgent.getTitle());
+			clientAccount.setStatus(Integer.parseInt(account.getState()));
+			clientAccount.setSysType(account.getSysType());
+			clientAccount.setBank("");
+			clientAccount.setBankAccount("");
+			clientAccount.setBankAccountName("");
+			clientAccount.setAgentId(account.getAgentId());
+			clientAccount.setOperatorId(account.getOperatorId());
+		}
+		if(account.getOperatorId()!=0 && account.getSysType()==2){
+			//是媒体账号的编辑
+			Operator operator = operatorService.findById(account.getOperatorId());
+			//把accout 和 operator封装成clientAccount对象
+			clientAccount = new ClientAccount();
+			clientAccount.setId(new Long(account.getId()));
+			clientAccount.setAccountName(account.getAccountName());
+			clientAccount.setPassword(account.getPassword());
+			clientAccount.setLinkMan(operator.getLinkMan());
+			clientAccount.setMobilePhone(operator.getMobile());
+			clientAccount.setTel(operator.getTel());
+			clientAccount.setCompanyName(operator.getCompanyName());
+			clientAccount.setHomePage(operator.getHomePage());
+			clientAccount.setAddress(operator.getAddress());
+			clientAccount.setEmail(operator.getEmail());
+			clientAccount.setZip(operator.getZip());
+			clientAccount.setBank(operator.getBank());
+			clientAccount.setBankAccount(operator.getAccount());
+			clientAccount.setBankAccountName(operator.getAccountName());
+			clientAccount.setStatus(Integer.parseInt(account.getState()));
+			clientAccount.setSysType(account.getSysType());
+			clientAccount.setTitle("");
+			clientAccount.setAgentId(account.getAgentId());
+			clientAccount.setOperatorId(account.getOperatorId());
+		}
+		System.out.println("ggggg"+clientAccount);
+		model.addAttribute("clientAccount",clientAccount);
+		return page("edit");
+	}
+	/**
+	 * 
+	 * @param ca
+	 * @param ensueensurePassword
+	 * @return
+	 */
+	@RequestMapping("/save")
+	public String save(@ModelAttribute("form") ClientAccount ca,
+			@RequestParam(value = "ensurePassword", defaultValue = "") String ensueensurePassword){
+		String password = ca.getPassword();
+		if(ca.getId()==null){//新增客户账号
+			//要先判断一下是插入的是operator还是agent
+			//要分两部分来做,一部分是t_account账号的插入,另一部分的插入是operator或者是agent的插入
+			//一个先插入,然后在插入另一个,查好了后还要编辑先插好的那个~~~~~好麻烦~!!
+			ca.setPassword(Md5Tool.getMd5(password));
+			//clientAccountService.add(ca);
+			if (ca.getSysType()==2) {
+				//2表示是媒体,3表示是代理商。
+				Operator o = new Operator();
+				o.setAccount(ca.getBankAccount());
+				o.setBank(ca.getBank());
+				o.setAccountName(ca.getBankAccountName());
+				o.setCompanyName(ca.getCompanyName());
+				o.setLinkMan(ca.getLinkMan());
+				o.setStatus(new Integer(0));
+				o.setTel(ca.getTel());
+				o.setMobile(ca.getMobilePhone());
+				o.setZip(ca.getZip());
+				o.setEmail(ca.getEmail());
+				o.setHomePage(ca.getHomePage());
+				o.setAddress(ca.getAddress());
+				
+				Account account = new Account();
+				account.setAccountName(ca.getAccountName());
+				account.setPassword(ca.getPassword());
+				account.setSysType(ca.getSysType());
+				account.setTel(ca.getTel());
+				account.setCreateTime(new Date());
+				account.setState(ca.getStatus().toString());
+				account.setRealName(ca.getLinkMan());
+				account.setType(new Integer(2));
+				account.setDescription(ca.getCompanyName());
+				accountService.addAccount(account);
+				Account account2 = accountService.querySingleAccount(account.getAccountName());
+				RoleAccount ra = new RoleAccount();//给客户账号分配媒体角色  角色ID=9
+				ra.setAccountId(account2.getId());
+				ra.setRoleId(9);
+				roleService.addAccRole(ra);
+				
+				o.setAdminId(new Long(account2.getId()));
+				operatorService.add(o);
+				Operator operatorNew = operatorService.getNew(o);
+				account2.setOperatorId(operatorNew.getId());
+				accountService.editAccount(account2);
+			}
+			if (ca.getSysType()==3) {
+				//插入的是代理商账号。
+				AdvAgent advAgent = new AdvAgent();
+				advAgent.setAddress(ca.getAddress());
+				advAgent.setContacts(ca.getLinkMan());
+				advAgent.setEmail(ca.getEmail());
+				advAgent.setHomePage(ca.getHomePage());
+				advAgent.setMobile(ca.getMobilePhone());
+				advAgent.setName(ca.getCompanyName());
+				advAgent.setStatus(new Integer(0));
+				advAgent.setTel(ca.getTel());
+				advAgent.setTitle(ca.getTitle());
+				advAgent.setZip(ca.getZip());
+				advAgent.setUpdated(new Date());
+				
+				Account account = new Account();
+				account.setAccountName(ca.getAccountName());
+				account.setPassword(ca.getPassword());
+				account.setSysType(ca.getSysType());
+				account.setTel(ca.getTel());
+				account.setCreateTime(new Date());
+				account.setState(ca.getStatus().toString());
+				account.setRealName(ca.getLinkMan());
+				account.setType(new Integer(5));
+				account.setDescription(ca.getCompanyName());
+				accountService.addAccount(account);
+				Account account2 = accountService.querySingleAccount(account.getAccountName());
+				RoleAccount ra = new RoleAccount();//给客户账号分配代理商角色 角色ID=7
+				ra.setAccountId(account2.getId());
+				ra.setRoleId(7);
+				roleService.addAccRole(ra);
+				
+				advAgent.setAdminId(new Long(account2.getId()));
+				advAgentService.add(advAgent);
+				AdvAgent advAgentNew = advAgentService.getNew(advAgent);
+				account2.setAgentId(advAgentNew.getId());
+				accountService.editAccount(account2);
+			}
+		}else{//x修改信息
+			//要先判断一下是插入的是operator还是agent
+			//要分两部分来做,一部分是t_account账号的插入,另一部分的插入是operator或者是agent的插入
+			//一个先插入,然后在插入另一个,查好了后还要编辑先插好的那个~~~~~好麻烦~!!
+			if(password != null){
+				ca.setPassword(Md5Tool.getMd5(password));
+			}
+			//clientAccountService.add(ca);
+			if (ca.getSysType()==2) {
+				//2表示是媒体,3表示是代理商。
+				Operator o = new Operator();
+				o.setId(ca.getOperatorId());
+				o.setAccount(ca.getBankAccount());
+				o.setBank(ca.getBank());
+				o.setAccountName(ca.getBankAccountName());
+				o.setCompanyName(ca.getCompanyName());
+				o.setLinkMan(ca.getLinkMan());
+				o.setStatus(new Integer(0));
+				o.setTel(ca.getTel());
+				o.setMobile(ca.getMobilePhone());
+				o.setZip(ca.getZip());
+				o.setEmail(ca.getEmail());
+				o.setHomePage(ca.getHomePage());
+				o.setAddress(ca.getAddress());
+				o.setAdminId(ca.getId());
+				
+				Account account = new Account();
+				account.setId(ca.getId().intValue());
+				account.setAccountName(ca.getAccountName());
+				if(password != null){
+					account.setPassword(ca.getPassword());
+				}
+//				account.setSysType(ca.getSysType());
+//				account.setTel(ca.getTel());
+//				account.setCreateTime(new Date());
+				account.setState(ca.getStatus().toString());
+//				account.setRealName(ca.getLinkMan());
+//				account.setType(new Integer(2));
+//				account.setOperatorId(ca.getOperatorId());
+				accountService.editAccount(account);
+				operatorService.edit(o);
+			}
+			if (ca.getSysType()==3) {
+				//插入的是代理商账号。
+				AdvAgent advAgent = new AdvAgent();
+				advAgent.setId(ca.getAgentId());
+				advAgent.setAddress(ca.getAddress());
+				advAgent.setContacts(ca.getLinkMan());
+				advAgent.setEmail(ca.getEmail());
+				advAgent.setHomePage(ca.getHomePage());
+				advAgent.setMobile(ca.getMobilePhone());
+				advAgent.setName(ca.getCompanyName());
+				advAgent.setStatus(ca.getStatus());
+				advAgent.setTel(ca.getTel());
+				advAgent.setTitle(ca.getTitle());
+				advAgent.setZip(ca.getZip());
+				advAgent.setUpdated(new Date());
+				advAgent.setAdminId(ca.getId());
+				Account account = new Account();
+				account.setId(ca.getId().intValue());
+				account.setAccountName(ca.getAccountName());
+				if(password != null){
+					account.setPassword(ca.getPassword());
+				}
+//				account.setSysType(ca.getSysType());
+//				account.setTel(ca.getTel());
+//				account.setCreateTime(new Date());
+				account.setState(ca.getStatus().toString());
+//				account.setRealName(ca.getLinkMan());
+//				account.setType(new Integer(2));
+//				account.setAgentId(ca.getAgentId());
+				accountService.editAccount(account);
+				advAgentService.edit(advAgent);
+			}
+		}
+		return redirect(page("list"));
+	}
+	
+	/**
+	 * 单个或者批量启用功能。
+	 * 后面要做登录检验的,如果是主账号登录直接检查是否被停用。
+	 * 
+	 * @return 成功则返回"ok"
+	 */
+	@RequestMapping("enable")
+	public @ResponseBody String enable(Long[] id) {
+//		LOG.debug("Args's value: id=" + Arrays.toString(id));
+		if (ArrayUtils.isNotEmpty(id)) {
+			for(int i = 0;i < id.length;i++){//依次找到对应客户端账号的更改对应的agent或者operator的状态!
+				Account account = accountService.getById(id[i].toString());
+				if(account.getAgentId()!=0 && account.getSysType()==3){
+					List<Long> l = new ArrayList<Long>();
+					l.add(account.getAgentId());
+					advAgentService.updateStatus(l, Status.enable.value);
+				}
+				if (account.getOperatorId()!=0 && account.getSysType()==2) {
+					List<Long> l = new ArrayList<Long>();
+					l.add(account.getOperatorId());
+					operatorService.updateStatusBack(l, Status.enable.value);
+				}
+			}
+		}
+		if (ArrayUtils.isNotEmpty(id)) {
+			accountService.updateState(LangUtil.array2List(id),
+					Status.disable.value);
+		}
+		return OK;
+	}
+
+	/**
+	 * 单个或者批量禁用功能。 
+	 * 
+	 * @return 成功则返回"ok"
+	 */
+	@RequestMapping("disable")
+	public @ResponseBody String disable(Long[] id) {
+//		LOG.debug("Args's value: id=" + Arrays.toString(id));\
+		if (ArrayUtils.isNotEmpty(id)) {
+			for(int i = 0;i < id.length;i++){//依次找到对应客户端账号的更改对应的agent或者operator的状态!
+				Account account = accountService.getById(id[i].toString());
+				if(account.getAgentId()!=0 && account.getSysType()==3){
+					List<Long> l = new ArrayList<Long>();
+					l.add(account.getAgentId());
+					advAgentService.updateStatus(l, Status.disable.value);
+				}
+				if (account.getOperatorId()!=0 && account.getSysType()==2) {
+					List<Long> l = new ArrayList<Long>();
+					l.add(account.getOperatorId());
+					operatorService.updateStatusBack(l, Status.disable.value);
+				}
+			}
+		}
+		if (ArrayUtils.isNotEmpty(id)) {
+			accountService.updateState(LangUtil.array2List(id),
+					Status.enable.value);
+		}
+		// 将来会被改updateState
+		return OK;
+	}
+	
+	@RequestMapping("isExist")
+	public @ResponseBody String isExist(Model model,
+			@RequestParam(defaultValue = "") String clientAccountName
+			) {
+		String success = "";
+		Account account = accountService.querySingleAccount(clientAccountName);
+//		System.err.println(account);
+		if(account!=null){
+			model.addAttribute("isExist", new Long(1));
+			success = "YES";
+//			System.out.println("yuanzhiq11111111");
+		}else {
+			model.addAttribute("isExist", new Long(0));
+			success = "NO";
+//			System.out.println("yuanzhiq0000000");
+		}
+		return success;
+	}
+	/**
+	 * 打开关联列表页
+	 * @param model
+	 * @return
+	 */
+	@RequestMapping("/correlation")
+	public String correlation(Model model,
+			@RequestParam(defaultValue="1") int page){
+		int totalRow = correlationService.countAllCorrelation();
+		Pager pager = new Pager();
+		pager.setPage(page);
+		pager.setTotalRow(totalRow);
+		List<Correlation> correlations = correlationService.findAllCorrelation(pager);
+		model.addAttribute("pager",pager);
+		model.addAttribute("correlations",correlations);
+		return page("correlation");
+	}
+	/**
+	 * 创建关联
+	 * @return
+	 */
+	@RequestMapping("createcorrelation")
+	public String createCorrelation(){
+		return page("createcorrelation");
+	}
+	/**
+	 * 取消关联
+	 * @return
+	 */
+	@RequestMapping("cancelcorrelation")
+	public String cancelCorrelation(@RequestParam Long agentId,
+			@RequestParam Long operatorId){
+		Correlation ca = new Correlation();
+		ca.setAgentId(agentId);
+		ca.setOperatorId(operatorId);
+		correlationService.deleteCorrelation(ca);
+		return redirect(page("correlation"));
+	}
+	/**
+	 * 保存关联
+	 * @return
+	 */
+	@RequestMapping("savecorrelation")
+	public String saveCorrelation(@ModelAttribute("form")Correlation ca){
+		correlationService.addCorrelation(ca);
+		return redirect(page("correlation"));
+	}
+	/**
+	 * 
+	 * 查询是否 存在关联
+	 * 
+	 * @author CloudCross
+	 */
+	@RequestMapping("is_exit")
+	public @ResponseBody String isExitCorrelation(@RequestParam Long operatorId){
+		List<Correlation>  co = correlationService.findCorrelationByOperatorId(operatorId);
+		if(co.size()>0){
+			return "YES";
+		}else {
+			return "NO";
+		}
+	}
+	
+	@RequestMapping("/exportDataReportExcel")
+	public void exportDataReportExcel(HttpServletRequest request,
+			HttpServletResponse response,
+			@RequestParam HashMap<String, Object> paramMap) {
+		/**
+		 * 参数和list里要一样
+		 */
+		if(paramMap.get("sysType")!=null){
+			Long sysType = Long.parseLong((String)paramMap.get("sysType"));
+			if (sysType!=0) {
+				paramMap.put("sysType", sysType);
+			}else {
+				paramMap.put("sysType",new Long(0));
+			}
+		}
+		Account loginAccount = getLoginUser();
+		paramMap.put("loginAccount", loginAccount);
+		List<ClientAccount> accountList = clientAccountService.findExcelAccounts(paramMap);
+		for (ClientAccount ca : accountList)
+		{
+			 Long userId = ca.getId();
+			 UserLogin ul = userLogin.getById(userId.toString());
+			 if (ul == null) {//要防止创建的账号从未登录过系统
+				 Account account = accountService.getById(userId.toString());
+				 ca.setLoginTime(account.getCreateTime());
+				 continue;
+			}
+			 ca.setLoginTime(ul.getLoginTime());
+		}
+		paramMap.put("dataList", accountList);
+		
+		response.reset();
+		// Content-Type:application/vnd.ms-excel;charset=utf8或者text/xml;charset=utf8
+		response.setContentType("application/vnd.ms-excel;charset=utf8");
+		// 设置excel文件名称
+		SimpleDateFormat df2 = new SimpleDateFormat("yyyyMMddHHmmss");
+		String fileName = "account" + df2.format(new Date());
+		response.setHeader("Content-Disposition", "attachment;filename="
+				+ fileName + ".xls");
+		// 需要对excel的列和行的总数进行指定
+		int column = 9;
+		paramMap.put("dataSize", (accountList.size() + 100));
+		paramMap.put("column", column);
+	
+		paramMap.put("accountList", "客户账号列表");
+		String excelTemplate = templateProcessor.processTemplate(
+				"excel/dataClientAccount.ftl", paramMap);
+		try {
+			PrintWriter out = response.getWriter();
+			out.write(excelTemplate);
+			out.flush();
+			out.close();
+		} catch (IOException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+	}
+}

+ 0 - 1
src/main/java/com/cloudcross/ssp/web/operator/main/ad/ZoneController.java

@@ -128,7 +128,6 @@ public  class ZoneController extends SimpleController {
 	public String list(Model model,
 			@RequestParam HashMap<String, Object> paramMap,		
 			@RequestParam(defaultValue="1") int page) {
-		System.out.println("paramMap"+paramMap);
 		//获取当前账号的id
 		Account account = getLoginUser();
 		paramMap.put("operatorId", account.getOperatorId());