diff --git a/SolarPower/Controllers/OperationController.cs b/SolarPower/Controllers/OperationController.cs index 9a00d89..1a98979 100644 --- a/SolarPower/Controllers/OperationController.cs +++ b/SolarPower/Controllers/OperationController.cs @@ -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 { 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 apiResult = new ApiResult(); 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"; @@ -113,15 +114,15 @@ namespace SolarPower.Controllers "CreatedBy" }; - - - 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 /// /// [HttpPost] - public async Task OperationRecodeListAsync(PostOperationRecodeFilter post) + public async Task OperationRecordListAsync(PostOperationRecordFilter post) { - ApiResult> apiResult = new ApiResult>(); + ApiResult> apiResult = new ApiResult>(); int totalRecords = 0; //總資料筆數 int recFilter = 0; //過濾後資料筆數 - List recodes = null; + List 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 = @$"填寫表單"; + record.FormId = @$"填寫表單"; } else { - recode.FormId = @$"{recode.FormId}"; + record.FormId = @$"{record.FormId}"; } - 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 /// /// [HttpPost] - public async Task> GetOneOperationRecode(int id) + public async Task> GetOneOperationRecord(int id) { - ApiResult apiResult = new ApiResult(); + ApiResult apiResult = new ApiResult(); - 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 /// /// /// - public async Task> SaveOperationRecode([FromForm] PostOperationRecode post) + public async Task> SaveOperationRecord([FromForm] PostOperationRecord post) { ApiResult apiResult = new ApiResult(); - 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 properties = new List() - { - "FormId", - "SerialNumber", - "PowerStationId", - "WorkType", - "ErrorCode", - "FixDo", - "FixFirm", - "Status", - "WorkPersonId", - "FinishTime", - "WorkTime", - "Notice", - "Description", - "CreatedBy" - }; + List properties = new List() + { + "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 insertOperationRecordPersonnels = new List(); + + foreach (var op in post.WorkPersonIds) + { + OperationRecordPersonnel operationRecordPersonnel = new OperationRecordPersonnel(); + operationRecordPersonnel.OperationRecordId = id; + operationRecordPersonnel.UserId = op; + + insertOperationRecordPersonnels.Add(operationRecordPersonnel); + } + + List operationRecordPersonnelProperties = new List() + { + "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 origOperationRecordPersonnels = null; //原先的運維人員 + + origOperationRecordPersonnels = await operationRepository.GetOperationRecordPersonnelIdsByOperationRecordId(operationRecord.Id); + + //判斷新進來的執行人員是否要歸類到新增 or 刪除 + #region 刪除執行人員編號 + if(post.WorkPersonIds != null && post.WorkPersonIds.Count() > 0) + { + //找出要刪除的 + List deleteOperationRecordPersonnelIds = origOperationRecordPersonnels.Where(x => !post.WorkPersonIds.Contains(x)).ToList(); + + List deleteOperationRecordPersonnels = new List(); + 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 insertOperationRecordPersonnelIds = post.WorkPersonIds.Where(x => !origOperationRecordPersonnels.Contains(x)).ToList(); + + List insertOperationRecordPersonnels = new List(); + + 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 operationRecordPersonnelProperties = new List() + { + "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> DeleteOneOperationRecode(int id) + public async Task> DeleteOneOperationRecord(int id) { ApiResult apiResult = new ApiResult(); 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 /// /// [HttpPost] - public async Task> SaveOperationRecodeFile([FromForm] PostOperationRecode post) + public async Task> SaveOperationRecordFile([FromForm] PostOperationRecord post) { - ApiResult apiResult = new ApiResult(); + ApiResult apiResult = new ApiResult(); - 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 operationRecodeFiles; + List 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(); + operationRecordFiles = new List(); - 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 fileProperties = new List() @@ -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> DeleteOperationRecodeFile(PostOperationRecodeIdAndSelectedId post) + public async Task> DeleteOperationRecordFile(PostOperationRecordIdAndSelectedId post) { ApiResult apiResult = new ApiResult(); - 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>> ExportOperationRecodeExcel(PostOperationRecodeFilter post) + public async Task>> ExportOperationRecordExcel(PostOperationRecordFilter post) { - ApiResult> apiResult = new ApiResult>(); + ApiResult> apiResult = new ApiResult>(); - List recodes = null; + List 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 = "" + file.FileName + ""; - if(recode.HyperLinks == null) + if (record.HyperLinks == null) { - recode.HyperLinks = new List(); + record.HyperLinks = new List(); } - 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); } diff --git a/SolarPower/Models/Operation.cs b/SolarPower/Models/Operation.cs index 84e0401..42be874 100644 --- a/SolarPower/Models/Operation.cs +++ b/SolarPower/Models/Operation.cs @@ -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 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 RecodeFiles { get; set; } + public List 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 /// /// 運維作業記錄的搜尋條件 /// - public class PostOperationRecodeFilter + public class PostOperationRecordFilter { public List CityIds { get; set; } //縣市編號 public List PowerStationIds { get; set; } //電站編號 @@ -226,7 +226,7 @@ namespace SolarPower.Models /// /// 運維作業記錄的表單 /// - public class OperationRecodeDataTable : OperationRecode + public class OperationRecordDataTable : OperationRecord { public string WorkTypeText { @@ -275,7 +275,7 @@ namespace SolarPower.Models public List 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 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 /// /// 針對運維作業記錄檔案 /// - 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; } + } + } diff --git a/SolarPower/Repository/Implement/OperationRepository.cs b/SolarPower/Repository/Implement/OperationRepository.cs index 5849cdf..b7cdcb4 100644 --- a/SolarPower/Repository/Implement/OperationRepository.cs +++ b/SolarPower/Repository/Implement/OperationRepository.cs @@ -198,9 +198,9 @@ namespace SolarPower.Repository.Implement /// /// /// - public async Task> GetAllRecodeByFilterAsync(PostOperationRecodeFilter filter) + public async Task> GetAllRecordByFilterAsync(PostOperationRecordFilter filter) { - List result; + List 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(sql, + result = (await conn.QueryAsync(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(sql_file, new { RecordId = x.Id })).ToList(); + x.RecordFiles = (await conn.QueryAsync(sql_file, new { RecordId = x.Id })).ToList(); } } catch (Exception exception) @@ -293,9 +293,9 @@ namespace SolarPower.Repository.Implement /// /// /// - public async Task GetOneOperationRecodeAsync(int id) + public async Task 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(sql, new { Id = id }); + result = await conn.QueryFirstOrDefaultAsync(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(sql_file, new { RecordId = result.Id })).ToList(); + result.RecordFiles = (await conn.QueryAsync(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(sql_operation_record_personnel, new { OperationRecordId = result.Id })).ToList(); } + + } catch (Exception exception) { @@ -335,7 +342,7 @@ namespace SolarPower.Repository.Implement /// /// /// - public async Task AddOneOperationRecodeAsync(OperationRecode entity, List properties) + public async Task AddOneOperationRecordAsync(OperationRecord entity, List properties) { var id = 0; using (IDbConnection conn = _databaseHelper.GetConnection()) @@ -375,7 +382,7 @@ namespace SolarPower.Repository.Implement /// /// /// - public async Task UpdateOperationRecodeAsync(UpdateOperationRecode entity, List properties) + public async Task UpdateOperationRecordAsync(UpdateOperationRecord entity, List 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 /// /// /// - public async Task AddOperationRecodeFilesAsync(List entity, List properties) + public async Task AddOperationRecordFilesAsync(List entity, List properties) { int count; using (IDbConnection conn = _databaseHelper.GetConnection()) @@ -466,9 +473,9 @@ namespace SolarPower.Repository.Implement /// /// /// - public async Task GetOneOperationRecodeFileAsync(int id) + public async Task 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(sql, new { Id = id }); + result = await conn.QueryFirstOrDefaultAsync(sql, new { Id = id }); } catch (Exception exception) { @@ -498,7 +505,7 @@ namespace SolarPower.Repository.Implement /// /// /// - 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 entity, List 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> GetOperationRecordPersonnelIdsByOperationRecordId(int operationRecordId) + { + List 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(sql, new { OperationRecordId = operationRecordId })).ToList(); + } + catch (Exception exception) + { + throw exception; + } + finally + { + conn.Close(); + } + return result; + } + } + + public async Task DeleteOperationRecordPersonnel(List 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(); + } + } + } + } } } diff --git a/SolarPower/Repository/Implement/PowerStationRepository.cs b/SolarPower/Repository/Implement/PowerStationRepository.cs index d5f325b..ac3ed07 100644 --- a/SolarPower/Repository/Implement/PowerStationRepository.cs +++ b/SolarPower/Repository/Implement/PowerStationRepository.cs @@ -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(sql, new { Filter = filter })).ToList(); } diff --git a/SolarPower/Repository/Interface/IOperationRepository.cs b/SolarPower/Repository/Interface/IOperationRepository.cs index 4f8e253..9ab50a8 100644 --- a/SolarPower/Repository/Interface/IOperationRepository.cs +++ b/SolarPower/Repository/Interface/IOperationRepository.cs @@ -21,14 +21,14 @@ namespace SolarPower.Repository.Interface /// /// /// - Task> GetAllRecodeByFilterAsync(PostOperationRecodeFilter filter); + Task> GetAllRecordByFilterAsync(PostOperationRecordFilter filter); /// /// 透過Id,取得單一筆運維作業記錄 /// /// /// - Task GetOneOperationRecodeAsync(int id); + Task GetOneOperationRecordAsync(int id); /// /// 新增一筆運維作業記錄 @@ -36,7 +36,7 @@ namespace SolarPower.Repository.Interface /// /// /// - Task AddOneOperationRecodeAsync(OperationRecode entity, List properties); + Task AddOneOperationRecordAsync(OperationRecord entity, List properties); /// /// 修改運維作業記錄 @@ -44,7 +44,7 @@ namespace SolarPower.Repository.Interface /// /// /// - Task UpdateOperationRecodeAsync(UpdateOperationRecode entity, List properties); + Task UpdateOperationRecordAsync(UpdateOperationRecord entity, List properties); /// /// 新增運維作業記錄的檔案 @@ -52,29 +52,35 @@ namespace SolarPower.Repository.Interface /// /// /// - Task AddOperationRecodeFilesAsync(List entity, List properties); + Task AddOperationRecordFilesAsync(List entity, List properties); - Task DeleteOneOperationRecodeAsync(int id); + Task DeleteOneOperationRecordAsync(int id); /// /// 透過Id,取得單一運維作業記錄檔案 /// /// /// - Task GetOneOperationRecodeFileAsync(int id); + Task GetOneOperationRecordFileAsync(int id); /// /// 透過Id,軟刪除運維作業記錄檔案 /// /// /// - Task DeleteOneOperationRecodeFile(int id); + Task DeleteOneOperationRecordFile(int id); Task> GetOperationSchedules(); Task> GetOperationPersonnel(int PowerStationId); Task InsertNoticeSchedule(List personal, string Title, string content); + + Task AddOperationRecordPersonnelAsync(List entity, List properties); + + Task> GetOperationRecordPersonnelIdsByOperationRecordId(int operationRecordId); + + Task DeleteOperationRecordPersonnel(List operationRecordPersonnels); } } diff --git a/SolarPower/Views/AnalysisInverter/Index.cshtml b/SolarPower/Views/AnalysisInverter/Index.cshtml index 02ae2c4..6cabe57 100644 --- a/SolarPower/Views/AnalysisInverter/Index.cshtml +++ b/SolarPower/Views/AnalysisInverter/Index.cshtml @@ -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"); } }); diff --git a/SolarPower/Views/AnalysisStationInfo/Index.cshtml b/SolarPower/Views/AnalysisStationInfo/Index.cshtml index 70eb257..3f00fb8 100644 --- a/SolarPower/Views/AnalysisStationInfo/Index.cshtml +++ b/SolarPower/Views/AnalysisStationInfo/Index.cshtml @@ -435,6 +435,8 @@ } } + console.log("default_compare_col", default_compare_col) + ReloadHighCharts(); }); diff --git a/SolarPower/Views/Operation/OperationRecord.cshtml b/SolarPower/Views/Operation/OperationRecord.cshtml index 313c5f1..5c684a3 100644 --- a/SolarPower/Views/Operation/OperationRecord.cshtml +++ b/SolarPower/Views/Operation/OperationRecord.cshtml @@ -79,13 +79,13 @@ 匯出 - + 維修單
- +
@@ -130,7 +130,7 @@ -
電廠