Explorar o código

客户管理接口优化;电量核算代码部分提交

fuyuchuan hai 3 días
pai
achega
94f1078e86

+ 26 - 2
service-vpp/service-vpp-biz/src/main/java/com/usky/vpp/controller/web/SettlementController.java

@@ -1,6 +1,8 @@
 package com.usky.vpp.controller.web;
 
 import com.usky.common.core.bean.ApiResult;
+import com.usky.common.core.bean.CommonPage;
+import com.usky.vpp.domain.VppEnergyReadingMonthly;
 import com.usky.vpp.service.VppSettlementService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
@@ -16,34 +18,56 @@ public class SettlementController {
     @Autowired
     private VppSettlementService vppSettlementService;
 
+    /**
+     * 分页查询powermeter数据
+     * <ul>
+     *   <li>id           主键ID 精确匹配</li>
+     *   <li>customerName 客户名称 模糊匹配</li>
+     *   <li>calcCycle    计算周期 模糊匹配</li>
+     *   <li>current      页码</li>
+     *   <li>size         页大小</li>
+     * </ul>
+     */
     @GetMapping(value = "/reading")
-    public ApiResult<Object> pageReading(@RequestParam(required = false) java.util.Map<String, Object> params) {
-        return ApiResult.success(null);
+    public ApiResult<CommonPage<VppEnergyReadingMonthly>> pageReading(
+            @RequestParam(value = "id", required = false) Long id,
+            @RequestParam(value = "customerName", required = false) String customerName,
+            @RequestParam(value = "calcCycle", required = false) String calcCycle,
+            @RequestParam(value = "current", required = false, defaultValue = "1") Integer current,
+            @RequestParam(value = "size", required = false, defaultValue = "20") Integer size) {
+        return ApiResult.success(vppSettlementService.pageReading(id, customerName, calcCycle, current, size));
     }
+
     @PostMapping(value = "/reading/calculate")
     public ApiResult<Void> calculateReading(@RequestBody(required = false) Object body) {
         return ApiResult.success();
     }
+
     @GetMapping(value = "/bill")
     public ApiResult<Object> pageBill(@RequestParam(required = false) java.util.Map<String, Object> params) {
         return ApiResult.success(null);
     }
+
     @PostMapping(value = "/bill")
     public ApiResult<Object> generateBill(@RequestBody(required = false) Object body) {
         return ApiResult.success(null);
     }
+
     @GetMapping(value = "/bill/{id}")
     public ApiResult<Object> getBill(@PathVariable("id") Long id, @RequestParam(required = false) java.util.Map<String, Object> params) {
         return ApiResult.success(null);
     }
+
     @GetMapping(value = "/bill/{id}/download")
     public ApiResult<Object> downloadBill(@PathVariable("id") Long id) {
         return ApiResult.success(null);
     }
+
     @GetMapping(value = "/payment")
     public ApiResult<Object> pagePayment(@RequestParam(required = false) java.util.Map<String, Object> params) {
         return ApiResult.success(null);
     }
+
     @PostMapping(value = "/payment")
     public ApiResult<Object> recordPayment(@RequestBody(required = false) Object body) {
         return ApiResult.success(null);

+ 1 - 0
service-vpp/service-vpp-biz/src/main/java/com/usky/vpp/domain/VppCustomer.java

@@ -104,6 +104,7 @@ public class VppCustomer implements Serializable {
     @TableField("delete_flag")
     private Integer deleteFlag;
     @TableField("deleted_at")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private LocalDateTime deletedAt;
 
     /**

+ 5 - 0
service-vpp/service-vpp-biz/src/main/java/com/usky/vpp/domain/VppEnergyReadingMonthly.java

@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
+
 import java.io.Serializable;
 import java.math.BigDecimal;
 import java.time.LocalDateTime;
@@ -24,6 +25,10 @@ public class VppEnergyReadingMonthly implements Serializable {
     private Long id;
     @TableField("customer_id")
     private Long customerId;
+
+    @TableField(exist = false)
+    private String customerName;
+
     @TableField("resource_id")
     private Long resourceId;
     @TableField("settle_year")

+ 1 - 1
service-vpp/service-vpp-biz/src/main/java/com/usky/vpp/job/VppUnPollScheduler.java

@@ -22,7 +22,7 @@ public class VppUnPollScheduler {
     @Autowired
     private VppUnIntegrationService integrationService;
 
-    @Scheduled(fixedDelayString = "#{${vpp.un.poll-interval-sec:10} * 1000}")
+    //@Scheduled(fixedDelayString = "#{${vpp.un.poll-interval-sec:10} * 1000}")
     public void pollUn() {
         if (!properties.isPollActive()) {
             return;

+ 3 - 0
service-vpp/service-vpp-biz/src/main/java/com/usky/vpp/service/VppSettlementService.java

@@ -1,6 +1,7 @@
 package com.usky.vpp.service;
 
 import com.usky.common.core.bean.CommonPage;
+import com.usky.vpp.domain.VppEnergyReadingMonthly;
 
 import java.util.Map;
 
@@ -12,4 +13,6 @@ public interface VppSettlementService {
     default Object stub(String action, Map<String, Object> params) {
         return null;
     }
+
+    CommonPage<VppEnergyReadingMonthly> pageReading(Long id, String customerName, String calcCycle, Integer current, Integer size);
 }

+ 22 - 22
service-vpp/service-vpp-biz/src/main/java/com/usky/vpp/service/impl/VppCustomerServiceImpl.java

@@ -414,17 +414,8 @@ public class VppCustomerServiceImpl implements VppCustomerService {
             throw new BusinessException("用电容量不能为空!");
         }
 
-        // 同租户下 accountNo 和 customerName 唯一校验
-        Integer tenantId = SecurityUtils.getTenantId();
-        LambdaQueryWrapper<VppCustomer> dupWrapper = new LambdaQueryWrapper<>();
-        dupWrapper.eq(VppCustomer::getTenantId, tenantId)
-                .eq(VppCustomer::getDeleteFlag, VppAuditHelper.NOT_DELETED)
-                .and(w -> w.eq(VppCustomer::getAccountNo, vo.getAccountNo())
-                        .or().eq(VppCustomer::getCustomerName, vo.getCustomerName()));
-        Integer dupCount = customerMapper.selectCount(dupWrapper);
-        if (dupCount != null && dupCount > 0) {
-            throw new BusinessException("同租户下已存在相同电力户号或客户名称的客户!");
-        }
+        // 电力户号全局唯一校验
+        checkAccountNoUnique(vo.getAccountNo(), null);
 
         // 构建客户
         VppCustomer customer = new VppCustomer();
@@ -598,18 +589,13 @@ public class VppCustomerServiceImpl implements VppCustomerService {
         VppCustomer existing = findCustomerById(id);
 
         // 仅更新非空字段
-        if (StringUtils.isNotBlank(vo.getCustomerName())) {
-            if (!vo.getCustomerName().equals(existing.getCustomerName())) {
-                // 校验同租户下客户名称唯一
-                LambdaQueryWrapper<VppCustomer> uniqueWrapper = new LambdaQueryWrapper<>();
-                uniqueWrapper.eq(VppCustomer::getTenantId, SecurityUtils.getTenantId())
-                        .eq(VppCustomer::getCustomerName, vo.getCustomerName())
-                        .eq(VppCustomer::getDeleteFlag, VppAuditHelper.NOT_DELETED);
-                Integer count = customerMapper.selectCount(uniqueWrapper);
-                if (count != null && count > 0) {
-                    throw new BusinessException("客户名称已存在,请更换!");
-                }
+        if (StringUtils.isNotBlank(vo.getAccountNo())) {
+            if (!vo.getAccountNo().equals(existing.getAccountNo())) {
+                checkAccountNoUnique(vo.getAccountNo(), id);
             }
+            existing.setAccountNo(vo.getAccountNo());
+        }
+        if (StringUtils.isNotBlank(vo.getCustomerName())) {
             existing.setCustomerName(vo.getCustomerName());
         }
         if (vo.getCustomerType() != null) {
@@ -1044,6 +1030,20 @@ public class VppCustomerServiceImpl implements VppCustomerService {
         return contact;
     }
 
+    /**
+     * 电力户号全局唯一校验(不限租户)
+     */
+    private void checkAccountNoUnique(String accountNo, Long excludeId) {
+        LambdaQueryWrapper<VppCustomer> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(VppCustomer::getAccountNo, accountNo)
+                .eq(VppCustomer::getDeleteFlag, VppAuditHelper.NOT_DELETED)
+                .ne(excludeId != null, VppCustomer::getId, excludeId);
+        Integer count = customerMapper.selectCount(wrapper);
+        if (count != null && count > 0) {
+            throw new BusinessException("电力户号已存在,请更换!");
+        }
+    }
+
     private void validateAccessRequest(CustomerAccessRequestVO request) {
         if (request == null || StringUtils.isBlank(request.getAccountNo())) {
             throw new BusinessException("电力户号不能为空!");

+ 71 - 0
service-vpp/service-vpp-biz/src/main/java/com/usky/vpp/service/impl/VppSettlementServiceImpl.java

@@ -1,11 +1,82 @@
 package com.usky.vpp.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.usky.common.core.bean.CommonPage;
+import com.usky.common.core.exception.BusinessException;
+import com.usky.common.security.utils.SecurityUtils;
+import com.usky.vpp.domain.VppCustomer;
+import com.usky.vpp.domain.VppEnergyReadingMonthly;
+import com.usky.vpp.mapper.VppCustomerMapper;
+import com.usky.vpp.mapper.VppEnergyReadingMonthlyMapper;
 import com.usky.vpp.service.VppSettlementService;
+import com.usky.vpp.util.VppAuditHelper;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
 /**
  * VppSettlementService 默认实现(待按业务完善)
  */
 @Service
 public class VppSettlementServiceImpl implements VppSettlementService {
+
+    @Autowired
+    private VppCustomerMapper vppCustomerMapper;
+    @Autowired
+    private VppEnergyReadingMonthlyMapper energyReadingMonthlyMapper;
+
+
+    @Override
+    public CommonPage<VppEnergyReadingMonthly> pageReading(Long id, String customerName, String calcCycle, Integer current, Integer size) {
+        IPage<VppEnergyReadingMonthly> page = new Page<>(current, size);
+        Integer tenantId = SecurityUtils.getTenantId();
+
+        LambdaQueryWrapper<VppCustomer> customerQueryWrapper = new LambdaQueryWrapper<VppCustomer>();
+        customerQueryWrapper.eq(VppCustomer::getTenantId, tenantId)
+                .eq(VppCustomer::getDeleteFlag, VppAuditHelper.NOT_DELETED)
+                .like(StringUtils.isNotBlank(customerName), VppCustomer::getCustomerName, customerName);
+        Map<Long, String> customerNameMap = vppCustomerMapper.selectList(customerQueryWrapper)
+                .stream()
+                .collect(Collectors.toMap(VppCustomer::getId, VppCustomer::getCustomerName));
+
+        LambdaQueryWrapper<VppEnergyReadingMonthly> energyReadingQueryWrapper = new LambdaQueryWrapper<VppEnergyReadingMonthly>();
+        energyReadingQueryWrapper.eq(VppEnergyReadingMonthly::getTenantId, tenantId)
+                .eq(VppEnergyReadingMonthly::getDeleteFlag, VppAuditHelper.NOT_DELETED)
+                .eq(id != null, VppEnergyReadingMonthly::getCustomerId, id)
+                .eq(StringUtils.isNotBlank(calcCycle), VppEnergyReadingMonthly::getSettleYear, resolveCalcCycle(calcCycle).get("settleYear"))
+                .eq(StringUtils.isNotBlank(calcCycle), VppEnergyReadingMonthly::getSettleMonth, resolveCalcCycle(calcCycle).get("settleMonth"))
+                .orderByDesc(VppEnergyReadingMonthly::getSettleYear);
+        page = energyReadingMonthlyMapper.selectPage(page, energyReadingQueryWrapper);
+
+        List<VppEnergyReadingMonthly> energyReadingMonthlyList = page.getRecords();
+        energyReadingMonthlyList.forEach(energyReadingMonthly -> {
+            energyReadingMonthly.setCustomerName(customerNameMap.get(energyReadingMonthly.getCustomerId()));
+        });
+
+        return new CommonPage<>(energyReadingMonthlyList, page.getTotal(), size, current);
+    }
+
+    /**
+     * 解析核算周期,年-月
+     * @param calcCycle
+     * @return
+     */
+    private Map<String, Object> resolveCalcCycle(String calcCycle) {
+        Map<String, Object> calcCycleMap = new HashMap<>();
+        String[] split = calcCycle.split("-");
+        try {
+            calcCycleMap.put("settleYear", split[0]);
+            calcCycleMap.put("settleMonth", split[1]);
+        } catch (Exception e) {
+            throw new BusinessException("解析核算周期失败!请核对参数!");
+        }
+        return calcCycleMap;
+    }
 }