| | |
| | | import com.lf.server.entity.all.BaseEntity; |
| | | import com.lf.server.entity.ctrl.TabMapperEntity; |
| | | import com.lf.server.entity.data.MetaEntity; |
| | | import com.lf.server.entity.data.MetaFileEntity; |
| | | import com.lf.server.helper.*; |
| | | import com.lf.server.mapper.all.BasicMapper; |
| | | import com.lf.server.mapper.all.GeomBaseMapper; |
| | |
| | | public class DataLoaderService extends BaseUploadService { |
| | | @Autowired |
| | | MetaService metaService; |
| | | |
| | | @Autowired |
| | | MetaFileService metaFileService; |
| | | |
| | | private final static String XLS = ".xls"; |
| | | |
| | |
| | | getGdbFiles(f.getName(), subPath, list); |
| | | continue; |
| | | } |
| | | if (!fileName.contains(ZIP)) { |
| | | // |
| | | if (fileName.contains(ZIP)) { |
| | | // 暂时不实现 |
| | | } |
| | | } |
| | | |
| | |
| | | /** |
| | | * 插入文件 |
| | | */ |
| | | public void insertFiles(MetaEntity entity, List<MetaFileEntity> list, List<TabMapperEntity> tabList) { |
| | | public void insertFiles(MetaEntity entity, List<MetaEntity> list, List<TabMapperEntity> tabList) { |
| | | try { |
| | | String temp = pathHelper.getConfig().getTempPath(); |
| | | String upload = pathHelper.getUploadFullPath(); |
| | | |
| | | for (MetaFileEntity mf : list) { |
| | | for (MetaEntity mf : list) { |
| | | File file = new File(temp + File.separator + mf.getPath()); |
| | | File newFile = new File(upload + File.separator + mf.getGuid()); |
| | | |
| | |
| | | continue; |
| | | } |
| | | |
| | | MetaFileEntity old = metaFileService.selectByGuid(mf.getGuid()); |
| | | MetaEntity old = metaService.selectByGuid(mf.getGuid()); |
| | | String filePath = null == old ? newFile.getPath() : old.getPath(); |
| | | |
| | | int count = 0; |
| | |
| | | case "shp": |
| | | case "gdb": |
| | | case "mdb": |
| | | insertDb(type, temp, mf, tab); |
| | | insertDb(type, temp, entity, tab); |
| | | break; |
| | | // case "xls": |
| | | default: |
| | | insertXls(temp, mf, tab); |
| | | insertXls(temp, entity, mf, tab); |
| | | break; |
| | | } |
| | | if (0 == tab.getRows()) { |
| | |
| | | continue; |
| | | } |
| | | |
| | | MetaFileEntity mfe = createMetaFileEntity(me, mf, filePath); |
| | | if (metaFileService.insert(mfe) == 0) { |
| | | MetaEntity mfe = createMetaFileEntity(me, mf, filePath); |
| | | if (metaService.insert(mfe) == 0) { |
| | | metaService.delete(me.getId()); |
| | | continue; |
| | | } |
| | |
| | | /** |
| | | * 获取 Tabs |
| | | */ |
| | | private List<TabMapperEntity> getTabs(MetaFileEntity mfe, List<TabMapperEntity> tabs) { |
| | | private List<TabMapperEntity> getTabs(MetaEntity mfe, List<TabMapperEntity> tabs) { |
| | | List<TabMapperEntity> list = new ArrayList<>(); |
| | | for (TabMapperEntity tab : tabs) { |
| | | if (!tab.getFileName().equals(mfe.getName()) || StringHelper.isEmpty(tab.getEntity())) { |
| | |
| | | /** |
| | | * 创建元数据实体 |
| | | */ |
| | | private MetaEntity createMetaEntity(MetaEntity entity, MetaFileEntity mf, String tab, int rows) { |
| | | private MetaEntity createMetaEntity(MetaEntity entity, MetaEntity mf, String tab, int rows) { |
| | | MetaEntity me = new MetaEntity(); |
| | | me.setDepid(entity.getDepid()); |
| | | me.setDirid(entity.getDirid()); |
| | | me.setVerid(entity.getVerid()); |
| | | me.setType(getType(mf.getName().toLowerCase())); |
| | | me.setGather(entity.getGather()); |
| | | me.setBatch(entity.getBatch()); |
| | | me.setDescr(entity.getDescr()); |
| | | me.setName(mf.getName()); |
| | | me.setSizes(mf.getSizes()); |
| | | me.setTab(tab); |
| | | me.setRows(rows); |
| | | me.setBstab(tab); |
| | | me.setBsrows(rows); |
| | | me.setCreateTime(entity.getCreateTime()); |
| | | me.setCreateUser(entity.getCreateUser()); |
| | | |
| | |
| | | /** |
| | | * 创建元数据文件实体 |
| | | */ |
| | | private MetaFileEntity createMetaFileEntity(MetaEntity me, MetaFileEntity entity, String filePath) { |
| | | MetaFileEntity mfe = new MetaFileEntity(); |
| | | private MetaEntity createMetaFileEntity(MetaEntity me, MetaEntity entity, String filePath) { |
| | | MetaEntity mfe = new MetaEntity(); |
| | | mfe.setName(entity.getName()); |
| | | mfe.setMetaid(me.getId()); |
| | | mfe.setGuid(entity.getGuid()); |
| | |
| | | /** |
| | | * 插入Excel |
| | | */ |
| | | private void insertXls(String root, MetaFileEntity mf, TabMapperEntity tab) { |
| | | private void insertXls(String root, MetaEntity me, MetaEntity mf, TabMapperEntity tab) { |
| | | BasicMapper basicMapper = ClassHelper.getBasicMapper(tab.getEntity()); |
| | | if (null == basicMapper) { |
| | | return; |
| | |
| | | if (list.isEmpty()) { |
| | | return; |
| | | } |
| | | setCreateInfo(list, mf); |
| | | setCreateInfo(list, me); |
| | | |
| | | int rows = 0; |
| | | for (int i = 0, c = list.size(); i < c; i++) { |
| | |
| | | /** |
| | | * 设置创建信息 |
| | | */ |
| | | private <T> void setCreateInfo(List<T> list, MetaFileEntity mf) { |
| | | private <T> void setCreateInfo(List<T> list, MetaEntity me) { |
| | | try { |
| | | for (T t : list) { |
| | | Field cuField = t.getClass().getDeclaredField("createuser"); |
| | | cuField.setAccessible(true); |
| | | cuField.set(t, mf.getCreateUser()); |
| | | if (!(list.get(0) instanceof BaseEntity)) { |
| | | return; |
| | | } |
| | | |
| | | Field ctField = t.getClass().getDeclaredField("createtime"); |
| | | ctField.setAccessible(true); |
| | | ctField.set(t, mf.getCreateTime()); |
| | | for (T t : list) { |
| | | BaseEntity be = (BaseEntity) t; |
| | | be.setCreateuser(me.getCreateUser()); |
| | | be.setCreatetime(me.getCreateTime()); |
| | | be.setDirid(me.getDirid()); |
| | | be.setDepid(me.getDepid()); |
| | | be.setVerid(me.getVerid()); |
| | | } |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | |
| | | /** |
| | | * 插入DB |
| | | */ |
| | | private void insertDb(String type, String root, MetaFileEntity mf, TabMapperEntity tab) { |
| | | private void insertDb(String type, String root, MetaEntity me, TabMapperEntity tab) { |
| | | BasicMapper basicMapper = ClassHelper.getBasicMapper(tab.getEntity()); |
| | | if (null == basicMapper) { |
| | | return; |
| | |
| | | if (null == list || list.isEmpty()) { |
| | | return; |
| | | } |
| | | setCreateInfo(list, mf); |
| | | setCreateInfo(list, me); |
| | | |
| | | int rows = basicMapper.insertBatch(list); |
| | | tab.setTab(tabName); |