package com.prolog.rdc.tms.controller;

import com.prolog.framework.common.message.RestMessage;
import com.prolog.framework.log.aop.annotation.UserLog;
import com.prolog.rdc.tms.model.dto.ConfigurationQueryDDTO;
import com.prolog.rdc.tms.model.dto.ConfigurationQueryDTO;
import com.prolog.rdc.tms.model.vo.ConfigurationHDeleteVO;
import com.prolog.rdc.tms.model.vo.ConfigurationHSaveVO;
import com.prolog.rdc.tms.model.vo.ConfigurationHSetVO;
import com.prolog.rdc.tms.model.vo.ConfigurationQueryVO;
import com.prolog.rdc.tms.service.SysQueryConfigurationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 高级查询配置控制层 Controller
 *
 * @version :1.0.0
 * @className :SysQueryConfigurationController
 * @description :
 */
@RestController
@Api(tags = "高级查询配置控制层")
@RequestMapping("/sysQueryConfiguration")
public class SysQueryConfigurationController {

    @Autowired
    private SysQueryConfigurationService sysQueryConfigurationService;

    @UserLog("查询汇总")
    @ApiOperation(value = "查询汇总", notes = "查询汇总")
    @PostMapping("/queryConfigurationH/v1.0")
    public RestMessage<List<ConfigurationQueryDTO>> queryConfigurationH(@RequestBody ConfigurationQueryVO configurationQueryVO) {
        try {
            List<ConfigurationQueryDTO> configurationQueryDTOs = sysQueryConfigurationService.queryConfigurationH(configurationQueryVO);
            return RestMessage.newInstance(true, "操作成功", configurationQueryDTOs);
        } catch (Exception e) {
            e.printStackTrace();
            return RestMessage.newInstance(false, e.getMessage(), null);
        }
    }

    @UserLog("保存")
    @ApiOperation(value = "保存", notes = "保存")
    @PostMapping("/saveConfiguration/v1.0")
    public RestMessage<Object> saveConfiguration(@RequestBody List<ConfigurationHSaveVO> configurationHSaveVOs) {
        sysQueryConfigurationService.saveConfiguration(configurationHSaveVOs);
        return RestMessage.newInstance(true, "操作成功", null);
    }

    @UserLog("删除汇总")
    @ApiOperation(value = "删除汇总", notes = "删除汇总")
    @PostMapping("/deleteConfigurationH/v1.0")
    public RestMessage<Object> deleteConfigurationH(@RequestBody ConfigurationHDeleteVO configurationHDeleteVO) {
        sysQueryConfigurationService.deleteConfigurationH(configurationHDeleteVO);
        return RestMessage.newInstance(true, "操作成功", null);
    }

    @UserLog("设为默认")
    @ApiOperation(value = "设为默认", notes = "设为默认")
    @PostMapping("/setDefaultConfiguration/v1.0")
    public RestMessage<Object> setDefaultConfiguration(@RequestBody ConfigurationHSetVO configurationHSetVO) {
        sysQueryConfigurationService.setDefaultConfiguration(configurationHSetVO);
        return RestMessage.newInstance(true, "操作成功", null);
    }

    @UserLog("查询明细")
    @ApiOperation(value = "查询明细", notes = "查询明细")
    @PostMapping("/queryConfigurationD/v1.0")
    public RestMessage<List<ConfigurationQueryDDTO>> queryConfigurationD(@RequestParam String hId) {
        List<ConfigurationQueryDDTO> configurationQueryDDTOs = sysQueryConfigurationService.queryConfigurationD(hId);
        return RestMessage.newInstance(true, "操作成功", configurationQueryDDTOs);
    }

    @UserLog("获取高级查询配置")
    @ApiOperation(value = "获取高级查询配置", notes = "获取高级查询配置")
    @PostMapping("/getQueryConfiguration/v1.0")
    public RestMessage<String> getQueryConfiguration(@RequestParam("bizType") String bizType) {
        String sqlwhere = sysQueryConfigurationService.getQueryConfiguration(bizType);
        return RestMessage.newInstance(true, "操作成功", sqlwhere);
    }

}