169 lines
6.5 KiB
C#
169 lines
6.5 KiB
C#
using Ninject;
|
||
using System;
|
||
using System.Configuration;
|
||
using System.Runtime.Serialization;
|
||
using System.ServiceModel;
|
||
using System.ServiceModel.Web;
|
||
using System.Threading.Tasks;
|
||
using WX.CRM.Common;
|
||
using WX.CRM.DAL.Redis;
|
||
using WX.CRM.IBLL.WeWork;
|
||
using WX.CRM.WebHelper.Infrastructure;
|
||
|
||
namespace WxService
|
||
{
|
||
|
||
public class WeWorkFilePath : IWeWorkFilePath
|
||
{
|
||
private IWeWork_MsgKey wework_msgkey = NinjectControllerFactory.ninjectKernel.Get<IWeWork_MsgKey>();
|
||
public async Task<JsonResult<string>> GetPath(string keymd5)
|
||
{
|
||
try
|
||
{
|
||
var host = ConfigurationManager.AppSettings["fileHost"] ?? "http://192.168.1.45:809";
|
||
string keyname = "weworkfile:" + keymd5;
|
||
RedisString<string> redis = new RedisString<string>(keyname);
|
||
var filePath = await redis.GetAsync();
|
||
if (string.IsNullOrEmpty(filePath))
|
||
{
|
||
filePath = wework_msgkey.GetFile(keyname);//如果redis查找不到,就从数据库中查找一次
|
||
}
|
||
if (string.IsNullOrEmpty(filePath))
|
||
return new JsonResult<string>() { result = true, retcode = 100, retmsg = filePath };
|
||
return new JsonResult<string>() { result = true, retcode = 200, retmsg = "" + keymd5 + "_" + host + filePath };
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Error(ex.ToString());
|
||
return new JsonResult<string>() { result = false, retcode = 50, retmsg = "系统错误" };
|
||
}
|
||
}
|
||
|
||
public async Task<JsonResult<string>> Get(string keymd5)
|
||
{
|
||
try
|
||
{
|
||
string keyname = "weworkfile:" + keymd5;
|
||
RedisString<string> redis = new RedisString<string>(keyname);
|
||
var ret = await redis.GetAsync();
|
||
if (string.IsNullOrEmpty(ret))
|
||
{
|
||
ret = wework_msgkey.GetFile(keyname);//如果redis查找不到,就从数据库中查找一次
|
||
}
|
||
if (string.IsNullOrEmpty(ret))
|
||
{
|
||
return new JsonResult<string>() { result = true, retcode = 100, retmsg = keymd5 };
|
||
}
|
||
//PushRedis(msgSvrId, fileName);//先去除
|
||
return new JsonResult<string>() { result = true, retcode = 200, retmsg = keymd5 };
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Error(ex.ToString());
|
||
return new JsonResult<string>() { result = false, retcode = 50, retmsg = "系统错误" };
|
||
}
|
||
}
|
||
|
||
public async Task<WeWorkPathsonResult> DoubleSearch(string maxmd5, string smallmd5)
|
||
{
|
||
try
|
||
{
|
||
var host = ConfigurationManager.AppSettings["fileHost"] ?? "http://192.168.1.45:809";
|
||
if (string.IsNullOrEmpty(maxmd5) || maxmd5 == "-1")
|
||
{
|
||
return new WeWorkPathsonResult() { result = false, retcode = 50, retmsg = "文件key不能为空", maxMd5 = maxmd5, smallMd5 = smallmd5 };
|
||
}
|
||
string maxkeyname = "weworkfile:" + maxmd5;
|
||
RedisString<string> maxredis = new RedisString<string>(maxkeyname);
|
||
var maxPath = await maxredis.GetAsync();
|
||
if (string.IsNullOrWhiteSpace(maxPath))
|
||
{
|
||
maxPath = wework_msgkey.GetFile(maxkeyname);//如果redis查找不到,就从数据库中查找一次
|
||
}
|
||
|
||
if (!string.IsNullOrWhiteSpace(maxPath))
|
||
{
|
||
maxPath = host + maxPath;
|
||
}
|
||
else
|
||
{
|
||
maxPath = null;
|
||
}
|
||
string smallpath = null;
|
||
if (smallmd5 != "-1")
|
||
{
|
||
string smallkeyname = "weworkfile:" + smallmd5;
|
||
RedisString<string> smallredis = new RedisString<string>(smallkeyname);
|
||
smallpath = await smallredis.GetAsync();
|
||
if (string.IsNullOrWhiteSpace(smallpath))
|
||
{
|
||
smallpath = wework_msgkey.GetFile(smallkeyname);//如果redis查找不到,就从数据库中查找一次
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(smallpath))
|
||
{
|
||
smallpath = host + smallpath;
|
||
}
|
||
else
|
||
{
|
||
smallpath = null;
|
||
}
|
||
}
|
||
return new WeWorkPathsonResult() { result = true, retcode = 200, retmsg = "文件获取成功", maxMd5 = maxmd5, smallMd5 = smallmd5, maxPath = maxPath, smallPath = smallpath };
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Error(ex.ToString());
|
||
return new WeWorkPathsonResult() { result = false, retcode = 50, retmsg = "系统错误", maxMd5 = maxmd5, smallMd5 = smallmd5 };
|
||
}
|
||
}
|
||
|
||
}
|
||
[DataContract]
|
||
public class WeWorkPathsonResult
|
||
{
|
||
[DataMember]
|
||
public bool result { get; set; }
|
||
[DataMember]
|
||
public int retcode { get; set; }
|
||
[DataMember]
|
||
public string retmsg { get; set; }
|
||
|
||
[DataMember]
|
||
public string maxMd5 { get; set; }
|
||
[DataMember]
|
||
public string smallMd5 { get; set; }
|
||
[DataMember]
|
||
public string maxPath { get; set; }
|
||
[DataMember]
|
||
public string smallPath { get; set; }
|
||
}
|
||
|
||
[ServiceContract]
|
||
public interface IWeWorkFilePath
|
||
{
|
||
[OperationContract]
|
||
[WebInvoke(Method = "*",
|
||
//RequestFormat = WebMessageFormat.Json,
|
||
ResponseFormat = WebMessageFormat.Json,
|
||
BodyStyle = WebMessageBodyStyle.Bare,
|
||
UriTemplate = "GetPath/{keymd5}")]
|
||
Task<JsonResult<string>> GetPath(string keymd5);
|
||
|
||
[OperationContract]
|
||
[WebInvoke(Method = "*",
|
||
ResponseFormat = WebMessageFormat.Json,
|
||
BodyStyle = WebMessageBodyStyle.Bare,
|
||
UriTemplate = "Get/{keymd5}")]
|
||
Task<JsonResult<string>> Get(string keymd5);
|
||
|
||
[OperationContract]
|
||
[WebInvoke(Method = "*",
|
||
ResponseFormat = WebMessageFormat.Json,
|
||
BodyStyle = WebMessageBodyStyle.Bare,
|
||
UriTemplate = "Search/{maxmd5}/{smallmd5}")]
|
||
Task<WeWorkPathsonResult> DoubleSearch(string maxmd5, string smallmd5);
|
||
|
||
|
||
}
|
||
}
|