package org.ta.pddserver.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.ta.pdd.entity.StorageEntity;
import org.ta.pddserver.mapper.StorageMapper;
import org.ta.pddserver.model.api.request.LogOrderMailDetailListRequest;
import org.ta.pddserver.model.api.request.StorageListRequest;
import org.ta.pddserver.model.api.request.StorageListVORequest;
import org.ta.pddserver.model.api.request.UnpackNoticeListRequest;
import org.ta.pddserver.model.api.response.LogOrderMailDetailListResponse;
import org.ta.pddserver.model.api.response.StorageListResponse;
import org.ta.pddserver.model.api.response.StorageResponse;
import org.ta.pddserver.model.api.response.UnpackNoticeListResponse;
import org.ta.pddserver.service.StorageService;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service
public class StorageImpl extends ServiceImpl<StorageMapper, StorageEntity> implements StorageService {


    public StorageEntity getInfoByLogisticsOrderCode(String logisticsOrderCode) {
        return baseMapper.getInfoByLogisticsOrderCode(logisticsOrderCode);
    }

    public StorageEntity getInfoByMailNo(String mailNo) {
        return baseMapper.getInfoByMailNo(mailNo);
    }

    public int findCountByLogisticsOrderCode(String logisticsOrderCode) {
        return baseMapper.findCountByLogisticsOrderCode(logisticsOrderCode);
    }

    public void updateNumByLogisticsOrderCode(String logisticsOrderCode) {
        baseMapper.updateNumByLogisticsOrderCode(logisticsOrderCode);
    }

    public int findAllCount(String code) {
        return baseMapper.findAllCount(code);
    }

    public Integer findReNumCount(String code) {
        return baseMapper.findReNumCount(code);
    }

    public StorageResponse storageSelect(String mailNo) {
        return baseMapper.storageSelect(mailNo);
    }

    public Map<String, Object> storageList(String logisticsOrderCode) {

        Map<String, Object> map = new HashMap<>();

        List<StorageListResponse> list = baseMapper.storageUnpackList(logisticsOrderCode);

        map.put("type", "unpack");

        if (list == null || list.isEmpty()) {
            list = baseMapper.storageCollectList(logisticsOrderCode);

            map.put("type", "collect");
        }

        map.put("list", list);

        return map;
    }

    public List<StorageListResponse> storageLists(String logisticsOrderCode) {


        List<StorageListResponse> list = baseMapper.storageUnpackList(logisticsOrderCode);


        if (list == null || list.isEmpty()) {
            list = baseMapper.storageCollectList(logisticsOrderCode);

        }


        return list;
    }

    public void storageDel(String ids) {
        baseMapper.storageDel(ids);
    }

    public StorageEntity getByBuyerCode(String buyerCode) {
        return this.baseMapper.selectByBuyerCode(buyerCode);
    }

    public Long countOned() {
        return this.baseMapper.countOned();
    }

    public Map<String, Object> notListedStorageList(StorageListVORequest param) {
        List<StorageEntity> list = baseMapper.notListedStorageList(param);
        Map<String, Object> map = new HashMap<>();
        map.put("list", list);
        return map;
    }

    public Map<String, Object> storageListPage(StorageListVORequest param) {
        Integer count = baseMapper.countUsableStorageListPage(param);
        param.checkPage(count,20);
        List<StorageEntity> list = baseMapper.getStorageListPage(param);
        Map<String, Object> map = new HashMap<>();
        map.put("total", count);
        map.put("list", list);
        map.put("page", param.getPage());
        return map;
    }

    public List<StorageEntity> getListByPlace(String place) {
        return this.baseMapper.findListByPlace(place);
    }
}