package com.ozs.rpm.controller.test;

import com.ozs.rpm.service.ReportDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ozs.rpm.util.JsonUtil;
import com.ozs.rpm.util.R;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = { "转发测试" })
@RestController
public class TestController {
	
	@Value(value="classpath:json/report.json")
	private Resource resource;
    
    @ApiOperation("测试")
    @GetMapping("/rpm/test")
    public String test() {
        return "sss";
    }
    
    @ApiOperation("保存报表")
    @PostMapping("/rpm/saveReport")
    public JSON saveReport(@RequestBody(required=false) JSONObject reportElement) {
    	return (JSON) JSON.parse(JsonUtil.getFileJson(resource));
    } 

    @ApiOperation("修改报表")
    @PutMapping("/rpm/updateReport")
    public JSON updateReport(@RequestBody(required=false) JSONObject reportElement) {
    	return (JSON) JSON.parse(JsonUtil.getFileJson(resource));
    } 
    
    @ApiOperation("查询报表")
    @GetMapping("/rpm/getReoprt")
    public JSON getReoprt(@RequestParam String reportId, @RequestParam int currentStep) {
        return (JSON) JSON.parse(JsonUtil.getFileJson(resource));
    } 
    
    @Autowired
    private ReportDataService reportDataService;
    
    @ApiOperation("获取报表数据")
    @GetMapping("/rpm/saveReportSql")
    public R<String> saveReportSql(@RequestParam("id") String reportId) {
        return reportDataService.saveReportSql(reportId);
    }
    
    public static void main(String[] args) {
        
        String sql = "select @slt^'——' 3574b058-020c-4938-aa2e-d72e4b87546e,'——' 912a8f1e-3234-4a6a-9270-f6a748af9880,@sum^@(^ format(sum((02839ca0-aba7-4c61-a22e-2ac5992f576b.num)+table_data_4.num),0) @)^ a7d396c3-3317-43ff-a4e1-72544e5d5455,@sum^@(^ format(sum(02839ca0-aba7-4c61-a22e-2ac5992f576b.price*02839ca0-aba7-4c61-a22e-2ac5992f576b.num),2) @)^ d9856a0b-ef6c-478e-b3e8-eb2f63ad0be8@slt^ from table_data_ddl_1table_data_4@whr^ where 1=1  and table_data_ddl_1.02839ca0-aba7-4c61-a22e-2ac5992f576b.id=table_data_4.255f317b-d31f-482a-945b-0ba944c1968c.id #time#  #query#  #other#  #page# @gry^ group by 3574b058-020c-4938-aa2e-d72e4b87546e,912a8f1e-3234-4a6a-9270-f6a748af9880 @gry^ #order# ";
        
        System.out.println(sql.replaceAll("@slt\\^", ""));
    }
}
