|
|
@@ -13,6 +13,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
|
|
import com.xjrsoft.common.enums.DeleteMark;
|
|
|
import com.xjrsoft.common.enums.GenderDictionaryEnum;
|
|
|
+import com.xjrsoft.common.exception.MyException;
|
|
|
import com.xjrsoft.common.model.result.R;
|
|
|
import com.xjrsoft.common.model.result.RT;
|
|
|
import com.xjrsoft.common.page.ConventPage;
|
|
|
@@ -42,6 +43,7 @@ import com.xjrsoft.module.teacher.entity.XjrUser;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
@@ -58,6 +60,7 @@ import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
import java.text.ParseException;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.Base64;
|
|
|
import java.util.Enumeration;
|
|
|
import java.util.HashMap;
|
|
|
@@ -249,16 +252,32 @@ public class StudentManagerController {
|
|
|
|
|
|
ZipFile zipFile = FileZipUtil.convertToZipFile(file);
|
|
|
Enumeration<? extends ZipEntry> entries = zipFile.entries();
|
|
|
+
|
|
|
+
|
|
|
+ Map<String, String> map = new HashMap<String, String>() {
|
|
|
+ {
|
|
|
+ put("jpg", "data:image/jpg;base64,");
|
|
|
+ put("jpeg", "data:image/jpeg;base64,");
|
|
|
+ put("png", "data:image/png;base64,");
|
|
|
+ }
|
|
|
+ };
|
|
|
+ String[] imgSuffix = new String[]{"png", "jpg", "jpeg"};
|
|
|
while (entries.hasMoreElements()){
|
|
|
ZipEntry entry = entries.nextElement();
|
|
|
String filename = entry.getName();
|
|
|
InputStream inputStream = zipFile.getInputStream(entry); //读取文件内容
|
|
|
String[] split = filename.split("\\.");
|
|
|
String idNumber = split[0].substring(split[0].length() - 18);
|
|
|
+ String suffix = StringUtils.substringAfterLast(filename, StringPool.DOT);
|
|
|
+
|
|
|
+
|
|
|
BaseStudentUser studentUser = studentMap.get(idNumber);
|
|
|
if(studentUser == null){
|
|
|
continue;
|
|
|
}
|
|
|
+ if (!Arrays.asList(imgSuffix).contains(suffix)) {
|
|
|
+ throw new MyException("图片格式不正确!");
|
|
|
+ }
|
|
|
//将照片转换成base64
|
|
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
|
byte[] buffer = new byte[4096];
|
|
|
@@ -267,7 +286,7 @@ public class StudentManagerController {
|
|
|
outputStream.write(buffer, 0, bytesRead);
|
|
|
}
|
|
|
byte[] imageBytes = outputStream.toByteArray();
|
|
|
- String base64String = Base64.getEncoder().encodeToString(imageBytes);
|
|
|
+ String base64String = map.get(suffix) + Base64.getEncoder().encodeToString(imageBytes);
|
|
|
inputStream.close();
|
|
|
outputStream.close();
|
|
|
|