完成数据大屏订单趋势接口
This commit is contained in:
parent
d65c0c5f33
commit
2b19bdf9b0
@ -4,6 +4,7 @@ import com.xhpc.common.core.domain.R;
|
|||||||
import com.xhpc.common.core.web.controller.BaseController;
|
import com.xhpc.common.core.web.controller.BaseController;
|
||||||
import com.xhpc.databigscreen.domain.CoreParam;
|
import com.xhpc.databigscreen.domain.CoreParam;
|
||||||
import com.xhpc.databigscreen.domain.OrderRatio;
|
import com.xhpc.databigscreen.domain.OrderRatio;
|
||||||
|
import com.xhpc.databigscreen.domain.OrderTrend;
|
||||||
import com.xhpc.databigscreen.domain.RealtimeOrders;
|
import com.xhpc.databigscreen.domain.RealtimeOrders;
|
||||||
import com.xhpc.databigscreen.service.XhpcDataBigScreenService;
|
import com.xhpc.databigscreen.service.XhpcDataBigScreenService;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
@ -28,6 +29,12 @@ public class XhpcDataBigScreenController extends BaseController {
|
|||||||
@Resource
|
@Resource
|
||||||
XhpcDataBigScreenService xhpcDataBigScreenService;
|
XhpcDataBigScreenService xhpcDataBigScreenService;
|
||||||
|
|
||||||
|
@GetMapping("/orders-trend")
|
||||||
|
public R<OrderTrend> queryOrdersTrend(CoreParam coreParam) {
|
||||||
|
|
||||||
|
return xhpcDataBigScreenService.queryOrderTrend(coreParam);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* query realtime orders by coreParam
|
* query realtime orders by coreParam
|
||||||
*
|
*
|
||||||
|
|||||||
@ -16,6 +16,7 @@ import lombok.NoArgsConstructor;
|
|||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
public class Condition extends CoreParam {
|
public class Condition extends CoreParam {
|
||||||
|
|
||||||
private String currentTime;
|
private String currentPage;
|
||||||
|
private String items;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,45 @@
|
|||||||
|
package com.xhpc.databigscreen.domain;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Data
|
||||||
|
public class OrderTrend {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* totalItems
|
||||||
|
*/
|
||||||
|
@JsonProperty("totalItems")
|
||||||
|
private Long totalItems;
|
||||||
|
/**
|
||||||
|
* data
|
||||||
|
*/
|
||||||
|
@JsonProperty("data")
|
||||||
|
private List<DataDTO> data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DataDTO
|
||||||
|
*/
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Data
|
||||||
|
public static class DataDTO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* time
|
||||||
|
*/
|
||||||
|
@JsonProperty("time")
|
||||||
|
private String time;
|
||||||
|
/**
|
||||||
|
* orderNumber
|
||||||
|
*/
|
||||||
|
@JsonProperty("orderNumber")
|
||||||
|
private Long orderNumber;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -4,6 +4,7 @@ import com.xhpc.databigscreen.pojo.XhpcHistoryOrder;
|
|||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public interface XhpcHistoryOrderMapper {
|
public interface XhpcHistoryOrderMapper {
|
||||||
|
|
||||||
@ -53,4 +54,15 @@ public interface XhpcHistoryOrderMapper {
|
|||||||
@Param("userType") Integer userType,
|
@Param("userType") Integer userType,
|
||||||
@Param("operatorId3rdptyEvcs") String operatorId3rdptyEvcs);
|
@Param("operatorId3rdptyEvcs") String operatorId3rdptyEvcs);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* query order trend of recent 15 day
|
||||||
|
*
|
||||||
|
* @author WH
|
||||||
|
* @date 2022/3/18 10:31
|
||||||
|
* @since version-1.0
|
||||||
|
*/
|
||||||
|
List<Map<String, Object>> selectOrderTrendByTenantIdsAndChargingStationIds(
|
||||||
|
@Param("tenantIdList") List<String> tenantIdList,
|
||||||
|
@Param("chargingStationIdList") List<Long> chargingStationIdList);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -3,6 +3,7 @@ package com.xhpc.databigscreen.service;
|
|||||||
import com.xhpc.common.core.domain.R;
|
import com.xhpc.common.core.domain.R;
|
||||||
import com.xhpc.databigscreen.domain.CoreParam;
|
import com.xhpc.databigscreen.domain.CoreParam;
|
||||||
import com.xhpc.databigscreen.domain.OrderRatio;
|
import com.xhpc.databigscreen.domain.OrderRatio;
|
||||||
|
import com.xhpc.databigscreen.domain.OrderTrend;
|
||||||
import com.xhpc.databigscreen.domain.RealtimeOrders;
|
import com.xhpc.databigscreen.domain.RealtimeOrders;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -68,4 +69,6 @@ public interface XhpcDataBigScreenService {
|
|||||||
*/
|
*/
|
||||||
R<RealtimeOrders> queryRealtimeOrders(CoreParam coreParam);
|
R<RealtimeOrders> queryRealtimeOrders(CoreParam coreParam);
|
||||||
|
|
||||||
|
R<OrderTrend> queryOrderTrend(CoreParam coreParam);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,7 @@ import com.xhpc.common.util.MyDateUtil;
|
|||||||
import com.xhpc.common.util.UserTypeUtil;
|
import com.xhpc.common.util.UserTypeUtil;
|
||||||
import com.xhpc.databigscreen.domain.CoreParam;
|
import com.xhpc.databigscreen.domain.CoreParam;
|
||||||
import com.xhpc.databigscreen.domain.OrderRatio;
|
import com.xhpc.databigscreen.domain.OrderRatio;
|
||||||
|
import com.xhpc.databigscreen.domain.OrderTrend;
|
||||||
import com.xhpc.databigscreen.domain.RealtimeOrders;
|
import com.xhpc.databigscreen.domain.RealtimeOrders;
|
||||||
import com.xhpc.databigscreen.mapper.XhpcAppUserMapper;
|
import com.xhpc.databigscreen.mapper.XhpcAppUserMapper;
|
||||||
import com.xhpc.databigscreen.mapper.XhpcChargingStationMapper;
|
import com.xhpc.databigscreen.mapper.XhpcChargingStationMapper;
|
||||||
@ -467,6 +468,86 @@ public class XhpcDataBigScreenServiceImpl implements XhpcDataBigScreenService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public R<OrderTrend> queryOrderTrend(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());
|
||||||
|
return getOrderTrend(tenantIdList, null);
|
||||||
|
} else {
|
||||||
|
return getOrderTrend(tenantIdList, null);
|
||||||
|
}
|
||||||
|
//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));
|
||||||
|
}
|
||||||
|
return getOrderTrend(tenantIdList, chargingStationIdList);
|
||||||
|
} 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));
|
||||||
|
}
|
||||||
|
return getOrderTrend(tenantIdList, chargingStationIdList);
|
||||||
|
}
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
return getOrderTrend(tenantIdList, chargingStationIdList);
|
||||||
|
} else {
|
||||||
|
return R.fail("传入的参数有误");
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return R.fail("param type is invalid");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private R<OrderTrend> getOrderTrend(List<String> tenantIdList, ArrayList<Long> chargingStationIdList) {
|
||||||
|
|
||||||
|
List<Map<String, Object>> orderTrendList = xhpcHistoryOrderMapper.selectOrderTrendByTenantIdsAndChargingStationIds(tenantIdList, chargingStationIdList);
|
||||||
|
OrderTrend orderTrend = new OrderTrend();
|
||||||
|
orderTrend.setData(new ArrayList<>());
|
||||||
|
orderTrend.setTotalItems(0L);
|
||||||
|
if (orderTrendList.isEmpty()) {
|
||||||
|
return R.ok(orderTrend);
|
||||||
|
}
|
||||||
|
for (Map<String, Object> orderTrendMap : orderTrendList) {
|
||||||
|
OrderTrend.DataDTO dataDTO = new OrderTrend.DataDTO();
|
||||||
|
dataDTO.setTime((String) orderTrendMap.get("current_time"));
|
||||||
|
dataDTO.setOrderNumber((Long) orderTrendMap.get("sum"));
|
||||||
|
orderTrend.getData().add(dataDTO);
|
||||||
|
}
|
||||||
|
orderTrend.setTotalItems((long) orderTrendList.size());
|
||||||
|
return R.ok(orderTrend);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取实时订单数据
|
* 获取实时订单数据
|
||||||
*
|
*
|
||||||
|
|||||||
@ -169,12 +169,51 @@
|
|||||||
</foreach>
|
</foreach>
|
||||||
</if>
|
</if>
|
||||||
<if test="chargingStationIdList!=null and chargingStationIdList.size()!=0 ">
|
<if test="chargingStationIdList!=null and chargingStationIdList.size()!=0 ">
|
||||||
AND tenant_id IN
|
AND charging_station_id IN
|
||||||
<foreach collection="chargingStationIdList" separator="," open="(" close=")" item="chargingStationId">
|
<foreach collection="chargingStationIdList" separator="," open="(" close=")" item="chargingStationId">
|
||||||
#{chargingStationId}
|
#{chargingStationId}
|
||||||
</foreach>
|
</foreach>
|
||||||
</if>
|
</if>
|
||||||
</select>
|
</select>
|
||||||
|
<select id="selectOrderTrendByTenantIdsAndChargingStationIds" resultType="java.util.Map">
|
||||||
|
SELECT
|
||||||
|
`current_time`,
|
||||||
|
IFNULL( sum, 0 ) sum
|
||||||
|
FROM
|
||||||
|
(
|
||||||
|
SELECT
|
||||||
|
date_format( date_add( now(), INTERVAL - t.help_topic_id DAY ), '%Y-%m-%d' ) AS 'current_time'
|
||||||
|
FROM
|
||||||
|
mysql.help_topic t
|
||||||
|
WHERE
|
||||||
|
t.help_topic_id <![CDATA[<=]]> 15
|
||||||
|
) a
|
||||||
|
LEFT JOIN (
|
||||||
|
SELECT
|
||||||
|
DATE_FORMAT( end_time, "%Y-%m-%d" ) end_time,
|
||||||
|
count( history_order_id ) sum
|
||||||
|
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>
|
||||||
|
AND end_time <![CDATA[>=]]> DATE_ADD( now(), INTERVAL - 15 DAY )
|
||||||
|
GROUP BY
|
||||||
|
DATE_FORMAT( end_time, "%Y-%m-%d" )) b ON a.`current_time` = b.end_time
|
||||||
|
ORDER BY
|
||||||
|
`current_time` DESC
|
||||||
|
</select>
|
||||||
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
|
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
|
||||||
delete
|
delete
|
||||||
from xhpc_history_order
|
from xhpc_history_order
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user