首页数据

This commit is contained in:
liuyingfang
2024-04-08 17:35:32 +08:00
parent 934a116cf2
commit 22bb4c6d15
10 changed files with 380 additions and 12 deletions

View File

@@ -2,10 +2,14 @@ package com.chaozhanggui.system.cashierservice.dao;
import com.chaozhanggui.system.cashierservice.entity.SysDict;
import com.chaozhanggui.system.cashierservice.entity.SysDictDetail;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
@Mapper
public interface SysDictDetailMapper {
int deleteByPrimaryKey(Long detailId);

View File

@@ -0,0 +1,91 @@
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)表数据库访问层
*
* @author lyf
* @since 2024-04-08 15:03:49
*/
@Component
@Mapper
public interface TagProductDeptsMapper {
/**
* 通过ID查询单条数据
*
* @param tagId 主键
* @return 实例对象
*/
TagProductDepts queryById(Integer tagId);
/**
* 查询指定行数据
*
* @param tagProductDepts 查询条件
* @param pageable 分页对象
* @return 对象列表
*/
List<TagProductDepts> queryAllByLimit(TagProductDepts tagProductDepts, @Param("pageable") Pageable pageable);
List<TagProductVO> queryTagAndProduct(@Param("list") List<Integer> list);
/**
* 统计总行数
*
* @param tagProductDepts 查询条件
* @return 总行数
*/
long count(TagProductDepts tagProductDepts);
/**
* 新增数据
*
* @param tagProductDepts 实例对象
* @return 影响行数
*/
int insert(TagProductDepts tagProductDepts);
/**
* 批量新增数据MyBatis原生foreach方法
*
* @param entities List<TagProductDepts> 实例对象列表
* @return 影响行数
*/
int insertBatch(@Param("entities") List<TagProductDepts> entities);
/**
* 批量新增或按主键更新数据MyBatis原生foreach方法
*
* @param entities List<TagProductDepts> 实例对象列表
* @return 影响行数
* @throws org.springframework.jdbc.BadSqlGrammarException 入参是空List的时候会抛SQL语句错误的异常请自行校验入参
*/
int insertOrUpdateBatch(@Param("entities") List<TagProductDepts> entities);
/**
* 修改数据
*
* @param tagProductDepts 实例对象
* @return 影响行数
*/
int update(TagProductDepts tagProductDepts);
/**
* 通过主键删除数据
*
* @param tagId 主键
* @return 影响行数
*/
int deleteById(Integer tagId);
}

View File

@@ -0,0 +1,53 @@
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;
}
}

View File

@@ -95,6 +95,18 @@ public class TbShopInfo implements Serializable {
* 商家二维码
*/
private String shopQrcode;
/**
* 商户标签
*/
private String tag;
public String getTag() {
return tag;
}
public void setTag(String tag) {
this.tag = tag;
}
public String getShopQrcode() {
return shopQrcode;

View File

@@ -1,6 +1,9 @@
package com.chaozhanggui.system.cashierservice.entity.vo;
import org.springframework.format.annotation.DateTimeFormat;
import java.math.BigDecimal;
import java.util.Date;
/**
* @author lyf
@@ -55,6 +58,19 @@ public class HomeVO {
private String distances ="100";
private Integer id;
/**
* 结束时间
*/
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private String endTime;
public String getEndTime() {
return endTime;
}
public void setEndTime(String endTime) {
this.endTime = endTime;
}
public Integer getId() {
return id;

View File

@@ -0,0 +1,34 @@
package com.chaozhanggui.system.cashierservice.entity.vo;
/**
* @author lyf
*/
public class TagProductVO {
private Integer productId;
private String name;
private String tags;
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;
}
}

View File

@@ -6,6 +6,7 @@ import com.chaozhanggui.system.cashierservice.entity.dto.HomeDto;
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.Threads;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@@ -36,6 +37,8 @@ public class HomePageService {
private TbProductMapper productMapper;
@Resource
private SysDictDetailMapper sysDictDetailMapper;
@Resource
private TagProductDeptsMapper tagProductDeptsMapper;
public Result homePage(HomeDto homeDto,String environmen) throws ExecutionException, InterruptedException {
@@ -50,9 +53,11 @@ public class HomePageService {
//统计shopId以及productId
List<String> shopIds = new ArrayList<>();
List<String> productIds = new ArrayList<>();
List<Integer> productIdsInt = new ArrayList<>();
for (TbMerchantCoupon coupon : tbMerchantCoupons) {
shopIds.add(coupon.getShopId());
productIds.add(coupon.getRelationIds());
productIdsInt.add(Integer.valueOf(coupon.getRelationIds()));
}
CompletableFuture<List<TbShopInfo>> shopInfo = CompletableFuture.supplyAsync(() ->
shopInfoMapper.selectByIds(shopIds));
@@ -60,26 +65,21 @@ public class HomePageService {
productMapper.selectByIds((productIds)));
CompletableFuture<List<TbProductSku>> productSku = CompletableFuture.supplyAsync(() ->
productSkuMapper.selectSkus((productIds)));
CompletableFuture<List<TbPlatformDict>> dictPro = CompletableFuture.supplyAsync(() ->
platformDictMapper.queryAllByType("proTag",environmen));
CompletableFuture<List<TbPlatformDict>> dictShop = CompletableFuture.supplyAsync(() ->
platformDictMapper.queryAllByType("shopTag",environmen));
Threads.call(shopInfo,product,productSku,dictPro,dictShop);
boolean isFirstAdded = true;
CompletableFuture<List<TagProductVO>> dictPro = CompletableFuture.supplyAsync(() ->
tagProductDeptsMapper.queryTagAndProduct(productIdsInt));
Threads.call(shopInfo,product,productSku,dictPro);
//组装
List<HomeVO> homeVOList = new ArrayList<>();
for (TbMerchantCoupon o :tbMerchantCoupons) {
HomeVO homeVO = new HomeVO();
homeVO.setDiscount(o.getRatio());
if (isFirstAdded){
homeVO.setShopTag(dictShop.get().get(0).getName());
homeVO.setProTag(dictPro.get().get(0).getName());
isFirstAdded = false;
}
for (TbShopInfo tbShopInfo : shopInfo.get()) {
if (o.getShopId().equals(tbShopInfo.getId().toString())) {
homeVO.setShopName(tbShopInfo.getShopName());
homeVO.setImage(tbShopInfo.getLogo());
TbPlatformDict tbPlatformDict = platformDictMapper.queryById(Integer.valueOf(tbShopInfo.getTag()));
homeVO.setShopTag(tbPlatformDict == null?"":tbPlatformDict.getName());
}
}
for (TbProduct tbProduct :product.get()) {
@@ -99,6 +99,12 @@ public class HomePageService {
homeVO.setSave(homeVO.getOriginPrice().subtract(homeVO.getSalePrice()));
}
}
for (TagProductVO tagProductVO :dictPro.get()) {
if (o.getRelationIds().equals(tagProductVO.getProductId().toString())){
homeVO.setProTag(tagProductVO.getTags());
}
}
homeVO.setEndTime(DateUtils.getTodayEndTimeAsString());
homeVOList.add(homeVO);
}

View File

@@ -3,8 +3,13 @@ package com.chaozhanggui.system.cashierservice.util;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
/**
* Created by SEELE on 2018/4/19.
@@ -242,6 +247,36 @@ public class DateUtils {
return date;
}
/**
* 今天结束时间
* @return
*/
public static Date getDayEnd() {
Calendar cal = new GregorianCalendar();
cal.set(Calendar.HOUR_OF_DAY, 23);
cal.set(Calendar.MINUTE, 59);
cal.set(Calendar.SECOND, 59);
cal.set(Calendar.MILLISECOND, 999);
return cal.getTime();
}
public static String getTodayEndTimeAsString() {
// 获取今天的日期
LocalDate today = LocalDate.now();
// 创建今天的结束时间23:59:59.999
LocalTime endTime = LocalTime.of(23, 59, 59, 999_000_000);
// 组合日期和时间
LocalDateTime todayEndTime = LocalDateTime.of(today, endTime);
// 格式化时间
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
// 转换为字符串
return todayEndTime.format(formatter);
}
/**
* 得到n天之后是周几
* @param days