LqStatisticsService.cs
3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using NCC.Common.Core.Manager;
using NCC.Common.Enum;
using NCC.Common.Extension;
using NCC.Common.Filter;
using NCC.Dependency;
using NCC.DynamicApiController;
using NCC.FriendlyException;
using NCC.Extend.Interfaces.LqStatistics;
using NCC.Extend.Entitys.Dto.LqStatistics;
using Microsoft.AspNetCore.Mvc;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using NCC.Extend.Entitys.lq_mdxx;
namespace NCC.Extend.LqStatistics
{
/// <summary>
/// 绿纤统计服务
/// </summary>
[ApiDescriptionSettings(Tag = "绿纤统计服务", Name = "LqStatistics", Order = 200, Groups = new[] { "Default" })]
[Route("api/Extend/[controller]")]
public class LqStatisticsService : ILqStatisticsService, IDynamicApiController, ITransient
{
private readonly ISqlSugarRepository<LqMdxxEntity> _lqMdxxRepository;
private readonly SqlSugarScope _db;
private readonly IUserManager _userManager;
/// <summary>
/// 初始化一个<see cref="LqStatisticsService"/>类型的新实例
/// </summary>
public LqStatisticsService(
ISqlSugarRepository<LqMdxxEntity> lqMdxxRepository,
IUserManager userManager)
{
_lqMdxxRepository = lqMdxxRepository;
_db = _lqMdxxRepository.Context;
_userManager = userManager;
}
/// <summary>
/// 测试接口
/// </summary>
/// <returns>测试结果</returns>
[HttpGet]
public async Task<dynamic> Test()
{
return await Task.FromResult(new { message = "绿纤统计服务运行正常", timestamp = DateTime.Now });
}
/// <summary>
/// 获取门店业绩统计列表
/// </summary>
/// <remarks>
/// 查询所有门店的目标业绩、完成业绩、完成率等关键指标
///
/// 返回数据包含:
/// - 门店编码和店名
/// - 目标业绩(生命线)
/// - 完成业绩(实付业绩)
/// - 完成率(百分比)
/// - 开单数量
///
/// 数据来源:v_store_performance_simple 视图
/// </remarks>
/// <returns>门店业绩统计列表</returns>
/// <response code="200">成功返回门店业绩统计列表</response>
/// <response code="500">服务器内部错误</response>
[HttpGet]
public async Task<List<StorePerformanceOutput>> GetStorePerformanceList()
{
try
{
var result = await _db.Ado.SqlQueryAsync<StorePerformanceOutput>(
"SELECT " +
"store_code AS StoreCode, " +
"store_name AS StoreName, " +
"target_performance AS TargetPerformance, " +
"actual_performance AS ActualPerformance, " +
"completion_rate AS CompletionRate, " +
"order_count AS OrderCount " +
"FROM v_store_performance_simple " +
"ORDER BY actual_performance DESC");
return result ?? new List<StorePerformanceOutput>();
}
catch (Exception ex)
{
throw NCCException.Oh(ErrorCode.COM1005, ex.Message);
}
}
}
}