package com.gxwebsoft.clinic.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.clinic.entity.ClinicMedicine;
import com.gxwebsoft.clinic.mapper.ClinicMedicineMapper;
import com.gxwebsoft.clinic.param.ClinicMedicineParam;
import com.gxwebsoft.clinic.service.ClinicMedicineService;
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:31
 */
@Service
public class ClinicMedicineServiceImpl extends ServiceImpl<ClinicMedicineMapper, ClinicMedicine> implements ClinicMedicineService {

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

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

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

}
