首页 金刚区 标签 详情 标签VO一堆

This commit is contained in:
2024-04-11 14:26:35 +08:00
parent 1b9d069bc6
commit 9a6f6eb5b6
21 changed files with 592 additions and 633 deletions

View File

@@ -7,8 +7,10 @@ import com.chaozhanggui.system.cashierservice.entity.vo.*;
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
import com.chaozhanggui.system.cashierservice.sign.Result;
import com.chaozhanggui.system.cashierservice.util.DateUtils;
import com.chaozhanggui.system.cashierservice.util.JSONUtil;
import com.chaozhanggui.system.cashierservice.util.Threads;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@@ -20,6 +22,7 @@ import java.util.Collections;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
/**
* @author lyf
@@ -80,12 +83,14 @@ public class HomePageService {
if (o.getShopId().equals(tbShopInfo.getId().toString())) {
homeVO.setShopName(tbShopInfo.getShopName());
homeVO.setImage(tbShopInfo.getLogo());
if (tbShopInfo.getTag() == null){
if (StringUtils.isBlank(tbShopInfo.getTag())){
homeVO.setShopTag(new ArrayList<>());
}else {
TbPlatformDict tbPlatformDict = platformDictMapper.queryById(Integer.valueOf(tbShopInfo.getTag()));
homeVO.setShopTag(tbPlatformDict == null ? new ArrayList<>() : Collections.singletonList(tbPlatformDict.getName()));
List<Integer> shopTagIds = Arrays.stream(tbShopInfo.getTag().split(","))
.map(Integer::parseInt)
.collect(Collectors.toList());
List<TbPlatformDict> tbPlatformDicts = platformDictMapper.queryByIdList(shopTagIds);
homeVO.setShopTag(JSONUtil.parseListTNewList(tbPlatformDicts, TagVo.class));
}
}
}
@@ -108,7 +113,7 @@ public class HomePageService {
}
for (TagProductVO tagProductVO :dictPro.get()) {
if (o.getRelationIds().equals(tagProductVO.getProductId().toString())){
homeVO.setProTag(tagList(tagProductVO.getTags()));
homeVO.getProTag().add(tagProductVO);
}
}
homeVO.setEndTime(DateUtils.getDayEndLong());
@@ -131,10 +136,11 @@ public class HomePageService {
HomeUpVO homeUpVO = new HomeUpVO();
//轮播图
List<TbPlatformDict> carouselList = platformDictMapper.queryAllByType("carousel", environment);
homeUpVO.setCarousel(carouselList);
homeUpVO.setCarousel(JSONUtil.parseListTNewList(carouselList, HomeCarouselVo.class));
//金刚区
List<TbPlatformDict> districtList = platformDictMapper.queryAllByType("homeDistrict", environment);
homeUpVO.setDistrict(districtList);
homeUpVO.setDistrict(JSONUtil.parseListTNewList(districtList, HomeDistrictVo.class));
//菜单
List<SysDict> sysDicts = sysDictDetailMapper.selectByAll();
List<DicDetailVO> dicDetailVO = new ArrayList<>();

View File

@@ -2,21 +2,32 @@ package com.chaozhanggui.system.cashierservice.service;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.chaozhanggui.system.cashierservice.dao.*;
import com.chaozhanggui.system.cashierservice.entity.*;
import com.chaozhanggui.system.cashierservice.entity.vo.ProductInfoVo;
import com.chaozhanggui.system.cashierservice.entity.vo.ProductVo;
import com.chaozhanggui.system.cashierservice.entity.vo.TagProductVO;
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
import com.chaozhanggui.system.cashierservice.sign.Result;
import com.chaozhanggui.system.cashierservice.socket.AppWebSocketServer;
import com.chaozhanggui.system.cashierservice.util.Threads;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutionException;
@Service
@Slf4j
@@ -37,90 +48,165 @@ public class ProductService {
@Autowired
private TbShopTableMapper tbShopTableMapper;
@Resource
private TagProductDeptsMapper tagProductDeptsMapper;
@Resource
private TbMerchantCouponMapper merchantCouponMapper;
@Resource
private TbPlatformDictMapper platformDictMapper;
@Resource
private TbShopUnitMapper unitMapper;
@Resource
private TbShopCategoryMapper categoryMapper;
@Resource
private TbPurchaseNoticeMapper purchaseNoticeMapper;
@Autowired
TbProductSkuMapper tbProductSkuMapper;
public Result queryProduct(String code, String productGroupId) {
ConcurrentMap<String, Object> concurrentMap = new ConcurrentHashMap<>();
public Result queryProduct(String code,String productGroupId){
ConcurrentMap<String,Object> concurrentMap=new ConcurrentHashMap<>();
TbShopTable tbShopTable= tbShopTableMapper.selectQRcode(code);
if(ObjectUtil.isEmpty(tbShopTable)||ObjectUtil.isNull(tbShopTable)){
TbShopTable tbShopTable = tbShopTableMapper.selectQRcode(code);
if (ObjectUtil.isEmpty(tbShopTable) || ObjectUtil.isNull(tbShopTable)) {
return Result.fail("台桌信息不存在");
}
Integer id= ObjectUtil.isNotEmpty(productGroupId)?Integer.valueOf(productGroupId):null;
List<TbProductGroup> groupList=tbProductGroupMapper.selectByQrcode(code,id);
if(ObjectUtil.isNotEmpty(groupList)&&groupList.size()>0){
Integer id = ObjectUtil.isNotEmpty(productGroupId) ? Integer.valueOf(productGroupId) : null;
List<TbProductGroup> groupList = tbProductGroupMapper.selectByQrcode(code, id);
if (ObjectUtil.isNotEmpty(groupList) && groupList.size() > 0) {
TbProductGroup group= groupList.get(0);
TbShopInfo shopInfo= tbShopInfoMapper.selectByPrimaryKey(group.getShopId()) ;
concurrentMap.put("shopTableInfo",tbShopTable);
concurrentMap.put("storeInfo",shopInfo);
groupList.parallelStream().forEach(g->{
String in=g.getProductIds().substring(1,g.getProductIds().length()-1);
TbProductGroup group = groupList.get(0);
TbShopInfo shopInfo = tbShopInfoMapper.selectByPrimaryKey(group.getShopId());
concurrentMap.put("shopTableInfo", tbShopTable);
concurrentMap.put("storeInfo", shopInfo);
groupList.parallelStream().forEach(g -> {
String in = g.getProductIds().substring(1, g.getProductIds().length() - 1);
if(ObjectUtil.isNotEmpty(in)&&ObjectUtil.isNotNull(in)){
log.info("请求参数:{}",in);
List<TbProduct> products= tbProductMapper.selectByIdIn(in);
if(ObjectUtil.isNotEmpty(products)&&products.size()>0){
products.parallelStream().forEach(it->{
if (ObjectUtil.isNotEmpty(in) && ObjectUtil.isNotNull(in)) {
log.info("请求参数:{}", in);
List<TbProduct> products = tbProductMapper.selectByIdIn(in);
if (ObjectUtil.isNotEmpty(products) && products.size() > 0) {
products.parallelStream().forEach(it -> {
Integer sum = 0;
if (AppWebSocketServer.userMap.containsKey(code)){
if (AppWebSocketServer.userMap.containsKey(code)) {
Set<String> userSet = AppWebSocketServer.userMap.get(code);
if (userSet.isEmpty()){
sum= tbProductMapper.selectByQcode(code,it.getId(),it.getShopId());
}else {
if (userSet.isEmpty()) {
sum = tbProductMapper.selectByQcode(code, it.getId(), it.getShopId());
} else {
List<String> userList = new ArrayList<>(userSet);
sum= tbProductMapper.selectByNewQcode(code,it.getId(),it.getShopId(),userList);
sum = tbProductMapper.selectByNewQcode(code, it.getId(), it.getShopId(), userList);
}
}else {
sum= tbProductMapper.selectByQcode(code,it.getId(),it.getShopId());
} else {
sum = tbProductMapper.selectByQcode(code, it.getId(), it.getShopId());
}
it.setCartNumber(sum==null?"0":String.valueOf(sum));
TbProductSkuResult skuResult= tbProductSkuResultMapper.selectByPrimaryKey(it.getId());
it.setCartNumber(sum == null ? "0" : String.valueOf(sum));
TbProductSkuResult skuResult = tbProductSkuResultMapper.selectByPrimaryKey(it.getId());
it.setProductSkuResult(skuResult);
});
g.setProducts(products);
}else {
} else {
g.setProducts(new ArrayList<>());
}
}else {
} else {
g.setProducts(new ArrayList<>());
}
});
concurrentMap.put("productInfo",groupList);
concurrentMap.put("productInfo", groupList);
}
return Result.success(CodeEnum.SUCCESS,concurrentMap);
return Result.success(CodeEnum.SUCCESS, concurrentMap);
}
public Result queryProductSku(String shopId, String productId, String spec_tag){
if(ObjectUtil.isEmpty(shopId)||ObjectUtil.isEmpty(productId)){
public Result queryProductSku(String shopId, String productId, String spec_tag) {
if (ObjectUtil.isEmpty(shopId) || ObjectUtil.isEmpty(productId)) {
return Result.fail("参数错误");
}
TbProductSkuWithBLOBs tbProductSkuWithBLOBs= tbProductSkuMapper.selectByShopIdAndProductIdAndSpec(shopId,productId,spec_tag);
return Result.success(CodeEnum.SUCCESS,tbProductSkuWithBLOBs);
TbProductSkuWithBLOBs tbProductSkuWithBLOBs = tbProductSkuMapper.selectByShopIdAndProductIdAndSpec(shopId, productId, spec_tag);
return Result.success(CodeEnum.SUCCESS, tbProductSkuWithBLOBs);
}
// public Result productInfo(Integer productId){
// TbShopInfo tbShopInfo = tbShopInfoMapper.selectByPrimaryKey(productId);
// }
public Result productInfo(Integer productId) throws Exception {
TbMerchantCoupon tbMerchantCoupon = merchantCouponMapper.queryById(productId);
CompletableFuture<TbShopInfo> shopInfo = CompletableFuture.supplyAsync(() ->
tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(tbMerchantCoupon.getShopId())));
CompletableFuture<TbProduct> product = CompletableFuture.supplyAsync(() ->
tbProductMapper.selectById(Integer.valueOf(tbMerchantCoupon.getRelationIds())));
CompletableFuture<List<TbProductSku>> productSku = CompletableFuture.supplyAsync(() ->
tbProductSkuMapper.selectSku(tbMerchantCoupon.getRelationIds()));
CompletableFuture<List<TagProductVO>> dictPro = CompletableFuture.supplyAsync(() ->
tagProductDeptsMapper.queryTagByProductId(tbMerchantCoupon.getRelationIds()));
CompletableFuture<TbPurchaseNotice> purchaseNotice = CompletableFuture.supplyAsync(() ->
purchaseNoticeMapper.queryById(tbMerchantCoupon.getId()));
Threads.call(shopInfo, product, productSku, dictPro);
ProductInfoVo productInfo = new ProductInfoVo();
// 图片组装
TbProduct tbProduct = product.get();
TbShopInfo tbShopInfo = shopInfo.get();
if (StringUtils.isNotBlank(tbProduct.getImages())) {
productInfo.setImages(JSON.parseArray(tbProduct.getImages()));
} else {
productInfo.setImages(new JSONArray());
}
//折扣
productInfo.setDiscount(tbMerchantCoupon.getRatio());
//价格组装
for (TbProductSku tbProductSku : productSku.get()) {
productInfo.setOriginPrice(tbProductSku.getSalePrice());
productInfo.setRealSalesNumber(tbProductSku.getRealSalesNumber() == null ? BigDecimal.ZERO : new BigDecimal(tbProductSku.getRealSalesNumber()));
Float discount = productInfo.getDiscount();
BigDecimal discountDecimal = new BigDecimal(discount);
productInfo.setSalePrice(tbProductSku.getSalePrice().multiply((discountDecimal.multiply(new BigDecimal("0.1")))));
}
//名称
productInfo.setProductName(tbProduct.getName());
//店铺
productInfo.setShopName(tbShopInfo.getShopName() + (StringUtils.isNotBlank(tbShopInfo.getChainName()) ? "(" + tbShopInfo.getChainName() + ")" : ""));
productInfo.setPhone(tbShopInfo.getPhone());
productInfo.setBusinessTime(tbShopInfo.getBusinessTime());
// productInfo.setDistances();//距离
productInfo.setAddress(tbShopInfo.getAddress());
//商品 暂时只做单商品
ProductVo productVo = new ProductVo();
TbShopUnit tbShopUnit = unitMapper.selectByPrimaryKey(Integer.valueOf(tbProduct.getUnitId()));
TbShopCategory tbShopCategory = categoryMapper.selectByPrimaryKey(Integer.valueOf(tbProduct.getCategoryId()));
productVo.setTitle(tbShopCategory.getName());
productVo.setNumber(1);
ProductVo.Food food = new ProductVo.Food();
food.setName(tbProduct.getName());
food.setUnit(tbShopUnit.getName());
food.setPrice(tbProduct.getLowPrice());
for (TagProductVO tagProductVO : dictPro.get()) {
food.getProTag().add(tagProductVO);
}
productVo.getFoods().add(food);
productInfo.getProductList().add(productVo);
productInfo.setPurchaseNotice(purchaseNotice.get());
return Result.success(CodeEnum.SUCCESS, productInfo);
}
private List<String> tagList(String tag) {
if (tag == null) {
return new ArrayList<>();
} else {
String[] arr = tag.split(",");
return new ArrayList<>(Arrays.asList(arr));
}
}
}