using BLL;
using BLL.API.HJGL;
using SgManager.AI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Policy;
using System.Web;
using System.Web.Mvc;

namespace WebAPI.Controllers
{
    /// <summary>
    /// 首页
    /// </summary>
    public class HomeController : Controller
    {
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        //public ActionResult Index()
        //{
        //    //APIIDCardInfoService.ReadIDCardInfo("https://tccsg.cntcc.cn:17001/sggl/FileUpLoad/IdCardAttachUrl/2023-04/newfile/556bded6-ce4e-4e86-b177-19602e8bbd86.png");
        //    //var welder = APIWelderService.GetWelderByIdCard("370322198609181310", "b54d4274-0bb6-4e04-b03a-9165b2a062fb");
        //    //if (welder != null)
        //    //{
        //    //    var installtion1 = APIBaseInfoService.GetInstallationList("b54d4274-0bb6-4e04-b03a-9165b2a062fb", welder.WED_Unit);
        //    //    var method = APIWelderService.GetWelderMethod(welder.WED_ID);
        //    //    var steel = APIWelderService.GetWelderBSSteel(welder.WED_ID);
        //    //    var consumables = APIWelderService.GetConsumables();

        //    //}

        //    //APICommonService.getaccess_token();

        //    //string url = "108.608963,21.724714|108.611963,21.715027|108.619114,21.70962|108.629911,21.710544|108.628186,21.714657|108.624827,21.719073|108.62339,21.723052|108.621701,21.725721|108.615359,21.726527";

        //    //string location = "108.61684,21.71513";
        //    //string[] area = url.Split('|');
        //    //Gpslocation myLocation = new Gpslocation();
        //    //string[] myp = location.Split(',');
        //    //myLocation.lat = float.Parse(myp[0]);
        //    //myLocation.lng = float.Parse(myp[1]);
        //    //List<Gpslocation> gpsLoactions = new List<Gpslocation>();
        //    //foreach (var po in area)
        //    //{
        //    //    Gpslocation gp = new Gpslocation();
        //    //    string[] p = po.Split(',');
        //    //    gp.lat = float.Parse(p[0]);
        //    //    gp.lng = float.Parse(p[1]);
        //    //    gpsLoactions.Add(gp);

        //    //}
        //    //GpsPolygonHelper.isPointInPolygon(myLocation, gpsLoactions);
        //    //string location = "108.61684,21.71513";
        //    //using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
        //    //{
        //    //    var person = db.SitePerson_Person.Where(u => u.IdentityCard == "342401199502012298" && u.ProjectId == "59fe12ee-a986-4a60-b288-2c33a241dc28").FirstOrDefault();
        //    //    if (person != null)
        //    //    {
        //    //        string inOrOutS = "进门";


        //    //        Model.t_d_facerecordItem newFacerecordItem = new Model.t_d_facerecordItem()
        //    //        {
        //    //            ProjectId = person.ProjectId,
        //    //            ID = 0,
        //    //            EmployName = person.PersonName,
        //    //            DepartmentID = person.TeamGroupId,
        //    //            DepartName = TeamGroupService.GetTeamGroupNameByTeamGroupId(person.TeamGroupId),
        //    //            EmployNO = person.IdentityCard,
        //    //            RoleID = "微信端",
        //    //            DateTimeRecord = DateTime.Now,
        //    //            RecordDes = "微信端:",
        //    //            InOrOut = inOrOutS,
        //    //            Des1 = "",
        //    //            Des2 = "",
        //    //        };
        //    //        var getfacerecord = db.T_d_facerecord.Where(x => x.ProjectId == person.ProjectId);
        //    //        if (getfacerecord.Count() > 0)
        //    //        {
        //    //            newFacerecordItem.ID = getfacerecord.Max(x => x.ID) + 1;
        //    //        }
        //    //        var area = db.WxProjectGpsPoint.Where(u => u.ProjectId == person.ProjectId).OrderBy(x=>x.Orders).ToList();
        //    //        if (area != null && area.Count > 0)
        //    //        {
        //    //            //  string points = area.Point;
        //    //            //if (!string.IsNullOrEmpty(points))
        //    //            //{
        //    //            //    string[] ps = points.Split('|');
        //    //            Gpslocation myLocation = new Gpslocation();
        //    //            string[] myp = location.Split(',');
        //    //            myLocation.lat = double.Parse(myp[1]);
        //    //            myLocation.lng = double.Parse(myp[0]);
        //    //            List<Gpslocation> gpsLoactions = new List<Gpslocation>();
        //    //            foreach (var po in area)
        //    //            {
        //    //                Gpslocation gp = new Gpslocation();
        //    //                string[] p = po.Point.Split(',');
        //    //                gp.lat = double.Parse(p[1])   ;
        //    //                gp.lng = double.Parse(p[0]);
        //    //                gpsLoactions.Add(gp);

        //    //            }
        //    //            //不规则图像x坐标集合
        //    //            List<double> xList = gpsLoactions.Select(x => x.lat).ToList();
        //    //            //不规则图像y坐标集合
        //    //            List<double> yList = gpsLoactions.Select(x => x.lng).ToList();
        //    //            GpsPolygonHelper. PositionPnpoly(gpsLoactions.Count, xList,yList, myLocation.lat, myLocation.lng);

        //    //            if (GpsPolygonHelper.isPointInPolygon(myLocation, gpsLoactions))
        //    //            {
        //    //                newFacerecordItem.RecordDes += "打卡成功";
        //    //                //APIPersonService.getPersonInOut(person.ProjectId, person.IdentityCard, isIn, DateTime.Now);

        //    //            }
        //    //            else
        //    //            {
        //    //                newFacerecordItem.RecordDes += "识别成功,不在项目区域内打卡";
        //    //                //responeData.code = 0;
        //    //            }
        //    //        }
        //    //    }
        //    //}
        //    //        //List<SgManager.AI.faceResult> kqFace = null;
        //    //try
        //    //{
        //    //    kqFace = (List<SgManager.AI.faceResult>)SgManager.AI.FaceClass.SearchFileFace("d://6.jpg");

        //    //}
        //    //catch (Exception e)
        //    //{

        //    //}
        //    //APICommonService.SendSubscribeMessage("C4A62EC0-E5D3-4EBF-A5FA-E56AA89633C0", "人员信息待您审核", "123", string.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now));

        //    ViewBag.Title = "Home Page";
        //    //   var db = Funs.DB;
        //    //var   getInfoList = (from x in db.License_LicenseManager
        //    //                  where  (x.WorkStates == "1" || x.WorkStates == "0")
        //    //                  orderby x.StartDate
        //    //                  select new Model.LicenseDataItem
        //    //                  {
        //    //                      LicenseId = x.LicenseManagerId,
        //    //                      MenuId = Const.ProjectLicenseManagerMenuId,
        //    //                      MenuName = db.Base_LicenseType.FirstOrDefault(y => y.LicenseTypeId == x.LicenseTypeId).LicenseTypeName,
        //    //                      LicenseTypeId = x.LicenseTypeId,
        //    //                      ProjectId = x.ProjectId,
        //    //                      LicenseCode = x.LicenseManagerCode,
        //    //                      ApplyUnitId = x.UnitId,
        //    //                      ApplyUnitName = db.Base_Unit.First(u => u.UnitId == x.UnitId).UnitName,
        //    //                      ApplyManId = x.CompileMan,
        //    //                      ApplyManName = x.ApplicantMan,
        //    //                      ApplyDate = string.Format("{0:yyyy-MM-dd HH:mm}", x.CompileDate),
        //    //                      WorkPalce = UnitWorkService.GetUnitWorkName(x.WorkAreaId),
        //    //                      ValidityStartTime = string.Format("{0:yyyy-MM-dd HH:mm}", x.StartDate),
        //    //                      ValidityEndTime = string.Format("{0:yyyy-MM-dd HH:mm}", x.EndDate),
        //    //                      States = x.WorkStates,

        //    //                      AttachUrl = APIUpLoadFileService.getFileUrl(x.LicenseManagerId, null),
        //    //                  }).ToList();
        //    return View();
        //}




        public ActionResult ZhuCeBaidu()
        {
            using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
            {
                var projectids = db.Base_Project.Where(p => p.IsFace == true).Select(p => p.ProjectId).ToList();
                var SitePersonList = db.SitePerson_Person.Where(p => projectids.Contains(p.ProjectId) && p.PhotoUrl != null).ToList();
                foreach (var getNewPerson in SitePersonList)
                {
                    if (!string.IsNullOrEmpty(getNewPerson.PhotoUrl))
                    {
                       
                     APIPersonService.PersonFace(getNewPerson);
                    }
                }

                //ViewBag.res = res;
            }
            return View("Index");
        }
    }
}