diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/ProductController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/ProductController.java index 5bcca82..2af5a4f 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/ProductController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/ProductController.java @@ -9,6 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.util.Map; +import java.util.concurrent.ExecutionException; @CrossOrigin(origins = "*") @RestController @@ -40,9 +41,9 @@ public class ProductController { return productService.queryProductSku(shopId,productId,spec_tag); } -// @GetMapping("/productInfo") -// public Result productInfo(@RequestParam Integer productId){ -// return productService.productInfo() -// } + @GetMapping("/productInfo") + public Result productInfo(@RequestParam Integer productId) throws Exception { + return productService.productInfo(productId); + } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TagProductDeptsMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TagProductDeptsMapper.java index 0b63548..d595e87 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TagProductDeptsMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TagProductDeptsMapper.java @@ -1,16 +1,14 @@ package com.chaozhanggui.system.cashierservice.dao; -import com.chaozhanggui.system.cashierservice.entity.TagProductDepts; import com.chaozhanggui.system.cashierservice.entity.vo.TagProductVO; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; -import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Component; import java.util.List; /** - * (TagProductDepts)表数据库访问层 + * (TagProductDepts) 商品标签 表数据库访问层 * * @author lyf * @since 2024-04-08 15:03:49 @@ -18,74 +16,7 @@ import java.util.List; @Component @Mapper public interface TagProductDeptsMapper { - - /** - * 通过ID查询单条数据 - * - * @param tagId 主键 - * @return 实例对象 - */ - TagProductDepts queryById(Integer tagId); - - /** - * 查询指定行数据 - * - * @param tagProductDepts 查询条件 - * @param pageable 分页对象 - * @return 对象列表 - */ - List queryAllByLimit(TagProductDepts tagProductDepts, @Param("pageable") Pageable pageable); - List queryTagAndProduct(@Param("list") List list); - - /** - * 统计总行数 - * - * @param tagProductDepts 查询条件 - * @return 总行数 - */ - long count(TagProductDepts tagProductDepts); - - /** - * 新增数据 - * - * @param tagProductDepts 实例对象 - * @return 影响行数 - */ - int insert(TagProductDepts tagProductDepts); - - /** - * 批量新增数据(MyBatis原生foreach方法) - * - * @param entities List 实例对象列表 - * @return 影响行数 - */ - int insertBatch(@Param("entities") List entities); - - /** - * 批量新增或按主键更新数据(MyBatis原生foreach方法) - * - * @param entities List 实例对象列表 - * @return 影响行数 - * @throws org.springframework.jdbc.BadSqlGrammarException 入参是空List的时候会抛SQL语句错误的异常,请自行校验入参 - */ - int insertOrUpdateBatch(@Param("entities") List entities); - - /** - * 修改数据 - * - * @param tagProductDepts 实例对象 - * @return 影响行数 - */ - int update(TagProductDepts tagProductDepts); - - /** - * 通过主键删除数据 - * - * @param tagId 主键 - * @return 影响行数 - */ - int deleteById(Integer tagId); - + List queryTagByProductId(@Param("productId") String productId); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbPlatformDictMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbPlatformDictMapper.java index fa1ce5b..3c7cd23 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbPlatformDictMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbPlatformDictMapper.java @@ -22,64 +22,9 @@ public interface TbPlatformDictMapper { */ TbPlatformDict queryById(Integer id); - /** - * 查询指定行数据 - * - * @param tbPlatformDict 查询条件 - * @param pageable 分页对象 - * @return 对象列表 - */ - List queryAllByLimit(TbPlatformDict tbPlatformDict, @Param("pageable") Pageable pageable); + List queryByIdList(List idList); List queryAllByType(@Param("type") String type,@Param("environment") String environment); - /** - * 统计总行数 - * - * @param tbPlatformDict 查询条件 - * @return 总行数 - */ - long count(TbPlatformDict tbPlatformDict); - - /** - * 新增数据 - * - * @param tbPlatformDict 实例对象 - * @return 影响行数 - */ - int insert(TbPlatformDict tbPlatformDict); - - /** - * 批量新增数据(MyBatis原生foreach方法) - * - * @param entities List 实例对象列表 - * @return 影响行数 - */ - int insertBatch(@Param("entities") List entities); - - /** - * 批量新增或按主键更新数据(MyBatis原生foreach方法) - * - * @param entities List 实例对象列表 - * @return 影响行数 - * @throws org.springframework.jdbc.BadSqlGrammarException 入参是空List的时候会抛SQL语句错误的异常,请自行校验入参 - */ - int insertOrUpdateBatch(@Param("entities") List entities); - - /** - * 修改数据 - * - * @param tbPlatformDict 实例对象 - * @return 影响行数 - */ - int update(TbPlatformDict tbPlatformDict); - - /** - * 通过主键删除数据 - * - * @param id 主键 - * @return 影响行数 - */ - int deleteById(Integer id); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbProductSkuMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbProductSkuMapper.java index 018ec3e..7edb951 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbProductSkuMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbProductSkuMapper.java @@ -38,4 +38,5 @@ public interface TbProductSkuMapper { List selectDownSku(@Param("list") List productId); List selectSkus(@Param("list") List productId); + List selectSku(@Param("productId") String productId); } \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbPurchaseNoticeMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbPurchaseNoticeMapper.java new file mode 100644 index 0000000..d1fa563 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbPurchaseNoticeMapper.java @@ -0,0 +1,22 @@ +package com.chaozhanggui.system.cashierservice.dao; + +import com.chaozhanggui.system.cashierservice.entity.TbPurchaseNotice; + +/** + * 购买须知(关联tb_merchant_coupon)(TbPurchaseNotice)表数据库访问层 + * + * @author ww + * @since 2024-04-11 10:00:23 + */ +public interface TbPurchaseNoticeMapper { + + /** + * 通过ID查询单条数据 + * + * @param id 主键 + * @return 实例对象 + */ + TbPurchaseNotice queryById(Integer id); + +} + diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TagProductDepts.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TagProductDepts.java deleted file mode 100644 index 37e6904..0000000 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TagProductDepts.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.chaozhanggui.system.cashierservice.entity; - -import java.util.Date; -import java.io.Serializable; - -/** - * (TagProductDepts)实体类 - * - * @author lyf - * @since 2024-04-08 14:57:05 - */ -public class TagProductDepts implements Serializable { - private static final long serialVersionUID = -39116122966010022L; - /** - * 标签id - */ - private Integer tagId; - /** - * 商品id - */ - private Integer productId; - /** - * 创建时间 - */ - private Date createTime; - - - public Integer getTagId() { - return tagId; - } - - public void setTagId(Integer tagId) { - this.tagId = tagId; - } - - public Integer getProductId() { - return productId; - } - - public void setProductId(Integer productId) { - this.productId = productId; - } - - public Date getCreateTime() { - return createTime; - } - - public void setCreateTime(Date createTime) { - this.createTime = createTime; - } - -} - diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbPlatformDict.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbPlatformDict.java index 55e42cf..9dbb00a 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbPlatformDict.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbPlatformDict.java @@ -12,10 +12,16 @@ public class TbPlatformDict implements Serializable { private static final long serialVersionUID = -34581903392247717L; private Integer id; + /** + * 标签前图标 + */ + private String shareImg; /** * 描述 同类型下 name唯一 */ private String name; + private String fontColor; + private String backColor; /** * homeDistrict--金刚区(首页) carousel--轮播图 tag--标签 */ @@ -24,10 +30,6 @@ public class TbPlatformDict implements Serializable { * 封面图 */ private String coverImg; - /** - * 分享图 - */ - private String shareImg; /** * 视频URL地址 */ @@ -36,10 +38,8 @@ public class TbPlatformDict implements Serializable { * 视频封面图 */ private String videoCoverImg; - /** - * 相对跳转地址 - */ - private String relUrl; + + private String jumpType; /** * 绝对跳转地址 */ @@ -78,6 +78,22 @@ public class TbPlatformDict implements Serializable { this.id = id; } + public String getFontColor() { + return fontColor; + } + + public void setFontColor(String fontColor) { + this.fontColor = fontColor; + } + + public String getBackColor() { + return backColor; + } + + public void setBackColor(String backColor) { + this.backColor = backColor; + } + public String getName() { return name; } @@ -126,12 +142,12 @@ public class TbPlatformDict implements Serializable { this.videoCoverImg = videoCoverImg; } - public String getRelUrl() { - return relUrl; + public String getJumpType() { + return jumpType; } - public void setRelUrl(String relUrl) { - this.relUrl = relUrl; + public void setJumpType(String jumpType) { + this.jumpType = jumpType; } public String getAbsUrl() { diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbPurchaseNotice.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbPurchaseNotice.java new file mode 100644 index 0000000..1085810 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbPurchaseNotice.java @@ -0,0 +1,160 @@ +package com.chaozhanggui.system.cashierservice.entity; + +import java.io.Serializable; + +/** + * 购买须知(关联tb_merchant_coupon)(TbPurchaseNotice)实体类 + * + * @author ww + * @since 2024-04-11 10:00:23 + */ +public class TbPurchaseNotice implements Serializable { + private static final long serialVersionUID = 811103518413221387L; + /** + * 自增 + */ + private Integer id; + /** + * 商户卷Id + */ + private Integer couponId; + /** + * 使用日期说明 + */ + private String dateUsed; + /** + * 可用时间说明 + */ + private String availableTime; + /** + * 预约方式 + */ + private String bookingType; + /** + * 退款说明 + */ + private String refundPolicy; + /** + * 使用规则 + */ + private String usageRules; + /** + * 发票说明 + */ + private String invoiceInfo; + /** + * 团购价说明 + */ + private String groupPurInfo; + /** + * 门市价/划线价说明 + */ + private String marketPriceInfo; + /** + * 折扣说明 + */ + private String discountInfo; + /** + * 平台温馨提示 + */ + private String platformTips; + + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public Integer getCouponId() { + return couponId; + } + + public void setCouponId(Integer couponId) { + this.couponId = couponId; + } + + public String getDateUsed() { + return dateUsed; + } + + public void setDateUsed(String dateUsed) { + this.dateUsed = dateUsed; + } + + public String getAvailableTime() { + return availableTime; + } + + public void setAvailableTime(String availableTime) { + this.availableTime = availableTime; + } + + public String getBookingType() { + return bookingType; + } + + public void setBookingType(String bookingType) { + this.bookingType = bookingType; + } + + public String getRefundPolicy() { + return refundPolicy; + } + + public void setRefundPolicy(String refundPolicy) { + this.refundPolicy = refundPolicy; + } + + public String getUsageRules() { + return usageRules; + } + + public void setUsageRules(String usageRules) { + this.usageRules = usageRules; + } + + public String getInvoiceInfo() { + return invoiceInfo; + } + + public void setInvoiceInfo(String invoiceInfo) { + this.invoiceInfo = invoiceInfo; + } + + public String getGroupPurInfo() { + return groupPurInfo; + } + + public void setGroupPurInfo(String groupPurInfo) { + this.groupPurInfo = groupPurInfo; + } + + public String getMarketPriceInfo() { + return marketPriceInfo; + } + + public void setMarketPriceInfo(String marketPriceInfo) { + this.marketPriceInfo = marketPriceInfo; + } + + public String getDiscountInfo() { + return discountInfo; + } + + public void setDiscountInfo(String discountInfo) { + this.discountInfo = discountInfo; + } + + public String getPlatformTips() { + return platformTips; + } + + public void setPlatformTips(String platformTips) { + this.platformTips = platformTips; + } + +} + diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeUpVO.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeUpVO.java index d1ea0a6..02728f4 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeUpVO.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeUpVO.java @@ -1,8 +1,6 @@ package com.chaozhanggui.system.cashierservice.entity.vo; -import com.chaozhanggui.system.cashierservice.entity.SysDict; import com.chaozhanggui.system.cashierservice.entity.TbPlatformDict; -import lombok.Data; import java.util.List; @@ -14,11 +12,11 @@ public class HomeUpVO { /** * 轮播图 */ - List carousel; + List carousel; /** * 金刚区 */ - List district; + List district; /** * 条件查询 */ @@ -60,19 +58,19 @@ public class HomeUpVO { this.salesList = salesList; } - public List getCarousel() { + public List getCarousel() { return carousel; } - public void setCarousel(List carousel) { + public void setCarousel(List carousel) { this.carousel = carousel; } - public List getDistrict() { + public List getDistrict() { return district; } - public void setDistrict(List district) { + public void setDistrict(List district) { this.district = district; } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeVO.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeVO.java index dc77381..a97c41a 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeVO.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/HomeVO.java @@ -1,9 +1,7 @@ package com.chaozhanggui.system.cashierservice.entity.vo; -import org.springframework.format.annotation.DateTimeFormat; - import java.math.BigDecimal; -import java.util.Date; +import java.util.ArrayList; import java.util.List; /** @@ -48,11 +46,11 @@ public class HomeVO { /** * 店铺标签 */ - private List shopTag; + private List shopTag; /** * 商品标签 */ - private List proTag; + private List proTag=new ArrayList<>(); /** * 距离 */ @@ -88,19 +86,19 @@ public class HomeVO { this.distances = distances; } - public List getShopTag() { + public List getShopTag() { return shopTag; } - public void setShopTag(List shopTag) { + public void setShopTag(List shopTag) { this.shopTag = shopTag; } - public List getProTag() { + public List getProTag() { return proTag; } - public void setProTag(List proTag) { + public void setProTag(List proTag) { this.proTag = proTag; } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/ProductInfoVo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/ProductInfoVo.java new file mode 100644 index 0000000..394eca8 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/ProductInfoVo.java @@ -0,0 +1,73 @@ +package com.chaozhanggui.system.cashierservice.entity.vo; + +import com.alibaba.fastjson.JSONArray; +import com.chaozhanggui.system.cashierservice.entity.TbPurchaseNotice; +import lombok.Data; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; + +/** + * @author lyf + */ +@Data +public class ProductInfoVo { + /** + * 商品图片 + */ + private JSONArray images; + + /** + * 现价 + */ + private BigDecimal salePrice; + /** + * 折扣 + */ + private Float discount; + /** + * 原价 + */ + private BigDecimal originPrice; + + /** + * 销量 + */ + private BigDecimal realSalesNumber; + + /** + * 商品名称 + */ + private String productName; + /** + * 店铺名称 + */ + private String shopName; + /** + * 联系方式 + */ + private String phone; + /** + * 营业时间 + */ + private String businessTime; + /** + * 距离 + */ + private String distances = "100"; + /** + * 地址 + */ + private String address; + + /** + * 套餐详情 + */ + List productList = new ArrayList<>(); + + /** + * 购买须知/价格说明 + */ + private TbPurchaseNotice purchaseNotice; +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/ProductVo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/ProductVo.java new file mode 100644 index 0000000..05c9af4 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/ProductVo.java @@ -0,0 +1,30 @@ +package com.chaozhanggui.system.cashierservice.entity.vo; + +import lombok.Data; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; + +@Data +public class ProductVo { + //选几个 + private Integer number; + + //类别 + private String title; + + //食物 + private List foods=new ArrayList<>(); // 食品列表 + + @Data + public static class Food { + private String name; // 商品名称 + private BigDecimal price; // 售价 + private String unit; // 单位 + /** + * 商品标签 + */ + private List proTag=new ArrayList<>(); + } +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/TagProductVO.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/TagProductVO.java index 939d5cc..1fbda4d 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/TagProductVO.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/TagProductVO.java @@ -1,34 +1,22 @@ package com.chaozhanggui.system.cashierservice.entity.vo; +import lombok.Data; + /** + * 商品 标签 * @author lyf */ +@Data public class TagProductVO { + //商品id private Integer productId; + //标签前 小图标 + private String shareImg; + //标签 名称 private String name; - private String tags; + //字体颜色 + private String fontColor; + //背景色 + private String backColor; - public Integer getProductId() { - return productId; - } - - public void setProductId(Integer productId) { - this.productId = productId; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getTags() { - return tags; - } - - public void setTags(String tags) { - this.tags = tags; - } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/productInfoVo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/productInfoVo.java deleted file mode 100644 index 0073c6e..0000000 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/productInfoVo.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.chaozhanggui.system.cashierservice.entity.vo; - -import java.math.BigDecimal; -import java.util.List; - -/** - * @author lyf - */ -public class productInfoVo { - /** - * 商品图片 - */ - private Listimages; - - /** - * 原价 - */ - private BigDecimal originPrice; - /** - * 现价 - */ - private BigDecimal salePrice; - /** - * 折扣 - */ - private Float discount; - /** - * 共省金额 - */ - private BigDecimal save; - - /** - * 销量 - */ - private BigDecimal realSalesNumber; - - /** - * 结束时间 - */ - private Long endTime; -} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java index 2e8773d..f59fd8a 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/HomePageService.java @@ -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 shopTagIds = Arrays.stream(tbShopInfo.getTag().split(",")) + .map(Integer::parseInt) + .collect(Collectors.toList()); + List 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 carouselList = platformDictMapper.queryAllByType("carousel", environment); - homeUpVO.setCarousel(carouselList); + homeUpVO.setCarousel(JSONUtil.parseListTNewList(carouselList, HomeCarouselVo.class)); //金刚区 List districtList = platformDictMapper.queryAllByType("homeDistrict", environment); - homeUpVO.setDistrict(districtList); + homeUpVO.setDistrict(JSONUtil.parseListTNewList(districtList, HomeDistrictVo.class)); + //菜单 List sysDicts = sysDictDetailMapper.selectByAll(); List dicDetailVO = new ArrayList<>(); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java index 8581305..53cfa05 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java @@ -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 concurrentMap = new ConcurrentHashMap<>(); - - - - public Result queryProduct(String code,String productGroupId){ - - ConcurrentMap 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 groupList=tbProductGroupMapper.selectByQrcode(code,id); - if(ObjectUtil.isNotEmpty(groupList)&&groupList.size()>0){ + Integer id = ObjectUtil.isNotEmpty(productGroupId) ? Integer.valueOf(productGroupId) : null; + List 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 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 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 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 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 shopInfo = CompletableFuture.supplyAsync(() -> + tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(tbMerchantCoupon.getShopId()))); + CompletableFuture product = CompletableFuture.supplyAsync(() -> + tbProductMapper.selectById(Integer.valueOf(tbMerchantCoupon.getRelationIds()))); + CompletableFuture> productSku = CompletableFuture.supplyAsync(() -> + tbProductSkuMapper.selectSku(tbMerchantCoupon.getRelationIds())); + CompletableFuture> dictPro = CompletableFuture.supplyAsync(() -> + tagProductDeptsMapper.queryTagByProductId(tbMerchantCoupon.getRelationIds())); + CompletableFuture 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 tagList(String tag) { + if (tag == null) { + return new ArrayList<>(); + } else { + String[] arr = tag.split(","); + return new ArrayList<>(Arrays.asList(arr)); + } + } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/util/JSONUtil.java b/src/main/java/com/chaozhanggui/system/cashierservice/util/JSONUtil.java index 69ff2ee..0020938 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/util/JSONUtil.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/util/JSONUtil.java @@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONArray; 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.*; @@ -172,6 +173,25 @@ public class JSONUtil { } } + /** + * @param list 某集合 + * @param clazz 要转成的实体 + * @return + * @param + */ + public static List parseListTNewList(List list, Class clazz) { + ObjectMapper objectMapper = new ObjectMapper(); // 创建JSON转换器 + try { + // 将List转换为JSON字符串 + String json = objectMapper.writeValueAsString(list); + // 将JSON字符串转换为List + return objectMapper.readValue(json, objectMapper.getTypeFactory().constructCollectionType(List.class, clazz)); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + public static class JSONEntity { public JSONEntity() { } diff --git a/src/main/resources/mapper/TagProductDeptsMapper.xml b/src/main/resources/mapper/TagProductDeptsMapper.xml index 17e44e5..3501c77 100644 --- a/src/main/resources/mapper/TagProductDeptsMapper.xml +++ b/src/main/resources/mapper/TagProductDeptsMapper.xml @@ -2,116 +2,39 @@ - - - - - - - - - - - - - - - - - insert into tag_product_depts(product_id, create_time) - values (#{productId}, #{createTime}) - - - - insert into tag_product_depts(product_id, create_time) - values - - (#{entity.productId}, #{entity.createTime}) - - - - - insert into tag_product_depts(product_id, create_time) - values - - (#{entity.productId}, #{entity.createTime}) - - on duplicate key update - product_id = values(product_id), - create_time = values(create_time) - - - - - update tag_product_depts - - - product_id = #{productId}, - - - create_time = #{createTime}, - - - where tag_id = #{tagId} - - - - - delete from tag_product_depts where tag_id = #{tagId} - + diff --git a/src/main/resources/mapper/TbPlatformDictMapper.xml b/src/main/resources/mapper/TbPlatformDictMapper.xml index bac90db..46e3530 100644 --- a/src/main/resources/mapper/TbPlatformDictMapper.xml +++ b/src/main/resources/mapper/TbPlatformDictMapper.xml @@ -4,13 +4,15 @@ + + + - - + @@ -23,121 +25,25 @@ - - select - id, name, type, cover_img, share_img, video, video_cover_img, rel_url, abs_url, created_at, updated_at, is_show_cash, is_show_mall, is_show_app, sort + id, name, type, font_color, back_color, cover_img, share_img, video, video_cover_img, jump_type, abs_url, created_at, updated_at, is_show_cash, is_show_mall, is_show_app, sort from tb_platform_dict - - - and id = #{id} - - - and name = #{name} - - - and type = #{type} - - - and cover_img = #{coverImg} - - - and share_img = #{shareImg} - - - and video = #{video} - - - and video_cover_img = #{videoCoverImg} - - - and rel_url = #{relUrl} - - - and abs_url = #{absUrl} - - - and created_at = #{createdAt} - - - and updated_at = #{updatedAt} - - - and is_show_cash = #{isShowCash} - - - and is_show_mall = #{isShowMall} - - - and is_show_app = #{isShowApp} - - - and sort = #{sort} - - - limit #{pageable.offset}, #{pageable.pageSize} + where id IN + + #{id} + - - - - - - insert into tb_platform_dict(name, type, cover_img, share_img, video, video_cover_img, rel_url, abs_url, created_at, updated_at, is_show_cash, is_show_mall, is_show_app, sort) - values (#{name}, #{type}, #{coverImg}, #{shareImg}, #{video}, #{videoCoverImg}, #{relUrl}, #{absUrl}, #{createdAt}, #{updatedAt}, #{isShowCash}, #{isShowMall}, #{isShowApp}, #{sort}) - - - - insert into tb_platform_dict(name, type, cover_img, share_img, video, video_cover_img, rel_url, abs_url, created_at, updated_at, is_show_cash, is_show_mall, is_show_app, sort) - values - - (#{entity.name}, #{entity.type}, #{entity.coverImg}, #{entity.shareImg}, #{entity.video}, #{entity.videoCoverImg}, #{entity.relUrl}, #{entity.absUrl}, #{entity.createdAt}, #{entity.updatedAt}, #{entity.isShowCash}, #{entity.isShowMall}, #{entity.isShowApp}, #{entity.sort}) - - - - - insert into tb_platform_dict(name, type, cover_img, share_img, video, video_cover_img, rel_url, abs_url, created_at, updated_at, is_show_cash, is_show_mall, is_show_app, sort) - values - - (#{entity.name}, #{entity.type}, #{entity.coverImg}, #{entity.shareImg}, #{entity.video}, #{entity.videoCoverImg}, #{entity.relUrl}, #{entity.absUrl}, #{entity.createdAt}, #{entity.updatedAt}, #{entity.isShowCash}, #{entity.isShowMall}, #{entity.isShowApp}, #{entity.sort}) - - on duplicate key update - name = values(name), - type = values(type), - cover_img = values(cover_img), - share_img = values(share_img), - video = values(video), - video_cover_img = values(video_cover_img), - rel_url = values(rel_url), - abs_url = values(abs_url), - created_at = values(created_at), - updated_at = values(updated_at), - is_show_cash = values(is_show_cash), - is_show_mall = values(is_show_mall), - is_show_app = values(is_show_app), - sort = values(sort) - - - - - update tb_platform_dict - - - name = #{name}, - - - type = #{type}, - - - cover_img = #{coverImg}, - - - share_img = #{shareImg}, - - - video = #{video}, - - - video_cover_img = #{videoCoverImg}, - - - rel_url = #{relUrl}, - - - abs_url = #{absUrl}, - - - created_at = #{createdAt}, - - - updated_at = #{updatedAt}, - - - is_show_cash = #{isShowCash}, - - - is_show_mall = #{isShowMall}, - - - is_show_app = #{isShowApp}, - - - sort = #{sort}, - - - where id = #{id} - - - - - delete from tb_platform_dict where id = #{id} - - diff --git a/src/main/resources/mapper/TbProductSkuMapper.xml b/src/main/resources/mapper/TbProductSkuMapper.xml index 2f30e56..44b1a0d 100644 --- a/src/main/resources/mapper/TbProductSkuMapper.xml +++ b/src/main/resources/mapper/TbProductSkuMapper.xml @@ -381,6 +381,14 @@ GROUP BY product_id + + select + + + from tb_purchase_notice + where id = #{id} + + + +