yxm
2024-07-01 fc2adc3521931c2f7bc5b2f3a3d94ebf407828d6
skjcmanager/skjcmanager-service/skjcmanager-sm/src/main/java/cn/gistack/sm/sjztmd/service/impl/TbResGeneralInvestigationServiceImpl.java
@@ -1,5 +1,7 @@
package cn.gistack.sm.sjztmd.service.impl;
import cn.gistack.sm.sjztmd.mapper.AttResBaseMapper;
import cn.gistack.sm.sjztmd.util.DownloadZipUtils;
import cn.gistack.sm.sjztmd.entity.TbResGeneralInvestigation;
import cn.gistack.sm.sjztmd.entity.TbResGeneralInvestigationState;
import cn.gistack.sm.sjztmd.mapper.TbResGeneralInvestigationMapper;
@@ -8,11 +10,19 @@
import cn.gistack.sm.sjztmd.statisticsVO.StatisticsBar;
import cn.gistack.sm.sjztmd.statisticsVO.StatisticsParams;
import cn.gistack.sm.sjztmd.statisticsVO.StatisticsPie;
import cn.gistack.sm.sjztmd.statisticsVO.StatisticsTable;
import cn.gistack.sm.sjztmd.util.CalculateUtils;
import cn.gistack.sm.sjztmd.vo.TbResGeneralInvestigationParam;
import cn.gistack.sm.sjztmd.util.DownloadZipUtils;
import cn.gistack.sm.sjztmd.vo.*;
import com.alibaba.nacos.shaded.com.google.gson.Gson;
import com.alibaba.nacos.shaded.com.google.gson.JsonArray;
import com.alibaba.nacos.shaded.com.google.gson.JsonElement;
import com.alibaba.nacos.shaded.com.google.gson.JsonObject;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.val;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.DateUtil;
@@ -21,9 +31,13 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
 * @PROJECT_NAME: skjcmanager
@@ -39,13 +53,21 @@
   @Autowired
   private ITbResGeneralInvestigationStateService tbResGeneralInvestigationStateService;
   @Autowired
   private AttResBaseMapper attResBaseMapper;
   @Autowired
   private HttpServletRequest request;
//   @Autowired
//   private HttpServletResponse response;
   @Override
   @Transactional
   public R saveOrUpdateBy(TbResGeneralInvestigation entity) {
      QueryWrapper queryWrapper = new QueryWrapper();
      queryWrapper.eq("\"res_guid\"",entity.getResGuid());
      queryWrapper.eq("\"tb_year\"",entity.getTbYear());
      queryWrapper.eq("\"res_guid\"", entity.getResGuid());
      queryWrapper.eq("\"tb_year\"", entity.getTbYear());
//      queryWrapper.eq("\"tb_quarter\"",entity.getTbQuarter());
      TbResGeneralInvestigationState state = tbResGeneralInvestigationStateService.getOne(queryWrapper);
      if (null == state) {
@@ -64,14 +86,16 @@
      // 是否普查完成 1是 0否
      if (entity.getCheckState() != 0) {
         state.setCheckState(entity.getIsInvCom());
      }else{
      } else {
         state.setCheckState(0);
      }
      tbResGeneralInvestigationStateService.saveOrUpdate(state);
      entity.setTbStateId(state.getGuid());
      return R.status(this.saveOrUpdate(entity));
//      return R.status(this.saveOrUpdate(entity));
      this.saveOrUpdate(entity);
      return R.data(entity);
   }
   @Override
@@ -82,8 +106,8 @@
      //查询该水库本年度是否有填报状态记录
      QueryWrapper queryWrapper = new QueryWrapper();
      queryWrapper.eq("\"res_guid\"",entity.getResGuid());
      queryWrapper.eq("\"tb_year\"",entity.getTbYear());
      queryWrapper.eq("\"res_guid\"", entity.getResGuid());
      queryWrapper.eq("\"tb_year\"", entity.getTbYear());
      TbResGeneralInvestigationState state = tbResGeneralInvestigationStateService.getOne(queryWrapper);
      if (null == state) {
         //无填报状态记录则新建
@@ -116,11 +140,11 @@
         //id清空方便批量新增
//         tbResGeneralInvestigation.setGuid("");
         if (tbResGeneralInvestigation.getCreateTime() == null){
         if (tbResGeneralInvestigation.getCreateTime() == null) {
            tbResGeneralInvestigation.setCreateTime(DateUtil.now());
         }
         if (tbResGeneralInvestigation.getCreateUser() == null){
         if (tbResGeneralInvestigation.getCreateUser() == null) {
            tbResGeneralInvestigation.setCreateUser(AuthUtil.getUserId().toString());
         }
@@ -136,57 +160,102 @@
   }
   @Override
   public List<StatisticsBar> statisticsBar(StatisticsParams statisticsParams) {
      String adCode = statisticsParams.getAdCode();
      //默认省
      String adGrad = "1";
      List<StatisticsBar> list = baseMapper.getStatisticsBar(statisticsParams);
      return list;
   }
      //若行政区划不为空
      if (StringUtil.isNotBlank(adCode)){
         if (adCode.substring(0,4).indexOf("00") > -1) {
            //前四位包含00说明是湖北省      4200/00000000
            adGrad = "1";
         } else if (adCode.substring(0,6).indexOf("00") > -1) {
            //前六位包含00说明是市级    420100/000000
            adGrad = "2";
         }else if (adCode.substring(0,8).indexOf("00") > -1){
            //前8位包含00 说明是区级     42011700/0000
            adGrad = "3";
         }
      }
      List<StatisticsBar> list = new ArrayList<>();
   @Override
   public List<StatisticsTable> statisticsTable(StatisticsParams statisticsParams) {
      if (adGrad.equals("3")){
         //区级需要展示水库
         list =  baseMapper.getCountyStatisticsBar(statisticsParams);
      }else if (adGrad.equals("2")){
         list =  baseMapper.getCityStatisticsBar(statisticsParams);
      }else  if (adGrad.equals("1")){
         statisticsParams.setAdCode("420000000000");
         list =  baseMapper.getProvinceStatisticsBar(statisticsParams);
      }
      List<StatisticsTable> list = baseMapper.getStatisticsTable(statisticsParams);
//      if (!adGrad.equals("3")){
//         //计算有蚁率
//         DecimalFormat df = new DecimalFormat("0.00");
//         list.forEach(statisticsBar -> {
//
//            //有蚁率 = 危害座数/水库总数   =》dangerRate = dangerNum / resNum
//            if (statisticsBar.getResNum() == 0){
//               //如果水库数量为0,有蚁率为0
//               statisticsBar.setDangerRate("0");
//            }else{
//               String percent = CalculateUtils.calculatePercent(statisticsBar.getDangerNum(), statisticsBar.getResNum());
//
//               statisticsBar.setDangerRate(percent);
//
//            }
//         });
//      }
      list.forEach(statisticsTable -> {
         statisticsTable.setUnInvestigationResNum(statisticsTable.getResNum() - statisticsTable.getInvestigationResNum());
         statisticsTable.setUnInvestigationDykeNum(statisticsTable.getDykeNum() - statisticsTable.getInvestigationDykeNum());
      });
      return list;
   }
   @Override
   public List<String> downZip(IPage<ImageAndVideoVO> page,String type) throws IOException {
      List<String> urls = new ArrayList<>();
      List<ImageAndVideoVO> iamgeAndVideoUrls;
      if (type.equals("1")) {
         iamgeAndVideoUrls = baseMapper.getIamgeAndVideoUrl(page);
      }else {
         iamgeAndVideoUrls = baseMapper.getIamgeAndVideoUrl(null);
      }
      for (ImageAndVideoVO iamgeAndVideoUrl : iamgeAndVideoUrls) {
         urls.add(iamgeAndVideoUrl.getImagesUrl());
         urls.add(iamgeAndVideoUrl.getVideosUrl());
      }
      List<String> urlss =DownloadZipUtils.getUrls(urls);
      if (urlss.isEmpty()) {
         return null;
      }else {
         // 打印提取的URLs
//         for (String url1 : urlss) {
//            //System.out.println(url1+"ssss");
//
//            DownloadZipUtils.downloadFile(url1);
//         }
         //DownloadZipUtils.downloadZip(request, response,1);
         return urlss;
      }
   }
   @Override
   public List<ResGentionVO> downZipCopy(IPage<AttResBaseGeneralInvestigationVO> page,String type,AttResBaseGeneralInvestigationVO attResBase) {
      //获取已审批的数据
      List<ResGentionVO> iamgeAndVideoUrlcopy = baseMapper.getIamgeAndVideoUrlcopy();
      for (ResGentionVO resGentionVO : iamgeAndVideoUrlcopy) {
         List<String> urls = new ArrayList<>();
         List<DyketionallVO> dyketionallVOS = new ArrayList<>();
         if(resGentionVO.getImagesUrls() != null){
            urls.add(resGentionVO.getImagesUrls());
         }
         if(resGentionVO.getVideoUrls() != null) {
            urls.add(resGentionVO.getVideoUrls());
         }
         //解析json中url 放入list集合中
         List<String> urlss = DownloadZipUtils.getUrls(urls);
         int counter=1;
         for (String s : urlss) {
            DyketionallVO dyketionallVO = new DyketionallVO();
            dyketionallVO.setUrlname(resGentionVO.getResname()+"+"+resGentionVO.getPpname()+"+"+resGentionVO.getRn()+String.format("%02d", counter++)+s.substring(s.length() - 4));
            dyketionallVO.setUrl(s);
            dyketionallVOS.add(dyketionallVO);
         }
         resGentionVO.setDyketionallVOS(dyketionallVOS);
      }
      //分页情况下
      if(type.equals("1")){
         //获取分页信息
//         AttResBaseGeneralInvestigationVO attResBaseGeneralInvestigationVO = new AttResBaseGeneralInvestigationVO();
//         attResBaseGeneralInvestigationVO.setTbYear(2024);
         List<AttResBaseGeneralInvestigationVO> attResBaseGeneralInvestigationVOS = attResBaseMapper.selectAttResBaseGeneralInvestigation(page, attResBase);
         List<String> resCode = new ArrayList<>();
         for (AttResBaseGeneralInvestigationVO imageAndVideoVO : attResBaseGeneralInvestigationVOS) {
            resCode.add(imageAndVideoVO.getCode());
         }
         List<ResGentionVO> iamgeAndVideoUrls = iamgeAndVideoUrlcopy.stream()
            .filter(resGentionVO -> resCode.contains(resGentionVO.getCode()))
            .collect(Collectors.toList());
         return iamgeAndVideoUrls;
      }
      return iamgeAndVideoUrlcopy;
   }
}