|
|
@@ -0,0 +1,180 @@
|
|
|
+package org.dromara.product.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import org.dromara.common.core.exception.ServiceException;
|
|
|
+import org.dromara.common.core.utils.MapstructUtils;
|
|
|
+import org.dromara.common.core.utils.StringUtils;
|
|
|
+import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
+import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.dromara.easyes.core.conditions.update.LambdaEsUpdateWrapper;
|
|
|
+import org.dromara.product.domain.ProductBase;
|
|
|
+import org.dromara.product.domain.ProductExquisite;
|
|
|
+import org.dromara.product.domain.vo.ProductBaseVo;
|
|
|
+import org.dromara.product.esmapper.ProductEsMapper;
|
|
|
+import org.dromara.product.mapper.ProductBaseMapper;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.dromara.product.domain.bo.ProductSelfBo;
|
|
|
+import org.dromara.product.domain.vo.ProductSelfVo;
|
|
|
+import org.dromara.product.domain.ProductSelf;
|
|
|
+import org.dromara.product.mapper.ProductSelfMapper;
|
|
|
+import org.dromara.product.service.IProductSelfService;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Collection;
|
|
|
+import java.util.Objects;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 自营商品池Service业务层处理
|
|
|
+ *
|
|
|
+ * @author LionLi
|
|
|
+ * @date 2026-03-23
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@RequiredArgsConstructor
|
|
|
+@Service
|
|
|
+public class ProductSelfServiceImpl extends ServiceImpl<ProductSelfMapper, ProductSelf> implements IProductSelfService {
|
|
|
+
|
|
|
+ private final ProductSelfMapper baseMapper;
|
|
|
+
|
|
|
+ private final ProductBaseMapper productBaseMapper;
|
|
|
+
|
|
|
+ private final ProductEsMapper productEsMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询自营商品池
|
|
|
+ *
|
|
|
+ * @param productId 主键
|
|
|
+ * @return 自营商品池
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ProductSelfVo queryById(Long productId){
|
|
|
+ return baseMapper.selectVoById(productId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页查询自营商品池列表
|
|
|
+ *
|
|
|
+ * @param bo 查询条件
|
|
|
+ * @param pageQuery 分页参数
|
|
|
+ * @return 自营商品池分页列表
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public TableDataInfo<ProductSelfVo> queryPageList(ProductSelfBo bo, PageQuery pageQuery) {
|
|
|
+ LambdaQueryWrapper<ProductSelf> lqw = buildQueryWrapper(bo);
|
|
|
+ Page<ProductSelfVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
|
|
+ return TableDataInfo.build(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询符合条件的自营商品池列表
|
|
|
+ *
|
|
|
+ * @param bo 查询条件
|
|
|
+ * @return 自营商品池列表
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<ProductSelfVo> queryList(ProductSelfBo bo) {
|
|
|
+ LambdaQueryWrapper<ProductSelf> lqw = buildQueryWrapper(bo);
|
|
|
+ return baseMapper.selectVoList(lqw);
|
|
|
+ }
|
|
|
+
|
|
|
+ private LambdaQueryWrapper<ProductSelf> buildQueryWrapper(ProductSelfBo bo) {
|
|
|
+ Map<String, Object> params = bo.getParams();
|
|
|
+ LambdaQueryWrapper<ProductSelf> lqw = Wrappers.lambdaQuery();
|
|
|
+ lqw.orderByAsc(ProductSelf::getProductId);
|
|
|
+ lqw.eq(bo.getAuditStatus() != null, ProductSelf::getAuditStatus, bo.getAuditStatus());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getAuditReason()), ProductSelf::getAuditReason, bo.getAuditReason());
|
|
|
+ lqw.eq(StringUtils.isNotBlank(bo.getPlatformCode()), ProductSelf::getPlatformCode, bo.getPlatformCode());
|
|
|
+ return lqw;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增自营商品池
|
|
|
+ *
|
|
|
+ * @param bo 自营商品池
|
|
|
+ * @return 是否新增成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Boolean insertByBo(ProductSelfBo bo) {
|
|
|
+ ProductSelf add = MapstructUtils.convert(bo, ProductSelf.class);
|
|
|
+ validEntityBeforeSave(add);
|
|
|
+ //如果存在该商品为更新
|
|
|
+ if(baseMapper.exists(new LambdaQueryWrapper<ProductSelf>().eq(ProductSelf::getProductId, add.getProductId()))){
|
|
|
+ return updateByBo(bo);
|
|
|
+ }
|
|
|
+ boolean flag = baseMapper.insert(add) > 0;
|
|
|
+
|
|
|
+ if (flag) {
|
|
|
+ bo.setProductId(add.getProductId());
|
|
|
+ }
|
|
|
+ return flag;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改自营商品池
|
|
|
+ *
|
|
|
+ * @param bo 自营商品池
|
|
|
+ * @return 是否修改成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Boolean updateByBo(ProductSelfBo bo) {
|
|
|
+ ProductSelf update = MapstructUtils.convert(bo, ProductSelf.class);
|
|
|
+// validEntityBeforeSave(update);
|
|
|
+ boolean flag = baseMapper.updateById(update) > 0;
|
|
|
+ if(Objects.equals(update.getAuditStatus(), 2)){
|
|
|
+ productBaseMapper.update(Wrappers.lambdaUpdate(ProductBase.class)
|
|
|
+ .eq(ProductBase::getId, update.getProductId())
|
|
|
+ .set(ProductBase::getIsSelf, 1)
|
|
|
+ );
|
|
|
+ productEsMapper.update(new LambdaEsUpdateWrapper<ProductBaseVo>()
|
|
|
+ .eq(ProductBaseVo::getId, update.getProductId())
|
|
|
+ .set(ProductBaseVo::getIsSelf, 1)
|
|
|
+ );
|
|
|
+ }else if(Objects.equals(update.getAuditStatus(), 3)){
|
|
|
+ productBaseMapper.update(Wrappers.lambdaUpdate(ProductBase.class)
|
|
|
+ .eq(ProductBase::getId, update.getProductId())
|
|
|
+ .set(ProductBase::getIsSelf, 0)
|
|
|
+ );
|
|
|
+ productEsMapper.update(new LambdaEsUpdateWrapper<ProductBaseVo>()
|
|
|
+ .eq(ProductBaseVo::getId, update.getProductId())
|
|
|
+ .set(ProductBaseVo::getIsSelf, 0)
|
|
|
+ );
|
|
|
+ }
|
|
|
+ return flag;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存前的数据校验
|
|
|
+ */
|
|
|
+ private void validEntityBeforeSave(ProductSelf entity){
|
|
|
+ //不要重复添加
|
|
|
+ if(baseMapper.exists(new LambdaQueryWrapper<ProductSelf>()
|
|
|
+ .eq(ProductSelf::getAuditStatus, 2)
|
|
|
+ .eq(ProductSelf::getProductId, entity.getProductId()))){
|
|
|
+ throw new ServiceException("商品已添加到池,请勿重复添加");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 校验并批量删除自营商品池信息
|
|
|
+ *
|
|
|
+ * @param ids 待删除的主键集合
|
|
|
+ * @param isValid 是否进行有效性校验
|
|
|
+ * @return 是否删除成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
|
|
|
+ if(isValid){
|
|
|
+ //TODO 做一些业务上的校验,判断是否需要校验
|
|
|
+ }
|
|
|
+ return baseMapper.deleteByIds(ids) > 0;
|
|
|
+ }
|
|
|
+}
|