package com.yonge.cooleshow.admin.controller.open;

import com.yonge.cooleshow.biz.dal.entity.SysConfig;
import com.yonge.cooleshow.biz.dal.service.SysConfigService;
import com.yonge.cooleshow.common.constant.SysConfigConstant;
import com.yonge.cooleshow.common.controller.BaseController;
import com.yonge.cooleshow.common.entity.HttpResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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 java.util.HashMap;
import java.util.Map;

/**
 * 系统配置控制层
 */
@RestController
@Api(tags = "系统参数设置")
@RequestMapping(value = "${app-config.url.admin:}/open/sysConfig")
public class OpenSysConfigController extends BaseController {

    @Autowired
    private SysConfigService sysConfigService;

    @ApiOperation(value = "查询客服手机号")
    @GetMapping(value = "/queryCustomerServicePhone")
    public HttpResponseResult<String> queryCustomerServicePhone() {
        SysConfig sysConfig = sysConfigService.findByParamName(SysConfigConstant.CUSTOMER_SERVICE_PHONE);
        return succeed(sysConfig.getParamValue());
    }

    @ApiOperation(value = "查询客服联系方式，电话和邮箱")
    @GetMapping(value = "/queryCustomerService")
    public HttpResponseResult<Map<String, String>> queryCustomerService() {
        SysConfig email = sysConfigService.findByParamName(SysConfigConstant.CUSTOMER_SERVICE_EMAIL);
        SysConfig phone = sysConfigService.findByParamName(SysConfigConstant.CUSTOMER_SERVICE_PHONE);
        Map<String, String> result = new HashMap<>();
        result.put("email", email == null ? "" : email.getParamValue());
        result.put("phone", phone == null ? "" : phone.getParamValue());
        return succeed(result);
    }

}
