public JsonResult RepairOperatorMachineAndDemandTypeMapping()
        {
            if (UserInfo == null || UserInfo.IsSuperAdmin == false)
            {
                throw new UnauthorizedAccessException();
            }

            using (var result = new ResponseResult <object>())
            {
                long recordCount    = 0;
                var  operatorRoleId = (int)RoleType.MachineryOperator;
                //获取所有农机手数据
                var operatorList = _userService.GetUserList(1, int.MaxValue, out recordCount, new Models.Models.WhereModel
                {
                    RoleId = operatorRoleId,
                });

                if (operatorList.Count > 0)
                {
                    foreach (var operatorItem in operatorList)
                    {
                        long totalCount = 0;
                        //获取该用户的角色申请信息
                        var operatorVerificationInfo = _operatorVerificationService.GetAll <DateTime>(
                            p => p.UserId == operatorItem.UserId && p.AuditState == 1
                            , null
                            , p => p.CreateTime
                            , 1
                            , 1
                            , out totalCount).FirstOrDefault();

                        if (operatorVerificationInfo == null)
                        {
                            continue;
                        }

                        //获取该用户的角色申请信息
                        var machineInfoString = operatorVerificationInfo.Machinery;
                        if (machineInfoString.IsNullOrEmpty() || machineInfoString.StartsWith("[") == false)
                        {
                            continue;
                        }

                        //获取大家户所拥有的机器
                        var machineList     = JsonHelper.FromJsonTo <List <ProductInfo> >(machineInfoString);
                        var machineNameList = machineList.Select(
                            p => p.Name)
                                              .Distinct()
                                              .ToList();

                        var machineIdList = _sysDictionaryService.GetAll(
                            p => machineNameList.Contains(p.DisplayName))
                                            .Select(p => p.Code)
                                            .Distinct()
                                            .ToList();

                        //将机器匹配上对应的服务能力
                        var operatorDemandTypeIdList = _machineDemandTypeRLService.GetAll(
                            p => machineIdList.Contains(p.MachineId))
                                                       .Select(p => p.DemandTypeId)
                                                       .Distinct()
                                                       .ToList();

                        //删除用户农机角色下的所有服务能力
                        _userRoleDemandTypeLevelRLService.Delete(
                            p => p.UserId == operatorItem.UserId &&
                            p.RoleId == operatorRoleId);

                        //将与机器匹配后的能力列表记录到数据库
                        _userRoleDemandTypeLevelRLService.Insert(
                            from demandTypeID in operatorDemandTypeIdList
                            select new T_USER_ROLE_DEMANDTYPELEVEL_RELATION
                        {
                            CreateTime = DateTime.Now,
                            RoleId     = operatorRoleId,
                            DemandId   = demandTypeID,
                            Star       = 1,
                            UserId     = operatorItem.UserId
                        }
                            );
                    }
                }

                result.IsSuccess = true;
                result.Message   = "农机手角色服务能力数据修复成功!";
                return(new JsonResultEx(result));
            }
        }
Beispiel #2
0
        /// <summary>
        /// 获取要修改的数据
        /// </summary>
        /// <returns></returns>
        public JsonResult GetUpdData(int id = 0)
        {
            using (var result = new ResponseResult <UserInfoModel>())
            {
                if (id == 0)
                {
                    result.IsSuccess = false;
                    result.Message   = string.Format("{0}-" + ResponeString.InvalidParameter, id);
                    return(Json(result));
                }
                //1获取所有的角色类别对应的的技能
                var skillinfo = this._userService.GetSkill().ToList();
                //2根据userid获取到该用户的基本信息
                var user = this._userService.GetByKey(id);

                //3根据userid获取该用户的技能以及每个技能的星星数
                var oneuserskillinfo = this._userService.GetOneUserSkill(id).ToList();
                //4获取该用户的角色类别列表
                var rolelist = this._userService.GetRoleList(id).OrderBy(x => x.RoleId).ToList();//ww按roleid从小到大排序
                //5将所有model数据合成一个model返回给视图
                var vm_userInfo = new UserInfoModel()
                {
                    SkillInfo        = skillinfo,
                    OneUserSkillInfo = oneuserskillinfo,
                    RoleList         = rolelist,
                };

                long totalCount;
                //查询亩数ww
                var farmerVerificationInfo = _farmerVerificationRepository.GetAll <DateTime>(p => p.UserId == id, null, p => p.CreateTime, 1, 1, out totalCount).FirstOrDefault();
                if (farmerVerificationInfo != null)
                {
                    vm_userInfo.Land           = farmerVerificationInfo.Land;
                    vm_userInfo.LandAuditState = farmerVerificationInfo.LandAuditState;
                }
                var machineList = _operatorService.GetAll <DateTime>(p => p.UserId == id, null, p => p.CreateTime, 1, 1, out totalCount);
                if (machineList.Count() > 0)
                {
                    var machinery = machineList.ElementAt(0).Machinery;
                    if (machinery.StartsWith("["))
                    {
                        try
                        {
                            vm_userInfo.MachineList = JsonHelper.FromJsonTo <List <DuPont.Models.Models.ProductInfo> >(machinery);
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
                vm_userInfo.Id          = user.Id;
                vm_userInfo.UserName    = user.UserName;
                vm_userInfo.DPoint      = user.DPoint;
                vm_userInfo.Province    = user.Province;
                vm_userInfo.PhoneNumber = user.PhoneNumber;
                vm_userInfo.City        = user.City;
                vm_userInfo.Region      = user.Region;
                vm_userInfo.Township    = user.Township;
                vm_userInfo.Village     = user.Village;

                result.IsSuccess = true;
                result.Entity    = vm_userInfo;

                return(new JsonResultEx(result));
            }
        }