package com.chinacreator.video.restful.controller;

import com.chinacreator.video.exception.BussinessException;
import com.chinacreator.video.restful.service.WoplusReqService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;

/**
 * @author yu.su
 * @date 2021.4.28
 */
@RestController
public class WoplusReqController {


    @Autowired
    private WoplusReqService woplusReqService;

    private Logger logger=Logger.getLogger("woplusReq");

   @PostMapping("/woplusReq")
    public Map<String,Object> insert(@RequestBody Map<String,Object> params){
        String resultCode="0";
        String resultInfo="";
        try {
            woplusReqService.busiCheck(params);
            woplusReqService.insert(params);
        } catch (Exception e) {
            e.printStackTrace();
            if (e instanceof BussinessException){
                resultCode=((BussinessException) e).getCode();
                resultInfo=e.getMessage();
            }else {
                resultCode="8000";
                resultInfo="系统异常,请稍后再试";
            }
        }
        Map<String, Object> res = new HashMap<>();
        res.put("resultCode",resultCode);
        res.put("resultInfo",resultInfo);
        logger.info("woplusReq请求参数=========="+params+"====woplusReq返回参数======"+params);
        return res;
    }
}
