package com.chushang.inspection.work.service.impl;

import cn.hutool.core.lang.Assert;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chushang.inspection.utils.StreamUtils;
import com.chushang.inspection.work.mapper.WrkInfoDispatchMapper;
import com.chushang.inspection.work.po.WrkInfoDispatch;
import com.chushang.inspection.work.service.WrkInfoDispatchService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * @auther: zhao
 * @date: 2024/7/4 10:34
 */
@Slf4j
@Service
public class WrkInfoDispatchServiceImpl extends ServiceImpl<WrkInfoDispatchMapper, WrkInfoDispatch> implements WrkInfoDispatchService {
    @Override
    @Transactional
    public void updateWorkOrderProgress(Long userId, int disStatus, List<Long> wrkIds, Long deptId) {
        // 修改 派单进度
        if (disStatus == 6) {
            List<WrkInfoDispatch> schedules = StreamUtils.toList(wrkIds, wrkId -> new WrkInfoDispatch(wrkId,userId, deptId, 6));
            saveBatch(schedules);
        } else {
            // 修改派单 进度
            updateBatchById(StreamUtils.toList(wrkIds, wrkId-> {
                WrkInfoDispatch wrkInfoDispatch = new WrkInfoDispatch();
                wrkInfoDispatch.setWrkId(wrkId);
                wrkInfoDispatch.setDisStatus(disStatus);
                return wrkInfoDispatch;
            }));
        }
    }
}
