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 ("systemName".equals(conf.getAttriKey())) {
                systemBaseInfo.setSystemName(conf.getAttriValue());
            } else if ("systemVersion".equals(conf.getAttriKey())) {
                systemBaseInfo.setSystemVersion(conf.getAttriValue());
            } else if ("loginType".equals(conf.getAttriKey())) {
                systemBaseInfo.setLoginType(conf.getAttriValue());
            } else if ("systemLogo".equals(conf.getAttriKey())) {
                systemBaseInfo.setSystemLogo(conf.getAttriValue());
            } else if ("homeUrl".equals(conf.getAttriKey())) {
                systemBaseInfo.setHomeUrl(conf.getAttriValue());
            } else if ("isTop".equals(conf.getAttriKey())) {
                systemBaseInfo.setIsTop(conf.getAttriValue());
            } else if ("apiUrl".equals(conf.getAttriKey())) {
                systemBaseInfo.setApiUrl(conf.getAttriValue());
            } else if ("pdfUrl".equals(conf.getAttriKey())) {
                systemBaseInfo.setPdfUrl(conf.getAttriValue());
            } else if ("imgUploadUrl".equals(conf.getAttriKey())) {
                systemBaseInfo.setImgUploadUrl(conf.getAttriValue());
            } else if ("imgViewUrl".equals(conf.getAttriKey())) {
                systemBaseInfo.setImgViewUrl(conf.getAttriValue());
            } else if ("loginTypeApp".equals(conf.getAttriKey())) {
                systemBaseInfo.setLoginTypeApp(conf.getAttriValue());
            } else if ("loginTypeH5".equals(conf.getAttriKey())) {
                systemBaseInfo.setLoginTypeH5(conf.getAttriValue());
            }
        }
        return systemBaseInfo;
    }
}
