package cn.iocoder.yudao.module.shop.controller;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.module.core.controller.BaseController;
import cn.iocoder.yudao.module.shop.entity.ShopUserCar;
import cn.iocoder.yudao.module.shop.service.IShopUserCarService;
import cn.iocoder.yudao.util.ExcelUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.checkerframework.checker.units.qual.C;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 用户车辆Controller
 *
 * @author ruoyi
 * @date 2023-07-10
 */
@RestController
@RequestMapping("/admin-api/system/userCar")
public class ShopUserCarController extends BaseController
{
    @Autowired

    private IShopUserCarService shopUserCarService;

    /**
     * 查询用户车辆列表
     */
//    @PreAuthorize("@ss.hasPermi('system:userCar:list')")
    @GetMapping("/list")
    public CommonResult list(ShopUserCar shopUserCar,
                             @RequestParam(value = "pageNum" ,required = false ,defaultValue = "1") Integer pageNum,
                             @RequestParam(value ="pageSize" ,required = false ,defaultValue = "10") Integer pageSize)
    {
        Page<ShopUserCar> page = new Page<>(pageNum, pageSize);
        IPage<ShopUserCar> list = shopUserCarService.selectShopUserCarList(page,shopUserCar);
        return success(list);
    }
    @GetMapping("/listOfPartner")
    public CommonResult listOfPartner(ShopUserCar shopUserCar,
                                      @RequestParam(value = "pageNum" ,required = false ,defaultValue = "1") Integer pageNum,
                                      @RequestParam(value ="pageSize" ,required = false ,defaultValue = "10") Integer pageSize)
    {
        Page<ShopUserCar> page = new Page<>(pageNum, pageSize);
        IPage<ShopUserCar> list = shopUserCarService.selectShopUserCarList(page,shopUserCar);
        return success(list);
    }
    /**
     * 导出用户车辆列表
     */
//    @PreAuthorize("@ss.hasPermi('system:userCar:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, ShopUserCar shopUserCar,
                       @RequestParam(value = "pageNum" ,required = false ,defaultValue = "1") Integer pageNum,
                       @RequestParam(value ="pageSize" ,required = false ,defaultValue = "10") Integer pageSize)
    {
        Page<ShopUserCar> page = new Page<>(pageNum,pageSize);
        IPage<ShopUserCar> list = shopUserCarService.selectShopUserCarList(page,shopUserCar);
        ExcelUtil<ShopUserCar> util = new ExcelUtil<ShopUserCar>(ShopUserCar.class);
        util.exportExcel(response, list.getRecords(), "用户车辆数据");
    }

    /**
     * 获取用户车辆详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:userCar:query')")
    @GetMapping(value = "/{carId}")
    public CommonResult getInfo(@PathVariable("carId") Long carId)
    {
        return success(shopUserCarService.selectShopUserCarByCarId(carId));
    }

    /**
     * 新增用户车辆
     */
//    @PreAuthorize("@ss.hasPermi('system:userCar:add')")

    @PostMapping
    public CommonResult add(@RequestBody ShopUserCar shopUserCar)
    {
        return toAjax(shopUserCarService.insertShopUserCar(shopUserCar));
    }

    /**
     * 修改用户车辆
     */
//    @PreAuthorize("@ss.hasPermi('system:userCar:edit')")

    @PutMapping
    public CommonResult edit(@RequestBody ShopUserCar shopUserCar)
    {
        return toAjax(shopUserCarService.updateShopUserCar(shopUserCar));
    }


    /**
     * 删除用户车辆
     */
//    @PreAuthorize("@ss.hasPermi('system:userCar:remove')")

	@DeleteMapping("/{carIds}")
    public CommonResult remove(@PathVariable Long[] carIds)
    {
        return toAjax(shopUserCarService.deleteShopUserCarByCarIds(carIds));
    }

    @GetMapping(value = "/getUserCar")
    @TenantIgnore
    public CommonResult getUserCarByUserId()
    {
        return success(shopUserCarService.selectShopUserCarByUserId(getUserId()));
    }

    @PostMapping("/vehicleLicenseOCR")
    public CommonResult vehicleLicenseOCR(String imagePath) throws Exception
    {
        return success(shopUserCarService.vehicleLicenseOCR(imagePath));
    }

    @PostMapping("/appVehicleLicenseOCR")
    public CommonResult appVehicleLicenseOCR(String imagePath) throws Exception
    {
        return success(shopUserCarService.appVehicleLicenseOCR(imagePath));
    }
//20240327追加接口
    @PostMapping("/appVehicleLicenseOCR2")
    public CommonResult appVehicleLicenseOCR2(String imagePath) throws Exception
    {
        return success(shopUserCarService.appVehicleLicenseOCR2(imagePath));
    }
    @PostMapping("/infoCardOCR")
    public CommonResult infoCardOCR(String imagePath) throws Exception
    {
        shopUserCarService.infoCardOCR(imagePath);
        return success();
    }
    @GetMapping("/getInfoCard")
    public CommonResult getInfoCard()
    {
        return success( shopUserCarService.getInfoCard());
    }
}
