package org.ta.pddserver.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.ta.pddserver.entity.LogOrderEntity;
import org.ta.pddserver.mapper.LogOrderMapper;
import org.ta.pddserver.model.api.request.LogOrderListRequest;
import org.ta.pddserver.model.api.response.LogOrderListResponse;
import org.ta.pddserver.service.LogOrderService;

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

@Service
public class LogOrderImpl extends ServiceImpl<LogOrderMapper, LogOrderEntity> implements LogOrderService {

    public Boolean savePackageQuantity(String logisticsOrderCode, Long packageQuantity) {

       Boolean result =  baseMapper.savePackageQuantity(logisticsOrderCode, packageQuantity);

       return result;
    }

    public LogOrderEntity getByOrderCode(String orderCode) {
        return baseMapper.selectByOrderCode(orderCode);
    }

    public int updateOrderStatus(int status, String uid) {
        return baseMapper.updateOrderStatusById(status, uid);
    }


    public Map<String, Object> getListByRequest(LogOrderListRequest param) {
        Integer count = baseMapper.countUsable(param);
        param.checkPage(count,20);
        List<LogOrderListResponse> list = baseMapper.getListByRequest(param);
        Map<String, Object> map = new HashMap<>();
        map.put("total", count);
        map.put("list", list);
        map.put("page", param.getPage());
        return map;
    }


}