浏览代码

Merge branch 'master' into zt

ljh 2 年之前
父节点
当前提交
1ed22e8012
共有 50 个文件被更改,包括 838 次插入221 次删除
  1. 7 7
      chuanyi_client/package-lock.json
  2. 1 1
      chuanyi_client/package.json
  3. 17 1
      chuanyi_client/src/api/user.js
  4. 16 10
      chuanyi_client/src/components/HeaderMain/index.vue
  5. 21 7
      chuanyi_client/src/permission.js
  6. 11 2
      chuanyi_client/src/router/index.js
  7. 11 0
      chuanyi_client/src/store/getters.js
  8. 15 11
      chuanyi_client/src/store/index.js
  9. 56 0
      chuanyi_client/src/store/modules/app.js
  10. 141 0
      chuanyi_client/src/store/modules/user.js
  11. 31 22
      chuanyi_client/src/utils/auth.js
  12. 1 1
      chuanyi_client/src/utils/request.js
  13. 11 22
      chuanyi_client/src/views/login.vue
  14. 1 8
      chuanyi_server/src/main/java/com/judong/chuanyiserver/config/OpcServerDaPoolFactory.java
  15. 2 2
      chuanyi_server/src/main/java/com/judong/chuanyiserver/controller/ConnectController.java
  16. 4 2
      chuanyi_server/src/main/java/com/judong/chuanyiserver/controller/DepartmentController.java
  17. 19 0
      chuanyi_server/src/main/java/com/judong/chuanyiserver/controller/MenuController.java
  18. 9 0
      chuanyi_server/src/main/java/com/judong/chuanyiserver/controller/PermissionController.java
  19. 17 1
      chuanyi_server/src/main/java/com/judong/chuanyiserver/controller/RoleController.java
  20. 62 7
      chuanyi_server/src/main/java/com/judong/chuanyiserver/controller/UserController.java
  21. 2 2
      chuanyi_server/src/main/java/com/judong/chuanyiserver/dao/DepartmentDao.java
  22. 1 1
      chuanyi_server/src/main/java/com/judong/chuanyiserver/dao/RoleDao.java
  23. 9 0
      chuanyi_server/src/main/java/com/judong/chuanyiserver/dao/UserDao.java
  24. 5 0
      chuanyi_server/src/main/java/com/judong/chuanyiserver/entity/Department.java
  25. 2 1
      chuanyi_server/src/main/java/com/judong/chuanyiserver/entity/Role.java
  26. 12 0
      chuanyi_server/src/main/java/com/judong/chuanyiserver/entity/ServerInformation.java
  27. 32 0
      chuanyi_server/src/main/java/com/judong/chuanyiserver/enums/ConnectModeEnum.java
  28. 1 1
      chuanyi_server/src/main/java/com/judong/chuanyiserver/enums/ModelEnum.java
  29. 1 1
      chuanyi_server/src/main/java/com/judong/chuanyiserver/enums/OperationEnum.java
  30. 7 1
      chuanyi_server/src/main/java/com/judong/chuanyiserver/exception/GlobalExceptionHandler.java
  31. 1 1
      chuanyi_server/src/main/java/com/judong/chuanyiserver/service/ConnectService.java
  32. 1 1
      chuanyi_server/src/main/java/com/judong/chuanyiserver/service/DepartmentService.java
  33. 6 0
      chuanyi_server/src/main/java/com/judong/chuanyiserver/service/UserService.java
  34. 37 25
      chuanyi_server/src/main/java/com/judong/chuanyiserver/service/impl/ConnectServiceImpl.java
  35. 13 6
      chuanyi_server/src/main/java/com/judong/chuanyiserver/service/impl/DepartmentServiceImpl.java
  36. 2 2
      chuanyi_server/src/main/java/com/judong/chuanyiserver/service/impl/LogServiceImpl.java
  37. 5 3
      chuanyi_server/src/main/java/com/judong/chuanyiserver/service/impl/MenuServiceImpl.java
  38. 2 2
      chuanyi_server/src/main/java/com/judong/chuanyiserver/service/impl/PermissionServiceImpl.java
  39. 3 4
      chuanyi_server/src/main/java/com/judong/chuanyiserver/service/impl/RoleServiceImpl.java
  40. 4 3
      chuanyi_server/src/main/java/com/judong/chuanyiserver/service/impl/ServerInServiceImpl.java
  41. 52 4
      chuanyi_server/src/main/java/com/judong/chuanyiserver/service/impl/UserServiceImpl.java
  42. 1 1
      chuanyi_server/src/main/java/com/judong/chuanyiserver/util/ConstantStr.java
  43. 27 23
      chuanyi_server/src/main/java/com/judong/chuanyiserver/util/KepOpcServerUtil.java
  44. 31 7
      chuanyi_server/src/main/java/com/judong/chuanyiserver/util/OpcServerUaUtil.java
  45. 0 16
      chuanyi_server/src/main/java/com/judong/chuanyiserver/util/Test.java
  46. 53 8
      chuanyi_server/src/main/resources/mapper/ConnectDao.xml
  47. 18 2
      chuanyi_server/src/main/resources/mapper/DepartmentDao.xml
  48. 1 0
      chuanyi_server/src/main/resources/mapper/MenuDao.xml
  49. 3 2
      chuanyi_server/src/main/resources/mapper/RoleDao.xml
  50. 53 0
      chuanyi_server/src/main/resources/mapper/UserDao.xml

+ 7 - 7
chuanyi_client/package-lock.json

@@ -20,7 +20,7 @@
         "sass-loader": "^13.1.0",
         "svg-sprite-loader": "^6.0.11",
         "vue": "^2.6.14",
-        "vue-router": "^3.5.1",
+        "vue-router": "3.0.2",
         "vue-splitpane": "^1.0.6",
         "vuex": "^3.6.2"
       },
@@ -14773,9 +14773,9 @@
       }
     },
     "node_modules/vue-router": {
-      "version": "3.6.5",
-      "resolved": "https://registry.npmmirror.com/vue-router/-/vue-router-3.6.5.tgz",
-      "integrity": "sha512-VYXZQLtjuvKxxcshuRAwjHnciqZVoXAjTjcqBTz4rKc8qih9g9pI3hbDjmqXaHdgL3v8pV6P8Z335XvHzESxLQ=="
+      "version": "3.0.2",
+      "resolved": "https://registry.npmmirror.com/vue-router/-/vue-router-3.0.2.tgz",
+      "integrity": "sha512-opKtsxjp9eOcFWdp6xLQPLmRGgfM932Tl56U9chYTnoWqKxQ8M20N7AkdEbM5beUh6wICoFGYugAX9vQjyJLFg=="
     },
     "node_modules/vue-splitpane": {
       "version": "1.0.6",
@@ -27804,9 +27804,9 @@
       }
     },
     "vue-router": {
-      "version": "3.6.5",
-      "resolved": "https://registry.npmmirror.com/vue-router/-/vue-router-3.6.5.tgz",
-      "integrity": "sha512-VYXZQLtjuvKxxcshuRAwjHnciqZVoXAjTjcqBTz4rKc8qih9g9pI3hbDjmqXaHdgL3v8pV6P8Z335XvHzESxLQ=="
+      "version": "3.0.2",
+      "resolved": "https://registry.npmmirror.com/vue-router/-/vue-router-3.0.2.tgz",
+      "integrity": "sha512-opKtsxjp9eOcFWdp6xLQPLmRGgfM932Tl56U9chYTnoWqKxQ8M20N7AkdEbM5beUh6wICoFGYugAX9vQjyJLFg=="
     },
     "vue-splitpane": {
       "version": "1.0.6",

+ 1 - 1
chuanyi_client/package.json

@@ -23,7 +23,7 @@
     "sass-loader": "^13.1.0",
     "svg-sprite-loader": "^6.0.11",
     "vue": "^2.6.14",
-    "vue-router": "^3.5.1",
+    "vue-router": "3.0.2",
     "vue-splitpane": "^1.0.6",
     "vuex": "^3.6.2"
   },

+ 17 - 1
chuanyi_client/src/api/user.js

@@ -70,4 +70,20 @@ export function getCode(hasPubKey) {
         method: 'get',
         params
     })
-}
+}
+
+/**
+ * 查询用户信息
+ * @param params
+ * @returns {AxiosPromise}
+ */
+export function getUserInfo(params) {
+    return request({
+        url: '/user/getUserById',
+        headers: {
+            isToken: true
+        },
+        method: 'get',
+        params
+    })
+}

+ 16 - 10
chuanyi_client/src/components/HeaderMain/index.vue

@@ -5,7 +5,7 @@
         <el-avatar shape="square" size="small" :src="avatar" @error="errorHandler">
           <img :src="avatarDefault"/>
         </el-avatar>
-        <span>{{ userName }}</span>
+        <span>{{ name }}</span>
       </div>
       <el-dropdown-menu slot="dropdown">
         <!--          <el-dropdown-item>详细信息</el-dropdown-item>-->
@@ -18,7 +18,7 @@
 
 <script>
 import avatarDefault from '@/assets/images/default.png'
-import {getUserName, getUserId, clearUserInfo} from "@/utils/auth";
+import { mapGetters } from 'vuex'
 import {logout} from "@/api/user";
 import {Message} from "element-ui";
 
@@ -26,12 +26,18 @@ export default {
   name: "HeaderMain",
   data() {
     return {
-      avatarDefault: avatarDefault,
-      avatar: '',
-      userName: getUserName(),
-      userId: getUserId()
+      avatarDefault: avatarDefault
     }
   },
+  computed: {
+    ...mapGetters([
+      'sidebar',
+      'avatar',
+      'name',
+      'uid',
+      'device'
+    ])
+  },
   methods: {
     errorHandler() {
       return true
@@ -45,16 +51,16 @@ export default {
     /**
      * 退出登录
      */
-    logout() {
+   logout() {
       this.$confirm('您确定要退出系统吗?', '提示', {
         confirmButtonText: '确定',
         cancelButtonText: '取消',
         type: 'warning'
       }).then(() => {
-        logout().then(res => {
-          clearUserInfo()
+        this.$store.dispatch('user/Logout').then(() => {
           location.href = '/index';
-        });
+        }).catch(() => {
+        })
       }).catch(() => {
       });
     }

+ 21 - 7
chuanyi_client/src/permission.js

@@ -1,26 +1,40 @@
 import router from './router'
+import store from './store'
 import NProgress from 'nprogress'
 import 'nprogress/nprogress.css'
-import { getToken } from '@/utils/auth'
+import {getToken} from '@/utils/auth'
 
 NProgress.configure({showSpinner: false})
 
 const whiteList = ['/login']
 
-router.beforeEach((to, from, next) => {
+router.beforeEach(async (to, from, next) => {
     NProgress.start()
     if (getToken()) {
-        // to.meta.title && store.dispatch('settings/setTitle', to.meta.title)
-        /* has token*/
         if (to.path === '/login') {
             next({path: '/'})
             NProgress.done()
         } else {
             if (to.matched.length === 0) {
-                next('/404')
-                NProgress.done()
+                // next('/404')
+                // NProgress.done()
+            }
+            const hasRoles = store.getters.roles && store.getters.roles.length > 0
+            if (hasRoles) {
+                next()
+            } else {
+                try {
+                    // 获取用户角色信息
+                    const {roleList} = await store.dispatch('user/getInfo')
+                    // 循环判断角色
+                    next({...to, replace: true})
+                } catch (error) {
+                    console.log(error)
+                    await store.dispatch('user/resetToken')
+                    next(`/login?redirect=${to.fullPath}`)
+                    NProgress.done()
+                }
             }
-            next()
         }
     } else {
         // 没有token

+ 11 - 2
chuanyi_client/src/router/index.js

@@ -43,10 +43,19 @@ const routes = [
     }
 ]
 
-const router = new VueRouter({
+const createRouter = () => new VueRouter({
     mode: 'history',
-    base: process.env.BASE_URL,
+    scrollBehavior: () => ({
+        y: 0
+    }),
     routes
 })
 
+const router = createRouter()
+
+export function resetRouter() {
+    const newRouter = createRouter()
+    router.matcher = newRouter.matcher
+}
+
 export default router

+ 11 - 0
chuanyi_client/src/store/getters.js

@@ -0,0 +1,11 @@
+const getters = {
+  sidebar: state => state.app.sidebar,
+  size: state => state.app.size,
+  device: state => state.app.device,
+  token: state => state.user.token,
+  avatar: state => state.user.avatar,
+  name: state => state.user.name,
+  uid: state => state.user.uid,
+  roles: state => state.user.roles
+}
+export default getters

+ 15 - 11
chuanyi_client/src/store/index.js

@@ -1,17 +1,21 @@
 import Vue from 'vue'
 import Vuex from 'vuex'
+import getters from './getters'
 
 Vue.use(Vuex)
 
-export default new Vuex.Store({
-  state: {
-  },
-  getters: {
-  },
-  mutations: {
-  },
-  actions: {
-  },
-  modules: {
-  }
+const modulesFiles = require.context('./modules', true, /\.js$/)
+
+const modules = modulesFiles.keys().reduce((modules, modulePath) => {
+  const moduleName = modulePath.replace(/^\.\/(.*)\.\w+$/, '$1')
+  const value = modulesFiles(modulePath)
+  modules[moduleName] = value.default
+  return modules
+}, {})
+
+const store = new Vuex.Store({
+  modules,
+  getters
 })
+
+export default store

+ 56 - 0
chuanyi_client/src/store/modules/app.js

@@ -0,0 +1,56 @@
+import Cookies from 'js-cookie'
+
+const state = {
+  sidebar: {
+    opened: Cookies.get('sidebarStatus') ? !!+Cookies.get('sidebarStatus') : true,
+    withoutAnimation: false
+  },
+  device: 'desktop',
+  size: Cookies.get('size') || 'medium'
+}
+
+const mutations = {
+  TOGGLE_SIDEBAR: state => {
+    state.sidebar.opened = !state.sidebar.opened
+    state.sidebar.withoutAnimation = false
+    if (state.sidebar.opened) {
+      Cookies.set('sidebarStatus', 1)
+    } else {
+      Cookies.set('sidebarStatus', 0)
+    }
+  },
+  CLOSE_SIDEBAR: (state, withoutAnimation) => {
+    Cookies.set('sidebarStatus', 0)
+    state.sidebar.opened = false
+    state.sidebar.withoutAnimation = withoutAnimation
+  },
+  TOGGLE_DEVICE: (state, device) => {
+    state.device = device
+  },
+  SET_SIZE: (state, size) => {
+    state.size = size
+    Cookies.set('size', size)
+  }
+}
+
+const actions = {
+  toggleSideBar({ commit }) {
+    commit('TOGGLE_SIDEBAR')
+  },
+  closeSideBar({ commit }, { withoutAnimation }) {
+    commit('CLOSE_SIDEBAR', withoutAnimation)
+  },
+  toggleDevice({ commit }, device) {
+    commit('TOGGLE_DEVICE', device)
+  },
+  setSize({ commit }, size) {
+    commit('SET_SIZE', size)
+  }
+}
+
+export default {
+  namespaced: true,
+  state,
+  mutations,
+  actions
+}

+ 141 - 0
chuanyi_client/src/store/modules/user.js

@@ -0,0 +1,141 @@
+import { getUserInfo, login, logout } from '@/api/user'
+import { getToken, setToken, getUid, getUsername, setUid, setUsername, removeAll, setPubKey } from '@/utils/auth'
+import { encrypt } from '@/utils/jsencrypt'
+import { resetRouter } from '@/router'
+import errorCode from '@/utils/errorCode'
+
+const state = {
+  token: getToken(),
+  uid: getUid(),
+  name: getUsername(),
+  avatar: '',
+  roles: []
+}
+
+const mutations = {
+  SET_TOKEN: (state, token) => {
+    state.token = token
+  },
+  SET_UID: (state, id) => {
+    state.uid = id
+  },
+  SET_NAME: (state, name) => {
+    state.name = name
+  },
+  SET_AVATAR: (state, avatar) => {
+    state.avatar = avatar
+  },
+  SET_ROLES: (state, roles) => {
+    state.roles = roles
+  }
+}
+
+const actions = {
+  /**
+   * 用户登录
+   * @param commit
+   * @param userInfo
+   * @returns {Promise<unknown>}
+   * @constructor
+   */
+  Login({ commit }, userInfo) {
+    const { username, password, code, uid, publicKey } = userInfo
+    setPubKey(publicKey)
+    const pwd = encrypt(password, publicKey)
+    return new Promise((resolve, reject) => {
+      login(username, pwd, code, uid).then(response => {
+        const { token, user } = response.data
+        commit('SET_TOKEN', token)
+        setToken(token)
+        commit('SET_UID', user.userId)
+        setUid(user.userId)
+        commit('SET_NAME', user.userName)
+        setUsername(user.userName)
+        // commit('SET_ROLES', user.roleList)
+        commit('SET_AVATAR', '')
+        resolve(response)
+      }).catch(error => {
+        reject(error)
+      })
+    }).catch(error => {
+      return Promise.reject(error)
+    })
+  },
+
+  /**
+   * 获取用户信息
+   * @param commit
+   * @param state
+   * @returns {Promise<unknown>}
+   */
+  getInfo({ commit, state }) {
+    return new Promise((resolve, reject) => {
+      const params = {
+        'userId': state.uid
+      }
+      getUserInfo(params).then(response => {
+        const { data } = response
+        if (!data) {
+          reject(errorCode[906])
+        }
+        const { userId, userName, roleList } = data
+
+        commit('SET_UID', userId)
+        setUid(userId)
+        commit('SET_NAME', userName)
+        setUsername(userName)
+        commit('SET_ROLES', roleList)
+        commit('SET_AVATAR', '')
+        resolve(data)
+      }).catch(error => {
+        reject(error)
+      })
+    })
+  },
+
+  /**
+   * 用户退出登录
+   * @param commit
+   * @param state
+   * @param dispatch
+   * @returns {Promise<unknown>}
+   * @constructor
+   */
+  Logout({ commit, state, dispatch }) {
+    return new Promise((resolve, reject) => {
+      logout().then(() => {
+        commit('SET_TOKEN', '')
+        commit('SET_ROLES', [])
+        removeAll()
+        resetRouter()
+
+        resolve()
+      }).catch(error => {
+        reject(error)
+      })
+    }).catch(error => {
+      return Promise.reject(error)
+    })
+  },
+
+  /**
+   * 清空用户信息
+   * @param commit
+   * @returns {Promise<unknown>}
+   */
+  resetToken({ commit }) {
+    return new Promise(resolve => {
+      commit('SET_TOKEN', '')
+      commit('SET_ROLES', [])
+      removeAll()
+      resolve()
+    })
+  }
+}
+
+export default {
+  namespaced: true,
+  state,
+  mutations,
+  actions
+}

+ 31 - 22
chuanyi_client/src/utils/auth.js

@@ -1,6 +1,6 @@
 import Cookies from 'js-cookie'
 
-const TOKEN_KEY = 'C_TOKEN', USER_ID_KEY = 'C_USER_ID', USER_NAME_KEY = 'C_USER_NAME'
+const TOKEN_KEY = 'C_TOKEN'
 
 export function getToken() {
     return Cookies.get(TOKEN_KEY)
@@ -14,38 +14,47 @@ export function removeToken() {
     return Cookies.remove(TOKEN_KEY)
 }
 
-export function getUserId() {
-    return Cookies.get(USER_ID_KEY)
+const UID_KEY = 'C_UID'
+
+export function getUid() {
+    return Cookies.get(UID_KEY)
+}
+
+export function setUid(id) {
+    return Cookies.set(UID_KEY, id)
 }
 
-export function setUserId(userId) {
-    return Cookies.set(USER_ID_KEY, userId)
+export function removeUid() {
+    return Cookies.remove(UID_KEY)
 }
 
-export function removeUserId() {
-    return Cookies.remove(USER_ID_KEY)
+const USERNAME_KEY = 'C_USERNAME'
+
+export function getUsername() {
+    return Cookies.get(USERNAME_KEY)
 }
 
-export function getUserName() {
-    return Cookies.get(USER_NAME_KEY)
+export function setUsername(name) {
+    return Cookies.set(USERNAME_KEY, name)
 }
 
-export function setUserName(userName) {
-    return Cookies.set(USER_NAME_KEY, userName)
+export function removeUsername() {
+    return Cookies.remove(USERNAME_KEY)
 }
 
-export function removeUserName() {
-    return Cookies.remove(USER_NAME_KEY)
+const PUB_KEY = 'PUB_KEY'
+
+export function getPubKey() {
+    return Cookies.get(PUB_KEY)
 }
 
-export function setUserInfo(user, token) {
-    setUserId(user.userId)
-    setUserName(user.userName)
-    setToken(token)
+export function setPubKey(name) {
+    return Cookies.set(PUB_KEY, name)
 }
 
-export function clearUserInfo() {
-    removeUserId()
-    removeUserName()
-    removeToken()
-}
+export function removeAll() {
+    Cookies.remove(TOKEN_KEY)
+    Cookies.remove(UID_KEY)
+    Cookies.remove(USERNAME_KEY)
+    Cookies.remove(PUB_KEY)
+}

+ 1 - 1
chuanyi_client/src/utils/request.js

@@ -15,7 +15,7 @@ axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
 // 创建axios实例
 const service = axios.create({
     // axios中请求配置有baseURL选项,表示请求URL公共部分
-    baseURL: "http://localhost:8081",
+    baseURL: "http://192.168.1.226:8081",
     // 超时
     timeout: 30000
 })

+ 11 - 22
chuanyi_client/src/views/login.vue

@@ -63,12 +63,9 @@
 </template>
 
 <script>
-import Cookies from "js-cookie";
-import { encrypt } from '@/utils/jsencrypt'
 import errorCode from '@/utils/errorCode'
-import { login, getCode, getPublicKey } from '@/api/user';
+import { getCode } from '@/api/user';
 import { Message } from "element-ui";
-import { setUserInfo } from "@/utils/auth";
 
 export default {
   name: "Login",
@@ -81,7 +78,8 @@ export default {
         password: "",
         rememberMe: false,
         code: "",
-        uid: ""
+        uid: "",
+        publicKey: ""
       },
       loginRules: {
         username: [
@@ -125,24 +123,16 @@ export default {
         if (this.captchaEnabled) {
           let data = res.data;
           this.loginForm.uid = data.uid;
-          this.publicKey = data.publicKey;
+          this.loginForm.publicKey = data.publicKey;
           this.codeUrl = "data:image/gif;base64," + data.verifyCode;
         }
       });
     },
     /**
-     * 获取公钥
-     */
-    getPublicKey() {
-      getPublicKey().then(res => {
-        this.publicKey = res.data;
-      });
-    },
-    /**
      * 登录
      */
     handleLogin() {
-      if (!this.publicKey) {
+      if (!this.loginForm.publicKey) {
         const msg = errorCode[900];
         Message.error(msg)
         return
@@ -150,14 +140,13 @@ export default {
       this.$refs.loginForm.validate(valid => {
         if (valid) {
           this.loading = true;
-          const pwd = encrypt(this.loginForm.password, this.publicKey)
-          login(this.loginForm.username.trim(), pwd, this.loginForm.code, this.loginForm.uid).then(res => {
-            setUserInfo(res.data.user, res.data.token)
-            this.$router.push({ path: this.redirect || "/" }).catch(()=>{});
-          }).catch((e) => {
-            this.loading = false;
+          this.$store.dispatch('user/Login', this.loginForm).then(() => {
+            this.$router.push({ path: this.redirect || '/', query: {} })
+            this.loading = false
+          }).catch(() => {
+            this.loading = false
             if (this.captchaEnabled) {
-              this.getCode();
+              this.getCode()
             }
           })
         }

+ 1 - 8
chuanyi_server/src/main/java/com/judong/chuanyiserver/config/OpcServerDaPoolFactory.java

@@ -153,21 +153,14 @@ public class OpcServerDaPoolFactory {
             ci.setDomain(""); // 域,为空就行
             ci.setUser(jsonObject.getString("user")); // 电脑上自己建好的用户名
             ci.setPassword(jsonObject.getString("password")); // 用户名的密码
-            // 使用MatrikonOPC Server的配置
-//            ci.setClsid("F8582CF2-88FB-11D0-B850-00C0F0104305"); // MatrikonOPC的注册表ID,可以在“组件服务”里看到
-            // 使用Stoner Simulation Server的配置
-//             ci.setClsid("83BFA400-BC06-11d4-AEC4-00902760973D"); // MatrikonOPC的注册表ID,可以在“组件服务”里看到
             // 使用KepOPC Server的配置
-            ci.setClsid("7BC0CC8E-482C-47CA-ABDC-0FE7F9C6E729"); // KEPServer的注册表ID,可以在“组件服务”里看到
-            // 使用King OPC Server的配置
-//            ci.setClsid("20667E7E-A3EF-422F-AEDD-890D23746358"); // KEPServer的注册表ID,可以在“组件服务”里看到
+            ci.setClsid(jsonObject.getString("clsid")); // KEPServer的注册表ID,可以在“组件服务”里看到
             Server server = new Server(ci, Executors.newSingleThreadScheduledExecutor());
             log.info("声明一个对象完成:" + server);
             try {
                 server.connect();
                 return server;
             } catch (Exception e) {
-//                throw new CustomException(ResultEnum.SERVER_ERROR.getRespCode(), "连接不可用");
                 server.dispose();
                 throw new CustomException(ResultEnum.SERVER_ERROR.getRespCode(), e.getMessage());
             }

+ 2 - 2
chuanyi_server/src/main/java/com/judong/chuanyiserver/controller/ConnectController.java

@@ -37,9 +37,9 @@ public class ConnectController {
      * @throws JIException
      * @throws UnknownHostException
      */
-    @GetMapping("/testConnect")
+    @PostMapping("/testConnect")
     public Result testConnect(ServerInformation serverInformation) throws AlreadyConnectedException, JIException, UnknownHostException {
-        if (Blank.isEmpty(serverInformation, serverInformation.getIpAddress(), serverInformation.getAgreementType())) {
+        if (Blank.isEmpty(serverInformation, serverInformation.getConnectName(), serverInformation.getConnectMode(), serverInformation.getIpAddress())) {
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
         }
         return connectService.testConnect(serverInformation);

+ 4 - 2
chuanyi_server/src/main/java/com/judong/chuanyiserver/controller/DepartmentController.java

@@ -54,15 +54,17 @@ public class DepartmentController {
      *
      * @param page
      * @param limit
+     * @param departmentName
+     * @param createTime
      * @return
      */
     @GetMapping("/getDepartmentListByPage")
     @PermissionControl
-    public Result getDepartmentListByPage(Integer page, Integer limit) {
+    public Result getDepartmentListByPage(Integer page, Integer limit, String departmentName, String createTime) {
         if (Blank.isEmpty(page, limit) || page < 1 || limit < 1) {
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
         }
-        return departmentService.getDepartmentListByPage(page, limit);
+        return departmentService.getDepartmentListByPage(page, limit, departmentName, createTime);
     }
 
     /**

+ 19 - 0
chuanyi_server/src/main/java/com/judong/chuanyiserver/controller/MenuController.java

@@ -1,7 +1,12 @@
 package com.judong.chuanyiserver.controller;
 
+import com.judong.chuanyiserver.annotation.PermissionControl;
+import com.judong.chuanyiserver.annotation.WebLog;
 import com.judong.chuanyiserver.entity.Menu;
+import com.judong.chuanyiserver.enums.ModelEnum;
+import com.judong.chuanyiserver.enums.OperationEnum;
 import com.judong.chuanyiserver.enums.ResultEnum;
+import com.judong.chuanyiserver.enums.ServerEnum;
 import com.judong.chuanyiserver.service.MenuService;
 import com.judong.chuanyiserver.util.Blank;
 import com.judong.chuanyiserver.util.Result;
@@ -22,6 +27,8 @@ public class MenuController {
      * @return
      */
     @PostMapping("/addMenu")
+    @PermissionControl
+    @WebLog(ServerEnum = ServerEnum.SERVER, ModelEnum = ModelEnum.MENU, OperationEnum = OperationEnum.ADD)
     public Result addMenu(Menu menu) {
         if (Blank.isEmpty(menu)) {
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
@@ -36,6 +43,8 @@ public class MenuController {
      * @return
      */
     @PostMapping("/updateMenu")
+    @PermissionControl
+    @WebLog(ServerEnum = ServerEnum.SERVER, ModelEnum = ModelEnum.MENU, OperationEnum = OperationEnum.UPDATE)
     public Result updateMenu(Menu menu) {
         if (Blank.isEmpty(menu)) {
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
@@ -51,6 +60,8 @@ public class MenuController {
      * @return
      */
     @GetMapping("/getMenuListByPage")
+    @PermissionControl
+    @WebLog(ServerEnum = ServerEnum.SERVER, ModelEnum = ModelEnum.MENU, OperationEnum = OperationEnum.SELECT)
     public Result getMenuListByPage(Integer page, Integer limit, String menuName, String menuUrl, Integer menuStatus) {
         if (Blank.isEmpty(page, limit) || page < 1 || limit < 1) {
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
@@ -65,6 +76,8 @@ public class MenuController {
      * @return
      */
     @GetMapping("/getMenuById")
+    @PermissionControl
+    @WebLog(ServerEnum = ServerEnum.SERVER, ModelEnum = ModelEnum.MENU, OperationEnum = OperationEnum.SELECT)
     public Result getMenuById(Integer id) {
         if (Blank.isEmpty(id)) {
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
@@ -79,6 +92,8 @@ public class MenuController {
      * @return
      */
     @PostMapping("/deleteMenuById")
+    @PermissionControl
+    @WebLog(ServerEnum = ServerEnum.SERVER, ModelEnum = ModelEnum.MENU, OperationEnum = OperationEnum.DELETE)
     public Result deleteMenuById(Integer id) {
         if (Blank.isEmpty(id)) {
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
@@ -93,6 +108,8 @@ public class MenuController {
      * @return
      */
     @PostMapping("/assignPermission")
+    @PermissionControl
+    @WebLog(ServerEnum = ServerEnum.SERVER, ModelEnum = ModelEnum.MENU, OperationEnum = OperationEnum.ASSIGN)
     public Result assignPermission(@RequestBody Menu menu) {
         if (Blank.isEmpty(menu, menu.getId(), menu.getPermissionList())) {
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
@@ -107,6 +124,8 @@ public class MenuController {
      * @return
      */
     @GetMapping("/getPermissionByMenuId")
+    @PermissionControl
+    @WebLog(ServerEnum = ServerEnum.SERVER, ModelEnum = ModelEnum.MENU, OperationEnum = OperationEnum.SELECT)
     public Result getPermissionByMenuId(Integer id) {
         if (Blank.isEmpty(id)) {
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());

+ 9 - 0
chuanyi_server/src/main/java/com/judong/chuanyiserver/controller/PermissionController.java

@@ -1,8 +1,12 @@
 package com.judong.chuanyiserver.controller;
 
 import com.judong.chuanyiserver.annotation.PermissionControl;
+import com.judong.chuanyiserver.annotation.WebLog;
 import com.judong.chuanyiserver.entity.Permission;
+import com.judong.chuanyiserver.enums.ModelEnum;
+import com.judong.chuanyiserver.enums.OperationEnum;
 import com.judong.chuanyiserver.enums.ResultEnum;
+import com.judong.chuanyiserver.enums.ServerEnum;
 import com.judong.chuanyiserver.service.PermissionService;
 import com.judong.chuanyiserver.util.Blank;
 import com.judong.chuanyiserver.util.Result;
@@ -27,6 +31,7 @@ public class PermissionController {
      */
     @PostMapping("/addPermission")
     @PermissionControl
+    @WebLog(ServerEnum = ServerEnum.SERVER, ModelEnum = ModelEnum.PERMISSION, OperationEnum = OperationEnum.ADD)
     public Result addPermission(Permission permission) {
         if (Blank.isEmpty(permission)) {
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
@@ -42,6 +47,7 @@ public class PermissionController {
      */
     @PostMapping("/updatePermission")
     @PermissionControl
+    @WebLog(ServerEnum = ServerEnum.SERVER, ModelEnum = ModelEnum.PERMISSION, OperationEnum = OperationEnum.UPDATE)
     public Result updatePermission(Permission permission) {
         if (Blank.isEmpty(permission)) {
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
@@ -57,6 +63,7 @@ public class PermissionController {
      */
     @GetMapping("/getPermissionById")
     @PermissionControl
+    @WebLog(ServerEnum = ServerEnum.SERVER, ModelEnum = ModelEnum.PERMISSION, OperationEnum = OperationEnum.SELECT)
     public Result getPermissionById(Integer id) {
         if (Blank.isEmpty(id)) {
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
@@ -73,6 +80,7 @@ public class PermissionController {
      */
     @GetMapping("/getPermissionListByPage")
     @PermissionControl
+    @WebLog(ServerEnum = ServerEnum.SERVER, ModelEnum = ModelEnum.PERMISSION, OperationEnum = OperationEnum.SELECT)
     public Result getPermissionListByPage(Integer page, Integer limit, String permissionUrl, String permissionName) {
         if (Blank.isEmpty(page, limit) || page < 1 || limit < 1) {
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
@@ -88,6 +96,7 @@ public class PermissionController {
      */
     @PostMapping("/deletePermissionById")
     @PermissionControl
+    @WebLog(ServerEnum = ServerEnum.SERVER, ModelEnum = ModelEnum.PERMISSION, OperationEnum = OperationEnum.DELETE)
     public Result deletePermissionById(Integer id) {
         if (Blank.isEmpty(id)) {
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());

+ 17 - 1
chuanyi_server/src/main/java/com/judong/chuanyiserver/controller/RoleController.java

@@ -1,9 +1,13 @@
 package com.judong.chuanyiserver.controller;
 
 import com.judong.chuanyiserver.annotation.PermissionControl;
+import com.judong.chuanyiserver.annotation.WebLog;
 import com.judong.chuanyiserver.entity.Role;
 import com.judong.chuanyiserver.entity.User;
+import com.judong.chuanyiserver.enums.ModelEnum;
+import com.judong.chuanyiserver.enums.OperationEnum;
 import com.judong.chuanyiserver.enums.ResultEnum;
+import com.judong.chuanyiserver.enums.ServerEnum;
 import com.judong.chuanyiserver.service.RoleService;
 import com.judong.chuanyiserver.util.Blank;
 import com.judong.chuanyiserver.util.Result;
@@ -28,6 +32,7 @@ public class RoleController {
      */
     @PostMapping("/addRole")
     @PermissionControl
+    @WebLog(ServerEnum = ServerEnum.SERVER, ModelEnum = ModelEnum.ROLE, OperationEnum = OperationEnum.ADD)
     public Result addRole(Role role) {
         if (Blank.isEmpty(role, role.getRoleName(), role.getRoleCode())) {
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
@@ -43,6 +48,7 @@ public class RoleController {
      */
     @PostMapping("/updateRole")
     @PermissionControl
+    @WebLog(ServerEnum = ServerEnum.SERVER, ModelEnum = ModelEnum.ROLE, OperationEnum = OperationEnum.UPDATE)
     public Result updateRole(Role role) {
         if (Blank.isEmpty(role)) {
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
@@ -59,6 +65,7 @@ public class RoleController {
      */
     @GetMapping("/getRoleListByPage")
     @PermissionControl
+    @WebLog(ServerEnum = ServerEnum.SERVER, ModelEnum = ModelEnum.ROLE, OperationEnum = OperationEnum.SELECT)
     public Result getRoleListByPage(Integer page, Integer limit, String roleName, String roleCode) {
         if (Blank.isEmpty(page, limit) || page < 1 || limit < 1) {
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
@@ -73,7 +80,8 @@ public class RoleController {
      * @return
      */
     @GetMapping("/getRoleById")
-//    @PermissionControl
+    @PermissionControl
+    @WebLog(ServerEnum = ServerEnum.SERVER, ModelEnum = ModelEnum.ROLE, OperationEnum = OperationEnum.SELECT)
     public Result getRoleById(Integer id) {
         if (Blank.isEmpty(id)) {
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
@@ -88,6 +96,8 @@ public class RoleController {
      * @return
      */
     @GetMapping("/getMenuListByRoleList")
+    @PermissionControl
+    @WebLog(ServerEnum = ServerEnum.SERVER, ModelEnum = ModelEnum.ROLE, OperationEnum = OperationEnum.SELECT)
     public Result getMenuListByRoleList(@RequestBody User user) {
         if (Blank.isEmpty(user, user.getRoleList())) {
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
@@ -102,6 +112,8 @@ public class RoleController {
      * @return
      */
     @PostMapping("/deleteRoleById")
+    @PermissionControl
+    @WebLog(ServerEnum = ServerEnum.SERVER, ModelEnum = ModelEnum.ROLE, OperationEnum = OperationEnum.DELETE)
     public Result deleteRoleById(Integer roleId) {
         if (Blank.isEmpty(roleId)) {
 
@@ -116,6 +128,8 @@ public class RoleController {
      * @return
      */
     @PostMapping("/assignMenu")
+    @PermissionControl
+    @WebLog(ServerEnum = ServerEnum.SERVER, ModelEnum = ModelEnum.ROLE, OperationEnum = OperationEnum.ASSIGN)
     public Result assignMenu(@RequestBody Role role) {
         if (Blank.isEmpty(role, role.getId(), role.getMenuList())) {
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
@@ -130,6 +144,8 @@ public class RoleController {
      * @return
      */
     @GetMapping("/getMenuTreeByRoleList")
+    @PermissionControl
+    @WebLog(ServerEnum = ServerEnum.SERVER, ModelEnum = ModelEnum.ROLE, OperationEnum = OperationEnum.SELECT)
     public Result getMenuTreeByRoleList(@RequestParam("roleIdList") List<Integer> roleIdList) {
         if (Blank.isEmpty(roleIdList)) {
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());

+ 62 - 7
chuanyi_server/src/main/java/com/judong/chuanyiserver/controller/UserController.java

@@ -14,6 +14,8 @@ import com.judong.chuanyiserver.util.Result;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.List;
+
 @RestController
 @RequestMapping("user")
 public class UserController {
@@ -89,8 +91,8 @@ public class UserController {
      * @return
      */
     @PostMapping("/addUser")
-    @WebLog(ServerEnum = ServerEnum.SERVER, ModelEnum = ModelEnum.USER, OperationEnum = OperationEnum.ADD)
     @PermissionControl
+    @WebLog(ServerEnum = ServerEnum.SERVER, ModelEnum = ModelEnum.USER, OperationEnum = OperationEnum.ADD)
     public Result addUser(@RequestBody User user) {
         if (Blank.isEmpty(user, user.getUserName(), user.getPassword(), user.getUserType())) {
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
@@ -104,8 +106,8 @@ public class UserController {
      * @param user
      * @return
      */
-    @PermissionControl
     @PostMapping("/updateUser")
+    @PermissionControl
     @WebLog(ServerEnum = ServerEnum.SERVER, ModelEnum = ModelEnum.USER, OperationEnum = OperationEnum.UPDATE)
     public Result updateUser(@RequestBody User user) {
         if (Blank.isEmpty(user)) {
@@ -122,7 +124,7 @@ public class UserController {
      * @return
      */
     @GetMapping("/getUserPage")
-//    @PermissionControl
+    @PermissionControl
     @WebLog(ServerEnum = ServerEnum.SERVER, ModelEnum = ModelEnum.USER, OperationEnum = OperationEnum.SELECT)
     public Result getUserPage(int page, int limit, String userName, Integer state, Integer userType) {
         if (Blank.isEmpty(page, limit) || page < 1 || limit < 1) {
@@ -153,8 +155,8 @@ public class UserController {
      * @return
      */
     @PostMapping("/updateUserStateById")
-    @WebLog(ServerEnum = ServerEnum.SERVER, ModelEnum = ModelEnum.USER, OperationEnum = OperationEnum.UPDATE)
     @PermissionControl
+    @WebLog(ServerEnum = ServerEnum.SERVER, ModelEnum = ModelEnum.USER, OperationEnum = OperationEnum.UPDATE)
     public Result updateUserStateById(String userId, Integer userState) {
         if (Blank.isEmpty(userId, userState)) {
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
@@ -169,8 +171,8 @@ public class UserController {
      * @return
      */
     @PostMapping("/deleteUserById")
-    @WebLog(ServerEnum = ServerEnum.SERVER, ModelEnum = ModelEnum.USER, OperationEnum = OperationEnum.DELETE)
     @PermissionControl
+    @WebLog(ServerEnum = ServerEnum.SERVER, ModelEnum = ModelEnum.USER, OperationEnum = OperationEnum.DELETE)
     public Result deleteUserById(@RequestBody User user) {
         if (Blank.isEmpty(user, user.getUserId())) {
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
@@ -185,8 +187,8 @@ public class UserController {
      * @return
      */
     @PostMapping("/assignRole")
-    @WebLog(ServerEnum = ServerEnum.SERVER, ModelEnum = ModelEnum.USER, OperationEnum = OperationEnum.ASSIGNROLE)
-//    @PermissionControl
+    @PermissionControl
+    @WebLog(ServerEnum = ServerEnum.SERVER, ModelEnum = ModelEnum.USER, OperationEnum = OperationEnum.ASSIGN)
     public Result assignRole(@RequestBody User user) {
         if (Blank.isEmpty(user, user.getUserId(), user.getRoleList())) {
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
@@ -194,4 +196,57 @@ public class UserController {
         return userService.assignRole(user.getUserId(), user.getRoleList());
     }
 
+    /**
+     * 根据角色ID查询该角色下人员
+     *
+     * @param page
+     * @param limit
+     * @param roleId
+     * @param userName
+     * @return
+     */
+    @GetMapping("/getUserListByRoleId")
+    @PermissionControl
+    @WebLog(ServerEnum = ServerEnum.SERVER, ModelEnum = ModelEnum.USER, OperationEnum = OperationEnum.SELECT)
+    public Result getUserListByRoleId(Integer page, Integer limit, Integer roleId, String userName) {
+        if (Blank.isEmpty(page, limit) || page < 1 || limit < 1) {
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
+        }
+        return userService.getUserListByRoleId(page, limit, roleId, userName);
+    }
+
+    /**
+     * 根据用户列表授权某一个角色
+     *
+     * @param userIdList
+     * @param roleId
+     * @return
+     */
+    @PostMapping("/assignUserListByRoleId")
+    @PermissionControl
+    @WebLog(ServerEnum = ServerEnum.SERVER, ModelEnum = ModelEnum.USER, OperationEnum = OperationEnum.ASSIGN)
+    public Result assignUserListByRoleId(List<String> userIdList, Integer roleId) {
+        if (Blank.isEmpty(userIdList, roleId)) {
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
+        }
+        return userService.assignUserListByRoleId(userIdList, roleId);
+    }
+
+    /**
+     * 根据角色ID和用户ID解除角色权限
+     *
+     * @param userId
+     * @param roleId
+     * @return
+     */
+    @PostMapping("/relieveUserRole")
+    @PermissionControl
+    @WebLog(ServerEnum = ServerEnum.SERVER, ModelEnum = ModelEnum.USER, OperationEnum = OperationEnum.RELIEVE)
+    public Result relieveUserRole(String userId, String roleId) {
+        if (Blank.isEmpty(userId, roleId)) {
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
+        }
+        return userService.relieveUserRole(userId, roleId);
+    }
+
 }

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

@@ -16,9 +16,9 @@ public interface DepartmentDao {
 
     Integer updateDepartment(Department department);
 
-    Long getDepartmentCount();
+    Long getDepartmentCount(String departmentName, String createTime, Integer noDelete);
 
-    List<Department> getDepartmentListByPage(Long startNum, Long limitNum);
+    List<Department> getDepartmentListByPage(Long startNum, Long limitNum, String departmentName, String createTime, Integer noDelete);
 
     Department getDepartmentById(Integer id);
 }

+ 1 - 1
chuanyi_server/src/main/java/com/judong/chuanyiserver/dao/RoleDao.java

@@ -22,7 +22,7 @@ public interface RoleDao {
 
     List<Role> getRoleListByPage(Long startNum, Long limitNum, String roleName, String roleCode, Integer noDelete);
 
-    Role getRoleById(Integer id);
+    Role getRoleById(Integer id, Integer noDelete);
 
     List<Menu> getMenuListByroleList(List<Role> roleList);
 

+ 9 - 0
chuanyi_server/src/main/java/com/judong/chuanyiserver/dao/UserDao.java

@@ -44,4 +44,13 @@ public interface UserDao {
 
     User getUserByNameNoId(String userId, String userName);
 
+    Long getUserListByRoleIdCount(Integer roleId, String userName, Integer noDelete, Integer tombstoneUser);
+
+    List<User> getUserListByRoleId(Long startNum, Long limitNum, Integer roleId, String userName, Integer noDelete, Integer tombstoneUser);
+
+    List<String> getAssignUserIdList(List<String> userIdList, Integer roleId);
+
+    Integer assignUserListByRoleId(List<String> userIdList, Integer roleId);
+
+    Integer deleteByUserIdRoleId(String userId, String roleId);
 }

+ 5 - 0
chuanyi_server/src/main/java/com/judong/chuanyiserver/entity/Department.java

@@ -1,5 +1,6 @@
 package com.judong.chuanyiserver.entity;
 
+import com.judong.chuanyiserver.util.ConstantStr;
 import lombok.Data;
 
 import java.io.Serializable;
@@ -38,4 +39,8 @@ public class Department implements Serializable {
      * 修改时间
      */
     private Date updateTime;
+    /**
+     * 逻辑删除0未删除,1已删除
+     */
+    private Integer isDelete = ConstantStr.PUBLIC_NO_DELETE;
 }

+ 2 - 1
chuanyi_server/src/main/java/com/judong/chuanyiserver/entity/Role.java

@@ -1,5 +1,6 @@
 package com.judong.chuanyiserver.entity;
 
+import com.judong.chuanyiserver.util.ConstantStr;
 import lombok.Data;
 
 import java.io.Serializable;
@@ -24,7 +25,7 @@ public class Role implements Serializable {
     /**
      * 逻辑删除0未删除,1已删除
      */
-    private Integer isDelete;
+    private Integer isDelete = ConstantStr.PUBLIC_NO_DELETE;
 
     private List<Menu> menuList;
 }

+ 12 - 0
chuanyi_server/src/main/java/com/judong/chuanyiserver/entity/ServerInformation.java

@@ -17,11 +17,23 @@ public class ServerInformation implements Serializable {
      * 用户id
      */
     private String userId;
+    /**
+     * 连接名称
+     */
+    private String connectName;
+    /**
+     * 连接方式;0KepServer,1kingScada
+     */
+    private int connectMode;
 
     /**
      * ip地址
      */
     private String ipAddress;
+    /**
+     * ip端口
+     */
+    private String ipPort;
 
     /**
      * ip用户名

+ 32 - 0
chuanyi_server/src/main/java/com/judong/chuanyiserver/enums/ConnectModeEnum.java

@@ -0,0 +1,32 @@
+package com.judong.chuanyiserver.enums;
+
+public enum ConnectModeEnum {
+    KEPOPCSERVER("7BC0CC8E-482C-47CA-ABDC-0FE7F9C6E729", 0),
+    KingOPCServer("20667E7E-A3EF-422F-AEDD-890D23746358", 1),
+    STONERSIMULATIONSERVER("83BFA400-BC06-11d4-AEC4-00902760973D", 2),
+    MATRIKONOPCSERVER("F8582CF2-88FB-11D0-B850-00C0F0104305", 3);
+
+    private String name;
+    private Integer value;
+
+    ConnectModeEnum(String name, Integer value) {
+        this.name = name;
+        this.value = value;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public Integer getValue() {
+        return value;
+    }
+
+    public void setValue(Integer value) {
+        this.value = value;
+    }
+}

+ 1 - 1
chuanyi_server/src/main/java/com/judong/chuanyiserver/enums/ModelEnum.java

@@ -4,7 +4,7 @@ public enum ModelEnum {
 
     UNKNOWN("未知模块", "UNKNOWN"),
 
-    USER("用户管理", "USER"), ROLE("角色管理", "ROLE"), BASIC_DATA("基础数据", "BASIC_DATA"), MENU("菜单管理", "MENU"),
+    USER("用户管理", "USER"), ROLE("角色管理", "ROLE"), BASIC_DATA("基础数据", "BASIC_DATA"), MENU("菜单管理", "MENU"),PERMISSION("接口权限管理", "PERMISSION"),
     DEPT("组织机构管理", "DEPT"), GROUP("用户组管理", "GROUP"), PERSON("人员管理", "PERSON"),
     MOBILE("移动端", "MOBILE"),
     WEBSITE("站点管理", "WEBSITE"),

+ 1 - 1
chuanyi_server/src/main/java/com/judong/chuanyiserver/enums/OperationEnum.java

@@ -6,7 +6,7 @@ public enum OperationEnum {
 
     LOGIN("登录", "LOGIN"), LOGOUT("退出登录", "LOGOUT"), UPDATEPASSWORD("修改密码", "UPDATEPASSWORD"),
     ADD("新增", "ADD"), SELECT("查看", "SELECT"), UPDATE("编辑", "UPDATE"), DELETE("删除", "DELETE"),
-    ASSIGNROLE("分配角色", "ASSIGNROLE"),
+    ASSIGN("分配", "ASSIGN"),RELIEVE("解除", "RELIEVE"),
     IMPORT("导入", "IMPORT"), EXPORT("导出", "EXPORT"),
     REGISTER("注册", "REGISTER");
 

+ 7 - 1
chuanyi_server/src/main/java/com/judong/chuanyiserver/exception/GlobalExceptionHandler.java

@@ -9,6 +9,8 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
 import org.springframework.web.bind.annotation.ResponseBody;
 
 import javax.annotation.Resource;
+import java.io.PrintWriter;
+import java.io.StringWriter;
 
 @ResponseBody
 @ControllerAdvice
@@ -24,10 +26,14 @@ public class GlobalExceptionHandler {
     public Result error(Exception e) {
         Log log = new Log();
         e.printStackTrace();
+//        StringWriter stringWriter= new StringWriter();
+//        PrintWriter writer= new PrintWriter(stringWriter);
+//        e.printStackTrace(writer);
+//        StringBuffer buffer= stringWriter.getBuffer();
         log.setContent(e.getMessage());
         log.setOperationStatus(500);
         logService.insertLog(log);
-        return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), ResultEnum.SERVER_ERROR.getRespMsg());
+        return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), e.getMessage());
     }
 
     /**

+ 1 - 1
chuanyi_server/src/main/java/com/judong/chuanyiserver/service/ConnectService.java

@@ -15,7 +15,7 @@ public interface ConnectService {
 
     Result readItemValue(int id, String itemName) throws Exception;
 
-    Result testConnect(ServerInformation serverInformation) throws AlreadyConnectedException, JIException, UnknownHostException;
+    Result testConnect(ServerInformation serverInformation) throws Exception;
 
     Result selectAllConnect();
 

+ 1 - 1
chuanyi_server/src/main/java/com/judong/chuanyiserver/service/DepartmentService.java

@@ -9,7 +9,7 @@ public interface DepartmentService {
 
     Result updateDepartment(Department department);
 
-    Result getDepartmentListByPage(Integer page, Integer limit);
+    Result getDepartmentListByPage(Integer page, Integer limit, String departmentName, String createTime);
 
     Result getDepartmentById(Integer id);
 }

+ 6 - 0
chuanyi_server/src/main/java/com/judong/chuanyiserver/service/UserService.java

@@ -48,4 +48,10 @@ public interface UserService {
     Result getCodeImage(boolean hasPubKey);
 
     Result deleteUserById(String userId);
+
+    Result getUserListByRoleId(Integer page, Integer limit, Integer roleId, String userName);
+
+    Result assignUserListByRoleId(List<String> userIdList, Integer roleId);
+
+    Result relieveUserRole(String userId, String roleId);
 }

+ 37 - 25
chuanyi_server/src/main/java/com/judong/chuanyiserver/service/impl/ConnectServiceImpl.java

@@ -2,45 +2,58 @@ package com.judong.chuanyiserver.service.impl;
 
 import com.judong.chuanyiserver.dao.ConnectDao;
 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 com.judong.chuanyiserver.service.ConnectService;
 import com.judong.chuanyiserver.util.*;
 import lombok.extern.slf4j.Slf4j;
 import org.jinterop.dcom.common.JIException;
-import org.openscada.opc.dcom.da.OPCSERVERSTATE;
 import org.openscada.opc.lib.common.AlreadyConnectedException;
-import org.openscada.opc.lib.common.ConnectionInformation;
-import org.openscada.opc.lib.da.Server;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import javax.annotation.Resource;
 import java.net.UnknownHostException;
-import java.util.concurrent.Executors;
 
 @Service
 @Transactional
 @Slf4j
 public class ConnectServiceImpl implements ConnectService {
 
-    @Autowired
+    @Resource
     private ConnectDao connectDao;
-    @Autowired
+
+    @Resource
     private UserUtil userUtil;
 
     @Override
-    public Result testConnect(ServerInformation serverInformation) throws AlreadyConnectedException, JIException, UnknownHostException {
-        switch (serverInformation.getAgreementType()) {
-            case ConstantStr.OPC_DA:
-                if(Blank.isEmpty(serverInformation.getIpUserName(),serverInformation.getIpPassword())){
-                    return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
+    public Result testConnect(ServerInformation serverInformation) throws Exception {
+        serverInformation.setIpPassword(RSAUtil.encryptByPublic(serverInformation.getIpPassword(), RSAUtil.PUBLIC_KEY));
+        //如果连接方式为kepOpcserver
+        if (serverInformation.getConnectMode() == ConnectModeEnum.KEPOPCSERVER.getValue()) {
+            if (Blank.isEmpty(serverInformation.getIpUserName(), serverInformation.getIpPassword())) {
+                return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
+            }
+            return KepOpcServerUtil.opcTestConnect(serverInformation);
+            //如果连接方式为kingOpcserver
+        } else if (serverInformation.getConnectMode() == ConnectModeEnum.KingOPCServer.getValue()) {
+            if (Blank.isEmpty(serverInformation.getIpAddress(), serverInformation.getIpPort())) {
+                return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
+            }
+            if (Blank.isEmpty(serverInformation.getIsAnonymous())) {
+                return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
+            } else {
+                if (serverInformation.getIsAnonymous() == ConstantStr.NOT_ANONYMOUS) {
+                    if (Blank.isEmpty(serverInformation.getIpUserName(), serverInformation.getIpPassword())) {
+                        return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
+                    }
                 }
-                return OpcServerDaUtil.opcDaTestConnect(serverInformation);
-            case ConstantStr.OPC_UA:
-                return OpcServerDaUtil.opcDaTestConnect(serverInformation);
-            default:
-                throw new CustomException(ResultEnum.NOT_FOUND.getRespCode(), "没有此协议类型");
+                return OpcServerUaUtil.opcTestConnect(serverInformation);
+            }
+        } else {
+            return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "没有此连接方式");
         }
     }
 
@@ -93,12 +106,11 @@ public class ConnectServiceImpl implements ConnectService {
         if (Blank.isEmpty(serverInformation)) {
             return Result.no(ResultEnum.NOT_FOUND.getRespCode(), ResultEnum.NOT_FOUND.getRespMsg());
         }
-        switch (serverInformation.getAgreementType()) {
-            //如果协议类型为OPCDA
-            case ConstantStr.OPC_DA:
-                return OpcServerDaUtil.opcDaReadItemTree(serverInformation);
-            default:
-                throw new CustomException(ResultEnum.NOT_FOUND.getRespCode(), "没有此协议类型");
+        //如果连接方式为kepserver
+        if (serverInformation.getConnectMode() == ConnectModeEnum.KEPOPCSERVER.getValue()) {
+            return KepOpcServerUtil.opcReadItemTree(serverInformation);
+        } else {
+            throw new CustomException(ResultEnum.NOT_FOUND.getRespCode(), "没有此连接方式");
         }
     }
 
@@ -108,9 +120,9 @@ public class ConnectServiceImpl implements ConnectService {
         if (Blank.isEmpty(serverInformation)) {
             return Result.no(ResultEnum.NOT_FOUND.getRespCode(), ResultEnum.NOT_FOUND.getRespMsg());
         }
-        //如果协议类型为OPCDA
-        if (serverInformation.getAgreementType() == ConstantStr.OPC_DA) {
-            return OpcServerDaUtil.opcDaReadItemValue(serverInformation, itemName);
+        //如果连接方式为kepserver
+        if (serverInformation.getConnectMode() == ConnectModeEnum.KEPOPCSERVER.getValue()) {
+            return KepOpcServerUtil.opcReadItemValue(serverInformation, itemName);
         }
         return Result.no(ResultEnum.NOT_FOUND.getRespCode(), ResultEnum.NOT_FOUND.getRespMsg());
     }

+ 13 - 6
chuanyi_server/src/main/java/com/judong/chuanyiserver/service/impl/DepartmentServiceImpl.java

@@ -6,18 +6,19 @@ import com.judong.chuanyiserver.entity.Department;
 import com.judong.chuanyiserver.enums.ResultEnum;
 import com.judong.chuanyiserver.service.DepartmentService;
 import com.judong.chuanyiserver.util.Blank;
+import com.judong.chuanyiserver.util.ConstantStr;
 import com.judong.chuanyiserver.util.Result;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import javax.annotation.Resource;
 import java.util.List;
 
 @Service
 @Transactional
 public class DepartmentServiceImpl implements DepartmentService {
 
-    @Autowired
+    @Resource
     private DepartmentDao departmentDao;
 
     @Override
@@ -49,11 +50,11 @@ public class DepartmentServiceImpl implements DepartmentService {
     }
 
     @Override
-    public Result getDepartmentListByPage(Integer page, Integer limit) {
+    public Result getDepartmentListByPage(Integer page, Integer limit, String departmentName, String createTime) {
         JSONObject jsonObject = new JSONObject();
-        Long count = departmentDao.getDepartmentCount();
+        Long count = departmentDao.getDepartmentCount(departmentName, createTime, ConstantStr.PUBLIC_NO_DELETE);
         Long startNum = Long.valueOf((page - 1) * limit);
-        List<Department> departmentList = departmentDao.getDepartmentListByPage(startNum, Long.valueOf(limit));
+        List<Department> departmentList = departmentDao.getDepartmentListByPage(startNum, Long.valueOf(limit), departmentName, createTime, ConstantStr.PUBLIC_NO_DELETE);
         jsonObject.put("count", count);
         jsonObject.put("departmentList", departmentList);
         return Result.ok(jsonObject);
@@ -61,6 +62,12 @@ public class DepartmentServiceImpl implements DepartmentService {
 
     @Override
     public Result getDepartmentById(Integer id) {
-        return Result.ok(departmentDao.getDepartmentById(id));
+        Department department = departmentDao.getDepartmentById(id);
+        if (Blank.isNotEmpty(department)) {
+            if (department.getIsDelete() == ConstantStr.PUBLIC_IS_DELETE) {
+                return Result.no(ResultEnum.NOT_FOUND.getRespCode(), "该部门已被逻辑删除,请联系管理员");
+            }
+        }
+        return Result.ok(department);
     }
 }

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

@@ -6,17 +6,17 @@ import com.judong.chuanyiserver.entity.Log;
 import com.judong.chuanyiserver.enums.ResultEnum;
 import com.judong.chuanyiserver.service.LogService;
 import com.judong.chuanyiserver.util.Result;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import javax.annotation.Resource;
 import java.util.List;
 
 @Service
 @Transactional
 public class LogServiceImpl implements LogService {
 
-    @Autowired
+    @Resource
     private LogDao logDao;
 
     @Override

+ 5 - 3
chuanyi_server/src/main/java/com/judong/chuanyiserver/service/impl/MenuServiceImpl.java

@@ -9,16 +9,18 @@ import com.judong.chuanyiserver.service.MenuService;
 import com.judong.chuanyiserver.util.Blank;
 import com.judong.chuanyiserver.util.ConstantStr;
 import com.judong.chuanyiserver.util.Result;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
-import java.util.*;
+import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.List;
 
 @Service
 @Transactional
 public class MenuServiceImpl implements MenuService {
-    @Autowired
+
+    @Resource
     private MenuDao menuDao;
 
     @Override

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

@@ -7,17 +7,17 @@ import com.judong.chuanyiserver.enums.ResultEnum;
 import com.judong.chuanyiserver.service.PermissionService;
 import com.judong.chuanyiserver.util.Blank;
 import com.judong.chuanyiserver.util.Result;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import javax.annotation.Resource;
 import java.util.List;
 
 @Service
 @Transactional
 public class PermissionServiceImpl implements PermissionService {
 
-    @Autowired
+    @Resource
     private PermissionDao permissionDao;
 
     @Override

+ 3 - 4
chuanyi_server/src/main/java/com/judong/chuanyiserver/service/impl/RoleServiceImpl.java

@@ -9,19 +9,18 @@ import com.judong.chuanyiserver.service.RoleService;
 import com.judong.chuanyiserver.util.Blank;
 import com.judong.chuanyiserver.util.ConstantStr;
 import com.judong.chuanyiserver.util.Result;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import javax.annotation.Resource;
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.List;
 
 @Service
 @Transactional
 public class RoleServiceImpl implements RoleService {
 
-    @Autowired
+    @Resource
     private RoleDao roleDao;
 
     @Override
@@ -62,7 +61,7 @@ public class RoleServiceImpl implements RoleService {
 
     @Override
     public Result getRoleById(Integer id) {
-        return Result.ok(roleDao.getRoleById(id));
+        return Result.ok(roleDao.getRoleById(id, ConstantStr.PUBLIC_NO_DELETE));
     }
 
     @Override

+ 4 - 3
chuanyi_server/src/main/java/com/judong/chuanyiserver/service/impl/ServerInServiceImpl.java

@@ -4,18 +4,19 @@ import com.judong.chuanyiserver.dao.ServerInDao;
 import com.judong.chuanyiserver.service.ServerInService;
 import com.judong.chuanyiserver.util.Result;
 import com.judong.chuanyiserver.util.UserUtil;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import javax.annotation.Resource;
+
 @Service
 @Transactional
 public class ServerInServiceImpl implements ServerInService {
 
-    @Autowired
+    @Resource
     private ServerInDao serverInDao;
 
-    @Autowired
+    @Resource
     private UserUtil userUtil;
 
     @Override

+ 52 - 4
chuanyi_server/src/main/java/com/judong/chuanyiserver/service/impl/UserServiceImpl.java

@@ -12,10 +12,10 @@ import com.judong.chuanyiserver.exception.CustomException;
 import com.judong.chuanyiserver.service.UserService;
 import com.judong.chuanyiserver.util.*;
 import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import java.util.ArrayList;
 import java.util.List;
@@ -26,13 +26,13 @@ import java.util.UUID;
 @Transactional
 public class UserServiceImpl implements UserService {
 
-    @Autowired
+    @Resource
     private UserDao userDao;
 
-    @Autowired
+    @Resource
     private RedisUtil redisUtil;
 
-    @Autowired
+    @Resource
     private UserUtil userUtil;
 
     @Override
@@ -299,6 +299,54 @@ public class UserServiceImpl implements UserService {
     }
 
     @Override
+    public Result getUserListByRoleId(Integer page, Integer limit, Integer roleId, String userName) {
+        JSONObject jsonObject = new JSONObject();
+        Long count = userDao.getUserListByRoleIdCount(roleId, userName, ConstantStr.PUBLIC_NO_DELETE, ConstantStr.TOMBSTONE);
+        Long startNum = Long.valueOf((page - 1) * limit);
+        List<User> userList = userDao.getUserListByRoleId(startNum, Long.valueOf(limit), roleId, userName, ConstantStr.PUBLIC_NO_DELETE, ConstantStr.TOMBSTONE);
+        jsonObject.put("count", count);
+        jsonObject.put("userList", userList);
+        return Result.ok(jsonObject);
+    }
+
+    @Override
+    public synchronized Result assignUserListByRoleId(List<String> userIdList, Integer roleId) {
+        //获取已经分配此角色id的用户id
+        List<String> assignUserIdList = userDao.getAssignUserIdList(userIdList, roleId);
+        List<String> noAssignUserIdList = new ArrayList<>();
+        if (Blank.isEmpty(assignUserIdList)) {
+            noAssignUserIdList = userIdList;
+        } else {
+            for (String userId : userIdList) {
+                Boolean flage = true;
+                for (int i = 0; i < assignUserIdList.size(); i++) {
+                    if (userId.equals(assignUserIdList.get(i))) {
+                        flage = false;
+                    }
+                }
+                if (flage) {
+                    noAssignUserIdList.add(userId);
+                }
+            }
+        }
+        if (Blank.isEmpty(noAssignUserIdList)) {
+            return Result.ok("分配角色成功");
+        }
+        if (userDao.assignUserListByRoleId(noAssignUserIdList, roleId) <= 0) {
+            return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), "分配角色失败");
+        }
+        return Result.ok("分配角色成功");
+    }
+
+    @Override
+    public Result relieveUserRole(String userId, String roleId) {
+        if (userDao.deleteByUserIdRoleId(userId, roleId) <= 0) {
+            return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), "解除角色失败");
+        }
+        return Result.ok("解除角色成功");
+    }
+
+    @Override
     public synchronized Result updateUser(User user) {
         if (Blank.isEmpty(user.getUserId(), user.getUserName(), user.getState(), user.getUserType())) {
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), "用户Id不能为空,用户名不能为空,用户状态不能为空,用户类型不能为空");

+ 1 - 1
chuanyi_server/src/main/java/com/judong/chuanyiserver/util/ConstantStr.java

@@ -39,7 +39,7 @@ public class ConstantStr {
     //顶级菜单常量
     public static final Integer TOP_LEVEL_MENU = 0;
 
-    //UA登录是否匿名
+    //UA登录是否匿名;0不匿名,1匿名
     public static final Integer NOT_ANONYMOUS = 0;
     public static final Integer IS_ANONYMOUS = 1;
 

+ 27 - 23
chuanyi_server/src/main/java/com/judong/chuanyiserver/util/OpcServerDaUtil.java → chuanyi_server/src/main/java/com/judong/chuanyiserver/util/KepOpcServerUtil.java

@@ -3,6 +3,7 @@ package com.judong.chuanyiserver.util;
 import com.alibaba.fastjson.JSONObject;
 import com.judong.chuanyiserver.config.OpcServerDaPoolFactory;
 import com.judong.chuanyiserver.entity.ServerInformation;
+import com.judong.chuanyiserver.enums.ConnectModeEnum;
 import com.judong.chuanyiserver.enums.ResultEnum;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.pool2.impl.GenericKeyedObjectPool;
@@ -23,10 +24,10 @@ import java.util.*;
 import java.util.concurrent.Executors;
 
 /**
- * OPCDa协议工具类
+ * KepOpcServer协议工具类
  */
 @Slf4j
-public class OpcServerDaUtil {
+public class KepOpcServerUtil {
 
     /**
      * 通过ip,user,password生成对应的连接池键
@@ -34,14 +35,16 @@ public class OpcServerDaUtil {
      * @param ip
      * @param user
      * @param password
+     * @param clsid
      * @return
      */
-    public static String generateOpcPoolKey(String ip, String user, String password) {
+    public static String generateOpcPoolKey(String ip, String user, String password, String clsid) {
         StringBuffer buffer = new StringBuffer("");
         buffer.append("{\"ip\":\"");
         buffer.append(ip + "\",\"user\":\"");
         buffer.append(user + "\",\"password\":\"");
-        buffer.append(password + "\"}");
+        buffer.append(password + "\",\"clsid\":\"");
+        buffer.append(clsid + "\"}");
         return buffer.toString();
     }
 
@@ -55,11 +58,12 @@ public class OpcServerDaUtil {
         if (Blank.isEmpty(key)) {
             return false;
         }
-        JSONObject jsonObject = (JSONObject) JSONObject.parse(key);
-        String ip = (String) jsonObject.get("ip");
-        String user = (String) jsonObject.get("user");
-        String password = (String) jsonObject.get("password");
-        if (Blank.isEmpty(ip) || Blank.isEmpty(user) || Blank.isEmpty(password)) {
+        JSONObject jsonObject = JSONObject.parseObject(key);
+        String ip = jsonObject.getString("ip");
+        String user = jsonObject.getString("user");
+        String password = jsonObject.getString("password");
+        String clsid = jsonObject.getString("clsid");
+        if (Blank.isEmpty(ip, user, password, clsid)) {
             return false;
         }
         return true;
@@ -95,7 +99,7 @@ public class OpcServerDaUtil {
         return OpcServerDaPoolFactory.getPool();
     }
 
-    public static Result opcDaTestConnect(ServerInformation serverInformation) throws AlreadyConnectedException, JIException, UnknownHostException {
+    public static Result opcTestConnect(ServerInformation serverInformation) throws AlreadyConnectedException, JIException, UnknownHostException {
         // 连接信息
         ConnectionInformation ci = new ConnectionInformation();
         //服务
@@ -105,7 +109,7 @@ public class OpcServerDaUtil {
             ci.setDomain(""); // 域,为空就行
             ci.setUser(serverInformation.getIpUserName()); // 电脑上自己建好的用户名
             ci.setPassword(serverInformation.getIpPassword()); // 用户名的密码
-            ci.setClsid("7BC0CC8E-482C-47CA-ABDC-0FE7F9C6E729"); // KEPServer的注册表ID,可以在“组件服务”里看到
+            ci.setClsid(ConnectModeEnum.KEPOPCSERVER.getName()); // KEPServer的注册表ID,可以在“组件服务”里看到
             // ci.setProgId("");
 
             // 连接到服务
@@ -133,17 +137,17 @@ public class OpcServerDaUtil {
      * @return
      * @throws Exception
      */
-    public static Result opcDaReadItemTree(ServerInformation serverInformation) throws Exception {
-        String opcServerDaPoolKey = OpcServerDaUtil.generateOpcPoolKey(serverInformation.getIpAddress(), serverInformation.getIpUserName(), RSAUtil.decrypt(serverInformation.getIpPassword(), "utf-8"));
-        if (OpcServerDaUtil.validationKey(opcServerDaPoolKey)) {
-            Server server = OpcServerDaUtil.getServer(opcServerDaPoolKey);
+    public static Result opcReadItemTree(ServerInformation serverInformation) throws Exception {
+        String opcServerDaPoolKey = KepOpcServerUtil.generateOpcPoolKey(serverInformation.getIpAddress(), serverInformation.getIpUserName(), RSAUtil.decrypt(serverInformation.getIpPassword(), "utf-8"), ConnectModeEnum.KEPOPCSERVER.getName());
+        if (KepOpcServerUtil.validationKey(opcServerDaPoolKey)) {
+            Server server = KepOpcServerUtil.getServer(opcServerDaPoolKey);
             if (null == server.getServerState()) {
                 return Result.no(ResultEnum.NOT_FOUND.getRespCode(), "连接失败");
             }
             if (OPCSERVERSTATE.OPC_STATUS_RUNNING == server.getServerState().getServerState()) {
                 JSONObject jsonObject = new JSONObject();
-                jsonObject.put("tree", OpcServerDaUtil.generOpcDaTree(server));
-                OpcServerDaUtil.returnServer(opcServerDaPoolKey, server);
+                jsonObject.put("tree", KepOpcServerUtil.generOpcTree(server));
+                KepOpcServerUtil.returnServer(opcServerDaPoolKey, server);
                 return Result.ok(jsonObject);
             }
         }
@@ -158,10 +162,10 @@ public class OpcServerDaUtil {
      * @return
      * @throws Exception
      */
-    public static Result opcDaReadItemValue(ServerInformation serverInformation, String itemName) throws Exception {
-        String opcServerDaPoolKey = OpcServerDaUtil.generateOpcPoolKey(serverInformation.getIpAddress(), serverInformation.getIpUserName(), RSAUtil.decrypt(serverInformation.getIpPassword(), "utf-8"));
-        if (OpcServerDaUtil.validationKey(opcServerDaPoolKey)) {
-            Server server = OpcServerDaUtil.getServer(opcServerDaPoolKey);
+    public static Result opcReadItemValue(ServerInformation serverInformation, String itemName) throws Exception {
+        String opcServerDaPoolKey = KepOpcServerUtil.generateOpcPoolKey(serverInformation.getIpAddress(), serverInformation.getIpUserName(), RSAUtil.decrypt(serverInformation.getIpPassword(), "utf-8"), ConnectModeEnum.KEPOPCSERVER.getName());
+        if (KepOpcServerUtil.validationKey(opcServerDaPoolKey)) {
+            Server server = KepOpcServerUtil.getServer(opcServerDaPoolKey);
             if (null == server.getServerState()) {
                 return Result.no(ResultEnum.NOT_FOUND.getRespCode(), "连接失败");
             }
@@ -172,7 +176,7 @@ public class OpcServerDaUtil {
                 Map<String, Object> value = getVal(item.read(true).getValue());
                 jsonObject.put("javaType", value.get("javaType"));
                 jsonObject.put("value", value);
-                OpcServerDaUtil.returnServer(opcServerDaPoolKey, server);
+                KepOpcServerUtil.returnServer(opcServerDaPoolKey, server);
                 return Result.ok(jsonObject);
             }
         }
@@ -184,7 +188,7 @@ public class OpcServerDaUtil {
      *
      * @return
      */
-    public static List<JSONObject> generOpcDaTree(Server server) throws JIException, UnknownHostException {
+    public static List<JSONObject> generOpcTree(Server server) throws JIException, UnknownHostException {
         List<JSONObject> jsonList = new ArrayList<>();
         //获取服务器下所有ITEM列表,树形展示
         TreeBrowser treeBrowser = server.getTreeBrowser();

+ 31 - 7
chuanyi_server/src/main/java/com/judong/chuanyiserver/util/OpcServerUaUtil.java

@@ -1,13 +1,17 @@
 package com.judong.chuanyiserver.util;
 
 import com.alibaba.fastjson.JSONObject;
+import com.judong.chuanyiserver.entity.ServerInformation;
+import com.judong.chuanyiserver.enums.ResultEnum;
 import lombok.extern.slf4j.Slf4j;
 import org.eclipse.milo.opcua.sdk.client.OpcUaClient;
 import org.eclipse.milo.opcua.sdk.client.api.config.OpcUaClientConfig;
 import org.eclipse.milo.opcua.sdk.client.api.identity.AnonymousProvider;
+import org.eclipse.milo.opcua.sdk.client.api.identity.UsernameProvider;
 import org.eclipse.milo.opcua.sdk.client.nodes.UaNode;
 import org.eclipse.milo.opcua.stack.client.DiscoveryClient;
 import org.eclipse.milo.opcua.stack.core.Identifiers;
+import org.eclipse.milo.opcua.stack.core.Stack;
 import org.eclipse.milo.opcua.stack.core.UaException;
 import org.eclipse.milo.opcua.stack.core.security.SecurityPolicy;
 import org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText;
@@ -16,6 +20,7 @@ import org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned;
 import org.eclipse.milo.opcua.stack.core.types.enumerated.TimestampsToReturn;
 import org.eclipse.milo.opcua.stack.core.types.structured.EndpointDescription;
 import org.jinterop.dcom.common.JIException;
+import org.openscada.opc.dcom.da.OPCSERVERSTATE;
 import org.openscada.opc.lib.da.Server;
 import org.openscada.opc.lib.da.browser.Branch;
 import org.openscada.opc.lib.da.browser.TreeBrowser;
@@ -38,7 +43,7 @@ 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:49322";
 //    private static final String endpointUrl = "opc.tcp://192.168.0.252:37800";
 
     /**
@@ -46,7 +51,8 @@ public class OpcServerUaUtil {
      *
      * @return
      */
-    public static OpcUaClient createClient() throws Exception {
+    public static OpcUaClient createClient(ServerInformation serverInformation) throws Exception {
+        String endpointUrl = serverInformation.getIpAddress() + ":" + serverInformation.getIpPort();
         Path securityTempDir = Paths.get(certPath, "security");
 
         Files.createDirectories(securityTempDir);
@@ -76,8 +82,8 @@ public class OpcServerUaUtil {
                 .setApplicationUri("urn:Jellyleo:UnifiedAutomation:UaExpert@Jellyleo")
                 .setCertificate(loader.getClientCertificate()).setKeyPair(loader.getClientKeyPair())
                 .setEndpoint(endpoint)
-//				.setIdentityProvider(new UsernameProvider("jellyleo", "123456"))
-                .setIdentityProvider(new AnonymousProvider()) // 匿名验证
+                //如果不是匿名则获取用户名和密码
+                .setIdentityProvider(serverInformation.getIsAnonymous() == ConstantStr.NOT_ANONYMOUS ? new UsernameProvider(serverInformation.getIpUserName(), serverInformation.getIpPassword()) : new AnonymousProvider())
                 .setRequestTimeout(Unsigned.uint(5000)).build();
 
         return OpcUaClient.create(config);
@@ -92,7 +98,7 @@ public class OpcServerUaUtil {
     }
 
     public static List<JSONObject> generOpcUaTree(OpcUaClient client, UaNode uaNode) throws UaException, ExecutionException, InterruptedException {
-        if(Blank.isEmpty(client)){
+        if (Blank.isEmpty(client)) {
             return null;
         }
         List<JSONObject> jsonList = new ArrayList<>();
@@ -103,7 +109,7 @@ public class OpcServerUaUtil {
             nodes = client.getAddressSpace().browseNodes(uaNode);
         }
         for (UaNode nd : nodes) {
-            if(Blank.isEmpty(nd)){
+            if (Blank.isEmpty(nd)) {
                 continue;
             }
             //排除系统行性节点,这些系统性节点名称一般都是以"_"开头
@@ -119,7 +125,7 @@ public class OpcServerUaUtil {
         return jsonList;
     }
 
-//    private  void browseNode(OpcUaClient client, UaNode uaNode) throws Exception {
+    //    private  void browseNode(OpcUaClient client, UaNode uaNode) throws Exception {
 //        List<? extends UaNode> nodes;
 //        if (uaNode == null) {
 //			nodes = client.getAddressSpace().browseNodes(Identifiers.ObjectsFolder);//从根目录
@@ -147,5 +153,23 @@ public class OpcServerUaUtil {
 //        }
 //        System.err.println();
 //    }
+    public static Result opcTestConnect(ServerInformation serverInformation) throws Exception {
+        OpcUaClient opcUaClient = createClient(serverInformation);
+        try {
+            long start = System.currentTimeMillis();
+            opcUaClient.connect();
+            long finish = System.currentTimeMillis();
+            log.info("连接耗费时间为:" + (finish - start) + "毫秒");
+//            if (null == server.getServerState()) {
+//                return Result.no(ResultEnum.NOT_FOUND.getRespCode(), "连接失败");
+//            }
+//            if (OPCSERVERSTATE.OPC_STATUS_RUNNING == server.getServerState().getServerState()) {
+//                return Result.ok(true);
+//            }
+        } finally {
+            opcUaClient.disconnect();
+        }
+        return Result.no(ResultEnum.SERVER_ERROR.getRespCode(), ResultEnum.SERVER_ERROR.getRespMsg());
+    }
 
 }

+ 0 - 16
chuanyi_server/src/main/java/com/judong/chuanyiserver/util/Test.java

@@ -28,21 +28,5 @@ public class Test {
 //        System.out.println(jsonObjectList.toString());
     }
 
-    public static OpcUaClient test() throws Exception {
-        OpcUaClient client = OpcServerUaUtil.createClient();
-        OpcServerUaUtil.getFuture().whenCompleteAsync((c, ex) -> {
-            if (ex != null) {
-                throw new CustomException(500, ex.getMessage());
-            }
-            try {
-                c.disconnect().get();
-                Stack.releaseSharedResources();
-            } catch (InterruptedException | ExecutionException e) {
-                throw new CustomException(500, e.getMessage());
-            }
-        });
-        return client;
-    }
-
 
 }

+ 53 - 8
chuanyi_server/src/main/resources/mapper/ConnectDao.xml

@@ -3,15 +3,21 @@
 <mapper namespace="com.judong.chuanyiserver.dao.ConnectDao">
 
     <insert id="saveConnect">
-        insert into sys_server_information(user_id, ip_address, ip_user_name, ip_password, agreement_type, create_time)
-            value (#{userId}, #{ipAddress}, #{ipUserName}, #{ipPassword}, #{agreementType}, now())
+        insert into sys_server_information(user_id, connect_name, connect_mode, ip_address, ip_port, ip_user_name,
+                                           ip_password, agreement_type, is_anonymous, create_time)
+            value (#{userId}, #{connectName}, #{connectMode}, #{ipAddress}, #{ipPort}, #{ipUserName}, #{ipPassword},
+                   #{agreementType}, #{isAnonymous}, now())
     </insert>
     <update id="editConnect">
         update sys_server_information
-        set ip_address=#{ipAddress},
+        set connect_name=#{connectName},
+            connect_mode=#{connectMode},
+            ip_address=#{ipAddress},
+            ip_port=#{ipPort},
             ip_user_name=#{ipUserName},
             ip_password=#{ipPassword},
-            agreement_type=#{agreementType}
+            agreement_type=#{agreementType},
+            is_anonymous=#{isAnonymous}
         where id = #{id}
     </update>
     <delete id="deleteConnect">
@@ -21,24 +27,63 @@
           and user_id = #{userId}
     </delete>
     <select id="getServerInformation" resultType="com.judong.chuanyiserver.entity.ServerInformation">
-        select id, user_id, ip_address, ip_user_name, ip_password, agreement_type, create_time
+        select id,
+               user_id,
+               connect_name,
+               connect_mode,
+               ip_address,
+               ip_port,
+               ip_user_name,
+               ip_password,
+               agreement_type,
+               is_anonymous,
+               create_time
         from sys_server_information
         where user_id = #{userId}
           and ip_address = #{ipAddress}
     </select>
     <select id="getServerInformationById" resultType="com.judong.chuanyiserver.entity.ServerInformation">
-        select id, user_id, ip_address, ip_user_name, ip_password, agreement_type, create_time
+        select id,
+               user_id,
+               connect_name,
+               connect_mode,
+               ip_address,
+               ip_port,
+               ip_user_name,
+               ip_password,
+               agreement_type,
+               is_anonymous,
+               create_time
         from sys_server_information
         where id = #{id}
     </select>
     <select id="selectAllConnect" resultType="com.judong.chuanyiserver.entity.ServerInformation">
-        select id, ip_address, agreement_type, create_time
+        select id,
+               user_id,
+               connect_name,
+               connect_mode,
+               ip_address,
+               ip_port,
+               ip_user_name,
+               agreement_type,
+               is_anonymous,
+               create_time
         from sys_server_information
         where user_id = #{userId}
         order by create_time desc
     </select>
     <select id="getServerInformationEdit" resultType="com.judong.chuanyiserver.entity.ServerInformation">
-        select id, user_id, ip_address, ip_user_name, ip_password, agreement_type, create_time
+        select id,
+               user_id,
+               connect_name,
+               connect_mode,
+               ip_address,
+               ip_port,
+               ip_user_name,
+               ip_password,
+               agreement_type,
+               is_anonymous,
+               create_time
         from sys_server_information
         where user_id = #{userId}
           and ip_address = #{ipAddress}

+ 18 - 2
chuanyi_server/src/main/resources/mapper/DepartmentDao.xml

@@ -3,8 +3,9 @@
 <mapper namespace="com.judong.chuanyiserver.dao.DepartmentDao">
 
     <insert id="addDepartment">
-        insert into sys_department (parent_id, department_name, department_describe, department_num, create_time)
-            VALUE (#{parentId}, #{departmentName}, #{departmentDescribe}, #{departmentNum}, now())
+        insert into sys_department (parent_id, department_name, department_describe, department_num, create_time,
+                                    is_delete)
+            VALUE (#{parentId}, #{departmentName}, #{departmentDescribe}, #{departmentNum}, now(), #{isDelete})
     </insert>
     <update id="updateDepartment">
         update sys_department
@@ -32,11 +33,26 @@
     <select id="getDepartmentCount" resultType="java.lang.Long">
         select count(*)
         from sys_department
+        where is_delete = #{noDelete}
+        <if test="departmentName != null">
+            AND department_name LIKE CONCAT('%', #{departmentName}, '%')
+        </if>
+        <if test="createTime != null">
+            AND create_time LIKE CONCAT('%', #{createTime}, '%')
+        </if>
     </select>
 
     <select id="getDepartmentListByPage" resultType="com.judong.chuanyiserver.entity.Department">
         select id, parent_id, department_name, department_describe, department_num, create_time, update_time
         from sys_department
+        where is_delete = #{noDelete}
+        <if test="departmentName != null">
+            AND department_name LIKE CONCAT('%', #{departmentName}, '%')
+        </if>
+        <if test="createTime != null">
+            AND create_time LIKE CONCAT('%', #{createTime}, '%')
+        </if>
+        order by create_time desc
         limit #{startNum},#{limitNum}
     </select>
 

+ 1 - 0
chuanyi_server/src/main/resources/mapper/MenuDao.xml

@@ -120,6 +120,7 @@
         <if test="menuUrl != null">
             AND menu_url=#{menuStatus}
         </if>
+        order by create_time desc
         limit #{startNum},#{limitNum}
     </select>
     <select id="getMenuById" resultType="com.judong.chuanyiserver.entity.Menu">

+ 3 - 2
chuanyi_server/src/main/resources/mapper/RoleDao.xml

@@ -3,8 +3,8 @@
 <mapper namespace="com.judong.chuanyiserver.dao.RoleDao">
 
     <insert id="addRole">
-        INSERT INTO sys_role (role_name, role_code)
-            VALUE (#{roleName}, #{roleCode})
+        INSERT INTO sys_role (role_name, role_code, is_delete)
+            VALUE (#{roleName}, #{roleCode}, #{isDelete})
     </insert>
 
     <insert id="addRoleMenuList">
@@ -84,6 +84,7 @@
         select id, role_name
         from sys_role
         where id = #{id}
+          and is_delete = #{noDelete}
     </select>
 
     <select id="getMenuListByroleList" resultType="com.judong.chuanyiserver.entity.Menu">

+ 53 - 0
chuanyi_server/src/main/resources/mapper/UserDao.xml

@@ -57,6 +57,13 @@
         </foreach>
     </insert>
 
+    <insert id="assignUserListByRoleId">
+        insert into sys_user_role (user_id, role_id) VALUES
+        <foreach collection="userIdList" item="userId" index="index" separator=",">
+            (#{userId},#{roleId})
+        </foreach>
+    </insert>
+
     <select id="getShareRoleList" resultType="com.judong.chuanyiserver.entity.Role">
         select sr.id, sr.role_name, sr.role_code
         from sys_role sr inner join
@@ -79,6 +86,13 @@
         where user_id = #{userId}
     </delete>
 
+    <delete id="deleteByUserIdRoleId">
+        delete
+        from sys_user_role
+        where user_id = #{userId}
+          and role_id = #{roleId}
+    </delete>
+
     <select id="getRoleListByUserId" resultType="com.judong.chuanyiserver.entity.Role">
         select sr.id, sr.role_name, sr.role_code
         from sys_role sr
@@ -132,6 +146,45 @@
           and user_name = #{userName}
     </select>
 
+    <select id="getUserListByRoleIdCount" resultType="java.lang.Long">
+        select count(*)
+        from sys_user su
+        inner join sys_user_role sur
+        inner join sys_role sr on sur.role_id = sr.id and su.user_id = sur.user_id
+        where sr.is_delete = #{noDelete}
+        and su.state != #{tombstoneUser}
+        and sr.id=#{roleId}
+        <if test="userName != null">
+            AND su.user_name LIKE CONCAT('%', #{userName}, '%')
+        </if>
+    </select>
+
+    <select id="getUserListByRoleId" resultType="com.judong.chuanyiserver.entity.User">
+        select su.user_id,
+        su.user_name,
+        su.create_time,
+        su.update_time,
+        su.last_login_time,
+        su.state,
+        su.user_type
+        from sys_user su
+        inner join sys_user_role sur
+        inner join sys_role sr on sur.role_id = sr.id and su.user_id = sur.user_id
+        where sr.is_delete = #{noDelete}
+        and su.state != #{tombstoneUser}
+        and sr.id=#{roleId}
+        <if test="userName != null">
+            AND su.user_name LIKE CONCAT('%', #{userName}, '%')
+        </if>
+    </select>
+
+    <select id="getAssignUserIdList" resultType="java.lang.String">
+        select user_id from sys_user_role where role_id=#{roleId} and user_id in (
+        <foreach collection="userIdList" item="userId" index="index" separator=",">
+            #{userId}
+        </foreach>)
+    </select>
+
     <update id="updateUserState">
         update sys_user
         set state=#{userState}