/// <summary>
        /// 零件的报工明细
        /// </summary>
        /// <param name="partId"></param>
        /// <param name="where"></param>
        /// <returns></returns>
        public virtual async Task <object> GetPartReportInfos(int partId, string where)
        {
            using (CurrentUnitOfWork.DisableFilter(AbpDataFilters.MustHaveTenant))
            {
                var query = Resolve <ProcessTaskReportManager>().GetAll()
                            .Include(o => o.ProcessTask).ThenInclude(o => o.ProcessType)
                            .Where(o => MESDbContext.GetJsonValueNumber(o.ProcessTask.Part.Project.Unit.Property, "$.TenantId") == AbpSession.TenantId.Value)
                            .Where(o => o.ProcessTask.PartId == partId);

                if (!string.IsNullOrEmpty(where))
                {
                    query = query.Where(where);
                }

                return(await query.Select(o => new
                {
                    o.ReportType,
                    o.ProcessTask.ProcessType.ProcessTypeName,
                    o.ReportTime,
                    o.Files
                }).ToListAsync());

                //return await query.ToListAsync();
            }
        }
        /// <summary>
        /// 获取零件加工信息
        /// </summary>
        /// <param name="projectId"></param>
        /// <returns></returns>
        public virtual async Task <object> GetProjectPartInfos(int projectId)
        {
            var parts = await Resolve <PartManager>().GetAll().IgnoreQueryFilters()
                        .Where(o => !o.IsDeleted)
                        .Include("ProcessTasks.ProcessTaskReports")
                        .Include("ProcessTasks.ProcessType")
                        .Where(o => o.EnableProcess)
                        .Where(o => MESDbContext.GetJsonValueNumber(o.Project.Unit.Property, "$.TenantId") == AbpSession.TenantId.Value)
                        .Where(o => o.ProjectId == projectId)
                        .ToListAsync()
            ;

            return(parts.Select(o =>
            {
                //零件的最后一次报工
                var lastReport = o.ProcessTasks.SelectMany(p => p.ProcessTaskReports).OrderBy(r => r.CreationTime).LastOrDefault();
                return new
                {
                    o.Id,
                    o.PartSN,
                    o.PartName,
                    o.PartImg,
                    LastReportTime = lastReport?.CreationTime,
                    lastReport?.ProcessTask.ProcessType.ProcessTypeName,
                    lastReport?.Files
                };
            }));
        }
예제 #3
0
        //public UserManager UserManager { get; set; }
        /// <summary>
        /// 通过公众号信息获取人员实体,若不存在则新增
        /// </summary>
        /// <param name="oAuthUserInfo"></param>
        /// <returns></returns>
        public virtual async Task <Person> GetPersonByWeUserOrInsert(OAuthUserInfo oAuthUserInfo)
        {
            //寻找对应的用户信息
            var user = await Resolve <UserManager>().FindAsync(new Microsoft.AspNetCore.Identity.UserLoginInfo(WeChatAuthProviderApi.Name, oAuthUserInfo.openid, ""));

            //先判断是否已有此人员
            var reporter = await Repository.GetAll().Where(o => MESDbContext.GetJsonValueString(o.Property, "$.OpenId") == oAuthUserInfo.openid && o.PersonSource == PersonSource.MLMW).FirstOrDefaultAsync();

            if (reporter == null)
            {
                reporter = new Person()
                {
                    Name = oAuthUserInfo.nickname
                };

                await Repository.InsertAsync(reporter);

                await CurrentUnitOfWork.SaveChangesAsync();
            }
            //如果已经有用户了,则取用户的名称
            if (user != null)
            {
                reporter.Name = user.Name;
            }
            reporter.SetPropertyValue("OpenId", oAuthUserInfo.openid);
            reporter.SetPropertyValue("HeadImgUrl", oAuthUserInfo.headimgurl);
            reporter.SetPropertyValue("NickName", oAuthUserInfo.nickname);

            await Repository.UpdateAsync(reporter);

            await CurrentUnitOfWork.SaveChangesAsync();

            return(reporter);
        }
예제 #4
0
        public static void SeedHostDb(MESDbContext context)
        {
            //context.Database.Migrate();
            context.SuppressAutoSetTenantId = true;
            //构建默认提醒策略
            BuildDefaultHostTactic(context);

            context.Database.ExecuteSqlCommand("update part set PartSource=4,enableprocess=1 where partsource=0");
        }
예제 #5
0
        public static void SeedHostDb(MESDbContext context)
        {
            context.SuppressAutoSetTenantId = true;

            // Host seed
            new InitialHostDbBuilder(context).Create();

            // Default tenant seed (in host database).
            new DefaultTenantBuilder(context).Create();
            new TenantRoleAndUserBuilder(context, 1).Create();
        }
예제 #6
0
        protected override async Task <IQueryable <ProcessTaskReport> > GetQueryable(RequestPageDto request)
        {
            var query = (await base.GetQueryable(request))
                        .Where(o => !o.ProcessTask.IsDeleted)
                        .Include(o => o.ProcessTask).ThenInclude(o => o.Part).ThenInclude(o => o.Project)
                        .Include(o => o.ProcessTask).ThenInclude(o => o.Supplier)
                        .Include(o => o.Reporter)
                        .Include(o => o.ProcessTask).ThenInclude(o => o.ProcessType)
                        .Include(o => o.Tenant)
                        .Where(o => o.ProcessTask.SupplierId != null)
                        .Where(o => MESDbContext.GetJsonValueNumber(o.ProcessTask.Supplier.Property, "$.TenantId") == AbpSession.TenantId.Value);

            return(query);
        }
예제 #7
0
 private static void BuildDefaultHostTactic(MESDbContext context)
 {
     if (!context.Tactic.Any(o => o.TacticName == "注册提醒" && o.TenantId == null))
     {
         //注册提醒
         var tactic = new Tactic()
         {
             TenantId   = null,
             TacticName = "注册提醒",
             TacticType = TacticType.Host,
             IsActive   = true
         };
         context.Tactic.Add(tactic);
         context.SaveChanges();
     }
 }
예제 #8
0
        private async Task <MESUnitReportRankDto> GetUnitReport(int unitId, IQueryable <ProcessTask> taskBaseQuery)
        {
            var taskQueryBySupplier = taskBaseQuery.Where(o => o.SupplierId == unitId);
            //总任务数
            var taskCount = await taskQueryBySupplier.CountAsync();

            //总报工记录数
            var reportCount = await taskQueryBySupplier.SelectMany(o => o.ProcessTaskReports).CountAsync();

            //有报工的任务数
            var reportTaskCount = await taskQueryBySupplier.Where(o => o.ProcessTaskReports.Count > 0).CountAsync();

            //todo:完成报工的任务数量的计算方式
            var completedCount = await taskQueryBySupplier.Where(o => o.EndDate != null).CountAsync();

            //延期上机任务数
            var delayStartCount = await taskQueryBySupplier.Where(o => o.AppointDate != null && ((o.StartDate != null && o.StartDate > o.AppointDate) || (o.StartDate == null && DateTime.Now > o.AppointDate))).CountAsync();

            //延期下机任务数
            var delayEndCount = await taskQueryBySupplier.Where(o => o.RequireDate != null && ((o.EndDate != null && o.EndDate > o.RequireDate) || (o.EndDate == null && DateTime.Now > o.RequireDate))).CountAsync();

            //超时任务数
            var overHourCount = await taskQueryBySupplier.Where(o => o.EstimateHours != null && o.ActualHours != null && o.ActualHours > o.EstimateHours).CountAsync();

            //不合格任务数
            var NGCount = await taskQueryBySupplier.Where(o => MESDbContext.GetJsonValueNumber(o.Property, "$.QuanlityType") == (int)QuanlityType.合格).CountAsync();

            return(new MESUnitReportRankDto()
            {
                UnitId = unitId,
                //UnitName = allUnits.Single(a => a.Id == unit.UnitId.Value).UnitName,
                TaskCount = taskCount,
                ReportCount = reportCount,
                ReportTaskCount = reportTaskCount,
                CompletedCount = completedCount,
                DelayStartCount = delayStartCount,
                DelayEndCount = delayEndCount,
                OverHourCount = overHourCount,
                NGCount = NGCount
            });
        }
예제 #9
0
 public DefaultEditionCreator(MESDbContext context)
 {
     _context = context;
 }
예제 #10
0
 public DefaultSettingsCreator(MESDbContext context)
 {
     _context = context;
 }
예제 #11
0
 public HostRoleAndUserCreator(MESDbContext context)
 {
     _context = context;
 }
예제 #12
0
 public TestDataBuilder(MESDbContext context)
 {
     _context = context;
 }
예제 #13
0
        /// <summary>
        /// 缓存方式获取项目的生产汇总数据
        /// </summary>
        /// <param name="project"></param>
        /// <returns></returns>
        public async Task <Dictionary <string, object> > GetProjectProcessSummary(Project project)
        {
            var cacheKey = $"{project.Id}@{project.TenantId}";

            return(await CacheManager.GetCache <string, Dictionary <string, object> >("ProjectProcessSummary").GetAsync(cacheKey, async o => {
                var processTypeManager = Resolve <ProcessTypeManager>();
                var processTaskManager = Resolve <ProcessTaskManager>();
                var dic = new Dictionary <string, object>()
                {
                    { "Id", project.Id },
                    { "ProjectSN", project.ProjectSN },
                    { "ProjectCharger", project.GetPropertyValue <string>("ProjectCharger") },
                    { "ProjectName", project.ProjectName }
                };
                var processTypes = await processTypeManager.GetAllList();

                var feeTotal = 0M;
                var innerFeeTotal = 0M;
                var outerFeeTotal = 0M;
                var hoursTotal = 0M;
                var taskNumberTotal = 0;
                var NGNumberTotal = 0;
                var delayNumberTotal = 0;
                foreach (var processType in processTypes)
                {
                    var taskQuery = processTaskManager.GetAll()
                                    .Where(t => t.Part.ProjectId == project.Id && t.ProcessTypeId == processType.Id && t.ProcessTaskStatus != ProcessTaskStatus.Inputed);
                    //强制回单的增加查询条件
                    //if (mustReturnFile)
                    //{
                    //    taskQuery = taskQuery.Where($"Status!=null and Status.Object.Contains(\"{ProcessTask.Status_Verify}\")");
                    //}
                    // .WhereIf(mustReturnFile, t =>t.Status!=null && t.Status.Object!=null && t.Status.Object.Contains(ProcessTask.Status_Verify))
                    //获取实际金额
                    var fee = taskQuery.Sum(t => t.Fee);
                    feeTotal += fee ?? 0;
                    dic.Add("ProcessType_" + processType.Id + "_Fee", fee?.ToString("0.00"));
                    //厂内金额
                    var innerFee = taskQuery.Where($"Status.Contains(\"{ProcessTask.Status_Inner}\")").Sum(t => t.Fee);
                    innerFeeTotal += innerFee ?? 0;
                    dic.Add("ProcessType_" + processType.Id + "_InnerFee", innerFee?.ToString("0.00"));
                    //厂外金额
                    outerFeeTotal += ((fee ?? 0) - (innerFee ?? 0));
                    dic.Add("ProcessType_" + processType.Id + "_OuterFee", ((fee ?? 0) - (innerFee ?? 0)).ToString("0.00"));
                    //实际工时
                    var hours = taskQuery.Sum(t => t.ActualHours);
                    hoursTotal += hours ?? 0;
                    dic.Add("ProcessType_" + processType.Id + "_ActualHours", hours?.ToString("0.00"));
                    //总数
                    var taskNumber = taskQuery.Count();
                    taskNumberTotal += taskNumber;
                    dic.Add("ProcessType_" + processType.Id + "_TaskNumber", taskNumber.ToString());
                    //不合格数
                    var NGNumber = taskQuery.Where(t => MESDbContext.GetJsonValueNumber(t.Property, "$.QuanlityType") == 2).Count();
                    NGNumberTotal += NGNumber;
                    dic.Add("ProcessType_" + processType.Id + "_NGNumber", NGNumber.ToString());
                    //延迟数
                    //var delayNumber = taskQuery.Where("(Convert.ToDateTime(RequireDate)-Convert.ToDateTime(EndDate==null?DateTime.Now.ToString():EndDate.ToString())).TotalDays<0  and RequireDate!=null").Count();
                    //貌似不能直接用ef core查询
                    var delayNumber = await DynamicQuery.SingleAsync <int?>($"select sum(datediff( case when enddate is null then NOW() else enddate end,requiredate)) from {nameof(ProcessTask)} where requiredate is not null and datediff( case when enddate is null then NOW() else enddate end,requiredate)>0 and ProcessTaskStatus!=0 and processTypeId={processType.Id} and partid in (select id from part where projectid={project.Id} and isdeleted=0) and isdeleted=0");
                    //var delayNumber = taskQuery.Where("(Convert.ToDateTime(RequireDate)-Convert.ToDateTime(EndDate)).TotalDays<0  and RequireDate!=null and EndDate!=null").Sum(o=> (o.EndDate.Value-o.StartDate.Value).TotalDays);
                    delayNumberTotal += delayNumber ?? 0;
                    dic.Add("ProcessType_" + processType.Id + "_DelayNumber", delayNumber.ToString());
                }
                dic.Add("FeeTotal", feeTotal.ToString("0.00"));
                dic.Add("InnerFeeTotal", innerFeeTotal.ToString("0.00"));
                dic.Add("OuterFeeTotal", outerFeeTotal.ToString("0.00"));
                dic.Add("HoursTotal", hoursTotal.ToString("0.00"));
                dic.Add("TaskNumberTotal", taskNumberTotal.ToString());
                dic.Add("NGNumberTotal", NGNumberTotal.ToString());
                dic.Add("DelayNumberTotal", delayNumberTotal.ToString("0"));

                return dic;
            }));
        }
예제 #14
0
 /// <summary>
 /// 通过微信openid获取person信息
 /// </summary>
 /// <param name="openId"></param>
 /// <returns></returns>
 public virtual async Task <Person> FindByWeOpenId(string openId)
 {
     return(await GetAll().Where(o => MESDbContext.GetJsonValueString(o.Property, "$.OpenId") == openId && o.PersonSource == PersonSource.MLMW)
            .FirstOrDefaultAsync());
 }
예제 #15
0
 public InitialHostDbBuilder(MESDbContext context)
 {
     _context = context;
 }
예제 #16
0
 public DefaultTenantBuilder(MESDbContext context)
 {
     _context = context;
 }
예제 #17
0
 public TenantRoleAndUserBuilder(MESDbContext context, int tenantId)
 {
     _context  = context;
     _tenantId = tenantId;
 }
예제 #18
0
 public DefaultLanguagesCreator(MESDbContext context)
 {
     _context = context;
 }