package com.bjtdba.system.controller;

import com.alibaba.fastjson.JSON;
import com.bjtdba.entity.system.SystemConfig;
import com.bjtdba.system.service.SystemConfigService;
import com.bjtdba.utils.ResponseUtil;
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;

/**
 * 配置表(RrxSystemConfig)表控制层
 *
 * @author makejava
 * @since 2022-08-23 16:54:21
 */
@RestController
@RequestMapping("/system_service/sysconfig")
public class SystemConfigController {
    /**
     * 系统配置
     */
    @Autowired
    private SystemConfigService systemConfigService;



    /**
     * 通过主键查询单条数据
     *
     * @param key 主键
     * @return 单条数据
     */
    @GetMapping("/queryByKey")
    public Object  queryByKey(String key) {
        Map<String,Object> data=new HashMap<String,Object>();
        SystemConfig systemConfig=this.systemConfigService.queryBykey(key);
        data.put("status",systemConfig.getStatus()+"");
        data.put("configName",systemConfig.getConfigName());
//        data.put("sysconfig",systemConfig);
        return ResponseUtil.ok(data);
    }

    /**
     * 微信小程序收款隐藏接口    key = wx_config_show    2隐藏  1显示
     */
    @GetMapping("/wxQueryByKey")
    public Object  wxQueryByKey(String key) {

        /*SystemConfig systemConfig=this.rrxSystemConfigService.wxQueryByKey(key);
        data.put("status",systemConfig.getStatus()+"");
        data.put("configName",systemConfig.getConfigName());*/
//        data.put("sysconfig",systemConfig);
        return systemConfigService.wxQueryByKey(key);
    }


    /**
     * 小程序首页分享
     *
     * @return 单条数据
     */
    @GetMapping("/xiaoShare")
    public Object  queryByKey() {
        Map<String,Object> data=new HashMap<String,Object>();
        String title=this.systemConfigService.configValeByKey("xiao_title");
        String info=this.systemConfigService.configValeByKey("xiao_info");
        String image=this.systemConfigService.configValeByKey("xiao_image");
        data.put("title", JSON.parse(title));
        data.put("info",JSON.parse(info));
        data.put("image",JSON.parse(image));
        return ResponseUtil.ok(data);
    }

}

