Pārlūkot izejas kodu

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

FinalYu 2 gadi atpakaļ
vecāks
revīzija
306a3917ba

+ 50 - 8
chuanyi_server/src/main/java/com/judong/chuanyiserver/controller/DictController.java

@@ -2,13 +2,12 @@ package com.judong.chuanyiserver.controller;
 
 
 import com.judong.chuanyiserver.entity.Dict;
+import com.judong.chuanyiserver.entity.DictType;
 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;
 import java.util.Map;
@@ -25,8 +24,8 @@ public class DictController {
      * 查询所有数据
      */
     @GetMapping("/queryAll")
-    public Result queryAll(){
-        return dictService.queryAll();
+    public Result queryAll(Integer page,Integer num){
+        return dictService.queryAll(page, num);
     }
 
     /**
@@ -65,8 +64,8 @@ public class DictController {
         if (Blank.isEmpty(parentId)){
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "父id不能为空");
         }
-        Map<String, Dict> stringDictMap = dictService.queryByParentId(parentId);
-        return Result.ok(stringDictMap);
+        List<Dict> dicts = dictService.queryByParentId(parentId);
+        return Result.ok(dicts);
     }
 
     /**
@@ -82,6 +81,7 @@ public class DictController {
      */
     @PostMapping("/updateById")
     public Result updataById(@RequestBody Dict dict){
+        System.out.println(dict);
         return dictService.updataById(dict);
     }
 
@@ -101,8 +101,50 @@ public class DictController {
         if (dictKeys.size()<=0){
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "参数错误");
         }
-        Map<String, Object> map = dictService.queryByDictKey(dictKeys);
-        return Result.ok(map);
+        List<Dict> dicts = dictService.queryByDictKey(dictKeys);
+        return Result.ok(dicts);
+    }
+
+    /**
+     *查询所有字典类型
+     */
+    @GetMapping("queryType")
+    public Result queryType(){
+        return dictService.queryType();
+    }
+
+
+    /**
+     *根据字典类型查询对应数据
+     */
+    @GetMapping("queryByType")
+    public Result queryByType(String keyType,Integer page,Integer num){
+        return dictService.queryByType(keyType, page, num);
+    }
+
+
+    /**
+     * 字典类型新增
+     */
+    @PostMapping("addDictType")
+    public Result addDictType(@RequestBody DictType dictType){
+        return dictService.addDictType(dictType);
+    }
+
+    /**
+     * 字典类型修改
+     */
+    @PostMapping("updataDictType")
+    public Result updataDictType(@RequestBody DictType dictType){
+        return dictService.updataDictType(dictType);
+    }
+
+    /**
+     * 根据字典类型id删除字典类型(批量)
+     */
+    @GetMapping("deleteDictTypeById")
+    public Result deleteDictTypeById(@RequestParam("ids") List<Integer> ids){
+        return dictService.deleteDictTypeById(ids);
     }
 
 

+ 49 - 2
chuanyi_server/src/main/java/com/judong/chuanyiserver/dao/DictDao.java

@@ -1,6 +1,7 @@
 package com.judong.chuanyiserver.dao;
 
 import com.judong.chuanyiserver.entity.Dict;
+import com.judong.chuanyiserver.entity.DictType;
 import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Repository;
 
@@ -12,7 +13,12 @@ public interface DictDao {
     /**
      * 查询所有数据
      */
-    List<Dict> queryAll();
+    List<Dict> queryAll(Integer page,Integer num);
+
+    /**
+     * 查询总条数
+     */
+    Integer queryAllnum();
 
     /**
      * 分页查询
@@ -24,7 +30,7 @@ public interface DictDao {
     List<Dict> queryPage(String dictKey,String dictValue,Integer page,Integer num);
 
     /**
-     * 查询总条数
+     * 模糊查询总条数
      */
     Integer queryNumber(String dictKey,String dictValue);
 
@@ -70,5 +76,46 @@ public interface DictDao {
      */
     List<Dict> queryByDictKey(@Param("dictKeys") List<String> dictKeys);
 
+    /**
+     * 辅助新增和修改的时候判断是否为重复数据
+     */
+    Dict queryIsExist(@Param("dict") Dict dict);
+
+    /**
+     *查询所有字典类型
+     */
+    List<DictType> queryType();
+
+
+    /**
+     *根据字典类型查询对应数据
+     */
+    List<Dict> queryByType(String keyType,Integer page,Integer num);
+
+    /**
+     * 根据字典类型查询总条数
+     */
+    Integer queryByTypeNum(String keyType);
+
+    /**
+     * 字典类型新增
+     */
+    Integer addDictType(@Param("dictType") DictType dictType);
+
+    /**
+     * 字典类型修改
+     */
+    Integer updataDictType(@Param("dictType") DictType dictType);
+
+    /**
+     * 根据字典类型id删除字典类型(批量)
+     */
+    Integer deleteDictTypeById(List<Integer> ids);
+
+    /**
+     * 根据字典类型值查字典类型对象(辅助判断)
+     */
+    DictType queryDictTypeByKeyType(String dictKeyType);
+
 
 }

+ 7 - 3
chuanyi_server/src/main/java/com/judong/chuanyiserver/entity/Dict.java

@@ -3,9 +3,7 @@ package com.judong.chuanyiserver.entity;
 import lombok.Data;
 
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 
 @Data
 public class Dict {
@@ -31,6 +29,12 @@ public class Dict {
     private String dictValue;
 
     /**
+     * 字典id
+     */
+    private Integer dictTypeId;
+
+
+    /**
      *排序号
      */
     private Integer sortNum;
@@ -43,6 +47,6 @@ public class Dict {
     /**
      * 子节点    private List<Dict> children=new ArrayList<>();
      */
-    private Map<String, Dict> children=new HashMap<>();
+    private List<Dict> children=new ArrayList<>();
 
 }

+ 32 - 0
chuanyi_server/src/main/java/com/judong/chuanyiserver/entity/DictType.java

@@ -0,0 +1,32 @@
+package com.judong.chuanyiserver.entity;
+
+import lombok.Data;
+
+@Data
+public class DictType {
+
+    /**
+     * id
+     */
+    private Integer id;
+
+    /**
+     * 字典类型
+     */
+    private String dictKeyType;
+
+    /**
+     *字典值
+     */
+    private String dictKeyValue;
+
+    /**
+     * 排序号
+     */
+    private Integer sortNum;
+
+    /**
+     * 描述
+     */
+    private String description;
+}

+ 36 - 3
chuanyi_server/src/main/java/com/judong/chuanyiserver/service/DictService.java

@@ -1,6 +1,7 @@
 package com.judong.chuanyiserver.service;
 
 import com.judong.chuanyiserver.entity.Dict;
+import com.judong.chuanyiserver.entity.DictType;
 import com.judong.chuanyiserver.util.Result;
 
 import java.util.List;
@@ -9,8 +10,10 @@ import java.util.Map;
 public interface DictService {
     /**
      * 查询所有数据
+     * param page
+     * param num
      */
-    Result queryAll();
+    Result queryAll(Integer page,Integer num);
 
     /**
      * 分页查询
@@ -31,7 +34,7 @@ public interface DictService {
      * 根据父id查子节点信息 树结构
      * param parentId
      */
-    Map<String, Dict> queryByParentId(Integer parentId);
+    List<Dict> queryByParentId(Integer parentId);
 
     /**
      * 新增
@@ -48,5 +51,35 @@ public interface DictService {
      */
     Result deleteByid( List<Integer> ids);
 
-    Map<String, Object> queryByDictKey(List<String> dictKeys);
+    /**
+     * 根据字典编码查数据(树结构)
+     */
+    List<Dict> queryByDictKey(List<String> dictKeys);
+
+    /**
+     *查询所有字典类型
+     */
+    Result queryType();
+
+
+    /**
+     *根据字典类型查询对应数据
+     */
+    Result queryByType(String keyType,Integer page,Integer num);
+
+
+    /**
+     * 字典类型新增
+     */
+    Result addDictType(DictType dictType);
+
+    /**
+     * 字典类型修改
+     */
+    Result updataDictType( DictType dictType);
+
+    /**
+     * 根据字典类型id删除字典类型(批量)
+     */
+    Result deleteDictTypeById(List<Integer> ids);
 }

+ 26 - 5
chuanyi_server/src/main/java/com/judong/chuanyiserver/service/impl/ChannelSettingServiceImpl.java

@@ -1,8 +1,10 @@
 package com.judong.chuanyiserver.service.impl;
 
 import com.alibaba.fastjson.JSONObject;
-import com.judong.chuanyiserver.dao.ConnectDao;
+import com.judong.chuanyiserver.config.KepOpcServerTimerTask;
+import com.judong.chuanyiserver.config.OpcAsyncTask;
 import com.judong.chuanyiserver.dao.ChannelSettingDao;
+import com.judong.chuanyiserver.dao.ConnectDao;
 import com.judong.chuanyiserver.entity.ChannelSetting;
 import com.judong.chuanyiserver.entity.Config;
 import com.judong.chuanyiserver.entity.ServerInformation;
@@ -17,7 +19,7 @@ import org.springframework.transaction.annotation.Transactional;
 import javax.annotation.Resource;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Map;
+import java.util.Timer;
 
 @Service
 @Transactional
@@ -29,6 +31,9 @@ public class ChannelSettingServiceImpl implements ChannelSettingService {
     @Resource
     private ChannelSettingDao channelSettingDao;
 
+    @Resource
+    private OpcAsyncTask opcAsyncTask;
+
     @Override
     public synchronized Result channelSetting(ChannelSetting channelSetting) {
         if (Blank.isEmpty(channelSetting.getId())) {
@@ -142,7 +147,7 @@ public class ChannelSettingServiceImpl implements ChannelSettingService {
 
     @Override
     public Result selectConfig(Integer configId) {
-        return Result.ok(channelSettingDao.getChannelByConfigId(configId));
+        return Result.ok(channelSettingDao.getConfigList(configId));
     }
 
     @Override
@@ -171,12 +176,28 @@ public class ChannelSettingServiceImpl implements ChannelSettingService {
         serverInformation.setIpPassword(RSAUtil.decrypt(serverInformation.getIpPassword(), "utf-8"));
         if (serverInformation.getConnectMode() == ConnectModeEnum.KEPOPCSERVER.getValue()) {
             if (KepOpcServerUtil.validationServerInformation(serverInformation)) {
-                return KepOpcServerUtil.opcReadItemListValue(serverInformation, channelSettingList);
+                if (runState==ConstantStr.START_UP){
+                    //将配置的状态更换为运行
+                    Timer timer = new Timer(true);
+                    timer.scheduleAtFixedRate(new KepOpcServerTimerTask(serverInformation,channelSettingList),0,1*1000);
+
+//                    opcAsyncTask.KepServerReadItemList(serverInformation, channelSettingList);
+                }else{
+                    //将配置的状态更换为停止
+
+                    opcAsyncTask.KepServerCloseReadItemList(serverInformation, channelSettingList);
+                }
+                return Result.ok("操作成功");
             }
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
         } else if (serverInformation.getConnectMode() == ConnectModeEnum.KingOPCServer.getValue()) {
             if (OpcServerUaUtil.validationServerInformation(serverInformation)) {
-                return OpcServerUaUtil.opcReadItemValue(serverInformation, "");
+                if (runState==ConstantStr.START_UP){
+                    opcAsyncTask.OpcServerUaReadItemList(serverInformation, channelSettingList);
+                }else{
+                    opcAsyncTask.OpcServerUaCloseReadItemList(serverInformation, channelSettingList);
+                }
+                return Result.ok("操作成功");
             }
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
         } else {

+ 93 - 27
chuanyi_server/src/main/java/com/judong/chuanyiserver/service/impl/DictServiceImpl.java

@@ -3,6 +3,7 @@ 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.entity.DictType;
 import com.judong.chuanyiserver.enums.ResultEnum;
 import com.judong.chuanyiserver.service.DictService;
 import com.judong.chuanyiserver.util.Blank;
@@ -11,9 +12,9 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
-import java.util.HashMap;
+import java.util.ArrayList;
 import java.util.List;
-import java.util.Map;
+
 
 
 @Service
@@ -24,12 +25,17 @@ public class DictServiceImpl implements DictService {
     private DictDao dictDao;
 
     @Override
-    public Result queryAll() {
-        List<Dict> dicts = dictDao.queryAll();
+    public Result queryAll(Integer page,Integer num) {
+        JSONObject jsonObject = new JSONObject();
+        Integer count = dictDao.queryAllnum();
+        Integer startNum=(page-1)*num;
+        List<Dict> dicts = dictDao.queryAll(startNum,num);
         if (dicts.size()<=0){
             return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), "暂无数据");
         }
-        return Result.ok(dicts);
+        jsonObject.put("count",count);
+        jsonObject.put("dicts",dicts);
+        return Result.ok(jsonObject);
     }
 
     @Override
@@ -61,26 +67,28 @@ public class DictServiceImpl implements DictService {
     }
 
     @Override
-    public Map<String, Dict> queryByParentId(Integer parentId) {
+    public List<Dict> queryByParentId(Integer parentId) {
         //存放节点数据
-        Map<String, Dict> map = new HashMap<>();
+        List<Dict> dicts = new ArrayList<>();
         //根据父节点获取子节点对象
         List<Dict> dictSon = dictDao.queryByParentId(parentId);
         //判断子节点是否为其他节点的父节点
         for (Dict d:dictSon){
             d.setChildren(queryByParentId(d.getId()));
-            map.put(d.getDictKey(),d);
+            dicts.add(d);
         }
-        return map;
+        return dicts;
     }
 
     @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,字典值以及序号不能为空");
+        if (Blank.isEmpty(dict.getParentId(),dict.getDictKey(),dict.getDictValue(),dict.getSortNum(),dict.getDictTypeId())){
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "父id,字典key,字典值,类型以及序号不能为空");
         }
-        if (Blank.isNotEmpty(dictDao.queryByDictKeyIsExist(dict.getDictKey()))){
-            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "字典key已存在");
+        //判断数据是否存在
+        Dict dictIsExist = dictDao.queryIsExist(dict);
+        if (dictIsExist !=null){
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "不可添加重复数据");
         }
         dictDao.addDict(dict);
         return Result.ok("新增成功");
@@ -88,17 +96,13 @@ public class DictServiceImpl implements DictService {
 
     @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 (Blank.isEmpty(dict.getParentId(),dict.getDictKey(),dict.getDictValue(),dict.getSortNum(),dict.getId(),dict.getDictTypeId())){
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "id,父id,字典key,字典值,类型以及序号不能为空");
         }
-        //判断key是否重复
-        if (Blank.isNotEmpty(dictDao.queryByDictKeyIsExist(dict.getDictKey()))){
-            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "key已存在,修改失败");
+        //判断数据是否存在
+        Dict dictIsExist = dictDao.queryIsExist(dict);
+        if (dictIsExist !=null){
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "不可更改为重复数据");
         }
         if (dictDao.updataById(dict)<=0){
             throw new ClassCastException("修改失败");
@@ -116,14 +120,76 @@ public class DictServiceImpl implements DictService {
     }
 
     @Override
-    public Map<String, Object> queryByDictKey(List<String> dictKeys) {
+    public List<Dict> queryByDictKey(List<String> dictKeys) {
         //存储数据
-        Map<String, Object> map = new HashMap<>();
+        List<Dict> dictAll = new ArrayList<>();
         List<Dict> dicts = dictDao.queryByDictKey(dictKeys);
         for (Dict d:dicts){
             d.setChildren(queryByParentId(d.getId()));
-            map.put(d.getDictKey(),d);
+            dictAll.add(d);
+        }
+        return dictAll;
+    }
+
+    @Override
+    public Result queryType() {
+        List<DictType> dictTypes = dictDao.queryType();
+        if (dictTypes.size()<=0){
+            throw new ClassCastException("暂无数据");
+        }
+        return Result.ok(dictTypes);
+    }
+
+    @Override
+    public Result queryByType(String keyType, Integer page, Integer num) {
+        JSONObject jsonObject = new JSONObject();
+        if (Blank.isEmpty(keyType)){
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "字典类型不能为空");
+        }
+        Integer count = dictDao.queryByTypeNum(keyType);
+        Integer startNum=(page-1)*num;
+        List<Dict> dicts = dictDao.queryByType(keyType, startNum, num);
+        jsonObject.put("count",count);
+        jsonObject.put("dicts",dicts);
+        return Result.ok(jsonObject);
+    }
+
+    @Override
+    public Result addDictType(DictType dictType) {
+        if (Blank.isEmpty(dictType.getDictKeyType(),dictType.getDictKeyValue(),dictType.getSortNum(),dictType.getDescription())){
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(),"字典类型,字典值,序号以及描述不能为空");
+        }
+        //判断类型key是否重复
+        if (dictDao.queryDictTypeByKeyType(dictType.getDictKeyType())!=null){
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(),"字典类型已被占用");
+        }
+        if (dictDao.addDictType(dictType)<=0){
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(),"新增失败");
+        }
+        return Result.ok("新增成功");
+    }
+
+    @Override
+    public Result updataDictType(DictType dictType) {
+        if (Blank.isEmpty(dictType.getDictKeyType(),dictType.getDictKeyValue(),dictType.getSortNum(),dictType.getDescription())){
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(),"字典类型,字典值,序号以及描述不能为空");
+        }
+        //判断类型key是否重复
+        if (dictDao.queryDictTypeByKeyType(dictType.getDictKeyType())!=null){
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(),"字典类型已被占用");
+        }
+        if (dictDao.updataDictType(dictType)<=0){
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(),"编辑失败");
+        }
+        return Result.ok("编辑成功");
+    }
+
+    @Override
+    public Result deleteDictTypeById(List<Integer> ids) {
+        if (ids.size()<=0){
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(),"参数错误");
         }
-        return map;
+        Integer num = dictDao.deleteDictTypeById(ids);
+        return Result.ok(num);
     }
 }

+ 77 - 8
chuanyi_server/src/main/resources/mapper/DictDao.xml

@@ -4,12 +4,19 @@
 
     <!--查询所有数据-->
     <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 id,parent_id,dict_key,dict_value,dict_type_id,sort_num,create_time FROM sys_dict
+        ORDER BY sort_num DESC
+        LIMIT #{page},#{num}
+    </select>
+
+    <!--查询总条数-->
+    <select id="queryAllnum" resultType="java.lang.Integer">
+        SELECT count(*) 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
+        SELECT id,parent_id,dict_key,dict_value,dict_type_id,sort_num,create_time FROM sys_dict
         <where>
             <if test=" dictKey!=null and dictKey !=''">
                 and dict_key like CONCAT('%', #{dictKey}, '%')
@@ -22,7 +29,7 @@
         LIMIT #{page},#{num}
     </select>
 
-    <!--查询总条数-->
+    <!--模糊查询总条数-->
     <select id="queryNumber" resultType="java.lang.Integer">
         SELECT count(*) FROM sys_dict
         <where>
@@ -37,7 +44,7 @@
 
     <!--条件查询-->
     <select id="queryByIdOrKey" resultType="com.judong.chuanyiserver.entity.Dict">
-        SELECT id,parent_id,dict_key,dict_value,sort_num,create_time FROM sys_dict
+        SELECT id,parent_id,dict_key,dict_value,dict_type_id,sort_num,create_time FROM sys_dict
         <where>
             <if test=" id !=null and id !=''">
                 and id=#{id}
@@ -65,18 +72,18 @@
 
     <!--根据父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
+        SELECT id,parent_id,dict_key,dict_value,dict_type_id,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 INTO sys_dict VALUES (DEFAULT,#{dict.parentId},#{dict.dictKey},#{dict.dictValue},#{dict.dictTypeId},#{dict.sortNum},NOW())
     </insert>
 
     <!--判断key是否重复-->
     <select id="queryByDictKeyIsExist" resultType="com.judong.chuanyiserver.entity.Dict">
-        SELECT id,parent_id,dict_key,dict_value,sort_num,create_time FROM sys_dict
+        SELECT id,parent_id,dict_key,dict_value,dict_type_id,sort_num,create_time FROM sys_dict
         where dict_key=#{dictKey}
     </select>
 
@@ -86,6 +93,7 @@
         parent_id=#{dict.parentId},
         dict_key=#{dict.dictKey},
         dict_value=#{dict.dictValue},
+        dict_type_id=#{dict.dictTypeId},
         sort_num=#{dict.sortNum}
         where id=#{dict.id}
     </update>
@@ -106,11 +114,72 @@
 
     <!--根据key批量查询-->
     <select id="queryByDictKey" resultType="com.judong.chuanyiserver.entity.Dict">
-        SELECT id,parent_id,dict_key,dict_value,sort_num,create_time FROM sys_dict
+        SELECT id,parent_id,dict_key,dict_value,dict_type_id,sort_num,create_time FROM sys_dict
         where dict_key in
         <foreach collection="dictKeys" item="dictKey" separator="," open="(" close=")">
             #{dictKey}
         </foreach>
     </select>
 
+    <!--判断新增或者修改的时候是否为重复数据-->
+    <select id="queryIsExist" resultType="com.judong.chuanyiserver.entity.Dict">
+       SELECT id,parent_id,dict_key,dict_value,dict_type_id,sort_num,create_time FROM sys_dict
+       where  parent_id=#{dict.parentId}
+       and dict_key=#{dict.dictKey}
+       and dict_value=#{dict.dictValue}
+       and dict_type_id=#{dict.dictTypeId}
+    </select>
+
+    <!--查询所有字典类型-->
+    <select id="queryType" resultType="com.judong.chuanyiserver.entity.DictType">
+        SELECT id,dict_key_type,dict_key_value,sort_num,description FROM sys_dict_type
+        GROUP BY dict_key_type
+    </select>
+
+    <!--根据字典类型查询对应数据-->
+    <select id="queryByType" resultType="com.judong.chuanyiserver.entity.Dict">
+        SELECT sd.id,sd.parent_id,sd.dict_key,sd.dict_value,sd.dict_type_id,sd.sort_num,sd.create_time FROM sys_dict sd
+        JOIN sys_dict_type sdt
+        ON sd.dict_type_id=sdt.id
+        AND sdt.dict_key_type=#{keyType}
+        ORDER BY sd.sort_num DESC
+        LIMIT #{page},#{num}
+    </select>
+
+    <!--根据字典类型查询总条数-->
+    <select id="queryByTypeNum" resultType="java.lang.Integer">
+        SELECT count(*) FROM sys_dict sd
+        JOIN sys_dict_type sdt
+        ON sd.dict_type_id=sdt.id
+        AND sdt.dict_key_type=#{keyType}
+    </select>
+
+    <!--字典类型新增-->
+    <insert id="addDictType">
+        INSERT INTO sys_dict_type VALUES (DEFAULT,#{dictType.dictKeyType},#{dictType.dictKeyValue},#{dictType.sortNum},#{dictType.description})
+    </insert>
+
+    <!--字典类型修改-->
+    <update id="updataDictType">
+        UPDATE sys_dict_type SET
+        dict_key_type=#{dictType.dictKeyType},
+        dict_key_value=#{dictType.dictKeyValue},
+        sort_num=#{dictType.sortNum},
+        description=#{dictType.description}
+        where id=#{dictType.id}
+    </update>
+
+    <!--根据字典类型id删除字典(批量)-->
+    <delete id="deleteDictTypeById">
+        DELETE FROM sys_dict_type WHERE id in
+        <foreach collection="ids" item="id" separator="," open="(" close=")">
+            #{id}
+        </foreach>
+    </delete>
+
+    <!--根据字典类型值查询字典类型对象(辅助判断)-->
+    <select id="queryDictTypeByKeyType" resultType="com.judong.chuanyiserver.entity.DictType">
+        SELECT id,dict_key_type,dict_key_value,sort_num,description FROM sys_dict_type where dict_key_type=#{dictKeyType}
+    </select>
+
 </mapper>