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

import com.cpop.common.utils.bean.BeanUtils;
import com.cpop.core.base.entity.PageDomain;
import com.cpop.core.utils.sql.SqlUtils;
import com.cpop.jambox.business.bo.PlugBo;
import com.cpop.jambox.business.vo.PlugPageVo;
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.Plug;
import com.cpop.jambox.business.mapper.PlugMapper;
import com.cpop.jambox.business.service.PlugService;
import org.springframework.stereotype.Service;

import static com.cpop.jambox.business.entity.table.PlugTableDef.PLUG;

/**
 * 果酱-插件 服务层实现。
 *
 * @author DB
 * @since 2024-01-05
 */
@Service("plugService")
public class PlugServiceImpl extends ServiceImpl<PlugMapper, Plug> implements PlugService {

    /**
     * 查询插件分页
     * @author DB
     * @since 2024/1/5
     * @return R<Page<PlugPageVo>>
     */
    @Override
    public Page<PlugPageVo> getPlugPage() {
        PageDomain pageDomain = SqlUtils.getInstance().getPageDomain();
        return this.pageAs(Page.of(pageDomain.getPageNum(), pageDomain.getPageSize()),
                QueryWrapper.create()
                        .select(PLUG.ID, PLUG.NAME, PLUG.ORDER_NO, PLUG.STATUS, PLUG.PLUG_TAG, PLUG.REMARK)
                        .orderBy(PLUG.ORDER_NO.desc()),
                PlugPageVo.class);
    }

    /**
     * 新增插件
     * @author DB
     * @since 2024/1/5
     * @param bo 请求参数
     */
    @Override
    public void insertPlug(PlugBo bo) {
        Plug plug = BeanUtils.mapToClass(bo, Plug.class);
        this.save(plug);
    }

    @Override
    public void updatePlug(PlugBo bo) {
        Plug plug = BeanUtils.mapToClass(bo, Plug.class);
        this.updateById(plug);
    }
}
