定期計畫

This commit is contained in:
b110212000 2021-06-23 09:30:50 +08:00
parent 948347c520
commit f789f3dbbb
5 changed files with 192 additions and 39 deletions

View File

@ -67,41 +67,78 @@ namespace SolarPower.Controllers
ApiResult<string> apiResult = new ApiResult<string>();
try
{
var now = DateTime.Now.ToString("yyyy-MM-dd");
var finalid = await operationRepository.GetCurrentSerialNumber("operation_plan_create", $"PowerStationId = {post.PowerStationId} AND CreatedAt LIKE '%{now}%'");
var newSerialNumber = GetLastSerialNumber(finalid);
var OperationPlan = new OperationCreatePlan()
if(post.Id == 0)
{
EmailType = post.EmailType,
ScheduleNum = post.ScheduleNum,
Description = post.Description,
WorkDay = post.WorkDay,
ScheduleType = post.ScheduleType,
SerialNumber = newSerialNumber,
StartTime = post.StartTime,
PowerStationId = post.PowerStationId,
Type = post.Type,
PlanId = DateTime.Now.ToString("yyyyMMdd") + newSerialNumber,
CreatedBy = myUser.Id
};
List<string> properties = new List<string>()
var now = DateTime.Now.ToString("yyyy-MM-dd");
var finalid = await operationRepository.GetCurrentSerialNumber("operation_plan_create", $"PowerStationId = {post.PowerStationId} AND CreatedAt LIKE '%{now}%'");
var newSerialNumber = GetLastSerialNumber(finalid);
var OperationPlan = new OperationCreatePlan()
{
EmailType = post.EmailType,
ScheduleNum = post.ScheduleNum,
Description = post.Description,
WorkDay = post.WorkDay,
ScheduleType = post.ScheduleType,
SerialNumber = newSerialNumber,
StartTime = post.StartTime,
PowerStationId = post.PowerStationId,
Type = post.Type,
PlanId = DateTime.Now.ToString("yyyyMMdd") + newSerialNumber,
CreatedBy = myUser.Id
};
List<string> properties = new List<string>()
{
"EmailType",
"ScheduleNum",
"Description",
"WorkDay",
"ScheduleType",
"SerialNumber",
"StartTime",
"PowerStationId",
"Type",
"PlanId",
"CreatedBy"
};
await operationRepository.AddOperationPlan(OperationPlan, properties);
apiResult.Code = "0000";
apiResult.Msg = "新增成功";
}
else
{
"EmailType",
"ScheduleNum",
"Description",
"WorkDay",
"ScheduleType",
"SerialNumber",
"StartTime",
"PowerStationId",
"Type",
"PlanId",
"CreatedBy"
};
await operationRepository.AddOperationPlan(OperationPlan, properties);
var OperationPlan = new OperationCreatePlan()
{
Id = post.Id,
EmailType = post.EmailType,
ScheduleNum = post.ScheduleNum,
Description = post.Description,
WorkDay = post.WorkDay,
ScheduleType = post.ScheduleType,
StartTime = post.StartTime,
PowerStationId = post.PowerStationId,
Type = post.Type,
UpdateBy = myUser.Id
};
List<string> properties = new List<string>()
{
"Id",
"EmailType",
"ScheduleNum",
"Description",
"WorkDay",
"ScheduleType",
"StartTime",
"PowerStationId",
"Type",
"UpdateBy"
};
await operationRepository.UpdateOperationPlan(OperationPlan, properties);
apiResult.Code = "0000";
apiResult.Msg = "編輯成功";
}
apiResult.Code = "0000";
apiResult.Msg = "新增成功";
}
catch (Exception exception)
{
@ -157,7 +194,7 @@ namespace SolarPower.Controllers
a.Schedule = "每" + a.ScheduleNum.ToString() + "年";
}
a.StartTimeString = a.StartTime.ToString("yyyy-MM-dd");
a.StartTimeString = a.StartTime;
var crst = a.CreatedAt.Split(" ");
a.CreateTimeString = crst[0];
@ -233,5 +270,24 @@ namespace SolarPower.Controllers
return apiResult;
}
public async Task<ApiResult<OperationCreatePlan>> GetOneOperationPlan(int Id)
{
ApiResult<OperationCreatePlan> apiResult = new ApiResult<OperationCreatePlan>();
OperationCreatePlan operationCreatePlan = new OperationCreatePlan();
try
{
apiResult.Code = "0000";
operationCreatePlan = await operationRepository.GetOneOperation(Id);
apiResult.Data = operationCreatePlan;
}
catch (Exception exception)
{
apiResult.Code = "9999";
apiResult.Msg = exception.ToString();
Logger.LogError("【" + controllerName + "/" + actionName + "】" + "Id=" + Id);
Logger.LogError("【" + controllerName + "/" + actionName + "】" + exception.Message);
}
return apiResult;
}
}
}

View File

@ -26,16 +26,44 @@ namespace SolarPower.Models
public string Text { get; set; }
public string Value { get; set; }
}
public class OperationCreatePlanModal : Created
{
private string startTime = "", endTime = "";
public int Id { get; set; }
public int PowerStationId { get; set; }
public int Type { get; set; }
public int ScheduleNum { get; set; }
public int ScheduleType { get; set; }
public int WorkDay { get; set; }
public DateTime StartTime { get; set; }
public DateTime EndTime { get; set; }
public string StartTime {
get
{
if (!string.IsNullOrEmpty(startTime))
{
return Convert.ToDateTime(startTime).ToString("yyyy-MM-dd");
}
else
{
return null;
}
}
set { startTime = value; }
}
public string EndTime {
get
{
if (!string.IsNullOrEmpty(endTime))
{
return Convert.ToDateTime(endTime).ToString("yyyy-MM-dd");
}
else
{
return null;
}
}
set { endTime = value; }
}
public string Description { get; set; }
public int EmailType { get; set; }
}
@ -43,6 +71,9 @@ namespace SolarPower.Models
{
public string PlanId { get; set; }
public string SerialNumber { get; set; }
private string updateAt;
public int UpdateBy { get; set; } //修改者
public string UpdateAt { get { return Convert.ToDateTime(updateAt).ToString("yyyy-MM-dd HH:mm:ss"); } set { updateAt = value; } } //修改時間
}
public class OperationPlanTable : OperationCreatePlan
{

View File

@ -35,7 +35,6 @@ namespace SolarPower.Repository.Implement
return result;
}
}
public async Task AddOperationPlan(OperationCreatePlan OperationPlan, List<string> properties)
{
using (IDbConnection conn = _databaseHelper.GetConnection())
@ -80,9 +79,11 @@ namespace SolarPower.Repository.Implement
{
try
{
var sql = @$"SELECT *,ps.Name AS PowerStationName ,us.Name AS CreatedPerson FROM operation_plan_create oc LEFT JOIN power_station ps
var sql = @$"SELECT oc.Id,oc.PlanId,oc.PowerStationId,oc.Type,
oc.ScheduleNum,oc.ScheduleType,oc.WorkDay,oc.StartTime,
oc.EmailType,oc.Description,oc.CreatedAt,ps.Name AS PowerStationName ,us.Name AS CreatedPerson FROM operation_plan_create oc LEFT JOIN power_station ps
ON oc.PowerStationId = ps.Id LEFT JOIN user us
ON us.Id = oc.CreatedBy WHERE {Wheresql} AND oc.Deleted = 0";
ON us.Id = oc.CreatedBy WHERE ({Wheresql}) AND oc.Deleted = 0";
result = (await conn.QueryAsync<OperationPlanTable>(sql)).ToList();
}
catch (Exception exception)
@ -116,5 +117,30 @@ namespace SolarPower.Repository.Implement
return result;
}
}
public async Task UpdateOperationPlan(OperationCreatePlan OperationPlan, List<string> properties)
{
using (IDbConnection conn = _databaseHelper.GetConnection())
{
conn.Open();
var trans = conn.BeginTransaction();
try
{
var sql = GenerateUpdateQuery(properties);
await conn.ExecuteAsync(sql, OperationPlan, trans);
trans.Commit();
}
catch (Exception exception)
{
trans.Rollback();
throw exception;
}
finally
{
conn.Close();
}
}
}
}
}

View File

@ -12,6 +12,8 @@ namespace SolarPower.Repository.Interface
Task AddOperationPlan(OperationCreatePlan OperationPlan, List<string> properties);
Task<List<OperationPlanTable>> OperationPlanTable(List<int> id);
Task<OperationCreatePlan> GetOneOperation(int id);
Task UpdateOperationPlan(OperationCreatePlan OperationPlan, List<string> properties);
}
}

View File

@ -357,8 +357,8 @@
//#region 儲存定時計畫資料
function SaveOperationPlan() {
var url = "/Operation/SaveOperationPlan";
var send_data = {
id: selected_id,
PowerStationId: $("#operation_powerStationselect_modal").val(),
Type: $("#operation_type_modal").val(),
ScheduleNum: $("#operation_scheduleNum_modal").val(),
@ -413,6 +413,44 @@
});
});
//#endregion
//#region 取一筆定時計畫
$('#OperationPlan_table').on("click", "button.edit-btn", function () {
$("#Operation-modal .modal-title").html("定時計劃 - 編輯");
selected_id = $(this).parents('tr').attr('data-id');
//取得單一異常設定資料
var url = "/Operation/GetOneOperationPlan/";
var send_data = {
id: selected_id
}
$.post(url, send_data, function (rel) {
if (rel.code != "0000") {
toast_error(rel.msg);
return;
}
$("#operation_powerStationselect_modal").val(rel.data.powerStationId);
$("#operation_type_modal").val(rel.data.type);
$("#operation_scheduleNum_modal").val(rel.data.scheduleNum);
$("#operation_scheduleType_modal").val(rel.data.scheduleType);
$("#operation_workDay_modal").val(rel.data.workDay);
var start = rel.data.startTime.split(' ');
$("#operation_startTime_modal").val(start[0]);
$("#operation_description_modal").val(rel.data.description);
$("#operation_emailType_modal").val(rel.data.emailType);
var dat = new Date(start);
var day = new Date(dat.setDate(dat.getDate() + Number(rel.data.workDay))).toISOString().split("T");
document.getElementById("operation_endTime_modal").innerHTML = day[0];
$("#Operation-modal").modal();
}, 'json');
});
//#endregion
</script>
}