1. 運維作業記錄匯出excel

This commit is contained in:
Kai 2021-06-24 16:36:32 +08:00
parent dc08866e85
commit c091961393
4 changed files with 170 additions and 25 deletions

View File

@ -37,6 +37,7 @@ namespace SolarPower.Controllers
protected MyUser myUser = null; protected MyUser myUser = null;
public string controllerName; public string controllerName;
public string actionName; public string actionName;
public string baseURL => HttpContext?.Request.Scheme + "://" + HttpContext?.Request.Host + "/";
public ErrorCode errorCode = new ErrorCode(); public ErrorCode errorCode = new ErrorCode();
@ -144,7 +145,7 @@ namespace SolarPower.Controllers
tempSerialNumber = 1; tempSerialNumber = 1;
} }
if(direction == 0) if (direction == 0)
{ {
return tempSerialNumber.ToString().Trim().PadLeft(pad, '0'); return tempSerialNumber.ToString().Trim().PadLeft(pad, '0');
} }
@ -153,5 +154,6 @@ namespace SolarPower.Controllers
return tempSerialNumber.ToString().Trim().PadRight(pad, '0'); return tempSerialNumber.ToString().Trim().PadRight(pad, '0');
} }
} }
} }
} }

View File

@ -179,14 +179,14 @@ namespace SolarPower.Controllers
/// </summary> /// </summary>
/// <param name="id"></param> /// <param name="id"></param>
/// <returns></returns> /// <returns></returns>
public async Task<ActionResult> OperationPlanTable(List<int> id,int type) public async Task<ActionResult> OperationPlanTable(List<int> id, int type)
{ {
List<OperationPlanTable> OperationPlanTable = new List<OperationPlanTable>(); List<OperationPlanTable> OperationPlanTable = new List<OperationPlanTable>();
ApiResult<List<OperationPlanTable>> apiResult = new ApiResult<List<OperationPlanTable>>(); ApiResult<List<OperationPlanTable>> apiResult = new ApiResult<List<OperationPlanTable>>();
try try
{ {
apiResult.Code = "0000"; apiResult.Code = "0000";
OperationPlanTable = await operationRepository.OperationPlanTable(id,type); OperationPlanTable = await operationRepository.OperationPlanTable(id, type);
foreach (OperationPlanTable a in OperationPlanTable) foreach (OperationPlanTable a in OperationPlanTable)
{ {
if (a.Type == 0) if (a.Type == 0)
@ -428,6 +428,11 @@ namespace SolarPower.Controllers
return apiResult; return apiResult;
} }
/// <summary>
/// 新增 維修單 / 修改運維作業記錄
/// </summary>
/// <param name="post"></param>
/// <returns></returns>
public async Task<ApiResult<OperationRecode>> SaveOperationRecode([FromForm] PostOperationRecode post) public async Task<ApiResult<OperationRecode>> SaveOperationRecode([FromForm] PostOperationRecode post)
{ {
ApiResult<OperationRecode> apiResult = new ApiResult<OperationRecode>(); ApiResult<OperationRecode> apiResult = new ApiResult<OperationRecode>();
@ -465,7 +470,7 @@ namespace SolarPower.Controllers
FormId = "op" + DateTime.Now.ToString("yyyyMMdd") + tempSerialNumber, FormId = "op" + DateTime.Now.ToString("yyyyMMdd") + tempSerialNumber,
SerialNumber = tempSerialNumber, SerialNumber = tempSerialNumber,
PowerStationId = post.PowerStationId, PowerStationId = post.PowerStationId,
WorkType = post.WorkType, WorkType = (int)OperationRecodeWorkTypeEnum.Fix,
ErrorCode = post.ErrorCode, ErrorCode = post.ErrorCode,
FixDo = post.FixDo, FixDo = post.FixDo,
Status = post.Status, Status = post.Status,
@ -589,6 +594,11 @@ namespace SolarPower.Controllers
return apiResult; return apiResult;
} }
/// <summary>
/// 儲存運維作業記錄檔案
/// </summary>
/// <param name="post"></param>
/// <returns></returns>
public async Task<ApiResult<OperationRecode>> SaveOperationRecodeFile([FromForm] PostOperationRecode post) public async Task<ApiResult<OperationRecode>> SaveOperationRecodeFile([FromForm] PostOperationRecode post)
{ {
ApiResult<OperationRecode> apiResult = new ApiResult<OperationRecode>(); ApiResult<OperationRecode> apiResult = new ApiResult<OperationRecode>();
@ -667,5 +677,55 @@ namespace SolarPower.Controllers
return apiResult; return apiResult;
} }
public async Task<ApiResult<List<OperationRecodeDataTable>>> ExportOperationRecodeExcel(PostOperationRecodeFilter post)
{
ApiResult<List<OperationRecodeDataTable>> apiResult = new ApiResult<List<OperationRecodeDataTable>>();
List<OperationRecodeDataTable> 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 = "<a href='" + baseURL + file.FileName + "'>" + file.FileName + "</a>";
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;
}
} }
} }

View File

@ -171,7 +171,7 @@ namespace SolarPower.Models
} }
else else
{ {
return null; return string.Empty;
} }
} }
set { finishTime = value; } set { finishTime = value; }
@ -252,11 +252,18 @@ namespace SolarPower.Models
public string OperationPredict public string OperationPredict
{ {
get get
{
if(!string.IsNullOrEmpty(StartTime) || !string.IsNullOrEmpty(EndTime))
{ {
return StartTime + " ~ " + EndTime; return StartTime + " ~ " + EndTime;
} }
else
{
return string.Empty;
}
}
} //本次作業預計 } //本次作業預計
public string FileList { get; set; } //檔案顯示 public List<string> HyperLinks { get; set; }
} }
public class PostOperationRecode public class PostOperationRecode

View File

@ -40,7 +40,7 @@
<div class="row d-flex justify-content-end px-3"> <div class="row d-flex justify-content-end px-3">
<button type="button" class="btn btn-info waves-effect waves-themed mb-3 mr-2"> <button type="button" class="btn btn-info waves-effect waves-themed mb-3 mr-2" onclick="ExportExcel()">
<span class="fal fa-file-excel mr-1"></span> <span class="fal fa-file-excel mr-1"></span>
匯出 匯出
</button> </button>
@ -68,6 +68,24 @@
<tbody> <tbody>
</tbody> </tbody>
</table> </table>
<table id="NoView" style="display:none">
<thead class="thead-themed">
<tr>
<th>電廠</th>
<th>表單號</th>
<th>項目</th>
<th>維修項目</th>
<th>狀態</th>
<th>執行人員</th>
<th>本次作業預計</th>
<th>照片</th>
<th>完成時間</th>
</tr>
</thead>
<tbody id="NoViewbody">
</tbody>
</table>
</div> </div>
</div> </div>
</div> </div>
@ -299,8 +317,8 @@
"url": "/Operation/OperationRecodeList", "url": "/Operation/OperationRecodeList",
"type": "POST", "type": "POST",
"data": function (d) { "data": function (d) {
d.CityIds = [1]; d.CityIds = [3];
d.PowerStationIds = [15, 16]; d.PowerStationIds = [1];
d.WorkType = $('#company_phone').val(); d.WorkType = $('#company_phone').val();
d.Range = $('#company_taxIDNumber').val(); d.Range = $('#company_taxIDNumber').val();
}, },
@ -413,7 +431,7 @@
}); });
//#endregion //#endregion
//#region 儲存表單資料(未用到先註解) //#region 儲存表單資料
function SaveRecode() { function SaveRecode() {
if ($("#recode-form").valid()) { if ($("#recode-form").valid()) {
@ -446,12 +464,13 @@
} }
var myDropzone = Dropzone.forElement("#recode-file-div"); var myDropzone = Dropzone.forElement("#recode-file-div");
if (myDropzone.getAcceptedFiles().length > 1) {
myDropzone.processQueue(); myDropzone.processQueue();
myDropzone.on("successmultiple", function (file, rel) { myDropzone.on("successmultiple", function (file, rel) {
if (rel.code == "9999") { if (rel.code != "0000") {
$('#recode-form-modal').modal('hide');
toast_error(rel.msg); toast_error(rel.msg);
return; return;
} }
@ -462,6 +481,12 @@
operationRecodeTable.ajax.reload(); operationRecodeTable.ajax.reload();
}); });
} else {
$('#recode-form-modal').modal('hide');
myDropzone.removeAllFiles();
operationRecodeTable.ajax.reload();
}
} }
}); });
} }
@ -489,7 +514,7 @@
} }
//#endregion //#endregion
//#region 表單檔案資料包含儲存 //#region 表單檔案資料
Dropzone.autoDiscover = false; Dropzone.autoDiscover = false;
recodeFileDropzone = new Dropzone("#recode-file-div", { recodeFileDropzone = new Dropzone("#recode-file-div", {
url: "/Operation/SaveOperationRecodeFile", url: "/Operation/SaveOperationRecodeFile",
@ -519,9 +544,9 @@
} }
}); });
//#endregion //#endregion
//#region 產生檔案html
function CreateRecodeFileBox(dom, value) { function CreateRecodeFileBox(dom, value) {
var str = ""; var str = "";
str += '<div class="col-2">'; str += '<div class="col-2">';
@ -540,6 +565,57 @@
str += '</div>'; str += '</div>';
dom.append(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 += "<tr>" +
"<td>" + value.powerStationName + "</td>" +
"<td>" + value.formId + "</td>" +
"<td>" + value.workTypeText + "</td>" +
"<td>" + value.fixDo + "</td>" +
"<td>" + value.statusText + "</td>" +
"<td>" + value.workPersonName + "</td>" +
"<td>" + value.operationPredict + "</td>";
str += "<td>";
if (value.hyperLinks != undefined || value.hyperLinks != null) {
value.hyperLinks.forEach(function (value2, index) {
str += value2 + "<br>";
});
}
str += "</td>";
str += "<td>" + value.finishTime + "</td>" +
"</tr>";
});
$('#NoViewbody').append(str);
$("#NoView").table2excel({
// 匯出的Excel文件的名稱
name: "abc",
// Excel檔案的名稱
filename: "test",
//檔案字尾名
fileext: ".xls",
});
}, 'json');
}
//#endregion
</script> </script>
} }