605 lines
29 KiB
C#
605 lines
29 KiB
C#
using Ewide.Nbzs.Entity;
|
||
using Ewide.Nbzs.Entity.Extends;
|
||
using Ewide.NbzsZheliban.Tools;
|
||
using Furion;
|
||
using Furion.DataEncryption;
|
||
using Furion.FriendlyException;
|
||
using Furion.JsonSerialization;
|
||
using Furion.UnifyResult;
|
||
using ImageMagick;
|
||
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;
|
||
using Furion.RemoteRequest.Extensions;
|
||
using Microsoft.AspNetCore.Hosting;
|
||
using Ewide.Core;
|
||
|
||
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;
|
||
private readonly ICache _cache;
|
||
public DataService(ISqlSugarRepository sqlSugarRepository, IJsonSerializerProvider jsonSerializer, IHostingEnvironment hostingEnvironment)
|
||
{
|
||
repository = sqlSugarRepository;
|
||
db = repository.Context;
|
||
_jsonSerializer = jsonSerializer;
|
||
this._hostingEnvironment = hostingEnvironment;
|
||
_cache = new RedisCache(Microsoft.Extensions.Options.Options.Create<CacheOptions>(new CacheOptions
|
||
{
|
||
CacheType = CacheType.RedisCache,
|
||
RedisConnectionString = App.GetConfig<string>("RedisConfig")
|
||
}));
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取当前用户信息
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[HttpPost("/userinfo")]
|
||
[Microsoft.AspNetCore.Authorization.AllowAnonymous]
|
||
public dynamic GetUserInfo([FromBody] JObject args)
|
||
{
|
||
var ticket = args.GetJsonValue("ticket", isThrowExp: true);
|
||
var userinfoObj = GetInfoByTicket(ticket);
|
||
return new Nbzs.Entity.Extends.ZhelibanUserInfo
|
||
{
|
||
CardId = userinfoObj["idnum"].ToString(),
|
||
Name = userinfoObj["username"].ToString()
|
||
};
|
||
}
|
||
/// <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();
|
||
//修改测试数据
|
||
//db.Ado.ExecuteCommand("update InvestigateTable set ExpropriatedCardNo='" + cardno + "' where id ='A80C1599-B658-4176-8CCF-DDA57A64254F' ");
|
||
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="cardno"></param>
|
||
/// <returns></returns>
|
||
private async Task<List<Dcbs>> GetzzDcbsAsync(string _cardno)
|
||
{
|
||
var cardno = MD5Encryption.Encrypt(_cardno);
|
||
var list = _cache.Get<List<Dcbs>>("CacheData-InvestigateTable");
|
||
if (list != null && list.Count > 0)
|
||
return list.Where(p => p.ExpropriatedCardNo == cardno).ToList();
|
||
else
|
||
//住宅调查表
|
||
return 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());
|
||
}
|
||
/// <summary>
|
||
/// 非住宅调查表
|
||
/// </summary>
|
||
/// <param name="cardno"></param>
|
||
/// <returns></returns>
|
||
private async Task<List<Dcbs>> GetfzzDcbsAsync(string _cardno)
|
||
{
|
||
var cardno = MD5Encryption.Encrypt(_cardno);
|
||
var list = _cache.Get<List<Dcbs>>("CacheData-NonResidentialInvestigateTable");
|
||
if (list != null && list.Count > 0)
|
||
return list.Where(p => p.ExpropriatedCardNo == cardno).ToList();
|
||
else
|
||
//非住宅调查表
|
||
return await db.Ado.SqlQueryAsync<Dcbs>("select ID dcbId,ProjectId PrjId from NonResidentialInvestigateTable b where b.PropertyRightPrsonCardNo=@ExpropriatedCardNo", new List<SugarParameter> { new SugarParameter("ExpropriatedCardNo", cardno, System.Data.DbType.String) }.ToArray());
|
||
}
|
||
/// <summary>
|
||
/// 项目列表
|
||
/// </summary>
|
||
/// <param name="list_dcbs"></param>
|
||
/// <returns></returns>
|
||
private async Task<List<H5IndexPrjModel>> GetPrjListAsync(IEnumerable<Dcbs> list_dcbs)
|
||
{
|
||
var list = _cache.Get<List<H5IndexPrjModel>>("CacheData-Projects");
|
||
if (list != null && list.Count > 0)
|
||
return list.Where(p => p.status == 2 && list_dcbs.Select(p => p.PrjId).Contains(p.PrjId)).ToList();
|
||
else
|
||
//项目列表
|
||
return 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,CreateRecordTime from Projects a where status = 2 and ID in ('" + string.Join("','", list_dcbs.Select(p => p.PrjId)) + "') ");
|
||
}
|
||
/// <summary>
|
||
/// 分户评估
|
||
/// </summary>
|
||
/// <param name="InvestigateTableID_param"></param>
|
||
/// <returns></returns>
|
||
private async Task<List<Fhpgs>> GetFHPGListAsync(IEnumerable<Dcbs> list_dcbs)
|
||
{
|
||
var list = _cache.Get<List<Fhpgs>>("CacheData-InvestigateTable_Assessment");
|
||
if (list != null && list.Count > 0)
|
||
return list.Where(p => list_dcbs.Select(p => p.dcbId).Contains(p.dcbId)).ToList();
|
||
else
|
||
{
|
||
var InvestigateTableID_param = "'" + string.Join("','", list_dcbs.Select(p => p.dcbId)) + "'";
|
||
//分户评估
|
||
return 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,1 type from InvestigateTable_Assessment d inner join InvestigateTable e on d.InvestigateTableId=e.ID where d.IsPublic=1 and 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,2 type from NonInvestigateTable_Assessment d inner join NonResidentialInvestigateTable e on d.NonInvestigateTableID = e.ID where d.IsPublic=1 and d.NonInvestigateTableID in ( " + InvestigateTableID_param + " ) ;");
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 补偿协议
|
||
/// </summary>
|
||
/// <param name="InvestigateTableID_param"></param>
|
||
/// <returns></returns>
|
||
private async Task<List<Bcxy>> GetBCXYListAsync(IEnumerable<Dcbs> list_dcbs)
|
||
{
|
||
var list = _cache.Get<List<Bcxy>>("CacheData-InvestigateTable_Assessment");
|
||
if (list != null && list.Count > 0)
|
||
return list.Where(p => list_dcbs.Select(p => p.dcbId).Contains(p.dcbId)).ToList();
|
||
else
|
||
{
|
||
var InvestigateTableID_param = "'" + string.Join("','", list_dcbs.Select(p => p.dcbId)) + "'";
|
||
//补偿协议
|
||
return 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,1 type from ResidentialAgreement d inner join InvestigateTable e on d.InvestigateTableId=e.ID where d.IsInRecords = 1 and 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,2 type from NonResidentialAgreement d inner join NonResidentialInvestigateTable e on d.NonInvestigateTableID = e.ID where d.IsInRecords = 1 and d.NonInvestigateTableID in ( " + InvestigateTableID_param + " ); ");
|
||
}
|
||
}
|
||
private async Task<H5IndexModel> GetInfoByCardNoAsync(string cardno, string username)
|
||
{
|
||
//var cardno_aes = AESEncryption.Decrypt(cardno, Common.GetHashKey());
|
||
var list_zz_dcb = await GetzzDcbsAsync(cardno);
|
||
var list_fzz_dcb = await GetfzzDcbsAsync(cardno);
|
||
//调查表集合
|
||
var list_dcbs = list_zz_dcb.Concat(list_fzz_dcb);
|
||
var list_projects = await GetPrjListAsync(list_dcbs);
|
||
|
||
var list_fhpgs = await GetFHPGListAsync(list_dcbs);
|
||
var list_bcxys = await GetBCXYListAsync(list_dcbs);
|
||
////解密
|
||
//list_bcxys.ForEach(xy=> {
|
||
//xy.ExpropriatedCardNo= AESEncryption.Decrypt(xy.ExpropriatedCardNo, Common.GetHashKey());
|
||
//});
|
||
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).FirstOrDefault()?.countValue);
|
||
p.BcxyList = bcxy;
|
||
listAreas.Add(Guid.Parse(p.AreaID));
|
||
});
|
||
List<PoliciesRegulation> list_PoliciesRegulations = null;
|
||
var listPoliciesRegulationsTemp = _cache.Get<List<Nbzs.Entity.PoliciesRegulations>>("CacheData-PoliciesRegulations");
|
||
if (listPoliciesRegulationsTemp != null && listPoliciesRegulationsTemp.Count > 0)
|
||
{
|
||
list_PoliciesRegulations = listPoliciesRegulationsTemp.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
|
||
}).ToList();
|
||
}
|
||
else
|
||
{
|
||
//政策
|
||
list_PoliciesRegulations = db.Queryable<Nbzs.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
|
||
}).ToList();
|
||
}
|
||
Nbzs.Entity.Extends.H5IndexModel h5IndexModel = new()
|
||
{
|
||
PrjList = list_projects,
|
||
IdCard = cardno,
|
||
UserName = username,
|
||
PoliciesRegulationsLists = new Nbzs.Entity.Extends.PoliciesRegulations { List = list_PoliciesRegulations, TotalCount = list_PoliciesRegulations.Count }
|
||
};
|
||
return h5IndexModel;
|
||
}
|
||
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)
|
||
{
|
||
var OriginalResponse = DESCEncryption.Decrypt(dbTicket.OriginalResponse, Common.GetZlbSecretKey());
|
||
return JObject.Parse(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 = MD5Encryption.Encrypt(userinfoObj["idnum"].ToString()),
|
||
UserName = userinfoObj["username"].ToString(),
|
||
ExpireTime = DateTime.Now.AddHours(4),//浙里办的token时效也是4个小时
|
||
CreateTime = DateTime.Now,
|
||
OriginalResponse = DESCEncryption.Encrypt(userinfoRsltStr, Common.GetZlbSecretKey())
|
||
}).ExecuteCommand();
|
||
if (temp1 <= 0)
|
||
throw Oops.Oh("出现异常,请联系管理员");
|
||
return userinfoObj;
|
||
}
|
||
}
|
||
/// <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<Nbzs.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_s")]
|
||
[Microsoft.AspNetCore.Authorization.AllowAnonymous]
|
||
public IActionResult AgreementInfoStream([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<Nbzs.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<Nbzs.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("/agreement/info_p")]
|
||
[Microsoft.AspNetCore.Authorization.AllowAnonymous]
|
||
public dynamic AgreementInfoPicture([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<Nbzs.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<Nbzs.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(-2001, "无附件");
|
||
var pics = new List<string>();
|
||
//var nbzs_file_path = App.Configuration["nbzs_file_path"];
|
||
var nbzs_domain = App.Configuration["nbzs_domain"];
|
||
var current_domain = App.Configuration["current_domain"];
|
||
|
||
var filePath = GetCurrentRootPath() + XyFile;
|
||
var pdfFile = new FileInfo(filePath);
|
||
if (File.Exists(pdfFile.Directory + "\\lock"))
|
||
{
|
||
var picCount = pdfFile.Directory.GetFiles(pdfFile.Name + "-*.jpg").Length;
|
||
for (int i = 0; i < picCount; i++)
|
||
{
|
||
pics.Add(current_domain + XyFile + "-" + i + ".jpg");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
var s = (nbzs_domain + XyFile).GetAsStreamAsync().Result;
|
||
StreamToFile(s, XyFile);
|
||
MagickReadSettings settings = new MagickReadSettings();
|
||
settings.Density = new Density(400, 400); //设置质量
|
||
using (MagickImageCollection images = new MagickImageCollection())
|
||
{
|
||
try
|
||
{
|
||
images.Read(filePath, settings);
|
||
for (int i = 0; i < images.Count; i++)
|
||
{
|
||
MagickImage image = (MagickImage)images[i];
|
||
image.Format = MagickFormat.Jpg;
|
||
var imagename = filePath + "-" + i + ".jpg";
|
||
image.Write(imagename);
|
||
pics.Add(current_domain + XyFile + "-" + i + ".jpg");
|
||
if (i == 0)
|
||
{
|
||
File.WriteAllText(pdfFile.Directory.FullName + "\\lock", "lock");
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
//throw Oops.Oh(ex.Message);
|
||
throw Oops.Oh(-2002, "无附件文件[" + nbzs_domain + XyFile + "]");
|
||
}
|
||
}
|
||
}
|
||
return new { pics, pdf = current_domain + XyFile };
|
||
}
|
||
private readonly IHostingEnvironment _hostingEnvironment;
|
||
private string GetCurrentRootPath()
|
||
{
|
||
return _hostingEnvironment.WebRootPath;
|
||
//return Path.GetDirectoryName(this.GetType().Assembly.Location);
|
||
}
|
||
private string StreamToFile(Stream s, string filename)
|
||
{
|
||
var d = GetCurrentRootPath() + filename;
|
||
FileInfo f = new(d);
|
||
if (!f.Directory.Exists)
|
||
f.Directory.Create();
|
||
using (MemoryStream stmMemory = new MemoryStream())
|
||
{
|
||
byte[] buffer = new byte[s.Length];
|
||
int i;
|
||
//将字节逐个放入到Byte中
|
||
while ((i = s.Read(buffer, 0, buffer.Length)) > 0)
|
||
{
|
||
stmMemory.Write(buffer, 0, i);
|
||
}
|
||
var fileBytes = stmMemory.ToArray();//文件流Byte,需要文件流可直接return,不需要下面的保存代码
|
||
stmMemory.Close();
|
||
using (MemoryStream m = new(fileBytes))
|
||
{
|
||
using (FileStream fs = new(d, FileMode.OpenOrCreate))
|
||
{
|
||
m.WriteTo(fs);
|
||
fs.Close();
|
||
}
|
||
m.Close();
|
||
}
|
||
}
|
||
return d;
|
||
}
|
||
/// <summary>
|
||
/// 分布评估详细
|
||
/// </summary>
|
||
/// <param name="args"></param>
|
||
/// <returns></returns>
|
||
[HttpPost("/house_estimate/info")]
|
||
[Microsoft.AspNetCore.Authorization.AllowAnonymous]
|
||
public dynamic HouseEstimateInfo([FromBody] JObject args)
|
||
{
|
||
var ticket = args.GetJsonValue("ticket", isThrowExp: true);
|
||
var id = args.GetJsonGuidValue("id", isThrowExp: true);
|
||
var type = args.GetJsonIntValue("type", isThrowExp: true);
|
||
JObject userInfoObj = GetInfoByTicket(ticket);
|
||
//var cardno = userInfoObj["idnum"].ToString();
|
||
FHPG jzlrModel = null;
|
||
if (type == 1)
|
||
{
|
||
jzlrModel = db.Ado.SqlQuery<FHPG>("select a.ID,b.HouseAddress,a.ValuationMethod,a.AssessmentNo,a.HousingAssessmentValue,a.countValue,a.AttachedAssessedValue,a.DecorateAssessedValue,a.Remark,a.ExceedLandMoney,a.AtticAssessedValue,1 Type from InvestigateTable_Assessment a inner join InvestigateTable b on a.InvestigateTableID=b.ID where a.IsPublic=1 and a.ID=@ID", new { ID = id }).FirstOrDefault();
|
||
}
|
||
else if (type == 2)
|
||
{
|
||
//非住宅
|
||
jzlrModel = db.Ado.SqlQuery<FHPG>("select b.HouseAddress,a.ValuationMethod,a.AssessmentNo,a.HousingAssessmentValue,a.countValue,a.AttachedAssessedValue,a.DecorateAssessedValue,a.Remark,a.ExceedLandMoney,2 Type from NonInvestigateTable_Assessment a inner join NonResidentialInvestigateTable b on a.NonInvestigateTableID=b.ID where a.IsPublic=1 and a.ID=@ID", new { ID = id }).FirstOrDefault();
|
||
}
|
||
if (jzlrModel == null)
|
||
throw Oops.Oh("ID有误");
|
||
switch (jzlrModel.ValuationMethod)
|
||
{
|
||
case 0:
|
||
jzlrModel.ValuationMethodText = "价值录入";
|
||
break;
|
||
case 1:
|
||
jzlrModel.ValuationMethodText = "普通报告录入";
|
||
break;
|
||
case 2:
|
||
jzlrModel.ValuationMethodText = "自定义报告录入";
|
||
break;
|
||
}
|
||
//if (jzlrModel.ValuationMethod == 0)
|
||
//{
|
||
//return jzlrModel;
|
||
//}
|
||
//else
|
||
//{
|
||
return GetHouseEstimateFile(jzlrModel);
|
||
//}
|
||
}
|
||
private dynamic GetHouseEstimateFile(FHPG jzlrModel)
|
||
{
|
||
var fileUrl = "";
|
||
if (jzlrModel.Type == 1)
|
||
{
|
||
//住宅
|
||
var entity_zz = db.Queryable<InvestigateTable_Assessment>().Where(p => p.ID == Guid.Parse(jzlrModel.Id)).Select(p => new { p.ID, p.AssementFile }).First();
|
||
if (entity_zz != null)
|
||
{
|
||
fileUrl = entity_zz.AssementFile;
|
||
}
|
||
}
|
||
else if (jzlrModel.Type == 2)
|
||
{
|
||
//非住宅
|
||
var entity_fzz = db.Queryable<NonInvestigateTable_Assessment>().Where(p => p.ID == Guid.Parse(jzlrModel.Id)).Select(p => new { p.ID, p.AssementFile }).First();
|
||
if (entity_fzz != null)
|
||
{
|
||
fileUrl = entity_fzz.AssementFile;
|
||
}
|
||
}
|
||
if (string.IsNullOrEmpty(fileUrl))
|
||
//throw Oops.Oh("未评估或未上传附件");
|
||
jzlrModel.IsExistPdf = false;
|
||
else
|
||
{
|
||
var pics = new List<string>();
|
||
var nbzs_file_path = App.Configuration["nbzs_file_path"];
|
||
var nbzs_domain = App.Configuration["nbzs_domain"];
|
||
var filePath = nbzs_file_path + fileUrl;
|
||
var pdfFile = new FileInfo(filePath);
|
||
if (!pdfFile.Exists)
|
||
jzlrModel.IsExistPdf = false;
|
||
else
|
||
{
|
||
if (File.Exists(pdfFile.Directory + "\\lock"))
|
||
{
|
||
var picCount = pdfFile.Directory.GetFiles(pdfFile.Name + "-*.jpg").Length;
|
||
for (int i = 0; i < picCount; i++)
|
||
{
|
||
pics.Add(nbzs_domain + fileUrl + "-" + i + ".jpg");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
MagickReadSettings settings = new MagickReadSettings();
|
||
settings.Density = new Density(400, 400); //设置质量
|
||
using (MagickImageCollection images = new MagickImageCollection())
|
||
{
|
||
try
|
||
{
|
||
images.Read(filePath, settings);
|
||
for (int i = 0; i < images.Count; i++)
|
||
{
|
||
MagickImage image = (MagickImage)images[i];
|
||
image.Format = MagickFormat.Jpg;
|
||
var imagename = filePath + "-" + i + ".jpg";
|
||
image.Write(imagename);
|
||
pics.Add(nbzs_domain + fileUrl + "-" + i + ".jpg");
|
||
if (i == 0)
|
||
{
|
||
File.WriteAllText(pdfFile.Directory.FullName + "\\lock", "lock");
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw Oops.Oh(ex.Message);
|
||
}
|
||
}
|
||
}
|
||
//return new { ValuationMethod, ValuationMethodText, pics, pdf = nbzs_domain + fileUrl };
|
||
jzlrModel.Pdf = nbzs_domain + fileUrl;
|
||
jzlrModel.Pics = pics.ToArray();
|
||
jzlrModel.IsExistPdf = true;
|
||
}
|
||
}
|
||
return jzlrModel;
|
||
}
|
||
|
||
}
|
||
}
|