123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- using Microsoft.AspNetCore.Mvc;
- using Newtonsoft.Json;
- using System.Data;
- using System.Web;
- using WMS.BZModels.Dto.PT.BillInvDtos;
- using WMS.BZServices.PT;
- using WMS.Info;
- using WMS.Util;
- namespace WMS.BZWeb.Areas.PTManager.Controllers
- {
- [Area("PTManager")]
- public class InventorysController : MvcControllerBase
- {
- private readonly BaseInvService baseInvService;
- public InventorysController(BaseInvService bll)
- {
- baseInvService = bll;
- }
- #region 视图功能
- public IActionResult Index()
- {
- return View();
- }
- public IActionResult InvManualOut()
- {
- ViewBag.PTWMSWebAPIUrl = ConfigHelper.GetConfig().PTWMSWebAPIUrl;
- return View();
- }
- public IActionResult Form()
- {
- ViewBag.PTWMSWebAPIUrl = ConfigHelper.GetConfig().PTWMSWebAPIUrl;
- return View();
- }
- #endregion
- public ActionResult GetPageList(string pagination, string queryJson)
- {
- Pagination paginationobj = InitPagination(pagination);
- var query = new BillInvNowQueryDto();
- if (!string.IsNullOrEmpty(queryJson))
- {
- query = JsonConvert.DeserializeObject<BillInvNowQueryDto>(queryJson);
- }
- var lists = baseInvService.GetPageList(paginationobj, query ?? new BillInvNowQueryDto());
- 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 BillInvNowQueryDto();
- try
- {
- if (!string.IsNullOrEmpty(queryJson))
- {
- query = JsonConvert.DeserializeObject<BillInvNowQueryDto>(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 = baseInvService.GetList(query ?? new BillInvNowQueryDto());
- 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);
- }
- /// <summary>
- /// 解锁
- /// </summary>
- /// <param name="ids"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult UnLock(string ids)
- {
- if (string.IsNullOrEmpty(ids))
- {
- return Fail("没有选择数据!");
- }
- var lists = JsonConvert.DeserializeObject<List<string>>(ids);
- var userid = WebUtil.GetItem("userId");
- baseInvService.UpdateInvLockState(lists, BZModels.InvLockState.InvState_Normal, userid?.ToString());
- return Success("保存成功!");
- }
- /// <summary>
- /// 锁定
- /// </summary>
- /// <param name="ids"></param>
- /// <returns></returns>
- [HttpPost]
- public ActionResult Lock(string ids)
- {
- if (string.IsNullOrEmpty(ids))
- {
- return Fail("没有选择数据!");
- }
- var lists = JsonConvert.DeserializeObject<List<string>>(ids);
- var userid = WebUtil.GetItem("userId");
- baseInvService.UpdateInvLockState(lists, BZModels.InvLockState.InvState_Lock, userid?.ToString());
- return Success("保存成功!");
- }
- }
- }
|