Commit caff71a30228330efb812afa23f044f181bd2f10

Authored by wxy
1 parent cb71a275

数据分析优化

juvenile-prosecution-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/controller/AnalyzeController.java
... ... @@ -74,6 +74,7 @@ public class AnalyzeController extends JeecgController<GaDemographic, IGaDemogra
74 74 private final List<MrSchool> resultSchools = new ArrayList<>();//分析后学籍的信息
75 75 private static final int corePoolSize = Runtime.getRuntime().availableProcessors();
76 76 private static final ThreadPoolExecutor executor = new ThreadPoolExecutor(corePoolSize, corePoolSize + 1, 10L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(1000));
  77 + private String random_number="00000000";
77 78  
78 79  
79 80 @AutoLog(value = "来源数据管理-分页列表查询")
... ... @@ -90,13 +91,13 @@ public class AnalyzeController extends JeecgController&lt;GaDemographic, IGaDemogra
90 91 System.out.println("未成年人数据批量新增总条数" + resultMinor.size());
91 92 System.out.println("学籍信息数据批量新增总条数" + resultSchools.size());
92 93 long startTime2 = System.currentTimeMillis();
93   - minorService.insertBatch(resultMinor,departs);
  94 + minorService.insertBatch(resultMinor);
94 95 System.out.println("未成年人数据批量新增所用时间" + (System.currentTimeMillis() - startTime2) / 1000 + "秒");
95 96 long startTime1 = System.currentTimeMillis();
96   - familyService.insertBatch(resultFamily,departs);
  97 + familyService.insertBatch(resultFamily);
97 98 System.out.println("家庭成员数据批量新增所用时间" + (System.currentTimeMillis() - startTime1) / 1000 + "秒");
98 99 long startTime3 = System.currentTimeMillis();
99   - schoolService.insertBatch(resultSchools,departs);
  100 + schoolService.insertBatch(resultSchools);
100 101 System.out.println("学籍信息入库时间" + (System.currentTimeMillis() - startTime3) / 1000 + "秒");
101 102 long startTime4 = System.currentTimeMillis();
102 103 getSourceData();
... ... @@ -114,53 +115,52 @@ public class AnalyzeController extends JeecgController&lt;GaDemographic, IGaDemogra
114 115 try {
115 116 System.out.println("开始数据分析");
116 117 long startTime = System.currentTimeMillis();
117   - ExecutorService pool = Executors.newFixedThreadPool(50);
118   - CompletableFuture<Map<String, GaPunishVo>> f1 = CompletableFuture.supplyAsync(() -> gaPunishService.queryAll(), executor);
119   - CompletableFuture<List<SpecialStudentVo>> f2 = CompletableFuture.supplyAsync(() -> specialStudentService.queryList(), executor);
120   - CompletableFuture<List<String>> f3 = CompletableFuture.supplyAsync(() -> mzOrphanService.getIdentityS(), executor);
121   - CompletableFuture<List<String>> f4 = CompletableFuture.supplyAsync(() -> mzUnsupportedService.getIdentityS(), executor);
122   - CompletableFuture<List<String>> f5 = CompletableFuture.supplyAsync(() -> mzLeftBehindChildrenService.getIdentityS(), executor);
123   - CompletableFuture<List<String>> f6 = CompletableFuture.supplyAsync(() -> mzAdoptionService.getIdentityS(), executor);
124   - CompletableFuture<List<MrSchool>> f7 = CompletableFuture.supplyAsync(() -> highSchoolService.getList(), executor);
125   - CompletableFuture<List<MrSchool>> f8 = CompletableFuture.supplyAsync(() -> primarySchoolService.getList(), executor);
126   -// CompletableFuture<Map<String,String>> f9 = CompletableFuture.supplyAsync(() -> gaDemographicService.getIdentityS(), executor);
  118 +// ExecutorService pool = Executors.newFixedThreadPool(8);
  119 +// CompletableFuture<Map<String, GaPunishVo>> f1 = CompletableFuture.supplyAsync(() -> gaPunishService.queryAll(), executor);
  120 +// CompletableFuture<List<SpecialStudentVo>> f2 = CompletableFuture.supplyAsync(() -> specialStudentService.queryList(), executor);
  121 +// CompletableFuture<List<String>> f3 = CompletableFuture.supplyAsync(() -> mzOrphanService.getIdentityS(), executor);
  122 +// CompletableFuture<List<String>> f4 = CompletableFuture.supplyAsync(() -> mzUnsupportedService.getIdentityS(), executor);
  123 +// CompletableFuture<List<String>> f5 = CompletableFuture.supplyAsync(() -> mzLeftBehindChildrenService.getIdentityS(), executor);
  124 +// CompletableFuture<List<String>> f6 = CompletableFuture.supplyAsync(() -> mzAdoptionService.getIdentityS(), executor);
  125 +// CompletableFuture<List<MrSchool>> f7 = CompletableFuture.supplyAsync(() -> highSchoolService.getList(), executor);
  126 +// CompletableFuture<List<MrSchool>> f8 = CompletableFuture.supplyAsync(() -> primarySchoolService.getList(), executor);
127 127 //行政处罚数据
128   -// Map<String,GaPunishVo> gaPunishVos = gaPunishService.queryAll();
129   - Map<String, GaPunishVo> gaPunishVos = new HashMap<>();
130   - gaPunishVos.putAll(f1.get());
131   -// List<SpecialStudentVo> specialStudentVos = specialStudentService.queryList();
132   - List<SpecialStudentVo> specialStudentVos = new ArrayList<>();
133   - specialStudentVos.addAll(f2.get());
  128 + Map<String,GaPunishVo> gaPunishVos = gaPunishService.queryAll();
  129 +// Map<String, GaPunishVo> gaPunishVos = new HashMap<>();
  130 +// gaPunishVos.putAll(f1.get());
  131 + List<SpecialStudentVo> specialStudentVos = specialStudentService.queryList();
  132 +// List<SpecialStudentVo> specialStudentVos = new ArrayList<>();
  133 +// specialStudentVos.addAll(f2.get());
134 134 //孤儿数据
135   -// List<String> mzOrphans = mzOrphanService.getIdentityS();
136   - List<String> mzOrphans = new ArrayList<>();
137   - mzOrphans.addAll(f3.get());
  135 + List<String> mzOrphans = mzOrphanService.getIdentityS();
  136 +// List<String> mzOrphans = new ArrayList<>();
  137 +// mzOrphans.addAll(f3.get());
138 138 //无人抚养
139   -// List<String> mzUnsupporteds = mzUnsupportedService.getIdentityS();
140   - List<String> mzUnsupporteds = new ArrayList<>();
141   - mzUnsupporteds.addAll(f4.get());
  139 + List<String> mzUnsupporteds = mzUnsupportedService.getIdentityS();
  140 +// List<String> mzUnsupporteds = new ArrayList<>();
  141 +// mzUnsupporteds.addAll(f4.get());
142 142 //留守儿童
143   -// List<String> mzLeftBehinds =mzLeftBehindChildrenService.getIdentityS();
144   - List<String> mzLeftBehinds = new ArrayList<>();
145   - mzLeftBehinds.addAll(f5.get());
  143 + List<String> mzLeftBehinds =mzLeftBehindChildrenService.getIdentityS();
  144 +// List<String> mzLeftBehinds = new ArrayList<>();
  145 +// mzLeftBehinds.addAll(f5.get());
146 146 //领养
147   -// List<String> mzAdoptions =mzAdoptionService.getIdentityS();
148   - List<String> mzAdoptions = new ArrayList<>();
149   - mzAdoptions.addAll(f6.get());
  147 + List<String> mzAdoptions =mzAdoptionService.getIdentityS();
  148 +// List<String> mzAdoptions = new ArrayList<>();
  149 +// mzAdoptions.addAll(f6.get());
150 150 //获取初高中学生信息
151   -// List<MrSchool> highSchools = highSchoolService.getList();
152   - List<MrSchool> highSchools = new ArrayList<>();
153   - highSchools.addAll(f7.get());
  151 + List<MrSchool> highSchools = highSchoolService.getList();
  152 +// List<MrSchool> highSchools = new ArrayList<>();
  153 +// highSchools.addAll(f7.get());
154 154 //获取幼小学生信息
155   -// List<MrSchool> primarySchools = primarySchoolService.getList();
156   - List<MrSchool> primarySchools = new ArrayList<>();
157   - primarySchools.addAll(f8.get());
  155 + List<MrSchool> primarySchools = primarySchoolService.getList();
  156 +// List<MrSchool> primarySchools = new ArrayList<>();
  157 +// primarySchools.addAll(f8.get());
158 158 //人口基本信息小于18岁
159 159 // Map<String,String> gaDemographics =gaDemographicService.getIdentityS();
160 160 // Map<String,String> gaDemographics =new HashMap<>();
161 161 // gaDemographics.putAll(f9.get());
162 162 //关闭线程池
163   - pool.shutdown();
  163 +// pool.shutdown();
164 164 Map<String, String> gaDemographics = gaDemographicService.getIdentityS();
165 165 System.out.println("线程池查询用时" + (System.currentTimeMillis() - startTime) / 1000 + "秒");
166 166 long startTime1 = System.currentTimeMillis();
... ... @@ -311,7 +311,7 @@ public class AnalyzeController extends JeecgController&lt;GaDemographic, IGaDemogra
311 311 //初高中学生信息和人口基本信息的交集
312 312 List<MrSchool> highSchoolIntersection = new ArrayList<>();
313 313 if (oConvertUtils.isNotEmpty(highSchools)) {
314   - highSchools.parallelStream().forEach(h -> {
  314 + highSchools.stream().forEach(h -> {
315 315 if (oConvertUtils.isNotEmpty(gaDemographics) && oConvertUtils.isNotEmpty(gaDemographics.get(h.getIdentity()))) {
316 316 if (h.getIdentity().equals(gaDemographics.get(h.getIdentity()))) {
317 317 //交集
... ... @@ -355,7 +355,7 @@ public class AnalyzeController extends JeecgController&lt;GaDemographic, IGaDemogra
355 355 //幼小学生信息和人口基本信息的交集
356 356 List<MrSchool> primarySchoolIntersection = new ArrayList<>();
357 357 if (oConvertUtils.isNotEmpty(primarySchools)) {
358   - primarySchools.parallelStream().forEach(p -> {
  358 + primarySchools.stream().forEach(p -> {
359 359 if (oConvertUtils.isNotEmpty(gaDemographics) && oConvertUtils.isNotEmpty(p) && oConvertUtils.isNotEmpty(gaDemographics.get(p.getIdentity()))) {
360 360 if (p.getIdentity().equals(gaDemographics.get(p.getIdentity()))) {
361 361 //交集
... ... @@ -391,8 +391,8 @@ public class AnalyzeController extends JeecgController&lt;GaDemographic, IGaDemogra
391 391 System.out.println("处理有人口基本信息但没有学籍信息的数据开始***********************" + gaDemographicDifference.size());
392 392 Map<String, Minor> minorMap = new HashMap<>();
393 393 if (oConvertUtils.isNotEmpty(gaDemographicDifference) && oConvertUtils.isNotEmpty(gaHouseholds)) {
394   - gaDemographicDifference.parallelStream().forEach(idCard -> {
395   - if (oConvertUtils.isNotEmpty(idCard) && oConvertUtils.isNotEmpty(gaHouseholds.get(idCard))) {
  394 + gaDemographicDifference.stream().forEach(idCard -> {
  395 + if (oConvertUtils.isNotEmpty(idCard) && oConvertUtils.isNotEmpty(gaHouseholds.get(idCard)) && IDNumberUtil.checkID(idCard)) {
396 396 Minor minor = new Minor();
397 397 minor.setSchool(Minor.SCHOOL_STATUS_YES);
398 398 minor.setName(gaHouseholds.get(idCard).getName());
... ... @@ -440,7 +440,7 @@ public class AnalyzeController extends JeecgController&lt;GaDemographic, IGaDemogra
440 440 System.out.println("交集数据里的所属单位开始" + (System.currentTimeMillis() - startTime) / 1000);
441 441 if (oConvertUtils.isNotEmpty(intersection) && oConvertUtils.isNotEmpty(departs) && departs.size() > 0) {
442 442 for (SysDepart d : departs) {
443   - intersection.parallelStream().forEach(i -> {
  443 + intersection.stream().forEach(i -> {
444 444 if (oConvertUtils.isNotEmpty(i) && oConvertUtils.isNotEmpty(i.getSchool()) && oConvertUtils.isNotEmpty(d) && oConvertUtils.isNotEmpty(d.getCommonCode())) {
445 445 if (d.getCommonCode().contains(i.getSchool())) {
446 446 i.setSysOrgCode(d.getOrgCode());
... ... @@ -452,8 +452,8 @@ public class AnalyzeController extends JeecgController&lt;GaDemographic, IGaDemogra
452 452 System.out.println("交集数据里的所属单位结束总数"+intersection.size()+"交集数据里的所属单位结束" + (System.currentTimeMillis() - startTime) / 1000);
453 453 Date creatDate = new Date();
454 454 if (oConvertUtils.isNotEmpty(intersection)) {
455   - intersection.parallelStream().forEach(i -> {
456   - if (oConvertUtils.isNotEmpty(i) && oConvertUtils.isNotEmpty(i.getIdentity())) {
  455 + intersection.stream().forEach(i -> {
  456 + if (oConvertUtils.isNotEmpty(i) && oConvertUtils.isNotEmpty(i.getIdentity()) && IDNumberUtil.checkID(i.getIdentity())) {
457 457 Minor minor = new Minor();
458 458 //身份证号
459 459 String idCard = i.getIdentity();
... ... @@ -507,9 +507,9 @@ public class AnalyzeController extends JeecgController&lt;GaDemographic, IGaDemogra
507 507 Date creatTime = new Date();
508 508 if (oConvertUtils.isNotEmpty(difference) && oConvertUtils.isNotEmpty(departs) && departs.size() > 0) {
509 509 for (SysDepart d : departs) {
510   - difference.parallelStream().forEach(m -> {
  510 + difference.stream().forEach(m -> {
511 511 Minor minor = new Minor();
512   - if (oConvertUtils.isNotEmpty(m)) {
  512 + if (oConvertUtils.isNotEmpty(m) && oConvertUtils.isNotEmpty(m.getIdentity()) && IDNumberUtil.checkID(m.getIdentity())) {
513 513 if (oConvertUtils.isNotEmpty(d) && oConvertUtils.isNotEmpty(d.getCommonCode()) && oConvertUtils.isNotEmpty(m.getSchool())) {
514 514 if (d.getCommonCode().contains(m.getSchool()) && oConvertUtils.isNotEmpty(minorMap.get(m.getIdentity()))) {
515 515 minor.setSysOrgCode(d.getOrgCode());
... ... @@ -692,9 +692,24 @@ public class AnalyzeController extends JeecgController&lt;GaDemographic, IGaDemogra
692 692 //户号-与监护人
693 693 Map<String, Family> guardians = new HashMap<>();
694 694 if (oConvertUtils.isNotEmpty(gaHouseholds)) {
  695 + int i=0;
695 696 for (Map.Entry<String, Family> m : gaHouseholds.entrySet()) {
696 697 String mapKey = m.getKey();
697 698 Family family = m.getValue();
  699 + if (oConvertUtils.isNotEmpty(family)) {
  700 + i=i+1;
  701 + if (oConvertUtils.isNotEmpty(gaPunishVos) && oConvertUtils.isNotEmpty(gaPunishVos.get(mapKey))) {
  702 + family.setCrime(Family.IS_CRIME);
  703 + if (oConvertUtils.isNotEmpty(gaPunishVos.get(mapKey).getAjmc())) {
  704 + family.setOther(gaPunishVos.get(mapKey).getAjmc());
  705 + }
  706 + if (oConvertUtils.isNotEmpty(gaPunishVos.get(mapKey).getSldwmc())) {
  707 + family.setReason(gaPunishVos.get(mapKey).getSldwmc());
  708 + }
  709 + } else {
  710 + family.setCrime(Family.IS_NOT_CRIME);
  711 + }
  712 + }
698 713 if (oConvertUtils.isNotEmpty(family) && oConvertUtils.isNotEmpty(family.getHouseholdNum()) && oConvertUtils.isNotEmpty(family.getIdentity())) {
699 714 String houseNum = family.getHouseholdNum();
700 715 List<Family> list = new ArrayList<>();
... ... @@ -715,19 +730,6 @@ public class AnalyzeController extends JeecgController&lt;GaDemographic, IGaDemogra
715 730 }
716 731 familyMaps.put(houseNum, list);
717 732 }
718   - if (oConvertUtils.isNotEmpty(family)) {
719   - if (oConvertUtils.isNotEmpty(gaPunishVos) && oConvertUtils.isNotEmpty(gaPunishVos.get(mapKey))) {
720   - family.setCrime(Family.IS_CRIME);
721   - if (oConvertUtils.isNotEmpty(gaPunishVos.get(mapKey).getAjmc())) {
722   - family.setOther(gaPunishVos.get(mapKey).getAjmc());
723   - }
724   - if (oConvertUtils.isNotEmpty(gaPunishVos.get(mapKey).getSldwmc())) {
725   - family.setReason(gaPunishVos.get(mapKey).getSldwmc());
726   - }
727   - } else {
728   - family.setCrime(Family.IS_NOT_CRIME);
729   - }
730   - }
731 733 }
732 734 }
733 735  
... ...
juvenile-prosecution-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/entity/Family.java
... ... @@ -30,10 +30,9 @@ public class Family implements Serializable {
30 30 public static final Integer IS_CRIME=1;//是
31 31 public static final Integer IS_NOT_CRIME=0;//否
32 32  
33   - /**主键*/
34   - @TableId(type = IdType.ASSIGN_ID)
  33 + @TableId(type = IdType.AUTO)
35 34 @ApiModelProperty(value = "主键")
36   - private String id;
  35 + private Integer id;
37 36 /**创建人*/
38 37 @ApiModelProperty(value = "创建人")
39 38 private String createBy;
... ...
juvenile-prosecution-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/entity/MrSchool.java
... ... @@ -32,7 +32,7 @@ public class MrSchool implements Serializable {
32 32 private static final long serialVersionUID = 1L;
33 33  
34 34 /**主键*/
35   - @TableId(type = IdType.ASSIGN_ID)
  35 + @TableId(type = IdType.ASSIGN_ID)
36 36 @ApiModelProperty(value = "主键")
37 37 private String id;
38 38 /**创建人*/
... ...
juvenile-prosecution-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/mapper/xml/PrimarySchoolMapper.xml
... ... @@ -5,17 +5,17 @@
5 5 <resultMap id="mrSchool" type="org.jeecg.modules.system.entity.MrSchool">
6 6 <result column="name" property="name"/>
7 7 <result column="identity" property="identity"/>
8   - <result column="class_name" property="className"/>
  8 + <result column="className" property="className"/>
9 9 <result column="address" property="address"/>
10 10 <result column="school" property="school"/>
11 11 <result column="phone" property="phone"/>
12   - <result column="admission_date" property="admissionDate"/>
13   - <result column="member_one" property="memberOne"/>
14   - <result column="connect_one" property="connectOne"/>
15   - <result column="phone_one" property="phoneOne"/>
16   - <result column="member_two" property="memberTwo"/>
17   - <result column="connect_two" property="connectTwo"/>
18   - <result column="phone_two" property="phoneTwo"/>
  12 + <result column="admissionDate" property="admissionDate"/>
  13 + <result column="memberOne" property="memberOne"/>
  14 + <result column="connectOne" property="connectOne"/>
  15 + <result column="phoneOne" property="phoneOne"/>
  16 + <result column="memberTwo" property="memberTwo"/>
  17 + <result column="connectTwo" property="connectTwo"/>
  18 + <result column="phoneTwo" property="phoneTwo"/>
19 19 </resultMap>
20 20  
21 21 <select id="getList" resultMap="mrSchool">
... ...
juvenile-prosecution-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/service/IFamilyService.java
... ... @@ -18,5 +18,5 @@ public interface IFamilyService extends IService&lt;Family&gt; {
18 18 public List<Family> selectByMainId(String mainId);
19 19  
20 20  
21   - public Integer insertBatch(List<Family> list,List<SysDepart> departs);
  21 + public Integer insertBatch(List<Family> list);
22 22 }
... ...
juvenile-prosecution-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/service/IMinorService.java
... ... @@ -40,5 +40,5 @@ public interface IMinorService extends IService&lt;Minor&gt; {
40 40 public void delBatchMain (Collection<? extends Serializable> idList);
41 41  
42 42  
43   - public Integer insertBatch(List<Minor> list,List<SysDepart> departs);
  43 + public Integer insertBatch(List<Minor> list);
44 44 }
... ...
juvenile-prosecution-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/service/IMrSchoolService.java
... ... @@ -13,5 +13,5 @@ import java.util.List;
13 13 * @Version: V1.0
14 14 */
15 15 public interface IMrSchoolService extends IService<MrSchool> {
16   - public Integer insertBatch(List<MrSchool> list,List<SysDepart> departs);
  16 + public Integer insertBatch(List<MrSchool> list);
17 17 }
... ...
juvenile-prosecution-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/service/impl/FamilyServiceImpl.java
1 1 package org.jeecg.modules.system.service.impl;
2 2  
  3 +import org.jeecg.common.util.oConvertUtils;
3 4 import org.jeecg.modules.system.entity.Family;
4 5 import org.jeecg.modules.system.entity.Minor;
5 6 import org.jeecg.modules.system.entity.SysDepart;
... ... @@ -19,6 +20,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
19 20 import org.springframework.beans.factory.annotation.Autowired;
20 21 import org.springframework.transaction.TransactionDefinition;
21 22 import org.springframework.transaction.TransactionStatus;
  23 +import org.springframework.transaction.annotation.Transactional;
22 24  
23 25 import javax.annotation.Resource;
24 26  
... ... @@ -44,38 +46,49 @@ public class FamilyServiceImpl extends ServiceImpl&lt;FamilyMapper, Family&gt; impleme
44 46 public List<Family> selectByMainId(String mainId) {
45 47 return familyMapper.selectByMainId(mainId);
46 48 }
47   - //分段大小
48   - private int splitSize = 100000;
  49 +
  50 + private Integer random_number=00000000;
  51 +
49 52 /**
50 53 * 批量新增
51 54 * @param list
52 55 * @return
53 56 */
54 57 @Override
55   - public Integer insertBatch(List<Family> list,List<SysDepart> departs) {
  58 + @Transactional
  59 + public Integer insertBatch(List<Family> list) {
  60 +// if(oConvertUtils.isNotEmpty(list)){
  61 +// for(int i=0;i<list.size();i++){
  62 +// String id=System.currentTimeMillis()+String.valueOf((random_number+i));
  63 +// System.out.println(id);
  64 +// list.get(i).setId(id);
  65 +// }
  66 +// }
56 67 updateStudentWithThreads(list);
57 68 return list.size();
58 69 }
59 70 private void addBatch(List<Family> list, CountDownLatch threadLatch){
60   - TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
  71 +// TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
61 72 System.out.println("子线程:" + Thread.currentThread().getName());
62 73 try {
63 74 list.forEach(s -> {
64   - String newTeacher = "TNO_" + new Random().nextInt(100);
65   - familyMapper.insert(s);
  75 + if(oConvertUtils.isNotEmpty(s)){
  76 + familyMapper.insert(s);
  77 + }
66 78 });
67   - dataSourceTransactionManager.commit(transactionStatus);
  79 +// familyMapper.insertBatch(list);
  80 +// dataSourceTransactionManager.commit(transactionStatus);
68 81 threadLatch.countDown();
69 82 } catch (Throwable e) {
70 83 e.printStackTrace();
71   - dataSourceTransactionManager.rollback(transactionStatus);
  84 +// dataSourceTransactionManager.rollback(transactionStatus);
72 85 }
73 86 }
74 87  
75 88  
76 89 public void updateStudentWithThreads(List<Family> list) {
77 90 // 线程数量
78   - final Integer threadCount = 1;
  91 + final Integer threadCount = 10;
79 92  
80 93 //每个线程处理的数据量
81 94 final Integer dataPartionLength = (list.size() + threadCount - 1) / threadCount;
... ...
juvenile-prosecution-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/service/impl/GaHouseholdServiceImpl.java
... ... @@ -36,7 +36,7 @@ public class GaHouseholdServiceImpl extends ServiceImpl&lt;GaHouseholdMapper, GaHou
36 36 System.out.println("数据查询时间" + (System.currentTimeMillis() - startTime) / 1000 + "秒");
37 37 long startTime2 = System.currentTimeMillis();
38 38 if (oConvertUtils.isNotEmpty(families)) {
39   - families.parallelStream().forEach(g -> {
  39 + families.stream().forEach(g -> {
40 40 if (oConvertUtils.isNotEmpty(g) && oConvertUtils.isNotEmpty(g.getIdentity())) {
41 41 familyMap.put(g.getIdentity(), g);
42 42 }
... ...
juvenile-prosecution-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/service/impl/MinorServiceImpl.java
... ... @@ -2,6 +2,7 @@ package org.jeecg.modules.system.service.impl;
2 2  
3 3 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
4 4 import javassist.bytecode.analysis.Executor;
  5 +import org.jeecg.common.util.oConvertUtils;
5 6 import org.jeecg.modules.system.entity.Family;
6 7 import org.jeecg.modules.system.entity.Minor;
7 8 import org.jeecg.modules.system.entity.SysDepart;
... ... @@ -47,9 +48,7 @@ public class MinorServiceImpl extends ServiceImpl&lt;MinorMapper, Minor&gt; implements
47 48 @Resource
48 49 private TransactionDefinition transactionDefinition;
49 50  
50   -
51   - //分段大小
52   - private int splitSize = 100000;
  51 + private Integer random_number=00000000;
53 52  
54 53 @Override
55 54 @Transactional
... ... @@ -120,54 +119,41 @@ public class MinorServiceImpl extends ServiceImpl&lt;MinorMapper, Minor&gt; implements
120 119 }
121 120  
122 121 @Override
123   - public Integer insertBatch(List<Minor> list,List<SysDepart> departs) {
  122 + @Transactional
  123 + public Integer insertBatch(List<Minor> list) {
  124 + if(oConvertUtils.isNotEmpty(list)){
  125 + for(int i=0;i<list.size();i++){
  126 + String id=System.currentTimeMillis()+String.valueOf((random_number+i));
  127 + list.get(i).setId(id);
  128 + }
  129 + }
124 130 updateStudentWithThreads(list);
125 131 return list.size();
126 132 }
127 133  
128   - /**
129   - * 将list集合平均分成几等份
130   - *
131   - * @param num 分的份数
132   - * @param list 需要分的集合
133   - */
134   - private List splitList(List list, Integer num) {
135   - int listSize = list.size(); //list 长度
136   - List<List> splitLists = new ArrayList<>();
137   - List stringlist = new ArrayList<>();
138   - for ( int i = 0; i < listSize; i++ ) {
139   - stringlist.add(list.get(i));
140   - if ( ((i + 1) % num == 0) || (i + 1 == listSize) ) {
141   - splitLists.add(stringlist);
142   - stringlist = new ArrayList<>();
143   - }
144   - }
145   - return splitLists;
146   - }
147 134  
148 135 private void addBatch(List<Minor> list, CountDownLatch threadLatch){
149   - TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
  136 +// TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
150 137 System.out.println("子线程:" + Thread.currentThread().getName());
151 138 try {
152 139 list.forEach(s -> {
153   - // 更新教师信息
154   - // String teacher = s.getTeacher();
155   - String newTeacher = "TNO_" + new Random().nextInt(100);
156   -// s.setTeacher(newTeacher);
157   - minorMapper.insert(s);
  140 + if(oConvertUtils.isNotEmpty(s)){
  141 + minorMapper.insert(s);
  142 + }
158 143 });
159   - dataSourceTransactionManager.commit(transactionStatus);
  144 +// minorMapper.insertBatch(list);
  145 +// dataSourceTransactionManager.commit(transactionStatus);
160 146 threadLatch.countDown();
161 147 } catch (Throwable e) {
162 148 e.printStackTrace();
163   - dataSourceTransactionManager.rollback(transactionStatus);
  149 +// dataSourceTransactionManager.rollback(transactionStatus);
164 150 }
165 151 }
166 152  
167 153  
168 154 public void updateStudentWithThreads(List<Minor> list) {
169 155 // 线程数量
170   - final Integer threadCount = 1;
  156 + final Integer threadCount = 10;
171 157  
172 158 //每个线程处理的数据量
173 159 final Integer dataPartionLength = (list.size() + threadCount - 1) / threadCount;
... ...
juvenile-prosecution-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/service/impl/MrSchoolServiceImpl.java
1 1 package org.jeecg.modules.system.service.impl;
2 2  
  3 +import org.jeecg.common.util.oConvertUtils;
3 4 import org.jeecg.modules.system.entity.Minor;
4 5 import org.jeecg.modules.system.entity.MrSchool;
5 6 import org.jeecg.modules.system.entity.SysDepart;
... ... @@ -11,6 +12,7 @@ import org.springframework.stereotype.Service;
11 12 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
12 13 import org.springframework.transaction.TransactionDefinition;
13 14 import org.springframework.transaction.TransactionStatus;
  15 +import org.springframework.transaction.annotation.Transactional;
14 16  
15 17 import javax.annotation.Resource;
16 18 import java.util.ArrayList;
... ... @@ -39,58 +41,48 @@ public class MrSchoolServiceImpl extends ServiceImpl&lt;MrSchoolMapper, MrSchool&gt; i
39 41 @Resource
40 42 private TransactionDefinition transactionDefinition;
41 43  
42   - //分段大小
43   - private int splitSize = 100000;
  44 + private Integer random_number=00000000;
  45 +
44 46  
45 47 @Override
46   - public Integer insertBatch(List<MrSchool> list,List<SysDepart> departs) {
  48 + @Transactional
  49 + public Integer insertBatch(List<MrSchool> list) {
  50 + if(oConvertUtils.isNotEmpty(list)){
  51 + for(int i=0;i<list.size();i++){
  52 + String id=System.currentTimeMillis()+String.valueOf((random_number+i));
  53 + list.get(i).setId(id);
  54 + }
  55 + }
47 56 updateStudentWithThreads(list);
48 57 return list.size();
49 58 }
50 59  
51   - /**
52   - * 将list集合平均分成几等份
53   - *
54   - * @param num 分的份数
55   - * @param list 需要分的集合
56   - */
57   - private List splitList(List list, Integer num) {
58   - int listSize = list.size(); //list 长度
59   - List<List> splitLists = new ArrayList<>();
60   - List stringlist = new ArrayList<>();
61   - for ( int i = 0; i < listSize; i++ ) {
62   - stringlist.add(list.get(i));
63   - if ( ((i + 1) % num == 0) || (i + 1 == listSize) ) {
64   - splitLists.add(stringlist);
65   - stringlist = new ArrayList<>();
66   - }
67   - }
68   - return splitLists;
69   - }
  60 +// public static void main(String[] args){
  61 +// System.out.println(System.currentTimeMillis()+"00000000"+1);
  62 +// }
70 63  
71 64 private void addBatch(List<MrSchool> list, CountDownLatch threadLatch){
72   - TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
  65 +// TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
73 66 System.out.println("子线程:" + Thread.currentThread().getName());
74 67 try {
75 68 list.forEach(s -> {
76   - // 更新教师信息
77   - // String teacher = s.getTeacher();
78   - String newTeacher = "TNO_" + new Random().nextInt(100);
79   -// s.setTeacher(newTeacher);
80   - schoolMapper.insert(s);
  69 + if(oConvertUtils.isNotEmpty(s)){
  70 +// s.setId();
  71 + schoolMapper.insert(s);
  72 + }
81 73 });
82   - dataSourceTransactionManager.commit(transactionStatus);
  74 +// dataSourceTransactionManager.commit(transactionStatus);
83 75 threadLatch.countDown();
84 76 } catch (Throwable e) {
85 77 e.printStackTrace();
86   - dataSourceTransactionManager.rollback(transactionStatus);
  78 +// dataSourceTransactionManager.rollback(transactionStatus);
87 79 }
88 80 }
89 81  
90 82  
91 83 public void updateStudentWithThreads(List<MrSchool> list) {
92 84 // 线程数量
93   - final Integer threadCount = 1;
  85 + final Integer threadCount = 10;
94 86  
95 87 //每个线程处理的数据量
96 88 final Integer dataPartionLength = (list.size() + threadCount - 1) / threadCount;
... ...