package com.tuoheng.admin.service.bnconnect.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tuoheng.admin.mapper.BnconnectMapper;
import com.tuoheng.admin.pojo.entity.Bnconnect;
import com.tuoheng.admin.pojo.request.BnconnectQuery;
import com.tuoheng.admin.service.bnconnect.IBnconnectService;
import com.tuoheng.common.common.BaseServiceImpl;
import com.tuoheng.common.utils.JsonResult;
import com.tuoheng.common.utils.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


/**
 * @Author: 吴彬
 * @CreateTime: 2023-06-12  11:12
 * @Description: 机场对接业务系统 服务实现类
 * @Version: 1.0
 */
@Service
public class BnconnectServiceImpl extends BaseServiceImpl<BnconnectMapper, Bnconnect> implements IBnconnectService {

    @Resource
    private BnconnectMapper bnconnectMapper;


    @Override
    public JsonResult getList(BnconnectQuery bnconnectQuery) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("mark","1");
        if(StringUtils.isNotEmpty(bnconnectQuery.getCode())) {
            wrapper.like("code", bnconnectQuery.getCode());
        }
        if(StringUtils.isNotEmpty(bnconnectQuery.getName())) {
            wrapper.like("name", bnconnectQuery.getName());
        }
        IPage<Bnconnect> page = new Page<>(bnconnectQuery.getPage(), bnconnectQuery.getLimit());
        return JsonResult.success(bnconnectMapper.selectPage(page,wrapper));
    }

    @Override
    public Bnconnect selectByCode(String code) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("mark","1");
        wrapper.eq("code",code);
        List list =bnconnectMapper.selectList(wrapper);
        if (list.size()>0){
            return (Bnconnect) list.get(0);
        }
        return null;
    }
    @Override
    public Bnconnect selectByUrl(String url) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("mark","1");
        wrapper.eq("api_url",url);
        List list =bnconnectMapper.selectList(wrapper);
        if (list.size()>0){
            return (Bnconnect) list.get(0);
        }
        return null;
    }

    @Override
    public JsonResult getListAll() {
        List<Bnconnect> list = list();
        Bnconnect bnconnect = new Bnconnect();
        bnconnect.setCode("airport");
        bnconnect.setName("机场平台");
        list.add(bnconnect);
        Bnconnect bnconnect1 = new Bnconnect();
        bnconnect1.setCode("airportTimer");
        bnconnect1.setName("机场平台定时任务");
        list.add(bnconnect1);
        return JsonResult.success(list);
    }
}
