会员活动赠送商品
This commit is contained in:
parent
1de1edb537
commit
1cb0d9c80f
|
|
@ -0,0 +1,30 @@
|
|||
package cn.ysk.cashier.dto;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 活动赠送商品表(TbActivateProduct)表查询类
|
||||
*
|
||||
* @author ww
|
||||
* @since 2024-08-20 11:27:40
|
||||
*/
|
||||
@Data
|
||||
public class TbActivateProductQueryCriteria {
|
||||
|
||||
private Integer id;
|
||||
//活动Id
|
||||
private Integer activateId;
|
||||
//商品id
|
||||
private Integer productId;
|
||||
//数量
|
||||
private Integer num;
|
||||
|
||||
private Date createTime;
|
||||
|
||||
private Date updateTime;
|
||||
private long page;
|
||||
private long size;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
package cn.ysk.cashier.mybatis.Handler;
|
||||
|
||||
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
||||
import org.apache.ibatis.reflection.MetaObject;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Component
|
||||
public class MyMetaObjectHandler implements MetaObjectHandler {
|
||||
|
||||
@Override
|
||||
public void insertFill(MetaObject metaObject) {
|
||||
this.strictInsertFill(metaObject, "createTime", Date.class, new Date());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateFill(MetaObject metaObject) {
|
||||
this.strictUpdateFill(metaObject, "updateTime", Date.class, new Date());
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
package cn.ysk.cashier.mybatis.entity;
|
||||
|
||||
import cn.ysk.cashier.utils.ListUtil;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
|
|
@ -8,12 +7,9 @@ import com.baomidou.mybatisplus.annotation.TableName;
|
|||
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
|
|
@ -28,26 +24,8 @@ public class Activate extends Model<Activate> {
|
|||
private BigDecimal handselNum;
|
||||
private String handselType;
|
||||
private String isDel;
|
||||
private String isUser;
|
||||
//是否赠送商品 0否 1是
|
||||
private Integer isGiftPro;
|
||||
private String productIds;
|
||||
@TableField(exist = false)
|
||||
private List<Integer> prodIds;
|
||||
|
||||
public void setProductIds(String productIds) {
|
||||
this.productIds = productIds;
|
||||
if(StringUtils.isNotBlank(productIds)){
|
||||
prodIds=ListUtil.stringChangeIntegerList(productIds);
|
||||
}
|
||||
}
|
||||
|
||||
public void setProdIds(List<Integer> prodIds) {
|
||||
this.prodIds = prodIds;
|
||||
if(!CollectionUtils.isEmpty(prodIds)){
|
||||
productIds="["+prodIds.stream()
|
||||
.map(String::valueOf)
|
||||
.collect(Collectors.joining(","))+"]";
|
||||
}
|
||||
}
|
||||
private List<TbActivateProduct> products;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,83 @@
|
|||
package cn.ysk.cashier.mybatis.entity;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 活动赠送商品表(TbActivateProduct)表实体类
|
||||
*
|
||||
* @author ww
|
||||
* @since 2024-08-20 11:27:40
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class TbActivateProduct extends Model<TbActivateProduct> {
|
||||
|
||||
private Integer id;
|
||||
//活动Id
|
||||
private Integer activateId;
|
||||
//商品id
|
||||
private Integer productId;
|
||||
//数量
|
||||
private Integer num;
|
||||
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private Date createTime;
|
||||
|
||||
@TableField(fill = FieldFill.UPDATE)
|
||||
private Date updateTime;
|
||||
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Integer getActivateId() {
|
||||
return activateId;
|
||||
}
|
||||
|
||||
public void setActivateId(Integer activateId) {
|
||||
this.activateId = activateId;
|
||||
}
|
||||
|
||||
public Integer getProductId() {
|
||||
return productId;
|
||||
}
|
||||
|
||||
public void setProductId(Integer productId) {
|
||||
this.productId = productId;
|
||||
}
|
||||
|
||||
public Integer getNum() {
|
||||
return num;
|
||||
}
|
||||
|
||||
public void setNum(Integer num) {
|
||||
this.num = num;
|
||||
}
|
||||
|
||||
public Date getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(Date createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
public Date getUpdateTime() {
|
||||
return updateTime;
|
||||
}
|
||||
|
||||
public void setUpdateTime(Date updateTime) {
|
||||
this.updateTime = updateTime;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package cn.ysk.cashier.mybatis.mapper;
|
||||
|
||||
import cn.ysk.cashier.mybatis.entity.TbActivateProduct;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* 活动赠送商品表(TbActivateProduct)表数据库访问层
|
||||
*
|
||||
* @author ww
|
||||
* @since 2024-08-20 11:27:40
|
||||
*/
|
||||
public interface TbActivateProductMapper extends BaseMapper<TbActivateProduct> {
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -48,7 +48,7 @@ public class StorageController {
|
|||
}
|
||||
@PostMapping("/modityActivate")
|
||||
public ResponseEntity<Object> modityActivate(@RequestBody Activate activate){
|
||||
if (activate.getIsGiftPro() != null && activate.getIsGiftPro() == 1 && CollectionUtils.isEmpty(activate.getProdIds()))
|
||||
if (activate.getIsGiftPro() != null && activate.getIsGiftPro() == 1 && CollectionUtils.isEmpty(activate.getProducts()))
|
||||
throw new BadRequestException("赠送商品不可为空");
|
||||
String userName = SecurityUtils.getCurrentUsername();
|
||||
shopService.modityActivate(activate);
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package cn.ysk.cashier.mybatis.service;
|
|||
|
||||
import cn.ysk.cashier.mybatis.entity.Activate;
|
||||
import cn.ysk.cashier.mybatis.entity.StorageVo;
|
||||
import cn.ysk.cashier.mybatis.vo.ActivateProsVo;
|
||||
import cn.ysk.cashier.pojo.product.TbProduct;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
|
|
@ -25,5 +26,5 @@ public interface ShopService {
|
|||
|
||||
void modityActivate(Activate activate);
|
||||
|
||||
List<TbProduct> findActivatePros(Integer activate);
|
||||
List<ActivateProsVo> findActivatePros(Integer activate);
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
package cn.ysk.cashier.mybatis.service;
|
||||
|
||||
import cn.ysk.cashier.mybatis.entity.TbActivateProduct;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
|
||||
/**
|
||||
* 活动赠送商品表(TbActivateProduct)表服务接口
|
||||
*
|
||||
* @author ww
|
||||
* @since 2024-08-20 11:27:40
|
||||
*/
|
||||
public interface TbActivateProductService extends IService<TbActivateProduct> {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -1,8 +1,12 @@
|
|||
package cn.ysk.cashier.mybatis.service.impl;
|
||||
|
||||
import cn.ysk.cashier.mybatis.entity.Activate;
|
||||
import cn.ysk.cashier.mybatis.entity.TbActivateProduct;
|
||||
import cn.ysk.cashier.mybatis.mapper.*;
|
||||
import cn.ysk.cashier.mybatis.service.TbActivateProductService;
|
||||
import cn.ysk.cashier.mybatis.vo.ActivateProsVo;
|
||||
import cn.ysk.cashier.pojo.product.TbProduct;
|
||||
import cn.ysk.cashier.pojo.product.TbProductSku;
|
||||
import cn.ysk.cashier.pojo.shop.TbMerchantAccount;
|
||||
import cn.ysk.cashier.repository.product.TbProductRepository;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
|
|
@ -19,7 +23,9 @@ import org.springframework.data.domain.Pageable;
|
|||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author admin
|
||||
|
|
@ -40,6 +46,8 @@ public class ShopServiceImpl implements ShopService {
|
|||
private ActivateMapper activateMapper;
|
||||
@Autowired
|
||||
private TbProductRepository tbProductRepository;
|
||||
@Resource
|
||||
private TbActivateProductService actProductService;
|
||||
@Override
|
||||
public Object findStorage(Integer shopId, String account, Pageable pageable) {
|
||||
QueryWrapper<TbUserStorage> queryWrapper = new QueryWrapper<>();
|
||||
|
|
@ -128,13 +136,45 @@ public class ShopServiceImpl implements ShopService {
|
|||
activate.setMaxNum(activate.getMinNum());
|
||||
activateMapper.insert(activate);
|
||||
}
|
||||
if(!CollectionUtils.isEmpty(activate.getProducts())){
|
||||
List<Integer> collect = new ArrayList<>();
|
||||
for (TbActivateProduct product : activate.getProducts()) {
|
||||
product.setActivateId(activate.getId());
|
||||
if (product.getId() != null) collect.add(product.getId());
|
||||
}
|
||||
QueryWrapper<TbActivateProduct> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("activate_id",activate.getId());
|
||||
List<TbActivateProduct> actProducts = actProductService.list(queryWrapper);
|
||||
for (TbActivateProduct actProduct : actProducts) {
|
||||
if (!collect.contains(actProduct.getId())) {
|
||||
actProductService.removeById(actProduct.getId());
|
||||
}
|
||||
}
|
||||
actProductService.saveOrUpdateBatch(activate.getProducts());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TbProduct> findActivatePros(Integer activateId) {
|
||||
Activate activate = activateMapper.selectById(activateId);
|
||||
if (!CollectionUtils.isEmpty(activate.getProdIds())){
|
||||
return tbProductRepository.findByIds(activate.getProdIds());
|
||||
public List<ActivateProsVo> findActivatePros(Integer activateId) {
|
||||
QueryWrapper<TbActivateProduct> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("activate_id", activateId);
|
||||
List<TbActivateProduct> actProducts = actProductService.list(queryWrapper);
|
||||
if (!CollectionUtils.isEmpty(actProducts)) {
|
||||
Map<Integer, Integer> map = actProducts.stream().collect(
|
||||
Collectors.toMap(
|
||||
TbActivateProduct::getProductId,
|
||||
TbActivateProduct::getNum,
|
||||
(existing, replacement) -> existing));
|
||||
if (!CollectionUtils.isEmpty(map)) {
|
||||
List<TbProduct> products = tbProductRepository.findByIds(new ArrayList<>(map.keySet()));
|
||||
List<ActivateProsVo> results= new ArrayList<>();
|
||||
for (TbProduct product : products) {
|
||||
ActivateProsVo pro =new ActivateProsVo(product.getId(),product.getName(),product.getCoverImg());
|
||||
pro.setNum(map.get(pro.getId()));
|
||||
results.add(pro);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
package cn.ysk.cashier.mybatis.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import cn.ysk.cashier.mybatis.mapper.TbActivateProductMapper;
|
||||
import cn.ysk.cashier.mybatis.entity.TbActivateProduct;
|
||||
import cn.ysk.cashier.mybatis.service.TbActivateProductService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import cn.ysk.cashier.dto.TbActivateProductQueryCriteria;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import cn.ysk.cashier.utils.PageUtil;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 活动赠送商品表(TbActivateProduct)表服务实现类
|
||||
*
|
||||
* @author ww
|
||||
* @since 2024-08-20 11:27:40
|
||||
*/
|
||||
@Service("tbActivateProductService")
|
||||
public class TbActivateProductServiceImpl extends ServiceImpl<TbActivateProductMapper, TbActivateProduct> implements TbActivateProductService {
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
package cn.ysk.cashier.mybatis.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ActivateProsVo {
|
||||
private Integer id;
|
||||
private String name;
|
||||
private String coverImg;
|
||||
private Integer num;
|
||||
|
||||
public ActivateProsVo(Integer id, String name, String coverImg) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.coverImg = coverImg;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue