<?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.chargingPile.mapper.SiteMapper">
|
|
<!-- 通用查询映射结果 -->
|
<resultMap id="BaseResultMap" type="com.ruoyi.chargingPile.api.model.Site">
|
<id column="id" property="id" />
|
<result column="partner_id" property="partnerId" />
|
<result column="`code`" property="code" />
|
<result column="`name`" property="name" />
|
<result column="site_type" property="siteType" />
|
<result column="business_category" property="businessCategory" />
|
<result column="status" property="status" />
|
<result column="construction_site" property="constructionSite" />
|
<result column="img_url" property="imgUrl" />
|
<result column="province" property="province" />
|
<result column="province_code" property="provinceCode" />
|
<result column="city" property="city" />
|
<result column="city_code" property="cityCode" />
|
<result column="districts" property="districts" />
|
<result column="districts_code" property="districtsCode" />
|
<result column="lon" property="lon" />
|
<result column="lat" property="lat" />
|
<result column="address" property="address" />
|
<result column="country_code" property="countryCode" />
|
<result column="phone" property="phone" />
|
<result column="service_phone" property="servicePhone" />
|
<result column="guide" property="guide" />
|
<result column="start_service_time" property="startServiceTime" />
|
<result column="end_service_time" property="endServiceTime" />
|
<result column="service_description" property="serviceDescription" />
|
<result column="vehicle_description" property="vehicleDescription" />
|
<result column="parking_space" property="parkingSpace" />
|
<result column="rate_description" property="rateDescription" />
|
<result column="space_charge_explain" property="spaceChargeExplain" />
|
<result column="accounting_strategy_id" property="accountingStrategyId" />
|
<result column="establishment_time" property="establishmentTime" />
|
<result column="sort" property="sort" />
|
<result column="remark" property="remark" />
|
<result column="mark" property="mark" />
|
<result column="create_time" property="createTime" />
|
<result column="del_flag" property="delFlag" />
|
</resultMap>
|
|
<!-- 通用查询结果列 -->
|
<sql id="Base_Column_List">
|
id, partner_id, code, `name`, site_type, business_category, status, construction_site, img_url, province, province_code, city, city_code, districts, districts_code, lon, lat, address, country_code, phone, service_phone, guide, start_service_time, end_service_time, service_description, vehicle_description, parking_space, rate_description, space_charge_explain, accounting_strategy_id, establishment_time, sort, remark, create_time, del_flag, mark
|
</sql>
|
|
<select id="getSiteList" resultType="com.ruoyi.chargingPile.api.dto.GetSiteListDTO">
|
select
|
a.id,
|
a.code,
|
a.name,
|
a.partner_id as partnerId,
|
b.name as partnerName,
|
a.site_type as siteType,
|
a.business_category as businessCategory,
|
a.status,
|
CONCAT(a.province, a.city, a.districts, a.address) as address,
|
a.phone,
|
a.service_phone as servicePhone,
|
a.parking_space as parkingSpace,
|
DATE_FORMAT(a.establishment_time, '%Y-%m-%d %H:%i:%s') as establishmentTime,
|
c.num as chargingPileNumber,
|
a.sort,
|
a.lon,
|
a.lat,
|
a.accounting_strategy_id as accountingStrategyId,
|
if(a.accounting_strategy_id is null, 1, if(d.site_id is null, 1, 2)) as accountingStrategyType
|
from t_site a
|
left join t_partner b on (a.partner_id = b.id)
|
left join (select site_id, count(1) as num from t_charging_pile where del_flag = 0 group by site_id) c on (a.id = c.site_id)
|
left join t_accounting_strategy d on (a.accounting_strategy_id = d.id)
|
WHERE a.del_flag = 0
|
<if test="null != item.name and '' != item.name">
|
and a.name like CONCAT('%', #{item.name}, '%')
|
</if>
|
<if test="null != item.partnerName and '' != item.partnerName">
|
and b.name like CONCAT('%', #{item.partnerName}, '%')
|
</if>
|
<if test="null != item.siteType">
|
and a.site_type = #{item.siteType}
|
</if>
|
<if test="null != item.businessCategory">
|
and a.business_category = #{item.businessCategory}
|
</if>
|
<if test="null != item.status">
|
and a.status = #{item.status}
|
</if>
|
<if test="null != item.provinceCode and '' != item.provinceCode">
|
and a.province_code = #{item.provinceCode}
|
</if>
|
<if test="null != item.cityCode and '' != item.cityCode">
|
and a.city_code = #{item.cityCode}
|
</if>
|
<if test="null != item.districtsCode and '' != item.districtsCode">
|
and a.districts_code = #{item.districtsCode}
|
</if>
|
<if test="null != ids">
|
and a.id in
|
<foreach collection="ids" item="itemm" index="index" open="(" separator="," close=")">
|
#{itemm}
|
</foreach>
|
</if>
|
order by a.sort desc, a.create_time desc
|
</select>
|
|
<select id="pageList" resultType="com.ruoyi.chargingPile.api.vo.SiteVO">
|
select
|
ts.id, ts.partner_id, ts.code, ts.`name`, ts.site_type, ts.business_category, ts.status, ts.construction_site, ts.img_url,
|
ts.lon, ts.lat, ts.address, ts.country_code, ts.phone,ts.guide, ts.service_description, ts.vehicle_description,
|
ts.parking_space, ts.rate_description, ts.space_charge_explain, ts.accounting_strategy_id,ts.del_flag,tcg.fastCount,
|
tcg.slowCount,tcg.superCount,tasd.electrovalence,tasd.vipElectrovalence,tasd.serviceCharge,tasd.electrovalenceOriginal,tcg.superFreeCount,tcg.fastFreeCount,tcg.slowFreeCount,
|
ROUND(
|
6378.138 * 2 * ASIN(
|
SQRT(
|
POW(
|
SIN(
|
(
|
#{query.lat} * PI() / 180 - ts.lat * PI() / 180
|
) / 2
|
),
|
2
|
) + COS(#{query.lat} * PI() / 180) * COS(ts.lat * PI() / 180) * POW(
|
SIN(
|
(
|
#{query.lon} * PI() / 180 - ts.lon * PI() / 180
|
) / 2
|
),
|
2
|
)
|
)
|
) * 1000
|
) AS distance
|
from t_site ts
|
left join (
|
select site_id,
|
SUM(CASE WHEN charge_mode = 1 THEN 1 ELSE 0 END) AS superCount,
|
SUM(CASE WHEN charge_mode = 2 THEN 1 ELSE 0 END) AS fastCount,
|
SUM(CASE WHEN charge_mode = 3 THEN 1 ELSE 0 END) AS slowCount,
|
SUM(CASE WHEN charge_mode = 1 and `status` = 2 THEN 1 ELSE 0 END) AS superFreeCount,
|
SUM(CASE WHEN charge_mode = 2 and `status` = 2 THEN 1 ELSE 0 END) AS fastFreeCount,
|
SUM(CASE WHEN charge_mode = 3 and `status` = 2 THEN 1 ELSE 0 END) AS slowFreeCount
|
from
|
t_charging_gun
|
where
|
del_flag = ${@com.ruoyi.common.core.enums.DelFlagEnum@NO.getCode()}
|
group by
|
site_id) tcg on (ts.id = tcg.site_id)
|
left join (
|
select
|
a.accounting_strategy_id,
|
a.service_charge AS serviceCharge,
|
a.electrovalence AS electrovalenceOriginal,
|
(a.electrovalence+a.service_charge) AS electrovalence,
|
(a.electrovalence + (a.service_charge*b.discount)) AS vipElectrovalence
|
from
|
t_accounting_strategy_detail a
|
left join
|
t_accounting_strategy b on (a.accounting_strategy_id = b.id)
|
where b.del_flag = ${@com.ruoyi.common.core.enums.DelFlagEnum@NO.getCode()}
|
AND DATE_FORMAT(NOW(), '%H:%i:%s') between a.start_time and a.end_time) tasd on (ts.accounting_strategy_id = tasd.accounting_strategy_id)
|
<where>
|
<if test="null != query.name and '' != query.name">
|
and ts.`name` like CONCAT('%', #{query.name}, '%')
|
</if>
|
<if test="null != query.cityCode and '' != query.cityCode">
|
and ts.cityCode = #{query.cityCode}
|
</if>
|
AND ts.del_flag = ${@com.ruoyi.common.core.enums.DelFlagEnum@NO.getCode()}
|
AND ts.status = ${@com.ruoyi.common.core.enums.status.SiteStatusEnum@NORMAL_USE.getCode()}
|
AND ts.accounting_strategy_id IS NOT NULL
|
</where>
|
<if test="query.sortType != null">
|
<choose>
|
<when test="query.sortType == 1">
|
ORDER BY distance ASC
|
</when>
|
<when test="query.sortType == 2">
|
ORDER BY tasd.electrovalence ASC
|
</when>
|
<when test="query.sortType == 3">
|
ORDER BY (tcg.fastCount + tcg.slowCount + tcg.superCount) DESC
|
</when>
|
</choose>
|
</if>
|
</select>
|
<select id="getDetailById" resultType="com.ruoyi.chargingPile.api.vo.SiteDetailVO">
|
SELECT id, partner_id, code, `name`, site_type, business_category, status, construction_site, img_url, province, province_code,
|
city, city_code, districts, districts_code, lon, lat, address, country_code, phone, service_phone, guide, start_service_time,
|
end_service_time, service_description, vehicle_description, parking_space, rate_description, space_charge_explain,
|
accounting_strategy_id, establishment_time, sort, remark, create_time, del_flag, mark,
|
ROUND(
|
6378.138 * 2 * ASIN(
|
SQRT(
|
POW(
|
SIN(
|
(
|
#{query.lat} * PI() / 180 - lat * PI() / 180
|
) / 2
|
),
|
2
|
) + COS(#{query.lat} * PI() / 180) * COS(lat * PI() / 180) * POW(
|
SIN(
|
(
|
#{query.lon} * PI() / 180 - lon * PI() / 180
|
) / 2
|
),
|
2
|
)
|
)
|
) * 1000
|
) AS distance
|
FROM t_site WHERE id = #{query.siteId} AND del_flag = ${@com.ruoyi.common.core.enums.DelFlagEnum@NO.getCode()}
|
</select>
|
<select id="getSiteListParkLot" resultType="com.ruoyi.chargingPile.api.model.Site">
|
select ts.id, ts.partner_id, ts.code, ts.`name`, ts.site_type, ts.business_category, ts.status
|
from t_site ts
|
<where>
|
<if test="null != ids and ids.size()>0">
|
AND ts.id IN
|
<foreach collection="ids" item="id" index="index" open="(" separator="," close=")">
|
#{id}
|
</foreach>
|
</if>
|
AND ts.del_flag = ${@com.ruoyi.common.core.enums.DelFlagEnum@NO.getCode()}
|
</where>
|
</select>
|
<select id="getSiteListGun" resultType="com.ruoyi.chargingPile.api.model.Site">
|
select <include refid="Base_Column_List"></include>
|
from t_site
|
<where>
|
<if test="null != ids and ids.size()>0">
|
AND id IN
|
<foreach collection="ids" item="id" index="index" open="(" separator="," close=")">
|
#{id}
|
</foreach>
|
</if>
|
AND del_flag = ${@com.ruoyi.common.core.enums.DelFlagEnum@NO.getCode()}
|
</where>
|
</select>
|
<select id="getMapSiteList" resultType="com.ruoyi.chargingPile.api.vo.SiteVO">
|
select
|
ts.id, ts.partner_id, ts.code, ts.`name`, ts.site_type, ts.business_category, ts.status, ts.construction_site, ts.img_url,
|
ts.lon, ts.lat, ts.address, ts.country_code, ts.phone,ts.guide, ts.service_description, ts.vehicle_description,
|
ts.parking_space, ts.rate_description, ts.space_charge_explain, ts.accounting_strategy_id,ts.del_flag,tcg.fastCount,
|
tcg.slowCount,tcg.superCount,tasd.electrovalence,tasd.vipElectrovalence,tcg.superFreeCount,tcg.fastFreeCount,tcg.slowFreeCount,
|
ROUND(
|
6378.138 * 2 * ASIN(
|
SQRT(
|
POW(
|
SIN(
|
(
|
#{query.lat} * PI() / 180 - ts.lat * PI() / 180
|
) / 2
|
),
|
2
|
) + COS(#{query.lat} * PI() / 180) * COS(ts.lat * PI() / 180) * POW(
|
SIN(
|
(
|
#{query.lon} * PI() / 180 - ts.lon * PI() / 180
|
) / 2
|
),
|
2
|
)
|
)
|
) * 1000
|
) AS distance
|
from t_site ts
|
left join (
|
select site_id,
|
SUM(CASE WHEN charge_mode = 1 THEN 1 ELSE 0 END) AS superCount,
|
SUM(CASE WHEN charge_mode = 2 THEN 1 ELSE 0 END) AS fastCount,
|
SUM(CASE WHEN charge_mode = 3 THEN 1 ELSE 0 END) AS slowCount,
|
SUM(CASE WHEN charge_mode = 1 and `status` = 2 THEN 1 ELSE 0 END) AS superFreeCount,
|
SUM(CASE WHEN charge_mode = 2 and `status` = 2 THEN 1 ELSE 0 END) AS fastFreeCount,
|
SUM(CASE WHEN charge_mode = 3 and `status` = 2 THEN 1 ELSE 0 END) AS slowFreeCount
|
from
|
t_charging_gun
|
where
|
del_flag = ${@com.ruoyi.common.core.enums.DelFlagEnum@NO.getCode()}
|
group by
|
site_id) tcg on (ts.id = tcg.site_id)
|
left join (
|
select
|
a.accounting_strategy_id,
|
(a.electrovalence+a.service_charge) AS electrovalence,
|
((a.electrovalence+a.service_charge)*b.discount) AS vipElectrovalence
|
from
|
t_accounting_strategy_detail a
|
left join
|
t_accounting_strategy b on (a.accounting_strategy_id = b.id)
|
where b.del_flag = ${@com.ruoyi.common.core.enums.DelFlagEnum@NO.getCode()}
|
AND DATE_FORMAT(NOW(), '%H:%i:%s') between a.start_time and a.end_time) tasd on (ts.accounting_strategy_id = tasd.accounting_strategy_id)
|
<where>
|
<if test="null != query.name and '' != query.name">
|
and ts.`name` like CONCAT('%', #{query.name}, '%')
|
</if>
|
<if test="null != query.cityCode and '' != query.cityCode">
|
and ts.cityCode = #{query.cityCode}
|
</if>
|
AND ts.del_flag = ${@com.ruoyi.common.core.enums.DelFlagEnum@NO.getCode()}
|
AND ts.status = ${@com.ruoyi.common.core.enums.status.SiteStatusEnum@NORMAL_USE.getCode()}
|
</where>
|
<if test="query.sortType != null">
|
<choose>
|
<when test="query.sortType == 1">
|
ORDER BY distance ASC
|
</when>
|
</choose>
|
</if>
|
</select>
|
</mapper>
|