2025-03-27 15:05:14 +08:00

74 lines
3.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using HZQR.Common;
using Newtonsoft.Json;
using SuperMap.RealEstate.ServiceModel;
using Business = SuperMap.RealEstate.Personnel.Storage.Business;
namespace Personnel.WebSite.Shanxi
{
public class HolidayDateHelper
{
/// <summary>
/// 请求接口查询节假日
/// </summary>
/// <param name="type">按日期范围查询type=3&date=2020-11-1~2020-11-10</param>
/// <param name="date">按月查询type=2&date=2020-10</param>
/// <returns></returns>
public static Models.HolidayDate GetWorkDateByApi(int type, string date)
{
string key = "ce9ac01a3105e7babff09452fbd564c5";
//请求接口,写入数据库,2:按月模式
string url = "https://api.tianapi.com/txapi/jiejiari/index?key=" + key + "&mode=1&type=" + type + "&date=" + date;
string jsonstr = HttpUtil.HttpUrlGet(url, 500);
JsonSerializer serializer = new JsonSerializer();
StringReader sr = new StringReader(jsonstr);
object obj = serializer.Deserialize(new JsonTextReader(sr), typeof(Models.HolidayDate));
Models.HolidayDate holidayDate = obj as Models.HolidayDate;
return holidayDate;
}
public static bool IsNeedSeachApi(Transaction _Transaction, string startDate, string endDate,
ref int workDay, ref string searchMonth)
{
//先查询数据库
string sqlWhere = string.Format(@"
WHERE TO_DATE(DATE_NAME,'yyyy-mm-dd')>=TO_DATE('{0}','yyyy-mm-dd') AND
TO_DATE(DATE_NAME,'yyyy-mm-dd')<=TO_DATE('{1}','yyyy-mm-dd')", startDate, endDate);
Business.DATE dateModel = new Business.DATE(_Transaction);
List<Business.DATE> list = dateModel.FillCollection(sqlWhere);
bool isSearchApi = false;
string startMonth = Convert.ToDateTime(startDate).ToString("yyyy-MM");
string endMonth = Convert.ToDateTime(endDate).ToString("yyyy-MM");
if (list.Count == 0)
{
isSearchApi = true;
if (startMonth == endMonth)//开始月份等于结束月份,请求一次接口即可
{
searchMonth = startMonth;//查询1个月份
}
return isSearchApi;
}
else
{
int diffMonth = Convert.ToDateTime(endDate).Month - Convert.ToDateTime(startDate).Month;
for (int i = 0; i <= diffMonth; i++)
{
startMonth = Convert.ToDateTime(startDate).AddMonths(i).ToString("yyyy-MM");
if (list.Where(o => Convert.ToDateTime(o.DATE_NAME).ToString("yyyy-MM") == startMonth).Count() == 0)
{
isSearchApi = true;
searchMonth += startMonth + ",";
return isSearchApi;
}
searchMonth = searchMonth.TrimEnd(',');
}
workDay = list.Where(o => o.DATE_ISNOTWORK == 0).Count();
}
return isSearchApi;
}
}
}