package com.yuchen.saas.park.service.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yuchen.saas.park.api.entity.park.PmgBatParkCompany;
import com.yuchen.saas.park.service.mapper.CompanyMapper;
import com.yuchen.saas.park.service.service.IParkCompanyService;
import org.nest.springwrap.core.mp.base.BaseServiceImpl;
import org.nest.springwrap.core.mp.support.Condition;
import org.nest.springwrap.core.mp.support.Query;
import org.nest.springwrap.core.tool.utils.ObjectUtil;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 吕海泉
 * @create 2020/12/7 15:17
 */
@Service
public class ParkCompanyServiceImpl extends BaseServiceImpl<CompanyMapper, PmgBatParkCompany> implements IParkCompanyService {

    @Override
    public List<PmgBatParkCompany> getCompanyByPKAndDN(String productKey, String deviceName) {
        return baseMapper.getCompanyByPKAndDN(productKey, deviceName);
    }

    @Override
    public IPage<PmgBatParkCompany> getPage(PmgBatParkCompany pmgBatParkCompany, Query query) {
        QueryWrapper<PmgBatParkCompany> queryWrapper = new QueryWrapper<>();
        if(ObjectUtil.isNotEmpty(pmgBatParkCompany.getParkId())){
            queryWrapper.eq("park_id", pmgBatParkCompany.getParkId());
        }
        if(ObjectUtil.isNotEmpty(pmgBatParkCompany.getCompanyName())){
            queryWrapper.like("company_name", pmgBatParkCompany.getCompanyName());
        }
        if(ObjectUtil.isNotEmpty(pmgBatParkCompany.getLegalPerson())){
            queryWrapper.like("legal_person", pmgBatParkCompany.getLegalPerson());
        }
        if(ObjectUtil.isNotEmpty(pmgBatParkCompany.getLinkMan())){
            queryWrapper.like("link_man", pmgBatParkCompany.getLinkMan());
        }
        return page(Condition.getPage(query),queryWrapper);
    }

    @Override
    public List<PmgBatParkCompany> getByParkId(Long parkId) {
        LambdaQueryWrapper<PmgBatParkCompany> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(PmgBatParkCompany::getParkId,parkId);
        return list(queryWrapper);
    }
}

