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;
public string controllerName;
public string actionName;
public string baseURL => HttpContext?.Request.Scheme + "://" + HttpContext?.Request.Host + "/";
public ErrorCode errorCode = new ErrorCode();
@ -153,5 +154,6 @@ namespace SolarPower.Controllers
return tempSerialNumber.ToString().Trim().PadRight(pad, '0');
}
}
}
}

View File

@ -428,6 +428,11 @@ namespace SolarPower.Controllers
return apiResult;
}
/// <summary>
/// 新增 維修單 / 修改運維作業記錄
/// </summary>
/// <param name="post"></param>
/// <returns></returns>
public async Task<ApiResult<OperationRecode>> SaveOperationRecode([FromForm] PostOperationRecode post)
{
ApiResult<OperationRecode> apiResult = new ApiResult<OperationRecode>();
@ -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;
}
/// <summary>
/// 儲存運維作業記錄檔案
/// </summary>
/// <param name="post"></param>
/// <returns></returns>
public async Task<ApiResult<OperationRecode>> SaveOperationRecodeFile([FromForm] PostOperationRecode post)
{
ApiResult<OperationRecode> apiResult = new ApiResult<OperationRecode>();
@ -667,5 +677,55 @@ namespace SolarPower.Controllers
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
{
return null;
return string.Empty;
}
}
set { finishTime = value; }
@ -252,11 +252,18 @@ namespace SolarPower.Models
public string OperationPredict
{
get
{
if(!string.IsNullOrEmpty(StartTime) || !string.IsNullOrEmpty(EndTime))
{
return StartTime + " ~ " + EndTime;
}
else
{
return string.Empty;
}
}
} //本次作業預計
public string FileList { get; set; } //檔案顯示
public List<string> HyperLinks { get; set; }
}
public class PostOperationRecode

View File

@ -40,7 +40,7 @@
<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>
匯出
</button>
@ -68,6 +68,24 @@
<tbody>
</tbody>
</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>
@ -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,12 +464,13 @@
}
var myDropzone = Dropzone.forElement("#recode-file-div");
if (myDropzone.getAcceptedFiles().length > 1) {
myDropzone.processQueue();
myDropzone.on("successmultiple", function (file, rel) {
if (rel.code == "9999") {
$('#recode-form-modal').modal('hide');
if (rel.code != "0000") {
toast_error(rel.msg);
return;
}
@ -462,6 +481,12 @@
operationRecodeTable.ajax.reload();
});
} else {
$('#recode-form-modal').modal('hide');
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 += '<div class="col-2">';
@ -540,6 +565,57 @@
str += '</div>';
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>
}