| | |
| | | package com.lf.server.service.data; |
| | | |
| | | import com.alibaba.druid.support.spring.stat.annotation.Stat; |
| | | import com.lf.server.entity.all.StaticData; |
| | | import com.lf.server.entity.data.CoordEntity; |
| | | import com.lf.server.entity.data.DirEntity; |
| | | import com.lf.server.entity.data.FmeLogEntity; |
| | | import com.lf.server.entity.data.MetaFileEntity; |
| | | import com.lf.server.entity.sys.UserEntity; |
| | | import com.lf.server.helper.StringHelper; |
| | | import com.lf.server.mapper.data.UploadMapper; |
| | | import com.lf.server.service.all.BaseUploadService; |
| | | import org.apache.commons.collections4.queue.PredicatedQueue; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.io.File; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | |
| | | public class UploadService extends BaseUploadService implements UploadMapper { |
| | | @Autowired |
| | | UploadMapper uploadMapper; |
| | | |
| | | @Autowired |
| | | FmeService fmeService; |
| | | |
| | | @Override |
| | | public List<CoordEntity> selectCoords(String zoning) { |
| | |
| | | /** |
| | | * 插入文件 |
| | | */ |
| | | public void insertFiles(UserEntity ue, List<MetaFileEntity> list) { |
| | | public void insertFiles(UserEntity ue, List<MetaFileEntity> list, HttpServletRequest req) { |
| | | checkMetaFiles(ue, list); |
| | | |
| | | loadExcel(list, req); |
| | | } |
| | | |
| | | /** |
| | |
| | | private void checkMetaFiles(UserEntity ue, List<MetaFileEntity> list) { |
| | | String tempPath = pathHelper.getConfig().getTempPath(); |
| | | |
| | | int i = 0; |
| | | while (i < list.size()) { |
| | | MetaFileEntity mf = list.get(i); |
| | | for (MetaFileEntity mf : list) { |
| | | mf.setCreateUser(ue.getId()); |
| | | mf.setDepid(ue.getDepid()); |
| | | |
| | | File f = new File(tempPath + File.separator + mf.getPath()); |
| | | if (!f.exists()) { |
| | | list.remove(i); |
| | | continue; |
| | | mf.setRows(-1); |
| | | mf.setMsg("文件不存在"); |
| | | } |
| | | |
| | | // mf.setCreateUser(ue.getId()); mf.setDepid(ue.getDepid()) |
| | | i++; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取Excel文件 |
| | | * Excel入库 |
| | | */ |
| | | private List<String> getExcelFiles(List<MetaFileEntity> list) { |
| | | String tempPath = pathHelper.getConfig().getTempPath(); |
| | | private void loadExcel(List<MetaFileEntity> list, HttpServletRequest req) { |
| | | List<MetaFileEntity> xlsList = getExcelFiles(list); |
| | | if (xlsList.isEmpty()) { |
| | | return; |
| | | } |
| | | |
| | | List<String> xlsList = new ArrayList<>(); |
| | | MetaFileEntity meta = getExcelMeta(xlsList); |
| | | String guid = fmeService.excelLoader(meta, req); |
| | | } |
| | | |
| | | /** |
| | | * 获取Excel元数据文件 |
| | | */ |
| | | private List<MetaFileEntity> getExcelFiles(List<MetaFileEntity> list) { |
| | | List<MetaFileEntity> xlsList = new ArrayList<>(); |
| | | for (MetaFileEntity mf : list) { |
| | | if (StaticData.XLS.equals(mf.getExtName()) || StaticData.XLSX.equals(mf.getExtName())) { |
| | | File f = new File(tempPath + File.separator + mf.getPath()); |
| | | if (f.exists() && !f.isDirectory()) { |
| | | xlsList.add(f.getPath()); |
| | | } |
| | | boolean isXls = StaticData.XLS.equals(mf.getExtName()) || StaticData.XLSX.equals(mf.getExtName()); |
| | | if (mf.getRows() > -1 && isXls) { |
| | | xlsList.add(mf); |
| | | } |
| | | } |
| | | |
| | | return xlsList; |
| | | } |
| | | |
| | | /** |
| | | * 获取Excel的元数据 |
| | | */ |
| | | private MetaFileEntity getExcelMeta(List<MetaFileEntity> xlsList) { |
| | | List<String> pathList = new ArrayList<>(); |
| | | List<String> dirList = new ArrayList<>(); |
| | | List<String> pidList = new ArrayList<>(); |
| | | |
| | | String tempPath = pathHelper.getConfig().getTempPath(); |
| | | for (MetaFileEntity mf : xlsList) { |
| | | pathList.add(tempPath + File.separator + mf.getPath()); |
| | | dirList.add(mf.getDirid() + ""); |
| | | pidList.add(mf.getEventid()); |
| | | } |
| | | |
| | | MetaFileEntity meta = new MetaFileEntity(); |
| | | meta.setPath(StringHelper.join(pathList, ",")); |
| | | meta.setEpsgCode(xlsList.get(0).getEpsgCode()); |
| | | meta.setName(StringHelper.join(dirList, ",")); |
| | | meta.setDepid(xlsList.get(0).getDepid()); |
| | | meta.setVerid(xlsList.get(0).getVerid()); |
| | | meta.setCreateUser(xlsList.get(0).getCreateUser()); |
| | | meta.setEventid(StringHelper.join(pidList, ",")); |
| | | |
| | | return meta; |
| | | } |
| | | } |