|
@@ -1,22 +1,29 @@
|
|
|
package com.fire.admin.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fire.admin.dto.CustomerProductDto;
|
|
|
import com.fire.admin.mapper.CustomerProductInfoMapper;
|
|
|
import com.fire.admin.service.CustomerProductInfoService;
|
|
|
import com.fire.admin.vo.CustomerProductInfoVo;
|
|
|
-import com.fire.common.exception.BaseException;
|
|
|
import com.fire.dto.CustomerProduct;
|
|
|
-import com.fire.dto.enums.Status;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
|
|
+import org.springframework.messaging.support.MessageBuilder;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import redis.clients.jedis.JedisCluster;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+import static com.fire.common.constants.RocketTags.CONSUMER_PRODUCT_TAG;
|
|
|
+import static com.fire.common.constants.RocketTopic.UPDATE_TOPIC;
|
|
|
+import static com.fire.dto.enums.RedisKey.GLOBAL_ID_INCR;
|
|
|
+
|
|
|
/**
|
|
|
* @author: liuliu
|
|
|
* @ClassName: CustomerProductInfoServiceImpl
|
|
@@ -27,6 +34,12 @@ import java.util.stream.Collectors;
|
|
|
@Service
|
|
|
public class CustomerProductInfoServiceImpl extends ServiceImpl<CustomerProductInfoMapper, CustomerProduct> implements CustomerProductInfoService {
|
|
|
|
|
|
+ @Resource
|
|
|
+ private JedisCluster jedisCluster;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private RocketMQTemplate rocketMQTemplate;
|
|
|
+
|
|
|
/**
|
|
|
* @Description: TODO 客户产品列表
|
|
|
* @Param: [customerId, type]
|
|
@@ -35,7 +48,7 @@ public class CustomerProductInfoServiceImpl extends ServiceImpl<CustomerProductI
|
|
|
* @Date: 2021/5/27 12:13
|
|
|
*/
|
|
|
@Override
|
|
|
- public List<CustomerProductInfoVo> getCustomerProductByCustomerId(Integer customerId, Integer type) {
|
|
|
+ public List<CustomerProductInfoVo> getCustomerProductByCustomerId(Long customerId, Integer type) {
|
|
|
return baseMapper.queryCustomerProductByCustomerId(customerId, type);
|
|
|
}
|
|
|
|
|
@@ -47,7 +60,7 @@ public class CustomerProductInfoServiceImpl extends ServiceImpl<CustomerProductI
|
|
|
* @Date: 2021/6/1 11:02
|
|
|
*/
|
|
|
@Override
|
|
|
- public void deleteCustomerProduct(Integer customerProductId) {
|
|
|
+ public void deleteCustomerProduct(Long customerProductId) {
|
|
|
int i = baseMapper.deleteById(customerProductId);
|
|
|
if (i > 0) {
|
|
|
log.info("-------------------------------- 客户产品删除成功,客户产品编号为:【{}】 ----------------------------------", customerProductId);
|
|
@@ -57,52 +70,58 @@ public class CustomerProductInfoServiceImpl extends ServiceImpl<CustomerProductI
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @Description: TODO 把客户单个产品置无效
|
|
|
- * @Param: [customerProductId]
|
|
|
- * @return: void
|
|
|
- * @Author: liuliu
|
|
|
- * @Date: 2021/6/1 11:47
|
|
|
- */
|
|
|
+ * @Description: TODO 把客户单个产品置无效
|
|
|
+ * @Param: [customerProductId]
|
|
|
+ * @return: void
|
|
|
+ * @Author: liuliu
|
|
|
+ * @Date: 2021/6/1 11:47
|
|
|
+ */
|
|
|
@Override
|
|
|
- public void validCustomerProduct(Integer customerProductId) {
|
|
|
+ public void validCustomerProduct(Long customerProductId) {
|
|
|
CustomerProduct product = CustomerProduct.builder().customerProductId(customerProductId)
|
|
|
.isEffective(0).build();
|
|
|
int count = baseMapper.updateById(product);
|
|
|
- if (count> 0) {
|
|
|
+ if (count > 0) {
|
|
|
log.info("-------------------------------- 客户产品置无效成功,客户产品编号为:【{}】 ----------------------------------", customerProductId);
|
|
|
// TODO 发送消息到客户产品topic
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @Description: TODO 批量修改和删除客户产品对象
|
|
|
- * @Param: [productDtoList]
|
|
|
- * @return: boolean
|
|
|
- * @Author: liuliu
|
|
|
- * @Date: 2021/6/1 12:25
|
|
|
- */
|
|
|
+ * @Description: TODO 批量修改和删除客户产品对象
|
|
|
+ * @Param: [productDtoList]
|
|
|
+ * @return: boolean
|
|
|
+ * @Author: liuliu
|
|
|
+ * @Date: 2021/6/1 12:25
|
|
|
+ */
|
|
|
@Override
|
|
|
public void saveOrUpdate(List<CustomerProductDto> productDtoList) {
|
|
|
|
|
|
- if(!productDtoList.isEmpty()){
|
|
|
+ if (!productDtoList.isEmpty()) {
|
|
|
List<CustomerProduct> productList = Lists.newArrayList();
|
|
|
- productDtoList.forEach(dto->{
|
|
|
+ productDtoList.forEach(dto -> {
|
|
|
+ Long id = null;
|
|
|
+ if (ObjectUtil.isEmpty(dto.getCustomerProductId())) {
|
|
|
+ id = jedisCluster.incr(GLOBAL_ID_INCR.key());
|
|
|
+ } else {
|
|
|
+ id = dto.getCustomerProductId();
|
|
|
+ }
|
|
|
CustomerProduct product = CustomerProduct.builder()
|
|
|
- .customerProductId(dto.getCustomerProductId())
|
|
|
+ .customerProductId(id)
|
|
|
.customerId(dto.getCustomerId())
|
|
|
.packageId(dto.getPackageId())
|
|
|
.type(dto.getType())
|
|
|
.price(Long.parseLong(String.valueOf((dto.getPrice().multiply(new BigDecimal(10000))).intValue())))
|
|
|
.facePrice(Long.parseLong(String.valueOf(dto.getFacePrice().multiply(new BigDecimal(10000)))))
|
|
|
.isEffective(dto.getIsEffective())
|
|
|
- .disCount(dto.getPrice().divide(dto.getFacePrice(),4,BigDecimal.ROUND_DOWN)).build();
|
|
|
+ .disCount(dto.getPrice().divide(dto.getFacePrice(), 4, BigDecimal.ROUND_DOWN)).build();
|
|
|
productList.add(product);
|
|
|
});
|
|
|
-
|
|
|
- boolean flag = this.saveOrUpdateBatch(productList);
|
|
|
- if(flag){
|
|
|
+ int count = baseMapper.customerProductSaveOrUpdate(productList);
|
|
|
+ if (count > 0) {
|
|
|
//TODO 发送消息到topic
|
|
|
-
|
|
|
+ log.info("客户{}产品有变化,发送消息到 topic", productList.get(0).getCustomerId());
|
|
|
+ rocketMQTemplate.send(UPDATE_TOPIC + ":" + CONSUMER_PRODUCT_TAG, MessageBuilder.withPayload(CONSUMER_PRODUCT_TAG).build());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -111,8 +130,8 @@ public class CustomerProductInfoServiceImpl extends ServiceImpl<CustomerProductI
|
|
|
public List<String> getCuProByCustomerId(Long customerId) {
|
|
|
|
|
|
LambdaQueryWrapper<CustomerProduct> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- queryWrapper.select(CustomerProduct::getCustomerProductId,CustomerProduct::getPackageId)
|
|
|
- .eq(CustomerProduct::getCustomerId,customerId);
|
|
|
+ queryWrapper.select(CustomerProduct::getCustomerProductId, CustomerProduct::getPackageId)
|
|
|
+ .eq(CustomerProduct::getCustomerId, customerId);
|
|
|
List<CustomerProduct> productList = baseMapper.selectList(queryWrapper);
|
|
|
return productList.stream().map(CustomerProduct::getPackageId).collect(Collectors.toList());
|
|
|
}
|