stuts批量导入


	//下载 货代填写价格  模板
	public void doDownloadHuoDaiPrice(){
		try {
			hyMonthInquiryList = new ArrayList<HyMonthInquiryFO>();
			//设置货代编码
			queryData.setGoodsAgentCode(super.getUserContext().getOrgaId());
			DboList hyMonthInquirysBj = getHyMonthInquiryBO().getHyMonthInquirysNotBj(super.getQueryContext());
			for(int i=0; i<hyMonthInquirysBj.size(); i++){
				HyMonthInquiry tmpHyMonthInquiry = (HyMonthInquiry) hyMonthInquirysBj.get(i);
				tmpHyMonthInquiry.setLocalLanguage(super.getLanguage());
				HyMonthInquiryFO tmpHyMonthInquiryFo = new HyMonthInquiryFO();

				BeanUtils.copy(tmpHyMonthInquiry, tmpHyMonthInquiryFo);
				codeToName(tmpHyMonthInquiryFo,tmpHyMonthInquiry);

			}
			String EXL = "HY_MONTH_INQUIRY_PRICE";
			ExcelGeneralOperate ex = new ExcelGeneralOperate();
			String fileName = ex.doGeneralExportValue(hyMonthInquirysBj, EXL);

			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			String ly_time = sdf.format(new java.util.Date());
			String filePath = SystemConfigs.GENDMS_FILE_PATH + "/" + SystemConfigs.TEMP_FILE_DIR + "/" + fileName;
			fileName = "未报价的月度询盘信息(" + ly_time + ").xls";

			OdDownloadLog downLog = this.getOdDownloadLogBO().createLog(fileName, fileName, filePath,"",fileName);
			super.outSuccess(downLog.getId());
		}catch (Exception e) {
			e.printStackTrace();
			super.outFailure(e.getMessage());
		}
	}


//导入报价信息
	public void importHyMonthInquiryInfo(){
		UserTransaction transaction = TransactionFactory.getInstance().createTransaction();
		try{
			transaction.begin();
			String path = SystemConfigs.GENDMS_FILE_PATH + File.separatorChar + SystemConfigs.TEMP_FILE_DIR + File.separatorChar + UUIDHexGenerator.getInstance().generate()+".xls";
			FileHelper.copyFile(file, path);
				List<ImportExcelErrorFO> errorList = this.getHyMonthInquiryBO().importHyMonthInquiryInfo(path,super.getQueryContext());
			if(errorList.size()>0){
				transaction.rollback();
				//返回错误提示
				StringBuffer s = new StringBuffer(JSONArray.fromObject(errorList).toString());
				outJsonStringForUpload("{success:false, data:" + s.toString() + "}");
			}else{
				transaction.commit();
				super.outSuccessHtml("成功");
			}
		} catch (Exception e) {
			transaction.rollback();
			e.printStackTrace();
			LogHome.getLog().error(e.getMessage(),e);
			super.outFailureForUploadReplace(e.getMessage());
		}
	}




//导入月度询盘报价
	public List<ImportExcelErrorFO> importHyMonthInquiryInfo(String path, IBoQueryContext queryContext) throws Exception {
		DboList list = new DboList();
		InputStream inStream = null;
		long userId = StringHelper.getUserSession().getId();
		List<ImportExcelErrorFO> errorList = new ArrayList<ImportExcelErrorFO>();
		try {
			inStream = new FileInputStream(path);
			HSSFWorkbook wb = new HSSFWorkbook(inStream);
			HSSFSheet sheet = wb.getSheetAt(0);
			errorList = this.validationHyMonthInquiryItem(sheet, list,queryContext);
		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		} finally {
			if (inStream != null) {
				inStream.close();
			}
		}

		if (errorList.size()==0){
			//如果没有错误批量导入
			try {
				for (int i = 0, count = list.size(); i < count; i++) {
					HyMonthInquiryItem item = (HyMonthInquiryItem) list.get(i);
					super.composeCreator(item, userId);
					String id = item.getId();
					DboList hyShipTypeList = this.getHyMonthInquiryDAO().queryShipType(id);
					for (int b=0;b<hyShipTypeList.size();b++ ) {
						GenericDO shipType =  hyShipTypeList.get(b);
						if (shipType.getAttrString("SHIP_TYPE").equals("集装箱")) {
							item.setBillingUnit("/柜");
						} else {
							item.setBillingUnit("/立方米");
						}
					}
					super.updateObject(item);
				}
			} catch (Exception e) {
				e.printStackTrace();
				//数据库执行异常
				ImportExcelErrorFO error = new ImportExcelErrorFO();
				error.setErrorMsg(e.getMessage());
				errorList.add(error);
			}

		}
		return errorList;
	}
	private List<ImportExcelErrorFO> validationHyMonthInquiryItem(HSSFSheet sheet, DboList list,IBoQueryContext queryContext) throws Exception {
		HSSFRow row = null;
		int rowNum = ExcelUtil.countRows(sheet);
		int currentRow = 1;
		List<ImportExcelErrorFO> errorList = new ArrayList<ImportExcelErrorFO>();
		String temp = "";
		HSSFRow testRow = sheet.getRow(currentRow);
		if (testRow != null) {
		} else {
			ImportExcelErrorFO error = new ImportExcelErrorFO();
			error.setErrorMsg("模板中无数据");
			errorList.add(error);
			return errorList;
		}

		for (int i = currentRow; i <= rowNum; i++, currentRow++) {
			row = sheet.getRow(currentRow);
			if (row == null) {
				continue;
			}
			HyMonthInquiryItem hyMonthInquiryItem = new HyMonthInquiryItem();
			StringBuffer errorString = new StringBuffer();
			ImportExcelErrorFO excelError = new ImportExcelErrorFO();
			excelError.setRowNum("第" + (currentRow + 1) + "行");

			temp = StringTools.getString(ExcelUtil.getCellValue(row.getCell(0), i, (	short) 0) + "", "");
			String hyGoodsAgentNametemp = StringTools.getString(ExcelUtil.getCellValue(row.getCell(1), i, (	short) 1) + "", "");
			String batchNo = temp;
			if (!"".equals(temp)) {
				//根据批次号 货代名称判断是否已经报价
				DboList hyMonthInquiryList = this.getHyMonthInquiryDAO().queryhyMonthInquiryById(queryContext, temp, hyGoodsAgentNametemp);
					GenericDO tmpHyMonthInquiry =  hyMonthInquiryList.get(0);
					if (tmpHyMonthInquiry.getAttrString("QUOTATION")!= null) {
						errorString.append("导入失败![报价信息已存在]");
				}
			}
			temp = StringTools.getString(ExcelUtil.getCellValue(row.getCell(5), i, (short) 5) + "", "");
			if (!"".equals(temp)) {
				try {
					hyMonthInquiryItem.setVoyageMin(temp);
				} catch (Exception e) {
					errorString.append("第" + (6) + "列 最小航程不能为空 ;");
				}
			}

			temp = StringTools.getString(ExcelUtil.getCellValue(row.getCell(6), i, (short) 6) + "", "");
			if (!"".equals(temp)) {
				hyMonthInquiryItem.setVoyageMax(temp);
			} else {
				errorString.append("第" + (7) + "列 最大航程不能为空  ;");
			}


			temp = StringTools.getString(ExcelUtil.getCellValue(row.getCell(7), i, (short) 7) + "", "");
			if (!"".equals(temp) && !temp.equals("0") && Double.valueOf(temp)>0) {
				hyMonthInquiryItem.setQuotation(Double.valueOf(temp));
			} else {
				errorString.append("第" + (8) + "列 货代报价不能为空或者为0,批次号["+batchNo+"];");
			}

			temp = StringTools.getString(ExcelUtil.getCellValue(row.getCell(8), i, (short) 8) + "", "");
			if (!"".equals(temp)) {
				hyMonthInquiryItem.setShippingSample(temp);
			}

			temp = StringTools.getString(ExcelUtil.getCellValue(row.getCell(9), i, (short) 9) + "", "");
			if (!"".equals(temp)) {
				hyMonthInquiryItem.setHdNote(temp);
			}

			temp = StringTools.getString(ExcelUtil.getCellValue(row.getCell(10), i, (short) 10) + "", "");
			if (!"".equals(temp)) {
				hyMonthInquiryItem.setId(temp);
			}


			if(errorString.length() != 0){
				excelError.setErrorMsg(errorString.toString());
				errorList.add(excelError);
			}
			else{
				list.add(hyMonthInquiryItem);
			}
		}

		return errorList;
	}
在使用MyEclipse进行Spring Struts2 Hibernate开发过程中,可以按照以下步骤进行前后台的添加。 首先,对于后台开发,需要配置Hibernate的相关环境。可以在MyEclipse中创建一个新的Java项目,然后在项目中添加相关的Hibernate库文件,包括Hibernate的核心库、连接池库和数据库驱动库。接着,在项目中创建一个Hibernate配置文件,配置数据库连接等相关信息。然后,创建实体类对应数据库表中的字段,并使用注解或XML文件进行映射。接下来,在DAO层中创建与数据库交互的方法,并使用Hibernate相关API进行数据库操作。 对于前台开发,可以使用Spring MVC和Struts2来进行。首先,需要在项目中添加相关的Spring和Struts2的库文件。然后,在Spring配置文件(如applicationContext.xml)中配置Spring MVC的相关信息,如视图解析器、控制器等。接着,在项目中创建Controller类,使用注解或XML文件进行映射URL与方法的关系,并在方法中实现相应的业务逻辑。同时,可以创建对应的JSP页面,用于展示数据或与用户交互。 在整个开发过程中,可以使用MyEclipse提供的快速开发工具来简化代码编写和调试,如自动生成实体类、自动生成Controller类等。此外,MyEclipse还提供了集成的调试工具,可以方便地进行代码调试和错误排查。 总结起来,使用MyEclipse进行Spring Struts2 Hibernate开发的前后台教学,需要进行环境配置、实体类的定义与映射、配置文件的编写、业务逻辑的实现以及页面的设计与交互等步骤。通过合理利用MyEclipse的功能,可以提高开发效率和代码质量,实现前后台数据的交互和展示。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值