浏览代码

更加了自定义菜单模块

wuweihao 5 年之前
父节点
当前提交
99340e5d9e

二进制
gis_application/src/main/resources/data/dacf7dfa24ae47fab8fcebfe4dc41ab9_50k.dam


+ 8 - 0
gis_domain/src/main/java/com/gis/domain/entity/MenuEntity.java

@@ -19,5 +19,13 @@ public class MenuEntity extends BaseEntity implements Serializable {
     @ApiModelProperty(value = "排序")
     private Integer sort;
 
+    @ApiModelProperty(value = "父级id")
+    private Long parentId;
+
+
+
+
+
+
 
 }

+ 22 - 0
gis_domain/src/main/java/com/gis/domain/entity/NewsEntity.java

@@ -0,0 +1,22 @@
+package com.gis.domain.entity;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.persistence.Table;
+
+/**
+ * Created by owen on 2020/6/10 0010 17:39
+ * 新闻
+ */
+@Data
+@Table(name = "tb_view")
+public class NewsEntity extends BaseEntity {
+
+    @ApiModelProperty(value = "标题" )
+    private String title;
+
+    @ApiModelProperty(value = "请求地址")
+    private String path;
+
+}

+ 0 - 58
gis_domain/src/main/java/com/gis/domain/entity/OverTimeEntity.java

@@ -1,58 +0,0 @@
-package com.gis.domain.entity;
-
-import io.swagger.annotations.ApiModelProperty;
-import lombok.Data;
-
-import javax.persistence.Table;
-import javax.validation.constraints.NotBlank;
-
-/**
- * Created by owen on 2020/6/10 0010 17:39
- */
-@Data
-@Table(name = "tb_over_time")
-public class OverTimeEntity extends BaseEntity {
-
-    @NotBlank(message = "userId不能为空")
-    @ApiModelProperty(value = "userId" , required = true)
-    private String userId;
-
-    @NotBlank(message = "userId不能为空")
-    @ApiModelProperty(value = "用户名称(真名)", required = true)
-    private String userName;
-
-    @NotBlank(message = "工号不能为空")
-    @ApiModelProperty(value = "工号" , required = true)
-    private String jobNumber;
-
-    @NotBlank(message = "userId不能为空")
-    @ApiModelProperty(value = "部门Id", required = true)
-    private String deptId;
-
-    @NotBlank(message = "userId不能为空")
-    @ApiModelProperty(value = "部门名称", required = true)
-    private String deptName;
-
-    @ApiModelProperty(value = "职位名称")
-    private String position;
-
-    @NotBlank(message = "加班开始时间不能为空")
-    @ApiModelProperty(value = "加班开始时间, 格式yyyy-MM-dd HH:mm:ss", required = true)
-    private String startTime;
-
-    @NotBlank(message = "加班结束时间不能为空")
-    @ApiModelProperty(value = "加班结束时间, 格式yyyy-MM-dd HH:mm:ss", required = true)
-    private String endTime;
-
-    @ApiModelProperty(value = "加班时间,单位:小时")
-    private Long totalHours;
-
-    @ApiModelProperty(value = "加班时间,单位:分钟")
-    private Long totalMinutes;
-
-//    @ApiModelProperty(value = "是否周末,1:是, 0:否")
-//    private Integer weekend;
-
-
-
-}

+ 23 - 0
gis_domain/src/main/java/com/gis/domain/entity/ViewEntity.java

@@ -0,0 +1,23 @@
+package com.gis.domain.entity;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.persistence.Table;
+import javax.validation.constraints.NotBlank;
+
+/**
+ * Created by owen on 2020/6/10 0010 17:39
+ * 访问量
+ */
+@Data
+@Table(name = "tb_view")
+public class ViewEntity extends BaseEntity {
+
+    @ApiModelProperty(value = "ip" )
+    private String ip;
+
+    @ApiModelProperty(value = "请求地址")
+    private String path;
+
+}

+ 3 - 0
gis_domain/src/main/java/com/gis/domain/request/MenuRequest.java

@@ -22,4 +22,7 @@ public class MenuRequest {
     @NotNull(message = "排序不能为空")
     @ApiModelProperty(value = "排序", required = true)
     private Integer sort;
+
+    @ApiModelProperty(value = "父级id")
+    private Long parentId;
 }

+ 2 - 8
gis_mapper/src/main/java/com/gis/mapper/OverTimeMapper.java

@@ -1,19 +1,13 @@
 package com.gis.mapper;
 
 
-import com.gis.domain.entity.OverTimeEntity;
-import com.gis.domain.request.PageDateRequest;
-import com.gis.mapper.provider.OverTimeProvider;
+import com.gis.domain.entity.ViewEntity;
 import org.apache.ibatis.annotations.Mapper;
-import org.apache.ibatis.annotations.Select;
-import org.apache.ibatis.annotations.SelectProvider;
 import org.springframework.stereotype.Component;
 
-import java.util.List;
-
 @Component
 @Mapper
-public interface OverTimeMapper extends IBaseMapper<OverTimeEntity, Long> {
+public interface ViewMapper extends IBaseMapper<ViewEntity, Long> {
 
 //    @Select(value = "select * from tb_over_time where rec_status = 'A' ")
 

+ 0 - 17
gis_service/src/main/java/com/gis/service/OverTimeService.java

@@ -1,17 +0,0 @@
-package com.gis.service;
-
-
-import com.gis.domain.entity.OverTimeEntity;
-import com.gis.domain.request.PageDateRequest;
-import org.apache.ibatis.annotations.SelectProvider;
-
-import java.util.List;
-
-
-/**
- * Created by owen on 2020/3/11 0011 16:14
- */
-public interface OverTimeService extends IBaseService<OverTimeEntity, Long> {
-
-
-}

+ 13 - 0
gis_service/src/main/java/com/gis/service/ViewService.java

@@ -0,0 +1,13 @@
+package com.gis.service;
+
+
+import com.gis.domain.entity.ViewEntity;
+
+
+/**
+ * Created by owen on 2020/3/11 0011 16:14
+ */
+public interface ViewService extends IBaseService<ViewEntity, Long> {
+
+
+}

+ 0 - 30
gis_service/src/main/java/com/gis/service/impl/OverTimeServiceImpl.java

@@ -1,30 +0,0 @@
-package com.gis.service.impl;
-
-import com.gis.domain.entity.OverTimeEntity;
-import com.gis.domain.request.PageDateRequest;
-import com.gis.mapper.OverTimeMapper;
-import com.gis.mapper.IBaseMapper;
-import com.gis.service.OverTimeService;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
-import java.util.List;
-
-
-/**
- * Created by owen on 2020/3/11 0011 16:16
- */
-@Service
-public class OverTimeServiceImpl extends IBaseServiceImpl<OverTimeEntity, Long> implements OverTimeService {
-
-    @Autowired
-    private OverTimeMapper entityMapper;
-
-    @Override
-    public IBaseMapper<OverTimeEntity, Long> getBaseMapper() {
-        return this.entityMapper;
-    }
-
-
-
-}

+ 27 - 0
gis_service/src/main/java/com/gis/service/impl/ViewServiceImpl.java

@@ -0,0 +1,27 @@
+package com.gis.service.impl;
+
+import com.gis.domain.entity.ViewEntity;
+import com.gis.mapper.ViewMapper;
+import com.gis.mapper.IBaseMapper;
+import com.gis.service.ViewService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+
+/**
+ * Created by owen on 2020/3/11 0011 16:16
+ */
+@Service
+public class ViewServiceImpl extends IBaseServiceImpl<ViewEntity, Long> implements ViewService {
+
+    @Autowired
+    private ViewMapper entityMapper;
+
+    @Override
+    public IBaseMapper<ViewEntity, Long> getBaseMapper() {
+        return this.entityMapper;
+    }
+
+
+
+}

+ 28 - 0
gis_service/src/main/java/com/gis/service/util/MenuTree.java

@@ -0,0 +1,28 @@
+package com.gis.service.util;
+
+import com.alibaba.fastjson.annotation.JSONField;
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class MenuTree {
+
+    private Long id;
+
+    private String name;
+
+    private Long parentId;
+
+    private Integer sort;
+
+    // 子菜单/或按钮
+    private List<MenuTree> children;
+
+    @JSONField(serialize = false)
+    private int level;
+
+
+
+
+}

+ 101 - 0
gis_service/src/main/java/com/gis/service/util/MenuTreeUtil.java

@@ -0,0 +1,101 @@
+package com.gis.service.util;
+
+import com.gis.domain.entity.MenuEntity;
+import com.gis.domain.entity.SysResourceEntity;
+import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class MenuTreeUtil {
+
+    private List<MenuTree> resultNodes = new ArrayList<MenuTree>();//树形结构排序之后list内容
+
+    private List<MenuTree> nodes = new ArrayList<MenuTree>();
+    //传入list参数
+
+    public MenuTreeUtil(List<MenuEntity> nodesList) {//通过构造函数初始化
+        for (MenuEntity n : nodesList) {
+            MenuTree treeGrid = new MenuTree();
+            treeGrid.setId(n.getId());
+            treeGrid.setName(n.getName());
+            treeGrid.setSort(n.getSort());
+
+            if (n.getParentId() != null) {
+                treeGrid.setParentId(n.getParentId());
+            }
+            nodes.add(treeGrid);
+        }
+    }
+
+    public MenuTreeUtil() {
+    }
+
+    /**
+     * 构建树形结构list
+     *
+     * @return 返回树形结构List列表
+     */
+    public List<MenuTree> buildTree() {
+        for (MenuTree node : nodes) {
+            Long id = node.getParentId();
+            if (id == null) {//通过循环一级节点 就可以通过递归获取二级以下节点
+                resultNodes.add(node);//添加一级节点
+                node.setLevel(1);
+                build(node, node.getLevel());//递归获取二级、三级、。。。节点
+            }
+        }
+        return resultNodes;
+    }
+
+    /**
+     * 递归循环子节点
+     *
+     * @param node 当前节点
+     */
+    private void build(MenuTree node, int level) {
+        List<MenuTree> children = getChildren(node);
+        if (!children.isEmpty()) {//如果存在子节点
+            node.setChildren(children);
+//        	level++;
+            for (MenuTree child : children) {//将子节点遍历加入返回值中
+        		child.setLevel(level);
+                build(child, child.getLevel());
+            }
+        }
+    }
+
+    /**
+     * @param node
+     * @return 返回
+     */
+    private List<MenuTree> getChildren(MenuTree node) {
+        List<MenuTree> children = new ArrayList<MenuTree>();
+        Long id = node.getId();
+        for (MenuTree child : nodes) {
+            if (id.equals(child.getParentId())) {//如果id等于父id
+                children.add(child);//将该节点加入循环列表中
+            }
+        }
+        return children;
+    }
+
+    public List<MenuTree> buildTree(List<SysResourceEntity> all, List<SysResourceEntity> in) {
+        for (SysResourceEntity n : all) {
+            MenuTree treeGrid = new MenuTree();
+            treeGrid.setId(n.getId());
+            treeGrid.setName(n.getName());
+            treeGrid.setSort(n.getSort());
+            for (SysResourceEntity nin : in) {
+                if (nin.getId().equals(n.getId())) {
+                }
+            }
+            if (n.getParentId() != null) {
+                treeGrid.setParentId(n.getParentId());
+            }
+            nodes.add(treeGrid);
+        }
+        return buildTree();
+    }
+
+}

+ 18 - 37
gis_web/src/main/java/com/gis/web/controller/ApiController.java

@@ -28,6 +28,7 @@ import org.springframework.web.multipart.MultipartFile;
 import javax.servlet.http.HttpServletRequest;
 import java.io.FileNotFoundException;
 import java.io.IOException;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -54,6 +55,12 @@ public class ApiController extends BaseController {
             return Result.failure("token header is null");
         }
 
+        SceneEntity entity = sceneService.findBySceneCode(sceneCode);
+        if (entity != null) {
+            log.error("场景码已存在,请更换新场景码: {}", sceneCode);
+            return Result.failure("场景码已存在,请更换新场景码");
+        }
+
         Boolean verify = JwtUtil.isVerify(token, TypeCode.TOKEN_API_KEY);
         if (!verify) {
             log.error("api token 无效");
@@ -80,10 +87,13 @@ public class ApiController extends BaseController {
 
         });
 
-        SceneEntity entity = new SceneEntity();
+
+
+        entity = new SceneEntity();
         entity.setSceneCode(sceneCode);
         entity.setPath(FILE_PATH + sceneCode);
         entity.setSceneTitle(sceneTitle);
+        entity.setUpdateTime(new Date());
 
 
 
@@ -129,6 +139,9 @@ public class ApiController extends BaseController {
     }
 
 
+
+
+
     @ApiOperation("获取场景码")
     @GetMapping("getSceneCode")
     public Result getSceneCode() {
@@ -190,9 +203,11 @@ public class ApiController extends BaseController {
 
         // 2.vision.txt转vision.modeldata
         CreateObjUtil.convertTxtToVisionmodeldata(basePath+"/vision.txt", basePath+"/vision.modeldata");
+        log.info("vision.modeldata转换完成");
 
         // 3. 生成一个空的data2.js, 里面是一个空的json
         FileUtil.writeUtf8String("{}",basePath+"/data2.js");
+        log.info("data2.js创建完成");
 
         // 4. 创建someData.json, 修改sid值为场景码目录
         createSomeData(basePath, sceneCode, sceneTitle);
@@ -201,40 +216,6 @@ public class ApiController extends BaseController {
     }
 
 
-
-//    @ApiOperation("文件转换")
-//    @GetMapping(value = "convert/{sceneCode}")
-//    public Result convert1(@PathVariable  String sceneCode) throws Exception {
-//        SceneEntity entity = sceneService.findBySceneCode(sceneCode);
-//        assert entity != null;
-//        String basePath = entity.getPath();
-//        log.info("filePath: {}", basePath);
-//
-//        // 1. 将XXX_50k.dam写到服务器
-////        FileUtils.fielWrite("", basePath+ "/"+ConstantFileName.modelUUID+"_50k.dam");
-//        String resourceUrl = FileUtils.getResourceUrl(ConstantFileName.modelUUID + "_50k.dam");
-//        FileUtil.writeUtf8String(resourceUrl, basePath+ "/"+ConstantFileName.modelUUID+"_50k.dam");
-//
-//
-//        if(!FileUtil.exist(basePath+"/vision.txt")){
-//            log.error("文件不存在: " + basePath+"/vision.txt");
-//            Result.failure("文件不存在: " + basePath+"/vision.txt");
-//        }
-//
-//        // 2.vision.txt转vision.modeldata
-//        CreateObjUtil.convertTxtToVisionmodeldata(basePath+"/vision.txt", basePath+"/vision.modeldata");
-//
-//        // 3. 生成一个空的data2.js, 里面是一个空的json
-//        FileUtil.writeUtf8String("{}",basePath+"/data2.js");
-//
-//        // 4. 创建someData.json, 修改sid值为场景码目录
-//        String sceneTitle = "1111111111111";
-//        createSomeData(basePath, sceneCode, sceneTitle);
-//
-//        return Result.success();
-//    }
-
-
     @Test
     public void createData2Js(){
         String basePath = "F:\\test\\army";
@@ -246,7 +227,6 @@ public class ApiController extends BaseController {
      * 创建someData.json
      */
     private static void createSomeData(String basePath, String sceneCode, String sceneTitle) throws IOException {
-        log.info("run createSomeData" );
         String path = ResourceUtils.getURL("classpath:").getPath();
         path = path + "data/someData.json";
         log.info("path: {}", path);
@@ -268,7 +248,8 @@ public class ApiController extends BaseController {
 
 
         FileUtil.writeUtf8String(jsonObject.toJSONString(), basePath+"/someData.json");
-        log.info("end createSomeData" );
+
+        log.info("someData.json创建完成");
 
     }
 

+ 2 - 1
gis_web/src/main/java/com/gis/web/controller/ExceptionController.java

@@ -23,7 +23,7 @@ import javax.validation.ValidationException;
  * 这里只可以捕获controller层的异常。
  */
 @Log4j2
-//@RestControllerAdvice
+@RestControllerAdvice
 public class ExceptionController {
 
     // 捕捉shiro的异常
@@ -53,6 +53,7 @@ public class ExceptionController {
     @ExceptionHandler(Exception.class)
     @ResponseStatus(HttpStatus.BAD_REQUEST)
     public Result globalException(HttpServletRequest request, Throwable ex) {
+        log.error(ex);
         return Result.failure(getStatus(request).value(), ex.getMessage());
     }
 

+ 16 - 0
gis_web/src/main/java/com/gis/web/controller/MenuController.java

@@ -7,6 +7,8 @@ import com.gis.domain.request.DeptRequest;
 import com.gis.domain.request.MenuRequest;
 import com.gis.domain.request.PageRequest;
 import com.gis.service.MenuService;
+import com.gis.service.util.MenuTree;
+import com.gis.service.util.MenuTreeUtil;
 import com.github.pagehelper.PageInfo;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -18,6 +20,7 @@ import springfox.documentation.annotations.ApiIgnore;
 import javax.validation.Valid;
 import java.time.LocalDateTime;
 import java.util.Date;
+import java.util.List;
 
 /**
  * Created by owen on 2020/5/8 0008 9:54
@@ -30,6 +33,8 @@ public class MenuController extends BaseController {
     @Autowired
     private MenuService menuService;
 
+
+
     @ApiOperation("列表")
     @PostMapping("list")
     public Result<MenuEntity> list(@RequestBody PageRequest param) {
@@ -70,4 +75,15 @@ public class MenuController extends BaseController {
 
         return Result.success();
     }
+
+    @ApiOperation("获取菜单")
+    @GetMapping("getMenu")
+    public Result getMenu() {
+        List<MenuEntity> entities = menuService.findAll();
+
+        MenuTreeUtil menuTreeUtil = new MenuTreeUtil(entities);
+        List<MenuTree> tree = menuTreeUtil.buildTree();
+
+        return Result.success(tree);
+    }
 }

+ 98 - 0
gis_web/src/main/java/com/gis/web/controller/WebController.java

@@ -0,0 +1,98 @@
+package com.gis.web.controller;
+
+
+import cn.hutool.core.io.FileUtil;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.gis.common.constant.TypeCode;
+import com.gis.common.exception.BaseRuntimeException;
+import com.gis.common.proto.constant.ConstantCmd;
+import com.gis.common.proto.constant.ConstantFileName;
+import com.gis.common.proto.util.CreateObjUtil;
+import com.gis.common.util.FileUtils;
+import com.gis.common.util.RandomUtils;
+import com.gis.common.util.Result;
+import com.gis.domain.entity.SceneEntity;
+import com.gis.domain.entity.ViewEntity;
+import com.gis.service.SceneService;
+import com.gis.service.ViewService;
+import com.gis.web.shiro.JwtUtil;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.log4j.Log4j2;
+import org.apache.commons.lang3.StringUtils;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.util.ResourceUtils;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.servlet.http.HttpServletRequest;
+import java.io.IOException;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Created by owen on 2020/6/10 0010 10:44
+ */
+@Log4j2
+@Api(tags = "展示页接口")
+@RestController
+@RequestMapping("api/web")
+public class WebController extends BaseController {
+
+    @Autowired
+    private ViewService viewService;
+
+
+
+    @ApiOperation("保存访问量")
+    @GetMapping("setCount")
+    public Result setCount(HttpServletRequest request) {
+
+        ViewEntity entity = new ViewEntity();
+        entity.setIp(request.getRemoteAddr());
+        entity.setPath(request.getRequestURI());
+        viewService.save(entity);
+        return Result.success();
+    }
+
+
+    @ApiOperation("访问量")
+    @GetMapping("count")
+    public Result count() {
+        long count = viewService.count();
+        return Result.success(count);
+    }
+//
+//
+//    /**
+//     * 给算法查询服务器文件位置
+//     * m 是场景码
+//     */
+//    @ApiOperation("查询服务器文件夹")
+//    @GetMapping(value = "getFolder")
+//    @ApiImplicitParam(name = "m", value = "场景码", required = true)
+//    public Result getFolder(String m) {
+//        SceneEntity entity = sceneService.findBySceneCode(m);
+//        assert entity != null;
+//        log.info("filePath: {}", entity.getPath());
+//        return Result.success(entity.getPath());
+//    }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+}

二进制
gis_web/src/main/resources/data/dacf7dfa24ae47fab8fcebfe4dc41ab9_50k.dam