/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.community.elevator.alarmdirector.controller;

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 javax.validation.Valid;

import org.springblade.community.residential.entity.Residential;
import org.springblade.community.residential.service.IResidentialService;
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.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestParam;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.community.elevator.alarmdirector.entity.AlarmDirector;
import org.springblade.community.elevator.alarmdirector.vo.AlarmDirectorVO;
import org.springblade.community.elevator.alarmdirector.wrapper.AlarmDirectorWrapper;
import org.springblade.community.elevator.alarmdirector.service.IAlarmDirectorService;
import org.springblade.core.boot.ctrl.BladeController;

/**
 * 电梯告警负责人 控制器
 *
 * @author BladeX
 * @since 2021-03-11
 */
@RestController
@AllArgsConstructor
@RequestMapping("community/elevator/alarmdirector")
@Api(value = "电梯告警负责人", tags = "电梯告警负责人接口")
public class AlarmDirectorController extends BladeController {

	private IAlarmDirectorService alarmDirectorService;
	private IResidentialService residentialService;

	/**
	 * 详情
	 */
	@GetMapping("/detail")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "传入alarmDirector")
	public R<AlarmDirectorVO> detail(AlarmDirector alarmDirector) {
		AlarmDirector detail = alarmDirectorService.getOne(Condition.getQueryWrapper(alarmDirector));
		return R.data(AlarmDirectorWrapper.build().entityVO(detail));
	}

	/**
	 * 分页 电梯告警负责人
	 */
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes = "传入alarmDirector")
	public R<IPage<AlarmDirectorVO>> list(AlarmDirector alarmDirector, Query query) {
		IPage<AlarmDirector> pages = alarmDirectorService.page(Condition.getPage(query), Condition.getQueryWrapper(alarmDirector));
		return R.data(AlarmDirectorWrapper.build().pageVO(pages));
	}


	/**
	 * 自定义分页 电梯告警负责人
	 */
	@GetMapping("/page")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "分页", notes = "传入alarmDirector")
	public R<IPage<AlarmDirectorVO>> page(AlarmDirectorVO alarmDirector, Query query) {
		IPage<AlarmDirectorVO> pages = alarmDirectorService.selectAlarmDirectorPage(Condition.getPage(query), alarmDirector);
		return R.data(pages);
	}

	/**
	 * 新增 电梯告警负责人
	 */
	@PostMapping("/save")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "新增", notes = "传入alarmDirector")
	public R save(@Valid @RequestBody AlarmDirector alarmDirector) {
		return R.status(alarmDirectorService.save(alarmDirector));
	}

	/**
	 * 修改 电梯告警负责人
	 */
	@PostMapping("/update")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "修改", notes = "传入alarmDirector")
	public R update(@Valid @RequestBody AlarmDirector alarmDirector) {
		return R.status(alarmDirectorService.updateById(alarmDirector));
	}

	/**
	 * 新增或修改 电梯告警负责人
	 */
	@PostMapping("/submit")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "新增或修改", notes = "传入alarmDirector")
	public R submit(@Valid @RequestBody AlarmDirector alarmDirector) {
		Residential residential = residentialService.getById(alarmDirector.getResidentialId());
		alarmDirector.setResidentialName(residential.getName());
		alarmDirector.setTenantId(residential.getTenantId());
		return R.status(alarmDirectorService.saveOrUpdate(alarmDirector));
	}


	/**
	 * 删除 电梯告警负责人
	 */
	@PostMapping("/remove")
	@ApiOperationSupport(order = 7)
	@ApiOperation(value = "逻辑删除", notes = "传入ids")
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		return R.status(alarmDirectorService.deleteLogic(Func.toLongList(ids)));
	}


}
