列表优化,拼团添加

master
‘mahaoran’ 2024-11-24 09:43:28 +08:00
parent 7063e0f6c6
commit 1b75139b17
16 changed files with 477 additions and 62 deletions

View File

@ -7,9 +7,18 @@ import javax.validation.constraints.NotNull;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
import java.util.List;
import java.util.function.Supplier;
import ch.qos.logback.core.joran.spi.RuleStore;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.muyu.common.core.web.domain.BaseEntity; import com.muyu.common.core.web.domain.BaseEntity;
import com.muyu.marketing.domain.model.ActivityTeamInfoAddModel;
import com.muyu.marketing.domain.req.ActivityTeamInfoSaveReq;
import com.muyu.marketing.domain.resp.RuleInfo;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
@ -18,6 +27,7 @@ import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder; import lombok.experimental.SuperBuilder;
import org.hibernate.validator.constraints.Length; import org.hibernate.validator.constraints.Length;
import org.springframework.format.annotation.DateTimeFormat;
/** /**
* *
@ -28,13 +38,14 @@ import org.hibernate.validator.constraints.Length;
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@TableName("activity_team_info") @TableName("activity_team_info")
@ApiModel(value = "ProjectInfo", description = "商品拼团信息") @ApiModel(value = "ProjectInfo", description = "拼团活动信息")
public class ActivityTeamInfo extends BaseEntity { public class ActivityTeamInfo extends BaseEntity {
/** /**
* *
*/ */
@TableId(value = "id",type = IdType.AUTO)
@ApiModelProperty("主键") @ApiModelProperty("主键")
private Long id; private Long id;
/** /**
@ -82,6 +93,8 @@ public class ActivityTeamInfo extends BaseEntity {
*/ */
@ApiModelProperty("活动结束时间") @ApiModelProperty("活动结束时间")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
private Date endTime; private Date endTime;
/** /**
* *
@ -116,13 +129,8 @@ public class ActivityTeamInfo extends BaseEntity {
@ApiModelProperty("策略ID") @ApiModelProperty("策略ID")
private Long strategyId; private Long strategyId;
/**
*
*/
@ApiModelProperty("备注")
private String remark;
/** /**
* *
*/ */
@ -149,5 +157,28 @@ public class ActivityTeamInfo extends BaseEntity {
private Date updateTime; private Date updateTime;
/**
*
*/
public static ActivityTeamInfo saveBuildModel(ActivityTeamInfoSaveReq activityTeamInfoAddModel, Supplier<String> createBy){
return ActivityTeamInfo.builder()
.name(activityTeamInfoAddModel.getName())
.productId(activityTeamInfoAddModel.getProductId())
.productImage(activityTeamInfoAddModel.getProductImage())
.introduction(activityTeamInfoAddModel.getIntroduction())
.unit(activityTeamInfoAddModel.getUnit())
.imageList(activityTeamInfoAddModel.getImageList() )
.endTime(activityTeamInfoAddModel.getEndTime())
.sort(activityTeamInfoAddModel.getSort())
.content(activityTeamInfoAddModel.getContent())
.strategyType(activityTeamInfoAddModel.getStrategyType())
.strategyId(activityTeamInfoAddModel.getStrategyId())
.content(activityTeamInfoAddModel.getContent())
.status(activityTeamInfoAddModel.getStatus())
.createBy(createBy.get())
.createTime(new Date())
.build();
}
} }

View File

@ -8,11 +8,19 @@ import java.io.Serializable;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Date; import java.util.Date;
import java.util.function.Supplier;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.muyu.marketing.domain.model.ActivityTeamInfoAddModel;
import com.muyu.marketing.domain.req.ActivityTeamInfoSaveReq;
import com.muyu.marketing.domain.resp.RuleInfo;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import org.hibernate.validator.constraints.Length; import org.hibernate.validator.constraints.Length;
/** /**
@ -22,13 +30,16 @@ import org.hibernate.validator.constraints.Length;
@Data @Data
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
@Builder @SuperBuilder
public class ActivityTeamProductSkuInfo implements Serializable { public class ActivityTeamProductSkuInfo {
/** /**
* *
*/ */
@TableId(value = "id",type = IdType.AUTO)
@ApiModelProperty("主键") @ApiModelProperty("主键")
private Long id; private Long id;
/** /**
@ -103,5 +114,16 @@ public class ActivityTeamProductSkuInfo implements Serializable {
private String remark; private String remark;
// public static ActivityTeamProductSkuInfo saveBuildModelSkuInfo(ActivityTeamInfoSaveReq activityTeamInfoSaveReq, RuleInfo ruleInfo,Supplier<String> createBy){
// return ActivityTeamProductSkuInfo.builder()
// .teamId(activityTeamInfoSaveReq.getId())
// .productSku(ruleInfo.getRuleSku())
// .teamStock(ruleInfo.getTeamStock())
// .teamPrice(ruleInfo.getTeamPrice())
// .productId(activityTeamInfoSaveReq.getProductId())
// .createTime(new Date())
// .createBy(createBy)
// .build();
// }
} }

View File

@ -0,0 +1,65 @@
package com.muyu.marketing.domain;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
import java.util.Date;
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@TableName("team_info")
@ApiModel(value = "TeamInfo", description = "拼团信息表")
public class TeamInfo {
/**
* Id
*/
private Long id;
/**
*
*/
private String name;
/**
*
*/
private String productimage;
/**
*
*/
private BigDecimal productPrice;
/**
*
*/
private BigDecimal teamPrice;
/**
*
*/
private Long openTeamNumber;
/**
*
*/
private Long addTeamBumber;
/**
*
*/
private Long teamStock;
/**
*
*/
private Long remainStock;
/**
*
*/
private Date endTime;
/**
*
*/
private String status;
private Long attendNumber;
}

View File

@ -0,0 +1,74 @@
package com.muyu.marketing.domain.model;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.muyu.common.core.web.domain.BaseEntity;
import com.muyu.marketing.domain.resp.RuleInfo;
import io.swagger.annotations.ApiModel;
import lombok.*;
import lombok.experimental.SuperBuilder;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
import java.util.List;
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "ActivityTeamInfo", description = "拼团活动表")
public class ActivityTeamInfoAddModel extends BaseEntity {
/**
* ID
*/
private Long productId;
/**
*
*/
private String productImage;
/**
*
*/
private String name;
/**
*
*/
private String intro;
/**
*
*/
private String unit;
/**
*
*/
private List<String> introduction;
/**
*
*/
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
private Date endTime;
/**
* ID
*/
private Long strategyId;
/**
*
*/
private String strategyType;
/**
* List
*/
private List<RuleInfo> ruleInfo ;
/**
*
*/
private Integer sort;
/**
*
*/
private String content;
}

View File

@ -8,7 +8,6 @@ import lombok.NoArgsConstructor;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Date; import java.util.Date;
import java.util.function.Consumer;
import java.util.function.Function; import java.util.function.Function;
@Data @Data
@ -70,15 +69,8 @@ public class ActivityTeamInfoListModel {
ActivityTeamInfoListModel builder = ActivityTeamInfoListModel.builder() ActivityTeamInfoListModel builder = ActivityTeamInfoListModel.builder()
.id(activityTeamInfo.getId()) .id(activityTeamInfo.getId())
.name(activityTeamInfo.getName()) .name(activityTeamInfo.getName())
// .addTeamNumber("00")
// .openTeamNumber("00")
// .attendNumber("00")
.endTime(activityTeamInfo.getEndTime()) .endTime(activityTeamInfo.getEndTime())
.productImage(activityTeamInfo.getProductImage()) .productImage(activityTeamInfo.getProductImage())
// .teamPrice("0")
// .productPrice("0")
// .remainStock("0")
// .teamStock("0")
.status(activityTeamInfo.getStatus()) .status(activityTeamInfo.getStatus())
.build(); .build();
return function.apply( return function.apply(

View File

@ -27,13 +27,13 @@ public class TeamProductDiscountPriceModel {
private Double disCount; private Double disCount;
public static TeamProductStockModel of(BigDecimal productPrice,BigDecimal teamPrice){ public static TeamProductDiscountPriceModel of(BigDecimal productPrice,BigDecimal teamPrice){
TeamProductDiscountPriceModel.builder() return TeamProductDiscountPriceModel.builder()
.productPrice(productPrice) .productPrice(productPrice)
.teamPrice(teamPrice) .teamPrice(teamPrice)
.disCount(productPrice.subtract(teamPrice).divide(productPrice,2, RoundingMode.HALF_UP).doubleValue()) .disCount(productPrice.subtract(teamPrice).divide(productPrice,2, RoundingMode.HALF_UP).doubleValue())
.build(); .build();
return of(productPrice, teamPrice);
} }
} }

View File

@ -12,5 +12,6 @@ import lombok.NoArgsConstructor;
public class TeamProductStockModel { public class TeamProductStockModel {
private Long teamStock; private Long teamStock;
private Long remainStock; private Long remainStock;
private Double discount;
} }

View File

@ -0,0 +1,88 @@
package com.muyu.marketing.domain.req;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.muyu.marketing.domain.resp.RuleInfo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
import java.util.List;
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@ApiModel(value = "AttributeInfo", description = "商品属性")
public class ActivityTeamInfoSaveReq {
@TableId(value = "id",type = IdType.AUTO)
@ApiModelProperty("主键")
private Long id;
/**
* ID
*/
private Long productId;
/**
*
*/
private String productImage;
/**
*
*/
private String name;
/**
*
*/
private String introduction;
/**
*
*/
private String unit;
/**
*
*/
private String imageList;
/**
*
*/
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
private Date endTime;
/**
* ID
*/
private Long strategyId;
/**
*
*/
private String strategyType;
/**
* List
*/
private List<RuleInfo> ruleInfo ;
/**
*
*/
private Integer sort;
/**
*
*/
private String content;
private String status;
}

View File

@ -0,0 +1,41 @@
package com.muyu.marketing.domain.resp;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
@Data
@NoArgsConstructor
@AllArgsConstructor
@TableName(value = "activity_team_product_sku_info")
public class RuleInfo {
/**
*
*/
@TableId(value = "id",type = IdType.AUTO)
@ApiModelProperty("主键")
private Long id;
/**
*Sku
*/
private String sku;
/**
*
*/
private Long stock;
/**
*
*/
private BigDecimal price;
}

View File

@ -1,6 +1,7 @@
package com.muyu.marketing.domain.resp; package com.muyu.marketing.domain.resp;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.muyu.marketing.domain.ActivityTeamInfo; import com.muyu.marketing.domain.ActivityTeamInfo;
import com.muyu.marketing.domain.model.ActivityTeamInfoListModel; import com.muyu.marketing.domain.model.ActivityTeamInfoListModel;
import com.muyu.marketing.domain.model.ActivityTeamInfoListQueryModel; import com.muyu.marketing.domain.model.ActivityTeamInfoListQueryModel;
@ -8,6 +9,7 @@ import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Date; import java.util.Date;
@ -57,14 +59,18 @@ public class TeamInfoListResp {
/** /**
* *
*/ */
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
private Date endTime; private Date endTime;
/** /**
* *
*/ */
private String status; private String status;
private Long attendNumber; private Long attendNumber;
public static TeamInfoListResp listModelBuild(ActivityTeamInfoListModel activityTeamInfoListModel){ public static TeamInfoListResp listModelBuild(ActivityTeamInfoListModel activityTeamInfoListModel){
return TeamInfoListResp.builder() return TeamInfoListResp.builder()
.id(activityTeamInfoListModel.getId()) .id(activityTeamInfoListModel.getId())

View File

@ -3,10 +3,11 @@ package com.muyu.marketing.controller;
import com.muyu.common.core.domain.Result; import com.muyu.common.core.domain.Result;
import com.muyu.common.core.web.page.TableDataInfo; import com.muyu.common.core.web.page.TableDataInfo;
import com.muyu.marketing.domain.model.ActivityTeamInfoListModel; import com.muyu.marketing.domain.model.ActivityTeamInfoListModel;
import com.muyu.marketing.domain.model.ActivityTeamInfoListQueryModel;
import com.muyu.marketing.domain.req.TeamInfoReqListReq; import com.muyu.marketing.domain.req.TeamInfoReqListReq;
import com.muyu.marketing.domain.req.ActivityTeamInfoSaveReq;
import com.muyu.marketing.domain.resp.TeamInfoListResp; import com.muyu.marketing.domain.resp.TeamInfoListResp;
import com.muyu.marketing.service.ActivityTeamInfoService; import com.muyu.marketing.service.ActivityTeamInfoService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
@ -14,12 +15,17 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.List; import java.util.List;
@Api(tags = "商品拼团信息")
@RestController @RestController
@RequestMapping("/team") @RequestMapping("/team")
public class ActivityTeamController { public class ActivityTeamController {
@Autowired @Autowired
private ActivityTeamInfoService activityTeamInfoService; private ActivityTeamInfoService activityTeamInfoService;
/**
*
* @param teamInfoReqListReq
* @return
*/
@PostMapping("list") @PostMapping("list")
public Result<TableDataInfo<TeamInfoListResp>> list(@RequestBody TeamInfoReqListReq teamInfoReqListReq){ public Result<TableDataInfo<TeamInfoListResp>> list(@RequestBody TeamInfoReqListReq teamInfoReqListReq){
TableDataInfo<ActivityTeamInfoListModel> tableDataInfo = activityTeamInfoService.query(teamInfoReqListReq.buildQueryModel()); TableDataInfo<ActivityTeamInfoListModel> tableDataInfo = activityTeamInfoService.query(teamInfoReqListReq.buildQueryModel());
@ -32,4 +38,15 @@ public class ActivityTeamController {
); );
} }
/**
*
* @param teamInfoSaveReq
* @return
*/
@PostMapping("add")
public Result add(@RequestBody ActivityTeamInfoSaveReq teamInfoSaveReq){
Result addActivityTeamInfo = activityTeamInfoService.add(teamInfoSaveReq);
return addActivityTeamInfo;
}
} }

View File

@ -1,19 +1,29 @@
package com.muyu.marketing.service; package com.muyu.marketing.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.web.page.TableDataInfo; import com.muyu.common.core.web.page.TableDataInfo;
import com.muyu.marketing.domain.ActivityTeamInfo; import com.muyu.marketing.domain.ActivityTeamInfo;
import com.muyu.marketing.domain.model.ActivityTeamInfoListModel; import com.muyu.marketing.domain.model.ActivityTeamInfoListModel;
import com.muyu.marketing.domain.model.ActivityTeamInfoListQueryModel; import com.muyu.marketing.domain.model.ActivityTeamInfoListQueryModel;
import com.muyu.marketing.domain.req.ActivityTeamInfoSaveReq;
import java.util.List; import java.util.List;
public interface ActivityTeamInfoService extends IService<ActivityTeamInfo> { public interface ActivityTeamInfoService extends IService<ActivityTeamInfo> {
/** /**
* *
* @param activityTeamInfoListQueryModel * @param activityTeamInfoListQueryModel
* @return * @return
*/ */
public TableDataInfo<ActivityTeamInfoListModel> query(ActivityTeamInfoListQueryModel activityTeamInfoListQueryModel); public TableDataInfo<ActivityTeamInfoListModel> query(ActivityTeamInfoListQueryModel activityTeamInfoListQueryModel);
/**
*
* @param teamInfoSaveReq
* @return
*/
Result add(ActivityTeamInfoSaveReq teamInfoSaveReq);
} }

View File

@ -18,5 +18,6 @@ public interface ActivityTeamProductSkuInfoService extends IService<ActivityTeam
} }
public TeamProductDiscountPriceModel getDiscountPrice(Long teamId); public TeamProductDiscountPriceModel getDiscountPrice(Long teamId);
public TeamProductStockModel getStock(Long teamId); public TeamProductStockModel getStock(Long teamId);
} }

View File

@ -1,30 +1,30 @@
package com.muyu.marketing.service.impl; package com.muyu.marketing.service.impl;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.StringUtils; import com.muyu.common.core.utils.StringUtils;
import com.muyu.common.core.web.page.TableDataInfo; import com.muyu.common.core.web.page.TableDataInfo;
import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.marketing.domain.ActivityTeamInfo; import com.muyu.marketing.domain.ActivityTeamInfo;
import com.muyu.marketing.domain.model.ActivityTeamInfoListModel; import com.muyu.marketing.domain.ActivityTeamProductSkuInfo;
import com.muyu.marketing.domain.model.ActivityTeamInfoListQueryModel; import com.muyu.marketing.domain.model.*;
import com.muyu.marketing.domain.model.TeamProductDiscountPriceModel; import com.muyu.marketing.domain.req.ActivityTeamInfoSaveReq;
import com.muyu.marketing.domain.model.TeamProductStockModel; import com.muyu.marketing.domain.resp.RuleInfo;
import com.muyu.marketing.mapper.ActivityInfoMapper;
import com.muyu.marketing.mapper.ActivityTeamInfoMapper; import com.muyu.marketing.mapper.ActivityTeamInfoMapper;
import com.muyu.marketing.service.ActivityOpenInfoService; import com.muyu.marketing.service.ActivityOpenInfoService;
import com.muyu.marketing.service.ActivityTeamInfoService; import com.muyu.marketing.service.ActivityTeamInfoService;
import com.muyu.marketing.service.ActivityTeamProductSkuInfoService; import com.muyu.marketing.service.ActivityTeamProductSkuInfoService;
import com.muyu.product.domain.ProjectInfo;
import com.muyu.product.domain.model.ProjectAddModel;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList; import java.math.BigDecimal;
import java.util.Arrays; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.stream.Stream;
@Service @Service
public class ActivityTeamInfoServiceImpl extends ServiceImpl<ActivityTeamInfoMapper,ActivityTeamInfo> implements ActivityTeamInfoService { public class ActivityTeamInfoServiceImpl extends ServiceImpl<ActivityTeamInfoMapper,ActivityTeamInfo> implements ActivityTeamInfoService {
@ -35,6 +35,11 @@ public class ActivityTeamInfoServiceImpl extends ServiceImpl<ActivityTeamInfoMap
@Autowired @Autowired
private ActivityOpenInfoService activityOpenInfoService; private ActivityOpenInfoService activityOpenInfoService;
/**
*
* @param activityTeamInfoListQueryModel
* @return
*/
@Override @Override
public TableDataInfo<ActivityTeamInfoListModel> query (ActivityTeamInfoListQueryModel activityTeamInfoListQueryModel) { public TableDataInfo<ActivityTeamInfoListModel> query (ActivityTeamInfoListQueryModel activityTeamInfoListQueryModel) {
LambdaQueryWrapper<ActivityTeamInfo> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<ActivityTeamInfo> queryWrapper = new LambdaQueryWrapper<>();
@ -47,15 +52,15 @@ public class ActivityTeamInfoServiceImpl extends ServiceImpl<ActivityTeamInfoMap
(activityTeamInfoListModelBuilder) -> { (activityTeamInfoListModelBuilder) -> {
Long openNumberByTeamIdAndType = activityOpenInfoService.getTeamOpenNumberByTeamIdAndType(activityTeamInfo.getId()); Long openNumberByTeamIdAndType = activityOpenInfoService.getTeamOpenNumberByTeamIdAndType(activityTeamInfo.getId());
Long inNumberByTeamIdAndType = activityOpenInfoService.getTeamInNumberByTeamIdAndType(activityTeamInfo.getId()); Long inNumberByTeamIdAndType = activityOpenInfoService.getTeamInNumberByTeamIdAndType(activityTeamInfo.getId());
TeamProductDiscountPriceModel discountPrice = activityTeamProductSkuInfoService.getDiscountPrice(activityTeamInfo.getId()); // TeamProductDiscountPriceModel discountPrice = activityTeamProductSkuInfoService.getDiscountPrice(activityTeamInfo.getId());
TeamProductStockModel teamProductStockModel = activityTeamProductSkuInfoService.getStock(activityTeamInfo.getId()); TeamProductStockModel teamProductStockModel = activityTeamProductSkuInfoService.getStock(activityTeamInfo.getId());
return activityTeamInfoListModelBuilder return activityTeamInfoListModelBuilder
.openTeamNumber(openNumberByTeamIdAndType) .openTeamNumber(openNumberByTeamIdAndType)
.addTeamNumber(inNumberByTeamIdAndType) .addTeamNumber(inNumberByTeamIdAndType)
.attendNumber(openNumberByTeamIdAndType + inNumberByTeamIdAndType) .attendNumber(openNumberByTeamIdAndType + inNumberByTeamIdAndType)
.teamPrice(discountPrice.getTeamPrice()) .teamPrice(BigDecimal.valueOf(1))
.productPrice(discountPrice.getProductPrice()) .productPrice(BigDecimal.valueOf(1))
.teamStock(teamProductStockModel.getTeamStock()) .teamStock(teamProductStockModel.getTeamStock())
.remainStock(teamProductStockModel.getRemainStock()) .remainStock(teamProductStockModel.getRemainStock())
.build(); .build();
@ -68,4 +73,30 @@ public class ActivityTeamInfoServiceImpl extends ServiceImpl<ActivityTeamInfoMap
return tableDataInfo; return tableDataInfo;
} }
/**
*
* @param teamInfoSaveReq
* @return
*/
@Transactional
@Override
public Result add(ActivityTeamInfoSaveReq teamInfoSaveReq) {
ActivityTeamInfo activityTeamInfo = ActivityTeamInfo.saveBuildModel(teamInfoSaveReq, SecurityUtils::getUsername);
this.save(activityTeamInfo);
List<RuleInfo> ruleInfoList = teamInfoSaveReq.getRuleInfo();
List<ActivityTeamProductSkuInfo> activityTeamProductSkuInfos = ruleInfoList.stream().map(ruleInfo -> {
ActivityTeamProductSkuInfo productSkuInfo = ActivityTeamProductSkuInfo.builder()
.teamId(activityTeamInfo.getId())
.productSku(ruleInfo.getSku())
.teamStock(ruleInfo.getStock())
.teamPrice(ruleInfo.getPrice())
.productId(teamInfoSaveReq.getProductId())
.createTime(new Date())
.build();
return productSkuInfo;
}).toList();
activityTeamProductSkuInfoService.saveBatch(activityTeamProductSkuInfos);
return Result.success(0,"添加成功");
}
} }

View File

@ -2,22 +2,23 @@ package com.muyu.marketing.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.common.core.exception.ServiceException;
import com.muyu.marketing.domain.ActivityTeamProductSkuInfo; import com.muyu.marketing.domain.ActivityTeamProductSkuInfo;
import com.muyu.marketing.domain.model.TeamProductDiscountPriceModel; import com.muyu.marketing.domain.model.TeamProductDiscountPriceModel;
import com.muyu.marketing.domain.model.TeamProductStockModel; import com.muyu.marketing.domain.model.TeamProductStockModel;
import com.muyu.marketing.mapper.ActivityTeamOpenInfoMapper;
import com.muyu.marketing.mapper.ActivityTeamProductSkuInfoMapper; import com.muyu.marketing.mapper.ActivityTeamProductSkuInfoMapper;
import com.muyu.marketing.service.ActivityTeamProductSkuInfoService; import com.muyu.marketing.service.ActivityTeamProductSkuInfoService;
import com.muyu.product.cache.ProjectSkuCache; import com.muyu.product.cache.ProjectSkuCache;
import com.muyu.product.cache.datasource.ProjectSkuData;
import com.muyu.product.domain.ProjectSkuInfo; import com.muyu.product.domain.ProjectSkuInfo;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional;
@Service @Service
public class ActivityTeamProductSkuInfoServiceImpl extends ServiceImpl<ActivityTeamProductSkuInfoMapper,ActivityTeamProductSkuInfo> implements ActivityTeamProductSkuInfoService { public class ActivityTeamProductSkuInfoServiceImpl extends ServiceImpl<ActivityTeamProductSkuInfoMapper,ActivityTeamProductSkuInfo> implements ActivityTeamProductSkuInfoService {
@ -26,30 +27,44 @@ public class ActivityTeamProductSkuInfoServiceImpl extends ServiceImpl<ActivityT
@Override @Override
public TeamProductDiscountPriceModel getDiscountPrice(Long teamId) { public TeamProductDiscountPriceModel getDiscountPrice(Long teamId) {
LambdaQueryWrapper<ActivityTeamProductSkuInfo> queryWrapper = new LambdaQueryWrapper<>(); List<ActivityTeamProductSkuInfo> teamProductSkuInfoList = this.getActivityTeamProductSkuInfoByTeamId(teamId);
queryWrapper.eq(ActivityTeamProductSkuInfo::getTeamId,teamId); //用stream把teamProductSkuInfoList集合里的数据转换给teamProductDiscountPriceModelArrayList
List<ActivityTeamProductSkuInfo> productSkuInfos = this.list(queryWrapper); Optional<TeamProductDiscountPriceModel> min = teamProductSkuInfoList.stream()
ArrayList<TeamProductDiscountPriceModel> teamProductDiscountPriceModels = new ArrayList<>(); .map(activityTeamProductSkuInfo -> {
for (ActivityTeamProductSkuInfo productSkuInfo : productSkuInfos) { ProjectSkuInfo projectSkuInfo = projectSkuCache.getData(Long.valueOf(activityTeamProductSkuInfo.getProductId()),activityTeamProductSkuInfo.getProductSku());
ProjectSkuInfo skuInfo = projectSkuCache.get(productSkuInfo.getProductId(), productSkuInfo.getProductSku()); return TeamProductDiscountPriceModel.of(projectSkuInfo.getPrice(), activityTeamProductSkuInfo.getTeamPrice());
BigDecimal price = skuInfo.getPrice(); }).min((o1, o2) -> Double.valueOf(o1.getDisCount() * 100 - o2.getDisCount() * 100).intValue());
BigDecimal teamPrice = productSkuInfo.getTeamPrice();
TeamProductDiscountPriceModel priceModel = new TeamProductDiscountPriceModel();
priceModel.setProductPrice(price);
priceModel.setTeamPrice(teamPrice);
priceModel.setDisCount(price.subtract(teamPrice).divide(price,2, RoundingMode.HALF_UP).doubleValue());
teamProductDiscountPriceModels.add(priceModel); if(min.isEmpty()){
throw new ServiceException("团购活动下没有商品了");
} }
TeamProductDiscountPriceModel teamProductDiscountPriceModel = teamProductDiscountPriceModels.get(0); return min.get();
for (TeamProductDiscountPriceModel productDiscountPriceModel : teamProductDiscountPriceModels) {
if(teamProductDiscountPriceModel.getDisCount() < productDiscountPriceModel.getDisCount()){
teamProductDiscountPriceModel = productDiscountPriceModel;
}
}
return teamProductDiscountPriceModel;
}
// LambdaQueryWrapper<ActivityTeamProductSkuInfo> queryWrapper = new LambdaQueryWrapper<>();
// queryWrapper.eq(ActivityTeamProductSkuInfo::getTeamId,teamId);
// List<ActivityTeamProductSkuInfo> productSkuInfos = this.list(queryWrapper);
// ArrayList<TeamProductDiscountPriceModel> teamProductDiscountPriceModels = new ArrayList<>();
// for (ActivityTeamProductSkuInfo productSkuInfo : productSkuInfos) {
// ProjectSkuInfo skuInfo = projectSkuCache.getData(productSkuInfo.getProductId(), productSkuInfo.getProductSku());
// BigDecimal price = skuInfo.getPrice();
// BigDecimal teamPrice = productSkuInfo.getTeamPrice();
// TeamProductDiscountPriceModel priceModel = new TeamProductDiscountPriceModel();
// priceModel.setProductPrice(price);
// priceModel.setTeamPrice(teamPrice);
// priceModel.setDisCount(price.subtract(teamPrice).divide(price,2, RoundingMode.HALF_UP).doubleValue());
//
// teamProductDiscountPriceModels.add(priceModel);
// }
// TeamProductDiscountPriceModel teamProductDiscountPriceModel = teamProductDiscountPriceModels.get(0);
// for (TeamProductDiscountPriceModel productDiscountPriceModel : teamProductDiscountPriceModels) {
// if(teamProductDiscountPriceModel.getDisCount() > productDiscountPriceModel.getDisCount()){
// teamProductDiscountPriceModel = productDiscountPriceModel;
// }
// }
// return teamProductDiscountPriceModel;
}
@Override @Override
public TeamProductStockModel getStock(Long teamId) { public TeamProductStockModel getStock(Long teamId) {

View File

@ -0,0 +1,21 @@
{
"商品id":"Long",
"商品图片":"String",
"拼团活动名称":"String",
"拼团活动简介":"String",
"商品单位":"String",
"商品轮播图":List<String>,
"活动时间":"Date",
"拼团时效":"Integer",
"拼团人数":"Integer",
"购买总量限制":"Integer",
"单词总量限制":"Integer",
"补齐人数":"Integer",
"商品规格id":[
"商品Sku":"属性名称"
],
"排序":"Integer",
"详情":"Text"
}