From b9efed08b3cf24f3f30b915b17557efd93195940 Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期四, 22 二月 2024 13:54:23 +0800
Subject: [PATCH] #

---
 zy-asrs-framework/src/main/resources/templates/react/Index.txt                  |    3 
 zy-asrs-flow/src/pages/system/role/components/scope.jsx                         |  125 +++++++++++++++++++++++++++++++
 zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/system/controller/RoleController.java |   34 +++++++-
 zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/system/controller/UserController.java |   16 +++
 zy-asrs-flow/src/pages/system/role/index.jsx                                    |   55 +++++++++++++
 5 files changed, 223 insertions(+), 10 deletions(-)

diff --git a/zy-asrs-flow/src/pages/system/role/components/scope.jsx b/zy-asrs-flow/src/pages/system/role/components/scope.jsx
new file mode 100644
index 0000000..84c3b84
--- /dev/null
+++ b/zy-asrs-flow/src/pages/system/role/components/scope.jsx
@@ -0,0 +1,125 @@
+import React, { useState, useRef, useEffect } from 'react';
+import {
+    ProForm,
+    ProFormDigit,
+    ProFormText,
+    ProFormSelect,
+} from '@ant-design/pro-components';
+import { Col, Form, Modal, Row, Checkbox, Skeleton, Tree } from 'antd';
+import Http from '@/utils/http';
+import { transformTreeData, getTreeAllKeys } from '@/utils/tree-util'
+
+const Scope = (props) => {
+    const [form] = Form.useForm();
+    const { } = props;
+    const [menuTreeLoading, setMenuTreeLoading] = useState(false);
+    const [menuTreeData, setMenuTreeData] = useState([]);
+
+    const loadMenuTree = (param) => {
+        setMenuTreeLoading(true);
+        Http.doPostPromise('/api/menu/tree', param, (res) => {
+            setMenuTreeLoading(false);
+            const rootMenu = { id: 0, name: '鍏ㄩ儴', value: 0, children: [] };
+            rootMenu.children = res.data;
+            // const treeData = transformTreeData([rootMenu]);
+            const treeData = transformTreeData(res.data);
+            setMenuTreeData(treeData);
+            // const treeAllKeys = getTreeAllKeys(treeData);
+            // setDeptExpandedKeys(treeAllKeys);
+        }).catch((err) => {
+            console.error(err);
+            setMenuTreeLoading(false);
+        })
+    }
+
+    useEffect(() => {
+        form.resetFields();
+        form.setFieldsValue({
+            ...props.values
+        })
+
+        loadMenuTree();
+    }, [form, props])
+
+    const handleCancel = () => {
+        props.onCancel();
+    };
+
+    const handleOk = () => {
+        form.submit();
+    }
+
+    const handleFinish = async (values) => {
+        props.onSubmit({ ...values });
+    }
+
+    return (
+        <>
+            <Modal
+                title="Scope"
+                width={640}
+                forceRender
+                destroyOnClose
+                open={props.open}
+                onCancel={handleCancel}
+                onOk={handleOk}
+            >
+                <ProForm
+                    form={form}
+                    submitter={false}
+                    onFinish={handleFinish}
+                    layout="horizontal"
+                    grid={true}
+                >
+                    <ProFormDigit
+                        name="id"
+                        disabled
+                        hidden={true}
+                    />
+
+                    <ProForm.Item
+                        name="deptIds"
+                        label="鑿滃崟鏉冮檺"
+                        colProps={{ md: 24, xl: 24 }}
+                    >
+
+                        <Row gutter={[16, 16]}>
+                            <Col md={24}>
+                                <Checkbox.Group
+                                    options={[
+                                        { label: '灞曞紑/鎶樺彔', value: 'deptExpand' },
+                                        { label: '鍏ㄩ��/鍏ㄤ笉閫�', value: 'deptNodeAll' },
+                                    ]}
+                                    onChange={(checkedValue) => {
+                                        console.log(checkedValue);
+                                    }} />
+                            </Col>
+                            <Col md={24}>
+                                {menuTreeLoading ? (
+                                    <Skeleton active />
+                                ) : (
+                                    <Tree
+                                        checkable
+                                        onExpand={(expandedKeys, { expanded, node }) => {
+
+                                        }}
+                                        // expandedKeys={expandedKeys}
+                                        // autoExpandParent={autoExpandParent}
+                                        // onCheck={onCheck}
+                                        // checkedKeys={checkedKeys}
+                                        // onSelect={onSelect}
+                                        // selectedKeys={selectedKeys}
+                                        treeData={menuTreeData}
+                                    />
+                                )}
+                            </Col>
+                        </Row>
+
+                    </ProForm.Item>
+                </ProForm>
+            </Modal>
+        </>
+    )
+}
+
+export default Scope;
\ No newline at end of file
diff --git a/zy-asrs-flow/src/pages/system/role/index.jsx b/zy-asrs-flow/src/pages/system/role/index.jsx
index 19ffeff..c1485b1 100644
--- a/zy-asrs-flow/src/pages/system/role/index.jsx
+++ b/zy-asrs-flow/src/pages/system/role/index.jsx
@@ -10,6 +10,7 @@
 import { PlusOutlined, ExportOutlined } from '@ant-design/icons';
 import Http from '@/utils/http';
 import Edit from './components/edit'
+import Scope from './components/scope'
 import { TextFilter, SelectFilter, DatetimeRangeFilter, LinkFilter } from '@/components/TableSearch'
 import { statusMap } from '@/utils/enum-util'
 
@@ -87,6 +88,24 @@
     }
 };
 
+const handleScope = async (val) => {
+    const hide = message.loading('姝e湪鍒嗛厤');
+    try {
+        const resp = await Http.doPost('api/role/scope', val);
+        if (resp.code === 200) {
+            message.success('鍒嗛厤鎴愬姛');
+            return true;
+        } else {
+            message.error(resp.msg);
+            return false;
+        }
+    } catch (error) {
+        message.error('鍒嗛厤澶辫触璇烽噸璇曪紒');
+        return false;
+    } finally {
+        hide();
+    }
+};
 
 const Main = () => {
     const formTableRef = useRef();
@@ -95,6 +114,8 @@
     const [modalVisible, setModalVisible] = useState(false);
     const [currentRow, setCurrentRow] = useState();
     const [searchParam, setSearchParam] = useState({});
+
+    const [scopeModalVisible, setScopeModalVisible] = useState(false);
 
     useEffect(() => {
 
@@ -180,6 +201,16 @@
             width: 140,
             valueType: 'option',
             render: (_, record) => [
+                <Button
+                    type="link"
+                    key="scope"
+                    onClick={() => {
+                        setScopeModalVisible(true);
+                        setCurrentRow(record);
+                    }}
+                >
+                    鍒嗛厤鏉冮檺
+                </Button>,
                 <Button
                     type="link"
                     key="edit"
@@ -356,6 +387,30 @@
                 }
                 }
             />
+
+            <Scope
+                open={scopeModalVisible}
+                values={currentRow || {}}
+                onCancel={
+                    () => {
+                        setScopeModalVisible(false);
+                        setCurrentRow(undefined);
+                    }
+                }
+                onSubmit={async (values) => {
+                    let ok = false;
+                    if (values.id) {
+                        ok = await handleScope({ ...values })
+                    }
+                    if (ok) {
+                        setScopeModalVisible(false);
+                        setCurrentRow(undefined);
+                        if (actionRef.current) {
+                            actionRef.current.reload();
+                        }
+                    }
+                }}
+            />
         </PageContainer>
     );
 };
diff --git a/zy-asrs-framework/src/main/resources/templates/react/Index.txt b/zy-asrs-framework/src/main/resources/templates/react/Index.txt
index a0ecaa8..c68da77 100644
--- a/zy-asrs-framework/src/main/resources/templates/react/Index.txt
+++ b/zy-asrs-framework/src/main/resources/templates/react/Index.txt
@@ -287,8 +287,7 @@
                             actionRef.current.reload();
                         }
                     }
-                }
-                }
+                }}
             />
         </PageContainer>
     );
diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/system/controller/RoleController.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/system/controller/RoleController.java
index 574cdd7..7907f50 100644
--- a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/system/controller/RoleController.java
+++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/system/controller/RoleController.java
@@ -4,22 +4,23 @@
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.zy.asrs.framework.common.Cools;
 import com.zy.asrs.framework.common.R;
+import com.zy.asrs.framework.exception.CoolException;
 import com.zy.asrs.wcs.common.annotation.OperationLog;
 import com.zy.asrs.wcs.common.domain.BaseParam;
 import com.zy.asrs.wcs.common.domain.KeyValVo;
 import com.zy.asrs.wcs.common.domain.PageParam;
 import com.zy.asrs.wcs.system.entity.Role;
+import com.zy.asrs.wcs.system.entity.RoleMenu;
+import com.zy.asrs.wcs.system.service.RoleMenuService;
 import com.zy.asrs.wcs.system.service.RoleService;
 import com.zy.asrs.wcs.utils.ExcelUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletResponse;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 
 /**
  * Created by vincent on 2/13/2024
@@ -30,6 +31,8 @@
 
     @Autowired
     private RoleService roleService;
+    @Autowired
+    private RoleMenuService roleMenuService;
 
     @PreAuthorize("hasAuthority('system:role:list')")
     @PostMapping("/role/page")
@@ -63,6 +66,8 @@
                 && roleService.count(new LambdaQueryWrapper<Role>().eq(Role::getCode, role.getCode())) > 0) {
             return R.error("瑙掕壊鏍囪瘑宸插瓨鍦�");
         }
+        role.setCreateTime(new Date());
+        role.setUpdateTime(new Date());
         if (!roleService.save(role)) {
             return R.error("娣诲姞澶辫触");
         }
@@ -83,6 +88,7 @@
                 .ne(Role::getId, role.getId())) > 0) {
             return R.error("瑙掕壊鍚嶇О宸插瓨鍦�");
         }
+        role.setUpdateTime(new Date());
         if (!roleService.updateById(role)) {
             return R.error("淇敼澶辫触");
         }
@@ -92,9 +98,15 @@
     @PreAuthorize("hasAuthority('system:role:remove')")
     @OperationLog("鍒犻櫎瑙掕壊")
     @PostMapping("/role/remove/{ids}")
+    @Transactional
     public R remove(@PathVariable Long[] ids) {
-        if (!roleService.removeByIds(Arrays.asList(ids))) {
-            return R.error("鍒犻櫎澶辫触");
+        for (Long roleId : ids) {
+            if (!roleService.removeById(roleId)) {
+                throw new CoolException("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇�");
+            }
+            if (!roleMenuService.remove(new LambdaQueryWrapper<RoleMenu>().eq(RoleMenu::getRoleId, roleId))) {
+                throw new CoolException("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇�");
+            }
         }
         return R.ok("鍒犻櫎鎴愬姛");
     }
@@ -119,4 +131,14 @@
         ExcelUtil.build(ExcelUtil.create(roleService.list(), Role.class), response);
     }
 
+    @PreAuthorize("hasAuthority('system:role:update')")
+    @OperationLog("鍒嗛厤鏉冮檺")
+    @PostMapping("/role/scope")
+    public R scope(@RequestBody Role role) {
+
+        
+
+        return R.ok("鍒嗛厤鎴愬姛");
+    }
+
 }
diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/system/controller/UserController.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/system/controller/UserController.java
index c1dcd49..b7a9423 100644
--- a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/system/controller/UserController.java
+++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/system/controller/UserController.java
@@ -4,15 +4,19 @@
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.zy.asrs.framework.common.Cools;
 import com.zy.asrs.framework.common.R;
+import com.zy.asrs.framework.exception.CoolException;
 import com.zy.asrs.wcs.common.annotation.OperationLog;
 import com.zy.asrs.wcs.common.domain.BaseParam;
 import com.zy.asrs.wcs.common.domain.KeyValVo;
 import com.zy.asrs.wcs.common.domain.PageParam;
 import com.zy.asrs.wcs.system.entity.User;
+import com.zy.asrs.wcs.system.entity.UserRole;
+import com.zy.asrs.wcs.system.service.UserRoleService;
 import com.zy.asrs.wcs.system.service.UserService;
 import com.zy.asrs.wcs.utils.ExcelUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletResponse;
@@ -26,6 +30,8 @@
 
     @Autowired
     private UserService userService;
+    @Autowired
+    private UserRoleService userRoleService;
 
     @PreAuthorize("hasAuthority('system:user:list')")
     @PostMapping("/user/page")
@@ -121,9 +127,15 @@
     @PreAuthorize("hasAuthority('system:user:remove')")
     @OperationLog("鍒犻櫎鐢ㄦ埛")
     @PostMapping("/user/remove/{ids}")
+    @Transactional
     public R remove(@PathVariable Long[] ids) {
-        if (!userService.removeByIds(Arrays.asList(ids))) {
-            return R.error("鍒犻櫎澶辫触");
+        for (Long userId : ids) {
+            if (!userService.removeById(userId)) {
+                throw new CoolException("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇�");
+            }
+            if (!userRoleService.remove(new LambdaQueryWrapper<UserRole>().eq(UserRole::getUserId, userId))) {
+                throw new CoolException("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇�");
+            }
         }
         return R.ok("鍒犻櫎鎴愬姛");
     }

--
Gitblit v1.9.1