| | |
| | | package com.lf.server.controller.data; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.metadata.OrderItem; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.lf.server.annotation.SysLog; |
| | | import com.lf.server.controller.all.BaseUploadController; |
| | | import com.lf.server.entity.all.ResponseMsg; |
| | |
| | | @SysLog() |
| | | @ApiOperation(value = "查询表中数据") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "metaid", value = "元数据ID", dataType = "Integer", paramType = "1") |
| | | @ApiImplicitParam(name = "id", value = "元数据ID", dataType = "Integer", paramType = "query", example = "113"), |
| | | @ApiImplicitParam(name = "pageIndex", value = "分页数(从1开始)", dataType = "Integer", paramType = "query", example = "1"), |
| | | @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "Integer", paramType = "query", example = "10") |
| | | }) |
| | | @GetMapping(value = "/selectDbData") |
| | | public ResponseMsg<Object> selectDbData(Integer metaid) { |
| | | public ResponseMsg<Object> selectDbData(Integer id, Integer pageIndex, Integer pageSize) { |
| | | try { |
| | | // |
| | | if (null == id || id < 0) { |
| | | return fail("元数据ID不能为空或小于0", null); |
| | | } |
| | | |
| | | return success(null); |
| | | MetaEntity meta = metaService.selectById(id); |
| | | if (null == meta || null == meta.getTab() || !meta.getTab().contains(".")) { |
| | | return fail("找不到元数据信息", null); |
| | | } |
| | | |
| | | String entity = meta.getTab().substring(meta.getTab().indexOf(".") + 1).replace("_", "").toLowerCase(); |
| | | BasicMapper baseMapper = ClassHelper.getBasicMapper(entity); |
| | | if (null == baseMapper) { |
| | | return null; |
| | | } |
| | | |
| | | QueryWrapper wrapper = new QueryWrapper(); |
| | | wrapper.eq("dirid", meta.getDirid()); |
| | | wrapper.eq("depid", meta.getDepid()); |
| | | wrapper.eq("verid", meta.getVerid()); |
| | | wrapper.eq("createtime", meta.getCreateTime()); |
| | | |
| | | Page<Object> page = new Page<>(pageIndex, pageSize); |
| | | page.addOrder(OrderItem.asc("gid")); |
| | | IPage<Object> paged = baseMapper.selectPage(page, wrapper); |
| | | |
| | | return success(paged.getTotal(), paged.getRecords()); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), null); |
| | | } |
| | |
| | | import org.apache.ibatis.mapping.MappedStatement; |
| | | import org.apache.ibatis.mapping.SqlSource; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 批量插入方法 |
| | | * @author WWW |
| | | */ |
| | | @SuppressWarnings("ALL") |
| | | public class InsertBatchMethod extends AbstractMethod { |
| | | private static List<String> excludeFields = new ArrayList<>(Arrays.asList("gid", "objectid", "updateuser", "updatetime", "shape_leng", "shape_area")); |
| | | |
| | | /** |
| | | * insert into user(id, name, age) values (1, "a", 17), (2, "b", 18); |
| | | * <script> |
| | |
| | | // fieldSql.append(tableInfo.getKeyColumn()).append(",") |
| | | // tableInfo.getFieldList().forEach(x -> fieldSql.append(x.getColumn()).append(",")) |
| | | for (TableFieldInfo f : tableInfo.getFieldList()) { |
| | | if (GdbHelper.excludeFields.contains(f.getColumn())) { |
| | | if (excludeFields.contains(f.getColumn())) { |
| | | continue; |
| | | } |
| | | |
| | |
| | | // valueSql.append("#{item.").append(tableInfo.getKeyProperty()).append("},") |
| | | // tableInfo.getFieldList().forEach(x -> valueSql.append("#{item.").append(x.getProperty()).append("},")) |
| | | for (TableFieldInfo f : tableInfo.getFieldList()) { |
| | | if (GdbHelper.excludeFields.contains(f.getColumn())) { |
| | | if (excludeFields.contains(f.getColumn())) { |
| | | continue; |
| | | } |
| | | |
| | |
| | | public class GdbHelper { |
| | | private final static Log log = LogFactory.getLog(GdbHelper.class); |
| | | |
| | | public static List<String> excludeFields = new ArrayList<>(Arrays.asList("gid", "shape_leng")); |
| | | private static List<String> excludeFields = new ArrayList<>(Arrays.asList("gid", "objectid", "dirid", "depid", "verid","createtime", "createuser", "updateuser", "updatetime", "shape_leng", "shape_area")); |
| | | |
| | | /** |
| | | * 销毁资源 |
| | |
| | | public static <T> void readLayer(Class clazz, Layer layer, List<T> list) { |
| | | try { |
| | | Field gField = getGeomField(clazz); |
| | | Map<Integer, Field> map = getFieldMapper(clazz, layer); |
| | | if (map.size() == 0) { |
| | | return; |
| | | } |
| | | if (1 > layer.GetFeatureCount()) { |
| | | |
| | | Map<Integer, Field> map = new HashMap<>(3); |
| | | getFieldMapper(clazz, layer, map); |
| | | if (map.isEmpty() || 0 == layer.GetFeatureCount()) { |
| | | return; |
| | | } |
| | | |
| | |
| | | /** |
| | | * 获取字段映射 |
| | | */ |
| | | private static <T> Map<Integer, Field> getFieldMapper(Class clazz, Layer layer) { |
| | | Map<Integer, Field> map = new HashMap<>(3); |
| | | |
| | | private static <T> void getFieldMapper(Class clazz, Layer layer, Map<Integer, Field> map) { |
| | | try { |
| | | FeatureDefn fd = layer.GetLayerDefn(); |
| | | for (int i = 0, count = fd.GetFieldCount(); i < count; i++) { |
| | |
| | | // |
| | | } |
| | | } |
| | | |
| | | if ("java.lang.Object" != clazz.getSuperclass().getName()) { |
| | | getFieldMapper(clazz.getSuperclass(), layer, map); |
| | | } |
| | | } catch (Exception ex) { |
| | | // |
| | | } |
| | | |
| | | return map; |
| | | } |
| | | |
| | | /** |
| | |
| | | * 设置值 |
| | | */ |
| | | private static <T> void setValue(T t, Feature f, Field field, Integer i) throws Exception { |
| | | switch (field.getType().toString()) { |
| | | case "class java.math.BigDecimal": |
| | | case "class java.lang.Double": |
| | | switch (field.getType().getName()) { |
| | | case "java.math.BigDecimal": |
| | | case "java.lang.Double": |
| | | case "double": |
| | | field.set(t, f.GetFieldAsDouble(i)); |
| | | break; |
| | | case "class java.lang.Long": |
| | | case "java.lang.Long": |
| | | case "long": |
| | | field.set(t, f.GetFieldAsInteger64(i)); |
| | | break; |
| | | case "class java.lang.Integer": |
| | | case "java.lang.Integer": |
| | | case "int": |
| | | field.set(t, f.GetFieldAsInteger(i)); |
| | | break; |
| | | case "class java.sql.Timestamp": |
| | | case "java.sql.Timestamp": |
| | | field.set(t, getTimestamp(f, i)); |
| | | break; |
| | | default: |
| | |
| | | public static boolean unzip(String filePath, String zipDir) { |
| | | ZipFile zipFile = null; |
| | | try { |
| | | File dir = new File(zipDir); |
| | | if (!dir.exists() || !dir.isDirectory()) { |
| | | dir.mkdirs(); |
| | | } |
| | | |
| | | int count; |
| | | zipFile = new ZipFile(filePath); |
| | | |
| | | Enumeration e = zipFile.entries(); |
| | | while (e.hasMoreElements()) { |
| | | ZipEntry entry = (ZipEntry) e.nextElement(); |
| | |
| | | BufferedInputStream is = new BufferedInputStream(zipFile.getInputStream(entry)); |
| | | FileOutputStream fos = new FileOutputStream(zipDir + File.separator + entry.getName()); |
| | | BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER_SIZE); |
| | | |
| | | while ((count = is.read(BUFFER, 0, BUFFER_SIZE)) != -1) { |
| | | dest.write(BUFFER, 0, count); |
| | | } |
| | |
| | | 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()) { |
| | |
| | | /** |
| | | * 插入Excel |
| | | */ |
| | | private void insertXls(String root, MetaFileEntity mf, TabMapperEntity tab) { |
| | | private void insertXls(String root, MetaEntity me, MetaFileEntity 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); |
| | |
| | | insert into lf.sys_meta |
| | | (name,dirid,depid,verid,type,sizes,tab,rows,cs,scale,resolution,gather,batch,descr,create_user,create_time,geom) |
| | | values |
| | | (#{name},#{dirid},#{depid},#{verid},#{type},#{sizes},#{tab},#{rows},#{cs},#{scale},#{resolution},#{createTime},#{batch},#{descr},#{createUser},now(),#{geom}) |
| | | (#{name},#{dirid},#{depid},#{verid},#{type},#{sizes},#{tab},#{rows},#{cs},#{scale},#{resolution},#{createTime},#{batch},#{descr},#{createUser},#{createTime},#{geom}) |
| | | </insert> |
| | | |
| | | <insert id="inserts"> |