package com.sunda.spmsoversea.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.sunda.spmsoversea.entity.OverseaWhsOutDtl;
import com.sunda.spmsoversea.mapper.OverseaWhsOutDtlMapper;
import com.sunda.spmsoversea.service.IOverseaWhsOutDtlService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 出库任务表明细 服务实现类
 * </p>
 *
 * @author Wayne
 * @since 2021-09-22
 */
@Service
public class OverseaWhsOutDtlServiceImpl extends ServiceImpl<OverseaWhsOutDtlMapper, OverseaWhsOutDtl> implements IOverseaWhsOutDtlService {

    @Override
    public List<OverseaWhsOutDtl> getOverseaWhsOutDtlList(String uuidWhsOut) {
        if (StringUtils.isEmpty(uuidWhsOut)){
            return null;
        }
        return this.baseMapper.selectList(new QueryWrapper<OverseaWhsOutDtl>().eq("UUID_WHS_OUT", uuidWhsOut));
    }

    @Override
    public int createOverseaWhsOutDtl(OverseaWhsOutDtl overseaWhsOutDtl) {
        if (overseaWhsOutDtl == null){
            return 0;
        }
        return this.baseMapper.insert(overseaWhsOutDtl);
    }

    @Override
    public List<Map<String, Object>> getOverseaWhsOutDtlListMap(String uuidWhsOut) {
        if (StringUtils.isEmpty(uuidWhsOut)){
            return null;
        }
        return this.baseMapper.getOverseaWhsOutDtlListMap(uuidWhsOut);
    }

    @Override
    public OverseaWhsOutDtl getWhsOutDtl(String uuidWhsOut, Integer item) {
        if (StringUtils.isEmpty(uuidWhsOut) || item == null){
            return null;
        }
        return this.baseMapper.selectOne(new QueryWrapper<OverseaWhsOutDtl>().eq("UUID_WHS_OUT", uuidWhsOut).eq("ITEM", item));
    }

    @Override
    public int updateWhsOutDtl(OverseaWhsOutDtl overseaWhsOutDtl) {
        if (overseaWhsOutDtl == null){
            return 0;
        }
        String uuidWhsOut = overseaWhsOutDtl.getUuidWhsOut();
        Integer item = overseaWhsOutDtl.getItem();
        if (StringUtils.isEmpty(uuidWhsOut) || item == null){
            return 0;
        }
        return this.baseMapper.update(overseaWhsOutDtl, new QueryWrapper<OverseaWhsOutDtl>().eq("UUID_WHS_OUT", uuidWhsOut).eq("ITEM", item));
    }
}
