fix bug
This commit is contained in:
@ -1,19 +1,15 @@
|
||||
/**
|
||||
* Copyright (C) 2018-2021
|
||||
* All rights reserved, Designed By www.yixiang.co
|
||||
|
||||
*/
|
||||
package co.yixiang.modules.security.service;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import co.yixiang.constant.ShopConstants;
|
||||
import co.yixiang.modules.security.config.SecurityProperties;
|
||||
import co.yixiang.modules.security.security.vo.JwtUser;
|
||||
import co.yixiang.modules.user.vo.OnlineUser;
|
||||
import co.yixiang.utils.EncryptUtils;
|
||||
import co.yixiang.utils.FileUtil;
|
||||
import co.yixiang.utils.PageUtil;
|
||||
import co.yixiang.utils.RedisUtils;
|
||||
import co.yixiang.utils.StringUtils;
|
||||
import co.yixiang.utils.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -21,12 +17,7 @@ import org.springframework.stereotype.Service;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
@ -50,18 +41,18 @@ public class OnlineUserService {
|
||||
* @param token /
|
||||
* @param request /
|
||||
*/
|
||||
public void save(JwtUser jwtUser, String token, HttpServletRequest request){
|
||||
public void save(JwtUser jwtUser, String token, HttpServletRequest request) {
|
||||
String job = jwtUser.getDept() + "/" + jwtUser.getJob();
|
||||
String ip = StringUtils.getIp(request);
|
||||
String browser = StringUtils.getBrowser(request);
|
||||
String address = StringUtils.getCityInfo(ip);
|
||||
OnlineUser onlineUser = null;
|
||||
try {
|
||||
onlineUser = new OnlineUser(jwtUser.getUsername(), jwtUser.getNickName(), job, browser , ip, address, EncryptUtils.desEncrypt(token), new Date());
|
||||
onlineUser = new OnlineUser(jwtUser.getUsername(), jwtUser.getNickName(), job, browser, ip, address, EncryptUtils.desEncrypt(token), new Date());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
redisUtils.set(properties.getOnlineKey() + token, onlineUser, properties.getTokenValidityInSeconds()/1000);
|
||||
redisUtils.set(properties.getOnlineKey() + token, onlineUser, properties.getTokenValidityInSeconds() / 1000);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -70,10 +61,10 @@ public class OnlineUserService {
|
||||
* @param pageable /
|
||||
* @return /
|
||||
*/
|
||||
public Map<String,Object> getAll(String filter, int type, Pageable pageable){
|
||||
List<OnlineUser> onlineUsers = getAll(filter,type);
|
||||
public Map<String, Object> getAll(String filter, int type, Pageable pageable) {
|
||||
List<OnlineUser> onlineUsers = getAll(filter, type);
|
||||
return PageUtil.toPage(
|
||||
PageUtil.toPage(pageable.getPageNumber(),pageable.getPageSize(),onlineUsers),
|
||||
PageUtil.toPage(pageable.getPageNumber(), pageable.getPageSize(), onlineUsers),
|
||||
onlineUsers.size()
|
||||
);
|
||||
}
|
||||
@ -83,11 +74,11 @@ public class OnlineUserService {
|
||||
* @param filter /
|
||||
* @return /
|
||||
*/
|
||||
public List<OnlineUser> getAll(String filter,int type){
|
||||
public List<OnlineUser> getAll(String filter, int type) {
|
||||
List<String> keys = null;
|
||||
if(type == 1){
|
||||
if (type == 1) {
|
||||
keys = redisUtils.scan(ShopConstants.YSHOP_APP_LOGIN_USER + "*");
|
||||
}else{
|
||||
} else {
|
||||
keys = redisUtils.scan(properties.getOnlineKey() + "*");
|
||||
}
|
||||
|
||||
@ -96,8 +87,8 @@ public class OnlineUserService {
|
||||
List<OnlineUser> onlineUsers = new ArrayList<>();
|
||||
for (String key : keys) {
|
||||
OnlineUser onlineUser = (OnlineUser) redisUtils.get(key);
|
||||
if(StringUtils.isNotBlank(filter)){
|
||||
if(onlineUser.toString().contains(filter)){
|
||||
if (StringUtils.isNotBlank(filter)) {
|
||||
if (onlineUser.toString().contains(filter)) {
|
||||
onlineUsers.add(onlineUser);
|
||||
}
|
||||
} else {
|
||||
@ -125,8 +116,8 @@ public class OnlineUserService {
|
||||
* @throws Exception /
|
||||
*/
|
||||
public void kickOutT(String key) throws Exception {
|
||||
|
||||
String keyt = ShopConstants.YSHOP_APP_LOGIN_USER + EncryptUtils.desDecrypt(key);
|
||||
String[] split = StrUtil.split(key, ":");
|
||||
String keyt = ShopConstants.YSHOP_APP_LOGIN_USER + split[0] + ":" + EncryptUtils.desDecrypt(split[1]);
|
||||
redisUtils.del(keyt);
|
||||
|
||||
}
|
||||
@ -149,7 +140,7 @@ public class OnlineUserService {
|
||||
public void download(List<OnlineUser> all, HttpServletResponse response) throws IOException {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (OnlineUser user : all) {
|
||||
Map<String,Object> map = new LinkedHashMap<>();
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("用户名", user.getUserName());
|
||||
map.put("用户昵称", user.getNickName());
|
||||
map.put("登录IP", user.getIp());
|
||||
@ -167,29 +158,29 @@ public class OnlineUserService {
|
||||
* @return /
|
||||
*/
|
||||
public OnlineUser getOne(String key) {
|
||||
return (OnlineUser)redisUtils.get(key);
|
||||
return (OnlineUser) redisUtils.get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测用户是否在之前已经登录,已经登录踢下线
|
||||
* @param userName 用户名
|
||||
*/
|
||||
public void checkLoginOnUser(String userName, String igoreToken){
|
||||
List<OnlineUser> onlineUsers = getAll(userName,0);
|
||||
if(onlineUsers ==null || onlineUsers.isEmpty()){
|
||||
public void checkLoginOnUser(String userName, String igoreToken) {
|
||||
List<OnlineUser> onlineUsers = getAll(userName, 0);
|
||||
if (onlineUsers == null || onlineUsers.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
for(OnlineUser onlineUser:onlineUsers){
|
||||
if(onlineUser.getUserName().equals(userName)){
|
||||
for (OnlineUser onlineUser : onlineUsers) {
|
||||
if (onlineUser.getUserName().equals(userName)) {
|
||||
try {
|
||||
String token =EncryptUtils.desDecrypt(onlineUser.getKey());
|
||||
if(StringUtils.isNotBlank(igoreToken)&&!igoreToken.equals(token)){
|
||||
String token = EncryptUtils.desDecrypt(onlineUser.getKey());
|
||||
if (StringUtils.isNotBlank(igoreToken) && !igoreToken.equals(token)) {
|
||||
this.kickOut(onlineUser.getKey());
|
||||
}else if(StringUtils.isBlank(igoreToken)){
|
||||
} else if (StringUtils.isBlank(igoreToken)) {
|
||||
this.kickOut(onlineUser.getKey());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("checkUser is error",e);
|
||||
log.error("checkUser is error", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,15 +20,18 @@ import co.yixiang.constant.ShopConstants;
|
||||
import co.yixiang.enums.AppFromEnum;
|
||||
import co.yixiang.modules.auth.param.LoginParam;
|
||||
import co.yixiang.modules.auth.param.RegParam;
|
||||
import co.yixiang.modules.mp.config.WxMaConfiguration;
|
||||
import co.yixiang.modules.mp.config.WxMpConfiguration;
|
||||
import co.yixiang.modules.shop.domain.YxSystemAttachment;
|
||||
import co.yixiang.modules.shop.service.YxSystemAttachmentService;
|
||||
import co.yixiang.modules.user.domain.YxUser;
|
||||
import co.yixiang.modules.user.service.YxUserService;
|
||||
import co.yixiang.modules.user.service.dto.WechatUserDto;
|
||||
import co.yixiang.modules.user.vo.OnlineUser;
|
||||
import co.yixiang.modules.mp.config.WxMpConfiguration;
|
||||
import co.yixiang.modules.mp.config.WxMaConfiguration;
|
||||
import co.yixiang.utils.*;
|
||||
import co.yixiang.utils.EncryptUtils;
|
||||
import co.yixiang.utils.RedisUtils;
|
||||
import co.yixiang.utils.ShopKeyUtils;
|
||||
import co.yixiang.utils.StringUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -69,10 +72,9 @@ public class AuthService {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 小程序登陆
|
||||
*
|
||||
* @param loginParam loginParam
|
||||
* @return long
|
||||
*/
|
||||
@ -101,7 +103,7 @@ public class AuthService {
|
||||
}
|
||||
|
||||
YxUser yxUser = userService.getOne(Wrappers.<YxUser>lambdaQuery()
|
||||
.eq(YxUser::getUsername, openid),false);
|
||||
.eq(YxUser::getUsername, openid), false);
|
||||
|
||||
if (ObjectUtil.isNull(yxUser)) {
|
||||
|
||||
@ -135,7 +137,7 @@ public class AuthService {
|
||||
userService.save(yxUser);
|
||||
|
||||
} else {
|
||||
WechatUserDto wechatUser =yxUser.getWxProfile();
|
||||
WechatUserDto wechatUser = yxUser.getWxProfile();
|
||||
if ((StrUtil.isBlank(wechatUser.getRoutineOpenid()) && StrUtil.isNotBlank(session.getOpenid()))
|
||||
|| (StrUtil.isBlank(wechatUser.getUnionId()) && StrUtil.isNotBlank(session.getUnionid()))) {
|
||||
wechatUser.setRoutineOpenid(session.getOpenid());
|
||||
@ -161,12 +163,13 @@ public class AuthService {
|
||||
|
||||
/**
|
||||
* 公众号登陆
|
||||
* @param code code码
|
||||
*
|
||||
* @param code code码
|
||||
* @param spread 上级用户
|
||||
* @return uid
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public YxUser wechatLogin(String code,String spread){
|
||||
public YxUser wechatLogin(String code, String spread) {
|
||||
try {
|
||||
WxMpService wxService = WxMpConfiguration.getWxMpService();
|
||||
WxOAuth2AccessToken wxOAuth2AccessToken = wxService.getOAuth2Service().getAccessToken(code);
|
||||
@ -180,11 +183,11 @@ public class AuthService {
|
||||
}
|
||||
|
||||
YxUser yxUser = userService.getOne(Wrappers.<YxUser>lambdaQuery()
|
||||
.eq(YxUser::getUsername,openid),false);
|
||||
.eq(YxUser::getUsername, openid), false);
|
||||
|
||||
//long uid = 0;
|
||||
YxUser returnUser = null;
|
||||
if(yxUser == null){
|
||||
if (yxUser == null) {
|
||||
//过滤掉表情
|
||||
String nickname = wxMpUser.getNickname();
|
||||
log.info("昵称:{}", nickname);
|
||||
@ -218,11 +221,11 @@ public class AuthService {
|
||||
userService.save(user);
|
||||
|
||||
returnUser = user;
|
||||
}else{
|
||||
} else {
|
||||
returnUser = yxUser;
|
||||
WechatUserDto wechatUser = yxUser.getWxProfile();
|
||||
if((StrUtil.isBlank(wechatUser.getOpenid()) && StrUtil.isNotBlank(wxMpUser.getOpenId()))
|
||||
|| (StrUtil.isBlank(wechatUser.getUnionId()) && StrUtil.isNotBlank(wxMpUser.getUnionId()))){
|
||||
if ((StrUtil.isBlank(wechatUser.getOpenid()) && StrUtil.isNotBlank(wxMpUser.getOpenId()))
|
||||
|| (StrUtil.isBlank(wechatUser.getUnionId()) && StrUtil.isNotBlank(wxMpUser.getUnionId()))) {
|
||||
wechatUser.setOpenid(wxMpUser.getOpenId());
|
||||
wechatUser.setUnionId(wxMpUser.getUnionId());
|
||||
|
||||
@ -234,9 +237,9 @@ public class AuthService {
|
||||
|
||||
}
|
||||
|
||||
userService.setSpread(spread,returnUser.getUid());
|
||||
userService.setSpread(spread, returnUser.getUid());
|
||||
|
||||
log.error("spread:{}",spread);
|
||||
log.error("spread:{}", spread);
|
||||
|
||||
return returnUser;
|
||||
|
||||
@ -250,10 +253,11 @@ public class AuthService {
|
||||
|
||||
/**
|
||||
* 注册
|
||||
*
|
||||
* @param param RegDTO
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void register(RegParam param){
|
||||
public void register(RegParam param) {
|
||||
|
||||
String account = param.getAccount();
|
||||
String ip = IpUtil.getRequestIp();
|
||||
@ -273,7 +277,7 @@ public class AuthService {
|
||||
//设置推广关系
|
||||
if (StrUtil.isNotBlank(param.getInviteCode())) {
|
||||
YxSystemAttachment systemAttachment = systemAttachmentService.getByCode(param.getInviteCode());
|
||||
if(systemAttachment != null){
|
||||
if (systemAttachment != null) {
|
||||
userService.setSpread(String.valueOf(systemAttachment.getUid()),
|
||||
user.getUid());
|
||||
}
|
||||
@ -284,18 +288,19 @@ public class AuthService {
|
||||
|
||||
/**
|
||||
* 保存在线用户信息
|
||||
* @param yxUser /
|
||||
* @param token /
|
||||
*
|
||||
* @param yxUser /
|
||||
* @param token /
|
||||
* @param request /
|
||||
*/
|
||||
public void save(YxUser yxUser, String token, HttpServletRequest request){
|
||||
public void save(YxUser yxUser, String token, HttpServletRequest request) {
|
||||
String job = "yshop开发工程师";
|
||||
String ip = StringUtils.getIp(request);
|
||||
String browser = StringUtils.getBrowser(request);
|
||||
String address = StringUtils.getCityInfo(ip);
|
||||
OnlineUser onlineUser = null;
|
||||
try {
|
||||
onlineUser = new OnlineUser(yxUser.getUsername(), yxUser.getNickname(), job, browser ,
|
||||
onlineUser = new OnlineUser(yxUser.getUsername(), yxUser.getNickname(), job, browser,
|
||||
ip, address, EncryptUtils.desEncrypt(token), new Date());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@ -339,10 +344,11 @@ public class AuthService {
|
||||
|
||||
/**
|
||||
* 退出登录
|
||||
*
|
||||
* @param token /
|
||||
*/
|
||||
public void logout(String userName,String token) {
|
||||
String key = ShopConstants.YSHOP_APP_LOGIN_USER+ userName + ":" + token;
|
||||
public void logout(String userName, String token) {
|
||||
String key = ShopConstants.YSHOP_APP_LOGIN_USER + userName + ":" + token;
|
||||
redisUtils.del(key);
|
||||
}
|
||||
|
||||
@ -367,5 +373,4 @@ public class AuthService {
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -22,14 +22,15 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @date 2020-05-13
|
||||
*/
|
||||
public interface YxStoreSeckillService extends BaseService<YxStoreSeckill>{
|
||||
* @author hupeng
|
||||
* @date 2020-05-13
|
||||
*/
|
||||
public interface YxStoreSeckillService extends BaseService<YxStoreSeckill> {
|
||||
|
||||
|
||||
/**
|
||||
* 产品详情
|
||||
*
|
||||
* @param id 秒杀商品id
|
||||
* @return StoreSeckillVo
|
||||
*/
|
||||
@ -37,7 +38,8 @@ public interface YxStoreSeckillService extends BaseService<YxStoreSeckill>{
|
||||
|
||||
/**
|
||||
* 秒杀产品列表
|
||||
* @param page page
|
||||
*
|
||||
* @param page page
|
||||
* @param limit limit
|
||||
* @return list
|
||||
*/
|
||||
@ -45,33 +47,37 @@ public interface YxStoreSeckillService extends BaseService<YxStoreSeckill>{
|
||||
|
||||
/**
|
||||
* 秒杀产品列表(首页用)
|
||||
* @param page page
|
||||
*
|
||||
* @param page page
|
||||
* @param limit limit
|
||||
* @return list
|
||||
*/
|
||||
List<YxStoreSeckillQueryVo> getList(int page, int limit);
|
||||
|
||||
/**
|
||||
* 查询数据分页
|
||||
* @param criteria 条件
|
||||
* @param pageable 分页参数
|
||||
* @return Map<String,Object>
|
||||
*/
|
||||
Map<String,Object> queryAll(YxStoreSeckillQueryCriteria criteria, Pageable pageable);
|
||||
* 查询数据分页
|
||||
*
|
||||
* @param criteria 条件
|
||||
* @param pageable 分页参数
|
||||
* @return Map<String, Object>
|
||||
*/
|
||||
Map<String, Object> queryAll(YxStoreSeckillQueryCriteria criteria, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 查询所有数据不分页
|
||||
* @param criteria 条件参数
|
||||
* @return List<YxStoreSeckillDto>
|
||||
*/
|
||||
* 查询所有数据不分页
|
||||
*
|
||||
* @param criteria 条件参数
|
||||
* @return List<YxStoreSeckillDto>
|
||||
*/
|
||||
List<YxStoreSeckill> queryAll(YxStoreSeckillQueryCriteria criteria);
|
||||
|
||||
/**
|
||||
* 导出数据
|
||||
* @param all 待导出的数据
|
||||
* @param response /
|
||||
* @throws IOException /
|
||||
*/
|
||||
* 导出数据
|
||||
*
|
||||
* @param all 待导出的数据
|
||||
* @param response /
|
||||
* @throws IOException /
|
||||
*/
|
||||
void download(List<YxStoreSeckillDto> all, HttpServletResponse response) throws IOException;
|
||||
|
||||
boolean saveSeckill(YxStoreSeckillDto resources);
|
||||
|
||||
@ -79,16 +79,6 @@ public class YxStoreSeckillServiceImpl extends BaseServiceImpl<YxStoreSeckillMap
|
||||
@Autowired
|
||||
private YxShippingTemplatesService shippingTemplatesService;
|
||||
|
||||
|
||||
// @Override
|
||||
// public YxStoreSeckill getSeckill(int id) {
|
||||
// LambdaQueryWrapper<YxStoreSeckill> wrapper = new LambdaQueryWrapper<>();
|
||||
// int nowTime = OrderUtil.getSecondTimestampTwo();
|
||||
// wrapper.eq("id",id).eq("is_del",0).eq("status",1)
|
||||
// .le("start_time",nowTime).ge("stop_time",nowTime);
|
||||
// return yxStoreSeckillMapper.selectOne(wrapper);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 产品详情
|
||||
* @param id 砍价商品id
|
||||
@ -114,7 +104,7 @@ public class YxStoreSeckillServiceImpl extends BaseServiceImpl<YxStoreSeckillMap
|
||||
String tempName = "";
|
||||
if(StrUtil.isBlank(storeFreePostage)
|
||||
|| !NumberUtil.isNumber(storeFreePostage)
|
||||
|| Integer.valueOf(storeFreePostage) == 0){
|
||||
|| Integer.parseInt(storeFreePostage) == 0){
|
||||
tempName = "全国包邮";
|
||||
}else{
|
||||
YxShippingTemplates shippingTemplates = shippingTemplatesService.getById(storeSeckill.getTempId());
|
||||
|
||||
@ -46,5 +46,5 @@ public interface YxStoreProductRuleService extends BaseService<YxStoreProductRu
|
||||
* @param response /
|
||||
* @throws IOException /
|
||||
*/
|
||||
void download(List<YxStoreProductRuleDto> all, HttpServletResponse response) throws IOException;
|
||||
void download(List<YxStoreProductRule> all, HttpServletResponse response) throws IOException;
|
||||
}
|
||||
|
||||
@ -88,6 +88,10 @@ public class YxStoreProductAttrServiceImpl extends BaseServiceImpl<StoreProductA
|
||||
attrGroup.add(yxStoreProductAttr);
|
||||
}
|
||||
|
||||
/*int count = storeProductAttrValueService.count(Wrappers.<YxStoreProductAttrValue>lambdaQuery().eq(YxStoreProductAttrValue::getProductId, productId));
|
||||
if (count > 0 ) {
|
||||
throw new BadRequestException("该产品已被添加到其他活动,禁止操作!");
|
||||
}*/
|
||||
|
||||
List<YxStoreProductAttrValue> valueGroup = new ArrayList<>();
|
||||
for (ProductFormatDto productFormatDto : attrs) {
|
||||
|
||||
@ -64,9 +64,9 @@ public class YxStoreProductRuleServiceImpl extends BaseServiceImpl<YxStoreProduc
|
||||
|
||||
|
||||
@Override
|
||||
public void download(List<YxStoreProductRuleDto> all, HttpServletResponse response) throws IOException {
|
||||
public void download(List<YxStoreProductRule> all, HttpServletResponse response) throws IOException {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (YxStoreProductRuleDto yxStoreProductRule : all) {
|
||||
for (YxStoreProductRule yxStoreProductRule : all) {
|
||||
Map<String,Object> map = new LinkedHashMap<>();
|
||||
map.put("规格名称", yxStoreProductRule.getRuleName());
|
||||
map.put("规格值", yxStoreProductRule.getRuleValue());
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
/**
|
||||
* Copyright (C) 2018-2021
|
||||
* All rights reserved, Designed By www.yixiang.co
|
||||
|
||||
*/
|
||||
package co.yixiang.modules.activity.rest;
|
||||
|
||||
@ -43,9 +42,9 @@ import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @date 2019-12-14
|
||||
*/
|
||||
* @author hupeng
|
||||
* @date 2019-12-14
|
||||
*/
|
||||
@Api(tags = "商城:秒杀管理")
|
||||
@RestController
|
||||
@RequestMapping("api")
|
||||
@ -57,6 +56,7 @@ public class StoreSeckillController {
|
||||
private final YxStoreProductRuleService yxStoreProductRuleService;
|
||||
private final YxStoreProductAttrValueService storeProductAttrValueService;
|
||||
private final YxStoreProductAttrResultService yxStoreProductAttrResultService;
|
||||
|
||||
public StoreSeckillController(IGenerator generator, YxStoreSeckillService yxStoreSeckillService, YxShippingTemplatesService yxShippingTemplatesService,
|
||||
YxStoreProductRuleService yxStoreProductRuleService, YxStoreProductAttrValueService storeProductAttrValueService,
|
||||
YxStoreProductAttrResultService yxStoreProductAttrResultService) {
|
||||
@ -72,12 +72,12 @@ public class StoreSeckillController {
|
||||
@ApiOperation(value = "列表")
|
||||
@GetMapping(value = "/yxStoreSeckill")
|
||||
@PreAuthorize("hasAnyRole('admin','YXSTORESECKILL_ALL','YXSTORESECKILL_SELECT')")
|
||||
public ResponseEntity getYxStoreSeckills(YxStoreSeckillQueryCriteria criteria, Pageable pageable){
|
||||
return new ResponseEntity<>(yxStoreSeckillService.queryAll(criteria,pageable),HttpStatus.OK);
|
||||
public ResponseEntity getYxStoreSeckills(YxStoreSeckillQueryCriteria criteria, Pageable pageable) {
|
||||
return new ResponseEntity<>(yxStoreSeckillService.queryAll(criteria, pageable), HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
@CacheEvict(cacheNames = ShopConstants.YSHOP_REDIS_INDEX_KEY,allEntries = true)
|
||||
@CacheEvict(cacheNames = ShopConstants.YSHOP_REDIS_INDEX_KEY, allEntries = true)
|
||||
@Log("发布")
|
||||
@ApiOperation(value = "发布")
|
||||
@PutMapping(value = "/yxStoreSeckill")
|
||||
@ -90,71 +90,73 @@ public class StoreSeckillController {
|
||||
return new ResponseEntity(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
}
|
||||
@CacheEvict(cacheNames = ShopConstants.YSHOP_REDIS_INDEX_KEY,allEntries = true)
|
||||
|
||||
@CacheEvict(cacheNames = ShopConstants.YSHOP_REDIS_INDEX_KEY, allEntries = true)
|
||||
@ForbidSubmit
|
||||
@Log("删除")
|
||||
@ApiOperation(value = "删除")
|
||||
@DeleteMapping(value = "/yxStoreSeckill/{id}")
|
||||
@PreAuthorize("hasAnyRole('admin','YXSTORESECKILL_ALL','YXSTORESECKILL_DELETE')")
|
||||
public ResponseEntity delete(@PathVariable Integer id){
|
||||
public ResponseEntity delete(@PathVariable Integer id) {
|
||||
yxStoreSeckillService.removeById(id);
|
||||
return new ResponseEntity(HttpStatus.OK);
|
||||
}
|
||||
@CacheEvict(cacheNames = ShopConstants.YSHOP_REDIS_INDEX_KEY,allEntries = true)
|
||||
|
||||
@CacheEvict(cacheNames = ShopConstants.YSHOP_REDIS_INDEX_KEY, allEntries = true)
|
||||
@Log("新增秒杀")
|
||||
@ApiOperation(value = "新增秒杀")
|
||||
@PostMapping(value = "/yxStoreSeckill")
|
||||
@PreAuthorize("hasAnyRole('admin','YXSTORESECKILL_ALL','YXSTORESECKILL_EDIT')")
|
||||
public ResponseEntity add(@Validated @RequestBody YxStoreSeckillDto resources){
|
||||
return new ResponseEntity<>(yxStoreSeckillService.saveSeckill(resources),HttpStatus.CREATED);
|
||||
public ResponseEntity add(@Validated @RequestBody YxStoreSeckillDto resources) {
|
||||
return new ResponseEntity<>(yxStoreSeckillService.saveSeckill(resources), HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取商品信息")
|
||||
@GetMapping(value = "/yxStoreSecKill/info/{id}")
|
||||
public ResponseEntity info(@PathVariable Long id){
|
||||
Map<String,Object> map = new LinkedHashMap<>(3);
|
||||
public ResponseEntity info(@PathVariable Long id) {
|
||||
Map<String, Object> map = new LinkedHashMap<>(3);
|
||||
|
||||
//运费模板
|
||||
List<YxShippingTemplates> shippingTemplatesList = yxShippingTemplatesService.list();
|
||||
map.put("tempList", shippingTemplatesList);
|
||||
|
||||
//商品规格
|
||||
map.put("ruleList",yxStoreProductRuleService.list());
|
||||
map.put("ruleList", yxStoreProductRuleService.list());
|
||||
|
||||
|
||||
if(id == 0){
|
||||
return new ResponseEntity<>(map,HttpStatus.OK);
|
||||
if (id == 0) {
|
||||
return new ResponseEntity<>(map, HttpStatus.OK);
|
||||
}
|
||||
|
||||
//处理商品详情
|
||||
YxStoreSeckill yxStoreSeckill = yxStoreSeckillService.getById(id);
|
||||
YxStoreSeckillDto productDto = new YxStoreSeckillDto();
|
||||
BeanUtil.copyProperties(yxStoreSeckill,productDto,"images");
|
||||
BeanUtil.copyProperties(yxStoreSeckill, productDto, "images");
|
||||
productDto.setSliderImage(Arrays.asList(yxStoreSeckill.getImages().split(",")));
|
||||
YxStoreProductAttrResult storeProductAttrResult = yxStoreProductAttrResultService
|
||||
.getOne(Wrappers.<YxStoreProductAttrResult>lambdaQuery()
|
||||
.eq(YxStoreProductAttrResult::getProductId,yxStoreSeckill.getProductId()).last("limit 1"));
|
||||
.eq(YxStoreProductAttrResult::getProductId, yxStoreSeckill.getProductId()).last("limit 1"));
|
||||
JSONObject result = JSON.parseObject(storeProductAttrResult.getResult());
|
||||
|
||||
List<YxStoreProductAttrValue> attrValues = storeProductAttrValueService.list(new LambdaQueryWrapper<YxStoreProductAttrValue>().eq(YxStoreProductAttrValue::getProductId, yxStoreSeckill.getProductId()));
|
||||
List<ProductFormatDto> productFormatDtos =attrValues.stream().map(i ->{
|
||||
List<ProductFormatDto> productFormatDtos = attrValues.stream().map(i -> {
|
||||
ProductFormatDto productFormatDto = new ProductFormatDto();
|
||||
BeanUtils.copyProperties(i,productFormatDto);
|
||||
BeanUtils.copyProperties(i, productFormatDto);
|
||||
productFormatDto.setPic(i.getImage());
|
||||
return productFormatDto;
|
||||
}).collect(Collectors.toList());
|
||||
if(SpecTypeEnum.TYPE_1.getValue().equals(yxStoreSeckill.getSpecType())){
|
||||
if (SpecTypeEnum.TYPE_1.getValue().equals(yxStoreSeckill.getSpecType())) {
|
||||
productDto.setAttr(new ProductFormatDto());
|
||||
productDto.setAttrs(productFormatDtos);
|
||||
productDto.setItems(result.getObject("attr",ArrayList.class));
|
||||
}else{
|
||||
productDto.setItems(result.getObject("attr", ArrayList.class));
|
||||
} else {
|
||||
productFormat(productDto, result);
|
||||
}
|
||||
|
||||
|
||||
map.put("productInfo",productDto);
|
||||
map.put("productInfo", productDto);
|
||||
|
||||
return new ResponseEntity<>(map,HttpStatus.OK);
|
||||
return new ResponseEntity<>(map, HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -163,7 +165,7 @@ public class StoreSeckillController {
|
||||
* @param result
|
||||
*/
|
||||
private void productFormat(YxStoreSeckillDto productDto, JSONObject result) {
|
||||
Map<String,Object> mapAttr = (Map<String,Object>) result.getObject("value",ArrayList.class).get(0);
|
||||
Map<String, Object> mapAttr = (Map<String, Object>) result.getObject("value", ArrayList.class).get(0);
|
||||
ProductFormatDto productFormatDto = ProductFormatDto.builder()
|
||||
.pic(mapAttr.get("pic").toString())
|
||||
.price(Double.valueOf(mapAttr.get("price").toString()))
|
||||
|
||||
@ -55,7 +55,7 @@ public class StoreProductRuleController {
|
||||
@GetMapping(value = "/download")
|
||||
@PreAuthorize("@el.check('admin','yxStoreProductRule:list')")
|
||||
public void download(HttpServletResponse response, YxStoreProductRuleQueryCriteria criteria) throws IOException {
|
||||
yxStoreProductRuleService.download(generator.convert(yxStoreProductRuleService.queryAll(criteria), YxStoreProductRuleDto.class), response);
|
||||
yxStoreProductRuleService.download(yxStoreProductRuleService.queryAll(criteria) , response);
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
|
||||
Reference in New Issue
Block a user