release-发布抽奖联动创建商品,参与抽奖联动创建订单

release-2024-04-25
wangqing 5 days ago
parent 962e33b730
commit edba9a3354

@ -4,5 +4,4 @@ spring:
name: eureka name: eureka
profile: dev profile: dev
label: master label: master
# uri: http://116.62.145.60:12000 uri: http://116.62.145.60:12000
uri: http://127.0.0.1:12000

@ -0,0 +1,73 @@
package com.luoo.user.config;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* @Author: yawei.huang
* @Package: com.luoo.music.config
* @Project: luoo_parent
* @Date: 2024/5/8 9:23
* @Filename: MallConfig
* @Describe:
*/
@Getter
@Setter
@Component
@ConfigurationProperties(prefix = "mall")
public class MallConfig {
// 表pms_product属性
/**
* id
*/
private Long brandId;
/**
*
*/
private String brandName;
/**
* id
*/
private Long productCategoryId;
/**
*
*/
private String productCategoryName;
/**
* id
*/
private Long productAttributeCategoryId;
// 表pms_product_attribute_value属性
/**
* id
*/
private Long artistId;
/**
*
*/
private Long artistName;
/**
* id
*/
private Long albumId;
/**
*
*/
private Long albumName;
/**
* id
*/
private Long songId;
// 其他
/**
* url
*/
private String productUrl;
}

@ -12,4 +12,6 @@ public interface RegionDao extends JpaRepository<Region, Integer>,
List<Region> getRegionsByPidOrderById(Integer parentId); List<Region> getRegionsByPidOrderById(Integer parentId);
// Region findRegionById(Integer id);
} }

@ -5,6 +5,7 @@ import cn.hutool.core.util.ObjectUtil;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.luoo.user.Scheduler.DrawLotteryScheduler; import com.luoo.user.Scheduler.DrawLotteryScheduler;
import com.luoo.user.config.EnvConfig; import com.luoo.user.config.EnvConfig;
import com.luoo.user.config.MallConfig;
import com.luoo.user.dao.*; import com.luoo.user.dao.*;
import com.luoo.user.dto.point.DrawDTO; import com.luoo.user.dto.point.DrawDTO;
import com.luoo.user.dto.point.LotteryParticipatedSearchDto; import com.luoo.user.dto.point.LotteryParticipatedSearchDto;
@ -21,14 +22,14 @@ import constants.Constants;
import constants.ErrorConstants; import constants.ErrorConstants;
import constants.RabbitmqConstants; import constants.RabbitmqConstants;
import constants.TaskPointIdConstants; import constants.TaskPointIdConstants;
import dto.MallProduct;
import dto.MallProductAttributeValue;
import dto.UserLoginDto; import dto.UserLoginDto;
import enums.PointEnums; import enums.*;
import enums.UserBetaEnum;
import enums.UserTypeEnum;
import enums.UserVipStatusEnum;
import exception.BizException; import exception.BizException;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -47,11 +48,9 @@ import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root; import javax.persistence.criteria.Root;
import java.io.IOException; import java.io.IOException;
import java.math.BigDecimal;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.*;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
/** /**
@ -99,6 +98,9 @@ public class LotteryService {
@Autowired @Autowired
private CommentDao commentDao; private CommentDao commentDao;
@Autowired
private MallConfig mallConfig;
public LotteryService(LotteryDao lotteryDao, JwtUtil jwtUtil, IdWorker idWorker, RedisLockUtil redisLockUtil, RegionService regionService, LotteryRegionDao lotteryRegionDao, UserInfoDao userInfoDao, RabbitTemplate rabbitTemplate, LotteryUserDao lotteryUserDao, DrawLotteryScheduler drawLotteryScheduler, JPAQueryFactory jpaQueryFactory, EnvConfig envConfig, UserinfoShippingAddressService userinfoShippingAddressService, UserPointLogService userPointLogService, public LotteryService(LotteryDao lotteryDao, JwtUtil jwtUtil, IdWorker idWorker, RedisLockUtil redisLockUtil, RegionService regionService, LotteryRegionDao lotteryRegionDao, UserInfoDao userInfoDao, RabbitTemplate rabbitTemplate, LotteryUserDao lotteryUserDao, DrawLotteryScheduler drawLotteryScheduler, JPAQueryFactory jpaQueryFactory, EnvConfig envConfig, UserinfoShippingAddressService userinfoShippingAddressService, UserPointLogService userPointLogService,
UserPointLogDao userPointLogDao) { UserPointLogDao userPointLogDao) {
this.lotteryDao = lotteryDao; this.lotteryDao = lotteryDao;
@ -317,6 +319,7 @@ public class LotteryService {
lottery.setStatus(PointEnums.LOTTERY_STATUS_SIGN.getCode()); lottery.setStatus(PointEnums.LOTTERY_STATUS_SIGN.getCode());
lotteryDao.save(lottery); lotteryDao.save(lottery);
shelving(lottery);
String result = drawLotteryScheduler.scheduleDraw(lottery.getApplyEndTime(), id); String result = drawLotteryScheduler.scheduleDraw(lottery.getApplyEndTime(), id);
@ -328,6 +331,40 @@ public class LotteryService {
} }
/**
*
*
* @param lottery
*/
private void shelving(Lottery lottery) {
// 只有待上架允许上架
MallProduct mallProduct = MallProduct.builder()
.brandId(mallConfig.getBrandId())
.brandName(mallConfig.getBrandName())
.productCategoryName(mallConfig.getProductCategoryName())
.productCategoryId(mallConfig.getProductCategoryId())
.productAttributeCategoryId(mallConfig.getProductAttributeCategoryId())
.name(lottery.getTitle())
.pic(lottery.getImage())
.subTitle(lottery.getTitle())
.price(new BigDecimal(lottery.getPoint()))
.build();
List<MallProductAttributeValue> attributeValueList = new ArrayList<>();
attributeValueList.add(MallProductAttributeValue.builder().productAttributeId(mallConfig.getAlbumId()).value(lottery.getId()).build());
attributeValueList.add(MallProductAttributeValue.builder().productAttributeId(mallConfig.getAlbumName()).value(lottery.getTitle()).build());
// attributeValueList.add(MallProductAttributeValue.builder().productAttributeId(mallConfig.getSongId()).value(lottery.getId()).build());
// attributeValueList.add(MallProductAttributeValue.builder().productAttributeId(mallConfig.getArtistId()).value(lottery.getId()).build());
attributeValueList.add(MallProductAttributeValue.builder().productAttributeId(mallConfig.getArtistName()).value(lottery.getTitle()).build());
Map<String, Object> mallMqMap = new HashMap<>();
mallMqMap.put("lotteryId", lottery.getId());
mallMqMap.put("mallProduct", mallProduct);
mallMqMap.put("attributeValueList", attributeValueList);
rabbitTemplate.convertAndSend("luoo_mall_lottery_product_add", mallMqMap);
}
/** /**
* *
* *

@ -2,10 +2,7 @@ package com.luoo.user.service;
import api.PageResult; import api.PageResult;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.luoo.user.dao.LotteryUserDao; import com.luoo.user.dao.*;
import com.luoo.user.dao.TaskPointDao;
import com.luoo.user.dao.UserInfoDao;
import com.luoo.user.dao.UserPointLogDao;
import com.luoo.user.dto.point.DrawDTO; import com.luoo.user.dto.point.DrawDTO;
import com.luoo.user.dto.point.UserPointLogSearchDto; import com.luoo.user.dto.point.UserPointLogSearchDto;
import com.luoo.user.pojo.*; import com.luoo.user.pojo.*;
@ -19,6 +16,8 @@ import com.querydsl.jpa.impl.JPAQueryFactory;
import constants.ErrorConstants; import constants.ErrorConstants;
import constants.RabbitmqConstants; import constants.RabbitmqConstants;
import constants.TaskPointIdConstants; import constants.TaskPointIdConstants;
import dto.MallProduct;
import dto.MallProductAttributeValue;
import dto.UserLoginDto; import dto.UserLoginDto;
import enums.PointEnums; import enums.PointEnums;
import exception.BizException; import exception.BizException;
@ -37,7 +36,9 @@ import java.io.IOException;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* @program: luoo_parent * @program: luoo_parent
@ -67,6 +68,12 @@ public class UserPointLogService {
private final LotteryUserDao lotteryUserDao; private final LotteryUserDao lotteryUserDao;
@Autowired
private UserinfoShippingAddressDao userinfoShippingAddressDao;
@Autowired
private RegionDao regionDao;
public UserPointLogService(UserPointLogDao userPointLogDao, IdWorker idWorker, JwtUtil jwtUtil, public UserPointLogService(UserPointLogDao userPointLogDao, IdWorker idWorker, JwtUtil jwtUtil,
TaskPointDao taskPointDao, RabbitTemplate rabbitTemplate, UserInfoDao userInfoDao, TaskPointDao taskPointDao, RabbitTemplate rabbitTemplate, UserInfoDao userInfoDao,
JPAQueryFactory jpaQueryFactory, LotteryUserDao lotteryUserDao) { JPAQueryFactory jpaQueryFactory, LotteryUserDao lotteryUserDao) {
@ -210,8 +217,47 @@ public class UserPointLogService {
.build(); .build();
lotteryUserDao.save(lotteryUser); lotteryUserDao.save(lotteryUser);
// 发消息创建订单
createOrder(lotteryUser);
}
/**
*
*
* @param lotteryUser
*/
private void createOrder(LotteryUser lotteryUser) {
// 只有待上架允许上架
Map<String, Object> mallMqMap = new HashMap<>();
mallMqMap.put("lotteryId", lotteryUser.getLotteryId());
// mallMqMap.put("mallProduct", mallProduct);
// mallMqMap.put("attributeValueList", attributeValueList);
// userid
mallMqMap.put("userId", lotteryUser.getUserId());
// username
UserInfo userInfo = userInfoDao.findById(lotteryUser.getUserId()).get();
mallMqMap.put("nickName", userInfo.getNickName());
List<UserinfoShippingAddress> byUserIdAndAcquiesce = userinfoShippingAddressDao.findByUserIdAndAcquiesce(lotteryUser.getUserId(), 1);
mallMqMap.put("receiverProvince","");
mallMqMap.put("receiverCity","");
mallMqMap.put("receiverRegion","");
mallMqMap.put("receiverDetailAddress","");
mallMqMap.put("receiverName","");
mallMqMap.put("receiverPhone","");
// 地址
if (null != byUserIdAndAcquiesce) {
mallMqMap.put("receiverProvince",regionDao.findById(byUserIdAndAcquiesce.get(0).getProvinceId()).get().getName());
mallMqMap.put("receiverCity",regionDao.findById(byUserIdAndAcquiesce.get(0).getCityId()).get().getName());
mallMqMap.put("receiverRegion",regionDao.findById(byUserIdAndAcquiesce.get(0).getDistrictId()).get().getName());
mallMqMap.put("receiverDetailAddress",byUserIdAndAcquiesce.get(0).getAddress());
mallMqMap.put("receiverName",byUserIdAndAcquiesce.get(0).getConsignee());
mallMqMap.put("receiverPhone",byUserIdAndAcquiesce.get(0).getPhone());
}
rabbitTemplate.convertAndSend("luoo_mall_lottery_order_add", mallMqMap);
} }
/** /**
* *
* *

@ -57,3 +57,16 @@ wx:
applePay: applePay:
certificate: https://sandbox.itunes.apple.com/verifyReceipt certificate: https://sandbox.itunes.apple.com/verifyReceipt
mall:
brandId: 60
brandName: 雀乐
productCategoryId: 57
productCategoryName: 歌曲
productAttributeCategoryId: 16
artistId: 74
artistName: 75
albumId: 76
albumName: 77
songId: 78
productUrl: http://43.248.137.154:8085/product/luoo/detail/{id}

Loading…
Cancel
Save