package com.unis.detectionnum.server.controller;

import com.unis.common.utils.ResponseWrapper;
import com.unis.detectionnum.common.vo.RobotCallRecordBaseVo;
import com.unis.detectionnum.server.service.RobotCallRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author yangkaifeng
 * @version 1.0
 * @Title RecordCallController
 * @ProjectName 通话记录回调 Controller
 * @Description  TODO
 * @date 2019/12/17 17点26分
 */
@RestController
@Api(value = "通话记录回调", tags = "通话记录回调")
@Slf4j
public class RecordCallController {
    @Autowired
    RobotCallRecordService  robotCallRecordService;

    /**
     * @author yangkaifeng
     * @Description 新增通话记录回调信息
     * @return 新增状态
     */
    @PostMapping(value = "/recordCall")
    @ApiOperation(value = "新增通话记录回调", notes = "参数：通话记录")
    public ResponseWrapper insert(@RequestBody RobotCallRecordBaseVo robotCallRecordBaseVo) {
        try{
            if(robotCallRecordBaseVo==null) {
                return ResponseWrapper.success(HttpStatus.BAD_REQUEST.value(), "对象不能为空，请传相应的参数", null);
            }
            int x = robotCallRecordService.insert(robotCallRecordBaseVo);
            if(x>0) {
                return ResponseWrapper.success(HttpStatus.OK.value(), HttpStatus.OK.getReasonPhrase(),null);
            } else if (x==0) {
                return ResponseWrapper.success(HttpStatus.BAD_REQUEST.value(), "添加通话记录失败", null);
            } else if (x==-1) {
                return ResponseWrapper.success(HttpStatus.BAD_REQUEST.value(), "添加通话记录失败", null);
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
        }
        return ResponseWrapper.error(HttpStatus.INTERNAL_SERVER_ERROR.value(), HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(),"服务错误，请联系管理员");
    }
}
