package com.yem.or.api;

import com.yem.or.utils.OrderApiUtils;
import kd.bos.openapi.common.custom.annotation.ApiController;
import kd.bos.openapi.common.custom.annotation.ApiParam;
import kd.bos.openapi.common.custom.annotation.ApiPostMapping;
import kd.bos.openapi.common.result.CustomApiResult;
import org.jetbrains.annotations.NotNull;

import java.io.IOException;
import java.util.Map;

/**
 * @author zhouc
 * @date 2024/3/18 14:51
 * @className Clientdemand
 * @description
 */
@ApiController(value = "yem_im", desc = "客户需求单")
public class Clientdemand {
    /**
     * 新增客户需求单接口
     *
     * @param data
     * @return
     * @throws IOException
     */
    @ApiPostMapping("/Clientdemand/create")
    public CustomApiResult<Object> CompleteCallback(@NotNull @ApiParam("参数") String data) throws IOException {
        String msg = "";
        try {
            Map<String, String> ordercreateuser = OrderApiUtils.Ordercreateuser(data, "yem_im_clientdema_pj");
            if (ordercreateuser.size() > 0) {
                String status = (String) ordercreateuser.get("status");
                msg = (String) ordercreateuser.get("msg");
                if (status.equals("error")) {
                    CustomApiResult<Object> fail = CustomApiResult.fail("501", ordercreateuser.get("msg"));
                    return fail;
                }
            } else {
                CustomApiResult<Object> fail = CustomApiResult.fail("501", "调用失败，请联系管理员！");
                return fail;
            }
        } catch (Exception e) {
            CustomApiResult<Object> fail = CustomApiResult.fail("501", e.getMessage());
            return fail;
        }
        CustomApiResult<Object> ces = CustomApiResult.success(msg);
        return ces;
    }

    /**
     * 撤销客户需求单
     *
     * @param id
     * @return
     * @throws IOException
     */
    @ApiPostMapping("/Clientdemand/unsubmit")
    public CustomApiResult<Object> Completeunsubmit(@NotNull @ApiParam("下单id") String id) throws IOException {
        String msg = "";
        try {
            Map<String, String> ordercreateuser = OrderApiUtils.Orderunsubmit(id);
            if (ordercreateuser.size() > 0) {
                String status = (String) ordercreateuser.get("status");
                msg = (String) ordercreateuser.get("msg");
                if (status.equals("error")) {
                    CustomApiResult<Object> fail = CustomApiResult.fail("501", ordercreateuser.get("msg"));
                    return fail;
                }
            } else {
                CustomApiResult<Object> fail = CustomApiResult.fail("501", "调用失败，请联系管理员！");
                return fail;
            }
        } catch (Exception e) {
            CustomApiResult<Object> fail = CustomApiResult.fail("501", e.getMessage());
            return fail;
        }
        CustomApiResult<Object> ces = CustomApiResult.success(msg);
        return ces;
    }

    /**
     * 下单平台确认收货自动下推合同
     *
     * @param data
     * @return
     * @throws IOException
     */
    @ApiPostMapping("/Clientdemand/push")
    public CustomApiResult<Object> Completepush(@NotNull @ApiParam("参数") String data) throws IOException {
        String msg = "";
        try {
            Map<String, String> ordercreateuser = OrderApiUtils.clientdemandtosalesorder(data);
            if (ordercreateuser.size() > 0) {
                String status = (String) ordercreateuser.get("status");
                msg = (String) ordercreateuser.get("msg");
                if (status.equals("error")) {
                    CustomApiResult<Object> fail = CustomApiResult.fail("501", ordercreateuser.get("msg"));
                    return fail;
                }
            } else {
                CustomApiResult<Object> fail = CustomApiResult.fail("501", "调用失败，请联系管理员！");
                return fail;
            }
        } catch (Exception e) {
            CustomApiResult<Object> fail = CustomApiResult.fail("501", e.getMessage());
            return fail;
        }
        CustomApiResult<Object> ces = CustomApiResult.success(msg);
        return ces;
    }


}
