1. 運維作業記錄匯出excel
This commit is contained in:
parent
dc08866e85
commit
c091961393
@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -179,14 +179,14 @@ namespace SolarPower.Controllers
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <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>();
|
||||
ApiResult<List<OperationPlanTable>> apiResult = new ApiResult<List<OperationPlanTable>>();
|
||||
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;
|
||||
}
|
||||
|
||||
/// <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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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<string> HyperLinks { get; set; }
|
||||
}
|
||||
|
||||
public class PostOperationRecode
|
||||
|
||||
@ -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>
|
||||
@ -173,8 +191,8 @@
|
||||
<div class="row px-3">
|
||||
<form id="recode-file-div" class="dropzone needsclick dz-clickable col-12" style="min-height: 7rem;">
|
||||
@*<div class="fallback">
|
||||
<input type="file" multiple />
|
||||
</div>*@
|
||||
<input type="file" multiple />
|
||||
</div>*@
|
||||
<div class="dz-message needsclick">
|
||||
<i class="fal fa-cloud-upload text-muted mb-3"></i> <br>
|
||||
<span class="text-uppercase">將圖片拖曳至這裡或點擊選擇圖片.</span>
|
||||
@ -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 += '<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>
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user