package com.bonus.sgzb.material.controller;

import cn.hutool.core.convert.Convert;
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.*;
import com.bonus.sgzb.material.service.MaWholeSetService;
import com.github.pagehelper.PageHelper;
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("查询整套抱杆管理")
    @GetMapping("/selectList")
    public TableDataInfo selectList(MaWholeSetDto dto) {
        PageHelper.startPage(dto.getPageNum() == 0 ? 1 : dto.getPageNum(), dto.getPageSize());
        List<MaWholeVo> maWholeVos = maWholeSetService.selectList(dto);
        return getDataTable(maWholeVos);
    }


    /**
     * 查询整套抱杆管理
     *
     * @param dto
     * @return
     */
    @ApiOperation("领料申请查询整套抱杆管理")
    @GetMapping("/selectWholeList")
    public AjaxResult selectWholeList(MaWholeSetDto dto) {
        List<MaWholeVo> maWholeVos = maWholeSetService.selectList(dto);
        List<MaWholeDto> tmTaskDtos = Convert.toList(MaWholeDto.class, maWholeVos);
        return AjaxResult.success(tmTaskDtos);
    }

    /**
     * 查询整套抱杆明细
     *
     * @param dto
     * @return
     */
    @ApiOperation("查询整套抱杆明细")
    @GetMapping("/selectListById")
    public AjaxResult selectListById(@ApiParam(value = "查询信息") MaWholeSetDto dto) {
        List<MaWholeVo> list = maWholeSetService.selectListById(dto);
        return AjaxResult.success(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);
    }

    /**
     * 查询整套抱杆明细
     *
     * @param wholeTypeName
     * @return
     */
    @ApiOperation("领料申请查询成套抱杆设备")
    @GetMapping("/selectListByWholeTypeName")
    public AjaxResult selectListByWholeTypeName(MaWholeSetDto wholeTypeName) {
        List<LeaseApplyDetails> list = maWholeSetService.selectListByWholeTypeName(wholeTypeName);
        return AjaxResult.success(list);
    }
}
