Commit feddd783 authored by jiaorz's avatar jiaorz

车辆信息统计

parent 626738d6
......@@ -7,6 +7,7 @@ import org.springframework.format.annotation.DateTimeFormat;
import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.util.Date;
/**
......@@ -40,5 +41,17 @@ public class BranchCompanyVehicleCount {
)
private Date countDate;
@DateTimeFormat(pattern="yyyy-MM-dd")
@JsonFormat(
pattern = "yyyy-MM-dd"
)
@Transient
private Date weekStartDate;
@DateTimeFormat(pattern="yyyy-MM-dd")
@JsonFormat(
pattern = "yyyy-MM-dd"
)
@Transient
private Date weekEndDate;
}
\ No newline at end of file
package com.xxfc.platform.vehicle.pojo;
import lombok.Data;
import java.util.Date;
@Data
public class VehicleWeekCountVo {
private Integer week;
private Date dateTime;
private Integer count;
}
......@@ -4,20 +4,26 @@ 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.google.common.collect.Lists;
import com.google.common.collect.Maps;
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.VehicleWeekCountVo;
import com.xxfc.platform.vehicle.pojo.dto.BranchCompanyVehicleCountDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
import org.springframework.stereotype.Service;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Service
@Slf4j
public class BranchCompanyVehicleCountBiz extends BaseBiz<BranchCompanyVehicleCountMapper, BranchCompanyVehicleCount> {
@Autowired
VehicleInformationDownloadBiz vehicleInformationDownloadBiz;
public ObjectRestResponse add(BranchCompanyVehicleCount branchCompanyVehicleCount) {
if (branchCompanyVehicleCount == null) {
......@@ -31,7 +37,6 @@ public class BranchCompanyVehicleCountBiz extends BaseBiz<BranchCompanyVehicleCo
}
public ObjectRestResponse<PageDataVO<BranchCompanyVehicleCount>> findAll(BranchCompanyVehicleCountDTO branchCompanyVehicleCountDTO) {
vehicleInformationDownloadBiz.addAll();
Integer pageNo = branchCompanyVehicleCountDTO.getPage() == null ? 1 : branchCompanyVehicleCountDTO.getPage();
Integer pageSize = branchCompanyVehicleCountDTO.getLimit() == null ? 10 : branchCompanyVehicleCountDTO.getLimit();
Integer type = branchCompanyVehicleCountDTO.getType() == null ? 1 : branchCompanyVehicleCountDTO.getType();
......@@ -47,7 +52,7 @@ public class BranchCompanyVehicleCountBiz extends BaseBiz<BranchCompanyVehicleCo
}
Query query = new Query(branchCompanyVehicleCountDTO);
PageDataVO<BranchCompanyVehicleCount> pageDataVO = PageDataVO.pageInfo(query, () -> mapper.getAllByParam(query.getSuper()));
return ObjectRestResponse.succ();
return ObjectRestResponse.succ(pageDataVO);
}
public int getCurrentMonthLastDay() {
......@@ -58,4 +63,102 @@ public class BranchCompanyVehicleCountBiz extends BaseBiz<BranchCompanyVehicleCo
return maxDate;
}
/**
* 获取所有公司名称
*
* @return
*/
public List<BranchCompanyVehicleCount> getAllBranchCompanyName() {
return mapper.getAllCompanyName();
}
/**
* 按月统计
*
* @param param
* @return
*/
public List<BranchCompanyVehicleCount> countByMonth(Map<String, Object> param) {
return mapper.countByMonth(param);
}
/**
* 按周统计
*
* @param param
* @return
*/
public List<VehicleWeekCountVo> countByWeek(Map<String, Object> param) {
return mapper.countByWeek(param);
}
/**
* 后台查询统计信息
*
* @param branchCompanyVehicleCountDTO
* @return
*/
public PageDataVO<BranchCompanyVehicleCount> countAllByMonth(BranchCompanyVehicleCountDTO branchCompanyVehicleCountDTO) {
if (StringUtils.isNotBlank(branchCompanyVehicleCountDTO.getCompanyName())) {
Query query = new Query(branchCompanyVehicleCountDTO);
PageDataVO<BranchCompanyVehicleCount> pageDataVO = PageDataVO.pageInfo(query, () -> mapper.countByMonth(query.getSuper()));
return pageDataVO;
}
List<BranchCompanyVehicleCount> resultList = Lists.newArrayList();
List<BranchCompanyVehicleCount> branCompanyNames = getAllBranchCompanyName();
if (branCompanyNames != null && branCompanyNames.size() > 0) {
for (BranchCompanyVehicleCount branchCompanyVehicleCount : branCompanyNames) {
branchCompanyVehicleCountDTO.setCompanyName(branchCompanyVehicleCount.getCompanyName());
Map<String, Object> map = Maps.newHashMap();
map.put("startTime", branchCompanyVehicleCountDTO.getStartTime());
map.put("endTime", branchCompanyVehicleCountDTO.getEndTime());
map.put("companyName", branchCompanyVehicleCountDTO.getCompanyName());
List<BranchCompanyVehicleCount> branchCompanyVehicleCounts = countByMonth(map);
if (branchCompanyVehicleCounts != null && branchCompanyVehicleCounts.size() > 0) {
branchCompanyVehicleCounts.forEach((a) -> a.setCompanyName(branchCompanyVehicleCountDTO.getCompanyName()));
resultList.addAll(branchCompanyVehicleCounts);
}
}
}
PageDataVO<BranchCompanyVehicleCount> pageDataVO = new PageDataVO<>();
if (resultList.size() > 0) {
List<BranchCompanyVehicleCount> dataList = resultList.subList((branchCompanyVehicleCountDTO.getPage() - 1) * branchCompanyVehicleCountDTO.getLimit(), branchCompanyVehicleCountDTO.getPage() * branchCompanyVehicleCountDTO.getLimit());
pageDataVO.setData(dataList);
} else {
pageDataVO.setData(resultList);
}
pageDataVO.setTotalCount(Long.parseLong(resultList.size() + ""));
pageDataVO.setTotalPage(resultList.size() % branchCompanyVehicleCountDTO.getLimit() == 0 ? resultList.size() / branchCompanyVehicleCountDTO.getLimit() : resultList.size() / branchCompanyVehicleCountDTO.getLimit() + 1);
pageDataVO.setPageNum(branchCompanyVehicleCountDTO.getLimit());
pageDataVO.setPageSize(branchCompanyVehicleCountDTO.getPage());
return pageDataVO;
}
/**
* 按周统计
*
* @param branchCompanyVehicleCountDTO
* @return
*/
public PageDataVO<BranchCompanyVehicleCount> countAllByWeek(BranchCompanyVehicleCountDTO branchCompanyVehicleCountDTO) {
if (StringUtils.isNotBlank(branchCompanyVehicleCountDTO.getCompanyName())) {
Query query = new Query(branchCompanyVehicleCountDTO);
PageDataVO<VehicleWeekCountVo> pageDataVO = PageDataVO.pageInfo(query, () -> mapper.countByWeek(query.getSuper()));
if (pageDataVO.getData() != null && pageDataVO.getData().size() > 0) {
List<BranchCompanyVehicleCount> list = Lists.newArrayList();
pageDataVO.getData().forEach(result -> {
BranchCompanyVehicleCount branchCompanyVehicleCount = new BranchCompanyVehicleCount();
branchCompanyVehicleCount.setCompanyName(branchCompanyVehicleCountDTO.getCompanyName());
branchCompanyVehicleCount.setCountDate(result.getDateTime());
branchCompanyVehicleCount.setVehicleNum(result.getCount());
Date weekStartDate = OrderDateUtils.getStartDayOfWeekNo(result.getDateTime().getYear(), result.getWeek());
branchCompanyVehicleCount.setWeekStartDate();
list.add(branchCompanyVehicleCount);
});
}
return pageDataVO;
}
return null;
}
}
package com.xxfc.platform.vehicle.mapper;
import com.xxfc.platform.vehicle.entity.BranchCompanyVehicleCount;
import com.xxfc.platform.vehicle.pojo.VehicleWeekCountVo;
import tk.mybatis.mapper.common.Mapper;
import java.util.List;
......@@ -9,4 +10,7 @@ import java.util.Map;
public interface BranchCompanyVehicleCountMapper extends Mapper<BranchCompanyVehicleCount> {
List<BranchCompanyVehicleCount> getAllByParam(Map<String, Object> param);
List<BranchCompanyVehicleCount> getAllCompanyName();
List<BranchCompanyVehicleCount> countByMonth(Map<String, Object> param);
List<VehicleWeekCountVo> countByWeek(Map<String, Object> param);
}
\ No newline at end of file
......@@ -103,4 +103,9 @@ public class VehicleInformationDownloadController extends BaseController<Vehicle
IoUtil.close(out);
}
@GetMapping("/app/unauth/addAll")
public void addAll() {
baseBiz.addAll();
}
}
......@@ -34,4 +34,55 @@
</where>
GROUP BY company_name
</select>
<select id="getAllCompanyName" resultType="com.xxfc.platform.vehicle.entity.BranchCompanyVehicleCount">
select distinct(company_name) from branch_company_vehicle_count group by company_name
</select>
<select id="countByMonth" parameterType="Map" resultType="com.xxfc.platform.vehicle.entity.BranchCompanyVehicleCount">
SELECT
DATE_FORMAT(b2.count_date, "%Y年%m月") AS countDate,
sum(b2.vehicle_num) as vehicleNum
FROM
(
select tmp.*
FROM
(
SELECT
b.*
FROM
branch_company_vehicle_count b
WHERE
b.company_name like concat('%', #{companyName}, '%')
<if test="startTime != null and startTime != ''">
and count_date &gt;= #{startTime} and count_date &lt;= #{endTime}
</if>
)tmp
) b2
GROUP BY
DATE_FORMAT(b2.count_date, "%Y年%m月")
ORDER BY
DATE_FORMAT(b2.count_date, "%Y年%m月") DESC;
</select>
<select id="countByWeek" resultType="com.xxfc.platform.vehicle.pojo.VehicleWeekCountVo" parameterType="Map">
SELECT DATE_FORMAT(count_date,'%u') as week,min(count_date) as dateTime,sum(b2.vehicle_num) as count
FROM (
select tmp.*
FROM
(
SELECT
b.*
FROM
branch_company_vehicle_count b
WHERE
b.company_name like concat('%', #{companyName}, '%')
<if test="startTime != null and startTime != ''">
and count_date &gt;= #{startTime} and count_date &lt;= #{endTime}
</if>
)tmp
) b2
GROUP BY week
ORDER BY week asc;
</select>
</mapper>
\ No newline at end of file
......@@ -592,15 +592,9 @@
<!--导出分公司停靠所有车辆-->
<select id="getAllVehicleInfo" resultType="com.xxfc.platform.vehicle.pojo.BranchCompanyVehicleCountVo" parameterType="Map">
select tmp.name as parkBranchCompanyName, COUNT(0) as count from (
select v1.number_plate, b.name from vehicle_book_record v
LEFT JOIN branch_company b on b.id = v.lift_company
LEFT JOIN vehicle v1 on v1.id = v.vehicle_id
where v.`status` != 4 and v.`status` != 6
and v.book_start_date &gt; #{startTime} and v.book_start_date &lt; #{endTime}
ORDER BY v.vehicle_id, v.book_start_date DESC
) tmp
GROUP BY name
select b.id as companyId, b.name as companyName, DATE_FORMAT(now(),'%Y') as countYear, DATE_FORMAT(now(),'%m') as countMonth,DATE_FORMAT(now(),'%u') as countWeek,DATE_FORMAT(now(),'%Y-%m-%d') as countDate,count(*) from vehicle v
LEFT JOIN branch_company b on b.id = v.park_branch_company_id
GROUP BY b.id
</select>
<select id="lockByCode" resultType="com.xxfc.platform.vehicle.entity.Vehicle"
......
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