对企标修改功能的企标标准号和企标名称的校验进行修正
This commit is contained in:
+181
-3
@@ -3,10 +3,12 @@ package com.adc.da.slrs.sarBussionessStand.controller;
|
||||
|
||||
import com.adc.da.Log.BusinessType;
|
||||
import com.adc.da.Log.EpcLog;
|
||||
import com.adc.da.common.FileUnZip;
|
||||
import com.adc.da.common.ReadExcel;
|
||||
import com.adc.da.person.service.IPersonCollectEOService;
|
||||
import com.adc.da.slrs.sarBussionessStand.entity.SarBussionessStandExport;
|
||||
import com.adc.da.slrs.sarBussionessStand.service.ISarBussionessStandService;
|
||||
import com.adc.da.slrs.sarLawsInfo.service.ISarLawsInfoService;
|
||||
import com.adc.da.slrs.sarResource.entity.TsResource;
|
||||
import com.adc.da.slrs.sarResource.service.ITsResourceService;
|
||||
import com.adc.da.slrs.sarStandardsInfo.entity.SarAdvanceSearchVO;
|
||||
@@ -23,25 +25,33 @@ import com.adc.da.util.exception.AdcDaBaseException;
|
||||
import com.adc.da.util.utils.IOUtils;
|
||||
import com.adc.da.util.utils.StringUtils;
|
||||
import com.adc.da.utils.util.BussStandExportUtil;
|
||||
import com.adc.da.utils.util.FieldConvertUtil;
|
||||
import com.adc.da.utils.util.SarAdvanceSearchUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import com.adc.da.slrs.sarBussionessStand.entity.SarBussionessStand;
|
||||
import io.swagger.annotations.Api;
|
||||
import com.adc.da.base.web.BaseController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -74,6 +84,12 @@ public class SarBussionessStandController extends BaseController<SarBussionessSt
|
||||
@Autowired
|
||||
private IDicTypeEOService dicTypeEOService;
|
||||
|
||||
@Value("${file.path}")
|
||||
private String filePath;
|
||||
|
||||
@Autowired
|
||||
ISarLawsInfoService sarLawsInfoEOService;
|
||||
|
||||
/**
|
||||
* 根据计划库制定状态查询企标编号
|
||||
*
|
||||
@@ -143,6 +159,14 @@ public class SarBussionessStandController extends BaseController<SarBussionessSt
|
||||
//401问题2021-03-31暂时注释掉 liuhuiwen
|
||||
// @RequiresPermissions("lawss:sarBussionessStand:updateSarBussionessStand")
|
||||
public ResponseMessage<SarBussionessStand> updateSarBussionessStand(@RequestBody SarBussionessStand sarBussionessStandEO) throws Exception {
|
||||
//校验编号和名称是否存在
|
||||
QueryWrapper<SarBussionessStand> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq(null!=sarBussionessStandEO.getStandCode(),"STAND_CODE",sarBussionessStandEO.getStandCode())
|
||||
.eq(null!=sarBussionessStandEO.getStandName(),"STAND_NAME",sarBussionessStandEO.getStandName());
|
||||
List<SarBussionessStand> list = sarBussionessStandEOService.list(queryWrapper);
|
||||
if ((list.size() ==1 && !list.get(0).getId().equals(sarBussionessStandEO.getId())) || list.size() >1){
|
||||
return Result.error("当前企标标准号和企标名称已存在");
|
||||
}
|
||||
sarBussionessStandEO.setModifyTime(new Date());
|
||||
sarBussionessStandEOService.updateSarBussionessStand(sarBussionessStandEO);
|
||||
return Result.success("","修改成功",sarBussionessStandEO);
|
||||
@@ -381,6 +405,160 @@ public class SarBussionessStandController extends BaseController<SarBussionessSt
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "|SarBussionessStand|导入")
|
||||
@PostMapping("/importSarBussionessStand")
|
||||
public ResponseMessage<SarBussionessStand> importSarBussionessStandFile(@RequestParam(value = "file",required = false) MultipartFile file)throws Exception {
|
||||
//截取后缀名
|
||||
int pos = file.getOriginalFilename().lastIndexOf(".");
|
||||
String str = file.getOriginalFilename().substring(pos + 1).toLowerCase();
|
||||
String filenameorg = file.getOriginalFilename().substring(0, pos);
|
||||
//判断上传文件必须是zip
|
||||
if (!str.equals("zip")) {
|
||||
return Result.error("fail", "请上传zip文件");
|
||||
}
|
||||
String path = filePath + "/modal/" + filenameorg;
|
||||
File saveDirectory = new File(path);
|
||||
if (!saveDirectory.isDirectory()) {
|
||||
saveDirectory.mkdir();
|
||||
}
|
||||
FileUtils.copyInputStreamToFile(file.getInputStream(), new File(path + "/" + file.getOriginalFilename()));
|
||||
try {
|
||||
//解压缩
|
||||
String zipEntryName = FileUnZip.unZipFiles(path + "/" + file.getOriginalFilename(), path);
|
||||
// 数据相关处理,
|
||||
// 1.获取其中的Excel,
|
||||
List<File> excelfilelist = FileUnZip.readImpExcelFile(zipEntryName);
|
||||
System.gc();
|
||||
if (excelfilelist.size() < 1) {
|
||||
int i = 0;
|
||||
for (File file1 : excelfilelist) {
|
||||
if (file1.getName().indexOf("导入模板") > -1) {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
if (i == 0) {
|
||||
//删除原上传文件
|
||||
FileUnZip.deleteDir(saveDirectory);
|
||||
return Result.error("fail", "压缩包内没有上传导入模板Excel");
|
||||
}
|
||||
} else if (excelfilelist.size() > 1) {
|
||||
int i = 0;
|
||||
for (File file1 : excelfilelist) {
|
||||
if (file1.getName().indexOf("导入模板") > -1) {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
if (i > 1) {
|
||||
//删除原上传文件
|
||||
FileUnZip.deleteDir(saveDirectory);
|
||||
return Result.error("fail", "压缩包内有多个导入模板Excel");
|
||||
}
|
||||
}
|
||||
File excelfile = excelfilelist.get(0);
|
||||
for (File file1 : excelfilelist) {
|
||||
if (file1.getName().indexOf("导入模板") > -1) {
|
||||
excelfile = file1;
|
||||
}
|
||||
}
|
||||
// 导入参数设置,默认即可
|
||||
Workbook workbook = null;
|
||||
try {
|
||||
workbook = WorkbookFactory.create(excelfile);
|
||||
List<Map<String, String>> dataList = new ArrayList<>();
|
||||
if (workbook != null) {
|
||||
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
|
||||
Sheet sheet = workbook.getSheetAt(0);
|
||||
if (sheet != null) {
|
||||
StringBuilder headerSb = new StringBuilder();
|
||||
int rowNos = sheet.getLastRowNum();// 得到excel的总记录条数
|
||||
for (int i = 0; i <= rowNos; i++) {// 遍历行
|
||||
Row row = sheet.getRow(i);
|
||||
Row headerRow = sheet.getRow(0);
|
||||
boolean isBlank = sarLawsInfoEOService.isRowEmpty(row);
|
||||
if (row != null && !isBlank) {
|
||||
int columNos = headerRow.getLastCellNum();// 表头总共的列数
|
||||
Map<String, String> rowList = new LinkedHashMap<>();
|
||||
for (int j = 0; j < columNos; j++) {
|
||||
Cell cell = row.getCell(j);
|
||||
Cell headerCell = headerRow.getCell(j);
|
||||
if (cell != null) {
|
||||
if (i == 0) {
|
||||
cell.setCellType(CellType.STRING);
|
||||
headerSb.append(cell.getStringCellValue() + ",");
|
||||
} else {
|
||||
if (CellType.NUMERIC == cell.getCellType() && HSSFDateUtil.isCellDateFormatted(cell)) {
|
||||
Date d = cell.getDateCellValue();
|
||||
rowList.put(headerCell.getStringCellValue(), df.format(d));
|
||||
} else {
|
||||
cell.setCellType(CellType.STRING);
|
||||
rowList.put(headerCell.getStringCellValue(), cell.getStringCellValue());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (i != 0) {
|
||||
rowList.put(headerCell.getStringCellValue(), "");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (i != 0) {
|
||||
dataList.add(rowList);
|
||||
}
|
||||
}
|
||||
}
|
||||
String fields = FieldConvertUtil.exportBaseFieldNamesBuss + "," + FieldConvertUtil.exportBaseFieldNamesBussCode + ",";
|
||||
String excelHeader = headerSb.toString();
|
||||
if (!fields.equals(excelHeader)) {
|
||||
workbook.close();
|
||||
//删除原上传文件
|
||||
FileUnZip.deleteDir(saveDirectory);
|
||||
return Result.error("fail", "读取失败,请严格按照模板文件导入数据");
|
||||
}
|
||||
}
|
||||
}
|
||||
//导入
|
||||
if(dataList!=null &&!dataList.isEmpty()){
|
||||
try {
|
||||
String unzipfilepath = zipEntryName;
|
||||
ResponseMessage<SarBussionessStand> message = sarBussionessStandEOService.importSarBussionessStand(dataList,unzipfilepath);
|
||||
workbook.close();
|
||||
//删除原上传文件
|
||||
FileUnZip.deleteDir(saveDirectory);
|
||||
return message;
|
||||
} catch (Exception e) {
|
||||
workbook.close();
|
||||
//删除原上传文件
|
||||
FileUnZip.deleteDir(saveDirectory);
|
||||
return Result.error("fail", e.getMessage());
|
||||
}
|
||||
}else{
|
||||
if (workbook != null) {
|
||||
workbook.close();
|
||||
}
|
||||
//删除原上传文件
|
||||
FileUnZip.deleteDir(saveDirectory);
|
||||
return Result.error("fail", "没有可导入的数据,请检查!");
|
||||
}
|
||||
} catch (NoSuchElementException e){
|
||||
if (workbook != null) {
|
||||
workbook.close();
|
||||
}
|
||||
FileUnZip.deleteDir(saveDirectory);
|
||||
return Result.error("fail", "没有可导入的数据,请检查!");
|
||||
} catch (Exception e) {
|
||||
if (workbook != null) {
|
||||
workbook.close();
|
||||
}
|
||||
//删除原上传文件
|
||||
FileUnZip.deleteDir(saveDirectory);
|
||||
return Result.error("fail", "读取失败,请严格按照模板文件导入数据");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
//删除原上传文件
|
||||
FileUnZip.deleteDir(saveDirectory);
|
||||
return Result.error("fail", "读取失败,请严格按照模板文件导入数据");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user