public Object excelImportTechResourceTmp(MultipartFile file) throws IOException {
LoginResult loginResult = this.getLoginUser();
if (file.getSize() == 0) {
return “excel表格异常”;
}
// 正式表
List techResourceList = new ArrayList<>();
// 临时表
List techResourceTmpList = new ArrayList<>();
// 需要待插入的大类
List techResourceUndertakeAddList = new ArrayList<>();
List techResourceCooperationAddList = new ArrayList<>();
List techResourceAppropriationLevelAddList = new ArrayList<>();
String fileName = file.getOriginalFilename();
String suffix = fileName.substring(fileName.lastIndexOf("."));
if (suffix.equals(".xls")) {
// 建立Excel对象
HSSFWorkbook workbook = new HSSFWorkbook(new POIFSFileSystem(file.getInputStream()));
// 获取Excel中的sheet数量
int numberOfSheets = workbook.getNumberOfSheets();
for (int i = 0; i < numberOfSheets; i++) {
// 获取excel sheet
HSSFSheet sheet = workbook.getSheetAt(i);
// 获取行的数量
int physicalNumberOfRows = sheet.getPhysicalNumberOfRows();
if (physicalNumberOfRows <= 1) {
workbook.close();
return “excel表格异常”;
}
// 查询业务处室 承担单位 主要协作单位 放到map 里面
SysOrgInfoQueryParam sysOrgInfoQueryParam = new SysOrgInfoQueryParam();
sysOrgInfoQueryParam.setPid(2);
sysOrgInfoQueryParam.setOrgTypes(“2,7”);
// 包含shortName简称和orgName只要有一个符合 就正确 需要进行判断
List orgList = sysOrgInfoMapper.selectQuery(sysOrgInfoQueryParam);
// orgName 的hashMap
HashMap<String, SysOrgInfo> orgNameHashMap = new HashMap<>();
// shortName 的hashMap
HashMap<String, SysOrgInfo> shortNameHashMap = new HashMap<>();
for (SysOrgInfo orgInfo : orgList) {
orgNameHashMap.put(orgInfo.getOrgName(), orgInfo);
shortNameHashMap.put(orgInfo.getShortName(), orgInfo);
}
// 查询拨款级放到map 里面
MasterCodeBQueryParam masterCodeBParam = new MasterCodeBQueryParam();
masterCodeBParam.setClassa(“TAL”);
masterCodeBParam.setPs(Integer.MAX_VALUE);
List appropriationLevelList = masterCodeBMapper.listQuery(masterCodeBParam);
// 拨款级的map
HashMap<String, MasterCodeB> appropriationLevelHashMap = new HashMap<>();
for (MasterCodeB masterCodeB : appropriationLevelList) {
appropriationLevelHashMap.put(masterCodeB.getName(), masterCodeB);
}
for (int j = 0; j < physicalNumberOfRows; j++) {
// 如果有标题则第一列不进行加载
if (j == 0) {
continue;// 标题行
} else {
// 获取该行的数据信息
HSSFRow row = sheet.getRow(j);
// 需要对每一行的数据进行一下非空处理
// 项目编号不能为空
if (row != null && row.getCell(1) != null && row.getCell(1).getStringCellValue().length() > 0) {
TechResourceTmp techResourceTmp = new TechResourceTmp();
if (row.getCell(1).getStringCellValue() != null) {
techResourceTmp.setProjectNumber(row.getCell(1).getStringCellValue());
}
// 资源类型
techResourceTmp.setResourceType("6");
// 计划类别
if (row.getCell(2) != null && row.getCell(2).getStringCellValue() != null) {
MasterCodeBQueryParam masterCodeBQueryParam = new MasterCodeBQueryParam();
masterCodeBQueryParam.setClassa("TPT");
masterCodeBQueryParam.setName(row.getCell(2).getStringCellValue());
masterCodeBQueryParam.setPs(Integer.MAX_VALUE);
List<MasterCodeB> listQuery = masterCodeBMapper.listQuery(masterCodeBQueryParam);
if (listQuery.size() > 0) {
for (MasterCodeB masterCodeB : listQuery) {
if (masterCodeB.getName().equals(row.getCell(2).getStringCellValue())) {
techResourceTmp.setProjectType(masterCodeB.getClassb());
techResourceTmp.setProjectTypeQualified(1);
techResourceTmp.setIsQualified(1);
} else {
techResourceTmp.setProjectType(row.getCell(2).getStringCellValue());
techResourceTmp.setProjectTypeQualified(0);
techResourceTmp.setIsQualified(0);
}
}
} else {
techResourceTmp.setProjectType(row.getCell(2).getStringCellValue());
techResourceTmp.setProjectTypeQualified(0);
techResourceTmp.setIsQualified(0);
}
}
// 项目名称
if (row.getCell(3) != null && row.getCell(3).getStringCellValue() != null) {
techResourceTmp.setProjectName(row.getCell(3).getStringCellValue());
}
// 承担单位
if (row.getCell(4) != null && row.getCell(4).getStringCellValue() != null) {
// 两种情况 如果导入的数据包含、 要进行切割验证
if (row.getCell(4).getStringCellValue().contains("、")) {
String rowValue = row.getCell(4).getStringCellValue().replaceAll("\r|\n", "");
// 多条的情况
String[] undertakeUnitArray = rowValue.split("、");
int length = undertakeUnitArray.length;
int count = 0;
for (String str : undertakeUnitArray) {
if (orgNameHashMap.containsKey(str) || shortNameHashMap.containsKey(str)) {
count++;
}
}
if (length != count) {
techResourceTmp.setUndertakeUnitName(row.getCell(4).getStringCellValue());
techResourceTmp.setUndertakeUnitQualified(0);
techResourceTmp.setIsQualified(0);
} else {
SysOrgInfo sysOrginfo = new SysOrgInfo();
techResourceTmp.setTechResourceUndertakeList(new ArrayList<>());
String undertakeUnitName = "";
for (String str : undertakeUnitArray) {
TechResourceUndertakeUnitR techResourceUndertakeUnitR = new TechResourceUndertakeUnitR();
if (orgNameHashMap.containsKey(str)) {
sysOrginfo = orgNameHashMap.get(str);
// techResourceTmp.setUndertakeUnitId(sysOrginfo.getId());
undertakeUnitName += sysOrginfo.getOrgName() + "、";
techResourceTmp.setUndertakeUnitName(
undertakeUnitName.substring(0, undertakeUnitName.length() - 1));
techResourceTmp.setUndertakeUnitQualified(1);
techResourceTmp.setIsQualified(1);
techResourceUndertakeUnitR.setUndertakeUnitId(sysOrginfo.getId());
techResourceUndertakeUnitR
.setUndertakeUnitName(sysOrginfo.getOrgName());
techResourceTmp.getTechResourceUndertakeList()
.add(techResourceUndertakeUnitR);
} else if (shortNameHashMap.containsKey(str)) {
sysOrginfo = shortNameHashMap.get(str);
// techResourceTmp.setUndertakeUnitId(sysOrginfo.getId());
undertakeUnitName += sysOrginfo.getShortName() + "、";
techResourceTmp.setUndertakeUnitName(
undertakeUnitName.substring(0, undertakeUnitName.length() - 1));
techResourceTmp.setUndertakeUnitQualified(1);
techResourceTmp.setIsQualified(1);
techResourceUndertakeUnitR.setUndertakeUnitId(sysOrginfo.getId());
techResourceUndertakeUnitR
.setUndertakeUnitName(sysOrginfo.getShortName());
techResourceTmp.getTechResourceUndertakeList()
.add(techResourceUndertakeUnitR);
}
// techResourceUndertakeAddList.add(techResourceUndertakeUnitR);
}
}
} else {
// 如果没有顿号分割,只有一条的情况
SysOrgInfo sysOrginfo = new SysOrgInfo();
techResourceTmp.setTechResourceUndertakeList(new ArrayList<>());
TechResourceUndertakeUnitR techResourceUndertakeUnitR = new TechResourceUndertakeUnitR();
if (orgNameHashMap.containsKey(row.getCell(4).getStringCellValue())) {
sysOrginfo = orgNameHashMap.get(row.getCell(4).getStringCellValue());
// techResourceTmp.setUndertakeUnitId(sysOrginfo.getId());
techResourceTmp.setUndertakeUnitName(sysOrginfo.getOrgName());
techResourceTmp.setUndertakeUnitQualified(1);
techResourceTmp.setIsQualified(1);
techResourceUndertakeUnitR.setUndertakeUnitId(sysOrginfo.getId());
techResourceUndertakeUnitR.setUndertakeUnitName(sysOrginfo.getOrgName());
techResourceTmp.getTechResourceUndertakeList().add(techResourceUndertakeUnitR);
} else if (shortNameHashMap.containsKey(row.getCell(4).getStringCellValue())) {
sysOrginfo = shortNameHashMap.get(row.getCell(4).getStringCellValue());
// techResourceTmp.setUndertakeUnitId(sysOrginfo.getId());
techResourceTmp.setUndertakeUnitName(sysOrginfo.getShortName());
techResourceTmp.setUndertakeUnitQualified(1);
techResourceTmp.setIsQualified(1);
techResourceUndertakeUnitR.setUndertakeUnitId(sysOrginfo.getId());
techResourceUndertakeUnitR.setUndertakeUnitName(sysOrginfo.getShortName());
techResourceTmp.getTechResourceUndertakeList().add(techResourceUndertakeUnitR);
} else {
techResourceTmp.setUndertakeUnitName(row.getCell(4).getStringCellValue());
techResourceTmp.setUndertakeUnitQualified(0);
techResourceTmp.setIsQualified(0);
}
// techResourceUndertakeAddList.add(techResourceUndertakeUnitR);
}
}
// 主要协作单位
if (row.getCell(5) != null && row.getCell(5).getStringCellValue() != null
&& !"".equals(row.getCell(5).getStringCellValue())) {
if (row.getCell(5).getStringCellValue().contains("、")) {
String rowValue = row.getCell(4).getStringCellValue().replaceAll("\r|\n", "");
String[] cooperationUnitArray = rowValue.split("、");
int length = cooperationUnitArray.length;
int count = 0;
for (String str : cooperationUnitArray) {
if (orgNameHashMap.containsKey(str) || shortNameHashMap.containsKey(str)) {
count++;
}
}
if (length != count) {
techResourceTmp.setCooperationUnitName(row.getCell(5).getStringCellValue());
techResourceTmp.setCooperationUnitQualified(0);
techResourceTmp.setIsQualified(0);
} else {
SysOrgInfo sysOrginfo = new SysOrgInfo();
techResourceTmp.setTechResourceCooperationList(new ArrayList<>());
String cooperationUnitName = "";
for (String str : cooperationUnitArray) {
TechResourceCooperationUnitR techResourceCooperationUnitR = new TechResourceCooperationUnitR();
if (orgNameHashMap.containsKey(str)) {
sysOrginfo = orgNameHashMap.get(str);
cooperationUnitName += sysOrginfo.getOrgName() + "、";
// techResourceTmp.setCooperationUnitId(sysOrginfo.getId());
techResourceTmp.setCooperationUnitName(cooperationUnitName.substring(0,
cooperationUnitName.length() - 1));
techResourceTmp.setCooperationUnitQualified(1);
techResourceTmp.setIsQualified(1);
techResourceCooperationUnitR.setCooperationUnitId(sysOrginfo.getId());
techResourceCooperationUnitR
.setCooperationUnitName(sysOrginfo.getOrgName());
techResourceTmp.getTechResourceCooperationList()
.add(techResourceCooperationUnitR);
} else if (shortNameHashMap.containsKey(str)) {
sysOrginfo = shortNameHashMap.get(str);
// techResourceTmp.setCooperationUnitId(sysOrginfo.getId());
cooperationUnitName += sysOrginfo.getOrgName() + "、";
techResourceTmp.setCooperationUnitName(cooperationUnitName.substring(0,
cooperationUnitName.length() - 1));
techResourceTmp.setCooperationUnitQualified(1);
techResourceTmp.setIsQualified(1);
techResourceCooperationUnitR.setCooperationUnitId(sysOrginfo.getId());
techResourceCooperationUnitR
.setCooperationUnitName(sysOrginfo.getShortName());
techResourceTmp.getTechResourceCooperationList()
.add(techResourceCooperationUnitR);
}
// techResourceCooperationAddList.add(techResourceCooperationUnitR);
}
}
} else {
// 进行模糊匹配修正
// 如果没有顿号分割
SysOrgInfo sysOrginfo = new SysOrgInfo();
techResourceTmp.setTechResourceCooperationList(new ArrayList<>());
TechResourceCooperationUnitR techResourceCooperationUnitR = new TechResourceCooperationUnitR();
if (orgNameHashMap.containsKey(row.getCell(5).getStringCellValue())) {
sysOrginfo = orgNameHashMap.get(row.getCell(5).getStringCellValue());
// techResourceTmp.setCooperationUnitId(sysOrginfo.getId());
techResourceTmp.setCooperationUnitName(sysOrginfo.getOrgName());
techResourceTmp.setCooperationUnitQualified(1);
techResourceTmp.setIsQualified(1);
techResourceCooperationUnitR.setCooperationUnitId(sysOrginfo.getId());
techResourceCooperationUnitR.setCooperationUnitName(sysOrginfo.getOrgName());
techResourceTmp.getTechResourceCooperationList()
.add(techResourceCooperationUnitR);
} else if (shortNameHashMap.containsKey(row.getCell(5).getStringCellValue())) {
sysOrginfo = shortNameHashMap.get(row.getCell(5).getStringCellValue());
// techResourceTmp.setCooperationUnitId(sysOrginfo.getId());
techResourceTmp.setCooperationUnitName(sysOrginfo.getShortName());
techResourceTmp.setCooperationUnitQualified(1);
techResourceTmp.setIsQualified(1);
techResourceCooperationUnitR.setCooperationUnitId(sysOrginfo.getId());
techResourceCooperationUnitR.setCooperationUnitName(sysOrginfo.getShortName());
techResourceTmp.getTechResourceCooperationList()
.add(techResourceCooperationUnitR);
} else {
// techResourceTmp.setCooperationUnitName(row.getCell(5).getStringCellValue());
techResourceTmp.setCooperationUnitQualified(0);
techResourceTmp.setIsQualified(0);
}
// techResourceCooperationAddList.add(techResourceCooperationUnitR);
}
} else {
techResourceTmp.setCooperationUnitQualified(1);
techResourceTmp.setIsQualified(1);
}
// 起止时间
if (row.getCell(6) != null && row.getCell(6).getStringCellValue() != null) {
String startEndTime = row.getCell(6).getStringCellValue();
String[] newStartEnd = startEndTime.split("-");
String startDate = newStartEnd[0];
String endDate = newStartEnd[1];
try {
techResourceTmp.setStartDate(
new Timestamp(new SimpleDateFormat("yyyy").parse(startDate).getTime()));
techResourceTmp.setEndDate(
new Timestamp(new SimpleDateFormat("yyyy").parse(endDate).getTime()));
} catch (ParseException e) { // TODO Auto-generated catch block
e.printStackTrace();
}
}
// 总投资
if (row.getCell(7) != null) {
HSSFCell cells = row.getCell(7);
// 设置单元格类型
cells.setCellType(CellType.STRING);
if (row.getCell(7).getStringCellValue() != null) {
techResourceTmp
.setTotalInvestment(new BigDecimal(row.getCell(7).getStringCellValue()));
}
}
// 市级拨款
if (row.getCell(8) != null) {
HSSFCell cella = row.getCell(8);
// 设置单元格类型
cella.setCellType(CellType.STRING);
if (row.getCell(8).getStringCellValue() != null) {
techResourceTmp
.setCityAppropriation(new BigDecimal(row.getCell(8).getStringCellValue()));
}
}
// 区市配套
if (row.getCell(9) != null) {
HSSFCell cellb = row.getCell(9);
// 设置单元格类型
cellb.setCellType(CellType.STRING);
if (row.getCell(9).getStringCellValue() != null
&& row.getCell(9).getStringCellValue().trim().length() > 0) {
techResourceTmp.setCountyAppropriation(
new BigDecimal(row.getCell(9).getStringCellValue()));
}
}
// 自筹
if (row.getCell(10) != null) {
HSSFCell cellc = row.getCell(10);
// 设置单元格类型
cellc.setCellType(CellType.STRING);
if (row.getCell(10).getStringCellValue() != null
&& row.getCell(10).getStringCellValue().trim().length() > 0) {
techResourceTmp.setIndependentlyAppropriation(
new BigDecimal(row.getCell(10).getStringCellValue()));
}
}
// 拨款年度
if (row.getCell(11) != null) {
HSSFCell celle = row.getCell(11);
celle.setCellType(CellType.STRING);
techResourceTmp.setAppropriationYear(row.getCell(11).getStringCellValue());
}
// 当年度拨款
if (row.getCell(12) != null) {
HSSFCell celld = row.getCell(12);
// 设置单元格类型
celld.setCellType(CellType.STRING);
if (row.getCell(12).getStringCellValue() != null
&& row.getCell(12).getStringCellValue().trim().length() > 0) {
techResourceTmp.setAppropriationNumber(
new BigDecimal(row.getCell(12).getStringCellValue()));
}
}
// 拨款批次
if (row.getCell(13) != null) {
// 设置单元格类型
HSSFCell celle = row.getCell(13);
celle.setCellType(CellType.STRING);
if (row.getCell(13).getStringCellValue() != null
&& row.getCell(13).getStringCellValue().trim().length() > 0) {
techResourceTmp.setAppropriationBatch(
Integer.valueOf(row.getCell(13).getStringCellValue()));
}
}
// 拨款级
if (row.getCell(14) != null && row.getCell(14).getStringCellValue() != null) {
if (row.getCell(14).getStringCellValue().contains("\n")) {
String[] appropriationLevelArray = row.getCell(14).getStringCellValue().split("\n");
int length = appropriationLevelArray.length;
int count = 0;
for (String str : appropriationLevelArray) {
if (appropriationLevelHashMap.containsKey(str)) {
count++;
}
}
if (length != count) {
techResourceTmp.setAppropriationLevel(row.getCell(5).getStringCellValue());
techResourceTmp.setAppropriationLevelQualified(0);
techResourceTmp.setIsQualified(0);
} else {
String appappropriationLevel = "";
MasterCodeB masterCodeB = new MasterCodeB();
TechResourceAppropriationLevelR techResourceAppropriationLevelR = new TechResourceAppropriationLevelR();
techResourceTmp.setTechResourceAppropriationLevelList(new ArrayList<>());
for (String str : appropriationLevelArray) {
if (appropriationLevelHashMap.containsKey(str)) {
techResourceAppropriationLevelR = new TechResourceAppropriationLevelR();
masterCodeB = appropriationLevelHashMap.get(str);
appappropriationLevel += masterCodeB.getName() + "\n";
techResourceTmp.setAppropriationLevel(appappropriationLevel.substring(0,
appappropriationLevel.length() - 1));
techResourceTmp.setAppropriationLevelQualified(1);
techResourceTmp.setIsQualified(1);
techResourceAppropriationLevelR
.setAppropriationLevel(masterCodeB.getClassb());
techResourceTmp.getTechResourceAppropriationLevelList()
.add(techResourceAppropriationLevelR);
}
// techResourceAppropriationLevelAddList.add(techResourceAppropriationLevelR);
}
}
} else if (row.getCell(14).getStringCellValue().contains(" ")) {
String[] appropriationLevelArray = row.getCell(14).getStringCellValue().split(" ");
int length = appropriationLevelArray.length;
int count = 0;
for (String str : appropriationLevelArray) {
if (appropriationLevelHashMap.containsKey(str)) {
count++;
}
}
if (length != count) {
techResourceTmp.setAppropriationLevel(row.getCell(14).getStringCellValue());
techResourceTmp.setAppropriationLevelQualified(0);
techResourceTmp.setIsQualified(0);
} else {
MasterCodeB masterCodeB = new MasterCodeB();
TechResourceAppropriationLevelR techResourceAppropriationLevelR = new TechResourceAppropriationLevelR();
techResourceTmp.setTechResourceAppropriationLevelList(new ArrayList<>());
String appappropriationLevel = "";
for (String str : appropriationLevelArray) {
if (appropriationLevelHashMap.containsKey(str)) {
techResourceAppropriationLevelR = new TechResourceAppropriationLevelR();
masterCodeB = appropriationLevelHashMap.get(str);
appappropriationLevel += masterCodeB.getName() + "\n";
techResourceTmp.setAppropriationLevel(appappropriationLevel.substring(0,
appappropriationLevel.length() - 1));
techResourceTmp.setAppropriationLevelQualified(1);
techResourceTmp.setIsQualified(1);
techResourceAppropriationLevelR
.setAppropriationLevel(masterCodeB.getClassb());
techResourceTmp.getTechResourceAppropriationLevelList()
.add(techResourceAppropriationLevelR);
}
// techResourceAppropriationLevelAddList.add(techResourceAppropriationLevelR);
}
}
} else {
MasterCodeB masterCodeB = new MasterCodeB();
TechResourceAppropriationLevelR techResourceAppropriationLevelR = new TechResourceAppropriationLevelR();
techResourceTmp.setTechResourceAppropriationLevelList(new ArrayList<>());
if (appropriationLevelHashMap.containsKey(row.getCell(14).getStringCellValue())) {
masterCodeB = appropriationLevelHashMap
.get(row.getCell(14).getStringCellValue());
techResourceTmp.setAppropriationLevelQualified(1);
techResourceTmp.setIsQualified(1);
techResourceTmp.setAppropriationLevel(masterCodeB.getClassb());
techResourceAppropriationLevelR.setAppropriationLevel(masterCodeB.getClassb());
techResourceTmp.getTechResourceAppropriationLevelList()
.add(techResourceAppropriationLevelR);
} else {
techResourceTmp.setAppropriationLevelQualified(0);
techResourceTmp.setIsQualified(0);
techResourceTmp.setAppropriationLevel(row.getCell(14).getStringCellValue());
}
// techResourceAppropriationLevelAddList.add(techResourceAppropriationLevelR);
}
}
// 业务处室
if (row.getCell(15) != null && row.getCell(15).getStringCellValue() != null) {
SysOrgInfo sysOrginfo = new SysOrgInfo();
if (orgNameHashMap.containsKey(row.getCell(15).getStringCellValue())) {
sysOrginfo = orgNameHashMap.get(row.getCell(15).getStringCellValue());
techResourceTmp.setOwnerOrgId(sysOrginfo.getId());
techResourceTmp.setOwnerOrgName(sysOrginfo.getOrgName());
techResourceTmp.setOwnerOrgQualified(1);
techResourceTmp.setIsQualified(1);
} else if (shortNameHashMap.containsKey(row.getCell(15).getStringCellValue())) {
sysOrginfo = shortNameHashMap.get(row.getCell(15).getStringCellValue());
techResourceTmp.setOwnerOrgId(sysOrginfo.getId());
techResourceTmp.setOwnerOrgName(sysOrginfo.getShortName());
techResourceTmp.setOwnerOrgQualified(1);
techResourceTmp.setIsQualified(1);
} else {
techResourceTmp.setUndertakeUnitName(row.getCell(15).getStringCellValue());
techResourceTmp.setOwnerOrgQualified(0);
techResourceTmp.setIsQualified(0);
}
}
// 验收年度
if (row.getCell(16) != null) {
HSSFCell celle = row.getCell(16);
celle.setCellType(CellType.STRING);
techResourceTmp.setAcceptanceYear(row.getCell(16).getStringCellValue());
}
// 验收结论
if (row.getCell(17) != null && row.getCell(17).getStringCellValue() != null) {
techResourceTmp.setAcceptanceResult(row.getCell(17).getStringCellValue());
}
// 二次验收结论
if (row.getCell(18) != null && row.getCell(18).getStringCellValue() != null) {
techResourceTmp.setAcceptanceTwoResult(row.getCell(18).getStringCellValue());
}
// 计划大本备注(人才姓名)
if (row.getCell(19) != null && row.getCell(19).getStringCellValue() != null) {
techResourceTmp.setProjectMemo(row.getCell(19).getStringCellValue());
}
// 修改备注
if (row.getCell(20) != null && row.getCell(20).getStringCellValue() != null) {
techResourceTmp.setEditionMemo(row.getCell(20).getStringCellValue());
}
if (loginResult != null) {
techResourceTmp.setCreateOrgId(loginResult.getUser().getOrgId());
techResourceTmp.setCreateTime(new Timestamp(System.currentTimeMillis()));
techResourceTmp.setCreateUserId(loginResult.getUser().getId());
techResourceTmp.setCreateUserName(loginResult.getUser().getShortName());
techResourceTmp.setUpdateTime(new Timestamp(System.currentTimeMillis()));
techResourceTmp.setUpdateUserName(loginResult.getUser().getUserName());
}
techResourceTmpList.add(techResourceTmp);
} else {
return "项目名称为空!";
}
}
}
workbook.close();
}
}
if (suffix.equals(".xlsx")) {
// 建立Excel对象
XSSFWorkbook workbook = new XSSFWorkbook(file.getInputStream());
// 获取Excel中的sheet数量
int numberOfSheets = workbook.getNumberOfSheets();
// 最后一个sheet放枚举 不进行加载
for (int i = 0; i < numberOfSheets; i++) {
// 获取excel sheet
XSSFSheet sheet = workbook.getSheetAt(i);
// 获取行的数量
int physicalNumberOfRows = sheet.getPhysicalNumberOfRows();
if (physicalNumberOfRows <= 1) {
workbook.close();
return "excel表格异常";
}
// 查询业务处室 承担单位 主要协作单位 放到map 里面
SysOrgInfoQueryParam sysOrgInfoQueryParam = new SysOrgInfoQueryParam();
sysOrgInfoQueryParam.setPid(2);
sysOrgInfoQueryParam.setOrgTypes("2,7");
// 包含shortName简称和orgName只要有一个符合 就正确 需要进行判断
List<SysOrgInfo> orgList = sysOrgInfoMapper.selectQuery(sysOrgInfoQueryParam);
// orgName 的hashMap
HashMap<String, SysOrgInfo> orgNameHashMap = new HashMap<>();
// shortName 的hashMap
HashMap<String, SysOrgInfo> shortNameHashMap = new HashMap<>();
for (SysOrgInfo orgInfo : orgList) {
orgNameHashMap.put(orgInfo.getOrgName(), orgInfo);
shortNameHashMap.put(orgInfo.getShortName(), orgInfo);
}
// 查询拨款级放到map 里面
MasterCodeBQueryParam masterCodeBParam = new MasterCodeBQueryParam();
masterCodeBParam.setClassa("TAL");
masterCodeBParam.setPs(Integer.MAX_VALUE);
List<MasterCodeB> appropriationLevelList = masterCodeBMapper.listQuery(masterCodeBParam);
// 拨款级的map
HashMap<String, MasterCodeB> appropriationLevelHashMap = new HashMap<>();
for (MasterCodeB masterCodeB : appropriationLevelList) {
appropriationLevelHashMap.put(masterCodeB.getName(), masterCodeB);
}
for (int j = 0; j < physicalNumberOfRows; j++) {
// 如果有标题则第一列不进行加载
if (j == 0) {
continue;// 标题行
} else {
// 获取该行的数据信息
XSSFRow row = sheet.getRow(j);
// 需要对每一行的数据进行一下非空处理
// 项目编号不能为空
if (row != null && row.getCell(1) != null && row.getCell(1).getStringCellValue().length() > 0) {
TechResourceTmp techResourceTmp = new TechResourceTmp();
if (row.getCell(1).getStringCellValue() != null) {
techResourceTmp.setProjectNumber(row.getCell(1).getStringCellValue());
}
// 资源类型
techResourceTmp.setResourceType("6");
// 计划类别
if (row.getCell(2) != null && row.getCell(2).getStringCellValue() != null) {
MasterCodeBQueryParam masterCodeBQueryParam = new MasterCodeBQueryParam();
masterCodeBQueryParam.setClassa("TPT");
masterCodeBQueryParam.setName(row.getCell(2).getStringCellValue());
masterCodeBQueryParam.setPs(Integer.MAX_VALUE);
List<MasterCodeB> listQuery = masterCodeBMapper.listQuery(masterCodeBQueryParam);
if (listQuery.size() > 0) {
for (MasterCodeB masterCodeB : listQuery) {
if (masterCodeB.getName().equals(row.getCell(2).getStringCellValue())) {
techResourceTmp.setProjectType(masterCodeB.getClassb());
techResourceTmp.setProjectTypeQualified(1);
techResourceTmp.setIsQualified(1);
} else {
techResourceTmp.setProjectType(row.getCell(2).getStringCellValue());
techResourceTmp.setProjectTypeQualified(0);
techResourceTmp.setIsQualified(0);
}
}
} else {
techResourceTmp.setProjectType(row.getCell(2).getStringCellValue());
techResourceTmp.setProjectTypeQualified(0);
techResourceTmp.setIsQualified(0);
}
}
// 项目名称
if (row.getCell(3) != null && row.getCell(3).getStringCellValue() != null) {
techResourceTmp.setProjectName(row.getCell(3).getStringCellValue());
}
// 承担单位
if (row.getCell(4) != null && row.getCell(4).getStringCellValue() != null) {
// 两种情况 如果导入的数据包含、 要进行切割验证
if (row.getCell(4).getStringCellValue().contains("、")) {
String rowValue = row.getCell(4).getStringCellValue().replaceAll("\r|\n", "");
// 多条的情况
String[] undertakeUnitArray = rowValue.split("、");
int length = undertakeUnitArray.length;
int count = 0;
for (String str : undertakeUnitArray) {
if (orgNameHashMap.containsKey(str) || shortNameHashMap.containsKey(str)) {
count++;
}
}
if (length != count) {
techResourceTmp.setUndertakeUnitName(row.getCell(4).getStringCellValue());
techResourceTmp.setUndertakeUnitQualified(0);
techResourceTmp.setIsQualified(0);
} else {
SysOrgInfo sysOrginfo = new SysOrgInfo();
techResourceTmp.setTechResourceUndertakeList(new ArrayList<>());
String undertakeUnitName = "";
for (String str : undertakeUnitArray) {
TechResourceUndertakeUnitR techResourceUndertakeUnitR = new TechResourceUndertakeUnitR();
if (orgNameHashMap.containsKey(str)) {
sysOrginfo = orgNameHashMap.get(str);
// techResourceTmp.setUndertakeUnitId(sysOrginfo.getId());
undertakeUnitName += sysOrginfo.getOrgName() + "、";
techResourceTmp.setUndertakeUnitName(
undertakeUnitName.substring(0, undertakeUnitName.length() - 1));
techResourceTmp.setUndertakeUnitQualified(1);
techResourceTmp.setIsQualified(1);
techResourceUndertakeUnitR.setUndertakeUnitId(sysOrginfo.getId());
techResourceUndertakeUnitR
.setUndertakeUnitName(sysOrginfo.getOrgName());
techResourceTmp.getTechResourceUndertakeList()
.add(techResourceUndertakeUnitR);
} else if (shortNameHashMap.containsKey(str)) {
sysOrginfo = shortNameHashMap.get(str);
// techResourceTmp.setUndertakeUnitId(sysOrginfo.getId());
undertakeUnitName += sysOrginfo.getShortName() + "、";
techResourceTmp.setUndertakeUnitName(
undertakeUnitName.substring(0, undertakeUnitName.length() - 1));
techResourceTmp.setUndertakeUnitQualified(1);
techResourceTmp.setIsQualified(1);
techResourceUndertakeUnitR.setUndertakeUnitId(sysOrginfo.getId());
techResourceUndertakeUnitR
.setUndertakeUnitName(sysOrginfo.getShortName());
techResourceTmp.getTechResourceUndertakeList()
.add(techResourceUndertakeUnitR);
}
// techResourceUndertakeAddList.add(techResourceUndertakeUnitR);
}
}
} else {
// 如果没有顿号分割,只有一条的情况
SysOrgInfo sysOrginfo = new SysOrgInfo();
techResourceTmp.setTechResourceUndertakeList(new ArrayList<>());
TechResourceUndertakeUnitR techResourceUndertakeUnitR = new TechResourceUndertakeUnitR();
if (orgNameHashMap.containsKey(row.getCell(4).getStringCellValue())) {
sysOrginfo = orgNameHashMap.get(row.getCell(4).getStringCellValue());
// techResourceTmp.setUndertakeUnitId(sysOrginfo.getId());
techResourceTmp.setUndertakeUnitName(sysOrginfo.getOrgName());
techResourceTmp.setUndertakeUnitQualified(1);
techResourceTmp.setIsQualified(1);
techResourceUndertakeUnitR.setUndertakeUnitId(sysOrginfo.getId());
techResourceUndertakeUnitR.setUndertakeUnitName(sysOrginfo.getOrgName());
techResourceTmp.getTechResourceUndertakeList().add(techResourceUndertakeUnitR);
} else if (shortNameHashMap.containsKey(row.getCell(4).getStringCellValue())) {
sysOrginfo = shortNameHashMap.get(row.getCell(4).getStringCellValue());
// techResourceTmp.setUndertakeUnitId(sysOrginfo.getId());
techResourceTmp.setUndertakeUnitName(sysOrginfo.getShortName());
techResourceTmp.setUndertakeUnitQualified(1);
techResourceTmp.setIsQualified(1);
techResourceUndertakeUnitR.setUndertakeUnitId(sysOrginfo.getId());
techResourceUndertakeUnitR.setUndertakeUnitName(sysOrginfo.getShortName());
techResourceTmp.getTechResourceUndertakeList().add(techResourceUndertakeUnitR);
} else {
techResourceTmp.setUndertakeUnitName(row.getCell(4).getStringCellValue());
techResourceTmp.setUndertakeUnitQualified(0);
techResourceTmp.setIsQualified(0);
}
// techResourceUndertakeAddList.add(techResourceUndertakeUnitR);
}
}
// 主要协作单位
if (row.getCell(5) != null && row.getCell(5).getStringCellValue() != null) {
if (row.getCell(5).getStringCellValue().contains("、")) {
String rowValue = row.getCell(5).getStringCellValue().replaceAll("\r|\n", "");
String[] cooperationUnitArray = rowValue.split("、");
int length = cooperationUnitArray.length;
int count = 0;
for (String str : cooperationUnitArray) {
if (orgNameHashMap.containsKey(str) || shortNameHashMap.containsKey(str)) {
count++;
}
}
if (length != count) {
techResourceTmp.setCooperationUnitName(row.getCell(5).getStringCellValue());
techResourceTmp.setCooperationUnitQualified(0);
techResourceTmp.setIsQualified(0);
} else {
SysOrgInfo sysOrginfo = new SysOrgInfo();
String cooperationUnitName = "";
techResourceTmp.setTechResourceCooperationList(new ArrayList<>());
for (String str : cooperationUnitArray) {
TechResourceCooperationUnitR techResourceCooperationUnitR = new TechResourceCooperationUnitR();
if (orgNameHashMap.containsKey(str)) {
sysOrginfo = orgNameHashMap.get(str);
// techResourceTmp.setCooperationUnitId(sysOrginfo.getId());
cooperationUnitName += sysOrginfo.getOrgName() + "、";
techResourceTmp.setCooperationUnitName(cooperationUnitName.substring(0,
cooperationUnitName.length() - 1));
techResourceTmp.setCooperationUnitQualified(1);
techResourceTmp.setIsQualified(1);
techResourceCooperationUnitR.setCooperationUnitId(sysOrginfo.getId());
techResourceCooperationUnitR
.setCooperationUnitName(sysOrginfo.getOrgName());
techResourceTmp.getTechResourceCooperationList()
.add(techResourceCooperationUnitR);
} else if (shortNameHashMap.containsKey(str)) {
sysOrginfo = shortNameHashMap.get(str);
// techResourceTmp.setCooperationUnitId(sysOrginfo.getId());
cooperationUnitName += sysOrginfo.getShortName() + "、";
techResourceTmp.setCooperationUnitName(cooperationUnitName.substring(0,
cooperationUnitName.length() - 1));
techResourceTmp.setCooperationUnitQualified(1);
techResourceTmp.setIsQualified(1);
techResourceCooperationUnitR.setCooperationUnitId(sysOrginfo.getId());
techResourceCooperationUnitR
.setCooperationUnitName(sysOrginfo.getShortName());
techResourceTmp.getTechResourceCooperationList()
.add(techResourceCooperationUnitR);
}
// techResourceCooperationAddList.add(techResourceCooperationUnitR);
}
}
} else {
// 进行模糊匹配修正
// 如果没有顿号分割
SysOrgInfo sysOrginfo = new SysOrgInfo();
techResourceTmp.setTechResourceCooperationList(new ArrayList<>());
TechResourceCooperationUnitR techResourceCooperationUnitR = new TechResourceCooperationUnitR();
if (orgNameHashMap.containsKey(row.getCell(5).getStringCellValue())) {
sysOrginfo = orgNameHashMap.get(row.getCell(5).getStringCellValue());
techResourceTmp.setCooperationUnitId(sysOrginfo.getId());
techResourceTmp.setCooperationUnitName(sysOrginfo.getOrgName());
techResourceTmp.setCooperationUnitQualified(1);
techResourceTmp.setIsQualified(1);
techResourceCooperationUnitR.setCooperationUnitId(sysOrginfo.getId());
techResourceCooperationUnitR.setCooperationUnitName(sysOrginfo.getOrgName());
techResourceTmp.getTechResourceCooperationList()
.add(techResourceCooperationUnitR);
} else if (shortNameHashMap.containsKey(row.getCell(5).getStringCellValue())) {
sysOrginfo = shortNameHashMap.get(row.getCell(5).getStringCellValue());
// techResourceTmp.setCooperationUnitId(sysOrginfo.getId());
techResourceTmp.setCooperationUnitName(sysOrginfo.getShortName());
techResourceTmp.setCooperationUnitQualified(1);
techResourceTmp.setIsQualified(1);
techResourceCooperationUnitR.setCooperationUnitId(sysOrginfo.getId());
techResourceCooperationUnitR.setCooperationUnitName(sysOrginfo.getShortName());
techResourceTmp.getTechResourceCooperationList()
.add(techResourceCooperationUnitR);
} else {
techResourceTmp.setCooperationUnitName(row.getCell(5).getStringCellValue());
techResourceTmp.setCooperationUnitQualified(0);
techResourceTmp.setIsQualified(0);
}
// techResourceCooperationAddList.add(techResourceCooperationUnitR);
}
} else {
techResourceTmp.setCooperationUnitQualified(1);
techResourceTmp.setIsQualified(1);
}
// 起止时间
if (row.getCell(6) != null && row.getCell(6).getStringCellValue() != null) {
String startEndTime = row.getCell(6).getStringCellValue();
String[] newStartEnd = startEndTime.split("-");
String startDate = newStartEnd[0];
String endDate = newStartEnd[1];
try {
techResourceTmp.setStartDate(
new Timestamp(new SimpleDateFormat("yyyy").parse(startDate).getTime()));
techResourceTmp.setEndDate(
new Timestamp(new SimpleDateFormat("yyyy").parse(endDate).getTime()));
} catch (ParseException e) { // TODO Auto-generated catch block
e.printStackTrace();
}
}
// 总投资
if (row.getCell(7) != null) {
XSSFCell cells = row.getCell(7);
// 设置单元格类型
cells.setCellType(CellType.STRING);
if (row.getCell(7).getStringCellValue() != null) {
techResourceTmp
.setTotalInvestment(new BigDecimal(row.getCell(7).getStringCellValue()));
}
}
// 市级拨款
if (row.getCell(8) != null) {
XSSFCell cella = row.getCell(8);
// 设置单元格类型
cella.setCellType(CellType.STRING);
if (row.getCell(8).getStringCellValue() != null) {
techResourceTmp
.setCityAppropriation(new BigDecimal(row.getCell(8).getStringCellValue()));
}
}
// 区市配套
if (row.getCell(9) != null) {
XSSFCell cellb = row.getCell(9);
// 设置单元格类型
cellb.setCellType(CellType.STRING);
if (row.getCell(9).getStringCellValue() != null
&& row.getCell(9).getStringCellValue().trim().length() > 0) {
techResourceTmp.setCountyAppropriation(
new BigDecimal(row.getCell(9).getStringCellValue()));
}
}
// 自筹
if (row.getCell(10) != null) {
XSSFCell cellc = row.getCell(10);
// 设置单元格类型
cellc.setCellType(CellType.STRING);
if (row.getCell(10).getStringCellValue() != null
&& row.getCell(10).getStringCellValue().trim().length() > 0) {
techResourceTmp.setIndependentlyAppropriation(
new BigDecimal(row.getCell(10).getStringCellValue()));
}
}
// 拨款年度
if (row.getCell(11) != null) {
XSSFCell celle = row.getCell(11);
celle.setCellType(CellType.STRING);
techResourceTmp.setAppropriationYear(row.getCell(11).getStringCellValue());
}
// 当年度拨款
if (row.getCell(12) != null) {
XSSFCell celld = row.getCell(12);
// 设置单元格类型
celld.setCellType(CellType.STRING);
if (row.getCell(12).getStringCellValue() != null
&& row.getCell(12).getStringCellValue().trim().length() > 0) {
techResourceTmp.setAppropriationNumber(
new BigDecimal(row.getCell(12).getStringCellValue()));
}
}
// 拨款批次
if (row.getCell(13) != null) {
// 设置单元格类型
XSSFCell celle = row.getCell(13);
celle.setCellType(CellType.STRING);
if (row.getCell(13).getStringCellValue() != null
&& row.getCell(13).getStringCellValue().trim().length() > 0) {
techResourceTmp.setAppropriationBatch(
Integer.valueOf(row.getCell(13).getStringCellValue()));
}
}
// 拨款级
if (row.getCell(14) != null && row.getCell(14).getStringCellValue() != null) {
if (row.getCell(14).getStringCellValue().contains("\n")) {
String[] appropriationLevelArray = row.getCell(14).getStringCellValue().split("\n");
int length = appropriationLevelArray.length;
int count = 0;
for (String str : appropriationLevelArray) {
if (appropriationLevelHashMap.containsKey(str)) {
count++;
}
}
if (length != count) {
techResourceTmp.setAppropriationLevel(row.getCell(14).getStringCellValue());
techResourceTmp.setAppropriationLevelQualified(0);
techResourceTmp.setIsQualified(0);
} else {
MasterCodeB masterCodeB = new MasterCodeB();
TechResourceAppropriationLevelR techResourceAppropriationLevelR = new TechResourceAppropriationLevelR();
techResourceTmp.setTechResourceAppropriationLevelList(new ArrayList<>());
String appappropriationLevel = "";
for (String str : appropriationLevelArray) {
if (appropriationLevelHashMap.containsKey(str)) {
techResourceAppropriationLevelR = new TechResourceAppropriationLevelR();
masterCodeB = appropriationLevelHashMap.get(str);
appappropriationLevel += masterCodeB.getName() + "\n";
techResourceTmp.setAppropriationLevel(appappropriationLevel.substring(0,
appappropriationLevel.length() - 1));
techResourceTmp.setAppropriationLevelQualified(1);
techResourceTmp.setIsQualified(1);
techResourceAppropriationLevelR
.setAppropriationLevel(masterCodeB.getClassb());
techResourceTmp.getTechResourceAppropriationLevelList()
.add(techResourceAppropriationLevelR);
}
techResourceAppropriationLevelAddList.add(techResourceAppropriationLevelR);
}
}
} else if (row.getCell(14).getStringCellValue().contains(" ")) {
String[] appropriationLevelArray = row.getCell(14).getStringCellValue().split(" ");
int length = appropriationLevelArray.length;
int count = 0;
for (String str : appropriationLevelArray) {
if (appropriationLevelHashMap.containsKey(str)) {
count++;
}
}
if (length != count) {
techResourceTmp.setAppropriationLevel(row.getCell(14).getStringCellValue());
techResourceTmp.setAppropriationLevelQualified(0);
techResourceTmp.setIsQualified(0);
} else {
MasterCodeB masterCodeB = new MasterCodeB();
TechResourceAppropriationLevelR techResourceAppropriationLevelR = new TechResourceAppropriationLevelR();
techResourceTmp.setTechResourceAppropriationLevelList(new ArrayList<>());
String appappropriationLevel = "";
for (String str : appropriationLevelArray) {
if (appropriationLevelHashMap.containsKey(str)) {
techResourceAppropriationLevelR = new TechResourceAppropriationLevelR();
masterCodeB = appropriationLevelHashMap.get(str);
appappropriationLevel += masterCodeB.getName() + "\n";
techResourceTmp.setAppropriationLevel(appappropriationLevel.substring(0,
appappropriationLevel.length() - 1));
techResourceTmp.setAppropriationLevelQualified(1);
techResourceTmp.setIsQualified(1);
techResourceAppropriationLevelR
.setAppropriationLevel(masterCodeB.getClassb());
techResourceTmp.getTechResourceAppropriationLevelList()
.add(techResourceAppropriationLevelR);
}
techResourceAppropriationLevelAddList.add(techResourceAppropriationLevelR);
}
}
} else {
MasterCodeB masterCodeB = new MasterCodeB();
TechResourceAppropriationLevelR techResourceAppropriationLevelR = new TechResourceAppropriationLevelR();
techResourceTmp.setTechResourceAppropriationLevelList(new ArrayList<>());
if (appropriationLevelHashMap.containsKey(row.getCell(14).getStringCellValue())) {
masterCodeB = appropriationLevelHashMap
.get(row.getCell(14).getStringCellValue());
techResourceTmp.setAppropriationLevelQualified(1);
techResourceTmp.setIsQualified(1);
techResourceTmp.setAppropriationLevel(masterCodeB.getClassb());
techResourceAppropriationLevelR.setAppropriationLevel(masterCodeB.getClassb());
techResourceTmp.getTechResourceAppropriationLevelList()
.add(techResourceAppropriationLevelR);
} else {
techResourceTmp.setAppropriationLevelQualified(0);
techResourceTmp.setIsQualified(0);
techResourceTmp.setAppropriationLevel(row.getCell(14).getStringCellValue());
}
techResourceAppropriationLevelAddList.add(techResourceAppropriationLevelR);
}
}
// 业务处室
if (row.getCell(15) != null && row.getCell(15).getStringCellValue() != null) {
SysOrgInfo sysOrginfo = new SysOrgInfo();
if (orgNameHashMap.containsKey(row.getCell(15).getStringCellValue())) {
sysOrginfo = orgNameHashMap.get(row.getCell(15).getStringCellValue());
techResourceTmp.setOwnerOrgId(sysOrginfo.getId());
techResourceTmp.setOwnerOrgName(sysOrginfo.getOrgName());
techResourceTmp.setOwnerOrgQualified(1);
techResourceTmp.setIsQualified(1);
} else if (shortNameHashMap.containsKey(row.getCell(15).getStringCellValue())) {
sysOrginfo = shortNameHashMap.get(row.getCell(15).getStringCellValue());
techResourceTmp.setOwnerOrgId(sysOrginfo.getId());
techResourceTmp.setOwnerOrgName(sysOrginfo.getShortName());
techResourceTmp.setOwnerOrgQualified(1);
techResourceTmp.setIsQualified(1);
} else {
techResourceTmp.setUndertakeUnitName(row.getCell(15).getStringCellValue());
techResourceTmp.setOwnerOrgQualified(0);
techResourceTmp.setIsQualified(0);
}
}
// 验收年度
if (row.getCell(16) != null) {
XSSFCell celle = row.getCell(16);
celle.setCellType(CellType.STRING);
techResourceTmp.setAcceptanceYear(row.getCell(16).getStringCellValue());
}
// 验收结论
if (row.getCell(17) != null && row.getCell(17).getStringCellValue() != null) {
techResourceTmp.setAcceptanceResult(row.getCell(17).getStringCellValue());
}
// 二次验收结论
if (row.getCell(18) != null && row.getCell(18).getStringCellValue() != null) {
techResourceTmp.setAcceptanceTwoResult(row.getCell(18).getStringCellValue());
}
// 计划大本备注(人才姓名)
if (row.getCell(19) != null && row.getCell(19).getStringCellValue() != null) {
techResourceTmp.setProjectMemo(row.getCell(19).getStringCellValue());
}
// 修改备注
if (row.getCell(20) != null && row.getCell(20).getStringCellValue() != null) {
techResourceTmp.setEditionMemo(row.getCell(20).getStringCellValue());
}
if (loginResult != null) {
techResourceTmp.setCreateOrgId(loginResult.getUser().getOrgId());
techResourceTmp.setCreateTime(new Timestamp(System.currentTimeMillis()));
techResourceTmp.setCreateUserId(loginResult.getUser().getId());
techResourceTmp.setCreateUserName(loginResult.getUser().getShortName());
techResourceTmp.setUpdateTime(new Timestamp(System.currentTimeMillis()));
techResourceTmp.setUpdateUserName(loginResult.getUser().getUserName());
}
// 临时表的list
techResourceTmpList.add(techResourceTmp);
}
}
}
workbook.close();
}
}
// techResourceAppropriationLevelList.add(techResourceAppropriationLevelR);
List<TechResourceTmp> techResourceTmpListNew = new ArrayList<>();
List<TechResourceTmp> listQuery = new ArrayList<>();
if (!techResourceTmpList.isEmpty()) {
for (TechResourceTmp techResourceTmp : techResourceTmpList) {
TechResource techResource = new TechResource();
if (techResourceTmp.getProjectTypeQualified().equals(1)
&& techResourceTmp.getUndertakeUnitQualified().equals(1)
&& techResourceTmp.getCooperationUnitQualified().equals(1)
&& techResourceTmp.getAppropriationLevelQualified().equals(1)
&& techResourceTmp.getOwnerOrgQualified().equals(1)) {
if (techResourceTmp.getIsQualified().toString().equals("1")) {
BeanUtils.copyProperties(techResourceTmp, techResource);
techResourceList.add(techResource);
} else {
techResourceTmpListNew.add(techResourceTmp);
}
} else {
techResourceTmpListNew.add(techResourceTmp);
}
}
}
Page<TechResource> page = new Page<>();
TechResourceTmpQueryParam techResourcTmpeQueryParam = new TechResourceTmpQueryParam();
PageInfo pageInfo = new PageInfo();
/*
* pageInfo.setCurrentPage(queryParam.getPn());
* pageInfo.setPageSize(queryParam.getPs());
*/
if (!techResourceList.isEmpty()) {
// 插入正式表
int count = techResourceMapper.insertBatch(techResourceList);
// 判断并循环相关list是否为空 循环正式表list,判断值是否相等 相等把主键id放进去
for (TechResource techResource : techResourceList) {
if (techResource.getTechResourceUndertakeList() != null
&& techResource.getTechResourceUndertakeList().size() > 0) {
String name = "";
for (TechResourceUndertakeUnitR techResourceUndertakeR : techResource
.getTechResourceUndertakeList()) {
techResourceUndertakeR.setTechResourceId(techResource.getId());
techResourceUndertakeAddList.add(techResourceUndertakeR);
name += techResourceUndertakeR.getUndertakeUnitName() + "、";
}
techResource.setUndertakeUnitName(name.substring(0, name.length() - 1));
}
if (techResource.getTechResourceCooperationList() != null
&& techResource.getTechResourceCooperationList().size() > 0) {
String name = "";
for (TechResourceCooperationUnitR techResourceCooperationR : techResource
.getTechResourceCooperationList()) {
techResourceCooperationR.setTechResourceId(techResource.getId());
techResourceCooperationAddList.add(techResourceCooperationR);
name += techResourceCooperationR.getCooperationUnitName() + "、";
}
techResource.setCooperationUnitName(name.substring(0, name.length() - 1));
}
if (techResource.getTechResourceAppropriationLevelList() != null
&& techResource.getTechResourceAppropriationLevelList().size() > 0) {
String name = "";
for (TechResourceAppropriationLevelR techResourceAppropriationLevelR : techResource
.getTechResourceAppropriationLevelList()) {
techResourceAppropriationLevelR.setTechResourceId(techResource.getId());
techResourceAppropriationLevelAddList.add(techResourceAppropriationLevelR);
name += techResourceAppropriationLevelR.getAppropriationLevel() + "\r|\n";
}
techResource.setAppropriationLevelName(name.substring(0, name.length() - 1));
}
// techResourceMapper.update(techResource);
}
if (techResourceUndertakeAddList != null && techResourceUndertakeAddList.size() > 0) {
List<TechResourceUndertakeUnitR> list = techResourceUndertakeAddList.stream().distinct().collect(Collectors.toList());
techResourceUndertakeUnitRMapper.insertBatch(list);
}
if (techResourceCooperationAddList != null && techResourceCooperationAddList.size() > 0) {
List<TechResourceCooperationUnitR> list = techResourceCooperationAddList.stream().distinct().collect(Collectors.toList());
techResourceCooperationUnitRMapper.insertBatch(list);
}
if (techResourceAppropriationLevelAddList != null && techResourceAppropriationLevelAddList.size() > 0) {
List<TechResourceAppropriationLevelR> list = techResourceAppropriationLevelAddList.stream().distinct().collect(Collectors.toList());
techResourceAppropriationLevelRMapper.insertBatch(list );
}
if (!techResourceTmpListNew.isEmpty()) {
// 插入临时表
techResourceTmpMapper.insertBatch(techResourceTmpListNew);
// TechResourceTmpQueryParam techResourcTmpeQueryParam = new
// TechResourceTmpQueryParam();
techResourcTmpeQueryParam.setPs(Integer.MAX_VALUE);
listQuery = techResourceTmpMapper.listQuery(techResourcTmpeQueryParam);
}
if (count > 0) {
return listQuery;
}
} else {
// 插入临时表
techResourceTmpMapper.insertBatch(techResourceTmpListNew);
// TechResourceTmpQueryParam techResourcTmpeQueryParam = new
// TechResourceTmpQueryParam();
techResourcTmpeQueryParam.setPs(Integer.MAX_VALUE);
listQuery = techResourceTmpMapper.listQuery(techResourcTmpeQueryParam);
return listQuery;
}
return listQuery;
/*
* if (!techResourceList.isEmpty()) { int count =
* techResourceMapper.insertBatch(techResourceList); if (count > 0) { return
* "导入成功"; } } else { techResourceTmpMapper.insertBatch(techResourceTmpList);
* return "文件为空"; }
*
* return "导入成功";
*/
}