370 lines
18 KiB
C#
370 lines
18 KiB
C#
using Ewide.NbzsZheliban.Entity;
|
|
using Ewide.NbzsZheliban.Entity.Base;
|
|
using Ewide.NbzsZheliban.Entity.Extends;
|
|
using Ewide.NbzsZheliban.Tools;
|
|
using Furion;
|
|
using Furion.DataEncryption;
|
|
using Furion.FriendlyException;
|
|
using Furion.JsonSerialization;
|
|
using Furion.UnifyResult;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.StaticFiles;
|
|
using Newtonsoft.Json.Linq;
|
|
using SqlSugar;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Ewide.NbzsZheliban.Service
|
|
{
|
|
[ApiDescriptionSettings(Name = "数据接口")]
|
|
public class DataService : Furion.DynamicApiController.IDynamicApiController///: BaseService
|
|
{
|
|
private readonly ISqlSugarRepository repository;
|
|
private readonly SqlSugarClient db;
|
|
private readonly IJsonSerializerProvider _jsonSerializer;
|
|
public DataService(ISqlSugarRepository sqlSugarRepository, IJsonSerializerProvider jsonSerializer)
|
|
{
|
|
repository = sqlSugarRepository;
|
|
db = repository.Context;
|
|
_jsonSerializer = jsonSerializer;
|
|
}
|
|
private JObject GetInfoByTicket(string ticket)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(ticket))
|
|
throw Oops.Oh("无效访问");
|
|
var dbTicket = db.Queryable<zjzwfwTickets>().Where(p => p.Ticket == ticket && p.ExpireTime > DateTime.Now).OrderBy(p => p.CreateTime, OrderByType.Desc).First();
|
|
if (dbTicket != null)
|
|
{
|
|
return JObject.Parse(dbTicket.OriginalResponse);
|
|
}
|
|
else
|
|
{
|
|
var time = DateTime.Now.ToString("yyyyMMddHHmmss");
|
|
var servicecode = App.Configuration["zlb_setting:servicecode"];
|
|
var servicepwd = App.Configuration["zlb_setting:servicepwd"];
|
|
var sign = MD5Encryption.Encrypt(servicecode + servicepwd + time);
|
|
var datatype = "json";
|
|
var url = App.Configuration["zlb_setting:ticket_url"]
|
|
.Replace("{servicecode}", servicecode)
|
|
.Replace("{time}", time)
|
|
.Replace("{sign}", sign)
|
|
.Replace("{ticket}", ticket)
|
|
.Replace("{datatype}", datatype)
|
|
;
|
|
var tickerRsltStr = Ewide.NbzsZheliban.Tools.HttpHelper.CallUrl(url, "");
|
|
JObject ticketObj = null;
|
|
try
|
|
{
|
|
ticketObj = JObject.Parse(tickerRsltStr);
|
|
}
|
|
catch (Newtonsoft.Json.JsonReaderException)
|
|
{
|
|
throw Oops.Oh($"ticket接口返回值有误,[{tickerRsltStr}]");
|
|
}
|
|
if (ticketObj["result"].Value<int>() != 0)
|
|
throw Oops.Oh(ticketObj["result"].Value<int>(), $"ticket接口返回值有误,[{tickerRsltStr}]");
|
|
time = DateTime.Now.ToString("yyyyMMddHHmmss");
|
|
sign = MD5Encryption.Encrypt(servicecode + servicepwd + time);
|
|
url = App.Configuration["zlb_setting:token_url"]
|
|
.Replace("{servicecode}", servicecode)
|
|
.Replace("{time}", time)
|
|
.Replace("{sign}", sign)
|
|
.Replace("{token}", ticketObj["token"].ToString())
|
|
.Replace("{datatype}", datatype)
|
|
;
|
|
var userinfoRsltStr = Ewide.NbzsZheliban.Tools.HttpHelper.CallUrl(url, "");
|
|
JObject userinfoObj = null;
|
|
try
|
|
{
|
|
userinfoObj = JObject.Parse(userinfoRsltStr);
|
|
}
|
|
catch (Newtonsoft.Json.JsonReaderException)
|
|
{
|
|
throw Oops.Oh($"token接口返回值有误,[{tickerRsltStr}]");
|
|
}
|
|
if (userinfoObj["result"].Value<int>() != 0)
|
|
throw Oops.Oh(userinfoObj["result"].Value<int>(), $"ticket接口返回值有误,[{tickerRsltStr}]");
|
|
var temp1 = db.Insertable<zjzwfwTickets>(new zjzwfwTickets
|
|
{
|
|
ID = Guid.NewGuid().ToString(),
|
|
Ticket = ticket,
|
|
IdCardNo = userinfoObj["idnum"].ToString(),
|
|
UserName = userinfoObj["username"].ToString(),
|
|
ExpireTime = DateTime.Now.AddHours(4),//浙里办的token时效也是4个小时
|
|
CreateTime = DateTime.Now,
|
|
OriginalResponse = userinfoRsltStr
|
|
}).ExecuteCommand();
|
|
if (temp1 <= 0)
|
|
throw Oops.Oh("出现异常,请联系管理员");
|
|
return userinfoObj;
|
|
}
|
|
}
|
|
private async Task<H5IndexModel> GetInfoByCardNoAsync(string cardno, string username)
|
|
{
|
|
//var cardno = args.GetJsonValue("cardno", isThrowExp: true);
|
|
//住宅调查表
|
|
var list_zz_dcb = await db.Ado.SqlQueryAsync<Dcbs>("select ID dcbId,ProjectId PrjId from InvestigateTable b where b.ExpropriatedCardNo=@ExpropriatedCardNo", new List<SugarParameter> { new SugarParameter("ExpropriatedCardNo", cardno, System.Data.DbType.String) }.ToArray());
|
|
//非住宅调查表
|
|
var list_fzz_dcb = await db.Ado.SqlQueryAsync<Dcbs>("select ID dcbId,ProjectId PrjId from NonResidentialInvestigateTable b where b.PropertyRightCardNo=@ExpropriatedCardNo", new List<SugarParameter> { new SugarParameter("ExpropriatedCardNo", cardno, System.Data.DbType.String) }.ToArray());
|
|
//调查表集合
|
|
var list_dcbs = list_zz_dcb.Concat(list_fzz_dcb);
|
|
//项目列表
|
|
var list_projects = await db.Ado.SqlQueryAsync<H5IndexPrjModel>("select a.ID Prjid,a.area,a.AreaID,a.HouseAcquisitionDepartment as zsbm,a.CollectDecisionNo1 as year,(isnull(a.CollectDecisionNoHeadName,'')+'['+cast(a.CollectDecisionNo1 as varchar)+']'+ isnull(cast(a.CollectDecisionNo2 as varchar),'')+'号') zsjdh,dbo.get_current_state(a.ID) CurrentState,NAME from Projects a where ID in ('" + string.Join("','", list_dcbs.Select(p => p.PrjId)) + "') ");
|
|
//分户评估
|
|
var InvestigateTableID_param = "'" + string.Join("','", list_dcbs.Select(p => p.dcbId)) + "'";
|
|
var list_fhpgs = await db.Ado.SqlQueryAsync<Fhpgs>("select d.id,e.ProjectId as PrjId ,d.AssessmentNo,e.HouseAddress,d.countValue,e.id dcbId,d.CreateTime,d.CreateUserName from InvestigateTable_Assessment d inner join InvestigateTable e on d.InvestigateTableId=e.ID where d.InvestigateTableID in ( " + InvestigateTableID_param + " ) union all select d.id,e.ProjectId as PrjId ,AssessmentNo, e.HouseAddress, d.countValue,e.id dcbId,d.CreateTime,d.CreateUserName from NonInvestigateTable_Assessment d inner join NonResidentialInvestigateTable e on d.NonInvestigateTableID = e.ID where d.NonInvestigateTableID in ( " + InvestigateTableID_param + " ) ;");
|
|
//补偿协议
|
|
var list_bcxys = await db.Ado.SqlQueryAsync<Bcxy>("select d.id,isnull(d.CollectDecisionNoHeadName,'')+isnull(d.No1,'')+'-'+isnull(d.No2,'')+(case when (d.No3 is null or d.No3 = '') then '' else ('-'+d.No3) end ) XyNo,d.SwitchProductionWay,e.HouseAddress,d.SummationShouldCompensateMoney,e.ProjectId as PrjId,e.id dcbId,d.SignTime from ResidentialAgreement d inner join InvestigateTable e on d.InvestigateTableId=e.ID where d.InvestigateTableID in ( " + InvestigateTableID_param + " ) union all select d.id,isnull(d.CollectDecisionNoHeadName, '') + isnull(d.No2, '') + '-' + isnull(d.No3, '') XyNo , d.SwitchProductionWay, e.HouseAddress, d.SummationShouldCompensateMoney, e.ProjectId as PrjId,e.id dcbId,d.SignTime from NonResidentialAgreement d inner join NonResidentialInvestigateTable e on d.NonInvestigateTableID = e.ID where d.NonInvestigateTableID in ( " + InvestigateTableID_param + " ); ");
|
|
var listAreas = new List<Guid?> { Guid.Parse("B2A0291C-84C7-4D86-A6D5-CB9FCCF4A2D8") };
|
|
list_projects.ForEach(p =>
|
|
{
|
|
p.FhpgList = list_fhpgs.Where(a => a.PrjId == p.PrjId).ToList();
|
|
var bcxy = list_bcxys.Where(a => a.PrjId == p.PrjId).ToList();
|
|
bcxy.ForEach(a => a.countValue = list_fhpgs.Where(b => b.dcbId == a.dcbId).First().countValue);
|
|
p.BcxyList = bcxy;
|
|
listAreas.Add(Guid.Parse(p.AreaID));
|
|
});
|
|
//政策
|
|
var list_PoliciesRegulations = await db.Queryable<Entity.PoliciesRegulations>().Where(a => listAreas.Contains(a.AreaID)).Select(b => new PoliciesRegulation
|
|
{
|
|
ID = b.ID,
|
|
Contents = b.Contents,
|
|
PublicTime = b.PublicTime,
|
|
Title = b.Title,
|
|
Area = b.Area
|
|
}).ToListAsync();
|
|
|
|
H5IndexModel h5IndexModel = new()
|
|
{
|
|
PrjList = list_projects,
|
|
IdCard = cardno,
|
|
UserName = username,
|
|
PoliciesRegulationsLists = new Entity.Extends.PoliciesRegulations { List = list_PoliciesRegulations, TotalCount = list_PoliciesRegulations.Count }
|
|
};
|
|
return h5IndexModel;
|
|
}
|
|
/// <summary>
|
|
/// 被征收人关联的项目列表
|
|
/// </summary>
|
|
/// <param name="args"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("/project/list")]
|
|
[Microsoft.AspNetCore.Authorization.AllowAnonymous]
|
|
public async Task<dynamic> PrjList([FromBody] JObject args)
|
|
{
|
|
var ticket = args.GetJsonValue("ticket", isThrowExp: true);
|
|
//var ticket = Request.Query["ticket"];
|
|
var userinfoObj = GetInfoByTicket(ticket);
|
|
var cardno = userinfoObj["idnum"].ToString();
|
|
var username = userinfoObj["username"].ToString();
|
|
return await GetInfoByCardNoAsync(cardno, username);
|
|
}
|
|
/// <summary>
|
|
/// 被征收人关联的项目列表
|
|
/// </summary>
|
|
/// <param name="args"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("/project/list2")]
|
|
[Microsoft.AspNetCore.Authorization.AllowAnonymous]
|
|
public async Task<dynamic> PrjList2([FromBody] JObject args)
|
|
{
|
|
var cardno = "341203199206303411";
|
|
var username = "张三丰";
|
|
return await GetInfoByCardNoAsync(cardno, username);
|
|
}
|
|
/// <summary>
|
|
/// 政策详细
|
|
/// </summary>
|
|
/// <param name="args"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("/policies/info")]
|
|
[Microsoft.AspNetCore.Authorization.AllowAnonymous]
|
|
public async Task<dynamic> PolicieInfo([FromBody] JObject args)
|
|
{
|
|
var ticket = args.GetJsonValue("ticket", isThrowExp: true);
|
|
var id = args.GetJsonGuidValue("id", isThrowExp: true);
|
|
JObject userInfoObj = GetInfoByTicket(ticket);
|
|
var entity = await db.Queryable<Entity.PoliciesRegulations>().Where(p => p.ID == id).Select(p => new PoliciesRegulation
|
|
{
|
|
ID = p.ID,
|
|
Area = p.Area,
|
|
Contents = p.Contents,
|
|
PublicTime = p.PublicTime,
|
|
Title = p.Title
|
|
}).FirstAsync();
|
|
return entity;
|
|
}
|
|
/// <summary>
|
|
/// 协议详细
|
|
/// </summary>
|
|
/// <param name="args"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("/agreement/info")]
|
|
[Microsoft.AspNetCore.Authorization.AllowAnonymous]
|
|
public async Task<dynamic> AgreementInfo([FromBody] JObject args)
|
|
{
|
|
var ticket = args.GetJsonValue("ticket", isThrowExp: true);
|
|
var id = args.GetJsonGuidValue("id", isThrowExp: true);
|
|
JObject userInfoObj = GetInfoByTicket(ticket);
|
|
var XyFile = "";
|
|
//住宅
|
|
var entity_zz = db.Queryable<Entity.ResidentialAgreement>().Where(p => p.ID == id).Select(p => new { p.ID, p.XyFile }).First();
|
|
if (entity_zz != null)
|
|
{
|
|
XyFile = entity_zz.XyFile;
|
|
}
|
|
//非住宅
|
|
else
|
|
{
|
|
var entity_fzz = db.Queryable<Entity.NonResidentialAgreement>().Where(p => p.ID == id).Select(p => new { p.ID, p.XyFile }).First();
|
|
if (entity_fzz != null)
|
|
{
|
|
XyFile = entity_fzz.XyFile;
|
|
}
|
|
else
|
|
throw Oops.Oh("ID错误");
|
|
}
|
|
if (string.IsNullOrEmpty(XyFile))
|
|
throw Oops.Oh("未上传附件");
|
|
var filePath = App.Configuration["nbzs_domain"] + XyFile;
|
|
return filePath;
|
|
}
|
|
///// <summary>
|
|
///// 协议详细
|
|
///// </summary>
|
|
///// <param name="args"></param>
|
|
///// <returns></returns>
|
|
//[HttpPost("/agreement/info")]
|
|
//[Microsoft.AspNetCore.Authorization.AllowAnonymous]
|
|
//public IActionResult AgreementInfo([FromBody] JObject args)
|
|
//{
|
|
// var ticket = args.GetJsonValue("ticket", isThrowExp: true);
|
|
// var id = args.GetJsonGuidValue("id", isThrowExp: true);
|
|
// JObject userInfoObj = GetInfoByTicket(ticket);
|
|
// var XyFile = "";
|
|
// //住宅
|
|
// var entity_zz = db.Queryable<Entity.ResidentialAgreement>().Where(p => p.ID == id).Select(p => new { p.ID, p.XyFile }).First();
|
|
// if (entity_zz != null)
|
|
// {
|
|
// XyFile = entity_zz.XyFile;
|
|
// }
|
|
// //非住宅
|
|
// else
|
|
// {
|
|
// var entity_fzz = db.Queryable<Entity.NonResidentialAgreement>().Where(p => p.ID == id).Select(p => new { p.ID, p.XyFile }).First();
|
|
// if (entity_fzz != null)
|
|
// {
|
|
// XyFile = entity_fzz.XyFile;
|
|
// }
|
|
// else
|
|
// throw Oops.Oh("ID错误");
|
|
// }
|
|
// if (string.IsNullOrEmpty(XyFile))
|
|
// throw Oops.Oh("未上传附件");
|
|
// var filePath = App.Configuration["nbzs_file_path"] + XyFile;
|
|
// return new FileStreamResult(new FileStream(filePath, FileMode.Open), "application/octet-stream") { FileDownloadName = new FileInfo(filePath).Name };
|
|
//}
|
|
/// <summary>
|
|
/// 分布评估详细
|
|
/// </summary>
|
|
/// <param name="args"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("/house_estimate/info")]
|
|
[Microsoft.AspNetCore.Authorization.AllowAnonymous]
|
|
public async Task<dynamic> HouseEstimateInfo([FromBody] JObject args)
|
|
{
|
|
var ticket = args.GetJsonValue("ticket", isThrowExp: true);
|
|
var id = args.GetJsonGuidValue("id", isThrowExp: true);
|
|
JObject userInfoObj = GetInfoByTicket(ticket);
|
|
var entity_zz = db.Queryable<Entity.InvestigateTable_Assessment>().Where(p => p.ID == id).First();
|
|
if (entity_zz != null)
|
|
{
|
|
if (entity_zz.ValuationMethod == 0)
|
|
{
|
|
return null;
|
|
}
|
|
else
|
|
throw Oops.Oh(199, "请使用文件接口");
|
|
}
|
|
else
|
|
{
|
|
var entity_fzz = db.Queryable<Entity.NonInvestigateTable_Assessment>().Where(p => p.ID == id).First();
|
|
if (entity_fzz != null)
|
|
{
|
|
if (entity_fzz.ValuationMethod == 0)
|
|
{
|
|
return null;
|
|
}
|
|
else
|
|
throw Oops.Oh(199, "请使用文件接口");
|
|
}
|
|
else
|
|
throw Oops.Oh("ID错误");
|
|
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 分布评估详细
|
|
/// </summary>
|
|
/// <param name="args"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("/house_estimate/file")]
|
|
[Microsoft.AspNetCore.Authorization.AllowAnonymous]
|
|
public IActionResult HouseEstimateInfoFile([FromBody] JObject args)
|
|
{
|
|
var ticket = args.GetJsonValue("ticket", isThrowExp: true);
|
|
var id = args.GetJsonGuidValue("id", isThrowExp: true);
|
|
JObject userInfoObj = GetInfoByTicket(ticket);
|
|
var entity_zz = db.Queryable<Entity.InvestigateTable_Assessment>().Where(p => p.ID == id).First();
|
|
if (entity_zz != null)
|
|
{
|
|
switch (entity_zz.ValuationMethod)
|
|
{
|
|
//pdf上传
|
|
case 1:
|
|
case 2:
|
|
if (!string.IsNullOrEmpty(entity_zz.File))
|
|
{
|
|
var filePath = App.Configuration["nbzs_file_path"] + entity_zz.File;
|
|
return new FileStreamResult(new FileStream(filePath, FileMode.Open), "application/octet-stream") { FileDownloadName = new FileInfo(filePath).Name };
|
|
}
|
|
else
|
|
throw Oops.Oh("未上传文件");
|
|
//金额录入
|
|
default:
|
|
throw Oops.Oh("无文件");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
var entity_fzz = db.Queryable<Entity.NonInvestigateTable_Assessment>().Where(p => p.ID == id).First();
|
|
if (entity_fzz != null)
|
|
{
|
|
switch (entity_fzz.ValuationMethod)
|
|
{
|
|
//pdf上传
|
|
case 1:
|
|
if (!string.IsNullOrEmpty(entity_fzz.File))
|
|
{
|
|
var filePath = App.Configuration["nbzs_file_path"] + entity_fzz.File;
|
|
return new FileStreamResult(new FileStream(filePath, FileMode.Open), "application/octet-stream") { FileDownloadName = new FileInfo(filePath).Name };
|
|
}
|
|
else
|
|
throw Oops.Oh("未上传文件");
|
|
//金额录入
|
|
default:
|
|
throw Oops.Oh("无文件");
|
|
}
|
|
}
|
|
else
|
|
throw Oops.Oh("ID错误");
|
|
}
|
|
throw Oops.Oh("出错了");
|
|
}
|
|
}
|
|
}
|