看看自己写的,诶,赞一个!!
两相比较,虽然还是个菜鸟,不得不给自己赞一个!由于结构比较乱,业务处理层就省了
/**
?* @description 处理上传的采购申请文件(Excel文件)
?* @author?....
?* @date 2010-12-29
?*/
public class OrdersBatchUploadAction extends Action {
?
?private static Logger logger = Logger.getLogger(OrdersBatchUploadAction.class);
?
?/**
? * 采购订单上传处理的步骤:1)获取上传的Excel文件,并将文件保存为服务器的临时文件?
? * ?????? 2)解析临时文件中的数据?
??*??????? 3)数据完整性校验
? *??????? 3)将解析的数据保存到数据库
? * ?????? 4)删除临时文件
? *????????5)显示结果数据列表
? */
?public ActionForward execute(ActionMapping mapping,?ActionForm form,
????HttpServletRequest request, HttpServletResponse response) {
??String forward = "prompt";
??
??HttpSession session = request.getSession();
??User loginUser = (User)session.getAttribute("loginUser");??
??String mode = request.getParameter("mode");? //获取将要执行的操作标志。mode='init'为初始化
??if (mode!=null && mode.equals("init")) {
???return mapping.findForward("init");
??}????????
??
??OrdersBatchUploadForm ordersUploadForm = (OrdersBatchUploadForm)form;
??FormFile file = ordersUploadForm.getFile();
??try {?????? ?
???if (file == null) {
????throw new ExpFoundException("上传文件发生异常!上传的文件不存在。");???
???}
???//暂时保存上传文件的文件夹路径(为部署的工程目录下的temp文件夹)
???String directory = servlet.getServletContext().getRealPath("/temp");?
???String fileName = loginUser.getUserName() + "_" + file.getFileName();? //设置暂存文件的文件名
???String filefullpath = directory + "/" + fileName;
???
???//缓存上传的采购申请数据文件
???saveTempFile(file, directory, fileName);
???//解析及检验上传的Excel文件
???ArrayList<PurchasingAppModel> purAppList =
???????????? ?ParsingImportedDataService.validatePurchasingAppData(filefullpath, loginUser);?
???//校验采购申请数据的完整性,并生成采购订单
???ArrayList<PurchaseOrder> orderList = ParsingImportedDataService.
????????????? validateIntegrityOfPurchasingAppData(purAppList, loginUser);
???//持久化采购申请数据(即备份批量导入的采购申请数据到数据库)
???PurchasingAppPO.batchPersistency(purAppList);
???
???//持久化采购订单数据,并获取采购订单凭证号列表
???ArrayList<String> ebelnList =
?????????????? ?PurchaseOrderPO.batchPersistency(orderList);???
???//删除采购申请导入的临时文件
???deleteTempFile(filefullpath);
???
???//检查采购申请数据是否都通过了完整性校验,如果存在没通过校验的,给用户提示出来。
???boolean isAllPassed = isAllPassedIntegralityValidation(purAppList);
???if (!isAllPassed) {
????String tip = "采购申请数据中存在未通过完整性校验的记录,请转到完整性校验结果处进行处理!";
????request.setAttribute("tip", tip);
???}
???//将生成的采购订单的凭证号集合传到结果显示Action
???String ebelnListTag = loginUser.getDepartment() + "ebelns";
???session.setAttribute(ebelnListTag, ebelnList);
???forward = "listresult";
??} catch (ExpFoundException efe) {
???request.setAttribute("prompt", "采购申请导入失败!" + efe.getMessage());
??}?????
??return mapping.findForward(forward);
?}