package com.fufan.mtsaas.modules.base.company.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.base.company.bo.request.CompanyQueryRequest;
import com.fufan.mtsaas.modules.base.company.bo.request.CompanySaveRequest;
import com.fufan.mtsaas.modules.base.company.bo.request.back.CompanyBackQueryRequest;
import com.fufan.mtsaas.modules.base.company.bo.request.back.CompanyBackSaveRequest;
import com.fufan.mtsaas.modules.base.company.bo.response.CompanyDataResponse;
import com.fufan.mtsaas.modules.base.company.bo.response.back.CompanyBackQueryResponse;
import com.fufan.mtsaas.modules.base.company.model.TCompany;
import com.fufan.mtsaas.modules.base.company.service.TCompanySvc;
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.validation.Valid;

/**
 * <p>
 * 企业信息相关接口
 * </p>
 *
 * @author Liby
 * @since 2022-03-16
 */
@Api(tags = "MTSaas：企业管理-企业信息相关接口", description = "Company对象接口")
@RestController
@RequestMapping("/SYS/Company")
@Slf4j
public class TCompanyCtrl {
    @Autowired
    private TCompanySvc targetService;

    /**
     * 分页查询企业信息表
     * */
    @ApiOperation(value = "分页查询所有企业信息表，根据需要传入分页参数：pageSize每页数量(默认为20)，currentPage当前页数(默认为1)", httpMethod = "POST", produces = "application/json")
    @PostMapping(value ="/doQueryPage")
    public Result<CompanyDataResponse> doQueryPage(@RequestBody @ApiIgnore DataRequest dataRequest, CompanyQueryRequest paramRequest){
        ResultPack resultPack = new ResultPack();
        RequestPojo requestPojo = ParamUtil.doChange();
        JSONObject mapdata = dataRequest.getData().getParam();
        CompanyQueryRequest map = JSonUtil.toBean(mapdata.toJSONString(), CompanyQueryRequest.class);
        return resultPack.doResultPack(targetService.doQueryPage(map,requestPojo),requestPojo.getIntfId(),requestPojo.getAppKey());

    }

    /**
     * 后台新增企业客户接口
     * */
    @ApiOperation(value = "后台新增企业客户接口", httpMethod = "POST", produces = "application/json")
    @RequestMapping(value ="/backData/doSave", method = RequestMethod.POST)
    public Result doSave(@RequestBody  @ApiIgnore @Valid DataRequestT<CompanyBackSaveRequest> dataRequest, CompanyBackSaveRequest paramRequest){
        log.debug("backData/doSave parameter: {}", dataRequest);
        ResultPack resultPack = new ResultPack();
        RequestPojo requestPojo = ParamUtil.doChange();
        return resultPack.doResultPack(targetService.doSave(dataRequest.getData().getParam(),requestPojo),requestPojo.getIntfId(),requestPojo.getAppKey());
    }

    /**
     * 后台分页查询企业客户信息
     * */
    @ApiOperation(value = "后台分页查询企业客户，根据需要传入分页参数：pageSize每页数量(默认为20)，currentPage当前页数(默认为1)", httpMethod = "POST", produces = "application/json")
    @PostMapping(value ="/backData/doQueryPage")
    public Result<CompanyBackQueryResponse> backDataQueryPage(@RequestBody @ApiIgnore DataRequest dataRequest, CompanyBackQueryRequest paramRequest){
        ResultPack resultPack = new ResultPack();
        RequestPojo requestPojo = ParamUtil.doChange();
        JSONObject mapdata = dataRequest.getData().getParam();
        CompanyBackQueryRequest map = JSonUtil.toBean(mapdata.toJSONString(), CompanyBackQueryRequest.class);
        return resultPack.doResultPack(targetService.doBackQueryPage(map,requestPojo),requestPojo.getIntfId(),requestPojo.getAppKey());
    }

    /**
     * 后台修改企业客户接口
     * */
    @ApiOperation(value = "后台修改企业客户接口", httpMethod = "POST", produces = "application/json")
    @RequestMapping(value ="/backData/doUpdate", method = RequestMethod.POST)
    public Result backDataSave(@RequestBody  @ApiIgnore @Valid DataRequestT<CompanyBackSaveRequest> dataRequest, CompanyBackSaveRequest paramRequest){
        log.debug("backData/doUpdate parameter: {}", dataRequest);
        ResultPack resultPack = new ResultPack();
        RequestPojo requestPojo = ParamUtil.doChange();
        return resultPack.doResultPack(targetService.backDataUpdate(dataRequest.getData().getParam(),requestPojo),requestPojo.getIntfId(),requestPojo.getAppKey());
    }

    /**
     * 修改
     * */
    @ApiOperation(value = "修改企业信息表", httpMethod = "PUT", produces = "application/json")
    @RequestMapping(value ="/doUpdate", method = RequestMethod.PUT)
    public Result<TCompany> doUpdate(@RequestBody @ApiIgnore @Valid DataRequestT<CompanySaveRequest> dataRequest, CompanySaveRequest paramRequest){
        log.debug("doUpdate parameter: {}", dataRequest);
        ResultPack resultPack = new ResultPack();
        RequestPojo requestPojo = ParamUtil.doChange();
//        JSONObject mapdata = dataRequest.getData().getParam();
//        CompanySaveRequest map = JSonUtil.toBean(mapdata.toJSONString(), CompanySaveRequest.class);
        return resultPack.doResultPack(targetService.doUpdate(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, CompanyQueryRequest companyQueryRequest){
//        ResultPack resultPack = new ResultPack();
//        RequestPojo requestPojo = ParamUtil.doChange();
//        JSONObject mapdata = dataRequest.getData().getParam();
//        CompanyQueryRequest map = JSonUtil.toBean(mapdata.toJSONString(), CompanyQueryRequest.class);
//        return resultPack.doResultPack(targetService.doDelete(map,requestPojo),requestPojo.getIntfId(),requestPojo.getAppKey());
//    }
	
}
