package com.sckw.fleet.service;


import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.sckw.fleet.model.TmsTruckAxleNum;
import com.sckw.fleet.model.request.TruckAxleNumUpdateParam;
import com.sckw.fleet.model.vo.TruckAxleNumVO;
import com.sckw.fleet.repository.KwfTruckAxleNumRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
*Author: donglang
*Time: 2025-10-24
*Des: 车辆管理Service
*Version: 1.0
*/

@Service
@RequiredArgsConstructor
public class KwfTruckAxleNumService {

    private final KwfTruckAxleNumRepository truckAxleNumRepository;

    /**
     * 查询轴数列表
     * @return
     */
    public List<TruckAxleNumVO> queryTruckAxleNumList() {
        List<TmsTruckAxleNum> truckAxleNums = truckAxleNumRepository.list(Wrappers.<TmsTruckAxleNum>lambdaQuery()
                .eq(TmsTruckAxleNum::getStatus, 1));
        return truckAxleNums.stream().map(TruckAxleNumVO::toTruckAxleNumVO).collect(Collectors.toList());
    }

    /**
     * 修改轴数
     * @param param
     */
    public void updateTruckAxleNum(TruckAxleNumUpdateParam param) {
        List<TruckAxleNumUpdateParam.TruckAxleNumUpdateParamVO> voList = param.getTruckAxleNumUpdateParamVOList();
        for (TruckAxleNumUpdateParam.TruckAxleNumUpdateParamVO vo : voList) {
            LambdaUpdateWrapper<TmsTruckAxleNum> updateWrapper = new LambdaUpdateWrapper<>();
            updateWrapper.eq(TmsTruckAxleNum::getId, vo.getId())
                    .set(TmsTruckAxleNum::getLegalLoad, vo.getLegalLoad())
                    .set(TmsTruckAxleNum::getTractorLegalLoad, vo.getTractorLegalLoad());
            truckAxleNumRepository.update(updateWrapper);
        }

    }


}
