ソースを参照

修改,可以添加模板配置可添加数据库和字段

DESKTOP-2K9OVK9\siwei 5 ヶ月 前
コミット
c7ee290c94

+ 18 - 0
onemap-modules/onemap-apply/src/main/java/com/onemap/apply/controller/supervise/TSuperviseYwlxController.java

@@ -5,6 +5,7 @@ import javax.servlet.http.HttpServletResponse;
 
 import com.onemap.apply.domain.supervise.TSuperviseYwlxDo;
 import com.onemap.apply.service.supervise.ITSuperviseYwlxService;
+import com.onemap.common.core.utils.StringUtils;
 import com.onemap.common.core.web.controller.BaseController;
 import com.onemap.common.core.utils.poi.ExcelUtil;
 import com.onemap.common.core.web.domain.AjaxResult;
@@ -67,10 +68,21 @@ public class TSuperviseYwlxController extends BaseController {
     @Log(title = "数据模板类型", businessType = BusinessType.INSERT)
     @PostMapping
     public AjaxResult add(@RequestBody TSuperviseYwlxDo tSuperviseYwlx) {
+        if (tSuperviseYwlx == null) {
+            return AjaxResult.error("参数缺失");
+        }
+        if (StringUtils.isEmpty(tSuperviseYwlx.getSjy())) {
+            return AjaxResult.error("参数缺失");
+        }
         TSuperviseYwlxDo bean = tSuperviseYwlxService.selectTSuperviseYwlxMapperByYwlx(tSuperviseYwlx.getYwlx());
         if (bean != null) {
             return AjaxResult.error("业务类型重复");
         }
+        List<String> tale = tSuperviseYwlxService.getOnemapTable(tSuperviseYwlx.getSjy());
+        if (tale != null && tale.size() > 0) {
+            return AjaxResult.error("数据源重复");
+        }
+        tSuperviseYwlxService.createOnemapTable(tSuperviseYwlx.getSjy());
         return toAjax(tSuperviseYwlxService.insertTSuperviseYwlx(tSuperviseYwlx));
     }
 
@@ -89,6 +101,12 @@ public class TSuperviseYwlxController extends BaseController {
     @Log(title = "数据模板类型", businessType = BusinessType.DELETE)
     @DeleteMapping("/{ywlxs}")
     public AjaxResult remove(@PathVariable String[] ywlxs) {
+        for (String id : ywlxs) {
+            TSuperviseYwlxDo bean = tSuperviseYwlxService.selectTSuperviseYwlxMapperByYwlx(id);
+            if (bean != null) {
+                tSuperviseYwlxService.dropOnemapTable(bean.getSjy());
+            }
+        }
         return toAjax(tSuperviseYwlxService.deleteTSuperviseYwlxByYwlxs(ywlxs));
     }
 }

+ 25 - 0
onemap-modules/onemap-apply/src/main/java/com/onemap/apply/controller/supervise/TSuperviseYwlxFieldController.java

@@ -3,8 +3,11 @@ package com.onemap.apply.controller.supervise;
 import java.util.List;
 import javax.servlet.http.HttpServletResponse;
 
+import com.onemap.apply.domain.supervise.TSuperviseYwlxDo;
 import com.onemap.apply.domain.supervise.TSuperviseYwlxFieldDo;
 import com.onemap.apply.service.supervise.ITSuperviseYwlxFieldService;
+import com.onemap.apply.service.supervise.ITSuperviseYwlxService;
+import com.onemap.common.core.utils.StringUtils;
 import com.onemap.common.core.utils.poi.ExcelUtil;
 import com.onemap.common.core.web.controller.BaseController;
 import com.onemap.common.core.web.domain.AjaxResult;
@@ -31,6 +34,8 @@ import org.springframework.web.bind.annotation.RestController;
 public class TSuperviseYwlxFieldController extends BaseController {
     @Autowired
     private ITSuperviseYwlxFieldService tSuperviseYwlxFieldService;
+    @Autowired
+    private ITSuperviseYwlxService tSuperviseYwlxService;
 
     /**
      * 查询模板字段列表
@@ -67,6 +72,17 @@ public class TSuperviseYwlxFieldController extends BaseController {
     @Log(title = "模板字段", businessType = BusinessType.INSERT)
     @PostMapping
     public AjaxResult add(@RequestBody TSuperviseYwlxFieldDo tSuperviseYwlxField) {
+        if (tSuperviseYwlxField == null) {
+            return AjaxResult.error("参数缺失");
+        }
+        if (StringUtils.isEmpty(tSuperviseYwlxField.getYwlx())) {
+            return AjaxResult.error("参数缺失");
+        }
+        TSuperviseYwlxDo bean = tSuperviseYwlxService.selectTSuperviseYwlxMapperByYwlx(tSuperviseYwlxField.getYwlx());
+        if (bean == null) {
+            return AjaxResult.error("业务类型参数缺失");
+        }
+        tSuperviseYwlxService.addOnemapTableColumn(bean.getSjy(), tSuperviseYwlxField.getFieldname());
         return toAjax(tSuperviseYwlxFieldService.insertTSuperviseYwlxField(tSuperviseYwlxField));
     }
 
@@ -85,6 +101,15 @@ public class TSuperviseYwlxFieldController extends BaseController {
     @Log(title = "模板字段", businessType = BusinessType.DELETE)
     @DeleteMapping("/{ids}")
     public AjaxResult remove(@PathVariable String[] ids) {
+        for (String id : ids) {
+            TSuperviseYwlxFieldDo bean = tSuperviseYwlxFieldService.selectTSuperviseYwlxFieldById(id);
+            if (bean != null) {
+                TSuperviseYwlxDo bean1 = tSuperviseYwlxService.selectTSuperviseYwlxMapperByYwlx(bean.getYwlx());
+                if (bean1 != null) {
+                    tSuperviseYwlxService.dropOnemapTableColumn(bean1.getSjy(), bean.getFieldname());
+                }
+            }
+        }
         return toAjax(tSuperviseYwlxFieldService.deleteTSuperviseYwlxFieldByIds(ids));
     }
 }

+ 16 - 0
onemap-modules/onemap-apply/src/main/java/com/onemap/apply/mapper/supervise/TSuperviseYwlxMapper.java

@@ -2,6 +2,7 @@ package com.onemap.apply.mapper.supervise;
 
 import com.onemap.apply.domain.supervise.TSuperviseYwlxDo;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
@@ -59,4 +60,19 @@ public interface TSuperviseYwlxMapper {
     public int deleteTSuperviseYwlxByYwlxs(String[] ywlxs);
 
 
+    /**
+     * 获取表是否存在
+     * @param tableName 表名
+     * @return
+     */
+    public List<String> getOnemapTable(String tableName);
+
+    public int createOnemapTable(String tableName);
+
+    public int dropOnemapTable(String tableName);
+
+    public int addOnemapTableColumn(@Param("tableName") String tableName, @Param("tableFiled") String tableFiled);
+
+    public int dropOnemapTableColumn(@Param("tableName") String tableName, @Param("tableFiled") String tableFiled);
+
 }

+ 2 - 2
onemap-modules/onemap-apply/src/main/java/com/onemap/apply/mapper/supervise/provider/TSupervisePcsjXqSqlProvider.java

@@ -33,7 +33,7 @@ public class TSupervisePcsjXqSqlProvider {
                 filedBuilder.append(filedList.get(i));
                 dataBuilder.append("public.ST_GeomFromEWKT(#{xq." + filedList.get(i) + "})");
             } else {
-                dataBuilder.append("#{xq." + filedList.get(i) + "}");
+                dataBuilder.append(" CAST('${xq." + filedList.get(i) + "}' as VARCHAR)");
                 filedBuilder.append(filedList.get(i));
             }
         }
@@ -48,7 +48,7 @@ public class TSupervisePcsjXqSqlProvider {
         String tableName = vo.get("tableName");
         StringBuilder sqlBuilder = new StringBuilder("");
         sqlBuilder.append("select count(*) spotsnumber,public.st_asewkt(public.ST_Envelope(PUBLIC.st_union(geom))) envelopegeom,");
-        sqlBuilder.append("sum(").append(sumField.trim()).append(") spotsarea");
+        sqlBuilder.append("sum(").append(sumField.trim()).append("::numeric) spotsarea");
         sqlBuilder.append(" ");
         sqlBuilder.append("from  ").append(tableName).append(" where pcsjid = #{pcsjid} ");
         return sqlBuilder.toString();

+ 10 - 0
onemap-modules/onemap-apply/src/main/java/com/onemap/apply/service/supervise/ITSuperviseYwlxService.java

@@ -55,4 +55,14 @@ public interface ITSuperviseYwlxService {
      * @return 结果
      */
     public int deleteTSuperviseYwlxByYwlx(String ywlx);
+
+    List<String> getOnemapTable(String sjy);
+
+    int addOnemapTableColumn(String sjy, String fileName);
+
+    int dropOnemapTableColumn(String sjy, String fileName);
+
+    int createOnemapTable(String sjy);
+
+    int dropOnemapTable(String sjy);
 }

+ 25 - 0
onemap-modules/onemap-apply/src/main/java/com/onemap/apply/service/supervise/impl/TSuperviseYwlxServiceImpl.java

@@ -85,4 +85,29 @@ public class TSuperviseYwlxServiceImpl implements ITSuperviseYwlxService {
     public int deleteTSuperviseYwlxByYwlx(String ywlx) {
         return tSuperviseYwlxMapper.deleteTSuperviseYwlxByYwlx(ywlx);
     }
+
+    @Override
+    public List<String> getOnemapTable(String sjy) {
+        return tSuperviseYwlxMapper.getOnemapTable(sjy);
+    }
+
+    @Override
+    public int addOnemapTableColumn(String sjy,String fileName) {
+        return tSuperviseYwlxMapper.addOnemapTableColumn(sjy,fileName);
+    }
+
+    @Override
+    public int dropOnemapTableColumn(String sjy,String fileName) {
+        return tSuperviseYwlxMapper.dropOnemapTableColumn(sjy,fileName);
+    }
+
+    @Override
+    public int createOnemapTable(String sjy) {
+        return tSuperviseYwlxMapper.createOnemapTable(sjy);
+    }
+
+    @Override
+    public int dropOnemapTable(String sjy) {
+        return tSuperviseYwlxMapper.dropOnemapTable(sjy);
+    }
 }

+ 35 - 0
onemap-modules/onemap-apply/src/main/resources/mapper/postgresql/supervise/TSuperviseYwlxMapper.xml

@@ -72,4 +72,39 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         </foreach>
     </delete>
 
+    <select id="getOnemapTable" resultType="String">
+        SELECT table_name FROM information_schema.tables  WHERE table_schema = 'onemap' and table_name = #{tableName}
+    </select>
+
+    <update id="createOnemapTable" parameterType="String">
+        CREATE TABLE ${tableName}
+        (
+            id varchar(64) PRIMARY KEY,
+            pcsjid varchar(64)
+        )
+    </update>
+
+    <update id="dropOnemapTable" parameterType="String">
+        drop table ${tableName}
+    </update>
+
+    <update id="addOnemapTableColumn" parameterType="String">
+        alter table ${tableName} add column
+        <choose>
+        <when test="tableFiled == 'geom'">
+            ${tableFiled} public.geometry
+        </when>
+        <otherwise>
+          ${tableFiled} varchar(100)
+         </otherwise>
+        </choose>
+    </update>
+
+
+    <update id="dropOnemapTableColumn" parameterType="String">
+        alter table ${tableName} drop column if exists  ${tableFiled}
+    </update>
+
+
+
 </mapper>