Quellcode durchsuchen

Merge remote-tracking branch 'origin/dev' into dev

wangliang vor 4 Jahren
Ursprung
Commit
9056af8150

+ 39 - 10
themis-backend/src/main/java/com/qmth/themis/backend/api/TEStudentController.java

@@ -1,12 +1,26 @@
 package com.qmth.themis.backend.api;
 
+import java.util.Collections;
+import java.util.Map;
+import java.util.Objects;
+
+import javax.annotation.Resource;
+
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
+
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.google.gson.Gson;
 import com.qmth.themis.business.annotation.ApiJsonObject;
 import com.qmth.themis.business.annotation.ApiJsonProperty;
 import com.qmth.themis.business.base.BasePage;
-import com.qmth.themis.business.constant.SystemConstant;
 import com.qmth.themis.business.dto.cache.TEStudentCacheDto;
 import com.qmth.themis.business.dto.response.TEStudentDto;
 import com.qmth.themis.business.dto.response.TEStudentExamRecordDto;
@@ -14,22 +28,18 @@ import com.qmth.themis.business.entity.TBUser;
 import com.qmth.themis.business.entity.TEStudent;
 import com.qmth.themis.business.entity.TOeExamRecord;
 import com.qmth.themis.business.service.TEStudentService;
-import com.qmth.themis.business.util.JacksonUtil;
 import com.qmth.themis.business.util.RedisUtil;
 import com.qmth.themis.business.util.ServletUtil;
 import com.qmth.themis.common.enums.ExceptionResultEnum;
 import com.qmth.themis.common.exception.BusinessException;
 import com.qmth.themis.common.util.Result;
 import com.qmth.themis.common.util.ResultUtil;
-import io.swagger.annotations.*;
-import org.springframework.transaction.annotation.Transactional;
-import org.springframework.web.bind.annotation.*;
 
-import javax.annotation.Resource;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
 
 /**
  * @Description: 学生档案 前端控制器
@@ -129,4 +139,23 @@ public class TEStudentController {
         BasePage basePage = new BasePage(teStudentExamRecordDtoIPage.getRecords(), teStudentExamRecordDtoIPage.getCurrent(), teStudentExamRecordDtoIPage.getSize(), teStudentExamRecordDtoIPage.getTotal());
         return ResultUtil.ok(basePage);
     }
+    
+    @ApiOperation(value = "底照上传")
+    @RequestMapping(value = "/photo/upload", method = RequestMethod.POST)
+    @ApiResponses({@ApiResponse(code = 200, message = "结果信息")})
+    public Result photoUpload(@ApiParam(value = "证件号", required = true) @RequestParam String identity,
+                             @ApiParam(value = "上传文件", required = true) @RequestParam MultipartFile file,
+                             @ApiParam(value = "md5", required = true) @RequestParam String md5) {
+    	if (StringUtils.isBlank(identity)) {
+            throw new BusinessException("证件号不能为空");
+        }
+    	if (file==null) {
+            throw new BusinessException("文件不能为空");
+        }
+    	if (StringUtils.isBlank(md5)) {
+            throw new BusinessException("md5不能为空");
+        }
+    	TBUser tbUser = (TBUser) ServletUtil.getRequestAccount();
+        return ResultUtil.ok(teStudentService.photoUpload(tbUser.getOrgId(), identity, file,  md5));
+    }
 }

+ 1 - 1
themis-backend/src/main/resources/application.properties

@@ -164,4 +164,4 @@ prefix.url.admin=api/admin
 
 #\u65E0\u9700\u9274\u6743\u7684url
 no.auth.urls=/webjars/**,/druid/**,/swagger-ui.html,/doc.html,/swagger-resources/**,/v2/api-docs,/webjars/springfox-swagger-ui/**,/api/admin/user/login/account,/api/admin/sys/org/queryByOrgCode,/file/**,/upload/**,/client/**,/base_photo/**,/frontend/**,/api/admin/monitor/call/list,/api/admin/monitor/call/query
-common.system.urls=/api/admin/sys/getMenu,/api/admin/user/logout,/api/admin/sys/env,/api/admin/sys/file/upload,/api/admin/sys/file/download,/api/admin/sys/org/query,/api/admin/sys/role/query,/api/admin/sys/examActivity/query,/api/admin/sys/exam/query,/api/admin/sys/examRoom/query
+common.system.urls=/api/admin/sys/getMenu,/api/admin/user/logout,/api/admin/sys/env,/api/admin/sys/file/upload,/api/admin/sys/file/download,/api/admin/sys/org/query,/api/admin/sys/role/query,/api/admin/sys/examActivity/query,/api/admin/sys/exam/query,/api/admin/sys/examRoom/query,/api/admin/student/photo/upload

+ 19 - 0
themis-business/src/main/java/com/qmth/themis/business/bean/backend/StudentPhotoUploadResponseBean.java

@@ -0,0 +1,19 @@
+package com.qmth.themis.business.bean.backend;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
+@ApiModel("学生底照上传返回信息")
+public class StudentPhotoUploadResponseBean {
+	@ApiModelProperty("照片地址")
+	private String photoUrl;
+	public String getPhotoUrl() {
+		return photoUrl;
+	}
+	public void setPhotoUrl(String photoUrl) {
+		this.photoUrl = photoUrl;
+	}
+
+	
+	
+}

+ 14 - 2
themis-business/src/main/java/com/qmth/themis/business/service/TEStudentService.java

@@ -1,13 +1,16 @@
 package com.qmth.themis.business.service;
 
+import java.util.Map;
+
+import org.springframework.web.multipart.MultipartFile;
+
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.qmth.themis.business.bean.backend.StudentPhotoUploadResponseBean;
 import com.qmth.themis.business.dto.response.TEStudentDto;
 import com.qmth.themis.business.dto.response.TEStudentExamRecordDto;
 import com.qmth.themis.business.entity.TEStudent;
 
-import java.util.Map;
-
 /**
  * @Description: 学生档案 服务类
  * @Param:
@@ -37,4 +40,13 @@ public interface TEStudentService extends IService<TEStudent> {
      * @return
      */
     public IPage<TEStudentExamRecordDto> studentExamRecordQuery(IPage<Map> iPage, Long studentId, Long examId);
+
+	/**底照上传
+	 * @param orgId
+	 * @param identity
+	 * @param file
+	 * @param md5
+	 * @return
+	 */
+    public StudentPhotoUploadResponseBean photoUpload(Long orgId, String identity, MultipartFile file, String md5);
 }

+ 60 - 4
themis-business/src/main/java/com/qmth/themis/business/service/impl/TEStudentServiceImpl.java

@@ -1,16 +1,28 @@
 package com.qmth.themis.business.service.impl;
 
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Map;
+
+import javax.annotation.Resource;
+
+import org.apache.commons.codec.digest.DigestUtils;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.multipart.MultipartFile;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.qmth.themis.business.bean.backend.StudentPhotoUploadResponseBean;
+import com.qmth.themis.business.config.SystemConfig;
 import com.qmth.themis.business.dao.TEStudentMapper;
 import com.qmth.themis.business.dto.response.TEStudentDto;
 import com.qmth.themis.business.dto.response.TEStudentExamRecordDto;
 import com.qmth.themis.business.entity.TEStudent;
 import com.qmth.themis.business.service.TEStudentService;
-import org.springframework.stereotype.Service;
-
-import javax.annotation.Resource;
-import java.util.Map;
+import com.qmth.themis.business.util.OssUtil;
+import com.qmth.themis.common.exception.BusinessException;
 
 /**
  * @Description: 学生档案 服务实现类
@@ -24,6 +36,10 @@ public class TEStudentServiceImpl extends ServiceImpl<TEStudentMapper, TEStudent
 
     @Resource
     TEStudentMapper teStudentMapper;
+    
+
+    @Resource
+    SystemConfig systemConfig;
 
     /**
      * 学生档案查询
@@ -51,4 +67,44 @@ public class TEStudentServiceImpl extends ServiceImpl<TEStudentMapper, TEStudent
     public IPage<TEStudentExamRecordDto> studentExamRecordQuery(IPage<Map> iPage, Long studentId, Long examId) {
         return teStudentMapper.studentExamRecordQuery(iPage, studentId, examId);
     }
+    
+    
+    @Transactional
+    @Override
+    public StudentPhotoUploadResponseBean photoUpload(Long orgId, String identity, MultipartFile file, String md5) {
+    	QueryWrapper<TEStudent> wrapper = new QueryWrapper<>();
+    	wrapper.lambda().eq(TEStudent::getOrgId, orgId);
+    	wrapper.lambda().eq(TEStudent::getIdentity, identity);
+    	TEStudent student=this.getOne(wrapper);
+    	if(student==null) {
+    		throw new BusinessException("学生不存在");
+    	}
+    	String fileName = file.getOriginalFilename();
+        String suffix = fileName.substring(fileName.lastIndexOf(".")+1).toLowerCase();
+        String filePath = "base_photo/"+orgId+"/"+student.getId()+"."+suffix;
+        InputStream in = null;
+        try {
+        	String fileMd5 = DigestUtils.md5Hex(file.getBytes());
+        	if (!md5.equals(fileMd5)) {
+        		throw new BusinessException("文件md5不一致");
+        	}
+        	student.setBasePhotoPath(filePath);
+        	this.saveOrUpdate(student);
+            in = file.getInputStream();
+            OssUtil.ossUploadStream(systemConfig.getOssEnv(3), filePath, in);
+            String url = systemConfig.getProperty("aliyun.oss.url") + "/" + filePath;
+            StudentPhotoUploadResponseBean ret=new StudentPhotoUploadResponseBean();
+            ret.setPhotoUrl(url);
+            return ret;
+        } catch (IOException e) {
+        	throw new BusinessException("文件读取出错");
+        } finally {
+            if (in != null) {
+                try {
+                    in.close();
+                } catch (IOException e) {
+                }
+            }
+        }
+    }
 }