Browse Source

上传一户一档二维码

master
Jackwang 3 years ago
parent
commit
59a5e95e03
  1. 12
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/HouseController.java
  2. 9
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/HouseService.java
  3. 39
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/HouseServiceImpl.java
  4. 3
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/IcNeighborHoodServiceImpl.java
  5. 64
      epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/util/ConvertToMultipartFile.java

12
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/HouseController.java

@ -52,6 +52,7 @@ import com.epmet.dto.form.*;
import com.epmet.dto.result.*;
import com.epmet.feign.EpmetCommonServiceOpenFeignClient;
import com.epmet.feign.EpmetUserOpenFeignClient;
import com.epmet.feign.OssFeignClient;
import com.epmet.service.HouseService;
import com.epmet.util.ExcelPoiUtils;
import com.google.common.cache.Cache;
@ -426,11 +427,12 @@ public class HouseController implements ResultDataResolver {
}
/**
* Desc: 生成某类型下的二维码
* @param formDTO
* @author zxc
* @date 2022/3/2 10:32 上午
*/
* @describe: 下载房屋编码
* @author wangtong
* @date 2022/6/1 17:24
* @params [formDTO, response]
* @return void
*/
@PostMapping("createHouseQrcode")
public void createQrCode(@RequestBody HouseQrcodeFormDTO formDTO, HttpServletResponse response){
ValidatorUtils.validateEntity(formDTO);

9
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/HouseService.java

@ -136,4 +136,13 @@ public interface HouseService {
* @return java.lang.String
*/
String createHouseCode(String customerId,String buildingId,String areaCode);
/**
* @describe: 生成一户一码的二维码地址
* @author wangtong
* @date 2022/6/1 17:41
* @params [houseId]
* @return java.lang.String
*/
String createHouseQrcodeUrl(String houseId);
}

39
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/HouseServiceImpl.java

@ -12,6 +12,7 @@ import com.epmet.commons.tools.enums.HouseQrcodeEnum;
import com.epmet.commons.tools.enums.OrgTypeEnum;
import com.epmet.commons.tools.exception.EpmetErrorCode;
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.feign.ResultDataResolver;
import com.epmet.commons.tools.page.PageData;
@ -38,10 +39,12 @@ import com.epmet.enums.HouseRentFlagEnums;
import com.epmet.enums.HouseTypeEnums;
import com.epmet.feign.EpmetCommonServiceOpenFeignClient;
import com.epmet.feign.EpmetUserOpenFeignClient;
import com.epmet.feign.OssFeignClient;
import com.epmet.model.HouseInfoModel;
import com.epmet.model.ImportHouseInfoListener;
import com.epmet.redis.IcHouseRedis;
import com.epmet.service.*;
import com.epmet.util.ConvertToMultipartFile;
import com.epmet.util.ExcelPoiUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
@ -53,6 +56,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.imageio.ImageIO;
@ -114,6 +118,8 @@ public class HouseServiceImpl implements HouseService, ResultDataResolver {
private HouseService houseService;
@Autowired
private IcHouseCodeInfoDao icHouseCodeInfoDao;
@Autowired
private OssFeignClient ossFeignClient;
@Override
@ -873,6 +879,39 @@ public class HouseServiceImpl implements HouseService, ResultDataResolver {
return result;
}
@Override
public String createHouseQrcodeUrl(String houseId) {
if (StringUtils.isBlank(houseId)) {
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "房屋id不可为空", "房屋id不可为空");
}
try {
IcHouseListResultDTO house = icHouseDao.selectHouseQrcodeById(houseId);
if (null == house) {
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "未查到房屋信息", "未查到房屋信息");
}
//url组成:小程序地址?房屋编码
String url = HouseQrcodeEnum.PREFIX.getCode() + "?houseCode=" + house.getHouseCode();
BufferedImage image = BarcodeUtils.drawQRImage(house.getNeighborHoodName() + house.getBuildingName() + house.getUnitNum() + house.getDoorName(), url);
//BufferedImage 转化为 ByteArrayOutputStream
ByteArrayOutputStream out = new ByteArrayOutputStream();
ImageIO.write(image, "jpg", out);
//ByteArrayOutputStream 转化为 byte[]
byte[] imageByte = out.toByteArray();
//将 byte[] 转为 MultipartFile
MultipartFile multipartFile = new ConvertToMultipartFile(imageByte, "newNamepic", "pic1", "jpg", imageByte.length);
Result<UploadImgResultDTO> uploadResult = ossFeignClient.uploadImportTaskDescFile(multipartFile);
if (uploadResult == null || !uploadResult.success()) {
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "上传一户一档二维码失败", "上传一户一档二维码失败");
} else {
return uploadResult.getData().getUrl();
}
} catch (Exception e) {
String errormsg = ExceptionUtils.getErrorStackTrace(e);
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "上传一户一档二维码失败" + errormsg, "上传一户一档二维码失败" + errormsg);
}
}
/**
* @return java.lang.String

3
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/IcNeighborHoodServiceImpl.java

@ -58,7 +58,6 @@ import com.epmet.dto.result.UploadImgResultDTO;
import com.epmet.entity.*;
import com.epmet.excel.IcNeighborHoodExcel;
import com.epmet.feign.EpmetCommonServiceOpenFeignClient;
import com.epmet.feign.OssFeignClient;
import com.epmet.model.ImportNeighborHoodInfoListener;
import com.epmet.model.NeighborHoodInfoModel;
import com.epmet.redis.IcHouseRedis;
@ -118,7 +117,7 @@ public class IcNeighborHoodServiceImpl extends BaseServiceImpl<IcNeighborHoodDao
@Autowired
private EpmetCommonServiceOpenFeignClient epmetCommonServiceOpenFeignClient;
@Autowired
private OssFeignClient ossFeignClient;
private OssFeignClient1 ossFeignClient;
@Autowired
private ExecutorService executorService;

64
epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/util/ConvertToMultipartFile.java

@ -0,0 +1,64 @@
package com.epmet.util;
import org.springframework.web.multipart.MultipartFile;
import java.io.*;
public class ConvertToMultipartFile implements MultipartFile {
private byte[] fileBytes;
String name;
String originalFilename;
String contentType;
boolean isEmpty;
long size;
public ConvertToMultipartFile(byte[] fileBytes, String name, String originalFilename, String contentType,
long size) {
this.fileBytes = fileBytes;
this.name = name;
this.originalFilename = originalFilename;
this.contentType = contentType;
this.size = size;
this.isEmpty = false;
}
@Override
public String getName() {
return name;
}
@Override
public String getOriginalFilename() {
return originalFilename;
}
@Override
public String getContentType() {
return contentType;
}
@Override
public boolean isEmpty() {
return isEmpty;
}
@Override
public long getSize() {
return size;
}
@Override
public byte[] getBytes() throws IOException {
return fileBytes;
}
@Override
public InputStream getInputStream() throws IOException {
return new ByteArrayInputStream(fileBytes);
}
@Override
public void transferTo(File dest) throws IOException, IllegalStateException {
new FileOutputStream(dest).write(fileBytes);
}
}
Loading…
Cancel
Save