后台涉农结果导入excel模板
This commit is contained in:
+47
@@ -11,11 +11,17 @@ import org.apache.commons.lang.StringUtils;
|
||||
import org.sothis.core.util.Pager;
|
||||
import org.sothis.web.mvc.ActionContext;
|
||||
import org.sothis.web.mvc.interceptors.MultipartHttpServletRequest;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
public class VillageIdentifyController {
|
||||
private VillageIdentifyService villageIdentifyService;
|
||||
@@ -27,6 +33,47 @@ public class VillageIdentifyController {
|
||||
return model;
|
||||
}
|
||||
|
||||
public void expectAction(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||
|
||||
// 编码文件名,避免乱码
|
||||
String fileName = "涉农结果导入后台模板.xlsx";
|
||||
String encodedFileName = encodeFileName(fileName, request);
|
||||
|
||||
// 设置 Content-Disposition 响应头
|
||||
response.setHeader("Content-Disposition", "attachment; filename=\"" + encodedFileName + "\"");
|
||||
|
||||
// 使用 ClassPathResource 来获取资源文件
|
||||
ClassPathResource resource = new ClassPathResource(fileName);
|
||||
InputStream in = resource.getInputStream();
|
||||
OutputStream out = response.getOutputStream();
|
||||
|
||||
byte[] buffer = new byte[1024];
|
||||
int bytesRead;
|
||||
|
||||
while ((bytesRead = in.read(buffer)) != -1) {
|
||||
out.write(buffer, 0, bytesRead);
|
||||
}
|
||||
|
||||
out.flush();
|
||||
|
||||
}
|
||||
|
||||
private String encodeFileName(String fileName, HttpServletRequest request) throws IOException {
|
||||
String userAgent = request.getHeader("User-Agent");
|
||||
String encodedFileName;
|
||||
|
||||
if (userAgent.contains("MSIE") || userAgent.contains("Trident")) {
|
||||
// 针对IE浏览器
|
||||
encodedFileName = URLEncoder.encode(fileName, "UTF-8").replace("+", "%20");
|
||||
} else {
|
||||
// 针对其他浏览器
|
||||
encodedFileName = new String(fileName.getBytes("UTF-8"), "ISO-8859-1");
|
||||
}
|
||||
|
||||
return encodedFileName;
|
||||
}
|
||||
|
||||
public Object uploadAction(HttpServletRequest request) throws IOException {
|
||||
Object fileInputStream = ActionContext.getContext().getParameters().get("fileInputStream")[0];
|
||||
JsonModel ret = new JsonModel();
|
||||
|
||||
Binary file not shown.
+87
-48
@@ -2,6 +2,7 @@ package com.fangjia.open.controllers;
|
||||
|
||||
import com.fangjia.core.util.HttpRequest;
|
||||
import com.fangjia.dal.common.DistrictKey;
|
||||
import com.fangjia.dal.mongo.model.VillageIdentify;
|
||||
import com.fangjia.dal.seaweed.model.District;
|
||||
import com.fangjia.open.dto.addressGovernance.*;
|
||||
import com.fangjia.open.interceptors.Authority;
|
||||
@@ -14,6 +15,7 @@ import com.fangjia.open.util.CommonDtoUtils;
|
||||
import com.fangjia.service.bo.DistrictStatBo;
|
||||
import com.fangjia.service.datastore.DistrictService;
|
||||
import com.fangjia.service.district.DistrictStatService;
|
||||
import com.fangjia.service.mongo.fangjia.VillageIdentifyService;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
@@ -28,6 +30,7 @@ import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.sothis.core.util.Pager;
|
||||
import sun.misc.BASE64Encoder;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -38,7 +41,6 @@ import java.net.Proxy;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Stack;
|
||||
|
||||
/**
|
||||
* 地址治理
|
||||
@@ -51,6 +53,7 @@ public class AddrSvcController {
|
||||
|
||||
private DistrictStatService districtStatService;
|
||||
private DistrictService districtService;
|
||||
private VillageIdentifyService villageIdentifyService;
|
||||
|
||||
/**
|
||||
* 地址结构化
|
||||
@@ -506,79 +509,111 @@ public class AddrSvcController {
|
||||
String address = model.getAddress();
|
||||
params.put("address", address);
|
||||
String type = StringUtils.isNotBlank(model.getType()) ? model.getType() : null;
|
||||
String villageType = "2".equals(model.getType()) ? "对公" : "对私";
|
||||
params.put("type", type);
|
||||
params.put("showFullValue", "2");
|
||||
Pager pager = new Pager(1, 1);
|
||||
VillageIdentify villageResult = villageIdentifyService.findAll(villageType, model.getCity(), model.getAddress(), pager).get(0);
|
||||
if (villageResult != null && StringUtils.isNotBlank(villageResult.getVerifyFlag())) {
|
||||
Map<String, String> resultMap = new HashMap<String, String>();
|
||||
resultMap.put("province",villageResult.getProvince());
|
||||
resultMap.put("city",villageResult.getCity1());
|
||||
resultMap.put("district",villageResult.getDistrict());
|
||||
resultMap.put("town",villageResult.getTown());
|
||||
resultMap.put("committee",villageResult.getCommittee());
|
||||
resultMap.put("provinceCode",villageResult.getCityCode());
|
||||
resultMap.put("cityCode",villageResult.getCityCode());
|
||||
resultMap.put("districtCode",villageResult.getDistrictCode());
|
||||
resultMap.put("townCode",villageResult.getTownCode());
|
||||
resultMap.put("committeeCode",villageResult.getCommitteeCode());
|
||||
resultMap.put("typeCode",villageResult.getTypeCode());
|
||||
resultMap.put("typeName",villageResult.getTypeName());
|
||||
resultMap.put("verifyFlag",villageResult.getVerifyFlag());
|
||||
resultMap.put("addrVerify", villageResult.getAddrVerify());
|
||||
resultMap.put("countyLevelCity",villageResult.getCountyLevelCity());
|
||||
resultMap.put("administrativeTowns",villageResult.getAdministrativeTowns());
|
||||
resultMap.put("countyGov",villageResult.getCountyGov());
|
||||
resultMap.put("devDistrict",villageResult.getDevDistrict());
|
||||
resultMap.put("devDistrictName",villageResult.getDevDistrictName());
|
||||
resultMap.put("devLevel",villageResult.getDevLevel());
|
||||
resultMap.put("addrArea",villageResult.getAddrArea());
|
||||
BasicModel basicModel = new BasicModel(200, "OK");
|
||||
basicModel.setResult(resultMap);
|
||||
mav.setModel(basicModel);
|
||||
} else {
|
||||
// params.put("showTestValue", "2");
|
||||
Integer radius = model.getRadius();
|
||||
params.put("radius", (radius != null && radius != 0) ? radius.toString() : null);
|
||||
try {
|
||||
json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/villageIdentify", params, "UTF-8");
|
||||
} catch (Exception e) {
|
||||
Integer radius = model.getRadius();
|
||||
params.put("radius", (radius != null && radius != 0) ? radius.toString() : null);
|
||||
try {
|
||||
json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/villageIdentify", params, "UTF-8");
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
json = request.getJsonContent("http://192.168.0.100:32080/FangJiaAddressService/villageIdentify", params, "UTF-8");
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (json != null) {
|
||||
int code = json.getInt("msgCode");
|
||||
String msg = json.getString("msg");
|
||||
BasicModel basicModel = new BasicModel(code, msg);
|
||||
if (json.containsKey("result")) {
|
||||
//我们的结果
|
||||
JSONObject result = json.getJSONObject("result");
|
||||
//我们省级及以上有开发区,直接用我们的结果
|
||||
if (result.containsKey("devDistrictName")) {
|
||||
basicModel.setResult(result);
|
||||
|
||||
} else {
|
||||
try {
|
||||
//如果是江苏省或者浙江省 调用齐梁的结果
|
||||
if ("江苏省".equals(result.getString("province")) || "浙江省".equals(result.getString("province"))) {
|
||||
if (json != null) {
|
||||
int code = json.getInt("msgCode");
|
||||
String msg = json.getString("msg");
|
||||
BasicModel basicModel = new BasicModel(code, msg);
|
||||
if (json.containsKey("result")) {
|
||||
//我们的结果
|
||||
JSONObject result = json.getJSONObject("result");
|
||||
//我们省级及以上有开发区,直接用我们的结果
|
||||
if (result.containsKey("devDistrictName")) {
|
||||
basicModel.setResult(result);
|
||||
|
||||
//结果比较,如果涉农结果不一致
|
||||
//调用齐梁 type :1 对公 0 对私
|
||||
//我们 type :1 对私 2 对共
|
||||
String qltype = "2".equals(type) ? "1" : "0";
|
||||
Map<String, String> map = senRequest(address, qltype);
|
||||
// 涉农结果不一样
|
||||
if (!map.get("verifyFlag").equals(result.get("verifyFlag"))) {
|
||||
//有市辖建制镇, 或者城市不一样 用我们
|
||||
if (result.containsKey("city")) {
|
||||
if ("是".equals(result.get("administrativeTowns")) || (!result.get("city").equals(map.get("city")) && StringUtils.isNotBlank(result.getString("city")))) {
|
||||
basicModel.setResult(result);
|
||||
} else {
|
||||
try {
|
||||
//如果是江苏省或者浙江省 调用齐梁的结果
|
||||
if ("江苏省".equals(result.getString("province")) || "浙江省".equals(result.getString("province"))) {
|
||||
|
||||
//结果比较,如果涉农结果不一致
|
||||
//调用齐梁 type :1 对公 0 对私
|
||||
//我们 type :1 对私 2 对共
|
||||
String qltype = "2".equals(type) ? "1" : "0";
|
||||
Map<String, String> map = senRequest(address, qltype);
|
||||
// 涉农结果不一样
|
||||
if (!map.get("verifyFlag").equals(result.get("verifyFlag"))) {
|
||||
//有市辖建制镇, 或者城市不一样 用我们
|
||||
if (result.containsKey("city")) {
|
||||
if ("是".equals(result.get("administrativeTowns")) || (!result.get("city").equals(map.get("city")) && StringUtils.isNotBlank(result.getString("city")))) {
|
||||
basicModel.setResult(result);
|
||||
} else {
|
||||
map.put("addrVerify", "地址有效");
|
||||
map.put("typeName", areaMap.get(map.get("typeCode")));
|
||||
basicModel.setResult(map);
|
||||
}
|
||||
} else {
|
||||
map.put("addrVerify", "地址有效");
|
||||
map.put("typeName", areaMap.get(map.get("typeCode")));
|
||||
basicModel.setResult(map);
|
||||
}
|
||||
|
||||
} else {
|
||||
map.put("addrVerify", "地址有效");
|
||||
map.put("typeName", areaMap.get(map.get("typeCode")));
|
||||
basicModel.setResult(map);
|
||||
basicModel.setResult(result);
|
||||
}
|
||||
|
||||
} else {
|
||||
basicModel.setResult(result);
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
basicModel.setResult(result);
|
||||
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
basicModel.setResult(result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
mav.setModel(basicModel);
|
||||
} else {
|
||||
mav.setModel(BasicModel.buildServerErrorModel().setMsg("服务升级中..."));
|
||||
}
|
||||
mav.setModel(basicModel);
|
||||
} else {
|
||||
mav.setModel(BasicModel.buildServerErrorModel().setMsg("服务升级中..."));
|
||||
}
|
||||
return mav;
|
||||
}
|
||||
@@ -757,8 +792,8 @@ public class AddrSvcController {
|
||||
params.put("district", StringUtils.isNotBlank(model.getDistrict()) ? model.getDistrict() : null);
|
||||
params.put("keywords", StringUtils.isNotBlank(model.getKeywords()) ? model.getKeywords() : null);
|
||||
if (StringUtils.isNotBlank(model.getLng()) && StringUtils.isNotBlank(model.getLat())) {
|
||||
params.put("lat",model.getLat());
|
||||
params.put("lng",model.getLng());
|
||||
params.put("lat", model.getLat());
|
||||
params.put("lng", model.getLng());
|
||||
}
|
||||
Integer radius = model.getRadius();
|
||||
params.put("radius", (radius != null && radius != 0) ? radius.toString() : null);
|
||||
@@ -793,4 +828,8 @@ public class AddrSvcController {
|
||||
public void setDistrictService(DistrictService districtService) {
|
||||
this.districtService = districtService;
|
||||
}
|
||||
|
||||
public void setVillageIdentifyService(VillageIdentifyService villageIdentifyService) {
|
||||
this.villageIdentifyService = villageIdentifyService;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user