EntityPmScheduleViewAction.java

/*
 *        @ Copyright 2001 FA Software;
 *        All right reserved. No part of this program may be reproduced or
 *        transmitted in any form or by any means, electronic or
 *        mechanical, including photocopying, recording, or by any
 *        information storage or retrieval system without written
 *        permission from FA Software, except for inclusion of brief
 *        quotations in a review.
 */
package com.mycim.webapp.actions.equipmentpm;

import com.fa.sesa.exception.Assert;
import com.fa.sesa.exception.Errors;
import com.fa.sesa.threadlocal.LocalContext;
import com.mycim.valueobject.MessageIdList;
import com.mycim.valueobject.ObjectList;
import com.mycim.valueobject.consts.SessionNames;
import com.mycim.valueobject.ems.Entity;
import com.mycim.webapp.actions.EmsSetupAction;
import com.mycim.webapp.forms.EntityPmScheduleViewForm;
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;

/**
 * EQP PM Schedule List
 *
 * @author pinyan.song
 * @version 6.0.0
 * @date 2019-12-4 18:32
 **/
public class EntityPmScheduleViewAction extends EmsSetupAction {

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

    public ActionForward ok(ActionMapping mapping, EntityPmScheduleViewForm theform, HttpServletRequest request,
                            HttpServletResponse response) {
        Entity entity = new Entity(theform.getEquipmentId(),
                                   getNamedSpace(ObjectList.ENTITY_KEY, LocalContext.getFacilityRrn()),
                                   ObjectList.ENTITY_KEY);
        entity = (Entity) getInstance(entity);

        Assert.isFalse(entity == null || entity.getInstanceRrn() <= 0,
                       Errors.create().key(MessageIdList.EQUIPMENT_MISSING_ID).content("设备号为空或不存在").build());

        request.setAttribute(SessionNames.ENTITY_KEY, entity);
        return (mapping.findForward("month"));
    }

}