|
|
@ -3486,19 +3486,22 @@ namespace AMESCoreStudio.Web.Controllers |
|
|
|
public async Task<IActionResult> WHS025UAsync(int id) |
|
|
|
{ |
|
|
|
await GetWorkingUnit(""); //報工生產單位
|
|
|
|
await GetFactoryUnitsListbyWH005(""); //途程生產單位
|
|
|
|
|
|
|
|
GetSideList(); |
|
|
|
|
|
|
|
var result = await _whsApi.GetWorkingStandardWorkTime(id); |
|
|
|
|
|
|
|
if (result.Count == 0) |
|
|
|
{ |
|
|
|
return View(); |
|
|
|
} |
|
|
|
|
|
|
|
return View(result[0]); |
|
|
|
} |
|
|
|
public async Task<IActionResult> WHS025DAsync(int id) |
|
|
|
{ |
|
|
|
var result = await _whsApi.DeleteWorkingStandardWorkTime(id); |
|
|
|
var deleteUserID = int.Parse(Request.Cookies["UserID"]); |
|
|
|
var result = await _whsApi.DeleteWorkingStandardWorkTime(id, deleteUserID); |
|
|
|
return Json(new Result() { success = true, msg = "" }); |
|
|
|
} |
|
|
|
[HttpPost] |
|
|
@ -3520,7 +3523,6 @@ namespace AMESCoreStudio.Web.Controllers |
|
|
|
ItemNo = model.ItemNo, |
|
|
|
WorkingUnitNo = model.WorkingUnitNo, |
|
|
|
UnitNo = model.UnitNo, |
|
|
|
|
|
|
|
WorkingStationID = model.WorkingStationID, |
|
|
|
Side = model.Side, |
|
|
|
OpCnt = model.OpCnt, |
|
|
@ -3540,13 +3542,13 @@ namespace AMESCoreStudio.Web.Controllers |
|
|
|
|
|
|
|
var json = JsonConvert.SerializeObject(item); |
|
|
|
var result = await _whsApi.PostWorkingStandardWorkTime(json); |
|
|
|
|
|
|
|
if (!result.Success) |
|
|
|
{ |
|
|
|
// 其中一筆失敗就回傳錯誤
|
|
|
|
ModelState.AddModelError("error", $"線別ID {lineId} 錯誤:{result.Msg}"); |
|
|
|
return View("WHS025C", model); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return RedirectToAction("Refresh", "Home", new { msg = "添加成功!" }); |
|
|
@ -3600,6 +3602,43 @@ namespace AMESCoreStudio.Web.Controllers |
|
|
|
} |
|
|
|
return View("WHS025U", model); |
|
|
|
} |
|
|
|
[HttpGet] |
|
|
|
public async Task<IActionResult> WHS025LAsync(int id) |
|
|
|
{ |
|
|
|
return View(id); |
|
|
|
} |
|
|
|
|
|
|
|
[ResponseCache(Duration = 0)] |
|
|
|
[HttpGet] |
|
|
|
public async Task<IActionResult> GetWorkingUnitNobyUnitAsync(string id) |
|
|
|
{ |
|
|
|
var result = await _whsApi.GetWorkingUnitbyNo(id); |
|
|
|
var data = new List<FactoryUnit>(); |
|
|
|
|
|
|
|
if (result != null && result.Count > 0) |
|
|
|
{ |
|
|
|
var unitNo = result[0].UnitNo; |
|
|
|
var resultUnit = await _basApi.GetFactoryUnits(); |
|
|
|
|
|
|
|
for (int i = 0; i < resultUnit.Count; i++) |
|
|
|
{ |
|
|
|
if (resultUnit[i].UnitNo == unitNo ) |
|
|
|
|
|
|
|
data.Add(new FactoryUnit |
|
|
|
{ |
|
|
|
UnitNo = resultUnit[i].UnitNo, |
|
|
|
UnitName = resultUnit[i].UnitName |
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
return Json(new Table { code = 0, msg = "", data = data, count = 1 }); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return Json(new Table { code = 0, msg = "No data found", data = null, count = 0 }); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[ResponseCache(Duration = 0)] |
|
|
@ -3617,6 +3656,9 @@ namespace AMESCoreStudio.Web.Controllers |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[ResponseCache(Duration = 0)] |
|
|
|
[HttpGet] |
|
|
|
public async Task<IActionResult> GetWorkingStationsbyUnitAsync(string id) |
|
|
@ -3633,19 +3675,19 @@ namespace AMESCoreStudio.Web.Controllers |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[ResponseCache(Duration = 0)] |
|
|
|
[HttpGet] |
|
|
|
public async Task<IActionResult> GetWorkingStandardWorkTimesAsync() |
|
|
|
{ |
|
|
|
var result = await _whsApi.GetWorkingStandardWorkTimes(); |
|
|
|
//[ResponseCache(Duration = 0)]
|
|
|
|
//[HttpGet]
|
|
|
|
//public async Task<IActionResult> GetWorkingStandardWorkTimesAsync()
|
|
|
|
//{
|
|
|
|
// var result = await _whsApi.GetWorkingStandardWorkTimes();
|
|
|
|
|
|
|
|
if (result.DataTotal > 0) |
|
|
|
{ |
|
|
|
return Json(new Table() { code = 0, msg = "", data = result.Data, count = result.DataTotal }); |
|
|
|
} |
|
|
|
// if (result.DataTotal > 0)
|
|
|
|
// {
|
|
|
|
// return Json(new Table() { code = 0, msg = "", data = result.Data, count = result.DataTotal });
|
|
|
|
// }
|
|
|
|
|
|
|
|
return Json(new Table() { count = 0, data = null }); |
|
|
|
} |
|
|
|
// return Json(new Table() { count = 0, data = null });
|
|
|
|
//}
|
|
|
|
|
|
|
|
[ResponseCache(Duration = 0)] |
|
|
|
[HttpGet] |
|
|
@ -3667,7 +3709,7 @@ namespace AMESCoreStudio.Web.Controllers |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var result = await _whsApi.GetWorkingStandardWorkTimesbyQuery(u, l, i, page, limit); |
|
|
|
var result = await _whsApi.GetWorkingStandardWorkTimesbyMultiQuery(u, l, i, page, limit); |
|
|
|
if (result.DataTotal > 0) |
|
|
|
{ |
|
|
|
return Json(new Table() { code = 0, msg = "", data = result.Data, count = result.DataTotal }); |
|
|
@ -3692,23 +3734,36 @@ namespace AMESCoreStudio.Web.Controllers |
|
|
|
ViewBag.FactoryUnit = UnitItems; |
|
|
|
} |
|
|
|
|
|
|
|
[ResponseCache(Duration = 0)] |
|
|
|
[HttpGet] |
|
|
|
public async Task<IActionResult> GetWorkingStandardWorkTimesLogAsync(int id, int page = 0, int limit = 10) |
|
|
|
{ |
|
|
|
|
|
|
|
var result = await _whsApi.GetWorkingStandardWorkTimeLogMulti(id,page,limit); |
|
|
|
if (result.DataTotal > 0) |
|
|
|
{ |
|
|
|
return Json(new Table() { code = 0, msg = "", data = result.Data, count = result.DataTotal }); |
|
|
|
} |
|
|
|
|
|
|
|
return Json(new Table() { count = 0, data = null }); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
///標準工時批次Excel匯入
|
|
|
|
/// 標準工時批次Excel匯入
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="Uploader"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpPost] |
|
|
|
public async Task<JsonResult> WHS025ExcelUpload(IFormFile Uploader) |
|
|
|
{ |
|
|
|
|
|
|
|
var user_id = Request.Cookies["UserID"]; |
|
|
|
//通過上傳檔案流初始化Mapper
|
|
|
|
using (var workbook = new XLWorkbook(Uploader.OpenReadStream())) |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
|
List<BarcodeGroupDto> barcodeGroup = new List<BarcodeGroupDto>(); |
|
|
|
List<WorkingStandardWorkTime> workingST = new List<WorkingStandardWorkTime>(); |
|
|
|
|
|
|
|
string Msg = string.Empty; |
|
|
|
var worksheet = workbook.Worksheet(1); |
|
|
@ -3720,119 +3775,134 @@ namespace AMESCoreStudio.Web.Controllers |
|
|
|
var data = worksheet.Range(firstCell.Address, lastCell.Address); |
|
|
|
var rowCount = data.RowCount(); |
|
|
|
var columnCount = data.ColumnCount(); |
|
|
|
var ErrorMsg = ""; |
|
|
|
var recordKeys = new HashSet<string>(); // 用於檢查組合是否重複
|
|
|
|
for (int i = 2; i <= rowCount; i++) |
|
|
|
{ |
|
|
|
string seq = data.Cell(i, 2).Value.ToString(); |
|
|
|
int sequence; |
|
|
|
bool isNumeric = int.TryParse(seq, out sequence); |
|
|
|
|
|
|
|
if (!isNumeric) |
|
|
|
var rowMsg = $"[第{i}列] "; |
|
|
|
try |
|
|
|
{ |
|
|
|
return Json(new Result() { success = false, msg = "Group順序" + seq + "請輸入數字", data = null }); |
|
|
|
|
|
|
|
var ItemNo = data.Cell(i, 1).GetString().Trim(); |
|
|
|
var WorkingUnitName = data.Cell(i, 2).GetString().Trim(); |
|
|
|
var WorkingLineName = data.Cell(i, 3).GetString().Trim(); |
|
|
|
var WorkingStationName = data.Cell(i, 4).GetString().Trim(); |
|
|
|
// var UnitName = data.Cell(i, 5).GetString().Trim();
|
|
|
|
var Side = data.Cell(i, 5).GetString().Trim(); |
|
|
|
var OpCntStr = data.Cell(i, 6).GetString().Trim(); |
|
|
|
var CtStr = data.Cell(i, 7).GetString().Trim(); |
|
|
|
var StationID = data.Cell(i, 8).GetString().Trim(); |
|
|
|
var MachineCntStr = data.Cell(i, 9).GetString().Trim(); |
|
|
|
var Remark = data.Cell(i, 10).GetString().Trim(); |
|
|
|
|
|
|
|
// 組合唯一鍵
|
|
|
|
var rowKey = $"{ItemNo}|{WorkingUnitName}|{WorkingLineName}|{WorkingStationName}|{Side}"; |
|
|
|
if (recordKeys.Contains(rowKey)) |
|
|
|
{ |
|
|
|
ErrorMsg += $"{rowMsg}資料重複:相同的料號與單位線別站別已存在。\n"; |
|
|
|
continue; |
|
|
|
} |
|
|
|
recordKeys.Add(rowKey); |
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(ItemNo)) { ErrorMsg += $"{rowMsg}料號不得為空\n"; continue; } |
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(WorkingUnitName)) { ErrorMsg += $"{rowMsg}報工生產單位不得為空\n"; continue; } |
|
|
|
if (string.IsNullOrWhiteSpace(WorkingLineName)) { ErrorMsg += $"{rowMsg}報工線別不得為空\n"; continue; } |
|
|
|
if (string.IsNullOrWhiteSpace(WorkingStationName)) { ErrorMsg += $"{rowMsg}報工站別不得為空\n"; continue; } |
|
|
|
// if (string.IsNullOrWhiteSpace(UnitName)) { ErrorMsg += $"{rowMsg}途程單位不得為空\n"; continue; }
|
|
|
|
List<string> validSides = new List<string> { "正面", "背面" }; |
|
|
|
if (string.IsNullOrWhiteSpace(Side)) { ErrorMsg += $"{rowMsg}面別不得為空\n"; continue; } |
|
|
|
else if (!validSides.Contains(Side)) |
|
|
|
{ |
|
|
|
ErrorMsg += $"{rowMsg}面別資料錯誤,請使用 N/A、正面、背面\n"; |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
if (!int.TryParse(OpCntStr, out int OpCnt)) |
|
|
|
{ |
|
|
|
ErrorMsg += $"{rowMsg}人數格式錯誤\n"; continue; |
|
|
|
} |
|
|
|
if (OpCnt <= 0) |
|
|
|
{ |
|
|
|
ErrorMsg += $"{rowMsg}人數必須大於 0\n"; continue; |
|
|
|
} |
|
|
|
|
|
|
|
if (!int.TryParse(CtStr, out int Ct)) |
|
|
|
{ |
|
|
|
ErrorMsg += $"{rowMsg}CT格式錯誤\n"; continue; |
|
|
|
} |
|
|
|
if (Ct <= 0) |
|
|
|
{ |
|
|
|
ErrorMsg += $"{rowMsg}CT 必須大於 0\n"; continue; |
|
|
|
} |
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(StationID)) |
|
|
|
{ |
|
|
|
ErrorMsg += $"{rowMsg}工站ID不得為空\n"; continue; |
|
|
|
} |
|
|
|
|
|
|
|
if (!int.TryParse(MachineCntStr, out int MachineCnt)) |
|
|
|
{ |
|
|
|
ErrorMsg += $"{rowMsg}機台數格式錯誤\n"; continue; |
|
|
|
} |
|
|
|
if (MachineCnt < 0) |
|
|
|
{ |
|
|
|
ErrorMsg += $"{rowMsg}機台數不得為負值\n"; continue; |
|
|
|
} |
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(Remark) && Remark.Length > 500) |
|
|
|
{ |
|
|
|
ErrorMsg += $"{rowMsg}備註過長,限制500字以內\n"; continue; |
|
|
|
} |
|
|
|
// 資料對應檢查
|
|
|
|
var WU = await _whsApi.GetWorkingUnitbyName(WorkingUnitName); |
|
|
|
var WL = await _whsApi.GetWorkingLinebyName(WorkingLineName); |
|
|
|
var WS = await _whsApi.GetWorkingStationbyName(WorkingStationName); |
|
|
|
// var UN = await _whsApi.GetFactoryUnitbyName(UnitName);
|
|
|
|
|
|
|
|
if (WU.Count == 0) { ErrorMsg += $"{rowMsg}查無 報工生產單位「{WorkingUnitName}」\n"; continue; } |
|
|
|
if (WL.Count == 0) { ErrorMsg += $"{rowMsg}查無 報工線別「{WorkingLineName}」\n"; continue; } |
|
|
|
if (WS.Count == 0) { ErrorMsg += $"{rowMsg}查無 報工站別「{WorkingStationName}」\n"; continue; } |
|
|
|
// if (UN.Count == 0) { ErrorMsg += $"{rowMsg}查無 途程生產單位「{UnitName}」\n"; continue; }
|
|
|
|
|
|
|
|
// 加入清單
|
|
|
|
workingST.Add(new WorkingStandardWorkTime |
|
|
|
{ |
|
|
|
WorkingUnitNo = WU[0].WorkingUnitNo, |
|
|
|
WorkingLineID = WL[0].WorkingLineID, |
|
|
|
WorkingStationID = WS[0].WorkingStationID, |
|
|
|
// UnitNo = UN[0].UnitNo,
|
|
|
|
UnitNo = WU[0].UnitNo, |
|
|
|
ItemNo = ItemNo, |
|
|
|
Side = Side, |
|
|
|
OpCnt = OpCnt, |
|
|
|
Ct = Ct, |
|
|
|
StationID = StationID, |
|
|
|
MachineCnt = MachineCnt, |
|
|
|
Remark = Remark, |
|
|
|
CreateDate = System.DateTime.Now, |
|
|
|
CreateUserID = int.Parse(user_id), |
|
|
|
UpdateDate = System.DateTime.Now, |
|
|
|
UpdateUserID = int.Parse(user_id) |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
barcodeGroup.Add(new BarcodeGroupDto |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
WipNo = data.Cell(i, 1).Value.ToString(), |
|
|
|
Sequence = int.Parse(data.Cell(i, 2).Value.ToString()), |
|
|
|
BarcodeNo = data.Cell(i, 3).Value.ToString(), |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
//#region 判斷序號是否在工單區間內
|
|
|
|
//var WipBarcode = await _pcbApi.GetWipBarcodesCheckInRange(data.Cell(i, 1).Value.ToString(), data.Cell(i, 3).Value.ToString());
|
|
|
|
//if (WipBarcode.Count == 0)
|
|
|
|
//{
|
|
|
|
// return Json(new Result() { success = false, msg = "生產序號" + data.Cell(i, 3).Value.ToString() + "不在工單" + data.Cell(i, 1).Value.ToString() + "區間內", data = null });
|
|
|
|
//}
|
|
|
|
//#endregion
|
|
|
|
|
|
|
|
//#region 判斷序號在Excel中是否重覆
|
|
|
|
//var duplicateBarcodeNos = barcodeGroup.GroupBy(x => x.BarcodeNo)
|
|
|
|
// .Where(group => group.Count() > 1)
|
|
|
|
// .Select(group => group.Key);
|
|
|
|
//if (duplicateBarcodeNos.Any())
|
|
|
|
//{
|
|
|
|
|
|
|
|
// return Json(new Result() { success = false, msg = "Excel檔案內的生產序號" + string.Join(", ", duplicateBarcodeNos) + "重覆", data = null });
|
|
|
|
//}
|
|
|
|
//#endregion
|
|
|
|
//#region 判斷序號是否已綁定群組
|
|
|
|
|
|
|
|
//var BarCodeinto = await _pcsApi.GetBarcodeInfoesByNo(data.Cell(i, 3).Value.ToString());
|
|
|
|
//if (BarCodeinto.Count() > 0)
|
|
|
|
//{
|
|
|
|
// var BarcodeGroup = await _pcsApi.GetBarcodeGroupByBarCodeID(BarCodeinto.Select(s => s.BarcodeID).FirstOrDefault());
|
|
|
|
// if (BarcodeGroup.Count() > 0)
|
|
|
|
// {
|
|
|
|
// return Json(new Result() { success = false, msg = "生產序號" + data.Cell(i, 3).Value.ToString() + "已綁定群組" + BarcodeGroup.Select(s => s.GroupID).FirstOrDefault() + ",不可重覆綁定", data = null });
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
//#endregion
|
|
|
|
} |
|
|
|
//#region 檢查工單是否全部一致
|
|
|
|
//if (barcodeGroup.Select(s => s.WipNo).Distinct().Count() != 1)
|
|
|
|
//{
|
|
|
|
// return Json(new Result() { success = false, msg = "Excel檔案內的工單不一致不可匯入", data = null });
|
|
|
|
|
|
|
|
//}
|
|
|
|
//#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//foreach (var item in barcodeGroup.Select(s => s.Sequence).Distinct())
|
|
|
|
//{
|
|
|
|
// foreach (var item1 in barcodeGroup.Where(w => w.Sequence == item))
|
|
|
|
// {
|
|
|
|
|
|
|
|
// #region 產生BarcodeInfo
|
|
|
|
// var barcodeInfo = new BarcodeInfo
|
|
|
|
// {
|
|
|
|
// BarcodeNo = item1.BarcodeNo,
|
|
|
|
// StationID = -1,
|
|
|
|
// LocationID = -1,
|
|
|
|
// WipID = -1,
|
|
|
|
// RuleStatus = "P",
|
|
|
|
// StatusID = -1,
|
|
|
|
// SysType = "S",
|
|
|
|
// StatusNo = "-1",
|
|
|
|
// CreateUserID = GetLogInUserID()
|
|
|
|
// };
|
|
|
|
|
|
|
|
// var PostResult = await _pcsApi.PostBarcodeInfoes(JsonConvert.SerializeObject(barcodeInfo));
|
|
|
|
|
|
|
|
// #endregion
|
|
|
|
// }
|
|
|
|
// #region 綁定Group
|
|
|
|
|
|
|
|
// var barcodeinfo = await _pcbApi.PostDapperByListBarcodeNO(JsonConvert.SerializeObject(barcodeGroup.Where(w => w.Sequence == item).Select(s => s.BarcodeNo)));
|
|
|
|
// int UserID = GetLogInUserID();
|
|
|
|
|
|
|
|
// List<BarcodeGroup> barcodeGroups = barcodeinfo
|
|
|
|
// .Select((b, index) => new BarcodeGroup
|
|
|
|
// {
|
|
|
|
// BarcodeID = b.BarcodeID,
|
|
|
|
// GroupID = 0,
|
|
|
|
// Sequence = item,
|
|
|
|
// CreateUserID = UserID,
|
|
|
|
// WipNo = barcodeGroup.Select(s => s.WipNo).FirstOrDefault()
|
|
|
|
// })
|
|
|
|
// .ToList();
|
|
|
|
|
|
|
|
// var BarCodeGroup = await _pcbApi.PostBarcodeGroupList(JsonConvert.SerializeObject(barcodeGroups));
|
|
|
|
|
|
|
|
|
|
|
|
// #endregion
|
|
|
|
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
return Json(new Result() { success = true, msg = "綁定成功", data = null }); |
|
|
|
|
|
|
|
ErrorMsg += $"{rowMsg}資料處理異常: {ex.Message}\n"; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(ErrorMsg)) |
|
|
|
{ |
|
|
|
return Json(new Result() { success = false, msg = $"匯入失敗:\n{ErrorMsg}", data = null }); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
var postData = await _whsApi.PostWorkingStandardWorkTimeList(JsonConvert.SerializeObject(workingST)); |
|
|
|
|
|
|
|
return Json(new Result() { success = true, msg = "匯入成功", data = null }); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|