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