123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- using Microsoft.AspNetCore.Mvc;
- using Newtonsoft.Json;
- using System.Data;
- using System.Web;
- using WMS.BZModels.Dto.CP.BillInventoryReportDtos;
- using WMS.BZServices.CP;
- using WMS.Info;
- using WMS.Util;
- namespace WMS.BZWeb.Areas.CPManager.Controllers
- {
- [Area("CPManager")]
- public class BillInventoryReportController : MvcControllerBase
- {
- private readonly BillInventoryReportService _billInventoryReportService;
- public BillInventoryReportController(BillInventoryReportService billInventoryReportService)
- {
- _billInventoryReportService = billInventoryReportService;
- }
- public IActionResult Index()
- {
- return View();
- }
- public ActionResult GetPageList(string pagination, string queryJson)
- {
- Pagination paginationobj = InitPagination(pagination);
- var query = new BillInventoryReportQueryDto();
- if (!string.IsNullOrEmpty(queryJson))
- {
- query = JsonConvert.DeserializeObject<BillInventoryReportQueryDto>(queryJson);
- }
- var lists = _billInventoryReportService.GetPageList(paginationobj, query ?? new BillInventoryReportQueryDto());
- var jsonData = new
- {
- rows = lists.Result,
- total = lists.TotalPage,
- page = lists.PageIndex,
- records = lists.TotalNum
- };
- return Success(jsonData);
- }
- [HttpPost]
- public IActionResult ExportExcel(string fileName, string queryJson, string exportField)
- {
- var query = new BillInventoryReportQueryDto();
- try
- {
- if (!string.IsNullOrEmpty(queryJson))
- {
- query = JsonConvert.DeserializeObject<BillInventoryReportQueryDto>(queryJson);
- }
- }
- catch (Exception ex)
- {
- }
- //设置导出格式
- ExcelConfig excelconfig = new ExcelConfig();
- excelconfig.Title = HttpUtility.UrlDecode(fileName);
- excelconfig.TitleFont = "微软雅黑";
- excelconfig.TitlePoint = 15;
- excelconfig.FileName = HttpUtility.UrlDecode(fileName) + ".xls";
- excelconfig.IsAllSizeColumn = true;
- excelconfig.ColumnEntity = new List<ColumnModel>();
- List<jfGridModel> columnList = exportField.ToList<jfGridModel>();
- if (columnList.Count == 0)
- {
- throw new Exception("未找到表头");
- }
- //行数据
- var lists = _billInventoryReportService.GetList(query ?? new BillInventoryReportQueryDto());
- var dataJson = JsonConvert.SerializeObject(lists);
- DataTable rowData = dataJson.ToTable();
- //写入Excel表头
- Dictionary<string, string> exportFieldMap = new Dictionary<string, string>();
- if (!string.IsNullOrEmpty(exportField))
- {
- string[] exportFields = exportField.Split(',');
- foreach (var field in exportFields)
- {
- if (!exportFieldMap.ContainsKey(field))
- {
- exportFieldMap.Add(field, "1");
- }
- }
- }
- foreach (var columnModel in columnList)
- {
- excelconfig.ColumnEntity.Add(new ColumnModel()
- {
- // Column =string.IsNullOrEmpty(columnModel.sortname)? columnModel.name: columnModel.sortname,
- Column = columnModel.name,
- ExcelColumn = columnModel.label,
- Alignment = columnModel.align,
- Width = columnModel.name.Length
- });
- }
- return File(ExcelHelper.NewExportMemoryStream(rowData, excelconfig), "application/ms-excel", excelconfig.FileName);
- }
- }
- }
|