Commit 404084de by lcx

保存时添加条件判断,置空原始typeid绑定

parent a7f11b4f
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
using Performance.Services.Queues; using Performance.Services.Queues;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
namespace Performance.Api.Controllers namespace Performance.Api.Controllers
{ {
...@@ -241,6 +242,19 @@ public ApiResponse DeleteExtractTypeAndScript([FromRoute] int typeId, int script ...@@ -241,6 +242,19 @@ public ApiResponse DeleteExtractTypeAndScript([FromRoute] int typeId, int script
[HttpPost("type/{hospitalId}/save")] [HttpPost("type/{hospitalId}/save")]
public ApiResponse EditExtractTypeAndScript([FromRoute] int hospitalId, [FromBody] ExtractConfigResponse request) public ApiResponse EditExtractTypeAndScript([FromRoute] int hospitalId, [FromBody] ExtractConfigResponse request)
{ {
var shettypes = new int[] { (int)SheetType.Income, (int)SheetType.OtherIncome, (int)SheetType.Expend, (int)SheetType.Workload, (int)SheetType.SpecialUnit };
if (shettypes.Contains(request.Source))
{
if (request.ModuleId == 0 && string.IsNullOrWhiteSpace(request.ModuleName))
return new ApiResponse(ResponseType.ParameterError, "新增模块信息不能为空");
if (request.Source != (int)SheetType.Income)
{
if (request.ItemId == 0 && string.IsNullOrWhiteSpace(request.ItemName))
return new ApiResponse(ResponseType.ParameterError, "新增提取项不能为空");
}
}
var flag = _preConfigService.EditExtractTypeAndScript(hospitalId, request); var flag = _preConfigService.EditExtractTypeAndScript(hospitalId, request);
return flag return flag
? new ApiResponse(ResponseType.OK, "操作成功") ? new ApiResponse(ResponseType.OK, "操作成功")
...@@ -298,6 +312,18 @@ public ApiResponse<List<TitleValue<int>>> GetConfigs([FromRoute] int hospitalId) ...@@ -298,6 +312,18 @@ public ApiResponse<List<TitleValue<int>>> GetConfigs([FromRoute] int hospitalId)
return new ApiResponse<List<TitleValue<int>>>(ResponseType.OK, list); return new ApiResponse<List<TitleValue<int>>>(ResponseType.OK, list);
} }
/// <summary>
/// 测算表模块配置项
/// </summary>
/// <param name="hospitalId"></param>
/// <returns></returns>
[HttpGet("modules/items/{hospitalId}")]
public ApiResponse GetModeuleAndItems([FromRoute] int hospitalId)
{
var list = _preConfigService.GetModeuleAndItems(hospitalId);
return new ApiResponse(ResponseType.OK, list);
}
#endregion #endregion
} }
} }
\ No newline at end of file
...@@ -44,6 +44,18 @@ public class ExtractConfigResponse ...@@ -44,6 +44,18 @@ public class ExtractConfigResponse
#endregion #endregion
#region Modele & Item
public int ModuleId { get; set; }
public string ModuleName { get; set; }
public int ItemId { get; set; }
public string ItemName { get; set; }
#endregion
public List<ExtractConfigResponse> Children { get; set; } = new List<ExtractConfigResponse>(); public List<ExtractConfigResponse> Children { get; set; } = new List<ExtractConfigResponse>();
} }
} }
using System.Collections.Generic;
namespace Performance.DtoModels
{
public class TreeItem<T>
{
public T Item { get; set; }
public List<TreeItem<T>> Children { get; set; }
}
public class SelectOption<T>
{
public string Label { get; set; }
public T Value { get; set; }
public int Source { get; set; }
public List<SelectOption<T>> Children { get; set; } = new List<SelectOption<T>>();
}
public class SelectOption : SelectOption<int>
{ }
}
...@@ -23,6 +23,7 @@ public class ExtractPreConfigService : IAutoInjection ...@@ -23,6 +23,7 @@ public class ExtractPreConfigService : IAutoInjection
private readonly PerforExmoduleRepository exmoduleRepository; private readonly PerforExmoduleRepository exmoduleRepository;
private readonly PerforExitemRepository exitemRepository; private readonly PerforExitemRepository exitemRepository;
private readonly PerforExspecialRepository exspecialRepository; private readonly PerforExspecialRepository exspecialRepository;
private readonly ExConfigService exConfigService;
private readonly QueryService queryService; private readonly QueryService queryService;
...@@ -36,7 +37,8 @@ public class ExtractPreConfigService : IAutoInjection ...@@ -36,7 +37,8 @@ public class ExtractPreConfigService : IAutoInjection
PerforExmoduleRepository exmoduleRepository, PerforExmoduleRepository exmoduleRepository,
PerforExitemRepository exitemRepository, PerforExitemRepository exitemRepository,
PerforExspecialRepository exspecialRepository, PerforExspecialRepository exspecialRepository,
QueryService queryService) QueryService queryService,
ExConfigService exConfigService)
{ {
this.logger = logger; this.logger = logger;
this.mapper = mapper; this.mapper = mapper;
...@@ -48,6 +50,7 @@ public class ExtractPreConfigService : IAutoInjection ...@@ -48,6 +50,7 @@ public class ExtractPreConfigService : IAutoInjection
this.exitemRepository = exitemRepository; this.exitemRepository = exitemRepository;
this.exspecialRepository = exspecialRepository; this.exspecialRepository = exspecialRepository;
this.queryService = queryService; this.queryService = queryService;
this.exConfigService = exConfigService;
} }
#region HospitalConfig #region HospitalConfig
...@@ -161,6 +164,15 @@ public List<ExtractConfigResponse> GetExtractTypeAndScript(int hospitalId) ...@@ -161,6 +164,15 @@ public List<ExtractConfigResponse> GetExtractTypeAndScript(int hospitalId)
var data = extypeRepository.GetEntities(w => w.HospitalId == hospitalId); var data = extypeRepository.GetEntities(w => w.HospitalId == hospitalId);
if (data == null || !data.Any()) return new List<ExtractConfigResponse>(); if (data == null || !data.Any()) return new List<ExtractConfigResponse>();
var modules = exmoduleRepository.GetEntities(w => w.HospitalId == hospitalId && w.TypeId.HasValue) ?? new List<ex_module>();
var items = new List<ex_item>();
if (items == null || !items.Any())
{
items = exitemRepository.GetEntities(w => modules.Select(t => t.Id).Contains(w.ModuleId ?? 0) && w.TypeId.HasValue)
?? new List<ex_item>();
}
var specials = exspecialRepository.GetEntities(w => w.HospitalId == hospitalId && w.TypeId.HasValue) ?? new List<ex_special>();
var result = sheettypes.Where(w => data.Select(t => t.Source).Contains(w.Value))? var result = sheettypes.Where(w => data.Select(t => t.Source).Contains(w.Value))?
.Select(t => new ExtractConfigResponse .Select(t => new ExtractConfigResponse
{ {
...@@ -200,6 +212,25 @@ public List<ExtractConfigResponse> GetExtractTypeAndScript(int hospitalId) ...@@ -200,6 +212,25 @@ public List<ExtractConfigResponse> GetExtractTypeAndScript(int hospitalId)
x.Name = item.EName + index; x.Name = item.EName + index;
index++; index++;
} }
switch (item.Source)
{
case (int)SheetType.Income:
x.ModuleId = modules.FirstOrDefault(w => w.TypeId == x.TypeId)?.Id ?? 0;
break;
case (int)SheetType.SpecialUnit:
x.ModuleId = -1;
x.ItemId = specials.FirstOrDefault(w => w.TypeId == x.TypeId)?.Id ?? 0;
break;
default:
var item = items.FirstOrDefault(w => w.TypeId == x.TypeId);
if (item != null)
{
x.ModuleId = item.ModuleId ?? 0;
x.ItemId = item.Id;
}
break;
}
}); });
} }
source.Children = sourcelist.OrderBy(t => t.Name).ToList(); source.Children = sourcelist.OrderBy(t => t.Name).ToList();
...@@ -227,6 +258,25 @@ public ExtractConfigResponse GetExtractTypeAndScriptById(int typeId, int scriptI ...@@ -227,6 +258,25 @@ public ExtractConfigResponse GetExtractTypeAndScriptById(int typeId, int scriptI
data.IsEnable = script.IsEnable; data.IsEnable = script.IsEnable;
} }
switch (type.Source)
{
case (int)SheetType.Income:
data.ModuleId = exmoduleRepository.GetEntity(w => w.TypeId == type.Id)?.Id ?? 0;
break;
case (int)SheetType.SpecialUnit:
data.ModuleId = -1;
data.ItemId = exspecialRepository.GetEntity(w => w.TypeId == type.Id)?.Id ?? 0;
break;
default:
var item = exitemRepository.GetEntity(w => w.TypeId == type.Id);
if (item != null)
{
data.ModuleId = item.ModuleId ?? 0;
data.ItemId = item.Id;
}
break;
}
return data; return data;
} }
...@@ -269,6 +319,7 @@ public bool EditExtractTypeAndScript(int hospitalId, ExtractConfigResponse reque ...@@ -269,6 +319,7 @@ public bool EditExtractTypeAndScript(int hospitalId, ExtractConfigResponse reque
var entity = mapper.Map<ex_type>(request); var entity = mapper.Map<ex_type>(request);
entity.HospitalId = hospitalId; entity.HospitalId = hospitalId;
if (!extypeRepository.Add(entity)) return false; if (!extypeRepository.Add(entity)) return false;
request.TypeId = entity.Id;
if (!string.IsNullOrEmpty(request.ExecScript)) if (!string.IsNullOrEmpty(request.ExecScript))
{ {
...@@ -285,6 +336,32 @@ public bool EditExtractTypeAndScript(int hospitalId, ExtractConfigResponse reque ...@@ -285,6 +336,32 @@ public bool EditExtractTypeAndScript(int hospitalId, ExtractConfigResponse reque
} }
else else
{ {
#region 取消其他typeid绑定
var modules = exmoduleRepository.GetEntities(w => w.TypeId == request.TypeId);
if (modules != null && modules.Any())
{
modules.ForEach(module => module.TypeId = null);
exmoduleRepository.UpdateRange(modules.ToArray());
}
var items = exitemRepository.GetEntities(w => w.TypeId == request.TypeId);
if (items != null && items.Any())
{
items.ForEach(item => item.TypeId = null);
exitemRepository.UpdateRange(items.ToArray());
}
var specials = exspecialRepository.GetEntities(w => w.TypeId == request.TypeId);
if (specials != null && specials.Any())
{
specials.ForEach(special => special.TypeId = null);
exspecialRepository.UpdateRange(specials.ToArray());
}
#endregion
var entity = extypeRepository.GetEntity(w => w.Id == request.TypeId); var entity = extypeRepository.GetEntity(w => w.Id == request.TypeId);
entity.EName = request.EName; entity.EName = request.EName;
entity.Description = request.Description; entity.Description = request.Description;
...@@ -317,6 +394,69 @@ public bool EditExtractTypeAndScript(int hospitalId, ExtractConfigResponse reque ...@@ -317,6 +394,69 @@ public bool EditExtractTypeAndScript(int hospitalId, ExtractConfigResponse reque
} }
} }
if (request.ModuleId == -1)
{
if (request.ItemId == 0)
{
var special = new ex_special
{
HospitalId = hospitalId,
Target = request.ItemName,
TypeId = request.TypeId,
ConfigId = request.ConfigId,
};
exspecialRepository.Add(special);
}
else
{
var special = exspecialRepository.GetEntity(w => w.Id == request.ItemId);
if (special != null)
{
special.TypeId = request.TypeId;
special.ConfigId = request.ConfigId;
exspecialRepository.Update(special);
}
}
}
else
{
if (request.ModuleId == 0)
{
var module = exConfigService.AddModule(new ModModuleRequest
{
HospitalId = hospitalId,
SheetType = request.Source,
ModuleName = request.ModuleName,
TypeId = request.TypeId,
ConfigId = request.ConfigId,
});
request.ModuleId = module.Id;
}
if (request.ItemId == 0)
{
var item = new ex_item
{
ModuleId = request.ModuleId,
ItemName = request.ItemName,
TypeId = request.TypeId,
ConfigId = request.ConfigId,
ReadOnly = 0
};
exitemRepository.Add(item);
}
else
{
var item = exitemRepository.GetEntity(w => w.Id == request.ItemId);
if (item != null)
{
item.ModuleId = request.ModuleId;
item.TypeId = request.TypeId;
item.ConfigId = request.ConfigId;
exitemRepository.Update(item);
}
}
}
return true; return true;
} }
...@@ -445,6 +585,60 @@ public List<TitleValue<int>> GetConfigs(int hospitalId) ...@@ -445,6 +585,60 @@ public List<TitleValue<int>> GetConfigs(int hospitalId)
}).ToList(); }).ToList();
} }
public List<SelectOption> GetModeuleAndItems(int hospitalId)
{
var modules = exmoduleRepository.GetEntities(w => w.HospitalId == hospitalId);
if (modules == null || modules.Any())
{
exConfigService.DefaultModules(hospitalId);
modules = exmoduleRepository.GetEntities(w => w.HospitalId == hospitalId);
}
var result = modules.Select(w => new SelectOption
{
Label = w.ModuleName,
Value = w.Id,
Source = w.SheetType ?? 0
}).ToList();
var items = exitemRepository.GetEntities(w => modules.Select(t => t.Id).Contains(w.ModuleId ?? 0));
if (items != null && items.Any())
{
foreach (var item in result)
{
var moduleItmes = items.Where(w => w.ModuleId == item.Value);
if (moduleItmes == null || !moduleItmes.Any()) continue;
item.Children = moduleItmes.Select(w => new SelectOption<int>
{
Label = w.ItemName,
Value = w.Id,
Source = item.Source
}).ToList();
}
}
var special = new SelectOption
{
Label = "4.2 特殊核算单元绩效测算表",
Value = -1,
Source = (int)SheetType.SpecialUnit
};
var specialItems = exspecialRepository.GetEntities(w => w.HospitalId == hospitalId);
if (specialItems != null && specialItems.Any())
{
special.Children = specialItems.Select(w => new SelectOption<int>
{
Label = w.Target,
Value = w.Id,
Source = (int)SheetType.SpecialUnit
}).ToList();
}
result.Add(special);
return result;
}
#endregion #endregion
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment