package com.jy.business.corporation.dao;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jy.business.corporation.mapper.CorporationShopMapper;
import com.jy.business.corporation.model.dto.CorporationShopSelectDto;
import com.jy.business.corporation.model.entity.CorporationShop;
import com.jy.business.corporation.model.table.CorporationShopTable;
import com.jy.business.corporation.model.table.CorporationTable;
import com.jy.business.corporation.model.vo.CorporationShopVo;
import com.jy.framework.model.base.BaseDao;
import com.jy.system.service.AuthService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

@Service
public class CorporationShopDao extends BaseDao<CorporationShopMapper, CorporationShop> {

    @Resource
    private AuthService authService;

    /**
     * 商铺信息分页
     */
    public Page<CorporationShopVo> getPage(CorporationShopSelectDto dto) {
        CorporationShopTable cs = CorporationShopTable.cs;
        CorporationTable c = CorporationTable.c;

        return sql(CorporationShopVo.class)
                .select(
                        cs.all,
                        c.name.as(CorporationShopVo::getCorporationName)
                )
                .from(cs)
                .leftJoin(c).on(c.id.eq(cs.corporationId))
                .where(
                        cs.createUser.in(authService.getUserPermissionSet())
                )
                .orderBy(
                        cs.id.desc()
                )
                .page(dto.getPage());
    }

    /**
     * 商铺信息明细
     */
    public CorporationShopVo getDetail(Long id) {
        CorporationShopTable cs = CorporationShopTable.cs;
        CorporationTable c = CorporationTable.c;

        return sql(CorporationShopVo.class)
                .select(
                        cs.all,
                        c.name.as(CorporationShopVo::getCorporationName)
                )
                .from(cs)
                .leftJoin(c).on(c.id.eq(cs.corporationId))
                .where(
                        cs.id.eq(id)
                )
                .one();
    }

}
