From 29166bc750623bea12a367ba7c527facdb582235 Mon Sep 17 00:00:00 2001
From: 李宇 <986321569@qq.com>
Date: 星期二, 13 七月 2021 17:12:28 +0800
Subject: [PATCH] 修改转移试剂,生成领用单
---
src/main/java/com/nanometer/smartlab/service/OpeApplyServiceImpl.java | 104 +++++++++++++++++++++++++++++++++++----------------
1 files changed, 71 insertions(+), 33 deletions(-)
diff --git a/src/main/java/com/nanometer/smartlab/service/OpeApplyServiceImpl.java b/src/main/java/com/nanometer/smartlab/service/OpeApplyServiceImpl.java
index dd9d9fc..fed8f2c 100644
--- a/src/main/java/com/nanometer/smartlab/service/OpeApplyServiceImpl.java
+++ b/src/main/java/com/nanometer/smartlab/service/OpeApplyServiceImpl.java
@@ -15,6 +15,7 @@
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
@@ -35,10 +36,10 @@
import java.io.InputStream;
import java.math.BigDecimal;
import java.sql.Timestamp;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.text.DecimalFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.*;
/**
* Created by johnny on 17/12/12.
@@ -747,9 +748,8 @@
@Override
@Transactional
- public void importApply(FileUploadEvent event,SysUser user) {
+ public void importApply(FileUploadEvent event,SysUser user) throws IOException {
- try {
UploadedFile file = event.getFile();
InputStream is = file.getInputstream();
@@ -772,39 +772,77 @@
List<String> valuesList = new ArrayList<String>();
row = sheet.getRow(i);
- totalCells = row.getPhysicalNumberOfCells();
-
- for (int t = 0; t < totalCells; t++) {
+ totalCells = row.getLastCellNum();
+ //第10列是课题,其他都不能为空
+ for (int index = 0; index < totalCells; index++) {
String cellInfo = "";
-
- if (row.getCell(t) != null) {
- if (row.getCell(t).getCellTypeEnum().toString().equals("NUMERIC")) {
- cellInfo = String.valueOf(row.getCell(t).getNumericCellValue());
+ if (row.getCell(index) != null) {
+ if (row.getCell(index).getCellType() == CellType.BLANK && index != 9) {
+ throw new BusinessException(ExceptionEnumCode.PARAM_NULL, "第" + ++i + "行:除了课题组都不能为空");
+ }
+ if (row.getCell(index).getCellType() == CellType.NUMERIC) {
+ DecimalFormat df = new DecimalFormat("#######"); //格式化number String字符
+ cellInfo = df.format(row.getCell(index).getNumericCellValue());
}else{
- cellInfo = row.getCell(t).getStringCellValue();
+ cellInfo = row.getCell(index).getStringCellValue();
}
}
valuesList.add(cellInfo);
}
Map<String,Object> detail = new HashMap<>();
- detail.put("name", valuesList.get(0));
- detail.put("cas", valuesList.get(1));
- detail.put("product_sn", valuesList.get(2));
- detail.put("main_metering", valuesList.get(3));
- detail.put("reagent_unit", valuesList.get(4));
- detail.put("reagent_character", valuesList.get(5));
- detail.put("product_home", valuesList.get(6));
+ detail.put("product_sn", valuesList.get(0));
+ detail.put("name", valuesList.get(1));
+ detail.put("reagent_format", valuesList.get(2));
+ detail.put("packing", valuesList.get(3));
+ detail.put("cas", valuesList.get(4));
+ detail.put("product_home", valuesList.get(5));
+ detail.put("reagent_type", valuesList.get(6));
SysReagent sysReagent = sysReagentService.getReagentByDetail(detail);
if (sysReagent == null) throw new BusinessException(ExceptionEnumCode.PARAM_NO_EXIST, i+"行:试剂不存在或者有多条,导入失败");
//申购数量
Integer num = new Double(valuesList.get(7)).intValue();
if (num < 1) throw new BusinessException(ExceptionEnumCode.PARAM_NO_EXIST, i+"行:试剂申购数量不合法,导入失败");
- //课题组
- String objective = valuesList.get(8);
+
+ //申购人姓名
+ String applyUserName = valuesList.get(8);
+ SysUser applyUser = sysUserService.getUserByName(applyUserName);
+ if (applyUser == null) throw new BusinessException(ExceptionEnumCode.PARAM_NO_EXIST, i+"行:申购人不存在或者申购人姓名存在重复,导入失败");
+ //课题组名称
+ String objective = valuesList.get(9);
+
+ String format = "yyyy-MM-dd";
+ SimpleDateFormat dateFormat = new SimpleDateFormat(format);
+ Date applyDate = null;
+ int cellnum = 10;
+ CellType type = row.getCell(cellnum).getCellType();
+ Object value = row.getCell(cellnum);
+ if (null == value || StringUtils.isBlank(value.toString())) {
+ throw new BusinessException(ExceptionEnumCode.PARAM_NO_EXIST, i+"行,申购日期不能为空");
+ } else {
+ if (type.equals(CellType.NUMERIC)) {
+ try {
+ applyDate = row.getCell(cellnum).getDateCellValue();
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new BusinessException(ExceptionEnumCode.PARAM_NO_EXIST, i+"行,申购日期解析错误,请检查是否有无效字符");
+ }
+ } else if (type.equals(CellType.STRING)) {
+ String cellInfo = row.getCell(10).getStringCellValue();
+ try {
+ applyDate = dateFormat.parse(cellInfo);
+ } catch (ParseException e) {
+ e.printStackTrace();
+ throw new BusinessException(ExceptionEnumCode.PARAM_NO_EXIST, i+"行:申购日期不合法,应如2016-10-09,导入失败");
+ }
+ } else {
+ throw new BusinessException(ExceptionEnumCode.PARAM_NO_EXIST, i+"行:申购日期解析错误,请检查是否有无效字符");
+ }
+ }
+
//选择的审批人姓名
- String approveUserName = valuesList.get(9);
+ String approveUserName = valuesList.get(11);
//根据姓名获取用户信息的id
SysUser approveUser = sysUserService.getUserByName(approveUserName);
if (approveUser == null) throw new BusinessException(ExceptionEnumCode.PARAM_NO_EXIST, i+"行:审批人不存在或者审批人姓名存在重复,导入失败");
@@ -816,6 +854,10 @@
opeApply.setApplyCode(sysSequenceService.getApplyCode());
//设置试剂id
opeApply.setReagent(sysReagent);
+ assert applyDate != null;
+ Timestamp applyTime = new Timestamp(applyDate.getTime());
+ opeApply.setCreateTime(applyTime);
+ opeApply.setUpdateTime(applyTime);
//价格
opeApply.setApplyPrice(sysReagent.getPrice());
//申购数量
@@ -832,18 +874,14 @@
}
if (adds.size() > 0) {
- opeApplyDao.insertOpeApplyList(adds);
+ opeApplyDao.insertList(adds);
}
+ }
-
-
-
-
- } catch (IOException e) {
- e.printStackTrace();
- }
-
+ @Override
+ public OpeApplyReserve getOpeApplyReserveListByNameForRowData(String rowKey) {
+ return opeApplyDao.getOpeApplyReserveListByNameForRowData(rowKey);
}
}
--
Gitblit v1.9.2