/*
 *      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.security.trans.settings.controller;

import io.swagger.annotations.*;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import lombok.AllArgsConstructor;
import javax.validation.Valid;


import org.security.trans.settings.dto.DeviceCategorySettingsDTO;
import org.security.trans.settings.wrapper.DCWrapper;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;

import org.springblade.core.secure.annotation.PreAuth;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.constant.RoleConstant;
import org.springblade.core.tool.utils.Func;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.security.trans.settings.entity.DeviceCategorySettings;
import org.security.trans.settings.vo.DeviceCategorySettingsVO;
import org.security.trans.settings.service.IDeviceCategorySettingsService;
import org.springblade.core.boot.ctrl.BladeController;
import springfox.documentation.annotations.ApiIgnore;

import java.text.ParseException;
import java.util.List;
import java.util.Map;

/**
 * 系统配置-设备类型设置 控制器
 *
 * @author BladeX
 * @since 2022-03-03
 */
@RestController
@AllArgsConstructor
@RequestMapping("/devicecategorysettings")
@Api(value = "系统配置-设备类型设置", tags = "系统配置-设备类型设置接口")
public class DeviceCategorySettingsController extends BladeController {

	private final IDeviceCategorySettingsService deviceCategorySettingsService;

	/**
	 * 详情
	 */
	@GetMapping("/{id}")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "详情", notes = "传入deviceCategorySettings id")
	public R<DeviceCategorySettingsVO> detail(@PathVariable String id) {
		return R.data(deviceCategorySettingsService.getDetailById(id));
	}


	/**
	 * 分页 系统配置-设备类型设置
	 */
	@GetMapping("/list")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "分页", notes = "传入deviceCategorySettings")
	public R<IPage<DeviceCategorySettings>> list(DeviceCategorySettings deviceCategorySettings, Query query) {
		IPage<DeviceCategorySettings> pages = deviceCategorySettingsService.page(Condition.getPage(query), Condition.getQueryWrapper(deviceCategorySettings));
		return R.data(pages);
	}

	/**
	 * 自定义分页 系统配置-设备类型设置
	 */
	@GetMapping("/page")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "分页", notes = "传入deviceCategorySettings")
	public R<IPage<DeviceCategorySettingsVO>> page(DeviceCategorySettingsVO deviceCategorySettings, Query query) {
		IPage<DeviceCategorySettingsVO> pages = deviceCategorySettingsService.selectDeviceCategorySettingsPage(Condition.getPage(query), deviceCategorySettings);
		return R.data(pages);
	}
	/**
	 * 获取树形结构
	 *
	 * @return
	 */
	@GetMapping("/tree")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "树形结构", notes = "树形结构")
	public R<List<DeviceCategorySettingsVO>> tree(DeviceCategorySettingsDTO deviceCategorySettingsDTO) {
		List<DeviceCategorySettingsVO> tree = deviceCategorySettingsService.tree(deviceCategorySettingsDTO);
		return R.data(tree);
	}
	/**
	 * 懒加载获取部门树形结构
	 */
	@GetMapping("/lazy-tree")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "懒加载树形结构", notes = "树形结构")
	public R<List<DeviceCategorySettingsVO>> lazyTree(Long parentId) {
		List<DeviceCategorySettingsVO> tree = deviceCategorySettingsService.lazyTree(parentId);
		return R.data(tree);
	}

	/**
	 * 懒加载列表
	 */
	@GetMapping("/lazy-list")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "name", value = "类型名称", paramType = "query", dataType = "string")
	})
	@PreAuth(RoleConstant.HAS_ROLE_ADMINISTRATOR)
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "懒加载列表", notes = "传入deviceCategorySettings")
	public R<List<DeviceCategorySettingsVO>> lazyList(Long parentId, @ApiIgnore @RequestParam Map<String, Object> deviceCategorySettings) {
		List<DeviceCategorySettingsVO> list = deviceCategorySettingsService.lazyList(parentId, deviceCategorySettings);
		return R.data(DCWrapper.build().listNodeLazyVO(list));
	}


	/**
	 * 新增或修改 系统配置-设备类型设置
	 */
	@PostMapping("/save")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "新增或修改", notes = "传入deviceCategorySettings")
	public R save(@Valid @RequestBody DeviceCategorySettingsDTO deviceCategorySettings) throws ParseException {
		return R.status(deviceCategorySettingsService.saveDeviceCategorySettings(deviceCategorySettings));
	}


	/**
	 * 删除 系统配置-设备类型设置
	 */
	@PostMapping("/remove")
	@ApiOperationSupport(order = 9)
	@ApiOperation(value = "删除", notes = "传入ids")
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) throws ParseException{
		return deviceCategorySettingsService.removeDeviceCategory(Func.toLongList(ids));
	}

	/**
	 * 联级选择器树形结构
	 *create:qx
	 * @return
	 */
	@GetMapping("/cascade")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "树形结构", notes = "树形结构")
	public R<List<DeviceCategorySettingsVO>> cascadeSelection() {
		List<DeviceCategorySettingsVO> list = deviceCategorySettingsService.cascadeSelection();
		return R.data(list);
	}

}
