185 lines
7.4 KiB
C#
185 lines
7.4 KiB
C#
using DocumentFormat.OpenXml.Spreadsheet;
|
|
using DocumentFormat.OpenXml.Wordprocessing;
|
|
using Infrastructure;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.Formatters;
|
|
using Newtonsoft.Json;
|
|
using OpenAuth.App.BaseApp.Base;
|
|
using OpenAuth.App.Const;
|
|
using OpenAuth.App.Interface;
|
|
using OpenAuth.App.ServiceApp.FireManagement.Response;
|
|
using OpenAuth.Repository;
|
|
using OpenAuth.Repository.Domain;
|
|
using OpenAuth.Repository.Domain.FireManagement;
|
|
using SqlSugar;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Net.Http.Headers;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Yitter.IdGenerator;
|
|
|
|
namespace OpenAuth.App.ServiceApp.FireManagement
|
|
{
|
|
public class FireCodeH5App : SqlSugarBaseApp<FmSiteInfo, SugarDbContext>
|
|
{
|
|
public FireCodeH5App(ISugarUnitOfWork<SugarDbContext> unitWork,
|
|
ISimpleClient<FmSiteInfo> repository, IAuth auth) : base(unitWork, repository, auth)
|
|
{
|
|
_auth = auth;
|
|
}
|
|
public async Task<Response<bool>> AddEnteringInfo(FmEnteringInfo info)
|
|
{
|
|
using (SugarDbContext db = base.UnitWork.CreateContext())
|
|
{
|
|
info.Id = YitIdHelper.NextId();
|
|
info.InTime = info.InTime.Year == 0001 ? DateTime.Now : info.InTime;
|
|
if (info.RegistrationType == 0)
|
|
info.RegistrationType = 1;
|
|
//出山登记,修改进山登记时的出山时间
|
|
if (info.RegistrationType == 2)
|
|
{
|
|
var oldinfo = await db.FmEnteringInfo.AsQueryable().Where(r => r.Phone == info.Phone).OrderByDescending(r => r.InTime).FirstAsync();
|
|
if (oldinfo != null)
|
|
{
|
|
oldinfo.OutTime = DateTime.Now;
|
|
await db.FmEnteringInfo.UpdateAsync(oldinfo);
|
|
info.InTime = oldinfo.InTime;
|
|
info.OutTime = DateTime.Now;
|
|
await db.FmEnteringInfo.InsertAsync(info);
|
|
}
|
|
else
|
|
{
|
|
info.OutTime = DateTime.Now;
|
|
await db.FmEnteringInfo.InsertAsync(info);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
await db.FmEnteringInfo.InsertAsync(info);
|
|
}
|
|
if (db.Commit())
|
|
{
|
|
return new Response<bool> { Result = true, Message = "操作成功" };
|
|
}
|
|
else
|
|
{
|
|
return new Response<bool> { Result = false, Message = "操作失败" };
|
|
}
|
|
}
|
|
}
|
|
public async Task<Response<PageInfo<List<dynamic>>>> LoadNameInfoByPhone(string phone, int pageIndex, int pageSize)
|
|
{
|
|
using (SugarDbContext db = base.UnitWork.CreateContext())
|
|
{
|
|
RefAsync<int> totalNumber = 0;
|
|
var query = await db.FmEnteringInfo.AsQueryable()
|
|
.Where(r => r.Phone == phone)
|
|
.Select<dynamic>(r => new
|
|
{
|
|
r.UserName,
|
|
r.Phone,
|
|
r.UserAddress,
|
|
r.CardNo
|
|
}).ToPageListAsync(pageIndex, pageSize, totalNumber);
|
|
return new Response<PageInfo<List<dynamic>>>
|
|
{
|
|
Result = new PageInfo<List<dynamic>> { Items = query, Total = totalNumber }
|
|
};
|
|
}
|
|
}
|
|
|
|
public async Task<Response<dynamic>> GetSiteInfo(long siteId)
|
|
{
|
|
using (SugarDbContext db = base.UnitWork.CreateContext())
|
|
{
|
|
RefAsync<int> totalNumber = 0;
|
|
var info = await db.FmSiteInfo.AsQueryable()
|
|
.Where(r => r.Id == siteId).Select<dynamic>(r => new
|
|
{
|
|
Id = r.Id.SelectAll(),
|
|
Accumulate = SqlFunc.Subqueryable<FmEnteringInfo>().Where(b => b.SiteId == r.Id).Count(),
|
|
}).FirstAsync();
|
|
var userinfo = await db.FmSiteUser.AsQueryable()
|
|
.LeftJoin<SysUser>((a, b) => a.SiteUserId == b.Id).Select<dynamic>((a, b) => new
|
|
{
|
|
Id = a.Id,
|
|
SiteUserId = a.SiteUserId,
|
|
SiteId = a.SiteId,
|
|
UserRole = a.UserRole,
|
|
Name = b.Name,
|
|
Phone = b.Account
|
|
}).ToListAsync();
|
|
info.SiteUser = userinfo;
|
|
return new Response<dynamic>
|
|
{
|
|
Result = info
|
|
};
|
|
}
|
|
}
|
|
public async Task GetFireInfoAsync()
|
|
{
|
|
using (var client = new HttpClient())
|
|
{
|
|
string url = "http://221.2.83.254:9001/api/YingJiJu/LoadInfo?pageIndex=1&pageSize=10";
|
|
|
|
client.DefaultRequestHeaders.Accept.Add(
|
|
new MediaTypeWithQualityHeaderValue("text/plain"));
|
|
try
|
|
{
|
|
// 发起 GET 请求
|
|
HttpResponseMessage response = await client.GetAsync(url);
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
string content = await response.Content.ReadAsStringAsync();
|
|
// 先反序列化为 JObject 以方便访问嵌套属性
|
|
var root = Newtonsoft.Json.Linq.JObject.Parse(content);
|
|
|
|
// 判断返回码
|
|
if (root["code"]?.ToString() != "200")
|
|
{
|
|
return;
|
|
}
|
|
// 解析 data 数组
|
|
var dataArray = root["data"]?.ToObject<List<YingJiJuResp>>();
|
|
if (dataArray == null || dataArray.Count == 0)
|
|
{
|
|
return;
|
|
}
|
|
List<FmFireclueInfo> fireInfo = new List<FmFireclueInfo>();
|
|
foreach (var item in dataArray)
|
|
{
|
|
fireInfo.Add(new FmFireclueInfo
|
|
{
|
|
Id = item.details_id,
|
|
ReportPerson = "",
|
|
ReportTime = item.start_time,
|
|
Describe = item.detailed_address,
|
|
Address = item.detailed_address,
|
|
Lng = item.longitude.ToString(),
|
|
Lat = item.latitude.ToString(),
|
|
SourceType = (int)SourceType.高空瞭望,
|
|
State = item.state,
|
|
AreaName = item.county,
|
|
DegreeType = 3,
|
|
Image = item.images_path
|
|
});
|
|
}
|
|
|
|
using (SugarDbContext db = base.UnitWork.CreateContext())
|
|
{
|
|
await db.FmFireclueInfo.InsertOrUpdateAsync(fireInfo);
|
|
db.Commit();
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|