diff --git a/20220330_Vote/Ewide.Core/SqlSugar/SqlsugarSetup.cs b/20220330_Vote/Ewide.Core/SqlSugar/SqlsugarSetup.cs index a4c47fb..8fef5a2 100644 --- a/20220330_Vote/Ewide.Core/SqlSugar/SqlsugarSetup.cs +++ b/20220330_Vote/Ewide.Core/SqlSugar/SqlsugarSetup.cs @@ -33,8 +33,7 @@ namespace Ewide.Core InitKeyType = InitKeyType.Attribute, MoreSettings = new ConnMoreSettings() { - IsAutoRemoveDataCache = true//自动清理缓存 - + IsAutoRemoveDataCache = true //自动清理缓存 }, ConfigureExternalServices = new ConfigureExternalServices() { @@ -50,10 +49,11 @@ namespace Ewide.Core EntityService = (type, column) => { var attributes = type.GetCustomAttributes(true); - if (attributes.Any(it => it is KeyAttribute))// by attribute set primarykey + if (attributes.Any(it => it is KeyAttribute)) // by attribute set primarykey { column.IsPrimarykey = true; //有哪些特性可以看 1.2 特性明细 } + if (attributes.Any(it => it is ColumnAttribute)) { column.DbColumnName = (attributes.First(it => it is ColumnAttribute) as ColumnAttribute).Name; @@ -97,19 +97,25 @@ namespace Ewide.Core { Console.ForegroundColor = ConsoleColor.Green; } + if (sql.StartsWith("UPDATE") || sql.StartsWith("INSERT")) { Console.ForegroundColor = ConsoleColor.White; } + if (sql.StartsWith("DELETE")) { Console.ForegroundColor = ConsoleColor.Blue; } + //Console.WriteLine("Sql:" + "\r\n\r\n" + UtilMethods.GetSqlString(c.DbType, sql, pars)); App.PrintToMiniProfiler("SqlSugar", "Info", UtilMethods.GetSqlString(c.DbType, sql, pars)); $"DB:{c.ConfigId}, Sql:\r\n\r\n {UtilMethods.GetSqlString(c.DbType, sql, pars)}".LogInformation(); - + Debugger.Log(1, "", $"===================CurrentConfigId:{db.CurrentConnectionConfig.ConfigId} SqlSugar log started ===================\r\n"); + Debugger.Log(2, "语句:", sql); + Debugger.Log(3, "参数:", string.Join(",", pars?.Select(it => it.ParameterName + ":" + it.Value))); + Debugger.Log(4, "", $"===================CurrentConfigId:{db.CurrentConnectionConfig.ConfigId} SqlSugar log end ===================\r\n"); }; dbProvider.Aop.DataExecuting = (oldValue, entityInfo) => @@ -160,7 +166,7 @@ namespace Ewide.Core //} }; - /* + /* * 使用 SqlSugarScope 循环配置此项的时候会覆盖整个 ConfigureExternalServices, * 移动到 New ConnectionConfig中配置 */ @@ -197,7 +203,6 @@ namespace Ewide.Core // }); //将Lambda传入过滤器 // } //} - } }); services.AddSingleton(sqlSugarScope); @@ -235,6 +240,7 @@ namespace Ewide.Core if (App.User == null) return false; return App.User.FindFirst(ClaimConst.CLAINM_SUPERADMIN)?.Value == AdminType.SuperAdmin.GetHashCode().ToString(); } + /// /// 添加 SqlSugar 拓展 /// @@ -280,4 +286,4 @@ namespace Ewide.Core public bool Enabled { get; set; } public string ProviderName { get; set; } } -} +} \ No newline at end of file diff --git a/20220330_Vote/Ewide.Core/Util/StringExtensions.cs b/20220330_Vote/Ewide.Core/Util/StringExtensions.cs index 161dced..5f45340 100644 --- a/20220330_Vote/Ewide.Core/Util/StringExtensions.cs +++ b/20220330_Vote/Ewide.Core/Util/StringExtensions.cs @@ -16,8 +16,7 @@ public static class StringExtensions public static string ToCamelCase(this string str, char split = '_', bool initialsUppder = true) { var _ = string.Join("", - str.Split(split).Select(p => p.Length > 1 ? - p.First().ToString().ToUpper() + p[1..] : p.ToUpper() + str.Split(split).Select(p => p.Length > 1 ? p.First().ToString().ToUpper() + p[1..] : p.ToUpper() ) ); @@ -45,4 +44,9 @@ public static class StringExtensions return _.ToLower(); } -} + + public static DateTime GetNow(this DateTime timestamp) + { + return DateTimeOffset.Now.ToOffset(TimeSpan.FromHours(8)).DateTime; + } +} \ No newline at end of file diff --git a/20220330_Vote/Ewide.EntityFramework.Core/dbsettings.Development.json b/20220330_Vote/Ewide.EntityFramework.Core/dbsettings.Development.json index c02bee5..2275d95 100644 --- a/20220330_Vote/Ewide.EntityFramework.Core/dbsettings.Development.json +++ b/20220330_Vote/Ewide.EntityFramework.Core/dbsettings.Development.json @@ -22,7 +22,7 @@ "Id": "118_3310_ewide", "DBType": 0, "Enabled": true, - "ConnectionString": "" + "ConnectionString": "Data Source=10.19.94.20;Port=3310;Database=yongjiangbei_vote;User ID=root;Password=Ewide.;pooling=true;sslmode=none;CharSet=utf8;" }, { //不知道干什么用的 diff --git a/20220330_Vote/Ewide.Web.Entry/appsettings.json b/20220330_Vote/Ewide.Web.Entry/appsettings.json index 4b7665c..483f08e 100644 --- a/20220330_Vote/Ewide.Web.Entry/appsettings.json +++ b/20220330_Vote/Ewide.Web.Entry/appsettings.json @@ -26,22 +26,28 @@ } ] }, - "AllowedHosts": "*", "CorsAccessorSettings": { "PolicyName": "自定义跨域策略名", - "WithOrigins": [ "http://localhost:8080", "https://mapi.zjzwfw.gov.cn" ] + "WithOrigins": [ + "http://localhost:8080", + "https://mapi.zjzwfw.gov.cn" + ] }, "AppSettings": { "InjectSpecificationDocument1": false }, "OSSProvider": { - "Provider": "HuaweiCloud", //枚举值支持:Minio/Aliyun/QCloud - "Endpoint": "http://10.74.25.87:6020", //腾讯云中表示AppId - "Region": "", //地域 + "Provider": "HuaweiCloud", + //枚举值支持:Minio/Aliyun/QCloud + "Endpoint": "http://10.74.25.87:6020", + //腾讯云中表示AppId + "Region": "", + //地域 "AccessKey": "C4D30C2801D928AAF687", "SecretKey": "ooZVXaB1tqIz7DHTv53RILD7o5cAAAGAAdkoqlR2", - "IsEnableCache": true //是否启用缓存,推荐开启 + "IsEnableCache": true + //是否启用缓存,推荐开启 }, "NingboZhiChun": { "OpenSms": 0, @@ -55,6 +61,8 @@ "SanjuKey": "vPFu7zKB08Uaxuzsc5zozAAT6W0zr3qw", "GetCommunitys": "http://sjk.test.ky.com/housesafety/statistics/GetCommunitys?searchName={0}", "GetHouseInfoCitysByCommunity": "http://sjk.test.ky.com/housesafety/statistics/GetHouseInfoCitysByCommunity?communityID={0}" + }, + "UserScore": { + "ExpertNumber": 10 } - } \ No newline at end of file diff --git a/20220330_Vote/Ewide.Web.Entry/wwwroot/html/userscore20250801/index.html b/20220330_Vote/Ewide.Web.Entry/wwwroot/html/userscore20250801/index.html new file mode 100644 index 0000000..27c099c --- /dev/null +++ b/20220330_Vote/Ewide.Web.Entry/wwwroot/html/userscore20250801/index.html @@ -0,0 +1,347 @@ + + + + + + + + + + + + + + +
+

2025年度XXXXXXXXXXXXX打分

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+ + 提交 +

+
+ + + + \ No newline at end of file diff --git a/20220330_Vote/Vote.Services/ApiController/UserScore20250801Service.cs b/20220330_Vote/Vote.Services/ApiController/UserScore20250801Service.cs new file mode 100644 index 0000000..395f39e --- /dev/null +++ b/20220330_Vote/Vote.Services/ApiController/UserScore20250801Service.cs @@ -0,0 +1,289 @@ +using Ewide.Core.Util; +using Furion.DatabaseAccessor; +using Furion.DynamicApiController; +using Furion.FriendlyException; +using Mapster; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Furion; +using Newtonsoft.Json; +using SqlSugar; +using Vote.Services.Dto; + +namespace Vote.Services.ApiController +{ + /// + /// 项目 + /// + [ApiDescriptionSettings("userscore", Order = 0)] + [Route("/gb/yjb/api/userscore20250801")] + public class UserScore20250801Service : IDynamicApiController + { + private readonly IRepository repuserscore20250801; + private readonly Ewide.Core.SqlSugarRepository repuserscore; + + public UserScore20250801Service(IRepository _repuserscore20250801 + , Ewide.Core.SqlSugarRepository _repuserscore) + { + repuserscore20250801 = _repuserscore20250801; + repuserscore = _repuserscore; + } + + /// + /// 列表 + /// + /// + [HttpPost] + [Microsoft.AspNetCore.Authorization.AllowAnonymous] + public async Task List() + { + var data = await repuserscore.AsQueryable() + .OrderBy(a => a.No) + .ToListAsync(); + // var data = await repuserscore20250801.DetachedEntities + // .OrderBy(a => a.No) + // .ToListAsync(); + return data; + } + + [HttpPost] + [Microsoft.AspNetCore.Authorization.AllowAnonymous] + public async Task Experts() + { + var list = new List(); + var number = App.GetConfig("UserScore:ExpertNumber"); + for (int i = 1; i < number + 1; i++) + { + list.Add(new ExpertColumn() { prop = "expert" + i, label = "专家" + i }); + } + + return list; + } + + + /// + /// 提交 + /// + /// + [HttpPost] + [UnitOfWork] + [Microsoft.AspNetCore.Authorization.AllowAnonymous] + public async Task SubmitSubmit(List args) + { + var list = await repuserscore.AsQueryable().ToListAsync(); + foreach (var entity in list) + { + var submituser = args.FirstOrDefault(a => a.userId == entity.Id); + if (submituser == null) + continue; + entity.scoresjson = JsonConvert.SerializeObject(submituser.scores); + entity.finalscore = submituser.finalscore; + entity.UpdatedTime = DateTime.Now.GetNow(); + } + + var r = await repuserscore.UpdateAsync(list); //.AsUpdateable(list) //.UpdateColumns(it => new { it.scoresjson, it.finalscore, it.UpdatedTime }) + // .ExecuteCommandAsync(); + // args.ForEach(async submituser => + // { + // //计算平均分 + // var scores = submituser.scores; + // // // 修正排序逻辑:先按分数升序排列,再排除首尾元素 + // // var sortedScores = scores.OrderBy(x => x.score).ToList(); + // // if (sortedScores.Count > 2) + // // { + // // sortedScores.RemoveAt(sortedScores.Count - 1); // 移除最高分 + // // sortedScores.RemoveAt(0); // 移除最低分 + // // } + // // + // // //取2位小数(使用处理后的分数) + // // var finalscore = Math.Round(sortedScores.Sum(a => a.score) / sortedScores.Count, 2); + // //根据id更新 + // var entity = list.FirstOrDefault(a => a.Id == submituser.userId); + // entity.scoresjson = JsonConvert.SerializeObject(submituser.scores); + // entity.finalscore = submituser.finalscore; + // entity.UpdatedTime = DateTime.Now.GetNow(); + // }); + // var r = await repuserscore.AsUpdateable(entity).UpdateColumns(it => new { it.scoresjson, it.finalscore }).ExecuteCommandAsync(); + // + return r == list.Count; + } + + // /// + // /// 检验提交码 + // /// + // /// + // [HttpPost] + // [Microsoft.AspNetCore.Authorization.AllowAnonymous] + // public async Task CheckSubmitCode(CheckSubmitCodeInput args) + // { + // var data = await rep_Experts.DetachedEntities.Where(p => !p.IsDeleted) + // .Where(a => a.login_code == args.code) + // .FirstOrDefaultAsync(); + // return data != null; + // } + // + // + // /// + // /// 提交 + // /// + // /// + // [HttpPost] + // [UnitOfWork] + // [Microsoft.AspNetCore.Authorization.AllowAnonymous] + // public async Task SubmitSubmitVote(SubmitInput args) + // { + // var data = await rep_Experts.DetachedEntities.Where(p => !p.IsDeleted) + // .Where(a => a.login_code == args.code) + // .FirstOrDefaultAsync(); + // _ = (data == null) ? throw Oops.Oh("提交码错误") : 1; + // //var list = args.projects.Adapt>(); + // //删除这个专家上次提交的结果 + // //或者提示不能再次提交 + // _ = (await rep_VoteRecords.DetachedEntities.Where(a => !a.IsDeleted && a.expert_login_code == args.code).CountAsync() > 0) ? throw Oops.Oh("已提交,无需再次提交") : 1; + // var now = DateTime.Now; + // args.projects.ForEach(async a => + // { + // var model = new Entities.VoteRecords + // { + // expert_login_code = args.code, + // project_id = a.id, + // is_agree = a.vote, + // vote_time = now + // }; + // await model.InsertOrUpdate(); + // }); + // return true; + // } + // + // private async Task> GetVoteData() + // { + // var query = from a in rep_Projects.DetachedEntities + // join b in rep_VoteRecords.DetachedEntities + // on a.Id equals b.project_id into grouping + // from p in grouping.DefaultIfEmpty() + // group new { a, p } by new { a.Id, a.name, a.serial_number, a.type } + // into pp + // select new ProjectsList2Output + // { + // serial_number = pp.Key.serial_number, + // id = pp.Key.Id, + // name = pp.Key.name, + // yes_count = pp.Where(a => a.p.is_agree).Count(), + // no_count = pp.Where(a => !a.p.is_agree).Count(), + // type = pp.Key.type + // }; + // return await query.OrderBy(a => a.serial_number).ToListAsync(); + // } + // + // /// + // /// 列表 + // /// + // /// + // [HttpPost] + // public async Task List2() + // { + // //var data = rep_Projects.DetachedEntities.Where(p => !p.IsDeleted) + // // //.Where(args.type != null, a => (int)a.type == args.type) + // // .Join(rep_VoteRecords.DetachedEntities, a => a.Id, a => a.project_id, (a, b) => + // // new + // // { + // // //a.Id, + // // //type = (int)a.type, + // // //serial_number = a.serial_number, + // // //name = a.name, + // // //no_count = b.Where(bb => !bb.is_agree).Count(), + // // //yes_count = b.Where(bb => bb.is_agree).Count(), + // // }).ToList(); + // ////.ProjectToType() + // ////.OrderBy(a => a.serial_number) + // ////.ToListAsync(); + // var data = await GetVoteData(); + // //var data0 = data.Where(a => a.type == Entities.EnumProjectType.FangJian).ToList(); + // //var data1 = data.Where(a => a.type == Entities.EnumProjectType.ShiZheng).ToList(); + // //var data2 = data.Where(a => a.type == Entities.EnumProjectType.GuiDaoGongCheng).ToList(); + // //var data3 = data.Where(a => a.type == Entities.EnumProjectType.DianLiGongCheng).ToList(); + // //var data4 = data.Where(a => a.type == Entities.EnumProjectType.JiaoTongGongCheng).ToList(); + // //var data5 = data.Where(a => a.type == Entities.EnumProjectType.ShuiLiGongCheng).ToList(); + // //return new + // //{ + // // data0, + // // data1, + // // data2, + // // data3, + // // data4, + // // data5 + // //}; + // var typeList = new List { "房建工程", "市政工程", "轨道交通工程" }; //, "电力工程", "交通工程", "水利工程" }; + // return new { data, typeList }; + // } + // + // /// + // /// + // /// + // /// + // public async Task Download() + // { + // var data = await GetVoteData(); + // //var filepath = Tools.ExcelHelper.WriteTemplate(data, 4, "C"); + // string template_name = "2024年度宁波市结构优质认定项目投票结果.xlsx"; + // var filepath = Tools.ExcelHelper.WriteTemplate(template_name, data, 5, "C"); + // return new FileStreamResult(new FileStream(filepath, FileMode.Open), "application/octet-stream") { FileDownloadName = filepath }; + // } + // + // /// + // /// + // /// + // /// + // public async Task ExpertVote() + // { + // var list = await rep_Experts.DetachedEntities.GroupJoin(rep_VoteRecords.DetachedEntities, a => a.login_code, a => a.expert_login_code, (a, b) => new { a, b }) + // .SelectMany(a => a.b.DefaultIfEmpty(), (a, b) => new { a.a.Id, a.a.login_code, is_vote = b != null }) + // .Distinct() + // .OrderBy(a => a.Id) + // .ToListAsync(); + // return list; + // //var query = from a in rep_Experts.DetachedEntities + // // join b in rep_VoteRecords.DetachedEntities on a.login_code equals b.expert_login_code into temp + // // from tt in temp.DefaultIfEmpty() + // // select new + // // { + // // a.Id, + // // a.login_code, + // // is_vote = tt == null + // // }; + // //return await query.ToListAsync(); + // } + // + // /// + // /// 新增专家 + // /// + // /// + // [HttpPost] + // public async Task AddExpert(AddExpertInput args) + // { + // if (args == null || args.expertnum <= 0) + // throw Oops.Oh("参数异常"); + // var list = new List(); + // for (int i = 0; i < args.expertnum; i++) + // { + // var newid = Ulid.NewUlid().ToString(); + // var newidsimple = newid.ToUpper().Replace("I", "").Replace("L", "").Replace("0", "").Replace("O", "").Replace("1", ""); + // list.Add(new Experts + // { + // Id = newid, + // login_code = newidsimple.Substring(newidsimple.Length - 6, 6), + // CreatedTime = DateTime.Now + // }); + // } + // + // await rep_Experts.InsertAsync(list); + // } + } +} \ No newline at end of file diff --git a/20220330_Vote/Vote.Services/Dto/UserScore20250801.cs b/20220330_Vote/Vote.Services/Dto/UserScore20250801.cs new file mode 100644 index 0000000..a743f3e --- /dev/null +++ b/20220330_Vote/Vote.Services/Dto/UserScore20250801.cs @@ -0,0 +1,26 @@ +using System.Collections.Generic; + +namespace Vote.Services.Dto; + +public class UserScore20250801 +{ +} + +public class ExpertColumn +{ + public string prop { get; set; } + public string label { get; set; } +} + +public class SubmitEntity +{ + public string userId { get; set; } + public List scores { get; set; } + public decimal finalscore { get; set; } +} + +public class UserScoreInput +{ + public string expertId { get; set; } + public decimal? score { get; set; } +} \ No newline at end of file diff --git a/20220330_Vote/Vote.Services/Entities/userscore20250801.cs b/20220330_Vote/Vote.Services/Entities/userscore20250801.cs new file mode 100644 index 0000000..80fd92b --- /dev/null +++ b/20220330_Vote/Vote.Services/Entities/userscore20250801.cs @@ -0,0 +1,55 @@ +using System; +using System.ComponentModel; +using Ewide.Core; +using SqlSugar; + +namespace Vote.Services.Entities; + +[SqlSugar.SugarTable] +[Serializable] +public class userscores20250801 : DEntityBase +{ + public userscores20250801() + { + this.No = 0; + this.Title = ""; + this.Postion = ""; + this.Name = ""; + } + + /// + /// + /// + [Description("")] + public int? No { get; set; } + + /// + /// + /// + [Description("")] + public string Title { get; set; } + + /// + /// + /// + [Description("")] + public string Postion { get; set; } + + /// + /// + /// + [Description("")] + public string Name { get; set; } + + public string scoresjson { get; set; } + public decimal? finalscore { get; set; } + + /// + /// 创建默认的主键值 + /// 当构造函数执行时如果Id为空,则会自动执行该函数 + /// + public void GenerateDefaultKeyVal() + { + Id = Ulid.NewUlid().ToString(); // Guid.NewGuid().ToString(); + } +} \ No newline at end of file diff --git a/20220330_Vote/Vote.Services/Vote.Services.xml b/20220330_Vote/Vote.Services/Vote.Services.xml index b20a6ec..d6da22a 100644 --- a/20220330_Vote/Vote.Services/Vote.Services.xml +++ b/20220330_Vote/Vote.Services/Vote.Services.xml @@ -297,6 +297,23 @@ + + + 项目 + + + + + 列表 + + + + + + 提交 + + + 微信 @@ -1068,6 +1085,32 @@ + + + + + + + + + + + + + + + + + + + + + + + 创建默认的主键值 + 当构造函数执行时如果Id为空,则会自动执行该函数 + + 投票记录