package vip.xiaonuo.quality.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import vip.xiaonuo.quality.entity.QualityTarget;
import vip.xiaonuo.quality.mapper.QualityTargetMapper;
import vip.xiaonuo.quality.param.QualityParam;
import vip.xiaonuo.quality.service.IQualityTargetService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 质量管控指标 服务实现类
 * </p>
 *
 * @author author
 * @since 2024-12-11
 */
@Service
public class QualityTargetServiceImpl extends ServiceImpl<QualityTargetMapper, QualityTarget> implements IQualityTargetService {

    @Autowired
    private QualityTargetMapper targetMapper;

    @Override
    public QualityTarget getTargetOne(QualityParam qualityParam) {
        String orgId = qualityParam.getOrgId();
        QueryWrapper<QualityTarget> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(orgId), "org_id", orgId);
        queryWrapper.orderByDesc("id").last(" limit 1");
        QualityTarget qualityTarget = targetMapper.selectOne(queryWrapper);
        return qualityTarget;
    }
}
