package com.gxwebsoft.clinic.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.clinic.entity.ClinicMedicineStock;
import com.gxwebsoft.clinic.mapper.ClinicMedicineStockMapper;
import com.gxwebsoft.clinic.param.ClinicMedicineStockParam;
import com.gxwebsoft.clinic.service.ClinicMedicineStockService;
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 2025-10-22 02:06:32
 */
@Service
public class ClinicMedicineStockServiceImpl extends ServiceImpl<ClinicMedicineStockMapper, ClinicMedicineStock> implements ClinicMedicineStockService {

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

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

    @Override
    public ClinicMedicineStock getByIdRel(Integer id) {
        ClinicMedicineStockParam param = new ClinicMedicineStockParam();
        param.setId(id);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
