PartsSaveAction.java

package com.mycim.webapp.actions.material;

import com.fa.sesa.threadlocal.LocalContext;
import com.mycim.framework.utils.lang.StringUtils;
import com.mycim.valueobject.ObjectList;
import com.mycim.valueobject.inv.MaterialDO;
import com.mycim.webapp.Constants;
import com.mycim.webapp.forms.MaterialInfoForm;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

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

/**
 * @Author: yibing.liu
 * @Date: 2021/8/27 17:42
 */
public class PartsSaveAction extends MaterialSaveAction {

    @Override
    public ActionForward init(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                              HttpServletResponse response) throws Exception {
        return super.init(mapping, form, request, response);
    }

    @Override
    public ActionForward create(ActionMapping mapping, MaterialInfoForm theform) throws Exception {
        validateMaterial(theform, 0L);

        MaterialDO material = new MaterialDO(theform.getInstanceId(),
                                             this.getNamedSpace(ObjectList.ITEM_KEY, LocalContext.getFacilityRrn()), ObjectList.ITEM_KEY);
        PropertyUtils.copyProperties(material, theform);
        material.setItemExtendNumber(StringUtils.isBlank(material.getItemExtendNumber()) ? null : material.getItemExtendNumber());
        material.setTransPerformedby(LocalContext.getUserId());
        material.setObjectType(ObjectList.ITEM_PART_KEY);
        asmService.insertMaterial(material);

        theform.setTransId(Constants.MODIFY_KEY);
        return mapping.findForward(Constants.MODIFY_KEY);
    }

    @Override
    public ActionForward modify(ActionMapping mapping, MaterialInfoForm theform) throws Exception {
        MaterialDO material = asmService.getMaterial(LocalContext.getFacilityRrn(), theform.getInstanceId());

        validateMaterial(theform, material.getInstanceRrn());

        PropertyUtils.copyProperties(material, theform);
        material.setItemExtendNumber(StringUtils.isBlank(material.getItemExtendNumber()) ? null : material.getItemExtendNumber());
        material.setTransPerformedby(LocalContext.getUserId());
        material.setObjectType(ObjectList.ITEM_PART_KEY);
        asmService.updateMaterial(material);

        theform.setTransId(Constants.MODIFY_KEY);
        return mapping.findForward(Constants.MODIFY_KEY);
    }

    @Override
    public ActionForward delete(ActionMapping mapping, MaterialInfoForm theform) {
        return super.delete(mapping, theform);
    }


    @Override
    public ActionForward cancel(ActionMapping mapping, ActionForm form, HttpServletRequest request,
                                HttpServletResponse response) {
        return super.cancel(mapping, form, request, response);
    }

}