package com.wms_main.service.controller.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wms_main.dao.ITAppJobsService;
import com.wms_main.model.dto.query.EquipmentQuery;
import com.wms_main.model.dto.query.JobQuery;
import com.wms_main.model.dto.response.wms.WmsApiResponse;
import com.wms_main.model.po.TAppEquipment;
import com.wms_main.model.po.TAppJobs;
import com.wms_main.model.vo.wms.EquipmentVo;
import com.wms_main.model.vo.wms.JobVo;
import com.wms_main.model.vo.wms.PageVo;
import com.wms_main.repository.utils.StringUtils;
import com.wms_main.service.controller.IJobControllerService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
@Slf4j
public class JobControllerServiceImpl implements IJobControllerService {
    private final ITAppJobsService jobsService;

    @Override
    public WmsApiResponse<PageVo<JobVo>> queryJobInfoByPage(JobQuery jobQuery) {
        if (jobQuery == null) {
            return WmsApiResponse.error("查询参数不能为NULL", null);
        }
        Page<TAppJobs> page = jobQuery.toMpPage();
        LambdaQueryWrapper<TAppJobs> lambdaQueryWrapper = new LambdaQueryWrapper<TAppJobs>()
                .like(StringUtils.isNotEmpty(jobQuery.getJobName()), TAppJobs::getJobName, jobQuery.getJobName())
                .like(StringUtils.isNotEmpty(jobQuery.getJobClass()), TAppJobs::getJobClass, jobQuery.getJobClass())
                .like(StringUtils.isNotEmpty(jobQuery.getCronExpression()), TAppJobs::getCronExpression, jobQuery.getCronExpression())
                .eq(jobQuery.getTimer() != null, TAppJobs::getTimer, jobQuery.getTimer())
                .eq(jobQuery.getTimerType() != null, TAppJobs::getTimerType, jobQuery.getTimerType())
                .eq(jobQuery.getJobStatus() != null, TAppJobs::getJobStatus, jobQuery.getJobStatus());
        Page<TAppJobs> poPage = jobsService.page(page, lambdaQueryWrapper);

        PageVo<JobVo> pageVo = PageVo.of(poPage, JobVo::of);
        return WmsApiResponse.success("查询定时任务成功", pageVo);
    }
}
