wangwei před 6 roky
rodič
revize
f3aa6878ca

+ 68 - 1
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/controller/SpecialtyController.java

@@ -25,6 +25,8 @@ 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.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
@@ -34,11 +36,12 @@ import cn.com.qmth.examcloud.commons.base.exception.StatusException;
 import cn.com.qmth.examcloud.commons.base.util.excel.ExcelError;
 import cn.com.qmth.examcloud.commons.web.security.bean.User;
 import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
+import cn.com.qmth.examcloud.core.basic.api.controller.bean.SpecialtyDomain;
 import cn.com.qmth.examcloud.core.basic.dao.SpecialtyRepo;
 import cn.com.qmth.examcloud.core.basic.dao.entity.CourseSpeciatlyRelationEntity;
 import cn.com.qmth.examcloud.core.basic.dao.entity.SpecialtyEntity;
 import cn.com.qmth.examcloud.core.basic.service.SpecialtyService;
-import cn.com.qmth.examcloud.core.basic.service.impl.SpecialtyServiceImpl;
+import cn.com.qmth.examcloud.core.basic.service.bean.SpecialtyInfo;
 import io.swagger.annotations.ApiOperation;
 
 /**
@@ -149,6 +152,70 @@ public class SpecialtyController extends ControllerSupport {
 		return specialty;
 	}
 
+	/**
+	 * 修正
+	 *
+	 * @author WANGWEI
+	 * @param domain
+	 * @return
+	 */
+	@ApiOperation(value = "新增专业", notes = "新增")
+	@PostMapping
+	public Long addSpecialty(@RequestBody SpecialtyDomain domain) {
+		trim(domain, true);
+
+		User accessUser = getAccessUser();
+		Long rootOrgId = accessUser.getRootOrgId();
+
+		String code = domain.getCode();
+		if (StringUtils.isBlank(code)) {
+			throw new StatusException("B-620001", "code is blank");
+		}
+		SpecialtyEntity course = specialtyRepo.findByRootOrgIdAndCode(rootOrgId, code);
+		if (null != course) {
+			throw new StatusException("B-620002", "专业编码已被占用");
+		}
+
+		SpecialtyInfo info = new SpecialtyInfo();
+		info.setRootOrgId(rootOrgId);
+		info.setCode(domain.getCode());
+		info.setEnable(domain.getEnable());
+		info.setId(domain.getId());
+		info.setName(domain.getName());
+		info.setEnable(domain.getEnable());
+
+		SpecialtyEntity saved = specialtyService.saveSpecialty(info);
+		return saved.getId();
+	}
+
+	/**
+	 * 修正
+	 *
+	 * @author WANGWEI
+	 * @param domain
+	 * @return
+	 */
+	@ApiOperation(value = "修改专业", notes = "新增")
+	@PutMapping
+	public Long updateSpecialty(@RequestBody SpecialtyDomain domain) {
+		trim(domain, true);
+
+		User accessUser = getAccessUser();
+		Long rootOrgId = accessUser.getRootOrgId();
+
+		SpecialtyInfo info = new SpecialtyInfo();
+		info.setId(info.getId());
+		info.setRootOrgId(rootOrgId);
+		info.setCode(domain.getCode());
+		info.setEnable(domain.getEnable());
+		info.setId(domain.getId());
+		info.setName(domain.getName());
+		info.setEnable(domain.getEnable());
+
+		SpecialtyEntity saved = specialtyService.saveSpecialty(info);
+		return saved.getId();
+	}
+
 	/**
 	 * 方法注释
 	 *