| | |
| | | import java.io.FileInputStream; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * 元数据 |
| | | * @author WWW |
| | | */ |
| | | @Service |
| | | @SuppressWarnings("ALL") |
| | | public class MetaService implements MetaMapper { |
| | | @Autowired |
| | | PathHelper pathHelper; |
| | |
| | | private final static Log log = LogFactory.getLog(MetaService.class); |
| | | |
| | | @Override |
| | | public Integer selectCount(String depcode, String dircode, Integer verid, String name) { |
| | | public Integer selectCount(String depcode, String dircode, Integer verid, String name, Integer sensorType, Integer mataType, Date startDate, Date endDate, String wkt) { |
| | | depcode = StringHelper.getRightLike(depcode); |
| | | dircode = StringHelper.getRightLike(dircode); |
| | | name = StringHelper.getLikeUpperStr(name); |
| | | |
| | | return metaMapper.selectCount(depcode, dircode, verid, name); |
| | | return metaMapper.selectCount(depcode, dircode, verid, name, sensorType, mataType, startDate, endDate, wkt); |
| | | } |
| | | |
| | | @Override |
| | | public List<MetaEntity> selectByPage(String depcode, String dircode, Integer verid, String name, Integer limit, Integer offset) { |
| | | public List<MetaEntity> selectByPage(String depcode, String dircode, Integer verid, String name, Integer sensorType, Integer mataType, Date startDate, Date endDate, String wkt, Integer limit, Integer offset) { |
| | | depcode = StringHelper.getRightLike(depcode); |
| | | dircode = StringHelper.getRightLike(dircode); |
| | | name = StringHelper.getLikeUpperStr(name); |
| | | |
| | | return metaMapper.selectByPage(depcode, dircode, verid, name, limit, offset); |
| | | return metaMapper.selectByPage(depcode, dircode, verid, name, sensorType, mataType, startDate, endDate, wkt, limit, offset); |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<MetaEntity> selectByIds(String ids) { |
| | | return metaMapper.selectByIds(ids); |
| | | } |
| | | |
| | | @Override |
| | | public MetaEntity selectByGuid(String guid, String dircode, String tab) { |
| | | return metaMapper.selectByGuid(guid, dircode, tab); |
| | | } |
| | |
| | | return metaMapper.selectByIdsForTab(ids); |
| | | } |
| | | |
| | | @Override |
| | | public List<MetaEntity> selectMetaFiles(List<Integer> ids) { |
| | | return metaMapper.selectMetaFiles(StringHelper.join(ids, StaticData.COMMA)); |
| | | } |
| | | |
| | | @Override |
| | | public List<MetaEntity> selectMetaFiles(String ids) { |
| | | return metaMapper.selectMetaFiles(ids); |
| | | } |
| | | |
| | |
| | | return metaMapper.updates(list); |
| | | } |
| | | |
| | | /** |
| | | * 删除元数据 |
| | | */ |
| | | public Integer deletes(List<Integer> list) { |
| | | String ids = StringHelper.join(list, ","); |
| | | |
| | |
| | | return deletes(sql, ids); |
| | | } |
| | | |
| | | /** |
| | | * 获取删除表记录SQL |
| | | */ |
| | | public String getDelTabsSql(List<MetaEntity> metas) { |
| | | List<String> list = getTabDeletes(metas, metas.get(0).getTab()); |
| | | addCascadDeletes(list); |
| | |
| | | return StringHelper.join(list, ";"); |
| | | } |
| | | |
| | | /** |
| | | * 获取删除表记录SQL |
| | | */ |
| | | private List<String> getTabDeletes(List<MetaEntity> metas, String tab) { |
| | | List<String> list = new ArrayList<>(); |
| | | |
| | |
| | | return list; |
| | | } |
| | | |
| | | /** |
| | | * 添加级联删除 |
| | | */ |
| | | private void addCascadDeletes(List<String> list) { |
| | | int i = 0, c = list.size(); |
| | | while (i < c) { |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 添加附件删除 |
| | | */ |
| | | private void addAttachDeletes(List<String> list) { |
| | | int i = 0, c = list.size(); |
| | | while (i < c) { |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 查看文件 |
| | | */ |
| | | public void downloadForView(String guid, boolean inline, HttpServletResponse res) { |
| | | try { |
| | | if (StringHelper.isEmpty(guid)) { |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 查询元数据中溢出的单位ID |
| | | */ |
| | | public List<String> selectMetaOverflowDep(UserEntity ue, DownloadReqEntity dr) { |
| | | String ids = StringHelper.join(dr.getIds(), ","); |
| | | |
| | | return selectMetaOverflowDep(ids, ue.getDepcode()); |
| | | } |
| | | |
| | | /** |
| | | * 请求元数据下载 |
| | | * |
| | | * @param ue 用户实体 |
| | | * @param dr 请求下载实体 |
| | | * @return 下载文件GUID |
| | | * @throws Exception 异常 |
| | | */ |
| | | public String downloadMeteReq(UserEntity ue, DownloadReqEntity dr) throws Exception { |
| | | List<MetaEntity> list = selectMetaFiles(dr.getIds()); |
| | | if (null == list || list.isEmpty()) { |
| | |
| | | return rows > 0 ? de.getGuid() : null; |
| | | } |
| | | |
| | | /** |
| | | * 获取数据表 |
| | | */ |
| | | private Map<String, List<String>> getTabs(List<MetaEntity> list) { |
| | | Map<String, List<String>> tabs = new HashMap<>(2); |
| | | for (MetaEntity meta : list) { |
| | |
| | | return tabs; |
| | | } |
| | | |
| | | /** |
| | | * 移除重复的元数据文件 |
| | | */ |
| | | private void rmRepeatMetas(List<MetaEntity> list) { |
| | | List<String> guidList = new ArrayList<>(); |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 查询数据 |
| | | */ |
| | | private void queryData(Map<String, List<String>> tabs, Map<String, List<?>> dataMap, Map<String, List<AttachEntity>> annexMap) { |
| | | for (String tab : tabs.keySet()) { |
| | | try { |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 添加数据 |
| | | */ |
| | | public void addData(String entity, BasicMapper baseMapper, QueryWrapper wrapper, Map<String, List<?>> dataMap, Map<String, List<AttachEntity>> annexMap) { |
| | | List list = baseMapper.selectList(wrapper); |
| | | if (null == list || list.size() == 0) { |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 创建查询包装器 |
| | | */ |
| | | private <T> QueryWrapper<T> createQueryWrapper(BasicMapper baseMapper, List<String> ids) { |
| | | for (int i = 0, c = ids.size(); i < c; i++) { |
| | | ids.set(i, "'" + ids.get(i) + "'"); |
| | |
| | | return wrapper; |
| | | } |
| | | |
| | | /** |
| | | * 添加附件 |
| | | */ |
| | | public void addAnnex(ZipFile zip, ZipParameters params, Map<String, List<AttachEntity>> annexMap) { |
| | | List<String> files = new ArrayList<>(); |
| | | String uploadPath = pathHelper.getConfig().getUploadPath(); |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 添加元数据文件至Zip包 |
| | | */ |
| | | private void addMetaFiles(ZipFile zip, ZipParameters params, List<MetaEntity> list) { |
| | | List<String> names = new ArrayList<>(); |
| | | String uploadPath = pathHelper.getConfig().getUploadPath(); |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 添加目录文件 |
| | | */ |
| | | private void addFolderFile(String uploadPath, MetaEntity mf, ZipFile zip, ZipParameters params) throws Exception { |
| | | File file = new File(uploadPath + File.separator + mf.getPath()); |
| | | if (!file.exists() || !file.isDirectory()) { |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 添加多文件 |
| | | */ |
| | | private void addMultiFile(String uploadPath, MetaEntity mf, ZipFile zip, ZipParameters params, List<String> extList) throws Exception { |
| | | addSingleFile(uploadPath, mf, zip, params); |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 添加单文件 |
| | | */ |
| | | private void addSingleFile(String uploadPath, MetaEntity mf, ZipFile zip, ZipParameters params) throws Exception { |
| | | File file = new File(uploadPath + File.separator + mf.getPath()); |
| | | if (!file.exists() || file.isDirectory()) { |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取下载实体类 |
| | | */ |
| | | private DownloadEntity getDownloadEntity(UserEntity ue, String file, String pwd) { |
| | | DownloadEntity de = new DownloadEntity(); |
| | | de.setName(FileHelper.getFileName(file)); |
| | |
| | | return de; |
| | | } |
| | | |
| | | /** |
| | | * 插入元数据-下载表 |
| | | */ |
| | | private void insertMetaDown(UserEntity ue, List<MetaEntity> metas, DownloadEntity de) { |
| | | List<MetaDownEntity> list = new ArrayList<>(); |
| | | for (MetaEntity me : metas) { |
| | |
| | | |
| | | metaDownService.inserts(list); |
| | | } |
| | | |
| | | public String getGeometryFilter(String wkt) throws Exception { |
| | | if (StringHelper.isEmpty(wkt)) { |
| | | return null; |
| | | } |
| | | |
| | | wkt = AesHelper.decrypt(wkt); |
| | | |
| | | return String.format("ST_Intersects(ST_GeomFromText('%s', %d), geom)", wkt, StaticData.I104903); |
| | | } |
| | | } |