<?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.model.Operator" resultType="com.cloudcross.ssp.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.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.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="operatorIdList"
		      open="(" separator="," close=")">
		        #{operatorId}
			</foreach>
	</update>
	
	<select id="queryAll" parameterType="java.util.Map" resultType="com.cloudcross.ssp.model.Operator">
		select id,company_name companyName from t_operator where status != -1 limit #{pager.offset}, #{pager.limit}
	</select>
	
	<select id="queryAllCount" resultType="java.lang.Integer">
		select count(1) from t_operator
	</select>
</mapper>