示例#1
0
    def del_user(self, ids):
        """
        删除指定用户
        :param id:
        :return:
        """
        conn = MysqlConn()
        try:
            db_name = configuration.get_database_name()
            for id in eval(str(ids)):
                # 删除该用户关联角色
                delete_role_condition = 'user_id=%s' % id
                delete_user_role_sql = self.create_delete_sql(
                    db_name, 'user_roles', delete_role_condition)
                self.delete_exec(conn, delete_user_role_sql)
                # 删除该用户关联部门
                delete_department_condition = 'user_id=%s' % id
                delete_user_department_sql = self.create_delete_sql(
                    db_name, 'users_department', delete_department_condition)
                self.delete_exec(conn, delete_user_department_sql)
                # 删除该用户关联用户组
                delete_group_condition = 'user_id=%s' % id
                delete_group_sql = self.create_delete_sql(
                    db_name, 'user_user_group', delete_group_condition)
                self.delete_exec(conn, delete_group_sql)
                # 删除该用户关联任务组
                delete_task_group_condition = 'user_id=%s' % id
                delete_task_group_sql = self.create_delete_sql(
                    db_name, 'user_task_group', delete_task_group_condition)
                self.delete_exec(conn, delete_task_group_sql)

                # 删除用户主表记录
                delete_user_condition = 'id=%s' % id
                delete_user_sql = self.create_delete_sql(
                    db_name, 'users', delete_user_condition)
                self.delete_exec(conn, delete_user_sql)

            data = response_code.SUCCESS
            return data
        except Exception as e:
            lg.error(e)
            return response_code.DELETE_DATA_FAIL
        finally:
            conn.close()
示例#2
0
 def get_user_by_id(self, id):
     """
     通过id获取用户
     :return:
     """
     conn = MysqlConn()
     try:
         condition = "id='%s'" % id
         db_name = configuration.get_database_name()
         sql = self.create_select_sql(db_name,
                                      'users',
                                      '*',
                                      condition=condition)
         return self.execute_fetch_one(conn, sql)
     except Exception as e:
         lg.error(e)
         return response_code.GET_DATA_FAIL
     finally:
         conn.close()
示例#3
0
    def post(self, version, user_id=None):
        xml = request.args.get('format')
        try:
            if user_id is not None:
                data = response_code.NOT_FOUND
                return response_result_process(data, xml=xml)
            request_data = req.request_process(request, xml,
                                               modelEnum.user.value)
            if isinstance(request_data, bool):
                request_data = response_code.REQUEST_PARAM_FORMAT_ERROR
                return response_result_process(request_data, xml=xml)
            if not request_data:
                data = response_code.REQUEST_PARAM_MISSED
                return response_result_process(data, xml=xml)
            fields = [
                'user_name', 'login_name', 'user_sex', 'icon', 'position',
                'email', 'phone', 'note_info', 'icon', 'role_ids', 'group_ids',
                'dpt_ids'
            ]
            must = req.verify_all_param_must(request_data, fields)
            if must:
                return response_result_process(must, xml=xml)
            par_type = {
                'user_name': str,
                'login_name': str,
                'user_sex': int,
                'icon': str,
                'position': str,
                'email': str,
                'phone': str,
                'note_info': str,
            }
            param_type = req.verify_all_param_type(request_data, par_type)
            if param_type:
                return response_result_process(param_type, xml=xml)

            data = user_singleton.add_user(request_data)
            return response_result_process(data, xml=xml)
        except Exception as e:
            lg.error(e)
            error_data = response_code.ADD_DATA_FAIL
            return response_result_process(error_data, xml=xml)
    def put(self, version, group_id=None):
        xml = request.args.get('format')
        try:
            if group_id is None:
                data = response_code.NOT_FOUND
                return response_result_process(data, xml=xml)

            if group_id is not None:
                request_data = req.request_process(request, xml,
                                                   modelEnum.user_group.value)
                if isinstance(request_data, bool):
                    request_data = response_code.REQUEST_PARAM_FORMAT_ERROR
                    return response_result_process(request_data, xml=xml)
                if not request_data:
                    data = response_code.REQUEST_PARAM_MISSED
                    return response_result_process(data, xml=xml)

                fields = ['name']
                must = req.verify_all_param_must(request_data, fields)
                if must:
                    return response_result_process(must, xml=xml)
                par_type = {'name': str, 'desc': str, 'role_ids': list}
                param_type = req.verify_all_param_type(request_data, par_type)
                if param_type:
                    return response_result_process(param_type, xml=xml)

                group_name = request_data.get('name')
                group_desc = request_data.get('desc')
                role_ids = request_data.get('role_ids')
                infos = {
                    'id': group_id,
                    'name': group_name if group_name else '',
                    'desc': group_desc if group_desc else '',
                    'role_ids': role_ids if role_ids else []
                }

                data = user_group_singleton.update_user_group(infos)
                return response_result_process(data, xml=xml)
        except Exception as e:
            lg.error(e)
            error_data = response_code.UPDATE_DATA_FAIL
            return response_result_process(error_data, xml=xml)
示例#5
0
 def get_all_department(self):
     """
     获取所有的部门信息
     :return:
     """
     db_conn = MysqlConn()
     try:
         db_name = configuration.get_database_name()
         table_name = 'department'
         fields = 'dpt_id,dpt_name,p_id'
         sql = self.create_select_sql(db_name, table_name, fields)
         result = self.execute_fetch_all(db_conn, sql)
         data = response_code.SUCCESS
         data['data'] = result
         return data
     except Exception as e:
         lg.error(e)
         return response_code.GET_DATA_FAIL
     finally:
         db_conn.close()
示例#6
0
 def get_all_user(self):
     """
     查询所有用户
     :return:
     """
     db_conn = MysqlConn()
     try:
         db_name = configuration.get_database_name()
         table_name = 'users'
         fields = 'id,user_name,user_sex,email,phone,position,note_info,login_name'
         sql = self.create_select_sql(db_name, table_name, fields)
         result = self.execute_fetch_all(db_conn, sql)
         data = response_code.SUCCESS
         data['data'] = result
         return data
     except Exception as e:
         lg.error(e)
         return response_code.GET_DATA_FAIL
     finally:
         db_conn.close()
示例#7
0
 def get_user_group_by_name(self, group_name):
     """
     通过名称查询用户组信息
     :param group_name:
     :return:
     """
     conn = MysqlConn()
     try:
         condition = 'name="%s"' % group_name
         db_name = configuration.get_database_name()
         sql = self.create_select_sql(db_name,
                                      'user_group',
                                      'id',
                                      condition=condition)
         return self.execute_fetch_one(conn, sql)
     except Exception as e:
         lg.error(e)
         return response_code.GET_DATA_FAIL
     finally:
         conn.close()
 def get_all_roles(self):
     """
     获取所有的角色信息
     :return:
     """
     db_conn = MysqlConn()
     try:
         db_name = configuration.get_database_name()
         table_name = 'role'
         role_fields = 'id,name,create_time,note_info,time_modify'
         sql = self.create_select_sql(db_name, table_name, role_fields)
         result = self.execute_fetch_all(db_conn, sql)
         data = response_code.SUCCESS
         data['data'] = result
         return data
     except Exception as e:
         lg.error(e)
         return response_code.GET_DATA_FAIL
     finally:
         db_conn.close()
示例#9
0
 def get_all_groups(self):
     """
     获取所有用户组
     :return:
     """
     db_conn = MysqlConn()
     try:
         db_name = configuration.get_database_name()
         table_name = 'user_group'
         fields = 'id,name,description as desc,create_time'
         sql = self.create_select_sql(db_name, table_name, fields)
         result = self.execute_fetch_all(db_conn, sql)
         data = response_code.SUCCESS
         data['data'] = result
         return data
     except Exception as e:
         lg.error(e)
         return response_code.GET_DATA_FAIL
     finally:
         db_conn.close()
示例#10
0
 def add_group(self, group_name, group_desc, role_ids):
     """
     添加用户组
     :param group_name:
     :param group_desc:
     :return:
     """
     db_conn = MysqlConn()
     try:
         db_name = configuration.get_database_name()
         table_name = 'user_group'
         filed = 'name'
         condition = "name = '%s'" % group_name
         is_exist_sql = self.create_select_sql(db_name, table_name, filed,
                                               condition)
         res = self.execute_fetch_one(db_conn, is_exist_sql)
         if res:
             return response_code.RECORD_EXIST
         fields = '(name,description,create_time)'
         create_time = get_system_datetime()
         value_tuple = (group_name, group_desc, create_time)
         insert_user_sql = self.create_insert_sql(db_name, table_name,
                                                  fields, value_tuple)
         self.insert_exec(db_conn, insert_user_sql)
         # 查询新添加的用户组
         new_group = self.get_user_group_by_name(group_name)
         new_group_id = new_group.get('id')
         # 添加用户组的角色
         group_role_fields = '(group_id,role_id)'
         for role_id in eval(str(role_ids)):
             group_role_value_tuple = (new_group_id, role_id)
             insert_user_sql = self.create_insert_sql(
                 db_name, "user_group_role", group_role_fields,
                 group_role_value_tuple)
             self.insert_exec(db_conn, insert_user_sql)
         return response_code.SUCCESS
     except Exception as e:
         lg.error(e)
         return response_code.ADD_DATA_FAIL
     finally:
         db_conn.close()
    def _xml_request(self, request, model_json=None):
        """
        处理xml请求参数为json格式
        :param data: 请求
        :return:
        """
        try:
            data = request.data
            temp = data.decode('utf-8')
            if temp == '':
                return {}
            try:
                param_temp = xml_to_json(temp)
            except Exception as e:
                return response_code.REQUEST_PARAM_FORMAT_ERROR
            param = json.loads(param_temp)

            root = model_json.get('root')
            body = model_json.get('body')

            root_data = param.get(root)
            request_param = None
            if root_data:
                body_data = root_data.get(body)
                if body_data:
                    if isinstance(body_data, list):
                        request_param = is_none(root_data)
                    else:
                        request_param = is_none(body_data)
            if root_data is None:
                s_body_data = param.get(body)
                if s_body_data:
                    if isinstance(is_none(s_body_data), dict):
                        request_param = s_body_data

            if isinstance(request_param, list) or request_param is None:
                return False
            return request_param
        except Exception as e:
            lg.error(e)
            return False
示例#12
0
 def pwd_reset(self, user_ids):
     '''
     重置用户密码
     :return:
     '''
     conn = MysqlConn()
     try:
         db_name = configuration.get_database_name()
         pass_word = generate_password_hash('123456')
         for user_id in eval(str(user_ids)):
             condition = 'id=%s' % user_id
             update_user_sql = self.create_update_sql(
                 db_name, 'users', ['pass_word'], [pass_word], condition)
             self.updete_exec(conn, update_user_sql)
         data = response_code.SUCCESS
         return data
     except Exception as e:
         lg.error(e)
         return response_code.PASS_WORD_RESET_FAIL
     finally:
         conn.close()
示例#13
0
    def post(self, version):
        print(request.args)
        xml = request.args.get('format')
        try:
            request_data = req.request_process(request, xml,
                                               modelEnum.login.value)
            if isinstance(request_data, bool):
                request_data = response_code.REQUEST_PARAM_FORMAT_ERROR
                return response_result_process(request_data, xml=xml)
            print(request_data)
            if not request_data:
                data = response_code.REQUEST_PARAM_MISSED
                return response_result_process(data, xml=xml)
            fields = ['login_name', 'login_password']
            must = req.verify_all_param_must(request_data, fields)
            if must:
                return response_result_process(must, xml=xml)

            login_name, login_password = request_data.get(
                'login_name'), request_data.get('login_password')
            # 对登录情况进行验证
            print(login_name, login_password)
            dict_user = Auth.authenticate(login_name, login_password)
            # 将用户信息写到全局
            user_key = dict_user.get('id')
            operation_log(description='login')
            if user_key:
                g.user_key = user_key
                data = {}
                data['code'] = 200
                data['msg'] = '请求成功'
                data['data'] = dict_user
            else:
                data = dict_user

            return response_result_process(data, xml=xml)
        except Exception as e:
            lg.error(e)
            error_data = response_code.LOGIN_FAIL
            return response_result_process(error_data, xml=xml)
示例#14
0
    def upd_group(self, group_json):
        """
        更新用户组
        :param group_json:
        :return:
        """
        db_conn = MysqlConn()
        try:
            db_name = configuration.get_database_name()
            # 解析参数成dict
            group = group_json
            table_name = 'user_group'
            condition = "id=%s" % group.get('id')
            # 更新用户基本信息
            update_group_fields = ['name', 'description']
            update_group_fields_value = [group.get('name'), group.get('desc')]
            update_group_sql = self.create_update_sql(
                db_name, table_name, update_group_fields,
                update_group_fields_value, condition)
            self.updete_exec(db_conn, update_group_sql)
            # 删除用户组原有角色
            condition = "group_id=%s" % group.get('id')
            delete_group_role_sql = self.create_delete_sql(
                db_name, "user_group_role", condition)
            self.delete_exec(db_conn, delete_group_role_sql)

            # 添加用户组的角色
            group_role_fields = '(group_id,role_id)'
            for role_id in eval(str(group.get('role_ids'))):
                group_role_value_tuple = (group.get('id'), role_id)
                insert_group_role_sql = self.create_insert_sql(
                    db_name, "user_group_role", group_role_fields,
                    group_role_value_tuple)
                self.insert_exec(db_conn, insert_group_role_sql)
            return response_code.SUCCESS
        except Exception as e:
            lg.error(e)
            return response_code.UPDATE_DATA_FAIL
        finally:
            db_conn.close()
示例#15
0
    def del_group(self, group_id, role_ids):
        """
        删除用户组
        :param group_id:
        :return:
        """
        db_conn = MysqlConn()
        try:
            db_name = configuration.get_database_name()
            # 关闭外键检测
            # db_conn.cur.execute('SET FOREIGN_KEY_CHECKS = 0;')
            # db_conn.conn.commit()
            # 删除用户组角色
            for role_id in eval(str(role_ids)):
                condition = "group_id=%s and role_id=%s" % (group_id, role_id)
                delete_group_role_sql = self.create_delete_sql(
                    db_name, "user_group_role", condition)
                self.delete_exec(db_conn, delete_group_role_sql)
            # 删除用户组下所有用户
            condition = "group_id=%s" % group_id
            delete_group_user_sql = self.create_delete_sql(
                db_name, "user_user_group", condition)
            self.delete_exec(db_conn, delete_group_user_sql)
            # 删除用户组主表信息
            table_name = 'user_group'
            condition = "id=%s" % group_id
            delete_group_sql = self.create_delete_sql(db_name, table_name,
                                                      condition)
            self.delete_exec(db_conn, delete_group_sql)

            # 开起外键检测
            # db_conn.cur.execute('SET FOREIGN_KEY_CHECKS = 1;')
            # db_conn.conn.commit()
            return response_code.SUCCESS
        except Exception as e:
            lg.error(e)
            return response_code.DELETE_DATA_FAIL
        finally:
            db_conn.close()
    def get_grafana_permission(self, user_id):
        """

        :param user_id:
        :return:
        """
        db_conn = MysqlConn()
        try:
            db_name = configuration.get_database_name()
            condition = 'user_id = %s' % user_id
            role_sql = self.create_select_sql(db_name, 'user_roles', 'role_id',
                                              condition)
            role_data = self.execute_fetch_all(db_conn, role_sql)
            permission_ids = []
            for role in role_data:
                per_condition = 'role_id = %s' % role.get('role_id')
                per_sql = self.create_select_sql(db_name, 'roles_permission',
                                                 'permission_id',
                                                 per_condition)
                per_data = self.execute_fetch_all(db_conn, per_sql)
                permission_ids += per_data
            gra_ids = []
            for per in permission_ids:
                gr_condition = 'id = %s and permission_type = 3 and grafana_id <> 0' % per.get(
                    'permission_id')
                gr_sql = self.create_select_sql(db_name, 'permission',
                                                'grafana_id', gr_condition)
                gr_data = self.execute_fetch_one(db_conn, gr_sql)
                if gr_data:
                    gra_ids.append(gr_data)
            data = response_code.SUCCESS
            gra_id = [i.get("grafana_id") for i in gra_ids]
            data['data'] = gra_id
            return data
        except Exception as e:
            lg.error(e)
            return response_code.GET_DATA_FAIL
        finally:
            db_conn.close()
示例#17
0
 def get_user_by_id_(self, id):
     """
     给前端使用的通过id获取用户
     :return:
     """
     conn = MysqlConn()
     try:
         condition = 'id=%s' % id
         db_name = configuration.get_database_name()
         fields = 'id,user_name,user_sex,email,phone,position,note_info,login_name,create_time'
         sql = self.create_select_sql(db_name,
                                      'users',
                                      fields,
                                      condition=condition)
         data = response_code.SUCCESS
         data['data'] = self.execute_fetch_one(conn, sql)
         return data
     except Exception as e:
         lg.error(e)
         return response_code.GET_DATA_FAIL
     finally:
         conn.close()
 def get_data_permission_info(self):
     """
     获取所有的数据权限信息
     :return:
     """
     db_conn = MysqlConn()
     try:
         db_name = configuration.get_database_name()
         table_name = 'permission'
         condition = 'permission_type=1'
         per_fields = 'id,name,create_time,p_id,permission_type'
         sql = self.create_select_sql(db_name, table_name, per_fields,
                                      condition)
         result = self.execute_fetch_all(db_conn, sql)
         data = response_code.SUCCESS
         data['data'] = result
         return data
     except Exception as e:
         lg.error(e)
         return response_code.GET_DATA_FAIL
     finally:
         db_conn.close()
示例#19
0
    def get_user_by_group_id(self, group_id, current_page, page_size):
        """
        查询用户组下所有用户
        :param group_id:
        :param current_page:
        :param page_size:
        :return:
        """
        db_conn = MysqlConn()
        try:
            start_num = str((current_page - 1) * page_size)
            db_name = configuration.get_database_name()
            table_name = 'user_user_group'
            fields = 'user_id'
            condition = 'group_id=%s' % group_id
            sql_count, sql = self.create_get_page_sql(db_name, table_name,
                                                      fields, start_num,
                                                      page_size, condition)
            result = self.execute_fetch_pages(db_conn, sql_count, sql,
                                              current_page, page_size)
            data_list = result.get('data_list')

            if data_list:
                user_data = tuple([user.get('user_id') for user in data_list])
                user_data_list = user_mgr.get_user_by_ids(user_data)
            else:
                user_data_list = []

            # user_data = tuple([user.get('user_id') for user in data])
            # user_data_list = user_mgr.get_user_by_ids(user_data)
            data = response_code.SUCCESS
            data['data'] = user_data_list
            data['total'] = result.get('total_count')
            return data
        except Exception as e:
            lg.error(e)
            return response_code.GET_DATA_FAIL
        finally:
            db_conn.close()
示例#20
0
 def get_user_group_roles(self, group_id):
     """
     获取用户组的角色信息
     :param group_id:
     :return:
     """
     db_conn = MysqlConn()
     try:
         db_name = configuration.get_database_name()
         table_name = 'user_group_role'
         fields = 'role_id'
         condition = 'group_id=%s' % group_id
         sql = self.create_select_sql(db_name,
                                      table_name,
                                      fields,
                                      condition=condition)
         result = self.execute_fetch_all(db_conn, sql)
         if result:
             role_ids = tuple([role.get('role_id') for role in result])
             if len(role_ids) == 1:
                 role_condition = 'id=%s' % role_ids[0]
             else:
                 role_condition = 'id in %s' % str(role_ids)
             sql = self.create_select_sql(db_name,
                                          'role',
                                          '*',
                                          condition=role_condition)
             role_result = self.execute_fetch_all(db_conn, sql)
             data = response_code.SUCCESS
             data['data'] = role_result
         else:
             data = response_code.SUCCESS
             data['data'] = []
         return data
     except Exception as e:
         lg.error(e)
         return response_code.GET_DATA_FAIL
     finally:
         db_conn.close()
示例#21
0
 def delete_department_staff(self, dpt_id, user_ids):
     """
     删除部门下的员工信息
     :param dpt_id: 部门ID
     :param user_ids:
     :return:
     """
     db_conn = MysqlConn()
     try:
         db_name = configuration.get_database_name()
         table_name = 'users_department'
         for user_id in eval(user_ids):
             condition = "user_id=%s and dpt_id = %s" % (user_id, dpt_id)
             sql = self.create_delete_sql(db_name, table_name, condition)
             # 删除部门员工
             self.execute_del_data(db_conn, sql)
         return response_code.SUCCESS
     except Exception as e:
         lg.error(e)
         return response_code.DELETE_DATA_FAIL
     finally:
         db_conn.close()
    def add_role_permission(self, role_id, per_keys):
        """
        给角色添加权限
        :param role_id: 角色id
        :param per_keys: 权限列表
        :return:
        """
        db_conn = MysqlConn()
        try:

            db_name = configuration.get_database_name()
            table_name = 'roles_permission'
            filed = 'role_id'
            condition = " role_id = '%s'" % role_id

            # 删除旧的权限
            old_role_sql = DbBase.create_select_sql(self, db_name, table_name,
                                                    filed, condition)
            old_role_id_data = DbBase.execute_fetch_one(
                self, db_conn, old_role_sql)
            if old_role_id_data:
                condition = "role_id=%s" % old_role_id_data.get('role_id')
                del_association_sql = self.create_delete_sql(
                    db_name, table_name, condition)
                # 删除用户和部门关联表的数据
                self.execute_del_data(db_conn, del_association_sql)
            # 添加新的权限
            for per_key in eval(per_keys):
                fields = '(role_id, permission_id)'
                pla_data = (role_id, per_key)
                sql = DbBase.create_insert_sql(self, db_name, table_name,
                                               fields, pla_data)
                DbBase.execute_sql_return_count(self, db_conn, sql)
            return response_code.SUCCESS
        except Exception as e:
            lg.error(e)
            return response_code.ADD_DATA_FAIL
        finally:
            db_conn.close()
示例#23
0
    def put(self, version, user_id=None):
        xml = request.args.get('format')
        try:
            if user_id is None:
                data = response_code.NOT_FOUND
                return response_result_process(data, xml=xml)

            if user_id is not None:
                request_data = req.request_process(request, xml,
                                                   modelEnum.user.value)
                if isinstance(request_data, bool):
                    request_data = response_code.REQUEST_PARAM_FORMAT_ERROR
                    return response_result_process(request_data, xml=xml)
                if not request_data:
                    data = response_code.REQUEST_PARAM_MISSED
                    return response_result_process(data, xml=xml)

                fields = ['user_name', 'login_name', 'phone', 'email']
                must = req.verify_all_param_must(request_data, fields)
                if must:
                    return response_result_process(must, xml=xml)
                par_type = {
                    'user_name': str,
                    'login_name': str,
                    'phone': str,
                    'email': str
                }
                param_type = req.verify_all_param_type(request_data, par_type)
                if param_type:
                    return response_result_process(param_type, xml=xml)

                request_data['user_id'] = user_id
                data = user_singleton.update_header_user_info(request_data)
                return response_result_process(data, xml=xml)
        except Exception as e:
            lg.error(e)
            error_data = response_code.UPDATE_DATA_FAIL
            return response_result_process(error_data, xml=xml)
示例#24
0
 def update_system_log(self, log_key, opinion, opinion_user, status):
     """
     处理后,修改日志信息
     :param log_key:日志id
     :param opinion:处理意见
     :param opinion_user:处理人
     :param status:状态
     :return:
     """
     db_conn = MysqlConn()
     try:
         db_name = configuration.get_database_name()
         table_name = 'system_log'
         condition = "log_key=%s" % log_key
         # 查看状态是否已经更新
         sql = self.create_select_sql(db_name, table_name, 'status',
                                      condition)
         log = self.execute_fetch_one(db_conn, sql)
         if log.get('status') == 2:
             return response_code.ALREADY_HANDLED
         # 更新日志信息
         opinion_time = get_system_datetime()
         update_group_fields = [
             'opinion', 'opinion_user', 'status', 'opinion_time'
         ]
         update_group_fields_value = [
             opinion, opinion_user, status, opinion_time
         ]
         update_group_sql = self.create_update_sql(
             db_name, table_name, update_group_fields,
             update_group_fields_value, condition)
         self.updete_exec(db_conn, update_group_sql)
         return response_code.SUCCESS
     except Exception as e:
         lg.error(e)
         return response_code.UPDATE_DATA_FAIL
     finally:
         db_conn.close()
示例#25
0
    def put(self, version, role_id=None):
        xml = request.args.get('format')
        try:
            if role_id is None:
                data = response_code.NOT_FOUND
                return response_result_process(data, xml=xml)

            if role_id is not None:
                request_data = req.request_process(request, xml,
                                                   modelEnum.role.value)
                if isinstance(request_data, bool):
                    request_data = response_code.REQUEST_PARAM_FORMAT_ERROR
                    return response_result_process(request_data, xml=xml)
                if not request_data:
                    data = response_code.REQUEST_PARAM_MISSED
                    return response_result_process(data, xml=xml)

                fields = ['role_name']
                must = req.verify_all_param_must(request_data, fields)
                if must:
                    return response_result_process(must, xml=xml)

                par_type = {'role_name': str, 'note_info': str}

                param_type = req.verify_all_param_type(request_data, par_type)
                if param_type:
                    return response_result_process(param_type, xml=xml)
                role_name = request_data.get('role_name')
                note_info = request_data.get('note_info') if request_data.get(
                    'note_info') else ''

                data = role_permission_singleton.update_role(
                    role_id, role_name, note_info)
                return response_result_process(data, xml=xml)
        except Exception as e:
            lg.error(e)
            error_data = response_code.UPDATE_DATA_FAIL
            return response_result_process(error_data, xml=xml)
示例#26
0
    def get_message_count(self, creator):
        db_conn = MysqlConn()
        try:
            db_name = configuration.get_database_name()
            table_name = 'inform_message'
            data = response_code.SUCCESS
            fields = 'id,title,content,create_time,state'
            condition = " state = 0"
            # 给定了查询字段
            sql_count, sql = self.create_get_page_sql(db_name, table_name,
                                                      fields, 0, 9000000,
                                                      condition)
            # 执行查询
            result = self.execute_fetch_pages(db_conn, sql_count, sql, 1,
                                              9000000)
            data['data'] = result

            return data
        except Exception as e:
            lg.error(e)
            return response_code.GET_DATA_FAIL
        finally:
            db_conn.close()
示例#27
0
 def get_user_by_ids(self, ids_tuple):
     """
     通过id元组获取用户
     :return:
     """
     conn = MysqlConn()
     try:
         db_name = configuration.get_database_name()
         if len(ids_tuple) == 1:
             condition = 'id=%s' % ids_tuple[0]
         else:
             condition = 'id in %s' % str(ids_tuple)
         fields = 'id,user_name,user_sex,email,phone,position,note_info,login_name'
         sql = self.create_select_sql(db_name,
                                      'users',
                                      fields,
                                      condition=condition)
         return self.execute_fetch_all(conn, sql)
     except Exception as e:
         lg.error(e)
         return response_code.GET_DATA_FAIL
     finally:
         conn.close()
    def get(self, version, dpt_id=None):
        xml = request.args.get('format')
        try:
            if dpt_id is None:
                data = response_code.NOT_FOUND
                return response_result_process(data, xml=xml)

            request_data = req.request_process(request, xml,
                                               modelEnum.department.value)
            if isinstance(request_data, bool):
                request_data = response_code.REQUEST_PARAM_FORMAT_ERROR
                return response_result_process(request_data, xml=xml)
            if not request_data:
                data = response_code.REQUEST_PARAM_MISSED
                return response_result_process(data, xml=xml)
            fields = ['current_page', 'page_size']
            must = req.verify_all_param_must(request_data, fields)
            if must:
                return response_result_process(must, xml=xml)
            par_type = {'page_size': int, 'current_page': int}
            param_type = req.verify_all_param_type(request_data, par_type)
            if param_type:
                return response_result_process(param_type, xml=xml)

            current_page, page_size = int(
                request_data.get('current_page')), int(
                    request_data.get('page_size'))
            data = department_singleton.get_dpt_user_info_by_id(
                dpt_id, current_page, page_size)
            body = modelEnum.department.value.get('body')
            return response_result_process(data,
                                           xml_structure_str=body,
                                           xml=xml)
        except Exception as e:
            lg.error(e)
            error_data = response_code.GET_DATA_FAIL
            return response_result_process(error_data, xml=xml)
示例#29
0
    def get(self, version, user_id=None):
        xml = request.args.get('format')
        try:
            body = modelEnum.user.value.get('body')
            if user_id is None:
                request_data = req.request_process(request, xml,
                                                   modelEnum.user.value)
                if isinstance(request_data, bool):
                    request_data = response_code.REQUEST_PARAM_FORMAT_ERROR
                    return response_result_process(request_data, xml=xml)
                if not request_data:
                    res = get_branch_all()
                    data = response_code.SUCCESS
                    data['data'] = res
            #     else:
            #         fields = ['current_page', 'page_size']
            #         must = req.verify_all_param_must(request_data, fields)
            #         if must:
            #             return response_result_process(must, xml=xml)
            #         par_type = {'page_size': int, 'current_page': int, 'search_data': dict}
            #         param_type = req.verify_all_param_type(request_data, par_type)
            #         if param_type:
            #             return response_result_process(param_type, xml=xml)
            #
            #         current_page, page_size = int(request_data.get('current_page')), int(request_data.get('page_size'))
            #         search_data = request_data.get('search_data') if request_data.get('search_data') else {}
            #         data = user_singleton.get_users_info(current_page, page_size, search_data)
            # else:
            #     data = user_singleton.get_user_info_by_id(user_id)

            return response_result_process(data,
                                           xml_structure_str=body,
                                           xml=xml)
        except Exception as e:
            lg.error(e)
            error_data = response_code.GET_DATA_FAIL
            return response_result_process(error_data, xml=xml)
    def get_pages_roles(self, current_page, page_size, search_data):
        """
        获取所有的角色信息
        :return:
        """
        db_conn = MysqlConn()
        try:
            start_num = (current_page - 1) * page_size
            db_name = configuration.get_database_name()
            table_name = 'role'
            param = search_data
            role_fields = 'id,name,create_time,note_info,time_modify'
            if param == {} or param == '':
                sql_count, sql = self.create_get_page_sql(
                    db_name, table_name, role_fields, start_num, page_size)
            else:
                condition = None
                for key, value in param.items():
                    condition = "  %s like '%%%s%%'" % (key, value)
                sql_count, sql = self.create_get_page_sql(
                    db_name, table_name, role_fields, start_num, page_size,
                    condition)

            # sql = self.create_select_sql(db_name, table_name, role_fields)

            result = self.execute_fetch_pages(db_conn, sql_count, sql,
                                              current_page, page_size)
            data = response_code.SUCCESS
            data["data"] = result.get('data_list')
            data["total"] = result.get('total_count')
            return data
        except Exception as e:
            lg.error(e)
            return response_code.GET_DATA_FAIL
        finally:
            db_conn.close()