|
@ -1,19 +1,19 @@ |
|
|
package com.epmet.service.impl; |
|
|
package com.epmet.service.impl; |
|
|
|
|
|
|
|
|
import cn.afterturn.easypoi.excel.entity.TemplateExportParams; |
|
|
import cn.afterturn.easypoi.excel.entity.TemplateExportParams; |
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
import com.epmet.commons.tools.enums.NeighborHoodUrlEnum; |
|
|
import com.epmet.commons.tools.enums.CollectUrlEnum; |
|
|
import com.epmet.commons.tools.enums.OrgTypeEnum; |
|
|
import com.epmet.commons.tools.enums.OrgTypeEnum; |
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
import com.epmet.commons.tools.exception.EpmetException; |
|
|
import com.epmet.commons.tools.exception.EpmetException; |
|
|
import com.epmet.commons.tools.exception.ExceptionUtils; |
|
|
|
|
|
import com.epmet.commons.tools.exception.RenException; |
|
|
import com.epmet.commons.tools.exception.RenException; |
|
|
import com.epmet.commons.tools.page.PageData; |
|
|
import com.epmet.commons.tools.page.PageData; |
|
|
import com.epmet.commons.tools.utils.BarcodeUtils; |
|
|
|
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
import com.epmet.commons.tools.utils.FileUtils; |
|
|
import com.epmet.commons.tools.utils.HttpClientManager; |
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
import com.epmet.constant.NeighborhoodConstant; |
|
|
import com.epmet.constant.NeighborhoodConstant; |
|
|
import com.epmet.dao.CustomerGridDao; |
|
|
import com.epmet.dao.CustomerGridDao; |
|
@ -39,28 +39,23 @@ import com.epmet.excel.IcNeighborHoodExcel; |
|
|
import com.epmet.feign.EpmetUserOpenFeignClient; |
|
|
import com.epmet.feign.EpmetUserOpenFeignClient; |
|
|
import com.epmet.feign.GovOrgOpenFeignClient; |
|
|
import com.epmet.feign.GovOrgOpenFeignClient; |
|
|
import com.epmet.feign.OssFeignClient; |
|
|
import com.epmet.feign.OssFeignClient; |
|
|
|
|
|
import com.epmet.resi.group.dto.QRCodeMultipartFileDTO; |
|
|
import com.epmet.service.IcNeighborHoodPropertyService; |
|
|
import com.epmet.service.IcNeighborHoodPropertyService; |
|
|
import com.epmet.service.IcNeighborHoodService; |
|
|
import com.epmet.service.IcNeighborHoodService; |
|
|
import com.epmet.service.NeighborHoodService; |
|
|
import com.epmet.service.NeighborHoodService; |
|
|
import com.epmet.util.ExcelPoiUtils; |
|
|
import com.epmet.util.ExcelPoiUtils; |
|
|
|
|
|
import com.epmet.utils.ThirdUtils; |
|
|
import com.github.pagehelper.PageHelper; |
|
|
import com.github.pagehelper.PageHelper; |
|
|
import com.github.pagehelper.PageInfo; |
|
|
import com.github.pagehelper.PageInfo; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import org.apache.commons.fileupload.FileItem; |
|
|
|
|
|
import org.apache.commons.fileupload.disk.DiskFileItemFactory; |
|
|
|
|
|
import org.apache.http.entity.ContentType; |
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
import org.springframework.util.StringUtils; |
|
|
import org.springframework.util.StringUtils; |
|
|
import org.springframework.web.multipart.commons.CommonsMultipartFile; |
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
import javax.annotation.Resource; |
|
|
import javax.imageio.ImageIO; |
|
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
import java.awt.image.BufferedImage; |
|
|
import java.nio.charset.StandardCharsets; |
|
|
import java.io.IOException; |
|
|
|
|
|
import java.io.OutputStream; |
|
|
|
|
|
import java.util.HashMap; |
|
|
import java.util.HashMap; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
import java.util.Map; |
|
|
import java.util.Map; |
|
@ -134,7 +129,7 @@ public class NeighborHoodServiceImpl extends BaseServiceImpl<IcNeighborHoodDao,I |
|
|
IcNeighborHoodEntity neiEntity = new IcNeighborHoodEntity(); |
|
|
IcNeighborHoodEntity neiEntity = new IcNeighborHoodEntity(); |
|
|
neiEntity.setId(entity.getId()); |
|
|
neiEntity.setId(entity.getId()); |
|
|
try { |
|
|
try { |
|
|
neiEntity.setQrcodeUrl(createNeiQrcodeUrl(entity.getId(),entity.getNeighborHoodName())); |
|
|
neiEntity.setQrcodeUrl(createNeiQrcodeUrl(entity)); |
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),"二维码生成失败","二维码生成失败"); |
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),"二维码生成失败","二维码生成失败"); |
|
|
} |
|
|
} |
|
@ -148,45 +143,44 @@ public class NeighborHoodServiceImpl extends BaseServiceImpl<IcNeighborHoodDao,I |
|
|
* @params [NeighborHood] |
|
|
* @params [NeighborHood] |
|
|
* @return java.lang.String |
|
|
* @return java.lang.String |
|
|
*/ |
|
|
*/ |
|
|
private String createNeiQrcodeUrl(String NeighborHood,String neighborHoodName) throws Exception { |
|
|
private String createNeiQrcodeUrl(IcNeighborHoodEntity entity) throws Exception { |
|
|
if (org.apache.commons.lang3.StringUtils.isBlank(NeighborHood)) { |
|
|
if (null == entity) { |
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "小区id不可为空", "小区id不可为空"); |
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "小区不可为空", "小区不可为空"); |
|
|
} |
|
|
} |
|
|
//二维码内容地址
|
|
|
//获取AccessToken
|
|
|
String url = NeighborHoodUrlEnum.URL_PRE.getCode()+"?neiId="+NeighborHood; |
|
|
String accessToken = ThirdUtils.getAccessToken(entity.getCustomerId()).getResiToken(); |
|
|
|
|
|
if (org.apache.commons.lang3.StringUtils.isBlank(accessToken)) { |
|
|
String fileName = neighborHoodName + ".png"; |
|
|
log.warn("获取accessToken失败,customerId:{}", entity.getCustomerId()); |
|
|
BufferedImage image = BarcodeUtils.drawQRImage(neighborHoodName, url); |
|
|
throw new RenException("获取accessToken失败,customerId:{}", entity.getCustomerId()); |
|
|
|
|
|
} |
|
|
|
|
|
//跳转的页面
|
|
|
|
|
|
StringBuilder path = new StringBuilder(CollectUrlEnum.URL_PRE.getCode()); |
|
|
|
|
|
path.append("?neiId=").append(entity.getId()).append("&agencyId=").append(entity.getAgencyId()); |
|
|
|
|
|
|
|
|
FileItem fileItem = new DiskFileItemFactory(DiskFileItemFactory.DEFAULT_SIZE_THRESHOLD, FileUtils.getAndCreateDirUnderEpmetFilesDir("temp").toFile()) |
|
|
//需要发送的Json
|
|
|
.createItem("file", ContentType.APPLICATION_OCTET_STREAM.toString(), false, fileName); |
|
|
JSONObject data = new JSONObject(); |
|
|
OutputStream os = fileItem.getOutputStream(); |
|
|
data.put("path", path.toString()); |
|
|
Result<UploadImgResultDTO> uploadResult = null; |
|
|
data.put("width", 400); |
|
|
try { |
|
|
//发送
|
|
|
ImageIO.write(image, "png", os); |
|
|
byte[] buffer = HttpClientManager.getInstance().getMediaByteArray(CollectUrlEnum.GET_CODE_URL.getCode() + accessToken, JSON.toJSONString(data)).getData(); |
|
|
uploadResult = ossFeignClient.uploadImportTaskDescFile(new CommonsMultipartFile(fileItem)); |
|
|
if (buffer != null && buffer.length < 500) { |
|
|
} catch (Exception e) { |
|
|
String wxResult = ""; |
|
|
String errormsg = ExceptionUtils.getErrorStackTrace(e); |
|
|
wxResult = new String(buffer, StandardCharsets.UTF_8); |
|
|
log.error("上传小区二维码:{}", errormsg); |
|
|
if (-1 != wxResult.indexOf("errcode")) { |
|
|
} finally { |
|
|
log.error("获取二维码接口返回错误:{}", wxResult); |
|
|
try { |
|
|
throw new RenException("获取二维码失败"); |
|
|
os.close(); |
|
|
|
|
|
} catch (IOException e) { |
|
|
|
|
|
String errormsg = ExceptionUtils.getErrorStackTrace(e); |
|
|
|
|
|
log.error("上传小区二维码关闭输出流:{}", errormsg); |
|
|
|
|
|
} |
|
|
|
|
|
try { |
|
|
|
|
|
fileItem.delete(); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
String errormsg = ExceptionUtils.getErrorStackTrace(e); |
|
|
|
|
|
log.error("上传小区二维码删除临时文件:{}", errormsg); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
if (uploadResult == null || !uploadResult.success()) { |
|
|
//上传
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "上传小区二维码失败", "上传小区二维码失败"); |
|
|
QRCodeMultipartFileDTO qrCodeMultipartFile = new QRCodeMultipartFileDTO(); |
|
|
} else { |
|
|
qrCodeMultipartFile.setBytes(buffer); |
|
|
return uploadResult.getData().getUrl(); |
|
|
String originalFilename = entity.getNeighborHoodName().concat(".jpg"); |
|
|
|
|
|
qrCodeMultipartFile.setOriginalFilename(originalFilename); |
|
|
|
|
|
Result<UploadImgResultDTO> uploadResult = ossFeignClient.uploadQrCode(qrCodeMultipartFile); |
|
|
|
|
|
if (!uploadResult.success()) { |
|
|
|
|
|
throw new RenException("调用oss服务上传活动居民信息录入码失败"); |
|
|
} |
|
|
} |
|
|
|
|
|
return uploadResult.getData().getUrl(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -356,7 +350,7 @@ public class NeighborHoodServiceImpl extends BaseServiceImpl<IcNeighborHoodDao,I |
|
|
neiList.forEach(nei->{ |
|
|
neiList.forEach(nei->{ |
|
|
if(org.apache.commons.lang3.StringUtils.isBlank(nei.getQrcodeUrl())){ |
|
|
if(org.apache.commons.lang3.StringUtils.isBlank(nei.getQrcodeUrl())){ |
|
|
try { |
|
|
try { |
|
|
nei.setQrcodeUrl(createNeiQrcodeUrl(nei.getId(),nei.getNeighborHoodName())); |
|
|
nei.setQrcodeUrl(createNeiQrcodeUrl(nei)); |
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
e.printStackTrace(); |
|
|
e.printStackTrace(); |
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),"二维码生成失败<neiId>:"+nei.getId(),"二维码生成失败<neiId>:"+nei.getId()); |
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),"二维码生成失败<neiId>:"+nei.getId(),"二维码生成失败<neiId>:"+nei.getId()); |
|
|