|  |  | @ -1,18 +1,27 @@ | 
			
		
	
		
			
				
					|  |  |  | package com.epmet.dataaggre.service.govorg.impl; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | import cn.afterturn.easypoi.excel.ExcelExportUtil; | 
			
		
	
		
			
				
					|  |  |  | import cn.afterturn.easypoi.excel.entity.ExportParams; | 
			
		
	
		
			
				
					|  |  |  | import com.alibaba.excel.EasyExcel; | 
			
		
	
		
			
				
					|  |  |  | import com.alibaba.excel.ExcelWriter; | 
			
		
	
		
			
				
					|  |  |  | import com.alibaba.excel.write.metadata.WriteSheet; | 
			
		
	
		
			
				
					|  |  |  | import com.alibaba.fastjson.JSON; | 
			
		
	
		
			
				
					|  |  |  | import com.dingtalk.api.request.OapiRobotSendRequest; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.dynamic.datasource.annotation.DataSource; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.constant.DingDingRobotConstant; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.constant.NumConstant; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.constant.StrConstant; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.dto.form.DingTextBriefNessFormDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.exception.EpmetErrorCode; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.exception.ExceptionUtils; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.exception.RenException; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.redis.common.CustomerStaffRedis; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.security.dto.TokenDto; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.utils.ConvertUtils; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.utils.ExcelUtils; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.utils.HttpClientManager; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.utils.Result; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dataaggre.constant.DataSourceConstant; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dataaggre.dao.govorg.*; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dataaggre.dto.epmetuser.result.ListStaffResultDTO; | 
			
		
	
	
		
			
				
					|  |  | @ -28,13 +37,23 @@ import com.epmet.dataaggre.service.datastats.DataStatsService; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dataaggre.service.epmetuser.EpmetUserService; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dataaggre.service.govorg.GovOrgService; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dataaggre.service.opercrm.CustomerRelation; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.result.UploadImgResultDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.feign.OssFeignClient; | 
			
		
	
		
			
				
					|  |  |  | import lombok.extern.slf4j.Slf4j; | 
			
		
	
		
			
				
					|  |  |  | import org.apache.commons.collections4.CollectionUtils; | 
			
		
	
		
			
				
					|  |  |  | import org.apache.commons.fileupload.FileItem; | 
			
		
	
		
			
				
					|  |  |  | import org.apache.commons.fileupload.FileItemFactory; | 
			
		
	
		
			
				
					|  |  |  | import org.apache.commons.fileupload.disk.DiskFileItemFactory; | 
			
		
	
		
			
				
					|  |  |  | import org.apache.commons.lang3.StringUtils; | 
			
		
	
		
			
				
					|  |  |  | import org.apache.http.entity.ContentType; | 
			
		
	
		
			
				
					|  |  |  | import org.apache.poi.ss.usermodel.Workbook; | 
			
		
	
		
			
				
					|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
			
		
	
		
			
				
					|  |  |  | import org.springframework.stereotype.Service; | 
			
		
	
		
			
				
					|  |  |  | import org.springframework.web.multipart.commons.CommonsMultipartFile; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | import javax.servlet.http.HttpServletResponse; | 
			
		
	
		
			
				
					|  |  |  | import java.io.IOException; | 
			
		
	
		
			
				
					|  |  |  | import java.io.OutputStream; | 
			
		
	
		
			
				
					|  |  |  | import java.text.NumberFormat; | 
			
		
	
		
			
				
					|  |  |  | import java.text.SimpleDateFormat; | 
			
		
	
		
			
				
					|  |  |  | import java.util.*; | 
			
		
	
	
		
			
				
					|  |  | @ -67,6 +86,8 @@ public class GovOrgServiceImpl implements GovOrgService { | 
			
		
	
		
			
				
					|  |  |  |     private EpmetUserService epmetUserService; | 
			
		
	
		
			
				
					|  |  |  |     @Autowired | 
			
		
	
		
			
				
					|  |  |  |     private DataStatsService dataStatsService; | 
			
		
	
		
			
				
					|  |  |  |     @Autowired | 
			
		
	
		
			
				
					|  |  |  |     private OssFeignClient ossFeignClient; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |      * @param staffId | 
			
		
	
	
		
			
				
					|  |  | @ -690,4 +711,80 @@ public class GovOrgServiceImpl implements GovOrgService { | 
			
		
	
		
			
				
					|  |  |  |         return name.toString(); | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |      * @Author sun | 
			
		
	
		
			
				
					|  |  |  |      * @Description 查询组织的直属下级组织下网格活跃度统计--文件导出 | 
			
		
	
		
			
				
					|  |  |  |      **/ | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     public void pcworkRecordListExportSendMsg(GridLivelyFormDTO formDTO) { | 
			
		
	
		
			
				
					|  |  |  |         List<GridLivelyExcel> data = ConvertUtils.sourceToTarget(grdiLively(formDTO), GridLivelyExcel.class); | 
			
		
	
		
			
				
					|  |  |  |         if(CollectionUtils.isEmpty(data)){ | 
			
		
	
		
			
				
					|  |  |  |             log.warn(String.format("网格员活跃度统计数据查询为空,入参【%s】", JSON.toJSONString(formDTO))); | 
			
		
	
		
			
				
					|  |  |  |             return; | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         ExportParams exportParams = new ExportParams(); | 
			
		
	
		
			
				
					|  |  |  |         String sheetName = excelSheetName(formDTO); | 
			
		
	
		
			
				
					|  |  |  |         exportParams.setSheetName(sheetName); | 
			
		
	
		
			
				
					|  |  |  |         Workbook workbook = ExcelExportUtil.exportExcel(exportParams, | 
			
		
	
		
			
				
					|  |  |  |                 GridLivelyExcel.class, data); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         // 文件名
 | 
			
		
	
		
			
				
					|  |  |  |         String resultDescFileName = sheetName.concat(".xls"); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         FileItemFactory factory = new DiskFileItemFactory(16, null); | 
			
		
	
		
			
				
					|  |  |  |         FileItem fileItem = factory.createItem("file", ContentType.APPLICATION_OCTET_STREAM.toString(), true, resultDescFileName); | 
			
		
	
		
			
				
					|  |  |  |         OutputStream os = null; | 
			
		
	
		
			
				
					|  |  |  |         Result<UploadImgResultDTO> uploadResult = null; | 
			
		
	
		
			
				
					|  |  |  |         try { | 
			
		
	
		
			
				
					|  |  |  |             os = fileItem.getOutputStream(); | 
			
		
	
		
			
				
					|  |  |  |             workbook.write(os); | 
			
		
	
		
			
				
					|  |  |  |             uploadResult = ossFeignClient.uploadImportTaskDescFile(new CommonsMultipartFile(fileItem)); | 
			
		
	
		
			
				
					|  |  |  |         } catch (Exception e) { | 
			
		
	
		
			
				
					|  |  |  |             String errormsg = ExceptionUtils.getErrorStackTrace(e); | 
			
		
	
		
			
				
					|  |  |  |             log.warn("【网格活跃度统计】上传错误描述文件异常:{}", errormsg); | 
			
		
	
		
			
				
					|  |  |  |         } finally { | 
			
		
	
		
			
				
					|  |  |  |             try { | 
			
		
	
		
			
				
					|  |  |  |                 os.close(); | 
			
		
	
		
			
				
					|  |  |  |             } catch (IOException e) { | 
			
		
	
		
			
				
					|  |  |  |                 String errormsg = ExceptionUtils.getErrorStackTrace(e); | 
			
		
	
		
			
				
					|  |  |  |                 log.warn("【网格活跃度统计】上传错误描述文件关闭输出流:{}", errormsg); | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |             try { | 
			
		
	
		
			
				
					|  |  |  |                 fileItem.delete(); | 
			
		
	
		
			
				
					|  |  |  |             } catch (Exception e) { | 
			
		
	
		
			
				
					|  |  |  |                 String errormsg = ExceptionUtils.getErrorStackTrace(e); | 
			
		
	
		
			
				
					|  |  |  |                 log.warn("【网格活跃度统计】上传错误描述文件删除临时文件:{}", errormsg); | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         log.warn(String.format("网格员活跃度统计数据查询为空,返参【%s】", JSON.toJSONString(uploadResult))); | 
			
		
	
		
			
				
					|  |  |  |         if (uploadResult == null || !uploadResult.success()) { | 
			
		
	
		
			
				
					|  |  |  |             log.warn("【网格活跃度统计】调用OSS上传结果描述文件失败"); | 
			
		
	
		
			
				
					|  |  |  |         } else { | 
			
		
	
		
			
				
					|  |  |  |             //EPMETV3群机器人
 | 
			
		
	
		
			
				
					|  |  |  |             String secret = DingDingRobotConstant.V3_ROBOT_SECRET; | 
			
		
	
		
			
				
					|  |  |  |             String url = DingDingRobotConstant.V3_ROBOT_URL; | 
			
		
	
		
			
				
					|  |  |  |             // String secret = DingDingRobotConstant.YZM_TEST_SECRET;
 | 
			
		
	
		
			
				
					|  |  |  |             // String url = DingDingRobotConstant.YZM_TEST_URL;
 | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             DingTextBriefNessFormDTO dingTalkTextMsg=new DingTextBriefNessFormDTO(); | 
			
		
	
		
			
				
					|  |  |  |             dingTalkTextMsg.setMsgtype("text"); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             //小雷哥手机号:18660295251,
 | 
			
		
	
		
			
				
					|  |  |  |             OapiRobotSendRequest.At at = new OapiRobotSendRequest.At(); | 
			
		
	
		
			
				
					|  |  |  |             at.setAtMobiles(Arrays.asList("18660295251","15764229697")); | 
			
		
	
		
			
				
					|  |  |  |             at.setIsAtAll(false); | 
			
		
	
		
			
				
					|  |  |  |             dingTalkTextMsg.setAt(at); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |             //文本方式发送
 | 
			
		
	
		
			
				
					|  |  |  |             OapiRobotSendRequest.Text text = new OapiRobotSendRequest.Text(); | 
			
		
	
		
			
				
					|  |  |  |             text.setContent("网格活跃度统计: \n" + | 
			
		
	
		
			
				
					|  |  |  |                     "起止时间: " + formDTO.getStartTime().concat(StrConstant.UNDER_LINE).concat(formDTO.getEndTime()) + "\n" + | 
			
		
	
		
			
				
					|  |  |  |                     "文件下载地址: " + uploadResult.getData().getUrl() + "\n"+ | 
			
		
	
		
			
				
					|  |  |  |                     "请查收@18660295251@15764229697"); | 
			
		
	
		
			
				
					|  |  |  |             dingTalkTextMsg.setText(text); | 
			
		
	
		
			
				
					|  |  |  |             HttpClientManager.getInstance().sendDingMsg(JSON.toJSONString(dingTalkTextMsg), url, secret); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | } | 
			
		
	
	
		
			
				
					|  |  | 
 |