
from BaseDataMaintenance.dataSource.source import getConnect_ots
from tablestore import *
from BaseDataMaintenance.model.ots.major_project import *
from BaseDataMaintenance.model.ots.document import *
from BaseDataMaintenance.common.Utils import *

from queue import Queue

from BaseDataMaintenance.common.multiThread import MultiThreadHandler
import pandas as pd
from BaseDataMaintenance.model.ots.enterprise import Enterprise
import random
from apscheduler.schedulers.blocking import BlockingScheduler

def get_stage_pattern():
    # stage_dict = {
    #     "审批阶段": "审批|批复|(可行性|节能|全过程|社会稳定风险|建议书|施工图|专项法律)(评估|研究|方案|)(报告书?|造价|编制|审查|服务)+",
    #     "设计阶段": "设计|勘察|勘查",
    #     "环评阶段": "环评|(环境影响|水土保持)(评估|研究|方案|)(报告书?|造价|编制|审查|服务)+",
    #     "施工准备": "监理",
    #     "施工在建": "施工"
    # }

    stage_dict = {
        "立项阶段": "立项",
        "可研阶段": "可行性研究|可研|工程量清单预算编制",
        "环评阶段": "环境评价|环境影响|环境评测|环评",
        "稳评阶段": "稳定风险|社会稳定|风险评估",
        "咨询阶段": "(水影响|能源|交通影响|地质灾害|地址灾害|地震安全性|地震安全性|气象|雷击风险|安全|海洋|森林环境)(评[价估测])|水土保持|(水|交|灾|震|能|气|安|海|林)评",
        "造价阶段": "(决算书|预算|结算|造价|决算)(编制|咨询)",
        "设计阶段": "(施工图纸?|初步|项目|工程|工程方案)设计|测绘",
        # "勘察阶段": "(勘察|勘查)设计|勘察技术|勘查|勘察",
        "施工图审": "(施工图纸?|防雷|消防|人防)审查",
        "施工许可": "施工许可证|施工许可",
        "施工准备": "施工准备|监理|资格预审|资审|勘察|勘探|工程量清单|施工预算|预算编制|施工招标代理",
        "施工在建": "施工",
        "竣工阶段": "竣工公告|验收公告",
        # "EPC总承包": "总承包|EPC"
    }
    # stage_dict = {
    #     "立项阶段": stage_dict_child.get("立项阶段"),
    #     "可研阶段": stage_dict_child.get("可研阶段"),
    #     "环评阶段": stage_dict_child.get("环评阶段") + "|" + stage_dict_child.get("稳评阶段") + "|" + stage_dict_child.get("咨询阶段"),
    #     "设计阶段": stage_dict_child.get("造价阶段") + "|" + stage_dict_child.get("设计阶段"),
    #     "施工准备": stage_dict_child.get("施工图审") + "|" + stage_dict_child.get("施工许可") + "|" + stage_dict_child.get("施工准备"),
    #     "施工在建": stage_dict_child.get("施工在建"),
    #     "竣工阶段": stage_dict_child.get("竣工阶段")
    # }


    stage_priority_dict = {
        "立项阶段": 1,
        "可研阶段": 3,
        "环评阶段": 3,
        "稳评阶段": 3,
        "咨询阶段": 2,
        "造价阶段": 2,
        "设计阶段": 4,
        "勘察阶段": 4,
        "施工图审": 2,
        "施工许可": 2,
        "施工准备": 3,
        "施工在建": 5,
        "竣工阶段": 3,
        "EPC总承包": 4
    }

    # stage_priority_dict = {
    #     "立项阶段": 1,
    #     "可研阶段": 2,
    #     "环评阶段": 2,
    #     "设计阶段": 2,
    #     "施工准备": 3,
    #     "施工在建": 4,
    #     "竣工阶段": 2,
    # }


    list_stage_v = []
    for k,v in stage_dict.items():
        list_stage_v.append("(?P<%s>%s)"%(k,v))
    stage_pattern = "|".join(list_stage_v)
    return stage_pattern, stage_priority_dict

def extract_legal_stage(content, _pattern, priority_dict):
    # 判断这几类直接返回
    if not content:
        return None,None
    if re.search("拍卖|转让|产权|出让|租赁|招租", content) is not None:
        return None,None
    # 替换混淆词
    _content = re.sub("设计院|设计总院", "", content)

    list_stage = []
    for stage_search in re.finditer(_pattern, _content):
        for k,v in stage_search.groupdict().items():
            if v is not None:
                list_stage.append([k, priority_dict.get(k),v])
    if len(list_stage)>0:
        # list_stage.sort(key=lambda x: x[1])
        return list_stage[0][0],list_stage[0][2]
    if re.search("总承包|EPC",_content) is not None:
        if re.search("设计",_content) is not None:
            return "设计阶段","设计"
        else:
            return "施工在建","总承包"
    return None,None

def read_industry_keyword(_path):
    df = pd.read_excel(_path)
    list_data = []
    for _kw,_industry,_idf in zip(df["关键词"],df["行业"],df["权重"]):
        _dict = {"keyword":_kw,
                 "industry":_industry,
                 "idf":_idf}
        list_data.append(_dict)
    return list_data

def getKeywordPattern(list_industry_keyword):
    list_keyword = []
    for _ik in list_industry_keyword:
        list_keyword.append(_ik.get("keyword",""))
    return "|".join([re.escape(i) for i in list_keyword])

def getDict_keyword(list_industry_keywrod):
    dict_keyword = {}
    for _ik in list_industry_keywrod:
        dict_keyword[_ik.get("keyword")] = _ik
    return dict_keyword


def extract_industry(dict_keyword,_pattern,content):
    dict_industry_prob = {}
    list_keyword = re.findall(_pattern,content)
    for word in list_keyword:
        if word!="":
            _ik = dict_keyword.get(word)
            if _ik is not None:
                _industry = _ik.get("industry")
                _idf = _ik.get("idf",0)
                if _industry not in dict_industry_prob:
                    dict_industry_prob[_industry] = 0
                dict_industry_prob[_industry] += _idf
    _industry = "未知"
    max_prob = 0
    for k,v in dict_industry_prob.items():
        if v>max_prob:
            max_prob = v
            _industry = k
    return _industry

def getWinTenderer(sub_docs_json,ots_client):
    _win_tenderer = ""
    _win_tenderer_contact_person = ""
    _win_tenderer_contact_phone = ""
    if sub_docs_json is None or sub_docs_json=="":
        pass
    else:
        sub_docs = json.loads(sub_docs_json)
        for _doc in sub_docs:
            if _doc.get("win_tenderer","")!="":
                _win_tenderer =  _doc.get("win_tenderer","")
                _win_tenderer_contact_person = _doc.get("win_tenderer_manager","")
                _win_tenderer_contact_phone = _doc.get("win_tenderer_phone","")
                break
    # if _win_tenderer!="":
    #     try:
    #
    #         en = Enterprise({"name":_win_tenderer})
    #         en.fix_columns(ots_client,["contacts"],False)
    #         list_contacts = json.loads(en.getProperties().get("contacts","[]"))
    #         list_contacts.sort(key=lambda x:x.get("score",0))
    #         if len(list_contacts)>0:
    #             _win_tenderer_contact_person = list_contacts[0].get("contact_person","")
    #             _win_tenderer_contact_phone = list_contacts[0].get("phone_no","")
    #             if _win_tenderer_contact_phone=="":
    #                 _win_tenderer_contact_phone = list_contacts[0].get("mobile_no","")
    #
    #     except Exception as e:
    #         pass
    return _win_tenderer,_win_tenderer_contact_person,_win_tenderer_contact_phone

def getIndustry(dict_industry):
    list_industry = []
    for k,v in dict_industry.items():
        list_industry.append([k,v])
    list_industry.sort(key=lambda x:x[1],reverse=True)
    industry = "未知"
    if len(list_industry)>0:
        industry = list_industry[0][0]
        if industry=="未知":
            if len(list_industry)>1:
                industry = list_industry[1][0]
    return industry

def dynamicDumplicate(list_dynamic):
    _set = set()
    l_d = []
    for _dynamic in list_dynamic:
        _key = "%s-%s"%(_dynamic.get("project_stage",""),_dynamic.get("page_time",""))
        if _key in _set:
            continue
        _set.add(_key)
        l_d.append(_dynamic)
    return l_d

def dynamicDumplicate2(list_dynamic,stage_order):
    _set = set()
    l_d = []
    list_dynamic.sort(key=lambda x:x.get("page_time",""))

    # list_dynamic.sort(key=lambda x:1 if x.get("docchannel","") in (101,119,120) else 0,reverse=True)


    #stage_keyword,docchannel去重

    dict_stage_channel_dynamic = {}

    last_stage = 0
    set_stage = set()
    for _dynamic in list_dynamic:

        _stage = _dynamic.get(project_dynamics_project_stage,"")
        if _stage=="":
            continue
        current_stage = stage_order.get(_stage,-1)
        if current_stage<last_stage:
            continue

        set_stage.add(_stage)
        last_stage = current_stage

        stage_keyword = _dynamic.get("project_stage_keyword","")
        new_channel = _dynamic.get("docchannel","")
        if new_channel in (101,119,120):
            new_channel = 1101
        if new_channel in (51,103,104,105,115,116,117):
            new_channel = 1201
        if _dynamic.get("sp_type","")!="":
            new_channel = 1001


        _key = "%s-%s"%(str(stage_keyword),str(new_channel))
        if new_channel!=1101:
            if _key in _set:
                continue
            else:
                dict_stage_channel_dynamic[_key] = _dynamic
        else:
            if _key in _set:
                b_dynamic = dict_stage_channel_dynamic[_key]
                if b_dynamic.get(project_dynamics_win_tenderer,"")=="" and _dynamic.get(project_dynamics_win_tenderer,"")!="":
                    dict_stage_channel_dynamic[_key] = _dynamic
            else:
                dict_stage_channel_dynamic[_key] = _dynamic

        _set.add(_key)
    for k,v in dict_stage_channel_dynamic.items():
        l_d.append(v)
        l_d.sort(key=lambda x:x.get(project_dynamics_page_time,""))
    return l_d,list(set_stage)


def getMaxStage(list_dynamic,stage_order):
    max_stage_index = -1
    _stage = "未知"
    for _dynamic in list_dynamic:
        project_stage = _dynamic.get("project_stage")
        if project_stage is None:
            continue
        if list(stage_order).count(project_stage)>0:
            _index = list(stage_order).index(project_stage)
            if _index>max_stage_index:
                max_stage_index = _index
                _stage = project_stage
    return _stage

class MajorUnion():

    def __init__(self):
        self.ots_client = getConnect_ots()
        self.search_columns = [major_project_project_name,major_project_province,major_project_project_stage,major_project_plan_start_time,major_project_total_investment]


        self.stage_pattern,self.stage_priority_dict = get_stage_pattern()
        self.current_path = os.path.abspath(os.path.dirname(__file__))

        self.list_industry_keyword = read_industry_keyword(os.path.join(self.current_path,"major_project_industry_keyword.xlsx"))
        self.keyword_pattern = getKeywordPattern(self.list_industry_keyword)
        self.dict_keyword = getDict_keyword(self.list_industry_keyword)

        self.stage_order = {"立项阶段":1,
                            "可研阶段":2,
                            "环评阶段":2,
                            "稳评阶段":2,
                            "咨询阶段":2,
                            "造价阶段":2,
                            "设计阶段":2,
                            "勘察阶段":2,
                            "施工图审":2,
                            "施工许可":2,
                            "施工准备":2,
                            "施工在建":3,
                            "竣工阶段":4,
                            }


    def producer(self):
        bool_query = BoolQuery(must_queries=[
            RangeQuery(major_project_status,1,50,True,True),
            # RangeQuery(major_project_status,201,301,True,True),
            # TermQuery(major_project_id,"00048953975ad762e883f1626f6b99ec")
            ]
        )

        # self.search_columns = [major_project_status]
        task_queue = Queue()

        rows,next_token,total_count,is_all_succeed = self.ots_client.search("major_project","major_project_index",
                                                                            SearchQuery(bool_query,sort=Sort(sorters=[FieldSort("status")]),get_total_count=True,limit=100),
                                                                            ColumnsToGet(self.search_columns,ColumnReturnType.SPECIFIED))
        log("major producer total count:%d"%(total_count))
        list_data = getRow_ots(rows)
        for _data in list_data:
            task_queue.put(_data)

        while next_token:
            rows,next_token,total_count,is_all_succeed = self.ots_client.search("major_project","major_project_index",
                                                                                SearchQuery(bool_query,next_token=next_token,get_total_count=True,limit=100),
                                                                                ColumnsToGet(self.search_columns,ColumnReturnType.SPECIFIED))
            list_data = getRow_ots(rows)
            for _data in list_data:
                task_queue.put(_data)
            if task_queue.qsize()>=3000:
                break
        return task_queue

    def set_status_to_adult(self,_major):
        _major.setValue(major_project_status,random.randint(201,300),True)


    def extract_projectDigest(self,content):
        _pattern = "(?P<projectDigest>(项目|工程|标的|需求|建设|招标|采购|内容)(概况|规模|简介|信息|范围|内容|说明|摘要).{10,300})"
        _pattern_search = re.search(_pattern,content)
        _projectDigest = ""
        _find = ""
        if _pattern_search is not None:
            _find = _pattern_search.groupdict().get("projectDigest","")
        if len(_find)>0:
            _projectDigest = "。".join(_find.split("。")[0:3])
        return _projectDigest


    def _handle1(self,item,result_queue):
        # _major = MajorProject(item)
        # _major.setValue(major_project_status,1,True)
        # _major.update_row(self.ots_client)
        # return

        project_name = item.get(major_project_project_name,"")


        province = item.get(major_project_province,"")
        _major = MajorProject(item)
        if project_name=="":

            #修改status
            self.set_status_to_adult(_major)
            _major.update_row(self.ots_client)
            return

        enterprise = Enterprise({"name":project_name})
        if enterprise.exists_row(self.ots_client):
            _major.setValue(major_project_industry,"",True)
            _major.setValue(major_project_project_dynamics,"[]",True)
            _major.setValue(major_project_project_dynamic_number,0,True)
            _major.setValue(major_project_project_stage,"",True)
            _major.setValue(major_project_latest_page_time,"",True)
            _major.setValue(major_project_update_time,getCurrent_date(format="%Y-%m-%d %H:%M:%S"),True)
            _major.setValue(major_project_all_project_dynamics,"[]]",True)
            _major.setValue(major_project_all_project_dynamic_number,0,True)
            _major.setValue(major_project_project_stages,",".join([]),True)
            self.set_status_to_adult(_major)
            _major.update_row(self.ots_client)
            self.set_status_to_adult(_major)
            _major.update_row(self.ots_client)
            return


        list_dynamics = []

        if len(project_name)>6:
            bool_query_sp = BoolQuery(must_queries=[
                MatchPhraseQuery("page_content",project_name),
                MatchPhraseQuery("province",province)
            ])
        else:
            bool_query_sp = BoolQuery(must_queries=[
                MatchPhraseQuery("page_title",project_name),
                MatchPhraseQuery("province",province)
            ])

        rows,next_token,total_count,is_all_succeed = self.ots_client.search("t_shen_pi_xiang_mu","t_shen_pi_xiang_mu_index",
                                                                            SearchQuery(bool_query_sp,limit=100),
                                                                            ColumnsToGet(["province","page_title","page_content","page_time","sp_type"],ColumnReturnType.SPECIFIED))
        list_data = getRow_ots(rows)
        dict_industry = {}

        list_area = []
        list_construction = []
        list_contact = []
        dict_tenderee = {}

        for _data in list_data:
            _content = _data.get("page_title","")+_data.get("page_content","")[:100]
            _stage,_stage_keyword = extract_legal_stage(_content,self.stage_pattern,self.stage_priority_dict)
            _dynamic = {"docid":str(_data.get("id")),
                        "doctype":2,
                        "doctitle":_data.get("page_title",""),
                        "page_time":_data.get("page_time",""),
                        "sp_type":str(_data.get("sp_type","")),
                        "project_stage":_stage,
                        "project_stage_keyword":_stage_keyword}
            list_dynamics.append(_dynamic)
            _industry = extract_industry(self.dict_keyword,self.keyword_pattern,_content)
            if _industry not in dict_industry:
                dict_industry[_industry] = 0
            dict_industry[_industry] += 1

            _construction = self.extract_projectDigest(_content)
            list_construction.append(_construction)

            _area = _data.get(document_area,"")
            _province = _data.get(document_province,"")
            _city = _data.get(document_city,"")
            _district = _data.get(document_district,"")

            _score = 0
            if _area!="":
                _score += 1
            if _province!="":
                _score += 1
            if _city!="":
                _score += 1
            if _district!="":
                _score += 1
            list_area.append({document_area:_area,
                              document_province:_province,
                              document_city:_city,
                              document_district:_district,
                              "score":_score})

            _tenderee = _data.get(document_tenderee,"")
            if _tenderee!="":
                if _tenderee not in dict_tenderee:
                    dict_tenderee[_tenderee] = 0
                dict_tenderee[_tenderee] += 1

            tenderee_contact = _data.get(document_tenderee_contact,"")
            tenderee_phone = _data.get(document_tenderee_phone,"")
            contact_score = 0
            if tenderee_phone!="":
                if recog_likeType(tenderee_phone)=="mobile":
                    contact_score += 2
                else:
                    contact_score += 1
            if tenderee_contact!="":
                contact_score += 1
            if contact_score>0:
                list_contact.append({document_tenderee_contact:tenderee_contact,
                                     document_tenderee_phone:tenderee_phone,
                                     "score":contact_score})



        log("%s search sp %d"%(item.get("id"),len(list_data)))


        if len(project_name)>6:
            bool_query_doc = BoolQuery(must_queries=[
                BoolQuery(should_queries=[
                    MatchPhraseQuery("doctitle",project_name),
                    TermQuery("project_name",project_name),
                ]),
                WildcardQuery("province","%s*"%province),
                RangeQuery("status",201,300,True,True)

            ],must_not_queries=[
                TermQuery("docchannel",106),
                TermQuery("docchannel",107)
            ])
        else:
            bool_query_doc = BoolQuery(must_queries=[
                BoolQuery(should_queries=[
                    MatchPhraseQuery("doctitle",project_name),
                    TermQuery("project_name",project_name),
                ]),
                WildcardQuery("province","%s*"%province),
                RangeQuery("status",201,300,True,True)

            ],must_not_queries=[
                TermQuery("docchannel",106),
                TermQuery("docchannel",107)
            ])
        rows,next_token,total_count,is_all_succeed = self.ots_client.search("document","document_index",
                                                                            SearchQuery(bool_query_doc,limit=100),
                                                                            ColumnsToGet(["doctitle","doctextcon","attachmenttextcon","page_time","docchannel","bidway","sub_docs_json","project_name",document_tenderee,document_tenderee_contact,document_tenderee_phone,document_area,document_province,document_city,document_district,document_total_tenderee_money],ColumnReturnType.SPECIFIED))
        list_data = getRow_ots(rows)

        log("%s search doc %d"%(item.get("id"),len(list_data)))
        for _data in list_data:
            _content = _data.get("doctitle","")+_data.get("doctextcon","")+_data.get("attachmenttextcon","")


            stage_content = _data.get("doctitle","")+_data.get("project_name","")
            win_tenderer,win_tenderer_manager,win_tenderer_phone = getWinTenderer(_data.get("sub_docs_json"),self.ots_client)
            _stage,_stage_keyword = extract_legal_stage(stage_content,self.stage_pattern,self.stage_priority_dict)
            _dynamic = {"docid":str(_data.get("docid")),
                        "doctype":1,
                        "doctitle":_data.get("doctitle",""),
                        "page_time":_data.get("page_time",""),
                        "docchannel":_data.get("docchannel",""),
                        "bidway":str(_data.get("bidway","")),
                        "project_stage":_stage,
                        "win_tenderer":win_tenderer,
                        "win_tenderer_manager":win_tenderer_manager,
                        "win_tenderer_phone":win_tenderer_phone,
                        "project_stage_keyword":_stage_keyword}
            list_dynamics.append(_dynamic)
            _industry = extract_industry(self.dict_keyword,self.keyword_pattern,_content)
            if _industry not in dict_industry:
                dict_industry[_industry] = 0
            dict_industry[_industry] += 1

            total_tenderee_money = _data.get(document_total_tenderee_money,0)
            if total_tenderee_money>0:
                if _major.getProperties().get(major_project_total_investment,0)==0:
                    _major.setValue(major_project_total_investment,total_tenderee_money/10000,True)

            _construction = self.extract_projectDigest(_content)
            list_construction.append(_construction)

            _area = _data.get(document_area,"")
            _province = _data.get(document_province,"")
            _city = _data.get(document_city,"")
            _district = _data.get(document_district,"")

            _score = 0
            if _area!="":
                _score += 1
            if _province!="":
                _score += 1
            if _city!="":
                _score += 1
            if _district!="":
                _score += 1
            list_area.append({document_area:_area,
                              document_province:_province,
                              document_city:_city,
                              document_district:_district,
                              "score":_score})

            _tenderee = _data.get(document_tenderee,"")
            if _tenderee!="":
                if _tenderee not in dict_tenderee:
                    dict_tenderee[_tenderee] = 0
                dict_tenderee[_tenderee] += 1

            tenderee_contact = _data.get(document_tenderee_contact,"")
            tenderee_phone = _data.get(document_tenderee_phone,"")
            contact_score = 0
            if tenderee_phone!="":
                if recog_likeType(tenderee_phone)=="mobile":
                    contact_score += 2
                else:
                    contact_score += 1
            if tenderee_contact!="":
                contact_score += 1
            if contact_score>0:
                list_contact.append({document_tenderee_contact:tenderee_contact,
                                     document_tenderee_phone:tenderee_phone,
                                     "score":contact_score})


        #补充属性
        if len(list_area)>0:
            list_area.sort(key=lambda x:x.get("score"),reverse=True)
            _dict = list_area[0]
            _major.setValue(major_project_area,_dict.get(document_area,""),True)
            _major.setValue(major_project_province,_dict.get(document_province,""),True)
            _major.setValue(major_project_city,_dict.get(document_city,""),True)
            _major.setValue(major_project_district,_dict.get(document_district,""),True)
        if len(list_construction)>0:
            list_construction.sort(key=lambda x:len(x),reverse=True)
            _major.setValue(major_project_project_overview,list_construction[0],True)
        if len(dict_tenderee.keys())>0:
            _l = []
            for k,v in dict_tenderee.items():
                _l.append([k,v])
            _l.sort(key=lambda x:x[1],reverse=True)
            _major.setValue(major_project_construction_enterprise,_l[0][0],True)

        if len(list_contact)>0:
            list_contact.sort(key=lambda x:x.get("score"),reverse=False)
            _major.setValue(major_project_project_leader,list_contact[0].get(document_tenderee_contact,""),True)
            _major.setValue(major_project_project_leader_phone,list_contact[0].get(document_tenderee_phone,""),True)
        # print(list_data)
        # print(list_dynamics)
        list_dynamics_all =  dynamicDumplicate(list_dynamics)
        industry = getIndustry(dict_industry)
        all_project_dynamics = json.dumps(list_dynamics_all,ensure_ascii=False)
        all_project_dynamic_number = len(list_dynamics_all)

        list_dynamics,list_stage = dynamicDumplicate2(list_dynamics_all,self.stage_order)
        list_dynamics.sort(key=lambda x:x.get("page_time",""),reverse=True)
        project_dynamic_number = len(list_dynamics)
        project_dynamics = json.dumps(list_dynamics,ensure_ascii=False)
        # project_stage = getMaxStage(list_dynamics,self.stage_order)
        current_stage = item.get(major_project_project_stage,"")
        project_stage = "未知"
        latest_page_time = ""

        if len(list_dynamics)>0:
            list_dynamics.sort(key=lambda x:x.get("page_time",""),reverse=True)
            latest_page_time = list_dynamics[0].get("page_time","")
            project_stage = list_dynamics[0].get("project_stage","未知")
        current_date = getCurrent_date(format="%Y")
        plan_start_time = item.get(major_project_plan_start_time,"")
        if (re.search("储备|前期|预备",current_stage) is not None or current_stage=="" or current_stage=="未知") and project_stage=="未知" and plan_start_time>=current_date:
            project_stage = "预备阶段"

        _major.setValue(major_project_industry,industry,True)
        _major.setValue(major_project_project_dynamics,project_dynamics,True)
        _major.setValue(major_project_project_dynamic_number,project_dynamic_number,True)
        _major.setValue(major_project_project_stage,project_stage,True)
        _major.setValue(major_project_latest_page_time,latest_page_time,True)
        _major.setValue(major_project_update_time,getCurrent_date(format="%Y-%m-%d %H:%M:%S"),True)
        _major.setValue(major_project_all_project_dynamics,all_project_dynamics,True)
        _major.setValue(major_project_all_project_dynamic_number,all_project_dynamic_number,True)
        _major.setValue(major_project_project_stages,",".join(list_stage),True)
        self.set_status_to_adult(_major)
        _major.update_row(self.ots_client)

    def comsumer(self):

        task_queue = self.producer()
        mt = MultiThreadHandler(task_queue,self._handle1,None,30)
        mt.run()

    def start_union(self):
        scheduler = BlockingScheduler()
        scheduler.add_job(self.comsumer,"cron",minute="*/1")
        scheduler.start()

def start_major_union():
    mu = MajorUnion()
    mu.start_union()
if __name__ == '__main__':
    start_major_union()
    # mu = MajorUnion()
    # mu.comsumer()