package com.bonus.sgzb.material.controller;

import com.bonus.sgzb.common.core.web.controller.BaseController;
import com.bonus.sgzb.common.core.web.domain.AjaxResult;
import com.bonus.sgzb.common.core.web.page.TableDataInfo;
import com.bonus.sgzb.material.config.PageResultVo;
import com.bonus.sgzb.material.domain.MaWholeSetDto;
import com.bonus.sgzb.material.domain.MaWholeTreeVo;
import com.bonus.sgzb.material.domain.MaWholeVo;
import com.bonus.sgzb.material.service.MaWholeSetService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author ma_sh
 * @create 2024/4/15 17:14
 */
@RestController
@RequestMapping("/maWhole")
@Slf4j
public class MaWholeSetController extends BaseController {

    @Resource
    private MaWholeSetService maWholeSetService;

    /**
     * 新增整套抱杆管理
     * @param dto
     * @return
     */
    @ApiOperation("新增整套抱杆管理")
    @PostMapping("/addOrUpdate")
    public AjaxResult addOrUpdate(@ApiParam(value = "添加信息", required = true)
                          @RequestBody MaWholeSetDto dto) {
        if (dto.getId() != null) {
            log.info("修改整套抱杆管理：{}", dto);
            return maWholeSetService.update(dto);
        }
        log.info("新增整套抱杆管理：{}", dto);
        return maWholeSetService.insert(dto);
    }

    /**
     * 查询整套抱杆管理
     * @param dto
     * @return
     */
    @ApiOperation("查询整套抱杆管理")
    @PostMapping("/selectList")
    public AjaxResult selectList(@ApiParam(value = "查询信息") @RequestBody MaWholeSetDto dto) {
        log.info("查询整套抱杆管理：{}", dto);
        PageResultVo<MaWholeVo> result = maWholeSetService.selectList(dto);
        return AjaxResult.success(result);
    }

    /**
     * 查询整套抱杆明细
     * @param dto
     * @return
     */
    @ApiOperation("查询整套抱杆明细")
    @PostMapping("/selectListById")
    public TableDataInfo selectListById(@ApiParam(value = "查询信息") @RequestBody MaWholeSetDto dto) {
        log.info("查询整套抱杆明细：{}", dto);
        startPage();
        List<MaWholeVo> list = maWholeSetService.selectListById(dto);
        return getDataTable(list);
    }

    /**
     * 修改时查询整套抱杆明细
     * @param dto
     * @return
     */
    @ApiOperation("修改时查询整套抱杆明细")
    @PostMapping("/selectListTree")
    public AjaxResult selectListTree(@ApiParam(value = "查询信息") @RequestBody MaWholeSetDto dto) {
        log.info("修改时查询整套抱杆明细：{}", dto);
        MaWholeTreeVo  maWholeTreeVo = maWholeSetService.selectListTree(dto.getId());
        return AjaxResult.success(maWholeTreeVo);
    }

    /**
     * 根据id删除整套抱杆
     * @param dto
     * @return
     */
    @ApiOperation("根据id删除整套抱杆")
    @PostMapping("/deleteById")
    public AjaxResult deleteById(@ApiParam(value = "删除信息") @RequestBody MaWholeSetDto dto) {
        log.info("根据id删除整套抱杆：{}", dto);
        return maWholeSetService.deleteById(dto);
    }
}
