Commit b5040071 authored by liudong1993's avatar liudong1993

app 考勤打卡

parent 176f2807
......@@ -40,5 +40,9 @@
/// 表单重复提交
/// </summary>
FormRepeatSubmit = 10003,
/// <summary>
/// 不在打卡范围
/// </summary>
NotInCardRange = 20001,
}
}
using Edu.Common.Plugin;
namespace Edu.Common.Enum.User
{
/// <summary>
/// 特殊日期打卡类型
/// </summary>
public enum TechnicalTypeEnum
{
/// <summary>
/// 打卡
/// </summary>
PunchCard = 1,
/// <summary>
/// 不打卡
/// </summary>
NoPunchCard = 2
}
}
\ No newline at end of file
using System;
namespace Edu.Common.Plugin
{
/// <summary>
/// 地图帮助类
/// </summary>
public class MapHelper
{
//地球半径,单位米
private const double EARTH_RADIUS = 6378137;
/// <summary>
/// 计算两点位置的距离,返回两点的距离,单位 米
/// </summary>
/// <param name="lat1">第一点纬度</param>
/// <param name="lng1">第一点经度</param>
/// <param name="lat2">第二点纬度</param>
/// <param name="lng2">第二点经度</param>
/// <returns></returns>
public static double GetDistance(double lat1, double lng1, double lat2, double lng2)
{
double radLat1 = Rad(lat1);
double radLng1 = Rad(lng1);
double radLat2 = Rad(lat2);
double radLng2 = Rad(lng2);
double a = radLat1 - radLat2;
double b = radLng1 - radLng2;
double result = 2 * Math.Asin(Math.Sqrt(Math.Pow(Math.Sin(a / 2), 2) + Math.Cos(radLat1) * Math.Cos(radLat2) * Math.Pow(Math.Sin(b / 2), 2))) * EARTH_RADIUS;
return result;
}
/// <summary>
/// 计算两个坐标点之间的距离
/// 计算两点位置的距离,返回两点的距离,单位 米
/// </summary>
/// <param name="firstPoint">第一个坐标点的(纬度,经度)</param>
/// <param name="secondPoint">第二个坐标点的(纬度,经度)</param>
/// <returns>返回两点之间的距离,单位:公里/千米</returns>
public static double GetPointDistance(string firstPoint, string secondPoint)
{
var firstArray = firstPoint.Split(',');
var secondArray = secondPoint.Split(',');
var firstLatitude = Convert.ToDouble(firstArray[0].Trim());
var firstLongitude = Convert.ToDouble(firstArray[1].Trim());
var secondLatitude = Convert.ToDouble(secondArray[0].Trim());
var secondLongitude = Convert.ToDouble(secondArray[1].Trim());
return GetDistance(firstLatitude, firstLongitude, secondLatitude, secondLongitude);
}
/// <summary>
/// 经纬度转化成弧度
/// </summary>
/// <param name="d"></param>
/// <returns></returns>
private static double Rad(double d)
{
return (double)d * Math.PI / 180d;
}
}
}
This diff is collapsed.
......@@ -29,17 +29,21 @@ namespace Edu.WebApi.Controllers.User
/// <summary>
/// 助教处理类对象
/// </summary>
private readonly NoticeModule noticeModule = AOPHelper.CreateAOPObject<NoticeModule>();
private readonly NoticeModule noticeModule = new NoticeModule();
/// <summary>
/// 考勤处理类
/// </summary>
private readonly AttendanceModule attendancemodule = new AttendanceModule();
/// <summary>
/// 审核处理
/// </summary>
private readonly WorkFlowModule workFlowModule = new WorkFlowModule();
/// <summary>
/// 考勤记录处理类
/// </summary>
public AttendanceRecodModule attendRecodeModule = new AttendanceRecodModule();
#region 公告管理
......@@ -1799,5 +1803,181 @@ namespace Edu.WebApi.Controllers.User
}
#endregion
#region APP考勤
/// <summary>
/// App获取今天打卡信息
/// </summary>
/// <returns></returns>
public ApiResult GetAttendRecod()
{
JObject parm = JObject.Parse(RequestParm.Msg.ToString());
UserInfo userInfo = UserReidsCache.GetUserLoginInfo(RequestParm.Uid);
string date = JsonHelper.GetStringValue(parm, "date");
if (string.IsNullOrWhiteSpace(date))
{
return ApiResult.ParamIsNull("日期时间为空");
}
JObject result = new JObject();
JObject recodeInfo = attendRecodeModule.GetAttendRecod(userInfo.Id, userInfo.DeptId, date);
if (recodeInfo == null)
{
result["isNeedCard"] = false;
result["recodeInfo"] = recodeInfo;
}
else
{
result["isNeedCard"] = true;
result["recodeInfo"] = recodeInfo;
}
return ApiResult.Success("获取成功", data: result);
}
/// <summary>
/// App验证是否在打卡范围
/// </summary>
/// <returns></returns>
public ApiResult VerifyPunchCard()
{
JObject parm = JObject.Parse(RequestParm.Msg.ToString());
string latAndLong = JsonHelper.GetStringValue(parm, "latAndLong");
string wifiMac = JsonHelper.GetStringValue(parm, "wifiMac");
string oldWifiMac = JsonHelper.GetStringValue(parm, "wifiMac");
string version = JsonHelper.GetStringValue(parm, "version");
if (string.IsNullOrWhiteSpace(latAndLong) && string.IsNullOrWhiteSpace(wifiMac))
{
return ApiResult.ParamIsNull("参数为空");
}
int empId = Convert.ToInt32(RequestParm.Uid);
List<RB_Attendance_Way_Extend> wayList = new List<RB_Attendance_Way_Extend>();
wifiMac = GetMdifyWifiMac(wifiMac);
bool isNotVerifyVifi = JudgeNotVerifyVifi(version, empId);
bool isRang = isNotVerifyVifi ? isNotVerifyVifi : attendRecodeModule.VerifyPunchCard(empId, latAndLong, wifiMac, oldWifiMac, out wayList);
var attendWay = wayList.Select(t => new { type = t.Type, name = t.Name, address = t.Address, targetAddress = t.TargetAddress, scope = t.Scope });
var result = new { isLegal = isRang, attendWay };
return ApiResult.Success("获取成功", data: result);
}
/// <summary>
/// App考勤打卡
/// </summary>
/// <returns></returns>
public ApiResult PunchCard()
{
JObject parm = JObject.Parse(RequestParm.Msg.ToString());
string latAndLong = JsonHelper.GetStringValue(parm, "latAndLong");
string address = JsonHelper.GetStringValue(parm, "address");
string wifiMac = JsonHelper.GetStringValue(parm, "wifiMac");
string oldWifiMac = wifiMac;
string phoneId = JsonHelper.GetStringValue(parm, "phoneId");
string PhoneName = JsonHelper.GetStringValue(parm, "PhoneName");
string version = JsonHelper.GetStringValue(parm, "version");
if (string.IsNullOrWhiteSpace(latAndLong) && string.IsNullOrWhiteSpace(wifiMac))
{
return ApiResult.ParamIsNull("参数为空");
}
if (string.IsNullOrWhiteSpace(phoneId))
{
return ApiResult.ParamIsNull("手机标识码为空");
}
UserInfo userInfo = UserReidsCache.GetUserLoginInfo(RequestParm.Uid);
string date = JsonHelper.GetStringValue(parm, "date");
wifiMac = GetMdifyWifiMac(wifiMac);
LogHelper.WriteInfo($"打卡信息:{JsonConvert.SerializeObject(RequestParm)}-->更新后的mac:{wifiMac}");
int PunchCardType;
bool isNotVerifyVifi = JudgeNotVerifyVifi(version, userInfo.Id);
string result = attendRecodeModule.PunchCard(userInfo.Id, userInfo.DeptId, latAndLong, wifiMac, oldWifiMac, phoneId, address, PhoneName, out PunchCardType, isNotVerifyVifi);
var resultData = new { punchCardType = PunchCardType };
if (result.Equals("ok"))
{
return ApiResult.Success("打卡成功", data: resultData);
}
else if (result.Equals("不在打卡范围"))
{
return new ApiResult() { Code = (int)ResultCode.NotInCardRange, Message = result };
}
else
{
return ApiResult.Failed(message: result);
}
}
/// <summary>
/// 不打卡wifi版本
/// </summary>
/// <param name="version"></param>
/// <param name="EmpId"></param>
/// <returns></returns>
private bool JudgeNotVerifyVifi(string version, int EmpId)
{
bool isNotVerifyVifi = false;
if (!string.IsNullOrWhiteSpace(version))
{
string[] versionInfo = version.Split('&');
if (versionInfo.Length == 3 && versionInfo[1].ToLower().Equals("ios") && versionInfo[2].Equals("1.1.8"))
{
isNotVerifyVifi = true;
}
}
return isNotVerifyVifi;
}
/// <summary>
/// 获取修改后wifimac
/// </summary>
/// <param name="wifiMac">原始</param>
/// <returns></returns>
private string GetMdifyWifiMac(string wifiMac)
{
if (!string.IsNullOrWhiteSpace(wifiMac))
{
string[] mac = wifiMac.Split(':');
for (int i = 0; i < mac.Length; i++)
{
if (mac[i].Length == 1)
{
mac[i] = $"0{mac[i]}";
}
}
wifiMac = string.Join(":", mac).ToLower();
}
return wifiMac;
}
/// <summary>
/// App考勤打卡统计
/// </summary>
/// <returns></returns>
public ApiResult PunchCardStatistical()
{
JObject parm = JObject.Parse(RequestParm.Msg.ToString());
string date = JsonHelper.GetStringValue(parm, "date");
if (string.IsNullOrWhiteSpace(date))
{
return ApiResult.ParamIsNull("日期为空");
}
int empId = Convert.ToInt32(RequestParm.Uid);
List<JObject> result = attendRecodeModule.PunchCardStatistical(empId, date);
return ApiResult.Success("获取成功", data: result);
}
/// <summary>
/// App考勤打卡月历
/// </summary>
/// <returns></returns>
public ApiResult PunchCardCalendar()
{
JObject parm = JObject.Parse(RequestParm.Msg.ToString());
string date = JsonHelper.GetStringValue(parm, "date");
if (string.IsNullOrWhiteSpace(date))
{
return ApiResult.ParamIsNull("日期为空");
}
int empId = Convert.ToInt32(RequestParm.Uid);
List<JObject> result = attendRecodeModule.PunchCardCalendar(empId, date);
return ApiResult.Success("获取成功", data: result);
}
#endregion
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment