张延森 пре 2 година
родитељ
комит
de90a51548

+ 40
- 0
src/main/java/com/njyunzhi/invoice/common/BaseController.java Прегледај датотеку

@@ -1,7 +1,47 @@
1 1
 package com.njyunzhi.invoice.common;
2 2
 
3
+import cn.dev33.satoken.stp.StpUtil;
4
+import com.njyunzhi.invoice.entity.SysUser;
5
+import com.njyunzhi.invoice.entity.TaPerson;
6
+import com.njyunzhi.invoice.service.ISysUserService;
7
+import com.njyunzhi.invoice.service.ITaPersonService;
8
+import org.springframework.beans.factory.annotation.Autowired;
3 9
 import org.springframework.stereotype.Component;
4 10
 
5 11
 @Component
6 12
 public class BaseController {
13
+
14
+    @Autowired
15
+    public ISysUserService iSysUserService;
16
+
17
+    @Autowired
18
+    public ITaPersonService iTaPersonService;
19
+
20
+    public SysUser currentUser() throws Exception {
21
+        String loginId = StpUtil.getLoginIdAsString();
22
+        if (StringUtils.isEmpty(loginId)) {
23
+            throw new Exception("请先登录");
24
+        }
25
+
26
+        SysUser user = iSysUserService.getById(loginId);
27
+        if (user == null || user.getStatus() == Constants.STATUS_DELETE) {
28
+            throw new Exception("人员不存在");
29
+        }
30
+
31
+        return user;
32
+    }
33
+
34
+    public TaPerson currentPerson() throws Exception {
35
+        String loginId = StpUtil.getLoginIdAsString();
36
+        if (StringUtils.isEmpty(loginId)) {
37
+            throw new Exception("请先登录");
38
+        }
39
+
40
+        TaPerson user = iTaPersonService.getById(loginId);
41
+        if (user == null || user.getStatus() == Constants.STATUS_DELETE) {
42
+            throw new Exception("人员不存在");
43
+        }
44
+
45
+        return user;
46
+    }
7 47
 }

+ 0
- 3
src/main/java/com/njyunzhi/invoice/controller/LoginController.java Прегледај датотеку

@@ -25,9 +25,6 @@ import java.util.Map;
25 25
 @RequestMapping("/")
26 26
 public class LoginController extends BaseController {
27 27
 
28
-    @Autowired
29
-    ISysUserService iSysUserService;
30
-
31 28
     @PostMapping("/admin/login")
32 29
     @ApiOperation(value="后台登录", notes = "后台登录", httpMethod = "POST", response = ResponseBean.class)
33 30
     public ResponseBean login(@ApiParam("登录参数") @RequestBody LoginParm loginParm) throws Exception {

+ 1
- 1
src/main/java/com/njyunzhi/invoice/controller/SysUserController.java Прегледај датотеку

@@ -46,7 +46,7 @@ public class SysUserController extends BaseController {
46 46
      * @param pageSize
47 47
      * @return
48 48
      */
49
-    @RequestMapping(value="/sysUser",method= RequestMethod.GET)
49
+    @RequestMapping(value="/admin/user",method= RequestMethod.GET)
50 50
     @ApiOperation(value="列表", notes = "列表", httpMethod = "GET", response = ResponseBean.class)
51 51
     public ResponseBean sysUserList(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
52 52
 									 @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize) throws Exception{

+ 36
- 0
src/main/java/com/njyunzhi/invoice/service/IBaseService.java Прегледај датотеку

@@ -0,0 +1,36 @@
1
+package com.njyunzhi.invoice.service;
2
+
3
+import com.baomidou.mybatisplus.extension.service.IService;
4
+
5
+import java.io.Serializable;
6
+import java.util.List;
7
+
8
+public interface IBaseService<T> extends IService<T> {
9
+    /**
10
+     * 逻辑删除
11
+     * @param id
12
+     * @return
13
+     */
14
+    boolean removeLogicById(Serializable id);
15
+
16
+    /**
17
+     * 逻辑删除
18
+     * @param id
19
+     * @return
20
+     */
21
+    boolean removeLogicByUser(Serializable id, String userId, String userType);
22
+
23
+    boolean removeBy(String column, Object value, boolean notDelete);
24
+
25
+    boolean canAccessData(Serializable id, String userId);
26
+
27
+    boolean remvoeWithDataScope(Serializable id, String userId);
28
+
29
+    int countBy(String column, Object value, boolean notDelete);
30
+
31
+    T getByButNot(String column, Object value, String col, Object val, boolean notDelete);
32
+
33
+    T getExistBy(String column, Object value, boolean normal, boolean notDelete);
34
+
35
+    List<T> getListBy(String column, Object value, boolean normal, boolean notDelete);
36
+}

+ 130
- 0
src/main/java/com/njyunzhi/invoice/service/impl/BaseServiceImpl.java Прегледај датотеку

@@ -0,0 +1,130 @@
1
+package com.njyunzhi.invoice.service.impl;
2
+
3
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
5
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
6
+import com.baomidou.mybatisplus.core.metadata.TableInfo;
7
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
8
+import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
9
+import com.njyunzhi.invoice.service.IBaseService;
10
+
11
+import java.io.Serializable;
12
+import java.time.LocalDateTime;
13
+import java.util.List;
14
+
15
+public class BaseServiceImpl<M extends BaseMapper<T>, T> extends ServiceImpl<M, T> implements IBaseService<T> {
16
+    @Override
17
+    public boolean removeLogicById(Serializable id) {
18
+
19
+        TableInfo tableInfo = SqlHelper.table(currentModelClass());
20
+        UpdateWrapper<T> updateWrapper = new UpdateWrapper<>();
21
+        updateWrapper.set("status", -1)
22
+                .eq(tableInfo.getKeyColumn(), id);
23
+
24
+        return update(updateWrapper);
25
+    }
26
+
27
+    @Override
28
+    public boolean removeLogicByUser(Serializable id, String userId, String userType) {
29
+
30
+        TableInfo tableInfo = SqlHelper.table(currentModelClass());
31
+        UpdateWrapper<T> updateWrapper = new UpdateWrapper<>();
32
+        updateWrapper.set("status", -1)
33
+                .set("delete_user_type", userType)
34
+                .set("delete_user", userId)
35
+                .set("delete_date", LocalDateTime.now())
36
+                .eq(tableInfo.getKeyColumn(), id);
37
+
38
+        return update(updateWrapper);
39
+    }
40
+
41
+    @Override
42
+    public boolean removeBy(String column, Object value, boolean notDelete) {
43
+        if (notDelete) {
44
+            UpdateWrapper<T> updateWrapper = new UpdateWrapper<>();
45
+            updateWrapper.set("status", -1);
46
+            updateWrapper.eq(column, value);
47
+            return update(updateWrapper);
48
+        } else {
49
+            QueryWrapper<T> queryWrapper = new QueryWrapper<>();
50
+            queryWrapper.eq(column, value);
51
+            return remove(queryWrapper);
52
+        }
53
+    }
54
+
55
+    @Override
56
+    public boolean canAccessData(Serializable id, String userId) {
57
+        TableInfo tableInfo = SqlHelper.table(currentModelClass());
58
+
59
+        String t = tableInfo.getTableName();
60
+//        String k = tableInfo.getKeyColumn();
61
+        String kAlias = t + ".org_id";
62
+
63
+        String joinSQL = "INNER JOIN sys_user_data_scope s ON ( "+ kAlias +" = s.org_id OR "+t+".create_user = s.user_id )";
64
+        String whereSQL = "WHERE " + kAlias + " = '"+ id +"' AND s.user_id = '" + userId + "'";
65
+
66
+        String sql = joinSQL + " " + whereSQL;
67
+
68
+        QueryWrapper<T> wrapper = new QueryWrapper<>();
69
+        wrapper.last(sql);
70
+        return count(wrapper) > 0;
71
+    }
72
+
73
+    @Override
74
+    public boolean remvoeWithDataScope(Serializable id, String userId) {
75
+        TableInfo tableInfo = SqlHelper.table(currentModelClass());
76
+
77
+        String t = tableInfo.getTableName();
78
+        String k = tableInfo.getKeyColumn();
79
+        String kAlias = t + "." + k;
80
+
81
+        String joinSQL = "INNER JOIN sys_user_data_scope s ON ( "+ kAlias +" = s.org_id OR "+t+".create_user = s.user_id )";
82
+        String setSQL = "SET status = -1";
83
+        String whereSQL = "WHERE " + kAlias + " = '"+ id +"' AND s.user_id = '" + userId + "'";
84
+
85
+        String sql = joinSQL + " " + setSQL + " " + whereSQL;
86
+
87
+        UpdateWrapper<T> wrapper = new UpdateWrapper<>();
88
+        wrapper.last(sql);
89
+        return update(wrapper);
90
+    }
91
+
92
+    @Override
93
+    public int countBy(String column, Object value, boolean notDelete) {
94
+        QueryWrapper<T> queryWrapper = new QueryWrapper<>();
95
+        queryWrapper.eq(column, value);
96
+        queryWrapper.gt(notDelete, "status", -1);
97
+
98
+        return (int) count(queryWrapper);
99
+    }
100
+
101
+    @Override
102
+    public T getByButNot(String column, Object value, String col, Object val, boolean notDelete) {
103
+        QueryWrapper<T> queryWrapper = new QueryWrapper<>();
104
+        queryWrapper.eq(column, value);
105
+        queryWrapper.ne(col, val);
106
+        queryWrapper.gt(notDelete, "status", -1);
107
+        queryWrapper.last("limit 1");
108
+
109
+        return getOne(queryWrapper);
110
+    }
111
+
112
+    @Override
113
+    public T getExistBy(String column, Object value, boolean normal, boolean notDelete) {
114
+        QueryWrapper<T> queryWrapper = new QueryWrapper<>();
115
+        queryWrapper.eq(column, value);
116
+        queryWrapper.eq(normal, "status", 1);
117
+        queryWrapper.gt(notDelete, "status", -1);
118
+        queryWrapper.last("limit 1");
119
+        return getOne(queryWrapper);
120
+    }
121
+
122
+    @Override
123
+    public List<T> getListBy(String column, Object value, boolean normal, boolean notDelete) {
124
+        QueryWrapper<T> queryWrapper = new QueryWrapper<>();
125
+        queryWrapper.eq(column, value);
126
+        queryWrapper.eq(normal, "status", 1);
127
+        queryWrapper.gt(notDelete, "status", -1);
128
+        return list(queryWrapper);
129
+    }
130
+}