Commit 5e34edae authored by jiaorz's avatar jiaorz

补充车辆统计数据

parent 2ddebc2d
......@@ -6,17 +6,22 @@ import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.util.Query;
import com.github.wxiaoqi.security.common.vo.PageDataVO;
import com.xxfc.platform.order.Utils.OrderDateUtils;
import com.xxfc.platform.vehicle.entity.BranchCompanyVehicleCount;
import com.xxfc.platform.vehicle.mapper.BranchCompanyVehicleCountMapper;
import com.xxfc.platform.vehicle.pojo.BranchCompanyVehicleCountVo;
import com.xxfc.platform.vehicle.pojo.dto.BranchCompanyVehicleCountDTO;
import com.xxfc.platform.vehicle.util.DateUtils;
import lombok.extern.slf4j.Slf4j;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
@Slf4j
......@@ -24,6 +29,10 @@ public class BranchCompanyVehicleCountBiz extends BaseBiz<BranchCompanyVehicleCo
@Autowired
VehicleBiz vehicleBiz;
//以时间字符串为key, 以公司ID和数量组成map为value
private static Map<String, Map<Integer, Integer>> mapMap = new HashMap<>();
public static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
public static final DateTimeFormatter DEFAULT_TIME_FORMATTER = DateTimeFormat.forPattern("yyyy-MM-dd");
public ObjectRestResponse add(BranchCompanyVehicleCount branchCompanyVehicleCount) {
if (branchCompanyVehicleCount == null) {
......@@ -80,34 +89,64 @@ public class BranchCompanyVehicleCountBiz extends BaseBiz<BranchCompanyVehicleCo
}
public ObjectRestResponse<PageDataVO<BranchCompanyVehicleCountVo>> getAllCountInfo(BranchCompanyVehicleCountDTO branchCompanyVehicleCountDTO) {
if (branchCompanyVehicleCountDTO == null) {
return ObjectRestResponse.paramIsEmpty();
}
Integer page = branchCompanyVehicleCountDTO.getPage() == null ? 1 : branchCompanyVehicleCountDTO.getPage();
Integer limit = branchCompanyVehicleCountDTO.getLimit() == null ? 10 : branchCompanyVehicleCountDTO.getLimit();
Integer type = branchCompanyVehicleCountDTO.getType() == null ? 1 : branchCompanyVehicleCountDTO.getType();
branchCompanyVehicleCountDTO.setPage(page);
branchCompanyVehicleCountDTO.setLimit(limit);
Query query = new Query(branchCompanyVehicleCountDTO);
if (type == 1) {//按天
return ObjectRestResponse.succ(countByDay(query));
}
if (type == 2) {//按周
PageDataVO<BranchCompanyVehicleCountVo> pageDataVO = countByWeek(query);
if (pageDataVO != null && pageDataVO.getData() != null && pageDataVO.getData().size() > 0) {
pageDataVO.getData().parallelStream().forEach(result -> {
String weekStartDate = OrderDateUtils.getStartDayOfWeekNo(result.getCountYear(), result.getCountWeek());
String weekEndDate = OrderDateUtils.getEndDayOfWeekNo(result.getCountYear(), result.getCountWeek());
result.setWeekStartDate(weekStartDate);
result.setWeekEndDate(weekEndDate);
});
}
return ObjectRestResponse.succ(pageDataVO);
getAllVehicleNum();
// if (branchCompanyVehicleCountDTO == null) {
// return ObjectRestResponse.paramIsEmpty();
// }
// Integer page = branchCompanyVehicleCountDTO.getPage() == null ? 1 : branchCompanyVehicleCountDTO.getPage();
// Integer limit = branchCompanyVehicleCountDTO.getLimit() == null ? 10 : branchCompanyVehicleCountDTO.getLimit();
// Integer type = branchCompanyVehicleCountDTO.getType() == null ? 1 : branchCompanyVehicleCountDTO.getType();
// branchCompanyVehicleCountDTO.setPage(page);
// branchCompanyVehicleCountDTO.setLimit(limit);
// Query query = new Query(branchCompanyVehicleCountDTO);
// if (type == 1) {//按天
// return ObjectRestResponse.succ(countByDay(query));
// }
// if (type == 2) {//按周
// PageDataVO<BranchCompanyVehicleCountVo> pageDataVO = countByWeek(query);
// if (pageDataVO != null && pageDataVO.getData() != null && pageDataVO.getData().size() > 0) {
// pageDataVO.getData().parallelStream().forEach(result -> {
// String weekStartDate = OrderDateUtils.getStartDayOfWeekNo(result.getCountYear(), result.getCountWeek());
// String weekEndDate = OrderDateUtils.getEndDayOfWeekNo(result.getCountYear(), result.getCountWeek());
// result.setWeekStartDate(weekStartDate);
// result.setWeekEndDate(weekEndDate);
// });
// }
// return ObjectRestResponse.succ(pageDataVO);
// }
// if (type == 3) {//按月
// return ObjectRestResponse.succ(countByMonth(query));
// }
return ObjectRestResponse.succ(new PageDataVO<>());
}
//获取所有月份车辆统计数据
public void getAllVehicleNum(DateTime dateTime) {
DateTime nowTime = DateTime.now().minusDays(1);
if(dateTime != null) {
nowTime = dateTime.minusDays(1);
}
if (type == 3) {//按月
return ObjectRestResponse.succ(countByMonth(query));
Long startTime = DateUtils.getStartOfDay(nowTime.toDate());
Long endTime = DateUtils.getEndOfDay(nowTime.toDate());
String timeStr = nowTime.toString(DEFAULT_TIME_FORMATTER);
Map<String, Object> map = new HashMap<>();
map.put("startTime", new DateTime().withMillis(startTime).toString(DATE_TIME_FORMATTER));
map.put("endTime", new DateTime().withMillis(endTime).toString(DATE_TIME_FORMATTER));
List<BranchCompanyVehicleCountVo> list = mapper.selectBookRecordByTime(map);
Map<Integer, Integer> companyMap = mapMap.getOrDefault(timeStr, new HashMap<>());
if (list != null && list.size() > 0) {
list.parallelStream().forEach(result -> {
companyMap.put(result.getCompanyId(), result.getVehicleNum());
});
mapMap.put(timeStr, companyMap);
}
return ObjectRestResponse.succ(new PageDataVO<>());
log.info("统计车辆数据: Map = {}", mapMap);
}
public void getAllVehicleNum() {
DateTime dateTime = DateTime.parse("2019-01-01");
for (DateTime curDate = dateTime.plusDays(1); curDate.compareTo(DateTime.now()) < 0; curDate = curDate.plusDays(1)) {
getAllVehicleNum(curDate);
}
}
}
......@@ -505,6 +505,7 @@ public class VehicleBookRecordBiz extends BaseBiz<VehicleBookRecordMapper, Vehic
return selectAllBookRecord(map);
}
/**
* 获取上月数据,并复制到历史表
*/
......
......@@ -14,5 +14,5 @@ public interface BranchCompanyVehicleCountMapper extends Mapper<BranchCompanyVeh
List<BranchCompanyVehicleCountVo> countByMonth(Map<String, Object> param);
List<BranchCompanyVehicleCountVo> countByWeek(Map<String, Object> param);
List<BranchCompanyVehicleCountVo> selectBookRecordByTime(Map<String, Object> param);
}
\ No newline at end of file
......@@ -58,4 +58,46 @@
GROUP BY c.company_id,c.count_year,c.count_week
</select>
<select id="selectBookRecordByTime" parameterType="Map" resultType="com.xxfc.platform.vehicle.pojo.BranchCompanyVehicleCountVo">
SELECT
tmp.lift_company as companyId, count(*) as vehicleNum
FROM
(
SELECT
*
FROM
vehicle_book_record
WHERE
STATUS = 2
AND (
(
book_start_date &gt; #{startTime}
AND book_start_date &lt; #{endTime}
AND book_end_date &gt; #{endTime}
)
OR (
book_start_date &lt; #{startTime}
AND book_end_date &gt; #{endTime}
)
OR (
book_start_date &lt; #{startTime}
AND book_end_date &gt; #{startTime}
AND book_end_date &lt; #{endTime}
)
OR (
book_start_date &gt; #{startTime}
AND book_end_date &lt; #{endTime}
)
)
ORDER BY
vehicle_id,
book_start_date
) tmp
GROUP BY
tmp.lift_company
</select>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment