⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 excleaction.java

📁 SSH示范
💻 JAVA
字号:
package com.iplan.portal.order.action;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BasicDynaBean;
import org.apache.commons.beanutils.BasicDynaClass;
import org.apache.commons.beanutils.DynaBean;
import org.apache.commons.beanutils.DynaClass;
import org.apache.commons.beanutils.DynaProperty;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.DynaActionForm;

import com.iplan.portal.admin.pojo.Area;
import com.iplan.portal.admin.service.IAreaService;
import com.iplan.portal.framework.Constants;
import com.iplan.portal.framework.base.struts.BaseAction;
import com.iplan.portal.order.pojo.OrderInfo;
import com.iplan.portal.order.service.IExcleService;
import com.iplan.portal.order.service.IOrderService;

/**
 * http://www.hao-se.cn
 * 
 * @author ws
 */
public class ExcleAction extends BaseAction {
	IOrderService orderService;

	IExcleService excleService;

	IAreaService areaService;

	public IOrderService getOrderService() {
		return orderService;
	}

	public void setOrderService(IOrderService orderService) {
		this.orderService = orderService;
	}

	public IExcleService getExcleService() {
		return excleService;
	}

	public void setExcleService(IExcleService excleService) {
		this.excleService = excleService;
	}

	public IAreaService getAreaService() {
		return areaService;
	}

	public void setAreaService(IAreaService areaService) {
		this.areaService = areaService;
	}

	public ActionForward select(ActionMapping actionMapping,
			ActionForm actionForm, HttpServletRequest httpServletRequest,
			HttpServletResponse httpServletResponse) throws Exception {

		List list = this.getAreaService().getUsedAreaListByUserId(
				(httpServletRequest.getSession()
						.getAttribute(Constants.CURRENT_USER_GUID)).toString());
		httpServletRequest.setAttribute("items", list);

		String sign = httpServletRequest.getParameter("sign");
		httpServletRequest.setAttribute("sign", sign);

		return actionMapping.findForward("AreaSelectList");
	}

	public ActionForward list(ActionMapping actionMapping,
			ActionForm actionForm, HttpServletRequest httpServletRequest,
			HttpServletResponse httpServletResponse) throws Exception {
		DynaActionForm daf = (DynaActionForm) actionForm;
		OrderInfo orderInfo = (OrderInfo) daf.get("orderInfo");
		String areaId = orderInfo.getAreaid();

		if (areaId == null || "".equals(areaId)) {
			areaId = (String) httpServletRequest.getSession().getAttribute(
					"areaid");
		} else {
			httpServletRequest.getSession().setAttribute("areaid", areaId);
		}

		httpServletRequest.setAttribute("result", "false");

		// 处理结果信息
		setOkInfo(httpServletRequest);

		Area area = this.getAreaService().getAreaById(areaId);
		httpServletRequest.setAttribute("areaName", area.getAreaName());

		return actionMapping.findForward("ExcleList");
	}

	public ActionForward search(ActionMapping actionMapping,
			ActionForm actionForm, HttpServletRequest httpServletRequest,
			HttpServletResponse httpServletResponse) throws Exception {
		String okStr = "";

		DynaActionForm daf = (DynaActionForm) actionForm;
		OrderInfo orderInfo = (OrderInfo) daf.get("orderInfo");

		String areaId = (String) httpServletRequest.getSession().getAttribute(
				"areaid");

		String userId = httpServletRequest.getSession().getAttribute(
				Constants.CURRENT_USER_GUID).toString();
		// 订单月份
		String month = orderInfo.getMonth();
		// 订单处理结果
		String ok = orderInfo.getOk();
		// 订单号
		String orderNo = orderInfo.getOrderNo().trim();
		// 订单日期
		String orderDateStr = orderInfo.getOrderDateStr();
		String orderDateStr2 = orderInfo.getOrderDateStr2();
		// 客户名称
		String customerName = orderInfo.getCustomerName().trim();
		// 打印装箱单时间
		String printingDateStr = orderInfo.getPrintingDateStr();
		String printingDateStr2 = orderInfo.getPrintingDateStr2();

		Area area = this.getAreaService().getAreaById(areaId);
		httpServletRequest.setAttribute("areaName", area.getAreaName());

		List list = this.getOrderService().getOrderInfoList(areaId, userId,
				orderNo, orderDateStr, orderDateStr2, customerName,
				printingDateStr, printingDateStr2, month, ok);
		if (!list.isEmpty()) {
			httpServletRequest.setAttribute("result", "true");
			httpServletRequest.setAttribute("count", String
					.valueOf(list.size()));
			httpServletRequest.setAttribute("areaName", area.getAreaName());

			if (ok != null && "OK".equals(ok)) {
				okStr = "处理完毕的订单";
			} else if (ok != null && "NO".equals(ok)) {
				okStr = "正在处理中的订单";
			} else {
				okStr = "所有订单";
			}

			httpServletRequest.setAttribute("month", month);
			httpServletRequest.setAttribute("ok", okStr);
			httpServletRequest.setAttribute("orderNo", orderNo);
			httpServletRequest.setAttribute("orderDateStr", orderDateStr);
			httpServletRequest.setAttribute("orderDateStr2", orderDateStr2);
			httpServletRequest.setAttribute("customerName", customerName);
			httpServletRequest.setAttribute("printingDateStr", printingDateStr);
			httpServletRequest.setAttribute("printingDateStr2",
					printingDateStr2);
		}

		// 处理结果信息
		setOkInfo(httpServletRequest);

		daf.set("orderInfo", orderInfo);

		return actionMapping.findForward("ExcleList");
	}

	public ActionForward upload(ActionMapping actionMapping,
			ActionForm actionForm, HttpServletRequest httpServletRequest,
			HttpServletResponse httpServletResponse) throws Exception {

		return actionMapping.findForward("Excle");
	}

	public ActionForward excle(ActionMapping actionMapping,
			ActionForm actionForm, HttpServletRequest httpServletRequest,
			HttpServletResponse httpServletResponse) throws Exception {
		String okStr = "";
		int result;
		List excleOKList = new ArrayList();
		List excleNOList = new ArrayList();

		DynaActionForm daf = (DynaActionForm) actionForm;
		OrderInfo orderInfo = (OrderInfo) daf.get("orderInfo");

		String areaId = (String) httpServletRequest.getSession().getAttribute(
				"areaid");

		String userId = httpServletRequest.getSession().getAttribute(
				Constants.CURRENT_USER_GUID).toString();

		Area area = this.getAreaService().getAreaById(areaId);

		// 订单月份
		String month = orderInfo.getMonth();
		// 订单处理结果
		String ok = orderInfo.getOk();
		// 订单号
		String orderNo = orderInfo.getOrderNo().trim();
		// 订单日期
		String orderDateStr = orderInfo.getOrderDateStr();
		String orderDateStr2 = orderInfo.getOrderDateStr2();
		// 客户名称
		String customerName = orderInfo.getCustomerName().trim();
		// 打印装箱单时间
		String printingDateStr = orderInfo.getPrintingDateStr();
		String printingDateStr2 = orderInfo.getPrintingDateStr2();

		String realPath = this.getServlet().getServletContext().getRealPath("");
		// 源文件
		String sourceFile = realPath + Constants.SOURCE_FILE_PATH
				+ Constants.SOURCE_FILE_NAME;
		// 目标文件
		String aimFile = realPath + Constants.AIM_FILE_PATH
				+ area.getAreaName() + Constants.AIM_FILE_NAME;

		if ("".equals(ok)) {
			excleOKList = this.getOrderService().getExcleInfoList(areaId,
					userId, orderNo, orderDateStr, orderDateStr2, customerName,
					printingDateStr, printingDateStr2, month, "OK");
			excleNOList = this.getOrderService().getExcleInfoList(areaId,
					userId, orderNo, orderDateStr, orderDateStr2, customerName,
					printingDateStr, printingDateStr2, month, "NO");
		} else if ("OK".equals(ok)) {
			excleOKList = this.getOrderService().getExcleInfoList(areaId,
					userId, orderNo, orderDateStr, orderDateStr2, customerName,
					printingDateStr, printingDateStr2, month, "OK");
		} else if ("NO".equals(ok)) {
			excleNOList = this.getOrderService().getExcleInfoList(areaId,
					userId, orderNo, orderDateStr, orderDateStr2, customerName,
					printingDateStr, printingDateStr2, month, "NO");
		}

		List okExcle = setOrderInfo(excleOKList);
		List noExcle = setOrderInfo(excleNOList);

		String fileAreaName = area.getAreaName() + Constants.AIM_FILE_NAME;
		fileAreaName = fileAreaName.substring(0, fileAreaName.length() - 4);

		// 做成Excle
		result = this.getExcleService().makeExcle(okExcle, noExcle, sourceFile,
				aimFile, fileAreaName);

		if (result >= 0) {
			httpServletRequest.setAttribute("aimFile", aimFile);
			httpServletRequest.setAttribute("aimFileView", area.getAreaName()
					+ Constants.AIM_FILE_NAME);

			if (month != null && !"".equals(month)) {
				httpServletRequest.setAttribute("month", month);
			} else {
				httpServletRequest.setAttribute("month", "所有月份");
			}

			if (ok != null && "OK".equals(ok)) {
				okStr = "处理完毕的订单";
			} else if (ok != null && "NO".equals(ok)) {
				okStr = "正在处理中的订单";
			} else {
				okStr = "所有订单";
			}
			httpServletRequest.setAttribute("orderType", okStr);
			httpServletRequest.setAttribute("okSize", String.valueOf(okExcle
					.size()));
			httpServletRequest.setAttribute("noSize", String.valueOf(noExcle
					.size()));
			httpServletRequest.setAttribute("areaName", area.getAreaName());
			if (result == 1) {
				httpServletRequest.setAttribute("result", "处理成功");
				httpServletRequest.setAttribute("flag", "true");
			} else if (result == 0) {
				httpServletRequest.setAttribute("result", "处理失败,请联系管理员");
				httpServletRequest.setAttribute("flag", "false");
			}

		} else {
			httpServletRequest.setAttribute("aimFile", "");
			httpServletRequest.setAttribute("aimFileView", "");
			httpServletRequest.setAttribute("month", "");
			httpServletRequest.setAttribute("orderType", "");
			httpServletRequest.setAttribute("okSize", "");
			httpServletRequest.setAttribute("noSize", "");
			httpServletRequest.setAttribute("areaName", area.getAreaName());
			httpServletRequest.setAttribute("result", "处理的数据为0件,请查询后再操作");
			httpServletRequest.setAttribute("flag", "false");
		}

		return actionMapping.findForward("Excle");
	}

	private List setOrderInfo(List list) {
		List viewList = new ArrayList();

		try {
			String result = "";

			DynaProperty[] property = {
					new DynaProperty("guid", Class.forName("java.lang.String")),
					new DynaProperty("orderno", Class
							.forName("java.lang.String")),
					new DynaProperty("orderdate", Class
							.forName("java.lang.String")),
					new DynaProperty("customername", Class
							.forName("java.lang.String")),
					new DynaProperty("warehouseid", Class
							.forName("java.lang.String")),
					new DynaProperty("printingdate", Class
							.forName("java.lang.String")),
					new DynaProperty("timenum", Class
							.forName("java.lang.String")),
					new DynaProperty("inputdate", Class
							.forName("java.lang.String")),
					new DynaProperty("effectiveinfo", Class
							.forName("java.lang.String")),
					new DynaProperty("shorting", Class
							.forName("java.lang.String")),
					new DynaProperty("amount", Class
							.forName("java.lang.String")),
					new DynaProperty("track", Class.forName("java.lang.String")),
					new DynaProperty("salespersons", Class
							.forName("java.lang.String")),
					new DynaProperty("ok", Class.forName("java.lang.String")),
					new DynaProperty("handmade", Class
							.forName("java.lang.String")),
					new DynaProperty("handmadeflg", Class
							.forName("java.lang.String")),
					new DynaProperty("remark", Class
							.forName("java.lang.String")) };
			DynaClass dynaClass = new BasicDynaClass("bean", null, property);
			DynaBean bean;

			BasicDynaBean beanTemp;
			for (int i = 0; i < list.size(); i++) {
				beanTemp = (BasicDynaBean) list.get(i);

				bean = dynaClass.newInstance();
				bean.set("guid", beanTemp.get("guid"));
				bean.set("orderno", beanTemp.get("orderno"));
				bean.set("orderdate", convertDateToString(beanTemp
						.get("orderdate")));
				bean.set("customername", beanTemp.get("customername"));
				bean.set("warehouseid", beanTemp.get("warehouseid"));
				bean.set("printingdate", convertDateToString(beanTemp
						.get("printingdate")));
				bean.set("timenum", "");
				bean.set("inputdate", convertDateToString(beanTemp
						.get("inputdate")));
				bean.set("effectiveinfo", beanTemp.get("effectiveinfo"));
				bean.set("shorting", beanTemp.get("shorting"));
				bean.set("amount", beanTemp.get("amount"));
				bean.set("track", beanTemp.get("track"));
				bean.set("salespersons", beanTemp.get("salespersons"));
				bean.set("handmade", beanTemp.get("handmade"));
				bean.set("handmadeflg", beanTemp.get("handmadeflg"));
				bean.set("remark", beanTemp.get("remark"));

				result = (String) beanTemp.get("ok");
				if ("OK".equals(result)) {
					bean.set("ok", result);
				} else {
					bean.set("ok", "");
				}

				viewList.add(bean);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

		return viewList;
	}

	private String convertDateToString(Object object) {

		String time = "";

		if (object != null && !"".equals(object)) {
			time = object.toString().substring(0, 10);
		}

		return time;
	}

	private void setOkInfo(HttpServletRequest httpServletRequest) {
		// 处理结果信息
		List okNameList = new ArrayList();
		List okIdList = new ArrayList();
		okNameList.add("");
		okNameList.add("处理完毕");
		okNameList.add("正在处理中");
		okIdList.add("");
		okIdList.add("OK");
		okIdList.add("NO");
		httpServletRequest.setAttribute("okNameList", okNameList);
		httpServletRequest.setAttribute("okIdList", okIdList);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -