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

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.module.system.dal.dataobject.permission.RoleDO;
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
import cn.iocoder.yudao.module.system.service.permission.PermissionService;
import cn.iocoder.yudao.module.system.service.permission.RoleService;
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.github.pagehelper.PageHelper;
import cn.iocoder.yudao.module.core.controller.BaseController;
import cn.iocoder.yudao.module.inspection.service.AppUserOwnService;
import cn.iocoder.yudao.module.shop.entity.ShopUserCar;
import cn.iocoder.yudao.module.shop.service.IShopUserCarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/admin-api/appInspection/userOwn")
public class AppUserOwnController extends BaseController {
    @Autowired
    private AppUserOwnService ownService;

    @Autowired
    private IShopUserCarService shopUserCarService;

    @Autowired
    private PermissionService permissionService;
    @Autowired
    private AdminUserService userService;
    @Autowired
    private RoleService roleService;

    @PostMapping("/updateRole")
    public CommonResult updateRole(String roleCode)
    {
        ownService.updateRole(roleCode);
        return   success();
    }

    @GetMapping("/getCars")
    @TenantIgnore
    public CommonResult getCars()
    {
        return   success(ownService.getCars());
    }

    @GetMapping("/getCanInspectionCars")
    public CommonResult getCanInspectionCars()
    {
        return   success(ownService.getCanInspectionCars());
    }

    @GetMapping("/getDbList")
    public CommonResult getDbList(String searchValue,
                                  @RequestParam(value = "pageNum" ,required = false ,defaultValue = "1") Integer pageNum,
                                  @RequestParam(value ="pageSize" ,required = false ,defaultValue = "10") Integer pageSize)
    {
        Page<AdminUserDO> page = new Page<>(pageNum, pageSize);
        IPage<AdminUserDO> dbList = ownService.getDbListTow(page,searchValue);
        return success(dbList);
    }

    @GetMapping(value = "/getAppUserCar")
    public CommonResult getAppUserCar()
    {
        return success(ownService.getAppUserCar());
    }

    /**
     * 修改用户车辆
     */
    @PostMapping("/editCar")
    public CommonResult edit(@RequestBody ShopUserCar shopUserCar)
    {
        return toAjax(shopUserCarService.updateShopUserCar(shopUserCar));
    }

    /**
     * 修改用户车辆
     */
    @GetMapping("/getCarById")
    public CommonResult getCarById(Long carId)
    {
        return success(shopUserCarService.selectShopUserCarByCarId(carId));
    }

}
