package org.springblade.modules.business.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.business.entity.FacilityModel;
import org.springblade.modules.business.service.IFacilityModelService;
import org.springblade.modules.business.vo.FacilityModelVO;
import org.springblade.modules.business.wrapper.FacilityModelWrapper;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 设备型号表 控制器
 *
 * @author BladeX
 * @since 2024-07-30
 */
@RestController
@AllArgsConstructor
@RequestMapping("facility/facilitymodel")
@Api(value = "设备型号表", tags = "设备型号表接口")
public class FacilityModelController extends BladeController {

	private final IFacilityModelService facilityModelService;

	/**
	 * 详情
	 */
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "传入facilityModel")
	public R<FacilityModelVO> detail(FacilityModel facilityModel) {
		FacilityModel detail = facilityModelService.getOne(Condition.getQueryWrapper(facilityModel));
		return R.data(FacilityModelWrapper.build().entityVO(detail));
	}

	/**
	 * 分页 设备型号表
	 */
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes = "传入facilityModel")
	public R<IPage<FacilityModelVO>> list(FacilityModel facilityModel, Query query) {
		IPage<FacilityModel> pages = facilityModelService.page(Condition.getPage(query), Condition.getQueryWrapper(facilityModel));
		return R.data(FacilityModelWrapper.build().pageVO(pages));
	}


	/**
	 * 自定义分页 设备型号表
	 */
	@GetMapping("/page")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "分页", notes = "传入facilityModel")
	public R<IPage<FacilityModelVO>> page(FacilityModelVO facilityModel, Query query) {
		IPage<FacilityModelVO> pages = facilityModelService.selectFacilityModelPage(Condition.getPage(query), facilityModel);
		return R.data(pages);
	}

	/**
	 * 新增 设备型号表
	 */
	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "新增", notes = "传入facilityModel")
	public R save(@Valid @RequestBody FacilityModel facilityModel) {
		return R.status(facilityModelService.save(facilityModel));
	}

	/**
	 * 修改 设备型号表
	 */
	@PostMapping("/update")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "修改", notes = "传入facilityModel")
	public R update(@Valid @RequestBody FacilityModel facilityModel) {
		return R.status(facilityModelService.updateById(facilityModel));
	}

	/**
	 * 新增或修改 设备型号表
	 */
	@PostMapping("/submit")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "新增或修改", notes = "传入facilityModel")
	public R submit(@Valid @RequestBody FacilityModel facilityModel) {
		return R.status(facilityModelService.saveOrUpdate(facilityModel));
	}

	
	/**
	 * 删除 设备型号表
	 */
	@PostMapping("/remove")
	@ApiOperationSupport(order = 7)
	@ApiOperation(value = "逻辑删除", notes = "传入ids")
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		return R.status(facilityModelService.removeByIds(Func.toLongList(ids)));
	}

	
}
