package com.cpop.system.business.service.impl;

import com.cpop.core.base.entity.PageDomain;
import com.cpop.core.utils.SqlUtils;
import com.cpop.system.business.vo.BrandPageVo;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.cpop.system.business.entity.Brand;
import com.cpop.system.business.mapper.BrandMapper;
import com.cpop.system.business.service.BrandService;
import org.springframework.stereotype.Service;

import static com.cpop.system.business.entity.table.BrandTableDef.BRAND;

/**
 * 系统-品牌表 服务层实现。
 *
 * @author DB
 * @since 2023-10-25
 */
@Service("brandService")
public class BrandServiceImpl extends ServiceImpl<BrandMapper, Brand> implements BrandService {

    /**
     * 查询品牌分页列表
     * @author DB
     * @since 2023/10/25 17:32
     * @param brandName 请求参数
     * @return com.mybatisflex.core.paginate.Page<com.cpop.system.business.vo.BrandPageVo>
     */
    @Override
    public Page<BrandPageVo> getBrandPage(String brandName) {
        PageDomain pageDomain = SqlUtils.getInstance().getPageDomain();
        return this.mapper.paginateAs(pageDomain.getPageNum(), pageDomain.getPageSize(), QueryWrapper.create()
                        .select(BRAND.ID, BRAND.BRAND_NAME, BRAND.WX_MCH_ID, BRAND.CREATE_TIME, BRAND.WX_MCH_ID, BRAND.BRAND_ADDR, BRAND.LICENSE_STATS, BRAND.LICENSE_PIC_URL, BRAND.LICENSE_CREDIT_CODE,
                                BRAND.LICENSE_FIRM_NAME, BRAND.LICENSE_USERNAME, BRAND.LICENSE_ADDR, BRAND.LICENSE_DATE)
                        .and(BRAND.BRAND_NAME.likeLeft(brandName))
                        .orderBy(BRAND.CREATE_TIME.desc()),
                BrandPageVo.class);
    }

}
