123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- package com.synyi.edc.controller;
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import javax.annotation.Resource;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.stereotype.Controller;
- import org.springframework.ui.Model;
- import org.springframework.util.CollectionUtils;
- import org.springframework.web.bind.annotation.RequestMapping;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONObject;
- import com.synyi.edc.pojo.Parameter;
- import com.synyi.edc.service.ISqlbuilderService;
- import com.synyi.edc.service.IUserService;
- import com.synyi.edc.util.SqlBuilderUtils;
- /**
- * sql语句生成主要contorller
- * @author wy
- *
- */
- @Controller
- @RequestMapping("/sqlbuilder")
- public class SqlbuilderController {
- @Resource
- private IUserService userService;
-
- @Resource
- private ISqlbuilderService sqlbuilderService;
-
-
- @RequestMapping("/toIndex")
- public String toJ(HttpServletRequest request,Model model){
- // int userId = Integer.parseInt(request.getParameter("id"));
- // User user = this.userService.getUserById(userId);
- // model.addAttribute("user", user);
- return "index";
- }
- /**
- * sql生成方法
- * @param request
- * @param model
- * @param param
- * @param res
- * @return
- */
- @RequestMapping("/generate")
- public String generate(HttpServletRequest request,Model model,Parameter param,HttpServletResponse res){
- System.out.println(param);
- System.out.println();
- String jsonStr = param.getEventData();
- String stepStr = param.getGroupData();
-
- String returnSql = SqlBuilderUtils.genGroupSql(jsonStr,stepStr);
-
- System.out.println(returnSql);
-
- printJson(res,returnSql);
- return null;
- }
-
- /**
- * 打印返回参数
- * @param res
- * @param str
- */
- public void printJson(HttpServletResponse res,String str){
-
- res.setContentType("text/plain");
- res.setCharacterEncoding("utf-8");
- res.setHeader("Access-Control-Allow-Origin", "*");
- res.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
- res.setHeader("Access-Control-Max-Age", "3600");
- res.setHeader("Access-Control-Allow-Headers", "x-requested-with");
- PrintWriter pw = null;
- try {
- pw = res.getWriter();
- pw.write(str);
- } catch (IOException e) {
- e.printStackTrace();
- }finally{
- pw.flush();
- pw.close();
- }
- }
- /**
- * 获取所有的医院列表
- * @param request
- * @param model
- * @param res
- * @return
- */
- @RequestMapping("/getAllOrg")
- public String getAllOrg(HttpServletRequest request,Model model,HttpServletResponse res){
-
- List<Parameter> par = sqlbuilderService.getAllOrgInfo();
- List list = new ArrayList();
- for(Parameter p:par){
- Map map1 = new HashMap();
- map1.put("value", p.getOrgCode());
- map1.put("label", p.getOrgName());
- list.add(map1);
- }
-
- String jsonString = JSONObject.toJSON(list).toString();
- printJson(res,jsonString);
- return null;
- }
- /**
- * 模糊匹配获取所有的检查名称
- * @param request
- * @param model
- * @param res
- * @param param
- * @return
- */
- @RequestMapping("/getAlllabInfo")
- public String getAllLabInfo(HttpServletRequest request,Model model,HttpServletResponse res,Parameter param){
-
- List<Parameter> par = sqlbuilderService.getAllLabInfo(param);
- List list = new ArrayList();
- for(Parameter p:par){
- Map map1 = new HashMap();
- map1.put("value", p.getItemId());
- map1.put("label", p.getItemName());
- list.add(map1);
- }
-
- String jsonString = JSONObject.toJSON(list).toString();
- printJson(res,jsonString);
- return null;
- }
-
- /**
- * 获取检验结果,文本结果和数字结果等suggestion列表
- * @param request
- * @param model
- * @param res
- * @param param
- * @return
- */
- @RequestMapping("/getSuggestionList")
- public String getSuggestionList(HttpServletRequest request,Model model,HttpServletResponse res,Parameter param){
-
- List<Parameter> par = sqlbuilderService.getSuggestionList(param);
- List list = new ArrayList();
- for(Parameter p:par){
- //c.item_name,text_value,numerical_value,reference_range,abnormal_flag_name
- Map map1 = new HashMap();
- map1.put("itemName", p.getItemName());
- map1.put("textValue", p.getTextValue());
- map1.put("numericalValue", p.getNumericalValue());
- map1.put("referenceRange", p.getReferenceRange());
- map1.put("abnormalFlagName", p.getAbnormalFlagName());
- list.add(map1);
- }
-
- String jsonString = JSONObject.toJSON(list).toString();
- printJson(res,jsonString);
- return null;
- }
-
- /**
- * 模糊匹配获取所有的药品名称
- * @param request
- * @param model
- * @param res
- * @param param
- * @return
- */
- @RequestMapping("/getAllDrugInfo")
- public String getAllDrugInfo(HttpServletRequest request,Model model,HttpServletResponse res,Parameter param){
-
- List<Parameter> par = sqlbuilderService.getAllDrugInfo(param);
- List list = new ArrayList();
- for(Parameter p:par){
- Map map1 = new HashMap();
- map1.put("value", p.getDrugId());
- map1.put("label", p.getDrugName());
- list.add(map1);
- }
-
- String jsonString = JSONObject.toJSON(list).toString();
- printJson(res,jsonString);
- return null;
- }
-
- }
|