package com.weaver.seconddev.meishi.controller;

import com.weaver.common.authority.annotation.WeaPermission;
import com.weaver.common.base.entity.result.WeaResult;
import com.weaver.seconddev.meishi.constant.Constants;
import com.weaver.seconddev.meishi.service.CreatePerformanceService;
import com.weaver.seconddev.meishi.util.CommonUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/api/secondev/lamex/addperformance")
public class CreatePerformanceController {
    private final Logger log = LoggerFactory.getLogger(CreatePerformanceController.class);

    @Autowired
    public CreatePerformanceService createPerformanceService ;

    @Autowired
    public CommonUtils CommonUtils;

    @GetMapping("/testWorkflow")
    @WeaPermission(publicPermission = true)
    public WeaResult<Object> testWorkflow(HttpServletRequest request){
        Map<String, Object> recordMap = new HashMap<String,Object>();
        log.error("testWorkflow");
        recordMap.put("test","test");
        return WeaResult.success(recordMap);
    }

    @GetMapping("/createWorkflowV1")
    @WeaPermission(publicPermission = true)
    public WeaResult<Object> createWorkflowV1(HttpServletRequest request){
        log.error("createWorkflowV1");
        Map<String,Object> requestMap = CommonUtils.requestToMap(request);
        log.error("TENANT_KEY:"+Constants.TENANT_KEY);
        Map<String, Object> recordMap = createPerformanceService.createWorkflowV1(Constants.TENANT_KEY,requestMap);
        return WeaResult.success(recordMap);
    }

}
