package com.unis.purchaseAndSalesSupervision.modular.storageTaskSupervise.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.unis.purchaseAndSalesSupervision.modular.storageTaskSupervise.entity.StorageFumigationTask;
import com.unis.purchaseAndSalesSupervision.modular.storageTaskSupervise.entity.StorageTaskSupervise;
import com.unis.purchaseAndSalesSupervision.modular.storageTaskSupervise.entity.StorageVentilationOperation;
import com.unis.purchaseAndSalesSupervision.modular.storageTaskSupervise.mapper.StorageTaskSuperviseMapper;
import com.unis.purchaseAndSalesSupervision.modular.storageTaskSupervise.param.StorageTaskSuperviseObject;
import com.unis.purchaseAndSalesSupervision.modular.storageTaskSupervise.param.StorageTaskSupervisePage;
import com.unis.purchaseAndSalesSupervision.modular.storageTaskSupervise.service.StorageTaskSuperviseService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author qingsong.han
 * @description:
 * @create 2024-06-15 15:59
 */
@Service
public class StorageTaskSuperviseServiceImpl extends ServiceImpl<StorageTaskSuperviseMapper, StorageTaskSupervise> implements StorageTaskSuperviseService {
    @Resource
    private StorageTaskSuperviseMapper storageTaskSuperviseMapper;

    @Override
    public IPage<StorageTaskSupervise> getPageList(StorageTaskSupervisePage param) {
        return storageTaskSuperviseMapper.getPageList(new Page<>(param.getCurrent(), param.getSize()), param.getOrgName());
    }

    @Override
    public StorageTaskSuperviseObject detail(String id, String zylx) {
        StorageTaskSuperviseObject object = new StorageTaskSuperviseObject();
        if ("通风".equals(zylx)) {
            StorageVentilationOperation ventilationOperation = storageTaskSuperviseMapper.getByIdTF(id);
            if (ObjectUtils.isNotEmpty(ventilationOperation)) {
                object.setVentilationOperation(ventilationOperation);
            }
        }
        if ("熏蒸".equals(zylx)) {
            StorageFumigationTask fumigationTask = storageTaskSuperviseMapper.getByIdXZ(id);
            if (ObjectUtils.isNotEmpty(fumigationTask)) {
                object.setFumigationTask(fumigationTask);
            }
        }
        return object;
    }
}
