Ver Fonte

目标展板导入和模板下载修改

zx há 6 meses atrás
pai
commit
856a1c8dba

BIN
ruoyi-admin/src/main/resources/excelTemplate/stopTarget.xlsx


+ 6 - 0
ruoyi-powerdistribution/pom.xml

@@ -43,6 +43,12 @@
             <version>1.2.83</version>
             <scope>compile</scope>
         </dependency>
+        <dependency>
+            <groupId>com.baomidou</groupId>
+            <artifactId>mybatis-plus-extension</artifactId>
+            <version>3.5.7</version>
+            <scope>compile</scope>
+        </dependency>
 
     </dependencies>
 

+ 9 - 6
ruoyi-powerdistribution/src/main/java/com/ruoyi/powerdistribution/controller/PdmStopTargeController.java

@@ -112,7 +112,7 @@ public class PdmStopTargeController extends BaseController
     @PostMapping("/downloadTemplate")
     @ApiOperation(value = "停电预算下载模板")
     public void downloadTemplate(HttpServletResponse response) {
-        String filePath = "excelTemplate/invoiceImport.xlsx";//未完成
+        String filePath = "excelTemplate/stopTarget.xlsx";//未完成
         byte[] buffer = new byte[1024];
         InputStream fis = Thread.currentThread().getContextClassLoader().getResourceAsStream(filePath);
         BufferedInputStream bis = null;
@@ -149,10 +149,13 @@ public class PdmStopTargeController extends BaseController
     @PostMapping("/import")
     @ApiOperation(value = "停电预算导入", notes = "停电预算导入")
     public R invoiceImport(@RequestParam("file") MultipartFile file,@RequestParam("reportYear") String reportYear) throws IOException {
-        //ImportExcelHelper<PdmStopTarge> helper = new ImportExcelHelper<>();
-        //List<PdmStopTarge> list = helper.getList(file.getInputStream(), PdmStopTarge.class, 0, 1);
-        logger.info("file" + file.getName());
-        logger.info("reportYear" + reportYear);
-        return R.ok("导入成功");
+        ImportExcelHelper<PdmStopTarge> helper = new ImportExcelHelper<>();
+        List<PdmStopTarge> list = helper.getList(file.getInputStream(), PdmStopTarge.class, 0, 2);
+        boolean resultFlag = pdmStopTargeService.batchSaveOrUpdate(list,reportYear);
+        if(resultFlag){
+            return R.ok("导入成功");
+        }
+        return R.fail("导入失败");
+
     }
 }

+ 51 - 2
ruoyi-powerdistribution/src/main/java/com/ruoyi/powerdistribution/domain/PdmStopTarge.java

@@ -1,6 +1,9 @@
 package com.ruoyi.powerdistribution.domain;
 
 import java.math.BigDecimal;
+
+import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
+import com.alibaba.excel.annotation.ExcelProperty;
 import org.apache.commons.lang3.builder.ToStringBuilder;
 import org.apache.commons.lang3.builder.ToStringStyle;
 import com.ruoyi.common.annotation.Excel;
@@ -12,6 +15,7 @@ import com.ruoyi.common.core.domain.BaseEntity;
  * @author ruoyi
  * @date 2024-12-09
  */
+@ExcelIgnoreUnannotated
 public class PdmStopTarge extends BaseEntity
 {
     private static final long serialVersionUID = 1L;
@@ -28,182 +32,227 @@ public class PdmStopTarge extends BaseEntity
     private String companyNo;
 
     /** 单位名称 */
-    @Excel(name = "单位名称")
+    @ExcelProperty(index = 0)
+    @Excel(name = "单位")
     private String companyName;
 
     /** 平均停电时长目标 */
-    @Excel(name = "平均停电时长目标")
+    @ExcelProperty(index = 1)
+    @Excel(name = "中压用户平均停电时长目标(小时)")
     private BigDecimal stopTimeAvg;
 
     /** 等效总用户数 */
+    @ExcelProperty(index = 2)
     @Excel(name = "等效总用户数")
     private BigDecimal userTotal;
 
     /** 停电总时长目标 */
+    @ExcelProperty(index = 3)
     @Excel(name = "停电总时长目标")
     private BigDecimal stopTimeTotal;
 
     /** 3年占比 */
+    @ExcelProperty(index = 4)
     @Excel(name = "3年占比")
     private String threeYearRatio;
 
     /** 预安排停电总时长目标 */
+    @ExcelProperty(index = 5)
     @Excel(name = "预安排停电总时长目标")
     private BigDecimal planStopTimeTotal;
 
     /** 预安排平均停电时长目标 */
+    @ExcelProperty(index = 6)
     @Excel(name = "预安排平均停电时长目标")
     private BigDecimal planStopTimeAvg;
 
     /** 故障停电总时长目标 */
+    @ExcelProperty(index = 7)
     @Excel(name = "故障停电总时长目标")
     private BigDecimal errorStopTimeTotal;
 
     /** 故障平均停电时长目标 */
+    @ExcelProperty(index = 8)
     @Excel(name = "故障平均停电时长目标")
     private BigDecimal errorStopTimeAvg;
 
     /** 停电月度时长-1月 */
+    @ExcelProperty(index = 9)
     @Excel(name = "停电月度时长-1月")
     private BigDecimal stopTimeMonth01;
 
     /** 停电月度时长-2月 */
+    @ExcelProperty(index = 10)
     @Excel(name = "停电月度时长-2月")
     private BigDecimal stopTimeMonth02;
 
     /** 停电月度时长-3月 */
+    @ExcelProperty(index = 11)
     @Excel(name = "停电月度时长-3月")
     private BigDecimal stopTimeMonth03;
 
     /** 停电月度时长-4月 */
+    @ExcelProperty(index = 12)
     @Excel(name = "停电月度时长-4月")
     private BigDecimal stopTimeMonth04;
 
     /** 停电月度时长-5月 */
+    @ExcelProperty(index = 13)
     @Excel(name = "停电月度时长-5月")
     private BigDecimal stopTimeMonth05;
 
     /** 停电月度时长-6月 */
+    @ExcelProperty(index = 14)
     @Excel(name = "停电月度时长-6月")
     private BigDecimal stopTimeMonth06;
 
     /** 停电月度时长-7月 */
+    @ExcelProperty(index = 15)
     @Excel(name = "停电月度时长-7月")
     private BigDecimal stopTimeMonth07;
 
     /** 停电月度时长-8月 */
+    @ExcelProperty(index = 16)
     @Excel(name = "停电月度时长-8月")
     private BigDecimal stopTimeMonth08;
 
     /** 停电月度时长-9月 */
+    @ExcelProperty(index = 17)
     @Excel(name = "停电月度时长-9月")
     private BigDecimal stopTimeMonth09;
 
     /** 停电月度时长-10月 */
+    @ExcelProperty(index = 18)
     @Excel(name = "停电月度时长-10月")
     private BigDecimal stopTimeMonth10;
 
     /** 停电月度时长-11月 */
+    @ExcelProperty(index = 19)
     @Excel(name = "停电月度时长-11月")
     private BigDecimal stopTimeMonth11;
 
     /** 停电月度时长-12月 */
+    @ExcelProperty(index = 20)
     @Excel(name = "停电月度时长-12月")
     private BigDecimal stopTimeMonth12;
 
     /** 预安排停电月度时长-1月 */
+    @ExcelProperty(index = 21)
     @Excel(name = "预安排停电月度时长-1月")
     private BigDecimal planStopTimeMonth01;
 
     /** 预安排停电月度时长-2月 */
+    @ExcelProperty(index = 22)
     @Excel(name = "预安排停电月度时长-2月")
     private BigDecimal planStopTimeMonth02;
 
     /** 预安排停电月度时长-3月 */
+    @ExcelProperty(index = 23)
     @Excel(name = "预安排停电月度时长-3月")
     private BigDecimal planStopTimeMonth03;
 
     /** 预安排停电月度时长-4月 */
+    @ExcelProperty(index = 24)
     @Excel(name = "预安排停电月度时长-4月")
     private BigDecimal planStopTimeMonth04;
 
     /** 预安排停电月度时长-5月 */
+    @ExcelProperty(index = 25)
     @Excel(name = "预安排停电月度时长-5月")
     private BigDecimal planStopTimeMonth05;
 
     /** 预安排停电月度时长-6月 */
+    @ExcelProperty(index = 26)
     @Excel(name = "预安排停电月度时长-6月")
     private BigDecimal planStopTimeMonth06;
 
     /** 预安排停电月度时长-7月 */
+    @ExcelProperty(index = 27)
     @Excel(name = "预安排停电月度时长-7月")
     private BigDecimal planStopTimeMonth07;
 
     /** 预安排停电月度时长-8月 */
+    @ExcelProperty(index = 28)
     @Excel(name = "预安排停电月度时长-8月")
     private BigDecimal planStopTimeMonth08;
 
     /** 预安排停电月度时长-9月 */
+    @ExcelProperty(index = 29)
     @Excel(name = "预安排停电月度时长-9月")
     private BigDecimal planStopTimeMonth09;
 
     /** 预安排停电月度时长-10月 */
+    @ExcelProperty(index = 30)
     @Excel(name = "预安排停电月度时长-10月")
     private BigDecimal planStopTimeMonth10;
 
     /** 预安排停电月度时长-11月 */
+    @ExcelProperty(index = 31)
     @Excel(name = "预安排停电月度时长-11月")
     private BigDecimal planStopTimeMonth11;
 
     /** 预安排停电月度时长-12月 */
+    @ExcelProperty(index = 32)
     @Excel(name = "预安排停电月度时长-12月")
     private BigDecimal planStopTimeMonth12;
 
     /** 故障停电月度时长-1月 */
+    @ExcelProperty(index = 33)
     @Excel(name = "故障停电月度时长-1月")
     private BigDecimal errorStopTimeMonth01;
 
     /** 故障停电月度时长-2月 */
+    @ExcelProperty(index = 34)
     @Excel(name = "故障停电月度时长-2月")
     private BigDecimal errorStopTimeMonth02;
 
     /** 故障停电月度时长-3月 */
+    @ExcelProperty(index = 35)
     @Excel(name = "故障停电月度时长-3月")
     private BigDecimal errorStopTimeMonth03;
 
     /** 故障停电月度时长-4月 */
+    @ExcelProperty(index = 36)
     @Excel(name = "故障停电月度时长-4月")
     private BigDecimal errorStopTimeMonth04;
 
     /** 故障停电月度时长-5月 */
+    @ExcelProperty(index = 37)
     @Excel(name = "故障停电月度时长-5月")
     private BigDecimal errorStopTimeMonth05;
 
     /** 故障停电月度时长-6月 */
+    @ExcelProperty(index = 38)
     @Excel(name = "故障停电月度时长-6月")
     private BigDecimal errorStopTimeMonth06;
 
     /** 故障停电月度时长-7月 */
+    @ExcelProperty(index = 39)
     @Excel(name = "故障停电月度时长-7月")
     private BigDecimal errorStopTimeMonth07;
 
     /** 故障停电月度时长-8月 */
+    @ExcelProperty(index = 40)
     @Excel(name = "故障停电月度时长-8月")
     private BigDecimal errorStopTimeMonth08;
 
     /** 故障停电月度时长-9月 */
+    @ExcelProperty(index = 41)
     @Excel(name = "故障停电月度时长-9月")
     private BigDecimal errorStopTimeMonth09;
 
     /** 故障停电月度时长-10月 */
+    @ExcelProperty(index = 42)
     @Excel(name = "故障停电月度时长-10月")
     private BigDecimal errorStopTimeMonth10;
 
     /** 故障停电月度时长-11月 */
+    @ExcelProperty(index = 43)
     @Excel(name = "故障停电月度时长-11月")
     private BigDecimal errorStopTimeMonth11;
 
     /** 故障停电月度时长-12月 */
+    @ExcelProperty(index = 44)
     @Excel(name = "故障停电月度时长-12月")
     private BigDecimal errorStopTimeMonth12;
 

+ 3 - 1
ruoyi-powerdistribution/src/main/java/com/ruoyi/powerdistribution/mapper/PdmStopTargeMapper.java

@@ -1,6 +1,8 @@
 package com.ruoyi.powerdistribution.mapper;
 
 import java.util.List;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.ruoyi.powerdistribution.domain.PdmStopTarge;
 
 /**
@@ -9,7 +11,7 @@ import com.ruoyi.powerdistribution.domain.PdmStopTarge;
  * @author ruoyi
  * @date 2024-12-09
  */
-public interface PdmStopTargeMapper
+public interface PdmStopTargeMapper extends BaseMapper<PdmStopTarge>
 {
     /**
      * 查询停电预算

+ 8 - 0
ruoyi-powerdistribution/src/main/java/com/ruoyi/powerdistribution/service/IPdmStopTargeService.java

@@ -58,4 +58,12 @@ public interface IPdmStopTargeService
      * @return 结果
      */
     public int deletePdmStopTargeById(Long id);
+
+    /**
+     * 按年份批量保存
+     * @param list
+     * @param reportYear 目标年份
+     * @return
+     */
+    boolean batchSaveOrUpdate(List<PdmStopTarge> list,String reportYear);
 }

+ 17 - 2
ruoyi-powerdistribution/src/main/java/com/ruoyi/powerdistribution/service/impl/PdmStopTargeServiceImpl.java

@@ -1,12 +1,16 @@
 package com.ruoyi.powerdistribution.service.impl;
 
 import java.util.List;
+
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.ruoyi.common.utils.DateUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.ruoyi.powerdistribution.mapper.PdmStopTargeMapper;
 import com.ruoyi.powerdistribution.domain.PdmStopTarge;
 import com.ruoyi.powerdistribution.service.IPdmStopTargeService;
+import org.springframework.transaction.annotation.Transactional;
 
 /**
  * 停电预算Service业务层处理
@@ -15,7 +19,7 @@ import com.ruoyi.powerdistribution.service.IPdmStopTargeService;
  * @date 2024-12-09
  */
 @Service
-public class PdmStopTargeServiceImpl implements IPdmStopTargeService
+public class PdmStopTargeServiceImpl extends ServiceImpl<PdmStopTargeMapper,PdmStopTarge> implements IPdmStopTargeService
 {
     @Autowired
     private PdmStopTargeMapper pdmStopTargeMapper;
@@ -54,7 +58,7 @@ public class PdmStopTargeServiceImpl implements IPdmStopTargeService
     public int insertPdmStopTarge(PdmStopTarge pdmStopTarge)
     {
         pdmStopTarge.setCreateTime(DateUtils.getNowDate());
-        return pdmStopTargeMapper.insertPdmStopTarge(pdmStopTarge);
+        return pdmStopTargeMapper.insert(pdmStopTarge);
     }
 
     /**
@@ -93,4 +97,15 @@ public class PdmStopTargeServiceImpl implements IPdmStopTargeService
     {
         return pdmStopTargeMapper.deletePdmStopTargeById(id);
     }
+
+    @Override
+    @Transactional
+    public boolean batchSaveOrUpdate(List<PdmStopTarge> list,String reportYear) {
+        this.remove(new LambdaUpdateWrapper<PdmStopTarge>().eq(PdmStopTarge::getReportYear,reportYear));
+        for(PdmStopTarge target:list){
+            target.setReportYear(reportYear);
+            pdmStopTargeMapper.insertPdmStopTarge(target);
+        }
+        return true;
+    }
 }