Merge branch 'master' of https://github.com/shanghohui-Company/SolarPower
This commit is contained in:
commit
4d7e31953a
@ -1,6 +1,9 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using SolarPower.Models;
|
using SolarPower.Models;
|
||||||
|
using SolarPower.Models.PowerStation;
|
||||||
using SolarPower.Models.Role;
|
using SolarPower.Models.Role;
|
||||||
using SolarPower.Repository.Interface;
|
using SolarPower.Repository.Interface;
|
||||||
using System;
|
using System;
|
||||||
@ -15,16 +18,22 @@ namespace SolarPower.Controllers
|
|||||||
public class OperationController : MyBaseController<OperationController>
|
public class OperationController : MyBaseController<OperationController>
|
||||||
{
|
{
|
||||||
private readonly IOperationRepository operationRepository;
|
private readonly IOperationRepository operationRepository;
|
||||||
private string operationRecordFilePath = "/upload/operation_record/";
|
private readonly IPowerStationRepository powerStationRepository;
|
||||||
|
private readonly IUserRepository userRepository;
|
||||||
|
private readonly INoticeScheduleRepository noticeScheduleRepository;
|
||||||
|
private string operationRecordFilePath = "/upload/operation_recode/";
|
||||||
private string operationRecordSaveAsPath = "";
|
private string operationRecordSaveAsPath = "";
|
||||||
|
public IWebHostEnvironment environment;
|
||||||
|
|
||||||
public OperationController(
|
public OperationController(
|
||||||
IOperationRepository operationRepository) : base()
|
IOperationRepository operationRepository, IWebHostEnvironment environment,IPowerStationRepository powerStationRepository,IUserRepository userRepository,INoticeScheduleRepository noticeScheduleRepository) : base()
|
||||||
{
|
{
|
||||||
|
this.noticeScheduleRepository = noticeScheduleRepository;
|
||||||
|
this.userRepository = userRepository;
|
||||||
|
this.powerStationRepository = powerStationRepository;
|
||||||
this.operationRepository = operationRepository;
|
this.operationRepository = operationRepository;
|
||||||
|
this.environment = environment;
|
||||||
operationRecordSaveAsPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "upload", "operation_record");
|
operationRecordSaveAsPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "upload", "operation_recode");
|
||||||
}
|
}
|
||||||
|
|
||||||
public IActionResult Index()
|
public IActionResult Index()
|
||||||
@ -534,8 +543,6 @@ namespace SolarPower.Controllers
|
|||||||
finishTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
finishTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||||||
}
|
}
|
||||||
|
|
||||||
using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
|
|
||||||
{
|
|
||||||
operationRecord = new OperationRecord()
|
operationRecord = new OperationRecord()
|
||||||
{
|
{
|
||||||
FormId = "op" + DateTime.Now.ToString("yyyyMMdd") + tempSerialNumber,
|
FormId = "op" + DateTime.Now.ToString("yyyyMMdd") + tempSerialNumber,
|
||||||
@ -595,9 +602,80 @@ namespace SolarPower.Controllers
|
|||||||
};
|
};
|
||||||
|
|
||||||
await operationRepository.AddOperationRecordPersonnelAsync(insertOperationRecordPersonnels, operationRecordPersonnelProperties);
|
await operationRepository.AddOperationRecordPersonnelAsync(insertOperationRecordPersonnels, operationRecordPersonnelProperties);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
scope.Complete();
|
|
||||||
|
if (post.WorkPersonIds.Count != 0)
|
||||||
|
{
|
||||||
|
var powerstations = await powerStationRepository.GetOneAsync(post.PowerStationId);
|
||||||
|
List<NoticeSchedule> noticeSchedules = new List<NoticeSchedule>();
|
||||||
|
foreach (var person in post.WorkPersonIds)
|
||||||
|
{
|
||||||
|
var fixtype = post.WorkType switch
|
||||||
|
{
|
||||||
|
0 => "清洗",
|
||||||
|
1 => "巡檢",
|
||||||
|
2 => "維修",
|
||||||
|
_ => ""
|
||||||
|
};
|
||||||
|
var user = await userRepository.GetOneAsync(person);
|
||||||
|
NoticeSchedule schedule = new NoticeSchedule()
|
||||||
|
{
|
||||||
|
EmailType = 3,
|
||||||
|
Type = 1,
|
||||||
|
UserId = person,
|
||||||
|
RecipientName = user.Name,
|
||||||
|
RecipientEmail = user.Email,
|
||||||
|
Subject = powerstations.Name + "-" + fixtype + "-" + post.WorkTime,
|
||||||
|
Content = "維修項目" + post.FixDo + "</br>注意事項 :" + post.Notice,
|
||||||
|
};
|
||||||
|
noticeSchedules.Add(schedule);
|
||||||
}
|
}
|
||||||
|
properties = new List<string>()
|
||||||
|
{
|
||||||
|
"UserId",
|
||||||
|
"EmailType",
|
||||||
|
"RecipientEmail",
|
||||||
|
"Subject",
|
||||||
|
"Content",
|
||||||
|
"RecipientName",
|
||||||
|
"Type",
|
||||||
|
"ExceptionId"
|
||||||
|
};
|
||||||
|
await noticeScheduleRepository.AddAnyThing<List<NoticeSchedule>>(noticeSchedules, properties, "notice_schedule");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (post.FixFirm != 0)
|
||||||
|
{
|
||||||
|
var powerstations = await powerStationRepository.GetOneAsync(post.PowerStationId);
|
||||||
|
var fixtype = operationRecord.WorkType switch
|
||||||
|
{
|
||||||
|
0 => "清洗",
|
||||||
|
1 => "巡檢",
|
||||||
|
2 => "維修",
|
||||||
|
_ => ""
|
||||||
|
};
|
||||||
|
var powerstation = await powerStationRepository.GetOneAsync(post.PowerStationId);
|
||||||
|
var firm = await operationRepository.GetOneWithCustomDBNameAndTableAsync<OperationInfo>(post.FixFirm, powerstations.SiteDB, "operation_firm");
|
||||||
|
NoticeSchedule schedule = new NoticeSchedule()
|
||||||
|
{
|
||||||
|
EmailType = 3,
|
||||||
|
Type = 1,
|
||||||
|
RecipientName = firm.Name,
|
||||||
|
RecipientEmail = firm.Email,
|
||||||
|
Subject = powerstations.Name + "-" + fixtype + "-" + post.WorkTime,
|
||||||
|
Content = "維修項目" + post.FixDo + "</br>注意事項 :" + post.Notice,
|
||||||
|
};
|
||||||
|
await noticeScheduleRepository.AddAnyThing<NoticeSchedule>(schedule, properties, "notice_schedule");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//using (TransactionScope scope = new TransactionScope(TransactionScopeAsyncFlowOption.Suppress))
|
||||||
|
//{
|
||||||
|
|
||||||
|
// scope.Complete();
|
||||||
|
//}
|
||||||
|
|
||||||
apiResult.Code = "0000";
|
apiResult.Code = "0000";
|
||||||
apiResult.Msg = "儲存成功";
|
apiResult.Msg = "儲存成功";
|
||||||
@ -606,9 +684,14 @@ namespace SolarPower.Controllers
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
//var transactionOption = new TransactionOptions();
|
||||||
|
//transactionOption.IsolationLevel = IsolationLevel.ReadUncommitted;
|
||||||
|
//using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, transactionOption, TransactionScopeAsyncFlowOption.Enabled))
|
||||||
|
//{
|
||||||
|
|
||||||
|
// scope.Complete();
|
||||||
|
//}
|
||||||
#region 修改運維作業記錄
|
#region 修改運維作業記錄
|
||||||
|
|
||||||
var finishTime = string.Empty;
|
var finishTime = string.Empty;
|
||||||
if (post.Status == (int)OperationRecordStatusEnum.Complete)
|
if (post.Status == (int)OperationRecordStatusEnum.Complete)
|
||||||
{
|
{
|
||||||
@ -650,8 +733,6 @@ namespace SolarPower.Controllers
|
|||||||
UpdatedBy = myUser.Id
|
UpdatedBy = myUser.Id
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
List<string> properties = new List<string>()
|
List<string> properties = new List<string>()
|
||||||
{
|
{
|
||||||
"Id",
|
"Id",
|
||||||
@ -704,7 +785,6 @@ namespace SolarPower.Controllers
|
|||||||
//刪除執行人員
|
//刪除執行人員
|
||||||
await operationRepository.DeleteOperationRecordPersonnel(deleteOperationRecordPersonnels);
|
await operationRepository.DeleteOperationRecordPersonnel(deleteOperationRecordPersonnels);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region 新增人員
|
#region 新增人員
|
||||||
@ -725,7 +805,6 @@ namespace SolarPower.Controllers
|
|||||||
|
|
||||||
insertOperationRecordPersonnels.Add(operationPersonnel);
|
insertOperationRecordPersonnels.Add(operationPersonnel);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<string> operationRecordPersonnelProperties = new List<string>()
|
List<string> operationRecordPersonnelProperties = new List<string>()
|
||||||
{
|
{
|
||||||
"OperationRecordId",
|
"OperationRecordId",
|
||||||
@ -733,15 +812,84 @@ namespace SolarPower.Controllers
|
|||||||
"UserId",
|
"UserId",
|
||||||
"CreatedBy",
|
"CreatedBy",
|
||||||
};
|
};
|
||||||
|
|
||||||
await operationRepository.AddOperationRecordPersonnelAsync(insertOperationRecordPersonnels, operationRecordPersonnelProperties);
|
await operationRepository.AddOperationRecordPersonnelAsync(insertOperationRecordPersonnels, operationRecordPersonnelProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
if (post.WorkPersonIds.Count != 0)
|
||||||
|
{
|
||||||
|
var powerstations = await powerStationRepository.GetOneAsync(post.PowerStationId);
|
||||||
|
List<NoticeSchedule> noticeSchedules = new List<NoticeSchedule>();
|
||||||
|
foreach (var person in post.WorkPersonIds)
|
||||||
|
{
|
||||||
|
var fixtype = operationRecord.WorkType switch
|
||||||
|
{
|
||||||
|
0 => "清洗",
|
||||||
|
1 => "巡檢",
|
||||||
|
2 => "維修",
|
||||||
|
_ => ""
|
||||||
|
};
|
||||||
|
var user = await userRepository.GetOneAsync(person);
|
||||||
|
NoticeSchedule schedule = new NoticeSchedule()
|
||||||
|
{
|
||||||
|
EmailType = 3,
|
||||||
|
Type = 1,
|
||||||
|
UserId = person,
|
||||||
|
RecipientName = user.Name,
|
||||||
|
RecipientEmail = user.Email,
|
||||||
|
Subject = powerstations.Name + "-" + fixtype + "-" + post.WorkTime,
|
||||||
|
Content = "維修項目" + post.FixDo + "</br>注意事項 :" + post.Notice,
|
||||||
|
};
|
||||||
|
noticeSchedules.Add(schedule);
|
||||||
|
}
|
||||||
|
properties = new List<string>()
|
||||||
|
{
|
||||||
|
"UserId",
|
||||||
|
"EmailType",
|
||||||
|
"RecipientEmail",
|
||||||
|
"Subject",
|
||||||
|
"Content",
|
||||||
|
"RecipientName",
|
||||||
|
"Type",
|
||||||
|
"ExceptionId"
|
||||||
|
};
|
||||||
|
await noticeScheduleRepository.AddAnyThing<List<NoticeSchedule>>(noticeSchedules, properties, "notice_schedule");
|
||||||
|
}
|
||||||
|
if (post.FixFirm != 0)
|
||||||
|
{
|
||||||
|
var powerstations = await powerStationRepository.GetOneAsync(post.PowerStationId);
|
||||||
|
var fixtype = post.WorkType switch
|
||||||
|
{
|
||||||
|
0 => "清洗",
|
||||||
|
1 => "巡檢",
|
||||||
|
2 => "維修",
|
||||||
|
_ => ""
|
||||||
|
};
|
||||||
|
var powerstation = await powerStationRepository.GetOneAsync(post.PowerStationId);
|
||||||
|
var firm = await operationRepository.GetOneWithCustomDBNameAndTableAsync<OperationInfo>(post.FixFirm, powerstations.SiteDB, "operation_firm");
|
||||||
|
NoticeSchedule schedule = new NoticeSchedule()
|
||||||
|
{
|
||||||
|
EmailType = 3,
|
||||||
|
Type = 1,
|
||||||
|
RecipientName = firm.Name,
|
||||||
|
RecipientEmail = firm.Email,
|
||||||
|
Subject = powerstations.Name + "-" + fixtype + "-" + post.WorkTime,
|
||||||
|
Content = "維修項目" + post.FixDo + "</br>注意事項 :" + post.Notice,
|
||||||
|
};
|
||||||
|
await noticeScheduleRepository.AddAnyThing<NoticeSchedule>(schedule, properties, "notice_schedule");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
apiResult.Code = "0000";
|
apiResult.Code = "0000";
|
||||||
apiResult.Msg = "儲存成功";
|
apiResult.Msg = "儲存成功";
|
||||||
apiResult.Data = operationRecord.Id;
|
apiResult.Data = operationRecord.Id;
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
|
|||||||
@ -878,7 +878,17 @@
|
|||||||
|
|
||||||
//#region 儲存表單資料
|
//#region 儲存表單資料
|
||||||
function SaveRecord() {
|
function SaveRecord() {
|
||||||
|
Swal.fire(
|
||||||
|
{
|
||||||
|
title: "儲存",
|
||||||
|
text: "你確定是否儲存此筆資料?\r\n 儲存成功後將會發送Email至負責人員及廠商",
|
||||||
|
type: "warning",
|
||||||
|
icon: 'warning',
|
||||||
|
showCancelButton: true,
|
||||||
|
confirmButtonText: "是",
|
||||||
|
cancelButtonText: "否"
|
||||||
|
}).then(function (result) {
|
||||||
|
if (result.value) {
|
||||||
if ($("#record-form").valid()) {
|
if ($("#record-form").valid()) {
|
||||||
var url = "/Operation/SaveOperationRecord";
|
var url = "/Operation/SaveOperationRecord";
|
||||||
|
|
||||||
@ -944,6 +954,14 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
|
|||||||
@ -853,9 +853,16 @@
|
|||||||
$.each(rel.data, function (index, val) {
|
$.each(rel.data, function (index, val) {
|
||||||
$("#ShareDevice_PowerStationId_modal").append($("<option />").val(val.value).text(val.text +"/"+ val.name));
|
$("#ShareDevice_PowerStationId_modal").append($("<option />").val(val.value).text(val.text +"/"+ val.name));
|
||||||
});
|
});
|
||||||
if (rel.data.length > 0)
|
if (rel.data.length > 0) {
|
||||||
{
|
|
||||||
DeviceUIDList($("#ShareDevice_PowerStationId_modal").val());
|
DeviceUIDList($("#ShareDevice_PowerStationId_modal").val());
|
||||||
|
$("#ShareDevice_PowerStationId_modal").attr('disabled', false);
|
||||||
|
$("#ShareDevice-modal").find('.btn-primary').attr('disabled', false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$("#ShareDevice_PowerStationId_modal").append($("<option />").val("").text("無其餘電站"));
|
||||||
|
$("#ShareDevice_PowerStationId_modal").attr('disabled', true);
|
||||||
|
$("#ShareDevice-modal").find('.btn-primary').attr('disabled', true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -938,12 +945,6 @@
|
|||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
//#region 代管切換
|
//#region 代管切換
|
||||||
@ -2984,6 +2985,38 @@
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
$("#Operation-form").validate({
|
||||||
|
rules: {
|
||||||
|
Operation_factory_modal: {
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
Operation_name_modal: {
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
Operation_phone_modal: {
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
Operation_email_modal: {
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
Operation_role_modal: {
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
$("#ShareDevice-form").validate({
|
||||||
|
rules: {
|
||||||
|
ShareDevice_PowerStationId_modal: {
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
ShareDevice_UID_modal: {
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
function urlApicallItem()
|
function urlApicallItem()
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user