|
@@ -1,18 +1,12 @@
|
|
|
package cn.hmsoft.art.service.ex.pad;
|
|
|
|
|
|
-import java.io.File;
|
|
|
-import java.time.LocalDateTime;
|
|
|
-import java.util.Date;
|
|
|
-
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.web.multipart.MultipartFile;
|
|
|
-
|
|
|
import cn.hmsoft.art.constants.ExamStdLogType;
|
|
|
import cn.hmsoft.art.constants.StdImageType;
|
|
|
import cn.hmsoft.art.data.dao.ex.ExStdLogDao;
|
|
|
+import cn.hmsoft.art.data.dao.ly.LyRoomModelPhotoDao;
|
|
|
import cn.hmsoft.art.data.dao.ly.LyStdSubjectDao;
|
|
|
import cn.hmsoft.art.data.dao.std.StdRegDao;
|
|
|
+import cn.hmsoft.art.data.model.ly.LyRoomModelPhoto;
|
|
|
import cn.hmsoft.art.data.model.ly.LyRoomWritten;
|
|
|
import cn.hmsoft.art.data.model.std.StdReg;
|
|
|
import cn.hmsoft.art.helper.ArtParamHelper;
|
|
@@ -21,60 +15,99 @@ import cn.hmsoft.frame.exception.BusinessException;
|
|
|
import cn.hmsoft.frame.util.FrameAssertUtil;
|
|
|
import cn.hmsoft.helper.FileHelper;
|
|
|
import cn.hmsoft.helper.RandomHelper;
|
|
|
+import cn.hmsoft.log.LogHelper;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
@Service
|
|
|
public class PadAppService extends ArtService {
|
|
|
+
|
|
|
@Autowired
|
|
|
private LyStdSubjectDao daoSubject;
|
|
|
+
|
|
|
@Autowired
|
|
|
private StdRegDao daoStd;
|
|
|
+
|
|
|
@Autowired
|
|
|
private ExStdLogDao daoLog;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private LyRoomModelPhotoDao roomModelPhotoDao;
|
|
|
|
|
|
//模特照片上传
|
|
|
public void uploadMoteImage(int room_id, int room_image_type, MultipartFile file) {
|
|
|
String suffix = FileHelper.getFileSuffix(file);
|
|
|
FrameAssertUtil.isNotEmpty(suffix, "必须带有图片格式的后缀名");
|
|
|
- String filename= file.getOriginalFilename().indexOf(".") > 0 ? file.getOriginalFilename().substring(0,file.getOriginalFilename().lastIndexOf(".")) : null;
|
|
|
- File newFile = this.makeMoteImageFile("mote_"+filename, room_id, room_image_type, suffix);
|
|
|
- if (!this.upload(file, newFile))
|
|
|
+ if (!suffix.equalsIgnoreCase("png") && !suffix.equalsIgnoreCase("jpg") && !suffix.equalsIgnoreCase("jpeg")) {
|
|
|
+ throw new BusinessException("请上传后缀为png、jpg、jpeg格式的图片文件");
|
|
|
+ }
|
|
|
+
|
|
|
+ //文件名称
|
|
|
+ String filename = Objects.requireNonNull(file.getOriginalFilename()).indexOf(".") > 0 ?
|
|
|
+ file.getOriginalFilename().substring(0, file.getOriginalFilename().lastIndexOf(".")) :
|
|
|
+ null;
|
|
|
+ LyRoomWritten rw = daoSubject.find(LyRoomWritten.class, room_id);
|
|
|
+ if (rw == null) {
|
|
|
+ throw new BusinessException("考场不存在,请确认考场是否正确");
|
|
|
+ }
|
|
|
+ File newFile = this.makeMoteImageFile(rw, "mote_" + filename, room_id, room_image_type, suffix);
|
|
|
+ if (!this.upload(file, newFile)) {
|
|
|
throw new BusinessException("服务器保存照片失败,请重试");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 关联考场
|
|
|
+ String photoPath = "mote" + File.separator + rw.getRoom_name() + "(" + rw.getRoom_addr() + ")" + File.separator + newFile.getName();
|
|
|
+ LyRoomModelPhoto photo = new LyRoomModelPhoto();
|
|
|
+ photo.setRoom_id(room_id);
|
|
|
+ photo.setPhoto_path(photoPath);
|
|
|
+ photo.setSeq(room_image_type);
|
|
|
+ photo.setCreate_time(LocalDateTime.now());
|
|
|
+ roomModelPhotoDao.insert(photo);
|
|
|
}
|
|
|
-
|
|
|
- public void uploadImage(int std_id, int agent_id, int room_id, int subject_id,
|
|
|
- String img_time, MultipartFile file) {
|
|
|
+
|
|
|
+ public void uploadImage(int std_id, int agent_id, int room_id, int subject_id, String img_time, MultipartFile file) {
|
|
|
+ // 图片格式判断
|
|
|
String suffix = FileHelper.getFileSuffix(file);
|
|
|
FrameAssertUtil.isNotEmpty(suffix, "必须带有图片格式的后缀名");
|
|
|
+ if (!suffix.equalsIgnoreCase("png") && !suffix.equalsIgnoreCase("jpg") && !suffix.equalsIgnoreCase("jpeg")) {
|
|
|
+ throw new BusinessException("请上传后缀为png、jpg、jpeg格式的图片文件");
|
|
|
+ }
|
|
|
+
|
|
|
StdReg std = this.daoStd.find(std_id);
|
|
|
- String file_name = "";
|
|
|
- File newFile = this.makeStdImageFile(StdImageType.StdWrite, agent_id,
|
|
|
- subject_id, std.getCert_id(), suffix);
|
|
|
- if (!this.upload(file, newFile))
|
|
|
+
|
|
|
+ // 上传图片到服务器
|
|
|
+ String file_name;
|
|
|
+ File newFile = this.makeStdImageFile(StdImageType.StdWrite, agent_id, subject_id, std.getCert_id(), suffix);
|
|
|
+ if (!this.upload(file, newFile)) {
|
|
|
throw new BusinessException("服务器保存照片失败,请重试");
|
|
|
+ }
|
|
|
// 保存图片
|
|
|
file_name = newFile.getName();
|
|
|
- this.daoLog.log(std_id, agent_id, subject_id, room_id,
|
|
|
- ExamStdLogType.ExamPhoto, LocalDateTime.now(), null);
|
|
|
- this.daoSubject.updateStdWrittenPhoto(room_id, std_id, subject_id, file_name +'.' + suffix);
|
|
|
+ //更新数据库中的图片字段
|
|
|
+ this.daoSubject.updateStdWrittenPhoto(room_id, std_id, subject_id, file_name + '.' + suffix);
|
|
|
+
|
|
|
+ this.daoLog.log(std_id, agent_id, subject_id, room_id, ExamStdLogType.ExamPhoto, LocalDateTime.now(), null);
|
|
|
+
|
|
|
}
|
|
|
-
|
|
|
- private File makeMoteImageFile(String image_type, int room_id,
|
|
|
- int room_image_type, String dot) {
|
|
|
- LyRoomWritten rw = daoSubject.find(LyRoomWritten.class, room_id);
|
|
|
+
|
|
|
+ private File makeMoteImageFile(LyRoomWritten rw, String image_type, int room_id, int room_image_type, String dot) {
|
|
|
+ // LyRoomWritten rw = daoSubject.find(LyRoomWritten.class, room_id);
|
|
|
File file = new File(ArtParamHelper.EnrolMaterialLocalPath
|
|
|
- + File.separator + "mote" + File.separator + rw.getRoom_name()+"(" + rw.getRoom_addr()+")" + File.separator + image_type
|
|
|
+ + File.separator + "mote" + File.separator + rw.getRoom_name() + "(" + rw.getRoom_addr() + ")" + File.separator + image_type
|
|
|
+ "_" + room_id + "_" + room_image_type + "_"
|
|
|
+ RandomHelper.getRandomValue(8) + "." + dot);
|
|
|
file.getParentFile().mkdirs();
|
|
|
return file;
|
|
|
}
|
|
|
-
|
|
|
- private File makeStdImageFile(String image_type, int agent_id,
|
|
|
- int subject_id, String cert_id, String dot) {
|
|
|
- File file = new File(ArtParamHelper.EnrolMaterialLocalPath
|
|
|
- + File.separator + image_type + File.separator + image_type
|
|
|
- + "_" + agent_id + "_" + subject_id + "_" + cert_id + "_"
|
|
|
- + RandomHelper.getRandomValue(8) + "." + dot);
|
|
|
+
|
|
|
+ private File makeStdImageFile(String image_type, int agent_id, int subject_id, String cert_id, String dot) {
|
|
|
+ File file = new File(ArtParamHelper.EnrolMaterialLocalPath + File.separator + image_type + File.separator + image_type
|
|
|
+ + "_" + agent_id + "_" + subject_id + "_" + cert_id + "_" + RandomHelper.getRandomValue(8) + "." + dot);
|
|
|
file.getParentFile().mkdirs();
|
|
|
return file;
|
|
|
}
|
|
@@ -86,9 +119,24 @@ public class PadAppService extends ArtService {
|
|
|
try {
|
|
|
source.transferTo(target);
|
|
|
} catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
+ LogHelper.error(e);
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ LyRoomWritten rw = new LyRoomWritten();
|
|
|
+ rw.setRoom_name("第1考场");
|
|
|
+ rw.setRoom_addr("附中教学楼1208");
|
|
|
+ String image_type = "mote_测试";
|
|
|
+ int room_id = 88;
|
|
|
+ int room_image_type = 1;
|
|
|
+ String dot = "jpg";
|
|
|
+ File file = new File(ArtParamHelper.EnrolMaterialLocalPath
|
|
|
+ + File.separator + "mote" + File.separator + rw.getRoom_name() + "(" + rw.getRoom_addr() + ")" + File.separator + image_type
|
|
|
+ + "_" + room_id + "_" + room_image_type + "_"
|
|
|
+ + RandomHelper.getRandomValue(8) + "." + dot);
|
|
|
+ System.out.println(file.getName());
|
|
|
+ }
|
|
|
}
|