package com.fufan.mtsaas.modules.sysmgr.sygroup.controller;


import com.alibaba.fastjson.JSONObject;
import com.fufan.mtsaas.modules.common.bo.request.DataRequest;
import com.fufan.mtsaas.modules.common.bo.request.DataRequestT;
import com.fufan.mtsaas.modules.common.bo.request.ResultPack;
import com.fufan.mtsaas.modules.common.bo.response.RequestPojo;
import com.fufan.mtsaas.modules.common.bo.response.Result;
import com.fufan.mtsaas.modules.sysmgr.sygroup.bo.request.GroupDetailQueryRequest;
import com.fufan.mtsaas.modules.sysmgr.sygroup.bo.request.GroupHQueryRequest;
import com.fufan.mtsaas.modules.sysmgr.sygroup.bo.request.GroupHSaveRequest;
import com.fufan.mtsaas.modules.sysmgr.sygroup.bo.response.SysNewMenuResponse;
import com.fufan.mtsaas.modules.common.bo.request.DataRequest;
import com.fufan.mtsaas.modules.common.bo.request.DataRequestT;
import com.fufan.mtsaas.modules.common.bo.request.ResultPack;
import com.fufan.mtsaas.modules.common.bo.response.RequestPojo;
import com.fufan.mtsaas.modules.common.bo.response.Result;
import com.fufan.mtsaas.modules.sysmgr.sygroup.bo.request.GroupDetailQueryRequest;
import com.fufan.mtsaas.modules.sysmgr.sygroup.bo.request.GroupHQueryRequest;
import com.fufan.mtsaas.modules.sysmgr.sygroup.bo.request.GroupHSaveRequest;
import com.fufan.mtsaas.modules.sysmgr.sygroup.bo.request.RoleDetailRequest;
import com.fufan.mtsaas.modules.sysmgr.sygroup.bo.response.SYGroupQueryResponse;
import com.fufan.mtsaas.modules.sysmgr.sygroup.bo.response.SYgroupHResponse;
import com.fufan.mtsaas.modules.sysmgr.sygroup.bo.response.SysNewMenuResponse;
import com.fufan.mtsaas.modules.sysmgr.sygroup.model.SYgroupH;
import com.fufan.mtsaas.modules.sysmgr.sygroup.service.SYgroupHSvc;
import com.fufan.mtsaas.util.JSonUtil;
import com.fufan.mtsaas.util.ParamUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpSession;
import javax.validation.Valid;

/**
 * <p>
 * 
 * </p>
 *
 * @author Liby
 * @since 2019-08-18
 */
@Slf4j
@Api(tags = "MTSaas：系统管理-角色组信息模块", description = "SYgroupH对象接口")
@RestController
@RequestMapping("/SYS/SYgroupH")
public class SYgroupHCtrl {
    @Autowired
    private SYgroupHSvc targetService;

    /**
     * 分页查询
     * */
    @ApiOperation(value = "分页查询所有，根据需要传入分页参数：pageSize每页数量(默认为10)，currentPage当前页数(默认为1)", httpMethod = "POST", produces = "application/json")
    @PostMapping(value ="/doQueryPage")
    public Result<SYGroupQueryResponse> doQueryPage(@RequestBody @ApiIgnore DataRequest dataRequest, GroupHQueryRequest request){
        ResultPack resultPack = new ResultPack();
        RequestPojo requestPojo = ParamUtil.doChange();
        JSONObject mapdata = dataRequest.getData().getParam();
        GroupHQueryRequest map = JSonUtil.toBean(mapdata.toJSONString(), GroupHQueryRequest.class);

        return resultPack.doResultPack(targetService.doQueryPage(map,requestPojo),requestPojo.getIntfId(),requestPojo.getAppKey());
    }

    /**
     * 明细查询
     * */
    @ApiOperation(value = "明细数据", httpMethod = "POST", produces = "application/json")
    @PostMapping(value ="/doQueryDetail")
    public Result<GroupHSaveRequest> doQueryDetail(@RequestBody @ApiIgnore DataRequest dataRequest, GroupDetailQueryRequest request){
        ResultPack resultPack = new ResultPack();
        RequestPojo requestPojo = ParamUtil.doChange();
        JSONObject mapdata = dataRequest.getData().getParam();
        GroupDetailQueryRequest map = JSonUtil.toBean(mapdata.toJSONString(), GroupDetailQueryRequest.class);

        return resultPack.doResultPack(targetService.doQueryDetail(map,requestPojo),requestPojo.getIntfId(),requestPojo.getAppKey());
    }

    /**
     * 获取菜单目录
     * */
    @ApiOperation(value = "获取菜单目录", httpMethod = "POST", produces = "application/json")
    @PostMapping(value ="/doQueryMenuData")
    public Result<SysNewMenuResponse> doQueryMenuData(@RequestBody @ApiIgnore DataRequest dataRequest, GroupDetailQueryRequest request){
        ResultPack resultPack = new ResultPack();
        RequestPojo requestPojo = ParamUtil.doChange();
        JSONObject mapdata = dataRequest.getData().getParam();
        GroupDetailQueryRequest map = JSonUtil.toBean(mapdata.toJSONString(), GroupDetailQueryRequest.class);

        return resultPack.doResultPack(targetService.doQueryMenuData(map,requestPojo),requestPojo.getIntfId(),requestPojo.getAppKey());
    }
    /**
     * 新增
     * */
    @ApiOperation(value = "新增", httpMethod = "POST", produces = "application/json")
    @RequestMapping(value = "/doSave", method = RequestMethod.POST)
    public Result doSaveMap(@RequestBody @ApiIgnore @Valid DataRequestT<GroupHSaveRequest> dataRequest, GroupHSaveRequest request, @ApiIgnore HttpSession session){
        ResultPack resultPack = new ResultPack();
        RequestPojo requestPojo = ParamUtil.doChange();

        return resultPack.doResultPack(targetService.doSaveMap(dataRequest.getData().getParam(), requestPojo), requestPojo.getIntfId(),requestPojo.getAppKey());
    }

    /**
     * 修改
     * */
    @ApiOperation(value = "修改", httpMethod = "PUT", produces = "application/json")
    @RequestMapping(value = "/doUpdate",method = RequestMethod.PUT)
    public Result doUpdate(@RequestBody @ApiIgnore @Valid DataRequestT<GroupHSaveRequest> dataRequest, GroupHSaveRequest request, @ApiIgnore HttpSession session){
        ResultPack resultPack = new ResultPack();
        RequestPojo requestPojo = ParamUtil.doChange();

        return resultPack.doResultPack(targetService.doUpdateMap(dataRequest.getData().getParam(), requestPojo), requestPojo.getIntfId(),requestPojo.getAppKey());
    }

    /**
     * 删除数据
     * */
    @ApiOperation(value = "删除数据", httpMethod = "DELETE", produces = "application/json")
    @RequestMapping(value = "/doDelete", method = RequestMethod.DELETE)
    public Result doDelete(@RequestBody @ApiIgnore DataRequest dataRequest, GroupDetailQueryRequest request){
        ResultPack resultPack = new ResultPack();
        RequestPojo requestPojo = ParamUtil.doChange();
        JSONObject mapdata = dataRequest.getData().getParam();
        GroupHQueryRequest map = JSonUtil.toBean(mapdata.toJSONString(), GroupHQueryRequest.class);

        return resultPack.doResultPack(targetService.doDelete(map, requestPojo), requestPojo.getIntfId(),requestPojo.getAppKey());
    }
}
