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.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.GroupDeptQueryRequest;
import com.fufan.mtsaas.modules.sysmgr.sygroup.bo.request.GroupDeptSaveBatchRequest;
import com.fufan.mtsaas.modules.sysmgr.sygroup.bo.request.GroupDeptSaveRequest;
import com.fufan.mtsaas.modules.common.bo.request.DataRequest;
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.GroupDeptQueryRequest;
import com.fufan.mtsaas.modules.sysmgr.sygroup.bo.request.GroupDeptSaveBatchRequest;
import com.fufan.mtsaas.modules.sysmgr.sygroup.bo.request.GroupDeptSaveRequest;
import com.fufan.mtsaas.modules.sysmgr.sygroup.model.SYgroupDept;
import com.fufan.mtsaas.modules.sysmgr.sygroup.service.SYgroupDeptSvc;
import com.fufan.mtsaas.util.JSonUtil;
import com.fufan.mtsaas.util.ParamUtil;
import io.swagger.annotations.*;
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;

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

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

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

    /**
     * 新增
     * */
    @ApiOperation(value = "新增", httpMethod = "POST", produces = "application/json")
//    @RequestMapping(value = "/doSave", method = RequestMethod.POST)
    public Result<SYgroupDept> doSaveMap(@RequestBody @ApiIgnore DataRequest dataRequest, GroupDeptSaveRequest request, @ApiIgnore HttpSession session){
        ResultPack resultPack = new ResultPack();
        RequestPojo requestPojo = ParamUtil.doChange();
        JSONObject mapdata = dataRequest.getData().getParam();
        GroupDeptSaveRequest map = JSonUtil.toBean(mapdata.toJSONString(), GroupDeptSaveRequest.class);

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

    /**
     * 修改
     * */
    @ApiOperation(value = "修改", httpMethod = "PUT", produces = "application/json")
//    @RequestMapping(value = "/doUpdate", method = RequestMethod.PUT)
    public Result<SYgroupDept> doUpdateMap(@RequestBody @ApiIgnore DataRequest dataRequest, GroupDeptSaveRequest request, @ApiIgnore HttpSession session){
        ResultPack resultPack = new ResultPack();
        RequestPojo requestPojo = ParamUtil.doChange();
        JSONObject mapdata = dataRequest.getData().getParam();
        GroupDeptSaveRequest map = JSonUtil.toBean(mapdata.toJSONString(), GroupDeptSaveRequest.class);

        return resultPack.doResultPack(targetService.doUpdateMap(map, 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, GroupDeptQueryRequest request){
        ResultPack resultPack = new ResultPack();
        RequestPojo requestPojo = ParamUtil.doChange();
        JSONObject mapdata = dataRequest.getData().getParam();
        GroupDeptQueryRequest map = JSonUtil.toBean(mapdata.toJSONString(), GroupDeptQueryRequest.class);

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

    /**
     * 分页查询
     * */
    @ApiOperation(value = "查询未选择的组部门记录", httpMethod = "GET", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "公司标识", name = "CompanyID", dataType = "string", required = true),
            @ApiImplicitParam(value = "组标识", name = "GroupID", dataType = "string", required = true)
    })
//    @PostMapping(value ="/doQueryUnSelectPage")
    public Result doQueryUnSelectPage(@RequestBody @ApiIgnore DataRequest dataRequest, GroupDeptQueryRequest request){
        ResultPack resultPack = new ResultPack();
        RequestPojo requestPojo = ParamUtil.doChange();

        JSONObject mapdata = dataRequest.getData().getParam();
        GroupDeptQueryRequest map = JSonUtil.toBean(mapdata.toJSONString(), GroupDeptQueryRequest.class);

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

    /**
     * 修改
     * */
    @ApiOperation(value = "批量处理", httpMethod = "POST", produces = "application/json")
//    @RequestMapping(value = "/doBatchUpdate", method = RequestMethod.POST)
    public Result doBatchUpdate(@RequestBody @ApiIgnore DataRequest dataRequest, GroupDeptSaveBatchRequest request, @ApiIgnore HttpSession session){
        ResultPack resultPack = new ResultPack();
        RequestPojo requestPojo = ParamUtil.doChange();

        JSONObject mapdata = dataRequest.getData().getParam();
        GroupDeptSaveBatchRequest map = JSonUtil.toBean(mapdata.toJSONString(), GroupDeptSaveBatchRequest.class);

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