工程管理

This commit is contained in:
cwchen 2024-03-13 15:21:14 +08:00
parent fdb391f5cf
commit 490f1a2af7
18 changed files with 1249 additions and 13 deletions

View File

@ -136,6 +136,7 @@
<artifactId>hibernate-validator</artifactId>
<version>6.0.18.Final</version>
</dependency>
</dependencies>
</project>

View File

@ -17,5 +17,46 @@ public class Constant {
public final static Integer SUCCESS = 200;
public final static String MSG = "msg";
public final static String CODE = "code";
public final static String XLSX = ".xlsx";
public final static String XLS = ".xls";
public final static String PRO_IMPORT_VO = "ProImportVo";
public final static Integer CELL_1 = 1;
public final static Integer CELL_2 = 2;
public final static Integer CELL_3 = 3;
public final static Integer CELL_4 = 4;
public final static Integer CELL_5 = 5;
public final static Integer CELL_6 = 6;
public final static Integer CELL_7 = 7;
public final static Integer CELL_8 = 8;
public final static Integer CELL_9 = 9;
public final static Integer CELL_10 = 10;
public final static Integer CELL_11 = 11;
public final static Integer CELL_12 = 12;
public final static Integer CELL_13 = 13;
public final static Integer CELL_14 = 14;
public final static Integer CELL_15 = 15;
public final static Integer CELL_16 = 16;
public final static Integer CELL_17 = 17;
public final static Integer CELL_18 = 18;
public final static Integer CELL_19 = 19;
public final static Integer CELL_20 = 20;
public final static Integer CELL_21 = 21;
public final static Integer CELL_22 = 22;
public final static Integer CELL_23 = 23;
public final static Integer CELL_24 = 24;
public final static Integer CELL_25 = 25;
public final static String FILE_2 = "file2";
public final static String FILE_3 = "file3";
public final static String FILE_4 = "file4";
public final static String FILE_5 = "file5";
public final static String FILE_6 = "file6";
public final static String FILE_7 = "file7";
}

View File

@ -0,0 +1,105 @@
package com.securitycontrol.common.core.utils;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItem;
import org.apache.poi.util.IOUtils;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import java.io.*;
import java.nio.file.Files;
/**
* @authorcwchen
* @date2024-03-12-17:53
* @version1.0
* @description字节数组转文件
*/
public class BytesToMultipartFileUtil {
/**
* byte 转换为 MultipartFile
*
* @param bytes
* @return
*/
public static MultipartFile encodeToMultipartFile(byte[] bytes, String path) {
MultipartFile multipartFile = null;
InputStream input = null;
OutputStream outputStream = null;
File tempFile = null;
try {
File file = new File(path);
if (!file.exists()) {
file.mkdirs();
}
path = path + File.separator + System.currentTimeMillis() + ".png";
tempFile = new File(path);
tempFile.createNewFile();
// byte 转换为 File 文件
getFileByBytes(bytes, path);
// 第一个参数 fieldName 就是文件上传的 name, 这里我写的是 uploadFile
FileItem fileItem = new DiskFileItem("uploadFile", Files.probeContentType(tempFile.toPath()), false, tempFile.getName(), (int) tempFile.length(), tempFile.getParentFile());
input = new FileInputStream(tempFile);
outputStream = fileItem.getOutputStream();
IOUtils.copy(input, outputStream);
multipartFile = new CommonsMultipartFile(fileItem);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
input.close();
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
// 删除这个 File
if (tempFile.exists()) {
tempFile.delete();
}
return multipartFile;
}
/**
* byte [] 转换为 File
*
* @param bytes
* @param filePath
*/
public static void getFileByBytes(byte[] bytes, String filePath) {
BufferedOutputStream bos = null;
FileOutputStream fos = null;
File file = null;
try {
File dir = new File(filePath);
// 判断文件目录是否存在
if (!dir.exists() && dir.isDirectory()) {
dir.mkdirs();
}
file = new File(filePath);
//输出流
fos = new FileOutputStream(file);
//缓冲流
bos = new BufferedOutputStream(fos);
//将字节数组写出
bos.write(bytes);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (bos != null) {
try {
bos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}

View File

@ -0,0 +1,449 @@
package com.securitycontrol.common.core.utils;
import com.alibaba.fastjson2.JSONObject;
import com.securitycontrol.common.core.constant.Constant;
import com.securitycontrol.common.core.exception.ServiceException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ooxml.POIXMLDocumentPart;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.*;
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTMarker;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author 10488
* excel文件导入-包含图片
*/
@Slf4j
public class ImportExcelUtils {
private static final List<String> PRONAME_LIST = new LinkedList<>();
public static List<JSONObject> readExcel(MultipartFile file, Class<?> mClass, String uploadPath) throws Exception {
String fileName = file.getOriginalFilename();
log.info("OriginalFilename:{}", fileName);
if (!StringUtils.endsWithAny(fileName, Constant.XLS, Constant.XLSX)) {
throw new ServiceException("不支持excel以外的文件导入");
}
List<JSONObject> list = new ArrayList<>();
InputStream inputStream = file.getInputStream();
String className = mClass.getSimpleName();
log.info("className:{}", className);
//根据指定的文件输入流导入Excel从而产生Workbook对象
Workbook workbook = null;
Sheet sheet = null;
Map<String, PictureData> mapData = null;
if (null != fileName && fileName.endsWith(Constant.XLS)) {
workbook = new HSSFWorkbook(inputStream);
//获取Excel文档中的第一个表单
sheet = workbook.getSheetAt(0);
if (!checkModal(sheet, className)) {
throw new ServiceException("模板错误,请重新选择模板!");
}
mapData = getPicturesXls((HSSFSheet) sheet, className);
}
if (null != fileName && fileName.endsWith(Constant.XLSX)) {
workbook = new XSSFWorkbook(inputStream);
//获取Excel文档中的第一个表单
sheet = workbook.getSheetAt(0);
if (!checkModal(sheet, className)) {
throw new ServiceException("模板错误,请重新选择模板!");
}
mapData = getPicturesXlsx((XSSFSheet) sheet, className);
}
List<Map<String, Object>> filenames = new ArrayList<>();
if (Objects.equals(className, Constant.PRO_IMPORT_VO)) {
log.info("开始读取并写入图片");
filenames = writeImg(mapData, className, uploadPath);
log.info("图片:{},写入完成!", filenames);
}
int sheetCount = 0;
if (workbook != null) {
workbook.getNumberOfSheets();
}
log.info("Sheet(表单)数量:{}", sheetCount);
log.info("filenames:{}", filenames);
//获得最后一条记录得的行号从0开始
int totalRowNum = 0;
if (sheet != null) {
totalRowNum = sheet.getLastRowNum();
}
log.info("总记录数:{}", (totalRowNum + 1));
list = createBean(sheet, mClass, filenames);
inputStream.close();
return list;
}
private static boolean checkModal(Sheet sheet, String className) {
int colNum = sheet.getRow(0).getLastCellNum();
if (Objects.equals(className, Constant.PRO_IMPORT_VO)) {
return colNum == 25;
}
return false;
}
private static List<JSONObject> createBean(Sheet sheet, Class<?> mClass, List<Map<String, Object>> filename) throws Exception {
if (sheet == null || sheet.getLastRowNum() < 0) {
return null;
}
List<JSONObject> list = new ArrayList<>();
// 总列数
int last = sheet.getRow(0).getLastCellNum();
log.info("列数:{}", last);
try {
for (Row row : sheet) {
if (row == null) {
continue;
}
// 第一行是标题栏
if (Objects.equals(mClass.getSimpleName(), Constant.PRO_IMPORT_VO)) {
if (row.getRowNum() < 2) {
continue;
}
}
boolean isBlankRow = true;
for (Cell c : row) {
if (c.getCellType() != CellType.BLANK) {
isBlankRow = false;
break;
}
}
if (isBlankRow) {
continue;
}
JSONObject obj = new JSONObject();
obj.put("rowNo", row.getRowNum() + 1);
if (Objects.equals(mClass.getSimpleName(), Constant.PRO_IMPORT_VO)) {
setExcelToString(18, row);
obj = setProObjData(row, obj, filename);
}
list.add(obj);
}
} catch (IllegalStateException e) {
e.printStackTrace();
throw new ServiceException("模板中含有单元格数据格式不正确");
}
return list;
}
/**
* 工程数据赋值
*
* @param row
* @param obj
* @return JSONObject
* @description
* @author cwchen
* @date 2024/3/12 15:09
*/
public static JSONObject setProObjData(Row row, JSONObject obj, List<Map<String, Object>> files) {
if (row.getCell(Constant.CELL_1) != null) {
// 建管单位
obj.put("org", row.getCell(Constant.CELL_1).getStringCellValue());
}
if (row.getCell(Constant.CELL_2) != null) {
// 工程名称
obj.put("proName", row.getCell(Constant.CELL_2).getStringCellValue());
}
if (row.getCell(Constant.CELL_3) != null) {
// 工程类型
obj.put("proType", row.getCell(Constant.CELL_3).getStringCellValue());
}
if (row.getCell(Constant.CELL_4) != null) {
// 工程编码
obj.put("proCode", row.getCell(Constant.CELL_4).getStringCellValue());
}
if (row.getCell(Constant.CELL_5) != null) {
// 工程状态
obj.put("status", row.getCell(Constant.CELL_5).getStringCellValue());
}
if (row.getCell(Constant.CELL_6) != null) {
// 单项编码
obj.put("signCode", row.getCell(Constant.CELL_6).getStringCellValue());
}
if (row.getCell(Constant.CELL_7) != null) {
// 标段编码
obj.put("bidCode", row.getCell(Constant.CELL_7).getStringCellValue());
}
if (row.getCell(Constant.CELL_8) != null) {
// 规模
obj.put("proScale", row.getCell(Constant.CELL_8).getStringCellValue());
}
if (row.getCell(Constant.CELL_9) != null) {
// 监理单位
obj.put("jlUnit", row.getCell(Constant.CELL_9).getStringCellValue());
}
if (row.getCell(Constant.CELL_10) != null) {
// 施工单位
obj.put("sgUnit", row.getCell(Constant.CELL_10).getStringCellValue());
}
if (row.getCell(Constant.CELL_11) != null) {
// 项目经理
obj.put("manager", row.getCell(Constant.CELL_11).getStringCellValue());
}
if (row.getCell(Constant.CELL_12) != null) {
// 计划开始时间
obj.put("planStartTime", row.getCell(Constant.CELL_12).getStringCellValue());
}
if (row.getCell(Constant.CELL_13) != null) {
// 计划结束时间
obj.put("planEndTime", row.getCell(Constant.CELL_13).getStringCellValue());
}
if (row.getCell(Constant.CELL_14) != null) {
// 实际开始时间
obj.put("startTime", row.getCell(Constant.CELL_14).getStringCellValue());
}
if (row.getCell(Constant.CELL_15) != null) {
// 实际结束时间
obj.put("endTime", row.getCell(Constant.CELL_15).getStringCellValue());
}
if (row.getCell(Constant.CELL_16) != null) {
// 项目总成本
obj.put("proCost", row.getCell(Constant.CELL_16).getStringCellValue());
}
if (row.getCell(Constant.CELL_17) != null) {
// 工程简介
obj.put("proBrief", row.getCell(Constant.CELL_17).getStringCellValue());
}
obj = setFileObj(row, obj, files);
return obj;
}
public static JSONObject setFileObj(Row row, JSONObject obj, List<Map<String, Object>> files) {
// 平面图
String fileName = "file" + "_" + row.getRowNum() + "_1";
for (Map<String, Object> map : files) {
for (String keyName : map.keySet()) {
if (Objects.equals(fileName, keyName)) {
obj.put("file", map.get(keyName));
}
}
}
// 图片1
String fileName2 = "file" + "_" + row.getRowNum() + "_2";
for (Map<String, Object> map : files) {
for (String keyName : map.keySet()) {
if (Objects.equals(fileName2, keyName)) {
obj.put("file2", map.get(keyName));
}
}
}
// 图片2
String fileName3 = "file" + "_" + row.getRowNum() + "_3";
for (Map<String, Object> map : files) {
for (String keyName : map.keySet()) {
if (Objects.equals(fileName3, keyName)) {
obj.put("file3", map.get(keyName));
}
}
}
// 图片3
String fileName4 = "file" + "_" + row.getRowNum() + "_4";
for (Map<String, Object> map : files) {
for (String keyName : map.keySet()) {
if (Objects.equals(fileName4, keyName)) {
obj.put("file4", map.get(keyName));
}
}
}
// 图片4
String fileName5 = "file" + "_" + row.getRowNum() + "_5";
for (Map<String, Object> map : files) {
for (String keyName : map.keySet()) {
if (Objects.equals(fileName5, keyName)) {
obj.put("file5", map.get(keyName));
}
}
}
// 图片3
String fileName6 = "file" + "_" + row.getRowNum() + "_6";
for (Map<String, Object> map : files) {
for (String keyName : map.keySet()) {
if (Objects.equals(fileName6, keyName)) {
obj.put("file6", map.get(keyName));
}
}
}
// 图片3
String fileName7 = "file" + "_" + row.getRowNum() + "_7";
for (Map<String, Object> map : files) {
for (String keyName : map.keySet()) {
if (Objects.equals(fileName7, keyName)) {
obj.put("file7", map.get(keyName));
}
}
}
return obj;
}
/**
* 获取图片和位置 (xlsx)
*
* @param sheet
* @return
* @throws IOException
*/
public static Map<String, PictureData> getPicturesXlsx(XSSFSheet sheet, String className) throws IOException {
Map<String, PictureData> map = new HashMap<>(16);
List<POIXMLDocumentPart> list = sheet.getRelations();
for (POIXMLDocumentPart part : list) {
if (part instanceof XSSFDrawing) {
XSSFDrawing drawing = (XSSFDrawing) part;
List<XSSFShape> shapes = drawing.getShapes();
for (XSSFShape shape : shapes) {
XSSFPicture picture = (XSSFPicture) shape;
XSSFClientAnchor anchor = picture.getPreferredSize();
CTMarker marker = anchor.getFrom();
Row row = sheet.getRow(marker.getRow());
if (row == null) {
continue;
}
String keyName = null;
if (Objects.equals(className, Constant.PRO_IMPORT_VO)) {
keyName = setKey(picture, row, Constant.PRO_IMPORT_VO);
} else {
keyName = "";
}
map.put(keyName, picture.getPictureData());
}
}
}
return map;
}
/**
* 获取图片和位置 (xls)
*
* @param sheet
* @return
* @throws IOException
*/
public static Map<String, PictureData> getPicturesXls(HSSFSheet sheet, String className) throws IOException {
int i = 0;
Map<String, PictureData> map = new HashMap<String, PictureData>(16);
if (sheet.getDrawingPatriarch() != null) {
List<HSSFShape> list = sheet.getDrawingPatriarch().getChildren();
for (HSSFShape shape : list) {
if (shape instanceof HSSFPicture) {
HSSFPicture picture = (HSSFPicture) shape;
int pictureIndex = ((HSSFPicture) shape).getPictureIndex();
if (pictureIndex != -1) {
HSSFClientAnchor cAnchor = picture.getClientAnchor();
Row row = sheet.getRow(cAnchor.getRow1());
if (row == null) {
continue;
}
String keyName = null;
if (cAnchor.getCol1() == 18) {
PRONAME_LIST.add(row.getCell(1).getStringCellValue());
keyName = "file" + "_" + cAnchor.getRow1() + "_1";
} else if (cAnchor.getCol1() == 19) {
PRONAME_LIST.add(row.getCell(1).getStringCellValue());
keyName = "file" + "_" + cAnchor.getRow1() + "_2";
} else if (cAnchor.getCol1() == 20) {
PRONAME_LIST.add(row.getCell(1).getStringCellValue());
keyName = "file" + "_" + cAnchor.getRow1() + "_3";
} else if (cAnchor.getCol1() == 21) {
PRONAME_LIST.add(row.getCell(1).getStringCellValue());
keyName = "file" + "_" + cAnchor.getRow1() + "_4";
} else if (cAnchor.getCol1() == 22) {
PRONAME_LIST.add(row.getCell(1).getStringCellValue());
keyName = "file" + "_" + cAnchor.getRow1() + "_5";
} else if (cAnchor.getCol1() == 23) {
PRONAME_LIST.add(row.getCell(1).getStringCellValue());
keyName = "file" + "_" + cAnchor.getRow1() + "_6";
} else if (cAnchor.getCol1() == 24) {
PRONAME_LIST.add(row.getCell(1).getStringCellValue());
keyName = "file" + "_" + cAnchor.getRow1() + "_7";
}
map.put(keyName, picture.getPictureData());
}
}
}
}
return map;
}
/**
* 图片写出
*/
public static List<Map<String, Object>> writeImg(Map<String, PictureData> mapData, String className, String uploadPath) throws IOException {
if (mapData == null || mapData.size() == 0) {
return new ArrayList<>();
}
Object[] keyArr = mapData.keySet().toArray();
ArrayList<Map<String, Object>> filename = new ArrayList<>();
for (int i = 0; i < mapData.size(); i++) {
Map<String, Object> map = new HashMap<>(16);
// 获取图片流
PictureData pic = mapData.get(keyArr[i]);
// 获取图片索引
String picName = keyArr[i].toString();
byte[] data = pic.getData();
MultipartFile multipartFile = BytesToMultipartFileUtil.encodeToMultipartFile(data, uploadPath);
map.put(picName + "", multipartFile);
filename.add(map);
}
return filename;
}
private static String setKey(XSSFPicture picture, Row row, String className) {
if (row == null) {
return null;
}
;
String result = picture.getPreferredSize().toString();
String pattern = "\\<xdr\\:col\\>[1-9]\\d*\\<\\/xdr\\:col\\>";
Pattern r = Pattern.compile(pattern);
String col = "";
Matcher m = r.matcher(result);
if (m.find()) {
col = m.group(0);
} else {
System.out.println("NO MATCH");
}
if (Objects.equals(className, Constant.PRO_IMPORT_VO)) {
switch (col) {
case "<xdr:col>18</xdr:col>":
return "file" + "_" + row.getRowNum() + "_1";
case "<xdr:col>19</xdr:col>":
return "file" + "_" + row.getRowNum() + "_2";
case "<xdr:col>20</xdr:col>":
return "file" + "_" + row.getRowNum() + "_3";
case "<xdr:col>21</xdr:col>":
return "file" + "_" + row.getRowNum() + "_4";
case "<xdr:col>22</xdr:col>":
return "file" + "_" + row.getRowNum() + "_5";
case "<xdr:col>23</xdr:col>":
return "file" + "_" + row.getRowNum() + "_6";
case "<xdr:col>24</xdr:col>":
return "file" + "_" + row.getRowNum() + "_7";
default:
return null;
}
} else {
return "";
}
}
private static void setExcelToString(int j, Row row) {
for (int i = 0; i < j; i++) {
if (row.getCell(i) != null) {
row.getCell(i).setCellType(CellType.STRING);
}
}
}
}

View File

@ -17,4 +17,7 @@ public class ProDto {
@ApiModelProperty(value = "1.图片 2.平面图")
private String fileType;
@ApiModelProperty(value = "关键字")
private String keyWord;
}

View File

@ -0,0 +1,99 @@
package com.securitycontrol.entity.system.base.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
/**
* @authorcwchen
* @date2024-03-12-14:21
* @version1.0
* @description工程导入-vo
*/
@Data
public class ProImportVo {
@ApiModelProperty(value = "工程ID")
private String proId;
@ApiModelProperty(value = "建管单位")
private String org;
@ApiModelProperty(value = "标段工程编码")
private String bidCode;
@ApiModelProperty(value = "单项工程编码")
private String signCode;
@ApiModelProperty(value = "工程编码")
private String proCode;
@ApiModelProperty(value = "工程名称")
private String proName;
@ApiModelProperty(value = "工程成本")
private String proCost;
@ApiModelProperty(value = "施工单位")
private String sgUnit;
@ApiModelProperty(value = "监理单位")
private String jlUnit;
@ApiModelProperty(value = "工程类型")
private String proType;
@ApiModelProperty(value = "工程规模")
private String proScale;
@ApiModelProperty(value = "项目经理")
private String manager;
@ApiModelProperty(value = "工程简介")
private String proBrief;
@ApiModelProperty(value = "工程状态")
private String status;
@ApiModelProperty(value = "计划开始时间")
private String planStartTime;
@ApiModelProperty(value = "计划结束时间")
private String planEndTime;
@ApiModelProperty(value = "实际开始时间")
private String startTime;
@ApiModelProperty(value = "实际竣工时间")
private String endTime;
@ApiModelProperty(value = "工程平面图")
private MultipartFile file;
@ApiModelProperty(value = "工程图片1")
private MultipartFile file2;
@ApiModelProperty(value = "工程图片2")
private MultipartFile file3;
@ApiModelProperty(value = "工程图片3")
private MultipartFile file4;
@ApiModelProperty(value = "工程图片4")
private MultipartFile file5;
@ApiModelProperty(value = "工程图片5")
private MultipartFile file6;
@ApiModelProperty(value = "工程图片6")
private MultipartFile file7;
@ApiModelProperty(value = "工程图片集合")
private List<MultipartFile> files;
@ApiModelProperty(value = "1.新增 2.修改")
private int type;
}

View File

@ -17,7 +17,10 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@ -130,14 +133,11 @@ public class OperLogAspect {
//利用是否有异常定性记录失败信息
String result = JSON.toJSONString(jsonResult);
JSONObject jsonObject = JSON.parseObject(result);
System.err.println(result);
if (e != null) {
//失败
sysLog.setResult(BusinessStatus.FAIL.ordinal());
System.err.println(e.getClass().getName());
sysLog.setFailureReason(StringUtils.substring(e.getMessage(), 0, 2000));
log.error("耗时:{} 用户id:{} 用户名username: {} 请求ip:{} User-Agent:{} 方法路径:{} 方法参数:{}",
sysLog.getTimes(),
sysLog.getUserId(),
@ -148,7 +148,7 @@ public class OperLogAspect {
sysLog.getParams());
log.error("==控制层方法通知异常==");
log.error("异常信息:{}", e.getMessage());
}else if(e == null && !Objects.equals(Integer.parseInt(jsonObject.getString(Constant.CODE)), Constant.SUCCESS)){
} else if (e == null && jsonObject != null && !Objects.equals(Integer.parseInt(jsonObject.getString(Constant.CODE)), Constant.SUCCESS)) {
sysLog.setResult(BusinessStatus.FAIL.ordinal());
sysLog.setFailureReason(StringUtils.substring(jsonObject.getString("msg"), 0, 2000));
log.error("耗时:{} 用户id:{} 用户名username: {} 请求ip:{} User-Agent:{} 方法路径:{} 方法参数:{}",
@ -246,7 +246,7 @@ public class OperLogAspect {
params.append(jsonObj.toString()).append(" ");
}
} else {
if(value != null){
if (value != null) {
Object jsonObj = JSON.toJSON(value);
params.append(jsonObj.toString()).append(" ");
}

View File

@ -32,7 +32,7 @@ public class MyFilter implements Filter {
}
}
public static final String[] EXCLUDE_URLS = {"/sys/pro/addPro","/sys/pro/editPro"};
public static final String[] EXCLUDE_URLS = {"/sys/pro/addPro","/sys/pro/editPro","/sys/pro/importProData"};
public boolean isFileUpload(HttpServletRequest request) {
for (String excludeUrl : EXCLUDE_URLS) {

View File

@ -61,7 +61,7 @@ public class ParamSecureHandler implements AsyncHandlerInterceptor {
// IResourceService resourceService = (IResourceService) AdapterFactory.getInstance(Constants.CLASS_RESOURCE);
public static final String[] EXCLUDE_URLS = {"/sys/pro/addPro","/sys/pro/editPro"};
public static final String[] EXCLUDE_URLS = {"/sys/pro/addPro","/sys/pro/editPro","/sys/pro/importProData"};
public boolean isFileUpload(HttpServletRequest request) {
for (String excludeUrl : EXCLUDE_URLS) {

View File

@ -119,6 +119,44 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<!-- easypoi相关的jar包 -->
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-base</artifactId>
<version>4.2.0</version>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-web</artifactId>
<version>4.2.0</version>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-annotation</artifactId>
<version>4.2.0</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>20.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.30</version>
<!-- <scope>provided</scope>-->
</dependency>
</dependencies>

View File

@ -1,8 +1,31 @@
package com.securitycontrol.system.base.controller;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import com.securitycontrol.common.log.annotation.Log;
import com.securitycontrol.common.log.enums.OperationType;
import com.securitycontrol.entity.system.base.dto.ProDto;
import com.securitycontrol.system.export.entity.ProExportVo;
import com.securitycontrol.entity.system.base.vo.ProVo;
import com.securitycontrol.system.base.service.IProService;
import com.securitycontrol.system.export.util.ExcelStyleUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
/**
* @authorcwchen
* @date2024-03-11-14:55
@ -11,6 +34,35 @@ import org.springframework.web.bind.annotation.RestController;
*/
@RestController
@RequestMapping("/sys/export/")
@Slf4j
public class ExportFileController {
@Resource(name = "IProService")
private IProService service;
@GetMapping("exportProData")
@Log(title = "基础管理", menu = "基础管理->工程管理", grade = OperationType.EXPORT_BUSINESS, details = "导出工程", type = "业务日志")
public void exportData(HttpServletRequest request, HttpServletResponse response, ProDto dto) {
try {
List<ProExportVo> proExportVoList = new ArrayList<>();
List<ProVo> proLists = service.getProLists(dto);
for (int i = 0; i < proLists.size(); i++) {
proLists.get(i).setProId((i + 1) + "");
ProExportVo exportVo = new ProExportVo();
BeanUtils.copyProperties(proLists.get(i), exportVo);
proExportVoList.add(exportVo);
}
ExportParams exportParams = new ExportParams("工程列表", "工程列表", ExcelType.XSSF);
exportParams.setStyle(ExcelStyleUtil.class);
Workbook workbook = ExcelExportUtil.exportExcel(exportParams,ProExportVo.class,proExportVoList);
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setHeader("content-disposition", "attachment;fileName=" + URLEncoder.encode("工程列表" + ".xlsx", "UTF-8"));
ServletOutputStream outputStream = response.getOutputStream();
workbook.write(outputStream);
outputStream.close();
workbook.close();
} catch (Exception e) {
log.error("导出工程", e);
}
}
}

View File

@ -1,5 +1,6 @@
package com.securitycontrol.system.base.controller;
import com.alibaba.fastjson2.JSONObject;
import com.securitycontrol.common.core.web.controller.BaseController;
import com.securitycontrol.common.core.web.domain.AjaxResult;
import com.securitycontrol.common.core.web.page.TableDataInfo;
@ -15,6 +16,7 @@ import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
@ -32,7 +34,7 @@ public class ProController extends BaseController {
@ApiOperation(value = "获取工程列表")
@GetMapping("getProLists")
@Log(title = "基础管理", menu = "基础管理->工程管理", grade = OperationType.QUERY_BUSINESS, details = "查询功能", type = "业务日志")
@Log(title = "基础管理", menu = "基础管理->工程管理", grade = OperationType.QUERY_BUSINESS, details = "查询工程", type = "业务日志")
public TableDataInfo getProLists(ProDto dto) {
startPage();
List<ProVo> list = service.getProLists(dto);
@ -78,4 +80,11 @@ public class ProController extends BaseController {
public AjaxResult viewProFile(ProDto dto) {
return service.viewProFile(dto);
}
@ApiOperation(value = "工程信息导入")
@PostMapping("importProData")
@Log(title = "基础管理", menu = "基础管理->工程管理", grade = OperationType.IMPORT_BUSINESS, details = "工程信息导入")
public AjaxResult importProData(MultipartFile file, HttpServletRequest request, HttpServletResponse response) {
return service.importProData(file,request,response);
}
}

View File

@ -6,6 +6,8 @@ import com.securitycontrol.entity.system.base.dto.ProGxPlanDto;
import com.securitycontrol.entity.system.base.vo.ProVo;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
@ -74,6 +76,8 @@ public interface IProService {
AjaxResult delProGxPlan(ProGxPlanDto dto);
/**
* 工程图片/平面图预览
*
* @param dto
* @return AjaxResult
* @description
@ -81,4 +85,16 @@ public interface IProService {
* @date 2024/3/12 13:11
*/
AjaxResult viewProFile(ProDto dto);
/**
* 工程信息导入
* @param file
* @param request
* @param response
* @return AjaxResult
* @description
* @author cwchen
* @date 2024/3/13 9:10
*/
AjaxResult importProData(MultipartFile file, HttpServletRequest request, HttpServletResponse response);
}

View File

@ -1,12 +1,16 @@
package com.securitycontrol.system.base.service.impl;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.securitycontrol.common.core.constant.Constant;
import com.securitycontrol.common.core.utils.ImportExcelUtils;
import com.securitycontrol.common.core.utils.StringUtils;
import com.securitycontrol.common.core.utils.aes.DateTimeHelper;
import com.securitycontrol.common.core.web.domain.AjaxResult;
import com.securitycontrol.common.security.utils.ValidatorsUtils;
import com.securitycontrol.entity.system.base.dto.ProDto;
import com.securitycontrol.entity.system.base.dto.ProGxPlanDto;
import com.securitycontrol.entity.system.base.vo.ProImportVo;
import com.securitycontrol.entity.system.base.vo.ProVo;
import com.securitycontrol.entity.system.vo.ResourceFileVo;
import com.securitycontrol.system.base.mapper.IProMapper;
@ -16,12 +20,16 @@ import com.securitycontrol.system.mongodb.util.MongodbFileUtil;
import com.securitycontrol.system.mongodb.vo.FileExportVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.*;
/**
@ -43,6 +51,9 @@ public class ProServiceImpl implements IProService {
@Resource(name = "fileMongoServiceImpl")
private FileUploadService mongoService;
@Value("${file.temp_file_path}")
private String temp_file_path;
@Override
public List<ProVo> getProLists(ProDto dto) {
@ -129,7 +140,7 @@ public class ProServiceImpl implements IProService {
ProVo vo = new ProVo();
vo = mapper.getProById(dto);
List<ResourceFileVo> resourceFileVos = mapper.getFiles(vo.getProId());
if(CollectionUtils.isNotEmpty(resourceFileVos)){
if (CollectionUtils.isNotEmpty(resourceFileVos)) {
List<ProVo.FileData> list = new ArrayList<>();
for (ResourceFileVo fileVo : resourceFileVos) {
FileExportVo fileExportVo = mongoService.downloadFile(fileVo.getFileId());
@ -175,9 +186,9 @@ public class ProServiceImpl implements IProService {
public AjaxResult viewProFile(ProDto dto) {
List<ProVo.FileData> list = new ArrayList<>();
List<ResourceFileVo> resourceFileVos = mapper.getFiles(dto.getProId());
if(CollectionUtils.isNotEmpty(resourceFileVos)){
if (CollectionUtils.isNotEmpty(resourceFileVos)) {
for (ResourceFileVo fileVo : resourceFileVos) {
if(Objects.equals(dto.getFileType(),fileVo.getSourceType())){
if (Objects.equals(dto.getFileType(), fileVo.getSourceType())) {
FileExportVo fileExportVo = mongoService.downloadFile(fileVo.getFileId());
String base64 = MongodbFileUtil.getBase64(fileExportVo);
ProVo.FileData fileData = new ProVo.FileData();
@ -190,4 +201,118 @@ public class ProServiceImpl implements IProService {
}
return AjaxResult.success(list);
}
@Override
@Transactional(rollbackFor = Exception.class)
public AjaxResult importProData(MultipartFile file, HttpServletRequest request, HttpServletResponse response) {
List<String> errorList = new ArrayList<>();
try {
List<JSONObject> lstObj = (List<JSONObject>) ImportExcelUtils.readExcel(file, ProImportVo.class, temp_file_path);
List<JSONObject> lstError = new ArrayList<>();
List<ProImportVo> list = new ArrayList<>();
if (lstObj != null && lstObj.size() > 0) {
list = new ArrayList<>();
lstError = new ArrayList<>();
for (JSONObject obj : lstObj) {
ProImportVo vo = new ProImportVo();
ProVo proVo = new ProVo();
vo = setProData(vo, obj);
BeanUtils.copyProperties(vo, proVo);
if (vo.getFile() != null) {
FileExportVo item = mongoService.uploadFile(vo.getFile());
if (item != null) {
errorList.add(item.getFileId());
ResourceFileVo fileVo = setResourceData(item,vo.getProId(),2);
mapper.addFiles(fileVo);
}
}
List<MultipartFile> files = vo.getFiles();
if(CollectionUtils.isNotEmpty(files)){
for (MultipartFile multipartFile : files) {
FileExportVo item = mongoService.uploadFile(multipartFile);
if (item != null) {
errorList.add(item.getFileId());
ResourceFileVo fileVo = setResourceData(item,vo.getProId(),1);
mapper.addFiles(fileVo);
}
}
}
mapper.addOrUpdatePro(proVo);
}
}
} catch (Exception e) {
log.error("工程文件导入", e);
// 删除文件
if (CollectionUtils.isNotEmpty(errorList)) {
errorList.forEach(item -> {
mongoService.removeFile(item);
});
}
//手动回滚异常
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
return AjaxResult.error();
}
return AjaxResult.success();
}
public ProImportVo setProData(ProImportVo vo, JSONObject obj) {
String proId = UUID.randomUUID().toString().replace("-", "");
vo.setProId(proId);
vo.setOrg(obj.getString("org"));
vo.setBidCode(obj.getString("bidCode"));
vo.setSignCode(obj.getString("signCode"));
vo.setProCode(obj.getString("proCode"));
vo.setProName(obj.getString("proName"));
vo.setProCost(obj.getString("proCost"));
vo.setSgUnit(obj.getString("sgUnit"));
vo.setJlUnit(obj.getString("jlUnit"));
vo.setProType(obj.getString("proType"));
vo.setProScale(obj.getString("proScale"));
vo.setManager(obj.getString("manager"));
vo.setProBrief(obj.getString("proBrief"));
vo.setStatus(obj.getString("status"));
vo.setPlanStartTime(obj.getString("planStartTime"));
vo.setPlanEndTime(obj.getString("planEndTime"));
vo.setStartTime(obj.getString("startTime"));
vo.setEndTime(obj.getString("endTime"));
vo.setFile(obj.get("file") != null ? (MultipartFile) obj.get("file") : null);
List<MultipartFile> files = new ArrayList<MultipartFile>();
if(obj.get(Constant.FILE_2) != null){
files.add((MultipartFile) obj.get(Constant.FILE_2));
}
if(obj.get(Constant.FILE_3) != null){
files.add((MultipartFile) obj.get(Constant.FILE_3));
}
if(obj.get(Constant.FILE_4) != null){
files.add((MultipartFile) obj.get(Constant.FILE_4));
}
if(obj.get(Constant.FILE_5) != null){
files.add((MultipartFile) obj.get(Constant.FILE_5));
}
if(obj.get(Constant.FILE_6) != null){
files.add((MultipartFile) obj.get(Constant.FILE_6));
}
if(obj.get(Constant.FILE_7) != null){
files.add((MultipartFile) obj.get(Constant.FILE_7));
}
vo.setFiles(files);
vo.setType(1);
return vo;
}
public ResourceFileVo setResourceData(FileExportVo item, String proId, int type) {
ResourceFileVo fileVo = new ResourceFileVo();
String resourceId = UUID.randomUUID().toString().replace("-", "");
fileVo.setResourceId(resourceId);
fileVo.setFileType(1);
fileVo.setFileId(item.getFileId());
fileVo.setFileSuffix(item.getSuffix());
fileVo.setFileName(item.getFileName());
fileVo.setSourceId(proId);
fileVo.setUpdateTime(DateTimeHelper.getNowTime());
fileVo.setSourceType(type == 1 ? "工程图片" : "工程平面图");
return fileVo;
}
}

View File

@ -0,0 +1,89 @@
package com.securitycontrol.system.export.entity;
import cn.afterturn.easypoi.excel.annotation.Excel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @authorcwchen
* @date2024-03-12-14:21
* @version1.0
* @description工程导入-vo
*/
@Data
public class ProExportVo {
@ApiModelProperty(value = "工程ID")
@Excel(name = "序号", width = 10.0, orderNum = "0")
private String proId;
@Excel(name = "建管单位", width = 10.0, orderNum = "1")
@ApiModelProperty(value = "建管单位")
private String org;
@ApiModelProperty(value = "工程名称")
@Excel(name = "工程名称", width = 10.0, orderNum = "2")
private String proName;
@ApiModelProperty(value = "标段工程编码")
@Excel(name = "标段工程编码", width = 20.0, orderNum = "3")
private String bidCode;
@ApiModelProperty(value = "单项工程编码")
@Excel(name = "单项工程编码", width = 20.0, orderNum = "4")
private String signCode;
@ApiModelProperty(value = "工程编码")
@Excel(name = "工程编码", width = 20.0, orderNum = "5")
private String proCode;
@ApiModelProperty(value = "工程类型")
@Excel(name = "工程类型", width = 20.0, orderNum = "6")
private String proType;
@ApiModelProperty(value = "工程规模")
@Excel(name = "工程规模", width = 20.0, orderNum = "7")
private String proScale;
@ApiModelProperty(value = "监理单位")
@Excel(name = "监理单位", width = 20.0, orderNum = "8")
private String jlUnit;
@ApiModelProperty(value = "施工单位")
@Excel(name = "施工单位", width = 20.0, orderNum = "9")
private String sgUnit;
@ApiModelProperty(value = "项目经理")
@Excel(name = "施工单位", width = 20.0, orderNum = "10")
private String manager;
@ApiModelProperty(value = "计划开始时间")
@Excel(name = "计划开始时间", width = 20.0, orderNum = "11")
private String planStartTime;
@ApiModelProperty(value = "计划结束时间")
@Excel(name = "计划结束时间", width = 20.0, orderNum = "12")
private String planEndTime;
@ApiModelProperty(value = "实际开始时间")
@Excel(name = "实际开始时间", width = 20.0, orderNum = "13")
private String startTime;
@ApiModelProperty(value = "实际竣工时间")
@Excel(name = "实际竣工时间", width = 20.0, orderNum = "14")
private String endTime;
@ApiModelProperty(value = "项目总成本")
@Excel(name = "项目总成本", width = 20.0, orderNum = "15")
private String proCost;
@ApiModelProperty(value = "工程简介")
@Excel(name = "工程简介", width = 20.0, orderNum = "16")
private String proBrief;
@ApiModelProperty(value = "工程状态")
@Excel(name = "工程状态", width = 10.0, orderNum = "17")
private String status;
}

View File

@ -0,0 +1,196 @@
package com.securitycontrol.system.export.util;
import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
import cn.afterturn.easypoi.excel.entity.params.ExcelForEachParams;
import cn.afterturn.easypoi.excel.export.styler.IExcelExportStyler;
import org.apache.poi.ss.usermodel.*;
/**
* @Auther: ccw
* @Date: 2022/05/12/16:22
* @description: easypoi 导出表格样式
*/
public class ExcelStyleUtil implements IExcelExportStyler {
private static final short STRING_FORMAT = (short) BuiltinFormats.getBuiltinFormat("TEXT");
private static final short FONT_SIZE_TEN = 10;
private static final short FONT_SIZE_ELEVEN = 11;
private static final short FONT_SIZE_TWELVE = 12;
/**
* 大标题样式
*/
private CellStyle headerStyle;
/**
* 每列标题样式
*/
private CellStyle titleStyle;
/**
* 数据行样式
*/
private CellStyle styles;
public ExcelStyleUtil(Workbook workbook) {
this.init(workbook);
}
/**
* 初始化样式
*
* @param workbook
*/
private void init(Workbook workbook) {
this.headerStyle = initHeaderStyle(workbook);
this.titleStyle = initTitleStyle(workbook);
this.styles = initStyles(workbook);
}
/**
* 大标题样式
*
* @param color
* @return
*/
@Override
public CellStyle getHeaderStyle(short color) {
return headerStyle;
}
/**
* 每列标题样式
*
* @param color
* @return
*/
@Override
public CellStyle getTitleStyle(short color) {
return titleStyle;
}
/**
* 数据行样式
*
* @param parity 可以用来表示奇偶行
* @param entity 数据内容
* @return 样式
*/
@Override
public CellStyle getStyles(boolean parity, ExcelExportEntity entity) {
return styles;
}
/**
* 获取样式方法
*
* @param dataRow 数据行
* @param obj 对象
* @param data 数据
*/
@Override
public CellStyle getStyles(Cell cell, int dataRow, ExcelExportEntity entity, Object obj, Object data) {
return getStyles(true, entity);
}
/**
* 模板使用的样式设置
*/
@Override
public CellStyle getTemplateStyles(boolean isSingle, ExcelForEachParams excelForEachParams) {
return null;
}
/**
* 初始化--大标题样式
*
* @param workbook
* @return
*/
private CellStyle initHeaderStyle(Workbook workbook) {
CellStyle style = getBaseCellStyle(workbook);
style.setFont(getFont(workbook, FONT_SIZE_TWELVE, true));
return style;
}
/**
* 初始化--每列标题样式
*
* @param workbook
* @return
*/
private CellStyle initTitleStyle(Workbook workbook) {
CellStyle style = getBaseCellStyle(workbook);
style.setFont(getFont(workbook, FONT_SIZE_ELEVEN, false));
//背景色
style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
return style;
}
/**
* 初始化--数据行样式
*
* @param workbook
* @return
*/
private CellStyle initStyles(Workbook workbook) {
CellStyle style = getBaseCellStyle(workbook);
style.setFont(getFont(workbook, FONT_SIZE_TEN, false));
style.setDataFormat(STRING_FORMAT);
return style;
}
/**
* 基础样式
*
* @return
*/
private CellStyle getBaseCellStyle(Workbook workbook) {
CellStyle style = workbook.createCellStyle();
//下边框
style.setBorderBottom(BorderStyle.THIN);
//左边框
style.setBorderLeft(BorderStyle.THIN);
//上边框
style.setBorderTop(BorderStyle.THIN);
//右边框
style.setBorderRight(BorderStyle.THIN);
//水平居中
style.setAlignment(HorizontalAlignment.CENTER);
//上下居中
style.setVerticalAlignment(VerticalAlignment.CENTER);
//设置自动换行
style.setWrapText(true);
return style;
}
/**
* 字体样式
*
* @param size 字体大小
* @param isBold 是否加粗
* @return
*/
private Font getFont(Workbook workbook, short size, boolean isBold) {
Font font = workbook.createFont();
//字体样式
font.setFontName("宋体");
//是否加粗
font.setBold(isBold);
//字体大小
font.setFontHeightInPoints(size);
return font;
}
}

View File

@ -130,9 +130,22 @@
tp.end_time AS endTime,
tp.pro_cost AS proCost,
tp.pro_brief AS proBrief,
tp.status
tp.status,
tp.bid_code AS bidCode,
tp.sign_code AS signCode,
tp.pro_code AS proCode
FROM tb_project tp
LEFT JOIN sys_build sb ON tp.org = sb.org_id
<where>
<if test="keyWord !=null and keyWord!=''">
AND (
INSTR(tp.pro_name,#{keyWord}) > 0 OR
INSTR(tp.jl_unit,#{keyWord}) > 0 OR
INSTR(tp.sg_unit,#{keyWord}) > 0 OR
INSTR(tp.manager,#{keyWord}) > 0 OR
)
</if>
</where>
</select>
<!--工程图片/平面图数量-->
<select id="getProFiles" resultType="java.lang.Integer">