package com.gree.mall.miniapp.logic.common.outside;

import cn.hutool.core.lang.TypeReference;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;
import com.gree.mall.miniapp.bean.user.CurrentCompanyWechat;
import com.gree.mall.miniapp.bean.workorder.OrderAddBeanDTO;
import com.gree.mall.miniapp.helper.ResponseHelper;
import com.gree.mall.miniapp.utils.HttpUtils;
import lombok.extern.slf4j.Slf4j;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class WorkOrderApiLogic extends OutsideBaseApi{

    /**
     * 创建工单
     * @param orderAddBeanDTO
     * @return
     */
    public void createOrder(OrderAddBeanDTO orderAddBeanDTO){

        if(StringUtils.isBlank(orderAddBeanDTO.getCompanyWechatId())) {
            CurrentCompanyWechat currentCompanyWechat = commonLogic.getCurrentCompanyWechat();
            orderAddBeanDTO.setCompanyWechatId(currentCompanyWechat.getCompanyWechatId());
            orderAddBeanDTO.setCompanyWechatName(currentCompanyWechat.getCurrentCompanyName());
            orderAddBeanDTO.setUserId(currentCompanyWechat.getUserId());
        }

        String s = HttpUtils.requestPostBody(pcUrl + "/order/base/save2", JSONObject.toJSONString(orderAddBeanDTO), getHeader());
        ResponseHelper result = JSONUtil.toBean(s, new TypeReference<ResponseHelper>() {
        }, false);

        checkData(result);
    }

}
