完成数据大屏实时订单接口

This commit is contained in:
wenhui 2022-03-17 16:20:47 +08:00
parent c8e28e0aaa
commit d65c0c5f33
7 changed files with 637 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import com.xhpc.common.core.domain.R;
import com.xhpc.common.core.web.controller.BaseController;
import com.xhpc.databigscreen.domain.CoreParam;
import com.xhpc.databigscreen.domain.OrderRatio;
import com.xhpc.databigscreen.domain.RealtimeOrders;
import com.xhpc.databigscreen.service.XhpcDataBigScreenService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@ -27,6 +28,19 @@ public class XhpcDataBigScreenController extends BaseController {
@Resource
XhpcDataBigScreenService xhpcDataBigScreenService;
/**
* query realtime orders by coreParam
*
* @author WH
* @date 2022/3/16 10:56
* @since version-1.0
*/
@GetMapping("/realtimeOrders")
public R<RealtimeOrders> queryRealtimeOrders(CoreParam coreParam) {
return xhpcDataBigScreenService.queryRealtimeOrders(coreParam);
}
/**
* Return order ratio
*

View File

@ -0,0 +1,78 @@
package com.xhpc.databigscreen.domain;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* @author WH
*/
@NoArgsConstructor
@Data
public class RealtimeOrders {
/**
* 总条数
*/
@JsonProperty("totalItems")
private Long totalItems;
/**
* 数据集合
*/
@JsonProperty("data")
private List<RealtimeOrder> data;
/**
* RealtimeOrder
*/
@NoArgsConstructor
@Data
public static class RealtimeOrder {
/**
* 用户类型
*/
@JsonProperty("userType")
private String userType;
/**
* 开始充电时间
*/
@JsonProperty("startChargingTime")
private String startChargingTime;
/**
* 充电时长
*/
@JsonProperty("chargingTime")
private String chargingTime;
/**
* 已充电量
*/
@JsonProperty("chargedElectric")
private Double chargedElectric;
/**
* 充电金额
*/
@JsonProperty("chargingSum")
private Double chargingSum;
/**
* 电流
*/
@JsonProperty("electricCurrent")
private Double electricCurrent;
/**
* 电压
*/
@JsonProperty("voltage")
private Double voltage;
/**
* SOC
*/
@JsonProperty("soc")
private String soc;
}
}

View File

@ -0,0 +1,33 @@
package com.xhpc.databigscreen.mapper;
import com.xhpc.databigscreen.pojo.XhpcRateTime;
import org.apache.ibatis.annotations.Param;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public interface XhpcRateTimeMapper {
int deleteByPrimaryKey(Long rateTimeId);
int insert(XhpcRateTime record);
int insertSelective(XhpcRateTime record);
XhpcRateTime selectByPrimaryKey(Long rateTimeId);
int updateByPrimaryKeySelective(XhpcRateTime record);
int updateByPrimaryKey(XhpcRateTime record);
/**
* query real time orders for big data screen
*
* @author WH
* @date 2022/3/17 14:46
* @since version-1.0
*/
List<Map<String, Object>> selectByTenantIdsAndCharingStationIds(@Param("tenantIdList") List<String> tenantIdList, @Param("xhpcChargingStationList") ArrayList<Long> xhpcChargingStationList);
}

View File

@ -0,0 +1,103 @@
package com.xhpc.databigscreen.pojo;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* xhpc_rate_time
*
* @author
*/
@Data
public class XhpcRateTime implements Serializable {
/**
* 费率时段id
*/
private Long rateTimeId;
/**
* 电站id
*/
private Long chargingStationId;
/**
* 费率id
*/
private Long rateId;
/**
* 启始时间
*/
private Date startTime;
/**
* 结束时间
*/
private Date endTime;
/**
* 状态0正常 1停用
*/
private Integer status;
/**
* 删除标志0代表存在 2代表删除
*/
private Integer delFlag;
/**
* 创建时间
*/
private Date createTime;
/**
* 创建者
*/
private String createBy;
/**
* 更新时间
*/
private Date updateTime;
/**
* 更新者
*/
private String updateBy;
/**
* 备注
*/
private String remark;
/**
* 计费模型id
*/
private Long rateModelId;
/**
* 时间排序
*/
private Integer sort;
/**
* 1 设置时间段 2默认时间段
*/
private Integer type;
/**
* 费率类型 00: 尖费率 01: 峰费率 02: 平费率 03: 谷费率
*/
private String rateValue;
/**
* 租户id
*/
private String tenantId;
private static final long serialVersionUID = 1L;
}

View File

@ -3,6 +3,7 @@ package com.xhpc.databigscreen.service;
import com.xhpc.common.core.domain.R;
import com.xhpc.databigscreen.domain.CoreParam;
import com.xhpc.databigscreen.domain.OrderRatio;
import com.xhpc.databigscreen.domain.RealtimeOrders;
import java.util.List;
import java.util.Map;
@ -59,4 +60,12 @@ public interface XhpcDataBigScreenService {
*/
R<OrderRatio> queryOrderRatio(CoreParam coreParam);
/**
* query realtime by coreParam
*
* @param coreParam
* @return
*/
R<RealtimeOrders> queryRealtimeOrders(CoreParam coreParam);
}

View File

@ -6,9 +6,11 @@ import com.xhpc.common.util.MyDateUtil;
import com.xhpc.common.util.UserTypeUtil;
import com.xhpc.databigscreen.domain.CoreParam;
import com.xhpc.databigscreen.domain.OrderRatio;
import com.xhpc.databigscreen.domain.RealtimeOrders;
import com.xhpc.databigscreen.mapper.XhpcAppUserMapper;
import com.xhpc.databigscreen.mapper.XhpcChargingStationMapper;
import com.xhpc.databigscreen.mapper.XhpcHistoryOrderMapper;
import com.xhpc.databigscreen.mapper.XhpcRateTimeMapper;
import com.xhpc.databigscreen.service.XhpcDataBigScreenService;
import org.springframework.stereotype.Service;
@ -33,6 +35,8 @@ public class XhpcDataBigScreenServiceImpl implements XhpcDataBigScreenService {
XhpcAppUserMapper xhpcAppUserMapper;
@Resource
XhpcHistoryOrderMapper xhpcHistoryOrderMapper;
@Resource
XhpcRateTimeMapper xhpcRateTimeMapper;
@Override
public R<List<Map<String, Object>>> returnCoreLocation(CoreParam coreParam) {
@ -397,6 +401,109 @@ public class XhpcDataBigScreenServiceImpl implements XhpcDataBigScreenService {
return null;
}
@Override
public R<RealtimeOrders> queryRealtimeOrders(CoreParam coreParam) {
String tenantIdsStr = null;
List<Map<String, Object>> xhpcChargingStationList = null;
List<String> tenantIdList = null;
String[] tenantIdArray = null;
//judge care param function
switch (coreParam.getParamType()) {
case 0:
tenantIdsStr = coreParam.getTenantIds();
if (!"".equals(tenantIdsStr) && tenantIdsStr != null) {
tenantIdArray = tenantIdsStr.split(",");
tenantIdList = Arrays.stream(tenantIdArray).collect(Collectors.toList());
List<Map<String, Object>> realtimeOrderList = xhpcRateTimeMapper.selectByTenantIdsAndCharingStationIds(tenantIdList, null);
return getRealtimeOrders(realtimeOrderList);
} else {
List<Map<String, Object>> realtimeOrderList = xhpcRateTimeMapper.selectByTenantIdsAndCharingStationIds(tenantIdList, null);
return getRealtimeOrders(realtimeOrderList);
}
//query charging station infos of whole area
case 1:
Integer areaCode = coreParam.getAreaCode();
tenantIdsStr = coreParam.getTenantIds();
if (!"".equals(tenantIdsStr) && tenantIdsStr != null) {
tenantIdArray = tenantIdsStr.split(",");
tenantIdList = Arrays.stream(tenantIdArray).collect(Collectors.toList());
xhpcChargingStationList = xhpcChargingStationMapper.selectByTenantIdAndAreaCode(tenantIdList, areaCode);
ArrayList<Long> chargingStationIdList = new ArrayList<>();
for (Map<String, Object> chargingStation : xhpcChargingStationList) {
chargingStationIdList.add((Long) chargingStation.get(ConstantClass.CHARGING_STATION_ID));
}
List<Map<String, Object>> realtimeOrderList = xhpcRateTimeMapper.selectByTenantIdsAndCharingStationIds(tenantIdList, chargingStationIdList);
return getRealtimeOrders(realtimeOrderList);
} else {
xhpcChargingStationList = xhpcChargingStationMapper.selectByTenantIdAndAreaCode(tenantIdList, areaCode);
ArrayList<Long> chargingStationIdList = new ArrayList<>();
for (Map<String, Object> chargingStation : xhpcChargingStationList) {
chargingStationIdList.add((Long) chargingStation.get(ConstantClass.CHARGING_STATION_ID));
}
List<Map<String, Object>> realtimeOrderList = xhpcRateTimeMapper.selectByTenantIdsAndCharingStationIds(tenantIdList, chargingStationIdList);
return getRealtimeOrders(realtimeOrderList);
}
case 2:
//query location info of special charging station of special tenant
tenantIdsStr = coreParam.getTenantIds();
if (!"".equals(tenantIdsStr) && tenantIdsStr != null) {
tenantIdArray = tenantIdsStr.split(",");
tenantIdList = Arrays.stream(tenantIdArray).collect(Collectors.toList());
String chargingStationIdStr = coreParam.getChargingStationIds();
long chargingStationId = Long.parseLong(chargingStationIdStr);
xhpcChargingStationList = xhpcChargingStationMapper.selectByTenantIdAndChargingStationId(tenantIdList, chargingStationId);
ArrayList<Long> chargingStationIdList = new ArrayList<>();
for (Map<String, Object> chargingStation : xhpcChargingStationList) {
chargingStationIdList.add((Long) chargingStation.get(ConstantClass.CHARGING_STATION_ID));
}
List<Map<String, Object>> realtimeOrderList = xhpcRateTimeMapper.selectByTenantIdsAndCharingStationIds(tenantIdList, chargingStationIdList);
return getRealtimeOrders(realtimeOrderList);
} else {
return R.fail("传入的参数有误");
}
default:
return R.fail("param type is invalid");
}
}
/**
* 获取实时订单数据
*
* @author WH
* @date 2022/3/17 15:46
* @since version-1.0
*/
private R<RealtimeOrders> getRealtimeOrders(List<Map<String, Object>> realtimeOrderList) {
//init wrapper class object,set default value
RealtimeOrders realtimeOrders = new RealtimeOrders();
ArrayList<RealtimeOrders.RealtimeOrder> realtimeOrderWrapperList = new ArrayList<>();
realtimeOrders.setData(realtimeOrderWrapperList);
realtimeOrders.setTotalItems(0L);
if (realtimeOrderList.isEmpty()) {
return R.ok(realtimeOrders);
}
realtimeOrders.setTotalItems((long) realtimeOrderList.size());
for (Map<String, Object> realtimeOrderMap : realtimeOrderList) {
RealtimeOrders.RealtimeOrder realtimeOrder = new RealtimeOrders.RealtimeOrder();
Integer userType = (Integer) realtimeOrderMap.get("source");
if (userType == 1) {
realtimeOrder.setUserType((String) realtimeOrderMap.get("chargingMode"));
} else {
realtimeOrder.setUserType((String) realtimeOrderMap.get("sourceMap"));
}
realtimeOrder.setStartChargingTime((String) realtimeOrderMap.get("startTime"));
realtimeOrder.setChargingTime((String) realtimeOrderMap.get("chargingTime"));
realtimeOrder.setChargedElectric((Double) realtimeOrderMap.get("chargingDegree"));
realtimeOrder.setChargingSum((Double) realtimeOrderMap.get("amountCharged"));
realtimeOrder.setElectricCurrent((Double) realtimeOrderMap.get("electricCurrent"));
realtimeOrder.setVoltage((Double) realtimeOrderMap.get("voltage"));
realtimeOrder.setSoc((String) realtimeOrderMap.get("soc"));
realtimeOrderWrapperList.add(realtimeOrder);
}
return R.ok(realtimeOrders);
}
/**
* 获取订单来源比例方法
*

View File

@ -0,0 +1,293 @@
<?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">
<!--suppress ALL -->
<mapper namespace="com.xhpc.databigscreen.mapper.XhpcRateTimeMapper">
<resultMap id="BaseResultMap" type="com.xhpc.databigscreen.pojo.XhpcRateTime">
<id column="rate_time_id" jdbcType="BIGINT" property="rateTimeId"/>
<result column="charging_station_id" jdbcType="BIGINT" property="chargingStationId"/>
<result column="rate_id" jdbcType="BIGINT" property="rateId"/>
<result column="start_time" jdbcType="TIME" property="startTime"/>
<result column="end_time" jdbcType="TIME" property="endTime"/>
<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="rate_model_id" jdbcType="BIGINT" property="rateModelId"/>
<result column="sort" jdbcType="INTEGER" property="sort"/>
<result column="type" jdbcType="INTEGER" property="type"/>
<result column="rate_value" jdbcType="VARCHAR" property="rateValue"/>
<result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
</resultMap>
<sql id="Base_Column_List">
rate_time_id
, charging_station_id, rate_id, start_time, end_time, `status`, del_flag,
create_time, create_by, update_time, update_by, remark, rate_model_id, sort, `type`,
rate_value, tenant_id
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from xhpc_rate_time
where rate_time_id = #{rateTimeId,jdbcType=BIGINT}
</select>
<select id="selectByTenantIdsAndCharingStationIds" resultType="Map">
select
r.charging_order_id chargingOrderId,
ROUND(r.charging_degree,2) as chargingDegree,
r.amount_charged amountCharged,
r.electric_current electricCurrent,
r.voltage,
r.soc,
r.source,
DATE_FORMAT(o.start_time,"%H:%m") as startTime,
CASE r.source
WHEN 0 THEN
"C端用户"
WHEN 2 THEN
"社区用户"
WHEN 3 THEN
"B端用户"
END sourceMap,
r.charging_time chargingTime,
CONCAT(o.charging_mode,"用户") as chargingMode
from
(SELECT
charging_order_id,
charging_degree,
amount_charged,
electric_current,
voltage,
soc,
source,
tenant_id,
charging_time
FROM
xhpc_real_time_order
WHERE
real_time_order_id IN
(SELECT
max(real_time_order_id)
FROM
xhpc_real_time_order
WHERE
charging_order_id IN
(SELECT charge_order_id FROM xhpc_charge_order WHERE STATUS = 0 and del_flag = 0
<if test="tenantIdList!=null and tenantIdList.size()!=0">
and tenant_id in
<foreach collection="tenantIdList" open="(" close=")" separator="," item="tenantId">
#{tenantId}
</foreach>
</if>
<if test="xhpcChargingStationList!=null and xhpcChargingStationList.size()!=0">
and charging_station_id in
<foreach collection="xhpcChargingStationList" open="(" close=")" separator="," item="chargingStationId">
#{chargingStationId}
</foreach>
</if>
)
GROUP BY charging_order_id))
AS r LEFT JOIN xhpc_charge_order as o on r.charging_order_id = o.charge_order_id
ORDER BY o.start_time ASC
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
delete
from xhpc_rate_time
where rate_time_id = #{rateTimeId,jdbcType=BIGINT}
</delete>
<insert id="insert" keyColumn="rate_time_id" keyProperty="rateTimeId"
parameterType="com.xhpc.databigscreen.pojo.XhpcRateTime" useGeneratedKeys="true">
insert into xhpc_rate_time (charging_station_id, rate_id, start_time,
end_time, `status`, del_flag,
create_time, create_by, update_time,
update_by, remark, rate_model_id,
sort, `type`, rate_value,
tenant_id)
values (#{chargingStationId,jdbcType=BIGINT}, #{rateId,jdbcType=BIGINT}, #{startTime,jdbcType=TIME},
#{endTime,jdbcType=TIME}, #{status,jdbcType=INTEGER}, #{delFlag,jdbcType=INTEGER},
#{createTime,jdbcType=TIMESTAMP}, #{createBy,jdbcType=VARCHAR}, #{updateTime,jdbcType=TIMESTAMP},
#{updateBy,jdbcType=VARCHAR}, #{remark,jdbcType=VARCHAR}, #{rateModelId,jdbcType=BIGINT},
#{sort,jdbcType=INTEGER}, #{type,jdbcType=INTEGER}, #{rateValue,jdbcType=VARCHAR},
#{tenantId,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" keyColumn="rate_time_id" keyProperty="rateTimeId"
parameterType="com.xhpc.databigscreen.pojo.XhpcRateTime" useGeneratedKeys="true">
insert into xhpc_rate_time
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="chargingStationId != null">
charging_station_id,
</if>
<if test="rateId != null">
rate_id,
</if>
<if test="startTime != null">
start_time,
</if>
<if test="endTime != null">
end_time,
</if>
<if test="status != null">
`status`,
</if>
<if test="delFlag != null">
del_flag,
</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="remark != null">
remark,
</if>
<if test="rateModelId != null">
rate_model_id,
</if>
<if test="sort != null">
sort,
</if>
<if test="type != null">
`type`,
</if>
<if test="rateValue != null">
rate_value,
</if>
<if test="tenantId != null">
tenant_id,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="chargingStationId != null">
#{chargingStationId,jdbcType=BIGINT},
</if>
<if test="rateId != null">
#{rateId,jdbcType=BIGINT},
</if>
<if test="startTime != null">
#{startTime,jdbcType=TIME},
</if>
<if test="endTime != null">
#{endTime,jdbcType=TIME},
</if>
<if test="status != null">
#{status,jdbcType=INTEGER},
</if>
<if test="delFlag != null">
#{delFlag,jdbcType=INTEGER},
</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="remark != null">
#{remark,jdbcType=VARCHAR},
</if>
<if test="rateModelId != null">
#{rateModelId,jdbcType=BIGINT},
</if>
<if test="sort != null">
#{sort,jdbcType=INTEGER},
</if>
<if test="type != null">
#{type,jdbcType=INTEGER},
</if>
<if test="rateValue != null">
#{rateValue,jdbcType=VARCHAR},
</if>
<if test="tenantId != null">
#{tenantId,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.xhpc.databigscreen.pojo.XhpcRateTime">
update xhpc_rate_time
<set>
<if test="chargingStationId != null">
charging_station_id = #{chargingStationId,jdbcType=BIGINT},
</if>
<if test="rateId != null">
rate_id = #{rateId,jdbcType=BIGINT},
</if>
<if test="startTime != null">
start_time = #{startTime,jdbcType=TIME},
</if>
<if test="endTime != null">
end_time = #{endTime,jdbcType=TIME},
</if>
<if test="status != null">
`status` = #{status,jdbcType=INTEGER},
</if>
<if test="delFlag != null">
del_flag = #{delFlag,jdbcType=INTEGER},
</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="remark != null">
remark = #{remark,jdbcType=VARCHAR},
</if>
<if test="rateModelId != null">
rate_model_id = #{rateModelId,jdbcType=BIGINT},
</if>
<if test="sort != null">
sort = #{sort,jdbcType=INTEGER},
</if>
<if test="type != null">
`type` = #{type,jdbcType=INTEGER},
</if>
<if test="rateValue != null">
rate_value = #{rateValue,jdbcType=VARCHAR},
</if>
<if test="tenantId != null">
tenant_id = #{tenantId,jdbcType=VARCHAR},
</if>
</set>
where rate_time_id = #{rateTimeId,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKey" parameterType="com.xhpc.databigscreen.pojo.XhpcRateTime">
update xhpc_rate_time
set charging_station_id = #{chargingStationId,jdbcType=BIGINT},
rate_id = #{rateId,jdbcType=BIGINT},
start_time = #{startTime,jdbcType=TIME},
end_time = #{endTime,jdbcType=TIME},
`status` = #{status,jdbcType=INTEGER},
del_flag = #{delFlag,jdbcType=INTEGER},
create_time = #{createTime,jdbcType=TIMESTAMP},
create_by = #{createBy,jdbcType=VARCHAR},
update_time = #{updateTime,jdbcType=TIMESTAMP},
update_by = #{updateBy,jdbcType=VARCHAR},
remark = #{remark,jdbcType=VARCHAR},
rate_model_id = #{rateModelId,jdbcType=BIGINT},
sort = #{sort,jdbcType=INTEGER},
`type` = #{type,jdbcType=INTEGER},
rate_value = #{rateValue,jdbcType=VARCHAR},
tenant_id = #{tenantId,jdbcType=VARCHAR}
where rate_time_id = #{rateTimeId,jdbcType=BIGINT}
</update>
</mapper>