Exemplo n.º 1
0
        /// <summary>
        /// 返回复原力数据
        /// </summary>
        /// <returns></returns>
        public Result GetResilienceData()
        {
            return(RunFun(logPath =>
            {
                List <GeelyField> list = (List <GeelyField>)GetAllPost(99999).Object;

                DataTable dicTable = new DataTable();
                dicTable.Columns.Add("cand");

                #region 获取用户数据

                foreach (var item in list)
                {
                    // 获取所有数据
                    Dictionary <string, string> tmp = ToolString.GetDiction(item.achievement);

                    // 添加表头
                    dicTable.Columns.AddRange(tmp.Keys.Where(c => !dicTable.Columns.Contains(c)).Select(c => new DataColumn(c)).ToArray());
                    // 添加一行数据
                    DataRow dr = dicTable.NewRow();
                    dr["cand"] = item.cand;// 添加唯一标识

                    // 添加数据
                    foreach (var key in tmp.Keys)
                    {
                        dr[key] = tmp[key];
                    }

                    dicTable.Rows.Add(dr);
                }

                #endregion


                DataTable dt = list.ToTable();

                #region 合并数据
                List <DataColumn> columnList = new List <DataColumn>
                {
                    dt.Columns["cand"]
                };

                dt.Union(dicTable, columnList);

                #endregion

                string resilience = "resilience";

                // 计算复原力
                foreach (DataRow dr in dt.Rows)
                {
                    dr[resilience] = GeelyField.Format((decimal.Parse(dr["自信"] + "") + decimal.Parse(dr["人际敏感"] + "") + decimal.Parse(dr["坚持不懈"] + "")) * 1.3M / 3);

                    if (!(dr["result"] + "").Contains(resilience))
                    {
                        string result = dr["result"] + "";

                        result = result.Substring(0, result.Length - 2);

                        result += $",\"{resilience}\":{dr[resilience]}" + "}}";
                        dr["result"] = result;
                    }
                    else
                    {
                        WriteLog(logPath, dr["cand"] + "");
                    }
                }

                dt.Columns.Remove("EntryID");
                dt.Columns.Remove("valid");
                dt.Columns.Remove("pid");
                dt.Columns.Remove("instr");
                dt.Columns.Remove("Speed");
                dt.Columns.Remove("isDown");
                dt.Columns.Remove("postT");
                dt.Columns.Remove("IsSend");
                dt.Columns.Remove("firstName");
                dt.Columns.Remove("email");
                dt.Columns.Remove("formula");
                dt.Columns.Remove("qualified");
                dt.Columns.Remove("createDate");
                dt.Columns.Remove("JobId");
                dt.Columns.Remove("Line178");
                dt.Columns.Remove("Line177");
                dt.Columns.Remove("Line175");
                dt.Columns.Remove("Line155");
                dt.Columns.Remove("Line110");
                dt.Columns.Remove("Line66");
                dt.Columns.Remove("Line11");

                ToolFile.TableToExcel(dt, @"C:\Users\mayn\Desktop\导出\Geely.xlsx");

                return Res;
            }));
        }