| | |
| | | using System.Threading.Tasks; |
| | | using WIDESEA_Core.BaseRepository; |
| | | using WIDESEA_Core.BaseServices; |
| | | using WIDESEA_Core.Seed; |
| | | using WIDESEA_IBasicService; |
| | | using WIDESEA_Model.Models; |
| | | using WIDESEA_Model.Models.Basic; |
| | |
| | | |
| | | private async Task UpdateSequenceInDatabase(DateTime date, string sequenceKey, int value) |
| | | { |
| | | var sequence = await Repository.Db.Queryable<DT_DailySequence>() |
| | | .Where(x => x.SequenceDate == date && x.SequenceKey == sequenceKey) |
| | | .FirstAsync(); |
| | | |
| | | if (sequence != null) |
| | | try |
| | | { |
| | | sequence.CurrentValue = value; |
| | | |
| | | await Repository.Db.Updateable(sequence).ExecuteCommandAsync(); |
| | | } |
| | | else |
| | | using SqlSugarClient sugarClient = new SqlSugarClient(new ConnectionConfig |
| | | { |
| | | // å¦ææ°æ®åºè®°å½ä¸åå¨ï¼åå建 |
| | | sequence = new DT_DailySequence |
| | | IsAutoCloseConnection = true, |
| | | DbType = DbType.SqlServer, |
| | | ConnectionString = DBContext.ConnectionString |
| | | }); |
| | | var result = await sugarClient.Updateable<DT_DailySequence>() |
| | | .SetColumns(it => new DT_DailySequence() |
| | | { |
| | | SequenceDate = date, |
| | | SequenceKey = sequenceKey, |
| | | CurrentValue = value, |
| | | }) |
| | | .Where(it => it.SequenceDate == date && it.SequenceKey == sequenceKey) |
| | | .ExecuteCommandAsync(); |
| | | |
| | | if (result == 0) |
| | | { |
| | | // å¦ææ²¡ææ´æ°å°è®°å½ï¼å¯è½æ¯é¦æ¬¡ä½¿ç¨ï¼æå
¥æ°è®°å½ |
| | | var newSequence = new DT_DailySequence |
| | | { |
| | | SequenceKey = sequenceKey, |
| | | SequenceDate = date, |
| | | CurrentValue = value, |
| | | Creater="admin", |
| | | CreateDate=DateTime.Now, |
| | | }; |
| | | await Repository.Db.Insertable(sequence).ExecuteCommandAsync(); |
| | | await sugarClient.Insertable(newSequence).ExecuteCommandAsync(); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | // è®°å½æ¥å¿å¹¶éæ°æåºå¼å¸¸ |
| | | Console.WriteLine($"æ´æ°åºå失败: {ex.Message}"); |
| | | throw; |
| | | } |
| | | |
| | | } |
| | | |
| | | public async Task CleanOldSequencesAsync(int keepDays = 30) |
| | | { |