合并
This commit is contained in:
@@ -303,6 +303,7 @@
|
||||
<Compile Include="Common\UserShowColumnsService.cs" />
|
||||
<Compile Include="Common\WeatherService.cs" />
|
||||
<Compile Include="Common\WeekDayService.cs" />
|
||||
<Compile Include="Common\YunMouHelper.cs" />
|
||||
<Compile Include="CQMS\Check\CheckControlApproveService.cs" />
|
||||
<Compile Include="CQMS\Check\CheckControlService.cs" />
|
||||
<Compile Include="CQMS\Check\CheckEquipmentApproveService.cs" />
|
||||
@@ -601,6 +602,7 @@
|
||||
<Compile Include="OpenService\MonitorService.cs" />
|
||||
<Compile Include="DynamicTHeaderHepler.cs" />
|
||||
<Compile Include="OpenService\GetDataService.cs" />
|
||||
<Compile Include="OpenService\YunMouService.cs" />
|
||||
<Compile Include="Person\PersonTotalService.cs" />
|
||||
<Compile Include="Person\Person_PersonContractService.cs" />
|
||||
<Compile Include="Person\Person_PersonTrainService.cs" />
|
||||
@@ -671,6 +673,7 @@
|
||||
<Compile Include="PHTGL\OAWebSevice.cs" />
|
||||
<Compile Include="ProjectData\MainItemService.cs" />
|
||||
<Compile Include="ProjectData\ProjectData_CodeTemplateRuleService.cs" />
|
||||
<Compile Include="ProjectData\ProjectDeviceService.cs" />
|
||||
<Compile Include="ProjectData\ProjectSateService.cs" />
|
||||
<Compile Include="ProjectData\ProjectService.cs" />
|
||||
<Compile Include="ProjectData\ProjectUnitService.cs" />
|
||||
|
||||
@@ -2048,6 +2048,10 @@ namespace BLL
|
||||
/// </summary>
|
||||
public const string DayReportMenuId = "8F15D3BE-BE21-4A6F-AD5C-2BBECEE46149";
|
||||
|
||||
/// <summary>
|
||||
/// 考勤时间管理
|
||||
/// </summary>
|
||||
public const string Menu_KqglDateManger = "5B302FF3-A6E4-4305-A0C0-64CA7377777A";
|
||||
/// <summary>
|
||||
/// 人工时月报
|
||||
/// </summary>
|
||||
@@ -5162,6 +5166,11 @@ namespace BLL
|
||||
/// </summary>
|
||||
public const string SafetyProductionEvaluationMenuId = "C48087A8-4C9F-485D-B0A4-C85E112BA705";
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 项目设备
|
||||
/// </summary>
|
||||
public const string ProjectDevicesMenuId = "E4DC0A35-C585-4C4F-8F79-10F528892314";
|
||||
/// <summary>
|
||||
/// 中央企业安全生产治本攻坚三年行动工作台账
|
||||
/// </summary>
|
||||
|
||||
@@ -0,0 +1,583 @@
|
||||
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
|
||||
namespace BLL.Common
|
||||
{
|
||||
public class YunMouHelper
|
||||
{
|
||||
public static string YunMouUrl = ConfigurationManager.AppSettings["YunMouUrl"];
|
||||
public static string ClientSecret = ConfigurationManager.AppSettings["ClientSecret"];
|
||||
public static string ClientId = ConfigurationManager.AppSettings["ClientId"];
|
||||
|
||||
public static string getToken()
|
||||
{
|
||||
string data = "client_id=" + ClientId + "&client_secret=" + ClientSecret + "&grant_type=client_credentials&scope=app";
|
||||
string result = Post(YunMouUrl + "oauth/token", data, "application/x-www-form-urlencoded", "");
|
||||
var j2 = JsonConvert.DeserializeObject<dynamic>(result);
|
||||
return j2.access_token;
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 添加设备组(一个项目一个)
|
||||
/// </summary>
|
||||
/// <param name="groupName"></param>
|
||||
/// <param name="groupNo"></param>
|
||||
/// <param name="access_token"></param>
|
||||
/// <returns></returns>
|
||||
public static string addDevicesGroups(string groupName, string groupNo, string access_token)
|
||||
{
|
||||
if (groupName.Length > 64)
|
||||
{
|
||||
groupName = groupName.Substring(0, 63);
|
||||
}
|
||||
string data = "{\"groupName\":\"" + groupName + "\",\"groupNo\":\"" + groupNo + "\"}";
|
||||
string result = Post(YunMouUrl + "api/v1/open/basic/groups/create", data, "application/json;charset=UTF-8", access_token);
|
||||
|
||||
ErrLogInfo.WriteLog(result);
|
||||
|
||||
var j2 = JsonConvert.DeserializeObject<dynamic>(result);
|
||||
if (j2.code == "200")
|
||||
return j2.message;
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除设备分组
|
||||
/// </summary>
|
||||
/// <param name="groupName"></param>
|
||||
/// <param name="groupNo"></param>
|
||||
/// <param name="access_token"></param>
|
||||
/// <returns></returns>
|
||||
public static string deleteDevicesGroups(string groupNo, string access_token)
|
||||
{
|
||||
|
||||
string result = Post(YunMouUrl + "api/v1/open/basic/groups/delete?groupNo=" + groupNo, "", "application/json;charset=UTF-8", access_token);
|
||||
ErrLogInfo.WriteLog(result);
|
||||
|
||||
var j2 = JsonConvert.DeserializeObject<dynamic>(result);
|
||||
if (j2.code == "200")
|
||||
return j2.message;
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加设备
|
||||
/// </summary>
|
||||
/// <param name="deviceSerial"></param>
|
||||
/// <param name="groupNo"></param>
|
||||
/// <param name="validateCode"></param>
|
||||
/// <param name="access_token"></param>
|
||||
/// <returns></returns>
|
||||
public static string addDevices(string deviceSerial, string groupNo, string validateCode, string access_token)
|
||||
{
|
||||
string data = "{\"deviceSerial\":\"" + deviceSerial + "\",\"groupNo\":\"" + groupNo + "\",\"validateCode\":\"" + validateCode + "\"}";
|
||||
string result = Post(YunMouUrl + "api/v1/open/basic/devices/create", data, "application/json;charset=UTF-8", access_token);
|
||||
ErrLogInfo.WriteLog(result);
|
||||
|
||||
var j2 = JsonConvert.DeserializeObject<dynamic>(result);
|
||||
if (j2.code == "200")
|
||||
return j2.data.groupId;
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 修改设备名称(按设备序列号)
|
||||
/// </summary>
|
||||
/// <param name="deviceSerial"></param>
|
||||
/// <param name="deviceName"></param>
|
||||
/// <param name="access_token"></param>
|
||||
/// <returns></returns>
|
||||
public static string updateDevices(string deviceSerial, string deviceName, string access_token)
|
||||
{
|
||||
string data = "{\"deviceSerial\":\"" + deviceSerial + "\",\"deviceName\":\"" + deviceName + "\"}";
|
||||
string result = Post(YunMouUrl + "api/v1/open/basic/devices/update", data, "application/json;charset=UTF-8", access_token);
|
||||
ErrLogInfo.WriteLog(result);
|
||||
|
||||
var j2 = JsonConvert.DeserializeObject<dynamic>(result);
|
||||
if (j2.code == "200")
|
||||
return j2.message;
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 删除设备
|
||||
/// </summary>
|
||||
/// <param name="deviceSerial"></param>
|
||||
/// <param name="access_token"></param>
|
||||
/// <returns></returns>
|
||||
public static string deleteDevices(string deviceSerial, string access_token)
|
||||
{
|
||||
|
||||
string result = Post(YunMouUrl + "api/v1/open/basic/devices/delete?deviceSerial=" + deviceSerial, "", "application/json;charset=UTF-8", access_token);
|
||||
ErrLogInfo.WriteLog(result);
|
||||
var j2 = JsonConvert.DeserializeObject<dynamic>(result);
|
||||
if (j2.code == "200")
|
||||
return j2.message;
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 添加权限组,建议一个项目一个
|
||||
/// </summary>
|
||||
/// <param name="groupName"></param>
|
||||
/// <param name="access_token"></param>
|
||||
/// <returns></returns>
|
||||
public static string addPermissionGroups(string groupName, string access_token)
|
||||
{
|
||||
|
||||
char[] TrimChar = { '、', ' ', '-', '\'', '\"', '\\', '.', '、', '-', '[', ']', '【', '】', '(', ')', '#', '@', '~', '<', '>' };
|
||||
//groupname不能大于32位
|
||||
if (groupName.Length > 32)
|
||||
{
|
||||
groupName = groupName.Substring(0, 31).Trim(TrimChar);
|
||||
}
|
||||
groupName = groupName.Replace("、", "").Replace("/", "").Replace(".", "").Replace("-", "").Replace("[", "").Replace("]", "").Replace("【", "").Replace("】", "").Replace("(", "")
|
||||
.Replace(")", "").Replace("#", "").Replace("@", "").Replace("~", "").Replace("<", "").Replace(">", "")
|
||||
.Replace("(", "")
|
||||
.Replace(")", "");
|
||||
string data = "{\"groupName\":\"" + groupName + "\"}";
|
||||
string result = Post(YunMouUrl + "api/v1/open/accessControl/permissionGroups/create", data, "application/json;charset=UTF-8", access_token);
|
||||
ErrLogInfo.WriteLog(result);
|
||||
var j2 = JsonConvert.DeserializeObject<dynamic>(result);
|
||||
if (j2.code == "200")
|
||||
return j2.data.groupId;
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据权限组下发权限
|
||||
/// </summary>
|
||||
/// <param name="groupName"></param>
|
||||
/// <param name="access_token"></param>
|
||||
/// <returns></returns>
|
||||
public static string issuedByGroup(string groupId, string access_token)
|
||||
{
|
||||
string data = "{\"groupId\":\"" + groupId + "\"}";
|
||||
string result = Post(YunMouUrl + "api/v1/open/accessControl/allots/actions/issuedByGroup", data, "application/json;charset=UTF-8", access_token);
|
||||
var j2 = JsonConvert.DeserializeObject<dynamic>(result);
|
||||
if (j2.code == "200")
|
||||
return j2.code;
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 删除权限组(会同时移除权限组下人员和设备下发记录以及已下发到设备的权限)
|
||||
/// </summary>
|
||||
/// <param name="groupId"></param>
|
||||
/// <param name="access_token"></param>
|
||||
/// <returns></returns>
|
||||
public static string deletePermissionGroups(string groupId, string access_token)
|
||||
{
|
||||
string result = Post(YunMouUrl + "api/v1/open/accessControl/permissionGroups/delete?groupId=" + groupId, "", "application/json;charset=UTF-8", access_token);
|
||||
var j2 = JsonConvert.DeserializeObject<dynamic>(result);
|
||||
if (j2.code == "200")
|
||||
{
|
||||
return j2.data.groupId;
|
||||
}
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 填加员工到权限组
|
||||
/// </summary>
|
||||
/// <param name="groupId"></param>
|
||||
/// <param name="employeeNos"></param>
|
||||
/// <param name="access_token"></param>
|
||||
/// <returns></returns>
|
||||
public static string addPersonsToGroups(string groupId, string[] employeeNos, string access_token)
|
||||
{
|
||||
|
||||
//string permissions = "";
|
||||
//if (employeeNos.Length == 1)
|
||||
//{
|
||||
// permissions = "\"permissions\":[{\"employeeNo\": \"" + employeeNos[0] + "\",\"validBeginTime\": \"2020-01-11\"," +
|
||||
// "\"validEndTime\": \"2050-12-30\"}]";
|
||||
//}
|
||||
string data = "{\"groupId\":\"" + groupId + "\",\"employeeNos\":[\"" + string.Join("\", \"", employeeNos) + "\"],\"autoIssue\":\"true\"}";
|
||||
string result = Post(YunMouUrl + "api/v1/open/accessControl/permissionGroups/actions/addPersons", data, "application/json;charset=UTF-8", access_token);
|
||||
ErrLogInfo.WriteLog(result);
|
||||
var j2 = JsonConvert.DeserializeObject<dynamic>(result);
|
||||
if (j2.code == "200")
|
||||
return j2.data.statisticsId;
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 从权限组移除员工
|
||||
/// </summary>
|
||||
/// <param name="groupId"></param>
|
||||
/// <param name="employeeNos"></param>
|
||||
/// <param name="access_token"></param>
|
||||
/// <returns></returns>
|
||||
public static string deletePersonsFromGroups(string groupId, string[] employeeNos, string access_token)
|
||||
{
|
||||
string data = "{\"groupId\":\"" + groupId + "\",\"employeeNos\":[\"" + string.Join("\", \"", employeeNos) + "\"]}";
|
||||
string result = Post(YunMouUrl + "api/v1/open/accessControl/permissionGroups/actions/removePersons", data, "application/json;charset=UTF-8", access_token);
|
||||
ErrLogInfo.WriteLog(result);
|
||||
var j2 = JsonConvert.DeserializeObject<dynamic>(result);
|
||||
if (j2.code == "200")
|
||||
return j2.data.statisticsId;
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 添加设备到权限组
|
||||
/// </summary>
|
||||
/// <param name="groupId"></param>
|
||||
/// <param name="devices"></param>
|
||||
/// <param name="access_token"></param>
|
||||
/// <returns></returns>
|
||||
public static string addDevicesToGroups(string groupId, string[] devices, string access_token)
|
||||
{
|
||||
string data = "{\"groupId\":\"" + groupId + "\",\"deviceSerials\":[\"" + string.Join("\", \"", devices) + "\"],\"autoIssue\":true,\"checkCapability\":true}";
|
||||
string result = Post(YunMouUrl + "api/v1/open/accessControl/permissionGroups/actions/addDevices", data, "application/json;charset=UTF-8", access_token);
|
||||
ErrLogInfo.WriteLog(result);
|
||||
|
||||
var j2 = JsonConvert.DeserializeObject<dynamic>(result);
|
||||
if (j2.code == "200")
|
||||
return j2.code;
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 从权限组移除设备
|
||||
/// </summary>
|
||||
/// <param name="groupId"></param>
|
||||
/// <param name="devices"></param>
|
||||
/// <param name="access_token"></param>
|
||||
/// <returns></returns>
|
||||
public static string deleteDevicesFromGroups(string groupId, string[] devices, string access_token)
|
||||
{
|
||||
string data = "{\"groupId\":\"" + groupId + "\",\"deviceSerials\":[\"" + string.Join("\", \"", devices) + "\"],\"autoIssue\":true,\"checkCapability\":true}";
|
||||
string result = Post(YunMouUrl + "api/v1/open/accessControl/permissionGroups/actions/removeDevices", data, "application/json;charset=UTF-8", access_token);
|
||||
ErrLogInfo.WriteLog(result);
|
||||
|
||||
var j2 = JsonConvert.DeserializeObject<dynamic>(result);
|
||||
if (j2.code == "200")
|
||||
return j2.message;
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 添加人员
|
||||
/// </summary>
|
||||
/// <param name="employeeNo"></param>
|
||||
/// <param name="personName"></param>
|
||||
/// <param name="personPhone"></param>
|
||||
/// <param name="pic"></param>
|
||||
/// <param name="access_token"></param>
|
||||
/// <returns></returns>
|
||||
|
||||
public static string addPerson(string employeeNo, string personName, string personPhone, string pic, string access_token)
|
||||
{
|
||||
string rootUrl = ConfigurationManager.AppSettings["localRoot"];
|
||||
string filename = rootUrl + pic;
|
||||
FileInfo fi1 = new FileInfo(filename);
|
||||
if (fi1.Length > 200 * 1024)//base64编码的人脸图片,图片大小需小于200kB,数据需去除base64前缀
|
||||
{
|
||||
filename = filename.Replace(".jpg", "_new.jpg").Replace(".jpeg", "_new.jpeg");
|
||||
CropImage(fi1.FullName, filename, 200);
|
||||
}
|
||||
string faceImageBase64 = ImageToByte64String(filename, System.Drawing.Imaging.ImageFormat.Jpeg); // 图片的base64编码
|
||||
string data = "{\"employeeNo\":\"" + employeeNo + "\",\"personName\":\"" + personName + "\",\"faceImageBase64\":\"" + faceImageBase64 + "\",\"verifyImage\":true}";
|
||||
string result = Post(YunMouUrl + "api/v1/open/basic/persons/create", data, "application/json;charset=UTF-8", access_token);
|
||||
|
||||
ErrLogInfo.WriteLog(personName + result);
|
||||
|
||||
var j2 = JsonConvert.DeserializeObject<dynamic>(result);
|
||||
return j2.code;
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据employeeNo更新人员信息
|
||||
/// </summary>
|
||||
/// <param name="employeeNo"></param>
|
||||
/// <param name="personName"></param>
|
||||
/// <param name="personPhone"></param>
|
||||
/// <param name="pic"></param>
|
||||
/// <param name="access_token"></param>
|
||||
/// <returns></returns>
|
||||
public static string updatePerson(string employeeNo, string personName, string personPhone, string pic, string access_token)
|
||||
{
|
||||
string rootUrl = ConfigurationManager.AppSettings["localRoot"];
|
||||
string filename = rootUrl + pic;
|
||||
FileInfo fi1 = new FileInfo(filename);
|
||||
if (fi1.Length > 200 * 1024)//base64编码的人脸图片,图片大小需小于200kB,数据需去除base64前缀
|
||||
{
|
||||
filename = filename.Replace(".jpg", "_new.jpg").Replace(".jpeg", "_new.jpeg");
|
||||
CropImage(fi1.FullName, filename, 200);
|
||||
}
|
||||
string faceImageBase64 = ImageToByte64String(filename, System.Drawing.Imaging.ImageFormat.Jpeg); // 图片的base64编码
|
||||
string data = "{\"employeeNo\":\"" + employeeNo + "\",\"personName\":\"" + personName + "\",\"faceImageBase64\":\"" + faceImageBase64 + "\",\"verifyImage\":true}";
|
||||
string result = Post(YunMouUrl + "api/v1/open/basic/persons/update", data, "application/json;charset=UTF-8", access_token);
|
||||
var j2 = JsonConvert.DeserializeObject<dynamic>(result);
|
||||
return j2.code;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取人员
|
||||
/// </summary>
|
||||
/// <param name="employeeNo"></param>
|
||||
/// <param name="access_token"></param>
|
||||
/// <returns></returns>
|
||||
public static string getPerson(string employeeNo, string access_token)
|
||||
{
|
||||
string result = Get(YunMouUrl + "api/v1/open/basic/persons/get?employeeNo=" + employeeNo, "application/json;charset=UTF-8", access_token);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 设备布防
|
||||
/// </summary>
|
||||
/// <param name="deviceSerial"></param>
|
||||
/// <param name="isDefence"></param>
|
||||
/// <param name="access_token"></param>
|
||||
/// <returns></returns>
|
||||
public static string setDefence(string deviceSerial, string isDefence, string access_token)
|
||||
{
|
||||
string result = Post(YunMouUrl + "api/v1/ezviz/devices/actions/setDefence/deviceSerial?deviceSerial=" + deviceSerial + "&isDefence=" + isDefence, "", "application/json;charset=UTF-8", access_token);
|
||||
var j2 = JsonConvert.DeserializeObject<dynamic>(result);
|
||||
if (j2.code == "200")
|
||||
return j2.message;
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加消息通道
|
||||
/// </summary>
|
||||
/// <param name="access_token"></param>
|
||||
/// <returns></returns>
|
||||
public static string addConsumer(string access_token)
|
||||
{
|
||||
string result = Post(YunMouUrl + "api/v1/mq/consumer/group1", "", "application/json;charset=UTF-8", access_token);
|
||||
var j2 = JsonConvert.DeserializeObject<dynamic>(result);
|
||||
if (j2.code == "200")
|
||||
return j2.data.consumerId;
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 提交偏移量
|
||||
/// </summary>
|
||||
/// <param name="consumerId"></param>
|
||||
/// <param name="access_token"></param>
|
||||
/// <returns></returns>
|
||||
public static string offsets(string consumerId, string access_token)
|
||||
{
|
||||
string data = "consumerId=" + consumerId;
|
||||
string result = Post(YunMouUrl + "api/v1/mq/consumer/offsets", data, "application/x-www-form-urlencoded", access_token);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 消费消息
|
||||
/// </summary>
|
||||
/// <param name="consumerId"></param>
|
||||
/// <param name="access_token"></param>
|
||||
/// <returns></returns>
|
||||
public static string consumerMessage(string consumerId, string access_token)
|
||||
{
|
||||
string data = "consumerId=" + consumerId + "&autoCommit=true";
|
||||
string result = Post(YunMouUrl + "api/v1/mq/consumer/messages", data, "application/x-www-form-urlencoded", access_token);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// POST请求
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="data"></param>
|
||||
/// <param name="ContentType"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
public static string Post(string url, string data, string ContentType, string token)
|
||||
{
|
||||
Encoding encoding = Encoding.Default;
|
||||
|
||||
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3;//设置这个安全协议必须在创建请求之前!
|
||||
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;//创建请求对象
|
||||
request.Method = "POST";//请求方式
|
||||
request.ContentType = ContentType;//链接类型
|
||||
if (!string.IsNullOrEmpty(token))
|
||||
{
|
||||
request.Headers.Add("Authorization", "Bearer " + token);
|
||||
}
|
||||
try
|
||||
{
|
||||
byte[] buffer = Encoding.UTF8.GetBytes(data);
|
||||
//RequestStream.Write(bytes, 0, bytes.Length);
|
||||
// byte[] buffer = encoding.GetBytes(data);
|
||||
request.ContentLength = buffer.Length;
|
||||
request.GetRequestStream().Write(buffer, 0, buffer.Length);
|
||||
HttpWebResponse webresponse = request.GetResponse() as HttpWebResponse;
|
||||
using (Stream s = webresponse.GetResponseStream())
|
||||
{
|
||||
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
||||
StreamReader reader = new StreamReader(s, Encoding.UTF8);
|
||||
|
||||
string res = reader.ReadToEnd();
|
||||
ErrLogInfo.WriteLog(res);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// GET请求
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="ContentType"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
public static string Get(string url, string ContentType, string token)
|
||||
{
|
||||
Encoding encoding = Encoding.Default;
|
||||
|
||||
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3;//设置这个安全协议必须在创建请求之前!
|
||||
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;//创建请求对象
|
||||
request.Method = "GET";//请求方式
|
||||
request.ContentType = ContentType;//链接类型
|
||||
if (!string.IsNullOrEmpty(token))
|
||||
{
|
||||
request.Headers.Add("Authorization", "Bearer " + token);
|
||||
}
|
||||
try
|
||||
{
|
||||
HttpWebResponse webresponse = request.GetResponse() as HttpWebResponse;
|
||||
using (Stream s = webresponse.GetResponseStream())
|
||||
{
|
||||
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
||||
StreamReader reader = new StreamReader(s, Encoding.UTF8);
|
||||
return reader.ReadToEnd();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
public static string ImageToByte64String(string filePath, System.Drawing.Imaging.ImageFormat format)
|
||||
{
|
||||
Bitmap bitmap = new Bitmap(filePath);
|
||||
MemoryStream memoryStream = new MemoryStream();
|
||||
bitmap.Save(memoryStream, format);
|
||||
byte[] array = new byte[memoryStream.Length];
|
||||
memoryStream.Position = 0L;
|
||||
memoryStream.Read(array, 0, (int)memoryStream.Length);
|
||||
memoryStream.Close();
|
||||
return Convert.ToBase64String(array);
|
||||
}
|
||||
public static void CropImage(string inputFilePath, string outputFilePath, int maxSizeInKB)
|
||||
{
|
||||
// 加载图片
|
||||
using (Image image = Image.FromFile(inputFilePath))
|
||||
{
|
||||
// 计算最大字节大小
|
||||
int maxSizeBytes = maxSizeInKB * 1024;
|
||||
|
||||
// 如果图片大小已经小于或等于最大限制,则不裁剪直接保存
|
||||
if (GetImageSizeInBytes(image) <= maxSizeBytes)
|
||||
{
|
||||
image.Save(outputFilePath, image.RawFormat);
|
||||
return;
|
||||
}
|
||||
|
||||
// 裁剪图片
|
||||
// 这里只是一个简单的示例,实际应用中可能需要根据需求来裁剪图片
|
||||
using (Image croppedImage = CropImageToHalfSize(image))
|
||||
{
|
||||
// 保存裁剪后的图片
|
||||
using (MemoryStream memoryStream = new MemoryStream())
|
||||
{
|
||||
croppedImage.Save(memoryStream, image.RawFormat);
|
||||
|
||||
// 如果裁剪后的图片大小仍然大于限制,则递归裁剪
|
||||
if (memoryStream.Length > maxSizeBytes)
|
||||
{
|
||||
memoryStream.Position = 0;
|
||||
string tempFile = outputFilePath.Replace(".jpg", "temp.jpg").Replace(".jpeg", "temp.jpg");
|
||||
using (FileStream fileStream = new FileStream(tempFile, FileMode.Create))
|
||||
{
|
||||
memoryStream.CopyTo(fileStream);
|
||||
}
|
||||
CropImage(tempFile, outputFilePath, maxSizeInKB);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 保存到文件
|
||||
memoryStream.Position = 0;
|
||||
using (FileStream fileStream = new FileStream(outputFilePath, FileMode.Create))
|
||||
{
|
||||
memoryStream.CopyTo(fileStream);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Image CropImageToHalfSize(Image image)
|
||||
{
|
||||
// 这里只是一个示例,实际情况可能需要根据需求来裁剪图片
|
||||
int newWidth = image.Width / 2;
|
||||
int newHeight = image.Height / 2;
|
||||
return image.GetThumbnailImage(newWidth, newHeight, () => { return false; }, IntPtr.Zero);
|
||||
}
|
||||
|
||||
private static long GetImageSizeInBytes(Image image)
|
||||
{
|
||||
using (MemoryStream memoryStream = new MemoryStream())
|
||||
{
|
||||
image.Save(memoryStream, image.RawFormat);
|
||||
return memoryStream.Length;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,416 @@
|
||||
using BLL.Common;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Timers;
|
||||
|
||||
namespace BLL
|
||||
{
|
||||
public class YunMouService
|
||||
{
|
||||
|
||||
#region 启动监视器 系统启动5分钟
|
||||
/// <summary>
|
||||
/// 监视组件
|
||||
/// </summary>
|
||||
private static Timer messageTimer;
|
||||
private static string token;
|
||||
private static string consumerId;
|
||||
/// <summary>
|
||||
/// 启动监视器,不一定能成功,根据系统设置决定对监视器执行的操作 系统启动5分钟
|
||||
/// </summary>
|
||||
public static void StartMonitor()
|
||||
{
|
||||
token = YunMouHelper.getToken();
|
||||
consumerId = YunMouHelper.addConsumer(token);
|
||||
|
||||
if (messageTimer != null)
|
||||
{
|
||||
messageTimer.Stop();
|
||||
messageTimer.Dispose();
|
||||
messageTimer = null;
|
||||
}
|
||||
|
||||
messageTimer = new Timer
|
||||
{
|
||||
AutoReset = true
|
||||
};
|
||||
messageTimer.Elapsed += new ElapsedEventHandler(InProcess);
|
||||
messageTimer.Interval = 4000 * 60;// 10分钟
|
||||
messageTimer.Start();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 流程确认 定时执行 系统启动5分钟
|
||||
/// </summary>
|
||||
/// <param name="sender">Timer组件</param>
|
||||
/// <param name="e">事件参数</param>
|
||||
private static void InProcess(object sender, ElapsedEventArgs e)
|
||||
{
|
||||
//自动调用
|
||||
DoSynchDataNew();
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 手动调用
|
||||
/// </summary>
|
||||
public static void manualOperation(string tokenSd, string consumerIdSd)
|
||||
{
|
||||
DoSynchData(tokenSd, consumerIdSd);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public static void DoSynchData(string tokenSd = "", string consumerIdSd = "")
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(token))
|
||||
{
|
||||
token = tokenSd;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(consumerId))
|
||||
{
|
||||
consumerId = consumerIdSd;
|
||||
}
|
||||
////获取token
|
||||
//token = YunMouHelper.getToken();
|
||||
////创建消费者消费者如果5分钟未调用拉取消息接口将被删除。
|
||||
//consumerId = YunMouHelper.addConsumer(token);
|
||||
ErrLogInfo.WriteLog(token + ";" + consumerId);
|
||||
|
||||
string content = YunMouHelper.consumerMessage(consumerId, token);
|
||||
//调用消息队列第一次
|
||||
ErrLogInfo.WriteLog(content);
|
||||
var j2 = JsonConvert.DeserializeObject<dynamic>(content);
|
||||
|
||||
//消费者首次拉取消息时需要与消息通道建立连接,此次调用实际拉到消息列表为空,
|
||||
//再次调用即可拉取到消息,30秒内必须再次调用拉取消息接口,否则将断开与消息通道的连接。
|
||||
//因此拉取间隔需要在30秒以内,否则每次拉到的消息是空的
|
||||
if (j2.data.Count > 0)
|
||||
{
|
||||
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
|
||||
{
|
||||
for (int i = 0; i < j2.data.Count; i++)
|
||||
{
|
||||
var msg = JsonConvert.DeserializeObject(j2.data[i]["content"].ToString());
|
||||
if (!string.IsNullOrEmpty(Convert.ToString(msg.employeeNo)))
|
||||
{
|
||||
string deviceSerial = Convert.ToString(msg.deviceSerial);
|
||||
string employeeNo = Convert.ToString(msg.employeeNo);
|
||||
DateTime dateTime = Convert.ToDateTime(Convert.ToString(msg.dateTime));
|
||||
var devices = Funs.DB.Project_Devices.FirstOrDefault(x => x.DeviceSerial == deviceSerial);
|
||||
Model.SitePerson_PersonInOut newInOut = new Model.SitePerson_PersonInOut
|
||||
{
|
||||
ProjectId = devices.ProjectId,
|
||||
IdentityCard = employeeNo,
|
||||
IsIn = true,
|
||||
ChangeTime = dateTime,
|
||||
InOutWay = Const.InOutWay_1,
|
||||
};
|
||||
InsertInOut(newInOut);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//修改 如果为空循环调用最多5次
|
||||
for (int y = 0; y < 5; y++)
|
||||
{
|
||||
//如果为空再调一次
|
||||
content = YunMouHelper.consumerMessage(consumerId, token);
|
||||
//调用消息队列第二次
|
||||
ErrLogInfo.WriteLog(content+"调用消息队列" + (y + 2).ToString());
|
||||
j2 = JsonConvert.DeserializeObject<dynamic>(content);
|
||||
if (j2.data.Count > 0)
|
||||
{
|
||||
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
|
||||
{
|
||||
for (int i = 0; i < j2.data.Count; i++)
|
||||
{
|
||||
var msg = JsonConvert.DeserializeObject(j2.data[i]["content"].ToString());
|
||||
if (!string.IsNullOrEmpty(Convert.ToString(msg.employeeNo)))
|
||||
{
|
||||
string deviceSerial = Convert.ToString(msg.deviceSerial);
|
||||
string employeeNo = Convert.ToString(msg.employeeNo);
|
||||
DateTime dateTime = Convert.ToDateTime(Convert.ToString(msg.dateTime));
|
||||
|
||||
var devices = Funs.DB.Project_Devices.FirstOrDefault(x => x.DeviceSerial == deviceSerial);
|
||||
//身份证号时
|
||||
if (employeeNo.Length == 18)
|
||||
{
|
||||
Model.SitePerson_PersonInOut newInOut = new Model.SitePerson_PersonInOut
|
||||
{
|
||||
ProjectId = devices.ProjectId,
|
||||
IdentityCard = employeeNo,
|
||||
IsIn = true,
|
||||
ChangeTime = dateTime,
|
||||
InOutWay = Const.InOutWay_1,
|
||||
};
|
||||
InsertInOut(newInOut);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//提交偏移量
|
||||
var msgOffset = YunMouHelper.offsets(consumerId, token);
|
||||
}
|
||||
//有值跳出循环
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var erro = ex.Message;
|
||||
ErrLogInfo.WriteLog(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
public static void DoSynchDataNew()
|
||||
{
|
||||
try
|
||||
{
|
||||
////获取token
|
||||
//token = YunMouHelper.getToken();
|
||||
////创建消费者消费者如果5分钟未调用拉取消息接口将被删除。
|
||||
//consumerId = YunMouHelper.addConsumer(token);
|
||||
|
||||
ErrLogInfo.WriteLog(token + ";" + consumerId+ "调用消息队列参数");
|
||||
string content = YunMouHelper.consumerMessage(consumerId, token);
|
||||
//调用消息队列第一次
|
||||
ErrLogInfo.WriteLog(content );
|
||||
var j2 = JsonConvert.DeserializeObject<dynamic>(content);
|
||||
|
||||
//消费者首次拉取消息时需要与消息通道建立连接,此次调用实际拉到消息列表为空,
|
||||
//再次调用即可拉取到消息,30秒内必须再次调用拉取消息接口,否则将断开与消息通道的连接。
|
||||
//因此拉取间隔需要在30秒以内,否则每次拉到的消息是空的
|
||||
if (j2.data.Count > 0)
|
||||
{
|
||||
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
|
||||
{
|
||||
for (int i = 0; i < j2.data.Count; i++)
|
||||
{
|
||||
var msg = JsonConvert.DeserializeObject(j2.data[i]["content"].ToString());
|
||||
if (!string.IsNullOrEmpty(Convert.ToString(msg.employeeNo)))
|
||||
{
|
||||
string deviceSerial = Convert.ToString(msg.deviceSerial);
|
||||
string employeeNo = Convert.ToString(msg.employeeNo);
|
||||
DateTime dateTime = Convert.ToDateTime(Convert.ToString(msg.dateTime));
|
||||
var devices = db.Project_Devices.FirstOrDefault(x => x.DeviceSerial == deviceSerial);
|
||||
Model.SitePerson_PersonInOut newInOut = new Model.SitePerson_PersonInOut
|
||||
{
|
||||
ProjectId = devices.ProjectId,
|
||||
IdentityCard = employeeNo,
|
||||
IsIn = true,
|
||||
ChangeTime = dateTime,
|
||||
InOutWay = Const.InOutWay_1,
|
||||
};
|
||||
InsertInOut(newInOut);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//修改 如果为空循环调用最多5次
|
||||
for (int y = 0; y < 5; y++)
|
||||
{
|
||||
//如果为空再调一次
|
||||
content = YunMouHelper.consumerMessage(consumerId, token);
|
||||
//调用消息队列第二次
|
||||
ErrLogInfo.WriteLog(content+ "调用消息队列" + (y + 2).ToString());
|
||||
j2 = JsonConvert.DeserializeObject<dynamic>(content);
|
||||
if (j2.data.Count > 0)
|
||||
{
|
||||
using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
|
||||
{
|
||||
for (int i = 0; i < j2.data.Count; i++)
|
||||
{
|
||||
var msg = JsonConvert.DeserializeObject(j2.data[i]["content"].ToString());
|
||||
if (!string.IsNullOrEmpty(Convert.ToString(msg.employeeNo)))
|
||||
{
|
||||
string deviceSerial = Convert.ToString(msg.deviceSerial);
|
||||
string employeeNo = Convert.ToString(msg.employeeNo);
|
||||
DateTime dateTime = Convert.ToDateTime(Convert.ToString(msg.dateTime));
|
||||
|
||||
var devices = Funs.DB.Project_Devices.FirstOrDefault(x => x.DeviceSerial == deviceSerial);
|
||||
//身份证号时
|
||||
if (employeeNo.Length == 18)
|
||||
{
|
||||
Model.SitePerson_PersonInOut newInOut = new Model.SitePerson_PersonInOut
|
||||
{
|
||||
ProjectId = devices.ProjectId,
|
||||
IdentityCard = employeeNo,
|
||||
IsIn = true,
|
||||
ChangeTime = dateTime,
|
||||
InOutWay = Const.InOutWay_1,
|
||||
};
|
||||
InsertInOut(newInOut);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//提交偏移量
|
||||
var msgOffset = YunMouHelper.offsets(consumerId, token);
|
||||
}
|
||||
//有值跳出循环
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var erro = ex.Message;
|
||||
ErrLogInfo.WriteLog(ex.Message );
|
||||
}
|
||||
}
|
||||
|
||||
#region 根据考勤时间进入考勤
|
||||
public static void InsertInOut(Model.SitePerson_PersonInOut model)
|
||||
{
|
||||
//考勤时间配置不为空的情况
|
||||
var Kqgl_DateManageModel = Funs.DB.Kqgl_DateManage.FirstOrDefault(x => x.ProjectId == model.ProjectId);
|
||||
if (Kqgl_DateManageModel != null)
|
||||
{
|
||||
var changeTime = Convert.ToDateTime(model.ChangeTime);
|
||||
var nowTime = TimeSpan.Parse(changeTime.ToString("HH:mm:ss"));//当前时间的时分秒
|
||||
#region 根据规则判断是进门还是出门
|
||||
TimeSpan AmStartTime1 = TimeSpan.Parse(Kqgl_DateManageModel.AmStartTime1.ToString());
|
||||
TimeSpan AmStartTime2 = TimeSpan.Parse(Kqgl_DateManageModel.AmStartTime2.ToString());
|
||||
|
||||
TimeSpan AmEndTime1 = TimeSpan.Parse(Kqgl_DateManageModel.AmEndTime1.ToString());
|
||||
TimeSpan AmEndTime2 = TimeSpan.Parse(Kqgl_DateManageModel.AmEndTime2.ToString());
|
||||
|
||||
TimeSpan PmStartTime1 = TimeSpan.Parse(Kqgl_DateManageModel.PmStartTime1.ToString());
|
||||
TimeSpan PmStartTime2 = TimeSpan.Parse(Kqgl_DateManageModel.PmStartTime2.ToString());
|
||||
|
||||
TimeSpan PmEndTime1 = TimeSpan.Parse(Kqgl_DateManageModel.PmEndTime1.ToString());
|
||||
TimeSpan PmEndTime2 = TimeSpan.Parse(Kqgl_DateManageModel.PmEndTime2.ToString());
|
||||
|
||||
TimeSpan time1 = new TimeSpan(0, Convert.ToInt32(Kqgl_DateManageModel.LateTime), 0);
|
||||
TimeSpan time2 = new TimeSpan(0, Convert.ToInt32(Kqgl_DateManageModel.LeaveTime), 0);
|
||||
//允许迟到x分钟
|
||||
AmStartTime2 = AmStartTime2.Add(time2);
|
||||
PmStartTime2 = PmStartTime2.Add(time2);
|
||||
|
||||
//允许早退x分钟
|
||||
AmEndTime1 = AmEndTime1.Add(-time1);
|
||||
PmEndTime1 = PmEndTime1.Add(-time1);
|
||||
|
||||
var personModel = Funs.DB.SitePerson_Person.FirstOrDefault(x => x.IdentityCard == model.IdentityCard && x.ProjectId == model.ProjectId);
|
||||
if (personModel != null)
|
||||
{
|
||||
//状态:0上午上班 1上午下班 2下午上班 3下午下班
|
||||
var state = "";
|
||||
//如果是在进场时间内
|
||||
if (nowTime >= AmStartTime1 && nowTime <= AmStartTime2)
|
||||
{
|
||||
model.IsIn = true;
|
||||
state = "0";
|
||||
}
|
||||
if (nowTime >= PmStartTime1 && nowTime <= PmStartTime2)
|
||||
{
|
||||
model.IsIn = true;
|
||||
state = "2";
|
||||
}
|
||||
if (nowTime >= AmEndTime1 && nowTime <= AmEndTime2)
|
||||
{
|
||||
model.IsIn = false;
|
||||
state = "1";
|
||||
}
|
||||
if (nowTime >= PmEndTime1 && nowTime <= PmEndTime2)
|
||||
{
|
||||
model.IsIn = false;
|
||||
state = "3";
|
||||
}
|
||||
Model.SGGLDB db = Funs.DB;
|
||||
#region 这个人该时间点内有数据的话,就删掉(上班打卡时间取最早不删除,下班取最晚,删除早的)
|
||||
var objTime1 = Convert.ToDateTime(Convert.ToDateTime(changeTime).ToString("yyyy-MM-dd") + " " + AmStartTime1.ToString());
|
||||
var objTime2 = Convert.ToDateTime(Convert.ToDateTime(changeTime).ToString("yyyy-MM-dd") + " " + AmStartTime2.ToString());
|
||||
|
||||
var objTime3 = Convert.ToDateTime(Convert.ToDateTime(changeTime).ToString("yyyy-MM-dd") + " " + AmEndTime1.ToString());
|
||||
var objTime4 = Convert.ToDateTime(Convert.ToDateTime(changeTime).ToString("yyyy-MM-dd") + " " + AmEndTime2.ToString());
|
||||
|
||||
var objTime5 = Convert.ToDateTime(Convert.ToDateTime(changeTime).ToString("yyyy-MM-dd") + " " + PmStartTime1.ToString());
|
||||
var objTime6 = Convert.ToDateTime(Convert.ToDateTime(changeTime).ToString("yyyy-MM-dd") + " " + PmStartTime2.ToString());
|
||||
|
||||
var objTime7 = Convert.ToDateTime(Convert.ToDateTime(changeTime).ToString("yyyy-MM-dd") + " " + PmEndTime1.ToString());
|
||||
var objTime8 = Convert.ToDateTime(Convert.ToDateTime(changeTime).ToString("yyyy-MM-dd") + " " + PmEndTime2.ToString());
|
||||
|
||||
//1.上午上班
|
||||
var result1 = db.SitePerson_PersonInOut.Where(x => x.ProjectId == model.ProjectId && x.IdentityCard == personModel.IdentityCard &&
|
||||
x.ChangeTime >= objTime1 && x.ChangeTime <= objTime2
|
||||
).ToList();
|
||||
//2.上午下班
|
||||
var result2 = db.SitePerson_PersonInOut.Where(x => x.ProjectId == model.ProjectId && x.IdentityCard == personModel.IdentityCard &&
|
||||
x.ChangeTime >= objTime3 && x.ChangeTime <= objTime4
|
||||
).ToList();
|
||||
//3.下午上班
|
||||
var result3 = db.SitePerson_PersonInOut.Where(x => x.ProjectId == model.ProjectId && x.IdentityCard == personModel.IdentityCard &&
|
||||
x.ChangeTime >= objTime5 && x.ChangeTime <= objTime6
|
||||
).ToList();
|
||||
//4.下午下班
|
||||
var result4 = db.SitePerson_PersonInOut.Where(x => x.ProjectId == model.ProjectId && x.IdentityCard == personModel.IdentityCard &&
|
||||
x.ChangeTime >= objTime7 && x.ChangeTime <= objTime8
|
||||
).ToList();
|
||||
|
||||
//上班打卡时间取最早,下班取最晚
|
||||
if (result1.Count > 0 && state == "0")
|
||||
{
|
||||
//db.SitePerson_PersonInOut.DeleteAllOnSubmit(result1);
|
||||
//db.SubmitChanges();
|
||||
}
|
||||
else if (result1.Count == 0 && state == "0")
|
||||
{
|
||||
PersonInOutService.AddPersonInOut(model);
|
||||
}
|
||||
if (result2.Count > 0 && state == "1")
|
||||
{
|
||||
db.SitePerson_PersonInOut.DeleteAllOnSubmit(result2);
|
||||
db.SubmitChanges();
|
||||
PersonInOutService.AddPersonInOut(model);
|
||||
}
|
||||
else if (result2.Count == 0 && state == "1")
|
||||
{
|
||||
PersonInOutService.AddPersonInOut(model);
|
||||
}
|
||||
if (result3.Count > 0 && state == "2")
|
||||
{
|
||||
//db.SitePerson_PersonInOut.DeleteAllOnSubmit(result3);
|
||||
//db.SubmitChanges();
|
||||
}
|
||||
else if (result3.Count == 0 && state == "2")
|
||||
{
|
||||
PersonInOutService.AddPersonInOut(model);
|
||||
}
|
||||
if (result4.Count > 0 && state == "3")
|
||||
{
|
||||
db.SitePerson_PersonInOut.DeleteAllOnSubmit(result4);
|
||||
db.SubmitChanges();
|
||||
PersonInOutService.AddPersonInOut(model);
|
||||
}
|
||||
else if (result4.Count == 0 && state == "3")
|
||||
{
|
||||
PersonInOutService.AddPersonInOut(model);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
namespace BLL
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Model;
|
||||
|
||||
public static class ProjectDeviceService
|
||||
{
|
||||
public static Model.SGGLDB db = Funs.DB;
|
||||
|
||||
/// <summary>
|
||||
///获取项目单位信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static Model.Project_Devices GetProjectDeviceById(string deviceId)
|
||||
{
|
||||
return Funs.DB.Project_Devices.FirstOrDefault(e => e.DeviceId == deviceId);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 增加项目设备信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static void AddProjectDevice(Project_Devices projectDevices)
|
||||
{
|
||||
SGGLDB db = Funs.DB;
|
||||
Project_Devices newProjectUnit = new Project_Devices
|
||||
{
|
||||
DeviceId = SQLHelper.GetNewID(typeof(Model.Project_Devices)),
|
||||
ProjectId = projectDevices.ProjectId,
|
||||
DeviceName = projectDevices.DeviceName,
|
||||
DeviceSerial = projectDevices.DeviceSerial,
|
||||
CreateDate = projectDevices.CreateDate,
|
||||
Address = projectDevices.Address,
|
||||
IsInOut = projectDevices.IsInOut,
|
||||
ValidateCode = projectDevices.ValidateCode,
|
||||
YunMouDeviceId = projectDevices.YunMouDeviceId,
|
||||
YunMouPermission = projectDevices.YunMouPermission,
|
||||
};
|
||||
db.Project_Devices.InsertOnSubmit(newProjectUnit);
|
||||
db.SubmitChanges();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///修改项目设备信息
|
||||
/// </summary>
|
||||
/// <param name="projectUnit"></param>
|
||||
public static void UpdateProjectDevice(Model.Project_Devices devices)
|
||||
{
|
||||
Model.SGGLDB db = Funs.DB;
|
||||
Model.Project_Devices newDevices = db.Project_Devices.FirstOrDefault(e => e.DeviceId == devices.DeviceId);
|
||||
if (newDevices != null)
|
||||
{
|
||||
newDevices.ProjectId = devices.ProjectId;
|
||||
newDevices.DeviceName = devices.DeviceName;
|
||||
newDevices.DeviceSerial = devices.DeviceSerial;
|
||||
newDevices.CreateDate = devices.CreateDate;
|
||||
newDevices.Address = devices.Address;
|
||||
newDevices.IsInOut = devices.IsInOut;
|
||||
newDevices.ValidateCode = devices.ValidateCode;
|
||||
newDevices.YunMouPermission = devices.YunMouPermission;
|
||||
newDevices.YunMouDeviceId = devices.YunMouDeviceId;
|
||||
db.SubmitChanges();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据项目单位Id删除一个项目单位信息
|
||||
/// </summary>
|
||||
/// <param name="projectUnitId"></param>
|
||||
public static void DeleteProjectDeviceById(string deviceId)
|
||||
{
|
||||
Model.SGGLDB db = Funs.DB;
|
||||
Model.Project_Devices devices = db.Project_Devices.FirstOrDefault(e => e.DeviceId == deviceId);
|
||||
if (devices != null)
|
||||
{
|
||||
db.Project_Devices.DeleteOnSubmit(devices);
|
||||
db.SubmitChanges();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user