package com.huatek.frame.base.group.controller;

import java.util.Map;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
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.RestController;

import com.alibaba.dubbo.config.annotation.Reference;
import com.huatek.torch.frame.log.KerLog;
import com.huatek.torch.frame.permission.KerPermission;
import com.huatek.torch.frame.validate.KerValid;

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

import com.huatek.frame.base.dto.GroupDTO;
import com.huatek.frame.base.entity.Group;
import com.huatek.frame.base.service.GroupService;
import com.huatek.frame.base.vo.GroupVO;

/**
 * @author key 组织
 */
@Api(tags={"组织接口"})
@RestController
@RequestMapping("/api/group")
public class GroupController {

	@Reference(check = false)
	private GroupService groupService;

	/**
	 * 组织列表
	 * 
	 * @param page
	 * @param limit
	 * @param group
	 * @return
	 */
	@ApiOperation(value = "组织列表",httpMethod="POST", notes= "组织列表", produces = "application/json;charset=utf-8",response=GroupVO.class)
	@KerLog(projectName = "PROJECTNAME", modelName = "GROUP.MODELNAME", methodName = "GROUP.MODELNAME.GROUPLIST")
	@PostMapping(value="/groups", produces = { "application/json;charset=utf-8"})
	public   @KerPermission("10018") Map<String, Object> groups(@RequestBody GroupDTO dto) {
		Map<String, Object> map = groupService.findGroupPage(dto);
		return map;
	}

	/**
	 * 查询组织对象
	 * 
	 * @param page
	 * @param limit
	 * @param group
	 * @return
	 */
	@ApiOperation(value = "查询组织对象",httpMethod="GET", notes= "查询组织对象", produces = "application/json;charset=utf-8",response=GroupVO.class)
	@KerLog(projectName = "PROJECTNAME", modelName = "GROUP.MODELNAME", methodName = "GROUP.MODELNAME.GROUPDETAIL")
	@GetMapping(value="/findGroup/{id}", produces = { "application/json;charset=utf-8"})
	public  @KerPermission("10019") Map<String, Object> findGroup(@ApiParam(value="组织id") @PathVariable("id")String id) {
		Map<String, Object> map = groupService.findGroup(id);
		return map;
	}

	/**
	 * 删除组织
	 * 
	 * @param ids
	 * @return
	 */
	@ApiOperation(value = "删除组织",httpMethod="POST", notes= "删除组织", produces = "application/json;charset=utf-8",response=Map.class)
	@KerLog(projectName = "PROJECTNAME", modelName = "GROUP.MODELNAME", methodName = "GROUP.MODELNAME.DELETEGROUP")
	@PostMapping(value="/deleteGroup", produces = { "application/json;charset=utf-8"})
	public   @KerPermission("10022") Map<String, Object> deleteGroup(@ApiParam(value="组织id集合") @RequestBody String[] ids) {
		Map<String, Object> map = groupService.deleteGroup(ids);
		return map;
	}

	/**
	 * 新增组织
	 * 
	 * @return
	 */
	@ApiOperation(value = "新增组织",httpMethod="POST", notes= "新增组织", produces = "application/json;charset=utf-8",response=Map.class)
	@KerLog(projectName = "PROJECTNAME", modelName = "GROUP.MODELNAME", methodName = "GROUP.MODELNAME.SAVEGROUP")
	@PostMapping(value = "/addGroup", produces = { "application/json;charset=utf-8"})
	public    @KerPermission("10020") @KerValid Map<String, Object> addGroup(@RequestBody Group group) {
		Map<String, Object> map = groupService.addGroup(group);
		return map;
	}

	/**
	 * 修改组织
	 * 
	 * @return
	 */
	@ApiOperation(value = "修改组织",httpMethod="POST", notes= "修改组织", produces = "application/json;charset=utf-8",response=Map.class)
	@KerLog(projectName = "PROJECTNAME", modelName = "GROUP.MODELNAME", methodName = "GROUP.MODELNAME.UPDATEGROUP")
	@PostMapping(value = "/modifyGroup", produces = { "application/json;charset=utf-8"})
	public    @KerPermission("10021") Map<String, Object> modifyGroup(@RequestBody Group group) {
		Map<String, Object> map = groupService.updateGroup(group);
		return map;
	} 
}
