<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Api id="__ClnbagETfn6kQhWmmjU">
  <name>模拟试卷</name>
  <parentId>__LgZds5MVHW3o08T7UcX</parentId>
  <applicationid>__LgZds5MVHW3o08T7UcX</applicationid>
  <status>published</status>
  <apiGroup></apiGroup>
  <encode>UTF-8</encode>
  <requestType>get</requestType>
  <requestUrl>/mock</requestUrl>
  <tags></tags>
  <responseType>json</responseType>
  <responseScript><![CDATA[(function(){
  var domainid = getDomainid();
  var areacode = "";
  var sqlp = "SELECT supervise_region_code FROM obpm2.tenant_organizations where id IN ('"+domainid+"')"
  var datasp = queryByDSName("tms",sqlp);
  if(datasp!=null){
    for(var iterator = datasp.iterator();iterator.hasNext();){
      var map1 = iterator.next();//取值
      areacode= map1.get("supervise_region_code");
    }
  }
  if(isNotNull(areacode)){
    areacode = areacode.substr(0,2);
  }
  var testid=""
  if("61".equals(areacode)){//西安
    testid="xa--__l3Ko9nPZUNquLF2vxi6"
  }else if("14".equals(areacode)){//晋城
    testid="jc--__l3Ko9nPZUNquLF2vxi6"
  }else if("11".equals(areacode)){//北京行业培训
    testid="bj--__l3Ko9nPZUNquLF2vxi6"
  }

    var result = new Packages.java.util.HashMap();
    var sqlMap = new Packages.java.util.HashMap();
    var selectExamInfoSql = "select item_singleNum,item_multipleNum,item_judgeNum,item_singleScore,item_multipleScore,item_judgeScore,item_testTopicBank from tlk_test_paper_base_info where id = '"+testid+"'"
    var selectExamInfo = queryByDSName("organizationAuth", selectExamInfoSql);
    if(selectExamInfo.size() > 0){
      for(var iterator = selectExamInfo.iterator();iterator.hasNext();){
        var map1 = iterator.next();//取值
        var singleNum = map1.get("item_singleNum");
        var multipleNum = map1.get("item_multipleNum");
        var judgeNum = map1.get("item_judgeNum");
        var singleScore = map1.get("item_singleScore");
        var multipleScore = map1.get("item_multipleScore");
        var judgeScore = map1.get("item_judgeScore");
        var testTopicBank = map1.get("item_testTopicBank");
        singleNum = singleNum.intValue();
        multipleNum = multipleNum.intValue();
        judgeNum = judgeNum.intValue();
        var singleSql = "SELECT '" + getDomainid() + "' as domainId, topic.ITEM_QUIZTOPIC, topic.ITEM_QUIZANALYSIS, CASE topic.ITEM_QUIZTYPE WHEN 0 THEN '单选题' WHEN 1 THEN '多选题' ELSE '判断题' END AS ITEM_QUIZTYPE,topic.id, 	case topic.ITEM_ANSWER when '对' then 'A' when '错' then 'B' else ITEM_ANSWER end ITEM_ANSWER," + singleScore + " AS item_myscore, topic.id AS item_id, option_data.item_option FROM tlk_test_quiz_base_info topic JOIN (SELECT CONCAT( GROUP_CONCAT( CONCAT( IFNULL(ITEM_OPTIONNAME,''), '#$#', IFNULL(ITEM_OPTIONCONTENT,''), '#$#', IFNULL(item_optionImage,'') ) ORDER BY ITEM_OPTIONNAME ASC SEPARATOR '$$' ) ) AS item_option, ITEM_QUIZID FROM tlk_test_quiz_option GROUP BY ITEM_QUIZID) AS option_data ON topic.id = option_data.ITEM_QUIZID WHERE topic.ITEM_QUIZTYPE = 0 AND topic.ITEM_TOPICBANKID = '" + testTopicBank + "' ORDER BY RAND() LIMIT " + singleNum 
        var multipleSql = "SELECT '" + getDomainid() + "' as domainId, topic.ITEM_QUIZTOPIC, topic.ITEM_QUIZANALYSIS, CASE topic.ITEM_QUIZTYPE WHEN 0 THEN '单选题' WHEN 1 THEN '多选题' ELSE '判断题' END AS ITEM_QUIZTYPE,topic.id, 	case topic.ITEM_ANSWER when '对' then 'A' when '错' then 'B' else ITEM_ANSWER end ITEM_ANSWER," + multipleScore + " AS item_myscore, topic.id AS item_id, option_data.item_option FROM tlk_test_quiz_base_info topic JOIN (SELECT CONCAT( GROUP_CONCAT( CONCAT( IFNULL(ITEM_OPTIONNAME,''), '#$#', IFNULL(ITEM_OPTIONCONTENT,''), '#$#', IFNULL(item_optionImage,'') ) ORDER BY ITEM_OPTIONNAME ASC SEPARATOR '$$' ) ) AS item_option, ITEM_QUIZID FROM tlk_test_quiz_option GROUP BY ITEM_QUIZID) AS option_data ON topic.id = option_data.ITEM_QUIZID WHERE topic.ITEM_QUIZTYPE = 1 AND topic.ITEM_TOPICBANKID = '" + testTopicBank + "' ORDER BY RAND() LIMIT " + multipleNum
        var judgeSql = "SELECT '" + getDomainid() + "' as domainId, topic.ITEM_QUIZTOPIC, topic.ITEM_QUIZANALYSIS, 'A#$#对#$#$$B#$#错' AS item_option, CASE topic.ITEM_QUIZTYPE WHEN 0 THEN '单选题' WHEN 1 THEN '多选题' ELSE '判断题' END AS ITEM_QUIZTYPE, id, 	case topic.ITEM_ANSWER when '对' then 'A' when '错' then 'B' else ITEM_ANSWER end ITEM_ANSWER, " + judgeScore + " AS item_myscore , topic.id AS item_id  FROM tlk_test_quiz_base_info topic WHERE ITEM_QUIZTYPE = 2 AND ITEM_TOPICBANKID = '" + testTopicBank + "' ORDER BY RAND() LIMIT " + judgeNum
        sqlMap.put("singleSql", singleSql);
        sqlMap.put("multipleSql", multipleSql);
        sqlMap.put("judgeSql", judgeSql);
      }
    } else {
      result.put("type","-1");
      result.put("msg","试卷配置信息无效");
      return result;
    }
    var singleSql = sqlMap.get("singleSql")
    var multipleSql = sqlMap.get("multipleSql")
    var judgeSql = sqlMap.get("judgeSql")

    var single_sqlDatas = queryByDSName("organizationAuth", singleSql);
    var multi_sqlDatas = queryByDSName("organizationAuth", multipleSql);
    var judge_sqlDatas = queryByDSName("organizationAuth", judgeSql);

    single_sqlDatas = unionCollection(single_sqlDatas,multi_sqlDatas);
    single_sqlDatas = unionCollection(single_sqlDatas,judge_sqlDatas);

    result.put("data", single_sqlDatas);
    return result;

  })()]]></responseScript>
</Api>