Exemplo n.º 1
0
        public void AddLllegalScore(LllegalRegisterEntity entity)
        {
            //当前用户
            Operator curUser = OperatorProvider.Provider.Current();

            #region 违章评分对象
            try
            {
                string           fileName         = "推送违章对接培训平台接口" + DateTime.Now.ToString("yyyyMMdd") + ".log";
                LllegalPunishBLL lllegalpunishbll = new LllegalPunishBLL();
                #region 添加用户积分
                string lllegaluserids  = string.Empty;
                string lllegaldeptcode = string.Empty;
                //考核人
                var relevanceList = lllegalpunishbll.GetListByLllegalId(entity.ID, "");
                foreach (LllegalPunishEntity lpEntity in relevanceList)
                {
                    if (lpEntity.ASSESSOBJECT.Contains("人员") && !string.IsNullOrEmpty(lpEntity.PERSONINCHARGEID))
                    {
                        //违章责任人
                        lllegalpunishbll.SaveUserScore(lpEntity.PERSONINCHARGEID, entity.LLLEGALLEVEL);
                        lllegaluserids += lpEntity.PERSONINCHARGEID + ",";
                    }
                    else if (lpEntity.ASSESSOBJECT.Contains("单位"))
                    {
                        lllegaldeptcode += lpEntity.PERSONINCHARGEID + ","; //记录单位编码
                    }
                }
                #endregion
                //考核用户id
                if (!string.IsNullOrEmpty(lllegaluserids))
                {
                    lllegaluserids = lllegaluserids.Substring(0, lllegaluserids.Length - 1);
                }
                //考核部门
                if (!string.IsNullOrEmpty(lllegaldeptcode))
                {
                    lllegaldeptcode = lllegaldeptcode.Substring(0, lllegaldeptcode.Length - 1);
                }

                #region 消息提醒考核的人员、考核的单位
                //消息通知的用户
                string pushaccount   = string.Empty;
                string pushusernames = string.Empty;
                string pushcode      = "WZ012"; //违章考核消息通知
                //考核人员
                if (!string.IsNullOrEmpty(lllegaluserids))
                {
                    DataTable dt = userbll.GetUserByDeptCodeAndRoleName(lllegaluserids, null, null);
                    if (dt.Rows.Count == 1)
                    {
                        pushaccount   += dt.Rows[0]["account"].ToString() + ",";  //账户
                        pushusernames += dt.Rows[0]["realname"].ToString() + ","; //姓名
                    }
                }
                //考核单位(获取单位负责人)
                if (!string.IsNullOrEmpty(lllegaldeptcode))
                {
                    DataTable dt = userbll.GetUserByDeptCodeAndRoleName(null, lllegaldeptcode, "负责人");
                    if (dt.Rows.Count == 1)
                    {
                        pushaccount   += dt.Rows[0]["account"].ToString() + ",";  //账户
                        pushusernames += dt.Rows[0]["realname"].ToString() + ","; //姓名
                    }
                }
                if (!string.IsNullOrEmpty(pushaccount))
                {
                    pushaccount   = pushaccount.Substring(0, pushaccount.Length - 1);
                    pushusernames = pushusernames.Substring(0, pushusernames.Length - 1);
                    //极光消息推送
                    JPushApi.PushMessage(pushaccount, pushusernames, pushcode, entity.ID);
                }
                #endregion


                #region 违章评分对象
                List <FwzTrainUserInfo> fwzlist = new List <FwzTrainUserInfo>();
                var lllegalPoint = dataitemdetailbll.GetDataItemListByItemCode("'LllegalTrainPointSetting'");

                if (lllegalPoint.Count() > 0)
                {
                    var    LllegalTrainingPointValue    = lllegalPoint.Where(p => p.ItemName == "LllegalTrainingPointValue").FirstOrDefault();    //违章培训积分值
                    var    LllegalTrainingPointStandard = lllegalPoint.Where(p => p.ItemName == "LllegalTrainingPointStandard").FirstOrDefault(); //违章培训积分标准
                    string basePoint     = string.Empty;                                                                                          //基础分数值
                    string pointStandard = string.Empty;                                                                                          //评分标准
                    string lllegaltypetraineeprojectid = string.Empty;                                                                            //违章类型培训项目
                    string safetyruletraineeprojectid  = string.Empty;                                                                            //安规培训项目
                    if (null != LllegalTrainingPointValue)
                    {
                        basePoint = LllegalTrainingPointValue.ItemValue;
                    }
                    if (null != LllegalTrainingPointStandard)
                    {
                        pointStandard = LllegalTrainingPointStandard.ItemValue;
                    }
                    ////违章类型培训项目
                    string wzKey = "LllegalTypeTraineeProjectId_" + curUser.OrganizeCode;
                    if (lllegalPoint.Where(p => p.ItemName == wzKey).Count() > 0)
                    {
                        var LllegalTypeTraineeProjectId = lllegalPoint.Where(p => p.ItemName == wzKey).FirstOrDefault();
                        if (null != LllegalTypeTraineeProjectId)
                        {
                            if (LllegalTypeTraineeProjectId.EnabledMark == 1)
                            {
                                lllegaltypetraineeprojectid = LllegalTypeTraineeProjectId.ItemValue;
                            }
                        }
                    }
                    //安规培训项目
                    string agKey = "SafetyRuleTraineeProjectId_" + curUser.OrganizeCode;
                    var    SafetyRuleTraineeProjectId = lllegalPoint.Where(p => p.ItemName == agKey).FirstOrDefault();
                    if (null != SafetyRuleTraineeProjectId)
                    {
                        if (SafetyRuleTraineeProjectId.EnabledMark == 1)
                        {
                            safetyruletraineeprojectid = SafetyRuleTraineeProjectId.ItemValue;
                        }
                    }
                    //评分标准
                    #region 评分标准
                    if (!string.IsNullOrEmpty(pointStandard))
                    {
                        DataTable resultDt = new DataTable();
                        resultDt.Columns.Add("username");
                        resultDt.Columns.Add("account");
                        resultDt.Columns.Add("score");
                        resultDt.Columns.Add("lllegalpoint");

                        string[] standardarr = pointStandard.Split(',');

                        //0分人员
                        foreach (string standard in standardarr)
                        {
                            DataTable upointdt = new DataTable();

                            upointdt = GetLllegalPointData(basePoint, DateTime.Now.Year.ToString(), lllegaluserids, standard);

                            foreach (DataRow row in upointdt.Rows)
                            {
                                decimal score        = !string.IsNullOrEmpty(row["score"].ToString()) ? Convert.ToDecimal(row["score"].ToString()) : 0;               //剩余分数
                                decimal lllegalpoint = !string.IsNullOrEmpty(row["lllegalpoint"].ToString()) ? Convert.ToDecimal(row["lllegalpoint"].ToString()) : 0; //扣除分数
                                DataRow rrow         = resultDt.NewRow();
                                rrow["username"]     = row["realname"].ToString();                                                                                    //人员姓名
                                rrow["account"]      = row["account"].ToString();                                                                                     //人员账号
                                rrow["score"]        = score.ToString();                                                                                              //剩余分数
                                rrow["lllegalpoint"] = lllegalpoint.ToString();                                                                                       //扣除分数
                                resultDt.Rows.Add(rrow);

                                FwzTrainUserInfo fwzuser = new FwzTrainUserInfo();
                                fwzuser.Useraccount    = row["account"].ToString();
                                fwzuser.TrainStartTime = null != entity.LLLEGALTIME ? entity.LLLEGALTIME.Value.ToString("yyyy-MM-dd HH:mm:ss") : DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                                fwzuser.TrainEndTime   = null != entity.LLLEGALTIME ? entity.LLLEGALTIME.Value.AddMonths(1).ToString("yyyy-MM-dd HH:mm:ss") : DateTime.Now.AddMonths(1).ToString("yyyy-MM-dd HH:mm:ss");
                                //安规培训
                                if (standard.Trim() == "score=0")
                                {
                                    fwzuser.StationName    = "所有人员";
                                    fwzuser.TrainProjectid = safetyruletraineeprojectid; //安规
                                }
                                else
                                {
                                    fwzuser.StationName = dataitemdetailbll.GetEntity(entity.LLLEGALTYPE).ItemName;
                                    if (!string.IsNullOrEmpty(lllegaltypetraineeprojectid))
                                    {
                                        fwzuser.TrainProjectid = lllegaltypetraineeprojectid;
                                    }
                                    else
                                    {
                                        var lllegalPointObj = lllegalPoint.Where(P => P.ItemName == fwzuser.StationName);
                                        if (lllegalPointObj.Count() > 0)
                                        {
                                            fwzuser.TrainProjectid = lllegalPointObj.FirstOrDefault().ItemValue;
                                        }
                                    }
                                }
                                fwzlist.Add(fwzuser);
                            }
                        }

                        if (fwzlist.Count() > 0)
                        {
                            dynamic lllegaldy = PushUserToTrainee(fwzlist);

                            if (null != lllegaldy)
                            {
                                //返回成功状态下
                                if (lllegaldy.Code.ToString() == "0")
                                {
                                    string curcode = "WZ013";
                                    string content = string.Empty;
                                    foreach (DataRow rrow in resultDt.Rows)
                                    {
                                        string score        = rrow["score"].ToString();        //剩余分数
                                        string lllegalpoint = rrow["lllegalpoint"].ToString(); //扣除分数
                                        string curaccount   = rrow["account"].ToString();      //账户
                                        string curname      = rrow["username"].ToString();     //姓名
                                        content = "您于" + DateTime.Now.ToString("yyyy-MM-dd") + "因违章被考核了" + lllegalpoint + "分,现反违章积分为" + score + "分,需进行反违章培训,请前去参加培训.";
                                        JPushApi.PushMessage(curaccount, curname, curcode, "违章考核信息", content, entity.ID);
                                    }
                                }
                                string    resultInfo = JsonConvert.SerializeObject(lllegaldy);
                                LogEntity logEntity  = new LogEntity();
                                logEntity.Browser           = System.Web.HttpContext.Current.Request.Browser.Browser;
                                logEntity.CategoryId        = 5;
                                logEntity.OperateTypeId     = ((int)OperationType.Submit).ToString();
                                logEntity.OperateType       = EnumAttribute.GetDescription(OperationType.Submit);
                                logEntity.OperateAccount    = curUser.UserName;
                                logEntity.OperateUserId     = curUser.UserId;
                                logEntity.ExecuteResult     = 1;
                                logEntity.Module            = SystemInfo.CurrentModuleName;
                                logEntity.ModuleId          = SystemInfo.CurrentModuleId;
                                logEntity.ExecuteResultJson = resultInfo;
                                LogBLL.WriteLog(logEntity);
                            }
                        }
                    }
                    #endregion
                }

                #endregion
            }
            catch (Exception ex)
            {
                LogEntity logEntity = new LogEntity();
                logEntity.CategoryId        = 4;
                logEntity.OperateTypeId     = ((int)OperationType.Exception).ToString();
                logEntity.OperateType       = EnumAttribute.GetDescription(OperationType.Exception);
                logEntity.OperateAccount    = curUser.UserName;
                logEntity.OperateUserId     = curUser.UserId;
                logEntity.ExecuteResult     = -1;
                logEntity.ExecuteResultJson = ex.Message;
                logEntity.Module            = SystemInfo.CurrentModuleName;
                logEntity.ModuleId          = SystemInfo.CurrentModuleId;
                logEntity.ExecuteResultJson = ex.ToJson();
                logEntity.WriteLog();

                string fileName = "推送当前用户到培训平台,建立相关培训及考试任务_" + DateTime.Now.ToString("yyyyMMdd") + ".log";
                System.IO.File.AppendAllText(HttpContext.Current.Server.MapPath("~/logs/" + fileName), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "推送当前用户到培训平台,建立相关培训及考试任务:" + ex.ToJson() + "\r\n");
            }
            #endregion
        }