package com.foreverwin.mesnac.common.controller;


import com.foreverwin.mesnac.common.model.CustomReport;
import com.foreverwin.mesnac.common.model.CustomReportConfig;
import com.foreverwin.mesnac.common.service.CustomReportConfigInterface;
import com.foreverwin.modular.core.util.CommonMethods;
import com.foreverwin.modular.core.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**  
 * 
 * @Title:  CustomReportConfigController.java   
 * @Package com.knsdev.webapi.ws   
 * @Description: 自定义报表配置 Controller  
 * @author: Andy    
 * @date:   2020年10月13日 下午4:18:54   
 * @version V1.0 
 *
 * @History 操作记录
 * 2020年10月13日 下午4:18:54 Andy add
 *
 * 相关联的FDS
 * ME-111-自定义报表配置 
 */

@RestController
@RequestMapping("/customReportConfig")
public class CustomReportConfigController {

	@Autowired
	private CustomReportConfigInterface configAPI;

 
	//报表作业编号弹出框
	@ResponseBody
	@GetMapping("/rptiddialog/{site}")
	public R rptIDDialogMethod(@PathVariable("site") String site)
	{
	  try{
			List<CustomReport>  rptIDList = configAPI.GetReportIDList(site);
			return R.ok(rptIDList);
		} catch (Exception ex) {
			return R.failed(ex.getMessage());
		}
	}
	
	//查询
	@ResponseBody
	@GetMapping("/query/{reportid}")
	public R queryMethod(@PathVariable("reportid") String reportid)
	{
	   try{
			CustomReportConfig config = configAPI.Query(reportid);
			return R.ok(config);
		} catch (Exception ex) {
		   return R.failed(ex.getMessage());
		}
	}

	//保存
	@ResponseBody
	@PostMapping("/")
	public R saveMethod(@RequestBody CustomReportConfig config)
	{
	 try{
			configAPI.Save(config);
		 	return R.ok("Success");
		} catch (Exception ex) {
			return R.failed(ex.getMessage());
		}
	}

	//删除
	@ResponseBody
	@GetMapping("/del//{site}/{reportid}")
	public R deleteMethod(@PathVariable("site") String site, @PathVariable("reportid") String reportid)
	{
	 try{
			configAPI.Delete(site, reportid);
			return R.ok("Success");
		} catch (Exception ex) {
			return R.failed(ex.getMessage());
		}
	}
}
