123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341 |
- using AutoMapper;
- using Cksoft.Data;
- using Cksoft.Data.Repository;
- using Cksoft.Unity;
- using DllEapCommon.NPOI;
- using DllEapDal.OFILM;
- using DllEapEntity;
- using DllEapEntity.Dtos;
- using DllEapEntity.Dtos.Export;
- using DllEapEntity.OFILM;
- using Microsoft.AspNetCore.Authorization;
- using Microsoft.AspNetCore.Mvc;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace DllEapBll.OFILM
- {
- /// <summary>
- /// 机台上线维护
- /// </summary>
- [Authorize]
- [ApiController]
- [Route("eap/api/[controller]/[action]")]
- public class MacRecipeController : ControllerBase
- {
- private readonly string connStr = "eapslave";
- private IMapper _mapper;
- public MacRecipeController(IMapper mapper)
- {
- _mapper = mapper;
- }
- /// <summary>
- /// 列表
- /// </summary>
- /// <param name="filter"></param>
- /// <param name="pageIndex"></param>
- /// <param name="pageSize"></param>
- /// <param name="sortField"></param>
- /// <param name="sortOrder"></param>
- /// <returns></returns>
- [HttpGet]
- public LayuiModel<MacRecipeDto> Get(string filter, int pageIndex = 1, int pageSize = 10, string sortField = "macCode", string sortOrder = "ascend")
- {
- if (sortOrder == "descend")
- {
- sortOrder = "desc";
- }
- else
- {
- sortOrder = "asc";
- }
- int start, end;
- start = (pageIndex - 1) * pageSize + 1;
- end = start + pageSize;
- int total;
- using (IDatabase db = DbFactory.Base(connStr))
- {
- db.BeginTrans();
- var dal = new MacRecipeDal(db);
- string errorinfo = string.Empty;
- var roles = dal.GetMacRecipeDtos(filter, start, pageSize, sortField, sortOrder, out total, ref errorinfo);
- return new LayuiModel<MacRecipeDto>
- {
- code = 1,
- count = total,
- data = roles,
- msg = ""
- };
- }
- }
- /// <summary>
- /// 列表
- /// </summary>
- /// <param name="filter"></param>
- /// <param name="pageIndex"></param>
- /// <param name="pageSize"></param>
- /// <param name="sortField"></param>
- /// <param name="sortOrder"></param>
- /// <returns></returns>
- [HttpGet]
- public LayuiModel<MachineInfo> GetMachineInfoes(string filter, int pageIndex = 1, int pageSize = 10, string sortField = "macCode", string sortOrder = "ascend")
- {
- if (sortOrder == "descend")
- {
- sortOrder = "desc";
- }
- else
- {
- sortOrder = "asc";
- }
- int start, end;
- start = (pageIndex - 1) * pageSize + 1;
- end = start + pageSize;
- int total;
- using (IDatabase db = DbFactory.Base(connStr))
- {
- db.BeginTrans();
- var dal = new MacRecipeDal(db);
- string errorinfo = string.Empty;
- var roles = dal.GetMachineInfoes(filter, start, pageSize, sortField, sortOrder, out total, ref errorinfo);
- return new LayuiModel<MachineInfo>
- {
- code = 1,
- count = total,
- data = roles,
- msg = ""
- };
- }
- }
- /// <summary>
- /// 详情
- /// </summary>
- /// <param name="macId"></param>
- /// <returns></returns>
- [HttpGet]
- public MacRecipeDto GetMachineInfoById(int macId)
- {
- int total;
- using (IDatabase db = DbFactory.Base(connStr))
- {
- db.BeginTrans();
- var dal = new MacRecipeDal(db);
- string errorinfo = string.Empty;
- var role = dal.GetMachineInfoes($" and a.id={macId}", 1, 1, "macid", "asc", out total, ref errorinfo)
- .FirstOrDefault();
- return role;
- }
- }
- /// <summary>
- /// 获取机台运行历史
- /// </summary>
- /// <param name="filter"></param>
- /// <param name="pageIndex"></param>
- /// <param name="pageSize"></param>
- /// <param name="sortField"></param>
- /// <param name="sortOrder"></param>
- /// <returns></returns>
- [HttpGet]
- public LayuiModel<MacRecipeDto> GetMacStatus(string filter, int pageIndex = 1, int pageSize = 10, string sortField = "stime", string sortOrder = "descend")
- {
- if (sortOrder == "descend")
- {
- sortOrder = "desc";
- }
- else
- {
- sortOrder = "asc";
- }
- int start, end;
- start = (pageIndex - 1) * pageSize + 1;
- end = start + pageSize;
- int total;
- using (IDatabase db = DbFactory.Base(connStr))
- {
- db.BeginTrans();
- var dal = new MacRecipeDal(db);
- string errorinfo = string.Empty;
- var roles = dal.GetMacStatusDtos(filter, start, pageSize, sortField, sortOrder, out total, ref errorinfo);
- return new LayuiModel<MacRecipeDto>
- {
- code = 1,
- count = total,
- data = roles,
- msg = ""
- };
- }
- }
- /// <summary>
- /// 机台运行历史导出
- /// </summary>
- /// <param name="filterInfo"></param>
- /// <returns></returns>
- [HttpPost]
- public async Task<IActionResult> ExportMacStatus(IDictionary<string, string> filterInfo)
- {
- string filter=string.Empty; int pageIndex = 1; int pageSize = 100000; string sortField = "stime"; string sortOrder = "descend";
- if (filterInfo.ContainsKey("filter"))
- {
- filter = filterInfo["filter"];
- }
- if (filterInfo.ContainsKey("pageIndex"))
- {
- pageIndex =Convert.ToInt32( filterInfo["pageIndex"]);
- }
- if (filterInfo.ContainsKey("pageSize"))
- {
- pageSize = Convert.ToInt32(filterInfo["pageSize"]);
- }
- if (filterInfo.ContainsKey("sortField"))
- {
- sortField = filterInfo["sortField"];
- }
- if (filterInfo.ContainsKey("sortOrder"))
- {
- sortOrder = filterInfo["sortOrder"];
- }
- var dto = GetMacStatus(filter, pageIndex, pageSize, sortField, sortOrder).data;
- var list = _mapper.Map<IEnumerable<ExportMacRecipeDto>>(dto).ToList();
- var book = DataExportHelper.EntityToExcel(list);
- MemoryStream ms = new MemoryStream();
- ms.Position = 0;
- book.Write(ms);
- ms.Dispose();
- ms.Close();
- await Task.CompletedTask;
- return File(ms.ToArray(), "application/octet-stream");
- }
- /// <summary>
- /// 导入数据
- /// </summary>
- /// <param name="importDto"></param>
- /// <returns></returns>
- [HttpPost]
- public EapResponse Import([FromBody] ImportDto importDto)
- {
- var res = new EapResponse { Code = 1, Msg = string.Empty };
- if (importDto.MacInfoes == null || importDto.MacInfoes.Count() <= 0)
- {
- res.Code = -1;
- res.Msg = "待导入的数据为空";
- return res;
- }
- using (IDatabase db = DbFactory.Base("eap"))
- {
- string errorinfo = string.Empty;
- var dal = new MacRecipeDal(db);
- db.BeginTrans();
- IList<string> existCodes = new List<string>();
- if (dal.ImportMachines(importDto.MacInfoes.ToArray(), Request.Headers["usercode"], existCodes, ref errorinfo) < 0)
- {
- db.Rollback();
- res.Code = -1;
- res.Msg = errorinfo;
- return res;
- }
- db.Commit();
- if (existCodes != null && existCodes.Count > 0)
- {
- res.Data = existCodes;
- res.Msg = $"机台[{string.Join(",", existCodes)}]在系统中已存在";
- }
- return res;
- }
- }
- /// <summary>
- /// 导入数据
- /// </summary>
- /// <param name="importDto"></param>
- /// <returns></returns>
- [HttpPost]
- public EapResponse ImportRest([FromBody] ImportDto importDto)
- {
- var res = new EapResponse { Code = 1, Msg = string.Empty };
- if (importDto.MacInfoes == null || importDto.MacInfoes.Count() <= 0)
- {
- res.Code = -1;
- res.Msg = "待导入的数据为空";
- return res;
- }
- using (IDatabase db = DbFactory.Base("eap"))
- {
- string errorinfo = string.Empty;
- var dal = new MacRecipeDal(db);
- db.BeginTrans();
- if (dal.UpdateMachines(importDto.MacInfoes.ToArray(), Request.Headers["usercode"], ref errorinfo) < 0)
- {
- db.Rollback();
- res.Code = -1;
- res.Msg = errorinfo;
- return res;
- }
- db.Commit();
- return res;
- }
- }
- /// <summary>
- /// 机台信息导出
- /// </summary>
- /// <param name="filterInfo"></param>
- /// <returns></returns>
- [HttpPost]
- public async Task<IActionResult> Export(IDictionary<string, string> filterInfo)
- {
- var filter = string.Empty;
- if (filterInfo.ContainsKey("filter"))
- filter = filterInfo["filter"];
- using (IDatabase db = DbFactory.Base(connStr))
- {
- db.BeginTrans();
- var dal = new MacRecipeDal(db);
- string errorinfo = string.Empty;
- int total;
- var roles = dal.GetMachineInfoes(filter, 1, 100000, "MacId", "asc", out total, ref errorinfo);
- var list = _mapper.Map<IEnumerable<MachineRecipeExportDto>>(roles).ToList();
- var book = DataExportHelper.EntityToExcel(list);
- MemoryStream ms = new MemoryStream();
- ms.Position = 0;
- book.Write(ms);
- ms.Dispose();
- ms.Close();
- await Task.CompletedTask;
- return File(ms.ToArray(), "application/octet-stream");
- }
- }
- /// <summary>
- /// 机台IP软件版本导出
- /// </summary>
- /// <param name="filterInfo"></param>
- /// <returns></returns>
- [HttpPost]
- public async Task<IActionResult> ExportIP(IDictionary<string, string> filterInfo)
- {
- var filter = string.Empty;
- if (filterInfo.ContainsKey("filter"))
- filter = filterInfo["filter"];
- var roles = Get(filter, 1, 10000).data;
- var list = _mapper.Map<IEnumerable<ExportIP>>(roles).ToList();
- var book = DataExportHelper.EntityToExcel(list);
- MemoryStream ms = new MemoryStream();
- ms.Position = 0;
- book.Write(ms);
- ms.Dispose();
- ms.Close();
- await Task.CompletedTask;
- return File(ms.ToArray(), "application/octet-stream");
- }
- }
- }
|