feat: 对公涉农接口支持AI配置与透传,API后台支持配置对公涉农启用AI

This commit is contained in:
王文艳
2026-09-04 10:37:51 +08:00
parent cfb3e4aa74
commit 90618f96b0
7 changed files with 85 additions and 1 deletions
@@ -1,6 +1,7 @@
package com.fangjia.open.controllers;
import com.fangjia.core.util.HttpRequest;
import com.fangjia.dal.mongo.model.ApiUserCfg;
import com.fangjia.dal.mongo.model.Township;
import com.fangjia.dal.mongo.model.VillageIdentify;
import com.fangjia.dal.seaweed.model.District;
@@ -10,6 +11,7 @@ import com.fangjia.open.dto.addressGovernance.DistrictDto;
import com.fangjia.open.dto.addressGovernance.DistrictIdentifyDto;
import com.fangjia.open.dto.addressGovernance.MatchedBuildingDto;
import com.fangjia.open.dto.addressGovernance.StructureAndCompleteDto;
import com.fangjia.open.interceptors.AuthenticationBean;
import com.fangjia.open.interceptors.Authority;
import com.fangjia.open.interceptors.Role;
import com.fangjia.open.model.AddesssMatchModel;
@@ -22,6 +24,7 @@ import com.fangjia.service.datastore.DistrictService;
import com.fangjia.service.district.DistrictStatService;
import com.fangjia.service.mongo.fangjia.TownshipService;
import com.fangjia.service.mongo.fangjia.VillageIdentifyService;
import com.fangjia.service.api.ApiUserCfgService;
import com.fangjia.service.open.DistrictAnalyDataService;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
@@ -42,8 +45,10 @@ import org.apache.http.impl.conn.DefaultProxyRoutePlanner;
import org.apache.http.util.EntityUtils;
import org.sothis.core.util.CollectionUtils;
import org.sothis.core.util.Pager;
import org.sothis.web.mvc.ActionContext;
import sun.misc.BASE64Encoder;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.net.Authenticator;
import java.net.PasswordAuthentication;
@@ -64,6 +69,7 @@ public class AddrSvcController {
private VillageIdentifyService villageIdentifyService;
private DistrictAnalyDataService districtAnalyDataService;
private TownshipService townshipService;
private ApiUserCfgService apiUserCfgService;
/**
* 地址结构化
@@ -1121,6 +1127,19 @@ public class AddrSvcController {
} else {
Integer radius = model.getRadius();
params.put("radius", (radius != null && radius != 0) ? radius.toString() : null);
HttpServletRequest req = ActionContext.getContext().getRequest();
if (req != null && apiUserCfgService != null) {
AuthenticationBean authenticationBean = (AuthenticationBean) req.getAttribute(AuthenticationBean.ATTR_AUTHENTICATION_BEAN);
if (authenticationBean != null && authenticationBean.apiUser != null) {
ApiUserCfg apiUserCfg = apiUserCfgService.findByUserId(authenticationBean.apiUser.getId(), ApiUserCfg.ApiUserCfgKey.ENTERPRISE_VILLAGE_AI);
if (apiUserCfg != null && apiUserCfg.getCfgValue() != null) {
String aiVal = apiUserCfg.getCfgValue().toString();
if ("1".equals(aiVal) || "true".equalsIgnoreCase(aiVal)) {
params.put("ai", "1");
}
}
}
}
try {
json = request.getJsonContent("http://192.168.0.80:32080/FangJiaAddressService/enterpriseVillageIdentify", params, "UTF-8");
} catch (Exception e) {
@@ -1745,4 +1764,8 @@ public class AddrSvcController {
public void setTownshipService(TownshipService townshipService) {
this.townshipService = townshipService;
}
public void setApiUserCfgService(ApiUserCfgService apiUserCfgService) {
this.apiUserCfgService = apiUserCfgService;
}
}
@@ -1,14 +1,19 @@
package com.fangjia.open.controllers;
import com.fangjia.core.util.HttpRequest;
import com.fangjia.dal.mongo.model.ApiUserCfg;
import com.fangjia.open.interceptors.AuthenticationBean;
import com.fangjia.open.interceptors.Authority;
import com.fangjia.open.interceptors.Role;
import com.fangjia.open.model.AddressModel;
import com.fangjia.open.model.BasicModel;
import com.fangjia.open.model.RestfulModelAndView;
import com.fangjia.service.api.ApiUserCfgService;
import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;
import org.sothis.web.mvc.ActionContext;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;
@@ -18,6 +23,8 @@ import java.util.Map;
@Authority(role = Role.USER)
public class GdBankController {
private ApiUserCfgService apiUserCfgService;
private static final Map<String, String> areaMap = new HashMap<String, String>() {
{
// 添加键值对到 Map 中
@@ -88,6 +95,19 @@ public class GdBankController {
Map<String, String> params = new HashMap<String, String>();
params.put("city", StringUtils.isNotBlank(model.getCity()) ? model.getCity() : null);
params.put("address", model.getAddress());
HttpServletRequest req = ActionContext.getContext().getRequest();
if (req != null && apiUserCfgService != null) {
AuthenticationBean authenticationBean = (AuthenticationBean) req.getAttribute(AuthenticationBean.ATTR_AUTHENTICATION_BEAN);
if (authenticationBean != null && authenticationBean.apiUser != null) {
ApiUserCfg apiUserCfg = apiUserCfgService.findByUserId(authenticationBean.apiUser.getId(), ApiUserCfg.ApiUserCfgKey.ENTERPRISE_VILLAGE_AI);
if (apiUserCfg != null && apiUserCfg.getCfgValue() != null) {
String aiVal = apiUserCfg.getCfgValue().toString();
if ("1".equals(aiVal) || "true".equalsIgnoreCase(aiVal)) {
params.put("ai", "1");
}
}
}
}
try {
json = request.getJsonContent("http://192.168.0.80:32080/FangJiaAddressService/cebEnterpriseVillageIdentify", params, "UTF-8");
} catch (Exception e) {
@@ -115,4 +135,8 @@ public class GdBankController {
return mav;
}
public void setApiUserCfgService(ApiUserCfgService apiUserCfgService) {
this.apiUserCfgService = apiUserCfgService;
}
}