You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

293 lines
21 KiB

<?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.qs.serve.modules.bms.mapper.BmsChannelPointMapper">
<resultMap id="bmsChannelPointMap" type="com.qs.serve.modules.bms.entity.BmsChannelPoint" >
<result property="id" column="id"/>
<result property="channelId" column="channel_id"/>
<result property="channelName" column="channel_name"/>
<result property="pointCode" column="point_code"/>
<result property="pointName" column="point_name"/>
<result property="shopArea" column="shop_area"/>
<result property="countCheckstand" column="count_checkstand"/>
<result property="pointLevel" column="point_level"/>
<result property="pointType" column="point_type"/>
<result property="address" column="address"/>
<result property="saleRegionId" column="sale_region_id"/>
<result property="saleRegionPath" column="sale_region_path"/>
<result property="saleRegionPathIds" column="sale_region_path_ids"/>
<result property="bizRegionId" column="biz_region_id"/>
<result property="bizRegionPath" column="biz_region_path"/>
<result property="bizRegionPathIds" column="biz_region_path_ids"/>
<result property="localY" column="local_y"/>
<result property="localX" column="local_x"/>
<result property="mapAddress" column="map_address"/>
<result property="remark" column="remark"/>
<result property="createTime" column="create_time"/>
<result property="updateTime" column="update_time"/>
<result property="tenantId" column="tenant_id"/>
<result property="delFlag" column="del_flag"/>
<result property="createBy" column="create_by"/>
<result property="updateBy" column="update_by"/>
<result property="costFlag" column="cost_flag"/>
</resultMap>
<sql id="bmsChannelPointSql">
bms_channel_point.`id`,
bms_channel_point.`channel_id`,
bms_channel_point.`channel_name`,
bms_channel_point.`point_code`,
bms_channel_point.`point_name`,
bms_channel_point.`shop_area`,
bms_channel_point.`count_checkstand`,
bms_channel_point.`point_level`,
bms_channel_point.`point_type`,
bms_channel_point.`address`,
bms_channel_point.`sale_region_id`,
bms_channel_point.`sale_region_path`,
bms_channel_point.`sale_region_path_ids`,
bms_channel_point.`biz_region_id`,
bms_channel_point.`biz_region_path`,
bms_channel_point.`biz_region_path_ids`,
bms_channel_point.`remark`,
bms_channel_point.`create_time`,
bms_channel_point.`update_time`,
bms_channel_point.`tenant_id`,
bms_channel_point.`local_x`,
bms_channel_point.`local_y`,
bms_channel_point.`map_address`,
bms_channel_point.`del_flag`,
bms_channel_point.`cost_flag`,
bms_channel_point.`create_by`,
bms_channel_point.`update_by` </sql>
<select id="selectChannelPointList" parameterType="com.qs.serve.modules.bms.entity.BmsChannelPoint" resultMap="bmsChannelPointMap">
SELECT <include refid="bmsChannelPointSql"/>
FROM `bms_channel_point` `bms_channel_point`
<if test="query.supplierId!=null and query.supplierId!=''">
LEFT JOIN bms_supplier_channel ON bms_supplier_channel.`channel_id` = `bms_channel_point`.`channel_id`
</if>
<where>
and `bms_channel_point`.`del_flag` = 0
<if test="query.supplierId!=null and query.supplierId!=''">
and bms_supplier_channel.`supplier_id` = #{query.supplierId} and bms_supplier_channel.`del_flag` = 0
</if>
<if test="query.id != null"> and `bms_channel_point`.`id` = #{query.id}</if>
<if test="query.channelId != null"> and `bms_channel_point`.`channel_id` = #{query.channelId}</if>
<if test="query.channelName != null and query.channelName != ''"> and `bms_channel_point`.`channel_name` like concat('%',#{query.channelName},'%') </if>
<if test="query.pointCode != null and query.pointCode != ''"> and `bms_channel_point`.`point_code` like concat('%',#{query.pointCode},'%') </if>
<if test="query.pointName != null and query.pointName != ''"> and `bms_channel_point`.`point_name` like concat('%',#{query.pointName},'%') </if>
<if test="query.shopArea != null and query.shopArea != ''"> and `bms_channel_point`.`shop_area` = #{query.shopArea}</if>
<if test="query.countCheckstand != null"> and `bms_channel_point`.`count_checkstand` = #{query.countCheckstand}</if>
<if test="query.pointLevel != null and query.pointLevel != ''"> and `bms_channel_point`.`point_level` = #{query.pointLevel}</if>
<if test="query.pointType != null and query.pointType != ''"> and `bms_channel_point`.`point_type` like concat('%',#{query.pointType},'%') </if>
<if test="query.address != null and query.address != ''"> and `bms_channel_point`.`address` = #{query.address}</if>
<if test="query.saleRegionId != null and query.saleRegionId != ''"> and `bms_channel_point`.`sale_region_id` = #{query.saleRegionId}</if>
<if test="query.saleRegionPath != null and query.saleRegionPath != ''"> and `bms_channel_point`.`sale_region_path` like concat('%',#{query.saleRegionPath},'%') </if>
<if test="query.saleRegionPathIds != null and query.saleRegionPathIds != ''"> and `bms_channel_point`.`sale_region_path_ids` = #{query.saleRegionPathIds}</if>
<if test="query.bizRegionId != null and query.bizRegionId != ''"> and `bms_channel_point`.`biz_region_id` = #{query.bizRegionId}</if>
<if test="query.bizRegionPath != null and query.bizRegionPath != ''"> and `bms_channel_point`.`biz_region_path` like concat('%',#{query.bizRegionPath},'%') </if>
<if test="query.bizRegionPathIds != null and query.bizRegionPathIds != ''"> and `bms_channel_point`.`biz_region_path_ids` = #{query.bizRegionPathIds}</if>
<if test="query.remark != null and query.remark != ''"> and `bms_channel_point`.`remark` = #{query.remark}</if>
<if test="query.createTime != null"> and `bms_channel_point`.`create_time` = #{query.createTime}</if>
<if test="query.updateTime != null"> and `bms_channel_point`.`update_time` = #{query.updateTime}</if>
<if test="query.tenantId != null and query.tenantId != ''"> and `bms_channel_point`.`tenant_id` = #{query.tenantId}</if>
<if test="query.createBy != null and query.createBy != ''"> and `bms_channel_point`.`create_by` = #{query.createBy}</if>
<if test="query.updateBy != null and query.updateBy != ''"> and `bms_channel_point`.`update_by` = #{query.updateBy}</if>
<if test="query.costFlag != null and query.costFlag != ''"> and `bms_channel_point`.`cost_flag` = #{query.costFlag}</if>
</where>
ORDER BY `bms_channel_point`.`create_time` DESC
</select>
<resultMap id="userPointList4VisitMap" type="com.qs.serve.modules.bms.entity.vo.BmsUserPoint4VisitVo" >
<result property="pointId" column="id"/>
<result property="pointName" column="point_name"/>
<result property="pointCode" column="point_code"/>
<result property="distance" column="distance"/>
<result property="channelName" column="channel_name"/>
<result property="address" column="address"/>
<result property="mapAddress" column="map_address"/>
<result property="localY" column="local_y"/>
<result property="localX" column="local_x"/>
</resultMap>
<select id="selectUserPointList4Visit" resultType="com.qs.serve.modules.bms.entity.vo.BmsUserPoint4VisitVo" resultMap="userPointList4VisitMap">
SELECT
`bms_channel_point`.id,
`bms_channel_point`.point_code,
`bms_channel_point`.point_name,
`bms_channel_point`.channel_name,
`bms_channel_point`.address,
`bms_channel_point`.local_y,
`bms_channel_point`.local_x,
`bms_channel_point`.map_address
<if test="query.localY!=null and query.localX!=null">
,st_distance_sphere (
POINT ( bms_channel_point.local_y, bms_channel_point.local_x ),
POINT ( #{query.localY}, #{query.localX} )) AS distance
</if>
FROM
( SELECT channel_id FROM `bms_supplier_channel`
LEFT JOIN `his_user_supplier` ON `his_user_supplier`.supplier_id = bms_supplier_channel.supplier_id
where his_user_supplier.user_id in
<foreach collection="userIds" item ="selectId" index="i" open="(" close=")" separator=",">
#{selectId}
</foreach>
and `bms_supplier_channel`.`del_flag` = 0
GROUP BY channel_id
) tmp
left join bms_channel_point ON `tmp`.channel_id = bms_channel_point.`channel_id`
<where>
and `bms_channel_point`.`del_flag` = 0
and `bms_supplier_channel`.`del_flag` = 0
<if test="query.pointCode != null and query.pointCode != ''"> and `bms_channel_point`.`point_code` like concat('%',#{query.pointCode},'%') </if>
<if test="query.pointName != null and query.pointName != ''"> and `bms_channel_point`.`point_name` like concat('%',#{query.pointName},'%') </if>
<if test="userIds != null and userIds.size > 0">
and his_user_supplier.user_id in
<foreach collection="userIds" item ="selectId" index="i" open="(" close=")" separator=",">
#{selectId}
</foreach>
</if>
</where>
ORDER BY
<if test="query.localY!=null and query.localX!=null">
-distance desc,
</if>
bms_channel_point.id
</select>
<select id="selectUserPointList4My" resultType="com.qs.serve.modules.bms.entity.BmsChannelPoint">
SELECT
<include refid="bmsChannelPointSql"/>
FROM (
SELECT DISTINCT mu.point_id target_id FROM `his_user_channel_point` mu WHERE del_flag = 0 AND user_id = #{query.userId} AND tenant_id = #{query.tenantId}
) pmu
LEFT JOIN `bms_channel_point` `bms_channel_point` ON `bms_channel_point`.id = pmu.target_id
<if test="query.supplierId!=null and query.supplierId!=''">
LEFT JOIN bms_supplier_channel ON bms_supplier_channel.`channel_id` = `bms_channel_point`.`channel_id`
</if>
<where>
and `bms_channel_point`.`del_flag` = 0
<if test="query.supplierId!=null and query.supplierId!=''">
and bms_supplier_channel.`supplier_id` = #{query.supplierId} and bms_supplier_channel.`del_flag` = 0
</if>
<if test="query.id != null"> and `bms_channel_point`.`id` = #{query.id}</if>
<if test="query.channelId != null"> and `bms_channel_point`.`channel_id` = #{query.channelId}</if>
<if test="query.channelName != null and query.channelName != ''"> and `bms_channel_point`.`channel_name` like concat('%',#{query.channelName},'%') </if>
<if test="query.pointCode != null and query.pointCode != ''"> and `bms_channel_point`.`point_code` like concat('%',#{query.pointCode},'%') </if>
<if test="query.pointName != null and query.pointName != ''"> and `bms_channel_point`.`point_name` like concat('%',#{query.pointName},'%') </if>
<if test="query.shopArea != null and query.shopArea != ''"> and `bms_channel_point`.`shop_area` = #{query.shopArea}</if>
<if test="query.countCheckstand != null"> and `bms_channel_point`.`count_checkstand` = #{query.countCheckstand}</if>
<if test="query.pointLevel != null and query.pointLevel != ''"> and `bms_channel_point`.`point_level` = #{query.pointLevel}</if>
<if test="query.pointType != null and query.pointType != ''"> and `bms_channel_point`.`point_type` like concat('%',#{query.pointType},'%') </if>
<if test="query.address != null and query.address != ''"> and `bms_channel_point`.`address` = #{query.address}</if>
<if test="query.saleRegionId != null and query.saleRegionId != ''"> and `bms_channel_point`.`sale_region_id` = #{query.saleRegionId}</if>
<if test="query.saleRegionPath != null and query.saleRegionPath != ''"> and `bms_channel_point`.`sale_region_path` like concat('%',#{query.saleRegionPath},'%') </if>
<if test="query.saleRegionPathIds != null and query.saleRegionPathIds != ''"> and `bms_channel_point`.`sale_region_path_ids` = #{query.saleRegionPathIds}</if>
<if test="query.bizRegionId != null and query.bizRegionId != ''"> and `bms_channel_point`.`biz_region_id` = #{query.bizRegionId}</if>
<if test="query.bizRegionPath != null and query.bizRegionPath != ''"> and `bms_channel_point`.`biz_region_path` like concat('%',#{query.bizRegionPath},'%') </if>
<if test="query.bizRegionPathIds != null and query.bizRegionPathIds != ''"> and `bms_channel_point`.`biz_region_path_ids` = #{query.bizRegionPathIds}</if>
<if test="query.remark != null and query.remark != ''"> and `bms_channel_point`.`remark` = #{query.remark}</if>
</where>
ORDER BY
bms_channel_point.id
</select>
<select id="selectUserPointList4MyUnder" resultType="com.qs.serve.modules.bms.entity.BmsChannelPoint">
SELECT
<include refid="bmsChannelPointSql"/>
FROM (
SELECT DISTINCT mu.point_id target_id
FROM `his_user_channel_point` mu
WHERE
1=1
<if test="(query.userIdList!=null and query.userIdList.size > 0) or (query.sourceIdsList!=null and query.sourceIdsList.size > 0)">
AND (
<if test="query.userIdList!=null and query.userIdList.size > 0">
`mu`.user_id in
<foreach collection="query.userIdList" item="selectId" index="i" open="(" close=")" separator=",">
#{selectId}
</foreach>
</if>
<if test="query.sourceIdsList!=null and query.sourceIdsList.size > 0">
<if test="query.userIdList!=null and query.userIdList.size > 0">
or
</if>
<foreach collection="query.sourceIdsList" item="selectId" index="i" open="(" close=")" separator="or">
`mu`.`source_ids` like concat(#{selectId},"_")
</foreach>
</if>
)
</if>
) pmu
LEFT JOIN `bms_channel_point` `bms_channel_point` ON `bms_channel_point`.id = pmu.target_id
<if test="query.supplierId!=null and query.supplierId!=''">
LEFT JOIN bms_supplier_channel ON bms_supplier_channel.`channel_id` = `bms_channel_point`.`channel_id`
</if>
<where>
and `bms_channel_point`.`del_flag` = 0
<if test="query.supplierId!=null and query.supplierId!=''">
and bms_supplier_channel.`supplier_id` = #{query.supplierId} and bms_supplier_channel.`del_flag` = 0
</if>
<if test="query.id != null"> and `bms_channel_point`.`id` = #{query.id}</if>
<if test="query.channelId != null"> and `bms_channel_point`.`channel_id` = #{query.channelId}</if>
<if test="query.channelName != null and query.channelName != ''"> and `bms_channel_point`.`channel_name` like concat('%',#{query.channelName},'%') </if>
<if test="query.pointCode != null and query.pointCode != ''"> and `bms_channel_point`.`point_code` like concat('%',#{query.pointCode},'%') </if>
<if test="query.pointName != null and query.pointName != ''"> and `bms_channel_point`.`point_name` like concat('%',#{query.pointName},'%') </if>
<if test="query.shopArea != null and query.shopArea != ''"> and `bms_channel_point`.`shop_area` = #{query.shopArea}</if>
<if test="query.countCheckstand != null"> and `bms_channel_point`.`count_checkstand` = #{query.countCheckstand}</if>
<if test="query.pointLevel != null and query.pointLevel != ''"> and `bms_channel_point`.`point_level` = #{query.pointLevel}</if>
<if test="query.pointType != null and query.pointType != ''"> and `bms_channel_point`.`point_type` like concat('%',#{query.pointType},'%') </if>
<if test="query.address != null and query.address != ''"> and `bms_channel_point`.`address` = #{query.address}</if>
<if test="query.saleRegionId != null and query.saleRegionId != ''"> and `bms_channel_point`.`sale_region_id` = #{query.saleRegionId}</if>
<if test="query.saleRegionPath != null and query.saleRegionPath != ''"> and `bms_channel_point`.`sale_region_path` like concat('%',#{query.saleRegionPath},'%') </if>
<if test="query.saleRegionPathIds != null and query.saleRegionPathIds != ''"> and `bms_channel_point`.`sale_region_path_ids` = #{query.saleRegionPathIds}</if>
<if test="query.bizRegionId != null and query.bizRegionId != ''"> and `bms_channel_point`.`biz_region_id` = #{query.bizRegionId}</if>
<if test="query.bizRegionPath != null and query.bizRegionPath != ''"> and `bms_channel_point`.`biz_region_path` like concat('%',#{query.bizRegionPath},'%') </if>
<if test="query.bizRegionPathIds != null and query.bizRegionPathIds != ''"> and `bms_channel_point`.`biz_region_path_ids` = #{query.bizRegionPathIds}</if>
<if test="query.remark != null and query.remark != ''"> and `bms_channel_point`.`remark` = #{query.remark}</if>
</where>
ORDER BY
bms_channel_point.id
</select>
<select id="selectPointByUserIds" resultType="com.qs.serve.modules.bms.entity.BmsChannelPoint">
SELECT <include refid="bmsChannelPointSql"/> FROM
( SELECT channel_id FROM `bms_supplier_channel`
LEFT JOIN `his_user_supplier` ON `his_user_supplier`.supplier_id = bms_supplier_channel.supplier_id
where his_user_supplier.user_id in
<foreach collection="userIds" item ="selectId" index="i" open="(" close=")" separator=",">
#{selectId}
</foreach>
and `bms_supplier_channel`.`del_flag` = 0
GROUP BY channel_id
) tmp left join`bms_channel_point` `bms_channel_point` ON `tmp`.channel_id = bms_channel_point.`channel_id`
<where>
and `bms_channel_point`.`del_flag` = 0
<if test="query.id != null"> and `bms_channel_point`.`id` = #{query.id}</if>
<if test="query.channelId != null"> and `bms_channel_point`.`channel_id` = #{query.channelId}</if>
<if test="query.channelName != null and query.channelName != ''"> and `bms_channel_point`.`channel_name` like concat('%',#{query.channelName},'%') </if>
<if test="query.pointCode != null and query.pointCode != ''"> and `bms_channel_point`.`point_code` like concat('%',#{query.pointCode},'%') </if>
<if test="query.pointName != null and query.pointName != ''"> and `bms_channel_point`.`point_name` like concat('%',#{query.pointName},'%') </if>
<if test="query.shopArea != null and query.shopArea != ''"> and `bms_channel_point`.`shop_area` = #{query.shopArea}</if>
<if test="query.countCheckstand != null"> and `bms_channel_point`.`count_checkstand` = #{query.countCheckstand}</if>
<if test="query.pointLevel != null and query.pointLevel != ''"> and `bms_channel_point`.`point_level` = #{query.pointLevel}</if>
<if test="query.pointType != null and query.pointType != ''"> and `bms_channel_point`.`point_type` like concat('%',#{query.pointType},'%') </if>
<if test="query.address != null and query.address != ''"> and `bms_channel_point`.`address` = #{query.address}</if>
<if test="query.saleRegionId != null and query.saleRegionId != ''"> and `bms_channel_point`.`sale_region_id` = #{query.saleRegionId}</if>
<if test="query.saleRegionPath != null and query.saleRegionPath != ''"> and `bms_channel_point`.`sale_region_path` like concat('%',#{query.saleRegionPath},'%') </if>
<if test="query.saleRegionPathIds != null and query.saleRegionPathIds != ''"> and `bms_channel_point`.`sale_region_path_ids` = #{query.saleRegionPathIds}</if>
<if test="query.bizRegionId != null and query.bizRegionId != ''"> and `bms_channel_point`.`biz_region_id` = #{query.bizRegionId}</if>
<if test="query.bizRegionPath != null and query.bizRegionPath != ''"> and `bms_channel_point`.`biz_region_path` like concat('%',#{query.bizRegionPath},'%') </if>
<if test="query.bizRegionPathIds != null and query.bizRegionPathIds != ''"> and `bms_channel_point`.`biz_region_path_ids` = #{query.bizRegionPathIds}</if>
<if test="query.remark != null and query.remark != ''"> and `bms_channel_point`.`remark` = #{query.remark}</if>
</where>
</select>
</mapper>