package vip.xiaonuo.write.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import vip.xiaonuo.common.pojo.CommonResult;
import vip.xiaonuo.write.entity.WriteList;
import vip.xiaonuo.write.mapper.WriteListMapper;
import vip.xiaonuo.write.param.WriteListPageParam;
import vip.xiaonuo.write.service.IWriteListService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 检验记录列表 服务实现类
 * </p>
 *
 * @author author
 * @since 2025-01-07
 */
@Service
public class WriteListServiceImpl extends ServiceImpl<WriteListMapper, WriteList> implements IWriteListService {

    @Autowired
    private WriteListMapper listMapper;

    @Override
    public CommonResult page(WriteListPageParam listPageParam) {
        Integer type = listPageParam.getType();
        Page<WriteList> page = new Page<>(listPageParam.getPageNum(), listPageParam.getPageSize());
        QueryWrapper<WriteList> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(listPageParam.getOrgId()), "org_id", listPageParam.getOrgId())
                .eq(StringUtils.isNotBlank(String.valueOf(type)), "type", type);
        if (null != type) {
            queryWrapper.eq("type", type);
        }
        return CommonResult.data(listMapper.selectPage(page, queryWrapper));
    }
}
