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 SolarPower.Models;
|
||||
using SolarPower.Models.PowerStation;
|
||||
using SolarPower.Models.Role;
|
||||
using SolarPower.Repository.Interface;
|
||||
using System;
|
||||
@ -15,16 +18,22 @@ namespace SolarPower.Controllers
|
||||
public class OperationController : MyBaseController<OperationController>
|
||||
{
|
||||
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 = "";
|
||||
|
||||
public IWebHostEnvironment environment;
|
||||
|
||||
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;
|
||||
|
||||
operationRecordSaveAsPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "upload", "operation_record");
|
||||
this.environment = environment;
|
||||
operationRecordSaveAsPath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "upload", "operation_recode");
|
||||
}
|
||||
|
||||
public IActionResult Index()
|
||||
@ -534,27 +543,25 @@ namespace SolarPower.Controllers
|
||||
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,
|
||||
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
|
||||
};
|
||||
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>()
|
||||
List<string> properties = new List<string>()
|
||||
{
|
||||
"FormId",
|
||||
"SerialNumber",
|
||||
@ -572,33 +579,104 @@ namespace SolarPower.Controllers
|
||||
"CreatedBy"
|
||||
};
|
||||
|
||||
id = await operationRepository.AddOneOperationRecordAsync(operationRecord, properties);
|
||||
id = await operationRepository.AddOneOperationRecordAsync(operationRecord, properties);
|
||||
|
||||
//加入執行人員
|
||||
if (post.WorkPersonIds != null)
|
||||
//加入執行人員
|
||||
if (post.WorkPersonIds != null)
|
||||
{
|
||||
List<OperationRecordPersonnel> insertOperationRecordPersonnels = new List<OperationRecordPersonnel>();
|
||||
|
||||
foreach (var op in post.WorkPersonIds)
|
||||
{
|
||||
List<OperationRecordPersonnel> insertOperationRecordPersonnels = new List<OperationRecordPersonnel>();
|
||||
OperationRecordPersonnel operationRecordPersonnel = new OperationRecordPersonnel();
|
||||
operationRecordPersonnel.OperationRecordId = id;
|
||||
operationRecordPersonnel.UserId = op;
|
||||
|
||||
foreach (var op in post.WorkPersonIds)
|
||||
{
|
||||
OperationRecordPersonnel operationRecordPersonnel = new OperationRecordPersonnel();
|
||||
operationRecordPersonnel.OperationRecordId = id;
|
||||
operationRecordPersonnel.UserId = op;
|
||||
insertOperationRecordPersonnels.Add(operationRecordPersonnel);
|
||||
}
|
||||
|
||||
insertOperationRecordPersonnels.Add(operationRecordPersonnel);
|
||||
}
|
||||
|
||||
List<string> operationRecordPersonnelProperties = new List<string>()
|
||||
List<string> operationRecordPersonnelProperties = new List<string>()
|
||||
{
|
||||
"OperationRecordId",
|
||||
"UserId",
|
||||
};
|
||||
|
||||
await operationRepository.AddOperationRecordPersonnelAsync(insertOperationRecordPersonnels, operationRecordPersonnelProperties);
|
||||
}
|
||||
scope.Complete();
|
||||
await operationRepository.AddOperationRecordPersonnelAsync(insertOperationRecordPersonnels, operationRecordPersonnelProperties);
|
||||
|
||||
|
||||
}
|
||||
|
||||
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.Msg = "儲存成功";
|
||||
apiResult.Data = id;
|
||||
@ -606,9 +684,14 @@ namespace SolarPower.Controllers
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
//var transactionOption = new TransactionOptions();
|
||||
//transactionOption.IsolationLevel = IsolationLevel.ReadUncommitted;
|
||||
//using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, transactionOption, TransactionScopeAsyncFlowOption.Enabled))
|
||||
//{
|
||||
|
||||
// scope.Complete();
|
||||
//}
|
||||
#region 修改運維作業記錄
|
||||
|
||||
var finishTime = string.Empty;
|
||||
if (post.Status == (int)OperationRecordStatusEnum.Complete)
|
||||
{
|
||||
@ -650,22 +733,20 @@ namespace SolarPower.Controllers
|
||||
UpdatedBy = myUser.Id
|
||||
};
|
||||
|
||||
|
||||
|
||||
List<string> properties = new List<string>()
|
||||
{
|
||||
"Id",
|
||||
"ErrorCode",
|
||||
"FixDo",
|
||||
"FixFirm",
|
||||
"Status",
|
||||
"FinishTime",
|
||||
"WorkTime",
|
||||
"Notice",
|
||||
"Description",
|
||||
//"WorkPersonId",
|
||||
"UpdatedBy",
|
||||
};
|
||||
{
|
||||
"Id",
|
||||
"ErrorCode",
|
||||
"FixDo",
|
||||
"FixFirm",
|
||||
"Status",
|
||||
"FinishTime",
|
||||
"WorkTime",
|
||||
"Notice",
|
||||
"Description",
|
||||
//"WorkPersonId",
|
||||
"UpdatedBy",
|
||||
};
|
||||
|
||||
if (string.IsNullOrEmpty(operationRecord.FormId))
|
||||
{
|
||||
@ -686,7 +767,7 @@ namespace SolarPower.Controllers
|
||||
|
||||
//判斷新進來的執行人員是否要歸類到新增 or 刪除
|
||||
#region 刪除執行人員編號
|
||||
if(post.WorkPersonIds != null && post.WorkPersonIds.Count() > 0)
|
||||
if (post.WorkPersonIds != null && post.WorkPersonIds.Count() > 0)
|
||||
{
|
||||
//找出要刪除的
|
||||
List<int> deleteOperationRecordPersonnelIds = origOperationRecordPersonnels.Where(x => !post.WorkPersonIds.Contains(x)).ToList();
|
||||
@ -704,7 +785,6 @@ namespace SolarPower.Controllers
|
||||
//刪除執行人員
|
||||
await operationRepository.DeleteOperationRecordPersonnel(deleteOperationRecordPersonnels);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 新增人員
|
||||
@ -725,23 +805,91 @@ namespace SolarPower.Controllers
|
||||
|
||||
insertOperationRecordPersonnels.Add(operationPersonnel);
|
||||
}
|
||||
|
||||
List<string> operationRecordPersonnelProperties = new List<string>()
|
||||
{
|
||||
"OperationRecordId",
|
||||
"Deleted",
|
||||
"UserId",
|
||||
"CreatedBy",
|
||||
};
|
||||
|
||||
{
|
||||
"OperationRecordId",
|
||||
"Deleted",
|
||||
"UserId",
|
||||
"CreatedBy",
|
||||
};
|
||||
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
|
||||
|
||||
apiResult.Code = "0000";
|
||||
apiResult.Msg = "儲存成功";
|
||||
apiResult.Data = operationRecord.Id;
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
|
||||
@ -878,72 +878,90 @@
|
||||
|
||||
//#region 儲存表單資料
|
||||
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()) {
|
||||
var url = "/Operation/SaveOperationRecord";
|
||||
|
||||
if ($("#record-form").valid()) {
|
||||
var url = "/Operation/SaveOperationRecord";
|
||||
var formData = new FormData();
|
||||
|
||||
var formData = new FormData();
|
||||
@*var work_person_ids = $.map($("#work_person_select_modal").val(), function (item) {
|
||||
return parseInt(item);
|
||||
}) *@
|
||||
|
||||
@*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);
|
||||
formData.append("ErrorCode", $("#error_code_modal").val());
|
||||
formData.append("FixDo", $("#fix_do_modal").val());
|
||||
formData.append("FixFirm", $("#fix_firm_select_modal").val());
|
||||
formData.append("Status", $("input[name=status_modal]:checked").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());
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: url,
|
||||
data: formData,
|
||||
cache: false,
|
||||
contentType: false,
|
||||
processData: false,
|
||||
success: function (rel) {
|
||||
if (rel.code != "0000") {
|
||||
toast_error(rel.msg);
|
||||
return;
|
||||
}
|
||||
|
||||
var myDropzone = Dropzone.forElement("#record-file-form");
|
||||
|
||||
if (myDropzone.files.length > 0) {
|
||||
|
||||
selected_id = rel.data;
|
||||
|
||||
myDropzone.processQueue();
|
||||
|
||||
myDropzone.on("successmultiple", function (file, rel) {
|
||||
if (rel.code != "0000") {
|
||||
toast_error(rel.msg);
|
||||
return;
|
||||
}
|
||||
|
||||
toast_ok(rel.msg);
|
||||
$('#record-form-modal').modal('hide');
|
||||
recordFileDropzone.removeAllFiles();
|
||||
|
||||
operationRecordTable.ajax.reload();
|
||||
formData.append("Id", selected_id);
|
||||
formData.append("PowerStationId", $("#power_station_select_modal").val());
|
||||
formData.append("WorkType", selected_work_type);
|
||||
formData.append("ErrorCode", $("#error_code_modal").val());
|
||||
formData.append("FixDo", $("#fix_do_modal").val());
|
||||
formData.append("FixFirm", $("#fix_firm_select_modal").val());
|
||||
formData.append("Status", $("input[name=status_modal]:checked").val());
|
||||
$("#work_person_select_modal").val().forEach(function (item) {
|
||||
formData.append("WorkPersonIds", parseInt(item));
|
||||
});
|
||||
} else {
|
||||
$('#record-form-modal').modal('hide');
|
||||
myDropzone.removeAllFiles();
|
||||
formData.append("WorkTime", $("#work_time_modal").val());
|
||||
formData.append("Notice", $("#notice_textarea_modal").val());
|
||||
formData.append("Description", $("#description_textarea_modal").val());
|
||||
|
||||
operationRecordTable.ajax.reload();
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: url,
|
||||
data: formData,
|
||||
cache: false,
|
||||
contentType: false,
|
||||
processData: false,
|
||||
success: function (rel) {
|
||||
if (rel.code != "0000") {
|
||||
toast_error(rel.msg);
|
||||
return;
|
||||
}
|
||||
|
||||
var myDropzone = Dropzone.forElement("#record-file-form");
|
||||
|
||||
if (myDropzone.files.length > 0) {
|
||||
|
||||
selected_id = rel.data;
|
||||
|
||||
myDropzone.processQueue();
|
||||
|
||||
myDropzone.on("successmultiple", function (file, rel) {
|
||||
if (rel.code != "0000") {
|
||||
toast_error(rel.msg);
|
||||
return;
|
||||
}
|
||||
|
||||
toast_ok(rel.msg);
|
||||
$('#record-form-modal').modal('hide');
|
||||
recordFileDropzone.removeAllFiles();
|
||||
|
||||
operationRecordTable.ajax.reload();
|
||||
});
|
||||
} else {
|
||||
$('#record-form-modal').modal('hide');
|
||||
myDropzone.removeAllFiles();
|
||||
|
||||
operationRecordTable.ajax.reload();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
//#endregion
|
||||
|
||||
|
||||
@ -853,9 +853,16 @@
|
||||
$.each(rel.data, function (index, val) {
|
||||
$("#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());
|
||||
$("#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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
//#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()
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user