宋悦 hace 8 años
padre
commit
afc45c531d

+ 108 - 0
core-api/src/main/java/cn/com/qmth/examcloud/service/core/api/ExamSiteApi.java

@@ -0,0 +1,108 @@
+package cn.com.qmth.examcloud.service.core.api;
+
+import cn.com.qmth.examcloud.common.uac.entity.AccessUser;
+import cn.com.qmth.examcloud.common.util.ErrorMsg;
+import cn.com.qmth.examcloud.common.util.excel.ExcelError;
+import cn.com.qmth.examcloud.service.core.entity.ExamSite;
+import cn.com.qmth.examcloud.service.core.repo.ExamSiteRepo;
+import cn.com.qmth.examcloud.service.core.repo.ExamSiteRepo;
+import cn.com.qmth.examcloud.service.core.service.ExamSiteService;
+import cn.com.qmth.examcloud.service.core.service.ExamSiteService;
+import cn.com.qmth.examcloud.service.core.util.ExportUtils;
+import io.swagger.annotations.ApiOperation;
+import org.apache.commons.io.IOUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+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.*;
+import org.springframework.web.multipart.commons.CommonsMultipartFile;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+/**
+ * 考点服务API
+ * Created by songyue on 17/1/14.
+ */
+@RestController
+@RequestMapping("${app.api.root}/examsite")
+public class ExamSiteApi {
+
+    private static final Logger LOG = LoggerFactory.getLogger(ExamSiteApi.class);
+
+    @Autowired
+    ExamSiteRepo examSiteRepo;
+
+    @Autowired
+    ExamSiteService examSiteService;
+
+    @ApiOperation(value = "查询考点分页带查询", notes = "分页带查询")
+    @GetMapping("/all/{curPage}/{pageSize}")
+    public ResponseEntity getAllExamSite(@ModelAttribute ExamSite examSiteCriteria,
+                                         HttpServletRequest request,
+                                         @PathVariable Integer curPage,
+                                         @PathVariable Integer pageSize) {
+        return new ResponseEntity(examSiteService.findAll(examSiteCriteria, new PageRequest(curPage - 1, pageSize)), HttpStatus.OK);
+    }
+
+
+    @ApiOperation(value = "查询考点不分页带查询", notes = "不分页带查询")
+    @GetMapping("/all")
+    public ResponseEntity getAllExam(@ModelAttribute ExamSite examSiteCriteria,
+                                     HttpServletRequest request) {
+        AccessUser accessUser = (AccessUser) request.getAttribute("accessUser");
+        if (accessUser != null) {
+            return new ResponseEntity(examSiteRepo.findByOrgId(accessUser.getOrgId()), HttpStatus.OK);
+        }
+        return new ResponseEntity(new ArrayList<ExamSite>(), HttpStatus.OK);
+    }
+
+    @ApiOperation(value = "按ID查询考点", notes = "ID查询")
+    @GetMapping("/{id}")
+    public ResponseEntity<ExamSite> getExamSiteById(@PathVariable Long id) {
+        return new ResponseEntity(examSiteRepo.findOne(id), HttpStatus.OK);
+    }
+
+    @ApiOperation(value = "新增考点", notes = "新增")
+    @PostMapping
+    public ResponseEntity addExamSite(@RequestBody ExamSite examSite, HttpServletRequest request) {
+
+        try {
+            examSite.setCreateTime(new Date());
+            return new ResponseEntity(examSiteService.save(examSite), HttpStatus.CREATED);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return new ResponseEntity(new ErrorMsg(e.getMessage()), HttpStatus.INTERNAL_SERVER_ERROR);
+        }
+    }
+
+    @ApiOperation(value = "更新考点", notes = "更新")
+    @PutMapping
+    public ResponseEntity updateExamSite(@RequestBody ExamSite examSite,
+                                         HttpServletRequest request) {
+        try {
+            return new ResponseEntity(examSiteService.update(examSite.getId(), examSite), HttpStatus.OK);
+        } catch (Exception e) {
+            return new ResponseEntity(new ErrorMsg(e.getMessage()), HttpStatus.INTERNAL_SERVER_ERROR);
+        }
+    }
+
+    @ApiOperation(value = "按ID删除考点", notes = "删除")
+    @DeleteMapping("/{id}")
+    public ResponseEntity deleteExamSite(@PathVariable String id) {
+        List<Long> examStuIds = Stream.of(id.split(",")).map(s->Long.parseLong(s.trim()))
+                .collect(Collectors.toList());
+        examSiteRepo.deleteInBatch(examSiteRepo.findAll(examStuIds));
+        return new ResponseEntity(HttpStatus.OK);
+    }
+}

+ 63 - 0
core-api/src/main/java/cn/com/qmth/examcloud/service/core/service/ExamSiteService.java

@@ -0,0 +1,63 @@
+package cn.com.qmth.examcloud.service.core.service;
+
+import cn.com.qmth.examcloud.service.core.entity.ExamSite;
+import cn.com.qmth.examcloud.service.core.repo.ExamSiteRepo;
+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.stereotype.Service;
+import java.util.Date;
+import java.util.List;
+
+import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.contains;
+
+@Service
+public class ExamSiteService {
+
+    @Autowired
+	ExamSiteRepo examSiteRepo;
+
+
+	public Page<ExamSite> findAll(ExamSite examSiteCriteria, Pageable pageable) {
+		ExampleMatcher exampleMatcher = ExampleMatcher.matching()
+				.withMatcher("name", contains())
+				.withMatcher("code", contains());
+		Example<ExamSite> examSiteExample = Example.of(examSiteCriteria,
+				exampleMatcher);
+		return examSiteRepo.findAll(examSiteExample, pageable);
+	}
+
+	public List<ExamSite> findAll(ExamSite examSiteCriteria) {
+		ExampleMatcher exampleMatcher = ExampleMatcher.matching()
+				.withMatcher("name", contains())
+				.withMatcher("code", contains());
+		Example<ExamSite> examSiteExample = Example.of(examSiteCriteria,
+				exampleMatcher);
+		return examSiteRepo.findAll(examSiteExample);
+	}
+
+	public ExamSite save(ExamSite examSite) throws Exception{
+		checkCode(examSite.getOrgId(),examSite.getCode());
+		examSite.setCreateTime(new Date());
+		return examSiteRepo.save(examSite);
+	}
+
+	private void checkCode(Long orgId,String code) {
+		ExamSite old = examSiteRepo.findFirstByOrgIdAndCode(orgId,code);
+		if(old!=null){
+			throw new RuntimeException("代码已存在");
+		}
+	}
+
+	public ExamSite update(Long id, ExamSite examSite) {
+		ExamSite old = examSiteRepo.findOne(id);
+		if(!old.getCode().equals(examSite.getCode())){
+			checkCode(examSite.getOrgId(),examSite.getCode());
+		}
+		examSite.setUpdateTime(new Date());
+		return examSiteRepo.save(examSite);
+	}
+
+}

+ 6 - 0
core-api/src/main/java/cn/com/qmth/examcloud/service/core/service/OrgService.java

@@ -63,6 +63,12 @@ public class OrgService {
 		if(StringUtils.isEmpty(dto.getName())){
 			return new ExcelError("名称不能为空");
 		}
+		if(StringUtils.isEmpty(dto.getContacts())){
+			return new ExcelError("联系人不能为空");
+		}
+		if(StringUtils.isEmpty(dto.getTelphone())){
+			return new ExcelError("联系电话不能为空");
+		}
 		Org org = orgRepo.findFirstByParentIdAndCode(dto.getParentId(),dto.getCode());
 		if(org!=null){
 			return new ExcelError("代码已存在");

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

@@ -0,0 +1,125 @@
+package cn.com.qmth.examcloud.service.core.entity;
+
+import org.springframework.format.annotation.DateTimeFormat;
+
+import javax.persistence.*;
+import javax.validation.constraints.NotNull;
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * Created by songyue on 17/7/27.
+ */
+@Entity
+@Table(name = "ecs_core_exam_site")
+public class ExamSite implements Serializable {
+    private static final long serialVersionUID = 8042526239290337481L;
+
+    @Id
+    @GeneratedValue
+    private Long id;
+
+    @NotNull
+    private Long orgId;
+
+    @NotNull
+    private String code;
+
+    @NotNull
+    private String name;
+
+
+    private Boolean enable;
+
+    /**
+     * 联系电话
+     */
+    private String telphone;
+    /**
+     * 联系人
+     */
+    private String contacts;
+
+    @Temporal(value = TemporalType.DATE)
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date createTime;
+
+    @Temporal(value = TemporalType.DATE)
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date updateTime;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public Long getOrgId() {
+        return orgId;
+    }
+
+    public void setOrgId(Long orgId) {
+        this.orgId = orgId;
+    }
+
+    public String getCode() {
+        return code;
+    }
+
+    public void setCode(String code) {
+        this.code = code;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public Boolean getEnable() {
+        return enable;
+    }
+
+    public void setEnable(Boolean enable) {
+        this.enable = enable;
+    }
+
+    public String getTelphone() {
+        return telphone;
+    }
+
+    public void setTelphone(String telphone) {
+        this.telphone = telphone;
+    }
+
+    public String getContacts() {
+        return contacts;
+    }
+
+    public void setContacts(String contacts) {
+        this.contacts = contacts;
+    }
+
+    public Date getCreateTime() {
+        return createTime;
+    }
+
+    public void setCreateTime(Date createTime) {
+        this.createTime = createTime;
+    }
+
+    public Date getUpdateTime() {
+        return updateTime;
+    }
+
+    public void setUpdateTime(Date updateTime) {
+        this.updateTime = updateTime;
+    }
+
+    public ExamSite() {
+    }
+}

+ 1 - 1
core-domain/src/main/java/cn/com/qmth/examcloud/service/core/entity/Student.java

@@ -21,7 +21,7 @@ public class Student implements Serializable {
 	@GeneratedValue
 	private Long id;
 
-	@OneToOne
+	@OneToOne(cascade = { CascadeType.ALL })
 	@JoinColumn(name = "userId")
 	private User user;
 

+ 23 - 0
core-domain/src/main/java/cn/com/qmth/examcloud/service/core/repo/ExamSiteRepo.java

@@ -0,0 +1,23 @@
+package cn.com.qmth.examcloud.service.core.repo;
+
+import cn.com.qmth.examcloud.service.core.entity.ExamSite;
+import cn.com.qmth.examcloud.service.core.entity.Org;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
+import org.springframework.data.repository.query.QueryByExampleExecutor;
+
+import java.util.List;
+
+/**
+ * Created by songyue on 17/1/13.
+ */
+public interface ExamSiteRepo extends JpaRepository<ExamSite,Long>,QueryByExampleExecutor<ExamSite>{
+
+    List<ExamSite> findByOrgId(Long orgId);
+
+    @Query(nativeQuery = true,value = "select *from ecs_core_exam_site where org_id=:orgId and code=:code")
+    ExamSite findFirstByOrgIdAndCode(@Param("orgId") Long orgId, @Param("code")String code);
+
+
+}

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

@@ -15,10 +15,12 @@ public interface OrgRepo extends JpaRepository<Org,Long>,QueryByExampleExecutor<
 
     List<Org> findByRootId(long rootId);
 
-    List<Org> findByParentId(long parentId);
+    @Query(nativeQuery = true,value = "select *from ecs_core_org where parent_id=:parentId and enable = 1")
+    List<Org> findByParentId(@Param("parentId") long parentId);
 
-    @Query(nativeQuery = true,value = "select *from ecs_core_org where id=:parentId or parent_id=:parentId")
+    @Query(nativeQuery = true,value = "select *from ecs_core_org where (id=:parentId or parent_id=:parentId) and enable = 1")
     List<Org> findAllByParentId(@Param("parentId") long parentId);
 
-	Org findFirstByParentIdAndCode(Long parentId, String code);
+    @Query(nativeQuery = true,value = "select *from ecs_core_org where parent_id=:parentId and code=:code and enable = 1")
+	Org findFirstByParentIdAndCode(@Param("parentId") Long parentId, @Param("code")String code);
 }