package com.ktg.iscs.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ktg.common.annotation.Log;
import com.ktg.common.core.controller.BaseController;
import com.ktg.common.enums.BusinessType;
import com.ktg.common.pojo.CommonResult;
import com.ktg.common.utils.poi.ExcelUtil;
import com.ktg.iscs.domain.IsMaterialsLoan;
import com.ktg.iscs.domain.dto.materialsLoan.MaterialsLoanPageDTO;
import com.ktg.iscs.domain.dto.materialsLoan.ReminderPageDTO;
import com.ktg.iscs.domain.vo.materialsLoan.MaterialsLoanPageVO;
import com.ktg.iscs.domain.vo.materialsLoan.ReminderPageVO;
import com.ktg.iscs.service.IIsMaterialsLoanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
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 cgj
 * @date 2024-11-08
 */
@Api(tags = "物资借出")
@RestController
@RequestMapping("/iscs/loan")
public class IsMaterialsLoanController extends BaseController
{
    @Autowired
    private IIsMaterialsLoanService isMaterialsLoanService;

    @ApiOperation("查询物资借出-分页")
    @Parameters({
            @Parameter(name = "page", description = "Page"),
            @Parameter(name = "dto", description = "实体参数")
    })
    @PreAuthorize("@ss.hasPermi('iscs:loan:list')")
    @GetMapping("/getIsMaterialsLoanPage")
    public CommonResult<Page<MaterialsLoanPageVO>> getIsMaterialsLoanPage(Page<IsMaterialsLoan> page, MaterialsLoanPageDTO dto)
    {
        Page<MaterialsLoanPageVO> result = isMaterialsLoanService.getIsMaterialsLoanPage(page, dto);
        return CommonResult.success(result);
    }

    @ApiOperation("导出物资借出列表")
    @Parameter(name = "isMaterialsLoan", description = "实体参数")
    @PreAuthorize("@ss.hasPermi('iscs:loan:export')")
    @Log(title = "物资借出", businessType = BusinessType.EXPORT)
    @PostMapping("/exportIsMaterialsLoan")
    public void exportIsMaterialsLoan(HttpServletResponse response, IsMaterialsLoan isMaterialsLoan)
    {
        List<IsMaterialsLoan> list = isMaterialsLoanService.selectIsMaterialsLoanList(isMaterialsLoan);
        ExcelUtil<IsMaterialsLoan> util = new ExcelUtil<IsMaterialsLoan>(IsMaterialsLoan.class);
        util.exportExcel(response, list, "物资借出数据");
    }

    @ApiOperation("获取物资借出详细信息")
    @Parameter(name = "materialsLoanId", description = "materialsLoanId")
    @PreAuthorize("@ss.hasPermi('iscs:loan:query')")
    @GetMapping(value = "/selectIsMaterialsLoanById")
    public CommonResult<IsMaterialsLoan> selectIsMaterialsLoanById(Long materialsLoanId)
    {
        return CommonResult.success(isMaterialsLoanService.selectIsMaterialsLoanByMaterialsLoanId(materialsLoanId));
    }


    /*@ApiOperation("新增物资借出")
    @PreAuthorize("@ss.hasPermi('iscs:loan:add')")
    @Log(title = "物资借出", businessType = BusinessType.INSERT)
    @PostMapping("/insertIsMaterialsLoan")
    public CommonResult<Boolean> insertIsMaterialsLoan(@RequestBody @Parameter(name = "dto", description = "新增数据类,放到body") AddLoanDTO dto)
    {
        return CommonResult.success(isMaterialsLoanService.insertIsMaterialsLoan(dto) == 1);
    }*/

    /*@ApiOperation("物资归还")
    @PreAuthorize("@ss.hasPermi('iscs:loan:edit')")
    @Log(title = "物资归还", businessType = BusinessType.INSERT)
    @PostMapping("/returnIsMaterialsLoan")
    public CommonResult<Boolean> returnIsMaterialsLoan(@RequestBody @Parameter(name = "dto", description = "新增数据类,放到body") ReturnLoanDTO dto)
    {
        return CommonResult.success(isMaterialsLoanService.returnIsMaterialsLoan(dto));
    }*/

    /**
     * 修改物资借出
     */
    @ApiOperation("修改物资借出")
    @PreAuthorize("@ss.hasPermi('iscs:loan:edit')")
    @Log(title = "物资借出", businessType = BusinessType.UPDATE)
    @PostMapping("/updateIsMaterialsLoan")
    public CommonResult<Boolean> updateIsMaterialsLoan(@RequestBody @Parameter(name = "isMaterialsLoan", description = "修改数据类,放到body") IsMaterialsLoan isMaterialsLoan)
    {
        return CommonResult.success(isMaterialsLoanService.updateIsMaterialsLoan(isMaterialsLoan) == 1);
    }

    /**
     * 删除物资借出
     */
    @ApiOperation("删除物资借出")
    @PreAuthorize("@ss.hasPermi('iscs:loan:remove')")
    @Log(title = "删除物资借出", businessType = BusinessType.DELETE)
	@PostMapping("/deleteIsMaterialsLoanByMaterialsLoanIds")
    public CommonResult<Boolean> deleteIsMaterialsLoanByMaterialsLoanIds(String materialsLoanIds)
    {
        return CommonResult.success(isMaterialsLoanService.deleteIsMaterialsLoanByMaterialsLoanIds(materialsLoanIds) != 0);
    }

    @ApiOperation("归还提醒-分页")
    @Parameters({
            @Parameter(name = "page", description = "Page"),
            @Parameter(name = "dto", description = "实体参数")
    })
    @PreAuthorize("@ss.hasPermi('iscs:loan:return')")
    @GetMapping("/getReturnReminderPage")
    public CommonResult<Page<ReminderPageVO>> getReturnReminderPage(Page<IsMaterialsLoan> page, ReminderPageDTO dto)
    {
        Page<ReminderPageVO> result = isMaterialsLoanService.getReturnReminderPage(page, dto);
        return CommonResult.success(result);
    }

    @ApiOperation("过期提醒-分页")
    @Parameters({
            @Parameter(name = "page", description = "Page"),
            @Parameter(name = "dto", description = "实体参数")
    })
    @PreAuthorize("@ss.hasPermi('iscs:loan:expired')")
    @GetMapping("/getExpiredReminderPage")
    public CommonResult<Page<ReminderPageVO>> getReminderPage(Page<IsMaterialsLoan> page, ReminderPageDTO dto)
    {
        Page<ReminderPageVO> result = isMaterialsLoanService.getExpiredReminderPage(page, dto);
        return CommonResult.success(result);
    }

}
