package org.springblade.modules.system.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springblade.modules.system.entity.VisualSubscribeNotifyConf;
import org.springblade.modules.system.enums.NotifyType;
import org.springblade.modules.system.service.ISystemBaseInfoService;
import org.springblade.modules.system.service.VisualSubscribeNotifyConfService;
import org.springblade.modules.system.vo.SystemBaseInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SystemBaseInfoServiceImpl implements ISystemBaseInfoService {

    @Autowired
    private VisualSubscribeNotifyConfService visualSubscribeNotifyConfService;

    @Override
    public SystemBaseInfoVO getSystemBaseInfoVO() {

        List<VisualSubscribeNotifyConf> confList = visualSubscribeNotifyConfService.list(Wrappers.<VisualSubscribeNotifyConf>lambdaQuery()
                .eq(VisualSubscribeNotifyConf::getNotifyType,NotifyType.systemSetting.getValue()));
        SystemBaseInfoVO systemBaseInfo = new SystemBaseInfoVO();
        // 先添加默认值
        systemBaseInfo.setSystemName("几何BI");
        systemBaseInfo.setHomeUrl("/#/newbi/mobile/88/923");
        systemBaseInfo.setSystemLogo("");
        systemBaseInfo.setIsTop("1");
        systemBaseInfo.setLoginType("1");
        systemBaseInfo.setApiUrl("https://windata.platomix.net");
        systemBaseInfo.setPdfUrl("https://windata.platomix.net");
        systemBaseInfo.setImgUploadUrl("https://windata.platomix.net/api");
        systemBaseInfo.setImgViewUrl("https://windata.platomix.net/uploads");
        systemBaseInfo.setSystemVersion("3.2.0");
        for (VisualSubscribeNotifyConf conf : confList) {
            if (conf.getAttriKey().equals("systemName")) {
                systemBaseInfo.setSystemName(conf.getAttriValue());
            } else if (conf.getAttriKey().equals("systemVersion")) {
                systemBaseInfo.setSystemVersion(conf.getAttriValue());
            } else if (conf.getAttriKey().equals("loginType")) {
                systemBaseInfo.setLoginType(conf.getAttriValue());
            } else if (conf.getAttriKey().equals("systemLogo")) {
                systemBaseInfo.setSystemLogo(conf.getAttriValue());
            } else if (conf.getAttriKey().equals("homeUrl")) {
                systemBaseInfo.setHomeUrl(conf.getAttriValue());
            } else if (conf.getAttriKey().equals("isTop")) {
                systemBaseInfo.setIsTop(conf.getAttriValue());
            } else if (conf.getAttriKey().equals("apiUrl")) {
                systemBaseInfo.setApiUrl(conf.getAttriValue());
            } else if (conf.getAttriKey().equals("pdfUrl")) {
                systemBaseInfo.setPdfUrl(conf.getAttriValue());
            } else if (conf.getAttriKey().equals("imgUploadUrl")) {
                systemBaseInfo.setImgUploadUrl(conf.getAttriValue());
            } else if (conf.getAttriKey().equals("imgViewUrl")) {
                systemBaseInfo.setImgViewUrl(conf.getAttriValue());
            } else if (conf.getAttriKey().equals("loginTypeApp")) {
                systemBaseInfo.setLoginTypeApp(conf.getAttriValue());
            } else if (conf.getAttriKey().equals("loginTypeH5")) {
                systemBaseInfo.setLoginTypeH5(conf.getAttriValue());
            }
        }
        return systemBaseInfo;
    }
}
