Explorar el Código

处理线上与线下通道不一致问题

杜魏 hace 4 años
padre
commit
23fa0ababf

+ 0 - 2
modules/admin/src/main/java/com/fire/admin/service/ChannelInfoService.java

@@ -29,8 +29,6 @@ public interface ChannelInfoService extends IService<ChannelInfo> {
 
     void insertChannelInfo(ChannelInfo channelInfo);
 
-    void saveOrUpdateChannelInfos(List<ChannelInfo> channelInfos);
-
     void deleteChannelAndChanProdByChannelId(Long channelId);
 
     int deleteChannelBySupplierId(Long supplierId);

+ 11 - 1
modules/admin/src/main/java/com/fire/admin/service/impl/BankCardServiceImpl.java

@@ -6,7 +6,9 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fire.admin.mapper.BankCardMapper;
 import com.fire.admin.service.BankCardService;
 import com.fire.admin.util.SecurityUtil;
+import com.fire.common.exception.BaseException;
 import com.fire.dto.BankCard;
+import com.fire.dto.enums.Status;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 import redis.clients.jedis.JedisCluster;
@@ -31,7 +33,7 @@ public class BankCardServiceImpl extends ServiceImpl<BankCardMapper, BankCard> i
     private JedisCluster jedisCluster;
 
     /**
-     * @Description: TODO 获取银行列表,distinguish :1 供应商  2: 客户
+     * @Description: TODO 获取银行列表,distinguish :1 供应商  2: 客户
      * @Param: [relationId, distinguish]
      * @return: java.util.List<com.fire.dto.BankCard>
      * @Date: 2021/6/16 11:44
@@ -60,8 +62,14 @@ public class BankCardServiceImpl extends ServiceImpl<BankCardMapper, BankCard> i
                     bankCard.setUpdateTime(new Date());
                     log.info("修改的银行卡是:【{}】", bankCards);
                 }
+
+                if (bankCard.getCardNo() == null) {
+                    throw new BaseException(Status.PARAM_LOSS.status(), Status.PARAM_LOSS.message());
+                }
             }
             this.saveOrUpdateBatch(bankCards);
+        } else {
+            throw new BaseException(Status.PARAM_LOSS.status(), Status.PARAM_LOSS.message());
         }
     }
 
@@ -72,6 +80,8 @@ public class BankCardServiceImpl extends ServiceImpl<BankCardMapper, BankCard> i
             if (result > 0) {
                 log.info("编号为:【{}】的银行卡删除成功!", bankId);
             }
+        } else {
+            throw new BaseException(Status.PARAM_LOSS.status(), Status.PARAM_LOSS.message());
         }
     }
 }

+ 5 - 3
modules/admin/src/main/java/com/fire/admin/service/impl/ChannelGroupServiceImpl.java

@@ -67,6 +67,7 @@ public class ChannelGroupServiceImpl extends ServiceImpl<ChannelGroupMapper, Cha
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public void addChannelGroup(ChannelGroup channelGroup) {
         if (channelGroup != null) {
             if (channelGroup.getChannelGroupId() == null) {
@@ -80,11 +81,12 @@ public class ChannelGroupServiceImpl extends ServiceImpl<ChannelGroupMapper, Cha
                 log.info("添加的通道组是:【{}】", channelGroup);
             }
         } else {
-            throw new BaseException(Status.PARAM_ERROR.status(), Status.PARAM_ERROR.message());
+            throw new BaseException(Status.PARAM_LOSS.status(), Status.PARAM_LOSS.message());
         }
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public void updateChannelGroupById(ChannelGroup channelGroup) {
         if (channelGroup != null) {
             channelGroup.setUpdator(SecurityUtil.getUser().getUsername());
@@ -104,7 +106,7 @@ public class ChannelGroupServiceImpl extends ServiceImpl<ChannelGroupMapper, Cha
             }
 
         } else {
-            throw new BaseException(Status.PARAM_ERROR.status(), Status.PARAM_ERROR.message());
+            throw new BaseException(Status.PARAM_LOSS.status(), Status.PARAM_LOSS.message());
         }
     }
 
@@ -120,7 +122,7 @@ public class ChannelGroupServiceImpl extends ServiceImpl<ChannelGroupMapper, Cha
                 log.info("通道组编号为【{}】的分发组删除成功!", channelGroupId);
             }
         } else {
-            throw new BaseException(Status.PARAM_ERROR.status(), Status.PARAM_ERROR.message());
+            throw new BaseException(Status.PARAM_LOSS.status(), Status.PARAM_LOSS.message());
         }
     }
 

+ 23 - 36
modules/admin/src/main/java/com/fire/admin/service/impl/ChannelInfoServiceImpl.java

@@ -76,7 +76,7 @@ public class ChannelInfoServiceImpl extends ServiceImpl<ChannelInfoMapper, Chann
     public List<ChannelInfo> getChannelInfoByOperator(Integer operator) {
         if (operator != null) {
             LambdaQueryWrapper<ChannelInfo> lambdaQueryWrapper = new LambdaQueryWrapper<>();
-            lambdaQueryWrapper.eq(ChannelInfo::getOperator,operator);
+            lambdaQueryWrapper.eq(ChannelInfo::getOperator, operator);
             List<ChannelInfo> channelInfos = baseMapper.selectList(lambdaQueryWrapper);
             if (ObjectUtil.isNotEmpty(channelInfos)) {
                 return channelInfos;
@@ -100,6 +100,7 @@ public class ChannelInfoServiceImpl extends ServiceImpl<ChannelInfoMapper, Chann
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public void updateChannelInfoById(ChannelInfo channelInfo) {
         if (channelInfo != null) {
             channelInfo.setUpdator(SecurityUtil.getUser().getUsername());
@@ -114,12 +115,13 @@ public class ChannelInfoServiceImpl extends ServiceImpl<ChannelInfoMapper, Chann
                 log.info("添加的通道产品是:【{}】", channelInfo.getChannelProductInfos().toString());
             }
         } else {
-            throw new BaseException(Status.PARAM_ERROR.status(), Status.PARAM_ERROR.message());
+            throw new BaseException(Status.PARAM_LOSS.status(), Status.PARAM_LOSS.message());
         }
 
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public void insertChannelInfo(ChannelInfo channelInfo) {
         if (channelInfo != null) {
             if (channelInfo.getChannelId() == null) {
@@ -138,32 +140,11 @@ public class ChannelInfoServiceImpl extends ServiceImpl<ChannelInfoMapper, Chann
                 log.info("添加的通道是:【{}】", channelInfo);
             }
         } else {
-            throw new BaseException(Status.PARAM_ERROR.status(), Status.PARAM_ERROR.message());
+            throw new BaseException(Status.PARAM_LOSS.status(), Status.PARAM_LOSS.message());
         }
 
     }
 
-    @Override
-    public void saveOrUpdateChannelInfos(List<ChannelInfo> channelInfos) {
-        if (ObjectUtil.isNotEmpty(channelInfos)) {
-            for (ChannelInfo info : channelInfos) {
-                if (info.getChannelId() == null) {
-                    info.setChannelId(jedisCluster.incr(GLOBAL_ID_INCR.key()));
-                    info.setCreator(SecurityUtil.getUser().getUsername());
-                    info.setCreateTime(new Date());
-                    log.info("添加的通道是:", channelInfos);
-                } else {
-                    info.setUpdator(SecurityUtil.getUser().getUsername());
-                    info.setUpdateTime(new Date());
-                    log.info("修改的通道是:", channelInfos);
-                }
-            }
-            this.saveOrUpdateBatch(channelInfos);
-        } else {
-            throw new BaseException(Status.PARAM_ERROR.status(), Status.PARAM_ERROR.message());
-        }
-    }
-
     @Override
     @Transactional(rollbackFor = Exception.class)
     public void deleteChannelAndChanProdByChannelId(Long channelId) {
@@ -176,11 +157,12 @@ public class ChannelInfoServiceImpl extends ServiceImpl<ChannelInfoMapper, Chann
                 log.info("通道编号为:【{}】的通道产品删除成功!", channelId);
             }
         } else {
-            throw new BaseException(Status.PARAM_ERROR.status(), Status.PARAM_ERROR.message());
+            throw new BaseException(Status.PARAM_LOSS.status(), Status.PARAM_LOSS.message());
         }
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public int deleteChannelBySupplierId(Long supplierId) {
         if (supplierId != null) {
             Map<String, Object> map = new HashMap<>();
@@ -193,7 +175,7 @@ public class ChannelInfoServiceImpl extends ServiceImpl<ChannelInfoMapper, Chann
                 return 0;
             }
         } else {
-            throw new BaseException(Status.PARAM_ERROR.status(), Status.PARAM_ERROR.message());
+            throw new BaseException(Status.PARAM_LOSS.status(), Status.PARAM_LOSS.message());
         }
     }
 
@@ -206,23 +188,28 @@ public class ChannelInfoServiceImpl extends ServiceImpl<ChannelInfoMapper, Chann
                 return result;
             }
         } else {
-            throw new BaseException(Status.PARAM_ERROR.status(), Status.PARAM_ERROR.message());
+            throw new BaseException(Status.PARAM_LOSS.status(), Status.PARAM_LOSS.message());
         }
         return 0;
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public void setInvalid(Long channelId, Integer isValid) {
-        ChannelInfo channelInfo = ChannelInfo.builder().channelId(channelId)
-                .isValid(isValid).build();
-        int result = baseMapper.updateById(channelInfo);
-        if (result > 0) {
-            rocketMQTemplate.send(UPDATE_TOPIC + ":" + SUPPLIER_TAG, MessageBuilder.withPayload(SUPPLIER_TAG).build());
-            if (channelInfo.getIsValid() == 0) {
-                log.info("编号为【{}】的通道已置无效", channelId);
-            } else {
-                log.info("编号为【{}】的通道已置有效", channelId);
+        if (channelId != null && isValid != null) {
+            ChannelInfo channelInfo = ChannelInfo.builder().channelId(channelId)
+                    .isValid(isValid).build();
+            int result = baseMapper.updateById(channelInfo);
+            if (result > 0) {
+                rocketMQTemplate.send(UPDATE_TOPIC + ":" + SUPPLIER_TAG, MessageBuilder.withPayload(SUPPLIER_TAG).build());
+                if (channelInfo.getIsValid() == 0) {
+                    log.info("编号为【{}】的通道已置无效", channelId);
+                } else {
+                    log.info("编号为【{}】的通道已置有效", channelId);
+                }
             }
+        } else {
+            throw new BaseException(Status.PARAM_LOSS.status(), Status.PARAM_LOSS.message());
         }
     }
 }

+ 7 - 2
modules/admin/src/main/java/com/fire/admin/service/impl/ChannelProductServiceImpl.java

@@ -12,6 +12,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.rocketmq.spring.core.RocketMQTemplate;
 import org.springframework.messaging.support.MessageBuilder;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 import redis.clients.jedis.JedisCluster;
 
 import javax.annotation.Resource;
@@ -70,10 +71,13 @@ public class ChannelProductServiceImpl extends ServiceImpl<ChannelProductMapper,
             if (result) {
                 rocketMQTemplate.send(UPDATE_TOPIC + ":" + SUPPLIER_TAG, MessageBuilder.withPayload(SUPPLIER_TAG).build());
             }
+        } else {
+            throw new BaseException(Status.PARAM_LOSS.status(), Status.PARAM_LOSS.message());
         }
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public void deleteChannelProductByChanProdId(Long channelProductId) {
         if (channelProductId != null) {
             int result = baseMapper.deleteById(channelProductId);
@@ -82,11 +86,12 @@ public class ChannelProductServiceImpl extends ServiceImpl<ChannelProductMapper,
                 log.info("通道产品编号为【{}】的通道产品删除成功!", channelProductId);
             }
         } else {
-            throw new BaseException(Status.PARAM_ERROR.status(), Status.PARAM_ERROR.message());
+            throw new BaseException(Status.PARAM_LOSS.status(), Status.PARAM_LOSS.message());
         }
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public int deleteChannelProductByChanId(Long channelId) {
         if (channelId != null) {
             Map<String, Object> map = new HashMap<>();
@@ -98,7 +103,7 @@ public class ChannelProductServiceImpl extends ServiceImpl<ChannelProductMapper,
             }
             return 0;
         } else {
-            throw new BaseException(Status.PARAM_ERROR.status(), Status.PARAM_ERROR.message());
+            throw new BaseException(Status.PARAM_LOSS.status(), Status.PARAM_LOSS.message());
         }
     }
 

+ 23 - 7
modules/admin/src/main/java/com/fire/admin/service/impl/DistGroupChannelServiceImpl.java

@@ -4,11 +4,14 @@ import cn.hutool.core.util.ObjectUtil;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fire.admin.mapper.DistGroupChannelMapper;
 import com.fire.admin.service.DistGroupChannelService;
+import com.fire.common.exception.BaseException;
 import com.fire.dto.DistributeGroupChannel;
+import com.fire.dto.enums.Status;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.rocketmq.spring.core.RocketMQTemplate;
 import org.springframework.messaging.support.MessageBuilder;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 import redis.clients.jedis.JedisCluster;
 
 import javax.annotation.Resource;
@@ -48,23 +51,31 @@ public class DistGroupChannelServiceImpl extends ServiceImpl<DistGroupChannelMap
     @Override
     public void saveOrUpdateChannels(List<DistributeGroupChannel> channels) {
         if (ObjectUtil.isNotEmpty(channels)) {
-            for (DistributeGroupChannel info : channels) {
-//                info.setDistributeGroupId(info.getDistributeGroupId());
-                if (info.getChannelGroupId() == null) {
-                    info.setChannelGroupId(1L);
-                }
-                if (info.getId() == null) {
-                    info.setId(jedisCluster.incr(GLOBAL_ID_INCR.key()));
+            for (DistributeGroupChannel channel : channels) {
+                if (channel.getId() == null) {
+                    channel.setId(jedisCluster.incr(GLOBAL_ID_INCR.key()));
                     log.info("添加的通道是:", channels);
                 } else {
                     log.info("修改的通道是:", channels);
                 }
+
+                if (channel.getChannelGroupId() == null) {
+                    channel.setChannelGroupId(1L);
+                }
+
+                if (channel.getWeight() == null) {
+                    throw new BaseException(Status.PARAM_LOSS.status(), Status.PARAM_LOSS.message());
+                }
+
             }
             this.saveOrUpdateBatch(channels);
+        } else {
+            throw new BaseException(Status.PARAM_LOSS.status(), Status.PARAM_LOSS.message());
         }
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public int removeChannelByDistGroupId(Long distGroupId) {
         if (distGroupId != null) {
             Map<String, Object> map = new HashMap<>();
@@ -75,11 +86,14 @@ public class DistGroupChannelServiceImpl extends ServiceImpl<DistGroupChannelMap
                 log.info("分发组编号为【{}】的通道删除成功!", distGroupId);
                 return result;
             }
+        } else {
+            throw new BaseException(Status.PARAM_LOSS.status(), Status.PARAM_LOSS.message());
         }
         return 0;
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public void removeChannelById(Long id) {
         if (id != null) {
             int result = baseMapper.deleteById(id);
@@ -87,6 +101,8 @@ public class DistGroupChannelServiceImpl extends ServiceImpl<DistGroupChannelMap
                 rocketMQTemplate.send(UPDATE_TOPIC + ":" + SUPPLIER_TAG, MessageBuilder.withPayload(SUPPLIER_TAG).build());
                 log.info("编号为【{}】的通道删除成功!", id);
             }
+        } else {
+            throw new BaseException(Status.PARAM_LOSS.status(), Status.PARAM_LOSS.message());
         }
     }
 }

+ 20 - 5
modules/admin/src/main/java/com/fire/admin/service/impl/DistributeGroupServiceImpl.java

@@ -15,6 +15,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.rocketmq.spring.core.RocketMQTemplate;
 import org.springframework.messaging.support.MessageBuilder;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 import redis.clients.jedis.JedisCluster;
 
 import javax.annotation.Resource;
@@ -64,9 +65,6 @@ public class DistributeGroupServiceImpl extends ServiceImpl<DistributeGroupMappe
     public void saveOrUpdateDistributeGroups(List<DistributeGroup> distributeGroups) {
         if (ObjectUtil.isNotEmpty(distributeGroups)) {
             for (DistributeGroup distributeGroup : distributeGroups) {
-                if (distributeGroup.getChannelGroupId() == null) {
-                    distributeGroup.setChannelGroupId(1L);
-                }
                 if (distributeGroup.getDistributeGroupId() == null) {
                     distributeGroup.setDistributeGroupId(jedisCluster.incr(GLOBAL_ID_INCR.key()));
                     distributeGroup.setCreator(SecurityUtil.getUser().getUsername());
@@ -77,6 +75,19 @@ public class DistributeGroupServiceImpl extends ServiceImpl<DistributeGroupMappe
                     distributeGroup.setUpdateTime(new Date());
                     log.info("修改的分发组是:", distributeGroups);
                 }
+
+                if (distributeGroup.getName() == null) {
+                    throw new BaseException(Status.PARAM_LOSS.status(), Status.PARAM_LOSS.message());
+                }
+
+                if (distributeGroup.getChannelGroupId() == null) {
+                    distributeGroup.setChannelGroupId(1L);
+                }
+
+                if (distributeGroup.getWeight() == null) {
+                    throw new BaseException(Status.PARAM_LOSS.status(), Status.PARAM_LOSS.message());
+                }
+
             }
             boolean result = this.saveOrUpdateBatch(distributeGroups);
 
@@ -92,11 +103,12 @@ public class DistributeGroupServiceImpl extends ServiceImpl<DistributeGroupMappe
                 log.info("分发组是:【{}】", distributeGroups);
             }
         } else {
-            throw new BaseException(Status.PARAM_ERROR.status(), Status.PARAM_ERROR.message());
+            throw new BaseException(Status.PARAM_LOSS.status(), Status.PARAM_LOSS.message());
         }
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public int removeDistributeGroupByChannelGroupId(Long channelGroupId) {
         if (channelGroupId != null) {
             Map<String, Object> map = new HashMap<>();
@@ -106,12 +118,15 @@ public class DistributeGroupServiceImpl extends ServiceImpl<DistributeGroupMappe
                 rocketMQTemplate.send(UPDATE_TOPIC + ":" + SUPPLIER_TAG, MessageBuilder.withPayload(SUPPLIER_TAG).build());
                 return result;
             }
+        } else {
+            throw new BaseException(Status.PARAM_LOSS.status(), Status.PARAM_LOSS.message());
         }
         return 0;
     }
 
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public void removeDistGroupAndChannelByDistGroupId(Long distGroupId) {
         if (distGroupId != null) {
             int distResult = baseMapper.deleteById(distGroupId);
@@ -122,7 +137,7 @@ public class DistributeGroupServiceImpl extends ServiceImpl<DistributeGroupMappe
                 log.info("分发组编号为【{}】的通道删除成功!", distGroupId);
             }
         } else {
-            throw new BaseException(Status.PARAM_ERROR.status(), Status.PARAM_ERROR.message());
+            throw new BaseException(Status.PARAM_LOSS.status(), Status.PARAM_LOSS.message());
         }
     }
 

+ 16 - 9
modules/admin/src/main/java/com/fire/admin/service/impl/SupplierServiceImpl.java

@@ -79,6 +79,7 @@ public class SupplierServiceImpl extends ServiceImpl<ChannelSupplierMapper, Chan
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public void updateSupplierById(ChannelSupplier channelSupplier) {
         if (channelSupplier != null) {
             channelSupplier.setUpdator(SecurityUtil.getUser().getUsername());
@@ -105,6 +106,7 @@ public class SupplierServiceImpl extends ServiceImpl<ChannelSupplierMapper, Chan
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public void saveSupplier(ChannelSupplier channelSupplier) {
         if (channelSupplier != null) {
             channelSupplier.setSupplierId(jedisCluster.incr(GLOBAL_ID_INCR.key()));
@@ -147,17 +149,22 @@ public class SupplierServiceImpl extends ServiceImpl<ChannelSupplierMapper, Chan
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public void setInvalid(Long supplierId, Integer isValid) {
-        ChannelSupplier channelSupplier = ChannelSupplier.builder().supplierId(supplierId)
-                .isValid(isValid).build();
-        int result = baseMapper.updateById(channelSupplier);
-        if (result > 0) {
-            rocketMQTemplate.send(UPDATE_TOPIC + ":" + SUPPLIER_TAG, MessageBuilder.withPayload(SUPPLIER_TAG).build());
-            if (channelSupplier.getIsValid() == 0) {
-                log.info("编号为【{}】的供应商已置无效", supplierId);
-            } else {
-                log.info("编号为【{}】的供应商已置有效", supplierId);
+        if (supplierId != null && isValid != null) {
+            ChannelSupplier channelSupplier = ChannelSupplier.builder().supplierId(supplierId)
+                    .isValid(isValid).build();
+            int result = baseMapper.updateById(channelSupplier);
+            if (result > 0) {
+                rocketMQTemplate.send(UPDATE_TOPIC + ":" + SUPPLIER_TAG, MessageBuilder.withPayload(SUPPLIER_TAG).build());
+                if (channelSupplier.getIsValid() == 0) {
+                    log.info("编号为【{}】的供应商已置无效", supplierId);
+                } else {
+                    log.info("编号为【{}】的供应商已置有效", supplierId);
+                }
             }
+        } else {
+            throw new BaseException(Status.PARAM_LOSS.status(), Status.PARAM_LOSS.message());
         }
     }
 }

+ 2 - 2
modules/admin/src/main/resources/bootstrap.yml

@@ -38,10 +38,10 @@ spring:
   cloud:
     nacos:
       config:
-        server-addr: 47.106.133.48:8848
+        server-addr: 139.155.226.217:8848
         file-extension: yaml
         namespace: fire
       discovery:
-        server-addr: 47.106.133.48:8848
+        server-addr: 139.155.226.217:8848
         namespace: fire
         service: admin