商品详情完成
This commit is contained in:
1 parent
0fb64654f1
commit
fe2d6ebeea
11 files changed
+171
-10
No files matched your search
+16
-3
@@ -11,6 +11,9 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
|
|||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ClassName 全局异常处理
|
* @ClassName 全局异常处理
|
||||||
@@ -27,11 +30,21 @@ public class LightSecurityExceptionHandler {
|
|||||||
* @return 发生异常时的返回
|
* @return 发生异常时的返回
|
||||||
*/
|
*/
|
||||||
@ExceptionHandler(value = {LightSecurityException.class})
|
@ExceptionHandler(value = {LightSecurityException.class})
|
||||||
@ResponseStatus(HttpStatus.UNAUTHORIZED)
|
//@ResponseStatus(HttpStatus.UNAUTHORIZED)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public R error(LightSecurityException exception) {
|
public R error(HttpServletRequest request, LightSecurityException exception, HttpServletResponse response) {
|
||||||
return R.error(401,"授权失败");
|
//System.out.println(request.getMethod());
|
||||||
|
//System.out.println(exception.getMessage());
|
||||||
|
String str1 = "com.itmuch.lightsecurity.exception.LightSecurityException: 没有找到名为Authorization的header";
|
||||||
|
String str2 = "com.itmuch.lightsecurity.exception.LightSecurityException: Token invalided.";
|
||||||
|
if (exception.getMessage().equals(str1) || exception.getMessage().equals(str2)) {
|
||||||
|
response.setStatus(401);
|
||||||
|
return R.error(401, "授权失败");
|
||||||
}
|
}
|
||||||
|
return R.error(4000, exception.getMessage());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ExceptionHandler(value = {Exception.class})
|
@ExceptionHandler(value = {Exception.class})
|
||||||
|
|||||||
+17
-1
@@ -1,7 +1,12 @@
|
|||||||
package com.ruoyi.app.common.persistence.dao;
|
package com.ruoyi.app.common.persistence.dao;
|
||||||
|
|
||||||
import com.ruoyi.app.common.persistence.model.StoreSpecGoodsPrice;
|
import com.ruoyi.app.common.persistence.model.StoreSpecGoodsPrice;
|
||||||
import com.baomidou.mybatisplus.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.ruoyi.app.modular.shop.service.dto.ItemDTO;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@@ -13,4 +18,15 @@ import com.baomidou.mybatisplus.mapper.BaseMapper;
|
|||||||
*/
|
*/
|
||||||
public interface StoreSpecGoodsPriceMapper extends BaseMapper<StoreSpecGoodsPrice> {
|
public interface StoreSpecGoodsPriceMapper extends BaseMapper<StoreSpecGoodsPrice> {
|
||||||
|
|
||||||
|
@Select("select GROUP_CONCAT(`key` ORDER BY store_count desc SEPARATOR '_') as keystr" +
|
||||||
|
" from store_spec_goods_price where goods_id=#{goodsId}")
|
||||||
|
String goodsSpecKey(int goodsId);
|
||||||
|
|
||||||
|
@Select("<script> SELECT a.name,b.id,b.spec_id as specId,b.item FROM store_spec AS a " +
|
||||||
|
"INNER JOIN store_spec_item AS b ON a.id = b.spec_id " +
|
||||||
|
"WHERE b.id IN " +
|
||||||
|
"<foreach item='item' index='index' collection='list' open='(' separator=',' close=')'> #{item} </foreach>" +
|
||||||
|
"ORDER BY b.id </script>")
|
||||||
|
List<ItemDTO> goodsSpec(List<String> keys);
|
||||||
|
|
||||||
}
|
}
|
||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
package com.ruoyi.app.common.persistence.dao;
|
package com.ruoyi.app.common.persistence.dao;
|
||||||
|
|
||||||
import com.ruoyi.app.common.persistence.model.StoreSpecItem;
|
import com.ruoyi.app.common.persistence.model.StoreSpecItem;
|
||||||
import com.baomidou.mybatisplus.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.ruoyi.app.common.persistence.dao;
|
package com.ruoyi.app.common.persistence.dao;
|
||||||
|
|
||||||
import com.ruoyi.app.common.persistence.model.StoreSpec;
|
import com.ruoyi.app.common.persistence.model.StoreSpec;
|
||||||
import com.baomidou.mybatisplus.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
|
|||||||
+1
@@ -35,6 +35,7 @@ public class StoreSpecGoodsPrice extends Model<StoreSpecGoodsPrice> {
|
|||||||
/**
|
/**
|
||||||
* 规格键名
|
* 规格键名
|
||||||
*/
|
*/
|
||||||
|
@TableField("`key`")
|
||||||
private String key;
|
private String key;
|
||||||
/**
|
/**
|
||||||
* 规格键名中文
|
* 规格键名中文
|
||||||
|
|||||||
@@ -2,21 +2,22 @@ package com.ruoyi.app.modular.shop.controller;
|
|||||||
|
|
||||||
import com.itmuch.lightsecurity.jwt.UserOperator;
|
import com.itmuch.lightsecurity.jwt.UserOperator;
|
||||||
import com.ruoyi.app.common.R;
|
import com.ruoyi.app.common.R;
|
||||||
|
import com.ruoyi.app.common.exception.BadRequestException;
|
||||||
|
import com.ruoyi.app.common.persistence.model.StoreSpecGoodsPrice;
|
||||||
import com.ruoyi.app.modular.shop.service.dto.CateDTO;
|
import com.ruoyi.app.modular.shop.service.dto.CateDTO;
|
||||||
import com.ruoyi.app.modular.shop.service.dto.GoodsDTO;
|
import com.ruoyi.app.modular.shop.service.dto.GoodsDTO;
|
||||||
|
import com.ruoyi.app.modular.shop.service.dto.SpecItemDTO;
|
||||||
import com.ruoyi.app.modular.shop.service.impl.CateServiceImpl;
|
import com.ruoyi.app.modular.shop.service.impl.CateServiceImpl;
|
||||||
import com.ruoyi.app.modular.shop.service.impl.GoodsServiceImpl;
|
import com.ruoyi.app.modular.shop.service.impl.GoodsServiceImpl;
|
||||||
import com.ruoyi.app.modular.shop.service.mapper.GoodsMapper;
|
import com.ruoyi.app.modular.shop.service.mapper.GoodsMapper;
|
||||||
|
import com.ruoyi.app.modular.shop.service.vo.CollectVO;
|
||||||
import com.ruoyi.app.modular.shop.service.vo.PageVO;
|
import com.ruoyi.app.modular.shop.service.vo.PageVO;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -72,4 +73,27 @@ public class MallController {
|
|||||||
map.put("list",goods);
|
map.put("list",goods);
|
||||||
return R.success(map);
|
return R.success(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/shop/mall-goods-detail")
|
||||||
|
@ApiOperation(value = "商品详情",notes = "商品详情")
|
||||||
|
public R goodsDetail(@RequestParam(value = "goods_id",defaultValue = "0") int goodsId){
|
||||||
|
Map<String, StoreSpecGoodsPrice> specPrice = goodsService.goodsSpecPrice(goodsId);
|
||||||
|
GoodsDTO goodsDetail = goodsMapper.toDto(goodsService.getById(goodsId));
|
||||||
|
Map<String, SpecItemDTO> specs = goodsService.goodsSpec(goodsId);
|
||||||
|
|
||||||
|
Map<String,Object> map = new HashMap<>();
|
||||||
|
map.put("detail",goodsDetail);
|
||||||
|
map.put("spec_price",specPrice);
|
||||||
|
map.put("specs",specs);
|
||||||
|
return R.success(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/shop/mall-add-collect")
|
||||||
|
public R addCollect(@Validated @RequestBody CollectVO collectVO){
|
||||||
|
int userId = userOperator.getUser().getId();
|
||||||
|
//throw new BadRequestException("已经收藏过");
|
||||||
|
goodsService.addOrCancelCollect(collectVO.getGoodsId(),userId,1);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -5,9 +5,11 @@ package com.ruoyi.app.modular.shop.service;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.ruoyi.app.common.persistence.model.StoreGoods;
|
import com.ruoyi.app.common.persistence.model.StoreGoods;
|
||||||
|
import com.ruoyi.app.common.persistence.model.StoreSpecGoodsPrice;
|
||||||
import com.ruoyi.app.modular.shop.service.dto.GoodsDTO;
|
import com.ruoyi.app.modular.shop.service.dto.GoodsDTO;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
public interface IGoodsService extends IService<StoreGoods> {
|
public interface IGoodsService extends IService<StoreGoods> {
|
||||||
@@ -17,4 +19,8 @@ public interface IGoodsService extends IService<StoreGoods> {
|
|||||||
public boolean isCollect(int goodsId,int userId);
|
public boolean isCollect(int goodsId,int userId);
|
||||||
|
|
||||||
public List<StoreGoods> collectGoods(int page,int limit,int userId);
|
public List<StoreGoods> collectGoods(int page,int limit,int userId);
|
||||||
|
|
||||||
|
public Map<String,StoreSpecGoodsPrice> goodsSpecPrice(int goodsId);
|
||||||
|
|
||||||
|
public boolean addOrCancelCollect(int goodsId,int userId,int type);
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package com.ruoyi.app.modular.shop.service.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName ItemDTO
|
||||||
|
* @Author hupeng <610796224@qq.com>
|
||||||
|
* @Date 2019/9/9
|
||||||
|
**/
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ItemDTO {
|
||||||
|
private String name;
|
||||||
|
private int id;
|
||||||
|
private int specId;
|
||||||
|
private String item;
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package com.ruoyi.app.modular.shop.service.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName SpecItemDTO
|
||||||
|
* @Author hupeng <610796224@qq.com>
|
||||||
|
* @Date 2019/9/9
|
||||||
|
**/
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class SpecItemDTO {
|
||||||
|
private int itemId;
|
||||||
|
private String item;
|
||||||
|
}
|
||||||
@@ -9,19 +9,28 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.itmuch.lightsecurity.exception.LightSecurityException;
|
||||||
|
import com.ruoyi.app.common.exception.BadRequestException;
|
||||||
import com.ruoyi.app.common.persistence.dao.StoreGoodsCollectMapper;
|
import com.ruoyi.app.common.persistence.dao.StoreGoodsCollectMapper;
|
||||||
import com.ruoyi.app.common.persistence.dao.StoreGoodsMapper;
|
import com.ruoyi.app.common.persistence.dao.StoreGoodsMapper;
|
||||||
|
import com.ruoyi.app.common.persistence.dao.StoreSpecGoodsPriceMapper;
|
||||||
import com.ruoyi.app.common.persistence.model.StoreGoods;
|
import com.ruoyi.app.common.persistence.model.StoreGoods;
|
||||||
import com.ruoyi.app.common.persistence.model.StoreGoodsCollect;
|
import com.ruoyi.app.common.persistence.model.StoreGoodsCollect;
|
||||||
|
import com.ruoyi.app.common.persistence.model.StoreSpecGoodsPrice;
|
||||||
import com.ruoyi.app.modular.shop.service.IGoodsService;
|
import com.ruoyi.app.modular.shop.service.IGoodsService;
|
||||||
import com.ruoyi.app.modular.shop.service.dto.GoodsDTO;
|
import com.ruoyi.app.modular.shop.service.dto.GoodsDTO;
|
||||||
|
import com.ruoyi.app.modular.shop.service.dto.ItemDTO;
|
||||||
|
import com.ruoyi.app.modular.shop.service.dto.SpecItemDTO;
|
||||||
import com.ruoyi.app.modular.shop.service.mapper.GoodsMapper;
|
import com.ruoyi.app.modular.shop.service.mapper.GoodsMapper;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
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.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@@ -31,6 +40,7 @@ public class GoodsServiceImpl extends ServiceImpl<StoreGoodsMapper, StoreGoods>
|
|||||||
private final GoodsMapper goodsMapper;
|
private final GoodsMapper goodsMapper;
|
||||||
private final StoreGoodsMapper storeGoodsMapper;
|
private final StoreGoodsMapper storeGoodsMapper;
|
||||||
private final StoreGoodsCollectMapper storeGoodsCollectMapper;
|
private final StoreGoodsCollectMapper storeGoodsCollectMapper;
|
||||||
|
private final StoreSpecGoodsPriceMapper storeSpecGoodsPriceMapper;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -102,4 +112,43 @@ public class GoodsServiceImpl extends ServiceImpl<StoreGoodsMapper, StoreGoods>
|
|||||||
//System.out.println(list);
|
//System.out.println(list);
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String,StoreSpecGoodsPrice> goodsSpecPrice(int goodsId) {
|
||||||
|
QueryWrapper<StoreSpecGoodsPrice> wrapper = new QueryWrapper<>();
|
||||||
|
wrapper.eq("goods_id",goodsId);
|
||||||
|
List<StoreSpecGoodsPrice> specGoodsPriceList = storeSpecGoodsPriceMapper
|
||||||
|
.selectList(wrapper);
|
||||||
|
Map<String, StoreSpecGoodsPrice> listMap = specGoodsPriceList.stream().collect(
|
||||||
|
Collectors.toMap(StoreSpecGoodsPrice::getKey,o->o));
|
||||||
|
|
||||||
|
return listMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, SpecItemDTO> goodsSpec(int goodsId){
|
||||||
|
|
||||||
|
String keys = storeSpecGoodsPriceMapper.goodsSpecKey(goodsId);
|
||||||
|
String[] strArr = keys.split("_");
|
||||||
|
Map<String,SpecItemDTO> itemMap = new HashMap<>();
|
||||||
|
List<ItemDTO> items = storeSpecGoodsPriceMapper.goodsSpec(Arrays.asList(strArr));
|
||||||
|
for (ItemDTO itemDTO : items) {
|
||||||
|
SpecItemDTO specItemDTO = new SpecItemDTO();
|
||||||
|
specItemDTO.setItemId(itemDTO.getId());
|
||||||
|
specItemDTO.setItem(itemDTO.getItem());
|
||||||
|
itemMap.put(itemDTO.getName(),specItemDTO);
|
||||||
|
}
|
||||||
|
return itemMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean addOrCancelCollect(int goodsId, int userId, int type) {
|
||||||
|
if(type == 1){//1-添加 2-取消
|
||||||
|
boolean isCollect = isCollect(goodsId,userId);
|
||||||
|
if(isCollect) throw new LightSecurityException("已经收藏过");
|
||||||
|
System.out.println("======");
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package com.ruoyi.app.modular.shop.service.vo;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.Min;
|
||||||
|
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class CollectVO {
|
||||||
|
|
||||||
|
@Min(message = "商品id必须为数值",value = 0)
|
||||||
|
private int goodsId;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Reference in new issue
Block a user