feat(新增): SecKill管理
This commit is contained in:
parent
92c76e578c
commit
757ed89c1a
|
@ -58,8 +58,8 @@ public class CodeGet {
|
||||||
@NotNull
|
@NotNull
|
||||||
private static StrategyConfig getStrategyConfig() {
|
private static StrategyConfig getStrategyConfig() {
|
||||||
StrategyConfig strategy = new StrategyConfig();
|
StrategyConfig strategy = new StrategyConfig();
|
||||||
|
// TODO 要生成的表
|
||||||
strategy.setInclude("activity_info", "activity_rule", "activity_sku", "coupon_info", "coupon_range", "coupon_use");
|
strategy.setInclude("seckill", "seckill_sku", "seckill_sku_notice", "sku_info");
|
||||||
strategy.setNaming(NamingStrategy.underline_to_camel);// 数据库表映射到实体的命名策略
|
strategy.setNaming(NamingStrategy.underline_to_camel);// 数据库表映射到实体的命名策略
|
||||||
strategy.setColumnNaming(NamingStrategy.underline_to_camel);// 数据库表字段映射到实体的命名策略
|
strategy.setColumnNaming(NamingStrategy.underline_to_camel);// 数据库表字段映射到实体的命名策略
|
||||||
strategy.setEntityLombokModel(true); // lombok 模型 @Accessors(chain = true) setter链式操作
|
strategy.setEntityLombokModel(true); // lombok 模型 @Accessors(chain = true) setter链式操作
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
package com.atguigu.ssyx.vo.user;
|
package com.atguigu.ssyx.vo.user;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
|
||||||
import io.swagger.annotations.ApiModel;
|
import io.swagger.annotations.ApiModel;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -13,47 +15,48 @@ import lombok.Data;
|
||||||
* @author qy
|
* @author qy
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
@ApiModel(description = "用户地址")
|
@ApiModel(description = "用户地址")
|
||||||
public class LeaderAddressVo {
|
public class LeaderAddressVo {
|
||||||
|
@ApiModelProperty(value = "用户id")
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
@ApiModelProperty(value = "用户id")
|
@ApiModelProperty(value = "团长id")
|
||||||
private Long userId;
|
private Long leaderId;
|
||||||
|
|
||||||
@ApiModelProperty(value = "团长id")
|
@ApiModelProperty(value = "团长名称")
|
||||||
private Long leaderId;
|
private String leaderName;
|
||||||
|
|
||||||
@ApiModelProperty(value = "团长名称")
|
@ApiModelProperty(value = "团长电话")
|
||||||
private String leaderName;
|
private String leaderPhone;
|
||||||
|
|
||||||
@ApiModelProperty(value = "团长电话")
|
@ApiModelProperty(value = "仓库id")
|
||||||
private String leaderPhone;
|
private Long wareId;
|
||||||
|
|
||||||
@ApiModelProperty(value = "仓库id")
|
@ApiModelProperty(value = "提货点名称")
|
||||||
private Long wareId;
|
private String takeName;
|
||||||
|
|
||||||
@ApiModelProperty(value = "提货点名称")
|
@ApiModelProperty(value = "省")
|
||||||
private String takeName;
|
private String province;
|
||||||
|
|
||||||
@ApiModelProperty(value = "省")
|
@ApiModelProperty(value = "城市")
|
||||||
private String province;
|
private String city;
|
||||||
|
|
||||||
@ApiModelProperty(value = "城市")
|
@ApiModelProperty(value = "区域")
|
||||||
private String city;
|
private String district;
|
||||||
|
|
||||||
@ApiModelProperty(value = "区域")
|
@ApiModelProperty(value = "详细地址")
|
||||||
private String district;
|
private String detailAddress;
|
||||||
|
|
||||||
@ApiModelProperty(value = "详细地址")
|
@ApiModelProperty(value = "经度")
|
||||||
private String detailAddress;
|
private String longitude;
|
||||||
|
|
||||||
@ApiModelProperty(value = "经度")
|
@ApiModelProperty(value = "纬度")
|
||||||
private String longitude;
|
private String latitude;
|
||||||
|
|
||||||
@ApiModelProperty(value = "纬度")
|
|
||||||
private String latitude;
|
|
||||||
|
|
||||||
@ApiModelProperty(value = "门店照片")
|
|
||||||
private String storePath;
|
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "门店照片")
|
||||||
|
private String storePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,4 +46,19 @@ public class PermissionController {
|
||||||
permissionService.removeChildById(id);
|
permissionService.removeChildById(id);
|
||||||
return Result.success();
|
return Result.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "查询所有菜单和角色分配菜单")
|
||||||
|
@GetMapping("toAssign/{roleId}")
|
||||||
|
public Result<List<Permission>> toAssign(@PathVariable Long roleId) {
|
||||||
|
List<Permission> permissionList = permissionService.findMenuByRoleId(roleId);
|
||||||
|
return Result.success(permissionList);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "查询所有菜单和角色分配菜单")
|
||||||
|
@PostMapping("doAssign")
|
||||||
|
public Result<Permission> doAssign(@RequestParam Long roleId,
|
||||||
|
@RequestParam List<Long> permissions) {
|
||||||
|
permissionService.doAssign(roleId, permissions);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
package com.atguigu.ssyx.acl.mapper;
|
||||||
|
|
||||||
|
import com.atguigu.ssyx.model.acl.RolePermission;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface RolePermissionMapper extends BaseMapper<RolePermission> {
|
||||||
|
}
|
|
@ -20,4 +20,20 @@ public interface PermissionService extends IService<Permission> {
|
||||||
* @param id 删除ID
|
* @param id 删除ID
|
||||||
*/
|
*/
|
||||||
void removeChildById(Long id);
|
void removeChildById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询所有菜单和角色分配菜单
|
||||||
|
*
|
||||||
|
* @param roleId 角色Id
|
||||||
|
* @return 权限列表
|
||||||
|
*/
|
||||||
|
List<Permission> findMenuByRoleId(Long roleId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询所有菜单和角色分配菜单
|
||||||
|
*
|
||||||
|
* @param roleId 角色Id
|
||||||
|
* @param permissions 分配权限Id
|
||||||
|
*/
|
||||||
|
void doAssign(Long roleId, List<Long> permissions);
|
||||||
}
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package com.atguigu.ssyx.acl.service;
|
||||||
|
|
||||||
|
import com.atguigu.ssyx.model.acl.RolePermission;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
|
||||||
|
public interface RolePermissionService extends IService<RolePermission> {
|
||||||
|
}
|
|
@ -3,19 +3,25 @@ package com.atguigu.ssyx.acl.service.impl;
|
||||||
import com.atguigu.common.utils.PermissionHelper;
|
import com.atguigu.common.utils.PermissionHelper;
|
||||||
import com.atguigu.ssyx.acl.mapper.PermissionMapper;
|
import com.atguigu.ssyx.acl.mapper.PermissionMapper;
|
||||||
import com.atguigu.ssyx.acl.service.PermissionService;
|
import com.atguigu.ssyx.acl.service.PermissionService;
|
||||||
|
import com.atguigu.ssyx.acl.service.RolePermissionService;
|
||||||
import com.atguigu.ssyx.acl.service.module.PermissionServiceModule;
|
import com.atguigu.ssyx.acl.service.module.PermissionServiceModule;
|
||||||
import com.atguigu.ssyx.model.acl.Permission;
|
import com.atguigu.ssyx.model.acl.Permission;
|
||||||
|
import com.atguigu.ssyx.model.acl.RolePermission;
|
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class PermissionServiceImpl extends ServiceImpl<PermissionMapper, Permission> implements PermissionService {
|
public class PermissionServiceImpl extends ServiceImpl<PermissionMapper, Permission> implements PermissionService {
|
||||||
@Autowired
|
@Autowired
|
||||||
private PermissionServiceModule permissionServiceModule;
|
private PermissionServiceModule permissionServiceModule;
|
||||||
|
@Autowired
|
||||||
|
private RolePermissionService rolePermissionService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取所有菜单列表
|
* 获取所有菜单列表
|
||||||
|
@ -43,4 +49,52 @@ public class PermissionServiceImpl extends ServiceImpl<PermissionMapper, Permiss
|
||||||
// 调用方法根据多个菜单ID删除
|
// 调用方法根据多个菜单ID删除
|
||||||
baseMapper.deleteBatchIds(idList);
|
baseMapper.deleteBatchIds(idList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询所有菜单和角色分配菜单
|
||||||
|
*
|
||||||
|
* @param roleId 角色Id
|
||||||
|
* @return 权限列表
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<Permission> findMenuByRoleId(Long roleId) {
|
||||||
|
List<Permission> permissionList = list();
|
||||||
|
|
||||||
|
List<RolePermission> rolePermissionList = rolePermissionService.list(
|
||||||
|
Wrappers.<RolePermission>lambdaQuery().eq(RolePermission::getRoleId, roleId)
|
||||||
|
);
|
||||||
|
|
||||||
|
List<Long> permissionIdList = rolePermissionList.stream().map(RolePermission::getPermissionId).collect(Collectors.toList());
|
||||||
|
|
||||||
|
permissionList.forEach(permission -> {
|
||||||
|
if (permissionIdList.contains(permission.getId())) {
|
||||||
|
permission.setSelect(true);
|
||||||
|
}
|
||||||
|
permission.setSelect(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
return PermissionHelper.buildPermissions(permissionList);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询所有菜单和角色分配菜单
|
||||||
|
*
|
||||||
|
* @param roleId 角色Id
|
||||||
|
* @param permissions 分配权限Id
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void doAssign(Long roleId, List<Long> permissions) {
|
||||||
|
// 先删除之前分配的角色
|
||||||
|
rolePermissionService.remove(Wrappers.<RolePermission>lambdaQuery().eq(RolePermission::getRoleId, roleId));
|
||||||
|
ArrayList<RolePermission> list = new ArrayList<>();
|
||||||
|
|
||||||
|
permissions.forEach(permissionId -> {
|
||||||
|
RolePermission rolePermission = new RolePermission();
|
||||||
|
rolePermission.setPermissionId(permissionId);
|
||||||
|
rolePermission.setRoleId(roleId);
|
||||||
|
list.add(rolePermission);
|
||||||
|
});
|
||||||
|
|
||||||
|
rolePermissionService.saveBatch(list);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.atguigu.ssyx.acl.service.impl;
|
||||||
|
|
||||||
|
import com.atguigu.ssyx.acl.mapper.RolePermissionMapper;
|
||||||
|
import com.atguigu.ssyx.acl.service.RolePermissionService;
|
||||||
|
import com.atguigu.ssyx.model.acl.RolePermission;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class RolePermissionServiceImpl extends ServiceImpl<RolePermissionMapper, RolePermission> implements RolePermissionService {
|
||||||
|
}
|
|
@ -18,6 +18,11 @@
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.atguigu</groupId>
|
||||||
|
<artifactId>service-util</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.atguigu</groupId>
|
<groupId>com.atguigu</groupId>
|
||||||
<artifactId>service-product-client</artifactId>
|
<artifactId>service-product-client</artifactId>
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
package com.atguigu.ssyx.user.controller;
|
||||||
|
|
||||||
|
import com.atguigu.ssyx.common.result.Result;
|
||||||
|
import com.atguigu.ssyx.user.service.WeiXinApiService;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Api(tags = "用户微信接口")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/user/weixin")
|
||||||
|
public class WeiXinApiController {
|
||||||
|
@Autowired
|
||||||
|
private WeiXinApiService weChatService;
|
||||||
|
|
||||||
|
@ApiOperation(value = "微信登录获取openid(小程序)")
|
||||||
|
@GetMapping("/wxLogin/{code}")
|
||||||
|
public Result<Map<String, Object>> callback(@PathVariable String code) {
|
||||||
|
Map<String, Object> map = weChatService.callback(code);
|
||||||
|
return Result.success(map);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
package com.atguigu.ssyx.user.service;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public interface WeiXinApiService {
|
||||||
|
/**
|
||||||
|
* * 微信登录获取openid
|
||||||
|
*
|
||||||
|
* @param code 登录码
|
||||||
|
*/
|
||||||
|
Map<String, Object> callback(String code);
|
||||||
|
}
|
|
@ -0,0 +1,78 @@
|
||||||
|
package com.atguigu.ssyx.user.service.impl;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.atguigu.common.utils.JwtHelper;
|
||||||
|
import com.atguigu.ssyx.common.constant.RedisConst;
|
||||||
|
import com.atguigu.ssyx.common.exception.BunnyException;
|
||||||
|
import com.atguigu.ssyx.common.result.ResultCodeEnum;
|
||||||
|
import com.atguigu.ssyx.enums.UserType;
|
||||||
|
import com.atguigu.ssyx.model.user.User;
|
||||||
|
import com.atguigu.ssyx.user.service.UserService;
|
||||||
|
import com.atguigu.ssyx.user.service.WeiXinApiService;
|
||||||
|
import com.atguigu.ssyx.user.service.module.WeiXinApiServiceModule;
|
||||||
|
import com.atguigu.ssyx.user.utils.HttpClientUtils;
|
||||||
|
import com.atguigu.ssyx.vo.user.LeaderAddressVo;
|
||||||
|
import com.atguigu.ssyx.vo.user.UserLoginVo;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
public class WeiXinApiServiceImpl implements WeiXinApiService {
|
||||||
|
@Autowired
|
||||||
|
private WeiXinApiServiceModule module;
|
||||||
|
@Autowired
|
||||||
|
private UserService userService;
|
||||||
|
@Autowired
|
||||||
|
private RedisTemplate<String, Object> redisTemplate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* * 微信登录获取openid
|
||||||
|
*
|
||||||
|
* @param code 登录码
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> callback(String code) {
|
||||||
|
// 拿到微信返回code临时票据纸
|
||||||
|
String accessTokenUrl = module.getAccessTokenUrl(code);
|
||||||
|
try {
|
||||||
|
String result = HttpClientUtils.get(accessTokenUrl);
|
||||||
|
// 请求微信接口服,返回两个值 session_key 和 openId
|
||||||
|
JSONObject jsonObject = JSONObject.parseObject(result);
|
||||||
|
String accessToken = jsonObject.getString("session_key");
|
||||||
|
String openId = jsonObject.getString("openid");
|
||||||
|
// 先根据openid进行数据库查询
|
||||||
|
User user = userService.getUserByOpenId(openId);
|
||||||
|
// 如果没有查到用户信息,那么调用微信个人信息获取的接口
|
||||||
|
if (null == user) {
|
||||||
|
user = new User();
|
||||||
|
user.setOpenId(openId);
|
||||||
|
user.setNickName(openId);
|
||||||
|
user.setPhotoUrl("");
|
||||||
|
user.setUserType(UserType.USER);
|
||||||
|
user.setIsNew(0);
|
||||||
|
userService.save(user);
|
||||||
|
}
|
||||||
|
// 根据用户Id查询默认团长Id
|
||||||
|
LeaderAddressVo leaderAddressVo = userService.getLeaderAddressVoByUserId(user.getId());
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
String name = user.getNickName();
|
||||||
|
map.put("user", user);
|
||||||
|
map.put("leaderAddressVo", leaderAddressVo);
|
||||||
|
String token = JwtHelper.createToken(user.getId(), name);
|
||||||
|
map.put("token", token);
|
||||||
|
|
||||||
|
// 获取当前用户登录信息
|
||||||
|
UserLoginVo userLoginVo = userService.getUserLoginVo(user.getId());
|
||||||
|
redisTemplate.opsForValue().set(RedisConst.USER_LOGIN_KEY_PREFIX + user.getId(), userLoginVo, RedisConst.USERKEY_TIMEOUT, TimeUnit.DAYS);
|
||||||
|
return map;
|
||||||
|
} catch (Exception exception) {
|
||||||
|
throw new BunnyException(ResultCodeEnum.FETCH_ACCESSTOKEN_FAILD);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
package com.atguigu.ssyx.user.service.module;
|
||||||
|
|
||||||
|
import com.atguigu.ssyx.common.properties.WeChatProperties;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class WeiXinApiServiceModule {
|
||||||
|
@Autowired
|
||||||
|
private WeChatProperties weChatProperties;
|
||||||
|
|
||||||
|
public String getAccessTokenUrl(String code) {
|
||||||
|
String appId = weChatProperties.getAppId();
|
||||||
|
String appSecret = weChatProperties.getAppSecret();
|
||||||
|
|
||||||
|
// 使用code和appid以及appscrect换取access_token
|
||||||
|
String baseAccessTokenUrl = "https://api.weixin.qq.com/sns/jscode2session" +
|
||||||
|
"?appid=%s" +
|
||||||
|
"&secret=%s" +
|
||||||
|
"&js_code=%s" +
|
||||||
|
"&grant_type=authorization_code";
|
||||||
|
|
||||||
|
// 拿着code+小程序Id+小程序秘钥 请求微信接口服务
|
||||||
|
return String.format(baseAccessTokenUrl, appId, appSecret, code);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue