Преглед на файлове

用户模块

tags/正式3.2.0
王宁 преди 2 години
родител
ревизия
a543736a54

+ 30
- 0
gateway/src/main/java/com/xhkjedu/gateway/config/CorsConfig.java Целия файл

@@ -0,0 +1,30 @@
1
+package com.xhkjedu.gateway.config;
2
+
3
+import org.springframework.context.annotation.Bean;
4
+import org.springframework.context.annotation.Configuration;
5
+import org.springframework.web.cors.CorsConfiguration;
6
+import org.springframework.web.cors.reactive.CorsWebFilter;
7
+import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;
8
+import org.springframework.web.util.pattern.PathPatternParser;
9
+
10
+/**
11
+ * @ClassName CorsConfig
12
+ * Description TODO
13
+ * Author WN
14
+ * Date 2022/2/23 17:00
15
+ **/
16
+@Configuration
17
+public class CorsConfig {
18
+    @Bean
19
+    public CorsWebFilter corsFilter() {
20
+        CorsConfiguration config = new CorsConfiguration();
21
+        config.addAllowedMethod("*");
22
+        config.addAllowedOrigin("*");
23
+        config.addAllowedHeader("*");
24
+
25
+        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(new PathPatternParser());
26
+        source.registerCorsConfiguration("/**", config);
27
+
28
+        return new CorsWebFilter(source);
29
+    }
30
+}

+ 103
- 0
sapi/src/main/java/com/xhkjedu/sapi/controller/system/UserModuleController.java Целия файл

@@ -0,0 +1,103 @@
1
+package com.xhkjedu.sapi.controller.system;
2
+
3
+import com.xhkjedu.sapi.model.system.TUserModule;
4
+import com.xhkjedu.sapi.service.system.UserModuleService;
5
+import com.xhkjedu.utils.N_Utils;
6
+import com.xhkjedu.vo.ResultVo;
7
+import com.xhkjedu.sapi.vo.system.UserModuleVo;
8
+import org.springframework.beans.factory.annotation.Autowired;
9
+import org.springframework.web.bind.annotation.PostMapping;
10
+import org.springframework.web.bind.annotation.RequestBody;
11
+import org.springframework.web.bind.annotation.RequestMapping;
12
+import org.springframework.web.bind.annotation.RestController;
13
+
14
+import java.util.List;
15
+
16
+/**
17
+ * @ClassName UserModuleController
18
+ * Description 用户常用应用
19
+ * Author WN
20
+ * Date 2020/6/15 15:06
21
+ **/
22
+@RestController
23
+@RequestMapping("/umodule")
24
+public class UserModuleController {
25
+
26
+    @Autowired
27
+    private UserModuleService userModuleService;
28
+
29
+    //用户常用应用集合
30
+    @PostMapping("/list")
31
+    public ResultVo listModules(@RequestBody TUserModule userModule){
32
+        N_Utils.validation(new Object[]{userModule.getUserid(),"用户id",1});
33
+        List<UserModuleVo> lst = userModuleService.listUserModules(userModule.getUserid());
34
+        return new ResultVo(0,"获取用户常用应用成功",lst);
35
+    }
36
+
37
+
38
+
39
+    /**
40
+     *功能描述 保存
41
+     * @author WN
42
+     * @date 2020/6/11
43
+     * @param  * @param module
44
+     * @return com.xhkjedu.vo.ResultVo
45
+     */
46
+    @PostMapping("/save")
47
+    public ResultVo save(@RequestBody TUserModule userModule){
48
+        N_Utils.validation(new Object[]{
49
+                userModule.getUserid(),"用户id",1,
50
+                userModule.getSchoolid(),"学校id",1
51
+        });
52
+        /*if(userModule.getModuleids()==null || userModule.getModuleids().size()==0){
53
+            return new ResultVo(1,"请选择常用应用");
54
+        }else{
55
+
56
+        }*/
57
+        int result = 0;
58
+        try {
59
+            result = userModuleService.save(userModule);
60
+        } catch (Exception e) {
61
+            return new ResultVo(1, "保存失败");
62
+        }
63
+        if (result > 0) {
64
+            return new ResultVo(0, "保存成功");
65
+        }else{
66
+            return new ResultVo(1, "保存失败");
67
+        }
68
+    }
69
+
70
+    /**
71
+     *功能描述 修改排序
72
+     * @author WN
73
+     * @date 2020/6/11
74
+     * @param  * @param module
75
+     * @return com.xhkjedu.vo.ResultVo
76
+     */
77
+    @PostMapping("/up")
78
+    public ResultVo update(@RequestBody TUserModule userModule){
79
+        N_Utils.validation(new Object[]{
80
+                userModule.getUmid(),"用户应用id",1,
81
+                userModule.getUmorder(),"应用显示顺序",1
82
+        });
83
+        int result = userModuleService.updateOrder(userModule);
84
+        if (result > 0) return new ResultVo(0,"修改成功");
85
+        else return new ResultVo(1,"修改失败");
86
+    }
87
+
88
+    /**
89
+     *功能描述  删除
90
+     * @author WN
91
+     * @date 2020/6/11
92
+     * @param  * @param module
93
+     * @return com.xhkjedu.vo.ResultVo
94
+     */
95
+    @PostMapping("/del")
96
+    public ResultVo del(@RequestBody TUserModule userModule) {
97
+        if (!N_Utils.isTrueInteger(userModule.getUmid()))
98
+            return new ResultVo(1,"未选择删除的常用应用");
99
+        int result = userModuleService.del(userModule.getUmid());
100
+        if (result > 0) return new ResultVo(0,"删除成功");
101
+        else return new ResultVo(1,"删失败");
102
+    }
103
+}

+ 60
- 0
sapi/src/main/java/com/xhkjedu/sapi/mapper/system/UserModuleMapper.java Целия файл

@@ -0,0 +1,60 @@
1
+package com.xhkjedu.sapi.mapper.system;
2
+
3
+import com.xhkjedu.sapi.base.TkMapper;
4
+import com.xhkjedu.sapi.model.system.TUserModule;
5
+import com.xhkjedu.sapi.vo.system.UserModuleVo;
6
+import org.apache.ibatis.annotations.Param;
7
+import org.springframework.stereotype.Repository;
8
+
9
+import java.util.List;
10
+
11
+/**
12
+ * @ClassName UserModuleMapper
13
+ * Description 用户常用模块
14
+ * Author WN
15
+ * Date 2020/6/15 14:51
16
+ **/
17
+@Repository
18
+public interface UserModuleMapper extends TkMapper<TUserModule> {
19
+
20
+    /**
21
+     *功能描述  获取用户常用模块
22
+     * @author WN
23
+     * @date 2020/6/15
24
+     * @param  * @param userid
25
+     * @return java.util.List<com.xhkjedu.vo.system.RoleModuleVo>
26
+     */
27
+    List<UserModuleVo> listUserModules(@Param("userid") Integer userid);
28
+
29
+    /**
30
+     *功能描述 批量保存用户模块信息
31
+     * @author WN
32
+     * @date 2020/6/15
33
+     * @param  * @param list
34
+     * @return void
35
+     */
36
+    Integer saveBathUserModule(@Param("list") List<TUserModule> list);
37
+
38
+    /**
39
+     *功能描述 根据用户删除常用应用
40
+     * @author WN
41
+     * @date 2020/6/15
42
+     * @param  * @param userid
43
+     * @return void
44
+     */
45
+    void deleteByUserid(@Param("userid") Integer userid);
46
+
47
+    /**
48
+     * @author ywx
49
+     * @description 获取有常用模块的用户id集合
50
+     * @date 2020/7/9 20:55
51
+     **/
52
+    List<Integer> listUserId(@Param("roleid") Integer roleid);
53
+
54
+    /**
55
+     * @author ywx
56
+     * @description 根据用户id删除没有权限的常用模块
57
+     * @date 2020/7/9 20:55
58
+     **/
59
+    Integer deleteNoRoleByUserId(@Param("userid") Integer userid);
60
+}

+ 78
- 0
sapi/src/main/java/com/xhkjedu/sapi/service/system/UserModuleService.java Целия файл

@@ -0,0 +1,78 @@
1
+package com.xhkjedu.sapi.service.system;
2
+
3
+import com.xhkjedu.sapi.mapper.system.UserModuleMapper;
4
+import com.xhkjedu.sapi.model.system.TUserModule;
5
+import com.xhkjedu.utils.N_Utils;
6
+import com.xhkjedu.sapi.vo.system.UserModuleVo;
7
+import lombok.extern.slf4j.Slf4j;
8
+import org.springframework.beans.BeanUtils;
9
+import org.springframework.beans.factory.annotation.Autowired;
10
+import org.springframework.stereotype.Service;
11
+import org.springframework.transaction.annotation.Transactional;
12
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
13
+
14
+import java.util.ArrayList;
15
+import java.util.List;
16
+
17
+/**
18
+ * @ClassName UserModuleService
19
+ * Description 用户常用模块
20
+ * Author WN
21
+ * Date 2020/6/15 14:58
22
+ **/
23
+@Service
24
+@Slf4j
25
+public class UserModuleService {
26
+    @Autowired
27
+    private UserModuleMapper userModuleMapper;
28
+
29
+    //用户常用模块集合
30
+    public List<UserModuleVo> listUserModules(Integer userid){
31
+        return userModuleMapper.listUserModules(userid);
32
+    }
33
+
34
+    //保存
35
+    @Transactional(rollbackFor = Exception.class)
36
+    public Integer save(TUserModule userModule) throws Exception {
37
+        try {
38
+            userModule.setCreatetime(N_Utils.getSecondTimestamp());
39
+            //先删除已存在
40
+            userModuleMapper.deleteByUserid(userModule.getUserid());
41
+            if(userModule.getModuleids()!=null && userModule.getModuleids().size()>0){
42
+                return saveUserModule(userModule.getModuleids(),userModule);
43
+            }else{
44
+                return 1;
45
+            }
46
+
47
+        } catch (Exception e) {
48
+            log.error("用户模块保存失败:"+e.getMessage());
49
+            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
50
+            throw new Exception("用户模块保存失败");
51
+        }
52
+    }
53
+
54
+    //批量保存用户模块信息
55
+    private Integer saveUserModule(List<String> moduleids,TUserModule userModule){
56
+        List<TUserModule> lst = new ArrayList<>();
57
+        for(int i=0;i<moduleids.size();i++){
58
+            TUserModule um = new TUserModule();
59
+            BeanUtils.copyProperties(userModule,um);
60
+            um.setModuleid(moduleids.get(i));
61
+            um.setUmorder(i+1);
62
+
63
+            lst.add(um);
64
+        }
65
+        //批量保存
66
+        return userModuleMapper.saveBathUserModule(lst);
67
+    }
68
+
69
+    //修改
70
+    public Integer updateOrder(TUserModule userModule){
71
+        return userModuleMapper.updateByPrimaryKeySelective(userModule);
72
+    }
73
+
74
+    //删除
75
+    public Integer del(Integer umid){
76
+        return userModuleMapper.deleteByPrimaryKey(umid);
77
+    }
78
+}

+ 33
- 0
sapi/src/main/java/com/xhkjedu/sapi/vo/system/UserModuleVo.java Целия файл

@@ -0,0 +1,33 @@
1
+package com.xhkjedu.sapi.vo.system;
2
+
3
+import lombok.Data;
4
+
5
+/**
6
+ * @ClassName RoleModuleVo
7
+ * Description 角色模块表
8
+ * Author WN
9
+ * Date 2020/6/15 14:18
10
+ **/
11
+@Data
12
+public class UserModuleVo {
13
+    //用户常用应用
14
+    private Integer umid;
15
+
16
+    private String moduleid;
17
+
18
+    //模块名称
19
+    private String modulename;
20
+
21
+    //模块简称
22
+    private String mabbrevname;
23
+
24
+    //模块地址
25
+    private String moduleurl;
26
+
27
+    //图标地址
28
+    private String moduleico;
29
+
30
+    //内外部应用1内容应用2外部应用
31
+    private Integer minout;
32
+
33
+}

+ 35
- 0
sapi/src/main/resources/mapper/system/UserModuleMapper.xml Целия файл

@@ -0,0 +1,35 @@
1
+<?xml version="1.0" encoding="UTF-8" ?>
2
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3
+<mapper namespace="com.xhkjedu.sapi.mapper.system.UserModuleMapper">
4
+    <!-- 用户常用模块列表 -->
5
+    <select id="listUserModules" resultType="com.xhkjedu.sapi.vo.system.UserModuleVo">
6
+        SELECT um.umid, um.moduleid,m.modulename,m.moduleurl,m.moduleico,m.minout,m.mabbrevname
7
+        FROM t_user_module um LEFT JOIN t_module m ON um.moduleid=m.moduleid
8
+        WHERE um.userid=#{userid} and m.display=1 ORDER BY um.umorder
9
+    </select>
10
+
11
+    <!-- 批量保存用户常用模块 -->
12
+    <insert id="saveBathUserModule">
13
+        INSERT INTO t_user_module (userid,moduleid,umorder,createtime,schoolid) VALUES
14
+        <foreach collection ="list" item="um" index= "index" separator =",">
15
+            (#{um.userid},#{um.moduleid},#{um.umorder},#{um.createtime},#{um.schoolid})
16
+        </foreach>
17
+    </insert>
18
+
19
+    <!--根据用户id删除用户常用应用-->
20
+    <delete id="deleteByUserid">
21
+        delete from t_user_module where userid=#{userid}
22
+    </delete>
23
+    <!--获取有常用模块的用户id集合-->
24
+    <select id="listUserId" resultType="java.lang.Integer">
25
+        SELECT um.userid FROM t_user_module um LEFT JOIN t_role_module rm ON um.moduleid=rm.moduleid
26
+        WHERE rm.roleid=#{roleid} GROUP BY um.userid
27
+    </select>
28
+    <!--根据用户id删除没有权限的常用模块-->
29
+    <delete id="deleteNoRoleByUserId">
30
+        DELETE FROM t_user_module WHERE userid=#{userid} AND moduleid
31
+        NOT IN(SELECT rm.moduleid FROM t_user u LEFT JOIN t_user_role ur ON u.userid=ur.userid
32
+        LEFT JOIN t_role_module rm ON ur.roleid=rm.roleid
33
+        WHERE u.userid=#{userid} GROUP BY rm.moduleid)
34
+    </delete>
35
+</mapper>

Loading…
Отказ
Запис