package com.tofly.gpsboot.custom.controller;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.tofly.common.core.entity.ResultRespone;
import com.tofly.common.ftp.config.FtpUtil;
import com.tofly.common.log.annotation.ToFlyAppLog;
import com.tofly.gpsboot.config.car.CarFilePathBean;
import com.tofly.gpsboot.service.car.CarRepairService;
import com.tofly.pojo.car.CarRepair;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.servlet.http.HttpServletRequest;


//@RestController
//@AllArgsConstructor
//@RequestMapping("/carrepair")
//@Api(tags="车辆维修信息管理接口")
public class CustomCarRepairController {

//    private final CarRepairService carRepairService;
//    private final CarFilePathBean carFilePathBean;
//
//    /**
//     * 新增车辆维修信息管理
//     * @param carRepair 车辆维修信息管理
//     * @return ResultRespone
//     */
//    @ToFlyAppLog(title="新增车辆维修信息管理" )
//    @ApiOperation(value = "新增车辆维修信息管理")
//    @PostMapping(headers = "content-type=multipart/form-data")
//    public ResultRespone save(HttpServletRequest request, CarRepair carRepair) {
//        MultiValueMap<String, MultipartFile> files = ((MultipartHttpServletRequest) request).getMultiFileMap();
//        StringBuilder fileNames=new StringBuilder();
//        files.forEach((k, v) -> {
//            //保存照片
//            v.forEach(file -> {
//                String fileName = file.getOriginalFilename();
//                String filePath = carFilePathBean.getCarpic() + IdWorker.getIdStr() + fileName.substring(fileName.lastIndexOf("."));
//                boolean b = FtpUtil.uploadFile2Ftp(file, filePath);
//                if (b) {
//                    fileNames.append(filePath).append(",");
//                }
//            });
//        });
//        if(fileNames.length()>0){
//            carRepair.setCarPic(fileNames.substring(0,fileNames.length()-1));
//        }
//        return ResultRespone.success(carRepairService.save(carRepair));
//    }
//
//    /**
//     * 修改车辆维修信息管理
//     * @param carRepair 车辆维修信息管理
//     * @return ResultRespone
//     */
//    @ToFlyAppLog(title="修改车辆维修信息管理" )
//    @ApiOperation(value = "修改车辆维修信息管理")
//    @PutMapping(headers = "content-type=multipart/form-data")
//    public ResultRespone updateById(HttpServletRequest request,CarRepair carRepair) {
//        MultiValueMap<String, MultipartFile> files = ((MultipartHttpServletRequest) request).getMultiFileMap();
//        StringBuilder fileNames=new StringBuilder();
//        files.forEach((k, v) -> {
//            //保存照片
//            v.forEach(file -> {
//                String fileName = file.getOriginalFilename();
//                String filePath = carFilePathBean.getCarpic() + IdWorker.getIdStr() + fileName.substring(fileName.lastIndexOf("."));
//                boolean b = FtpUtil.uploadFile2Ftp(file, filePath);
//                if (b) {
//                    fileNames.append(filePath).append(",");
//                }
//            });
//        });
//        if(fileNames.length()>0){
//            carRepair.setCarPic(fileNames.substring(0,fileNames.length()-1));
//        }
//        return ResultRespone.success(carRepairService.updateById(carRepair));
//    }
}
