public Result AssignFaultDevice([FromBody] List <FaultDevice> faultDevices)
        {
            var ids             = faultDevices.Select(x => x.Id);
            var oldFaultDevices = FaultDeviceHelper.GetDetails(ids);

            if (oldFaultDevices.Count() != faultDevices.Count)
            {
                return(Result.GenError <Result>(Error.FaultDeviceNotExist));
            }

            var maintainerAccounts = faultDevices.SelectMany(x => x.Maintainers).GroupBy(y => y).Select(z => z.Key);
            var maintainers        =
                ServerConfig.ApiDb.Query <Maintainer>("SELECT * FROM `maintainer` WHERE Account IN @Account AND `MarkedDelete` = 0;", new { Account = maintainerAccounts });

            if (maintainers.Count() != maintainerAccounts.Count())
            {
                return(Result.GenError <Result>(Error.MaintainerNotExist));
            }

            var time = DateTime.Now;

            foreach (var faultDevice in faultDevices)
            {
                faultDevice.AssignTime = time;
            }
            ServerConfig.ApiDb.Execute(
                "UPDATE fault_device_repair SET `AssignTime` = @AssignTime, `Maintainer` = @Maintainer, `Priority` = @Priority, `Grade` = @Grade WHERE `Id` = @Id;", faultDevices);

            var faultTypes =
                ServerConfig.ApiDb.Query <FaultType>("SELECT Id, FaultTypeName FROM `fault_type` WHERE Id IN @Id;", new { Id = oldFaultDevices.Where(y => faultDevices.Any(z => z.Id == y.Id)).Select(x => x.FaultTypeId) });

            foreach (var faultDevice in oldFaultDevices)
            {
                var assignors = faultDevices.First(x => x.Id == faultDevice.Id).Maintainers;
                var atMobiles = maintainers.Where(x => assignors.Contains(x.Account)).Where(y => !y.Phone.IsNullOrEmpty()).Select(z => z.Phone).ToArray();
                var faultType = faultTypes.First(x => x.Id == faultDevice.FaultTypeId).FaultTypeName ?? "";
                faultDevice.FaultTypeName = faultType;
                var content = NotifyFormat.Format(NotifyMsgEnum.FaultAssign, faultDevice);
                HNotifyHelper.NotifyChat(NotifyTypeEnum.Repair, NotifyMsgEnum.FaultAssign, content, NotifyMsgTypeEnum.text, atMobiles);
            }
            return(Result.GenError <Result>(Error.Success));
        }
示例#2
0
        public static void Init(IConfiguration configuration)
        {
            RedisHelper.Init(configuration);
            RedisHelper.CloseWrite = _close;
            ServerId   = configuration.GetAppSettings <int>("ServerId");
            IsAnalysis = configuration.GetAppSettings <bool>("Analysis");
            ApiDb      = new DataBase(configuration.GetConnectionString("ApiDb"))
            {
                CloseWrite = _close
            };
            _loads = new Dictionary <string, Action>
            {
                //{PermissionHelper.TableName, PermissionHelper.LoadConfig},
                { "ReadDB", LoadDateBase },
                { PermissionHelper.TableName, PermissionHelper.LoadConfig },
                { PermissionGroupHelper.TableName, PermissionGroupHelper.LoadConfig },
                { NpcProxyLinkServerHelper.TableName, NpcProxyLinkServerHelper.LoadConfig },
            };

            foreach (var action in _loads.Values)
            {
                action();
            }

            GateUrl = configuration.GetAppSettings <string>("GateUrl");
            ErpUrl  = configuration.GetAppSettings <string>("ErpUrl");
            GlobalConfig.LoadGlobalConfig();
            AccountInfoHelper.Init(configuration);
            WorkFlowHelper.Init();
            OldWorkFlowHelper.Init();
            //HMaterialHelper.MaterialChange3();
            //return;
            if (ServerId == 1)
            {
                HKanBanHelper.Init();
            }
            else if (ServerId == 2)
            {
                HNotifyHelper.Init();
                HWarningHelper.Init();
                HOpScheduleHelper.Init();
                //HFlowCardHelper.Init();
                //SimulateHelper.Init();
                HScheduleHelper.Init();
                TimerHelper.Init();
                //HMaterialHelper.Init();
            }
            else if (ServerId == 3)
            {
                AnalysisHelper.Init();
                HKanBanHelper.Init();
            }
            if (!RedisHelper.Exists(IsSetProcessDataKey))
            {
                RedisHelper.SetForever(IsSetProcessDataKey, 1);
            }
            if (!RedisHelper.Exists(IsSetDataIgnoreKey))
            {
                RedisHelper.SetForever(IsSetDataIgnoreKey, 0);
            }

            _loads.Add(HWarningHelper.RedisReloadKey, HWarningHelper.NeedReload);
            _loads.Add(HOpScheduleHelper.RedisReloadKey, HOpScheduleHelper.NeedReload);
            Log.InfoFormat("ServerConfig Done");
        }
        public Result PostFaultDevice([FromBody] List <FaultDeviceDetail> faultDevices)
        {
            IEnumerable <DeviceDetail> devices = null;

            if (faultDevices.Any(x => x.DeviceId == 0))
            {
                var cnt =
                    ServerConfig.ApiDb.Query <int>("SELECT COUNT(1) FROM `device` WHERE `Code` IN @Code AND `MarkedDelete` = 0;",
                                                   new { Code = faultDevices.Where(x => x.DeviceId == 0).Select(y => y.DeviceCode) }).FirstOrDefault();
                if (cnt > 0)
                {
                    return(Result.GenError <Result>(Error.ReportDeviceCodeIsExist));
                }
            }
            else
            {
                devices = ServerConfig.ApiDb.Query <DeviceDetail>("SELECT a.*, IFNULL(b.Phone, '') Phone FROM `device` a JOIN maintainer b ON a.Administrator = b.Account WHERE a.Id IN @DeviceId AND a.MarkedDelete = 0 AND b.MarkedDelete = 0;",
                                                                  new { DeviceId = faultDevices.Select(x => x.DeviceId) });
            }

            var createUserId = Request.GetIdentityInformation();
            var now          = DateTime.Now;

            foreach (var faultDevice in faultDevices)
            {
                faultDevice.CreateUserId   = createUserId;
                faultDevice.MarkedDateTime = now;
                faultDevice.IsReport       = true;

                faultDevice.Administrator = "";
                faultDevice.Maintainer    = "";
                faultDevice.Images        = faultDevice.Images.IsNullOrEmpty() ? "[]" : faultDevice.Images;
                if (devices != null)
                {
                    faultDevice.DeviceCode    = devices.FirstOrDefault(x => x.Id == faultDevice.DeviceId)?.Code ?? (faultDevice.DeviceCode ?? "");
                    faultDevice.Administrator = devices.FirstOrDefault(x => x.Id == faultDevice.DeviceId)?.Admin ?? "";
                    faultDevice.Maintainer    = devices.FirstOrDefault(x => x.Id == faultDevice.DeviceId)?.Admin ?? "";
                    faultDevice.Phone         = devices.FirstOrDefault(x => x.Id == faultDevice.DeviceId)?.Phone ?? "";
                }
            }

            FaultDeviceHelper.Instance.Add(faultDevices);

            var faultTypes =
                ServerConfig.ApiDb.Query <FaultType>("SELECT Id, FaultTypeName FROM `fault_type` WHERE Id IN @Id;", new { Id = faultDevices.Select(x => x.FaultTypeId) });

            foreach (var faultDevice in faultDevices)
            {
                var atMobiles = new string[] { };
                if (!faultDevice.Phone.IsNullOrEmpty())
                {
                    atMobiles = new[] { faultDevice.Phone };
                }

                var faultType = faultTypes.First(x => x.Id == faultDevice.FaultTypeId).FaultTypeName ?? "";
                faultDevice.FaultTypeName = faultType;
                var content = NotifyFormat.Format(NotifyMsgEnum.FaultReport, faultDevice);
                HNotifyHelper.NotifyChat(NotifyTypeEnum.Repair, NotifyMsgEnum.FaultReport, content, NotifyMsgTypeEnum.markdown, atMobiles);
            }
            return(Result.GenError <Result>(Error.Success));
        }