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

import com.cpop.core.base.entity.PageDomain;
import com.cpop.core.utils.sql.SqlUtils;
import com.cpop.jambox.business.entity.website.CooperationType;
import com.cpop.jambox.business.service.CooperationTypeService;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.cpop.jambox.business.entity.website.Cooperation;
import com.cpop.jambox.business.mapper.CooperationMapper;
import com.cpop.jambox.business.service.CooperationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 果酱模块化官网 合作平台表 服务层实现。
 *
 * @author Yxz
 * @since 2024-01-19
 */
@Service("cooperationService")
public class CooperationServiceImpl extends ServiceImpl<CooperationMapper, Cooperation> implements CooperationService {
    @Autowired
    private CooperationTypeService cooperationTypeService;

    /**
     * 查询所有果酱模块化官网 合作平台表
     *
     * @author: Yxz
     * @date: 2024/1/21 14:27
     * @param: []
     * @return: java.util.List<com.cpop.jambox.business.entity.website.Cooperation>
     **/
    @Override
    public List<Cooperation> selectTypeNameList() {
        List<Cooperation> cooperationList = this.mapper.selectAll();
        // 设置种类名称
        cooperationList.forEach(item -> {
            CooperationType cooperationType = cooperationTypeService.getById(item.getTypeId());
            item.setTypeName(cooperationType.getTypeName());
        });
        return cooperationList;
    }

    /**
     * 分页查询果酱模块化官网 合作平台表
     *
     * @author: Yxz
     * @date: 2024/1/21 15:39
     * @param: [typeId]
     * @return: com.mybatisflex.core.paginate.Page<com.cpop.jambox.business.entity.website.Cooperation>
     **/
    @Override
    public Page<Cooperation> getPage(String typeId) {
        PageDomain pageDomain = SqlUtils.getInstance().getPageDomain();
        Page<Cooperation> cooperationPage = this.mapper.paginate(Page.of(pageDomain.getPageNum(), pageDomain.getPageSize()), QueryWrapper.create().eq("type_id", typeId));
        return cooperationPage;
    }
}
