Exemple #1
0
def addUpdateEletronicBatchDataStore(BrandCode, PUCode, BatchID, ke, val):
    try:
        oc = db_session.query(EletronicBatchDataStore).filter(
            EletronicBatchDataStore.BrandID == BrandCode,
            EletronicBatchDataStore.PUCode == PUCode,
            EletronicBatchDataStore.BatchID == BatchID,
            EletronicBatchDataStore.Content == ke).first()
        if oc == None:
            db_session.add(
                EletronicBatchDataStore(BrandCode=BrandCode,
                                        BatchID=BatchID,
                                        PUCode=PUCode,
                                        Content=ke,
                                        OperationpValue=val,
                                        Operator=current_user.Name))
        else:
            oc.Content = ke
            oc.OperationpValue = val
            oc.Operator = current_user.Name
        db_session.commit()
    except Exception as e:
        db_session.rollback()
        print(e)
        logger.error(e)
        insertSyslog("error", "保存更新EletronicBatchDataStore报错:" + str(e),
                     current_user.Name)
        return json.dumps("保存更新EletronicBatchDataStore报错",
                          cls=AlchemyEncoder,
                          ensure_ascii=False)
Exemple #2
0
def PermissionsSave():
    if request.method == 'POST':
        data = request.values
        try:
            datastr = json.loads(data.get("data"))
            #删除之前的权限
            perss = db_session.query(Permission).filter(
                Permission.WorkNumber == datastr[0].get("WorkNumber")).all()
            for pe in perss:
                db_session.delete(pe)
            db_session.commit()
            for i in datastr:
                per = Permission()
                per.MenuName = i.get("MenuName")
                per.MenuType = i.get("MenuType")
                per.MenuCode = i.get("MenuCode")
                per.Name = i.get("Name")
                per.WorkNumber = i.get("WorkNumber")
                db_session.add(per)
            db_session.commit()
            return '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)
Exemple #3
0
def getTaskNo():
    bReturn = True
    qry = db_session.query(func.max(TaskNoGenerator.TaskNoInt)).all()
    intTaskNo = int(qry[0][0])
    varTaskNo = str(intTaskNo + 1)
    if len(varTaskNo) == 1:
        varTaskNo = "00000" + varTaskNo
    elif len(varTaskNo) == 2:
        varTaskNo = "0000" + varTaskNo
    if len(varTaskNo) == 3:
        varTaskNo = "000" + varTaskNo
    if len(varTaskNo) == 4:
        varTaskNo = "00" + varTaskNo
    if len(varTaskNo) == 5:
        varTaskNo = "0" + varTaskNo
    else:
        varTaskNo = varTaskNo
    try:
        db_session.add(
            TaskNoGenerator(TaskNoInt=intTaskNo + 1,
                            TaskNoVar=varTaskNo,
                            Description=""))
        db_session.commit()
        return bReturn, varTaskNo
    except Exception as e:
        bReturn = False
        print(e)
        logger.error(e)
        return bReturn, varTaskNo
Exemple #4
0
def batchusemodelselect():
    '''查询批记录使用模版'''
    if request.method == 'GET':
        data = request.values
        try:
            PUCode = data.get("PUCode")
            BrandCode = data.get("BrandCode")
            PUIDName = data.get("PUIDName")
            BrandName = data.get("BrandName")
            BatchID = data.get("BatchID")
            oclass = db_session.query(BatchUseModel).filter(
                BatchUseModel.BrandCode == BrandCode,
                BatchUseModel.PUCode == PUCode,
                BatchUseModel.BatchID == BatchID).first()
            dir = {}
            if not oclass:  #初始化批记录模板
                bum = BatchUseModel()
                bum.BatchID = BatchID
                bum.BrandCode = BrandCode
                bum.BrandName = BrandName
                bum.PUCode = PUCode
                bum.PUIDName = PUIDName
                oclass = db_session.query(BatchModel).filter(
                    BatchModel.BrandCode == BrandCode,
                    BatchModel.PUCode == PUCode).first()
                bum.UseParameter = oclass.Parameter
                db_session.add(bum)
                db_session.commit()
                oc = db_session.query(BatchUseModel).filter(
                    BatchUseModel.BrandCode == BrandCode,
                    BatchUseModel.PUCode == PUCode,
                    BatchUseModel.BatchID == BatchID).first()
                dir["ID"] = oc.ID
                dir["BrandCode"] = oc.FileName
                dir["BrandName"] = oc.FileName
                dir["PUIDName"] = oc.FileName
                dir["PUCode"] = oc.PUCode
                dir["UseParameter"] = oc.Parameter
            else:
                dir["ID"] = oclass.ID
                dir["BrandCode"] = oclass.FileName
                dir["BrandName"] = oclass.FileName
                dir["PUIDName"] = oclass.FileName
                dir["PUCode"] = oclass.PUCode
                dir["UseParameter"] = oclass.UseParameter
            return json.dumps({"code": "200", "message": dir})
        except Exception as e:
            db_session.rollback()
            print(e)
            logger.error(e)
            insertSyslog("error", "查询批记录使用模版报错Error:" + str(e),
                         current_user.Name)
            return json.dumps({"code": "500", "message": "后端报错"})
Exemple #5
0
def addscheduledates():
    '''
    添加工作日休息日
    :return:
    '''
    if request.method == 'GET':
        data = request.values
        try:
            month = data['month']
            count = db_session.query(scheduledate).filter(
                scheduledate.WorkDate.like("%" + month + "%")).count()
            if count < 20:
                mou = month.split("-")
                monthRange = calendar.monthrange(int(mou[0]), int(mou[1]))
                re = timeChange(mou[0], str(int(mou[1])), monthRange[1])
                lis = [
                    '星期一',
                    '星期二',
                    '星期三',
                    '星期四',
                    '星期五',
                    '星期六',
                    '星期日',
                ]
                dic = dict(enumerate(lis))
                for i in re:
                    ymr = i.split("-")
                    w = datetime.date(int(ymr[0]), int(ymr[1]), int(ymr[2]))
                    xq = dic[w.weekday()]
                    if xq == "星期六" or xq == "星期日":
                        # dc = db_session.query(scheduleDateType).filter(scheduleDateType.DateTypeName == "周末").first()
                        DateType = "周末"
                        color = "#FA7D00"
                    else:
                        DateType = "工作日"
                        color = "#00CAFA"
                    sc = scheduledate()
                    sc.WorkDate = i
                    sc.DateType = DateType
                    sc.comment = xq
                    sc.color = color
                    db_session.add(sc)
                    db_session.commit()
                db_session.close_all()
            return 'OK'
        except Exception as e:
            db_session.rollback()
            logger.error(e)
            insertSyslog("error", "添加工作日休息日报错Error:" + str(e),
                         current_user.Name)
            return json.dumps("添加工作日休息日报错",
                              cls=AlchemyEncoder,
                              ensure_ascii=False)
Exemple #6
0
def add_role():
    rcode = request.json.get('role_code')
    did = request.json.get('did')
    rname = request.json.get('role_name')
    rdes = request.json.get('role_description')
    department = db_session.query(DepartmentManager).filter(
        DepartmentManager.ID == int(did)).first()
    role = Role(RoleCode=rcode,
                RoleName=rname,
                Description=rdes,
                ParentNode=department.DepartCode)
    db_session.add(role)
    db_session.commit()
    return json.dumps({'code': 10003, 'msg': '新增成功', 'data': {'rid': role.ID}})
Exemple #7
0
def add_department():
    did = request.json.get('department_code')
    dname = request.json.get('department_name')
    fname = request.json.get('factory_name')
    depart = DepartmentManager(DepartCode=did,
                               DepartName=dname,
                               DepartLoad=fname)
    db_session.add(depart)
    db_session.commit()
    return json.dumps({
        'code': 10000,
        'msg': '新增成功',
        'data': {
            'Did': depart.ID
        }
    })
Exemple #8
0
def saveuserusershiftsgroup():
    '''
    用户添加班组
    :return:
    '''
    if request.method == 'POST':
        data = request.values
        try:
            userID = data.get("userID")
            shiftsgroupIDs = data.get("shiftsgroupIDs")
            if shiftsgroupIDs:
                shiftsgroupIDs = eval(shiftsgroupIDs)
            userclass = db_session.query(User).filter(
                User.ID == int(userID)).first()
            sql = "delete from usershiftsgroup where UserID = " + userID
            db_session.execute(sql)
            db_session.commit()
            for pid in shiftsgroupIDs:
                shiftsgroupcalss = db_session.query(ShiftsGroup).filter(
                    ShiftsGroup.ID == int(pid)).first()
                rpclas = db_session.query(UserShiftsGroup).filter(
                    UserShiftsGroup.UserID == userclass.ID,
                    UserShiftsGroup.ShiftsGroupID ==
                    shiftsgroupcalss.ID).first()
                if not rpclas:
                    rp = UserShiftsGroup()
                    rp.UserID = userclass.ID
                    rp.Name = userclass.Name
                    rp.ShiftsGroupID = shiftsgroupcalss.ID
                    rp.ShiftsGroupName = shiftsgroupcalss.ShiftsGroupName
                    db_session.add(rp)
                    db_session.commit()
            return json.dumps({
                "code": "200",
                "message": "请求成功"
            },
                              cls=AlchemyEncoder,
                              ensure_ascii=False)
        except Exception as e:
            db_session.rollback()
            print(e)
            logger.error(e)
            insertSyslog("error", "角色添加权限Error:" + str(e), current_user.Name)
Exemple #9
0
def saverolepermission():
    '''
    角色添加权限
    :return:
    '''
    if request.method == 'POST':
        data = request.values
        try:
            roleID = data.get("roleID")
            permissionIDs = data.get("permissionIDs")
            if permissionIDs:
                permissionIDs = eval(permissionIDs)
            roleclass = db_session.query(Role).filter(
                Role.ID == int(roleID)).first()
            sql = "delete from RolePermission where RoleID = " + roleID
            db_session.execute(sql)
            db_session.commit()
            for pid in permissionIDs:
                permissioncalss = db_session.query(Permission).filter(
                    Permission.ID == int(pid)).first()
                rpclas = db_session.query(RolePermission).filter(
                    RolePermission.RoleID == roleclass.ID,
                    RolePermission.PermissionID == permissioncalss.ID).first()
                if not rpclas:
                    rp = RolePermission()
                    rp.RoleID = roleclass.ID
                    rp.RoleName = roleclass.RoleName
                    rp.PermissionID = permissioncalss.ID
                    rp.PermissionName = permissioncalss.PermissionName
                    db_session.add(rp)
                    db_session.commit()
            return json.dumps({
                "code": "200",
                "message": "请求成功"
            },
                              cls=AlchemyEncoder,
                              ensure_ascii=False)
        except Exception as e:
            db_session.rollback()
            print(e)
            logger.error(e)
            insertSyslog("error", "角色添加权限Error:" + str(e), current_user.Name)
Exemple #10
0
def saveroleuser():
    '''
    用户添加角色
    :return:
    '''
    if request.method == 'POST':
        data = request.values
        try:
            UserID = data.get("UserID")
            RoleIDs = data.get("RoleIDs")
            if RoleIDs:
                RoleIDs = eval(RoleIDs)
            userclass = db_session.query(User).filter(
                User.ID == int(UserID)).first()
            sql = "delete from RoleUser where UserID = " + UserID
            db_session.execute(sql)
            db_session.commit()
            for pid in RoleIDs:
                rolecalss = db_session.query(Role).filter(
                    Role.ID == int(pid)).first()
                rpclas = db_session.query(RoleUser).filter(
                    RoleUser.UserID == userclass.ID,
                    RoleUser.RoleID == rolecalss.ID).first()
                if not rpclas:
                    rp = RoleUser()
                    rp.UserID = userclass.ID
                    rp.UserName = userclass.Name
                    rp.RoleID = rolecalss.ID
                    rp.RoleName = rolecalss.RoleName
                    db_session.add(rp)
                    db_session.commit()
            return json.dumps({
                "code": "200",
                "message": "请求成功"
            },
                              cls=AlchemyEncoder,
                              ensure_ascii=False)
        except Exception as e:
            db_session.rollback()
            print(e)
            logger.error(e)
            insertSyslog("error", "用户添加角色Error:" + str(e), current_user.Name)
Exemple #11
0
def batchmodelinsert():
    '''批记录模板名称路径储存'''
    if request.method == 'POST':
        data = request.values
        try:
            BrandName = data.get("BrandName")
            PUCode = data.get("PUCode")
            BrandCode = data.get("BrandCode")
            PUIDName = data.get("PUIDName")
            FileName = data.get("FileName")
            Parameter = data.get("Parameter")
            #删除之前存的
            oclass = db_session.query(BatchModel).filter(
                BatchModel.PUCode == PUCode).all()
            for oc in oclass:
                db_session.delete(oc)
                os.remove(oc.FilePath)
            db_session.commit()
            #新添加的
            bm = BatchModel()
            bm.BrandName = BrandName
            bm.PUCode = PUCode
            bm.BrandCode = BrandCode
            bm.PUIDName = PUIDName
            bm.FileName = FileName
            bm.FilePath = os.path.join(
                os.path.realpath(r"system_backend\SystemManagement\files"),
                FileName)
            bm.UserName = current_user.Name
            bm.Parameter = Parameter
            db_session.add(bm)
            db_session.commit()
            return json.dumps({"code": "200", "message": "上传成功!"})
        except Exception as e:
            db_session.rollback()
            print(e)
            logger.error(e)
            insertSyslog("error", "批记录模板导入报错Error:" + str(e),
                         current_user.Name)
            return json.dumps({"code": "500", "message": "后端报错"})
Exemple #12
0
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)
Exemple #13
0
def makeZYPlanZYTask(id):
    try:
        ocalss = db_session.query(PlanManager).filter(
            PlanManager.ID == id).first()
        if ocalss:
            if ocalss.PlanStatus == Global.PlanStatus.PreRUN.value:
                proclass = db_session.query(ProductUnit).filter(
                    ProductUnit.BrandCode == ocalss.BrandCode).order_by(
                        "Seq").all()
                for i in proclass:
                    pu = db_session.query(ProcessUnit).filter(
                        ProcessUnit.PUCode == i.PUCode).first()
                    zyplan = ZYPlan()
                    zyplan.PlanDate = ocalss.PlanBeginTime
                    zyplan.PlanNo = ocalss.SchedulePlanCode
                    zyplan.BatchID = ocalss.BatchID
                    zyplan.PlanSeq = i.Seq
                    zyplan.PUCode = i.PUCode
                    zyplan.PUName = i.PUName
                    zyplan.PlanType = Global.PLANTYPE.SCHEDULE.value
                    zyplan.BrandCode = ocalss.BrandCode
                    zyplan.BrandName = ocalss.BrandName
                    zyplan.ERPOrderNo = ""
                    zyplan.PlanQuantity = ocalss.PlanQuantity
                    zyplan.Unit = ocalss.Unit
                    zyplan.EnterTime = ""
                    zyplan.PlanBeginTime = ""
                    zyplan.ZYPlanStatus = Global.ZYPlanStatus.Produced.value
                    zyplan.LockStatus = Global.TASKLOCKSTATUS.UNLOCK.value
                    zyplan.INFStatus = Global.TASKSTATUS.NEW.value
                    zyplan.WMSStatus = Global.TASKSTATUS.NEW.value
                    db_session.add(zyplan)
                    db_session.commit()

                    # ebps = db_session.query(EquipmentBatchRunTime).filter(EquipmentBatchRunTime.BrandCode == ocalss.BrandCode,
                    #                 EquipmentBatchRunTime.BatchID == ocalss.BatchID, EquipmentBatchRunTime.PUCode == i.PUCode).all()
                    # iTaskSeq = 0
                    # for j in ebps:
                    #     iTaskSeq = iTaskSeq + 1
                    #     bReturn, strTaskNo = getTaskNo()
                    #     if bReturn == False:
                    #         return False
                    #     zytask = ZYTask()
                    #     zytask.PlanDate = j.StartTime
                    #     zytask.TaskID = strTaskNo
                    #     zytask.BatchID = ocalss.BatchID
                    #     zytask.PlanSeq = iTaskSeq
                    #     if i.PUName == "备料":#备料段为满足前端展示需要,虚拟了一个设备出来,所以下发要排除
                    #         zytask.PUCode = ""
                    #         zytask.PUName = ""
                    #     else:
                    #         zytask.PUCode = i.PUCode
                    #         zytask.PUName = i.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.EQPCode
                    #     zytask.EQPName = j.EQPName
                    #     zytask.StartBC = j.StartBC
                    #     zytask.EndBC = j.EndBC
                    #     zytask.PlanStartTime = j.StartTime
                    #     zytask.PlanEndTime = j.EndTime
                    #     zytask.TaskStatus = ""
                    #     zytask.LockStatus = Global.TASKLOCKSTATUS.UNLOCK.value
                    #     db_session.add(zytask)
    except Exception as ee:
        db_session.rollback()
        print(ee)
        logger.error(ee)
        insertSyslog("error", "下发计划生成ZY计划、任务报错Error" + str(ee),
                     current_user.Name)
        return 'NO'
Exemple #14
0
def makePlan():
    if request.method == 'POST':
        data = request.values  # 返回请求中的参数和form
        try:
            json_str = json.dumps(data.to_dict())
            if len(json_str) > 10:
                BatchID = data.get("BatchID")
                # PlanEndTime = data.get("PlanEndTime")
                BrandCode = data.get("BrandCode")
                # PlanBeginTime = data.get("PlanBeginTime")
                #批次号判重
                pcBatchID = db_session.query(PlanManager.BatchID).filter(
                    PlanManager.BatchID == BatchID,
                    PlanManager.BrandCode == BrandCode).first()
                if pcBatchID:
                    return json.dumps({"code": "201", "message": "批次号重复!"})
                pm = PlanManager()
                pm.SchedulePlanCode = str(datetime.datetime.now().strftime(
                    "%Y-%m-%d %H:%M:%S"))[0:10]
                pm.BatchID = BatchID
                pr = db_session.query(ProductRule).filter(
                    ProductRule.BrandCode == BrandCode).first()
                pm.PlanQuantity = pr.BatchWeight
                pm.Unit = pr.Unit
                pm.PlanNum = data.get("PlanNum")
                pm.BrandCode = BrandCode
                pm.BrandName = pr.BrandName
                pm.PlanStatus = Global.PlanStatus.Confirm.value
                # pm.PlanBeginTime = data.get("PlanBeginTime")
                # pm.PlanEndTime = data.get("PlanEndTime")
                pm.BrandType = pr.BrandType
                pm.EqpCodes = data.get("EqpCodes")
                db_session.add(pm)
                sp = SchedulePlan()
                sp.SchedulePlanCode = str(datetime.datetime.now().strftime(
                    "%Y-%m-%d %H:%M:%S"))[0:10]
                sp.Description = Global.SCHEDULETYPE.DAY.value
                sp.dEndTime = datetime.datetime.strptime(
                    str(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
                    [0:10], '%Y-%m-%d') + timedelta(days=1)
                sp.PlanBeginTime = ""
                sp.PlanEndTime = ""
                Type = Global.SCHEDULETYPE.DAY.value
                db_session.add(sp)
                db_session.commit()
                return json.dumps({"code": "200", "message": "添加成功!"})
        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)
    if request.method == 'GET':
        '''修改批次信息'''
        data = request.values
        try:
            ID = data.get("ID")
            BatchID = data.get("BatchID")
            # PlanQuantity = data.get("PlanQuantity")
            # PlanBeginTime = data.get("PlanBeginTime")
            # PlanEndTime = data.get("PlanEndTime")
            # Unit = data.get("Unit")
            ocalss = db_session.query(PlanManager).filter(
                PlanManager.ID == ID).first()
            if ocalss:
                pl = db_session.query(PlanManager).filter(
                    PlanManager.BatchID == BatchID,
                    PlanManager.BrandCode == ocalss.BrandCode).first()
                if not pl:
                    ocalss.BatchID = BatchID
                    # ocalss.PlanQuantity = PlanQuantity
                    # ocalss.PlanBeginTime = PlanBeginTime
                    # ocalss.PlanEndTime = PlanEndTime
                    # ocalss.Unit = Unit
                    ocalss.PlanStatus = Global.PlanStatus.Confirm.value
                    db_session.commit()
                    return json.dumps({"code": "200", "message": "修改成功!"})
                else:
                    return json.dumps({"code": "201", "message": "批次号重复!"})
        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)
Exemple #15
0
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)
Exemple #16
0
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)