def createZYPlanZYtask(): '''生产确认''' if request.method == 'POST': data = request.values # 返回请求中的参数和form try: jsonstr = json.dumps(data.to_dict()) if len(jsonstr) > 10: PlanStatus = data.get("PlanStatus") if PlanStatus == "待备料": IDs = json.loads(data.get("IDs")) for ID in IDs: returnmsg = makeZYPlanZYTask(ID) if (returnmsg == False): return json.dumps({ "code": "500", "message": "生产确认失败!" }) oclassplan = db_session.query(PlanManager).filter_by( ID=ID).first() oclassplan.PlanStatus = Global.PlanStatus.PreMaterial.value db_session.commit() insertAuditTrace( "生产确认计划", "批次号是:" + oclassplan.BatchID + "的" + oclassplan.BrandName + "在" + datetime.datetime.now().strftime( '%Y-%m-%d %H:%M:%S') + "生产确认计划操作", "PlanManager", current_user.Name, "") return json.dumps({"code": "200", "message": "生产确认成功!!"}) else: return json.dumps({"code": "200", "message": "批次计划状态不正确!"}) except Exception as e: print(e) logger.error(e) insertSyslog("error", "生产确认报错Error:" + str(e), current_user.Name) return 'NO'
def checkPlanManagerSingle(): ''' 单条审核计划 :return: ''' if request.method == 'POST': data = request.values # 返回请求中的参数和form try: PlanStatus = data.get("PlanStatus") Description = data.get("Describtion") ID = data.get("ID") oclassplan = db_session.query(PlanManager).filter_by(ID=ID).first() oclassplan.PlanStatus = PlanStatus oclassplan.Description = Description db_session.commit() insertAuditTrace( "审核计划", "批次号是:" + oclassplan.BatchID + "的" + oclassplan.BrandName + "在" + datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') + "进行计划审核操作", "PlanManager", current_user.Name, "") return json.dumps({"code": "200", "message": "OK"}) except Exception as e: db_session.rollback() print(e) logger.error(e) insertSyslog("error", "审核计划报错Error:" + str(e), current_user.Name) return json.dumps([{ "status": "Error:" + str(e) }], cls=AlchemyEncoder, ensure_ascii=False)
def PlanManagerRealse(): '''计划下发''' if request.method == 'POST': data = request.values # 返回请求中的参数和form try: jsonstr = json.dumps(data.to_dict()) if len(jsonstr) > 10: PlanStatus = data.get("PlanStatus") if PlanStatus == "待执行": IDs = json.loads(data.get("IDs")) for ID in IDs: oclass = db_session.query(PlanManager).filter( PlanManager.ID == ID).first() oclass.PlanStatus = PlanStatus db_session.commit() insertAuditTrace( "计划下发", "批次号是:" + oclass.BatchID + "的" + oclass.BrandName + "在" + datetime.datetime.now().strftime( '%Y-%m-%d %H:%M:%S') + "计划下发操作", "PlanManager", current_user.Name, "") return json.dumps({"code": "200", "message": "生产确认成功!!"}) elif PlanStatus == "撤回": ID = data.get("ID") oclassplan = db_session.query(PlanManager).filter_by( ID=ID).first() oclassplan.PlanStatus = Global.PlanStatus.Recall.value db_session.commit() insertAuditTrace( "撤回计划", "批次号是:" + oclassplan.BatchID + "的" + oclassplan.BrandName + "在" + datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') + "进行撤回计划操作", "PlanManager", current_user.Name, "") return json.dumps({"code": "200", "message": "成功!!"}) else: return json.dumps({"code": "200", "message": "批次计划状态不正确!"}) except Exception as e: print(e) logger.error(e) insertSyslog("error", "生产确认报错Error:" + str(e), current_user.Name) return 'NO'
def taskSaveEqpCheckReview(): ''' 任务审核复核(选择设备) :return: ''' if request.method == 'POST': data = request.values try: ZYPlanStatus = data.get("ZYPlanStatus") ocalss = db_session.query(ZYPlan).filter( ZYPlan.ID == data.get("ID")).first() # datalist = json.loads(data.get("datalist")) # iTaskSeq = 0 # for i in datalist: # ocalss = db_session.query(ZYTask).filter(ZYTask.ID == i.get("ID")).first() # ocalss.EQPCode = i.get("EQPCode") # ocalss.EQPName = i.get("EQPName") # db_session.commit() ocalss.ZYPlanStatus = ZYPlanStatus db_session.commit() insertAuditTrace( "任务审核复核(选择设备)", "批次号是:" + ocalss.BatchID + "的" + ocalss.BrandName + "在" + ocalss.PUName + "段的" + datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') + "进行计划审核操作", "PlanManager", current_user.Name, "") return json.dumps({ "code": "200", "message": "任务选择设备成功!", "data": "OK" }) except Exception as e: db_session.rollback() print(e) logger.error(e) insertSyslog("error", "任务审核复核报错Error:" + str(e), current_user.Name) return json.dumps("任务审核复核报错", cls=AlchemyEncoder, ensure_ascii=False)
def taskSaveEqpCheck(): ''' 设备审核(选择设备) :return: ''' if request.method == 'POST': data = request.values try: ocalss = db_session.query(ZYPlan).filter( ZYPlan.ID == data.get("ID")).first() zytasks = db_session.query(ZYTask).filter( ZYTask.BatchID == ocalss.BatchID, ZYTask.BrandCode == ocalss.BrandCode, ZYTask.PUCode == ocalss.PUCode).all() for zy in zytasks: db_session.delete(zy) db_session.commit() iTaskSeq = 0 if "提取" in ocalss.PUName: bms = db_session.query(BatchMaterialInfo).filter( BatchMaterialInfo.BatchID == ocalss.BatchID, BatchMaterialInfo.BrandCode == ocalss.BrandCode).all() for bm in bms: iTaskSeq = iTaskSeq + 1 bReturn, strTaskNo = getTaskNo() if bReturn == False: return False zytask = ZYTask() zytask.PlanDate = datetime.datetime.now().strftime( "%Y-%m-%d") zytask.TaskID = strTaskNo zytask.BatchID = ocalss.BatchID zytask.PlanSeq = iTaskSeq zytask.PUCode = ocalss.PUCode zytask.PUName = ocalss.PUName zytask.PlanType = Global.PLANTYPE.SCHEDULE.value zytask.BrandCode = ocalss.BrandCode zytask.BrandName = ocalss.BrandName zytask.PlanQuantity = ocalss.PlanQuantity zytask.Unit = ocalss.Unit zytask.EnterTime = "" zytask.EQPCode = bm.EQPCode zytask.EQPName = bm.EQPName zytask.PlanStartTime = "" zytask.PlanEndTime = "" zytask.TaskStatus = Global.TASKSTATUS.NEW.value zytask.LockStatus = Global.TASKLOCKSTATUS.UNLOCK.value db_session.add(zytask) db_session.commit() ocalss.ZYPlanStatus = Global.ZYPlanStatus.Produncting.value db_session.commit() else: if data.get("EqpList") != None and data.get("EqpList") != "": EqpList = json.loads(data.get("EqpList")) for j in EqpList: iTaskSeq = iTaskSeq + 1 bReturn, strTaskNo = getTaskNo() if bReturn == False: return False zytask = ZYTask() zytask.PlanDate = datetime.datetime.now().strftime( "%Y-%m-%d") zytask.TaskID = strTaskNo zytask.BatchID = ocalss.BatchID zytask.PlanSeq = iTaskSeq zytask.PUCode = ocalss.PUCode zytask.PUName = ocalss.PUName zytask.PlanType = Global.PLANTYPE.SCHEDULE.value zytask.BrandCode = ocalss.BrandCode zytask.BrandName = ocalss.BrandName zytask.PlanQuantity = ocalss.PlanQuantity zytask.Unit = ocalss.Unit zytask.EnterTime = "" zytask.EQPCode = j.get("EQPCode") zytask.EQPName = j.get("EQPName") zytask.PlanStartTime = "" zytask.PlanEndTime = "" zytask.TaskStatus = Global.TASKSTATUS.NEW.value zytask.LockStatus = Global.TASKLOCKSTATUS.UNLOCK.value db_session.add(zytask) db_session.commit() insertAuditTrace( "设备审核(选择设备)", "品名:" + ocalss.BrandName + " 批次:" + ocalss.BatchID + "设备审核(选择设备)", "PlanManager", current_user.Name, "") return json.dumps({ "code": "200", "message": "任务选择设备成功!", "data": "OK" }) except Exception as e: db_session.rollback() print(e) logger.error(e) insertSyslog("error", "设备审核(选择设备)报错Error:" + str(e), current_user.Name) return json.dumps("设备审核(选择设备)报错", cls=AlchemyEncoder, ensure_ascii=False)
def addEquipmentBatchRunTime(): ''' 生产配置添加设备 :return: ''' if request.method == 'POST': data = request.values try: ID = data.get('ID') processList = json.loads(data.get('processList')) oclass = db_session.query(PlanManager).filter( PlanManager.ID == ID).first() #清空之前保存的数据 delete_list = db_session.query(EquipmentBatchRunTime).filter( EquipmentBatchRunTime.BrandCode == oclass.BrandCode, EquipmentBatchRunTime.BatchID == oclass.BatchID).all() for i in delete_list: db_session.delete(i) db_session.commit() dir = {} if oclass: for pl in processList: PUName = pl.get("PUName") PUCode = pl.get("PUCode") eqList = pl.get('eqList') for el in eqList: isSelected = el.get("isSelected") if isSelected == True: #选中过的设备 ert = EquipmentBatchRunTime() ert.BatchID = oclass.BatchID ert.BrandCode = oclass.BrandCode ert.BrandName = oclass.BrandName ert.EQPCode = el.get("EQPCode") ert.EQPName = el.get("EQPName") ert.PUCode = PUCode ert.PUName = PUName ert.StartBC = el.get("StartBC") ert.EndBC = el.get("EndBC") sft = db_session.query(Shifts).filter( Shifts.ShiftsName == ert.StartBC).first() ert.StartTime = str( el.get("StartTime")) + " " + sft.BeginTime eft = db_session.query(Shifts).filter( Shifts.ShiftsName == ert.EndBC).first() if eft.ShiftsName == "中" or eft.ShiftsName == "晚": endt = (datetime.datetime.strptime( el.get("EndTime"), "%Y-%m-%d") + datetime.timedelta(hours=24) ).strftime("%Y-%m-%d") else: endt = el.get("EndTime") ert.EndTime = str(endt) + " " + eft.EndTime db_session.add(ert) oclass.PlanStatus = Global.PlanStatus.WaitRealse.value db_session.commit() insertAuditTrace( "生产配置添加设备", "批次号是:" + oclass.BatchID + "的" + oclass.BrandName + "在" + datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') + "进行生产配置添加设备操作", "PlanManager", current_user.Name, "") return json.dumps({ "code": "200", "message": "保存成功!", "data": "OK" }) except Exception as e: db_session.rollback() print(e) logger.error(e) insertSyslog("error", "生产配置添加设备报错Error:" + str(e), current_user.Name) return json.dumps("生产配置添加设备报错", cls=AlchemyEncoder, ensure_ascii=False)
def planschedul(): ''' 计划排产 :return: ''' if request.method == 'POST': data = request.values try: data_list = json.loads(data.get('selectPlanList')) for i in data_list: dir = {} proclass = db_session.query(ProductRule).filter( ProductRule.BrandCode == i.get("BrandCode")).first() for BatchNo in range(0, int(i.get("BatchNum"))): pm = PlanManager() pm.PlanNum = i.get("PlanNum") pm.SchedulePlanCode = str(datetime.datetime.now().strftime( "%Y-%m-%d %H:%M:%S"))[0:10] # nowtime = datetime.datetime.now().strftime("%Y-%m %M:%S").replace(":","").replace("-","").replace(" ","") pm.BatchID = "" pm.Seq = BatchNo pm.PlanQuantity = proclass.BatchWeight pm.Unit = proclass.Unit pm.BrandCode = i.get("BrandCode") pm.BrandName = i.get("BrandName") # #计算计划开始时间结束时间 # pu = db_session.query(ProductUnit).filter(ProductUnit.BrandCode == oclass.BrandCode, ProductUnit.PUName.like("%提%")).first() # proc = db_session.query(ProcessUnit).filter(ProcessUnit.PUCode == pu.PUCode).first() # beg = int(proclass.BatchTimeLength)*BatchNo # end = beg + int(proclass.BatchTimeLength) # PlanBeginTime = (datetime.datetime.strptime(StartTime, "%Y-%m-%d %H:%M:%S") + datetime.timedelta(hours=beg)).strftime("%Y-%m-%d %H:%M:%S") # PlanEndTime = (datetime.datetime.strptime(StartTime, # "%Y-%m-%d %H:%M:%S") + datetime.timedelta( # hours=end)).strftime("%Y-%m-%d %H:%M:%S") # pm.PlanBeginTime = PlanBeginTime # pm.PlanEndTime = PlanEndTime pm.BrandType = proclass.BrandType pm.PlanStatus = Global.PlanStatus.Confirm.value db_session.add(pm) db_session.commit() PlanNums = i.get("PlanNum").split(",") for pn in PlanNums: oc = db_session.query(product_plan).filter( product_plan.PlanNum == pn).first() if oc: oc.PlanStatus = "已分批" db_session.commit() insertAuditTrace( "订单排产", "订单号是:" + oc.PlanNum + "的" + oc.BrandName + "在" + datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') + "进行订单排产操作", "PlanManager", current_user.Name, "") return json.dumps({ "code": "200", "message": "排产成功!", "data": "OK" }) except Exception as e: db_session.rollback() print(e) logger.error(e) insertSyslog("error", "计划排产报错Error:" + str(e), current_user.Name) return json.dumps("计划排产报错", cls=AlchemyEncoder, ensure_ascii=False)