You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
169 lines
6.3 KiB
169 lines
6.3 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Reflection;
|
|
using System.Collections;
|
|
using System.IO;
|
|
using System.Text;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using System.Configuration;
|
|
|
|
namespace FangYar.WebUI.Handle
|
|
{
|
|
/// <summary>
|
|
/// AKSKPDDPersonRec 的摘要说明 阿克苏柯坪大队
|
|
/// </summary>
|
|
public class AKSKPDDPersonRec : IHttpHandler
|
|
{
|
|
|
|
FangYar.BLL.TBL_PERSONACCESS bll = new FangYar.BLL.TBL_PERSONACCESS();
|
|
FangYar.BLL.TBL_VISITOR vis_bll = new FangYar.BLL.TBL_VISITOR();
|
|
|
|
public void ProcessRequest(HttpContext context)
|
|
{
|
|
context.Response.ContentType = "text/plain";
|
|
string returnStr = "";
|
|
|
|
returnStr = ReceiveAlarmInfoPlate(context);
|
|
context.Response.Write(returnStr);
|
|
}
|
|
private string ReceiveAlarmInfoPlate(HttpContext context)
|
|
{
|
|
WriteLog("进入!");
|
|
HttpRequest request = context.Request;
|
|
Stream stream = request.InputStream;
|
|
string data = string.Empty;
|
|
string response = string.Empty;
|
|
bool isadd = false;
|
|
if (stream.Length != 0)
|
|
{
|
|
try
|
|
{
|
|
StreamReader streamReader = new StreamReader(stream);
|
|
data = streamReader.ReadToEnd();
|
|
#region 用于传递数据的输出
|
|
|
|
if (stream.Length != 0)
|
|
{
|
|
WriteLog(data.ToString());
|
|
}
|
|
#endregion
|
|
string redata_string = data.Replace(Environment.NewLine, "");
|
|
string redata_string_json = "[";
|
|
if (redata_string.Contains("} {"))
|
|
{
|
|
redata_string = redata_string.Replace("} {", "},{");
|
|
}
|
|
else if (redata_string.Contains("}{"))
|
|
{
|
|
redata_string = redata_string.Replace("}{", "},{");
|
|
}
|
|
redata_string_json += redata_string;
|
|
redata_string_json += "]";
|
|
|
|
bool flag = false;
|
|
try
|
|
{
|
|
JArray jsonStr = JsonConvert.DeserializeObject<JArray>(redata_string_json);
|
|
flag = true;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
flag = false;
|
|
}
|
|
if (flag)
|
|
{
|
|
List<FangYar.Model.MJ_DATA> rz_data = JsonConvert.DeserializeObject<List<FangYar.Model.MJ_DATA>>(redata_string_json);
|
|
for (int i = 0; i < rz_data.Count; i++)
|
|
{
|
|
string avatar = rz_data[i].avatar.Replace("\u003d", "=");
|
|
byte[] avatar_byte = Convert.FromBase64String(avatar);
|
|
string ImagePath = GetFilePath(avatar_byte);
|
|
rz_data[i].imagePath = ImagePath;
|
|
rz_data[i].orgId = "35B405471BCD45D89469E0E308A24A7D";
|
|
isadd = bll.MjData_Add(rz_data[i]);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
WriteLog("\r\n 数据有误: 字符串不是json格式");
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
WriteLog(e.Message);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
WriteLog("输入流的长度为0!");
|
|
}
|
|
|
|
if (isadd == true)
|
|
{
|
|
return "true";
|
|
}
|
|
else
|
|
{
|
|
return "false";
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// base转图片保存到服务器
|
|
/// </summary>
|
|
/// <param name="msg"></param>
|
|
private string GetFilePath(byte[] bytes)
|
|
{
|
|
string fileName = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString();//年月
|
|
string ImageFilePath = "/Attachment" + "/Person/akskpdd/" + DateTime.Now.Year.ToString() + "/"+DateTime.Now.Month.ToString();
|
|
if (System.IO.Directory.Exists(HttpContext.Current.Server.MapPath(ImageFilePath)) == false)//如果不存在就创建文件夹
|
|
{
|
|
System.IO.Directory.CreateDirectory(HttpContext.Current.Server.MapPath(ImageFilePath));
|
|
}
|
|
string ImagePath;
|
|
//string str = System.DateTime.Now.ToString("yyyyHHddHHmmss");
|
|
string str = System.DateTime.Now.ToString("yyyyHHddHHmmssfff") + Guid.NewGuid().ToString();
|
|
ImagePath = HttpContext.Current.Server.MapPath(ImageFilePath) + "/" + str;//定义图片名称
|
|
File.WriteAllBytes(ImagePath + ".png", bytes); //保存图片到服务器,然后获取路径
|
|
return ImageFilePath + "/" + str + ".png";//获取保存后的路径
|
|
|
|
}
|
|
|
|
private void WriteLog(string msg)
|
|
{
|
|
FangYar.Common.MyLogHelper.WriteMsg(new FangYar.Common.LogInfoMo() { message = msg, msgType = FangYar.Common.EnumLogMsgTypeEnum.Error, path = "AKSKPDDperson" });
|
|
//string path = AppDomain.CurrentDomain.BaseDirectory + "log\\AKSKPDDperson\\";
|
|
//string filename = DateTime.Now.ToString("yyyyMMdd") + ".txt";
|
|
|
|
//if (Directory.Exists(path) == false)//如果不存在就创建文件夹
|
|
//{
|
|
// Directory.CreateDirectory(path);
|
|
//}
|
|
//FileInfo file = new FileInfo(path + filename);
|
|
//if (!file.Exists)
|
|
//{
|
|
// FileStream fs;
|
|
// fs = File.Create(path + filename);
|
|
// fs.Close();
|
|
//}
|
|
|
|
//using (FileStream fs = new FileStream(path + filename, FileMode.Append, FileAccess.Write))
|
|
//{
|
|
// using (StreamWriter sw = new StreamWriter(fs))
|
|
// {
|
|
// sw.WriteLine("时间:" + DateTime.Now.ToString() + " 信息:" + msg);
|
|
// }
|
|
//}
|
|
}
|
|
public bool IsReusable
|
|
{
|
|
get
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|