using Infrastructure;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using NetTopologySuite.Features;
using NetTopologySuite.Geometries;
using NetTopologySuite.IO;
using OpenAuth.App.FormModule;
using OpenAuth.App.Request;
using OpenAuth.App.ServiceApp;
using OpenAuth.App.ServiceApp.DroneCaseInfo;
using OpenAuth.App.ServiceApp.DroneCaseInfo.Request;
using OpenAuth.App.ServiceApp.DroneCaseInfo.Response;
using OpenAuth.App.ServiceApp.Jobs;
using OpenAuth.App.ServiceApp.Request;
using OpenAuth.App.ServiceApp.Response;
using OpenAuth.Repository.Domain;
using System.IO.Compression;
using System.Text;

namespace OpenAuth.WebApi.Controllers.ServiceControllers;

/// <summary>
/// 工作管理
/// </summary>
[Route("api/[controller]/[action]")]
[ApiController]
public class DroneCaseInfoMineralsController : ControllerBase
{
    private readonly DroneCaseInfoMineralsApp _app;

    private readonly CloudQueryTask _task;

    private readonly CloudQueryTimeTask _land;

    private readonly CloudQueryScreenshotTask _shot;


    public DroneCaseInfoMineralsController(DroneCaseInfoMineralsApp app, CloudQueryTask task, CloudQueryTimeTask land, CloudQueryScreenshotTask shot)
    {
        _app = app;
        _task = task;
        _land = land;
        _shot = shot;
    }

    /// <summary>
    /// 案件详情
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    [HttpGet]
    public async Task<Response<DroneCaseInfoMinerals>> GetCaseInfoById(string id)
    {
        var response = new Response<DroneCaseInfoMinerals>();
        try
        {
            return await _app.GetCaseInfoById(id);
        }
        catch (Exception ex)
        {
            response.Code = 500;
            response.Message = ex.InnerException?.Message ?? ex.Message;
        }

        return response;
    }

    #region 工作管理

    //     // handle_status_id  1-待填报， 2-待整改， 3-待县级审核，
    // 4-待市级审核 5-待查处 6. 查处待县级审核 7. 查处待市级审核
    // 8. 查处后待整改 9. 整改后待县级审核 10. 整改后待市级审核 99-已归档
    // 返回字段 县区 街镇 图斑号 处理状态 图斑类型 总面积 违法面积 耕地面积
    // todo 关于驳回后违法不违法是否需要判断 图斑调整后，案件是否需要查询
    /// <summary>
    /// 图斑调整
    /// </summary>
    /// <param name="req"></param>
    /// <returns>查询待填报图斑</returns>
    [HttpGet]
    [Obsolete]
    public async Task<Response<PageInfo<List<dynamic>>>> LoadModifyingTaskList([FromQuery] MineralsTaskListReq req)
    {
        return await _app.LoadModifyingTaskList(req);
    }

    /// <summary>
    /// 图斑填报
    /// </summary>
    /// <param name="req"></param>
    /// <returns>查询待填报，整改的图斑</returns>
    [HttpGet]
    public async Task<Response<PageInfo<List<dynamic>>>> LoadReportingTaskList([FromQuery] MineralsTaskListReq req)
    {
        return await _app.LoadReportingTaskList(req);
    }

    /// <summary>
    /// 填报审核
    /// </summary>
    /// <param name="req"></param>
    /// <returns>填报及违法整改之后的审核（审核有handle_status_id  3-县级审核， 4-市级审核）</returns>
    [HttpGet]
    public async Task<Response<PageInfo<List<MineralsCaseInfoResponse>>>> LoadReportingAuditTaskList([FromQuery] MineralsTaskListReq req)
    {
        return await _app.LoadReportingAuditTaskList(req);
    }

    /// <summary>
    /// 图斑查处
    /// </summary>
    /// <param name="req"></param>
    /// <returns></returns>
    [HttpGet]
    public async Task<Response<PageInfo<List<dynamic>>>> LoadExaminingTaskList([FromQuery] MineralsTaskListReq req)
    {
        return await _app.LoadExaminingTaskList(req);
    }

    /// <summary>
    /// 查处审核
    /// </summary>
    /// <param name="req"></param>
    /// <returns></returns>
    [HttpGet]
    [Obsolete(message:"矿产专题已不使用")]
    public async Task<Response<PageInfo<List<dynamic>>>> LoadExaminingAuditTaskList([FromQuery] MineralsTaskListReq req)
    {
        return await _app.LoadExaminingAuditTaskList(req);
    }

    /// <summary>
    /// 图斑整改
    /// </summary>
    /// <param name="req"></param>
    /// <returns></returns>
    [HttpGet]
    public async Task<Response<PageInfo<List<dynamic>>>> LoadRectifyingTaskList([FromQuery] MineralsTaskListReq req)
    {
        return await _app.LoadRectifyingTaskList(req);
    }

    /// <summary>
    /// 整改审核 
    /// </summary>
    /// <param name="req"></param>
    /// <returns></returns>
    [HttpGet]
    public async Task<Response<PageInfo<List<dynamic>>>> LoadRectifyingAuditTaskList(
        [FromQuery] MineralsTaskListReq req)
    {
        return await _app.LoadRectifyingAuditTaskList(req);
    }


    #region 图斑收藏

    /// <summary>
    /// 图斑收藏
    /// </summary>
    /// <param name="model"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<Response<bool>> AddTaskFavorite([FromBody] DroneTaskFavorite model)
    {
        Response<bool> response = new Response<bool>();
        try
        {
            response = await _app.AddTaskFavorite(model);
        }
        catch (Exception ex)
        {
            response.Code = 500;
            response.Message = ex.InnerException?.Message ?? ex.Message;
        }
        return response;
    }

    /// <summary>
    /// 图斑取消收藏
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>

    [HttpPost]
    public async Task<Response<bool>> CancelTaskFavorite([FromBody] string id)
    {
        Response<bool> response = new Response<bool>();
        try
        {
            response = await _app.CancelTaskFavorite(id);
        }
        catch (Exception ex)
        {
            response.Code = 500;
            response.Message = ex.InnerException?.Message ?? ex.Message;
        }
        return response;
    }





    #endregion

    #endregion

    /// <summary>
    /// 图斑列表
    /// </summary>
    /// <param name="req"></param>
    /// <returns></returns>
    [HttpGet]
    public async Task<Response<PageInfo<List<dynamic>>>> LoadCaseInfoMineralsTuBanList(
        [FromQuery] CaseInfoMineralsTuBanReq req)
    {
        return await _app.LoadCaseInfoMineralsTuBanList(req);
    }

    #region 统计台账
    /// <summary>
    /// 开采台账
    /// </summary>
    /// <param name="req"></param>
    /// <returns></returns>
    [HttpGet]
    public async Task<Response<PageInfo<List<MineralsLedgerResp>>>> LoadMineralsLedger([FromQuery] QueryCaseOffencetReq req)
    {
        return await _app.LoadMineralsLedger(req);
    }
    /// <summary>
    /// 导出开采台账
    /// </summary>
    /// <param name="req"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<IActionResult> ExprotMineralsLedger([FromQuery] QueryCaseOffencetReq req)
    {
        var res = new Response();

        // 获取列表数据
        Response<PageInfo<List<MineralsLedgerResp>>> response = await _app.LoadMineralsLedger(req);
        if (response.Code != 200)
        {
            res.Code = response.Code;
            res.Message = "获取数据失败";
            return Ok(res);
        }
        // 获取模板数据
        List<ModuleColumn> headers = GetHeaders();
        // 导出Excel
        var excelRes = _app.ListToExcelMineralsLedger(response.Result.Items, headers);
        if (excelRes.Code == 200)
        {
            return File(excelRes.Result.ToArray(),
                "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
                $"开采台账{DateTime.Now:yyyyMMddHHmmss}.xls");
        }
        else
        {
            res.Code = excelRes.Code;
            res.Message = "导出失败";
        }

        return Ok(res);
    }
    private List<ModuleColumn> GetHeaders()
    {
        var headers = new List<ModuleColumn>
        {
            new() { key = "xuhao", value = "序号" },
            new() { key = "syear_base", value = "年" },
            new() { key = "xiafatime_base", value = "接收时间" },
            new() { key = "tubannum_base", value = "编号" },
            new() { key = "laiyuan_base", value = "线索来源" },
            new() { key = "miaoshu_base", value = "线索描述" },
            new() { key = "weizhixianname_base", value = "县区" },
            new() { key = "weizhizhenname_base", value = "乡镇" },
            new() { key = "weizhicunname_base", value = "村居" },
            new() { key = "kaicaizhuti_kcfill", value = "开采主体" },
            new() { key = "zhutitype_kcfill", value = "主体类型" },
            new() { key = "fashentime_kcfill", value = "违法行为发生时间" },
            new() { key = "endtime_kcfill", value = "违法行为结束时间" },
            new() { key = "kuangzhong_kcfill", value = "矿种" },
            new() { key = "kaicaiarea_kcfill", value = "开采面积" },
            new() { key = "fangliang_kcfill", value = "方量" },
            new() { key = "chafengliang_kcfill", value = "采出的矿产品查封方量" },
            new() { key = "caichujiazhi_kcfill", value = "采出的矿产品价值" },
            new() { key = "hefaqingxing_kcfill", value = "是否村民自采自用" },
            new() { key = "ishedaocaisha_kcfill", value = "是否河道采砂" },
            new() { key = "hefapanding_fill", value = "是否非法采矿行为" },
            new() { key = "islian_punish", value = "是否符合立案条件" },
            new() { key = "isnewadd_kcfill", value = "是否新增" },
            new() { key = "wefatype_kcfill", value = "违法类型" },
            new() { key = "iszhongda_kcfill", value = "是否重大典型问题" },
            new() { key = "iszhongdian_kcfill", value = "是否位于重点敏感区域" },
            new() { key = "isshexing", value = "是否涉刑" },
            new() { key = "tianbaoren_fill", value = "核查人员名单" },
            new() { key = "xianshenheren_fill", value = "审核人员名单" },
            new() { key = "chulishixian_base", value = "办理时间限定" },
            new() { key = "shuoming_fill", value = "是否提交核查报告" },

        };
        return headers;
    }

    /// <summary>
    /// 加工台账
    /// </summary>
    /// <param name="req"></param>
    /// <returns></returns>
    [HttpGet]
    public async Task<Response<PageInfo<List<MineralsProcessResp>>>> LoadMineralsProcess([FromQuery] QueryCaseOffencetReq req)
    {
        return await _app.LoadMineralsProcess(req);
    }
    /// <summary>
    /// 导出加工台账
    /// </summary>
    /// <param name="req"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<IActionResult> ExprotMineralsProcess([FromQuery] QueryCaseOffencetReq req)
    {
        var res = new Response();

        // 获取列表数据
        Response<PageInfo<List<MineralsProcessResp>>> response = await _app.LoadMineralsProcess(req);
        if (response.Code != 200)
        {
            res.Code = response.Code;
            res.Message = "获取数据失败";
            return Ok(res);
        }
        // 获取模板数据
        List<ModuleColumn> headers = GetProcessHeaders();
        // 导出Excel
        var excelRes = _app.ListToExcelMineralsProcess(response.Result.Items, headers);
        if (excelRes.Code == 200)
        {
            return File(excelRes.Result.ToArray(),
                "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
                $"加工台账{DateTime.Now:yyyyMMddHHmmss}.xls");
        }
        else
        {
            res.Code = excelRes.Code;
            res.Message = "导出失败";
        }

        return Ok(res);
    }
    private List<ModuleColumn> GetProcessHeaders()
    {
        var headers = new List<ModuleColumn>
        {
            new() { key = "xuhao", value = "序号" },
            new() { key = "syear_base", value = "年" },
            new() { key = "xiafatime_base", value = "接收时间" },
            new() { key = "tubannum_base", value = "编号" },
            new() { key = "laiyuan_base", value = "线索来源" },
            new() { key = "miaoshu_base", value = "线索描述" },
            new() { key = "weizhixianname_base", value = "县区" },
            new() { key = "weizhizhenname_base", value = "乡镇" },
            new() { key = "weizhicunname_base", value = "村居" },
            new() { key = "danweiname_jgzhg", value = "开采主体" },
            new() { key = "weifatype_jgfill", value = "违法类型" },
            new() { key = "zhenggaitype_jgzhg", value = "整改类型" },
            new() { key = "tianbaoren_fill", value = "核查人员名单" },
            new() { key = "xianshenheren_fill", value = "审核人员名单" },
            new() { key = "chulishixian_base", value = "办理时间限定" },
            new() { key = "shuoming_fill", value = "是否提交核查报告" },

        };
        return headers;
    }
    #endregion

    /// <summary>
    /// 图斑列表excel导出
    /// </summary>
    /// <param name="req"></param>
    /// <returns></returns>
    [HttpPost]
    public IActionResult ExportCaseInfoMineralsTuBanList([FromQuery] CaseInfoMineralsTuBanReq req)
    {
        var res = new Response();
        //获取列表数
        Response<List<CaseInfoMineralTubanExport>> response = _app.LoadCaseInfoMineralsExportTuBanList(req);
        //获取模板数据
        List<ModuleColumn> headers = new List<ModuleColumn>();
        ModuleColumn m01 = new ModuleColumn();
        m01.key = "xuhao";
        m01.value = "序号";
        headers.Add(m01);
        ModuleColumn m1 = new ModuleColumn();
        m1.key = "syear_base";
        m1.value = "年度";
        headers.Add(m1);
        ModuleColumn m411 = new ModuleColumn();
        m411.key = "tubannum_base";
        m411.value = "图斑编号";
        headers.Add(m411);
        ModuleColumn m2 = new ModuleColumn();
        m2.key = "weizhixianname_base";
        m2.value = "县区名称";
        headers.Add(m2);
        ModuleColumn m3 = new ModuleColumn();
        m3.key = "weizhizhenname_base";
        m3.value = "乡镇名称";
        headers.Add(m3);
        ModuleColumn m31 = new ModuleColumn();
        m31.key = "weizhicunname_base";
        m31.value = "社区/村名称";
        headers.Add(m31);
        ModuleColumn m4 = new ModuleColumn();
        m4.key = "type_base";
        m4.value = "图斑类型";
        headers.Add(m4);
        ModuleColumn m41 = new ModuleColumn();
        m41.key = "kuangzhong_kcfill";
        m41.value = "矿种";
        headers.Add(m41);
        ModuleColumn m5 = new ModuleColumn();
        m5.key = "shuoming_fill";
        m5.value = "图斑变化情况说明";
        headers.Add(m5);
        ModuleColumn m6 = new ModuleColumn();
        m6.key = "zhongdianname_base";
        m6.value = "所属重点矿区名称";
        headers.Add(m6);
        ModuleColumn m711 = new ModuleColumn();
        m711.key = "ziranbaohuname_base";
        m711.value = "所在国建自然保护区名称";
        headers.Add(m711);
        ModuleColumn m7 = new ModuleColumn();
        m7.key = "weifaarea_base";
        m7.value = "图斑面积";
        headers.Add(m7);
        ModuleColumn m71 = new ModuleColumn();
        m71.key = "jbntarea_base";
        m71.value = "耕地面积";
        headers.Add(m71);
        ModuleColumn m8 = new ModuleColumn();
        m8.key = "kaicaiarea_kcfill";
        m8.value = "违法开采面积";
        headers.Add(m8);
        ModuleColumn m9 = new ModuleColumn();
        m9.key = "weifaarea_punish";
        m9.value = "违法占地面积";
        headers.Add(m9);
        ModuleColumn m111 = new ModuleColumn();
        m111.key = "jieshou_people";
        m111.value = "是否持续违法";
        headers.Add(m111);
        ModuleColumn m121 = new ModuleColumn();
        m121.key = "status_base";
        m121.value = "当前状态";
        headers.Add(m121);
        ModuleColumn m11 = new ModuleColumn();
        m11.key = "hefapanding_fill";
        m11.value = "判定结果";
        headers.Add(m11);
        ModuleColumn m12 = new ModuleColumn();
        m12.key = "xiafatime_base";
        m12.value = "下发时间";
        headers.Add(m12);
        ModuleColumn m13 = new ModuleColumn();
        m13.key = "kaicaizhuti_kcfill";
        m13.value = "项目主体";
        headers.Add(m13);
        ModuleColumn m14 = new ModuleColumn();
        m14.key = "wefatype_kcfill";
        m14.value = "开采违法类型";
        headers.Add(m14);
        ModuleColumn m221 = new ModuleColumn();
        m221.key = "weifatype_jgfill";
        m221.value = "加工违法类型";
        headers.Add(m221);
        ModuleColumn m131 = new ModuleColumn();
        m131.key = "zhenggaitype_jgzhg";
        m131.value = "整改措施";
        headers.Add(m131);
        ModuleColumn m141 = new ModuleColumn();
        m141.key = "chulishixian_base";
        m141.value = "处理时限";
        headers.Add(m141);
      /*  ModuleColumn m10 = new ModuleColumn();
        m10.key = "measureName";
        m10.value = "整改措施";
        headers.Add(m10);
        ModuleColumn m15 = new ModuleColumn();
        m15.key = "transactor_name";
        m15.value = "办理人";
        headers.Add(m15);
        ModuleColumn m151 = new ModuleColumn();
        m151.key = "transact_time";
        m151.value = "办理时间";
        headers.Add(m151);
        ModuleColumn m152 = new ModuleColumn();
        m152.key = "remark";
        m152.value = "备注";
        headers.Add(m152);
        ModuleColumn m23 = new ModuleColumn();
        m23.key = "xjshenhejieguo";
        m23.value = "县级审核结果";
        headers.Add(m23);
        ModuleColumn m24 = new ModuleColumn();
        m24.key = "xianjiyijian";
        m24.value = "县级审核意见";
        headers.Add(m24);
        ModuleColumn m25 = new ModuleColumn();
        m25.key = "verifyuser";
        m25.value = "县级审核人";
        headers.Add(m25);
        ModuleColumn m26 = new ModuleColumn();
        m26.key = "verifytime";
        m26.value = "县级审核时间";
        headers.Add(m26);
        ModuleColumn m27 = new ModuleColumn();
        m27.key = "sjshenhejieguo";
        m27.value = "市级审核结果";
        headers.Add(m27);
        ModuleColumn m28 = new ModuleColumn();
        m28.key = "shijiyijian";
        m28.value = "市级审核意见";
        headers.Add(m28);
        ModuleColumn m29 = new ModuleColumn();
        m29.key = "hexiaoren";
        m29.value = "市级审核人";
        headers.Add(m29);
        ModuleColumn m30 = new ModuleColumn();
        m30.key = "hexiaotime";
        m30.value = "市级审核时间";
        headers.Add(m30);*/
        var excelRes = _app.ListToExcelTuban(response.Result, headers);
        if (excelRes.Code == 200)
        {
            return File(excelRes.Result.ToArray(),
                "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
                "数据导出" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls");
        }
        else
        {
            res.Code = excelRes.Code;
            res.Message = "导出失败";
        }
        return Ok(res);
    }

    /// <summary>
    /// 导出非法采矿shp文件
    /// </summary>
    /// <param name="req"></param>
    /// <returns></returns>
    [HttpPost]
    public IActionResult ExportIllegalCaiKuangShapefile([FromQuery] CaseInfoMineralsTuBanReq req)
    {
        try
        {
            string shpFilePath = Path.Combine(Path.GetTempPath(), $"图斑信息{DateTime.Now:yyyyMMddHHmmss}.shp");
            string shpFilePathzip = Path.Combine(Path.GetTempPath(), $"图斑信息{DateTime.Now:yyyyMMddHHmmss}.zip");
            _app.ExportIllegalCaiKuangShapefile(req, shpFilePath, shpFilePathzip);
            byte[] fileBytes = System.IO.File.ReadAllBytes(shpFilePathzip);
            return File(fileBytes, "application/octet-stream", $"图斑信息{DateTime.Now:yyyyMMddHHmmss}.zip");
        }
        catch (Exception ex)
        {
            return StatusCode(500, $"Internal server error: {ex.Message}");
        }
    }
    [HttpGet]
    public async Task<Response<Dictionary<string, object>>> LoadMyUncompletedKuangChanTask([FromQuery] MineralsTaskListReq req)
    {
        return await _app.LoadMyUncompletedKuangChanTask(req);
    }


    [HttpGet]
   
    public async Task<Response<Dictionary<string, object>>> LoadAllKuangChanTask([FromQuery] MineralsTaskListReq req)
    {
        return await _app.LoadAllKuangChanTask(req);
    }
    /// <summary>
    /// 图斑调整
    /// </summary>
    /// <param name="req"></param>
    /// <returns></returns>
    [HttpGet]
    public async Task<Response<PageInfo<List<dynamic>>>> LoadTasklList([FromQuery] TaskListReq req)
    {
        return await _app.LoadTaskList(req);
    }

    [HttpPost]
    public Response<string> UpdateDroneCaseInfo(DronCaseSingleCityUpdateReq req)
    {
        Response<string> response = new Response<string>();
        try
        {
            _app.UpdateDroneCaseInfo(req);
            response.Result = "修改成功";
        }
        catch (Exception ex)
        {
            response.Code = 500;
            response.Message = ex.InnerException?.Message ?? ex.Message;
        }

        return response;


    }

    /// <summary>
    /// 案件还原合并
    /// </summary>
    /// <param name="req"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<Response<string>> CaseRecover([FromBody] CaseRecoverReq req)
    {

        Response<string> response = new Response<string>();
        try
        {
            return await _app.CaseRecover(req);
        }
        catch (Exception ex)
        {
            response.Code = 500;
            response.Message = ex.InnerException?.Message ?? ex.Message;
        }
        return response;
    }
    [AllowAnonymous]
    [HttpGet]
    public async void test() {
        await _task.Execute1();
    }
    [AllowAnonymous]
    [HttpGet]
    public async void test1()
    {
        await _land.Execute1();
    }

    [AllowAnonymous]
    [HttpGet]
    public async void test2()
    {
        await _shot.Execute1();
    }

    /// <summary>
    /// 关闭案件--矿产专题
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<Response<bool>> CloseMineralCaseInfo(CloseCaseInfoReq req)
    {
        Response<bool> response = new Response<bool>();
        try
        {
            response = await _app.CloseMineralCaseInfo(req.id,req.closereason);
        }
        catch (Exception ex)
        {
            response.Code = 500;
            response.Message = ex.InnerException?.Message ?? ex.Message;
        }
        return response;
    }

    /// <summary>
    /// 案件信息列表
    /// </summary>
    /// <param name="req"></param>
    /// <returns></returns>
    [HttpGet]
    public async Task<Response<PageInfo<List<dynamic>>>> LoadCaseInfoCheckTuBanList([FromQuery] CaseInfoTypeName req)
    {
        return await _app.LoadCaseInfoCheckTuBanList(req);
    }

    
    /// <summary>
    /// 矿产下发待审核shape导出
    /// </summary>
    /// <param name="req"></param>
    /// <returns></returns>
    [HttpPost]
    public IActionResult ExportApprovalCaseInfoShapefile([FromQuery] CaseInfoTypeName req )
    {
        try
        {
            string shpFilePath = Path.Combine(Path.GetTempPath(), $"图斑信息{DateTime.Now:yyyyMMddHHmmss}.shp");
            string shpFilePathZip = Path.Combine(Path.GetTempPath(), $"图斑信息{DateTime.Now:yyyyMMddHHmmss}.zip");
            _app.ExportApprovalCaseInfoShapefile(req,shpFilePath, shpFilePathZip);
            byte[] fileBytes = System.IO.File.ReadAllBytes(shpFilePathZip);
            return File(fileBytes, "application/octet-stream", $"图斑信息{DateTime.Now:yyyyMMddHHmmss}.zip");

        }
        catch (Exception ex)
        {
            return StatusCode(500, $"Internal server error: {ex.Message}");
        }
    }
    
    #region 采矿统计表
    /// <summary>
    /// 采矿汇总表
    /// </summary>
    /// <param name="startTime"></param>
    /// <param name="endTime"></param>
    /// <returns></returns>
    [HttpGet]
    public Response<List<OffenceMineralsResp>> CaseOffenceMinerals(DateTime startTime, DateTime endTime)
    {
        Response<List<OffenceMineralsResp>> response = new Response<List<OffenceMineralsResp>>();
        try
        {
            response = _app.CaseMineralsForExcel(startTime, endTime);
        }
        catch (Exception ex)
        {
            response.Code = 500;
            response.Message = ex.InnerException?.Message ?? ex.Message;
        }

        return response;
    }
    /// <summary>
    /// 导出汇总表
    /// </summary>
    /// <param name="startTime"></param>
    /// <param name="endTime"></param>
    /// <returns></returns>
    [HttpPost]
    public IActionResult CaseOfMineralsToExcel(DateTime startTime, DateTime endTime)
    {
        var res = new Response();
        var excelRes = _app.CaseOfMineralsToExcel(startTime, endTime);
        if (excelRes.Code == 200)
        {
            return File(excelRes.Result.ToArray(),
                "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
                "汇总表.xls");
        }
        else
        {
            res.Code = excelRes.Code;
            res.Message = excelRes.Message;
        }
        return Ok(res);
    }
    #endregion

    #region 采矿统计表
    /// <summary>
    /// 采矿汇总表
    /// </summary>
    /// <param name="startTime"></param>
    /// <param name="endTime"></param>
    /// <returns></returns>
    [HttpGet]
    public Response<List<OffenceMineralsNewResp>> CaseOffenceMineralsNew(DateTime startTime, DateTime endTime,string tubanlaiyuan)
    {
        Response<List<OffenceMineralsNewResp>> response = new Response<List<OffenceMineralsNewResp>>();
        try
        {
            response = _app.CaseMineralsForExcelNew(startTime, endTime,tubanlaiyuan);
        }
        catch (Exception ex)
        {
            response.Code = 500;
            response.Message = ex.InnerException?.Message ?? ex.Message;
        }

        return response;
    }
    /// <summary>
    /// 导出汇总表
    /// </summary>
    /// <param name="startTime"></param>
    /// <param name="endTime"></param>
    /// <returns></returns>
    [HttpPost]
    public IActionResult CaseOfMineralsToExcelNew(DateTime startTime, DateTime endTime,string tubanlaiyuan)
    {
        var res = new Response();
        var excelRes = _app.CaseOfMineralsToExcelNew(startTime, endTime,tubanlaiyuan);
        if (excelRes.Code == 200)
        {
            return File(excelRes.Result.ToArray(),
                "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
                "汇总表.xls");
        }
        else
        {
            res.Code = excelRes.Code;
            res.Message = excelRes.Message;
        }
        return Ok(res);
    }
    #endregion

    /// <summary>
    /// 案件详情
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    [HttpGet]
    public async Task<Response<AddOrUpdateDroneCaseInfoReqExtCurrent>> GetCaseInfo(string id)
    {
        var response = new Response<AddOrUpdateDroneCaseInfoReqExtCurrent>();
        try
        {
            return await _app.GetCaseInfo(id);
        }
        catch (Exception ex)
        {
            response.Code = 500;
            response.Message = ex.InnerException?.Message ?? ex.Message;
        }

        return response;
    }
   
}