Yansen 2 years ago
parent
commit
be83bc691e

+ 43
- 1
pom.xml View File

@@ -72,6 +72,14 @@
72 72
         </dependency>
73 73
         <!--mybatis-plus end-->
74 74
 
75
+        <!--weixin-miniapp start-->
76
+        <dependency>
77
+            <groupId>com.github.binarywang</groupId>
78
+            <artifactId>weixin-java-miniapp</artifactId>
79
+            <version>4.4.0</version>
80
+        </dependency>
81
+        <!--weixin-miniapp start-->
82
+
75 83
         <!--swagger start-->
76 84
         <dependency>
77 85
             <groupId>io.springfox</groupId>
@@ -81,6 +89,30 @@
81 89
         <!--swagger end-->
82 90
     </dependencies>
83 91
 
92
+
93
+    <profiles>
94
+        <profile>
95
+            <id>dev</id>
96
+            <properties>
97
+                <profileActive>dev</profileActive>
98
+            </properties>
99
+            <activation>
100
+                <activeByDefault>true</activeByDefault>
101
+            </activation>
102
+        </profile>
103
+        <profile>
104
+            <id>prod</id>
105
+            <properties>
106
+                <profileActive>prod</profileActive>
107
+            </properties>
108
+            <activation>
109
+                <activeByDefault>false</activeByDefault>
110
+            </activation>
111
+            <build>
112
+            </build>
113
+        </profile>
114
+    </profiles>
115
+
84 116
     <build>
85 117
         <plugins>
86 118
             <plugin>
@@ -96,6 +128,16 @@
96 128
                 </configuration>
97 129
             </plugin>
98 130
         </plugins>
131
+        <resources>
132
+            <resource>
133
+                <directory>src/main/resources</directory>
134
+                <filtering>true</filtering>
135
+                <includes>
136
+                    <include>**/*.xml</include>
137
+                    <include>application.yml</include>
138
+                    <include>application-${profileActive}.yml</include>
139
+                </includes>
140
+            </resource>
141
+        </resources>
99 142
     </build>
100
-
101 143
 </project>

+ 38
- 0
src/main/java/com/example/civilizedcity/common/BaseController.java View File

@@ -1,9 +1,47 @@
1 1
 package com.example.civilizedcity.common;
2 2
 
3
+import cn.dev33.satoken.stp.StpUtil;
4
+import com.example.civilizedcity.entity.SysUser;
5
+import com.example.civilizedcity.entity.TaPerson;
6
+import com.example.civilizedcity.service.SysUserService;
7
+import com.example.civilizedcity.service.TaPersonService;
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 {
7 13
 
14
+    @Autowired
15
+    protected SysUserService sysUserService;
8 16
 
17
+    @Autowired
18
+    protected TaPersonService taPersonService;
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 = sysUserService.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 taPerson = taPersonService.getById(loginId);
41
+        if (taPerson == null || taPerson.getStatus() == Constants.STATUS_DELETE) {
42
+            throw new Exception("人员不存在");
43
+        }
44
+
45
+        return taPerson;
46
+    }
9 47
 }

+ 10
- 0
src/main/java/com/example/civilizedcity/config/WxMaConfig.java View File

@@ -0,0 +1,10 @@
1
+package com.example.civilizedcity.config;
2
+
3
+import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
4
+import org.springframework.boot.context.properties.ConfigurationProperties;
5
+import org.springframework.stereotype.Component;
6
+
7
+@Component
8
+@ConfigurationProperties(prefix = "wx.miniapp")
9
+public class WxMaConfig extends WxMaDefaultConfigImpl {
10
+}

+ 52
- 0
src/main/java/com/example/civilizedcity/config/WxMaUitl.java View File

@@ -0,0 +1,52 @@
1
+package com.example.civilizedcity.config;
2
+
3
+import cn.binarywang.wx.miniapp.api.WxMaService;
4
+import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
5
+import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
6
+import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
7
+import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
8
+import io.swagger.annotations.ApiModel;
9
+import lombok.Data;
10
+import me.chanjar.weixin.common.error.WxErrorException;
11
+import org.springframework.beans.factory.annotation.Autowired;
12
+import org.springframework.stereotype.Component;
13
+
14
+@Component
15
+public class WxMaUitl {
16
+    WxMaConfig wxMaConfig;
17
+    WxMaService service;
18
+
19
+    @Autowired
20
+    public WxMaUitl(WxMaConfig wxMaConfig) {
21
+        this.wxMaConfig = wxMaConfig;
22
+        this.wxMaConfig.setMsgDataFormat("JSON");
23
+
24
+        service = new WxMaServiceImpl();
25
+        service.setWxMaConfig(this.wxMaConfig);
26
+    }
27
+
28
+    public WxMaService getService() {
29
+        return service;
30
+    }
31
+
32
+    public WxMaJscode2SessionResult getOpenid(String code) throws WxErrorException {
33
+        return service.getUserService().getSessionInfo(code);
34
+    }
35
+
36
+    public WxMaUserInfo getUserInfo(AuthParam param) {
37
+        return service.getUserService().getUserInfo(param.getSessionKey(), param.getEncryptedData(), param.getIv());
38
+    }
39
+
40
+    public WxMaPhoneNumberInfo getPhoneNoInfo(AuthParam param) {
41
+        return service.getUserService().getPhoneNoInfo(param.getSessionKey(), param.getEncryptedData(), param.getIv());
42
+    }
43
+
44
+    @Data
45
+    public static class AuthParam {
46
+        String signature;
47
+        String rawData;
48
+        String encryptedData;
49
+        String iv;
50
+        String sessionKey;
51
+    }
52
+}

+ 69
- 0
src/main/java/com/example/civilizedcity/controller/LoginController.java View File

@@ -0,0 +1,69 @@
1
+package com.example.civilizedcity.controller;
2
+
3
+import cn.dev33.satoken.stp.StpUtil;
4
+import com.example.civilizedcity.common.BaseController;
5
+import com.example.civilizedcity.common.ResponseBean;
6
+import com.example.civilizedcity.common.StringUtils;
7
+import com.example.civilizedcity.entity.SysUser;
8
+import com.example.civilizedcity.vo.ChangePassword;
9
+import com.example.civilizedcity.vo.LoginParam;
10
+import io.swagger.annotations.Api;
11
+import io.swagger.annotations.ApiOperation;
12
+import io.swagger.annotations.ApiParam;
13
+import org.springframework.web.bind.annotation.*;
14
+
15
+import java.util.HashMap;
16
+import java.util.Map;
17
+
18
+
19
+@Api(tags ="登录")
20
+@RestController
21
+@RequestMapping("/admin")
22
+public class LoginController extends BaseController {
23
+
24
+    @PostMapping("/login")
25
+    @ApiOperation(value="后台登录", notes = "后台登录", httpMethod = "POST", response = ResponseBean.class)
26
+    public ResponseBean login(@ApiParam("登录参数") @RequestBody LoginParam loginParm) throws Exception {
27
+
28
+        if (StringUtils.isEmpty(loginParm.getAccount()) || StringUtils.isEmpty(loginParm.getPassword())) {
29
+            return ResponseBean.error("登录用户或者密码不能为空");
30
+        }
31
+
32
+        SysUser sysUser = sysUserService.login(loginParm);
33
+
34
+        StpUtil.login(sysUser.getUserId(), "admin");
35
+        String tokenValue = StpUtil.getTokenValue();
36
+
37
+        Map<String, Object> result = new HashMap<>();
38
+        result.put("user", sysUser);
39
+        result.put("token", tokenValue);
40
+
41
+        return ResponseBean.success(result);
42
+    }
43
+
44
+    @PostMapping("/logout")
45
+    @ApiOperation(value="登出", notes = "登出", httpMethod = "POST", response = ResponseBean.class)
46
+    public ResponseBean logout() throws Exception {
47
+        SysUser sysUser = currentUser();
48
+        StpUtil.logout(sysUser.getUserId(), "admin");
49
+        return ResponseBean.success("success");
50
+    }
51
+
52
+
53
+    @PutMapping("/change-password")
54
+    @ApiOperation(value="修改密码", notes = "修改密码", httpMethod = "PUT", response = ResponseBean.class)
55
+    public ResponseBean changePassword(@ApiParam("修改密码参数") @RequestBody ChangePassword param) throws Exception {
56
+        if (StringUtils.isEmpty(param.getOriginPassword()) || StringUtils.isEmpty(param.getNewPassword())) {
57
+            return ResponseBean.error("原始密码或新密码不能为空", ResponseBean.ERROR_ILLEGAL_PARAMS);
58
+        }
59
+
60
+        SysUser user = currentUser();
61
+
62
+        boolean isOk = sysUserService.changePassword(user, param);
63
+        if (!isOk) {
64
+            ResponseBean.error("修改失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
65
+        }
66
+
67
+        return ResponseBean.success("密码修改成功");
68
+    }
69
+}

+ 174
- 0
src/main/java/com/example/civilizedcity/controller/WxMaController.java View File

@@ -0,0 +1,174 @@
1
+package com.example.civilizedcity.controller;
2
+
3
+import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
4
+import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
5
+import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
6
+import cn.dev33.satoken.stp.StpUtil;
7
+import com.example.civilizedcity.common.BaseController;
8
+import com.example.civilizedcity.common.Constants;
9
+import com.example.civilizedcity.common.ResponseBean;
10
+import com.example.civilizedcity.common.StringUtils;
11
+import com.example.civilizedcity.config.WxMaUitl;
12
+import com.example.civilizedcity.entity.SysUser;
13
+import com.example.civilizedcity.entity.TaPerson;
14
+import com.example.civilizedcity.entity.TaPersonReflect;
15
+import com.example.civilizedcity.service.TaPersonReflectService;
16
+import com.example.civilizedcity.vo.LoginParam;
17
+import io.swagger.annotations.Api;
18
+import io.swagger.annotations.ApiOperation;
19
+import io.swagger.annotations.ApiParam;
20
+import org.springframework.beans.factory.annotation.Autowired;
21
+import org.springframework.web.bind.annotation.*;
22
+
23
+import java.time.LocalDateTime;
24
+import java.util.HashMap;
25
+import java.util.Map;
26
+
27
+@Api(tags = "小程序登入/登出")
28
+@RestController
29
+@RequestMapping("/ma")
30
+public class WxMaController extends BaseController {
31
+
32
+    @Autowired
33
+    WxMaUitl wxMaUitl;
34
+
35
+    @Autowired
36
+    TaPersonReflectService taPersonReflectService;
37
+
38
+
39
+//    private boolean checkLoginParam(LoginParam loginParam) {
40
+//        return !StringUtils.isEmpty(loginParam.getCode())
41
+//                && !StringUtils.isEmpty(loginParam.getUserName())
42
+//                && !StringUtils.isEmpty(loginParam.getPassword());
43
+//    }
44
+
45
+//    @GetMapping("/preload")
46
+//    @ApiOperation(value="小程序登录", notes = "小程序登录", httpMethod = "POST", response = ResponseBean.class)
47
+//    public ResponseBean preload(@ApiParam("客户端ID") @PathVariable String clientId,
48
+//                                @ApiParam("小程序预加载参数") @RequestParam(required = false) WxMaPreload wxMaPreload) throws Exception {
49
+//
50
+//        if (Constants.CLIENT_WORKER.equals(clientId)) {
51
+//            List<TaMessageTemplate> list = iTaMessageTemplateService.getByTplType(Constants.MESSAGE_MINIAPP);
52
+//            return ResponseBean.success(new HashMap<String, Object>(){{
53
+//                put("tpls", list);
54
+//            }});
55
+//        }
56
+//
57
+//        return ResponseBean.success(null);
58
+//    }
59
+
60
+    /**
61
+     * 小程序
62
+     * @param code
63
+     * @return
64
+     * @throws Exception
65
+     */
66
+    @PostMapping("/login")
67
+    @ApiOperation(value="小程序登录", notes = "小程序登录", httpMethod = "POST", response = ResponseBean.class)
68
+    public ResponseBean login(@ApiParam("登录参数") @RequestParam String code) throws Exception {
69
+
70
+        if (StringUtils.isEmpty(code)) {
71
+            return ResponseBean.error("CODE 不能为空");
72
+        }
73
+
74
+        WxMaJscode2SessionResult sessionInfo = wxMaUitl.getOpenid(code);
75
+        String openid = sessionInfo.getOpenid();
76
+        String sessionKey = sessionInfo.getSessionKey();
77
+
78
+        TaPerson taPerson = taPersonService.getByOpenId(openid);
79
+        if (null == taPerson) {
80
+            taPerson = new TaPerson();
81
+            taPerson.setOpenid(openid);
82
+            taPerson.setStatus(Constants.STATUS_NORMAL);
83
+            taPerson.setCreateDate(LocalDateTime.now());
84
+            taPersonService.save(taPerson);
85
+        }
86
+
87
+//        SysUser user = taPersonService.getReflectUser(taPerson);
88
+
89
+        StpUtil.login(taPerson.getPersonId(), "miniapp");
90
+        Map<String, Object> res = new HashMap<>();
91
+        res.put("person", taPerson);
92
+//        res.put("user", user);
93
+        res.put("token", StpUtil.getTokenValue());
94
+        res.put("sessionKey", sessionKey);
95
+
96
+        return ResponseBean.success(res);
97
+    }
98
+
99
+    /**
100
+     * 系统人员登录
101
+     * @param param
102
+     * @return
103
+     * @throws Exception
104
+     */
105
+    public ResponseBean signin(@ApiParam("登录参数") LoginParam param) throws Exception {
106
+
107
+        if (StringUtils.isEmpty(param.getAccount()) || StringUtils.isEmpty(param.getPassword())) {
108
+            return ResponseBean.error("登录用户或者密码不能为空");
109
+        }
110
+
111
+        SysUser user = sysUserService.login(param);
112
+
113
+        TaPerson taPerson = currentPerson();
114
+        TaPerson reflectd = taPersonService.getByUser(user);
115
+
116
+        // 如果未绑定
117
+        if (null == reflectd) {
118
+            TaPersonReflect personReflect = new TaPersonReflect();
119
+            taPersonReflectService.save(personReflect);
120
+            reflectd = taPerson;
121
+        }
122
+
123
+        // 退出原用户
124
+        StpUtil.logout(taPerson.getPersonId(), "miniapp");
125
+        // 登录新用户
126
+        StpUtil.login(reflectd.getPersonId(), "miniapp");
127
+
128
+        Map<String, Object> res = new HashMap<>();
129
+        res.put("person", reflectd);
130
+        res.put("user", user);
131
+        res.put("token", StpUtil.getTokenValue());
132
+
133
+        return ResponseBean.success(res);
134
+    }
135
+
136
+    @PutMapping("/auth-user")
137
+    @ApiOperation(value="授权头像", notes = "授权头像", httpMethod = "PUT", response = TaPerson.class)
138
+    public ResponseBean updateUserInfo(@ApiParam("授权头像的参数") @RequestBody WxMaUitl.AuthParam param) throws Exception {
139
+        // 解密用户信息
140
+        WxMaUserInfo userInfo = wxMaUitl.getUserInfo(param);
141
+
142
+        TaPerson taPerson = currentPerson();
143
+        if (null == taPerson) {
144
+            throw new Exception("校验当前人员失败, 请重试");
145
+        }
146
+
147
+        taPerson.setAvatar(userInfo.getAvatarUrl());
148
+        taPerson.setName(userInfo.getNickName());
149
+//        taPerson.setSex(Integer.parseInt(userInfo.getGender()));
150
+
151
+        taPersonService.updateById(taPerson);
152
+
153
+        return ResponseBean.success(taPerson);
154
+    }
155
+
156
+    @ApiOperation(value="授权手机", notes = "授权手机", httpMethod = "PUT", response = TaPerson.class)
157
+    @PutMapping("/auth-phone")
158
+    public ResponseBean updateUserPhone(@ApiParam("授权手机的参数") @RequestBody WxMaUitl.AuthParam param) throws Exception {
159
+
160
+        // 解密
161
+        WxMaPhoneNumberInfo phoneNoInfo = wxMaUitl.getPhoneNoInfo(param);
162
+
163
+        TaPerson taPerson = currentPerson();
164
+        if (null == taPerson) {
165
+            throw new Exception("校验当前人员失败, 请重试");
166
+        }
167
+
168
+        taPerson.setPhone(phoneNoInfo.getPhoneNumber());
169
+        taPersonService.updateById(taPerson);
170
+
171
+        return ResponseBean.success(taPerson);
172
+    }
173
+
174
+}

+ 4
- 2
src/main/java/com/example/civilizedcity/mapper/SysLoginMapper.java View File

@@ -12,5 +12,7 @@ import com.example.civilizedcity.entity.SysLogin;
12 12
  */
13 13
 @Mapper
14 14
 public interface SysLoginMapper  extends BaseMapper<SysLogin>{
15
-    
16
-}
15
+    SysLogin getByAccount(@Param("account") String account);
16
+
17
+     SysLogin getByUserAndPassword(@Param("userId") String userId, @Param("password") String password);
18
+ }

+ 1
- 2
src/main/java/com/example/civilizedcity/mapper/SysUserMapper.java View File

@@ -12,5 +12,4 @@ import com.example.civilizedcity.entity.SysUser;
12 12
  */
13 13
 @Mapper
14 14
 public interface SysUserMapper  extends BaseMapper<SysUser>{
15
-    
16
-}
15
+ }

+ 8
- 2
src/main/java/com/example/civilizedcity/mapper/TaPersonMapper.java View File

@@ -1,6 +1,7 @@
1 1
 package com.example.civilizedcity.mapper;
2 2
 
3 3
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4
+import com.example.civilizedcity.entity.SysUser;
4 5
 import org.apache.ibatis.annotations.Mapper;
5 6
 import org.apache.ibatis.annotations.Param;
6 7
 import com.example.civilizedcity.entity.TaPerson;
@@ -12,5 +13,10 @@ import com.example.civilizedcity.entity.TaPerson;
12 13
  */
13 14
 @Mapper
14 15
 public interface TaPersonMapper  extends BaseMapper<TaPerson>{
15
-    
16
-}
16
+
17
+     SysUser getReflectUser(@Param("personId") String personId);
18
+
19
+     TaPerson getByUser(@Param("userId") String userId);
20
+
21
+     TaPerson getByUserAndPerson(@Param("userId") String userId, @Param("personId") String personId);
22
+ }

+ 8
- 3
src/main/java/com/example/civilizedcity/service/SysUserService.java View File

@@ -1,13 +1,18 @@
1 1
 package com.example.civilizedcity.service;
2 2
 
3
-import com.baomidou.mybatisplus.extension.service.IService;
4 3
 import com.example.civilizedcity.entity.SysUser;
4
+import com.example.civilizedcity.vo.ChangePassword;
5
+import com.example.civilizedcity.vo.LoginParam;
5 6
 
6
- /**
7
+/**
7 8
  * 用户表;(sys_user)表服务接口
9
+ *
8 10
  * @author : http://njyunzhi.com
9 11
  * @date : 2022-12-12
10 12
  */
11 13
 public interface SysUserService extends IBaseService<SysUser> {
12
-    
14
+
15
+    SysUser login(LoginParam loginParm) throws Exception;
16
+
17
+    boolean changePassword(SysUser user, ChangePassword param) throws Exception;
13 18
 }

+ 10
- 2
src/main/java/com/example/civilizedcity/service/TaPersonService.java View File

@@ -1,6 +1,7 @@
1 1
 package com.example.civilizedcity.service;
2 2
 
3 3
 import com.baomidou.mybatisplus.extension.service.IService;
4
+import com.example.civilizedcity.entity.SysUser;
4 5
 import com.example.civilizedcity.entity.TaPerson;
5 6
 
6 7
  /**
@@ -9,5 +10,12 @@ import com.example.civilizedcity.entity.TaPerson;
9 10
  * @date : 2022-12-12
10 11
  */
11 12
 public interface TaPersonService extends IBaseService<TaPerson> {
12
-    
13
-}
13
+
14
+     TaPerson getByOpenId(String openid);
15
+
16
+     SysUser getReflectUser(TaPerson taPerson);
17
+
18
+     TaPerson getByUser(SysUser sysUser);
19
+
20
+     TaPerson getByUserAndPerson(SysUser user, String personId);
21
+ }

+ 62
- 2
src/main/java/com/example/civilizedcity/service/impl/SysUserServiceImpl.java View File

@@ -1,16 +1,76 @@
1 1
 package com.example.civilizedcity.service.impl;
2 2
 
3
+import com.example.civilizedcity.common.Constants;
4
+import com.example.civilizedcity.common.EncryptUtils;
5
+import com.example.civilizedcity.common.StringUtils;
6
+import com.example.civilizedcity.entity.SysLogin;
7
+import com.example.civilizedcity.mapper.SysLoginMapper;
8
+import com.example.civilizedcity.vo.ChangePassword;
9
+import com.example.civilizedcity.vo.LoginParam;
3 10
 import org.springframework.beans.factory.annotation.Autowired;
4 11
 import org.springframework.stereotype.Service;
5 12
 import com.example.civilizedcity.entity.SysUser;
6 13
 import com.example.civilizedcity.mapper.SysUserMapper;
7 14
 import com.example.civilizedcity.service.SysUserService;
8
- /**
15
+
16
+/**
9 17
  * 用户表;(sys_user)表服务实现类
18
+ *
10 19
  * @author : http://www.chiner.pro
11 20
  * @date : 2022-12-12
12 21
  */
13 22
 @Service
14 23
 public class SysUserServiceImpl extends BaseServiceImpl<SysUserMapper, SysUser> implements SysUserService {
15
-    
24
+
25
+    @Autowired
26
+    SysLoginMapper sysLoginMapper;
27
+
28
+    @Override
29
+    public SysUser login(LoginParam loginParm) throws Exception {
30
+        SysLogin sysLogin = sysLoginMapper.getByAccount(loginParm.getAccount());
31
+        if (null == sysLogin) {
32
+            throw new Exception("用户名或者密码不正确");
33
+        }
34
+
35
+        String userId = sysLogin.getUserId();
36
+        if (StringUtils.isEmpty(userId)) {
37
+            throw new Exception("用户名或者密码不正确");
38
+        }
39
+
40
+        boolean isRight = checkPassword(loginParm.getPassword(), sysLogin.getPassword(), userId);
41
+        if (!isRight) {
42
+            throw new Exception("用户名或者密码不正确");
43
+        }
44
+
45
+        SysUser sysUser = getById(userId);
46
+        if (Constants.STATUS_DELETE == sysUser.getStatus()) {
47
+            throw new Exception("用户账户已删除");
48
+        }
49
+
50
+        if (Constants.STATUS_NORMAL != sysUser.getStatus()) {
51
+            throw new Exception("用户已停用");
52
+        }
53
+
54
+        return sysUser;
55
+    }
56
+
57
+    @Override
58
+    public boolean changePassword(SysUser user, ChangePassword param) throws Exception {
59
+        String passwordEncrypted = EncryptUtils.md5(param.getOriginPassword(), user.getUserId());
60
+        SysLogin sysLogin = sysLoginMapper.getByUserAndPassword(user.getUserId(), passwordEncrypted);
61
+
62
+        if (null == sysLogin) {
63
+            throw new Exception("原始密码不正确");
64
+        }
65
+
66
+        String newPassword = EncryptUtils.md5(param.getNewPassword(), user.getUserId());
67
+        sysLogin.setPassword(newPassword);
68
+
69
+        return sysLoginMapper.updateById(sysLogin) > 0;
70
+    }
71
+
72
+    boolean checkPassword(String src, String targ, String salt) {
73
+        String newPass = EncryptUtils.md5(src, salt);
74
+        return targ.equals(newPass);
75
+    }
16 76
 }

+ 24
- 2
src/main/java/com/example/civilizedcity/service/impl/TaPersonServiceImpl.java View File

@@ -1,16 +1,38 @@
1 1
 package com.example.civilizedcity.service.impl;
2 2
 
3
+import com.example.civilizedcity.entity.SysUser;
3 4
 import org.springframework.beans.factory.annotation.Autowired;
4 5
 import org.springframework.stereotype.Service;
5 6
 import com.example.civilizedcity.entity.TaPerson;
6 7
 import com.example.civilizedcity.mapper.TaPersonMapper;
7 8
 import com.example.civilizedcity.service.TaPersonService;
8
- /**
9
+
10
+/**
9 11
  * 人员表;(ta_person)表服务实现类
12
+ *
10 13
  * @author : http://www.chiner.pro
11 14
  * @date : 2022-12-12
12 15
  */
13 16
 @Service
14 17
 public class TaPersonServiceImpl extends BaseServiceImpl<TaPersonMapper, TaPerson> implements TaPersonService {
15
-    
18
+
19
+    @Override
20
+    public TaPerson getByOpenId(String openid) {
21
+        return getExistBy("openid", openid, false, true);
22
+    }
23
+
24
+    @Override
25
+    public SysUser getReflectUser(TaPerson taPerson) {
26
+        return baseMapper.getReflectUser(taPerson.getPersonId());
27
+    }
28
+
29
+    @Override
30
+    public TaPerson getByUser(SysUser sysUser) {
31
+        return baseMapper.getByUser(sysUser.getUserId());
32
+    }
33
+
34
+    @Override
35
+    public TaPerson getByUserAndPerson(SysUser user, String personId) {
36
+        return baseMapper.getByUserAndPerson(user.getUserId(), personId);
37
+    }
16 38
 }

+ 17
- 0
src/main/java/com/example/civilizedcity/vo/ChangePassword.java View File

@@ -0,0 +1,17 @@
1
+package com.example.civilizedcity.vo;
2
+
3
+
4
+import io.swagger.annotations.ApiModel;
5
+import io.swagger.annotations.ApiModelProperty;
6
+import lombok.Data;
7
+
8
+@ApiModel(description = "登录参数")
9
+@Data
10
+public class ChangePassword {
11
+
12
+    @ApiModelProperty("原始密码")
13
+    String originPassword;
14
+
15
+    @ApiModelProperty("新密码")
16
+    String newPassword;
17
+}

+ 17
- 0
src/main/java/com/example/civilizedcity/vo/LoginParam.java View File

@@ -0,0 +1,17 @@
1
+package com.example.civilizedcity.vo;
2
+
3
+import io.swagger.annotations.ApiModel;
4
+import io.swagger.annotations.ApiModelProperty;
5
+import lombok.Data;
6
+
7
+@Data
8
+@ApiModel("登录参数")
9
+public class LoginParam {
10
+
11
+    @ApiModelProperty("用户名")
12
+    String account;
13
+
14
+    @ApiModelProperty("密码")
15
+    String password;
16
+
17
+}

+ 11
- 1
src/main/resources/application.yml View File

@@ -15,6 +15,8 @@ spring:
15 15
     multipart:
16 16
       max-file-size: 1024MB
17 17
       max-request-size: 1024MB
18
+  profiles:
19
+    active: @profileActive@
18 20
 
19 21
 ###
20 22
 yz:
@@ -23,8 +25,16 @@ yz:
23 25
       - "/swagger-ui/**"
24 26
       - "/swagger-resources/**"
25 27
       - "/v2/**"
26
-      - "/login"
27 28
       - "/static/**"
29
+      - "/**/login"
30
+
31
+wx:
32
+  miniapp:
33
+    appid:
34
+    secret:
35
+    token:
36
+    aesKey:
37
+
28 38
 
29 39
 sa-token:
30 40
   # jwt秘钥

+ 18
- 1
src/main/resources/mapper/SysLoginMapper.xml View File

@@ -2,5 +2,22 @@
2 2
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3 3
 
4 4
 <mapper namespace="com.example.civilizedcity.mapper.SysLoginMapper">
5
-    
5
+
6
+    <select id="getByAccount" resultType="com.example.civilizedcity.entity.SysLogin">
7
+        SELECT
8
+            *
9
+        FROM
10
+            sys_login t
11
+        WHERE
12
+            t.account = #{account}
13
+    </select>
14
+    <select id="getByUserAndPassword" resultType="com.example.civilizedcity.entity.SysLogin">
15
+        SELECT
16
+            *
17
+        FROM
18
+            sys_login t
19
+        WHERE
20
+            t.user_id = #{userId}
21
+          AND t.`password` = #{password}
22
+    </select>
6 23
 </mapper>

+ 29
- 1
src/main/resources/mapper/TaPersonMapper.xml View File

@@ -2,5 +2,33 @@
2 2
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3 3
 
4 4
 <mapper namespace="com.example.civilizedcity.mapper.TaPersonMapper">
5
-    
5
+
6
+    <select id="getReflectUser" resultType="com.example.civilizedcity.entity.SysUser">
7
+        SELECT
8
+            m.*
9
+        FROM
10
+            ta_person_reflect t
11
+                INNER JOIN sys_user m ON m.user_id = t.user_id
12
+        WHERE
13
+            t.person_id = #{personId}
14
+    </select>
15
+    <select id="getByUser" resultType="com.example.civilizedcity.entity.TaPerson">
16
+        SELECT
17
+            m.*
18
+        FROM
19
+            ta_person_reflect t
20
+                INNER JOIN ta_person m ON m.person_id = t.person_id
21
+        WHERE
22
+            t.user_id = #{userId}
23
+    </select>
24
+    <select id="getByUserAndPerson" resultType="com.example.civilizedcity.entity.TaPerson">
25
+        SELECT
26
+            m.*
27
+        FROM
28
+            ta_person_reflect t
29
+                INNER JOIN ta_person m ON m.person_id = t.person_id
30
+        WHERE
31
+            t.person_id = #{personId}
32
+            AND t.user_id = #{userId}
33
+    </select>
6 34
 </mapper>