| | |
| | | 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; |
| | |
| | | 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.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * Created by johnny on 17/12/12. |
| | |
| | | |
| | | @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(); |
| | |
| | | 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(index) != null) { |
| | | if (row.getCell(index).getCellTypeEnum() == CellType.BLANK && index != 9) { |
| | | throw new BusinessException(ExceptionEnumCode.PARAM_NULL, "第" + ++i + "行:除了课题组都不能为空"); |
| | | } |
| | | |
| | | if (row.getCell(t) != null) { |
| | | if (row.getCell(t).getCellTypeEnum().toString().equals("NUMERIC")) { |
| | | cellInfo = String.valueOf(row.getCell(t).getNumericCellValue()); |
| | | if (row.getCell(index).getCellTypeEnum() == CellType.NUMERIC) { |
| | | cellInfo = String.valueOf(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 applyDateStr = valuesList.get(10); |
| | | String format = "yyyy-MM-dd"; |
| | | SimpleDateFormat dateFormat = new SimpleDateFormat(format); |
| | | Date applyDate = null; |
| | | try { |
| | | applyDate = dateFormat.parse(applyDateStr); |
| | | } catch (ParseException e) { |
| | | e.printStackTrace(); |
| | | throw new BusinessException(ExceptionEnumCode.PARAM_NO_EXIST, i+"行:申购日期不合法,应如2016-10-09,导入失败"); |
| | | } |
| | | //选择的审批人姓名 |
| | | 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+"行:审批人不存在或者审批人姓名存在重复,导入失败"); |
| | |
| | | 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()); |
| | | //申购数量 |
| | |
| | | } |
| | | |
| | | if (adds.size() > 0) { |
| | | opeApplyDao.insertOpeApplyList(adds); |
| | | opeApplyDao.insertList(adds); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | } |
| | | |