Bladeren bron

Merge branch 'master' of http://116.63.33.55/git/read_opc

FinalYu 2 jaren geleden
bovenliggende
commit
23312982db
22 gewijzigde bestanden met toevoegingen van 1004 en 39 verwijderingen
  1. 9 0
      chuanyi-admin/src/api/system/menu.js
  2. 6 5
      chuanyi-admin/src/components/SelectTree/index.vue
  3. 3 1
      chuanyi-admin/src/main.js
  4. 12 1
      chuanyi-admin/src/utils/index.js
  5. 7 10
      chuanyi-admin/src/views/system/dept/index.vue
  6. 9 1
      chuanyi_server/src/main/java/com/judong/chuanyiserver/annotation/WebLogAspect.java
  7. 2 2
      chuanyi_server/src/main/java/com/judong/chuanyiserver/config/OpcServerUaPoolFactory.java
  8. 80 0
      chuanyi_server/src/main/java/com/judong/chuanyiserver/controller/ChannelSettingController.java
  9. 97 0
      chuanyi_server/src/main/java/com/judong/chuanyiserver/controller/DictController.java
  10. 26 0
      chuanyi_server/src/main/java/com/judong/chuanyiserver/dao/ChannelSettingDao.java
  11. 65 0
      chuanyi_server/src/main/java/com/judong/chuanyiserver/dao/DictDao.java
  12. 48 0
      chuanyi_server/src/main/java/com/judong/chuanyiserver/entity/ChannelSetting.java
  13. 46 0
      chuanyi_server/src/main/java/com/judong/chuanyiserver/entity/Dict.java
  14. 17 0
      chuanyi_server/src/main/java/com/judong/chuanyiserver/service/ChannelSettingService.java
  15. 49 0
      chuanyi_server/src/main/java/com/judong/chuanyiserver/service/DictService.java
  16. 90 0
      chuanyi_server/src/main/java/com/judong/chuanyiserver/service/impl/ChannelSettingServiceImpl.java
  17. 13 2
      chuanyi_server/src/main/java/com/judong/chuanyiserver/service/impl/ConnectServiceImpl.java
  18. 109 0
      chuanyi_server/src/main/java/com/judong/chuanyiserver/service/impl/DictServiceImpl.java
  19. 106 7
      chuanyi_server/src/main/java/com/judong/chuanyiserver/util/KepOpcServerUtil.java
  20. 11 10
      chuanyi_server/src/main/java/com/judong/chuanyiserver/util/OpcServerUaUtil.java
  21. 98 0
      chuanyi_server/src/main/resources/mapper/ChannelSettingDao.xml
  22. 101 0
      chuanyi_server/src/main/resources/mapper/DictDao.xml

+ 9 - 0
chuanyi-admin/src/api/system/menu.js

@@ -44,3 +44,12 @@ export function editMenuList(data) {
     data
   })
 }
+
+// 获取父级及所有自己的菜单权限
+export function getTreeMenuList(query) {
+  return request({
+    url: '/menu/getPermissionByMenuId',
+    method: 'get',
+    params: query
+  })
+}

+ 6 - 5
chuanyi-admin/src/components/SelectTree/index.vue

@@ -1,6 +1,6 @@
 <template>
   <div id="app">
-    <treeselect :options="options" :normalizer="normalizer" :placeholder="placeholder" @input="handelInput" />
+    <treeselect :options="options" :placeholder="placeholder" :normalizer="normalizer" @input="handelInput" />
   </div>
 </template>
 
@@ -15,10 +15,6 @@ export default {
     options: {
       type: Array
     },
-    // 自定义键名
-    normalizer: {
-      type: Function
-    },
     // 占位符
     placeholder: {
       type: String
@@ -32,6 +28,11 @@ export default {
   methods: {
     handelInput(val) {
       this.$emit('handelGetValue', val)
+    },
+    normalizer(node) {
+      return {
+        label: node.departmentName
+      }
     }
   }
 }

+ 3 - 1
chuanyi-admin/src/main.js

@@ -13,7 +13,9 @@ import './permission'
 import './utils/error-log'
 import * as filters from './filters'
 import Pagination from '@/components/Pagination'
+import { delTreeChildrenNode } from './utils/index'
 
+Vue.prototype.$delTreeChildrenNode = delTreeChildrenNode
 /**
  * If you don't want to use mock-server
  * you want to use MockJs for mock api
@@ -30,7 +32,7 @@ if (process.env.NODE_ENV === 'production') {
 Vue.component('Pagination', Pagination)
 
 Vue.use(Element, {
-  size: Cookies.get('size') || 'medium', // set element-ui default size
+  size: Cookies.get('size') || 'medium' // set element-ui default size
 })
 
 // register global utility filters

+ 12 - 1
chuanyi-admin/src/utils/index.js

@@ -45,7 +45,7 @@ export function parseTime(time, cFormat) {
   const time_str = format.replace(/{([ymdhisa])+}/g, (result, key) => {
     const value = formatObj[key]
     // Note: getDay() returns 0 on Sunday
-    if (key === 'a') { return ['日', '一', '二', '三', '四', '五', '六'][value ] }
+    if (key === 'a') { return ['日', '一', '二', '三', '四', '五', '六'][value] }
     return value.toString().padStart(2, '0')
   })
   return time_str
@@ -355,3 +355,14 @@ export function removeClass(ele, cls) {
     ele.className = ele.className.replace(reg, ' ')
   }
 }
+
+/** 删除树形数据子节点children */
+export function delTreeChildrenNode(data) {
+  for (let i = 0; i < data.length; i++) {
+    if (data[i].children && data[i].children.length > 0) {
+      delTreeChildrenNode(data[i].children)
+    } else {
+      delete data[i].children
+    }
+  }
+}

+ 7 - 10
chuanyi-admin/src/views/system/dept/index.vue

@@ -60,8 +60,8 @@
           <el-col :span="24">
             <el-form-item label="上级部门" prop="parentId">
               <selectTree
+                v-if="options.length"
                 :options="options"
-                :normalizer="normalizer"
                 placeholder="请选择上级部门"
                 @handelGetValue="handelGetValue"
               />
@@ -147,8 +147,7 @@ export default {
       multiple: true,
       // 删除部门id集合
       ids: [],
-      // 自定义树状键名
-      normalizer: null
+      name: null
     }
   },
   created() {
@@ -168,13 +167,11 @@ export default {
     /** 获取上级部门 */
     getOptionsList() {
       getAllSonMenuList().then(res => {
-        this.options = res.data
-        /** 自定义上级部门键名 */
-        this.normalizer = function(node) {
-          return {
-            label: node.departmentName
-          }
-        }
+        const data = res.data
+        this.$nextTick(() => {
+          this.$delTreeChildrenNode(data)
+          this.options = data
+        })
       })
     },
     /** 搜索 */

+ 9 - 1
chuanyi_server/src/main/java/com/judong/chuanyiserver/annotation/WebLogAspect.java

@@ -2,17 +2,21 @@ package com.judong.chuanyiserver.annotation;
 
 import cn.hutool.core.convert.Convert;
 import cn.hutool.extra.servlet.ServletUtil;
+import com.alibaba.fastjson.JSONObject;
 import com.judong.chuanyiserver.dao.UserDao;
 import com.judong.chuanyiserver.entity.Log;
 import com.judong.chuanyiserver.entity.User;
 import com.judong.chuanyiserver.service.LogService;
+import com.judong.chuanyiserver.util.Blank;
 import com.judong.chuanyiserver.util.RedisUtil;
+import com.judong.chuanyiserver.util.Result;
 import lombok.extern.slf4j.Slf4j;
 import org.aspectj.lang.JoinPoint;
 import org.aspectj.lang.ProceedingJoinPoint;
 import org.aspectj.lang.Signature;
 import org.aspectj.lang.annotation.*;
 import org.aspectj.lang.reflect.MethodSignature;
+import org.springframework.beans.BeanUtils;
 import org.springframework.core.annotation.Order;
 import org.springframework.stereotype.Component;
 
@@ -105,7 +109,11 @@ public class WebLogAspect {
             log.setModelName(webLog.ModelEnum().getValue());
         }
         log.setMethodName(methodName);
-        log.setOperationStatus(1);
+        if (Blank.isNotEmpty(result)) {
+            if (result instanceof Result){
+                log.setOperationStatus(((Result) result).getCode());
+            }
+        }
         log.setContent("操作类型:" + webLog.OperationEnum().getValue() + "\n请求参数:" + requestArgs + "\n响应结果:" + result.toString());
         String userId = Convert.toStr(redisUtil.get(request.getHeader("token")));
         User user = userDao.getUserById(userId);

+ 2 - 2
chuanyi_server/src/main/java/com/judong/chuanyiserver/config/OpcServerUaPoolFactory.java

@@ -162,7 +162,7 @@ public class OpcServerUaPoolFactory {
                 opcUaClient.connect().get();
                 return opcUaClient;
             } catch (Exception e) {
-                opcUaClient.disconnect();
+                opcUaClient.disconnect().get();
                 throw new CustomException(ResultEnum.SERVER_ERROR.getRespCode(), e.getMessage());
             }
         }
@@ -207,7 +207,7 @@ public class OpcServerUaPoolFactory {
          */
         public void destroyObject(String key, PooledObject<OpcUaClient> p)
                 throws Exception {
-            p.getObject().disconnect();
+            p.getObject().disconnect().get();
             log.info("对象" + p.getObject() + "被摧毁了");
         }
 

+ 80 - 0
chuanyi_server/src/main/java/com/judong/chuanyiserver/controller/ChannelSettingController.java

@@ -0,0 +1,80 @@
+package com.judong.chuanyiserver.controller;
+
+import com.judong.chuanyiserver.entity.ChannelSetting;
+import com.judong.chuanyiserver.enums.ResultEnum;
+import com.judong.chuanyiserver.service.ChannelSettingService;
+import com.judong.chuanyiserver.util.Blank;
+import com.judong.chuanyiserver.util.Result;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+import java.util.List;
+
+@RestController
+@RequestMapping("channelSetting")
+@Slf4j
+public class ChannelSettingController {
+
+    @Resource
+    private ChannelSettingService channelSettingService;
+
+    /**
+     * 保存通道配置
+     *
+     * @param channelSetting
+     * @return
+     */
+    @PostMapping("/channelSetting")
+    public Result channelSetting(@RequestBody ChannelSetting channelSetting) {
+        if (Blank.isEmpty(channelSetting, channelSetting.getServerId(), channelSetting.getChannelName())) {
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
+        }
+        return channelSettingService.channelSetting(channelSetting);
+    }
+
+    /**
+     * 通过服务器id和通道名称获取通道的配置信息
+     *
+     * @param serverId
+     * @param channelName
+     * @return
+     */
+    @GetMapping("/getChannelSetting")
+    public Result getChannelSetting(Integer serverId, String channelName) {
+        if (Blank.isEmpty(serverId, channelName)) {
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
+        }
+        return channelSettingService.getChannelSetting(serverId, channelName);
+    }
+
+    /**
+     * 通过服务器id获取此服务器下未分配的树节点
+     *
+     * @param serverId
+     * @return
+     */
+    @GetMapping("/getConnectTree")
+    public Result getConnectTree(Integer serverId) {
+        if (Blank.isEmpty(serverId)) {
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
+        }
+        return channelSettingService.getConnectTree(serverId);
+    }
+
+    /**
+     * 保存配置里面的通道配置
+     *
+     * @param serverId
+     * @param channelNameList
+     * @param configName
+     * @return
+     */
+    @PostMapping("/assignChannelSettingList")
+    public Result assignChannelSettingList(Integer serverId, List<String> channelNameList, String configName) {
+        if (Blank.isEmpty(serverId, channelNameList, configName)) {
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
+        }
+        return channelSettingService.assignChannelSettingList(serverId, channelNameList, configName);
+    }
+}

+ 97 - 0
chuanyi_server/src/main/java/com/judong/chuanyiserver/controller/DictController.java

@@ -0,0 +1,97 @@
+package com.judong.chuanyiserver.controller;
+
+
+import com.judong.chuanyiserver.entity.Dict;
+import com.judong.chuanyiserver.enums.ResultEnum;
+import com.judong.chuanyiserver.service.DictService;
+import com.judong.chuanyiserver.util.Blank;
+import com.judong.chuanyiserver.util.Result;
+import org.apache.ibatis.annotations.Param;
+import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+import java.util.List;
+
+@RestController
+@RequestMapping("dict")
+public class DictController {
+
+    @Resource
+    private DictService dictService;
+
+
+    /**
+     * 查询所有数据
+     */
+    @GetMapping("/queryAll")
+    public Result queryAll(){
+        return dictService.queryAll();
+    }
+
+    /**
+     * 分页查询
+     * param dictKey
+     * param dictValue
+     * param page
+     * param num
+     */
+    @GetMapping("/queryPage")
+    public Result queryPage(String dictKey,String dictValue,Integer page,Integer num){
+        if (Blank.isEmpty(page,num)){
+            return  Result.no(ResultEnum.SERVER_ERROR.getRespCode(), "参数错误");
+        }
+        return dictService.queryPage(dictKey, dictValue, page, num);
+    }
+
+
+    /**
+     * 根据id或者dice_key查询
+     */
+    @GetMapping("/queryByIdorKey")
+    public Result queryByIdOrKey(Integer id,String dictKey,Integer page,Integer num){
+        if (Blank.isEmpty(page,num)){
+            return  Result.no(ResultEnum.SERVER_ERROR.getRespCode(), "参数错误");
+        }
+        return dictService.queryByIdOrKey(id, dictKey,page,num);
+    }
+
+    /**
+     * 根据父id查子节点信息 树结构
+     * param parentId
+     */
+    @GetMapping("/queryByParentId")
+    public Result queryByParentId(Integer parentId){
+        if (Blank.isEmpty(parentId)){
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "父id不能为空");
+        }
+        List<Dict> dicts = dictService.queryByParentId(parentId);
+        return Result.ok(dicts);
+    }
+
+    /**
+     * 新增
+     */
+    @PostMapping("/addDict")
+    public Result addDict(@RequestBody Dict dict){
+        return dictService.addDict(dict);
+    }
+
+    /**
+     * 根据id修改
+     */
+    @PostMapping("/updateById")
+    public Result updataById(@RequestBody Dict dict){
+        return dictService.updataById(dict);
+    }
+
+    /**
+     * 根据id删除(批量)
+     */
+    @GetMapping("deleteById")
+    public Result deleteByid(@RequestParam("ids") List<Integer> ids){
+        return dictService.deleteByid(ids);
+    }
+
+
+
+}

+ 26 - 0
chuanyi_server/src/main/java/com/judong/chuanyiserver/dao/ChannelSettingDao.java

@@ -0,0 +1,26 @@
+package com.judong.chuanyiserver.dao;
+
+import com.judong.chuanyiserver.entity.ChannelSetting;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+
+@Repository
+public interface ChannelSettingDao {
+
+    ChannelSetting getChannelBySeChName(Integer serverId, String channelName);
+
+    Integer addChannelSetting(ChannelSetting channelSetting);
+
+    ChannelSetting getLabelByIdSeChName(Integer id, Integer serverId, String channelName);
+
+    Integer updateChannelSetting(ChannelSetting channelSetting);
+
+    List<String> getConfigList(int serverId);
+
+    List<ChannelSetting> getChannelListNoConfig(Integer serverId);
+
+    Integer clearConfigByName(Integer serverId, String configName);
+
+    Integer addConfigByName(Integer serverId, List<String> channelNameList, String configName);
+}

+ 65 - 0
chuanyi_server/src/main/java/com/judong/chuanyiserver/dao/DictDao.java

@@ -0,0 +1,65 @@
+package com.judong.chuanyiserver.dao;
+
+import com.judong.chuanyiserver.entity.Dict;
+import org.apache.ibatis.annotations.Param;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+
+@Repository
+public interface DictDao {
+
+    /**
+     * 查询所有数据
+     */
+    List<Dict> queryAll();
+
+    /**
+     * 分页查询
+     * param dictKey
+     * param dictValue
+     * param page
+     * param num
+     */
+    List<Dict> queryPage(String dictKey,String dictValue,Integer page,Integer num);
+
+    /**
+     * 查询总条数
+     */
+    Integer queryNumber(String dictKey,String dictValue);
+
+    /**
+     * 根据id或者dice_key查询
+     */
+    List<Dict> queryByIdOrKey(Integer id,String dictKey,Integer page,Integer num);
+
+    /**
+     * 根据id或者dice_key查询总条数
+     */
+    Integer queryByIdOrKeyNum(Integer id,String dictKey);
+
+    /**
+     * 根据父id查子节点信息 树结构
+     */
+    List<Dict> queryByParentId(Integer parentId);
+
+    /**
+     * 新增
+     */
+    Integer addDict(@Param("dict") Dict dict);
+
+    /**
+     * 根据id修改
+     */
+    Integer updataById(@Param("dict") Dict dict);
+
+    /**
+     * 根据id删除(批量)
+     */
+    Integer deleteByid(@Param("ids") List<Integer> ids);
+
+    Dict queryById(Integer id);
+
+
+
+}

+ 48 - 0
chuanyi_server/src/main/java/com/judong/chuanyiserver/entity/ChannelSetting.java

@@ -0,0 +1,48 @@
+package com.judong.chuanyiserver.entity;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+public class ChannelSetting implements Serializable {
+
+    private static final long serialVersionUID = -96536212774977561L;
+
+    /**
+     * 主键id
+     */
+    private Integer id;
+    /**
+     * 服务器id
+     */
+    private Integer serverId;
+    /**
+     * 标签原始名称
+     */
+    private String channelName;
+    /**
+     * 标签映射名称
+     */
+    private String channelMapName;
+    /**
+     * 数据类型
+     */
+    private Integer dataType;
+    /**
+     * 读取机制
+     */
+    private Integer readMechanism;
+    /**
+     * 读取策略
+     */
+    private Integer readPolicy;
+    /**
+     * 策略值
+     */
+    private String policyValue;
+    /**
+     * 配置名称
+     */
+    private String configurationName;
+}

+ 46 - 0
chuanyi_server/src/main/java/com/judong/chuanyiserver/entity/Dict.java

@@ -0,0 +1,46 @@
+package com.judong.chuanyiserver.entity;
+
+import lombok.Data;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@Data
+public class Dict {
+
+    /**
+     *id
+     */
+    private Integer id;
+
+    /**
+     *父id
+     */
+    private Integer parentId;
+
+    /**
+     *字典编码
+     */
+    private String dictKey;
+
+    /**
+     *字典值
+     */
+    private String dictValue;
+
+    /**
+     *排序号
+     */
+    private Integer sortNum;
+
+    /**
+     *创建时间
+     */
+    private String createTime;
+
+    /**
+     * 子节点
+     */
+    private List<Dict> children=new ArrayList<>();
+
+}

+ 17 - 0
chuanyi_server/src/main/java/com/judong/chuanyiserver/service/ChannelSettingService.java

@@ -0,0 +1,17 @@
+package com.judong.chuanyiserver.service;
+
+import com.judong.chuanyiserver.entity.ChannelSetting;
+import com.judong.chuanyiserver.util.Result;
+
+import java.util.List;
+
+public interface ChannelSettingService {
+
+    Result channelSetting(ChannelSetting channelSetting);
+
+    Result getChannelSetting(Integer serverId,String ChannelName);
+
+    Result getConnectTree(Integer serverId);
+
+    Result assignChannelSettingList(Integer serverId, List<String> channelNameList, String configName);
+}

+ 49 - 0
chuanyi_server/src/main/java/com/judong/chuanyiserver/service/DictService.java

@@ -0,0 +1,49 @@
+package com.judong.chuanyiserver.service;
+
+import com.judong.chuanyiserver.entity.Dict;
+import com.judong.chuanyiserver.util.Result;
+
+import java.util.List;
+
+public interface DictService {
+    /**
+     * 查询所有数据
+     */
+    Result queryAll();
+
+    /**
+     * 分页查询
+     * param dictKey
+     * param dictValue
+     * param page
+     * param num
+     */
+    Result queryPage(String dictKey,String dictValue,Integer page,Integer num);
+
+
+    /**
+     * 根据id或者dice_key查询
+     */
+    Result queryByIdOrKey(Integer id,String diceKey,Integer page,Integer num);
+
+    /**
+     * 根据父id查子节点信息 树结构
+     * param parentId
+     */
+    List<Dict> queryByParentId(Integer parentId);
+
+    /**
+     * 新增
+     */
+    Result addDict(Dict dict);
+
+    /**
+     * 根据id修改
+     */
+    Result updataById(Dict dict);
+
+    /**
+     * 根据id删除(批量)
+     */
+    Result deleteByid( List<Integer> ids);
+}

+ 90 - 0
chuanyi_server/src/main/java/com/judong/chuanyiserver/service/impl/ChannelSettingServiceImpl.java

@@ -0,0 +1,90 @@
+package com.judong.chuanyiserver.service.impl;
+
+import com.alibaba.fastjson.JSONObject;
+import com.judong.chuanyiserver.dao.ConnectDao;
+import com.judong.chuanyiserver.dao.ChannelSettingDao;
+import com.judong.chuanyiserver.entity.ChannelSetting;
+import com.judong.chuanyiserver.entity.ServerInformation;
+import com.judong.chuanyiserver.enums.ConnectModeEnum;
+import com.judong.chuanyiserver.enums.ResultEnum;
+import com.judong.chuanyiserver.service.ChannelSettingService;
+import com.judong.chuanyiserver.util.Blank;
+import com.judong.chuanyiserver.util.KepOpcServerUtil;
+import com.judong.chuanyiserver.util.Result;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.annotation.Resource;
+import java.util.List;
+
+@Service
+@Transactional
+public class ChannelSettingServiceImpl implements ChannelSettingService {
+
+    @Resource
+    private ConnectDao connectDao;
+
+    @Resource
+    private ChannelSettingDao channelSettingDao;
+
+    @Override
+    public synchronized Result channelSetting(ChannelSetting channelSetting) {
+        if (Blank.isEmpty(channelSetting.getId())) {
+            ChannelSetting isExistChannelSetting = channelSettingDao.getChannelBySeChName(channelSetting.getServerId(), channelSetting.getChannelName());
+            if (Blank.isNotEmpty(isExistChannelSetting)) {
+                return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "已经存在此标签配置,请更换标签名称");
+            }
+            if (channelSettingDao.addChannelSetting(channelSetting) <= 0) {
+                return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), "保存标签配置失败");
+            }
+            return Result.ok("保存标签配置成功");
+        } else {
+            ChannelSetting isExistChannelSetting = channelSettingDao.getLabelByIdSeChName(channelSetting.getId(), channelSetting.getServerId(), channelSetting.getChannelName());
+            if (Blank.isNotEmpty(isExistChannelSetting)) {
+                return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "已经存在此标签配置,请更换标签名称");
+            }
+            if (channelSettingDao.updateChannelSetting(channelSetting) <= 0) {
+                return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), "保存标签配置失败");
+            }
+            return Result.ok("保存标签配置成功");
+        }
+    }
+
+    @Override
+    public Result getChannelSetting(Integer serverId, String channelName) {
+        return Result.ok(channelSettingDao.getChannelBySeChName(serverId, channelName));
+    }
+
+    @Override
+    public Result getConnectTree(Integer serverId) {
+        ServerInformation serverInformation = connectDao.getServerInformationById(serverId);
+        if (Blank.isEmpty(serverInformation)) {
+            return Result.no(ResultEnum.NOT_FOUND.getRespCode(), ResultEnum.NOT_FOUND.getRespMsg());
+        }
+        if (serverInformation.getConnectMode() == ConnectModeEnum.KEPOPCSERVER.getValue()) {
+            if (KepOpcServerUtil.validationServerInformation(serverInformation)) {
+                JSONObject jsonObject = new JSONObject();
+                List<ChannelSetting> channelSettings = channelSettingDao.getChannelListNoConfig(serverId);
+                if (Blank.isNotEmpty(channelSettings)) {
+                    jsonObject.put("tree", KepOpcServerUtil.opcNoConfigTree(serverInformation, channelSettings));
+                } else {
+                    jsonObject.put("tree", KepOpcServerUtil.opcReadItemTree(serverInformation));
+                }
+                return Result.ok(jsonObject);
+            }
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
+        }
+        return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "后续类型带更新");
+    }
+
+    @Override
+    public synchronized Result assignChannelSettingList(Integer serverId, List<String> channelNameList, String configName) {
+        //清空配置名称为configName的通道配置
+        channelSettingDao.clearConfigByName(serverId, configName);
+        //给传入的List都添加configName
+        if (channelSettingDao.addConfigByName(serverId, channelNameList, configName) <= 0) {
+            return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), "保存配置失败");
+        }
+        return Result.ok("保存配置成功");
+    }
+}

+ 13 - 2
chuanyi_server/src/main/java/com/judong/chuanyiserver/service/impl/ConnectServiceImpl.java

@@ -1,6 +1,8 @@
 package com.judong.chuanyiserver.service.impl;
 
+import com.alibaba.fastjson.JSONObject;
 import com.judong.chuanyiserver.dao.ConnectDao;
+import com.judong.chuanyiserver.dao.ChannelSettingDao;
 import com.judong.chuanyiserver.entity.ServerInformation;
 import com.judong.chuanyiserver.enums.ConnectModeEnum;
 import com.judong.chuanyiserver.enums.ResultEnum;
@@ -12,6 +14,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
+import java.util.List;
 
 @Service
 @Transactional
@@ -24,6 +27,9 @@ public class ConnectServiceImpl implements ConnectService {
     @Resource
     private UserUtil userUtil;
 
+    @Resource
+    private ChannelSettingDao channelSettingDao;
+
     @Override
     public Result testConnect(ServerInformation serverInformation) {
         try {
@@ -155,14 +161,19 @@ public class ConnectServiceImpl implements ConnectService {
         }
         serverInformation.setIpPassword(RSAUtil.decrypt(serverInformation.getIpPassword(), "utf-8"));
         //如果连接方式为kepserver
+        JSONObject jsonObject = new JSONObject();
+        List<String> configList = channelSettingDao.getConfigList(id);
+        jsonObject.put("config", configList);
         if (serverInformation.getConnectMode() == ConnectModeEnum.KEPOPCSERVER.getValue()) {
             if (KepOpcServerUtil.validationServerInformation(serverInformation)) {
-                return KepOpcServerUtil.opcReadItemTree(serverInformation);
+                jsonObject.put("tree", KepOpcServerUtil.opcReadItemTree(serverInformation));
+                return Result.ok(jsonObject);
             }
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
         } else if (serverInformation.getConnectMode() == ConnectModeEnum.KingOPCServer.getValue()) {
             if (OpcServerUaUtil.validationServerInformation(serverInformation)) {
-                return OpcServerUaUtil.opcReadItemTree(serverInformation);
+                jsonObject.put("tree", OpcServerUaUtil.opcReadItemTree(serverInformation));
+                return Result.ok(jsonObject);
             }
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
         } else {

+ 109 - 0
chuanyi_server/src/main/java/com/judong/chuanyiserver/service/impl/DictServiceImpl.java

@@ -0,0 +1,109 @@
+package com.judong.chuanyiserver.service.impl;
+
+import com.alibaba.fastjson.JSONObject;
+import com.judong.chuanyiserver.dao.DictDao;
+import com.judong.chuanyiserver.entity.Dict;
+import com.judong.chuanyiserver.enums.ResultEnum;
+import com.judong.chuanyiserver.service.DictService;
+import com.judong.chuanyiserver.util.Blank;
+import com.judong.chuanyiserver.util.Result;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.List;
+
+
+@Service
+@Transactional
+public class DictServiceImpl implements DictService {
+
+    @Resource
+    private DictDao dictDao;
+
+    @Override
+    public Result queryAll() {
+        List<Dict> dicts = dictDao.queryAll();
+        if (dicts.size()<=0){
+            return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), "暂无数据");
+        }
+        return Result.ok(dicts);
+    }
+
+    @Override
+    public Result queryPage(String dictKey, String dictValue, Integer page, Integer num) {
+        JSONObject jsonObject = new JSONObject();
+        Integer count = dictDao.queryNumber(dictKey, dictValue);
+        Integer startNum=(page-1)*num;
+        List<Dict> dictPage = dictDao.queryPage(dictKey, dictValue, startNum, num);
+        if (dictPage.size()<=0){
+            return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), "暂无数据");
+        }
+        jsonObject.put("count",count);
+        jsonObject.put("dictPage",dictPage);
+        return Result.ok(jsonObject);
+    }
+
+    @Override
+    public Result queryByIdOrKey(Integer id, String diceKey,Integer page,Integer num) {
+        JSONObject jsonObject = new JSONObject();
+        Integer count = dictDao.queryByIdOrKeyNum(id, diceKey);
+        Integer statrNum=(page-1)*num;
+        List<Dict> dicts = dictDao.queryByIdOrKey(id, diceKey,statrNum,num);
+        if (dicts.size()<=0){
+            return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), "暂无数据");
+        }
+        jsonObject.put("count",count);
+        jsonObject.put("dicts",dicts);
+        return Result.ok(jsonObject);
+    }
+
+    @Override
+    public List<Dict> queryByParentId(Integer parentId) {
+        //存放节点数据
+        List<Dict> dictAll = new ArrayList<>();
+        //根据父节点获取子节点对象
+        List<Dict> dictSon = dictDao.queryByParentId(parentId);
+        //判断子节点是否为其他节点的父节点
+        for (Dict d : dictSon){
+            d.setChildren(queryByParentId(d.getId()));
+            dictAll.add(d);
+        }
+        return dictAll;
+    }
+
+    @Override
+    public Result addDict(Dict dict) {
+        if (Blank.isEmpty(dict.getParentId(),dict.getDictKey(),dict.getDictValue(),dict.getSortNum())){
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "父id,字典key,字典值以及序号不能为空");
+        }
+        dictDao.addDict(dict);
+        return Result.ok("新增成功");
+    }
+
+    @Override
+    public Result updataById(Dict dict) {
+        if (Blank.isEmpty(dict.getParentId(),dict.getDictKey(),dict.getDictValue(),dict.getSortNum(),dict.getId())){
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "id,父id,字典key,字典值以及序号不能为空");
+        }
+        //判断是否有数据
+        Dict dictShow = dictDao.queryById(dict.getId());
+        if (dictShow==null){
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "修改失败");
+        }
+        if (dictDao.updataById(dict)<=0){
+            throw new ClassCastException("修改失败");
+        }
+        return Result.ok("修改成功");
+    }
+
+    @Override
+    public Result deleteByid(List<Integer> ids) {
+        if (ids.size()<=0){
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "id不能为空");
+        }
+        Integer integer = dictDao.deleteByid(ids);
+        return Result.ok(integer);
+    }
+}

+ 106 - 7
chuanyi_server/src/main/java/com/judong/chuanyiserver/util/KepOpcServerUtil.java

@@ -2,9 +2,11 @@ package com.judong.chuanyiserver.util;
 
 import com.alibaba.fastjson.JSONObject;
 import com.judong.chuanyiserver.config.KepOpcServerPoolFactory;
+import com.judong.chuanyiserver.entity.ChannelSetting;
 import com.judong.chuanyiserver.entity.ServerInformation;
 import com.judong.chuanyiserver.enums.ConnectModeEnum;
 import com.judong.chuanyiserver.enums.ResultEnum;
+import com.judong.chuanyiserver.exception.CustomException;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.pool2.impl.GenericKeyedObjectPool;
 import org.jinterop.dcom.common.JIException;
@@ -163,25 +165,44 @@ public class KepOpcServerUtil {
      * @return
      * @throws Exception
      */
-    public static Result opcReadItemTree(ServerInformation serverInformation) {
+    public static List<JSONObject> opcReadItemTree(ServerInformation serverInformation) {
         try {
             String opcServerDaPoolKey = KepOpcServerUtil.generateOpcPoolKey(serverInformation);
             if (KepOpcServerUtil.validationKey(opcServerDaPoolKey)) {
                 Server server = KepOpcServerUtil.getServer(opcServerDaPoolKey);
                 if (null == server.getServerState()) {
-                    return Result.no(ResultEnum.NOT_FOUND.getRespCode(), "连接失败");
+                    throw new CustomException(ResultEnum.NOT_FOUND.getRespCode(), "连接失败");
                 }
                 if (OPCSERVERSTATE.OPC_STATUS_RUNNING == server.getServerState().getServerState()) {
-                    JSONObject jsonObject = new JSONObject();
-                    jsonObject.put("tree", generOpcTree(server));
+                    List<JSONObject> jsonObjectList = generOpcTree(server);
                     KepOpcServerUtil.returnServer(opcServerDaPoolKey, server);
-                    return Result.ok(jsonObject);
+                    return jsonObjectList;
                 }
             }
         } catch (Exception e) {
-            return Result.no(ResultEnum.REQUEST_TIME_OUT.getRespCode(), e.getMessage());
+            throw new CustomException(ResultEnum.REQUEST_TIME_OUT.getRespCode(), e.getMessage());
         }
-        return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), ResultEnum.SERVER_ERROR.getRespMsg());
+        throw new CustomException(ResultEnum.SERVER_ERROR.getRespCode(), ResultEnum.SERVER_ERROR.getRespMsg());
+    }
+
+    public static List<JSONObject> opcNoConfigTree(ServerInformation serverInformation, List<ChannelSetting> channelSettings) {
+        try {
+            String opcServerDaPoolKey = KepOpcServerUtil.generateOpcPoolKey(serverInformation);
+            if (KepOpcServerUtil.validationKey(opcServerDaPoolKey)) {
+                Server server = KepOpcServerUtil.getServer(opcServerDaPoolKey);
+                if (null == server.getServerState()) {
+                    throw new CustomException(ResultEnum.NOT_FOUND.getRespCode(), "连接失败");
+                }
+                if (OPCSERVERSTATE.OPC_STATUS_RUNNING == server.getServerState().getServerState()) {
+                    List<JSONObject> jsonObjectList = generOpcNoConfigTree(server, channelSettings);
+                    KepOpcServerUtil.returnServer(opcServerDaPoolKey, server);
+                    return jsonObjectList;
+                }
+            }
+        } catch (Exception e) {
+            throw new CustomException(ResultEnum.REQUEST_TIME_OUT.getRespCode(), e.getMessage());
+        }
+        throw new CustomException(ResultEnum.SERVER_ERROR.getRespCode(), ResultEnum.SERVER_ERROR.getRespMsg());
     }
 
     public static Result closeConnect(ServerInformation serverInformation) {
@@ -277,6 +298,84 @@ public class KepOpcServerUtil {
         return jsonObjectList;
     }
 
+    public static List<JSONObject> generOpcNoConfigTree(Server server, List<ChannelSetting> channelSettings) throws JIException, UnknownHostException {
+        List<JSONObject> jsonList = new ArrayList<>();
+        //获取服务器下所有ITEM列表,树形展示
+        TreeBrowser treeBrowser = server.getTreeBrowser();
+        Branch browse = treeBrowser.browse();
+        if (Blank.isEmpty(browse)) {
+            return null;
+        }
+        Collection<Branch> branches = browse.getBranches();
+        for (Branch branch : branches) {
+            Iterator<ChannelSetting> iterator = channelSettings.iterator();
+            if (Blank.isNotEmpty(branch.getBranches())) {
+                String branchName = branch.getName();
+                Boolean flage = true;
+                while (iterator.hasNext()) {
+                    if (iterator.next().getChannelName().equals(branchName)) {
+                        flage = false;
+                        iterator.remove();
+                    }
+                }
+                if (flage) {
+                    JSONObject jsonObject = new JSONObject();
+                    jsonObject.put("label", branchName);
+                    jsonObject.put("children", recursionNoConfigChildren(branch.getBranches(), channelSettings, branchName));
+                    jsonList.add(jsonObject);
+                }
+            }
+        }
+        return jsonList;
+    }
+
+    public static List<JSONObject> recursionNoConfigChildren(Collection<Branch> branchCollection, List<ChannelSetting> channelSettings, String branchName) {
+        List<JSONObject> jsonList = new ArrayList<>();
+        for (Branch branch : branchCollection) {
+            Iterator<ChannelSetting> iterator = channelSettings.iterator();
+            String newBranchName = branchName + "." + branch.getName();
+            Boolean flage = true;
+            while (iterator.hasNext()) {
+                if (iterator.next().getChannelName().equals(newBranchName)) {
+                    flage = false;
+                    iterator.remove();
+                }
+            }
+            if (flage) {
+                JSONObject jsonObject = new JSONObject();
+                jsonObject.put("label", branch.getName());
+                if (Blank.isNotEmpty(branch.getBranches())) {
+                    jsonObject.put("children", recursionNoConfigChildren(branch.getBranches(), channelSettings, newBranchName));
+                } else {
+                    jsonObject.put("children", generNoConfigLeaf(branch.getLeaves(), channelSettings, newBranchName));
+                }
+                jsonList.add(jsonObject);
+            }
+        }
+        return jsonList;
+    }
+
+    public static List<JSONObject> generNoConfigLeaf(Collection<Leaf> leaves, List<ChannelSetting> channelSettings, String branchName) {
+        List<JSONObject> jsonObjectList = new ArrayList<>();
+        for (Leaf leaf : leaves) {
+            Iterator<ChannelSetting> iterator = channelSettings.iterator();
+            String newBranchName = branchName + "." + leaf.getName();
+            Boolean flage = true;
+            while (iterator.hasNext()) {
+                if (iterator.next().getChannelName().equals(newBranchName)) {
+                    flage = false;
+                }
+            }
+            if (flage) {
+                JSONObject jsonObject = new JSONObject();
+                jsonObject.put("label", leaf.getName());
+                jsonObjectList.add(jsonObject);
+            }
+        }
+        return jsonObjectList;
+    }
+
+
     /**
      * 通过itemid获取响应的值
      *

+ 11 - 10
chuanyi_server/src/main/java/com/judong/chuanyiserver/util/OpcServerUaUtil.java

@@ -6,6 +6,7 @@ import com.judong.chuanyiserver.config.OpcServerUaPoolFactory;
 import com.judong.chuanyiserver.entity.ServerInformation;
 import com.judong.chuanyiserver.enums.ConnectModeEnum;
 import com.judong.chuanyiserver.enums.ResultEnum;
+import com.judong.chuanyiserver.exception.CustomException;
 import lombok.extern.slf4j.Slf4j;
 import org.eclipse.milo.opcua.sdk.client.OpcUaClient;
 import org.eclipse.milo.opcua.sdk.client.api.config.OpcUaClientConfig;
@@ -42,8 +43,6 @@ import java.util.function.Predicate;
 public class OpcServerUaUtil {
 
     private static final String certPath = "C:/Users/Administrator/Desktop/";
-    //    private static final String endpointUrl = "opc.tcp://192.168.0.252:49322";
-//    private static final String endpointUrl = "opc.tcp://192.168.0.252:37800";
 
     /**
      * 通过传入的serverInformation,判断是否符合生成键
@@ -233,19 +232,18 @@ public class OpcServerUaUtil {
         }
     }
 
-    public static Result opcReadItemTree(ServerInformation serverInformation) {
+    public static List<JSONObject> opcReadItemTree(ServerInformation serverInformation) {
         try {
             String opcServerDaPoolKey = OpcServerUaUtil.generateOpcPoolKey(serverInformation);
             if (!OpcServerUaUtil.validationKey(opcServerDaPoolKey)) {
-                return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
+                throw new CustomException(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
             }
             OpcUaClient opcUaClient = OpcServerUaUtil.getClient(opcServerDaPoolKey);
-            JSONObject jsonObject = new JSONObject();
-            jsonObject.put("tree", generOpcUaTree(opcUaClient, null));
+            List<JSONObject> jsonObjectList = generOpcUaTree(opcUaClient, null);
             OpcServerUaUtil.returnClient(opcServerDaPoolKey, opcUaClient);
-            return Result.ok(jsonObject);
+            return jsonObjectList;
         } catch (Exception e) {
-            return Result.no(ResultEnum.REQUEST_TIME_OUT.getRespCode(), e.getMessage());
+            throw new CustomException(ResultEnum.REQUEST_TIME_OUT.getRespCode(), e.getMessage());
         }
     }
 
@@ -264,10 +262,13 @@ public class OpcServerUaUtil {
             String opcServerDaPoolKey = OpcServerUaUtil.generateOpcPoolKey(serverInformation);
             if (OpcServerUaUtil.validationKey(opcServerDaPoolKey)) {
                 OpcUaClient opcUaClient = OpcServerUaUtil.getClient(opcServerDaPoolKey);
-                if (Blank.isEmpty(opcUaClient)){
+                if (Blank.isEmpty(opcUaClient)) {
                     return Result.no(ResultEnum.REQUEST_TIME_OUT.getRespCode(), "客户端创建失败");
                 }
-                NodeId nodeId = new NodeId(2, itemName);
+                //chuangyi.以太网<192.168.0.1>.$DeviceStatusOfts
+//                NodeId nodeId = new NodeId(2, "chuangyi.ts.$DeviceStatusOfts");
+                NodeId nodeId = new NodeId(2, "以太网<192.168.0.1>.ts.$DeviceStatusOfts");
+//                NodeId nodeId = new NodeId(2, itemName);
                 //读取节点数据
                 DataValue value = opcUaClient.readValue(0.0, TimestampsToReturn.Neither, nodeId).get();
                 return Result.ok(value.getValue().getValue());

+ 98 - 0
chuanyi_server/src/main/resources/mapper/ChannelSettingDao.xml

@@ -0,0 +1,98 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.judong.chuanyiserver.dao.ChannelSettingDao">
+
+    <insert id="addChannelSetting">
+        insert into t_channel_setting(server_id, channel_name, channel_map_name, data_type, read_mechanism, read_policy,
+                                      policy_value, configuration_name, create_time)
+            value (#{serverId}, #{channelName},
+                   #{channelMapName}, #{dataType},
+                   #{readMechanism}, #{readPolicy},
+                   #{policyValue}, #{configurationName}, now())
+    </insert>
+
+    <update id="addConfigByName">
+        update t_channel_setting
+        set configuration_name=#{configName}
+        where server_id = #{serverId}
+        and channel_name in (
+        <foreach collection="channelNameList" item="channelName" index="index" separator=",">
+            #{channelName}
+        </foreach>
+        )
+    </update>
+
+    <update id="updateChannelSetting">
+        update t_channel_setting
+        set channel_map_name=#{channelMapName},
+            data_type=#{dataType},
+            read_mechanism=#{readMechanism},
+            read_policy=#{readPolicy},
+            policy_value=#{policyValue}
+        where id = #{id}
+    </update>
+
+    <update id="clearConfigByName">
+        update t_channel_setting
+        set configuration_name=null
+        where server_id = #{serverId}
+          and configuration_name = #{configName}
+    </update>
+
+    <select id="getChannelBySeChName" resultType="com.judong.chuanyiserver.entity.ChannelSetting">
+        select id,
+               server_id,
+               channel_name,
+               channel_map_name,
+               data_type,
+               read_mechanism,
+               read_policy,
+               policy_value,
+               configuration_name,
+               create_time
+        from t_channel_setting
+        where server_id = #{serverId}
+          and channel_name = #{channelName}
+    </select>
+
+    <select id="getLabelByIdSeChName" resultType="com.judong.chuanyiserver.entity.ChannelSetting">
+        select id,
+               server_id,
+               channel_name,
+               channel_map_name,
+               data_type,
+               read_mechanism,
+               read_policy,
+               policy_value,
+               configuration_name,
+               create_time
+        from t_channel_setting
+        where server_id = #{serverId}
+          and channel_name = #{channelName}
+          and id != #{id}
+    </select>
+
+    <select id="getConfigList" resultType="java.lang.String">
+        select distinct (tcs.configuration_name)
+        from (select configuration_name
+              from t_channel_setting
+              order by create_time) tcs
+    </select>
+
+    <select id="getChannelListNoConfig" resultType="com.judong.chuanyiserver.entity.ChannelSetting">
+        select id,
+               server_id,
+               channel_name,
+               channel_map_name,
+               data_type,
+               read_mechanism,
+               read_policy,
+               policy_value,
+               configuration_name,
+               create_time
+        from t_channel_setting
+        where server_id = #{serverId}
+          and configuration_name is null
+    </select>
+
+</mapper>

+ 101 - 0
chuanyi_server/src/main/resources/mapper/DictDao.xml

@@ -0,0 +1,101 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.judong.chuanyiserver.dao.DictDao">
+
+    <!--查询所有数据-->
+    <select id="queryAll" resultType="com.judong.chuanyiserver.entity.Dict">
+        SELECT id,parent_id,dict_key,dict_value,sort_num,create_time FROM sys_dict
+    </select>
+
+    <!--分页条件查询-->
+    <select id="queryPage" resultType="com.judong.chuanyiserver.entity.Dict">
+        SELECT id,parent_id,dict_key,dict_value,sort_num,create_time FROM sys_dict
+        <where>
+            <if test=" dictKey!=null and dictKey !=''">
+                and dict_key like CONCAT('%', #{dictKey}, '%')
+            </if>
+            <if test="dictValue !=null and dictValue !=''">
+                and dict_value like CONCAT('%', #{dictValue}, '%')
+            </if>
+        </where>
+        ORDER BY sort_num DESC
+        LIMIT #{page},#{num}
+    </select>
+
+    <!--查询总条数-->
+    <select id="queryNumber" resultType="java.lang.Integer">
+        SELECT count(*) FROM sys_dict
+        <where>
+            <if test=" dictKey!=null and dictKey !=''">
+                and dict_key like CONCAT('%', #{dictKey}, '%')
+            </if>
+            <if test="dictValue !=null and dictValue !=''">
+                and dict_value like CONCAT('%', #{dictValue}, '%')
+            </if>
+        </where>
+    </select>
+
+    <!--条件查询-->
+    <select id="queryByIdOrKey" resultType="com.judong.chuanyiserver.entity.Dict">
+        SELECT id,parent_id,dict_key,dict_value,sort_num,create_time FROM sys_dict
+        <where>
+            <if test=" id !=null and id !=''">
+                and id=#{id}
+            </if>
+            <if test="dictKey !=null and dictKey !=''">
+                and dict_key=#{dictKey}
+            </if>
+        </where>
+        ORDER BY sort_num DESC
+        LIMIT #{page},#{num}
+    </select>
+
+    <!--条件查询总条数-->
+    <select id="queryByIdOrKeyNum" resultType="java.lang.Integer">
+        SELECT count(*) FROM sys_dict
+        <where>
+            <if test=" dictKey!=null and dictKey !=''">
+                and dict_key =#{dictKey}
+            </if>
+            <if test="id !=null and id !=''">
+                and id=#{id}
+            </if>
+        </where>
+    </select>
+
+    <!--根据父id查所有子节点-->
+    <select id="queryByParentId" resultType="com.judong.chuanyiserver.entity.Dict">
+        SELECT id,parent_id,dict_key,dict_value,sort_num,create_time FROM sys_dict
+        where parent_id=#{parentId}
+    </select>
+
+    <!--新增-->
+    <insert id="addDict">
+        INSERT INTO sys_dict VALUES (DEFAULT,#{dict.parentId},#{dict.dictKey},#{dict.dictValue},#{dict.sortNum},NOW())
+    </insert>
+
+    <!--修改-->
+    <update id="updataById">
+        UPDATE sys_dict SET
+        parent_id=#{dict.parentId},
+        dict_key=#{dict.dictKey},
+        dict_value=#{dict.dictValue},
+        sort_num=#{dict.sortNum}
+        where id=#{dict.id}
+    </update>
+
+    <!--批量删除-->
+    <delete id="deleteByid">
+        DELETE FROM sys_dict WHERE id in
+        <foreach collection="ids" item="id" separator="," open="(" close=")">
+            #{id}
+        </foreach>
+    </delete>
+
+    <!--根据id查数据-->
+    <select id="queryById" resultType="com.judong.chuanyiserver.entity.Dict">
+        SELECT id,parent_id,dict_key,dict_value,sort_num,create_time FROM sys_dict
+        where id=#{id}
+    </select>
+
+</mapper>