package com.willalp.web.controller.system;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.willalp.common.annotation.Log;
import com.willalp.common.constant.UserConstants;
import com.willalp.common.core.controller.BaseController;
import com.willalp.common.core.domain.AjaxResult;
import com.willalp.common.core.domain.entity.SysUser;
import com.willalp.common.core.page.TableDataInfo;
import com.willalp.common.enums.BusinessType;
import com.willalp.common.exception.base.BaseException;
import com.willalp.common.utils.DateUtils;
import com.willalp.common.utils.SecurityUtils;
import com.willalp.common.utils.poi.ExcelUtil;
import com.willalp.system.domain.SysCardInfo;
import com.willalp.system.service.ISysCardInfoService;
import com.willalp.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 卡片用户信息Controller
 *
 * @author willalp
 * @date 2021-11-30
 */
@RestController
@RequestMapping("/system/info")
public class SysCardInfoController extends BaseController {
    @Autowired
    private ISysCardInfoService sysCardInfoService;

    @Autowired
    private ISysUserService iSysUserService;

    /**
     * 查询卡片用户信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysCardInfo sysCardInfo)
    {
        startPage();
        List<SysCardInfo> list = sysCardInfoService.selectSysCardInfoList(sysCardInfo);
        return getDataTable(list);
    }

    /**
     * 导出卡片用户信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:export')")
    @Log(title = "卡片用户信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysCardInfo sysCardInfo)
    {
        List<SysCardInfo> list = sysCardInfoService.selectSysCardInfoList(sysCardInfo);
        ExcelUtil<SysCardInfo> util = new ExcelUtil<SysCardInfo>(SysCardInfo.class);
        return util.exportExcel(list, "卡片用户信息数据");
    }

    /**
     * 获取卡片用户信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(sysCardInfoService.getById(id));
    }

    /**
     * 新增卡片用户信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:add')")
    @Log(title = "卡片用户信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysCardInfo sysCardInfo) {
        sysCardInfoService.saveInfo(sysCardInfo);
        return AjaxResult.success();
    }

    /**
     * 修改卡片用户信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:edit')")
    @Log(title = "卡片用户信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysCardInfo sysCardInfo) {
        sysCardInfoService.updateInfoById(sysCardInfo);
        return AjaxResult.success();
    }

    /**
     * 删除卡片用户信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:remove')")
    @Log(title = "卡片用户信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(sysCardInfoService.removeByIds(Arrays.asList(ids)));
    }
}
