package cn.iocoder.yudao.module.tickets.service.impl;

import cn.iocoder.yudao.module.tickets.entity.Tickets;
import cn.iocoder.yudao.module.tickets.mapper.TicketsMapper;
import cn.iocoder.yudao.module.tickets.service.BaseRepairRecordsService;
import cn.iocoder.yudao.module.tickets.service.TicketsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 小李
 * @date 9:35 2024/9/25
**/
@Service
public class TicketsServiceImpl extends ServiceImpl<TicketsMapper, Tickets> implements TicketsService {
    @Autowired
    private BaseRepairRecordsService baseRepairRecordsService;

    /**
     * 更新工单状态为已结账-----小程序结算工单
     * 考虑可能有批量操作的情况，采用批量更新的方式
     *
     * @author 小李
     * @date 9:36 2024/9/25
     * @param ticketIds 工单ids
     **/
    @Override
    public void updateTickets(List<String> ticketIds){
        for (String id:ticketIds){
            Tickets tickets = this.getById(id);
            if("1".equals(tickets.getIsHandover())){
                //已交车，已结算，那么需要把工单状态置为已完成
                tickets.setTicketsStatus("08");
                tickets.setIsFinish("1");
            }else{
                tickets.setTicketsStatus("02");
            }
            this.updateById(tickets);
            baseRepairRecordsService.saveRepairRecord(id, null, "js", "线上支付结算", null);
        }
    }
}
