1. 程式人生 > >django報障系統之解決工單和報表

django報障系統之解決工單和報表

django

前面實現了用戶的角色管理、權限管理、故障管理。下面學習下解決故障

  • 當有權限的用戶登錄後,可以看到自己創建的單子,或者自己已經接了單子和解決完成的單子
    技術分享圖片
  • 創建好對應的url
  • 當用戶處理的時候,跳轉到處理的頁面
    技術分享圖片
  • 處理完成後把狀態 改成“已處理”,沒有完成的把狀態改成“處理中”

    下面是報表管理

    報表只有總監能看到,這裏用的報表使用了hichart,插件來實現的

    
    {% extends ‘layout.html‘ %}

{% block content %}
<div id="container" style="min-width:300px;height:300px"></div>

<div id="container2" style="min-width:500px;height:500px"></div>
{% endblock %}

{% block js %}
<script src="https://img.hcharts.cn/highcharts/highcharts.js"></script>
<script src="https://img.hcharts.cn/highcharts/modules/exporting.js"></script>
<script src="https://img.hcharts.cn/highcharts-plugins/highcharts-zh_CN.js"></script>

<script>
    $(function () {
        Highcharts.setOptions({
            global: {
                useUTC: false
            }
        });
        $.ajax({
            url: ‘/report.html‘,
            type: "POST",
            data: {‘csrfmiddlewaretoken‘: ‘{{ csrf_token }}‘},
            dataType: ‘JSON‘,
            success: function (arg) {
                console.log(arg);

                $(‘#container‘).highcharts({
                    chart: {
                        plotBackgroundColor: null,
                        plotBorderWidth: null,
                        plotShadow: false
                    },
                    title: {
                        text: ‘運維人員處理報障占比‘
                    },
                    tooltip: {
                        headerFormat: ‘{series.name}<br>‘,
                        pointFormat: ‘{point.name}: <b>{point.percentage:.1f}%</b>‘
                    },
                    plotOptions: {
                        pie: {
                            allowPointSelect: true,
                            cursor: ‘pointer‘,
                            dataLabels: {
                                enabled: true,
                                format: ‘<b>{point.name}</b>: {point.percentage:.1f} %‘,
                                style: {
                                    color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || ‘black‘
                                }
                            }
                        }
                    },
                    series: [{
                        type: ‘pie‘,
                        name: ‘運維人員處理報障占比‘,
                        data: arg.pie
                    }]
                });

                Highcharts.chart(‘container2‘, {
                    title: {
                        text: ‘每日處理訂單詳細‘,
                        x: -20 //center
                    },
                    subtitle: {
                        text: ‘...‘,
                        x: -20
                    },
                    legend: {
                        layout: ‘horizontal‘,
                        align: ‘center‘,
                        verticalAlign: ‘bottom‘,
                        borderWidth: 1
                    },
                    xAxis:{
                        labels:{
                            formatter:function(){
                                return Highcharts.dateFormat("%Y-%m-%d",this.value);
                                //return this.value;
                            }
                        },
                        minTickInterval:24
                    },
                    series: arg.zhexian
                });
            }
        });

    })
</script>

{% endblock %}


後端的數據提供是:

def report(request):
if request.permission_code == "LOOK":
if request.method == "GET":
return render(request,‘report.html‘)
else:
from django.db.models import Count
#餅圖
result = models.Order.objects.filter(status=3).values_list(‘processor__nickname‘).annotate(ct=Count(‘id‘))
response = {}
result_dic ={}

for bin in result:

        #     key = bin[‘processor_id‘]
        #     if key in result_dic:
        #         result_dic[key][‘data‘].append([bin[‘processor__nickname‘],bin[‘ct‘]])
        #     else:
        #         result_dic[key]={‘data‘:[[bin[‘processor__nickname‘],bin[‘ct‘]],]}
        response[‘pie‘]=list(result)
        ymd_list = models.Order.objects.filter(status=3).extra(select={‘ymd‘:"strftime(‘%%s‘,strftime(‘%%Y-%%m-%%d‘,ptime))"}).values(‘processor_id‘,‘processor__nickname‘,‘ymd‘).annotate(ct=Count(‘id‘))
        ymd_dict = {}
        for row in ymd_list:
            key = row[‘processor_id‘]
            if key in ymd_dict:
                ymd_dict[key][‘data‘].append([float(row[‘ymd‘])*1000, row[‘ct‘]])
            else:
                ymd_dict[key] = {‘name‘:row[‘processor__nickname‘],‘data‘:[ [float(row[‘ymd‘])*1000, row[‘ct‘]],  ]}
        response[‘zhexian‘]=list(ymd_dict.values())
        return HttpResponse(json.dumps(response))


結果:
![](http://i2.51cto.com/images/blog/201805/22/f5728870af697d0d7f23052846fb8791.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)

django報障系統之解決工單和報表