|  | @@ -1,20 +1,31 @@
 | 
	
		
			
				|  |  |  package com.tzld.piaoquan.api.service.contentplatform.impl;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +import com.alibaba.excel.EasyExcel;
 | 
	
		
			
				|  |  | +import com.stuuudy.commons.external.filestorage.enums.EnumFileType;
 | 
	
		
			
				|  |  | +import com.stuuudy.commons.external.filestorage.enums.EnumPublicBuckets;
 | 
	
		
			
				|  |  |  import com.tzld.piaoquan.api.dao.mapper.contentplatform.ext.ContentPlatformDataStatMapperExt;
 | 
	
		
			
				|  |  |  import com.tzld.piaoquan.api.model.config.LoginUserContext;
 | 
	
		
			
				|  |  |  import com.tzld.piaoquan.api.model.param.contentplatform.GzhDatastatListParam;
 | 
	
		
			
				|  |  |  import com.tzld.piaoquan.api.model.param.contentplatform.QwDatastatListParam;
 | 
	
		
			
				|  |  |  import com.tzld.piaoquan.api.model.po.contentplatform.*;
 | 
	
		
			
				|  |  | +import com.tzld.piaoquan.api.model.vo.contentplatform.GzhDatastatItemExportVO;
 | 
	
		
			
				|  |  |  import com.tzld.piaoquan.api.model.vo.contentplatform.GzhDatastatItemVO;
 | 
	
		
			
				|  |  | +import com.tzld.piaoquan.api.model.vo.contentplatform.QwDatastatItemExportVO;
 | 
	
		
			
				|  |  |  import com.tzld.piaoquan.api.model.vo.contentplatform.QwDatastatItemVO;
 | 
	
		
			
				|  |  |  import com.tzld.piaoquan.api.service.contentplatform.ContentPlatformCooperateAccountService;
 | 
	
		
			
				|  |  |  import com.tzld.piaoquan.api.service.contentplatform.ContentPlatformDatastatService;
 | 
	
		
			
				|  |  |  import com.tzld.piaoquan.api.service.contentplatform.ContentPlatformPlanService;
 | 
	
		
			
				|  |  | +import com.tzld.piaoquan.api.util.AliOssFileTool;
 | 
	
		
			
				|  |  | +import com.tzld.piaoquan.api.util.CdnUtil;
 | 
	
		
			
				|  |  |  import com.tzld.piaoquan.growth.common.utils.page.Page;
 | 
	
		
			
				|  |  |  import org.apache.commons.collections4.CollectionUtils;
 | 
	
		
			
				|  |  |  import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  |  import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +import java.io.ByteArrayInputStream;
 | 
	
		
			
				|  |  | +import java.io.ByteArrayOutputStream;
 | 
	
		
			
				|  |  | +import java.math.BigDecimal;
 | 
	
		
			
				|  |  | +import java.math.RoundingMode;
 | 
	
		
			
				|  |  |  import java.util.*;
 | 
	
		
			
				|  |  |  import java.util.stream.Collectors;
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -94,7 +105,9 @@ public class ContentPlatformDatastatServiceImpl implements ContentPlatformDatast
 | 
	
		
			
				|  |  |              vo.setFirstLevel(datastat.getFirstLevelCount());
 | 
	
		
			
				|  |  |              vo.setScore(datastat.getScore());
 | 
	
		
			
				|  |  |              if (Objects.nonNull(vo.getFansIncreaseCount()) && vo.getFansIncreaseCount() > 0) {
 | 
	
		
			
				|  |  | -                vo.setOpenRate(vo.getFirstLevel() / (double) vo.getFansIncreaseCount());
 | 
	
		
			
				|  |  | +                BigDecimal num = BigDecimal.valueOf(vo.getFirstLevel() / (double) vo.getFansIncreaseCount());
 | 
	
		
			
				|  |  | +                BigDecimal rounded = num.setScale(3, RoundingMode.HALF_UP);
 | 
	
		
			
				|  |  | +                vo.setOpenRate(rounded.doubleValue());
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              result.add(vo);
 | 
	
		
			
				|  |  |          }
 | 
	
	
		
			
				|  | @@ -213,11 +226,55 @@ public class ContentPlatformDatastatServiceImpl implements ContentPlatformDatast
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      public String gzhDatastatExport(GzhDatastatListParam param) {
 | 
	
		
			
				|  |  | -        return null;
 | 
	
		
			
				|  |  | +        param.setPageNum(1);
 | 
	
		
			
				|  |  | +        param.setPageSize(10000);
 | 
	
		
			
				|  |  | +        Page<GzhDatastatItemVO> pageResult = gzhDatastatList(param);
 | 
	
		
			
				|  |  | +        List<GzhDatastatItemVO> dataList = pageResult.getObjs();
 | 
	
		
			
				|  |  | +        return generateGzhDatastatExcelFile(dataList);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    public String generateGzhDatastatExcelFile(List<GzhDatastatItemVO> dataList) {
 | 
	
		
			
				|  |  | +        ArrayList<GzhDatastatItemExportVO> list = new ArrayList<>();
 | 
	
		
			
				|  |  | +        if (CollectionUtils.isNotEmpty(dataList)) {
 | 
	
		
			
				|  |  | +            for (GzhDatastatItemVO data : dataList) {
 | 
	
		
			
				|  |  | +                list.add(new GzhDatastatItemExportVO(data.getDateStr(), data.getName(),
 | 
	
		
			
				|  |  | +                        data.getFansIncreaseCount(), data.getFirstLevel(),  data.getOpenRate(), data.getScore()));
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            list.add(new GzhDatastatItemExportVO());
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        ByteArrayOutputStream out = new ByteArrayOutputStream();
 | 
	
		
			
				|  |  | +        EasyExcel.write(out, GzhDatastatItemExportVO.class).sheet("").doWrite(list);
 | 
	
		
			
				|  |  | +        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(out.toByteArray());
 | 
	
		
			
				|  |  | +        String fileName = "公众号数据统计_" + System.currentTimeMillis() + ".xls";
 | 
	
		
			
				|  |  | +        AliOssFileTool.saveInPublicReturnHost(byteArrayInputStream, EnumPublicBuckets.PUBBUCKET, fileName, EnumFileType.TEMP_PICTURE);
 | 
	
		
			
				|  |  | +        return CdnUtil.DOWNLOAD_CDN_URL_HOST_PICTURE + fileName;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      public String qwDatastatExport(QwDatastatListParam param) {
 | 
	
		
			
				|  |  | -        return null;
 | 
	
		
			
				|  |  | +        param.setPageNum(1);
 | 
	
		
			
				|  |  | +        param.setPageSize(10000);
 | 
	
		
			
				|  |  | +        Page<QwDatastatItemVO> pageResult = qwDatastatList(param);
 | 
	
		
			
				|  |  | +        List<QwDatastatItemVO> dataList = pageResult.getObjs();
 | 
	
		
			
				|  |  | +        return generateQwDatastatExcelFile(dataList);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    public String generateQwDatastatExcelFile(List<QwDatastatItemVO> dataList) {
 | 
	
		
			
				|  |  | +        ArrayList<QwDatastatItemExportVO> list = new ArrayList<>();
 | 
	
		
			
				|  |  | +        if (CollectionUtils.isNotEmpty(dataList)) {
 | 
	
		
			
				|  |  | +            for (QwDatastatItemVO data : dataList) {
 | 
	
		
			
				|  |  | +                list.add(new QwDatastatItemExportVO(data.getDateStr(), data.getFirstLevel(),
 | 
	
		
			
				|  |  | +                        data.getScore(), data.getTitle(),  data.getVideoId()));
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            list.add(new QwDatastatItemExportVO());
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        ByteArrayOutputStream out = new ByteArrayOutputStream();
 | 
	
		
			
				|  |  | +        EasyExcel.write(out, QwDatastatItemExportVO.class).sheet("").doWrite(list);
 | 
	
		
			
				|  |  | +        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(out.toByteArray());
 | 
	
		
			
				|  |  | +        String fileName = "企微数据统计_" + System.currentTimeMillis() + ".xls";
 | 
	
		
			
				|  |  | +        AliOssFileTool.saveInPublicReturnHost(byteArrayInputStream, EnumPublicBuckets.PUBBUCKET, fileName, EnumFileType.TEMP_PICTURE);
 | 
	
		
			
				|  |  | +        return CdnUtil.DOWNLOAD_CDN_URL_HOST_PICTURE + fileName;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  }
 |