package com.ideabobo.controller;
import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import com.alibaba.fastjson.JSON;
import com.ideabobo.model.Dbservice;
import com.ideabobo.model.Dbtablemapping;
import com.ideabobo.service.DatabaseService;
import com.ideabobo.util.Common;
import com.ideabobo.util.Page;
import com.ideabobo.util.QRCodeUtil;
import com.ideabobo.util.StringUtil;
@CrossOrigin(origins="*")
@Controller
@RequestMapping(value = "/database")
public class DatabaseController {
//private static final Logger logger = Logger.getLogger(DatabaseController.class);
@Autowired
private DatabaseService databaseService;
@RequestMapping(value = "/list", produces = "application/json; charset=utf-8", method = { RequestMethod.GET,
RequestMethod.POST })
@ResponseBody
public List<Map<String,Object>> list(HttpServletRequest req) {
Dbservice dbm = new Dbservice(databaseService);
String table = Dbservice.getTableName(req.getParameter("table"));
Object objectObj = Common.getByRequest(Dbtablemapping.getModelByTable(table), req, false);
//Robj robj = new Robj();
List<Map<String,Object>> list = null;
try {
String sql = dbm.list(table,objectObj);
list = databaseService.find(sql);
} catch (Exception e) {
e.printStackTrace();
}
return list;
}
@RequestMapping(value = "/listJ", produces = "text/plain; charset=utf-8", method = { RequestMethod.GET,
RequestMethod.POST })
@ResponseBody
public String listJ(HttpServletRequest req) {
Dbservice dbm = new Dbservice(databaseService);
String table = Dbservice.getTableName(req.getParameter("table"));
Object objectObj = Common.getByRequest(Dbtablemapping.getModelByTable(table), req, false);
//Robj robj = new Robj();
List<Map<String,Object>> list = null;
try {
String sql = dbm.list(table,objectObj);
list = databaseService.find(sql);
} catch (Exception e) {
e.printStackTrace();
}
return renderJsonp(list, req);
}
@RequestMapping(value = "/find", produces = "application/json; charset=utf-8", method = { RequestMethod.GET,
RequestMethod.POST })
@ResponseBody
public Map<String,Object> find(HttpServletRequest req) {
Dbservice dbm = new Dbservice(databaseService);
String table = Dbservice.getTableName(req.getParameter("table"));
Object objectObj = Common.getByRequest(Dbtablemapping.getModelByTable(table), req, false);
//Robj robj = new Robj();
List<Map<String,Object>> list = null;
try {
String sql = dbm.list(table,objectObj);
list = databaseService.find(sql);
} catch (Exception e) {
e.printStackTrace();
}
if (list!=null && list.size()>0) {
return list.get(0);
}else{
return null;
}
}
@RequestMapping(value = "/findJ", produces = "text/plain; charset=utf-8", method = { RequestMethod.GET,
RequestMethod.POST })
@ResponseBody
public String findJ(HttpServletRequest req) {
Dbservice dbm = new Dbservice(databaseService);
String table = Dbservice.getTableName(req.getParameter("table"));
Object objectObj = Common.getByRequest(Dbtablemapping.getModelByTable(table), req, false);
//Robj robj = new Robj();
List<Map<String,Object>> list = null;
try {
String sql = dbm.list(table,objectObj);
list = databaseService.find(sql);
} catch (Exception e) {
e.printStackTrace();
}
if (list!=null && list.size()>0) {
return renderJsonp(list.get(0), req);
}else{
return renderJsonp(null, req);
}
}
@RequestMapping(value = "/listApp", produces = "application/json; charset=utf-8", method = { RequestMethod.GET,
RequestMethod.POST })
@ResponseBody
public List<Map<String,Object>> listApp(HttpServletRequest req) {
Dbservice dbm = new Dbservice(databaseService);
String table = Dbservice.getTableName(req.getParameter("table"));
//Robj robj = new Robj();
List<Map<String,Object>> list = null;
try {
String object = req.getParameter("object");
//if(StringUtil.isNotNullOrEmpty(object)){
Object objectObj = Dbtablemapping.parseStringModel(object, table);
String sql = dbm.list(table,objectObj);
list = databaseService.find(sql);
//robj.setData(databaseService.find(sql));
//}
} catch (Exception e) {
e.printStackTrace();
}
return list;
}
@RequestMapping(value = "/listC", produces = "text/plain; charset=utf-8", method = { RequestMethod.GET,
RequestMethod.POST })
@ResponseBody
public String listC(HttpServletRequest req) {
Dbservice dbm = new Dbservice(databaseService);
String table = Dbservice.getTableName(req.getParameter("table"));
//Robj robj = new Robj();
List<Map<String,Object>> list = null;
try {
String object = req.getParameter("object");
//if(StringUtil.isNotNullOrEmpty(object)){
Object objectObj = Dbtablemapping.parseStringModel(object, table);
String sql = dbm.list(table,objectObj);
list = databaseService.find(sql);
//robj.setData(databaseService.find(sql));
//}
} catch (Exception e) {
e.printStackTrace();
}
return renderJsonp(list, req);
}
@RequestMapping(value = "/findApp", produces = "application/json; charset=utf-8", method = { RequestMethod.GET,
RequestMethod.POST })
@ResponseBody
public Map<String,Object> findApp(HttpServletRequest req) {
Dbservice dbm = new Dbservice(databaseService);
String table = Dbservice.getTableName(req.getParameter("table"));
//Robj robj = new Robj();
List<Map<String,Object>> list = null;
try {
String object = req.getParameter("object");
//if(StringUtil.isNotNullOrEmpty(object)){
Object objectObj = Dbtablemapping.parseStringModel(object, table);
String sql = dbm.list(table,objectObj);
list = databaseService.find(sql);
//robj.setData(databaseService.find(sql));
//}
} catch (Exception e) {
e.printStackTrace();
}
if (list!=null && list.size()>0) {
return list.get(0);
}else{
return null;
}
}
@RequestMapping(value = "/findC", produces = "text/plain; charset=utf-8", method = { RequestMethod.GET,
RequestMethod.POST })
@ResponseBody
public String findC(HttpServletRequest req) {
Dbservice dbm = new Dbservice(databaseService);
String table = Dbservice.getTableName(req.getParameter("table"));
//Robj robj = new Robj();
List<Map<String,Object>> list = null;
try {
String object = req.getParameter("object");
//if(StringUtil.isNotNullOrEmpty(object)){
Object objectObj = Dbtablemapping.parseStringModel(object, table);
String sql = dbm.list(table,objectObj);
list = databaseService.find(sql);
//robj.setData(databaseService.find(sql));
//}
} catch (Exception e) {
e.printStackTrace();
}
if (list!=null && list.size()>0) {
return renderJsonp(list.get(0), req);
}else{
return renderJsonp(null, req);
}
}
@RequestMapping(value = "/listPage", produces = "application/json; charset=utf-8", method = { RequestMethod.GET,
RequestMethod.POST })
@ResponseBody
public Page listPage(HttpServl