旧版报表、仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

322 lines
16 KiB

using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
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.Text.RegularExpressions;
using System.Web.Http;
using Warehouse.DAL.PackOutput;
using Warehouse.WebApi.Model;
namespace Warehouse.WebApi
{
[RoutePrefix("api/PackOutputNew")]
public class PackOutputNewController : BaseController
{
PackOutput Pot = new PackOutput();
[Route("QueryInfoNew")]
[HttpPost]
public IHttpActionResult QueryInfoNew(PackOutputControllerModel model)
{
try
{
//序列号
var serialNum = "";
if (!string.IsNullOrEmpty(model.SerialNum))
{
var serialNumGet = model.SerialNum.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries).ToList();
var serialNumList = serialNumGet.Select(x => x.Trim()).Distinct().Where(s => !string.IsNullOrEmpty(s)).ToList();
serialNum = string.Join("','", serialNumList);
serialNum = "'" + serialNum + "'";
}
//柜号
var containerNum = "";
if (!string.IsNullOrEmpty(model.ContainerNum))
{
var containerNumGet = model.ContainerNum.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries).ToList();
var containerNumList = containerNumGet.Select(x => x.Trim()).Distinct().Where(s => !string.IsNullOrEmpty(s)).ToList();
containerNum = string.Join("','", containerNumList);
containerNum = "'" + containerNum + "'";
}
//托盘号
var palletNum = "";
if (!string.IsNullOrEmpty(model.PalletNum))
{
var palletNumGet = model.PalletNum.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries).ToList();
var palletNumList = palletNumGet.Select(x => x.Trim()).Distinct().Where(s => !string.IsNullOrEmpty(s)).ToList();
palletNum = string.Join("','", palletNumList);
palletNum = "'" + palletNum + "'";
}
//获取数据
var res = Pot.QueryInfo(model.WorkShop, model.TestTimeBegin, model.TestTimeEnd, serialNum, containerNum, palletNum, model.Checkno, model.WorkOrder);
//处理数据
var list = new List<dynamic>();
res.ForEach(x => {
list.Add(new
{
container_nbr = x.container_nbr.ToString() ?? "-",
pallet_nbr = x.pallet_nbr.ToString() ?? "-",
pack_seq = x.pack_seq.ToString() ?? "-",
workorder = x.workorder.ToString() ?? "-",
sale_order = x.sale_order.ToString() ?? "-",
serial_nbr = x.serial_nbr.ToString() ?? "-",
pack_date = x.pack_date.ToString() ?? "-", //.ToString("yyyy-MM-dd HH:mm:ss")
TestMachineNum = x.wks_visit_date.ToString() ?? "-",
PowerGrade = x.wks_id.ToString() ?? "-",
power_grade = x.power_grade.ToString() ?? "-",
current_grade = x.current_grade.ToString() ?? "-",
exterior_grade = x.exterior_grade.ToString() ?? "-",
el_grade = x.el_grade.ToString() ?? "-",
pmax = x.pmax ?? "-",
isc = x.isc ?? "-",
voc = x.voc ?? "-",
ipm = x.ipm ?? "-",
vpm = x.vpm ?? "-",
ff = x.ff ?? "-",
rs = x.rs ?? "-",
rsh = x.rsh ?? "-",
eff = x.eff ?? "-",
env_temp = x.env_temp ?? "-",
tmod = x.tmod ?? "-",
cell_supplier = x.cell_supplier.ToString() ?? "-",
cell_uop = x.cell_uop.ToString() ?? "-",
cell_color = x.cell_color.ToString() ?? "-",
cell_grade = x.cell_grade.ToString() ?? "-",
cell_type = x.cell_type.ToString() ?? "-",
cell_eff = x.cell_eff.ToString() ?? "-",
pallet_status_desc = x.pallet_status_desc.ToString() ?? "-",
});
});
//返回数据
return Success(new
{
data = list
});
}
catch (Exception e)
{
//TODO 记录日志
}
return Failure("查询异常");
// var res = Pot.QueryInfo( workshop,bt,et,lot,container,pallet,check, workorder);
//return Json(res);
//return Json<dynamic>(new { AA = "aa", BB = "cc" });
}
[Route("QueryStatus")]
[HttpPost]
public IHttpActionResult QueryStatus()
{
var res = Pot.QueryStatus();
return Json(res);
}
//[Route("QueryStatus")]
//[HttpPost]
//public FileResult tt()
//{
// return FileResult();
//}
#region 下载
[HttpPost, Route("DownloadPackOutReportGet")]
public HttpResponseMessage DownloadPackOutReportGet(PackOutputControllerModel model)
{
try
{
HSSFWorkbook hssfworkbook = new HSSFWorkbook();
hssfworkbook.CreateSheet("包装信息查询报表");
ICellStyle style = hssfworkbook.CreateCellStyle();
//设置单元格的样式:水平对齐居中
style.Alignment = HorizontalAlignment.Center;
ISheet sheet = null;
sheet = hssfworkbook.GetSheetAt(0);
IRow row = null;
#region 添加表头
var thList = new List<string> {
"柜号",
"托盘号",
"包装顺序",
"工单号",
"订单号",
"组件序列号",
"包装时间",
"测试日期时间",
"测试机台号",
"功率档位",
"电流档位",
"外观等级",
"EL等级",
"最终等级",
"Pmax",
"FF",
"VOC",
"ISC",
"VPM",
"IPM",
"RS",
"RSH",
"EFF",
"Envtmp",
"Tmod",
"电池片厂家",
"单片功率",
"电池片颜色",
"电池片等级",
"电池片类型",
"电池片效率档",
"托盘状态"
};
//设置第一列列宽
// sheet.SetColumnWidth(0, 20 * 256);
//设置第一列之后的列宽
for (int i = 1; i < thList.Count; i++)
{
sheet.SetColumnWidth(i, 10 * 256);
}
var rowCount = sheet.LastRowNum;
row = sheet.CreateRow(rowCount);
//添加表头并设置样式字体居中
for (int i = 0; i < thList.Count; i++)
{
row.CreateCell(i).SetCellValue(thList[i]);
row.GetCell(i).CellStyle = style;
}
#endregion
//序列号
var serialNum = "";
if (!string.IsNullOrEmpty(model.SerialNum))
{
var serialNumGet = model.SerialNum.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries).ToList();
var serialNumList = serialNumGet.Select(x => x.Trim()).Distinct().Where(s => !string.IsNullOrEmpty(s)).ToList();
serialNum = string.Join("','", serialNumList);
serialNum = "'" + serialNum + "'";
}
//柜号
var containerNum = "";
if (!string.IsNullOrEmpty(model.ContainerNum))
{
var containerNumGet = model.ContainerNum.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries).ToList();
var containerNumList = containerNumGet.Select(x => x.Trim()).Distinct().Where(s => !string.IsNullOrEmpty(s)).ToList();
containerNum = string.Join("','", containerNumList);
containerNum = "'" + containerNum + "'";
}
//托盘号
var palletNum = "";
if (!string.IsNullOrEmpty(model.PalletNum))
{
var palletNumGet = model.PalletNum.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries).ToList();
var palletNumList = palletNumGet.Select(x => x.Trim()).Distinct().Where(s => !string.IsNullOrEmpty(s)).ToList();
palletNum = string.Join("','", palletNumList);
palletNum = "'" + palletNum + "'";
}
//获取数据
var res = Pot.QueryInfo(model.WorkShop, model.TestTimeBegin, model.TestTimeEnd, serialNum, containerNum, palletNum, model.Checkno, model.WorkOrder);
foreach (var item in res.ToList())
{
var rowCount1 = sheet.LastRowNum + 1;
row = sheet.CreateRow(rowCount1);
row.CreateCell(0).SetCellValue(item.container_nbr.ToString());
row.GetCell(0).CellStyle = style;
row.CreateCell(1).SetCellValue(item.pallet_nbr.ToString());
row.GetCell(1).CellStyle = style;
row.CreateCell(2).SetCellValue(item.pack_seq.ToString());
row.GetCell(2).CellStyle = style;
row.CreateCell(3).SetCellValue(item.workorder.ToString());
row.GetCell(3).CellStyle = style;
row.CreateCell(4).SetCellValue(item.sale_order.ToString());
row.GetCell(4).CellStyle = style;
row.CreateCell(5).SetCellValue(item.serial_nbr.ToString());
row.GetCell(5).CellStyle = style;
row.CreateCell(6).SetCellValue(item.pack_date.ToString());
row.GetCell(6).CellStyle = style;
row.CreateCell(7).SetCellValue(item.wks_visit_date.ToString());
row.GetCell(7).CellStyle = style;
row.CreateCell(8).SetCellValue(item.wks_id.ToString());
row.GetCell(8).CellStyle = style;
row.CreateCell(9).SetCellValue(item.power_grade.ToString());
row.GetCell(9).CellStyle = style;
row.CreateCell(10).SetCellValue(item.current_grade.ToString());
row.GetCell(10).CellStyle = style;
row.CreateCell(11).SetCellValue(item.exterior_grade.ToString());
row.GetCell(11).CellStyle = style;
row.CreateCell(12).SetCellValue(item.el_grade.ToString());
row.GetCell(12).CellStyle = style;
row.CreateCell(13).SetCellValue(item.final_grade.ToString());
row.GetCell(13).CellStyle = style;
row.CreateCell(14).SetCellValue(string.IsNullOrEmpty(item.pmax.ToString()) ? "" : item.pmax.ToString("0"));
row.GetCell(14).CellStyle = style;
row.CreateCell(15).SetCellValue(string.IsNullOrEmpty(item.ff.ToString()) ? "" : item.isc.ToString("0"));
row.GetCell(15).CellStyle = style;
row.CreateCell(16).SetCellValue(string.IsNullOrEmpty(item.voc.ToString()) ? "" : item.voc.ToString("0"));
row.GetCell(16).CellStyle = style;
row.CreateCell(17).SetCellValue(string.IsNullOrEmpty(item.isc.ToString()) ? "" : item.ipm.ToString("0"));
row.GetCell(17).CellStyle = style;
row.CreateCell(18).SetCellValue(string.IsNullOrEmpty(item.vpm.ToString()) ? "" : item.vpm.ToString("0"));
row.GetCell(18).CellStyle = style;
row.CreateCell(19).SetCellValue(string.IsNullOrEmpty(item.ipm.ToString()) ? "" : item.ff.ToString("0"));
row.GetCell(19).CellStyle = style;
row.CreateCell(20).SetCellValue(string.IsNullOrEmpty(item.rs.ToString()) ? "" : item.rs.ToString("0"));
row.GetCell(20).CellStyle = style;
row.CreateCell(21).SetCellValue(string.IsNullOrEmpty(item.rsh.ToString()) ? "" : item.rsh.ToString("0"));
row.GetCell(21).CellStyle = style;
row.CreateCell(22).SetCellValue(string.IsNullOrEmpty(item.eff.ToString()) ? "" : item.eff.ToString("0"));
row.GetCell(22).CellStyle = style;
row.CreateCell(23).SetCellValue(string.IsNullOrEmpty(item.env_temp.ToString()) ? "" : item.env_temp.ToString("0"));
row.GetCell(23).CellStyle = style;
row.CreateCell(24).SetCellValue(string.IsNullOrEmpty(item.tmod.ToString()) ? "" : item.tmod.ToString("0"));
row.GetCell(24).CellStyle = style;
row.CreateCell(25).SetCellValue(item.cell_supplier.ToString());
row.GetCell(25).CellStyle = style;
row.CreateCell(26).SetCellValue(item.cell_uop.ToString());
row.GetCell(26).CellStyle = style;
row.CreateCell(27).SetCellValue(item.cell_color.ToString());
row.GetCell(27).CellStyle = style;
row.CreateCell(28).SetCellValue(item.cell_grade.ToString());
row.GetCell(28).CellStyle = style;
row.CreateCell(29).SetCellValue(item.cell_type.ToString());
row.GetCell(29).CellStyle = style;
row.CreateCell(30).SetCellValue(item.cell_eff.ToString());
row.GetCell(30).CellStyle = style;
row.CreateCell(31).SetCellValue(item.pallet_status_desc.ToString());
row.GetCell(31).CellStyle = style;
}
MemoryStream ms = new MemoryStream(); //创建内存流用于写入文件
hssfworkbook.Write(ms);//将Excel写入流
ms.Flush();
ms.Position = 0;
HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
result.Content = new StreamContent(ms);
result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{
FileName = "包装信息查询报表.xls"
};
return result;
}
catch (Exception)
{
}
return new HttpResponseMessage(HttpStatusCode.NoContent);
}
#endregion
}
}