package com.ruoyi.web.v2.v1.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.web.v2.v1.model.JsProduceCheck;
import com.ruoyi.web.v2.v1.mapper.JsProduceCheckMapper;
import com.ruoyi.web.v2.v1.service.IJsProduceCheckService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import static com.ruoyi.common.core.domain.AjaxResult.success;

/**
 * <p>
 * v2.0生产检验检疫登记 服务实现类
 * </p>
 *
 * @author author
 * @since 2025-05-23
 */
@Service
public class JsProduceCheckServiceImpl extends ServiceImpl<JsProduceCheckMapper, JsProduceCheck> implements IJsProduceCheckService {

    @Autowired
    private JsProduceCheckMapper produceCheckMapper;

    @Override
    public AjaxResult add(JsProduceCheck produceCheck) {
        produceCheckMapper.insert(produceCheck);
        return success();
    }

    @Override
    public AjaxResult edit(JsProduceCheck produceCheck) {
        produceCheckMapper.updateById(produceCheck);
        return success();
    }

    @Override
    public AjaxResult delete(String ids) {
        String[] split = ids.split(",");
        for (String s : split) {
            produceCheckMapper.deleteById(s);
        }
        return success();
    }

    @Override
    public AjaxResult page(Integer pageNum, Integer pageSize, String startTime, String endTime, String animalCertNo ,String animalType) {
        Page<JsProduceCheck> page = new Page<>(pageNum, pageSize);
        QueryWrapper<JsProduceCheck> queryWrapper = new QueryWrapper<>();
        if ("".equals(startTime) || null == startTime) {

        } else {
            queryWrapper.between("check_time", startTime+" 00:00:00", endTime+" 23:59:59");
        }
        queryWrapper.orderByDesc("check_time");
        queryWrapper.eq(StringUtils.isNotEmpty(animalType),"animal_type",  animalType);
        queryWrapper.like(StringUtils.isNotEmpty(animalCertNo),"animal_cert_no", animalCertNo);
        return success(produceCheckMapper.selectPage(page, queryWrapper));
    }

    @Override
    public AjaxResult listAll() {
        return success(produceCheckMapper.selectList(null));
    }
}
