/** * 生管PH设定维护页-保存 * @author caohong * @date 2016年11月16日14:55:51 */ public class SaveOrUpdateModifyPHSetupAction extends ERPProxyAction { private void bulidSaveTableBean(TableBean tableBean, String key, String value, String rowBeanKey, HashMap<String, String> hmKeyToDBColumnName, String parentKey, String parentValue) { RowBean rowBean = tableBean.get(rowBeanKey); if (rowBean == null) { rowBean = new RowBean(rowBeanKey); rowBean.addCellBean(new CellBean(hmKeyToDBColumnName.get(parentKey), parentValue)); tableBean.addRowBean(rowBean); } rowBean.addCellBean(new CellBean(hmKeyToDBColumnName.get(key), value)); } @Override protected ActionForward doExecute(FormBean parameterFB, ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { FormBean userInfoFormBean = (FormBean) request.getSession().getAttribute(TriangleDefinition.SESSION_ATTRIBUTE_KEY_USER_INFO); String userId = userInfoFormBean.getCellBeanValue(TriangleDefinition.COLUMN_NAME_CN_ID); DataBean dataBean = new DataBean();// 用于更新数据库的DataBean TableBean pmcPHSetupTB = new TableBean("TN_PMC_PH_SETUP");// 用于更新数据库 FormBean updatePrarmeterFormBean = new FormBean("parameterFB");// 用于更新数据库 dataBean.addFormBean(updatePrarmeterFormBean); dataBean.addTableBean(pmcPHSetupTB); updatePrarmeterFormBean.addCellBean(new CellBean("userId", userId)); HashMap<String, String> hmKeyToDBColumnName = new HashMap<String, String>();// 用户替换View的Key到DBColumnName // PMCPHSetupTB hmKeyToDBColumnName.put("primaryId", "CN_ID"); hmKeyToDBColumnName.put("articleId", "CR_ARTICLE_ID"); hmKeyToDBColumnName.put("sectionId", "CR_SECTION_ID"); hmKeyToDBColumnName.put("leadTimeDay", "CN_LEADTIME"); hmKeyToDBColumnName.put("PH", "CN_PMC_PH_QTY"); String articleId = parameterFB.getCellBeanValue("articleNumber"); // 解析参数,构建用于更新数据库的TableBean for (int i = 0; i < parameterFB.size(); i++) { CellBean cellBean = parameterFB.get(i); String key = cellBean.getKey(); String value = cellBean.getValue(); // 处理PMCPHSetupTB // "sectionName_"+sectionId // PMCPHSetupTB的RowBeankey为sectionId if (key.startsWith("leadTimeDay_")) { String rowBeanKey = key.split("_")[1]; this.bulidSaveTableBean(pmcPHSetupTB, "leadTimeDay", value, rowBeanKey, hmKeyToDBColumnName, "articleId", articleId); } else if (key.startsWith("PH_")) { String rowBeanKey = key.split("_")[1]; this.bulidSaveTableBean(pmcPHSetupTB, "PH", value, rowBeanKey, hmKeyToDBColumnName, "articleId", articleId); } else if (key.startsWith("sectionId_")) { String rowBeanKey = key.split("_")[1]; this.bulidSaveTableBean(pmcPHSetupTB, "sectionId", value, rowBeanKey, hmKeyToDBColumnName, "articleId", articleId); } else if (key.startsWith("primaryId_")) { String rowBeanKey = key.split("_")[1]; this.bulidSaveTableBean(pmcPHSetupTB, "primaryId", value, rowBeanKey, hmKeyToDBColumnName, "articleId", articleId); } } String errorMsg = ""; try { //保存数据 FormBean resultFormBean = this.getERPServiceDelegation().getMasterProductionScheduleService().saveOrUpdateModifyPHSetup(dataBean); errorMsg = resultFormBean.getCellBeanValue("errorMsg"); } catch (Exception e) { e.printStackTrace(); errorMsg = e.getMessage(); } finally { AlertMessagePOJO alertMessagePOJO = new AlertMessagePOJO(errorMsg, AlertMessagePOJO.TYPE_ERROR); if (StringUtils.isBlank(errorMsg)) { alertMessagePOJO = new AlertMessagePOJO(TriangleUIHelper.getMessageResources(request, TriangleUIHelper.getMulKeyPrefixAlert() + "saveSuccess"), AlertMessagePOJO.TYPE_INFO); } request.getSession().setAttribute(TriangleDefinition.SESSION_ATTRIBUTE_KEY_ALERT_MESSAGE, alertMessagePOJO); } return TriangleUIHelper.getForward("success", mapping, "articleId=" + articleId); } }
第二种写法
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, ""); } }
公司用-->页面表单提交用的key是拼接的,保存时action的写法,struts1
最新推荐文章于 2022-03-25 13:53:09 发布