302 lines
12 KiB
C#
302 lines
12 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using MiniExcelLibs;
|
|
using System.Linq.Expressions;
|
|
using WCS.BLL.DbModels;
|
|
using WCS.BLL.Services.IService;
|
|
using WCS.BLL.Services.Service;
|
|
using WCS.DAL.Db;
|
|
using WCS.DAL.DbModels;
|
|
using WCS.Model;
|
|
using WCS.Model.ApiModel;
|
|
using WCS.Model.ApiModel.BatchBindMatDetail;
|
|
using WCS.Model.ApiModel.Home;
|
|
using WCS.Model.ApiModel.MatBaseInfo;
|
|
using WCS.Model.ApiModel.PDAMatBind;
|
|
using WCS.Model.ApiModel.StoreInfo;
|
|
using WCS.Model.ApiModel.User;
|
|
using WCS.Model.WebSocketModel;
|
|
|
|
namespace WCS.WebApi.Controllers
|
|
{
|
|
/// <summary>
|
|
/// PDA物料绑定相关接口
|
|
/// </summary>
|
|
[ApiController]
|
|
[Route("[controller]")]
|
|
public class BatchBindMatDetailController : ControllerBase
|
|
{
|
|
public IBatchBindMatDetailService _batchBindMatDetailService { get; set; }
|
|
|
|
public BatchBindMatDetailController(IBatchBindMatDetailService batchBindMatDetailService)
|
|
{
|
|
_batchBindMatDetailService = batchBindMatDetailService;
|
|
}
|
|
|
|
[Route("getOrderTypes")]
|
|
[HttpPost(Name = "getOrderTypes")]
|
|
public async Task<ResponseBase> getOrderTypes(RequestBase request)
|
|
{
|
|
try
|
|
{
|
|
//直接获取当前所有货架类型并返回
|
|
var OrderTypes = DbHelp.db.Queryable<OrderTypeInfo>()
|
|
.Select(t => new OrderTypeModel()
|
|
{
|
|
Id = t.Id,
|
|
OrderTypeName = t.OrderTypeName
|
|
})
|
|
.ToList();
|
|
return new PageQueryResponse<OrderTypeModel>()
|
|
{
|
|
Code = 200,
|
|
Message = "success",
|
|
Data = new PageQueryResponseData<OrderTypeModel>
|
|
{
|
|
Lists = OrderTypes,
|
|
Count = OrderTypes.Count
|
|
}
|
|
};
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new PageQueryResponse<OrderTypeModel>()
|
|
{
|
|
Code = 300,
|
|
Message = $"查询失败:{ex.Message}",
|
|
};
|
|
}
|
|
}
|
|
|
|
[Route("getMatDetailCurrentInfosByStationCode")]
|
|
[HttpPost(Name = "getMatDetailCurrentInfosByStationCode")]
|
|
public async Task<ResponseBase> GetMatDetailCurrentInfosByStationCode(GetMatDetailCurrentInfosByStationCodeRequest request)
|
|
{
|
|
|
|
////判断参数
|
|
//if (string.IsNullOrEmpty(request.StationCode))
|
|
//{
|
|
// return new ResponseCommon()
|
|
// {
|
|
// Code = 201,
|
|
// Message = "工位编码为空,请联系相关人员进行配置!",
|
|
// Data = null,
|
|
// };
|
|
//}
|
|
////判断工位是否存在
|
|
//var isExsistLocation = await DbHelp.db.Queryable<LocationInfo>()
|
|
// .Where(t => t.LocationCode == request.StationCode)
|
|
// .AnyAsync();
|
|
////不存在工位
|
|
//if (!isExsistLocation)
|
|
//{
|
|
// return new ResponseCommon()
|
|
// {
|
|
// Code = 201,
|
|
// Message = $"工位[{request.StationCode}]不存在,暂时无法使用此功能!",
|
|
// Data = null,
|
|
// };
|
|
//}
|
|
return await _batchBindMatDetailService.GetMatDetailCurrentInfosByStationCode(request);
|
|
}
|
|
|
|
[HttpPost("updateMatDetailCurrentInfoForBind")]
|
|
public async Task<ResponseCommon<object>> updateMatDetailCurrentInfoForBind(AddLocaionInfoRequest<MatDetailCurrentInfo> request)
|
|
{
|
|
return await _batchBindMatDetailService.updateMatDetailCurrentInfo(request);
|
|
}
|
|
|
|
[HttpPost("deleteMatDetailCurrentInfoForBind")]
|
|
public async Task<ResponseCommon<object>> deleteMatDetailCurrentInfoForBind(DeleteInfosRequest request)
|
|
{
|
|
//校验
|
|
if (request.needDeleteIds == null || request.needDeleteIds.Count == 0)
|
|
{
|
|
return new ResponseCommon<object>()
|
|
{
|
|
Code = 201,
|
|
Message = "操作失败:参数校验失败(ID)."
|
|
};
|
|
}
|
|
return await _batchBindMatDetailService.deleteMatDetailCurrentInfo(request);
|
|
}
|
|
|
|
[HttpPost("importMatDetailCurrentInfos")]
|
|
public async Task<ResponseBase> importMatDetailCurrentInfos([FromForm] IFormFile excelFile, [FromForm] string userName
|
|
, [FromForm] string deviceType, [FromForm] string stationCode)
|
|
{
|
|
//文件校验
|
|
if (excelFile == null || excelFile.Length == 0)
|
|
{
|
|
return new ResponseCommon()
|
|
{
|
|
Code = 201,
|
|
Message = "导入失败:文件无有效内容!"
|
|
};
|
|
}
|
|
//输入数据校验
|
|
if (string.IsNullOrEmpty(userName))
|
|
{
|
|
return new ResponseCommon()
|
|
{
|
|
Code = 201,
|
|
Message = "导入失败:参数[用户名]无效,请登录后重试!"
|
|
};
|
|
}
|
|
if (string.IsNullOrEmpty(deviceType))
|
|
{
|
|
return new ResponseCommon()
|
|
{
|
|
Code = 201,
|
|
Message = "导入失败:参数[设备类型]无效!"
|
|
};
|
|
}
|
|
if (string.IsNullOrEmpty(stationCode))
|
|
{
|
|
return new ResponseCommon()
|
|
{
|
|
Code = 201,
|
|
Message = "导入失败:参数[工位]无效,请联系相关人员维护工位编码!"
|
|
};
|
|
}
|
|
|
|
using (var stream = new MemoryStream())
|
|
{
|
|
await excelFile.CopyToAsync(stream);
|
|
stream.Position = 0;
|
|
var list = MiniExcelLibs.MiniExcel.Query<MatDetailCurrentInfoImportModel>(stream, "物料绑定", ExcelType.XLSX).ToList();
|
|
//去除空白行
|
|
//infoList.RemoveAll(x => string.IsNullOrWhiteSpace(x.物料编码));
|
|
if (list == null || list.Count == 0)
|
|
{
|
|
return new ResponseCommon()
|
|
{
|
|
Code = 201,
|
|
Message = "导入失败:上传的文件中不存在有效的数据!"
|
|
};
|
|
}
|
|
return await _batchBindMatDetailService.importMatDetailCurrentInfo(list, userName, deviceType, stationCode);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 导入旧系统绑定关系
|
|
/// </summary>
|
|
/// <param name="excelFile"></param>
|
|
/// <param name="userName"></param>
|
|
/// <param name="deviceType"></param>
|
|
/// <param name="stationCode"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("importOldSystem")]
|
|
public async Task<ResponseBase> importOldSystem([FromForm] IFormFile excelFile, [FromForm] string userName
|
|
, [FromForm] string deviceType)
|
|
{
|
|
try
|
|
{
|
|
//文件校验
|
|
if (excelFile == null || excelFile.Length == 0)
|
|
{
|
|
return new ResponseCommon()
|
|
{
|
|
Code = 201,
|
|
Message = "导入失败:文件无有效内容!"
|
|
};
|
|
}
|
|
//输入数据校验
|
|
if (string.IsNullOrEmpty(userName))
|
|
{
|
|
return new ResponseCommon()
|
|
{
|
|
Code = 201,
|
|
Message = "导入失败:参数[用户名]无效,请登录后重试!"
|
|
};
|
|
}
|
|
if (string.IsNullOrEmpty(deviceType))
|
|
{
|
|
return new ResponseCommon()
|
|
{
|
|
Code = 201,
|
|
Message = "导入失败:参数[设备类型]无效!"
|
|
};
|
|
}
|
|
|
|
|
|
using (var stream = new MemoryStream())
|
|
{
|
|
await excelFile.CopyToAsync(stream);
|
|
stream.Position = 0;
|
|
var infoList = MiniExcelLibs.MiniExcel.Query<OldSystemImportModel>(stream, "货架管理", ExcelType.XLSX).ToList();
|
|
//去除空白行
|
|
infoList.RemoveAll(x => string.IsNullOrWhiteSpace(x.物料批次号));
|
|
if (infoList == null || infoList.Count == 0)
|
|
{
|
|
return new ResponseCommon()
|
|
{
|
|
Code = 201,
|
|
Message = "导入失败:上传的文件中不存在有效的数据!"
|
|
};
|
|
}
|
|
var shelfAlreadyBind = DbHelp.db.Queryable<MatDetailCurrentInfo>().Select(t => t.ShelfId).Distinct().ToList();
|
|
var shelfCodes = infoList.Select(t => t.货架编号).Distinct().ToList();
|
|
//获取系统中的货架
|
|
var shelfs = DbHelp.db.Queryable<ShelfInfo>()
|
|
.LeftJoin<MatDetailCurrentInfo>((si, mci) => mci.ShelfId == si.Id)
|
|
|
|
.Where((si, mci) => shelfCodes.Contains(si.ShelfCode) && !shelfAlreadyBind.Contains(si.Id))
|
|
|
|
.Select((si, mci) => si)
|
|
.Distinct()
|
|
.ToList();
|
|
|
|
|
|
//var shelfCodesInDb = shelfs.Select(t => t.ShelfCode).Distinct().ToList();
|
|
|
|
var matCurrentInfos = new List<MatDetailCurrentInfo>();
|
|
foreach (var info in infoList)
|
|
{
|
|
var shelf = shelfs.Where(t => t.ShelfCode == info.货架编号).FirstOrDefault();
|
|
//此货架已在新系统绑定的情况
|
|
if (shelf == null)
|
|
{
|
|
continue;
|
|
}
|
|
var matCurrentInfo = new MatDetailCurrentInfo()
|
|
{
|
|
ShelfId = shelf.Id,
|
|
ShelfCode = shelf.ShelfCode,
|
|
ShelfType = shelf.ShelfTypeName,
|
|
MatCode = info.物料批次号 + "(旧系统)",
|
|
MatName = info.物料批次号 + "(旧系统)",
|
|
MatBatch = "",
|
|
MatQty = 1,
|
|
ModifyUser = "system"
|
|
};
|
|
matCurrentInfos.Add(matCurrentInfo);
|
|
}
|
|
|
|
//删除上一次导入的信息
|
|
DbHelp.db.Deleteable<MatDetailCurrentInfo>().Where(t => t.MatCode.Contains("(旧系统)")).ExecuteCommand();
|
|
DbHelp.db.Insertable(matCurrentInfos).ExecuteCommand();
|
|
|
|
|
|
return new ResponseCommon()
|
|
{
|
|
Code = 200,
|
|
Message = "Success"
|
|
};
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
|
|
return new ResponseCommon()
|
|
{
|
|
Code = 201,
|
|
Message = "失败" + ex.Message
|
|
};
|
|
}
|
|
}
|
|
}
|
|
}
|