You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
129 lines
5.2 KiB
Java
129 lines
5.2 KiB
Java
|
1 month ago
|
package com.sztzjy.linkCommerce.service.impl;
|
||
|
|
|
||
|
|
import com.sztzjy.linkCommerce.entity.SchoolClass;
|
||
|
|
import com.sztzjy.linkCommerce.entity.SchoolDefaultTaskInitialization;
|
||
|
|
import com.sztzjy.linkCommerce.entity.TaskAllocation;
|
||
|
|
import com.sztzjy.linkCommerce.entity.TaskAllocationExample;
|
||
|
|
import com.sztzjy.linkCommerce.mapper.SchoolClassMapper;
|
||
|
|
import com.sztzjy.linkCommerce.mapper.SchoolDefaultTaskInitializationMapper;
|
||
|
|
import com.sztzjy.linkCommerce.mapper.TaskAllocationMapper;
|
||
|
|
import com.sztzjy.linkCommerce.service.SchoolDefaultTaskService;
|
||
|
|
import org.apache.commons.lang3.StringUtils;
|
||
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
||
|
|
import org.springframework.stereotype.Service;
|
||
|
|
|
||
|
|
import java.util.Collections;
|
||
|
|
import java.util.Date;
|
||
|
|
import java.util.List;
|
||
|
|
import java.util.UUID;
|
||
|
|
|
||
|
|
@Service
|
||
|
|
public class SchoolDefaultTaskServiceImpl implements SchoolDefaultTaskService {
|
||
|
|
private static final String SCHOOL_DEFAULT_PREFIX = "SCHOOL_DEFAULT:";
|
||
|
|
|
||
|
|
@Autowired
|
||
|
|
TaskAllocationMapper taskAllocationMapper;
|
||
|
|
@Autowired
|
||
|
|
SchoolClassMapper schoolClassMapper;
|
||
|
|
@Autowired(required = false)
|
||
|
|
SchoolDefaultTaskInitializationMapper initializationMapper;
|
||
|
|
|
||
|
|
public static String schoolDefaultClassId(String schoolId) {
|
||
|
|
return SCHOOL_DEFAULT_PREFIX + schoolId;
|
||
|
|
}
|
||
|
|
|
||
|
|
@Override
|
||
|
|
public List<TaskAllocation> resolveForTeachingClass(String teachingClassId) {
|
||
|
|
List<TaskAllocation> teachingClassTasks = listByClassId(teachingClassId);
|
||
|
|
if (!teachingClassTasks.isEmpty()) {
|
||
|
|
return teachingClassTasks;
|
||
|
|
}
|
||
|
|
SchoolClass schoolClass = schoolClassMapper == null ? null : schoolClassMapper.selectByPrimaryKey(teachingClassId);
|
||
|
|
if (schoolClass != null && StringUtils.isNotBlank(schoolClass.getSchoolId())) {
|
||
|
|
List<TaskAllocation> schoolTasks = getSchoolDefault(schoolClass.getSchoolId());
|
||
|
|
if (!schoolTasks.isEmpty()) {
|
||
|
|
return schoolTasks;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return listByClassId(PLATFORM_DEFAULT_CLASS_ID);
|
||
|
|
}
|
||
|
|
|
||
|
|
@Override
|
||
|
|
public List<TaskAllocation> getSchoolDefault(String schoolId) {
|
||
|
|
if (StringUtils.isBlank(schoolId)) {
|
||
|
|
return Collections.emptyList();
|
||
|
|
}
|
||
|
|
return listByClassId(schoolDefaultClassId(schoolId));
|
||
|
|
}
|
||
|
|
|
||
|
|
@Override
|
||
|
|
public SchoolDefaultTaskInitialization getInitialization(String schoolId) {
|
||
|
|
return initializationMapper == null || StringUtils.isBlank(schoolId)
|
||
|
|
? null : initializationMapper.selectByPrimaryKey(schoolId);
|
||
|
|
}
|
||
|
|
|
||
|
|
@Override
|
||
|
|
public void replaceSchoolDefault(String schoolId, List<TaskAllocation> tasks) {
|
||
|
|
if (StringUtils.isBlank(schoolId)) {
|
||
|
|
throw new IllegalArgumentException("学校不能为空");
|
||
|
|
}
|
||
|
|
String classId = schoolDefaultClassId(schoolId);
|
||
|
|
TaskAllocationExample example = new TaskAllocationExample();
|
||
|
|
example.createCriteria().andClassIdEqualTo(classId);
|
||
|
|
taskAllocationMapper.deleteByExample(example);
|
||
|
|
for (TaskAllocation task : tasks == null ? Collections.<TaskAllocation>emptyList() : tasks) {
|
||
|
|
task.setId(UUID.randomUUID().toString());
|
||
|
|
task.setClassId(classId);
|
||
|
|
task.setSchoolId(schoolId);
|
||
|
|
taskAllocationMapper.insert(task);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
@Override
|
||
|
|
public void initializeSchoolDefault(String schoolId) {
|
||
|
|
if (StringUtils.isBlank(schoolId) || hasSchoolDefault(schoolId)) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
List<TaskAllocation> platformTasks = listByClassId(PLATFORM_DEFAULT_CLASS_ID);
|
||
|
|
for (TaskAllocation source : platformTasks) {
|
||
|
|
TaskAllocation copy = new TaskAllocation();
|
||
|
|
copy.setId(UUID.randomUUID().toString());
|
||
|
|
copy.setClassId(schoolDefaultClassId(schoolId));
|
||
|
|
copy.setSchoolId(schoolId);
|
||
|
|
copy.setModule(source.getModule());
|
||
|
|
copy.setDisabledStatus(source.getDisabledStatus());
|
||
|
|
copy.setSort(source.getSort());
|
||
|
|
taskAllocationMapper.insert(copy);
|
||
|
|
}
|
||
|
|
markReady(schoolId);
|
||
|
|
}
|
||
|
|
|
||
|
|
private boolean hasSchoolDefault(String schoolId) {
|
||
|
|
TaskAllocationExample example = new TaskAllocationExample();
|
||
|
|
example.createCriteria().andClassIdEqualTo(schoolDefaultClassId(schoolId));
|
||
|
|
return taskAllocationMapper.countByExample(example) > 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
private List<TaskAllocation> listByClassId(String classId) {
|
||
|
|
if (taskAllocationMapper == null || StringUtils.isBlank(classId)) {
|
||
|
|
return Collections.emptyList();
|
||
|
|
}
|
||
|
|
TaskAllocationExample example = new TaskAllocationExample();
|
||
|
|
example.createCriteria().andClassIdEqualTo(classId);
|
||
|
|
example.setOrderByClause("sort asc");
|
||
|
|
List<TaskAllocation> tasks = taskAllocationMapper.selectByExample(example);
|
||
|
|
return tasks == null ? Collections.emptyList() : tasks;
|
||
|
|
}
|
||
|
|
|
||
|
|
private void markReady(String schoolId) {
|
||
|
|
if (initializationMapper == null) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
SchoolDefaultTaskInitialization record = new SchoolDefaultTaskInitialization();
|
||
|
|
record.setSchoolId(schoolId);
|
||
|
|
record.setStatus("READY");
|
||
|
|
record.setUpdateTime(new Date());
|
||
|
|
initializationMapper.updateByPrimaryKeySelective(record);
|
||
|
|
}
|
||
|
|
}
|