Commit a9c90d1c by levphon

微信小程序后端服务

1 parent aa553e14
...@@ -44,6 +44,13 @@ ...@@ -44,6 +44,13 @@
<version>1.1.0-SNAPSHOT</version> <version>1.1.0-SNAPSHOT</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<!-- devicemonitor-api -->
<dependency>
<groupId>com.glsx</groupId>
<artifactId>ne-shield-devicemonitor-api</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>
......
package cn.com.glsx.app.config; package cn.com.glsx.app.config;
import cn.com.glsx.auth.interceptor.WebRequestAuthorizeInterceptor; import cn.com.glsx.auth.interceptor.WebRequestAuthorizeInterceptor;
import com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.util.List;
/** /**
* @author payu * @author payu
*/ */
...@@ -31,6 +34,10 @@ public class WebConfig implements WebMvcConfigurer { ...@@ -31,6 +34,10 @@ public class WebConfig implements WebMvcConfigurer {
.addPathPatterns("/**") .addPathPatterns("/**")
.excludePathPatterns("/") .excludePathPatterns("/")
.excludePathPatterns("/login") .excludePathPatterns("/login")
.excludePathPatterns("/wechatAuth")
.excludePathPatterns("/wechatLogin")
.excludePathPatterns("/qqAuth")
.excludePathPatterns("/qqLogin")
.excludePathPatterns("/xactuator/**") .excludePathPatterns("/xactuator/**")
.excludePathPatterns("/api/**") .excludePathPatterns("/api/**")
.excludePathPatterns("/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui.html/**"); .excludePathPatterns("/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui.html/**");
......
...@@ -41,11 +41,10 @@ public class ThirdLoginController { ...@@ -41,11 +41,10 @@ public class ThirdLoginController {
private WxMaService wxMaService; private WxMaService wxMaService;
@NoLogin @NoLogin
@RequestMapping(value = "/wechatAuth") @GetMapping(value = "/wechatAuth")
public R wechatAuth(@RequestParam String code) throws WxErrorException { public R wechatAuth(@RequestParam String code) throws WxErrorException {
//获取openId、unionid、session_key //获取openId、unionid、session_key
WxMaJscode2SessionResult sessionInfo = wxMaService.getUserService().getSessionInfo(code); WxMaJscode2SessionResult sessionInfo = wxMaService.getUserService().getSessionInfo(code);
log.info("微信code[{}]获取的Session信息为{}", code, JSONUtil.toJsonStr(sessionInfo)); log.info("微信code[{}]获取的Session信息为{}", code, JSONUtil.toJsonStr(sessionInfo));
UserAuthRel authRel = loginService.wechatAuth(sessionInfo); UserAuthRel authRel = loginService.wechatAuth(sessionInfo);
...@@ -66,7 +65,7 @@ public class ThirdLoginController { ...@@ -66,7 +65,7 @@ public class ThirdLoginController {
} }
@NoLogin @NoLogin
@RequestMapping(value = "/qqAuth") @GetMapping(value = "/qqAuth")
public R qqAuth(@RequestParam String code) { public R qqAuth(@RequestParam String code) {
QQOAuth2AccessToken accessToken = new QQOAuth2AccessToken(); QQOAuth2AccessToken accessToken = new QQOAuth2AccessToken();
...@@ -79,7 +78,7 @@ public class ThirdLoginController { ...@@ -79,7 +78,7 @@ public class ThirdLoginController {
} }
@NoLogin @NoLogin
@RequestMapping(value = "/qqLogin") @PostMapping(value = "/qqLogin")
public R qqLogin(@RequestBody QQLoginBO loginBO) { public R qqLogin(@RequestBody QQLoginBO loginBO) {
log.info("QQ授权参数 {}", loginBO.toString()); log.info("QQ授权参数 {}", loginBO.toString());
UserAuthRel qqAuthRel = loginService.qqLogin(loginBO); UserAuthRel qqAuthRel = loginService.qqLogin(loginBO);
...@@ -100,7 +99,7 @@ public class ThirdLoginController { ...@@ -100,7 +99,7 @@ public class ThirdLoginController {
rtnMap.put("token", token); rtnMap.put("token", token);
rtnMap.put("user", user); rtnMap.put("user", user);
} else { } else {
//没有绑定用户 //没有绑定用户,跳转登录界面登录,回传此id
rtnMap.put("authRelId", authRel.getId()); rtnMap.put("authRelId", authRel.getId());
} }
return rtnMap; return rtnMap;
......
package cn.com.glsx.app.modules.controller; package cn.com.glsx.app.modules.controller;
import cn.com.glsx.app.modules.model.VehicleDeviceDTO; import cn.com.glsx.app.modules.model.VehicleDeviceDTO;
import cn.com.glsx.app.modules.model.VehicleLocationDTO;
import cn.com.glsx.app.modules.service.VehicleMonitorService; import cn.com.glsx.app.modules.service.VehicleMonitorService;
import com.glsx.plat.core.web.R; import com.glsx.plat.core.web.R;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
...@@ -9,6 +10,7 @@ import lombok.extern.slf4j.Slf4j; ...@@ -9,6 +10,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.List; import java.util.List;
...@@ -28,9 +30,15 @@ public class VehicleMonitorController { ...@@ -28,9 +30,15 @@ public class VehicleMonitorController {
*/ */
@ApiOperation(value = "车辆树") @ApiOperation(value = "车辆树")
@GetMapping("/search") @GetMapping("/search")
public R<List> search(String term) { public R<List<VehicleDeviceDTO>> search(String term) {
List<VehicleDeviceDTO> list = vehicleMonitorService.search(term); List<VehicleDeviceDTO> list = vehicleMonitorService.search(term);
return R.ok().data(list); return R.ok().data(list);
} }
@GetMapping("/location")
public R location(@RequestParam("sns") String sns) {
List<VehicleLocationDTO> vehicleLocations = vehicleMonitorService.getVehicleLocations(sns);
return R.ok().data(vehicleLocations);
}
} }
...@@ -20,6 +20,11 @@ public class LoginByAccountBO { ...@@ -20,6 +20,11 @@ public class LoginByAccountBO {
@NotBlank(message = "验证码/密码不能为空") @NotBlank(message = "验证码/密码不能为空")
private String code; private String code;
/**
* 第三方授权关联id
*/
private Long authRelId;
// @NotNull(message = "APP客户端ID不能为空") // @NotNull(message = "APP客户端ID不能为空")
// private String clientId; // private String clientId;
......
package cn.com.glsx.app.modules.model;
import lombok.Data;
@Data
public class VehicleLocationDTO {
}
...@@ -16,6 +16,8 @@ import org.springframework.stereotype.Service; ...@@ -16,6 +16,8 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Date;
import java.util.Objects;
@Service @Service
public class LoginService { public class LoginService {
...@@ -54,6 +56,17 @@ public class LoginService { ...@@ -54,6 +56,17 @@ public class LoginService {
if (localAuth == null) { if (localAuth == null) {
throw new AppServerException("请先开通登录权限"); throw new AppServerException("请先开通登录权限");
} }
//2022/3/25 绑定第三方授权
if (!Objects.isNull(loginBO.getAuthRelId())) {
UserAuthRel authRel = authRelMapper.selectById(loginBO.getAuthRelId());
if (authRel != null) {
authRel.setUserId(simpleUser.getId());
authRel.setUpdatedDate(new Date());
authRelMapper.updateByPrimaryKeySelective(authRel);
}
}
return UserConverter.INSTANCE.su2au(simpleUser); return UserConverter.INSTANCE.su2au(simpleUser);
} else if (loginBO.getLoginType() == 2) { } else if (loginBO.getLoginType() == 2) {
//验证码校验 //验证码校验
......
package cn.com.glsx.app.modules.service; package cn.com.glsx.app.modules.service;
import cn.com.glsx.app.common.exception.AppServerException;
import cn.com.glsx.app.modules.converter.UserConverter;
import cn.com.glsx.app.modules.model.AppUser; import cn.com.glsx.app.modules.model.AppUser;
import cn.com.glsx.auth.api.AuthFeignClient;
import cn.com.glsx.auth.model.SimpleUser;
import cn.hutool.core.lang.UUID; import cn.hutool.core.lang.UUID;
import com.glsx.plat.common.utils.ObjectUtils; import com.glsx.plat.common.utils.ObjectUtils;
import com.glsx.plat.core.web.R;
import com.glsx.plat.jwt.base.ComJwtUser; import com.glsx.plat.jwt.base.ComJwtUser;
import com.glsx.plat.jwt.util.JwtUtils; import com.glsx.plat.jwt.util.JwtUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import javax.annotation.Resource;
import java.util.Map; import java.util.Map;
@Service @Service
public class UserService { public class UserService {
@Resource @Autowired
private JwtUtils<ComJwtUser> jwtUtils; private JwtUtils<ComJwtUser> jwtUtils;
@Autowired
private AuthFeignClient authFeignClient;
/** /**
* 生成带用户信息的token * 生成带用户信息的token
* *
...@@ -36,8 +44,13 @@ public class UserService { ...@@ -36,8 +44,13 @@ public class UserService {
return jwtUtils.createToken(userMap); return jwtUtils.createToken(userMap);
} }
public AppUser getAppUserByUserId(Long aLong) { public AppUser getAppUserByUserId(Long userId) {
return null; R<SimpleUser> userR = authFeignClient.getSimpleUserById(userId);
SimpleUser simpleUser = userR.getData(SimpleUser.class);
if (!userR.isSuccess() || simpleUser == null) {
throw new AppServerException(userR.getMessage());
}
return UserConverter.INSTANCE.su2au(simpleUser);
} }
} }
...@@ -2,9 +2,16 @@ package cn.com.glsx.app.modules.service; ...@@ -2,9 +2,16 @@ package cn.com.glsx.app.modules.service;
import cn.com.glsx.app.modules.mapper.VehicleMapper; import cn.com.glsx.app.modules.mapper.VehicleMapper;
import cn.com.glsx.app.modules.model.VehicleDeviceDTO; import cn.com.glsx.app.modules.model.VehicleDeviceDTO;
import cn.com.glsx.app.modules.model.VehicleLocationDTO;
import cn.com.glsx.devicemonitor.api.dto.response.DeviceLocationDTO;
import cn.com.glsx.devicemonitor.api.feign.GpsBsFeignService;
import com.glsx.plat.core.web.R;
import com.google.gson.reflect.TypeToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List; import java.util.List;
@Service @Service
...@@ -13,8 +20,21 @@ public class VehicleMonitorService { ...@@ -13,8 +20,21 @@ public class VehicleMonitorService {
@Resource @Resource
private VehicleMapper vehicleMapper; private VehicleMapper vehicleMapper;
@Autowired
private GpsBsFeignService gpsBsFeignService;
public List<VehicleDeviceDTO> search(String term) { public List<VehicleDeviceDTO> search(String term) {
return vehicleMapper.search(term); return vehicleMapper.search(term);
} }
public List<VehicleLocationDTO> getVehicleLocations(String sns) {
R<List<DeviceLocationDTO>> listR = gpsBsFeignService.listDeviceMonitorInfo(sns, null);
List<DeviceLocationDTO> dataList = listR.getDataList(new TypeToken<List<DeviceLocationDTO>>() {
}.getType());
List<VehicleLocationDTO> retVehicleBoList = new ArrayList<>();
// TODO: 2022/3/25 转换
return retVehicleBoList;
}
} }
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
<id column="id" jdbcType="INTEGER" property="id"/> <id column="id" jdbcType="INTEGER" property="id"/>
<result column="auth_id" jdbcType="INTEGER" property="authId"/> <result column="auth_id" jdbcType="INTEGER" property="authId"/>
<result column="union_id" jdbcType="VARCHAR" property="unionId"/> <result column="union_id" jdbcType="VARCHAR" property="unionId"/>
<result column="wechat_avatar" jdbcType="VARCHAR" property="wechatAvatar"/> <result column="wechat_avatar" jdbcType="VARCHAR" property="avatar"/>
<result column="wechat_name" jdbcType="VARCHAR" property="wechatName"/> <result column="wechat_name" jdbcType="VARCHAR" property="wechatName"/>
<result column="del_flag" jdbcType="TINYINT" property="delFlag"/> <result column="del_flag" jdbcType="TINYINT" property="delFlag"/>
<result column="created_date" jdbcType="TIMESTAMP" property="createdDate"/> <result column="created_date" jdbcType="TIMESTAMP" property="createdDate"/>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!