package com.zhgd.xmgl.modules.basicdata.controller.admin;

import com.zhgd.annotation.OperLog;
import com.zhgd.jeecg.common.api.vo.Result;
import com.zhgd.xmgl.modules.basicdata.entity.BaseAction;
import com.zhgd.xmgl.modules.basicdata.service.IBaseActionService;
import com.zhgd.xmgl.util.MessageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
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 java.util.List;
import java.util.Map;
import java.util.Set;


/**
 * @Title: Controller
 * @Description: 系统资源-功能操作
 * @author： pds
 * @date：   2020-10-27
 * @version： V1.0
 */
@RestController
@RequestMapping("/xmgl/action")
@Slf4j
@Api(tags = "系统资源-功能按钮操作")
public class BaseActionController {
	@Autowired
	private IBaseActionService baseActionService;

	@OperLog(operModul = "功能按钮管理", operType = "查询", operDesc = "查询菜单下的按钮权限")
    @ApiOperation(value = "获取菜单下所有操作", notes = "获取菜单下所有操作", httpMethod="POST")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "menuId", value = "menuId", paramType = "form"),
    })
    @PostMapping("/list")
    public Result<List<BaseAction>> getMenuAction(@RequestBody Map<String,Object> map) {
        return Result.success(baseActionService.findListByMenuId(MapUtils.getString(map,"menuId")));
    }

	@OperLog(operModul = "功能按钮管理", operType = "查询", operDesc = "查询菜单下的按钮权限CODE")
	@ApiOperation(value = "查询菜单下的按钮权限CODE", notes = "查询菜单下的按钮权限CODE", httpMethod="POST")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "menuId", value = "menuId", paramType = "form"),
	})
	@PostMapping("/codeList")
	public Result<Set<String>> getMenuCode(@RequestBody Map<String,Object> map) {
		return Result.success(baseActionService.getMenuCode(MapUtils.getString(map,"menuId")));
	}
	
	/**
	  *   添加
	 * @param baseAction
	 * @return
	 */
	@OperLog(operModul = "功能按钮管理", operType = "新增", operDesc = "新增按钮权限")
	@ApiOperation(value = " 添加系统资源-功能操作信息", notes = "添加系统资源-功能操作信息" , httpMethod="POST")
	@PostMapping(value = "/add")
	public Result<BaseAction> add(@RequestBody BaseAction baseAction) {
        baseActionService.addBaseAction(baseAction);
		return Result.ok();
	}
	
	/**
	  *  编辑
	 * @param baseAction
	 * @return
	 */
	@OperLog(operModul = "功能按钮管理", operType = "修改", operDesc = "修改按钮权限")
	@ApiOperation(value = "编辑系统资源-功能操作信息", notes = "编辑系统资源-功能操作信息" , httpMethod="POST")
	@PostMapping(value = "/edit")
	public Result<BaseAction> edit(@RequestBody BaseAction baseAction) {
        baseActionService.editBaseAction(baseAction);
        return Result.ok();
	}
	
	/**
	  *   通过id删除
	 * @param
	 * @return
	 */
	@OperLog(operModul = "功能按钮管理", operType = "删除", operDesc = "删除单个按钮权限")
	@ApiOperation(value = "删除系统资源-功能操作信息", notes = "删除系统资源-功能操作信息" , httpMethod="POST")
	@ApiImplicitParam(name = "actionId", value = "系统资源-功能操作ID", paramType = "query", required = true, dataType = "Integer")
	@PostMapping(value = "/delete")
	public Result<BaseAction> delete(@RequestBody Map<String,Object> map) {
         baseActionService.deleteBaseAction(MapUtils.getString(map,"actionId"));
         return Result.ok();
	}
	

	
	/**
	  * 通过id查询
	 * @param
	 * @return
	 */
	@OperLog(operModul = "功能按钮管理", operType = "查询", operDesc = "查询单个按钮权限")
	@ApiOperation(value = "通过id查询系统资源-功能操作信息", notes = "通过id查询系统资源-功能操作信息" , httpMethod="POST")
    @ApiImplicitParam(name = "actionId", value = "系统资源-功能操作ID", paramType = "query", required = true, dataType = "Integer")
	@PostMapping(value = "/queryById")
	public Result<BaseAction> queryById(@RequestBody Map<String,Object> map) {
		Result<BaseAction> result = new Result<BaseAction>();
		BaseAction baseAction = baseActionService.getById(MapUtils.getString(map,"actionId"));
		if(baseAction==null) {
            result.error500(MessageUtil.get("notFindErr"));
		}else {
			result.setResult(baseAction);
			result.setSuccess(true);
		}
		return result;
	}


}
