package com.bonus.material.devConfig.controller;

/**
 * @author 30791
 * @version 1.0
 * Create by 2025/10/11 23:17
 */

// EquipmentTypeController.java


import com.bonus.common.core.utils.poi.ExcelUtil;
import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.core.web.page.TableDataInfo;
import com.bonus.material.devConfig.domain.*;
import com.bonus.material.devConfig.service.EquipmentTypeService;
import com.bonus.material.device.domain.vo.DevInfoVo;
import com.bonus.material.toolProcess.domain.ToolApplyEntity;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

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

/**
 * 装备分类管理
 */
@RestController
@RequestMapping("/equipment/type")
public class EquipmentTypeController extends BaseController {

    @Autowired
    private EquipmentTypeService equipmentTypeService;

    //获取树
    @GetMapping("/tree")
    public AjaxResult getEquipmentTree() {
        List<EquipmentTypeDTO> tree = equipmentTypeService.getEquipmentTypeTree();
        return AjaxResult.success(tree);
    }

    //获取层级
    @GetMapping("/cascader")
    public AjaxResult getEquipmentCascader() {
        List<EquipmentTypeDTO> cascaderData = equipmentTypeService.getEquipmentCascader();
        return AjaxResult.success(cascaderData);
    }

    //获取列表
    @GetMapping("/list")
    public TableDataInfo getEquipmentTypeList(EquipmentTypeEntity query) {
        try {
            startPage();
            List<EquipmentTypeEntity> list = equipmentTypeService.getEquipmentTypeList(query);
            return getDataTable(list);
        } catch (Exception e) {
            logger.error(e.toString(), e);
        }
        return getDataTableError(new ArrayList<>());
    }

    //获取列表
    @PostMapping("/export")
    public void export(HttpServletResponse response, EquipmentTypeEntity query) {
        List<EquipmentTypeEntity> list = equipmentTypeService.getEquipmentTypeList(query);
        ExcelUtil<EquipmentTypeEntity> util = new ExcelUtil<>(EquipmentTypeEntity.class);
        util.exportExcel(response, list, "装备类型数据");

    }


    //获取详细信息
    @GetMapping("/detail/{id}")
    public AjaxResult getEquipmentTypeDetail(@PathVariable Long id) {
        EquipmentType detail = equipmentTypeService.getEquipmentTypeDetail(id);
        return AjaxResult.success(detail);
    }

    //添加
    @PostMapping("/add")
    public AjaxResult addEquipmentType(@Validated @RequestBody EquipmentType equipmentType) {
        return equipmentTypeService.addEquipmentType(equipmentType);
    }

    //更新
    @PutMapping("/update")
    public AjaxResult updateEquipmentType(@Validated @RequestBody EquipmentType equipmentType) {
        return equipmentTypeService.updateEquipmentType(equipmentType);
    }

    //删除
    @DeleteMapping("/delete/{id}")
    public AjaxResult deleteEquipmentType(@PathVariable Long id) {
        equipmentTypeService.deleteEquipmentType(id);
        return AjaxResult.success();
    }


}
