|
@@ -1,26 +1,37 @@
|
|
|
package com.pj.project.tb_fee_statistics;
|
|
|
|
|
|
+import java.io.File;
|
|
|
+import java.io.InputStream;
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.date.Month;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
+import com.alibaba.excel.ExcelWriter;
|
|
|
+import com.alibaba.excel.write.metadata.WriteSheet;
|
|
|
+import com.alibaba.excel.write.metadata.fill.FillConfig;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.IService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.pj.api.wx.bo.PriceBO;
|
|
|
+import com.pj.current.config.MyConfig;
|
|
|
import com.pj.current.config.PartConfig;
|
|
|
import com.pj.project.tb_business.TbBusiness;
|
|
|
import com.pj.project.tb_business.TbBusinessService;
|
|
|
import com.pj.project.tb_business_car.TbBusinessCar;
|
|
|
import com.pj.project.tb_business_car.TbBusinessCarService;
|
|
|
import com.pj.project.tb_business_item.TbBusinessItem;
|
|
|
+import com.pj.project.tb_fee_details.ExportFeeDetailDTO;
|
|
|
import com.pj.project.tb_fee_details.TbFeeDetails;
|
|
|
import com.pj.project.tb_fee_details.TbFeeDetailsService;
|
|
|
+import com.pj.project4sp.uploadfile.UploadUtil;
|
|
|
import com.pj.utils.so.SoMap;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.core.io.ClassPathResource;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
@@ -51,6 +62,8 @@ public class TbFeeStatisticsService extends ServiceImpl<TbFeeStatisticsMapper, T
|
|
|
TbFeeDetailsService tbFeeDetailsService;
|
|
|
@Resource
|
|
|
private PartConfig partConfig;
|
|
|
+ @Resource
|
|
|
+ private MyConfig myConfig;
|
|
|
|
|
|
/**
|
|
|
* 增
|
|
@@ -259,4 +272,76 @@ public class TbFeeStatisticsService extends ServiceImpl<TbFeeStatisticsMapper, T
|
|
|
return feeStatistics;
|
|
|
}
|
|
|
|
|
|
+ public String exportMonthStatistics(SoMap so) throws Exception{
|
|
|
+ String monthStr = so.getString("exportMonth");
|
|
|
+ so.put("month",monthStr);
|
|
|
+ Date month = DateUtil.parse(monthStr, "yyyy-MM");
|
|
|
+ Month monthEnum = DateUtil.monthEnum(month);
|
|
|
+ boolean leap = DateUtil.isLeapYear(DateUtil.year(month));
|
|
|
+ Integer lastDay = monthEnum.getLastDay(leap);
|
|
|
+ Map<String, ExportMonthDataDTO> dataMap = new TreeMap<>();
|
|
|
+ for(int i=1; i<=lastDay ; i++){
|
|
|
+ ExportMonthDataDTO data = new ExportMonthDataDTO();
|
|
|
+ String index = i<10 ? "0"+i : ""+i;
|
|
|
+ String day = monthStr + "-" + index;
|
|
|
+ data.setIndex(index).setDay(day);
|
|
|
+ dataMap.put(index, data);
|
|
|
+ }
|
|
|
+ List<TbFeeStatistics> list = this.getList(so);
|
|
|
+ Integer totalIn = 0;
|
|
|
+ Integer totalOut= 0;
|
|
|
+ Integer totalAdd = 0;
|
|
|
+ BigDecimal totalMoney = BigDecimal.valueOf(0);
|
|
|
+ for (TbFeeStatistics statistics : list) {
|
|
|
+ String day = statistics.getDay();
|
|
|
+ String key = StrUtil.sub(day, 8, 10);
|
|
|
+ ExportMonthDataDTO data = dataMap.get(key);
|
|
|
+ List<TbBusinessCar> inCarList = tbBusinessCarService.findInCarByDay(day);
|
|
|
+ List<TbBusinessCar> outCarList = tbBusinessCarService.findOutCarByDay(day);
|
|
|
+ Integer inNum = inCarList != null ? inCarList.size() : 0;
|
|
|
+ Integer outNum = outCarList != null ? outCarList.size() : 0;
|
|
|
+ Integer addNum = inNum - outNum;
|
|
|
+ data.setDay(day).setInNum(inNum).setOutNum(outNum).setAddNum(addNum).setDayMoney(statistics.getTaxMoney());
|
|
|
+ //dataMap.put(key, data);
|
|
|
+ totalIn += inNum;
|
|
|
+ totalOut += outNum;
|
|
|
+ totalAdd += addNum;
|
|
|
+ totalMoney = totalMoney.add(statistics.getTaxMoney());
|
|
|
+ }
|
|
|
+ List<ExportMonthDataDTO> exportList = new ArrayList<>(dataMap.values()) ;
|
|
|
+
|
|
|
+ Map<String, String> head = new HashMap<>();
|
|
|
+ Integer exportMonth = Integer.valueOf(StrUtil.sub(monthStr, 5,7));
|
|
|
+ String today = DateUtil.today();
|
|
|
+ head.put("exportMonth", exportMonth + "");
|
|
|
+ head.put("exportDay", today);
|
|
|
+ head.put("totalIn", totalIn + "");
|
|
|
+ head.put("totalOut", totalOut + "");
|
|
|
+ head.put("totalAdd", totalAdd + "");
|
|
|
+ head.put("totalMoney", totalMoney.toString());
|
|
|
+
|
|
|
+ String separator = File.separator;
|
|
|
+
|
|
|
+ String rootPath = UploadUtil.uploadConfig.rootFolder + separator + UploadUtil.uploadConfig.httpPrefix;
|
|
|
+ String prefix = myConfig.getDomain() + UploadUtil.uploadConfig.httpPrefix;
|
|
|
+ String extPath = "feeStatistics_month" + separator + today + separator;
|
|
|
+ String fileName = "收费月统计表_" + monthStr + ".xlsx";
|
|
|
+ String savePath = rootPath + separator + extPath;
|
|
|
+ File saveFIle = new File(savePath);
|
|
|
+ if (!saveFIle.exists()) {
|
|
|
+ saveFIle.mkdirs();
|
|
|
+ }
|
|
|
+
|
|
|
+ ClassPathResource classPathResource = new ClassPathResource("static/month-fee.xlsx");
|
|
|
+ InputStream tempInputStream =classPathResource.getInputStream();
|
|
|
+ ExcelWriter excelWriter = EasyExcel.write(savePath + fileName, ExportFeeDetailDTO.class)
|
|
|
+ .withTemplate(tempInputStream).build();
|
|
|
+ WriteSheet writeSheet = EasyExcel.writerSheet().build();
|
|
|
+ FillConfig fillConfig = FillConfig.builder().forceNewRow(true).build();//换行
|
|
|
+ excelWriter.fill(head, writeSheet);
|
|
|
+ excelWriter.fill(exportList, fillConfig, writeSheet);
|
|
|
+ excelWriter.finish();
|
|
|
+ return prefix + "/feeStatistics_month/" + today + "/收费月统计表_" + monthStr + ".xlsx";
|
|
|
+ }
|
|
|
+
|
|
|
}
|