package com.gxwebsoft.clinic.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.clinic.entity.ClinicPrescriptionItem;
import com.gxwebsoft.clinic.mapper.ClinicPrescriptionItemMapper;
import com.gxwebsoft.clinic.param.ClinicPrescriptionItemParam;
import com.gxwebsoft.clinic.service.ClinicPrescriptionItemService;
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:01:13
 */
@Service
public class ClinicPrescriptionItemServiceImpl extends ServiceImpl<ClinicPrescriptionItemMapper, ClinicPrescriptionItem> implements ClinicPrescriptionItemService {

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

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

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

}
