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.EquipmentStandardEquipmentUser;
import com.casic.missiles.service.equipment.IEquipmentStandardEquipmentUserService;
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;
import java.util.List;

/**
 * <p>
 * 标准装置-计量人员表 前端控制器
 * </p>
 *
 * @author cuicheng
 * @since 2022-12-15
 */
@RestController
@Api(tags = "标准装置-计量人员")
@RequestMapping("/meter/standard/user")
public class EquipmentStandardEquipmentUserController extends ExportController {

    @Autowired
    private IEquipmentStandardEquipmentUserService meterStandardEquipmentUserService;

    /**
     * 标准装置-计量人员列表
     */
    @ApiOperation("标准装置-计量人员列表（分页）")
    @PostMapping("/listPage")
    @ResponseBody
    public ReturnDTO<PageInfoBT<EquipmentStandardEquipmentUser>> listPage(@RequestBody @Valid IdDTO request) throws Exception {
        Page<EquipmentStandardEquipmentUser> page = PageFactory.defaultPage();
        return ReturnUtil.success(super.packForBT(meterStandardEquipmentUserService.listPage(page, request)));
    }

    /**
     * 添加计量人员
     */
    @ApiOperation("添加计量人员")
    @PostMapping("/add")
    @ResponseBody
    public ReturnDTO add(@RequestBody @Valid EquipmentStandardEquipmentUser meterStandardEquipmentUser) throws Exception {
        return meterStandardEquipmentUserService.add(meterStandardEquipmentUser);
    }

    /**
     * 批量添加计量人员
     */
    @ApiOperation("批量添加计量人员")
    @PostMapping("/batchAdd")
    @ResponseBody
    public ReturnDTO add(@RequestBody @Valid List<EquipmentStandardEquipmentUser> meterStandardEquipmentUserList) throws Exception {
        return meterStandardEquipmentUserService.addList(meterStandardEquipmentUserList);
    }

    /**
     * 删除计量人员
     */
    @ApiOperation("删除计量人员")
    @PostMapping("/delete")
    @ResponseBody
    public ReturnDTO delete(@RequestBody @Valid IdDTO idDTO) {
        return meterStandardEquipmentUserService.deleteById(idDTO.getId());
    }

    /**
     * 批量删除计量人员
     */
    @ApiOperation("批量删除计量人员")
    @PostMapping("/batchDelete")
    @ResponseBody
    public ReturnDTO batchDelete(@RequestBody @Valid IdsDTO idsDTO) {
        return meterStandardEquipmentUserService.batchDelete(idsDTO.getIds());
    }

}
