package com.ruoyi.szxc.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.szxc.domain.SzxcBankcardInfo;
import com.ruoyi.szxc.service.ISzxcBankcardInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 银行卡信息Controller
 * 
 * @author hs
 * @date 2024-03-15
 */
@RestController
@RequestMapping("/szxc/bankinfo")
public class SzxcBankcardInfoController extends BaseController
{
    @Autowired
    private ISzxcBankcardInfoService szxcBankcardInfoService;

    /**
     * 查询银行卡信息列表
     */
    @PreAuthorize("@ss.hasPermi('szxc:bankinfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(SzxcBankcardInfo szxcBankcardInfo)
    {
        startPage();
        List<SzxcBankcardInfo> list = szxcBankcardInfoService.selectSzxcBankcardInfoList(szxcBankcardInfo);
        return getDataTable(list);
    }

    /**
     * 导出银行卡信息列表
     */
    @PreAuthorize("@ss.hasPermi('szxc:bankinfo:export')")
    @Log(title = "银行卡信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SzxcBankcardInfo szxcBankcardInfo)
    {
        List<SzxcBankcardInfo> list = szxcBankcardInfoService.selectSzxcBankcardInfoList(szxcBankcardInfo);
        ExcelUtil<SzxcBankcardInfo> util = new ExcelUtil<SzxcBankcardInfo>(SzxcBankcardInfo.class);
        util.exportExcel(response, list, "银行卡信息数据");
    }

    /**
     * 获取银行卡信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('szxc:bankinfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(szxcBankcardInfoService.selectSzxcBankcardInfoById(id));
    }

    /**
     * 新增银行卡信息
     */
    @PreAuthorize("@ss.hasPermi('szxc:bankinfo:add')")
    @Log(title = "银行卡信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SzxcBankcardInfo szxcBankcardInfo)
    {
        //根据前端传递过来的部门存储，如果没传则存储当前用户的部门
        if(szxcBankcardInfo.getDeptId()==null){
            szxcBankcardInfo.setDeptId(getDeptId());
        }
        szxcBankcardInfo.setUserId(getUserId());
        return toAjax(szxcBankcardInfoService.insertSzxcBankcardInfo(szxcBankcardInfo));
    }

    /**
     * 修改银行卡信息
     */
    @PreAuthorize("@ss.hasPermi('szxc:bankinfo:edit')")
    @Log(title = "银行卡信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SzxcBankcardInfo szxcBankcardInfo)
    {
        return toAjax(szxcBankcardInfoService.updateSzxcBankcardInfo(szxcBankcardInfo));
    }
    /**
     * 修改默认银行卡接口
     */
    @PreAuthorize("@ss.hasPermi('szxc:bankinfo:edit')")
    @Log(title = "银行卡信息", businessType = BusinessType.UPDATE)
    @PutMapping("/editDefault")
    public AjaxResult editDefault(@RequestBody SzxcBankcardInfo szxcBankcardInfo)
    {
        return toAjax(szxcBankcardInfoService.updateSzxcBankcardInfo2(szxcBankcardInfo));
    }

    /**
     * 删除银行卡信息
     */
    @PreAuthorize("@ss.hasPermi('szxc:bankinfo:remove')")
    @Log(title = "银行卡信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(szxcBankcardInfoService.deleteSzxcBankcardInfoByIds(ids));
    }
}
