package org.springblade.customer.controller;


import java.util.Date;
import java.util.List;

import javax.validation.Valid;

import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.secure.BladeUser;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.customer.entity.CustomerReportCategory;
import org.springblade.customer.enums.ImportsEnum;
import org.springblade.customer.query.CustomerReportQuery;
import org.springblade.customer.service.ICustomerReportCategoryService;
import org.springblade.system.client.UserClient;
import org.springblade.system.client.model.UserModel;
import org.springframework.beans.factory.annotation.Autowired;
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.metadata.IPage;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;

/**
 * <p>
 * 客服数据分类表 前端控制器
 * </p>
 *
 * @author zbc
 * @since 2021-10-20
 */
@RestController
@RequestMapping("customerReport/category")
@AllArgsConstructor
@Api(value = "客服数据分类管理", tags = "客服数据分类管理")
public class CustomerReportCategoryController {

	@Autowired
	private ICustomerReportCategoryService customerReportCategoryService;

	@Autowired
	private UserClient userService;

	@PostMapping("/save")
	@ApiOperation(value = "新增", notes = "传入customerReportCategory")
	public R save(@Valid @RequestBody CustomerReportCategory customerReportCategory) {
		BladeUser bladeUser = AuthUtil.getUser();
		UserModel user = userService.getById(bladeUser.getUserId());
		customerReportCategory.setCreateTime(new Date());
		customerReportCategory.setCreateUser(user.getName());
		return R.status(customerReportCategoryService.save(customerReportCategory));
	}


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


	@PostMapping("/update")
	@ApiOperation(value = "修改", notes = "传入customerReportCategory")
	public R update(@Valid @RequestBody CustomerReportCategory customerReportCategory) {
		return R.status(customerReportCategoryService.updateById(customerReportCategory));
	}


	@GetMapping("/list")
	@ApiOperation(value = "列表")
	public R<List<CustomerReportCategory>> list() {
		List<CustomerReportCategory> list = customerReportCategoryService.list();
		return R.data(list);
	}


	@GetMapping("/page")
	@ApiOperation(value = "分页")
	public R<IPage<CustomerReportCategory>> page(CustomerReportQuery pageQuery, Query query) {
		IPage<CustomerReportCategory> page = Condition.getPage(query);
		IPage<CustomerReportCategory> pages = customerReportCategoryService.getPageByQuery(page, pageQuery);
		return R.data(pages);
	}


	@PostMapping("/getCode")
	@ApiOperation(value = "获取客服分类code")
	public R getCode() {
		return R.data(ImportsEnum.values());
	}

}

