Merge remote-tracking branch 'origin/master'

This commit is contained in:
齐天大圣 2024-06-05 13:37:27 +08:00
commit 1fd65bd72b
3 changed files with 43 additions and 71 deletions

View File

@ -129,6 +129,47 @@ public class QrCodeUtils {
}
}
public void createLogoCodePictures(String tagCodeSn,InputStream logoStream, String url, String outImgPath, Integer staffId, Integer storeId,String urls) {
try {
Image srcImg = ImageIO.read(logoStream);
//获取图片的宽
int srcImgWidth = srcImg.getWidth(null);
//获取图片的高
int srcImgHeight = srcImg.getHeight(null);
BufferedImage bufImg = new BufferedImage(srcImgWidth, srcImgHeight, BufferedImage.TYPE_INT_RGB);
Graphics2D g = bufImg.createGraphics();
g.drawImage(srcImg, 0, 0, srcImgWidth, srcImgHeight, null);
//使用工具类生成二维码
Image image = createQrCode(null, url, 360, 360);
//将小图片绘到大图片上,500,300 .表示你的小图片在大图片上的位置
g.drawImage(image, (bufImg.getWidth()-360)/2, (bufImg.getHeight()-360)/2-30, null);
// 设置字体样式字体大小
// g.setFont(new Font("TimesRoman", Font.BOLD, 40));
g.setFont(chineseFont());
//设置颜色
g.setColor(Color.BLACK);
g.drawString("SN"+tagCodeSn, returnX(g, bufImg.getWidth(), "SN"+tagCodeSn), 440);
g.dispose();
// 输出图片
String urlsss = "/temp/qrCode/";
if (ObjectUtils.isNotEmpty(urls)){
urlsss = urls;
}
File file1 = new File(urlsss);
// 判断目录是否存在
if (!file1.exists()) {
file1.mkdirs();
}
FileOutputStream outImgStream = new FileOutputStream(outImgPath);
ImageIO.write(bufImg, "jpg", outImgStream);
outImgStream.flush();
outImgStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public void createLogoCodePictureByPos(InputStream backgroundStream, InputStream logoStream, String url, String outImgPath, Integer staffId, Integer storeId,String urls) {
try {
// 读取原图片信息
@ -166,56 +207,7 @@ public class QrCodeUtils {
}
}
public void createLogoCodePictures(InputStream logoStream, String url, String outImgPath, Integer staffId, Integer storeId,String urls) {
try {
// 读取原图片信息
//得到文件
//// File file = ResourceUtils.getFile(roundImage);
// ClassPathResource resource = new ClassPathResource(roundImage);
// ClassPathResource logoResource = new ClassPathResource(logoImage);
// File file = resource.getFile();
//文件转化为图片
// 加水印
//使用工具类生成二维码
Image image = createQrCode(logoStream, url, 360, 360);
//将小图片绘到大图片上,500,300 .表示你的小图片在大图片上的位置
// 查询当前店铺信息
if (ObjectUtils.isNotEmpty(storeId)){
LJStore store = storeService.selectStoreByStoreId(storeId);
// 查询加油员信息
LJStaff staff = null;
if (ObjectUtil.isNotEmpty(staffId)){
staff = staffService.selectStaffById(staffId);
}
LJStaff staff1 = staffService.selectStaffByStoreId(storeId);
}else {
//drawStringWithMultiLine(g,"欢迎光临", bufImg.getWidth()-20,20,940,10 );
}
// // 将码牌编号文字绘制到指定位置
// g.drawString(storeNumber, 200, 800);
// 输出图片
String urlsss = "/temp/qrCode/";
if (ObjectUtils.isNotEmpty(urls)){
urlsss = urls;
}
File file1 = new File(urlsss);
// 判断目录是否存在
if (!file1.exists()) {
file1.mkdirs();
}
FileOutputStream outImgStream = new FileOutputStream(outImgPath);
ImageIO.write((RenderedImage) image, "jpg", outImgStream);
outImgStream.flush();
outImgStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public Font chineseFont() throws Exception {

View File

@ -59,8 +59,6 @@ public class TagCodeServiceImpl extends ServiceImpl<TagCodeMapper, TagCode> impl
@Autowired
private BackendFileController backendFileController;
//private static final String IMAGE_DIRECTORY = "D:\\temp\\qrCode";
@Override
@Transactional
public ResponseEntity<InputStreamResource> add(TagCodeDTO tagCodeDTO, HttpServletRequest request, HttpServletResponse response) throws Exception {
@ -74,29 +72,21 @@ public class TagCodeServiceImpl extends ServiceImpl<TagCodeMapper, TagCode> impl
for (int i = 0; i < total; i++) {
Random random = new Random();
int i1 = random.nextInt(90000000);
//String url = "https://oil.youkerr.com/";
String url = "https://www.tuofeng.cc/oilRefuel?sn=byx"+i1;
// String finalPath="/temp/qrCode/" + oilTag.getSnCode() + ".jpg";
//String finalPath="D:\\office\\document\\photos\\tagCode\\"+"str"+i+".jpg";
//String finalPath="/temp/tagCode/" + "byx"+i1 + ".jpg";
//String finalPath="/temp/tagCode/"+ DateUtil.formatDate(new Date(), "yyyyMMdd") + "/"+i2 + "byx"+i1 + ".jpg";
TagCode tagCode = new TagCode();
tagCode.setCollection(url);
tagCode.setTagCodeSn("byx"+i1);
tagCode.setDeptId(Integer.parseInt(nowAccountInfo.getDeptId().toString()));
//在图片上生成二维码
String backgroundImage = "static/qrCodeImg/huanyingguanglin.jpg";
String backgroundImage = "static/qrCodeImg/white2.jpg";
InputStream backgroundStream = this.getClass().getClassLoader().getResourceAsStream(backgroundImage);
String urls = "";
urls = "/temp/tagCode/"+ DateUtil.formatDate(new Date(), "yyyyMMdd") + "-"+i2;
File file1 = new File(urls);
// String finalPath="/temp/tagCode/" + "byx"+i1 + ".jpg";
String finalPath=urls+"/" + "byx"+i1 + ".jpg";
qrCodeUtils.createLogoCodePictures(null, url, finalPath, null,null,urls);
qrCodeUtils.createLogoCodePictures(tagCode.getTagCodeSn(),backgroundStream, url, finalPath, null,null,urls);
// 判断目录是否存在
if (!file1.exists()) {
@ -105,17 +95,13 @@ public class TagCodeServiceImpl extends ServiceImpl<TagCodeMapper, TagCode> impl
File file =new File(finalPath);
FileInputStream fileInputStream =new FileInputStream(file);
// FileInputStream fileInputStream =new FileInputStream(file1);
MultipartFile resFile = new MockMultipartFile("file", file.getName(), null, fileInputStream);
// 返回图片路径
String saveFile = backendFileController.saveFile(resFile);
//return saveFile;
tagCode.setImageUrl(saveFile);
flag = save(tagCode);
}
//导出码牌
//String IMAGE_DIRECTORY = "D:\\temp\\tagCode\\"+DateUtil.formatDate(new Date(), "yyyyMMdd")+"-"+i2;
String IMAGE_DIRECTORY = "/temp/tagCode/"+DateUtil.formatDate(new Date(), "yyyyMMdd")+"-"+i2;
List<File> imageFiles = getImageFiles(IMAGE_DIRECTORY);
@ -135,12 +121,6 @@ public class TagCodeServiceImpl extends ServiceImpl<TagCodeMapper, TagCode> impl
return ResponseEntity.ok()
.body(new InputStreamResource(inputStream));
}
//String IMAGE_DIRECTORY = "D:\\temp\\qrCode\\DateUtil.formatDate(new Date(), \"yyyyMMdd\") +";
//return flag;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB