商品 可售时间 处理
This commit is contained in:
@@ -10,23 +10,24 @@ import java.util.List;
|
|||||||
@Component
|
@Component
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface TbProductGroupMapper {
|
public interface TbProductGroupMapper {
|
||||||
int deleteByPrimaryKey(Integer id);
|
// int deleteByPrimaryKey(Integer id);
|
||||||
|
|
||||||
int insert(TbProductGroup record);
|
// int insert(TbProductGroup record);
|
||||||
|
|
||||||
int insertSelective(TbProductGroup record);
|
// int insertSelective(TbProductGroup record);
|
||||||
|
|
||||||
TbProductGroup selectByPrimaryKey(Integer id);
|
TbProductGroup selectByPrimaryKey(Integer id);
|
||||||
|
|
||||||
int updateByPrimaryKeySelective(TbProductGroup record);
|
// int updateByPrimaryKeySelective(TbProductGroup record);
|
||||||
|
|
||||||
int updateByPrimaryKeyWithBLOBs(TbProductGroup record);
|
// int updateByPrimaryKeyWithBLOBs(TbProductGroup record);
|
||||||
|
|
||||||
int updateByPrimaryKey(TbProductGroup record);
|
// int updateByPrimaryKey(TbProductGroup record);
|
||||||
|
|
||||||
List<TbProductGroup> selectByIdAndShopId(@Param("code") String code);
|
List<TbProductGroup> selectByIdAndShopId(@Param("code") String code);
|
||||||
|
|
||||||
List<TbProductGroup> selectByQrcode(@Param("qrCode") String qrCode,@Param("groupId") Integer groupId);
|
List<TbProductGroup> selectByQrcode(@Param("qrCode") String qrCode,@Param("groupId") Integer groupId);
|
||||||
List<TbProductGroup> selectByShopId(@Param("shopId") String shopId,@Param("groupId") Integer groupId);
|
List<TbProductGroup> selectByShopId(@Param("shopId") String shopId,@Param("groupId") Integer groupId);
|
||||||
|
List<TbProductGroup> selectByProductId(@Param("shopId") String shopId,@Param("productId") String productId);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -137,6 +137,9 @@ public class TbProduct implements Serializable {
|
|||||||
private Integer stockNumber;
|
private Integer stockNumber;
|
||||||
private Integer suit;
|
private Integer suit;
|
||||||
|
|
||||||
|
//是否可售 1 可售 0非可售
|
||||||
|
private Integer isSale = 1;
|
||||||
|
|
||||||
|
|
||||||
public String getImages() {
|
public String getImages() {
|
||||||
return images;
|
return images;
|
||||||
@@ -672,4 +675,12 @@ public class TbProduct implements Serializable {
|
|||||||
public void setSuit(Integer suit) {
|
public void setSuit(Integer suit) {
|
||||||
this.suit = suit;
|
this.suit = suit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Integer getIsSale() {
|
||||||
|
return isSale;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsSale(Integer isSale) {
|
||||||
|
this.isSale = isSale;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.chaozhanggui.system.cashierservice.entity;
|
|||||||
|
|
||||||
import org.springframework.data.annotation.Transient;
|
import org.springframework.data.annotation.Transient;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -31,6 +32,15 @@ public class TbProductGroup implements Serializable {
|
|||||||
|
|
||||||
private String productIds;
|
private String productIds;
|
||||||
|
|
||||||
|
//是否可售 1 可售 0非可售
|
||||||
|
private Integer isSale = 1;
|
||||||
|
//是否使用时间管控 0不使用 1使用
|
||||||
|
private Integer useTime = 0;
|
||||||
|
|
||||||
|
private String saleStartTime;
|
||||||
|
|
||||||
|
private String saleEndTime;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Transient
|
@Transient
|
||||||
@@ -144,4 +154,37 @@ public class TbProductGroup implements Serializable {
|
|||||||
public void setProductIds(String productIds) {
|
public void setProductIds(String productIds) {
|
||||||
this.productIds = productIds == null ? null : productIds.trim();
|
this.productIds = productIds == null ? null : productIds.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Integer getUseTime() {
|
||||||
|
return useTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUseTime(Integer useTime) {
|
||||||
|
this.useTime = useTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSaleStartTime() {
|
||||||
|
return saleStartTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSaleStartTime(String saleStartTime) {
|
||||||
|
this.saleStartTime = saleStartTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSaleEndTime() {
|
||||||
|
return saleEndTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSaleEndTime(String saleEndTime) {
|
||||||
|
this.saleEndTime = saleEndTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getIsSale() {
|
||||||
|
return isSale;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsSale(Integer isSale) {
|
||||||
|
this.isSale = isSale;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -18,6 +18,7 @@ import com.chaozhanggui.system.cashierservice.util.*;
|
|||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
import com.google.common.util.concurrent.AtomicDouble;
|
import com.google.common.util.concurrent.AtomicDouble;
|
||||||
|
import lombok.Data;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -26,6 +27,10 @@ import org.springframework.util.CollectionUtils;
|
|||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.LocalTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
@@ -136,32 +141,72 @@ public class ProductService {
|
|||||||
Integer id = ObjectUtil.isNotEmpty(productGroupId) ? Integer.valueOf(productGroupId) : null;
|
Integer id = ObjectUtil.isNotEmpty(productGroupId) ? Integer.valueOf(productGroupId) : null;
|
||||||
//招牌菜
|
//招牌菜
|
||||||
List<TbProduct> tbProducts = tbProductMapper.selectIsSpecialty(Integer.valueOf(shopId));
|
List<TbProduct> tbProducts = tbProductMapper.selectIsSpecialty(Integer.valueOf(shopId));
|
||||||
concurrentMap.put("hots", handleDate(tbProducts));
|
concurrentMap.put("hots", handleDate(tbProducts,true));
|
||||||
List<TbProductGroup> groupList = tbProductGroupMapper.selectByShopId(shopId, id);
|
List<TbProductGroup> groupList = tbProductGroupMapper.selectByShopId(shopId, id);
|
||||||
if (ObjectUtil.isNotEmpty(groupList) && groupList.size() > 0) {
|
if (ObjectUtil.isNotEmpty(groupList) && groupList.size() > 0) {
|
||||||
//热销
|
//热销
|
||||||
TbProductGroup hot = new TbProductGroup();
|
TbProductGroup hot = new TbProductGroup();
|
||||||
hot.setName("热销");
|
hot.setName("热销");
|
||||||
List<TbProduct> hots = tbProductMapper.selectHot(shopId);
|
List<TbProduct> hots = tbProductMapper.selectHot(shopId);
|
||||||
hot.setProducts(handleDate(hots));
|
hot.setProducts(handleDate(hots,true));
|
||||||
//商品
|
//商品
|
||||||
groupList.parallelStream().forEach(g -> {
|
groupList.parallelStream().forEach(g -> {
|
||||||
|
if (g.getUseTime()==1) g.setIsSale(getIsSale(g.getSaleStartTime(),g.getSaleEndTime()));
|
||||||
String in = g.getProductIds().substring(1, g.getProductIds().length() - 1);
|
String in = g.getProductIds().substring(1, g.getProductIds().length() - 1);
|
||||||
if (ObjectUtil.isNotEmpty(in) && ObjectUtil.isNotNull(in)) {
|
if (ObjectUtil.isNotEmpty(in) && ObjectUtil.isNotNull(in)) {
|
||||||
// List<TbProduct> products = tbProductMapper.selectByIdIn(in);
|
// List<TbProduct> products = tbProductMapper.selectByIdIn(in);
|
||||||
List<TbProduct> products = tbProductMapper.selectByIdInAndCheck(in);
|
List<TbProduct> products = tbProductMapper.selectByIdInAndCheck(in);
|
||||||
g.setProducts(handleDate(products));
|
g.setProducts(handleDate(products,false));
|
||||||
} else {
|
} else {
|
||||||
g.setProducts(new ArrayList<>());
|
g.setProducts(new ArrayList<>());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
groupList.add(0, hot);
|
groupList.add(0, hot);
|
||||||
|
groupList.sort(Comparator.comparingInt(TbProductGroup::getIsSale));
|
||||||
concurrentMap.put("productInfo", groupList);
|
concurrentMap.put("productInfo", groupList);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Result.success(CodeEnum.SUCCESS, concurrentMap);
|
return Result.success(CodeEnum.SUCCESS, concurrentMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断是否在可售时间内
|
||||||
|
* @param startTimeStr HH:mm
|
||||||
|
* @param endTimeStr HH:mm
|
||||||
|
* @return 1 可售 0 不可售
|
||||||
|
*/
|
||||||
|
public Integer getIsSale(String startTimeStr,String endTimeStr) {
|
||||||
|
// 定义时间格式
|
||||||
|
DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("HH:mm");
|
||||||
|
// 解析时间字符串为 LocalTime 对象
|
||||||
|
LocalTime startTime = LocalTime.parse(startTimeStr, timeFormatter);
|
||||||
|
LocalTime endTime = LocalTime.parse(endTimeStr, timeFormatter);
|
||||||
|
// 获取当前日期
|
||||||
|
LocalDate today = LocalDate.now();
|
||||||
|
// 创建 LocalDateTime 对象
|
||||||
|
LocalDateTime startDateTime = LocalDateTime.of(today, startTime);
|
||||||
|
LocalDateTime endDateTime = LocalDateTime.of(today, endTime);
|
||||||
|
// 如果结束时间早于开始时间,说明时间段跨日
|
||||||
|
if (endDateTime.isBefore(startDateTime)) {
|
||||||
|
endDateTime = endDateTime.plusDays(1);
|
||||||
|
}
|
||||||
|
// 获取当前日期时间
|
||||||
|
LocalDateTime now = LocalDateTime.now();
|
||||||
|
if (now.isBefore(startDateTime)) {
|
||||||
|
// 将当前时间加上24小时(一天),进行比较
|
||||||
|
LocalDateTime nowPlus24 = now.plusHours(24);
|
||||||
|
//当前时间 小于开始时间,且结束时间小于开始时间
|
||||||
|
if (nowPlus24.isBefore(endDateTime)) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (now.isBefore(endDateTime)) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
public Object querySpec(QuerySpecDTO querySpecDTO) {
|
public Object querySpec(QuerySpecDTO querySpecDTO) {
|
||||||
TbProduct tbProduct = tbProductMapper.selectById(querySpecDTO.getProductId());
|
TbProduct tbProduct = tbProductMapper.selectById(querySpecDTO.getProductId());
|
||||||
if (tbProduct == null) {
|
if (tbProduct == null) {
|
||||||
@@ -296,9 +341,26 @@ public class ProductService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<TbProduct> handleDate(List<TbProduct> products){
|
/**
|
||||||
|
* 组装商品
|
||||||
|
* @param products 商品列表
|
||||||
|
* @param check 是否校验可售
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public List<TbProduct> handleDate(List<TbProduct> products,boolean check){
|
||||||
if (!CollectionUtils.isEmpty(products)) {
|
if (!CollectionUtils.isEmpty(products)) {
|
||||||
products.parallelStream().forEach(it -> {
|
products.parallelStream().forEach(it -> {
|
||||||
|
if(check){
|
||||||
|
List<TbProductGroup> tbProductGroups = tbProductGroupMapper.selectByProductId(it.getShopId(), it.getId().toString());
|
||||||
|
for (TbProductGroup g : tbProductGroups) {
|
||||||
|
if (g.getUseTime()==1) {
|
||||||
|
if (getIsSale(g.getSaleStartTime(), g.getSaleEndTime()) == 0) {
|
||||||
|
it.setIsSale(0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
TbShopUnit tbShopUnit = unitMapper.selectByPrimaryKey(Integer.valueOf(it.getUnitId()));
|
TbShopUnit tbShopUnit = unitMapper.selectByPrimaryKey(Integer.valueOf(it.getUnitId()));
|
||||||
it.setUnitSnap(tbShopUnit != null ? tbShopUnit.getName() : "");
|
it.setUnitSnap(tbShopUnit != null ? tbShopUnit.getName() : "");
|
||||||
//购物车数量
|
//购物车数量
|
||||||
|
|||||||
@@ -11,6 +11,9 @@
|
|||||||
<result column="detail" jdbcType="VARCHAR" property="detail" />
|
<result column="detail" jdbcType="VARCHAR" property="detail" />
|
||||||
<result column="style" jdbcType="VARCHAR" property="style" />
|
<result column="style" jdbcType="VARCHAR" property="style" />
|
||||||
<result column="sort" jdbcType="INTEGER" property="sort" />
|
<result column="sort" jdbcType="INTEGER" property="sort" />
|
||||||
|
<result column="use_time" jdbcType="INTEGER" property="useTime" />
|
||||||
|
<result column="sale_start_time" jdbcType="INTEGER" property="saleStartTime" />
|
||||||
|
<result column="sale_end_time" jdbcType="INTEGER" property="saleEndTime" />
|
||||||
<result column="created_at" jdbcType="BIGINT" property="createdAt" />
|
<result column="created_at" jdbcType="BIGINT" property="createdAt" />
|
||||||
<result column="updated_at" jdbcType="BIGINT" property="updatedAt" />
|
<result column="updated_at" jdbcType="BIGINT" property="updatedAt" />
|
||||||
</resultMap>
|
</resultMap>
|
||||||
@@ -18,7 +21,7 @@
|
|||||||
<result column="product_ids" jdbcType="LONGVARCHAR" property="productIds" />
|
<result column="product_ids" jdbcType="LONGVARCHAR" property="productIds" />
|
||||||
</resultMap>
|
</resultMap>
|
||||||
<sql id="Base_Column_List">
|
<sql id="Base_Column_List">
|
||||||
id, name, merchant_id, shop_id, pic, is_show, detail, style, sort, created_at, updated_at
|
id, name, merchant_id, shop_id, pic, is_show, detail, style, sort, created_at, updated_at , use_time, sale_start_time, sale_end_time
|
||||||
</sql>
|
</sql>
|
||||||
<sql id="Blob_Column_List">
|
<sql id="Blob_Column_List">
|
||||||
product_ids
|
product_ids
|
||||||
@@ -234,4 +237,9 @@
|
|||||||
</if>
|
</if>
|
||||||
order by sort asc
|
order by sort asc
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="selectByProductId" resultMap="BaseResultMap">
|
||||||
|
SELECT * FROM tb_product_group WHERE `shop_id` = #{shopId,jdbcType=VARCHAR} AND is_show = 1
|
||||||
|
AND `product_ids` LIKE concat('%',#{productId,jdbcType=VARCHAR},'%')
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
Reference in New Issue
Block a user