Example #1
0
def recommend_engineer(request):
    if request.method=='GET':
        area_id = int(request.GET.get('area_id',1))
        accountname = request.GET.get('accountname')
        
        order = Order()
        order.creator = request.user.username
        order.accountname = accountname
        
        dd = {}
        
        staff = executive_helper(order)
        
        if staff:
            # 优先级 1:'紧急',2:'普通'
            dd['priority_level'] = 1
        else:
            staff = designate_engineer(area_id)
            dd['priority_level'] = 2
        
        comment = ''
        if staff:
            comment = u"系统推荐:" + staff.area.name + ' ' + staff.realname
            dd['comment'] = comment
            dd['id'] = staff.id
            dd['area_id'] = staff.area.id
        else:
            comment = u"此区域没有对应的IT工程师"
            dd['comment'] = comment
            
        return HttpResponse(json.dumps(dd))
    else:
        return  HttpResponseBadRequest(u"错误请求")
Example #2
0
def add(request):
    # 一级问题类目
    first_level_problem_list = ProblemType.objects.filter(level=1, is_available=1)
    # 区域
    area_list = Area.objects.all()
    
    if request.POST:
        # 1) 保存工单记录
        order = Order()
        # 创建时间
        order.create_time = datetime.datetime.now()
        # creator
        order.creator = request.user.username
        # 故障申报人姓名
        order.realname = request.POST.get('realname')
        # 账户名(故障申报人) 
        order.accountname = request.POST.get('accountname')
        # 部门
        order.department = request.POST.get('department')
        # 电子邮件
        order.email = request.POST.get('email')
        # 电话
        order.phone = request.POST.get('phone')
        # 所属区域
        order.area_id = int(request.POST.get('area_id'))
        # 故障类目(三级)
        order.problem_type_third = int(request.POST.get('third_level_problem'))
        # 故障描述
        order.problem_desc = request.POST.get('problem_desc')
        # 优先级 1:优先 2:普通
        order.priority_level = int(request.POST.get('priority_level',2))
        # 状态 1.已接受
        order.status = 2
        # 工单编号 
        order.case_number = genCaseID()
        # 工位
        order.workseat = request.POST.get('workseat')
        
        # IT工程师ID
        deal_engineer_id = request.POST.get('deal_engineer_id',None)
        
        # 来源
        # 话务员
        if 'order_feedback' in request.session["authority_set"]:
            order.source = 1   # 电话
        else:
            order.source = 2   # 网络 
            
        # 校验下申报人是否合法
        res_list = search_user(order.accountname, True)
        #print res_list
        if res_list == None or len(res_list) > 1:
            return HttpResponse(simplejson.dumps({"statusCode":400, "message":u'申报人不是合法用户!'}), mimetype='application/json')
        
        # 人工指派
        if deal_engineer_id:
            staff = Staff.objects.get(id=deal_engineer_id)
            
        # 系统指派 又分为两种 1) 高管 2) 非高管
        else:
            staff = executive_helper(order)
            if staff:
                # 1:'优先',2:'普通'
                order.priority_level = 1
            else:
                staff = designate_engineer(order.area_id)
            
        # 处理人的账户名称
        order.dealer_accountname = staff.accountname
        # 处理人的用户名
        order.dealer_realname = staff.realname
        
        # 工单处理结果的默认评级
        order.feedback_rate = 5
        
        order.save()
        
        # 2) 流转记录
        wander = Wander()
        wander.create_time = datetime.datetime.now()
        wander.source_name = order.realname
        wander.target_name = order.dealer_realname
        wander.operation = 1
        wander.order = order
        wander.save()
        
        # 3) 短信邮件通知
        # 邮件发送给申报人
        distribute_customer.delay(order)
        
        # 邮件发送给工程师
        distribute_engineer.delay(order)
        
        # 短信发送给工程师
        sms_notify.delay(order)
        
        return HttpResponse(simplejson.dumps({"statusCode":200,"url": "/order/in_hand", "message":u'工单提交成功'}), mimetype='application/json')
    return render_to_response('order/add.html',{'area_list':area_list, 'priority_dict':priority_dict, 
        'user':request.user,'first_level_problem_list':first_level_problem_list,'auth_set':request.session["authority_set"]})