示例#1
0
def get_manager_detail(manager_id):
    manager = ManagerMgr.get(manager_id)
    if manager is None:
        return dict(status='error', msg='用户不存在')
    basic = to_dict(manager)
    role_ids = UserRightsRoleMapMgr.get_user_role_ids([manager_id])
    roles = UserRightsRoleMgr.get_roles_by_ids(role_ids)
    proj_rights_list = UserProjRightsMapMgr.get_rights_by_manager_id(
        manager_id)
    company_rights = [
        item.company_id for item in proj_rights_list if item.proj_id == 0
    ]
    proj_rights = [{
        'company_id': item.company_id,
        'proj_id': item.proj_id
    } for item in proj_rights_list if item.proj_id == 0]
    data = {
        'status': 'ok',
        'content': {
            'basic': basic,
            'roles': to_dict(roles),
            'proj_rights': {
                'company_rights': company_rights,
                'proj_rights': proj_rights
            }
        }
    }
    return data
示例#2
0
def calculate(proj_id, date):
    offers = ProjOfferMgr.query({'proj_id': proj_id, 'is_del': 0})
    date_timestamp = time_util.dateString2timestampCommon(date)
    raw_datas = WageRawDataMgr.query({'proj_id': proj_id, 'wage_time': date_timestamp, 'is_del': 0})
    calculated_datas = []
    for offer in offers:
        if offer.position != '所有':
            data = {'offer': to_dict(offer), 'raw_datas': to_dict(raw_datas), 'calculated_datas': []}
            result = execute_plugin('offer', offer.id, 'on_position_calculate', {}, data)
            calculated_datas.extend(result['data']['calculated_datas'])

    wage_maps = {}
    for data in calculated_datas:
        key = '%s_%s_%s' % (data['supplier_id'], data['offer_type'], data['crew_id'])
        if key in wage_maps:
            wage_maps[key]['amount'] += data['amount']
            wage_maps[key]['work_rate'] += data['work_rate']
        else:
            wage_maps[key] = data
    for offer in offers:
        if offer.position == '所有':
            data = {'offer': to_dict(offer), 'wage_datas': wage_maps.values()}
            result = execute_plugin('offer', offer.id, 'on_position_agregate_calculate', {}, data)
            for item in result['data']['wage_datas']:
                WageMgr.create_override_if_exist(item)
示例#3
0
def create_or_update_rich_text(bus_type,
                               bus_id,
                               title,
                               text_type,
                               content,
                               sequence=0,
                               subtitle='',
                               rich_text_id=0):
    if rich_text_id:
        rich_text = RichTextMgr.get(rich_text_id)
        RichTextMgr.update(rich_text,
                           title=title,
                           sequence=sequence,
                           rich_text=content,
                           subtitle=subtitle)
    else:
        sequence = RichTextMgr.get_last_sequence_by_type(
            bus_type, bus_id, text_type) + 1
        rich_text = RichTextMgr.create(bus_type=bus_type,
                                       bus_id=bus_id,
                                       title=title,
                                       text_type=text_type,
                                       sequence=sequence,
                                       rich_text=content,
                                       subtitle=subtitle)
    if bus_type == 'post':
        ProjRecruitPostMgr.modified(bus_id)
    return to_dict(rich_text)
示例#4
0
def __get_plugins_by_proj_id(org_id, proj_id):
    plugins = PluginMgr.query({
        'org_id': org_id,
        'proj_id': proj_id,
        'is_del': 0
    })
    return to_dict(plugins)
示例#5
0
 def list_wage_by_wage_time_desc(proj_id,
                                 crew_id,
                                 offer_type,
                                 start_time,
                                 end_time,
                                 page,
                                 page_size=10):
     """获取结算列表并分页, 根据实际工作时间倒序排列"""
     filter_condition = {
         'is_del': 0,
         'proj_id': proj_id,
         'offer_type': offer_type
     }
     expressions = []
     if 0 < start_time < end_time:
         expressions = [
             WageMgr.model.wage_time > start_time,
             WageMgr.model.wage_time < end_time
         ]
     if crew_id:
         expressions.append(WageMgr.model.crew_id == crew_id)
     count = WageMgr.count(expressions=expressions,
                           filter_conditions=filter_condition)
     if page_size > 5000:
         page_size = 5000
     records = WageMgr.query(expressions=expressions,
                             filter_conditions=filter_condition,
                             limit=page_size,
                             offset=(page - 1) * 10,
                             order_list=[
                                 WageMgr.model.wage_time.desc(),
                                 WageMgr.model.amount.desc()
                             ])
     return {'total_count': count, 'datas': to_dict(records)}
示例#6
0
def get_data_getter():
    try:
        items = DaoRelationMapMgr.query({'is_del': 0})
        return jsonify(status='ok', data=to_dict(items))
    except Exception, ex:
        traceback.print_exc()
        return jsonify(status='error', msg=ex.message)
示例#7
0
 def list_fine_by_occur_time_desc(proj_id,
                                  crew_id,
                                  start_time,
                                  end_time,
                                  page,
                                  page_size=10):
     """获取项目列表并分页, 根据发生时间倒序排列"""
     filter_condition = {'is_del': 0, 'proj_id': proj_id}
     expressions = []
     if 0 < start_time < end_time:
         expressions = [
             FineMgr.model.occur_time > start_time,
             FineMgr.model.occur_time < end_time
         ]
     if crew_id:
         expressions.append(FineMgr.model.crew_id == crew_id)
     count = FineMgr.count(expressions=expressions,
                           filter_conditions=filter_condition)
     if page_size > 5000:
         page_size = 5000
     records = FineMgr.query(expressions=expressions,
                             filter_conditions=filter_condition,
                             limit=page_size,
                             offset=(page - 1) * 10,
                             order_list=[FineMgr.model.occur_time.desc()])
     return {'total_count': count, 'datas': to_dict(records)}
示例#8
0
 def add_newest_points(scale, data):
     """
     赔付发生日期yyyy-mm-dd
     """
     if 'id' in data:
         dataset_id = data['id']
         data_type = data['data_type']
         if data_type == 'billboard':
             points = DwBillboardPointsMgr.query(
                 {
                     'dataset_id': dataset_id,
                     'is_del': 0
                 },
                 limit=scale,
                 order_list=[DwBillboardPointsMgr.model.rank_time.desc()])
         elif data_type == 'chart':
             points = DwChartPointsMgr.query(
                 {
                     'dataset_id': dataset_id,
                     'is_del': 0
                 },
                 limit=scale,
                 order_list=[DwChartPointsMgr.model.x_time.desc()])
         else:
             points = []
         data['points'] = to_dict(points)
示例#9
0
def get_page_result(model,
                    page=1,
                    page_size=10,
                    expressions=list(),
                    order_by_list=list(),
                    filter_func=None):
    result_list, total_page = __do_query(model, page, page_size, expressions,
                                         order_by_list)
    result = []
    for item in result_list:
        if filter_func is None:
            obj = to_dict(item)
        else:
            obj = filter_func(item, {
                'result_list': result_list,
                'cache_data': {}
            })
        result.append(obj)

    data = {
        'status': 'ok',
        'content': {
            'result': result,
            'page': page,
            'total_page': total_page,
        }
    }
    return data
示例#10
0
 def get_proj_post(proj_id):
     """通过项目id获取项目招聘宣传贴"""
     post = ProjRecruitPostMgr.query_first({'proj_id': proj_id})
     if not post:
         post = ProjRecruitPostMgr.create(proj_id=proj_id)
     post = to_dict(post)
     return post
示例#11
0
 def get_dataset_by_title(org_id, proj_id, sampler):
     """通过项目id获取单个项目"""
     dataset = DatasetMgr.query_first({
         'org_id': org_id,
         'proj_id': proj_id,
         'sampler': sampler
     })
     return to_dict(dataset)
示例#12
0
def update_post(post_id, form):
    post = ProjRecruitPostMgr.get(post_id)
    if post is None:
        return dict(status='error', msg='招聘贴不存在')
    ProjRecruitPostMgr.update(post, **form)
    # 新增操作记录
    __add_proj_op_log(web_util.get_operator_id(), post.id,
                      proj_constant.PROJ_OP_TYPE_UPDATE, "更改招聘贴信息", 0, 0)
    return dict(status='ok', data=to_dict(post))
示例#13
0
def get_apply_records(proj_id, page, filters):
    filter_condition = {'proj_id': proj_id, 'is_del': 0}
    expressions = []
    search_key = filters['searchKey'] if 'searchKey' in filters else None
    if search_key:
        crew_expression = [
            or_(CrewMgr.model.crew_name == search_key,
                CrewMgr.model.phone == search_key,
                CrewMgr.model.id_card_num == search_key,
                CrewMgr.model.crew_account == search_key)
        ]
        search_crews = CrewMgr.query({'is_del': 0},
                                     expressions=crew_expression)
        search_crew_ids = [item.id for item in search_crews]
        expressions.append(CrewProjMapMgr.model.crew_id.in_(search_crew_ids))
    if 'crew_id' in filters and filters['crew_id']:
        expressions.append(CrewProjMapMgr.model.crew_id == filters['crew_id'])
    if 'entry_status' in filters:
        expressions.append(
            CrewProjMapMgr.model.entry_status == filters['entry_status'])
    count = CrewProjMapMgr.count(expressions=expressions,
                                 filter_conditions=filter_condition)
    if page != 0:
        records = CrewProjMapMgr.query(
            expressions=expressions,
            filter_conditions=filter_condition,
            limit=10,
            offset=(page - 1) * 10,
            order_list=[CrewProjMapMgr.model.create_time.desc()])
    else:
        if count > 5000:  # 数据量过大保护
            records = CrewProjMapMgr.query(
                expressions=expressions,
                filter_conditions=filter_condition,
                limit=5000,
                order_list=[CrewProjMapMgr.model.create_time.desc()])
        else:
            records = CrewProjMapMgr.query(expressions=expressions,
                                           filter_conditions=filter_condition)
    data = {'proj_id': proj_id, 'count': count, 'records': records}
    for record in data['records']:
        crew = CrewMgr.get(record.crew_id)
        if not crew:
            continue
        crew = to_dict(crew)
        crew['create_time'] = time_util.timestamp2dateString(
            crew['create_time'])
        crew['start_time'] = time_util.timestamp2dateString(
            record.start_time) if record.start_time else '待定'
        crew['entry_status'] = CrewProjMapMgr.translate_entry_status(
            record.entry_status)
        crew['age'] = GetInformation(crew['id_card_num']).get_age()
        crew['gender'] = GetInformation(crew['id_card_num']).get_gender_text()
        crew['apply_id'] = record.id
        data['result'].append(crew)
    data['result'] = json.dumps(data['result'])
    return data['result']
示例#14
0
def create_offer(form):

    proj_id = get_request_proj_id()
    offer = ProjOfferMgr.create(proj_id=proj_id, **form)

    # 新增操作记录
    __add_proj_op_log(web_util.get_operator_id(), offer.id,
                      proj_constant.PROJ_OP_TYPE_CREATE, "新建一个报价单", 0, 0)
    return dict(status='ok', data=to_dict(offer))
示例#15
0
def update_offer(offer_id, form):
    offer = ProjOfferMgr.get(offer_id)
    if offer is None:
        return dict(status='error', msg='报价单不存在')
    ProjOfferMgr.update(offer, **form)
    # 新增操作记录
    __add_proj_op_log(web_util.get_operator_id(), offer.id,
                      proj_constant.PROJ_OP_TYPE_UPDATE, "更改报价单信息", 0, 0)
    return dict(status='ok', data=to_dict(offer))
示例#16
0
 def list_supplier(org_id, page, page_size=10):
     """获取供应商列表并分页,"""
     filter_condition = {'is_del': 0, 'org_id': org_id}
     count = SupplierMgr.count(filter_conditions=filter_condition)
     if page_size > 5000:
         page_size = 5000
     records = SupplierMgr.query(filter_conditions=filter_condition,
                                 limit=page_size,
                                 offset=(page - 1) * 10)
     return {'total_count': count, 'datas': to_dict(records)}
示例#17
0
def update_proj(proj_id, form):
    proj = ProjMgr.get(proj_id)
    if proj is None:
        return dict(status='error', msg='无效的项目编号')
    ProjMgr.update(proj, **form)
    # 新增操作记录
    __add_proj_op_log(web_util.get_operator_id(), proj.id,
                      proj_constant.PROJ_OP_TYPE_UPDATE, "更改项目信息",
                      proj.proj_status, proj.proj_status)
    return dict(status='ok', data=to_dict(proj))
示例#18
0
def create_proj(form):

    org_id = get_request_org_id()
    proj = ProjMgr.create(org_id=org_id, **form)

    # 新增操作记录
    __add_proj_op_log(web_util.get_operator_id(), proj.id,
                      proj_constant.PROJ_OP_TYPE_CREATE, "新建一个项目",
                      proj.proj_status, proj.proj_status)
    return dict(status='ok', data=to_dict(proj))
示例#19
0
def create_supplier(form):

    org_id = get_request_org_id()
    name = form['supplier_name']
    supplier = SupplierMgr.query_first({'supplier_name': name})
    if supplier:
        if supplier.is_del == 1:
            SupplierMgr.restore(supplier)
    else:
        supplier = SupplierMgr.create(org_id=org_id, supplier_name=name)
    return dict(status='ok', data=to_dict(supplier))
示例#20
0
def get_rights_role_detail(role_id):
    role = UserRightsRoleMgr.get(role_id)
    if not role:
        return dict(status='error', msg='角色不存在')

    resource_ids = UserRoleRightsResourceMapMgr.get_resource_ids_by_role_ids(
        [role_id])
    if len(resource_ids) == 0:
        rights_resource = []
    else:
        rights_resource = to_dict(
            UserRightsResourceMgr.get_resource_by_ids(resource_ids))
    data = {
        'status': 'ok',
        'content': {
            'basic': to_dict(role),
            'rights_resource': rights_resource
        }
    }
    return data
示例#21
0
 def list_proj(org_id, page, page_size=10):
     """获取项目列表并分页"""
     filter_condition = {'is_del': 0, 'org_id': org_id}
     count = ProjMgr.count(filter_conditions=filter_condition)
     if page_size > 5000:
         page_size = 5000
     records = ProjMgr.query(filter_conditions=filter_condition,
                             limit=page_size,
                             offset=(page - 1) * page_size,
                             order_list=[ProjMgr.model.create_time.desc()])
     return {'total_count': count, 'datas': to_dict(records)}
示例#22
0
 def add_offer_plugins(data):
     """
     获取工资规则插件
     """
     if 'id' in data:
         plugins = PluginMgr.query({
             'bus_type': 'offer',
             'bus_id': data['id'],
             'is_del': 0
         })
         data['plugins'] = to_dict(plugins)
示例#23
0
def update_fe_configure():
    try:
        proj_id = get_request_proj_id()
        page_url = request.form.get("page_url")
        gear_id = request.form.get('gear_id')
        props = request.form.get('props')
        props_format = request.form.get('props_format')
        config = FeConfigureMgr.create_or_update(proj_id, page_url, gear_id,
                                                 props, props_format)
        return jsonify(status='ok', data=to_dict(config))
    except Exception, ex:
        traceback.print_exc()
        return jsonify(status='error', msg=ex.message)
示例#24
0
def update_proj_plugin(params):
    plugin = PluginMgr.query_first(
        filter_conditions={
            'module_type': params['module_type'],
            'module_id': params['module_id'],
            'plugin_id': params['plugin_id'],
            'is_del': 0
        })
    if plugin:
        PluginMgr.update(plugin, props=params['props'])
    else:
        plugin = PluginMgr.create(**params)
    return to_dict(plugin)
示例#25
0
 def list_crew_by_create_time_desc(proj_id, search_key, page, page_size=10):
     """获取员工列表并分页, 根据发生时间倒序排列"""
     filter_condition = {'is_del': 0}
     if proj_id:
         filter_condition['proj_id'] = proj_id
     expressions = []
     if search_key:
         expressions = [or_(CrewMgr.model.crew_name == search_key, CrewMgr.model.phone == search_key,
                            CrewMgr.model.id_card_num == search_key, CrewMgr.model.crew_account == search_key)]
     count = CrewMgr.count(expressions=expressions, filter_conditions=filter_condition)
     if page_size > 5000:  # 数据量过大保护
         page_size = 5000
     records = CrewMgr.query(expressions=expressions, filter_conditions=filter_condition, limit=page_size,
                             offset=page_size*(page-1), order_list=[CrewMgr.model.create_time.desc()])
     return {'total_count': count, 'datas': to_dict(records)}
示例#26
0
 def add_recruit_post_details(id, data):
     """
     获取项目招工贴中的招工详情介绍,为富文本+图片集的形式
     """
     rich_text_list = RichTextMgr.get_richtext_by_type(
         'post', id, 'proj_recruit_detail')
     result = []
     for item in rich_text_list:
         rich_text = to_dict(item)
         intro_pic_list = PicMgr.get_img_by_type('post', id, item.title)
         rich_text['pic_list'] = []
         for pic in intro_pic_list:
             rich_text['pic_list'].append({'url': pic.url, 'id': pic.id})
         result.append(rich_text)
     data['recruit_post_details'] = result
示例#27
0
 def list_proj_offers(proj_id, offer_type, page, page_size=10):
     """获取项目列表并分页"""
     filter_condition = {
         'is_del': 0,
         'proj_id': proj_id,
         'offer_type': offer_type
     }
     count = ProjOfferMgr.count(filter_conditions=filter_condition)
     if page_size > 5000:
         page_size = 5000
     records = ProjOfferMgr.query(
         filter_conditions=filter_condition,
         limit=page_size,
         offset=(page - 1) * page_size,
         order_list=[ProjOfferMgr.model.start_time.desc()])
     return {'total_count': count, 'datas': to_dict(records)}
示例#28
0
 def list_posts_by_org(org_id, page, page_size=10):
     """获取单个公司所有项目招聘宣传贴"""
     proj_ids = ProjMgr.get_proj_ids_by_org(org_id)
     filter_condition = {'is_del': 0}
     expressions = [ProjRecruitPostMgr.model.proj_id.in_(proj_ids)]
     count = ProjRecruitPostMgr.count(filter_conditions=filter_condition,
                                      expressions=expressions)
     if page_size > 5000:
         page_size = 5000
     records = ProjRecruitPostMgr.query(
         filter_conditions=filter_condition,
         expressions=expressions,
         limit=page_size,
         offset=(page - 1) * page_size,
         order_list=[ProjRecruitPostMgr.model.modify_time.desc()])
     return {'total_count': count, 'datas': to_dict(records)}
示例#29
0
 def add_plugins(supplier_id, offer_type, position, data):
     """
     工作数据产生日期yyyy-mm-dd
     """
     offer = ProjOfferMgr.query_first({
         'supplier_id': supplier_id,
         'offer_type': offer_type,
         'position': position,
         'is_del': 0
     })
     if offer:
         plugins = PluginMgr.query({
             'bus_type': 'offer',
             'bus_id': offer.id,
             'is_del': 0
         })
         data['plugins'] = to_dict(plugins)
示例#30
0
def get_rights_tree():
    resources = UserRightsResourceMgr.query(filter_conditions={'is_del': 0})
    group = [resource.id for resource in resources if resource.parent_id == 0]
    group_child_map = dict()
    for group_id in group:
        group_child_map[group_id] = [resource.id for resource in resources if resource.parent_id == group_id]
    detail = [{resource.id: to_dict(resource)} for resource in resources]

    data = {
        'status': 'ok',
        'content': {
            'group': group,
            'group_child_map': group_child_map,
            'detail': detail
        }
    }
    return data