Commit 2ce01ec6 authored by kongfm's avatar kongfm

查看电梯时添加二维码

parent 704398d5
......@@ -122,4 +122,45 @@ public class QRCodeUtil {
}
return null;
}
/**
* 根据二维码信息,生成二维码图片 用户excel,word等导出图片 可自定义图片大小
*
* @param content
* @return
*/
public static byte[] generateQRCodeImageByteData(String content, int size) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
Hashtable<EncodeHintType, Object> hints = new Hashtable<EncodeHintType, Object>();
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
hints.put(EncodeHintType.CHARACTER_SET, CHARSET);
hints.put(EncodeHintType.MARGIN, 1);
BitMatrix bitMatrix = new MultiFormatWriter().encode(
content
, BarcodeFormat.QR_CODE
, size
, size,
hints);
int width = bitMatrix.getWidth();
int height = bitMatrix.getHeight();
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
image.setRGB(x, y, bitMatrix.get(x, y) ? 0xFF000000 : 0xFFFFFFFF);
}
}
ImageIO.write(image, "png", out);
return out.toByteArray();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
}
......@@ -16,4 +16,11 @@ public interface IElevatorService extends IService<Elevator> {
* @return
*/
Elevator selectByAlertId(Long alertId);
/**
* 根据电梯id 生成电梯二维码
* @param elevatorId
* @return
*/
String saveElevatorQrCode(Long elevatorId);
}
......@@ -145,7 +145,7 @@ public class ElevatorController extends BaseController {
* @param sequenceNbr sequenceNbr
* @return 返回结果
*/
@TycloudOperation(needAuth = false, ApiLevel = UserType.AGENCY)
@TycloudOperation(ApiLevel = UserType.AGENCY)
@RequestMapping(value = "/{sequenceNbr}", method = RequestMethod.GET)
@ApiOperation(httpMethod = "GET", value = "根据id查询", notes = "根据id查询")
public ResponseModel<com.yeejoin.amos.boot.module.tzs.api.dto.ElevatorDto> selectById(@PathVariable Long sequenceNbr) {
......
package com.yeejoin.amos.boot.module.tzs.biz.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.google.common.collect.Lists;
import com.yeejoin.amos.boot.biz.common.utils.QRCodeUtil;
import com.yeejoin.amos.boot.module.common.api.dto.AttachmentDto;
import com.yeejoin.amos.boot.module.common.biz.service.impl.SourceFileServiceImpl;
import com.yeejoin.amos.boot.module.tzs.api.dto.AlertCalledDto;
import com.yeejoin.amos.boot.module.tzs.api.dto.ElevatorDto;
......@@ -10,13 +13,22 @@ import com.yeejoin.amos.boot.module.tzs.api.dto.ElevatorWlInfoDto;
import com.yeejoin.amos.boot.module.tzs.api.entity.Elevator;
import com.yeejoin.amos.boot.module.tzs.api.mapper.ElevatorMapper;
import com.yeejoin.amos.boot.module.tzs.api.service.IElevatorService;
import com.yeejoin.amos.component.feign.model.FeignClientResult;
import com.yeejoin.amos.feign.systemctl.Systemctl;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import org.typroject.tyboot.core.rdbms.service.BaseService;
import org.typroject.tyboot.core.restful.exception.instance.BadRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 服务实现类
......@@ -27,6 +39,9 @@ import java.util.List;
@Service
public class ElevatorServiceImpl extends BaseService<ElevatorDto, Elevator, ElevatorMapper> implements IElevatorService {
private final Logger logger = LogManager.getLogger(ElevatorServiceImpl.class);
@Autowired
SourceFileServiceImpl sourceFileService;
......@@ -36,6 +51,7 @@ public class ElevatorServiceImpl extends BaseService<ElevatorDto, Elevator, Elev
@Autowired
ElevatorMapper elevatorMapper;
/**
* 保存电梯信息
*
......@@ -89,9 +105,17 @@ public class ElevatorServiceImpl extends BaseService<ElevatorDto, Elevator, Elev
*/
public ElevatorDto selectBySeq(Long sequenceNbr) {
ElevatorDto elevatorDto = this.queryBySeq(sequenceNbr);
Map<String, List<AttachmentDto>> attachment = sourceFileService.getAttachments(sequenceNbr);
// 获取附件
elevatorDto.setAttachments(sourceFileService.getAttachments(sequenceNbr));
elevatorDto.setAttachments(attachment);
// 判断是否存在qrcode 如果不存在则生成qrcode
if(attachment.get("qrCode") == null) {
this.saveElevatorQrCode(sequenceNbr);
attachment = sourceFileService.getAttachments(sequenceNbr);
// 获取附件
elevatorDto.setAttachments(attachment);
}
return elevatorDto;
}
......@@ -113,6 +137,41 @@ public class ElevatorServiceImpl extends BaseService<ElevatorDto, Elevator, Elev
return elevator;
}
@Override
public String saveElevatorQrCode(Long elevatorId) {
// 二维码生成规则
JSONObject qrString = new JSONObject();
Elevator elevator = this.getById(elevatorId);
if(elevator == null) {
throw new BadRequest("未找到电梯数据");
}
qrString.put("elevatorId",elevator.getSequenceNbr());
qrString.put("rescueCode",elevator.getRescueCode());
byte[] bytes = QRCodeUtil.generateQRCodeImageByteData(qrString.toJSONString(), 480);
MultipartFile file = new MockMultipartFile("elevator_" + elevator.getSequenceNbr() + ".png","elevator_" + elevator.getSequenceNbr() + ".png","application/octet-stream" ,bytes);
FeignClientResult<Map<String, String>> result = Systemctl.fileStorageClient.updateCommonFile(file);
Map<String, String> map = result.getResult();
if(map.isEmpty()) {
logger.error("未生成二维码文件");
throw new BadRequest("未生成二维码文件");
}
String filePath = "";
for(Map.Entry<String,String> fileResult : map.entrySet()) {
filePath = fileResult.getKey();
}
// 保存qrCode
List<AttachmentDto> qrCode = new ArrayList<>();
AttachmentDto temp = new AttachmentDto();
temp.setName("elevator_" + elevator.getSequenceNbr() + ".png");
temp.setType("image");
temp.setUrl(filePath);
qrCode.add(temp);
Map<String, List<AttachmentDto>> attachmentMap = new HashMap<>();
attachmentMap.put("qrCode",qrCode);
sourceFileService.saveAttachments(elevatorId,attachmentMap);
return filePath;
}
public List<ElevatorWlInfoDto> queryElevatorList(ElevatorWlInfoDto esElevatorDto) {
return elevatorMapper.queryElevatorList(esElevatorDto.getAddress(),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment