From 9b7ca47ae4b00b0eae05da4e76410ee1fc1dd8b4 Mon Sep 17 00:00:00 2001 From: zhenxianyimeng <1920405993@qq.com> Date: Sun, 21 Jul 2019 17:23:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=91=98=E5=B7=A5=E5=88=97=E8=A1=A8=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=83=A8=E9=97=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin-web/src/models/admin/adminList.js | 82 +++++-- admin-web/src/pages/Admin/AdminList.js | 220 +++++++++++++----- docs/sql/mall_admin.sql | 1 + .../controller/admins/AdminController.java | 16 ++ .../admin/application/vo/admin/AdminVO.java | 18 ++ .../mall/admin/api/bo/admin/AdminBO.java | 3 + .../mall/admin/api/dto/admin/AdminAddDTO.java | 5 + .../admin/api/dto/admin/AdminPageDTO.java | 4 + .../admin/api/dto/admin/AdminUpdateDTO.java | 4 + .../iocoder/mall/admin/dao/AdminMapper.java | 10 +- .../mall/admin/dataobject/AdminDO.java | 6 + .../admin/service/DeptmentServiceImpl.java | 6 + 12 files changed, 295 insertions(+), 80 deletions(-) diff --git a/admin-web/src/models/admin/adminList.js b/admin-web/src/models/admin/adminList.js index c9c433ec7..95025b69f 100644 --- a/admin-web/src/models/admin/adminList.js +++ b/admin-web/src/models/admin/adminList.js @@ -1,5 +1,5 @@ -import {message} from 'antd'; -import {buildTreeNode, findCheckedKeys} from '../../utils/tree.utils'; +import { message } from 'antd'; +import { buildTreeNode, findCheckedKeys } from '../../utils/tree.utils'; import { addAdmin, adminRoleAssign, @@ -8,14 +8,30 @@ import { queryAdminRoleList, updateAdmin, updateAdminStatus, + deptTreeAll, } from '../../services/admin'; -import {arrayToStringParams} from '../../utils/request.qs'; +import { arrayToStringParams } from '../../utils/request.qs'; import PaginationHelper from '../../../helpers/PaginationHelper'; const SEARCH_PARAMS_DEFAULT = { nickname: '', }; +const buildSelectTree = list => { + return list.map(item => { + let children = []; + if (item.children) { + children = buildSelectTree(item.children); + } + return { + title: item.name, + value: `${item.name}-${item.id}`, + key: item.id, + children, + }; + }); +}; + export default { namespace: 'adminList', @@ -37,11 +53,22 @@ export default { roleModalVisible: false, roleCheckedKeys: [], // 此处的 Key ,就是角色编号 roleAssignLoading: false, + + //部门相关 + deptSelectTree: [], }, effects: { + *getDeptmentTree({ payload }, { call, put }) { + const result = yield call(deptTreeAll, payload); + yield put({ + type: 'treeSuccess', + payload: result.data, + }); + }, + // 查询列表 - * query({ payload }, { call, put }) { + *query({ payload }, { call, put }) { // 显示加载中 yield put({ type: 'changeListLoading', @@ -57,8 +84,8 @@ export default { list: response.data.list, pagination: PaginationHelper.formatPagination(response.data, payload), searchParams: { - nickname: payload.nickname || '' - } + nickname: payload.nickname || '', + }, }, }); @@ -68,7 +95,7 @@ export default { payload: false, }); }, - * add({ payload }, { call, put }) { + *add({ payload }, { call, put }) { // 显示加载中 yield put({ type: 'changeModalLoading', @@ -87,7 +114,7 @@ export default { yield put({ type: 'query', payload: { - ...PaginationHelper.defaultPayload + ...PaginationHelper.defaultPayload, }, }); } @@ -98,7 +125,7 @@ export default { payload: false, }); }, - * update({ payload }, { call, put }) { + *update({ payload }, { call, put }) { const { callback, body } = payload; // 显示加载中 yield put({ @@ -117,7 +144,7 @@ export default { yield put({ type: 'query', payload: { - ...PaginationHelper.defaultPayload + ...PaginationHelper.defaultPayload, }, }); } @@ -129,7 +156,7 @@ export default { }); }, - * updateStatus({ payload }, { call, put }) { + *updateStatus({ payload }, { call, put }) { // 请求 const response = yield call(updateAdminStatus, payload); // 响应 @@ -139,13 +166,13 @@ export default { yield put({ type: 'query', payload: { - ...PaginationHelper.defaultPayload + ...PaginationHelper.defaultPayload, }, }); } }, - * delete({ payload }, { call, put }) { + *delete({ payload }, { call, put }) { // 请求 const response = yield call(deleteAdmin, payload); // 响应 @@ -155,13 +182,13 @@ export default { yield put({ type: 'query', payload: { - ...PaginationHelper.defaultPayload + ...PaginationHelper.defaultPayload, }, }); } }, - * queryRoleList({ payload }, { call, put }) { + *queryRoleList({ payload }, { call, put }) { // 显示加载中 yield put({ type: 'changeRoleAssignLoading', @@ -191,7 +218,7 @@ export default { }); }, - * roleAssign({ payload }, { call, put }) { + *roleAssign({ payload }, { call, put }) { const { callback, body } = payload; // 显示加载中 yield put({ @@ -220,6 +247,27 @@ export default { }, reducers: { + treeSuccess(state, { payload }) { + const resultData = payload; + const treeData = buildSelectTree(resultData); + + // // value 要保护 displayName 不然,搜索会失效 + // const rootNode = [ + // { + // title: '根节点', + // value: `根节点-0`, + // key: 0, + // children: [], + // }, + // ]; + + // const deptSelectTree = rootNode.concat(treeData); + return { + ...state, + // list: resultData, + deptSelectTree: treeData, + }; + }, changeRoleCheckedKeys(state, { payload }) { return { ...state, @@ -251,6 +299,6 @@ export default { ...state, ...payload, }; - } + }, }, }; diff --git a/admin-web/src/pages/Admin/AdminList.js b/admin-web/src/pages/Admin/AdminList.js index 8e4e77ca5..1866cfad8 100644 --- a/admin-web/src/pages/Admin/AdminList.js +++ b/admin-web/src/pages/Admin/AdminList.js @@ -2,22 +2,44 @@ import React, { PureComponent, Fragment } from 'react'; import { connect } from 'dva'; -import {Card, Form, Input, Button, Modal, message, Table, Divider, Tree, Spin, Row, Col, Select, Icon} from 'antd'; -import { checkTypeWithEnglishAndNumbers } from '../../../helpers/validator' +import { + Card, + Form, + Input, + Button, + Modal, + message, + Table, + Divider, + Tree, + Spin, + Row, + Col, + Select, + Icon, + TreeSelect, +} from 'antd'; +import { checkTypeWithEnglishAndNumbers } from '../../../helpers/validator'; import PageHeaderWrapper from '@/components/PageHeaderWrapper'; import styles from './AdminList.less'; -import moment from "moment"; -import PaginationHelper from "../../../helpers/PaginationHelper"; +import moment from 'moment'; +import PaginationHelper from '../../../helpers/PaginationHelper'; const FormItem = Form.Item; const { TreeNode } = Tree; const status = ['未知', '正常', '禁用']; // 列表 -function List ({ dataSource, loading, pagination, searchParams, dispatch, - handleModalVisible, handleRoleAssignModalVisible}) { - +function List({ + dataSource, + loading, + pagination, + searchParams, + dispatch, + handleModalVisible, + handleRoleAssignModalVisible, +}) { function handleRoleAssign(record) { // 显示 Modal handleRoleAssignModalVisible(true, record); @@ -66,12 +88,16 @@ function List ({ dataSource, loading, pagination, searchParams, dispatch, const columns = [ { title: '账号', - dataIndex: 'username' + dataIndex: 'username', }, { title: '员工姓名', dataIndex: 'nickname', }, + { + title: '部门', + dataIndex: 'deptment.name', + }, { title: '角色', dataIndex: 'roles', @@ -85,8 +111,8 @@ function List ({ dataSource, loading, pagination, searchParams, dispatch, text += roles[i].name; } } - return ({text}); - } + return {text}; + }, }, { title: '状态', @@ -114,30 +140,30 @@ function List ({ dataSource, loading, pagination, searchParams, dispatch, handleStatus(record)}> {statusText} - { - record.status === 2 ? - - - handleDelete(record)}> - 删除 - - : null - } + {record.status === 2 ? ( + + + handleDelete(record)}> + 删除 + + + ) : null} ); }, }, ]; - function onPageChange(page) { // 翻页 + function onPageChange(page) { + // 翻页 dispatch({ type: 'adminList/query', payload: { pageNo: page.current, pageSize: page.pageSize, - ...searchParams - } - }) + ...searchParams, + }, + }); } return ( @@ -149,7 +175,7 @@ function List ({ dataSource, loading, pagination, searchParams, dispatch, pagination={pagination} onChange={onPageChange} /> - ) + ); } // 搜索表单 @@ -157,17 +183,23 @@ const SearchForm = Form.create()(props => { const { form, form: { getFieldDecorator }, - dispatch + dispatch, + deptSelectTree, } = props; function search() { + const fields = form.getFieldsValue(); + if (fields.deptmentId) { + const deptmentId = fields.deptmentId.split('-')[1]; + fields.deptmentId = deptmentId; + } dispatch({ type: 'adminList/query', payload: { ...PaginationHelper.defaultPayload, - ...form.getFieldsValue() - } - }) + ...fields, + }, + }); } // 提交搜索 @@ -189,20 +221,36 @@ const SearchForm = Form.create()(props => { return (
- + - {getFieldDecorator('nickname')()} + {getFieldDecorator('nickname')()} - - - - - + + + {getFieldDecorator('deptmentId', { + rules: [{ required: true, message: '请选择部门' }], + })( + + )} + + + + + + + +
@@ -211,12 +259,24 @@ const SearchForm = Form.create()(props => { // 添加 or 修改 Form 表单 const AddOrUpdateForm = Form.create()(props => { - const { dispatch, modalVisible, form, handleModalVisible, modalType, formVals } = props; + const { + dispatch, + modalVisible, + form, + handleModalVisible, + modalType, + formVals, + deptSelectTree, + } = props; const okHandle = () => { form.validateFields((err, fields) => { if (err) return; // 添加表单 + if (fields.deptmentId) { + const deptmentId = fields.deptmentId.split('-')[1]; + fields.deptmentId = deptmentId; + } if (modalType === 'add') { dispatch({ type: 'adminList/add', @@ -264,29 +324,52 @@ const AddOrUpdateForm = Form.create()(props => { title={title} visible={modalVisible} onOk={okHandle} - okText='保存' + okText="保存" onCancel={() => handleModalVisible()} > {form.getFieldDecorator('username', { - rules: [{ required: true, message: '请输入账号!'}, - {max: 16, min:6, message: '长度为 6-16 位'}, - { validator: (rule, value, callback) => checkTypeWithEnglishAndNumbers(rule, value, callback, '数字以及字母')} + rules: [ + { required: true, message: '请输入账号!' }, + { max: 16, min: 6, message: '长度为 6-16 位' }, + { + validator: (rule, value, callback) => + checkTypeWithEnglishAndNumbers(rule, value, callback, '数字以及字母'), + }, ], initialValue: formVals.username, })()} {form.getFieldDecorator('nickname', { - rules: [{ required: true, message: '请输入员工姓名!'}, - {max: 10, message: '姓名最大长度为 10'}], + rules: [ + { required: true, message: '请输入员工姓名!' }, + { max: 10, message: '姓名最大长度为 10' }, + ], initialValue: formVals.nickname, })()} + + {form.getFieldDecorator('deptmentId', { + rules: [{ required: true, message: '请选择部门' }], + initialValue: + formVals.deptmentId && formVals.deptmentId !== 0 ? formVals.deptmentId : null, + })( + + )} + {form.getFieldDecorator('password', { - rules: [{ required: modalType === 'add', message: '请填写密码'}, // 添加时,必须输入密码 - {max: 16, min: 6, message: '长度为 6-18 位'}], + rules: [ + { required: modalType === 'add', message: '请填写密码' }, // 添加时,必须输入密码 + { max: 16, min: 6, message: '长度为 6-18 位' }, + ], initialValue: formVals.password, })()} @@ -321,7 +404,8 @@ const RoleAssignModal = Form.create()(props => { const renderTreeNodes = data => { return data.map(item => { - if (item.children) { // 递归拼接节点 + if (item.children) { + // 递归拼接节点 return ( {renderTreeNodes(item.children)} @@ -387,32 +471,31 @@ const RoleAssignModal = Form.create()(props => { onOk={okHandle} onCancel={() => handleModalVisible()} > - - {renderModalContent(treeData)} - + {renderModalContent(treeData)} ); }); - @connect(({ adminList }) => ({ // list: adminList.list, // pagination: adminList.pagination, ...adminList, })) - // 主界面 @Form.create() class AdminList extends PureComponent { - componentDidMount() { const { dispatch } = this.props; dispatch({ type: 'adminList/query', payload: { - ...PaginationHelper.defaultPayload + ...PaginationHelper.defaultPayload, }, }); + dispatch({ + type: 'adminList/getDeptmentTree', + payload: {}, + }); } handleModalVisible = (modalVisible, modalType, record) => { @@ -422,7 +505,7 @@ class AdminList extends PureComponent { payload: { modalVisible, modalType, - formVals: record || {} + formVals: record || {}, }, }); }; @@ -433,18 +516,29 @@ class AdminList extends PureComponent { type: 'adminList/setAll', payload: { roleModalVisible: roleModalVisible, - formVals: record || {} + formVals: record || {}, }, }); }; render() { // let that = this; - const { dispatch, - list, listLoading, searchParams, pagination, - modalVisible, modalType, formVals, + const { + dispatch, + list, + listLoading, + searchParams, + pagination, + modalVisible, + modalType, + formVals, confirmLoading, - roleList, roleModalVisible, roleAssignLoading, roleCheckedKeys } = this.props; + roleList, + roleModalVisible, + roleAssignLoading, + roleCheckedKeys, + deptSelectTree, + } = this.props; // 列表属性 const listProps = { @@ -461,6 +555,7 @@ class AdminList extends PureComponent { // 搜索表单属性 const searchFormProps = { dispatch, + deptSelectTree, }; // 添加 or 更新表单属性 @@ -469,6 +564,7 @@ class AdminList extends PureComponent { modalType, formVals, dispatch, + deptSelectTree, handleModalVisible: this.handleModalVisible, // Function }; diff --git a/docs/sql/mall_admin.sql b/docs/sql/mall_admin.sql index 2eb9e7227..f7083d39e 100644 --- a/docs/sql/mall_admin.sql +++ b/docs/sql/mall_admin.sql @@ -50,6 +50,7 @@ CREATE TABLE `admin` ( `nickname` varchar(10) NOT NULL COMMENT '昵称', `password` varchar(32) NOT NULL COMMENT '密码\n *\n * TODO 芋艿 暂时最简单的 MD5', `status` tinyint(11) NOT NULL COMMENT '账号状态', + `deptment_id` int(11) DEFAULT 0 NOT NULL '部门id', `create_time` datetime NOT NULL COMMENT '创建时间', `update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `deleted` bit(1) DEFAULT NULL, diff --git a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/AdminController.java b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/AdminController.java index 8b874d5ac..36754ec2c 100644 --- a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/AdminController.java +++ b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/controller/admins/AdminController.java @@ -5,8 +5,10 @@ import cn.iocoder.common.framework.util.CollectionUtil; import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.common.framework.vo.PageResult; import cn.iocoder.mall.admin.api.AdminService; +import cn.iocoder.mall.admin.api.DeptmentService; import cn.iocoder.mall.admin.api.ResourceService; import cn.iocoder.mall.admin.api.RoleService; +import cn.iocoder.mall.admin.api.bo.deptment.DeptmentBO; import cn.iocoder.mall.admin.api.bo.resource.ResourceBO; import cn.iocoder.mall.admin.api.bo.role.RoleBO; import cn.iocoder.mall.admin.api.bo.admin.AdminBO; @@ -23,6 +25,7 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiOperation; import org.apache.dubbo.config.annotation.Reference; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.util.*; @@ -44,6 +47,9 @@ public class AdminController { @Reference(validation = "true", version = "${dubbo.provider.RoleService.version}") private RoleService roleService; + @Autowired + private DeptmentService deptmentService; + // =========== 当前管理员相关的资源 API =========== // TODO 功能:当前管理员 @@ -97,7 +103,17 @@ public class AdminController { // 查询角色数组 Map> roleMap = adminService.getAdminRolesMap(CollectionUtil.convertList(resultPage.getList(), AdminBO::getId)); resultPage.getList().forEach(admin -> admin.setRoles(AdminConvert.INSTANCE.convertAdminVORoleList(roleMap.get(admin.getId())))); + + // 查询对应部门 + List deptmentBOS = deptmentService.getAllDeptments(); + Map deptNameMap = deptmentBOS.stream().collect(Collectors.toMap(d->d.getId(), d->d.getName())); + //管理员所在部门被删后,变成未分配状态 + deptNameMap.put(0, "未分配"); + resultPage.getList().forEach(admin->{ + admin.setDeptment(new AdminVO.Deptment(admin.getDeptmentId(), deptNameMap.get(admin.getDeptmentId()))); + }); } + return success(resultPage); } diff --git a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/admin/AdminVO.java b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/admin/AdminVO.java index 086e4266e..6847d1829 100644 --- a/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/admin/AdminVO.java +++ b/system/system-application/src/main/java/cn/iocoder/mall/admin/application/vo/admin/AdminVO.java @@ -3,6 +3,7 @@ package cn.iocoder.mall.admin.application.vo.admin; import cn.iocoder.mall.admin.api.bo.admin.AdminBO; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; import lombok.Data; import lombok.experimental.Accessors; @@ -15,6 +16,8 @@ public class AdminVO extends AdminBO { private List roles; + private Deptment deptment; + @ApiModel("管理员 VO - 角色") @Data @Accessors(chain = true) @@ -28,4 +31,19 @@ public class AdminVO extends AdminBO { } + @ApiModel("管理员 VO - 部门") + @Data + @Accessors(chain = true) + @AllArgsConstructor + public static class Deptment { + + @ApiModelProperty(value = "部门编号", required = true, example = "1") + private Integer id; + + @ApiModelProperty(value = "部门名称", required = true, example = "研发部") + private String name; + + + } + } diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/admin/AdminBO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/admin/AdminBO.java index 88dbb3428..b348f2c3d 100644 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/admin/AdminBO.java +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/bo/admin/AdminBO.java @@ -28,4 +28,7 @@ public class AdminBO implements Serializable { @ApiModelProperty(value = "创建时间", required = true, example = "时间戳格式") private Date createTime; + @ApiModelProperty(value = "部门ID", required = true, example = "1") + private Integer deptmentId; + } diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/admin/AdminAddDTO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/admin/AdminAddDTO.java index 79ed25335..748b77399 100644 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/admin/AdminAddDTO.java +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/admin/AdminAddDTO.java @@ -7,6 +7,7 @@ import lombok.experimental.Accessors; import org.hibernate.validator.constraints.Length; import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; import javax.validation.constraints.Pattern; import java.io.Serializable; @@ -31,4 +32,8 @@ public class AdminAddDTO implements Serializable { @Length(min = 4, max = 16, message = "密码长度为 4-16 位") private String password; + @ApiModelProperty(value = "部门ID", required = true, example = "1") + @NotNull(message = "部门不能为空") + private Integer deptmentId; + } diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/admin/AdminPageDTO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/admin/AdminPageDTO.java index 923890f56..86062413d 100644 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/admin/AdminPageDTO.java +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/admin/AdminPageDTO.java @@ -17,4 +17,8 @@ public class AdminPageDTO extends PageParam { @ApiModelProperty(value = "昵称,模糊匹配", example = "小王") private String nickname; + + @ApiModelProperty(value = "所在部门ID") + private Integer deptmentId; + } diff --git a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/admin/AdminUpdateDTO.java b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/admin/AdminUpdateDTO.java index 5fac82467..c88c6e05b 100644 --- a/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/admin/AdminUpdateDTO.java +++ b/system/system-service-api/src/main/java/cn/iocoder/mall/admin/api/dto/admin/AdminUpdateDTO.java @@ -35,4 +35,8 @@ public class AdminUpdateDTO implements Serializable { @Length(min = 4, max = 16, message = "密码长度为 4-16 位") private String password; + @ApiModelProperty(value = "部门ID", required = true, example = "1") + @NotNull(message = "部门不能为空") + private Integer deptmentId; + } diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/AdminMapper.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/AdminMapper.java index 49e049537..a15c940cd 100644 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/AdminMapper.java +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dao/AdminMapper.java @@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import org.apache.ibatis.annotations.Param; +import org.omg.PortableInterceptor.INACTIVE; import org.springframework.stereotype.Repository; @Repository @@ -19,7 +20,14 @@ public interface AdminMapper extends BaseMapper { default IPage selectPage(AdminPageDTO adminPageDTO) { return selectPage(new Page<>(adminPageDTO.getPageNo(), adminPageDTO.getPageSize()), - new QueryWrapperX().likeIfPresent("nickname", adminPageDTO.getNickname())); + new QueryWrapperX().likeIfPresent("nickname", adminPageDTO.getNickname()) + .eqIfPresent("deptment_id", adminPageDTO.getDeptmentId())); + } + + default int updateDeptByDeptId(@Param("fromDeptId")Integer fromDeptId, @Param("toDeptId")Integer toDeptId){ + QueryWrapper query = new QueryWrapper() + .eq("deptment_id", fromDeptId); + return update(new AdminDO().setDeptmentId(toDeptId), query); } } diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/AdminDO.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/AdminDO.java index 08b030628..88f7643d6 100644 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/AdminDO.java +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/dataobject/AdminDO.java @@ -36,6 +36,12 @@ public class AdminDO extends DeletableDO { */ private Integer status; + /** + * 管理员部门id + */ + private Integer deptmentId; + + // TODO 芋艿,最后登陆时间、最后登陆 IP // TODO 芋艿,登陆日志 diff --git a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/DeptmentServiceImpl.java b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/DeptmentServiceImpl.java index d7ec20235..2a02040cb 100644 --- a/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/DeptmentServiceImpl.java +++ b/system/system-service-impl/src/main/java/cn/iocoder/mall/admin/service/DeptmentServiceImpl.java @@ -11,6 +11,7 @@ import cn.iocoder.mall.admin.api.dto.depetment.DeptmentAddDTO; import cn.iocoder.mall.admin.api.dto.depetment.DeptmentPageDTO; import cn.iocoder.mall.admin.api.dto.depetment.DeptmentUpdateDTO; import cn.iocoder.mall.admin.convert.DeptmentConvert; +import cn.iocoder.mall.admin.dao.AdminMapper; import cn.iocoder.mall.admin.dao.DeptmentMapper; import cn.iocoder.mall.admin.dao.DeptmentRoleMapper; import cn.iocoder.mall.admin.dataobject.DeptmentDO; @@ -39,6 +40,9 @@ public class DeptmentServiceImpl implements DeptmentService { @Autowired private DeptmentRoleMapper deptmentRoleMapper; + @Autowired + private AdminMapper adminMapper; + @Override public DeptmentBO addDeptment(Integer adminId, DeptmentAddDTO deptmentAddDTO) { if (deptmentAddDTO.getPid() != 0 && @@ -69,6 +73,8 @@ public class DeptmentServiceImpl implements DeptmentService { deptmentRoleMapper.deleteByDeptmentId(deptmentId); + //将改部门下所有员工的DeptmentID设置为0 + adminMapper.updateDeptByDeptId(deptmentId, 0); return true; }