package com.dgtly.web.controller.people;

import java.util.List;
import java.util.Map;

import com.dgtly.framework.util.ShiroUtils;
import com.dgtly.system.domain.SysUser;
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.dgtly.common.annotation.Log;
import com.dgtly.common.enums.BusinessType;
import com.dgtly.system.domain.EntryPass;
import com.dgtly.system.service.IEntryPassService;
import com.dgtly.common.core.controller.BaseController;
import com.dgtly.common.core.domain.AjaxResult;
import com.dgtly.common.utils.poi.ExcelUtil;
import com.dgtly.common.core.page.TableDataInfo;

/**
 * 出入证Controller
 * 
 * @author dgtly
 * @date 2020-02-15
 */
@Controller
@RequestMapping("/people/pass")
public class EntryPassController extends BaseController
{
    private String prefix = "system/people/pass";

    @Autowired
    private IEntryPassService entryPassService;

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

    /**
     * 查询出入证列表
     */
    @RequiresPermissions("people:pass:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(EntryPass entryPass)
    {
        startPage();
        List<EntryPass> list = entryPassService.selectEntryPassList(entryPass);
        return getDataTable(list);
    }


    /**
     * 修改出入证
     */
    @GetMapping("/edit/{userId}")
    public String edit(@PathVariable("userId") Long userId, ModelMap mmap)
    {
        EntryPass entryPass = entryPassService.selectEntryPassByUserId(userId);
        mmap.put("entryPass", entryPass);
        return prefix + "/edit";
    }

    /**
     * 修改保存出入证
     */
    @RequiresPermissions("people:pass:edit")
    @Log(title = "出入证", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(EntryPass entryPass)
    {
        return toAjax(entryPassService.updateEntryPass(entryPass));
    }

    /**
     * 获取出入证待审批列表
     * @return
     */
    @PostMapping("/checkPass")
    @ResponseBody
    public AjaxResult checkPass(EntryPass entryPass){

        int i  = entryPassService.updateEntryPass(entryPass);
        if(i>0){
            return success();
        }
        return error();
    }

}
