package org.dromara.erp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.erp.domain.ErpColorKind;
import org.dromara.erp.domain.query.ErpColorKindQuery;
import org.dromara.erp.domain.vo.ErpColorKindVo;
import org.dromara.erp.mapper.ErpColorKindMapper;
import org.dromara.erp.service.IErpColorKindService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * ERP 颜色种类 Service 业务层处理
 *
 * @Author: Antigravity
 */
@RequiredArgsConstructor
@Service
public class ErpColorKindServiceImpl implements IErpColorKindService {

    private final ErpColorKindMapper baseMapper;

    @Override
    public TableDataInfo<ErpColorKindVo> queryPageList(ErpColorKindQuery query, PageQuery pageQuery) {
        LambdaQueryWrapper<ErpColorKind> lqw = buildQueryWrapper(query);
        IPage<ErpColorKindVo> page = baseMapper.selectVoPage(pageQuery.build(), lqw);
        return TableDataInfo.build(page);
    }

    private LambdaQueryWrapper<ErpColorKind> buildQueryWrapper(ErpColorKindQuery query) {
        LambdaQueryWrapper<ErpColorKind> lqw = Wrappers.lambdaQuery();
        lqw.eq(ErpColorKind::getStopUse, 0);
        lqw.orderByAsc(ErpColorKind::getNum);
        return lqw;
    }

    @Override
    public List<ErpColorKindVo> queryList() {
        return baseMapper.selectVoList(Wrappers.lambdaQuery(ErpColorKind.class)
            .eq(ErpColorKind::getStopUse, 0)
            .orderByAsc(ErpColorKind::getNum));
    }

}
