package com.fs.erp.service.impl;

import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.fs.common.config.FSSysConfig;
import com.fs.erp.domain.ErpUser;
import com.fs.erp.dto.BaseResponse;
import com.fs.erp.dto.ErpShopResponse;
import com.fs.erp.service.IErpShopService;
import com.fs.erp.service.IErpUserService;
import com.fs.erp.utils.CommonUtils;
import com.sun.org.apache.bcel.internal.generic.RETURN;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 参数配置 服务层实现
 *

 */
@Service
public class ErpUserServiceImpl implements IErpUserService
{

    @Autowired
    FSSysConfig sysConfig;


    @Override
    public BaseResponse addUser(ErpUser user) {
        JSONObject param = JSONUtil.createObj();
        param.set("appkey", sysConfig.getErpAppKey());
        param.set("sessionkey", sysConfig.getErpSessionKey());
        param.set("method", "gy.erp.vip.add");
        param.set("code", user.getCode());
        param.set("name", user.getName());
        param.set("shop_code", user.getShop_code());
        param.set("receive_infos", user.getReceive_infos());
        param.set("sign",CommonUtils.sign(param.toString(),sysConfig.getErpSecret()));
        String result = HttpUtil.post(sysConfig.getErpUrl(), param.toString());
        BaseResponse response=JSONUtil.toBean(result, BaseResponse.class);
        return response;
    }
}
