12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- package cn.com.qmth.am.task;
- import java.util.List;
- import org.apache.commons.collections4.CollectionUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.scheduling.annotation.Scheduled;
- import org.springframework.stereotype.Service;
- import com.qmth.boot.core.concurrent.service.ConcurrentService;
- import cn.com.qmth.am.config.SysProperty;
- import cn.com.qmth.am.entity.StudentScoreEntity;
- import cn.com.qmth.am.enums.LockType;
- import cn.com.qmth.am.service.StudentScoreService;
- @Service
- public class AiMarkingJob {
- public static Boolean enable=null;
- @Autowired
- private StudentScoreService studentScoreService;
- @Autowired
- private ConcurrentService concurrentService;
- @Autowired
- private SysProperty sysProperty;
- @Scheduled(fixedDelay = 5 * 1000, initialDelay = 20 * 1000)
- public void doJob() {
- if(enable==null) {
- enable=sysProperty.getMarkingTaskEnable();
- }
- if(!enable) {
- return;
- }
- List<StudentScoreEntity> scores = studentScoreService.findAllToAiMarking();
- if (CollectionUtils.isEmpty(scores)) {
- return;
- }
- boolean lock = concurrentService.getReadWriteLock(LockType.AI_MARKING.name()).writeLock().tryLock();
- try {
- if (!lock) {
- return;
- }
- this.dispose(scores);
- } finally {
- if (lock) {
- concurrentService.getReadWriteLock(LockType.AI_MARKING.name()).writeLock().unlock();
- }
- }
- }
- private void dispose(List<StudentScoreEntity> scores) {
- for (StudentScoreEntity score : scores) {
- if(!enable) {
- return;
- }
- studentScoreService.aiMarking(score);
- }
- }
- }
|