From 00754b2fb8e71be738e6c312e11d62e64a4e82c3 Mon Sep 17 00:00:00 2001
From: Administrator <admin>
Date: Fri, 10 Dec 2021 17:13:59 +0800
Subject: [PATCH] 1.二维码批量生成修改,新增图片批量下载 2.用户修改 rtime bug 修改

---
 src/main/java/org/springblade/modules/system/service/impl/UserServiceImpl.java |   70 ++++++++++++-----
 src/main/java/org/springblade/common/utils/ImageUtils.java                     |   41 ++++++++++
 src/main/java/org/springblade/modules/system/controller/UserController.java    |   94 +++++++++++++++--------
 3 files changed, 150 insertions(+), 55 deletions(-)

diff --git a/src/main/java/org/springblade/common/utils/ImageUtils.java b/src/main/java/org/springblade/common/utils/ImageUtils.java
index d19071f..eefae91 100644
--- a/src/main/java/org/springblade/common/utils/ImageUtils.java
+++ b/src/main/java/org/springblade/common/utils/ImageUtils.java
@@ -72,6 +72,47 @@
 		g.dispose();
 		return bimage;
 	}
+
+	/**
+	 * 得到文件流
+	 * @param url 图片地址
+	 * @return
+	 */
+	public static byte[] getFileStream(String url){
+		try {
+			URL httpUrl = new URL(url);
+			HttpURLConnection conn = (HttpURLConnection)httpUrl.openConnection();
+			conn.setRequestMethod("GET");
+			conn.setConnectTimeout(5 * 1000);
+			//通过输入流获取图片数据
+			InputStream inStream = conn.getInputStream();
+			//得到图片的二进制数据
+			byte[] btImg = readInputStream(inStream);
+			return btImg;
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		return null;
+	}
+
+	/**
+	 * 从输入流中获取数据
+	 * @param inStream 输入流
+	 * @return
+	 * @throws Exception
+	 */
+	public static byte[] readInputStream(InputStream inStream) throws Exception{
+		ByteArrayOutputStream outStream = new ByteArrayOutputStream();
+		byte[] buffer = new byte[1024];
+		int len = 0;
+		while( (len=inStream.read(buffer)) != -1 ){
+			outStream.write(buffer, 0, len);
+		}
+		inStream.close();
+		return outStream.toByteArray();
+	}
+
+
 	/**
 	 * 通过图片的url获取图片的base64字符串
 	 * @param imgUrl    图片url
diff --git a/src/main/java/org/springblade/modules/system/controller/UserController.java b/src/main/java/org/springblade/modules/system/controller/UserController.java
index 523eeb6..2fcbd89 100644
--- a/src/main/java/org/springblade/modules/system/controller/UserController.java
+++ b/src/main/java/org/springblade/modules/system/controller/UserController.java
@@ -401,42 +401,70 @@
 		userService.updateById(user);
 		String rtime;
 		if (user.getRtime() == null) {
-			rtime = null;
+			String s1 =
+				"update blade_user set account = " + "'" + user.getAccount() + "'"
+					+ ",name = " + "'" + user.getName() + "'"
+					+ ",real_name = " + "'" + user.getRealName() + "'"
+					+ ",avatar = " + "'" + user.getAvatar() + "'"
+					+ ",email = " + "'" + user.getEmail() + "'"
+					+ ",phone = " + "'" + user.getPhone() + "'"
+					+ ",sex = " + "'" + user.getSex() + "'"
+					+ ",role_id = " + "'" + user.getRoleId() + "'"
+					+ ",dept_id = " + "'" + user.getDeptId() + "'"
+					+ ",cardid = " + "'" + user.getCardid() + "'"
+					+ ",nativePlace = " + "'" + user.getNativeplace() + "'"
+					+ ",nation = " + "'" + user.getNation() + "'"
+					+ ",education = " + "'" + user.getEducation() + "'"
+					+ ",politicaloutlook = " + "'" + user.getPoliticaloutlook() + "'"
+					+ ",healstats = " + "'" + user.getHealstats() + "'"
+					+ ",height = " + "'" + user.getHeight() + "'"
+					+ ",fingerprint = " + "'" + url + "'"
+					+ ",my_picture = " + "'" + user.getMyPicture() + "'"
+					+ ",address = " + "'" + user.getAddress() + "'"
+					+ ",registered = " + "'" + user.getRegistered() + "'"
+					+ ",dispatch = " + "'" + user.getDispatch() + "'"
+					+ ",securitynumber = " + "'" + user.getSecuritynumber() + "'"
+					+ ",hold = " + "'" + user.getHold() + "'"
+					+ ",jurisdiction = " + "'" + user.getJurisdiction() + "'"
+					+ ",reason_for_leav = " + "'" + user.getReasonForLeav() + "'"
+					+ ",guncode = " + "'" + user.getGuncode() + "'"
+					+ ",update_time = " + "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(user.getUpdateTime()) + "'"
+					+ " " + "where id = " + "'" + user.getId() + "'";
+			FtpUtil.sqlFileUpload(s1);
 		} else {
 			rtime = new SimpleDateFormat("yyyy-MM-dd").format(user.getRtime());
+			String s1 =
+				"update blade_user set account = " + "'" + user.getAccount() + "'"
+					+ ",name = " + "'" + user.getName() + "'"
+					+ ",real_name = " + "'" + user.getRealName() + "'"
+					+ ",avatar = " + "'" + user.getAvatar() + "'"
+					+ ",email = " + "'" + user.getEmail() + "'"
+					+ ",phone = " + "'" + user.getPhone() + "'"
+					+ ",sex = " + "'" + user.getSex() + "'"
+					+ ",role_id = " + "'" + user.getRoleId() + "'"
+					+ ",dept_id = " + "'" + user.getDeptId() + "'"
+					+ ",cardid = " + "'" + user.getCardid() + "'"
+					+ ",nativePlace = " + "'" + user.getNativeplace() + "'"
+					+ ",nation = " + "'" + user.getNation() + "'"
+					+ ",education = " + "'" + user.getEducation() + "'"
+					+ ",politicaloutlook = " + "'" + user.getPoliticaloutlook() + "'"
+					+ ",healstats = " + "'" + user.getHealstats() + "'"
+					+ ",height = " + "'" + user.getHeight() + "'"
+					+ ",fingerprint = " + "'" + url + "'"
+					+ ",my_picture = " + "'" + user.getMyPicture() + "'"
+					+ ",address = " + "'" + user.getAddress() + "'"
+					+ ",registered = " + "'" + user.getRegistered() + "'"
+					+ ",rtime = " + "'" + rtime + "'"
+					+ ",dispatch = " + "'" + user.getDispatch() + "'"
+					+ ",securitynumber = " + "'" + user.getSecuritynumber() + "'"
+					+ ",hold = " + "'" + user.getHold() + "'"
+					+ ",jurisdiction = " + "'" + user.getJurisdiction() + "'"
+					+ ",reason_for_leav = " + "'" + user.getReasonForLeav() + "'"
+					+ ",guncode = " + "'" + user.getGuncode() + "'"
+					+ ",update_time = " + "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(user.getUpdateTime()) + "'"
+					+ " " + "where id = " + "'" + user.getId() + "'";
+			FtpUtil.sqlFileUpload(s1);
 		}
-
-		String s1 =
-			"update blade_user set account = " + "'" + user.getAccount() + "'"
-				+ ",name = " + "'" + user.getName() + "'"
-				+ ",real_name = " + "'" + user.getRealName() + "'"
-				+ ",avatar = " + "'" + user.getAvatar() + "'"
-				+ ",email = " + "'" + user.getEmail() + "'"
-				+ ",phone = " + "'" + user.getPhone() + "'"
-				+ ",sex = " + "'" + user.getSex() + "'"
-				+ ",role_id = " + "'" + user.getRoleId() + "'"
-				+ ",dept_id = " + "'" + user.getDeptId() + "'"
-				+ ",cardid = " + "'" + user.getCardid() + "'"
-				+ ",nativePlace = " + "'" + user.getNativeplace() + "'"
-				+ ",nation = " + "'" + user.getNation() + "'"
-				+ ",education = " + "'" + user.getEducation() + "'"
-				+ ",politicaloutlook = " + "'" + user.getPoliticaloutlook() + "'"
-				+ ",healstats = " + "'" + user.getHealstats() + "'"
-				+ ",height = " + "'" + user.getHeight() + "'"
-				+ ",fingerprint = " + "'" + url + "'"
-				+ ",my_picture = " + "'" + user.getMyPicture() + "'"
-				+ ",address = " + "'" + user.getAddress() + "'"
-				+ ",registered = " + "'" + user.getRegistered() + "'"
-				+ ",rtime = " + "'" + rtime + "'"
-				+ ",dispatch = " + "'" + user.getDispatch() + "'"
-				+ ",securitynumber = " + "'" + user.getSecuritynumber() + "'"
-				+ ",hold = " + "'" + user.getHold() + "'"
-				+ ",jurisdiction = " + "'" + user.getJurisdiction() + "'"
-				+ ",reason_for_leav = " + "'" + user.getReasonForLeav() + "'"
-				+ ",guncode = " + "'" + user.getGuncode() + "'"
-				+ ",update_time = " + "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(user.getUpdateTime()) + "'"
-				+ " " + "where id = " + "'" + user.getId() + "'";
-		FtpUtil.sqlFileUpload(s1);
 		return R.success("修改成功");
 	}
 
diff --git a/src/main/java/org/springblade/modules/system/service/impl/UserServiceImpl.java b/src/main/java/org/springblade/modules/system/service/impl/UserServiceImpl.java
index 5e31813..9c66160 100644
--- a/src/main/java/org/springblade/modules/system/service/impl/UserServiceImpl.java
+++ b/src/main/java/org/springblade/modules/system/service/impl/UserServiceImpl.java
@@ -28,6 +28,7 @@
 import org.springblade.common.constant.CommonConstant;
 import org.springblade.common.constant.TenantConstant;
 import org.springblade.common.utils.IdCardNoUtil;
+import org.springblade.common.utils.ImageUtils;
 import org.springblade.common.utils.QRCodeUtil;
 import org.springblade.core.log.exception.ServiceException;
 import org.springblade.core.mp.base.BaseServiceImpl;
@@ -120,10 +121,6 @@
 			throw new ServiceException(StringUtil.format("当前用户 [{}] 已存在!", user.getAccount()));
 		}
 		boolean b = save(user) && submitUserDept(user);
-		String rtime = null;
-		if (null != user.getRtime()) {
-			rtime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(user.getRtime());
-		}
 		user.setIsDeleted(0);
 		String s = "insert into blade_user(id,tenant_id,account,password,real_name,email,phone,sex,role_id,dept_id,cardid,nativePlace,nation," +
 			"politicaloutlook,healstats,height,address,registered,securitynumber,hold,status,dispatch,jurisdiction,is_deleted) " +
@@ -1494,31 +1491,60 @@
 	 */
 	@Override
 	public void importQrCode(List<QrCodeExcel> data, Boolean isCovered, String deptId) {
-		String url = "http://223.82.109.183:2080/securityInfo.html";
+//		String url = "http://223.82.109.183:2080/securityInfo.html";
+//		data.forEach(qrCodeExcel -> {
+//			if (null!=qrCodeExcel.getSecuritynumber()) {
+//				String encoded = null;
+//				try {
+//					//中文字符串编码
+//					encoded = URLEncoder.encode(qrCodeExcel.getSecuritynumber(),"UTF-8");
+//				} catch (UnsupportedEncodingException e) {
+//					e.printStackTrace();
+//				}
+//				//url 拼接
+//				String content = url + "?securityNumber=" + encoded;
+//				byte[] qrCodeImage = new byte[0];
+//				try {
+//					//生成二维码字节流
+//					qrCodeImage = QRCodeUtil.getQRCodeImage(content, 350, 350);
+//				} catch (WriterException e) {
+//					e.printStackTrace();
+//				} catch (IOException e) {
+//					e.printStackTrace();
+//				}
+//				String path = "D:\\QrCode\\";
+//				FileOutputStream fileOutputStream = null;
+//				try {
+//					fileOutputStream = new FileOutputStream(path+qrCodeExcel.getSecuritynumber()+".png");
+//				} catch (FileNotFoundException e) {
+//					e.printStackTrace();
+//				}
+//				try {
+//					//图片下载到本地
+//					fileOutputStream.write(qrCodeImage,0,qrCodeImage.length);
+//					fileOutputStream.flush();
+//					fileOutputStream.close();
+//				} catch (IOException e) {
+//					e.printStackTrace();
+//				}
+//			}
+//		});
+		//头像生成
 		data.forEach(qrCodeExcel -> {
 			if (null!=qrCodeExcel.getSecuritynumber()) {
-				String encoded = null;
-				try {
-					//中文字符串编码
-					encoded = URLEncoder.encode(qrCodeExcel.getSecuritynumber(),"UTF-8");
-				} catch (UnsupportedEncodingException e) {
-					e.printStackTrace();
-				}
+				//查询用户头像url
+				User user = new User();
+				user.setSecuritynumber(qrCodeExcel.getSecuritynumber());
+				User user1 = this.getOne(Condition.getQueryWrapper(user));
 				//url 拼接
-				String content = url + "?securityNumber=" + encoded;
 				byte[] qrCodeImage = new byte[0];
-				try {
-					//生成二维码字节流
-					qrCodeImage = QRCodeUtil.getQRCodeImage(content, 350, 350);
-				} catch (WriterException e) {
-					e.printStackTrace();
-				} catch (IOException e) {
-					e.printStackTrace();
-				}
+				//获取图片
+				qrCodeImage = ImageUtils.getFileStream(user1.getAvatar());
+				//路径
 				String path = "D:\\QrCode\\";
 				FileOutputStream fileOutputStream = null;
 				try {
-					fileOutputStream = new FileOutputStream(path+qrCodeExcel.getSecuritynumber()+".png");
+					fileOutputStream = new FileOutputStream(path+user1.getRealName()+user1.getCardid()+".png");
 				} catch (FileNotFoundException e) {
 					e.printStackTrace();
 				}

--
Gitblit v1.9.3