完成数据大屏订单来源比例接口
This commit is contained in:
parent
338ab9eeae
commit
4cd3d35b23
@ -31,6 +31,17 @@ public class ConstantClass {
|
||||
public static final Integer AREA = 1;
|
||||
public static final Integer POINT = 2;
|
||||
|
||||
/**
|
||||
* 三方的evcs常量
|
||||
*
|
||||
* @date 2022/3/15 16:05
|
||||
* @since version-1.0
|
||||
*/
|
||||
public static final String KUAI_DIAN_EVCS = "MA005DBW1";
|
||||
public static final String HENG_DA_EVCS = "MA5FF58R7";
|
||||
public static final String XIN_DIAN_TU_EVCS = "MA25CNM38";
|
||||
public static final String XIAO_JU_EVCS = "101437000";
|
||||
|
||||
/**
|
||||
* 刷卡的卡类型
|
||||
*/
|
||||
|
||||
@ -3,6 +3,7 @@ package com.xhpc.databigscreen.controller;
|
||||
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.service.XhpcDataBigScreenService;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@ -26,6 +27,32 @@ public class XhpcDataBigScreenController extends BaseController {
|
||||
@Resource
|
||||
XhpcDataBigScreenService xhpcDataBigScreenService;
|
||||
|
||||
/**
|
||||
* Return order ratio
|
||||
*
|
||||
* @author WH
|
||||
* @date 2022/3/9 15:49
|
||||
* @since version-1.0
|
||||
*/
|
||||
@GetMapping("/order-ratio")
|
||||
public R<OrderRatio> queryOrderRatio(CoreParam coreParam) {
|
||||
|
||||
return xhpcDataBigScreenService.queryOrderRatio(coreParam);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return total electric quantity
|
||||
*
|
||||
* @author WH
|
||||
* @date 2022/3/9 15:49
|
||||
* @since version-1.0
|
||||
*/
|
||||
@GetMapping("/electric-quantity")
|
||||
public R<Object> queryElectricQuantity(CoreParam coreParam) {
|
||||
|
||||
return xhpcDataBigScreenService.queryElectricQuantity(coreParam);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return user activation
|
||||
*
|
||||
|
||||
@ -0,0 +1,30 @@
|
||||
package com.xhpc.databigscreen.domain;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* Wrapper class of history ratio
|
||||
*
|
||||
* @author WH
|
||||
* @date 2022/3/11 13:57
|
||||
* @since version-1.0
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class OrderRatio {
|
||||
|
||||
private Long totalCount;
|
||||
private Long cClientRatio;
|
||||
private Long stClientRatio;
|
||||
private Long bClientRatio;
|
||||
|
||||
/**
|
||||
* 三方订单
|
||||
*/
|
||||
private Long xiaoJuRatio;
|
||||
private Long kuaiDianRatio;
|
||||
private Long xinDianTuRatio;
|
||||
private Long hengDaRatio;
|
||||
|
||||
}
|
||||
@ -32,4 +32,25 @@ public interface XhpcHistoryOrderMapper {
|
||||
@Param("userType") Integer userType,
|
||||
@Param("currentTime") String currentTime);
|
||||
|
||||
/**
|
||||
* query total electric quantity by multiple tenant or multiple charging station
|
||||
*
|
||||
* @author WH
|
||||
* @date 2022/3/9 16:29
|
||||
* @since version-1.0
|
||||
*/
|
||||
Long selectTotalElectricQuantity(
|
||||
@Param("tenantIdList") List<String> tenantIdList,
|
||||
@Param("chargingStationIdList") List<Long> chargingStationIdList);
|
||||
|
||||
Long selectCountByTenantIdsAndChargingStationIds(
|
||||
@Param("tenantIdList") List<String> tenantIdList,
|
||||
@Param("chargingStationIdList") List<Long> chargingStationIdList);
|
||||
|
||||
Long selectOrderCountBy(
|
||||
@Param("tenantIdList") List<String> tenantIdList,
|
||||
@Param("chargingStationIdList") List<Long> chargingStationIdList,
|
||||
@Param("userType") Integer userType,
|
||||
@Param("operatorId3rdptyEvcs") String operatorId3rdptyEvcs);
|
||||
|
||||
}
|
||||
@ -2,6 +2,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 java.util.List;
|
||||
import java.util.Map;
|
||||
@ -40,4 +41,22 @@ public interface XhpcDataBigScreenService {
|
||||
*/
|
||||
R<Object> queryUserActivation(CoreParam coreParam);
|
||||
|
||||
/**
|
||||
* query charge electric quantity
|
||||
*
|
||||
* @author WH
|
||||
* @date 2022/3/9 15:53
|
||||
* @since version-1.0
|
||||
*/
|
||||
R<Object> queryElectricQuantity(CoreParam coreParam);
|
||||
|
||||
/**
|
||||
* query order ratio by multiple kind of area
|
||||
*
|
||||
* @author WH
|
||||
* @date 2022/3/9 17:35
|
||||
* @since version-1.0
|
||||
*/
|
||||
R<OrderRatio> queryOrderRatio(CoreParam coreParam);
|
||||
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ import com.xhpc.common.core.domain.R;
|
||||
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.mapper.XhpcAppUserMapper;
|
||||
import com.xhpc.databigscreen.mapper.XhpcChargingStationMapper;
|
||||
import com.xhpc.databigscreen.mapper.XhpcHistoryOrderMapper;
|
||||
@ -259,4 +260,185 @@ public class XhpcDataBigScreenServiceImpl implements XhpcDataBigScreenService {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<Object> queryElectricQuantity(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());
|
||||
Long totalElectricQuantity = xhpcHistoryOrderMapper.selectTotalElectricQuantity(tenantIdList, null);
|
||||
return R.ok(totalElectricQuantity);
|
||||
} else {
|
||||
Long totalElectricQuantity = xhpcHistoryOrderMapper.selectTotalElectricQuantity(null, null);
|
||||
return R.ok(totalElectricQuantity);
|
||||
}
|
||||
//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));
|
||||
}
|
||||
Long totalElectricQuantity = xhpcHistoryOrderMapper.selectTotalElectricQuantity(tenantIdList, chargingStationIdList);
|
||||
return R.ok(totalElectricQuantity);
|
||||
} 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));
|
||||
}
|
||||
Long totalElectricQuantity = xhpcHistoryOrderMapper.selectTotalElectricQuantity(tenantIdList, chargingStationIdList);
|
||||
return R.ok(totalElectricQuantity);
|
||||
}
|
||||
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));
|
||||
}
|
||||
Long totalElectricQuantity = xhpcHistoryOrderMapper.selectTotalElectricQuantity(tenantIdList, chargingStationIdList);
|
||||
return R.ok(totalElectricQuantity);
|
||||
} else {
|
||||
return R.fail("传入的参数有误");
|
||||
}
|
||||
default:
|
||||
R.fail("param type is invalid");
|
||||
break;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<OrderRatio> queryOrderRatio(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());
|
||||
OrderRatio orderRatio = getOrderRatio(tenantIdList, null);
|
||||
return R.ok(orderRatio);
|
||||
} else {
|
||||
OrderRatio orderRatio = getOrderRatio(null, null);
|
||||
return R.ok(orderRatio);
|
||||
}
|
||||
//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));
|
||||
}
|
||||
OrderRatio orderRatio = getOrderRatio(tenantIdList, chargingStationIdList);
|
||||
return R.ok(orderRatio);
|
||||
} 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));
|
||||
}
|
||||
OrderRatio orderRatio = getOrderRatio(tenantIdList, chargingStationIdList);
|
||||
return R.ok(orderRatio);
|
||||
}
|
||||
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));
|
||||
}
|
||||
OrderRatio orderRatio = getOrderRatio(tenantIdList, chargingStationIdList);
|
||||
return R.ok(orderRatio);
|
||||
} else {
|
||||
return R.fail("传入的参数有误");
|
||||
}
|
||||
default:
|
||||
R.fail("param type is invalid");
|
||||
break;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取订单来源比例方法
|
||||
*
|
||||
* @param tenantIdList 租户id集合
|
||||
* @param chargingStationIdList 电站id集合
|
||||
* @author WH
|
||||
* @date 2022/3/15 17:08
|
||||
* @since version-1.0
|
||||
*/
|
||||
private OrderRatio getOrderRatio(List<String> tenantIdList, List<Long> chargingStationIdList) {
|
||||
|
||||
Long totalCount = xhpcHistoryOrderMapper.selectCountByTenantIdsAndChargingStationIds(tenantIdList, null);
|
||||
OrderRatio orderRatio = new OrderRatio();
|
||||
orderRatio.setTotalCount(totalCount);
|
||||
Long stClientNumber = xhpcHistoryOrderMapper.selectOrderCountBy(tenantIdList, chargingStationIdList, UserTypeUtil.COMMUNIT_TYPE, null);
|
||||
double stClientNumberDouble = stClientNumber.doubleValue();
|
||||
long stClientRatio = (long) (stClientNumberDouble / totalCount * 100);
|
||||
orderRatio.setStClientRatio(stClientRatio);
|
||||
Long bClientNumber = xhpcHistoryOrderMapper.selectOrderCountBy(tenantIdList, chargingStationIdList, UserTypeUtil.CUSTOMERS_TYPE, null);
|
||||
double bClientNumberDouble = bClientNumber.doubleValue();
|
||||
long bClientRatio = (long) (bClientNumberDouble / totalCount * 100);
|
||||
orderRatio.setBClientRatio(bClientRatio);
|
||||
Long kuaiDianNumber = xhpcHistoryOrderMapper.selectOrderCountBy(tenantIdList, chargingStationIdList, UserTypeUtil.INTERNET_TYPE, ConstantClass.KUAI_DIAN_EVCS);
|
||||
double kuaiDianNumberDouble = kuaiDianNumber.doubleValue();
|
||||
long kuaiDianRatio = (long) (kuaiDianNumberDouble / totalCount * 100);
|
||||
orderRatio.setKuaiDianRatio(kuaiDianRatio);
|
||||
Long hengDaNumber = xhpcHistoryOrderMapper.selectOrderCountBy(tenantIdList, chargingStationIdList, UserTypeUtil.INTERNET_TYPE, ConstantClass.HENG_DA_EVCS);
|
||||
double hengDaNumberDouble = hengDaNumber.doubleValue();
|
||||
long hengDaRatio = (long) (hengDaNumberDouble / totalCount * 100);
|
||||
orderRatio.setHengDaRatio(hengDaRatio);
|
||||
Long xinDianTuNumber = xhpcHistoryOrderMapper.selectOrderCountBy(tenantIdList, chargingStationIdList, UserTypeUtil.INTERNET_TYPE, ConstantClass.XIN_DIAN_TU_EVCS);
|
||||
double xinDianTuNumberDouble = xinDianTuNumber.doubleValue();
|
||||
long xinDianTuRatio = (long) (xinDianTuNumberDouble / totalCount * 100);
|
||||
orderRatio.setXinDianTuRatio(xinDianTuRatio);
|
||||
Long xiaoJuNumber = xhpcHistoryOrderMapper.selectOrderCountBy(tenantIdList, chargingStationIdList, UserTypeUtil.INTERNET_TYPE, ConstantClass.XIAO_JU_EVCS);
|
||||
double xiaoJuNumberDouble = xiaoJuNumber.doubleValue();
|
||||
long xiaoJuRatio = (long) (xiaoJuNumberDouble / totalCount * 100);
|
||||
orderRatio.setXiaoJuRatio(xiaoJuRatio);
|
||||
//为了防止转换成百分比导致的进度丢失问题,故C端用户直接算出来,而不是查出来
|
||||
long cClientRatio = 100 - xiaoJuRatio - kuaiDianRatio - xinDianTuRatio - hengDaRatio - stClientRatio - bClientRatio;
|
||||
orderRatio.setCClientRatio(cClientRatio);
|
||||
return orderRatio;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -109,6 +109,72 @@
|
||||
</if>
|
||||
) AS a
|
||||
</select>
|
||||
<select id="selectTotalElectricQuantity" resultType="java.lang.Long">
|
||||
SELECT
|
||||
sum( total_power ) AS totalPower
|
||||
FROM
|
||||
xhpc_history_order
|
||||
WHERE
|
||||
del_flag = 0
|
||||
<if test="tenantIdList!=null and tenantIdList.size()!=0 ">
|
||||
and tenant_id in
|
||||
<foreach collection="tenantIdList" separator="," open="(" close=")" item="tenantId">
|
||||
#{tenantId}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="chargingStationIdList!=null and chargingStationIdList.size()!=0 ">
|
||||
and charging_station_id in
|
||||
<foreach collection="chargingStationIdList" separator="," open="(" close=")" item="chargingStationId">
|
||||
#{chargingStationId}
|
||||
</foreach>
|
||||
</if>
|
||||
</select>
|
||||
<select id="selectCountByTenantIdsAndChargingStationIds" resultType="java.lang.Long">
|
||||
SELECT
|
||||
count( history_order_id )
|
||||
FROM
|
||||
xhpc_history_order
|
||||
WHERE
|
||||
del_flag = 0
|
||||
<if test="tenantIdList!=null and tenantIdList.size()!=0">
|
||||
and tenant_id in
|
||||
<foreach collection="tenantIdList" separator="," open="(" close=")" item="tenantId">
|
||||
#{tenantId}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="chargingStationIdList!=null and chargingStationIdList.size()!=0 ">
|
||||
and charging_station_id in
|
||||
<foreach collection="chargingStationIdList" separator="," open="(" close=")" item="chargingStationId">
|
||||
#{chargingStationId}
|
||||
</foreach>
|
||||
</if>
|
||||
</select>
|
||||
<select id="selectOrderCountBy" resultType="java.lang.Long">
|
||||
SELECT
|
||||
count( history_order_id )
|
||||
FROM
|
||||
xhpc_history_order
|
||||
WHERE
|
||||
del_flag = 0
|
||||
<if test="userType!=null">
|
||||
AND source = #{userType}
|
||||
<if test="userType==1">
|
||||
and operator_id3rdpty_evcs = #{operatorId3rdptyEvcs}
|
||||
</if>
|
||||
</if>
|
||||
<if test="tenantIdList!=null and tenantIdList.size()!=0 ">
|
||||
AND tenant_id IN
|
||||
<foreach collection="tenantIdList" separator="," open="(" close=")" item="tenantId">
|
||||
#{tenantId}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="chargingStationIdList!=null and chargingStationIdList.size()!=0 ">
|
||||
AND tenant_id IN
|
||||
<foreach collection="chargingStationIdList" separator="," open="(" close=")" item="chargingStationId">
|
||||
#{chargingStationId}
|
||||
</foreach>
|
||||
</if>
|
||||
</select>
|
||||
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
|
||||
delete
|
||||
from xhpc_history_order
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user