|
|
@ -17,17 +17,19 @@ |
|
|
|
|
|
|
|
package com.epmet.controller; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.epmet.commons.rocketmq.messages.OrgOrStaffMQMsg; |
|
|
|
import com.epmet.commons.tools.annotation.LoginUser; |
|
|
|
import com.epmet.commons.tools.annotation.RequirePermission; |
|
|
|
import com.epmet.commons.tools.constant.StrConstant; |
|
|
|
import com.epmet.commons.tools.enums.EnvEnum; |
|
|
|
import com.epmet.commons.tools.enums.CollectUrlEnum; |
|
|
|
import com.epmet.commons.tools.enums.RequirePermissionEnum; |
|
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
|
import com.epmet.commons.tools.exception.EpmetException; |
|
|
|
import com.epmet.commons.tools.exception.RenException; |
|
|
|
import com.epmet.commons.tools.security.dto.TokenDto; |
|
|
|
import com.epmet.commons.tools.utils.BarcodeUtils; |
|
|
|
import com.epmet.commons.tools.utils.HttpClientManager; |
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
import com.epmet.commons.tools.validator.ValidatorUtils; |
|
|
|
import com.epmet.constant.CustomerAgencyConstant; |
|
|
@ -37,10 +39,13 @@ import com.epmet.dto.form.*; |
|
|
|
import com.epmet.dto.result.*; |
|
|
|
import com.epmet.entity.CustomerAgencyEntity; |
|
|
|
import com.epmet.feign.EpmetMessageOpenFeignClient; |
|
|
|
import com.epmet.feign.OssFeignClient; |
|
|
|
import com.epmet.resi.group.dto.QRCodeMultipartFileDTO; |
|
|
|
import com.epmet.send.SendMqMsgUtil; |
|
|
|
import com.epmet.service.AgencyService; |
|
|
|
import com.epmet.service.CustomerAgencyService; |
|
|
|
import com.epmet.service.IcNeighborHoodService; |
|
|
|
import com.epmet.utils.ThirdUtils; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
@ -55,9 +60,9 @@ import java.io.ByteArrayInputStream; |
|
|
|
import java.io.ByteArrayOutputStream; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.io.OutputStream; |
|
|
|
import java.net.URL; |
|
|
|
import java.net.URLEncoder; |
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.time.ZoneOffset; |
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
@ -81,6 +86,8 @@ public class AgencyController { |
|
|
|
private EpmetMessageOpenFeignClient epmetMessageOpenFeignClient; |
|
|
|
@Autowired |
|
|
|
private IcNeighborHoodService neighborHoodService; |
|
|
|
@Autowired |
|
|
|
private OssFeignClient ossFeignClient; |
|
|
|
|
|
|
|
/** |
|
|
|
* @param formDTO |
|
|
@ -399,41 +406,60 @@ public class AgencyController { |
|
|
|
public void createQrCode(@LoginUser TokenDto tokenDto, @RequestBody CreateQrCodeFormDTO formDTO, HttpServletResponse response) { |
|
|
|
ValidatorUtils.validateEntity(formDTO, CreateQrCodeFormDTO.CreateQrCodeForm.class); |
|
|
|
String id = formDTO.getId(); |
|
|
|
String type = formDTO.getType(); |
|
|
|
String name = ""; |
|
|
|
if(!formDTO.getType().equals(OrgInfoConstant.COMMUNITY)){ |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "只可生成社区码"); |
|
|
|
} |
|
|
|
try { |
|
|
|
if (type.equals(OrgInfoConstant.COMMUNITY)) { |
|
|
|
//获取AccessToken
|
|
|
|
String accessToken = ThirdUtils.getAccessToken(tokenDto.getCustomerId()).getResiToken(); |
|
|
|
if (org.apache.commons.lang3.StringUtils.isBlank(accessToken)) { |
|
|
|
log.warn("获取accessToken失败,customerId:{}", tokenDto.getCustomerId()); |
|
|
|
throw new RenException("获取accessToken失败,customerId:{}", tokenDto.getCustomerId()); |
|
|
|
} |
|
|
|
CustomerAgencyDTO customerAgencyDTO = customerAgencyService.get(id); |
|
|
|
if (customerAgencyDTO == null) { |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "组织信息不存在"); |
|
|
|
} |
|
|
|
name = customerAgencyDTO.getOrganizationName(); |
|
|
|
} else { |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "小区信息不存在"); |
|
|
|
} |
|
|
|
//url组成:数字社区地址?小区id&用户id
|
|
|
|
//String url = "https://demo.tduckapp.com/s/7314b64b3a26455ab793fb8c640856b6?id="+id;
|
|
|
|
String url = EnvEnum.getCurrentEnv().getUrl() |
|
|
|
.replace("cloud", "open") |
|
|
|
.replace("api/", StrConstant.EPMETY_STR) |
|
|
|
.concat("epmet-oper-gov/#/caiji/") |
|
|
|
.concat(id).concat("?") |
|
|
|
.concat("name=").concat(URLEncoder.encode(name, StrConstant.UTF_8)).concat(StrConstant.AND_MARK) |
|
|
|
.concat("customerId=").concat(tokenDto.getCustomerId()).concat(StrConstant.AND_MARK) |
|
|
|
.concat("type=").concat(type).concat(StrConstant.AND_MARK) |
|
|
|
.concat("userId=").concat(tokenDto.getUserId()) |
|
|
|
.concat(StrConstant.AND_MARK).concat(String.valueOf(LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli())); |
|
|
|
BufferedImage image = BarcodeUtils.drawQRImage(name, url); |
|
|
|
//BufferedImage 转 InputStream
|
|
|
|
//url组成:信息采集地址?社区id
|
|
|
|
StringBuilder path = new StringBuilder(CollectUrlEnum.URL_PRE.getCode()); |
|
|
|
path.append("?agencyId=").append(formDTO.getId()); |
|
|
|
//需要发送的Json
|
|
|
|
JSONObject data = new JSONObject(); |
|
|
|
data.put("path", path.toString()); |
|
|
|
data.put("width", 400); |
|
|
|
//发送
|
|
|
|
byte[] buffer = HttpClientManager.getInstance().getMediaByteArray(CollectUrlEnum.GET_CODE_URL.getCode() + accessToken, JSON.toJSONString(data)).getData(); |
|
|
|
if (buffer != null && buffer.length < 500) { |
|
|
|
String wxResult = ""; |
|
|
|
wxResult = new String(buffer, StandardCharsets.UTF_8); |
|
|
|
if (-1 != wxResult.indexOf("errcode")) { |
|
|
|
log.error("获取二维码接口返回错误:{}", wxResult); |
|
|
|
throw new RenException("获取二维码失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
//上传
|
|
|
|
QRCodeMultipartFileDTO qrCodeMultipartFile = new QRCodeMultipartFileDTO(); |
|
|
|
qrCodeMultipartFile.setBytes(buffer); |
|
|
|
String originalFilename = name.concat(".jpg"); |
|
|
|
qrCodeMultipartFile.setOriginalFilename(originalFilename); |
|
|
|
Result<UploadImgResultDTO> uploadResult = ossFeignClient.uploadQrCode(qrCodeMultipartFile); |
|
|
|
if (!uploadResult.success()) { |
|
|
|
throw new RenException("调用oss服务上传活动居民信息录入码失败"); |
|
|
|
} |
|
|
|
|
|
|
|
URL url = new URL(uploadResult.getData().getUrl()); |
|
|
|
BufferedImage img = ImageIO.read(url); |
|
|
|
|
|
|
|
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); |
|
|
|
ImageOutputStream imageOutput = ImageIO.createImageOutputStream(byteArrayOutputStream); |
|
|
|
ImageIO.write(image, "png", imageOutput); |
|
|
|
ImageIO.write(img, "png", imageOutput); |
|
|
|
InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray()); |
|
|
|
long length = imageOutput.length(); |
|
|
|
String fileName = name + ".png"; |
|
|
|
response.setContentType("application/octet-stream"); |
|
|
|
response.setContentLength((int) length); |
|
|
|
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, StrConstant.UTF_8)); |
|
|
|
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(originalFilename, StrConstant.UTF_8)); |
|
|
|
|
|
|
|
//输出流
|
|
|
|
byte[] bytes = new byte[1024]; |
|
|
@ -445,6 +471,7 @@ public class AgencyController { |
|
|
|
outputStream.write(bytes, 0, len); |
|
|
|
} |
|
|
|
outputStream.flush(); |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
log.error("method exception", e); |
|
|
|
} |
|
|
|