110 lines
3.6 KiB
C#
110 lines
3.6 KiB
C#
using Ewide.Core;
|
|
using Furion.DatabaseAccessor;
|
|
using Furion.DatabaseAccessor.Extensions;
|
|
using Furion.DependencyInjection;
|
|
using Furion.DynamicApiController;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Ewide.Application.Service
|
|
{
|
|
public class HouseLogService : IHouseLogService, ITransient
|
|
{
|
|
private readonly IRepository<BsHouseLog> _bsHouseLogRep;
|
|
|
|
public HouseLogService(IRepository<BsHouseLog> bsHouseLogRep)
|
|
{
|
|
_bsHouseLogRep = bsHouseLogRep;
|
|
}
|
|
|
|
[UnitOfWork]
|
|
public async Task Add(string houseCodeId, SysUser targetUser, HouseLogType type)
|
|
{
|
|
await Add(houseCodeId, new List<SysUser> { targetUser }, type);
|
|
}
|
|
|
|
[UnitOfWork]
|
|
public async Task Add(string houseCodeId, List<SysUser> targetUsers, HouseLogType type)
|
|
{
|
|
await new BsHouseLog
|
|
{
|
|
Id = Guid.NewGuid().ToString(),
|
|
HouseCodeId = houseCodeId,
|
|
TargetUserIds = String.Join(",", targetUsers.Select(p => p.Id)),
|
|
Type = type,
|
|
Status = HouseLogStatus.Handle
|
|
}.InsertAsync();
|
|
}
|
|
|
|
[UnitOfWork]
|
|
public async Task Read(string houseCodeId)
|
|
{
|
|
var log = await _bsHouseLogRep
|
|
.Where(p => p.HouseCodeId.Equals(houseCodeId) && p.Status.Equals(HouseLogStatus.Handle))
|
|
.OrderByDescending(p => p.CreatedTime)
|
|
.FirstOrDefaultAsync();
|
|
if (log != null)
|
|
{
|
|
log.Status = HouseLogStatus.Handling;
|
|
await log.UpdateAsync();
|
|
}
|
|
}
|
|
|
|
[UnitOfWork]
|
|
public async Task Done(string houseCodeId)
|
|
{
|
|
var log = await _bsHouseLogRep
|
|
.Where(p => p.HouseCodeId.Equals(houseCodeId) && !p.Status.Equals(HouseLogStatus.Handled))
|
|
.OrderByDescending(p => p.CreatedTime)
|
|
.FirstOrDefaultAsync();
|
|
if (log != null)
|
|
{
|
|
log.Status = HouseLogStatus.Handled;
|
|
await log.UpdateAsync();
|
|
}
|
|
}
|
|
|
|
[UnitOfWork]
|
|
public async Task AddThenRead(string houseCodeId, SysUser targetUser, HouseLogType type)
|
|
{
|
|
await AddThenRead(houseCodeId, new List<SysUser> { targetUser }, type);
|
|
}
|
|
|
|
[UnitOfWork]
|
|
public async Task AddThenRead(string houseCodeId, List<SysUser> targetUsers, HouseLogType type)
|
|
{
|
|
await new BsHouseLog
|
|
{
|
|
Id = Guid.NewGuid().ToString(),
|
|
HouseCodeId = houseCodeId,
|
|
TargetUserIds = String.Join(",", targetUsers.Select(p => p.Id)),
|
|
Type = type,
|
|
Status = HouseLogStatus.Handling
|
|
}.InsertAsync();
|
|
}
|
|
|
|
[UnitOfWork]
|
|
public async Task AddThenDone(string houseCodeId, SysUser targetUser, HouseLogType type)
|
|
{
|
|
await AddThenDone(houseCodeId, new List<SysUser> { targetUser }, type);
|
|
}
|
|
|
|
[UnitOfWork]
|
|
public async Task AddThenDone(string houseCodeId, List<SysUser> targetUsers, HouseLogType type)
|
|
{
|
|
await new BsHouseLog
|
|
{
|
|
Id = Guid.NewGuid().ToString(),
|
|
HouseCodeId = houseCodeId,
|
|
TargetUserIds = String.Join(",", targetUsers.Select(p => p.Id)),
|
|
Type = type,
|
|
Status = HouseLogStatus.Handled
|
|
}.InsertAsync();
|
|
}
|
|
}
|
|
}
|