| | |
| | | import java.io.File; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * 资料馆 |
| | | * @author WWW |
| | | */ |
| | | @Service |
| | | @SuppressWarnings("ALL") |
| | | public class DataLibService { |
| | | @Autowired |
| | | PathHelper pathHelper; |
| | |
| | | |
| | | private final static Log log = LogFactory.getLog(DataLibService.class); |
| | | |
| | | /** |
| | | * 查询DB中溢出的单位编码 |
| | | */ |
| | | public List<String> selectDbOverflowDep(UserEntity ue, DownloadReqEntity dr) { |
| | | if (!StringHelper.isEmpty(dr.getWkt())) { |
| | | return selectDbOverflowDep4Wkt(ue, dr); |
| | |
| | | return selectDbOverflowDep4Prop(ue, dr); |
| | | } |
| | | |
| | | /** |
| | | * 查询DB中溢出的单位编码-空间查询 |
| | | */ |
| | | public List<String> selectDbOverflowDep4Wkt(UserEntity ue, DownloadReqEntity dr) { |
| | | List<String> rs = new ArrayList<>(); |
| | | for (String entity : dr.getEntities()) { |
| | |
| | | return rs; |
| | | } |
| | | |
| | | /** |
| | | * 查询DB中溢出的单位编码-属性查询 |
| | | */ |
| | | public List<String> selectDbOverflowDep4Prop(UserEntity ue, DownloadReqEntity dr) { |
| | | List<String> rs = new ArrayList<>(); |
| | | BasicMapper<?> baseMapper = ClassHelper.getBasicMapper(dr.getEntities().get(0)); |
| | |
| | | return rs; |
| | | } |
| | | |
| | | /** |
| | | * 查询DB中溢出单位编码的查询包装器 |
| | | */ |
| | | private <T> QueryWrapper<T> getWrapper4DbOverflow(UserEntity ue, DownloadReqEntity dr) { |
| | | QueryWrapper<T> wrapper = new QueryWrapper<T>(); |
| | | wrapper.select("depid"); |
| | |
| | | return wrapper; |
| | | } |
| | | |
| | | /** |
| | | * 添加单位编码 |
| | | */ |
| | | private void addDepCodes(List<String> rs, List<String> ids) { |
| | | if (null == ids || ids.isEmpty()) { |
| | | return; |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 请求DB数据下载 |
| | | */ |
| | | public String downloadDbReq(UserEntity ue, DownloadReqEntity dr) throws Exception { |
| | | Map<String, List<?>> dataMap = new HashMap<>(2); |
| | | Map<String, List<AttachEntity>> annexMap = new HashMap<>(2); |
| | |
| | | return rows > 0 ? de.getGuid() : null; |
| | | } |
| | | |
| | | /** |
| | | * 查询数据+附件 |
| | | */ |
| | | private void queryData(DownloadReqEntity dr, Map<String, List<?>> dataMap, Map<String, List<AttachEntity>> annexMap) { |
| | | for (String entity : dr.getEntities()) { |
| | | try { |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 创建查询包装器 |
| | | */ |
| | | private <T> QueryWrapper<T> createQueryWrapper(BasicMapper baseMapper, DownloadReqEntity dr) { |
| | | QueryWrapper<T> wrapper = new QueryWrapper<T>(); |
| | | |
| | |
| | | return wrapper; |
| | | } |
| | | |
| | | /** |
| | | * 创建附件 * |
| | | */ |
| | | private void createAnnex(String annexPath, Map<String, List<AttachEntity>> annexMap) { |
| | | if (annexMap.size() == 0) { |
| | | return; |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取下载实体类 |
| | | */ |
| | | private DownloadEntity getDownloadEntity(UserEntity ue, String file, String pwd) { |
| | | DownloadEntity de = new DownloadEntity(); |
| | | de.setName(FileHelper.getFileName(file)); |
| | |
| | | return de; |
| | | } |
| | | |
| | | /** |
| | | * 处理编码 |
| | | */ |
| | | public static String copeCodes(String codes, String field) { |
| | | if (StringHelper.isEmpty(codes) || StringHelper.isSqlInjection(codes)) { |
| | | return null; |
| | | } |
| | | |
| | | List<String> list = codesAsList(codes); |
| | | removeDuplicate(list); |
| | | list = copeDirCodes(list); |
| | | setRightLike(list, field); |
| | | |
| | | return "(" + StringHelper.join(list, " or ") + ")"; |
| | | } |
| | | |
| | | /** |
| | | * 单位编码转集合 |
| | | */ |
| | | private static List<String> codesAsList(String codes) { |
| | | List<String> list = Arrays.asList(codes.split(",")); |
| | | Set set = new HashSet(list); |
| | |
| | | return newList; |
| | | } |
| | | |
| | | /** |
| | | * 去除重复 |
| | | */ |
| | | private static void removeDuplicate(List<String> list) { |
| | | int i = 0; |
| | | while (i < list.size()) { |
| | | int j = findStr(list, i); |
| | | if (j > -1) { |
| | | list.remove(j); |
| | | private static List<String> copeDirCodes(List<String> list) { |
| | | List<String> prjList = getDirCodesByLen(list, 0, 2); |
| | | List<String> appList = getDirCodesByLen(list, 3, 30); |
| | | if (prjList.isEmpty() && appList.isEmpty()) { |
| | | return list; |
| | | } |
| | | if (prjList.isEmpty()) { |
| | | return appList; |
| | | } |
| | | if (appList.isEmpty()) { |
| | | return prjList; |
| | | } |
| | | |
| | | return filterCodes(prjList, appList); |
| | | } |
| | | |
| | | private static List<String> getDirCodesByLen(List<String> list, int start, int end) { |
| | | List<String> rs = new ArrayList<>(); |
| | | for (String code : list) { |
| | | if (StringHelper.isEmpty(code)) { |
| | | continue; |
| | | } |
| | | |
| | | i++; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 查找字符串 |
| | | */ |
| | | private static int findStr(List<String> list, int i) { |
| | | String source = list.get(i); |
| | | for (int j = i + 1, c = list.size(); j < c; j++) { |
| | | if (list.get(j).startsWith(source)) { |
| | | return j; |
| | | if (code.length() >= start && code.length() <= end) { |
| | | rs.add(code); |
| | | } |
| | | } |
| | | |
| | | return -1; |
| | | return rs; |
| | | } |
| | | |
| | | /** |
| | | * 设置 右like |
| | | */ |
| | | private static List<String> filterCodes(List<String> prjList, List<String> appList) { |
| | | int i = 0; |
| | | while (i < appList.size()) { |
| | | boolean flag = false; |
| | | for (String prj : prjList) { |
| | | if (appList.get(i).startsWith(prj)) { |
| | | flag = true; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | if (!flag) { |
| | | appList.remove(i); |
| | | continue; |
| | | } |
| | | i++; |
| | | } |
| | | |
| | | return appList; |
| | | } |
| | | |
| | | private static void setRightLike(List<String> list, String field) { |
| | | if (list.isEmpty()) { |
| | | list.add("1 = 2"); |
| | | return; |
| | | } |
| | | |
| | | for (int i = 0, c = list.size(); i < c; i++) { |
| | | String str = String.format("%s like '%s%%'", field, list.get(i)); |
| | | list.set(i, str); |