package com.goldenwater.web.controller.system;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
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.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.goldenwater.common.annotation.Log;
import com.goldenwater.common.core.controller.BaseController;
import com.goldenwater.common.core.domain.AjaxResult;
import com.goldenwater.common.core.page.TableDataInfo;
import com.goldenwater.common.enums.BusinessType;
import com.goldenwater.system.domain.SysRoleApperFor;
import com.goldenwater.system.service.ISysRoleApperForService;

/**
 * 注册审批 操作处理
 * 
 * @author goldenwater
 */
@RestController
@RequestMapping("/system/role/apper/for")
public class SysRoleApperForController extends BaseController
{
    @Autowired
    private ISysRoleApperForService sysRoleApperForService;

    /**
     * 查询注册审批列表
     */
    @PreAuthorize("@ss.hasPermi('system:apper:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysRoleApperFor sysRoleApperFor)
    {
        startPage();
        List<SysRoleApperFor> list = sysRoleApperForService.selectList(sysRoleApperFor);
        return getDataTable(list);
    }

    /**
     * 获取注册审批详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:apper:list')")
    @GetMapping(value = "/{apperId}")
    public AjaxResult getInfo(@PathVariable String apperId)
    {
        return success(sysRoleApperForService.selectById(apperId));
    }

    /**
     * 审批通过
     */
    @PreAuthorize("@ss.hasPermi('system:apper:approve')")
    @Log(title = "注册审批", businessType = BusinessType.UPDATE)
    @PutMapping("/approve")
    public AjaxResult approve(@RequestParam String apperId)
    {
        return toAjax(sysRoleApperForService.updatePass(apperId, "7"));
    }

    /**
     * 审批驳回
     */
    @PreAuthorize("@ss.hasPermi('system:apper:approve')")
    @Log(title = "注册审批", businessType = BusinessType.UPDATE)
    @PutMapping("/reject")
    public AjaxResult reject(@RequestParam String apperId)
    {
        return toAjax(sysRoleApperForService.updatePass(apperId, "1"));
    }

    /**
     * 锁定/解锁账号
     */
    @PreAuthorize("@ss.hasPermi('system:apper:block')")
    @Log(title = "注册审批", businessType = BusinessType.UPDATE)
    @PutMapping("/block")
    public AjaxResult block(@RequestParam String apperId, @RequestParam Boolean block)
    {
        return toAjax(sysRoleApperForService.blockAccount(apperId, block));
    }

    /**
     * 根据登录名查询用户类型
     */
    @PreAuthorize("@ss.hasPermi('system:apper:list')")
    @GetMapping("/getUserType")
    public AjaxResult getUserType(@RequestParam String userName)
    {
        return success(sysRoleApperForService.getUserType(userName));
    }

    /**
     * 创建账号
     */
    @PreAuthorize("@ss.hasPermi('system:apper:create')")
    @Log(title = "注册审批", businessType = BusinessType.INSERT)
    @PostMapping("/createAccount")
    public AjaxResult createAccount(@RequestParam String apperId, @RequestParam String password)
    {
        return toAjax(sysRoleApperForService.createAccount(apperId, password));
    }

    /**
     * 删除注册审批
     */
    @PreAuthorize("@ss.hasPermi('system:apper:list')")
    @Log(title = "注册审批", businessType = BusinessType.DELETE)
    @DeleteMapping("/{apperId}")
    public AjaxResult remove(@PathVariable String apperId)
    {
        return toAjax(sysRoleApperForService.deleteById(apperId));
    }
}
