WcBlackoutPlanServiceImpl.java 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. package com.bizmatics.service.impl;
  2. import cn.afterturn.easypoi.excel.ExcelExportUtil;
  3. import cn.afterturn.easypoi.excel.entity.ExportParams;
  4. import com.bizmatics.common.core.bean.CommonPage;
  5. import com.bizmatics.common.core.exception.BusinessException;
  6. import com.bizmatics.common.core.util.BeanMapperUtils;
  7. import com.bizmatics.common.core.util.FileUtils;
  8. import com.bizmatics.common.mvc.base.AbstractCrudService;
  9. import com.bizmatics.common.spring.util.GlobalUtils;
  10. import com.bizmatics.model.WcBlackoutPlan;
  11. import com.bizmatics.model.system.SysUser;
  12. import com.bizmatics.model.vo.PlannedOutageVo;
  13. import com.bizmatics.model.vo.WcBlackoutPlanOneVo;
  14. import com.bizmatics.model.vo.WcBlackoutPlanVo;
  15. import com.bizmatics.persistence.mapper.WcBlackoutPlanMapper;
  16. import com.bizmatics.service.WcBlackoutPlanService;
  17. import com.bizmatics.service.util.SecurityUtils;
  18. import com.bizmatics.service.vo.WcBlackoutPlanOneExportVo;
  19. import org.apache.poi.ss.usermodel.Workbook;
  20. import org.springframework.stereotype.Service;
  21. import java.io.File;
  22. import java.io.FileOutputStream;
  23. import java.io.IOException;
  24. import java.text.DateFormat;
  25. import java.text.SimpleDateFormat;
  26. import java.util.ArrayList;
  27. import java.util.Date;
  28. import java.util.List;
  29. /**
  30. * 计划停电
  31. *
  32. * @author ya
  33. * @since 2021-07-07
  34. */
  35. @Service
  36. public class WcBlackoutPlanServiceImpl extends AbstractCrudService<WcBlackoutPlanMapper, WcBlackoutPlan> implements WcBlackoutPlanService {
  37. @Override
  38. public void plannedOutageAdd(WcBlackoutPlan wcBlackoutPlan) {
  39. SysUser user = SecurityUtils.getLoginUser().getUser();
  40. wcBlackoutPlan.setEnable(1);
  41. wcBlackoutPlan.setCreator(user.getUserName());
  42. wcBlackoutPlan.setCreateTime(new Date());
  43. this.save(wcBlackoutPlan);
  44. }
  45. @Override
  46. public void plannedOutageUpdate(WcBlackoutPlan wcBlackoutPlan) {
  47. this.updateById(wcBlackoutPlan);
  48. }
  49. @Override
  50. public void plannedOutageDel(int id) {
  51. WcBlackoutPlan wcBlackoutPlan = new WcBlackoutPlan();
  52. wcBlackoutPlan.setId(id);
  53. wcBlackoutPlan.setEnable(0);
  54. this.updateById(wcBlackoutPlan);
  55. }
  56. @Override
  57. public CommonPage<WcBlackoutPlanVo> plannedOutageList(PlannedOutageVo plannedOutageVo) {
  58. List<WcBlackoutPlanVo> wcBlackoutPlanVoListOne = baseMapper.plannedOutageList(plannedOutageVo.getStartTime(), plannedOutageVo.getEndTime(), plannedOutageVo.getType(), plannedOutageVo.getId(), 0, null);
  59. int total = 0;
  60. if (wcBlackoutPlanVoListOne.size() > 0) {
  61. total = wcBlackoutPlanVoListOne.size();
  62. }
  63. int startCurrent = (plannedOutageVo.getCurrent() - 1) * plannedOutageVo.getSize();
  64. List<WcBlackoutPlanVo> plannedOutageList = baseMapper.plannedOutageList(plannedOutageVo.getStartTime(), plannedOutageVo.getEndTime(), plannedOutageVo.getType(), plannedOutageVo.getId(), plannedOutageVo.getSize(), startCurrent);
  65. List<WcBlackoutPlanVo> plannedOutageListOne = new ArrayList<>();
  66. if (plannedOutageList.size() > 0) {
  67. for (int i = 0; i < plannedOutageList.size(); i++) {
  68. WcBlackoutPlanVo wcBlackoutPlanVo = new WcBlackoutPlanVo();
  69. wcBlackoutPlanVo.setSiteId(plannedOutageList.get(i).getSiteId());
  70. wcBlackoutPlanVo.setPlanType(plannedOutageList.get(i).getPlanType());
  71. wcBlackoutPlanVo.setStartTime(plannedOutageList.get(i).getStartTime());
  72. wcBlackoutPlanVo.setEndTime(plannedOutageList.get(i).getEndTime());
  73. wcBlackoutPlanVo.setContacts(plannedOutageList.get(i).getContacts());
  74. wcBlackoutPlanVo.setPhone(plannedOutageList.get(i).getPhone());
  75. wcBlackoutPlanVo.setEnable(plannedOutageList.get(i).getEnable());
  76. wcBlackoutPlanVo.setCreator(plannedOutageList.get(i).getCreator());
  77. wcBlackoutPlanVo.setCreateTime(plannedOutageList.get(i).getCreateTime());
  78. wcBlackoutPlanVo.setSiteName(plannedOutageList.get(i).getSiteName());
  79. wcBlackoutPlanVo.setId(plannedOutageList.get(i).getId());
  80. if (plannedOutageList.get(i).getStartTime().getTime() > new Date().getTime()) {
  81. wcBlackoutPlanVo.setType(1);
  82. } else if (plannedOutageList.get(i).getStartTime().getTime() < new Date().getTime() && plannedOutageList.get(i).getEndTime().getTime() > new Date().getTime()) {
  83. wcBlackoutPlanVo.setType(2);
  84. } else if (plannedOutageList.get(i).getEndTime().getTime() < new Date().getTime()) {
  85. wcBlackoutPlanVo.setType(3);
  86. }
  87. plannedOutageListOne.add(wcBlackoutPlanVo);
  88. }
  89. }
  90. return new CommonPage<>(plannedOutageListOne, total, plannedOutageVo.getSize(), plannedOutageVo.getCurrent());
  91. }
  92. @Override
  93. public String outagePlanListExport(String startTime, String endTime, Integer type) {
  94. Workbook workbook = null;
  95. File file = null;
  96. try {
  97. ExportParams params = new ExportParams(null, "停电计划列表");
  98. workbook = ExcelExportUtil.exportBigExcel(params, WcBlackoutPlanOneExportVo.class,
  99. (o, i) -> {
  100. int startCurrent = (i - 1) * 30;
  101. List<WcBlackoutPlanOneVo> plannedOutageList = this.wcBlackoutPlanOneVolist(startTime, endTime, type, startCurrent);
  102. return new ArrayList<>(BeanMapperUtils.mapList(plannedOutageList, WcBlackoutPlanOneVo.class, WcBlackoutPlanOneExportVo.class));
  103. }, null);
  104. if (null != workbook) {
  105. file = FileUtils.getFile(GlobalUtils.getTempBaseDir(), String.format("%s-%s.xlsx", "停电计划列表", System.currentTimeMillis() + ""));
  106. FileUtils.createFile(file.getAbsolutePath());
  107. FileOutputStream allListingFileOutputStream = new FileOutputStream(file);
  108. workbook.write(allListingFileOutputStream);
  109. } else {
  110. throw new BusinessException("表格数据为空");
  111. }
  112. } catch (Exception e) {
  113. log.error("导出文件失败", e);
  114. throw new BusinessException("导出文件失败");
  115. } finally {
  116. if (workbook != null) {
  117. try {
  118. workbook.close();
  119. } catch (IOException e) {
  120. log.error("===export spec=== 关闭workbook失败", e);
  121. }
  122. }
  123. }
  124. return file.getName();
  125. }
  126. @Override
  127. public List<WcBlackoutPlanOneVo> wcBlackoutPlanOneVolist(String startTime, String endTime, Integer type, Integer startCurrent) {
  128. List<WcBlackoutPlanOneVo> plannedOutageListOne = new ArrayList<>();
  129. DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  130. List<WcBlackoutPlanVo> plannedOutageList = baseMapper.plannedOutageList(startTime, endTime, type, 0, 30, startCurrent);
  131. if (plannedOutageList.size() > 0) {
  132. for (int j = 0; j < plannedOutageList.size(); j++) {
  133. WcBlackoutPlanOneVo wcBlackoutPlanVo = new WcBlackoutPlanOneVo();
  134. wcBlackoutPlanVo.setEndTime(format1.format(plannedOutageList.get(j).getEndTime()));
  135. wcBlackoutPlanVo.setContacts(plannedOutageList.get(j).getContacts());
  136. wcBlackoutPlanVo.setStartTime(format1.format(plannedOutageList.get(j).getStartTime()));
  137. wcBlackoutPlanVo.setEnable(plannedOutageList.get(j).getEnable());
  138. wcBlackoutPlanVo.setCreator(plannedOutageList.get(j).getCreator());
  139. wcBlackoutPlanVo.setCreateTime(format1.format(plannedOutageList.get(j).getCreateTime()));
  140. wcBlackoutPlanVo.setPhone(plannedOutageList.get(j).getPhone());
  141. wcBlackoutPlanVo.setSiteName(plannedOutageList.get(j).getSiteName());
  142. wcBlackoutPlanVo.setId(plannedOutageList.get(j).getId());
  143. wcBlackoutPlanVo.setPlanType(plannedOutageList.get(j).getPlanType());
  144. wcBlackoutPlanVo.setSiteId(plannedOutageList.get(j).getSiteId());
  145. if (plannedOutageList.get(j).getStartTime().getTime() > new Date().getTime()) {
  146. wcBlackoutPlanVo.setType("未执行");
  147. } else if (plannedOutageList.get(j).getStartTime().getTime() < new Date().getTime() && plannedOutageList.get(j).getEndTime().getTime() > new Date().getTime()) {
  148. wcBlackoutPlanVo.setType("执行中");
  149. } else if (plannedOutageList.get(j).getEndTime().getTime() < new Date().getTime()) {
  150. wcBlackoutPlanVo.setType("已执行");
  151. }
  152. plannedOutageListOne.add(wcBlackoutPlanVo);
  153. }
  154. }
  155. return plannedOutageListOne;
  156. }
  157. }