def insert_same_data(bon_version, url, new_data, shape_data, bin_data, comment, best_num): conn = Mssql() sql_text = "SELECT * FROM T_BOM_PlateUtilUsedRate WHERE BOMVersion='%s'" % bon_version # 拿结果 res = conn.exec_query(sql_text) # 先看是否存在, 存在就删除原来数据 sql_text = "delete T_BOM_PlateUtilState where BOMVersion='%s'" % new_data['BOMVersion'] conn.exec_non_query(sql_text) sql_text = "delete T_BOM_PlateUtilUsedRate where BOMVersion='%s'" % new_data['BOMVersion'] conn.exec_non_query(sql_text) # 插入新数据 insert_data = list() for data in res: insert_data.append((new_data['SkuCode'], new_data['BOMVersion'], data[3], data[4])) sql_text = "insert into T_BOM_PlateUtilUsedRate values (%s, %s, %s, %s)" conn.exec_many_query(sql_text, insert_data) # 插入新的状态 timestamps = dt.today().strftime('%Y-%m-%d %H:%M:%S') sql_text = "insert into T_BOM_PlateUtilState values ('%s','%s','%s','%s','%s','%s','%s','%s','%s', '%s')" % ( new_data['SkuCode'], new_data['BOMVersion'], comment, url, shape_data, bin_data, OK_STATUS, timestamps, timestamps, best_num) conn.exec_non_query(sql_text)
def update_result(data): update_middle_result(data) conn = Mssql() if 'rates' in data.keys(): # 先看是否存在, 存在就删除原来数据 sql_text = "delete T_BOM_PlateUtilUsedRate where BOMVersion='%s'" % data['BOMVersion'] conn.exec_non_query(sql_text) sql_text = "insert into T_BOM_PlateUtilUsedRate values (%s, %s, %s, %s)" conn.exec_many_query(sql_text, data['rates'])
def insert_work(data): insert_data = list() for d in data: insert_data.append(( d['SkuCode'], d['BOMVersion'], d['Product'], '', d['ShapeData'], d['BinData'], u'新任务', d['Created'].strftime('%Y-%m-%d %H:%M:%S'), d['Created'].strftime('%Y-%m-%d %H:%M:%S'), 0 )) conn = Mssql() insert_sql = "insert into T_BOM_PlateUtilState values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%d)" conn.exec_many_query(insert_sql, insert_data)
def insert_mix_status(paramets, user_name, other): created = dt.today() conn = Mssql() row_id = uuid.uuid4() sql_text = "insert into T_BOM_PlateUtilMixedState values ('%s','%s','%s','%s','%s','%s','%s', '%s', '%s', '%s')" % ( row_id, u'新任务', ' ', paramets['comment'], user_name, created.strftime('%Y-%m-%d %H:%M:%S'), created.strftime('%Y-%m-%d %H:%M:%S'), paramets['shape_data'], paramets['bin_data'], other) conn.exec_non_query(sql_text) # 更新明细 comments = json.loads(paramets['comment']) # 整理数据 insert_data = list() for data in comments: insert_data.append( (row_id, data['Series'], data['SkuCode'], data['ItemName'], data['SkuName'], data['SeriesVersion'], data['BOMVersion'], data['Amount'])) sql_text = "insert into T_BOM_PlateUtilMixedDetail values (%s,%s,%s,%s,%s,%s,%s,%s)" conn.exec_many_query(sql_text, insert_data) return row_id