Merge remote-tracking branch 'origin/main'

This commit is contained in:
wangyilin 2024-09-05 10:42:21 +08:00
commit 23e90cd5d9
47 changed files with 879 additions and 210 deletions

View File

@ -24,30 +24,25 @@
</a-menu> -->
<!-- 动态生成菜单项 -->
<a-menu v-model:selectedKeys="selectedKeys" theme="light" mode="inline">
<template v-for="route in menuRoutes">
<!-- -->
<a-menu-item v-if="route.name === 'dashboard'">
<template v-for="route in staticRouter">
<a-menu-item v-if="route.meta?.title === undefined && route.children">
<router-link :to="`${route.children[0].path}`">
<pie-chart-outlined />
<span>{{ route.meta?.title }}</span>
<HomeOutlined v-if="route.name === 'dashboard'" />
<InsuranceOutlined v-if="route.name === 'police'" />
<SoundOutlined v-if="route.name === 'law'" />
<ApartmentOutlined v-if="route.name === 'warning'" />
<span>{{ route?.children[0]?.meta?.title }}</span>
</router-link>
</a-menu-item>
<a-sub-menu v-if="route.children && route.children.length && route?.name !== 'dashboard'" :key="route.path">
<a-sub-menu v-if="route.children && route.children.length && route?.meta?.title" :key="route.path">
<template #title>
<pie-chart-outlined />
<MailOutlined />
<span>{{ route.meta?.title }}</span>
</template>
<a-menu-item v-for="child in route.children" :key="child.path">
<router-link :to="`${route.path}${child.path}`">{{ child.meta?.title }}</router-link>
<router-link :to="`${route.path}/${child.path}`">{{ child.meta?.title }}</router-link>
</a-menu-item>
</a-sub-menu>
<!-- -->
<a-menu-item v-if="!route.children">
<router-link :to="route.path">
<pie-chart-outlined />
<span>{{ route.meta?.title }}</span>
</router-link>
</a-menu-item>
</template>
</a-menu>
</a-layout-sider>
@ -56,10 +51,14 @@
<layout-header v-model:collapsed="collapsed" />
</a-layout-header>
<a-layout-content class="layout-content">
<router-view v-slot="{ Component, route }">
<!-- <keep-alive> 会缓存已经访问过的组件当你再次访问同一个页面时它会直接从缓存中加载而不会触发重新渲染 -->
<!-- router-view 必须绑定一个key 否则就会出现 路由切换白屏的问题路由切换后页面不显示内容刷新后正常显示但是这样也会导致一个问题就是 会导致keep-alive失效因为这种方式会强制刷新路由-->
<router-view v-slot="{ Component, route }" :key="route.path">
<!-- <router-view v-slot="{ Component, route }"> -->
<transition appear name="fade-transform" mode="out-in">
<keep-alive :include="keepAliveNames">
<component :is="Component" :key="route.fullPath" />
<component :is="Component" :key="route.path" />
</keep-alive>
</transition>
</router-view>
@ -69,9 +68,9 @@
</template>
<script setup lang="ts">
import { InsuranceOutlined, HomeOutlined, SoundOutlined, MailOutlined, ApartmentOutlined, InboxOutlined, AppstoreOutlined } from '@ant-design/icons-vue'
import LayoutHeader from '@/components/layout/header/LayoutHeader.vue'
import { computed } from 'vue'
// import Sliber from '@/components/layout/sliber/sliber.vue'
import { staticRouter } from '@/router/staticRouters'
import { useRoute } from 'vue-router'
const route = useRoute()
@ -81,7 +80,10 @@ const route = useRoute()
const selectedKeys = computed(() => [route.path])
//
const menuRoutes = computed(() => staticRouter.filter((route) => route.meta && route.meta.title))
// const menuRoutes = computed(() => staticRouter.filter((route) => route.meta && route.meta.title))
// staticRouter.forEach((element) => {
// console.log(element.meta?.title)
// })
//
// const keepAliveNames = ref(['index'])
@ -90,7 +92,8 @@ import { ref } from 'vue'
//
const collapsed = ref<boolean>(false)
const keepAliveNames = ref<string[]>([])
// const keepAliveNames = ref<string[]>(['Index', 'Register'])
const keepAliveNames = ref<string[]>(['index', 'rindex'])
</script>
<style scoped lang="scss">

View File

@ -15,7 +15,7 @@
<script lang="ts" setup>
import { ref } from 'vue'
import { FormInstance, message, notification } from 'ant-design-vue'
import { FormInstance, notification } from 'ant-design-vue'
import { Rule } from 'ant-design-vue/es/form'
import { LoginParams } from '@/types/views/login.ts'
import api from '@/axios'
@ -24,7 +24,10 @@ import rsaUtil from '@/utils/rsaUtil.ts'
import { TokenInfo } from '@/types/stores/userStore.ts'
import { useUserStore } from '@/stores/modules/userStore.ts'
import { useRouter } from 'vue-router'
const props = defineProps<{
account: string
password: string
}>()
const userStore = useUserStore()
const router = useRouter()
@ -47,9 +50,11 @@ const loginParamsRule: Record<keyof LoginParams, Rule[]> = {
],
}
const loginParams = ref<LoginParams>({
accountOrTelephone: __APP_ENV.VITE_APP_ENV === 'development' ? 'ERwuf2' : '',
password: __APP_ENV.VITE_APP_ENV === 'development' ? '123456' : '',
accountOrTelephone: __APP_ENV.VITE_APP_ENV === 'development' ? '' : '',
password: __APP_ENV.VITE_APP_ENV === 'development' ? '' : '',
})
loginParams.value.accountOrTelephone = props.account
loginParams.value.password = props.password
/**
* 登录

View File

@ -8,3 +8,15 @@ interface JsonResult<T> {
message: string;
data?: T;
}
interface dataStatus {
account: string;
password: string;
remark: string;
checkStatus: {
extData: {
color: string;
};
label: string;
value: number;
};
}

View File

@ -27,22 +27,19 @@ router.beforeEach(async (to, from, next) => {
return next(from.fullPath)
}
//判断访问路径是不是白名单d
console.log('访问路径', to.path);
// console.log('访问路径', to.path);
if (ROUTER_WHITE_LIST.includes(to.path)) {
return next();
} else {
//不在白名单内需要查看是否携带token 没有token需要返回登录页进行登录
if (!userStore.getTokenInfo?.value) {
await message.warn('未找到token请重新登陆!')
return next('/login');
}
}
//不在白名单内需要查看是否携带token 没有token需要返回登录页进行登录
// if (!userStore.getTokenInfo?.value) {
// await message.warn('未找到token请重新登陆!')
// return next('/login');
// }
//放行
return next();
})

View File

@ -5,19 +5,10 @@ export const Layout = () => import("@/components/layout/layout.vue");
export const staticRouter: RouteRecordRaw[] =
[
{
path: "/",
name: "/",
component: Layout,
redirect: "/dashboard",
children: []
},
{
path: '',
path: '/',
name: 'dashboard',
redirect: '/index',
meta: {
title: '首页',
keepalive: true
},
component: Layout,
@ -39,45 +30,111 @@ export const staticRouter: RouteRecordRaw[] =
{
path: '',
name: 'register',
path: '/query-',
name: 'query-',
meta: {
title: '注册',
title: '信息查询',
keepalive: true
},
component: Layout,
children: [
{
path: '/register', // 这里使用相对路径而不是 '/register'
name: '',
path: 'public-unit', // 这里使用相对路径而不是 '/register'
name: 'public-unit',
meta: {
title: '注册',
title: '企事业单位',
keepalive: true
},
component: () => import('@/views/register.vue')
component: () => import('@/views/query/publicUnit.vue')
},
{
path: 'weapp-user', // 这里使用相对路径而不是 '/register'
name: 'weapp-user',
meta: {
title: '微信小程序用户',
keepalive: true
},
component: () => import('@/views/query/weappUser.vue')
},
]
},
{
//登录页面
path: '/login',
name: 'login',
meta: {
// title: '登录',
// keepalive: true
keepalive: true
},
component: () => import('@/views/login.vue')
},
{
//登录页面
path: '/register-index',
name: 'register-index',
meta: {
// title: '注册',
},
component: () => import('@/views/register.vue')
},
{
path: '/law',
name: 'law',
meta: {
},
component: Layout,
children: [
{
path: '/law-index',
name: 'law-index',
meta: {
title: '法制宣传',
keepalive: true
},
component: () => import('@/views/law/index.vue')
},
]
},
{
path: '/police',
name: 'police',
meta: {
},
component: Layout,
children: [
{
path: '/police-presence',
name: 'police-presence',
meta: {
title: '警保风采',
keepalive: true
},
component: () => import('@/views/police/index.vue')
},
]
},
{
path: '/warning',
name: 'warning',
meta: {
},
component: Layout,
children: [
{
path: '/early-warning',
name: 'early-warning',
meta: {
title: '三色预警',
keepalive: true
},
component: () => import('@/views/warning/index.vue')
},
]
},
]

View File

@ -1,5 +1,5 @@
import {defineStore} from "pinia";
import {TokenInfo, UserStore} from "@/types/stores/userStore.ts";
import { defineStore } from "pinia";
import { TokenInfo, UserStore } from "@/types/stores/userStore.ts";
export const useUserStore = defineStore({
id: 'useUserStore',
@ -19,6 +19,10 @@ export const useUserStore = defineStore({
getters: {
getTokenInfo: (state): TokenInfo => state.tokenInfo as TokenInfo,
},
// persist 是 Pinia 的一个插件 pinia-plugin-persistedstate 提供的功能
// 用来让状态数据在页面刷新或重新加载时保存在浏览器的存储中
// 通过这个插件,你可以让 Pinia store 的状态持久化,即即使页面刷新,数据也不会丢失
persist: {
key: "useUserStore",
storage: window.localStorage,

View File

@ -1,6 +1,10 @@
<template><div>111111</div></template>
<script setup lang="ts"></script>
<script setup lang="ts">
defineOptions({
name: 'Index',
})
</script>
<style scoped lang="scss"></style>
<!-- <template>

View File

@ -0,0 +1,9 @@
<template>
<div>
<!-- 法制宣传 -->
法制宣传
</div>
</template>
<script setup lang="ts"></script>

View File

@ -10,7 +10,7 @@
<div class="title">欢迎来到超级后台</div>
<a-tabs class="account-tab" v-model:active-key="activeKey">
<a-tab-pane :key="0" tab="账号登录">
<TelephoneLogin />
<TelephoneLogin :account="account" :password="password" />
</a-tab-pane>
</a-tabs>
<div class="oauth">
@ -38,8 +38,15 @@
import { QqOutlined, WechatOutlined } from '@ant-design/icons-vue'
import TelephoneLogin from '@/components/login/TelephoneLogin.vue'
import { ref } from 'vue'
import { useRoute } from 'vue-router'
const route = useRoute()
const account = ref<string>('')
const password = ref<string>('')
const activeKey = ref(0)
account.value = route.query.account as string
password.value = route.query.password as string
// console.log('Account:', account.value)
// console.log('Password:', password.value)
</script>
<style lang="scss" scoped>

View File

@ -0,0 +1,8 @@
<template>
<div>
<!-- 警保风采 -->
警保风采
</div>
</template>
<script setup lang="ts"></script>

View File

@ -0,0 +1,8 @@
<template>
<div>
<!-- 企事业单位 -->
企事业单位
</div>
</template>
<script setup lang="ts"></script>

View File

@ -0,0 +1,8 @@
<template>
<div>
<!-- 微信小程序用户 -->
微信小程序用户
</div>
</template>
<script setup lang="ts"></script>

View File

@ -32,21 +32,21 @@
</a-form-item>
</div>
<!-- 用户根据单位代码去查询 审核状态 -->
<a-form-item has-feedback label="单位代码" name="code">
<a-form-item has-feedback label="单位机构代码" name="code">
<a-input v-model:value="formState.code" autocomplete="off" />
</a-form-item>
<a-form-item has-feedback label="单位名称" name="name">
<a-form-item has-feedback label="单位机构名称" name="name">
<a-input v-model:value="formState.name" autocomplete="off" />
</a-form-item>
<a-form-item has-feedback label="详细地址" name="address">
<a-input v-model:value="formState.address" autocomplete="off" />
</a-form-item>
<a-form-item has-feedback label="联系人姓名" name="contactPersonInfo">
<a-input v-model:value="formState.contactPersonInfo.name" autocomplete="off" />
<a-form-item has-feedback label="联系人姓名" name="contactName">
<a-input v-model:value="formState.contactName" autocomplete="off" />
</a-form-item>
<a-form-item has-feedback label="联系人电话" name="contactPersonInfo">
<a-input v-model:value="formState.contactPersonInfo.telephone" autocomplete="off" />
<a-form-item has-feedback label="联系人电话" name="telephone">
<a-input v-model:value="formState.telephone" autocomplete="off" />
</a-form-item>
<!-- -->
@ -60,13 +60,14 @@
</a-tab-pane>
<a-tab-pane key="2" tab="查询注册结果">
<div class="flex items-center justify-center flex-col" style="max-height: 500px; overflow-y: auto">
<a-card v-if="isLogin" class="mb-8" style="width: 300px">
<div>账户{{ account }}</div>
<div>密码{{ password }}</div>
</a-card>
<a-input v-if="isHasAccount" class="w-40 mb-8" v-model:value="searchCode.code" autocomplete="off" placeholder="请输入单位代码查询" />
<a-button v-if="isHasAccount" size="large" type="primary" :loading="loading" @click="getCheckStatus"> 查询审核状态 </a-button>
<a-button v-if="isLogin" size="large" type="primary" @click="toLogin"> 去登录 </a-button>
<a-form :label-col="labelCol" :wrapper-col="wrapperCol" :model="statusDate" layout="horizontal">
<a-form-item label="单位机构代码" name="onlyCode" :rules="[{ required: true, message: '请输入单位代码进行查询' }]">
<a-input placeholder="请输入单位代码查询" :allowClear="true" v-model:value="statusDate.onlyCode"></a-input>
</a-form-item>
<a-form-item :wrapper-col="{ offset: 8, span: 16 }">
<a-button type="primary" html-type="submit" style="width: 100px" @click="getCheckStatus">确认</a-button>
</a-form-item>
</a-form>
</div>
</a-tab-pane>
</a-tabs>
@ -78,21 +79,25 @@
<script setup lang="ts">
import { useRouter } from 'vue-router'
const router = useRouter()
import { message } from 'ant-design-vue'
// import type { CascaderProps } from 'ant-design-vue';
import { ExclamationCircleOutlined } from '@ant-design/icons-vue'
import { message, Modal } from 'ant-design-vue'
import api from '@/axios/index.ts'
import type { ShowSearchType } from 'ant-design-vue/es/cascader'
import { onMounted, reactive, ref } from 'vue'
import { onMounted, reactive, ref, defineComponent, createVNode, h } from 'vue'
defineComponent({
name: 'Register',
})
onMounted(() => {
getTree()
})
const labelCol = { style: { width: '120px' } }
const wrapperCol = { span: 14 }
const filter: ShowSearchType['filter'] = (inputValue, path) => {
return path.some((option) => option.title.toLowerCase().indexOf(inputValue.toLowerCase()) > -1)
}
const value = ref<string[]>([])
const options = ref<any[]>([])
const cascaderChange = (value: any, selectedOptions: any): void => {
const cascaderChange = (value: any): void => {
formState.administrativeDivisionCodes = [...value]
}
@ -151,7 +156,6 @@ const loadTreeFromCache = async (): Promise<any | null> => {
const request = store.get('treeData')
request.onsuccess = () => {
// console.log('🚀 ~ loadTreeFromCache ~ request.result:', request.result)
if (request.result !== undefined) {
resolve(request.result) //
} else {
@ -169,7 +173,6 @@ const loadTreeFromCache = async (): Promise<any | null> => {
const getTree = async () => {
//
const cachedData = await loadTreeFromCache()
// console.log('🚀 ~ getTree ~ cachedData:', cachedData)
if (cachedData) {
console.log('未发请求')
// 使
@ -190,66 +193,83 @@ interface FormState {
name: string
code: number | string
administrativeDivisionCodes: any[]
address: string
contactPersonInfo: ContactPersonInfo
telephone: string //
contactName: string //
}
const formRef = ref<FormInstance>()
interface ContactPersonInfo {
telephone: string
name: string
}
const formState = reactive<FormState>({
name: '',
code: '',
administrativeDivisionCodes: [],
// province: '',
// city: '',
// districts: '',
// street: '',
address: '',
contactPersonInfo: {
telephone: '',
name: '',
},
telephone: '',
contactName: '',
})
const checkIsNull = async (_rule: Rule, value: string) => {
const checkName = async (_rule: Rule, value: string) => {
if (value === '') {
return Promise.reject('请输入')
return Promise.reject('请输入单位机构名称')
} else {
return Promise.resolve()
}
}
const checkOBJ = async (_rule: Rule, value: ContactPersonInfo) => {
// console.log('🚀 ~ checkOBJ ~ value:', value)
if (value.telephone !== '' && value.name !== '') {
return Promise.resolve()
const checkCode = async (_rule: Rule, value: string) => {
if (value === '') {
return Promise.reject('请输入单位机构代码')
} else {
// return Promise.reject('')
// return Promise.reject('')
return Promise.resolve()
}
}
const checkAddress = async (_rule: Rule, value: string) => {
if (value === '') {
return Promise.reject('请输入详细地址')
} else {
return Promise.resolve()
}
}
const checkTelephone = async (_rule: Rule, value: string) => {
if (value === '') {
return Promise.reject('请输入联系人电话')
} else {
return Promise.resolve()
}
}
const checkContactName = async (_rule: Rule, value: string) => {
if (value === '') {
return Promise.reject('请输入联系人姓名')
} else {
return Promise.resolve()
}
}
// Rule
const rules: Record<string, Rule[]> = {
name: [{ required: true, validator: checkIsNull, trigger: 'change' }],
code: [{ required: true, validator: checkIsNull, trigger: 'change' }],
address: [{ required: true, validator: checkIsNull, trigger: 'change' }],
contactPersonInfo: [{ required: true, validator: checkOBJ, trigger: 'change' }],
name: [{ required: true, validator: checkName, trigger: 'change' }],
code: [{ required: true, validator: checkCode, trigger: 'change' }],
address: [{ required: true, validator: checkAddress, trigger: 'change' }],
telephone: [{ required: true, validator: checkTelephone, trigger: 'change' }],
contactName: [{ required: true, validator: checkContactName, trigger: 'change' }],
}
const layout = {
labelCol: { span: 4 },
wrapperCol: { span: 14 },
}
const register = (values: any) => {
const register = () => {
if (value.value.length === 0) {
message.error('请选择行政区划')
return
} else {
api.post<any>('/common/policeUnitRegister', { ...formState }).then((res) => {
const { telephone, contactName, ...rest } = formState
const contactPersonInfo = {
telephone,
name: contactName,
}
const submitForm = {
...rest,
contactPersonInfo,
}
api.post<any>('/common/policeUnitRegister', { ...submitForm }).then((res) => {
console.log(res)
if (res.code === 200) {
message.success('提交成功')
@ -259,14 +279,15 @@ const register = (values: any) => {
}
const handleFinish = (values: FormState) => {
console.log(values, formState)
register(values)
console.log('自定义校验成功')
console.log(values)
register()
}
const handleFinishFailed = (errors: any) => {
console.log(errors)
}
const resetForm = () => {
formRef.value.resetFields()
formRef.value?.resetFields()
value.value = []
}
const handleValidate = (...args: any[]) => {
@ -275,35 +296,55 @@ const handleValidate = (...args: any[]) => {
const activeKey = ref('1')
const loading = ref<boolean>(false)
const account = ref<string>('')
const password = ref<string>('')
const isHasAccount = ref<boolean>(true)
const isLogin = ref<boolean>(false)
// const searchCode = ref<string>()
//
const searchCode = reactive({
code: __APP_ENV.VITE_APP_ENV === 'development' ? 'dawda' : '',
})
const getCheckStatus = () => {
const getCheckStatus = async () => {
if (statusDate.onlyCode.trim() === '') {
return
}
loading.value = true
api
.post<any>('/management/getCheckStatus', { onlyCode: searchCode.code, unitOptType: 'POLICE_UNIT' })
.post<dataStatus>('/management/getCheckStatus', statusDate)
.then((res) => {
console.log('🚀 ~ api.post<any> ~ res:', res)
if (res.code === 200) {
loading.value = false
isHasAccount.value = false
isLogin.value = true
account.value = res.data.account
password.value = res.data.password
}
showConfirm(res.data as dataStatus)
})
.finally(() => {
loading.value = false
})
}
const toLogin = () => {
router.replace({ path: '/login' })
import { useUserStore } from '@/stores/modules/userStore.ts'
const showConfirm = (columnsDate: dataStatus) => {
if (columnsDate.checkStatus.value === 0) {
Modal.success({
title: `审核通过`,
icon: createVNode(ExclamationCircleOutlined),
content: h('div', {}, [h('div', `账号:${columnsDate.account}`), h('div', `密码:${columnsDate.password}`), h('div', `${columnsDate.remark}`)]),
okText: '跳转',
async onOk() {
await useUserStore().resetUserInfo()
await router
.replace({
path: '/login',
query: {
account: columnsDate.account,
password: columnsDate.password,
},
})
.then(() => {})
},
onCancel() {},
})
} else {
Modal.error({
title: `未审核`,
icon: createVNode(ExclamationCircleOutlined),
content: `${columnsDate.remark}`,
})
}
}
const statusDate = reactive({
// __APP_ENV.VITE_APP_ENV === 'development' ? 'dawda' : '',
onlyCode: '',
unitOptType: 'POLICE_UNIT',
})
</script>

View File

@ -0,0 +1,8 @@
<template>
<div>
<!-- 三色预警 -->
三色预警
</div>
</template>
<script setup lang="ts"></script>

View File

@ -147,6 +147,30 @@
<artifactId>sa-token-redis</artifactId>
<version>${sa.token.version}</version>
</dependency>
<!-- Sa-Token 整合 jwt -->
<dependency>
<groupId>cn.dev33</groupId>
<artifactId>sa-token-jwt</artifactId>
<version>${sa.token.version}</version>
<exclusions>
<exclusion>
<groupId>cn.hutool</groupId>
<artifactId>hutool-core</artifactId>
</exclusion>
<exclusion>
<groupId>cn.hutool</groupId>
<artifactId>hutool-crypto</artifactId>
</exclusion>
<exclusion>
<groupId>cn.hutool</groupId>
<artifactId>hutool-json</artifactId>
</exclusion>
<exclusion>
<groupId>cn.hutool</groupId>
<artifactId>hutool-jwt</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- mysql 驱动 注:最新版本的MySQL Connector/J已经迁移到了符合反转DNS规范的Maven坐标 因此您需要按照新的坐标来引用该依赖。根据错误消息中提供的信息将mysql:mysql-connector-java替换为com.mysql:mysql-connector-j版本保持不变。-->
<dependency>
<groupId>com.mysql</groupId>

View File

@ -0,0 +1,28 @@
package com.changhu.common.annotation;
import com.changhu.enums.ClientType;
import org.springframework.web.bind.annotation.RestController;
import java.lang.annotation.*;
/**
* @author 20252
* @createTime 2024/9/4 下午4:01
* @desc CheckClientType...
*/
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@RestController
public @interface CheckClientType {
/**
* 是否需要校验客户端类型
*/
boolean value() default true;
/**
* 需要的客户端类型
*/
ClientType clientType() default ClientType.NONE;
}

View File

@ -1,5 +1,6 @@
package com.changhu.common.utils;
import cn.dev33.satoken.stp.SaLoginConfig;
import cn.dev33.satoken.stp.SaTokenInfo;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.util.IdUtil;
@ -7,6 +8,7 @@ import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import com.changhu.common.enums.ResultCode;
import com.changhu.common.exception.MessageException;
import com.changhu.enums.ClientType;
import lombok.extern.slf4j.Slf4j;
import java.util.Optional;
@ -43,6 +45,29 @@ public class UserUtil {
return getTokenInfo();
}
public static SaTokenInfo loginAndTokenInfo(Long userId, ClientType clientType, Long unitId) {
StpUtil.login(userId, SaLoginConfig.setExtra("clientType", clientType).setExtra("unitId", unitId));
return getTokenInfo();
}
/**
* 获取客户端类型
*/
public static ClientType getClientType() {
Object clientType = StpUtil.getExtra("clientType");
if (clientType instanceof String ct) {
return ClientType.valueOf(ct);
}
return null;
}
/**
* 获取单位id
*/
public static Long getUnitId() {
return Long.parseLong(StpUtil.getExtra("unitId") + "");
}
/**
* 用户登出
*/

View File

@ -2,6 +2,7 @@ package com.changhu.config;
import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.stp.StpUtil;
import com.changhu.support.interceptor.ClientTypeInterceptor;
import com.changhu.support.interceptor.JsonBodyInterceptor;
import org.jetbrains.annotations.NotNull;
import org.springframework.context.annotation.Configuration;
@ -49,6 +50,8 @@ public class WebConfig implements WebMvcConfigurer {
.excludePathPatterns(whiteList);
// 注册jsonBody 拦截器 用于标识是否需要JsonResult返回
registry.addInterceptor(new JsonBodyInterceptor());
// 注册clientType 拦截器 用于校验当前用户是否匹配操作客户端
registry.addInterceptor(new ClientTypeInterceptor());
}
@Override

View File

@ -15,6 +15,7 @@ import lombok.Getter;
@Getter
@AllArgsConstructor
public enum ClientType {
NONE("未定义", null),
MANAGEMENT_SUPER("超级后台", ManagementSuperLogin.instance),
MANAGEMENT_POLICE("公安后台", ManagementPoliceUnitLogin.instance),
MANAGEMENT_SECURITY("保安后台", ManagementSecurityUnitLogin.instance),

View File

@ -1,8 +1,8 @@
package com.changhu.enums.handler;
import cn.dev33.satoken.stp.SaTokenInfo;
import cn.hutool.extra.spring.SpringUtil;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.extension.toolkit.Db;
import com.changhu.common.db.enums.IsEnable;
import com.changhu.common.enums.ResultCode;
import com.changhu.common.exception.MessageException;
@ -10,10 +10,9 @@ import com.changhu.common.pojo.vo.TokenInfo;
import com.changhu.common.utils.RsaUtil;
import com.changhu.common.utils.UserUtil;
import com.changhu.common.utils.ValidatorUtil;
import com.changhu.enums.ClientType;
import com.changhu.module.management.pojo.entity.ManagementPoliceUnitUser;
import com.changhu.module.management.pojo.entity.PoliceUnit;
import com.changhu.module.management.service.ManagementPoliceUnitUserService;
import com.changhu.module.management.service.PoliceUnitService;
import com.changhu.pojo.params.ManagementPoliceUnitLoginParams;
import com.changhu.support.mybatisplus.pojo.entity.BaseEntity;
@ -24,9 +23,6 @@ import com.changhu.support.mybatisplus.pojo.entity.BaseEntity;
*/
public class ManagementPoliceUnitLogin extends AbstractLoginHandler {
private final ManagementPoliceUnitUserService policeUnitUserService = SpringUtil.getBean(ManagementPoliceUnitUserService.class);
private final PoliceUnitService policeUnitService = SpringUtil.getBean(PoliceUnitService.class);
public static final ManagementPoliceUnitLogin instance = new ManagementPoliceUnitLogin();
private ManagementPoliceUnitLogin() {
@ -42,7 +38,7 @@ public class ManagementPoliceUnitLogin extends AbstractLoginHandler {
String password = RsaUtil.decrypt(managementPoliceUnitLoginParams.getPassword());
//查看 账号/手机号 是否存在
ManagementPoliceUnitUser managementPoliceUnitUser = policeUnitUserService.lambdaQuery()
ManagementPoliceUnitUser managementPoliceUnitUser = Db.lambdaQuery(ManagementPoliceUnitUser.class)
.eq(ManagementPoliceUnitUser::getAccount, accountOrTelephone)
.or()
.eq(ManagementPoliceUnitUser::getTelephone, accountOrTelephone)
@ -55,7 +51,7 @@ public class ManagementPoliceUnitLogin extends AbstractLoginHandler {
}
//判断单位是否禁用
IsEnable unitEnable = policeUnitService.lambdaQuery()
IsEnable unitEnable = Db.lambdaQuery(PoliceUnit.class)
.eq(BaseEntity::getSnowFlakeId, managementPoliceUnitUser.getPoliceUnitId())
.oneOpt()
.map(PoliceUnit::getIsEnable)
@ -71,7 +67,11 @@ public class ManagementPoliceUnitLogin extends AbstractLoginHandler {
}
//登录
SaTokenInfo saTokenInfo = UserUtil.loginAndTokenInfo(managementPoliceUnitUser.getSnowFlakeId());
SaTokenInfo saTokenInfo = UserUtil.loginAndTokenInfo(
managementPoliceUnitUser.getSnowFlakeId(),
ClientType.MANAGEMENT_POLICE,
managementPoliceUnitUser.getPoliceUnitId()
);
//返回token
return new TokenInfo(saTokenInfo.getTokenName(), saTokenInfo.getTokenValue());
}

View File

@ -1,8 +1,8 @@
package com.changhu.enums.handler;
import cn.dev33.satoken.stp.SaTokenInfo;
import cn.hutool.extra.spring.SpringUtil;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.extension.toolkit.Db;
import com.changhu.common.db.enums.IsEnable;
import com.changhu.common.enums.ResultCode;
import com.changhu.common.exception.MessageException;
@ -10,11 +10,9 @@ import com.changhu.common.pojo.vo.TokenInfo;
import com.changhu.common.utils.RsaUtil;
import com.changhu.common.utils.UserUtil;
import com.changhu.common.utils.ValidatorUtil;
import com.changhu.enums.ClientType;
import com.changhu.module.management.pojo.entity.ManagementSecurityUnitUser;
import com.changhu.module.management.pojo.entity.PoliceUnit;
import com.changhu.module.management.pojo.entity.SecurityUnit;
import com.changhu.module.management.service.ManagementSecurityUnitUserService;
import com.changhu.module.management.service.SecurityUnitService;
import com.changhu.pojo.params.ManagementSecurityUnitLoginParams;
import com.changhu.support.mybatisplus.pojo.entity.BaseEntity;
@ -25,9 +23,6 @@ import com.changhu.support.mybatisplus.pojo.entity.BaseEntity;
*/
public class ManagementSecurityUnitLogin extends AbstractLoginHandler {
private final ManagementSecurityUnitUserService securityUnitUserService = SpringUtil.getBean(ManagementSecurityUnitUserService.class);
private final SecurityUnitService securityUnitService = SpringUtil.getBean(SecurityUnitService.class);
public static final ManagementSecurityUnitLogin instance = new ManagementSecurityUnitLogin();
private ManagementSecurityUnitLogin() {
@ -42,7 +37,7 @@ public class ManagementSecurityUnitLogin extends AbstractLoginHandler {
String password = RsaUtil.decrypt(loginParams.getPassword());
//查看 账号/手机号 是否存在
ManagementSecurityUnitUser managementSecurityUnitUser = securityUnitUserService.lambdaQuery()
ManagementSecurityUnitUser managementSecurityUnitUser = Db.lambdaQuery(ManagementSecurityUnitUser.class)
.eq(ManagementSecurityUnitUser::getAccount, accountOrTelephone)
.or()
.eq(ManagementSecurityUnitUser::getTelephone, accountOrTelephone)
@ -55,7 +50,7 @@ public class ManagementSecurityUnitLogin extends AbstractLoginHandler {
}
//判断单位是否禁用
IsEnable unitEnable = securityUnitService.lambdaQuery()
IsEnable unitEnable = Db.lambdaQuery(SecurityUnit.class)
.eq(BaseEntity::getSnowFlakeId, managementSecurityUnitUser.getSecurityUnitId())
.oneOpt()
.map(SecurityUnit::getIsEnable)
@ -70,7 +65,11 @@ public class ManagementSecurityUnitLogin extends AbstractLoginHandler {
}
//登录
SaTokenInfo saTokenInfo = UserUtil.loginAndTokenInfo(managementSecurityUnitUser.getSnowFlakeId());
SaTokenInfo saTokenInfo = UserUtil.loginAndTokenInfo(
managementSecurityUnitUser.getSnowFlakeId(),
ClientType.MANAGEMENT_SECURITY,
managementSecurityUnitUser.getSecurityUnitId()
);
//返回token
return new TokenInfo(saTokenInfo.getTokenName(), saTokenInfo.getTokenValue());
}

View File

@ -1,16 +1,16 @@
package com.changhu.enums.handler;
import cn.dev33.satoken.stp.SaTokenInfo;
import cn.hutool.extra.spring.SpringUtil;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.extension.toolkit.Db;
import com.changhu.common.enums.ResultCode;
import com.changhu.common.exception.MessageException;
import com.changhu.common.pojo.vo.TokenInfo;
import com.changhu.common.utils.RsaUtil;
import com.changhu.common.utils.UserUtil;
import com.changhu.common.utils.ValidatorUtil;
import com.changhu.enums.ClientType;
import com.changhu.module.management.pojo.entity.ManagementSuperUser;
import com.changhu.module.management.service.ManagementSuperUserService;
import com.changhu.pojo.params.ManagementSuperLoginParams;
/**
@ -20,8 +20,6 @@ import com.changhu.pojo.params.ManagementSuperLoginParams;
*/
public class ManagementSuperLogin extends AbstractLoginHandler {
private static final ManagementSuperUserService managementSuperUserService = SpringUtil.getBean(ManagementSuperUserService.class);
public static final ManagementSuperLogin instance = new ManagementSuperLogin();
private ManagementSuperLogin() {
@ -35,7 +33,7 @@ public class ManagementSuperLogin extends AbstractLoginHandler {
String password = RsaUtil.decrypt(loginParams.getPassword());
//用户是否存在
ManagementSuperUser user = managementSuperUserService.lambdaQuery()
ManagementSuperUser user = Db.lambdaQuery(ManagementSuperUser.class)
.eq(ManagementSuperUser::getTelephone, telephone)
.oneOpt()
.orElseThrow(() -> new MessageException(ResultCode.USER_NOT_FOUND));
@ -45,7 +43,10 @@ public class ManagementSuperLogin extends AbstractLoginHandler {
throw new MessageException(ResultCode.PASSWORD_ERROR);
}
//登录
SaTokenInfo saTokenInfo = UserUtil.loginAndTokenInfo(user.getSnowFlakeId());
SaTokenInfo saTokenInfo = UserUtil.loginAndTokenInfo(
user.getSnowFlakeId(),
ClientType.MANAGEMENT_SUPER,
null);
//返回token
return new TokenInfo(saTokenInfo.getTokenName(), saTokenInfo.getTokenValue());
}

View File

@ -2,9 +2,7 @@ package com.changhu.module.management.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.changhu.common.annotation.JsonBody;
import com.changhu.common.pojo.vo.TreeNodeVo;
import com.changhu.common.utils.JavaClassToTsUtil;
import com.changhu.mapper.AdministrativeDivisionMapper;
import com.changhu.common.exception.MessageException;
import com.changhu.module.management.pojo.params.EnterprisesUnitSaveOrUpdateParams;
import com.changhu.module.management.pojo.queryParams.EnterprisesUnitPagerQueryParams;
import com.changhu.module.management.pojo.vo.EnterprisesUnitPagerVo;
@ -14,12 +12,11 @@ import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.List;
/**
* @author 20252
* @createTime 2024/9/3 上午10:17
@ -45,8 +42,13 @@ public class EnterprisesUnitController {
enterprisesUnitService.saveOrUpdate(params);
}
public static void main(String[] args) {
System.out.println(JavaClassToTsUtil.parse(EnterprisesUnitSaveOrUpdateParams.class));
@Operation(summary = "根据id删除")
@DeleteMapping("/deleteById")
public void deleteById(@RequestBody Long enterprisesUnitId) {
boolean b = enterprisesUnitService.removeById(enterprisesUnitId);
if (!b) {
throw new MessageException();
}
}
}

View File

@ -1,14 +1,54 @@
package com.changhu.module.management.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.changhu.common.annotation.CheckClientType;
import com.changhu.common.annotation.JsonBody;
import com.changhu.enums.ClientType;
import com.changhu.module.management.pojo.params.ManagementPoliceUserSaveOrUpdateParams;
import com.changhu.module.management.pojo.queryParams.ManagementPoliceUnitUserPagerQueryParams;
import com.changhu.module.management.pojo.vo.ManagementPoliceUnitUserPagerVo;
import com.changhu.module.management.service.ManagementPoliceUnitUserService;
import com.changhu.support.mybatisplus.pojo.params.PageParams;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
/**
* @author 20252
* @createTime 2024/9/3 上午10:21
* @desc ManagementPoliceUnitUserController...
*/
@Tag(name = "后台-公安用户")
@JsonBody
@CheckClientType(clientType = ClientType.MANAGEMENT_POLICE)
@RequestMapping("/managementPoliceUnitUser")
public class ManagementPoliceUnitUserController {
@Autowired
private ManagementPoliceUnitUserService managementPoliceUnitUserService;
@Operation(summary = "新增或保存")
@PostMapping("/saveOrUpdate")
public void saveOrUpdate(@RequestBody @Valid ManagementPoliceUserSaveOrUpdateParams params) {
managementPoliceUnitUserService.saveOrUpdate(params);
}
@Operation(summary = "分页查询")
@PostMapping("/pager")
public Page<ManagementPoliceUnitUserPagerVo> pager(@RequestBody PageParams<ManagementPoliceUnitUserPagerQueryParams, ManagementPoliceUnitUserPagerVo> queryParams) {
return managementPoliceUnitUserService.pager(queryParams);
}
@Operation(summary = "根据id删除")
@PostMapping("/deleteById")
public void deleteById(@RequestParam @Schema(description = "后台公安用户id") Long managementPoliceUnitUserId) {
managementPoliceUnitUserService.deleteById(managementPoliceUnitUserId);
}
}

View File

@ -1,19 +1,20 @@
package com.changhu.module.management.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.changhu.common.annotation.CheckClientType;
import com.changhu.common.annotation.JsonBody;
import com.changhu.enums.ClientType;
import com.changhu.module.management.pojo.params.ManagementSecurityUnitUserSaveOrUpdateParams;
import com.changhu.module.management.pojo.queryParams.ManagementSecurityUnitUserPagerQueryParams;
import com.changhu.module.management.pojo.vo.ManagementSecurityUnitUserPagerVo;
import com.changhu.module.management.service.ManagementSecurityUnitUserService;
import com.changhu.support.mybatisplus.pojo.params.PageParams;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.*;
/**
* @author 20252
@ -23,6 +24,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
@Tag(name = "后台-保安用户")
@JsonBody
@RequestMapping("/managementSecurityUnitUser")
@CheckClientType(clientType = ClientType.MANAGEMENT_SECURITY)
public class ManagementSecurityUnitUserController {
@Autowired
@ -39,4 +41,9 @@ public class ManagementSecurityUnitUserController {
public Page<ManagementSecurityUnitUserPagerVo> pager(@RequestBody PageParams<ManagementSecurityUnitUserPagerQueryParams, ManagementSecurityUnitUserPagerVo> queryParams) {
return managementSecurityUnitUserService.pager(queryParams);
}
@DeleteMapping("/deleteById")
public void deleteById(@RequestParam @Schema(description = "后台保安用户id") Long managementSecurityUnitUserId) {
managementSecurityUnitUserService.deleteById(managementSecurityUnitUserId);
}
}

View File

@ -12,7 +12,6 @@ import com.changhu.common.exception.MessageException;
import com.changhu.common.utils.UserUtil;
import com.changhu.module.management.pojo.entity.ManagementPoliceUnitUser;
import com.changhu.module.management.pojo.entity.PoliceUnit;
import com.changhu.module.management.pojo.entity.SecurityUnit;
import com.changhu.module.management.pojo.vo.UnitCheckStatusVo;
import com.changhu.module.management.service.ManagementPoliceUnitUserService;
import com.changhu.module.management.service.PoliceUnitService;

View File

@ -1,8 +1,14 @@
package com.changhu.module.management.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.changhu.module.management.pojo.entity.ManagementPoliceUnitUser;
import com.changhu.module.management.pojo.queryParams.ManagementPoliceUnitUserPagerQueryParams;
import com.changhu.module.management.pojo.vo.ManagementPoliceUnitUserPagerVo;
import com.changhu.support.mybatisplus.annotation.DataScope;
import com.changhu.support.mybatisplus.handler.permission.management.ManagementPoliceUnitUserPagerPermissionHandler;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/**
* management_police_user (后台-公安单位用户表) 固化类
@ -12,4 +18,14 @@ import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface ManagementPoliceUnitUserMapper extends BaseMapper<ManagementPoliceUnitUser> {
/**
* 分页查询
*
* @param page 分页参数
* @param params 查询参数
* @return 结果
*/
@DataScope(permissionHandler = ManagementPoliceUnitUserPagerPermissionHandler.class)
Page<ManagementPoliceUnitUserPagerVo> pager(@Param("page") Page<ManagementPoliceUnitUserPagerVo> page,
@Param("params") ManagementPoliceUnitUserPagerQueryParams params);
}

View File

@ -1,18 +1,18 @@
package com.changhu.module.management.pojo.entity;
import java.io.Serial;
import java.io.Serializable;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.handlers.Fastjson2TypeHandler;
import com.changhu.module.management.pojo.model.ContactPersonInfo;
import com.changhu.support.mybatisplus.pojo.entity.BaseEntity;
import lombok.Data;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import lombok.EqualsAndHashCode;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serial;
import java.io.Serializable;
/**

View File

@ -0,0 +1,39 @@
package com.changhu.module.management.pojo.params;
import com.changhu.common.db.enums.IsEnable;
import com.changhu.common.db.enums.Sex;
import com.changhu.common.validator.annotation.IsMobile;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
/**
* @author 20252
* @createTime 2024/9/4 下午3:04
* @desc ManagementPoliceUserSaveOrUpdateParams...
*/
@Data
public class ManagementPoliceUserSaveOrUpdateParams {
@Schema(description = "id")
private Long snowFlakeId;
@NotNull(message = "名称不能为空")
@Schema(description = "名称")
private String name;
@NotNull(message = "性别不能为空")
@Schema(description = "性别")
private Sex sex;
@IsMobile
@NotBlank(message = "手机号不能为空")
@Schema(description = "手机号")
private String telephone;
@NotNull(message = "是否启用不能为空")
@Schema(description = "是否启用")
private IsEnable isEnable;
}

View File

@ -3,15 +3,11 @@ package com.changhu.module.management.pojo.params;
import com.changhu.common.db.enums.IsEnable;
import com.changhu.common.db.enums.Sex;
import com.changhu.common.validator.annotation.IsMobile;
import com.changhu.module.management.pojo.model.ContactPersonInfo;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import java.util.List;
/**
* @author 20252
* @createTime 2024/9/3 上午10:26

View File

@ -0,0 +1,20 @@
package com.changhu.module.management.pojo.queryParams;
import com.changhu.common.db.enums.Sex;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
/**
* @author 20252
* @createTime 2024/9/4 下午3:22
* @desc ManagementPoliceUnitUserPagerQueryParams...
*/
@Data
public class ManagementPoliceUnitUserPagerQueryParams {
@Schema(description = "名字")
private String name;
@Schema(description = "手机号")
private String telephone;
@Schema(description = "性别")
private Sex sex;
}

View File

@ -0,0 +1,46 @@
package com.changhu.module.management.pojo.vo;
import com.changhu.common.db.enums.IsEnable;
import com.changhu.common.db.enums.IsOrNot;
import com.changhu.common.db.enums.Sex;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.time.LocalDateTime;
/**
* @author 20252
* @createTime 2024/9/3 上午10:59
* @desc ManagementSecurityUnitUserPagerVo...
*/
@Data
public class ManagementPoliceUnitUserPagerVo {
@Schema(description = "id")
private Long snowFlakeId;
@Schema(description = "名称")
private String name;
@Schema(description = "性别")
private Sex sex;
@Schema(description = "性别")
private String account;
@Schema(description = "手机号")
private String telephone;
@Schema(description = "是否启用")
private IsEnable isEnable;
@Schema(description = "是否是超管")
private IsOrNot isAdmin;
@Schema(description = "创建人")
private String createUserName;
@Schema(description = "创建时间")
private LocalDateTime createTime;
}

View File

@ -1,7 +1,12 @@
package com.changhu.module.management.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.changhu.module.management.pojo.entity.ManagementPoliceUnitUser;
import com.changhu.module.management.pojo.params.ManagementPoliceUserSaveOrUpdateParams;
import com.changhu.module.management.pojo.queryParams.ManagementPoliceUnitUserPagerQueryParams;
import com.changhu.module.management.pojo.vo.ManagementPoliceUnitUserPagerVo;
import com.changhu.support.mybatisplus.pojo.params.PageParams;
/**
* management_police_user (后台-公安单位用户表) 服务类
@ -10,4 +15,25 @@ import com.changhu.module.management.pojo.entity.ManagementPoliceUnitUser;
*/
public interface ManagementPoliceUnitUserService extends IService<ManagementPoliceUnitUser> {
/**
* 新增或者保持
*
* @param params 参数
*/
void saveOrUpdate(ManagementPoliceUserSaveOrUpdateParams params);
/**
* 分页查询
*
* @param queryParams 查询参数
* @return 结果
*/
Page<ManagementPoliceUnitUserPagerVo> pager(PageParams<ManagementPoliceUnitUserPagerQueryParams, ManagementPoliceUnitUserPagerVo> queryParams);
/**
* 根据id删除
*
* @param managementPoliceUnitUserId 后台公安用户id
*/
void deleteById(Long managementPoliceUnitUserId);
}

View File

@ -29,4 +29,11 @@ public interface ManagementSecurityUnitUserService extends IService<ManagementSe
* @return 分页结果
*/
Page<ManagementSecurityUnitUserPagerVo> pager(PageParams<ManagementSecurityUnitUserPagerQueryParams, ManagementSecurityUnitUserPagerVo> queryParams);
/**
* 根据id删除
*
* @param managementSecurityUnitUserId 后台保安用户id
*/
void deleteById(Long managementSecurityUnitUserId);
}

View File

@ -1,10 +1,26 @@
package com.changhu.module.management.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.changhu.common.enums.ResultCode;
import com.changhu.common.exception.MessageException;
import com.changhu.common.utils.UserUtil;
import com.changhu.enums.ClientType;
import com.changhu.module.management.mapper.ManagementPoliceUnitUserMapper;
import com.changhu.module.management.pojo.entity.ManagementPoliceUnitUser;
import com.changhu.module.management.pojo.params.ManagementPoliceUserSaveOrUpdateParams;
import com.changhu.module.management.pojo.queryParams.ManagementPoliceUnitUserPagerQueryParams;
import com.changhu.module.management.pojo.vo.ManagementPoliceUnitUserPagerVo;
import com.changhu.module.management.service.ManagementPoliceUnitUserService;
import com.changhu.support.mybatisplus.pojo.entity.BaseEntity;
import com.changhu.support.mybatisplus.pojo.params.PageParams;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
* management_police_user (后台-公安单位用户表) 服务实现类
@ -14,4 +30,57 @@ import org.springframework.stereotype.Service;
@Service
public class ManagementPoliceUnitUserServiceImpl extends ServiceImpl<ManagementPoliceUnitUserMapper, ManagementPoliceUnitUser> implements ManagementPoliceUnitUserService {
@Transactional(rollbackFor = Exception.class)
@Override
public void saveOrUpdate(ManagementPoliceUserSaveOrUpdateParams params) {
//查看手机号是否存在
boolean exists = this.lambdaQuery()
.eq(ManagementPoliceUnitUser::getTelephone, params.getTelephone())
.exists();
if (exists) {
throw new MessageException("该手机号已存在");
}
ManagementPoliceUnitUser managementPoliceUnitUser = BeanUtil.copyProperties(params, ManagementPoliceUnitUser.class);
//新增 补全信息
if (managementPoliceUnitUser.getSnowFlakeId() == null) {
String account = RandomUtil.randomString(6);
boolean accExits = this.lambdaQuery().eq(ManagementPoliceUnitUser::getAccount, account).exists();
if (accExits) {
throw new MessageException("生成的账号已存在 请重新提交生成");
}
//生成账号
managementPoliceUnitUser.setAccount(account);
//补全单位
managementPoliceUnitUser.setPoliceUnitId(UserUtil.getUnitId());
//生成密码
String passWordEncrypt = UserUtil.passWordEncrypt(UserUtil.DEFAULT_PASSWORD);
List<String> saltAndPassWord = StrUtil.split(passWordEncrypt, "$$");
managementPoliceUnitUser.setSalt(saltAndPassWord.get(0));
managementPoliceUnitUser.setPassword(saltAndPassWord.get(1));
}
this.saveOrUpdate(managementPoliceUnitUser);
}
@Override
public Page<ManagementPoliceUnitUserPagerVo> pager(PageParams<ManagementPoliceUnitUserPagerQueryParams, ManagementPoliceUnitUserPagerVo> queryParams) {
return baseMapper.pager(queryParams.getPage(), queryParams.getParams());
}
@Override
public void deleteById(Long managementPoliceUnitUserId) {
Long unitId = UserUtil.getUnitId();
Long l = this.lambdaQuery()
.eq(BaseEntity::getSnowFlakeId, managementPoliceUnitUserId)
.oneOpt()
.map(ManagementPoliceUnitUser::getPoliceUnitId)
.orElseThrow(() -> new MessageException(ResultCode.USER_NOT_FOUND));
if (!unitId.equals(l)) {
throw new MessageException("单位不匹配,无权操作");
}
boolean b = this.removeById(managementPoliceUnitUserId);
if (!b) {
throw new MessageException();
}
}
}

View File

@ -5,14 +5,18 @@ import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.changhu.common.enums.ResultCode;
import com.changhu.common.exception.MessageException;
import com.changhu.common.utils.UserUtil;
import com.changhu.enums.ClientType;
import com.changhu.module.management.mapper.ManagementSecurityUnitUserMapper;
import com.changhu.module.management.pojo.entity.ManagementPoliceUnitUser;
import com.changhu.module.management.pojo.entity.ManagementSecurityUnitUser;
import com.changhu.module.management.pojo.params.ManagementSecurityUnitUserSaveOrUpdateParams;
import com.changhu.module.management.pojo.queryParams.ManagementSecurityUnitUserPagerQueryParams;
import com.changhu.module.management.pojo.vo.ManagementSecurityUnitUserPagerVo;
import com.changhu.module.management.service.ManagementSecurityUnitUserService;
import com.changhu.support.mybatisplus.pojo.entity.BaseEntity;
import com.changhu.support.mybatisplus.pojo.params.PageParams;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -37,6 +41,7 @@ public class ManagementSecurityUnitUserServiceImpl extends ServiceImpl<Managemen
if (exists) {
throw new MessageException("该手机号已存在");
}
ManagementSecurityUnitUser managementSecurityUnitUser = BeanUtil.copyProperties(saveOrUpdateParams, ManagementSecurityUnitUser.class);
//新增 需要补全一些信息
if (managementSecurityUnitUser.getSnowFlakeId() == null) {
@ -49,6 +54,11 @@ public class ManagementSecurityUnitUserServiceImpl extends ServiceImpl<Managemen
}
//生成账号
managementSecurityUnitUser.setAccount(account);
if (!ClientType.MANAGEMENT_SECURITY.equals(UserUtil.getClientType())) {
throw new MessageException("客户端类型不对");
}
//补全单位
managementSecurityUnitUser.setSecurityUnitId(UserUtil.getUnitId());
//生成密码
String passWordEncrypt = UserUtil.passWordEncrypt(UserUtil.DEFAULT_PASSWORD);
List<String> saltAndPassWord = StrUtil.split(passWordEncrypt, "$$");
@ -62,4 +72,21 @@ public class ManagementSecurityUnitUserServiceImpl extends ServiceImpl<Managemen
public Page<ManagementSecurityUnitUserPagerVo> pager(PageParams<ManagementSecurityUnitUserPagerQueryParams, ManagementSecurityUnitUserPagerVo> queryParams) {
return baseMapper.pager(queryParams.getPage(), queryParams.getParams());
}
@Override
public void deleteById(Long managementSecurityUnitUserId) {
Long unitId = UserUtil.getUnitId();
Long l = this.lambdaQuery()
.eq(BaseEntity::getSnowFlakeId, managementSecurityUnitUserId)
.oneOpt()
.map(ManagementSecurityUnitUser::getSecurityUnitId)
.orElseThrow(() -> new MessageException(ResultCode.USER_NOT_FOUND));
if (!unitId.equals(l)) {
throw new MessageException("单位不匹配,无权操作");
}
boolean b = this.removeById(managementSecurityUnitUserId);
if (!b) {
throw new MessageException();
}
}
}

View File

@ -36,7 +36,7 @@ public class GlobalExceptionHandler {
@ExceptionHandler(Throwable.class)
public JsonResult<String> throwableHandler(Throwable throwable) {
String errorLabel = "系统错误:" + ExceptionUtil.getMessage(throwable);
log.error("系统错误:{}", ExceptionUtil.stacktraceToString(throwable));
log.error("系统错误:", throwable);
return JsonResult.custom(ResultCode.ERROR.getCode(), errorLabel);
}

View File

@ -0,0 +1,54 @@
package com.changhu.support.interceptor;
import com.changhu.common.annotation.CheckClientType;
import com.changhu.common.exception.MessageException;
import com.changhu.common.utils.UserUtil;
import com.changhu.enums.ClientType;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.jetbrains.annotations.NotNull;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;
/**
* @author 20252
* @createTime 2024/9/4 下午4:00
* @desc ClientTypeInterceptor...
*/
public class ClientTypeInterceptor implements HandlerInterceptor {
@Override
public boolean preHandle(@NotNull HttpServletRequest request,
@NotNull HttpServletResponse response,
@NotNull Object handler) {
if (handler instanceof HandlerMethod handlerMethod) {
boolean b = false;
ClientType ct = null;
CheckClientType clazzJsonBody = handlerMethod.getBeanType().getAnnotation(CheckClientType.class);
CheckClientType methodJsonBody = handlerMethod.getMethodAnnotation(CheckClientType.class);
if (clazzJsonBody != null) {
if (methodJsonBody == null) {
b = true;
ct = clazzJsonBody.clientType();
} else if (methodJsonBody.value()) {
b = true;
ct = methodJsonBody.clientType();
}
} else {
if (methodJsonBody != null && methodJsonBody.value()) {
b = true;
ct = methodJsonBody.clientType();
}
}
if (b) {
if (!ct.equals(UserUtil.getClientType())) {
throw new MessageException("客户端类型不对");
}
}
}
return true;
}
}

View File

@ -0,0 +1,29 @@
package com.changhu.support.mybatisplus.handler.permission.management;
import com.changhu.common.utils.UserUtil;
import com.changhu.support.mybatisplus.handler.permission.AbstractDataPermissionHandler;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.LongValue;
import net.sf.jsqlparser.expression.operators.relational.EqualsTo;
import net.sf.jsqlparser.schema.Column;
import net.sf.jsqlparser.schema.Table;
/**
* @author 20252
* @createTime 2024/9/4 下午3:29
* @desc ManagementPoliceUnitUserPagerPermissionHandler...
*/
public class ManagementPoliceUnitUserPagerPermissionHandler implements AbstractDataPermissionHandler {
@Override
public Expression apply(Table table, Expression where, String mappedStatementId) {
if ("mpuu".equals(table.getAlias().getName())) {
return sqlFragment();
}
return null;
}
@Override
public Expression sqlFragment() {
return new EqualsTo(new Column("mpuu.police_unit_id"), new LongValue(UserUtil.getUnitId()));
}
}

View File

@ -1,12 +1,7 @@
package com.changhu.support.mybatisplus.handler.permission.management;
import com.baomidou.mybatisplus.extension.toolkit.Db;
import com.changhu.common.enums.ResultCode;
import com.changhu.common.exception.MessageException;
import com.changhu.common.utils.UserUtil;
import com.changhu.module.management.pojo.entity.ManagementSecurityUnitUser;
import com.changhu.support.mybatisplus.handler.permission.AbstractDataPermissionHandler;
import com.changhu.support.mybatisplus.pojo.entity.BaseEntity;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.LongValue;
import net.sf.jsqlparser.expression.operators.relational.EqualsTo;
@ -29,12 +24,6 @@ public class ManagementSecurityUnitUserPagerPermissionHandler implements Abstrac
@Override
public Expression sqlFragment() {
//查出当前用户
ManagementSecurityUnitUser managementSecurityUnitUser = Db.lambdaQuery(ManagementSecurityUnitUser.class)
.select(BaseEntity::getSnowFlakeId, ManagementSecurityUnitUser::getSecurityUnitId)
.eq(BaseEntity::getSnowFlakeId, UserUtil.getUserId())
.oneOpt()
.orElseThrow(() -> new MessageException(ResultCode.USER_NOT_FOUND));
return new EqualsTo(new Column("msuu.security_unit_id"), new LongValue(managementSecurityUnitUser.getSecurityUnitId()));
return new EqualsTo(new Column("msuu.security_unit_id"), new LongValue(UserUtil.getUnitId()));
}
}

View File

@ -1,8 +1,11 @@
package com.changhu.support.satoken;
import cn.dev33.satoken.dao.SaTokenDaoRedis;
import cn.dev33.satoken.jwt.StpLogicJwtForSimple;
import cn.dev33.satoken.stp.StpLogic;
import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
@ -29,4 +32,12 @@ public class SaTokenConfig {
this.saTokenDaoRedis.stringRedisTemplate = this.stringRedisTemplate;
this.saTokenDaoRedis.objectRedisTemplate = this.redisTemplate;
}
/**
* Sa-Token 整合 jwt (Simple 简单模式)
*/
@Bean
public StpLogic getStpLogicJwt() {
return new StpLogicJwtForSimple();
}
}

View File

@ -138,6 +138,8 @@ sa-token:
is-log: true
# 是否尝试从 cookie 里读取 token
is-read-cookie: false
# jwt秘钥
jwt-secret-key: a29216f8-cd60-4e96-89c5-ab6012159052
project:
env: dev

View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.changhu.module.management.mapper.ManagementPoliceUnitUserMapper">
<select id="pager" resultType="com.changhu.module.management.pojo.vo.ManagementPoliceUnitUserPagerVo">
select
mpuu.*,
mpuu2.name as 'createUserName'
from management_police_unit_user mpuu
left join management_police_unit_user mpuu2 on mpuu.create_by = mpuu2.snow_flake_id
where
mpuu.delete_flag = 0
<if test="params.name!=null and params.name!=''">
and mpuu.name like concat('%',#{params.name},'%')
</if>
<if test="params.telephone!=null and params.telephone!=''">
and mpuu.telephone like concat('%',#{params.telephone},'%')
</if>
<if test="params.sex!=null">
and mpuu.sex = #{params.sex.value}
</if>
order by mpuu.create_time desc
</select>
</mapper>

View File

@ -6,7 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<script type="module" src="/src/assets/iconfont/iconfont.js"></script>
<title>Vite + Vue + TS</title>
<title>超级后台</title>
</head>
<body>
<div id="app"></div>

View File

@ -24,7 +24,7 @@ import {dictSelectNodes} from "@/config/dict.ts";
import {message, Modal} from "ant-design-vue";
import {UNIT_TYPE} from "@/config";
import {PageParams} from "@/types/hooks/useTableProMax.ts";
import {submitSimpleFormModal} from "@/components/tsx/ModalPro.tsx";
import {submitSimpleFormModal, deleteDataModal} from "@/components/tsx/ModalPro.tsx";
import useSelectAndTreeNodeVos from "@/hooks/useSelectAndTreeNodeVos.ts";
type TableProps = TableProMaxProps<PoliceUnitPagerVo, PoliceUnitPagerQueryParams>
@ -103,13 +103,17 @@ const columns: TableProps['columns'] = [
},
}
]
const searchFormOptions: TableProps["searchFormOptions"] = {
const searchFormOptions = ref<TableProps["searchFormOptions"]>({
name: {
type: 'input',
label: '名称'
}, code: {
type: 'input',
label: '代码'
}, administrativeDivisionCodes: {
type: 'cascader',
label: '行政区划',
options: administrativeDivisionTree
}, isEnable: {
type: 'select',
label: '是否启用',
@ -129,7 +133,7 @@ const searchFormOptions: TableProps["searchFormOptions"] = {
}, ...dictSelectNodes('CheckStatus')
]
}
}
})
type _TableProps = TableProMaxProps<EnterprisesUnitPagerVo, EnterprisesUnitPagerQueryParams>;
const showEnterprisesUnit = (policeUnitPagerVo: PoliceUnitPagerVo) => {
@ -226,6 +230,14 @@ const showEnterprisesUnit = (policeUnitPagerVo: PoliceUnitPagerVo) => {
})}
>编辑
</a-button>
<a-button class="btn-danger" onClick={() => deleteDataModal(record.name, async () => {
const resp = await api.delete('/enterprisesUnit/deleteById', {
enterprisesUnitId: record.snowFlakeId
})
message.success(resp.message)
await _tableRef.value?.requestGetTableData()
})}>删除
</a-button>
</a-space>
}
]

View File

@ -81,21 +81,24 @@ const columns: TableProps['columns'] = [
title: '操作',
fixed: "right",
customRender({record}) {
if (record.checkStatus.value === 1) {
return <a-space>
<a-popconfirm
title="确认审核通过嘛?"
onConfirm={async () => {
const resp = await api.post('/management/checkPass', {
checkDataId: record.snowFlakeId,
unitOptType: UNIT_TYPE.security
})
message.success(resp.message)
await tableRef.value?.requestGetTableData()
}}>
<a-button type="primary">审核通过
</a-button>
</a-popconfirm>
</a-space>
}
return <a-space>
{record.checkStatus.value === 1 && <a-popconfirm
title="确认审核通过嘛?"
onConfirm={async () => {
const resp = await api.post('/management/checkPass', {
checkDataId: record.snowFlakeId,
unitOptType: UNIT_TYPE.security
})
message.success(resp.message)
await tableRef.value?.requestGetTableData()
}}>
<a-button type="primary">审核通过
</a-button>
</a-popconfirm>
}
<a-button
class={record.isEnable.value === 0 ? 'btn-danger' : 'btn-success'}
onClick={async () => {