package com.gxwebsoft.oa.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.oa.mapper.OaProductMapper;
import com.gxwebsoft.oa.service.OaProductService;
import com.gxwebsoft.oa.entity.OaProduct;
import com.gxwebsoft.oa.param.OaProductParam;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 产品记录表Service实现
 *
 * @author 科技小王子
 * @since 2024-09-10 20:57:42
 */
@Service
public class OaProductServiceImpl extends ServiceImpl<OaProductMapper, OaProduct> implements OaProductService {

    @Override
    public PageResult<OaProduct> pageRel(OaProductParam param) {
        PageParam<OaProduct, OaProductParam> page = new PageParam<>(param);
        page.setDefaultOrder("create_time desc");
        List<OaProduct> list = baseMapper.selectPageRel(page, param);
        return new PageResult<>(list, page.getTotal());
    }

    @Override
    public List<OaProduct> listRel(OaProductParam param) {
        List<OaProduct> list = baseMapper.selectListRel(param);
        // 排序
        PageParam<OaProduct, OaProductParam> page = new PageParam<>();
        page.setDefaultOrder("create_time desc");
        return page.sortRecords(list);
    }

    @Override
    public OaProduct getByIdRel(Integer productId) {
        OaProductParam param = new OaProductParam();
        param.setProductId(productId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
