<?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.neusoft.smart.pos.org.persistent.mapper.ShopMapper">
    <resultMap id="BaseResultMap" type="com.neusoft.smart.pos.org.persistent.domain.Shop">
        <id column="id" jdbcType="INTEGER" property="id"/>
        <result column="name" jdbcType="VARCHAR" property="name"/>
        <result column="org" jdbcType="INTEGER" property="org"/>
        <result column="orgname" jdbcType="VARCHAR" property="orgname"/>
        <result column="province" jdbcType="VARCHAR" property="province"/>
        <result column="city" jdbcType="VARCHAR" property="city"/>
        <result column="address" jdbcType="VARCHAR" property="address"/>
        <result column="phone" jdbcType="VARCHAR" property="phone"/>
        <result column="image" jdbcType="VARCHAR" property="image"/>
        <result column="comment" jdbcType="VARCHAR" property="comment"/>
        <result column="payeeType" jdbcType="VARCHAR" property="payeetype"/>
        <result column="openhours" jdbcType="VARCHAR" property="openhours"/>
        <result column="posnum" jdbcType="INTEGER" property="posnum"/>
        <result column="membernum" jdbcType="INTEGER" property="membernum"/>
        <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
        <result column="provincename" jdbcType="VARCHAR" property="provincename"/>
        <result column="cityname" jdbcType="VARCHAR" property="cityname"/>
        <result column="membertype" jdbcType="VARCHAR" property="membertype"/>
        <result column="settle" jdbcType="VARCHAR" property="settle"/>
    </resultMap>
    <sql id="Example_Where_Clause">
        <where>
            <foreach collection="oredCriteria" item="criteria" separator="or">
                <if test="criteria.valid">
                    <trim prefix="(" prefixOverrides="and" suffix=")">
                        <foreach collection="criteria.criteria" item="criterion">
                            <choose>
                                <when test="criterion.noValue">
                                    and ${criterion.condition}
                                </when>
                                <when test="criterion.singleValue">
                                    and ${criterion.condition} #{criterion.value}
                                </when>
                                <when test="criterion.betweenValue">
                                    and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                                </when>
                                <when test="criterion.listValue">
                                    and ${criterion.condition}
                                    <foreach close=")" collection="criterion.value" item="listItem" open="("
                                             separator=",">
                                        #{listItem}
                                    </foreach>
                                </when>
                            </choose>
                        </foreach>
                    </trim>
                </if>
            </foreach>
        </where>
    </sql>
    <sql id="Update_By_Example_Where_Clause">
        <where>
            <foreach collection="example.oredCriteria" item="criteria" separator="or">
                <if test="criteria.valid">
                    <trim prefix="(" prefixOverrides="and" suffix=")">
                        <foreach collection="criteria.criteria" item="criterion">
                            <choose>
                                <when test="criterion.noValue">
                                    and ${criterion.condition}
                                </when>
                                <when test="criterion.singleValue">
                                    and ${criterion.condition} #{criterion.value}
                                </when>
                                <when test="criterion.betweenValue">
                                    and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                                </when>
                                <when test="criterion.listValue">
                                    and ${criterion.condition}
                                    <foreach close=")" collection="criterion.value" item="listItem" open="("
                                             separator=",">
                                        #{listItem}
                                    </foreach>
                                </when>
                            </choose>
                        </foreach>
                    </trim>
                </if>
            </foreach>
        </where>
    </sql>
    <sql id="Base_Column_List">
    shop.id, shop.name, shop.org, org.name as orgname, shop.province, shop.city, shop.membertype, shop.settle,
    (select region_name from city_region_dictionary where region_number = shop.province) as provincename,
	(select region_name from city_region_dictionary where region_number = shop.city) as cityname, 
    shop.address, shop.phone, shop.image, shop.comment, shop.payeeType, shop.openhours, shop.posnum, shop.membernum, date_format(shop.create_date, '%Y-%m-%d') as create_date
  </sql>
    <select id="selectByExample" parameterType="com.neusoft.smart.pos.org.persistent.domain.ShopExample"
            resultMap="BaseResultMap">
        select
        <if test="distinct">
            distinct
        </if>
        <include refid="Base_Column_List"/>
        from `shop`
        inner join `org` ON shop.org = org.id
        <if test="_parameter != null">
            <include refid="Example_Where_Clause"/>            
        </if>
        <if test="orderByClause != null">
            order by ${orderByClause}
        </if>
        <if test="offset != null and limit != null">
            limit ${offset}, ${limit}
        </if>
    </select>
    <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from `shop`
        inner join `org` ON shop.org = org.id
        where shop.id = #{id,jdbcType=INTEGER}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from `shop`
    where id = #{id,jdbcType=INTEGER}
  </delete>
    <delete id="deleteByExample" parameterType="com.neusoft.smart.pos.org.persistent.domain.ShopExample">
        delete from `shop`
        <if test="_parameter != null">
            <include refid="Example_Where_Clause"/>
        </if>
    </delete>
    <insert id="insert" parameterType="com.neusoft.smart.pos.org.persistent.domain.Shop">
    insert into `shop` (id, name, org, 
      province, city, address, 
      phone, image, comment, 
      payeeType, openhours, membertype, settle)
    values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{org,jdbcType=INTEGER}, 
      #{province,jdbcType=VARCHAR}, #{city,jdbcType=VARCHAR}, #{address,jdbcType=VARCHAR}, 
      #{phone,jdbcType=VARCHAR}, #{image,jdbcType=VARCHAR}, #{comment,jdbcType=VARCHAR}, 
      #{payeetype,jdbcType=VARCHAR}, #{openhours,jdbcType=VARCHAR}, #{membertype,jdbcType=VARCHAR}, #{settle,jdbcType=VARCHAR})
  </insert>
    <insert id="insertSelective" parameterType="com.neusoft.smart.pos.org.persistent.domain.Shop">
    	<selectKey resultType="java.lang.Integer" order="AFTER" keyProperty="id">
          SELECT LAST_INSERT_ID()
      	</selectKey>
        insert into `shop`
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">
                id,
            </if>
            <if test="name != null">
                name,
            </if>
            <if test="org != null">
                org,
            </if>
            <if test="province != null">
                province,
            </if>
            <if test="city != null">
                city,
            </if>
            <if test="address != null">
                address,
            </if>
            <if test="phone != null">
                phone,
            </if>
            <if test="image != null">
                image,
            </if>
            <if test="comment != null">
                comment,
            </if>
            <if test="payeetype != null">
                payeeType,
            </if>
            <if test="openhours != null">
                openhours,
            </if>
            <if test="membertype != null">
                membertype,
            </if>
            <if test="settle != null">
                settle,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">
                #{id,jdbcType=INTEGER},
            </if>
            <if test="name != null">
                #{name,jdbcType=VARCHAR},
            </if>
            <if test="org != null">
                #{org,jdbcType=INTEGER},
            </if>
            <if test="province != null">
                #{province,jdbcType=VARCHAR},
            </if>
            <if test="city != null">
                #{city,jdbcType=VARCHAR},
            </if>
            <if test="address != null">
                #{address,jdbcType=VARCHAR},
            </if>
            <if test="phone != null">
                #{phone,jdbcType=VARCHAR},
            </if>
            <if test="image != null">
                #{image,jdbcType=VARCHAR},
            </if>
            <if test="comment != null">
                #{comment,jdbcType=VARCHAR},
            </if>
            <if test="payeetype != null">
                #{payeetype,jdbcType=VARCHAR},
            </if>
            <if test="openhours != null">
                #{openhours,jdbcType=VARCHAR},
            </if>
            <if test="membertype != null">
                #{membertype,jdbcType=VARCHAR},
            </if>
            <if test="settle != null">
                #{settle,jdbcType=VARCHAR},
            </if>
        </trim>
    </insert>
    <select id="countByExample" parameterType="com.neusoft.smart.pos.org.persistent.domain.ShopExample"
            resultType="java.lang.Integer">
        select count(*) from `shop`
        <if test="_parameter != null">
            <include refid="Example_Where_Clause"/>
        </if>
    </select>
    <update id="updateByExampleSelective" parameterType="map">
        update `shop`
        <set>
            <if test="record.id != null">
                id = #{record.id,jdbcType=INTEGER},
            </if>
            <if test="record.name != null">
                name = #{record.name,jdbcType=VARCHAR},
            </if>
            <if test="record.org != null">
                org = #{record.org,jdbcType=INTEGER},
            </if>
            <if test="record.province != null">
                province = #{record.province,jdbcType=VARCHAR},
            </if>
            <if test="record.city != null">
                city = #{record.city,jdbcType=VARCHAR},
            </if>
            <if test="record.address != null">
                address = #{record.address,jdbcType=VARCHAR},
            </if>
            <if test="record.phone != null">
                phone = #{record.phone,jdbcType=VARCHAR},
            </if>
            <if test="record.image != null">
                image = #{record.image,jdbcType=VARCHAR},
            </if>
            <if test="record.comment != null">
                comment = #{record.comment,jdbcType=VARCHAR},
            </if>
            <if test="record.payeetype != null">
                payeeType = #{record.payeetype,jdbcType=VARCHAR},
            </if>
            <if test="record.openhours != null">
                openhours = #{record.openhours,jdbcType=VARCHAR},
            </if>
            <if test="record.posnum != null">
                posnum = #{record.posnum,jdbcType=INTEGER},
            </if>
            <if test="record.membernum != null">
                membernum = #{record.membernum,jdbcType=INTEGER},
            </if>
            <if test="record.status != null">
                status = #{record.status,jdbcType=VARCHAR},
            </if>
            <if test="record.settle != null">
                settle = #{record.settle,jdbcType=VARCHAR},
            </if>
        </set>
        <if test="_parameter != null">
            <include refid="Update_By_Example_Where_Clause"/>
        </if>
    </update>
    <update id="updateByExample" parameterType="map">
        update `shop`
        set id = #{record.id,jdbcType=INTEGER},
        name = #{record.name,jdbcType=VARCHAR},
        org = #{record.org,jdbcType=INTEGER},
        province = #{record.province,jdbcType=VARCHAR},
        city = #{record.city,jdbcType=VARCHAR},
        address = #{record.address,jdbcType=VARCHAR},
        phone = #{record.phone,jdbcType=VARCHAR},
        image = #{record.image,jdbcType=VARCHAR},
        comment = #{record.comment,jdbcType=VARCHAR},
        payeeType = #{record.payeetype,jdbcType=VARCHAR},
        openhours = #{record.openhours,jdbcType=VARCHAR},
        posnum = #{record.posnum,jdbcType=INTEGER},
        membernum = #{record.membernum,jdbcType=INTEGER},
        status = #{record.status,jdbcType=VARCHAR},
        settle = #{record.settle,jdbcType=VARCHAR}
        <if test="_parameter != null">
            <include refid="Update_By_Example_Where_Clause"/>
        </if>
    </update>
    <update id="updateByPrimaryKeySelective" parameterType="com.neusoft.smart.pos.org.persistent.domain.Shop">
        update `shop`
        <set>
            <if test="name != null">
                name = #{name,jdbcType=VARCHAR},
            </if>
            <if test="org != null">
                org = #{org,jdbcType=INTEGER},
            </if>
            <if test="province != null">
                province = #{province,jdbcType=VARCHAR},
            </if>
            <if test="city != null">
                city = #{city,jdbcType=VARCHAR},
            </if>
            <if test="address != null">
                address = #{address,jdbcType=VARCHAR},
            </if>
            <if test="phone != null">
                phone = #{phone,jdbcType=VARCHAR},
            </if>
            <if test="image != null">
                image = #{image,jdbcType=VARCHAR},
            </if>
            <if test="comment != null">
                comment = #{comment,jdbcType=VARCHAR},
            </if>
            <if test="payeetype != null">
                payeeType = #{payeetype,jdbcType=VARCHAR},
            </if>
            <if test="openhours != null">
                openhours = #{openhours,jdbcType=VARCHAR},
            </if>
            <if test="posnum != null">
                posnum = #{posnum,jdbcType=INTEGER},
            </if>
            <if test="membernum != null">
                membernum = #{membernum,jdbcType=INTEGER},
            </if>
            <if test="status != null">
                status = #{status,jdbcType=VARCHAR},
            </if>
            <if test="settle != null">
                settle = #{settle,jdbcType=VARCHAR},
            </if>
        </set>
        where id = #{id,jdbcType=INTEGER}
    </update>
    <update id="updateByPrimaryKey" parameterType="com.neusoft.smart.pos.org.persistent.domain.Shop">
    update `shop`
    set name = #{name,jdbcType=VARCHAR},
      org = #{org,jdbcType=INTEGER},
      province = #{province,jdbcType=VARCHAR},
      city = #{city,jdbcType=VARCHAR},
      address = #{address,jdbcType=VARCHAR},
      phone = #{phone,jdbcType=VARCHAR},
      image = #{image,jdbcType=VARCHAR},
      comment = #{comment,jdbcType=VARCHAR},
      payeeType = #{payeetype,jdbcType=VARCHAR},
      openhours = #{openhours,jdbcType=VARCHAR},
      posnum = #{posnum,jdbcType=INTEGER},
      membernum = #{membernum,jdbcType=INTEGER},
      status = #{status,jdbcType=VARCHAR},
      settle = #{settle,jdbcType=VARCHAR}
    where id = #{id,jdbcType=INTEGER}
  </update>
</mapper>