|
|
@@ -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;
|
|
|
+ }
|
|
|
}
|