/**
 * Copyright © 2021-2026 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.test.wdt.merchantCompany.service;

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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jeeplus.core.query.QueryWrapperGenerator;
import com.jeeplus.sys.domain.Post;
import com.jeeplus.sys.mapper.PostMapper;
import com.jeeplus.test.wdt.merchantCompany.domain.MerchantCompany;
import com.jeeplus.test.wdt.merchantCompany.domain.SettledPlatform;
import com.jeeplus.test.wdt.merchantCompany.mapper.SettledPlatformMapper;
import com.jeeplus.test.wdt.merchantCompany.service.dto.MerchantCompanyDTO;
import com.jeeplus.test.wdt.merchantCompany.service.dto.SettledPlatformDTO;
import com.jeeplus.test.wdt.merchantCompany.service.mapstuct.MerchantCompanyWrapper;
import com.jeeplus.test.wdt.merchantCompany.service.mapstuct.SettledPlatformWrapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 入驻平台Service
 * @author 徐滕
 * @version 2024-01-04 15:18
 */
@Service
@Transactional
public class SettledPlatformService extends ServiceImpl <SettledPlatformMapper, SettledPlatform> {

    /**
     * 自定义分页检索
     * @param page
     * @param settledPlatformDTO
     * @return
     */
    public IPage<SettledPlatformDTO> findPage(Page<SettledPlatformDTO> page, SettledPlatformDTO settledPlatformDTO) throws Exception {
        QueryWrapper<SettledPlatform> queryWrapper = QueryWrapperGenerator.buildQueryCondition ( SettledPlatformWrapper.INSTANCE.toEntity(settledPlatformDTO), SettledPlatform.class );
        queryWrapper.eq ("a.del_flag", 0 ); // 排除已经删除
        queryWrapper.orderByAsc("a.sort");
        if(StringUtils.isNotBlank(settledPlatformDTO.getName())){
            queryWrapper.like("a.name",settledPlatformDTO.getName());
        }
        if (settledPlatformDTO.getDates() != null && settledPlatformDTO.getDates().length > 0) {
            if(settledPlatformDTO.getDates().length == 1){
                queryWrapper.ge("a.create_time",settledPlatformDTO.getDates()[0]);
            }else {
                queryWrapper.between("a.create_time", settledPlatformDTO.getDates()[0], settledPlatformDTO.getDates()[1]);
            }
        }
        return  baseMapper.findList (page, queryWrapper);
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    public SettledPlatformDTO findById(String id) {
        return baseMapper.findById ( id );
    }

}
