Ver código fonte

feat:广告增删改查完毕

Zhenghanjv 2 meses atrás
pai
commit
4880bd3be8

+ 31 - 18
Platform/AI.Platform.Page/Pages/Media/Media.razor

@@ -1,4 +1,5 @@
 @page "/media/list"
+@using AI.Platform.Core.Entity.Media
 @attribute [ReuseTabsPage(Title = "广告列表")]
 
 <Spin Spinning="Loading">
@@ -50,36 +51,48 @@
 
     <UpdateMediaDialog onCallback="OnDialogCallback" onVisibleCallback="OnDialogVisibleCallback"  @bind-IsVisible="isOpen" @bind-model="model" />
 
-    @* <Table @ref="_Table" AutoHeight TItem="SystemMenu" DataSource="_DataSource" @bind-PageSize="Ps" @bind-PageIndex="Pi"
-           TreeChildren="item=>item.Children" @bind-SelectedRows="_SelectedRows" OnChange="OnChange">
+    <Table @ref="_Table" AutoHeight TItem="MediaEntity" DataSource="_DataSource" PageSize="filterData.pageSize" Total="Total"
+    OnChange="OnChange">
         <ColumnDefinitions Context="row">
-            <PropertyColumn Property="c => c.Name" Title="菜单名称" />
-            <PropertyColumn Property="c => c.Path" Title="路由" />
-            <PropertyColumn Property="c=>c.Necessary">
+            <PropertyColumn Property="c => c.FileName" Title="文件名" />
+            <PropertyColumn Property="c => c.Uploader" Title="上传人" />
+            <PropertyColumn Property="c=>c.MediaState" Title="文件状态">
                 @{
-                    var tag = row.Necessary ? "必需" : "非必需";
-                    var color = row.Necessary ? TagColor.Green : TagColor.Blue;
+                    var tag = row.MediaState == 1 ? "可用" : "禁用";
+                    var color = row.MediaState == 1 ? TagColor.Green : TagColor.Red;
                 }
                 <Tag Color="@color">@tag</Tag>
             </PropertyColumn>
-            <PropertyColumn Property="c => c.Key" Title="自定义唯一键值" />
-            <PropertyColumn Property="c => c.Icon" Title="图标">
+            <PropertyColumn Property="c => Utils.MachineStateJsonToString(c.MachineState)" Title="油机状态" />
+            <PropertyColumn Property="c => c.StartTime" Title="播放时段">
                 @{
-                    var type = row.Icon;
+                    var tag = $"{row.StartTime}-{row.EndTime}";
                 }
-                <Icon Type="@type" Theme="IconThemeType.Outline" />
+                <Tag>@tag</Tag>
             </PropertyColumn>
-            <PropertyColumn Property="c => c.Sort" Title="排序" />
+            @* <PropertyColumn Property="c => c.EndTime" Title="结束播放时间" /> *@
+            <PropertyColumn Property="c => Utils.JoinDateTime(c.EffectiveTime,c.FailureTime)" Title="有效时间段" />
+            @* <PropertyColumn Property="c => c.FailureTime" Title="失效日期" /> *@
+            <PropertyColumn Property="c => c.CreateTime" Title="创建日期" />
+            <PropertyColumn Property="c => c.EditTime" Title="修改日期" />
+
+            <ActionColumn Width="180" Title="操作" Fixed="ColumnFixPlacement.Right">
+                <Button Type="ButtonType.Primary" Color="Color.Blue6" OnClick="@(() => ShowDialog(2, row))">编辑</Button>
+                <Button Type="ButtonType.Primary" Color="Color.Red6" OnClick="@(() => ShowDialog(3, row))">删除</Button>
+            </ActionColumn>
         </ColumnDefinitions>
+
         <PaginationTemplate>
             <Pagination Class="@(context.PaginationClass + " my-custom-pagination")"
-                        Total="context.Total"
-                        PageSize="context.PageSize"
-                        Current="context.PageIndex"
-                        ShowSizeChanger
-                        OnChange="context.HandlePageChange" />
+                        Total="Total"
+                        PageSize="filterData.pageSize"
+                        Current="filterData.currentPage"
+                        ShowSizeChanger="true"
+                        ShowQuickJumper="true"
+                        OnChange="OnPageChange"
+                        ShowTotal="showTotal" />
         </PaginationTemplate>
-    </Table> *@
+    </Table>
 </Spin>
 
 <style>

+ 80 - 15
Platform/AI.Platform.Page/Pages/Media/Media.razor.cs

@@ -7,6 +7,7 @@ using Dm.util;
 using Microsoft.AspNetCore.Components;
 using Microsoft.JSInterop;
 using SqlSugar;
+using System.Data.Common;
 using System.Text.Json;
 using System.Threading.Tasks;
 
@@ -66,17 +67,32 @@ public partial class Media
     /// </summary>
     private UpdateMediaDialog updateMediaDialog { set; get; } = new();
 
+    /// <summary>
+    /// 标识弹窗是否显示
+    /// </summary>
     private bool isOpen { set; get; } = false;
 
     private MediaDialogModel model = new MediaDialogModel();
 
+    /// <summary>
+    /// 打开编辑弹窗
+    /// </summary>
+    /// <param name="type">类型:1:新增;2:编辑;3:删除</param>
+    /// <param name="media">广告信息</param>
+    /// <returns></returns>
     private async Task ShowDialog(int type,MediaEntity? media)
     {
         model = new MediaDialogModel();
         model.Type = type;
-        if(type == 2)
+        if(type == 2 || type == 3)
         {
+            model.Id = media?.Id;
+            model.GroupID = media?.GroupID ?? "";
+            model.BusinessUnitID = media?.BusinessUnitID ?? "";
             model.FileName = media?.FileName ?? "";
+            model.GuidFileName = media?.GuidFileName ?? "";
+            model.FileExtension = media?.FileExtension ?? "";
+            model.SavePath = media?.LocalPath ?? "";
             model.MediaUploader = media?.Uploader ?? "";
             model.StartTime = media?.StartTime;
             model.EndTime = media?.EndTime;
@@ -84,31 +100,58 @@ public partial class Media
             model.FailureTime = media?.FailureTime;
             model.MediaState = media?.MediaState ?? 0;
             model.MachineStateList = JsonSerializer.Deserialize<List<string>>(media?.MachineState ?? "[]");
+            model.Remark = media?.Remark ?? "";
         }
 
         isOpen = true;
     }
-    private void OnUploadChange(UploadInfo info)
-    {
-        // 处理上传逻辑
-    }
+    
     /// <summary>
-    /// 弹窗信息回调
+    /// 编辑弹窗信息回调
     /// </summary>
     /// <param name="model"></param>
     private async Task OnDialogCallback(MediaDialogModel model)
     {
         Console.WriteLine(model);
-        await _Repository.InsertAsync(model.ToCompany());
-        
-            
+        switch (model.Type)
+        {
+            case 1:
+                await _Repository.InsertAsync(model.ToCompany());
+                break;
+            case 2:
+                MediaEntity mediaEntity = model.ToCompany();
+                await _Repository.Context.Updateable(mediaEntity).
+                    UpdateColumns(it => new { it.MediaState,it.MachineState, it.StartTime, it.EndTime ,it.EffectiveTime,it.FailureTime,it.Remark })
+                    .ExecuteCommandAsync();
+                break;
+            case 3:
+                await _Repository.DeleteByIdAsync(model.Id);
+                if(model.SavePath.IsNotNullOrEmpty())
+                {
+                    File.Delete(model.SavePath);
+                }
+                break;
+        }
+        await Query();
     }
 
+    /// <summary>
+    /// 编辑弹窗是否显示回调
+    /// </summary>
+    /// <param name="isOpen"></param>
     private void OnDialogVisibleCallback(bool isOpen)
     {
         this.isOpen = isOpen;
     }
 
+    /// <summary>
+    /// 表格查询
+    /// </summary>
+    /// <param name="query"></param>
+    /// <returns></returns>
+    private async Task OnChange(QueryModel<MediaEntity> query)
+        => await Query();
+
     /// <summary>
     /// 查
     /// </summary>
@@ -117,22 +160,44 @@ public partial class Media
     {
         Loading = true;
 
-        _DataSource = await _Repository.AsQueryable()
+        var query =  _Repository.AsQueryable()
             .WhereIF(filterData.searchFileName != null, it => it.FileName.Contains(filterData.searchFileName))
             .WhereIF(filterData.searchMediaUploader != null, it => it.Uploader.Contains(filterData.searchMediaUploader))
             .WhereIF(filterData.searchMediaState != null && filterData.searchMediaState != -1, it => it.MediaState == filterData.searchMediaState)
-            .WhereIF(filterData.searchMachineStateList.IsNotNullOrEmpty(), it => SqlFunc.ContainsArray(filterData.searchMachineStateList, it.MachineState))
             .WhereIF(filterData.searchStartTime != null && filterData.searchEndTime != null, it => it.StartTime >= filterData.searchStartTime && it.EndTime <= filterData.searchEndTime)
             .WhereIF(filterData.searchEffecitiveTime != null && filterData.searchFailureTime != null, it => it.EffectiveTime >= filterData.searchEffecitiveTime && it.FailureTime <= filterData.searchFailureTime)
-            .WhereIF(filterData.searchStartEditTime != null && filterData.searchEndEditTime != null, it => it.EditTime >= filterData.searchStartEditTime && it.EditTime <= filterData.searchEndEditTime)
-            .OrderByDescending(it => it.EditTime)
-            .ToPageListAsync(filterData.currentPage,filterData.pageSize);
+            .WhereIF(filterData.searchStartEditTime != null && filterData.searchEndEditTime != null, it => it.EditTime >= filterData.searchStartEditTime && it.EditTime <= filterData.searchEndEditTime);
 
-        Total = _DataSource.size();
+        if (filterData.searchMachineStateList.IsNotNullOrEmpty())
+        {
+            Expressionable<MediaEntity> expressionable = Expressionable.Create<MediaEntity>();
+            foreach (var state in filterData.searchMachineStateList)
+            {
+                var jsonQuoted = $"\"{state}\"";
+                expressionable.Or(m => m.MachineState.Contains(jsonQuoted));
+            }
+            query = query.Where(expressionable.ToExpression());
+        }
+
+        Total = await query.CountAsync();
+        _DataSource = await query
+            .OrderByDescending(it => it.EditTime)
+            .Skip((filterData.currentPage - 1) * filterData.pageSize)
+            .Take(filterData.pageSize)
+            .ToListAsync();
 
         Loading = false;
     }
 
+    Func<PaginationTotalContext, string> showTotal = ctx => $"总数 {ctx.Total} ";
+
+    private async Task OnPageChange(PaginationEventArgs args)
+    {
+        filterData.pageSize = args.PageSize;
+        filterData.currentPage = args.Page;
+        await Query();
+    }
+
     /// <summary>
     /// 清空查询条件
     /// </summary>

+ 43 - 8
Platform/AI.Platform.Page/Pages/Media/Model/MediaModel.cs

@@ -1,5 +1,7 @@
-using AI.Platform.Core.Entity.Media;
+using AI.Platform.Core;
+using AI.Platform.Core.Entity.Media;
 using Microsoft.AspNetCore.Components;
+using SqlSugar;
 using System;
 using System.Collections.Generic;
 using System.Text;
@@ -17,10 +19,25 @@ namespace AI.Platform.Page.Pages.Media.Model
     public class MediaDialogModel
     {
         /// <summary>
-        /// 类型:1:新增;2:编辑;3:删除
+        /// 表id
+        /// </summary>
+        public long? Id { get; set; }
+
+        /// <summary>
+        /// 弹窗类型:1:新增;2:编辑;3:删除
         /// </summary>
         public int Type { get; set; }
 
+        /// <summary>
+        /// 集团ID
+        /// </summary>
+        public string GroupID { get; set; }
+
+        /// <summary>
+        /// 站点ID
+        /// </summary>
+        public string BusinessUnitID { get; set; }
+
         /// <summary>
         /// 文件名
         /// </summary>
@@ -74,7 +91,7 @@ namespace AI.Platform.Page.Pages.Media.Model
         /// <summary>
         /// 文件上传人
         /// </summary>
-        public string MediaUploader { set; get; }
+        public string MediaUploader { set; get; } = Global.CurrentUser.NickName;
 
         /// <summary>
         /// 备注
@@ -84,26 +101,44 @@ namespace AI.Platform.Page.Pages.Media.Model
 
         public MediaEntity ToCompany()
         {
-            
-            return new MediaEntity()
+            var media = new MediaEntity()
             {
                 LocalPath = SavePath,
+                GroupID = this.GroupID ?? "",
+                BusinessUnitID = this.BusinessUnitID ?? "",
                 FileName = FileName,
-                GroupID = "",
-                BusinessUnitID = "",
                 FileExtension = this.FileExtension,
                 GuidFileName = this.GuidFileName,
                 StartTime = this.StartTime ?? 0,
                 EndTime = this.EndTime ?? 0,
                 EffectiveTime = this.EffecitiveTime ?? DateTime.Now,
                 FailureTime = this.FailureTime ?? DateTime.Now,
-                MachineState = JsonSerializer.Serialize(this.MachineStateList),
+                MachineState = JsonSerializer.Serialize(getMachineStateList()),
                 MediaState = this.MediaState,
                 Uploader = this.MediaUploader ?? "",
                 CreateTime = DateTime.Now,
                 EditTime = DateTime.Now,
                 Remark = this.Remark
             };
+            if(this.Id != null) media.Id = (long)Id;
+            return media;
+        }
+
+        /// <summary>
+        /// 获取油机状态列表,为空则返回所有状态
+        /// </summary>
+        /// <returns></returns>
+        public List<string> getMachineStateList()
+        {
+            if (MachineStateList.IsNullOrEmpty())
+            {
+                return new List<string>
+                {
+                    "idle","lock","offline","lift","authorised","start","fueling"
+                };
+            }
+
+            return MachineStateList;
         }
     }
 }

+ 52 - 3
Platform/AI.Platform.Page/Pages/Media/UpdateMediaDialog.razor

@@ -23,7 +23,7 @@
                     </SimpleSelect>
 
                     <span>油机状态</span>
-                    <SimpleSelect DefaultValues="@Model.MachineStateList" OnSelectedItemsChanged="OnSelectItemsChange" Mode="SelectMode.Multiple" style="width:30%">
+                    <SimpleSelect DefaultValues="@Model.getMachineStateList()" OnSelectedItemsChanged="OnSelectItemsChange" Mode="SelectMode.Multiple" style="width:30%">
                         <SelectOptions>
                             <SimpleSelectOption Value="idle" Label="空闲" />
                             <SimpleSelectOption Value="lock" Label="锁枪" />
@@ -37,8 +37,8 @@
                 </div>
 
                 <div class="filter_row">
-                    <span>有效时间段</span><RangePicker TValue="DateTime?[]" OnChange="@(date => onDateChage(date, 1))" />
-                    <span style="margin-right:5%">播放时段</span><RangePicker TValue="DateTime?[]" Picker="DatePickerType.Time" Format="@("HH")" OnChange="@(date => onDateChage(date, 2))" />
+                    <span>有效时间段</span><RangePicker TValue="DateTime?[]" Value="EffecitiveTime"  OnChange="@(date => onDateChage(date, 1))" />
+                    <span style="margin-right:5%">播放时段</span><RangePicker TValue="DateTime?[]" Value="playRange" Picker="DatePickerType.Time" Format="@("HH")" OnChange="@(date => onDateChage(date, 2))" />
                 </div>
 
                 <div class="filter_row" style="justify-content:start">
@@ -59,6 +59,11 @@
                 </Upload>
             }
 
+            @if(Model?.Type == 3)
+            {
+                <h3>是否删除广告?@(Model.FileName)</h3>
+            }
+
             <div class="filter_row" style="justify-content:end;margin-top:5%;">
                 <Button Icon="plus" OnClick="onSure" Style="margin-right:2%">确定</Button>
                 <Button Icon="reload" OnClick="Close" Style="margin-right:2%">取消</Button>
@@ -101,8 +106,42 @@
     /// </summary>
     [Parameter] public bool IsVisible { get; set; }
 
+    /// <summary>
+    /// 上传文件
+    /// </summary>
     private List<UploadFileItem> fileList = new List<UploadFileItem>();
 
+    /// <summary>
+    /// 用于显示当前有效时间范围
+    /// </summary>
+    private DateTime?[] EffecitiveTime = new DateTime?[2];
+
+    /// <summary>
+    /// 用于显示当前播放时段
+    /// </summary>
+    private DateTime?[] playRange = new DateTime?[2];
+
+
+    protected override void OnParametersSet()
+    {
+        fileList.Clear();
+        EffecitiveTime = new DateTime?[]
+        {
+            Model?.EffecitiveTime,
+            Model?.FailureTime
+        };
+
+        int startTimeInt = Math.Max(0, Math.Min(23, Model?.StartTime ?? 0));
+        int endTimeInt = Math.Max(0, Math.Min(23, Model?.EndTime ?? 0));
+        DateTime startTime = DateTime.Today.AddHours(startTimeInt);
+        DateTime endTime = DateTime.Today.AddHours(endTimeInt);
+        playRange = new DateTime?[]
+        {
+          startTime,endTime
+        };
+    }
+
+
     /// <summary>
     /// 关闭弹窗
     /// </summary>
@@ -185,12 +224,22 @@
             case 1:
                 Model.EffecitiveTime = value.Dates[0];
                 Model.FailureTime = value.Dates[1];
+                EffecitiveTime = new DateTime?[]
+                {
+                    value.Dates[0],value.Dates[1]
+                };
                 break;
             case 2:
                 DateTime? startTime = value.Dates[0];
                 DateTime? endTime = value.Dates[1];
                 Model.StartTime = startTime?.Hour;
                 Model.EndTime = endTime?.Hour;
+
+                playRange = new DateTime?[]
+                {
+                     value.Dates[0], value.Dates[1]
+                };
+
                 break;
         }
     }

+ 40 - 0
Platform/AI.Platform.Page/Pages/Media/Utils.cs

@@ -0,0 +1,40 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Text.Json;
+
+namespace AI.Platform.Page.Pages.Media
+{
+    public class Utils
+    {
+        private static Dictionary<string, string> _StateDic = new Dictionary<string, string>()
+        {
+            { "idle","空闲" },{ "lock","锁枪" },{ "offline","脱机" },{ "lift","提枪" },{ "authorised","授权" },{ "start","开始" },{ "fueling","加油中" }
+        };
+
+        /// <summary>
+        /// 根据数据库中的油枪状态json转中文拼接
+        /// </summary>
+        /// <param name="jsonStr"></param>
+        /// <returns></returns>
+        public static string MachineStateJsonToString(string jsonStr)
+        {
+            List<string>? list = JsonSerializer.Deserialize<List<string>>(jsonStr);
+            if (list == null || list.Count == 0) return "";
+
+            var result = "";
+            foreach(string item in list)
+            {
+                string? state = _StateDic.GetValueOrDefault(item);
+                if (state == null || state.Length == 0) continue;
+                 result += state + ",";
+            }
+            return result.Remove(result.Length - 1);
+        }
+
+        public static string JoinDateTime(DateTime start,DateTime end)
+        {
+            return $"{start}-{end}";
+        }
+    }
+}