update 完成片区新增
This commit is contained in:
@@ -6,8 +6,23 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Application
|
||||
{
|
||||
public enum ZoneRole
|
||||
public enum HouseManagerRole
|
||||
{
|
||||
/// <summary>
|
||||
/// 市住建部门
|
||||
/// </summary>
|
||||
CityManager,
|
||||
|
||||
/// <summary>
|
||||
/// 区住建部门
|
||||
/// </summary>
|
||||
AreaManager,
|
||||
|
||||
/// <summary>
|
||||
/// 街道管理员
|
||||
/// </summary>
|
||||
RoadManager,
|
||||
|
||||
/// <summary>
|
||||
/// 片区监管员
|
||||
/// </summary>
|
||||
@@ -359,12 +359,27 @@
|
||||
单位联系人电话
|
||||
</summary>
|
||||
</member>
|
||||
<member name="F:Ewide.Application.ZoneRole.ZoneManager">
|
||||
<member name="F:Ewide.Application.HouseManagerRole.CityManager">
|
||||
<summary>
|
||||
市住建部门
|
||||
</summary>
|
||||
</member>
|
||||
<member name="F:Ewide.Application.HouseManagerRole.AreaManager">
|
||||
<summary>
|
||||
区住建部门
|
||||
</summary>
|
||||
</member>
|
||||
<member name="F:Ewide.Application.HouseManagerRole.RoadManager">
|
||||
<summary>
|
||||
街道管理员
|
||||
</summary>
|
||||
</member>
|
||||
<member name="F:Ewide.Application.HouseManagerRole.ZoneManager">
|
||||
<summary>
|
||||
片区监管员
|
||||
</summary>
|
||||
</member>
|
||||
<member name="F:Ewide.Application.ZoneRole.HouseSecurityManager">
|
||||
<member name="F:Ewide.Application.HouseManagerRole.HouseSecurityManager">
|
||||
<summary>
|
||||
房屋安全管理员
|
||||
</summary>
|
||||
|
||||
@@ -265,7 +265,7 @@ WHERE 1=1";
|
||||
var roleIds = await _sysUserRoleRep.DetachedEntities.Where(p => userIds.Contains(p.SysUserId)).Select(p => p.SysRoleId).ToListAsync();
|
||||
|
||||
var _sysRoleRep = Db.GetRepository<SysRole>();
|
||||
var isExistZoneManager = await _sysRoleRep.DetachedEntities.AnyAsync(p => roleIds.Contains(p.Id) && p.Code == System.Enum.GetName(ZoneRole.ZoneManager).ToUnderScoreCase());
|
||||
var isExistZoneManager = await _sysRoleRep.DetachedEntities.AnyAsync(p => roleIds.Contains(p.Id) && p.Code == System.Enum.GetName(HouseManagerRole.ZoneManager).ToUnderScoreCase());
|
||||
// 存在片区监管员,返回安全员, 否则返回监管员
|
||||
if (isExistZoneManager)
|
||||
{
|
||||
@@ -282,7 +282,7 @@ WHERE 1=1";
|
||||
[NonAction]
|
||||
private async Task<List<SysRole>> GetRoleRange()
|
||||
{
|
||||
var codes = System.Enum.GetNames(typeof(ZoneRole)).Select(p => p.ToUnderScoreCase());
|
||||
var codes = System.Enum.GetNames(typeof(HouseManagerRole)).Select(p => p.ToUnderScoreCase());
|
||||
|
||||
var _sysRoleRep = Db.GetRepository<SysRole>();
|
||||
var roles = await _sysRoleRep.DetachedEntities.Where(p => codes.Contains(p.Code)).ToListAsync();
|
||||
|
||||
@@ -55,15 +55,13 @@ 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
|
||||
WHERE HM.Id IS NULL";
|
||||
return await _dapperRep.QueryPageDataDynamic(sql, input, param: new
|
||||
{
|
||||
input.UserId,
|
||||
Address = "%" + input.Address + "%",
|
||||
HouseCode = "%" + input.HouseCode + "%"
|
||||
input.UserId
|
||||
}, filterFields: new[] {
|
||||
nameof(BsHouseCode.Address) ,
|
||||
nameof(BsHouseCode.CreatedTime)
|
||||
});
|
||||
}
|
||||
|
||||
@@ -82,15 +80,13 @@ 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
|
||||
INNER JOIN (SELECT * FROM bs_house_member_relation WHERE SysUserId = @UserId) HM ON HC.Id = HM.HouseCodeId";
|
||||
return await _dapperRep.QueryPageDataDynamic(sql, input, param: new
|
||||
{
|
||||
input.UserId,
|
||||
Address = "%" + input.Address + "%",
|
||||
HouseCode = "%" + input.HouseCode + "%"
|
||||
input.UserId
|
||||
}, filterFields: new[] {
|
||||
nameof(BsHouseCode.Address) ,
|
||||
nameof(BsHouseCode.CreatedTime)
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
using Ewide.Core;
|
||||
using Ewide.Core.Service;
|
||||
using Furion.DatabaseAccessor;
|
||||
using Furion.DependencyInjection;
|
||||
using Furion.DynamicApiController;
|
||||
using Furion.FriendlyException;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
@@ -18,15 +20,22 @@ namespace Ewide.Application.Service
|
||||
[ApiDescriptionSettings(Name = "HouseZone", Order = 180)]
|
||||
public class HouseZoneService : IHouseZoneService, IDynamicApiController, ITransient
|
||||
{
|
||||
private readonly IUserManager _userManager;
|
||||
private readonly IRepository<SysOrg> _sysOrgRep;
|
||||
private readonly IRepository<SysEmp> _sysEmpRep;
|
||||
private readonly ISysOrgService _sysOrgService;
|
||||
|
||||
public HouseZoneService(
|
||||
IRepository<SysOrg> sysOrgRep,
|
||||
IRepository<SysEmp> sysEmpRep
|
||||
IUserManager userManager,
|
||||
IRepository<SysOrg> sysOrgRep,
|
||||
IRepository<SysEmp> sysEmpRep,
|
||||
ISysOrgService sysOrgService
|
||||
)
|
||||
{
|
||||
_userManager = userManager;
|
||||
_sysOrgRep = sysOrgRep;
|
||||
_sysEmpRep = sysEmpRep;
|
||||
_sysOrgService = sysOrgService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -57,7 +66,7 @@ namespace Ewide.Application.Service
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("houseZone/getByUser")]
|
||||
[HttpGet("/houseZone/getByUser")]
|
||||
public async Task<string> GetZoneByUser([FromQuery][Required(ErrorMessage = "用户Id不能为空")] string userId)
|
||||
{
|
||||
var data = await _sysEmpRep.DetachedEntities.FirstOrDefaultAsync(p => p.Id == userId);
|
||||
@@ -66,5 +75,57 @@ namespace Ewide.Application.Service
|
||||
if(org == null) throw Oops.Oh("用户不在片区中");
|
||||
return org.Id;
|
||||
}
|
||||
|
||||
[HttpGet("/houseZone/autoIncrement")]
|
||||
public async Task<dynamic> AutoIncrement([FromQuery] string code)
|
||||
{
|
||||
var road = await _sysOrgRep.DetachedEntities.FirstOrDefaultAsync(p => p.AreaCode == code);
|
||||
if (road == null) throw Oops.Oh("组织机构错误");
|
||||
return await AutoIncrement(road);
|
||||
}
|
||||
|
||||
[NonAction]
|
||||
public async Task<dynamic> AutoIncrement(SysOrg road)
|
||||
{
|
||||
var maxZone = (await _sysOrgRep.DetachedEntities.Where(p => p.Pid == road.Id && p.Type == (int)OrgType.片区).MaxAsync(p => p.Code)) ?? "000";
|
||||
return Convert.ToInt32(maxZone[^3..]) + 1;
|
||||
}
|
||||
|
||||
[HttpPost("/houseZone/add")]
|
||||
public async Task AddZone(AddOrgInput input)
|
||||
{
|
||||
/*
|
||||
* 区县市限定所属区域/上级机构是否为当前区
|
||||
* 街道自动获取所属区域/上级机构
|
||||
* 自动生成唯一编码, 街道Code+三位编号
|
||||
*
|
||||
* 机构类型默认为片区
|
||||
*/
|
||||
|
||||
var org = await _userManager.GetUserOrgInfo();
|
||||
|
||||
var areaManager = Enum.GetName(HouseManagerRole.AreaManager).ToUnderScoreCase();
|
||||
var roadManager = Enum.GetName(HouseManagerRole.RoadManager).ToUnderScoreCase();
|
||||
var roles = await _userManager.GetUserRoleList();
|
||||
if (roles.Any(p => p.Code == areaManager))
|
||||
{
|
||||
var road = await _sysOrgRep.DetachedEntities.FirstOrDefaultAsync(p => p.AreaCode == input.AreaCode);
|
||||
if (!road.Pids.Contains(org.Id)) throw Oops.Oh("组织机构错误");
|
||||
|
||||
input.Pid = road.Id;
|
||||
input.Code = road.Code + (await AutoIncrement(road)).ToString().PadLeft(3, '0');
|
||||
}
|
||||
else if (roles.Any(p => p.Code == roadManager))
|
||||
{
|
||||
input.Pid = org.Id;
|
||||
input.AreaCode = org.AreaCode;
|
||||
|
||||
input.Code = org.Code + (await AutoIncrement(org)).ToString().PadLeft(3, '0');
|
||||
}
|
||||
|
||||
input.Type = (int)OrgType.片区;
|
||||
|
||||
await _sysOrgService.AddOrg(input);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user