|
@@ -1,24 +1,53 @@
|
|
|
package com.hjy.module.service.report.impl;
|
|
|
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
+import cn.hutool.core.util.NumberUtil;
|
|
|
+import cn.hutool.core.util.ReflectUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
+import cn.hutool.poi.excel.ExcelReader;
|
|
|
+import cn.hutool.poi.excel.ExcelUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.hjy.common.config.ZhbsqConfig;
|
|
|
import com.hjy.common.core.page.TableDataInfo;
|
|
|
import com.hjy.common.utils.PageUtils;
|
|
|
|
|
|
+import com.hjy.common.utils.StringUtils;
|
|
|
import com.hjy.common.utils.file.FileUploadUtils;
|
|
|
-import com.hjy.module.domain.report.ReportRecord;
|
|
|
-import com.hjy.module.domain.report.ReportWord;
|
|
|
+import com.hjy.module.domain.report.*;
|
|
|
import com.hjy.module.mapper.report.ReportRecordMapper;
|
|
|
+import com.hjy.module.service.activecompanies.IActiveCompaniesService;
|
|
|
import com.hjy.module.service.report.IReportRecordService;
|
|
|
+import com.hjy.module.service.report.IReportTemplateService;
|
|
|
import com.hjy.module.service.report.IReportWordService;
|
|
|
+import com.hjy.module.service.template.IExcelOutInTotalService;
|
|
|
+import com.hjy.module.vo.activecompanies.ActiveCompaniesVo;
|
|
|
import com.hjy.module.vo.report.ReportRecordVo;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.poi.ss.usermodel.*;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
+import org.apache.poi.xwpf.usermodel.*;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileInputStream;
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.lang.reflect.Field;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.nio.file.Paths;
|
|
|
+import java.sql.PreparedStatement;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import static cn.hutool.poi.excel.cell.CellUtil.getCellValue;
|
|
|
+import static java.lang.Character.getNumericValue;
|
|
|
|
|
|
/**
|
|
|
* 辅助决策Service业务层处理
|
|
@@ -27,11 +56,23 @@ import java.util.List;
|
|
|
* @date 2024-04-26
|
|
|
*/
|
|
|
@Service
|
|
|
+@Slf4j
|
|
|
public class ReportRecordServiceImpl extends ServiceImpl<ReportRecordMapper, ReportRecord> implements IReportRecordService {
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
private IReportWordService reportWordService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private IExcelOutInTotalService excelOutInTotalService;
|
|
|
+ @Resource
|
|
|
+ private IReportTemplateService reportTemplateService;
|
|
|
+ @Resource
|
|
|
+ private IReportRecordService reportRecordService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private IActiveCompaniesService activeCompaniesService;
|
|
|
+
|
|
|
@Override
|
|
|
public TableDataInfo<ReportRecordVo> queryList(ReportRecordVo entity) {
|
|
|
return PageUtils.buildDataInfo(this.baseMapper.queryList(PageUtils.buildPage(), entity));
|
|
@@ -43,7 +84,6 @@ public class ReportRecordServiceImpl extends ServiceImpl<ReportRecordMapper, Rep
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
@Override
|
|
|
public ReportRecordVo queryById(String id) {
|
|
|
return this.baseMapper.queryById(id);
|
|
@@ -51,21 +91,468 @@ public class ReportRecordServiceImpl extends ServiceImpl<ReportRecordMapper, Rep
|
|
|
|
|
|
@Override
|
|
|
public ReportRecord findReport(String year, String month) {
|
|
|
- QueryWrapper<ReportRecord>ew=new QueryWrapper<>();
|
|
|
- ew.lambda().eq(ReportRecord::getReportYear,year)
|
|
|
- .eq(ReportRecord::getReportMonth,month);
|
|
|
- List<ReportRecord>list= list(ew);
|
|
|
- return list.isEmpty()?null:list.get(0);
|
|
|
+ QueryWrapper<ReportRecord> ew = new QueryWrapper<>();
|
|
|
+ ew.lambda().eq(ReportRecord::getReportYear, year)
|
|
|
+ .eq(ReportRecord::getReportMonth, month);
|
|
|
+ List<ReportRecord> list = list(ew);
|
|
|
+ return list.isEmpty() ? null : list.get(0);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public boolean upload(MultipartFile file, String id) throws Exception{
|
|
|
+ public boolean upload(MultipartFile file, String id) throws Exception {
|
|
|
String filePath = ZhbsqConfig.getWordPath();
|
|
|
- String fileName ="/profile"+ FileUploadUtils.upload(filePath, file);
|
|
|
- ReportWord reportWord=new ReportWord();
|
|
|
+ String fileName = "/profile" + FileUploadUtils.upload(filePath, file);
|
|
|
+ ReportWord reportWord = new ReportWord();
|
|
|
reportWord.setWordName(file.getOriginalFilename()).setWordPath(fileName).setRecordId(id);
|
|
|
reportWordService.save(reportWord);
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String importExcel(MultipartFile file) throws Exception {
|
|
|
+ String filePath = ZhbsqConfig.getUploadPath() + "/analyze/";
|
|
|
+ File saveDirFile = new File(filePath);
|
|
|
+ if (!saveDirFile.exists()) {
|
|
|
+ saveDirFile.mkdirs();
|
|
|
+ }
|
|
|
+ String fileName = file.getOriginalFilename();
|
|
|
+ File checkFile = new File(saveDirFile + fileName);
|
|
|
+ if (checkFile.exists()) {
|
|
|
+ FileUtil.del(checkFile);
|
|
|
+ }
|
|
|
+ String absPath = FileUploadUtils.getAbsoluteFile(filePath, fileName).getAbsolutePath();
|
|
|
+ file.transferTo(Paths.get(absPath));
|
|
|
+ return absPath;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int saveForm(ReportRecordVo entity) {
|
|
|
+ final String inoutStr = "特定地区进出口总值表";
|
|
|
+ final String tradeTypeStr = "加工贸易";
|
|
|
+ final String activeCompanyStr = "活跃家数";
|
|
|
+ String paths = entity.getPaths();
|
|
|
+ StrUtil.split(paths, ",").forEach(path -> {
|
|
|
+ try (ExcelReader reader = ExcelUtil.getReader(path, 0)) {
|
|
|
+ String text = reader.readAsText(false);
|
|
|
+ if (StrUtil.contains(text, inoutStr)) {
|
|
|
+ excelOutInTotalService.analyze(reader, entity.getGxTradeTotalMoney(), entity.getPreface());
|
|
|
+ } else if (StrUtil.contains(text, activeCompanyStr)) {
|
|
|
+ analyzeActiveCompany(entity.getGxTradeTotalMoney(), entity.getPreface(), path);
|
|
|
+ } else if (StrUtil.contains(text, tradeTypeStr)) {
|
|
|
+ analyzeTradeType(entity.getGxTradeTotalMoney(), entity.getPreface(), path);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void analyzeTradeType(String gxTradeTotalMoney, String preface, String filePath) {
|
|
|
+ final String nn = "南宁";
|
|
|
+ final String wz = "梧州";
|
|
|
+ final String qz = "钦州";
|
|
|
+ final String bh = "北海";
|
|
|
+ final String px = "凭祥";
|
|
|
+ final String chineseStr = "中文";
|
|
|
+ final String regionStr = "地区";
|
|
|
+ final String totalStr = "合计";
|
|
|
+ final String jgStr = "加工";
|
|
|
+ final String bsStr = "保税";
|
|
|
+ TradeTypeReportDTO tradeTypeReportDTO = new TradeTypeReportDTO();
|
|
|
+ tradeTypeReportDTO.setPreface(preface);
|
|
|
+ BigDecimal hundred = BigDecimal.valueOf(100);
|
|
|
+ try (FileInputStream fis = new FileInputStream(filePath)) {
|
|
|
+ // 创建Workbook对象
|
|
|
+ Workbook workbook = WorkbookFactory.create(fis);
|
|
|
+ // 获取工作簿
|
|
|
+ Sheet sheet = workbook.getSheetAt(0);
|
|
|
+
|
|
|
+ // 获取数据开始行和列
|
|
|
+ int dataStartRow = 2;
|
|
|
+ int lastRowNum = sheet.getLastRowNum();
|
|
|
+ String year = "";
|
|
|
+ String month = "";
|
|
|
+ String currentArea = "全区";
|
|
|
+ // 遍历每个综保区
|
|
|
+ for (int rowNum = dataStartRow; rowNum <= lastRowNum; rowNum++) {
|
|
|
+ Row row = sheet.getRow(rowNum);
|
|
|
+ // 提取数据
|
|
|
+ if (row != null) {
|
|
|
+ if (row.getCell(0) == null && row.getCell(1) == null) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ String region = getValue(row.getCell(0));
|
|
|
+ String tradeType = getValue(row.getCell(1));
|
|
|
+ String valueRMB = getValue(row.getCell(2));
|
|
|
+ String valueRMBChange = getValue(row.getCell(3));
|
|
|
+ valueRMBChange = StrUtil.contains(valueRMBChange, "-") ? valueRMBChange : valueRMBChange + "%";
|
|
|
+ if (StrUtil.contains(region, regionStr)) {
|
|
|
+ month = StrUtil.subAfter(valueRMB, "年", true).replace("月", "");
|
|
|
+ year = StrUtil.subBetween(valueRMB, "-", "年");
|
|
|
+ continue;
|
|
|
+ } else if (StrUtil.contains(region, chineseStr)) {
|
|
|
+ continue;
|
|
|
+ } else if (StrUtil.contains(region, totalStr)) {
|
|
|
+ tradeTypeReportDTO.setTradeTypeAllTotal(valueRMB).setTradeTypeAllTotalInc(valueRMBChange);
|
|
|
+ continue;
|
|
|
+ } else if (StrUtil.contains(region, bh)) {
|
|
|
+ currentArea = bh;
|
|
|
+ tradeTypeReportDTO.setTradeTypeBHTotal(valueRMB).setTradeTypeBHTotalInc(valueRMBChange);
|
|
|
+ } else if (StrUtil.contains(region, wz)) {
|
|
|
+ currentArea = wz;
|
|
|
+ tradeTypeReportDTO.setTradeTypeWZTotal(valueRMB).setTradeTypeWZTotalInc(valueRMBChange);
|
|
|
+ } else if (StrUtil.contains(region, nn)) {
|
|
|
+ currentArea = nn;
|
|
|
+ tradeTypeReportDTO.setTradeTypeNNTotal(valueRMB).setTradeTypeNNTotalInc(valueRMBChange);
|
|
|
+ } else if (StrUtil.contains(region, px)) {
|
|
|
+ currentArea = px;
|
|
|
+ tradeTypeReportDTO.setTradeTypePXTotal(valueRMB).setTradeTypePXTotalInc(valueRMBChange);
|
|
|
+ } else if (StrUtil.contains(region, qz)) {
|
|
|
+ currentArea = qz;
|
|
|
+ tradeTypeReportDTO.setTradeTypeQZTotal(valueRMB).setTradeTypeQZTotalInc(valueRMBChange);
|
|
|
+ }
|
|
|
+ if (StrUtil.equals(currentArea, nn)) {
|
|
|
+ if (StrUtil.contains(tradeType, jgStr)) {
|
|
|
+ tradeTypeReportDTO.setTradeJGNNTotal(valueRMB).setTradeJGNNTotalInc(valueRMBChange);
|
|
|
+ } else if (StrUtil.contains(tradeType, bsStr)) {
|
|
|
+ tradeTypeReportDTO.setTradeBSNNTotal(valueRMB).setTradeBSNNTotalInc(valueRMBChange);
|
|
|
+ }
|
|
|
+ } else if (StrUtil.equals(currentArea, px)) {
|
|
|
+ if (StrUtil.contains(tradeType, jgStr)) {
|
|
|
+ tradeTypeReportDTO.setTradeJGPXTotal(valueRMB).setTradeJGPXTotalInc(valueRMBChange);
|
|
|
+ } else if (StrUtil.contains(tradeType, bsStr)) {
|
|
|
+ tradeTypeReportDTO.setTradeBSPXTotal(valueRMB).setTradeBSPXTotalInc(valueRMBChange);
|
|
|
+ }
|
|
|
+ } else if (StrUtil.equals(currentArea, bh)) {
|
|
|
+ if (StrUtil.contains(tradeType, jgStr)) {
|
|
|
+ tradeTypeReportDTO.setTradeJGBHTotal(valueRMB).setTradeJGBHTotalInc(valueRMBChange);
|
|
|
+ } else if (StrUtil.contains(tradeType, bsStr)) {
|
|
|
+ tradeTypeReportDTO.setTradeBSBHTotal(valueRMB).setTradeBSBHTotalInc(valueRMBChange);
|
|
|
+ }
|
|
|
+ } else if (StrUtil.equals(currentArea, qz)) {
|
|
|
+ if (StrUtil.contains(tradeType, jgStr)) {
|
|
|
+ tradeTypeReportDTO.setTradeJGQZTotal(valueRMB).setTradeJGQZTotalInc(valueRMBChange);
|
|
|
+ } else if (StrUtil.contains(tradeType, bsStr)) {
|
|
|
+ tradeTypeReportDTO.setTradeBSQZTotal(valueRMB).setTradeBSQZTotalInc(valueRMBChange);
|
|
|
+ }
|
|
|
+ } else if (StrUtil.equals(currentArea, wz)) {
|
|
|
+ if (StrUtil.contains(tradeType, jgStr)) {
|
|
|
+ tradeTypeReportDTO.setTradeJGWZTotal(valueRMB).setTradeJGWZTotalInc(valueRMBChange);
|
|
|
+ } else if (StrUtil.contains(tradeType, bsStr)) {
|
|
|
+ tradeTypeReportDTO.setTradeBSWZTotal(valueRMB).setTradeBSWZTotalInc(valueRMBChange);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.info("record:{},{},{},{},{},{}", region, tradeType, valueRMB, valueRMBChange, year, month);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ tradeTypeReportDTO.setYear(year).setMonth(month);
|
|
|
+ BigDecimal tradeBSNNTotal = StringUtils.strToBigDecimal(tradeTypeReportDTO.getTradeBSNNTotal());
|
|
|
+ BigDecimal tradeBSPXTotal = StringUtils.strToBigDecimal(tradeTypeReportDTO.getTradeBSPXTotal());
|
|
|
+ BigDecimal tradeBSWZTotal = StringUtils.strToBigDecimal(tradeTypeReportDTO.getTradeBSWZTotal());
|
|
|
+ BigDecimal tradeBSQZTotal = StringUtils.strToBigDecimal(tradeTypeReportDTO.getTradeBSQZTotal());
|
|
|
+ BigDecimal tradeBSBHTotal = StringUtils.strToBigDecimal(tradeTypeReportDTO.getTradeBSBHTotal());
|
|
|
+ String bsTotal = tradeBSNNTotal.add(tradeBSPXTotal).add(tradeBSWZTotal).add(tradeBSQZTotal).add(tradeBSBHTotal).toString();
|
|
|
+ tradeTypeReportDTO.setTradeBSAllTotal(bsTotal);
|
|
|
+ BigDecimal tradeJGNNTotal = StringUtils.strToBigDecimal(tradeTypeReportDTO.getTradeJGNNTotal());
|
|
|
+ BigDecimal tradeJGPXTotal = StringUtils.strToBigDecimal(tradeTypeReportDTO.getTradeJGPXTotal());
|
|
|
+ BigDecimal tradeJGWZTotal = StringUtils.strToBigDecimal(tradeTypeReportDTO.getTradeJGWZTotal());
|
|
|
+ BigDecimal tradeJGQZTotal = StringUtils.strToBigDecimal(tradeTypeReportDTO.getTradeJGQZTotal());
|
|
|
+ BigDecimal tradeJGBHTotal = StringUtils.strToBigDecimal(tradeTypeReportDTO.getTradeJGBHTotal());
|
|
|
+ String jgTotal = tradeJGNNTotal.add(tradeJGPXTotal).add(tradeJGWZTotal).add(tradeJGQZTotal).add(tradeJGBHTotal).toString();
|
|
|
+ tradeTypeReportDTO.setTradeJGAllTotal(jgTotal);
|
|
|
+ if (StrUtil.isNotEmpty(gxTradeTotalMoney)) {
|
|
|
+ tradeTypeReportDTO.setGxTradeTotalMoney(gxTradeTotalMoney);
|
|
|
+ BigDecimal gxTradeTotal = new BigDecimal(gxTradeTotalMoney);
|
|
|
+ String bsTradeAllPercent = new BigDecimal(tradeTypeReportDTO.getTradeTypeAllTotal())
|
|
|
+ .divide(gxTradeTotal, 3, RoundingMode.UP).multiply(hundred) + "%";
|
|
|
+ tradeTypeReportDTO.setBsTradeAllPercent(bsTradeAllPercent);
|
|
|
+ String bsNNTradeAllPercent = new BigDecimal(tradeTypeReportDTO.getTradeTypeNNTotal())
|
|
|
+ .divide(gxTradeTotal, 3, RoundingMode.UP).multiply(hundred) + "%";
|
|
|
+
|
|
|
+ String bsPXTradeAllPercent = new BigDecimal(tradeTypeReportDTO.getTradeTypePXTotal())
|
|
|
+ .divide(gxTradeTotal, 3, RoundingMode.UP).multiply(hundred) + "%";
|
|
|
+
|
|
|
+ String bsWzTradeAllPercent = new BigDecimal(tradeTypeReportDTO.getTradeTypeWZTotal())
|
|
|
+ .divide(gxTradeTotal, 3, RoundingMode.UP).multiply(hundred) + "%";
|
|
|
+
|
|
|
+ String bsQZTradeAllPercent = new BigDecimal(tradeTypeReportDTO.getTradeTypeQZTotal())
|
|
|
+ .divide(gxTradeTotal, 3, RoundingMode.UP).multiply(hundred) + "%";
|
|
|
+ String bsBHTradeAllPercent = new BigDecimal(tradeTypeReportDTO.getTradeTypeBHTotal())
|
|
|
+ .divide(gxTradeTotal, 3, RoundingMode.UP).multiply(hundred) + "%";
|
|
|
+ tradeTypeReportDTO.setBsNNTradeAllPercent(bsNNTradeAllPercent)
|
|
|
+ .setBsPXTradeAllPercent(bsPXTradeAllPercent)
|
|
|
+ .setBsWZTradeAllPercent(bsWzTradeAllPercent)
|
|
|
+ .setBsQZTradeAllPercent(bsQZTradeAllPercent)
|
|
|
+ .setBsBHTradeAllPercent(bsBHTradeAllPercent);
|
|
|
+ }
|
|
|
+
|
|
|
+ workbook.close();
|
|
|
+ log.info("report data:{}", JSONUtil.toJsonStr(tradeTypeReportDTO));
|
|
|
+ ReportRecord reportRecord = createReport(year, month);
|
|
|
+ createWord(tradeTypeReportDTO, reportRecord);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private ReportRecord createReport(String year, String month) {
|
|
|
+ ReportRecord reportRecord = reportRecordService.findReport(year, month);
|
|
|
+ if (reportRecord == null) {
|
|
|
+ reportRecord = new ReportRecord();
|
|
|
+ reportRecord.setReportYear(year)
|
|
|
+ .setReportMonth(month);
|
|
|
+ reportRecordService.save(reportRecord);
|
|
|
+ }
|
|
|
+ return reportRecord;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getValue(Cell cell) {
|
|
|
+ CellType cellType = cell.getCellType();
|
|
|
+ String value = "";
|
|
|
+ switch (cellType) {
|
|
|
+ case NUMERIC:
|
|
|
+ value = cell.getNumericCellValue() + "";
|
|
|
+ break;
|
|
|
+ case BLANK:
|
|
|
+ value = StrUtil.EMPTY;
|
|
|
+ break;
|
|
|
+ case ERROR:
|
|
|
+ final FormulaError error = FormulaError.forInt(cell.getErrorCellValue());
|
|
|
+ value = (null == error) ? StrUtil.EMPTY : error.getString();
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ value = cell.getStringCellValue();
|
|
|
+ }
|
|
|
+ return value;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void analyzeActiveCompany(String gxTradeTotalMoney, String preface, String path) {
|
|
|
+ final String nn = "南宁";
|
|
|
+ final String wz = "梧州";
|
|
|
+ final String qz = "钦州";
|
|
|
+ final String bh = "北海";
|
|
|
+ final String px = "凭祥";
|
|
|
+ try (FileInputStream fis = new FileInputStream(path);
|
|
|
+ Workbook workbook = WorkbookFactory.create(fis)) {
|
|
|
+ Sheet sheet = workbook.getSheetAt(0);
|
|
|
+ String year = "";
|
|
|
+ String month = "";
|
|
|
+ ActiveCompaniesDTO activeCompaniesDTO = new ActiveCompaniesDTO();
|
|
|
+ activeCompaniesDTO.setPreface(preface);
|
|
|
+ List<ActiveCompaniesVo> activeCompaniesVoList = new ArrayList<>();
|
|
|
+ StringBuilder sb = new StringBuilder("其中,");
|
|
|
+ for (Row row : sheet) {
|
|
|
+ if (row == null || row.getCell(0) == null) break;
|
|
|
+ String code = StrUtil.subBefore(getValue(row.getCell(0)), ".", true);
|
|
|
+ if (row.getRowNum() == 0) {
|
|
|
+ year = StrUtil.subBetween(code, "保税区", "年");
|
|
|
+ month = StrUtil.subBetween(code, "-", "月");
|
|
|
+ ActiveCompaniesVo activeCompaniesVo = new ActiveCompaniesVo();
|
|
|
+ activeCompaniesVo.setStaticsYear((Integer.parseInt(year) - 1) + "").setStaticsMonth(Integer.valueOf(month) + "");
|
|
|
+ activeCompaniesVoList = activeCompaniesService.queryAll(activeCompaniesVo);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (row.getRowNum() > 1 && StrUtil.isNotEmpty(code)) {
|
|
|
+ String name = getValue(row.getCell(1));
|
|
|
+ int activeCompanies = (int) row.getCell(2).getNumericCellValue();
|
|
|
+ sb.append(name + activeCompanies).append("家");
|
|
|
+ if (StrUtil.contains(name, nn)) {
|
|
|
+ activeCompaniesDTO.setNNActiveCompany(activeCompanies + "");
|
|
|
+ activeCompaniesVoList.stream().filter(activeCompaniesVo -> StrUtil.equals(activeCompaniesVo.getCode(), code))
|
|
|
+ .findFirst().ifPresent(activeCompaniesVo -> {
|
|
|
+ int act = Integer.parseInt(activeCompaniesVo.getNumber());
|
|
|
+ double inc = NumberUtil.mul(NumberUtil.div(activeCompanies - act, act, 3, RoundingMode.HALF_UP), 100);
|
|
|
+ String desc = inc > 0 ? "增长" : "下降";
|
|
|
+ sb.append(",同比").append(desc).append(Math.abs(inc)+"%").append(",");
|
|
|
+ activeCompaniesDTO.setNNActiveCompanyInc(inc + "%");
|
|
|
+ });
|
|
|
+ } else if (StrUtil.contains(name, wz)) {
|
|
|
+ activeCompaniesDTO.setWZActiveCompany(activeCompanies + "");
|
|
|
+
|
|
|
+ activeCompaniesVoList.stream().filter(activeCompaniesVo -> StrUtil.equals(activeCompaniesVo.getCode(), code))
|
|
|
+ .findFirst().ifPresent(activeCompaniesVo -> {
|
|
|
+ int act = Integer.parseInt(activeCompaniesVo.getNumber());
|
|
|
+ double inc = NumberUtil.mul(NumberUtil.div(activeCompanies - act, act, 3, RoundingMode.HALF_UP), 100);
|
|
|
+ activeCompaniesDTO.setWZActiveCompanyInc(inc + "%");
|
|
|
+ String desc = inc > 0 ? "增长" : "下降";
|
|
|
+ sb.append(",同比").append(desc).append(Math.abs(inc)+"%").append("。");
|
|
|
+ });
|
|
|
+ } else if (StrUtil.contains(name, bh)) {
|
|
|
+
|
|
|
+ activeCompaniesDTO.setBHActiveCompany(activeCompanies + "");
|
|
|
+ activeCompaniesVoList.stream().filter(activeCompaniesVo -> StrUtil.equals(activeCompaniesVo.getCode(), code))
|
|
|
+ .findFirst().ifPresent(activeCompaniesVo -> {
|
|
|
+ int act = Integer.parseInt(activeCompaniesVo.getNumber());
|
|
|
+ double inc = NumberUtil.mul(NumberUtil.div(activeCompanies - act, act, 3, RoundingMode.HALF_UP), 100);
|
|
|
+ activeCompaniesDTO.setBHActiveCompanyInc(inc + "%");
|
|
|
+ String desc = inc > 0 ? "增长" : "下降";
|
|
|
+ sb.append(",同比").append(desc).append(Math.abs(inc)+"%").append(",");
|
|
|
+ });
|
|
|
+ } else if (StrUtil.contains(name, qz)) {
|
|
|
+ activeCompaniesDTO.setQZActiveCompany(activeCompanies + "");
|
|
|
+ activeCompaniesVoList.stream().filter(activeCompaniesVo -> StrUtil.equals(activeCompaniesVo.getCode(), code))
|
|
|
+ .findFirst().ifPresent(activeCompaniesVo -> {
|
|
|
+ int act = Integer.parseInt(activeCompaniesVo.getNumber());
|
|
|
+ double inc = NumberUtil.mul(NumberUtil.div(activeCompanies - act, act, 3, RoundingMode.HALF_UP), 100);
|
|
|
+ activeCompaniesDTO.setQZActiveCompanyInc(inc + "%");
|
|
|
+ String desc = inc > 0 ? "增长" : "下降";
|
|
|
+ sb.append(",同比").append(desc).append(Math.abs(inc)+"%").append(",");
|
|
|
+ });
|
|
|
+ } else if (StrUtil.contains(name, px)) {
|
|
|
+ activeCompaniesDTO.setPXActiveCompany(activeCompanies + "");
|
|
|
+ activeCompaniesVoList.stream().filter(activeCompaniesVo -> StrUtil.equals(activeCompaniesVo.getCode(), code))
|
|
|
+ .findFirst().ifPresent(activeCompaniesVo -> {
|
|
|
+ int act = Integer.parseInt(activeCompaniesVo.getNumber());
|
|
|
+ double inc = NumberUtil.mul(NumberUtil.div(activeCompanies - act, act, 3, RoundingMode.HALF_UP), 100);
|
|
|
+ activeCompaniesDTO.setPXActiveCompanyInc(inc + "%");
|
|
|
+ String desc = inc > 0 ? "增长" : "下降";
|
|
|
+ sb.append(",同比").append(desc).append(Math.abs(inc)+"%").append(",");
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ activeCompaniesDTO.setYear(year).setMonth(month);
|
|
|
+ BigDecimal NNActiveCompany = new BigDecimal(activeCompaniesDTO.getNNActiveCompany());
|
|
|
+ BigDecimal WZActiveCompany = new BigDecimal(activeCompaniesDTO.getWZActiveCompany());
|
|
|
+ BigDecimal BHActiveCompany = new BigDecimal(activeCompaniesDTO.getBHActiveCompany());
|
|
|
+ BigDecimal PXActiveCompany = new BigDecimal(activeCompaniesDTO.getPXActiveCompany());
|
|
|
+ BigDecimal QZActiveCompany = new BigDecimal(activeCompaniesDTO.getQZActiveCompany());
|
|
|
+ BigDecimal totalCompany = NNActiveCompany.add(WZActiveCompany).add(BHActiveCompany).add(PXActiveCompany).add(QZActiveCompany);
|
|
|
+ activeCompaniesDTO.setTotalActiveCompany(totalCompany.toString()).setActiveCompaniesDesc(sb.toString());
|
|
|
+ long beforeSum = activeCompaniesVoList.stream().collect(Collectors.summarizingInt(act -> Integer.parseInt(act.getNumber()))).getSum();
|
|
|
+ double totalInc = NumberUtil.mul(NumberUtil.div(totalCompany.longValue() - beforeSum, beforeSum, 4, RoundingMode.UP), 100);
|
|
|
+ String totalActiveCompanyDesc=totalInc>0? "增长" : "下降";
|
|
|
+ activeCompaniesDTO.setTotalActiveCompanyInc(Math.abs(totalInc) + "%").setTotalActiveCompanyDesc(totalActiveCompanyDesc);
|
|
|
+ String totalActiveCompanyPercent = totalCompany.divide(new BigDecimal(220), 3, RoundingMode.HALF_UP).multiply(new BigDecimal(100)).doubleValue()+"%";
|
|
|
+ activeCompaniesDTO.setTotalActiveCompanyPercent(totalActiveCompanyPercent);
|
|
|
+ ReportRecord reportRecord = createReport(year, month);
|
|
|
+ createWord(activeCompaniesDTO, reportRecord);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ throw new RuntimeException("活跃企业家excel解析异常");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ReportRecord findByYearAndMonth(String year, String month) {
|
|
|
+ QueryWrapper<ReportRecord> ew = new QueryWrapper<>();
|
|
|
+ ew.lambda().eq(ReportRecord::getReportYear, year)
|
|
|
+ .eq(ReportRecord::getReportMonth, month);
|
|
|
+ List<ReportRecord> list = list(ew);
|
|
|
+ return list.isEmpty() ? null : list.get(0);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成word文档
|
|
|
+ *
|
|
|
+ * @param reportDTO
|
|
|
+ */
|
|
|
+ public void createWord(ReportDTO reportDTO, ReportRecord reportRecord) {
|
|
|
+ // 上传文件路径
|
|
|
+ String filePath = ZhbsqConfig.getWordPath();
|
|
|
+ File file = new File(filePath);
|
|
|
+ if (!file.exists()) {
|
|
|
+ file.mkdirs();
|
|
|
+ }
|
|
|
+ String year = reportDTO.getYear();
|
|
|
+ String month = reportDTO.getMonth();
|
|
|
+ ReportTemplate reportTemplate = reportTemplateService.findActive();
|
|
|
+ String templatePath = ZhbsqConfig.getTemplatePath() + reportTemplate.getFilename().replace("/profile/template", "");
|
|
|
+ ReportRecord db = reportRecordService.findByYearAndMonth(year, month);
|
|
|
+ if (db != null) {
|
|
|
+ ReportWord reportWord = reportWordService.findTheNewWord(reportRecord.getId());
|
|
|
+ if (reportWord != null) {
|
|
|
+ templatePath = ZhbsqConfig.getWordPath() + reportWord.getWordPath().replace("/profile/word", "");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Field[] fields = ReflectUtil.getFields(reportDTO.getClass());
|
|
|
+ try (FileInputStream fileInputStream = new FileInputStream(templatePath)) {
|
|
|
+ XWPFDocument document = new XWPFDocument(fileInputStream);
|
|
|
+ List<XWPFParagraph> paragraphs = document.getParagraphs();
|
|
|
+ paragraphs.forEach(paragraph -> {
|
|
|
+ List<XWPFRun> runs = paragraph.getRuns();
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ for (XWPFRun r : runs) {
|
|
|
+ sb.append(r.getText(0));
|
|
|
+ }
|
|
|
+
|
|
|
+ String text = sb.toString();
|
|
|
+ for (Field field : fields) {
|
|
|
+ String fieldName = field.getName();
|
|
|
+ if (text.contains("${" + fieldName + "}")) {
|
|
|
+ Object fieldValue = ReflectUtil.getFieldValue(reportDTO, fieldName);
|
|
|
+ if (fieldValue != null && StrUtil.isNotEmpty(fieldValue.toString())) {
|
|
|
+ text = StrUtil.replace(text, "${" + fieldName + "}", fieldValue.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (StrUtil.isNotEmpty(text)) {
|
|
|
+ // 清除所有的runs
|
|
|
+ for (int i = runs.size() - 1; i >= 0; i--) {
|
|
|
+ paragraph.removeRun(i);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 添加新的run
|
|
|
+ XWPFRun newRun = paragraph.createRun();
|
|
|
+ newRun.setText(text);
|
|
|
+ if (text.contains("广西综合保税区经济运行分析") || text.contains("月经济运行指标情况")) {
|
|
|
+ newRun.setFontSize(22);
|
|
|
+ newRun.setFontFamily("方正小标宋_GBK");
|
|
|
+ } else if (text.contains("(一)")) {
|
|
|
+ newRun.setFontSize(16);
|
|
|
+ newRun.setFontFamily("方正仿宋_GBK");
|
|
|
+ } else {
|
|
|
+ newRun.setFontSize(16);
|
|
|
+ newRun.setFontFamily("方正仿宋_GBK");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ List<XWPFTable> tables = document.getTables();
|
|
|
+ for (XWPFTable table : tables) {
|
|
|
+ List<XWPFTableRow> rows = table.getRows();
|
|
|
+ for (XWPFTableRow row : rows) {
|
|
|
+ for (XWPFTableCell cell : row.getTableCells()) {
|
|
|
+ String text = cell.getText();
|
|
|
+ for (Field field : fields) {
|
|
|
+ String fieldName = field.getName();
|
|
|
+ if (text.contains("${" + fieldName + "}")) {
|
|
|
+ Object fieldValue = ReflectUtil.getFieldValue(reportDTO, fieldName);
|
|
|
+ if (fieldValue != null && StrUtil.isNotEmpty(fieldValue.toString())) {
|
|
|
+ // 清空单元格
|
|
|
+ cell.removeParagraph(0);
|
|
|
+ XWPFParagraph newPara = cell.addParagraph();
|
|
|
+ //居中
|
|
|
+ newPara.setAlignment(ParagraphAlignment.CENTER);
|
|
|
+ XWPFRun run = newPara.createRun();
|
|
|
+ if (text.contains("tradeTotalMoney")) {
|
|
|
+ run.setBold(true);
|
|
|
+ }
|
|
|
+ text = StrUtil.replace(text, "${" + fieldName + "}", fieldValue.toString());
|
|
|
+ run.setText(text);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ fileInputStream.close();
|
|
|
+ String filename = reportDTO.getYear() + "年-" + reportDTO.getMonth() + "月分析报告-" + System.currentTimeMillis() + ".docx";
|
|
|
+ FileOutputStream out = new FileOutputStream(filePath + File.separator + filename);
|
|
|
+ document.write(out);
|
|
|
+ out.close();
|
|
|
+ document.close();
|
|
|
+ ReportWord reportWord = new ReportWord();
|
|
|
+ reportWord.setWordName(filename).setWordPath("/profile/word/" + filename).setRecordId(reportRecord.getId());
|
|
|
+ reportWordService.save(reportWord);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|