package com.hw.ems.base.controller;

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

import com.hw.common.core.domain.Ztree;

import com.hw.ems.base.domain.BaseBusinessType;
import com.hw.ems.base.service.IBaseBusinessTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.hw.common.log.annotation.Log;
import com.hw.common.log.enums.BusinessType;
import com.hw.common.security.annotation.RequiresPermissions;
import com.hw.common.core.web.controller.BaseController;
import com.hw.common.core.web.domain.AjaxResult;
import com.hw.common.core.utils.poi.ExcelUtil;

/**
 * 业态类型管理Controller
 *
 * @author YinQ
 * @date 2023-05-05
 */
@RestController
@RequestMapping("/businessType")
public class BaseBusinessTypeController extends BaseController {
    @Autowired
    private IBaseBusinessTypeService baseBusinessTypeService;

    /**
     * 查询业态类型管理列表
     */
    @RequiresPermissions("base:businessType:list")
    @GetMapping("/list")
    public AjaxResult list(BaseBusinessType baseBusinessType) {
        List<BaseBusinessType> list = baseBusinessTypeService.selectBaseBusinessTypeList(baseBusinessType);
        return success(list);
    }

    /**
     * 导出业态类型管理列表
     */
    @RequiresPermissions("base:businessType:export")
    @Log(title = "业态类型管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseBusinessType baseBusinessType) {
        List<BaseBusinessType> list = baseBusinessTypeService.selectBaseBusinessTypeList(baseBusinessType);
        ExcelUtil<BaseBusinessType> util = new ExcelUtil<BaseBusinessType>(BaseBusinessType.class);
        util.exportExcel(response, list, "业态类型管理数据");
    }

    /**
     * 获取业态类型管理详细信息
     */
    @RequiresPermissions("base:businessType:query")
    @GetMapping(value = "/{objid}")
    public AjaxResult getInfo(@PathVariable("objid") Long objid) {
        return success(baseBusinessTypeService.selectBaseBusinessTypeByObjid(objid));
    }

    /**
     * 新增业态类型管理
     */
    @RequiresPermissions("base:businessType:add")
    @Log(title = "业态类型管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseBusinessType baseBusinessType) {
        return toAjax(baseBusinessTypeService.insertBaseBusinessType(baseBusinessType));
    }

    /**
     * 修改业态类型管理
     */
    @RequiresPermissions("base:businessType:edit")
    @Log(title = "业态类型管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseBusinessType baseBusinessType) {
        return toAjax(baseBusinessTypeService.updateBaseBusinessType(baseBusinessType));
    }

    /**
     * 删除业态类型管理
     */
    @RequiresPermissions("base:businessType:remove")
    @Log(title = "业态类型管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{objids}")
    public AjaxResult remove(@PathVariable Long[] objids) {
        return toAjax(baseBusinessTypeService.deleteBaseBusinessTypeByObjids(objids));
    }

    /**
     * 加载业态类型管理树列表
     */
    @GetMapping("/treeData")
    @ResponseBody
    public List<Ztree> treeData() {
        List<Ztree> ztrees = baseBusinessTypeService.selectBaseBusinessTypeTree();
        return ztrees;
    }
}
