package com.gic.haoban.manage.web.controller.order;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.gic.api.base.commons.ServiceResponse;
import com.gic.business.order.dto.logistics.OrderLogisticsDTO;
import com.gic.business.order.qdto.logistics.QueryLogisticsQDTO;
import com.gic.business.order.service.logistics.LogisticsApiService;
import com.gic.commons.util.EntityUtil;
import com.gic.commons.webapi.reponse.RestResponse;
import com.gic.dict.api.dto.LogisticsCompanyDTO;
import com.gic.dict.api.service.ManagerDictService;
import com.gic.haoban.manage.web.qo.order.QueryLogisticsQO;

/**
 * 物流
 */
@Controller
public class LogisticsController {

    @Autowired
    private LogisticsApiService logisticsApiService;

    @Autowired
    private ManagerDictService managerDictService;

    /**
     * 物流公司列表
     *
     * @return RestResponse
     */
    @ResponseBody
    @RequestMapping("list-logistics")
    public RestResponse<Object> listLogistics() {
        List<LogisticsCompanyDTO> response = managerDictService.getLogisticsCompany();
        return RestResponse.successResult(response);
    }

    /**
     * 查询物流
     *
     * @param queryLogisticsQO 查询物流
     * @return RestResponse
     */
    @ResponseBody
    @RequestMapping("get-logistics")
    public RestResponse<Object> getLogistics(@RequestBody QueryLogisticsQO queryLogisticsQO) {
        QueryLogisticsQDTO qdto = EntityUtil.changeEntityByJSON(QueryLogisticsQDTO.class, queryLogisticsQO);
        ServiceResponse<OrderLogisticsDTO> response = logisticsApiService.queryLogistics(qdto);
        if (response.isSuccess()) {
            return RestResponse.successResult(response.getResult());
        }
        return RestResponse.failure(response.getCode(), response.getMessage());
    }

}
