商品列表 V2
This commit is contained in:
parent
aa880477cb
commit
4a6d12f3ad
|
|
@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
|
|||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.serializer.SerializeConfig;
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
|
@ -87,6 +88,26 @@ public class JSONUtil {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list 某集合
|
||||
* @param clazz 要转成的实体
|
||||
* 需要在目标实体增加注解 忽略未知属性 @JsonIgnoreProperties(ignoreUnknown = true)
|
||||
* @return
|
||||
* @param <T>
|
||||
*/
|
||||
public static <T> List<T> parseListTNewList(List<?> list, Class<T> clazz) {
|
||||
ObjectMapper objectMapper = new ObjectMapper(); // 创建JSON转换器
|
||||
try {
|
||||
// 将List<?>转换为JSON字符串
|
||||
String json = objectMapper.writeValueAsString(list);
|
||||
// 将JSON字符串转换为List<T>
|
||||
return objectMapper.readValue(json, objectMapper.getTypeFactory().constructCollectionType(List.class, clazz));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String sss = "{\"bizData\":{\"amount\":1,\"currency\":\"cny\",\"ifCode\":\"sxfpay\",\"mchOrderNo\":\"CZ1715744291232\",\"mercNo\":\"B240510702030\",\"note\":\"等待用户付款\",\"payOrderId\":\"O1790587460614225921\",\"payType\":\"WECHAT\",\"settlementType\":\"D1\",\"state\":\"TRADE_AWAIT\",\"storeId\":\"S2405103298\",\"subject\":\"测试支付\",\"tradeFee\":0},\"code\":\"000000\",\"msg\":\"请求成功\",\"sign\":\"40710a3c293eeac3c7f4a1b0696a2bf6\",\"signType\":\"MD5\",\"timestamp\":\"20240515113813\"}";
|
||||
// TypeReference<PublicResp<MainScanResp>> typeRef = new TypeReference<PublicResp<MainScanResp>>(){};
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ package cn.ysk.cashier;
|
|||
import io.swagger.annotations.Api;
|
||||
import cn.ysk.cashier.annotation.rest.AnonymousGetMapping;
|
||||
import cn.ysk.cashier.utils.SpringContextHolder;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.context.ApplicationPidFileWriter;
|
||||
|
|
@ -24,6 +25,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
@Api(hidden = true)
|
||||
@EnableTransactionManagement
|
||||
@SpringBootApplication
|
||||
@MapperScan("cn.ysk.cashier.mybatis.mapper")
|
||||
@EnableJpaAuditing(auditorAwareRef = "auditorAware")
|
||||
public class AppRun {
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ import java.util.Collections;
|
|||
|
||||
|
||||
@Configuration
|
||||
@MapperScan("cn.ysk.cashier.mybatis.mapper")
|
||||
@EnableTransactionManagement
|
||||
public class MybatisPlusConfig {
|
||||
|
||||
|
|
|
|||
|
|
@ -44,8 +44,12 @@ public class ViewConSku implements Serializable {
|
|||
@ApiModelProperty(value = "耗材id")
|
||||
private Integer conInfoId;
|
||||
|
||||
@Column(name = "`product_sku_id`",nullable = false)
|
||||
@Column(name = "`product_id`",nullable = false)
|
||||
@NotNull
|
||||
@ApiModelProperty(value = "商品id")
|
||||
private Integer productId;
|
||||
|
||||
@Column(name = "`product_sku_id`",nullable = false)
|
||||
@ApiModelProperty(value = "商品规格id")
|
||||
private Integer productSkuId;
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package cn.ysk.cashier.controller.product;
|
|||
|
||||
import cn.ysk.cashier.annotation.AnonymousAccess;
|
||||
import cn.ysk.cashier.annotation.Log;
|
||||
import cn.ysk.cashier.dto.product.TbProductQueryV2Criteria;
|
||||
import cn.ysk.cashier.dto.product.TbProductSortCriteria;
|
||||
import cn.ysk.cashier.vo.TbProductVo;
|
||||
import cn.ysk.cashier.service.product.TbProductService;
|
||||
|
|
@ -33,7 +34,11 @@ public class TbProductController {
|
|||
return new ResponseEntity<>(tbProductService.queryAll(criteria, false),HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/list/v2")
|
||||
@ApiOperation("查询商品列表 新")
|
||||
public ResponseEntity<Object> queryTbProductV2(TbProductQueryV2Criteria criteria){
|
||||
return new ResponseEntity<>(tbProductService.queryAllV2(criteria),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("查询/productForAdmin")
|
||||
|
|
@ -41,26 +46,29 @@ public class TbProductController {
|
|||
return new ResponseEntity<>(tbProductService.queryAll(criteria, true),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("/isHot")
|
||||
public ResponseEntity<Object> updateIsHot(@RequestParam Integer isHot, @RequestParam Integer id){
|
||||
tbProductService.updateIsHot(id,isHot);
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@GetMapping("/{product}")
|
||||
@ApiOperation("查询/product")
|
||||
@ApiOperation("查询商品详情")
|
||||
public Object queryTbProductInfo(@PathVariable("product") Integer product)throws Exception{
|
||||
return tbProductService.findByProductId(product);
|
||||
}
|
||||
|
||||
@GetMapping ("/productList")
|
||||
@ApiOperation("查询/product")
|
||||
@ApiOperation("根据集合查询商品")
|
||||
public Object queryTbProductInfo(@RequestParam List<String> productList){
|
||||
return tbProductService.findByProductList(productList);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@GetMapping("/isHot")
|
||||
@ApiOperation("设为招牌菜")
|
||||
public ResponseEntity<Object> updateIsHot(@RequestParam Integer isHot, @RequestParam Integer id){
|
||||
tbProductService.updateIsHot(id,isHot);
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/upProSort")
|
||||
@ApiOperation("修改商品排序")
|
||||
public ResponseEntity<Object> upProSort(@RequestBody TbProductSortCriteria param){
|
||||
|
|
|
|||
|
|
@ -15,11 +15,10 @@
|
|||
*/
|
||||
package cn.ysk.cashier.dto.product;
|
||||
|
||||
import cn.ysk.cashier.annotation.Query;
|
||||
import lombok.Data;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import cn.ysk.cashier.annotation.Query;
|
||||
|
||||
import static cn.ysk.cashier.annotation.Query.Type.INNER_LIKE;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package cn.ysk.cashier.dto.product;
|
||||
|
||||
import cn.ysk.cashier.annotation.Query;
|
||||
import lombok.Data;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.ysk.cashier.annotation.Query.Type.IN;
|
||||
import static cn.ysk.cashier.annotation.Query.Type.INNER_LIKE;
|
||||
|
||||
/**
|
||||
* @website https://eladmin.vip
|
||||
* @author lyf
|
||||
* @date 2023-12-11
|
||||
**/
|
||||
@Data
|
||||
public class TbProductQueryV2Criteria {
|
||||
|
||||
/** 精确 */
|
||||
@Query
|
||||
private String shopId;
|
||||
|
||||
/** 精确 */
|
||||
@Query(type = INNER_LIKE)
|
||||
private String name;
|
||||
|
||||
@Query
|
||||
private String categoryId;
|
||||
|
||||
/** 精确 */
|
||||
@Query
|
||||
private Integer status =1;
|
||||
|
||||
/** 精确 */
|
||||
@Query
|
||||
private Integer isDel = 0;
|
||||
|
||||
@Query
|
||||
private String type;
|
||||
|
||||
@Query(type = IN)
|
||||
private List<String> typeEnum = Arrays.asList("normal","sku");
|
||||
|
||||
private Integer page;
|
||||
|
||||
private Integer size;
|
||||
|
||||
public void setType(String type) {
|
||||
if(StringUtils.isNotBlank(type)){
|
||||
this.typeEnum=Arrays.asList(type);
|
||||
this.type = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,9 +3,12 @@ package cn.ysk.cashier.service.impl.productimpl;
|
|||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.ysk.cashier.cons.domain.ViewConSku;
|
||||
import cn.ysk.cashier.cons.repository.ViewConSkuRepository;
|
||||
import cn.ysk.cashier.dto.TbPlatformDictDto;
|
||||
import cn.ysk.cashier.dto.product.TbProductDto;
|
||||
import cn.ysk.cashier.dto.product.TbProductQueryCriteria;
|
||||
import cn.ysk.cashier.dto.product.TbProductQueryV2Criteria;
|
||||
import cn.ysk.cashier.dto.product.TbProductSortCriteria;
|
||||
import cn.ysk.cashier.dto.shop.TbCouponCategoryDto;
|
||||
import cn.ysk.cashier.exception.BadRequestException;
|
||||
|
|
@ -25,6 +28,7 @@ import cn.ysk.cashier.service.TbPlatformDictService;
|
|||
import cn.ysk.cashier.service.product.TbProductService;
|
||||
import cn.ysk.cashier.service.shop.TbCouponCategoryService;
|
||||
import cn.ysk.cashier.utils.*;
|
||||
import cn.ysk.cashier.vo.TbProductNewVo;
|
||||
import cn.ysk.cashier.vo.TbProductVo;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
|
@ -34,10 +38,7 @@ import lombok.RequiredArgsConstructor;
|
|||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.domain.*;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
|
@ -48,7 +49,6 @@ import java.math.BigDecimal;
|
|||
import java.time.Instant;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.DoubleSupplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
|
|
@ -78,6 +78,7 @@ public class TbProductServiceImpl implements TbProductService {
|
|||
private final TbProducSkutMapper producSkutMapper;
|
||||
private final cn.ysk.cashier.mybatis.mapper.TbProductMapper productMapper;
|
||||
private final TbProductSkuResultRepository productSkuResultRepository;
|
||||
private final ViewConSkuRepository viewConSkuRepository;
|
||||
|
||||
|
||||
private final RedisUtils redisUtils;
|
||||
|
|
@ -235,6 +236,36 @@ public class TbProductServiceImpl implements TbProductService {
|
|||
return PageUtil.toPage(tbProductVoList, page.getTotalElements());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> queryAllV2(TbProductQueryV2Criteria criteria) {
|
||||
Sort sort = Sort.by(Sort.Direction.ASC, "sort");
|
||||
Pageable pageable = PageRequest.of(criteria.getPage(), criteria.getSize(), sort);
|
||||
//查询商品数据
|
||||
Page<TbProduct> page = tbProductRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), pageable);
|
||||
List<TbProductNewVo> products = new ArrayList<>();
|
||||
for (TbProduct product : page.getContent()) {
|
||||
TbProductNewVo productNewVo = new TbProductNewVo();
|
||||
BeanUtils.copyProperties(product, productNewVo);
|
||||
productNewVo.setLowPrice("¥"+product.getLowPrice().toString());
|
||||
List<TbProductSku> tbProductSkus = tbProductSkuRepository.searchSku(product.getId().toString());
|
||||
if (tbProductSkus.size() > 1) {
|
||||
BigDecimal maxPrice = tbProductSkus.stream().map(TbProductSku::getSalePrice).max(BigDecimal::compareTo).get();
|
||||
productNewVo.setLowPrice(productNewVo.getLowPrice() + "~¥" + maxPrice);
|
||||
}
|
||||
//规格填充
|
||||
List<TbProductNewVo.TbProductSkuVos> tbProductSkuVos = JSONUtil.parseListTNewList(tbProductSkus, TbProductNewVo.TbProductSkuVos.class);
|
||||
productNewVo.setSkuList(tbProductSkuVos);
|
||||
ViewConSku viewConSku=new ViewConSku();
|
||||
viewConSku.setShopId(Integer.valueOf(product.getShopId()));
|
||||
viewConSku.setProductId(product.getId());
|
||||
Example<ViewConSku> query = Example.of(viewConSku);
|
||||
List<ViewConSku> skuCons = viewConSkuRepository.findAll(query);
|
||||
productNewVo.setConInfos(skuCons);
|
||||
products.add(productNewVo);
|
||||
}
|
||||
return PageUtil.toPage(products, page.getTotalElements());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public TbProductVo findByProductId(Integer id) throws Exception {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package cn.ysk.cashier.service.product;
|
||||
|
||||
import cn.ysk.cashier.dto.product.TbProductQueryV2Criteria;
|
||||
import cn.ysk.cashier.dto.product.TbProductSortCriteria;
|
||||
import cn.ysk.cashier.pojo.product.TbProduct;
|
||||
import cn.ysk.cashier.vo.TbProductVo;
|
||||
|
|
@ -29,6 +30,9 @@ public interface TbProductService {
|
|||
Map<String, Object> queryAll(TbProductQueryCriteria criteria, boolean isAdmin);
|
||||
|
||||
|
||||
Map<String, Object> queryAllV2(TbProductQueryV2Criteria criteria);
|
||||
|
||||
|
||||
/**
|
||||
* 查询所有数据不分页
|
||||
*
|
||||
|
|
|
|||
|
|
@ -0,0 +1,78 @@
|
|||
package cn.ysk.cashier.vo;
|
||||
|
||||
import cn.ysk.cashier.cons.domain.ViewConSku;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author ww
|
||||
*/
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class TbProductNewVo {
|
||||
|
||||
private Integer id;
|
||||
//店铺id
|
||||
private String shopId;
|
||||
//图片
|
||||
private String coverImg;
|
||||
//商品名称
|
||||
private String name;
|
||||
//售价
|
||||
private String lowPrice;
|
||||
//类型 单规格/多规格
|
||||
private String typeEnum;
|
||||
//库存
|
||||
private Double stockNumber;
|
||||
//是否在收银端上架 0否1是
|
||||
private Integer isShowCash;
|
||||
//是否在小程序上架 0否1是
|
||||
private Integer isShowMall;
|
||||
//是否售罄 0否1是
|
||||
private Integer isPauseSale;
|
||||
//是否热销
|
||||
private Integer isHot;
|
||||
|
||||
private List<ViewConSku> conInfos;
|
||||
|
||||
private List<TbProductSkuVos> skuList;
|
||||
//排序
|
||||
private Integer sort;
|
||||
|
||||
public void setTypeEnum(String typeEnum) {
|
||||
switch (typeEnum) {
|
||||
case "normal":
|
||||
this.typeEnum = "单规格";
|
||||
break;
|
||||
case "sku":
|
||||
this.typeEnum = "多规格";
|
||||
break;
|
||||
case "weight":
|
||||
this.typeEnum = "称重商品";
|
||||
break;
|
||||
case "currentPrice":
|
||||
this.typeEnum = "时价商品";
|
||||
break;
|
||||
case "group":
|
||||
this.typeEnum = "套餐商品/团购卷";
|
||||
break;
|
||||
default:
|
||||
this.typeEnum = typeEnum;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class TbProductSkuVos {
|
||||
private Integer id;
|
||||
private BigDecimal salePrice = new BigDecimal("0.00");
|
||||
private String specSnap="";
|
||||
private Integer isPauseSale = 0;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue