package org.springblade.complaints.controller;


import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import javax.validation.Valid;

import org.springblade.complaints.entity.BladeCustomerComplaints;
import org.springblade.complaints.service.IBladeCustomerComplaintsService;
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.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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;

/**
 * <p>
 * 客诉管理 前端控制器
 * </p>
 *
 * @author zbc
 * @since 2021-04-09
 */


@RestController
@AllArgsConstructor
@RequestMapping("complaints/bladeCustomerComplaints")
@Api(value = "客诉管理", tags = "客诉管理接口")
public class BladeCustomerComplaintsController extends BladeController {

	private final IBladeCustomerComplaintsService bladeCustomerComplaintsService;


	@PostMapping("/save")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "新增", notes = "传入bladeCustomerComplaints")
	public R save(@Valid @RequestBody BladeCustomerComplaints bladeCustomerComplaints) {
		return R.status(bladeCustomerComplaintsService.save(bladeCustomerComplaints));
	}


	@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(bladeCustomerComplaintsService.removeByIds(Func.toLongList(ids)));
	}


	@PostMapping("/update")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "修改", notes = "传入bladeCustomerComplaints")
	public R update(@Valid @RequestBody BladeCustomerComplaints bladeCustomerComplaints) {
		return R.status(bladeCustomerComplaintsService.updateById(bladeCustomerComplaints));
	}


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


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


	@GetMapping("/select/list")
	@ApiOperationSupport(order = 6)
	@ApiOperation(value = "客诉管理下拉列表")
	public R selectList() {
		List<BladeCustomerComplaints> list = bladeCustomerComplaintsService.list(
			new LambdaQueryWrapper<BladeCustomerComplaints>()
				.eq(BladeCustomerComplaints::getIsDeleted, 0)
		);
		List<Map<String, Object>> data = list.stream()
			.map(obj -> {
				Map<String, Object> map = new HashMap<>();
				map.put("id", obj.getId());
				map.put("name", obj.getComplaintName());
				return map;
			}).collect(Collectors.toList());
		return R.data(data);
	}

}

