fengjin
2022-11-08 17f1c3a86565cb9fbda2e28896066acb7b8f29b6
工单可以批量导入
3个文件已修改
90 ■■■■■ 已修改文件
flower_city/src/main/java/com/dg/core/controller/TransactionEventController.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
flower_city/src/main/java/com/dg/core/service/ITransactionEventService.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
flower_city/src/main/java/com/dg/core/service/impl/TransactionEventImpl.java 76 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
flower_city/src/main/java/com/dg/core/controller/TransactionEventController.java
@@ -303,11 +303,15 @@
    {
        boolean a = false;
        String fileName = file.getOriginalFilename();
        boolean b = iTransactionEventService.batchImport(fileName, file);
        if (b){
            return  ResultData.success("导入成功");
         Integer b = iTransactionEventService.batchImport(fileName, file);
        if (b == 3) {//
            return ResultData.success("全部导入成功");//全部导入成功
        } else if (b == 2) {
            return ResultData.success("部分导入成功");//部分导入成功
        } else if (b == 0) {
            return ResultData.error("部分失败");//导入失败
        }
        return   ResultData.error("导入失败");
        return ResultData.error("部分失败");//导入失败
    }
flower_city/src/main/java/com/dg/core/service/ITransactionEventService.java
@@ -151,6 +151,6 @@
     * @return
     */
    List<TransactionEvent> selectClassifyList(List<String> ids);
    boolean batchImport(String fileName, MultipartFile file) ;
    Integer batchImport(String fileName, MultipartFile file) ;
}
flower_city/src/main/java/com/dg/core/service/impl/TransactionEventImpl.java
@@ -12,9 +12,7 @@
import com.dg.core.service.ITransactionEventService;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -253,15 +251,14 @@
    public List<TransactionEvent> selectList(String keyWord) {
        if (keyWord!=null&&keyWord!=""){
            return baseMapper.selectList(new QueryWrapper<TransactionEvent>().lambda().like(TransactionEvent::getMatterName,keyWord));
        }
        else {
        } else {
        return baseMapper.selectList(new QueryWrapper<TransactionEvent>().lambda());
        }
    }
    @Override
    public boolean batchImport(String fileName, MultipartFile file)  {
    public Integer batchImport(String fileName, MultipartFile file) {
        boolean notNull = false;
        if (!fileName.matches("^.+\\.(?i)(xls)$") && !fileName.matches("^.+\\.(?i)(xlsx)$")) {
            throw   new RuntimeException("选择文件格式不正确,请下载模板上传");
@@ -291,26 +288,29 @@
                throw new RuntimeException(e);
            }
        }
        Integer failNum = 0;//失败数量
        // 获取excel的sheet页数
        int numberOfSheets = wb.getNumberOfSheets();
        for (int j = 0; j < numberOfSheets; j++) {
        //获取excel字段名称进行比较
        Sheet sheetAt = wb.getSheetAt(0);
            Sheet sheetAt = wb.getSheetAt(j);
            if(sheetAt.getRow(2)!=null){
        Row row1 = sheetAt.getRow(2);
        TransactionEvent transactionEvent = baseMapper.selectOne(new QueryWrapper<TransactionEvent>().lambda().eq(TransactionEvent::getMatterName, row1.getCell(1).getStringCellValue()));
            TransactionEvent transactionEvent = baseMapper.selectOne(new QueryWrapper<TransactionEvent>().lambda().eq(TransactionEvent::getMatterName, new DataFormatter().formatCellValue(row1.getCell(1))));
        boolean isAdd=false;
        if(transactionEvent==null){
            transactionEvent=new TransactionEvent();
            isAdd=true;
        }
        transactionEvent.setMatterName(row1.getCell(1).getStringCellValue());
            transactionEvent.setMatterName(new DataFormatter().formatCellValue(row1.getCell(1)));
        Row row2 = sheetAt.getRow(3);
        transactionEvent.setSetGist("<p>"+row2.getCell(1).getStringCellValue()+"</p>");
            transactionEvent.setSetGist("<p>" + new DataFormatter().formatCellValue(row2.getCell(1)) + "</p>");
        Row row3 = sheetAt.getRow(4);
        Row row4 = sheetAt.getRow(5);
        transactionEvent.setBasicInformation("<p> 事项名称:"+row1.getCell(1).getStringCellValue()+"<br />"
            +row3.getCell(0).getStringCellValue()+":"+row3.getCell(1).getStringCellValue()+"<br />"
            +row3.getCell(3).getStringCellValue()+":"+row3.getCell(4).getStringCellValue()+"<br />"
                +row4.getCell(0).getStringCellValue()+":"+row4.getCell(1).getStringCellValue()+"</p>");
            transactionEvent.setBasicInformation("<p> 事项名称:" + new DataFormatter().formatCellValue(row1.getCell(1)) + "<br />"
                    + new DataFormatter().formatCellValue(row3.getCell(0)) + ":" + new DataFormatter().formatCellValue(row3.getCell(1))+ "<br />"
                    + new DataFormatter().formatCellValue(row3.getCell(3)) + ":" + new DataFormatter().formatCellValue(row3.getCell(4)) + "<br />"
                    + new DataFormatter().formatCellValue(row4.getCell(0)) + ":" + new DataFormatter().formatCellValue(row4.getCell(1)) + "</p>");
        int i=7;
        String applicationMaterial="<p>";
        while (true){
@@ -319,10 +319,10 @@
                i=i+2;
                break;
            }
            applicationMaterial=applicationMaterial+"办理区域:"+row.getCell(0).getStringCellValue()+"<br />"
                    +"咨询电话:"+row.getCell(1).getStringCellValue()+"<br />"
                    +"办公地址:"+row.getCell(2).getStringCellValue()+"<br />"
                    +"办公时间:"+row.getCell(3).getStringCellValue()+"<br />";
                applicationMaterial = applicationMaterial + "办理区域:" + new DataFormatter().formatCellValue(row.getCell(0)) + "<br />"
                        + "咨询电话:" + new DataFormatter().formatCellValue(row.getCell(1)) + "<br />"
                        + "办公地址:" + new DataFormatter().formatCellValue(row.getCell(2)) + "<br />"
                        + "办公时间:" + new DataFormatter().formatCellValue(row.getCell(3)) + "<br />";
            applicationMaterial=applicationMaterial+"<br />";
            i++;
        }
@@ -335,9 +335,9 @@
                i=i+1;
                break;
            }
            acceptConditions=acceptConditions+row.getCell(0).getStringCellValue()+"&nbsp; "
                    +row.getCell(1).getStringCellValue()+"&nbsp; "
                    +row.getCell(2).getStringCellValue()+"&nbsp; ";
                acceptConditions = acceptConditions + new DataFormatter().formatCellValue(row.getCell(0)) + "&nbsp; "
                        +new DataFormatter().formatCellValue( row.getCell(1)) + "&nbsp; "
                        + new DataFormatter().formatCellValue(row.getCell(2)) + "&nbsp; ";
            acceptConditions=acceptConditions+"<br />";
            i++;
        }
@@ -350,9 +350,9 @@
                i=i+1;
                break;
            }
            rates=rates+row.getCell(0).getStringCellValue()+"&nbsp; "
                    +row.getCell(1).getStringCellValue()+"&nbsp; "
                    +row.getCell(2).getStringCellValue()+"&nbsp; ";
                rates = rates + new DataFormatter().formatCellValue(row.getCell(0)) + "&nbsp; "
                        + new DataFormatter().formatCellValue(row.getCell(1)) + "&nbsp; "
                        + new DataFormatter().formatCellValue(row.getCell(2)) + "&nbsp; ";
            rates=rates+"<br />";
            i++;
        }
@@ -365,9 +365,9 @@
                i=i+1;
                break;
            }
            transactionArea=transactionArea+row.getCell(0).getStringCellValue()+"&nbsp; "
                    +row.getCell(1).getStringCellValue()+"&nbsp; "
                    +row.getCell(2).getStringCellValue()+"&nbsp; ";
                transactionArea = transactionArea + new DataFormatter().formatCellValue(row.getCell(0)) + "&nbsp; "
                        + new DataFormatter().formatCellValue(row.getCell(1)) + "&nbsp; "
                        + new DataFormatter().formatCellValue(row.getCell(2)) + "&nbsp; ";
            transactionArea=transactionArea+"<br />";
            i++;
        }
@@ -380,9 +380,9 @@
                i=i+1;
                break;
            }
            handlingProcedures=handlingProcedures+row.getCell(0).getStringCellValue()+"&nbsp; "
                    +row.getCell(1).getStringCellValue()+"&nbsp; "
                    +row.getCell(2).getStringCellValue()+"&nbsp; ";
                handlingProcedures = handlingProcedures + new DataFormatter().formatCellValue(row.getCell(0)) + "&nbsp; "
                        + new DataFormatter().formatCellValue(row.getCell(1)) + "&nbsp; "
                        + new DataFormatter().formatCellValue(row.getCell(2)) + "&nbsp; ";
            handlingProcedures=handlingProcedures+"<br />";
            i++;
        }
@@ -394,13 +394,21 @@
        }else {
            ans =baseMapper.updateById(transactionEvent);
        }
       if (ans>0){
           return  true;
            if (ans <= 0) {
                failNum++;
       }
       return  false;
    }
        }
        if (failNum == 0) {//
            return 3;//全部导入成功
        } else if (failNum < numberOfSheets) {
            return 2;//部分导入成功
        } else if (failNum.equals(numberOfSheets)) {
            return 0;//导入失败
        }
        return 0;
    }
}