Browse Source

品牌排序修改及商品删除下架时判断

zyj
sj 2 years ago
parent
commit
2b25c63f4e
  1. 5
      zsw-bxg/pom.xml
  2. 4
      zsw-bxg/src/main/java/co/yixiang/app/modules/coupon/rest/CouponController.java
  3. 2
      zsw-bxg/src/main/java/co/yixiang/app/modules/product/rest/AppStoreBrandController.java
  4. 31
      zsw-bxg/src/main/java/co/yixiang/modules/product/rest/StoreProductController.java
  5. 47
      zsw-bxg/src/main/java/co/yixiang/modules/product/service/impl/YxStoreProductServiceImpl.java
  6. 2
      zsw-bxg/src/main/java/co/yixiang/modules/store/service/YxStoreBrandService.java
  7. 20
      zsw-bxg/src/main/java/co/yixiang/modules/store/service/impl/Sort.java
  8. 48
      zsw-bxg/src/main/java/co/yixiang/modules/store/service/impl/YxStoreBrandServiceImpl.java
  9. 1
      zsw-bxg/src/main/java/co/yixiang/utils/BrandDTO.java

5
zsw-bxg/pom.xml

@ -27,6 +27,11 @@
<artifactId>yudao-module-system-impl</artifactId>
<version>1.6.2-snapshot</version>
</dependency>
<dependency>
<groupId>com.belerweb</groupId>
<artifactId>pinyin4j</artifactId>
<version>2.5.1</version>
</dependency>
<dependency>
<groupId>com.dtflys.forest</groupId>
<artifactId>forest-spring-boot-starter</artifactId>

4
zsw-bxg/src/main/java/co/yixiang/app/modules/coupon/rest/CouponController.java

@ -124,9 +124,11 @@ public class CouponController {
List<YxStoreCouponUserQueryVo> list = storeCouponUserService.getUserCoupon(uid);
List<YxStoreCouponUserQueryVo> list1 = new ArrayList<>();
for (YxStoreCouponUserQueryVo couponUser : list) {
if (couponUser.getIsFail() == 1){//已失效
//已失效 //已过期
if (couponUser.getIsFail() == 1||couponUser.getStatus() == 2){
list1.add(couponUser);
}
}
return ApiResult.ok(list1);
}

2
zsw-bxg/src/main/java/co/yixiang/app/modules/product/rest/AppStoreBrandController.java

@ -49,7 +49,7 @@ public class AppStoreBrandController {
@AnonymousAccess
@GetMapping("/brandByName")
@ApiOperation(value = "商品品牌列表",notes = "商品品牌列表")
public ApiResult<Map<String,List<YxStoreBrandNameDto>>> getListByName(){
public ApiResult<Map<String,List<BrandDTO>>> getListByName(){
return ApiResult.ok(yxStoreBrandService.getListByName());
}

31
zsw-bxg/src/main/java/co/yixiang/modules/product/rest/StoreProductController.java

@ -9,6 +9,8 @@
package co.yixiang.modules.product.rest;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.framework.common.exception.YshopException;
import co.yixiang.constant.ShopConstants;
import co.yixiang.dozer.service.IGenerator;
import co.yixiang.enums.ShopCommonEnum;
@ -17,9 +19,14 @@ import co.yixiang.logging.aop.log.Log;
import co.yixiang.modules.aop.ForbidSubmit;
import co.yixiang.modules.category.domain.YxStoreCategory;
import co.yixiang.modules.category.service.YxStoreCategoryService;
import co.yixiang.modules.evaluation.domain.YxEvaluation;
import co.yixiang.modules.evaluation.service.mapper.YxEvaluationMapper;
import co.yixiang.modules.hotList.domain.YxStoreHotList;
import co.yixiang.modules.hotList.service.mapper.YxStoreHotListMapper;
import co.yixiang.modules.product.domain.YxStoreProduct;
import co.yixiang.modules.product.domain.YxStoreProductAttrResult;
import co.yixiang.modules.product.domain.YxStoreProductAttrValue;
import co.yixiang.modules.product.domain.YxStoreProductRelation;
import co.yixiang.modules.product.service.YxStoreProductAttrResultService;
import co.yixiang.modules.product.service.YxStoreProductAttrValueService;
import co.yixiang.modules.product.service.YxStoreProductRuleService;
@ -37,6 +44,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
@ -63,6 +71,10 @@ import java.util.stream.Collectors;
@RequestMapping("api")
public class StoreProductController {
@Autowired
private YxStoreHotListMapper yxStoreHotListMapper;
@Autowired
private YxEvaluationMapper yxEvaluationMapper;
private final YxStoreProductService yxStoreProductService;
private final YxStoreCategoryService yxStoreCategoryService;
private final YxShippingTemplatesService yxShippingTemplatesService;
@ -120,6 +132,24 @@ public class StoreProductController {
@PreAuthorize("@ss.hasAnyPermissions('admin','YXSTOREPRODUCT_ALL','YXSTOREPRODUCT_DELETE')")
public ResponseEntity delete(@PathVariable Long id){
//这里增加评测/热榜判断
Long count = yxEvaluationMapper
.selectCount(Wrappers.<YxEvaluation>lambdaQuery()
.eq(YxEvaluation::getIsShow,1)
.eq(YxEvaluation::getProduct,id));
//此商品关联有评测
if(count > 0) {
//不能删除
throw new YshopException("当前商品已绑定评测,不能被删除");
}
Long count1 = yxStoreHotListMapper
.selectCount(Wrappers.<YxStoreHotList>lambdaQuery()
.eq(YxStoreHotList::getIsShow,1)
.like(YxStoreHotList::getProductList,id));
//此商品被热门榜单绑定,不能删除
if(count1 > 0) {
//不能删除
throw new YshopException("当前商品已绑定热门榜单,不能被删除");
}
yxStoreProductService.removeById(id);
return new ResponseEntity(HttpStatus.OK);
}
@ -130,6 +160,7 @@ public class StoreProductController {
@CacheEvict(cacheNames = ShopConstants.ZSW_REDIS_INDEX_KEY,allEntries = true)
@PostMapping(value = "/yxStoreProduct/onsale/{id}")
public ResponseEntity onSale(@PathVariable Long id,@RequestBody String jsonStr){
JSONObject jsonObject = JSON.parseObject(jsonStr);
Integer status = jsonObject.getInteger("status");
yxStoreProductService.onSale(id,status);

47
zsw-bxg/src/main/java/co/yixiang/modules/product/service/impl/YxStoreProductServiceImpl.java

@ -29,6 +29,10 @@ import co.yixiang.exception.BadRequestException;
import co.yixiang.exception.ErrorRequestException;
import co.yixiang.modules.activity.service.mapper.YxStoreBargainMapper;
import co.yixiang.modules.category.service.YxStoreCategoryService;
import co.yixiang.modules.evaluation.domain.YxEvaluation;
import co.yixiang.modules.evaluation.service.mapper.YxEvaluationMapper;
import co.yixiang.modules.hotList.domain.YxStoreHotList;
import co.yixiang.modules.hotList.service.mapper.YxStoreHotListMapper;
import co.yixiang.modules.store.domain.YxStoreBrand;
import co.yixiang.modules.store.service.YxStoreBrandService;
import co.yixiang.modules.product.domain.YxStoreProduct;
@ -90,6 +94,10 @@ import java.util.stream.Collectors;
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public class YxStoreProductServiceImpl extends BaseServiceImpl<StoreProductMapper, YxStoreProduct> implements YxStoreProductService {
@Autowired
private YxStoreHotListMapper yxStoreHotListMapper;
@Autowired
private YxEvaluationMapper yxEvaluationMapper;
@Autowired
private IGenerator generator;
@Autowired
@ -302,9 +310,18 @@ public class YxStoreProductServiceImpl extends BaseServiceImpl<StoreProductMappe
IPage<YxStoreProduct> pageList = storeProductMapper.selectPage(pageModel, wrapper);
List<YxStoreProductQueryVo> list = generator.convert(pageList.getRecords(), YxStoreProductQueryVo.class);
//放入品牌信息
list.forEach(item->{
item.setBrandName(yxStoreBrandMapper.selectById(item.getBrandId()).getBrandName());
item.setPic(yxStoreBrandMapper.selectById(item.getBrandId()).getPic());
YxStoreBrand yxStoreBrand=yxStoreBrandMapper.selectById(item.getBrandId());
//没有品牌
if (ObjectUtil.isEmpty(yxStoreBrand)){
item.setBrandName("暂无品牌");
item.setPic("");
}else {
item.setBrandName(yxStoreBrand.getBrandName());
item.setPic(yxStoreBrand.getPic());
}
});
return list;
}
@ -380,9 +397,13 @@ public class YxStoreProductServiceImpl extends BaseServiceImpl<StoreProductMappe
}
productVo.setTempName(tempName);
//品牌信息
if (ObjectUtil.isEmpty(yxStoreBrandVo)){
productVo.setBrandInfo(new YxStoreBrandVo().setBrandName("暂无品牌"));
}else {
productVo.setBrandInfo(yxStoreBrandVo);
}
//设置商品相关信息
productVo.setBrandInfo(yxStoreBrandVo);
productVo.setStoreInfo(storeProductQueryVo);
productVo.setProductAttr((List<YxStoreProductAttrQueryVo>) returnMap.get("productAttr"));
productVo.setProductValue((Map<String, YxStoreProductAttrValue>) returnMap.get("productValue"));
@ -555,6 +576,24 @@ public class YxStoreProductServiceImpl extends BaseServiceImpl<StoreProductMappe
@Override
public void onSale(Long id, Integer status) {
if (ShopCommonEnum.SHOW_1.getValue().equals(status)) {
//下架时候需进行判断
//这里增加评测/热榜判断
Long count = yxEvaluationMapper
.selectCount(Wrappers.<YxEvaluation>lambdaQuery()
.eq(YxEvaluation::getIsShow,1)
.eq(YxEvaluation::getProduct,id));
//此商品关联有评测
if(count > 0) {
throw new YshopException("当前商品已绑定评测,不能被下架");
}
Long count1 = yxStoreHotListMapper
.selectCount(Wrappers.<YxStoreHotList>lambdaQuery()
.eq(YxStoreHotList::getIsShow,1)
.like(YxStoreHotList::getProductList,id));
//此商品被热门榜单绑定,不能下架
if(count1 > 0) {
throw new YshopException("当前商品已绑定热门榜单,不能被下架");
}
status = ShopCommonEnum.SHOW_0.getValue();
} else {
status = ShopCommonEnum.SHOW_1.getValue();

2
zsw-bxg/src/main/java/co/yixiang/modules/store/service/YxStoreBrandService.java

@ -28,7 +28,7 @@ public interface YxStoreBrandService extends BaseService<YxStoreBrand> {
List<BrandDTO> getList();
Map<String,List<YxStoreBrandNameDto>> getListByName();
Map<String,List<BrandDTO>> getListByName();
/**
* 查询数据分页
* @param criteria 条件

20
zsw-bxg/src/main/java/co/yixiang/modules/store/service/impl/Sort.java

@ -6,6 +6,8 @@ package co.yixiang.modules.store.service.impl;
* @creation date 2022-10-26
*/
import co.yixiang.utils.BrandDTO;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -24,9 +26,9 @@ public class Sort {
* @param list 需要排序的List集合
* @return
*/
public Map<String, List<String>> sort(List<String> list){
Map<String,List<String>> map = new HashMap<String,List<String>>();
List<String> arraylist = new ArrayList<String>();
public Map<String, List<BrandDTO>> sort(List<BrandDTO> list){
Map<String,List<BrandDTO>> map = new HashMap<>();
List<BrandDTO> arraylist = new ArrayList<>();
String[] alphatableb =
{
"A", "B", "C", "D", "E", "F", "G", "H", "I",
@ -34,12 +36,16 @@ public class Sort {
};
for(String a:alphatableb){
for(int i=0;i<list.size();i++){//为了排序都返回大写字母
if(a.equals(String2AlphaFirst(list.get(i).toString(),Letter_flag_capital))){
arraylist.add(list.get(i).toString());
if(a.equals(String2AlphaFirst(list.get(i).getBrandName(),Letter_flag_capital))){
arraylist.add(list.get(i));
}
}
map.put(a,arraylist);
arraylist=new ArrayList<String>();
if (arraylist.isEmpty()){
//没有品牌,不进行添加
}else {
map.put(a,arraylist);
}
arraylist=new ArrayList<BrandDTO>();
}
return map;
}

48
zsw-bxg/src/main/java/co/yixiang/modules/store/service/impl/YxStoreBrandServiceImpl.java

@ -53,8 +53,8 @@ public class YxStoreBrandServiceImpl extends BaseServiceImpl<YxStoreBrandMapper,
@Autowired
private YxStoreBrandMapper yxStoreBrandMapper;
/**
* 获取商家品牌并根据首字母排序
* @return List
* 获取商家品牌
* @return list
*/
@Override
public List<BrandDTO> getList() {
@ -65,44 +65,14 @@ public class YxStoreBrandServiceImpl extends BaseServiceImpl<YxStoreBrandMapper,
// return TreeUtil.list2TreeConverter(list,0);
return list;
}
private static final String KEY_SPLIT = "!";
public Map<String,List<YxStoreBrandNameDto> > getListByName() {
ArrayList list=new ArrayList();
this.getList().forEach(item->{
list.add(item.getBrandName()+KEY_SPLIT+item.getId()+KEY_SPLIT+item.getPic());
});
/**
* 获取商家品牌并根据首字母排序
* @return map
*/
public Map<String,List<BrandDTO> > getListByName() {
Sort sort=new Sort();
Map<String,List<String>> map = sort.sort(list);
Map<String, List<YxStoreBrandNameDto>> resultMap = new HashMap<>();
// 遍历排序之后的集合
for (Map.Entry<String, List<String>> listEntry : map.entrySet()) {
for (String value : listEntry.getValue()) {
// map中的key是否包含品牌首字母,若存在则把数据处理之后存储到对象里面,然后添加到List里面,
// 否则新建key然后再把数据处理之后存储到对象里面,然后添加到List里面
if (resultMap.containsKey(listEntry.getKey())) {
YxStoreBrandNameDto brandNameDto = new YxStoreBrandNameDto();
String [] brandArray = value.split(KEY_SPLIT); // 按:把品牌信息分开
brandNameDto.setBrandName(brandArray[0]); // 品牌名称
brandNameDto.setId(Integer.valueOf(brandArray[1])); // 品牌id
brandNameDto.setPic(brandArray[2]); //品牌图标
// brandNameDto.setCarBrandFirstLetter(listEntry.getKey()); // 品牌名称首字母
resultMap.get(listEntry.getKey()).add(brandNameDto);
}else {
List<YxStoreBrandNameDto> list2 = new ArrayList<YxStoreBrandNameDto>();
YxStoreBrandNameDto brandNameDto = new YxStoreBrandNameDto();
String [] brandArray = value.split(KEY_SPLIT); // 按:把品牌名称和id分开
brandNameDto.setBrandName(brandArray[0]); // 品牌名称
brandNameDto.setId(Integer.valueOf(brandArray[1])); // 品牌id
brandNameDto.setPic(brandArray[2]); //品牌图标
// brandNameDto.setCarBrandFirstLetter(listEntry.getKey()); // 品牌名称首字母
list2.add(brandNameDto);
resultMap.put(listEntry.getKey(), list2);
}
}
}
return resultMap;
Map<String,List<BrandDTO>> map = sort.sort(this.getList());
return map;
}
@Override
//@Cacheable

1
zsw-bxg/src/main/java/co/yixiang/utils/BrandDTO.java

@ -25,7 +25,6 @@ public class BrandDTO implements Serializable {
* 商品品牌名称
*/
private String brandName;
/**
* 缩略图url
*/

Loading…
Cancel
Save