Exemple #1
0
        public List <Reqlist> GetReqlist(JObject Json, string fbillid)
        {
            string jsonData           = Json["data"].ToString();
            JArray jo                 = (JArray)JsonConvert.DeserializeObject(jsonData);
            List <ApprovalProcess> ap = jo.ToObject <List <ApprovalProcess> >();
            //获取最近的一次流程
            List <Reqlist> list = new List <Reqlist>();

            foreach (var item in ap)
            {
                Reqlist reqList = new Reqlist()
                {
                    Fbilltype   = item.ActivityType, //单据类型
                    Fbillno     = item.FlowInstId,   //单据编号
                    Fbillid     = fbillid,           //单据Id
                    Fcheckerman = item.Name,         //审核人
                    Fcheckstep  = item.ActivityName  //审核级次
                };
                //创建时间
                if (item.CreateTime != null)
                {
                    reqList.CreateTime = TimeFormat.ToLocalTimeTime((long)item.CreateTime);
                }
                //执行时间
                if (item.HandleTime != null)
                {
                    reqList.HandleTime = TimeFormat.ToLocalTimeTime((long)item.HandleTime);
                }
                list.Add(reqList);
            }
            return(list);
        }
Exemple #2
0
        //[Invoke(Begin = "2020-11-11 00:00", Interval = 1000 * 3600, SkipWhileExecuting = true)]
        public void DoTask()
        {
            int totalCount = 0;
            int count      = 0;
            //获取AccessToken
            string accessToken = CallExternal.GetAccessToken();
            //获取外部接口日志
            DateTime time = DateTime.Today.AddDays(-13);//开始时间

            using (var db = new TestContext())
            {
                var query = db.ExternalLog.OrderByDescending(e => e.EndTime).FirstOrDefault();
                if (query != null)
                {
                    time = query.EndTime;
                }
            }
            long          startTime = TimeFormat.ToUnixTimestampByMilliseconds(time.AddMinutes(-1)); //开始时间
            long          endTime   = TimeFormat.ToUnixTimestampByMilliseconds(DateTime.Now);        //结束时间
            string        pageId    = null;                                                          //页码Id 上一页则传当前最小记录id,下一页则传当前最大id,首页或者最后页传null
            string        pageType  = "first";                                                       //页码类型 prev=上一页,next=下一页,first=第一页,last=最后一页
            var           pushLogs  = GetExternalLog(accessToken, startTime, endTime, pageId, pageType);
            List <string> insList   = new List <string>();

            pushLogs.ForEach(p =>
            {
                string ins = GetInstance(p.FormInstId, p.FormCodeId, accessToken);
                insList.Add(ins);
            });
            insList    = insList.Where(i => i.Contains("true")).ToList();
            totalCount = insList.Count();
            //获取实例
            try
            {
                insList.ForEach(p =>
                {
                    JObject jObject = JObject.Parse(p);
                    if (jObject["success"].ToString() == "True")
                    {
                        count += 1;
                        using (var db = new TestContext())
                        {
                            //解析数据存入数据库
                            //获取CGSqlist
                            ParseEntity PE = new ParseEntity();
                            CGSqlist cg    = PE.GetCGSQlist(jObject);
                            cg.FirstInput  = false;
                            //审批流
                            List <Reqlist> rlList = PE.GetReqlist(JObject.Parse(GetFlowRecord(cg.FormInstId, cg.FormCodeId)), cg.Fbillid);
                            rlList.ForEach(r =>
                            {
                                var list = db.Reqlist.AsNoTracking().Where(c => c.CreateTime == r.CreateTime)
                                           .Where(c => c.Fbillno == r.Fbillno).ToList();
                                if (list.Count() == 0)
                                {
                                    db.Reqlist.Add(r);
                                }
                            });
                            var query = db.CGSqlist.AsNoTracking()
                                        .Where(c => c.SerialNumber.Equals(cg.SerialNumber))
                                        .ToList();
                            if (query.Count == 0)
                            {
                                //获取CgsqListentry
                                List <CgsqListentry> cleList = PE.GetCgsqListentry(jObject, cg.Fbillid);
                                db.CGSqlist.Add(cg);
                                db.CgsqListentry.AddRange(cleList);
                            }
                            db.SaveChanges();
                        }
                    }
                });
                using (var DbContext = new TestContext())
                {
                    ExternalLog log = new ExternalLog
                    {
                        StartTime    = TimeFormat.ToLocalTimeTime(startTime),
                        EndTime      = TimeFormat.ToLocalTimeTime(endTime),
                        QueryState   = QueryState.成功,
                        FailTotalNum = totalCount,
                        TakeStatus   = TakeStatus.完全同步,
                        CatchNum     = count,
                        CreationTime = TimeFormat.ToLocalTimeTime(endTime),
                        TakeTime     = TimeFormat.ToLocalTimeTime(endTime)
                    };
                    DbContext.ExternalLog.Add(log);
                    DbContext.SaveChanges();
                }
            }
            catch (Exception e)
            {
                using (var DbContext = new TestContext())
                {
                    ExternalLog log = new ExternalLog
                    {
                        StartTime    = TimeFormat.ToLocalTimeTime(startTime),
                        EndTime      = TimeFormat.ToLocalTimeTime(endTime),
                        QueryState   = QueryState.失败,
                        FailTotalNum = totalCount,
                        TakeStatus   = TakeStatus.部分同步,
                        CatchNum     = count,
                        CreationTime = TimeFormat.ToLocalTimeTime(endTime),
                        TakeTime     = TimeFormat.ToLocalTimeTime(endTime)
                    };
                    if (totalCount == 0 || count == 0)
                    {
                        log.TakeStatus = TakeStatus.未同步;
                    }
                    DbContext.ExternalLog.Add(log);
                    DbContext.SaveChanges();
                }
            }
        }
Exemple #3
0
        public CGSqlist GetCGSQlist(JObject Json)
        {
            //添加信息
            //标题
            string title = Json["data"]["formInfo"]["widgetMap"]["_S_TITLE"]["value"].ToString();
            //流水号
            string serialNumber = Json["data"]["formInfo"]["widgetMap"]["_S_SERIAL"]["value"].ToString();
            //FormCodeId
            string formCodeId = Json["data"]["basicInfo"]["formCodeId"].ToString();
            //FormInstId
            string formInstId = Json["data"]["basicInfo"]["formInstId"].ToString();
            //申请金额
            decimal applyAmount = decimal.Parse(Json["data"]["formInfo"]["widgetMap"]["Mo_1"]["value"].ToString());
            //执行人
            List <PersonInfo> persons  = GetPerson(Json["data"]["formInfo"]["widgetMap"]["Ps_0"]["personInfo"].ToString());
            string            executor = "";//内容

            persons.ForEach(p =>
            {
                executor += p.Name.ToString() + ",";
            });
            executor = executor.Remove(executor.LastIndexOf(','), 1);
            //市场区域
            List <MarketArea> markets    = GetMarket(Json["data"]["formInfo"]["widgetMap"]["Ra_0"]["options"].ToString());
            string            marketKey  = Json["data"]["formInfo"]["widgetMap"]["Ra_0"]["value"].ToString();
            string            marketArea = "";//内容

            foreach (var item in markets)
            {
                if (item.Key.Equals(marketKey))
                {
                    marketArea = item.Value;
                }
            }
            //提交人
            List <PersonInfo> subpersons = GetPerson(Json["data"]["formInfo"]["widgetMap"]["_S_APPLY"]["personInfo"].ToString());
            string            submitter  = "";//内容

            persons.ForEach(p =>
            {
                submitter += p.Name.ToString() + ",";
            });
            submitter = submitter.Remove(submitter.LastIndexOf(','), 1);
            //申请内容
            string content = Json["data"]["formInfo"]["widgetMap"]["Ta_0"]["value"].ToString();
            //所属部门
            List <DeptInfo> deptInfo   = GetDept(Json["data"]["formInfo"]["widgetMap"]["_S_DEPT"]["deptInfo"].ToString());
            string          department = "";//内容

            deptInfo.ForEach(d =>
            {
                department += d.Name.ToString() + ",";
            });
            department = department.Remove(department.LastIndexOf(','), 1);
            //时间
            DateTime eventTime = TimeFormat.ToLocalTimeTime((long)Json["data"]["basicInfo"]["eventTime"]);
            //费用类型
            List <FeeType> feeTypes = GetFeeType(Json["data"]["formInfo"]["widgetMap"]["Ra_1"]["options"].ToString());
            string         feeKey   = Json["data"]["formInfo"]["widgetMap"]["Ra_1"]["value"].ToString();//内容
            string         feeType  = "";

            foreach (var item in feeTypes)
            {
                if (item.Key.Equals(feeKey))
                {
                    feeType = item.Value;
                }
            }
            List <WidgetValue> widgetValues = GetWidgetValue(Json["data"]["formInfo"]["detailMap"]["Dd_0"]["widgetValue"].ToString());
            //总数量
            int totalCount = 0;
            //总金额
            decimal totalFee = 0;

            widgetValues.ForEach(w =>
            {
                if (w.Nu_1 != "")
                {
                    totalCount += int.Parse(w.Nu_1);
                }
                if (w.Mo_0 != "")
                {
                    totalFee += decimal.Parse(w.Mo_0);
                }
            });
            CGSqlist cg = new CGSqlist()
            {
                Title           = title,//标题
                FormCodeId      = formCodeId,
                FormInstId      = formInstId,
                SerialNumber    = serialNumber,
                Fbillid         = "DD" + DateTime.Now.ToString("yyMMddHHmmss") + RandomHelper.RandomString(4), //Fbillid
                Freqamount      = applyAmount,                                                                 //申请金额
                Fuseman         = executor,                                                                    //执行人
                FmarkertOrea    = marketArea,                                                                  //市场区域
                Fsubmitman      = submitter,                                                                   //提交人
                FrequestContext = content,                                                                     //申请内容
                Fdepartment     = department,                                                                  //所属部门
                FirstInput      = true,
                FeeType         = feeType,                                                                     //费用类型
                TotalCount      = totalCount,                                                                  //总数量
                TotalFee        = totalFee,                                                                    //总金额
                EventTime       = eventTime
            };

            return(cg);
        }