公司用-->页面表单提交用的key是拼接的,保存时action的写法,struts1

/**
 * 生管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, "");
	}
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值