Merge branch 'refs/heads/dev' into gyj

This commit is contained in:
GYJ
2024-11-01 10:00:25 +08:00
24 changed files with 539 additions and 66 deletions

View File

@@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.chaozhanggui.system.cashierservice.dao.*;
import com.chaozhanggui.system.cashierservice.entity.*;
import com.chaozhanggui.system.cashierservice.entity.Enum.ShopWxMsgTypeEnum;
import com.chaozhanggui.system.cashierservice.exception.MsgException;
import com.chaozhanggui.system.cashierservice.netty.PushToAppChannelHandlerAdapter;
import com.chaozhanggui.system.cashierservice.rabbit.RabbitProducer;
@@ -336,13 +337,13 @@ public class CartService {
(product.getIsDistribute() == 1 && product.getStockNumber() - num <= productSku.getWarnLine())
|| (product.getIsDistribute() != 1) && productSku.getStockNumber() - num <= productSku.getWarnLine()
) {
List<TbShopOpenId> shopOpenIds = shopOpenIdMapper.selectByShopId(Integer.valueOf(product.getShopId()));
List<TbShopOpenId> shopOpenIds = shopOpenIdMapper.selectStateByShopIdAndType(product.getShopId(), ShopWxMsgTypeEnum.STOCK_MSG.getType());
shopOpenIds.forEach(item -> {
String message = redisUtil.getMessage(RedisCst.SEND_STOCK_WARN_MSG + product.getId() + ":" + item.getOpenId());
if (message == null) {
wxAccountUtil.sendStockWarnMsg("商品库存不足", product.getName(),
product.getIsDistribute() == 1 ? product.getStockNumber() - num : (int) (productSku.getStockNumber() - num)
, item.getOpenId());
, item.getOpenId(), ShopWxMsgTypeEnum.STOCK_MSG, shopInfo.getId());
redisUtil.saveMessage(RedisCst.SEND_STOCK_WARN_MSG + product.getId() + ":" + item.getOpenId(), product.getId().toString(), 60 * 30L);
}else {
log.info("{}已在30分钟内推送过消息跳过发送", item.getOpenId());

View File

@@ -1,6 +1,7 @@
package com.chaozhanggui.system.cashierservice.service;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
@@ -60,43 +61,61 @@ public class LoginService {
private final TbShopOpenIdMapper shopOpenIdMapper;
private final static int[] MSG_TYPE_LIST = new int[] {0, 1, 2};
public LoginService(TbShopOpenIdMapper shopOpenIdMapper) {
this.shopOpenIdMapper = shopOpenIdMapper;
}
public void addShopId(String openId, String shopId, Integer type, String nickName, String avatar) {
TbUserShopMsg shopMsg = tbUserShopMsgMapper.selectByShopIdAndOpenId(Integer.valueOf(shopId), openId);
if (Objects.isNull(shopMsg)) {
shopMsg = new TbUserShopMsg();
shopMsg.setShopId(Integer.valueOf(shopId));
shopMsg.setOpenId(openId);
shopMsg.setCreateTime(new Date());
shopMsg.setStatus("1");
tbUserShopMsgMapper.insert(shopMsg);
}
public void addShopId(String openId, String shopId, Integer type1, String nickName, String avatar) {
// 为商家绑定openid
TbShopOpenId tbShopOpenId = shopOpenIdMapper.countByOpenId(openId, Integer.valueOf(shopId), type);
if (tbShopOpenId == null) {
TbShopOpenId shopOpenId = new TbShopOpenId();
shopOpenId.setOpenId(openId);
shopOpenId.setCreateTime(DateUtil.date());
shopOpenId.setShopId(Integer.valueOf(shopId));
shopOpenId.setStatus(1);
shopOpenId.setNickname(nickName);
shopOpenId.setAvatar(avatar);
shopOpenId.setType(type == null ? -1 : type);
shopOpenIdMapper.insert(shopOpenId);
// TbShopOpenId tbShopOpenId = shopOpenIdMapper.countByOpenId(openId, Integer.valueOf(shopId), null);
List<TbShopOpenId> shopOpenIdList = shopOpenIdMapper.selectStateByShopIdAndOpenId(openId, shopId);
int openCount = shopOpenIdMapper.selectStateByShopId(shopId);
if (shopOpenIdList.isEmpty()) {
for (int type : MSG_TYPE_LIST) {
addShopOpenId(openId, shopId, nickName, avatar, openCount, type);
}
} else {
tbShopOpenId.setUpdateTime(DateUtil.date());
tbShopOpenId.setNickname(nickName);
tbShopOpenId.setAvatar(avatar);
shopOpenIdMapper.updateByPrimaryKeySelective(tbShopOpenId);
boolean fullSize = shopOpenIdList.size() == MSG_TYPE_LIST.length;
HashMap<String, Object> typeMap = new HashMap<>();
for (TbShopOpenId tbShopOpenId : shopOpenIdList) {
typeMap.put(tbShopOpenId.getType().toString(), tbShopOpenId.getOpenId());
tbShopOpenId.setType(null);
tbShopOpenId.setUpdateTime(DateUtil.date());
tbShopOpenId.setNickname(nickName);
tbShopOpenId.setAvatar(avatar);
shopOpenIdMapper.updateByPrimaryKeySelective(tbShopOpenId);
}
if (fullSize) {
return;
}
for (int type : MSG_TYPE_LIST) {
if (typeMap.get(String.valueOf(type)) == null) {
addShopOpenId(openId, shopId, nickName, avatar, openCount, type);
}
}
}
}
private void addShopOpenId(String openId, String shopId, String nickName, String avatar, int openCount, int type) {
int count = shopOpenIdMapper.countStateByShopIdAndType(shopId, type);
TbShopOpenId shopOpenId = new TbShopOpenId();
shopOpenId.setOpenId(openId);
shopOpenId.setCreateTime(DateUtil.date());
shopOpenId.setShopId(Integer.valueOf(shopId));
shopOpenId.setStatus(openCount > 0 ? count > 0 ? 1 : 0 : 0);
shopOpenId.setNickname(nickName);
shopOpenId.setAvatar(avatar);
shopOpenId.setType(type);
shopOpenIdMapper.insert(shopOpenId);
}
public Result wxBusinessLogin(String openId, String shopId) {
TbUserShopMsg shopMsg = tbUserShopMsgMapper.selectByShopIdAndOpenId(Integer.valueOf(shopId), openId);

View File

@@ -18,6 +18,7 @@ import com.chaozhanggui.system.cashierservice.util.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.common.util.concurrent.AtomicDouble;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -26,6 +27,10 @@ import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
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.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
@@ -136,25 +141,27 @@ public class ProductService {
Integer id = ObjectUtil.isNotEmpty(productGroupId) ? Integer.valueOf(productGroupId) : null;
//招牌菜
List<TbProduct> tbProducts = tbProductMapper.selectIsSpecialty(Integer.valueOf(shopId));
concurrentMap.put("hots", handleDate(tbProducts));
concurrentMap.put("hots", handleDate(tbProducts,true,1));
List<TbProductGroup> groupList = tbProductGroupMapper.selectByShopId(shopId, id);
if (ObjectUtil.isNotEmpty(groupList) && groupList.size() > 0) {
//热销
TbProductGroup hot = new TbProductGroup();
hot.setName("热销");
List<TbProduct> hots = tbProductMapper.selectHot(shopId);
hot.setProducts(handleDate(hots));
hot.setProducts(handleDate(hots,true,1));
//商品
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);
if (ObjectUtil.isNotEmpty(in) && ObjectUtil.isNotNull(in)) {
// List<TbProduct> products = tbProductMapper.selectByIdIn(in);
List<TbProduct> products = tbProductMapper.selectByIdInAndCheck(in);
g.setProducts(handleDate(products));
g.setProducts(handleDate(products,false,g.getIsSale()));
} else {
g.setProducts(new ArrayList<>());
}
});
groupList.sort(Comparator.comparingInt(TbProductGroup::getIsSale).reversed());
groupList.add(0, hot);
concurrentMap.put("productInfo", groupList);
}
@@ -162,6 +169,44 @@ public class ProductService {
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) {
TbProduct tbProduct = tbProductMapper.selectById(querySpecDTO.getProductId());
if (tbProduct == null) {
@@ -296,9 +341,28 @@ public class ProductService {
}
}
public List<TbProduct> handleDate(List<TbProduct> products){
/**
* 组装商品
* @param products 商品列表
* @param check 是否校验可售
* @return
*/
public List<TbProduct> handleDate(List<TbProduct> products,boolean check,Integer isSale){
if (!CollectionUtils.isEmpty(products)) {
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;
}
}
}
}else {
it.setIsSale(isSale);
}
TbShopUnit tbShopUnit = unitMapper.selectByPrimaryKey(Integer.valueOf(it.getUnitId()));
it.setUnitSnap(tbShopUnit != null ? tbShopUnit.getName() : "");
//购物车数量

View File

@@ -1,19 +1,19 @@
package com.chaozhanggui.system.cashierservice.service;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.qrcode.QrCodeUtil;
import cn.hutool.extra.qrcode.QrConfig;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.chaozhanggui.system.cashierservice.dao.*;
import com.chaozhanggui.system.cashierservice.entity.*;
import com.chaozhanggui.system.cashierservice.entity.TbReleaseFlow;
import com.chaozhanggui.system.cashierservice.entity.TbShopInfo;
import com.chaozhanggui.system.cashierservice.entity.TbShopUser;
import com.chaozhanggui.system.cashierservice.entity.TbUserInfo;
import com.chaozhanggui.system.cashierservice.entity.vo.IntegralFlowVo;
import com.chaozhanggui.system.cashierservice.entity.vo.IntegralVo;
import com.chaozhanggui.system.cashierservice.entity.vo.OpenMemberVo;
import com.chaozhanggui.system.cashierservice.exception.MsgException;
import com.chaozhanggui.system.cashierservice.redis.RedisCst;
import com.chaozhanggui.system.cashierservice.redis.RedisUtil;
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
import com.chaozhanggui.system.cashierservice.sign.Result;
import com.chaozhanggui.system.cashierservice.util.*;
@@ -23,14 +23,11 @@ import com.github.pagehelper.PageInfo;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
@@ -264,10 +261,35 @@ public class UserService {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Resource resource = resourceLoader.getResource("classpath:/static/logo.jpg");
InputStream inputStream = resource.getInputStream();
QrCodeUtil.generate(wxAccountUtil.getRadarQrCode(Integer.valueOf(shopId), -1), new QrConfig(500, 500).
// String url = wxAccountUtil.getRadarQrCode(Integer.valueOf(shopId), -1);
String url = StrUtil.format("https://invoice.sxczgkj.cn/index/wechat/weuserk?shopId={}", shopId);
QrCodeUtil.generate(url, new QrConfig(500, 500).
setImg(ImageIO.read(inputStream)).setErrorCorrection(ErrorCorrectionLevel.H).setRatio(4), "png", outputStream);
return fileService.uploadFileByInputStream("png", new ByteArrayInputStream(outputStream.toByteArray()));
}
public Result openMember(OpenMemberVo memberVo) {
TbUserInfo userInfo = new TbUserInfo();
userInfo.setId(memberVo.getId());
userInfo.setHeadImg(memberVo.getHeadImg());
userInfo.setNickName(memberVo.getNickName());
userInfo.setTelephone(memberVo.getTelephone());
userInfo.setBirthDay(memberVo.getBirthDay());
userInfoMapper.updateByPrimaryKeySelective(userInfo);
List<TbShopUser> tbShopUsers = shopUserMapper.selectAllByUserId(memberVo.getId().toString());
for (TbShopUser tbShopUser : tbShopUsers) {
tbShopUser.setTelephone(memberVo.getTelephone());
shopUserMapper.updateByPrimaryKey(tbShopUser);
}
TbShopUser tbShopUser = shopUserMapper.selectByUserIdAndShopId(memberVo.getId().toString(), memberVo.getShopId().toString());
tbShopUser.setName(memberVo.getNickName());
tbShopUser.setHeadImg(memberVo.getHeadImg());
tbShopUser.setTelephone(memberVo.getTelephone());
tbShopUser.setBirthDay(memberVo.getBirthDay());
tbShopUser.setIsVip(Byte.parseByte("1"));
shopUserMapper.updateByPrimaryKey(tbShopUser);
return Result.success(CodeEnum.SUCCESS);
}
}