package com.jeethink.using.controller;

import com.jeethink.bean.domain.ArchivesMaster;
import com.jeethink.common.core.controller.BaseController;
import com.jeethink.common.core.domain.AjaxResult;
import com.jeethink.common.core.page.TableDataInfo;
import com.jeethink.using.domain.ArchivesBorrow;
import com.jeethink.using.service.IBorrowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/using/borrow")
public class BorrowController extends BaseController {

    @Autowired
    private IBorrowService service;

    @GetMapping("/list")
    public TableDataInfo list(ArchivesMaster archives) {

        startPage();
        List<ArchivesMaster> list = service.selectArchivesList(archives);
        return getDataTable(list);
    }

    @PostMapping
    public AjaxResult apply(@RequestBody ArchivesBorrow borrow) {

        service.applyBorrow(borrow);
        return AjaxResult.success();
    }

    @GetMapping("/my")
    public TableDataInfo myBorrow(ArchivesBorrow borrow) {

        startPage();
        List<ArchivesBorrow> list = service.selectMyBorrowList(borrow);
        return getDataTable(list);
    }

    @GetMapping("/revocation")
    public AjaxResult revocation(@RequestParam String borrowId) {

        service.revocationBorrow(borrowId);
        return AjaxResult.success();
    }

    @GetMapping("/info")
    public AjaxResult borrowInfo(@RequestParam String borrowId) {

        return AjaxResult.success(service.selectById(borrowId));
    }

    @GetMapping("/history")
    public TableDataInfo history(ArchivesBorrow borrow) {

        startPage();
        List<ArchivesBorrow> list = service.selectBorrowHistory(borrow);
        return getDataTable(list);
    }

    @GetMapping("/reback")
    public AjaxResult reback(@RequestParam String borrowId) {

        service.reback(borrowId);
        return AjaxResult.success();
    }

    @GetMapping("/cancelback")
    public AjaxResult cancelback(@RequestParam String borrowId) {

        service.cancelReback(borrowId);
        return AjaxResult.success();
    }
}
