package org.springblade.bignet.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 lombok.Data;
import org.springblade.bignet.entity.BladeBignet;
import org.springblade.bignet.service.IBladeBignetService;
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 javax.validation.Valid;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 * 大网数据管理表 前端控制器
 * </p>
 *
 * @author zbc
 * @since 2021-04-19
 */
@RestController
@AllArgsConstructor
@RequestMapping("Bignet/bladeBignet")
@Api(value = "大网数据管理", tags = "大网数据管理接口")
public class BladeBignetController {

	private final IBladeBignetService bladeBignetService;

	@PostMapping("/save")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "新增", notes = "传入bladeBignet")
	public R save(@Valid @RequestBody BladeBignet bladeBignet) {
		bladeBignet.setCreateTime(new Date());
		return R.status(bladeBignetService.save(bladeBignet));
	}


	@PostMapping("/remove")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "删除", notes = "传入ids")
	public R remove(@ApiParam(value = "主键集合  1,2,3", required = true) @RequestParam String ids) {
		return R.status(bladeBignetService.removeByIds(Func.toLongList(ids)));
	}


	@PostMapping("/update")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "修改", notes = "传入bladeBignet")
	public R update(@Valid @RequestBody BladeBignet bladeBignet) {
		bladeBignet.setUpdateTime(new Date());
		return R.status(bladeBignetService.updateById(bladeBignet));
	}


	@GetMapping("/list")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "分页", notes = "传入bladeBignet")
	public R<IPage<BladeBignet>> list(BladeBignet bladeBignet, Query query) {
		IPage<BladeBignet> pages = bladeBignetService.page(Condition.getPage(query), Condition.getQueryWrapper(bladeBignet));
		return R.data(pages);
	}


	@GetMapping("/detail")
	@ApiOperationSupport(order = 5)
	@ApiOperation(value = "详情", notes = "传入bladeBignet")
	public R<BladeBignet> detail(BladeBignet bladeBignet) {
		BladeBignet detail = bladeBignetService.getOne(Condition.getQueryWrapper(bladeBignet));
		return R.data(detail);
	}


	@GetMapping("/select/list")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "大网数据管理下拉列表")
	public R selectList() {
		List<BladeBignet> list = bladeBignetService.list();
		List<Map<String, Object>> data = list.stream()
			.map(obj -> {
				Map<String, Object> map = new HashMap<>();
				map.put("id", obj.getId());
				map.put("name", obj.getBignetName());
				return map;
			}).collect(Collectors.toList());
		return R.data(data);
	}

}

