package com.heyu.api.controller.mm;


import com.heyu.api.alibaba.request.mm.order.resp.VvAdminLogisticsCompanyRequest;
import com.heyu.api.alibaba.request.mm.order.resp.VvAdminLogisticsRequest;
import com.heyu.api.common.annotation.Describe;
import com.heyu.api.data.dto.vv.KuaiDi100DTO;
import com.heyu.api.data.dto.vv.KuaiDi100VO;
import com.heyu.api.data.enums.RoleEnums;
import com.heyu.api.data.kuaidi100.LogisticsMapUtils;
import com.heyu.api.data.service.vv.VvPackageService;
import com.heyu.api.data.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/mm/logistics")
public class AdminLogisticsController {


    @Autowired
    private VvPackageService vvPackageService;

    // http://localhost:8888/mm/logistics/query
    @Describe("后台物流查询")
    @RequestMapping("/query")
    public R query(@RequestBody VvAdminLogisticsRequest request) {
        KuaiDi100DTO kuaiDi100DTO = vvPackageService.selectVvKuaidiAndUpdateData(request.getTrackNumber(), RoleEnums.admin.getRole(), false);
        KuaiDi100VO kuaiDi100VO = new KuaiDi100VO();
        BeanUtils.copyProperties(kuaiDi100DTO, kuaiDi100VO);

        String logisticsCompany = LogisticsMapUtils.getLogisticsCompanyName(kuaiDi100DTO.getCom());
        kuaiDi100VO.setLogisticsCompany(logisticsCompany);
        return R.ok().setData(kuaiDi100VO);
    }


    // http://localhost:8888/mm/logistics/companyList
    @Describe("物流公司")
    @RequestMapping("/companyList")
    public R companyList(@RequestBody VvAdminLogisticsCompanyRequest request) {
        return R.ok().setData(LogisticsMapUtils.logisticsMap);
    }


}
