using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using MadRunFabric.Common;
using ConfigurationApi.IRepositories;
using Microsoft.Extensions.Logging;
using MadRunFabric.Model;
using MongoDB.Driver;
using ConfigurationApi.Models.Dto;
using Microsoft.AspNetCore.Authorization;

namespace ConfigurationApi.Controllers
{
    /// <summary>
    /// 省市县/省市项目[医院]
    /// </summary>
    //[Authorize]
    [ApiVersion("6.0")]
    [Produces("application/json")]
    [Route("api/[controller]")]
    public class ProvincesAddressController : BaseController
    {
        private readonly ILogger<ProvincesAddressController> _logger;
        private readonly ISys_ProvincesRepository _sys_provincesrepository;
        private readonly ISys_CityRepository _sys_cityrepository;
        private readonly ISys_CountyRepository _sys_countyrepository;
        private readonly IPro_Project_InfoRepository _pro_project_inforepository;

        public ProvincesAddressController(
            ILogger<ProvincesAddressController> logger,
            ISys_ProvincesRepository sys_provincesrepository,
            ISys_CityRepository sys_cityrepository,
            ISys_CountyRepository sys_countyrepository,
            IPro_Project_InfoRepository pro_project_inforepository
            )
        {
            _logger = logger;
            _sys_provincesrepository = sys_provincesrepository;
            _sys_cityrepository = sys_cityrepository;
            _sys_countyrepository = sys_countyrepository;
            _pro_project_inforepository = pro_project_inforepository;
        }

        #region 省(添加修改删除)
        /// <summary>
        /// 获取省列表 by page
        /// </summary>
        /// <param name="keyword"></param>
        /// <param name="stime"></param>
        /// <param name="etime"></param>
        /// <param name="pageindex"></param>
        /// <param name="pagesize"></param>
        /// <returns></returns>
        [HttpGet("getprovinceslistbypage")]
        public async Task<IActionResult> GetProvincesListsByPageAsync(string keyword, int pageindex = 1, int pagesize = 10)
        {
            #region 条件信息
            ////排序字段
            var sort = Builders<Sys_Provinces>.Sort.Descending("provincecode");
            var list = await _sys_provincesrepository.GetByPage(null, pageindex, pagesize, sort);
            var redCount = await _sys_provincesrepository.CountAsync(null); //获取总数
            //根据条件查询集合
            var listfilter = new List<FilterDefinition<Sys_Provinces>>();
            //模糊查询
            if (!string.IsNullOrEmpty(keyword))
                listfilter.Add(Builders<Sys_Provinces>.Filter.Where(s => s.provincename.Contains(keyword)));
            #endregion
            int recordCount = 0;
            if (listfilter.Count > 0)
            {
                var filter = Builders<Sys_Provinces>.Filter.And(listfilter);
                list = await _sys_provincesrepository.GetByPage(filter, pageindex, pagesize, sort);
                redCount = await _sys_provincesrepository.CountAsync(filter);   //获取总数
            }
            recordCount = int.Parse(redCount.ToString());

            var obj = new
            {
                state = "success",
                message = "成功",
                rows = list,
                total = recordCount,
            };
            return Content(obj.ToJson());
        }

        /// <summary>
        /// 获取省详情 by id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet("getprovincesdetailes")]
        public async Task<IActionResult> GetProvincesDetailsAsync(string id)
        {
            if (string.IsNullOrEmpty(id))
                return Error("参数错误");
            var model = await _sys_provincesrepository.GetSingle(id);
            if (model != null)
            {
                var result = new
                {
                    id = model.id,
                    provincecode = model.provincecode,
                    provincename = model.provincename,
                };
                return Success("获取成功！", result);
            }
            return Error("获取失败");
        }

        /// <summary>
        /// 添加省
        /// </summary>
        /// <param name="provincecode"></param>
        /// <param name="provincename"></param>
        /// <returns></returns>
        [HttpPost("addprovinces")]
        public async Task<IActionResult> AddProvincesAsync(string provincecode,string provincename)
        {
            if (string.IsNullOrEmpty(provincecode))
                return Error("项目名称不能为空");
            if (string.IsNullOrEmpty(provincename))
                return Error("科室名称不能为空");
            var model = new Sys_Provinces();
            model.provincecode = provincecode;
            model.provincename = provincename;
            #region 添加信息
            //model.provincecode = ordercode;
            //model.provincename = 2;
            #endregion
            bool b = await _sys_provincesrepository.Add(model);
            if (b)
                return Success("添加成功");
            return Error("添加失败");
        }

        /// <summary>
        /// 修改省信息
        /// </summary>
        /// <param name="id"></param>
        /// <param name="provincecode"></param>
        /// <param name="provincename"></param>
        /// <returns></returns>
        [HttpPost("updateprovinces")]
        public async Task<IActionResult> UpdateProvincesAsync(string id, string provincecode, string provincename)
        {
            if (string.IsNullOrEmpty(id))
                return Error("项目名称不能为空");
            if (string.IsNullOrEmpty(provincecode))
                return Error("项目名称不能为空");
            if (string.IsNullOrEmpty(provincename))
                return Error("项目名称不能为空");

            var model = new Sys_Provinces();
            model = await _sys_provincesrepository.GetSingle(id);
            if (model == null)
                return Error("操作失败");
            model.provincecode = provincecode;
            model.provincename = provincename;
            bool b = await _sys_provincesrepository.Update(model);
            if (b)
                return Success("保存成功");
            return Error("保存失败");
        }

        /// <summary>
        /// 删除省信息 by ids
        /// </summary>
        /// <param name="ids">string[] id</param>
        /// <returns></returns>
        [HttpPost("deleteprovinces")]
        public async Task<IActionResult> DeleteProvincesAsync(string[] ids)
        {
            int num = 0;
            if (ids == null && ids.Length <= 0)
                return Error("请选择要删除的记录");
            foreach (var item in ids)
            {
                if (await _sys_provincesrepository.Remove(item))
                    num += 1;
            }
            if (num == ids.Length)
                return Success("删除成功");
            if (num > 0 && num < ids.Length)
                return Error("部分删除失败，请查看后重新操作");
            return Error("删除失败，请查看后重新操作");
        }
        #endregion

        #region 市(添加修改删除)
        /// <summary>
        /// 获取省列表 by page
        /// </summary>
        /// <param name="keyword"></param>
        /// <param name="stime"></param>
        /// <param name="etime"></param>
        /// <param name="pageindex"></param>
        /// <param name="pagesize"></param>
        /// <returns></returns>
        [HttpGet("getcitylistbypage")]
        public async Task<IActionResult> GetCityListsByPageAsync(string keyword, string provincecode, int pageindex = 1, int pagesize = 10)
        {
            #region 条件信息
            ////排序字段
            var sort = Builders<Sys_City>.Sort.Descending("citycode");
            var list = await _sys_cityrepository.GetByPage(null, pageindex, pagesize, sort);
            var redCount = await _sys_cityrepository.CountAsync(null); //获取总数
            //根据条件查询集合
            var listfilter = new List<FilterDefinition<Sys_City>>();
            //查询
            if (!string.IsNullOrEmpty(provincecode))
                listfilter.Add(Builders<Sys_City>.Filter.Where(s => s.provincecode.Equals(provincecode)));
            if (!string.IsNullOrEmpty(keyword))
                listfilter.Add(Builders<Sys_City>.Filter.Where(s => s.cityname.Contains(keyword)));
            #endregion
            int recordCount = 0;
            if (listfilter.Count > 0)
            {
                var filter = Builders<Sys_City>.Filter.And(listfilter);
                list = await _sys_cityrepository.GetByPage(filter, pageindex, pagesize, sort);
                redCount = await _sys_cityrepository.CountAsync(filter);   //获取总数
            }
            recordCount = int.Parse(redCount.ToString());

            var obj = new
            {
                state = "success",
                message = "成功",
                rows = list,
                total = recordCount,
            };
            return Content(obj.ToJson());
        }

        /// <summary>
        /// 获取省详情 by id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet("getcitydetailes")]
        public async Task<IActionResult> GetCityDetailsAsync(string id)
        {
            if (string.IsNullOrEmpty(id))
                return Error("参数错误");
            var model = await _sys_cityrepository.GetSingle(id);
            if (model != null)
            {
                var result = new
                {
                    id = model.id,
                    citycode = model.citycode,
                    cityname = model.cityname,
                    provincecode = model.provincecode,
                };
                return Success("获取成功！", result);
            }
            return Error("获取失败");
        }

        /// <summary>
        /// 添加省
        /// </summary>
        /// <param name="provincecode"></param>
        /// <param name="provincename"></param>
        /// <returns></returns>
        [HttpPost("addcity")]
        public async Task<IActionResult> AddCityAsync(string citycode, string cityname, string provincecode)
        {
            if (string.IsNullOrEmpty(citycode))
                return Error("项目名称不能为空");
            if (string.IsNullOrEmpty(cityname))
                return Error("科室名称不能为空");
            if (string.IsNullOrEmpty(provincecode))
                return Error("科室名称不能为空");
            var model = new Sys_City();
            model.citycode = citycode;
            model.cityname = cityname;
            model.provincecode = provincecode;
            #region 添加信息
            //model.provincecode = ordercode;
            //model.provincename = 2;
            #endregion
            bool b = await _sys_cityrepository.Add(model);
            if (b)
                return Success("添加成功");
            return Error("添加失败");
        }

        /// <summary>
        /// 修改省信息
        /// </summary>
        /// <param name="id"></param>
        /// <param name="provincecode"></param>
        /// <param name="provincename"></param>
        /// <returns></returns>
        [HttpPost("updatecity")]
        public async Task<IActionResult> UpdateCityAsync(string id, string citycode, string cityname, string provincecode)
        {
            if (string.IsNullOrEmpty(id))
                return Error("项目名称不能为空");
            if (string.IsNullOrEmpty(citycode))
                return Error("项目名称不能为空");
            if (string.IsNullOrEmpty(cityname))
                return Error("项目名称不能为空");
            if (string.IsNullOrEmpty(provincecode))
                return Error("项目名称不能为空");

            var model = new Sys_City();
            model = await _sys_cityrepository.GetSingle(id);
            if (model == null)
                return Error("操作失败");
            model.citycode = citycode;
            model.cityname = cityname;
            model.provincecode = provincecode;
            bool b = await _sys_cityrepository.Update(model);
            if (b)
                return Success("保存成功");
            return Error("保存失败");
        }

        /// <summary>
        /// 删除省信息 by ids
        /// </summary>
        /// <param name="ids">string[] id</param>
        /// <returns></returns>
        [HttpPost("deletecity")]
        public async Task<IActionResult> DeleteCityAsync(string[] ids)
        {
            int num = 0;
            if (ids == null && ids.Length <= 0)
                return Error("请选择要删除的记录");
            foreach (var item in ids)
            {
                if (await _sys_cityrepository.Remove(item))
                    num += 1;
            }
            if (num == ids.Length)
                return Success("删除成功");
            if (num > 0 && num < ids.Length)
                return Error("部分删除失败，请查看后重新操作");
            return Error("删除失败，请查看后重新操作");
        }

        #endregion

        #region 县/地区(添加修改删除)
        /// <summary>
        /// 获取省列表 by page
        /// </summary>
        /// <param name="keyword"></param>
        /// <param name="stime"></param>
        /// <param name="etime"></param>
        /// <param name="pageindex"></param>
        /// <param name="pagesize"></param>
        /// <returns></returns>
        [HttpGet("getlistbypage")]
        public async Task<IActionResult> GetCountyListsByPageAsync(string keyword, int pageindex = 1, int pagesize = 10)
        {
            #region 条件信息
            ////排序字段
            var sort = Builders<Sys_County>.Sort.Descending("Countycode");
            var list = await _sys_countyrepository.GetByPage(null, pageindex, pagesize, sort);
            var redCount = await _sys_countyrepository.CountAsync(null); //获取总数
            //根据条件查询集合
            var listfilter = new List<FilterDefinition<Sys_County>>();
            //模糊查询
            if (!string.IsNullOrEmpty(keyword))
                listfilter.Add(Builders<Sys_County>.Filter.Where(s => s.countyname.Contains(keyword)));
            #endregion
            int recordCount = 0;
            if (listfilter.Count > 0)
            {
                var filter = Builders<Sys_County>.Filter.And(listfilter);
                list = await _sys_countyrepository.GetByPage(filter, pageindex, pagesize, sort);
                redCount = await _sys_countyrepository.CountAsync(filter);   //获取总数
            }
            recordCount = int.Parse(redCount.ToString());

            var obj = new
            {
                state = "success",
                message = "成功",
                rows = list,
                total = recordCount,
            };
            return Content(obj.ToJson());
        }

        /// <summary>
        /// 获取省详情 by id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet("getcountydetailes")]
        public async Task<IActionResult> GetCountyDetailsAsync(string id)
        {
            if (string.IsNullOrEmpty(id))
                return Error("参数错误");
            var model = await _sys_countyrepository.GetSingle(id);
            if (model != null)
            {
                var result = new
                {
                    id = model.id,
                    countycode = model.countycode,
                    countyname = model.countyname,
                    citycode = model.citycode,
            };
                return Success("获取成功！", result);
            }
            return Error("获取失败");
        }

        /// <summary>
        /// 添加省
        /// </summary>
        /// <param name="provincecode"></param>
        /// <param name="provincename"></param>
        /// <returns></returns>
        [HttpPost("addcounty")]
        public async Task<IActionResult> AddCountyAsync(string countycode, string countyname, string citycode)
        {
            if (string.IsNullOrEmpty(countycode))
                return Error("项目名称不能为空");
            if (string.IsNullOrEmpty(countyname))
                return Error("科室名称不能为空");
            if (string.IsNullOrEmpty(citycode))
                return Error("科室名称不能为空");
            var model = new Sys_County();
            model.countycode = countycode;
            model.countyname = countyname;
            model.citycode = citycode;
            #region 添加信息
            //model.provincecode = ordercode;
            //model.provincename = 2;
            #endregion
            bool b = await _sys_countyrepository.Add(model);
            if (b)
                return Success("添加成功");
            return Error("添加失败");
        }

        /// <summary>
        /// 修改省信息
        /// </summary>
        /// <param name="id"></param>
        /// <param name="provincecode"></param>
        /// <param name="provincename"></param>
        /// <returns></returns>
        [HttpPost("updatecounty")]
        public async Task<IActionResult> UpdateCountyAsync(string id, string countycode, string countyname, string citycode)
        {
            if (string.IsNullOrEmpty(id))
                return Error("项目名称不能为空");
            if (string.IsNullOrEmpty(countycode))
                return Error("项目名称不能为空");
            if (string.IsNullOrEmpty(countyname))
                return Error("项目名称不能为空");
            if (string.IsNullOrEmpty(citycode))
                return Error("项目名称不能为空");

            var model = new Sys_County();
            model = await _sys_countyrepository.GetSingle(id);
            if (model == null)
                return Error("操作失败");
            model.countycode = countycode;
            model.countyname = countyname;
            model.citycode = citycode;
            bool b = await _sys_countyrepository.Update(model);
            if (b)
                return Success("保存成功");
            return Error("保存失败");
        }

        /// <summary>
        /// 删除省信息 by ids
        /// </summary>
        /// <param name="ids">string[] id</param>
        /// <returns></returns>
        [HttpPost("deletecounty")]
        public async Task<IActionResult> DeleteCountyAsync(string[] ids)
        {
            int num = 0;
            if (ids == null && ids.Length <= 0)
                return Error("请选择要删除的记录");
            foreach (var item in ids)
            {
                if (await _sys_countyrepository.Remove(item))
                    num += 1;
            }
            if (num == ids.Length)
                return Success("删除成功");
            if (num > 0 && num < ids.Length)
                return Error("部分删除失败，请查看后重新操作");
            return Error("删除失败，请查看后重新操作");
        }
        #endregion

        #region 三级联动
        /// <summary>
        /// 三级联动（省市项目[医院]）
        /// </summary>
        /// <returns></returns>
        [HttpGet("getaddressandprojson")]
        public async Task<IActionResult> GetAddressAndProJson()
        {
            var listProvinces = await _sys_provincesrepository.GetAll();                //省列表
            var listCity = await _sys_cityrepository.GetAll();                          //市列表
            var listPro = await _pro_project_inforepository.Get(x => x.isdelete == 0); //项目列表

            var treeList = new List<ProvincesAddressListDto>();
            foreach (var itemProvinces in listProvinces)
            {
                //市
                var listCityByPid = listCity.Where(x => x.provincecode == itemProvinces.provincecode);
                var treeListCity = new List<ProvincesAddressListDto>();
                foreach (var itemCity in listCityByPid)
                {
                    //项目
                    var listProByPid = listPro.Where(x => x.project_city == itemCity.citycode);
                    var treeListPro = new List<ProvincesAddressListDto>();
                    foreach (var itemPro in listProByPid)
                    {
                        var treeModelPro = new ProvincesAddressListDto();
                        treeModelPro.id = itemPro.id;
                        treeModelPro.code = itemPro.id;
                        treeModelPro.name = itemPro.project_name;   //项目名称（医院）
                        treeModelPro.parentcode = itemPro.project_city;
                        treeModelPro.entityJson = null;
                        treeListPro.Add(treeModelPro);
                    }
                    var treeModelCity = new ProvincesAddressListDto();
                    treeModelCity.id = itemCity.id;
                    treeModelCity.code = itemCity.citycode;
                    treeModelCity.name = itemCity.cityname;
                    treeModelCity.parentcode = itemCity.provincecode;
                    treeModelCity.entityJson = treeListPro;
                    treeListCity.Add(treeModelCity);
                }
                //省
                var treeModel = new ProvincesAddressListDto();
                treeModel.id = itemProvinces.id;
                treeModel.code = itemProvinces.provincecode;
                treeModel.name = itemProvinces.provincename;
                treeModel.parentcode = null;
                treeModel.entityJson = treeListCity;    //市
                treeList.Add(treeModel);
            }
            return Success("成功", treeList);
        }

        /// <summary>
        /// 二级联动（省市）
        /// </summary>
        /// <returns></returns>
        [HttpGet("getaddressjson")]
        public async Task<IActionResult> GetAddressJson()
        {
            var listProvinces = await _sys_provincesrepository.GetAll();                //省列表
            var listCity = await _sys_cityrepository.GetAll();                          //市列表

            var treeList = new List<ProvincesAddressListDto>();
            foreach (var itemProvinces in listProvinces)
            {
                //市
                var listCityByPid = listCity.Where(x => x.provincecode == itemProvinces.provincecode);
                var treeListCity = new List<ProvincesAddressListDto>();
                foreach (var itemCity in listCityByPid)
                {
                    var treeModelCity = new ProvincesAddressListDto();
                    treeModelCity.id = itemCity.id;
                    treeModelCity.code = itemCity.citycode;
                    treeModelCity.name = itemCity.cityname;
                    treeModelCity.parentcode = itemCity.provincecode;
                    treeModelCity.entityJson = null;
                    treeModelCity.children = null;//2019-7-3 前端需要换这个名字使用
                    treeListCity.Add(treeModelCity);
                }
                //省
                var treeModel = new ProvincesAddressListDto();
                treeModel.id = itemProvinces.id;
                treeModel.code = itemProvinces.provincecode;
                treeModel.name = itemProvinces.provincename;
                treeModel.parentcode = null;
                treeModel.entityJson = treeListCity;    //市
                treeModel.children  = treeListCity;//2019-7-3 前端需要换这个名字使用
                treeList.Add(treeModel);
            }
            return Success("成功", treeList);
        }

        #endregion

        #region 测试导入
        /// <summary>
        /// 省
        /// </summary>
        /// <returns></returns>
        [HttpPost("importprovinces")]
        public async Task<IActionResult> ImportProvinces()
        {
            Microsoft.AspNetCore.Http.IFormFile _upfile = Request.Form.Files[0];
            if (!_upfile.ContentType.Equals("application/vnd.ms-excel") && !_upfile.ContentType.Equals("application/x-xls") && !_upfile.ContentType.Equals("application/x-xlsx") && !_upfile.ContentType.Equals("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") && !_upfile.ContentType.Equals("application/octet-stream"))
                return Error($"请正确上传Excel文件：file.ContentType={_upfile.ContentType}");
           
            //将设备数据导入数据库
            int headrow = 0;
            NPOIHelper npoi = new NPOIHelper();
            var dtExcel = npoi.ExcelToTable1(_upfile, headrow);
            if (dtExcel.Rows.Count > 0)
            {
                IList<Sys_Provinces> IEquipments = ModelConvertHelper<Sys_Provinces>.ConvertToModel(dtExcel);
                List<Sys_Provinces> equipments = ModelConvertHelper<Sys_Provinces>.ConvertIListToList(IEquipments);
                int num = equipments.Count;
                int isuccess = 0;
                foreach (var eq in equipments)
                {
                    #region 保存数据库
                    var model = new Sys_Provinces();
                    model.provincecode = eq.provincecode;
                    model.provincename = eq.provincename;
                    bool b = await _sys_provincesrepository.Add(model);
                    if (b)
                        isuccess++;

                    #endregion
                }
                if (num == isuccess)
                {
                    return Success("已导入数据");
                }
                else
                {
                    return Error("导入失败");
                }
            }
            return Success("请选择要导入的文件");
        }

        /// <summary>
        /// 市
        /// </summary>
        /// <returns></returns>
        [HttpPost("importcity")]
        public async Task<IActionResult> ImportCity()
        {
            Microsoft.AspNetCore.Http.IFormFile _upfile = Request.Form.Files[0];
            if (!_upfile.ContentType.Equals("application/vnd.ms-excel") && !_upfile.ContentType.Equals("application/x-xls") && !_upfile.ContentType.Equals("application/x-xlsx") && !_upfile.ContentType.Equals("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") && !_upfile.ContentType.Equals("application/octet-stream"))
                return Error($"请正确上传Excel文件：file.ContentType={_upfile.ContentType}");

            //将设备数据导入数据库
            int headrow = 0;
            NPOIHelper npoi = new NPOIHelper();
            var dtExcel = npoi.ExcelToTable1(_upfile, headrow);
            if (dtExcel.Rows.Count > 0)
            {
                IList<Sys_City> IEquipments = ModelConvertHelper<Sys_City>.ConvertToModel(dtExcel);
                List<Sys_City> equipments = ModelConvertHelper<Sys_City>.ConvertIListToList(IEquipments);
                int num = equipments.Count;
                int isuccess = 0;
                foreach (var eq in equipments)
                {
                    #region 保存数据库
                    var model = new Sys_City();
                    model.cityname = eq.cityname;
                    model.citycode = eq.citycode;
                    model.provincecode = eq.provincecode;
                    bool b = await _sys_cityrepository.Add(model);
                    if (b)
                        isuccess++;

                    #endregion
                }
                if (num == isuccess)
                {
                    return Success("已导入数据");
                }
                else
                {
                    return Error("导入失败");
                }
            }
            return Success("请选择要导入的文件");
        }

        /// <summary>
        /// 县
        /// </summary>
        /// <returns></returns>
        [HttpPost("importcounty")]
        public async Task<IActionResult> ImportCounty()
        {
            Microsoft.AspNetCore.Http.IFormFile _upfile = Request.Form.Files[0];
            if (!_upfile.ContentType.Equals("application/vnd.ms-excel") && !_upfile.ContentType.Equals("application/x-xls") && !_upfile.ContentType.Equals("application/x-xlsx") && !_upfile.ContentType.Equals("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") && !_upfile.ContentType.Equals("application/octet-stream"))
                return Error($"请正确上传Excel文件：file.ContentType={_upfile.ContentType}");

            //将设备数据导入数据库
            int headrow = 0;
            NPOIHelper npoi = new NPOIHelper();
            var dtExcel = npoi.ExcelToTable1(_upfile, headrow);
            if (dtExcel.Rows.Count > 0)
            {
                IList<Sys_County> IEquipments = ModelConvertHelper<Sys_County>.ConvertToModel(dtExcel);
                List<Sys_County> equipments = ModelConvertHelper<Sys_County>.ConvertIListToList(IEquipments);
                int num = equipments.Count;
                int isuccess = 0;
                foreach (var eq in equipments)
                {
                    #region 保存数据库
                    var model = new Sys_County();
                    model.countycode = eq.countycode;
                    model.countyname = eq.countyname;
                    model.citycode = eq.citycode;
                    bool b = await _sys_countyrepository.Add(model);
                    if (b)
                        isuccess++;

                    #endregion
                }
                if (num == isuccess)
                {
                    return Success("已导入数据");
                }
                else
                {
                    return Error("导入失败");
                }
            }
            return Success("请选择要导入的文件");
        }
        #endregion

    }

}