| | |
| | | package com.lf.server.service.data; |
| | | |
| | | import com.google.common.collect.Lists; |
| | | import com.lf.server.entity.all.BaseEntity; |
| | | import com.lf.server.entity.all.StaticData; |
| | | import com.lf.server.entity.data.*; |
| | |
| | | } |
| | | setCreateInfo(list, mf); |
| | | |
| | | int rows = basicMapper.insertBatch(list); |
| | | int rows = batchInserts(basicMapper, list); |
| | | if (rows > 0) { |
| | | mf.setEntity(mf.getTab()); |
| | | mf.setTab(tabName); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 批量插入 |
| | | */ |
| | | private <T> int batchInserts(BasicMapper basicMapper, List<T> list) { |
| | | int rows = 0; |
| | | int count = (int) Math.ceil(list.size() / StaticData.D100); |
| | | |
| | | List<List<T>> subLists = Lists.partition(list, count); |
| | | for (List<T> sub : subLists) { |
| | | try { |
| | | rows += basicMapper.insertBatch(sub); |
| | | } catch (Exception ex) { |
| | | log.error(ex); |
| | | } |
| | | } |
| | | |
| | | return rows; |
| | | } |
| | | |
| | | /** |
| | | * 设置创建信息 |
| | | */ |
| | | private <T> void setCreateInfo(List<T> list, MetaFileEntity mf) { |