宋悦 7 жил өмнө
parent
commit
27350f1545

+ 1 - 1
core-api/src/main/java/cn/com/qmth/examcloud/service/core/api/CourseSpeciatlyApi.java

@@ -51,7 +51,7 @@ public class CourseSpeciatlyApi {
 		List<Course> list = courseRepo.findAll();
 		Map map = new HashMap();
 		map.put("courseList", courses);
-		map.put("courseDate", list);
+		map.put("courseAllList", list);
 		return new ResponseEntity(map,HttpStatus.OK);
 	}
 	

+ 44 - 13
core-api/src/main/java/cn/com/qmth/examcloud/service/core/api/SpecialtyApi.java

@@ -1,5 +1,6 @@
 package cn.com.qmth.examcloud.service.core.api;
 
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
@@ -12,8 +13,8 @@ import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 
-
-
+import cn.com.qmth.examcloud.common.util.excel.ExcelError;
+import cn.com.qmth.examcloud.service.core.dto.CourseDTO;
 import io.swagger.annotations.ApiOperation;
 
 
@@ -23,17 +24,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.PageRequest;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
-import org.springframework.web.bind.annotation.DeleteMapping;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.ModelAttribute;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.PutMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-
+import org.springframework.web.bind.annotation.*;
 
 
 import cn.com.qmth.examcloud.common.uac.entity.AccessUser;
@@ -43,6 +34,7 @@ import cn.com.qmth.examcloud.service.core.entity.Specialty;
 import cn.com.qmth.examcloud.service.core.repo.SpecialtyRepo;
 import cn.com.qmth.examcloud.service.core.service.SpecialtyService;
 import cn.com.qmth.examcloud.service.core.util.ExportUtils;
+import org.springframework.web.multipart.commons.CommonsMultipartFile;
 
 /**
  * @Description: 专业服务API
@@ -81,6 +73,18 @@ public class SpecialtyApi {
 		}
 		return new ResponseEntity(specialtyService.findAll(specialty, new PageRequest(curPage-1, pageSize)),HttpStatus.OK);
 	}
+
+	/**
+	 * 按code查询专业
+	 * @param orgId
+	 * @param code
+	 * @return
+	 */
+	@ApiOperation(value="按code查询专业",notes="按code查询专业")
+	@GetMapping
+	public ResponseEntity getAll(@RequestParam Long orgId, @RequestParam String code){
+		return new ResponseEntity(specialtyRepo.findByOrgIdAndCode(orgId,code),HttpStatus.OK);
+	}
 	
 	/**
 	 * 查询专业不带分页
@@ -166,6 +170,33 @@ public class SpecialtyApi {
 		specialtyRepo.delete(Long.parseLong(id));
 		return new ResponseEntity(HttpStatus.OK);
 	}
+
+	@ApiOperation(value="下载导入模板",notes = "下载导入模板")
+	@GetMapping("/download")
+	public void importFileTemplate(HttpServletResponse response){
+		List<SpecialtyDTO> list= new ArrayList<SpecialtyDTO>();
+		ExportUtils.exportEXCEL("专业导入模板", SpecialtyDTO.class, list, response);
+	}
+
+	@ApiOperation(value="导入",notes = "导入")
+	@PostMapping("/import")
+	public ResponseEntity importCourse(HttpServletRequest request,
+									   @RequestParam CommonsMultipartFile file){
+		AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
+		Long orgId = null;
+		if(accessUser != null){
+			orgId = accessUser.getRootOrgId();
+		}else{
+			return new ResponseEntity(new ErrorMsg("用户token不存在或已失效"),HttpStatus.NOT_FOUND);
+		}
+		try {
+			List<ExcelError> errors = specialtyService.importSpecialty(orgId,file.getInputStream());
+			return new ResponseEntity(errors,HttpStatus.OK);
+		} catch (IOException e) {
+			e.printStackTrace();
+			return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR);
+		}
+	}
 	
 	/**
 	 * 导出专业

+ 46 - 0
core-api/src/main/java/cn/com/qmth/examcloud/service/core/service/SpecialtyService.java

@@ -1,5 +1,6 @@
 package cn.com.qmth.examcloud.service.core.service;
 
+import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
@@ -7,7 +8,14 @@ import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
 import javax.persistence.criteria.Predicate;
+import javax.transaction.Transactional;
 
+import cn.com.qmth.examcloud.common.dto.core.enums.CourseLevel;
+import cn.com.qmth.examcloud.common.util.excel.ExcelError;
+import cn.com.qmth.examcloud.common.util.excel.ExcelReader;
+import cn.com.qmth.examcloud.common.util.excel.ExcelReaderHandle;
+import cn.com.qmth.examcloud.service.core.dto.SpecialtyDTO;
+import cn.com.qmth.examcloud.service.core.entity.Specialty;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Pageable;
@@ -25,6 +33,44 @@ public class SpecialtyService {
 
 	@Autowired
 	SpecialtyRepo specialtyRepo;
+
+
+	@Transactional
+	public List<ExcelError> importSpecialty(Long orgId, InputStream inputStream) {
+		List<Specialty> list = new ArrayList<Specialty>();
+		ExcelReader excelReader = new ExcelReader(SpecialtyDTO.class);
+		List<ExcelError> excelErrors = excelReader.reader(inputStream, new ExcelReaderHandle() {
+			@Override
+			public ExcelError handle(Object obj) {
+				SpecialtyDTO dto = (SpecialtyDTO) obj;
+				Specialty specialty = new Specialty(dto.getCode(),dto.getName());
+				specialty.setOrgId(orgId);
+				specialty.setCreateTime(new Date());
+				specialty.setEnable(true);
+				ExcelError error = importCheck(specialty);
+				if (error == null) {
+					list.add(specialty);
+				}
+				return error;
+			}
+		});
+		List<Specialty> specialtyList = specialtyRepo.save(list);
+		return excelErrors;
+	}
+
+	private ExcelError importCheck(Specialty Specialty) {
+		if(StringUtils.isEmpty(Specialty.getCode())){
+			return new ExcelError("代码不能为空");
+		}
+		if(StringUtils.isEmpty(Specialty.getName())){
+			return new ExcelError("名称不能为空");
+		}
+		Specialty domain = specialtyRepo.findByOrgIdAndCode(Specialty.getOrgId(),Specialty.getCode());
+		if(domain != null){
+			return new ExcelError("代码已存在");
+		}
+		return null;
+	}
 	
 	/**
 	 * 带分页查询专业

+ 11 - 0
core-api/src/main/java/cn/com/qmth/examcloud/service/core/service/StudentFaceInfoService.java

@@ -4,6 +4,8 @@ import java.util.Date;
 
 import javax.transaction.Transactional;
 
+import cn.com.qmth.examcloud.service.core.entity.Student;
+import cn.com.qmth.examcloud.service.core.repo.StudentRepo;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -17,6 +19,9 @@ public class StudentFaceInfoService {
     @Autowired
     StudentFaceInfoRepo studentFaceInfoRepo;
 
+	@Autowired
+	StudentRepo studentRepo;
+
     @Transactional
     public StudentFaceInfo save(StudentFaceInfo studentFaceInfo) {
     	StudentFaceInfo old = studentFaceInfoRepo.findByStudentId(studentFaceInfo.getStudent().getId());
@@ -28,6 +33,12 @@ public class StudentFaceInfoService {
     	old.setFaceSetToken(studentFaceInfo.getFaceSetToken());
     	old.setFaceToken(studentFaceInfo.getFaceToken());
     	old.setPhotoMD5(studentFaceInfo.getPhotoMD5());
+
+		Student student = studentRepo.findOne(studentFaceInfo.getStudent().getId());
+		if(student != null){
+			student.setPhotoPath(student.getIdentityNumber()+"/"+studentFaceInfo.getPhotoMD5());
+			studentRepo.save(student);
+		}
         return studentFaceInfoRepo.save(old);
     }
 

+ 6 - 1
core-api/src/main/java/cn/com/qmth/examcloud/service/core/service/StudentService.java

@@ -41,12 +41,16 @@ public class StudentService {
 
     @Autowired
     StudentRepo studentRepo;
+
     @Autowired
     UserRepo userRepo;
+
     @Autowired
     UserService userService;
+
     @Autowired
     OrgRepo orgRepo;
+
     @Autowired
     DataSendService dataSendService;
 
@@ -62,7 +66,8 @@ public class StudentService {
     public Page<Student> getAllStudent(Student studentCriteria, Pageable pageable) {
         ExampleMatcher exampleMatcher = ExampleMatcher.matching()
                 .withMatcher("name", contains())
-                .withMatcher("studentCode", contains()).withIgnoreNullValues();
+                .withMatcher("studentCode", contains())
+                .withMatcher("identityNumber", contains()).withIgnoreNullValues();
         Example<Student> studentExample = Example.of(studentCriteria, exampleMatcher);
         return studentRepo.findAll(studentExample, pageable);
     }

+ 31 - 15
core-api/src/main/java/cn/com/qmth/examcloud/service/core/service/UserService.java

@@ -15,10 +15,7 @@ import javax.persistence.criteria.*;
 
 import org.apache.commons.lang.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.domain.Example;
-import org.springframework.data.domain.ExampleMatcher;
-import org.springframework.data.domain.Page;
-import org.springframework.data.domain.Pageable;
+import org.springframework.data.domain.*;
 import org.springframework.data.jpa.domain.Specification;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
@@ -90,15 +87,6 @@ public class UserService {
     public Page<User> findAll(User userCriteria, Pageable pageable){
         Specification<User> userSpecification = (root, query, cb) -> {
             List<Predicate> predicates = new ArrayList<>();
-//            Subquery<UserRole> subquery = query.subquery(UserRole.class);
-//            Root<UserRole> subRootEntity = subquery.from(UserRole.class);
-//            List<Predicate> subPredicates = new ArrayList<Predicate>();
-//            subPredicates.add(cb.equal(subRootEntity.get("roleCode"), RoleMeta.MARKER.name()));
-//            subPredicates.add(cb.equal(subRootEntity.get("userId"), root.get("id")));
-//            subquery.select(subRootEntity).where(subPredicates.toArray(new Predicate[subPredicates.size()]));
-//            predicates.add(cb.not(cb.exists(subquery)));
-//            Join join = root.join("userRoles");
-//            predicates.add(cb.equal(join.get("roleCode"), RoleMeta.MARKER.name()));
             predicates.add(cb.equal(root.get("type"),UserType.NOT_STUDENT));
             predicates.add(cb.equal(root.get("rootOrgId"),userCriteria.getRootOrgId()));
             if(StringUtils.isNotEmpty(userCriteria.getLoginName())){
@@ -115,8 +103,36 @@ public class UserService {
             }
             return cb.and(predicates.toArray(new Predicate[predicates.size()]));
         };
-        Page<User> users = userRepo.findAll(userSpecification, pageable);
-        return users;
+        List<User> users = userRepo.findAll(userSpecification);
+        int pageNumber = pageable.getPageNumber();
+        int pageSize = pageable.getPageSize();
+        users = users.stream()
+                .filter(user -> filterUser(user))
+                .collect(Collectors.toList());
+        long total = users.size();
+        users = users.stream()
+                .skip(pageNumber * pageSize)
+                .limit(pageSize)
+                .collect(Collectors.toList());
+        Page<User> userPage = new PageImpl<User>(users,pageable,total);
+        return userPage;
+    }
+
+    /**
+     * 过滤评卷员
+     * @param user
+     * @return
+     */
+    private boolean filterUser(User user){
+        List<UserRole> userRoles = user.getUserRoles();
+        if(userRoles != null){
+            if(userRoles.size() == 1 && userRoles.get(0).getRoleCode().equals(RoleMeta.MARKER.name())){
+                return false;
+            }
+            return true;
+        }else{
+            return false;
+        }
     }
 
     /**

+ 8 - 0
core-domain/src/main/java/cn/com/qmth/examcloud/service/core/entity/Specialty.java

@@ -106,4 +106,12 @@ public class Specialty implements Serializable{
 	public static long getSerialversionuid() {
 		return serialVersionUID;
 	}
+
+	public Specialty(String code, String name) {
+		this.code = code;
+		this.name = name;
+	}
+
+	public Specialty() {
+	}
 }