ChannelMapper.xml
6.22 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
<?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>
<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>
<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>
</mapper>