Compare commits

..

2 Commits

@ -125,6 +125,12 @@
<artifactId>javax.servlet-api</artifactId> <artifactId>javax.servlet-api</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>core</artifactId>
<version>3.3.3</version>
</dependency>
</dependencies> </dependencies>
</project> </project>

@ -5,11 +5,16 @@ import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.Base64; import java.util.*;
import java.util.Objects;
import java.util.UUID;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix;
import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.FilenameUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import com.ruoyi.common.config.RuoYiConfig; import com.ruoyi.common.config.RuoYiConfig;
@ -30,6 +35,7 @@ import javax.servlet.http.HttpServletRequest;
*/ */
public class FileUploadUtils public class FileUploadUtils
{ {
private static final Logger logger = LoggerFactory.getLogger(FileUploadUtils.class);
/** /**
* 50M * 50M
*/ */
@ -256,6 +262,7 @@ public class FileUploadUtils
b[i] += 256; b[i] += 256;
} }
} }
logger.info("file path :{}{}", uploadFilePath, imgClassPath);
// 保存图片 // 保存图片
OutputStream out = new FileOutputStream(uploadFilePath.concat(imgClassPath)); OutputStream out = new FileOutputStream(uploadFilePath.concat(imgClassPath));
out.write(b); out.write(b);
@ -264,7 +271,31 @@ public class FileUploadUtils
// 返回图片的相对路径 = 图片分类路径+图片名+图片后缀 // 返回图片的相对路径 = 图片分类路径+图片名+图片后缀
return imgClassPath; return imgClassPath;
} catch (IOException e) { } catch (IOException e) {
logger.error("generateImage error", e);
return null; return null;
} }
} }
public static String code(String content,String path) {
String picPath = "";
try {
String codeName = UUID.randomUUID().toString();// 二维码的图片名
String imageType = "jpg";// 图片类型
picPath = codeName + "." + imageType;
MultiFormatWriter multiFormatWriter = new MultiFormatWriter();
Map<EncodeHintType, String> hints = new HashMap<EncodeHintType, String>();
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
BitMatrix bitMatrix = multiFormatWriter.encode(content, BarcodeFormat.QR_CODE, 400, 400, hints);
File file1 = new File(path, picPath);
MatrixToImageWriter.writeToFile(bitMatrix, imageType, file1);
} catch (WriterException e) {
logger.error("code WriterException:", e);
e.printStackTrace();
} catch (IOException e) {
logger.error("code IOException:", e);
e.printStackTrace();
}
return picPath;
}
} }

@ -0,0 +1,43 @@
package com.ruoyi.common.utils.file;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import com.google.zxing.common.BitMatrix;
/**
*
*
* @author 18316
*
*/
public class MatrixToImageWriter {
private static final int BLACK = 0xFF000000;
private static final int WHITE = 0xFFFFFFFF;
private MatrixToImageWriter() {
}
public static BufferedImage toBufferedImage(BitMatrix matrix) {
int width = matrix.getWidth();
int height = matrix.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, matrix.get(x, y) ? BLACK : WHITE);
}
}
return image;
}
public static void writeToFile(BitMatrix matrix, String format, File file) throws IOException {
BufferedImage image = toBufferedImage(matrix);
if (!ImageIO.write(image, format, file)) {
throw new IOException("Could not write an image of format " + format + " to " + file);
}
}
}

@ -2,6 +2,7 @@ package com.ruoyi.framework.web.service;
import javax.annotation.Resource; import javax.annotation.Resource;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.UserStatus; import com.ruoyi.common.enums.UserStatus;
import com.ruoyi.common.utils.*; import com.ruoyi.common.utils.*;
@ -34,6 +35,7 @@ import com.ruoyi.system.service.ISysConfigService;
import com.ruoyi.system.service.ISysUserService; import com.ruoyi.system.service.ISysUserService;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
@ -204,6 +206,13 @@ public class SysLoginService
tDoctor.setUserId(sysUser.getUserId()); tDoctor.setUserId(sysUser.getUserId());
tDoctorMapper.insertTDoctor(tDoctor); tDoctorMapper.insertTDoctor(tDoctor);
tDoctor.setIdentifier("10000000" + tDoctor.getId()); tDoctor.setIdentifier("10000000" + tDoctor.getId());
Map map = new HashMap();
map.put("id", tDoctor.getId());
map.put("from", "yinuo");
String content = JSONObject.toJSONString(map);
String qrCode = FileUploadUtils.code(content, uploadFilePath);
tDoctor.setQrCode(qrCode);
log.info("update doctor :{}", tDoctor);
tDoctorMapper.updateTDoctor(tDoctor); tDoctorMapper.updateTDoctor(tDoctor);
} }
LoginUser loginUser = new LoginUser(); LoginUser loginUser = new LoginUser();

@ -32,6 +32,8 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects; import java.util.Objects;
@Service @Service
@ -183,6 +185,14 @@ public class WechatServiceImpl implements IWechatService {
tDoctor.setUserId(sysUser.getUserId()); tDoctor.setUserId(sysUser.getUserId());
tDoctorMapper.insertTDoctor(tDoctor); tDoctorMapper.insertTDoctor(tDoctor);
tDoctor.setIdentifier("10000000" + tDoctor.getId()); tDoctor.setIdentifier("10000000" + tDoctor.getId());
Map map = new HashMap();
map.put("id", tDoctor.getId());
map.put("from", "yinuo");
String content = JSONObject.toJSONString(map);
String qrCode = FileUploadUtils.code(content, uploadFilePath);
tDoctor.setQrCode(qrCode);
logger.info("update doctor :{}", tDoctor);
tDoctorMapper.updateTDoctor(tDoctor); tDoctorMapper.updateTDoctor(tDoctor);
wechatUser.setUserId(tDoctor.getId()); wechatUser.setUserId(tDoctor.getId());

Loading…
Cancel
Save