Browse Source

。。。

wangwei 7 years ago
parent
commit
2bb5211fb6

+ 64 - 74
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/controller/ExamSiteController.java

@@ -1,7 +1,6 @@
 package cn.com.qmth.examcloud.core.basic.api.controller;
 
 import java.util.ArrayList;
-import java.util.Date;
 import java.util.List;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
@@ -14,6 +13,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.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.DeleteMapping;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.ModelAttribute;
@@ -24,8 +24,6 @@ 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.commons.base.util.ErrorMsg;
-import cn.com.qmth.examcloud.commons.web.security.entity.AccessUser;
 import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
 import cn.com.qmth.examcloud.core.basic.dao.ExamSiteRepo;
 import cn.com.qmth.examcloud.core.basic.dao.entity.ExamSite;
@@ -33,78 +31,70 @@ import cn.com.qmth.examcloud.core.basic.service.impl.ExamSiteService;
 import io.swagger.annotations.ApiOperation;
 
 /**
- * 考点服务API
- * Created by songyue on 17/1/14.
+ * 考点服务API Created by songyue on 17/1/14.
  */
+@Transactional
 @RestController
 @RequestMapping("${$rmp.ctr.basic}/examsite")
-public class ExamSiteController extends ControllerSupport{
-
-    private static final Logger LOG = LoggerFactory.getLogger(ExamSiteController.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) {
-        cn.com.qmth.examcloud.commons.web.security.bean.User accessUser = getAccessUser();
-        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);
-    }
+public class ExamSiteController extends ControllerSupport {
+
+	private static final Logger LOG = LoggerFactory.getLogger(ExamSiteController.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) {
+		cn.com.qmth.examcloud.commons.web.security.bean.User accessUser = getAccessUser();
+		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 ExamSite addExamSite(@RequestBody ExamSite examSite) {
+		trim(examSite);
+		return examSiteService.save(examSite);
+	}
+
+	@ApiOperation(value = "更新考点", notes = "更新")
+	@PutMapping
+	public ExamSite updateExamSite(@RequestBody ExamSite examSite) {
+		trim(examSite);
+		ExamSite updated = examSiteService.update(examSite.getId(), examSite);
+		return updated;
+	}
+
+	@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);
+	}
 }

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

@@ -257,6 +257,11 @@ public class OrgController extends ControllerSupport {
 	public Org addSubOrg(@RequestBody Org org) {
 		trim(org);
 		User accessUser = getAccessUser();
+
+		Org subOrg = orgRepo.findByRootIdAndCode(accessUser.getRootOrgId(), org.getCode());
+		if (null != subOrg) {
+			throw new StatusException("B-140001", "机构代码已存在");
+		}
 		org.setParentId(accessUser.getRootOrgId());
 		org.setRootId(accessUser.getRootOrgId());
 		Org saved = orgService.save(org);

+ 75 - 101
examcloud-core-basic-dao/src/main/java/cn/com/qmth/examcloud/core/basic/dao/entity/ExamSite.java

@@ -1,136 +1,110 @@
 package cn.com.qmth.examcloud.core.basic.dao.entity;
 
-import org.springframework.format.annotation.DateTimeFormat;
-
-import javax.persistence.*;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Table;
 import javax.validation.constraints.NotNull;
-import java.io.Serializable;
-import java.util.Date;
+
+import cn.com.qmth.examcloud.commons.web.jpa.JpaEntity;
 
 /**
  * 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;
+public class ExamSite extends JpaEntity {
+	private static final long serialVersionUID = 8042526239290337481L;
 
-    @Temporal(value = TemporalType.DATE)
-    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
-    private Date createTime;
+	@Id
+	@GeneratedValue
+	private Long id;
 
-    @Temporal(value = TemporalType.DATE)
-    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
-    private Date updateTime;
+	@NotNull
+	private Long orgId;
 
+	@NotNull
+	private String code;
 
-    private String remark;
+	@NotNull
+	private String name;
 
-    public Long getId() {
-        return id;
-    }
+	private Boolean enable;
 
-    public void setId(Long id) {
-        this.id = id;
-    }
+	/**
+	 * 联系电话
+	 */
+	private String telphone;
 
-    public Long getOrgId() {
-        return orgId;
-    }
+	/**
+	 * 联系人
+	 */
+	private String contacts;
 
-    public void setOrgId(Long orgId) {
-        this.orgId = orgId;
-    }
+	private String remark;
 
-    public String getCode() {
-        return code;
-    }
+	public Long getId() {
+		return id;
+	}
 
-    public void setCode(String code) {
-        this.code = code;
-    }
+	public void setId(Long id) {
+		this.id = id;
+	}
 
-    public String getName() {
-        return name;
-    }
+	public Long getOrgId() {
+		return orgId;
+	}
 
-    public void setName(String name) {
-        this.name = name;
-    }
+	public void setOrgId(Long orgId) {
+		this.orgId = orgId;
+	}
 
-    public Boolean getEnable() {
-        return enable;
-    }
+	public String getCode() {
+		return code;
+	}
 
-    public void setEnable(Boolean enable) {
-        this.enable = enable;
-    }
+	public void setCode(String code) {
+		this.code = code;
+	}
 
-    public String getTelphone() {
-        return telphone;
-    }
+	public String getName() {
+		return name;
+	}
 
-    public void setTelphone(String telphone) {
-        this.telphone = telphone;
-    }
+	public void setName(String name) {
+		this.name = name;
+	}
 
-    public String getContacts() {
-        return contacts;
-    }
+	public Boolean getEnable() {
+		return enable;
+	}
 
-    public void setContacts(String contacts) {
-        this.contacts = contacts;
-    }
+	public void setEnable(Boolean enable) {
+		this.enable = enable;
+	}
 
-    public Date getCreateTime() {
-        return createTime;
-    }
+	public String getTelphone() {
+		return telphone;
+	}
 
-    public void setCreateTime(Date createTime) {
-        this.createTime = createTime;
-    }
+	public void setTelphone(String telphone) {
+		this.telphone = telphone;
+	}
 
-    public Date getUpdateTime() {
-        return updateTime;
-    }
+	public String getContacts() {
+		return contacts;
+	}
 
-    public void setUpdateTime(Date updateTime) {
-        this.updateTime = updateTime;
-    }
+	public void setContacts(String contacts) {
+		this.contacts = contacts;
+	}
 
-    public String getRemark() {
-        return remark;
-    }
+	public String getRemark() {
+		return remark;
+	}
 
-    public void setRemark(String remark) {
-        this.remark = remark;
-    }
+	public void setRemark(String remark) {
+		this.remark = remark;
+	}
 
-    public ExamSite() {
-    }
 }

+ 14 - 22
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/impl/ExamSiteService.java

@@ -18,47 +18,39 @@ import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatc
 @Service
 public class ExamSiteService {
 
-    @Autowired
+	@Autowired
 	ExamSiteRepo examSiteRepo;
 
-
 	public Page<ExamSite> findAll(ExamSite examSiteCriteria, Pageable pageable) {
-		ExampleMatcher exampleMatcher = ExampleMatcher.matching()
-				.withMatcher("name", contains())
-				.withMatcher("code", contains())
-                .withMatcher("orgId",exact());
-		Example<ExamSite> examSiteExample = Example.of(examSiteCriteria,
-				exampleMatcher);
+		ExampleMatcher exampleMatcher = ExampleMatcher.matching().withMatcher("name", contains())
+				.withMatcher("code", contains()).withMatcher("orgId", exact());
+		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())
-                .withMatcher("orgId",exact());
-		Example<ExamSite> examSiteExample = Example.of(examSiteCriteria,
-				exampleMatcher);
+		ExampleMatcher exampleMatcher = ExampleMatcher.matching().withMatcher("name", contains())
+				.withMatcher("code", contains()).withMatcher("orgId", exact());
+		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());
+	public ExamSite save(ExamSite examSite) {
+		checkCode(examSite.getOrgId(), examSite.getCode());
 		return examSiteRepo.save(examSite);
 	}
 
-	private void checkCode(Long orgId,String code) {
-		ExamSite old = examSiteRepo.findFirstByOrgIdAndCode(orgId,code);
-		if(old!=null){
+	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());
+		if (!old.getCode().equals(examSite.getCode())) {
+			checkCode(examSite.getOrgId(), examSite.getCode());
 		}
 		examSite.setUpdateTime(new Date());
 		return examSiteRepo.save(examSite);

+ 0 - 4
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/impl/OrgService.java

@@ -4,7 +4,6 @@ import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatc
 
 import java.io.InputStream;
 import java.util.ArrayList;
-import java.util.Date;
 import java.util.List;
 
 import javax.persistence.criteria.Predicate;
@@ -161,9 +160,6 @@ public class OrgService {
 		examSite.setCode(orgDto.getExamSiteCode());
 		examSite.setName(orgDto.getExamSiteName());
 		examSite.setOrgId(orgDto.getId());
-		// examSite.setContacts(orgDto.getContacts());
-		// examSite.setTelphone(orgDto.getTelphone());
-		examSite.setCreateTime(new Date());
 		examSite.setEnable(true);
 		return examSite;
 	}