350 lines
18 KiB
XML

<?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.xhpc.activity.mapper.XhpcHistoryOrderMapper">
<resultMap type="com.xhpc.order.domain.XhpcHistoryOrder" id="XhpcHistoryOrderResult">
<id column="history_order_id" jdbcType="BIGINT" property="historyOrderId" />
<result column="charging_station_id" jdbcType="BIGINT" property="chargingStationId" />
<result column="charge_order_id" jdbcType="BIGINT" property="chargeOrderId" />
<result column="user_id" jdbcType="BIGINT" property="userId" />
<result column="terminal_id" jdbcType="BIGINT" property="terminalId" />
<result column="serial_number" jdbcType="VARCHAR" property="serialNumber" />
<result column="internet_serial_number" jdbcType="VARCHAR" property="internetSerialNumber" />
<result column="power_price_total" jdbcType="DECIMAL" property="powerPriceTotal" />
<result column="service_price_total" jdbcType="DECIMAL" property="servicePriceTotal" />
<result column="total_price" jdbcType="DECIMAL" property="totalPrice" />
<result column="activity_power_price_total" jdbcType="DECIMAL" property="activityPowerPriceTotal"/>
<result column="activity_service_price_total" jdbcType="DECIMAL" property="activityServicePriceTotal"/>
<result column="activity_total_price" jdbcType="DECIMAL" property="activityTotalPrice"/>
<result column="promotion_discount" jdbcType="DECIMAL" property="promotionDiscount" />
<result column="act_price" jdbcType="DECIMAL" property="actPrice" />
<result column="act_power_price" jdbcType="DECIMAL" property="actPowerPrice" />
<result column="act_service_price" jdbcType="DECIMAL" property="actServicePrice" />
<result column="internet_commission" jdbcType="DECIMAL" property="internetCommission" />
<result column="internet_svc_commission" jdbcType="DECIMAL" property="internetSvcCommission" />
<result column="platform_commission" jdbcType="DECIMAL" property="platformCommission" />
<result column="platform_svc_commisssion" jdbcType="DECIMAL" property="platformSvcCommisssion" />
<result column="operation_commission" jdbcType="DECIMAL" property="operationCommission" />
<result column="operation_svc_commission" jdbcType="DECIMAL" property="operationSvcCommission" />
<result column="start_soc" jdbcType="VARCHAR" property="startSoc" />
<result column="end_soc" jdbcType="VARCHAR" property="endSoc" />
<result column="reconciliation_status" jdbcType="INTEGER" property="reconciliationStatus" />
<result column="sorting_status" jdbcType="INTEGER" property="sortingStatus" />
<result column="type" jdbcType="TINYINT" property="type" />
<result column="status" jdbcType="INTEGER" property="status" />
<result column="del_flag" jdbcType="INTEGER" property="delFlag" />
<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="remark" jdbcType="VARCHAR" property="remark" />
<result column="state" jdbcType="INTEGER" property="state" />
<result column="vin_normal" jdbcType="VARCHAR" property="vinNormal" />
<result column="search_value" jdbcType="VARCHAR" property="searchValue" />
<result column="operator_id_evcs" jdbcType="VARCHAR" property="operatorIdEvcs" />
<result column="charge_model_evcs" jdbcType="INTEGER" property="chargeModelEvcs" />
<result column="connector_power_evcs" jdbcType="DOUBLE" property="connectorPowerEvcs" />
<result column="meter_value_end_evcs" jdbcType="DOUBLE" property="meterValueEndEvcs" />
<result column="meter_value_start_evcs" jdbcType="DOUBLE" property="meterValueStartEvcs" />
<result column="operator_id3rdpty_evcs" jdbcType="VARCHAR" property="operatorId3rdptyEvcs" />
<result column="start_time" jdbcType="TIMESTAMP" property="startTime" />
<result column="end_time" jdbcType="TIMESTAMP" property="endTime" />
<result column="stop_reason_evcs" jdbcType="VARCHAR" property="stopReasonEvcs" />
<result column="total_power" jdbcType="DOUBLE" property="totalPower" />
<result column="user_name_evcs" jdbcType="VARCHAR" property="userNameEvcs" />
<result column="phone" jdbcType="VARCHAR" property="phone" />
<result column="evcs_order_no" jdbcType="VARCHAR" property="evcsOrderNo" />
<result column="confirm_Result" jdbcType="INTEGER" property="confirmResult" />
<result column="rate_model_id" jdbcType="BIGINT" property="rateModelId" />
<result column="charging_mode" jdbcType="VARCHAR" property="chargingMode" />
<result column="internet_degree_commission" jdbcType="DECIMAL" property="internetDegreeCommission" />
<result column="source" jdbcType="INTEGER" property="source" />
<result column="tenant_id" jdbcType="VARCHAR" property="tenantId" />
</resultMap>
<sql id="Base_Column_List">
ho.history_order_id, ho.charging_station_id, ho.charge_order_id, ho.user_id, ho.terminal_id, ho.serial_number,
ho.internet_serial_number, ho.power_price_total, ho.service_price_total, ho.total_price, ho.promotion_discount,
ho.act_price, ho.act_power_price, ho.act_service_price, ho.internet_commission, ho.internet_svc_commission,
ho.platform_commission, ho.platform_svc_commisssion, ho.operation_commission, ho.operation_svc_commission,
ho.start_soc, ho.end_soc, ho.reconciliation_status, ho.sorting_status, ho.`type`, ho.`status`, ho.del_flag,
ho.create_time, ho.create_by, ho.update_time, ho.update_by, ho.remark, ho.`state`, ho.vin_normal, ho.search_value,
ho.operator_id_evcs, ho.charge_model_evcs, ho.connector_power_evcs, ho.meter_value_end_evcs,
ho.meter_value_start_evcs, ho.operator_id3rdpty_evcs, ho.start_time, ho.end_time, ho.stop_reason_evcs,
ho.total_power, ho.user_name_evcs, ho.phone, ho.evcs_order_no, ho.confirm_Result, ho.rate_model_id,
ho.charging_mode, ho.internet_degree_commission, ho.`source`, ho.tenant_id, ho.activity_power_price_total,
ho.activity_service_price_total, ho.activity_total_price
</sql>
<select id="selectUnclearingAmount" resultType="java.math.BigDecimal">
select
ifnull(sum(ho.act_power_price + ho.act_service_price), 0)
from xhpc_clearing_history_order as ho
left join xhpc_charging_station as ct on ct.charging_station_id = ho.charging_station_id
left join xhpc_operator as op on op.operator_id = ct.operator_id
where ho.del_flag=0 and ho.check_status not in (1,2) and ct.operator_id=#{operatorId}
</select>
<update id="updateStatusBatchByOrderIds">
update xhpc_history_order set state=#{status}
where find_in_set(history_order_id, #{orderIds})
</update>
<!--
原查询方案
<select id="getOrderPage" resultType="map">
select
co.serial_number as 'serialNumber',
co.source as 'source',
case co.source when 0 then 'C端用户'
when 1 then '流量方用户'
when 2 then '社区用户'
when 3 then 'B端用户' end as 'sourceName',
replace(co.start_time, 'T', ' ') as 'startTime',
replace(co.end_time, 'T', ' ') as 'endTime'
from xhpc_charge_order as co
left join xhpc_charging_station as st on st.charging_station_id =co.charging_station_id
where co.del_flag =0
<if test="params.orderId!=null and params.orderId!=''">
and co.serial_number like concat('%', #{params.orderId},'%')
</if>
<if test="params.number !=0 and params.number ==1">
and co.charging_station_id in(select charging_station_id from xhpc_charging_station where operator_id=#{params.operatorId})
</if>
<if test="params.number !=0 and params.number ==2">
and co.charging_station_id in(select charging_station_id from xhpc_user_privilege where user_id=#{params.operatorId})
</if>
<if test="params.tenantId != null and params.tenantId != ''">
and co.tenant_id = #{params.tenantId}
</if>
<if test="params.startTime!=null and params.startTime!=''">
and co.start_time <![CDATA[ >= ]]> #{params.startTime}
</if>
<if test="params.endTime !=null and params.endTime!=''">
and co.create_time <![CDATA[ <= ]]> #{params.endTime}
</if>
order by co.create_time desc
</select>-->
<select id="getOrderPage" resultType="map">
SELECT
co.serial_number AS 'serialNumber',
co.source AS 'source',
CASE co.source
WHEN 0 THEN 'C端用户'
WHEN 1 THEN '流量方用户'
WHEN 2 THEN '社区用户'
WHEN 3 THEN 'B端用户'
END AS 'sourceName',
co.start_time AS 'startTimeRaw', -- 原始数据
co.end_time AS 'endTimeRaw' -- 原始数据
FROM xhpc_charge_order co
LEFT JOIN xhpc_charging_station st
ON st.charging_station_id = co.charging_station_id
WHERE co.del_flag = 0
<if test="params.orderId!=null and params.orderId!=''">
AND co.serial_number LIKE CONCAT('%',#{params.orderId}, '%')
</if>
<if test="params.number !=0 and params.number ==1">
AND EXISTS (
SELECT 1
FROM xhpc_charging_station st_sub
WHERE st_sub.charging_station_id = co.charging_station_id
AND st_sub.operator_id = #{params.operatorId}
)
</if>
<if test="params.number !=0 and params.number ==2">
AND EXISTS (
SELECT 1
FROM xhpc_user_privilege up
WHERE up.charging_station_id = co.charging_station_id
AND up.user_id = #{params.operatorId}
)
</if>
<if test="params.tenantId != null and params.tenantId != ''">
AND co.tenant_id = #{params.tenantId}
</if>
<if test="params.startTime!=null and params.startTime!=''">
AND co.start_time >= #{params.startTime}
</if>
<if test="params.endTime !=null and params.endTime!=''">
AND co.create_time <= #{params.endTime}
</if>
ORDER BY co.create_time DESC
LIMIT 100; -- 必须添加分页限制
</select>
<select id="findOneBySerialNumber" resultType="com.xhpc.activity.domain.XhpcHistoryOrderDomain">
select
<include refid="Base_Column_List" />,
s.name as 'charging_station_name'
from
xhpc_history_order ho
left join xhpc_charging_station s on ho.charging_station_id=s.charging_station_id
where ho.serial_number=#{serialNumber}
</select>
<select id="findOneByInternetSerialNumber" resultType="com.xhpc.activity.domain.XhpcHistoryOrderDomain">
select
<include refid="Base_Column_List" />,
s.name as 'charging_station_name',
c.charging_degree as 'charging_degree',
c.charging_time as 'charging_time'
from xhpc_history_order ho
left join xhpc_charging_station s on ho.charging_station_id=s.charging_station_id
left join xhpc_charge_order c on ho.charge_order_id=c.charge_order_id
where ho.internet_serial_number=#{internetSerialNumber}
</select>
<select id="findListByInternetSerialNumbers" resultType="com.xhpc.activity.domain.XhpcHistoryOrderDomain">
select
<include refid="Base_Column_List" />,
s.name as 'charging_station_name',
c.charging_degree as 'charging_degree',
c.charging_time as 'charging_time'
from xhpc_history_order ho
left join xhpc_charging_station s on ho.charging_station_id=s.charging_station_id
left join xhpc_charge_order c on ho.charge_order_id=c.charge_order_id
where ho.internet_serial_number in
<foreach collection="orderNumbers" item="orderNumber" open="(" close=")" separator=",">
#{orderNumber}
</foreach>
</select>
<select id="findListByTimeBetween" resultType="com.xhpc.activity.domain.XhpcHistoryOrderDomain">
select
<include refid="Base_Column_List" />,
s.name as 'charging_station_name',
c.charging_degree as 'charging_degree',
c.charging_time as 'charging_time'
from xhpc_history_order ho
left join xhpc_charging_station s on ho.charging_station_id=s.charging_station_id
left join xhpc_charge_order c on ho.charge_order_id=c.charge_order_id
where ho.del_flag =0 and ho.source=1 and ho.tenant_id=#{tenantId}
<if test="startTime!=null and startTime != ''">
and ho.create_time <![CDATA[ >= ]]> #{startTime}
</if>
<if test="endTime != null and endTime !=''">
and ho.create_time <![CDATA[ <= ]]> #{endTime}
</if>
<if test="chargingMode != null and chargingMode !=''">
and ho.charging_mode=#{chargingMode}
</if>
</select>
<select id="selectUnsyncOrderListCount" resultType="java.lang.Integer">
select
count(1)
from xhpc_history_order as ho
where ho.state <![CDATA[ <> ]]> 3 and ho.del_flag=0
<if test="endTime !=null and endTime !=''">
and ho.update_time <![CDATA[ <= ]]> #{endTime}
</if>
</select>
<select id="selectUnsyncOrderList" resultType="com.xhpc.activity.domain.XhpcHistoryOrderDomain">
select
<include refid="Base_Column_List" />,
op.operator_id,
op.name as 'operator_name'
from xhpc_history_order as ho
left join xhpc_charging_station as ct on ct.charging_station_id = ho.charging_station_id
left join xhpc_operator as op on op.operator_id = ct.operator_id
where ho.state <![CDATA[ <> ]]> 3 and ho.del_flag=0 limit 1000
</select>
<select id="selectSyncedOrderIds" resultType="java.lang.String">
SELECT GROUP_CONCAT( `history_order_id`) FROM `xhpc_history_order` WHERE state <![CDATA[ <> ]]> 3 and `del_flag` = 0
and `history_order_id` in ( SELECT clearing_order_id from `xhpc_clearing_history_order` WHERE `check_status` = 2)
</select>
<select id="getListPage" resultType="map">
select
ho.history_order_id as historyOrderId,
co.charge_order_id as chargeOrderId,
ho.serial_number as serialNumber,
ct.name as chargingStationName,
ter.pile_serial_number as pileSerialNumber,
ter.name as terminalName,
op.operator_id as operatorId,
op.name as operatorName,
cp.power as power,
cp.type as type,
ho.type as orderType,
ho.start_soc as startSoc,
ho.end_soc as endSoc,
ho.vin_normal as vinCode,
ho.internet_serial_number as internetSerialNumber,
ho.evcs_order_no as evcsOrderNo,
ifnull(ho.total_price,0.0) as totalPrice,
ifnull(ho.act_price,0.0) as actPrice,
ho.confirm_Result as confirmResult,
co.charging_time as chargingTime,
ho.total_power as chargingDegree,
ho.start_time as startTime,
ho.end_time as endTime,
co.update_time as updateTime,
co.source as source,
co.Plate_num as plateNum,
co.driver_id as internetUserPhone,
inu.name as internetName,
ifnull(ho.power_price_total,0.0) as powerPriceTotal,
ifnull(ho.service_price_total,0.0) as servicePriceTotal,
ho.promotion_discount as promotionDiscount,
ho.activity_power_price_total as activityPowerPriceTotal,
ho.activity_service_price_total as activityServicePriceTotal,
ho.activity_total_price as activityTotalPrice,
ifnull(ho.act_power_price,0.0) as actPowerPrice,
ifnull(ho.act_service_price,0.0) as actServicePrice,
(ho.act_power_price+ho.act_service_price) as actSumPrice,
ifnull(ho.internet_commission,0.0) as internetCommission,
ifnull(ho.internet_svc_commission,0.0) as internetSvcCommission,
ifnull(ho.internet_degree_commission,0.0) as internetDegreeCommission,
ho.platform_commission as platformCommission,
ho.platform_svc_commisssion as platformSvcCommisssion,
ho.operation_commission as operationCommission,
ho.operation_svc_commission as operationSvcCommission,
ho.stop_reason_evcs as stopReasonEvcs,
case when ho.charging_mode="1" then "快电"
when ho.charging_mode="2" then "恒大"
when ho.charging_mode="3" then "新电途"
when ho.charging_mode="4" then "小桔"
when ho.charging_mode="微信" then "微信"
when ho.charging_mode="支付宝" then "支付宝"
when ho.charging_mode="App" then "App"
when ho.charging_mode="刷卡" then "刷卡"
else "vin码"
end chargingModeName
from xhpc_history_order as ho
left join xhpc_charging_station as ct on ct.charging_station_id = ho.charging_station_id
left join xhpc_operator as op on op.operator_id = ct.operator_id
left join xhpc_terminal as ter on ter.terminal_id = ho.terminal_id
left join xhpc_charging_pile as cp on cp.charging_pile_id = ter.charging_pile_id
left join xhpc_internet_user as inu on inu.internet_user_id = ho.user_id and ho.internet_serial_number is not null and ho.source=1
left join xhpc_charge_order co on co.charge_order_id = ho.charge_order_id
where ho.status =0 and ho.del_flag=0 and ho.source =1
and ho.user_id =#{type}
and ho.internet_serial_number in
<foreach collection="totalOrderNos" item="internetSerialNumber" open="(" separator="," close=")">
#{internetSerialNumber}
</foreach>
order by ho.end_time desc
</select>
</mapper>