home il y a 2 ans
Parent
commit
0726e552aa
21 fichiers modifiés avec 740 ajouts et 21 suppressions
  1. 49 0
      hx-service-api/victoriatourist-api/src/main/java/com/fjhx/entity/excel/ExcelImportFailLine.java
  2. 60 0
      hx-service-api/victoriatourist-api/src/main/java/com/fjhx/entity/excel/ExcelImportLog.java
  3. 17 0
      hx-service-api/victoriatourist-api/src/main/java/com/fjhx/params/excel/ExcelImportFailLineEx.java
  4. 17 0
      hx-service-api/victoriatourist-api/src/main/java/com/fjhx/params/excel/ExcelImportFailLineVo.java
  5. 17 0
      hx-service-api/victoriatourist-api/src/main/java/com/fjhx/params/excel/ExcelImportLogEx.java
  6. 17 0
      hx-service-api/victoriatourist-api/src/main/java/com/fjhx/params/excel/ExcelImportLogVo.java
  7. 18 0
      hx-service-api/victoriatourist-api/src/main/java/com/fjhx/params/excel/ExcelProcessingProgress.java
  8. 7 7
      hx-service/storage/src/main/java/com/fjhx/stock/service/impl/StockBackPlanServiceImpl.java
  9. 44 0
      hx-service/victoriatourist/src/main/java/com/fjhx/config/TaskPoolConfig.java
  10. 56 0
      hx-service/victoriatourist/src/main/java/com/fjhx/controller/excel/ExcelImportFailLineController.java
  11. 31 0
      hx-service/victoriatourist/src/main/java/com/fjhx/controller/excel/ExcelImportLogController.java
  12. 21 0
      hx-service/victoriatourist/src/main/java/com/fjhx/controller/warehouse/TestExcel.java
  13. 13 14
      hx-service/victoriatourist/src/main/java/com/fjhx/listener/EasyExcelListener.java
  14. 16 0
      hx-service/victoriatourist/src/main/java/com/fjhx/mapper/excel/ExcelImportFailLineMapper.java
  15. 5 0
      hx-service/victoriatourist/src/main/java/com/fjhx/mapper/excel/ExcelImportFailLineMapper.xml
  16. 16 0
      hx-service/victoriatourist/src/main/java/com/fjhx/mapper/excel/ExcelImportLogMapper.java
  17. 5 0
      hx-service/victoriatourist/src/main/java/com/fjhx/mapper/excel/ExcelImportLogMapper.xml
  18. 28 0
      hx-service/victoriatourist/src/main/java/com/fjhx/service/excel/ExcelImportFailLineService.java
  19. 49 0
      hx-service/victoriatourist/src/main/java/com/fjhx/service/excel/ExcelImportLogService.java
  20. 48 0
      hx-service/victoriatourist/src/main/java/com/fjhx/service/excel/impl/ExcelImportFailLineServiceImpl.java
  21. 206 0
      hx-service/victoriatourist/src/main/java/com/fjhx/service/excel/impl/ExcelImportLogServiceImpl.java

+ 49 - 0
hx-service-api/victoriatourist-api/src/main/java/com/fjhx/entity/excel/ExcelImportFailLine.java

@@ -0,0 +1,49 @@
+package com.fjhx.entity.excel;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.Version;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.FieldFill;
+import com.baomidou.mybatisplus.annotation.TableLogic;
+import com.fjhx.base.BaseEntity;
+import com.baomidou.mybatisplus.annotation.TableField;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+/**
+ * <p>
+ * 
+ * </p>
+ *
+ * @author ${author}
+ * @since 2022-12-07
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class ExcelImportFailLine extends BaseEntity {
+
+
+    /**
+     * excel导入记录id
+     */
+    private Integer excelImportLogId;
+
+    /**
+     * 行号
+     */
+    private Integer lineNumber;
+
+    /**
+     * 失败原因
+     */
+    private String failReason;
+
+    /**
+     * 逻辑删除 0未删除 1已删除
+     */
+    @TableField(fill = FieldFill.INSERT)
+    @TableLogic
+    private Integer delFlag;
+
+
+}

+ 60 - 0
hx-service-api/victoriatourist-api/src/main/java/com/fjhx/entity/excel/ExcelImportLog.java

@@ -0,0 +1,60 @@
+package com.fjhx.entity.excel;
+
+import com.baomidou.mybatisplus.annotation.FieldFill;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableLogic;
+import com.fjhx.base.BaseEntity;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+/**
+ * <p>
+ *
+ * </p>
+ *
+ * @author ${author}
+ * @since 2022-12-07
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class ExcelImportLog extends BaseEntity {
+
+    /**
+     * 标记
+     */
+    private String flag;
+
+    /**
+     * 业务类型
+     */
+    private Integer businessType;
+
+    /**
+     * 状态 (0初始化 1成功 2失败 3导入时手动停止 4成功后被删除)
+     */
+    private Integer status;
+
+    /**
+     * 文件名
+     */
+    private String fileName;
+
+    /**
+     * 执行时间(秒)
+     */
+    private Long executeTime;
+
+    /**
+     * 源文件
+     */
+    private byte[] sourceFile;
+
+    /**
+     * 逻辑删除 0未删除 1已删除
+     */
+    @TableField(fill = FieldFill.INSERT)
+    @TableLogic
+    private Integer delFlag;
+
+
+}

+ 17 - 0
hx-service-api/victoriatourist-api/src/main/java/com/fjhx/params/excel/ExcelImportFailLineEx.java

@@ -0,0 +1,17 @@
+package com.fjhx.params.excel;
+
+import com.fjhx.entity.excel.ExcelImportFailLine;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+/**
+ * 
+ *
+ * @author ${author}
+ * @since 2022-12-07
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class ExcelImportFailLineEx extends ExcelImportFailLine {
+
+}

+ 17 - 0
hx-service-api/victoriatourist-api/src/main/java/com/fjhx/params/excel/ExcelImportFailLineVo.java

@@ -0,0 +1,17 @@
+package com.fjhx.params.excel;
+
+import com.fjhx.entity.excel.ExcelImportFailLine;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+/**
+ * 
+ *
+ * @author ${author}
+ * @since 2022-12-07
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class ExcelImportFailLineVo extends ExcelImportFailLine {
+
+}

+ 17 - 0
hx-service-api/victoriatourist-api/src/main/java/com/fjhx/params/excel/ExcelImportLogEx.java

@@ -0,0 +1,17 @@
+package com.fjhx.params.excel;
+
+import com.fjhx.entity.excel.ExcelImportLog;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+/**
+ * 
+ *
+ * @author ${author}
+ * @since 2022-12-07
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class ExcelImportLogEx extends ExcelImportLog {
+
+}

+ 17 - 0
hx-service-api/victoriatourist-api/src/main/java/com/fjhx/params/excel/ExcelImportLogVo.java

@@ -0,0 +1,17 @@
+package com.fjhx.params.excel;
+
+import com.fjhx.entity.excel.ExcelImportLog;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+/**
+ * 
+ *
+ * @author ${author}
+ * @since 2022-12-07
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class ExcelImportLogVo extends ExcelImportLog {
+
+}

+ 18 - 0
hx-service-api/victoriatourist-api/src/main/java/com/fjhx/params/excel/ExcelProcessingProgress.java

@@ -0,0 +1,18 @@
+package com.fjhx.params.excel;
+
+import lombok.Data;
+
+@Data
+public class ExcelProcessingProgress {
+
+    /**
+     * 1、预处理 2、解析中 3、处理中 4、发生异常 5、已完成 6、用户取消
+     */
+    Integer status;
+
+    /**
+     * 进度百分比
+     */
+    Integer percentage;
+
+}

+ 7 - 7
hx-service/storage/src/main/java/com/fjhx/stock/service/impl/StockBackPlanServiceImpl.java

@@ -255,7 +255,7 @@ public class StockBackPlanServiceImpl extends ServiceImpl<StockBackPlanMapper, S
                 .in("uu.DepartmentID", "A007", "A012", "A017")
 //                .likeRight("m.Code", "01.")
 //                .notIn("m.Code", "01.002.0045", "01.002.0124", "01.002.0381", "01.002.0383")
-                .ne("m.CategoryCode", "99.999.")
+                .notIn("m.CategoryCode", "99.999.", "01.007.")
                 .isNotNull("uu.JobNo"));
 
         for (Map<String, Object> map : pickingList) {
@@ -316,7 +316,7 @@ public class StockBackPlanServiceImpl extends ServiceImpl<StockBackPlanMapper, S
                 .eq("uu.DepartmentID", "A008")
 //                .likeRight("m.Code", "01.")
 //                .notIn("m.Code", "01.002.0045", "01.002.0124", "01.002.0381", "01.002.0383")
-                .ne("m.CategoryCode", "99.999.")
+                .notIn("m.CategoryCode", "99.999.", "01.007.")
                 .isNotNull("uu.JobNo"));
 
         for (Map<String, Object> map : pickingList) {
@@ -380,7 +380,7 @@ public class StockBackPlanServiceImpl extends ServiceImpl<StockBackPlanMapper, S
                         .eq("uu.IsDelete", 0)
                         .in("uu.DepartmentID", "A007", "A012", "A017")
                         .isNotNull("uu.JobNo")
-                        .ne("m.CategoryCode", "99.999.")
+                        .notIn("m.CategoryCode", "99.999.", "01.007.")
 //                .likeRight("m.Code", "01.")
 //                .notIn("m.Code", "01.002.0045", "01.002.0124", "01.002.0381", "01.002.0383")
 
@@ -440,7 +440,7 @@ public class StockBackPlanServiceImpl extends ServiceImpl<StockBackPlanMapper, S
                         .eq("uu.IsDelete", 0)
                         .eq("uu.DepartmentID", "A008")
                         .isNotNull("uu.JobNo")
-                        .ne("m.CategoryCode", "99.999.")
+                        .notIn("m.CategoryCode", "99.999.", "01.007.")
 //                .likeRight("m.Code", "01.")
 //                .notIn("m.Code", "01.002.0045", "01.002.0124", "01.002.0381", "01.002.0383")
         );
@@ -502,7 +502,7 @@ public class StockBackPlanServiceImpl extends ServiceImpl<StockBackPlanMapper, S
                         .gt("sbc.correct_time", DateUtil.format(beginDate, "yyyy-MM-dd 00:00:00"))
                         .isNotNull("uu.JobNo")
 //                .notIn("m.Code", "01.002.0045", "01.002.0124", "01.002.0381", "01.002.0383")
-                        .ne("m.CategoryCode", "99.999.")
+                        .notIn("m.CategoryCode", "99.999.", "01.007.")
         );
         for (Map<String, Object> map : correctList) {
             // 出库时间
@@ -536,7 +536,7 @@ public class StockBackPlanServiceImpl extends ServiceImpl<StockBackPlanMapper, S
                         .eq("st.status", StatusConstant.YES)
                         .eq("st.del_flag", 0)
 //                .notIn("m.Code", "01.002.0045", "01.002.0124", "01.002.0381", "01.002.0383")
-                        .ne("m.CategoryCode", "99.999.")
+                        .notIn("m.CategoryCode", "99.999.", "01.007.")
         );
 
         for (Map<String, Object> map : transferPickingList) {
@@ -599,7 +599,7 @@ public class StockBackPlanServiceImpl extends ServiceImpl<StockBackPlanMapper, S
                         .eq("st.status", StatusConstant.YES)
                         .eq("st.del_flag", 0)
 //                .notIn("m.Code", "01.002.0045", "01.002.0124", "01.002.0381", "01.002.0383")
-                        .ne("m.CategoryCode", "99.999.")
+                        .notIn("m.CategoryCode", "99.999.", "01.007.")
         );
 
         for (Map<String, Object> map : transferBackList) {

+ 44 - 0
hx-service/victoriatourist/src/main/java/com/fjhx/config/TaskPoolConfig.java

@@ -0,0 +1,44 @@
+package com.fjhx.config;
+
+import com.fjhx.constants.ErrorMsgConstant;
+import org.springblade.core.log.exception.ServiceException;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.EnableAsync;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
+
+import java.util.concurrent.Executor;
+
+/**
+ * 线程池配置
+ */
+@EnableAsync
+@Configuration
+public class TaskPoolConfig {
+
+    public static final String excelExecutor = "excelExecutor";
+
+    @Bean(name = excelExecutor)
+    public ThreadPoolTaskExecutor taskExecutor() {
+        ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();
+        //配置核心线程数
+        threadPoolTaskExecutor.setCorePoolSize(2);
+        //配置最大线程数
+        threadPoolTaskExecutor.setMaxPoolSize(5);
+        //配置队列大小
+        threadPoolTaskExecutor.setQueueCapacity(10);
+        //缓冲队列大小
+        threadPoolTaskExecutor.setKeepAliveSeconds(10);
+        //配置线程池中的线程的名称前缀
+        threadPoolTaskExecutor.setThreadNamePrefix(excelExecutor + ":");
+        // 线程池对拒绝任务的处理策略:由调用线程(提交任务的线程)处理该任务
+        threadPoolTaskExecutor.setRejectedExecutionHandler((r, executor) -> {
+            throw new ServiceException(ErrorMsgConstant.SYSTEM_BUSY_ERROR);
+        });
+
+        //执行初始化
+        threadPoolTaskExecutor.initialize();
+        return threadPoolTaskExecutor;
+    }
+
+}

+ 56 - 0
hx-service/victoriatourist/src/main/java/com/fjhx/controller/excel/ExcelImportFailLineController.java

@@ -0,0 +1,56 @@
+package com.fjhx.controller.excel;
+
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import org.springblade.core.tool.api.R;
+import com.fjhx.entity.excel.ExcelImportFailLine;
+import com.fjhx.params.excel.ExcelImportFailLineVo;
+import com.fjhx.service.excel.ExcelImportFailLineService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.Map;
+
+/**
+ * <p>
+ *  前端控制器
+ * </p>
+ *
+ * @author ${author}
+ * @since 2022-12-07
+ */
+@RestController
+@RequestMapping("/excelImportFailLine")
+public class ExcelImportFailLineController {
+
+    @Autowired
+    private ExcelImportFailLineService excelImportFailLineService;
+
+    @PostMapping("/page")
+    public R page(@RequestBody Map<String, Object> condition){
+        Page<ExcelImportFailLine> result = excelImportFailLineService.getPage(condition);
+        return R.success(result);
+    }
+
+    @PostMapping("/add")
+    public R add(@RequestBody ExcelImportFailLineVo excelImportFailLineVo){
+        excelImportFailLineService.add(excelImportFailLineVo);
+        return R.success();
+    }
+
+    @PostMapping("/edit")
+    public R edit(@RequestBody ExcelImportFailLineVo excelImportFailLineVo){
+        excelImportFailLineService.edit(excelImportFailLineVo);
+        return R.success();
+    }
+
+    @PostMapping("/delete")
+    public R delete(@RequestBody ExcelImportFailLineVo excelImportFailLineVo){
+        excelImportFailLineService.delete(excelImportFailLineVo);
+        return R.success();
+    }
+
+}
+

+ 31 - 0
hx-service/victoriatourist/src/main/java/com/fjhx/controller/excel/ExcelImportLogController.java

@@ -0,0 +1,31 @@
+package com.fjhx.controller.excel;
+
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.fjhx.entity.excel.ExcelImportLog;
+import com.fjhx.service.excel.ExcelImportLogService;
+import org.springblade.core.tool.api.R;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.Map;
+
+/**
+ * <p>
+ * 前端控制器
+ * </p>
+ *
+ * @author ${author}
+ * @since 2022-12-07
+ */
+@RestController
+@RequestMapping("/excelImportLog")
+public class ExcelImportLogController {
+
+    @Autowired
+    private ExcelImportLogService excelImportLogService;
+
+}
+

+ 21 - 0
hx-service/victoriatourist/src/main/java/com/fjhx/controller/warehouse/TestExcel.java

@@ -0,0 +1,21 @@
+package com.fjhx.controller.warehouse;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import lombok.Data;
+
+@Data
+public class TestExcel {
+
+    @ExcelProperty("全国现货库存")
+    private int xh;
+
+    @ExcelProperty("全国可用库存")
+    private int kc;
+
+    @ExcelProperty("全国昨日出库商品件数")
+    private int js;
+
+
+
+
+}

+ 13 - 14
hx-service/victoriatourist/src/main/java/com/fjhx/listener/EasyExcelConsumerListener.java → hx-service/victoriatourist/src/main/java/com/fjhx/listener/EasyExcelListener.java

@@ -7,15 +7,15 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.function.Consumer;
 
-public class EasyExcelConsumerListener<T> extends AnalysisEventListener<T> {
+public class EasyExcelListener<T> extends AnalysisEventListener<T> {
     private final int pageSize;
     private final List<T> list;
-    private final Consumer<List<T>> consumer;
-    private final Runnable runnable;
+    private final EasyExcelInterface<T> consumer;
+    private final Consumer<Exception> runnable;
     private int radeLine = 0;
-    private int approximateTotalRowNumber = 0;
+    private Integer totalLine;
 
-    public EasyExcelConsumerListener(int pageSize, Consumer<List<T>> consumer, Runnable runnable) {
+    public EasyExcelListener(int pageSize, EasyExcelInterface<T> consumer, Consumer<Exception> runnable) {
         this.pageSize = pageSize;
         this.consumer = consumer;
         this.runnable = runnable;
@@ -26,9 +26,11 @@ public class EasyExcelConsumerListener<T> extends AnalysisEventListener<T> {
     public void invoke(T data, AnalysisContext context) {
         list.add(data);
         if (list.size() >= pageSize) {
-            approximateTotalRowNumber = context.readSheetHolder().getApproximateTotalRowNumber();
+            if (totalLine == null) {
+                totalLine = context.readSheetHolder().getApproximateTotalRowNumber();
+            }
             radeLine += list.size();
-            consumer.accept(list);
+            consumer.execute(list, totalLine, radeLine);
             list.clear();
         }
     }
@@ -36,20 +38,17 @@ public class EasyExcelConsumerListener<T> extends AnalysisEventListener<T> {
     @Override
     public void doAfterAllAnalysed(AnalysisContext context) {
         if (list.size() > 0) {
-            consumer.accept(list);
+            consumer.execute(list, totalLine, radeLine);
         }
     }
 
     @Override
     public void onException(Exception exception, AnalysisContext context) {
-        runnable.run();
+        runnable.accept(exception);
     }
 
-    public int getRadeLine() {
-        return radeLine;
+    public interface EasyExcelInterface<T> {
+        void execute(List<T> list, int totalLine, int radeLine);
     }
 
-    public int getApproximateTotalRowNumber() {
-        return approximateTotalRowNumber;
-    }
 }

+ 16 - 0
hx-service/victoriatourist/src/main/java/com/fjhx/mapper/excel/ExcelImportFailLineMapper.java

@@ -0,0 +1,16 @@
+package com.fjhx.mapper.excel;
+
+import com.fjhx.entity.excel.ExcelImportFailLine;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * <p>
+ *  Mapper 接口
+ * </p>
+ *
+ * @author ${author}
+ * @since 2022-12-07
+ */
+public interface ExcelImportFailLineMapper extends BaseMapper<ExcelImportFailLine> {
+
+}

+ 5 - 0
hx-service/victoriatourist/src/main/java/com/fjhx/mapper/excel/ExcelImportFailLineMapper.xml

@@ -0,0 +1,5 @@
+<?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.fjhx.mapper.excel.ExcelImportFailLineMapper">
+
+</mapper>

+ 16 - 0
hx-service/victoriatourist/src/main/java/com/fjhx/mapper/excel/ExcelImportLogMapper.java

@@ -0,0 +1,16 @@
+package com.fjhx.mapper.excel;
+
+import com.fjhx.entity.excel.ExcelImportLog;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * <p>
+ *  Mapper 接口
+ * </p>
+ *
+ * @author ${author}
+ * @since 2022-12-07
+ */
+public interface ExcelImportLogMapper extends BaseMapper<ExcelImportLog> {
+
+}

+ 5 - 0
hx-service/victoriatourist/src/main/java/com/fjhx/mapper/excel/ExcelImportLogMapper.xml

@@ -0,0 +1,5 @@
+<?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.fjhx.mapper.excel.ExcelImportLogMapper">
+
+</mapper>

+ 28 - 0
hx-service/victoriatourist/src/main/java/com/fjhx/service/excel/ExcelImportFailLineService.java

@@ -0,0 +1,28 @@
+package com.fjhx.service.excel;
+
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.fjhx.entity.excel.ExcelImportFailLine;
+import com.fjhx.params.excel.ExcelImportFailLineVo;
+import com.fjhx.base.BaseService;
+
+import java.util.Map;
+
+/**
+ * <p>
+ *  服务类
+ * </p>
+ *
+ * @author ${author}
+ * @since 2022-12-07
+ */
+public interface ExcelImportFailLineService extends BaseService<ExcelImportFailLine> {
+
+    Page<ExcelImportFailLine> getPage(Map<String, Object> condition);
+
+    void add(ExcelImportFailLineVo excelImportFailLineVo);
+
+    void edit(ExcelImportFailLineVo excelImportFailLineVo);
+
+    void delete(ExcelImportFailLineVo excelImportFailLineVo);
+
+}

+ 49 - 0
hx-service/victoriatourist/src/main/java/com/fjhx/service/excel/ExcelImportLogService.java

@@ -0,0 +1,49 @@
+package com.fjhx.service.excel;
+
+import com.fjhx.base.BaseService;
+import com.fjhx.entity.excel.ExcelImportLog;
+import com.fjhx.params.excel.ExcelProcessingProgress;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.util.List;
+import java.util.function.Consumer;
+
+/**
+ * <p>
+ * 服务类
+ * </p>
+ *
+ * @author ${author}
+ * @since 2022-12-07
+ */
+public interface ExcelImportLogService extends BaseService<ExcelImportLog> {
+
+    /**
+     * 异步分批处理excel数据
+     *
+     * @param flag         缓存标记
+     * @param file         excel文件
+     * @param cls          转换对象
+     * @param businessType 业务类型
+     * @param handleFun    读取到数据处理方法
+     * @param errorFun     发生异常处理方法
+     * @param <T>          对象类型
+     */
+    <T> void asyncRead(String flag, MultipartFile file, Class<T> cls, Integer businessType,
+                       Consumer<List<T>> handleFun, Runnable errorFun);
+
+    /**
+     * 查看处理进度
+     *
+     * @param flag 缓存标记
+     */
+    ExcelProcessingProgress getReadRate(String flag);
+
+    /**
+     * 停止处理
+     *
+     * @param flag 缓存标记
+     */
+    void stopRead(String flag);
+
+}

+ 48 - 0
hx-service/victoriatourist/src/main/java/com/fjhx/service/excel/impl/ExcelImportFailLineServiceImpl.java

@@ -0,0 +1,48 @@
+package com.fjhx.service.excel.impl;
+
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.fjhx.entity.excel.ExcelImportFailLine;
+import com.fjhx.params.excel.ExcelImportFailLineVo;
+import com.fjhx.mapper.excel.ExcelImportFailLineMapper;
+import com.fjhx.service.excel.ExcelImportFailLineService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.fjhx.utils.wrapperUtil.IWrapper;
+import org.springframework.stereotype.Service;
+
+import java.util.Map;
+
+/**
+ * <p>
+ *  服务实现类
+ * </p>
+ *
+ * @author ${author}
+ * @since 2022-12-07
+ */
+@Service
+public class ExcelImportFailLineServiceImpl extends ServiceImpl<ExcelImportFailLineMapper, ExcelImportFailLine> implements ExcelImportFailLineService {
+
+    @Override
+    public Page<ExcelImportFailLine> getPage(Map<String, Object> condition) {
+
+        IWrapper<ExcelImportFailLine> wrapper = IWrapper.getWrapper(condition);
+
+        return page(condition, wrapper);
+    }
+
+    @Override
+    public void add(ExcelImportFailLineVo excelImportFailLineVo) {
+        save(excelImportFailLineVo);
+    }
+
+    @Override
+    public void edit(ExcelImportFailLineVo excelImportFailLineVo) {
+        updateById(excelImportFailLineVo);
+    }
+
+    @Override
+    public void delete(ExcelImportFailLineVo excelImportFailLineVo) {
+        removeById(excelImportFailLineVo.getId());
+    }
+
+}

+ 206 - 0
hx-service/victoriatourist/src/main/java/com/fjhx/service/excel/impl/ExcelImportLogServiceImpl.java

@@ -0,0 +1,206 @@
+package com.fjhx.service.excel.impl;
+
+import cn.hutool.core.io.IoUtil;
+import cn.hutool.core.util.ObjectUtil;
+import com.alibaba.excel.EasyExcel;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.fjhx.base.BaseEntity;
+import com.fjhx.config.TaskPoolConfig;
+import com.fjhx.entity.excel.ExcelImportLog;
+import com.fjhx.listener.EasyExcelListener;
+import com.fjhx.mapper.excel.ExcelImportLogMapper;
+import com.fjhx.params.excel.ExcelProcessingProgress;
+import com.fjhx.service.excel.ExcelImportLogService;
+import org.springblade.core.excel.support.ExcelException;
+import org.springblade.core.redis.cache.BladeRedis;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
+import org.springframework.stereotype.Service;
+import org.springframework.util.ObjectUtils;
+import org.springframework.util.StringUtils;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.annotation.Resource;
+import java.io.BufferedInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Date;
+import java.util.List;
+import java.util.function.Consumer;
+
+/**
+ * <p>
+ * 服务实现类
+ * </p>
+ *
+ * @author ${author}
+ * @since 2022-12-07
+ */
+@Service
+public class ExcelImportLogServiceImpl extends ServiceImpl<ExcelImportLogMapper, ExcelImportLog> implements ExcelImportLogService {
+
+    @Qualifier(TaskPoolConfig.excelExecutor)
+    @Autowired
+    private ThreadPoolTaskExecutor executor;
+
+    @Resource
+    private BladeRedis bladeRedis;
+
+    @Override
+    public <T> void asyncRead(String flag, MultipartFile file, Class<T> cls, Integer businessType,
+                              Consumer<List<T>> handleFun, Runnable errorFun) {
+
+        String filename = file.getOriginalFilename();
+        if (ObjectUtils.isEmpty(filename)) {
+            throw new ExcelException("请上传文件!");
+        }
+        if ((!StringUtils.endsWithIgnoreCase(filename, ".xls") && !StringUtils.endsWithIgnoreCase(filename, ".xlsx"))) {
+            throw new ExcelException("请上传正确的excel文件!");
+        }
+
+        InputStream inputStream;
+        try {
+            inputStream = new BufferedInputStream(file.getInputStream());
+        } catch (IOException e) {
+            throw new ExcelException("文件读取失败!");
+        }
+
+        // 导入信息放入redis缓存
+        ExcelProcessingProgress excelProcessingProgress = new ExcelProcessingProgress();
+        excelProcessingProgress.setStatus(1); // 预处理阶段
+        excelProcessingProgress.setPercentage(5); // 进度 5%
+        setProgress(flag, excelProcessingProgress); // 保存
+
+        executor.execute(() -> {
+            try {
+                // 开始时间
+                long start = System.currentTimeMillis();
+
+                // 信息保存到数据库
+                saveLog(flag, businessType, file);
+
+                // 开始处理 进度 10%
+                verificationAndUpdateProgress(flag, 2, 10);
+
+                EasyExcel.read(inputStream, cls, new EasyExcelListener<T>(
+                        500,
+                        (list, totalLine, readLine) -> {
+                            handleFun.accept(list);
+                            if (totalLine == readLine) {
+                                editLog(start, flag, 1);
+                                // 已完成
+                                verificationAndUpdateProgress(flag, 5, 100);
+                            } else {
+                                // 处理中
+                                verificationAndUpdateProgress(flag, 3, 10 + readLine * 90 / totalLine);
+                            }
+                        },
+                        (exception) -> {
+                            exception.printStackTrace();
+                            errorFun.run();
+                            // 用户取消
+                            if (exception instanceof ExcelException) {
+                                editLog(start, flag, 3);
+                                verificationAndUpdateProgress(flag, 6, 0);
+                            }
+                            // 发生异常
+                            else {
+                                editLog(start, flag, 2);
+                                verificationAndUpdateProgress(flag, 4, 0);
+                            }
+                        })).doReadAll();
+            } catch (Exception e) {
+                log.error(e.getMessage());
+            } finally {
+                IoUtil.close(inputStream);
+            }
+        });
+    }
+
+    @Override
+    public ExcelProcessingProgress getReadRate(String flag) {
+        ExcelProcessingProgress excelProcessingProgress = bladeRedis.get(flag);
+
+        // 如果处理完成、用户取消、发生异常,删除缓存
+        if (excelProcessingProgress != null && excelProcessingProgress.getStatus() > 3) {
+            bladeRedis.del(flag);
+        }
+
+        return excelProcessingProgress;
+    }
+
+    @Override
+    public void stopRead(String flag) {
+        // 导入信息放入redis缓存
+        ExcelProcessingProgress excelProcessingProgress = new ExcelProcessingProgress();
+        excelProcessingProgress.setStatus(6); // 预处理阶段
+        excelProcessingProgress.setPercentage(0); // 进度 0%
+        setProgress(flag, excelProcessingProgress);
+    }
+
+    /**
+     * 插入缓存信息
+     *
+     * @param flag                    缓存标记
+     * @param excelProcessingProgress 缓存对象
+     */
+    private synchronized void setProgress(String flag, ExcelProcessingProgress excelProcessingProgress) {
+        bladeRedis.setEx(flag, excelProcessingProgress, 60L * 60 * 12);
+    }
+
+    /**
+     * 验证并更新缓存信息
+     *
+     * @param flag       缓存标记
+     * @param status     状态
+     * @param percentage 进度
+     */
+    private synchronized void verificationAndUpdateProgress(String flag, Integer status, Integer percentage) {
+        ExcelProcessingProgress excelProcessingProgress = bladeRedis.get(flag);
+        if (ObjectUtil.isNull(excelProcessingProgress) || excelProcessingProgress.getStatus().equals(6)) {
+            throw new ExcelException("取消导入");
+        }
+
+        excelProcessingProgress.setStatus(status);
+        excelProcessingProgress.setPercentage(percentage);
+        bladeRedis.setEx(flag, excelProcessingProgress, 60L * 60 * 12);
+    }
+
+    /**
+     * 保存导入记录
+     *
+     * @param flag         导入标记
+     * @param businessType 业务类型
+     * @param file         文件
+     */
+    private void saveLog(String flag, Integer businessType, MultipartFile file) {
+        // 上传记录记录数据库
+        ExcelImportLog excelImportLog = new ExcelImportLog();
+        excelImportLog.setFlag(flag);
+        excelImportLog.setBusinessType(businessType);
+        excelImportLog.setStatus(0);
+        excelImportLog.setFileName(file.getOriginalFilename());
+        save(excelImportLog);
+    }
+
+    /**
+     * 更新导入记录
+     *
+     * @param start  开始导入时间戳
+     * @param flag   标记
+     * @param status 状态
+     */
+    private void editLog(Long start, String flag, Integer status) {
+        long end = System.currentTimeMillis();
+
+        update(q -> q
+                .eq(ExcelImportLog::getFlag, flag)
+                .set(ExcelImportLog::getStatus, status)
+                .set(ExcelImportLog::getExecuteTime, (end - start) / 1000)
+                .set(BaseEntity::getUpdateTime, new Date())
+        );
+    }
+
+
+}