package com.zbf.web.controller.system;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

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.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zbf.common.annotation.Log;
import com.zbf.common.core.controller.BaseController;
import com.zbf.common.core.domain.AjaxResult;
import com.zbf.common.core.page.TableDataInfo;
import com.zbf.common.enums.BusinessType;
import com.zbf.common.utils.poi.ExcelUtil;
import com.zbf.system.domain.SysUserBusinessColumn;
import com.zbf.system.service.ISysUserBusinessColumnService;

/**
 * 用户展示字段定义管理Controller
 *
 * @author tony
 * @date 2024-06-16
 */
@RestController
@RequestMapping("/system/COLUMN")
public class SysUserBusinessColumnController extends BaseController
{
    @Autowired
    private ISysUserBusinessColumnService sysUserBusinessColumnService;

/**
 * 查询用户展示字段定义管理列表
 */
@GetMapping("/list")
    public TableDataInfo list(SysUserBusinessColumn sysUserBusinessColumn)
    {
        startPage();
        List<SysUserBusinessColumn> list = sysUserBusinessColumnService.selectSysUserBusinessColumnList(sysUserBusinessColumn);
        return getDataTable(list);
    }

    /**
     * 导出用户展示字段定义管理列表
     */
    @Log(title = "用户展示字段定义管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysUserBusinessColumn sysUserBusinessColumn)
    {
        List<SysUserBusinessColumn> list = sysUserBusinessColumnService.selectSysUserBusinessColumnList(sysUserBusinessColumn);
        ExcelUtil<SysUserBusinessColumn> util = new ExcelUtil<SysUserBusinessColumn>(SysUserBusinessColumn.class);
        util.exportExcel(response, list, "用户展示字段定义管理数据");
    }

    /**
     * 获取用户展示字段定义管理详细信息
     */
    @GetMapping(value = "/{ID}")
    public AjaxResult getInfo(@PathVariable("ID") Long ID)
    {
        return success(sysUserBusinessColumnService.selectSysUserBusinessColumnByID(ID));
    }

    /**
     * 新增用户展示字段定义管理
     */
    @Log(title = "用户展示字段定义管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysUserBusinessColumn sysUserBusinessColumn)
    {
        return toAjax(sysUserBusinessColumnService.insertSysUserBusinessColumn(sysUserBusinessColumn));
    }

    /**
     * 修改用户展示字段定义管理
     */
    @Log(title = "用户展示字段定义管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysUserBusinessColumn sysUserBusinessColumn)
    {
        String userName = getLoginUser().getUsername();
        String hideColumn = sysUserBusinessColumn.getColumnHide();
        sysUserBusinessColumn.setColumnHide("");
        sysUserBusinessColumn.setUserName(userName);
        List<SysUserBusinessColumn> result = sysUserBusinessColumnService.selectSysUserBusinessColumnList(sysUserBusinessColumn);

        if (result.size() == 0) {
            sysUserBusinessColumn.setColumnHide(hideColumn);
            return toAjax(sysUserBusinessColumnService.insertSysUserBusinessColumn(sysUserBusinessColumn));
        }
        SysUserBusinessColumn updateRecord = result.get(0);
        updateRecord.setColumnHide(hideColumn);
        return toAjax(sysUserBusinessColumnService.updateSysUserBusinessColumn(updateRecord));
    }

    /**
     * 删除用户展示字段定义管理
     */
    @Log(title = "用户展示字段定义管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{IDs}")
    public AjaxResult remove(@PathVariable Long[] IDs)
    {
        return toAjax(sysUserBusinessColumnService.deleteSysUserBusinessColumnByIDs(IDs));
    }

    /**
     * 启用
     */
    @Log(title = "用户展示字段定义管理", businessType = BusinessType.UPDATE)
    @DeleteMapping("/disable/{IDs}")
    public AjaxResult disable(@PathVariable Long[] IDs)
    {
        return toAjax(sysUserBusinessColumnService.disabledSysUserBusinessColumnByIDs(IDs));
    }

    /**
     * 禁用
     */
    @Log(title = "用户展示字段定义管理", businessType = BusinessType.UPDATE)
    @DeleteMapping("/enable/{IDs}")
    public AjaxResult enable(@PathVariable Long[] IDs)
    {
        return toAjax(sysUserBusinessColumnService.enableSysUserBusinessColumnByIDs(IDs));
    }

    /**
     * 修改状态
     */
    @Log(title = "用户展示字段定义管理", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody SysUserBusinessColumn sysUserBusinessColumn) {
        return toAjax(sysUserBusinessColumnService.updateStatus(sysUserBusinessColumn));
    }

}

