package com.palmnest.service.ws;

import com.palmnest.application.core.util.HttpKit;
import com.palmnest.application.core.util.LogExceptionStackUtil;
import com.palmnest.application.core.util.PropertiesKit;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONObject;
import org.springframework.web.client.HttpClientErrorException;

/**
 * 同步一键报修用户数据
 *
 * @author HJY
 */
@Slf4j
public class UserinformationSync {


	private static String syncUserMsgUrl = PropertiesKit.readPropertiesValue("syncUserMsgUrl", "app.properties");

	private static String syncOrganizationMsgUrl = PropertiesKit.readPropertiesValue("syncOrganizationMsgUrl", "app.properties");

	private static String bannerUrl = PropertiesKit.readPropertiesValue("bannerUrl", "app.properties");

	/**
	 * 客户基本资料信息同步接口
	 *
	 * @param params
	 * @return
	 * @throws Exception `
	 */
	public static boolean assignuser(String params) {
		try {
			String     reslut     = HttpKit.Post(params, syncUserMsgUrl);
			JSONObject resultJson = JSONObject.fromObject(reslut);
			if (resultJson.getString("resultCode").equals("200")) {
				return true;
			}
		} catch (HttpClientErrorException clientErrorException) {
			log.error(LogExceptionStackUtil.LogExceptionStack(clientErrorException));
		} catch (Exception e) {
			log.error(LogExceptionStackUtil.LogExceptionStack(e));
		}
		return false;
	}

	/**
	 * Banner广告信息查询
	 *
	 * @param params
	 * @return
	 * @throws Exception `
	 */
	public static String getBanner(String params) {
		try {
			String reslut = HttpKit.Post(params, bannerUrl);
			log.info(reslut);
			JSONObject resultJson = JSONObject.fromObject(reslut);
			if (resultJson.getString("resultCode").equals("200")) {
				return resultJson.getString("returnDTO");
			}
		} catch (HttpClientErrorException clientErrorException) {
			log.error(LogExceptionStackUtil.LogExceptionStack(clientErrorException));
		} catch (Exception e) {
			log.error(LogExceptionStackUtil.LogExceptionStack(e));
		}
		return null;
	}

	/**
	 * 项目资料信息同步接口
	 *
	 * @param params
	 * @return
	 * @throws Exception `
	 */
	public static boolean assignOrganization(String params) {
		try {
			String     reslut     = HttpKit.Post(params, syncOrganizationMsgUrl);
			JSONObject resultJson = JSONObject.fromObject(reslut);
			if (resultJson.getString("resultCode").equals("200")) {
				return true;
			}
		} catch (HttpClientErrorException clientErrorException) {
			log.error(LogExceptionStackUtil.LogExceptionStack(clientErrorException));
		} catch (Exception e) {
			log.error(LogExceptionStackUtil.LogExceptionStack(e));
		}
		return false;
	}

	public static void main(String[] args) {
		System.out.println(UserinformationSync.getBanner("projectCode=SZ-HDDS&serviceType=-1"));
	}

}
