bug,设备迁移
This commit is contained in:
95
EquipMgr/Tnb.EquipMgr/EqpWorkshopChangeLogService.cs
Normal file
95
EquipMgr/Tnb.EquipMgr/EqpWorkshopChangeLogService.cs
Normal file
@@ -0,0 +1,95 @@
|
||||
using JNPF.Common.Core.Manager;
|
||||
using JNPF.Common.Enums;
|
||||
using JNPF.Common.Filter;
|
||||
using JNPF.DependencyInjection;
|
||||
using JNPF.DynamicApiController;
|
||||
using JNPF.FriendlyException;
|
||||
using JNPF.Systems.Entitys.Permission;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json;
|
||||
using SqlSugar;
|
||||
using Tnb.EquipMgr.Entities;
|
||||
using Tnb.EquipMgr.Entities.Dto;
|
||||
using Tnb.EquipMgr.Interfaces;
|
||||
|
||||
namespace Tnb.EquipMgr
|
||||
{
|
||||
/// <summary>
|
||||
/// 设备技术参数
|
||||
/// </summary>
|
||||
[ApiDescriptionSettings(Tag = ModuleConsts.Tag, Area = ModuleConsts.Area, Order = 700)]
|
||||
[Route("api/[area]/[controller]/[action]")]
|
||||
public class EqpWorkshopChangeLogService : IEqpWorkshopChangeLogService, IDynamicApiController, ITransient
|
||||
{
|
||||
private readonly ISqlSugarRepository<EqpWorkshopChangeLog> _repository;
|
||||
private readonly IUserManager _userManager;
|
||||
|
||||
public EqpWorkshopChangeLogService(ISqlSugarRepository<EqpWorkshopChangeLog> repository, IUserManager userManager)
|
||||
{
|
||||
_userManager = userManager;
|
||||
_repository = repository;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<dynamic> GetEquipWorkshopChangeList(EquipQueryInput input)
|
||||
{
|
||||
var db = _repository.AsSugarClient();
|
||||
// Dictionary<string, string>? queryJson = new Dictionary<string, string>();
|
||||
// if (input!=null && !string.IsNullOrEmpty(input.queryJson))
|
||||
// {
|
||||
// queryJson = JsonConvert.DeserializeObject<Dictionary<string, string>>(input?.queryJson ?? "");
|
||||
// }
|
||||
var result = await db.Queryable<EqpWorkshopChangeLog>()
|
||||
.LeftJoin<OrganizeEntity>((a,b)=>a.old_workshop_id==b.Id)
|
||||
.LeftJoin<OrganizeEntity>((a,b,c)=>a.new_workshop_id==c.Id)
|
||||
.WhereIF(input!=null,a=>a.equip_id==input.equip_id)
|
||||
//.WhereIF(queryJson!=null && queryJson.ContainsKey("name"),a=>a.name.Contains(queryJson["name"]))
|
||||
.Select((a,b,c) => new EquipWorkshopChangeQueryOutput
|
||||
{
|
||||
id = a.id,
|
||||
old_workshop_id = b.FullName,
|
||||
new_workshop_id = c.FullName,
|
||||
old_installation_location = a.old_installation_location,
|
||||
new_installation_location = a.new_installation_location,
|
||||
remark = a.remark,
|
||||
create_time = a.create_time==null ? null : a.create_time.Value.ToString("yyyy-MM-dd"),
|
||||
}).ToPagedListAsync((input?.currentPage??1), (input?.pageSize??50));
|
||||
|
||||
return PageResult<EquipWorkshopChangeQueryOutput>.SqlSugarPageResult(result);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<dynamic> WorkshopChange(EquipWorkshopChangeInput input)
|
||||
{
|
||||
var db = _repository.AsSugarClient();
|
||||
DbResult<bool> result = await db.Ado.UseTranAsync(async () =>
|
||||
{
|
||||
EqpEquipment eqpEquipment = await db.Queryable<EqpEquipment>().SingleAsync(x => x.id == input.equip_id);
|
||||
|
||||
EqpWorkshopChangeLog eqpWorkshopChangeLog = new EqpWorkshopChangeLog()
|
||||
{
|
||||
equip_id = input.equip_id,
|
||||
old_workshop_id = eqpEquipment.use_department_id,
|
||||
new_workshop_id = input.new_workshop_id,
|
||||
old_installation_location = eqpEquipment.installation_location,
|
||||
new_installation_location = input.new_installation_location,
|
||||
remark = input.remark,
|
||||
create_id = _userManager.UserId,
|
||||
create_time = DateTime.Now,
|
||||
org_id = _userManager.GetUserInfo().Result.organizeId
|
||||
};
|
||||
|
||||
await _repository.InsertAsync(eqpWorkshopChangeLog);
|
||||
|
||||
await db.Updateable<EqpEquipment>()
|
||||
.SetColumns(x => x.use_department_id == input.new_workshop_id)
|
||||
.SetColumns(x => x.installation_location == input.new_installation_location)
|
||||
.Where(x => x.id == input.equip_id).ExecuteCommandAsync();
|
||||
|
||||
});
|
||||
|
||||
if(!result.IsSuccess) throw Oops.Oh(ErrorCode.COM1008);
|
||||
return result.IsSuccess ? "迁移成功" : result.ErrorMessage;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user