wangwei 7 роки тому
батько
коміт
5c59559a54

+ 51 - 0
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/controller/StudentController.java

@@ -2,6 +2,8 @@ package cn.com.qmth.examcloud.core.basic.api.controller;
 
 import java.io.File;
 import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 import javax.servlet.http.HttpServletRequest;
 
@@ -10,15 +12,19 @@ import org.springframework.data.domain.Page;
 import org.springframework.data.domain.PageRequest;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
+import org.springframework.transaction.annotation.Transactional;
 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.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
+import com.google.common.collect.Lists;
+
 import cn.com.qmth.examcloud.commons.base.util.ErrorMsg;
 import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
 import cn.com.qmth.examcloud.core.basic.dao.StudentRepo;
@@ -30,6 +36,7 @@ import io.swagger.annotations.ApiOperation;
 /**
  * 学生服务API Created by songyue on 17/1/14.
  */
+@Transactional
 @RestController
 @RequestMapping("${$rmp.ctr.basic}/student")
 public class StudentController extends ControllerSupport {
@@ -114,4 +121,48 @@ public class StudentController extends ControllerSupport {
 		}
 	}
 
+	/**
+	 * 方法注释
+	 *
+	 * @author WANGWEI
+	 * @param ids
+	 * @return
+	 */
+	@ApiOperation(value = "启用学生")
+	@PutMapping("/enable/{ids}")
+	public List<String> enableStudent(@PathVariable String ids) {
+		List<Long> studentIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
+				.collect(Collectors.toList());
+		List<String> ret = Lists.newArrayList();
+		for (Long userId : studentIds) {
+			Student user = studentRepo.findOne(userId);
+			user.setEnable(true);
+			studentRepo.save(user);
+			ret.add(user.getId() + ":" + user.getName());
+		}
+		return ret;
+	}
+
+	/**
+	 * 方法注释
+	 *
+	 * @author WANGWEI
+	 * @param ids
+	 * @return
+	 */
+	@ApiOperation(value = "禁用学生")
+	@PutMapping("/disable/{ids}")
+	public List<String> disableStudent(@PathVariable String ids) {
+		List<Long> studentIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
+				.collect(Collectors.toList());
+		List<String> ret = Lists.newArrayList();
+		for (Long userId : studentIds) {
+			Student user = studentRepo.findOne(userId);
+			user.setEnable(false);
+			studentRepo.save(user);
+			ret.add(user.getId() + ":" + user.getName());
+		}
+		return ret;
+	}
+
 }