|
@@ -13,14 +13,21 @@ import com.fire.common.exception.BaseException;
|
|
|
import com.fire.dto.ChannelSupplier;
|
|
|
import com.fire.dto.enums.Status;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.messaging.support.MessageBuilder;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import redis.clients.jedis.JedisCluster;
|
|
|
|
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
+import static com.fire.common.constants.RocketTags.SUPPLIER_TAG;
|
|
|
+import static com.fire.common.constants.RocketTopic.UPDATE_TOPIC;
|
|
|
+import static com.fire.dto.enums.RedisKey.GLOBAL_ID_INCR;
|
|
|
+
|
|
|
/**
|
|
|
* @author: admin
|
|
|
* @Description:
|
|
@@ -34,12 +41,18 @@ public class SupplierServiceImpl extends ServiceImpl<ChannelSupplierMapper, Chan
|
|
|
@Autowired
|
|
|
private BankCardService bankCardService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private RocketMQTemplate rocketMQTemplate;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private JedisCluster jedisCluster;
|
|
|
+
|
|
|
@Override
|
|
|
public IPage<ChannelSupplier> getSupplierList(SupplierPageParam supplierPageParam) {
|
|
|
LambdaQueryWrapper<ChannelSupplier> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
lambdaQueryWrapper.
|
|
|
like(supplierPageParam.getSupplierName() != null, ChannelSupplier::getSupplierName, supplierPageParam.getSupplierName())
|
|
|
- .orderByDesc(ChannelSupplier::getBalance, ChannelSupplier::getIsValid);
|
|
|
+ .orderByDesc(ChannelSupplier::getIsValid, ChannelSupplier::getBalance, ChannelSupplier::getCreateTime);
|
|
|
IPage<ChannelSupplier> supplierList = baseMapper.selectPage(supplierPageParam, lambdaQueryWrapper);
|
|
|
|
|
|
if (supplierList != null) {
|
|
@@ -60,20 +73,22 @@ public class SupplierServiceImpl extends ServiceImpl<ChannelSupplierMapper, Chan
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void updateSupplierByRelationId(ChannelSupplier channelSupplier) {
|
|
|
+ public void updateSupplierById(ChannelSupplier channelSupplier) {
|
|
|
channelSupplier.setUpdator("admin");
|
|
|
channelSupplier.setUpdateTime(new Date());
|
|
|
LambdaUpdateWrapper<ChannelSupplier> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
|
|
lambdaUpdateWrapper.eq(channelSupplier.getSupplierId() != null, ChannelSupplier::getSupplierId, channelSupplier.getSupplierId());
|
|
|
int result = baseMapper.update(channelSupplier, lambdaUpdateWrapper);
|
|
|
- log.info("供应商已修改为:【{}】", channelSupplier);
|
|
|
if (result > 0) {
|
|
|
- // TODO: 2021/5/18 向MQ推送消息
|
|
|
+ rocketMQTemplate.send(UPDATE_TOPIC + ":" + SUPPLIER_TAG, MessageBuilder.withPayload(SUPPLIER_TAG).build());
|
|
|
}
|
|
|
+ log.info("供应商已修改为:【{}】", channelSupplier);
|
|
|
if (ObjectUtil.isNotEmpty(channelSupplier.getBankCards())) {
|
|
|
- // TODO 把供应商编号写入添加的银行里面
|
|
|
+ /**
|
|
|
+ 把供应商编号写入添加的银行里面
|
|
|
+ */
|
|
|
channelSupplier.getBankCards().forEach(bankCard -> {
|
|
|
- bankCard.setRelationId(channelSupplier.getSupplierId());
|
|
|
+ bankCard.setRelationId(channelSupplier.getSupplierId().intValue());
|
|
|
});
|
|
|
|
|
|
bankCardService.saveBankCards(channelSupplier.getBankCards());
|
|
@@ -85,23 +100,24 @@ public class SupplierServiceImpl extends ServiceImpl<ChannelSupplierMapper, Chan
|
|
|
public void saveSupplier(ChannelSupplier channelSupplier) {
|
|
|
channelSupplier.setCreator("admin");
|
|
|
channelSupplier.setCreateTime(new Date());
|
|
|
+ channelSupplier.setSupplierId(jedisCluster.incr(GLOBAL_ID_INCR.key()));
|
|
|
int result = baseMapper.insert(channelSupplier);
|
|
|
- log.info("添加的供应商是:【{}】", channelSupplier);
|
|
|
if (result > 0) {
|
|
|
- // TODO:2021/5/18 向MQ推送消息
|
|
|
+ rocketMQTemplate.send(UPDATE_TOPIC + ":" + SUPPLIER_TAG, MessageBuilder.withPayload(SUPPLIER_TAG).build());
|
|
|
}
|
|
|
+ log.info("添加的供应商是:【{}】", channelSupplier);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void deleteSupplierById(Integer id) {
|
|
|
if (id != null) {
|
|
|
int result = baseMapper.deleteById(id);
|
|
|
- log.info("编号为:【{}】的供应商删除成功!", id);
|
|
|
if (result > 0) {
|
|
|
- // TODO:2021/5/18 向MQ推送消息
|
|
|
+ rocketMQTemplate.send(UPDATE_TOPIC + ":" + SUPPLIER_TAG, MessageBuilder.withPayload(SUPPLIER_TAG).build());
|
|
|
}
|
|
|
+ log.info("编号为:【{}】的供应商删除成功!", id);
|
|
|
} else {
|
|
|
- throw new BaseException(Status.REQUEST_PARAM_ERROR.status(),Status.REQUEST_PARAM_ERROR.message());
|
|
|
+ throw new BaseException(Status.PARAM_ERROR.status(), Status.PARAM_ERROR.message());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -110,12 +126,11 @@ public class SupplierServiceImpl extends ServiceImpl<ChannelSupplierMapper, Chan
|
|
|
if (bankId != null) {
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
map.put("id", bankId);
|
|
|
- int result = baseMapper.deleteByMap(map);
|
|
|
- if (result > 0) {
|
|
|
- // TODO:2021/5/18 向MQ推送消息
|
|
|
- }
|
|
|
+
|
|
|
+ baseMapper.deleteByMap(map);
|
|
|
+
|
|
|
} else {
|
|
|
- throw new BaseException(Status.REQUEST_PARAM_ERROR.status(),Status.REQUEST_PARAM_ERROR.message());
|
|
|
+ throw new BaseException(Status.PARAM_ERROR.status(), Status.PARAM_ERROR.message());
|
|
|
}
|
|
|
}
|
|
|
|