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.EquipmentStandardVerifyRegulation;
import com.casic.missiles.service.equipment.IEquipmentStandardVerifyRegulationService;
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/regulation")
public class EquipmentStandardVerifyRegulationController extends ExportController {
    @Autowired
    private IEquipmentStandardVerifyRegulationService meterStandardVerifyRegulationService;

    /**
     * 标准装置-检定规程列表
     */
    @ApiOperation("标准装置-检定规程列表（分页）")
    @PostMapping("/listPage")
    @ResponseBody
    public ReturnDTO<PageInfoBT<EquipmentStandardVerifyRegulation>> listPage(@RequestBody @Valid IdDTO request) throws Exception {
        Page<EquipmentStandardVerifyRegulation> page = PageFactory.defaultPage();
        return ReturnUtil.success(super.packForBT(meterStandardVerifyRegulationService.listPage(page, request)));
    }

    /**
     * 添加检定规程
     */
    @ApiOperation("添加检定规程")
    @PostMapping("/add")
    @ResponseBody
    public ReturnDTO add(@RequestBody @Valid EquipmentStandardVerifyRegulation equipmentStandardVerifyRegulation) throws Exception {
        return meterStandardVerifyRegulationService.add(equipmentStandardVerifyRegulation);
    }


    /**
     * 删除检定规程
     */
    @ApiOperation("删除检定规程")
    @PostMapping("/delete")
    @ResponseBody
    public ReturnDTO delete(@RequestBody @Valid IdsDTO idsDTO) {
        return meterStandardVerifyRegulationService.batchDelete(idsDTO.getIds());
    }
}
