feat: 设备二维码优化
This commit is contained in:
parent
96d52dcdb2
commit
8371104912
|
|
@ -708,7 +708,7 @@ public class DeviceController extends ControllerBase {
|
||||||
devices.forEach(device -> {
|
devices.forEach(device -> {
|
||||||
try {
|
try {
|
||||||
DeviceQRCodeVO vo=new DeviceQRCodeVO();
|
DeviceQRCodeVO vo=new DeviceQRCodeVO();
|
||||||
byte[] bytes=deviceQRCodeService.generate(device.getDeviceNo());
|
byte[] bytes=deviceQRCodeService.generate(device.getDeviceNo(),device.getModelNo());
|
||||||
vo.setDeviceNo(device.getDeviceNo());
|
vo.setDeviceNo(device.getDeviceNo());
|
||||||
vo.setUrl(fileUploadService.upload("temp/qrcode/device/"+IdUtil.fastUUID()+".png",new ByteArrayInputStream(bytes)));
|
vo.setUrl(fileUploadService.upload("temp/qrcode/device/"+IdUtil.fastUUID()+".png",new ByteArrayInputStream(bytes)));
|
||||||
vos.add(vo);
|
vos.add(vo);
|
||||||
|
|
@ -725,14 +725,14 @@ public class DeviceController extends ControllerBase {
|
||||||
*/
|
*/
|
||||||
@PostMapping("exportImages")
|
@PostMapping("exportImages")
|
||||||
public ResponseEntity<byte[]> exportImages(@Valid @RequestBody IdPostRequest request){
|
public ResponseEntity<byte[]> exportImages(@Valid @RequestBody IdPostRequest request){
|
||||||
Collection<String> deviceNos=deviceService.listByIds(request.getIds()).stream().map(Device::getDeviceNo).collect(Collectors.toSet());
|
List<Device> devices=deviceService.listByIds(request.getIds());
|
||||||
if (CollUtil.isNotEmpty(deviceNos)){
|
if (CollUtil.isNotEmpty(devices)){
|
||||||
try {
|
try {
|
||||||
if (deviceNos.size()==1){
|
if (devices.size()==1){
|
||||||
String deviceNo=deviceNos.stream().findFirst().get();
|
Device device=devices.get(0);
|
||||||
byte[] bytes=deviceQRCodeService.generate(deviceNo);
|
byte[] bytes=deviceQRCodeService.generate(device.getDeviceNo(),device.getModelNo());
|
||||||
HttpHeaders headers = new HttpHeaders();
|
HttpHeaders headers = new HttpHeaders();
|
||||||
headers.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename="+ deviceNo+".jpg");
|
headers.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename="+ device.getDeviceNo()+".jpg");
|
||||||
return ResponseEntity.ok()
|
return ResponseEntity.ok()
|
||||||
.headers(headers)
|
.headers(headers)
|
||||||
.contentType(MediaType.APPLICATION_OCTET_STREAM)
|
.contentType(MediaType.APPLICATION_OCTET_STREAM)
|
||||||
|
|
@ -741,10 +741,15 @@ public class DeviceController extends ControllerBase {
|
||||||
Path tempZipFile = Files.createTempFile("files", ".zip");
|
Path tempZipFile = Files.createTempFile("files", ".zip");
|
||||||
try (FileOutputStream fos = new FileOutputStream(tempZipFile.toFile());
|
try (FileOutputStream fos = new FileOutputStream(tempZipFile.toFile());
|
||||||
ZipOutputStream zos = new ZipOutputStream(fos)) {
|
ZipOutputStream zos = new ZipOutputStream(fos)) {
|
||||||
for (String deviceNo : deviceNos) {
|
List<Device> tds=new ArrayList<>();
|
||||||
ZipEntry zipEntry = new ZipEntry(deviceNo+".jpg");
|
for (Device device : devices) {
|
||||||
|
if (tds.stream().anyMatch(td -> StrUtil.equals(td.getDeviceNo(), device.getDeviceNo()))){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
tds.add(device);
|
||||||
|
ZipEntry zipEntry = new ZipEntry(device.getDeviceNo()+".jpg");
|
||||||
zos.putNextEntry(zipEntry);
|
zos.putNextEntry(zipEntry);
|
||||||
byte[] bytes=deviceQRCodeService.generate(deviceNo);
|
byte[] bytes=deviceQRCodeService.generate(device.getDeviceNo(),device.getModelNo());
|
||||||
zos.write(bytes, 0, bytes.length);
|
zos.write(bytes, 0, bytes.length);
|
||||||
zos.closeEntry();
|
zos.closeEntry();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,9 +26,11 @@ public class TestController extends ControllerBase{
|
||||||
* @param deviceNo 设备编号
|
* @param deviceNo 设备编号
|
||||||
*/
|
*/
|
||||||
@GetMapping("showDeviceQRCode")
|
@GetMapping("showDeviceQRCode")
|
||||||
public void showDeviceQRCode(HttpServletResponse response, @RequestParam(defaultValue = "dsadwe3d3cdsd") String deviceNo){
|
public void showDeviceQRCode(HttpServletResponse response
|
||||||
|
, @RequestParam(defaultValue = "dsadwe3d3cdsd") String deviceNo
|
||||||
|
, @RequestParam(defaultValue = "sadasd") String modelNo){
|
||||||
try {
|
try {
|
||||||
byte[] bytes=deviceQRCodeService.generate(deviceNo);
|
byte[] bytes=deviceQRCodeService.generate(deviceNo,modelNo);
|
||||||
response.setContentType("image/png");
|
response.setContentType("image/png");
|
||||||
response.setHeader("Content-Disposition", "attachment;filename=qrcode.png");
|
response.setHeader("Content-Disposition", "attachment;filename=qrcode.png");
|
||||||
try (OutputStream outputStream = response.getOutputStream()) {
|
try (OutputStream outputStream = response.getOutputStream()) {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.nflg.mobilebroken.admin.service;
|
package com.nflg.mobilebroken.admin.service;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.nflg.mobilebroken.common.util.QRCodeUtil;
|
import com.nflg.mobilebroken.common.util.QRCodeUtil;
|
||||||
import com.nflg.mobilebroken.repository.entity.ParamConfig;
|
import com.nflg.mobilebroken.repository.entity.ParamConfig;
|
||||||
import com.nflg.mobilebroken.repository.service.IParamConfigService;
|
import com.nflg.mobilebroken.repository.service.IParamConfigService;
|
||||||
|
|
@ -15,8 +16,8 @@ public class DeviceQRCodeService {
|
||||||
@Resource
|
@Resource
|
||||||
private IParamConfigService paramConfigService;
|
private IParamConfigService paramConfigService;
|
||||||
|
|
||||||
public byte[] generate(String deviceNo) throws Exception {
|
public byte[] generate(String deviceNo, String modelNo) throws Exception {
|
||||||
ParamConfig config = paramConfigService.lambdaQuery().eq(ParamConfig::getCode, "DeviceQRCodeHost").one();
|
ParamConfig config = paramConfigService.lambdaQuery().eq(ParamConfig::getCode, "DeviceQRCodeHost").one();
|
||||||
return QRCodeUtil.generateDeviceQRCode(deviceNo ,config.getValue() + deviceNo,200, 200);
|
return QRCodeUtil.generateDeviceQRCode(deviceNo ,StrUtil.format(config.getValue(), deviceNo,modelNo),200, 200);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue