package com.nova.sankuai.domain.api.tianshi; import com.alibaba.fastjson.JSONObject; import com.nova.sankuai.domain.dto.CustomerCompareDto; import com.nova.sankuai.domain.entity.Customer; import com.nova.sankuai.security.MD5Encryption; import io.swagger.annotations.ApiModel; import lombok.Data; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import java.lang.reflect.Field; import java.lang.reflect.Modifier; /** *

* 苏州天师公司接口对接 *

* * @author: zcj 2022/2/14 */ @Data @Component @ApiModel(value = "苏州天师接口公司对接") public class TianShiUtil { @Value("${suzhoutianshi.hitUrl}") public String hitUrl; @Value("${suzhoutianshi.commitUrl}") public String commitUrl; @Value("${suzhoutianshi.source}") public String source; @Value("${suzhoutianshi.secretapi}") public String secretapi; public JSONObject parseHitParam(Customer customer) { JSONObject object = new JSONObject(); object.put("source", this.source); String phone = MD5Encryption.getMD5(customer.getPhone()); object.put("mobile", phone); object.put("name", customer.getName()); object.put("city", customer.getCityName().substring(0,customer.getCityName().indexOf('市'))); return object; } public JSONObject parseCommitParam(Customer customer) { CustomerCompareDto parse = CustomerCompareDto.parse(customer); JSONObject json = new JSONObject(); json.put("source", this.source); json.put("name", customer.getName()); json.put("mobile", customer.getPhone()); json.put("city", customer.getCityName().substring(0,customer.getCityName().indexOf('市'))); json.put("age", customer.getAge()); json.put("money", parse.getQuota()); json.put("car", parse.isCarStatus() ? "有" : null); json.put("house", parse.isHouseStatus() ? "有" : null); json.put("shebao", parse.isSocialSecurity() ? "有" : null); json.put("gongjijin", parse.isProvidentFund() ? "有" : null); json.put("credit_card", parse.isCreditCard() ? "有" : null); return json; } public static String getFailMessage(Integer code) { Field[] fields = TianShiResponse.class.getFields(); for (Field field : fields) { if (Modifier.isFinal(field.getModifiers())) { if (field.getName().contains(Integer.toString(code))) { try { return (String) field.get(null); } catch (IllegalAccessException e) { e.printStackTrace(); } } } } return code.toString(); } }