Esempio n. 1
0
 public JsonResult OperateReportSend(long projectId, SummaryDataModel model, string note)
 {
     return(ExceptionCatch.Invoke(() =>
     {
         ProjectService.OperateReportSend(projectId, model, UserHelper.GetCurrentUser().Id, note);
     }));
 }
        public async Task <SummaryDataModel> GetBatchSummary(Guid id)
        {
            if (_lastBatchSummary != null && _lastBatchId == id)
            {
                var newLastUpdated = await GetLastUpdated();

                if (newLastUpdated <= _lastUpdated)
                {
                    return(_lastBatchSummary);
                }
            }
            var start = DateTime.Now;

            Console.WriteLine("Start:" + DateTime.Now);
            _lastBatchSummary = await _client.GetFromMessagePackAsync <SummaryDataModel>($"Data/BatchSummary/{id}");

            Console.WriteLine("End:" + DateTime.Now);
            var timeTaken = DateTime.Now - start;

            Console.WriteLine(timeTaken);
            if (_lastBatchSummary != null)
            {
                _lastUpdated = _lastBatchSummary.LastUpdated;
            }
            _lastBatchId = id;
            return(_lastBatchSummary);
        }
Esempio n. 3
0
        /// <summary>
        /// Get start-end time list
        /// </summary>
        /// <param name="DBline"></param>
        /// <param name="rangeDate"></param>
        /// <param name="assy"></param>
        /// <param name="unit"></param>
        /// <returns></returns>
        private List <DtData> GetDtData(string DBline, List <DateTime> rangeDate, string assy, string unit)
        {
            List <DtData> dtDataRet = new List <DtData>();

            try
            {
                XDocument XMLdoc = XDocument.Load(Application.StartupPath + @"\Parameter\Display.xml");
                //string url = XMLdoc.Descendants("url").FirstOrDefault().Value;
                string url = "";
                switch (DBHelper.DBremark)
                {
                case "kk09":
                    url = XMLdoc.Descendants("urlkk09").FirstOrDefault().Value;
                    break;

                case "kk08":
                    url = XMLdoc.Descendants("urlkk08").FirstOrDefault().Value;
                    break;
                    //case "kk07":
                    //    url = XMLdoc.Descendants("url").FirstOrDefault().Value;
                    //    break;
                }
                string start_time = rangeDate[0].ToString("yyyy-MM-dd HH:mm:ss");
                string end_time   = rangeDate[1].ToString("yyyy-MM-dd HH:mm:ss");

                //// 测试用start
                //string start_time = "2019-07-19 08:00:00";
                //string end_time = "2019-07-19 16:00:00";
                //DBline = "L03";
                //assy = "Final";


                SummaryDataModel summaryDataModel = new SummaryDataModel()
                {
                    line_cd = DBline,
                    assy_cd = assy,
                    unit_cd = unit,
                    start   = start_time,
                    end     = end_time
                };
                string summaryDataModelStr = SerializeObject <SummaryDataModel>(summaryDataModel);
                string res = PostHttp(url, summaryDataModelStr);
                ResObjModel <List <DtData> > resObj = DeserializeJsonToObject <ResObjModel <List <DtData> > >(res);
                foreach (DtData item in resObj.data)
                {
                    dtDataRet.Add(new DtData {
                        start = item.start, end = item.end
                    });
                }
                return(dtDataRet);
            }
            catch (Exception ex)
            {
                string str = LogHelper.GetExceptionMsg(ex, "獲取API數據失敗!");
                LogHelper.WriteErrorLog(str);
                return(dtDataRet);
            }
        }
Esempio n. 4
0
        public JsonResult OperateReportEstimate(long projectId, SummaryDataModel model, string note)
        {
            string data = JsonConvert.SerializeObject(model);

            return(ExceptionCatch.Invoke(() =>
            {
                ProjectService.OperateReportEstimate(projectId, model, UserHelper.GetCurrentUser().Id, note);
            }));
        }
        public async Task <Device> UpdateDevice(Device device)
        {
            var devRes = await _client.PostReadAsMessagePackAsync <Device>($"Data/DeviceUpdate/{device.DeviceId}", device);

            if (devRes != null && string.IsNullOrWhiteSpace(devRes.StatusData.Message) && devRes.DeviceId == _lastDeviceId)
            {
                _lastDeviceSummary = null;
            }
            return(devRes);
        }
Esempio n. 6
0
        public SummaryDataModel SummaryData(Guid?deviceId = null, bool devicesOnly = false, bool batchesOnly = false, bool current = false)
        {
            var data = new SummaryDataModel();

            data.DeviceId = deviceId;
            data.Devices  = DeviceSummaryList(deviceId).Result;
            if (!devicesOnly)
            {
                data.Batches = BatchSummaryList(deviceId, current: current).Result;
            }
            return(data);
        }
Esempio n. 7
0
        public async Task <SummaryDataModel> SummaryData(Guid?deviceId = null, bool devicesOnly = false, bool batchesOnly = false, bool current = false)
        {
            var data = new SummaryDataModel();

            data.DeviceId = deviceId;
            data.Devices  = await DeviceSummaryList(deviceId);

            if (!devicesOnly)
            {
                data.Batches = await BatchSummaryList(deviceId, current : current);
            }
            return(data);
        }
        public async Task <Batch> EndBatch(Batch batch)
        {
            var res = await _client.PostAsMessagePackAsync <Batch>($"Data/BatchEnd/{batch.BatchId}", batch);

            var devRes = res.Content.ReadFromMessagePackAsync <Batch>().Result;

            if (devRes != null && string.IsNullOrWhiteSpace(devRes.StatusData.Message) && devRes.BatchId == _lastBatchId)
            {
                _lastBatchSummary  = null;
                _lastDeviceSummary = null;
                _lastSummary       = null;
            }
            return(devRes);
        }
        public async Task <Log> DeleteLog(Log log)
        {
            var res = await _client.PostAsMessagePackAsync <Log>($"Data/LogDelete/{log.LogId}", log);

            var devRes = res.Content.ReadFromMessagePackAsync <Log>().Result;

            if (devRes != null && string.IsNullOrWhiteSpace(devRes.StatusData.Message) && devRes.BatchId == _lastBatchId)
            {
                _lastBatchSummary  = null;
                _lastDeviceSummary = null;
                _lastSummary       = null;
            }
            return(devRes);
        }
Esempio n. 10
0
        public async Task <SummaryDataModel> SummaryData(Guid?deviceId = null, bool devicesOnly = false, bool batchesOnly = false, bool current = false)
        {
            var data = new SummaryDataModel();

            data.DeviceId = deviceId;
            data.Devices  = await DeviceSummaryList(deviceId);

            if (!devicesOnly)
            {
                data.Batches = await BatchSummaryList(deviceId, current : current);
            }
            if (deviceId.HasValue && data.Devices.Any())
            {
                data.Devices.First().IsDetail = true;
            }
            return(data);
        }
        public async Task <SummaryDataModel> GetSummary()
        {
            if (_lastSummary != null)
            {
                var newLastUpdated = await GetLastUpdated();

                if (newLastUpdated <= _lastUpdated)
                {
                    return(_lastSummary);
                }
            }
            _lastSummary = await _client.GetFromMessagePackAsync <SummaryDataModel>("Data/Summary");

            if (_lastSummary != null)
            {
                _lastUpdated = _lastSummary.LastUpdated;
            }
            return(_lastSummary);
        }
Esempio n. 12
0
        /// <summary>
        /// 数据库查询出数据
        /// </summary>
        /// <param name="inputName"></param>
        /// <param name="outputName"></param>
        /// <param name="process_cd"></param>
        /// <param name="DBline"></param>
        /// <param name="dayOrNight"></param>
        /// <param name="nowShifList"></param>
        /// <returns></returns>
        //private DataTable QueryDT(string inputName, string outputName, string[] process_cd, string DBline, List<DateTime> rangeDate)
        //{
        //    string process_cd_in = string.Format("'{0}', '{1}', '{2}'", inputName, outputName, String.Join("','", process_cd));

        //    // 查询数据
        //    //测试用
        //    string sql = string.Format(@"
        //        SELECT AA.proc_uuid, process_at, judge_text,
        //      ROW_NUMBER() OVER (PARTITION BY AA.proc_uuid ORDER BY process_at) AS rid
        //        FROM(
        //         SELECT proc_uuid,process_cd
        //         FROM m_process
        //         WHERE process_cd in('AE-1')
        //         AND line_cd='L03'
        //        )PP
        //        LEFT JOIN t_insp_kk07 AA ON AA.proc_uuid = pp.proc_uuid
        //        WHERE process_at >= '2018-06-30 20:00' and  process_at < '2018-07-01 05:00'
        //    ");

        //    //string sql = string.Format(@"
        //    //    SELECT AA.proc_uuid, process_at, judge_text,
        //    //  ROW_NUMBER() OVER (PARTITION BY AA.proc_uuid ORDER BY process_at) AS rid
        //    //    FROM(
        //    //     SELECT proc_uuid,process_cd
        //    //     FROM m_process
        //    //     WHERE process_cd in({0})
        //    //     AND line_cd='{1}'
        //    //    )PP
        //    //    LEFT JOIN t_insp_{2} AA ON AA.proc_uuid = pp.proc_uuid
        //    //    WHERE process_at >= '{3}' and  process_at < '{4}'
        //    //", process_cd_in, DBline, DBHelper.DBremark, rangeDate[0].ToString("yyyy-MM-dd HH:mm"), rangeDate[1].ToString("yyyy-MM-dd HH:mm"));

        //    DataTable dt = new DataTable();
        //    Console.WriteLine(sql);
        //    new DBHelper().ExecuteDataTable(1, sql, ref dt);
        //    return dt;
        //}

        private DataTable QueryDT(string inputName, string outputName, string[] process_cd, string DBline, List <DateTime> rangeDate, string assy)
        {
            //string start_time = rangeDate[0].ToString("yyyy-MM-dd HH:mm:ss");
            //string end_time = rangeDate[1].ToString("yyyy-MM-dd HH:mm:ss");

            string start_time = "http://10.107.171.57:8000";
            string end_time   = "2019-07-17 17:00:00";

            assy = "TUB";
            SummaryDataModel summaryDataModel = new SummaryDataModel()
            {
                line_cd = DBline,
                assy_cd = assy,
                start   = start_time,
                end     = end_time
            };

            string summaryDataModelStr = SerializeObject <SummaryDataModel>(summaryDataModel);
            string url = "http://10.107.171.57:8000/get_status_data_api";
            string res = PostHttp(url, summaryDataModelStr);
            ResObjModel <List <SummaryDataModel> > resObj = DeserializeJsonToObject <ResObjModel <List <SummaryDataModel> > >(res);
            DataTable dt = new DataTable();

            if (resObj.state)
            {
                dt.Columns.Add("proc_uuid");
                dt.Columns.Add("process_at");
                dt.Columns.Add("judge_text");
                dt.Columns.Add("rid");
                foreach (SummaryDataModel item in resObj.data)
                {
                    DataRow dr = dt.NewRow();
                    dr["line_cd"] = item.line_cd.ToString();
                    dr["assy_cd"] = item.assy_cd.ToString();
                    dr["start"]   = item.start.ToString();
                    dr["end"]     = item.end.ToString();
                    dt.Rows.Add(dr);
                }
                return(dt);
            }
            return(dt);
        }
Esempio n. 13
0
        public ActionResult Index()
        {
            var customers     = Services.CustomerService.GetAllCustomers();
            var settledBets   = Services.SettledBetService.GetAllBets();
            var unsettledBets = Services.UnsettledBetService.GetAllBets();

            var model = new SummaryDataModel();

            model.CustomersWithHighWinRate = Services.CustomerAnalysisService.GetUnusualCustomers(customers, settledBets);
            model.BetsFromUnusualCustomers =
                Services.UnsettledBetAnalysisService.GetBetsFromUnusualCustomers(model.CustomersWithHighWinRate, unsettledBets);
            model.Bet10TimesHigherThanAvg = Services.UnsettledBetAnalysisService.GetBetsWithStake10TimesAboveAvg(customers,
                                                                                                                 unsettledBets);
            model.Bet30TimesHigherThanAvg = Services.UnsettledBetAnalysisService.GetBetsWithStake30TimesAboveAvg(customers,
                                                                                                                 unsettledBets);
            model.BetsWithHighWinAmount = Services.UnsettledBetAnalysisService.GetBetsWithLargeWinAmount(unsettledBets);


            return(View(model));
        }
        public async Task <SummaryDataModel> GetDeviceSummary(Guid id)
        {
            if (_lastDeviceSummary != null && _lastDeviceId == id)
            {
                var newLastUpdated = await GetLastUpdated();

                if (newLastUpdated <= _lastUpdated)
                {
                    return(_lastDeviceSummary);
                }
            }
            _lastDeviceSummary = await _client.GetFromMessagePackAsync <SummaryDataModel>($"Data/DeviceSummary/{id}");

            if (_lastDeviceSummary != null)
            {
                _lastUpdated = _lastDeviceSummary.LastUpdated;
            }
            _lastDeviceId = id;
            return(_lastDeviceSummary);
        }
Esempio n. 15
0
        public async Task <SummaryDataModel> BatchGetWithSummary(Guid batchId)
        {
            var data = new SummaryDataModel();

            data.Batch = await _context.Batches.FindAsync(batchId);

            if (data.Batch == null)
            {
                return(null);
            }
            data.BatchId    = batchId;
            data.Batch.Logs = await _context.Logs.Where(l => l.BatchId == batchId).ToListAsync();

            data.DeviceId = data.Batch.DeviceId;
            data.Devices  = await DeviceSummaryList(data.DeviceId);

            data.Batches = await BatchSummaryList(batchId : batchId);

            return(data);
        }
Esempio n. 16
0
        public async Task <SummaryDataModel> BatchGetWithSummary(Guid batchId)
        {
            var data = new SummaryDataModel();

            //data.Batch = await _context.Batches.FindAsync(batchId);
            //var x = _context.Batches.Include(b => b.Logs).Where(b => b.BatchId == batchId);
            data.Batch = await _context.Batches.Include(b => b.Logs).FirstOrDefaultAsync(b => b.BatchId == batchId);

            if (data.Batch == null)
            {
                return(null);
            }
            data.BatchId = batchId;
            //data.Batch.Logs = await _context.Logs.Where(l => l.BatchId == batchId).ToListAsync();
            data.DeviceId = data.Batch.DeviceId;
            data.Devices  = await DeviceSummaryList(data.DeviceId);

            data.Batches = await BatchSummaryList(batchId : batchId);

            data.LastUpdated = _lastUpdated;
            return(data);
        }
Esempio n. 17
0
 /// <summary>
 /// 报告预估
 /// </summary>
 /// <param name="projectId"></param>
 /// <param name="entity"></param>
 /// <param name="userId"></param>
 /// <returns></returns>
 public bool OperateReportEstimate(long projectId, SummaryDataModel entity, long userId, string note)
 {
     return(ProjectService.Instance.OperateReportEstimate(projectId, entity.ToModel <SummaryData>(), userId, note));
 }
Esempio n. 18
0
        public ResponseResult ReportSend(string userKeyId, [FromBody] SummaryDataRequest request)
        {
            LogHelper.Error(string.Format("调用报告发送API,userKeyId:{0},request:{1}", userKeyId, request.ToJson()), null);
            var responseResult = new ResponseResult();

            try
            {
                var user    = UserService.GetUserByKeyId(userKeyId);
                var project = ProjectService.GetByProjectNo(request.ProjectNo, user.Id);
                //正式报告
                byte[] resourceData;
                if (string.IsNullOrEmpty(request.ResourceUrl))
                {
                    throw new ServiceException("正式报告文件不能为空");
                }
                else
                {
                    resourceData = (new WebClient()).DownloadData(request.ResourceUrl);
                    if (resourceData.Length == 0)
                    {
                        throw new ServiceException("无法获取正式报告文件");
                    }
                    else
                    {
                        string fileName = System.IO.Path.GetFileName(request.ResourceUrl);
                        string result   = ProjectService.UploadProjectResource(project.Id, fileName, resourceData, user.Id, ResourcesEnum.正式报告);
                        if (result != "上传成功!")
                        {
                            throw new ServiceException(result);
                        }
                    }
                }
                //保存
                var sourceType      = request.GetType();                                          //源对象
                var sourcePropertys = sourceType.GetProperties();
                var data            = new SummaryDataModel();                                     //赋值对象
                var targetType      = data.GetType();
                var exceptPropertys = new string[] { "EstimateUnitPrice", "EstimateTotalPrice" }; //剔除预估信息
                foreach (var property in targetType.GetProperties())
                {
                    if (!sourcePropertys.Select(x => x.Name).Contains(property.Name) || exceptPropertys.Contains(property.Name))
                    {
                        continue;
                    }
                    var value = sourceType.GetProperty(property.Name).GetValue(request, null);
                    property.SetValue(data, value, null);
                }
                ProjectService.OperateReportSend(project.Id, data, user.Id, request.Note);
                responseResult.Code    = 0;
                responseResult.Message = "success";
            }
            catch (ServiceException ex)
            {
                responseResult.Code    = 1;
                responseResult.Message = ex.Message;
            }
            catch (Exception ex)
            {
                responseResult.Code    = 1;
                responseResult.Message = "error";
                LogHelper.Error("调用报告发送API错误日志:", ex);
            }
            return(responseResult);
        }
Esempio n. 19
0
        private SummaryDataModel LoadSummary(List <Criterias> criteria, string userRestriction)
        {
            SummaryDataModel sdm = new SummaryDataModel();
            ReportController rc  = new ReportController();
            //Loading MainSummary
            OrderSummary result = rc.GetReportDataWithSummary(criteria, userRestriction);

            sdm.MainSummary = result;
            //Loading This Week So Far
            //First day of selected week is :
            System.Globalization.CultureInfo ci = System.Threading.Thread.CurrentThread.CurrentCulture;
            DayOfWeek fdow  = ci.DateTimeFormat.FirstDayOfWeek;
            DayOfWeek today = DateTime.Now.DayOfWeek;
            DateTime  sow   = DateTime.Now.AddDays(-(today - fdow)).Date;

            foreach (var item in criteria)
            {
                item.startdate = sow.Month + "/" + sow.Day + "/" + sow.Year;
                item.enddate   = DateTime.Now.Month + "/" + DateTime.Now.Day + "/" + DateTime.Now.Year;
            }
            result            = rc.GetReportDataWithSummary(criteria, userRestriction);
            sdm.ThisWeekSoFar = result;

            //Last Week
            DateTime lw = sow.AddDays(-7);

            foreach (var item in criteria)
            {
                item.startdate = lw.Month + "/" + lw.Day + "/" + lw.Year;
                item.enddate   = sow.Month + "/" + sow.Day + "/" + sow.Year;
            }
            result       = rc.GetReportDataWithSummary(criteria, userRestriction);
            sdm.LastWeek = result;
            //This Week Last Year
            DateTime lys = sow.AddYears(-1);
            DateTime lye = DateTime.Now.AddYears(-1);

            foreach (var item in criteria)
            {
                item.startdate = lys.Month + "/" + lys.Day + "/" + lys.Year;
                item.enddate   = lye.Month + "/" + lye.Day + "/" + lye.Year;
            }
            result = rc.GetReportDataWithSummary(criteria, userRestriction);
            sdm.ThisWeekLastYear = result;


            OrderSummary changefrLw = new OrderSummary();

            if (sdm.ThisWeekSoFar.UnitsOrdered > 0)
            {
                changefrLw.UnitsOrderedPercent = Math.Round((Convert.ToDecimal(sdm.ThisWeekSoFar.UnitsOrdered - sdm.LastWeek.UnitsOrdered) / Convert.ToDecimal(sdm.ThisWeekSoFar.UnitsOrdered) * 100), 3);
            }
            if (sdm.ThisWeekSoFar.TotalOrderItems > 0)
            {
                changefrLw.TotalOrderItemsPercent = Math.Round((Convert.ToDecimal(sdm.ThisWeekSoFar.TotalOrderItems - sdm.LastWeek.TotalOrderItems) / Convert.ToDecimal(sdm.ThisWeekSoFar.TotalOrderItems) * 100), 3);
            }
            if (sdm.ThisWeekSoFar.OrderedProductSales > 0)
            {
                changefrLw.OrderedProductSales = Math.Round((Convert.ToDecimal(sdm.ThisWeekSoFar.OrderedProductSales - sdm.LastWeek.OrderedProductSales) / Convert.ToDecimal(sdm.ThisWeekSoFar.OrderedProductSales) * 100), 3);
            }
            if (sdm.ThisWeekSoFar.AvgUnitsOrderItem > 0)
            {
                changefrLw.AvgUnitsOrderItem = Math.Round((Convert.ToDecimal(sdm.ThisWeekSoFar.AvgUnitsOrderItem - sdm.LastWeek.AvgUnitsOrderItem) / Convert.ToDecimal(sdm.ThisWeekSoFar.AvgUnitsOrderItem) * 100), 3);
            }
            if (sdm.ThisWeekSoFar.AvgSalesOrderItem > 0)
            {
                changefrLw.AvgSalesOrderItem = Math.Round((Convert.ToDecimal(sdm.ThisWeekSoFar.AvgSalesOrderItem - sdm.LastWeek.AvgSalesOrderItem) / Convert.ToDecimal(sdm.ThisWeekSoFar.AvgSalesOrderItem) * 100), 3);
            }

            sdm.ChangeFromLastWeek = changefrLw;



            OrderSummary changefrLy = new OrderSummary();

            if (sdm.ThisWeekSoFar.UnitsOrdered > 0)
            {
                changefrLy.UnitsOrderedPercent = Math.Round((Convert.ToDecimal(sdm.ThisWeekSoFar.UnitsOrdered - sdm.ThisWeekLastYear.UnitsOrdered) / Convert.ToDecimal(sdm.ThisWeekSoFar.UnitsOrdered) * 100), 3);
            }

            if (sdm.ThisWeekSoFar.TotalOrderItems > 0)
            {
                changefrLy.TotalOrderItemsPercent = Math.Round((Convert.ToDecimal(sdm.ThisWeekSoFar.TotalOrderItems - sdm.ThisWeekLastYear.TotalOrderItems) / Convert.ToDecimal(sdm.ThisWeekSoFar.TotalOrderItems) * 100), 3);
            }
            if (sdm.ThisWeekSoFar.OrderedProductSales > 0)
            {
                changefrLy.OrderedProductSales = Math.Round((Convert.ToDecimal(sdm.ThisWeekSoFar.OrderedProductSales - sdm.ThisWeekLastYear.OrderedProductSales) / Convert.ToDecimal(sdm.ThisWeekSoFar.OrderedProductSales) * 100), 3);
            }
            if (sdm.ThisWeekSoFar.AvgUnitsOrderItem > 0)
            {
                changefrLy.AvgUnitsOrderItem = Math.Round((Convert.ToDecimal(sdm.ThisWeekSoFar.AvgUnitsOrderItem - sdm.ThisWeekLastYear.AvgUnitsOrderItem) / Convert.ToDecimal(sdm.ThisWeekSoFar.AvgUnitsOrderItem) * 100), 3);
            }
            if (sdm.ThisWeekSoFar.AvgSalesOrderItem > 0)
            {
                changefrLy.AvgSalesOrderItem = Math.Round((Convert.ToDecimal(sdm.ThisWeekSoFar.AvgSalesOrderItem - sdm.ThisWeekLastYear.AvgSalesOrderItem) / Convert.ToDecimal(sdm.ThisWeekSoFar.AvgSalesOrderItem) * 100), 3);
            }
            sdm.ChangeFromLastYear = changefrLy;


            return(sdm);
        }