ソースを参照

修改课程属性中一级属性的属性要能够上下调整的bug

weiwenhai 7 年 前
コミット
70637e8ad6

+ 12 - 0
cqb-question-resource/src/main/java/com/qmth/cqb/question/service/PropertyService.java

@@ -69,4 +69,16 @@ public interface PropertyService {
 	 * @return
 	 */
 	public List<Property> findPropertyParents(Long coursePropertyId, AccessUser user);
+	
+	/**
+	 * 上移
+	 * @param property
+	 */
+	public void moveUp(Property property) throws Exception;
+	
+	/**
+	 * 下移
+	 * @param property
+	 */
+	public void moveDown(Property property) throws Exception;
 }

+ 47 - 0
cqb-question-resource/src/main/java/com/qmth/cqb/question/service/impl/PropertyServiceImpl.java

@@ -7,6 +7,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import cn.com.qmth.examcloud.common.uac.entity.AccessUser;
+import cn.com.qmth.examcloud.common.util.excel.ExcelError;
 
 import com.qmth.cqb.question.assemble.PropertyAssembler;
 import com.qmth.cqb.question.dao.PropertyRepo;
@@ -147,4 +148,50 @@ public class PropertyServiceImpl implements PropertyService{
 		return properties;
 	}
 
+	@Override
+	public void moveUp(Property property) throws Exception{
+		//查询所有一级属性
+		List<Property> properties = propertyRepo.findByOrgIdAndCoursePropertyIdAndParentIdOrderByNumber(property.getOrgId(), property.getCoursePropertyId(), 0L);
+		if(properties.size()<2){
+			throw new Exception("无法上移");
+		}else{
+			for(int i=0;i<properties.size();i++){
+				if(property.getId().equals(properties.get(i).getId())){
+					if(i==0){
+						throw new Exception("无法上移");
+					}else{
+						Integer number = property.getNumber();
+						property.setNumber(properties.get(i-1).getNumber());
+						properties.get(i-1).setNumber(number);
+						propertyRepo.save(property);
+						propertyRepo.save(properties.get(i-1));
+					}
+				}
+			}
+		}
+	}
+
+	@Override
+	public void moveDown(Property property) throws Exception{
+		//查询所有一级属性
+		List<Property> properties = propertyRepo.findByOrgIdAndCoursePropertyIdAndParentIdOrderByNumber(property.getOrgId(), property.getCoursePropertyId(), 0l);
+		if(properties.size()<2){
+			throw new Exception("无法下移");
+		}else{
+			for(int i=0;i<properties.size();i++){
+				if(property.getId().equals(properties.get(i).getId())){
+					if(i==(properties.size()-1)){
+						throw new Exception("无法下移");
+					}else{
+						Integer number = property.getNumber();
+						property.setNumber(properties.get(i+1).getNumber());
+						properties.get(i+1).setNumber(number);
+						propertyRepo.save(property);
+						propertyRepo.save(properties.get(i+1));
+					}
+				}
+			}
+		}
+	}
+
 }

+ 34 - 0
cqb-question-resource/src/main/java/com/qmth/cqb/question/web/PropertyController.java

@@ -124,4 +124,38 @@ public class PropertyController {
 		}
 		return new ResponseEntity<Object>(HttpStatus.NOT_FOUND);
 	}
+	
+	@ApiOperation(value="上移",notes="上移")
+	@PutMapping(value="/property/moveUp")
+	public ResponseEntity<Object> moveUp(HttpServletRequest request, @RequestBody Property property){
+		AccessUser accessUser = (AccessUser)request.getAttribute("accessUser");
+		if(accessUser != null){
+			try {
+				property.setOrgId(accessUser.getRootOrgId());
+				propertyService.moveUp(property);
+				return new ResponseEntity<Object>(HttpStatus.OK);
+			} catch (Exception e) {
+				e.printStackTrace();
+				return new ResponseEntity<Object>(HttpStatus.INTERNAL_SERVER_ERROR);
+			}
+		}
+		return new ResponseEntity<Object>(HttpStatus.NOT_FOUND);
+	}
+	
+	@ApiOperation(value="下移",notes="下移")
+	@PutMapping(value="/property/moveDown")
+	public ResponseEntity<Object> moveDown(HttpServletRequest request, @RequestBody Property property){
+		AccessUser accessUser = (AccessUser)request.getAttribute("accessUser");
+		if(accessUser != null){
+			try {
+				property.setOrgId(accessUser.getRootOrgId());
+				propertyService.moveDown(property);
+				return new ResponseEntity<Object>(HttpStatus.OK);
+			} catch (Exception e) {
+				e.printStackTrace();
+				return new ResponseEntity<Object>(HttpStatus.INTERNAL_SERVER_ERROR);
+			}
+		}
+		return new ResponseEntity<Object>(HttpStatus.NOT_FOUND);
+	}
 }