package com.gxwebsoft.clinic.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.clinic.entity.ClinicMedicineInout;
import com.gxwebsoft.clinic.mapper.ClinicMedicineInoutMapper;
import com.gxwebsoft.clinic.param.ClinicMedicineInoutParam;
import com.gxwebsoft.clinic.service.ClinicMedicineInoutService;
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 ClinicMedicineInoutServiceImpl extends ServiceImpl<ClinicMedicineInoutMapper, ClinicMedicineInout> implements ClinicMedicineInoutService {

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

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

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

}
