<?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="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> </mapper>