update 完成选房
This commit is contained in:
@@ -6,7 +6,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Application.Service.HouseCode.Dto
|
||||
namespace Ewide.Application
|
||||
{
|
||||
public class HouseCodeInput
|
||||
{
|
||||
|
||||
@@ -7,10 +7,18 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Application
|
||||
{
|
||||
public class HouseSelectorInput
|
||||
public class HouseSelectInput
|
||||
{
|
||||
[Required(ErrorMessage = "区域编码不可为空")]
|
||||
[MinLength(9, ErrorMessage = "区域编码长度必须为9位及以上")]
|
||||
public string AreaCode { get; set; }
|
||||
[Required(ErrorMessage = "用户Id不能为空")]
|
||||
public string UserId { get; set; }
|
||||
|
||||
[Required(ErrorMessage = "房屋编码Id不能为空")]
|
||||
public string[] Ids { get; set; }
|
||||
}
|
||||
|
||||
public class QueryHouseSelectorInput : QueryHouseCodeInput
|
||||
{
|
||||
[Required(ErrorMessage = "用户Id不能为空")]
|
||||
public string UserId { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using Ewide.Core;
|
||||
using Dapper;
|
||||
using Ewide.Core.Extension;
|
||||
using Furion.DatabaseAccessor;
|
||||
using Furion.DatabaseAccessor.Extensions;
|
||||
using Furion.DependencyInjection;
|
||||
using Furion.DynamicApiController;
|
||||
using Furion.FriendlyException;
|
||||
@@ -17,5 +19,153 @@ namespace Ewide.Application.Service
|
||||
[ApiDescriptionSettings(Name = "HouseSelector", Order = 180)]
|
||||
public class HouseSelectorService : IHouseSelectorService, IDynamicApiController, ITransient
|
||||
{
|
||||
private readonly IDapperRepository _dapperRep;
|
||||
|
||||
private readonly IRepository<BsHouseMemberRelation> _bsHouseMemberRelationRep;
|
||||
private readonly IRepository<BsHouseCode> _bsHouseCodeRep;
|
||||
private readonly IHouseZoneService _houseZoneService;
|
||||
|
||||
public HouseSelectorService(
|
||||
IDapperRepository dapperRep,
|
||||
IRepository<BsHouseMemberRelation> bsHouseMemberRelationRep,
|
||||
IRepository<BsHouseCode> bsHouseCodeRep,
|
||||
IHouseZoneService houseZoneService
|
||||
)
|
||||
{
|
||||
_dapperRep = dapperRep;
|
||||
_bsHouseMemberRelationRep = bsHouseMemberRelationRep;
|
||||
_bsHouseCodeRep = bsHouseCodeRep;
|
||||
_houseZoneService = houseZoneService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取人员允许绑定的房屋编码列表
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("/houseSelector/selectorPage")]
|
||||
public async Task<dynamic> HouseSelectorList([FromBody] QueryHouseSelectorInput input)
|
||||
{
|
||||
var sql = @"SELECT
|
||||
HC.*,AA.Name AreaName,RA.Name RoadName,CA.Name CommName,Proj.AreaCode,Proj.Note,CONCAT(Proj.`Name`,'(',Proj.Note,')') FullProjName
|
||||
FROM bs_house_code HC
|
||||
LEFT JOIN bs_house_projectinfo Proj ON Proj.Id=HC.ProjectId
|
||||
LEFT JOIN sys_area_code CA ON CA.Code = Proj.AreaCode
|
||||
LEFT JOIN sys_area_code RA ON RA.AdCode = SUBSTR(CA.AdCode,1,9)
|
||||
LEFT JOIN sys_area_code AA ON AA.AdCode = SUBSTR(CA.AdCode,1,6)
|
||||
LEFT JOIN bs_house_member_relation HM ON HC.Id = HM.HouseCodeId
|
||||
INNER JOIN (SELECT * FROM sys_emp WHERE Id = @UserId) E ON HC.ZoneId = E.OrgId
|
||||
WHERE 1=1
|
||||
AND HM.Id IS NULL
|
||||
AND HC.Address LIKE @Address
|
||||
AND HC.HouseCode LIKE @HouseCode";
|
||||
return await _dapperRep.QueryPageData(sql, input, param: new
|
||||
{
|
||||
input.UserId,
|
||||
Address = "%" + input.Address + "%",
|
||||
HouseCode = "%" + input.HouseCode + "%"
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取人员已经绑定的房屋编码列表
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("/houseSelector/selectedPage")]
|
||||
public async Task<dynamic> HouseSelectedList([FromBody] QueryHouseSelectorInput input)
|
||||
{
|
||||
var sql = @"SELECT
|
||||
HC.*,AA.Name AreaName,RA.Name RoadName,CA.Name CommName,Proj.AreaCode,Proj.Note,CONCAT(Proj.`Name`,'(',Proj.Note,')') FullProjName
|
||||
FROM bs_house_code HC
|
||||
LEFT JOIN bs_house_projectinfo Proj ON Proj.Id=HC.ProjectId
|
||||
LEFT JOIN sys_area_code CA ON CA.Code = Proj.AreaCode
|
||||
LEFT JOIN sys_area_code RA ON RA.AdCode = SUBSTR(CA.AdCode,1,9)
|
||||
LEFT JOIN sys_area_code AA ON AA.AdCode = SUBSTR(CA.AdCode,1,6)
|
||||
INNER JOIN (SELECT * FROM bs_house_member_relation WHERE SysUserId = @UserId) HM ON HC.Id = HM.HouseCodeId
|
||||
WHERE 1=1
|
||||
AND HC.Address LIKE @Address
|
||||
AND HC.HouseCode LIKE @HouseCode";
|
||||
return await _dapperRep.QueryPageData(sql, input, param: new
|
||||
{
|
||||
input.UserId,
|
||||
Address = "%" + input.Address + "%",
|
||||
HouseCode = "%" + input.HouseCode + "%"
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从人员选择房屋
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("/houseSelector/select")]
|
||||
[UnitOfWork]
|
||||
public async Task Select([FromBody] HouseSelectInput input)
|
||||
{
|
||||
#region 验证房屋是否在当前用户可选范围内
|
||||
|
||||
var ids = input.Ids.Distinct().ToList();
|
||||
if (ids.Count == 0) throw Oops.Oh("没有选中任何房屋");
|
||||
|
||||
// 验证当前用户是否安全员 **须补充
|
||||
|
||||
// 已经被选中的房屋,从ids中剔除
|
||||
var houseSelected = await _bsHouseMemberRelationRep.DetachedEntities
|
||||
.Where(p => ids.Contains(p.HouseCodeId))
|
||||
.Select(p => p.HouseCodeId)
|
||||
.ToListAsync();
|
||||
if (houseSelected.Count > 0)
|
||||
{
|
||||
houseSelected.ForEach(p =>
|
||||
{
|
||||
var index = ids.IndexOf(p);
|
||||
if (index > -1)
|
||||
{
|
||||
ids.RemoveAt(index);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (ids.Count == 0) throw Oops.Oh("当前房屋在此之前已经全部被选中,请确认");
|
||||
|
||||
// 从用户所在片区中过滤房屋
|
||||
var zoneId = await _houseZoneService.GetZoneByUser(input.UserId);
|
||||
var house = await _bsHouseCodeRep.DetachedEntities.Where(p => ids.Contains(p.Id) && p.ZoneId == zoneId).Select(p => p.Id).ToListAsync();
|
||||
|
||||
if (house.Count == 0) throw Oops.Oh("选中的房屋错误");
|
||||
|
||||
#endregion
|
||||
|
||||
// 选定房屋
|
||||
house.ForEach(p =>
|
||||
{
|
||||
new BsHouseMemberRelation
|
||||
{
|
||||
SysUserId = input.UserId,
|
||||
HouseCodeId = p
|
||||
}.Insert();
|
||||
});
|
||||
}
|
||||
|
||||
[HttpPost("/houseSelector/revoke")]
|
||||
[UnitOfWork]
|
||||
public async Task Revoke([FromBody] HouseSelectInput input)
|
||||
{
|
||||
var ids = input.Ids.Distinct().ToList();
|
||||
if (ids.Count == 0) throw Oops.Oh("没有选中任何房屋");
|
||||
|
||||
var selected = await _bsHouseMemberRelationRep.Where(p => ids.Contains(p.HouseCodeId) && p.SysUserId == input.UserId).ToListAsync();
|
||||
|
||||
selected.ForEach(p =>
|
||||
{
|
||||
p.Delete();
|
||||
});
|
||||
}
|
||||
|
||||
public async Task SelectMember()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,5 +9,10 @@ namespace Ewide.Application.Service
|
||||
{
|
||||
public interface IHouseSelectorService
|
||||
{
|
||||
Task<dynamic> HouseSelectorList([FromQuery] QueryHouseSelectorInput input);
|
||||
Task<dynamic> HouseSelectedList([FromQuery] QueryHouseSelectorInput input);
|
||||
Task Select([FromBody] HouseSelectInput input);
|
||||
Task Revoke([FromBody] HouseSelectInput input);
|
||||
Task SelectMember();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ using Furion.FriendlyException;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -17,13 +18,28 @@ namespace Ewide.Application.Service
|
||||
[ApiDescriptionSettings(Name = "HouseZone", Order = 180)]
|
||||
public class HouseZoneService : IHouseZoneService, IDynamicApiController, ITransient
|
||||
{
|
||||
private readonly IRepository<SysOrg> _sysOrgRep;
|
||||
private readonly IRepository<SysEmp> _sysEmpRep;
|
||||
public HouseZoneService(
|
||||
IRepository<SysOrg> sysOrgRep,
|
||||
IRepository<SysEmp> sysEmpRep
|
||||
)
|
||||
{
|
||||
_sysOrgRep = sysOrgRep;
|
||||
_sysEmpRep = sysEmpRep;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取片区列表
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("/houseZone/list")]
|
||||
public async Task<dynamic> GetHouseZoneList([FromQuery] HouseZoneInput input)
|
||||
{
|
||||
var areaCode = input.AreaCode.Substring(0, 9);
|
||||
var _sysOrgRep = Db.GetRepository<SysOrg>();
|
||||
var road = await _sysOrgRep.DetachedEntities.FirstOrDefaultAsync(p => p.AreaCode == areaCode);
|
||||
if (road == null) throw Oops.Oh("街道编码错误");
|
||||
if (road == null) throw Oops.Oh("未在组织机构中配置街道");
|
||||
return await _sysOrgRep.DetachedEntities
|
||||
.Where(p => p.Pid == road.Id)
|
||||
.Where(p => p.Type == (int)OrgType.片区)
|
||||
@@ -35,5 +51,20 @@ namespace Ewide.Application.Service
|
||||
})
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据用户Id获取所在片区的Id
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("houseZone/getByUser")]
|
||||
public async Task<string> GetZoneByUser([FromQuery][Required(ErrorMessage = "用户Id不能为空")] string userId)
|
||||
{
|
||||
var data = await _sysEmpRep.DetachedEntities.FirstOrDefaultAsync(p => p.Id == userId);
|
||||
if(data == null) throw Oops.Oh("用户不在组织机构中");
|
||||
var org = await _sysOrgRep.DetachedEntities.FirstOrDefaultAsync(p => p.Id == data.OrgId && p.Type == (int)OrgType.片区);
|
||||
if(org == null) throw Oops.Oh("用户不在片区中");
|
||||
return org.Id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,5 +10,6 @@ namespace Ewide.Application.Service
|
||||
public interface IHouseZoneService
|
||||
{
|
||||
Task<dynamic> GetHouseZoneList([FromQuery] HouseZoneInput input);
|
||||
Task<string> GetZoneByUser([FromQuery] string userId);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user