package org.ta.pddserver.service.impl;


import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.ta.pddserver.entity.StorageEntity;
import org.ta.pddserver.mapper.StorageMapper;
import org.ta.pddserver.model.api.request.StorageListRequest;
import org.ta.pddserver.model.api.response.StorageListResponse;
import org.ta.pddserver.model.api.response.StorageResponse;
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);
    }
}