package com.bonus.zlpt.equip.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.bonus.zlpt.common.core.utils.poi.ExcelUtil;
import com.bonus.zlpt.common.core.web.controller.BaseController;
import com.bonus.zlpt.common.core.web.domain.AjaxResult;
import com.bonus.zlpt.common.core.web.page.TableDataInfo;
import com.bonus.zlpt.common.log.annotation.Log;
import com.bonus.zlpt.common.log.enums.BusinessType;
import com.bonus.zlpt.common.security.annotation.RequiresPermissions;
import com.bonus.zlpt.equip.api.domain.LeaseInfo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.bonus.zlpt.equip.service.ILeaseInfoService;

/**
 * 租赁信息Controller
 * 
 * @author xsheng
 * @date 2023-12-02
 */
@Api(tags = "装备租赁数据接口")
@RestController
@RequestMapping("/lease")
public class LeaseInfoController extends BaseController
{
    @Autowired
    private ILeaseInfoService leaseInfoService;

    /**
     * 查询租赁信息列表
     */
    @RequiresPermissions("equip:info:list")
    @GetMapping("/list")
    public TableDataInfo list(LeaseInfo leaseInfo)
    {
        startPage();
        List<LeaseInfo> list = leaseInfoService.selectLeaseInfoList(leaseInfo);
        return getDataTable(list);
    }

    /**
     * 导出租赁信息列表
     */
    @RequiresPermissions("equip:info:export")
    @Log(title = "租赁信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LeaseInfo leaseInfo)
    {
        List<LeaseInfo> list = leaseInfoService.selectLeaseInfoList(leaseInfo);
        ExcelUtil<LeaseInfo> util = new ExcelUtil<LeaseInfo>(LeaseInfo.class);
        util.exportExcel(response, list, "租赁信息数据");
    }

    /**
     * 获取租赁信息详细信息
     */
    @RequiresPermissions("equip:info:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(leaseInfoService.selectLeaseInfoById(id));
    }

    /**
     * 新增租赁信息
     */
    @RequiresPermissions("equip:info:add")
    @Log(title = "租赁信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LeaseInfo leaseInfo)
    {
        return toAjax(leaseInfoService.insertLeaseInfo(leaseInfo));
    }

    /**
     * 修改租赁信息
     */
    @RequiresPermissions("equip:info:edit")
    @Log(title = "租赁信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LeaseInfo leaseInfo)
    {
        return toAjax(leaseInfoService.updateLeaseInfo(leaseInfo));
    }

    /**
     * 删除租赁信息
     */
    @RequiresPermissions("equip:info:remove")
    @Log(title = "租赁信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(leaseInfoService.deleteLeaseInfoByIds(ids));
    }
}
