package com.muyu.server.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.muyu.common.core.domain.Result;
import com.muyu.domain.CarInformation;
import com.muyu.domain.CarType;
import com.muyu.enterprise.cache.car.VehicleCacheCarTypeService;
import com.muyu.server.service.CarInformationService;
import com.muyu.server.service.CarTypeService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Locale;

/**
 * 车辆类型控制层
 * @Author：weiran
 * @Package：com.muyu.cloud.faultmanage.controller
 * @Project：cloud-server-8
 * @name：CarTypeController
 * @Date：2024/9/21 19:01
 */

@RequestMapping("/cartype")
@RestController
@AllArgsConstructor
public class CarTypeController {

    private final CarTypeService carTypeService;
    private final CarInformationService carInformationService;
    private final VehicleCacheCarTypeService vehicleCacheCarTypeService;


    /**
     * 车辆类型
     * @return
     */
    @PostMapping("/list")
    @Operation(summary = "车辆类型",description = "车辆类型信息")
    public Result carTypeList(){

        List<CarType> data = carTypeService.selectcarType();
        data.forEach(carType -> {
            List<CarInformation> list = carInformationService.list(new LambdaQueryWrapper<CarInformation>()
                    .eq(CarInformation::getCarInformationType, carType.getCarTypeId()));
            list.forEach(carInformation -> {
                vehicleCacheCarTypeService
                        .put(vehicleCacheCarTypeService
                                .keyPre()+carInformation
                                .getCarInformationVIN(),carType);
            });
        });
        return Result.success(data);
    }
}
