软测单独项目
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.
 
 
 
 
 
 

136 lines
5.2 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;
namespace FangYar.WebUI.Handle
{
/// <summary>
/// VISHIA 的摘要说明 石河子消防支队 添加访客登记
/// </summary>
public class VISHIA : IHttpHandler
{
FangYar.BLL.OA.TBL_VISITOR_REG vis_bll = new FangYar.BLL.OA.TBL_VISITOR_REG();
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("进入!");
int code = -1;
string msg = "申请失败";
HttpRequest request = context.Request;
Stream stream = request.InputStream;
string data = string.Empty;
if (stream.Length != 0)
{
try
{
StreamReader streamReader = new StreamReader(stream);
data = streamReader.ReadToEnd();
WriteLog(data.ToString());
string redata_string = data.Replace(Environment.NewLine, "");
FangYar.Model.RZ_DATA rz_data = JsonConvert.DeserializeObject<FangYar.Model.RZ_DATA>(redata_string);
string avatar = rz_data.avatar.Replace("\u003d", "=");
byte[] avatar_byte = Convert.FromBase64String(avatar);
string ImagePath = GetFilePath(avatar_byte);
rz_data.imagePath = ImagePath;
if (vis_bll.RzData_Add(rz_data))
{
FangYar.BLL.TBL.SysUsersBLL ubll = new BLL.TBL.SysUsersBLL();
string hostId = rz_data.hostId;//被访问人员ID
Model.TBL.TBL_SYS_USERS_Model usersModel = ubll.CheckLoginByUserID(hostId);
//HardWareInteface.MessageService.CwsClient cws = new HardWareInteface.MessageService.CwsClient();
//cws.yqMessageSend(usersModel.USERS_MOBILE, usersModel.USERS_NAME, "访客", "待审批");
msg = "success!";
code = 200;
}
}
catch (Exception e)
{
msg = "catch异常:" + e.Message;
}
}
else
{
code = -2;
msg = "申请失败,数据为空";
}
return "{\"code\":\"" + code + "\",\"msg\":\"" + msg + "\"}";
}
/// <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" + "/VisitorReg/" + 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 = "VISHIA" });
//string path = AppDomain.CurrentDomain.BaseDirectory + "log\\VISHIA\\";
//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;
}
}
}
}