package com.casic.missiles.controller.equipment;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.casic.missiles.core.base.controller.ExportController;
import com.casic.missiles.core.page.PageFactory;
import com.casic.missiles.core.page.PageInfoBT;
import com.casic.missiles.dto.IdDTO;
import com.casic.missiles.dto.IdsDTO;
import com.casic.missiles.dto.ReturnDTO;
import com.casic.missiles.dto.ReturnUtil;
import com.casic.missiles.model.equipment.EquipmentStandardSupportEquipment;
import com.casic.missiles.service.equipment.IEquipmentStandardSupportEquipmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 标准装置-标准配套设备表 前端控制器
 * </p>
 *
 * @author cuicheng
 * @since 2022-12-15
 */
@RestController
@Api(tags = "标准装置-标准配套设备表")
@RequestMapping("/meter/standard/equipment")
public class EquipmentStandardSupportEquipmentController extends ExportController {
    /**
     * 标准配套装置service
     */
    @Autowired
    private IEquipmentStandardSupportEquipmentService meterStandardSupportEquipmentService;

    /**
     * 标准装置-配套设备列表(分页)
     */
    @ApiOperation("标准装置-配套设备列表(分页)")
    @PostMapping("/listPage")
    @ResponseBody
    public ReturnDTO<PageInfoBT<EquipmentStandardSupportEquipment>> listPage(@RequestBody @Valid IdDTO request) throws Exception {
        Page<EquipmentStandardSupportEquipment> page = PageFactory.defaultPage();
        return ReturnUtil.success(super.packForBT(meterStandardSupportEquipmentService.listPage(page, request)));
    }

    /**
     * 添加标准配套设备
     */
    @ApiOperation("添加标准配套设备")
    @PostMapping("/add")
    @ResponseBody
    public ReturnDTO add(@RequestBody @Valid EquipmentStandardSupportEquipment meterStandardSupportEquipment) throws Exception {
        return meterStandardSupportEquipmentService.add(meterStandardSupportEquipment);
    }

    /**
     * 删除标准配套设备
     */
    @ApiOperation("删除标准配套设备")
    @PostMapping("/delete")
    @ResponseBody
    public ReturnDTO delete(@RequestBody @Valid IdsDTO idsDTO) {
        return meterStandardSupportEquipmentService.batchDelete(idsDTO.getIds());
    }
}
