<?xml version="1.0" encoding="UTF-8"?>  
<!DOCTYPE sqlMap   
    PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"   
    "http://ibatis.apache.org/dtd/sql-map-2.dtd">  
<sqlMap namespace="com.hst.tmService.dao.WxGzzListAppMapper">
	<select id="selectWxYhxxByKey"  parameterClass="java.util.Map" resultClass="com.hst.taxService.domain.WxYhxxDomain">
		select a.appid appid,
	       a.openid openid,
	       a.sex sex,
	       a.nickname nickname,
	       a.city city,
	       a.country country,
	       a.province province,
	       a.subscribe_day subscribe_day,
	       a.subscribe_time subscribe_time,
	       a.subscribe subscribe,
	       a.remark subscribe,
	       a.groupid groupid
	  from $databaseUsername$.wx_yhxx a
	 where a.appid = #appid#
	   and a.openid = #openid#
	
	</select>
	
	<insert id="insertWxYhxx"  parameterClass="com.hst.taxService.domain.WxYhxxDomain">
		insert into $databaseUsername$.wx_yhxx
		  (appid,
		   openid,
		   sex,
		   nickname,
		   city,
		   country,
		   province,
		   subscribe_day,
		   subscribe_time,
		   subscribe,
		   remark,
		   groupid)
		values
		  (#appid:VARCHAR#,
		   #openid:VARCHAR#,
		   #sex:VARCHAR#,
		   #nickname:VARCHAR#,
		   #city:VARCHAR#,
		   #country:VARCHAR#,
		   #province:VARCHAR#,
		   TO_DATE(#subscribe_day:DATE#, 'yyyy-MM-dd'),
		   TO_DATE(#subscribe_time:DATE#, 'yyyy-MM-dd hh24:mi:ss'),
		   #subscribe:VARCHAR#,
		   #remark:VARCHAR#,
		   #groupid:VARCHAR#)
	</insert>
	<insert id="insertLsbWxYhxx"  parameterClass="com.hst.taxService.domain.WxYhxxDomain">
		insert into $databaseUsername$.tm_lsb_wx_yhxx
		  (appid,
		   openid,
		   sex,
		   nickname,
		   city,
		   country,
		   province,
		   subscribe_day,
		   subscribe_time,
		   subscribe,
		   remark,
		   groupid)
		values
		  (#appid:VARCHAR#,
		   #openid:VARCHAR#,
		   #sex:VARCHAR#,
		   #nickname:VARCHAR#,
		   #city:VARCHAR#,
		   #country:VARCHAR#,
		   #province:VARCHAR#,
		   TO_DATE(#subscribe_day:DATE#, 'yyyy-MM-dd'),
		   TO_DATE(#subscribe_time:DATE#, 'yyyy-MM-dd hh24:mi:ss'),
		   #subscribe:VARCHAR#,
		   #remark:VARCHAR#,
		   #groupid:VARCHAR#)
	</insert>
	<update id="updateWxYhxxSubscribe"  parameterClass="java.util.Map" >
			update $databaseUsername$.wx_yhxx a set subscribe='0'
			  where  a.appid=#appid#  and  not EXISTS  (select * from $databaseUsername$.tm_lsb_wx_yhxx b  where a.appid=b.appid and a.openid=b.openid  ) 
	</update>
	<!-- 删除未关注外的数据 后面重新插入 -->
	<delete id="deleteWxYhxxWgz">
		delete from  $databaseUsername$.wx_yhxx  a where a.appid=#appid#  and  EXISTS  (select * from $databaseUsername$.tm_lsb_wx_yhxx b  where a.appid=b.appid and a.openid=b.openid  )
	</delete>
	<delete id="deleteWxYhxxLsb">
		delete from  $databaseUsername$.tm_lsb_wx_yhxx  
	</delete>
	
	<insert id="insertWxYhxxFromLsb" >
		insert    into $databaseUsername$.wx_yhxx select * from $databaseUsername$.tm_lsb_wx_yhxx b 
	</insert>
	
	<update id="updateWxYhxxByKey" parameterClass="com.hst.taxService.domain.WxYhxxDomain">
		update $databaseUsername$.wx_yhxx a
		   set appid          = #appid#,
		       openid         = #openid#,
		       sex            = #sex#,
		       nickname       = #nickname#,
		       city           = #city#,
		       country        = #country#,
		       province       = #province#,
		       subscribe_day  = to_date(#subscribe_day#,'yyyy-mm-dd'),
		       subscribe_time =  to_date(#subscribe_time#,'yyyy-mm-dd hh24:mi:ss'),
		       subscribe      = #subscribe#,
		       groupid        = #groupid#
		 where a.appid=#appid# and a.openid=#openid#
	</update>
	
	
</sqlMap>