Merge branch 'develop_3' into 'develop_master'
Develop 3 See merge request LiuChao/foton-slrs-system-rest!236
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
package com.adc.da.slrs.ImportExcelDatas.POIUtil;
|
||||
|
||||
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.CellType;
|
||||
import org.apache.poi.ss.usermodel.DateUtil;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
@Component
|
||||
public class POIUtil {
|
||||
|
||||
|
||||
//获取单元格各类型值,返回字符串类型
|
||||
public static String getCellValueByCell(Cell cell) {
|
||||
//判断是否为null或空串
|
||||
if (cell==null || cell.toString().trim().equals("")) {
|
||||
return "";
|
||||
}
|
||||
String cellValue = "";
|
||||
CellType cellType = cell.getCellType();
|
||||
cell.getCellType();
|
||||
switch (cellType) {
|
||||
case NUMERIC: // 数字
|
||||
short format = cell.getCellStyle().getDataFormat();
|
||||
if (DateUtil.isCellDateFormatted(cell)) {
|
||||
SimpleDateFormat sdf = null;
|
||||
//System.out.println("cell.getCellStyle().getDataFormat()="+cell.getCellStyle().getDataFormat());
|
||||
if (format == 20 || format == 32) {
|
||||
sdf = new SimpleDateFormat("HH:mm");
|
||||
} else if (format == 14 || format == 31 || format == 57 || format == 58) {
|
||||
// 处理自定义日期格式:m月d日(通过判断单元格的格式id解决,id的值是58)
|
||||
sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
double value = cell.getNumericCellValue();
|
||||
Date date = org.apache.poi.ss.usermodel.DateUtil
|
||||
.getJavaDate(value);
|
||||
cellValue = sdf.format(date);
|
||||
}else {// 日期
|
||||
sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
}
|
||||
try {
|
||||
cellValue = sdf.format(cell.getDateCellValue());// 日期
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
throw new Exception("exception on get date data !".concat(e.toString()));
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}finally{
|
||||
sdf = null;
|
||||
}
|
||||
} else {
|
||||
BigDecimal bd = new BigDecimal(cell.getNumericCellValue());
|
||||
cellValue = bd.toPlainString();// 数值 这种用BigDecimal包装再获取plainString,可以防止获取到科学计数值
|
||||
}
|
||||
break;
|
||||
case STRING: // 字符串
|
||||
cellValue = cell.getStringCellValue();
|
||||
break;
|
||||
case BOOLEAN: // Boolean
|
||||
cellValue = cell.getBooleanCellValue()+"";;
|
||||
break;
|
||||
case FORMULA: // 公式
|
||||
cellValue = cell.getCellFormula();
|
||||
break;
|
||||
case BLANK: // 空值
|
||||
cellValue = "";
|
||||
break;
|
||||
case ERROR: // 故障
|
||||
cellValue = "ERROR VALUE";
|
||||
break;
|
||||
default:
|
||||
cellValue = "UNKNOW VALUE";
|
||||
break;
|
||||
}
|
||||
return cellValue;
|
||||
}
|
||||
}
|
||||
@@ -14,10 +14,8 @@ import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.time.Year;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
|
||||
+45
-25
@@ -1,10 +1,11 @@
|
||||
package com.adc.da.slrs.ImportExcelDatas.comment;
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.CellType;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.apache.poi.xssf.usermodel.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
@@ -18,44 +19,64 @@ import java.util.HashMap;
|
||||
public class PathMatcher {
|
||||
private static final Logger logger = LoggerFactory.getLogger(PathMatcher.class);
|
||||
|
||||
public void run(MultipartFile target,MultipartFile attach) throws IOException {
|
||||
|
||||
|
||||
public void run(MultipartFile target, MultipartFile attach) throws IOException {
|
||||
InputStream inputStream = target.getInputStream();
|
||||
XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
|
||||
|
||||
XSSFSheet sheet = workbook.getSheetAt(0);
|
||||
XSSFSheet mySheet = workbook.getSheetAt(0);
|
||||
|
||||
HashMap<String, String> fileMap = getFileMap(attach);
|
||||
|
||||
|
||||
for (Row row : sheet) {
|
||||
|
||||
String latter = row.getCell(1).getStringCellValue().trim();//标准号
|
||||
String fileId="";
|
||||
if (row.getCell(10)!=null){
|
||||
fileId = row.getCell(10).getStringCellValue().trim();//文档id
|
||||
}else {
|
||||
for (Row row : mySheet) {
|
||||
if (row.getCell(1) == null || row.getCell(10) == null) {
|
||||
logger.info("+");
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append(fileId)
|
||||
.append(latter);
|
||||
if (fileMap.containsKey(builder.toString())){
|
||||
Cell cell = row.createCell(9);
|
||||
cell.setCellType(CellType.STRING);
|
||||
cell.setCellValue(fileMap.get(builder.toString()));
|
||||
logger.info("*");
|
||||
}else {
|
||||
logger.info("-");
|
||||
String latter = row.getCell(1).getStringCellValue().trim();//标准号
|
||||
|
||||
String[] fileIdArray = row.getCell(10).getStringCellValue().trim().split(",");//文档id
|
||||
|
||||
HashMap<String, String> idMapPath = new HashMap<>(); //文件id和路径的键值对
|
||||
|
||||
|
||||
|
||||
|
||||
for (String fileId : fileIdArray) { //遍历文件id
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append(fileId)
|
||||
.append(latter);//拼接文件id和标准号
|
||||
|
||||
|
||||
if (!fileMap.containsKey(builder.toString())) {
|
||||
logger.info("-");
|
||||
continue;
|
||||
}else {
|
||||
Cell cell = row.createCell(9);
|
||||
|
||||
|
||||
idMapPath.put(fileId,fileMap.get(builder.toString()));
|
||||
String json = JSON.toJSONString(idMapPath);
|
||||
|
||||
cell.setCellType(CellType.STRING);
|
||||
cell.setCellValue(json);
|
||||
logger.info("*");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
File file = new File("C:\\Users\\22501\\Desktop\\foton标准数据\\匹配带入文件路径-国内库.xlsx");
|
||||
File file = new File("C:\\Users\\22501\\Desktop\\foton标准数据\\匹配带入文件路径-国内-多个路径.xlsx");
|
||||
FileOutputStream os = new FileOutputStream(file);
|
||||
workbook.write(os);
|
||||
|
||||
@@ -63,8 +84,7 @@ public class PathMatcher {
|
||||
}
|
||||
|
||||
|
||||
|
||||
private HashMap<String,String> getFileMap(MultipartFile excel) throws IOException {
|
||||
private HashMap<String, String> getFileMap(MultipartFile excel) throws IOException {
|
||||
|
||||
InputStream inputStream = excel.getInputStream();
|
||||
|
||||
@@ -86,7 +106,7 @@ public class PathMatcher {
|
||||
|
||||
String path = strArray[3];
|
||||
|
||||
resultMap.put(builder.toString(),path);
|
||||
resultMap.put(builder.toString(), path);
|
||||
|
||||
}
|
||||
|
||||
|
||||
+22
-7
@@ -38,20 +38,27 @@ public class StandMatcher {
|
||||
|
||||
for (Row row : sheet) {
|
||||
|
||||
/**
|
||||
* 企标
|
||||
*/
|
||||
// String letter =convertCellValueToString(row.getCell(1));//标准号
|
||||
// String publish = convertCellValueToString(row.getCell(4));//发布日期
|
||||
// String impl= convertCellValueToString(row.getCell(5));//实施日期
|
||||
// String state = convertCellValueToString(row.getCell(3));//状态
|
||||
// String replace= convertCellValueToString(row.getCell(6));//代替标准号
|
||||
|
||||
/**
|
||||
* 国内
|
||||
*/
|
||||
String letter =convertCellValueToString(row.getCell(1));//标准号
|
||||
|
||||
String publish = convertCellValueToString(row.getCell(3));//发布日期
|
||||
|
||||
String impl= convertCellValueToString(row.getCell(4));//实施日期
|
||||
|
||||
String state = convertCellValueToString(row.getCell(2));//状态
|
||||
|
||||
String replace= convertCellValueToString(row.getCell(5));//代替标准号
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
StringBuilder strBuilder = new StringBuilder();
|
||||
strBuilder.append(letter)
|
||||
.append(publish)
|
||||
@@ -72,7 +79,7 @@ public class StandMatcher {
|
||||
|
||||
}
|
||||
|
||||
File result = new File("C:\\Users\\22501\\Desktop\\foton标准数据\\匹配带入文件id-国内库.xlsx");
|
||||
File result = new File("C:\\Users\\22501\\Desktop\\foton标准数据\\匹配带入文件id-国内-多个文件id.xlsx");
|
||||
FileOutputStream os = new FileOutputStream(result);
|
||||
workbook.write(os);
|
||||
}
|
||||
@@ -115,7 +122,15 @@ public class StandMatcher {
|
||||
if (row.getCell(7).getCellType()== NUMERIC){
|
||||
String s = row.getCell(7).toString();
|
||||
String fileId =s.substring(0,s.length()-2);//文件id
|
||||
resultSet.put(strBuilder.toString(),fileId);
|
||||
String standStr = strBuilder.toString();
|
||||
if(resultSet.containsKey(standStr)){
|
||||
String s1 = resultSet.get(standStr);
|
||||
|
||||
resultSet.replace(standStr,s1+","+fileId);
|
||||
}else {
|
||||
resultSet.put(standStr,fileId);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,169 @@
|
||||
package com.adc.da.slrs.ImportExcelDatas.comment;
|
||||
|
||||
import com.adc.da.att.service.IAttFileEOService;
|
||||
import com.adc.da.att.vo.AttFileVo;
|
||||
import com.adc.da.slrs.ImportExcelDatas.POIUtil.POIUtil;
|
||||
import com.adc.da.slrs.sarStandardsInfo.entity.SarStandardsInfo;
|
||||
import com.adc.da.utils.util.InitStandAttrUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.google.gson.Gson;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
@Component
|
||||
public class Standard {
|
||||
|
||||
|
||||
@Autowired
|
||||
private IAttFileEOService attFileEOService;
|
||||
|
||||
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(Standard.class);
|
||||
Map<String,String> standAttrMap = new TreeMap<>();
|
||||
private String standType="";
|
||||
|
||||
|
||||
|
||||
Standard(){
|
||||
/**
|
||||
* 初始化国内外标准属性字段
|
||||
*/
|
||||
List<String> listStandField = InitStandAttrUtil.queryFieldList;
|
||||
listStandField.forEach(item ->{
|
||||
this.standAttrMap.put(item,"");
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void setStandType(String standType) {
|
||||
|
||||
if (!"INLAND,FOREIGN".contains(standType)){
|
||||
logger.error("标准类别错误");
|
||||
}else {
|
||||
this.standType = standType;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public SarStandardsInfo getStandardsInfo(Row row){
|
||||
|
||||
|
||||
SarStandardsInfo sarStandardsInfo = new SarStandardsInfo();
|
||||
|
||||
|
||||
if ("".equals(standType)){
|
||||
logger.error("未设置标准类型");
|
||||
}else {
|
||||
sarStandardsInfo.setStandType(standType);
|
||||
}
|
||||
|
||||
|
||||
sarStandardsInfo.setValidFlag("0");
|
||||
Map<String, String> fieldMap = standAttrMap;//标准字段初化
|
||||
for (int i=0;i<10;i++){
|
||||
Cell cell = row.getCell(i);
|
||||
String value = POIUtil.getCellValueByCell(cell);
|
||||
switch (i){
|
||||
case 0://标准名称
|
||||
sarStandardsInfo.setStandName(value);
|
||||
break;
|
||||
case 2://标准状态
|
||||
//TODO 标准状态转换为代码
|
||||
switch (value){
|
||||
case "有效":
|
||||
value="vsaga7nwub";
|
||||
break;
|
||||
case "作废":
|
||||
value="chblaarg77";
|
||||
break;
|
||||
case "参考":
|
||||
value="-";
|
||||
break;
|
||||
case "0":
|
||||
value="-";
|
||||
break;
|
||||
default:value="-";
|
||||
}
|
||||
sarStandardsInfo.setTextStatus(value);
|
||||
break;
|
||||
case 3://发布日期
|
||||
//日期格式转换 1970/1/1 时发布日期为空
|
||||
if ("1970/1/1".equals(value.trim())){
|
||||
value="";
|
||||
}
|
||||
sarStandardsInfo.setIssueTime(value);
|
||||
break;
|
||||
case 4://实施日期
|
||||
fieldMap.put("SSRQ", value);
|
||||
break;
|
||||
case 5://代替标准号
|
||||
fieldMap.put("DTBJH", value);
|
||||
break;
|
||||
case 6://标准类别
|
||||
sarStandardsInfo.setStandSort(value);
|
||||
break;
|
||||
case 7://标准号
|
||||
sarStandardsInfo.setStandNumber(value);
|
||||
break;
|
||||
case 8://标准年份
|
||||
sarStandardsInfo.setStandYear(value);
|
||||
break;
|
||||
case 9://附件路径 ->上传
|
||||
HashMap<String,String> pathMap = JSON.parseObject(value, HashMap.class);
|
||||
if (pathMap!=null){
|
||||
Cell standCodeCell = row.getCell(1);
|
||||
String standCode = POIUtil.getCellValueByCell(standCodeCell);
|
||||
|
||||
StringBuilder fileNameBuilder = new StringBuilder();
|
||||
fileNameBuilder.append(standCode) //标准号
|
||||
.append(sarStandardsInfo.getStandName());//标准名称
|
||||
AttFileVo fileInfo = importFile(pathMap,fileNameBuilder.toString());//上传文件
|
||||
fieldMap.put("FBGBJBD", fileInfo.getAttId());
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Gson gson = new Gson();
|
||||
String attrInfoJson = gson.toJson(fieldMap);
|
||||
sarStandardsInfo.setSarStandAttrEOStr(attrInfoJson);//新增修改时属性表信息
|
||||
|
||||
return sarStandardsInfo;
|
||||
}
|
||||
|
||||
|
||||
private AttFileVo importFile(HashMap<String,String> pathMap,String customName){
|
||||
String realPath = "";
|
||||
|
||||
for(String path: pathMap.values()) {
|
||||
String filePath[] = path.split("/");
|
||||
for (int i = 3; i < filePath.length; i++) {
|
||||
realPath = realPath + "/" + filePath[i];
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
File file = new File("/data/from12/Attach_swf_bak" + realPath);
|
||||
|
||||
|
||||
return attFileEOService.insertFileInfo(file,customName);
|
||||
}
|
||||
|
||||
}
|
||||
+14
-2
@@ -4,6 +4,7 @@ import com.adc.da.base.web.BaseController;
|
||||
import com.adc.da.common.ReadExcel;
|
||||
import com.adc.da.slrs.ImportExcelDatas.comment.*;
|
||||
import com.adc.da.slrs.ImportExcelDatas.entity.ImportDto;
|
||||
import com.adc.da.slrs.ImportExcelDatas.service.IImportStandExcelService;
|
||||
import com.adc.da.slrs.ImportExcelDatas.service.ImportExcelService;
|
||||
import com.adc.da.util.exception.AdcDaBaseException;
|
||||
import com.adc.da.util.utils.IOUtils;
|
||||
@@ -155,7 +156,7 @@ public class ImportExcelController extends BaseController<ImportDto> {
|
||||
|
||||
|
||||
|
||||
@ApiOperation("匹配文件id")
|
||||
@ApiOperation("匹配文件id(多个id)")
|
||||
@PostMapping("/matching")
|
||||
public void matching(MultipartFile targetExcel,MultipartFile attachExcel) throws IOException {
|
||||
StandMatcher standMatcher = new StandMatcher();
|
||||
@@ -163,7 +164,7 @@ public class ImportExcelController extends BaseController<ImportDto> {
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("根据文件id和标准匹配文件路径")
|
||||
@ApiOperation("根据文件id和标准号匹配文件路径")
|
||||
@PostMapping("/matchingPath")
|
||||
public void matchingPath(MultipartFile targetExcel,MultipartFile attachExcel) throws IOException {
|
||||
|
||||
@@ -171,4 +172,15 @@ public class ImportExcelController extends BaseController<ImportDto> {
|
||||
pathMatcher.run(targetExcel,attachExcel);
|
||||
}
|
||||
|
||||
|
||||
@Autowired
|
||||
private IImportStandExcelService iImportStandExcelService;
|
||||
|
||||
@ApiOperation("根据分解后的excel表 导入标准数据和附件")
|
||||
@PostMapping("importStandFormExcel")
|
||||
public void importStandFormExcel(MultipartFile targetExcel,String standType) throws IOException {
|
||||
iImportStandExcelService.importStandExcel(targetExcel,standType);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package com.adc.da.slrs.ImportExcelDatas.service;
|
||||
|
||||
import com.adc.da.slrs.ImportExcelDatas.entity.ImportDto;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface IImportStandExcelService {
|
||||
|
||||
String importStandExcel(MultipartFile file,String standType) throws IOException;
|
||||
|
||||
}
|
||||
+5
@@ -18,4 +18,9 @@ public interface ImportExcelService extends IService<ImportDto> {
|
||||
|
||||
|
||||
public String isExist(MultipartFile exclFile);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
+8
-5
@@ -324,11 +324,14 @@ public class ImportExcelServiceImpl extends ServiceImpl<ImportExcelDao, ImportDt
|
||||
List<DicTypeEO> isExist = dicTypeEOService.getTypeIdByDicIdAndTypeName("JKSADFH564S", null, null, null);
|
||||
isExist.forEach(item->{
|
||||
sarSort.add(item.getDicTypeCode());
|
||||
});
|
||||
});//标准类别集合
|
||||
|
||||
|
||||
error = importListMap.get("error");
|
||||
|
||||
/**
|
||||
* 计数
|
||||
*/
|
||||
AtomicInteger QYBZcount= new AtomicInteger();
|
||||
AtomicInteger QYBZcountUpdate= new AtomicInteger();
|
||||
AtomicInteger HWBZcount= new AtomicInteger();
|
||||
@@ -350,7 +353,7 @@ public class ImportExcelServiceImpl extends ServiceImpl<ImportExcelDao, ImportDt
|
||||
*/
|
||||
|
||||
|
||||
/*importListMap.get("HWBZ").forEach(item -> {
|
||||
importListMap.get("HWBZ").forEach(item -> {
|
||||
if (true ) {
|
||||
String standID = UUIDUtils.randomUUID20();
|
||||
|
||||
@@ -409,14 +412,14 @@ public class ImportExcelServiceImpl extends ServiceImpl<ImportExcelDao, ImportDt
|
||||
|
||||
|
||||
|
||||
});*/
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* 国内标准
|
||||
*/
|
||||
|
||||
/*importListMap.get("GNBZ").forEach(item -> {
|
||||
importListMap.get("GNBZ").forEach(item -> {
|
||||
|
||||
|
||||
if (true) {
|
||||
@@ -472,7 +475,7 @@ public class ImportExcelServiceImpl extends ServiceImpl<ImportExcelDao, ImportDt
|
||||
|
||||
}
|
||||
|
||||
});*/
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
package com.adc.da.slrs.ImportExcelDatas.service.impl;
|
||||
|
||||
import com.adc.da.att.service.IAttFileEOService;
|
||||
import com.adc.da.att.vo.AttFileVo;
|
||||
import com.adc.da.slrs.ImportExcelDatas.POIUtil.POIUtil;
|
||||
import com.adc.da.slrs.ImportExcelDatas.comment.PathMatcher;
|
||||
import com.adc.da.slrs.ImportExcelDatas.comment.Standard;
|
||||
import com.adc.da.slrs.ImportExcelDatas.entity.ImportDto;
|
||||
import com.adc.da.slrs.ImportExcelDatas.service.IImportStandExcelService;
|
||||
import com.adc.da.slrs.sarBussionessStand.entity.SarBussionessStand;
|
||||
import com.adc.da.slrs.sarBussionessStand.service.ISarBussionessStandService;
|
||||
import com.adc.da.slrs.sarStandardsInfo.entity.SarStandardsInfo;
|
||||
import com.adc.da.slrs.sarStandardsInfo.service.ISarStandardsInfoService;
|
||||
import com.adc.da.sys.service.impl.DicTypeEOServiceImpl;
|
||||
import com.adc.da.utils.util.InitStandAttrUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.google.gson.Gson;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.xssf.usermodel.XSSFRow;
|
||||
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@Service
|
||||
public class ImportStandExcelServiceImpl implements IImportStandExcelService {
|
||||
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(PathMatcher.class);
|
||||
@Autowired
|
||||
private ISarStandardsInfoService sarStandardsInfoService;
|
||||
|
||||
@Autowired
|
||||
private Standard standard;
|
||||
|
||||
private List<ImportDto> error = new ArrayList<>();
|
||||
|
||||
private List<ImportDto> fileError = new ArrayList<>();
|
||||
|
||||
|
||||
@Async
|
||||
@Override
|
||||
public String importStandExcel(MultipartFile file,String standType) throws IOException {
|
||||
|
||||
AtomicInteger countUpdate= new AtomicInteger();//更新 数量
|
||||
AtomicInteger countInsert= new AtomicInteger();//新增 数量
|
||||
|
||||
InputStream inputStream = file.getInputStream();
|
||||
XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
|
||||
XSSFSheet sheet = workbook.getSheetAt(0);
|
||||
|
||||
standard.setStandType(standType);
|
||||
|
||||
int lastRowNum = sheet.getLastRowNum();
|
||||
|
||||
for (int i = 1; i < lastRowNum; i++) {
|
||||
XSSFRow row = sheet.getRow(i);
|
||||
SarStandardsInfo standardsInfo = standard.getStandardsInfo(row);
|
||||
|
||||
QueryWrapper<SarStandardsInfo> standSaveWrapper = new QueryWrapper<>();
|
||||
standSaveWrapper
|
||||
.eq("STAND_SORT", standardsInfo.getStandSort())
|
||||
.eq("STAND_NUMBER", standardsInfo.getStandNumber())
|
||||
.eq("STAND_YEAR", standardsInfo.getStandYear());
|
||||
|
||||
|
||||
SarStandardsInfo one = sarStandardsInfoService.getOne(standSaveWrapper);
|
||||
if (one != null) {
|
||||
|
||||
|
||||
standardsInfo.setId(one.getId());
|
||||
try {
|
||||
sarStandardsInfoService.updateSarStandardsInfo(standardsInfo);
|
||||
countUpdate.getAndIncrement();
|
||||
logger.info("执行更新"+countUpdate+"条数据");
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
try {
|
||||
sarStandardsInfoService.createSarStandardsInfo(standardsInfo);
|
||||
countInsert.getAndIncrement();
|
||||
logger.info("执行新增"+countInsert+"条数据");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return "success";
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
+3
-2
@@ -5,6 +5,7 @@ import com.adc.da.http.Result;
|
||||
import com.adc.da.slrs.sarIssueTrack.entity.IssueTrack;
|
||||
import com.adc.da.slrs.sarIssueTrack.entity.IssueTrackVo;
|
||||
import com.adc.da.slrs.sarIssueTrack.service.IIssueTrackService;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -42,8 +43,8 @@ public class IssueTrackController {
|
||||
|
||||
@GetMapping
|
||||
@ApiOperation("查询重点标准跟踪清单")
|
||||
public ResponseMessage<List<IssueTrack>> getIssueTrack(IssueTrackVo wrapper){
|
||||
List<IssueTrack> issueTrack = issueTrackService.getIssueTrack(wrapper);
|
||||
public ResponseMessage<IPage<IssueTrack>> getIssueTrack(IssueTrackVo wrapper){
|
||||
IPage<IssueTrack> issueTrack = issueTrackService.getIssueTrack(wrapper);
|
||||
return Result.success(issueTrack);
|
||||
}
|
||||
|
||||
|
||||
@@ -37,5 +37,10 @@ public class IssueTrack {
|
||||
@TableField("del_flag")
|
||||
private String delFlag;
|
||||
|
||||
@TableField(exist = false)
|
||||
private Integer page;
|
||||
|
||||
@TableField(exist = false)
|
||||
private Integer pageSize;
|
||||
|
||||
}
|
||||
|
||||
+2
-1
@@ -2,6 +2,7 @@ package com.adc.da.slrs.sarIssueTrack.service;
|
||||
|
||||
import com.adc.da.slrs.sarIssueTrack.entity.IssueTrack;
|
||||
import com.adc.da.slrs.sarIssueTrack.entity.IssueTrackVo;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -11,7 +12,7 @@ public interface IIssueTrackService {
|
||||
|
||||
public boolean removeIssueTrack(List<String> idList);
|
||||
|
||||
public List<IssueTrack> getIssueTrack(IssueTrackVo objVo);
|
||||
public IPage<IssueTrack> getIssueTrack(IssueTrackVo objVo);
|
||||
|
||||
public boolean updateIssueTrack(IssueTrack obj);
|
||||
}
|
||||
|
||||
+33
-18
@@ -6,7 +6,10 @@ import com.adc.da.slrs.sarIssueTrack.entity.IssueTrackVo;
|
||||
import com.adc.da.slrs.sarIssueTrack.service.IIssueTrackService;
|
||||
import com.adc.da.util.UUIDUtils;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -14,6 +17,12 @@ import java.util.List;
|
||||
|
||||
@Service
|
||||
public class IssueTrackServiceImpl extends ServiceImpl<IssueTrackDao, IssueTrack> implements IIssueTrackService {
|
||||
|
||||
|
||||
@Autowired
|
||||
private IssueTrackDao issueTrackDao;
|
||||
|
||||
|
||||
@Override
|
||||
public boolean addIssueTrack(IssueTrack obj) {
|
||||
obj.setId(UUIDUtils.randomUUID20());
|
||||
@@ -27,27 +36,33 @@ public class IssueTrackServiceImpl extends ServiceImpl<IssueTrackDao, IssueTrack
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IssueTrack> getIssueTrack(IssueTrackVo objVo) {
|
||||
List<IssueTrack> result=new ArrayList<>();
|
||||
if (objVo==null){
|
||||
result=this.list();
|
||||
public IPage<IssueTrack> getIssueTrack(IssueTrackVo objVo) {
|
||||
|
||||
IPage<IssueTrack> trackPage = new Page<>(objVo.getPage(), objVo.getPageSize());
|
||||
|
||||
QueryWrapper<IssueTrack> wrapper = new QueryWrapper<>();
|
||||
|
||||
if (objVo.getPage()!=null && objVo.getPageSize()!=null){
|
||||
trackPage=new Page<>(objVo.getPage(),objVo.getPageSize());
|
||||
}else {
|
||||
QueryWrapper<IssueTrack> wrapper = new QueryWrapper<>();
|
||||
|
||||
if (objVo.getLawId()!=null){
|
||||
wrapper.like("law_id",objVo.getLawId());
|
||||
}
|
||||
if (objVo.getLawName()!=null){
|
||||
wrapper.like("law_name",objVo.getLawName());
|
||||
}
|
||||
if (objVo.getProductType()!=null){
|
||||
wrapper.like("product_type",objVo.getProductType());
|
||||
}
|
||||
|
||||
result=list(wrapper);
|
||||
Integer count = issueTrackDao.selectCount(wrapper);
|
||||
trackPage=new Page<>(0,count,false);
|
||||
}
|
||||
|
||||
return result;
|
||||
if (objVo.getLawId()!=null){
|
||||
wrapper.like("law_id",objVo.getLawId());
|
||||
}
|
||||
if (objVo.getLawName()!=null){
|
||||
wrapper.like("law_name",objVo.getLawName());
|
||||
}
|
||||
if (objVo.getProductType()!=null){
|
||||
wrapper.like("product_type",objVo.getProductType());
|
||||
}
|
||||
|
||||
trackPage = issueTrackDao.selectPage(trackPage, wrapper);
|
||||
|
||||
|
||||
return trackPage;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -22,4 +22,6 @@ public interface IAttFileEOService extends IService<AttFileEO> {
|
||||
|
||||
public String saveFileAttId(File file);
|
||||
|
||||
public AttFileVo insertFileInfo(File file,String fileName);
|
||||
|
||||
}
|
||||
|
||||
@@ -358,4 +358,74 @@ public class AttFileEOServiceImpl extends ServiceImpl<AttFileEODao, AttFileEO> i
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 保存文件并返回文件ID
|
||||
*
|
||||
* @param file
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public AttFileVo insertFileInfo(File file,String customFileName) {
|
||||
/**
|
||||
* 1、首先生成文件保存的主键ID
|
||||
* 2、根据文件ID生成随机路径
|
||||
* 3、生成文件名
|
||||
* 3、保存文件
|
||||
* 4、获取文件相关信息
|
||||
* 5、判断当前表是否有存在,如果存在则执行insert语句 如果不存在则创建表结构
|
||||
* 5、保存入库并返回主键ID
|
||||
*/
|
||||
AttFileVo attFileVo = new AttFileVo();
|
||||
String fileId = UUIDUtils.randomUUID20();
|
||||
try {
|
||||
String uuidPath = UUIDUtils.getUUIDPath(fileId);
|
||||
|
||||
String FileSavePath = filePath + uuidPath + "/";
|
||||
File dir = new File(FileSavePath);
|
||||
if (!dir.exists()) {
|
||||
dir.mkdirs();
|
||||
}
|
||||
|
||||
String fileName = file.getName();
|
||||
String fileSuffix = fileName.substring(fileName.lastIndexOf(".")+1, fileName.length());
|
||||
|
||||
String newFileName = fileId +"."+ fileSuffix;
|
||||
String oldName=customFileName+"."+fileSuffix;
|
||||
|
||||
|
||||
|
||||
File saveFile = new File(FileSavePath + newFileName);
|
||||
FileUtils.copyFile(file,saveFile);
|
||||
//开始存储文件信息
|
||||
String tableName = UUIDUtils.getAttTable();
|
||||
int existTable = this.baseMapper.existTable(tableName);
|
||||
if (existTable == 0) {
|
||||
this.baseMapper.creatTableInfo(tableName);
|
||||
}
|
||||
fileId = tableName + "_" + fileId;
|
||||
AttFileEO attFileEO = new AttFileEO();
|
||||
attFileEO.setTableName(tableName);
|
||||
attFileEO.setId(fileId);
|
||||
attFileEO.setOldFileName(customFileName);
|
||||
attFileEO.setFileSuffix(fileSuffix);
|
||||
attFileEO.setFilePath(uuidPath);
|
||||
attFileEO.setFileName(oldName);
|
||||
attFileEO.setValidFlag(ValidFlagEnum.VALID_TRUE.getValue());
|
||||
attFileEO.setCreationTime(new Date());
|
||||
attFileEO.setModifyTime(new Date());
|
||||
this.baseMapper.insertData(attFileEO);
|
||||
attFileVo.setId(fileId);
|
||||
attFileVo.setFileName(newFileName);
|
||||
attFileVo.setFilePath(uuidPath);
|
||||
attFileVo.setFileSuffix(fileSuffix);
|
||||
attFileVo.setOldFileName(oldName);
|
||||
} catch (IOException e) {
|
||||
log.error(e.getMessage(),e);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(),e);
|
||||
}
|
||||
return attFileVo;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user