第二种写法
package gts.erp.action.masterProductionSchedule; import gts.erp.action.base.ERPProxyAction; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.lang.StringUtils; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import com.oletech.triangle.component.CellBean; import com.oletech.triangle.component.DataBean; import com.oletech.triangle.component.FormBean; import com.oletech.triangle.component.RowBean; import com.oletech.triangle.component.TableBean; import com.oletech.triangle.pojo.AlertMessagePOJO; import com.oletech.triangle.utils.TriangleDefinition; import com.oletech.triangle.utils.TriangleUIHelper; /** * 保存行事历 * @author WANGCHAO * @date 2016年7月21日 */ public class SaveOrUpdateProductionCalendarAction extends ERPProxyAction { @Override protected ActionForward doExecute(FormBean parameterFB, ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { DataBean dataBean = new DataBean(); long time=System.currentTimeMillis(); //获取用户信息 FormBean userInfoFormBean = (FormBean) request.getSession().getAttribute(TriangleDefinition.SESSION_ATTRIBUTE_KEY_USER_INFO); String userId = userInfoFormBean.getCellBeanValue(TriangleDefinition.COLUMN_NAME_CN_ID); String pageName="oletech.triangle.multilanguage.toolbar.productionCalendar"; String factory=parameterFB.getCellBeanValue("factory"); String department=parameterFB.getCellBeanValue("department"); FormBean formBean = new FormBean("paramFormBean"); formBean.addCellBean(new CellBean("userId", userId)); formBean.addCellBean(new CellBean("pageName", pageName)); dataBean.addFormBean(formBean); TableBean tbProductionCalendar = new TableBean("TN_PRODUCTION_CALENDAR"); for (int i = 0; i < parameterFB.size(); i++) { CellBean cellBean = parameterFB.get(i); String cellBeanKey = cellBean.getKey(); String cellBeanValue = cellBean.getValue(); if (cellBeanKey.contains("_") && cellBeanKey.split("_").length == 2) { String rowBeanKey = cellBeanKey.split("_")[1]; RowBean rowBean = tbProductionCalendar.get(rowBeanKey); if (rowBean == null) { rowBean = new RowBean(rowBeanKey); rowBean.addCellBean(new CellBean("CR_COMPANY_ID", factory)); rowBean.addCellBean(new CellBean("CR_DEPARTMENT_ID", department)); rowBean.addCellBean(new CellBean("CR_CREATE_USER_ID", userId)); rowBean.addCellBean(new CellBean("CN_CREATE_DATETIME", ""+time)); rowBean.addCellBean(new CellBean("CR_MODIFY_USER_ID", userId)); rowBean.addCellBean(new CellBean("CN_MODIFY_DATETIME", ""+time)); rowBean.addCellBean(new CellBean("CR_IS_WORKDAY", TriangleDefinition.NO)); tbProductionCalendar.addRowBean(rowBean); } if (cellBeanKey.startsWith("productionCalendarId_")) { if (StringUtils.isNotBlank(cellBeanValue)) { rowBean.setDbTableDataOperationId(TriangleDefinition.DATABASE_TABLE_DATA_OPERATION_UPDATE); rowBean.addCellBean(new CellBean(TriangleDefinition.COLUMN_NAME_CN_ID, cellBeanValue)); } else { rowBean.setDbTableDataOperationId(TriangleDefinition.DATABASE_TABLE_DATA_OPERATION_INSERT); } } else if (cellBeanKey.startsWith("date_")) { rowBean.addCellBean(new CellBean("CN_DATE", cellBeanValue)); } else if (cellBeanKey.startsWith("isWorkDay_")) { if("on".equals(cellBeanValue)){ rowBean.setCellBeanValue("CR_IS_WORKDAY", TriangleDefinition.YES); } } else if (cellBeanKey.startsWith("remark_")) { rowBean.addCellBean(new CellBean("CN_REMARK", cellBeanValue)); } else if (cellBeanKey.startsWith("manHour_")) { rowBean.addCellBean(new CellBean("CN_WORK_HOURS", cellBeanValue, TriangleDefinition.CLASS_ATTRIBUTE_DB_TYPE_LONG)); } else if (cellBeanKey.startsWith("targetQty_")) { rowBean.addCellBean(new CellBean("CN_TARGET_QTY", cellBeanValue, TriangleDefinition.CLASS_ATTRIBUTE_DB_TYPE_LONG)); } } } dataBean.addTableBean(tbProductionCalendar); FormBean returnInfoFormBean = this.getERPServiceDelegation().getMasterProductionScheduleService().saveOrUpdateProductionCalendar(dataBean); String errorMsg = returnInfoFormBean.getCellBeanValue("errorMsg"); AlertMessagePOJO alertMessagePOJO = new AlertMessagePOJO(TriangleUIHelper.getMessageResources(request, errorMsg), AlertMessagePOJO.TYPE_ERROR); if (StringUtils.isBlank(errorMsg)) { alertMessagePOJO = new AlertMessagePOJO(TriangleUIHelper.getMessageResources(request, "oletech.triangle.multilanguage.alert.saveSuccess"), AlertMessagePOJO.TYPE_INFO); } request.getSession().setAttribute(TriangleDefinition.SESSION_ATTRIBUTE_KEY_ALERT_MESSAGE, alertMessagePOJO); return TriangleUIHelper.getForward("success", mapping, ""); } }