/**
 * 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.test.wdt.merchantCompany.domain.CompanyType;
import com.jeeplus.test.wdt.merchantCompany.domain.MerchantProduct;
import com.jeeplus.test.wdt.merchantCompany.mapper.CompanyTypeMapper;
import com.jeeplus.test.wdt.merchantCompany.mapper.MerchantProductMapper;
import com.jeeplus.test.wdt.merchantCompany.service.dto.CompanyTypeDTO;
import com.jeeplus.test.wdt.merchantCompany.service.dto.MerchantProductDTO;
import com.jeeplus.test.wdt.merchantCompany.service.mapstuct.CompanyTypeWrapper;
import com.jeeplus.test.wdt.merchantCompany.service.mapstuct.MerchantProductWrapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 入驻公司类型Service
 * @author 徐滕
 * @version 2024-01-04 15:18
 */
@Service
@Transactional
public class CompanyTypeService extends ServiceImpl <CompanyTypeMapper, CompanyType> {

    /**
     * 自定义分页检索
     * @param page
     * @param companyTypeDTO
     * @return
     */
    public IPage<CompanyTypeDTO> findPage(Page<CompanyTypeDTO> page, CompanyTypeDTO companyTypeDTO) throws Exception {
        QueryWrapper<CompanyType> queryWrapper = QueryWrapperGenerator.buildQueryCondition ( CompanyTypeWrapper.INSTANCE.toEntity(companyTypeDTO), CompanyType.class );
        queryWrapper.eq ("a.del_flag", 0 ); // 排除已经删除
        queryWrapper.orderByAsc("a.sort");
        if(StringUtils.isNotBlank(companyTypeDTO.getName())){
            queryWrapper.like("a.name",companyTypeDTO.getName());
        }
        return  baseMapper.findList (page, queryWrapper);
    }

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



    /**
     * 自定义分页检索
     * @param companyTypeDTO
     * @return
     */
    public List<CompanyTypeDTO> getListJson(CompanyTypeDTO companyTypeDTO) throws Exception {
        QueryWrapper<CompanyType> queryWrapper = QueryWrapperGenerator.buildQueryCondition ( CompanyTypeWrapper.INSTANCE.toEntity(companyTypeDTO), CompanyType.class );

        queryWrapper.eq ("a.del_flag", 0 ); // 排除已经删除
        queryWrapper.orderByDesc("a.name");
        return  baseMapper.getListJson (queryWrapper);
    }


}
