diff --git a/SolarPower/Controllers/MyBaseController.cs b/SolarPower/Controllers/MyBaseController.cs index 7c52141..ad923fe 100644 --- a/SolarPower/Controllers/MyBaseController.cs +++ b/SolarPower/Controllers/MyBaseController.cs @@ -37,6 +37,7 @@ namespace SolarPower.Controllers protected MyUser myUser = null; public string controllerName; public string actionName; + public string baseURL => HttpContext?.Request.Scheme + "://" + HttpContext?.Request.Host + "/"; public ErrorCode errorCode = new ErrorCode(); @@ -144,7 +145,7 @@ namespace SolarPower.Controllers tempSerialNumber = 1; } - if(direction == 0) + if (direction == 0) { return tempSerialNumber.ToString().Trim().PadLeft(pad, '0'); } @@ -153,5 +154,6 @@ namespace SolarPower.Controllers return tempSerialNumber.ToString().Trim().PadRight(pad, '0'); } } + } } diff --git a/SolarPower/Controllers/OperationController.cs b/SolarPower/Controllers/OperationController.cs index eaeb38e..7d338b2 100644 --- a/SolarPower/Controllers/OperationController.cs +++ b/SolarPower/Controllers/OperationController.cs @@ -179,14 +179,14 @@ namespace SolarPower.Controllers /// /// /// - public async Task OperationPlanTable(List id,int type) + public async Task OperationPlanTable(List id, int type) { List OperationPlanTable = new List(); ApiResult> apiResult = new ApiResult>(); try { apiResult.Code = "0000"; - OperationPlanTable = await operationRepository.OperationPlanTable(id,type); + OperationPlanTable = await operationRepository.OperationPlanTable(id, type); foreach (OperationPlanTable a in OperationPlanTable) { if (a.Type == 0) @@ -428,6 +428,11 @@ namespace SolarPower.Controllers return apiResult; } + /// + /// 新增 維修單 / 修改運維作業記錄 + /// + /// + /// public async Task> SaveOperationRecode([FromForm] PostOperationRecode post) { ApiResult apiResult = new ApiResult(); @@ -465,7 +470,7 @@ namespace SolarPower.Controllers FormId = "op" + DateTime.Now.ToString("yyyyMMdd") + tempSerialNumber, SerialNumber = tempSerialNumber, PowerStationId = post.PowerStationId, - WorkType = post.WorkType, + WorkType = (int)OperationRecodeWorkTypeEnum.Fix, ErrorCode = post.ErrorCode, FixDo = post.FixDo, Status = post.Status, @@ -589,6 +594,11 @@ namespace SolarPower.Controllers return apiResult; } + /// + /// 儲存運維作業記錄檔案 + /// + /// + /// public async Task> SaveOperationRecodeFile([FromForm] PostOperationRecode post) { ApiResult apiResult = new ApiResult(); @@ -667,5 +677,55 @@ namespace SolarPower.Controllers return apiResult; } + + public async Task>> ExportOperationRecodeExcel(PostOperationRecodeFilter post) + { + ApiResult> apiResult = new ApiResult>(); + + List recodes = null; + + try + { + + //if (!IsPlatformLayer(myUser.Role.Layer)) + //{ //如果只是身分公司管理員 或 公司使用者,就只能看自己公司的資料 + // post.SelectedCompanyId = myUser.CompanyId; + //} + + recodes = await operationRepository.GetAllRecodeByFilterAsync(post); + + foreach (var recode in recodes) + { + recode.PowerStationName = !string.IsNullOrEmpty(recode.PowerStationName) ? recode.PowerStationName : ""; + recode.FormId = !string.IsNullOrEmpty(recode.FormId) ? recode.FormId : ""; + recode.FixDo = !string.IsNullOrEmpty(recode.FixDo) ? recode.FixDo : ""; + recode.WorkPersonName = !string.IsNullOrEmpty(recode.WorkPersonName) ? recode.WorkPersonName : ""; + recode.FinishTime = !string.IsNullOrEmpty(recode.FinishTime) ? recode.FinishTime : ""; + + if (recode.RecodeFiles != null && recode.RecodeFiles.Count > 0) + { + foreach (var file in recode.RecodeFiles) + { + var hyperLink = "" + file.FileName + ""; + + recode.HyperLinks.Add(hyperLink); + } + } + } + + apiResult.Code = "0000"; + apiResult.Data = recodes; + } + catch (Exception exception) + { + apiResult.Code = "9999"; + string json = System.Text.Json.JsonSerializer.Serialize(post); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + json); + Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message); + } + + apiResult.Msg = errorCode.GetString(apiResult.Code); + return apiResult; + } } } diff --git a/SolarPower/Models/Operation.cs b/SolarPower/Models/Operation.cs index ceed613..c4d43b0 100644 --- a/SolarPower/Models/Operation.cs +++ b/SolarPower/Models/Operation.cs @@ -171,7 +171,7 @@ namespace SolarPower.Models } else { - return null; + return string.Empty; } } set { finishTime = value; } @@ -253,10 +253,17 @@ namespace SolarPower.Models { get { - return StartTime + " ~ " + EndTime; + if(!string.IsNullOrEmpty(StartTime) || !string.IsNullOrEmpty(EndTime)) + { + return StartTime + " ~ " + EndTime; + } + else + { + return string.Empty; + } } } //本次作業預計 - public string FileList { get; set; } //檔案顯示 + public List HyperLinks { get; set; } } public class PostOperationRecode diff --git a/SolarPower/Views/Operation/OperationRecord.cshtml b/SolarPower/Views/Operation/OperationRecord.cshtml index 5ba4d7e..1c050b4 100644 --- a/SolarPower/Views/Operation/OperationRecord.cshtml +++ b/SolarPower/Views/Operation/OperationRecord.cshtml @@ -40,7 +40,7 @@
- @@ -68,6 +68,24 @@ + + + + + + + + + + + + + + + + + +
@@ -173,8 +191,8 @@
@*
- -
*@ + +
*@

將圖片拖曳至這裡或點擊選擇圖片. @@ -299,8 +317,8 @@ "url": "/Operation/OperationRecodeList", "type": "POST", "data": function (d) { - d.CityIds = [1]; - d.PowerStationIds = [15, 16]; + d.CityIds = [3]; + d.PowerStationIds = [1]; d.WorkType = $('#company_phone').val(); d.Range = $('#company_taxIDNumber').val(); }, @@ -413,7 +431,7 @@ }); //#endregion - //#region 儲存表單資料(未用到先註解) + //#region 儲存表單資料 function SaveRecode() { if ($("#recode-form").valid()) { @@ -446,22 +464,29 @@ } var myDropzone = Dropzone.forElement("#recode-file-div"); - myDropzone.processQueue(); + if (myDropzone.getAcceptedFiles().length > 1) { - myDropzone.on("successmultiple", function (file, rel) { - if (rel.code == "9999") { + myDropzone.processQueue(); + + myDropzone.on("successmultiple", function (file, rel) { + if (rel.code != "0000") { + toast_error(rel.msg); + return; + } + + toast_ok(rel.msg); $('#recode-form-modal').modal('hide'); - toast_error(rel.msg); - return; - } + recodeFileDropzone.removeAllFiles(); - toast_ok(rel.msg); + operationRecodeTable.ajax.reload(); + }); + } else { $('#recode-form-modal').modal('hide'); - recodeFileDropzone.removeAllFiles(); + myDropzone.removeAllFiles(); operationRecodeTable.ajax.reload(); - }); + } } }); } @@ -489,7 +514,7 @@ } //#endregion - //#region 表單檔案資料包含儲存 + //#region 表單檔案資料 Dropzone.autoDiscover = false; recodeFileDropzone = new Dropzone("#recode-file-div", { url: "/Operation/SaveOperationRecodeFile", @@ -519,9 +544,9 @@ } }); - //#endregion + //#region 產生檔案html function CreateRecodeFileBox(dom, value) { var str = ""; str += '
'; @@ -540,6 +565,57 @@ str += '
'; dom.append(str); } - + //#endregion + + //#region 匯出excel + function ExportExcel() { + var url = "/Operation/ExportOperationRecodeExcel"; + var send_data = { + CityIds: [3], + PowerStationIds: [1] + }; + $.post(url, send_data, function (rel) { + if (rel.code != "0000") { + toast_error(rel.msg); + return; + } + $('#NoViewbody').empty(); + + var str = ""; + rel.data.forEach(function (value, index) { + str += "" + + "" + value.powerStationName + "" + + "" + value.formId + "" + + "" + value.workTypeText + "" + + "" + value.fixDo + "" + + "" + value.statusText + "" + + "" + value.workPersonName + "" + + "" + value.operationPredict + ""; + + str += ""; + if (value.hyperLinks != undefined || value.hyperLinks != null) { + value.hyperLinks.forEach(function (value2, index) { + str += value2 + "
"; + }); + } + str += ""; + + str += "" + value.finishTime + "" + + ""; + }); + + $('#NoViewbody').append(str); + + $("#NoView").table2excel({ + // 匯出的Excel文件的名稱 + name: "abc", + // Excel檔案的名稱 + filename: "test", + //檔案字尾名 + fileext: ".xls", + }); + }, 'json'); + } + //#endregion } \ No newline at end of file