Commit fac23d8f85112bd547c60f19519571295d75e125

Authored by liquanyu
1 parent 530d00d06a

update

Showing 3 changed files with 87 additions and 22 deletions

platform-biz-service/src/main/java/com/lyms/platform/permission/service/impl/LisServiceImpl.java View file @ fac23d8
... ... @@ -9,12 +9,16 @@
9 9 import com.lyms.platform.permission.model.LisReportModel;
10 10 import com.lyms.platform.permission.model.LisReportQuery;
11 11 import com.lyms.platform.permission.service.LisService;
  12 +import com.lyms.platform.pojo.BasicConfig;
12 13 import org.apache.commons.collections.CollectionUtils;
13 14 import org.codehaus.jackson.type.TypeReference;
14 15 import org.springframework.beans.factory.annotation.Autowired;
15 16 import org.springframework.stereotype.Service;
16 17  
  18 +import java.util.ArrayList;
17 19 import java.util.List;
  20 +import java.util.concurrent.CountDownLatch;
  21 +import java.util.concurrent.Future;
18 22  
19 23  
20 24 @Service("lisService")
21 25  
22 26  
23 27  
... ... @@ -25,26 +29,31 @@
25 29  
26 30 @Override
27 31 public BaseResponse saveLisData(final List<LisReportModel> lisList) {
28   -
29 32 try {
30 33 System.out.println("saveLis data size = "+ lisList.size());
31 34 if (CollectionUtils.isNotEmpty(lisList))
32 35 {
33   - new Thread(new Runnable() {
34   - @Override
35   - public void run() {
36   - for(LisReportModel model : lisList)
37   - {
38   - List<LisReportModel> dbLis = masterLisMapper.queryLisDataByModel(model);
39   - if (CollectionUtils.isEmpty(dbLis))
40   - {
41   - masterLisMapper.saveLisData(model);
42   - }
43   -
44   - }
  36 + int batchSize = 10;
  37 + //线程数
  38 + int threadCount = lisList.size()%batchSize == 0 ? lisList.size()/batchSize : lisList.size()/batchSize+1;
  39 + System.out.println("threadCount = "+ threadCount);
  40 + CountDownLatch countDownLatch = new CountDownLatch(threadCount);
  41 + int end = 0;
  42 + for (int i = 0; i < lisList.size(); i += batchSize) {
  43 + end = (end + batchSize);
  44 + if (end > lisList.size()) {
  45 + end = lisList.size();
45 46 }
46   - },"saveLisDataThread").start();
  47 + List<LisReportModel> models = lisList.subList(i, end);
  48 + LisSaveTask lis =new LisSaveTask(countDownLatch,masterLisMapper,models);
  49 + Thread t1=new Thread(lis);
  50 + t1.start();
  51 + System.out.println("spit end");
  52 + }
  53 + countDownLatch.await();
47 54  
  55 + System.out.println("exce end");
  56 +
48 57 }
49 58 return new BaseResponse().setErrorcode(ErrorCodeConstants.SUCCESS).setErrormsg("成功");
50 59 }
... ... @@ -53,6 +62,33 @@
53 62 return new BaseResponse().setErrorcode(ErrorCodeConstants.SYSTEM_ERROR).setErrormsg(ErrorCodeConstants.SYSTEM_ERROR_DESCRIPTION);
54 63 }
55 64  
  65 +// try {
  66 +// System.out.println("saveLis data size = "+ lisList.size());
  67 +// if (CollectionUtils.isNotEmpty(lisList))
  68 +// {
  69 +// new Thread(new Runnable() {
  70 +// @Override
  71 +// public void run() {
  72 +// for(LisReportModel model : lisList)
  73 +// {
  74 +// List<LisReportModel> dbLis = masterLisMapper.queryLisDataByModel(model);
  75 +// if (CollectionUtils.isEmpty(dbLis))
  76 +// {
  77 +// masterLisMapper.saveLisData(model);
  78 +// }
  79 +//
  80 +// }
  81 +// }
  82 +// },"saveLisDataThread").start();
  83 +//
  84 +// }
  85 +// return new BaseResponse().setErrorcode(ErrorCodeConstants.SUCCESS).setErrormsg("成功");
  86 +// }
  87 +// catch (Exception e)
  88 +// {
  89 +// return new BaseResponse().setErrorcode(ErrorCodeConstants.SYSTEM_ERROR).setErrormsg(ErrorCodeConstants.SYSTEM_ERROR_DESCRIPTION);
  90 +// }
  91 +
56 92 }
57 93  
58 94 @Override
... ... @@ -87,6 +123,35 @@
87 123 @Override
88 124 public int saveLisDataTemp(LisReportModel models) {
89 125 return masterLisMapper.saveLisDataTemp(models);
  126 + }
  127 +
  128 +
  129 + public class LisSaveTask implements Runnable {
  130 +
  131 + private CountDownLatch countDownLatch;
  132 + private MasterLisMapper masterLisMapper;
  133 + private List<LisReportModel> lisList;
  134 + private LisSaveTask(CountDownLatch countDownLatch,
  135 + MasterLisMapper masterLisMapper,
  136 + List<LisReportModel> lisList)
  137 + {
  138 + this.lisList = lisList;
  139 + this.masterLisMapper = masterLisMapper;
  140 + this.countDownLatch = countDownLatch;
  141 + }
  142 +
  143 + @Override
  144 + public void run() {
  145 + for(LisReportModel model : lisList)
  146 + {
  147 + List<LisReportModel> dbLis = masterLisMapper.queryLisDataByModel(model);
  148 + if (CollectionUtils.isEmpty(dbLis))
  149 + {
  150 + masterLisMapper.saveLisData(model);
  151 + }
  152 + }
  153 + countDownLatch.countDown();
  154 + }
90 155 }
91 156 }
platform-operate-api/src/main/java/com/lyms/platform/operate/web/Test.java View file @ fac23d8
... ... @@ -82,13 +82,13 @@
82 82 // }
83 83 // }
84 84  
85   -
86   - String sql = "INSERT INTO LIS_REPORT_TBL( LIS_ID, TITLE) VALUES ('122', 'bbbb')";
87   - sql = sql.replaceFirst("\\(","(ID,");
88   -
89   -
90   - sql = sql.substring(0,sql.lastIndexOf("(")+1)+"11212,"+sql.substring(sql.lastIndexOf("(")+1,sql.length());
91   - System.out.println(sql);
  85 + System.out.println(39/20);
  86 +// String sql = "INSERT INTO LIS_REPORT_TBL( LIS_ID, TITLE) VALUES ('122', 'bbbb')";
  87 +// sql = sql.replaceFirst("\\(","(ID,");
  88 +//
  89 +//
  90 +// sql = sql.substring(0,sql.lastIndexOf("(")+1)+"11212,"+sql.substring(sql.lastIndexOf("(")+1,sql.length());
  91 +// System.out.println(sql);
92 92  
93 93 }
94 94 }
platform-operate-api/src/main/resources/config.properties View file @ fac23d8
... ... @@ -28,7 +28,7 @@
28 28 area_count_url=119.90.57.26:1522
29 29  
30 30 #同步mysql数据到各个区域的地址,多个用逗号隔开 如:https://area-qhd-api.healthbaby.com.cn:18019/syncMysqlData,https://area-dz-api.healthbaby.com.cn:12356/syncMysqlData
31   -sync_mysql_data_url=
  31 +sync_mysql_data_url=https://dev-rp-api.healthbaby.com.cn/syncMysqlData
32 32  
33 33 #数据源相关配置
34 34 jdbc.0.driver=oracle.jdbc.driver.OracleDriver