From c5fd66896596c2ba00d46e1328296604aaf5b8be Mon Sep 17 00:00:00 2001
From: rk <94314517@qq.com>
Date: 星期四, 12 三月 2026 17:36:46 +0800
Subject: [PATCH] 报表数据
---
server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/CarUseBookServiceImpl.java | 186 +++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 180 insertions(+), 6 deletions(-)
diff --git a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/CarUseBookServiceImpl.java b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/CarUseBookServiceImpl.java
index a12733a..e4fa22a 100644
--- a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/CarUseBookServiceImpl.java
+++ b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/CarUseBookServiceImpl.java
@@ -3,10 +3,15 @@
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.doumee.biz.system.SystemDictDataBiz;
+import com.doumee.core.annotation.excel.ExcelExporter;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.dao.admin.response.InterestedListVO;
import com.doumee.dao.business.dao.UserActionMapper;
+import com.doumee.dao.business.dto.CarUseDataDTO;
+import com.doumee.dao.business.dto.InParkDataDTO;
+import com.doumee.dao.business.vo.GeneralDataVO;
+import com.doumee.dao.business.vo.InParkUserDataVO;
import com.doumee.service.business.third.model.LoginUserInfo;
import com.doumee.service.business.third.model.PageData;
import com.doumee.service.business.third.model.PageWrap;
@@ -44,10 +49,13 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
-import java.time.LocalDateTime;
-import java.time.ZoneId;
-import java.time.ZonedDateTime;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.net.URLEncoder;
+import java.nio.charset.Charset;
+import java.time.*;
import java.time.format.DateTimeFormatter;
+import java.time.temporal.TemporalAdjusters;
import java.util.*;
import java.util.Date;
import java.util.stream.Collectors;
@@ -789,7 +797,173 @@
}
return list;
}
-
-
-
+
+
+
+
+ public InParkUserDataVO getCarUseData(CarUseDataDTO carUseDataDTO){
+ //鏌ヨ鏈懆鐨勫紑濮嬫棩鏈熷拰缁撴潫鏃ユ湡
+ Long weekStart = LocalDate.now().with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY)).atStartOfDay(ZoneOffset.UTC).toInstant().toEpochMilli();
+ InParkUserDataVO inParkUserDataVO = new InParkUserDataVO();
+ List<CarUseBook> yearList = carUseBookMapper.selectJoinList(CarUseBook.class,new MPJLambdaWrapper<CarUseBook>()
+ .selectAll(CarUseBook.class)
+ .eq(CarUseBook::getIsdeleted,Constants.ZERO)
+ .apply(" ( DATE_FORMAT(CREATE_DATE, '%Y') = DATE_FORMAT(now(), '%Y') ) ")
+ );
+ List<CarUseBook> monthList = yearList.stream().filter(i->DateUtil.formatDate(i.getCreateDate(),"yyyy-MM").equals(DateUtil.formatDate(new Date(),"yyyy-MM"))).collect(Collectors.toList());
+ List<CarUseBook> weekList = yearList.stream().filter(i->i.getCreateDate().getTime()>=weekStart).collect(Collectors.toList());
+ List<CarUseBook> todayList = weekList.stream().filter(i-> DateUtil.formatDate(i.getCreateDate(),"yyyy-MM-dd").equals(DateUtil.formatDate(new Date(),"yyyy-MM-dd"))).collect(Collectors.toList());
+ List<CarUseBook> yesterdayList = yearList.stream().filter(i-> DateUtil.formatDate(i.getCreateDate(),"yyyy-MM-dd").equals(DateUtil.getBeforDay(new Date(),1))).collect(Collectors.toList());
+ inParkUserDataVO.setYearTotal(yearList.size());
+ inParkUserDataVO.setMonthTotal(monthList.size());
+ inParkUserDataVO.setTodayTotal(todayList.size());
+ inParkUserDataVO.setWeekTotal(weekList.size());
+ inParkUserDataVO.setYesterdayTotal(yesterdayList.size());
+// //澶勭悊骞村害鎶樼嚎鍥炬暟鎹�
+ List<GeneralDataVO> cumulativeDataList = new ArrayList<>();
+ for (int i = 1; i <=12 ; i++) {
+ GeneralDataVO generalDataVO = new GeneralDataVO();
+ generalDataVO.setName(Integer.toString(i));
+ generalDataVO.setTotal(yearList.stream().filter(j->Constants.equalsInteger(Integer.valueOf(generalDataVO.getName()),Integer.valueOf(DateUtil.formatDate(j.getCreateDate(),"MM")))).collect(Collectors.toList()).size());
+ generalDataVO.setName(generalDataVO.getName()+"鏈�");
+ cumulativeDataList.add(generalDataVO);
+ }
+ inParkUserDataVO.setCumulativeDataList(cumulativeDataList);
+ return inParkUserDataVO;
+ }
+
+
+ @Override
+ public List<List<String>> getReportList(CarUseDataDTO carUseDataDTO){
+ if(Objects.isNull(carUseDataDTO)
+ || StringUtils.isBlank(carUseDataDTO.getDateStr())
+ || !( Constants.equalsInteger(carUseDataDTO.getDateStr().length(),4) || Constants.equalsInteger(carUseDataDTO.getDateStr().length(),7) )
+ ){
+ throw new BusinessException(ResponseStatus.BAD_REQUEST);
+ }
+ List<CarUseBook> allList = new ArrayList<>();
+ MPJLambdaWrapper mpjLambdaWrapper = new MPJLambdaWrapper<CarUseBook>()
+ .eq(CarUseBook::getIsdeleted,Constants.ZERO)
+ .in(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(carUseDataDTO.getCarCodeList()),CarUseBook::getCarCode,carUseDataDTO.getCarCodeList())
+ .apply(Constants.equalsInteger(carUseDataDTO.getDateStr().length(),4)," ( DATE_FORMAT(CREATE_DATE, '%Y') = '"+carUseDataDTO.getDateStr()+"' ) ")
+ .apply(Constants.equalsInteger(carUseDataDTO.getDateStr().length(),7)," ( DATE_FORMAT(CREATE_DATE, '%Y-%m') = '"+carUseDataDTO.getDateStr()+"' ) ");
+ mpjLambdaWrapper.groupBy(Constants.equalsInteger(carUseDataDTO.getDateStr().length(),4),
+ "car_code,DATE_FORMAT(CREATE_DATE, '%Y-%m')")
+ .groupBy(Constants.equalsInteger(carUseDataDTO.getDateStr().length(),7),
+ "car_code,DATE_FORMAT(CREATE_DATE, '%Y-%m-%d')");
+ if(Constants.equalsInteger(carUseDataDTO.getDateStr().length(),4)){
+ mpjLambdaWrapper.select("car_code,DATE_FORMAT(CREATE_DATE, '%Y-%m') as createDateStr ");
+ }else{
+ mpjLambdaWrapper.select("car_code,DATE_FORMAT(CREATE_DATE, '%Y-%m-%d') as createDateStr ");
+ }
+ allList = carUseBookMapper.selectJoinList(CarUseBook.class,mpjLambdaWrapper);
+
+ List<List<String>> resultList = new ArrayList<>();
+
+
+ List<String> dateList = new ArrayList<>();
+ //骞翠唤
+ if(Constants.equalsInteger(carUseDataDTO.getDateStr().length(),4)){
+ Integer maxMonth = 12;
+ if(Constants.equalsInteger(DateUtil.getNowYearNum(),Integer.valueOf(carUseDataDTO.getDateStr()))){
+ maxMonth = DateUtil.getNowMonthNum();
+ }
+ for (int i = maxMonth; i >0 ; i--) {
+ dateList.add(DateUtil.getNowYearNum()+"-"+ StringUtils.leftPad(i+"",2,"0"));
+ }
+ }else {
+ //鏃ユ湡
+ Integer year = Integer.valueOf(carUseDataDTO.getDateStr().substring(0,4));
+ Integer month = Integer.valueOf(carUseDataDTO.getDateStr().substring(5,7));
+ Integer today = DateUtil.getNowDayNum();
+ YearMonth yearMonth = YearMonth.of(year, month);
+ // 鑾峰彇璇ユ湀鐨勬渶鍚庝竴澶�
+ LocalDate lastDayDate = yearMonth.atEndOfMonth();
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd");
+ Integer lastDay = Integer.valueOf(lastDayDate.format(formatter));
+ if(Constants.equalsInteger(year,DateUtil.getNowYearNum()) && Constants.equalsInteger(month,DateUtil.getNowMonthNum())){
+ if(today < lastDay){
+ lastDay = today;
+ }
+ }
+ for (int i = lastDay; i > 0 ; i--) {
+ dateList.add(year + "-" + StringUtils.leftPad(month.toString(),2,"0") + "-" + StringUtils.leftPad(Integer.toString(i),2,"0"));
+ }
+ }
+ return this.dealResultData(allList,carUseDataDTO.getCarCodeList(),dateList,carUseDataDTO.getDateStr());
+ }
+
+
+ public List<List<String>> dealResultData(List<CarUseBook> allList,List<String> queryCarList,List<String> dataList ,String dateStr){
+ List<List<String>> resultList = new ArrayList<>();
+ List<String> totalString = new ArrayList<>();
+ totalString.add("鏁版嵁鏃ユ湡");
+ List<String> carCodeList = new ArrayList<>();
+ if (com.github.xiaoymin.knife4j.core.util.CollectionUtils.isEmpty(queryCarList)) {
+ List<Cars> list = carsMapper.selectJoinList(Cars.class,
+ new MPJLambdaWrapper<Cars>().selectAll(Cars.class)
+ .leftJoin(Category.class,Category::getId,Cars::getCateId)
+ .eq(Category::getBizType,Constants.FOUR)
+ .eq(Cars::getIsdeleted,Constants.ZERO)
+ );
+ if(CollectionUtils.isEmpty(list)){
+ return resultList;
+ }
+ carCodeList = list.stream().map(i->i.getCode()).collect(Collectors.toList());
+ }else{
+ carCodeList = queryCarList;
+ }
+ Set<String> setList = new HashSet<>(carCodeList);
+ for (String categoryName:setList) {
+ totalString.add(categoryName);
+ }
+ totalString.add("鍚堣");
+ resultList.add(totalString);
+ for (String str:dataList) {
+ Integer total = 0;
+ List<String> dataChildList = new ArrayList<>();
+ dataChildList.add(str);
+ for (String carCode:setList) {
+ if(Constants.equalsInteger(dateStr.length(),4)){
+ Integer childNum = allList.stream().filter(i->carCode.equals(i.getCarCode())
+ && i.getCreateDateStr().equals(str)).collect(Collectors.toList()).size();
+ dataChildList.add(
+ Integer.toString(childNum)
+ );
+ total = total + childNum;
+ }else if(Constants.equalsInteger(dateStr.length(),7)){
+ Integer childNum = allList.stream().filter(i->carCode.equals(i.getCarCode())
+ &&i.getCreateDateStr().equals(str)).collect(Collectors.toList()).size();
+ dataChildList.add(
+ Integer.toString(childNum)
+ );
+ total = total + childNum;
+ }
+ }
+ dataChildList.add(Integer.toString(total));
+ resultList.add(dataChildList);
+ }
+ return resultList;
+ }
+
+
+ @Override
+ public void excel(CarUseDataDTO carUseDataDTO, HttpServletResponse response){
+ List<List<String>> data = this.getReportList(carUseDataDTO);
+ try {
+ String fileName = "娲捐溅鐢宠缁熻琛╛"+System.currentTimeMillis();
+ String encodeFileName = URLEncoder.encode(fileName, Charset.forName("UTF-8").toString()) + ".xlsx";
+ response.setHeader("Content-Disposition","attachment;filename=" + encodeFileName);
+ response.setContentType("application/octet-stream");
+ response.setHeader("eva-opera-type", "download");
+ response.setHeader("eva-download-filename", encodeFileName);
+ ExcelExporter.exportList(data, fileName, response.getOutputStream());
+ } catch (IOException e) {
+ throw new BusinessException(ResponseStatus.EXPORT_EXCEL_ERROR, e);
+ }
+ }
+
+
+
+
}
--
Gitblit v1.9.3