he2802 2 年之前
父節點
當前提交
ff660c0470

+ 33 - 4
zhongzheng-system/src/main/java/com/zhongzheng/modules/distribution/service/impl/DistributionLinkServiceImpl.java

@@ -1,15 +1,22 @@
 package com.zhongzheng.modules.distribution.service.impl;
 
 import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.lang.Validator;
 import cn.hutool.core.util.StrUtil;
+import com.zhongzheng.common.exception.CustomException;
 import com.zhongzheng.common.utils.DateUtils;
+import com.zhongzheng.common.utils.ToolsUtils;
 import com.zhongzheng.modules.distribution.bo.DistributionLinkAddBo;
 import com.zhongzheng.modules.distribution.bo.DistributionLinkEditBo;
 import com.zhongzheng.modules.distribution.bo.DistributionLinkQueryBo;
 import com.zhongzheng.modules.distribution.domain.DistributionLink;
+import com.zhongzheng.modules.distribution.domain.DistributionSeller;
 import com.zhongzheng.modules.distribution.mapper.DistributionLinkMapper;
 import com.zhongzheng.modules.distribution.service.IDistributionLinkService;
+import com.zhongzheng.modules.distribution.service.IDistributionSellerService;
 import com.zhongzheng.modules.distribution.vo.DistributionLinkVo;
+import com.zhongzheng.modules.system.domain.SysTenant;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@@ -29,6 +36,10 @@ import java.util.stream.Collectors;
 @Service
 public class DistributionLinkServiceImpl extends ServiceImpl<DistributionLinkMapper, DistributionLink> implements IDistributionLinkService {
 
+    @Autowired
+    private  IDistributionSellerService iDistributionSellerService;
+
+
     @Override
     public DistributionLinkVo queryById(Long id){
         DistributionLink db = this.baseMapper.selectById(id);
@@ -68,11 +79,29 @@ public class DistributionLinkServiceImpl extends ServiceImpl<DistributionLinkMap
 
     @Override
     public Boolean insertByAddBo(DistributionLinkAddBo bo) {
+        if(Validator.isNotEmpty(bo.getDistributionId())){
+            throw new CustomException("活动ID不能为空");
+        }
+        if(Validator.isNotEmpty(bo.getLinkCode())){
+            throw new CustomException("活动ID不能为空");
+        }
         DistributionLink add = BeanUtil.toBean(bo, DistributionLink.class);
-        validEntityBeforeSave(add);
-        add.setCreateTime(DateUtils.getNowTime());
-        add.setUpdateTime(DateUtils.getNowTime());
-        return this.save(add);
+        DistributionSeller seller = iDistributionSellerService.getOne(new LambdaQueryWrapper<DistributionSeller>().eq(DistributionSeller::getUserId, bo.getUserId()));
+        if(Validator.isNotEmpty(seller)){
+            DistributionLink link = getOne(new LambdaQueryWrapper<DistributionLink>().eq(DistributionLink::getSellerId, seller.getSellerId())
+                    .eq(DistributionLink::getDistributionId, bo.getDistributionId())
+                    .eq(DistributionLink::getLinkCode, bo.getLinkCode()));
+            if(Validator.isNotEmpty(link)){
+                return false;
+            }
+            add.setSellerId(seller.getSellerId());
+            validEntityBeforeSave(add);
+            add.setCreateTime(DateUtils.getNowTime());
+            add.setOwner(0);
+            add.setUpdateTime(DateUtils.getNowTime());
+            return this.save(add);
+        }
+        return false;
     }
 
     @Override