package com.mosty.base.manager.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mosty.base.model.entity.jcgl.TbJcglZbfl;
import com.mosty.base.manager.service.TpJcglZbflService;
import com.mosty.common.base.domain.ResponseResult;
import com.mosty.common.base.entity.log.BusinessType;
import com.mosty.common.base.entity.log.Log;
import com.mosty.common.token.JwtSysUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@AllArgsConstructor
@RequestMapping({"/tpJcglZbfl"})
@Api(tags = {"装备分类管理"})
public class TpJcglZbflController {

    private final TpJcglZbflService tpJcglZbflService;


    @PostMapping("{addZbfl}")
    @JwtSysUser
    @Log(title = "新增装备类型", businessType = BusinessType.INSERT)
    @ApiOperation(value = "新增装备类型")
    public ResponseResult<Void> addZbfl(@RequestBody TbJcglZbfl zbfl) {
        tpJcglZbflService.addZbfl(zbfl);
        return ResponseResult.success();
    }

    @GetMapping(value = "selectLxList")
    @JwtSysUser
    @ApiOperation(value = "查询装备类型列表")
    public ResponseResult<IPage<TbJcglZbfl>> selectList(TbJcglZbfl zbfl) {
        IPage<TbJcglZbfl> page = new Page<>(zbfl.getPageNo(),zbfl.getPageSize());
        return ResponseResult.success(tpJcglZbflService.selectList(zbfl,page));
    }

    @GetMapping("{zbTree}")
    @JwtSysUser
    @ApiOperation(value = "查询装备树")
    public ResponseResult<List<TbJcglZbfl>> zbTree(String scode) {
        return ResponseResult.success(tpJcglZbflService.zbTree(scode));
    }

    @PutMapping("{editZbfl}")
    @JwtSysUser
    @Log(title = "编辑装备类型", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "编辑装备类型")
    public ResponseResult<Void> editZbfl(@RequestBody TbJcglZbfl zbfl) {
        tpJcglZbflService.editZbfl(zbfl);
        return ResponseResult.success();
    }

    @PostMapping("deleteZbfl")
    @JwtSysUser
    @Log(title = "递归删除装备类型", businessType = BusinessType.DELETE)
    @ApiOperation(value = "递归删除装备类型")
    public ResponseResult<Void> deleteZbfl(@RequestBody List<String> id) {
        tpJcglZbflService.deleteZbfl(id);
        return ResponseResult.success();
    }
}