|
|
@@ -0,0 +1,449 @@
|
|
|
+package com.hdkj.lt.bf.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.util.IdUtil;
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.esotericsoftware.minlog.Log;
|
|
|
+import com.hdkj.fhzg.request.AutoTaskQueryPageRequest;
|
|
|
+import com.hdkj.fhzg.request.AutoTaskQueryRequest;
|
|
|
+import com.hdkj.fhzg.response.*;
|
|
|
+import com.hdkj.hussar.ApiResponse;
|
|
|
+import com.hdkj.lt.base.exception.BusinessException;
|
|
|
+import com.hdkj.lt.bf.entity.FhzgAutoTaskCountryInfo;
|
|
|
+import com.hdkj.lt.bf.entity.FhzgAutoTaskFeederChange;
|
|
|
+import com.hdkj.lt.bf.entity.FhzgAutoTaskPlan;
|
|
|
+import com.hdkj.lt.bf.entity.FhzgAutoTaskPlanDetail;
|
|
|
+import com.hdkj.lt.bf.service.*;
|
|
|
+import com.hdkj.lt.core.bizms.modle.po.DwdShbDsFeederBase;
|
|
|
+import com.hdkj.lt.feign.IPlanCreateClient;
|
|
|
+import com.hdkj.lt.modle.dto.plan.AcceptPlanPowerCutListRequest;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.http.HttpHeaders;
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.net.URLEncoder;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.temporal.TemporalAdjusters;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author rj
|
|
|
+ * @date 2026/3/10 16:04
|
|
|
+ * @description
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+@RequiredArgsConstructor
|
|
|
+public class AutoTaskServiceImpl implements AutoTaskService {
|
|
|
+
|
|
|
+ private final FhzgAutoTaskPlanService autoTaskPlanService;
|
|
|
+
|
|
|
+ private final FhzgAutoTaskCountryInfoService autoTaskCountryInfoService;
|
|
|
+
|
|
|
+ private final FhzgAutoTaskPlanDetailService autoTaskPlanDetailService;
|
|
|
+
|
|
|
+ private final FhzgAutoTaskFeederChangeService autoTaskFeederChangeService;
|
|
|
+
|
|
|
+ private final IPlanCreateClient planCreateClient;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<AutoTaskFeederResponse> getCountryStatistic(AutoTaskQueryRequest request) {
|
|
|
+ LambdaQueryWrapper<FhzgAutoTaskCountryInfo> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+
|
|
|
+ queryWrapper.eq(StringUtils.isNotBlank(request.getCityCode()), FhzgAutoTaskCountryInfo::getCityCode, request.getCityCode());
|
|
|
+ queryWrapper.eq(StringUtils.isNotBlank(request.getCountryCode()), FhzgAutoTaskCountryInfo::getCountryCode, request.getCountryCode());
|
|
|
+ LocalDate startTime = LocalDate.now().with(TemporalAdjusters.firstDayOfMonth());
|
|
|
+ LocalDate endTime = LocalDate.now().with(TemporalAdjusters.lastDayOfMonth());
|
|
|
+ queryWrapper.between(FhzgAutoTaskCountryInfo::getUpdateTime, startTime, endTime);
|
|
|
+ List<FhzgAutoTaskCountryInfo> list = autoTaskCountryInfoService.list(queryWrapper);
|
|
|
+ List<AutoTaskFeederResponse> responseList = new ArrayList<>();
|
|
|
+ for (FhzgAutoTaskCountryInfo fhzgAutoTaskCountryInfo : list) {
|
|
|
+ AutoTaskFeederResponse response = new AutoTaskFeederResponse();
|
|
|
+ response.setCountryName(fhzgAutoTaskCountryInfo.getCountryName());
|
|
|
+ response.setCountryCode(fhzgAutoTaskCountryInfo.getCountryCode());
|
|
|
+ response.setFeederTotal(fhzgAutoTaskCountryInfo.getFeederTotal());
|
|
|
+ response.setContactFeederTotal(fhzgAutoTaskCountryInfo.getContactFeederTotal());
|
|
|
+ AutoTaskQueryRequest request1 = new AutoTaskQueryRequest();
|
|
|
+ request1.setCountryCode(fhzgAutoTaskCountryInfo.getCountryCode());
|
|
|
+ List<AutoTaskFeederChangeResponse> countryFeederChangeList = this.getCountryFeederChangeList(request1);
|
|
|
+ response.setFeederTotalAdd((int) countryFeederChangeList.stream().filter(i -> i.getType() == 1).count());
|
|
|
+ response.setFeederTotalDelete((int) countryFeederChangeList.stream().filter(i -> i.getType() == 0).count());
|
|
|
+ response.setContactFeederTotalAdd((int) countryFeederChangeList.stream().filter(i -> i.getHaveContact() == 1 && i.getType() == 1).count());
|
|
|
+ response.setContactFeederTotalDelete((int) countryFeederChangeList.stream().filter(i -> i.getHaveContact() == 1 && i.getType() == 0).count());
|
|
|
+ responseList.add(response);
|
|
|
+ }
|
|
|
+ return responseList;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<AutoTaskFeederChangeResponse> getCountryFeederChangeList(AutoTaskQueryRequest request) {
|
|
|
+ LambdaQueryWrapper<FhzgAutoTaskFeederChange> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(StringUtils.isNotBlank(request.getCityCode()), FhzgAutoTaskFeederChange::getCityCode, request.getCityCode());
|
|
|
+ queryWrapper.eq(StringUtils.isNotBlank(request.getCountryCode()), FhzgAutoTaskFeederChange::getCountryCode, request.getCountryCode());
|
|
|
+ queryWrapper.eq(request.getFeederType() != null && request.getFeederType() == 2, FhzgAutoTaskFeederChange::getType, 1);
|
|
|
+ LocalDate startTime = LocalDate.now().with(TemporalAdjusters.firstDayOfMonth());
|
|
|
+ LocalDate endTime = LocalDate.now().with(TemporalAdjusters.lastDayOfMonth());
|
|
|
+ queryWrapper.between(FhzgAutoTaskFeederChange::getCreateTime, startTime, endTime);
|
|
|
+ List<FhzgAutoTaskFeederChange> list = autoTaskFeederChangeService.list(queryWrapper);
|
|
|
+ List<AutoTaskFeederChangeResponse> result = new ArrayList<>();
|
|
|
+ for (FhzgAutoTaskFeederChange fhzgAutoTaskFeederChange : list) {
|
|
|
+ AutoTaskFeederChangeResponse response = new AutoTaskFeederChangeResponse();
|
|
|
+ response.setFeederId(fhzgAutoTaskFeederChange.getFeederId());
|
|
|
+ response.setFeederName(fhzgAutoTaskFeederChange.getFeederName());
|
|
|
+ response.setType(fhzgAutoTaskFeederChange.getType());
|
|
|
+ response.setHaveContact(fhzgAutoTaskFeederChange.getIsHavaContact());
|
|
|
+ result.add(response);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<AutoTaskCityDetailResponse> getCityDetailList(AutoTaskQueryRequest request) {
|
|
|
+ LambdaQueryWrapper<FhzgAutoTaskCountryInfo> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(StringUtils.isNotBlank(request.getCityCode()), FhzgAutoTaskCountryInfo::getCityCode, request.getCityCode());
|
|
|
+ queryWrapper.eq(StringUtils.isNotBlank(request.getCountryCode()), FhzgAutoTaskCountryInfo::getCountryCode, request.getCountryCode());
|
|
|
+ queryWrapper.orderByAsc(FhzgAutoTaskCountryInfo::getSimulationSuccessRate);
|
|
|
+ LocalDate startTime = LocalDate.now().with(TemporalAdjusters.firstDayOfMonth());
|
|
|
+ LocalDate endTime = LocalDate.now().with(TemporalAdjusters.lastDayOfMonth());
|
|
|
+ queryWrapper.between(FhzgAutoTaskCountryInfo::getUpdateTime, startTime, endTime);
|
|
|
+ List<FhzgAutoTaskCountryInfo> list = autoTaskCountryInfoService.list(queryWrapper);
|
|
|
+ List<AutoTaskCityDetailResponse> responseList = new ArrayList<>();
|
|
|
+ for (FhzgAutoTaskCountryInfo fhzgAutoTaskCountryInfo : list) {
|
|
|
+ AutoTaskCityDetailResponse response = new AutoTaskCityDetailResponse();
|
|
|
+ response.setCountryName(fhzgAutoTaskCountryInfo.getCountryName());
|
|
|
+ response.setFeederTotal(fhzgAutoTaskCountryInfo.getFeederTotal());
|
|
|
+ response.setContactFeederTotal(fhzgAutoTaskCountryInfo.getContactFeederTotal());
|
|
|
+ response.setSimulationSuccess(fhzgAutoTaskCountryInfo.getSimulationSuccessRate());
|
|
|
+ response.setSimulationSuccessRate(fhzgAutoTaskCountryInfo.getSimulationSuccessRate());
|
|
|
+ response.setSchemeSuccess(fhzgAutoTaskCountryInfo.getSimulationSuccessRate());
|
|
|
+ response.setSchemeSuccessRate(fhzgAutoTaskCountryInfo.getSimulationSuccessRate());
|
|
|
+ response.setSvgSuccess(fhzgAutoTaskCountryInfo.getSimulationSuccessRate());
|
|
|
+ response.setSvgSuccessRate(fhzgAutoTaskCountryInfo.getSimulationSuccessRate());
|
|
|
+ responseList.add(response);
|
|
|
+ }
|
|
|
+ return responseList;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<AutoTaskCountryDetailResponse> getCountryDetailList(AutoTaskQueryRequest request) {
|
|
|
+ LambdaQueryWrapper<FhzgAutoTaskPlanDetail> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(StringUtils.isNotBlank(request.getCountryCode()), FhzgAutoTaskPlanDetail::getCountryCode, request.getCountryCode());
|
|
|
+ LocalDate startTime = LocalDate.now().with(TemporalAdjusters.firstDayOfMonth());
|
|
|
+ LocalDate endTime = LocalDate.now().with(TemporalAdjusters.lastDayOfMonth());
|
|
|
+ queryWrapper.between(FhzgAutoTaskPlanDetail::getCreateTime, startTime, endTime);
|
|
|
+ queryWrapper.orderByAsc(FhzgAutoTaskPlanDetail::getIsHaveContact);
|
|
|
+ queryWrapper.orderByAsc(FhzgAutoTaskPlanDetail::getIsSimulationSuccess);
|
|
|
+ queryWrapper.orderByAsc(FhzgAutoTaskPlanDetail::getIsSchemeSuccess);
|
|
|
+ queryWrapper.orderByAsc(FhzgAutoTaskPlanDetail::getIsSvgSuccess);
|
|
|
+ List<FhzgAutoTaskPlanDetail> list = autoTaskPlanDetailService.list(queryWrapper);
|
|
|
+ List<AutoTaskCountryDetailResponse> result = new ArrayList<>();
|
|
|
+ for (FhzgAutoTaskPlanDetail fhzgAutoTaskPlanDetail : list) {
|
|
|
+ AutoTaskCountryDetailResponse response = new AutoTaskCountryDetailResponse();
|
|
|
+ response.setFeederId(fhzgAutoTaskPlanDetail.getFeederId());
|
|
|
+ response.setFeederName(fhzgAutoTaskPlanDetail.getFeederName());
|
|
|
+ response.setCountryName(fhzgAutoTaskPlanDetail.getCountryName());
|
|
|
+ response.setPlanNo(fhzgAutoTaskPlanDetail.getPlanNo());
|
|
|
+ response.setCreateTime(fhzgAutoTaskPlanDetail.getCreateTime());
|
|
|
+ response.setHaveContact(fhzgAutoTaskPlanDetail.getIsHaveContact());
|
|
|
+ response.setSimulationSuccess(fhzgAutoTaskPlanDetail.getIsSimulationSuccess());
|
|
|
+ response.setSchemeSuccess(fhzgAutoTaskPlanDetail.getIsSchemeSuccess());
|
|
|
+ response.setSvgSuccess(fhzgAutoTaskPlanDetail.getIsSvgSuccess());
|
|
|
+ result.add(response);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<AutoTaskChartResponse> getCountryDetailChart(AutoTaskQueryRequest request) {
|
|
|
+ LambdaQueryWrapper<FhzgAutoTaskCountryInfo> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(StringUtils.isNotBlank(request.getCountryCode()), FhzgAutoTaskCountryInfo::getCountryCode, request.getCountryCode());
|
|
|
+ if (request.getStartDate() == null || request.getEndDate() == null) {
|
|
|
+ //如果没传时间就默认返回最近6个月的数据
|
|
|
+ LocalDate startTime = LocalDate.now().minusMonths(6).withDayOfMonth(1);
|
|
|
+ LocalDate endTime = LocalDate.now().with(TemporalAdjusters.lastDayOfMonth());
|
|
|
+ queryWrapper.between(FhzgAutoTaskCountryInfo::getUpdateTime, startTime, endTime);
|
|
|
+ } else {
|
|
|
+ LocalDate startTime = request.getStartDate().atDay(1);
|
|
|
+ LocalDate endTime = request.getEndDate().atEndOfMonth();
|
|
|
+ queryWrapper.between(FhzgAutoTaskCountryInfo::getUpdateTime, startTime, endTime);
|
|
|
+ }
|
|
|
+
|
|
|
+ queryWrapper.orderByAsc(FhzgAutoTaskCountryInfo::getUpdateTime);
|
|
|
+ List<FhzgAutoTaskCountryInfo> list = autoTaskCountryInfoService.list(queryWrapper);
|
|
|
+ List<AutoTaskChartResponse> responseList = new ArrayList<>();
|
|
|
+ for (FhzgAutoTaskCountryInfo fhzgAutoTaskCountryInfo : list) {
|
|
|
+ AutoTaskChartResponse response = new AutoTaskChartResponse();
|
|
|
+ response.setKey(fhzgAutoTaskCountryInfo.getUpdateTime().getYear() + "年" +
|
|
|
+ fhzgAutoTaskCountryInfo.getUpdateTime().getMonth().getValue() + "月");
|
|
|
+ if (request.getChartType() == 1) {
|
|
|
+ response.setValue(String.valueOf(fhzgAutoTaskCountryInfo.getSimulationSuccessRate()));
|
|
|
+ } else if (request.getChartType() == 2) {
|
|
|
+ response.setValue(String.valueOf(fhzgAutoTaskCountryInfo.getSchemeSuccessRate()));
|
|
|
+ } else if (request.getChartType() == 3) {
|
|
|
+ response.setValue(String.valueOf(fhzgAutoTaskCountryInfo.getSvgSuccessRate()));
|
|
|
+ }
|
|
|
+ responseList.add(response);
|
|
|
+ }
|
|
|
+ return responseList;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<AutoTaskChartResponse> getCityDetailChart(AutoTaskQueryRequest request) {
|
|
|
+ LambdaQueryWrapper<FhzgAutoTaskCountryInfo> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(StringUtils.isNotBlank(request.getCityCode()), FhzgAutoTaskCountryInfo::getCityCode, request.getCityCode());
|
|
|
+ queryWrapper.eq(StringUtils.isNotBlank(request.getCountryCode()), FhzgAutoTaskCountryInfo::getCountryCode, request.getCountryCode());
|
|
|
+ LocalDate startTime = LocalDate.now().with(TemporalAdjusters.firstDayOfMonth());
|
|
|
+ LocalDate endTime = LocalDate.now().with(TemporalAdjusters.lastDayOfMonth());
|
|
|
+ queryWrapper.between(FhzgAutoTaskCountryInfo::getUpdateTime, startTime, endTime);
|
|
|
+ List<FhzgAutoTaskCountryInfo> list = autoTaskCountryInfoService.list(queryWrapper);
|
|
|
+ List<AutoTaskChartResponse> responseList = new ArrayList<>();
|
|
|
+ for (FhzgAutoTaskCountryInfo fhzgAutoTaskCountryInfo : list) {
|
|
|
+ AutoTaskChartResponse response = new AutoTaskChartResponse();
|
|
|
+ response.setKey(fhzgAutoTaskCountryInfo.getCountryName());
|
|
|
+ if (request.getChartType() == 1) {
|
|
|
+ response.setValue(String.valueOf(fhzgAutoTaskCountryInfo.getSimulationSuccessRate()));
|
|
|
+ } else if (request.getChartType() == 2) {
|
|
|
+ response.setValue(String.valueOf(fhzgAutoTaskCountryInfo.getSchemeSuccessRate()));
|
|
|
+ } else if (request.getChartType() == 3) {
|
|
|
+ response.setValue(String.valueOf(fhzgAutoTaskCountryInfo.getSvgSuccessRate()));
|
|
|
+ }
|
|
|
+ responseList.add(response);
|
|
|
+ }
|
|
|
+ return responseList;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public com.hdkj.fhzg.entity.Page<AutoTaskCityDetailResponse> getCityDetailPage(AutoTaskQueryPageRequest request) {
|
|
|
+ LambdaQueryWrapper<FhzgAutoTaskCountryInfo> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(StringUtils.isNotBlank(request.getCityCode()), FhzgAutoTaskCountryInfo::getCityCode, request.getCityCode());
|
|
|
+ LocalDate startTime = LocalDate.now().with(TemporalAdjusters.firstDayOfMonth());
|
|
|
+ LocalDate endTime = LocalDate.now().with(TemporalAdjusters.lastDayOfMonth());
|
|
|
+ queryWrapper.between(FhzgAutoTaskCountryInfo::getUpdateTime, startTime, endTime);
|
|
|
+ queryWrapper.orderByAsc(FhzgAutoTaskCountryInfo::getSimulationSuccessRate);
|
|
|
+ Page<FhzgAutoTaskCountryInfo> page = new Page<>();
|
|
|
+ page.setCurrent(request.getCurrent());
|
|
|
+ page.setSize(request.getSize());
|
|
|
+ Page<FhzgAutoTaskCountryInfo> pageResult = autoTaskCountryInfoService.page(page, queryWrapper);
|
|
|
+ List<AutoTaskCityDetailResponse> responseList = new ArrayList<>();
|
|
|
+ for (FhzgAutoTaskCountryInfo fhzgAutoTaskCountryInfo : pageResult.getRecords()) {
|
|
|
+ AutoTaskCityDetailResponse response = new AutoTaskCityDetailResponse();
|
|
|
+ response.setCountryName(fhzgAutoTaskCountryInfo.getCountryName());
|
|
|
+ response.setFeederTotal(fhzgAutoTaskCountryInfo.getFeederTotal());
|
|
|
+ response.setContactFeederTotal(fhzgAutoTaskCountryInfo.getContactFeederTotal());
|
|
|
+ response.setSimulationSuccess(fhzgAutoTaskCountryInfo.getSimulationSuccessRate());
|
|
|
+ response.setSimulationSuccessRate(fhzgAutoTaskCountryInfo.getSimulationSuccessRate());
|
|
|
+ response.setSchemeSuccess(fhzgAutoTaskCountryInfo.getSimulationSuccessRate());
|
|
|
+ response.setSchemeSuccessRate(fhzgAutoTaskCountryInfo.getSimulationSuccessRate());
|
|
|
+ response.setSvgSuccess(fhzgAutoTaskCountryInfo.getSimulationSuccessRate());
|
|
|
+ response.setSvgSuccessRate(fhzgAutoTaskCountryInfo.getSimulationSuccessRate());
|
|
|
+ responseList.add(response);
|
|
|
+ }
|
|
|
+ com.hdkj.fhzg.entity.Page<AutoTaskCityDetailResponse> result = new com.hdkj.fhzg.entity.Page<>();
|
|
|
+ result.setCurrent(page.getCurrent());
|
|
|
+ result.setSize(page.getSize());
|
|
|
+ result.setRecords(responseList);
|
|
|
+ result.setTotal(pageResult.getTotal());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public com.hdkj.fhzg.entity.Page<AutoTaskCountryDetailResponse> getCountryDetailPage(AutoTaskQueryPageRequest request) {
|
|
|
+ LambdaQueryWrapper<FhzgAutoTaskPlanDetail> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(StringUtils.isNotBlank(request.getCountryCode()), FhzgAutoTaskPlanDetail::getCountryCode, request.getCountryCode());
|
|
|
+ queryWrapper.eq(StringUtils.isNotBlank(request.getFeederId()), FhzgAutoTaskPlanDetail::getFeederId, request.getFeederId());
|
|
|
+ queryWrapper.eq(StringUtils.isNotBlank(request.getPlanNo()), FhzgAutoTaskPlanDetail::getPlanNo, request.getPlanNo());
|
|
|
+ queryWrapper.like(StringUtils.isNotBlank(request.getFeederName()), FhzgAutoTaskPlanDetail::getFeederName, request.getFeederName());
|
|
|
+ queryWrapper.between(FhzgAutoTaskPlanDetail::getCreateTime, request.getStartTime(), request.getEndTime());
|
|
|
+ queryWrapper.orderByAsc(FhzgAutoTaskPlanDetail::getIsHaveContact);
|
|
|
+ queryWrapper.orderByAsc(FhzgAutoTaskPlanDetail::getIsSimulationSuccess);
|
|
|
+ queryWrapper.orderByAsc(FhzgAutoTaskPlanDetail::getIsSchemeSuccess);
|
|
|
+ queryWrapper.orderByAsc(FhzgAutoTaskPlanDetail::getIsSvgSuccess);
|
|
|
+ Page<FhzgAutoTaskPlanDetail> page = new Page<>();
|
|
|
+ page.setCurrent(request.getCurrent());
|
|
|
+ page.setSize(request.getSize());
|
|
|
+ Page<FhzgAutoTaskPlanDetail> pageResult = autoTaskPlanDetailService.page(page, queryWrapper);
|
|
|
+ List<AutoTaskCountryDetailResponse> responseList = new ArrayList<>();
|
|
|
+ for (FhzgAutoTaskPlanDetail fhzgAutoTaskPlanDetail : pageResult.getRecords()) {
|
|
|
+ AutoTaskCountryDetailResponse response = new AutoTaskCountryDetailResponse();
|
|
|
+ response.setFeederId(fhzgAutoTaskPlanDetail.getFeederId());
|
|
|
+ response.setFeederName(fhzgAutoTaskPlanDetail.getFeederName());
|
|
|
+ response.setCountryName(fhzgAutoTaskPlanDetail.getCountryName());
|
|
|
+ response.setPlanNo(fhzgAutoTaskPlanDetail.getPlanNo());
|
|
|
+ response.setCreateTime(fhzgAutoTaskPlanDetail.getCreateTime());
|
|
|
+ response.setHaveContact(fhzgAutoTaskPlanDetail.getIsHaveContact());
|
|
|
+ response.setSimulationSuccess(fhzgAutoTaskPlanDetail.getIsSimulationSuccess());
|
|
|
+ response.setSchemeSuccess(fhzgAutoTaskPlanDetail.getIsSchemeSuccess());
|
|
|
+ response.setSvgSuccess(fhzgAutoTaskPlanDetail.getIsSvgSuccess());
|
|
|
+ responseList.add(response);
|
|
|
+ }
|
|
|
+ com.hdkj.fhzg.entity.Page<AutoTaskCountryDetailResponse> result = new com.hdkj.fhzg.entity.Page<>();
|
|
|
+ result.setCurrent(page.getCurrent());
|
|
|
+ result.setSize(page.getSize());
|
|
|
+ result.setRecords(responseList);
|
|
|
+ result.setTotal(pageResult.getTotal());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void export(AutoTaskQueryPageRequest request, HttpServletResponse response) {
|
|
|
+ if (!StringUtils.isEmpty(request.getCityCode())) {
|
|
|
+ //导出地市统计数据
|
|
|
+ LambdaQueryWrapper<FhzgAutoTaskCountryInfo> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(StringUtils.isNotBlank(request.getCityCode()), FhzgAutoTaskCountryInfo::getCityCode, request.getCityCode());
|
|
|
+ LocalDate startTime = LocalDate.now().with(TemporalAdjusters.firstDayOfMonth());
|
|
|
+ LocalDate endTime = LocalDate.now().with(TemporalAdjusters.lastDayOfMonth());
|
|
|
+ queryWrapper.between(FhzgAutoTaskCountryInfo::getUpdateTime, startTime, endTime);
|
|
|
+ queryWrapper.orderByAsc(FhzgAutoTaskCountryInfo::getSimulationSuccessRate);
|
|
|
+ List<FhzgAutoTaskCountryInfo> countryInfoList = autoTaskCountryInfoService.list(queryWrapper);
|
|
|
+ List<AutoTaskCityDetailResponse> responseList = new ArrayList<>();
|
|
|
+ for (FhzgAutoTaskCountryInfo fhzgAutoTaskCountryInfo : countryInfoList) {
|
|
|
+ AutoTaskCityDetailResponse cityDetailResponse = new AutoTaskCityDetailResponse();
|
|
|
+ cityDetailResponse.setCountryName(fhzgAutoTaskCountryInfo.getCountryName());
|
|
|
+ cityDetailResponse.setFeederTotal(fhzgAutoTaskCountryInfo.getFeederTotal());
|
|
|
+ cityDetailResponse.setContactFeederTotal(fhzgAutoTaskCountryInfo.getContactFeederTotal());
|
|
|
+ cityDetailResponse.setSimulationSuccess(fhzgAutoTaskCountryInfo.getSimulationSuccessRate());
|
|
|
+ cityDetailResponse.setSimulationSuccessRate(fhzgAutoTaskCountryInfo.getSimulationSuccessRate());
|
|
|
+ cityDetailResponse.setSchemeSuccess(fhzgAutoTaskCountryInfo.getSimulationSuccessRate());
|
|
|
+ cityDetailResponse.setSchemeSuccessRate(fhzgAutoTaskCountryInfo.getSimulationSuccessRate());
|
|
|
+ cityDetailResponse.setSvgSuccess(fhzgAutoTaskCountryInfo.getSimulationSuccessRate());
|
|
|
+ cityDetailResponse.setSvgSuccessRate(fhzgAutoTaskCountryInfo.getSimulationSuccessRate());
|
|
|
+ responseList.add(cityDetailResponse);
|
|
|
+ }
|
|
|
+ String cityName = "";
|
|
|
+ if (!countryInfoList.isEmpty()) {
|
|
|
+ cityName = countryInfoList.get(0).getCityName();
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ response.setContentType("application/vnd.ms-excel");
|
|
|
+ response.setCharacterEncoding("UTF-8");
|
|
|
+ String fileName = cityName + "导出.xlsx";
|
|
|
+ response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + URLEncoder.encode(fileName, "utf-8"));
|
|
|
+ EasyExcel.write(response.getOutputStream(), AutoTaskCityDetailResponse.class)
|
|
|
+ .sheet()
|
|
|
+ .doWrite(responseList);
|
|
|
+ } catch (Exception e) {
|
|
|
+ Log.error("导出地市统计数据失败", e);
|
|
|
+ throw new BusinessException("导出失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ } else if (!StringUtils.isEmpty(request.getCountryCode())) {
|
|
|
+ //导出区县数据
|
|
|
+ LambdaQueryWrapper<FhzgAutoTaskPlanDetail> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(StringUtils.isNotBlank(request.getCountryCode()), FhzgAutoTaskPlanDetail::getCountryCode, request.getCountryCode());
|
|
|
+ queryWrapper.eq(StringUtils.isNotBlank(request.getFeederId()), FhzgAutoTaskPlanDetail::getFeederId, request.getFeederId());
|
|
|
+ queryWrapper.eq(StringUtils.isNotBlank(request.getPlanNo()), FhzgAutoTaskPlanDetail::getPlanNo, request.getPlanNo());
|
|
|
+ queryWrapper.like(StringUtils.isNotBlank(request.getFeederName()), FhzgAutoTaskPlanDetail::getFeederName, request.getFeederName());
|
|
|
+ queryWrapper.between(FhzgAutoTaskPlanDetail::getCreateTime, request.getStartTime(), request.getEndTime());
|
|
|
+ queryWrapper.orderByAsc(FhzgAutoTaskPlanDetail::getIsHaveContact);
|
|
|
+ queryWrapper.orderByAsc(FhzgAutoTaskPlanDetail::getIsSimulationSuccess);
|
|
|
+ queryWrapper.orderByAsc(FhzgAutoTaskPlanDetail::getIsSchemeSuccess);
|
|
|
+ queryWrapper.orderByAsc(FhzgAutoTaskPlanDetail::getIsSvgSuccess);
|
|
|
+ List<FhzgAutoTaskPlanDetail> detailList = autoTaskPlanDetailService.list(queryWrapper);
|
|
|
+ List<AutoTaskCountryDetailResponse> responseList = new ArrayList<>();
|
|
|
+ for (FhzgAutoTaskPlanDetail fhzgAutoTaskPlanDetail : detailList) {
|
|
|
+ AutoTaskCountryDetailResponse detailResponse = new AutoTaskCountryDetailResponse();
|
|
|
+ detailResponse.setFeederId(fhzgAutoTaskPlanDetail.getFeederId());
|
|
|
+ detailResponse.setFeederName(fhzgAutoTaskPlanDetail.getFeederName());
|
|
|
+ detailResponse.setCountryName(fhzgAutoTaskPlanDetail.getCountryName());
|
|
|
+ detailResponse.setPlanNo(fhzgAutoTaskPlanDetail.getPlanNo());
|
|
|
+ detailResponse.setCreateTime(fhzgAutoTaskPlanDetail.getCreateTime());
|
|
|
+ detailResponse.setHaveContact(fhzgAutoTaskPlanDetail.getIsHaveContact());
|
|
|
+ detailResponse.setSimulationSuccess(fhzgAutoTaskPlanDetail.getIsSimulationSuccess());
|
|
|
+ detailResponse.setSchemeSuccess(fhzgAutoTaskPlanDetail.getIsSchemeSuccess());
|
|
|
+ detailResponse.setSvgSuccess(fhzgAutoTaskPlanDetail.getIsSvgSuccess());
|
|
|
+ responseList.add(detailResponse);
|
|
|
+ }
|
|
|
+ String countryName = "";
|
|
|
+ if (!responseList.isEmpty()) {
|
|
|
+ countryName = responseList.get(0).getCountryName();
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ response.setContentType("application/vnd.ms-excel");
|
|
|
+ response.setCharacterEncoding("UTF-8");
|
|
|
+ String fileName = countryName + "导出.xlsx";
|
|
|
+ response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + URLEncoder.encode(fileName, "utf-8"));
|
|
|
+ EasyExcel.write(response.getOutputStream(), AutoTaskCountryDetailResponse.class)
|
|
|
+ .sheet()
|
|
|
+ .doWrite(responseList);
|
|
|
+ } catch (Exception e) {
|
|
|
+ Log.error("导出地市统计数据失败", e);
|
|
|
+ throw new BusinessException("导出失败");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new BusinessException("地市编码为空");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public String createTask(String cityCode) {
|
|
|
+ //1.查询是否有对应的计划
|
|
|
+ LocalDate startTime = LocalDate.now().with(TemporalAdjusters.firstDayOfMonth());
|
|
|
+ LocalDate endTime = LocalDate.now().with(TemporalAdjusters.lastDayOfMonth());
|
|
|
+ LambdaQueryWrapper<FhzgAutoTaskPlan> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(FhzgAutoTaskPlan::getCityCode, cityCode);
|
|
|
+ queryWrapper.between(FhzgAutoTaskPlan::getCreateTime, startTime, endTime);
|
|
|
+ List<FhzgAutoTaskPlan> list = autoTaskPlanService.list(queryWrapper);
|
|
|
+ if (list.isEmpty()) {
|
|
|
+ long snowflakeNextId = IdUtil.getSnowflakeNextId();
|
|
|
+ FhzgAutoTaskPlan fhzgAutoTaskPlan = new FhzgAutoTaskPlan();
|
|
|
+ fhzgAutoTaskPlan.setId(snowflakeNextId);
|
|
|
+ fhzgAutoTaskPlan.setCityCode(cityCode);
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ fhzgAutoTaskPlan.setCreateTime(now);
|
|
|
+ autoTaskPlanService.save(fhzgAutoTaskPlan);
|
|
|
+ //查询对应地市的线路
|
|
|
+ List<String> contactFeederList = autoTaskPlanService.getContactFeederList(cityCode);
|
|
|
+ List<String> haveStartKgFeederList = autoTaskPlanService.getHaveStartKgFeederList(cityCode);
|
|
|
+ List<DwdShbDsFeederBase> feederBaseList = autoTaskPlanService.getFeederInfoByCityCode(cityCode);
|
|
|
+ Map<String, DwdShbDsFeederBase> feederSwitchBaseMap = feederBaseList.stream().collect(Collectors.toMap(DwdShbDsFeederBase::getPsrId, i -> i));
|
|
|
+
|
|
|
+ Set<String> haveStartKgAndContactFeederSet = new HashSet<>(haveStartKgFeederList);
|
|
|
+ haveStartKgAndContactFeederSet.addAll(contactFeederList);
|
|
|
+ List<FhzgAutoTaskPlanDetail> detailList = new ArrayList<>();
|
|
|
+ haveStartKgAndContactFeederSet.forEach(i -> {
|
|
|
+ DwdShbDsFeederBase dwdShbDsFeederBase = feederSwitchBaseMap.get(i);
|
|
|
+ FhzgAutoTaskPlanDetail fhzgAutoTaskPlanDetail = new FhzgAutoTaskPlanDetail();
|
|
|
+ fhzgAutoTaskPlanDetail.setTaskId(snowflakeNextId);
|
|
|
+ fhzgAutoTaskPlanDetail.setFeederId(i);
|
|
|
+ fhzgAutoTaskPlanDetail.setFeederName(dwdShbDsFeederBase.getName());
|
|
|
+ fhzgAutoTaskPlanDetail.setCityCode(dwdShbDsFeederBase.getCity());
|
|
|
+ fhzgAutoTaskPlanDetail.setCityName(dwdShbDsFeederBase.getCityName());
|
|
|
+ fhzgAutoTaskPlanDetail.setCountryCode(dwdShbDsFeederBase.getMaintOrg());
|
|
|
+ fhzgAutoTaskPlanDetail.setCountryName(dwdShbDsFeederBase.getMaintOrgName());
|
|
|
+ fhzgAutoTaskPlanDetail.setIsHaveContact(1);
|
|
|
+ fhzgAutoTaskPlanDetail.setCreateTime(now);
|
|
|
+ detailList.add(fhzgAutoTaskPlanDetail);
|
|
|
+ });
|
|
|
+ autoTaskPlanDetailService.saveBatch(detailList);
|
|
|
+ return "创建成功";
|
|
|
+ } else {
|
|
|
+ return "已经创建";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Scheduled(cron = "0 0/5 * * * *")
|
|
|
+ public void runTask() {
|
|
|
+ LambdaQueryWrapper<FhzgAutoTaskPlanDetail> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.isNull(FhzgAutoTaskPlanDetail::getPlanNo);
|
|
|
+ List<FhzgAutoTaskPlanDetail> list = autoTaskPlanDetailService.list(queryWrapper);
|
|
|
+ if (!list.isEmpty()) {
|
|
|
+ FhzgAutoTaskPlanDetail fhzgAutoTaskPlanDetail = list.get(0);
|
|
|
+ AcceptPlanPowerCutListRequest request = new AcceptPlanPowerCutListRequest();
|
|
|
+ request.setStartTime(fhzgAutoTaskPlanDetail.getCreateTime());
|
|
|
+ request.setEndTime(fhzgAutoTaskPlanDetail.getCreateTime().plusHours(2));
|
|
|
+ request.setFeederList(Collections.singletonList(fhzgAutoTaskPlanDetail.getFeederId()));
|
|
|
+ ApiResponse<String> stringApiResponse = planCreateClient.acceptPlanPowerCut(request);
|
|
|
+ fhzgAutoTaskPlanDetail.setPlanNo(stringApiResponse.getMsg());
|
|
|
+ autoTaskPlanDetailService.updateById(fhzgAutoTaskPlanDetail);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|