package com.tuoheng.admin.service.inspection.query.handle;

import com.tuoheng.admin.entity.Dept;
import com.tuoheng.admin.entity.User;
import com.tuoheng.admin.enums.InspectionStatusEnum;
import com.tuoheng.admin.enums.InspectionTypeEnum;
import com.tuoheng.admin.vo.inspection.InspectionVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service("resubmitHandle")
public class ResubmitHandle implements GenerateInspectionFieldHander {

    private GenerateInspectionFieldHander handler;

    @Override
    public void setNextHandler(GenerateInspectionFieldHander handler) {
        this.handler = handler;
    }

    /**
     *  1）、当任务处于任务失败状态时显示
     *  2）、仅巡检方式为机场巡逻的任务有此功能
     *
     * @param inspectionVo
     */
    @Override
    public void handler(User user, Dept dept, InspectionVo inspectionVo) {
//        log.info("处理重新提交字段");
        if (InspectionStatusEnum.FLIGHT_FAILED.getCode() != inspectionVo.getStatus()) {
            if (null != handler) {
                handler.handler(user, dept, inspectionVo);
            }
            return;
        }
        if (InspectionTypeEnum.AIRPORT.getCode() != inspectionVo.getInspectionType()) {
            if (null != handler) {
                handler.handler(user, dept,inspectionVo);
            }
            return;
        }
        inspectionVo.setResubmit(true);
        if (null != handler) {
            handler.handler(user, dept,inspectionVo);
        }
    }

}
