Jianghan 3 éve
szülő
commit
f626471b77
4 módosított fájl, 86 hozzáadás és 34 törlés
  1. 8 0
      src/front/front.go
  2. 42 4
      src/front/server.go
  3. 1 2
      src/main.go
  4. 35 28
      src/web/templates/review.html

+ 8 - 0
src/front/front.go

@@ -1,6 +1,7 @@
 package front
 
 import (
+	"github.com/shopspring/decimal"
 	"math"
 
 	//"container/list"
@@ -1224,3 +1225,10 @@ func GetLabeler(coll string) (labeler []string) {
 	qu.Debug("labeler:", labeler)
 	return
 }
+
+// 计算百分比
+func CountPr(c1, c2 int) string {
+	decimal.DivisionPrecision = 2
+	d := decimal.NewFromInt32(int32(c1)).Div(decimal.NewFromInt32(int32(c2))).Mul(decimal.NewFromInt32(100))
+	return d.String() + "%"
+}

+ 42 - 4
src/front/server.go

@@ -799,9 +799,17 @@ func (i *Front) Review() error {
 		},
 	}).All(&labeler)
 
+	var maps []map[string]interface{}
+	maps = append(maps, map[string]interface{}{"title": ""})
+	for k, v := range util.Config.Fields{
+		if v {
+			m := map[string]interface{}{"title": k}
+			maps = append(maps, m)
+		}
+	}
+	maps = append(maps, map[string]interface{}{"title": "All"})
+	i.T["fields"] = maps
 	i.T["users"] = labeler
-	qu.Debug(util.Config.Fields)
-	i.T["fields"] = util.Config.Fields
 	return i.Render("review.html", &i.T)
 }
 
@@ -1118,6 +1126,7 @@ func (i *Front) ReviewStat() {
 				umaps[user] = up
 				if flag {
 					rgmark ++
+					up["rgmark_count"] += 1
 				}
 			}
 		}
@@ -1126,13 +1135,42 @@ func (i *Front) ReviewStat() {
 	qu.Debug("count:", count, ",cmark:", cmark, ",rmark:", rmark, ",rgmark:", rgmark)
 	qu.Debug(cmaps)
 	qu.Debug(umaps)
+	if rmark == 0 {
+		i.ServeJson(map[string]interface{}{"rep": false, "msg": "无质检审核数据!"})
+		return
+	}
 	save := bson.M{"total_count": count, "cmake_count": cmark, "rmark_count": rmark, "rgmark_count": rgmark}
 	save["result"] = cmaps
 	save["user_result"] = umaps
+	save["re_user"] = i.GetSession("loginuser").(string)
 	id := util.MgoM.Save("review_result", save)
 	if id != "" {
-		i.ServeJson(map[string]interface{}{"rep": true})
+		// 前台页面数据
+		var dataSource [][]interface{}
+		var tmp []interface{}
+		tmp  = append(tmp, "全部")
+		for k, v := range util.Config.Fields{
+			if v {
+				tmp = append(tmp, CountPr(cmaps[k], rmark))
+			}
+		}
+		tmp = append(tmp, CountPr(rgmark, rmark))
+		dataSource = append(dataSource, tmp)
+		for k1, v1 := range umaps{
+			if v2, o := v1.(map[string]int); o {
+				var tmp2 []interface{}
+				tmp2 = append(tmp2, k1)
+				for k, v := range util.Config.Fields{
+					if v {
+						tmp2 = append(tmp2, CountPr(v2[k], v2["count"]))
+					}
+				}
+				tmp2 = append(tmp2, CountPr(v2["rgmark_count"], v2["count"]))
+				dataSource = append(dataSource, tmp2)
+			}
+		}
+		i.ServeJson(map[string]interface{}{"rep": true, "data": dataSource})
 	}else {
-		i.ServeJson(map[string]interface{}{"rep": false})
+		i.ServeJson(map[string]interface{}{"rep": false, "msg": "统计失败!"})
 	}
 }

+ 1 - 2
src/main.go

@@ -49,7 +49,6 @@ func init() {
 }
 
 func main() {
-	var SE = qu.SimpleEncrypt{Key: "topJYBX2019"}
-	qu.Debug(SE.EncodeString("601d7ac3cf5d499d509b83d8"))
+
 	xweb.Run(":" + util.Config.Port)
 }

+ 35 - 28
src/web/templates/review.html

@@ -66,21 +66,19 @@
     </div>
 
     <!-- 通用标签modal -->
-    <div class="modal fade" id="modal-result" tabindex="-1" role="dialog" aria-hidden="true">
+    <div class="modal fade" id="modal-result" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static">
         <div class="modal-dialog" style="width: 50%">
             <div class="modal-content">
                 <div class="modal-header">
                     <div class="modal-header">
+                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                         <div class="edit-form">
                             <div class="edit-info">
-                                <span class="info"><i class="fa fa-fw fa-tags fa-lg"></i>公共标签</span>
+                                <span class="info"><i class="fa fa-fw fa-tags fa-lg"></i>统计结果</span>
                             </div>
                             <div class="content">
                                 <table id="result" class="table table-bordered">
                                     <thead>
-                                    <tr id="tableTitle">
-                                    <th></th>
-                                    </tr>
                                     </thead>
                                 </table>
                             </div>
@@ -96,6 +94,7 @@
 
 <script>
     var fields = {{ .T.fields }}
+    var reFlag = false          // 结果统计标记
     $(document).ready(function () {
         $("#user").append("<option value=-1>请选择</option>")
         $("#user").append("<option value=0>全部</option>")
@@ -151,19 +150,23 @@
                 }
             }
         })
-
-        console.log({{.T.fields}})
-        for(k in fields){
-//             console.log(k, fields[k], type of(fields[k]))
-//             if fields[k] {
-//                 $('#result').append('<th>' + k + '</th>');
-//             }
-        }
+         $('#result').DataTable({
+            "paging": false,
+            "info": false,
+            "lengthChange": false,
+            "searching": false,
+            "ordering": false,
+            "autoWidth": false,
+            "serverSide": false,
+            "columns": fields,
+            "language": {
+                "url": "/dataTables.chinese.lang"
+            }
+        });
     });
     function findData() {
 
         var name = $("#user option:selected").val()
-        console.log(name)
         $.ajax({
             url:"/center/reviewlist",
             type:"post",
@@ -182,20 +185,24 @@
         window.open("/center/reviewdetail/"+_id+".html");
     }
     function statResult() {
-        $("#modal-result").modal("show");
-        return
-         $.ajax({
-            url:"/center/review/result",
-            type:"get",
-            success:function(r){
-            if (r.rep) {
-//                     $("#modal-result").modal("show");
-                    alert("统计成功!")
-                }else {
-                    alert("统计失败!")
-                }
-            }
-        })
+        if (reFlag) {
+            $("#modal-result").modal("show");
+            return
+        }
+        $.ajax({
+           url:"/center/review/result",
+           type:"get",
+           success:function(r){
+           if (r.rep) {
+                   reFlag = true
+                   $("#modal-result").modal("show");
+                   $('#result').dataTable().fnClearTable();
+                   $('#result').dataTable().fnAddData(r.data);
+               }else {
+                   alert(r.msg)
+               }
+           }
+       })
     }
 </script>