Joburgess 5 years ago
parent
commit
95319de000

+ 9 - 0
edu-user/edu-user-server/src/main/java/com/keao/edu/user/service/ExamTeacherSalaryService.java

@@ -23,6 +23,15 @@ public interface ExamTeacherSalaryService extends BaseService<Long, ExamTeacherS
     void teacherSalarySettlementWithExam(Long examId);
     void teacherSalarySettlementWithExam(Long examId);
 
 
     /**
     /**
+     * @describe 结算指定考试中教师的薪酬
+     * @author Joburgess
+     * @date 2020.07.01
+     * @param examIds:
+     * @return void
+     */
+    void teacherSalarySettlementWithExam(List<Long> examIds);
+
+    /**
      * @describe
      * @describe
      * @author Joburgess
      * @author Joburgess
      * @date 2020.07.08
      * @date 2020.07.08

+ 12 - 1
edu-user/edu-user-server/src/main/java/com/keao/edu/user/service/impl/ExamRoomServiceImpl.java

@@ -19,6 +19,7 @@ import com.keao.edu.user.entity.ExamRegistration;
 import com.keao.edu.user.entity.ExaminationBasic;
 import com.keao.edu.user.entity.ExaminationBasic;
 import com.keao.edu.user.page.ExamRoomQueryInfo;
 import com.keao.edu.user.page.ExamRoomQueryInfo;
 import com.keao.edu.user.service.ExamRoomService;
 import com.keao.edu.user.service.ExamRoomService;
+import com.keao.edu.user.service.ExamTeacherSalaryService;
 import com.keao.edu.user.service.OrganizationService;
 import com.keao.edu.user.service.OrganizationService;
 import com.keao.edu.util.collection.MapUtil;
 import com.keao.edu.util.collection.MapUtil;
 import com.keao.edu.util.date.DateUtil;
 import com.keao.edu.util.date.DateUtil;
@@ -27,6 +28,7 @@ import org.apache.commons.lang.time.DateUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 import org.springframework.util.CollectionUtils;
 
 
 import java.util.*;
 import java.util.*;
@@ -47,6 +49,8 @@ public class ExamRoomServiceImpl extends BaseServiceImpl<Long, ExamRoom> impleme
 	private ExaminationBasicDao examinationBasicDao;
 	private ExaminationBasicDao examinationBasicDao;
 	@Autowired
 	@Autowired
 	private SysUserDao sysUserDao;
 	private SysUserDao sysUserDao;
+	@Autowired
+	private ExamTeacherSalaryService examTeacherSalaryService;
 
 
 	@Override
 	@Override
 	public BaseDAO<Long, ExamRoom> getDAO() {
 	public BaseDAO<Long, ExamRoom> getDAO() {
@@ -191,6 +195,8 @@ public class ExamRoomServiceImpl extends BaseServiceImpl<Long, ExamRoom> impleme
 		}
 		}
 		examRoomDao.batchInsert(examRooms);
 		examRoomDao.batchInsert(examRooms);
 		examinationBasicDao.update(examinationBasic);
 		examinationBasicDao.update(examinationBasic);
+
+		examTeacherSalaryService.teacherSalarySettlementWithExam(examinationBasic.getId());
 	}
 	}
 
 
 	@Override
 	@Override
@@ -221,13 +227,19 @@ public class ExamRoomServiceImpl extends BaseServiceImpl<Long, ExamRoom> impleme
 	}
 	}
 
 
 	@Override
 	@Override
+	@Transactional(rollbackFor = Exception.class)
 	public void deleteExamRooms(String examRoomIdsStr) {
 	public void deleteExamRooms(String examRoomIdsStr) {
 		if(StringUtils.isBlank(examRoomIdsStr)){
 		if(StringUtils.isBlank(examRoomIdsStr)){
 			return;
 			return;
 		}
 		}
 		List<Long> examRoomIds = Arrays.asList(examRoomIdsStr.split(",")).stream().map(e -> Long.valueOf(e)).collect(Collectors.toList());
 		List<Long> examRoomIds = Arrays.asList(examRoomIdsStr.split(",")).stream().map(e -> Long.valueOf(e)).collect(Collectors.toList());
+
+		ExamRoom examRoom = examRoomDao.get(examRoomIds.get(0));
+
 		examRoomDao.batchDeleteExamRooms(examRoomIds);
 		examRoomDao.batchDeleteExamRooms(examRoomIds);
 		examRoomStudentRelationDao.deleteWithExamRooms(examRoomIds);
 		examRoomStudentRelationDao.deleteWithExamRooms(examRoomIds);
+
+		examTeacherSalaryService.teacherSalarySettlementWithExam(examRoom.getExaminationBasicId());
 	}
 	}
 
 
 	@Override
 	@Override
@@ -237,7 +249,6 @@ public class ExamRoomServiceImpl extends BaseServiceImpl<Long, ExamRoom> impleme
 		if(withoutExamRoomStudentNum>0){
 		if(withoutExamRoomStudentNum>0){
 			throw new BizException("存在未安排教室的学员");
 			throw new BizException("存在未安排教室的学员");
 		}
 		}
-
 	}
 	}
 
 
 	@Override
 	@Override

+ 5 - 2
edu-user/edu-user-server/src/main/java/com/keao/edu/user/service/impl/ExamRoomStudentRelationServiceImpl.java

@@ -238,11 +238,12 @@ public class ExamRoomStudentRelationServiceImpl extends BaseServiceImpl<Long, Ex
 	}
 	}
 
 
 	@Override
 	@Override
+	@Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
 	public void deleteStudentFromRoom(Long examRoomId, String registIdsStr) {
 	public void deleteStudentFromRoom(Long examRoomId, String registIdsStr) {
 		if(Objects.isNull(examRoomId)){
 		if(Objects.isNull(examRoomId)){
 			throw new BizException("请指定教室");
 			throw new BizException("请指定教室");
 		}
 		}
-		ExamRoom examRoom = examRoomDao.get(examRoomId);
+		ExamRoom examRoom = examRoomDao.lockRoom(examRoomId);
 		if(Objects.isNull(examRoom)){
 		if(Objects.isNull(examRoom)){
 			throw new BizException("教室不存在");
 			throw new BizException("教室不存在");
 		}
 		}
@@ -251,7 +252,9 @@ public class ExamRoomStudentRelationServiceImpl extends BaseServiceImpl<Long, Ex
 		}
 		}
 		List<Long> registIds = Arrays.asList(registIdsStr.split(",")).stream().map(e -> Long.valueOf(e)).collect(Collectors.toList());
 		List<Long> registIds = Arrays.asList(registIdsStr.split(",")).stream().map(e -> Long.valueOf(e)).collect(Collectors.toList());
 		examRoomStudentRelationDao.deleteStudentsFromExamRoom(examRoomId, registIds);
 		examRoomStudentRelationDao.deleteStudentsFromExamRoom(examRoomId, registIds);
-		examCertificationDao.deleteWithRegist(registIds);
+		int deleteNum = examCertificationDao.deleteWithRegist(registIds);
+		examRoom.setExamRoomStudentNum(examRoom.getExamRoomStudentNum()-deleteNum);
+		examRoomDao.update(examRoom);
 		examTeacherSalaryService.teacherSalarySettlementWithExam(examRoom.getExaminationBasicId());
 		examTeacherSalaryService.teacherSalarySettlementWithExam(examRoom.getExaminationBasicId());
 	}
 	}
 
 

+ 51 - 0
edu-user/edu-user-server/src/main/java/com/keao/edu/user/service/impl/ExamTeacherSalaryServiceImpl.java

@@ -17,6 +17,7 @@ import com.keao.edu.util.collection.MapUtil;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 import org.springframework.util.CollectionUtils;
 
 
 import java.math.BigDecimal;
 import java.math.BigDecimal;
@@ -43,6 +44,7 @@ public class ExamTeacherSalaryServiceImpl extends BaseServiceImpl<Long, ExamTeac
 	}
 	}
 
 
 	@Override
 	@Override
+	@Transactional(rollbackFor = Exception.class)
 	public void teacherSalarySettlementWithExam(Long examId) {
 	public void teacherSalarySettlementWithExam(Long examId) {
 		List<ExamRoom> examRooms = examRoomDao.getWithExam(null, examId);
 		List<ExamRoom> examRooms = examRoomDao.getWithExam(null, examId);
 		if(CollectionUtils.isEmpty(examRooms)){
 		if(CollectionUtils.isEmpty(examRooms)){
@@ -87,6 +89,55 @@ public class ExamTeacherSalaryServiceImpl extends BaseServiceImpl<Long, ExamTeac
 	}
 	}
 
 
 	@Override
 	@Override
+	public void teacherSalarySettlementWithExam(List<Long> examIds) {
+		if(CollectionUtils.isEmpty(examIds)){
+			return;
+		}
+		for (Long examId : examIds) {
+			List<ExamRoom> examRooms = examRoomDao.getWithExam(null, examId);
+			if(CollectionUtils.isEmpty(examRooms)){
+				return;
+			}
+
+			Map<Integer, List<ExamRoom>> teacherExamRoomMap=new HashMap<>();
+			for (ExamRoom examRoom : examRooms) {
+				if(!teacherExamRoomMap.containsKey(examRoom.getMainTeacherUserId())){
+					teacherExamRoomMap.put(examRoom.getMainTeacherUserId(), new ArrayList<>());
+				}
+				teacherExamRoomMap.get(examRoom.getMainTeacherUserId()).add(examRoom);
+				if(StringUtils.isBlank(examRoom.getAssistantTeacherUserIdList())){
+					continue;
+				}
+				for (String assistantTeacherId : examRoom.getAssistantTeacherUserIdList().split(",")) {
+					if(!teacherExamRoomMap.containsKey(Integer.valueOf(assistantTeacherId))){
+						teacherExamRoomMap.put(Integer.valueOf(assistantTeacherId), new ArrayList<>());
+					}
+					teacherExamRoomMap.get(Integer.valueOf(assistantTeacherId)).add(examRoom);
+				}
+			}
+
+			List<ExamRoomStudentRelation> examRoomStudentRelations = examRoomStudentRelationDao.getExamRoomStudentRelations(examId, null, null);
+
+			List<ExamTeacherSalary> examTeacherSalaries = examTeacherSalaryDao.queryWithExam(examId);
+			for (ExamTeacherSalary examTeacherSalary : examTeacherSalaries) {
+				List<ExamRoom> teacherExamRooms = teacherExamRoomMap.get(examTeacherSalary.getTeacherId());
+				if(CollectionUtils.isEmpty(teacherExamRooms)){
+					examTeacherSalary.setTotalInvigilationNum(0);
+					examTeacherSalary.setTotalInvigilationStudentNum(0);
+					examTeacherSalary.setTotalSettlementCost(BigDecimal.ZERO);
+					continue;
+				}
+				Set<Long> examRoomIds = teacherExamRooms.stream().map(ExamRoom::getId).collect(Collectors.toSet());
+				long studentNum = examRoomStudentRelations.stream().filter(e -> examRoomIds.contains(e.getExamRoomId())).count();
+				examTeacherSalary.setTotalInvigilationNum(examRoomIds.size());
+				examTeacherSalary.setTotalInvigilationStudentNum((int) studentNum);
+				examTeacherSalary.setTotalSettlementCost(examTeacherSalary.getShareProfitAmount().multiply(new BigDecimal(studentNum)));
+			}
+			examTeacherSalaryDao.batchUpdate(examTeacherSalaries);
+		}
+	}
+
+	@Override
 	public PageInfo<ExamTeacherSalaryDto> queryExamTeacherSalary(ExamTeacherSalaryQueryInfo queryInfo) {
 	public PageInfo<ExamTeacherSalaryDto> queryExamTeacherSalary(ExamTeacherSalaryQueryInfo queryInfo) {
 		PageInfo<ExamTeacherSalaryDto> pageInfo = new PageInfo<>(queryInfo.getPage(), queryInfo.getRows());
 		PageInfo<ExamTeacherSalaryDto> pageInfo = new PageInfo<>(queryInfo.getPage(), queryInfo.getRows());
 		Map<String, Object> params = new HashMap<String, Object>();
 		Map<String, Object> params = new HashMap<String, Object>();

+ 1 - 1
edu-user/edu-user-server/src/main/resources/config/mybatis/ExamRegistrationMapper.xml

@@ -194,7 +194,7 @@
 				</if>
 				</if>
 				update_time_ = NOW()
 				update_time_ = NOW()
 			</set>
 			</set>
-			WHERE id_ = #{id}
+			WHERE id_ = #{regist.id}
 		</foreach>
 		</foreach>
 	</update>
 	</update>