bug fixed

master
old易 2025-05-12 14:20:58 +08:00
parent abb235df8a
commit 7beb557c68
1 changed files with 86 additions and 72 deletions

View File

@ -94,43 +94,56 @@ public class WeChatUserExService : IDynamicApiController, ITransient
throw Oops.Oh("用户token无效"); throw Oops.Oh("用户token无效");
} }
var result = new WeChatUserExResponseDto(); var result = new WeChatUserExResponseDto();
await PerfectInfo(new WeChatUserExRequestDto()
{
className = "test",
provinceCode = "310000",
provinceName = "上海",
schoolName = "上海中学",
score = 660,
sp = 0,
subjectGroup = "物,化,地",
Year = 2021
});
var userext = await _rep.GetFirstAsync(u => u.WxId == _userManager.UserId); var userext = await _rep.GetFirstAsync(u => u.WxId == _userManager.UserId);
var wechatinfo = await _sysWechatUserRep.GetFirstAsync(u => u.Id == _userManager.UserId); var wechatinfo = await _sysWechatUserRep.GetFirstAsync(u => u.Id == _userManager.UserId);
result.nickName = MarkPhoneUtil.MaskPhoneNumber(wechatinfo.Mobile); result.nickName = MarkPhoneUtil.MaskPhoneNumber(wechatinfo.Mobile);
// result.mobile = wechatinfo.Mobile;不给手机号 // result.mobile = wechatinfo.Mobile;不给手机号
result.avatar = wechatinfo.Avatar; result.avatar = wechatinfo.Avatar;
result.customerType = wechatinfo.CustomerType; result.customerType = wechatinfo.CustomerType;
if (result.customerType == CustomerTypeEnum.Enterprise) //if (result.customerType == CustomerTypeEnum.Enterprise)
//{
// var spInfo = await _specialist.AsQueryable().FirstAsync(e => e.Phone == wechatinfo.Mobile && e.IsDelete == false);
// if (spInfo != null)
// {
// result.cartId = spInfo?.MajorType.ToString();
// result.nickName = spInfo?.Name;
// }
//}
//if (userext != null && !string.IsNullOrWhiteSpace(userext.ProvinceCode))
//{
// try
// {
// var province = await _busProvince.AsQueryable().FirstAsync(u => u.Code == userext.ProvinceCode);
// userext.ProvinceName = province?.Name;
// result.BatchDataUrl = string.Format("https://api.static.ycymedu.com/api/v1/batch/s/{0}.json", userext.ProvinceCode);
// //var response = await result.BatchDataUrl.SetJsonSerialization<NewtonsoftJsonSerializerProvider>().GetAsAsync<batchobject>();
// var response = await result.BatchDataUrl.GetJsonAsync<batchobject>() ;
// var batches = response.result.OrderByDescending(e => e.year).FirstOrDefault().batches;
// result.batchName = batches.Where(e => userext.expectedScore >= e.score).Any() ? batches.Where(e => userext.expectedScore >= e.score).OrderByDescending(c => c.score).FirstOrDefault().batch : "";
// result.batchScore = batches.Where(e => userext.expectedScore >= e.score).Any() ? batches.Where(e => userext.expectedScore >= e.score).OrderByDescending(c => c.score).FirstOrDefault().score : 0;
// }
// catch (Exception ex)
// {
// result.batchName = "";
// }
//}
if (userext != null)
{ {
var spInfo = await _specialist.AsQueryable().FirstAsync(e => e.Phone == wechatinfo.Mobile && e.IsDelete == false);
if (spInfo != null)
{
result.cartId = spInfo?.MajorType.ToString();
result.nickName = spInfo?.Name;
}
}
if (userext != null && !string.IsNullOrWhiteSpace(userext.ProvinceCode))
{
try
{
var province = await _busProvince.AsQueryable().FirstAsync(u => u.Code == userext.ProvinceCode);
userext.ProvinceName = province?.Name;
result.BatchDataUrl = string.Format("https://api.static.ycymedu.com/api/v1/batch/s/{0}.json", userext.ProvinceCode);
//var response = await result.BatchDataUrl.SetJsonSerialization<NewtonsoftJsonSerializerProvider>().GetAsAsync<batchobject>();
var response = await result.BatchDataUrl.GetJsonAsync<batchobject>() ;
var batches = response.result.OrderByDescending(e => e.year).FirstOrDefault().batches;
result.batchName = batches.Where(e => userext.expectedScore >= e.score).Any() ? batches.Where(e => userext.expectedScore >= e.score).OrderByDescending(c => c.score).FirstOrDefault().batch : "";
result.batchScore = batches.Where(e => userext.expectedScore >= e.score).Any() ? batches.Where(e => userext.expectedScore >= e.score).OrderByDescending(c => c.score).FirstOrDefault().score : 0;
}
catch (Exception ex)
{
result.batchName = "";
}
}
if (userext != null && userext.sp.HasValue)
{
result.SelectRule = userext.sp.Value > 0 ? new List<string>() { "综合" } : new List<string>() { "文科", "理科" };
result.userExtend = userext; result.userExtend = userext;
} }
var ylist = new List<YearRule>(); var ylist = new List<YearRule>();
@ -157,25 +170,25 @@ public class WeChatUserExService : IDynamicApiController, ITransient
result.yearRules = ylist; result.yearRules = ylist;
if (userext != null) if (userext != null)
{ {
var batchcache = await _distributed.GetAsync(CacheConst.KeyProvinceBatch + userext.ProvinceCode); //var batchcache = await _distributed.GetAsync(CacheConst.KeyProvinceBatch + userext.ProvinceCode);
if (batchcache == null)// 判断缓存是否存在,存在就直接返回,不存在就重新获取 //if (batchcache == null)// 判断缓存是否存在,存在就直接返回,不存在就重新获取
{ //{
var areaconfig = await _sysAreaConfig.AsQueryable().Where(e => e.IsDelete == false && e.LocationCode == userext.ProvinceCode) // var areaconfig = await _sysAreaConfig.AsQueryable().Where(e => e.IsDelete == false && e.LocationCode == userext.ProvinceCode)
.Select(s => new ZyBatchRule() // .Select(s => new ZyBatchRule()
{ // {
batchName = s.BatchName, // batchName = s.BatchName,
Count = s.Count, // Count = s.Count,
ItemCount = s.ItemCount, // ItemCount = s.ItemCount,
}) // })
.ToListAsync(); // .ToListAsync();
_distributed.Set($"{CacheConst.KeyProvinceBatch}{userext.ProvinceCode}", Encoding.UTF8.GetBytes(areaconfig.ToJson()), new DistributedCacheEntryOptions() // _distributed.Set($"{CacheConst.KeyProvinceBatch}{userext.ProvinceCode}", Encoding.UTF8.GetBytes(areaconfig.ToJson()), new DistributedCacheEntryOptions()
.SetSlidingExpiration(TimeSpan.FromHours(24))); // .SetSlidingExpiration(TimeSpan.FromHours(24)));
result.zyBatches = areaconfig; // result.zyBatches = areaconfig;
} //}
else //else
{ //{
result.zyBatches = JsonConvert.DeserializeObject<List<ZyBatchRule>>(Encoding.UTF8.GetString(_distributed.Get($"{CacheConst.KeyProvinceBatch}{userext.ProvinceCode}"))); // result.zyBatches = JsonConvert.DeserializeObject<List<ZyBatchRule>>(Encoding.UTF8.GetString(_distributed.Get($"{CacheConst.KeyProvinceBatch}{userext.ProvinceCode}")));
} //}
} }
return result; return result;
@ -239,23 +252,24 @@ public class WeChatUserExService : IDynamicApiController, ITransient
{ {
throw Oops.Oh("不存在该用户"); throw Oops.Oh("不存在该用户");
} }
var db_client = _mongoRepository.Context.GetDatabase("zhiyuan");
DateTime dt = DateTime.Now; DateTime dt = DateTime.Now;
DateTime fixedDate = new DateTime(dt.Year, 7, 20); // 创建当前年份的7月20日 DateTime fixedDate = new DateTime(dt.Year, 7, 20); // 创建当前年份的7月20日
int year = dt > fixedDate ? dt.Year : dt.Year - 1; // 比较当前日期与固定日期 int year = dt > fixedDate ? dt.Year : dt.Year - 1; // 比较当前日期与固定日期
var be_json = db_client.GetCollection<ZYOneScoreOneSection>(string.Format("scoresection_{0}_{1}", requestDto.provinceCode, year)); // var db_client = _mongoRepository.Context.GetDatabase("zhiyuan");
// 动态条件列表 // var be_json = db_client.GetCollection<ZYOneScoreOneSection>(string.Format("scoresection_{0}_{1}", requestDto.provinceCode, year));
var filterBuilders = new List<FilterDefinition<ZYOneScoreOneSection>>(); // 动态条件列表
if (requestDto.score.HasValue && requestDto.score > 0) //var filterBuilders = new List<FilterDefinition<ZYOneScoreOneSection>>();
{ //if (requestDto.score.HasValue && requestDto.score > 0)
filterBuilders.Add(Builders<ZYOneScoreOneSection>.Filter.Lte(e => e.Score.Value, requestDto.score.Value)); //{
// filterBuilders.Add(Builders<ZYOneScoreOneSection>.Filter.Lte(e => e.Score.Value, requestDto.score.Value));
} //}
FilterDefinition<ZYOneScoreOneSection> filter = filterBuilders.Count > 0 //FilterDefinition<ZYOneScoreOneSection> filter = filterBuilders.Count > 0
? Builders<ZYOneScoreOneSection>.Filter.And(filterBuilders) // ? Builders<ZYOneScoreOneSection>.Filter.And(filterBuilders)
: new BsonDocument(); // 如果没有条件,则使用空过滤器 // : new BsonDocument(); // 如果没有条件,则使用空过滤器
var limit = await be_json.Find(filter).Sort(Builders<ZYOneScoreOneSection>.Sort.Descending(s => s.Score)).Limit(1).FirstOrDefaultAsync(); // var limit = await be_json.Find(filter).Sort(Builders<ZYOneScoreOneSection>.Sort.Descending(s => s.Score)).Limit(1).FirstOrDefaultAsync();
var model = await _rep.GetSingleAsync(e => e.WxId == _userManager.UserId); var model = await _rep.GetSingleAsync(e => e.WxId == _userManager.UserId);
if (model == null) if (model == null)
@ -285,11 +299,11 @@ public class WeChatUserExService : IDynamicApiController, ITransient
{ {
model.Year = requestDto.Year.Value; model.Year = requestDto.Year.Value;
} }
if (requestDto.score.HasValue) //if (requestDto.score.HasValue)
{ //{
model.expectedScore = requestDto.score.Value; // model.expectedScore = requestDto.score.Value;
model.Rank = limit != null ? limit.CumulativeCount : 0; // model.Rank = limit != null ? limit.CumulativeCount : 0;
} //}
if (requestDto.sp.HasValue) if (requestDto.sp.HasValue)
{ {
model.sp = requestDto.sp.Value; model.sp = requestDto.sp.Value;
@ -323,11 +337,11 @@ public class WeChatUserExService : IDynamicApiController, ITransient
{ {
model.Year = requestDto.Year.Value; model.Year = requestDto.Year.Value;
} }
if (requestDto.score.HasValue) //if (requestDto.score.HasValue)
{ //{
model.expectedScore = requestDto.score.Value; // model.expectedScore = requestDto.score.Value;
model.Rank = limit != null ? limit.CumulativeCount : 0; // model.Rank = limit != null ? limit.CumulativeCount : 0;
} //}
if (requestDto.sp.HasValue) if (requestDto.sp.HasValue)
{ {
model.sp = requestDto.sp.Value; model.sp = requestDto.sp.Value;