166 lines
5.5 KiB
C#
166 lines
5.5 KiB
C#
using Dapper;
|
|
using Ewide.Core;
|
|
using Furion.DatabaseAccessor;
|
|
using Furion.DatabaseAccessor.Extensions;
|
|
using Furion.DependencyInjection;
|
|
using Furion.DynamicApiController;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Ewide.Application.Service
|
|
{
|
|
/// <summary>
|
|
/// 房屋流转日志
|
|
/// </summary>
|
|
[ApiDescriptionSettings(Name = "HouseLog", Order = 210)]
|
|
public class HouseLogService : IHouseLogService, IDynamicApiController, ITransient
|
|
{
|
|
private readonly IDapperRepository _dapperRep;
|
|
|
|
private readonly IRepository<BsHouseLog> _bsHouseLogRep;
|
|
|
|
public HouseLogService(IDapperRepository dapperRep, IRepository<BsHouseLog> bsHouseLogRep)
|
|
{
|
|
_dapperRep = dapperRep;
|
|
_bsHouseLogRep = bsHouseLogRep;
|
|
}
|
|
|
|
[NonAction]
|
|
[UnitOfWork]
|
|
public async Task Add(string houseCodeId, SysUser targetUser, HouseLogType type)
|
|
{
|
|
await Add(houseCodeId, new List<SysUser> { targetUser }, type);
|
|
}
|
|
|
|
[NonAction]
|
|
[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();
|
|
}
|
|
|
|
[NonAction]
|
|
[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();
|
|
}
|
|
}
|
|
|
|
[NonAction]
|
|
[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();
|
|
}
|
|
}
|
|
|
|
[NonAction]
|
|
[UnitOfWork]
|
|
public async Task AddThenRead(string houseCodeId, SysUser targetUser, HouseLogType type)
|
|
{
|
|
await AddThenRead(houseCodeId, new List<SysUser> { targetUser }, type);
|
|
}
|
|
|
|
[NonAction]
|
|
[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();
|
|
}
|
|
|
|
[NonAction]
|
|
[UnitOfWork]
|
|
public async Task AddThenDone(string houseCodeId, SysUser targetUser, HouseLogType type)
|
|
{
|
|
await AddThenDone(houseCodeId, new List<SysUser> { targetUser }, type);
|
|
}
|
|
|
|
[NonAction]
|
|
[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();
|
|
}
|
|
|
|
[HttpGet("/houseLog/list")]
|
|
public async Task<dynamic> List([FromQuery] HouseLogInput input)
|
|
{
|
|
var sql = @"SELECT *,
|
|
(SELECT GROUP_CONCAT(`Name`) FROM sys_user
|
|
WHERE Id IN (
|
|
SELECT DISTINCT SUBSTRING_INDEX(SUBSTRING_INDEX(_HL.TargetUserIds,',',HT.help_topic_id + 1),',',-1)
|
|
FROM bs_house_log _HL
|
|
JOIN mysql.help_topic HT ON HT.help_topic_id < (LENGTH(_HL.TargetUserIds) - LENGTH(REPLACE(_HL.TargetUserIds,',','')) + 1)
|
|
WHERE _HL.Id = HL.Id
|
|
)
|
|
) TargetUserNames
|
|
FROM bs_house_log HL
|
|
WHERE HouseCodeId = @HouseCodeId
|
|
ORDER BY HL.CreatedTime DESC, Type DESC";
|
|
|
|
return await _dapperRep.QueryAsync<HouseLogOutput>(sql, new { houseCodeId = input.Id });
|
|
}
|
|
|
|
[HttpGet("/houseLog/listByInfoId")]
|
|
public async Task<dynamic> ListByInfoId([FromQuery] HouseLogInput input)
|
|
{
|
|
var info = await Db.GetRepository<BsHouseInfo>().DetachedEntities.FirstOrDefaultAsync(p => p.Id.Equals(input.Id));
|
|
return await List(new HouseLogInput
|
|
{
|
|
Id = info.HouseCodeId
|
|
});
|
|
}
|
|
|
|
[HttpGet("/houseLog/listByTaskId")]
|
|
public async Task<dynamic> ListByTaskId([FromQuery] HouseLogInput input)
|
|
{
|
|
var task = await Db.GetRepository<BsHouseTask>().DetachedEntities.FirstOrDefaultAsync(p => p.Id.Equals(input.Id));
|
|
return await List(new HouseLogInput
|
|
{
|
|
Id = task.HouseCodeId
|
|
});
|
|
}
|
|
}
|
|
}
|