|
|
@@ -57,7 +57,7 @@ class report {
|
|
|
}
|
|
|
|
|
|
$rc = $_POST ['rc'];
|
|
|
- if ($rc == - 1) {
|
|
|
+ if ($rc == -1) {
|
|
|
$sql = "select count(*) from public.kln_report_template where " .$sqlWhere;
|
|
|
$rc = common::excuteOneSql($sql);
|
|
|
}
|
|
|
@@ -81,7 +81,7 @@ class report {
|
|
|
}
|
|
|
|
|
|
if ($operate == "add"){
|
|
|
- $serial_no = common::deCode($_REQUEST['serial_no'], 'D');
|
|
|
+ $serial_no = $_REQUEST['serial_no'];
|
|
|
if(!empty($serial_no)){
|
|
|
//代表编辑
|
|
|
$reportMain = common::excuteObjectSql("select *,
|
|
|
@@ -90,13 +90,22 @@ class report {
|
|
|
from kln_report_template where serial_no = '$serial_no'");
|
|
|
|
|
|
$reportFields = array();
|
|
|
- $reportField = common::excuteListSql("select field_id,field_level,field_type,field_db,field_display_name,
|
|
|
- field_display_name_user,data_type,custom_value_type,
|
|
|
- custom_fixed_value,is_filter_enabled,is_sort_enabled
|
|
|
- from kln_report_field_config where template_serial_no = '$serial_no' order by order_index");
|
|
|
+ $reportField = common::excuteListSql("select
|
|
|
+ field_id as ids,
|
|
|
+ field_level as \"fieldLevel\",
|
|
|
+ field_type as \"fieldType\",
|
|
|
+ field_group_name as \"groupName\",
|
|
|
+ field_db as field,
|
|
|
+ field_display_name as title,
|
|
|
+ field_display_name_user as \"displayName\",
|
|
|
+ data_type as \"dataType\",
|
|
|
+ custom_fixed_value as value,
|
|
|
+ is_filter_enabled as \"isFilter\",
|
|
|
+ is_sort_enabled as \"isSort\"
|
|
|
+ from kln_report_field_config where template_serial_no = '$serial_no' order by id");
|
|
|
foreach($reportField as $_reportField){
|
|
|
- $_reportField['is_filter_enabled'] = $_reportField['is_filter_enabled'] == 't' ? true : false;
|
|
|
- $_reportField['is_sort_enabled'] = $_reportField['is_sort_enabled'] == 't' ? true : false;
|
|
|
+ $_reportField['isFilter'] = $_reportField['isFilter'] == 't' ? true : false;
|
|
|
+ $_reportField['isSort'] = $_reportField['isSort'] == 't' ? true : false;
|
|
|
$reportFields[] = $_reportField;
|
|
|
}
|
|
|
|
|
|
@@ -117,7 +126,7 @@ class report {
|
|
|
}
|
|
|
|
|
|
if ($operate == "save"){
|
|
|
- $serial_no = common::deCode($_POST['serial_no'], 'D');
|
|
|
+ $serial_no = $_POST['serial_no'];
|
|
|
$name = common::check_input($_POST['report_name']);
|
|
|
$description = common::check_input($_POST['report_description']);
|
|
|
$level = common::check_input($_POST['report_level']);
|
|
|
@@ -125,23 +134,21 @@ class report {
|
|
|
$party_ids = $_POST['party_ids'];
|
|
|
$group_names = $_POST['group_names'];
|
|
|
|
|
|
- //字段配置信息
|
|
|
- $field_ids = $_POST['field_id'];
|
|
|
- $field_level = $_POST['field_level'];
|
|
|
- $field_type = $_POST['field_type'];
|
|
|
- $field_db = $_POST['field_db'];
|
|
|
- $field_code = $_POST['field_code'];
|
|
|
- $display_name = $_POST['display_name'];
|
|
|
- $data_type = $_POST['data_type'];
|
|
|
- $value_type = $_POST['value_type'];
|
|
|
- $fixed_value = $_POST['fixed_value'];
|
|
|
- $is_filter_enabled = $_POST['is_filter_enabled'];
|
|
|
- $is_sort_enabled = $_POST['is_sort_enabled'];
|
|
|
-
|
|
|
- $report_sql = common::excuteOneSql("select sql from public.kln_report_sql_manage where level = '$level'");
|
|
|
+ //单独处理字段id
|
|
|
+ $fieldsList = $_POST['fieldsList'];
|
|
|
+ $field_ids = array();
|
|
|
+ foreach($fieldsList as $_fieldsList){
|
|
|
+ if (!empty($_fieldsList['ids'])){
|
|
|
+ $field_ids[] = $_fieldsList['ids'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $report_sql_data = common::excuteObjectSql("select sql,count_sql from public.kln_report_sql_manage where level = '$level'");
|
|
|
$sql = "";
|
|
|
if (!empty($serial_no)){
|
|
|
- $updateSqlSet = " report_sql = '$report_sql', modify_by = '"._getLoginName()."',update_time = now()";
|
|
|
+ $updateSqlSet = " report_sql = '".common::check_input($report_sql_data['sql'])."',
|
|
|
+ count_sql = '".common::check_input($report_sql_data['count_sql'])."',
|
|
|
+ modify_by = '"._getLoginName()."',update_time = now()";
|
|
|
if (!empty($name)) {
|
|
|
$updateSqlSet.= ", name = '$name' ";
|
|
|
}
|
|
|
@@ -155,84 +162,79 @@ class report {
|
|
|
$updateSqlSet.= ", access_type = '$access_type' ";
|
|
|
}
|
|
|
if (!empty($party_ids)) {
|
|
|
- $pgsql_array = '"' . implode('","', array_map(fn($v) => str_replace("'", "''", $v), $party_ids)) . '"';
|
|
|
- $updateSqlSet.= ", party_ids = '{".$pgsql_array."}'::text[]";
|
|
|
+ $party_ids_filed= common::toPgTextArrayLiteral($party_ids);
|
|
|
+ $updateSqlSet.= ", party_ids = $party_ids_filed";
|
|
|
}
|
|
|
if (!empty($group_names)) {
|
|
|
- $pgsql_array = '"' . implode('","', array_map(fn($v) => str_replace("'", "''", $v), $group_names)) . '"';
|
|
|
- $updateSqlSet.= ", group_names = '{".$pgsql_array."}'::text[]";
|
|
|
+ $group_names_filed = common::toPgTextArrayLiteral($group_names);
|
|
|
+ $updateSqlSet.= ", group_names = $group_names_filed";
|
|
|
}
|
|
|
if (!empty($field_ids)) {
|
|
|
- $pgsql_array = '"' . implode('","', array_map(fn($v) => str_replace("'", "''", $v), $field_ids)) . '"';
|
|
|
- $updateSqlSet.= ", field_ids = '{".$pgsql_array."}'::INTEGER[]";
|
|
|
+ $ids_filed = common::toPgTextArrayLiteral($field_ids);
|
|
|
+ $updateSqlSet.= ", field_ids = $ids_filed";
|
|
|
}
|
|
|
//代表update
|
|
|
$sql .= "update public.kln_report_template set ".$updateSqlSet."
|
|
|
where serial_no = '$serial_no';";
|
|
|
} else {
|
|
|
- $party_ids_filed = null;
|
|
|
+ $party_ids_filed = "NULL";
|
|
|
if (!empty($party_ids)) {
|
|
|
- $pgsql_array = '"' . implode('","', array_map(fn($v) => str_replace("'", "''", $v), $party_ids)) . '"';
|
|
|
- $party_ids_filed= "'{".$pgsql_array."}'::text[]";
|
|
|
+ $party_ids_filed= common::toPgTextArrayLiteral($party_ids);
|
|
|
}
|
|
|
|
|
|
- $group_names_filed = null;
|
|
|
+ $group_names_filed = "NULL";
|
|
|
if (!empty($group_names)) {
|
|
|
- $pgsql_array = '"' . implode('","', array_map(fn($v) => str_replace("'", "''", $v), $group_names)) . '"';
|
|
|
- $group_names_filed = "'{".$pgsql_array."}'::text[]";
|
|
|
+ $group_names_filed = common::toPgTextArrayLiteral($group_names);
|
|
|
}
|
|
|
|
|
|
- $ids_filed = null;
|
|
|
+ $ids_filed = "NULL";
|
|
|
if (!empty($field_ids)) {
|
|
|
- $pgsql_array = '"' . implode('","', array_map(fn($v) => str_replace("'", "''", $v), $field_ids)) . '"';
|
|
|
- $ids_filed = "'{".$pgsql_array."}'::INTEGER[]";
|
|
|
+ $ids_filed = common::toPgTextArrayLiteral($field_ids);
|
|
|
}
|
|
|
|
|
|
$serial_no = common::uuid();
|
|
|
$sql .= "INSERT INTO public.kln_report_template(
|
|
|
- serial_no,name, description, level, field_ids, access_type, report_sql,
|
|
|
+ serial_no,name, description, level, field_ids, access_type, report_sql,count_sql,
|
|
|
party_ids, group_names, create_by, created_time, modify_by, update_time )
|
|
|
- VALUES ('$serial_no','$name', '$description', '$level', $ids_filed, '$access_type', '$report_sql'
|
|
|
- $party_ids_filed, $group_names_filed , '"._getLoginName()."', now(), '"._getLoginName()."', now());";
|
|
|
+ VALUES ('$serial_no','$name', '$description', '$level', $ids_filed, '$access_type',
|
|
|
+ '".common::check_input($report_sql_data['sql'])."','".common::check_input($report_sql_data['count_sql'])."',
|
|
|
+ $party_ids_filed, $group_names_filed , '"._getLoginName()."', now(), '"._getLoginName()."', now());";
|
|
|
}
|
|
|
-
|
|
|
- $errmsg = "";
|
|
|
- //柜子是先删除,后添加
|
|
|
+ //先删除,后添加
|
|
|
$sql .= "delete from public.kln_report_field_config where template_serial_no = '$serial_no';";
|
|
|
- foreach($field_ids as $key =>$_field_id){
|
|
|
- $_field_level = $field_level[$key];
|
|
|
- $_ield_type = $field_type[$key];
|
|
|
- $_field_db = $field_db[$key];
|
|
|
- $_field_code = $field_code[$key];
|
|
|
- $_display_name = $display_name[$key];
|
|
|
- $_data_type = $data_type[$key];
|
|
|
- $_value_type = $value_type[$key];
|
|
|
- $_fixed_value = $fixed_value[$key];
|
|
|
- $_is_filter_enabled = $is_filter_enabled[$key];
|
|
|
- $_is_sort_enabled = $is_sort_enabled[$key];
|
|
|
+ foreach($fieldsList as $key =>$_tempFieldsList){
|
|
|
+ $_field_id = empty($_tempFieldsList['ids'])? "NULL": $_tempFieldsList['ids'];
|
|
|
+ $_field_level = common::check_input($_tempFieldsList['fieldLevel']);
|
|
|
+ $_field_type = common::check_input($_tempFieldsList['fieldType']);
|
|
|
+ $_field_group_name = common::check_input($_tempFieldsList['groupName']);
|
|
|
+ $_field_db = common::check_input($_tempFieldsList['field']);
|
|
|
+ $_field_code = common::check_input($_tempFieldsList['title']);
|
|
|
+ $_display_name = common::check_input($_tempFieldsList['displayName']);
|
|
|
+ $_data_type = common::check_input($_tempFieldsList['dataType']);
|
|
|
+ $_value_type = $_field_type == "System" ? "" : (empty($_tempFieldsList['value']) ? "Blank" :"Fixed Value");
|
|
|
+ $_fixed_value = common::check_input($_tempFieldsList['value']);
|
|
|
+ $_is_filter_enabled = $_tempFieldsList['isFilter'];
|
|
|
+ $_is_sort_enabled = $_tempFieldsList['isSort'];
|
|
|
$sql .= "INSERT INTO public.kln_report_field_config(
|
|
|
- template_serial_no, field_id, field_level, field_type, field_db,
|
|
|
+ template_serial_no, field_id, field_level, field_type, field_db, field_group_name,
|
|
|
field_display_name, field_display_name_user, data_type, custom_value_type,
|
|
|
custom_fixed_value, is_filter_enabled, is_sort_enabled, created_time)
|
|
|
- VALUES ('$serial_no', '$_field_id', '$_field_level', '$_ield_type', '$_field_db',
|
|
|
+ VALUES ('$serial_no', $_field_id, '$_field_level', '$_field_type', '$_field_db', '$_field_group_name',
|
|
|
'$_field_code', '$_display_name', '$_data_type', '$_value_type',
|
|
|
'$_fixed_value', '$_is_filter_enabled', '$_is_sort_enabled',now());";
|
|
|
-
|
|
|
}
|
|
|
- if (empty($errmsg) && !empty($sql)){
|
|
|
+ if (!empty($sql)){
|
|
|
common::excuteUpdateSql($sql);
|
|
|
$data = array("msg" =>"success");
|
|
|
- } else {
|
|
|
- $data = array("msg" =>$errmsg);
|
|
|
- }
|
|
|
+ }
|
|
|
common::echo_json_encode(200,$data);
|
|
|
exit();
|
|
|
}
|
|
|
|
|
|
- if ($operate == "delete"){
|
|
|
- $serial_no = common::deCode($_POST['a'], 'D');
|
|
|
- $sql = "delete from public.kln_report_template where serial_no = '$serial_no';";
|
|
|
- $sql .= "delete from public.kln_report_field_config where template_serial_no = '$serial_no';";
|
|
|
+ if ($operate == "active"){
|
|
|
+ $serial_no =$_POST['serial_no'];
|
|
|
+ $is_active = $_POST['is_active'];
|
|
|
+ $sql = "update public.kln_report_template set is_active = '$is_active' where serial_no = '$serial_no';";
|
|
|
common::excuteUpdateSql($sql);
|
|
|
$data = array("msg" =>"success");
|
|
|
common::echo_json_encode(200,$data);
|
|
|
@@ -288,36 +290,236 @@ class report {
|
|
|
|
|
|
if ($operate == "report_detail") {
|
|
|
$serial_no = common::check_input($_POST ['serial_no']);
|
|
|
+ $dataReturn = array();
|
|
|
+ $tableColumns = array();
|
|
|
+ $filtersList = array();
|
|
|
+ $sortByOptions = array();
|
|
|
+ $reportFiled = common::excuteListSql("select * from public.kln_report_field_config where template_serial_no = '".$serial_no."'
|
|
|
+ and field_type = 'System' and is_enabled = true order by id ");
|
|
|
+ foreach($reportFiled as $filed){
|
|
|
+ if($filed['is_filter_enabled'] == 't'){
|
|
|
+ $type = $filed['data_type'] == "string" ? "input" : ($filed['data_type'] == "date" ? "date" : "input");
|
|
|
+ $filtersList[] = array(
|
|
|
+ "label"=>$filed['field_display_name_user'],
|
|
|
+ "field"=>$filed['field_display_name'],
|
|
|
+ "type"=>$type,
|
|
|
+ "data_type"=>$filed['data_type'],
|
|
|
+ "value"=>[],"options"=>[]);
|
|
|
+ }
|
|
|
+ if($filed['is_sort_enabled'] == 't'){
|
|
|
+ $sortByOptions[] = $filed['field_db'];
|
|
|
+ }
|
|
|
+
|
|
|
+ $temp = array();
|
|
|
+ $temp['field'] = $filed['field_display_name'];
|
|
|
+ $temp['title'] = $filed['field_display_name_user'];
|
|
|
+ $temp['type'] = $filed['field_db'] == "Status" ? "status" : "normal";
|
|
|
+ $temp['formatter'] = "";
|
|
|
+ $tableColumns[] = $temp;
|
|
|
+ }
|
|
|
+ $dataReturn['tableColumns'] = $tableColumns;
|
|
|
+ $dataReturn['filtersList'] = $filtersList;
|
|
|
+ if(!empty($sortByOptions)){
|
|
|
+ $dataReturn['sortBy'] = array("field"=>$sortByOptions[0],"options"=>$sortByOptions,"order"=>"asc");
|
|
|
+ }else{
|
|
|
+ $dataReturn['sortBy'] = array("field"=>"","options"=>[],"order"=>"asc");
|
|
|
+ }
|
|
|
|
|
|
- common::excuteListSql("select * from kln_report_field_config where template_serial_no = '".$serial_no."' and field_type = 'System' order by id ");
|
|
|
-
|
|
|
+ $reportFiled = common::excuteObjectSql("select report_sql,count_sql from public.kln_report_template where serial_no = '".$serial_no."'");
|
|
|
+ $report_sql = $reportFiled["report_sql"];
|
|
|
+ $count_sql = $reportFiled["count_sql"];
|
|
|
|
|
|
- //第一次进来,把查询放到一起了
|
|
|
- $cp = 10;
|
|
|
- $ps = 1;
|
|
|
- $rc = $_POST ['rc'];
|
|
|
- if ($rc == - 1) {
|
|
|
- $sql = "select count(*) from public.kln_report_template where " ;
|
|
|
- $rc = common::excuteOneSql($sql);
|
|
|
+ $filterSQLArr = $this->returnFilterSql($filtersList);
|
|
|
+ //return array("vvSearchKLN"=>$vvSearchKLN,"klnOceanSearchKLN"=>$klnOceanSearchKLN,"ocItemSearchKLN"=>$ocItemSearchKLN);
|
|
|
+ $report_sql = str_replace('<{vvSearchKLN}>', $filterSQLArr['vvSearchKLN'], $report_sql);
|
|
|
+ $report_sql = str_replace('<{klnOceanSearchKLN}>', $filterSQLArr['klnOceanSearchKLN'], $report_sql);
|
|
|
+ $report_sql = str_replace('<{ocItemSearchKLN}>', $filterSQLArr['ocItemSearchKLN'], $report_sql);
|
|
|
+
|
|
|
+
|
|
|
+ //查询data
|
|
|
+ $cp = common::check_input($_POST ['cp']); //current_page
|
|
|
+ $ps = common::check_input($_POST ['ps']); //ps
|
|
|
+ if (empty($ps))
|
|
|
+ $ps = 10;
|
|
|
+ if (empty($cp))
|
|
|
+ $cp = 1;
|
|
|
+
|
|
|
+ if (true) {
|
|
|
+ $count_sql = str_replace('<{orderby}>', "", $count_sql);
|
|
|
+ error_log($count_sql);
|
|
|
+ $rc = common::excuteOneSql($count_sql);
|
|
|
}
|
|
|
$tp = ceil($rc / $ps);
|
|
|
if ($rc > 0) {
|
|
|
- $sql = "select name,description from public.kln_report_template where " ;
|
|
|
- $sql .= " order by id desc limit " . $ps . " offset " . ($cp - 1) * $ps;
|
|
|
- $rs = common::excuteListSql($sql);
|
|
|
+ $report_sql = str_replace('<{orderby}>', $this->returnSortBySql(), $report_sql);
|
|
|
+ $tmp_search_without_limit = $report_sql;
|
|
|
+ $report_sql .= " limit " . $ps . " offset " . ($cp - 1) * $ps;
|
|
|
+ error_log($report_sql);
|
|
|
+
|
|
|
+ $rs = common::excuteListSql($report_sql);
|
|
|
$arrTmp = array('searchData' => $rs,
|
|
|
'rc' => intval($rc),
|
|
|
'ps' => intval($ps),
|
|
|
'cp' => intval($cp),
|
|
|
'tp' => intval($tp));
|
|
|
- common::echo_json_encode(200,$arrTmp);
|
|
|
- exit();
|
|
|
}else{
|
|
|
$arrTmp = array('searchData' => array());
|
|
|
- common::echo_json_encode(200, $arrTmp);
|
|
|
- exit();
|
|
|
}
|
|
|
+ $dataReturn['tableData'] = $arrTmp;
|
|
|
+ $dataReturn['tmp_search'] = common::deCode($tmp_search_without_limit, 'E');
|
|
|
+ common::echo_json_encode(200, $dataReturn);
|
|
|
+ exit();
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+ * export excel
|
|
|
+ */
|
|
|
+ if ($operate == "excel") {
|
|
|
+ $sql = common::deCode($_POST['tmp_search'], 'D');
|
|
|
+ if(!empty($sql)){
|
|
|
+ $rs = common::excuteListSql($sql);
|
|
|
+ }
|
|
|
+ //去除null
|
|
|
+ foreach($rs as $index => $val) {
|
|
|
+ foreach($val as $index_2 => $_val) {
|
|
|
+ if(empty($rs[$index][$index_2]) || $rs[$index][$index_2] == null){
|
|
|
+ $rs[$index][$index_2] = "";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ common::echo_json_encode(200,array("msg"=>"success","Data" => $rs));
|
|
|
+ exit;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($operate == "manage_fileds") {
|
|
|
+ $serial_no = common::check_input($_POST ['serial_no']);
|
|
|
+ $reportFiled = common::excuteListSql("select * from public.kln_report_field_config
|
|
|
+ where template_serial_no = '".$serial_no."'
|
|
|
+ and field_type = 'System' order by id ");
|
|
|
+ $showData = array();
|
|
|
+ $hideData = array();
|
|
|
+ foreach($reportFiled as $_reportFiled){
|
|
|
+ $_reportFiled['is_filter_enabled'] = $_reportFiled['is_filter_enabled'] == 't' ? true : false;
|
|
|
+ $_reportFiled['is_sort_enabled'] = $_reportFiled['is_sort_enabled'] == 't' ? true : false;
|
|
|
+ if($_reportFiled['is_enabled'] == 't'){
|
|
|
+ $showData[] = $_reportFiled;
|
|
|
+ }else{
|
|
|
+ $hideData[] = $_reportFiled;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ common::echo_json_encode(200,array("msg"=>"success","showData" => $showData,"hideData" => $hideData));
|
|
|
+ exit;
|
|
|
+ }
|
|
|
+ if ($operate == "manage_fileds_save") {
|
|
|
+ $serial_no = common::check_input($_POST['serial_no']);
|
|
|
+ $fieldsList = $_POST['fieldsList'];
|
|
|
+ //先删除,后添加 因为不涉及系统配置字段,全部用kln_report_field_config 字段name
|
|
|
+ $sql = "delete from public.kln_report_field_config where template_serial_no = '$serial_no';";
|
|
|
+ foreach($fieldsList as $key =>$_tempFieldsList){
|
|
|
+ $_field_id = empty($_tempFieldsList['field_id'])? "NULL": $_tempFieldsList['field_id'];
|
|
|
+ $_field_level = common::check_input($_tempFieldsList['field_level']);
|
|
|
+ $_field_type = common::check_input($_tempFieldsList['field_type']);
|
|
|
+ $_field_group_name = common::check_input($_tempFieldsList['field_group_name']);
|
|
|
+ $_field_db = common::check_input($_tempFieldsList['field_db']);
|
|
|
+ $_field_code = common::check_input($_tempFieldsList['field_display_name']);
|
|
|
+ $_display_name = common::check_input($_tempFieldsList['field_display_name_user']);
|
|
|
+ $_data_type = common::check_input($_tempFieldsList['data_type']);
|
|
|
+ $_value_type = common::check_input($_tempFieldsList['custom_value_type']);
|
|
|
+ $_fixed_value = common::check_input($_tempFieldsList['custom_fixed_value']);
|
|
|
+ $_is_filter_enabled = $_tempFieldsList['is_filter_enabled'];
|
|
|
+ $_is_sort_enabled = $_tempFieldsList['is_sort_enabled'];
|
|
|
+ $sql .= "INSERT INTO public.kln_report_field_config(
|
|
|
+ template_serial_no, field_id, field_level, field_type, field_db, field_group_name,
|
|
|
+ field_display_name, field_display_name_user, data_type, custom_value_type,
|
|
|
+ custom_fixed_value, is_filter_enabled, is_sort_enabled, created_time)
|
|
|
+ VALUES ('$serial_no', $_field_id, '$_field_level', '$_field_type', '$_field_db', '$_field_group_name',
|
|
|
+ '$_field_code', '$_display_name', '$_data_type', '$_value_type',
|
|
|
+ '$_fixed_value', '$_is_filter_enabled', '$_is_sort_enabled',now());";
|
|
|
+ }
|
|
|
+ if (!empty($sql)){
|
|
|
+ common::excuteUpdateSql($sql);
|
|
|
+ $data = array("msg" =>"success");
|
|
|
+ }
|
|
|
+
|
|
|
+ common::echo_json_encode(200,array("msg"=>"success","Data" => ''));
|
|
|
+ exit;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据提交的参数动态的拼接filter sql
|
|
|
+ */
|
|
|
+ public function returnFilterSql($filtersList){
|
|
|
+ $klnOceanDb = common::getReportRealDBFiled("klnOceanDb");
|
|
|
+ $ocItemDb = common::getReportRealDBFiled("ocItemDb");
|
|
|
+
|
|
|
+ $vvSearchKLN = " where 1=1 ";
|
|
|
+ $klnOceanSearchKLN = ' where ' . common::searchExtendHand_KLN("ocean", $_SESSION["ONLINE_USER"]);
|
|
|
+ $ocItemSearchKLN = " where 1=1 ";
|
|
|
+
|
|
|
+ foreach($filtersList as $fiter){
|
|
|
+ if(!empty($_POST[$fiter['field']])){
|
|
|
+ $key = array_search($fiter['field'], $klnOceanDb);
|
|
|
+ $ockey = array_search($fiter['field'], $ocItemDb);
|
|
|
+ if($key !== false){
|
|
|
+ //找到给key
|
|
|
+ if ($fiter['data_type'] == "string"){
|
|
|
+ $klnOceanSearchKLN .= " and ".$key." = '". common::check_input($_POST[$fiter['field']])."'";
|
|
|
+ } elseif ($fiter['data_type'] == "number"){
|
|
|
+ $klnOceanSearchKLN .= " and ".$key." >= '". common::check_input($_POST[$fiter['field']."_from"])."'";
|
|
|
+ $klnOceanSearchKLN .= " and ".$key." <= '". common::check_input($_POST[$fiter['field']."_to"])."'";
|
|
|
+ } elseif ($fiter['data_type'] == "date"){
|
|
|
+ $date_from = common::check_input(common::usDate2sqlDate($_POST [$fiter['field']."_from"]) . ' 00:00:00');
|
|
|
+ $date_to = common::check_input(common::usDate2sqlDate($_POST [$fiter['field']."_to"]) . ' 23:59:59');
|
|
|
+ $klnOceanSearchKLN .= " and ".$key." >= '". $date_from."'";
|
|
|
+ $klnOceanSearchKLN .= " and ".$key." <= '". $date_to."'";
|
|
|
+ }
|
|
|
+ } elseif ($ockey !== false){
|
|
|
+ //找到给key
|
|
|
+ if ($fiter['data_type'] == "string"){
|
|
|
+ $ocItemSearchKLN .= " and ".$ockey." = '". common::check_input($_POST[$fiter['field']])."'";
|
|
|
+ } elseif ($fiter['data_type'] == "number"){
|
|
|
+ $ocItemSearchKLN .= " and ".$ockey." >= '". common::check_input($_POST[$fiter['field']."_from"])."'";
|
|
|
+ $ocItemSearchKLN .= " and ".$ockey." <= '". common::check_input($_POST[$fiter['field']."_to"])."'";
|
|
|
+ } elseif ($fiter['data_type'] == "date"){
|
|
|
+ $date_from = common::check_input(common::usDate2sqlDate($_POST[$fiter['field']."_from"]) . ' 00:00:00');
|
|
|
+ $date_to = common::check_input(common::usDate2sqlDate($_POST[$fiter['field']."_to"]) . ' 23:59:59');
|
|
|
+ $ocItemSearchKLN .= " and ".$ockey." >= '". $date_from."'";
|
|
|
+ $ocItemSearchKLN .= " and ".$ockey." <= '". $date_to."'";
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if ($fiter['data_type'] == "string"){
|
|
|
+ $vvSearchKLN .= " and \"".$fiter['field']."\" ilike '%". common::check_input($_POST [$fiter['field']])."%'";
|
|
|
+ } elseif ($fiter['data_type'] == "number"){
|
|
|
+ $vvSearchKLN .= " and \"".$fiter['field']."\" >= '". common::check_input($_POST [$fiter['field']."_from"])."'";
|
|
|
+ $vvSearchKLN .= " and \"".$fiter['field']."\" <= '". common::check_input($_POST [$fiter['field']."_to"])."'";
|
|
|
+ } elseif ($fiter['data_type'] == "date"){
|
|
|
+ $date_from = common::check_input(common::usDate2sqlDate($_POST [$fiter['field']."_from"]) . ' 00:00:00');
|
|
|
+ $date_to = common::check_input(common::usDate2sqlDate($_POST [$fiter['field']."_to"]) . ' 23:59:59');
|
|
|
+ //先判断日期字符串是否为空,这里则有做 是因为sql 整合了柜子315时间,和 milestone的时间, 只能text转date
|
|
|
+ $vvSearchKLN .= " and COALESCE(\"".$fiter['field']."\",''::text)<> ''::text ";
|
|
|
+ $vvSearchKLN .= " and to_timestamp(\"".$fiter['field']."\", 'MM/DD/YYYY HH24:MI:SS') >= '". $date_from."'";
|
|
|
+ $vvSearchKLN .= " and to_timestamp(\"".$fiter['field']."\", 'MM/DD/YYYY HH24:MI:SS') <= '". $date_to."'";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return array("vvSearchKLN"=>$vvSearchKLN,"klnOceanSearchKLN"=>$klnOceanSearchKLN,"ocItemSearchKLN"=>$ocItemSearchKLN);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据提交的参数动态的拼接sort by sql
|
|
|
+ */
|
|
|
+ public function returnSortBySql(){
|
|
|
+ $sortByField = $_POST['sortByField'];
|
|
|
+ $sortByOrder = $_POST['sortByOrder'];
|
|
|
+
|
|
|
+ $sort_sql_temp = " ";
|
|
|
+ if(!empty($sortByField) && !empty($sortByOrder)){
|
|
|
+ $sort_sql_temp = " order by \"".$sortByField."\" ". $sortByOrder;
|
|
|
}
|
|
|
+ return $sort_sql_temp;
|
|
|
}
|
|
|
}
|
|
|
|