<?php
/**
 *
 * @author：llbjj
 * @DateTime：2022/5/6 10:57
 * @Description：
 *
 */

namespace Application\Service\DB\Tmp;
use Interop\Container\ContainerInterface;
use Laminas\Db\Sql\Predicate\IsNotNull;
use Laminas\Db\Sql\Predicate\Operator;
use Laminas\Stdlib\ArrayUtils;
use Application\Common\Com;

class Rawmate extends \Application\Service\DB\AbstractDb
{
    public function __construct($dbAdapter, ContainerInterface $container)
    {
        $this->tableName = 'yikeen_tmp_rawmate';
        parent::__construct($dbAdapter, $container);
    }

    /**
     * Notes: 添加新指标
     * User: llbjj
     * DateTime: 2023/6/9 13:54
     *
     * @param array $params
     */
    public function addNewMateData(array $params) {

        // 删除之前匹配上的指标
        $this->upDelState([
            'raw_id' => $params['raw_id'],
            'is_mate' => 1
        ]);

        $rawData = $this->LocalService()->tmpRawdata->fetchOne([
            'where' => [
                'id' => $params['raw_id'],
                'is_del' => 0
            ],
            'columns' => ['annex_id', 'itemsig_id', 'patient_id', 'raw_name']
        ]);

        $keywordData = $this->LocalService()->tmpKeyword->fetchOne([
            'where' => ['id' => $params['keyword_id'], 'is_del' => 0],
            'columns' => ['category_name', 'keyword_name']
        ]);

        $addData = [
            'annex_id' => $rawData['annex_id'],
            'itemsig_id' => $rawData['itemsig_id'],
            'patient_id' => $rawData['patient_id'],
            'raw_id' => $params['raw_id'],
            'raw_name' => $rawData['raw_name'],
            'category_name' => $keywordData['category_name'],
            'keyword_id' => $params['keyword_id'],
            'keyword_name' => $keywordData['keyword_name'],
            'mate_keyword' => json_encode([$keywordData['keyword_name']]),
            'is_mate' => 1,
            'mate_num' => 1,
            'mate_rate' => 100,
            'name_rate' => 100,
            'is_del' => 0
        ];

        $this->save($addData);
    }

    /**
     * Notes: 获取指定条件下的识别结果数据 与 指标关键字匹配，存入匹配信息表
     * User: lltyy
     * DateTime: 2023/4/25 10:16
     *
     * @param $where
     * @return array
     */
    public function mateData($where,$limit=0,$offset=0,&$keywordDatas,&$black_word_arr){
        //获取指定条件下的识别结果数据
        $rawCond = [
            'where'=>$where,
            'columns'=>['id','annex_id','itemsig_id','patient_id','raw_name','raw_result','raw_date','raw_judge'],
            'order'=>['id']
        ];
        if(!empty($limit) || !empty($offset)){
            $rawCond['limit'] = $limit;
            $rawCond['offset'] = $offset;
        }
        $rawDatas = $this->LocalService()->tmpRawdata->fetchAll($rawCond);
        $last_raw_id = 0;
        if(!empty($rawDatas)){
            $delete_mate_raw = $patient_id_arr = [];
            $delete_str_arr = ["↑","↓","#","！","~","*","☑","★","◆","。",".","(",")","（","）","?",":","：","√","？","^","<",">","|","、","《","》","，",",","{","}","[","]","【","】","+","--","=","～"];
            foreach($rawDatas as $rawKey=>$raw_info){
                $last_raw_id = $raw_info['id'];
                $raw_info_name = trim($raw_info['raw_name']);
                $raw_info_end_name = str_replace($delete_str_arr,'',$raw_info_name);
                $rawDatas[$rawKey]['end_mate_name'] = $raw_info_end_name;
                $delete_mate_raw[] = $raw_info['id'];
                if(!in_array($raw_info['patient_id'],$patient_id_arr)){
                    $patient_id_arr[] = $raw_info['patient_id'];
                }
            }
            $rawDatas = array_values($rawDatas);

            //删除原匹配数据
            /*$this->upDelState(['is_del'=>0,'raw_id'=>$delete_mate_raw]],1);
            $this->LocalService()->tmpRawblack->upDelState(['is_del'=>0,'raw_id'=>$delete_mate_raw]],1);
            $this->LocalService()->tmpRawlock->upDelState(['is_del'=>0,'raw_id'=>$delete_mate_raw]],1);*/
            unset($delete_mate_raw);


            //信息匹配
            if(!empty($rawDatas) && !empty($keywordDatas)){
                $black_name_arr = !empty($black_word_arr['name']) ? $black_word_arr['name'] : [];
                $black_code_arr = !empty($black_word_arr['code']) ? $black_word_arr['code'] : [];
                //获取受试者性别
                $patientSexData = $this->LocalService()->tmpPatient->fetchCol('sex',['is_del'=>0,'id'=>$patient_id_arr]]);
                unset($patient_id_arr);
                //与检查项匹配
                foreach($rawDatas as $rawKey=>$rawData){
                    $raw_id = $rawData['id'];
                    $annex_id = $rawData['annex_id'];
                    $sig_id = $rawData['itemsig_id'];
                    $patient_id = $rawData['patient_id'];
                    $patient_sex = isset($patientSexData[$patient_id]) && !empty($patientSexData[$patient_id]) ? $patientSexData[$patient_id] : 1;
                    $raw_name = trim($rawData['raw_name']);
                    $mate_raw_name = $rawData['end_mate_name'];

                    //切割识别名称
                    $rawName = "{$mate_raw_name}";
                    $raw_keyword =  !empty($rawName) ? Com::cutIntoSlices($rawName) : [];
                    $raw_keyword = !empty($raw_keyword) ? array_values($raw_keyword) : [];

                    //识别数据匹配ID
                    $raw_mate_arr = $mate_info_arr = [];
                    foreach($keywordDatas as $keywordData){
                        $keyword_id = $keywordData['id'];
                        $keyword_name = trim($keywordData['keyword_name']);
                        if($keyword_name != ''){
                            $mate_decimal_digit = 0;
                            $mate_raw_min = $mate_raw_max = '';
                            if(isset($keywordData['sig_set']) && isset($keywordData['sig_set'][$sig_id]) && isset($keywordData['sig_set'][$sig_id]['decimal_digit']) && !is_null($keywordData['sig_set'][$sig_id]['decimal_digit'])){
                                $mate_decimal_digit = !is_null($keywordData['sig_set'][$sig_id]['decimal_digit']) && !empty($keywordData['sig_set'][$sig_id]['decimal_digit']) ? $keywordData['sig_set'][$sig_id]['decimal_digit'] : 0;
                                if($patient_sex == 1){
                                    $mate_raw_min = !is_null($keywordData['sig_set'][$sig_id]['boy_min']) && $keywordData['sig_set'][$sig_id]['boy_min'] != '' ? $keywordData['sig_set'][$sig_id]['boy_min'] : '';
                                    $mate_raw_max = !is_null($keywordData['sig_set'][$sig_id]['boy_max']) && $keywordData['sig_set'][$sig_id]['boy_max'] != '' ? $keywordData['sig_set'][$sig_id]['boy_max'] : '';
                                }else{
                                    $mate_raw_min = !is_null($keywordData['sig_set'][$sig_id]['girl_min']) && $keywordData['sig_set'][$sig_id]['girl_min'] != '' ? $keywordData['sig_set'][$sig_id]['girl_min'] : '';
                                    $mate_raw_max = !is_null($keywordData['sig_set'][$sig_id]['girl_max']) && $keywordData['sig_set'][$sig_id]['girl_max'] != '' ? $keywordData['sig_set'][$sig_id]['girl_max'] : '';
                                }
                            }else{
                                $mate_decimal_digit = !is_null($keywordData['decimal_digit']) && !empty($keywordData['decimal_digit']) ? $keywordData['decimal_digit'] : 0;
                                if($patient_sex == 1){
                                    $mate_raw_min = !is_null($keywordData['boy_min']) && $keywordData['boy_min'] != '' ? $keywordData['boy_min'] : '';
                                    $mate_raw_max = !is_null($keywordData['boy_max']) && $keywordData['boy_max'] != '' ? $keywordData['boy_max'] : '';
                                }else{
                                    $mate_raw_min = !is_null($keywordData['girl_min']) && $keywordData['girl_min'] != '' ? $keywordData['girl_min'] : '';
                                    $mate_raw_max = !is_null($keywordData['girl_max']) && $keywordData['girl_max'] != '' ? $keywordData['girl_max'] : '';
                                }
                            }
                            $keyword_code = trim($keywordData['keyword_code']);
                            $category_name = trim($keywordData['category_name']);

                            $mate_keywork_code = str_replace($delete_str_arr,'',$keyword_code);
                            $mate_keywork_name = str_replace($delete_str_arr,'',$keyword_name);
                            $cateName = "{$mate_keywork_code}{$mate_keywork_name}";
                            $keyword_info_arr =  !empty($cateName) ? Com::cutIntoSlices($cateName) : [];
                            $keyword_info_arr = !empty($keyword_info_arr) ? array_values($keyword_info_arr) : [];

                            //关键字匹配
                            $mate_keyword_arr = !empty($keyword_info_arr) ? array_uintersect($keyword_info_arr,$raw_keyword,"strcasecmp") : [];
                            $mate_keyword_arr = isset($mate_keyword_arr) && !empty($mate_keyword_arr) ? array_values($mate_keyword_arr) : [];

                            $mate_num = count($mate_keyword_arr);//匹配数
                            if($mate_num > 0){
                                //（匹配数/关键字数）*100 > 10
                                $keyword_num = count($keyword_info_arr);
                                $rate = ($mate_num/$keyword_num)*100;

                                //(匹配上指标名称的长度/识别的名称长度)*100 >= 15
                                $keyword_length = mb_strlen($mate_keywork_name,'utf-8');
                                $raw_name_length = mb_strlen($mate_raw_name,'utf-8');
                                $name_rate = ($keyword_length/$raw_name_length)*100;

                                $save_data = [
                                    'annex_id'=>$annex_id,
                                    'itemsig_id'=>$sig_id,
                                    'patient_id'=>$patient_id,
                                    'raw_id'=>$raw_id,
                                    'category_name'=>$category_name,
                                    'raw_name'=>$raw_name,
                                    'keyword_id'=>$keyword_id,
                                    'keyword_name'=>$keyword_name,
                                    'mate_keyword'=>json_encode($mate_keyword_arr),
                                    'mate_num'=>$mate_num,
                                    'mate_rate'=>$rate,
                                    'name_rate'=>$name_rate,
                                    'is_mate'=>0
                                ];
                                $mate_id = $this->save($save_data);
                                if($rate > 10 && $name_rate > 15){
                                    $raw_mate_arr[$mate_num][$rate][] = $mate_id;
                                    $mate_info_arr[$mate_id]['decimal_digit'] = $mate_decimal_digit;
                                    $mate_info_arr[$mate_id]['raw_min'] = $mate_raw_min;
                                    $mate_info_arr[$mate_id]['raw_max'] = $mate_raw_max;
                                    $mate_info_arr[$mate_id]['keyword_name'] = $keyword_name;
                                    $mate_info_arr[$mate_id]['keyword_id'] = $keyword_id;
                                    $mate_info_arr[$mate_id]['category_name'] = $category_name;
                                }
                                unset($save_data);
                            }

                            unset($mate_keyword_arr);
                            unset($keyword_info_arr);
                        }
                    }

                    //更新默认匹配数据
                    $raw_mate_type = $set_decimal_digit = $set_keyword_id = 0;
                    $set_raw_min = $set_raw_max = $set_keyword_name = $set_category_name = '';
                    if(!empty($raw_mate_arr)){
                        $raw_mate_type = 1;
                        //更新默认匹配数据
                        krsort($raw_mate_arr);
                        $is_mate_id = 0;
                        foreach($raw_mate_arr as $raw_mate_infos){
                            krsort($raw_mate_infos);
                            foreach($raw_mate_infos as $raw_mate_info){
                                if(empty($is_mate_id)){
                                    $is_mate_id = isset($raw_mate_info[0]) && !empty($raw_mate_info[0]) ? $raw_mate_info[0] : 0;
                                }
                            }
                        }
                        $set_decimal_digit = isset($mate_info_arr[$is_mate_id]) && isset($mate_info_arr[$is_mate_id]['decimal_digit']) && !empty($mate_info_arr[$is_mate_id]['decimal_digit']) ? $mate_info_arr[$is_mate_id]['decimal_digit'] : 0;
                        $set_raw_min = isset($mate_info_arr[$is_mate_id]) && isset($mate_info_arr[$is_mate_id]['raw_min']) && $mate_info_arr[$is_mate_id]['raw_min'] != '' ? $mate_info_arr[$is_mate_id]['raw_min'] : '';
                        $set_raw_max = isset($mate_info_arr[$is_mate_id]) && isset($mate_info_arr[$is_mate_id]['raw_max']) && $mate_info_arr[$is_mate_id]['raw_max'] != '' ? $mate_info_arr[$is_mate_id]['raw_max'] : '';
                        $set_keyword_name = isset($mate_info_arr[$is_mate_id]) && isset($mate_info_arr[$is_mate_id]['keyword_name']) && $mate_info_arr[$is_mate_id]['keyword_name'] != '' ? $mate_info_arr[$is_mate_id]['keyword_name'] : '';
                        $set_category_name = isset($mate_info_arr[$is_mate_id]) && isset($mate_info_arr[$is_mate_id]['category_name']) && $mate_info_arr[$is_mate_id]['category_name'] != '' ? $mate_info_arr[$is_mate_id]['category_name'] : '';
                        $set_keyword_id = isset($mate_info_arr[$is_mate_id]) && isset($mate_info_arr[$is_mate_id]['keyword_id']) && $mate_info_arr[$is_mate_id]['keyword_id'] != '' ? $mate_info_arr[$is_mate_id]['keyword_id'] : 0;
                        $this->updateField($is_mate_id,'is_mate',1);

                        //与黑名单匹配
                        if((!empty($black_name_arr) || !empty($black_code_arr)) && ($set_keyword_name != '超敏肌钙蛋白I' || ($set_keyword_name == '超敏肌钙蛋白I' && strpos($raw_name,'超') == false  && strpos($raw_name,'敏') == false && strpos($raw_name,'肌') == false && strpos($raw_name,'蛋') == false && strpos($raw_name,'白') == false))){
                            //已匹配上黑名单的名称
                            $black_word = !empty($black_name_arr)  ? array_uintersect($black_name_arr,$raw_keyword,"strcasecmp") : [];
                            $black_word = isset($black_word) && !empty($black_word) ? array_values($black_word) : [];

                            //已匹配上黑名单的项目代号
                            $black_code = !empty($black_code_arr)  ? array_uintersect($black_code_arr,$raw_keyword,"strcasecmp") : [];
                            $black_code = isset($black_code) && !empty($black_code) ? array_values($black_code) : [];

                            $black_word = !empty($black_code) ? array_merge($black_word,$black_code) : $black_word;
                            $black_word = isset($black_word) && !empty($black_word) ? array_values($black_word) : [];

                            if(!empty($black_word)){
                                $raw_mate_type = 2;
                                //保存指标匹配上的数据与黑名单匹配数据
                                $save_black = [
                                    'annex_id'=>$annex_id,
                                    'itemsig_id'=>$sig_id,
                                    'patient_id'=>$patient_id,
                                    'raw_id'=>$raw_id,
                                    'raw_name'=>$raw_name,
                                    'black_word'=>json_encode($black_word_arr),
                                    'mate_black'=>json_encode($black_word)
                                ];
                                $this->LocalService()->tmpRawblack->save($save_black);
                                unset($save_black);
                            }
                            unset($black_word);
                        }

                    }
                    unset($mate_info_arr);
                    unset($raw_mate_arr);
                    unset($raw_keyword);


                    //更新识别结果、识别判断
                    $raw_result = trim($rawData['raw_result']);
                    $raw_judge = 0;
                    if($raw_mate_type == 1){
                        if($raw_result != ''){
                            $raw_result = $this->LocalService()->tmpRawdata->replaceRawdata($raw_result,0);
                            $raw_result = $raw_result != '' ? $raw_result : '';

                            unset($new_raw_result);
                            $raw_result = str_replace(['↑','↓'],'',$raw_result);//替换字符串中的特殊字符
                            $raw_result = $raw_result != '' ? $raw_result : '';
                            $raw_result = Com::numberDigit($raw_result,$set_decimal_digit);
                            if($raw_result != '' && is_numeric($raw_result)){
                                if($set_raw_min != ''){
                                    if($raw_result < $set_raw_min){
                                        $raw_judge = 1;
                                    }else{
                                        if($set_raw_max != '' && $raw_result > $set_raw_max){
                                            $raw_judge = 2;
                                        }
                                    }
                                }else{
                                    if($set_raw_max != ''){
                                        if(strpos($set_raw_max,'<') !== false){
                                            $set_raw_max_number = str_replace('<','',$set_raw_max);
                                            if($raw_result > $set_raw_max_number){
                                                $raw_judge = 2;
                                            }
                                        }else{
                                            if($raw_result < $set_raw_min){
                                                $raw_judge = 1;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }else{
                        $set_raw_min = $set_raw_max = '';
                    }
                    $update_data = [
                        'mate_type'=>$raw_mate_type,
                        'raw_result'=>$raw_result,
                        'raw_min'=>$set_raw_min,
                        'raw_max'=>$set_raw_max,
                        'keyword_id'=>$set_keyword_id,
                        'mate_name'=>$set_keyword_name,
                        'mate_category'=>$set_category_name,
                        'raw_judge'=>$raw_judge
                    ];
                    $this->LocalService()->tmpRawdata->update($update_data,['id'=>$raw_id]);

                    unset($rawDatas[$rawKey]);
                }
            }
        }
        unset($rawDatas);

        return $last_raw_id;
    }

    /**
     * Notes: 获取指定条件下的识别结果匹配的数据【按照匹配度降序排列】
     * User: lltyy
     * DateTime: 2023/5/18 8:56
     *
     * @param $where
     * @param int $return_type 【0 所有数据 1 默认为匹配数据】
     * @return array[]
     */
    public function fetchRawMatedata($where,$return_type=0){
        $datas = [
            'mate'=>[],
            'no_mate'=>[]
        ];

        if($return_type == 1){
            $datas = [];
        }
        //获取指定条件下的识别结果数据
        $cond = [
            'where'=>$where,
            'columns'=>['id','category_name','itemsig_id','patient_id','raw_name','raw_id','keyword_id','keyword_name','mate_keyword','mate_num','name_rate','mate_rate'],
            'order'=>['raw_id','is_mate desc','mate_num desc','mate_rate desc']
        ];
        $matedatas = $this->fetchAll($cond);
        if(!empty($matedatas)){
            //获取受试者性别
            $patientSexData = $this->LocalService()->tmpPatient->fetchCol('sex',['is_del'=>0,new Operator('pid',Operator::OP_GT,0)]);

            //获取中心设置的信息
            $sigKeywordData = $this->LocalService()->tmpSigkeyword->fetchDataById(['is_del'=>0],['keyword_id','itemsig_id','keyword_code','keyword_unit','boy_min','boy_max','girl_min','girl_max'],1);

            //获取关键字英文名
            $keywordData = $this->LocalService()->tmpKeyword->fetchDataById(['is_del'=>0],['id','parent_id','keyword_code','keyword_unit','boy_min','boy_max','girl_min','girl_max']);
            foreach($matedatas as &$matedata) {
                $raw_sig = $matedata['itemsig_id'];
                $raw_patient = $matedata['patient_id'];
                $patient_sex = isset($patientSexData[$raw_patient]) && !empty($patientSexData[$raw_patient]) ? $patientSexData[$raw_patient] : 1;
                //获取匹配上的数据
                $keyword_id = $matedata['keyword_id'];
                $keyword_data = [];
                if(isset($sigKeywordData[$raw_sig]) && isset($sigKeywordData[$raw_sig][$keyword_id]) && !empty($sigKeywordData[$raw_sig][$keyword_id])){
                    $keyword_data = $sigKeywordData[$raw_sig][$keyword_id];
                }
                if(empty($keyword_data)){
                    $keyword_data = isset($keywordData[$keyword_id]) && !empty($keywordData[$keyword_id]) ? $keywordData[$keyword_id] : [];
                }
                $mate_keyword = !empty($matedata['mate_keyword']) ? json_decode($matedata['mate_keyword'], true) : [];
                $matedata['mate_keyword'] = implode('、', $mate_keyword);
                $matedata['keyword_code'] = isset($keyword_data['keyword_code']) && !empty($keyword_data['keyword_code']) ? $keyword_data['keyword_code'] : '';
                $matedata['keyword_unit'] = isset($keyword_data['keyword_unit']) && $keyword_data['keyword_unit'] != '' ? $keyword_data['keyword_unit'] : '';
                $matedata['keyword_parent'] = isset($keywordData[$keyword_id]) && isset($keywordData[$keyword_id]['parent_id']) && !empty($keywordData[$keyword_id]['parent_id']) ? $keywordData[$keyword_id]['parent_id'] : 0;
                $matedata['keyword_min'] = $matedata['keyword_max'] = '';
                if($patient_sex == 2){//女性
                    $matedata['keyword_min'] = isset($keyword_data['girl_min']) && $keyword_data['girl_min'] != '' ? $keyword_data['girl_min'] : '';
                    $matedata['keyword_max'] = isset($keyword_data['girl_max']) && $keyword_data['girl_max'] != '' ? $keyword_data['girl_max'] : '';
                }else{//男性
                    $matedata['keyword_min'] = isset($keyword_data['boy_min']) && $keyword_data['boy_min'] != '' ? $keyword_data['boy_min'] : '';
                    $matedata['keyword_max'] = isset($keyword_data['boy_max']) && $keyword_data['boy_max'] != '' ? $keyword_data['boy_max'] : '';
                }
                $matedata['keyword_range'] = $matedata['keyword_min'] != '' || $matedata['keyword_max'] != '' ? $matedata['keyword_min'].'--'.$matedata['keyword_max'] : '';
                if($matedata['keyword_min'] == '' && $matedata['keyword_max'] != ''){
                    if(strpos($matedata['keyword_max'],'<') !== false || strpos($matedata['keyword_max'],'>') !== false){
                        $matedata['keyword_range'] = $matedata['keyword_max'];
                    }
                }
                if($matedata['keyword_min'] != '' && $matedata['keyword_max'] == ''){
                    if(strpos($matedata['keyword_min'],'<') !== false || strpos($matedata['keyword_min'],'>') !== false){
                        $matedata['keyword_range'] = $matedata['keyword_min'];
                    }
                }
                $raw_id = $matedata['raw_id'];
                if($return_type == 1){
                    $datas[$raw_id] = $matedata;
                }else{
                    if($matedata['mate_rate'] > 10 && $matedata['name_rate'] > 15){
                        $datas['mate'][$raw_id][] = $matedata;
                    }else{
                        $datas['no_mate'][$raw_id][] = $matedata;
                    }
                }
            }
        }
        unset($cond);
        unset($matedatas);
        return $datas;
    }


    /**
     * Notes: 获取指定条件下的识别结果匹配的数据【按照匹配度降序排列】
     * User: lltyy
     * DateTime: 2023/5/18 8:56
     *
     * @param $where
     * @return array[]
     */
    public function fetchMateKeywordByRaw($where,$columns){
        $datas = [];
        //获取指定条件下的识别结果数据
        $cond = [
            'where'=>$where,
            'columns'=>$columns,
            'order'=>['raw_id']
        ];
        $matedatas = $this->fetchAll($cond);
        if(!empty($matedatas)){
            foreach($matedatas as &$matedata) {
                //获取匹配上的数据
                $raw_id = $matedata['raw_id'];
                $keyword_id = $matedata['keyword_id'];
                $datas[$raw_id][$keyword_id] = $matedata;
            }
        }
        unset($cond);
        unset($matedatas);
        return $datas;
    }

    /**
     * Notes:化验单自动匹配
     * User: lltyy
     * DateTime: 2023/5/26 15:26
     *
     */
    public function scanData($where=[]){
        $sigKeywordWhere = ['is_del'=>0];
        if(empty($where)) {
            $where = ['is_del'=>0,'is_lock'=>0];
        }

        //获取指标关键字信息
        $keywordCond = [
            'where'=>[
                'is_del'=>0,
                new IsNotNull('keyword_name'),
                new Operator('keyword_name',Operator::OP_NE,"")
            ],
            'columns'=>['id','category_name','keyword_code','keyword_name','decimal_digit','boy_min','boy_max','girl_min','girl_max'],
            'order'=>['category_name','parent_id','id']
        ];
        $keywordDatas = $this->LocalService()->tmpKeyword->fetchAll($keywordCond);
        if(!empty($keywordDatas)){
            //获取中心检查项信息
            $sigKeywordDatas = $this->LocalService()->tmpSigkeyword->fetchDataById($sigKeywordWhere,['keyword_id','itemsig_id','decimal_digit','boy_min','boy_max','girl_min','girl_max'],2);
            foreach($keywordDatas as &$keywordData){
                $keywordData_id = $keywordData['id'];
                $keywordData['sig_set'] = isset($sigKeywordDatas[$keywordData_id]) && !empty($sigKeywordDatas[$keywordData_id]) ? $sigKeywordDatas[$keywordData_id] : [];
            }
            unset($sigKeywordDatas);
        }
        unset($sigKeywordWhere);
        unset($keywordCond);


        //获取指标黑名单信息
        $black_word_arr = [
            'name'=>[],
            'code'=>[]
        ];
        $blackCond = [
            'where'=>['is_del'=>0],
            'columns'=>['id','category_name','word_code','word_name'],
            'order'=>['category_name','id']
        ];
        $blackDatas = $this->LocalService()->tmpRawword->fetchAll($blackCond);
        if(!empty($blackDatas)){
            foreach($blackDatas as $blackData){
                $black_word_arr['name'][] = $blackData['word_name'];
                if($blackData['word_code'] != ''){
                    $black_word_arr['code'][] = $blackData['word_code'];
                }
            }
        }
        unset($blackCond);
        unset($blackDatas);

        $bool = true;
        $page = 0;
        $limit = 1000;
        $last_raw_id = 0;
        while ($bool) {
            $page++;
            echo "rawPAGE {$page}：" . PHP_EOL;
            $mateDataWhere = $where;
            $mateDataWhere[] = new Operator('id',Operator::OP_GT,$last_raw_id);
            $last_raw_id = $this->mateData($mateDataWhere, $limit,0,$keywordDatas,$black_word_arr);
            unset($mateDataWhere);
            if(!$last_raw_id) $bool = false;
        }
        unset($keywordDatas);
        unset($black_word_arr);
    }
}