diff --git a/zsw-bxg/pom.xml b/zsw-bxg/pom.xml index b1b98840..b53df462 100644 --- a/zsw-bxg/pom.xml +++ b/zsw-bxg/pom.xml @@ -27,6 +27,11 @@ yudao-module-system-impl 1.6.2-snapshot + + com.belerweb + pinyin4j + 2.5.1 + com.dtflys.forest forest-spring-boot-starter diff --git a/zsw-bxg/src/main/java/co/yixiang/app/modules/coupon/rest/CouponController.java b/zsw-bxg/src/main/java/co/yixiang/app/modules/coupon/rest/CouponController.java index 0a88129e..c09199c7 100644 --- a/zsw-bxg/src/main/java/co/yixiang/app/modules/coupon/rest/CouponController.java +++ b/zsw-bxg/src/main/java/co/yixiang/app/modules/coupon/rest/CouponController.java @@ -124,9 +124,11 @@ public class CouponController { List list = storeCouponUserService.getUserCoupon(uid); List 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); } diff --git a/zsw-bxg/src/main/java/co/yixiang/app/modules/product/rest/AppStoreBrandController.java b/zsw-bxg/src/main/java/co/yixiang/app/modules/product/rest/AppStoreBrandController.java index 0f032beb..5990615c 100644 --- a/zsw-bxg/src/main/java/co/yixiang/app/modules/product/rest/AppStoreBrandController.java +++ b/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>> getListByName(){ + public ApiResult>> getListByName(){ return ApiResult.ok(yxStoreBrandService.getListByName()); } diff --git a/zsw-bxg/src/main/java/co/yixiang/modules/product/rest/StoreProductController.java b/zsw-bxg/src/main/java/co/yixiang/modules/product/rest/StoreProductController.java index e66f871a..e64643ef 100644 --- a/zsw-bxg/src/main/java/co/yixiang/modules/product/rest/StoreProductController.java +++ b/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.lambdaQuery() + .eq(YxEvaluation::getIsShow,1) + .eq(YxEvaluation::getProduct,id)); + //此商品关联有评测 + if(count > 0) { + //不能删除 + throw new YshopException("当前商品已绑定评测,不能被删除"); + } + Long count1 = yxStoreHotListMapper + .selectCount(Wrappers.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); diff --git a/zsw-bxg/src/main/java/co/yixiang/modules/product/service/impl/YxStoreProductServiceImpl.java b/zsw-bxg/src/main/java/co/yixiang/modules/product/service/impl/YxStoreProductServiceImpl.java index c8125771..95937443 100644 --- a/zsw-bxg/src/main/java/co/yixiang/modules/product/service/impl/YxStoreProductServiceImpl.java +++ b/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 implements YxStoreProductService { + @Autowired + private YxStoreHotListMapper yxStoreHotListMapper; + @Autowired + private YxEvaluationMapper yxEvaluationMapper; @Autowired private IGenerator generator; @Autowired @@ -302,9 +310,18 @@ public class YxStoreProductServiceImpl extends BaseServiceImpl pageList = storeProductMapper.selectPage(pageModel, wrapper); List 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) returnMap.get("productAttr")); productVo.setProductValue((Map) returnMap.get("productValue")); @@ -555,6 +576,24 @@ public class YxStoreProductServiceImpl extends BaseServiceImpllambdaQuery() + .eq(YxEvaluation::getIsShow,1) + .eq(YxEvaluation::getProduct,id)); + //此商品关联有评测 + if(count > 0) { + throw new YshopException("当前商品已绑定评测,不能被下架"); + } + Long count1 = yxStoreHotListMapper + .selectCount(Wrappers.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(); diff --git a/zsw-bxg/src/main/java/co/yixiang/modules/store/service/YxStoreBrandService.java b/zsw-bxg/src/main/java/co/yixiang/modules/store/service/YxStoreBrandService.java index 2de1ce90..f92f73af 100644 --- a/zsw-bxg/src/main/java/co/yixiang/modules/store/service/YxStoreBrandService.java +++ b/zsw-bxg/src/main/java/co/yixiang/modules/store/service/YxStoreBrandService.java @@ -28,7 +28,7 @@ public interface YxStoreBrandService extends BaseService { List getList(); - Map> getListByName(); + Map> getListByName(); /** * 查询数据分页 * @param criteria 条件 diff --git a/zsw-bxg/src/main/java/co/yixiang/modules/store/service/impl/Sort.java b/zsw-bxg/src/main/java/co/yixiang/modules/store/service/impl/Sort.java index 40524404..5e86d0a9 100644 --- a/zsw-bxg/src/main/java/co/yixiang/modules/store/service/impl/Sort.java +++ b/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> sort(List list){ - Map> map = new HashMap>(); - List arraylist = new ArrayList(); + public Map> sort(List list){ + Map> map = new HashMap<>(); + List 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(); + if (arraylist.isEmpty()){ + //没有品牌,不进行添加 + }else { + map.put(a,arraylist); + } + arraylist=new ArrayList(); } return map; } diff --git a/zsw-bxg/src/main/java/co/yixiang/modules/store/service/impl/YxStoreBrandServiceImpl.java b/zsw-bxg/src/main/java/co/yixiang/modules/store/service/impl/YxStoreBrandServiceImpl.java index dce195e1..87300d04 100644 --- a/zsw-bxg/src/main/java/co/yixiang/modules/store/service/impl/YxStoreBrandServiceImpl.java +++ b/zsw-bxg/src/main/java/co/yixiang/modules/store/service/impl/YxStoreBrandServiceImpl.java @@ -53,8 +53,8 @@ public class YxStoreBrandServiceImpl extends BaseServiceImpl getList() { @@ -65,44 +65,14 @@ public class YxStoreBrandServiceImpl extends BaseServiceImpl > 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 > getListByName() { Sort sort=new Sort(); - Map> map = sort.sort(list); - Map> resultMap = new HashMap<>(); - // 遍历排序之后的集合 - for (Map.Entry> 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 list2 = new ArrayList(); - 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> map = sort.sort(this.getList()); + return map; } @Override //@Cacheable diff --git a/zsw-bxg/src/main/java/co/yixiang/utils/BrandDTO.java b/zsw-bxg/src/main/java/co/yixiang/utils/BrandDTO.java index 7466bdcf..7f514b92 100644 --- a/zsw-bxg/src/main/java/co/yixiang/utils/BrandDTO.java +++ b/zsw-bxg/src/main/java/co/yixiang/utils/BrandDTO.java @@ -25,7 +25,6 @@ public class BrandDTO implements Serializable { * 商品品牌名称 */ private String brandName; - /** * 缩略图url */