📄 uploadexcleaction.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.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.action.DynaActionForm;
import org.apache.struts.upload.FormFile;
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.service.ICustomerService;
import com.iplan.portal.order.service.IOrderService;
import com.iplan.portal.order.service.IUploadExcleService;
import com.iplan.portal.order.service.IWarehouseService;
/**
* http://www.hao-se.cn
*
* @author ws
*/
public class UploadExcleAction extends BaseAction {
private IUploadExcleService uploadExcleService;
private IOrderService orderService;
private IAreaService areaService;
private ICustomerService customerService;
IWarehouseService warehouseService;
public IUploadExcleService getUploadExcleService() {
return uploadExcleService;
}
public void setUploadExcleService(IUploadExcleService uploadExcleService) {
this.uploadExcleService = uploadExcleService;
}
public IAreaService getAreaService() {
return areaService;
}
public void setAreaService(IAreaService areaService) {
this.areaService = areaService;
}
public IOrderService getOrderService() {
return orderService;
}
public void setOrderService(IOrderService orderService) {
this.orderService = orderService;
}
public ICustomerService getCustomerService() {
return customerService;
}
public void setCustomerService(ICustomerService customerService) {
this.customerService = customerService;
}
public IWarehouseService getWarehouseService() {
return warehouseService;
}
public void setWarehouseService(IWarehouseService warehouseService) {
this.warehouseService = warehouseService;
}
public ActionForward list(ActionMapping actionMapping,
ActionForm actionForm, HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) throws Exception {
setAreaInfo(httpServletRequest);
return actionMapping.findForward("success");
}
public ActionForward submit(ActionMapping actionMapping,
ActionForm actionForm, HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) throws Exception {
DynaActionForm daf = (DynaActionForm) actionForm;
FormFile file = (FormFile) daf.get("theFile");
String areaId = (String) daf.get("areaId");
String fileName = file.getFileName();
setAreaInfo(httpServletRequest);
String userId = httpServletRequest.getSession().getAttribute(
Constants.CURRENT_USER_GUID).toString();
ActionMessages messages = new ActionMessages();
ActionMessage message = null;
if (fileName == null || "".equals(fileName.trim())) {
message = new ActionMessage("errors.nofilePath");
} else {
int index = fileName.lastIndexOf(".");
if (index >= 0) {
String signStr = fileName.substring(index + 1, fileName
.length());
if (!"xls".equals(signStr)) {
message = new ActionMessage("errors.fileFormat");
} else {
// 上载Excle文件
boolean bl = this.getUploadExcleService().uploadExcle(
file.getInputStream(), userId, areaId,
this.getOrderService(), this.getCustomerService(),
this.getWarehouseService());
if (bl) {
message = new ActionMessage("success.uploadExcle");
} else {
message = new ActionMessage("errors.uploadExcle");
}
}
} else {
message = new ActionMessage("errors.fileFormat");
}
}
messages.add(ActionMessages.GLOBAL_MESSAGE, message);
saveMessages(httpServletRequest, messages);
return actionMapping.findForward("success");
}
private void setAreaInfo(HttpServletRequest httpServletRequest) {
String userId = httpServletRequest.getSession().getAttribute(
Constants.CURRENT_USER_GUID).toString();
List list = this.getAreaService().getUsedAreaListByUserId(userId);
List areaIdList = new ArrayList();
List areaNameList = new ArrayList();
for (int i = 0; i < list.size(); i++) {
BasicDynaBean bean = (BasicDynaBean) list.get(i);
areaIdList.add(bean.get("guid"));
areaNameList.add(bean.get("areaname"));
}
httpServletRequest.setAttribute("areaIdList", areaIdList);
httpServletRequest.setAttribute("areaNameList", areaNameList);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -