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.fs.his.config.FsErpConfig;
import com.fs.his.utils.ConfigUtil;
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
    ConfigUtil configUtil;


    @Override
    public BaseResponse addUser(ErpUser user) {
        FsErpConfig erpConfig = configUtil.getErpConfig();
        JSONObject param = JSONUtil.createObj();
        param.set("appkey", erpConfig.getErpAppKey());
        param.set("sessionkey", erpConfig.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(),erpConfig.getErpSecret()));
        String result = HttpUtil.post(erpConfig.getErpUrl(), param.toString());
        BaseResponse response=JSONUtil.toBean(result, BaseResponse.class);
        return response;
    }
}
