fix 成本中心统计
This commit is contained in:
@@ -83,7 +83,7 @@ public class BalancesController : ControllerBase
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("recordByCostI")]
|
||||
public async Task<Pagination<BalanceRecordResponse>> RecordByCostIdAsync([FromQuery] BalanceRecordPageByCostIdRequest request)
|
||||
public async Task<List<BalanceRecordCostIdResponse>> RecordByCostIdAsync([FromQuery] BalanceRecordPageByCostIdRequest request)
|
||||
{
|
||||
return await _balanceService.RecordByCostIdAsync(request);
|
||||
}
|
||||
|
||||
@@ -3,12 +3,37 @@ using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Dlhis.Canteen.Order.Request
|
||||
{
|
||||
public class BalanceRecordPageByCostIdRequest : PageDto
|
||||
public class BalanceRecordPageByCostIdRequest :PageDto
|
||||
{
|
||||
/// <summary>
|
||||
/// 成本中心
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "成本中心号不能为空")]
|
||||
public string CostId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 学工号
|
||||
/// </summary>
|
||||
public string UserCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 开始日期
|
||||
/// </summary>
|
||||
public DateTime? StartDatetime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 结束日期
|
||||
/// </summary>
|
||||
public DateTime? EndDatetime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 部门号
|
||||
/// </summary>
|
||||
public string DepartmentNo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 人事范围
|
||||
/// </summary>
|
||||
public string OriginTenantId { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
namespace Dlhis.Canteen.Order.Response
|
||||
{
|
||||
public class BalanceRecordCostIdResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// 成本中心
|
||||
/// </summary>
|
||||
public string CostId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 早餐人数
|
||||
/// </summary>
|
||||
|
||||
public int BreakfastNumberOfPeople { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 早餐单价price
|
||||
/// </summary>
|
||||
|
||||
public decimal BreakfastPrice { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 早餐金额
|
||||
/// </summary>
|
||||
|
||||
public decimal BreakfastAmount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 午餐人数
|
||||
/// </summary>
|
||||
|
||||
public int LunchNumberOfPeople { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 午餐单价price
|
||||
/// </summary>
|
||||
|
||||
public decimal LunchPrice { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 午餐金额
|
||||
/// </summary>
|
||||
|
||||
public decimal LunchAmount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 晚餐人数
|
||||
/// </summary>
|
||||
|
||||
public int DinnerNumberOfPeople { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 晚餐单价price
|
||||
/// </summary>
|
||||
|
||||
public decimal DinnerPrice { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 晚餐金额
|
||||
/// </summary>
|
||||
|
||||
public decimal DinnerAmount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 宵夜人数
|
||||
/// </summary>
|
||||
|
||||
public int LateNightNumberOfPeople { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 宵夜单价price
|
||||
/// </summary>
|
||||
|
||||
public decimal LateNightPrice { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 宵夜金额
|
||||
/// </summary>
|
||||
|
||||
public decimal LateNightAmount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 总金额
|
||||
/// </summary>
|
||||
|
||||
public decimal TotalAmount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 总人数
|
||||
/// </summary>
|
||||
|
||||
public int TotalNumberOfPeople { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ public interface IBalanceService : IScopeDependency
|
||||
|
||||
Task ObsoluteAsync(BalanceRecordObsoluteRequest request);
|
||||
|
||||
Task<Pagination<BalanceRecordResponse>> RecordByCostIdAsync(BalanceRecordPageByCostIdRequest request);
|
||||
Task<List<BalanceRecordCostIdResponse>> RecordByCostIdAsync(BalanceRecordPageByCostIdRequest request);
|
||||
|
||||
Task<Pagination<BalanceRecordResponse>> RecordPageDetailsAsync(BalanceRecordPageDetailsRequest request);
|
||||
|
||||
|
||||
@@ -73,45 +73,61 @@ public class BalanceService : IBalanceService
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<Pagination<BalanceRecordResponse>> RecordByCostIdAsync(BalanceRecordPageByCostIdRequest request)
|
||||
public async Task<List<BalanceRecordCostIdResponse>> RecordByCostIdAsync(BalanceRecordPageByCostIdRequest request)
|
||||
{
|
||||
var pageinfo = await _dbContext.Queryable<BalanceRecordEntity>()
|
||||
.LeftJoin<DepartmentEntity>((record, department) => record.DepartmentNo == department.No)
|
||||
.LeftJoin<CanteenBusinessPlaceEntity>((record, department, bplace) => record.BusinessPlaceCode == bplace.Code)
|
||||
.LeftJoin<CanteenBusinessShiftEntity>((record, department, bplace, bshift) => record.BusinessShiftCode == bshift.Code)
|
||||
.LeftJoin<BasicTypeEntity>((record, department, bplace, bshift, type) => record.BusinessShiftCode.ToString() == type.Code)
|
||||
.Where(record => record.CostId == request.CostId)
|
||||
.OrderBy(record => record.CreateTime, OrderByType.Desc)
|
||||
.Select((record, department, bplace, bshift, type) => new BalanceRecordResponse
|
||||
{
|
||||
Id = record.Id,
|
||||
Amount = record.Amount,
|
||||
BusinessPlaceCode = record.BusinessPlaceCode,
|
||||
BusinessShiftCode = record.BusinessShiftCode,
|
||||
CostDate = record.CostDate,
|
||||
CostId = record.CostId,
|
||||
DepartmentNo = record.DepartmentNo,
|
||||
DeviceInfo = record.DeviceInfo,
|
||||
IP = record.IP,
|
||||
UserNo = record.UserNo,
|
||||
UserCode = record.UserCode,
|
||||
Type = record.Type,
|
||||
SubsidiesFromMonth = record.SubsidiesFromMonth,
|
||||
Status = record.Status,
|
||||
Source = record.Source,
|
||||
No = record.No,
|
||||
IsCostCrossTenant = record.IsCostCrossTenant,
|
||||
OriginTenantId = record.OriginTenantId,
|
||||
Name = record.Name,
|
||||
DepartmentName = department.Name,
|
||||
BusinessPlaceName = bplace.Name,
|
||||
BusinessShiftName = type.Display,
|
||||
CostDateTime = record.CreateTime // todo
|
||||
})
|
||||
.ToPageListAsync(request);
|
||||
var shiftCodeDict = await GetShiftCode();
|
||||
|
||||
return pageinfo;
|
||||
var paeginfos = await _dbContext.Queryable<BalanceRecordEntity>()
|
||||
.WhereIF(!request.UserCode.IsEmpty(), record => record.UserCode == request.UserCode)
|
||||
.WhereIF(!request.DepartmentNo.IsEmpty(), record => record.DepartmentNo == request.DepartmentNo)
|
||||
.WhereIF(!request.OriginTenantId.IsEmpty(), record => record.OriginTenantId == request.OriginTenantId)
|
||||
.WhereIF(request.StartDatetime.HasValue, record => record.CostDateTime >= request.StartDatetime)
|
||||
.WhereIF(request.EndDatetime.HasValue, record => record.CostDateTime <= request.EndDatetime)
|
||||
.Where(record => record.Type == BalanceRecordTypeEnumType.Out)
|
||||
.OrderBy(record => record.CreateTime, OrderByType.Desc)
|
||||
.ToListAsync();
|
||||
|
||||
var lst = new List<BalanceRecordCostIdResponse>();
|
||||
foreach (var costIdGroup in paeginfos.GroupBy(record => record.CostId))
|
||||
{
|
||||
//每个costID
|
||||
var obj = new BalanceRecordCostIdResponse
|
||||
{
|
||||
CostId = costIdGroup.Key
|
||||
};
|
||||
|
||||
// 每个餐次人数
|
||||
obj.BreakfastNumberOfPeople = costIdGroup.Count(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Breakfast"]);
|
||||
|
||||
obj.LunchNumberOfPeople = costIdGroup.Count(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Lunch"]);
|
||||
|
||||
obj.DinnerNumberOfPeople = costIdGroup.Count(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Dinner"]);
|
||||
|
||||
obj.LateNightNumberOfPeople = costIdGroup.Count(x => x.BusinessShiftCode.ToString() == shiftCodeDict["LateNight"]);
|
||||
|
||||
//餐次金额
|
||||
obj.BreakfastAmount = costIdGroup.Where(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Breakfast"]).Sum(x => x.Amount);
|
||||
|
||||
obj.LunchAmount = costIdGroup.Where(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Lunch"]).Sum(x => x.Amount);
|
||||
|
||||
obj.DinnerAmount = costIdGroup.Where(x => x.BusinessShiftCode.ToString() == shiftCodeDict["Dinner"]).Sum(x => x.Amount);
|
||||
|
||||
obj.LateNightAmount = costIdGroup.Where(x => x.BusinessShiftCode.ToString() == shiftCodeDict["LateNight"]).Sum(x => x.Amount);
|
||||
|
||||
// 每个餐次单价
|
||||
obj.BreakfastPrice = obj.BreakfastNumberOfPeople == 0 ? 0 : obj.BreakfastAmount / obj.BreakfastNumberOfPeople;
|
||||
obj.LunchPrice = obj.LunchNumberOfPeople == 0 ? 0 : obj.LunchAmount / obj.LunchNumberOfPeople;
|
||||
obj.DinnerPrice = obj.DinnerNumberOfPeople == 0 ? 0 : obj.DinnerAmount / obj.DinnerNumberOfPeople;
|
||||
obj.LateNightPrice = obj.LateNightNumberOfPeople == 0 ? 0 : obj.LateNightAmount / obj.LateNightNumberOfPeople;
|
||||
|
||||
// 总人数 总金额
|
||||
obj.TotalNumberOfPeople = obj.BreakfastNumberOfPeople + obj.LunchNumberOfPeople + obj.DinnerNumberOfPeople + obj.LateNightNumberOfPeople;
|
||||
obj.TotalAmount = obj.BreakfastAmount + obj.LunchAmount + obj.DinnerAmount + obj.LateNightAmount;
|
||||
lst.Add(obj);
|
||||
}
|
||||
return lst;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 消费明细
|
||||
/// </summary>
|
||||
|
||||
@@ -27,20 +27,20 @@ public class ApkFIileController : ControllerBase
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task FormSingleFileUpload([FromForm] ApkRequest request)
|
||||
public async Task<ApkFileResponse> FormSingleFileUpload([FromForm] ApkRequest request)
|
||||
{
|
||||
await _apkFIileService.FormSingleFileUpload(request);
|
||||
return await _apkFIileService.FormSingleFileUpload(request);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 文件下载
|
||||
/// </summary>
|
||||
/// <param name="filename"></param>
|
||||
/// <param name="fileName"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("url")]
|
||||
public async Task<string> RequestDownloadFile()
|
||||
public async Task<string> RequestDownloadFile(string fileName)
|
||||
{
|
||||
return await _apkFIileService.RequestDownloadFile();
|
||||
return await _apkFIileService.RequestDownloadFile(fileName);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -3,11 +3,11 @@ using Kurisu.SqlSugar.Extensions;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Minio;
|
||||
|
||||
//namespace Dlhis.Common.Packs
|
||||
//{
|
||||
// public class MinioPack : BaseAppPack
|
||||
// {
|
||||
// public override bool IsBeforeUseRouting { get; }
|
||||
namespace Dlhis.Common.Packs
|
||||
{
|
||||
public class MinioPack : BaseAppPack
|
||||
{
|
||||
public override bool IsBeforeUseRouting { get; }
|
||||
|
||||
public override void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
|
||||
@@ -10,13 +10,13 @@ namespace Dlhis.Common.Services;
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
Task FormSingleFileUpload(ApkRequest request);
|
||||
Task<ApkFileResponse> FormSingleFileUpload(ApkRequest request);
|
||||
|
||||
/// <summary>
|
||||
/// 文件下载
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<string> RequestDownloadFile();
|
||||
Task<string> RequestDownloadFile(string fileName);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ namespace Dlhis.Common.Services
|
||||
{
|
||||
public interface IMinioService : IScopeDependency
|
||||
{
|
||||
Task MinloUploadFileAsync(ApkRequest request);
|
||||
Task<string> MinloDownloadLinkAsync();
|
||||
Task MinloRemoveFileAsync(ApkRequest request);
|
||||
Task<string> MinloUploadFileAsync(ApkRequest request);
|
||||
Task<string> MinloDownloadLinkAsync(string fileName);
|
||||
Task MinloRemoveFileAsync(string fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,29 +2,19 @@
|
||||
using Dlhis.Common.Response;
|
||||
using Dlhis.Entity.Common;
|
||||
using Kurisu.SqlSugar.Services;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Minio;
|
||||
using Minio.DataModel;
|
||||
using Minio.DataModel.Args;
|
||||
using Minio.Exceptions;
|
||||
using System.Xml.Linq;
|
||||
using System;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
using Minio.DataModel.Encryption;
|
||||
using MySqlX.XDevAPI;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.IO;
|
||||
using Mapster;
|
||||
|
||||
namespace Dlhis.Common.Services.Implements;
|
||||
|
||||
public class ApkFIileService : IApkFIileService
|
||||
{
|
||||
private readonly IMinioService _minioService;
|
||||
private readonly IDbContext _dbContext;
|
||||
|
||||
public ApkFIileService( IMinioService minioService)
|
||||
public ApkFIileService(IMinioService minioService, IDbContext dbContext)
|
||||
{
|
||||
_minioService = minioService;
|
||||
_dbContext = dbContext;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -32,18 +22,45 @@ public class ApkFIileService : IApkFIileService
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
public async Task FormSingleFileUpload(ApkRequest request)
|
||||
public async Task<ApkFileResponse> FormSingleFileUpload(ApkRequest request)
|
||||
{
|
||||
await _minioService.MinloUploadFileAsync(request);
|
||||
//上传
|
||||
var fileUrl = await _minioService.MinloUploadFileAsync(request);
|
||||
|
||||
string fileName = request.formFile.FileName;
|
||||
|
||||
//更新数据库
|
||||
var entity = await _dbContext.Queryable<ApkFileEntity>().Where(x => x.Name == fileName).FirstAsync();
|
||||
if (entity == null)
|
||||
{
|
||||
var info = new ApkFileEntity
|
||||
{
|
||||
Name = fileName,
|
||||
Url = fileUrl,
|
||||
VersionCode = request.VersionCode,
|
||||
UpdateMessage = request.UpdateMessage,
|
||||
};
|
||||
await _dbContext.InsertAsync(info);
|
||||
}
|
||||
else
|
||||
{
|
||||
entity.Url = fileUrl;
|
||||
entity.VersionCode = request.VersionCode;
|
||||
entity.UpdateMessage = request.UpdateMessage;
|
||||
await _dbContext.UpdateAsync(entity);
|
||||
}
|
||||
var newEntity = await _dbContext.Queryable<ApkFileEntity>().Where(x => x.Name == fileName).FirstAsync();
|
||||
var res = newEntity.Adapt<ApkFileResponse>();
|
||||
return res;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 文件下载
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<string> RequestDownloadFile()
|
||||
public async Task<string> RequestDownloadFile(string fileName)
|
||||
{
|
||||
return await _minioService.MinloDownloadLinkAsync();
|
||||
return await _minioService.MinloDownloadLinkAsync(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,15 +12,12 @@ namespace Dlhis.Common.Services.Implements
|
||||
{
|
||||
public class MinioService : IMinioService
|
||||
{
|
||||
|
||||
private readonly IDbContext _dbContext;
|
||||
private readonly IMinioClient _client;
|
||||
|
||||
private static string bucketName = "apk";
|
||||
|
||||
public MinioService(IDbContext dbContext, IMinioClient client)
|
||||
public MinioService( IMinioClient client)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_client = client;
|
||||
}
|
||||
|
||||
@@ -30,55 +27,36 @@ namespace Dlhis.Common.Services.Implements
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
public async Task MinloUploadFileAsync(ApkRequest request)
|
||||
public async Task<string> MinloUploadFileAsync(ApkRequest request)
|
||||
{
|
||||
string fileName = request.formFile.FileName;
|
||||
|
||||
using (MemoryStream filestream = new MemoryStream())
|
||||
{
|
||||
await request.formFile.CopyToAsync(filestream);
|
||||
filestream.Position = 0;
|
||||
|
||||
string fileName = request.formFile.FileName;
|
||||
|
||||
var res = await _client.PutObjectAsync(new PutObjectArgs()
|
||||
.WithBucket(bucketName)
|
||||
.WithObject(fileName)
|
||||
.WithStreamData(filestream)
|
||||
.WithObjectSize(filestream.Length));
|
||||
//"\"698d51a19d8a121ce581499d7b701668\""
|
||||
//更新数据库
|
||||
var entity = await _dbContext.Queryable<ApkFileEntity>().Where(x => x.Name == fileName).FirstAsync();
|
||||
if (entity == null)
|
||||
{
|
||||
var info = new ApkFileEntity
|
||||
{
|
||||
Name = fileName,
|
||||
Url = fileName,
|
||||
VersionCode = request.VersionCode,
|
||||
UpdateMessage = request.UpdateMessage,
|
||||
};
|
||||
await _dbContext.InsertAsync(info);
|
||||
}
|
||||
else
|
||||
{
|
||||
entity.Url = fileName;
|
||||
entity.VersionCode = request.VersionCode;
|
||||
entity.UpdateMessage = request.UpdateMessage;
|
||||
}
|
||||
}
|
||||
var filerl = await MinloDownloadLinkAsync(fileName);
|
||||
return filerl;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 文件下载链接
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<string> MinloDownloadLinkAsync()
|
||||
public async Task<string> MinloDownloadLinkAsync(string fileName)
|
||||
{
|
||||
try
|
||||
{
|
||||
var url = await _client.PresignedGetObjectAsync(new PresignedGetObjectArgs()
|
||||
.WithBucket(bucketName)
|
||||
.WithObject("消费API逻辑.txt")
|
||||
.WithObject(fileName)
|
||||
.WithExpiry(60 * 60 * 24));//链接时效
|
||||
return url;
|
||||
}
|
||||
@@ -93,11 +71,10 @@ namespace Dlhis.Common.Services.Implements
|
||||
/// <summary>
|
||||
/// 单个删除文件
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="fileName"></param>
|
||||
/// <returns></returns>
|
||||
public async Task MinloRemoveFileAsync(ApkRequest request)
|
||||
public async Task MinloRemoveFileAsync(string fileName)
|
||||
{
|
||||
string fileName = request.formFile.FileName;
|
||||
await _client.RemoveObjectAsync(new RemoveObjectArgs()
|
||||
.WithBucket(bucketName)
|
||||
.WithObject(fileName));
|
||||
|
||||
@@ -37,6 +37,16 @@
|
||||
"ClientSecret": "123456"
|
||||
}
|
||||
},
|
||||
"MinIO": {
|
||||
//服务器IP
|
||||
"Endpoint": "http://192.168.199.124:9000",
|
||||
//账号
|
||||
"AccessKey": "Zbjj05OFtR19e5TJopQU",
|
||||
//密码
|
||||
"SecretKey": "UMXtNdZhufhAAyYJ3XND4cEgZNUsgOWtbUzksizK",
|
||||
//apk默认存储桶
|
||||
"Bucket": "apk"
|
||||
},
|
||||
"Serilog": {
|
||||
"MinimumLevel": {
|
||||
"Default": "Information",
|
||||
|
||||
Reference in New Issue
Block a user