package com.blueland.service.impl;


import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.blueland.service.IAppService;
import org.springframework.stereotype.Service;

import com.blueland.bo.AppEntity;
import com.blueland.dao.AppDao;

import java.util.List;

@Service
public class AppServiceImpl extends ServiceImpl<AppDao, AppEntity> implements IAppService {

    @Override
    public AppEntity get(AppEntity bo) {
        return this.baseMapper.selectOne(buildQueryWrapper(bo));
    }

    @Override
    public Page<AppEntity> findPage(AppEntity bo) {
        Page<AppEntity> page = new Page(bo.getPageNum(), bo.getPageSize());
        return this.baseMapper.findPage(page, bo);
    }

    private LambdaQueryWrapper<AppEntity> buildQueryWrapper(AppEntity bo) {
        LambdaQueryWrapper<AppEntity> lqw = Wrappers.lambdaQuery();
        lqw.eq(ObjectUtil.isNotEmpty(bo.getAppId()), AppEntity::getAppId, bo.getAppId());
        lqw.like(ObjectUtil.isNotEmpty(bo.getAppName()), AppEntity::getAppName, bo.getAppName());
        lqw.like(ObjectUtil.isNotEmpty(bo.getAppDesc()), AppEntity::getAppDesc, bo.getAppDesc());
        lqw.eq(ObjectUtil.isNotEmpty(bo.getAppVisitUrl()), AppEntity::getAppVisitUrl, bo.getAppVisitUrl());
        lqw.eq(ObjectUtil.isNotEmpty(bo.getAppType()), AppEntity::getAppType, bo.getAppType());
        lqw.eq(ObjectUtil.isNotEmpty(bo.getAppPriority()), AppEntity::getAppPriority, bo.getAppPriority());
        lqw.eq(ObjectUtil.isNotEmpty(bo.getStatus()), AppEntity::getStatus, bo.getStatus());
        lqw.eq(ObjectUtil.isNotEmpty(bo.getCreatorId()), AppEntity::getCreatorId, bo.getCreatorId());
        lqw.eq(ObjectUtil.isNotEmpty(bo.getIsApply()), AppEntity::getIsApply, bo.getIsApply());
        lqw.eq(ObjectUtil.isNotEmpty(bo.getIsSync()), AppEntity::getIsSync, bo.getIsSync());
        return lqw;
    }
}
