package com.zhyc.module.base.controller;

import com.zhyc.common.annotation.Log;
import com.zhyc.common.core.controller.BaseController;
import com.zhyc.common.core.domain.AjaxResult;
import com.zhyc.common.enums.BusinessType;
import com.zhyc.common.utils.poi.ExcelUtil;
import com.zhyc.module.base.domain.BasSheepGroup;
import com.zhyc.module.base.service.IBasSheepGroupService;
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 wyt
 * @date 2025-07-14
 */
@RestController
@RequestMapping("/group_management/group_management")
public class BasSheepGroupController extends BaseController
{
    @Autowired
    private IBasSheepGroupService basSheepGroupService;

    /**
     * 查询分组管理列表
     */
    @PreAuthorize("@ss.hasPermi('group_management:group_management:list')")
    @GetMapping("/list")
    public AjaxResult list(BasSheepGroup basSheepGroup)
    {
        List<BasSheepGroup> list = basSheepGroupService.selectBasSheepGroupList(basSheepGroup);
        return success(list);
    }

    /**
     * 导出分组管理列表
     */
    @PreAuthorize("@ss.hasPermi('group_management:group_management:export')")
    @Log(title = "分组管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BasSheepGroup basSheepGroup)
    {
        List<BasSheepGroup> list = basSheepGroupService.selectBasSheepGroupList(basSheepGroup);
        ExcelUtil<BasSheepGroup> util = new ExcelUtil<BasSheepGroup>(BasSheepGroup.class);
        util.exportExcel(response, list, "分组管理数据");
    }

    /**
     * 获取分组管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('group_management:group_management:query')")
    @GetMapping(value = "/{groupId}")
    public AjaxResult getInfo(@PathVariable("groupId") Long groupId)
    {
        return success(basSheepGroupService.selectBasSheepGroupByGroupId(groupId));
    }

    /**
     * 新增分组管理
     */
    @PreAuthorize("@ss.hasPermi('group_management:group_management:add')")
    @Log(title = "分组管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BasSheepGroup basSheepGroup)
    {
        return toAjax(basSheepGroupService.insertBasSheepGroup(basSheepGroup));
    }

    /**
     * 修改分组管理
     */
    @PreAuthorize("@ss.hasPermi('group_management:group_management:edit')")
    @Log(title = "分组管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BasSheepGroup basSheepGroup)
    {
        return toAjax(basSheepGroupService.updateBasSheepGroup(basSheepGroup));
    }

    /**
     * 删除分组管理
     */
    @PreAuthorize("@ss.hasPermi('group_management:group_management:remove')")
    @Log(title = "分组管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{groupIds}")
    public AjaxResult remove(@PathVariable Long[] groupIds)
    {
        return toAjax(basSheepGroupService.deleteBasSheepGroupByGroupIds(groupIds));
    }

    @PreAuthorize("@ss.hasPermi('group_management:group_management:list')")
    @GetMapping("/leaf")
    public AjaxResult selectLeafNodes() {
        List<BasSheepGroup> leafNodes = basSheepGroupService.selectLeafNodes();
        return success(leafNodes);
    }

}
