|
@@ -0,0 +1,184 @@
|
|
|
+package cn.com.qmth.examcloud.service.core.api;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.function.Consumer;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+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 cn.com.qmth.examcloud.common.uac.entity.AccessUser;
|
|
|
+import cn.com.qmth.examcloud.common.util.ErrorMsg;
|
|
|
+import cn.com.qmth.examcloud.service.core.dto.SpecialtyDTO;
|
|
|
+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;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Description: 专业服务API
|
|
|
+ * @author weiwenhai
|
|
|
+ * @Date 2017年8月7号
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping("${app.api.root}/specialty")
|
|
|
+public class SpecialtyApi {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ SpecialtyService specialtyService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ SpecialtyRepo specialtyRepo;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 带分页查询
|
|
|
+ * @param specialty
|
|
|
+ * @param curPage
|
|
|
+ * @param pageSize
|
|
|
+ * @param request
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(value="查询专业带分页", notes="查询专业带分页")
|
|
|
+ @GetMapping("/all/{curPage}/{pageSize}")
|
|
|
+ public ResponseEntity getAllOrg(@ModelAttribute Specialty specialty,
|
|
|
+ @PathVariable Integer curPage,
|
|
|
+ @PathVariable Integer pageSize,
|
|
|
+ HttpServletRequest request){
|
|
|
+ AccessUser accessUser = (AccessUser)request.getAttribute("accessUser");
|
|
|
+ if(accessUser != null){
|
|
|
+ specialty.setOrgId(accessUser.getRootOrgId());
|
|
|
+ }else {
|
|
|
+ return new ResponseEntity(HttpStatus.NOT_FOUND);
|
|
|
+ }
|
|
|
+ return new ResponseEntity(specialtyService.findAll(specialty, new PageRequest(curPage-1, pageSize)),HttpStatus.OK);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询专业不带分页
|
|
|
+ * @param specialty
|
|
|
+ * @param request
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(value="查询专业不带分页",notes="查询专业不带分页")
|
|
|
+ @GetMapping("/all")
|
|
|
+ public ResponseEntity getAll(@ModelAttribute Specialty specialty,HttpServletRequest request){
|
|
|
+ AccessUser accessUser = (AccessUser)request.getAttribute("accessUser");
|
|
|
+ if(accessUser != null){
|
|
|
+ specialty.setOrgId(accessUser.getRootOrgId());
|
|
|
+ }
|
|
|
+ specialty.setEnable(true);
|
|
|
+ return new ResponseEntity(specialtyService.findAll(specialty),HttpStatus.OK);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增专业
|
|
|
+ * @param specialty
|
|
|
+ * @param request
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(value="新增专业", notes="新增专业")
|
|
|
+ @PostMapping("/addSpecialty")
|
|
|
+ public ResponseEntity addSpecialty(@RequestBody Specialty specialty,HttpServletRequest request){
|
|
|
+ specialty.setCreateTime(new Date());
|
|
|
+ AccessUser accessUser = (AccessUser)request.getAttribute("accessUser");
|
|
|
+ if(accessUser != null){
|
|
|
+ specialty.setOrgId(accessUser.getRootOrgId());
|
|
|
+ }else {
|
|
|
+ return new ResponseEntity(HttpStatus.NOT_FOUND);
|
|
|
+ }
|
|
|
+ try{
|
|
|
+ specialtyService.save(specialty);
|
|
|
+ return new ResponseEntity(HttpStatus.CREATED);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return new ResponseEntity(new ErrorMsg(e.getMessage()), HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新专业
|
|
|
+ * @param specialty
|
|
|
+ * @param request
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(value="更新专业",notes="更新专业")
|
|
|
+ @PutMapping("/updateSpecialty")
|
|
|
+ public ResponseEntity updateSpecialty(@RequestBody Specialty specialty,HttpServletRequest request){
|
|
|
+ AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
|
|
|
+ if(accessUser != null){
|
|
|
+ specialty.setOrgId(accessUser.getRootOrgId());
|
|
|
+ }else {
|
|
|
+ return new ResponseEntity(HttpStatus.NOT_FOUND);
|
|
|
+ }
|
|
|
+ try{
|
|
|
+ specialtyService.updateSpecialty(specialty);
|
|
|
+ return new ResponseEntity(HttpStatus.OK);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return new ResponseEntity(new ErrorMsg(e.getMessage()), HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据ID删除专业
|
|
|
+ * @param ids
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @ApiOperation(value="根据ID删除专业",notes="根据ID删除专业")
|
|
|
+ @DeleteMapping("/{ids}")
|
|
|
+ public ResponseEntity deleteSpecialtyIds(@PathVariable String ids){
|
|
|
+ specialtyService.deleteSpecialty(ids);
|
|
|
+ return new ResponseEntity(HttpStatus.OK);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="根据ID删除专业",notes="根据ID删除专业")
|
|
|
+ @DeleteMapping("/delete/{id}")
|
|
|
+ public ResponseEntity deleteSpecialtyId(@PathVariable String id){
|
|
|
+ specialtyRepo.delete(Long.parseLong(id));
|
|
|
+ return new ResponseEntity(HttpStatus.OK);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导出专业
|
|
|
+ * @param specialty
|
|
|
+ * @param response
|
|
|
+ */
|
|
|
+ @ApiOperation(value="导出专业", notes="导出专业")
|
|
|
+ @GetMapping("/export")
|
|
|
+ public void exportSpecialty(@ModelAttribute Specialty specialty,HttpServletResponse response){
|
|
|
+ List<SpecialtyDTO> list = new ArrayList<SpecialtyDTO>();
|
|
|
+ specialtyService.findAll(specialty).forEach(c -> {
|
|
|
+ list.add(new SpecialtyDTO(c));
|
|
|
+ });
|
|
|
+ ExportUtils.exportEXCEL("专业列表", SpecialtyDTO.class, list, response);
|
|
|
+ }
|
|
|
+}
|