Browse Source

PDA安装包管理

user_zyx 1 year ago
parent
commit
ee4b0791b8

+ 150 - 0
ZrAdminNetCore-net7.0/ZR.Admin.WebApi/Controllers/System/PdaAutoUpdateController.cs

@@ -0,0 +1,150 @@
+using Infrastructure;
+using Infrastructure.Attribute;
+using Infrastructure.Enums;
+using Infrastructure.Model;
+using Mapster;
+using Microsoft.AspNetCore.Mvc;
+using ZR.Model.Dto;
+using ZR.Model.Models;
+using ZR.Service.Business.IBusinessService;
+using ZR.Admin.WebApi.Extensions;
+using ZR.Admin.WebApi.Filters;
+using ZR.Common;
+using ZR.Model.System;
+using ZR.Service.System.IService;
+using System.Data;
+using ZR.Model.Dto.Inspect;
+using ZR.Model.Models.Inspect;
+
+namespace ZR.Admin.WebApi.Controllers
+{
+    /// <summary>
+    /// Controller
+    /// 
+    /// @tableName pda_auto_update
+    /// @author admin
+    /// @date 2024-03-18
+    /// </summary>
+    [Verify]
+    [Route("business/PdaAutoUpdate")]
+    public class PdaAutoUpdateController : BaseController
+    {
+        /// <summary>
+        /// 接口
+        /// </summary>
+        private readonly IPdaAutoUpdateService _PdaAutoUpdateService;
+        private readonly ISysFileService FileService;
+        private IWebHostEnvironment hostEnvironment;
+
+        public PdaAutoUpdateController(IPdaAutoUpdateService PdaAutoUpdateService,
+            ISysFileService sysFileService,
+            IWebHostEnvironment hostEnvironment)
+        {
+            _PdaAutoUpdateService = PdaAutoUpdateService;
+            FileService = sysFileService;
+            this.hostEnvironment = hostEnvironment;
+        }
+
+        /// <summary>
+        /// 查询列表
+        /// </summary>
+        /// <param name="parm"></param>
+        /// <returns></returns>
+        [HttpGet("list")]
+        [ActionPermissionFilter(Permission = "business:pdaautoupdate:list")]
+        public IActionResult QueryPdaAutoUpdate([FromQuery] PdaAutoUpdateQueryDto parm)
+        {
+            var response = _PdaAutoUpdateService.GetList(parm);
+            return SUCCESS(response);
+        }
+
+
+        /// <summary>
+        /// 查询详情
+        /// </summary>
+        /// <param name="Id"></param>
+        /// <returns></returns>
+        [HttpGet("{Id}")]
+        [ActionPermissionFilter(Permission = "business:pdaautoupdate:query")]
+        public IActionResult GetPdaAutoUpdate(int Id)
+        {
+            var response = _PdaAutoUpdateService.GetFirst(x => x.Id == Id);
+
+            return SUCCESS(response);
+        }
+
+        /// <summary>
+        /// 添加
+        /// </summary>
+        /// <returns></returns>
+        [HttpPost]
+        [ActionPermissionFilter(Permission = "business:pdaautoupdate:add")]
+        [Log(Title = "", BusinessType = BusinessType.INSERT)]
+        public IActionResult AddPdaAutoUpdate([FromBody] PdaAutoUpdateDto parm)
+        {
+            if (parm == null)
+            {
+                throw new CustomException("请求参数错误");
+            }
+            var modal = parm.Adapt<PdaAutoUpdate>().ToCreate(HttpContext);
+
+            var response = _PdaAutoUpdateService.AddPdaAutoUpdate(modal);
+
+            return ToResponse(response);
+        }
+
+        /// <summary>
+        /// 更新
+        /// </summary>
+        /// <returns></returns>
+        [HttpPut]
+        [ActionPermissionFilter(Permission = "business:pdaautoupdate:edit")]
+        [Log(Title = "", BusinessType = BusinessType.UPDATE)]
+        public IActionResult UpdatePdaAutoUpdate([FromBody] PdaAutoUpdateDto parm)
+        {
+            if (parm == null)
+            {
+                throw new CustomException("请求实体不能为空");
+            }
+            var modal = parm.Adapt<PdaAutoUpdate>().ToUpdate(HttpContext);
+
+            var response = _PdaAutoUpdateService.UpdatePdaAutoUpdate(modal);
+
+            return ToResponse(response);
+        }
+
+        /// <summary>
+        /// 删除
+        /// </summary>
+        /// <returns></returns>
+        [HttpDelete("{ids}")]
+        [ActionPermissionFilter(Permission = "business:pdaautoupdate:delete")]
+        [Log(Title = "", BusinessType = BusinessType.DELETE)]
+        public IActionResult DeletePdaAutoUpdate(string ids)
+        {
+            int[] idsArr = Tools.SpitIntArrary(ids);
+            if (idsArr.Length <= 0) { return ToResponse(ApiResult.Error($"删除失败Id 不能为空")); }
+
+            var response = _PdaAutoUpdateService.Delete(idsArr);
+
+            return ToResponse(response);
+        }
+
+        /// <summary>
+        /// 导入
+        /// </summary>
+        /// <param name="formFile">使用IFromFile必须使用name属性否则获取不到文件</param>
+        /// <returns></returns>
+        [HttpPost("upload")]
+        [Log(Title = "PDA软件安装包导入", BusinessType = BusinessType.IMPORT, IsSaveRequestData = false, IsSaveResponseData = false)]
+        [ActionPermissionFilter(Permission = "business:pdaautoupdate:import")]
+        public async Task<IActionResult> ImportDataAsync([FromForm(Name = "file")] IFormFile formFile)
+        {
+            SysFile file = await FileService.SaveFileToLocalNoDateDir(hostEnvironment.WebRootPath, formFile.FileName,"" , HttpContext.GetName(), formFile);
+            //TODO 业务逻辑,自行插入数据到db
+            return SUCCESS($"上传{file.FileName}成功。");
+        }
+
+
+    }
+}

+ 10 - 0
ZrAdminNetCore-net7.0/ZR.Admin.WebApi/ZRModel.xml

@@ -285,6 +285,16 @@
             多语言配置查询对象
             </summary>
         </member>
+        <member name="T:ZR.Model.Dto.PdaAutoUpdateQueryDto">
+            <summary>
+            查询对象
+            </summary>
+        </member>
+        <member name="T:ZR.Model.Dto.PdaAutoUpdateDto">
+            <summary>
+            输入输出对象
+            </summary>
+        </member>
         <member name="T:ZR.Model.Models.Balance.StkBalanceDtl">
              <summary>
              库存管理/库存明细表,数据实体对象

+ 4 - 4
ZrAdminNetCore-net7.0/ZR.Admin.WebApi/appsettings.json

@@ -7,8 +7,8 @@
     }
   },
   "ConnectionStrings": {
-    "conn_db": "Data Source=localhost;port=3306;User ID=sa;Password=sa123456;Database=mytest_db;CharSet=utf8;sslmode=none;",
-    //"conn_db": "Data Source=39.106.7.239;port=3306;User ID=sa;Password=123456;Database=mytest_db;CharSet=utf8;sslmode=none;",
+    //"conn_db": "Data Source=localhost;port=3306;User ID=sa;Password=sa123456;Database=mytest_db;CharSet=utf8;sslmode=none;",
+    "conn_db": "Data Source=39.106.7.239;port=3306;User ID=sa;Password=123456;Database=mytest_db;CharSet=utf8;sslmode=none;",
     //"conn_db": "Data Source=192.168.0.1;port=3306;User ID=sa;Password=123456;Database=mytest_db;CharSet=utf8;sslmode=none;",
     "conn_db_type": "0" //数据库类型 MySql = 0, SqlServer = 1, Oracle = 3
   },
@@ -45,8 +45,8 @@
     "SendUser": "@all"
   },
   "gen": {
-    "conn": "Data Source=localhost;port=3306;User ID=sa;Password=sa123456;Database=mytest_db;CharSet=utf8;sslmode=none;",
-    //"conn": "Data Source=39.106.7.239;port=3306;User ID=sa;Password=123456;Database=mytest_db;CharSet=utf8;sslmode=none;",
+    //"conn": "Data Source=localhost;port=3306;User ID=sa;Password=sa123456;Database=mytest_db;CharSet=utf8;sslmode=none;",
+    "conn": "Data Source=39.106.7.239;port=3306;User ID=sa;Password=123456;Database=mytest_db;CharSet=utf8;sslmode=none;",
     //"conn": "Data Source=192.168.0.1;port=3306;User ID=sa;Password=123456;Database=mytest_db;CharSet=utf8;sslmode=none;",
     "dbType": 0, //MySql = 0, SqlServer = 1
     "autoPre": true, //自动去除表前缀

BIN
ZrAdminNetCore-net7.0/ZR.Admin.WebApi/wwwroot/TFT_PDA_20240314_test.apk


BIN
ZrAdminNetCore-net7.0/ZR.Admin.WebApi/wwwroot/avatar/20240319/7901BA7307527C4D.png


+ 51 - 0
ZrAdminNetCore-net7.0/ZR.Model/System/Dto/PdaAutoUpdateDto.cs

@@ -0,0 +1,51 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using Newtonsoft.Json;
+using ZR.Model.Dto;
+using ZR.Model.Models;
+
+namespace ZR.Model.Dto
+{
+    /// <summary>
+    /// 查询对象
+    /// </summary>
+    public class PdaAutoUpdateQueryDto : PagerInfo
+    {
+        public string PackageName { get; set; }
+        public int? VersionNo { get; set; }
+        public string VersionName { get; set; }
+        public string UpdateDetails { get; set; }
+        public DateTime? BeginTime { get; set; }
+        public DateTime? EndTime { get; set; }
+    }
+
+    /// <summary>
+    /// 输入输出对象
+    /// </summary>
+    public class PdaAutoUpdateDto
+    {
+        [Required(ErrorMessage = "不能为空")]
+        public int Id { get; set; }
+
+        [Required(ErrorMessage = "安装包名称不能为空")]
+        public string PackageName { get; set; }
+
+        [Required(ErrorMessage = "版本号不能为空")]
+        public int VersionNo { get; set; }
+
+        [Required(ErrorMessage = "版本名称不能为空")]
+        public string VersionName { get; set; }
+
+        [Required(ErrorMessage = "发布时间不能为空")]
+        public DateTime? PublishTime { get; set; }
+
+        [Required(ErrorMessage = "更新内容不能为空")]
+        public string UpdateDetails { get; set; }
+
+        public string Remark { get; set; }
+
+
+
+    }
+}

+ 6 - 0
ZrAdminNetCore-net7.0/ZR.Service/System/IService/IPdaAutoUpdateService.cs

@@ -3,6 +3,8 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using ZR.Model.Dto;
+using ZR.Model;
 using ZR.Model.System;
 
 namespace ZR.Service.System.IService
@@ -10,6 +12,10 @@ namespace ZR.Service.System.IService
     public interface IPdaAutoUpdateService : IBaseService<PdaAutoUpdate>
     {
         int AddPdaAutoUpdate(PdaAutoUpdate model);
+
+        PagedInfo<PdaAutoUpdateDto> GetList(PdaAutoUpdateQueryDto parm);
+
+        int UpdatePdaAutoUpdate(PdaAutoUpdate parm);
         PdaAutoUpdate GetPdaLatestmsg();
     }
 }

+ 5 - 4
ZrAdminNetCore-net7.0/ZR.Service/System/IService/ISysFileService.cs

@@ -13,13 +13,14 @@ namespace ZR.Service.System.IService
         /// <summary>
         /// 上传文件
         /// </summary>
-        /// <param name="fileDir"></param>
-        /// <param name="fileName"></param>
-        /// <param name="formFile"></param>
-        /// <param name="rootPath"></param>
+        /// <param name="fileDir">存储文件夹</param>
+        /// <param name="rootPath">存储根目录</param>
+        /// <param name="fileName">自定文件名</param>
+        /// <param name="formFile">上传的文件流</param>
         /// <param name="userName"></param>
         /// <returns>文件对象</returns>
         Task<SysFile> SaveFileToLocal(string rootPath, string fileName, string fileDir, string userName, IFormFile formFile);
+        Task<SysFile> SaveFileToLocalNoDateDir(string rootPath, string fileName, string fileDir, string userName, IFormFile formFile);
 
         Task<SysFile> SaveFileToAliyun(SysFile file, IFormFile formFile);
         /// <summary>

+ 50 - 0
ZrAdminNetCore-net7.0/ZR.Service/System/PdaAutoUpdateService.cs

@@ -1,11 +1,15 @@
 using Infrastructure.Attribute;
+using SqlSugar;
 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using ZR.Model;
+using ZR.Model.Dto;
 using ZR.Model.Models.Inspect;
 using ZR.Model.System;
+using ZR.Repository;
 using ZR.Service.System.IService;
 
 namespace ZR.Service.System
@@ -32,6 +36,52 @@ namespace ZR.Service.System
                 .OrderByDescending(x => x.Id).First();
             return response;
         }
+
+        #region 2024年3月18日 赵亚雄
+        /// <summary>
+        /// 查询列表
+        /// </summary>
+        /// <param name="parm"></param>
+        /// <returns></returns>
+        public PagedInfo<PdaAutoUpdateDto> GetList(PdaAutoUpdateQueryDto parm)
+        {
+            //开始拼装查询条件
+            var predicate = Expressionable.Create<PdaAutoUpdate>();
+
+            predicate.AndIF(parm.BeginTime != null && parm.EndTime != null, q => q.PublishTime > parm.BeginTime && q.PublishTime < parm.EndTime);
+            predicate.AndIF(!string.IsNullOrEmpty(parm.PackageName), q => q.PackageName.Contains(parm.PackageName));
+            predicate.AndIF(parm.VersionNo != null, q => q.VersionNo == parm.VersionNo);
+            predicate.AndIF(!string.IsNullOrEmpty(parm.VersionName), q => q.VersionName.Contains(parm.VersionName));
+            predicate.AndIF(!string.IsNullOrEmpty(parm.UpdateDetails), q => q.UpdateDetails.Contains(parm.UpdateDetails));
+
+            //搜索条件查询语法参考Sqlsugar
+            var response = Queryable()
+                .Where(predicate.ToExpression())
+                .ToPage<PdaAutoUpdate, PdaAutoUpdateDto>(parm);
+
+            return response;
+        }
+        /// <summary>
+        /// 修改
+        /// </summary>
+        /// <param name="model"></param>
+        /// <returns></returns>
+        public int UpdatePdaAutoUpdate(PdaAutoUpdate model)
+        {
+            //var response = Update(w => w.Id == model.Id, it => new PdaAutoUpdate()
+            //{
+            //    PackageName = model.PackageName,
+            //    VersionNo = model.VersionNo,
+            //    VersionName = model.VersionName,
+            //    PublishTime = model.PublishTime,
+            //    UpdateDetails = model.UpdateDetails,
+            //    Remark = model.Remark,
+            //});
+            //return response;
+            return Update(model, true);
+        }
+
+        #endregion
         #endregion
     }
 }

+ 29 - 0
ZrAdminNetCore-net7.0/ZR.Service/System/SysFileService.cs

@@ -69,6 +69,35 @@ namespace ZR.Service.System
             file.Id = await InsertFile(file);
             return file;
         }
+        public async Task<SysFile> SaveFileToLocalNoDateDir(string rootPath, string fileName, string fileDir, string userName, IFormFile formFile)
+        {
+            string fileExt = Path.GetExtension(formFile.FileName);
+            fileName = fileName.IsEmpty() ? HashFileName() + fileExt : fileName;
+
+            string finalFilePath = Path.Combine(rootPath, fileDir, fileName);
+            double fileSize = Math.Round(formFile.Length / 1024.0, 2);
+
+            if (!Directory.Exists(Path.GetDirectoryName(finalFilePath)))
+            {
+                Directory.CreateDirectory(Path.GetDirectoryName(finalFilePath));
+            }
+
+            using (var stream = new FileStream(finalFilePath, FileMode.Create))
+            {
+                await formFile.CopyToAsync(stream);
+            }
+            string uploadUrl = OptionsSetting.Upload.UploadUrl;
+            string accessPath = string.Concat(uploadUrl, "/", fileDir.Replace("\\", "/"), "/", fileName);
+            SysFile file = new(formFile.FileName, fileName, fileExt, fileSize + "kb", fileDir, userName)
+            {
+                StoreType = (int)Infrastructure.Enums.StoreType.LOCAL,
+                FileType = formFile.ContentType,
+                FileUrl = finalFilePath.Replace("\\", "/"),
+                AccessUrl = accessPath
+            };
+            file.Id = await InsertFile(file);
+            return file;
+        }
 
         /// <summary>
         /// 上传文件到阿里云