package cn.com.capcloud.api.action.myself.system.data;

import cn.com.capcloud.api.action.service.ApiDao;
import cn.com.capcloud.api.action.service.ApiService;
import cn.com.capcloud.ccui.core.common.json.JackJSONObject;
import cn.com.capcloud.core.cache.KHCRedisCache;
import cn.com.capcloud.core.noentitydb.BaseService;
import cn.com.capcloud.core.noentitydb.DefaultAction;
import cn.com.capcloud.core.system.user.UserService;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class DataHtmlViewAction extends DefaultAction {
    @Resource
    private BaseService baseService;
    @Resource
    private UserService userService;
    @Resource
    private KHCRedisCache khcRedisCache;
    @Resource
    private ApiService apiService;
    private static DataHtmlViewAction action;
    @PostConstruct
    public void init(){
        action=this;
        action.baseService=this.baseService;
        action.userService=this.userService;
        action.apiService =this.apiService;
        action.khcRedisCache =this.khcRedisCache;
    }
    public Map<String,Object> getHtmlViewInfo(String jsonStr, JackJSONObject retJson, HttpServletRequest request){
        JackJSONObject json= JackJSONObject.fromObject(jsonStr);
        Map<String,Object> retMap=new HashMap<>();
        String htmlViewCode= String.valueOf(json.get("htmlViewCode"));
        String sql="select * from tbl_data_html_view where html_view_code='"+htmlViewCode+"'";
        List<Map<String, Object>> list= this.getJdbcTemplate().queryForList(sql);
        String htmlViewSql=String.valueOf(list.get(0).get("html_view_sql"));
        if(!htmlViewSql.equals("null")&&htmlViewSql.length()>0){
            htmlViewSql= ApiDao.htmlDecode(htmlViewSql);
            List<Map<String, Object>> listMap=this.getJdbcTemplate().queryForList(htmlViewSql);
            list.get(0).put("data",listMap);
        }
        retMap.put("message","查询成功");
        retMap.put("htmlViewInfo",list.get(0));
        return retMap;
    }
}
