【Django-CI系统】by部门展示人均建议数-20220525

8 篇文章 0 订阅

效果:by部门展示人均建议数

在这里插入图片描述

views.py

    # 将所有模型都查出来
    suggestion_all = suggestion.objects.all()
    dept_review_all = dept_review.objects.all()
    headcount_all = headcount.objects.all()
    User_all = User.objects.all()



    # main24参数提取(by各部门人均建议提出条数)
    # 读取编制的数值(需要每个月都维护编制,否则可能报错)(headcount_item不存在则需要追认这一年最后一笔编制)
    headcount_item = headcount_all.filter(Q(headcount_datetime__range=(start_date3, end_date3))).order_by('headcount_datetime').last()
    print('headcount_item',headcount_item)
    if headcount_item:
        pass
    else:
        headcount_item = headcount_all.filter(Q(headcount_datetime__range=(this_year_start, this_year_end))).order_by('headcount_datetime').last()
    headcount_ttl_count = headcount_item.headcount_ttl
 
    print('headcount_item',headcount_item)
    headcount_dict = {'总体':headcount_item.headcount_ttl,
                      '生产部':headcount_item.headcount_shengchanbu,
                      '物流部':headcount_item.headcount_wuliubu,
                      '人事综合管理部':headcount_item.headcount_renshizonghebu,
                      '工艺质量部':headcount_item.headcount_gongyizhiliangbu,
                      '项目部':headcount_item.headcount_xiangmubu,
                      '总经办':headcount_item.headcount_zongjingban,
                      '财务部':headcount_item.headcount_caiwubu,
                      '研发部':headcount_item.headcount_yanfabu,
                    }
    person_average_suggestion = suggestion_count/headcount_ttl_count
    # 计算平均数
    suggestion_count = suggestion_all.filter(Q(suggestion_date__range=(start_date3, end_date3))).count()
    # 人均建议条数
    #print('headcount_datetime',headcount_all.filter(Q(headcount_datetime__range=(start_date3, end_date3))).order_by('headcount_datetime').last().headcount_datetime)
    list_of_suggestion_dept_count = []
    dict_of_sum_suggestion_dept_count = {'总体':round(suggestion_count/headcount_ttl_count,1),
                                        '生产部':0,
                                        '物流部':0,
                                        '人事综合管理部':0,
                                        '工艺质量部':0,
                                        '项目部':0,
                                        '总经办':0,
                                        '财务部':0,
                                        '研发部':0,
                                        }
    for su in suggestion_all:
        list_of_suggestion_dept_count.append(su.suggestion_employee_dept)
    for suggestion_employee_dept in list_of_suggestion_dept_count:
        dept_sum = suggestion_all.filter(Q(suggestion_employee_dept=suggestion_employee_dept) & Q(suggestion_date__range=(start_date1, end_date1))).aggregate(suggestion_employee_dept=Count('suggestion_employee_id'))
        process_dict = {suggestion_employee_dept : round(dept_sum['suggestion_employee_dept']/headcount_dict[suggestion_employee_dept],1)}
        dict_of_sum_suggestion_dept_count.update(process_dict)
    #print('dict_of_sum_suggestion_dept_count',dict_of_sum_suggestion_dept_count)
    value24A = []
    value24B = []
    for key,value in dict_of_sum_suggestion_dept_count.items():
        value24A.append(key)
        value24B.append(value)

dashboard.html

          <div class="row p-2 pt-3 m-2 border">
            <!--各部门人均建议提出条数-->
              <div class="col-12" id="main24" style="width: 300px;height:300px;">
                  <div id="main24" style="width: 90%;height:90%;"></div>
              </div>
          </div>

          <script type="text/javascript">
            //获取变量值
            var value24A_js = JSON.parse('{{ value24A|safe }}');
            console.log('value24A_js',value24A_js);
            var value24B_js = JSON.parse('{{ value24B|safe }}');
            console.log('value24B_js',value24B_js);
  
            // 基于准备好的dom,初始化echarts实例
           var myChart = echarts.init(document.getElementById('main24'));
     
           // 指定图表的配置项和数据
           var option = {
                 title: {
                   text: '各部门人均合理化建议'
                 },
                 tooltip: {
                   trigger: 'axis',
                   axisPointer: {
                     type: 'shadow'
                   }
                 },
                 legend: {
                 top: "10%",
                 },
                 grid: {
                   left: '3%',
                   right: '4%',
                   bottom: '3%',
                   containLabel: true
                 },
                 xAxis: {
                   type: 'value',
                   //boundaryGap: [0, 0.01],
                   minInterval:0.1,
                   min: 0,
                   //max: 0.7,
                 },
                 yAxis: {
                   type: 'category',
                   inverse: true,
                   //data: ['A部', 'B部', 'C部', 'D部', ],
                   data: value24A_js,
                 },
                 series: [
                   // {
                   //   name: '2021',
                   //   type: 'bar',
                   //   data: [0.40, 0.22, 0.15, 0.77, 0.61, 0.03, 0.02]
                   // },
                   {
                     name: '提出数量',
                     type: 'bar',
                    //data: [0.22,0.03,0.09,0.40,0.15,0.09,0.02],
                     data: value24B_js,
                     label: {
                        normal: {
                          show: true,
                          position: 'right'
                        },
                        formatter: '{@value}'
                      },
                   }
                 ],
                 itemStyle: {
                   //color: '#1E90FF'
                   color: '#4169E1'
                 },
               };
  
  
  
           // 使用刚指定的配置项和数据显示图表。
           myChart.setOption(option);
           
         </script>
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值