def getDetailTable(): _id = request.args.get('product_info_id') print("Detail Ajax : ", end='') print(_id) if current_user.is_authenticated: print(current_user) try: db_object = MongodbConnection() rows_collection = db_object.db_conn(db_object.db_client(), 'history') history_list = list( query.find_history_all_item(rows_collection, _id)) except Exception as e: print("DB_error : insert_manufacture()", end=" : ") print(e) print(history_list) product_info_list = [] try: rows_collection = db_object.db_conn(db_object.db_client(), 'product_info') product_info_dic = query.find_production_info_item( rows_collection, _id) except Exception as e: print("DB_error : insert_manufacture()", end=" : ") print(e) finally: db_object.db_close() print(product_info_dic) try: rows_collection = db_object.db_conn(db_object.db_client(), 'model') model_dic = rows_collection.find_one( {'_id': product_info_dic['model_id']}) except Exception as e: print("DB_error : insert_manufacture()", end=" : ") print(e) print(model_dic) print("Product info : ", end='') merge_dic = {} merge_dic.update(product_info_dic) merge_dic.pop('model_id') merge_dic['model'] = model_dic['model'] product_info_list.append(merge_dic) print(product_info_list) for result in history_list: product_info_list.append(result) return jsonify(product_info_list) else: return render_template('error.html', title='405 method not allowed :(', str='Please... re try the login.', url='main_login'), 404
def getModelList(): model_list = [] try: _DB_object = MongodbConnection() model_collection = _DB_object.db_conn(_DB_object.db_client(), 'model') cursor = model_collection.find({}, {'_id': False}) except Exception as e: print("DB_error : Class Rows.manufacture()", end=" >> ") print(e) finally: _DB_object.db_close() for _dic in cursor: model_list.append(_dic['model']) return jsonify(model_list)
def manufacture_insert(): date = datetime.datetime.today().strftime('%Y-%m-%d') if current_user.is_authenticated: print(current_user) # Input name value _week = request.values.get("week") _model = request.values.getlist("model") _number = request.values.getlist("number") print("Insert Get Data : ", end='') print(_week, end=' ') print(_model, end=' ') print(_number, end=' ') print(type(_number), end=' ') print(len(_model)) _data_list = [] for i in range(0, len(_model)): _list = [_week, _model[i], int(_number[i]), date] _data_list.append(_list) print("Data List : ") for data in _data_list: print(data) try: db_object = MongodbConnection() for i in range(0, len(_data_list)): rows_collection = db_object.db_conn(db_object.db_client(), 'manufacture') _insert_id = query.insert_manufacture_info( rows_collection, _data_list[i]) except Exception as e: print("DB_error : insert_manufacture()", end=" : ") print(e) finally: db_object.db_close() return redirect(url_for('manufacture_main')) else: return render_template('error.html', title='405 method not allowed :(', str='Please... re try the login.', url='main_login'), 404
def partner_register(): _classification = request.values.get('classification') _partner_name = request.values.get('partner_name_field') _b = request.values.get('b_field') _address = request.values.get('address_field') _header = request.values.get('header_field') _phone = request.values.get('phone_field') _email = request.values.get('email_field') _var = request.values.get('var_field') print("GET Classification: ", end='') print(_classification, end=' ') print(" Partner_name_field : ", end='') print(_partner_name) print("b_field : ", end='') print(_b, end=' ') print(" Address_field : ", end='') print(_address) print("Header_field : ", end='') print(_header, end=' ') print("Phone_field : ", end='') print(_phone) print("Email_field PN : ", end='') print(_email, end=' ') print("Var_field : ", end='') print(_var) insert_data_list = [ _classification, _partner_name, _b, _address, _header, _phone, _email, _var ] try: db_object = MongodbConnection() rows_collection = db_object.db_conn(db_object.db_client(), 'project_num') _insert_id = query.insert_partner_list(rows_collection, insert_data_list) except Exception as e: print("DB_error : insert_manufacture()", end=" : ") print(e) finally: db_object.db_close() return redirect(url_for('sales_main'))
def project_number_register(): _number_of_pn = request.values.get('pn_field') _project_name = request.values.get('project_name_field') print("GET PN : ", end='') print(_number_of_pn, end=' ') print(" Name : ", end='') print(_project_name) insert_data_list = [_number_of_pn, _project_name] try: db_object = MongodbConnection() rows_collection = db_object.db_conn(db_object.db_client(), 'project_num') _insert_id = insert_project_num(rows_collection, insert_data_list) except Exception as e: print("DB_error : insert_manufacture()", end=" : ") print(e) finally: db_object.db_close() return redirect(url_for('sales_main'))
def create_table(): if current_user.is_authenticated: print(current_user) start_date = request.values.get('sdate') end_date = request.values.get('edate') _filter = request.values.get('filter') _sub_filter = request.values.getlist('sub_filter') condition = request.values.get('condition') print("POST:", end=" ") print(start_date, end=" ") print(end_date, end=" ") print(_filter, end=" ") print(_sub_filter, end=" ") print(condition) start_date = start_date.split('-') end_date = end_date.split('-') for i in range(0, 3): start_date[i] = int(start_date[i]) end_date[i] = int(end_date[i]) sWeek = week_num(start_date[0], start_date[1], start_date[2]) eWeek = week_num(end_date[0], end_date[1], end_date[2]) def find_model_count(db_object, model): query = {'model': model} collection = db_object.db_conn(db_object.db_client(), 'model') obj = collection.find_one(query) print(obj) collection = db_object.db_conn(db_object.db_client(), 'product_info') query2 = {'model_id': obj['_id']} return collection.find(query2).count() def find_model_count2(db_object, sWeek, eWeek, model): query = { "$and": [{ u"week": { u"$gte": sWeek } }, { u"week": { u"$lte": eWeek } }, { u"model_id": { u"$eq": model } }, { u"show": { u"$eq": '1' } }] } collection = db_object.db_conn(db_object.db_client(), 'product_info') return collection.find(query).count() def find_model_count3(db_object, sWeek, eWeek, model, filter, sub_filter): query = { "$and": [{ u"week": { u"$gte": sWeek } }, { u"week": { u"$lte": eWeek } }, { u"model_id": { u"$eq": model } }, { u"show": { u"$eq": '1' } }] } collection = db_object.db_conn(db_object.db_client(), 'product_info') cursor = collection.find(query) collection = db_object.db_conn(db_object.db_client(), 'history') count = 0 for obj in cursor: for _sub_filter in sub_filter: history_obj = collection.find_one({ 'product_id': obj['_id'], filter: _sub_filter, 'show': '1' }) if history_obj is not None: print(history_obj) count += 1 return count def find_week_search(db_object, sWeek, eWeek, _filter, _sub_filter): query = { "$and": [{ u"week": { u"$gte": sWeek } }, { u"week": { u"$lte": eWeek } }, { u"show": { u"$eq": '1' } }] } collection = db_object.db_conn(db_object.db_client(), 'product_info') cursor = list(collection.find(query)) history_obj_list = [] print( "\n---해당 기간동안의 Obj와 Id 그리고 조건이 일치하는 데이터가 있으면 history_obj_list에 추가 ----" ) filtering_list = [] flag = False if _filter != '전체': flag = True if _filter == '위치': _filter = 'location' elif _filter == '상태': _filter = 'state' collection = db_object.db_conn(db_object.db_client(), 'history') for sub_filter in _sub_filter: for obj in cursor: history_obj = collection.find_one({ 'product_id': obj['_id'], 'show': '1', _filter: sub_filter }) if history_obj is not None: _dic = {} _dic.update(obj) _dic.update(history_obj) history_obj_list.append(_dic) for obj in history_obj_list: print(obj) cursor = history_obj_list else: print("\n----------------") print("\n---id와 일치하는 model 찾아서 model_list에 저장---") collection = db_object.db_conn(db_object.db_client(), 'model') model_list = [] model_dic_list = [] for obj in cursor: model_obj = collection.find_one({'_id': obj['model_id']}) #model_dic_list.append({'model': model_obj['model']}) model_list.append(obj['model_id']) print("\n----model_list 중복 제거하고 해당 모델과 맞는 수량 검색----") model_list = set(model_list) dic_list = [] total_sum = 0 for _list in model_list: if flag is True: num = find_model_count3(db_object, sWeek, eWeek, _list, _filter, _sub_filter) else: num = find_model_count2(db_object, sWeek, eWeek, _list) dic = {'model_id': _list, 'num': num} dic_list.append(dic) total_sum += num print(_list, end=" : ") print(num) print("\n------- 결과 -----") collection = db_object.db_conn(db_object.db_client(), 'model') for dic in dic_list: obj = collection.find_one({'_id': dic['model_id']}) dic.update({'model': obj['model']}) del dic['model_id'] print(dic) db_object.db_close() dic_list.append({"model": "총합", "num": total_sum}) return dic_list # ----------------------------------------------------------------------------------- db_object = MongodbConnection() if condition == '1': collection = db_object.db_conn(db_object.db_client(), 'model') model_list = collection.distinct('model') dic_list = [] total_sum = 0 for model in model_list: num = find_model_count(db_object, model) dic = {'model': model, 'num': num} dic_list.append(dic) total_sum += num db_object.db_close() dic_list.append({"model": "총합", "num": total_sum}) for dic in dic_list: print(dic) # ----------------------------------------------------------------------------------- if condition == '2': dic_list = find_week_search(db_object, sWeek, eWeek, _filter, _sub_filter) return jsonify(dic_list) else: return render_template('error.html', title='405 method not allowed :(', str='Please... re try the login.', url='main_login'), 404
def sendDetailModificationModalValue(): _sn = request.values.get("modify_sn") _week = request.values.get("modify_week") _header = request.values.get("modify_header") _product_id = request.values.get("modify_product_id") print("Get modification data : ", end="") print(type(_sn), end=" ") print(len(_sn), end=" ") print(_sn, end=" ") print(_week, end=" ") print(_header, end=" ") print(_product_id) if current_user.is_authenticated: modify_list = [] if not _sn and _week and _header: print("Post value is Empty") if _sn: modify_list.append(_sn) else: modify_list.append(None) if _week: modify_list.append(_week) else: modify_list.append(None) if _header: modify_list.append(_header) else: modify_list.append(None) print("Modify_list : ") print(modify_list) try: db_object = MongodbConnection() rows_collection = db_object.db_conn( db_object.db_client(), 'product_info') # test db : Copy_of_product_info _DicTypeResult = query.update_product_info(rows_collection, _product_id, modify_list) except Exception as e: print("DB_error : insert_manufacture()", end=" : ") print(e) print("Result : ") print(_DicTypeResult) _date = request.values.getlist('modify_date') _location = request.values.getlist('modify_location') _state = request.values.getlist('modify_state') _reason = request.values.getlist('modify_reason') _text = request.values.getlist("modify_text") history_list = [] print("Get modification list data : ", end="") print(_date, end=" ") print(_location, end=" ") print(_state, end=" ") print(_reason, end=" ") print(_text) for i in range(0, len(_date)): history_list.append({ 'date': _date[i], 'location': _location[i], 'state': _state[i], 'reason': _reason[i], 'note': _text[i] }) print("history List : ") for result in history_list: print(result) # 지금은 Index 방법으로 update를 하지만 추 후에는 ajax과정에서 id들도 같이 넘여주어서 id를 통해 update를 해야한다. try: rows_collection = db_object.db_conn( db_object.db_client(), 'history') # test db : Copy_of_history _CurTypeResult = rows_collection.find( {'product_id': ObjectId(_product_id)}) except Exception as e: print("DB_error : rows_collection.find()", end=" : ") print(e) print("Result : ") historyId = [] for result in _CurTypeResult: historyId.append(result['_id']) print(result) print("History Id : ") print(historyId) try: rows_collection = db_object.db_conn( db_object.db_client(), 'history') # test db = Copy_of_history for i in range(0, len(historyId)): _DicTypeResult = query.update_modification_history( rows_collection, historyId[i], history_list[i]) print("Modify !!") print(_DicTypeResult) except Exception as e: print("DB_error : update_modification_history()", end=" : ") print(e) finally: db_object.db_close() return redirect(url_for('product_main')) else: return render_template('error.html', title='405 method not allowed :(', str='Please... re try the login.', url='main_login'), 404
def filtering(): _filter = request.values.get('filter') _sub_filter = request.values.get('sub_filter') _sDate = request.values.get('sDate') _eDate = request.values.get('eDate') print("Filtering1 Get value : ") print(_filter + ' ' + _sub_filter + ' ' + _sDate + ' ' + _eDate) _sDate = _sDate.split('-') _eDate = _eDate.split('-') for i in range(0, 3): _sDate[i] = int(_sDate[i]) _eDate[i] = int(_eDate[i]) s_week = week_num(_sDate[0], _sDate[1], _sDate[2]) e_week = week_num(_eDate[0], _eDate[1], _eDate[2]) query = { "$and": [{ u"week": { u"$gte": s_week } }, { u"week": { u"$lte": e_week } }, { u"show": { u"$eq": '1' } }] } try: _DB_object = MongodbConnection() rows_collection = _DB_object.db_conn(_DB_object.db_client(), 'product_info') rows_list = list( rows_collection.find(query)) # cursor type -> list type except Exception as e: print("DB_error : Class Rows.manufacture()", end=" >> ") print(e) finally: _DB_object.db_close() model_rows = [] model_coll = _DB_object.db_conn(_DB_object.db_client(), 'model') for row in rows_list: query = {"_id": {'$eq': ObjectId(row['model_id'])}} model_rows.extend(list( model_coll.find(query))) # cursor type -> list type history_rows = [] history_coll = _DB_object.db_conn(_DB_object.db_client(), 'history') for row in rows_list: query = { "$and": [{ "product_id": { '$eq': str(row['_id']) } }, { 'show': { '$eq': '1' } }] } history_rows.extend(list( history_coll.find(query))) # cursor type -> list type print("Date match rows :") for row in rows_list: print(row) print("Reference model rows :") for row in model_rows: print(row) print("Reference history rows :") for row in history_rows: print(row) merge_list = [] for i in range(0, len(rows_list)): new_dic = {} new_dic.update(rows_list[i]) new_dic.update(model_rows[i]) new_dic.update(history_rows[i]) merge_list.append(new_dic) print("Merge List") for lis in merge_list: print(lis) if _filter == '전체': m_value = None l_value = None s_value = None elif _filter == '모델': m_value = _sub_filter l_value = None s_value = None elif _filter == '위치': m_value = None l_value = _sub_filter s_value = None elif _filter == '상태': m_value = None l_value = None s_value = _sub_filter else: m_value = _sub_filter l_value = _sub_filter s_value = _sub_filter _filter_dic = {'model': m_value, 'location': l_value, 'state': s_value} print(_filter_dic) first_filtering_list = [] second_filtering_list = [] third_filtering_list = [] print("> Model Filtering") if _filter_dic['model'] is not None: for idx, merge_row in enumerate(merge_list): if merge_row.get('model') == _filter_dic['model']: print(idx, merge_row) first_filtering_list.append(merge_row) else: print("Delete : ", end='') print(idx, merge_row) else: first_filtering_list = merge_list print(">> Location Filtering") if _filter_dic['location'] is not None: for idx, merge_row in enumerate(first_filtering_list): if merge_row.get('location') == _filter_dic['location']: print(idx, merge_row) second_filtering_list.append(merge_row) else: print("Delete : ", end='') print(idx, merge_row) else: second_filtering_list = first_filtering_list print(">>> State Filtering") if _filter_dic['state'] is not None: for idx, merge_row in enumerate(second_filtering_list): if merge_row.get('state') == _filter_dic['state']: print(idx, merge_row) third_filtering_list.append(merge_row) else: print("Delete : ", end='') print(idx, merge_row) else: third_filtering_list = second_filtering_list print("After Filtering") if not third_filtering_list: print("After filtering . . . List is Empty") else: for lis in third_filtering_list: print(lis) row_object = Rows() return render_template('production_main.html', specific_list=third_filtering_list, object=row_object)
def insert_data(): print("POST - Insert Data :") date = datetime.datetime.today().strftime('%Y-%m-%d') # Input name value _week = request.values.getlist("insert_week") _model = request.values.getlist("insert_model") _sn = request.values.getlist("insert_sn") _header = request.values.getlist("insert_header") def find_model(collection, model): query = {'model': model} return collection.find_one(query) if current_user.is_authenticated: print(current_user) for i in range(0, len(_model)): try: db_object = MongodbConnection() rows_collection = db_object.db_conn(db_object.db_client(), 'model') _model_dic = find_model(rows_collection, _model[i]) print(_model_dic) except Exception as e: db_object.db_close() print("DB_error : insert_model()", end=" : ") print(e) # Auto value _quality = 'N' _show = '1' auto_values = [ _model_dic['_id'], _sn[i], _header[i], _week[i], _quality, _show ] try: rows_collection = db_object.db_conn(db_object.db_client(), 'product_info') _product_id = query.insert_product_info( rows_collection, auto_values) print(_product_id) except Exception as e: print("DB_error : insert_product_info()", end=" >> ") print(e) finally: db_object.db_close() # History value _date = date _location = '대전' _state = '재고' # 재고, 출고, 폐기 _reason = '신규생산' # 신규생산, 판매, 기증, 내수용, A/S, 불량, 반납, 이동 _note = ' ' history_values = [ _product_id, _date, _location, _state, _reason, _note ] try: rows_collection = db_object.db_conn(db_object.db_client(), 'history') query.insert_history(rows_collection, history_values) except Exception as e: db_object.db_close() print("DB_error : insert_history()", end=" : ") print(e) return redirect(url_for('product_main')) else: return render_template('error.html', title='405 method not allowed :(', str='Please... re try the login.', url='main_login'), 404
def state_change(): def getStateFromReason(reason): # state_map = { # '신규생산': '재고', # '반납': '재고', # '이동': '재고', # '판매': '출고', # '기증': '출고', # '내수용': '출고', # 'A/S': '출고', # '불량': '폐기' # } state_map = { '매입': '입고', '생산': '입고', '교체(입고)': '입고', '이월': '입고', '회수': '입고', '이동(입고)': '입고', '내수': '입고', '기타(입고)': '입고', '판매': '출고', '대여': '출고', '교체(출고)': '출고', '기증': '출고', '과제': '출고', '이동(출고)': '출고', '손상': '출고', '기타(출고)': '출고' } return state_map[reason] if current_user.is_authenticated: print(current_user) # if not len(request.values.getlist("check_box")): # print("state_change rows is empty") # return redirect('/') # else: try: date = datetime.datetime.today().strftime('%Y-%m-%d') _date = {'date': date} # _checked_id = request.values.getlist("check_box") # Checked the Object _id value _id = request.values.getlist("id") _location = request.values.getlist("location") _reason = request.values.getlist("reason") _note = request.values.getlist("text") row_list = [] print("GET State Change List : ", end="") print(_id, end=" ") print(_location, end=" ") print(_reason, end=" ") print(_note) for i in range(0, len(_id)): _state = getStateFromReason(_reason[i]) row_list.append({ 'id': _id[i], 'location': _location[i], 'state': _state, 'reason': _reason[i], 'note': _note[i] }) except Exception as e: print("POST_error : state_change()", end=" >> ") print(e) else: # print(_checked_id, end=" ") print("POST row_list : ") for row in row_list: print(row) try: db_object = MongodbConnection() rows_collection = db_object.db_conn(db_object.db_client(), 'history') # for i in range(0, len(_checked_id)): for j in range(0, len(row_list)): # if _checked_id[i] == row_list[j]['id']: print("Change !! - ", end=" ") # print(_checked_id[i], end=" <-- ") print(row_list[j]) # return find() -> Cursor Type # return insert() -> Object Type # return update() -> Dict Type p_id = row_list[j]['id'] query.update_history(rows_collection, p_id) data = [ row_list[j]['id'], date, row_list[j]['location'], row_list[j]['state'], row_list[j]['reason'], row_list[j]['note'] ] query.insert_history(rows_collection, data) except Exception as e: print("DB_error : state_change()", end=" >> ") print(e) finally: db_object.db_close() return redirect(url_for('product_main')) else: return render_template('error.html', title='405 method not allowed :(', str='Please... re try the login.', url='main_login'), 404
def __init__(self): print("Rows Class init") self._DB_object = MongodbConnection()
def search_query(sdate, edate, page): # rows_list = list(rows_collection.find({'$and': [{'week': {'$gte': sdate}},{'week': {'$lte': edate}}]})) # query = {} # query["$and"] = [ if page == 'p_page': collection_of_model = 'model' collection_of_history = 'history' collection_of_product_info = 'product_info' product_info_query = { "$and": [{ u"week": { u"$gte": sdate } }, { u"week": { u"$lte": edate } }, { u"show": { u"$eq": '1' } }] } else: print("page parameter is wrong") try: db_object = MongodbConnection() rows_collection = db_object.db_conn(db_object.db_client(), collection_of_product_info) rows_list = list(rows_collection.find( product_info_query)) # cursor type -> list type list_of_model_id = [] list_of_history_id = [] for row in rows_list: list_of_model_id.append(row['model_id']) list_of_history_id.append(str(row['_id'])) # print("list_of_model_id : ", end="") # print(list_of_model_id) # print("list_of_history_id : ", end="") # print(list_of_history_id) rows_collection = db_object.db_conn(db_object.db_client(), collection_of_model) list_of_model = [] for model_id in list_of_model_id: model_query = {u"_id": {u"$eq": ObjectId(model_id)}} list_of_model.extend(list( rows_collection.find(model_query))) # cursor type -> list type rows_collection = db_object.db_conn(db_object.db_client(), collection_of_history) list_of_history = [] for history_id in list_of_history_id: history_query = { "$and": [{ u"product_id": { u"$eq": history_id } }, { u"show": { u"$eq": '1' } }] } list_of_history.extend(list(rows_collection.find( history_query))) # cursor type -> list type except Exception as e: print("DB_error : search_query()", end=" >> ") print(e) finally: db_object.db_close() new_list = [] for i in range(0, len(rows_list)): new_dic = { 'model': list_of_model[i]['model'], 'sn': rows_list[i]['sn'], 'week': rows_list[i]['week'], 'state': list_of_history[i]['state'], 'location': list_of_history[i]['location'], '_id': rows_list[i]['_id'] } new_list.append(new_dic) print("Result List : ") for row in new_list: print(row) return new_list
def filtering2(): if current_user.is_authenticated: print(current_user) _filter = request.args.get('filter') _sub_filter = request.args.get('sub_filter') _sDate = request.args.get('sDate') _eDate = request.args.get('eDate') _flag = request.args.get('second_filter_flag') if _flag == 'true': _second_filter = request.args.get('second_filter') _second_sub_filter = request.args.get('second_sub_filter') print("Get Sub_filter Value : ", end="") print(_second_filter, end=" ") print(_second_sub_filter) print("Filtering2 Get value : ", end="") print(_filter + ' ' + _sub_filter + ' ' + _sDate + ' ' + _eDate) _sDate = _sDate.split('-') _eDate = _eDate.split('-') for i in range(0, 3): _sDate[i] = int(_sDate[i]) _eDate[i] = int(_eDate[i]) s_week = week_num(_sDate[0], _sDate[1], _sDate[2]) e_week = week_num(_eDate[0], _eDate[1], _eDate[2]) query = { "$and": [{ u"week": { u"$gte": s_week } }, { u"week": { u"$lte": e_week } }, { u"show": { u"$eq": '1' } }] } try: _DB_object = MongodbConnection() rows_collection = _DB_object.db_conn(_DB_object.db_client(), 'product_info') rows_cursor = rows_collection.find(query) _list = [] for row in rows_cursor: _list.append(row) print("--------------------------") model_coll = _DB_object.db_conn(_DB_object.db_client(), 'model') for _item in _list: query = {"_id": {'$eq': _item['model_id']}} _item.update(model_coll.find_one(query, {'_id': False})) history_coll = _DB_object.db_conn(_DB_object.db_client(), 'history') print("--------------------------") for _item in _list: query = { "$and": [{ "product_id": { '$eq': _item['_id'] } }, { 'show': { '$eq': '1' } }] } a = history_coll.find_one(query, {'_id': False}) _item.update(a) merge_list = _list.copy() except Exception as e: print("DB_error : filtering()", end=" >> ") print(e) finally: _DB_object.db_close() print("Merge List") for lis in merge_list: del lis['_id'] del lis['model_id'] lis['product_id'] = str(lis['product_id']) print(lis) def dynamic_filter(dic): result = [] print("Filtering Start") for key, val in dic.items(): print(key, end=" ") print(val) if key == '전체': continue elif key == '모델': result.append({'model': val}) elif key == '위치': result.append({'location': val}) elif key == '상태': result.append({'state': val}) # elif key == '모델': # result['model'] = val # elif key == '위치': # result['location'] = val # elif key == '상태': # result['state'] = val return result if _flag == 'false': filter_dic = {_filter: _sub_filter} else: filter_dic = { _filter: _sub_filter, _second_filter: _second_sub_filter } print(filter_dic) result_list = merge_list.copy() after_filtering_list = [] for item in dynamic_filter(filter_dic): print("\nFiltering : ", end="") print(item) if 'model' in item: print("> Model Filtering") for idx, merge_row in enumerate(result_list): if merge_row.get('model') == item['model']: print(idx, merge_row) after_filtering_list.append(merge_row) else: print("Delete : ", end='') print(idx, merge_row) if 'location' in item: print(">> Location Filtering") for idx, merge_row in enumerate(result_list): if merge_row.get('location') == item['location']: print(idx, merge_row) after_filtering_list.append(merge_row) else: print("Delete : ", end='') print(idx, merge_row) if 'state' in item: print(">>> State Filtering") for idx, merge_row in enumerate(result_list): if merge_row.get('state') == item['state']: print(idx, merge_row) after_filtering_list.append(merge_row) else: print("Delete : ", end='') print(idx, merge_row) result_list.clear() result_list = after_filtering_list.copy() after_filtering_list.clear() print("\nAfter Filtering") if not result_list: print("After filtering . . . List is Empty") else: for lis in result_list: print(lis) return jsonify(result_list) else: return render_template('error.html', title='405 method not allowed :(', str='Please... re try the login.', url='main_login'), 404
def getStateChangeTable(): _product_info_id = eval(request.args.get('product_info_id')) print("Checkbox Agix : ", end='') print(_product_info_id) if current_user.is_authenticated: print(current_user) if not len(_product_info_id): print("Not have a Checked box") return jsonify(_product_info_id) result_list = [] for _id in _product_info_id: try: db_object = MongodbConnection() rows_collection = db_object.db_conn(db_object.db_client(), 'product_info') product_dic = query.find_production_info_item( rows_collection, _id) product_dic['model_id'] = str(product_dic['model_id']) except Exception as e: print("DB_error : getStateChangeTable() - product_info", end=" : ") print(e) try: rows_collection = db_object.db_conn(db_object.db_client(), 'model') model_dic = rows_collection.find_one( {'_id': ObjectId(product_dic['model_id'])}, {'_id': False}) except Exception as e: print("DB_error : getStateChangeTable() - product_info", end=" : ") print(e) try: rows_collection = db_object.db_conn(db_object.db_client(), 'history') history_dic = query.find_history_item(rows_collection, _id) history_dic['product_id'] = str(history_dic['product_id']) except Exception as e: print("DB_error : getStateChangeTable() - history", end=" : ") print(e) finally: db_object.db_close() print("Product list : ") print(product_dic) print("Model list : ") print(model_dic) print("History list : ") print(history_dic) result_dic = {} result_dic.update(product_dic) result_dic.update(model_dic) result_dic.update(history_dic) result_list.append(result_dic) print("Result list : ") print(result_list) return jsonify(result_list) else: return render_template('error.html', title='405 method not allowed :(', str='Please... re try the login.', url='main_login'), 404
def getProductData(): # 모델명을 받아서 model 콜렉션에서 해당 일치하는 모델의 수를 넘겨준다. # 그 수량이 완료 필드에 들어가야한다. Aging은 넘겨줘서 계산하도록 한다. # 완료 수량 = 재고 DB에 있는 모델의 수 _model_list = eval(request.args.get('model_list')) _week_list = eval(request.args.get('week_list')) _table_list = eval(request.args.get('table_list')) # print(_model_list) db_object = MongodbConnection() rows_collection = db_object.db_conn(db_object.db_client(), 'model') obj_list = [] count_dic = {} for model in _model_list: obj = rows_collection.find_one({'model': model}) obj_list.append(obj) pprint(obj_list) rows_collection = db_object.db_conn(db_object.db_client(), 'product_info') for idx, obj in enumerate(obj_list): count_dic[obj['model']] = query.find_number_of_model( rows_collection, obj['_id'], _week_list[idx]) print("Number of Model Dic : ") print(count_dic) print("Result rows : ") for row in _table_list: result = list(row.values() & count_dic.keys()) row[result[0]] = count_dic[result[0]] print(row) rows_collection = db_object.db_conn(db_object.db_client(), 'manufacture') print("\n---------\n") cur = list( rows_collection.find({}, { '_id': False, 'number': False, 'date': False })) _li = "" _list = [] for c in cur: _li += str(c) _list.append(_li) _li = "" _list = set(_list) for i in _list: print(i) print("--------") _list = list(_list) _list2 = [] for i in _list: i = ast.literal_eval(i) _list2.append(i) print("--------") for i in _list2: print(i) def fun(collection, week, model): _pipeline = [{ "$match": { "week": { "$eq": week }, "model": { "$eq": model } } }, { "$group": { "_id": "$model", "number": { "$sum": "$number" } } }] return collection.aggregate(_pipeline) for row in _list2: num = list(fun(rows_collection, row['week'], row['model'])) row['number'] = num[0]['number'] print(row) rows_collection = db_object.db_conn(db_object.db_client(), 'model') for row in _list2: model_id = rows_collection.find_one({'model': row['model']}) row.update({'model_id': model_id['_id']}) print(row) try: rows_collection = db_object.db_conn(db_object.db_client(), 'product_info') for idx, obj in enumerate(_list2): num = query.find_number_of_model(rows_collection, obj['model_id'], obj['week']) obj.update({obj['model']: num}) except Exception as e: print("DB_error : getProductData()", end=" : ") print(e) finally: db_object.db_close() print("--------") for i in _list2: del i['model_id'] print(i) return jsonify(_list2)
def filteringForSN(): _sn = request.args.get('sn') print(_sn) if current_user.is_authenticated: print(current_user) def find_product_to_sn(collection, sn): query = {'sn': {'$regex': sn, '$options': 'i'}} return collection.find(query) try: _DB_object = MongodbConnection() rows_collection = _DB_object.db_conn(_DB_object.db_client(), 'product_info') rows_list = list(find_product_to_sn(rows_collection, _sn)) except Exception as e: print("DB_error : filteringForSN()", end=" : ") print(e) finally: _DB_object.db_close() model_rows = [] model_coll = _DB_object.db_conn(_DB_object.db_client(), 'model') for row in rows_list: query = {"_id": {'$eq': ObjectId(row['model_id'])}} model_rows.extend(list( model_coll.find(query))) # cursor type -> list type history_rows = [] history_coll = _DB_object.db_conn(_DB_object.db_client(), 'history') for row in rows_list: query = { "$and": [{ "product_id": { '$eq': ObjectId(str(row['_id'])) } }, { 'show': { '$eq': '1' } }] } history_rows.extend(list( history_coll.find(query))) # cursor type -> list type merge_list = [] for i in range(0, len(rows_list)): new_dic = {} new_dic.update(rows_list[i]) new_dic.update(model_rows[i]) new_dic.update(history_rows[i]) merge_list.append(new_dic) for row_dic in merge_list: row_dic['_id'] = str(row_dic['_id']) row_dic['model_id'] = str(row_dic['model_id']) row_dic['product_id'] = str(row_dic['product_id']) print(row_dic) return jsonify(merge_list) else: return render_template('error.html', title='405 method not allowed :(', str='Please... re try the login.', url='main_login'), 404
def getManufactureDB(): _week = request.args.get("week") _model = request.args.get("model") _index = int(request.args.get("index")) print("Get ManufactureDB Ajax : ", end="") print(_week, end=" ") print(_model, end=" ") print(_index) def find_manufacture_count(collection, week, model): _query = {u"week": {u"$eq": week}, u"model": {u"$eq": model}} _pipeline = [{ "$match": { "week": { "$eq": week }, "model": { "$eq": model } } }, { "$group": { "_id": "$model", "number": { "$sum": "$number" } } }] #return collection.find(_query) return collection.aggregate(_pipeline) try: db_object = MongodbConnection() rows_collection = db_object.db_conn(db_object.db_client(), 'manufacture') numberOfManufacture = list( find_manufacture_count(rows_collection, _week, _model)) except Exception as e: print("DB_error : getManufactureDB() - manufacture", end=" : ") print(e) print(numberOfManufacture) if not numberOfManufacture: numberOfManufacture = 0 else: numberOfManufacture = numberOfManufacture[0]['number'] print("Number of result : ", end="") print(numberOfManufacture) try: rows_collection = db_object.db_conn(db_object.db_client(), 'model') model_dic = rows_collection.find_one({'model': _model}) except Exception as e: print("DB_error : getManufactureDB() - product", end=" : ") print(e) print(model_dic['_id']) def find_product_count(collection, week, model_id): _query = {u"week": week, u"model_id": model_id} return collection.find(_query).count() try: rows_collection = db_object.db_conn(db_object.db_client(), 'product_info') numberOfProduct = find_product_count(rows_collection, _week, model_dic['_id']) except Exception as e: print("DB_error : getManufactureDB() - product", end=" : ") print(e) finally: db_object.db_close() print("numberOfProduct : ", end="") print(numberOfProduct) result = {"number": numberOfManufacture - numberOfProduct, "index": _index} print("Result : ", end="") print(result) return jsonify(result)
def getBarGraph2(): def distinct_week_value_list(coll): return coll.distinct('week') def distinct_model_value_list(coll): return coll.distinct('model') def find_number_of_model_from_week_and_model(coll, _week, _model): query = { "$and": [{ u"week": { u"$eq": _week } }, { u'model': { '$eq': _model } }] } cs = coll.find(query) _list = [] for cs_item in cs: _list.extend(copy.deepcopy(cs_item['number'])) # print(_list) return sum(map(int, _list)) try: db_object = MongodbConnection() rows_collection = db_object.db_conn(db_object.db_client(), 'manufacture') week_list = distinct_week_value_list(rows_collection) except Exception as e: print("DB_error : distinct_manufacture", end=" : ") print(e) print(week_list) try: model_list = distinct_model_value_list(rows_collection) except Exception as e: print("DB_error : distinct_manufacture", end=" : ") print(e) print(model_list) number_of_model_list = [] number_of_model_dic = {} temp_dic = {} try: for _week in week_list: for _model in model_list: number_of_model_dic[ _model] = find_number_of_model_from_week_and_model( rows_collection, _week, _model) temp_dic = number_of_model_dic.copy() number_of_model_list.append(temp_dic) except Exception as e: print("DB_error : find_number_of_model_from_week_and_model()", end=" : ") print(e) finally: db_object.db_close() # for val in number_of_model_list: # print(val) result = [week_list, model_list, number_of_model_list] for val in result: for item in val: print(item) return jsonify(result)
class Rows: def __init__(self): print("Rows Class init") self._DB_object = MongodbConnection() # def production_main_list(self): def main_table_rows(self): print('Load - Class main_table_rows()') result_rows = [] # show key is the most recently value. query = {"show": {'$eq': '1'}} try: rows_collection = self._DB_object.db_conn( self._DB_object.db_client(), 'history') _history_list = list( rows_collection.find(query)) # cursor type -> list type except Exception as e: print("DB_error : Class Rows.model()", end=" >> ") print(e) _product_id_list = [] _location_list = [] _state_list = [] _date_list = [] _reason_list = [] for row in _history_list: _product_id_list.append(row['product_id']) _location_list.append(row['location']) _state_list.append(row['state']) _date_list.append(row['date']) _reason_list.append(row['reason']) _week_list = [] _sn_list = [] _model_list = [] _model_id_list = [] try: product_info_collection = self._DB_object.db_conn( self._DB_object.db_client(), 'product_info') except Exception as e: print("DB_error : Class Rows.model()", end=" >> ") print(e) for product_id in _product_id_list: query = {"_id": {'$eq': ObjectId(product_id)}} try: product_info_obj = product_info_collection.find_one( query) # obj type except Exception as e: print("DB_error : Class Rows.model()", end=" >> ") print(e) if product_info_obj is not None: # print("info_dic : ", end="") # print(product_info_dic) _week_list.append(product_info_obj['week']) _sn_list.append(product_info_obj['sn']) _model_id_list.append(product_info_obj['model_id']) # _model_list.append(product_info_dic['model']) model_collection = self._DB_object.db_conn(self._DB_object.db_client(), 'model') for test_item in _model_id_list: _object = model_collection.find_one({'_id': ObjectId(test_item)}) _model_list.append(_object['model']) for i in range(0, len(_product_id_list)): res = { "product_id": _product_id_list[i], "model": _model_list[i], "sn": _sn_list[i], "week": _week_list[i], "location": _location_list[i], "state": _state_list[i], "reason": _reason_list[i], 'model_id': _model_id_list[i] } result_rows.append(res) self._DB_object.db_close() print("Main Table : ", end="") print(result_rows) if not result_rows: print('empty') elif result_rows: print('exist') return result_rows def production_main_model(self): print('Load - Class production_main_model()') try: # db_object = Mongodb_connection() rows_collection = self._DB_object.db_conn( self._DB_object.db_client(), 'model') rows_list = list( rows_collection.find()) # cursor type -> list type except Exception as e: print("DB_error : Class Rows.model()", end=" >> ") print(e) finally: self._DB_object.db_close() # print("all list")\ return rows_list def production_main_history(self): print('Load - Class production_main_history()') try: # db_object = Mongodb_connection() rows_collection = self._DB_object.db_conn( self._DB_object.db_client(), 'history') rows_list = list( rows_collection.find()) # cursor type -> list type except Exception as e: print("DB_error : Class Rows.history()", end=" >> ") print(e) finally: self._DB_object.db_close() # print("all list")\ return rows_list def production_main_info_list(self): print('Load - Class production_main_info_list()') try: # db_object = Mongodb_connection() rows_collection = self._DB_object.db_conn( self._DB_object.db_client(), 'product_info') rows_list = list( rows_collection.find()) # cursor type -> list type except Exception as e: print("DB_error : Class Rows.info()", end=" >> ") print(e) finally: self._DB_object.db_close() # print("all info list")\ return rows_list def production_main_specific_date_list(self): print('Load - Class production_main_specific_date_list()') page = 'p_page' date = datetime.datetime.today().strftime('%Y-%m-%d') now = date.split('-') for i in range(0, 3): now[i] = int(now[i]) now = week_num(now[0], now[1], now[2]) # year, month, day try: rows_list = search_query(now, now, page) except Exception as e: print("DB_error : production_main()", end=" >> ") print(e) return render_template('404.html'), 404 # print("date list") return rows_list def model_list(self): print('Load - Class model_list()') try: # db_object = Mongodb_connection() rows_collection = self._DB_object.db_conn( self._DB_object.db_client(), 'model') rows_list = list( rows_collection.distinct('model')) # cursor type -> list type except Exception as e: print("DB_error : Class Rows.info()", end=" >> ") print(e) finally: self._DB_object.db_close() # print("all info list") for _list in rows_list: print(_list) return rows_list def reason_list(self): print('Load - Class model_list()') try: # db_object = Mongodb_connection() rows_collection = self._DB_object.db_conn( self._DB_object.db_client(), 'history') rows_list = list( rows_collection.distinct('reason')) # cursor type -> list type except Exception as e: print("DB_error : Class Rows.info()", end=" >> ") print(e) finally: self._DB_object.db_close() # print("all info list")\ for _list in rows_list: print(_list) return rows_list def week(self): print('Load - Class week()') date = datetime.datetime.today().strftime('%Y-%m-%d') now = date.split('-') for i in range(0, 3): now[i] = int(now[i]) week = week_num(now[0], now[1], now[2]) return week def manufacture_list(self): print('Load - Class manufacture_list()') try: rows_collection = self._DB_object.db_conn( self._DB_object.db_client(), 'manufacture') rows_list = list( rows_collection.find()) # cursor type -> list type except Exception as e: print("DB_error : Class Rows.manufacture()", end=" >> ") print(e) finally: self._DB_object.db_close() # print("all info list") # rows_list = [{"model": "씨발", "new_product": "444"}] return rows_list def sales_list(self): print('Load - Class sales_list()') try: rows_collection = self._DB_object.db_conn( self._DB_object.db_client(), 'project_num') rows_list = list( rows_collection.find()) # cursor type -> list type except Exception as e: print("DB_error : Class Rows.manufacture()", end=" >> ") print(e) finally: self._DB_object.db_close() if not rows_list: print('Database is Empty') rows_list = None print("Sales Row List : ", end='') print(rows_list) return rows_list def date(self): print('Load - Class date()') return datetime.datetime.today().strftime('%Y-%m-%d')