package com.ruoyi.manage.controller;

import java.util.List;

import com.ruoyi.manage.domain.ResultBeen;
import com.ruoyi.system.service.ISysConfigService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.manage.domain.LedgerRfid;
import com.ruoyi.manage.service.ILedgerRfidService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 轮挡台账Controller
 *
 * @author wangh
 * @date 2024-01-17
 */
@Controller
@RequestMapping("/manage/ledger_rfid")
public class LedgerRfidController extends BaseController {
    private String prefix = "manage/ledger_rfid";

    @Autowired
    private ILedgerRfidService ledgerRfidService;

    @Autowired
    private ISysConfigService configService;

    @RequiresPermissions("manage:ledger_rfid:view")
    @GetMapping()
    public String ledger_rfid() {
        return prefix + "/ledger_rfid";
    }

    @GetMapping("/count")
    public String count() {
        return prefix + "/count";
    }

    /**
     * 查询轮挡台账列表
     */
    @RequiresPermissions("manage:ledger_rfid:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(LedgerRfid ledgerRfid) {
        startPage();
        List<LedgerRfid> list = ledgerRfidService.selectLedgerRfidList(ledgerRfid);
        return getDataTable(list);
    }

    /**
     * 导出轮挡台账列表
     */
    @RequiresPermissions("manage:ledger_rfid:export")
    @Log(title = "轮挡台账", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(LedgerRfid ledgerRfid) {
        List<LedgerRfid> list = ledgerRfidService.selectLedgerRfidList(ledgerRfid);
        ExcelUtil<LedgerRfid> util = new ExcelUtil<LedgerRfid>(LedgerRfid.class);
        return util.exportExcel(list, "轮挡台账数据");
    }

    /**
     * 新增轮挡台账
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存轮挡台账
     */
    @RequiresPermissions("manage:ledger_rfid:add")
    @Log(title = "轮挡台账", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(LedgerRfid ledgerRfid) {
        return toAjax(ledgerRfidService.insertLedgerRfid(ledgerRfid));
    }

    /**
     * 修改轮挡台账
     */
    @RequiresPermissions("manage:ledger_rfid:edit")
    @GetMapping("/edit/{objid}")
    public String edit(@PathVariable("objid") Long objid, ModelMap mmap) {
        LedgerRfid ledgerRfid = ledgerRfidService.selectLedgerRfidByObjid(objid);
        mmap.put("ledgerRfid", ledgerRfid);
        return prefix + "/edit";
    }

    /**
     * 修改保存轮挡台账
     */
    @RequiresPermissions("manage:ledger_rfid:edit")
    @Log(title = "轮挡台账", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(LedgerRfid ledgerRfid) {
        return toAjax(ledgerRfidService.updateLedgerRfid(ledgerRfid));
    }

    /**
     * 删除轮挡台账
     */
    @RequiresPermissions("manage:ledger_rfid:remove")
    @Log(title = "轮挡台账", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(ledgerRfidService.deleteLedgerRfidByObjids(ids));
    }

    @RequiresPermissions("manage:ledger_rfid:list")
    @PostMapping("/selectWasteNumber")
    @ResponseBody
    public AjaxResult selectWasteNumber() {
        int number = ledgerRfidService.countWasteNumber();
        int s = Integer.parseInt(configService.selectConfigByKey("manage.selectWasteNumber"));
        System.out.println("设定数量="+configService.selectConfigByKey("manage.selectWasteNumber"));
        if (number>=s){
            return success(number);
        }
        return error();
    }

  @PostMapping("/countRfid")
    @ResponseBody
    public AjaxResult countRfid() {
        List<ResultBeen> list=ledgerRfidService.countRfid();
        return success(list);
    }


}
