package cn.iocoder.yudao.module.jx.controller.admin;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.module.jx.core.controller.BaseController;
import cn.iocoder.yudao.module.jx.domain.DriveSchoolInfo;
import cn.iocoder.yudao.module.jx.payment.vo.PayVo;
import cn.iocoder.yudao.module.jx.service.IDriveSchoolInfoService;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 驾校信息Controller
 *
 * @author ruoyi
 * @date 2024-03-19
 */
@RestController
@RequestMapping("/drivingSchool/system/schoolInfo")
public class DriveSchoolInfoController extends BaseController
{
    @Resource
    private IDriveSchoolInfoService driveSchoolInfoService;
    @Resource
    private AdminUserApi userApi;

    /**
     * 查询自己的订单
     * @return 返回订单列表
     */
    @GetMapping("/findSelfSchoolData")
    public List<PayVo> findSelfSchoolData() {
        List<PayVo> selfSchoolData = driveSchoolInfoService.findSelfSchoolData();
        return selfSchoolData;
    }

    /**
     * 查询驾校信息列表
     */

    @GetMapping("/list")
    public CommonResult<IPage<?>> list(DriveSchoolInfo driveSchoolInfo)
    {
        if(null == driveSchoolInfo.getPageNum()){
            driveSchoolInfo.setPageNum(1);
        }
        if (null == driveSchoolInfo.getPageSize()){
            driveSchoolInfo.setPageSize(100);
        }
        Page<DriveSchoolInfo> page = new Page<>(driveSchoolInfo.getPageNum(), driveSchoolInfo.getPageSize());
        IPage<DriveSchoolInfo> driveSchoolInfoIPage = driveSchoolInfoService.selectDriveSchoolInfoList(driveSchoolInfo, page);
        return CommonResult.success(driveSchoolInfoIPage);
        //return getDataTable(list);
    }

    /**
     * 导出驾校信息列表
     */
    //@Log(title = "驾校信息", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, DriveSchoolInfo driveSchoolInfo)
//    {
//        List<DriveSchoolInfo> list = driveSchoolInfoService.selectDriveSchoolInfoList(driveSchoolInfo);
//        ExcelUtil<DriveSchoolInfo> util = new ExcelUtil<DriveSchoolInfo>(DriveSchoolInfo.class);
//        util.exportExcel(response, list, "驾校信息数据");
//    }

    /**
     * 获取驾校信息详细信息
     */
    @GetMapping(value = "/{id}")
    public CommonResult getInfo(@PathVariable("id") Long id)
    {
        return success(driveSchoolInfoService.selectDriveSchoolInfoById(id));
    }

    /**
     * 根据机构id获取驾校信息详细信息
     */
    @GetMapping("/getSchoolInfoByDeptId")
    public CommonResult getSchoolInfoByDeptId()
    {
        Long userId = SecurityFrameworkUtils.getLoginUserId();
        AdminUserRespDTO sysUser = userApi.getUser(userId);
        Long deptId = sysUser.getDeptId();
        return success(driveSchoolInfoService.getSchoolInfoByDeptId(deptId));
    }

    /**
     * 新增驾校信息
     */
    //@Log(title = "驾校信息", businessType = BusinessType.INSERT)
    @PostMapping
    public CommonResult add(@RequestBody DriveSchoolInfo driveSchoolInfo)
    {
        return driveSchoolInfoService.insertDriveSchoolInfo(driveSchoolInfo);
    }

    /**
     * 修改驾校信息
     */
    //@Log(title = "驾校信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public CommonResult edit(@RequestBody DriveSchoolInfo driveSchoolInfo)
    {
        return toAjax(driveSchoolInfoService.updateDriveSchoolInfo(driveSchoolInfo));
    }

    /**
     * 删除驾校信息
     */
    //@Log(title = "驾校信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public CommonResult remove(@PathVariable Long[] ids)
    {
        return toAjax(driveSchoolInfoService.deleteDriveSchoolInfoByIds(ids));
    }
}
