Beispiel #1
0
        public WorkReport GetWorkReportByID(string id)
        {
            if (string.IsNullOrWhiteSpace(id))
            {
                return(null);
            }
            PlanDac    planDac = new PlanDac();
            WorkReport wr      = planDac.GetWorkReportByID(id);

            wr.WorkReportComps = planDac.GetComponentsByID(wr.ID);
            wr.WorkReportPics  = planDac.GetPicturesByID(wr.ID);
            List <string> userIDs = planDac.GetRecipientsByID(wr.ID);

            if (userIDs != null && userIDs.Count > 0)
            {
                wr.WorkReportRecipients = GetUserInfos(userIDs);
            }
            if (!string.IsNullOrEmpty(wr.Creator))
            {
                SysUser user = userService.GetUserByID(wr.Creator);
                wr.CreatorName = user == null ? "某某" : user.Name;
            }
            return(wr);
        }
Beispiel #2
0
        internal void UpdateWorkReport(WorkReport workReport, bool isReNotice)
        {
            if (workReport == null || string.IsNullOrWhiteSpace(workReport.ID))
            {
                return;
            }
            var     db      = Utils.GetDb();
            PlanDac planDac = new PlanDac(db);

            db.BeginTransaction();
            try
            {
                planDac.UpdateWorkReportBaseInfo(workReport);
                planDac.DeletaWorkReportComps(workReport.ID);
                // planDac.DeletaWorkReportRecipients(workReport.ID);
                planDac.AddWorkReportComps(workReport.WorkReportComps, workReport.ID);
                // planDac.AddWorkReportRecipients(workReport);

                List <WRPicture> newPics = workReport.WorkReportPics;
                if (newPics == null || newPics.Count <= 0)
                {
                    planDac.DeletaWorkReportPics(workReport.ID);
                }
                else
                {
                    List <WRPicture> oldPics = planDac.GetPicturesByID(workReport.ID);
                    if (oldPics == null || oldPics.Count <= 0)
                    {
                        planDac.AddWorkReportPictures(newPics, workReport.ID);
                    }
                    else
                    {
                        List <WRPicture> newAddPics  = new List <WRPicture>();
                        List <string>    deletedPics = new List <string>();
                        List <string>    oldPicIDs   = new List <string>();
                        List <string>    newPicIDs   = new List <string>();
                        oldPics.ForEach(pic =>
                        {
                            oldPicIDs.Add(pic.ID);
                        });
                        newPics.ForEach(pic =>
                        {
                            newPicIDs.Add(pic.ID);
                            if (string.IsNullOrEmpty(pic.ID) || !oldPicIDs.Contains(pic.ID))
                            {
                                newAddPics.Add(pic);
                            }
                        });
                        oldPics.ForEach(pic =>
                        {
                            if (!newPicIDs.Contains(pic.ID))
                            {
                                deletedPics.Add(pic.ID);
                            }
                        });
                        planDac.DeletaWorkReportPics(deletedPics);
                        planDac.AddWorkReportPictures(newAddPics, workReport.ID);
                    }
                }

                db.Commit();
                // 推送通知
                if (isReNotice)
                {
                    List <string> recipients = planDac.GetRecipientsByID(workReport.ID);
                    if (recipients != null && recipients.Count > 0)
                    {
                        NoticeRecipients(recipients);
                    }
                }
            }
            catch
            {
                db.Rollback();
            }
        }