package com.wms_main.service.controller.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wms_main.dao.impl.TAppOutsServiceImpl;
import com.wms_main.dao.impl.TAppPickTaskServiceImpl;
import com.wms_main.dao.impl.TAppTaskServiceImpl;
import com.wms_main.model.po.TAppOuts;
import com.wms_main.model.po.TAppPickTask;
import com.wms_main.service.controller.IDataControllerService;
import com.wms_main.model.po.TAppTask;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 数据控制器服务实现类
 */
@Service
@RequiredArgsConstructor
public class DataControllerServiceImpl implements IDataControllerService {

    private final TAppTaskServiceImpl tAppTaskService;
    private final TAppOutsServiceImpl tAppOutsService;
    private final TAppPickTaskServiceImpl tAppPickTaskService;

    /**
     * 获取任务类型为1的任务数据
     * @return 任务类型为1的任务列表
     */
    @Override
    public List<TAppTask> getTaskTypInData(int pageNum, int pageSize, int standId) {
        LambdaQueryWrapper<TAppTask> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(TAppTask::getTaskType, 1);

        // 如果 standId 等于 1，则筛选终点以 "A1" 或 "A2" 开头的数据
        if (standId == 1) {
            queryWrapper.and(wrapper -> wrapper.likeRight(TAppTask::getDestination, "A1")
                    .or()
                    .likeRight(TAppTask::getDestination, "A2"));
        }else if (standId == 2){
            queryWrapper.and(wrapper -> wrapper.likeRight(TAppTask::getDestination, "A3")
                    .or()
                    .likeRight(TAppTask::getDestination, "A4"));
        } else if (standId == 3) {
            queryWrapper.and(wrapper -> wrapper.likeRight(TAppTask::getDestination, "A5")
                    .or()
                    .likeRight(TAppTask::getDestination, "A6"));
        }

        return tAppTaskService.page(new Page<>(pageNum, pageSize), queryWrapper).getRecords();
    }


    /**
     * 获取出库数据
     * @return 出库数据列表
     */
    @Override
    public List<TAppOuts> getOutsData(int pageNum, int pageSize) {
        LambdaQueryWrapper<TAppOuts> queryWrapper = new LambdaQueryWrapper<>();
        return tAppOutsService.page(new Page<>(pageNum, pageSize), queryWrapper).getRecords();
    }

    /**
     * 获取拣选任务数据
     * @return 拣选任务数据列表
     */
    @Override
    public List<TAppPickTask> getPickTaskDataP1(int pageNum, int pageSize) {
        LambdaQueryWrapper<TAppPickTask> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(TAppPickTask::getPickStand, "P11", "P12", "P13")
                .orderByDesc(TAppPickTask::getPickStatus);
        return tAppPickTaskService.page(new Page<>(pageNum, pageSize), queryWrapper).getRecords();
    }

    @Override
    public List<TAppPickTask> getPickTaskDataP2(int pageNum, int pageSize) {
        LambdaQueryWrapper<TAppPickTask> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(TAppPickTask::getPickStand, "P14", "P15", "P16")
                .orderByDesc(TAppPickTask::getPickStatus);
        return tAppPickTaskService.page(new Page<>(pageNum, pageSize), queryWrapper).getRecords();
    }

    @Override
    public List<TAppPickTask> getPickTaskDataP3(int pageNum, int pageSize) {
        LambdaQueryWrapper<TAppPickTask> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(TAppPickTask::getPickStand, "P17", "P18", "P19")
                .orderByDesc(TAppPickTask::getPickStatus);;
        return tAppPickTaskService.page(new Page<>(pageNum, pageSize), queryWrapper).getRecords();
    }
}
