package com.mosty.common.config.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mosty.common.base.constant.enums.DeletedEnum;
import com.mosty.common.config.entity.SysDict;
import com.mosty.common.config.entity.SysVersionManage;
import com.mosty.common.config.entity.vo.VersionManagePage;
import com.mosty.common.config.mapper.SysVersionManageMapper;
import com.mosty.common.config.service.SysVersionManageService;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 版本管理表 服务实现类
 * </p>
 *
 * @author kevin
 * @since 2022-02-21
 */
@Service
@AllArgsConstructor
public class SysVersionManageServiceImpl extends ServiceImpl<SysVersionManageMapper, SysVersionManage> implements SysVersionManageService {

    private final SysVersionManageMapper sysVersionManageMapper;

    @Override
    public IPage<SysVersionManage> selectByPage(VersionManagePage versionManagePage) {
        QueryWrapper<SysVersionManage> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotBlank(versionManagePage.getSysVersion())) {
            queryWrapper.and(wrapper -> wrapper.like("sys_version", versionManagePage.getSysVersion()));
        }
        if (StringUtils.isNotBlank(versionManagePage.getStartPublishTime())) {
            queryWrapper.and(wrapper -> wrapper.gt("publish_time", versionManagePage.getStartPublishTime()));
        }
        if (StringUtils.isNotBlank(versionManagePage.getEndPublishTime())) {
            queryWrapper.and(wrapper -> wrapper.le("publish_time", versionManagePage.getEndPublishTime()));
        }
        queryWrapper.and(wrapper -> wrapper.le("xt_zxbz", DeletedEnum.NATURE.code));
        queryWrapper.orderByDesc("publish_time");
        return getBaseMapper().selectPage(versionManagePage, queryWrapper);
    }
}
