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.BaseSubentryType;
import com.hw.ems.base.service.IBaseSubentryTypeService;
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-06
 */
@RestController
@RequestMapping("/subentryType")
public class BaseSubentryTypeController extends BaseController
{
    @Autowired
    private IBaseSubentryTypeService baseSubentryTypeService;

    /**
     * 查询分项类型管理列表
     */
    @RequiresPermissions("base:subentryType:list")
    @GetMapping("/list")
    public AjaxResult list(BaseSubentryType baseSubentryType)
    {
        List<BaseSubentryType> list = baseSubentryTypeService.selectBaseSubentryTypeList(baseSubentryType);
        return success(list);
    }

    /**
     * 导出分项类型管理列表
     */
    @RequiresPermissions("base:subentryType:export")
    @Log(title = "分项类型管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseSubentryType baseSubentryType)
    {
        List<BaseSubentryType> list = baseSubentryTypeService.selectBaseSubentryTypeList(baseSubentryType);
        ExcelUtil<BaseSubentryType> util = new ExcelUtil<BaseSubentryType>(BaseSubentryType.class);
        util.exportExcel(response, list, "分项类型管理数据");
    }

    /**
     * 获取分项类型管理详细信息
     */
    @RequiresPermissions("base:subentryType:query")
    @GetMapping(value = "/{objid}")
    public AjaxResult getInfo(@PathVariable("objid") Long objid)
    {
        return success(baseSubentryTypeService.selectBaseSubentryTypeByObjid(objid));
    }

    /**
     * 新增分项类型管理
     */
    @RequiresPermissions("base:subentryType:add")
    @Log(title = "分项类型管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseSubentryType baseSubentryType)
    {
        return toAjax(baseSubentryTypeService.insertBaseSubentryType(baseSubentryType));
    }

    /**
     * 修改分项类型管理
     */
    @RequiresPermissions("base:subentryType:edit")
    @Log(title = "分项类型管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseSubentryType baseSubentryType)
    {
        return toAjax(baseSubentryTypeService.updateBaseSubentryType(baseSubentryType));
    }

    /**
     * 删除分项类型管理
     */
    @RequiresPermissions("base:subentryType:remove")
    @Log(title = "分项类型管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{objids}")
    public AjaxResult remove(@PathVariable Long[] objids)
    {
        return toAjax(baseSubentryTypeService.deleteBaseSubentryTypeByObjids(objids));
    }
    /**
     * 加载分项类型管理树列表
     */
    @GetMapping("/treeData")
    @ResponseBody
    public List<Ztree> treeData()
    {
        List<Ztree> ztrees = baseSubentryTypeService.selectBaseSubentryTypeTree();
        return ztrees;
    }
}
