Commit 0d6de0de by wangjian

2025-11-29 wj 修改

parent d0159bf8
package com.qianhe.controller;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.qianhe.common.exception.BusinessException;
import com.qianhe.common.utils.DateUtils;
import com.qianhe.common.utils.SecurityUtils;
import com.qianhe.common.utils.StringUtils;
import com.qianhe.domain.SjFybp;
import com.qianhe.domain.SjGfjsZsdwkhpj;
import com.qianhe.system.domain.SysDeptCb;
import com.qianhe.system.mapper.SysDeptCbMapper;
import com.qianhe.system.mapper.SysDeptMapper;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
......@@ -24,6 +35,7 @@ import com.qianhe.domain.SjFybpZb;
import com.qianhe.service.ISjFybpZbService;
import com.qianhe.common.utils.poi.ExcelUtil;
import com.qianhe.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;
/**
* 三基-费用报批主Controller
......@@ -512,4 +524,108 @@ public class SjFybpZbController extends BaseController
return success(sjFybpZb);
}
//导入模板 下载
@PostMapping("/exportDrmb")
public void exportDrmb(HttpServletResponse response, SjFybpZb sjFybpZb)
{
Workbook exl = null;
OutputStream out = null;
InputStream in = null;
try {
in =this.getClass().getResourceAsStream("/static/fybp_drmb.xlsx");
exl = WorkbookFactory.create(in);
out = response.getOutputStream();
response.reset();
String filename = URLEncoder.encode("费用上报导入模板.xlsx", "UTF-8");
response.setCharacterEncoding("UTF-8");
response.setHeader("Content-Disposition", "attachment;filename=" + filename);
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
Sheet sheet = exl.getSheet("Sheet1");
CellStyle cellStyle = exl.createCellStyle();
cellStyle.setWrapText(true);
cellStyle.setAlignment(HorizontalAlignment.LEFT);
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
cellStyle.setBorderBottom(BorderStyle.THIN);
cellStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex());
cellStyle.setBorderLeft(BorderStyle.THIN);
cellStyle.setLeftBorderColor(IndexedColors.BLACK.getIndex());
cellStyle.setBorderRight(BorderStyle.THIN);
cellStyle.setRightBorderColor(IndexedColors.BLACK.getIndex());
cellStyle.setBorderTop(BorderStyle.THIN);
cellStyle.setTopBorderColor(IndexedColors.BLACK.getIndex());
exl.write(out);
exl.close();
}catch (Exception e){
e.getMessage();
throw new BusinessException("导出Excel失败,请联系网站管理员!");
}finally {
if (exl != null) {
try {
exl.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
if (out != null) {
try {
out.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
}
//导入
@PostMapping("/importData")
public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception{
List<SjFybp> list = new ArrayList<>();
XSSFWorkbook workbook = null;
try {
//装载流
workbook = new XSSFWorkbook(file.getInputStream());
// 获取一个工作表,下标从0开始
XSSFSheet sheet = workbook.getSheetAt(0);
int lastRowNum = sheet.getLastRowNum();
// 通过循环,逐行取出表中每行数据
for(int i=0;i<=lastRowNum;i++) {//跳过第一行和第二行
if(i==0 || i==1){
continue;
}
// 获取行
XSSFRow row = sheet.getRow(i);
SjFybp cb = new SjFybp();
System.out.println(row);
//项目金额
String fyje = new DataFormatter().formatCellValue(row.getCell(0));
cb.setFyje(new BigDecimal(fyje));
//项目内容
String fyms = new DataFormatter().formatCellValue(row.getCell(1));
cb.setFyms(fyms);
list.add(cb);
}
// if(list.size()>0){
// sjGfjsZsdwkhpjService.pledit(list);
// }
} catch (Exception e) {
e.getMessage();
e.printStackTrace();
throw new BusinessException("导入Excel失败,请检查数据格式,尤其是金额!");
} finally {
workbook.close();
}
return AjaxResult.success(list);
}
}
......@@ -42,11 +42,11 @@ public class SjFybp extends BaseEntity
private String fylx;
/** 费用描述 */
@Excel(name = "费用描述")
@Excel(name = "项目内容")
private String fyms;
/** 费用金额 */
@Excel(name = "费用金额")
@Excel(name = "项目金额")
private BigDecimal fyje;
/** 文件关联id */
......@@ -87,23 +87,18 @@ public class SjFybp extends BaseEntity
private String spyj;
/** 预留1 */
@Excel(name = "预留1")
private String yl1;
/** 预留2 */
@Excel(name = "预留2")
private String yl2;
/** 预留3 */
@Excel(name = "预留3")
private String yl3;
/** 预留4 */
@Excel(name = "预留4")
private String yl4;
/** 预留5 */
@Excel(name = "预留5")
private String yl5;
//费用审批查询 (传1 查不等于未提交的数据,2查等于已批复的数据)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment