From 3e56ecdfa4ba14eaeac61b6efe75bb9ae0eaadff Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期五, 23 二月 2024 09:29:41 +0800
Subject: [PATCH] #

---
 zy-asrs-flow/src/pages/system/user/components/edit.jsx                                |   16 +++++-----------
 zy-asrs-flow/src/pages/system/operationRecord/components/edit.jsx                     |    2 +-
 zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/system/controller/UserController.java       |   22 ++++++++++++++++++++--
 zy-asrs-framework/src/main/java/com/zy/asrs/framework/generators/BetterGenerator.java |    2 +-
 zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/system/entity/User.java                     |   15 +++++++++++++++
 5 files changed, 42 insertions(+), 15 deletions(-)

diff --git a/zy-asrs-flow/src/pages/system/operationRecord/components/edit.jsx b/zy-asrs-flow/src/pages/system/operationRecord/components/edit.jsx
index d0f6552..2264cec 100644
--- a/zy-asrs-flow/src/pages/system/operationRecord/components/edit.jsx
+++ b/zy-asrs-flow/src/pages/system/operationRecord/components/edit.jsx
@@ -142,7 +142,7 @@
                             debounceTime={300}
                             request={async ({ keyWords }) => {
                                 const resp = await Http.doPostForm('api/user/query', { condition: keyWords });
-                            return resp.data;
+                                return resp.data;
                             }}
                         />
                         <ProFormDateTimePicker
diff --git a/zy-asrs-flow/src/pages/system/user/components/edit.jsx b/zy-asrs-flow/src/pages/system/user/components/edit.jsx
index 52ea22b..906512d 100644
--- a/zy-asrs-flow/src/pages/system/user/components/edit.jsx
+++ b/zy-asrs-flow/src/pages/system/user/components/edit.jsx
@@ -151,16 +151,6 @@
                         />
                     </ProForm.Group>
                     <ProForm.Group>
-                        {/* <ProFormSelect
-                            name="status"
-                            label="鐘舵��"
-                            colProps={{ md: 12, xl: 12 }}
-                            placeholder="璇烽�夋嫨"
-                            options={[
-                                { label: '姝e父', value: 1 },
-                                { label: '绂佺敤', value: 0 },
-                            ]}
-                        /> */}
                         <ProFormRadio.Group
                             name="status"
                             label="鐘舵��"
@@ -177,7 +167,11 @@
                             label="瑙掕壊"
                             colProps={{ md: 12, xl: 12 }}
                             placeholder="璇烽�夋嫨"
-                            rules={[{ required: true, message: '瑙掕壊涓嶈兘涓虹┖!' }]}
+                            rules={[{ required: true, type: 'array', message: '瑙掕壊涓嶈兘涓虹┖!' }]}
+                            request={async ({ keyWords }) => {
+                                const resp = await Http.doPostForm('api/role/query', { condition: keyWords });
+                                return resp.data;
+                            }}
                         />
                     </ProForm.Group>
                     <ProFormTextArea
diff --git a/zy-asrs-framework/src/main/java/com/zy/asrs/framework/generators/BetterGenerator.java b/zy-asrs-framework/src/main/java/com/zy/asrs/framework/generators/BetterGenerator.java
index 7087589..a557854 100644
--- a/zy-asrs-framework/src/main/java/com/zy/asrs/framework/generators/BetterGenerator.java
+++ b/zy-asrs-framework/src/main/java/com/zy/asrs/framework/generators/BetterGenerator.java
@@ -953,7 +953,7 @@
                         .append("                            debounceTime={300}\n")
                         .append("                            request={async ({ keyWords }) => {\n")
                         .append("                                const resp = await Http.doPostForm('api/").append(GeneratorUtils.firstCharConvert(column.getForeignKey())).append("/query', { condition: keyWords });\n")
-                        .append("                            return resp.data;\n")
+                        .append("                                return resp.data;\n")
                         .append("                            }}\n");
             }
 
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 b7a9423..220a56a 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
@@ -64,6 +64,7 @@
     @PreAuthorize("hasAuthority('system:user:save')")
     @OperationLog("娣诲姞鐢ㄦ埛")
     @PostMapping("/user/save")
+    @Transactional
     public R save(@RequestBody User user) {
         if (!Cools.isEmpty(user.getUsername())
                 && userService.count(new LambdaQueryWrapper<User>().eq(User::getUsername, user.getUsername())) > 0) {
@@ -86,14 +87,23 @@
         user.setUpdateTime(new Date());
 
         if (!userService.save(user)) {
-            return R.error("娣诲姞澶辫触");
+            throw new CoolException("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇�");
         }
+
+        userRoleService.remove(new LambdaQueryWrapper<UserRole>().eq(UserRole::getUserId, user.getId()));
+        for (Long roleId : user.getRoleIds()) {
+            if (!userRoleService.save(new UserRole(user.getId(), roleId))) {
+                throw new CoolException("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇�");
+            }
+        }
+
         return R.ok("娣诲姞鎴愬姛");
     }
 
     @PreAuthorize("hasAuthority('system:user:update')")
     @OperationLog("淇敼鐢ㄦ埛")
     @PostMapping("/user/update")
+    @Transactional
     public R update(@RequestBody User user) {
         if (!Cools.isEmpty(user.getUsername()) && userService.count(new LambdaQueryWrapper<User>()
                 .eq(User::getUsername, user.getUsername())
@@ -119,8 +129,16 @@
         user.setUpdateTime(new Date());
 
         if (!userService.updateById(user)) {
-            return R.error("淇敼澶辫触");
+            throw new CoolException("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇�");
         }
+
+        userRoleService.remove(new LambdaQueryWrapper<UserRole>().eq(UserRole::getUserId, user.getId()));
+        for (Long roleId : user.getRoleIds()) {
+            if (!userRoleService.save(new UserRole(user.getId(), roleId))) {
+                throw new CoolException("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇�");
+            }
+        }
+
         return R.ok("淇敼鎴愬姛");
     }
 
diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/system/entity/User.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/system/entity/User.java
index 0cd193d..01d500b 100644
--- a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/system/entity/User.java
+++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/system/entity/User.java
@@ -1,10 +1,12 @@
 package com.zy.asrs.wcs.system.entity;
 
 import com.baomidou.mybatisplus.annotation.*;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.zy.asrs.framework.common.Cools;
 import com.zy.asrs.framework.common.SpringUtils;
 import com.zy.asrs.wcs.system.service.DeptService;
 import com.zy.asrs.wcs.system.service.HostService;
+import com.zy.asrs.wcs.system.service.UserRoleService;
 import com.zy.asrs.wcs.system.service.UserService;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
@@ -165,6 +167,9 @@
     private String memo;
 
     @TableField(exist = false)
+    private Long[] roleIds;
+
+    @TableField(exist = false)
     private List<Role> roles;
 
     @TableField(exist = false)
@@ -322,6 +327,16 @@
         return null;
     }
 
+    public Long[] getRoleIds() {
+        if (Cools.isEmpty((Object) this.roleIds)) {
+            UserRoleService service = SpringUtils.getBean(UserRoleService.class);
+            List<UserRole> list = service.list(new LambdaQueryWrapper<UserRole>().eq(UserRole::getUserId, this.id));
+            return list.stream().map(UserRole::getRoleId).toArray(Long[]::new);
+        } else {
+            return this.roleIds;
+        }
+    }
+
     @Override
     public boolean isAccountNonExpired() {
         return true;

--
Gitblit v1.9.1