package com.sooka.system.controller;

import java.util.List;

import com.sooka.common.core.controller.BaseController;
import com.sooka.common.core.domain.AjaxResult;
import com.sooka.common.core.page.TableDataInfo;
import com.sooka.common.enums.BusinessType;
import com.sooka.common.utils.poi.ExcelUtil;
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.sooka.common.annotation.Log;
import com.sooka.system.domain.TgjjDkxx;
import com.sooka.system.service.ITgjjDkxxService;

/**
 * 个人贷款信息Controller
 * 
 * @author lei
 * @date 2021-11-16
 */
@Controller
@RequestMapping("/system/dkxx")
public class TgjjDkxxController extends BaseController
{
    private String prefix = "system/dkxx";

    @Autowired
    private ITgjjDkxxService tgjjDkxxService;

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

    /**
     * 查询个人贷款信息列表
     */
    @RequiresPermissions("system:dkxx:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TgjjDkxx tgjjDkxx)
    {
        startPage();
        List<TgjjDkxx> list = tgjjDkxxService.selectTgjjDkxxList(tgjjDkxx);
        return getDataTable(list);
    }

    /**
     * 导出个人贷款信息列表
     */
    @RequiresPermissions("system:dkxx:export")
    @Log(title = "个人贷款信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TgjjDkxx tgjjDkxx)
    {
        List<TgjjDkxx> list = tgjjDkxxService.selectTgjjDkxxList(tgjjDkxx);
        ExcelUtil<TgjjDkxx> util = new ExcelUtil<TgjjDkxx>(TgjjDkxx.class);
        return util.exportExcel(list, "dkxx");
    }

    /**
     * 新增个人贷款信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存个人贷款信息
     */
    @RequiresPermissions("system:dkxx:add")
    @Log(title = "个人贷款信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TgjjDkxx tgjjDkxx)
    {
        return toAjax(tgjjDkxxService.insertTgjjDkxx(tgjjDkxx));
    }

    /**
     * 修改个人贷款信息
     */
    @GetMapping("/edit/{ID}")
    public String edit(@PathVariable("ID") Long ID, ModelMap mmap)
    {
        TgjjDkxx tgjjDkxx = tgjjDkxxService.selectTgjjDkxxById(ID);
        mmap.put("tgjjDkxx", tgjjDkxx);
        return prefix + "/edit";
    }

    /**
     * 修改保存个人贷款信息
     */
    @RequiresPermissions("system:dkxx:edit")
    @Log(title = "个人贷款信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TgjjDkxx tgjjDkxx)
    {
        return toAjax(tgjjDkxxService.updateTgjjDkxx(tgjjDkxx));
    }

    /**
     * 删除个人贷款信息
     */
    @RequiresPermissions("system:dkxx:remove")
    @Log(title = "个人贷款信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tgjjDkxxService.deleteTgjjDkxxByIds(ids));
    }
}
