package com.hotent.uc.controller;


import com.hotent.base.controller.BaseController2;
import com.hotent.base.model.CommonResult;
import com.hotent.base.query.PageList;
import com.hotent.base.query.QueryFilter;
import com.hotent.base.query.QueryOP;
import com.hotent.base.util.StringUtil;
import com.hotent.uc.manager.UcGroupManager;
import com.hotent.uc.model.UcGroup;
import com.hotent.uc.util.ContextUtil;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;


/**
 * 群组管理 前端控制器
 *
 * @company 广州宏天软件股份有限公司
 * @author 超级管理员
 * @email test
 * @since 2021-01-15
 */
@RestController
@RequestMapping("/uc/ucGroup/v2/")
public class UcGroupController2 extends BaseController2<UcGroupManager, UcGroup> {
	@PostMapping("/save")
	@ApiOperation("添加实体的接口")
	public CommonResult<String> create(@ApiParam(name="model", value="实体信息") @RequestBody UcGroup ucGroup) {
		String msg="添加群组成功";
		if(StringUtil.isNotEmpty(ucGroup.getId())){
			baseService.update(ucGroup);
			msg="更新群组成功";
		}else{
			ucGroup.setCreatorName(ContextUtil.getCurrentUser().getFullname());
			baseService.save(ucGroup);
		}
		return CommonResult.<String>ok().message(msg);
	}

	@PostMapping(value="/query", produces={"application/json; charset=utf-8" })
	@ApiOperation("分页查询结果")
	public CommonResult<PageList<UcGroup>> query(@ApiParam(name="queryFilter", value="分页查询信息") @RequestBody QueryFilter<UcGroup> queryFilter) {
		queryFilter.addFilter("create_by_",ContextUtil.getCurrentUserId(), QueryOP.EQUAL);
		PageList<UcGroup> query = baseService.query(queryFilter);
		return CommonResult.<PageList<UcGroup>>ok().value(query);
	}

	@DeleteMapping("/remove")
	@ApiOperation("根据id集合批量删除")
	public CommonResult<String> remove(@ApiParam(name="ids", value="实体集合") @RequestParam String...ids) {
		baseService.deleteByIds(Arrays.asList(ids));
		return CommonResult.<String>ok().message("删除群组成功");
	}

}
