Bläddra i källkod

【NEW】新增导出全面检查记录,零部件更换记录,隔离开关检测记录,导出excel功能。

fenghao 4 år sedan
förälder
incheckning
3ae10b13a8
15 ändrade filer med 149 tillägg och 35 borttagningar
  1. 11 11
      railway-admin/src/main/java/com/railway/web/controller/business/catenary/BusJcbGlkgController.java
  2. 15 11
      railway-admin/src/main/java/com/railway/web/controller/business/catenary/BusJcebLbjghjlController.java
  3. 15 11
      railway-admin/src/main/java/com/railway/web/controller/business/catenary/BusJcebQmjcjlController.java
  4. 2 0
      railway-business/src/main/java/com/railway/business/catenary/service/IBusJcbGlkgService.java
  5. 2 0
      railway-business/src/main/java/com/railway/business/catenary/service/IBusJcebLbjghjlService.java
  6. 2 0
      railway-business/src/main/java/com/railway/business/catenary/service/IBusJcebQmjcjlService.java
  7. 23 0
      railway-business/src/main/java/com/railway/business/catenary/service/impl/BusJcbGlkgServiceImpl.java
  8. 12 1
      railway-business/src/main/java/com/railway/business/catenary/service/impl/BusJcebLbjghjlServiceImpl.java
  9. 11 1
      railway-business/src/main/java/com/railway/business/catenary/service/impl/BusJcebQmjcjlServiceImpl.java
  10. BIN
      railway-business/src/main/resources/excel/template/全面检查记录.xls
  11. BIN
      railway-business/src/main/resources/excel/template/隔离开关检测记录.xls
  12. BIN
      railway-business/src/main/resources/excel/template/零部件更换记录.xls
  13. 6 0
      railway-common/src/main/java/com/railway/common/utils/StringUtils.java
  14. 11 0
      railway-common/src/main/java/com/railway/common/utils/poi/EasyExcelUtil.java
  15. 39 0
      railway-common/src/main/java/com/railway/common/utils/poi/LocalDateConverter.java

+ 11 - 11
railway-admin/src/main/java/com/railway/web/controller/business/catenary/BusJcbGlkgController.java

@@ -11,20 +11,13 @@ import com.railway.common.utils.poi.WordUtils;
 import com.railway.system.service.ISysFileService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+import javax.validation.Valid;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import javax.validation.Valid;
-import org.springframework.validation.annotation.Validated;
-import org.springframework.web.bind.annotation.DeleteMapping;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.PutMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
 
 /**
  * @author fenghao
@@ -100,6 +93,13 @@ public class BusJcbGlkgController extends BaseController {
         return getDataTable(list);
     }
 
+    @ApiOperation(value = "导出excel")
+    @GetMapping(value = "exportExcel")
+    public AjaxResult exportExcel(BusJcbGlkg busJcbGlkg) {
+        String localFilePath = busJcbGlkgService.exportExcel(busJcbGlkg);
+        return sysFileService.uploadFile(localFilePath);
+    }
+
     @ApiOperation(value = "获取上次检测值")
     @GetMapping(value = "getLastOne")
     public AjaxResult getLastOne(BusJcbGlkg busJcbGlkg) {

+ 15 - 11
railway-admin/src/main/java/com/railway/web/controller/business/catenary/BusJcebLbjghjlController.java

@@ -5,19 +5,14 @@ import com.railway.business.catenary.service.IBusJcebLbjghjlService;
 import com.railway.common.core.controller.BaseController;
 import com.railway.common.core.domain.AjaxResult;
 import com.railway.common.core.page.TableDataInfo;
+import com.railway.system.service.ISysFileService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
-import java.util.List;
-import javax.validation.Valid;
 import org.springframework.validation.annotation.Validated;
-import org.springframework.web.bind.annotation.DeleteMapping;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.PutMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
+
+import javax.validation.Valid;
+import java.util.List;
 
 /**
  * @author fenghao
@@ -29,9 +24,11 @@ import org.springframework.web.bind.annotation.RestController;
 public class BusJcebLbjghjlController extends BaseController {
 
     private final IBusJcebLbjghjlService busJcbLbjghjlService;
+    private final ISysFileService sysFileService;
 
-    public BusJcebLbjghjlController(IBusJcebLbjghjlService busJcbLbjghjlService) {
+    public BusJcebLbjghjlController(IBusJcebLbjghjlService busJcbLbjghjlService, ISysFileService sysFileService) {
         this.busJcbLbjghjlService = busJcbLbjghjlService;
+        this.sysFileService = sysFileService;
     }
 
     @ApiOperation(value = "新增")
@@ -69,6 +66,13 @@ public class BusJcebLbjghjlController extends BaseController {
         return getDataTable(list);
     }
 
+    @ApiOperation(value = "导出excel")
+    @GetMapping(value = "exportExcel")
+    public AjaxResult exportExcel(BusJcebLbjghjl busJcebLbjghjl) {
+        String localFilePath = busJcbLbjghjlService.exportExcel(busJcebLbjghjl);
+        return sysFileService.uploadFile(localFilePath);
+    }
+
     @ApiOperation(value = "提交")
     @PutMapping("/submit")
     public AjaxResult submit(@RequestBody BusJcebLbjghjl busJcebLbjghjl) {

+ 15 - 11
railway-admin/src/main/java/com/railway/web/controller/business/catenary/BusJcebQmjcjlController.java

@@ -5,19 +5,14 @@ import com.railway.business.catenary.service.IBusJcebQmjcjlService;
 import com.railway.common.core.controller.BaseController;
 import com.railway.common.core.domain.AjaxResult;
 import com.railway.common.core.page.TableDataInfo;
+import com.railway.system.service.ISysFileService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
-import java.util.List;
-import javax.validation.Valid;
 import org.springframework.validation.annotation.Validated;
-import org.springframework.web.bind.annotation.DeleteMapping;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.PutMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
+
+import javax.validation.Valid;
+import java.util.List;
 
 /**
  * @author fenghao
@@ -29,9 +24,11 @@ import org.springframework.web.bind.annotation.RestController;
 public class BusJcebQmjcjlController extends BaseController {
 
     private final IBusJcebQmjcjlService busJcbQmjcjlService;
+    private final ISysFileService sysFileService;
 
-    public BusJcebQmjcjlController(IBusJcebQmjcjlService busJcbQmjcjlService) {
+    public BusJcebQmjcjlController(IBusJcebQmjcjlService busJcbQmjcjlService, ISysFileService sysFileService) {
         this.busJcbQmjcjlService = busJcbQmjcjlService;
+        this.sysFileService = sysFileService;
     }
 
     @ApiOperation(value = "新增")
@@ -69,6 +66,13 @@ public class BusJcebQmjcjlController extends BaseController {
         return getDataTable(list);
     }
 
+    @ApiOperation(value = "导出excel")
+    @GetMapping(value = "exportExcel")
+    public AjaxResult exportExcel(BusJcebQmjcjl busJcebQmjcjl) {
+        String localFilePath = busJcbQmjcjlService.exportExcel(busJcebQmjcjl);
+        return sysFileService.uploadFile(localFilePath);
+    }
+
     @ApiOperation(value = "提交")
     @PutMapping("/submit")
     public AjaxResult submit(@RequestBody BusJcebQmjcjl busJcebQmjcjl) {

+ 2 - 0
railway-business/src/main/java/com/railway/business/catenary/service/IBusJcbGlkgService.java

@@ -79,4 +79,6 @@ public interface IBusJcbGlkgService{
      */
     JcebRecordVo getCountByType(JcebQueryVo query);
 
+    String exportExcel(BusJcbGlkg busJcbGlkg);
+
 }

+ 2 - 0
railway-business/src/main/java/com/railway/business/catenary/service/IBusJcebLbjghjlService.java

@@ -10,4 +10,6 @@ import com.railway.business.catenary.domain.BusJcebLbjghjl;
  */
 public interface IBusJcebLbjghjlService extends IBusJcebService<BusJcebLbjghjl> {
 
+    String exportExcel(BusJcebLbjghjl busJcebLbjghjl);
+
 }

+ 2 - 0
railway-business/src/main/java/com/railway/business/catenary/service/IBusJcebQmjcjlService.java

@@ -10,4 +10,6 @@ import com.railway.business.catenary.domain.BusJcebQmjcjl;
  */
 public interface IBusJcebQmjcjlService extends IBusJcebService<BusJcebQmjcjl> {
 
+    String exportExcel(BusJcebQmjcjl busJcebQmjcjl);
+
 }

+ 23 - 0
railway-business/src/main/java/com/railway/business/catenary/service/impl/BusJcbGlkgServiceImpl.java

@@ -11,6 +11,8 @@ import com.railway.business.catenary.service.IBusJcbGlkgService;
 import com.railway.common.utils.StringUtils;
 import java.util.Date;
 import java.util.List;
+
+import com.railway.common.utils.poi.EasyExcelUtil;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 /**
@@ -147,4 +149,25 @@ public class BusJcbGlkgServiceImpl extends BusJcabServiceImpl implements IBusJcb
 		setQuery(query);
 		return busJcbGlkgMapper.getCountByType(query);
 	}
+
+	@Override
+	public String exportExcel(BusJcbGlkg busJcbGlkg) {
+		List<BusJcbGlkg> list = this.getList(busJcbGlkg);
+		this.formatList(list);
+		String fileName = "隔离开关检测记录.xls";
+		String templateFileName = "excel/template/隔离开关检测记录.xls";
+		return new EasyExcelUtil().writeExcel(fileName, templateFileName, list);
+	}
+
+	private void formatList(List<BusJcbGlkg> list) {
+		for (BusJcbGlkg busJcbGlkg : list) {
+			busJcbGlkg.setZcjyzztA(StringUtils.goodOrBad(busJcbGlkg.getZcjyzztA()));
+			busJcbGlkg.setYdfhsyA(StringUtils.goodOrBad(busJcbGlkg.getYdfhsyA()));
+			busJcbGlkg.setDdfhsyA(StringUtils.goodOrBad(busJcbGlkg.getDdfhsyA()));
+			busJcbGlkg.setSdfhsyA(StringUtils.goodOrBad(busJcbGlkg.getSdfhsyA()));
+			busJcbGlkg.setYxztA(StringUtils.goodOrBad(busJcbGlkg.getYxztA()));
+			busJcbGlkg.setJgxA(StringUtils.goodOrBad(busJcbGlkg.getJgxA()));
+		}
+	}
+
 }

+ 12 - 1
railway-business/src/main/java/com/railway/business/catenary/service/impl/BusJcebLbjghjlServiceImpl.java

@@ -5,10 +5,12 @@ import com.railway.business.catenary.domain.BusJcebLbjghjl;
 import com.railway.business.catenary.mapper.BusJcebLbjghjlMapper;
 import com.railway.business.catenary.service.IBusJcebLbjghjlService;
 import com.railway.common.utils.StringUtils;
-import java.util.List;
+import com.railway.common.utils.poi.EasyExcelUtil;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.util.List;
+
 /**
  * 检测表-零部件更换记录
  *
@@ -114,4 +116,13 @@ public class BusJcebLbjghjlServiceImpl extends BusJcebServiceImpl<BusJcebLbjghjl
     setConfirm(busJcebLbjghjl);
     return update(busJcebLbjghjl);
   }
+
+  @Override
+  public String exportExcel(BusJcebLbjghjl busJcebLbjghjl) {
+    List<BusJcebLbjghjl> list = this.getList(busJcebLbjghjl);
+    String fileName = "零部件更换记录.xls";
+    String templateFileName = "excel/template/零部件更换记录.xls";
+    return new EasyExcelUtil().writeExcel(fileName, templateFileName, list);
+  }
+
 }

+ 11 - 1
railway-business/src/main/java/com/railway/business/catenary/service/impl/BusJcebQmjcjlServiceImpl.java

@@ -5,10 +5,12 @@ import com.railway.business.catenary.domain.BusJcebQmjcjl;
 import com.railway.business.catenary.mapper.BusJcebQmjcjlMapper;
 import com.railway.business.catenary.service.IBusJcebQmjcjlService;
 import com.railway.common.utils.StringUtils;
-import java.util.List;
+import com.railway.common.utils.poi.EasyExcelUtil;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.util.List;
+
 /**
  * 检测表-全面检查记录
  *
@@ -114,4 +116,12 @@ public class BusJcebQmjcjlServiceImpl extends BusJcebServiceImpl<BusJcebQmjcjl>
     setConfirm(busJcebQmjcjl);
     return update(busJcebQmjcjl);
   }
+
+  @Override
+  public String exportExcel(BusJcebQmjcjl busJcebQmjcjl) {
+    List<BusJcebQmjcjl> list = this.getList(busJcebQmjcjl);
+    String fileName = "全面检查记录.xls";
+    String templateFileName = "excel/template/全面检查记录.xls";
+    return new EasyExcelUtil().writeExcel(fileName, templateFileName, list);
+  }
 }

BIN
railway-business/src/main/resources/excel/template/全面检查记录.xls


BIN
railway-business/src/main/resources/excel/template/隔离开关检测记录.xls


BIN
railway-business/src/main/resources/excel/template/零部件更换记录.xls


+ 6 - 0
railway-common/src/main/java/com/railway/common/utils/StringUtils.java

@@ -31,11 +31,17 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
   public static final String YES_VALUE = "1";
   private static final String NO = "×";
   private static final String SLASH = "/";
+  private static final String GOOD = "良好";
+  private static final String BAD = "恶劣";
 
   public static String yesOrNo(String value){
     return YES_VALUE.equals(value) ? YES : NO;
   }
 
+  public static String goodOrBad(String value) {
+    return YES_VALUE.equals(value) ? GOOD : BAD;
+  }
+
   public static String getSlash(String value){
     return StringUtils.isNoneBlank(value) ? value : SLASH;
   }

+ 11 - 0
railway-common/src/main/java/com/railway/common/utils/poi/EasyExcelUtil.java

@@ -10,6 +10,7 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.util.List;
 import java.util.Map;
 import java.util.UUID;
 
@@ -31,6 +32,16 @@ public class EasyExcelUtil {
         return filePath;
     }
 
+    public <T> String writeExcel(String fileName, String templateFileName, List<T> list) {
+        String filePath = FileUploadUtils.getAbsoluteFile(encodingFilename(fileName));
+        try (InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(templateFileName)) {
+            EasyExcel.write(filePath).withTemplate(is).registerConverter(new LocalDateConverter()).sheet().doFill(list);
+        } catch (IOException e) {
+            return null;
+        }
+        return filePath;
+    }
+
     /**
      * 编码文件名
      */

+ 39 - 0
railway-common/src/main/java/com/railway/common/utils/poi/LocalDateConverter.java

@@ -0,0 +1,39 @@
+package com.railway.common.utils.poi;
+
+import com.alibaba.excel.converters.Converter;
+import com.alibaba.excel.enums.CellDataTypeEnum;
+import com.alibaba.excel.metadata.CellData;
+import com.alibaba.excel.metadata.GlobalConfiguration;
+import com.alibaba.excel.metadata.property.ExcelContentProperty;
+import org.springframework.stereotype.Component;
+
+import java.time.LocalDate;
+import java.time.format.DateTimeFormatter;
+
+/**
+ * LocalDate类型转换器
+ */
+@Component
+public class LocalDateConverter implements Converter<LocalDate> {
+    @Override
+    public Class<LocalDate> supportJavaTypeKey() {
+        return LocalDate.class;
+    }
+
+    @Override
+    public CellDataTypeEnum supportExcelTypeKey() {
+        return CellDataTypeEnum.STRING;
+    }
+
+    @Override
+    public LocalDate convertToJavaData(CellData cellData, ExcelContentProperty excelContentProperty
+            , GlobalConfiguration globalConfiguration) throws Exception {
+        return LocalDate.parse(cellData.getStringValue(), DateTimeFormatter.ofPattern("yyyy-MM-dd"));
+    }
+
+    @Override
+    public CellData convertToExcelData(LocalDate localDate, ExcelContentProperty excelContentProperty
+            , GlobalConfiguration globalConfiguration) throws Exception {
+        return new CellData<>(localDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
+    }
+}