package com.chinacreator.video.restful.controller;

import com.chinacreator.video.exception.BussinessException;
import com.chinacreator.video.restful.service.BackBusiConfService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author yu.su
 * @date  2021.3.31
 * 后向产品配置
 */
@RestController
public class BackBusiConfController {

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

    @Autowired
    private BackBusiConfService backBusiConfService;
    @PostMapping("/backBusiConf")
    public Map<String,Object> backCheck(@RequestBody Map<String,Object>  params){
        logger.info("请求参数:"+params);
        String resultCode="0";
        String errorInfo="";
        Map<String,Object> respMap=new HashMap<>();
        Map<String,String> map=null;
        try {
             backBusiConfService.check(params);
             backBusiConfService.checkParams(params);
             map=backBusiConfService.addBakcBusiConf(params);
        } catch (Exception e) {
            e.printStackTrace();
            if (e instanceof BussinessException){
                resultCode= ((BussinessException) e).getCode();
                errorInfo= ((BussinessException) e).getMessage();
            }else{
                resultCode="8000";
                errorInfo="系统异常,请联系管理员!!!";
            }
        }finally {
            respMap.put("resultCode",resultCode);
            respMap.put("errorInfo",errorInfo);
            respMap.put("data",map);
            logger.info("响应参数==="+respMap);
        }
        return respMap;
    }
}
