package com.zd.system.api.factory;

import com.zd.common.core.domain.R;
import com.zd.common.core.enums.HardwareOperate;
import com.zd.common.core.exception.ServiceException;
import com.zd.common.core.web.domain.AjaxResult;
import com.zd.common.core.web.page.TableDataInfo;
import com.zd.system.api.domain.Algorithm;
import com.zd.system.api.laboratory.RemoteLaboratoryService;
import com.zd.system.api.laboratory.domain.*;
import com.zd.system.api.laboratory.domain.vo.LabGradeManageWorkVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

@Component
public class RemoteLaboratoryFallbackFactory implements FallbackFactory<RemoteLaboratoryService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteLaboratoryFallbackFactory.class);

    @Override
    public RemoteLaboratoryService create(Throwable cause) {
        log.error("实验室服务调用失败:{}", cause.getMessage());
        return new RemoteLaboratoryService() {
            @Override
            public R<List<LabSubjectVO>> getInfoByUserIds(String ids) {
                return R.fail("获取负责人实验室数据失败:" + cause.getMessage());
            }

            @Override
            public R<Object> appReceivePhotoNote(Map<String, Object> photoNote) {
                return R.fail("登录人接收随手拍统计失败:" + cause.getMessage());
            }

            @Override
            public R<Object> addPhotoNote(Map<String, Object> labPhotoNote) {
                return R.fail("随手拍提交失败:" + cause.getMessage());
            }

            @Override
            public TableDataInfo getAppList(Map appInfo) {
                TableDataInfo tableDataInfo = new TableDataInfo();
                tableDataInfo.setMsg("查询随手拍记录列表信息列表失败:" + cause.getMessage());
                tableDataInfo.setCode(500);
                return tableDataInfo;
            }

            @Override
            public R<Object> isadmin(Map<String, Object> map) {
                return R.fail("查询是否管理员失败:" + cause.getMessage());
            }

            @Override
            public R<Object> getPhotonoteInfo(Long id) {
                return R.fail("获取随手拍详情失败:" + cause.getMessage());
            }

            @Override
            public R<Object> editPhotoNote(Map appInfo) {
                return R.fail("随手拍审批失败:" + cause.getMessage());
            }

            @Override
            public R<Object> outSubjectPhoto() {
                return R.fail("离开实验室拍照附件列表失败:" + cause.getMessage());
            }

            @Override
            public R<Object> outSubjectList() {
                return R.fail("获取签到离开的实验室列表失败:" + cause.getMessage());
            }

            @Override
            public R<Object> addPhotoInspection(Map<String,Object> labPhotoInspection) {
                return R.fail("拍照检查附件提交失败:" + cause.getMessage());
            }

            @Override
            public R<Object> getApprovalCount(@RequestParam Map<String, Object> approval) {
                return R.fail("统计安全准入审批不同信息:" + cause.getMessage());
            }

            @Override
            public TableDataInfo getApprovalList(Map approval) {
                TableDataInfo tableDataInfo = new TableDataInfo();
                tableDataInfo.setMsg("查询安全准入审批记录列表失败:" + cause.getMessage());
                tableDataInfo.setCode(500);
                return tableDataInfo;
            }

            @Override
            public TableDataInfo getViolationList(Map violation) {
                TableDataInfo tableDataInfo = new TableDataInfo();
                tableDataInfo.setMsg("查询查询违规记录列表失败:" + cause.getMessage());
                tableDataInfo.setCode(500);
                return tableDataInfo;
            }

            @Override
            public R<Object> myViolationCount(Map violation) {
                return R.fail("查询违规记录列表失败:" + cause.getMessage());
            }

            @Override
            public R<Object> editViolation(Map<String, Object> params) {
                return R.fail("修改违规记录失败:" + cause.getMessage());
            }

            @Override
            public R<Object> mySubjectList(Map violation) {
                return R.fail("查询我的实验室列表失败:" + cause.getMessage());
            }

            @Override
            public R getMyCardInfo() {
                return R.fail("获取学生卡和人脸信息失败:" + cause.getMessage());
            }

            @Override
            public R<Object> subjectMaterialList(Map material) {
                return R.fail("获取实验室下的安全准入资格材料列表失败:" + cause.getMessage());
            }

            @Override
            public R<Object> getSubjectDict() {
                return R.fail("小程序查询实验室列表失败:" + cause.getMessage());
            }

            @Override
            public R<Object> blacklistLearningRules(Map<String,Object> blackdetailMap) {
                return R.fail("黑名单完成学习规则执行失败:" + cause.getMessage());
            }




            /**
             * 负面清单完成学习规则
             *
             * @param violationId
             * @param status
             */
            @Override
            public R negativelistLearningRules(Long violationId, int status) {
                return R.fail("负面清单完成学习规则执行失败:" + cause.getMessage());
            }

            @Override
            public R<Object> getBlackTimeArea(Map<String,Object> blackdetailMap) {
                return R.fail("获取黑名单惩罚时间区间失败:" + cause.getMessage());
            }

            @Override
            public R<Object> approvalDetail(String ids) {
                return R.fail("获取安全准入审批记录详细信息失败:" + cause.getMessage());
            }

            @Override
            public R<Object> accessReview(Map<String, Object> labApprovalMap) {
                return R.fail("提交安全准入资格信息失败:" + cause.getMessage());
            }

            @Override
            public R<Object> appOperation(Map<String, Object> labApprovalMap) {
                return R.fail("安全准入审批失败:" + cause.getMessage());
            }

            @Override
            public R<Object> failedOperation(Map<String, Object> labApprovalMap) {
                return R.fail("安全准入审批拒绝失败:" + cause.getMessage());
            }

            @Override
            public R<Object> uploadFace(MultipartFile file) {
                return R.fail("获取小程序人脸识别接口失败:" + cause.getMessage());
            }

            @Override
            public R<Object> userBlacklist(Long userId) {
                return R.fail("获取用户黑名单信息失败:" + cause.getMessage());
            }

            @Override
            public R sends(String num, HardwareOperate hardwareOperate) {
                return R.fail("摄像头在线离线调用失败:" + cause.getMessage());
            }

            @Override
            public AjaxResult outTimeRecord() {
                return AjaxResult.error("定时查询离开时间超过24小时，记违规任务失败：" + cause.getMessage());
            }

            @Override
            public AjaxResult outTimeClearMessage() {
                return AjaxResult.error("清理消息失败：" + cause.getMessage());
            }

            @Override
            public AjaxResult publishMess(LabMessageContent labMessageContent) {
                return AjaxResult.error("发送消息失败：" + cause.getMessage());
            }

            /**
             * 查询实验室控制数据列表- 仅负责人权限（小程序使用）
             *
             * @return
             */
            @Override
            public R queryMyAadminSubCListVO() {
                return R.fail("查询我的实验室列表失败:" + cause.getMessage());

            }

            @Override
            public R<List<TotalByID>> queryBuildingSubTotal(Long[] ids) {
                return R.fail("获取实验室数量信息失败:" + cause.getMessage());
            }

            @Override
            public TableDataInfo getSafeWarnList(Map riskPlanAbnormalLog) {
                TableDataInfo tableDataInfo = new TableDataInfo();
                tableDataInfo.setMsg("查询安全报警记录列表失败:" + cause.getMessage());
                tableDataInfo.setCode(500);
                return tableDataInfo;
            }

            @Override
            public R getSafeWarnCount() {
                return R.fail("查询安全报警记录统计失败:" + cause.getMessage());

            }

            @Override
            public TableDataInfo getSubByRiskPlan(Map riskPlanAbnormalLog) {
                TableDataInfo tableDataInfo = new TableDataInfo();
                tableDataInfo.setMsg("查询预案列表失败:" + cause.getMessage());
                tableDataInfo.setCode(500);
                return tableDataInfo;
            }

            @Override
            public R saveData(Algorithm algorithm) {
                return R.fail("保存算法失败:" + cause.getMessage());
            }

            @Override
            public R getCheckInfo(Long id) {
                return R.fail("获取实验室检查项失败:" + cause.getMessage());
            }

            @Override
            public R userexist(Long userId) {
                return R.fail("查询用户违规项失败:" + cause.getMessage());
            }

            @Override
            public R getPersonInfo() {
                 return R.fail("查询用户及违规信息失败:" + cause.getMessage());
            }

            @Override
            public R getViolationTime(Long violationId) {
                return R.fail("查询违规起始时间失败:" + cause.getMessage());
            }

            @Override
            public R getPracticeNum(Long violationId) {
                return R.fail("查询做题数量失败:" + cause.getMessage());
            }

            @Override
            public R<Object> listGroupBy(Map<String, Object> map) {
                return R.fail("安全检查项按时间分组查询失败:" + cause.getMessage());
            }

            @Override
            public R<Object> selectInfoByRoom(Map<String, Object> map) {
                return R.fail("根据参数查询实验室信息失败:" + cause.getMessage());
            }

            @Override
            public R<Object> addCg(Map<String, Object> map) {
                return R.fail("安全检查草稿保存失败:" + cause.getMessage());
            }

            @Override
            public R<Object> addTj(Map<String, Object> map) {
                return R.fail("安全检查保存失败:" + cause.getMessage());
            }

            @Override
            public R<Object> recordDettailsList(Integer id) {
                return R.fail("根据检查项获取 隐患整改集合失败:" + cause.getMessage());
            }

            @Override
            public R<Object> editCheckRecord(Map<String, Object> map) {
                return R.fail("安全检查修改失败:" + cause.getMessage());
            }

            @Override
            public R<Object> editCheckRecordDetailsList(Map<String, Object> map) {
                return R.fail("安全检查详情列表添加失败:" + cause.getMessage());
            }

            @Override
            public R<Object> selectUserInfoById(Long id) {
                return R.fail("根据用户id查询用户信息失败:" + cause.getMessage());
            }

            @Override
            public void genNotice(Long id, HttpServletResponse response) {
                throw new ServiceException("生成整改通知书失败" + cause.getMessage());
            }

            @Override
            public void genReport(Long id, HttpServletResponse response) {
                throw new ServiceException("生成整改报告" + cause.getMessage());
            }

            @Override
            public R<Object> getSpeakerByFloor(Long floorId) {
                throw new ServiceException("根据楼层获取喇叭列表" + cause.getMessage());
            }

            @Override
            public R<Object> getSpeakerBySub(Long floorId, Long subId) {
                throw new ServiceException("根据楼层获取喇叭列表" + cause.getMessage());
            }

            @Override
            public void workArrange() {
                throw new ServiceException("定时任务分级管控工作过期记录 - 并排列下次工作计划失败：" + cause.getMessage());
            }

            @Override
            public void workOverdue() {
                throw new ServiceException("定时任务分级管控早8点管控工作逾期通知：" + cause.getMessage());
            }

            @Override
            public void workExecuteByDay() {
                throw new ServiceException("定时任务分级管控工作下午7点 管控工作执行通知：" + cause.getMessage());
            }

            @Override
            public void workExecute() {
                throw new ServiceException("定时任务分级管控早8点 其他管控工作执行通知：" + cause.getMessage());
            }

            @Override
            public R<List<LabGradeManageWorkVO>> havingList(LabGradeManageRecord labGradeManageRecord) {
                throw new ServiceException("查询分级管控未完成工作列表" + cause.getMessage());
            }

            @Override
            public R<List<LabGradeManageWorkVO>> finishList(LabGradeManageRecord labGradeManageRecord) {
                throw new ServiceException("查询分级管控已完成工作列表" + cause.getMessage());
            }

            @Override
            public R<LabGradeManageRecord> finish(LabGradeManageRecord labGradeManageRecord) {
                throw new ServiceException("完成分级管控工作" + cause.getMessage());
            }

            @Override
            public R<LabGradeManageRecord> getInfo(Long id) {
                throw new ServiceException("获取分级管控工作详细信息" + cause.getMessage());
            }

            @Override
            public R<LabGradeManageWorkVO> queryByMessage(LabGradeManageRecord labGradeManageRecord) {
                throw new ServiceException("获取分级管控工作详细信息" + cause.getMessage());
            }

            /**
             * 安全检查隐患项未整改逾期通知
             */
            @Override
            public void checkSendMsgBeOverdue() {
                throw new ServiceException("安全检查隐患项未整改逾期通知" + cause.getMessage());
            }

            @Override
            public void logoNotice() {
                throw new ServiceException("logo通知失败" + cause.getMessage());
            }

            @Override
            public Object controlByInside(Long id, String type) {
                throw new ServiceException("继电器远程控制失败：" + cause.getMessage());
            }

            @Override
            public R <List <LinkedHashMap <String, String>>> getHardwareByLockList(Map cabinetSetId) {
                throw new ServiceException("获取柜锁列表失败：" + cause.getMessage());
            }

            @Override
            public R<List<RemoteLabHardware>> listStart() {
                return R.fail("查询FRID设备失败：" + cause.getMessage());
            }

            @Override
            public R<List<RemoteLabHardware>> remoteList(RemoteLabHardware remoteLabHardware) {
                return R.fail("查询设备失败：" + cause.getMessage());
            }

            @Override
            public R<Integer> update(@RequestParam("operate") HardwareOperate operate, String ipAddress) {
                return R.fail("FRID设备状态修改失败：" + cause.getMessage());
            }

        };
    }
}
