def before_update(self, request, kwargs): receiver_id = request.data.get('receiver', None) project_id = request.data.get('project', None) if project_id is None: raise Exception('项目 id 不能为空!') if receiver_id is not None: task_id = str(kwargs['pk']) task = Task.objects.get(id=task_id) # 如果当前任务已经存在负责人 if task.receiver: if receiver_id != task.receiver.id: if task.receive_status.id == TaskStatus.objects.get( key='accepted').id: BusinessPublic.create_message( task.sender.id, task.receiver.id, menu_id=2, messages='该任务已被项目负责人移走了!') request.data['is_published'] = 0 request.data[ 'receive_status'] = BusinessPublic.GetTaskStatusIdByKey( 'assigned') else: request.data[ 'receive_status'] = BusinessPublic.GetTaskStatusIdByKey( 'assigned') else: request.data[ 'receive_status'] = BusinessPublic.GetTaskStatusIdByKey( 'unassigned')
def update_project(self, project_id): if project_id is not None: project = Project.objects.get(id=project_id) if project: # 验收成功 project.receive_status = BusinessPublic.GetProjectStatusObjectByKey('checked') project.save() # 商务人员以及项目经理积分及米值分配 projectpoints = ProjectPoints.objects.filter(project_id=project_id, task__isnull=True, is_created=0) if projectpoints: for projectpoint in projectpoints: if projectpoint: self.create_user_points(None, projectpoint.user.id, projectpoint.points, 1, 1, projectpoint.type) project_points = ProjectPoints.objects.get(id=projectpoint.id) project_points.is_created = 1 project_points.save() # 任务负责人积分及米值分配 taskpoints = Task.objects.filter(project_id=project_id, is_active=1) if taskpoints: for taskpoint in taskpoints: if taskpoint: self.create_user_points(taskpoint.task.id, taskpoint.receiver.id, taskpoint.points, 1, 1, 1) BusinessPublic.create_message(project.auditor_id, project.receiver_id, menu_id=2, messages='恭喜,你的项目已验收通过!')
def update_project(self, project_id): project = Project.objects.get(id=project_id) if project: # 项目负责人已接手,项目正式开始 project.receive_status = BusinessPublic.GetProjectStatusObjectByKey('accepted') project.save() BusinessPublic.create_message(project.receiver_id, project.sender_id, menu_id=2, messages='项目负责人已接手!')
def after_update(self, request, serializer): # 富文本内容 content = request.data.get('content', None) # 文件 files = request.data.get('files', None) # 新增任务上传文件日志 BusinessPublic.create_task_file_texts(serializer.data['id'], files, content)
def update_project(self, project_id): if project_id is not None: project = Project.objects.get(id=project_id) if project: # 验收提交 project.receive_status = BusinessPublic.GetProjectStatusObjectByKey('wait_check') project.save() BusinessPublic.create_message(project.receiver.id, project.auditor.id, menu_id=2, messages='该项目已完成,等待你的验收,请尽快处理!')
def destroy(self, request, *args, **kwargs): instance = self.get_object() instance.is_active = 0 instance.save() # self.perform_destroy(instance) project_id = instance.project_id BusinessPublic.update_progress_by_project_id(project_id) return Response(status=status.HTTP_204_NO_CONTENT)
def before_create(self, request): # 将当前登录用户作为项目创建人 request.data['sender'] = request.user.id receiver_id = request.data.get('receiver', None) # 如果存在项目负责人,则将项目接收状态置为 '待接手' if receiver_id is not None: BusinessPublic.create_message(request.user.id, receiver_id, menu_id=2, messages='你有新的项目等待接手!') request.data['receive_status'] = ProjectStatus.objects.get(key='wait_accept').id # 如果不存在项目负责人,则将项目接手状态置为 '未指派项目负责人' else: request.data['receive_status'] = ProjectStatus.objects.get(key='unassigned').id
def update_task(self, task_id): if task_id is not None: from business.models.task import Task task = Task.objects.get(id=task_id) if task is not None: task.receive_status = BusinessPublic.GetTaskStatusObjectByKey( 'wait_check') task.save() BusinessPublic.create_message(task.receiver.id, task.sender.id, menu_id=2, messages='有新的任务需要你的验收,请尽快处理!')
def update_project(self, project_id, reason): project = Project.objects.get(id=project_id) if project: # 驳回 project.audit_status = 3 project.save() BusinessPublic.create_reason(project.id, project.auditor.id, project.sender.id, BusinessPublic.GetReasonTypeIdByKey('project_audit_reject'), reason) BusinessPublic.create_message(project.auditor.id, project.sender.id, menu_id=2, messages='你的项目已被驳回,请尽快处理!')
def update_task(self, task_id): if task_id is not None: from business.models.task import Task task = Task.objects.get(id=task_id) if task is not None: # 任务负责人已拒接手 task.receive_status = BusinessPublic.GetTaskStatusObjectByKey( 'rejected') task.save() BusinessPublic.create_message(task.receiver.id, task.sender.id, menu_id=2, messages='任务负责人已拒接!')
def post(self, request, format=None): try: project_id = request.data.get('project_id') auditor_id = request.data.get('auditor_id') if project_id is not None and auditor_id is not None: self.update_project(project_id, auditor_id) user_id = request.user.id BusinessPublic.create_message(user_id, auditor_id, menu_id=2, messages='有新的项目需要你的审核,请尽快处理!') except Exception as e: return MykeyResponse(status=status.HTTP_400_BAD_REQUEST, msg='请求失败') return MykeyResponse(status=status.HTTP_200_OK, msg='请求成功')
def update_project(self, project_ids): if len(project_ids) > 0: for project_id in project_ids: project = Project.objects.get(id=project_id) if project.receiver is None: raise Exception('未填写项目负责人!') # 已审核 project.audit_status = 2 project.save() BusinessPublic.create_message( project.auditor.id, project.receiver.id, menu_id=2, messages='项目已通过审核!' )
def after_create(self, request, serializer): project_id = request.data.get('project', None) project = Project.objects.get(id=project_id) # 富文本内容 content = request.data.get('content', None) # 文件 files = request.data.get('files', None) # - 更新相关项目信息 self.update_project(project) # - 新增任务上传文件日志 BusinessPublic.create_task_file_texts(serializer.data['id'], files, content)
def update_task(self, request, task_id, task_design_type_id): if task_id is not None and task_design_type_id is not None: task = Task.objects.get(id=task_id) if task is not None: # 任务负责人已接手,任务执行中 task.receive_status = TaskStatus.objects.get(key='accepted') if task.receiver is None: task.receiver = request.user task.task_design_type = TaskDesignType.objects.get( id=task_design_type_id) task.save() self.create_step(task_id, task_design_type_id, request.user) BusinessPublic.create_message(task.receiver.id, task.sender.id, menu_id=2, messages='任务负责人已接手,任务执行中!')
def update_task(self, task_id): if task_id is not None: task = Task.objects.filter(id=task_id, is_published=0).first() if task: task.is_published = 1 task.publish_time = datetime.datetime.now().strftime( '%Y-%m-%d %H:%M:%S') task.receive_status = BusinessPublic.GetTaskStatusObjectByKey( 'wait_accept') task.save() if task.receiver: # 新增消息 BusinessPublic.create_message(task.sender.id, task.receiver.id, menu_id=2, messages='已安排新的任务,请查看!')
def get_task_manager_cost(self, project_id): """ 计算所有任务负责人平均工资 """ if project_id is not None: duration = 0 project = Project.objects.get(id=project_id) if project is not None: duration = BusinessPublic.Caltime(project.end_time, project.begin_time) from business.models.task import Task tasks = Task.objects.filter(project_id=project_id, is_active=1) all_total_fee = 0 salary = 0 for task in tasks: if task: if task.receiver: receiver_id = task.receiver.id user = UserProfile.objects.get(id=receiver_id) if user: salary = user.base_salary else: task_type = TaskType.objects.get(id=task.task_type.id) salary = task_type.average_salary aveage_fee = salary / 21.75 aveage_fee = round(aveage_fee, 2) total_fee = duration * aveage_fee total_fee = round(total_fee, 2) salary_obj = {} salary_obj["person_nums"] = 1 if task.receiver: salary_obj["user"] = task.receiver.name else: salary_obj["user"] = '' salary_obj["duration"] = duration salary_obj["name"] = '平均工资' salary_obj["fee"] = int(aveage_fee) salary_obj["total_fee"] = int(total_fee) salary_obj["task"] = {} salary_obj["type"] = 1 salary_obj["role"] = "任务负责人" list_project_person_objects.append(salary_obj) all_total_fee = all_total_fee + int(total_fee) return all_total_fee
def update_task(self, task_id, assessment_id, comments): if task_id is not None: if assessment_id is not None and comments is not None: assessment = TaskAssessment.objects.get(id=assessment_id) task = Task.objects.get(id=task_id) if task is not None: # 任务已通过验收 task.receive_status = BusinessPublic.GetTaskStatusObjectByKey( 'checked') task.task_assessment = assessment task.comments = comments task.save() project_id = task.project_id BusinessPublic.update_progress_by_project_id(project_id) BusinessPublic.create_message(task.sender.id, task.receiver.id, menu_id=2, messages='任务已通过验收!')
def update_task(self, request, task_ids, receiver_id): if len(task_ids) > 0: for task_id in task_ids: from business.models.task import Task task = Task.objects.get(id=task_id) if task is not None: old_receiver_id = task.receiver.id receiver = UserProfile.objects.get(id=receiver_id) task.receiver = receiver task.superior_id = request.user.id task.receive_status = BusinessPublic.GetTaskStatusObjectByKey( 'wait_accept') task.save() if old_receiver_id != receiver_id: # 转移积分 ProjectPoints.objects.filter( user_id=task.receiver.id, is_created=0, project_id=task.project.id).update( user_id=receiver_id) BusinessPublic.create_message(task.superior.id, task.receiver.id, menu_id=2, messages='已安排新的任务,请查看!')
def before_create(self, request): # 任务创建人 request.data['sender'] = request.user.id # 上级主管 request.data['superior'] = request.user.id # 获取该任务所属的项目 id project_id = request.data.get('project', None) if project_id is None: raise Exception('项目 id 不能为空!') project = Project.objects.get(id=project_id) # 将项目负责人作为该任务的审核员 if project.receiver_id is not None: request.data['auditor'] = project.receiver_id if request.data.get('receiver', None): request.data[ 'receive_status'] = BusinessPublic.GetTaskStatusIdByKey( 'assigned') else: request.data[ 'receive_status'] = BusinessPublic.GetTaskStatusIdByKey( 'unassigned')
def update_project(self, project_id, reason): project = Project.objects.get(id=project_id) if project is not None: # 拒接 project.receive_status = BusinessPublic.GetProjectStatusObjectByKey('rejected') project.save() reason_type_id = BusinessPublic.GetReasonTypeIdByKey('project_reject') BusinessPublic.create_reason(project.id, project.receiver.id, project.sender.id, reason_type_id, reason) BusinessPublic.create_message(project.receiver.id, project.sender.id, menu_id=2, messages='项目负责人拒接了你的项目,请尽快处理!')
def update_project(self, project_id, reason): if project_id is not None: project = Project.objects.get(id=project_id) if project: # 验收不通过 project.receive_status = BusinessPublic.GetProjectStatusObjectByKey('check_rejected') project.save() BusinessPublic.create_reason(project.id, project.receiver.id, project.auditor.id, BusinessPublic.GetReasonTypeIdByKey('project_check_reject'), reason) BusinessPublic.create_message(project.receiver.id, project.auditor.id, menu_id=2, messages='你的项目验收不通过,请尽快检查!')
def get_projectfee_cost(self, project_id): if project_id is not None: project = Project.objects.get(id=project_id) if project: duration = BusinessPublic.Caltime(project.end_time, project.begin_time) all_total_fee = 0 tasks = Task.objects.filter(project_id=project_id, is_active=1) if tasks: # 项目总人数 = 任务总人数 + 项目负责人 + 商务人员 project_person_nums = tasks.count() + 2 # 公司总人数 users = UserProfile.objects.filter(base_salary__gt=0) if users: company_person_nums = users.count() fees = ProjectFee.objects.filter(project_id=project.id) if fees: for fee in fees: aveage_fee = fee.value / company_person_nums aveage_fee = aveage_fee / 30 aveage_fee = round(aveage_fee, 2) total_fee = aveage_fee * project_person_nums * duration total_fee = round(total_fee, 2) fee_obj = {} fee_obj["id"] = '' fee_obj["person_nums"] = project_person_nums fee_obj["duration"] = duration fee_obj["name"] = fee.name fee_obj["fee"] = int(aveage_fee) fee_obj["total_fee"] = int(total_fee) fee_obj["type"] = 1 list_project_fee_objects.append(fee_obj) all_total_fee = all_total_fee + int(total_fee) return all_total_fee
def update_task(self, task_id, reason): if task_id is not None: from business.models.task import Task task = Task.objects.get(id=task_id) if task is not None: # 任务验收不通过 task.receive_status = BusinessPublic.GetTaskStatusObjectByKey( 'check_rejected') task.save() BusinessPublic.create_reason( task.id, task.receiver.id, task.sender.id, BusinessPublic.GetReasonTypeIdByKey('task_check_reject'), reason) BusinessPublic.create_message(task.receiver.id, task.sender.id, menu_id=2, messages='任务验收不通过')
def get_market_manager_cost(self, project_id): """ 计算商务人员平均工资 """ if project_id is not None: project = Project.objects.get(id=project_id) if project is not None: if project.sender: duration = BusinessPublic.Caltime(project.end_time, project.begin_time) sender_id = project.sender.id user = UserProfile.objects.get(id=sender_id) if user: salary = user.base_salary aveage_fee = salary / 21.75 aveage_fee = round(aveage_fee, 2) total_fee = duration * aveage_fee total_fee = round(total_fee, 2) salary_obj = {} salary_obj["person_nums"] = 1 salary_obj["user"] = user.name salary_obj["duration"] = duration salary_obj["name"] = '平均工资' salary_obj["fee"] = int(aveage_fee) salary_obj["total_fee"] = int(total_fee) salary_obj["project"] = {} salary_obj["type"] = 0 salary_obj["role"] = "商务人员" list_project_person_objects.append(salary_obj) return int(total_fee)
def before_update(self, request, kwargs): project_id = str(kwargs['pk']) receiver_id = request.data.get('receiver', None) if receiver_id is not None and receiver_id != '': if project_id is not None: project = Project.objects.get(id=project_id) if project.receiver: # 如果是驳回状态,需要重新发送消息 if receiver_id == str(project.receiver.id) and project.receive_status.id == 5: # 新增消息 BusinessPublic.create_message(request.user.id, receiver_id, menu_id=2, messages='你有新的项目等待接手!') elif receiver_id != str(project.receiver.id): # 新增消息 BusinessPublic.create_message(request.user.id, receiver_id, menu_id=2, messages='你有新的项目等待接手!') else: BusinessPublic.create_message(request.user.id, receiver_id, menu_id=2, messages='你有新的项目等待接手!') request.data['receive_status'] = ProjectStatus.objects.get(key='wait_accept').id else: request.data['receive_status'] = ProjectStatus.objects.get(key='unassigned').id
def import_excel_data(cls, project_id, file_name): obj = {} DataList = [] try: with xlrd.open_workbook(file_name) as data: table = data.sheet_by_index(0) # 获取工作表 project_receiver_id = 0 n = 1 x = y = z = 0 WorkList = [] # nrows = table.nrows # 行数 ncols = table.ncols # 列数 print sh.row_values(rownum) for line in range(n, table.nrows): n = n + 1 row = table.row_values(line) # 查看行值是否为空 if row: # 判断该行值是否在数据库中重复 if Task.objects.filter(name=row[0].strip(), project_id=project_id, is_active=1).exists(): x = x + 1 # 重复值计数 dict_obj = {} dict_obj["info"] = '第' + str(n) + '行,第1列任务名称重复' DataList.append(dict_obj) z = z + 1 continue else: if not TaskType.objects.filter( name=row[1].strip()).exists(): dict_obj = {} dict_obj["info"] = '第' + str( n) + '行,第2列任务类型不存在' DataList.append(dict_obj) z = z + 1 continue if not TaskPriority.objects.filter( name=row[3].strip()).exists(): dict_obj = {} dict_obj["info"] = '第' + str( n) + '行,第4列任务优先级不存在' DataList.append(dict_obj) z = z + 1 continue if not TaskQuality.objects.filter( name=row[4].strip()).exists(): dict_obj = {} dict_obj["info"] = '第' + str( n) + '行,第5列任务品质要求不存在' DataList.append(dict_obj) z = z + 1 continue if not UserProfile.objects.filter( name=row[7].strip()).exists( ) and row[7].strip() != '': dict_obj = {} dict_obj["info"] = '第' + str( n) + '行,第8列任务负责人不存在' DataList.append(dict_obj) z = z + 1 continue if not cls.isVaildDate(row[5], data): dict_obj = {} dict_obj["info"] = '第' + str( n) + '行,第6列时间格式不正确' DataList.append(dict_obj) z = z + 1 continue if not cls.isVaildDate(row[6], data): dict_obj = {} dict_obj["info"] = '第' + str( n) + '行,第7列时间格式不正确' DataList.append(dict_obj) z = z + 1 continue if row[7].strip() != '': task_type = TaskType.objects.get( name=row[1].strip()) receiver = UserProfile.objects.get( name=row[7].strip()) user_skill_ids = cls.get_user_skills( receiver.id) if task_type.id not in user_skill_ids: dict_obj = {} dict_obj["info"] = '第' + str( n) + '行,第2列的技能不在任务负责人的技能列表' DataList.append(dict_obj) z = z + 1 continue if project_id is not None: # 根据项目 id 查项目负责人 project = Project.objects.get(id=project_id) project_receiver_id = project.receiver_id # 如果项目状态为已完成,则当创建任务时,需要将项目状态改为已接手 if project.receive_status.key == 'finished': project.receive_status_id = BusinessPublic.GetProjectStatusIdByKey( 'accepted') project.save() # 如果创建任务时指定了任务负责人,则任务接收状态为 1 - 已安排任务负责人 auditor = None if row[7].strip() != '': if project_id is not None: # 根据项目 id 查项目审核状态 project = Project.objects.get( id=project_id) if project.audit_status == 2: receive_status = BusinessPublic.GetTaskStatusObjectByKey( 'wait_accept') else: receive_status = BusinessPublic.GetTaskStatusObjectByKey( 'assigned') else: receive_status = BusinessPublic.GetTaskStatusObjectByKey( 'assigned') # 如果创建任务时未指定任务负责人,则任务接收状态为 0 - 未安排任务负责人 else: receive_status = BusinessPublic.GetTaskStatusObjectByKey( 'unassigned') # 如果存在项目负责人则将该项目负责人作为任务审核员 if project_receiver_id is not None: auditor = UserProfile.objects.get( id=project_receiver_id) project = Project.objects.get(id=project_id) task_type = TaskType.objects.get( name=row[1].strip()) task_priority = TaskPriority.objects.get( name=row[3].strip()) task_quality = TaskQuality.objects.get( name=row[4].strip()) receiver = None if row[7].strip() != '': receiver = UserProfile.objects.get( name=row[7].strip()) sender = None if project_receiver_id: sender = UserProfile.objects.get( id=project_receiver_id) WorkList.append( Task( project=project, name=row[0].strip(), task_type=task_type, content=row[2].strip(), task_priority=task_priority, task_quality=task_quality, begin_time=cls.getDate(row[5], data), end_time=cls.getDate(row[6], data), receiver=receiver, memo=row[8].strip(), sender=sender, auditor=auditor, receive_status=receive_status, superior=sender, )) y = y + 1 # 非重复计数 else: # 空行 z = z + 1 dict_obj = {} dict_obj["info"] = '第' + str(n) + '行为空行' DataList.append(dict_obj) if (n - 1) % 2 == 0: Task.objects.bulk_create(WorkList) WorkList = [] if len(WorkList) > 0: Task.objects.bulk_create(WorkList) obj["success"] = y obj["fail"] = z obj['infos'] = DataList except Exception as e: dict_obj = {} dict_obj["info"] = '数据异常' DataList.append(dict_obj) obj['infos'] = DataList obj["success"] = 0 return obj return obj
def update_project_progress(self, project_id): # 更新项目进度 BusinessPublic.update_progress_by_project_id(project_id)
def update_project_status(self, project): # 如果项目状态为已完成,则当创建任务时,需要将项目状态调整为已接手 if project.receive_status.key == 'finished': project.receive_status_id = BusinessPublic.GetProjectStatusIdByKey( 'accepted') project.save()
def get(self, request, format=None): user_id = request.user.id user_role_list = self.get_user_roles(user_id) users = UserProfile.objects.filter(superior_id=user_id) users = self.filter_user(request, users) sign = True if '项目负责人' in user_role_list: sign = True elif '任务负责人' in user_role_list: sign = False list_objects = [] if sign: for user in users: user_obj = {} user_obj["id"] = user.id user_obj["name"] = user.name list_objects.append(user_obj) else: for user in users: # tasks = Task.objects.filter(receiver_id=user.id, is_active=1, receive_status__lte=3) tasks = Task.objects.filter( ~Q(receive_status=BusinessPublic.GetTaskStatusIdByKey( 'checked')), receiver_id=user.id, is_active=1) if len(tasks) > 0: for task in tasks: if task is not None: dict_obj1 = {} dict_obj1["user_id"] = user.id dict_obj1["name"] = user.name dict_obj1["task_type"] = task.task_type.name dict_obj1["task_progress"] = task.progress dict_obj1["task_name"] = task.name dict_obj1["end_time"] = task.end_time dict_obj1["leftdays"] = ( task.end_time - datetime.datetime.now().date()).days + 1 dict_obj1[ "receive_status"] = task.receive_status.text list_objects.append(dict_obj1) else: dict_obj2 = {} dict_obj2["user_id"] = user.id dict_obj2["name"] = user.name dict_obj2["task_type"] = '' dict_obj2["task_progress"] = '' dict_obj2["task_name"] = '' dict_obj2["end_time"] = '' dict_obj2["leftdays"] = '' dict_obj2["receive_status"] = '' list_objects.append(dict_obj2) return MykeyResponse(status=status.HTTP_200_OK, msg='请求成功', data=list_objects)