WorkAttendanceController.cs 2.27 KB
using Hh.Mes.Common.Request;
using Hh.Mes.POJO.Entity;
using Hh.Mes.POJO.Response;
using Hh.Mes.Service;
using Hh.Mes.Service.SystemAuth;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;


namespace WebMvc.Controllers
{
    public class WorkAttendanceController : BaseController
    {
        private readonly AttendanceService service;
        private IHttpContextAccessor _accessor;

        public WorkAttendanceController(IAuth authUtil, AttendanceService attendanceService, IHttpContextAccessor accessort) : base(authUtil)
        {
            service = attendanceService;
            service.sysWebUser = authUtil.GetCurrentUser().User;
            this._accessor = accessort;
            service.ObjValue = _accessor.HttpContext.Connection.RemoteIpAddress.ToString();
        }
        public ActionResult Index()
        {
            return View();
        }

        #region 获取数据
        /// <summary>
        /// 加载及分页查询
        /// </summary>
        /// <param name="pageRequest">表单请求信息</param>
        /// <param name="entity">请求条件实例</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<string> Load(PageReq pageRequest, sys_punch_clock entity)
        {
            var dataResult = await service.Load(pageRequest, entity);
            var dataTable = dataResult.Tables[0];
            var retrunResult = new Response
            {
                Result = dataTable,
                Count = entity.Exel ? dataTable.Rows.Count : (int)dataResult.Tables[1].Rows[0]["rowTotal"]
            };
            return Serialize(retrunResult);
        }



        #endregion


        [HttpPost]
        public string Clock(string webcam, string idcard)
        {
            var resp = new Response();
            //工卡登录
            if (!string.IsNullOrEmpty(idcard))
            {
                resp = service.IdCardClockService(idcard);
            }
            else if (!string.IsNullOrEmpty(webcam))
            {
                resp = service.FaceClockService(webcam);
            }
            else
            {
                resp.Code = 500;
                resp.Message = "请选择考勤方式";
            }
            return Serialize(resp);
        }
    }
}