1. 維修單 負責人員多選

2. 維修單 新增廠商欄位
This commit is contained in:
Kai 2021-08-26 15:13:58 +08:00
parent c8f605168c
commit 72e2daebeb
8 changed files with 450 additions and 247 deletions

View File

@ -8,14 +8,15 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Transactions;
namespace SolarPower.Controllers
{
public class OperationController : MyBaseController<OperationController>
{
private readonly IOperationRepository operationRepository;
private string operationRecodeFilePath = "/upload/operation_recode/";
private string operationRecodeSaveAsPath = "";
private string operationRecordFilePath = "/upload/operation_recode/";
private string operationRecordSaveAsPath = "";
public OperationController(
@ -23,7 +24,7 @@ namespace SolarPower.Controllers
{
this.operationRepository = operationRepository;
operationRecodeSaveAsPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "upload", "operation_recode");
operationRecordSaveAsPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "upload", "operation_recode");
}
public IActionResult Index()
@ -71,7 +72,7 @@ namespace SolarPower.Controllers
ApiResult<string> apiResult = new ApiResult<string>();
try
{
if(Convert.ToDateTime(post.StartTime) < Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd")))
if (Convert.ToDateTime(post.StartTime) < Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd")))
{
apiResult.Msg = "開始時間不能選擇過去";
apiResult.Code = "0099";
@ -115,13 +116,13 @@ namespace SolarPower.Controllers
if(post.StartTime == DateTime.Now.ToString("yyyy-MM-dd"))
if (post.StartTime == DateTime.Now.ToString("yyyy-MM-dd"))
{
string endtime = "";
switch (post.ScheduleType)
{
case 0:
endtime = (Convert.ToDateTime(post.StartTime).AddDays(post.ScheduleNum)).ToString("yyyy-MM-dd 00:00:00");break;
endtime = (Convert.ToDateTime(post.StartTime).AddDays(post.ScheduleNum)).ToString("yyyy-MM-dd 00:00:00"); break;
case 1:
endtime = (Convert.ToDateTime(post.StartTime).AddDays(post.ScheduleNum * 7)).ToString("yyyy-MM-dd 00:00:00"); break;
case 2:
@ -388,45 +389,45 @@ namespace SolarPower.Controllers
/// <param name="post"></param>
/// <returns></returns>
[HttpPost]
public async Task<ActionResult> OperationRecodeListAsync(PostOperationRecodeFilter post)
public async Task<ActionResult> OperationRecordListAsync(PostOperationRecordFilter post)
{
ApiResult<List<OperationRecodeDataTable>> apiResult = new ApiResult<List<OperationRecodeDataTable>>();
ApiResult<List<OperationRecordDataTable>> apiResult = new ApiResult<List<OperationRecordDataTable>>();
int totalRecords = 0; //總資料筆數
int recFilter = 0; //過濾後資料筆數
List<OperationRecodeDataTable> recodes = null;
List<OperationRecordDataTable> records = null;
try
{
recodes = await operationRepository.GetAllRecodeByFilterAsync(post);
records = await operationRepository.GetAllRecordByFilterAsync(post);
foreach (var recode in recodes)
foreach (var record in records)
{
if (string.IsNullOrEmpty(recode.FormId))
if (string.IsNullOrEmpty(record.FormId))
{
recode.FormId = @$"<a href='javascript:;' class='btn btn-success waves-effect waves-themed mb-3 mr-2 edit-btn'>填寫表單</a>";
record.FormId = @$"<a href='javascript:;' class='btn btn-success waves-effect waves-themed mb-3 mr-2 edit-btn'>填寫表單</a>";
}
else
{
recode.FormId = @$"<a href='javascript:;' class='waves-effect waves-themed mb-3 mr-2 edit-btn'>{recode.FormId}</a>";
record.FormId = @$"<a href='javascript:;' class='waves-effect waves-themed mb-3 mr-2 edit-btn'>{record.FormId}</a>";
}
if (recode.RecodeFiles != null && recode.RecodeFiles.Count > 0)
if (record.RecordFiles != null && record.RecordFiles.Count > 0)
{
foreach (var file in recode.RecodeFiles)
foreach (var file in record.RecordFiles)
{
file.FileName = Path.Combine(operationRecodeFilePath, recode.Id.ToString()) + "/" + file.FileName;
file.FileName = Path.Combine(operationRecordFilePath, record.Id.ToString()) + "/" + file.FileName;
}
}
}
totalRecords = recodes.Count();
recFilter = recodes.Count();
totalRecords = records.Count();
recFilter = records.Count();
apiResult.Code = "0000";
apiResult.Data = recodes;
apiResult.Data = records;
}
catch (Exception exception)
{
@ -453,11 +454,11 @@ namespace SolarPower.Controllers
/// <param name="post"></param>
/// <returns></returns>
[HttpPost]
public async Task<ApiResult<OperationRecode>> GetOneOperationRecode(int id)
public async Task<ApiResult<OperationRecord>> GetOneOperationRecord(int id)
{
ApiResult<OperationRecode> apiResult = new ApiResult<OperationRecode>();
ApiResult<OperationRecord> apiResult = new ApiResult<OperationRecord>();
OperationRecode operationRecode;
OperationRecord operationRecord;
try
{
@ -467,22 +468,22 @@ namespace SolarPower.Controllers
// post.SelectedCompanyId = myUser.CompanyId;
//}
operationRecode = await operationRepository.GetOneOperationRecodeAsync(id);
operationRecord = await operationRepository.GetOneOperationRecordAsync(id);
if (operationRecode == null)
if (operationRecord == null)
{
apiResult.Code = "9989";
apiResult.Msg = errorCode.GetString(apiResult.Code);
return apiResult;
}
foreach (var recodeFile in operationRecode.RecodeFiles)
foreach (var recodeFile in operationRecord.RecordFiles)
{
recodeFile.FileName = Path.Combine(operationRecodeFilePath, operationRecode.Id.ToString()) + "/" + recodeFile.FileName;
recodeFile.FileName = Path.Combine(operationRecordFilePath, operationRecord.Id.ToString()) + "/" + recodeFile.FileName;
}
apiResult.Code = "0000";
apiResult.Data = operationRecode;
apiResult.Data = operationRecord;
}
catch (Exception exception)
{
@ -500,20 +501,21 @@ namespace SolarPower.Controllers
/// </summary>
/// <param name="post"></param>
/// <returns></returns>
public async Task<ApiResult<int>> SaveOperationRecode([FromForm] PostOperationRecode post)
public async Task<ApiResult<int>> SaveOperationRecord([FromForm] PostOperationRecord post)
{
ApiResult<int> apiResult = new ApiResult<int>();
OperationRecode operationRecode = null;
OperationRecord operationRecord = null;
var id = 0;
try
{
operationRecode = await operationRepository.GetOneOperationRecodeAsync(post.Id);
operationRecord = await operationRepository.GetOneOperationRecordAsync(post.Id);
//取得運維作業記錄最後流水號
var currentSerialNumber = await operationRepository.GetCurrentSerialNumber("operation_record");
if (operationRecode == null)
if (operationRecord == null)
{
if (post.Id != 0)
{
@ -527,48 +529,75 @@ namespace SolarPower.Controllers
var tempSerialNumber = GetLastSerialNumber(currentSerialNumber);
var finishTime = string.Empty;
if (post.Status == (int)OperationRecodeStatusEnum.Complete)
if (post.Status == (int)OperationRecordStatusEnum.Complete)
{
finishTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
}
operationRecode = new OperationRecode()
using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
{
FormId = "op" + DateTime.Now.ToString("yyyyMMdd") + tempSerialNumber,
SerialNumber = tempSerialNumber,
PowerStationId = post.PowerStationId,
WorkType = (int)OperationRecodeWorkTypeEnum.Fix,
ErrorCode = post.ErrorCode,
FixDo = post.FixDo,
FixFirm = post.FixFirm,
Status = post.Status,
WorkPersonId = post.WorkPersonId,
FinishTime = finishTime,
WorkTime = post.WorkTime,
Notice = post.Notice,
Description = post.Description,
CreatedBy = myUser.Id
};
operationRecord = new OperationRecord()
{
FormId = "op" + DateTime.Now.ToString("yyyyMMdd") + tempSerialNumber,
SerialNumber = tempSerialNumber,
PowerStationId = post.PowerStationId,
WorkType = (int)OperationRecordWorkTypeEnum.Fix,
ErrorCode = post.ErrorCode,
FixDo = post.FixDo,
FixFirm = post.FixFirm,
Status = post.Status,
//WorkPersonId = post.WorkPersonId,
FinishTime = finishTime,
WorkTime = post.WorkTime,
Notice = post.Notice,
Description = post.Description,
CreatedBy = myUser.Id
};
List<string> properties = new List<string>()
{
"FormId",
"SerialNumber",
"PowerStationId",
"WorkType",
"ErrorCode",
"FixDo",
"FixFirm",
"Status",
"WorkPersonId",
"FinishTime",
"WorkTime",
"Notice",
"Description",
"CreatedBy"
};
List<string> properties = new List<string>()
{
"FormId",
"SerialNumber",
"PowerStationId",
"WorkType",
"ErrorCode",
"FixDo",
"FixFirm",
"Status",
//"WorkPersonId",
"FinishTime",
"WorkTime",
"Notice",
"Description",
"CreatedBy"
};
var id = await operationRepository.AddOneOperationRecodeAsync(operationRecode, properties);
id = await operationRepository.AddOneOperationRecordAsync(operationRecord, properties);
//加入執行人員
if (post.WorkPersonIds != null)
{
List<OperationRecordPersonnel> insertOperationRecordPersonnels = new List<OperationRecordPersonnel>();
foreach (var op in post.WorkPersonIds)
{
OperationRecordPersonnel operationRecordPersonnel = new OperationRecordPersonnel();
operationRecordPersonnel.OperationRecordId = id;
operationRecordPersonnel.UserId = op;
insertOperationRecordPersonnels.Add(operationRecordPersonnel);
}
List<string> operationRecordPersonnelProperties = new List<string>()
{
"OperationRecordId",
"UserId",
};
await operationRepository.AddOperationRecordPersonnelAsync(insertOperationRecordPersonnels, operationRecordPersonnelProperties);
}
scope.Complete();
}
apiResult.Code = "0000";
apiResult.Msg = "儲存成功";
@ -581,12 +610,12 @@ namespace SolarPower.Controllers
#region
var finishTime = string.Empty;
if (post.Status == (int)OperationRecodeStatusEnum.Complete)
if (post.Status == (int)OperationRecordStatusEnum.Complete)
{
finishTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
}
if (operationRecode.WorkType != (int)OperationRecodeWorkTypeEnum.Fix)
if (operationRecord.WorkType != (int)OperationRecordWorkTypeEnum.Fix)
{ //針對清洗、巡檢
var now = DateTime.Now;
@ -595,18 +624,18 @@ namespace SolarPower.Controllers
if (now > endTime)
{
if (post.Status == (int)OperationRecodeStatusEnum.NoneComplete)
if (post.Status == (int)OperationRecordStatusEnum.NoneComplete)
{ //超過時間修改成 未完成-過期
post.Status = (int)OperationRecodeStatusEnum.NoneCompleteExpired;
post.Status = (int)OperationRecordStatusEnum.NoneCompleteExpired;
}
else if (post.Status == (int)OperationRecodeStatusEnum.Complete)
else if (post.Status == (int)OperationRecordStatusEnum.Complete)
{ //超過時間修改成 完成-過期
post.Status = (int)OperationRecodeStatusEnum.CompleteExpired;
post.Status = (int)OperationRecordStatusEnum.CompleteExpired;
}
}
}
UpdateOperationRecode update = new UpdateOperationRecode()
UpdateOperationRecord update = new UpdateOperationRecord()
{
Id = post.Id,
ErrorCode = post.ErrorCode,
@ -614,7 +643,7 @@ namespace SolarPower.Controllers
FixFirm = post.FixFirm,
Status = post.Status,
FinishTime = !string.IsNullOrEmpty(finishTime) ? finishTime : null,
WorkPersonId = post.WorkPersonId,
//WorkPersonId = post.WorkPersonId,
WorkTime = post.WorkTime,
Notice = post.Notice,
Description = post.Description,
@ -634,11 +663,11 @@ namespace SolarPower.Controllers
"WorkTime",
"Notice",
"Description",
"WorkPersonId",
//"WorkPersonId",
"UpdatedBy",
};
if (string.IsNullOrEmpty(operationRecode.FormId))
if (string.IsNullOrEmpty(operationRecord.FormId))
{
var tempSerialNumber = GetLastSerialNumber(currentSerialNumber);
@ -649,11 +678,69 @@ namespace SolarPower.Controllers
properties.Add("SerialNumber");
}
await operationRepository.UpdateOperationRecodeAsync(update, properties);
await operationRepository.UpdateOperationRecordAsync(update, properties);
List<int> origOperationRecordPersonnels = null; //原先的運維人員
origOperationRecordPersonnels = await operationRepository.GetOperationRecordPersonnelIdsByOperationRecordId(operationRecord.Id);
//判斷新進來的執行人員是否要歸類到新增 or 刪除
#region
if(post.WorkPersonIds != null && post.WorkPersonIds.Count() > 0)
{
//找出要刪除的
List<int> deleteOperationRecordPersonnelIds = origOperationRecordPersonnels.Where(x => !post.WorkPersonIds.Contains(x)).ToList();
List<OperationRecordPersonnel> deleteOperationRecordPersonnels = new List<OperationRecordPersonnel>();
foreach (var opId in deleteOperationRecordPersonnelIds)
{
OperationRecordPersonnel operationRecordPersonnel = new OperationRecordPersonnel();
operationRecordPersonnel.OperationRecordId = operationRecord.Id;
operationRecordPersonnel.UserId = opId;
deleteOperationRecordPersonnels.Add(operationRecordPersonnel);
}
//刪除執行人員
await operationRepository.DeleteOperationRecordPersonnel(deleteOperationRecordPersonnels);
}
#endregion
#region
//找出要新增的
if (post.WorkPersonIds != null && post.WorkPersonIds.Count() > 0)
{
List<int> insertOperationRecordPersonnelIds = post.WorkPersonIds.Where(x => !origOperationRecordPersonnels.Contains(x)).ToList();
List<OperationRecordPersonnel> insertOperationRecordPersonnels = new List<OperationRecordPersonnel>();
foreach (var op in insertOperationRecordPersonnelIds)
{
OperationRecordPersonnel operationPersonnel = new OperationRecordPersonnel();
operationPersonnel.OperationRecordId = operationRecord.Id;
operationPersonnel.Deleted = 0;
operationPersonnel.UserId = op;
operationPersonnel.CreatedBy = myUser.Id;
insertOperationRecordPersonnels.Add(operationPersonnel);
}
List<string> operationRecordPersonnelProperties = new List<string>()
{
"OperationRecordId",
"Deleted",
"UserId",
"CreatedBy",
};
await operationRepository.AddOperationRecordPersonnelAsync(insertOperationRecordPersonnels, operationRecordPersonnelProperties);
}
#endregion
apiResult.Code = "0000";
apiResult.Msg = "儲存成功";
apiResult.Data = operationRecode.Id;
apiResult.Data = operationRecord.Id;
#endregion
}
}
@ -669,22 +756,22 @@ namespace SolarPower.Controllers
return apiResult;
}
public async Task<ApiResult<string>> DeleteOneOperationRecode(int id)
public async Task<ApiResult<string>> DeleteOneOperationRecord(int id)
{
ApiResult<string> apiResult = new ApiResult<string>();
try
{
var operationRecode = await operationRepository.GetOneOperationRecodeAsync(id);
var operationRecord = await operationRepository.GetOneOperationRecordAsync(id);
if (operationRecode == null)
if (operationRecord == null)
{
apiResult.Code = "9989";
apiResult.Msg = errorCode.GetString(apiResult.Code);
return apiResult;
}
await operationRepository.DeleteOneOperationRecodeAsync(id);
await operationRepository.DeleteOneOperationRecordAsync(id);
apiResult.Code = "0000";
apiResult.Msg = "刪除成功";
@ -706,17 +793,17 @@ namespace SolarPower.Controllers
/// <param name="post"></param>
/// <returns></returns>
[HttpPost]
public async Task<ApiResult<OperationRecode>> SaveOperationRecodeFile([FromForm] PostOperationRecode post)
public async Task<ApiResult<OperationRecord>> SaveOperationRecordFile([FromForm] PostOperationRecord post)
{
ApiResult<OperationRecode> apiResult = new ApiResult<OperationRecode>();
ApiResult<OperationRecord> apiResult = new ApiResult<OperationRecord>();
OperationRecode operationRecode = null;
OperationRecord operationRecord = null;
try
{
operationRecode = await operationRepository.GetOneOperationRecodeAsync(post.Id);
operationRecord = await operationRepository.GetOneOperationRecordAsync(post.Id);
if (operationRecode == null)
if (operationRecord == null)
{
apiResult.Code = "9989";
apiResult.Msg = errorCode.GetString(apiResult.Code);
@ -724,19 +811,19 @@ namespace SolarPower.Controllers
}
#region
List<OperationRecodeFile> operationRecodeFiles;
List<OperationRecordFile> operationRecordFiles;
if (post.RecodeFiles != null && post.RecodeFiles.Length > 0)
if (post.RecordFiles != null && post.RecordFiles.Length > 0)
{
FolderFunction folderFunction = new FolderFunction();
var fileSaveAsPath = Path.Combine(operationRecodeSaveAsPath, operationRecode.Id.ToString());
var fileSaveAsPath = Path.Combine(operationRecordSaveAsPath, operationRecord.Id.ToString());
folderFunction.CreateFolder(fileSaveAsPath, 0);
operationRecodeFiles = new List<OperationRecodeFile>();
operationRecordFiles = new List<OperationRecordFile>();
foreach (var file in post.RecodeFiles)
foreach (var file in post.RecordFiles)
{
var split = file.FileName.Split(".");
@ -749,14 +836,14 @@ namespace SolarPower.Controllers
file.CopyTo(stream);
}
OperationRecodeFile operationRecodeFile = new OperationRecodeFile()
OperationRecordFile operationRecordFile = new OperationRecordFile()
{
RecordId = operationRecode.Id,
RecordId = operationRecord.Id,
FileName = fileName,
CreatedBy = myUser.Id
};
operationRecodeFiles.Add(operationRecodeFile);
operationRecordFiles.Add(operationRecordFile);
}
List<string> fileProperties = new List<string>()
@ -766,7 +853,7 @@ namespace SolarPower.Controllers
"CreatedBy"
};
await operationRepository.AddOperationRecodeFilesAsync(operationRecodeFiles, fileProperties);
await operationRepository.AddOperationRecordFilesAsync(operationRecordFiles, fileProperties);
}
#endregion
@ -785,34 +872,34 @@ namespace SolarPower.Controllers
return apiResult;
}
public async Task<ApiResult<string>> DeleteOperationRecodeFile(PostOperationRecodeIdAndSelectedId post)
public async Task<ApiResult<string>> DeleteOperationRecordFile(PostOperationRecordIdAndSelectedId post)
{
ApiResult<string> apiResult = new ApiResult<string>();
OperationRecode operationRecode = null;
OperationRecodeFile operationRecodeFile = null;
OperationRecord operationRecord = null;
OperationRecordFile operationRecordFile = null;
try
{
operationRecode = await operationRepository.GetOneOperationRecodeAsync(post.ReocdeId);
operationRecord = await operationRepository.GetOneOperationRecordAsync(post.ReocdeId);
if (operationRecode == null)
if (operationRecord == null)
{
apiResult.Code = "9989";
apiResult.Msg = errorCode.GetString(apiResult.Code);
return apiResult;
}
operationRecodeFile = await operationRepository.GetOneOperationRecodeFileAsync(post.SelectedId);
operationRecordFile = await operationRepository.GetOneOperationRecordFileAsync(post.SelectedId);
if (operationRecodeFile == null)
if (operationRecordFile == null)
{
apiResult.Code = "9987";
apiResult.Msg = errorCode.GetString(apiResult.Code);
return apiResult;
}
await operationRepository.DeleteOneOperationRecodeFile(post.SelectedId);
await operationRepository.DeleteOneOperationRecordFile(post.SelectedId);
apiResult.Code = "0000";
apiResult.Msg = "刪除成功";
@ -829,11 +916,11 @@ namespace SolarPower.Controllers
return apiResult;
}
public async Task<ApiResult<List<OperationRecodeDataTable>>> ExportOperationRecodeExcel(PostOperationRecodeFilter post)
public async Task<ApiResult<List<OperationRecordDataTable>>> ExportOperationRecordExcel(PostOperationRecordFilter post)
{
ApiResult<List<OperationRecodeDataTable>> apiResult = new ApiResult<List<OperationRecodeDataTable>>();
ApiResult<List<OperationRecordDataTable>> apiResult = new ApiResult<List<OperationRecordDataTable>>();
List<OperationRecodeDataTable> recodes = null;
List<OperationRecordDataTable> records = null;
try
{
@ -843,32 +930,32 @@ namespace SolarPower.Controllers
// post.SelectedCompanyId = myUser.CompanyId;
//}
recodes = await operationRepository.GetAllRecodeByFilterAsync(post);
records = await operationRepository.GetAllRecordByFilterAsync(post);
foreach (var recode in recodes)
foreach (var record in records)
{
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 : "";
record.PowerStationName = !string.IsNullOrEmpty(record.PowerStationName) ? record.PowerStationName : "";
record.FormId = !string.IsNullOrEmpty(record.FormId) ? record.FormId : "";
record.FixDo = !string.IsNullOrEmpty(record.FixDo) ? record.FixDo : "";
record.WorkPersonName = !string.IsNullOrEmpty(record.WorkPersonName) ? record.WorkPersonName : "";
//record.FinishTime = !string.IsNullOrEmpty(record.FinishTime) ? record.FinishTime : "";
if (recode.RecodeFiles != null && recode.RecodeFiles.Count > 0)
if (record.RecordFiles != null && record.RecordFiles.Count > 0)
{
foreach (var file in recode.RecodeFiles)
foreach (var file in record.RecordFiles)
{
var hyperLink = "<a href='" + baseURL + file.FileName + "'>" + file.FileName + "</a>";
if(recode.HyperLinks == null)
if (record.HyperLinks == null)
{
recode.HyperLinks = new List<string>();
record.HyperLinks = new List<string>();
}
recode.HyperLinks.Add(hyperLink);
record.HyperLinks.Add(hyperLink);
}
}
}
apiResult.Code = "0000";
apiResult.Data = recodes;
apiResult.Data = records;
}
catch (Exception exception)
{
@ -882,18 +969,19 @@ namespace SolarPower.Controllers
return apiResult;
}
public async void Schedule ()
public async void Schedule()
{
try {
try
{
var getTime = await operationRepository.GetOperationSchedules();
foreach(OperationCreatePlanModal a in getTime)
foreach (OperationCreatePlanModal a in getTime)
{
DateTime Updatedtime;
if (a.ScheduleType == 0)//日
{
Updatedtime = Convert.ToDateTime(a.StartTime).AddDays(a.ScheduleNum);
}
else if(a.ScheduleType == 1)//周
else if (a.ScheduleType == 1)//周
{
Updatedtime = Convert.ToDateTime(a.StartTime).AddDays(a.ScheduleNum * 7);
}

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace SolarPower.Models
{
public enum OperationRecodeStatusEnum : byte
public enum OperationRecordStatusEnum : byte
{
NoneComplete = 0, //未完成
Complete = 1, //完成
@ -14,7 +14,7 @@ namespace SolarPower.Models
CompleteExpired = 3, //完成-過期
}
public enum OperationRecodeWorkTypeEnum : byte
public enum OperationRecordWorkTypeEnum : byte
{
Clearn = 0, //清潔
Inspection = 1, //巡檢
@ -123,7 +123,7 @@ namespace SolarPower.Models
public string EndTime { get; set; }
}
public class OperationRecode : Created
public class OperationRecord : Created
{
private string startTime, endTime, finishTime, workTime;
public int Id { get; set; }
@ -136,7 +136,7 @@ namespace SolarPower.Models
public string FixDo { get; set; }
public byte FixFirm { get; set; }
public byte Status { get; set; }
public int WorkPersonId { get; set; }
public List<int> WorkPersonIds { get; set; }
public string StartTime
{
get
@ -199,10 +199,10 @@ namespace SolarPower.Models
} // 工作時間
public string Notice { get; set; }
public string Description { get; set; }
public List<OperationRecodeFile> RecodeFiles { get; set; }
public List<OperationRecordFile> RecordFiles { get; set; }
}
public class OperationRecodeFile : Created
public class OperationRecordFile : Created
{
public int Id { get; set; }
public int RecordId { get; set; }
@ -212,7 +212,7 @@ namespace SolarPower.Models
/// <summary>
/// 運維作業記錄的搜尋條件
/// </summary>
public class PostOperationRecodeFilter
public class PostOperationRecordFilter
{
public List<int> CityIds { get; set; } //縣市編號
public List<int> PowerStationIds { get; set; } //電站編號
@ -226,7 +226,7 @@ namespace SolarPower.Models
/// <summary>
/// 運維作業記錄的表單
/// </summary>
public class OperationRecodeDataTable : OperationRecode
public class OperationRecordDataTable : OperationRecord
{
public string WorkTypeText
{
@ -275,7 +275,7 @@ namespace SolarPower.Models
public List<string> HyperLinks { get; set; }
}
public class PostOperationRecode
public class PostOperationRecord
{
public int Id { get; set; }
public int PowerStationId { get; set; }
@ -284,17 +284,17 @@ namespace SolarPower.Models
public string FixDo { get; set; }
public byte FixFirm { get; set; }
public byte Status { get; set; }
public int WorkPersonId { get; set; }
public List<int> WorkPersonIds { get; set; }
public string StartTime { get; set; }//開始時間
public string EndTime { get; set; } // 結束時間
public string FinishTime { get; set; } // 完成時間
public string WorkTime { get; set; } // 工作時間
public string Notice { get; set; }
public string Description { get; set; }
public IFormFile[] RecodeFiles { get; set; }
public IFormFile[] RecordFiles { get; set; }
}
public class UpdateOperationRecode : Updated
public class UpdateOperationRecord : Updated
{
public string FormId { get; set; }
public string SerialNumber { get; set; }
@ -312,7 +312,7 @@ namespace SolarPower.Models
/// <summary>
/// 針對運維作業記錄檔案
/// </summary>
public class PostOperationRecodeIdAndSelectedId
public class PostOperationRecordIdAndSelectedId
{
public int ReocdeId { get; set; }
public int SelectedId { get; set; }
@ -327,4 +327,12 @@ namespace SolarPower.Models
public string StartTime { get { return Convert.ToDateTime(startTime).ToString("yyyy-MM-dd HH:mm:ss"); } set { startTime = value; } } //修改時間
}
public class OperationRecordPersonnel : Created
{
public int Id { get; set; }
public byte Deleted { get; set; }
public int OperationRecordId { get; set; }
public int UserId { get; set; }
}
}

View File

@ -198,9 +198,9 @@ namespace SolarPower.Repository.Implement
/// </summary>
/// <param name="filter"></param>
/// <returns></returns>
public async Task<List<OperationRecodeDataTable>> GetAllRecodeByFilterAsync(PostOperationRecodeFilter filter)
public async Task<List<OperationRecordDataTable>> GetAllRecordByFilterAsync(PostOperationRecordFilter filter)
{
List<OperationRecodeDataTable> result;
List<OperationRecordDataTable> result;
using (IDbConnection conn = this._databaseHelper.GetConnection())
{
try
@ -266,7 +266,7 @@ namespace SolarPower.Repository.Implement
sql += " ) aa ORDER BY aa.CreatedAt DESC";
result = (await conn.QueryAsync<OperationRecodeDataTable>(sql,
result = (await conn.QueryAsync<OperationRecordDataTable>(sql,
new {
PowerStationIds = filter.PowerStationIds,
WorkType = filter.WorkType,
@ -277,7 +277,7 @@ namespace SolarPower.Repository.Implement
var sql_file = "SELECT * FROM operation_record_file WHERE Deleted = 0 AND RecordId = @RecordId";
foreach (var x in result)
{
x.RecodeFiles = (await conn.QueryAsync<OperationRecodeFile>(sql_file, new { RecordId = x.Id })).ToList();
x.RecordFiles = (await conn.QueryAsync<OperationRecordFile>(sql_file, new { RecordId = x.Id })).ToList();
}
}
catch (Exception exception)
@ -293,9 +293,9 @@ namespace SolarPower.Repository.Implement
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public async Task<OperationRecode> GetOneOperationRecodeAsync(int id)
public async Task<OperationRecord> GetOneOperationRecordAsync(int id)
{
OperationRecode result;
OperationRecord result;
using (IDbConnection conn = this._databaseHelper.GetConnection())
{
@ -307,15 +307,22 @@ namespace SolarPower.Repository.Implement
LEFT JOIN power_station ps ON opr.PowerStationId = ps.Id
WHERE opr.Deleted = 0 AND opr.Id = @Id";
result = await conn.QueryFirstOrDefaultAsync<OperationRecode>(sql, new { Id = id });
result = await conn.QueryFirstOrDefaultAsync<OperationRecord>(sql, new { Id = id });
if (result != null)
{
//取得圖片 or 檔案
var sql_file = @"SELECT * FROM operation_record_file WHERE Deleted = 0 AND RecordId = @RecordId";
result.RecodeFiles = (await conn.QueryAsync<OperationRecodeFile>(sql_file, new { RecordId = result.Id })).ToList();
result.RecordFiles = (await conn.QueryAsync<OperationRecordFile>(sql_file, new { RecordId = result.Id })).ToList();
//取得負責人員
var sql_operation_record_personnel = @"SELECT UserId FROM operation_record_personnel WHERE Deleted = 0 AND OperationRecordId = @OperationRecordId";
result.WorkPersonIds = (await conn.QueryAsync<int>(sql_operation_record_personnel, new { OperationRecordId = result.Id })).ToList();
}
}
catch (Exception exception)
{
@ -335,7 +342,7 @@ namespace SolarPower.Repository.Implement
/// <param name="entity"></param>
/// <param name="properties"></param>
/// <returns></returns>
public async Task<int> AddOneOperationRecodeAsync(OperationRecode entity, List<string> properties)
public async Task<int> AddOneOperationRecordAsync(OperationRecord entity, List<string> properties)
{
var id = 0;
using (IDbConnection conn = _databaseHelper.GetConnection())
@ -375,7 +382,7 @@ namespace SolarPower.Repository.Implement
/// <param name="properties"></param>
/// <param name="db_name"></param>
/// <returns></returns>
public async Task UpdateOperationRecodeAsync(UpdateOperationRecode entity, List<string> properties)
public async Task UpdateOperationRecordAsync(UpdateOperationRecord entity, List<string> properties)
{
using (IDbConnection conn = this._databaseHelper.GetConnection())
{
@ -402,7 +409,7 @@ namespace SolarPower.Repository.Implement
}
}
public async Task DeleteOneOperationRecodeAsync(int id)
public async Task DeleteOneOperationRecordAsync(int id)
{
using (IDbConnection conn = this._databaseHelper.GetConnection())
{
@ -436,7 +443,7 @@ namespace SolarPower.Repository.Implement
/// <param name="entity"></param>
/// <param name="properties"></param>
/// <returns></returns>
public async Task<int> AddOperationRecodeFilesAsync(List<OperationRecodeFile> entity, List<string> properties)
public async Task<int> AddOperationRecordFilesAsync(List<OperationRecordFile> entity, List<string> properties)
{
int count;
using (IDbConnection conn = _databaseHelper.GetConnection())
@ -466,9 +473,9 @@ namespace SolarPower.Repository.Implement
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public async Task<OperationRecodeFile> GetOneOperationRecodeFileAsync(int id)
public async Task<OperationRecordFile> GetOneOperationRecordFileAsync(int id)
{
OperationRecodeFile result;
OperationRecordFile result;
using (IDbConnection conn = this._databaseHelper.GetConnection())
{
@ -479,7 +486,7 @@ namespace SolarPower.Repository.Implement
FROM operation_record_file
WHERE Deleted = 0 AND Id = @Id";
result = await conn.QueryFirstOrDefaultAsync<OperationRecodeFile>(sql, new { Id = id });
result = await conn.QueryFirstOrDefaultAsync<OperationRecordFile>(sql, new { Id = id });
}
catch (Exception exception)
{
@ -498,7 +505,7 @@ namespace SolarPower.Repository.Implement
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public async Task DeleteOneOperationRecodeFile(int id)
public async Task DeleteOneOperationRecordFile(int id)
{
using (IDbConnection conn = this._databaseHelper.GetConnection())
{
@ -598,5 +605,82 @@ namespace SolarPower.Repository.Implement
}
}
}
public async Task AddOperationRecordPersonnelAsync(List<OperationRecordPersonnel> entity, List<string> properties)
{
int count;
using (IDbConnection conn = _databaseHelper.GetConnection())
{
conn.Open();
try
{
string sql = GenerateInsertQueryWithCustomTable(properties, "operation_record_personnel");
count = await conn.ExecuteAsync(sql, entity);
}
catch (Exception exception)
{
throw exception;
}
finally
{
conn.Close();
}
//return count;
}
}
public async Task<List<int>> GetOperationRecordPersonnelIdsByOperationRecordId(int operationRecordId)
{
List<int> result;
using (IDbConnection conn = this._databaseHelper.GetConnection())
{
conn.Open();
try
{
var sql = @$"SELECT UserId FROM operation_record_personnel WHERE Deleted = 0 AND OperationRecordId = @OperationRecordId";
result = (await conn.QueryAsync<int>(sql, new { OperationRecordId = operationRecordId })).ToList();
}
catch (Exception exception)
{
throw exception;
}
finally
{
conn.Close();
}
return result;
}
}
public async Task DeleteOperationRecordPersonnel(List<OperationRecordPersonnel> operationPersonnels)
{
using (IDbConnection conn = this._databaseHelper.GetConnection())
{
conn.Open();
using (var trans = conn.BeginTransaction())
{
try
{
var sql = $"UPDATE operation_record_personnel SET Deleted = 1 WHERE OperationRecordId = @OperationRecordId AND UserId = @UserId";
await conn.ExecuteAsync(sql, operationPersonnels, trans);
trans.Commit();
}
catch (Exception exception)
{
trans.Rollback();
throw exception;
}
finally
{
conn.Close();
}
}
}
}
}
}

View File

@ -4184,7 +4184,7 @@ namespace SolarPower.Repository.Implement
}
sql = string.Join(" UNION ", sql_perSiteDB);
sql = "(" + sql + ") ORDER BY Priority";
sql = "(" + sql + ") ORDER BY c.Priority, inv.CreatedAt";
result = (await conn.QueryAsync<PowerStationInverter>(sql, new { Filter = filter })).ToList();
}

View File

@ -21,14 +21,14 @@ namespace SolarPower.Repository.Interface
/// </summary>
/// <param name="filter"></param>
/// <returns></returns>
Task<List<OperationRecodeDataTable>> GetAllRecodeByFilterAsync(PostOperationRecodeFilter filter);
Task<List<OperationRecordDataTable>> GetAllRecordByFilterAsync(PostOperationRecordFilter filter);
/// <summary>
/// 透過Id取得單一筆運維作業記錄
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
Task<OperationRecode> GetOneOperationRecodeAsync(int id);
Task<OperationRecord> GetOneOperationRecordAsync(int id);
/// <summary>
/// 新增一筆運維作業記錄
@ -36,7 +36,7 @@ namespace SolarPower.Repository.Interface
/// <param name="entity"></param>
/// <param name="properties"></param>
/// <returns></returns>
Task<int> AddOneOperationRecodeAsync(OperationRecode entity, List<string> properties);
Task<int> AddOneOperationRecordAsync(OperationRecord entity, List<string> properties);
/// <summary>
/// 修改運維作業記錄
@ -44,7 +44,7 @@ namespace SolarPower.Repository.Interface
/// <param name="entity"></param>
/// <param name="properties"></param>
/// <returns></returns>
Task UpdateOperationRecodeAsync(UpdateOperationRecode entity, List<string> properties);
Task UpdateOperationRecordAsync(UpdateOperationRecord entity, List<string> properties);
/// <summary>
/// 新增運維作業記錄的檔案
@ -52,29 +52,35 @@ namespace SolarPower.Repository.Interface
/// <param name="entity"></param>
/// <param name="properties"></param>
/// <returns></returns>
Task<int> AddOperationRecodeFilesAsync(List<OperationRecodeFile> entity, List<string> properties);
Task<int> AddOperationRecordFilesAsync(List<OperationRecordFile> entity, List<string> properties);
Task DeleteOneOperationRecodeAsync(int id);
Task DeleteOneOperationRecordAsync(int id);
/// <summary>
/// 透過Id取得單一運維作業記錄檔案
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
Task<OperationRecodeFile> GetOneOperationRecodeFileAsync(int id);
Task<OperationRecordFile> GetOneOperationRecordFileAsync(int id);
/// <summary>
/// 透過Id軟刪除運維作業記錄檔案
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
Task DeleteOneOperationRecodeFile(int id);
Task DeleteOneOperationRecordFile(int id);
Task<List<OperationCreatePlan>> GetOperationSchedules();
Task<List<MyUser>> GetOperationPersonnel(int PowerStationId);
Task InsertNoticeSchedule(List<MyUser> personal, string Title, string content);
Task AddOperationRecordPersonnelAsync(List<OperationRecordPersonnel> entity, List<string> properties);
Task<List<int>> GetOperationRecordPersonnelIdsByOperationRecordId(int operationRecordId);
Task DeleteOperationRecordPersonnel(List<OperationRecordPersonnel> operationRecordPersonnels);
}
}

View File

@ -403,9 +403,9 @@
$('#js_list_accordion').on("change", 'input[name="selectedInverterLayer2[]"]', function (event) {
if (this.checked) {
$(this).parents(".list-group-item").find('input[name="selectedInverterId[]"]').prop("checked", true).trigger("change");
$(this).parents(".selected_group").find('input[name="selectedInverterId[]"]').prop("checked", true).trigger("change");
} else {
$(this).parents(".list-group-item").find('input[name="selectedInverterId[]"]').prop("checked", false).trigger("change");
$(this).parents(".selected_group").find('input[name="selectedInverterId[]"]').prop("checked", false).trigger("change");
}
});

View File

@ -435,6 +435,8 @@
}
}
console.log("default_compare_col", default_compare_col)
ReloadHighCharts();
});

View File

@ -79,13 +79,13 @@
<span class="fal fa-file-excel mr-1"></span>
匯出
</button>
<a href="javascript:;" class="btn btn-success waves-effect waves-themed mb-3 mr-2" onclick="AddRecode()">
<a href="javascript:;" class="btn btn-success waves-effect waves-themed mb-3 mr-2" onclick="AddRecord()">
<span class="fal fa-plus mr-1"></span>
維修單
</a>
</div>
<div class="frame-wrap">
<table id="operation_recode_table" class="table table-bordered table-hover m-0 text-center">
<table id="operation_record_table" class="table table-bordered table-hover m-0 text-center">
<thead class="thead-themed">
<tr>
<th>電廠</th>
@ -130,7 +130,7 @@
</div>
</div>
<div class="modal fade" id="recode-form-modal" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static" data-keyboard="false">
<div class="modal fade" id="record-form-modal" tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static" data-keyboard="false">
<div class="modal-dialog modal-dialog-centered modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
@ -142,7 +142,7 @@
</button>
</div>
<div class="modal-body">
<form id="recode-form">
<form id="record-form">
<div class="row mb-3">
<div class="col-lg-6">
<div class="form-group">
@ -176,9 +176,9 @@
</div>
</div>
<div class="col-lg-6">
<div class="form-group">
<div class="">
<label class="form-label" for="work_person_select_modal">執行人員</label>
<select class="form-control" id="work_person_select_modal">
<select class="form-control" id="work_person_select_modal" multiple="multiple">
</select>
</div>
</div>
@ -231,14 +231,14 @@
<div class="col-2">
<p>檔案上傳</p>
</div>
<div id="recode_files_div" class="col-10">
<div id="record_files_div" class="col-10">
<div class="row px-3 mb-3 d-flex justify-content-start align-items-center img-zoom-div">
</div>
</div>
</div>
<div class="row px-3">
<form id="recode-file-form" class="dropzone needsclick dz-clickable col-12" style="min-height: 7rem;">
<form id="record-file-form" class="dropzone needsclick dz-clickable col-12" style="min-height: 7rem;">
@*<div class="fallback">
<input type="file" multiple />
</div>*@
@ -253,7 +253,7 @@
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
<button type="button" class="btn btn-primary" id="save-recode-btn" onclick="SaveRecode()">確定</button>
<button type="button" class="btn btn-primary" id="save-record-btn" onclick="SaveRecord()">確定</button>
</div>
</div>
</div>
@ -261,11 +261,11 @@
@section Scripts{
<script>
var operationRecodeTable;
var operationRecordTable;
var selected_id = 0; var selected_work_type = -1;
var recode;
var countOperationRecodeFile = 0;
var recodeFileDropzone;
var record;
var countOperationRecordFile = 0;
var recordFileDropzone;
var ids = new Array(0);//當前選擇縣市
var powerids = new Array(0);//當前選擇電站
var Allids = new Array(0);//全部縣市
@ -354,7 +354,7 @@
$("#power_station_select_modal").val($("#power_station_select_modal option:first").val()).trigger('change');
$('#Allcity').trigger("click");
operationRecodeTable.ajax.reload();
operationRecordTable.ajax.reload();
})
})
@ -383,10 +383,14 @@
$("#work_person_select_modal").append($("<option />").val(val.value).text(val.text));
});
if (recode != null || recode != undefined) {
$("#work_person_select_modal").val(recode.workPersonId);
if (record != null || record != undefined) {
$("#work_person_select_modal").val(record.workPersonIds);
}
}
$("#work_person_select_modal").select2({ dropdownParent: $('#record-form-modal') });
});
//查詢該電站的廠商
@ -407,12 +411,16 @@
}
$("#fix_firm_select_modal").val($("#fix_firm_select_modal option:first").val()).trigger('change');
if (record != undefined && record != null) {
$("#fix_firm_select_modal").val(record.fixFirm)
}
});
});
//#endregion
//#region 運維作業記錄 DataTable
operationRecodeTable = $("#operation_recode_table").DataTable({
operationRecordTable = $("#operation_record_table").DataTable({
"pageLength": 20,
"paging": true,
"lengthChange": false,
@ -437,7 +445,7 @@
}, {
"data": "operationPredict"
}, {
"data": "recodeFiles"
"data": "recordFiles"
}, {
"data": "finishTime"
},{
@ -457,7 +465,7 @@
if (cellData != null) {
cellData.forEach(function (value, index) {
CreateRecodeFileBox($(td).children(".row"), value, false);
CreateRecordFileBox($(td).children(".row"), value, false);
});
}
}
@ -492,7 +500,7 @@
$(row).attr('data-work-type', data.workType);
},
"ajax": {
"url": "/Operation/OperationRecodeList",
"url": "/Operation/OperationRecordList",
"type": "POST",
"data": function (d) {
d.PowerStationIds = powerids;
@ -544,29 +552,29 @@
document.getElementById(name).setAttribute("class", "btn btn-secondary waves-effect waves-themed");
}
document.getElementById("button" + type).setAttribute("class", "btn btn-success waves-effect waves-themed");
operationRecodeTable.ajax.reload();
operationRecordTable.ajax.reload();
}
//#endregion
//#region 改變日期
$('#date-range').on('change', function () {
operationRecodeTable.ajax.reload();
operationRecordTable.ajax.reload();
});
//#endregion
//#region 新增維修單
function AddRecode() {
function AddRecord() {
selected_id = 0;
$("#recode-form-modal .modal-title .main-title").html("維修單");
$("#recode-form-modal .modal-title .sub-title").html("");
$("#record-form-modal .modal-title .main-title").html("維修單");
$("#record-form-modal .modal-title .sub-title").html("");
$("#power_station_select_modal").attr("disabled", false);
$(".fix-div").show();
$("#recode-form").trigger("reset");
$("#record-form").trigger("reset");
$("input[name=status_modal][value='" + 0 + "']").prop('checked', true); //狀態
$("#recode_files_div > .row").empty();
$("#record_files_div > .row").empty();
$("#recode-form-modal").modal();
$("#record-form-modal").modal();
}
//#endregion
@ -621,7 +629,7 @@
powerids = [];
powerids = Newpowerids;
})
operationRecodeTable.ajax.reload();
operationRecordTable.ajax.reload();
}
function Allcity2() {
@ -691,7 +699,7 @@
powerids = [];
}
})
operationRecodeTable.ajax.reload();
operationRecordTable.ajax.reload();
})
}
//#endregion
@ -714,7 +722,7 @@
powerids = [];
}
})
operationRecodeTable.ajax.reload();
operationRecordTable.ajax.reload();
}
//#endregion
@ -764,7 +772,7 @@
powerids = [];
powerids = Newpowerids;
})
operationRecodeTable.ajax.reload();
operationRecordTable.ajax.reload();
})
//#endregion
@ -779,35 +787,35 @@
else {
powerids.remove(classid[1]);
}
operationRecodeTable.ajax.reload();
operationRecordTable.ajax.reload();
})
//#endregion
//#region 點擊圖片放大
$('#operation_recode_table').on("click", "img.img-zoom", function () {
$('#operation_record_table').on("click", "img.img-zoom", function () {
var _this = $(this);//將當前的pimg元素作為_this傳入函式
imgShow("#img-zoom-outer-div", "#innerdiv", "#bigimg", _this);
});
//#endregion
//#region 編輯表單內容
$('#operation_recode_table').on("click", "a.edit-btn", function () {
$('#operation_record_table').on("click", "a.edit-btn", function () {
work_type = $(this).parents('tr').attr('data-work-type');
if (work_type == 0) {
$("#recode-form-modal .modal-title .main-title").html("清洗單 - ");
$("#record-form-modal .modal-title .main-title").html("清洗單 - ");
} else if (work_type == 1) {
$("#recode-form-modal .modal-title .main-title").html("巡檢單 - ");
$("#record-form-modal .modal-title .main-title").html("巡檢單 - ");
} else {
$("#recode-form-modal .modal-title .main-title").html("維修單 - ");
$("#record-form-modal .modal-title .main-title").html("維修單 - ");
}
selected_id = $(this).parents('tr').attr('data-id');
//取得單一記錄表單
var url = "/Operation/GetOneOperationRecode/";
var url = "/Operation/GetOneOperationRecord/";
var send_data = {
id: selected_id
@ -819,62 +827,67 @@
return;
}
recode = rel.data;
record = rel.data;
countOperationRecodeFile = recode.recodeFiles.length;
countOperationRecordFile = record.recordFiles.length;
$("#recode-form-modal .modal-title .sub-title").html(recode.powerStationName);
$("#record-form-modal .modal-title .sub-title").html(record.powerStationName);
$("#power_station_select_modal").val(recode.powerStationId).trigger('change');
$("#power_station_select_modal").val(record.powerStationId).trigger('change');
$("#power_station_select_modal").attr("disabled", true);
$("#work_time_modal").val(recode.workTime);
$("#work_time_modal").val(record.workTime);
var status = -1;
if (recode.status == 0 || recode.status == 2) {
if (record.status == 0 || record.status == 2) {
status = 0;
} else if (recode.status == 1 || recode.status == 3) {
} else if (record.status == 1 || record.status == 3) {
status = 1;
}
$("input[name=status_modal][value='" + status + "']").prop('checked', true); //狀態
$('#work_person_select_modal').val(recode.workPersonId);
$('#work_person_select_modal').val(record.workPersonIds).trigger("change");
if (work_type != 2) {
$(".fix-div").hide();
} else {
$(".fix-div").show();
$("#error_code_modal").val(recode.errorCode);
$("#fix_do_modal").val(recode.fixDo);
$("#error_code_modal").val(record.errorCode);
$("#fix_do_modal").val(record.fixDo);
}
$("#notice_textarea_modal").val(recode.notice);
$("#description_textarea_modal").val(recode.description);
$("#fix_firm_select_modal").val(record.fixFirm).trigger("change");
$("#notice_textarea_modal").val(record.notice);
$("#description_textarea_modal").val(record.description);
var str = "";
RecodeFileBox = $("#recode_files_div > .row");
RecodeFileBox.empty();
recode.recodeFiles.forEach(function (value, index) {
CreateRecodeFileBox(RecodeFileBox, value, true);
RecordFileBox = $("#record_files_div > .row");
RecordFileBox.empty();
record.recordFiles.forEach(function (value, index) {
CreateRecordFileBox(RecordFileBox, value, true);
});
$("#recode-form-modal").modal();
$("#record-form-modal").modal();
}, 'json');
});
//#endregion
//#region 表單驗證
$("#recode-form").validate({
$("#record-form").validate({
rules: {
},
});
//#endregion
//#region 儲存表單資料
function SaveRecode() {
function SaveRecord() {
if ($("#recode-form").valid()) {
var url = "/Operation/SaveOperationRecode";
if ($("#record-form").valid()) {
var url = "/Operation/SaveOperationRecord";
var formData = new FormData();
@*var work_person_ids = $.map($("#work_person_select_modal").val(), function (item) {
return parseInt(item);
})*@
formData.append("Id", selected_id);
formData.append("PowerStationId", $("#power_station_select_modal").val());
formData.append("WorkType", selected_work_type);
@ -882,7 +895,9 @@
formData.append("FixDo", $("#fix_do_modal").val());
formData.append("FixFirm", $("#fix_firm_select_modal").val());
formData.append("Status", $("input[name=status_modal]:checked").val());
formData.append("WorkPersonId", $("#work_person_select_modal").val());
$("#work_person_select_modal").val().forEach(function (item) {
formData.append("WorkPersonIds", parseInt(item));
});
formData.append("WorkTime", $("#work_time_modal").val());
formData.append("Notice", $("#notice_textarea_modal").val());
formData.append("Description", $("#description_textarea_modal").val());
@ -900,7 +915,7 @@
return;
}
var myDropzone = Dropzone.forElement("#recode-file-form");
var myDropzone = Dropzone.forElement("#record-file-form");
if (myDropzone.files.length > 0) {
@ -915,16 +930,16 @@
}
toast_ok(rel.msg);
$('#recode-form-modal').modal('hide');
recodeFileDropzone.removeAllFiles();
$('#record-form-modal').modal('hide');
recordFileDropzone.removeAllFiles();
operationRecodeTable.ajax.reload();
operationRecordTable.ajax.reload();
});
} else {
$('#recode-form-modal').modal('hide');
$('#record-form-modal').modal('hide');
myDropzone.removeAllFiles();
operationRecodeTable.ajax.reload();
operationRecordTable.ajax.reload();
}
}
});
@ -933,7 +948,7 @@
//#endregion
//#region 刪除公司
$('#operation_recode_table').on("click", "button.del-btn", function () {
$('#operation_record_table').on("click", "button.del-btn", function () {
selected_id = $(this).parents('tr').attr('data-id');
Swal.fire(
@ -948,7 +963,7 @@
}).then(function (result) {
if (result.value) {
//刪除單一運維紀錄
var url = "/Operation/DeleteOneOperationRecode/";
var url = "/Operation/DeleteOneOperationRecord/";
var send_data = {
Id: selected_id
}
@ -963,7 +978,7 @@
}
toast_ok(rel.msg);
operationRecodeTable.ajax.reload();
operationRecordTable.ajax.reload();
}, 'json');
}
});
@ -993,8 +1008,8 @@
//#region 表單檔案資料
Dropzone.autoDiscover = false;
recodeFileDropzone = new Dropzone("#recode-file-form", {
url: "/Operation/SaveOperationRecodeFile",
recordFileDropzone = new Dropzone("#record-file-form", {
url: "/Operation/SaveOperationRecordFile",
acceptedFiles: "image/*, application/pdf,.doc,.docx,.xls,.xlsx",
autoProcessQueue: false,
parallelUploads: 5,
@ -1007,14 +1022,14 @@
var myDropzone = this;
myDropzone.on("sending", function (file, xhr, data) {
if ((countOperationRecodeFile + myDropzone.files.length) > 5) {
if ((countOperationRecordFile + myDropzone.files.length) > 5) {
toast_warning("檔案總數量不可超過 5 張");
myDropzone.removeFile(file);
return;
} else {
data.append("Id", selected_id);
data.append("RecodeFiles", file);
data.append("RecordFiles", file);
}
});
@ -1024,7 +1039,7 @@
//#endregion
//#region 產生檔案html
function CreateRecodeFileBox(dom, value, show_del_btn) {
function CreateRecordFileBox(dom, value, show_del_btn) {
var str = "";
str += '<div class="col-2 px-0 py-2 mx-2">';
var split = value.fileName.split(".");
@ -1041,7 +1056,7 @@
}
if (show_del_btn) {
str += '<a href="javascript:;" class="del-operation-recode-file-btn" data-id="' + value.id + '">';
str += '<a href="javascript:;" class="del-operation-record-file-btn" data-id="' + value.id + '">';
str += '<span class="badge border border-light rounded-pill bg-danger-500 position-absolute pos-top pos-right"><i class="fal fa-times"></i></span>';
str += '</a>';
}
@ -1052,7 +1067,7 @@
//#endregion
//#region 刪除檔案
$('#recode_files_div').on("click", "a.del-operation-recode-file-btn", function () {
$('#record_files_div').on("click", "a.del-operation-record-file-btn", function () {
var selectedFileId = $(this).attr("data-id");
@ -1069,7 +1084,7 @@
}).then(function (result) {
if (result.value) {
var url = "/Operation/DeleteOperationRecodeFile";
var url = "/Operation/DeleteOperationRecordFile";
var send_data = {
ReocdeId: selected_id,
@ -1092,7 +1107,7 @@
//#region 匯出excel
function ExportExcel() {
var url = "/Operation/ExportOperationRecodeExcel";
var url = "/Operation/ExportOperationRecordExcel";
var send_data = {
CityIds: [3],
PowerStationIds: [1]
@ -1172,7 +1187,7 @@
$(".status-type").removeClass("btn-success").addClass("btn-secondary");
}
$(e).removeClass("btn-secondary").addClass("btn-success");
operationRecodeTable.ajax.reload();
operationRecordTable.ajax.reload();
}
//#endregion