Browse Source

feat(web):油品信息设置接口

Zhenghanjv 7 months ago
parent
commit
a95ae6b7ba

+ 46 - 2
src/FccLife.Web/Controller/ConfigController.cs

@@ -1,5 +1,8 @@
-using FccLite.Web.Domain.FccStationInfo.Input;
+using FccLite.Web.Domain.FccOilInfo.Input;
+using FccLite.Web.Domain.FccOilInfo.Ouput;
+using FccLite.Web.Domain.FccStationInfo.Input;
 using FccLite.Web.Domain.FccStationInfo.Output;
+using FccLite.Web.Services.FccOilInfo;
 using FccLite.Web.Services.FccStaionInfo;
 using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Mvc;
@@ -14,9 +17,11 @@ namespace FccLite.Web.Controller
     public class ConfigController : ControllerBase
     {
         private readonly IStationService _stationService;
-        public ConfigController(IStationService stationService) 
+        private readonly IOilInfoService _oilInfoService;
+        public ConfigController(IStationService stationService,IOilInfoService oilInfoService) 
         {
             _stationService = stationService;
+            _oilInfoService = oilInfoService;
         }
 
         /// <summary>
@@ -59,5 +64,44 @@ namespace FccLite.Web.Controller
             return Ok(response);
 
         }
+
+        /// <summary>
+        /// 分页获取油品信息
+        /// </summary>
+        /// <param name="page">页数</param>
+        /// <param name="size">页码</param>
+        /// <param name="id">过滤条件——id</param>
+        /// <param name="name">过滤条件——油品名</param>
+        /// <param name="code">过滤条件——油品码</param>
+        /// <returns></returns>
+        [HttpGet("getOilInfo")]
+        public async Task<IActionResult> GetOilInfo(int page,int size,long? id,string? name,int? code)
+        {
+            var response = await _oilInfoService.GetPage(page, size, id, name, code);
+            return Ok(response);
+        }
+
+        /// <summary>
+        /// 新增、修改油品信息
+        /// </summary>
+        /// <param name="oilInfoInput">油品信息</param>
+        /// <returns></returns>
+        [HttpPost("upLoadOilInfo")]
+        public async Task<OilInfoSetOutput> UpLoadOilInfo(OilInfoInput oilInfoInput)
+        {
+            return await _oilInfoService.Save(oilInfoInput);
+        }
+
+        /// <summary>
+        /// 通过 id 删除油品信息
+        /// </summary>
+        /// <param name="id">id</param>
+        /// <returns></returns>
+        [HttpPost("deleteOilInfo")]
+        public async Task<IActionResult> DeleteOilInfo(long id)
+        {
+            var response = await _oilInfoService.DeleteById(id);
+            return Ok(response);
+        }
     }
 }

+ 4 - 1
src/FccLife.Web/Core/database/MysqlDbContext.cs

@@ -1,4 +1,5 @@
-using FccLite.Web.Domain.FccStationInfo;
+using FccLite.Web.Domain.FccOilInfo;
+using FccLite.Web.Domain.FccStationInfo;
 using Microsoft.EntityFrameworkCore;
 
 namespace FccLite.Web.utils.database
@@ -9,6 +10,8 @@ namespace FccLite.Web.utils.database
 
         public DbSet<FccStationInfo> FccStationInfos { get; set; }
 
+        public DbSet<FccOilInfo> OilInfos { get; set; }
+
         protected override void OnModelCreating(ModelBuilder modelBuilder)
         {
             //modelBuilder.Entity<FccStationInfo>(entity =>

+ 6 - 0
src/FccLife.Web/Domain/FccNozzleInfo/NozzleInfo.cs

@@ -0,0 +1,6 @@
+namespace FccLite.Web.Domain.FccNozzleInfo
+{
+    public class NozzleInfo
+    {
+    }
+}

+ 31 - 0
src/FccLife.Web/Domain/FccOilInfo/FccOilInfo.cs

@@ -0,0 +1,31 @@
+using System.ComponentModel.DataAnnotations;
+using System.ComponentModel.DataAnnotations.Schema;
+
+namespace FccLite.Web.Domain.FccOilInfo
+{
+    [Table("qr_oil")]
+    public class FccOilInfo
+    {
+        /// <summary>
+        /// id
+        /// </summary>
+        [Key]
+        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
+        public long Id { get; set; }
+
+        /// <summary>
+        /// 油品码
+        /// </summary>
+        public int Code { get; set; }
+
+        /// <summary>
+        /// 油品名
+        /// </summary>
+        public string Name { get; set; }
+
+        /// <summary>
+        /// 单价
+        /// </summary>
+        public decimal Price { get; set; }
+    }
+}

+ 35 - 0
src/FccLife.Web/Domain/FccOilInfo/Input/OilInfoInput.cs

@@ -0,0 +1,35 @@
+namespace FccLite.Web.Domain.FccOilInfo.Input
+{
+    public class OilInfoInput
+    {
+        /// <summary>
+        /// id
+        /// </summary>
+        public long? Id { get; set; }
+
+        /// <summary>
+        /// 油品id
+        /// </summary>
+        public int Code { get; set; }
+
+        /// <summary>
+        /// 油品名
+        /// </summary>
+        public string Name { get; set; }
+
+        /// <summary>
+        /// 单价
+        /// </summary>
+        public decimal Price { get; set; }
+
+        public FccOilInfo ToComponent()
+        {
+            return new FccOilInfo()
+            {
+                Code = this.Code,
+                Name = this.Name,
+                Price = this.Price,
+            };
+        }
+    }
+}

+ 32 - 0
src/FccLife.Web/Domain/FccOilInfo/Ouput/OilInfoOutput.cs

@@ -0,0 +1,32 @@
+namespace FccLite.Web.Domain.FccOilInfo.Ouput
+{
+    public class OilInfoOutput
+    {
+        public int Total {  get; set; }
+
+        public List<OilInfo> OilInfoList { get; set; }
+
+        public class OilInfo
+        {
+            /// <summary>
+            /// id
+            /// </summary>
+            public long? Id { get; set; }
+
+            /// <summary>
+            /// 油品id
+            /// </summary>
+            public int Code { get; set; }
+
+            /// <summary>
+            /// 油品名
+            /// </summary>
+            public string Name { get; set; }
+
+            /// <summary>
+            /// 单价
+            /// </summary>
+            public decimal Price { get; set; }
+        }
+    }
+}

+ 18 - 0
src/FccLife.Web/Domain/FccOilInfo/Ouput/OilInfoSetOutput.cs

@@ -0,0 +1,18 @@
+namespace FccLite.Web.Domain.FccOilInfo.Ouput
+{
+    /// <summary>
+    /// 新增/修改/删除油品基本信息结果
+    /// </summary>
+    public class OilInfoSetOutput
+    {
+        /// <summary>
+        /// 保存结果
+        /// </summary>
+        public bool Result { get; set; }
+
+        /// <summary>
+        /// 信息
+        /// </summary>
+        public string Message { get; set; }
+    }
+}

+ 5 - 1
src/FccLife.Web/Program.cs

@@ -1,4 +1,6 @@
-using FccLite.Web.Repositories.FccStationInfo;
+using FccLite.Web.Repositories.FccOilInfo;
+using FccLite.Web.Repositories.FccStationInfo;
+using FccLite.Web.Services.FccOilInfo;
 using FccLite.Web.Services.FccStaionInfo;
 using FccLite.Web.utils.database;
 using Microsoft.EntityFrameworkCore;
@@ -18,6 +20,8 @@ builder.Services.AddControllers();
 //服务注册
 builder.Services.AddScoped<IStationService, StationServiceImpl>();
 builder.Services.AddScoped<IStationRepository, StationRepository>();
+builder.Services.AddScoped<IOilInfoService, OilInfoServiceImpl>();
+builder.Services.AddScoped<IOilInfoReposity, OilInfoReposity>();
 
 //swagger
 builder.Services.AddSwaggerGen(c =>

+ 33 - 0
src/FccLife.Web/Repositories/FccOilInfo/IOilInfoReposity.cs

@@ -0,0 +1,33 @@
+
+using FccLite.Web.Domain.FccOilInfo.Input;
+
+namespace FccLite.Web.Repositories.FccOilInfo
+{
+    public interface IOilInfoReposity
+    {
+        /// <summary>
+        /// 新增、更改油品信息
+        /// </summary>
+        /// <param name="oilInfoInput"></param>
+        /// <returns></returns>
+        Task<FccLite.Web.Domain.FccOilInfo.FccOilInfo> UploadOilInfo(OilInfoInput oilInfoInput);
+
+        /// <summary>
+        /// 分页获取油品信息
+        /// </summary>
+        /// <param name="page">页码</param>
+        /// <param name="size">页数</param>
+        /// <param name="id">过滤信息——id</param>
+        /// <param name="name">过滤信息——油品名</param>
+        /// <param name="code">过滤信息——油品码</param>
+        /// <returns></returns>
+        Task<IEnumerable<FccLite.Web.Domain.FccOilInfo.FccOilInfo>> GetPage(int page, int size, long? id, string? name, int? code);
+
+        /// <summary>
+        /// 通过id 删除油品信息
+        /// </summary>
+        /// <param name="id"></param>
+        /// <returns></returns>
+        Task<Boolean> DeleteByID(long id);
+    }
+}

+ 74 - 0
src/FccLife.Web/Repositories/FccOilInfo/OilInfoReposity.cs

@@ -0,0 +1,74 @@
+using FccLite.Web.Core.database;
+using FccLite.Web.Domain.FccOilInfo.Input;
+using FccLite.Web.utils.database;
+using Microsoft.EntityFrameworkCore;
+
+namespace FccLite.Web.Repositories.FccOilInfo
+{
+    public class OilInfoReposity : IOilInfoReposity
+    {
+        private readonly MysqlDbContext _dbContext;
+        public OilInfoReposity(MysqlDbContext mysqlDbContext) 
+        {
+            _dbContext = mysqlDbContext;
+        }
+
+        /// <summary>
+        /// 通过id 删除油品信息
+        /// </summary>
+        /// <param name="id"></param>
+        /// <returns></returns>
+        public async Task<bool> DeleteByID(long id)
+        {
+            Domain.FccOilInfo.FccOilInfo? info = await _dbContext.OilInfos.FindAsync(id);
+            if (info == null) return false;
+            _dbContext.OilInfos.Remove(info);
+            await _dbContext.SaveChangesAsync();
+            return true;
+        }
+
+        /// <summary>
+        /// 分页获取油品信息
+        /// </summary>
+        /// <param name="page">页码</param>
+        /// <param name="size">页数</param>
+        /// <param name="id">过滤信息——id</param>
+        /// <param name="name">过滤信息——油品名</param>
+        /// <param name="code">过滤信息——油品码</param>
+        /// <returns></returns>
+        public async Task<IEnumerable<Domain.FccOilInfo.FccOilInfo>> GetPage(int page, int size, long? id, string? name, int? code)
+        {
+            IQueryable<Domain.FccOilInfo.FccOilInfo> query = _dbContext.OilInfos.AsQueryable();
+
+            query = query.WhereIf(id != null, info => info.Id == id);
+            query = query.WhereIf(!string.IsNullOrEmpty(name), info => info.Name.Contains(name));
+            query = query.WhereIf(code != null, info => info.Code == code);
+
+            return await query.Skip((page - 1) * size).Take(size).ToListAsync();
+        }
+
+        /// <summary>
+        /// 新增、更改油品信息
+        /// </summary>
+        /// <param name="oilInfoInput"></param>
+        /// <returns></returns>
+        public async Task<Domain.FccOilInfo.FccOilInfo> UploadOilInfo(OilInfoInput? oilInfoInput)
+        {
+            if (oilInfoInput == null) return null;
+            if(oilInfoInput.Id != null)
+            {
+                Domain.FccOilInfo.FccOilInfo? info = await _dbContext.OilInfos.FindAsync(oilInfoInput.Id);
+                if (info == null) return null;
+                info.Name = oilInfoInput.Name;
+                info.Code = oilInfoInput.Code;
+                info.Price = oilInfoInput.Price;
+                await _dbContext.SaveChangesAsync();
+                return info;
+            }
+            Domain.FccOilInfo.FccOilInfo fccOilInfo = oilInfoInput.ToComponent();
+            _dbContext.OilInfos.Add(fccOilInfo);
+            await _dbContext.SaveChangesAsync();
+            return fccOilInfo;
+        }
+    }
+}

+ 33 - 0
src/FccLife.Web/Services/FccOilInfo/IOilInfoService.cs

@@ -0,0 +1,33 @@
+using FccLite.Web.Domain.FccOilInfo.Input;
+using FccLite.Web.Domain.FccOilInfo.Ouput;
+
+namespace FccLite.Web.Services.FccOilInfo
+{
+    public interface IOilInfoService
+    {
+        /// <summary>
+        /// 分页获取油品信息
+        /// </summary>
+        /// <param name="page">页码</param>
+        /// <param name="size">页数</param>
+        /// <param name="id">过滤条件——id</param>
+        /// <param name="name">过滤条件——油品名</param>
+        /// <param name="code">过滤条件——油品码</param>
+        /// <returns></returns>
+        Task<OilInfoOutput> GetPage(int page, int size, long? id, string? name, int? code);
+
+        /// <summary>
+        /// 新增、修改油品信息
+        /// </summary>
+        /// <param name="oilInfoInput">油品信息</param>
+        /// <returns></returns>
+        Task<OilInfoSetOutput> Save(OilInfoInput oilInfoInput);
+
+        /// <summary>
+        /// 通过 id 删除油品信息
+        /// </summary>
+        /// <param name="id">id</param>
+        /// <returns></returns>
+        Task<OilInfoSetOutput> DeleteById(long id);
+    }
+}

+ 93 - 0
src/FccLife.Web/Services/FccOilInfo/OilInfoServiceImpl.cs

@@ -0,0 +1,93 @@
+using FccLite.Web.Domain.FccOilInfo.Input;
+using FccLite.Web.Domain.FccOilInfo.Ouput;
+using FccLite.Web.Repositories.FccOilInfo;
+
+namespace FccLite.Web.Services.FccOilInfo
+{
+    public class OilInfoServiceImpl : IOilInfoService
+    {
+        private readonly IOilInfoReposity _oilInfoReposity;
+        public OilInfoServiceImpl(IOilInfoReposity oilInfoReposity) 
+        {
+            _oilInfoReposity = oilInfoReposity;
+        }
+
+        /// <summary>
+        /// 通过 id 删除油品信息
+        /// </summary>
+        /// <param name="id">id</param>
+        /// <returns></returns>
+        public async Task<OilInfoSetOutput> DeleteById(long id)
+        {
+            bool result = await _oilInfoReposity.DeleteByID(id);
+            if (result)
+            {
+                return new OilInfoSetOutput()
+                {
+                    Result = true,
+                    Message = "删除成功"
+                };
+            }
+
+            return new OilInfoSetOutput()
+            {
+                Result = false,
+                Message = "删除失败"
+            };
+        }
+
+        /// <summary>
+        /// 分页获取油品信息
+        /// </summary>
+        /// <param name="page">页码</param>
+        /// <param name="size">页数</param>
+        /// <param name="id">过滤条件——id</param>
+        /// <param name="name">过滤条件——油品名</param>
+        /// <param name="code">过滤条件——油品码</param>
+        /// <returns></returns>
+        public async Task<OilInfoOutput> GetPage(int page, int size, long? id, string? name, int? code)
+        {
+            IEnumerable<Domain.FccOilInfo.FccOilInfo> enumerable = await _oilInfoReposity.GetPage(page, size, id, name, code);
+
+            List<OilInfoOutput.OilInfo> oilInfos = enumerable.Select(info =>
+                new OilInfoOutput.OilInfo()
+                {
+                    Id = info.Id,
+                    Name = info.Name,
+                    Code = info.Code,
+                    Price = info.Price
+                }
+            ).ToList();
+
+            return new OilInfoOutput()
+            {
+                Total = oilInfos.Count,
+                OilInfoList = oilInfos
+            };
+        }
+
+        /// <summary>
+        /// 新增、修改油品信息
+        /// </summary>
+        /// <param name="oilInfoInput">油品信息</param>
+        /// <returns></returns>
+        public async Task<OilInfoSetOutput> Save(OilInfoInput oilInfoInput)
+        {
+            Domain.FccOilInfo.FccOilInfo fccOilInfo = await _oilInfoReposity.UploadOilInfo(oilInfoInput);
+            if (fccOilInfo == null)
+            {
+                return new OilInfoSetOutput()
+                {
+                    Result = false,
+                    Message = "保存失败"
+                };
+            }
+
+            return new OilInfoSetOutput()
+            {
+                Result = true,
+                Message = "保存成功"
+            };
+        }
+    }
+}