using HH.WMS.BLL;
|
using HH.WMS.BLL.Basic;
|
using HH.WMS.Common;
|
using HH.WMS.Entitys;
|
using HH.WMS.Entitys.Basic;
|
using HH.WMS.Utils;
|
using HH.WMS.WebApi.Areas.Common.Controllers;
|
using Newtonsoft.Json;
|
using System;
|
using System.Collections.Generic;
|
using System.IO;
|
using System.Linq;
|
using System.Net;
|
using System.Net.Http;
|
using System.Net.Http.Headers;
|
using System.Web;
|
using System.Web.Http;
|
|
namespace HH.WMS.WebApi.Areas.Basic
|
{
|
/// <summary>
|
/// 打印模板控制器
|
/// </summary>
|
public class PrintTempletController : BaseController
|
{
|
#region 获取打印模板
|
/// <summary>
|
/// 获取打印模板
|
/// </summary>
|
/// <param name="mac">mac地址</param>
|
/// <returns></returns>
|
/// <History>[Hanhe(DBS)] created 2018/12/1</History>
|
public OperateResult GetPrintTemplet(string mac)
|
{
|
return ValidateToken(k =>
|
{
|
List<TN_WM_PRINT_TEMPLETEntity> list = BLLCreator.Create<TN_WM_PRINT_TEMPLETBLL>().GetAllowOperationList(mac);
|
|
list.FindAll(x=>x.CN_S_MAC!=mac && x.CN_C_IS_TOOL_PRINT=="Y").ForEach(x=>{
|
x.CN_S_PRINTER = "";
|
});
|
List<string> templetNames = list.GroupBy(x => x.CN_S_TEMPLET_NAME).Select(x=>x.Key).ToList();
|
|
foreach (string s in templetNames)
|
{
|
//存在多个模板名相同的模板
|
if (list.FindAll(x => x.CN_S_TEMPLET_NAME.Equals(s)).Count > 1)
|
{
|
list.RemoveAll(x => x.CN_C_IS_FIRST.Equals("Y") && x.CN_S_TEMPLET_NAME == s);
|
}
|
}
|
return OperateResult.Succeed("", list);
|
});
|
}
|
#endregion
|
|
#region 查询打印任务
|
/// <summary>
|
/// 查询打印任务
|
/// </summary>
|
/// <param name="mac">机器MAC地址</param>
|
/// <param name="isHistory">是否查询已打印记录(Y/N)</param>
|
/// <param name="key">模糊搜索的打印任务</param>
|
/// <param name="startDate">开始时间</param>
|
/// <param name="endDate">结束时间</param>
|
/// <returns></returns>
|
/// <History>[Hanhe(DBS)] created 2018/12/12</History>
|
public OperateResult GetPrintTask(string mac, string isHistory, string key, string startDate, string endDate)
|
{
|
return ValidateToken(m =>
|
{
|
List<TN_WM_PRINT_TASKEntity> list = BLLCreator.Create<TN_WM_PRINT_TASKBLL>().GetList(mac,isHistory,key,startDate,endDate);
|
|
return OperateResult.Succeed("", list);
|
});
|
}
|
#endregion
|
|
//#region 保存打印模板
|
///// <summary>
|
///// 保存打印模板
|
///// </summary>
|
///// <param name="list">打印模板接口</param>
|
///// <returns></returns>
|
///// <History>[Hanhe(DBS)] created 2018/12/11</History>
|
//[HttpPost]
|
//public OperateResult Save(List<TN_WM_PRINT_TEMPLETEntity> list)
|
//{
|
// return ValidateToken(list[0].TokenId, m =>
|
// {
|
// OperateResult result = BLLCreator.Create<TN_WM_PRINT_TEMPLETBLL>().Save(list);
|
// return OperateResult.Succeed("", result);
|
// });
|
//}
|
//#endregion
|
|
#region 更新打印任务标识
|
/// <summary>
|
/// 更新打印任务标识
|
/// </summary>
|
/// <param name="guids">打印任务guid,多个用逗号隔开</param>
|
/// <returns></returns>
|
/// <History>[Hanhe(DBS)] created 2018/12/12</History>
|
[HttpGet]
|
public OperateResult UpdatePrintFlag(string guids)
|
{
|
return ValidateToken(m =>
|
{
|
return BLLCreator.Create<TN_WM_PRINT_TEMPLETBLL>().UpdatePrintFlag(guids);
|
});
|
}
|
#endregion
|
|
#region 创建模板
|
/// <summary>
|
/// 创建模板
|
/// </summary>
|
/// <param name="mac">mac地址</param>
|
/// <param name="stockCode">仓库号</param>
|
/// <param name="type">模板类型</param>
|
/// <param name="name">模板名称</param>
|
/// <returns></returns>
|
/// <History>[Hanhe(DBS)] created 2018/12/1</History>
|
[HttpGet]
|
public OperateResult CreateTemplet(string mac,string ip, string stockCode, string type, string name)
|
{
|
return ValidateToken(m =>
|
{
|
TN_WM_PRINT_TEMPLETEntity model = new TN_WM_PRINT_TEMPLETEntity()
|
{
|
CN_S_MAC = mac,
|
CN_S_STOCK_CODE = stockCode,
|
CN_S_PRINTER = "",
|
CN_S_TEMPLET_NAME = name,
|
CN_S_TEMPLET_TYPE = type,
|
CN_S_IP = ip,
|
CN_GUID = Guid.NewGuid().ToString(),
|
CN_C_IS_UPLOADED = "N",
|
//CN_S_UPLOADOR = m.CN_S_NAME,
|
CN_T_UPLOAD_TIME = DateTime.Now,
|
CN_C_IS_FIRST="Y"
|
};
|
if (type.Equals("物料标签") || type.Equals("装箱标签"))
|
model.CN_C_IS_TOOL_PRINT = "Y";
|
else
|
model.CN_C_IS_TOOL_PRINT = "N";
|
|
|
return BLLCreator.Create<DapperBLL<TN_WM_PRINT_TEMPLETEntity>>().Add(model);
|
});
|
}
|
#endregion
|
|
#region 更新文件名
|
/// <summary>
|
/// 更新文件名
|
/// </summary>
|
/// <param name="guid">guid</param>
|
/// <param name="fileName">模板文件名</param>
|
/// <returns></returns>
|
/// <History>[Hanhe(DBS)] created 2018/12/1</History>
|
[HttpGet]
|
public OperateResult UpdateTempletName(string guid, string fileName)
|
{
|
return ValidateToken(m =>
|
{
|
return BLLCreator.Create<DapperBLL<TN_WM_PRINT_TEMPLETEntity>>().Update(new { CN_S_TEMPLET_NAME = fileName }, new { CN_GUID = guid });
|
});
|
}
|
#endregion
|
|
#region 更新模板打印机
|
/// <summary>
|
/// 更新模板打印机
|
/// </summary>
|
/// <param name="guid">guid</param>
|
/// <param name="printer">打印机</param>
|
/// <returns></returns>
|
/// <History>[Hanhe(lt)] created 2018/12/28</History>
|
/// <History>[Hanhe(dbs)] created 2019/3/6</History>
|
public OperateResult UpdateTempletPrinter(TN_WM_PRINT_TEMPLETEntity model)
|
{
|
return ValidateToken(model.TokenId,m =>
|
{
|
return BLLCreator.Create<DapperBLL<TN_WM_PRINT_TEMPLETEntity>>().Update(new { CN_S_TEMPLET_NAME = model.CN_S_TEMPLET_NAME }, new { CN_GUID = model.CN_GUID });
|
});
|
}
|
public OperateResult CreateTempletPrinter(TN_WM_PRINT_TEMPLETEntity model)
|
{
|
TN_WM_PRINT_TEMPLETEntity templet = BLLCreator.Create<DapperBLL<TN_WM_PRINT_TEMPLETEntity>>().GetSingleEntity(new { CN_GUID = model.CN_GUID });
|
templet.CN_S_MAC = model.CN_S_MAC;
|
templet.CN_GUID = Guid.NewGuid().ToString();
|
templet.CN_T_UPLOAD_TIME = DateTime.Now;
|
templet.CN_C_IS_FIRST = "N";
|
return ValidateToken(model.TokenId, m =>
|
{
|
return BLLCreator.Create<DapperBLL<TN_WM_PRINT_TEMPLETEntity>>().Add(templet);
|
});
|
}
|
#endregion
|
|
#region 删除模板
|
/// <summary>
|
/// 删除模板
|
/// </summary>
|
/// <param name="guid">guid</param>
|
/// <returns></returns>
|
/// <History>[Hanhe(DBS)] created 2018/12/1</History>
|
[HttpGet]
|
public OperateResult DeleteTemplet(string guid)
|
{
|
return ValidateToken(m =>
|
{
|
return BLLCreator.Create<DapperBLL<TN_WM_PRINT_TEMPLETEntity>>().Delete(new { CN_GUID = guid });
|
});
|
}
|
#endregion
|
|
#region 查询打印模版
|
/// <summary>
|
/// 查询打印模版
|
/// </summary>
|
/// <param name="type">模版类型</param>
|
/// <returns></returns>
|
/// <History>[Hanhe(lt)] created 2018/12/28</History>
|
public OperateResult GetPrintTempletByType(string type)
|
{
|
return ValidateToken(m =>
|
{
|
List<TN_WM_PRINT_TEMPLETEntity> list = BLLCreator.Create<DapperBLL<TN_WM_PRINT_TEMPLETEntity>>().GetList(
|
new { CN_S_TEMPLET_TYPE = type }).GroupBy(x => new
|
{
|
CN_S_TEMPLET_NAME = x.CN_S_TEMPLET_NAME
|
}).Select(y => new TN_WM_PRINT_TEMPLETEntity() { CN_S_TEMPLET_NAME = y.Key.CN_S_TEMPLET_NAME}).ToList();
|
|
return OperateResult.Succeed("", list);
|
});
|
}
|
#endregion
|
|
#region 模板上传
|
[HttpPost]
|
public string UploadTemplet([FromBody] dynamic res)
|
{
|
try
|
{
|
string tokenId = res.tokenId.ToString();
|
return ValidateToken(tokenId ,m =>
|
{
|
string savePath = Constants.SysConfig.UI_ROOT_PATH.Replace('*','\\') + @"\ActiveReport\Template";
|
|
string fileName = res.fileName.ToString();
|
string guid = res.guid.ToString();
|
var filePath = string.Format(@"{0}\{1}", savePath, fileName);
|
if (File.Exists(filePath))
|
{
|
////服务器中已存在该模板,则找该模板的最新版本号
|
//List<TN_WM_PRINT_TEMPLETEntity> temps = BLLCreator.Create<DapperBLL<TN_WM_PRINT_TEMPLETEntity>>().GetList(new { CN_S_TEMPLET_NAME = fileName }).OrderByDescending(x=>x.CN_N_VERSION).ToList();
|
//if (temps.Count > 0)
|
//{
|
//}
|
if (File.Exists(filePath))
|
{
|
File.Delete(filePath);
|
}
|
}
|
FileUtils.SaveFile((byte[])res.file, savePath, res.fileName.ToString());
|
OperateResult or = BLLCreator.Create<DapperBLL<TN_WM_PRINT_TEMPLETEntity>>().Update(new { CN_C_IS_UPLOADED = "Y", CN_S_UPLOADOR = m.CN_S_NAME, CN_T_UPLOAD_TIME = DateTime.Now }, new { CN_S_TEMPLET_NAME = fileName,CN_C_IS_FIRST="Y" });
|
|
return JsonConvert.SerializeObject(or);
|
});
|
}
|
catch (Exception ex)
|
{
|
return JsonConvert.SerializeObject(OperateResult.Error(ex.Message));
|
}
|
}
|
#endregion
|
|
#region 下载文件
|
/// <summary>
|
/// 下载文件
|
/// </summary>
|
/// <param name="fileName">文件名</param>
|
/// <returns></returns>
|
[HttpGet]
|
public HttpResponseMessage DownLoadTemplet(string fileName)
|
{
|
FileStream stream=null;
|
try
|
{
|
string filePath = Constants.SysConfig.UI_ROOT_PATH.Replace('*', '\\') + @"\ActiveReport\Template\" + fileName;
|
if (!File.Exists(filePath))
|
{
|
return new HttpResponseMessage();
|
}
|
stream = new FileStream(filePath, FileMode.Open);
|
HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
|
response.Content = new StreamContent(stream);
|
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
|
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
|
{
|
FileName = HttpUtility.UrlEncode(fileName)
|
};
|
response.Headers.Add("Access-Control-Expose-Headers", "FileName");
|
response.Headers.Add("FileName", HttpUtility.UrlEncode(fileName));
|
return response;
|
}
|
catch (Exception ex)
|
{
|
if (stream != null)
|
{
|
stream.Close();
|
stream.Dispose();
|
}
|
}
|
return new HttpResponseMessage();
|
}
|
#endregion
|
}
|
}
|