ResistPortalAction.java

package com.mycim.webapp.actions.resist;

import com.fa.sesa.exception.Assert;
import com.fa.sesa.exception.Errors;
import com.fa.sesa.exception.SystemIllegalArgumentException;
import com.fa.sesa.i18n.I18nUtils;
import com.fa.sesa.threadlocal.LocalContext;
import com.mycim.framework.jdbc.Page;
import com.mycim.framework.utils.beans.BeanUtils;
import com.mycim.framework.utils.lang.BooleanUtils;
import com.mycim.framework.utils.lang.StringUtils;
import com.mycim.framework.utils.lang.collections.MapUtils;
import com.mycim.framework.utils.lang.math.NumberUtils;
import com.mycim.framework.utils.lang.time.DateUtils;
import com.mycim.valueobject.MessageIdList;
import com.mycim.valueobject.ObjectList;
import com.mycim.valueobject.ems.Resist;
import com.mycim.valueobject.ems.ResistEnum;
import com.mycim.valueobject.ems.ResistEqptMapping;
import com.mycim.valueobject.ems.ResistMapping;
import com.mycim.webapp.WebUtils;
import com.mycim.webapp.actions.ResistSetupAction;
import com.mycim.webapp.forms.ResistForm;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.beanutils.converters.DateConverter;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import javax.servlet.http.HttpServletRequest;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @author yanbing.chen
 * @version 6.0.0
 * @date 2019/10/29
 **/
public class ResistPortalAction extends ResistSetupAction {

    private static final int VENDOR_BARCODEDE_DEFAULT_LENGTH = 27;

    private static final int VENDOR_BARCODEDE_LENGTH = 29;

    private static final int RESIST_NO_START_POSITION = 7;

    private static final int RESIST_NO_SPECIAL_START_POSITION = 5;

    private static final int RESIST_NO_SPECIAL_END_POSITION = 11;

    private static final int VALID_DATE_START_POSITION = 15;

    private static final int VALID_DATE_END_POSITION = 21;

    private static final int VALID_SPECIAL_DATE_START_POSITION = 14;

    private static final int VALID_SPECIAL_DATE_END_POSITION = 19;

    private static final int VALID_SPECIAL_DAY_AND_MONTH_POSITION = 4;

    private static final String VALID_DATE_FORMAT = "yyMMdd";

    private static final String RESIST_NO_DEFAULT_SUFFIX = "00";

    private static final int MONTH_AND_DAY_TEN = 10;

    private static final int VALID_BATCHNO_START = 19;


    public ActionForward initOption(HttpServletRequest request, ActionMapping mapping) {
        long facilityRrn = LocalContext.getFacilityRrn();
        String[] types = new String[]{"RESIST_STATUS"};
        registerOptionType(facilityRrn, Arrays.asList(types), request);
        return mapping.findForward("resist");
    }

    public Map queryResist(Map argMap) {
        Page resistMappingPage = new Page(MapUtils.getInteger(argMap, "page"), MapUtils.getInteger(argMap, "limit"));
        resistMappingPage = resistService.qryResistByPage(resistMappingPage, argMap);
        Map pageJson = new HashMap();
        pageJson.put("totalItems", resistMappingPage.getTotalItems() + "");
        pageJson.put("items", resistMappingPage.getResults());
        return pageJson;
    }

    public Map getResistInfoByVendorBarcode(Resist resist) throws Exception {
        String vendorBarcode = resist.getVendorBarcode();

        Assert.isTrue(StringUtils.isNotBlank(vendorBarcode) &&
                              (vendorBarcode.length() == VENDOR_BARCODEDE_DEFAULT_LENGTH ||
                                      vendorBarcode.length() == VENDOR_BARCODEDE_LENGTH),
                      Errors.create().key(MessageIdList.RESIST_BARCODE_LENGTH_RULE)
                            .content("Length of Vendor Barcode must be 27 or 29!</br>").build());

        Boolean hasVendorBarodeReceived = resistService.hasVendorBarodeReceived(vendorBarcode);
        Boolean hasResistIdReceived = resistService.hasResistIdReceived(vendorBarcode);
        Assert.isFalse(BooleanUtils.isNotFalse(hasVendorBarodeReceived) || BooleanUtils.isNotFalse(hasResistIdReceived),
                       Errors.create().key(MessageIdList.RESIST_BARCODE_HAS_BE_RECEIVED)
                             .content("Vendor Barcode has be " + "received!").args(vendorBarcode).build());
        if (vendorBarcode.length() == VENDOR_BARCODEDE_DEFAULT_LENGTH) {
            String resistNo = vendorBarcode.substring(NumberUtils.INTEGER_ZERO, RESIST_NO_START_POSITION);
            ResistMapping resistMapping = resistService.getResistMappingByResistNo(resistNo);

            Assert.isFalse(resistMapping == null,
                           Errors.create().key(MessageIdList.RESIST_RESISTNO_MISSING).content("ResistNo not exists")
                                 .build());

            Map resistInfo = BeanUtils.copyBeanToMap(resistMapping);
            resistInfo.put("vendorBarcode", vendorBarcode);
            resistInfo.put("instanceId", vendorBarcode);
            return resistInfo;
        } else {
            String resistNo = StringUtils.toString(NumberUtils.INTEGER_ZERO) +
                    vendorBarcode.substring(RESIST_NO_SPECIAL_START_POSITION, RESIST_NO_SPECIAL_END_POSITION);
            ResistMapping resistMapping = resistService.getResistMappingByResistNo(resistNo);

            Assert.isFalse(resistMapping == null,
                           Errors.create().key(MessageIdList.RESIST_RESISTNO_MISSING).content("ResistNo not exists")
                                 .build());

            String validDate = getSpecialExpireDate(vendorBarcode, resistMapping);

            Long serialNumber = resistService.getMaxSerialNumber(resistNo) + NumberUtils.LONG_ONE;
            String batchNo = vendorBarcode.substring(VALID_BATCHNO_START, VENDOR_BARCODEDE_DEFAULT_LENGTH);
            String instanceId = resistNo + batchNo + validDate + String.format("%0" + "6d", serialNumber);
            Map resistInfo = BeanUtils.copyBeanToMap(resistMapping);
            resistInfo.put("vendorBarcode", vendorBarcode);
            resistInfo.put("instanceId", instanceId);
            return resistInfo;
        }
    }

    public void addResist(Resist resist) throws Exception {
        long facilityRrn = LocalContext.getFacilityRrn();
        String user = LocalContext.getUserId();
        String vendorBarcode = resist.getVendorBarcode();
        Long eventSetRrn = baseService.getNamedObjectRrn(ObjectList.RESIST_ALLOWABLE_EVENTS, baseService
                .getNamedSpace(facilityRrn, ObjectList.ALLOWABLEEVENTSET_KEY), ObjectList.ALLOWABLEEVENTSET_KEY);

        Assert.isFalse(eventSetRrn <= NumberUtils.INTEGER_ZERO,
                       Errors.create().key(MessageIdList.EVENT_EVENTSET_MISSING).content("Eventset not exists !")
                             .args(ObjectList.RESIST_ALLOWABLE_EVENTS).build());
        Assert.isFalse(StringUtils.isBlank(vendorBarcode) || vendorBarcode.length() != VENDOR_BARCODEDE_DEFAULT_LENGTH,
                       Errors.create().key(MessageIdList.RESIST_BARCODE_LENGTH_RULE)
                             .content("Length of Vendor Barcode must be 27 or 29!</br>").build());

        Boolean hasVendorBarodeReceived = resistService.hasVendorBarodeReceived(vendorBarcode);
        Boolean hasResistIdReceived = resistService.hasResistIdReceived(vendorBarcode);

        Assert.isFalse(BooleanUtils.isNotFalse(hasVendorBarodeReceived) || BooleanUtils.isNotFalse(hasResistIdReceived) ,
                       Errors.create().key(MessageIdList.RESIST_BARCODE_HAS_BE_RECEIVED)
                             .content("Vendor Barcode has be " + "received!").args(vendorBarcode).build());

        this.validateExpireDate(resist);

        String resistNo = vendorBarcode.substring(NumberUtils.INTEGER_ZERO, RESIST_NO_START_POSITION);
        ResistMapping resistMapping = resistService.getResistMappingByResistNo(resistNo);

        Assert.isFalse(resistMapping == null,
                       Errors.create().key(MessageIdList.RESIST_RESISTNO_MISSING).content("ResistNo not exists")
                             .args(resistNo).build());

        Long serialNumber = resistService.getMaxSerialNumber(resistNo) + NumberUtils.LONG_ONE;

        String instanceId = vendorBarcode;

        Resist newResist = new Resist(instanceId, getNamedSpace(ObjectList.ENTITY_KEY, facilityRrn),
                                      ObjectList.ENTITY_KEY);

        newResist.setVendorBarcode(vendorBarcode);
        newResist.setResistNo(resistNo);
        newResist.setSerialNumber(serialNumber);
        newResist.setInstanceId(instanceId);
        newResist.setExpireDate(newResist.getExpireDate());

        newResist.setAllowableEventsRrn(eventSetRrn);
        newResist.setObjectType(ObjectList.RESIST_KEY);

        newResist.setCreateBy(user);
        newResist.setModifyBy(user);
        resistService.addResist(newResist);
    }

    public void addSpecialResist(Resist resist) throws Exception {
        long facilityRrn = LocalContext.getFacilityRrn();
        String user = LocalContext.getUserId();
        String vendorBarcode = resist.getVendorBarcode();
        Long eventSetRrn = baseService.getNamedObjectRrn(ObjectList.RESIST_ALLOWABLE_EVENTS, baseService
                .getNamedSpace(facilityRrn, ObjectList.ALLOWABLEEVENTSET_KEY), ObjectList.ALLOWABLEEVENTSET_KEY);

        Assert.isFalse(eventSetRrn <= NumberUtils.INTEGER_ZERO,
                       Errors.create().key(MessageIdList.EVENT_EVENTSET_MISSING).content("Eventset not exists !")
                             .args(ObjectList.RESIST_ALLOWABLE_EVENTS).build());
        Assert.isFalse(StringUtils.isBlank(vendorBarcode) || vendorBarcode.length() != VENDOR_BARCODEDE_LENGTH,
                       Errors.create().key(MessageIdList.RESIST_BARCODE_LENGTH_RULE)
                             .content("Length of Vendor Barcode must be 27 or 29!</br>").build());

        Boolean hasVendorBarodeReceived = resistService.hasVendorBarodeReceived(vendorBarcode);
        Assert.isFalse(BooleanUtils.isNotFalse(hasVendorBarodeReceived),
                       Errors.create().key(MessageIdList.RESIST_BARCODE_HAS_BE_RECEIVED)
                             .content("Vendor Barcode has be " + "received!").args(vendorBarcode).build());

        this.validateExpireDate(resist);

        String resistNo = StringUtils.toString(NumberUtils.INTEGER_ZERO) +
                vendorBarcode.substring(RESIST_NO_SPECIAL_START_POSITION, RESIST_NO_SPECIAL_END_POSITION);
        ResistMapping resistMapping = resistService.getResistMappingByResistNo(resistNo);

        Assert.isFalse(resistMapping == null,
                       Errors.create().key(MessageIdList.RESIST_RESISTNO_MISSING).content("ResistNo not exists")
                             .args(resistNo).build());

        String validDate = getSpecialExpireDate(vendorBarcode, resistMapping);

        Long serialNumber = resistService.getMaxSerialNumber(resistNo) + NumberUtils.LONG_ONE;

        String batchNo = vendorBarcode.substring(VALID_BATCHNO_START, VENDOR_BARCODEDE_DEFAULT_LENGTH);
        String instanceId = resistNo + batchNo + validDate + String.format("%0" + "6d", serialNumber);

        Resist newResist = new Resist(instanceId, getNamedSpace(ObjectList.ENTITY_KEY, facilityRrn),
                                      ObjectList.ENTITY_KEY);

        newResist.setVendorBarcode(vendorBarcode);
        newResist.setResistNo(resistNo);
        newResist.setSerialNumber(serialNumber);
        newResist.setInstanceId(instanceId);
        newResist.setExpireDate(newResist.getExpireDate());

        newResist.setAllowableEventsRrn(eventSetRrn);
        newResist.setObjectType(ObjectList.RESIST_KEY);

        newResist.setCreateBy(user);
        newResist.setModifyBy(user);
        resistService.addResist(newResist);
    }

    public ActionForward queryResistInfo(ActionMapping mapping, HttpServletRequest request) {

        String instanceId = WebUtils.getParameterUpperCase("instanceId", request);
        Resist resist = resistService.getResistByResistId(instanceId);
        Resist recommendResist = resistService.getRecommendResist(resist);

        if (recommendResist != null) {
            request.setAttribute("recommendResist", recommendResist);
        }
        request.setAttribute("resist", resist);
        return mapping.findForward("resistInfo");
    }

    public Resist modifyResistExpireDate(Resist transResist) {
        String user = LocalContext.getUserId();
        String instanceId = StringUtils.trimToUpperCase(transResist.getInstanceId());

        Resist resist = resistService.getResistByResistId(instanceId);
        Assert.isFalse(resist == null,
                       Errors.create().key(MessageIdList.RESIST_RESIST_MISSING).content("Resist not exist!").build());

        validateExpireDate(transResist);

        resist.setExpireDate(transResist.getExpireDate());
        resist.setModifyBy(user);

        resistService.modifyResistExpireDate(resist);
        resist = resistService.getResistByResistId(instanceId);
        return resist;
    }

    public void deleteResist(ResistForm theForm) {
        String user = LocalContext.getUserId();
        String instanceId = StringUtils.trimToUpperCase(theForm.getInstanceId());

        Resist resist = resistService.getResistByResistId(instanceId);
        Assert.isFalse(resist == null,
                       Errors.create().key(MessageIdList.RESIST_RESIST_MISSING).content("Resist not exist!").build());
        Assert.isFalse(StringUtils.isNotEmpty(resist.getEqptId()),
                       Errors.create().key(MessageIdList.RESIST_IN_USE).content("Resist is used by eqpt!").build());
        resist.setModifyBy(user);
        resistService.deleteResist(resist);
    }

    public Resist changeResistStatus(Map paramMap) {
        String user = LocalContext.getUserId();
        Long facilityRrn = LocalContext.getFacilityRrn();

        String instanceId = MapUtils.getString(paramMap, "instanceId");
        String targetStatus = MapUtils.getString(paramMap, "targetStatus");
        String comments = MapUtils.getString(paramMap, "comments");
        Resist resist = resistService.getResistByResistId(instanceId);

        String targetEventId = resistService
                .getResistEventIdBy2Status(resist.getInstanceRrn(), resist.getCurrentEntityStatus(), targetStatus);

        Assert.isFalse(StringUtils.isEmpty(targetEventId),
                       Errors.create().key(MessageIdList.EVENT_SET_UP_NOT_CORRECT).content("Event set up not correct!")
                             .build());

        Map<String, Object> transMap = new HashMap<String, Object>();
        resist.setModifyBy(user);
        transMap.put("facilityRrn", facilityRrn);
        transMap.put("resist", resist);
        transMap.put("eventId", targetEventId);
        transMap.put("comments", comments);
        resist.setComments(comments);

        resistService.changeResistStatus(transMap);
        resist = resistService.getResistByResistId(instanceId);
        return resist;
    }

    public Resist removeResist(Resist transResist) {
        String user = LocalContext.getUserId();
        String instanceId = transResist.getInstanceId();

        Resist tmpResist = resistService.getResistByResistId(instanceId);
        Assert.isFalse(tmpResist == null || tmpResist.getInstanceRrn() <= 0,
                       Errors.create().key(MessageIdList.RESIST_RESIST_MISSING).content("Resist not exist!").build());


        String targetEventId = resistService
                .getResistEventIdBy2Status(tmpResist.getInstanceRrn(), tmpResist.getCurrentEntityStatus(),
                                           ResistEnum.FINISH.getValue());

        Assert.isFalse(StringUtils.isEmpty(targetEventId),
                       Errors.create().key(MessageIdList.EVENT_SET_UP_NOT_CORRECT).content("Event set up not correct!")
                             .build());
        ConvertUtils.register(new DateConverter(null), java.util.Date.class);

        Resist resist = new Resist();
        BeanUtils.copyProperties(tmpResist, resist);
        BeanUtils.copyProperties(transResist, resist);
        resist.setInstanceRrn(tmpResist.getInstanceRrn());

        resist.setModifyBy(user);

        resist.setComments("Remove old resist");
        resistService.resistMoveInAndRemove(targetEventId, resist);
        resist = resistService.getResistByResistId(instanceId);
        return resist;
    }

    public void exchangeResistCheck(Map map) {
        String oldResistId = MapUtils.getString(map, "oldResistId");
        String newResistId = MapUtils.getString(map, "newResistId");
        String resistEqptBarcode = MapUtils.getString(map, "resistEqptBarcode");
        String manualOldResistId = MapUtils.getString(map,"manualOldResistId");
        Resist oldResist = resistService.getResistByResistId(oldResistId);
        Resist newResist = resistService.getResistByResistId(newResistId);
        validResistInfoForExchange(oldResist,resistEqptBarcode, manualOldResistId, newResist);
    }

    public Resist exchangeResist(Map map) {
        String oldResistId = MapUtils.getString(map, "oldResistId");
        String newResistId = MapUtils.getString(map, "newResistId");
        Resist oldResist = resistService.getResistByResistId(oldResistId);
        Resist newResist = resistService.getResistByResistId(newResistId);
        String resistEqptBarcode = MapUtils.getString(map, "resistEqptBarcode");
        String manualOldResistId = MapUtils.getString(map,"manualOldResistId");
        validResistInfoForExchange(oldResist,resistEqptBarcode, manualOldResistId, newResist);

        String targetEventIdForOld = resistService
                .getResistEventIdBy2Status(oldResist.getInstanceRrn(), oldResist.getCurrentEntityStatus(),
                                           ResistEnum.FINISH.getValue());
        Assert.isFalse(StringUtils.isEmpty(targetEventIdForOld),
                       Errors.create().key(MessageIdList.EVENT_SET_UP_NOT_CORRECT).content("Event set up not correct!")
                             .build());

        String targetEventIdForNew = resistService
                .getResistEventIdBy2Status(newResist.getInstanceRrn(), newResist.getCurrentEntityStatus(),
                                           ResistEnum.INUSE.getValue());
        Assert.isFalse(StringUtils.isEmpty(targetEventIdForNew),
                       Errors.create().key(MessageIdList.EVENT_SET_UP_NOT_CORRECT).content("Event set up not correct!")
                             .build());

        ConvertUtils.register(new DateConverter(null), java.util.Date.class);
        oldResist.setModifyBy(LocalContext.getUserId());

        newResist.setEqptId(oldResist.getEqptId());
        newResist.setUnit(oldResist.getUnit());
        newResist.setPrPipe(oldResist.getPrPipe());
        oldResist.setEqptId(null);
        oldResist.setUnit(null);
        oldResist.setPrPipe(null);
        resistService.resistExchange(oldResist, newResist, targetEventIdForOld, targetEventIdForNew);
        oldResist = resistService.getResistByResistId(oldResistId);
        return oldResist;
    }

    private String getExpireDate(String vendorBarcode, ResistMapping resistMapping) throws Exception {
        String expireDate = StringUtils.EMPTY;

        if (StringUtils
                .equalsIgnoreCase(resistMapping.getLifeTimeType(), ResistEnum.FOLLOW_BOTTLE_LIFE_TYPE.getValue())) {
            try {
                expireDate = vendorBarcode.substring(VALID_DATE_START_POSITION, VALID_DATE_END_POSITION);

                Calendar cal = Calendar.getInstance();
                String year = String.valueOf(cal.get(Calendar.YEAR));

                year = year.substring(NumberUtils.INTEGER_ZERO, NumberUtils.INTEGER_TWO);
                expireDate = year + expireDate;

                // 严格从vendor code 中获取的日期是否正确
                SimpleDateFormat sdf = new SimpleDateFormat(VALID_DATE_FORMAT);
                sdf.setLenient(false);
                sdf.parse(expireDate);
            } catch (Exception e) {
                throw new SystemIllegalArgumentException(Errors.create().key(MessageIdList.RESIST_DATE_FORMAT_ERROR)
                                                               .content(
                                                                       "Date format error in Vendorcode! 16th " + "to" +
                                                                               " 21st dates(yyMMDD)")
                                                               .args(vendorBarcode).build());
            }

        } else {// 计算得到的 格式必定符合规则
            Long timeMilleSec = System.currentTimeMillis() + 1000L * convertTime(resistMapping.getDefrostTime()) +
                    1000L * resistMapping.getBufferDays() * 24 * 60 * 60;

            expireDate = DateUtils.formatDate(new Date(timeMilleSec), VALID_DATE_FORMAT);

        }
        return expireDate;
    }

    private String getSpecialExpireDate(String vendorBarcode, ResistMapping resistMapping) throws ParseException {
        String expireDate = StringUtils.EMPTY;
        if (StringUtils
                .equalsIgnoreCase(resistMapping.getLifeTimeType(), ResistEnum.FOLLOW_BOTTLE_LIFE_TYPE.getValue())) {
            expireDate = vendorBarcode.substring(VALID_SPECIAL_DATE_START_POSITION, VALID_SPECIAL_DATE_END_POSITION);
            Calendar cal = Calendar.getInstance();
            String year = String.valueOf(cal.get(Calendar.YEAR));
            String endYear = expireDate.substring(NumberUtils.INTEGER_ZERO, NumberUtils.INTEGER_TWO);
            year = year.substring(NumberUtils.INTEGER_ZERO, NumberUtils.INTEGER_TWO);
            expireDate = year + expireDate;
            String expireDateYear = expireDate
                    .substring(NumberUtils.INTEGER_ZERO, VALID_SPECIAL_DAY_AND_MONTH_POSITION);
            String expireDay = expireDate.substring(VALID_SPECIAL_DAY_AND_MONTH_POSITION);
            Integer numberDay = (Integer) NumberUtils.parseNumber(expireDay, Integer.class);
            String expireMonth = StringUtils.EMPTY;
            //将具体天数转换为month 和 day
            for (int i = NumberUtils.INTEGER_ONE; i <= DateUtils.MAX_MONTH; i++) {
                Integer numberYear = (Integer) NumberUtils.parseNumber(expireDateYear, Integer.class);
                int maxDayOnMonthAndYear = DateUtils.maxDayOnMonthAndYear(i, numberYear);
                if (numberDay > maxDayOnMonthAndYear) {
                    numberDay = numberDay - maxDayOnMonthAndYear;
                } else {
                    if (i < MONTH_AND_DAY_TEN) {
                        expireMonth = StringUtils.toString(NumberUtils.INTEGER_ZERO) + StringUtils.toString(i);
                    } else {
                        expireMonth = StringUtils.toString(i);
                    }
                    break;
                }
            }
            Assert.isFalse(StringUtils.isEmpty(expireMonth) || numberDay < NumberUtils.INTEGER_ONE,
                           Errors.create().key(MessageIdList.RESIST_BARCODE_DATE_FORMAT_ERROR)
                                 .content("Date format error in Vendorcode!").build());
            String stringDay = StringUtils.EMPTY;
            if (numberDay < MONTH_AND_DAY_TEN) {
                stringDay = StringUtils.toString(NumberUtils.INTEGER_ZERO) + StringUtils.toString(numberDay);
            } else {
                stringDay = StringUtils.toString(numberDay);
            }
            expireDate = endYear + expireMonth + stringDay;
        } else {// 计算得到的 格式必定符合规则
            Long timeMilleSec = System.currentTimeMillis() + 1000L * convertTime(resistMapping.getDefrostTime()) +
                    1000L * resistMapping.getBufferDays() * 24 * 60 * 60;

            expireDate = DateUtils.formatDate(new Date(timeMilleSec), VALID_DATE_FORMAT);

        }
        return expireDate;
    }

    private void validateExpireDate(Resist resist) {
        if (StringUtils.isNotEmpty(resist.getExpireDates())) {
            resist.setExpireDate(resist.getExpireDates() + " " +
                                         (StringUtils.isEmpty(resist.getExpireTime()) ? "00:00:00" : resist
                                                 .getExpireTime()));
        }
        if (StringUtils.isNotBlank(resist.getExpireDate())) {
            long nowTime = System.currentTimeMillis();
            Timestamp dueDate = DateUtils.stringToTimestamp(resist.getExpireDate());

            Assert.isTrue(dueDate != null, Errors.create().content("Date format is wrong!").build());
            Assert.isFalse(dueDate.getTime() < nowTime,
                           Errors.create().content("Expire date must after the current date").build());
        }
    }

    private void validResistInfoForExchange(Resist oldResist,String resistEqptBarcode,String manualOldResistId, Resist newResist) {
        Assert.isFalse(oldResist == null,
                       Errors.create().key(MessageIdList.RESIST_OLD_RESIST_MISSING).content("Old resist not exist!")
                             .build());
        Assert.isFalse(!StringUtils.equalsIgnoreCase(oldResist.getCurrentEntityStatus(), ResistEnum.EMPTY.getValue()) &&
                               !StringUtils.equalsIgnoreCase(oldResist.getCurrentEntityStatus(),
                                                             ResistEnum.HOLD.getValue()),
                       Errors.create().key(MessageIdList.RESIST_OLD_CURRENT_STATUS)
                             .content("Old resist in {} " + "status!").args(oldResist.getCurrentEntityStatus())
                             .build());

        Assert.isFalse(newResist == null,
                       Errors.create().content(MessageIdList.RESIST_NEW_RESIST_MISSING).content("New resist not exist!")
                             .build());
        Assert.isTrue(StringUtils.equalsIgnoreCase(newResist.getCurrentEntityStatus(), ResistEnum.READY.getValue()),
                      Errors.create().key(MessageIdList.RESIST_NEW_CURRENT_STATUS)
                            .content("New resist not in READY status!").build());

        Assert.isTrue(StringUtils.equalsIgnoreCase(oldResist.getResistNo(), newResist.getResistNo()),
                      Errors.create().key(MessageIdList.RESIST_RESIST_NOT_MATCH)
                            .content("ResistNo of Old and new resist not match!").build());

        Assert.isFalse(StringUtils.isBlank(oldResist.getEqptId()),
                       Errors.create().key(MessageIdList.RESIST_OLD_RESIT_EQPT_EMPTY)
                             .content("Eqpt of old resist is empty!").build());
        Assert.isFalse(StringUtils.isNotBlank(newResist.getEqptId()),
                       Errors.create().key(MessageIdList.RESIST_NEW_RESIT_EQPT_NOT_EMPTY)
                             .content("Eqpt of new resist is not empty!").build());

        Assert.isTrue(StringUtils.equalsIgnoreCase(oldResist.getInstanceId(), manualOldResistId),
                      Errors.create().key(MessageIdList.RESIST_BARCODE_OLDRESIST_MATCHING)
                            .content("Old Resist and Resist Barcode is not matching!").build());

        ResistEqptMapping oldResistEqptMapping = resistService.getResistEqptMappingByResist(oldResist);

        Assert.isTrue(StringUtils.equals(oldResistEqptMapping.getResistEqptBarcode(), resistEqptBarcode),
                      Errors.create().key(MessageIdList.RESIST_EQPT_BARCODE_MATCHING)
                            .content("EQP-PRPipe Resist is not matching!").build());

    }

}