Ejemplo n.º 1
0
    def to_ot_judgment_diffed(self, old, todat):
        """选择to库,此处可以是个任意库,但是必须对应配置文件中的库.

        此前该方法作为验证正确性使用,现在用于更新使用


        """

        # if old.status in ['-1', '3', '1'] or (not old.url):
        #    return

        print old.id, old.url
        olds = Otraw

        #diff = ot_judgment_diffed()

        print "[Analysis to %s] time: %s " % (todat, time.strftime('%y-%m-%d %H-%M-%S'))

        if ('openlaw' in old.url):
            self.point.set_tablename(Open)
            self.point.set_filter(filter='id = %s' % old.parent_id, limit=1)

        else:
            self.point.set_tablename(olds)
            self.point.set_filter(filter='id = %s' % old.parent_id, limit=1)

        old_data = self.point.query()
        if not old_data:
            return

        old_data = old_data[0]

        analysis_data = self.fuzzy_analyse(old_data)

        """将此处代码注释去掉,可对验证正确性库进行写入数据
        new_plain_lawyer = {'Success': old.plaintiff_lawyers,
                            'old': plaintiff_lawyers,
                            'new': analysis_data[1][1]
                            }
        new_defen_lawyer = {'Success': old.defendant_lawyers,
                    'old': defendant_lawyers,
                    'new': analysis_data[2][1]
                    }
        plaintiff = ';'.join(u"%s:%s:%s" % client for client in old_data.clients_attr[u'原告'])
        defendant = ';'.join(u"%s:%s:%s" % client for client in old_data.clients_attr[u'被告'])
        
        new_plain_people = {'Success': old.plaintiff, 
                            'old': plaintiff,
                            'new': analysis_data[1][0]
                            }
        new_defen_people = {'Success': old.defendant, 
                            'old': defendant,
                            'new': analysis_data[2][0]
                            }
        
        diff.case_sign = analysis_data[0][3]
        diff.header = analysis_data[0][0]
        diff.content = analysis_data[0][2]
        diff.firsthead = analysis_data[0][1]
        diff.defendant = json.dumps(new_defen_people)
        diff.defendant_lawyers = json.dumps(new_defen_lawyer)
        diff.plaintiff = json.dumps(new_plain_people)
        diff.plaintiff_lawyers = json.dumps(new_plain_lawyer)
        diff.judgmentid = old.id
        diff.url = old.url
        point = insert_database('Judgment', tablename = todat, editor = diff)  #设置添加数据
        point.insert()   #添加数据
        """

        Update = ot_judge_base()

        # if (not old.chief_judge and not old.judge and not old.acting_judges ) or \
        #   (u'事务所' not in analysis_data[1][1] and u'事务所' not in analysis_data[2][1]):
        # : 删除信息
        # print 'Delete new Analy %s' % old.id
        # point = insert_database('Judgment', tablename = ot_judge_base, filter = 'id = %s' % old.id)
        # point.delete()
        #    pass
        #: 更新CASE_SIGN
        case_sign = analysis_data[0][3].split('\n')
        Update.case_sign = '<p>' + '</p><p>'.join(case_sign) + '</p>'
        # else:
        Pules = {}
        #: 更新案由信息
        anyou = []
        if old.type == u'行政':
            #: 检查标题
            anyou.extend(filter(lambda x: x in analysis_data[0][0], ACTIONS))
            if not anyou:
                #: 检查第一行
                anyou.extend(filter(
                    lambda x: x in "".join(analysis_data[0][2].split('\n')[:1]), ACTIONS))

        else:
            anyou.extend(filter(
                lambda x: x in "".join(analysis_data[0][2].split('\n')[:1]), ACTIONS))
            # if not anyou:
            anyou.extend(filter(lambda x: x in analysis_data[0][0], ACTIONS))

        for item in anyou:
            Pules[len(item)] = item

        if Pules:
            anyou = Pules[max(Pules)]

        if anyou:
            Update.anyou_id = ACTION_ID[anyou.strip()]
            if ANYOU_ALIAS.has_key(anyou):
                Update.anyou = ANYOU_ALIAS[anyou]
            else:
                Update.anyou = anyou
        else:
            Update.anyou = ''
            Update.anyou_id = 0
        # print Update.anyou_id
        area_item = AREA.ident(old.department.replace(u'县', '').replace(u'自治区', '')
                               .replace(u'管城回族区', '管城回区').encode('gbk'))

        if area_item:
            Update.areacode = area_item['areano']
        else:
            area_item = AREA.ident(
                old.department.replace(u'市', '').replace(u'区', '').replace(u'省', '').encode('gbk'))
            if area_item:
                Update.areacode = area_item['areano']

        # print 'Update new Analysis'
        Update.defendant = analysis_data[2][0]
        Update.defendant_lawyers = analysis_data[2][1]
        Update.plaintiff = analysis_data[1][0]
        Update.plaintiff_lawyers = analysis_data[1][1]
        Update.id = old.id

        #: 更新审判人员信息
        case_sign_key = analysis_data[3]

        Update.chief_judge = ",".join(case_sign_key[u'审判长'])
        Update.acting_judges = ",".join(case_sign_key[u'代理审判员'])
        Update.judge = ",".join(case_sign_key[u'审判员'])
        Update.clerk = ",".join(list(set(case_sign_key[u'书记员'])))

        head_key = analysis_data[4]

        Update.department = head_key['department']
        Update.case_number = head_key['case_number']

        Update.type = head_key['type']
        Update.title = head_key['title']

        #: 分析裁判时间
        Update.end_date = arrow.get(
            analysis_data[6], 'Asia/Shanghai').timestamp
        #: 敏感信息
        Update.replace_data = analysis_data[5]

        #: 检查敏感信息
        #: for item in REPLACE:
        #:     if item in old_data.content_all:
        #:          Update.replace_data[item] = '****'

        Update.replace_data = json.dumps(Update.replace_data)
        #: 开始检查数据 正确性
        ero = JudgmentCheck.Judgment_checking(
            analysis_data[0][0], analysis_data[0][1], analysis_data[0][2], analysis_data[0][3])

        #: 验证案由
        ero.Checking_anyou(Update.anyou, old.type)

        #: 验证地区
        ero.Checking_area(Update.areacode, old.department)

        #: 验证原告被告
        ero.Checking_people(Update.plaintiff, Update.defendant)

        #: 验证原、被告律师
        ero.Checking_lawyer(Update.plaintiff_lawyers, Update.defendant_lawyers)

        #: 验证署名
        #: 署名可以添加详细署名
        #:如
        #: keys = {'judge': old.judge}
        #: ero.Checking_sign(keys)
        #: 这样就可以验证详细的署名信息
        ero.Checking_sign()

        #: 审理机构检查
        ero.Checking_department(old.department.decode('utf8'))

        if not ero.errors:
            for attr in old.__dict__.keys():
                if not getattr(old, attr) or str(getattr(old, attr)).strip() == u'无':
                    if (not getattr(Update, attr)) or str(getattr(Update, attr)).strip() == '':
                        setattr(Update, attr, u'无')
            Update.come_from = 'Update_Judgment_Checking_Success'
            Update.base_check = 1
            Update.status = 2

        else:

            Update.come_from = 'Update_Judgment_Checking_Faild'
            Update.status = 0
            Update.base_check = 0

        point = insert_database(
            'Judgment', tablename=ot_judge_base, editor=Update)
        code = point.update()
        if code == 1062:
            #: 存在重复数据
            print "Delte From id = %s, table = %s" % (Update.id, ot_judge_base.__name__)
            point.set_filter('id = %s' % old.id)
            point.delete()
        return
Ejemplo n.º 2
0
def insert_base(old, Update_id=0):
    area = Area_duct()
    actions_id, actions, replace, anyou_alias = anyou_replace("Judgment")
    new = ot_judge_base()
    for attr in ("content", "case_sign", "case_type", "department", "end_date"):
        if getattr(old, attr) is None:
            print >> __output__, u"【提示】%s 字段为空,请检查数据" % attr
            return
    # if old.case_type not in self.case_mode:
    #    return
    for mode in case_mode:
        if mode in old.case_type:
            new.case_type = mode
    if not new.case_type:
        print >> __output__, u"【提示】文书字号为空"
        return
    if old.content == "":
        print >> __output__, "u你所访问的数据为空"
    new.content = "<p>" + "</p><p>".join(old.content.split("\n")) + "</p>"
    new.content_md5 = md5(new.content.encode("utf8")).hexdigest()
    new.case_sign = "<p>" + "</p><p>".join(old.case_sign.split("\n")) + "</p>"
    new.case_number = old.case_number

    new.type = new.case_type[:-3]
    #: 如果是仲裁,那属于民事
    if new.type == u"仲裁":
        new.type = u"民事"
    new.title = old.title
    if not new.title:
        new.title = old.content_all.split("\n")[0]

    Pules = {}
    #: 更新案由信息

    if new.type == u"行政":
        anyou = filter(lambda x: x in new.title, actions)
        if not anyou:
            anyou = filter(lambda x: x in old.content.split("\n")[0], actions)
            if anyou:
                anyou = anyou[0]
        else:
            for item in anyou:
                Pules[len(item)] = item
    else:
        anyou = filter(lambda x: x in old.content.split("\n")[0], actions)
        if not anyou:
            anyou = filter(lambda x: x in new.title, actions)
            for item in anyou:
                Pules[len(item)] = item
        else:
            anyou = anyou[0]
    if Pules:
        anyou = Pules[max(Pules)]

    new.anyou_id = actions_id[anyou.strip()]
    new.anyou = anyou
    # new.anyou_id = actions_id[new.anyou]

    new.department = old.department

    new.chief_judge = old.chief_judge

    new.judge = old.judge

    if old.acting_judges:
        new.acting_judges = old.acting_judges
    else:
        new.acting_judges = "无"

    new.clerk = old.clerk

    new.plaintiff = ";".join(u"%s:%s:%s" % client for client in old.clients_attr[u"原告"])
    new.plaintiff_lawyers = ";".join(u"%s:%s" % lawyer for lawyer in old.lawyers_attr[u"原告"])
    print >> __plai_people__, u"原告:%s, 律师:%s" % (new.plaintiff, new.plaintiff_lawyers)
    new.defendant = ";".join(u"%s:%s:%s" % client for client in old.clients_attr[u"被告"])
    new.defendant_lawyers = ";".join(u"%s:%s" % lawyer for lawyer in old.lawyers_attr[u"被告"])
    print >> __defan_people__, u"被告:%s, 律师:%s" % (new.defendant, new.defendant_lawyers)
    new.procedure = old.procedure

    new.end_date = arrow.get(old.end_date, "Asia/Shanghai").timestamp

    # 分析地区
    area_item = area.ident(new.department.encode("gbk"))

    if area_item and area_item.get("staut") == "timed out":
        new.areacode = area_item["areano"]

    new.url = old.referer

    print >> __infomation__, old.case_sign
    new.replace_data = json.dumps(old.replace_data)
    # dic = {}
    # for k, v in old.replace_data.iteritems():
    #    if not re.match(ur".*(某|X|x|\*).*", k):
    #        dic.update({k:v})
    # new.replace_data = json.dumps(dic)
    new.input_time = arrow.now().timestamp
    if (not new.chief_judge and not new.judge and not new.acting_judges.strip()) or (
        u"事务所" not in new.plaintiff_lawyers and u"事务所" not in new.defendant_lawyers
    ):
        print >> __output__, u"不存在事务所或者署名信息"
        return
    print old.id
    if Update_id != 0:
        new.id = Update_id
        new.url = old.url
        point = insert_database("Judgment", tablename=ot_judge_base, editor=new)
        point.update()
    else:
        point = insert_database("Judgment", tablename=ot_judge_base, editor=new)
        point.insert()