Database_connection_Normal_punch_card.py
    import pymysql

    class DB_Connect_Normal:

    1. ##上班打卡,下班打卡
    2. def db_connect_normal_card(self, attendance_date, started_at, end_at):
    3. # 指定数据库地址、用户、密码、端口,使用connect()方法声明一个Mysql连接对象db
    4. self.db = pymysql.connect(host='192.168.0.229', user='backyard', password='123456', port=3306)
    5. # 调用cursor()方法获得Mysql的操作游标,利用游标来执行SQL语句。
    6. self.cursor = self.db.cursor()
    7. # 直接用execute()方法执行,第一句用于获得Mysql版本,然后调用fetchone()方法获得第一条数据
    8. #attendance_date 考勤日期' "2019-11-20"
    9. #`started_at` '上班打卡时间' '2019-11-20 08:31:15.909'
    10. #`end_at` '下班打卡时间' 2019-11-20 12:31:15.909
    11. sql_daka = "INSERT INTO backyard.staff_work_attendance" \
    12. "(id, staff_info_id, organization_id, organization_type, attendance_date, shift_start, shift_end," \
    13. " working_day, started_at, started_state, started_staff_lat, started_staff_lng, started_store_id, " \
    14. "started_store_lng, started_store_lat, started_clientid, started_clientid_num, started_equipment_type, " \
    15. "started_os, started_path, started_bucket, started_remark, end_at, end_state, end_staff_lat," \
    16. " end_staff_lng, end_store_id, end_store_lng, end_store_lat, end_clientid, end_clientid_num, " \
    17. "end_equipment_type, end_os, end_path, end_bucket, end_remark , created_at, updated_at) " \
    18. "VALUES (NULL, 22344, 'TH01010101', 1, \"%s\", NULL, NULL, 0, \"%s\", 1," \
    19. " 40.03013680, 116.41032670, 'TH01010101', 116.41037800, 40.03036699, '862122049073801460078013055338', 1, " \
    20. "'3', 'android', 'workAttendanceSource/1573806618-b3537b8829bb49949375b93a1ced1d5f.jpg', 'fle-staging-asset-internal'," \
    21. " NULL, \"%s\", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL," \
    22. " '2019-11-20 08:31:15.913', '2019-11-20 08:32:52.845')"%(str(attendance_date), str(started_at), str(end_at))
    23. #self.cursor.execute(sql)
    24. # 执行SQL,并返回收影响行数
    25. effect_row = self.cursor.execute(sql_daka)
    26. # 提交,不然无法保存新建或者修改的数据
    27. self.db.commit()
    28. # self.data = self.cursor.fetchone()
    29. #打印影响的行数
    30. print('database version:', effect_row)
    31. # 关闭游标
    32. self.cursor.close()
    33. # 关闭连接
    34. self.db.close()
    35. ##上班打卡,下班打卡
    36. def db_connect_normal_card_22344(self, attendance_date, started_at, end_at):
    37. # 指定数据库地址、用户、密码、端口,使用connect()方法声明一个Mysql连接对象db
    38. self.db = pymysql.connect(host='192.168.0.229', user='backyard', password='123456', port=3306)
    39. # 调用cursor()方法获得Mysql的操作游标,利用游标来执行SQL语句。
    40. self.cursor = self.db.cursor()
    41. # 直接用execute()方法执行,第一句用于获得Mysql版本,然后调用fetchone()方法获得第一条数据
    42. # attendance_date 考勤日期' "2019-11-20"
    43. # `started_at` '上班打卡时间' '2019-11-20 08:31:15.909'
    44. # `end_at` '下班打卡时间' 2019-11-20 12:31:15.909
    45. sql_daka = "INSERT INTO backyard.staff_work_attendance" \
    46. "(id, staff_info_id, organization_id, organization_type, attendance_date, shift_start, shift_end," \
    47. " working_day, started_at, started_state, started_staff_lat, started_staff_lng, started_store_id, " \
    48. "started_store_lng, started_store_lat, started_clientid, started_clientid_num, started_equipment_type, " \
    49. "started_os, started_path, started_bucket, started_remark, end_at, end_state, end_staff_lat," \
    50. " end_staff_lng, end_store_id, end_store_lng, end_store_lat, end_clientid, end_clientid_num, " \
    51. "end_equipment_type, end_os, end_path, end_bucket, end_remark , created_at, updated_at) " \
    52. "VALUES (NULL, 22344, 'TH01010101', 1, \"%s\", NULL, NULL, 0, \"%s\", 1," \
    53. " 40.03013680, 116.41032670, 'TH01010101', 116.41037800, 40.03036699, '862122049073801460078013055338', 1, " \
    54. "'3', 'android', 'workAttendanceSource/1573806618-b3537b8829bb49949375b93a1ced1d5f.jpg', 'fle-staging-asset-internal'," \
    55. " NULL, \"%s\", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL," \
    56. " '2019-11-20 08:31:15.913', '2019-11-20 08:32:52.845')"%(str(attendance_date), str(started_at), str(end_at))
    57. # self.cursor.execute(sql)
    58. # 执行SQL,并返回收影响行数
    59. effect_row = self.cursor.execute(sql_daka)
    60. # 提交,不然无法保存新建或者修改的数据
    61. self.db.commit()
    62. # self.data = self.cursor.fetchone()
    63. # 打印影响的行数
    64. print('database version:', effect_row)
    65. # 关闭游标
    66. self.cursor.close()
    67. # 关闭连接
    68. self.db.close()
    69. #只有上班打卡,下班没有打卡
    70. def db_connect_normal_card_end_at_null(self,attendance_date, started_at):
    71. # 指定数据库地址、用户、密码、端口,使用connect()方法声明一个Mysql连接对象db
    72. self.db = pymysql.connect(host='192.168.0.229', user='backyard', password='123456', port=3306)
    73. # 调用cursor()方法获得Mysql的操作游标,利用游标来执行SQL语句。
    74. self.cursor = self.db.cursor()
    75. # 直接用execute()方法执行,第一句用于获得Mysql版本,然后调用fetchone()方法获得第一条数据
    76. # attendance_date 考勤日期' "2019-11-20"
    77. # `started_at` '上班打卡时间' '2019-11-20 08:31:15.909'
    78. # sql_end_at_null = "INSERT INTO backyard.staff_work_attendance" \
    79. # "(id, staff_info_id, organization_id, organization_type, attendance_date, shift_start, shift_end," \
    80. # " working_day, started_at, started_state, started_staff_lat, started_staff_lng, started_store_id, " \
    81. # "started_store_lng, started_store_lat, started_clientid, started_clientid_num, started_equipment_type, " \
    82. # "started_os, started_path, started_bucket, started_remark, end_at, end_state, end_staff_lat," \
    83. # " end_staff_lng, end_store_id, end_store_lng, end_store_lat, end_clientid, end_clientid_num, " \
    84. # "end_equipment_type, end_os, end_path, end_bucket, end_remark , created_at, updated_at) " \
    85. # "VALUES (NULL, 22344, 'TH01010101', 1, \"%s\", NULL, NULL, 0, \"%s\", 1," \
    86. # " 40.03013680, 116.41032670, 'TH01010101', 116.41037800, 40.03036699, '862122049073801460078013055338', 1, " \
    87. # "'3', 'android', 'workAttendanceSource/1573806618-b3537b8829bb49949375b93a1ced1d5f.jpg', 'fle-staging-asset-internal'," \
    88. # " NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL," \
    89. # " '2019-11-20 08:31:15.913', '2019-11-20 08:32:52.845')" % (
    90. # str(attendance_date), str(started_at))
    91. sql_end_at_null = """
    92. INSERT INTO backyard.staff_work_attendance (id,staff_info_id,organization_id,organization_type,attendance_date,shift_start,shift_end,working_day,started_at,started_state,started_staff_lat,started_staff_lng,started_store_id,started_store_lng,started_store_lat,started_clientid,started_clientid_num,started_equipment_type,started_os,started_path,started_bucket,started_remark,end_at,end_state,end_staff_lat,end_staff_lng,end_store_id,end_store_lng,end_store_lat,end_clientid,end_clientid_num,end_equipment_type,end_os,end_path,end_bucket,end_remark,created_at,updated_at) \
    93. VALUES (1623655,22344,'TH01010101',1,'2019-11-26',NULL,NULL,0,'2019-11-26 02:00:00.909',1,40.03013680,116.41032670,'TH01010101',116.41037800,40.03036699,'862122049073801460078013055338',1,'3','android','workAttendanceSource/1573806618-b3537b8829bb49949375b93a1ced1d5f.jpg','fle-staging-asset-internal',NULL,'2019-11-26 12:55:00.909',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'2019-11-26 02:00:15.913','2019-11-26 12:55:00.845')
    94. """
    95. # self.cursor.execute(sql)
    96. # 执行SQL,并返回收影响行数
    97. # sqlString = "SELECT * FROM backyard.staff_work_attendance"
    98. # effect_row = self.cursor.execute(sqlString)
    99. try:
    100. effect_row = self.cursor.execute(sql_end_at_null)
    101. print('database version:', effect_row)
    102. # 提交,不然无法保存新建或者修改的数据
    103. self.db.commit()
    104. except Exception as e:#捕获数据库执行语句异常
    105. print(e)
    106. # self.data = self.cursor.fetchone()
    107. # 打印影响的行数
    108. # print('database version:', effect_row)
    109. # 关闭游标
    110. self.cursor.close()
    111. # 关闭连接
    112. self.db.close()
    113. # 只有上班打卡,下班没有打卡
    114. def db_connect_normal_card_end_at_null_22344(self, attendance_date, started_at):
    115. # 指定数据库地址、用户、密码、端口,使用connect()方法声明一个Mysql连接对象db
    116. self.db = pymysql.connect(host='192.168.0.229', user='backyard', password='123456', port=3306)
    117. # 调用cursor()方法获得Mysql的操作游标,利用游标来执行SQL语句。
    118. self.cursor = self.db.cursor()
    119. # 直接用execute()方法执行,第一句用于获得Mysql版本,然后调用fetchone()方法获得第一条数据
    120. # attendance_date 考勤日期' "2019-11-20"
    121. # `started_at` '上班打卡时间' '2019-11-20 08:31:15.909'
    122. sql_end_at_null = "INSERT INTO backyard.staff_work_attendance" \
    123. "(id, staff_info_id, organization_id, organization_type, attendance_date, shift_start, shift_end," \
    124. " working_day, started_at, started_state, started_staff_lat, started_staff_lng, started_store_id, " \
    125. "started_store_lng, started_store_lat, started_clientid, started_clientid_num, started_equipment_type, " \
    126. "started_os, started_path, started_bucket, started_remark, end_at, end_state, end_staff_lat," \
    127. " end_staff_lng, end_store_id, end_store_lng, end_store_lat, end_clientid, end_clientid_num, " \
    128. "end_equipment_type, end_os, end_path, end_bucket, end_remark , created_at, updated_at) " \
    129. "VALUES (NULL, 22344, 'TH01010101', 1, \"%s\", NULL, NULL, 0, \"%s\", 1," \
    130. " 40.03013680, 116.41032670, 'TH01010101', 116.41037800, 40.03036699, '862122049073801460078013055338', 1, " \
    131. "'3', 'android', 'workAttendanceSource/1573806618-b3537b8829bb49949375b93a1ced1d5f.jpg', 'fle-staging-asset-internal'," \
    132. " NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL," \
    133. " '2019-11-20 08:31:15.913', '2019-11-20 08:32:52.845')" % (
    134. str(attendance_date), str(started_at))
    135. # self.cursor.execute(sql)
    136. # 执行SQL,并返回收影响行数
    137. effect_row = self.cursor.execute(sql_end_at_null)
    138. # 提交,不然无法保存新建或者修改的数据
    139. self.db.commit()
    140. # self.data = self.cursor.fetchone()
    141. # 打印影响的行数
    142. print('database version:', effect_row)
    143. # 关闭游标
    144. self.cursor.close()
    145. # 关闭连接
    146. self.db.close()

    if name == ‘main‘:
    db = DB_Connect_Normal()
    # db.db_connect_normal_card(“2019-11-20”, “2019-11-20 08:31:15.909”, “2019-11-20 12:31:15.909”)
    db.db_connect_normal_card_end_at_null(“2019-11-20”, “2019-11-20 08:31:15.909”)