ChannelMapper.xml 17.4 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445
<?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" />
        <result column="report_routine_url" jdbcType="VARCHAR" property="reportRoutineUrl" />
        <result column="register" property="register" />
    </resultMap>

    <select id="getReportChannel" resultMap="ChannelMap">
        select * , (select count(*) from report_voluntary.dbo.users as users where users.channelId = channel.id) as register
        from channel where state = 1
        <if test="name != null and name != ''">
         and name like '%${name}%'
        </if>
    </select>

    <select id="getReportChannelCount" resultType="java.lang.Integer">
        select count(*)
        from channel where state = 1
        <if test="name != null and name != ''">
            and name like '%${name}%'
        </if>
    </select>

    <select id="getByName" parameterType="java.lang.String" resultMap="ChannelMap">
        select * from channel where name = #{name} and state = 1
    </select>

    <update id="updateRoutine" >
        update channel set report_routine_url = #{reportRoutineUrl} where id = #{id}
    </update>

    <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>