Пример #1
0
    def get(self, version, proid):
        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_sku_by_proid(proid)

                if isinstance(res, dict):
                    data = res

                if isinstance(res, list):
                    data = response_code.SUCCESS
                    data['data'] = res

            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)
Пример #2
0
    def get(self, version, group_id=None):
        xml = request.args.get('format')
        try:
            body = modelEnum.user_group.value.get('body')
            if group_id is 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 = user_group_singleton.get_groups_list(1, 1000000, '')
                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_name = request_data.get('search_name') if request_data.get('search_name') else {}

                    data = user_group_singleton.get_groups_list(current_page, page_size, search_name)

                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)
Пример #3
0
    def get(self, version, user_id=None):
        xml = request.args.get('format')
        try:
            lg.info("Call run BranchSkuList")
            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_sku_list()
            #     # data = response_code.SUCCESS
            #     # data['data'] = res
            # else:
            if request_data:
                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,
                    'exact': bool
                }
                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 {}

                exact_data = bool(request_data.get('exact'))

                # res = get_branch_sku_list(current_page, page_size, search_data,exact_data)
                res = get_branch_sku_list.delay(current_page, page_size,
                                                search_data, exact_data)

                if isinstance(res, dict):
                    data = res

                if isinstance(res, list):
                    data = response_code.SUCCESS
                    data['data'] = res

            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)
Пример #4
0
 def get(self, version):
     xml = request.args.get('format')
     try:
         body = modelEnum.permission.value.get('body')
         data = role_permission_singleton.get_user_permission_info()
         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)
Пример #5
0
 def post(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)
         data = user_singleton.reset_password([user_id])
         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)
 def get(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)
         data = user_group_singleton.get_user_group_roles(group_id)
         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)
Пример #7
0
    def delete(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:
                data = user_singleton.delete_user([user_id])
                return response_result_process(data, xml=xml)
        except Exception as e:
            lg.error(e)
            error_data = response_code.DELETE_DATA_FAIL
            return response_result_process(error_data, xml=xml)
 def get(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)
         data = role_permission_singleton.get_role_permission_info(role_id)
         body = modelEnum.role_permission.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)
    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:

                    # print(g.user_key)
                    userinfo = user_singleton.get_user_info_by_id(g.user_key)
                    log_str = "Apply Account:==>" + userinfo['data'][
                        'user_name']
                    lg.log(log_str)
                    # print(userinfo['data'])
                    res = get_branch_all()
                    data = response_code.SUCCESS
                    data['data'] = res

                    # data = user_singleton.get_users_info()
                    # data = UserSingleton.get_all_users(self)
                # 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)
Пример #10
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 get(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)

            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 = ['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 = user_group_singleton.get_users_by_group_id(group_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)
Пример #12
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 = ['old_password', 'new_password', 'new_password_ok']
                must = req.verify_all_param_must(request_data, fields)
                if must:
                    return response_result_process(must, xml=xml)
                par_type = {
                    'old_password': str,
                    'new_password': str,
                    'new_password_ok': str
                }
                param_type = req.verify_all_param_type(request_data, par_type)
                if param_type:
                    return response_result_process(param_type, xml=xml)

                old_pwd = request_data.get('old_password')
                new_pwd = request_data.get('new_password')
                new_pwd_ok = request_data.get('new_password_ok')

                # 判断输入的数据是否为空
                if not all([user_id, old_pwd, new_pwd_ok]):
                    error_data = response_code.PASS_WORD_INFO_NOT_FILL
                    return response_result_process(error_data, xml=xml)
                # 核对两次输入的密码是否一致
                if new_pwd_ok != new_pwd:
                    error_data = response_code.TWO_PASS_WORD_DIFFERENT
                    return response_result_process(error_data, xml=xml)

                data = user_singleton.update_user_password(
                    user_id, old_pwd, new_pwd)
                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)
Пример #13
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)
    def delete(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 = ['user_ids']
            must = req.verify_all_param_must(request_data, fields)
            if must:
                return response_result_process(must, xml=xml)
            par_type = {'user_ids': list}
            param_type = req.verify_all_param_type(request_data, par_type)
            if param_type:
                return response_result_process(param_type, xml=xml)
            user_ids = str(request_data.get('user_ids'))

            data = department_singleton.delete_department_staff(
                dpt_id, user_ids)
            return response_result_process(data, xml=xml)

        except Exception as e:
            lg.error(e)
            error_data = response_code.DELETE_DATA_FAIL
            return response_result_process(error_data, xml=xml)
Пример #15
0
 def post(self, version, dpt_id=None):
     xml = request.args.get('format')
     try:
         if dpt_id is not 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 = ['dpt_name', 'p_id']
         must = req.verify_all_param_must(request_data, fields)
         if must:
             return response_result_process(must, xml=xml)
         par_type = {'dpt_name': str, 'p_id': int}
         param_type = req.verify_all_param_type(request_data, par_type)
         if param_type:
             return response_result_process(param_type, xml=xml)
         dpt_name, dpt_p_id = request_data.get(
             'dpt_name'), request_data.get('p_id')
         data = department_singleton.add_department(dpt_name, dpt_p_id)
         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)
Пример #16
0
    def post(self, version, role_id=None):
        xml = request.args.get('format')
        try:
            if role_id is not None:
                data = response_code.NOT_FOUND
                return response_result_process(data, xml=xml)
            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') is not None else ''

            data = role_permission_singleton.add_role(role_name, note_info)
            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 post(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)
         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 = ['role_ids']
         must = req.verify_all_param_must(request_data, fields)
         if must:
             return response_result_process(must, xml=xml)
         par_type = {'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)
         role_ids = str(request_data.get('role_ids'))
         data = user_group_singleton.add_user_group_roles(group_id, role_ids)
         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 verify_version(self, version, xml=None):
     """
     API版本验证
     :param version: 版本信息
     :param xml: 是否是xml
     :return:
     """
     if version == apiVersion.version1.value:
         return True, True
     else:  # 版本信息不存在给的提示
         result = response_code.REQUEST_VERSION_ISEXISTENCE
         return False, response_result_process(result, xml=xml)
Пример #19
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)
    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)
Пример #21
0
    def get(self, version, role_id=None):
        xml = request.args.get('format')
        try:
            if role_id is not None:
                data = response_code.NOT_FOUND
                return response_result_process(data, xml=xml)

            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 = role_permission_singleton.get_all_roles()
            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 = role_permission_singleton.get_pages_roles(
                    current_page, page_size, search_data)

            body = modelEnum.role.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)