diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/dto/TbActivateProductQueryCriteria.java b/eladmin-system/src/main/java/cn/ysk/cashier/dto/TbActivateProductQueryCriteria.java new file mode 100644 index 00000000..b6f4b3a3 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/dto/TbActivateProductQueryCriteria.java @@ -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; +} + diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/Handler/MyMetaObjectHandler.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/Handler/MyMetaObjectHandler.java new file mode 100644 index 00000000..36a34034 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/Handler/MyMetaObjectHandler.java @@ -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()); + + } +} diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/entity/Activate.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/entity/Activate.java index 8252f2fa..214a96ee 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/entity/Activate.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/entity/Activate.java @@ -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 { 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 prodIds; - - public void setProductIds(String productIds) { - this.productIds = productIds; - if(StringUtils.isNotBlank(productIds)){ - prodIds=ListUtil.stringChangeIntegerList(productIds); - } - } - - public void setProdIds(List prodIds) { - this.prodIds = prodIds; - if(!CollectionUtils.isEmpty(prodIds)){ - productIds="["+prodIds.stream() - .map(String::valueOf) - .collect(Collectors.joining(","))+"]"; - } - } + private List products; } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/entity/TbActivateProduct.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/entity/TbActivateProduct.java new file mode 100644 index 00000000..952423a4 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/entity/TbActivateProduct.java @@ -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 { + + 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; + } +} + diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbActivateProductMapper.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbActivateProductMapper.java new file mode 100644 index 00000000..71e3d676 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/mapper/TbActivateProductMapper.java @@ -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 { + +} + diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/rest/StorageController.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/rest/StorageController.java index a9fefcc7..d6d3631e 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/rest/StorageController.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/rest/StorageController.java @@ -48,7 +48,7 @@ public class StorageController { } @PostMapping("/modityActivate") public ResponseEntity 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); diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/ShopService.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/ShopService.java index 93a8462d..a0588b83 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/ShopService.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/ShopService.java @@ -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 findActivatePros(Integer activate); + List findActivatePros(Integer activate); } \ No newline at end of file diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/TbActivateProductService.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/TbActivateProductService.java new file mode 100644 index 00000000..14781817 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/TbActivateProductService.java @@ -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 { + + +} + diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/ShopServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/ShopServiceImpl.java index 485d762c..11477210 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/ShopServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/ShopServiceImpl.java @@ -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 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 collect = new ArrayList<>(); + for (TbActivateProduct product : activate.getProducts()) { + product.setActivateId(activate.getId()); + if (product.getId() != null) collect.add(product.getId()); + } + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("activate_id",activate.getId()); + List actProducts = actProductService.list(queryWrapper); + for (TbActivateProduct actProduct : actProducts) { + if (!collect.contains(actProduct.getId())) { + actProductService.removeById(actProduct.getId()); + } + } + actProductService.saveOrUpdateBatch(activate.getProducts()); + } } @Override - public List findActivatePros(Integer activateId) { - Activate activate = activateMapper.selectById(activateId); - if (!CollectionUtils.isEmpty(activate.getProdIds())){ - return tbProductRepository.findByIds(activate.getProdIds()); + public List findActivatePros(Integer activateId) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("activate_id", activateId); + List actProducts = actProductService.list(queryWrapper); + if (!CollectionUtils.isEmpty(actProducts)) { + Map map = actProducts.stream().collect( + Collectors.toMap( + TbActivateProduct::getProductId, + TbActivateProduct::getNum, + (existing, replacement) -> existing)); + if (!CollectionUtils.isEmpty(map)) { + List products = tbProductRepository.findByIds(new ArrayList<>(map.keySet())); + List 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<>(); } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbActivateProductServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbActivateProductServiceImpl.java new file mode 100644 index 00000000..ec780b6c --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/service/impl/TbActivateProductServiceImpl.java @@ -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 implements TbActivateProductService { + +} + diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/vo/ActivateProsVo.java b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/vo/ActivateProsVo.java new file mode 100644 index 00000000..2292ce20 --- /dev/null +++ b/eladmin-system/src/main/java/cn/ysk/cashier/mybatis/vo/ActivateProsVo.java @@ -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; + } +}