public async Task <NewErrorModel> Modify(ProcessingProgressModel processingProgressModel)
        {
            try
            {
                using (DDContext context = new DDContext())
                {
                    DingTalkServersController dingTalkServersController = new DingTalkServersController();
                    foreach (var item in processingProgressModel.processingProgresses)
                    {
                        string eappUrl = string.Format("eapp://page/start/productionMonitoring/productionMonitoring?taskid={0}&companyId={1}", item.TaskId, item.CompanyId);
                        //判断当前修改权限
                        NewErrorModel errorModel = GetPower(processingProgressModel.applyManId, item.TaskId);
                        List <int>    vs         = (List <int>)errorModel.data;

                        if (vs.Contains(1) && vs.Contains(3)) //  0 生产加工进度发起人 1 生产加工进度分配人 2 没权限(设计人员) 3.实际记录人
                        {
                            context.Entry <ProcessingProgress>(item).State = System.Data.Entity.EntityState.Modified;
                            if (!string.IsNullOrEmpty(item.SpeedOfProgress)) //获取工作进度表状态
                            {
                                //推送制表人
                                await dingTalkServersController.SendProcessingProgress(item.TabulatorId, 2, processingProgressModel.applyMan, item.Bom
                                                                                       , item.TaskId, item.CompanyName, item.SpeedOfProgress, item.IsAlreadyRead, eappUrl);

                                //推送设计人员
                                await dingTalkServersController.SendProcessingProgress(item.DesignerId, 2, processingProgressModel.applyMan, item.Bom
                                                                                       , item.TaskId, item.CompanyName, item.SpeedOfProgress, item.IsAlreadyRead, eappUrl);
                            }
                            context.SaveChanges();
                            return(new NewErrorModel()
                            {
                                error = new Error(0, "修改成功!", "")
                                {
                                },
                            });
                        }

                        if (vs.Count == 1 && vs.Contains(1)) //  0 生产加工进度发起人 1 生产加工进度分配人 2 没权限(设计人员) 3.实际记录人
                        {
                            context.Entry <ProcessingProgress>(item).State = System.Data.Entity.EntityState.Modified;
                            if (!string.IsNullOrEmpty(item.SpeedOfProgress)) //获取工作进度表状态
                            {
                                //推送实际记录人
                                await dingTalkServersController.SendProcessingProgress(item.NoteTakerId, 3, processingProgressModel.applyMan, item.Bom
                                                                                       , item.TaskId, item.CompanyName, item.SpeedOfProgress, item.IsAlreadyRead, eappUrl);
                            }
                        }
                        if (vs.Count == 1 && vs.Contains(0))  //制表人 暂时不通知(添加的时候通知了)
                        {
                            context.Entry <ProcessingProgress>(item).State = System.Data.Entity.EntityState.Modified;
                        }
                        if (vs.Count == 1 && vs.Contains(2)) //  0 生产加工进度发起人 1 生产加工进度分配人 2 没权限(设计人员) 3.实际记录人
                        {
                            if (item.IsAlreadyRead == true)
                            {
                                item.FinishTime = DateTime.Now.ToString("yyyy-MM-dd");
                            }
                            //修改已读状态
                            context.Entry <ProcessingProgress>(item).State = System.Data.Entity.EntityState.Modified;

                            //推送制表人
                            await dingTalkServersController.SendProcessingProgress(item.TabulatorId, 1, processingProgressModel.applyMan, item.Bom
                                                                                   , item.TaskId, item.CompanyName, item.SpeedOfProgress, item.IsAlreadyRead, eappUrl);

                            //推送分配人
                            await dingTalkServersController.SendProcessingProgress(item.HeadOfDepartmentsId, 1, processingProgressModel.applyMan, item.Bom
                                                                                   , item.TaskId, item.CompanyName, item.SpeedOfProgress, item.IsAlreadyRead, eappUrl);
                        }
                        if (/*vs.Count == 1 &&*/ vs.Contains(3)) //  0 生产加工进度发起人 1 生产加工进度分配人 2 没权限(设计人员) 3.实际记录人
                        {
                            context.Entry <ProcessingProgress>(item).State = System.Data.Entity.EntityState.Modified;
                            if (!string.IsNullOrEmpty(item.SpeedOfProgress)) //获取工作进度表状态
                            {
                                //推送制表人
                                await dingTalkServersController.SendProcessingProgress(item.TabulatorId, 0, processingProgressModel.applyMan, item.Bom
                                                                                       , item.TaskId, item.CompanyName, item.SpeedOfProgress, item.IsAlreadyRead, eappUrl);

                                //推送设计人员
                                await dingTalkServersController.SendProcessingProgress(item.DesignerId, 0, processingProgressModel.applyMan, item.Bom
                                                                                       , item.TaskId, item.CompanyName, item.SpeedOfProgress, item.IsAlreadyRead, eappUrl);

                                //推送分配人
                                await dingTalkServersController.SendProcessingProgress(item.HeadOfDepartmentsId, 0, processingProgressModel.applyMan, item.Bom
                                                                                       , item.TaskId, item.CompanyName, item.SpeedOfProgress, item.IsAlreadyRead, eappUrl);
                            }
                        }
                    }
                    context.SaveChanges();
                }
                return(new NewErrorModel()
                {
                    error = new Error(0, "修改成功!", "")
                    {
                    },
                });
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 2
0
        public object ReadDefault(string ApplyManId, string TaskId)
        {
            try
            {
                //Dictionary<string, string> keyValuePairs = new Dictionary<string, string>();
                //keyValuePairs.Add("FBillNo", "88");
                //string result = HttpPost("http://wuliao5222.55555.io:35705/api/GoDown/GetGodownInfoByFBillNo",
                //   keyValuePairs);


                HttpWebResponse httpWebResponse = CreateGetHttpResponse("http://wuliao5222.55555.io:35705/api/Pick/GetAll", 5000, null, null);

                StreamReader  reader        = new StreamReader(httpWebResponse.GetResponseStream(), Encoding.UTF8);
                string        content       = reader.ReadToEnd();
                NewErrorModel newErrorModel = new NewErrorModel()
                {
                    data = new List <GodownModel>()
                    {
                    },
                };
                newErrorModel = JsonConvert.DeserializeObject <NewErrorModel>(content);

                using (DDContext context = new DDContext())
                {
                    List <GodownModel> goDowns          = JsonConvert.DeserializeObject <List <GodownModel> >(newErrorModel.data.ToString());;
                    Flows                flows          = context.Flows.Where(f => f.FlowName.Contains("采购")).First();
                    List <Tasks>         tasks          = FlowInfoServer.ReturnUnFinishedTaskId(flows.FlowId.ToString());
                    List <Tasks>         taskQuery      = tasks.Where(t => t.TaskId.ToString() == TaskId && t.NodeId == 1).ToList();
                    List <PurchaseTable> PurchaseTables = new List <PurchaseTable>();
                    foreach (var task in taskQuery)
                    {
                        PurchaseTables.AddRange(context.PurchaseTable.Where(g => g.TaskId == task.TaskId.ToString()));
                    }
                    List <GodownModel> GodownModelList = new List <GodownModel>();
                    foreach (var goDown in goDowns)
                    {
                        foreach (var PurchaseTable in PurchaseTables)
                        {
                            if (goDown.fNumber == PurchaseTable.CodeNo)
                            {
                                GodownModelList.Add(goDown);
                            }
                        }
                    }

                    return(new NewErrorModel()
                    {
                        count = GodownModelList.Count,
                        data = GodownModelList,
                        error = new Error(0, "读取成功!", "")
                        {
                        },
                    });
                }
            }
            catch (Exception ex)
            {
                return(new NewErrorModel()
                {
                    error = new Error(1, ex.Message, "")
                    {
                    },
                });
            }
        }
        public async Task <NewErrorModel> Read(string applyManId, int pageIndex, int pageSize, string projectType = "",
                                               string projectSmallType = "", string taskId = "", string key = "", bool IsPrint = false, int companyId = 3)
        {
            try
            {
                DDContext context = new DDContext();
                List <ProcessingProgress> processingProgresses =
                    context.ProcessingProgress.Where(t => t.TabulatorId.Contains(applyManId) ||
                                                     t.DesignerId.Contains(applyManId) || t.HeadOfDepartmentsId.Contains(applyManId) ||
                                                     t.NoteTakerId.Contains(applyManId)).ToList();
                if (companyId != 3)
                {
                    processingProgresses = processingProgresses.Where(p => p.CompanyId == companyId.ToString()).ToList();
                }
                processingProgresses = processingProgresses.Where(t =>
                                                                  (taskId != "" ? t.TaskId == taskId : 1 == 1)).ToList();
                processingProgresses = processingProgresses.Where(t =>
                                                                  (key != "" ? (t.ProjectName.Contains(key) || (t.Bom.Contains(key) || (t.Designer.Contains(key) || (t.NoteTaker.Contains(key))))) : 1 == 1)).ToList();

                processingProgresses = processingProgresses.Where(t =>
                                                                  (projectType != "" ? t.ProjectType == projectType : 1 == 1) &&
                                                                  (projectSmallType != "" ? t.ProjectSmallType == projectSmallType : 1 == 1)).OrderBy(t => t.SpeedOfProgress).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
                foreach (var item in processingProgresses)
                {
                    NewErrorModel errorModel = GetPower(applyManId, item.TaskId);
                    item.Power = (List <int>)errorModel.data;
                }
                if (IsPrint == false)
                {
                    return(new NewErrorModel()
                    {
                        count = processingProgresses.Count,
                        data = processingProgresses,
                        error = new Error(0, "读取成功!", "")
                        {
                        },
                    });
                }
                else
                {
                    DataTable dtpurchaseTables = ClassChangeHelper.ToDataTable(processingProgresses, new List <string>()
                    {
                        "DesignerId", "CompanyId", "HeadOfDepartmentsId", "NoteTakerId", "TabulatorId", "CreateTime", "FinishTime", "Power"
                    });
                    string path    = HttpContext.Current.Server.MapPath(string.Format("~/UploadFile/Excel/Templet/{0}.xlsx", "生产加工进度表模板"));
                    string time    = DateTime.Now.ToString("yyyyMMddHHmmss");
                    string newPath = HttpContext.Current.Server.MapPath("~/UploadFile/Excel/Templet") + "\\" + "生产加工进度表" + time + ".xlsx";
                    File.Copy(path, newPath, true);
                    if (ExcelHelperByNPOI.UpdateExcel(newPath, "研究院+华数", dtpurchaseTables, 0, 3))
                    {
                        DingTalkServersController dingTalkServersController = new DingTalkServersController();
                        //上盯盘
                        var resultUploadMedia = await dingTalkServersController.UploadMedia("~/UploadFile/Excel/Templet/" + "生产加工进度表" + time + ".xlsx");

                        //推送用户
                        FileSendModel fileSendModel = JsonConvert.DeserializeObject <FileSendModel>(resultUploadMedia);
                        fileSendModel.UserId = applyManId;
                        var result = await dingTalkServersController.SendFileMessage(fileSendModel);

                        //删除文件
                        File.Delete(newPath);
                        return(new NewErrorModel()
                        {
                            error = new Error(0, result, "")
                            {
                            },
                        });
                    }
                    else
                    {
                        return(new NewErrorModel()
                        {
                            error = new Error(1, "文件有误", "")
                            {
                            },
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }