PayrollComputation.cs 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124
  1. using Google.Protobuf.WellKnownTypes;
  2. using NPOI.OpenXmlFormats.Spreadsheet;
  3. using NPOI.SS.Formula.Functions;
  4. using OASystem.API.OAMethodLib.QiYeWeChatAPI;
  5. using OASystem.Domain;
  6. using OASystem.Domain.Entities.PersonnelModule;
  7. using OASystem.Domain.ViewModels.PersonnelModule;
  8. using OASystem.Domain.ViewModels.QiYeWeChat;
  9. using OASystem.Infrastructure.Repositories.Groups;
  10. using System;
  11. using System.Diagnostics.Eventing.Reader;
  12. using System.Linq.Expressions;
  13. using TencentCloud.Ocr.V20181119.Models;
  14. namespace OASystem.API.OAMethodLib
  15. {
  16. /// <summary>
  17. /// 工资计算
  18. /// </summary>
  19. public static class PayrollComputation
  20. {
  21. private static Result _result = new Result();
  22. private static readonly IQiYeWeChatApiService _qiYeWeChatApiService = AutofacIocManager.Instance.GetService<IQiYeWeChatApiService>();
  23. private static readonly UsersRepository _usersRep = AutofacIocManager.Instance.GetService<UsersRepository>();
  24. private static readonly IMapper _mapper = AutofacIocManager.Instance.GetService<IMapper>();
  25. private static readonly decimal _chengDuMinimumWage = 2100.00M;
  26. /// <summary>
  27. /// 计算工资
  28. /// </summary>
  29. /// <param name="pm_WageSheetDattaSources"></param>
  30. /// <param name="userNames"></param>
  31. /// <param name="thisYearMonth"></param>
  32. /// <param name="startDt"></param>
  33. /// <param name="endDt"></param>
  34. /// <returns></returns>
  35. public static async Task<Result> SalaryCalculatorAsync(
  36. List<Pm_WageSheet> pm_WageSheetDattaSources, List<UserNameView> userNames, int userId, string thisYearMonth, DateTime startDt, DateTime endDt)
  37. {
  38. if (pm_WageSheetDattaSources.Count <= 0)
  39. {
  40. _result.Msg = "计算工资传入数据为空!";
  41. return _result;
  42. }
  43. if (userNames.Count <= 0)
  44. {
  45. var nameData = await _usersRep.GetUserNameList(1);
  46. userNames = nameData.Data;
  47. }
  48. //计算时间段内工作日
  49. int work_days = GetWorkDays(startDt, endDt);
  50. //获取所有打卡数据
  51. CheckInView checkIn = await _qiYeWeChatApiService.GetCheckin_MonthDataAsync(startDt, endDt); //时间段内所有 打卡数据
  52. if (checkIn.errcode != 0)
  53. {
  54. _result.Msg = "【企业微信】【打卡】【获取所有月打卡数据】【Msg】" + checkIn.errmsg;
  55. return _result;
  56. }
  57. List<Data> checkInDatas = checkIn.datas;
  58. //获取 请假类型 Sp_Detail.template_id
  59. string leave_template_id = "C4NzTJCh1onCUK915rRkvy7Fh5Vqz4YbiEV9jrBY1";
  60. List<VacationLeaveTypeView> vacationLeaveTypes = await GetVacationLeaveTypes(leave_template_id);
  61. if (vacationLeaveTypes.Count <= 0)
  62. {
  63. _result.Msg = startDt + " - " + endDt + "请假 类型数据 获取失败!";
  64. return _result;
  65. }
  66. _result.Msg = string.Empty;
  67. try
  68. {
  69. foreach (var pm_wsInfo in pm_WageSheetDattaSources)
  70. {
  71. string itemName = userNames.Where(it => it.Id == pm_wsInfo.UserId).FirstOrDefault().CnName;
  72. //补贴 金额
  73. decimal meal_subsidy = 0.00M; // 午餐(午餐10元/天) 补贴 * 计算方式:单日上午请假时长(小时)大于或者等于三小时 没有餐补
  74. //事假 病假 总金额
  75. decimal personalLeaveTotal = 0.00M, // 事假 日薪 *计算方式:日平均工资 = 月工资/当月应出勤天数。
  76. sickLeaveTotal = 0.00M; // 病假 日薪 *计算方式:日平均工资 = 成都市最低工资标准的80%/当月应出勤天数。 短期病假=当月15天内
  77. //扣款金额
  78. decimal beLate_deduction = 0.00M, // 迟到 扣款金额 *计算方式:
  79. // 一个自然月内,不足 10 分钟的迟到/早退,不超过 2 次的部分,不做处罚;3 次及以上,按50元 / 次处罚;
  80. // 超过 10 分钟(含 10 分钟),不足 60 分钟的迟到/早退,按 50 元/次处罚;
  81. // 超过 60 分钟(含 60 分钟),不足 3 小时的迟到/早退,且无请假者,按旷工半日处理;超过3 小时的迟到 / 早退,且无请假者,按旷工一日处理。
  82. early_deduction = 0.00M, // 早退 扣款金额
  83. absenteeism_deduction = 0.00M, // 旷工 扣款金额 *计算方式:旷工扣发当日工资
  84. unprinted_deduction = 0.00M, // 未打卡 扣款金额 *计算方式:
  85. // 试用期员工每月有 2 次 补卡机会,超过 2 次不足 5 次的部分,按 10 元 / 次处罚,5 次及以上的漏卡,按 50 元 / 次处罚;
  86. // 正式员工每月 3 次以内的补卡,按 10 元 / 次处罚,3 次及以上的漏卡,按 50 元 / 次处罚。
  87. sickLeave_deduction = 0.00M, // 病假
  88. other_deduction = 0.00M; // 其他 扣款金额
  89. decimal meal_deduction = 0.00M; // 餐补 扣款金额
  90. decimal reissuecard_deduction = 0.00M; // 补卡 扣款金额
  91. //打卡数据
  92. Data? checkInData = checkInDatas.Where(it => it.base_info.name == itemName).FirstOrDefault();
  93. if (checkInData == null) { continue; }
  94. string acctid = checkInData.base_info.acctid; //用户Id
  95. //当月总计数据
  96. Summary_Info? summary_Info = checkInData.summary_info;
  97. if (summary_Info == null) { continue; }
  98. //int work_days = summary_Info.work_days -1; //应出勤天数
  99. //int regular_days = summary_Info.regular_days - 1; //正常出勤天数
  100. meal_subsidy = work_days * 10; //应发放餐补
  101. #region 计算日工资 正常日薪 事假日薪 病假日薪
  102. //月 - 应发工资
  103. decimal amountPayable = pm_wsInfo.Basic + pm_wsInfo.Floats + pm_wsInfo.PostAllowance + pm_wsInfo.InformationSecurityFee + pm_wsInfo.OtherSubsidies;
  104. // 日薪 = *计算方式:日平均工资 = 月工资/当月应出勤天数。
  105. decimal dailyWage = ConvertToDecimal(amountPayable / work_days);
  106. // 病假日薪 *计算方式:日平均工资 = 成都市最低工资标准的80%/当月应出勤天数。 短期病假=当月15天内
  107. decimal sickLeave_dailywage = ConvertToDecimal(_chengDuMinimumWage / work_days);
  108. //病假 一天扣款
  109. sickLeave_deduction = dailyWage - sickLeave_dailywage;
  110. #endregion
  111. int annualLeaveNum = 0, //年假
  112. personalLeaveNum = 0, //事假
  113. sickLeaveNum = 0, //病假
  114. lieuLeaveNum = 0, //调休假
  115. marriageLeaveNum = 0, //婚嫁
  116. maternityLeaveNum = 0, //产假
  117. paternityLeaveNum = 0, //陪产假
  118. funeralLeaveNum = 0, //丧假
  119. reissueCardNum = 0, //补卡 次数
  120. evectionNum = 0, //出差 次数
  121. outIngNum = 0, //外出 次数
  122. outWorkNum = 0, //外勤 次数
  123. otherLeaveNum = 0; //其他
  124. #region 假勤 处理 1-请假;2-补卡;3-出差;4-外出;100-外勤;
  125. List<Sp_Item>? sp_items = checkInData.sp_items.Where(it => it.count != 0).ToList();
  126. if (sp_items != null && sp_items.Count > 0)
  127. {
  128. annualLeaveNum = Fallibilitydispose(sp_items, 1, "年假");
  129. personalLeaveNum = Fallibilitydispose(sp_items, 1, "事假");
  130. sickLeaveNum = Fallibilitydispose(sp_items, 1, "病假");
  131. lieuLeaveNum = Fallibilitydispose(sp_items, 1, "调休假");
  132. marriageLeaveNum = Fallibilitydispose(sp_items, 1, "婚嫁");
  133. maternityLeaveNum = Fallibilitydispose(sp_items, 1, "产假");
  134. paternityLeaveNum = Fallibilitydispose(sp_items, 1, "陪产假");
  135. funeralLeaveNum = Fallibilitydispose(sp_items, 1, "丧假");
  136. otherLeaveNum = Fallibilitydispose(sp_items, 1, "其他");
  137. reissueCardNum = Fallibilitydispose(sp_items, 2, "补卡次数");
  138. evectionNum = Fallibilitydispose(sp_items, 3, "出差");
  139. outIngNum = Fallibilitydispose(sp_items, 4, "外出");
  140. outWorkNum = Fallibilitydispose(sp_items, 3, "外勤");
  141. }
  142. #region 请假类型金额/餐补 处理
  143. List<Sp_Detail> sp_leave_details = new List<Sp_Detail>();
  144. sp_leave_details = await _qiYeWeChatApiService.GetApprovalDetailsAsync(startDt, endDt, acctid, 2, 1); //时间段内所有 已同意的 请假 审批数据
  145. if (sp_leave_details.Count <= 0)
  146. {
  147. _result.Msg += startDt + " - " + endDt + " " + itemName + " 请假 审批数据获取未获取到!\r\n";
  148. //continue;
  149. }
  150. List<Ex_Items> ex_Items = new List<Ex_Items>();//假勤 And 打卡备注集合
  151. Ex_Items ex_Items_jq = new Ex_Items() { Type = "假勤" }; //假勤
  152. List<Ex_Item> ex_ItemInfos = new List<Ex_Item>();
  153. foreach (Sp_Detail sp_item in sp_leave_details)
  154. {
  155. Apply_data? apply_data = sp_item.apply_data;
  156. if (apply_data != null)
  157. {
  158. List<ContentsItem> contents = apply_data.contents;
  159. ContentsItem content_Vacation = contents.Where(it => it.control == "Vacation").FirstOrDefault(); //请假类型
  160. ContentsItem content_Textarea = contents.Where(it => it.control == "Textarea").FirstOrDefault(); //多行文本
  161. if (content_Vacation != null)
  162. {
  163. Vacation vacation = content_Vacation.value.vacation;
  164. Attendance attendance = vacation.attendance; //假勤组件
  165. Selector selector = vacation.selector; //请假类型
  166. List<OptionsItem> optionsItems = selector.options; //key 请假类型 id
  167. List<TitleItem> value = optionsItems[0].value; // value 文本描述值
  168. int leaveType = int.Parse(optionsItems[0].key); //key 请假子类型 id
  169. Date_range date_Range = attendance.date_range;
  170. //筛选 不在工作日内的假勤申请
  171. if (startDt >= date_Range.new_begin_dt && date_Range.new_end_dt <= endDt)
  172. {
  173. continue;
  174. }
  175. decimal thisTypeDeduction = 0.00M;//当前类型扣款
  176. string leave_starttime = date_Range.new_begin_dt.ToString("HH:mm");
  177. string leave_endtime = date_Range.new_end_dt.ToString("HH:mm");
  178. string typeName = string.Empty;
  179. string unit = string.Empty;
  180. int leaveTypeId = leaveType;
  181. var leaveTypeData = vacationLeaveTypes.Where(it => it.id == leaveTypeId).FirstOrDefault();
  182. if (leaveTypeData != null) { typeName = leaveTypeData.name; }
  183. string startTime = string.Empty;
  184. string endTime = string.Empty;
  185. //计算请假类型扣款金额
  186. decimal new_duration = 0.00M;
  187. if (date_Range.type == "halfday")
  188. {
  189. new_duration = Convert.ToDecimal(date_Range.new_duration) / 86400M;
  190. unit = "天";
  191. startTime = date_Range.new_begin_dt.ToString("yyyy-MM-dd") + " 09:00";
  192. endTime = date_Range.new_begin_dt.ToString("yyyy-MM-dd") + " 18:00";
  193. }
  194. else if (date_Range.type == "hour")
  195. {
  196. new_duration = Convert.ToDecimal(date_Range.new_duration) / 3600M;
  197. unit = "小时";
  198. startTime = date_Range.new_begin_dt.ToString("yyyy-MM-dd HH:mm:ss");
  199. endTime = date_Range.new_end_dt.ToString("yyyy-MM-dd HH:mm:ss");
  200. }
  201. decimal leave_meals = 0.00M;
  202. //计算餐补 假勤类型扣款
  203. CalculateTypeFee(leaveType, date_Range.type, leave_starttime, leave_endtime, amountPayable, work_days, new_duration,
  204. out leave_meals, out thisTypeDeduction);
  205. #region 累计类型扣款
  206. //1年假;2事假;3病假;4调休假;5婚假;6产假;7陪产假;8其他;9丧假
  207. if (leaveType == 2) //事假
  208. {
  209. personalLeaveTotal += thisTypeDeduction;
  210. }
  211. else if (leaveType == 3) //病假
  212. {
  213. sickLeaveTotal = thisTypeDeduction;
  214. }
  215. #endregion
  216. meal_deduction += leave_meals;
  217. Ex_Item ex_Item = new Ex_Item()
  218. {
  219. SubTypeId = leaveType,
  220. SubType = typeName,
  221. StartTimeDt = Convert.ToDateTime(startTime),
  222. EndTimeDt = Convert.ToDateTime(endTime),
  223. Duration = new_duration,
  224. Unit = unit,
  225. Deduction = thisTypeDeduction,
  226. //Reason = apply_data.reason,
  227. Apply_time_dt = Convert.ToDateTime(sp_item.apply_time_dt.ToString("yyyy-MM-dd HH:mm:ss")),
  228. //Approval_name = sp_item.approval_name,
  229. };
  230. ex_ItemInfos.Add(ex_Item);
  231. }
  232. }
  233. }
  234. if (ex_ItemInfos.Count > 0)
  235. {
  236. ex_Items_jq.Ex_ItemInfo = ex_ItemInfos.OrderBy(it => it.SubTypeId).ThenBy(it => it.Apply_time_dt).ToList();
  237. ex_Items.Add(ex_Items_jq);
  238. }
  239. #endregion
  240. #endregion
  241. Ex_Items ex_Items_dk = new Ex_Items() { Type = "打卡" }; //打卡
  242. List<Ex_Item> ex_reissuecard_Items = new List<Ex_Item>();
  243. #region 打卡补卡 补卡次数 处理
  244. if (reissueCardNum > 0)
  245. {
  246. List<Sp_Detail> sp_buka_details = new List<Sp_Detail>();
  247. sp_leave_details = await _qiYeWeChatApiService.GetApprovalDetailsAsync(startDt, endDt, acctid, 2, 2); //时间段内所有 已同意的 请假 审批数据
  248. int bukaNum = 1;
  249. foreach (var item in sp_leave_details)
  250. {
  251. decimal bukaPrice = 0.00M;
  252. if (bukaNum <= 2)
  253. {
  254. bukaPrice = 10.00M;
  255. }
  256. else {
  257. bukaPrice = 50.00M;
  258. }
  259. var app_data = item.apply_data;
  260. var punch_correction1 = app_data.contents[0].value.punch_correction; //未打卡时间
  261. var punch_correction2 = app_data.contents[1].value;
  262. Ex_Item ex_reissueCard = new Ex_Item()
  263. {
  264. SubTypeId = 7,
  265. SubType = "打卡补卡",
  266. StartTimeDt = Convert.ToDateTime(punch_correction1.time_dt.ToString("yyyy-MM-dd HH:mm:ss")), //未打卡时间
  267. Deduction = bukaPrice,
  268. Reason = punch_correction2.text,
  269. Unit = string.Empty
  270. };
  271. unprinted_deduction += bukaPrice;
  272. ex_reissuecard_Items.Add(ex_reissueCard);
  273. bukaNum++;
  274. }
  275. }
  276. #endregion
  277. List<Sp_Detail> sp_reissuecard_details = new List<Sp_Detail>();
  278. //统计迟到次数
  279. int beLateNum = 0, // 1-迟到;
  280. leaveEarlyNum = 0, // 2-早退;
  281. dummyDeckNum = 0, // 3-缺卡;
  282. minerNum = 0, // 4-旷工;
  283. locationAnomalyNum = 0, // 5-地点异常;
  284. unitExNum = 0; // 6-设备异常;
  285. if (summary_Info.except_days > 0)
  286. {
  287. List<Exception_Info>? ex_infos = checkInData.exception_infos;
  288. if (ex_infos != null && ex_infos.Count >= 0)
  289. {
  290. beLateNum = ExceptionStatistics(ex_infos, 1);
  291. leaveEarlyNum = ExceptionStatistics(ex_infos, 2);
  292. dummyDeckNum = ExceptionStatistics(ex_infos, 3);
  293. minerNum = ExceptionStatistics(ex_infos, 4);
  294. locationAnomalyNum = ExceptionStatistics(ex_infos, 5);
  295. unitExNum = ExceptionStatistics(ex_infos, 6);
  296. }
  297. }
  298. //打卡记录
  299. CheckInDataView checkInDataView = new CheckInDataView();
  300. checkInDataView = await _qiYeWeChatApiService.GetCheckinDataAsync(new List<string>() { acctid }, 3, startDt, endDt);
  301. if (checkInDataView.errcode != 0)
  302. {
  303. _result.Msg += startDt + " - " + endDt + " " + itemName + " 打卡记录 " + checkInDataView.errmsg + " \r\n";
  304. }
  305. //筛选时间异常的打卡记录
  306. List<CheckInDataInfo> checkInDataInfos = checkInDataView.checkindata.Where(it => !string.IsNullOrEmpty(it.exception_type)).ToList();
  307. //处理 未打卡的记录是否已经通过假勤审批
  308. List<CheckInDataInfo> leave_checkInDataInfos = new List<CheckInDataInfo>();
  309. if (checkInDataInfos.Count > 0)
  310. {
  311. foreach (var leaveItem in ex_ItemInfos)
  312. {
  313. if (leaveItem.StartTimeDt.ToString("yyyy-MM-dd").Equals(leaveItem.EndTimeDt.ToString("yyyy-MM-dd"))) //单天
  314. {
  315. leave_checkInDataInfos.AddRange(checkInDataInfos.Where(it => it.checkin_time_dt.ToString("yyyy-MM-dd") == leaveItem.StartTimeDt.ToString("yyyy-MM-dd")).ToList());
  316. }
  317. else //多天
  318. {
  319. leave_checkInDataInfos.AddRange(checkInDataInfos.Where(it => it.checkin_time_dt >= leaveItem.StartTimeDt && it.checkin_time_dt <= leaveItem.EndTimeDt).ToList());
  320. }
  321. }
  322. }
  323. //处理 时间异常的记录是否已经通过补卡审批
  324. List<CheckInDataInfo> pullcard_checkInDataInfos = new List<CheckInDataInfo>();
  325. if (leave_checkInDataInfos.Count > 0)
  326. {
  327. //获取异常打卡数据 并且 未通过假勤审批
  328. pullcard_checkInDataInfos = checkInDataInfos.Except(leave_checkInDataInfos).ToList();
  329. if (pullcard_checkInDataInfos.Count > 0)
  330. {
  331. CheckInDayDataView checkInDayDataView = await _qiYeWeChatApiService.GetCheckInDayDataAsync(new List<string>() { acctid }, startDt, endDt);
  332. if (checkInDayDataView.errcode != 0)
  333. {
  334. _result.Msg += startDt + " - " + endDt + " " + itemName + " 异常信息数据获取未获取到!\r\n";
  335. }
  336. List<Root> roots_words = checkInDayDataView.datas.Where(it => it.base_info.day_type == 0).ToList(); //获取工作日日报信息
  337. List<Root> roots_exs = checkInDayDataView.datas.Where(it => it.exception_infos.Count > 0).ToList();
  338. int user_cd_zt_num = 0;
  339. foreach (var roots_ex in roots_exs)
  340. {
  341. foreach (var exception_info in roots_ex.exception_infos)
  342. {
  343. decimal timelength = ConvertToDecimal( (Convert.ToDecimal(exception_info.duration) / 3600.00M) * 60.00M); //时长 分钟
  344. if (timelength == 9) timelength = 7.50M;
  345. int exception = exception_info.exception; //异常类型
  346. decimal day_miner_unit = ConvertToDecimal(dailyWage / 15); //以0.5小时为单位
  347. //1:一个自然月内,不足 10 分钟的迟到/早退,不超过 2 次的部分,不做处罚;3 次及以上,按50 元 / 次处罚;
  348. //2:超过 10 分钟(含 10 分钟),不足 60 分钟的迟到 / 早退,按 50 元 / 次处罚;
  349. //3:超过 60 分钟(含 60 分钟),不足 3 小时的迟到 / 早退,且无请假者,按旷工半日处理;超过 3 小时的迟到 / 早退,且无请假者,按旷工一日处理。
  350. long date = roots_ex.base_info.date; //当日工作日期
  351. long earliest_time = roots_ex.summary_info.earliest_time; //最早打卡时间
  352. long lastest_time = roots_ex.summary_info.lastest_time; //最晚打卡时间
  353. long this_date = date + earliest_time;
  354. DateTime thisDt = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)).AddTicks(this_date * 10000000);
  355. string thisDtStr = thisDt.ToString("yyyy-MM-dd");
  356. Ex_Item beLate_belate_ex = new Ex_Item()
  357. {
  358. SubTypeId = 4,
  359. SubType = "旷工",
  360. Duration = timelength,
  361. StartTimeDt = Convert.ToDateTime(roots_ex.base_info.dateDt.ToString("yyyy-MM-dd HH:mm:ss")),
  362. Unit = "分钟",
  363. };
  364. decimal day_deduction = 0.00M;
  365. //1 - 迟到;2 - 早退;3 - 缺卡;4 - 旷工;5 - 地点异常;6 - 设备异常
  366. if (exception == 1) //迟到
  367. {
  368. if (timelength < 10)
  369. {
  370. user_cd_zt_num++;
  371. beLate_belate_ex.SubTypeId = 1;
  372. beLate_belate_ex.SubType = "迟到";
  373. if (reissueCardNum >= 3)
  374. {
  375. day_deduction = 50.00M;
  376. }
  377. else
  378. {
  379. day_deduction = 0.00M;
  380. }
  381. beLate_deduction += day_deduction; //迟到扣款 总额
  382. }
  383. else if (timelength >= 10 && timelength <= 60)
  384. {
  385. day_deduction = 50.00M;
  386. beLate_deduction += day_deduction; //迟到扣款 总额
  387. beLate_belate_ex.SubTypeId = 1;
  388. beLate_belate_ex.SubType = "迟到";
  389. }
  390. else if (timelength > 60 && timelength <= 180)
  391. {
  392. day_deduction = day_miner_unit * 6; //3小时
  393. meal_deduction += 10.00M; //餐补扣款
  394. absenteeism_deduction += day_deduction; //矿工半日
  395. }
  396. else
  397. {
  398. day_deduction = dailyWage;
  399. absenteeism_deduction += day_deduction; //矿工一日
  400. meal_deduction += 10.00M;
  401. }
  402. beLate_belate_ex.Deduction = day_deduction;
  403. ex_reissuecard_Items.Add(beLate_belate_ex);
  404. }
  405. else if (exception == 2) //早退
  406. {
  407. if (timelength < 10)
  408. {
  409. user_cd_zt_num++;
  410. beLate_belate_ex.SubTypeId = 2;
  411. beLate_belate_ex.SubType = "早退";
  412. if (reissueCardNum >= 3)
  413. {
  414. day_deduction = 50.00M;
  415. }
  416. else {
  417. day_deduction = 0.00M;
  418. }
  419. early_deduction += day_deduction; //早退扣款 总计
  420. }
  421. else if (timelength >= 10 && timelength <= 60)
  422. {
  423. day_deduction = 50.00M;
  424. early_deduction += day_deduction; //早退扣款 总计
  425. beLate_belate_ex.SubTypeId = 2;
  426. beLate_belate_ex.SubType = "早退";
  427. }
  428. else if (timelength > 60 && timelength <= 180)
  429. {
  430. day_deduction = day_miner_unit * 6; //3小时
  431. absenteeism_deduction += day_deduction; //矿工半日
  432. }
  433. else
  434. {
  435. day_deduction = dailyWage;
  436. meal_deduction += 10.00M;
  437. absenteeism_deduction += day_deduction; //矿工一日
  438. }
  439. beLate_belate_ex.Deduction = day_deduction;
  440. ex_reissuecard_Items.Add(beLate_belate_ex);
  441. }
  442. else if (exception == 3) //缺卡
  443. {
  444. if (roots_ex.exception_infos.Count == 2)
  445. {
  446. day_deduction = dailyWage;
  447. meal_deduction += 10.00M;
  448. absenteeism_deduction += day_deduction;
  449. beLate_belate_ex.Reason = "上午-下午 缺卡/未打卡为旷工 一天";
  450. beLate_belate_ex.Deduction = day_deduction;
  451. ex_reissuecard_Items.Add(beLate_belate_ex);
  452. }
  453. else if (roots_ex.exception_infos.Count == 1)
  454. {
  455. if (earliest_time == lastest_time)
  456. {
  457. DateTime thisDt1 = Convert.ToDateTime(thisDtStr + " 12:00");
  458. //ex_ItemInfos
  459. Ex_Item zt_jq = new Ex_Item();
  460. zt_jq = ex_ItemInfos.Where(it => it.StartTimeDt.ToString("yyyy-MM-dd") == thisDtStr).FirstOrDefault();
  461. if (thisDt <= thisDt1) //旷工 下午
  462. {
  463. if (zt_jq != null) if (zt_jq.EndTimeDt == Convert.ToDateTime(thisDtStr + " 18:00")) continue; //排除已有假期的缺卡
  464. day_deduction = day_miner_unit * 9; //4.5小时
  465. meal_deduction += 10.00M;
  466. absenteeism_deduction += day_deduction; //矿工半日
  467. beLate_belate_ex.Reason = thisDtStr + " 下午(18:00)缺卡/未打卡视为下午旷工(4.5小时)";
  468. beLate_belate_ex.Deduction = day_deduction;
  469. ex_reissuecard_Items.Add(beLate_belate_ex);
  470. }
  471. else if (thisDt >= thisDt1) //旷工下午
  472. {
  473. if (zt_jq != null) if (zt_jq.EndTimeDt == Convert.ToDateTime(thisDtStr + " 09:00")) continue; //排除已有假期的缺卡
  474. day_deduction = day_miner_unit * 6; //3小时
  475. absenteeism_deduction += day_deduction; //矿工半日
  476. beLate_belate_ex.Reason = thisDtStr + " 上午(09:00)缺卡/未打卡视为上午旷工(3小时)";
  477. beLate_belate_ex.Deduction = day_deduction;
  478. ex_reissuecard_Items.Add(beLate_belate_ex);
  479. }
  480. else //矿工一日
  481. {
  482. day_deduction = dailyWage;
  483. meal_deduction += 10.00M;
  484. absenteeism_deduction += day_deduction;
  485. beLate_belate_ex.Reason = thisDtStr + " 上午(09:00)-下午(18:00) 缺卡/未打视为旷工一天(7.5小时)";
  486. beLate_belate_ex.Deduction = day_deduction;
  487. ex_reissuecard_Items.Add(beLate_belate_ex);
  488. }
  489. }
  490. }
  491. }
  492. else if (exception == 4) //旷工
  493. {
  494. if (timelength > 60 && timelength <= 180)
  495. {
  496. day_deduction = day_miner_unit * 6; //3小时
  497. beLate_belate_ex.Reason = thisDtStr + " 缺卡/未打视为旷工上午(3小时)";
  498. meal_deduction += 10.00M;
  499. absenteeism_deduction += day_deduction; //矿工半日
  500. }
  501. else
  502. {
  503. day_deduction = dailyWage;
  504. beLate_belate_ex.Reason = thisDtStr + " 上午(09:00)-下午(18:00) 缺卡/未打视为旷工一天(7.5小时)";
  505. meal_deduction += 10.00M;
  506. absenteeism_deduction += day_deduction; //矿工一日
  507. }
  508. beLate_belate_ex.Deduction = day_deduction;
  509. ex_reissuecard_Items.Add(beLate_belate_ex);
  510. }
  511. }
  512. }
  513. }
  514. }
  515. if (ex_reissuecard_Items.Count > 0)
  516. {
  517. ex_Items_dk.Ex_ItemInfo = ex_reissuecard_Items;
  518. ex_Items_dk.Ex_ItemInfo = ex_reissuecard_Items.OrderBy(it => it.SubTypeId).ThenBy(it => it.StartTimeDt).ToList();
  519. ex_Items.Add(ex_Items_dk);
  520. }
  521. #region 应发合计 实发合计 扣款合计(假勤扣款,其他扣款,社保扣款,公积金代扣,个税扣款)
  522. decimal mealTotal = meal_subsidy - meal_deduction; //餐补
  523. decimal salaryTotal = amountPayable + mealTotal; //应发合计
  524. //扣款合计 不含个税
  525. decimal eductionTotal = sickLeaveTotal + personalLeaveTotal + beLate_deduction + early_deduction + absenteeism_deduction + unprinted_deduction + other_deduction +
  526. pm_wsInfo.WithholdingInsurance + pm_wsInfo.ReservedFunds + pm_wsInfo.OtherDeductions;
  527. decimal actualReleaseTotal = salaryTotal - eductionTotal; //实发合计 * 不含个税
  528. #endregion
  529. #region 处理当月工资数据
  530. pm_wsInfo.YearMonth = thisYearMonth;
  531. pm_wsInfo.StartDate = startDt.ToString("yyyy-MM-dd");
  532. pm_wsInfo.EndDate = endDt.AddDays(-1).ToString("yyyy-MM-dd");
  533. pm_wsInfo.WorkDays = work_days; //当月应出勤天数
  534. //pm_wsInfo.RegularDays = regular_days; //当月正常出勤天数
  535. pm_wsInfo.SickLeave = sickLeaveTotal; //病假
  536. pm_wsInfo.SomethingFalse = personalLeaveTotal; //事假
  537. pm_wsInfo.LateTo = beLate_deduction; //迟到
  538. pm_wsInfo.LeaveEarly = early_deduction; //早退
  539. pm_wsInfo.Absenteeism = absenteeism_deduction; //旷工
  540. pm_wsInfo.NotPunch = unprinted_deduction; //未打卡
  541. pm_wsInfo.OtherDeductions = other_deduction; //其他
  542. pm_wsInfo.Ex_ItemsRemark = JsonConvert.SerializeObject(ex_Items); //
  543. pm_wsInfo.Mealsupplement = mealTotal; //餐补
  544. pm_wsInfo.Should = salaryTotal; //应发合计
  545. pm_wsInfo.TotalDeductions = eductionTotal; //扣款合计
  546. pm_wsInfo.TotalRealHair = actualReleaseTotal; //实发合计
  547. pm_wsInfo.AfterTax = actualReleaseTotal - pm_wsInfo.WithholdingTax; //税后工资
  548. pm_wsInfo.LastUpdateUserId = userId;
  549. pm_wsInfo.LastUpdateDt = DateTime.Now;
  550. pm_wsInfo.CreateUserId = userId;
  551. pm_wsInfo.CreateTime = DateTime.Now;
  552. pm_wsInfo.DeleteUserId = null;
  553. pm_wsInfo.DeleteTime = null;
  554. #endregion
  555. }
  556. }
  557. catch (Exception ex)
  558. {
  559. _result.Msg = ex.Message;
  560. return _result;
  561. }
  562. _result.Code = 0;
  563. _result.Data = pm_WageSheetDattaSources;
  564. return _result;
  565. }
  566. /// <summary>
  567. /// decimal 保留两位小数 不四舍五入
  568. /// </summary>
  569. /// <param name="number"></param>
  570. /// <returns></returns>
  571. private static decimal ConvertToDecimal(decimal number)
  572. {
  573. return Convert.ToDecimal(number.ToString("0.00"));
  574. }
  575. /// <summary>
  576. /// 获取请假类型
  577. /// </summary>
  578. /// <param name="template_id"></param>
  579. /// <returns></returns>
  580. public static async Task<List<VacationLeaveTypeView>> GetVacationLeaveTypes(string template_id)
  581. {
  582. List<VacationLeaveTypeView> vacationLeaveTypes = new List<VacationLeaveTypeView>();
  583. TemplateDetailView templateDetailView = new TemplateDetailView();
  584. templateDetailView = await _qiYeWeChatApiService.GetTemplateDetailAsync(template_id);
  585. if (templateDetailView.errcode != 0)
  586. {
  587. Serilog.Log.Error("【企业微信】【审批】【获取假勤类型的审批】【Msg】"+ templateDetailView.errmsg);
  588. return vacationLeaveTypes;
  589. }
  590. List<VacationItemInfo> VacationItemInfos = templateDetailView.vacation_list.item;
  591. foreach (var item in VacationItemInfos)
  592. {
  593. ValueItem valueInfo = item.name.Where(it => it.lang == "zh_CN").FirstOrDefault();
  594. if (valueInfo != null)
  595. {
  596. vacationLeaveTypes.Add(
  597. new VacationLeaveTypeView()
  598. {
  599. id = item.id,
  600. name = valueInfo.text
  601. });
  602. }
  603. }
  604. return vacationLeaveTypes;
  605. }
  606. /// <summary>
  607. /// 计算类型费用
  608. /// </summary>
  609. /// <param name="leaveType">
  610. /// 1年假;2事假;3病假;4调休假;5婚假;6产假;7陪产假;8其他;9丧假
  611. /// </param>
  612. /// <param name="date_Range_type">
  613. /// halfday 全天
  614. /// hour 小时
  615. /// </param>
  616. /// <param name="startTime"></param>
  617. /// <param name="endTime"></param>
  618. /// <param name="duration"></param>
  619. /// <param name="mealDeduction"></param>
  620. /// <param name="typeDeduction"></param>
  621. public static void CalculateTypeFee(int leaveType, string date_Range_type, string startTime, string endTime,decimal amountPayable,int work_days,
  622. decimal duration, out decimal mealDeduction, out decimal typeDeduction)
  623. {
  624. typeDeduction = 0;
  625. mealDeduction = 0;
  626. string am_starttime = "08:59";
  627. string am_endtime = "13:01";
  628. decimal personalkLeave_dailywage_day = ConvertToDecimal( amountPayable / work_days); //日薪 = 事假日薪 *计算方式:日平均工资 = 当月应发工资 /当月应出勤天数。
  629. //半小时单位
  630. decimal halfHour = Convert.ToDecimal(7.5) / Convert.ToDecimal(0.5);
  631. switch (leaveType)
  632. {
  633. case 1: //年假
  634. CalculateTypeFeeSub(date_Range_type, startTime, endTime, duration, out mealDeduction);
  635. break;
  636. case 2: //2事假
  637. // 事假日薪 *计算方式:日平均工资 = 当月应发工资 /当月应出勤天数。
  638. decimal personalkLeave_dailywage_halfhour = ConvertToDecimal( personalkLeave_dailywage_day / halfHour); //事假单位 0.5小时
  639. if (date_Range_type == "halfday")
  640. {
  641. mealDeduction = 10; //餐补扣款
  642. typeDeduction = personalkLeave_dailywage_day;
  643. }
  644. else if (date_Range_type == "hour")
  645. {
  646. decimal leave_halfHour = Convert.ToDecimal(duration) / Convert.ToDecimal(0.5);
  647. typeDeduction = personalkLeave_dailywage_halfhour * leave_halfHour;
  648. if (duration >= 3 && duration <= 7.5M) //单天请假三小时 && 请假时间在上午 则没有餐补
  649. {
  650. //处理开始时间
  651. if (startTime.CompareTo(am_starttime) > 0 && startTime.CompareTo(am_endtime) < 0)
  652. {
  653. //处理结束时间
  654. //if (endTime.CompareTo(am_starttime) > 0 && endTime.CompareTo(am_endtime) > 0)
  655. //{
  656. mealDeduction = 10; //餐补扣款
  657. //}
  658. }
  659. }
  660. else if (duration > 7.5M) //多天计算
  661. {
  662. decimal leave_halfHour1 = Convert.ToDecimal(duration) / Convert.ToDecimal(0.5);
  663. typeDeduction = personalkLeave_dailywage_halfhour * leave_halfHour1;
  664. decimal leaveDays = duration / 7.5M;
  665. if (leaveDays % 1 == 0)
  666. {
  667. mealDeduction = 10 * leaveDays; //餐补扣款
  668. }
  669. else
  670. {
  671. mealDeduction = 10 * Convert.ToInt32(leaveDays);
  672. //得到最后一天的请假时间 是否有餐补
  673. int lastHours = (Convert.ToDateTime(endTime) - Convert.ToDateTime("09:00")).Hours;
  674. if (lastHours >= 3)
  675. {
  676. //处理结束时间
  677. if (endTime.CompareTo(am_starttime) > 0 && endTime.CompareTo(am_endtime) < 0)
  678. {
  679. mealDeduction += 10; //餐补扣款
  680. }
  681. }
  682. }
  683. }
  684. }
  685. break;
  686. case 3: //3病假
  687. // 病假日薪 *计算方式:日平均工资 = 成都市最低工资标准的80% /当月应出勤天数。 短期病假=当月15天内
  688. decimal chengDuMinimumWage_halrHour = ConvertToDecimal( _chengDuMinimumWage / work_days) / halfHour;
  689. decimal sickLeave_dailywage_halfhour_deduction = personalkLeave_dailywage_day - chengDuMinimumWage_halrHour; //病假单位 0.5小时 扣款金额
  690. if (date_Range_type == "halfday")
  691. {
  692. mealDeduction = 10; //餐补扣款
  693. typeDeduction = sickLeave_dailywage_halfhour_deduction * halfHour;
  694. }
  695. else if (date_Range_type == "hour")
  696. {
  697. decimal sickLeave_halfHour = duration / 0.5M;
  698. typeDeduction = sickLeave_dailywage_halfhour_deduction *sickLeave_halfHour ;
  699. if (duration >= 3 && duration <= 7.5M) //单天请假三小时 && 请假时间在上午 则没有餐补
  700. {
  701. //处理开始时间
  702. if (startTime.CompareTo(am_starttime) > 0 && startTime.CompareTo(am_endtime) < 0)
  703. {
  704. //处理结束时间
  705. if (endTime.CompareTo(am_starttime) > 0 && endTime.CompareTo(am_endtime) < 0)
  706. {
  707. mealDeduction = 10; //餐补扣款
  708. }
  709. }
  710. }
  711. else if (duration > 7.5M) //多天计算
  712. {
  713. decimal sickLeave_halfHour1 = duration / 0.5M;
  714. typeDeduction = sickLeave_dailywage_halfhour_deduction * sickLeave_halfHour1;
  715. decimal leaveDays = Convert.ToDecimal(duration / 7.5M);
  716. if (leaveDays % 1 == 0)
  717. {
  718. mealDeduction = 10 * leaveDays; //餐补扣款
  719. }
  720. else
  721. {
  722. mealDeduction = 10 * Convert.ToInt32(leaveDays);
  723. //得到最后一天的请假时间 是否有餐补
  724. int lastHours = (Convert.ToDateTime(endTime) - Convert.ToDateTime("09:00")).Hours;
  725. if (lastHours >= 3)
  726. {
  727. //处理结束时间
  728. if (endTime.CompareTo(am_starttime) > 0 && endTime.CompareTo(am_endtime) < 0)
  729. {
  730. mealDeduction += 10; //餐补扣款
  731. }
  732. }
  733. }
  734. }
  735. }
  736. break;
  737. case 4: //4调休假
  738. CalculateTypeFeeSub(date_Range_type, startTime, endTime, duration, out mealDeduction);
  739. break;
  740. case 5: //5婚假
  741. CalculateTypeFeeSub(date_Range_type, startTime, endTime, duration, out mealDeduction);
  742. break;
  743. case 6: //6产假
  744. CalculateTypeFeeSub(date_Range_type, startTime, endTime, duration, out mealDeduction);
  745. break;
  746. case 7: //7陪产假
  747. CalculateTypeFeeSub(date_Range_type, startTime, endTime, duration, out mealDeduction);
  748. break;
  749. case 8: //8其他
  750. CalculateTypeFeeSub(date_Range_type, startTime, endTime, duration, out mealDeduction);
  751. break;
  752. case 9: //9丧假
  753. CalculateTypeFeeSub(date_Range_type, startTime, endTime, duration, out mealDeduction);
  754. break;
  755. }
  756. }
  757. /// <summary>
  758. /// 计算类型费用
  759. /// </summary>
  760. /// <param name="date_Range_type">
  761. /// halfday 全天
  762. /// hour 小时
  763. /// </param>
  764. /// <param name="startTime"></param>
  765. /// <param name="endTime"></param>
  766. /// <param name="duration"></param>
  767. /// <param name="mealDeduction"></param>
  768. public static void CalculateTypeFeeSub(string date_Range_type, string startTime, string endTime, decimal duration, out decimal mealDeduction)
  769. {
  770. mealDeduction = 0;
  771. string am_starttime = "08:59";
  772. string am_endtime = "13:01";
  773. if (date_Range_type == "halfday")
  774. {
  775. mealDeduction = 10; //餐补扣款
  776. }
  777. else if (date_Range_type == "hour")
  778. {
  779. if (duration >= 3 && duration < 7) //单天请假三小时 && 请假时间在上午 则没有餐补
  780. {
  781. //处理开始时间
  782. if (startTime.CompareTo(am_starttime) > 0 && startTime.CompareTo(am_endtime) < 0)
  783. {
  784. //处理结束时间
  785. if (endTime.CompareTo(am_starttime) > 0 && endTime.CompareTo(am_endtime) < 0)
  786. {
  787. mealDeduction = 10; //餐补扣款
  788. }
  789. }
  790. }
  791. else if (duration >= 7 && duration <= 7.50M )
  792. {
  793. mealDeduction = 10; //餐补扣款
  794. }
  795. else if (duration >= 7.50M) //多天计算
  796. {
  797. decimal leaveDays = Convert.ToDecimal(duration / 7.50M);
  798. if (leaveDays % 1 == 0)
  799. {
  800. mealDeduction = 10 * leaveDays; //餐补扣款
  801. }
  802. else
  803. {
  804. mealDeduction = 10 * Convert.ToInt32(leaveDays);
  805. //得到最后一天的请假时间 是否有餐补
  806. int lastHours = (Convert.ToDateTime(endTime) - Convert.ToDateTime("09:00")).Hours;
  807. if (lastHours >= 3)
  808. {
  809. //处理结束时间
  810. if (endTime.CompareTo(am_starttime) > 0 && endTime.CompareTo(am_endtime) < 0)
  811. {
  812. mealDeduction += 10; //餐补扣款
  813. }
  814. }
  815. }
  816. }
  817. }
  818. }
  819. /// <summary>
  820. /// 获取打卡补卡类型
  821. /// </summary>
  822. /// <param name="template_id"></param>
  823. /// <returns></returns>
  824. public static async Task<List<VacationLeaveTypeView>> GetVacationReissueCardTypes(string template_id)
  825. {
  826. List<VacationLeaveTypeView> vacationLeaveTypes = new List<VacationLeaveTypeView>();
  827. TemplateDetailView templateDetailView = new TemplateDetailView();
  828. templateDetailView = await _qiYeWeChatApiService.GetTemplateDetailAsync(template_id);
  829. if (templateDetailView.errcode != 0)
  830. {
  831. return vacationLeaveTypes;
  832. }
  833. List<VacationItemInfo> VacationItemInfos = templateDetailView.vacation_list.item;
  834. foreach (var item in VacationItemInfos)
  835. {
  836. ValueItem valueInfo = item.name.Where(it => it.lang == "zh_CN").FirstOrDefault();
  837. if (valueInfo != null)
  838. {
  839. vacationLeaveTypes.Add(
  840. new VacationLeaveTypeView()
  841. {
  842. id = item.id,
  843. name = valueInfo.text
  844. });
  845. }
  846. }
  847. return vacationLeaveTypes;
  848. }
  849. /// <summary>
  850. /// 打卡数据
  851. /// 假勤数据 统计
  852. /// </summary>
  853. /// <param name="datas">数据源</param>
  854. /// <param name="type">
  855. /// 1-请假;2-补卡;3-出差;4-外出;100-外勤;
  856. /// </param>
  857. /// <param name="subTypeName">
  858. /// 年假 事假 病假 调休假 婚嫁 产假 陪产假 丧假 补卡次数 出差 外出数 外勤 其他
  859. /// </param>
  860. /// <returns></returns>
  861. private static int Fallibilitydispose(List<Sp_Item> datas, int type, string? subTypeName)
  862. {
  863. int num = 0;
  864. Sp_Item _Info = datas.Where(it => it.type == type && it.name == subTypeName).FirstOrDefault();
  865. if (_Info != null) { num = _Info.count; }
  866. return num;
  867. }
  868. /// <summary>
  869. /// 打卡数据
  870. /// 异常数据 统计
  871. /// </summary>
  872. /// <returns></returns>
  873. private static int ExceptionStatistics(List<Exception_Info> datas, int type)
  874. {
  875. int num = 0;
  876. Exception_Info _Info = datas.Where(it => it.exception == type).FirstOrDefault();
  877. if (_Info != null) { num = _Info.count; }
  878. return num;
  879. }
  880. /// <summary>
  881. /// 获取时间段内除周末 节假日外的 工作日
  882. /// </summary>
  883. /// <param name="startDt"></param>
  884. /// <param name="endDt"></param>
  885. /// <returns></returns>
  886. public static int GetWorkDays(DateTime startDt,DateTime endDt)
  887. {
  888. //{
  889. // "userId": 0,
  890. // "yearMonth": "2023-09",
  891. // "startDt": "2023-08-28",
  892. // "endDt": "2023-09-27"
  893. // }
  894. string startYear = startDt.ToString("yyyy");
  895. string endYear = endDt.ToString("yyyy");
  896. var holidays = AppSettingsHelper.Get<HoliDaysDataSourceView>("HoliDayDataSource");
  897. List<HoliDaysDataSourceView> holiDatas = new List<HoliDaysDataSourceView>();
  898. if (startYear.Equals(endYear))
  899. {
  900. holiDatas.Add(holidays.Where(it => it.Year == startYear).FirstOrDefault());
  901. }
  902. else
  903. {
  904. holiDatas.Add(holidays.Where(it => it.Year == startYear).FirstOrDefault());
  905. holiDatas.Add(holidays.Where(it => it.Year == endYear).FirstOrDefault());
  906. }
  907. int _totalDays = (int)(endDt - startDt).TotalDays;
  908. List<HolidaysInfo> _holidays = new List<HolidaysInfo>();
  909. List<HolidaysInfo> _weekdys = new List<HolidaysInfo>();
  910. List<HolidaysInfo> _workdays = new List<HolidaysInfo>();
  911. string[] Day = new string[] { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
  912. for (int i = 0; i < _totalDays; i++)
  913. {
  914. string thisYear = startDt.ToString("yyyy");
  915. string thisDt = startDt.ToString("MM-dd");
  916. string thisYMD = startDt.ToString("yyyy-MM-dd");
  917. string thisWeek = Day[Convert.ToInt32(startDt.DayOfWeek.ToString("d"))].ToString();
  918. HoliDaysDataSourceView holiDaysData = new HoliDaysDataSourceView();
  919. holiDaysData = holiDatas.Where(it => it.Year == thisYear).FirstOrDefault();
  920. //周末
  921. if (thisWeek.Equals("星期六") || thisWeek.Equals("星期日"))
  922. {
  923. HolidaysInfo holidaysInfo = new HolidaysInfo();
  924. holidaysInfo = holiDaysData.Holidays.Where(it => it.HoliDate == thisDt).FirstOrDefault();
  925. if (holidaysInfo != null)
  926. {
  927. if (holidaysInfo.HoliName.Equals("工作日"))
  928. {
  929. _workdays.Add(new HolidaysInfo { HoliDate = thisYMD, HoliName = Day[Convert.ToInt32(startDt.DayOfWeek.ToString("d"))].ToString() });
  930. startDt = startDt.AddDays(1);
  931. continue;
  932. }
  933. }
  934. _weekdys.Add(new HolidaysInfo { HoliDate = thisYMD, HoliName = thisWeek });
  935. startDt = startDt.AddDays(1);
  936. continue;
  937. }
  938. //节假日
  939. if (holiDaysData != null)
  940. {
  941. HolidaysInfo holidaysInfo = new HolidaysInfo();
  942. holidaysInfo = holiDaysData.Holidays.Where(it => it.HoliDate == thisDt).FirstOrDefault();
  943. if (holidaysInfo != null)
  944. {
  945. _holidays.Add(new HolidaysInfo { HoliDate = thisYMD, HoliName = holidaysInfo.HoliName });
  946. startDt = startDt.AddDays(1);
  947. continue;
  948. }
  949. }
  950. //工作日
  951. _workdays.Add(new HolidaysInfo { HoliDate = thisYMD, HoliName = Day[Convert.ToInt32(startDt.DayOfWeek.ToString("d"))].ToString() });
  952. startDt = startDt.AddDays(1);
  953. }
  954. return _workdays.Count();
  955. }
  956. }
  957. }