почти готово
This commit is contained in:
parent
f923669aa7
commit
ba28f317fa
3
.gitignore
vendored
3
.gitignore
vendored
@ -407,3 +407,6 @@ FodyWeavers.xsd
|
|||||||
/docBuses1.docx
|
/docBuses1.docx
|
||||||
/excel1.xlsx
|
/excel1.xlsx
|
||||||
/pdf1.pdf
|
/pdf1.pdf
|
||||||
|
*.xlsx
|
||||||
|
*.docx
|
||||||
|
*.pdf
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
namespace ProjectPassengerTransportation.Entities;
|
|
||||||
|
|
||||||
public class TempStartingShiftEmployee
|
|
||||||
{
|
|
||||||
public int Starting_shift_id { get; private set; }
|
|
||||||
|
|
||||||
public int Employee_id { get; private set; }
|
|
||||||
|
|
||||||
public int Route_list_id { get; private set; }
|
|
||||||
|
|
||||||
public int Bus_id { get; private set; }
|
|
||||||
|
|
||||||
public DateTime Date { get; private set; }
|
|
||||||
|
|
||||||
public int Work_time { get; private set; }
|
|
||||||
}
|
|
@ -83,7 +83,12 @@ namespace ProjectPassengerTransportation.Forms
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadList() => dataGridViewData.DataSource = _busRepository.ReadBuses();
|
private void LoadList()
|
||||||
|
{
|
||||||
|
dataGridViewData.DataSource = _busRepository.ReadBuses();
|
||||||
|
dataGridViewData.Columns["Id"].Visible = false;
|
||||||
|
dataGridViewData.Columns["Model_and_plate"].Visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
{
|
{
|
||||||
|
@ -83,7 +83,12 @@ namespace ProjectPassengerTransportation.Forms
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadList() => dataGridViewData.DataSource = _employeeRepository.ReadEmployees();
|
private void LoadList()
|
||||||
|
{
|
||||||
|
dataGridViewData.DataSource = _employeeRepository.ReadEmployees();
|
||||||
|
dataGridViewData.Columns["Id"].Visible = false;
|
||||||
|
dataGridViewData.Columns["Full_name"].Visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
{
|
{
|
||||||
|
@ -63,7 +63,13 @@ public partial class FormGoToServices : Form
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadList() => dataGridViewData.DataSource = _goToServiceRepository.ReadServices();
|
private void LoadList()
|
||||||
|
{
|
||||||
|
dataGridViewData.DataSource = _goToServiceRepository.ReadServices();
|
||||||
|
dataGridViewData.Columns["Id"].Visible = false;
|
||||||
|
dataGridViewData.Columns["Date"].DefaultCellStyle.Format = "dd.MM.yyyy";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
{
|
{
|
||||||
|
@ -83,7 +83,12 @@ namespace ProjectPassengerTransportation.Forms
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadList() => dataGridViewData.DataSource = _routeListRepository.ReadRouteLists();
|
private void LoadList()
|
||||||
|
{
|
||||||
|
dataGridViewData.DataSource = _routeListRepository.ReadRouteLists();
|
||||||
|
dataGridViewData.Columns["Id"].Visible = false;
|
||||||
|
dataGridViewData.Columns["Route_time"].Visible = false;
|
||||||
|
}
|
||||||
|
|
||||||
private bool TryGetIdentifierFromSelectedRow(out int id)
|
private bool TryGetIdentifierFromSelectedRow(out int id)
|
||||||
{
|
{
|
||||||
|
@ -40,5 +40,10 @@ public partial class FormStartingShifts : Form
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadList() => dataGridViewData.DataSource = _startingShiftRepository.ReadShifts();
|
private void LoadList()
|
||||||
|
{
|
||||||
|
dataGridViewData.DataSource = _startingShiftRepository.ReadShifts();
|
||||||
|
dataGridViewData.Columns["Id"].Visible = false;
|
||||||
|
dataGridViewData.Columns["Date"].DefaultCellStyle.Format = "dd MMMM yyyy hh:mm";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ public class ChartReport
|
|||||||
{
|
{
|
||||||
new PdfBuilder(filePath)
|
new PdfBuilder(filePath)
|
||||||
.AddHeader("Тех обслуживание")
|
.AddHeader("Тех обслуживание")
|
||||||
.AddPieChart("Количество неисправных элементов", GetData(dateTime))
|
.AddPieChart($"Количество неисправных элементов на {dateTime:dd MMMM yyyy}", GetData(dateTime))
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -36,9 +36,9 @@ public class ChartReport
|
|||||||
private List<(string Caption, double Value)> GetData(DateTime dateTime)
|
private List<(string Caption, double Value)> GetData(DateTime dateTime)
|
||||||
{
|
{
|
||||||
return _goToServiceRepository
|
return _goToServiceRepository
|
||||||
.ReadServices()
|
.ReadServices(dateFrom: dateTime.Date, dateTo: dateTime.Date.AddDays(1))
|
||||||
.Where(x => x.Date.Date == dateTime.Date)
|
.Where(x => x.Date.Date == dateTime.Date)
|
||||||
.GroupBy(x => x.Bus_id, (key, group) => new {
|
.GroupBy(x => x.Bus_name, (key, group) => new {
|
||||||
Id = key,
|
Id = key,
|
||||||
Elements = group.Sum(x => (double)x.Broken_elements)
|
Elements = group.Sum(x => (double)x.Broken_elements)
|
||||||
})
|
})
|
||||||
|
@ -28,7 +28,7 @@ public class TableReport
|
|||||||
{
|
{
|
||||||
new ExcelBuilder(filePath)
|
new ExcelBuilder(filePath)
|
||||||
.AddHeader("Сводка по работникам и автобусам", 0, 5)
|
.AddHeader("Сводка по работникам и автобусам", 0, 5)
|
||||||
.AddParagraph("за период", 0)
|
.AddParagraph($"за период c {startDate:dd.MM.yyyy} по {endDate: dd.MM.yyyy}", 0)
|
||||||
.AddTable([10, 10, 10, 15, 15], GetData(employeeId, busId, startDate, endDate))
|
.AddTable([10, 10, 10, 15, 15], GetData(employeeId, busId, startDate, endDate))
|
||||||
.Build();
|
.Build();
|
||||||
return true;
|
return true;
|
||||||
@ -43,11 +43,11 @@ public class TableReport
|
|||||||
private List<string[]> GetData(int employeeId, int busId, DateTime startDate, DateTime endDate)
|
private List<string[]> GetData(int employeeId, int busId, DateTime startDate, DateTime endDate)
|
||||||
{
|
{
|
||||||
var data = _startingShiftRepository
|
var data = _startingShiftRepository
|
||||||
.ReadShifts()
|
.ReadShifts(dateFrom: startDate, dateTo: endDate, employeeId: employeeId, busId: busId)
|
||||||
.Where(x => x.Date >= startDate && x.Date <= endDate && x.Starting_shift_employees.Any(y => y.Employee_id == employeeId))
|
.Where(x => x.Date >= startDate && x.Date <= endDate && x.Starting_shift_employees.Any(y => y.Employee_id == employeeId))
|
||||||
.Select(x => new {
|
.Select(x => new {
|
||||||
EmployeeId = (int?)employeeId,
|
EmployeeId = (int?)employeeId,
|
||||||
BusId = (int?)null,
|
BusId = (string?)null,
|
||||||
x.Date,
|
x.Date,
|
||||||
WorkHours = x.Starting_shift_employees.FirstOrDefault(y => y.Employee_id == employeeId)?.Work_time,
|
WorkHours = x.Starting_shift_employees.FirstOrDefault(y => y.Employee_id == employeeId)?.Work_time,
|
||||||
Price = (int?)null
|
Price = (int?)null
|
||||||
@ -57,21 +57,22 @@ public class TableReport
|
|||||||
.Where(x => x.Date >= startDate && x.Date <= endDate && x.Bus_id == busId)
|
.Where(x => x.Date >= startDate && x.Date <= endDate && x.Bus_id == busId)
|
||||||
.Select(x => new {
|
.Select(x => new {
|
||||||
EmployeeId = (int?)null,
|
EmployeeId = (int?)null,
|
||||||
BusId = (int?)busId,
|
BusId = (string?)x.Bus_name,
|
||||||
x.Date,
|
x.Date,
|
||||||
WorkHours = (int?)null,
|
WorkHours = (int?)null,
|
||||||
Price = (int?)x.Price
|
Price = (int?)x.Price
|
||||||
}))
|
}))
|
||||||
.OrderBy(x => x.Date);
|
.OrderBy(x => x.Date);
|
||||||
|
|
||||||
return new List<string[]>() { item }
|
return new List<string[]>() { item }
|
||||||
.Union(data
|
.Union(data
|
||||||
.Select(x => new string[] {
|
.Select(x => new string[] {
|
||||||
x.EmployeeId.ToString() ?? string.Empty,
|
x.EmployeeId.ToString() ?? string.Empty,
|
||||||
x.BusId.ToString() ?? string.Empty,
|
x.BusId ?? string.Empty,
|
||||||
x.Date.ToString(),
|
x.Date.ToString("dd.MM.yyyy"),
|
||||||
x.WorkHours?.ToString() ?? string.Empty,
|
x.WorkHours?.ToString("N0") ?? string.Empty,
|
||||||
x.Price?.ToString() ?? string.Empty}))
|
x.Price?.ToString("N0") ?? string.Empty}))
|
||||||
.Union([["Всего", "", "", data.Sum(x => x.WorkHours ?? 0).ToString(), data.Sum(x => x.Price ?? 0).ToString()]])
|
.Union([["Всего", "", "", data.Sum(x => x.WorkHours ?? 0).ToString("N0"), data.Sum(x => x.Price ?? 0).ToString("N0")]])
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,19 +60,38 @@ WHERE id=@id";
|
|||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<GoToService> ReadServices(DateTime? dateFrom = null, DateTime? dateTo = null,
|
public IEnumerable<GoToService> ReadServices(DateTime? dateFrom = null, DateTime? dateTo = null,
|
||||||
BrokenElements BrokenElements = BrokenElements.None, int? price = null, int? busId = null)
|
BrokenElements broken_elements = BrokenElements.None, int? price = null, int? bus_id = null)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Получение всех объектов");
|
_logger.LogInformation("Получение всех объектов");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
var builder = new QueryBuilder();
|
||||||
|
if (dateFrom.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("gts.date >= @dateFrom");
|
||||||
|
}
|
||||||
|
if (dateTo.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("gts.date <= @dateTo");
|
||||||
|
}
|
||||||
|
if (price.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("gts.price = @price");
|
||||||
|
}
|
||||||
|
if (bus_id.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("gts.bus_id = @bus_id");
|
||||||
|
}
|
||||||
|
|
||||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
var querySelect = @"
|
var querySelect = @$"
|
||||||
SELECT
|
SELECT
|
||||||
gts.*,
|
gts.*,
|
||||||
b.licence_plate as Bus_name
|
b.licence_plate as Bus_name
|
||||||
FROM go_to_service gts
|
FROM go_to_service gts
|
||||||
LEFT JOIN bus b on b.id = gts.bus_id";
|
LEFT JOIN bus b on b.id = gts.bus_id
|
||||||
var services = connection.Query<GoToService>(querySelect);
|
{builder.Build()}";
|
||||||
|
var services = connection.Query<GoToService>(querySelect, new { dateFrom, dateTo, broken_elements, price, bus_id });
|
||||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(services));
|
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(services));
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,34 @@
|
|||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace ProjectPassengerTransportation.Repositories.Implementations;
|
||||||
|
|
||||||
|
public class QueryBuilder
|
||||||
|
{
|
||||||
|
private readonly StringBuilder _builder;
|
||||||
|
|
||||||
|
public QueryBuilder()
|
||||||
|
{
|
||||||
|
_builder = new();
|
||||||
|
}
|
||||||
|
|
||||||
|
public QueryBuilder AddCondition(string condition)
|
||||||
|
{
|
||||||
|
if (_builder.Length > 0)
|
||||||
|
{
|
||||||
|
_builder.Append(" AND ");
|
||||||
|
}
|
||||||
|
|
||||||
|
_builder.Append(condition);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Build()
|
||||||
|
{
|
||||||
|
if (_builder.Length == 0)
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $"WHERE {_builder}";
|
||||||
|
}
|
||||||
|
}
|
@ -50,24 +50,50 @@ VALUES (@Starting_shift_id, @Employee_id, @Work_time)";
|
|||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<StartingShift> ReadShifts(DateTime? dateFrom = null, DateTime? dateTo = null,
|
public IEnumerable<StartingShift> ReadShifts(DateTime? dateFrom = null, DateTime? dateTo = null,
|
||||||
int? routeListId = null, int? employeeId = null, int? busId = null)
|
int? route_list_id = null, int? employee_id = null, int? bus_id = null)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Получение всех объектов");
|
_logger.LogInformation("Получение всех объектов");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
var builder = new QueryBuilder();
|
||||||
|
if (dateFrom.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("ss.date >= @dateFrom");
|
||||||
|
}
|
||||||
|
if (dateTo.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("ss.date <= @dateTo");
|
||||||
|
}
|
||||||
|
if (route_list_id.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("ss.route_list_id = @route_list_id");
|
||||||
|
}
|
||||||
|
if (bus_id.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("ss.bus_id = @bus_id");
|
||||||
|
}
|
||||||
|
if (employee_id.HasValue)
|
||||||
|
{
|
||||||
|
builder.AddCondition("sse.employee_id = @employee_id");
|
||||||
|
}
|
||||||
|
|
||||||
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
using var connection = new NpgsqlConnection(_connectionString.ConnectionString);
|
||||||
var querySelect = @"
|
var querySelect = @$"
|
||||||
SELECT
|
SELECT
|
||||||
sse.starting_shift_id,
|
ss.id,
|
||||||
ss.date,
|
ss.date,
|
||||||
CONCAT(rl.route_start, '-', rl.route_finish) as Route_list_name,
|
CONCAT(rl.route_start, '-', rl.route_finish) as Route_list_name,
|
||||||
CONCAT(b.model, ' ', b.licence_plate) as Bus_name,
|
CONCAT(b.model, ' ', b.licence_plate) as Bus_name,
|
||||||
|
CONCAT(e.first_name, ' ', e.last_name) as Employee_name,
|
||||||
sse.employee_id,
|
sse.employee_id,
|
||||||
sse.work_time
|
sse.work_time
|
||||||
FROM starting_shift ss
|
FROM starting_shift ss
|
||||||
LEFT JOIN route_list rl on rl.id = ss.route_list_id
|
LEFT JOIN route_list rl on rl.id = ss.route_list_id
|
||||||
LEFT JOIN bus b on b.id = ss.bus_id
|
LEFT JOIN bus b on b.id = ss.bus_id
|
||||||
INNER JOIN starting_shift_employee sse ON sse.starting_shift_id = ss.id";
|
INNER JOIN starting_shift_employee sse ON sse.starting_shift_id = ss.id
|
||||||
|
LEFT JOIN employee e on e.id = sse.employee_id
|
||||||
|
{builder.Build()}";
|
||||||
|
|
||||||
var startingShiftDict = new Dictionary<int, List<StartingShiftEmployee>>();
|
var startingShiftDict = new Dictionary<int, List<StartingShiftEmployee>>();
|
||||||
|
|
||||||
var startingShifts = connection.Query<StartingShift, StartingShiftEmployee, StartingShift>(querySelect, (startingShift, startingShifts) =>
|
var startingShifts = connection.Query<StartingShift, StartingShiftEmployee, StartingShift>(querySelect, (startingShift, startingShifts) =>
|
||||||
@ -79,7 +105,7 @@ INNER JOIN starting_shift_employee sse ON sse.starting_shift_id = ss.id";
|
|||||||
}
|
}
|
||||||
sse.Add(startingShifts);
|
sse.Add(startingShifts);
|
||||||
return startingShift;
|
return startingShift;
|
||||||
}, splitOn: "Employee_id", param: new { dateFrom, dateTo, routeListId, employeeId, busId });
|
}, splitOn: "Employee_name", param: new { dateFrom, dateTo, route_list_id, employee_id, bus_id });
|
||||||
|
|
||||||
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(startingShifts));
|
_logger.LogDebug("Полученные объекты: {json}", JsonConvert.SerializeObject(startingShifts));
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user