<?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="com.sincere.wechatbusiness.mapper.ChannelMapper"> <resultMap id="ChannelMap" type="com.sincere.wechatbusiness.model.Channel"> <id column="id" jdbcType="INTEGER" property="id" /> <result column="name" jdbcType="VARCHAR" property="name" /> <result column="mobile" jdbcType="VARCHAR" property="mobile" /> <result column="province" jdbcType="VARCHAR" property="province" /> <result column="city" jdbcType="VARCHAR" property="city" /> <result column="templateId" jdbcType="INTEGER" property="templateId" /> <result column="state" jdbcType="INTEGER" property="state"/> <result column="create_time" jdbcType="TIMESTAMP" property="createTime" /> <result column="product_count" jdbcType="INTEGER" property="productCount" /> <result column="template_name" jdbcType="VARCHAR" property="templateName" /> <result column="province_code" jdbcType="VARCHAR" property="provinceCode" /> <result column="city_code" jdbcType="VARCHAR" property="cityCode" /> </resultMap> <select id="getByName" parameterType="java.lang.String" resultMap="ChannelMap"> select * from channel where name = #{name} and state = 1 </select> <resultMap id="AreaMap" type="com.sincere.wechatbusiness.model.Area"> <result column="value" jdbcType="VARCHAR" property="value" /> <result column="label" jdbcType="VARCHAR" property="label" /> </resultMap> <resultMap id="TemplateMap" type="com.sincere.wechatbusiness.model.Template"> <id column="id" jdbcType="INTEGER" property="id" /> <result column="title" jdbcType="VARCHAR" property="title" /> <result column="img_url" jdbcType="VARCHAR" property="imgUrl" /> <result column="state" jdbcType="INTEGER" property="state"/> <result column="create_time" jdbcType="TIMESTAMP" property="createTime" /> </resultMap> <resultMap id="ManagerMap" type="com.sincere.wechatbusiness.model.Manager"> <id column="id" jdbcType="INTEGER" property="id" /> <result column="mobile" jdbcType="VARCHAR" property="mobile" /> <result column="state" jdbcType="INTEGER" property="state"/> <result column="create_time" jdbcType="TIMESTAMP" property="createTime" /> </resultMap> <resultMap id="LogMap" type="com.sincere.wechatbusiness.model.Log"> <id column="id" jdbcType="INTEGER" property="id" /> <result column="mobile" jdbcType="VARCHAR" property="mobile" /> <result column="operation" jdbcType="VARCHAR" property="operation"/> <result column="create_time" jdbcType="TIMESTAMP" property="createTime" /> </resultMap> <resultMap id="UsersMap" type="com.sincere.wechatbusiness.model.Users"> <result column="account" jdbcType="VARCHAR" property="account" /> <result column="userName" jdbcType="VARCHAR" property="userName"/> <result column="count" jdbcType="INTEGER" property="count" /> <result column="phone" jdbcType="VARCHAR" property="phone"/> <result column="create_time" jdbcType="TIMESTAMP" property="createTime" /> </resultMap> <resultMap id="PackageMap" type="com.sincere.wechatbusiness.model.DiscountPackage"> <id column="id" jdbcType="INTEGER" property="id" /> <result column="package_name" jdbcType="VARCHAR" property="package_name" /> <result column="account" jdbcType="VARCHAR" property="account" /> <result column="count" jdbcType="INTEGER" property="count" /> <result column="intime" jdbcType="TIMESTAMP" property="intime" /> </resultMap> <resultMap id="AccessTokenMap" type="com.sincere.wechatbusiness.model.AccessToken"> <id column="id" jdbcType="INTEGER" property="id" /> <result column="access_token" jdbcType="VARCHAR" property="accessToken" /> <result column="create_time" jdbcType="TIMESTAMP" property="createTime" /> </resultMap> <select id="getListByTemplate" parameterType="java.lang.Integer" resultMap="ChannelMap"> select * from channel where templateId = #{templateId} </select> <select id="getList" parameterType="com.sincere.wechatbusiness.model.Channel" resultMap="ChannelMap"> select *,(select count(0) from channel_product where channelId=c.id and state=1) as product_count, (select title from template where id=c.templateId) as template_name from channel c <where> <if test="state != 0"> and state=1 </if> <if test="name!='' and name!=null"> and name like '%${name}%' </if> </where> order by create_time </select> <select id="getListCount" parameterType="com.sincere.wechatbusiness.model.Channel" resultType="java.lang.Integer"> select count(0) from channel <where> <if test="state != 0"> and state=1 </if> <if test="name!='' and name!=null"> and name like '%${name}%' </if> </where> </select> <select id="getDetail" parameterType="java.lang.Integer" resultMap="ChannelMap"> select *,(select top 1 area_code from sys_area where c.province=area_name) as province_code, (select top 1 area_code from sys_area where c.city=area_name) as city_code from channel c where id=#{id} </select> <insert id="insert" parameterType="com.sincere.wechatbusiness.model.Channel" useGeneratedKeys="true" keyProperty="id"> insert into channel (name, mobile,province,city,templateId) values (#{name,jdbcType=VARCHAR}, #{mobile,jdbcType=VARCHAR}, #{province,jdbcType=VARCHAR}, #{city,jdbcType=VARCHAR}, #{templateId,jdbcType=INTEGER} ) </insert> <update id="update" parameterType="com.sincere.wechatbusiness.model.Channel"> update channel <trim prefix="set" suffixOverrides=","> <if test="name!=null and name!=''"> name=#{name}, </if> <if test="mobile!=null and mobile!=''"> mobile=#{mobile}, </if> <if test="province!=null and province!=''"> province=#{province}, </if> <if test="city!=null and city!=''"> city=#{city}, </if> <if test="templateId!=0"> templateId=#{templateId}, </if> </trim> where id = #{id} </update> <update id="deleteChannel" parameterType="java.lang.Integer"> update channel set state=0 where id = #{id} update channel_product set state=0 where channelId = #{id} </update> <select id="getProvince" resultMap="AreaMap"> select area_code as value,area_name as label from sys_area where area_code like '__' </select> <select id="getCity" parameterType="java.lang.String" resultMap="AreaMap"> select area_code as value,area_name as label from sys_area where area_code like '____' and area_code like #{areaCode}+'%' </select> <select id="getArea" parameterType="java.lang.String" resultMap="AreaMap"> select area_code as value,area_name as label from sys_area where area_code like '______' and area_code like #{areaCode}+'%' </select> <select id="getTemplateList" resultMap="TemplateMap"> select * from template where state=1 order by create_time </select> <select id="getManagerDetail" parameterType="java.lang.String" resultMap="ManagerMap"> select * from manager where mobile=#{mobile} and state=1 </select> <insert id="insertLog" parameterType="com.sincere.wechatbusiness.model.Log"> insert into log (mobile,operation) values (#{mobile,jdbcType=VARCHAR}, #{operation,jdbcType=VARCHAR} ) </insert> <select id="getRegisterCount" resultType="java.lang.Integer"> select count(0) from report_voluntary.dbo.users <where> <if test="channelId > 0"> and channelId=#{channelId} </if> <if test="agentId>0"> and agentId=#{agentId} </if> <if test="type==1"> and DateDiff(dd,create_time,getdate())=0 </if> <if test="type==2"> and DateDiff(mm,create_time,getdate())=0 </if> </where> </select> <select id="getPageViewCount" resultType="java.lang.Integer"> select count(0) from page_view <where> <if test="channelId > 0"> and channel_id=#{channelId} </if> <if test="agentId>0"> and agent_id=#{agentId} </if> <if test="type==1"> and DateDiff(dd,create_time,getdate())=0 </if> <if test="type==2"> and DateDiff(mm,create_time,getdate())=0 </if> </where> </select> <select id="getOrderCount" resultType="java.lang.Integer"> select count(0) from (select distinct account from report_voluntary.dbo.orderpay <where> <if test="channelId > 0"> and channelId=#{channelId} </if> <if test="agentId>0"> and agentId=#{agentId} </if> <if test="type==1"> and DateDiff(dd,intime,getdate())=0 </if> <if test="type==2"> and DateDiff(mm,intime,getdate())=0 </if> <if test="state==1"> and paystate=1 </if> </where> ) a </select> <select id="getAgentRegisterList" resultMap="UsersMap"> select * from (select a.id as agentId,0 as channelId,RIGHT(mobile,4) as account,name as userName,(select count(0) from report_voluntary.dbo.users <where> <if test="state==1"> and agentId=a.id </if> <if test="type==1"> and DateDiff(dd,create_time,getdate())=0 </if> <if test="type==2"> and DateDiff(mm,create_time,getdate())=0 </if> </where> ) as count from agent a where channelId=#{channelId} and state=1) b where count>0 </select> <select id="getAgentPageViewList" resultMap="UsersMap"> select * from (select a.id as agentId,0 as channelId,RIGHT(mobile,4) as account,name as userName,(select count(0) from page_view <where> <if test="state==1"> and agent_id=a.id </if> <if test="type==1"> and DateDiff(dd,create_time,getdate())=0 </if> <if test="type==2"> and DateDiff(mm,create_time,getdate())=0 </if> </where> ) as count from agent a where channelId=#{channelId} and state=1 <if test="agentId != 0"> and id = #{agentId} </if> ) b where count>0 </select> <select id="getChannelRegister" resultMap="UsersMap"> select * from (select c.id as channelId,0 as agentId,RIGHT(mobile,4) as account,name+'(本人)' as userName,(select count(0) from report_voluntary.dbo.users <where> <if test="state==1"> and channelId=c.id and (agentId=0 or agentId=null) </if> <if test="type==1"> and DateDiff(dd,create_time,getdate())=0 </if> <if test="type==2"> and DateDiff(mm,create_time,getdate())=0 </if> </where> ) as count from channel c where id=#{channelId} and state=1) b where count>0 </select> <select id="getChannelPageView" resultMap="UsersMap"> select * from (select c.id as channelId,0 as agentId,RIGHT(mobile,4) as account,name+'(本人)' as userName,(select count(0) from page_view <where> <if test="state==1"> and channel_id=c.id and (agent_id=0 or agent_id=null) </if> <if test="type==1"> and DateDiff(dd,create_time,getdate())=0 </if> <if test="type==2"> and DateDiff(mm,create_time,getdate())=0 </if> </where> ) as count from channel c where id=#{channelId} and state=1) b where count>0 </select> <select id="getAgentOrderList" resultMap="UsersMap"> select * from (select a.id as agentId,0 as channelId,RIGHT(mobile,4) as account,name as userName,(select count(0) from (select distinct account from report_voluntary.dbo.orderpay <where> <if test="state==1"> and agentId=a.id and paystate=1 </if> <if test="type==1"> and DateDiff(dd,intime,getdate())=0 </if> <if test="type==2"> and DateDiff(mm,intime,getdate())=0 </if> </where> ) b) as count from agent a where channelId=#{channelId} and state=1) c where count>0 </select> <select id="getChannelOrder" resultMap="UsersMap"> select * from (select c.id as channelId,0 as agentId,RIGHT(mobile,4) as account,name+'(本人)' as userName,(select count(0) from (select distinct account from report_voluntary.dbo.orderpay <where> <if test="state==1"> and channelId=c.id and ( agentId=0 or agentId=null) and paystate=1 </if> <if test="type==1"> and DateDiff(dd,intime,getdate())=0 </if> <if test="type==2"> and DateDiff(mm,intime,getdate())=0 </if> </where> ) b) as count from channel c where id=#{channelId} and state=1) c where count>0 </select> <select id="getOrderList" resultMap="PackageMap"> select * from (select p.package_name,p.id,(select count(0) from (select distinct account from report_voluntary.dbo.orderpay <where> <if test="state==1"> and product_id=p.id and paystate=1 </if> <if test="channelId>0"> and channelId=#{channelId} </if> <if test="agentId>0"> and agentId=#{agentId} </if> <if test="type==1"> and DateDiff(dd,intime,getdate())=0 </if> <if test="type==2"> and DateDiff(mm,intime,getdate())=0 </if> </where> ) b) as count from channel_product c inner join report_voluntary.dbo.package p on c.productId=p.id where channelId=#{channelId} and c.state=1) c where count>0 </select> <select id="getRegisterDetailList" resultMap="UsersMap"> select phone,create_time from report_voluntary.dbo.users <where> <if test="channelId>0"> and channelId=#{channelId} </if> <if test="agentId==0"> and (agentId=0 or agentId=null) </if> <if test="agentId>0"> and agentId=#{agentId} </if> <if test="type==1"> and DateDiff(dd,create_time,getdate())=0 </if> <if test="type==2"> and DateDiff(mm,create_time,getdate())=0 </if> </where> order by create_time desc </select> <select id="getOrderDetailList" resultMap="PackageMap"> select account,product_name as package_name,intime from report_voluntary.dbo.orderpay <where> <if test="state==1"> and paystate=1 </if> <if test="channelId>0"> and channelId=#{channelId} </if> <if test="agentId>0"> and agentId=#{agentId} </if> <if test="agentId==0"> and (agentId=0 or agentId=null) </if> <if test="productId>0"> and product_id=#{productId} </if> <if test="type==1"> and DateDiff(dd,intime,getdate())=0 </if> <if test="type==2"> and DateDiff(mm,intime,getdate())=0 </if> </where> order by intime desc </select> <insert id="insertAccessToken" parameterType="com.sincere.wechatbusiness.model.AccessToken"> insert into access_token (access_token) values (#{accessToken,jdbcType=VARCHAR} ) </insert> <select id="getAccessToken" resultMap="AccessTokenMap"> select top 1.* from access_token order by create_time desc </select> <delete id="deleteToken"> delete access_token </delete> </mapper>