Bladeren bron

功能提交:手写 客户产品saveOrUpdate sql,替换以前mybatis-plus 的方法

杨六六 4 jaren geleden
bovenliggende
commit
c59d95d652

+ 1 - 1
common/fire-dto/src/main/java/com/fire/dto/CustomerProduct.java

@@ -29,7 +29,7 @@ public class CustomerProduct {
 
     @ApiModelProperty(value = "主键")
     @TableId(value="customer_product_id",type = IdType.AUTO)
-    private Integer customerProductId;
+    private Long customerProductId;
 
     @ApiModelProperty(value = "客户编号(前端不展示)")
     private Long customerId;

+ 1 - 1
common/fire-dto/src/main/java/com/fire/dto/FlowOrderInfo.java

@@ -92,7 +92,7 @@ public class FlowOrderInfo {
     private Long operatorBalancePrice;
 
     @ApiModelProperty(value = "客户产品id")
-    private Integer customerProductId;
+    private Long customerProductId;
 
     @ApiModelProperty(value = "通道ID")
     private Integer channelId;

+ 1 - 1
modules/admin/src/main/java/com/fire/admin/dto/CustomerProductDto.java

@@ -17,7 +17,7 @@ import java.math.BigInteger;
 @Builder
 public class CustomerProductDto {
 
- private Integer customerProductId;
+ private Long customerProductId;
 
    @ApiModelProperty(value = "客户ID")
     private Long customerId;

+ 16 - 6
modules/admin/src/main/java/com/fire/admin/mapper/CustomerProductInfoMapper.java

@@ -1,9 +1,9 @@
 package com.fire.admin.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.fire.admin.dto.CustomerProductDto;
 import com.fire.admin.vo.CustomerProductInfoVo;
 import com.fire.dto.CustomerProduct;
+import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Repository;
 import java.util.List;
 
@@ -17,12 +17,22 @@ import java.util.List;
 public interface CustomerProductInfoMapper extends BaseMapper<CustomerProduct> {
 
     /***
-    * @Description:  TODO 通过客户编号获取客户的产品信息
-    * @Param:  customerId : 客户编号   type:产品类型 1:话费 2:流量
-    * @return:
+     * @Description: TODO 通过客户编号获取客户的产品信息
+     * @Param: customerId : 客户编号   type:产品类型 1:话费 2:流量
+     * @return:
+     * @Author: liuliu
+     * @Date: 2021/5/20 14:09
+     */
+    List<CustomerProductInfoVo> queryCustomerProductByCustomerId(Long customerId, Integer type);
+
+
+    /**
+    * @Description:  TODO  批量修改或新增
+    * @Param: [customerProductList]
+    * @return: int
     * @Author: liuliu
-    * @Date: 2021/5/20 14:09
+    * @Date: 2021/6/15 19:07
     */
-    List<CustomerProductInfoVo> queryCustomerProductByCustomerId(Integer customerId, Integer type);
+    int customerProductSaveOrUpdate(@Param("list") List<CustomerProduct> customerProductList);
 
 }

+ 3 - 3
modules/admin/src/main/java/com/fire/admin/rest/CustomerProductInfoController.java

@@ -33,21 +33,21 @@ public class CustomerProductInfoController {
 
     @ApiOperation("客户产品详情")
     @GetMapping("/info")
-    public BaseRestResponse getCustomerProductInfo(Integer customerId, Integer type){
+    public BaseRestResponse getCustomerProductInfo(Long customerId, Integer type){
         return new BaseRestResponse<>(customerProductInfoService.getCustomerProductByCustomerId(customerId,type));
     }
 
 
     @ApiOperation(value = "客户产品物理删除")
     @DeleteMapping("/{customerProductId}")
-    public BaseResponse delCustomerProduct(@PathVariable("customerProductId") Integer customerProductId){
+    public BaseResponse delCustomerProduct(@PathVariable("customerProductId") Long customerProductId){
         customerProductInfoService.deleteCustomerProduct(customerProductId);
         return new BaseResponse();
     }
 
     @ApiOperation(value = "客户产品置无效")
     @PutMapping("/{customerProductId}")
-    public BaseResponse makeValidCustomerProduct(@PathVariable("customerProductId" ) Integer customerProductId){
+    public BaseResponse makeValidCustomerProduct(@PathVariable("customerProductId" ) Long customerProductId){
         customerProductInfoService.validCustomerProduct(customerProductId);
         return new BaseResponse();
     }

+ 11 - 2
modules/admin/src/main/java/com/fire/admin/rest/SysUserController.java

@@ -152,8 +152,17 @@ public class SysUserController {
     }
 
 
-
-
+    /**
+    * @Description:  TODO 获取用户属性为客户和中间人的所有用户
+    * @Param:
+    * @return:
+    * @Author: liuliu
+    * @Date: 2021/6/15 16:46
+    */
+    public  BaseRestResponse getTypeAllUser(){
+
+        return new BaseRestResponse();
+    }
 
 }
 

+ 3 - 3
modules/admin/src/main/java/com/fire/admin/service/CustomerProductInfoService.java

@@ -23,7 +23,7 @@ public interface CustomerProductInfoService extends IService<CustomerProduct> {
     * @Author: liuliu
     * @Date: 2021/5/27 12:12
     */
-    List<CustomerProductInfoVo> getCustomerProductByCustomerId(Integer customerId, Integer type);
+    List<CustomerProductInfoVo> getCustomerProductByCustomerId(Long customerId, Integer type);
 
 
     /**
@@ -33,7 +33,7 @@ public interface CustomerProductInfoService extends IService<CustomerProduct> {
     * @Author: liuliu
     * @Date: 2021/6/1 11:02
     */
-    void deleteCustomerProduct(Integer customerProductId);
+    void deleteCustomerProduct(Long customerProductId);
 
     /**
     * @Description:  TODO  把客户单个产品置无效
@@ -42,7 +42,7 @@ public interface CustomerProductInfoService extends IService<CustomerProduct> {
     * @Author: liuliu
     * @Date: 2021/6/1 11:46
     */
-    void validCustomerProduct(Integer customerProductId);
+    void validCustomerProduct(Long customerProductId);
 
     
     /**

+ 47 - 28
modules/admin/src/main/java/com/fire/admin/service/impl/CustomerProductInfoServiceImpl.java

@@ -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());
     }

+ 36 - 0
modules/admin/src/main/resources/mapper/CustomerProductInfoMapper.xml

@@ -59,4 +59,40 @@
     </select>
 
 
+    <insert id="customerProductSaveOrUpdate" parameterType="java.util.List">
+        INSERT INTO
+        customer_product
+        (
+            customer_product_id,
+            customer_id,
+            package_id,
+            type,
+            price,
+            face_price,
+            is_effective,
+            discount
+        )
+        VALUES
+        <foreach collection="list" item="item" index="index" separator=",">
+            (
+            #{item.customerProductId},
+            #{item.customerId},
+            #{item.packageId},
+            #{item.type},
+            #{item.price},
+            #{item.facePrice},
+            #{item.isEffective},
+            #{item.disCount}
+            )
+        </foreach>
+        ON DUPLICATE KEY UPDATE
+        customer_id=VALUES(customer_id),
+        package_id=VALUES(package_id),
+        type=VALUES(type),
+        price=VALUES(price),
+        face_price=VALUES(face_price),
+        is_effective=VALUES(is_effective),
+        discount=VALUES(discount)
+    </insert>
+
 </mapper>