| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 | # Author renyupeng# coding=utf-8# @Time    : 2021/11/17 6:48 下午# @Site    : # @File    : MonitorTask.py# @Software: PyCharm# @contact: renyupeng@c-top.com.cn# @Tel 1501435553import loggingfrom Apietl.conn.TidbConn import TidbConnfrom Apietl.conn.TidbProConn import TidbProConnfrom OuterDataCompareInnerData.Utils.sendMessage import feishuMsgclass MonitorTask:    def __init__(self):        self.InnerConn = TidbConn.get_connection()        self.OuterConn = TidbProConn.get_connection()        self.table_list = ['ctop_account_attribution_info',                           'ctop_advertiser',                           'ctop_cwjs_agent_info',                           'ctop_material_ascription',                           'ctop_material_image_info',                           'ctop_material_info',                           'ctop_material_tag_info',                           'ctop_oauth_token',                           'ctop_product',                           'ctop_project',                           'ctop_project_member',                           'ctop_tag_info',                           'ctop_user_allocation',                           'sys_company',                           'sys_depart',                           'sys_depart_permission',                           'sys_depart_role',                           'sys_depart_role_permission',                           'sys_depart_role_user',                           'sys_permission',                           'sys_role',                           'sys_role_permission',                           'sys_user',                           'sys_user_agent',                           'sys_user_depart',                           'sys_user_role',                           'user_company'                           ]    def CheckTask(self):        try:            for table in self.table_list:                try:                    sql = """select count(1) from `jeecg-boot`.{table}""".format(table=table)                    InnertotalNum = TidbConn.quary(self.InnerConn, sql)[0][0]                    OutertotalNum = TidbConn.quary(self.OuterConn, sql)[0][0]                    if InnertotalNum != OutertotalNum:                        print("""{table} 内网数量为{InnertotalNum},外网数量为{OutertotalNum} 数量不想等""".format(table=table,                                                                                                   InnertotalNum=InnertotalNum,                                                                                                   OutertotalNum=OutertotalNum))                        feishuMsg.send_robot_msg(                            """{table} 内网数量为{InnertotalNum},外网数量为{OutertotalNum}数量不想等""".format(table=table,                                                                                                InnertotalNum=InnertotalNum,                                                                                                OutertotalNum=OutertotalNum))                except Exception as e:                    logging.error(e)            TidbConn.conn_close(conn=self.InnerConn)            TidbProConn.conn_close(conn=self.OuterConn)        except Exception as e:            logging.error(e)if __name__ == '__main__':    MonitorTask().CheckTask()
 |