WeeklyReportController.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. package com.ruoyi.powerdistribution.controller;
  2. import com.ruoyi.common.core.controller.BaseController;
  3. import com.ruoyi.common.utils.DateUtils;
  4. import com.ruoyi.common.utils.StringUtils;
  5. import com.ruoyi.common.utils.bean.BeanUtils;
  6. import com.ruoyi.common.utils.uuid.UUID;
  7. import com.ruoyi.powerdistribution.domain.*;
  8. import com.ruoyi.powerdistribution.domain.dto.PdmWorkPlanDTO;
  9. import com.ruoyi.powerdistribution.domain.vo.SupRiskTeam;
  10. import com.ruoyi.powerdistribution.domain.vo.TaskRiskPlan;
  11. import com.ruoyi.powerdistribution.domain.vo.ThreeLevelRiskJob;
  12. import com.ruoyi.powerdistribution.service.*;
  13. import com.ruoyi.powerdistribution.util.GenerateWordUtil;
  14. import io.swagger.annotations.ApiOperation;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import org.springframework.beans.factory.annotation.Value;
  17. import org.springframework.web.bind.annotation.PostMapping;
  18. import org.springframework.web.bind.annotation.RequestMapping;
  19. import org.springframework.web.bind.annotation.RestController;
  20. import javax.activation.MimetypesFileTypeMap;
  21. import javax.servlet.http.HttpServletResponse;
  22. import java.io.*;
  23. import java.text.ParseException;
  24. import java.text.SimpleDateFormat;
  25. import java.util.*;
  26. import java.util.stream.Collectors;
  27. /**
  28. * 周报导出
  29. */
  30. @RestController
  31. @RequestMapping("/power/weklyReport")
  32. public class WeeklyReportController extends BaseController {
  33. @Value("${printReplenishmentPath}")
  34. private String printReplenishmentPath;
  35. @Autowired
  36. private IPdmReportIllegalDayService pdmReportIllegalDayService;
  37. @Autowired
  38. private IPdmReportPlanNextDayService pdmReportPlanNextDayService;
  39. @Autowired
  40. private IPdmWorkPlanService pdmWorkPlanService;
  41. @Autowired
  42. private IPdmReportPlanDayService pdmReportPlanDayService;
  43. @Autowired
  44. private IPdmReportAppointmentDayService pdmReportAppointmentDayService;
  45. @PostMapping("/export")
  46. @ApiOperation(value = "周报导出")
  47. public void export(HttpServletResponse response, String beingDate,String endDate) throws IOException, ParseException {
  48. PdmReportIllegalDay pdmReportIllegalDay = new PdmReportIllegalDay();
  49. pdmReportIllegalDay.setReportDate(beingDate);
  50. Map<String,Object> dataMap = new HashMap();
  51. SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
  52. Date cvrtFirstDate = sdf.parse(beingDate);
  53. Date cvrtEndDate = sdf.parse(endDate);
  54. //日期公共使用
  55. String month=new SimpleDateFormat("MM").format(cvrtFirstDate);
  56. dataMap.put("beginDay",month+"月"+new SimpleDateFormat("dd").format(cvrtFirstDate)+"日");//开始日
  57. dataMap.put("endDay",month+"月"+new SimpleDateFormat("dd").format(cvrtEndDate)+"日");//结束日
  58. //一.风险计划管控
  59. //1.本周计划执行情况
  60. PdmReportPlanDay pdmReportPlan = new PdmReportPlanDay();
  61. pdmReportPlan.setStartDate(beingDate);
  62. pdmReportPlan.setEndDate(endDate);
  63. List<PdmReportPlanDay> planlist = pdmReportPlanDayService.selectPlanReport(pdmReportPlan);
  64. dataMap.put("planlist",planlist);//本周计划执行情况
  65. long jobRecNum=0;
  66. long weekPlanJobReNum=0;
  67. long cancelRecNum=0;
  68. String implRate="";
  69. long tmpPlanRecNum=0;
  70. String tmpPlanRate="";
  71. long cancelTmpPlanRecNum=0;
  72. String tmpPlanImplRate="";
  73. String lowImplUnit="";
  74. String lowImplRate="";
  75. if(planlist!=null && planlist.size()>1){
  76. pdmReportPlan=planlist.get(planlist.size()-1);
  77. jobRecNum=pdmReportPlan.getTotal();
  78. weekPlanJobReNum=pdmReportPlan.getWeekSum();
  79. cancelRecNum=pdmReportPlan.getWeekCancelSum();
  80. implRate=pdmReportPlan.getWeekRatio();
  81. tmpPlanRecNum=pdmReportPlan.getTemporarySum();
  82. tmpPlanRate=pdmReportPlan.getTemporaryPlanRatio();
  83. cancelTmpPlanRecNum=pdmReportPlan.getTemporaryCancelSum();
  84. tmpPlanImplRate=pdmReportPlan.getTemporaryRatio();
  85. List<PdmReportPlanDay> planlist2=new ArrayList<>();
  86. planlist.forEach(plan->{
  87. if(!plan.getCompany().equals("总计")){
  88. PdmReportPlanDay planWeek=new PdmReportPlanDay();
  89. BeanUtils.copyBeanProp(planWeek,plan);
  90. planlist2.add(planWeek);
  91. }
  92. });
  93. // Collections.sort(planlist2, new Comparator<PdmReportPlanWeek>(){
  94. // public int compare(PdmReportPlanWeek o1, PdmReportPlanWeek o2) {
  95. // //按照周计划执行率行升序排列
  96. // if((o1.getWeekSum()-o1.getWeekCancelSum())/o1.getWeekSum() > (o2.getWeekSum()-o2.getWeekCancelSum())/o2.getWeekSum()){
  97. // return -1;
  98. // }
  99. // if((o1.getWeekSum()-o1.getWeekCancelSum())/o1.getWeekSum() < (o2.getWeekSum()-o2.getWeekCancelSum())/o2.getWeekSum()){
  100. // return 1;
  101. // }
  102. // return 0;
  103. // }
  104. // });
  105. PdmReportPlanDay lowPdmReportPlan=planlist2.get(planlist2.size()-1);
  106. lowImplUnit=lowPdmReportPlan.getCompany();
  107. lowImplRate=lowPdmReportPlan.getWeekRatio();
  108. }
  109. dataMap.put("jobRecNum",jobRecNum);//发布作业信息条数
  110. dataMap.put("weekPlanJobReNum",weekPlanJobReNum);//来源于周计划的作业条数
  111. dataMap.put("cancelRecNum",cancelRecNum);//已取消
  112. dataMap.put("implRate",implRate);//执行率
  113. dataMap.put("lowImplUnit",lowImplUnit);//较低的单位 ()
  114. dataMap.put("lowImplRate",lowImplRate);//较低的单位执行率
  115. dataMap.put("tmpPlanRecNum",tmpPlanRecNum);//临时计划
  116. dataMap.put("repairRecNum",0);//其中抢修
  117. dataMap.put("operateRecNum",0);//操作条数
  118. dataMap.put("maintenanceNum",0);//运维检修
  119. dataMap.put("expanRelocationNum",0);//业扩
  120. dataMap.put("networkReformNum",0);//网改
  121. dataMap.put("tmpPlanRate",tmpPlanRate);//临时计划率
  122. dataMap.put("cancelTmpPlanRecNum",cancelTmpPlanRecNum);//临时取消计划数
  123. dataMap.put("tmpPlanImplRate",tmpPlanImplRate);//临时计划执行率
  124. //2.下周计划安排情况
  125. String nextMonday=DateUtils.getNextMonday(beingDate,"yyyyMMdd");
  126. String nextSunday=DateUtils.getNextSunday(endDate,"yyyyMMdd");
  127. Date cvrtNextMonday = sdf.parse(nextMonday);
  128. Date cvrtNextSunday = sdf.parse(nextSunday);
  129. long nextWeekJobRecNum=0;
  130. long nextWeekSwitchingNum=0;
  131. long distribuNetworkEngineNum=0;
  132. long nextWeekExpanRelocationNum=0;
  133. long nextWeekMaintenanceNum=0;
  134. String threeLevelRiskNum="0";
  135. String fourLevelRiskNum="0";
  136. String fiveLevelRiskNum="0";
  137. long liveWorkingNum=0;
  138. PdmReportPlanNextDay next = new PdmReportPlanNextDay();
  139. next.setStartDate(nextMonday);
  140. next.setEndDate(nextSunday);
  141. List<PdmReportPlanNextDay> nextList = pdmReportPlanNextDayService.selectReportPlanNext(next);
  142. if(nextList!=null && nextList.size()>1){
  143. next=nextList.get(nextList.size()-1);
  144. nextWeekJobRecNum=next.getWorkTotal();
  145. nextWeekSwitchingNum=next.getWorkType1Sum();
  146. distribuNetworkEngineNum=next.getWorkType2Sum();
  147. nextWeekExpanRelocationNum=next.getWorkType3Sum();
  148. nextWeekMaintenanceNum=next.getWorkType4Sum();
  149. threeLevelRiskNum=next.getPlanLeve3();
  150. fourLevelRiskNum=next.getPlanLeve4();
  151. fiveLevelRiskNum=next.getPlanLeve5();
  152. liveWorkingNum=next.getElePlanSum();
  153. }
  154. month=new SimpleDateFormat("MM").format(cvrtNextMonday);
  155. dataMap.put("nextWeekBeginDay",month+"月"+new SimpleDateFormat("dd").format(cvrtNextMonday)+"日");//下周开始日
  156. dataMap.put("nextWeekEndDay",month+"月"+new SimpleDateFormat("dd").format(cvrtNextSunday)+"日");//下周结束日
  157. dataMap.put("nextWeekJobRecNum",nextWeekJobRecNum);//配网专业计划总数
  158. dataMap.put("nextWeekSwitchingNum",nextWeekSwitchingNum);//倒闸操作
  159. dataMap.put("distribuNetworkEngineNum",distribuNetworkEngineNum);//配网工程
  160. dataMap.put("nextWeekExpanRelocationNum",nextWeekExpanRelocationNum);//业扩杆迁
  161. dataMap.put("nextWeekMaintenanceNum",nextWeekMaintenanceNum);//运维检修
  162. dataMap.put("threeLevelRiskNum",threeLevelRiskNum);//三级风险作业
  163. dataMap.put("fourLevelRiskNum",fourLevelRiskNum);//四级风险作业
  164. dataMap.put("fiveLevelRiskNum",fiveLevelRiskNum);//五级风险作业
  165. dataMap.put("liveWorkingNum",liveWorkingNum);//带电作业
  166. dataMap.put("liveDisconnectLeadNum",0);//带电断接引
  167. dataMap.put("assemDeviceNum",0);//带电消缺、装拆设备
  168. //三级及以上作业风险计划
  169. PdmWorkPlanDTO workPlan = new PdmWorkPlanDTO();
  170. workPlan.setStartDate(nextMonday);
  171. workPlan.setEndDate(nextSunday);
  172. workPlan.setLevel3Flag("1");//三级及以上作业
  173. List<PdmWorkPlan> workList = pdmWorkPlanService.selectPdmWorkPlanList(workPlan);
  174. dataMap.put("threeLevelRiskWorkList",workList);//三级及以上作业列表明细
  175. //三级风险作业内容:
  176. List<String> threeLevelRiskJobs=new ArrayList<String>() ;
  177. for(int i=0;i<workList.size();i++){
  178. StringBuilder builder=new StringBuilder();
  179. PdmWorkPlan threeLevelRiskJob=workList.get(i);
  180. month=new SimpleDateFormat("MM").format(threeLevelRiskJob.getPlanStartWkTm());
  181. String day=new SimpleDateFormat("dd").format(threeLevelRiskJob.getPlanStartWkTm());
  182. builder.append(threeLevelRiskJob.getSubmitOrgNm()).append(": ").append(month+"月"+day+"日").append(",").append(threeLevelRiskJob.getOpContent()).append("。");
  183. threeLevelRiskJobs.add(builder.toString());
  184. }
  185. dataMap.put("threeLevelRiskJobs",threeLevelRiskJobs);//三级风险作业内容:
  186. dataMap.put("fousMaintenanceNum",0);//重点关注检修面个数
  187. String fousMaintenanceInfo="";//重点关注检修面内容
  188. dataMap.put("fousMaintenanceInfo", StringUtils.isEmpty(fousMaintenanceInfo)?"无":fousMaintenanceInfo);//重点关注检修面内容
  189. //下周计划安排情况
  190. dataMap.put("nextWeekWorkList",nextList);//下周计划安排情况列表
  191. //二、专业反违章履职情况
  192. //1.本周违章查处情况
  193. long provinceInvestSeriousRecNum=0;
  194. long provinceInvestGeneralRecNum=0;
  195. long cityInvestSeriousRecNum=0;
  196. long cityInvestGeneralRecNum=0;
  197. long countyInvestSeriousRecNum=0;
  198. long countyInvestGeneralRecNum=0;
  199. PdmReportIllegalDay pdmReportIllegal = new PdmReportIllegalDay();
  200. pdmReportIllegal.setStartDate(beingDate);
  201. pdmReportIllegal.setEndDate(endDate);
  202. List<PdmReportIllegalDay> illegalList = pdmReportIllegalDayService.selectIllegalReport(pdmReportIllegal);
  203. if(illegalList!=null && illegalList.size()>1){
  204. pdmReportIllegal=illegalList.get(illegalList.size()-1);
  205. provinceInvestSeriousRecNum=pdmReportIllegal.getProvinceNum1();
  206. provinceInvestGeneralRecNum=pdmReportIllegal.getProvinceNum2();
  207. cityInvestSeriousRecNum=pdmReportIllegal.getCityNum1();
  208. cityInvestGeneralRecNum=pdmReportIllegal.getCityNum2();
  209. countyInvestSeriousRecNum=pdmReportIllegal.getCountyNum1();
  210. countyInvestGeneralRecNum=pdmReportIllegal.getCountyNum2();
  211. }
  212. dataMap.put("investPunishRecAllNum",(provinceInvestSeriousRecNum+provinceInvestGeneralRecNum+cityInvestSeriousRecNum+cityInvestGeneralRecNum+countyInvestSeriousRecNum+countyInvestGeneralRecNum));//配网专业共计查处违章
  213. dataMap.put("provinceInvestPunishRecNum",(provinceInvestSeriousRecNum+provinceInvestGeneralRecNum));//被省公司查处违章
  214. dataMap.put("cityInvestPunishRecNum",(cityInvestSeriousRecNum+cityInvestGeneralRecNum));//被市公司查处违章
  215. dataMap.put("cityInvestSeriousRecNum",cityInvestSeriousRecNum);//严重违章
  216. dataMap.put("cityInvestGeneralRecNum",cityInvestGeneralRecNum);//一般违章
  217. dataMap.put("countyInvestPunishRecNum",(countyInvestSeriousRecNum+countyInvestGeneralRecNum));//县区公司自查处违章
  218. dataMap.put("countyInvestSeriousRecNum",countyInvestSeriousRecNum);//严重违章
  219. dataMap.put("countyInvestGeneralRecNum",countyInvestGeneralRecNum);//一般违章
  220. //本周违章查处情况列表
  221. dataMap.put("illegalList",illegalList);//违章列表明细
  222. String typicalIllegal="";//其中典型违章通报如下
  223. dataMap.put("typicalIllegal",StringUtils.isEmpty(typicalIllegal)?"无":typicalIllegal);//其中典型违章通报如下
  224. //2.本周人员到岗到位履职情况
  225. long leaderSupervTimes=0;
  226. long manageSupervTimes=0;
  227. long problemNum=0;
  228. long cityFindProblemNum=0;
  229. long derelictionDutyNum=0;
  230. PdmReportAppointmentDay pdmReportAppointment = new PdmReportAppointmentDay();
  231. pdmReportAppointment.setStartDate(beingDate);
  232. pdmReportAppointment.setEndDate(endDate);
  233. List<PdmReportAppointmentDay> appointmentlist = pdmReportAppointmentDayService.selectAppointmentReport(pdmReportAppointment);
  234. if(appointmentlist!=null && appointmentlist.size()>1) {
  235. pdmReportAppointment=appointmentlist.get(appointmentlist.size()-1);
  236. leaderSupervTimes=pdmReportAppointment.getBossSum();
  237. manageSupervTimes=pdmReportAppointment.getManageSum();
  238. problemNum=pdmReportAppointment.getProblemSum();
  239. cityFindProblemNum=pdmReportAppointment.getCityCheckSum();
  240. derelictionDutyNum=pdmReportAppointment.getAbsentSum();
  241. }
  242. dataMap.put("appointmentlist",appointmentlist);//本周到岗到位履职情况
  243. dataMap.put("supervTimes",(leaderSupervTimes+manageSupervTimes));//督察共计次数
  244. dataMap.put("leaderSupervTimes",leaderSupervTimes);//领导督察共计次数
  245. dataMap.put("manageSupervTimes",manageSupervTimes);//管理人员督察次数
  246. dataMap.put("problemNum",problemNum);//督察发现问题
  247. dataMap.put("cityFindProblemNum",cityFindProblemNum);//市公司发现问题处数
  248. dataMap.put("derelictionDutyNum",derelictionDutyNum);//履职不到位(应查未查)
  249. File descFile=null;
  250. try {
  251. String fileN = UUID.randomUUID().toString();
  252. File fileFold = new File(printReplenishmentPath+"/temp_print/");
  253. if(!fileFold.exists()){
  254. fileFold.mkdirs();
  255. }
  256. String fileDocPath = fileFold+"/"+fileN+".doc";
  257. GenerateWordUtil.generateWord(dataMap, "生产周例会配电汇报内容.ftl", new OutputStreamWriter(new FileOutputStream(new File(fileDocPath)), "utf-8"));
  258. descFile = new File(fileDocPath);
  259. String type = new MimetypesFileTypeMap().getContentType(descFile);
  260. response.setHeader("Content-type",type);
  261. String filename = new String(descFile.getName().getBytes("utf-8"), "iso-8859-1");
  262. response.setHeader("Content-Disposition", "attachment;filename=" + filename);
  263. response.setContentType("application/octet-stream");
  264. response.reset();
  265. OutputStream outputStream1 = response.getOutputStream();
  266. BufferedInputStream bis = null;
  267. bis = new BufferedInputStream(new FileInputStream(descFile));
  268. byte[] buff = new byte[bis.available()];
  269. bis.read(buff);
  270. outputStream1.write(buff);
  271. outputStream1.close();
  272. bis.close();
  273. } catch (Exception e) {
  274. e.printStackTrace();
  275. }finally {
  276. // if(descFile!=null)
  277. // descFile.deleteOnExit();
  278. }
  279. //下载之后删除
  280. try {
  281. if(descFile.exists()){
  282. descFile.delete();
  283. }
  284. } catch (Exception e) {
  285. e.printStackTrace();
  286. }
  287. }
  288. }