Commit f09d7c0b authored by m1991's avatar m1991

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	wisenergy-mapper/src/main/java/cn/wisenergy/mapper/UsersMapper.java
parents 8e97a67a 5926295c
......@@ -48,4 +48,11 @@ public interface UsersMapper extends BaseMapper<User> {
String findPswByName(String UserName);
void save(User user);
/**
* 获取用户信息
* @param userId 用户id
* @return 用户信息
*/
User getByUserId(@Param("userId") Integer userId);
}
......@@ -128,20 +128,16 @@
from
<include refid="table"/>
<where>
is_delete=0
<if test="startTime != null">
and create_time
between #{startTime}
</if>
<if test="endTime != null">and #{endTime}</if>
<if test="userName != null">and user_name like ('%' #{userName} '%')</if>
</where>
</select>
<if test="phone != null">and phone like ('%' #{phone} '%')</if>
order by create_time desc
limit #{pageNo},#{pageSize}
<select id="getByUserId" resultType="cn.wisenergy.model.app.User">
select
<include refid="cols_all"/>
from
<include refid="table"/>
<where>
user_id=#{userId}
</where>
</select>
......
......@@ -2,6 +2,7 @@ package cn.wisenergy.service.app;
import cn.wisenergy.common.utils.R;
import cn.wisenergy.model.app.AccountInfo;
import cn.wisenergy.model.app.OrderInfo;
import java.util.List;
......@@ -17,4 +18,11 @@ public interface AccountService {
* @return true or false
*/
R<Boolean> orderRebate(List<OrderInfo> list);
/**
* 获取账户信息
* @param userId 用户id
* @return 账户信息
*/
R<AccountInfo> getByUserId(Integer userId);
}
......@@ -18,7 +18,14 @@ public interface UserService {
* @param userId 用户id
* @return 用户信息
*/
User getById(Integer userId);
R<User> getById(Integer userId);
/**
* 获取用户信息
* @param userId 用户id
* @return 用户信息
*/
User getByUserId(Integer userId);
R<List<User>> test();
......
......@@ -76,4 +76,10 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, AccountInfo>
}
return R.ok(0, true);
}
@Override
public R<AccountInfo> getByUserId(Integer userId) {
AccountInfo accountInfo = accountMapper.getByUserId(userId);
return R.ok(accountInfo);
}
}
......@@ -8,13 +8,14 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author 86187
* @ Description: 用户接口实现
* @ Author : 86187
* @ Date : 2021/1/6 16:11
* @author 86187
*/
@Service
@Slf4j
......@@ -24,8 +25,14 @@ public class UserServiceImpl extends ServiceImpl<UsersMapper, User> implements U
private UsersMapper usersMapper;
@Override
public User getById(Integer userId) {
return null;
public R<User> getById(Integer userId) {
return R.ok(usersMapper.getByUserId(userId));
}
@Override
public User getByUserId(Integer userId) {
return usersMapper.getByUserId(userId);
}
@Override
......
package cn.wisenergy.web.admin.controller.app;
import cn.wisenergy.common.utils.R;
import cn.wisenergy.model.app.AccountInfo;
import cn.wisenergy.model.app.User;
import cn.wisenergy.service.app.AccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
......@@ -15,6 +20,13 @@ import org.springframework.web.bind.annotation.*;
@Slf4j
public class AccountController {
@Autowired
private AccountService accountSerivce;
private AccountService accountService;
@ApiOperation(value = "获取账户信息", notes = "获取账户信息", httpMethod = "GET")
@ApiImplicitParam(name = "userId", value = "用户id", dataType = "int")
@GetMapping("/getByUserId")
public R<AccountInfo> getByUserId(Integer userId){
return accountService.getByUserId(userId);
}
}
package cn.wisenergy.web.admin.controller.app;
import cn.wisenergy.common.constant.RedisConsts;
import cn.wisenergy.common.utils.R;
import cn.wisenergy.model.app.User;
import cn.wisenergy.service.app.UserService;
import cn.wisenergy.web.common.BaseController;
import cn.wisenergy.web.config.JwtConfig;
import cn.wisenergy.web.shiro.JwtUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @author 86187
*/
@Api(tags = "用户管理")
@RestController
@RequestMapping("/user")
@Slf4j
public class UserController extends BaseController {
@Autowired
private UserService userService;
@Autowired
private JwtUtil jwtUtil;
@Autowired
private JwtConfig jwtConfig;
@Autowired
private RedisTemplate<String, Object> redisTemplate;
@ApiOperation(value = "获取用户信息", notes = "获取用户信息", httpMethod = "GET")
@ApiImplicitParam(name = "userId", value = "用户id", dataType = "int")
@GetMapping("/getByUserId")
public R<User> getByUserId(Integer userId){
return userService.getById(userId);
}
/**
* shiro登录
*
* @return
*/
@ApiOperation(value = "获取token接口", notes = "获取token接口", httpMethod = "POST")
@PostMapping(value = "/login")
public R<String> login(Integer id) {
if (null == id) {
return R.error("入参为空!");
}
//用户信息
User user = userService.getByUserId(id);
// 创建token
String token = jwtUtil.generateToken(user);
// 保存Redis
redisTemplate.opsForValue().set(RedisConsts.JWT_ACCESS_TOKEN + token, token);
return R.ok(token);
}
}
......@@ -3,14 +3,21 @@ package cn.wisenergy.web.config.swagger;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.ResponseEntity;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.*;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spi.service.contexts.SecurityContext;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.time.LocalDate;
import java.util.List;
import static com.google.common.collect.Lists.newArrayList;
//注解开启 swagger2 功能
@EnableSwagger2
//注解标示,这是一个配置类,@Configuation注解包含了@Component注解
......@@ -25,27 +32,50 @@ public class Swagger2 {
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())//调用apiInfo方法,创建一个ApiInfo实例,里面是展示在文档页面信息内容
.select()
//控制暴露出去的路径下的实例
//如果某个接口不想暴露,可以使用以下注解
//@ApiIgnore 这样,该接口就不会暴露在 swagger2 的页面下
.apis(RequestHandlerSelectors.basePackage("cn.wisenergy.web.admin.controller.app"))
//@ApiIgnore 这样,该接口就不会暴露在 swagger2
.apis(RequestHandlerSelectors.basePackage("cn.wisenergy.web.admin.controller"))
.paths(PathSelectors.any())
.build();
.build()
.apiInfo(apiInfo())
.pathMapping("/")
.directModelSubstitute(LocalDate.class, String.class)
.genericModelSubstitutes(ResponseEntity.class)
.useDefaultResponseMessages(false)
.securitySchemes(newArrayList(apiKey()))
.securityContexts(newArrayList(securityContext()))
.enableUrlTemplating(false);
}
//构建 api文档的详细信息函数
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
//页面标题
.title("西田森app")
//创建人
.contact(new Contact("WYY", "", ""))
//版本号
.version("2.0")
.title("Api Documentation")
//描述
.description("API接口描述")
.description("Api Documentation")
.contact(new Contact("Danny Lee", "http://blog.51cto.com/7308310", "liqinwyyx@163.com"))
//版本号
.version("1.0.0")
.build();
}
private ApiKey apiKey() {
return new ApiKey("BearerToken", "Authorization", "header");
}
private SecurityContext securityContext() {
return SecurityContext.builder()
.securityReferences(defaultAuth())
.forPaths(PathSelectors.regex("/.*"))
.build();
}
List<SecurityReference> defaultAuth() {
AuthorizationScope authorizationScope = new AuthorizationScope("global", "accessEverything");
AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
authorizationScopes[0] = authorizationScope;
return newArrayList(new SecurityReference("BearerToken", authorizationScopes));
}
}
......@@ -53,19 +53,19 @@ public class ShiroConfig {
// 设置拦截器集合
Map<String, String> filterChainDefinitionMap = new LinkedHashMap<String, String>();
// filterChainDefinitionMap.put("/authInformation/save", "anon");//存储设备IMEI号和手机SIM卡ID号
// filterChainDefinitionMap.put("/sys/login", "anon"); // 登录页面-身份认证
// filterChainDefinitionMap.put("/sys/registered", "anon"); // 注册页面
// filterChainDefinitionMap.put("/swagger-ui.html", "anon"); // swagger接口-匿名访问
// filterChainDefinitionMap.put("/swagger/**", "anon");
// filterChainDefinitionMap.put("/admin/anon/**", "anon");
// filterChainDefinitionMap.put("/webjars/springfox-swagger-ui/**", "anon");
// filterChainDefinitionMap.put("/swagger-resources/**", "anon");
// filterChainDefinitionMap.put("/v2/api-docs", "anon");
// filterChainDefinitionMap.put("/upload_flowChart/**", "anon");//图片地址
// filterChainDefinitionMap.put("/webSocket/**", "anon");//socket
// filterChainDefinitionMap.put("/message/**", "anon");//消息推送接口
// filterChainDefinitionMap.put("/**", "oauth2"); // 其他路径均需要身份认证,一般位于最下面,优先级最低
filterChainDefinitionMap.put("/authInformation/save", "anon");//存储设备IMEI号和手机SIM卡ID号
filterChainDefinitionMap.put("/sys/login", "anon"); // 登录页面-身份认证
filterChainDefinitionMap.put("/sys/registered", "anon"); // 注册页面
filterChainDefinitionMap.put("/swagger-ui.html", "anon"); // swagger接口-匿名访问
filterChainDefinitionMap.put("/swagger/**", "anon");
filterChainDefinitionMap.put("/user/**", "anon");
filterChainDefinitionMap.put("/webjars/springfox-swagger-ui/**", "anon");
filterChainDefinitionMap.put("/swagger-resources/**", "anon");
filterChainDefinitionMap.put("/v2/api-docs", "anon");
filterChainDefinitionMap.put("/upload_flowChart/**", "anon");//图片地址
filterChainDefinitionMap.put("/webSocket/**", "anon");//socket
filterChainDefinitionMap.put("/message/**", "anon");//消息推送接口
filterChainDefinitionMap.put("/**", "oauth2"); // 其他路径均需要身份认证,一般位于最下面,优先级最低
// 设置拦截器
shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap);
......
......@@ -99,7 +99,7 @@ public class AuthRealm extends AuthorizingRealm {
throw new IncorrectCredentialsException(RespCodeEnum.TOKEN_IS_NOT_TIMEOUT.getMsg());
}*/
//查询用户信息
User user = authUserService.getById(userEntity.getId());
User user = authUserService.getByUserId(userEntity.getId());
// 判断请求token与redis中是否相同,如果token被刷新,则不判断
if (!refreshFlag && !StringUtils.equals(accessToken, redisToken)) {
throw new IncorrectCredentialsException(RespCodeEnum.NO_AUTH_REQUEST.getMsg());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment