UtilityController.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.IO;
  5. using System.Linq;
  6. using WMS.Core;
  7. using WMS.Util;
  8. using WMS.Info;
  9. using System.Web;
  10. using System.Text;
  11. using WMS.Core.ImportExecl;
  12. using Microsoft.AspNetCore.Mvc;
  13. using WMS.BZWeb;
  14. using System.Net;
  15. using WMS.BZModels;
  16. using WMS.BZServices.HJ;
  17. using WMS.BZUtil;
  18. using WMS.BZServices;
  19. //using FastReport.Web;
  20. //using FastReport;
  21. namespace WMS.BZWeb.Controllers
  22. {
  23. /// <summary>
  24. /// 描 述:通用控制器,处理通用的接口
  25. /// </summary>
  26. //[HandlerLogin(EFilterMode.Ignore)]
  27. public class UtilityController : MvcControllerBase
  28. {
  29. private readonly WarehouseService _warehouseService;
  30. private readonly AnnexesFileService _annexesFileService;
  31. private readonly ImportDataOrExcelService _importDataOrExeclService;
  32. public UtilityController(WarehouseService warehouse, AnnexesFileService annexesFileService, ImportDataOrExcelService importDataOrExeclService)
  33. {
  34. _warehouseService = warehouse;
  35. _annexesFileService = annexesFileService;
  36. _importDataOrExeclService = importDataOrExeclService;
  37. }
  38. AnnexesFileCore AnnexesFile = new AnnexesFileCore();
  39. /// <summary>
  40. /// 图标的选择
  41. /// </summary>
  42. /// <returns></returns>
  43. [HttpGet]
  44. ///[HandlerLogin(EFilterMode.Enforce)]
  45. public ActionResult Icon()
  46. {
  47. return View();
  48. }
  49. /// <summary>
  50. /// 移动图标的选择
  51. /// </summary>
  52. /// <returns></returns>
  53. [HttpGet]
  54. //[HandlerLogin(EFilterMode.Enforce)]
  55. public ActionResult AppIcon()
  56. {
  57. return View();
  58. }
  59. /// <summary>
  60. /// 导入数据
  61. /// </summary>
  62. /// <returns></returns>
  63. [HttpGet]
  64. //[HandlerLogin(EFilterMode.Enforce)]
  65. public ActionResult ImportForm()
  66. {
  67. return View();
  68. }
  69. /// <summary>
  70. /// 请选择要导出的字段页面
  71. /// </summary>
  72. /// <returns></returns>
  73. [HttpGet]
  74. //[HandlerLogin(EFilterMode.Enforce)]
  75. public ActionResult ExcelExportForm()
  76. {
  77. return View();
  78. }
  79. [HttpGet]
  80. public ActionResult ExcelExportColumn()
  81. {
  82. return View();
  83. }
  84. /// <summary>
  85. ///
  86. /// </summary>
  87. /// <returns></returns>
  88. //[HttpGet]
  89. //public ActionResult FastReportIndex(int id)
  90. //{
  91. // FastReport.Web.WebReport webReport = new FastReport.Web.WebReport();
  92. // SetReport(webReport);
  93. // webReport.Width = "1080";
  94. // webReport.Height = "925";
  95. // // webReport.ToolbarIconsStyle = ToolbarIconsStyle.Black;
  96. // // webReport.LocalizationFile = "~/Localization/German.frl";
  97. // webReport.EmbedPictures = true;
  98. // //webReport.XlsxPageBreaks = false;
  99. // // webReport.XlsxSeamless = true;
  100. // // webReport.ZoomMode = ZoomMode.Width;
  101. // //本地化文件 this.Server.MapPath("~/DataFiles/FastReport/") ConfigHelper.GetValue<string>("baseDir")
  102. // webReport.LocalizationFile = ConfigHelper.GetValue<string>("baseDir") + "/wwwroot/DataFiles/FastReport/Localization/Chinese (Simplified).frl";
  103. // //webReport.PrintInPdf = false;
  104. // // fill the parameters on startup
  105. // //webReport.Report.SetParameterValue("Test parameter 1", "Value of parameter 1 from application code");
  106. // //webReport.Report.SetParameterValue("parameter2", "1002");
  107. // ViewBag.WebReport = webReport;
  108. // return View();
  109. //}
  110. //private void SetReport(WebReport webReport)
  111. //{
  112. // string report_path = GetReportPath();
  113. // System.Data.DataSet dataSet = new System.Data.DataSet();
  114. // dataSet.ReadXml(report_path + "nwind.xml");
  115. // webReport.Report.Load(Path.Combine(report_path, "Simple List.frx"));
  116. // webReport.Report.RegisterData(dataSet, "NorthWind");
  117. // //model.WebReport.SinglePage = true;
  118. // webReport.Designer.Path = "/WebReportDesigner/index.html";
  119. // //model.WebReport.Designer.SaveCallBack = "/SaveDesignedReport";
  120. // webReport.Designer.SaveMethod = (string reportID, string filename, string report) =>
  121. // {
  122. // string pathToSave = Path.Combine(report_path, "DesignedReports", filename);
  123. // if (!Directory.Exists(pathToSave))
  124. // Directory.CreateDirectory(Path.GetDirectoryName(pathToSave));
  125. // System.IO.File.WriteAllTextAsync(pathToSave, report);
  126. // return "OK";
  127. // };
  128. // // tab 4
  129. // //Report report4 = new Report();
  130. // //webReport.Report.Load(report_path + "wcsdevices.frx");
  131. // //report4.SetParameterValue("parameter2", "1002");
  132. // //webReport.Report.SetParameterValue("parameter2", "1002");
  133. // //webReport.CurrentTab.Name = "wcsdevices";
  134. // //System.Data.DataSet dataSet = new System.Data.DataSet();
  135. // //dataSet.ReadXml(report_path + "nwind.xml");
  136. // //Report report = new Report();
  137. // //report.RegisterData(dataSet, "NorthWind");
  138. // //report.Load(report_path + "Simple List.frx");
  139. // //report.SetParameterValue("Test parameter 1", "Value of parameter 1 from application code");
  140. // // webReport.CurrentTab.Name = "Simple List";
  141. // // webReport.AddTab(report, "Simple List");
  142. // // tab 2
  143. // //Report report2 = new Report();
  144. // //report2.RegisterData(dataSet, "NorthWind");
  145. // //report2.Load(report_path + "Chart.frx");
  146. // //webReport.AddTab(report2, "Charts");
  147. // // tab 3
  148. // //Report report3 = new Report();
  149. // //report3.RegisterData(dataSet, "NorthWind");
  150. // //report3.Load(report_path + "Master-Detail.frx");
  151. // //webReport.AddTab(report3, "Master-Detail");
  152. // //Report report5 = new Report();
  153. // //report5.Report.Load(report_path + "wcsdevices.frx");
  154. // //report5.SetParameterValue("parameter2", "1003");
  155. // //webReport.Report.SetParameterValue("parameter2", "1003");
  156. // //webReport.AddTab(report5, "wcsdevices5");
  157. //}
  158. private string GetReportPath()
  159. {
  160. // this.Server.MapPath("~/DataFiles/FastReport/");
  161. return ConfigHelper.GetValue<string>("baseDir") +"/wwwroot/DataFiles/FastReport/";
  162. }
  163. [HttpPost ]
  164. public IActionResult ExportExcel(string fileName, string columnJson, string dataJson, string orderJson, string exportField)
  165. {
  166. //设置导出格式
  167. ExcelConfig excelconfig = new ExcelConfig();
  168. excelconfig.Title = WebUtility.UrlDecode(fileName);
  169. excelconfig.TitleFont = "微软雅黑";
  170. excelconfig.TitlePoint = 15;
  171. excelconfig.FileName = WebUtility.UrlDecode(fileName)+DateTime.Now.Ticks + ".xls";
  172. excelconfig.IsAllSizeColumn = true;
  173. excelconfig.ColumnEntity = new List<ColumnModel>();
  174. //表头
  175. List<jfGridModel> columnList = columnJson.ToList<jfGridModel>();
  176. string columns = string.Empty;
  177. //写入Excel表头
  178. Dictionary<string, string> exportFieldMap = new Dictionary<string, string>();
  179. if (!string.IsNullOrEmpty(exportField))
  180. {
  181. string[] exportFields = exportField.Split(',');
  182. foreach (var field in exportFields)
  183. {
  184. if (field == "F_ORDERNOSPLIT")
  185. //columns += "(case when regexp_substr(F_FROMORDERNO,'[^_]+',1,2) is null then F_FROMORDERNO else regexp_substr(F_FROMORDERNO,'[^_]+',1,2) end) F_ORDERNOSPLIT,";
  186. columns += "F_FROMORDERNO F_ORDERNOSPLIT,";
  187. else
  188. columns += field + ",";
  189. if (!exportFieldMap.ContainsKey(field))
  190. {
  191. exportFieldMap.Add(field, "1");
  192. }
  193. }
  194. }
  195. else
  196. {
  197. throw new Exception("没找到表头");
  198. }
  199. columns = columns.Trim(',');
  200. //行数据
  201. DataTable rowData = null;
  202. // 如果表头数据为空,则表示按照表头导出
  203. if (string.IsNullOrEmpty(orderJson))
  204. {
  205. try
  206. {
  207. rowData = dataJson.ToTable();
  208. }
  209. catch (Exception ex)
  210. {
  211. throw;
  212. }
  213. }
  214. else
  215. {
  216. //string keyNo = string.Empty;
  217. //if (orderJson.ToTable().Columns.Contains("F_NOSPLIT"))
  218. // keyNo = "F_NOSPLIT";
  219. //else
  220. // keyNo = "F_NO";
  221. //var orderlist = orderJson.ToTable().AsEnumerable().Select(v => Convert.ToString(v.Field<string>(keyNo))).ToArray();
  222. //rowData = new OrderCore().GetOrderItem(orderlist, columns);
  223. }
  224. foreach (jfGridModel columnModel in columnList)
  225. {
  226. if (exportFieldMap.ContainsKey(columnModel.name) || string.IsNullOrEmpty(exportField))
  227. {
  228. excelconfig.ColumnEntity.Add(new ColumnModel()
  229. {
  230. Column = columnModel.name,
  231. ExcelColumn = columnModel.label,
  232. Alignment = columnModel.align,
  233. });
  234. }
  235. }
  236. // ExcelHelper.ExcelDownload(rowData, excelconfig);
  237. return File(ExcelHelper.ExportMemoryStream(rowData, excelconfig), "application/ms-excel", excelconfig.FileName);
  238. }
  239. /// <summary>
  240. /// 上传附件分片数据
  241. /// </summary>
  242. /// <param name="fileGuid">文件主键</param>
  243. /// <param name="chunk">分片序号</param>
  244. /// <param name="Filedata">文件数据</param>
  245. /// <returns></returns>
  246. [HttpPost]
  247. [ValidateAntiForgeryToken]
  248. //public ActionResult UploadAnnexesFileChunk(string fileGuid, int chunk, int chunks, IFormFile Filedata)
  249. //{
  250. // //没有文件上传,直接返回
  251. // if (Filedata == null || string.IsNullOrEmpty(Filedata.FileName) || Filedata.Length == 0)
  252. // {
  253. // return null;
  254. // }
  255. // AnnexesFile.SaveChunkAnnexes(fileGuid, chunk, Filedata.OpenReadStream());
  256. // return Success("保存成功");
  257. //}
  258. /// <summary>
  259. /// 上传附件分片数据
  260. /// </summary>
  261. /// <param name="fileGuid">文件主键</param>
  262. /// <param name="chunk">分片序号</param>
  263. /// <param name="Filedata">文件数据</param>
  264. /// <returns></returns>
  265. [HttpPost]
  266. public IActionResult UploadAnnexesFileChunk(string fileGuid, int chunk, int chunks)
  267. {
  268. var files = Request.Form.Files;
  269. //没有文件上传,直接返回
  270. if (files[0].Length == 0 || string.IsNullOrEmpty(files[0].FileName))
  271. {
  272. return Fail("没有文件信息");
  273. }
  274. byte[] bytes = new byte[files[0].Length];
  275. MemoryStream ms = new MemoryStream();
  276. files[0].CopyTo(ms);
  277. ms.Flush();
  278. ms.Position = 0;
  279. ms.Read(bytes, 0, bytes.Length);
  280. ms.Close();
  281. ms.Dispose();
  282. // FileHelper.WriteCache(chunk + "_" + fileGuid, bytes);
  283. _annexesFileService.SaveChunkAnnexes(fileGuid, chunk, bytes);
  284. return Success("保存成功");
  285. }
  286. #region 下载文件
  287. /// <summary>
  288. /// 下载文件
  289. /// </summary>
  290. /// <param name="fileId">文件id</param>
  291. /// <returns></returns>
  292. [HttpPost]
  293. [ValidateAntiForgeryToken]
  294. public IActionResult DownSchemeFile(int bustype)
  295. {
  296. return AnnexesFile.DownSchemeFile(bustype);
  297. }
  298. /// <summary>
  299. /// excel文件导入(通用)
  300. /// </summary>
  301. /// <param name="templateId">模板Id</param>
  302. /// <param name="fileId">文件主键</param>
  303. /// <param name="chunks">分片数</param>
  304. /// <param name="ext">文件扩展名</param>
  305. /// <returns></returns>
  306. [HttpPost]
  307. //////[AjaxOnly]
  308. ////[HandlerValidateAntiForgeryToken]
  309. public ActionResult ExecuteImportExcel(string fileId, int ordertype, int chunks, string ext) // EOrderType
  310. {
  311. try
  312. {
  313. JsonExecl json = null;
  314. LoginUserInfo LoginUser = GetLoginUser();
  315. DataTable dt = _annexesFileService.SaveAnnexesToDataTable(fileId, ext, chunks);
  316. if (ordertype == 100)
  317. json = _importDataOrExeclService.ImportBillMatInfo(dt, (int)ordertype, LoginUser.UserNo);
  318. //else
  319. // json = itmp.ImportData(dt, (int)ordertype, LoginBLLCore.GetLoginUser().UserNo);
  320. if (json.Type == 0)
  321. // 异常
  322. return FailEx(json.Message);
  323. else if (json.Type == 1)
  324. {
  325. if (json.dtSou == null || json.dtSou.Rows.Count == 0)
  326. return FailEx(json.Message);
  327. AnnexesFile.SaveErrJsonExecl(fileId, json);
  328. return Fail(json.Message);
  329. }
  330. else
  331. // 成功
  332. return Success(json.Message);
  333. }
  334. catch (Exception ex)
  335. {
  336. return ToJsonResult(SysExCore.GetResErr(ex));
  337. }
  338. }
  339. /// <summary>
  340. /// 下载文件(导入文件未被导入的数据)
  341. /// </summary>
  342. /// <param name="fileId">文件id</param>
  343. /// <returns></returns>
  344. [HttpPost]
  345. [ValidateAntiForgeryToken]
  346. public void DownImportErrorFile(string fileId, string fileName)
  347. {
  348. string fname = WebUtility.UrlDecode("未导入错误数据【" + fileName + "】") + ".xls";
  349. AnnexesFile.DownErrJsonExecl(fileId, fname);
  350. }
  351. /// <summary>
  352. /// 移除附件分片数据
  353. /// </summary>
  354. /// <param name="fileGuid">文件主键</param>
  355. /// <param name="chunks">总分片数</param>
  356. /// <returns></returns>
  357. [HttpPost]
  358. [ValidateAntiForgeryToken]
  359. public ActionResult RemoveAnnexesFileChunk(string fileGuid, int chunks)
  360. {
  361. AnnexesFile.RemoveChunkAnnexes(fileGuid, chunks);
  362. return Success("移除成功");
  363. }
  364. #endregion
  365. #region jfgrid弹层选择
  366. /// <summary>
  367. /// 列表选择弹层
  368. /// </summary>
  369. /// <returns></returns>
  370. [HttpGet]
  371. //[HandlerLogin(FilterMode.Enforce)]
  372. public ActionResult JfGirdLayerForm()
  373. {
  374. return View();
  375. }
  376. #endregion
  377. /// <summary>
  378. /// 获取仓库的树形数据
  379. /// </summary>
  380. /// <param name="parentId">父级id</param>
  381. /// <returns></returns>
  382. [HttpGet]
  383. ////[AjaxOnly]
  384. public ActionResult GetWareHouseTree(string parentId)
  385. {
  386. var data = _warehouseService.GetTree(parentId);
  387. return Success("", data);
  388. }
  389. [HttpGet]
  390. public ActionResult WearHouseList()
  391. {
  392. return Success(_warehouseService.WearHouseList());
  393. }
  394. }
  395. }