|
@@ -0,0 +1,169 @@
|
|
|
+package com.bz.smart_city.service.impl.pay;
|
|
|
+
|
|
|
+import com.bz.smart_city.commom.util.UserUtil;
|
|
|
+import com.bz.smart_city.dao.pay.BaseClosingAccountInfoMapper;
|
|
|
+import com.bz.smart_city.dao.pay.PayChargeSurveyMapper;
|
|
|
+import com.bz.smart_city.dto.LoginUser;
|
|
|
+import com.bz.smart_city.dto.pay.BaseClosingAccountInfoDto;
|
|
|
+import com.bz.smart_city.dto.pay.PayChangePeriodDto;
|
|
|
+import com.bz.smart_city.dto.pay.PayChargeSurveyDto;
|
|
|
+import com.bz.smart_city.entity.pay.PayAccountSurvey;
|
|
|
+import com.bz.smart_city.service.pay.PayChargeSurveyService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.BigInteger;
|
|
|
+import java.text.DecimalFormat;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class PayChargeSurveyServiceImpl implements PayChargeSurveyService {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private PayChargeSurveyMapper payChargeSurveyMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private BaseClosingAccountInfoMapper baseClosingAccountInfoMapper;
|
|
|
+
|
|
|
+
|
|
|
+ public Integer getAccountCount(){
|
|
|
+ return payChargeSurveyMapper.getAccountCount();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ try {
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");//格式化为年月日
|
|
|
+ Calendar startDate = Calendar.getInstance();//起始年月
|
|
|
+ startDate.setTime(sdf.parse("2020-07-01"));
|
|
|
+ startDate.add(Calendar.YEAR, -1); //月份减1;
|
|
|
+ startDate.add(Calendar.MONTH, -1); //月份减1;
|
|
|
+
|
|
|
+ Date lastStartMonth = startDate.getTime(); //结果
|
|
|
+ String lastStart = sdf.format(lastStartMonth);
|
|
|
+ System.out.println("时间:"+lastStart);
|
|
|
+ }catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 客户概况
|
|
|
+ * @return payChargeSurveyDto
|
|
|
+ */
|
|
|
+ public PayChargeSurveyDto accountSurvey(){
|
|
|
+ PayChargeSurveyDto payChargeSurveyDto = new PayChargeSurveyDto();
|
|
|
+ LoginUser loginUser = UserUtil.getCurrentUser();
|
|
|
+ DecimalFormat df = new DecimalFormat("0.0");
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");//格式化为年月日
|
|
|
+ BigInteger siteId = BigInteger.valueOf(loginUser.getSiteId());
|
|
|
+ BigInteger customerId = BigInteger.valueOf(loginUser.getCustomerId());
|
|
|
+ try {
|
|
|
+ //1.获取客户总数跟较上月比率
|
|
|
+ /***********************************时间计算*****************************************/
|
|
|
+ //获取当前账期
|
|
|
+ List<BaseClosingAccountInfoDto> list = baseClosingAccountInfoMapper.getList(null,null,
|
|
|
+ siteId,customerId,null);
|
|
|
+ String startPeriod = list.get(0).getYear()+"-"+String.format("%02d", list.get(0).getMonth())+"-01";
|
|
|
+ String endPeriod = list.get(0).getYear()+"-"+String.format("%02d", list.get(0).getMonth())+"-31";
|
|
|
+
|
|
|
+ //取上一账期时间
|
|
|
+ Calendar startDate = Calendar.getInstance();//起始年月
|
|
|
+ Calendar enddate = Calendar.getInstance();//起始年月
|
|
|
+ startDate.setTime(sdf.parse(startPeriod));
|
|
|
+ startDate.add(Calendar.MONTH, -1); //月份减1;
|
|
|
+ enddate.setTime(sdf.parse(endPeriod));
|
|
|
+ enddate.add(Calendar.MONTH, -1); //月份减1;
|
|
|
+
|
|
|
+ Date lastStartMonth = startDate.getTime(); //结果
|
|
|
+ Date laseEndMonth = enddate.getTime();
|
|
|
+ String lastStart = sdf.format(lastStartMonth);
|
|
|
+ String lastEnd = sdf.format(laseEndMonth);
|
|
|
+ //System.out.println("当前账期:"+period+";上一账期:"+lastPeriod);
|
|
|
+
|
|
|
+ //上一账期汇总
|
|
|
+ PayAccountSurvey accountSurvey = payChargeSurveyMapper.getlastAccount(lastStart,siteId,customerId);
|
|
|
+
|
|
|
+ //客户总数计算
|
|
|
+ //当前账期以内客户总数
|
|
|
+ Integer sumAccount = payChargeSurveyMapper.getAccountNumber(null,endPeriod,siteId,customerId);
|
|
|
+ //当前账期客户总数
|
|
|
+ Integer sumCurrentAccount = payChargeSurveyMapper.getAccountNumber(startPeriod,endPeriod,siteId,customerId);
|
|
|
+ //上一期客户数
|
|
|
+ Integer sumLastAccount = accountSurvey != null && accountSurvey.getAccountNumber() != null ? accountSurvey.getAccountNumber() : 0;
|
|
|
+ //客户总数较上月比率
|
|
|
+ String lastAccountRate = "";
|
|
|
+ float num =(float)((sumCurrentAccount - sumLastAccount)/(sumLastAccount != null && sumLastAccount != 0 ? sumLastAccount : 1)*100);
|
|
|
+ lastAccountRate = df.format(num);
|
|
|
+ //赋值客户总数跟上月比率
|
|
|
+ payChargeSurveyDto.setAccountNumber(sumAccount);
|
|
|
+ payChargeSurveyDto.setLastAccountRate(lastAccountRate);
|
|
|
+
|
|
|
+
|
|
|
+ //水表总数计算
|
|
|
+ //当前账期以内的水表总数
|
|
|
+ Integer sumMeter = payChargeSurveyMapper.getMeterNumber(null,endPeriod,siteId,customerId);
|
|
|
+ //当前账期水表数
|
|
|
+ Integer sumCurrentMeter = payChargeSurveyMapper.getMeterNumber(startPeriod,endPeriod,siteId,customerId);
|
|
|
+ //上一期水表数
|
|
|
+ Integer sumLastMeter = accountSurvey != null && accountSurvey.getMeterNumber() != null ? accountSurvey.getMeterNumber() :0;
|
|
|
+ //水表总数较上月比率
|
|
|
+ String lastMeterRate = "";
|
|
|
+ num =(float)((sumCurrentMeter - sumLastMeter)/(sumLastMeter != null && sumLastMeter != 0 ? sumLastMeter : 1)*100);
|
|
|
+ lastMeterRate = df.format(num);
|
|
|
+ //赋值水表总数跟上月比率
|
|
|
+ payChargeSurveyDto.setMeterNumber(sumMeter);
|
|
|
+ payChargeSurveyDto.setLastMeterRate(lastMeterRate);
|
|
|
+
|
|
|
+
|
|
|
+ //开户总数计算
|
|
|
+ Integer sumCustomer = payChargeSurveyMapper.getCustomerNumber(null,endPeriod,siteId,customerId);
|
|
|
+ //当前账期开户数
|
|
|
+ Integer sumCurrentCustomer = payChargeSurveyMapper.getCustomerNumber(startPeriod,endPeriod,siteId,customerId);
|
|
|
+ //上一账期开户数
|
|
|
+ Integer sumLastCustomer = accountSurvey != null && accountSurvey.getCustomerNumber() != null ? accountSurvey.getCustomerNumber() : 0;
|
|
|
+ //水表总数较上月比率
|
|
|
+ String lastCusstomerRate = "";
|
|
|
+ num =(float)((sumCurrentCustomer - sumLastCustomer)/(sumLastCustomer != null && sumLastCustomer != 0 ? sumLastCustomer : 1)*100);
|
|
|
+ lastCusstomerRate = df.format(num);
|
|
|
+ //赋值开户总数跟上月比率
|
|
|
+ payChargeSurveyDto.setCustomerNumber(sumCustomer);
|
|
|
+ payChargeSurveyDto.setLastCustomerRate(lastCusstomerRate);
|
|
|
+
|
|
|
+
|
|
|
+ //开户率
|
|
|
+ String customerRate = "";
|
|
|
+ num =(float)(sumCurrentCustomer/(sumCurrentMeter != null && sumCurrentMeter != 0 ? sumCurrentMeter : 1)*100);
|
|
|
+ customerRate = df.format(num);
|
|
|
+ payChargeSurveyDto.setCustomerRate(customerRate);
|
|
|
+
|
|
|
+
|
|
|
+ //折线图统计,取最近一年
|
|
|
+ Calendar lately = Calendar.getInstance();//起始年月
|
|
|
+ lately.setTime(sdf.parse(startPeriod));
|
|
|
+ lately.add(Calendar.YEAR, -1); //年份减1;
|
|
|
+ lately.add(Calendar.MONTH, -1); //月份减1;
|
|
|
+ Date latelyDay = lately.getTime(); //结果
|
|
|
+ String latelyDate = sdf.format(latelyDay);
|
|
|
+ List<PayChangePeriodDto> accoutList = payChargeSurveyMapper.getAccountList(startPeriod,latelyDate,siteId,customerId);
|
|
|
+ PayChangePeriodDto periodDto = new PayChangePeriodDto();
|
|
|
+ List<PayChangePeriodDto> accountList2 = new ArrayList<PayChangePeriodDto>();
|
|
|
+ periodDto.setYear(list.get(0).getYear()+"");
|
|
|
+ periodDto.setMonth(list.get(0).getMonth());
|
|
|
+ periodDto.setAccountNumber(sumCurrentAccount);
|
|
|
+ periodDto.setCustomerNumber(sumCurrentCustomer);
|
|
|
+ periodDto.setMeterNumber(sumCurrentMeter);
|
|
|
+ accountList2.add(periodDto);
|
|
|
+ accountList2.addAll(accoutList);
|
|
|
+ payChargeSurveyDto.setList(accountList2);
|
|
|
+ //System.out.println("时间:"+latelyDate);
|
|
|
+ }catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return payChargeSurveyDto;
|
|
|
+ }
|
|
|
+}
|