package vip.xiaonuo.production.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.production.entity.ProductionCheck;
import vip.xiaonuo.production.mapper.ProductionCheckMapper;
import vip.xiaonuo.production.param.ProductionCheckParam;
import vip.xiaonuo.production.service.IProductionCheckService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 生成管控产品检测 服务实现类
 * </p>
 *
 * @author author
 * @since 2024-12-12
 */
@Service
public class ProductionCheckServiceImpl extends ServiceImpl<ProductionCheckMapper, ProductionCheck> implements IProductionCheckService {

    @Autowired
    private ProductionCheckMapper checkMapper;

    @Override
    public Page<ProductionCheck> getList(ProductionCheckParam checkParam) {
        String orgId = checkParam.getOrgId();
        String locationName = checkParam.getLocationName();
        String time = checkParam.getTime();
        String produceName = checkParam.getProduceName();
        QueryWrapper<ProductionCheck> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(orgId), "org_id", orgId)
                .eq(StringUtils.isNotBlank(locationName), "location_name", locationName)
                .eq(StringUtils.isNotBlank(produceName), "material", produceName);
        if (StringUtils.isNotBlank(time)) {
            queryWrapper.between("create_time", time + "-01 00:00:00", time + "-31 23:59:59");
        }
        Page<ProductionCheck> page = new Page(checkParam.getPageNum(), checkParam.getPageSize());
        return checkMapper.selectPage(page, queryWrapper);
    }
}
