809 lines
38 KiB
C#
809 lines
38 KiB
C#
using Infrastructure;
|
|
using Microsoft.Extensions.Configuration;
|
|
using NPOI.HSSF.UserModel;
|
|
using NPOI.SS.UserModel;
|
|
using NPOI.SS.Util;
|
|
using OpenAuth.App.BaseApp.Base;
|
|
using OpenAuth.App.Interface;
|
|
using OpenAuth.App.ServiceApp.Response;
|
|
using OpenAuth.Repository;
|
|
using OpenAuth.Repository.Domain;
|
|
using SqlSugar;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace OpenAuth.App.ServiceApp
|
|
{
|
|
/// <summary>
|
|
/// 统计分析
|
|
/// </summary>
|
|
public class DataAnalysisApp : SqlSugarBaseApp<InsTask, SugarDbContext>
|
|
{
|
|
private readonly IConfiguration _configuration;
|
|
private readonly ISqlSugarClient client;
|
|
private readonly IAuth _auth;
|
|
public DataAnalysisApp(ISugarUnitOfWork<SugarDbContext> unitWork, ISimpleClient<InsTask> repository, IAuth auth, ISqlSugarClient sqlSugarClient, IConfiguration configuration) : base(unitWork, repository, auth)
|
|
{
|
|
_configuration = configuration;
|
|
this.client = sqlSugarClient;
|
|
_auth = auth;
|
|
}
|
|
/// <summary>
|
|
/// 时相统计
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<Response<PageInfo<List<InsTask>>>> GteTaskListForAdmin(int month, int week, DateTime beginTime, DateTime endTime, string taskName, int page, int limit)
|
|
{
|
|
using (var db = base.UnitWork.CreateContext())
|
|
{
|
|
RefAsync<int> totalCount = 0;
|
|
var tsakList = await db.InsTask.AsQueryable()
|
|
.WhereIF(string.IsNullOrEmpty(taskName), r => r.TaskName.Contains(taskName))
|
|
.ToPageListAsync(page, limit, totalCount);
|
|
|
|
if (beginTime.Year == 0001)
|
|
{
|
|
beginTime = GetMonthStartAndEndDate(month).Start;
|
|
endTime = GetMonthStartAndEndDate(month).End;
|
|
}
|
|
var tifList = await db.InsTif.AsQueryable()
|
|
.WhereIF(beginTime.Year != 0001 || month != 0, r => r.CreateTime >= beginTime && r.CreateTime <= endTime)
|
|
.ToListAsync();
|
|
//总面积
|
|
var totalTifArea = tifList.Sum(r => r.AreaNum);
|
|
//个数
|
|
var totalTifCount = tifList.Count();
|
|
return new Response<PageInfo<List<InsTask>>>
|
|
{
|
|
Result = new PageInfo<List<InsTask>>
|
|
{
|
|
Items = tsakList,
|
|
Total = totalCount
|
|
}
|
|
};
|
|
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 每个县区的时相统计
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<Response<List<dynamic>>> GetShiXiangForArea(int month, int week, DateTime beginTime, DateTime endTime)
|
|
{
|
|
using (var db = base.UnitWork.CreateContext())
|
|
{
|
|
if (beginTime.Year == 0001)
|
|
{
|
|
beginTime = GetMonthStartAndEndDate(month).Start;
|
|
endTime = GetMonthStartAndEndDate(month).End;
|
|
}
|
|
var tifList = db.InsTif.AsQueryable()
|
|
.WhereIF(beginTime.Year != 0001 || month != 0, r => r.CreateTime >= beginTime && r.CreateTime <= endTime);
|
|
//总面积
|
|
var totalTifArea = tifList.Sum(r => r.AreaNum);
|
|
//个数
|
|
var totalTifCount = tifList.Count();
|
|
|
|
var endData = await tifList.GroupBy(r => r.AreaNum).Select<dynamic>(r => new
|
|
{
|
|
r.AreaName,
|
|
sumArea = SqlFunc.AggregateSum(r.AreaNum),
|
|
}).ToListAsync();
|
|
return new Response<List<dynamic>>
|
|
{
|
|
Result = endData,
|
|
};
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 每天时相统计
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<Response<List<dynamic>>> GetShiXiangForTime(int month, int week, DateTime beginTime, DateTime endTime)
|
|
{
|
|
using (var db = base.UnitWork.CreateContext())
|
|
{
|
|
if (beginTime.Year == 0001)
|
|
{
|
|
beginTime = GetMonthStartAndEndDate(month).Start;
|
|
endTime = GetMonthStartAndEndDate(month).End;
|
|
}
|
|
var tifList = db.InsTif.AsQueryable()
|
|
.WhereIF(beginTime.Year != 0001 || month != 0, r => r.CreateTime >= beginTime && r.CreateTime <= endTime);
|
|
//总面积
|
|
var totalTifArea = tifList.Sum(r => r.AreaNum);
|
|
//个数
|
|
var totalTifCount = tifList.Count();
|
|
|
|
var endData = await tifList.GroupBy(r => r.CreateTime).Select<dynamic>(r => new
|
|
{
|
|
r.CreateTime,
|
|
sumArea = SqlFunc.AggregateSum(r.AreaNum),
|
|
}).ToListAsync();
|
|
return new Response<List<dynamic>>
|
|
{
|
|
Result = endData,
|
|
};
|
|
}
|
|
}
|
|
static (DateTime Start, DateTime End) GetMonthStartAndEndDate(int month)
|
|
{
|
|
int year = DateTime.Now.Year; // 获取当前年份
|
|
DateTime startDate = new DateTime(year, month, 1, 0, 0, 0); // 当月起始日期
|
|
DateTime endDate = startDate.AddMonths(1).AddSeconds(-1); // 当月结束日期
|
|
return (startDate, endDate);
|
|
}
|
|
// 获取本月的起始时间和结束时间
|
|
public static (DateTime startOfMonth, DateTime endOfMonth) GetStartEndOfMonth()
|
|
{
|
|
DateTime now = DateTime.Now;
|
|
// 本月的第一天
|
|
DateTime startOfMonth = new DateTime(now.Year, now.Month, 1, 0, 0, 0);
|
|
// 本月的最后一天
|
|
DateTime endOfMonth = startOfMonth.AddMonths(1).AddSeconds(-1);
|
|
|
|
return (startOfMonth, endOfMonth);
|
|
}
|
|
public static (DateTime startOfWeek, DateTime endOfWeek) GetStartEndOfWeek()
|
|
{
|
|
DateTime now = DateTime.Now;
|
|
// 计算本周的第一天(假设一周从周一开始)
|
|
DateTime startOfWeek = now.AddDays(-((int)now.DayOfWeek - 1));
|
|
startOfWeek = startOfWeek.Date;
|
|
// 计算本周的最后一天(假设一周从周一开始,周日为最后一天)
|
|
DateTime endOfWeek = startOfWeek.AddDays(7).AddSeconds(-1);
|
|
return (startOfWeek, endOfWeek);
|
|
}
|
|
|
|
|
|
#region 统计数据
|
|
/// <summary>
|
|
/// 小组 人员 的任务数和图斑数
|
|
/// </summary>
|
|
/// <param name="type"></param>
|
|
/// <param name="dateType"></param>
|
|
/// <returns></returns>
|
|
public async Task<Response<List<UserOrGroupTaskResp>>> GetGroupOrUserTaskAndTuBan(int type, int dateType)
|
|
{
|
|
var user = _auth.GetCurrentUser().User;
|
|
|
|
DateTime beginTime, endTime;
|
|
if (dateType == 1)
|
|
{
|
|
beginTime = GetStartEndOfMonth().startOfMonth;
|
|
endTime = GetStartEndOfMonth().endOfMonth;
|
|
}
|
|
else if (dateType == 2)
|
|
{
|
|
beginTime = GetStartEndOfWeek().startOfWeek;
|
|
endTime = GetStartEndOfWeek().endOfWeek;
|
|
}
|
|
else
|
|
{
|
|
beginTime = DateTime.Today;
|
|
endTime = DateTime.Now;
|
|
}
|
|
|
|
using (var db = base.UnitWork.CreateContext())
|
|
{
|
|
// 获取当前用户相关的所有小组用户
|
|
var groupIds = await db.SysGroup.AsQueryable()
|
|
.Where(r => r.GroupLeaderId == user.Id.ToString())
|
|
.Select(r => r.Id)
|
|
.ToListAsync();
|
|
|
|
var groupUser = await db.SysGroupuser.AsQueryable()
|
|
.Where(r => groupIds.Contains(r.GroupId) || r.UserId == user.Id.ToString())
|
|
.Select(r => r.UserId)
|
|
.ToListAsync();
|
|
|
|
// 如果是小组统计
|
|
if (type == 1)
|
|
{
|
|
var result = await db.InsTaskgroup.AsQueryable()
|
|
.LeftJoin<SysUser>((a, b) => a.ReciveUserId == b.Id.ToString())
|
|
.WhereIF(beginTime.Year != 0001, a => a.CreateTime >= beginTime && a.CreateTime <= endTime)
|
|
.WhereIF(groupUser.Count > 0, a => groupUser.Contains(a.ReciveUserId))
|
|
.Where((a, b) => !string.IsNullOrEmpty(a.ReciveUserId))
|
|
.GroupBy((a, b) => b.Name)
|
|
.Select((a, b) => new UserOrGroupTaskResp
|
|
{
|
|
UserName = b.Name,
|
|
TaskCount = SqlFunc.AggregateCount(a.Id),
|
|
TuBanCount = SqlFunc.AggregateSum(a.EndNum - a.BeginNum),
|
|
}).MergeTable().OrderByDescending((t) => t.TuBanCount).ToListAsync();
|
|
|
|
return new Response<List<UserOrGroupTaskResp>>
|
|
{
|
|
Result = result,
|
|
};
|
|
}
|
|
// 如果是人员统计
|
|
else if (type == 2)
|
|
{
|
|
var result = await db.InsTaskgroup.AsQueryable()
|
|
.LeftJoin<SysGroupuser>((a, b) => a.ReciveUserId == b.UserId)
|
|
.LeftJoin<SysGroup>((a, b, c) => b.GroupId == c.Id)
|
|
.WhereIF(beginTime.Year != 0001, a => a.CreateTime >= beginTime && a.CreateTime <= endTime)
|
|
.WhereIF(groupUser.Count > 0, a => groupUser.Contains(a.ReciveUserId))
|
|
.Where((a, b) => !string.IsNullOrEmpty(a.ReciveUserId))
|
|
.GroupBy((a, b, c) => c.Name)
|
|
.Select((a, b, c) => new UserOrGroupTaskResp
|
|
{
|
|
UserName = c.Name,
|
|
TaskCount = SqlFunc.AggregateCount(a.Id),
|
|
TuBanCount = SqlFunc.AggregateSum(a.EndNum - a.BeginNum),
|
|
}).MergeTable().OrderByDescending((t) => t.TuBanCount).ToListAsync();
|
|
|
|
return new Response<List<UserOrGroupTaskResp>>
|
|
{
|
|
Result = result,
|
|
};
|
|
}
|
|
}
|
|
|
|
return new Response<List<UserOrGroupTaskResp>>(); // 默认返回空列表
|
|
}
|
|
|
|
/// <summary>
|
|
/// 小组 人员 的任务数和图斑数
|
|
/// </summary>
|
|
/// <param name="type"></param>
|
|
/// <param name="dateType"></param>
|
|
/// <returns></returns>
|
|
public async Task<Response<List<UserOrGroupTaskResp>>> GetGroupOrUserTaskAndTuBanByTime(DateTime beginTime, DateTime endTime)
|
|
{
|
|
var user = _auth.GetCurrentUser().User;
|
|
var role = _auth.GetCurrentUser().Roles;
|
|
|
|
using (var db = base.UnitWork.CreateContext())
|
|
{
|
|
// 获取当前用户相关的所有小组用户
|
|
var groupIds = await db.SysGroup.AsQueryable()
|
|
.Where(r => r.GroupLeaderId == user.Id.ToString())
|
|
.Select(r => r.Id)
|
|
.ToListAsync();
|
|
|
|
var groupUser = await db.SysGroupuser.AsQueryable()
|
|
.Where(r => groupIds.Contains(r.GroupId) || r.UserId == user.Id.ToString())
|
|
.ToListAsync();
|
|
|
|
// 管理员角色
|
|
if (role.Any(r => r.Name.Contains("管理员")) || user.Id == -1)
|
|
{
|
|
// 获取所有小组信息
|
|
var groupInfo = await db.SysGroup.AsQueryable().ToListAsync();
|
|
|
|
// 获取任务和图斑信息
|
|
var taskInfo = await db.InsTaskgroup.AsQueryable()
|
|
.LeftJoin<SysGroupuser>((a, b) => a.ReciveUserId == b.UserId)
|
|
.LeftJoin<SysGroup>((a, b, c) => b.GroupId == c.Id)
|
|
.WhereIF(beginTime.Year != 0001, a => a.CreateTime >= beginTime && a.CreateTime <= endTime)
|
|
.Where((a, b) => !string.IsNullOrEmpty(a.ReciveUserId))
|
|
.Select((a, b, c) => new
|
|
{
|
|
a.Id,
|
|
a.ReciveUserId,
|
|
c.Name,
|
|
a.IsComplate,
|
|
a.EndNum,
|
|
a.BeginNum
|
|
})
|
|
.ToListAsync();
|
|
|
|
// 组织任务信息
|
|
var groupTaskStats = groupInfo.Select(group =>
|
|
{
|
|
var groupTaskInfo = taskInfo.Where(t => t.Name == group.Name).ToList();
|
|
|
|
var taskCount = groupTaskInfo.Count;
|
|
var taskComplateCount = groupTaskInfo.Count(t => t.IsComplate);
|
|
var taskNoComplateCount = taskCount - taskComplateCount;
|
|
|
|
var tuBanCount = groupTaskInfo.Sum(t => t.EndNum - t.BeginNum + 1);
|
|
var tuBanComplateCount = groupTaskInfo.Where(t => t.IsComplate).Sum(t => t.EndNum - t.BeginNum + 1);
|
|
var tuBanNoComplateCount = tuBanCount - tuBanComplateCount;
|
|
|
|
return new UserOrGroupTaskResp
|
|
{
|
|
UserName = group.Name,
|
|
TaskCount = taskCount,
|
|
TaskComplateCount = taskComplateCount,
|
|
TaskNoComplateCount = taskNoComplateCount,
|
|
TuBanCount = tuBanCount,
|
|
TuBanComplateCount = tuBanComplateCount,
|
|
TuBanNoComplateCount = tuBanNoComplateCount
|
|
};
|
|
}).ToList();
|
|
|
|
return new Response<List<UserOrGroupTaskResp>>
|
|
{
|
|
Result = groupTaskStats
|
|
};
|
|
}
|
|
else if (groupIds.Count > 0)//小组查看人员
|
|
{
|
|
var users = await db.User.AsQueryable().Where(r => groupUser.Select(r => r.UserId).ToList().Contains(r.Id.ToString())).ToListAsync();
|
|
// 获取任务和图斑信息
|
|
var taskInfo = await db.InsTaskgroup.AsQueryable()
|
|
.WhereIF(beginTime.Year != 0001, a => a.CreateTime >= beginTime && a.CreateTime <= endTime)
|
|
.WhereIF(groupUser.Any(), a => groupUser.Select(r => r.UserId).ToList().Contains(a.ReciveUserId))
|
|
.Where((a) => !string.IsNullOrEmpty(a.ReciveUserId))
|
|
.Select((a) => new
|
|
{
|
|
a.Id,
|
|
a.ReciveUserId,
|
|
a.IsComplate,
|
|
a.EndNum,
|
|
a.BeginNum
|
|
}).ToListAsync();
|
|
var groupTaskStats = users.Select(group =>
|
|
{
|
|
var groupTaskInfo = taskInfo.Where(t => t.ReciveUserId == group.Id.ToString()).ToList();
|
|
|
|
var taskCount = groupTaskInfo.Count;
|
|
var taskComplateCount = groupTaskInfo.Count(t => t.IsComplate);
|
|
var taskNoComplateCount = taskCount - taskComplateCount;
|
|
|
|
var tuBanCount = groupTaskInfo.Sum(t => t.EndNum - t.BeginNum + 1);
|
|
var tuBanComplateCount = groupTaskInfo.Where(t => t.IsComplate).Sum(t => t.EndNum - t.BeginNum + 1);
|
|
var tuBanNoComplateCount = tuBanCount - tuBanComplateCount;
|
|
|
|
return new UserOrGroupTaskResp
|
|
{
|
|
UserName = group.Name,
|
|
TaskCount = taskCount,
|
|
TaskComplateCount = taskComplateCount,
|
|
TaskNoComplateCount = taskNoComplateCount,
|
|
TuBanCount = tuBanCount,
|
|
TuBanComplateCount = tuBanComplateCount,
|
|
TuBanNoComplateCount = tuBanNoComplateCount
|
|
};
|
|
}).ToList();
|
|
return new Response<List<UserOrGroupTaskResp>>
|
|
{
|
|
Result = groupTaskStats
|
|
};
|
|
}
|
|
else//查看个人任务列表
|
|
{
|
|
//var taskInfo = await db.InsTaskgroup.AsQueryable().Where(r => r.ReciveUserId == user.Id.ToString() && r.CreateTime >= beginTime && r.CreateTime <= endTime).ToListAsync();
|
|
//return new Response<List<UserOrGroupTaskResp>>
|
|
//{
|
|
// Result = taskInfo
|
|
//};
|
|
}
|
|
}
|
|
|
|
return new Response<List<UserOrGroupTaskResp>>(); // 默认返回空列表
|
|
}
|
|
|
|
|
|
//public async Task<Response<List<AiShpDataExpenseAccountingTableResp>>> GetAiShpDataExpenseAccountingTableOld(DateTime beginTime, DateTime endTime)
|
|
//{
|
|
// using (var db = base.UnitWork.CreateContext())
|
|
// {
|
|
// var aiShpList = db.InsAishp.AsQueryable()
|
|
// .WhereIF(beginTime.Year != 0001, r => r.CreateTime >= beginTime && r.CreateTime <= endTime);
|
|
// //总面积
|
|
// var totalTifArea = aiShpList.Sum(r => r.AreaNum);
|
|
// //个数
|
|
// var totalTifCount = aiShpList.Count();
|
|
|
|
// var endData = await aiShpList.GroupBy(r => r.ShpDate.Date).Select(r => new AiShpDataExpenseAccountingTableResp
|
|
// {
|
|
// ShapDate = r.ShpDate.Date.ToString("yyyyMMdd"),
|
|
// AreaNum = SqlFunc.AggregateSum(r.AreaNum),
|
|
// ShpCount = SqlFunc.AggregateSum(r.ShpCount),
|
|
// }).ToListAsync();
|
|
// return new Response<List<AiShpDataExpenseAccountingTableResp>>()
|
|
// {
|
|
// Result = endData
|
|
// };
|
|
// }
|
|
//}
|
|
public async Task<Response<AiShpDataExpenseAccountingTableResp>> GetAiShpDataExpenseAccountingTable1(DateTime beginTime, DateTime endTime)
|
|
{
|
|
using (var db = base.UnitWork.CreateContext())
|
|
{
|
|
List<DateTime> dateList = new List<DateTime>();
|
|
List<AiShpDataExpenseAccountingResp> dataList = new List<AiShpDataExpenseAccountingResp>();
|
|
if (beginTime > endTime)
|
|
{
|
|
throw new ArgumentException("开始时间需要小于结束时间");
|
|
}
|
|
// 从开始日期遍历到结束日期
|
|
for (DateTime date = beginTime.Date; date <= endTime.Date; date = date.AddDays(1))
|
|
{
|
|
dateList.Add(date);
|
|
}
|
|
var aiShpList = db.InsAishp.AsQueryable().WhereIF(beginTime.Year != 0001, r => r.CreateTime >= beginTime && r.CreateTime <= endTime);
|
|
var taskList = db.InsTask.AsQueryable().WhereIF(beginTime.Year != 0001, t => t.CreateTime >= beginTime && t.CreateTime <= endTime);
|
|
for (int i = 0; i < dateList.Count; i++)
|
|
{
|
|
AiShpDataExpenseAccountingResp aiShpDataExpenseAccountingResp = new AiShpDataExpenseAccountingResp();
|
|
|
|
var aiShpListDay = db.InsAishp.AsQueryable().Where(r => r.ShpDate >= dateList[i]);
|
|
aiShpDataExpenseAccountingResp.Number = i + 1;
|
|
aiShpDataExpenseAccountingResp.ShapDate = dateList[i].ToString("yyyyMMdd");
|
|
//提取个数
|
|
aiShpDataExpenseAccountingResp.AreaNum = await aiShpListDay.SumAsync(r => r.AreaNum);
|
|
aiShpDataExpenseAccountingResp.ShpCount = await aiShpListDay.SumAsync(r => r.ShpCount);
|
|
//下发数量
|
|
aiShpDataExpenseAccountingResp.IssuedCount = await taskList.Where(t => aiShpListDay.Select(r => r.Id).ToList().Contains(t.ShpId)).CountAsync();
|
|
|
|
}
|
|
AiShpDataExpenseAccountingTableResp aiShpDataExpenseAccountingTableResp = new AiShpDataExpenseAccountingTableResp();
|
|
aiShpDataExpenseAccountingTableResp.RespData = dataList;
|
|
//总面积
|
|
aiShpDataExpenseAccountingTableResp.TotalShpArea = aiShpList.Sum(r => r.AreaNum);
|
|
//个数
|
|
aiShpDataExpenseAccountingTableResp.TotalShpCount = aiShpList.Count();
|
|
return new Response<AiShpDataExpenseAccountingTableResp>()
|
|
{
|
|
Result = aiShpDataExpenseAccountingTableResp
|
|
};
|
|
}
|
|
}
|
|
public async Task<Response<AiShpDataExpenseAccountingTableResp>> GetAiShpDataExpenseAccountingTable(DateTime beginTime, DateTime endTime)
|
|
{
|
|
using (var db = base.UnitWork.CreateContext())
|
|
{
|
|
if (beginTime > endTime)
|
|
{
|
|
throw new ArgumentException("开始时间需要小于结束时间");
|
|
}
|
|
|
|
var dateList = Enumerable.Range(0, (endTime.Date - beginTime.Date).Days + 1)
|
|
.Select(offset => beginTime.Date.AddDays(offset))
|
|
.ToList();
|
|
|
|
var aiShpList = await db.InsAishp.AsQueryable()
|
|
.Where(r => r.ShpDate >= beginTime && r.ShpDate <= endTime)
|
|
.ToListAsync();
|
|
|
|
var taskList = await db.InsTask.AsQueryable()
|
|
.Where(t => t.CreateTime >= beginTime && t.CreateTime <= endTime)
|
|
.ToListAsync();
|
|
int TotalIssuedCount = 0;
|
|
decimal totalShpArea = 0;
|
|
int totalShpCount = 0;
|
|
var dataList = dateList.Select(date =>
|
|
{
|
|
var aiShpForDay = aiShpList.Where(r => r.ShpDate.Date == date).ToList();
|
|
|
|
var areaNum = aiShpForDay.Sum(r => r.AreaNum);
|
|
var shpCount = aiShpForDay.Sum(r => r.ShpCount ?? 0);
|
|
totalShpCount += shpCount;
|
|
//var issuedCount = taskList.Count(t => aiShpForDay.Any(r => r.Id == t.ShpId));
|
|
var issuedCount = shpCount;
|
|
TotalIssuedCount += issuedCount;
|
|
//文件夹
|
|
var folderPath = string.Join(",", aiShpForDay.Select(r =>
|
|
{
|
|
var directory = Path.GetDirectoryName(r.ShpPath); // 获取目录部分
|
|
return directory != null ? Path.GetFileName(directory) : string.Empty; // 获取目录名
|
|
}).ToList());
|
|
|
|
return new AiShpDataExpenseAccountingResp
|
|
{
|
|
Number = dateList.IndexOf(date) + 1,
|
|
ShapDate = date.ToString("MMdd"),
|
|
AreaNum = areaNum,
|
|
ShpCount = shpCount,
|
|
IssuedCount = issuedCount,
|
|
FolderPath = folderPath,
|
|
};
|
|
}).ToList();
|
|
|
|
var aiShpDataExpenseAccountingTableResp = new AiShpDataExpenseAccountingTableResp
|
|
{
|
|
RespData = dataList,
|
|
TotalShpArea = totalShpArea,
|
|
TotalShpCount = totalShpCount,
|
|
TotalShpProduction = 0,
|
|
TotalShpInterpretation = 0,
|
|
TotalJudgment = 0,
|
|
TotalPush = 0,
|
|
TotalCost = 0,
|
|
TotalIssuedCount = TotalIssuedCount
|
|
};
|
|
|
|
return new Response<AiShpDataExpenseAccountingTableResp>
|
|
{
|
|
Result = aiShpDataExpenseAccountingTableResp
|
|
};
|
|
}
|
|
}
|
|
//导出
|
|
public Response<MemoryStream> AiShpDataExpenseAccountingTableToExcel(DateTime startTime, DateTime endTime)
|
|
{
|
|
Response<MemoryStream> response = new Response<MemoryStream>();
|
|
try
|
|
{
|
|
var list = GetAiShpDataExpenseAccountingTable(startTime, endTime).Result;
|
|
HSSFWorkbook workbook = new HSSFWorkbook();
|
|
|
|
#region 样式设置
|
|
|
|
ICellStyle CreateCellStyle(HSSFWorkbook wb, short fontHeight, string fontName, HorizontalAlignment hAlign,
|
|
VerticalAlignment vAlign, bool bold = false)
|
|
{
|
|
IFont font = wb.CreateFont();
|
|
font.FontName = fontName;
|
|
font.FontHeightInPoints = fontHeight;
|
|
font.IsBold = bold;
|
|
|
|
ICellStyle style = wb.CreateCellStyle();
|
|
style.BorderBottom = BorderStyle.Thin;
|
|
style.BorderLeft = BorderStyle.Thin;
|
|
style.BorderRight = BorderStyle.Thin;
|
|
style.BorderTop = BorderStyle.Thin;
|
|
style.Alignment = hAlign;
|
|
style.VerticalAlignment = vAlign;
|
|
style.SetFont(font);
|
|
style.WrapText = true;
|
|
|
|
return style;
|
|
}
|
|
|
|
ICellStyle CreateCellStyle2(HSSFWorkbook wb, short fontHeight, string fontName, HorizontalAlignment hAlign,
|
|
VerticalAlignment vAlign, bool bold = false)
|
|
{
|
|
IFont font = wb.CreateFont();
|
|
font.FontName = fontName;
|
|
font.FontHeightInPoints = fontHeight;
|
|
font.IsBold = bold;
|
|
|
|
ICellStyle style = wb.CreateCellStyle();
|
|
style.Alignment = hAlign;
|
|
style.VerticalAlignment = vAlign;
|
|
style.SetFont(font);
|
|
style.WrapText = true;
|
|
|
|
return style;
|
|
}
|
|
|
|
// 创建右对齐样式
|
|
ICellStyle rightAlignStyle = workbook.CreateCellStyle();
|
|
rightAlignStyle.Alignment = HorizontalAlignment.Right; // 设置右对齐
|
|
rightAlignStyle.VerticalAlignment = VerticalAlignment.Center;
|
|
IFont font = workbook.CreateFont();
|
|
font.FontName = "宋体";
|
|
font.FontHeightInPoints = 12;
|
|
rightAlignStyle.SetFont(font);
|
|
rightAlignStyle.WrapText = true;
|
|
//第二个sheet右对齐样式
|
|
ICellStyle rightAlignStyle2 = workbook.CreateCellStyle();
|
|
rightAlignStyle2.Alignment = HorizontalAlignment.Right; // 设置右对齐
|
|
rightAlignStyle2.VerticalAlignment = VerticalAlignment.Center;
|
|
IFont font1 = workbook.CreateFont();
|
|
font1.FontName = "宋体";
|
|
font1.FontHeightInPoints = 9;
|
|
rightAlignStyle2.SetFont(font1);
|
|
rightAlignStyle2.WrapText = true;
|
|
|
|
ICellStyle contentStyle =
|
|
CreateCellStyle(workbook, 16, "宋体", HorizontalAlignment.Center, VerticalAlignment.Center);
|
|
ICellStyle titleStyle =
|
|
CreateCellStyle2(workbook, 10, "宋体", HorizontalAlignment.Left, VerticalAlignment.Center);
|
|
ICellStyle headerStyle1 = CreateCellStyle2(workbook, 18, "方正小标宋简体", HorizontalAlignment.Center,
|
|
VerticalAlignment.Center);
|
|
ICellStyle headerStyle2 =
|
|
CreateCellStyle(workbook, 16, "宋体", HorizontalAlignment.Right, VerticalAlignment.Center);
|
|
ICellStyle headerStyle3 =
|
|
CreateCellStyle(workbook, 16, "宋体", HorizontalAlignment.Center, VerticalAlignment.Center);
|
|
//第二个sheet
|
|
ICellStyle contentStyle22 =
|
|
CreateCellStyle(workbook, 12, "宋体", HorizontalAlignment.Center, VerticalAlignment.Center);
|
|
ICellStyle titleStyle2 =
|
|
CreateCellStyle2(workbook, 9, "宋体", HorizontalAlignment.Left, VerticalAlignment.Center);
|
|
ICellStyle headerStyle21 = CreateCellStyle2(workbook, 16, "方正小标宋简体", HorizontalAlignment.Center,
|
|
VerticalAlignment.Center, true);
|
|
ICellStyle headerStyle23 =
|
|
CreateCellStyle(workbook, 12, "国标宋体", HorizontalAlignment.Center, VerticalAlignment.Center, true);
|
|
ICellStyle headerStyle24 =
|
|
CreateCellStyle2(workbook, 12, "国标宋体", HorizontalAlignment.Left, VerticalAlignment.Center, true);
|
|
ICellStyle beizhuStyle21 =
|
|
CreateCellStyle2(workbook, 9, "宋体", HorizontalAlignment.Left, VerticalAlignment.Center);
|
|
|
|
#endregion
|
|
|
|
#region 第一个sheet
|
|
|
|
#region 创建表头
|
|
|
|
IRow CreateRowWithHeight(ISheet sht, int rowIndex, float heightInPoints)
|
|
{
|
|
IRow row = sht.CreateRow(rowIndex);
|
|
row.HeightInPoints = heightInPoints;
|
|
return row;
|
|
}
|
|
|
|
void SetCellStyle(IRow row, ICellStyle style)
|
|
{
|
|
foreach (NPOI.SS.UserModel.ICell cell in row.Cells)
|
|
{
|
|
cell.CellStyle = style;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
#region 第二个sheet
|
|
|
|
ISheet sheet2 = workbook.CreateSheet("Sheet1");
|
|
|
|
#region 创建表头
|
|
|
|
IRow row20 = CreateRowWithHeight(sheet2, 0, 29);
|
|
row20.CreateCell(0).SetCellValue("解译分析数据交付与费用记账表");
|
|
|
|
IRow row21 = CreateRowWithHeight(sheet2, 1, 22);
|
|
row21.CreateCell(0);
|
|
row21.CreateCell(1);
|
|
row21.CreateCell(2);
|
|
row21.CreateCell(3);
|
|
row21.CreateCell(4);
|
|
row21.CreateCell(5);
|
|
row21.CreateCell(6);
|
|
row21.CreateCell(7);
|
|
row21.CreateCell(8);
|
|
row21.CreateCell(9).SetCellValue("编号:");
|
|
row21.CreateCell(10);
|
|
row21.CreateCell(11);
|
|
IRow row22 = CreateRowWithHeight(sheet2, 2, 25);
|
|
|
|
row22.CreateCell(0).SetCellValue("序号");
|
|
row22.CreateCell(1).SetCellValue("日期");
|
|
row22.CreateCell(2).SetCellValue("影像生产");
|
|
row22.CreateCell(3).SetCellValue("影像解译");
|
|
row22.CreateCell(4).SetCellValue("研判分析");
|
|
row22.CreateCell(5).SetCellValue("图斑推送");
|
|
row22.CreateCell(6).SetCellValue("费用");
|
|
row22.CreateCell(7).SetCellValue("初始提取个数");
|
|
row22.CreateCell(8).SetCellValue("最终下发个数");
|
|
row22.CreateCell(9).SetCellValue("文件夹名称");
|
|
row22.CreateCell(10).SetCellValue("格式");
|
|
row22.CreateCell(11).SetCellValue("备注");
|
|
// 设置样式
|
|
SetCellStyle(row20, headerStyle21);
|
|
SetCellStyle(row22, headerStyle23);
|
|
SetCellStyle(row21, headerStyle24);
|
|
// 合并单元格
|
|
sheet2.AddMergedRegion(new CellRangeAddress(0, 0, 0, 11)); // 合并标题行
|
|
sheet2.AddMergedRegion(new CellRangeAddress(1, 1, 9, 11));
|
|
int[] normalColumns2 = { 1, 2, 3, 4, 5, 6, 10 };
|
|
foreach (var index in normalColumns2) sheet2.SetColumnWidth(index, 11 * 256); // 设置列宽
|
|
sheet2.SetColumnWidth(0, 6 * 256);
|
|
sheet2.SetColumnWidth(7, 14 * 256);
|
|
sheet2.SetColumnWidth(8, 14 * 256);
|
|
sheet2.SetColumnWidth(9, 13 * 256);
|
|
sheet2.SetColumnWidth(11, 8 * 256);
|
|
#endregion
|
|
|
|
#region 填充数据
|
|
for (int i = 0; i < list.Result.RespData.Count - 1; i++)
|
|
{
|
|
var rowIndex = i + 3; // 数据从第5行开始
|
|
var row = CreateRowWithHeight(sheet2, rowIndex, 32);
|
|
row.CreateCell(0).SetCellValue(list.Result.RespData[i].Number);
|
|
row.CreateCell(1).SetCellValue(list.Result.RespData[i].ShapDate.ToString());
|
|
row.CreateCell(2).SetCellValue(list.Result.RespData[i].ShpProduction);
|
|
row.CreateCell(3).SetCellValue(list.Result.RespData[i].ShpInterpretation);
|
|
row.CreateCell(4).SetCellValue(list.Result.RespData[i].Judgment);
|
|
row.CreateCell(5).SetCellValue(list.Result.RespData[i].Push);
|
|
//row.CreateCell(6).SetCellValue(list.Result.RespData[i].Cost);
|
|
row.CreateCell(6).SetCellFormula($"F{rowIndex + 1}*9");
|
|
row.CreateCell(7).SetCellValue(list.Result.RespData[i].ShpCount.ToString());
|
|
row.CreateCell(8).SetCellValue(list.Result.RespData[i].IssuedCount);
|
|
row.CreateCell(9).SetCellValue(list.Result.RespData[i].FolderPath);
|
|
row.CreateCell(10).SetCellValue(list.Result.RespData[i].Format);
|
|
row.CreateCell(11).SetCellValue(list.Result.RespData[i].Remark);
|
|
SetCellStyle(row, headerStyle23);
|
|
}
|
|
#endregion
|
|
|
|
//填充完数据,合并单元格
|
|
sheet2.AddMergedRegion(new CellRangeAddress(list.Result.RespData.Count + 2, list.Result.RespData.Count + 2, 0, 1)); // 合并
|
|
sheet2.AddMergedRegion(new CellRangeAddress(list.Result.RespData.Count + 3, list.Result.RespData.Count + 3, 0, 1));
|
|
sheet2.AddMergedRegion(new CellRangeAddress(list.Result.RespData.Count + 4, list.Result.RespData.Count + 4, 0, 1));
|
|
sheet2.AddMergedRegion(new CellRangeAddress(list.Result.RespData.Count + 5, list.Result.RespData.Count + 5, 0, 1));
|
|
//sheet2.AddMergedRegion(new CellRangeAddress(list.Result.RespData.Count + 2, list.Result.RespData.Count + 2, 2, 6));
|
|
//sheet2.AddMergedRegion(new CellRangeAddress(list.Result.RespData.Count + 2, list.Result.RespData.Count + 2, 8, 11));
|
|
|
|
sheet2.AddMergedRegion(new CellRangeAddress(list.Result.RespData.Count + 3, list.Result.RespData.Count + 3, 2, 6));
|
|
sheet2.AddMergedRegion(new CellRangeAddress(list.Result.RespData.Count + 3, list.Result.RespData.Count + 3, 8, 11));
|
|
|
|
sheet2.AddMergedRegion(new CellRangeAddress(list.Result.RespData.Count + 4, list.Result.RespData.Count + 4, 2, 6));
|
|
sheet2.AddMergedRegion(new CellRangeAddress(list.Result.RespData.Count + 4, list.Result.RespData.Count + 4, 8, 11));
|
|
|
|
sheet2.AddMergedRegion(new CellRangeAddress(list.Result.RespData.Count + 5, list.Result.RespData.Count + 5, 2, 6));
|
|
sheet2.AddMergedRegion(new CellRangeAddress(list.Result.RespData.Count + 5, list.Result.RespData.Count + 5, 8, 11));
|
|
|
|
IRow rowhj = CreateRowWithHeight(sheet2, list.Result.RespData.Count + 2, 33);
|
|
rowhj.CreateCell(0).SetCellValue("合计");
|
|
rowhj.CreateCell(1);
|
|
rowhj.CreateCell(2).SetCellValue(list.Result.TotalShpProduction);
|
|
rowhj.CreateCell(3).SetCellValue(list.Result.TotalShpInterpretation);
|
|
rowhj.CreateCell(4).SetCellValue(list.Result.TotalJudgment);
|
|
rowhj.CreateCell(5).SetCellValue(list.Result.TotalPush);
|
|
//rowhj.CreateCell(6).SetCellValue(list.Result.TotalCost);
|
|
rowhj.CreateCell(6).SetCellFormula($"SUM(G4:G{list.Result.RespData.Count + 2})");
|
|
rowhj.CreateCell(7).SetCellValue(list.Result.TotalShpCount);
|
|
rowhj.CreateCell(8).SetCellValue(list.Result.TotalIssuedCount);
|
|
rowhj.CreateCell(9);
|
|
rowhj.CreateCell(10);
|
|
rowhj.CreateCell(11);
|
|
SetCellStyle(rowhj, headerStyle23);
|
|
IRow rowjf = CreateRowWithHeight(sheet2, list.Result.RespData.Count + 3, 33);
|
|
rowjf.CreateCell(0).SetCellValue("交付单位");
|
|
rowjf.CreateCell(1);
|
|
rowjf.CreateCell(2);
|
|
rowjf.CreateCell(3);
|
|
rowjf.CreateCell(4);
|
|
rowjf.CreateCell(5);
|
|
rowjf.CreateCell(6);
|
|
rowjf.CreateCell(7).SetCellValue("接收单位");
|
|
rowjf.CreateCell(8);
|
|
rowjf.CreateCell(9);
|
|
rowjf.CreateCell(10);
|
|
rowjf.CreateCell(11);
|
|
SetCellStyle(rowjf, headerStyle23);
|
|
IRow rowjb = CreateRowWithHeight(sheet2, list.Result.RespData.Count + 4, 33);
|
|
rowjb.CreateCell(0).SetCellValue("交付经办人");
|
|
rowjb.CreateCell(1);
|
|
rowjb.CreateCell(2);
|
|
rowjb.CreateCell(3);
|
|
rowjb.CreateCell(4);
|
|
rowjb.CreateCell(5);
|
|
rowjb.CreateCell(6);
|
|
rowjb.CreateCell(7).SetCellValue("接收经办人");
|
|
rowjb.CreateCell(8);
|
|
rowjb.CreateCell(9);
|
|
rowjb.CreateCell(10);
|
|
rowjb.CreateCell(11);
|
|
SetCellStyle(rowjb, headerStyle23);
|
|
IRow rowrq = CreateRowWithHeight(sheet2, list.Result.RespData.Count + 5, 33);
|
|
rowrq.CreateCell(0).SetCellValue("交付日期");
|
|
rowrq.CreateCell(1);
|
|
rowrq.CreateCell(2);
|
|
rowrq.CreateCell(3);
|
|
rowrq.CreateCell(4);
|
|
rowrq.CreateCell(5);
|
|
rowrq.CreateCell(6);
|
|
rowrq.CreateCell(7).SetCellValue("接收日期");
|
|
rowrq.CreateCell(8);
|
|
rowrq.CreateCell(9);
|
|
rowrq.CreateCell(10);
|
|
rowrq.CreateCell(11);
|
|
SetCellStyle(rowrq, headerStyle23);
|
|
#endregion
|
|
|
|
response.Result = new MemoryStream();
|
|
workbook.Write(response.Result);
|
|
response.Result.Position = 0;
|
|
workbook.Close();
|
|
|
|
response.Code = 200;
|
|
response.Message = "获取成功";
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
response.Code = 500;
|
|
response.Message = ex.Message;
|
|
}
|
|
|
|
return response;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|