package cn.quantgroup.customer.service.impl;

import static cn.quantgroup.customer.constant.Constant.GSON;

import cn.quantgroup.customer.enums.ErrorCodeEnum;
import cn.quantgroup.customer.rest.vo.JsonResult;
import cn.quantgroup.customer.rest.vo.thirdworkorder.ThirdWorkOrderExportVo;
import cn.quantgroup.customer.service.IKdspService;
import cn.quantgroup.customer.service.http.IHttpService;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/**
 * @author Wang Xiangwei
 * @version 2020/3/9
 */
@Slf4j
@Service
public class KdspServiceImpl implements IKdspService {


    @Value("${kdsp-operation}")
    private String kdspOperationUrl;

    @Autowired
    private IHttpService httpService;

    @Override
    public JsonResult<List<ThirdWorkOrderExportVo>> getOrderDetailForWorkOder(
        List<String> orderNos,Integer tenantId) {

        String url = kdspOperationUrl+"/api/kdsp/op/order/getOrderDetailForWorkOder";
        JsonResult<List<ThirdWorkOrderExportVo>> jsonResult = null;
        try {
            Map<String,String> header = new HashMap<>();
            header.put("qg-tenant-id",tenantId.toString());
            String result = httpService.post(url, header,orderNos);
            jsonResult = GSON.fromJson(result, JsonResult.class);
            log.info("工单查询订单详情返回值:{}", result);
        } catch (Exception ex) {
            log.error("工单查询订单详情异常",ex);
            return JsonResult.buildErrorStateResult(ErrorCodeEnum.NET_ERROR.getMessage(), null);
        }
        return  jsonResult;
    }
}
