Beispiel #1
0
 def ModifyModel(self, AFilename, ATableName):
     currentPath = os.path.abspath('.')
     model_path = PATH(currentPath + r'\\' + AFilename)
     i = 0
     tmp = ""
     try:
         if not os.path.exists(model_path):
             print("不存在!")
         else:
             # print("存在!!")
             with open(AFilename, 'r', encoding='UTF-8') as f:
                 lines = f.readlines()
                 i = 0
                 strTbStart = "#" + ATableName + "_START"
                 strTbEnd = "#" + ATableName + "_END"
                 strExecStart = "# 生成表单的执行语句_START"
                 strExecEnd = "# 生成表单的执行语句_END"
                 isExist = "FLASE"
                 for line in lines:
                     iposstart = line.find(strTbStart)
                     iposend = line.find(strTbEnd)
                     istart = line.find(strExecStart)
                     iend = line.find(strExecEnd)
                     if iposstart >= 0:
                         isExist = "TRUE"
                         i = 1
                         continue
                     elif iposend >= 0:
                         i = 0
                         continue
                     elif istart >= 0:
                         i = 1
                         continue
                     elif iend >= 0:
                         i = 0
                         continue
                     elif i == 1:
                         continue
                     tmp += line
             if tmp is "":
                 tmp += self.makeDevNotes()
                 tmp += self.makeImportNotes()
                 tmp += self.makeDBNotes()
                 tmp += self.makeBaseModel()
                 tmp += self.makeEndImplement()
             if isExist == "TRUE":
                 ATableNameNew = ATableName + datetime.datetime.now(
                 ).strftime('%Y-%m-%d %H:%M:%S')
                 sql = "EXEC sp_rename '" + ATableName + "', '" + ATableNameNew + "'"
                 db_session.execute(sql)
                 db_session.commit()
         f = open(AFilename, 'w', encoding='utf-8')
         f.write(tmp)
         f.close()
         return tmp
     except Exception as e:
         print(e)
         os.remove("make_model_test.txt")
         db_session.rollback()
         logger.error(e)
Beispiel #2
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)
Beispiel #3
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)
Beispiel #4
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)
Beispiel #5
0
def selectplanmanager():
    '''
    查询排产好的计划
    :return:
    '''
    if request.method == 'GET':
        data = request.values
        try:
            PlanNums = json.loads(data.get('PlanNums'))
            tableName = "PlanManager"
            pages = data.get("offset")
            pages = int(data.get("offset")) + 1
            rowsnumber = int(data.get("limit"))
            newTable = Table(tableName,
                             metadata,
                             autoload=True,
                             autoload_with=engine)
            columns = ""
            for column in newTable.columns:
                if columns == "":
                    columns = "[" + str(column).split(".")[1] + "]"
                else:
                    columns = columns + ",[" + str(column).split(".")[1] + "]"
            params = ""
            for key in PlanNums:
                if params == "":
                    params = "PlanNum like '%" + key + "%'"
                else:
                    params = params + " OR PlanNum like '%" + key + "%'"
            sql = "select top " + str(
                rowsnumber) + " " + columns + " from [LIMS].[dbo].[" + tableName + "] where (" + params + \
                  ") AND ID not in (select top " + str(
                (
                            pages - 1) * rowsnumber) + " ID FROM [LIMS].[dbo].[" + tableName + "] where " + params +" ORDER BY ID DESC) ORDER BY ID DESC"
            sqlcount = "select count(ID) from [LIMS].[dbo].[" + tableName + "] where " + params
            re = db_session.execute(sql).fetchall()
            recount = db_session.execute(sqlcount).fetchall()
            dict_list = []
            for i in re:
                dir = {}
                column_list = columns.split(",")
                for col in column_list:
                    dir[col[1:-1]] = i[col[1:-1]]
                dict_list.append(dir)
            return json.dumps({
                "code": "200",
                "message": "查询成功!",
                "data": {
                    "total": recount[0][0],
                    "rows": dict_list
                }
            })
        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)