Răsfoiți Sursa

user增加rootOrgId

ting.yin 8 ani în urmă
părinte
comite
c68968090f

+ 14 - 10
core-api/src/main/java/cn/com/qmth/examcloud/service/core/api/CourseApi.java

@@ -3,10 +3,9 @@ package cn.com.qmth.examcloud.service.core.api;
 import io.swagger.annotations.ApiOperation;
 
 import java.io.IOException;
+import java.util.Date;
 import java.util.List;
 
-import javax.servlet.http.HttpServletRequest;
-
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
@@ -21,7 +20,6 @@ import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.multipart.MultipartFile;
 
-import cn.com.qmth.examcloud.common.uac.entity.AccessUser;
 import cn.com.qmth.examcloud.common.util.excel.ExcelError;
 import cn.com.qmth.examcloud.service.core.entity.Course;
 import cn.com.qmth.examcloud.service.core.repo.CourseRepo;
@@ -41,16 +39,22 @@ public class CourseApi {
     @Autowired
     CourseService courseService;
 
-    @ApiOperation(value="查询所有课程")
+    @ApiOperation(value="查询所有课程",notes="enable为查询条件,可为空")
     @GetMapping
-    public ResponseEntity getAllCourse(){
-        return new ResponseEntity(courseRepo.findAll(), HttpStatus.OK);
+    public ResponseEntity getAllCourse(@RequestParam Long orgId,@RequestParam(required = false) Boolean enable){
+    	List<Course> list = null;
+    	if(enable!=null){
+    		list = courseRepo.findByOrgIdAndEnable(orgId,enable);
+    	}else{
+    		list = courseRepo.findByOrgId(orgId);
+    	}
+    	return new ResponseEntity(list, HttpStatus.OK);
     }
 
     @ApiOperation(value="按ID查询课程",notes="ID查询")
     @GetMapping("/{id}")
     public ResponseEntity getCourseById(@PathVariable Long id){
-        return new ResponseEntity(courseRepo.findById(id),HttpStatus.OK);
+        return new ResponseEntity(courseRepo.findOne(id),HttpStatus.OK);
     }
 
     @ApiOperation(value="新增课程",notes="新增")
@@ -62,6 +66,7 @@ public class CourseApi {
     @ApiOperation(value="更新课程",notes="更新")
     @PutMapping
     public ResponseEntity updateCourse(@RequestBody Course course){
+    	course.setUpdateTime(new Date());
         return new ResponseEntity(courseRepo.save(course),HttpStatus.OK);
     }
 
@@ -74,10 +79,9 @@ public class CourseApi {
     
     @ApiOperation(value="导入课程",notes = "导入")
     @PostMapping("/import")
-    public ResponseEntity importCourse(HttpServletRequest request,@RequestParam MultipartFile file){
+    public ResponseEntity importCourse(@RequestParam Long orgId,@RequestParam MultipartFile file){
     	try {
-    		AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
-    		List<ExcelError> errors = courseService.importCourse(accessUser.getRootOrgId(),file.getInputStream());
+    		List<ExcelError> errors = courseService.importCourse(orgId,file.getInputStream());
     		return new ResponseEntity(errors,HttpStatus.OK);
 		} catch (IOException e) {
 			e.printStackTrace();

+ 24 - 7
core-api/src/main/java/cn/com/qmth/examcloud/service/core/api/OrgApi.java

@@ -1,20 +1,30 @@
 package cn.com.qmth.examcloud.service.core.api;
 
+import io.swagger.annotations.ApiOperation;
+
 import java.io.IOException;
+import java.util.Date;
 import java.util.List;
 
-import cn.com.qmth.examcloud.common.util.excel.ExcelError;
-import cn.com.qmth.examcloud.service.core.repo.OrgRepo;
-import cn.com.qmth.examcloud.service.core.entity.Org;
-import cn.com.qmth.examcloud.service.core.service.OrgService;
-import io.swagger.annotations.ApiOperation;
-
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+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.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.multipart.MultipartFile;
 
+import cn.com.qmth.examcloud.common.util.excel.ExcelError;
+import cn.com.qmth.examcloud.service.core.entity.Org;
+import cn.com.qmth.examcloud.service.core.repo.OrgRepo;
+import cn.com.qmth.examcloud.service.core.service.OrgService;
+
 /**
  * 机构服务API
  * Created by songyue on 17/1/14.
@@ -62,6 +72,7 @@ public class OrgApi {
     @ApiOperation(value="更新机构",notes="更新")
     @PutMapping
     public ResponseEntity updateSchool(@RequestBody Org org){
+    	org.setUpdateTime(new Date());
         return new ResponseEntity(orgRepo.save(org),HttpStatus.OK);
     }
 
@@ -83,4 +94,10 @@ public class OrgApi {
 			return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR);
 		}
     }
+    
+    @ApiOperation(value="禁用/启用机构",notes="禁用/启用")
+    @PutMapping("/{id}")
+    public ResponseEntity enableSchool(@PathVariable Long id,@RequestParam boolean enable){
+        return new ResponseEntity(orgService.enableSchool(id,enable),HttpStatus.OK);
+    }
 }

+ 2 - 6
core-api/src/main/java/cn/com/qmth/examcloud/service/core/api/StudentApi.java

@@ -5,8 +5,6 @@ import io.swagger.annotations.ApiOperation;
 import java.io.File;
 import java.util.List;
 
-import javax.servlet.http.HttpServletRequest;
-
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.PageRequest;
 import org.springframework.http.HttpStatus;
@@ -22,7 +20,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
-import cn.com.qmth.examcloud.common.uac.entity.AccessUser;
 import cn.com.qmth.examcloud.common.util.ErrorMsg;
 import cn.com.qmth.examcloud.service.core.entity.Student;
 import cn.com.qmth.examcloud.service.core.repo.StudentRepo;
@@ -81,10 +78,9 @@ public class StudentApi {
     
     @ApiOperation(value="学生照片绑定",notes = "照片绑定")
     @PostMapping("/photo")
-    public ResponseEntity photopBundled (HttpServletRequest request,@RequestParam File file){
+    public ResponseEntity photopBundled (@RequestParam Long orgId,@RequestParam File file){
     	try {
-    		AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
-    		List<ErrorMsg> errorMsgs = studentService.photopBundled(accessUser.getRootOrgId(),file);
+    		List<ErrorMsg> errorMsgs = studentService.photopBundled(orgId,file);
     		return new ResponseEntity(errorMsgs,HttpStatus.OK);
 		} catch (Exception e) {
 			e.printStackTrace();

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

@@ -40,7 +40,7 @@ public class UserApi {
     @ApiOperation(value="按id查询用户",notes="id查询")
     @GetMapping("/{id}")
     public ResponseEntity getUserById(@PathVariable long id){
-        return new ResponseEntity(userRepo.findById(id), HttpStatus.OK);
+        return new ResponseEntity(userRepo.findOne(id), HttpStatus.OK);
     }
 
     @ApiOperation(value="按orgId查询用户",notes="机构id查询")

+ 4 - 4
core-api/src/main/java/cn/com/qmth/examcloud/service/core/service/CourseService.java

@@ -47,12 +47,12 @@ public class CourseService {
 		return excelErrors;
 	}
 
-	private ExcelError importCheck(Course dto) {
-		if(null == dto.getLevel()){
+	private ExcelError importCheck(Course course) {
+		if(null == course.getLevel()){
 			return new ExcelError("层次不存在");
 		}
-		Course course = courseRepo.findByCode(dto.getCode());
-		if(course != null){
+		Course domain = courseRepo.findByOrgIdAndCode(course.getOrgId(),course.getCode());
+		if(domain != null){
 			return new ExcelError("代码已存在");
 		}
 		return null;

+ 28 - 5
core-api/src/main/java/cn/com/qmth/examcloud/service/core/service/OrgService.java

@@ -7,23 +7,25 @@ import java.util.List;
 
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 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.entity.Org;
+import cn.com.qmth.examcloud.service.core.entity.User;
 import cn.com.qmth.examcloud.service.core.repo.OrgRepo;
+import cn.com.qmth.examcloud.service.core.repo.UserRepo;
 
-/**
- * 学校服务类
- * Created by songyue on 17/1/14.
- */
 @Service
 public class OrgService {
 
     @Autowired
     OrgRepo orgRepo;
-
+    @Autowired
+    UserRepo userRepo;
+    
+    @Transactional
 	public List<ExcelError> importLearnCenter(Long orgId, InputStream inputStream) {
 		List<Org> list = new ArrayList<Org>();
 		Org parentOrg = orgRepo.findById(orgId);
@@ -56,4 +58,25 @@ public class OrgService {
 		return null;
 	}
 
+	/**
+	 * 启用/禁用机构;禁用机构时禁用该机构下的所有用户
+	 * @param id
+	 * @param enable
+	 * @return
+	 */
+	@Transactional
+	public Org enableSchool(Long id, boolean enable) {
+		Org org = orgRepo.findOne(id);
+		org.setEnable(enable);
+		orgRepo.save(org);
+		if(enable == false){
+			List<User> users = userRepo.findByOrgId(id);
+			for (User user : users) {
+				user.setEnable(false);
+				userRepo.save(user);
+			}
+		}
+		return org;
+	}
+
 }

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

@@ -49,7 +49,7 @@ public class UserService {
      * @param userId
      */
     public void initPassword(long userId){
-        User user = userRepo.findById(userId);
+        User user = userRepo.findOne(userId);
         //根据用户类型采用不同的初始化策略
         if(user.getType() == UserType.NOT_STUDENT){
             //初始化为默认密码
@@ -142,6 +142,7 @@ public class UserService {
         Org rootOrg = orgRepo.findById(user.getRootOrgId());
         userInfo.setUserId(user.getId());
         userInfo.setOrgId(user.getOrgId());
+        userInfo.setRootOrgId(user.getRootOrgId());
         userInfo.setName(user.getName());
         userInfo.setAvatar(user.getAvatar());
         userInfo.setLoginName(user.getLoginName());

+ 10 - 0
core-domain/src/main/java/cn/com/qmth/examcloud/service/core/dto/UserInfo.java

@@ -11,6 +11,8 @@ public class UserInfo implements Serializable{
     private Long userId;
     
     private Long orgId;
+    
+    private Long rootOrgId;
 
     private String name;
 
@@ -112,6 +114,14 @@ public class UserInfo implements Serializable{
 		this.orgId = orgId;
 	}
 
+	public Long getRootOrgId() {
+		return rootOrgId;
+	}
+
+	public void setRootOrgId(Long rootOrgId) {
+		this.rootOrgId = rootOrgId;
+	}
+
 	public UserInfo() {
     }
 }

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

@@ -61,10 +61,12 @@ public class Org implements Serializable{
     /**
      * 联系电话
      */
+    @ExcelProperty(index = 3)
     private String telphone;
     /**
      * 联系人
      */
+    @ExcelProperty(index = 2)
     private String contacts;
 
     @Temporal(value = TemporalType.DATE)

+ 7 - 3
core-domain/src/main/java/cn/com/qmth/examcloud/service/core/repo/CourseRepo.java

@@ -1,14 +1,18 @@
 package cn.com.qmth.examcloud.service.core.repo;
 
+import java.util.List;
+
 import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.repository.query.QueryByExampleExecutor;
 
 import cn.com.qmth.examcloud.service.core.entity.Course;
-import org.springframework.data.repository.query.QueryByExampleExecutor;
 
 public interface CourseRepo extends JpaRepository<Course, Long>,QueryByExampleExecutor<Course> {
 
-    Course findById(long id);
+    Course findByOrgIdAndCode(Long orgId,String code);
+
+	List<Course> findByOrgId(Long orgId);
 
-    Course findByCode(String code);
+	List<Course> findByOrgIdAndEnable(Long orgId, Boolean enable);
 
 }

+ 5 - 4
core-domain/src/main/java/cn/com/qmth/examcloud/service/core/repo/UserRepo.java

@@ -1,6 +1,7 @@
 package cn.com.qmth.examcloud.service.core.repo;
 
-import cn.com.qmth.examcloud.service.core.entity.User;
+import java.util.List;
+
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.Modifying;
 import org.springframework.data.jpa.repository.Query;
@@ -8,15 +9,13 @@ import org.springframework.data.repository.query.Param;
 import org.springframework.data.repository.query.QueryByExampleExecutor;
 import org.springframework.transaction.annotation.Transactional;
 
-import java.util.List;
+import cn.com.qmth.examcloud.service.core.entity.User;
 
 /**
  * Created by songyue on 17/1/13.
  */
 public interface UserRepo extends JpaRepository<User,Long>,QueryByExampleExecutor<User>{
 
-    User findById(long id);
-
     User findByRootOrgIdAndLoginName(long rootOrgId,String loginName);
 
     User findByLoginName(String loginName);
@@ -32,4 +31,6 @@ public interface UserRepo extends JpaRepository<User,Long>,QueryByExampleExecuto
 
     List<User> findByRootOrgIdAndType(long rootOrgId,String userType);
 
+	List<User> findByOrgId(Long orgId);
+
 }