package com.zd.system.api.factory;

import com.zd.common.core.domain.R;
import com.zd.common.core.web.page.TableDataInfo;
import com.zd.system.api.laboratory.RemoteMessageContentService;
import com.zd.system.api.laboratory.domain.LabMessageUser;
import com.zd.system.api.laboratory.domain.vo.LabMessageUserListVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * @Author: zhoupan
 * @Date: 2021/09/07/8:30
 * @Description:
 */
@Component
public class RemoteMessageContentFallbackFactory implements FallbackFactory<RemoteMessageContentService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteMessageContentFallbackFactory.class);


    @Override
    public RemoteMessageContentService create(Throwable cause) {
        log.error("实验室服务调用失败:{}", cause.getMessage());
        return new RemoteMessageContentService() {
            /**
             * 查询我的消息
             *
             * @param pagNum
             * @param PageSize
             */
            @Override
            public TableDataInfo<LabMessageUserListVO> mylist(Long pagNum, Long PageSize) {
                TableDataInfo tableDataInfo = new TableDataInfo();
                tableDataInfo.setCode(500);
                tableDataInfo.setMsg("查询消息列表错误失败:" + cause.getMessage());
                return tableDataInfo;
            }

            /**
             * 查询我的消息-发送人分组-(只查询管理员消息)
             *
             * @param pageNum
             * @param pageSize
             */
            @Override
            public TableDataInfo myGrouplist(Long pageNum, Long pageSize) {
                TableDataInfo tableDataInfo = new TableDataInfo();
                tableDataInfo.setCode(500);
                tableDataInfo.setMsg("查询我的消息-发送人分组失败:" + cause.getMessage());
                return tableDataInfo;
            }

            /**
             * 查询我的消息统计数量
             *
             * @return
             */
            @Override
            public R<Object> myGroupTotalCount() {
                return R.fail("查询我的消息统计数量失败:" + cause.getMessage());
            }

            /**
             * 查询安全准入消息信息
             *
             * @param messageId
             * @return
             */
            @Override
            public R<Object> myRead(Long messageId) {
                return R.fail("查询安全准入消息信息失败:" + cause.getMessage());
            }

            /**
             * 查询我的消息-发送人分组-分组内消息
             *
             * @param pageNum
             * @param pageSize
             * @param id
             */
            @Override
            public TableDataInfo myGrouplistById(Long pageNum, Long pageSize, Long id) {
                TableDataInfo tableDataInfo = new TableDataInfo();
                tableDataInfo.setCode(500);
                tableDataInfo.setMsg("查询我的消息-发送人分组失败:" + cause.getMessage());
                return tableDataInfo;
            }

            /**
             * 查询消息内容
             *
             * @param id
             * @return
             */
            @Override
            public R<LabMessageUser> message(Long id) {
                return R.fail("查询消息内容失败:" + cause.getMessage());
            }

            @Override
            public void readByLoginUser(LabMessageUser labMessageUser) {

            }

            @Override
            public R addDynamicMessage(Object obj) {
                return null;
            }
        };
    }
}
