diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/basic/TtMerchantPoiController.java b/mallinkAdmin/src/main/java/com/iformall/controller/basic/TtMerchantPoiController.java index 929793101..3999aa20c 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/basic/TtMerchantPoiController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/basic/TtMerchantPoiController.java @@ -249,6 +249,84 @@ public class TtMerchantPoiController extends DouyinBaseController { } } + @TenantIgnore + @PostMapping(value = "/addLocationInfo", consumes = "multipart/*") + //@SystemControllerLog(description = "poi-来客模版补齐地理位置信息") + public void addLocationInfo(@RequestParam("poiFile") MultipartFile mFile,HttpServletRequest request, HttpServletResponse response) { + try { + boolean isSaas = this.isGoodLifeSaas(); + if (!isSaas) { + //return addLocationInfo(mFile,false); + throw new MallinkException(Result.ERROR,"当前版本无需补齐地理位置信息"); + }else { + addLocationInfo(mFile,true,"1bdc087fc6f72820dc5c848a033de7f9",request,response); + } + } catch (Exception e) { + logger.error("addLocationInfo error.",e); + throw new MallinkException(Result.ERROR,e.getMessage()); + } + } + + private void addLocationInfo(MultipartFile mFile,boolean isNew,String gaodeKey, + HttpServletRequest request, HttpServletResponse response) throws Exception{ + if (mFile.isEmpty()) { + throw new MallinkException(Result.ERROR, "上传文件不能为空"); + } + //得到当前用户ID + final MallUserInfo user = getUser(); + + String fpath = fmUploadDir; + File targetFile = new File(fpath); + if (!targetFile.exists()) { + targetFile.mkdirs(); + } + String fileName = "poiAddLocation" + Math.round(Math.random() * 100000000000L); + int dot = mFile.getOriginalFilename().lastIndexOf('.'); + fileName = fileName + mFile.getOriginalFilename().substring(dot, mFile.getOriginalFilename().length()); + + File lFile = new File(fpath + File.separator + fileName); + + FileOutputStream fos = null; + BufferedInputStream fs = null; + try { + fos = new FileOutputStream(lFile); + fs = (BufferedInputStream) mFile.getInputStream(); + byte[] buffer = new byte[1024]; + int len = 0; + while ((len = fs.read(buffer)) != -1) { + fos.write(buffer, 0, len); + } + fos.close(); + fs.close(); + } catch (Exception e) { + logger.error("poiAddLocation create tempFile error.",e); + throw new MallinkException(Result.ERROR,e.getMessage()); + } finally { + if (fos != null) { + try { + fos.close(); + } catch (IOException e) { + logger.error("poiAddLocation create tempFile error.",e); + throw new MallinkException(Result.ERROR,e.getMessage()); + } + } + if (fs != null) { + try { + fs.close(); + } catch (IOException e) { + logger.error("poiAddLocation create tempFile error.",e); + throw new MallinkException(Result.ERROR,e.getMessage()); + } + } + } + if (isNew) { + asyncTask.exportExcelPoiDataAddLocationForNew(gaodeKey,lFile,request,response); + }else { + } + + } + + @TenantIgnore @PostMapping(value = "/importPoi", consumes = "multipart/*") @SystemControllerLog(description = "poi-导入数据") diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/mem/AsyncTask.java b/mallinkAdmin/src/main/java/com/iformall/controller/mem/AsyncTask.java index 25ebee27a..91459f4a2 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/mem/AsyncTask.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/mem/AsyncTask.java @@ -1,20 +1,29 @@ package com.iformall.controller.mem; +import cn.afterturn.easypoi.excel.ExcelExportUtil; import cn.afterturn.easypoi.excel.ExcelImportUtil; +import cn.afterturn.easypoi.excel.entity.ExportParams; import cn.afterturn.easypoi.excel.entity.ImportParams; import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult; import cn.afterturn.easypoi.handler.impl.ExcelDataHandlerDefaultImpl; import cn.afterturn.easypoi.handler.inter.IExcelDataHandler; + +import com.iformall.common.ErrorCode; import com.iformall.domain.po.MallUserInfo; import com.iformall.domain.po.WxTags; import com.iformall.domain.vo.CUserBaseInfoT; +import com.iformall.domain.vo.GaoDePoiInfo; import com.iformall.domain.vo.MerchantPoiT; import com.iformall.domain.vo.MerchantPoiTNew; import com.iformall.domain.vo.WxCardPriceTemplate; +import com.iformall.exception.MallinkException; import com.iformall.service.TtMerchantPoiService; import com.iformall.service.WxCUserBasicInfoService; import com.iformall.service.WxCouponPasswordService; import com.iformall.service.WxTagsService; + +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.ss.usermodel.Workbook; import org.apache.shiro.session.UnknownSessionException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -24,9 +33,13 @@ import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; import java.io.File; +import java.io.OutputStream; import java.util.List; import java.util.concurrent.TimeUnit; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + @Component public class AsyncTask { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @@ -222,14 +235,90 @@ public class AsyncTask { } } + public void exportExcelPoiDataAddLocationForNew(String gaodeKey,File file,HttpServletRequest request, HttpServletResponse response) throws Exception { + ImportParams params = new ImportParams(); + // 需要验证 + String[] headers = new String[]{"门店名称", "门店ID", "城市", "详细地址","富茂系统省份", "富茂系统城市", "富茂系统地址","富茂系统经度", "富茂系统纬度","高德匹配备注", "富茂系统商户ID", "富茂系统商户名称"}; + params.setImportFields(headers); + IExcelDataHandler handler = new AsyncTask.PoiNewExcelHandler(); + handler.setNeedHandlerFields(new String[]{"门店名称", "门店ID", "城市", "详细地址"}); + params.setNeedVerify(true); + + ExcelImportResult datalist = null; + + try { + datalist = ExcelImportUtil.importExcelMore(file, MerchantPoiTNew.class, params); + } catch (Exception e) { + logger.error("exportExcelPoiDataAddLocationForNew import error.",e); + // 删除缓存文件 + file.delete(); + throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),e.getMessage()); + } + // 删除缓存文件 + file.delete(); + + if(datalist == null) { + throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"解析模版失败,请检查模版格式"); + } + + List successList = datalist.getList(); + //List failList = datalist.getFailList(); + if(null != successList && successList.size() > 0 ) { + try { + successList.parallelStream().forEach(poiBase -> { + try { + GaoDePoiInfo gaodeInfo = ttMerchantPoiService.queryGaoDePoiInfo(gaodeKey, poiBase.getPoiCity()+poiBase.getPoiAddress()); + if (null != gaodeInfo) { + if (gaodeInfo.isSuccess()) { + poiBase.setProvince(gaodeInfo.getProvince()); + poiBase.setCity(gaodeInfo.getCity()); + poiBase.setAddress(poiBase.getPoiAddress()); + poiBase.setLongitude(gaodeInfo.getLongitude()); + poiBase.setLatitude(gaodeInfo.getLatitude()); + poiBase.setGaodeRemark("匹配成功"); + }else { + poiBase.setGaodeRemark("匹配失败,"+gaodeInfo.getErrMsg()); + } + }else { + poiBase.setGaodeRemark("未匹配到信息"); + } + } catch (UnknownSessionException ue) { + logger.error("session :"+ue.getMessage()); + } + }); + + + ExportParams exportParams = new ExportParams(); + exportParams.setCreateHeadRows(true); + exportParams.setExclusions(headers); + Workbook workBook = ExcelExportUtil.exportExcel(exportParams, MerchantPoiTNew.class, successList); + exportExcel(request, response, workBook, "POI匹配模版-高德.xls"); + } catch (Exception e) { + logger.error("更新地理信息失败:"+e.getMessage(),e); + } + } + } + + private static void exportExcel(HttpServletRequest request, HttpServletResponse response, Workbook wb, String fileName) throws Exception { + response.setContentType("application/octet-stream;charset=UTF-8"); + response.setHeader("Content-Type", "application/vnd.ms-excel"); + response.setHeader("Content-Disposition", "attachment;filename=" + new String(fileName.getBytes("GB2312"), "8859_1")); + response.addHeader("Pargam", "no-cache"); + response.addHeader("Cache-Control", "no-cache"); + OutputStream out = response.getOutputStream(); + wb.write(out); + out.flush(); + out.close(); + } + @Async public void importExcelPoiDataForNew(File file, MallUserInfo user, String importKey) { ImportParams params = new ImportParams(); // 需要验证 - params.setImportFields(new String[]{"富茂商户ID", "富茂商户名称", "经度", "纬度", - "来客门店名称", "来客门店ID", "省份", "城市", "地址"}); + String[] headers = new String[]{"门店名称", "门店ID", "城市", "详细地址","富茂系统省份", "富茂系统城市", "富茂系统地址","富茂系统经度", "富茂系统纬度","高德匹配备注", "富茂系统商户ID", "富茂系统商户名称"}; + params.setImportFields(headers); IExcelDataHandler handler = new AsyncTask.PoiNewExcelHandler(); - handler.setNeedHandlerFields(new String[]{"富茂商户ID","来客门店ID"}); + handler.setNeedHandlerFields(new String[]{"富茂商户ID","来客门店ID","富茂系统省份", "富茂系统城市", "富茂系统地址","富茂系统经度", "富茂系统纬度"}); params.setNeedVerify(true); ExcelImportResult datalist = null; diff --git a/mallinkAdmin/src/main/java/com/iformall/utils/UrlCheck.java b/mallinkAdmin/src/main/java/com/iformall/utils/UrlCheck.java index 86676b39d..b865b2297 100644 --- a/mallinkAdmin/src/main/java/com/iformall/utils/UrlCheck.java +++ b/mallinkAdmin/src/main/java/com/iformall/utils/UrlCheck.java @@ -25,6 +25,7 @@ public class UrlCheck { || url.contains("/alipay/imageUpload") || url.contains("/video/upload") || url.contains("/merchantPoi/importPoi") + || url.contains("/merchantPoi/addLocationInfo") || url.contains("/couponPassword/importPrice"); } diff --git a/mallinkService/src/main/java/com/iformall/domain/vo/GaoDePoiInfo.java b/mallinkService/src/main/java/com/iformall/domain/vo/GaoDePoiInfo.java new file mode 100644 index 000000000..db4f18d09 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/domain/vo/GaoDePoiInfo.java @@ -0,0 +1,30 @@ +package com.iformall.domain.vo; + +import lombok.Data; +import java.io.Serializable; +import java.math.BigDecimal; + +@Data +public class GaoDePoiInfo implements Serializable { + + private boolean success; + private String errMsg; + + @io.swagger.annotations.ApiModelProperty(value="名称",name="name") + private String name; + @io.swagger.annotations.ApiModelProperty(value="国家",name="country") + private String country; + @io.swagger.annotations.ApiModelProperty(value="省份",name="province") + private String province; + @io.swagger.annotations.ApiModelProperty(value="城市",name="city") + private String city; + @io.swagger.annotations.ApiModelProperty(value="区",name="province") + private String district; + @io.swagger.annotations.ApiModelProperty(value="详细地址",name="address") + private String address; + @io.swagger.annotations.ApiModelProperty(value="经度",name="longitude") + private BigDecimal longitude; + @io.swagger.annotations.ApiModelProperty(value="纬度",name="latitude") + private BigDecimal latitude; + +} diff --git a/mallinkService/src/main/java/com/iformall/domain/vo/MerchantPoiTNew.java b/mallinkService/src/main/java/com/iformall/domain/vo/MerchantPoiTNew.java index c818fc21a..dbb7545ca 100644 --- a/mallinkService/src/main/java/com/iformall/domain/vo/MerchantPoiTNew.java +++ b/mallinkService/src/main/java/com/iformall/domain/vo/MerchantPoiTNew.java @@ -12,36 +12,50 @@ import java.math.BigDecimal; @Data public class MerchantPoiTNew implements Serializable { - @NotNull - @Excel(name="富茂商户ID",width = 20,orderNum = "1") - @io.swagger.annotations.ApiModelProperty(value="富茂商户ID",name="merchantId") - private String merchantId; - @Excel(name="富茂商户名称",width = 20,orderNum = "2") - @io.swagger.annotations.ApiModelProperty(value="富茂商户名称",name="merchantName") - private String merchantName; - @Excel(name="经度",width = 20,orderNum = "3") - @io.swagger.annotations.ApiModelProperty(value="经度",name="longitude") - private BigDecimal longitude; - @Excel(name = "纬度", width = 20, orderNum = "4") - @io.swagger.annotations.ApiModelProperty(value="纬度",name="latitude") - private BigDecimal latitude; - - @Excel(name = "来客门店名称", width = 20, orderNum = "5") + @Excel(name = "门店名称", width = 20, orderNum = "1") @io.swagger.annotations.ApiModelProperty(value="来客门店名称",name="poiName") private String poiName; - @Excel(name="来客门店ID",width = 20,orderNum = "6") + @Excel(name="门店ID",width = 20,orderNum = "2") @io.swagger.annotations.ApiModelProperty(value="来客门店ID",name="poiId") private String poiId; - - @Excel(name = "省份", width = 20, orderNum = "7") - @io.swagger.annotations.ApiModelProperty(value="已匹配POI省份",name="province") + @Excel(name = "城市", width = 20, orderNum = "3") + @io.swagger.annotations.ApiModelProperty(value="来客门店城市",name="poiCity") + private String poiCity; + @Excel(name = "详细地址", width = 20, orderNum = "4") + @io.swagger.annotations.ApiModelProperty(value="来客门店详细地址",name="poiAddress") + private String poiAddress; + + @Excel(name = "富茂系统省份", width = 20, orderNum = "5") + @io.swagger.annotations.ApiModelProperty(value="富茂系统省份",name="province") private String province; - - @Excel(name = "城市", width = 20, orderNum = "8") - @io.swagger.annotations.ApiModelProperty(value="已匹配POI城市",name="city") + @Excel(name = "富茂系统城市", width = 20, orderNum = "6") + @io.swagger.annotations.ApiModelProperty(value="富茂系统城市",name="city") private String city; - - @Excel(name = "地址", width = 20, orderNum = "9") - @io.swagger.annotations.ApiModelProperty(value="已匹配POI地址",name="address") + @Excel(name = "富茂系统地址", width = 20, orderNum = "7") + @io.swagger.annotations.ApiModelProperty(value="富茂系统地址",name="address") private String address; + @Excel(name="富茂系统经度",width = 20,orderNum = "8") + @io.swagger.annotations.ApiModelProperty(value="富茂系统经度",name="longitude") + private BigDecimal longitude; + @Excel(name = "富茂系统纬度", width = 20, orderNum = "9") + @io.swagger.annotations.ApiModelProperty(value="富茂系统纬度",name="latitude") + private BigDecimal latitude; + @Excel(name = "高德匹配备注", width = 20, orderNum = "10") + @io.swagger.annotations.ApiModelProperty(value="高德匹配备注",name="gaodeRemark") + private String gaodeRemark; + @Excel(name="富茂系统商户ID",width = 20,orderNum = "11") + @io.swagger.annotations.ApiModelProperty(value="富茂系统商户ID",name="merchantId") + private String merchantId; + @Excel(name="富茂系统商户名称",width = 20,orderNum = "12") + @io.swagger.annotations.ApiModelProperty(value="富茂系统商户名称",name="merchantName") + private String merchantName; + + + + + + + + + } diff --git a/mallinkService/src/main/java/com/iformall/service/TtMerchantPoiService.java b/mallinkService/src/main/java/com/iformall/service/TtMerchantPoiService.java index 8306a4f7a..dee2a6e10 100644 --- a/mallinkService/src/main/java/com/iformall/service/TtMerchantPoiService.java +++ b/mallinkService/src/main/java/com/iformall/service/TtMerchantPoiService.java @@ -5,6 +5,7 @@ import com.iformall.common.ResultData; import com.iformall.domain.po.MallUserInfo; import com.iformall.domain.po.TtMerchantPoi; import com.iformall.domain.po.base.TenantEntity; +import com.iformall.domain.vo.GaoDePoiInfo; import com.iformall.domain.vo.MerchantPoiT; import com.iformall.domain.vo.MerchantPoiTNew; import com.iformall.douyin.web.api.goodlifesaas.TtGoodLifeSaasService; @@ -67,4 +68,6 @@ public interface TtMerchantPoiService { void importOnePoiNew(MallUserInfo user, String importKey, MerchantPoiTNew poiBase); void exportTemplate(HttpServletRequest request, HttpServletResponse response,boolean isNew); + + GaoDePoiInfo queryGaoDePoiInfo(String gaodeKey,String address); } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/TtMerchantPoiServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/TtMerchantPoiServiceImpl.java index 26902b85c..3dd53597e 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/TtMerchantPoiServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/TtMerchantPoiServiceImpl.java @@ -1,6 +1,8 @@ package com.iformall.service.impl; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; @@ -10,6 +12,7 @@ import com.iformall.common.ErrorCode; import com.iformall.common.ResultData; import com.iformall.domain.po.*; import com.iformall.domain.po.base.TenantEntity; +import com.iformall.domain.vo.GaoDePoiInfo; import com.iformall.domain.vo.MerchantPoiT; import com.iformall.domain.vo.MerchantPoiTNew; import com.iformall.domain.vo.WxCardPriceTemplate; @@ -22,6 +25,7 @@ import com.iformall.exception.MallinkException; import com.iformall.mapper.*; import com.iformall.service.*; import com.iformall.utils.Constant; +import com.iformall.utils.HttpUtil; import com.iformall.utils.MaUtil; import me.chanjar.weixin.common.error.WxErrorException; import org.apache.commons.lang3.StringUtils; @@ -31,6 +35,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Service; +import java.math.BigDecimal; import java.util.*; import java.util.concurrent.TimeUnit; @@ -713,6 +718,62 @@ public class TtMerchantPoiServiceImpl implements TtMerchantPoiService { } } + @Override + public GaoDePoiInfo queryGaoDePoiInfo(String gaodeKey,String address) { + StringBuffer url = new StringBuffer("https://restapi.amap.com/v3/geocode/geo?"); + try { + String result = HttpUtil.doGet(url.append("key=").append(gaodeKey).append("&address=").append(address).toString()); + if (!StringUtils.isBlank(result)){ + GaoDePoiInfo gaodeInfo = new GaoDePoiInfo(); + JSONObject reo = JSON.parseObject(result); + String status = reo.getString("status"); + if ("1".equals(status)){ + JSONArray geocodes = reo.getJSONArray("geocodes"); + if (null == geocodes || geocodes.size() <= 0 ) { + gaodeInfo.setSuccess(false); + gaodeInfo.setErrMsg("高德未查询到该地址信息"); + }else if (geocodes.size() > 1) { + gaodeInfo.setSuccess(false); + gaodeInfo.setErrMsg("高德匹配到多条信息"); + }else { + gaodeInfo.setSuccess(true); + String country = reo.getString("country"); + if (StringUtils.isNotBlank(country)) { + gaodeInfo.setCountry(country); + } + String province = reo.getString("province"); + if (StringUtils.isNotBlank(province)) { + gaodeInfo.setProvince(province); + } + String city = reo.getString("city"); + if (StringUtils.isNotBlank(city)) { + gaodeInfo.setCity(city); + } + String district = reo.getString("district"); + if (StringUtils.isNotBlank(district)) { + gaodeInfo.setDistrict(district); + } + String location = reo.getString("location"); + if (StringUtils.isNotBlank(location)) { + String[] locas = location.split(","); + if (null != locas && locas.length == 2) { + gaodeInfo.setLongitude(new BigDecimal(locas[0])); + gaodeInfo.setLatitude(new BigDecimal(locas[1])) ; + } + } + } + }else { + String info = reo.getString("info"); + gaodeInfo.setSuccess(false); + gaodeInfo.setErrMsg(info); + } + } + }catch(Exception e) { + logger.error("queryGaoDePoiInfo error.",e); + } + return null; + } + // @Override // public ResultData spuSync(TenantEntity tenantInfo, Long couponChannelId, List merchantIds) { // WxCouponChannel couponChannel = wxCouponChannelMapper.selectById(couponChannelId, tenantInfo.getTenantId()); diff --git a/mallinkService/src/main/java/com/iformall/utils/HttpUtil.java b/mallinkService/src/main/java/com/iformall/utils/HttpUtil.java index 7d78d7706..2095dac50 100644 --- a/mallinkService/src/main/java/com/iformall/utils/HttpUtil.java +++ b/mallinkService/src/main/java/com/iformall/utils/HttpUtil.java @@ -59,32 +59,32 @@ public class HttpUtil { private static final String DEFAULT_USER_AGENT = "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36"; -// /** -// * get请求 -// * @return -// */ -// public static String doGet(String url) { -// try { -// CloseableHttpClient client = HttpClients.createDefault(); -// //发送get请求 -// HttpGet request = new HttpGet(url); -// HttpResponse response = client.execute(request); -// -// /**请求发送成功,并得到响应**/ -// if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { -// /**读取服务器返回过来的json字符串数据**/ -// String strResult = EntityUtils.toString(response.getEntity()); -// -// return strResult; -// } -// } -// catch (IOException e) { -// logger.error(e.getMessage()); -// throw new RuntimeException(e); -// } -// -// return null; -// } + /** + * get请求 + * @return + */ + public static String doGet(String url) { + try { + CloseableHttpClient client = HttpClients.createDefault(); + //发送get请求 + HttpGet request = new HttpGet(url); + HttpResponse response = client.execute(request); + + /**请求发送成功,并得到响应**/ + if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { + /**读取服务器返回过来的json字符串数据**/ + String strResult = EntityUtils.toString(response.getEntity()); + + return strResult; + } + } + catch (IOException e) { + logger.error(e.getMessage()); + throw new RuntimeException(e); + } + + return null; + } /** * get请求