xiatian 2 years ago
parent
commit
f2a3ad1173

+ 2 - 1
db/init.sql

@@ -149,7 +149,8 @@ CREATE TABLE `mps_paper_group_unit` (
   `detail_number` int NOT NULL,
   `detail_unit_number` int NOT NULL,
   PRIMARY KEY (`id`),
-  UNIQUE KEY `IDX_PAPER_GROUP_UNIT_01` (`paper_id`,`group_id`,`detail_number`,`detail_unit_number`)
+  UNIQUE KEY `IDX_PAPER_GROUP_UNIT_01` (`paper_id`,`detail_number`,`detail_unit_number`),
+  KEY `IDX_PAPER_GROUP_UNIT_02` (`group_id`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
 
 -- ----------------------------

+ 2 - 2
src/main/java/cn/com/qmth/mps/controller/PaperController.java

@@ -150,8 +150,8 @@ public class PaperController extends BaseController {
 	
 	@ApiOperation(value = "删除分组信息")
 	@RequestMapping(value = "group/delete", method = RequestMethod.POST)
-	public void groupDelete(@RequestParam Long paperId, @RequestParam Integer groupNumber) {
-		paperGroupService.groupDelete(paperId,groupNumber,getAccessUser());
+	public void groupDelete(@RequestParam Long groupId) {
+		paperGroupService.groupDelete(groupId,getAccessUser());
 	}
 	
 	@ApiOperation(value = "清空分组信息")

+ 1 - 1
src/main/java/cn/com/qmth/mps/service/PaperGroupService.java

@@ -26,7 +26,7 @@ public interface PaperGroupService  extends IService<PaperGroupEntity> {
 
 	void groupSave(PaperGroupDomain domain, User accessUser);
 
-	void groupDelete(Long paperId, Integer groupNumber, User accessUser);
+	void groupDelete(Long groupId, User accessUser);
 
 	Boolean existsGroup(Long paperId);
 

+ 1 - 1
src/main/java/cn/com/qmth/mps/service/PaperGroupUnitService.java

@@ -13,7 +13,7 @@ public interface PaperGroupUnitService  extends IService<PaperGroupUnitEntity> {
 
 	Map<Long, List<PaperGroupUnit>> getGroupInfo(Long paperId);
 
-	void removeByPaperIdAndGroup(Long paperId, Long groupId);
+	void removeByGroupId(Long groupId);
 
 	void saveUnit(PaperGroupEntity group, List<PaperGroupUnit> groupUnits);
 

+ 17 - 12
src/main/java/cn/com/qmth/mps/service/impl/PaperGroupServiceImpl.java

@@ -218,11 +218,16 @@ public class PaperGroupServiceImpl extends ServiceImpl<PaperGroupDao, PaperGroup
 		if (!paper.getStructFinish()) {
 			throw new StatusException("试卷结构未提交,不能设置分组");
 		}
-		groupDelete(domain.getPaperId(), domain.getNumber(), user);
-		PaperGroupEntity g = new PaperGroupEntity();
+		PaperGroupEntity g;
+		if(domain.getGroupId()!=null) {
+			g=this.getById(domain.getGroupId());
+			paperGroupUnitService.removeByGroupId(domain.getGroupId());
+		}else {
+			g = new PaperGroupEntity();
+			g.setPaperId(domain.getPaperId());
+		}
 		g.setNumber(domain.getNumber());
-		g.setPaperId(domain.getPaperId());
-		this.save(g);
+		this.saveOrUpdate(g);
 		List<PaperDetail> pds = paperDetailService.getStructInfo(domain.getPaperId());
 		if (CollectionUtils.isEmpty(pds)) {
 			throw new StatusException("试卷结构小题信息为空");
@@ -258,20 +263,20 @@ public class PaperGroupServiceImpl extends ServiceImpl<PaperGroupDao, PaperGroup
 
 	@Transactional
 	@Override
-	public void groupDelete(Long paperId, Integer groupNumber, User user) {
-		PaperEntity paper = paperService.getById(paperId);
+	public void groupDelete(Long groupId, User user) {
+		PaperGroupEntity group=this.getById(groupId);
+		if (group == null) {
+			throw new StatusException("未找到分组信息");
+		}
+		PaperEntity paper = paperService.getById(group.getPaperId());
 		if (paper == null) {
 			throw new StatusException("未找到试卷结构");
 		}
 		if (!user.getRole().equals(Role.SUPER_ADMIN) && !user.getSchoolId().equals(paper.getSchoolId())) {
 			throw new StatusException("没有权限");
 		}
-		PaperGroupEntity old = getByPaperIdAndNumber(paperId, groupNumber);
-		if (old == null) {
-			return;
-		}
-		this.removeById(old.getId());
-		paperGroupUnitService.removeByPaperIdAndGroup(paperId, old.getId());
+		this.removeById(groupId);
+		paperGroupUnitService.removeByGroupId(groupId);
 		paper.setGroupFinish(false);
 		paperService.updateById(paper);
 	}

+ 1 - 2
src/main/java/cn/com/qmth/mps/service/impl/PaperGroupUnitServiceImpl.java

@@ -53,10 +53,9 @@ public class PaperGroupUnitServiceImpl extends ServiceImpl<PaperGroupUnitDao, Pa
 	}
 	@Transactional
 	@Override
-	public void removeByPaperIdAndGroup(Long paperId, Long groupId) {
+	public void removeByGroupId( Long groupId) {
 		QueryWrapper<PaperGroupUnitEntity> wrapper = new QueryWrapper<>();
 		LambdaQueryWrapper<PaperGroupUnitEntity> lw = wrapper.lambda();
-		lw.eq(PaperGroupUnitEntity::getPaperId, paperId);
 		lw.eq(PaperGroupUnitEntity::getGroupId, groupId);
 		this.remove(wrapper);
 	}

+ 8 - 0
src/main/java/cn/com/qmth/mps/vo/paper/PaperGroupDomain.java

@@ -6,6 +6,8 @@ import cn.com.qmth.mps.bean.PaperGroupUnit;
 import io.swagger.annotations.ApiModelProperty;
 
 public class PaperGroupDomain {
+	@ApiModelProperty("分组ID")
+	private Long groupId;
 	@ApiModelProperty("试卷结构ID")
 	private Long paperId;
 	@ApiModelProperty("分组序号")
@@ -30,5 +32,11 @@ public class PaperGroupDomain {
 	public void setPaperId(Long paperId) {
 		this.paperId = paperId;
 	}
+	public Long getGroupId() {
+		return groupId;
+	}
+	public void setGroupId(Long groupId) {
+		this.groupId = groupId;
+	}
 	
 }