Browse Source

兼容多个表格一次性导入解析

qzy 9 months ago
parent
commit
275e660fc3
30 changed files with 1267 additions and 217 deletions
  1. 8 1
      pom.xml
  2. 8 7
      zhbsq-admin/src/main/java/com/hjy/ZhbsqApplication.java
  3. 90 0
      zhbsq-admin/src/main/java/com/hjy/modlue/activecompanies/ActiveCompaniesController.java
  4. 14 1
      zhbsq-admin/src/main/java/com/hjy/modlue/report/ReportRecordController.java
  5. 2 7
      zhbsq-admin/src/main/java/com/hjy/modlue/report/ReportTemplateController.java
  6. 0 2
      zhbsq-admin/src/main/java/com/hjy/modlue/report/ReportWordController.java
  7. 3 5
      zhbsq-admin/src/main/java/com/hjy/modlue/template/controller/GenerateTemplateController.java
  8. 4 1
      zhbsq-common/pom.xml
  9. 0 8
      zhbsq-common/src/main/java/com/hjy/common/config/ZhbsqConfig.java
  10. 11 2
      zhbsq-common/src/main/java/com/hjy/common/utils/StringUtils.java
  11. 6 0
      zhbsq-common/src/main/java/com/hjy/common/utils/file/FileUtils.java
  12. 62 0
      zhbsq-modlue/src/main/java/com/hjy/module/domain/activecompanies/ActiveCompanies.java
  13. 28 0
      zhbsq-modlue/src/main/java/com/hjy/module/domain/report/ActiveCompaniesDTO.java
  14. 31 0
      zhbsq-modlue/src/main/java/com/hjy/module/domain/report/ActiveReportDTO.java
  15. 6 2
      zhbsq-modlue/src/main/java/com/hjy/module/domain/report/ReportDTO.java
  16. 160 0
      zhbsq-modlue/src/main/java/com/hjy/module/domain/report/TradeTypeReportDTO.java
  17. 26 0
      zhbsq-modlue/src/main/java/com/hjy/module/mapper/activecompanies/ActiveCompaniesMapper.java
  18. 45 0
      zhbsq-modlue/src/main/java/com/hjy/module/service/activecompanies/IActiveCompaniesService.java
  19. 40 0
      zhbsq-modlue/src/main/java/com/hjy/module/service/activecompanies/impl/ActiveCompaniesServiceImpl.java
  20. 10 0
      zhbsq-modlue/src/main/java/com/hjy/module/service/report/IReportRecordService.java
  21. 2 0
      zhbsq-modlue/src/main/java/com/hjy/module/service/report/IReportTemplateService.java
  22. 3 0
      zhbsq-modlue/src/main/java/com/hjy/module/service/report/IReportWordService.java
  23. 498 11
      zhbsq-modlue/src/main/java/com/hjy/module/service/report/impl/ReportRecordServiceImpl.java
  24. 36 0
      zhbsq-modlue/src/main/java/com/hjy/module/service/report/impl/ReportTemplateServiceImpl.java
  25. 10 0
      zhbsq-modlue/src/main/java/com/hjy/module/service/report/impl/ReportWordServiceImpl.java
  26. 5 1
      zhbsq-modlue/src/main/java/com/hjy/module/service/template/IExcelOutInTotalService.java
  27. 81 169
      zhbsq-modlue/src/main/java/com/hjy/module/service/template/impl/ExcelOutInTotalServiceImpl.java
  28. 21 0
      zhbsq-modlue/src/main/java/com/hjy/module/vo/activecompanies/ActiveCompaniesVo.java
  29. 4 0
      zhbsq-modlue/src/main/java/com/hjy/module/vo/report/ReportRecordVo.java
  30. 53 0
      zhbsq-modlue/src/main/resources/mapper/activecompanies/ActiveCompaniesMapper.xml

+ 8 - 1
pom.xml

@@ -23,6 +23,9 @@
         <kaptcha.version>2.3.2</kaptcha.version>
         <lombok.version>1.18.20</lombok.version>
         <hutool.version>5.7.2</hutool.version>
+        <ccompress.version>1.26.0</ccompress.version>
+
+
         <mybatis-plus-spring-boot.version>3.4.2</mybatis-plus-spring-boot.version>
         <pagehelper.boot.version>1.4.3</pagehelper.boot.version>
         <fastjson.version>2.0.12</fastjson.version>
@@ -175,7 +178,11 @@
                 <artifactId>hutool-all</artifactId>
                 <version>${hutool.version}</version>
             </dependency>
-
+            <dependency>
+                <groupId>org.apache.commons</groupId>
+                <artifactId>commons-compress</artifactId>
+                <version>${ccompress.version}</version>
+            </dependency>
             <!-- 公众号(包括订阅号和服务号) -->
             <dependency>
                 <groupId>com.github.binarywang</groupId>

+ 8 - 7
zhbsq-admin/src/main/java/com/hjy/ZhbsqApplication.java

@@ -3,9 +3,12 @@ package com.hjy;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
+import org.springframework.boot.context.ApplicationPidFileWriter;
 import org.springframework.context.ConfigurableApplicationContext;
 
+import java.io.File;
 import java.net.UnknownHostException;
+import java.util.Properties;
 
 /**
  * 启动程序
@@ -15,12 +18,10 @@ import java.net.UnknownHostException;
 @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
 public class ZhbsqApplication {
     public static void main(String[] args) throws UnknownHostException {
-        ConfigurableApplicationContext application = SpringApplication.run(ZhbsqApplication.class, args);
-        System.out.println("(♥◠‿◠)ノ゙后台项目启动成功   ლ(´ڡ`ლ)゙ ");
-//        Environment env = application.getEnvironment();
-//        String ip = InetAddress.getLocalHost().getHostAddress();
-//        String port = env.getProperty("server.port");
-//        String path = env.getProperty("server.servlet.context-path");
-//        System.out.println("Swagger文档: \thttp://" + ip + ":" + port + path + "/doc.html\n");
+        Properties properties = System.getProperties();
+        String rootPath = properties.getProperty("user.dir");
+        SpringApplication application = new SpringApplication(ZhbsqApplication.class);
+        application.addListeners(new ApplicationPidFileWriter(rootPath + File.separator + "app.pid"));
+        application.run(args);
     }
 }

+ 90 - 0
zhbsq-admin/src/main/java/com/hjy/modlue/activecompanies/ActiveCompaniesController.java

@@ -0,0 +1,90 @@
+package com.hjy.modlue.activecompanies;
+
+import com.hjy.common.annotation.Log;
+import com.hjy.common.core.controller.BaseController;
+import com.hjy.common.core.domain.AjaxResult;
+import com.hjy.common.enums.BusinessType;
+import com.hjy.common.utils.poi.ExcelUtil;
+
+import com.hjy.module.service.activecompanies.IActiveCompaniesService;
+import com.hjy.module.vo.activecompanies.ActiveCompaniesVo;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.RequiredArgsConstructor;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.web.bind.annotation.*;
+import com.hjy.common.core.page.TableDataInfo;
+
+import javax.servlet.http.HttpServletResponse;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * 历年活跃企业数Controller
+ *
+ * @author Tellsea
+ * @date 2024-05-28
+ */
+@Api(tags = "历年活跃企业数Controller")
+@RestController
+@RequestMapping("/business/ACTIVECOMPANIES")
+@RequiredArgsConstructor(onConstructor_ = @Autowired)
+public class ActiveCompaniesController extends BaseController {
+
+    private final IActiveCompaniesService activeCompaniesService;
+
+    @ApiOperation("查询历年活跃企业数列表")
+    @PreAuthorize("@ss.hasPermi('business:ACTIVECOMPANIES:list')")
+    @GetMapping("/list")
+    public TableDataInfo<ActiveCompaniesVo> list(ActiveCompaniesVo entity) {
+        return activeCompaniesService.queryList(entity);
+    }
+
+    @ApiOperation("查询历年活跃企业数所有列表")
+    @GetMapping("/listAll")
+    public AjaxResult listAll(ActiveCompaniesVo entity) {
+        return AjaxResult.success("查询成功", activeCompaniesService.queryAll(entity));
+    }
+
+    @ApiOperation("导出历年活跃企业数列表")
+    @PreAuthorize("@ss.hasPermi('business:ACTIVECOMPANIES:export')")
+    @Log(title = "历年活跃企业数", businessType = BusinessType.EXPORT)
+    @PostMapping("/export")
+    public void export(HttpServletResponse response, ActiveCompaniesVo entity) {
+        List<ActiveCompaniesVo> list = activeCompaniesService.queryAll(entity);
+        ExcelUtil<ActiveCompaniesVo> util = new ExcelUtil<>(ActiveCompaniesVo.class);
+        util.exportExcel(response, list, "历年活跃企业数数据");
+    }
+
+    @ApiOperation("获取历年活跃企业数详细信息")
+    @PreAuthorize("@ss.hasPermi('business:ACTIVECOMPANIES:query')")
+    @GetMapping(value = "/getInfo/{id}")
+    public AjaxResult getInfo(@PathVariable("id") String id) {
+        return AjaxResult.success("查询成功", activeCompaniesService.queryById(id));
+    }
+
+    @ApiOperation("新增历年活跃企业数")
+    @PreAuthorize("@ss.hasPermi('business:ACTIVECOMPANIES:add')")
+    @Log(title = "历年活跃企业数", businessType = BusinessType.INSERT)
+    @PostMapping("add")
+    public AjaxResult add(@RequestBody ActiveCompaniesVo entity) {
+        return toAjax(activeCompaniesService.save(entity));
+    }
+
+    @ApiOperation("修改历年活跃企业数")
+    @PreAuthorize("@ss.hasPermi('business:ACTIVECOMPANIES:edit')")
+    @Log(title = "历年活跃企业数", businessType = BusinessType.UPDATE)
+    @PostMapping("edit")
+    public AjaxResult edit(@RequestBody ActiveCompaniesVo entity) {
+        return toAjax(activeCompaniesService.updateById(entity));
+    }
+
+    @ApiOperation("删除历年活跃企业数")
+    @PreAuthorize("@ss.hasPermi('business:ACTIVECOMPANIES:remove')")
+    @Log(title = "历年活跃企业数", businessType = BusinessType.DELETE)
+	@GetMapping("/remove/{ids}")
+    public AjaxResult remove(@PathVariable String[] ids) {
+        return toAjax(activeCompaniesService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
+    }
+}

+ 14 - 1
zhbsq-admin/src/main/java/com/hjy/modlue/report/ReportRecordController.java

@@ -1,5 +1,6 @@
 package com.hjy.modlue.report;
 
+import cn.hutool.core.util.StrUtil;
 import com.hjy.common.annotation.Log;
 import com.hjy.common.core.controller.BaseController;
 import com.hjy.common.core.domain.AjaxResult;
@@ -74,8 +75,13 @@ public class ReportRecordController extends BaseController {
     @PreAuthorize("@ss.hasPermi('report:RECORD:add')")
     @Log(title = "辅助决策", businessType = BusinessType.INSERT)
     @PostMapping("add")
+    @Transactional(rollbackFor = Exception.class)
     public AjaxResult add(@RequestBody ReportRecordVo entity) {
-        return toAjax(reportRecordService.save(entity));
+        String paths=entity.getPaths();
+        if (StrUtil.isEmpty(paths)){
+            return AjaxResult.error("请上传原数据");
+        }
+        return toAjax(reportRecordService.saveForm(entity));
     }
 
     @ApiOperation("修改辅助决策")
@@ -105,4 +111,11 @@ public class ReportRecordController extends BaseController {
         }
         return toAjax(reportRecordService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
     }
+
+    @ApiOperation("导入excel、支持批量")
+    @PreAuthorize("@ss.hasPermi('business:template:import')")
+    @PostMapping("/importExcel")
+    public AjaxResult importExcelBatch(@RequestParam(value = "file")MultipartFile file )throws Exception{
+        return AjaxResult.success("导入成功", reportRecordService.importExcel(file));
+    }
 }

+ 2 - 7
zhbsq-admin/src/main/java/com/hjy/modlue/report/ReportTemplateController.java

@@ -48,12 +48,7 @@ public class ReportTemplateController extends BaseController {
     @PreAuthorize("@ss.hasPermi('report:TEMPLATE:list')")
     @GetMapping("/list")
     public TableDataInfo<ReportTemplateVo> list(ReportTemplateVo entity) {
-        String url=serverConfig.getUrl();
-        TableDataInfo<ReportTemplateVo> reportTemplateVoTableDataInfo = reportTemplateService.queryList(entity);
-        reportTemplateVoTableDataInfo.getRows().forEach(vo ->{
-            vo.setTemplatePath(url + vo.getFilename());
-        });
-        return reportTemplateVoTableDataInfo;
+        return reportTemplateService.queryList(entity);
     }
 
     @ApiOperation("查询模板管理所有列表")
@@ -132,7 +127,7 @@ public class ReportTemplateController extends BaseController {
             fileName = "/profile/template/" + fileName;
         } catch (IOException e) {
             e.printStackTrace();
-            return AjaxResult.error("导入成功");
+            return AjaxResult.error("导入失败");
         }
         return AjaxResult.success("导入成功", fileName);
     }

+ 0 - 2
zhbsq-admin/src/main/java/com/hjy/modlue/report/ReportWordController.java

@@ -47,8 +47,6 @@ public class ReportWordController extends BaseController {
     @GetMapping("/listAll")
     public AjaxResult listAll(ReportWordVo entity) {
         List<ReportWordVo>list= reportWordService.queryAll(entity);
-        String url=serverConfig.getUrl();
-        list.forEach(word->word.setWordPath(url+word.getWordPath()));
         return AjaxResult.success("查询成功",list);
     }
 

+ 3 - 5
zhbsq-admin/src/main/java/com/hjy/modlue/template/controller/GenerateTemplateController.java

@@ -11,10 +11,7 @@ import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.util.List;
@@ -58,8 +55,9 @@ public class GenerateTemplateController extends BaseController {
         if(voList.size() != 1) {
             return AjaxResult.error("没有启用模版或者启用了多个模版,请检查模版管理菜单");
         }
-        excelOutInTotalService.analyze(file,gxTradeTotalMoney,voList.get(0).getFilename());
+        excelOutInTotalService.analyze(file,gxTradeTotalMoney);
         return AjaxResult.success("导入成功");
     }
 
+
 }

+ 4 - 1
zhbsq-common/pom.xml

@@ -166,7 +166,10 @@
             <groupId>cn.hutool</groupId>
             <artifactId>hutool-all</artifactId>
         </dependency>
-
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-compress</artifactId>
+        </dependency>
         <dependency>
             <groupId>org.projectlombok</groupId>
             <artifactId>lombok</artifactId>

+ 0 - 8
zhbsq-common/src/main/java/com/hjy/common/config/ZhbsqConfig.java

@@ -39,15 +39,7 @@ public class ZhbsqConfig {
      * 实例演示开关
      */
     private boolean demoEnabled;
-    private String reportPath;
 
-    public String getReportPath() {
-        return reportPath;
-    }
-
-    public void setReportPath(String reportPath) {
-        this.reportPath = reportPath;
-    }
 
     public static String getProfile() {
         return profile;

+ 11 - 2
zhbsq-common/src/main/java/com/hjy/common/utils/StringUtils.java

@@ -1,5 +1,6 @@
 package com.hjy.common.utils;
 
+import cn.hutool.core.util.StrUtil;
 import com.hjy.common.constant.Constants;
 import com.hjy.common.core.text.Convert;
 import com.hjy.common.core.text.StrFormatter;
@@ -7,6 +8,7 @@ import org.jsoup.Jsoup;
 import org.jsoup.nodes.Document;
 import org.springframework.util.AntPathMatcher;
 
+import java.math.BigDecimal;
 import java.util.*;
 
 /**
@@ -537,7 +539,14 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
         return document.body().children().toString();
     }
 
-    public static void main(String[] args) {
-        System.out.println(appendStr("1"));
+    public static BigDecimal strToBigDecimal(String str){
+        str=StrUtil.replace(str,"%","");
+        if (StrUtil.isEmpty(str)||StrUtil.contains(str,"-")) {
+            return new BigDecimal("0");
+        }
+        return new BigDecimal(str);
     }
+
+
+
 }

+ 6 - 0
zhbsq-common/src/main/java/com/hjy/common/utils/file/FileUtils.java

@@ -15,6 +15,10 @@ import javax.servlet.http.HttpServletResponse;
 import java.io.*;
 import java.net.URLEncoder;
 import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 /**
  * 文件处理工具类
@@ -25,6 +29,8 @@ import java.nio.charset.StandardCharsets;
 public class FileUtils {
     public static String FILENAME_PATTERN = "[a-zA-Z0-9_\\-\\|\\.\\u4e00-\\u9fa5]+";
 
+    public static final List<String>COMPRESSLIST = Stream.of("zip","rar").collect(Collectors.toList());
+
     /**
      * 输出指定文件的byte数组
      *

+ 62 - 0
zhbsq-modlue/src/main/java/com/hjy/module/domain/activecompanies/ActiveCompanies.java

@@ -0,0 +1,62 @@
+package com.hjy.module.domain.activecompanies;
+
+import com.hjy.common.annotation.Excel;
+
+import com.hjy.common.core.domain.BaseEntity;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.ToString;
+import lombok.experimental.Accessors;
+
+/**
+ * 历年活跃企业数对象 CB_ACTIVE_COMPANIES
+ *
+ * @author Tellsea
+ * @date 2024-05-28
+ */
+@Data
+@Accessors(chain = true)
+@ToString(callSuper = true)
+@EqualsAndHashCode(callSuper = true)
+public class ActiveCompanies extends BaseEntity {
+
+    /**
+     * 主键
+     */
+    @Excel(name = "主键")
+    private String id;
+
+    /**
+     * 编号
+     */
+    @Excel(name = "编号")
+    private String code;
+
+    /**
+     * 名称
+     */
+    @Excel(name = "名称")
+    private String name;
+
+    /**
+     * 活跃数
+     */
+    @Excel(name = "活跃数")
+    private String number;
+
+    /**
+     * 年份
+     */
+    @Excel(name = "年份")
+    private String staticsYear;
+
+    /**
+     * 月份
+     */
+    @Excel(name = "月份")
+    private String staticsMonth;
+
+    @Excel(name = "同比增长")
+    private String inc;
+
+}

+ 28 - 0
zhbsq-modlue/src/main/java/com/hjy/module/domain/report/ActiveCompaniesDTO.java

@@ -0,0 +1,28 @@
+package com.hjy.module.domain.report;
+
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+import java.io.Serializable;
+@Data
+@Accessors(chain = true)
+public class ActiveCompaniesDTO extends ReportDTO implements Serializable {
+    private static final long serialVersionUID = 1L;
+    private String NNActiveCompany;
+    private String WZActiveCompany;
+    private String BHActiveCompany;
+    private String PXActiveCompany;
+    private String QZActiveCompany;
+
+    private String totalActiveCompany;
+    private String totalActiveCompanyInc;
+
+    private String NNActiveCompanyInc="-";
+    private String WZActiveCompanyInc="-";
+    private String BHActiveCompanyInc="-";
+    private String PXActiveCompanyInc="-";
+    private String QZActiveCompanyInc="-";
+    private String totalActiveCompanyPercent;
+    private String totalActiveCompanyDesc;
+    private String activeCompaniesDesc;
+}

+ 31 - 0
zhbsq-modlue/src/main/java/com/hjy/module/domain/report/ActiveReportDTO.java

@@ -0,0 +1,31 @@
+package com.hjy.module.domain.report;
+
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+import java.io.Serializable;
+
+
+
+@Data
+@Accessors(chain = true)
+public class ActiveReportDTO extends ReportDTO implements Serializable {
+    private static final long serialVersionUID =1L;
+    private String totalActiveCompany;
+    private String totalActiveCompanyInc;
+
+
+    private String NNActiveCompany;
+    private String NNActiveCompanyInc;
+
+
+
+    private String BHActiveCompany;
+    private String BHActiveCompanyInc;
+
+    private String QZActiveCompany;
+    private String QZActiveCompanyInc;
+
+    private String PXActiveCompany;
+    private String PXActiveCompanyInc;
+}

+ 6 - 2
zhbsq-modlue/src/main/java/com/hjy/module/domain/report/ReportDTO.java

@@ -4,6 +4,7 @@ import lombok.Data;
 import lombok.experimental.Accessors;
 
 import java.io.Serializable;
+
 @Data
 @Accessors(chain = true)
 public class ReportDTO implements Serializable {
@@ -29,7 +30,7 @@ public class ReportDTO implements Serializable {
      */
     private String tradeTotalMoney;
     /**
-     *占全区进出口总值百分比
+     * 占全区进出口总值百分比
      */
     private String tradeTotalMoneyPercent;
     /**
@@ -41,7 +42,6 @@ public class ReportDTO implements Serializable {
      */
     private String tradeTotalMoneyInc;
     /**
-     *
      * 整体状况
      */
     private String tradeSituation;
@@ -119,4 +119,8 @@ public class ReportDTO implements Serializable {
      */
     private String tradeTotalMoneyIndexDesc;
 
+
+
+
+
 }

+ 160 - 0
zhbsq-modlue/src/main/java/com/hjy/module/domain/report/TradeTypeReportDTO.java

@@ -0,0 +1,160 @@
+package com.hjy.module.domain.report;
+
+import com.hjy.common.utils.StringUtils;
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+
+@Data
+@Accessors(chain = true)
+public class TradeTypeReportDTO extends ReportDTO implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * -------------------------------综保区业务进出口总值---------------------------------
+     */
+
+    /**
+     * 全区合计(加工贸易+保税物流)
+     */
+    private String tradeTypeAllTotal;
+    /**
+     * 全区合计(加工贸易+保税物流)同比
+     */
+    private String tradeTypeAllTotalInc;
+    /**
+     * 南宁
+     */
+    private String tradeTypeNNTotal;
+    private String tradeTypeNNTotalInc;
+
+    /**
+     * 梧州
+     */
+    private String tradeTypeWZTotal;
+    private String tradeTypeWZTotalInc;
+
+    /**
+     * 北海
+     */
+    private String tradeTypeBHTotal;
+    private String tradeTypeBHTotalInc;
+
+    /**
+     * 钦州
+     */
+    private String tradeTypeQZTotal;
+    private String tradeTypeQZTotalInc;
+
+
+    /**
+     * 凭祥
+     */
+    private String tradeTypePXTotal;
+    private String tradeTypePXTotalInc;
+
+    /**
+     * -------------------------------加工贸易--------------------------------
+     */
+
+    /**
+     * 全区合计(加工贸易+保税物流)
+     */
+    private String tradeJGAllTotal;
+    /**
+     * 全区合计(加工贸易+保税物流)同比
+     */
+    private String tradeJGAllTotalInc;
+    /**
+     * 南宁
+     */
+    private String tradeJGNNTotal;
+    private String tradeJGNNTotalInc;
+
+    /**
+     * 梧州
+     */
+    private String tradeJGWZTotal="-";
+    private String tradeJGWZTotalInc="-";
+
+    /**
+     * 北海
+     */
+    private String tradeJGBHTotal;
+    private String tradeJGBHTotalInc;
+
+    /**
+     * 钦州
+     */
+    private String tradeJGQZTotal;
+    private String tradeJGQZTotalInc;
+
+
+    /**
+     * 凭祥
+     */
+    private String tradeJGPXTotal;
+    private String tradeJGPXTotalInc;
+
+    /**
+     * -------------保税物流-------------
+     */
+
+    /**
+     * 全区合计(保税物流)
+     */
+    private String tradeBSAllTotal;
+    /**
+     * 全区合计(保税物流)同比
+     */
+    private String tradeBSAllTotalInc;
+    /**
+     * 南宁
+     */
+    private String tradeBSNNTotal;
+    private String tradeBSNNTotalInc;
+
+    /**
+     * 梧州
+     */
+    private String tradeBSWZTotal;
+    private String tradeBSWZTotalInc;
+
+    /**
+     * 北海
+     */
+    private String tradeBSBHTotal;
+    private String tradeBSBHTotalInc;
+
+    /**
+     * 钦州
+     */
+    private String tradeBSQZTotal;
+    private String tradeBSQZTotalInc;
+
+
+    /**
+     * 凭祥
+     */
+    private String tradeBSPXTotal;
+    private String tradeBSPXTotalInc;
+
+    /**
+     * ------------------------------------保税业务进出口值占所在地外贸进出口总值的比重----------------------------
+     */
+    private String bsTradeAllPercent;
+    private String bsNNTradeAllPercent;
+    private String bsBHTradeAllPercent;
+    private String bsQZTradeAllPercent;
+    private String bsPXTradeAllPercent;
+    private String bsWZTradeAllPercent;
+
+
+
+
+
+
+}

+ 26 - 0
zhbsq-modlue/src/main/java/com/hjy/module/mapper/activecompanies/ActiveCompaniesMapper.java

@@ -0,0 +1,26 @@
+package com.hjy.module.mapper.activecompanies;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+
+import com.hjy.module.domain.activecompanies.ActiveCompanies;
+import com.hjy.module.vo.activecompanies.ActiveCompaniesVo;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * 历年活跃企业数Mapper接口
+ *
+ * @author Tellsea
+ * @date 2024-05-28
+ */
+public interface ActiveCompaniesMapper extends BaseMapper<ActiveCompanies> {
+
+    Page<ActiveCompaniesVo> queryList(Page<?> page, @Param("entity") ActiveCompaniesVo entity);
+
+    List<ActiveCompaniesVo> queryList(@Param("entity") ActiveCompaniesVo entity);
+
+    ActiveCompaniesVo queryById(@Param("id") String id);
+
+}

+ 45 - 0
zhbsq-modlue/src/main/java/com/hjy/module/service/activecompanies/IActiveCompaniesService.java

@@ -0,0 +1,45 @@
+package com.hjy.module.service.activecompanies;
+
+
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.hjy.common.core.page.TableDataInfo;
+import com.hjy.module.domain.activecompanies.ActiveCompanies;
+import com.hjy.module.vo.activecompanies.ActiveCompaniesVo;
+
+import java.util.List;
+
+/**
+ * 历年活跃企业数Service接口
+ *
+ * @author Tellsea
+ * @date 2024-05-28
+ */
+public interface IActiveCompaniesService extends IService<ActiveCompanies> {
+
+    /**
+     * 分页查询
+     *
+     * @param entity
+     * @return
+     */
+    TableDataInfo<ActiveCompaniesVo> queryList(ActiveCompaniesVo entity);
+
+    /**
+     * 查询全部
+     *
+     * @param entity
+     * @return
+     */
+    List<ActiveCompaniesVo> queryAll(ActiveCompaniesVo entity);
+
+    /**
+     * 根据ID查询
+     *
+     * @param id
+     * @return
+     */
+    ActiveCompaniesVo queryById(String id);
+
+
+}

+ 40 - 0
zhbsq-modlue/src/main/java/com/hjy/module/service/activecompanies/impl/ActiveCompaniesServiceImpl.java

@@ -0,0 +1,40 @@
+package com.hjy.module.service.activecompanies.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.hjy.common.core.page.TableDataInfo;
+import com.hjy.common.utils.PageUtils;
+
+import com.hjy.module.domain.activecompanies.ActiveCompanies;
+import com.hjy.module.mapper.activecompanies.ActiveCompaniesMapper;
+import com.hjy.module.service.activecompanies.IActiveCompaniesService;
+import com.hjy.module.vo.activecompanies.ActiveCompaniesVo;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+/**
+ * 历年活跃企业数Service业务层处理
+ *
+ * @author Tellsea
+ * @date 2024-05-28
+ */
+@Service
+public class ActiveCompaniesServiceImpl extends ServiceImpl<ActiveCompaniesMapper, ActiveCompanies> implements IActiveCompaniesService {
+
+    @Override
+    public TableDataInfo<ActiveCompaniesVo> queryList(ActiveCompaniesVo entity) {
+        return PageUtils.buildDataInfo(this.baseMapper.queryList(PageUtils.buildPage(), entity));
+    }
+
+    @Override
+    public List<ActiveCompaniesVo> queryAll(ActiveCompaniesVo entity) {
+        return this.baseMapper.queryList(entity);
+    }
+
+
+
+    @Override
+    public ActiveCompaniesVo queryById(String id) {
+        return this.baseMapper.queryById(id);
+    }
+}

+ 10 - 0
zhbsq-modlue/src/main/java/com/hjy/module/service/report/IReportRecordService.java

@@ -2,6 +2,7 @@ package com.hjy.module.service.report;
 
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.hjy.common.core.page.TableDataInfo;
+import com.hjy.module.domain.report.ReportDTO;
 import com.hjy.module.domain.report.ReportRecord;
 import com.hjy.module.vo.report.ReportRecordVo;
 import org.springframework.web.multipart.MultipartFile;
@@ -44,4 +45,13 @@ public interface IReportRecordService extends IService<ReportRecord> {
     ReportRecord findReport(String year, String month);
 
     boolean upload(MultipartFile file, String id)throws Exception;
+
+
+    String importExcel(MultipartFile file)throws Exception;
+
+    int saveForm(ReportRecordVo entity);
+
+    ReportRecord findByYearAndMonth(String year, String month);
+
+     void createWord(ReportDTO reportDTO, ReportRecord reportRecord);
 }

+ 2 - 0
zhbsq-modlue/src/main/java/com/hjy/module/service/report/IReportTemplateService.java

@@ -40,5 +40,7 @@ public interface IReportTemplateService extends IService<ReportTemplate> {
     ReportTemplateVo queryById(String id);
 
     int queryStatusNum();
+    ReportTemplate findActive();
+    String findWordTemplate(String year,String month);
 
 }

+ 3 - 0
zhbsq-modlue/src/main/java/com/hjy/module/service/report/IReportWordService.java

@@ -41,4 +41,7 @@ public interface IReportWordService extends IService<ReportWord> {
     ReportWordVo queryById(String id);
 
     void removeByReportId(String reportId);
+
+
+    ReportWord findTheNewWord(String recordId);
 }

+ 498 - 11
zhbsq-modlue/src/main/java/com/hjy/module/service/report/impl/ReportRecordServiceImpl.java

@@ -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);
+        }
+    }
 }

+ 36 - 0
zhbsq-modlue/src/main/java/com/hjy/module/service/report/impl/ReportTemplateServiceImpl.java

@@ -1,14 +1,20 @@
 package com.hjy.module.service.report.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.hjy.common.core.page.TableDataInfo;
 import com.hjy.common.utils.PageUtils;
+import com.hjy.module.domain.report.ReportRecord;
 import com.hjy.module.domain.report.ReportTemplate;
+import com.hjy.module.domain.report.ReportWord;
 import com.hjy.module.mapper.report.ReportTemplateMapper;
+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.vo.report.ReportTemplateVo;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.Resource;
 import java.util.List;
 
 /**
@@ -20,6 +26,11 @@ import java.util.List;
 @Service
 public class ReportTemplateServiceImpl extends ServiceImpl<ReportTemplateMapper, ReportTemplate> implements IReportTemplateService {
 
+    @Resource
+    private IReportWordService reportWordService;
+    @Resource
+    private IReportRecordService reportRecordService;
+
     @Override
     public TableDataInfo<ReportTemplateVo> queryList(ReportTemplateVo entity) {
         return PageUtils.buildDataInfo(this.baseMapper.queryList(PageUtils.buildPage(), entity));
@@ -40,4 +51,29 @@ public class ReportTemplateServiceImpl extends ServiceImpl<ReportTemplateMapper,
         return this.baseMapper.queryStatusNum();
     }
 
+    @Override
+    public ReportTemplate findActive() {
+        QueryWrapper<ReportTemplate>ew=new QueryWrapper<>();
+        ew.lambda().eq(ReportTemplate::getStatus,1);
+        List<ReportTemplate>list= list(ew);
+        return list.isEmpty()?null:list.get(0);
+    }
+
+
+    @Override
+    public String findWordTemplate(String year, String month) {
+        ReportRecord reportRecord= reportRecordService.findByYearAndMonth(year,month);
+        if (reportRecord!=null){
+           ReportWord reportWord= reportWordService.findTheNewWord(reportRecord.getId());
+          if (reportWord!=null){
+              return reportWord.getWordPath();
+          }
+        }
+        ReportTemplate reportTemplate=  findActive();
+        if (reportTemplate==null){
+            return "";
+        }
+        return reportTemplate.getFilename();
+    }
+
 }

+ 10 - 0
zhbsq-modlue/src/main/java/com/hjy/module/service/report/impl/ReportWordServiceImpl.java

@@ -2,6 +2,7 @@ package com.hjy.module.service.report.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.hjy.common.core.domain.BaseEntity;
 import com.hjy.common.core.page.TableDataInfo;
 import com.hjy.common.utils.PageUtils;
 
@@ -44,5 +45,14 @@ public class ReportWordServiceImpl extends ServiceImpl<ReportWordMapper, ReportW
         this.baseMapper.delete(ew);
     }
 
+    @Override
+    public ReportWord findTheNewWord(String recordId) {
+        QueryWrapper<ReportWord>ew=new QueryWrapper<>();
+        ew.lambda().eq(ReportWord::getRecordId,recordId)
+                .orderByDesc(BaseEntity::getCreateTime);
+        List<ReportWord>list=list(ew);
+        return list.isEmpty()?null : list.get(0);
+    }
+
 
 }

+ 5 - 1
zhbsq-modlue/src/main/java/com/hjy/module/service/template/IExcelOutInTotalService.java

@@ -2,12 +2,14 @@ package com.hjy.module.service.template;
 
 
 
+import cn.hutool.poi.excel.ExcelReader;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.hjy.common.core.page.TableDataInfo;
 import com.hjy.module.domain.template.ExcelOutInTotal;
 import com.hjy.module.vo.template.ExcelOutInTotalVo;
 import org.springframework.web.multipart.MultipartFile;
 
+import java.io.File;
 import java.util.List;
 
 /**
@@ -42,7 +44,9 @@ public interface IExcelOutInTotalService extends IService<ExcelOutInTotal> {
      */
     ExcelOutInTotalVo queryById(Long id);
 
-    boolean analyze(MultipartFile file,String gxTradeTotalMoney,String templatePath);
+    boolean analyze(MultipartFile file,String gxTradeTotalMoney);
+     boolean analyze(ExcelReader reader, String gxTradeTotalMoney, String preface);
 
     void removeByReportId(String reportId);
+
 }

+ 81 - 169
zhbsq-modlue/src/main/java/com/hjy/module/service/template/impl/ExcelOutInTotalServiceImpl.java

@@ -1,5 +1,6 @@
 package com.hjy.module.service.template.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;
@@ -37,6 +38,7 @@ import java.io.*;
 import java.lang.reflect.Field;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
+import java.nio.file.Paths;
 import java.time.LocalDate;
 import java.util.*;
 import java.util.stream.Collectors;
@@ -57,10 +59,6 @@ public class ExcelOutInTotalServiceImpl extends ServiceImpl<ExcelOutInTotalMappe
     @Resource
     private IReportSettingService reportSettingService;
 
-    @Resource
-    private ZhbsqConfig zhbsqConfig;
-    @Resource
-    private IReportWordService reportWordService;
 
 
 
@@ -80,7 +78,20 @@ public class ExcelOutInTotalServiceImpl extends ServiceImpl<ExcelOutInTotalMappe
     }
 
     @Override
-    public boolean analyze(MultipartFile file,String gxTradeTotalMoney,String templatePath) {
+    public boolean analyze(MultipartFile file, String gxTradeTotalMoney) {
+
+        try (InputStream inputStream = file.getInputStream()) {
+            ExcelReader reader = ExcelUtil.getReader(inputStream);
+            return analyze(reader, gxTradeTotalMoney, "");
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return false;
+    }
+
+
+    @Override
+    public boolean analyze(ExcelReader reader, String gxTradeTotalMoney, String preface) {
         final String nn = "南宁综";
         final String wz = "梧州综";
         final String qz = "钦州综";
@@ -88,73 +99,68 @@ public class ExcelOutInTotalServiceImpl extends ServiceImpl<ExcelOutInTotalMappe
         final String px = "凭祥综";
         BigDecimal tenThousand = BigDecimal.valueOf(10000);
         ReportDTO reportDTO = new ReportDTO();
-        reportDTO.setGxTradeTotalMoney(gxTradeTotalMoney+"");
-        try (InputStream inputStream = file.getInputStream()) {
-            ExcelReader reader = ExcelUtil.getReader(inputStream);
-            String text = reader.readAsText(false);
-            List<String> arrayList = StrUtil.split(StrUtil.trim(StrUtil.replace(text, ",", "")), "\n");
-            String monthStr = arrayList.get(3);
-            List<String> monthList = StrUtil.split(monthStr, "\t");
-            String currentMonth = monthList.get(0);
-            String cumulativeMonth = monthList.get(1);
-            String title = arrayList.get(0);
-            String time = StrUtil.subBefore(StrUtil.subAfter(title, "20", true), "特定地区进出口总值", true);
-            String year = "20" + StrUtil.subBefore(time, "年", true);
-            String month = StrUtil.subBetween(time, "年", "月");
-            reportDTO.setYear(year).setMonth(month);
-            ReportRecord reportRecord = reportRecordService.findReport(year, month);
-            if (reportRecord == null) {
-                reportRecord = new ReportRecord();
-                reportRecord.setReportYear(year)
-                        .setReportMonth(month);
-                reportRecordService.save(reportRecord);
-            }
-            String reportId = reportRecord.getId();
-            this.removeByReportId(reportId);
+        reportDTO.setGxTradeTotalMoney(gxTradeTotalMoney + "").setPreface(preface);
+        String text = reader.readAsText(false);
+        List<String> arrayList = StrUtil.split(StrUtil.trim(StrUtil.replace(text, ",", "")), "\n");
+        String monthStr = arrayList.get(3);
+        List<String> monthList = StrUtil.split(monthStr, "\t");
+        String currentMonth = monthList.get(0);
+        String cumulativeMonth = monthList.get(1);
+        String title = arrayList.get(0);
+        String time = StrUtil.subBefore(StrUtil.subAfter(title, "20", true), "特定地区进出口总值", true);
+        String year = "20" + StrUtil.subBefore(time, "年", true);
+        String month = StrUtil.subBetween(time, "年", "月");
+        reportDTO.setYear(year).setMonth(month);
+        ReportRecord reportRecord = reportRecordService.findReport(year, month);
+        if (reportRecord == null) {
+            reportRecord = new ReportRecord();
+            reportRecord.setReportYear(year)
+                    .setReportMonth(month);
+            reportRecordService.save(reportRecord);
+        }
+        String reportId = reportRecord.getId();
+        this.removeByReportId(reportId);
 
-            List<String> zongbaoList = arrayList.stream().filter(str -> str.contains("综合保税区")).collect(Collectors.toList());
-            List<ExcelOutInTotal> excelDTOList = buildDTO(zongbaoList, currentMonth, cumulativeMonth);
+        List<String> zongbaoList = arrayList.stream().filter(str -> str.contains("综合保税区")).collect(Collectors.toList());
+        List<ExcelOutInTotal> excelDTOList = buildDTO(zongbaoList, currentMonth, cumulativeMonth);
 
-            //全国综保区数据
-            ExcelOutInTotal totalDTO = excelDTOList.get(0);
-            reportRecord.setNactionForeignTrade(totalDTO.getTotalCumulativeMonth())
-                    .setNactionForeignTradeInc(totalDTO.getTotalInc());
-            List<ExcelOutInTotal> gxList = excelDTOList.stream().filter(str -> {
-                String name = str.getName();
-                return name.contains(nn) || name.contains(wz) || name.contains(qz) || name.contains(bh) || name.contains(px);
-            }).collect(Collectors.toList());
-            gxList.forEach(excelOutInTotal -> {
-                excelOutInTotal.setReportId(reportId);
-                String name = excelOutInTotal.getName();
-                int index = excelOutInTotal.getIndex();
-                String totalInc = excelOutInTotal.getTotalInc()+"%";
-                totalInc=Double.parseDouble(excelOutInTotal.getTotalInc())==0?"-":totalInc;
-                String totalMoney = new BigDecimal(excelOutInTotal.getTotalCumulativeMonth()).divide(tenThousand, 1, RoundingMode.HALF_UP).toString();
-                if (name.contains(nn)) {
-                    reportDTO.setNnIndex(index)
-                            .setNnInc(totalInc)
-                            .setNnTotalMoney(totalMoney);
-                } else if (name.contains(px)) {
-                    reportDTO.setPxIndex(index).setPxInc(totalInc).setPxTotalMoney(totalMoney);
-                } else if (name.contains(wz)) {
-                    reportDTO.setWzIndex(index).setWzInc(totalInc).setWzTotalMoney(totalMoney);
-                } else if (name.contains(bh)) {
-                    reportDTO.setBhIndex(index).setBhInc(totalInc).setBhTotalMoney(totalMoney);
-                } else if (name.contains(qz)) {
-                    reportDTO.setQzIndex(index).setQzInc(totalInc).setQzTotalMoney(totalMoney);
-                }
-            });
-            this.saveBatch(gxList);
-            generateReport(reportRecord, gxList, excelDTOList.size(), reportDTO,templatePath);
-            reportRecordService.updateById(reportRecord);
-        } catch (IOException e) {
-            e.printStackTrace();
-        }
-        return false;
+        //全国综保区数据
+        ExcelOutInTotal totalDTO = excelDTOList.get(0);
+        reportRecord.setNactionForeignTrade(totalDTO.getTotalCumulativeMonth())
+                .setNactionForeignTradeInc(totalDTO.getTotalInc());
+        List<ExcelOutInTotal> gxList = excelDTOList.stream().filter(str -> {
+            String name = str.getName();
+            return name.contains(nn) || name.contains(wz) || name.contains(qz) || name.contains(bh) || name.contains(px);
+        }).collect(Collectors.toList());
+        gxList.forEach(excelOutInTotal -> {
+            excelOutInTotal.setReportId(reportId);
+            String name = excelOutInTotal.getName();
+            int index = excelOutInTotal.getIndex();
+            String totalInc = excelOutInTotal.getTotalInc() + "%";
+            totalInc = Double.parseDouble(excelOutInTotal.getTotalInc()) == 0 ? "-" : totalInc;
+            String totalMoney = new BigDecimal(excelOutInTotal.getTotalCumulativeMonth()).divide(tenThousand, 1, RoundingMode.HALF_UP).toString();
+            if (name.contains(nn)) {
+                reportDTO.setNnIndex(index)
+                        .setNnInc(totalInc)
+                        .setNnTotalMoney(totalMoney);
+            } else if (name.contains(px)) {
+                reportDTO.setPxIndex(index).setPxInc(totalInc).setPxTotalMoney(totalMoney);
+            } else if (name.contains(wz)) {
+                reportDTO.setWzIndex(index).setWzInc(totalInc).setWzTotalMoney(totalMoney);
+            } else if (name.contains(bh)) {
+                reportDTO.setBhIndex(index).setBhInc(totalInc).setBhTotalMoney(totalMoney);
+            } else if (name.contains(qz)) {
+                reportDTO.setQzIndex(index).setQzInc(totalInc).setQzTotalMoney(totalMoney);
+            }
+        });
+        this.saveBatch(gxList);
+        generateReport(reportRecord, gxList, excelDTOList.size(), reportDTO);
+        reportRecordService.updateById(reportRecord);
+        return true;
     }
 
 
-    private void generateReport(ReportRecord reportRecord, List<ExcelOutInTotal> gxList, int total, ReportDTO reportDTO,String templatePath) {
+    private void generateReport(ReportRecord reportRecord, List<ExcelOutInTotal> gxList, int total, ReportDTO reportDTO) {
         Double beforeTotalCumulativeMonth = 0D;
         BigDecimal hundred = BigDecimal.valueOf(100);
         BigDecimal tenThousand = BigDecimal.valueOf(10000);
@@ -178,12 +184,13 @@ public class ExcelOutInTotalServiceImpl extends ServiceImpl<ExcelOutInTotalMappe
             tradeTotalMoneyIndexDesc.append(excelOutInTotal.getName()).append("排名").append(excelOutInTotal.getIndex()).append("、");
         }
         reportDTO.setTradeTotalMoneyIndexDesc(tradeTotalMoneyIndexDesc.toString());
-        String gxTradeTotalMoney=reportDTO.getGxTradeTotalMoney();
+        String gxTradeTotalMoney = reportDTO.getGxTradeTotalMoney();
         long tradeTotalMoney = gxList.stream().collect(Collectors.summarizingLong(e -> Long.parseLong(e.getTotalCumulativeMonth()))).getSum();
-        if (StrUtil.isNotEmpty(gxTradeTotalMoney)&&!StrUtil.equals(gxTradeTotalMoney,"undefined")){
-           BigDecimal tradeTotalMoneyPercent= new BigDecimal(tradeTotalMoney)
-                   .divide(tenThousand,1,RoundingMode.UP).divide(new BigDecimal(gxTradeTotalMoney),3,RoundingMode.UP);
-           reportDTO.setTradeTotalMoneyPercent(tradeTotalMoneyPercent.multiply(hundred).toString());
+        if (StrUtil.isNotEmpty(gxTradeTotalMoney) && !StrUtil.equals(gxTradeTotalMoney, "undefined")) {
+            BigDecimal tradeTotalMoneyPercent = new BigDecimal(tradeTotalMoney)
+                    .divide(tenThousand, 1, RoundingMode.UP)
+                    .divide(new BigDecimal(gxTradeTotalMoney), 3, RoundingMode.UP);
+            reportDTO.setTradeTotalMoneyPercent(tradeTotalMoneyPercent.multiply(hundred)+"%");
         }
         //同比增长
         double tradeTotalMoneyInc = (BigDecimal.valueOf(tradeTotalMoney).subtract(BigDecimal.valueOf(beforeTotalCumulativeMonth)))
@@ -214,106 +221,10 @@ public class ExcelOutInTotalServiceImpl extends ServiceImpl<ExcelOutInTotalMappe
 
         reportDTO.setBondedIncAnalyse(bondedIncAnalyse.toString());
         log.info("report:{}", JSONUtil.toJsonStr(reportDTO));
-        createWord(reportDTO,reportRecord,templatePath);
+        reportRecordService.createWord(reportDTO, reportRecord);
     }
 
-    /**
-     * 生成word文档
-     * @param reportDTO
-     */
-    private void createWord(ReportDTO reportDTO,ReportRecord reportRecord,String templatePath) {
-        // 上传文件路径
-        String filePath = ZhbsqConfig.getWordPath();
-        File file=new File(filePath);
-        if (!file.exists()) {
-            file.mkdirs();
-        }
-        Field[] fields = ReflectUtil.getFields(reportDTO.getClass());
-        templatePath = ZhbsqConfig.getTemplatePath() + templatePath.replace("/profile/template","");
-        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) {
-                            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) {
-                                    // 清空单元格
-                                    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);
-        }
-    }
 
     private List<ExcelOutInTotal> buildDTO(List<String> list, String currentMonth, String cumulativeMonth) {
         List<ExcelOutInTotal> excelDTOList = new ArrayList<>();
@@ -351,4 +262,5 @@ public class ExcelOutInTotalServiceImpl extends ServiceImpl<ExcelOutInTotalMappe
         this.baseMapper.removeByReportId(reportId);
     }
 
+
 }

+ 21 - 0
zhbsq-modlue/src/main/java/com/hjy/module/vo/activecompanies/ActiveCompaniesVo.java

@@ -0,0 +1,21 @@
+package com.hjy.module.vo.activecompanies;
+
+import com.hjy.module.domain.activecompanies.ActiveCompanies;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.ToString;
+import lombok.experimental.Accessors;
+
+/**
+ * 历年活跃企业数Vo对象 CB_ACTIVE_COMPANIES
+ *
+ * @author Tellsea
+ * @date 2024-05-28
+ */
+@Data
+@Accessors(chain = true)
+@ToString(callSuper = true)
+@EqualsAndHashCode(callSuper = true)
+public class ActiveCompaniesVo extends ActiveCompanies {
+
+}

+ 4 - 0
zhbsq-modlue/src/main/java/com/hjy/module/vo/report/ReportRecordVo.java

@@ -18,4 +18,8 @@ import lombok.experimental.Accessors;
 @EqualsAndHashCode(callSuper = true)
 public class ReportRecordVo extends ReportRecord {
 
+    private String gxTradeTotalMoney;
+    private String preface;
+    private String paths;
+
 }

+ 53 - 0
zhbsq-modlue/src/main/resources/mapper/activecompanies/ActiveCompaniesMapper.xml

@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.hjy.module.mapper.activecompanies.ActiveCompaniesMapper">
+
+    <sql id="querySql">
+        select <include refid="allField"/>
+        from CB_ACTIVE_COMPANIES A
+        <include refid="search"/>
+    </sql>
+
+    <select id="queryList" resultType="com.hjy.module.vo.activecompanies.ActiveCompaniesVo">
+        <include refid="querySql"/>
+        <if test="entity.code != null and entity.code != ''">
+            and A.CODE =#{entity.code}
+        </if>
+        <if test="entity.name != null and entity.name != ''">
+            and A.NAME like concat('%', #{entity.name}, '%')
+        </if>
+
+        <if test="entity.staticsYear != null and entity.staticsYear != ''">
+            and A.STATICS_YEAR = #{entity.staticsYear}
+        </if>
+        <if test="entity.staticsMonth != null and entity.staticsMonth != ''">
+            and A.STATICS_MONTH =#{entity.staticsMonth}
+        </if>
+        order by A.create_time desc
+    </select>
+
+    <select id="queryById" resultType="com.hjy.module.vo.activecompanies.ActiveCompaniesVo">
+        <include refid="querySql"/>
+        and A.id = #{id}
+    </select>
+
+    <sql id="allField">
+        A.ID,
+        A.CODE,
+        A.NAME,
+        A.NUMBER,
+        A.inc,
+        A.STATICS_YEAR,
+        A.STATICS_MONTH,
+        A.CREATE_TIME,
+        A.CREATE_BY,
+        A.UPDATE_TIME,
+        A.UPDATE_BY
+    </sql>
+
+    <sql id="search">
+        where 1 = 1
+    </sql>
+</mapper>