|
@@ -0,0 +1,83 @@
|
|
|
|
|
+package org.dromara.server.sync.business.batch;
|
|
|
|
|
+
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.dromara.common.core.exception.ServiceException;
|
|
|
|
|
+import org.dromara.common.core.utils.SpringUtils;
|
|
|
|
|
+import org.dromara.common.core.utils.StringUtils;
|
|
|
|
|
+import org.dromara.server.common.constant.SyncResourceConstants;
|
|
|
|
|
+import org.dromara.server.common.domain.bo.ResourceDept;
|
|
|
|
|
+import org.dromara.server.sync.business.batch.mapper.TrainClassRecordMapper;
|
|
|
|
|
+import org.dromara.server.sync.domain.dto.request.TrainClassRecordRequest;
|
|
|
|
|
+import org.dromara.server.sync.domain.dto.wrapper.BatchSyncRequest;
|
|
|
|
|
+import org.dromara.server.sync.strategy.dept.ISyncDeptStrategy;
|
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+
|
|
|
|
|
+@Service
|
|
|
|
|
+@Slf4j
|
|
|
|
|
+@RequiredArgsConstructor
|
|
|
|
|
+public class TrainBatchSyncService {
|
|
|
|
|
+
|
|
|
|
|
+ private final TrainClassRecordMapper trainClassRecordMapper;
|
|
|
|
|
+
|
|
|
|
|
+ public void syncTrainClass(BatchSyncRequest<TrainClassRecordRequest> request) {
|
|
|
|
|
+ if (request == null || CollUtil.isEmpty(request.getRecords())) {
|
|
|
|
|
+ throw new ServiceException("records 不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ List<ResourceDept> addOrUpdateList = new ArrayList<>();
|
|
|
|
|
+ List<ResourceDept> deleteList = new ArrayList<>();
|
|
|
|
|
+
|
|
|
|
|
+ for (TrainClassRecordRequest record : request.getRecords()) {
|
|
|
|
|
+ validateRecord(record);
|
|
|
|
|
+ ResourceDept dept = trainClassRecordMapper.toResourceDept(record);
|
|
|
|
|
+ if ("1".equals(record.getDelFlag())) {
|
|
|
|
|
+ deleteList.add(dept);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ addOrUpdateList.add(dept);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ ISyncDeptStrategy syncDeptStrategy = SpringUtils.getBean(SyncResourceConstants.TRAIN_CLASS, ISyncDeptStrategy.class);
|
|
|
|
|
+ if (CollUtil.isNotEmpty(deleteList)) {
|
|
|
|
|
+ syncDeptStrategy.syncDelDept(deleteList);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (CollUtil.isNotEmpty(addOrUpdateList)) {
|
|
|
|
|
+ syncDeptStrategy.syncDept(addOrUpdateList);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ log.info("[batch-sync-train-class]-[总数:{}]-[新增更新:{}]-[删除:{}]",
|
|
|
|
|
+ request.getRecords().size(), addOrUpdateList.size(), deleteList.size());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void validateRecord(TrainClassRecordRequest record) {
|
|
|
|
|
+ if (record == null) {
|
|
|
|
|
+ throw new ServiceException("record 不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.isBlank(record.getClassId())) {
|
|
|
|
|
+ throw new ServiceException("classId 不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.isBlank(record.getClassName())) {
|
|
|
|
|
+ throw new ServiceException("className 不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.isBlank(record.getYear())) {
|
|
|
|
|
+ throw new ServiceException("year 不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.isBlank(record.getSemester())) {
|
|
|
|
|
+ throw new ServiceException("semester 不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.isBlank(record.getCheckinTime())) {
|
|
|
|
|
+ throw new ServiceException("checkinTime 不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.isBlank(record.getStartTime())) {
|
|
|
|
|
+ throw new ServiceException("startTime 不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.isBlank(record.getEndTime())) {
|
|
|
|
|
+ throw new ServiceException("endTime 不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|