123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- package com.bizmatics.service.impl;
- import cn.afterturn.easypoi.excel.ExcelExportUtil;
- import cn.afterturn.easypoi.excel.entity.ExportParams;
- import com.bizmatics.common.core.bean.CommonPage;
- import com.bizmatics.common.core.exception.BusinessException;
- import com.bizmatics.common.core.util.BeanMapperUtils;
- import com.bizmatics.common.core.util.FileUtils;
- import com.bizmatics.common.mvc.base.AbstractCrudService;
- import com.bizmatics.common.spring.util.GlobalUtils;
- import com.bizmatics.model.WcBlackoutPlan;
- import com.bizmatics.model.system.SysUser;
- import com.bizmatics.model.vo.PlannedOutageVo;
- import com.bizmatics.model.vo.WcBlackoutPlanOneVo;
- import com.bizmatics.model.vo.WcBlackoutPlanVo;
- import com.bizmatics.persistence.mapper.WcBlackoutPlanMapper;
- import com.bizmatics.service.WcBlackoutPlanService;
- import com.bizmatics.service.util.SecurityUtils;
- import com.bizmatics.service.vo.WcBlackoutPlanOneExportVo;
- import org.apache.poi.ss.usermodel.Workbook;
- import org.springframework.stereotype.Service;
- import java.io.File;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.text.DateFormat;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.List;
- /**
- * 计划停电
- *
- * @author ya
- * @since 2021-07-07
- */
- @Service
- public class WcBlackoutPlanServiceImpl extends AbstractCrudService<WcBlackoutPlanMapper, WcBlackoutPlan> implements WcBlackoutPlanService {
- @Override
- public void plannedOutageAdd(WcBlackoutPlan wcBlackoutPlan) {
- SysUser user = SecurityUtils.getLoginUser().getUser();
- wcBlackoutPlan.setEnable(1);
- wcBlackoutPlan.setCreator(user.getUserName());
- wcBlackoutPlan.setCreateTime(new Date());
- this.save(wcBlackoutPlan);
- }
- @Override
- public void plannedOutageUpdate(WcBlackoutPlan wcBlackoutPlan) {
- this.updateById(wcBlackoutPlan);
- }
- @Override
- public void plannedOutageDel(int id) {
- WcBlackoutPlan wcBlackoutPlan = new WcBlackoutPlan();
- wcBlackoutPlan.setId(id);
- wcBlackoutPlan.setEnable(0);
- this.updateById(wcBlackoutPlan);
- }
- @Override
- public CommonPage<WcBlackoutPlanVo> plannedOutageList(PlannedOutageVo plannedOutageVo) {
- List<WcBlackoutPlanVo> wcBlackoutPlanVoListOne = baseMapper.plannedOutageList(plannedOutageVo.getStartTime(), plannedOutageVo.getEndTime(), plannedOutageVo.getType(), plannedOutageVo.getId(), 0, null);
- int total = 0;
- if (wcBlackoutPlanVoListOne.size() > 0) {
- total = wcBlackoutPlanVoListOne.size();
- }
- int startCurrent = (plannedOutageVo.getCurrent() - 1) * plannedOutageVo.getSize();
- List<WcBlackoutPlanVo> plannedOutageList = baseMapper.plannedOutageList(plannedOutageVo.getStartTime(), plannedOutageVo.getEndTime(), plannedOutageVo.getType(), plannedOutageVo.getId(), plannedOutageVo.getSize(), startCurrent);
- List<WcBlackoutPlanVo> plannedOutageListOne = new ArrayList<>();
- if (plannedOutageList.size() > 0) {
- for (int i = 0; i < plannedOutageList.size(); i++) {
- WcBlackoutPlanVo wcBlackoutPlanVo = new WcBlackoutPlanVo();
- wcBlackoutPlanVo.setSiteId(plannedOutageList.get(i).getSiteId());
- wcBlackoutPlanVo.setPlanType(plannedOutageList.get(i).getPlanType());
- wcBlackoutPlanVo.setStartTime(plannedOutageList.get(i).getStartTime());
- wcBlackoutPlanVo.setEndTime(plannedOutageList.get(i).getEndTime());
- wcBlackoutPlanVo.setContacts(plannedOutageList.get(i).getContacts());
- wcBlackoutPlanVo.setPhone(plannedOutageList.get(i).getPhone());
- wcBlackoutPlanVo.setEnable(plannedOutageList.get(i).getEnable());
- wcBlackoutPlanVo.setCreator(plannedOutageList.get(i).getCreator());
- wcBlackoutPlanVo.setCreateTime(plannedOutageList.get(i).getCreateTime());
- wcBlackoutPlanVo.setSiteName(plannedOutageList.get(i).getSiteName());
- wcBlackoutPlanVo.setId(plannedOutageList.get(i).getId());
- if (plannedOutageList.get(i).getStartTime().getTime() > new Date().getTime()) {
- wcBlackoutPlanVo.setType(1);
- } else if (plannedOutageList.get(i).getStartTime().getTime() < new Date().getTime() && plannedOutageList.get(i).getEndTime().getTime() > new Date().getTime()) {
- wcBlackoutPlanVo.setType(2);
- } else if (plannedOutageList.get(i).getEndTime().getTime() < new Date().getTime()) {
- wcBlackoutPlanVo.setType(3);
- }
- plannedOutageListOne.add(wcBlackoutPlanVo);
- }
- }
- return new CommonPage<>(plannedOutageListOne, total, plannedOutageVo.getSize(), plannedOutageVo.getCurrent());
- }
- @Override
- public String outagePlanListExport(String startTime, String endTime, Integer type) {
- Workbook workbook = null;
- File file = null;
- try {
- ExportParams params = new ExportParams(null, "停电计划列表");
- workbook = ExcelExportUtil.exportBigExcel(params, WcBlackoutPlanOneExportVo.class,
- (o, i) -> {
- int startCurrent = (i - 1) * 30;
- List<WcBlackoutPlanOneVo> plannedOutageList = this.wcBlackoutPlanOneVolist(startTime, endTime, type, startCurrent);
- return new ArrayList<>(BeanMapperUtils.mapList(plannedOutageList, WcBlackoutPlanOneVo.class, WcBlackoutPlanOneExportVo.class));
- }, null);
- if (null != workbook) {
- file = FileUtils.getFile(GlobalUtils.getTempBaseDir(), String.format("%s-%s.xlsx", "停电计划列表", System.currentTimeMillis() + ""));
- FileUtils.createFile(file.getAbsolutePath());
- FileOutputStream allListingFileOutputStream = new FileOutputStream(file);
- workbook.write(allListingFileOutputStream);
- } else {
- throw new BusinessException("表格数据为空");
- }
- } catch (Exception e) {
- log.error("导出文件失败", e);
- throw new BusinessException("导出文件失败");
- } finally {
- if (workbook != null) {
- try {
- workbook.close();
- } catch (IOException e) {
- log.error("===export spec=== 关闭workbook失败", e);
- }
- }
- }
- return file.getName();
- }
- @Override
- public List<WcBlackoutPlanOneVo> wcBlackoutPlanOneVolist(String startTime, String endTime, Integer type, Integer startCurrent) {
- List<WcBlackoutPlanOneVo> plannedOutageListOne = new ArrayList<>();
- DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- List<WcBlackoutPlanVo> plannedOutageList = baseMapper.plannedOutageList(startTime, endTime, type, 0, 30, startCurrent);
- if (plannedOutageList.size() > 0) {
- for (int j = 0; j < plannedOutageList.size(); j++) {
- WcBlackoutPlanOneVo wcBlackoutPlanVo = new WcBlackoutPlanOneVo();
- wcBlackoutPlanVo.setEndTime(format1.format(plannedOutageList.get(j).getEndTime()));
- wcBlackoutPlanVo.setContacts(plannedOutageList.get(j).getContacts());
- wcBlackoutPlanVo.setStartTime(format1.format(plannedOutageList.get(j).getStartTime()));
- wcBlackoutPlanVo.setEnable(plannedOutageList.get(j).getEnable());
- wcBlackoutPlanVo.setCreator(plannedOutageList.get(j).getCreator());
- wcBlackoutPlanVo.setCreateTime(format1.format(plannedOutageList.get(j).getCreateTime()));
- wcBlackoutPlanVo.setPhone(plannedOutageList.get(j).getPhone());
- wcBlackoutPlanVo.setSiteName(plannedOutageList.get(j).getSiteName());
- wcBlackoutPlanVo.setId(plannedOutageList.get(j).getId());
- wcBlackoutPlanVo.setPlanType(plannedOutageList.get(j).getPlanType());
- wcBlackoutPlanVo.setSiteId(plannedOutageList.get(j).getSiteId());
- if (plannedOutageList.get(j).getStartTime().getTime() > new Date().getTime()) {
- wcBlackoutPlanVo.setType("未执行");
- } else if (plannedOutageList.get(j).getStartTime().getTime() < new Date().getTime() && plannedOutageList.get(j).getEndTime().getTime() > new Date().getTime()) {
- wcBlackoutPlanVo.setType("执行中");
- } else if (plannedOutageList.get(j).getEndTime().getTime() < new Date().getTime()) {
- wcBlackoutPlanVo.setType("已执行");
- }
- plannedOutageListOne.add(wcBlackoutPlanVo);
- }
- }
- return plannedOutageListOne;
- }
- }
|