修改了二维码接口,返回了一个二维码集合
修改了二维码插入图片的业务逻辑,使其能够根据url(没有做拼接)获取图片
This commit is contained in:
parent
df07b3bf2a
commit
1f31d0defd
@ -20,6 +20,8 @@ import com.platform.modules.live.vo.LiveCasterSubVo;
|
||||
import com.platform.modules.live.vo.LiveInfoVo;
|
||||
import com.platform.modules.live.vo.SceneEntityVo;
|
||||
import com.platform.modules.sys.controller.AbstractController;
|
||||
import com.platform.modules.sys.entity.SysTenantEntity;
|
||||
import com.platform.modules.sys.service.impl.SysTenantServiceImpl;
|
||||
import com.platform.plugs.common.rpc.RpcResponse;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
@ -38,6 +40,7 @@ import javax.servlet.http.HttpServletResponse;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -60,8 +63,10 @@ public class LiveSceneController extends AbstractController {
|
||||
private LiveSceneLiveInfoService liveSceneLiveInfoService;
|
||||
@Autowired
|
||||
private LiveChannelService liveChannelService;
|
||||
@Autowired
|
||||
private SysTenantServiceImpl sysTenantService;
|
||||
|
||||
/**
|
||||
/**
|
||||
* 分页数据
|
||||
*/
|
||||
@GetMapping("/page")
|
||||
@ -564,12 +569,14 @@ public class LiveSceneController extends AbstractController {
|
||||
@ApiOperation("现场详情生成二维码接口")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(value = "现场ID", name = "id", paramType = "query", dataType = "int")})
|
||||
public String qrcode(Integer id, HttpServletResponse response) {
|
||||
public List<String> qrcode(Integer id, HttpServletResponse response) {
|
||||
String content = "";
|
||||
if(id == null) {
|
||||
List<String> list = new ArrayList<>();
|
||||
LiveSceneEntity sceneEntity = null;
|
||||
if(id == null) {
|
||||
content = "参数错误:id为空";
|
||||
} else {
|
||||
LiveSceneEntity sceneEntity = liveSceneService.selectById(id);
|
||||
sceneEntity = liveSceneService.selectById(id);
|
||||
if(sceneEntity == null) {
|
||||
content = "未找到现场,id:" + id;
|
||||
} else {
|
||||
@ -588,7 +595,24 @@ public class LiveSceneController extends AbstractController {
|
||||
BufferedImage image = QrCodeUtils.encode(content, os);
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
ImageIO.write(image, "png",outputStream);
|
||||
return Base64.encodeBase64String(outputStream.toByteArray());
|
||||
list.add(Base64.encodeBase64String(outputStream.toByteArray()));
|
||||
|
||||
//1.查询机构LOGO的URL地址
|
||||
Long tenantId = null;
|
||||
if (sceneEntity != null) {
|
||||
tenantId = sceneEntity.getTenantId();
|
||||
}
|
||||
SysTenantEntity tenantEntity = sysTenantService.selectById(tenantId);
|
||||
String logoUrl = null;
|
||||
if(tenantEntity!=null){
|
||||
logoUrl = tenantEntity.getTLogoUrl();
|
||||
}
|
||||
//创建带有LOGO的二维码
|
||||
BufferedImage imageLogo = QrCodeUtils.createImage(content, logoUrl, true);
|
||||
ByteArrayOutputStream outputStreamLogo = new ByteArrayOutputStream();
|
||||
ImageIO.write(imageLogo, "png",outputStreamLogo);
|
||||
list.add(Base64.encodeBase64String(outputStreamLogo.toByteArray()));
|
||||
return list;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@ -957,11 +957,11 @@ public class LiveSceneServiceImpl extends ServiceImpl<LiveSceneDao, LiveSceneEnt
|
||||
liveSceneLiveInfoExtService.saveOrUpdate(infoExtEntity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据流列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
/**
|
||||
* 数据流列表
|
||||
* @param params SceneId
|
||||
* @return 流集合
|
||||
*/
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
public List<LiveInfoVo> streamList(Map<String, Object> params) {
|
||||
|
||||
@ -14,6 +14,7 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URL;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Random;
|
||||
/**
|
||||
@ -58,10 +59,24 @@ public class QrCodeUtils {
|
||||
return image;
|
||||
}
|
||||
// 插入图片
|
||||
QrCodeUtils.insertImage(image, logoPath, needCompress);
|
||||
if (logoPath != null && !logoPath.isEmpty()) {
|
||||
try (InputStream logoInputStream = getLogoInputStream(logoPath)) {
|
||||
insertImage(image, logoInputStream, needCompress);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to load logo: " + logoPath, e);
|
||||
}
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
private static InputStream getLogoInputStream(String logoPath) throws IOException {
|
||||
if (logoPath.startsWith("http://") || logoPath.startsWith("https://")) {
|
||||
return new URL(logoPath).openStream();
|
||||
} else {
|
||||
return Thread.currentThread().getContextClassLoader().getResourceAsStream(logoPath);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 插入LOGO
|
||||
*
|
||||
@ -70,11 +85,9 @@ public class QrCodeUtils {
|
||||
* @param needCompress 是否压缩
|
||||
* @throws IOException
|
||||
*/
|
||||
private static void insertImage(BufferedImage source, String logoPath, boolean needCompress) throws IOException {
|
||||
InputStream inputStream = null;
|
||||
private static void insertImage(BufferedImage source, InputStream logoPath, boolean needCompress) throws IOException {
|
||||
try {
|
||||
inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(logoPath);
|
||||
Image src = ImageIO.read(inputStream);
|
||||
Image src = ImageIO.read(logoPath);
|
||||
int width = src.getWidth(null);
|
||||
int height = src.getHeight(null);
|
||||
if (needCompress) { // 压缩LOGO
|
||||
@ -104,8 +117,8 @@ public class QrCodeUtils {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
if (inputStream != null) {
|
||||
inputStream.close();
|
||||
if (logoPath != null) {
|
||||
logoPath.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user