lenovodn 2 năm trước cách đây
mục cha
commit
a3e29bd539

+ 5 - 1
jeecg-boot-base-core/src/main/java/org/jeecg/common/system/base/controller/JeecgController.java

@@ -19,6 +19,7 @@ import org.jeecgframework.poi.excel.entity.enmus.ExcelType;
 import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.web.multipart.MultipartFile;
 import org.springframework.web.multipart.MultipartHttpServletRequest;
 import org.springframework.web.servlet.ModelAndView;
@@ -27,6 +28,7 @@ import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.util.*;
+import java.util.concurrent.CountDownLatch;
 import java.util.stream.Collectors;
 
 /**
@@ -206,7 +208,7 @@ public class JeecgController<T, S extends IService<T>> {
                 List<T> list = ExcelImportUtil.importExcel(file.getInputStream(), clazz, params);
                 //update-begin-author:taoyan date:20190528 for:批量插入数据
                 long start = System.currentTimeMillis();
-                service.saveBatch(list);
+                service.saveBatch(list,1000);
                 //400条 saveBatch消耗时间1592毫秒  循环插入消耗时间1947毫秒
                 //1200条  saveBatch消耗时间3687毫秒 循环插入消耗时间5212毫秒
                 log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒");
@@ -232,4 +234,6 @@ public class JeecgController<T, S extends IService<T>> {
         }
         return Result.error("文件导入失败!");
     }
+
+
 }

+ 32 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/config/init/ThreadPoolConfig.java

@@ -0,0 +1,32 @@
+package org.jeecg.config.init;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+@Data
+@ConfigurationProperties(prefix = "thread.pool")
+public class ThreadPoolConfig {
+    /**
+     * 核心线程数
+     */
+    private Integer corePoolSize;
+
+    /**
+     * 设置最大线程数
+     */
+    private Integer maxPoolSize;
+
+    /**
+     * 设置线程活跃时间
+     */
+    private Integer keepAliveSeconds;
+
+    /**
+     * 设置队列容量
+     */
+    private Integer queueCapacity;
+
+    /**
+     * 线程名称前缀
+     */
+    private String prefixName;
+}

+ 41 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/config/init/ThreadPoolExecutorConfig.java

@@ -0,0 +1,41 @@
+//package org.jeecg.config.init;
+//
+//import lombok.extern.slf4j.Slf4j;
+//import org.jeecg.modules.medical.CommonThreadPoolConfig;
+//import org.springframework.beans.factory.annotation.Autowired;
+//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;
+//import java.util.concurrent.ThreadPoolExecutor;
+//
+//@Configuration
+//@EnableAsync
+//@Slf4j
+//public class ThreadPoolExecutorConfig {
+//
+//    private ThreadPoolConfig threadPoolConfig;
+//
+//    public ThreadPoolExecutorConfig(ThreadPoolConfig threadPoolConfig) {
+//        this.threadPoolConfig = threadPoolConfig;
+//    }
+//
+//    @Bean(name = "asyncServiceExecutor")
+//    public Executor asyncServiceExecutor() {
+//        log.info("start asyncServiceExecutor");
+//        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
+//        executor.setCorePoolSize(threadPoolConfig.getCorePoolSize());
+//        executor.setMaxPoolSize(threadPoolConfig.getMaxPoolSize());
+//        executor.setQueueCapacity(threadPoolConfig.getQueueCapacity());
+//        executor.setKeepAliveSeconds(threadPoolConfig.getKeepAliveSeconds());
+//         // 拒绝策略
+//        executor.setThreadNamePrefix(threadPoolConfig.getPrefixName());
+//        // 拒绝策略
+//        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
+//        // 初始化
+//        executor.initialize();
+//        return executor;
+//    }
+//}

+ 5 - 1
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/medical/controller/ConsumableMaterialController.java

@@ -9,6 +9,8 @@ import java.io.UnsupportedEncodingException;
 import java.net.URLDecoder;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+
+import org.apache.poi.ss.formula.functions.T;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.system.query.QueryGenerator;
 import org.jeecg.common.util.oConvertUtils;
@@ -166,7 +168,9 @@ public class ConsumableMaterialController extends JeecgController<ConsumableMate
     */
     @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
     public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
-        return super.importExcel(request, response, ConsumableMaterial.class);
+        return consumableMaterialService.importExcel(request, response, ConsumableMaterial.class);
     }
 
+
+
 }

+ 2 - 2
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/medical/controller/MaterialItemsController.java

@@ -150,8 +150,8 @@ public class MaterialItemsController extends JeecgController<MaterialItems, IMat
     */
     @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
     public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
-//        return super.importExcel(request, response, MaterialItems.class);
-		return materialItemsService.importExcel(request, response);
+        return super.importExcel(request, response, MaterialItems.class);
+//		return materialItemsService.importExcel(request, response);
     }
 
 }

+ 33 - 27
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/medical/entity/ConsumableMaterial.java

@@ -32,73 +32,79 @@ import lombok.experimental.Accessors;
 public class ConsumableMaterial implements Serializable {
     private static final long serialVersionUID = 1L;
 
+    @Excel(name = "一级分类 (学科、  品类)", width = 15,orderNum = "1")
+    @ApiModelProperty(value = "一级分类")
+    private java.lang.String oneCategory;
+    @Excel(name = "二级分类 (用途、  品 目)", width = 15,orderNum = "2")
+    @ApiModelProperty(value = "二级分类")
+    private java.lang.String twoCategory;
+    @Excel(name = "三级分类 (部位、功能、  品种)", width = 15,orderNum = "3")
+    @ApiModelProperty(value = "三级分类")
+    private java.lang.String threeCategory;
+
+
+    /**规格*/
+    @Excel(name = "规格 (特征、参数)", width = 15,orderNum = "6")
+    @ApiModelProperty(value = "规格 (特征、参数)")
+    private java.lang.String regSpe;
+
+
 	/**主键ID*/
-	@TableId(type = IdType.ASSIGN_ID)
+	@TableId(type = IdType.AUTO)
     @ApiModelProperty(value = "主键ID")
     private java.lang.Integer id;
 	/**耗材名称*/
-	@Excel(name = "耗材名称", width = 15)
-    @ApiModelProperty(value = "耗材名称")
+	@Excel(name = "医保通用名", width = 15,orderNum = "4")
+    @ApiModelProperty(value = "医保通用名")
     private java.lang.String consumableName;
 	/**耗材编码*/
-	@Excel(name = "耗材编码", width = 15)
+	@Excel(name = "耗材编码", width = 15,orderNum = "0")
     @ApiModelProperty(value = "耗材编码")
     private java.lang.String consumableCode;
 
-    @Excel(name = "单价", width = 15)
+//    @Excel(name = "单价", width = 15)
     @ApiModelProperty(value = "单价")
     private BigDecimal price;
 
 	/**耗材版本*/
-	@Excel(name = "耗材版本", width = 15)
+//	@Excel(name = "耗材版本", width = 15)
     @ApiModelProperty(value = "耗材版本")
     private java.lang.String consumableVersion;
 	/**耗材材质*/
-	@Excel(name = "耗材材质", width = 15)
+	@Excel(name = "耗材材质", width = 15,orderNum = "5")
     @ApiModelProperty(value = "耗材材质")
     private java.lang.String consumableMaterial;
 	/**注册备案产品名称*/
-	@Excel(name = "注册备案产品名称", width = 15)
+//	@Excel(name = "注册备案产品名称", width = 15)
     @ApiModelProperty(value = "注册备案产品名称")
     private java.lang.String registeredProductName;
 	/**企业名称*/
-	@Excel(name = "企业名称", width = 15)
+	@Excel(name = "企业名称", width = 15,orderNum = "7")
     @ApiModelProperty(value = "企业名称")
     private java.lang.String companyName;
 	/**产品名称*/
-	@Excel(name = "产品名称", width = 15)
+//	@Excel(name = "产品名称", width = 15)
     @ApiModelProperty(value = "产品名称")
     private java.lang.String productName;
 	/**注册备案号*/
-	@Excel(name = "注册备案号", width = 15)
+//	@Excel(name = "注册备案号", width = 15)
     @ApiModelProperty(value = "注册备案号")
     private java.lang.String registrationNumber;
 	/**计量单位*/
-	@Excel(name = "计量单位", width = 15)
+//	@Excel(name = "计量单位", width = 15)
     @ApiModelProperty(value = "计量单位")
     private java.lang.String unit;
-	/**一级分类*/
-	@Excel(name = "一级分类", width = 15)
-    @ApiModelProperty(value = "一级分类")
-    private java.lang.String oneCategory;
-	/**二级分类*/
-	@Excel(name = "二级分类", width = 15)
-    @ApiModelProperty(value = "二级分类")
-    private java.lang.String twoCategory;
-	/**三级分类*/
-	@Excel(name = "三级分类", width = 15)
-    @ApiModelProperty(value = "三级分类")
-    private java.lang.String threeCategory;
+
 	/**说明*/
-	@Excel(name = "说明", width = 15)
+//	@Excel(name = "说明", width = 15)
     @ApiModelProperty(value = "说明")
     private java.lang.String description;
 	/**状态*/
-	@Excel(name = "状态", width = 15)
+//	@Excel(name = "状态", width = 15)
     @ApiModelProperty(value = "状态")
     private java.lang.String state;
 	/**版本号*/
-	@Excel(name = "版本号", width = 15)
+//	@Excel(name = "版本号", width = 15)
     @ApiModelProperty(value = "版本号")
     private java.lang.Integer revision;
 	/**创建人*/

+ 12 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/medical/service/IConsumableMaterialService.java

@@ -1,7 +1,18 @@
 package org.jeecg.modules.medical.service;
 
+import org.jeecg.common.api.vo.Result;
 import org.jeecg.modules.medical.entity.ConsumableMaterial;
 import com.baomidou.mybatisplus.extension.service.IService;
+import org.jeecgframework.poi.excel.ExcelImportUtil;
+import org.jeecgframework.poi.excel.entity.ImportParams;
+import org.springframework.web.multipart.MultipartFile;
+import org.springframework.web.multipart.MultipartHttpServletRequest;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
 
 /**
  * @Description: consumable_material
@@ -11,4 +22,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface IConsumableMaterialService extends IService<ConsumableMaterial> {
 
+    Result<?> importExcel(HttpServletRequest request, HttpServletResponse response, Class<ConsumableMaterial> consumableMaterialClass);
 }

+ 83 - 0
jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/medical/service/impl/ConsumableMaterialServiceImpl.java

@@ -1,11 +1,26 @@
 package org.jeecg.modules.medical.service.impl;
 
+import com.google.common.collect.Lists;
+import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.api.vo.Result;
 import org.jeecg.modules.medical.entity.ConsumableMaterial;
 import org.jeecg.modules.medical.mapper.ConsumableMaterialMapper;
 import org.jeecg.modules.medical.service.IConsumableMaterialService;
+import org.jeecgframework.poi.excel.ExcelImportUtil;
+import org.jeecgframework.poi.excel.entity.ImportParams;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.web.multipart.MultipartFile;
+import org.springframework.web.multipart.MultipartHttpServletRequest;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CountDownLatch;
 
 /**
  * @Description: consumable_material
@@ -14,6 +29,74 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  * @Version: V1.0
  */
 @Service
+@Slf4j
 public class ConsumableMaterialServiceImpl extends ServiceImpl<ConsumableMaterialMapper, ConsumableMaterial> implements IConsumableMaterialService {
 
+
+    /**
+     * 通过excel导入数据
+     *
+     * @param request
+     * @param response
+     * @return
+     */
+    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response, Class<ConsumableMaterial> consumableMaterialClass) {
+        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
+        Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
+        for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
+            // 获取上传文件对象
+            MultipartFile file = entity.getValue();
+            ImportParams params = new ImportParams();
+            params.setTitleRows(2);
+            params.setHeadRows(1);
+            params.setNeedSave(true);
+            try {
+                List<ConsumableMaterial> list = ExcelImportUtil.importExcel(file.getInputStream(), ConsumableMaterial.class, params);
+                List<List<ConsumableMaterial>> lists = Lists.partition(list, 1000);
+                CountDownLatch countDownLatch = new CountDownLatch(lists.size());
+                long startTime = System.currentTimeMillis();
+                lists.forEach(listSub -> executeAsync(listSub,  countDownLatch));
+                try {
+                    // 保证之前的所有的线程都执行完成,才会走下面的
+                    countDownLatch.await();
+                } catch (InterruptedException e) {
+                    log.error("阻塞异常:" + e.getMessage());
+                }
+                long endTime = System.currentTimeMillis();
+                log.info("共耗时:{} 秒", (endTime - startTime) / 1000);
+                return Result.ok("文件导入成功!数据行数:" + list.size());
+            } catch (Exception e) {
+                //update-begin-author:taoyan date:20211124 for: 导入数据重复增加提示
+                String msg = e.getMessage();
+                log.error(msg, e);
+                if(msg!=null && msg.indexOf("Duplicate entry")>=0){
+                    return Result.error("文件导入失败:有重复数据!");
+                }else{
+                    return Result.error("文件导入失败:" + e.getMessage());
+                }
+                //update-end-author:taoyan date:20211124 for: 导入数据重复增加提示
+            } finally {
+                try {
+                    file.getInputStream().close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+        return Result.error("文件导入失败!");
+    }
+
+
+    @Async("commonTaskAsyncPool")
+    public void executeAsync(List<ConsumableMaterial> list,  CountDownLatch countDownLatch) {
+        try {
+            log.info("start executeAsync");
+            // 异步线程需要做的事情
+            this.saveBatch(list);
+            log.info("end executeAsync");
+        } finally {
+            // 无论上面程序是否异常必须执行 countDown,否则 await 无法释放
+            countDownLatch.countDown();
+        }
+    }
 }

+ 11 - 3
jeecg-module-system/jeecg-system-start/src/main/resources/application-dev.yml

@@ -131,9 +131,9 @@ spring:
         connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000
       datasource:
         master:
-          url: jdbc:mysql://49.235.245.113:3306/medical?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
+          url: jdbc:mysql://124.220.224.184:3306/medical?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
           username: root
-          password: G@7NYpxIn%&*sxLOn%l
+          password: G@7NYpxInsxLOn%l
           driver-class-name: com.mysql.cj.jdbc.Driver
           # 多数据源配置
           #multi-datasource1:
@@ -144,7 +144,7 @@ spring:
   #redis 配置
   redis:
     database: 9
-    host: 49.235.245.113
+    host: 124.220.224.184
     port: 6379
     password: 'v!54GWsBB8yJ'
 #mybatis plus 设置
@@ -292,3 +292,11 @@ third-app:
       # appSecret
       client-secret: ??
       agent-id: ??
+
+cdr:
+  threadpool:
+    corePoolSize: 8 # 核心线程数
+    maxPoolSize: 20 # 设置最大线程数
+    keepAliveSeconds: 300 # 设置线程活跃时间
+    queueCapacity: 100 # 设置队列容量
+    prefixName: async-service- # 线程名称前缀

+ 3 - 3
jeecg-module-system/jeecg-system-start/src/main/resources/application-prod.yml

@@ -131,9 +131,9 @@ spring:
         connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000
       datasource:
         master:
-          url: jdbc:mysql://49.235.245.113:3306/medical?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
+          url: jdbc:mysql://120.220.224.184:3306/medical?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
           username: root
-          password: G@7NYpxIn%&*sxLOn%l
+          password: G@7NYpxInsxLOn%l
           driver-class-name: com.mysql.cj.jdbc.Driver
           # 多数据源配置
           #multi-datasource1:
@@ -144,7 +144,7 @@ spring:
   #redis 配置
   redis:
     database: 9
-    host: 49.235.245.113
+    host: 120.220.224.184
     port: 6379
     password: 'v!54GWsBB8yJ'
 #mybatis plus 设置