| | |
| | | } |
| | | ] |
| | | }, |
| | | { |
| | | path:'role', |
| | | name: 'role', |
| | | component: () => import('../views/system/role/Role.vue'), |
| | | children:[ |
| | | { |
| | | path: 'roleList', |
| | | name: 'roleList', |
| | | component: () => import('../views/system/role/RoleList.vue') |
| | | }, |
| | | { |
| | | name:'role', |
| | | path: '', |
| | | redirect:'/main/role/roleList' |
| | | } |
| | | ] |
| | | }, |
| | | |
| | | //sd模块 |
| | | { |
| | |
| | | } |
| | | |
| | | const tagCheck = (state) => { |
| | | if(typeof trademarkAttr.value.location === 'string'){ |
| | | return false |
| | | } |
| | | const filterArr = trademarkAttr.value.location.filter((item) =>{ |
| | | return item === state |
| | | }) |
| | | return filterArr.length > 0 |
| | | |
| | | return trademarkAttr.value.location === state |
| | | } |
| | | const resetTrademark = () => { |
| | | for(const key in trademarkAttr.value){ |
| | |
| | | <el-row> |
| | | <el-col :span="4">商标位置:</el-col> |
| | | <el-col :span="25"> |
| | | <el-checkbox v-model="trademarkAttr.location" v-for="item in trademarkLocation" :label="item" /> |
| | | <el-radio v-model="trademarkAttr.location" v-for="item in trademarkLocation" :label="item" /> |
| | | </el-col> |
| | | </el-row> |
| | | |
New file |
| | |
| | | <script setup> |
| | | import {ArrowLeftBold, ArrowRight, Search} from "@element-plus/icons-vue" |
| | | import {useRouter,useRoute,onBeforeRouteUpdate} from "vue-router" |
| | | import {useI18n} from "vue-i18n" |
| | | const { t } = useI18n() |
| | | const router = useRouter() |
| | | const route = useRoute() |
| | | let indexFlag=$ref(1) |
| | | function changeRouter(index){ |
| | | indexFlag=index |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | </script> |
| | | |
| | | <template> |
| | | <div id="main-div"> |
| | | <div id="div-title"> |
| | | <el-breadcrumb :separator-icon="ArrowRight"> |
| | | <el-breadcrumb-item @click="changeRouter(1)" :class="indexFlag===1?'indexTag':''" :to="{ path: '/main/role/roleList' }">角色首页</el-breadcrumb-item> |
| | | <el-breadcrumb-item v-show="false" @click="changeRouter(2)" :class="indexFlag===2?'indexTag':''" :to="{ path: '/main/order/createOrder' }">{{$t('basicData.create')}}</el-breadcrumb-item> |
| | | </el-breadcrumb> |
| | | </div> |
| | | |
| | | <div id="main-body"> |
| | | <router-view :key="route.fullPath" /> |
| | | </div> |
| | | </div> |
| | | </template> |
| | | |
| | | <style scoped> |
| | | #main-div{ |
| | | width: 99%; |
| | | height: 100%; |
| | | } |
| | | #div-title{ |
| | | height: 2%; |
| | | width: 100%; |
| | | } |
| | | #searchButton{ |
| | | margin-top: -5px; |
| | | margin-left: 1rem; |
| | | } |
| | | #searchButton1{ |
| | | //margin-left: 10rem; |
| | | } |
| | | /*main-body样式*/ |
| | | #main-body{ |
| | | width: 100%; |
| | | height: 95%; |
| | | margin-top: 1%; |
| | | } |
| | | #select{ |
| | | margin-left:0.5rem; |
| | | } |
| | | :deep(.indexTag .el-breadcrumb__inner){ |
| | | color: #5CADFE !important; |
| | | } |
| | | </style> |
| | |
| | | <script setup> |
| | | import {changeFilterEvent, filterChanged} from "@/hook" |
| | | import {onBeforeMount, onMounted, reactive, ref} from "vue" |
| | | import request from "@/utils/request" |
| | | import {useRouter,useRoute} from "vue-router" |
| | | import {useI18n} from "vue-i18n" |
| | | import {ElMessage, ElMessageBox} from "element-plus" |
| | | const { t } = useI18n() |
| | | const router = useRouter() |
| | | const route = useRoute() |
| | | const dialogVisible = ref(false) |
| | | let selectValue = ref(null) |
| | | let options = ref([]) |
| | | |
| | | const xGrid = ref() |
| | | const gridOptions = reactive({ |
| | | border: "full",//表格加边框 |
| | | keepSource: true,//保持源数据 |
| | | align: 'center',//文字居中 |
| | | stripe:true,//斑马纹 |
| | | rowConfig: {isCurrent: true, isHover: true,height: 30},//鼠标移动或选择高亮 |
| | | id: 'userList', |
| | | showFooter: false,//显示脚 |
| | | printConfig: {}, |
| | | importConfig: {}, |
| | | exportConfig: {}, |
| | | scrollY:{ enabled: true },//开启虚拟滚动 |
| | | showOverflow:true, |
| | | columnConfig: { |
| | | resizable: true, |
| | | useKey: true |
| | | }, |
| | | filterConfig: { //筛选配置项 |
| | | }, |
| | | customConfig: { |
| | | storage: true |
| | | }, |
| | | editConfig: { |
| | | trigger: 'click', |
| | | mode: 'row', |
| | | showStatus: true |
| | | }, |
| | | |
| | | //表头参数 |
| | | columns:[ |
| | | |
| | | ], |
| | | |
| | | //表头按钮 |
| | | toolbarConfig: { |
| | | buttons: [ |
| | | |
| | | ], |
| | | zoom: true, |
| | | custom: true |
| | | }, |
| | | }) |
| | | |
| | | const pGrid = ref() |
| | | const permissionOptions = reactive({ |
| | | border: "full",//表格加边框 |
| | | keepSource: true,//保持源数据 |
| | | align: 'center',//文字居中 |
| | | stripe:true,//斑马纹 |
| | | rowConfig: {isCurrent: true, isHover: true,height: 30},//鼠标移动或选择高亮 |
| | | id: 'permissionList', |
| | | showFooter: false,//显示脚 |
| | | printConfig: {}, |
| | | importConfig: {}, |
| | | exportConfig: {}, |
| | | scrollY:{ enabled: true },//开启虚拟滚动 |
| | | showOverflow:true, |
| | | columnConfig: { |
| | | resizable: true, |
| | | useKey: true |
| | | }, |
| | | filterConfig: { //筛选配置项 |
| | | }, |
| | | customConfig: { |
| | | storage: true |
| | | }, |
| | | editConfig: { |
| | | trigger: 'click', |
| | | mode: 'row', |
| | | showStatus: true |
| | | }, |
| | | |
| | | //表头参数 |
| | | columns:[ |
| | | |
| | | ], |
| | | |
| | | //表头按钮 |
| | | toolbarConfig: { |
| | | buttons: [ |
| | | |
| | | ], |
| | | slots:{ |
| | | buttons: "toolbar_buttons" |
| | | }, |
| | | zoom: true, |
| | | custom: true |
| | | }, |
| | | }) |
| | | |
| | | |
| | | |
| | | onBeforeMount(()=>{ |
| | | let columns = [{title: t('basicData.operate'), width: 133, slots: { default: 'button_slot' }}] |
| | | const columnName = { |
| | | id: 'ID', |
| | | role:'角色' |
| | | } |
| | | for (let columnNameKey in columnName) { |
| | | let column = {field: columnNameKey, |
| | | title: columnName[columnNameKey] |
| | | } |
| | | columns.push(column) |
| | | } |
| | | gridOptions.columns = columns |
| | | |
| | | |
| | | let columnsP = [ |
| | | { type: 'seq', width: 60 }, |
| | | { type: 'checkbox', width: 50 } |
| | | ] |
| | | const columnNameP = { |
| | | id: 'ID', |
| | | menu: '菜单', |
| | | page:'页面', |
| | | permission:'权限' |
| | | } |
| | | for (let columnNameKey in columnNameP) { |
| | | let column = {field: columnNameKey, |
| | | title: columnNameP[columnNameKey] |
| | | } |
| | | columnsP.push(column) |
| | | } |
| | | permissionOptions.columns = columnsP |
| | | |
| | | }) |
| | | |
| | | onMounted(()=>{ |
| | | request.get('/role/findAll').then(res=>{ |
| | | gridOptions.data = res.data |
| | | }) |
| | | request.post('/permission/getPermissionList').then(res=>{ |
| | | options.value = res.data |
| | | }) |
| | | }) |
| | | |
| | | const getTableRow = (row,type) => { |
| | | switch (type) { |
| | | case 'edit': { |
| | | dialogVisible.value = true |
| | | break |
| | | } |
| | | } |
| | | } |
| | | |
| | | const getPermissionList = () => { |
| | | request.post(`/permission/getPermission/${2}`).then(res=>{ |
| | | permissionOptions.data = res.data |
| | | }) |
| | | } |
| | | |
| | | const selectChange = ()=>{ |
| | | console.log(selectValue.value) |
| | | } |
| | | |
| | | </script> |
| | | |
| | | <template> |
| | | <div style="width: 50%;height: 100% ;"> |
| | | <vxe-grid |
| | | max-height="100%" |
| | | class="mytable-scrollbar" |
| | | ref="xGrid" |
| | | v-bind="gridOptions" |
| | | > |
| | | <template #filter="{ column, $panel }"> |
| | | <div> |
| | | <div v-for="(option, index) in column.filters" :key="index"> |
| | | <input type="type" v-model="option.data" @input="changeFilterEvent($event, option, $panel)"/> |
| | | </div> |
| | | </div> |
| | | </template> |
| | | |
| | | <template #button_slot="{ row }"> |
| | | <el-button @click="getTableRow(row,'edit')" link type="primary" size="small">角色权限</el-button> |
| | | </template> |
| | | </vxe-grid> |
| | | |
| | | <el-dialog |
| | | v-model="dialogVisible" |
| | | @open="getPermissionList" |
| | | style="height: 70%;width: 70%" |
| | | title="权限选择"> |
| | | <vxe-grid |
| | | height="100%" |
| | | class="mytable-scrollbar" |
| | | ref="pGrid" |
| | | v-bind="permissionOptions" |
| | | > |
| | | <template #toolbar_buttons> |
| | | <el-cascader |
| | | v-model="selectValue" |
| | | :options="options" |
| | | @change="selectChange" |
| | | /> |
| | | </template> |
| | | |
| | | </vxe-grid> |
| | | |
| | | |
| | | </el-dialog> |
| | | </div> |
| | | </template> |
| | | |
| | | <style scoped> |
| | | |
| | | :deep(.el-dialog__body){ |
| | | height: 80%; |
| | | } |
| | | </style> |
| | |
| | | import {onBeforeMount, onMounted, reactive, ref} from "vue" |
| | | import {changeFilterEvent,filterChanged} from "@/hook" |
| | | import request from "@/utils/request" |
| | | import {useRouter,useRoute} from "vue-router" |
| | | import {useI18n} from "vue-i18n" |
| | | import {ElMessage, ElMessageBox} from "element-plus" |
| | | const { t } = useI18n() |
| | | const router = useRouter() |
| | | const route = useRoute() |
| | | const dialogVisible = ref(false) |
| | | let roleList = ref([]) |
| | | let userRole= ref({ |
| | | userId:'', |
| | | roles:[] |
| | | }) |
| | | const xGrid = ref() |
| | | const gridOptions = reactive({ |
| | | border: "full",//表格加边框 |
| | |
| | | const columnName = { |
| | | loginName: '用户ID', |
| | | userName:'用户', |
| | | address:'地址', |
| | | phone:'电话', |
| | | // address:'地址', |
| | | // phone:'电话', |
| | | role:'角色', |
| | | createTime:'创建时间' |
| | | } |
| | |
| | | }) |
| | | onMounted(()=>{ |
| | | request.get('/userInfo/findAll').then(res=>{ |
| | | gridOptions.data = res.data |
| | | let arr = res.data.users[0] |
| | | arr.forEach(item=>{ |
| | | let bValues = item.userRoleList.map(item => item.role); |
| | | item.role = bValues.join(',') |
| | | }) |
| | | gridOptions.data = res.data.users[0] |
| | | roleList.value = res.data.role[0] |
| | | }) |
| | | }) |
| | | |
| | | const getTableRow = (row,type) => { |
| | | switch (type) { |
| | | case 'edit': { |
| | | userRole.value.roles = [] |
| | | dialogVisible.value = true |
| | | row.userRoleList.forEach(item=>{ |
| | | userRole.value.roles.push(item.roleId) |
| | | }) |
| | | userRole.value.userId = row.id |
| | | break |
| | | } |
| | | case 'delete': { |
| | | request.post(`/userInfo/userDelete/${row.id}`).then((res) => { |
| | | if(res.code==200 && res.data ===true){ |
| | | ElMessage.success(t('searchOrder.msgDeleteSuccess')) |
| | | router.push({path:'/main/user/userList',query:{random:Math.random()}}) |
| | | }else{ |
| | | ElMessage.warning(t('searchOrder.msgDeleteFail')) |
| | | } |
| | | }) |
| | | break |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | const handleClose = (done) => { |
| | | userRole.value.roles = [] |
| | | done() |
| | | } |
| | | |
| | | const roleUpdate = () => { |
| | | request.post('userRole/updateUserRole',userRole.value).then(res=>{ |
| | | if(res.code==200 && res.data===true){ |
| | | ElMessage.success(t('basicData.msg.saveSuccess')) |
| | | router.push({path:'/main/user/userList',query:{random:Math.random()}}) |
| | | } |
| | | |
| | | }) |
| | | dialogVisible.value = false |
| | | } |
| | | |
| | | |
| | | |
| | | </script> |
| | | |
| | | <template> |
| | |
| | | </el-popconfirm> |
| | | </template> |
| | | </vxe-grid> |
| | | |
| | | <el-dialog |
| | | v-model="dialogVisible" |
| | | title="角色选择" |
| | | width="30%" |
| | | :before-close="handleClose" |
| | | > |
| | | <span> |
| | | <el-checkbox v-for="(item) in roleList" |
| | | :label="item.id" |
| | | v-model="userRole.roles" > |
| | | {{item.role}} |
| | | </el-checkbox> |
| | | </span> |
| | | <template #footer> |
| | | <span class="dialog-footer"> |
| | | <el-button @click="dialogVisible = false">取消</el-button> |
| | | <el-button type="primary" @click="roleUpdate"> |
| | | 确认 |
| | | </el-button> |
| | | </span> |
| | | </template> |
| | | </el-dialog> |
| | | </div> |
| | | </template> |
| | | |
| | | <style scoped> |
| | | .dialog-footer button:first-child { |
| | | margin-right: 10px; |
| | | } |
| | | </style> |
New file |
| | |
| | | package com.example.erp.controller.userInfo; |
| | | |
| | | import com.example.erp.common.Result; |
| | | import com.example.erp.service.userInfo.PermissionBasicService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.PathVariable; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | @RestController |
| | | @RequestMapping("/permission") |
| | | public class PermissionBasicController { |
| | | private final PermissionBasicService permissionBasicService; |
| | | |
| | | public PermissionBasicController(PermissionBasicService permissionBasicService) { |
| | | this.permissionBasicService = permissionBasicService; |
| | | } |
| | | |
| | | @PostMapping("getPermission/{userId}") |
| | | public Result getPermission(@PathVariable Integer userId){ |
| | | return Result.seccess(permissionBasicService.getPermission(userId)); |
| | | } |
| | | |
| | | @PostMapping("getPermissionList") |
| | | public Result getPermission(){ |
| | | return Result.seccess(permissionBasicService.getPermissionList()); |
| | | } |
| | | } |
New file |
| | |
| | | package com.example.erp.controller.userInfo; |
| | | |
| | | import com.example.erp.common.Result; |
| | | import com.example.erp.service.userInfo.RoleService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | @RestController |
| | | @RequestMapping("/role") |
| | | public class RoleController { |
| | | private final RoleService roleService; |
| | | |
| | | public RoleController(RoleService roleService) { |
| | | this.roleService = roleService; |
| | | } |
| | | |
| | | @GetMapping("/findAll") |
| | | public Result findAll(){ |
| | | return Result.seccess(roleService.findAll()); |
| | | } |
| | | } |
| | |
| | | return Result.seccess(StpUtil.getTokenInfo()); |
| | | } |
| | | |
| | | @PostMapping("/userDelete") |
| | | public Result userDelete() { |
| | | return Result.seccess(123123); |
| | | @PostMapping("/userDelete/{id}") |
| | | public Result userDelete(@PathVariable Integer id) { |
| | | return Result.seccess(userService.userDelete(id)); |
| | | } |
| | | |
| | | @GetMapping("findAll") |
New file |
| | |
| | | package com.example.erp.controller.userInfo; |
| | | |
| | | import com.example.erp.common.Result; |
| | | import com.example.erp.controller.dto.UserDTO; |
| | | import com.example.erp.service.userInfo.UserRoleService; |
| | | 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.RestController; |
| | | |
| | | import java.util.Map; |
| | | |
| | | @RestController |
| | | @RequestMapping("/userRole") |
| | | public class UserRoleController { |
| | | private final UserRoleService userRoleService; |
| | | |
| | | public UserRoleController(UserRoleService userRoleService) { |
| | | this.userRoleService = userRoleService; |
| | | } |
| | | |
| | | @PostMapping("/updateUserRole") |
| | | public Result updateUserRole(@RequestBody Map<String,Object> params) { |
| | | return Result.seccess(userRoleService.updateUserRole(params)); |
| | | } |
| | | } |
| | |
| | | public class PermissionBasic { |
| | | @TableId(type = IdType.AUTO) |
| | | private Integer id; |
| | | private String menu; |
| | | private String page; |
| | | private String permission; |
| | | private String state; |
| | |
| | | private Integer id; |
| | | private Integer roleId; |
| | | private Integer permissionId; |
| | | |
| | | } |
| | |
| | | @Data |
| | | public class Role { |
| | | @TableId(type = IdType.AUTO) |
| | | private String id; |
| | | private Integer id; |
| | | private String role; |
| | | } |
| | |
| | | package com.example.erp.entity.userInfo; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.IdType; |
| | | import com.baomidou.mybatisplus.annotation.TableField; |
| | | import com.baomidou.mybatisplus.annotation.TableId; |
| | | import lombok.Data; |
| | | |
| | | import java.util.List; |
| | | |
| | | @Data //get与set代码简写 |
| | | public class User { |
| | |
| | | private String createTime; |
| | | private String updateTime; |
| | | private Integer state; |
| | | @TableField(select = false,exist = false) |
| | | private List<UserRole> userRoleList; |
| | | |
| | | } |
New file |
| | |
| | | package com.example.erp.entity.userInfo; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.IdType; |
| | | import com.baomidou.mybatisplus.annotation.TableField; |
| | | import com.baomidou.mybatisplus.annotation.TableId; |
| | | import lombok.Data; |
| | | |
| | | @Data |
| | | public class UserRole { |
| | | @TableId(type = IdType.AUTO) |
| | | private Integer id; |
| | | private Integer userId; |
| | | private Integer roleId; |
| | | @TableField(select = false,exist = false) |
| | | private String role; |
| | | |
| | | } |
New file |
| | |
| | | package com.example.erp.mapper.userInfo; |
| | | |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import com.example.erp.entity.userInfo.PermissionBasic; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @Mapper |
| | | public interface PermissionBasicMapper extends BaseMapper<PermissionBasic> { |
| | | List<PermissionBasic> getPermission(Integer userId); |
| | | |
| | | List<PermissionBasic> selectOneLevel(); |
| | | |
| | | List<Map<String,Object>> selectTowLevel(String menu); |
| | | } |
New file |
| | |
| | | package com.example.erp.mapper.userInfo; |
| | | |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import com.example.erp.entity.userInfo.Role; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | |
| | | @Mapper |
| | | public interface RoleMapper extends BaseMapper<Role> { |
| | | |
| | | |
| | | |
| | | } |
| | |
| | | Boolean register(User user); |
| | | |
| | | List<String> getUserRole(Integer id); |
| | | |
| | | Boolean userDelete(Integer id); |
| | | } |
New file |
| | |
| | | package com.example.erp.mapper.userInfo; |
| | | |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import com.example.erp.entity.userInfo.UserRole; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | |
| | | @Mapper |
| | | public interface UserRoleMapper extends BaseMapper<UserRole> { |
| | | } |
New file |
| | |
| | | package com.example.erp.service.userInfo; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.example.erp.entity.userInfo.PermissionBasic; |
| | | import com.example.erp.mapper.userInfo.PermissionBasicMapper; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @Service |
| | | public class PermissionBasicService { |
| | | private final PermissionBasicMapper permissionBasicMapper; |
| | | |
| | | public PermissionBasicService(PermissionBasicMapper permissionBasicMapper) { |
| | | this.permissionBasicMapper = permissionBasicMapper; |
| | | } |
| | | |
| | | public List<PermissionBasic> getPermission(Integer userId) { |
| | | return permissionBasicMapper.getPermission(userId); |
| | | } |
| | | |
| | | public Object getPermissionList() { |
| | | List<PermissionBasic> getOne = permissionBasicMapper.selectOneLevel(); |
| | | List<Map<String,Object>> ListOne = new ArrayList<>(); |
| | | |
| | | for(PermissionBasic permissionBasic : getOne){ |
| | | |
| | | Map<String,Object> map = new HashMap<>(); |
| | | map.put("value",permissionBasic.getId()); |
| | | map.put("label",permissionBasic.getMenu()); |
| | | map.put("children",permissionBasicMapper.selectTowLevel(permissionBasic.getMenu())); |
| | | ListOne.add(map); |
| | | } |
| | | |
| | | return ListOne; |
| | | } |
| | | } |
New file |
| | |
| | | package com.example.erp.service.userInfo; |
| | | |
| | | import com.baomidou.dynamic.datasource.annotation.DS; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.example.erp.entity.userInfo.Role; |
| | | import com.example.erp.mapper.userInfo.RoleMapper; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.List; |
| | | |
| | | @Service |
| | | @DS("user_info") |
| | | public class RoleService { |
| | | private final RoleMapper roleMapper; |
| | | |
| | | public RoleService(RoleMapper roleMapper) { |
| | | this.roleMapper = roleMapper; |
| | | } |
| | | |
| | | public List<Role> findAll() { |
| | | return roleMapper.selectList( |
| | | new QueryWrapper<Role>() |
| | | .ne("role","admin") |
| | | ); |
| | | } |
| | | } |
New file |
| | |
| | | package com.example.erp.service.userInfo; |
| | | |
| | | import com.baomidou.dynamic.datasource.annotation.DS; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.example.erp.entity.userInfo.UserRole; |
| | | import com.example.erp.mapper.userInfo.UserRoleMapper; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @Service |
| | | @DS("user_info") |
| | | public class UserRoleService { |
| | | private final UserRoleMapper userRoleMapper; |
| | | |
| | | public UserRoleService(UserRoleMapper userRoleMapper) { |
| | | this.userRoleMapper = userRoleMapper; |
| | | } |
| | | |
| | | public Boolean updateUserRole(Map<String, Object> params) { |
| | | Integer userId = (Integer) params.get("userId"); |
| | | List<Integer> list = (List<Integer>) params.get("roles"); |
| | | List<UserRole> userRoleList = new ArrayList<>(); |
| | | if(!list.isEmpty()) { |
| | | for (Integer roleId : list) { |
| | | UserRole userRole = new UserRole(); |
| | | userRole.setUserId(userId); |
| | | userRole.setRoleId(roleId); |
| | | userRoleList.add(userRole); |
| | | } |
| | | } |
| | | userRoleMapper.delete(new QueryWrapper<UserRole>().eq("user_id", userId)); |
| | | userRoleList.forEach(userRole -> { |
| | | userRoleMapper.insert(userRole); |
| | | }); |
| | | return true; |
| | | } |
| | | } |
| | |
| | | import com.baomidou.dynamic.datasource.annotation.DS; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.example.erp.controller.dto.UserDTO; |
| | | import com.example.erp.entity.userInfo.Role; |
| | | import com.example.erp.entity.userInfo.User; |
| | | import com.example.erp.mapper.userInfo.RoleMapper; |
| | | import com.example.erp.mapper.userInfo.UserMapper; |
| | | import com.example.erp.tools.TokenTools; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.cache.annotation.CacheEvict; |
| | | import org.springframework.cache.annotation.Cacheable; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.Collections; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @Service |
| | | @DS("user_info") |
| | | public class UserService { |
| | | |
| | | private final UserMapper userMapper; |
| | | private final RoleMapper roleMapper; |
| | | |
| | | public UserService(UserMapper userMapper) { |
| | | public UserService(UserMapper userMapper, RoleMapper roleMapper) { |
| | | this.userMapper = userMapper; |
| | | this.roleMapper = roleMapper; |
| | | } |
| | | |
| | | |
| | |
| | | return true; |
| | | } |
| | | |
| | | public List<User> findAll() { |
| | | public Map<String,List<Object>> findAll() { |
| | | List<User> users = userMapper.findAll(); |
| | | users.forEach(user -> { |
| | | user.setPassword(null); |
| | | }); |
| | | return users; |
| | | Map<String,List<Object>> map = new HashMap<>(); |
| | | |
| | | map.put("users", Collections.singletonList(users)); |
| | | map.put("role", Collections.singletonList( |
| | | roleMapper.selectList( |
| | | new QueryWrapper<Role>() |
| | | .ne("role","admin") |
| | | ) |
| | | )); |
| | | return map; |
| | | } |
| | | |
| | | public Boolean userDelete(Integer id) { |
| | | |
| | | return userMapper.userDelete(id); |
| | | } |
| | | } |
| | | |
New file |
| | |
| | | <?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.example.erp.mapper.userInfo.PermissionBasicMapper"> |
| | | <select id="getPermission"> |
| | | select a.*, |
| | | CASE |
| | | WHEN b.id IS NULL THEN 0 |
| | | ELSE 1 |
| | | END |
| | | from permission_basic as a |
| | | left join permission_role as b |
| | | on a.id = b.permission_id |
| | | left join user_role as c |
| | | on b.role_id = c.role_id |
| | | left join user as d |
| | | on c.user_id = d.id |
| | | and d.id = #{userId} |
| | | where a.id!=1 and a.state=1 |
| | | group by a.id |
| | | </select> |
| | | |
| | | <select id="selectOneLevel"> |
| | | select * |
| | | from permission_basic |
| | | where id!=1 and state=1 |
| | | group by menu |
| | | |
| | | </select> |
| | | |
| | | <select id="selectTowLevel"> |
| | | select |
| | | id as value, |
| | | page as label |
| | | from permission_basic |
| | | where id!=1 and state=1 |
| | | group by menu |
| | | |
| | | </select> |
| | | |
| | | </mapper> |
New file |
| | |
| | | <?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.example.erp.mapper.userInfo.RoleMapper"> |
| | | |
| | | |
| | | </mapper> |
| | |
| | | PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" |
| | | "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | <mapper namespace="com.example.erp.mapper.userInfo.UserMapper"> |
| | | <select id="findAll"> |
| | | SELECT * |
| | | FROM erp_user_info.user |
| | | where state =1 |
| | | <resultMap id="findAllMap" type="com.example.erp.entity.userInfo.User"> |
| | | <id property="id" column="id"/> |
| | | <result property="loginName" column="login_name"/> |
| | | <result property="userName" column="user_name"/> |
| | | <result property="createTime" column="create_time"/> |
| | | |
| | | <collection property="userRoleList" ofType="com.example.erp.entity.userInfo.UserRole"> |
| | | <result property="userId" column="user_id"/> |
| | | <result property="roleId" column="role_id"/> |
| | | <result property="role" column="role"/> |
| | | </collection> |
| | | </resultMap> |
| | | |
| | | |
| | | <select id="findAll" resultMap="findAllMap"> |
| | | SELECT a.*, |
| | | b.role_id, |
| | | c.role |
| | | FROM erp_user_info.user as a |
| | | left join user_role as b |
| | | on a.id = b.user_id |
| | | left join role as c |
| | | on b.role_id = c.id |
| | | where state =1 and a.id != 1 |
| | | </select> |
| | | |
| | | <select id="findOne" > |
| | |
| | | where a.id = #{loginId} |
| | | |
| | | </select> |
| | | <update id="userDelete"> |
| | | update user |
| | | set state =0 |
| | | where id = #{id} |
| | | </update> |
| | | </mapper> |
| | |
| | | PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" |
| | | "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | <mapper namespace="com.example.erp.mapper.userInfo.UserMapper"> |
| | | <select id="findAll"> |
| | | SELECT * |
| | | FROM erp_user_info.user |
| | | where state =1 |
| | | <resultMap id="findAllMap" type="com.example.erp.entity.userInfo.User"> |
| | | <id property="id" column="id"/> |
| | | <result property="loginName" column="login_name"/> |
| | | <result property="userName" column="user_name"/> |
| | | <result property="createTime" column="create_time"/> |
| | | |
| | | <collection property="userRoleList" ofType="com.example.erp.entity.userInfo.UserRole"> |
| | | <result property="userId" column="user_id"/> |
| | | <result property="roleId" column="role_id"/> |
| | | <result property="role" column="role"/> |
| | | </collection> |
| | | </resultMap> |
| | | |
| | | |
| | | <select id="findAll" resultMap="findAllMap"> |
| | | SELECT a.*, |
| | | b.role_id, |
| | | c.role |
| | | FROM erp_user_info.user as a |
| | | left join user_role as b |
| | | on a.id = b.user_id |
| | | left join role as c |
| | | on b.role_id = c.id |
| | | where state =1 and a.id != 1 |
| | | </select> |
| | | |
| | | <select id="findOne" > |
| | |
| | | where a.id = #{loginId} |
| | | |
| | | </select> |
| | | <update id="userDelete"> |
| | | update user |
| | | set state =0 |
| | | where id = #{id} |
| | | </update> |
| | | </mapper> |