|
@@ -15,6 +15,15 @@ using ZhonTai.Admin.Services.User.Dto;
|
|
using ZhonTai.Admin.Domain.UserRole;
|
|
using ZhonTai.Admin.Domain.UserRole;
|
|
using ZhonTai.Admin.Domain.Project;
|
|
using ZhonTai.Admin.Domain.Project;
|
|
using ZhonTai.Admin.Services.Project.Dto;
|
|
using ZhonTai.Admin.Services.Project.Dto;
|
|
|
|
+using ZhonTai.Admin.Core.Attributes;
|
|
|
|
+using ZhonTai.Admin.Domain.Tenant;
|
|
|
|
+using ZhonTai.Admin.Domain.TenantPkg;
|
|
|
|
+using ZhonTai.Admin.Domain.Pkg;
|
|
|
|
+using ZhonTai.Admin.Repositories;
|
|
|
|
+using ZhonTai.Admin.Services.Tenant.Dto;
|
|
|
|
+using System.Linq.Expressions;
|
|
|
|
+using ZhonTai.Admin.Domain.Org;
|
|
|
|
+using ZhonTai.Admin.Services.Pkg;
|
|
|
|
|
|
namespace ZhonTai.Admin.Services.Project
|
|
namespace ZhonTai.Admin.Services.Project
|
|
{
|
|
{
|
|
@@ -25,7 +34,7 @@ namespace ZhonTai.Admin.Services.Project
|
|
[DynamicApi(Area = AdminConsts.AreaName)]
|
|
[DynamicApi(Area = AdminConsts.AreaName)]
|
|
public partial class ProjectService : BaseService, IProjectService, IDynamicApi
|
|
public partial class ProjectService : BaseService, IProjectService, IDynamicApi
|
|
{
|
|
{
|
|
- private readonly IProjectRepository _projectRepository ;
|
|
|
|
|
|
+ private readonly IProjectRepository _projectRepository;
|
|
private readonly IProjectPriceRepository _projectPriceRepository;
|
|
private readonly IProjectPriceRepository _projectPriceRepository;
|
|
|
|
|
|
public ProjectService(IProjectRepository projectRepository, IProjectPriceRepository projectPriceRepository)
|
|
public ProjectService(IProjectRepository projectRepository, IProjectPriceRepository projectPriceRepository)
|
|
@@ -33,6 +42,31 @@ namespace ZhonTai.Admin.Services.Project
|
|
_projectRepository = projectRepository;
|
|
_projectRepository = projectRepository;
|
|
_projectPriceRepository = projectPriceRepository;
|
|
_projectPriceRepository = projectPriceRepository;
|
|
}
|
|
}
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// 查询
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <param name="id"></param>
|
|
|
|
+ /// <returns></returns>
|
|
|
|
+ public async Task<ProjectGetOutput> GetAsync(long id)
|
|
|
|
+ {
|
|
|
|
+ var project = await _projectRepository.Select
|
|
|
|
+ .WhereDynamic(id)
|
|
|
|
+ .FirstAsync(a => new ProjectGetOutput
|
|
|
|
+ {
|
|
|
|
+ Name = a.Name,
|
|
|
|
+ Logo = a.Logo,
|
|
|
|
+ Tips = a.Tips,
|
|
|
|
+ SettleDay = a.SettleDay,
|
|
|
|
+ MaxPrice = a.MaxPrice,
|
|
|
|
+ Works = a.Works,
|
|
|
|
+ VideoUrl = a.VideoUrl,
|
|
|
|
+ Detail = a.Detail,
|
|
|
|
+ Id = a.Id,
|
|
|
|
+ prices = _projectPriceRepository.Select.Where(m => m.ProjectId == a.Id).ToList<ProjectPriceAddInput>()
|
|
|
|
+ });
|
|
|
|
+ return project;
|
|
|
|
+ }
|
|
|
|
+
|
|
/// <summary>
|
|
/// <summary>
|
|
/// 查询分页
|
|
/// 查询分页
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -60,19 +94,98 @@ namespace ZhonTai.Admin.Services.Project
|
|
return data;
|
|
return data;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <summary>
|
|
- /// 添加项目
|
|
|
|
|
|
+ /// 添加
|
|
/// </summary>
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[HttpPost]
|
|
- public async Task<long> AddAsync(ProjectGetPageInput input)
|
|
|
|
|
|
+ [AdminTransaction]
|
|
|
|
+ public async Task<long> AddAsync(ProjectAddInput input)
|
|
{
|
|
{
|
|
|
|
|
|
//添加项目
|
|
//添加项目
|
|
|
|
+ ProjectEntity entity = Mapper.Map<ProjectEntity>(input);
|
|
|
|
+ ProjectEntity project = await _projectRepository.InsertAsync(entity);
|
|
|
|
+ long projectId = project.Id;
|
|
|
|
+
|
|
|
|
+ //添加项目价格
|
|
|
|
+ var prices = input.prices.Select(m => new ProjectPriceEntity
|
|
|
|
+ {
|
|
|
|
+ ProjectId = projectId,
|
|
|
|
+ Name=m.Name,
|
|
|
|
+ Price=m.Price
|
|
|
|
+ }).ToList();
|
|
|
|
+
|
|
|
|
+ await _projectPriceRepository.InsertAsync(prices);
|
|
|
|
+
|
|
|
|
+ return 1;
|
|
|
|
+ }
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// 修改
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <param name="input"></param>
|
|
|
|
+ /// <returns></returns>
|
|
|
|
+ public async Task UpdateAsync(ProjectUpdateInput input)
|
|
|
|
+ {
|
|
|
|
+
|
|
|
|
+ var project = await _projectRepository.GetAsync(input.Id);
|
|
|
|
+ if (!(project?.Id > 0))
|
|
|
|
+ {
|
|
|
|
+ throw ResultOutput.Exception("项目不存在");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //更新项目
|
|
|
|
+ await _projectRepository.UpdateDiy.SetSource(
|
|
|
|
+ new ProjectEntity()
|
|
|
|
+ {
|
|
|
|
+ Id = project.Id,
|
|
|
|
+ Name = input.Name,
|
|
|
|
+ Logo = input.Logo,
|
|
|
|
+ Tips = input.Tips,
|
|
|
|
+ SettleDay = input.SettleDay,
|
|
|
|
+ MaxPrice = input.MaxPrice,
|
|
|
|
+ Works = input.Works,
|
|
|
|
+ VideoUrl = input.VideoUrl,
|
|
|
|
+ Detail = input.Detail,
|
|
|
|
+ })
|
|
|
|
+ .UpdateColumns(a => new { a.Name, a.Logo, a.Tips, a.SettleDay, a.MaxPrice, a.VideoUrl, a.Detail, a.ModifiedTime }).ExecuteAffrowsAsync();
|
|
|
|
+
|
|
|
|
+ //删除项目价格
|
|
|
|
+ var PriceIds = _projectPriceRepository.Select.Where(m => m.ProjectId == project.Id).ToList(m => m.Id);
|
|
|
|
+ var inputPrice = input.prices.Where(m => m.Id > 0).ToList();
|
|
|
|
+ var inputPriceIds = inputPrice.Select(m => m.Id).ToList();
|
|
|
|
+ var deletePriceIds = PriceIds.Except(inputPriceIds).ToList();
|
|
|
|
+ if (deletePriceIds.Count() > 0)
|
|
|
|
+ {
|
|
|
|
+ await _projectPriceRepository.SoftDeleteAsync(a => deletePriceIds.Contains(a.Id));
|
|
|
|
+ }
|
|
|
|
+ //新增项目价格
|
|
|
|
+ var addPriceIds = input.prices.Where(m => m.Id <= 0).ToList();
|
|
|
|
+ if (addPriceIds.Count() > 0)
|
|
|
|
+ {
|
|
|
|
+ var list = addPriceIds.Select(m => new ProjectPriceEntity
|
|
|
|
+ {
|
|
|
|
+ ProjectId = project.Id,
|
|
|
|
+ Name = m.Name,
|
|
|
|
+ Price = m.Price
|
|
|
|
+ }).ToList();
|
|
|
|
+ await _projectPriceRepository.InsertAsync(list);
|
|
|
|
+ }
|
|
|
|
+ //更新项目价格
|
|
|
|
+ foreach (var item in inputPrice)
|
|
|
|
+ {
|
|
|
|
+ await _projectPriceRepository.UpdateDiy.SetSource(
|
|
|
|
+ new ProjectPriceEntity()
|
|
|
|
+ {
|
|
|
|
+ Id = item.Id,
|
|
|
|
+ Name = item.Name,
|
|
|
|
+ Price = item.Price
|
|
|
|
+ })
|
|
|
|
+ .UpdateColumns(a => new { a.Name, a.Price, a.ModifiedTime }).ExecuteAffrowsAsync();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
- //添加项目价格
|
|
|
|
|
|
|
|
- return 0;
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|