|
|
@ -24,6 +24,7 @@ import com.epmet.commons.tools.redis.common.bean.HouseInfoCache; |
|
|
|
import com.epmet.commons.tools.security.dto.TokenDto; |
|
|
|
import com.epmet.commons.tools.utils.BarcodeUtils; |
|
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
|
import com.epmet.commons.tools.utils.FileUtils; |
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
import com.epmet.constant.CustomerGridConstant; |
|
|
|
import com.epmet.constants.ImportTaskConstants; |
|
|
@ -46,19 +47,21 @@ 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; |
|
|
|
import com.google.common.cache.Cache; |
|
|
|
import com.google.common.cache.CacheBuilder; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.fileupload.FileItem; |
|
|
|
import org.apache.commons.fileupload.disk.DiskFileItemFactory; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.apache.http.entity.ContentType; |
|
|
|
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 org.springframework.web.multipart.commons.CommonsMultipartFile; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import javax.imageio.ImageIO; |
|
|
@ -887,36 +890,49 @@ public class HouseServiceImpl implements HouseService, ResultDataResolver { |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public String createHouseQrcodeUrl(String houseId) { |
|
|
|
public String createHouseQrcodeUrl(String houseId) throws Exception { |
|
|
|
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(); |
|
|
|
String fileName = house.getNeighborHoodName() + house.getBuildingName() +house.getUnitNum()+ house.getDoorName()+".png"; |
|
|
|
BufferedImage image = BarcodeUtils.drawQRImage(house.getNeighborHoodName() + house.getBuildingName() + house.getUnitNum() + house.getDoorName(), url); |
|
|
|
|
|
|
|
//BufferedImage 转化为 ByteArrayOutputStream
|
|
|
|
ByteArrayOutputStream out = new ByteArrayOutputStream(); |
|
|
|
ImageIO.write(image, "png", out); |
|
|
|
//ByteArrayOutputStream 转化为 byte[]
|
|
|
|
byte[] imageByte = out.toByteArray(); |
|
|
|
//将 byte[] 转为 MultipartFile
|
|
|
|
MultipartFile multipartFile = new ConvertToMultipartFile(imageByte, "newNamepic", "pic1", "png", imageByte.length); |
|
|
|
Result<UploadImgResultDTO> uploadResult = ossFeignClient.uploadQrCodeV2(multipartFile,house.getCustomerId()); |
|
|
|
|
|
|
|
FileItem fileItem = new DiskFileItemFactory(DiskFileItemFactory.DEFAULT_SIZE_THRESHOLD, FileUtils.getAndCreateDirUnderEpmetFilesDir("temp").toFile()) |
|
|
|
.createItem("file", ContentType.APPLICATION_OCTET_STREAM.toString(), false, fileName); |
|
|
|
OutputStream os = fileItem.getOutputStream(); |
|
|
|
Result<UploadImgResultDTO> uploadResult = null; |
|
|
|
try { |
|
|
|
ImageIO.write(image, "png", os); |
|
|
|
uploadResult = ossFeignClient.uploadImportTaskDescFile(new CommonsMultipartFile(fileItem)); |
|
|
|
} catch (Exception e) { |
|
|
|
String errormsg = ExceptionUtils.getErrorStackTrace(e); |
|
|
|
log.error("上传一户一档二维码:{}", errormsg); |
|
|
|
} finally { |
|
|
|
try { |
|
|
|
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(), "上传一户一档二维码失败", "上传一户一档二维码失败"); |
|
|
|
} else { |
|
|
|
return uploadResult.getData().getUrl(); |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
String errormsg = ExceptionUtils.getErrorStackTrace(e); |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "上传一户一档二维码失败" + errormsg, "上传一户一档二维码失败" + errormsg); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|