package com.heyu.api.controller.vv;


import com.heyu.api.alibaba.request.mm.VvAppLogisticsRequest;
import com.heyu.api.common.annotation.AppRealyLogin;
import com.heyu.api.common.annotation.Describe;
import com.heyu.api.data.dao.vv.VvTradeOrderLineDao;
import com.heyu.api.data.dto.vv.KuaiDi100DTO;
import com.heyu.api.data.entity.vv.VvTradeOrderLineEntity;
import com.heyu.api.data.enums.RoleEnums;
import com.heyu.api.data.service.vv.VvPackageService;
import com.heyu.api.data.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/app/logistics")
public class AppLogisticsController {

    @Autowired
    private VvTradeOrderLineDao vvTradeOrderLineDao;

    @Autowired
    private VvPackageService vvPackageService;

    // http://localhost:8888/app/logistics/query
    @Describe("物流查询")
    @RequestMapping("/query")
    @AppRealyLogin
    public R query(@RequestBody VvAppLogisticsRequest request) {
        List<VvTradeOrderLineEntity> vvTradeOrderLineEntity = vvTradeOrderLineDao.selectVvTradeOrderLineByBuyerIdTrackNumber(request.getBuyerId(), request.getTrackNumber());
        if (CollectionUtils.isEmpty(vvTradeOrderLineEntity)) {
            return R.error("trackNumber不是你的");
        }
        KuaiDi100DTO kuaiDi100DTO = vvPackageService.selectVvKuaidiAndUpdateData(request.getTrackNumber(), RoleEnums.user.getRole(), true);
        return R.ok().setData(kuaiDi100DTO);
    }

}
