skyouc
10 天以前 b7b3328fdfa45cf13d1943fa79d47f1b6bb43f01
rsf-server/src/main/java/com/vincent/rsf/server/manager/schedules/TaskSchedules.java
@@ -8,6 +8,9 @@
import com.vincent.rsf.server.system.constant.GlobalConfigCode;
import com.vincent.rsf.server.system.entity.Config;
import com.vincent.rsf.server.system.service.ConfigService;
import com.vincent.rsf.server.system.utils.SystemAuthUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
@@ -27,6 +30,8 @@
@Component
public class TaskSchedules {
    public static Logger logger = LoggerFactory.getLogger(TaskSchedules.class);
    @Autowired
    private TaskService taskService;
    @Autowired
@@ -35,18 +40,6 @@
    private TaskLogService taskLogService;
    @Autowired
    private TaskItemLogService taskItemLogService;
    @Autowired
    private StockItemService stockItemService;
    @Autowired
    private PurchaseService purchaseService;
    @Autowired
    private AsnOrderService asnOrderService;
    @Autowired
    private AsnOrderItemService asnOrderItemService;
    @Autowired
    private StockService stockService;
    @Autowired
    private LocService locService;
    @Autowired
    private ConfigService configService;
@@ -107,14 +100,6 @@
            return;
        }
        List<Long> list = tasks.stream().map(Task::getId).collect(Collectors.toList());
        List<TaskItem> taskItems = taskItemService.list(new LambdaQueryWrapper<TaskItem>().in(TaskItem::getTaskId, list));
        if (taskItems.isEmpty()) {
            return;
        }
        Map<Long, List<TaskItem>> listMap = taskItems.stream().collect(Collectors.groupingBy(TaskItem::getTaskId));
        tasks.forEach(task -> {
            TaskLog taskLog = new TaskLog();
            BeanUtils.copyProperties(task, taskLog);
@@ -123,9 +108,9 @@
            if (!taskLogService.save(taskLog)) {
                throw new CoolException("任务历史档保存失败!!");
            }
            List<TaskItem> taskItems = taskItemService.list(new LambdaQueryWrapper<TaskItem>().eq(TaskItem::getTaskId, task.getId()));
            List<TaskItemLog> itemLogs = new ArrayList<>();
            for (TaskItem item : listMap.get(task.getId())) {
            for (TaskItem item : taskItems) {
                TaskItemLog itemLog = new TaskItemLog();
                BeanUtils.copyProperties(item, itemLog);
                itemLog.setId(null)
@@ -135,19 +120,19 @@
                itemLogs.add(itemLog);
            }
            if (!taskItemLogService.saveBatch(itemLogs)) {
                throw new CoolException("任务明细历史档保存失败!!");
            if (!taskService.removeById(task.getId())) {
                throw new CoolException("原始任务删除失败!!");
            }
            if (!taskItems.isEmpty()) {
                if (!taskItemLogService.saveBatch(itemLogs)) {
                    throw new CoolException("任务明细历史档保存失败!!");
                }
                if (!taskItemService.remove(new LambdaQueryWrapper<TaskItem>().eq(TaskItem::getTaskId, task.getId()))) {
                    throw new CoolException("原始任务明细删除失败!!");
                }
            }
        });
        if (!taskService.removeByIds(list)) {
            throw new CoolException("原始任务删除失败!!");
        }
        List<Long> itemIds = taskItems.stream().map(TaskItem::getId).collect(Collectors.toList());
        if (!taskItemService.removeByIds(itemIds)) {
            throw new CoolException("原始任务明细删除失败!!");
        }
    }
}