<?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.ruoyi.system.mapper.grid.GridShopMapper">
    <resultMap id="BaseResultMap" type="com.ruoyi.system.domain.grid.GridShop">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="shop_name" jdbcType="VARCHAR" property="shopName"/>
        <result column="shop_owner" jdbcType="VARCHAR" property="shopOwner"/>
        <result column="shop_phone" jdbcType="VARCHAR" property="shopPhone"/>
        <result column="shop_address" jdbcType="VARCHAR" property="shopAddress"/>
        <result column="shop_type" jdbcType="VARCHAR" property="shopType"/>
        <result column="belong_area" jdbcType="VARCHAR" property="belongArea"/>
        <result column="wg_code" jdbcType="VARCHAR" property="wgCode"/>
        <result column="longitude" jdbcType="VARCHAR" property="longitude"/>
        <result column="latitude" jdbcType="VARCHAR" property="latitude"/>
        <result column="valid" jdbcType="TINYINT" property="valid"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="create_by" jdbcType="VARCHAR" property="createBy"/>
        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
        <result column="update_by" jdbcType="VARCHAR" property="updateBy"/>
        <result column="license_code" jdbcType="VARCHAR" property="licenseCode"/>
        <result column="shop_type_name" jdbcType="VARCHAR" property="shopTypeName"/>
    </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">
        id
        , shop_name, shop_owner, shop_phone, shop_address, shop_type, belong_area, wg_code,
    longitude, latitude, valid, create_time, create_by, update_time, update_by,
    license_code, shop_type_name
    </sql>
    <select id="selectByExample" parameterType="com.ruoyi.system.domain.grid.GridShopExample" resultMap="BaseResultMap">
        select
        <if test="distinct">
            distinct
        </if>
        <include refid="Base_Column_List"/>
        from grid_shop
        <if test="_parameter != null">
            <include refid="Example_Where_Clause"/>
        </if>
        <if test="orderByClause != null">
            order by ${orderByClause}
        </if>
    </select>
    <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from grid_shop
        where id = #{id,jdbcType=BIGINT}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
        delete
        from grid_shop
        where id = #{id,jdbcType=BIGINT}
    </delete>
    <delete id="deleteByExample" parameterType="com.ruoyi.system.domain.grid.GridShopExample">
        delete from grid_shop
        <if test="_parameter != null">
            <include refid="Example_Where_Clause"/>
        </if>
    </delete>
    <insert id="insert" parameterType="com.ruoyi.system.domain.grid.GridShop" useGeneratedKeys="true" keyProperty="id">
        insert into grid_shop (id, shop_name, shop_owner,
                               shop_phone, shop_address, shop_type,
                               belong_area, wg_code, longitude,
                               latitude, valid,
                               create_time, create_by, update_time,
                               update_by, license_code, shop_type_name)
        values (#{id,jdbcType=BIGINT}, #{shopName,jdbcType=VARCHAR}, #{shopOwner,jdbcType=VARCHAR},
                #{shopPhone,jdbcType=VARCHAR}, #{shopAddress,jdbcType=VARCHAR}, #{shopType,jdbcType=VARCHAR},
                #{belongArea,jdbcType=VARCHAR}, #{wgCode,jdbcType=VARCHAR}, #{longitude,jdbcType=VARCHAR},
                #{latitude,jdbcType=VARCHAR}, #{valid,jdbcType=TINYINT},
                #{createTime,jdbcType=TIMESTAMP}, #{createBy,jdbcType=VARCHAR}, #{updateTime,jdbcType=TIMESTAMP},
                #{updateBy,jdbcType=VARCHAR}, #{licenseCode,jdbcType=VARCHAR}, #{shopTypeName,jdbcType=VARCHAR})
    </insert>
    <insert id="insertSelective" parameterType="com.ruoyi.system.domain.grid.GridShop" useGeneratedKeys="true"
            keyProperty="id">
        insert into grid_shop
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">
                id,
            </if>
            <if test="shopName != null">
                shop_name,
            </if>
            <if test="shopOwner != null">
                shop_owner,
            </if>
            <if test="shopPhone != null">
                shop_phone,
            </if>
            <if test="shopAddress != null">
                shop_address,
            </if>
            <if test="shopType != null">
                shop_type,
            </if>
            <if test="belongArea != null">
                belong_area,
            </if>
            <if test="wgCode != null">
                wg_code,
            </if>
            <if test="longitude != null">
                longitude,
            </if>
            <if test="latitude != null">
                latitude,
            </if>
            <if test="valid != null">
                valid,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="createBy != null">
                create_by,
            </if>
            <if test="updateTime != null">
                update_time,
            </if>
            <if test="updateBy != null">
                update_by,
            </if>
            <if test="licenseCode != null">
                license_code,
            </if>
            <if test="shopTypeName != null">
                shop_type_name,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">
                #{id,jdbcType=BIGINT},
            </if>
            <if test="shopName != null">
                #{shopName,jdbcType=VARCHAR},
            </if>
            <if test="shopOwner != null">
                #{shopOwner,jdbcType=VARCHAR},
            </if>
            <if test="shopPhone != null">
                #{shopPhone,jdbcType=VARCHAR},
            </if>
            <if test="shopAddress != null">
                #{shopAddress,jdbcType=VARCHAR},
            </if>
            <if test="shopType != null">
                #{shopType,jdbcType=VARCHAR},
            </if>
            <if test="belongArea != null">
                #{belongArea,jdbcType=VARCHAR},
            </if>
            <if test="wgCode != null">
                #{wgCode,jdbcType=VARCHAR},
            </if>
            <if test="longitude != null">
                #{longitude,jdbcType=VARCHAR},
            </if>
            <if test="latitude != null">
                #{latitude,jdbcType=VARCHAR},
            </if>
            <if test="valid != null">
                #{valid,jdbcType=TINYINT},
            </if>
            <if test="createTime != null">
                #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="createBy != null">
                #{createBy,jdbcType=VARCHAR},
            </if>
            <if test="updateTime != null">
                #{updateTime,jdbcType=TIMESTAMP},
            </if>
            <if test="updateBy != null">
                #{updateBy,jdbcType=VARCHAR},
            </if>
            <if test="licenseCode != null">
                #{licenseCode,jdbcType=VARCHAR},
            </if>
            <if test="shopTypeName != null">
                #{shopTypeName,jdbcType=VARCHAR},
            </if>
        </trim>
    </insert>
    <select id="countByExample" parameterType="com.ruoyi.system.domain.grid.GridShopExample"
            resultType="java.lang.Long">
        select count(*) from grid_shop
        <if test="_parameter != null">
            <include refid="Example_Where_Clause"/>
        </if>
    </select>
    <update id="updateByExampleSelective" parameterType="map">
        update grid_shop
        <set>
            <if test="record.id != null">
                id = #{record.id,jdbcType=BIGINT},
            </if>
            <if test="record.shopName != null">
                shop_name = #{record.shopName,jdbcType=VARCHAR},
            </if>
            <if test="record.shopOwner != null">
                shop_owner = #{record.shopOwner,jdbcType=VARCHAR},
            </if>
            <if test="record.shopPhone != null">
                shop_phone = #{record.shopPhone,jdbcType=VARCHAR},
            </if>
            <if test="record.shopAddress != null">
                shop_address = #{record.shopAddress,jdbcType=VARCHAR},
            </if>
            <if test="record.shopType != null">
                shop_type = #{record.shopType,jdbcType=VARCHAR},
            </if>
            <if test="record.belongArea != null">
                belong_area = #{record.belongArea,jdbcType=VARCHAR},
            </if>
            <if test="record.wgCode != null">
                wg_code = #{record.wgCode,jdbcType=VARCHAR},
            </if>
            <if test="record.longitude != null">
                longitude = #{record.longitude,jdbcType=VARCHAR},
            </if>
            <if test="record.latitude != null">
                latitude = #{record.latitude,jdbcType=VARCHAR},
            </if>
            <if test="record.valid != null">
                valid = #{record.valid,jdbcType=TINYINT},
            </if>
            <if test="record.createTime != null">
                create_time = #{record.createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="record.createBy != null">
                create_by = #{record.createBy,jdbcType=VARCHAR},
            </if>
            <if test="record.updateTime != null">
                update_time = #{record.updateTime,jdbcType=TIMESTAMP},
            </if>
            <if test="record.updateBy != null">
                update_by = #{record.updateBy,jdbcType=VARCHAR},
            </if>
            <if test="record.licenseCode != null">
                license_code = #{record.licenseCode,jdbcType=VARCHAR},
            </if>
            <if test="record.shopTypeName != null">
                shop_type_name = #{record.shopTypeName,jdbcType=VARCHAR},
            </if>
        </set>
        <if test="_parameter != null">
            <include refid="Update_By_Example_Where_Clause"/>
        </if>
    </update>
    <update id="updateByExample" parameterType="map">
        update grid_shop
        set id = #{record.id,jdbcType=BIGINT},
        shop_name = #{record.shopName,jdbcType=VARCHAR},
        shop_owner = #{record.shopOwner,jdbcType=VARCHAR},
        shop_phone = #{record.shopPhone,jdbcType=VARCHAR},
        shop_address = #{record.shopAddress,jdbcType=VARCHAR},
        shop_type = #{record.shopType,jdbcType=VARCHAR},
        belong_area = #{record.belongArea,jdbcType=VARCHAR},
        wg_code = #{record.wgCode,jdbcType=VARCHAR},
        longitude = #{record.longitude,jdbcType=VARCHAR},
        latitude = #{record.latitude,jdbcType=VARCHAR},
        valid = #{record.valid,jdbcType=TINYINT},
        create_time = #{record.createTime,jdbcType=TIMESTAMP},
        create_by = #{record.createBy,jdbcType=VARCHAR},
        update_time = #{record.updateTime,jdbcType=TIMESTAMP},
        update_by = #{record.updateBy,jdbcType=VARCHAR},
        license_code = #{record.licenseCode,jdbcType=VARCHAR},
        shop_type_name = #{record.shopTypeName,jdbcType=VARCHAR}
        <if test="_parameter != null">
            <include refid="Update_By_Example_Where_Clause"/>
        </if>
    </update>
    <update id="updateByPrimaryKeySelective" parameterType="com.ruoyi.system.domain.grid.GridShop">
        update grid_shop
        <set>
            <if test="shopName != null">
                shop_name = #{shopName,jdbcType=VARCHAR},
            </if>
            <if test="shopOwner != null">
                shop_owner = #{shopOwner,jdbcType=VARCHAR},
            </if>
            <if test="shopPhone != null">
                shop_phone = #{shopPhone,jdbcType=VARCHAR},
            </if>
            <if test="shopAddress != null">
                shop_address = #{shopAddress,jdbcType=VARCHAR},
            </if>
            <if test="shopType != null">
                shop_type = #{shopType,jdbcType=VARCHAR},
            </if>
            <if test="belongArea != null">
                belong_area = #{belongArea,jdbcType=VARCHAR},
            </if>
            <if test="wgCode != null">
                wg_code = #{wgCode,jdbcType=VARCHAR},
            </if>
            <if test="longitude != null">
                longitude = #{longitude,jdbcType=VARCHAR},
            </if>
            <if test="latitude != null">
                latitude = #{latitude,jdbcType=VARCHAR},
            </if>
            <if test="valid != null">
                valid = #{valid,jdbcType=TINYINT},
            </if>
            <if test="createTime != null">
                create_time = #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="createBy != null">
                create_by = #{createBy,jdbcType=VARCHAR},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime,jdbcType=TIMESTAMP},
            </if>
            <if test="updateBy != null">
                update_by = #{updateBy,jdbcType=VARCHAR},
            </if>
            <if test="licenseCode != null">
                license_code = #{licenseCode,jdbcType=VARCHAR},
            </if>
            <if test="shopTypeName != null">
                shop_type_name = #{shopTypeName,jdbcType=VARCHAR},
            </if>
        </set>
        where id = #{id,jdbcType=BIGINT}
    </update>
    <update id="updateByPrimaryKey" parameterType="com.ruoyi.system.domain.grid.GridShop">
        update grid_shop
        set shop_name      = #{shopName,jdbcType=VARCHAR},
            shop_owner     = #{shopOwner,jdbcType=VARCHAR},
            shop_phone     = #{shopPhone,jdbcType=VARCHAR},
            shop_address   = #{shopAddress,jdbcType=VARCHAR},
            shop_type      = #{shopType,jdbcType=VARCHAR},
            belong_area    = #{belongArea,jdbcType=VARCHAR},
            wg_code        = #{wgCode,jdbcType=VARCHAR},
            longitude      = #{longitude,jdbcType=VARCHAR},
            latitude       = #{latitude,jdbcType=VARCHAR},
            valid          = #{valid,jdbcType=TINYINT},
            create_time    = #{createTime,jdbcType=TIMESTAMP},
            create_by      = #{createBy,jdbcType=VARCHAR},
            update_time    = #{updateTime,jdbcType=TIMESTAMP},
            update_by      = #{updateBy,jdbcType=VARCHAR},
            license_code   = #{licenseCode,jdbcType=VARCHAR},
            shop_type_name = #{shopTypeName,jdbcType=VARCHAR}
        where id = #{id,jdbcType=BIGINT}
    </update>

    <select id="countGridShop" parameterType="java.lang.String" resultType="map">
        select a.name, count(b.id) as number from bs_common as a LEFT JOIN grid_shop as b on a.code = b.shop_type and
        b.valid = 1
        <if test="wgCodeLikes != null and wgCodeLikes.size() > 0">
            and (
            <foreach collection="wgCodeLikes" item="wgCode" open="(" close=")" separator="or">
                b.wg_code like CONCAT(#{wgCode}, '%')
            </foreach>
            )
        </if>
        where a.parent_id = (select id from bs_common where code = 'spjylx') and a.is_valid = '1' GROUP BY a.code ORDER
        BY number desc, a.sort
    </select>

    <select id="countGridShopByGrid" parameterType="java.lang.String" resultType="map">
        select a.wg_name as name, count(b.id) as number
        from grid_region as a
                 LEFT JOIN grid_shop as b on b.wg_code like concat(a.wg_code, '%')
            and b.valid = 1
        where a.level = '2'
          and a.is_valid = '1'
        GROUP BY a.wg_code
        ORDER BY number desc, a.wg_code
    </select>
    <select id="countByParam" resultType="java.lang.Integer" parameterType="com.ruoyi.system.domain.grid.vo.GridShopSearchParam">
        select count(1) from grid_shop where valid = '1'
        <if test="wgCodeLikes != null and wgCodeLikes.size() > 0">
            and (
            <foreach collection="wgCodeLikes" item="wgCode" open="(" close=")" separator="or">
                wg_code like CONCAT(#{wgCode}, '%')
            </foreach>
            )
        </if>
    </select>
    <select id="listByParam" resultType="com.ruoyi.system.domain.grid.GridShop" parameterType="com.ruoyi.system.domain.grid.vo.GridShopSearchParam">
        select * from grid_shop where valid = '1'
        <if test="wgCodeLikes != null and wgCodeLikes.size() > 0">
            and (
            <foreach collection="wgCodeLikes" item="wgCode" open="(" close=")" separator="or">
                wg_code like CONCAT(#{wgCode}, '%')
            </foreach>
            )
        </if>
        <if test="shopType != null and shopType != ''">
            and shop_type = #{shopType}
        </if>
        <if test="belongArea != null and belongArea !=''">
            and belong_area like CONCAT('%', #{belongArea}, '%')
        </if>
        <if test="shopName != null and shopName != ''">
            and shop_name like CONCAT('%', #{shopName}, '%')
        </if>
        order by id desc
    </select>
    <select id="listShopPoint" resultType="com.ruoyi.system.domain.grid.vo.SimpleGridShopItem">
        select id, shop_name as shopName, wg_code as wgCode,longitude,latitude from grid_shop where valid = '1'
        and longitude is not null and latitude is not null and longitude != '' and latitude != ''
        <if test="name != null and name != ''">
            and shop_name like CONCAT('%', #{name}, '%')
        </if>
        <if test="wgCode != null and wgCode != ''">
            and wg_code like CONCAT(#{wgCode}, '%')
        </if>
    </select>

</mapper>
