.
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
using Ewide.Core;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Application
|
||||
{
|
||||
public class HouseCodeInput
|
||||
{
|
||||
}
|
||||
|
||||
public class AddHouseCodeInput : PageInputBase
|
||||
{
|
||||
public string HouseCode { get; set; }
|
||||
[Required(ErrorMessage = "行政区域编码不能为空")]
|
||||
public string AreaCode { get; set; }
|
||||
[Required(ErrorMessage = "项目Id不能为空")]
|
||||
public string ProjectId { get; set; }
|
||||
[Required(ErrorMessage = "房屋编号不能为空")]
|
||||
public int No { get; set; }
|
||||
[Required(ErrorMessage = "片区Id不能为空")]
|
||||
public string ZoneId { get; set; }
|
||||
[Required(ErrorMessage = "房屋地址不能为空")]
|
||||
public string Address { get; set; }
|
||||
[Required(ErrorMessage = "房屋性质不能为空")]
|
||||
public int Type { get; set; }
|
||||
[Required(ErrorMessage = "所属行业不能为空")]
|
||||
public int Industry { get; set; }
|
||||
[Required(ErrorMessage = "经度不能为空")]
|
||||
public string Lng { get; set; }
|
||||
[Required(ErrorMessage = "纬度不能为空")]
|
||||
public string Lat { get; set; }
|
||||
}
|
||||
|
||||
public class EditHouseCodeInput : AddHouseCodeInput
|
||||
{
|
||||
[Required(ErrorMessage = "房屋编码Id不能为空")]
|
||||
public string Id { get; set; }
|
||||
}
|
||||
|
||||
public class DeleteHouseCodeInput
|
||||
{
|
||||
[Required(ErrorMessage = "房屋编码ID不可为空")]
|
||||
public string Id { get; set; }
|
||||
}
|
||||
|
||||
public class QueryHouseCodeInput : PageInputBase
|
||||
{
|
||||
public string HouseCode { get; set; }
|
||||
public int? No { get; set; }
|
||||
public string Address { get; set; }
|
||||
public string ProjectId { get; set; }
|
||||
public string ZoonId { get; set; }
|
||||
public int Type { get; set; }
|
||||
}
|
||||
|
||||
public class GetHouseCodeInput
|
||||
{
|
||||
[Required(ErrorMessage = "房屋编码ID不可为空")]
|
||||
public string Id { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using Ewide.Core;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Application
|
||||
{
|
||||
public class HouseCodeOutput
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string Address { get; set; }
|
||||
public string ProjectId { get; set; }
|
||||
public string ZoneId { get; set; }
|
||||
public int Type { get; set; }
|
||||
public string AreaName { get; set; }
|
||||
public string RoadName { get; set; }
|
||||
public string CommName { get; set; }
|
||||
public string ZoneName { get; set; }
|
||||
public string ProjectNote { get; set; }
|
||||
public string FullProjName { get; set; }
|
||||
public string HouseCode { get; set; }
|
||||
public int No { get; set; }
|
||||
public string Lng { get; set; }
|
||||
public string Lat { get; set; }
|
||||
}
|
||||
|
||||
public class GetHouseCodeOutput
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string HouseCode { get; set; }
|
||||
public int Type { get; set; }
|
||||
public int Industry { get; set; }
|
||||
public string AreaCode { get; set; }
|
||||
public string ProjectId { get; set; }
|
||||
public int No { get; set; }
|
||||
public string ZoneId { get; set; }
|
||||
public string Address { get; set; }
|
||||
public string Lng { get; set; }
|
||||
public string Lat { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
using Ewide.Application.Entity;
|
||||
using Ewide.Core;
|
||||
using Furion.DatabaseAccessor;
|
||||
using Furion.DatabaseAccessor.Extensions;
|
||||
using Furion.DependencyInjection;
|
||||
using Furion.DynamicApiController;
|
||||
using Furion.FriendlyException;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Threading.Tasks;
|
||||
using Dapper;
|
||||
using Ewide.Core.Extension;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Ewide.Application.Service.HouseCode
|
||||
{
|
||||
/// <summary>
|
||||
/// 房屋编码相关
|
||||
/// </summary>
|
||||
[ApiDescriptionSettings(Name = "HouseCode", Order = 180)]
|
||||
public class HouseCodeService : IHouseCodeService, IDynamicApiController, ITransient
|
||||
{
|
||||
private readonly IRepository<BsHouseCode> _houseCodeRep;
|
||||
private readonly IDapperRepository _dapperRepository;
|
||||
|
||||
private readonly IUserManager _userManager;
|
||||
private readonly IHouseLogService _houseLogService;
|
||||
|
||||
public HouseCodeService(IRepository<BsHouseCode> HouseCodeRep, IDapperRepository dapperRepository, IUserManager userManager, IHouseLogService houseLogService)
|
||||
{
|
||||
_houseCodeRep = HouseCodeRep;
|
||||
_dapperRepository = dapperRepository;
|
||||
|
||||
_userManager = userManager;
|
||||
_houseLogService = houseLogService;
|
||||
}
|
||||
|
||||
[HttpPost("/houseCode/add")]
|
||||
[UnitOfWork]
|
||||
public async Task AddHouseCode(AddHouseCodeInput input)
|
||||
{
|
||||
var houseProjectInfoRep = Db.GetRepository<BsHouseProjectInfo>();
|
||||
var houseProject = await houseProjectInfoRep.FirstOrDefaultAsync(p => p.Id == input.ProjectId);
|
||||
if (houseProject == null) throw Oops.Oh("项目参数有误,添加失败");
|
||||
|
||||
var areaCodeRep = Db.GetRepository<SysAreaCode>();
|
||||
var areaCode = await areaCodeRep.DetachedEntities.FirstOrDefaultAsync(a => a.Code == input.AreaCode && a.LevelType == 4);
|
||||
if(areaCode == null) throw Oops.Oh("区域编码有误,添加失败");
|
||||
input.HouseCode = areaCode.AdCode + houseProject.Sort.ToString().PadLeft(3, '0') + input.No.ToString().PadLeft(3, '0');
|
||||
var id = System.Guid.NewGuid().ToString().ToLower();
|
||||
var houseCode = input.Adapt<BsHouseCode>();
|
||||
houseCode.Id = id;
|
||||
var isExist = await _houseCodeRep.AnyAsync(p => p.HouseCode == houseCode.HouseCode);
|
||||
if (isExist) throw Oops.Oh("房屋编码已存在,不可重复添加");
|
||||
await houseCode.InsertAsync();
|
||||
|
||||
// 添加到流转日志
|
||||
var sort = await _houseLogService.AddThenDone(id, _userManager.User, HouseLogType.CreateCode);
|
||||
sort = await _houseLogService.Add(id, _userManager.User, HouseLogType.SelectMember, sort: sort);
|
||||
}
|
||||
|
||||
[HttpPost("/houseCode/edit")]
|
||||
public async Task EditHouseCode(EditHouseCodeInput input)
|
||||
{
|
||||
var houseCode = input.Adapt<BsHouseCode>();
|
||||
await houseCode.UpdateExcludeAsync(new[] { nameof(BsHouseCode.HouseCode) }, true);
|
||||
}
|
||||
|
||||
[HttpPost("/houseCode/delete")]
|
||||
public async Task DeleteHouseCode(DeleteHouseCodeInput input)
|
||||
{
|
||||
var houseCode = _houseCodeRep.FirstOrDefault(p => p.Id == input.Id);
|
||||
await houseCode.DeleteNowAsync();
|
||||
}
|
||||
|
||||
[HttpPost("/houseCode/page")]
|
||||
public async Task<dynamic> QueryPage([FromBody] QueryHouseCodeInput input)
|
||||
{
|
||||
var sql = @"SELECT
|
||||
HC.*,AA.Name AreaName,RA.Name RoadName,CA.Name CommName,Proj.AreaCode,Proj.Note,CONCAT(Proj.`Name`, IFNULL(CONCAT('(',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) ";
|
||||
return await _dapperRepository.QueryPageDataDynamic(sql, input, filterFields: new string[] {"Type", "Address", "HouseCode","AreaCode"});
|
||||
}
|
||||
|
||||
[HttpGet("/houseCode/detail")]
|
||||
public async Task<dynamic> GetHouserCode([FromQuery] GetHouseCodeInput input)
|
||||
{
|
||||
var houseCode = await _houseCodeRep.DetachedEntities.FirstOrDefaultAsync(p => p.Id == input.Id);
|
||||
var areaCode = (await Db.GetRepository<BsHouseProjectInfo>().DetachedEntities.FirstOrDefaultAsync(p => p.Id == houseCode.ProjectId)).AreaCode;
|
||||
var result = houseCode.Adapt<GetHouseCodeOutput>();
|
||||
result.AreaCode = areaCode;
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取同一区域下的下一个编号
|
||||
/// </summary>
|
||||
/// <param name="projectId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("/houseCode/getNextNoByCode")]
|
||||
public async Task<dynamic> GetNextNoByFullNumber([Required] string projectId)
|
||||
{
|
||||
var areaCodeRep = Db.GetRepository<SysAreaCode>();
|
||||
var houseProjectInfoRep = Db.GetRepository<BsHouseProjectInfo>();
|
||||
var houseProject = await houseProjectInfoRep.FirstOrDefaultAsync(p => p.Id == projectId);
|
||||
if(houseProject == null) throw Oops.Oh("项目参数有误,房屋编码生成失败");
|
||||
//取到社区编码
|
||||
var commAreaCode = await areaCodeRep.FirstOrDefaultAsync(a => a.Code == houseProject.AreaCode && a.LevelType == 4);
|
||||
if(commAreaCode == null) throw Oops.Oh("项目区域编码有误,房屋编码生成失败");
|
||||
var maxNo = await _houseCodeRep.DetachedEntities
|
||||
.Where(h => h.HouseCode.Contains(commAreaCode.AdCode + houseProject.Sort.ToString().PadLeft(3, '0')))
|
||||
.MaxAsync(h => (int?)h.No);
|
||||
return maxNo.GetValueOrDefault(0) + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Application.Service.HouseCode
|
||||
{
|
||||
public interface IHouseCodeService
|
||||
{
|
||||
Task AddHouseCode(AddHouseCodeInput input);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
using Ewide.Core;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Application
|
||||
{
|
||||
public class HouseCompanyInput
|
||||
{
|
||||
[Required(ErrorMessage = "Id不能为空")]
|
||||
public string Id { get; set; }
|
||||
}
|
||||
|
||||
public class HouseCompanyInfoInput
|
||||
{
|
||||
[Required(ErrorMessage = "信息名称不能为空")]
|
||||
public string Name { get; set; }
|
||||
[Required(ErrorMessage = "信息内容不能为空")]
|
||||
public string Value { get; set; }
|
||||
}
|
||||
|
||||
public class HouseCompanyPageInput : PageInputBase {}
|
||||
|
||||
public class HouseCompanyAddInput
|
||||
{
|
||||
[Required(ErrorMessage = "名称不能为空")]
|
||||
public virtual string Name { get; set; }
|
||||
|
||||
private string _Type { get; set; }
|
||||
|
||||
[Required(ErrorMessage = "类型不能为空")]
|
||||
public virtual string Type
|
||||
{
|
||||
get
|
||||
{
|
||||
return _Type;
|
||||
}
|
||||
set
|
||||
{
|
||||
_Type = String.Join(",", value.Split(',').Select(p => $"[{p}]"));
|
||||
}
|
||||
}
|
||||
|
||||
public virtual List<HouseCompanyInfoInput> Info { get; set; }
|
||||
}
|
||||
|
||||
public class HouseCompanyEditInput : HouseCompanyAddInput
|
||||
{
|
||||
[Required(ErrorMessage = "Id不能为空")]
|
||||
public string Id { get; set; }
|
||||
}
|
||||
|
||||
public class HouseCompanyListInput
|
||||
{
|
||||
[Required(ErrorMessage = "类型不能为空")]
|
||||
public string Type { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Application
|
||||
{
|
||||
public class HouseCompanyInfoOutput
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Value { get; set; }
|
||||
}
|
||||
|
||||
public class HouseCompanyDetailOutput
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
private string _Type { get; set; }
|
||||
public string Type
|
||||
{
|
||||
get
|
||||
{
|
||||
return _Type;
|
||||
}
|
||||
set
|
||||
{
|
||||
_Type = String.Join(",", value.Split(',').Select(p => p.Replace("[", "").Replace("]", "")));
|
||||
}
|
||||
}
|
||||
public List<HouseCompanyInfoOutput> Info { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
using Ewide.Core.Extension;
|
||||
using Furion.DatabaseAccessor;
|
||||
using Furion.DatabaseAccessor.Extensions;
|
||||
using Furion.DependencyInjection;
|
||||
using Furion.DynamicApiController;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Application.Service
|
||||
{
|
||||
[ApiDescriptionSettings(Name = "HouseCompany")]
|
||||
public class HouseCompanyService : IHouseCompanyService, IDynamicApiController, ITransient
|
||||
{
|
||||
private readonly IRepository<BsHouseCompany> _bsHouseCompanyRep;
|
||||
|
||||
public HouseCompanyService(IRepository<BsHouseCompany> bsHouseCompanyRep)
|
||||
{
|
||||
_bsHouseCompanyRep = bsHouseCompanyRep;
|
||||
}
|
||||
|
||||
[HttpPost("/houseCompany/page")]
|
||||
public async Task<dynamic> Page([FromBody] HouseCompanyPageInput input)
|
||||
{
|
||||
var config = new TypeAdapterConfig().ForType<BsHouseCompany, HouseCompanyDetailOutput>()
|
||||
.Map(target => target.Info, src => JsonConvert.DeserializeObject<List<HouseCompanyInfoOutput>>(src.Info))
|
||||
.Config;
|
||||
return await _bsHouseCompanyRep.DetachedEntities.ToPageData<BsHouseCompany, HouseCompanyDetailOutput>(input, config);
|
||||
}
|
||||
|
||||
[HttpPost("/houseCompany/add")]
|
||||
public async Task Add([FromBody] HouseCompanyAddInput input)
|
||||
{
|
||||
var info = JsonConvert.SerializeObject(input.Info);
|
||||
var config = new TypeAdapterConfig().ForType<HouseCompanyAddInput, BsHouseCompany>()
|
||||
.Map(target => target.Info, src => JsonConvert.SerializeObject(src.Info))
|
||||
.Config;
|
||||
var company = input.Adapt<BsHouseCompany>(config);
|
||||
await company.InsertAsync();
|
||||
}
|
||||
|
||||
[HttpPost("/houseCompany/edit")]
|
||||
public async Task Edit([FromBody] HouseCompanyEditInput input)
|
||||
{
|
||||
var config = new TypeAdapterConfig().ForType<HouseCompanyEditInput, BsHouseCompany>()
|
||||
.Map(target => target.Info, src => JsonConvert.SerializeObject(src.Info))
|
||||
.Config;
|
||||
var company = input.Adapt<BsHouseCompany>(config);
|
||||
await company.UpdateAsync();
|
||||
}
|
||||
|
||||
[HttpPost("/houseCompany/delete")]
|
||||
public async Task Delete([FromBody] HouseCompanyInput input)
|
||||
{
|
||||
var company = await _bsHouseCompanyRep.FirstOrDefaultAsync(p => p.Id.Equals(input.Id));
|
||||
await company.DeleteAsync();
|
||||
}
|
||||
|
||||
[HttpGet("/houseCompany/detail")]
|
||||
public async Task<HouseCompanyDetailOutput> Detail([FromQuery] HouseCompanyInput input)
|
||||
{
|
||||
var company = await _bsHouseCompanyRep.FirstOrDefaultAsync(p => p.Id.Equals(input.Id));
|
||||
var config = new TypeAdapterConfig().ForType<BsHouseCompany, HouseCompanyDetailOutput>()
|
||||
.Map(target => target.Info, src => JsonConvert.DeserializeObject<List<HouseCompanyInfoOutput>>(src.Info))
|
||||
.Config;
|
||||
var output = company.Adapt<HouseCompanyDetailOutput>(config);
|
||||
return output;
|
||||
}
|
||||
|
||||
[HttpGet("/houseCompany/list")]
|
||||
public async Task<dynamic> List([FromQuery] HouseCompanyListInput input)
|
||||
{
|
||||
var types = input.Type.Split(',');
|
||||
var result = new List<HouseCompanyDetailOutput>();
|
||||
var config = new TypeAdapterConfig().ForType<BsHouseCompany, HouseCompanyDetailOutput>()
|
||||
.Map(target => target.Info, src => JsonConvert.DeserializeObject<List<HouseCompanyInfoOutput>>(src.Info))
|
||||
.Config;
|
||||
foreach (var type in types)
|
||||
{
|
||||
var list = (await _bsHouseCompanyRep.DetachedEntities
|
||||
.Where(p => EF.Functions.Like(p.Type, $"%[{type.Trim()}]%"))
|
||||
.OrderBy(p => p.Name)
|
||||
.ToListAsync())
|
||||
.Select(p =>
|
||||
{
|
||||
var output = p.Adapt<HouseCompanyDetailOutput>(config);
|
||||
return output;
|
||||
});
|
||||
result.AddRange(list);
|
||||
}
|
||||
|
||||
return result.Distinct();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Application.Service
|
||||
{
|
||||
public interface IHouseCompanyService
|
||||
{
|
||||
Task<dynamic> Page([FromBody] HouseCompanyPageInput input);
|
||||
Task Add([FromBody] HouseCompanyAddInput input);
|
||||
Task Edit([FromBody] HouseCompanyEditInput input);
|
||||
Task Delete([FromBody] HouseCompanyInput input);
|
||||
Task<HouseCompanyDetailOutput> Detail([FromQuery] HouseCompanyInput input);
|
||||
Task<dynamic> List([FromQuery] HouseCompanyListInput input);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,239 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Application
|
||||
{
|
||||
public class HouseInfoInput
|
||||
{
|
||||
#region 建筑物基本信息building
|
||||
public string BuildingName { get; set; }
|
||||
|
||||
public int? LandAttribute { get; set; }
|
||||
|
||||
public int? StructureType { get; set; }
|
||||
|
||||
public int? SeismicGrade { get; set; }
|
||||
|
||||
public int? BaseInfo { get; set; }
|
||||
|
||||
public string InsulationMaterial { get; set; }
|
||||
|
||||
public string WallMaterial { get; set; }
|
||||
|
||||
public string FireproofGrade { get; set; }
|
||||
public int? CurtainWall { get; set; }
|
||||
public int? FaceBrick { get; set; }
|
||||
public int? WhiteWash { get; set; }
|
||||
public int? Coating { get; set; }
|
||||
public string Elevator { get; set; }
|
||||
public DateTime? CompletedDate { get; set; }
|
||||
public int? UsefulYear { get; set; }
|
||||
/// <summary>
|
||||
/// 总建筑面积
|
||||
/// </summary>
|
||||
public float? TotalArea { get; set; }
|
||||
/// <summary>
|
||||
/// 总户数(户)
|
||||
/// </summary>
|
||||
public int? HouseHolds { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 房屋单元数
|
||||
/// </summary>
|
||||
public int? Units { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 各单元每层户数(户)
|
||||
/// </summary>
|
||||
public int? UnitFloorHolds { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 总层数
|
||||
/// </summary>
|
||||
public int? TotalFloor { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 地上层数
|
||||
/// </summary>
|
||||
public int? LandFloorCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 地上商业层数开始
|
||||
/// </summary>
|
||||
public int? LandBsFloorStart { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 地上商业层数结束
|
||||
/// </summary>
|
||||
public int? LandBsFloorEnd { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 地上车棚层开始
|
||||
/// </summary>
|
||||
public int? LandBikeFloorStart { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 地上住宅层开始
|
||||
/// </summary>
|
||||
public int? LandResidenceFloorStart { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 地上住宅层结束
|
||||
/// </summary>
|
||||
public int? LandResidenceFloorEnd { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 地下层数
|
||||
/// </summary>
|
||||
public int? UnderFloorCount { get; set; }
|
||||
#endregion
|
||||
#region 权属情况ownership
|
||||
/// <summary>
|
||||
/// 产权性质
|
||||
/// </summary>
|
||||
public string PropertyRights { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 总共套数
|
||||
/// </summary>
|
||||
public int? HouseCount { get; set; }
|
||||
/// <summary>
|
||||
/// 直管公房套数
|
||||
/// </summary>
|
||||
public int? StraightHouseCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 自管公房套数
|
||||
/// </summary>
|
||||
public int? SelfHouseCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 私房套数
|
||||
/// </summary>
|
||||
public int? PrivateHouseCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 商品房套数
|
||||
/// </summary>
|
||||
public int? BusinessCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 房改房套数
|
||||
/// </summary>
|
||||
public int? ChangeHouseCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 拆迁安置房套数
|
||||
/// </summary>
|
||||
public int? ResettlementHouseCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 其它套数
|
||||
/// </summary>
|
||||
public int? OtherCount { get; set; }
|
||||
|
||||
#endregion
|
||||
#region 管理情况manager
|
||||
#endregion
|
||||
|
||||
#region 鉴定治理identification
|
||||
|
||||
/// <summary>
|
||||
/// 房屋等级 1,2,3,4,C,d
|
||||
/// </summary>
|
||||
public int? HouseGrade { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 房屋使用状态
|
||||
/// </summary>
|
||||
public int? HouseUsedStatus { get; set; }
|
||||
#endregion
|
||||
|
||||
#region 图纸资料存档处drawing
|
||||
|
||||
/// <summary>
|
||||
/// 图纸资料存档处
|
||||
/// </summary>
|
||||
public string DrawingMaterial { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 其他图纸存档
|
||||
/// </summary>
|
||||
public string DrawingMaterialText { get; set; }
|
||||
#endregion
|
||||
|
||||
#region 相关附件资料attachments
|
||||
/// <summary>
|
||||
/// 立项文件
|
||||
/// </summary>
|
||||
public string AnEntryDocument { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 规划许可
|
||||
/// </summary>
|
||||
public string PlanningPermission { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 竣工验收备案
|
||||
/// </summary>
|
||||
public string CompletionRecord { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 监理资料
|
||||
/// </summary>
|
||||
public string MonitorDocument { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 鉴定报告
|
||||
/// </summary>
|
||||
public string IdentificationReport { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 其它资料
|
||||
/// </summary>
|
||||
public string OtherDocument { get; set; }
|
||||
#endregion
|
||||
|
||||
#region 建筑概貌aspect
|
||||
/// <summary>
|
||||
/// 外立面照片
|
||||
/// </summary>
|
||||
public string FacadePhoto { get; set; }
|
||||
#endregion
|
||||
|
||||
#region 调查单位unit
|
||||
/// <summary>
|
||||
/// 调查登记机构
|
||||
/// </summary>
|
||||
public string InvestigateAgency { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 纸质资料调查人
|
||||
/// </summary>
|
||||
public string InvestigateUser { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 纸质资料审核人
|
||||
/// </summary>
|
||||
public string OfflineAuditor { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 主管部门
|
||||
/// </summary>
|
||||
public string CompetentDepartment { get; set; }
|
||||
#endregion
|
||||
|
||||
public int State { get; set; }
|
||||
}
|
||||
|
||||
public class HouseInfoInputSave
|
||||
{
|
||||
public HouseCodeOutput houseCode { get; set; }
|
||||
public HouseInfoInput houseInfo { get; set; }
|
||||
public EditHouseTaskInput PatrolInfo { get; set; }
|
||||
public HouseTaskCheckRecordInput TaskCheckRecord { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,239 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Application
|
||||
{
|
||||
public class HouseInfoOutput
|
||||
{
|
||||
#region 建筑物基本信息building
|
||||
public string BuildingName { get; set; }
|
||||
|
||||
public int? LandAttribute { get; set; }
|
||||
|
||||
public int? StructureType { get; set; }
|
||||
|
||||
public int? SeismicGrade { get; set; }
|
||||
|
||||
public int? BaseInfo { get; set; }
|
||||
|
||||
public string InsulationMaterial { get; set; }
|
||||
|
||||
public string WallMaterial { get; set; }
|
||||
|
||||
public string FireproofGrade { get; set; }
|
||||
public int? CurtainWall { get; set; }
|
||||
public int? FaceBrick { get; set; }
|
||||
public int? WhiteWash { get; set; }
|
||||
public int? Coating { get; set; }
|
||||
public string Elevator { get; set; }
|
||||
public DateTime? CompletedDate { get; set; }
|
||||
public int? UsefulYear { get; set; }
|
||||
/// <summary>
|
||||
/// 总建筑面积
|
||||
/// </summary>
|
||||
public float? TotalArea { get; set; }
|
||||
/// <summary>
|
||||
/// 总户数(户)
|
||||
/// </summary>
|
||||
public int? HouseHolds { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 房屋单元数
|
||||
/// </summary>
|
||||
public int? Units { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 各单元每层户数(户)
|
||||
/// </summary>
|
||||
public int? UnitFloorHolds { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 总层数
|
||||
/// </summary>
|
||||
public int? TotalFloor { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 地上层数
|
||||
/// </summary>
|
||||
public int? LandFloorCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 地上商业层数开始
|
||||
/// </summary>
|
||||
public int? LandBsFloorStart { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 地上商业层数结束
|
||||
/// </summary>
|
||||
public int? LandBsFloorEnd { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 地上车棚层开始
|
||||
/// </summary>
|
||||
public int? LandBikeFloorStart { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 地上住宅层开始
|
||||
/// </summary>
|
||||
public int? LandResidenceFloorStart { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 地上住宅层结束
|
||||
/// </summary>
|
||||
public int? LandResidenceFloorEnd { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 地下层数
|
||||
/// </summary>
|
||||
public int? UnderFloorCount { get; set; }
|
||||
#endregion
|
||||
#region 权属情况ownership
|
||||
/// <summary>
|
||||
/// 产权性质
|
||||
/// </summary>
|
||||
public string PropertyRights { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 总共套数
|
||||
/// </summary>
|
||||
public int? HouseCount { get; set; }
|
||||
/// <summary>
|
||||
/// 直管公房套数
|
||||
/// </summary>
|
||||
public int? StraightHouseCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 自管公房套数
|
||||
/// </summary>
|
||||
public int? SelfHouseCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 私房套数
|
||||
/// </summary>
|
||||
public int? PrivateHouseCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 商品房套数
|
||||
/// </summary>
|
||||
public int? BusinessCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 房改房套数
|
||||
/// </summary>
|
||||
public int? ChangeHouseCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 拆迁安置房套数
|
||||
/// </summary>
|
||||
public int? ResettlementHouseCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 其它套数
|
||||
/// </summary>
|
||||
public int? OtherCount { get; set; }
|
||||
|
||||
#endregion
|
||||
#region 管理情况manager
|
||||
#endregion
|
||||
|
||||
#region 鉴定治理identification
|
||||
|
||||
/// <summary>
|
||||
/// 房屋等级 1,2,3,4,C,d
|
||||
/// </summary>
|
||||
public int? HouseGrade { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 房屋使用状态
|
||||
/// </summary>
|
||||
public int? HouseUsedStatus { get; set; }
|
||||
#endregion
|
||||
|
||||
#region 图纸资料存档处drawing
|
||||
|
||||
/// <summary>
|
||||
/// 图纸资料存档处
|
||||
/// </summary>
|
||||
public string DrawingMaterial { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 其他图纸存档
|
||||
/// </summary>
|
||||
public string DrawingMaterialText { get; set; }
|
||||
#endregion
|
||||
|
||||
#region 相关附件资料attachments
|
||||
/// <summary>
|
||||
/// 立项文件
|
||||
/// </summary>
|
||||
public string AnEntryDocument { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 规划许可
|
||||
/// </summary>
|
||||
public string PlanningPermission { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 竣工验收备案
|
||||
/// </summary>
|
||||
public string CompletionRecord { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 监理资料
|
||||
/// </summary>
|
||||
public string MonitorDocument { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 鉴定报告
|
||||
/// </summary>
|
||||
public string IdentificationReport { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 其它资料
|
||||
/// </summary>
|
||||
public string OtherDocument { get; set; }
|
||||
#endregion
|
||||
|
||||
#region 建筑概貌aspect
|
||||
/// <summary>
|
||||
/// 外立面照片
|
||||
/// </summary>
|
||||
public string FacadePhoto { get; set; }
|
||||
#endregion
|
||||
public int State { get; set; }
|
||||
#region 调查单位unit
|
||||
/// <summary>
|
||||
/// 调查登记机构
|
||||
/// </summary>
|
||||
public string InvestigateAgency { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 纸质资料调查人
|
||||
/// </summary>
|
||||
public string InvestigateUser { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 纸质资料审核人
|
||||
/// </summary>
|
||||
public string OfflineAuditor { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 主管部门
|
||||
/// </summary>
|
||||
public string CompetentDepartment { get; set; }
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class HouseInfoOutputForDetailPage
|
||||
{
|
||||
#region header
|
||||
public HouseCodeOutput HouseCode { get; set; }
|
||||
#endregion
|
||||
|
||||
public HouseInfoOutput HouseInfo { get; set; }
|
||||
public HouseTaskOutput PatrolInfo { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,208 @@
|
||||
using Dapper;
|
||||
using Ewide.Core;
|
||||
using Furion.DatabaseAccessor;
|
||||
using Furion.DatabaseAccessor.Extensions;
|
||||
using Furion.DependencyInjection;
|
||||
using Furion.DynamicApiController;
|
||||
using Furion.FriendlyException;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Application.Service.HouseSafety.HouseInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// 房屋详细信息
|
||||
/// </summary>
|
||||
[ApiDescriptionSettings(Name = "HouseInfo", Order = 200)]
|
||||
public class HouseInfoService : IHouseInfoService, IDynamicApiController, ITransient
|
||||
{
|
||||
|
||||
private readonly IRepository<BsHouseCode> _houseCodeRep;
|
||||
private readonly IRepository<BsHouseInfo> _houseInfoRep;
|
||||
private readonly IRepository<BsHouseTask> _houseTaskRep;
|
||||
private readonly IRepository<SysUser> _sysUserRep;
|
||||
private readonly IUserManager _userManager;
|
||||
private readonly IDapperRepository _dapperRepository;
|
||||
|
||||
private readonly IHouseLogService _houseLogService;
|
||||
|
||||
|
||||
public HouseInfoService(
|
||||
IRepository<BsHouseCode> HouseCodeRep,
|
||||
IRepository<BsHouseInfo> HouseInfoRep,
|
||||
IRepository<BsHouseTask> HouseTaskRep,
|
||||
IRepository<SysUser> sysUserRep,
|
||||
IUserManager userManager, IDapperRepository dapperRepository, IHouseLogService houseLogService)
|
||||
{
|
||||
_houseCodeRep = HouseCodeRep;
|
||||
_houseInfoRep = HouseInfoRep;
|
||||
_houseTaskRep = HouseTaskRep;
|
||||
_sysUserRep = sysUserRep;
|
||||
_userManager = userManager;
|
||||
_dapperRepository = dapperRepository;
|
||||
|
||||
_houseLogService = houseLogService;
|
||||
}
|
||||
|
||||
[HttpPost("/houseInfo/save")]
|
||||
[UnitOfWork]
|
||||
[AllowAnonymous]
|
||||
public async Task Save([FromBody] HouseInfoInputSave input)
|
||||
{
|
||||
await InputDataProcess(input, DataStatus.Saved);
|
||||
}
|
||||
|
||||
[HttpPost("/houseInfo/submitToCheck")]
|
||||
[UnitOfWork]
|
||||
[AllowAnonymous]
|
||||
public async Task SubmitToCheck([FromBody] HouseInfoInputSave input)
|
||||
{
|
||||
await InputDataProcess(input,DataStatus.Submited);
|
||||
}
|
||||
|
||||
[HttpPost("/houseInfo/check")]
|
||||
[UnitOfWork]
|
||||
public async Task Check([FromBody] HouseInfoInputSave input)
|
||||
{
|
||||
await InputDataProcess(input, input.TaskCheckRecord.PassOrBackDataStatus );
|
||||
}
|
||||
|
||||
[HttpGet("/houseInfo/getByTaskId")]
|
||||
[UnitOfWork]
|
||||
public async Task<HouseInfoOutputForDetailPage> GetByTaskId([Required] string taskId)
|
||||
{
|
||||
//获取任务实体
|
||||
var houseTask = await _houseTaskRep.DetachedEntities.FirstOrDefaultAsync(t=>t.Id == taskId);
|
||||
if(houseTask == null) throw Oops.Oh("任务不存在");
|
||||
|
||||
//获取房屋编码信息
|
||||
var houseCodeOutputAsync = await _dapperRepository.QueryAsync<HouseCodeOutput>(
|
||||
@"SELECT
|
||||
HC.Id,HC.Address,HC.ProjectId,HC.ZoneId,HC.Type,AA.Name AreaName,RA.Name RoadName,CA.Name CommName,O.Name ZoneName,Proj.Note ProjectNote,CONCAT(Proj.`Name`, IFNULL(CONCAT('(',Proj.Note,')'), '')) FullProjName,HC.HouseCode,HC.Lng,HC.Lat,HC.No
|
||||
FROM bs_house_code HC
|
||||
LEFT JOIN bs_house_projectinfo Proj ON Proj.Id=HC.ProjectId
|
||||
LEFT JOIN sys_org O ON HC.ZoneId = O.Id
|
||||
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)
|
||||
WHERE HC.Id=@HouseCodeId", new { houseTask.HouseCodeId }
|
||||
);
|
||||
var houseCodeOutput= houseCodeOutputAsync.SingleOrDefault();
|
||||
if (houseCodeOutput == null) throw Oops.Oh("任务已失效:房屋编码不存在,请重新加载任务列表");
|
||||
|
||||
//获取当前登录账号
|
||||
var currentUser = await _userManager.CheckUserAsync();
|
||||
|
||||
//查询房屋详细信息是否存在
|
||||
var houseInfo = await _houseInfoRep.DetachedEntities.FirstOrDefaultAsync(h => h.HouseCodeId == houseTask.HouseCodeId);
|
||||
var houseInfoOutputForDetailPage = new HouseInfoOutputForDetailPage
|
||||
{
|
||||
HouseCode = houseCodeOutput
|
||||
};
|
||||
|
||||
var taskOutput = houseTask.Adapt<HouseTaskOutput>();
|
||||
taskOutput.PatrolDate = houseTask.PatrolDate.GetValueOrDefault(DateTime.Now);
|
||||
taskOutput.PatrolUser = String.IsNullOrEmpty(houseTask.PatrolUser) ? currentUser.Name : houseTask.PatrolUser;
|
||||
houseInfoOutputForDetailPage.PatrolInfo = taskOutput;
|
||||
|
||||
if (houseInfo == null || houseInfo.State <= (int)DataStatus.Submited)
|
||||
{
|
||||
// 未建档或者当前数据未提交时打开,标记为已读
|
||||
await _houseLogService.Read(houseCodeOutput.Id);
|
||||
}
|
||||
|
||||
if (houseInfo == null)
|
||||
{
|
||||
houseInfoOutputForDetailPage.HouseInfo = new HouseInfoOutput();
|
||||
return houseInfoOutputForDetailPage;
|
||||
}
|
||||
|
||||
var houseInfoOutput = (await _houseInfoRep.DetachedEntities.FirstOrDefaultAsync(p => p.HouseCodeId == houseTask.HouseCodeId)).Adapt<HouseInfoOutput>();
|
||||
houseInfoOutputForDetailPage.HouseInfo = houseInfoOutput;
|
||||
|
||||
return houseInfoOutputForDetailPage;
|
||||
}
|
||||
|
||||
[NonAction]
|
||||
[UnitOfWork]
|
||||
public async Task InputDataProcess(HouseInfoInputSave input,DataStatus dataStatus = DataStatus.Init)
|
||||
{
|
||||
//房屋编码地址/坐标单独更新
|
||||
var houseCode = input.houseCode.Adapt<BsHouseCode>();
|
||||
await houseCode.UpdateIncludeAsync(new[] { nameof(BsHouseCode.Address), nameof(BsHouseCode.Lng), nameof(BsHouseCode.Lat) }, true);
|
||||
|
||||
//获取房屋详情实体,判断是新增还是更新
|
||||
var houseEntity = await _houseInfoRep.DetachedEntities.FirstOrDefaultAsync(h => h.HouseCodeId == input.houseCode.Id);
|
||||
|
||||
//建档审核通过的房屋数据修改时,对应的建档任务Task不处理
|
||||
var houseTask = await _houseTaskRep.DetachedEntities.FirstOrDefaultAsync(p => p.Id == input.PatrolInfo.Id);
|
||||
if (houseEntity == null || houseEntity.State != 6)
|
||||
{
|
||||
var _houseTask = input.PatrolInfo.Adapt<BsHouseTask>();
|
||||
_houseTask.HouseCodeId = input.houseCode.Id;
|
||||
//任务没有暂存状态,其他状态与HouseInfo的State一致
|
||||
_houseTask.Status = dataStatus == DataStatus.TempSaved ? (int)DataStatus.Saved : (int)dataStatus;
|
||||
await _houseTask.UpdateExcludeAsync(new string[] { nameof(BsHouseTask.TaskType) }, ignoreNullValues: true);
|
||||
}
|
||||
//判断房屋建档状态
|
||||
//dataStatus == DataStatus.Saved 若是保存操作 则判断是新增/更新
|
||||
//判断是新增/更新 根据传入参数dataStatus确定
|
||||
input.houseInfo.State = dataStatus == DataStatus.Saved ? (houseEntity == null ? (int)DataStatus.Saved : houseEntity.State) : (int)dataStatus;
|
||||
var houseInfo = input.houseInfo.Adapt<BsHouseInfo>();
|
||||
houseInfo.HouseCodeId = input.houseCode.Id;
|
||||
|
||||
if (houseEntity == null)
|
||||
{
|
||||
houseInfo.Id = Guid.NewGuid().ToString();
|
||||
await houseInfo.InsertAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
houseInfo.Id = houseEntity.Id;
|
||||
await houseInfo.UpdateExcludeAsync(new[] { nameof(BsHouseInfo.HouseGrade) }, true);
|
||||
}
|
||||
|
||||
int? logSort = null;
|
||||
|
||||
if (dataStatus == DataStatus.Submited)
|
||||
{
|
||||
await _houseLogService.Done(input.houseCode.Id);
|
||||
|
||||
var org = await _userManager.GetUserOrgInfo();
|
||||
|
||||
var _sysEmpRep = Db.GetRepository<SysEmp>();
|
||||
var _sysUserRoleRep = Db.GetRepository<SysUserRole>();
|
||||
var _sysRoleRep = Db.GetRepository<SysRole>();
|
||||
var zoneManagerList = await (from u in _sysUserRep.DetachedEntities
|
||||
join e in _sysEmpRep.DetachedEntities on u.Id equals e.Id
|
||||
join ur in _sysUserRoleRep.DetachedEntities on u.Id equals ur.SysUserId
|
||||
join r in _sysRoleRep.DetachedEntities on ur.SysRoleId equals r.Id
|
||||
where e.OrgId == org.Id && r.Code == Enum.GetName(HouseManagerRole.ZoneManager).ToUnderScoreCase()
|
||||
select u).ToListAsync();
|
||||
|
||||
logSort = await _houseLogService.Add(input.houseCode.Id, zoneManagerList, HouseLogType.Check);
|
||||
}
|
||||
//审核操作则新增一条审核记录
|
||||
if (dataStatus == DataStatus.Back || dataStatus == DataStatus.Passed)
|
||||
{
|
||||
var checkRecord = input.TaskCheckRecord.Adapt<BsHouseTaskCheckRecord>();
|
||||
await checkRecord.InsertAsync();
|
||||
await _houseLogService.Done(input.houseCode.Id);
|
||||
logSort = await _houseLogService.AddThenDone(input.houseCode.Id, _userManager.User, dataStatus == DataStatus.Passed ? HouseLogType.Agree : HouseLogType.Disagree, remark: checkRecord.Content, sort: logSort);
|
||||
if (dataStatus == DataStatus.Back)
|
||||
{
|
||||
var user = await _sysUserRep.DetachedEntities.FirstOrDefaultAsync(p => p.Id.Equals(houseTask.UserID));
|
||||
logSort = await _houseLogService.Add(input.houseCode.Id, user, HouseLogType.CreateInfo, sort: logSort);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Application.Service
|
||||
{
|
||||
public interface IHouseInfoService
|
||||
{
|
||||
Task<HouseInfoOutputForDetailPage> GetByTaskId(string taskId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Application
|
||||
{
|
||||
public class HouseLogInput
|
||||
{
|
||||
[Required(ErrorMessage = "Id不能为空")]
|
||||
public string Id { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Application
|
||||
{
|
||||
public class HouseLogOutput
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string TargetUserNames { get; set; }
|
||||
public int Type { get; set; }
|
||||
public int Status { get; set; }
|
||||
public string Remark { get; set; }
|
||||
public DateTime? FinishedTime { get; set; }
|
||||
public string FinishedUserId { get; set; }
|
||||
public string FinishedUserName { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,209 @@
|
||||
using Dapper;
|
||||
using Ewide.Core;
|
||||
using Furion.DatabaseAccessor;
|
||||
using Furion.DatabaseAccessor.Extensions;
|
||||
using Furion.DependencyInjection;
|
||||
using Furion.DynamicApiController;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Application.Service
|
||||
{
|
||||
/// <summary>
|
||||
/// 房屋流转日志
|
||||
/// </summary>
|
||||
[ApiDescriptionSettings(Name = "HouseLog", Order = 210)]
|
||||
public class HouseLogService : IHouseLogService, IDynamicApiController, ITransient
|
||||
{
|
||||
private readonly IDapperRepository _dapperRep;
|
||||
|
||||
private readonly IUserManager _userManager;
|
||||
|
||||
private readonly IRepository<BsHouseLog> _bsHouseLogRep;
|
||||
|
||||
public HouseLogService(IDapperRepository dapperRep, IUserManager userManager, IRepository<BsHouseLog> bsHouseLogRep)
|
||||
{
|
||||
_dapperRep = dapperRep;
|
||||
_userManager = userManager;
|
||||
_bsHouseLogRep = bsHouseLogRep;
|
||||
}
|
||||
|
||||
[NonAction]
|
||||
[UnitOfWork]
|
||||
public async Task<int> Add(string houseCodeId, SysUser targetUser, HouseLogType type, string remark = null, int? sort = null)
|
||||
{
|
||||
return await Add(houseCodeId, new List<SysUser> { targetUser }, type, remark, sort);
|
||||
}
|
||||
|
||||
[NonAction]
|
||||
[UnitOfWork]
|
||||
public async Task<int> Add(string houseCodeId, List<SysUser> targetUsers, HouseLogType type, string remark = null, int? sort = null)
|
||||
{
|
||||
if (!sort.HasValue)
|
||||
{
|
||||
sort = await _bsHouseLogRep.DetachedEntities.Where(p => p.HouseCodeId.Equals(houseCodeId)).MaxAsync(p => p.Sort);
|
||||
}
|
||||
var _sort = sort.GetValueOrDefault(1) + 1;
|
||||
await new BsHouseLog
|
||||
{
|
||||
Id = Guid.NewGuid().ToString(),
|
||||
HouseCodeId = houseCodeId,
|
||||
TargetUserIds = String.Join(",", targetUsers.Select(p => p.Id)),
|
||||
Type = type,
|
||||
Status = HouseLogStatus.Handle,
|
||||
Remark = remark,
|
||||
Sort = _sort
|
||||
}.InsertAsync();
|
||||
|
||||
return _sort;
|
||||
}
|
||||
|
||||
[NonAction]
|
||||
[UnitOfWork]
|
||||
public async Task Read(string houseCodeId)
|
||||
{
|
||||
var log = await _bsHouseLogRep
|
||||
.Where(p => p.HouseCodeId.Equals(houseCodeId) && p.Status.Equals(HouseLogStatus.Handle))
|
||||
.OrderByDescending(p => p.CreatedTime)
|
||||
.FirstOrDefaultAsync();
|
||||
if (log != null)
|
||||
{
|
||||
log.Status = HouseLogStatus.Handling;
|
||||
await log.UpdateAsync();
|
||||
}
|
||||
}
|
||||
|
||||
[NonAction]
|
||||
[UnitOfWork]
|
||||
public async Task Done(string houseCodeId)
|
||||
{
|
||||
var log = await _bsHouseLogRep
|
||||
.Where(p => p.HouseCodeId.Equals(houseCodeId) && !p.Status.Equals(HouseLogStatus.Handled))
|
||||
.OrderByDescending(p => p.CreatedTime)
|
||||
.FirstOrDefaultAsync();
|
||||
if (log != null)
|
||||
{
|
||||
log.Status = HouseLogStatus.Handled;
|
||||
log.FinishedTime = DateTime.Now;
|
||||
log.FinishedUserId = _userManager.UserId;
|
||||
log.FinishedUserName = _userManager.User.Account;
|
||||
await log.UpdateAsync();
|
||||
}
|
||||
}
|
||||
|
||||
[NonAction]
|
||||
[UnitOfWork]
|
||||
public async Task<int> AddThenRead(string houseCodeId, SysUser targetUser, HouseLogType type, string remark = null, int? sort = null)
|
||||
{
|
||||
return await AddThenRead(houseCodeId, new List<SysUser> { targetUser }, type, remark, sort);
|
||||
}
|
||||
|
||||
[NonAction]
|
||||
[UnitOfWork]
|
||||
public async Task<int> AddThenRead(string houseCodeId, List<SysUser> targetUsers, HouseLogType type, string remark = null, int? sort = null)
|
||||
{
|
||||
if (!sort.HasValue)
|
||||
{
|
||||
sort = await _bsHouseLogRep.DetachedEntities.Where(p => p.HouseCodeId.Equals(houseCodeId)).MaxAsync(p => p.Sort);
|
||||
}
|
||||
var _sort = sort.GetValueOrDefault(1) + 1;
|
||||
await new BsHouseLog
|
||||
{
|
||||
Id = Guid.NewGuid().ToString(),
|
||||
HouseCodeId = houseCodeId,
|
||||
TargetUserIds = String.Join(",", targetUsers.Select(p => p.Id)),
|
||||
Type = type,
|
||||
Status = HouseLogStatus.Handling,
|
||||
Remark = remark,
|
||||
Sort = _sort
|
||||
}.InsertAsync();
|
||||
|
||||
return _sort;
|
||||
}
|
||||
|
||||
[NonAction]
|
||||
[UnitOfWork]
|
||||
public async Task<int> AddThenDone(string houseCodeId, SysUser targetUser, HouseLogType type, string remark = null, int? sort = null)
|
||||
{
|
||||
return await AddThenDone(houseCodeId, new List<SysUser> { targetUser }, type, remark, sort);
|
||||
}
|
||||
|
||||
[NonAction]
|
||||
[UnitOfWork]
|
||||
public async Task<int> AddThenDone(string houseCodeId, List<SysUser> targetUsers, HouseLogType type, string remark = null, int? sort = null)
|
||||
{
|
||||
if (!sort.HasValue)
|
||||
{
|
||||
sort = await _bsHouseLogRep.DetachedEntities.Where(p => p.HouseCodeId.Equals(houseCodeId)).MaxAsync(p => p.Sort);
|
||||
}
|
||||
var _sort = sort.GetValueOrDefault(1) + 1;
|
||||
await new BsHouseLog
|
||||
{
|
||||
Id = Guid.NewGuid().ToString(),
|
||||
HouseCodeId = houseCodeId,
|
||||
TargetUserIds = String.Join(",", targetUsers.Select(p => p.Id)),
|
||||
Type = type,
|
||||
Status = HouseLogStatus.Handled,
|
||||
Remark = remark,
|
||||
FinishedTime = DateTime.Now,
|
||||
FinishedUserId = _userManager.UserId,
|
||||
FinishedUserName = _userManager.User.Account,
|
||||
Sort = _sort
|
||||
}.InsertAsync();
|
||||
|
||||
return _sort;
|
||||
}
|
||||
|
||||
[HttpGet("/houseLog/list")]
|
||||
public async Task<dynamic> List([FromQuery] HouseLogInput input)
|
||||
{
|
||||
var sql = @"SELECT
|
||||
HL.Id,
|
||||
HL.Type,
|
||||
HL.`Status`,
|
||||
HL.Remark,
|
||||
HL.FinishedTime,
|
||||
HL.FinishedUserId,
|
||||
IFNULL(NickName, `Name`) FinishedUserName,
|
||||
(SELECT GROUP_CONCAT(IFNULL(NickName,`Name`)) FROM sys_user
|
||||
WHERE Id IN (
|
||||
SELECT DISTINCT SUBSTRING_INDEX(SUBSTRING_INDEX(_HL.TargetUserIds,',',HT.help_topic_id + 1),',',-1)
|
||||
FROM bs_house_log _HL
|
||||
JOIN mysql.help_topic HT ON HT.help_topic_id < (LENGTH(_HL.TargetUserIds) - LENGTH(REPLACE(_HL.TargetUserIds,',','')) + 1)
|
||||
WHERE _HL.Id = HL.Id
|
||||
)
|
||||
) TargetUserNames
|
||||
FROM bs_house_log HL
|
||||
LEFT JOIN sys_user SU ON HL.FinishedUserId = SU.Id
|
||||
WHERE HouseCodeId = @HouseCodeId
|
||||
ORDER BY Sort DESC";
|
||||
|
||||
return await _dapperRep.QueryAsync<HouseLogOutput>(sql, new { houseCodeId = input.Id });
|
||||
}
|
||||
|
||||
[HttpGet("/houseLog/listByInfoId")]
|
||||
public async Task<dynamic> ListByInfoId([FromQuery] HouseLogInput input)
|
||||
{
|
||||
var info = await Db.GetRepository<BsHouseInfo>().DetachedEntities.FirstOrDefaultAsync(p => p.Id.Equals(input.Id));
|
||||
return await List(new HouseLogInput
|
||||
{
|
||||
Id = info.HouseCodeId
|
||||
});
|
||||
}
|
||||
|
||||
[HttpGet("/houseLog/listByTaskId")]
|
||||
public async Task<dynamic> ListByTaskId([FromQuery] HouseLogInput input)
|
||||
{
|
||||
var task = await Db.GetRepository<BsHouseTask>().DetachedEntities.FirstOrDefaultAsync(p => p.Id.Equals(input.Id));
|
||||
return await List(new HouseLogInput
|
||||
{
|
||||
Id = task.HouseCodeId
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using Ewide.Core;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Application.Service
|
||||
{
|
||||
public interface IHouseLogService
|
||||
{
|
||||
Task<int> Add(string houseCodeId, SysUser targetUser, HouseLogType type, string remark = null, int? sort = null);
|
||||
Task<int> Add(string houseCodeId, List<SysUser> targetUsers, HouseLogType type, string remark = null, int? sort = null);
|
||||
Task Read(string houseCodeId);
|
||||
Task Done(string houseCodeId);
|
||||
Task<int> AddThenRead(string houseCodeId, SysUser targetUser, HouseLogType type, string remark = null, int? sort = null);
|
||||
Task<int> AddThenRead(string houseCodeId, List<SysUser> targetUsers, HouseLogType type, string remark = null, int? sort = null);
|
||||
Task<int> AddThenDone(string houseCodeId, SysUser targetUser, HouseLogType type, string remark = null, int? sort = null);
|
||||
Task<int> AddThenDone(string houseCodeId, List<SysUser> targetUsers, HouseLogType type, string remark = null, int? sort = null);
|
||||
Task<dynamic> List(HouseLogInput input);
|
||||
Task<dynamic> ListByInfoId(HouseLogInput input);
|
||||
Task<dynamic> ListByTaskId(HouseLogInput input);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using Ewide.Core.Service;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Application.Service
|
||||
{
|
||||
public class AddHouseMemberInput : AddUserInput
|
||||
{
|
||||
[Required(ErrorMessage = "角色不能为空")]
|
||||
public string RoleId { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using Ewide.Core.Service;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Application.Service
|
||||
{
|
||||
public class HouseMemberOutput
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,326 @@
|
||||
using Dapper;
|
||||
using Ewide.Core;
|
||||
using Ewide.Core.Extension;
|
||||
using Ewide.Core.Service;
|
||||
using Furion.DatabaseAccessor;
|
||||
using Furion.DataEncryption;
|
||||
using Furion.DependencyInjection;
|
||||
using Furion.DynamicApiController;
|
||||
using Furion.FriendlyException;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System;
|
||||
|
||||
namespace Ewide.Application.Service
|
||||
{
|
||||
[ApiDescriptionSettings(Name = "HouseMember")]
|
||||
public class HouseMemberService : IHouseMemberService, IDynamicApiController, ITransient
|
||||
{
|
||||
private readonly IDapperRepository _dapperRepository;
|
||||
|
||||
private readonly IRepository<SysUser> _sysUserRep; // 用户表仓储
|
||||
private readonly IUserManager _userManager;
|
||||
private readonly ISysUserService _sysUserService;
|
||||
private readonly ISysEmpService _sysEmpService;
|
||||
|
||||
public HouseMemberService(
|
||||
IDapperRepository dapperRepository,
|
||||
IRepository<SysUser> sysUserRep,
|
||||
IUserManager userManager,
|
||||
ISysUserService sysUserService,
|
||||
ISysEmpService sysEmpService
|
||||
)
|
||||
{
|
||||
_dapperRepository = dapperRepository;
|
||||
_sysUserRep = sysUserRep;
|
||||
_userManager = userManager;
|
||||
_sysUserService = sysUserService;
|
||||
_sysEmpService = sysEmpService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 分页查询用户
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("/houseMember/page")]
|
||||
public async Task<dynamic> QueryMemberPageList([FromBody] UserInput input)
|
||||
{
|
||||
var dataScopes = await _userManager.GetUserAllDataScopeList();
|
||||
|
||||
var sql = @"SELECT
|
||||
SU.*,
|
||||
SO.Name OrgName,
|
||||
SUR.RoleName,
|
||||
SUR.RoleCode
|
||||
FROM sys_user SU
|
||||
LEFT JOIN sys_emp SE ON SU.Id = SE.Id
|
||||
LEFT JOIN sys_org SO ON SE.OrgId = SO.Id
|
||||
LEFT JOIN (
|
||||
SELECT
|
||||
SUR.SysUserId,
|
||||
GROUP_CONCAT(SR.Name) RoleName,
|
||||
GROUP_CONCAT(SR.Code) RoleCode
|
||||
FROM sys_user_role SUR
|
||||
LEFT JOIN sys_role SR ON SUR.SysRoleId = SR.Id
|
||||
GROUP BY SUR.SysUserId
|
||||
) SUR ON SU.Id = SUR.SysUserId
|
||||
WHERE 1=1";
|
||||
var param = new DynamicParameters();
|
||||
|
||||
if (!string.IsNullOrEmpty(input.SearchValue))
|
||||
{
|
||||
sql += @" AND (SU.Account Like @SearchValue
|
||||
OR SU.Name Like @SearchValue
|
||||
OR SU.Phone Like @SearchValue)";
|
||||
param.Add("SearchValue", "%" + input.SearchValue + "%");
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(input.SysEmpParam.OrgId))
|
||||
{
|
||||
var filter = " AND (SO.Id = @OrgId {0}) ";
|
||||
filter = String.Format(filter, input.TreeNodeDataScope.GetValueOrDefault(1) == 2 ? " OR SO.Pids Like CONCAT('%[', @OrgId, ']%') " : "");
|
||||
sql += filter;
|
||||
param.Add("OrgId", input.SysEmpParam.OrgId);
|
||||
}
|
||||
|
||||
if (input.SearchStatus >= 0)
|
||||
{
|
||||
sql += " AND SU.Status = @Status";
|
||||
param.Add("Status", input.SearchStatus);
|
||||
}
|
||||
|
||||
if (!_userManager.SuperAdmin)
|
||||
{
|
||||
sql += " AND SU.AdminType <> @AdminType";
|
||||
param.Add("AdminType", AdminType.SuperAdmin);
|
||||
|
||||
sql += " AND SU.Id <> @UserId";
|
||||
param.Add("UserId", _userManager.UserId);
|
||||
|
||||
if (dataScopes.Count > 0)
|
||||
{
|
||||
sql += " AND SO.Id IN @OrgIds";
|
||||
param.Add("OrgIds", dataScopes.ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
var users = await _dapperRepository.QueryPageData<UserOutput>(sql, input, param);
|
||||
|
||||
//foreach (var user in users.Items)
|
||||
//{
|
||||
// user.SysEmpInfo = await _sysEmpService.GetEmpInfo(user.Id);
|
||||
//}
|
||||
return PageDataResult<UserOutput>.PageResult(users);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 增加用户
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("/houseMember/add")]
|
||||
[UnitOfWork]
|
||||
public async Task AddUser(AddHouseMemberInput input)
|
||||
{
|
||||
var id = await _sysUserService.AddUser(input);
|
||||
var grantRoleInput = input.Adapt<UpdateUserInput>();
|
||||
grantRoleInput.Id = id;
|
||||
|
||||
// 添加角色
|
||||
grantRoleInput.GrantRoleIdList.Add(input.RoleId);
|
||||
await _sysUserService.GrantUserRole(grantRoleInput);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取角色
|
||||
/// </summary>
|
||||
/// <param name="orgId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("/houseMember/defaultRole")]
|
||||
public async Task<dynamic> DefaultRole([FromQuery] string orgId)
|
||||
{
|
||||
return (await GetDefaultRole(orgId)).Adapt<RoleOutput>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户拥有角色
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("/houseMember/ownRole")]
|
||||
public async Task<dynamic> GetUserOwnRole([FromQuery] QueryUserInput input)
|
||||
{
|
||||
return await _sysUserService.GetUserOwnRole(input);
|
||||
}
|
||||
|
||||
[HttpGet("/houseMember/defaultRoleRange")]
|
||||
public async Task<dynamic> DefaultRoleRange()
|
||||
{
|
||||
return (await GetRoleRange()).Select(p => p.Adapt<RoleOutput>()).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除用户
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("/houseMember/delete")]
|
||||
[UnitOfWork]
|
||||
public async Task DeleteUser(DeleteUserInput input)
|
||||
{
|
||||
/*
|
||||
* 未处理逻辑
|
||||
* 片区监管员在本片区已有安全员的情况下无法删除
|
||||
*/
|
||||
|
||||
await _sysUserService.DeleteUser(input);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新用户
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("/houseMember/edit")]
|
||||
[UnitOfWork]
|
||||
public async Task UpdateUser(UpdateUserInput input)
|
||||
{
|
||||
/*
|
||||
* 未处理逻辑
|
||||
* 如果移动组织架构,会产生以下几种逻辑
|
||||
* 片区1监管员(无安全员或有其他监管员)=>片区2,直接成功
|
||||
* 片区1监管员(有安全员并且无其他监管员)=>片区2,无法移动
|
||||
* 片区1安全员=>片区2(有监管员),直接成功
|
||||
* 片区1安全员=>片区2(无监管员),无法移动,需要创建监管员
|
||||
*/
|
||||
|
||||
await _sysUserService.UpdateUser(input);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查看用户
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("/houseMember/detail")]
|
||||
public async Task<dynamic> GetUser([FromQuery] QueryUserInput input)
|
||||
{
|
||||
var sql = @"SELECT
|
||||
SU.*,
|
||||
SO.Name OrgName,
|
||||
SUR.RoleName,
|
||||
SUR.RoleCode
|
||||
FROM sys_user SU
|
||||
LEFT JOIN sys_emp SE ON SU.Id = SE.Id
|
||||
LEFT JOIN sys_org SO ON SE.OrgId = SO.Id
|
||||
LEFT JOIN (
|
||||
SELECT
|
||||
SUR.SysUserId,
|
||||
GROUP_CONCAT(SR.Name) RoleName,
|
||||
GROUP_CONCAT(SR.Code) RoleCode
|
||||
FROM sys_user_role SUR
|
||||
LEFT JOIN sys_role SR ON SUR.SysRoleId = SR.Id
|
||||
GROUP BY SUR.SysUserId
|
||||
) SUR ON SU.Id = SUR.SysUserId
|
||||
WHERE SU.Id=@Id";
|
||||
var user = (await _dapperRepository.QueryAsync<UserOutput>(sql, new { input.Id })).SingleOrDefault();
|
||||
if (user != null)
|
||||
{
|
||||
user.SysEmpInfo = await _sysEmpService.GetEmpInfo(user.Id);
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改用户状态
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("/houseMember/changeStatus")]
|
||||
public async Task ChangeUserStatus(UpdateUserInput input)
|
||||
{
|
||||
await _sysUserService.ChangeUserStatus(input);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 授权用户数据范围
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("/houseMember/grantData")]
|
||||
public async Task GrantUserData(UpdateUserInput input)
|
||||
{
|
||||
await _sysUserService.GrantUserData(input);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户拥有数据
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("/houseMember/ownData")]
|
||||
public async Task<dynamic> GetUserOwnData([FromQuery] QueryUserInput input)
|
||||
{
|
||||
return await _sysUserService.GetUserOwnData(input);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前机构中所创建的默认角色
|
||||
/// 片区中的第一个帐号必定为片区监管员
|
||||
/// </summary>
|
||||
/// <param name="orgId"></param>
|
||||
/// <returns></returns>
|
||||
[NonAction]
|
||||
private async Task<SysRole> GetDefaultRole(string orgId)
|
||||
{
|
||||
var roles = await GetRoleRange();
|
||||
if (roles.Count < 2) throw Oops.Oh("未配置正确的角色");
|
||||
|
||||
var _sysOrgRep = Db.GetRepository<SysOrg>();
|
||||
var org = await _sysOrgRep.DetachedEntities.FirstOrDefaultAsync(p => p.Id == orgId);
|
||||
// 如果当前组织为街道, 则直接返回安全员
|
||||
if (org == null || org.Type <= (int)OrgType.乡镇街道办事处)
|
||||
{
|
||||
return roles.LastOrDefault();
|
||||
}
|
||||
|
||||
var _sysEmpRep = Db.GetRepository<SysEmp>();
|
||||
var _sysUserRoleRep = Db.GetRepository<SysUserRole>();
|
||||
var userIds = await _sysEmpRep.DetachedEntities.Where(p => p.OrgId == orgId).Select(p => p.Id).ToListAsync();
|
||||
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 == Enum.GetName(HouseManagerRole.ZoneManager).ToUnderScoreCase());
|
||||
// 存在片区监管员,返回安全员, 否则返回监管员
|
||||
if (isExistZoneManager)
|
||||
{
|
||||
return roles.LastOrDefault();
|
||||
}
|
||||
|
||||
return roles.FirstOrDefault();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取可创建的角色列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[NonAction]
|
||||
private async Task<List<SysRole>> GetRoleRange()
|
||||
{
|
||||
var codes = (new[] {
|
||||
Enum.GetName(HouseManagerRole.ZoneManager),
|
||||
Enum.GetName(HouseManagerRole.HouseSecurityManager),
|
||||
}).Select(p => p.ToUnderScoreCase());
|
||||
|
||||
var _sysRoleRep = Db.GetRepository<SysRole>();
|
||||
var roles = await _sysRoleRep.DetachedEntities.Where(p => codes.Contains(p.Code)).ToListAsync();
|
||||
|
||||
return roles;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using Ewide.Core.Service;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Application.Service
|
||||
{
|
||||
public interface IHouseMemberService
|
||||
{
|
||||
Task<dynamic> QueryMemberPageList([FromBody] UserInput input);
|
||||
Task AddUser(AddHouseMemberInput input);
|
||||
Task<dynamic> DefaultRole([FromQuery] string orgId);
|
||||
Task DeleteUser(DeleteUserInput input);
|
||||
Task UpdateUser(UpdateUserInput input);
|
||||
Task<dynamic> GetUser([FromQuery] QueryUserInput input);
|
||||
Task ChangeUserStatus(UpdateUserInput input);
|
||||
Task<dynamic> GetUserOwnRole([FromQuery] QueryUserInput input);
|
||||
Task GrantUserData(UpdateUserInput input);
|
||||
Task<dynamic> GetUserOwnData([FromQuery] QueryUserInput input);
|
||||
Task<dynamic> DefaultRoleRange();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
using Ewide.Core;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Application.Service.HouseProjectInfo.Dto
|
||||
{
|
||||
public class HouseProjectInfoInput : InputBase
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Note { get; set; }
|
||||
public int Sort { get; set; }
|
||||
public string AreaCode { get; set; }
|
||||
public int Type { get; set; }
|
||||
}
|
||||
public class AddProjectInput : HouseProjectInfoInput
|
||||
{
|
||||
|
||||
}
|
||||
public class UpdateProjectInput : HouseProjectInfoInput
|
||||
{
|
||||
[Required(ErrorMessage = "项目ID不可为空")]
|
||||
public string Id { get; set; }
|
||||
}
|
||||
|
||||
public class DeleteProjectInput
|
||||
{
|
||||
[Required(ErrorMessage = "项目ID不可为空")]
|
||||
public string Id { get; set; }
|
||||
}
|
||||
|
||||
public class QueryProjectInput : UpdateProjectInput
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public class PageProjectInput: HouseProjectInfoInput
|
||||
{
|
||||
public string pid { get; set; }
|
||||
}
|
||||
|
||||
public class ListHouseProjectInfoInput
|
||||
{
|
||||
[Required(ErrorMessage = "区域编码不可为空")]
|
||||
public string AreaCode { get; set; }
|
||||
[Required(ErrorMessage = "性质不可为空")]
|
||||
public int Type { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Application.Service.HouseProjectInfo.Dto
|
||||
{
|
||||
public class HouseProjectOutput
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Note { get; set; }
|
||||
public int Sort { get; set; }
|
||||
public string AreaCode { get; set; }
|
||||
public string AreaName { get; set; }
|
||||
public int Type { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
using Ewide.Application.Entity;
|
||||
using Ewide.Application.Service.HouseProjectInfo.Dto;
|
||||
using Ewide.Core;
|
||||
using Ewide.Core.Service;
|
||||
using Furion.DatabaseAccessor;
|
||||
using Furion.DatabaseAccessor.Extensions;
|
||||
using Furion.DependencyInjection;
|
||||
using Furion.DynamicApiController;
|
||||
using Furion.FriendlyException;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Application.Service.HouseProjectInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// 项目管理相关服务
|
||||
/// </summary>
|
||||
[ApiDescriptionSettings(Name = "HouseProjectInfo", Order = 170)]
|
||||
public class HouseProjectInfoService : IHouseProjectInfoService, ITransient, IDynamicApiController
|
||||
{
|
||||
private readonly IRepository<BsHouseProjectInfo> _houseProjectInfoRep;
|
||||
|
||||
public HouseProjectInfoService(IRepository<BsHouseProjectInfo> houseProjectInfoRep)
|
||||
{
|
||||
_houseProjectInfoRep = houseProjectInfoRep;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加项目
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("/houseProjectInfo/add")]
|
||||
public async Task AddProject(AddProjectInput input)
|
||||
{
|
||||
await _houseProjectInfoRep.InsertNowAsync(input.Adapt<BsHouseProjectInfo>());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除项目
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("/houseProjectInfo/delete")]
|
||||
public async Task DeleteProject(DeleteProjectInput input)
|
||||
{
|
||||
var project = _houseProjectInfoRep.FirstOrDefault(p => p.Id == input.Id);
|
||||
await project.DeleteNowAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 编辑项目
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("/houseProjectInfo/edit")]
|
||||
public async Task UpdateProject(UpdateProjectInput input)
|
||||
{
|
||||
var project = input.Adapt<BsHouseProjectInfo>();
|
||||
await project.UpdateExcludeAsync(new[] { nameof(BsHouseProjectInfo.AreaCode) }, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通过ID获取项目
|
||||
/// </summary>
|
||||
/// <param name="projectId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("/houseProjectInfo/getById")]
|
||||
public async Task<BsHouseProjectInfo> GetById([Required] string projectId)
|
||||
{
|
||||
return await _houseProjectInfoRep.DetachedEntities.FirstOrDefaultAsync(p => p.Id == projectId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 分页查询
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("/houseProjectInfo/page")]
|
||||
public async Task<dynamic> QueryProjectPageList([FromBody] PageProjectInput input)
|
||||
{
|
||||
var areaCodeRep = Db.GetRepository<SysAreaCode>();
|
||||
var projects = await _houseProjectInfoRep.DetachedEntities
|
||||
.Join(areaCodeRep.DetachedEntities, p => p.AreaCode, a => a.Code, (p, a) => new { p, AreaName = a.Name })
|
||||
.Where(input.Type>0, x => x.p.Type == input.Type)
|
||||
.Where(!string.IsNullOrEmpty(input.Name), x => x.p.Name.Contains(input.Name))
|
||||
.Where(!string.IsNullOrEmpty(input.Note), x => x.p.Note.Contains(input.Note))
|
||||
.Where(!string.IsNullOrEmpty(input.AreaCode), x => x.p.AreaCode == input.AreaCode)
|
||||
.Where(!string.IsNullOrEmpty(input.pid) , x=> x.p.AreaCode.Contains(input.pid))
|
||||
.Select(x => new { x.p.Id, x.p.Name, x.p.Note, x.p.Sort, x.p.AreaCode, x.AreaName, x.p.Type }.Adapt<HouseProjectOutput>()).ToPagedListAsync(input.PageIndex, input.PageSize);
|
||||
return PageDataResult<HouseProjectOutput>.PageResult(projects);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("/houseProjectInfo/detail")]
|
||||
public async Task<dynamic> GetProject([FromQuery] QueryProjectInput input)
|
||||
{
|
||||
var user = await _houseProjectInfoRep.DetachedEntities.FirstOrDefaultAsync(p => p.Id == input.Id);
|
||||
var userDto = user.Adapt<UserOutput>();
|
||||
|
||||
return userDto;
|
||||
}
|
||||
|
||||
[HttpGet("/houseProjectInfo/nextSort")]
|
||||
public async Task<int> GetNextProjectSortByAreaCode([FromQuery] ListHouseProjectInfoInput input)
|
||||
{
|
||||
//var projects = await _houseProjectInfoRep.DetachedEntities
|
||||
// .Where(p => p.AreaCode == input.AreaCode && p.Type == input.Type)
|
||||
// .Select(p => p.Sort)
|
||||
// .DefaultIfEmpty()
|
||||
// .MaxAsync();
|
||||
if (input.Type > 2 || input.Type < 1)
|
||||
{
|
||||
throw Oops.Oh("类型参数异常");
|
||||
}
|
||||
var p = await _houseProjectInfoRep.DetachedEntities
|
||||
.Where(p => p.AreaCode == input.AreaCode && p.Type == input.Type)
|
||||
.MaxAsync(p => (int?)p.Sort);
|
||||
|
||||
return p.GetValueOrDefault(0) + 1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取项目下拉列表
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("houseProjectInfo/list")]
|
||||
public async Task<dynamic> GetProjectList([FromQuery] ListHouseProjectInfoInput input)
|
||||
{
|
||||
return await _houseProjectInfoRep.DetachedEntities
|
||||
.Where(p => p.AreaCode == input.AreaCode && p.Type == input.Type)
|
||||
.OrderBy(p => p.Sort)
|
||||
.ToListAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using Ewide.Application.Entity;
|
||||
using Ewide.Application.Service.HouseProjectInfo.Dto;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Application.Service.HouseProjectInfo
|
||||
{
|
||||
public interface IHouseProjectInfoService
|
||||
{
|
||||
Task AddProject(AddProjectInput input);
|
||||
Task DeleteProject(DeleteProjectInput input);
|
||||
Task UpdateProject(UpdateProjectInput input);
|
||||
Task<BsHouseProjectInfo> GetById([FromRoute] string projectId);
|
||||
Task<dynamic> GetProject([FromQuery] QueryProjectInput input);
|
||||
Task<dynamic> QueryProjectPageList([FromQuery] PageProjectInput input);
|
||||
|
||||
Task<int> GetNextProjectSortByAreaCode([FromQuery] ListHouseProjectInfoInput input);
|
||||
Task<dynamic> GetProjectList([FromQuery] ListHouseProjectInfoInput input);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using Ewide.Core;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Application
|
||||
{
|
||||
public class HouseQueryInput: PageInputBase
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public class HouseQueryDetailInput
|
||||
{
|
||||
[Required(ErrorMessage = "Id不能为空")]
|
||||
public string Id { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Application
|
||||
{
|
||||
public class HouseQueryOutput
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
using Dapper;
|
||||
using Ewide.Core.Extension;
|
||||
using Furion.DatabaseAccessor;
|
||||
using Furion.DependencyInjection;
|
||||
using Furion.DynamicApiController;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Application.Service.HouseSafety.HouseQuery
|
||||
{
|
||||
/// <summary>
|
||||
/// 住宅查询
|
||||
/// </summary>
|
||||
[ApiDescriptionSettings(Name = "HouseQuery", Order = 210)]
|
||||
public class HouseQueryService : IHouseQueryService, IDynamicApiController, ITransient
|
||||
{
|
||||
private readonly IRepository<BsHouseCode> _houseCodeRep;
|
||||
private readonly IRepository<BsHouseInfo> _houseInfoRep;
|
||||
private readonly IRepository<BsHouseTask> _houseTaskRep;
|
||||
private readonly IDapperRepository _dapperRepository;
|
||||
|
||||
public HouseQueryService(IRepository<BsHouseCode> HouseCodeRep, IRepository<BsHouseInfo> HouseInfoRep, IRepository<BsHouseTask> HouseTaskRep, IDapperRepository dapperRepository)
|
||||
{
|
||||
_houseCodeRep = HouseCodeRep;
|
||||
_houseInfoRep = HouseInfoRep;
|
||||
_houseTaskRep = HouseTaskRep;
|
||||
_dapperRepository = dapperRepository;
|
||||
}
|
||||
|
||||
[HttpPost("/houseQuery/page")]
|
||||
public async Task<dynamic> QueryPage([FromBody] HouseQueryInput input)
|
||||
{
|
||||
var sql = @"SELECT
|
||||
HC.ID,
|
||||
HC.HouseCode,
|
||||
AA.Name AreaName,
|
||||
RA.Name RoadName,
|
||||
CA.Name CommName,
|
||||
Proj.AreaCode,
|
||||
Proj.Note,
|
||||
Proj.Name,
|
||||
CONCAT(Proj.Name,'(',Proj.Note,')') FullProjName,
|
||||
HC.Address,
|
||||
IFNULL(HI.BuildingName,'') BuildingName,
|
||||
IFNULL(HI.TotalFloor,0) TotalFloor,
|
||||
IFNULL(HI.TotalArea,0) TotalArea,
|
||||
HI.LandAttribute,
|
||||
IFNULL(HI.HouseGrade,0) HouseGrade,
|
||||
HC.Type,
|
||||
HC.No,
|
||||
HI.State,
|
||||
HI.CompletedDate,
|
||||
HI.CreatedTime
|
||||
FROM bs_house_code HC
|
||||
LEFT JOIN bs_house_info HI ON HI.HouseCodeId = HC.Id
|
||||
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)
|
||||
WHERE 1=1";
|
||||
|
||||
return await _dapperRepository.QueryPageDataDynamic(sql, input, filterFields: new string[] {
|
||||
"HouseCode",
|
||||
"Address",
|
||||
"BuildingName",
|
||||
"State",
|
||||
"AreaCode",
|
||||
"LandAttribute",
|
||||
"HouseGrade",
|
||||
"CompletedDate",
|
||||
"CreatedTime",
|
||||
"TotalArea",
|
||||
"TotalFloor"
|
||||
});
|
||||
}
|
||||
|
||||
[HttpGet("/houseQuery/detail")]
|
||||
public async Task<dynamic> Detail([FromQuery] HouseQueryDetailInput input)
|
||||
{
|
||||
var houseCodeOutputAsync = await _dapperRepository.QueryAsync<HouseCodeOutput>(
|
||||
@"SELECT HC.Id,HC.Address,HC.ProjectId,HC.ZoneId,HC.Type,AA.Name AreaName,RA.Name RoadName,CA.Name CommName,O.Name ZoneName,Proj.Note ProjectNote,CONCAT(Proj.Name,'(',Proj.Note,')') ProjectFullName,HC.HouseCode,HC.Lng,HC.Lat,HC.No FROM bs_house_code HC
|
||||
LEFT JOIN bs_house_projectinfo Proj ON Proj.Id=HC.ProjectId
|
||||
LEFT JOIN sys_org O ON HC.ZoneId = O.Id
|
||||
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)
|
||||
WHERE HC.Id=@Id", new { input.Id }
|
||||
);
|
||||
|
||||
var houseCodeOutput = houseCodeOutputAsync.SingleOrDefault();
|
||||
|
||||
|
||||
var houseInfoOutputForDetailPage = new HouseInfoOutputForDetailPage
|
||||
{
|
||||
HouseCode = houseCodeOutput
|
||||
};
|
||||
|
||||
var houseInfoOutput = (await _houseInfoRep.DetachedEntities.FirstOrDefaultAsync(p => p.HouseCodeId == houseCodeOutput.Id)).Adapt<HouseInfoOutput>();
|
||||
houseInfoOutputForDetailPage.HouseInfo = houseInfoOutput;
|
||||
|
||||
return houseInfoOutputForDetailPage;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Application.Service.HouseSafety.HouseQuery
|
||||
{
|
||||
public interface IHouseQueryService
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Application
|
||||
{
|
||||
public class HouseSelectInput
|
||||
{
|
||||
[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; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Application
|
||||
{
|
||||
public class HouseSelectorOutput
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,225 @@
|
||||
using Dapper;
|
||||
using Ewide.Core;
|
||||
using Ewide.Core.Extension;
|
||||
using Furion.DatabaseAccessor;
|
||||
using Furion.DatabaseAccessor.Extensions;
|
||||
using Furion.DependencyInjection;
|
||||
using Furion.DynamicApiController;
|
||||
using Furion.FriendlyException;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Application.Service
|
||||
{
|
||||
/// <summary>
|
||||
/// 选房相关
|
||||
/// </summary>
|
||||
[ApiDescriptionSettings(Name = "HouseSelector", Order = 180)]
|
||||
public class HouseSelectorService : IHouseSelectorService, IDynamicApiController, ITransient
|
||||
{
|
||||
private readonly IUserManager _userManager;
|
||||
private readonly IDapperRepository _dapperRep;
|
||||
|
||||
private readonly IRepository<BsHouseMemberRelation> _bsHouseMemberRelationRep;
|
||||
private readonly IRepository<BsHouseCode> _bsHouseCodeRep;
|
||||
private readonly IRepository<BsHouseTask> _bsHouseTaskRep;
|
||||
private readonly IRepository<SysUser> _sysUserRep;
|
||||
private readonly IHouseZoneService _houseZoneService;
|
||||
|
||||
private readonly IHouseLogService _houseLogService;
|
||||
|
||||
public HouseSelectorService(
|
||||
IUserManager userManager,
|
||||
IDapperRepository dapperRep,
|
||||
IRepository<BsHouseMemberRelation> bsHouseMemberRelationRep,
|
||||
IRepository<BsHouseCode> bsHouseCodeRep,
|
||||
IRepository<BsHouseTask> bsHouseTaskRep,
|
||||
IRepository<SysUser> sysUserRep,
|
||||
IHouseZoneService houseZoneService,
|
||||
IHouseLogService houseLogService
|
||||
)
|
||||
{
|
||||
_userManager = userManager;
|
||||
|
||||
_dapperRep = dapperRep;
|
||||
_bsHouseMemberRelationRep = bsHouseMemberRelationRep;
|
||||
_bsHouseCodeRep = bsHouseCodeRep;
|
||||
_bsHouseTaskRep = bsHouseTaskRep;
|
||||
_sysUserRep = sysUserRep;
|
||||
_houseZoneService = houseZoneService;
|
||||
|
||||
_houseLogService = houseLogService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取人员允许绑定的房屋编码列表
|
||||
/// </summary>
|
||||
/// <param name="input"></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`, IFNULL(CONCAT('(',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 HM.Id IS NULL";
|
||||
return await _dapperRep.QueryPageDataDynamic(sql, input, param: new
|
||||
{
|
||||
input.UserId
|
||||
}, filterFields: new[] {
|
||||
nameof(BsHouseCode.Address) ,
|
||||
nameof(BsHouseCode.CreatedTime)
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取人员已经绑定的房屋编码列表
|
||||
/// </summary>
|
||||
/// <param name="input"></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`, IFNULL(CONCAT('(',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";
|
||||
return await _dapperRep.QueryPageDataDynamic(sql, input, param: new
|
||||
{
|
||||
input.UserId
|
||||
}, filterFields: new[] {
|
||||
nameof(BsHouseCode.Address) ,
|
||||
nameof(BsHouseCode.CreatedTime)
|
||||
});
|
||||
}
|
||||
|
||||
/// <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 selectedUser = await _sysUserRep.DetachedEntities.FirstOrDefaultAsync(p => p.Id.Equals(input.UserId));
|
||||
|
||||
// 从用户所在片区中过滤房屋
|
||||
var zoneId = await _houseZoneService.GetZoneByUser(selectedUser.Id);
|
||||
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(async p =>
|
||||
{
|
||||
var originalTask = _bsHouseTaskRep.DetachedEntities.FirstOrDefault(t => t.HouseCodeId == p && t.TaskType == 0 && t.IsEnabled);
|
||||
if (originalTask == null)
|
||||
{
|
||||
new BsHouseTask
|
||||
{
|
||||
Id = System.Guid.NewGuid().ToString(),
|
||||
HouseCodeId = p,
|
||||
UserID = selectedUser.Id,
|
||||
EndTime = System.DateTime.Now.AddMonths(1),
|
||||
Status = 0,
|
||||
TaskType = 0
|
||||
}.Insert();
|
||||
|
||||
await _houseLogService.Done(p);
|
||||
await _houseLogService.Add(p, selectedUser, HouseLogType.CreateInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
var sort = await _houseLogService.AddThenDone(p, _userManager.User, HouseLogType.SelectMember);
|
||||
if (originalTask.Status != 6)//建档未完成,生成新建档任务分配给新的人员;原建档任务数据保留,有效性设置为false,取消巡查关系
|
||||
{
|
||||
var newTask = originalTask.Adapt<BsHouseTask>();
|
||||
newTask.Id = System.Guid.NewGuid().ToString();
|
||||
newTask.UserID = input.UserId;
|
||||
newTask.EndTime = System.DateTime.Now.AddMonths(1);
|
||||
newTask.Insert();
|
||||
|
||||
originalTask.IsEnabled = false;
|
||||
originalTask.Update();
|
||||
|
||||
sort = await _houseLogService.Add(p, selectedUser, HouseLogType.CreateInfo, sort: sort);
|
||||
}//已建档完成,不再分配建档任务,仅更换巡查关系
|
||||
else
|
||||
{
|
||||
var originalRelation = _bsHouseMemberRelationRep.DetachedEntities.FirstOrDefault(r => r.HouseCodeId == p && r.SysUserId == originalTask.UserID);
|
||||
originalRelation.Delete();
|
||||
}
|
||||
}
|
||||
|
||||
new BsHouseMemberRelation
|
||||
{
|
||||
SysUserId = selectedUser.Id,
|
||||
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()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
using Ewide.Core;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Application
|
||||
{
|
||||
public class HouseTaskInput
|
||||
{
|
||||
[Required(ErrorMessage = "巡查日期不能为空")]
|
||||
public DateTime PatrolDate { get; set; }
|
||||
|
||||
[Required(ErrorMessage = "巡查人员/单位不能为空")]
|
||||
public string PatrolUser { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 沉降倾斜
|
||||
/// </summary>
|
||||
public string SettlementTilt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 沉降倾斜附件
|
||||
/// </summary>
|
||||
public string SettlementTiltFiles { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 其他情况
|
||||
/// </summary>
|
||||
public string OtherInfo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 其他情况附件
|
||||
/// </summary>
|
||||
public string OtherInfoFiles { get; set; }
|
||||
|
||||
//[Required(ErrorMessage = "巡查初始等级不能为空")]
|
||||
public int InitGrade { get; set; }
|
||||
//[Required(ErrorMessage = "巡查损坏等级不能为空")]
|
||||
public int DamageGrade { get; set; }
|
||||
//[Required(ErrorMessage = "巡查综合等级不能为空")]
|
||||
public int ComprehensiveGrade { get; set; }
|
||||
#region 调查情况investigation
|
||||
/// <summary>
|
||||
/// 房屋场地
|
||||
/// </summary>
|
||||
public string HouseSite { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 相邻施工
|
||||
/// </summary>
|
||||
public string AdjacentConstruction { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 化学侵蚀
|
||||
/// </summary>
|
||||
public string ChemicalErosion { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 结构拆改
|
||||
/// </summary>
|
||||
public int? StructuralDismantling { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 加层改造
|
||||
/// </summary>
|
||||
public int? AddingLayer { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 修缮加固
|
||||
/// </summary>
|
||||
public string RepairAndReinforce { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 历史灾害
|
||||
/// </summary>
|
||||
public string HistoricalCalamity { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 使用功能变更
|
||||
/// </summary>
|
||||
public string FunctionalChange { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 其他调查内容
|
||||
/// </summary>
|
||||
public string OtherContents { get; set; }
|
||||
#endregion
|
||||
/// <summary>
|
||||
/// 主要安全隐患综述
|
||||
/// </summary>
|
||||
public string MainSafety { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 处理意见
|
||||
/// </summary>
|
||||
public int? HandlingOpinion { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 处理意见备注
|
||||
/// </summary>
|
||||
public string HandlingOpinionRemark { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 整改情况
|
||||
/// </summary>
|
||||
public int? RectifyAndReform { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 整改情况备注
|
||||
/// </summary>
|
||||
public string RectifyAndReformRemark { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 巡查结果:1正常,-1异常
|
||||
/// </summary>
|
||||
//[Required(ErrorMessage = "巡查结果不能为空")]
|
||||
public int PatrolResult { get; set; }
|
||||
|
||||
public string PatrolResultRemark { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 上报街道
|
||||
/// </summary>
|
||||
public int? ReportRoad { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 上报街道时间
|
||||
/// </summary>
|
||||
public DateTime? ReportRoadTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 上报区住建
|
||||
/// </summary>
|
||||
public int? ReportArea { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 上报区住建时间
|
||||
/// </summary>
|
||||
public DateTime? ReportAreaTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 上报备注
|
||||
/// </summary>
|
||||
public string ReportRemark { get; set; }
|
||||
}
|
||||
|
||||
public class AddHouseTaskInput : HouseTaskInput
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public class EditHouseTaskInput : HouseTaskInput
|
||||
{
|
||||
[Required(ErrorMessage = "任务Id不能为空")]
|
||||
public string Id { get; set; }
|
||||
}
|
||||
|
||||
public class SubmitHouseTaskInput
|
||||
{
|
||||
[Required(ErrorMessage = "任务Id不能为空")]
|
||||
public string TaskId { get; set; }
|
||||
}
|
||||
|
||||
public class QueryHouseTaskInput : PageInputBase
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Application
|
||||
{
|
||||
public class HouseTaskOutput
|
||||
{
|
||||
public DateTime? PatrolDate { get; set; }
|
||||
public string PatrolUser { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 沉降倾斜
|
||||
/// </summary>
|
||||
public string SettlementTilt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 沉降倾斜附件
|
||||
/// </summary>
|
||||
public string SettlementTiltFiles { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 其他情况
|
||||
/// </summary>
|
||||
public string OtherInfo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 其他情况附件
|
||||
/// </summary>
|
||||
public string OtherInfoFiles { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 初始等级
|
||||
/// </summary>
|
||||
public int? InitGrade { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 损坏等级
|
||||
/// </summary>
|
||||
public int? DamageGrade { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 综合等级
|
||||
/// </summary>
|
||||
public int? ComprehensiveGrade { get; set; }
|
||||
|
||||
#region 调查情况investigation
|
||||
/// <summary>
|
||||
/// 房屋场地
|
||||
/// </summary>
|
||||
public string HouseSite { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 相邻施工
|
||||
/// </summary>
|
||||
public string AdjacentConstruction { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 化学侵蚀
|
||||
/// </summary>
|
||||
public string ChemicalErosion { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 结构拆改
|
||||
/// </summary>
|
||||
public int? StructuralDismantling { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 加层改造
|
||||
/// </summary>
|
||||
public int? AddingLayer { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 修缮加固
|
||||
/// </summary>
|
||||
public string RepairAndReinforce { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 历史灾害
|
||||
/// </summary>
|
||||
public string HistoricalCalamity { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 使用功能变更
|
||||
/// </summary>
|
||||
public string FunctionalChange { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 其他调查内容
|
||||
/// </summary>
|
||||
public string OtherContents { get; set; }
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 主要安全隐患综述
|
||||
/// </summary>
|
||||
public string MainSafety { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 处理意见
|
||||
/// </summary>
|
||||
public int? HandlingOpinion { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 处理意见备注
|
||||
/// </summary>
|
||||
public string HandlingOpinionRemark { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 整改情况
|
||||
/// </summary>
|
||||
public int? RectifyAndReform { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 整改情况备注
|
||||
/// </summary>
|
||||
public string RectifyAndReformRemark { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 巡查结果:1正常,-1异常
|
||||
/// </summary>
|
||||
public int? PatrolResult { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 巡查异常描述
|
||||
/// </summary>
|
||||
public string PatrolResultRemark { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 上报街道
|
||||
/// </summary>
|
||||
public int? ReportRoad { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 上报街道时间
|
||||
/// </summary>
|
||||
public DateTime? ReportRoadTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 上报区住建
|
||||
/// </summary>
|
||||
public int? ReportArea { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 上报区住建时间
|
||||
/// </summary>
|
||||
public DateTime? ReportAreaTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 上报备注
|
||||
/// </summary>
|
||||
public string ReportRemark { get; set; }
|
||||
|
||||
public int Status { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 提交时间
|
||||
/// </summary>
|
||||
public DateTime? SubmitTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 最后提交时间
|
||||
/// </summary>
|
||||
public DateTime? LastSubmitTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否有效
|
||||
/// </summary>
|
||||
public bool IsEnabled { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
using Dapper;
|
||||
using Ewide.Core;
|
||||
using Ewide.Core.Extension;
|
||||
using Furion.DatabaseAccessor;
|
||||
using Furion.DatabaseAccessor.Extensions;
|
||||
using Furion.DependencyInjection;
|
||||
using Furion.DynamicApiController;
|
||||
using Furion.FriendlyException;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Application.Service
|
||||
{
|
||||
/// <summary>
|
||||
/// 房屋任务(巡查任务/建档任务)
|
||||
/// </summary>
|
||||
[ApiDescriptionSettings(Name = "HouseTask", Order = 190)]
|
||||
public class HouseTaskService : IHouseTaskService, IDynamicApiController, ITransient
|
||||
{
|
||||
private readonly IRepository<BsHouseTask> _houseTaskRep;
|
||||
private readonly IRepository<BsHouseInfo> _houseInfoRep;
|
||||
private readonly IDapperRepository _dapperRepository;
|
||||
private readonly IUserManager _userManager;
|
||||
|
||||
private readonly IHouseLogService _houseLogService;
|
||||
|
||||
public HouseTaskService(IRepository<BsHouseTask> HouseTaskRep, IRepository<BsHouseInfo> HouseInfoRep, IDapperRepository dapperRepository, IUserManager userManager, IHouseLogService houseLogService)
|
||||
{
|
||||
_houseTaskRep = HouseTaskRep;
|
||||
_houseInfoRep = HouseInfoRep;
|
||||
_dapperRepository = dapperRepository;
|
||||
_userManager = userManager;
|
||||
|
||||
_houseLogService = houseLogService;
|
||||
}
|
||||
|
||||
[HttpPost("/houseTask/page")]
|
||||
public async Task<dynamic> QueryPage([FromBody] QueryHouseTaskInput input)
|
||||
{
|
||||
var sql = @"SELECT T.Id,AA.Name AreaName,RA.Name RoadName,CA.Name CommName,Proj.AreaCode,Proj.Note,Proj.Name,CONCAT(Proj.`Name`, IFNULL(CONCAT('(',Proj.Note,')'), '')) FullProjName,HC.HouseCode,HC.Address,T.EndTime,HC.Type,HC.Industry,HC.No,T.Status,IFNULL(HI.State,0) State FROM `bs_house_task` T
|
||||
LEFT JOIN bs_house_code HC ON T.HouseCodeId = HC.Id
|
||||
LEFT JOIN bs_house_info HI ON HI.HouseCodeId = T.HouseCodeId
|
||||
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)
|
||||
WHERE T.IsEnabled = 1 {0}";
|
||||
var user = await _userManager.CheckUserAsync();
|
||||
if (user == null) throw Oops.Oh("登录信息丢失");
|
||||
|
||||
var userRoles = await _userManager.GetUserRoleList();
|
||||
var userOrg = await _userManager.GetUserOrgInfo();
|
||||
var param = new DynamicParameters();
|
||||
if (userRoles.Where(r => r.Code == Enum.GetName(HouseManagerRole.HouseSecurityManager).ToUnderScoreCase()).Any())
|
||||
{
|
||||
sql = String.Format(sql, " AND T.UserID=@UserID ");
|
||||
param.Add("UserID", user.Id);
|
||||
}
|
||||
|
||||
if (userRoles.Where(r => r.Code == Enum.GetName(HouseManagerRole.ZoneManager).ToUnderScoreCase()).Any())
|
||||
{
|
||||
sql = String.Format(sql, " AND (T.Status=3 OR T.Status=6) AND HC.ZoneId = @ZoneId ");
|
||||
param.Add("ZoneId", userOrg.Id);
|
||||
}
|
||||
|
||||
return await _dapperRepository.QueryPageDataDynamic(sql, input, param, filterFields: new string[] { "Type", "Address", "HouseCode", "Status","State" });
|
||||
}
|
||||
|
||||
[HttpPost("/houseTask/submit")]
|
||||
[UnitOfWork]
|
||||
[AllowAnonymous]
|
||||
public async Task Submit([FromBody] SubmitHouseTaskInput input)
|
||||
{
|
||||
//获取任务实体
|
||||
var houseTask = await _houseTaskRep.DetachedEntities.FirstOrDefaultAsync(t => t.Id == input.TaskId);
|
||||
if (houseTask == null) throw Oops.Oh("任务不存在");
|
||||
houseTask.Status = 2;
|
||||
houseTask.LastSubmitTime = DateTime.Now;
|
||||
if (!houseTask.SubmitTime.HasValue) houseTask.SubmitTime = houseTask.LastSubmitTime;
|
||||
await houseTask.UpdateExcludeAsync(new string[] { nameof(BsHouseTask.TaskType) }, ignoreNullValues: true);
|
||||
|
||||
if(houseTask.TaskType == 0)
|
||||
{
|
||||
var houseInfo = await _houseInfoRep.DetachedEntities.FirstOrDefaultAsync(h => h.HouseCodeId == houseTask.HouseCodeId);
|
||||
if (houseInfo == null) throw Oops.Oh("提交审核失败:请先保存后再提交");
|
||||
|
||||
houseInfo.State = 5;
|
||||
await houseInfo.UpdateExcludeAsync(new[] { nameof(BsHouseInfo.HouseGrade) }, true);
|
||||
}
|
||||
|
||||
// 提交时流转日志
|
||||
await _houseLogService.Done(houseTask.HouseCodeId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Application.Service
|
||||
{
|
||||
public interface IHouseTaskService
|
||||
{
|
||||
Task<dynamic> QueryPage(QueryHouseTaskInput input);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Application
|
||||
{
|
||||
public class HouseTaskCheckRecordInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 任务Id
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "任务参数有误")]
|
||||
public string TaskId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 通过3;退回-1
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "审核结果不能为空")]
|
||||
public int PassOrBack { get; set; }
|
||||
|
||||
public DataStatus PassOrBackDataStatus
|
||||
{
|
||||
get
|
||||
{
|
||||
return PassOrBack switch
|
||||
{
|
||||
-1 => DataStatus.Back,
|
||||
1 => DataStatus.TempSaved,
|
||||
2 => DataStatus.Saved,
|
||||
3 => DataStatus.Submited,
|
||||
6 => DataStatus.Passed,
|
||||
_ => DataStatus.Init,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 审核内容
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "审核内容不能为空")]
|
||||
public string Content { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Application.Service.HouseSafety.HouseTaskCheckRecord.Dto
|
||||
{
|
||||
public class HouseTaskCheckRecordOutput
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
using Ewide.Core.Service;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Application
|
||||
{
|
||||
public class HouseZoneInput
|
||||
{
|
||||
[Required(ErrorMessage = "区域编码不可为空")]
|
||||
[MinLength(9, ErrorMessage = "区域编码长度必须为9位及以上")]
|
||||
public string AreaCode { get; set; }
|
||||
}
|
||||
|
||||
public class AddHouseZoneInput : OrgInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 所属街道
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "所属街道不能为空")]
|
||||
public override string Pid { get; set; }
|
||||
/// <summary>
|
||||
/// 名称
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "片区名称不能为空")]
|
||||
public override string Name { get; set; }
|
||||
|
||||
}
|
||||
|
||||
public class UpdateHouseZoneInput : AddHouseZoneInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 机构Id
|
||||
/// </summary>
|
||||
[Required(ErrorMessage = "片区Id不能为空")]
|
||||
public string Id { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Application
|
||||
{
|
||||
class HouseZoneOutput
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
using Ewide.Core;
|
||||
using Ewide.Core.Extension;
|
||||
using Ewide.Core.Service;
|
||||
using Furion.DatabaseAccessor;
|
||||
using Furion.DatabaseAccessor.Extensions;
|
||||
using Furion.DependencyInjection;
|
||||
using Furion.DynamicApiController;
|
||||
using Furion.FriendlyException;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Application.Service
|
||||
{
|
||||
/// <summary>
|
||||
/// 片区相关
|
||||
/// </summary>
|
||||
[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(
|
||||
IUserManager userManager,
|
||||
IRepository<SysOrg> sysOrgRep,
|
||||
IRepository<SysEmp> sysEmpRep,
|
||||
ISysOrgService sysOrgService
|
||||
)
|
||||
{
|
||||
_userManager = userManager;
|
||||
_sysOrgRep = sysOrgRep;
|
||||
_sysEmpRep = sysEmpRep;
|
||||
_sysOrgService = sysOrgService;
|
||||
}
|
||||
|
||||
/// <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 road = await _sysOrgRep.DetachedEntities.FirstOrDefaultAsync(p => p.AreaCode == areaCode);
|
||||
if (road == null) throw Oops.Oh("未在组织机构中配置街道");
|
||||
return await _sysOrgRep.DetachedEntities
|
||||
.Where(p => p.Pid == road.Id)
|
||||
.Where(p => p.Type == (int)OrgType.片区)
|
||||
.OrderBy(p => p.Sort)
|
||||
.Select(p => new
|
||||
{
|
||||
p.Id,
|
||||
p.Name
|
||||
})
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
[HttpGet("/houseZone/getById")]
|
||||
public async Task<dynamic> GetById([Required] string zoneId)
|
||||
{
|
||||
return await _sysOrgRep.DetachedEntities.FirstOrDefaultAsync(p => p.Id == zoneId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 分页查询片区
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("/houseZone/page")]
|
||||
public async Task<dynamic> QueryZonePageList([FromBody] PageOrgInput input)
|
||||
{
|
||||
var dataScopeList = _sysOrgService.GetDataScopeList(await _userManager.GetUserAllDataScopeList());
|
||||
|
||||
var name = !string.IsNullOrEmpty(input.Name?.Trim());
|
||||
var id = !string.IsNullOrEmpty(input.Id?.Trim());
|
||||
var pId = !string.IsNullOrEmpty(input.Pid?.Trim());
|
||||
var orgs = await _sysOrgRep.DetachedEntities
|
||||
.Where((name, u => EF.Functions.Like(u.Name, $"%{input.Name.Trim()}%")), // 根据机构名称模糊查询
|
||||
(id, u => u.Id == input.Id.Trim()), // 根据机构id查询
|
||||
(pId, u => EF.Functions.Like(u.Pids, $"%[{input.Pid.Trim()}]%")
|
||||
|| u.Id == input.Pid.Trim())) // 根据父机构id查询
|
||||
.Where(dataScopeList.Count > 0, u => dataScopeList.Contains(u.Id)) // 非管理员范围限制
|
||||
.Where(u => u.Status != CommonStatus.DELETED)
|
||||
.Where(u => u.Type == (int)OrgType.片区)
|
||||
.OrderBy(u => u.Sort)
|
||||
.ToPageData<SysOrg, OrgOutput>(input);
|
||||
return PageDataResult<OrgOutput>.PageResult(orgs);
|
||||
}
|
||||
|
||||
/// <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;
|
||||
}
|
||||
|
||||
[HttpGet("/houseZone/autoIncrement")]
|
||||
public async Task<dynamic> AutoIncrement([FromQuery] string roadId)
|
||||
{
|
||||
var road = await _sysOrgRep.DetachedEntities.FirstOrDefaultAsync(p => p.Id == roadId && p.Type == 3);
|
||||
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(AddHouseZoneInput 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.Id == input.Pid);
|
||||
if (!road.Pids.Contains(org.Id)) throw Oops.Oh("当前用户组织机构错误");
|
||||
|
||||
input.AreaCode = road.AreaCode;
|
||||
input.Code = road.Code + (await AutoIncrement(road)).ToString().PadLeft(3, '0');
|
||||
}
|
||||
else if (roles.Any(p => p.Code == roadManager))
|
||||
{
|
||||
input.AreaCode = org.AreaCode;
|
||||
|
||||
input.Code = org.Code + (await AutoIncrement(org)).ToString().PadLeft(3, '0');
|
||||
}
|
||||
|
||||
input.Type = (int)OrgType.片区;
|
||||
|
||||
AddOrgInput addOrgInput = input.Adapt<AddOrgInput>();
|
||||
await _sysOrgService.AddOrg(addOrgInput);
|
||||
}
|
||||
|
||||
[HttpPost("/houseZone/edit")]
|
||||
public async Task EditZone(UpdateHouseZoneInput input)
|
||||
{
|
||||
var zone = await _sysOrgRep.DetachedEntities.FirstOrDefaultAsync(z => z.Id == input.Id);
|
||||
if(zone == null) throw Oops.Oh("修改失败:数据有误,刷新列表后再尝试修改");
|
||||
zone.Remark = input.Remark;
|
||||
await zone.UpdateIncludeAsync(new[] { nameof(SysOrg.Remark) }, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Application.Service
|
||||
{
|
||||
public interface IHouseZoneService
|
||||
{
|
||||
Task<dynamic> GetHouseZoneList([FromQuery] HouseZoneInput input);
|
||||
Task<string> GetZoneByUser([FromQuery] string userId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
using Ewide.Core;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Application
|
||||
{
|
||||
public class InspectionOrgKeyInput
|
||||
{
|
||||
public virtual string Id { get; set; }
|
||||
}
|
||||
|
||||
public class InspectionOrgKeyRequiredInput : InspectionOrgKeyInput
|
||||
{
|
||||
[Required]
|
||||
public override string Id { get; set; }
|
||||
}
|
||||
|
||||
public class InspectionOrgPageInput : PageInputBase
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public class InspectionOrgRegisterInput
|
||||
{
|
||||
[MaxLength(100)]
|
||||
[Required]
|
||||
public string Name { get; set; }
|
||||
|
||||
[MaxLength(50)]
|
||||
[Required]
|
||||
public string CreditCode { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Address { get; set; }
|
||||
|
||||
[MaxLength(50)]
|
||||
[Required]
|
||||
public string Contacts { get; set; }
|
||||
|
||||
[MaxLength(50)]
|
||||
[Required]
|
||||
public string ContactsPhone { get; set; }
|
||||
|
||||
[MaxLength(50)]
|
||||
[Required]
|
||||
public string LegalPerson { get; set; }
|
||||
|
||||
[MaxLength(50)]
|
||||
public string OrgTelephone { get; set; }
|
||||
|
||||
[Required]
|
||||
public string ApplicationFormFiles { get; set; }
|
||||
|
||||
[Required]
|
||||
public string OrgBusinessLicenseFiles { get; set; }
|
||||
|
||||
[Required]
|
||||
public string InspectionQualificationCertificateFiles { get; set; }
|
||||
|
||||
[Required]
|
||||
public string OfficeInformationFiles { get; set; }
|
||||
|
||||
[Required]
|
||||
public string EmployeeCertificateFiles { get; set; }
|
||||
|
||||
[Required]
|
||||
public string CalibrationCertificateFiles { get; set; }
|
||||
|
||||
public string OtherFiles { get; set; }
|
||||
}
|
||||
|
||||
public class InspectionOrgReviewNotApprovedInput : InspectionOrgKeyRequiredInput
|
||||
{
|
||||
[Required]
|
||||
public string Remark { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Application
|
||||
{
|
||||
public class InspectionOrgDetailOutput
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string Code { get; set; }
|
||||
public InspectionOrgStatus Status { get; set; }
|
||||
public InspectionOrgUpdateStatus UpdateStatus { get; set; }
|
||||
public string Remark { get; set; }
|
||||
public DateTime? CreatedTime { get; set; }
|
||||
public DateTime? UpdatedTime { get; set; }
|
||||
public InspectionOrgRegisterInput Record { get; set; }
|
||||
public InspectionOrgRegisterInput UpdateRecord { get; set; }
|
||||
}
|
||||
|
||||
public class InspectionRegisterStatusOutput
|
||||
{
|
||||
public DateTime BeginDate { get; set; }
|
||||
public DateTime EndDate { get; set; }
|
||||
public InspectionOrgDetailOutput InspectionOrg { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Application.Service
|
||||
{
|
||||
public interface IInspectionOrgService
|
||||
{
|
||||
public Task<string> NewCode();
|
||||
public Task<InspectionRegisterStatusOutput> RegisterStatus();
|
||||
public Task Register(InspectionOrgRegisterInput input);
|
||||
public Task Update(InspectionOrgRegisterInput input);
|
||||
public Task<InspectionOrgDetailOutput> Detail(InspectionOrgKeyInput input);
|
||||
public Task<dynamic> ReviewPage(InspectionOrgPageInput input);
|
||||
public Task<dynamic> ReviewUpdatePage(InspectionOrgPageInput input);
|
||||
public Task ReviewApproved(InspectionOrgKeyRequiredInput input);
|
||||
public Task ReviewNotApproved(InspectionOrgReviewNotApprovedInput input);
|
||||
public Task<dynamic> History(InspectionOrgKeyRequiredInput input);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,410 @@
|
||||
using Dapper;
|
||||
using Ewide.Core;
|
||||
using Ewide.Core.Extension;
|
||||
using Furion.DatabaseAccessor;
|
||||
using Furion.DatabaseAccessor.Extensions;
|
||||
using Furion.DependencyInjection;
|
||||
using Furion.DynamicApiController;
|
||||
using Furion.FriendlyException;
|
||||
using Furion.JsonSerialization;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Application.Service
|
||||
{
|
||||
/// <summary>
|
||||
/// 鉴定机构相关
|
||||
/// </summary>
|
||||
[ApiDescriptionSettings(Name = "InspectionOrg")]
|
||||
public class InspectionOrgService : IInspectionOrgService, IDynamicApiController, ITransient
|
||||
{
|
||||
private readonly IJsonSerializerProvider _jsonSerializer;
|
||||
private readonly IDapperRepository _dapperRep;
|
||||
|
||||
private readonly IUserManager _userManager;
|
||||
|
||||
private readonly IRepository<BsInspectionOrg> _orgRep;
|
||||
private readonly IRepository<BsInspectionOrgUpdate> _orgUpdateRep;
|
||||
private readonly IRepository<BsInspectionMemberRelation> _relationRep;
|
||||
private readonly IRepository<BsInspectionOrgSetting> _settingRep;
|
||||
|
||||
public InspectionOrgService(
|
||||
IJsonSerializerProvider jsonSerializer,
|
||||
IDapperRepository dapperRep,
|
||||
IUserManager userManager,
|
||||
IRepository<BsInspectionOrg> orgRep,
|
||||
IRepository<BsInspectionOrgUpdate> orgUpdateRep,
|
||||
IRepository<BsInspectionMemberRelation> relationRep,
|
||||
IRepository<BsInspectionOrgSetting> settingRep
|
||||
)
|
||||
{
|
||||
_jsonSerializer = jsonSerializer;
|
||||
_dapperRep = dapperRep;
|
||||
|
||||
_userManager = userManager;
|
||||
|
||||
_orgRep = orgRep;
|
||||
_orgUpdateRep = orgUpdateRep;
|
||||
_relationRep = relationRep;
|
||||
_settingRep = settingRep;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取可登记的时间范围
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private async Task<BsInspectionOrgSetting_DateRange> DateRange()
|
||||
{
|
||||
// 验证当前时间是否已在可申报时间范围内
|
||||
var setting = await _settingRep.DetachedEntities.FirstOrDefaultAsync(p => p.Type == InspectionOrgSettingType.DateRange);
|
||||
var dateRange = _jsonSerializer.Deserialize<BsInspectionOrgSetting_DateRange>(setting.Setting);
|
||||
return dateRange;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前用户所在机构
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private async Task<string> RelationOrgId()
|
||||
{
|
||||
var relation = await _relationRep.DetachedEntities.FirstOrDefaultAsync(p => p.SysUserId.Equals(_userManager.UserId));
|
||||
if (relation == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return relation.InspectionOrgId;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取最新备案编号
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("/inspectionOrg/newCode")]
|
||||
public async Task<string> NewCode()
|
||||
{
|
||||
var nowYear = DateTime.Now.Year;
|
||||
var code = await _orgRep.DetachedEntities.MaxAsync(p => p.Code);
|
||||
if (String.IsNullOrEmpty(code))
|
||||
{
|
||||
code = nowYear + "001";
|
||||
}
|
||||
else
|
||||
{
|
||||
var year = int.Parse(code.Substring(0, 4));
|
||||
var no = int.Parse(code.Substring(4, 3));
|
||||
if (year < nowYear)
|
||||
{
|
||||
code = nowYear + "001";
|
||||
}
|
||||
else
|
||||
{
|
||||
code = year + (no + 1).ToString().PadLeft(3, '0');
|
||||
}
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前用户所在鉴定机构信息及登记时间范围
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet("/inspectionOrg/registerStatus")]
|
||||
public async Task<InspectionRegisterStatusOutput> RegisterStatus()
|
||||
{
|
||||
var orgId = await RelationOrgId();
|
||||
var dateRange = await DateRange();
|
||||
var output = dateRange.Adapt<InspectionRegisterStatusOutput>();
|
||||
if (String.IsNullOrEmpty(orgId))
|
||||
{
|
||||
return output;
|
||||
}
|
||||
|
||||
var org = await _orgRep.DetachedEntities.FirstOrDefaultAsync(p => p.Id.Equals(orgId));
|
||||
var orgUpdate = await _orgUpdateRep.DetachedEntities.Where(p => p.OrgId.Equals(orgId)).OrderByDescending(p => p.CreatedTime).FirstOrDefaultAsync();
|
||||
output.InspectionOrg = org.Adapt<InspectionOrgDetailOutput>();
|
||||
output.InspectionOrg.UpdateStatus = orgUpdate.Status;
|
||||
output.InspectionOrg.Remark = orgUpdate.Remark;
|
||||
return output;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 鉴定机构登记
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("/inspectionOrg/register")]
|
||||
[UnitOfWork]
|
||||
public async Task Register([FromBody] InspectionOrgRegisterInput input)
|
||||
{
|
||||
// 验证当前时间是否已在可申报时间范围内
|
||||
var dateRange = await DateRange();
|
||||
var now = DateTime.Now;
|
||||
if (!(now >= dateRange.BeginDate && now < dateRange.EndDate.AddDays(1)))
|
||||
throw Oops.Oh("当前时间段无法登记鉴定机构");
|
||||
|
||||
// 登记时主表数据应为空, 只向记录数据中插入当前填表的内容
|
||||
var updateData = input.Adapt<BsInspectionOrgUpdate>();
|
||||
var orgId = await RelationOrgId();
|
||||
if (String.IsNullOrEmpty(orgId))
|
||||
{
|
||||
orgId = Guid.NewGuid().ToString().ToLower();
|
||||
var code = await NewCode();
|
||||
// 登记主表
|
||||
var data = new BsInspectionOrg
|
||||
{
|
||||
Id = orgId,
|
||||
Code = code,
|
||||
};
|
||||
await data.InsertAsync();
|
||||
|
||||
// 用户关系表
|
||||
await new BsInspectionMemberRelation
|
||||
{
|
||||
SysUserId = _userManager.UserId,
|
||||
InspectionOrgId = orgId
|
||||
}.InsertAsync();
|
||||
}
|
||||
// 登记记录表
|
||||
updateData.OrgId = orgId;
|
||||
updateData.Type = InspectionOrgUpdateType.Register;
|
||||
updateData.Status = InspectionOrgUpdateStatus.Reviewing;
|
||||
await updateData.InsertAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 鉴定机构申请修改
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("/inspectionOrg/update")]
|
||||
public async Task Update([FromBody] InspectionOrgRegisterInput input)
|
||||
{
|
||||
var orgId = await RelationOrgId();
|
||||
var org = await _orgRep.DetachedEntities.FirstOrDefaultAsync(p => p.Id.Equals(orgId));
|
||||
var updateData = input.Adapt<BsInspectionOrgUpdate>();
|
||||
// 与之前的值进行对比, 没有变更则不提交
|
||||
var updated = false;
|
||||
var TSource = org.GetType();
|
||||
var TSourceProperties = TSource.GetProperties();
|
||||
var TTarget = updateData.GetType();
|
||||
var TTargetProperties = TTarget.GetProperties();
|
||||
var compareFields = new[] {
|
||||
nameof(BsInspectionOrg.Name),
|
||||
nameof(BsInspectionOrg.CreditCode),
|
||||
nameof(BsInspectionOrg.Address),
|
||||
nameof(BsInspectionOrg.Contacts),
|
||||
nameof(BsInspectionOrg.ContactsPhone),
|
||||
nameof(BsInspectionOrg.LegalPerson),
|
||||
nameof(BsInspectionOrg.OrgTelephone),
|
||||
nameof(BsInspectionOrg.ApplicationFormFiles),
|
||||
nameof(BsInspectionOrg.OrgBusinessLicenseFiles),
|
||||
nameof(BsInspectionOrg.InspectionQualificationCertificateFiles),
|
||||
nameof(BsInspectionOrg.OfficeInformationFiles),
|
||||
nameof(BsInspectionOrg.EmployeeCertificateFiles),
|
||||
nameof(BsInspectionOrg.CalibrationCertificateFiles),
|
||||
nameof(BsInspectionOrg.OtherFiles)
|
||||
};
|
||||
|
||||
foreach (var fields in compareFields)
|
||||
{
|
||||
var PSource = TSourceProperties.FirstOrDefault(p => p.Name.Equals(fields));
|
||||
var VSource = PSource.GetValue(org);
|
||||
var PTarget = TTargetProperties.FirstOrDefault(p => p.Name.Equals(fields));
|
||||
var VTarget = PTarget.GetValue(updateData);
|
||||
if (
|
||||
(VSource == null && VTarget != null)
|
||||
||
|
||||
(VSource != null && !VSource.Equals(VTarget))
|
||||
)
|
||||
{
|
||||
updated = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!updated)
|
||||
{
|
||||
throw Oops.Oh("当前信息未修改");
|
||||
}
|
||||
|
||||
// 登记记录表
|
||||
updateData.OrgId = orgId;
|
||||
updateData.Type = InspectionOrgUpdateType.Update;
|
||||
updateData.Status = InspectionOrgUpdateStatus.Reviewing;
|
||||
await updateData.InsertAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 鉴定机构详情
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("/inspectionOrg/detail")]
|
||||
public async Task<InspectionOrgDetailOutput> Detail([FromQuery] InspectionOrgKeyInput input)
|
||||
{
|
||||
var orgId = String.Empty;
|
||||
// 传入Id表示查看他人,否则查看自己
|
||||
if (!String.IsNullOrEmpty(input.Id))
|
||||
{
|
||||
orgId = input.Id;
|
||||
}
|
||||
else
|
||||
{
|
||||
orgId = await RelationOrgId();
|
||||
}
|
||||
|
||||
if (String.IsNullOrEmpty(orgId))
|
||||
return null;
|
||||
|
||||
var output = new InspectionOrgDetailOutput();
|
||||
|
||||
var org = await _orgRep.DetachedEntities.FirstOrDefaultAsync(p => p.Id.Equals(orgId));
|
||||
var orgUpdate = await _orgUpdateRep.DetachedEntities.Where(p => p.OrgId.Equals(orgId)).OrderByDescending(p => p.CreatedTime).FirstOrDefaultAsync();
|
||||
|
||||
if (org.Status == InspectionOrgStatus.Normal)
|
||||
{
|
||||
output.Record = org.Adapt<InspectionOrgRegisterInput>();
|
||||
}
|
||||
if (orgUpdate != null &&
|
||||
(orgUpdate.Status == InspectionOrgUpdateStatus.Reviewing || orgUpdate.Status == InspectionOrgUpdateStatus.Back))
|
||||
{
|
||||
output.UpdateRecord = orgUpdate.Adapt<InspectionOrgRegisterInput>();
|
||||
}
|
||||
|
||||
// 获取最新更新时间
|
||||
var lastOrgUpdatedTime = await _orgUpdateRep.DetachedEntities
|
||||
.Where(p => p.OrgId.Equals(orgId))
|
||||
.Where(p => p.Status == InspectionOrgUpdateStatus.Approved)
|
||||
.MaxAsync(p => p.UpdatedTime);
|
||||
|
||||
output.Id = orgId;
|
||||
output.Code = org.Code;
|
||||
output.Status = org.Status;
|
||||
output.UpdateStatus = orgUpdate.Status;
|
||||
output.Remark = orgUpdate.Remark;
|
||||
output.CreatedTime = org.CreatedTime;
|
||||
output.UpdatedTime = lastOrgUpdatedTime;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
private async Task<dynamic> Page(InspectionOrgPageInput input, int Type)
|
||||
{
|
||||
var sql = @"SELECT
|
||||
IO.Id,
|
||||
IO.Code,
|
||||
IOU.Name,
|
||||
IOU.CreditCode,
|
||||
IOU.Address,
|
||||
IOU.Contacts,
|
||||
IOU.ContactsPhone,
|
||||
IOU.LegalPerson,
|
||||
IOU.OrgTelephone,
|
||||
IO.Status,
|
||||
IOU.Type UpdateType,
|
||||
IOU.Status UpdateStatus,
|
||||
(SELECT COUNT(0) FROM bs_inspection_org_update WHERE OrgId = IO.Id AND Status <> 1) UpdateCount,
|
||||
IOU.UpdatedTime
|
||||
FROM bs_inspection_org IO
|
||||
LEFT JOIN
|
||||
(SELECT * FROM bs_inspection_org_update WHERE CreatedTime IN (SELECT MAX(CreatedTime) FROM bs_inspection_org_update WHERE Status <> -2 AND Type = @UpdateType GROUP BY OrgId))
|
||||
IOU ON IOU.OrgId = IO.Id";
|
||||
|
||||
return await _dapperRep.QueryPageDataDynamic(
|
||||
sql,
|
||||
input,
|
||||
param: new { UpdateType = Type },
|
||||
filterFields: new[] { "Code", "UpdateStatus" }
|
||||
);
|
||||
}
|
||||
|
||||
[HttpPost("/inspectionOrg/reviewPage")]
|
||||
public async Task<dynamic> ReviewPage([FromBody] InspectionOrgPageInput input)
|
||||
{
|
||||
return await Page(input, 1);
|
||||
}
|
||||
|
||||
[HttpPost("/inspectionOrg/reviewUpdatePage")]
|
||||
public async Task<dynamic> ReviewUpdatePage([FromBody] InspectionOrgPageInput input)
|
||||
{
|
||||
return await Page(input, 2);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 登记审核通过
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("/inspectionOrg/reviewApproved")]
|
||||
[UnitOfWork]
|
||||
public async Task ReviewApproved([FromBody] InspectionOrgKeyRequiredInput input)
|
||||
{
|
||||
var orgUpdate = await _orgUpdateRep.DetachedEntities.Where(p => p.OrgId.Equals(input.Id)).OrderByDescending(p => p.CreatedTime).FirstOrDefaultAsync();
|
||||
|
||||
orgUpdate.Status = InspectionOrgUpdateStatus.Approved;
|
||||
await orgUpdate.UpdateIncludeAsync(new [] {
|
||||
nameof(BsInspectionOrgUpdate.Status)
|
||||
});
|
||||
|
||||
var org = orgUpdate.Adapt<BsInspectionOrg>();
|
||||
org.Id = input.Id;
|
||||
org.Status = InspectionOrgStatus.Normal;
|
||||
|
||||
await org.UpdateExcludeAsync(new[] {
|
||||
nameof(BsInspectionOrg.Code)
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 登记审核退回
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("/inspectionOrg/reviewNotApproved")]
|
||||
public async Task ReviewNotApproved([FromBody] InspectionOrgReviewNotApprovedInput input)
|
||||
{
|
||||
var orgUpdate = await _orgUpdateRep.DetachedEntities.Where(p => p.OrgId.Equals(input.Id)).OrderByDescending(p => p.CreatedTime).FirstOrDefaultAsync();
|
||||
|
||||
orgUpdate.Status = InspectionOrgUpdateStatus.Back;
|
||||
orgUpdate.Remark = input.Remark;
|
||||
await orgUpdate.UpdateIncludeAsync(new[] {
|
||||
nameof(BsInspectionOrgUpdate.Status),
|
||||
nameof(BsInspectionOrgUpdate.Remark)
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取审核记录
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("/inspectionOrg/history")]
|
||||
public async Task<dynamic> History([FromQuery] InspectionOrgKeyRequiredInput input)
|
||||
{
|
||||
var sql = @"SELECT
|
||||
IOU.Id,
|
||||
IOU.OrgId,
|
||||
IO.Code,
|
||||
IOU.Remark,
|
||||
IOU.Type,
|
||||
IOU.Status,
|
||||
IOU.CreatedTime,
|
||||
IOU.UpdatedTime
|
||||
FROM bs_inspection_org_update IOU
|
||||
LEFT JOIN bs_inspection_org IO ON IO.Id = IOU.OrgId
|
||||
WHERE IO.Id = @Id
|
||||
AND IOU.Status <> 1 -- 审核中
|
||||
ORDER BY CreatedTime DESC";
|
||||
return await _dapperRep.QueryAsync(sql, new { Id = input.Id });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
using Ewide.Core;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Application
|
||||
{
|
||||
public class InspectionOrgDirKeyInput
|
||||
{
|
||||
public virtual string Id { get; set; }
|
||||
}
|
||||
|
||||
public class InspectionOrgDirKeyRequiredInput : InspectionOrgDirKeyInput
|
||||
{
|
||||
[Required]
|
||||
public override string Id { get; set; }
|
||||
}
|
||||
|
||||
public class InspectionOrgDirPageInput : PageInputBase
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public class InspectionOrgDirSaveInput : InspectionOrgDirKeyInput
|
||||
{
|
||||
[Required]
|
||||
public string No { get; set; }
|
||||
[Required]
|
||||
public InspectionOrgDirSaveDetailInput[] Detail { get; set; }
|
||||
}
|
||||
|
||||
public class InspectionOrgDirSaveDetailInput
|
||||
{
|
||||
[Required]
|
||||
public string OrgId { get; set; }
|
||||
[Required]
|
||||
public int Score { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Application
|
||||
{
|
||||
public class InspectionOrgDirPreviewOutput
|
||||
{
|
||||
public BsInspectionOrgDirStage Stage { get; set; }
|
||||
public int Count { get; set; }
|
||||
public dynamic List { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Application.Service
|
||||
{
|
||||
public interface IInspectionOrgDirService
|
||||
{
|
||||
public Task<dynamic> Page(InspectionOrgDirPageInput input);
|
||||
public Task<dynamic> ListScore();
|
||||
public Task<dynamic> Detail();
|
||||
public Task SaveScore(InspectionOrgDirSaveInput input);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,295 @@
|
||||
using Dapper;
|
||||
using Ewide.Core.Extension;
|
||||
using Furion.DatabaseAccessor;
|
||||
using Furion.DatabaseAccessor.Extensions;
|
||||
using Furion.DependencyInjection;
|
||||
using Furion.DynamicApiController;
|
||||
using Furion.FriendlyException;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Application.Service
|
||||
{
|
||||
public class InspectionOrgDirService : IInspectionOrgDirService, IDynamicApiController, ITransient
|
||||
{
|
||||
private readonly IDapperRepository _dapperRep;
|
||||
|
||||
private readonly IRepository<BsInspectionOrgDirStage> _dirStageRep;
|
||||
private readonly IRepository<BsInspectionOrgDirDetail> _dirDetailRep;
|
||||
private readonly IRepository<BsInspectionOrg> _orgRep;
|
||||
|
||||
public InspectionOrgDirService(
|
||||
IDapperRepository dapperRep,
|
||||
|
||||
IRepository<BsInspectionOrgDirStage> dirStageRep,
|
||||
IRepository<BsInspectionOrgDirDetail> dirDetailRep,
|
||||
IRepository<BsInspectionOrg> orgRep
|
||||
)
|
||||
{
|
||||
_dapperRep = dapperRep;
|
||||
|
||||
_dirStageRep = dirStageRep;
|
||||
_dirDetailRep = dirDetailRep;
|
||||
_orgRep = orgRep;
|
||||
}
|
||||
|
||||
[HttpPost("/inspectionOrgDir/page")]
|
||||
public async Task<dynamic> Page([FromBody] InspectionOrgDirPageInput input)
|
||||
{
|
||||
var sql = "SELECT * FROM bs_inspection_org_dir_stage WHERE Status = 1 ORDER BY PublishTime DESC";
|
||||
return await _dapperRep.QueryPageDataDynamic(sql, input, filterFields: new[] { nameof(BsInspectionOrgDirStage.No) });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前名录打分列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost("/inspectionOrgDir/listScore")]
|
||||
public async Task<dynamic> ListScore()
|
||||
{
|
||||
var sql = @"SELECT * FROM
|
||||
(
|
||||
SELECT
|
||||
IO.Id,
|
||||
IO.`Code`,
|
||||
IO.`Name`,
|
||||
CASE WHEN LIODD.ScoreResult IS NULL THEN 1 ELSE 0 END IsNew,
|
||||
LIODD.ScoreResult PrevScoreResult,
|
||||
TIODD.Score,
|
||||
TIODD.ScoreResult
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
*,
|
||||
(SELECT Id FROM bs_inspection_org_dir_stage WHERE Status = 1 ORDER BY CreatedTime DESC LIMIT 1) PrevStageId,
|
||||
(SELECT Id FROM bs_inspection_org_dir_stage WHERE Status = 0) CurrentStageId
|
||||
FROM
|
||||
bs_inspection_org
|
||||
) IO
|
||||
LEFT JOIN bs_inspection_org_dir_detail LIODD ON IO.PrevStageId = LIODD.StageId AND IO.Id = LIODD.OrgId
|
||||
LEFT JOIN bs_inspection_org_dir_detail TIODD ON IO.CurrentStageId = TIODD.StageId AND IO.Id = TIODD.OrgId
|
||||
WHERE IO.Status = 1
|
||||
) T ORDER BY IsNew DESC, `Code`";
|
||||
return await _dapperRep.QueryAsync(sql);
|
||||
}
|
||||
|
||||
[HttpGet("/inspectionOrgDir/detail")]
|
||||
public async Task<dynamic> Detail()
|
||||
{
|
||||
return await _dirStageRep.DetachedEntities.FirstOrDefaultAsync(p => p.Status.Equals(0));
|
||||
}
|
||||
|
||||
private int ScoreResult(int score, int? prevScoreResult)
|
||||
{
|
||||
int result;
|
||||
if (score >= 10)
|
||||
{
|
||||
result = 1;
|
||||
}
|
||||
else if (score >= 8)
|
||||
{
|
||||
result = 2;
|
||||
}
|
||||
else if (score >= 6)
|
||||
{
|
||||
result = 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = 4;
|
||||
}
|
||||
|
||||
if (prevScoreResult.GetValueOrDefault(0).Equals(3) && result.Equals(3))
|
||||
{
|
||||
result = 4;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
[HttpPost("/inspectionOrgDir/saveScore")]
|
||||
[UnitOfWork]
|
||||
public async Task SaveScore([FromBody] InspectionOrgDirSaveInput input)
|
||||
{
|
||||
var stageId = input.Id;
|
||||
|
||||
var isAdd = false;
|
||||
// 新增修改名录主表
|
||||
if (String.IsNullOrEmpty(stageId))
|
||||
{
|
||||
// 新增
|
||||
// 如果存在未公布的名录,则失败
|
||||
var isExistUnpublished = await _dirStageRep.DetachedEntities.AnyAsync(p => p.Status.Equals(0));
|
||||
if(isExistUnpublished)
|
||||
throw Oops.Oh("存在未公布的名录,无法新增");
|
||||
|
||||
var isExistNo = await _dirStageRep.DetachedEntities.AnyAsync(p => p.No.Equals(input.No));
|
||||
if (isExistNo)
|
||||
throw Oops.Oh("名录期号已存在");
|
||||
|
||||
var stage = input.Adapt<BsInspectionOrgDirStage>();
|
||||
stageId = Guid.NewGuid().ToString().ToLower();
|
||||
stage.Id = stageId;
|
||||
|
||||
await stage.InsertAsync();
|
||||
|
||||
isAdd = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
var isExistNo = await _dirStageRep.DetachedEntities.AnyAsync(p => p.No.Equals(input.No) && !p.Id.Equals(input.Id));
|
||||
if (isExistNo)
|
||||
throw Oops.Oh("名录期号已存在");
|
||||
|
||||
// 修改
|
||||
var stage = await _dirStageRep.FirstOrDefaultAsync(p => p.Id.Equals(input.Id));
|
||||
stage.No = input.No;
|
||||
|
||||
await stage.UpdateAsync();
|
||||
}
|
||||
|
||||
var prevStage = await _dirStageRep.DetachedEntities.OrderByDescending(p => p.CreatedTime).FirstOrDefaultAsync(p => !p.Id.Equals(stageId));
|
||||
var prevDetails = new List<BsInspectionOrgDirDetail>();
|
||||
if (prevStage != null)
|
||||
{
|
||||
prevDetails = await _dirDetailRep.DetachedEntities.Where(p => p.StageId.Equals(prevStage.Id)).ToListAsync();
|
||||
}
|
||||
|
||||
// 新增修改名录详细表
|
||||
foreach (var detail in input.Detail)
|
||||
{
|
||||
var prevDetail = prevDetails.FirstOrDefault(p => p.OrgId.Equals(detail.OrgId));
|
||||
var scoreResult = ScoreResult(detail.Score, prevDetail?.ScoreResult);
|
||||
|
||||
if (!isAdd)
|
||||
{
|
||||
// 名录已经存在时,判断每个机构的打分记录是否已经存在
|
||||
var _data = await _dirDetailRep.FirstOrDefaultAsync(p => p.OrgId.Equals(detail.OrgId) && p.StageId.Equals(stageId));
|
||||
if (_data != null)
|
||||
{
|
||||
_data.Score = detail.Score;
|
||||
_data.ScoreResult = scoreResult;
|
||||
await _data.UpdateAsync();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
var data = detail.Adapt<BsInspectionOrgDirDetail>();
|
||||
data.StageId = stageId;
|
||||
data.ScoreResult = scoreResult;
|
||||
|
||||
await data.InsertAsync();
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("/inspectionOrgDir/preview")]
|
||||
public async Task<InspectionOrgDirPreviewOutput> Preview()
|
||||
{
|
||||
var stage = await _dirStageRep.FirstOrDefaultAsync(p => p.Status.Equals(0));
|
||||
if (stage == null)
|
||||
{
|
||||
// 当前没有需要发布的名录
|
||||
return null;
|
||||
}
|
||||
|
||||
var count = await _dirDetailRep.Where(p => p.StageId.Equals(stage.Id) && !p.ScoreResult.Equals(4)).CountAsync();
|
||||
|
||||
var sql = @"SELECT * FROM
|
||||
(
|
||||
SELECT
|
||||
IO.Id,
|
||||
IO.`Code`,
|
||||
IO.`Name`,
|
||||
IO.Address,
|
||||
CASE
|
||||
WHEN TIODD.ScoreResult = 4 THEN -1
|
||||
WHEN LIODD.ScoreResult IS NULL THEN 1
|
||||
ELSE 0 END `Status`
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
*,
|
||||
(SELECT Id FROM bs_inspection_org_dir_stage WHERE Status = 1 ORDER BY CreatedTime DESC LIMIT 1) PrevStageId,
|
||||
(SELECT Id FROM bs_inspection_org_dir_stage WHERE Status = 0) CurrentStageId
|
||||
FROM
|
||||
bs_inspection_org
|
||||
) IO
|
||||
LEFT JOIN bs_inspection_org_dir_detail LIODD ON IO.PrevStageId = LIODD.StageId AND IO.Id = LIODD.OrgId
|
||||
LEFT JOIN bs_inspection_org_dir_detail TIODD ON IO.CurrentStageId = TIODD.StageId AND IO.Id = TIODD.OrgId
|
||||
WHERE (LIODD.ScoreResult IS NULL OR LIODD.ScoreResult < 4) AND IO.`Status` >= 0
|
||||
) T ORDER BY `Status` DESC, `Code`";
|
||||
var list = await _dapperRep.QueryAsync(sql);
|
||||
|
||||
return new InspectionOrgDirPreviewOutput
|
||||
{
|
||||
Stage = stage,
|
||||
Count = count,
|
||||
List = list
|
||||
};
|
||||
}
|
||||
|
||||
[HttpPost("/inspectionOrgDir/publish")]
|
||||
[UnitOfWork]
|
||||
public async Task Publish()
|
||||
{
|
||||
var stage = await _dirStageRep.FirstOrDefaultAsync(p => p.Status.Equals(0));
|
||||
if (stage == null)
|
||||
throw Oops.Oh("当前名录数据错误");
|
||||
|
||||
// 评分详情
|
||||
var details = await _dirDetailRep.DetachedEntities.Where(p => p.StageId.Equals(stage.Id)).ToListAsync();
|
||||
// 当前需打分的机构
|
||||
var orgIds = await _orgRep.DetachedEntities.Where(p => p.Status != InspectionOrgStatus.Delisting && p.Status != InspectionOrgStatus.Revoke).Select(p => p.Id).ToListAsync();
|
||||
if (orgIds.Any(p => !details.Select(p => p.OrgId).Contains(p)))
|
||||
throw Oops.Oh("存在未评分的机构");
|
||||
|
||||
// 往期名录
|
||||
var prevStage = await _dirStageRep.DetachedEntities.OrderByDescending(p => p.CreatedTime).FirstOrDefaultAsync(p => !p.Id.Equals(stage.Id));
|
||||
// 往期机构
|
||||
var prevDetails = await _dirDetailRep.DetachedEntities.Where(p => p.StageId.Equals(prevStage.Id)).ToListAsync();
|
||||
// 往期黄牌机构
|
||||
var prevFilteredDetailOrgIds = new List<string>();
|
||||
if (prevStage != null)
|
||||
{
|
||||
// 获取往期黄牌机构
|
||||
prevFilteredDetailOrgIds = prevDetails.Where(p => p.ScoreResult.Equals(3)).Select(p => p.OrgId).ToList();
|
||||
}
|
||||
|
||||
// 对除名的机构修改状态
|
||||
var revmoeCount = 0;
|
||||
var mayBeRemovedDetails = details.Where(p => p.ScoreResult.Equals(3) || p.ScoreResult.Equals(4)).ToList();
|
||||
foreach (var detail in mayBeRemovedDetails)
|
||||
{
|
||||
if ((detail.ScoreResult.Equals(3) && prevFilteredDetailOrgIds.Contains(detail.OrgId))
|
||||
|| detail.ScoreResult.Equals(4))
|
||||
{
|
||||
// 本期及往期为黄牌或者本期为红牌的,进行除名
|
||||
var org = await _orgRep.FirstOrDefaultAsync(p => p.Id.Equals(detail.OrgId));
|
||||
org.Status = InspectionOrgStatus.Delisting;
|
||||
await org.UpdateIncludeAsync(new[] { nameof(BsInspectionOrg.Status) });
|
||||
revmoeCount++;
|
||||
}
|
||||
}
|
||||
|
||||
// 新增机构数量
|
||||
var newDetailsCount = details.Where(p => (p.ScoreResult.Equals(1) || p.ScoreResult.Equals(2)) && !prevDetails.Select(p => p.OrgId).Contains(p.OrgId)).Count();
|
||||
|
||||
// 总数减去除名
|
||||
stage.OrgAmount = details.Count - revmoeCount;
|
||||
// 除名
|
||||
stage.RemovedOrgAmount = revmoeCount;
|
||||
// 新增
|
||||
stage.NewOrgAmount = newDetailsCount;
|
||||
|
||||
stage.Status = 1;
|
||||
stage.PublishTime = DateTime.Now;
|
||||
await stage.UpdateAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user