|
@@ -7,7 +7,6 @@ import java.util.List;
|
|
|
import org.apache.commons.io.FileUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
@@ -28,6 +27,7 @@ import cn.com.qmth.examcloud.exchange.outer.api.request.OuterSaveStudentReq;
|
|
|
import cn.com.qmth.examcloud.exchange.outer.api.response.BatchOuterSaveStudentResp;
|
|
|
import cn.com.qmth.examcloud.exchange.outer.api.response.OuterSaveStudentResp;
|
|
|
import cn.com.qmth.examcloud.exchange.outer.service.FaceService;
|
|
|
+import cn.com.qmth.examcloud.web.config.SystemConfig;
|
|
|
import cn.com.qmth.examcloud.web.support.ControllerSupport;
|
|
|
import cn.com.qmth.examcloud.web.support.StatusResponse;
|
|
|
import io.swagger.annotations.Api;
|
|
@@ -56,8 +56,8 @@ public class StudentOuterServiceProvider extends ControllerSupport implements St
|
|
|
@Autowired
|
|
|
private FaceService faceService;
|
|
|
|
|
|
- @Value("${$tempDir}")
|
|
|
- private String tempDir;
|
|
|
+ @Autowired
|
|
|
+ SystemConfig systemConfig;
|
|
|
|
|
|
@ApiOperation(value = "保存学生信息", httpMethod = "POST")
|
|
|
@ApiResponses({@ApiResponse(code = 200, message = "成功", response = OuterSaveStudentResp.class),
|
|
@@ -69,7 +69,7 @@ public class StudentOuterServiceProvider extends ControllerSupport implements St
|
|
|
trim(req);
|
|
|
Long rootOrgId = req.getRootOrgId();
|
|
|
if (!getSecurityRootOrgId().equals(rootOrgId)) {
|
|
|
- throw new StatusException("EX-1000001", "rootOrgId is wrong");
|
|
|
+ throw new StatusException("1000001", "rootOrgId is wrong");
|
|
|
}
|
|
|
|
|
|
SaveStudentReq request = new SaveStudentReq();
|
|
@@ -82,16 +82,17 @@ public class StudentOuterServiceProvider extends ControllerSupport implements St
|
|
|
request.setRemark(req.getRemark());
|
|
|
request.setRootOrgId(req.getRootOrgId());
|
|
|
request.setStudentCode(req.getStudentCode());
|
|
|
-
|
|
|
- return processOuterSaveStudentReq(request,req.getPhotoUrl(),req.getOperator());
|
|
|
+
|
|
|
+ return processOuterSaveStudentReq(request, req.getPhotoUrl(), req.getOperator());
|
|
|
}
|
|
|
-
|
|
|
- private OuterSaveStudentResp processOuterSaveStudentReq(SaveStudentReq saveStudentReq,String photoUrl,String operator){
|
|
|
- //保存学生
|
|
|
+
|
|
|
+ private OuterSaveStudentResp processOuterSaveStudentReq(SaveStudentReq saveStudentReq,
|
|
|
+ String photoUrl, String operator) {
|
|
|
+ // 保存学生
|
|
|
SaveStudentResp response = studentCloudService.saveStudent(saveStudentReq);
|
|
|
- //处理照片
|
|
|
- processPhotoUrl(saveStudentReq,photoUrl,operator);
|
|
|
-
|
|
|
+ // 处理照片
|
|
|
+ processPhotoUrl(saveStudentReq, photoUrl, operator);
|
|
|
+
|
|
|
OuterSaveStudentResp resp = new OuterSaveStudentResp();
|
|
|
resp.setOrgId(response.getOrgId());
|
|
|
resp.setOrgName(response.getOrgName());
|
|
@@ -99,28 +100,29 @@ public class StudentOuterServiceProvider extends ControllerSupport implements St
|
|
|
resp.setStudentId(response.getStudentId());
|
|
|
return resp;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 处理照片
|
|
|
+ *
|
|
|
* @param req
|
|
|
*/
|
|
|
- private void processPhotoUrl(SaveStudentReq request,String photoUrl,String operator){
|
|
|
+ private void processPhotoUrl(SaveStudentReq request, String photoUrl, String operator) {
|
|
|
Long rootOrgId = request.getRootOrgId();
|
|
|
String identityNumber = request.getIdentityNumber();
|
|
|
-
|
|
|
+
|
|
|
if (StringUtils.isNotBlank(photoUrl)) {
|
|
|
byte[] bs = HttpClientUtil.get(photoUrl);
|
|
|
|
|
|
int lastIndexOf = photoUrl.lastIndexOf(".");
|
|
|
if (0 > lastIndexOf) {
|
|
|
- throw new StatusException("EX-100002",
|
|
|
+ throw new StatusException("100002",
|
|
|
"photoPath is not end with photo file suffix.");
|
|
|
}
|
|
|
String fileSuffix = photoUrl.substring(lastIndexOf);
|
|
|
|
|
|
String fileName = System.currentTimeMillis() + fileSuffix;
|
|
|
- File temp = new File(
|
|
|
- tempDir + File.separator + "student_photo" + File.separator + fileName);
|
|
|
+ File temp = new File(systemConfig.getTempDataDir() + File.separator + "student_photo"
|
|
|
+ + File.separator + fileName);
|
|
|
|
|
|
try {
|
|
|
FileUtils.writeByteArrayToFile(temp, bs);
|
|
@@ -130,11 +132,11 @@ public class StudentOuterServiceProvider extends ControllerSupport implements St
|
|
|
} catch (IOException ex) {
|
|
|
// ignore
|
|
|
}
|
|
|
- throw new StatusException("EX-100003", "文件读写失败", e);
|
|
|
+ throw new StatusException("100003", "文件读写失败", e);
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
- faceService.processFace(rootOrgId, identityNumber, fileSuffix, temp,operator);
|
|
|
+ faceService.processFace(rootOrgId, identityNumber, fileSuffix, temp, operator);
|
|
|
} finally {
|
|
|
try {
|
|
|
FileUtils.forceDelete(temp);
|
|
@@ -144,23 +146,24 @@ public class StudentOuterServiceProvider extends ControllerSupport implements St
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
@ApiOperation(value = "批量保存学生信息", httpMethod = "POST")
|
|
|
@ApiResponses({
|
|
|
@ApiResponse(code = 200, message = "成功", response = BatchOuterSaveStudentResp.class),
|
|
|
@ApiResponse(code = 500, message = "系统异常(异常信息见响应体)", response = StatusResponse.class)})
|
|
|
@PostMapping("batchSaveStudent")
|
|
|
@Override
|
|
|
- public BatchOuterSaveStudentResp batchSaveStudent(@RequestBody @ApiParam(required = true) OuterBatchSaveStudentReq outerBatchSaveStudentReq) {
|
|
|
+ public BatchOuterSaveStudentResp batchSaveStudent(
|
|
|
+ @RequestBody @ApiParam(required = true) OuterBatchSaveStudentReq outerBatchSaveStudentReq) {
|
|
|
if (!getSecurityRootOrgId().equals(outerBatchSaveStudentReq.getRootOrgId())) {
|
|
|
- throw new StatusException("EX-1000001", "rootOrgId is wrong");
|
|
|
+ throw new StatusException("1000001", "rootOrgId is wrong");
|
|
|
}
|
|
|
List<Student4BatchBean> studentList = outerBatchSaveStudentReq.getStudentList();
|
|
|
-
|
|
|
+
|
|
|
List<StudentStatus4BatchBean> successList = Lists.newArrayList();
|
|
|
List<StudentStatus4BatchBean> failureList = Lists.newArrayList();
|
|
|
-
|
|
|
- for(Student4BatchBean req:studentList){
|
|
|
+
|
|
|
+ for (Student4BatchBean req : studentList) {
|
|
|
SaveStudentReq request = new SaveStudentReq();
|
|
|
request.setIdentityNumber(req.getIdentityNumber());
|
|
|
request.setName(req.getName());
|
|
@@ -171,16 +174,17 @@ public class StudentOuterServiceProvider extends ControllerSupport implements St
|
|
|
request.setRemark(req.getRemark());
|
|
|
request.setRootOrgId(req.getRootOrgId());
|
|
|
request.setStudentCode(req.getStudentCode());
|
|
|
-
|
|
|
- try{
|
|
|
- OuterSaveStudentResp outerSaveStudentResp = processOuterSaveStudentReq(request,req.getPhotoUrl(),req.getOperator());
|
|
|
+
|
|
|
+ try {
|
|
|
+ OuterSaveStudentResp outerSaveStudentResp = processOuterSaveStudentReq(request,
|
|
|
+ req.getPhotoUrl(), req.getOperator());
|
|
|
StudentStatus4BatchBean studentStatus4BatchBeanSuccess = new StudentStatus4BatchBean();
|
|
|
studentStatus4BatchBeanSuccess.setStudentId(outerSaveStudentResp.getStudentId());
|
|
|
studentStatus4BatchBeanSuccess.setIdentityNumber(req.getIdentityNumber());
|
|
|
studentStatus4BatchBeanSuccess.setName(req.getName());
|
|
|
studentStatus4BatchBeanSuccess.setStudentCode(req.getStudentCode());
|
|
|
successList.add(studentStatus4BatchBeanSuccess);
|
|
|
- }catch(Exception e){
|
|
|
+ } catch (Exception e) {
|
|
|
StudentStatus4BatchBean studentStatus4BatchBeanfailure = new StudentStatus4BatchBean();
|
|
|
studentStatus4BatchBeanfailure.setIdentityNumber(req.getIdentityNumber());
|
|
|
studentStatus4BatchBeanfailure.setName(req.getName());
|