ERPServiceImpl.java 1.92 KB
package com.huaheng.api.erp.service;

import com.alibaba.fastjson.JSON;
import com.huaheng.api.erp.domain.jind.ERPLoginResult;
import com.huaheng.api.erp.domain.jind.ErpLogin;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.utils.http.OkHttpUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.framework.web.service.ConfigService;
import com.huaheng.pc.config.address.service.AddressService;
import com.huaheng.pc.system.config.domain.Config;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/***
 * @author tongzonghao
 *
 */
@Service
public class ERPServiceImpl implements ERPService {

    @Resource
    private AddressService addressService;
    @Resource
    private ConfigService configService;

    @Override
    public AjaxResult innerLoginERP() {
        ErpLogin erpLogin = new ErpLogin();
        erpLogin.setAcctID(QuantityConstant.ERP_AcctID);
        erpLogin.setAppID(QuantityConstant.ERP_AppID);
        erpLogin.setAppSec(QuantityConstant.ERP_AppSec);
        erpLogin.setUserName(QuantityConstant.ERP_UserName);
        erpLogin.setPassword(QuantityConstant.ERP_PASSWORD);
        erpLogin.setLCID(QuantityConstant.ERP_LCID);
        String url = addressService.selectAddress(QuantityConstant.ERP_K3CLOUD_LOGIN,
                QuantityConstant.DEFAULT_WAREHOUSE, "");
        String jsonParam = JSON.toJSONString(erpLogin);
        String result = OkHttpUtils.bodypost(url, jsonParam);
        ERPLoginResult erpLoginResult = JSON.parseObject(result, ERPLoginResult.class);
        String sessionId = erpLoginResult.getKDSVCSessionId();
        Config config1 = new Config();
        config1.setConfigKey(QuantityConstant.ERP_SESSION_ID);
        Config config = configService.selectConfigList(config1).get(0);
        config.setConfigValue(sessionId);
        int ret = configService.updateConfig(config);
        return AjaxResult.success();
    }

}