123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597 |
- using Autofac.Diagnostics;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.AspNetCore.Mvc.RazorPages;
- using OASystem.API.OAMethodLib.QiYeWeChatAPI;
- using OASystem.Domain;
- using OASystem.Domain.Dtos.PersonnelModule;
- using OASystem.Domain.Dtos.QiYeWeChat;
- using OASystem.Domain.Entities.PersonnelModule;
- using OASystem.Domain.ViewModels.JuHeExchangeRate;
- using OASystem.Domain.ViewModels.PersonnelModule;
- using OASystem.Domain.ViewModels.QiYeWeChat;
- using OASystem.Infrastructure.Repositories.PersonnelModule;
- using SqlSugar;
- using StackExchange.Redis;
- using System.Collections.Generic;
- using System.Globalization;
- namespace OASystem.API.Controllers
- {
- /// <summary>
- /// 人事模块
- /// </summary>
- [Route("api/[controller]/[action]")]
- public class PersonnelModuleController : ControllerBase
- {
- private Result _result;
- private readonly IMapper _mapper;
- private readonly decimal _chengDuMinimumWage = 2100.00M;
- private readonly IQiYeWeChatApiService _qiYeWeChatApiService;
- private readonly WageSheetRepository _wageSheetRep;
- private readonly UsersRepository _usersRep;
- /// <summary>
- /// 初始化
- /// </summary>
- /// <param name="qiYeWeChatApiService"></param>
- /// <param name="wageSheetRep"></param>
- /// <param name="usersRep"></param>
- /// <param name="mapper"></param>
- public PersonnelModuleController(IQiYeWeChatApiService qiYeWeChatApiService,WageSheetRepository wageSheetRep, UsersRepository usersRep, IMapper mapper)
- {
- _mapper = mapper;
- _usersRep = usersRep;
- _qiYeWeChatApiService = qiYeWeChatApiService;
- _wageSheetRep = wageSheetRep;
- _result = new Result();
- }
- #region 工资表单
- /// <summary>
- /// 获取工资表单
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> GetWageSheetList(WageSheetListDto dto)
- {
- //参数处理
- string ymFormat = "yyyy-MM";
- DateTime yearMonthDt;
- bool yearMonthDttIsValid = DateTime.TryParseExact(dto.YearMonth, ymFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out yearMonthDt);
- if (!yearMonthDttIsValid)
- {
- _result.Msg = "年月格式错误!正确时间格式:yyyy-MM ";
- return Ok(JsonView(false, _result.Msg));
- }
- //获取月工资数据
- string yearMonth = yearMonthDt.ToString("yyyy-MM");
- string startDt = yearMonthDt.AddDays(-1).ToString("yyyy-MM") + "-28",
- endDt = yearMonth + "-27";
- //应发合计 = 基本工资 +绩效工资 + 岗位津贴 + 员工的岗位津贴 + 服装洗理补贴 + 通讯补贴 + 交通补贴 + 保密费 + 操作奖金+ 其他补贴 + 部门集体团建费 + 代扣保险 + 代扣公积金 + 餐补 - 个税
- //事假 病假 合计
- //扣款合计 = 迟到 + 早退 + 矿工 + 未打卡 + 其他扣款
- _result = await _wageSheetRep.Get_WageSheet_ListByYearMonthAsync(yearMonth);
- if (_result.Code != 0)
- {
- return Ok(JsonView(false, _result.Msg));
- }
-
- if (dto.PortType == 1)
- {
- }
- else if (dto.PortType == 2)
- { }
- else if (dto.PortType == 3)
- { }
- else
- {
- return Ok(JsonView(false, "请选择正确的端口参数"));
- }
- return Ok(JsonView(true, _result.Msg, _result.Data));
- }
- /// <summary>
- /// 获取工资 详情
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> GetWageSheetById(WageSheetInfoDto dto)
- {
- if (dto.PortType == 1)
- {
- _result = await _wageSheetRep.Get_WageSheet_InfoByIdAsync(dto.Id);
- if (_result.Code != 0)
- {
- return Ok(JsonView(false, _result.Msg));
- }
- }
- else if (dto.PortType == 2)
- { }
- else if (dto.PortType == 3)
- { }
- else
- {
- return Ok(JsonView(false, "请选择正确的端口参数"));
- }
- return Ok(JsonView(true, _result.Msg, _result.Data));
- }
- /// <summary>
- /// 人事模块 工资表单 添加 Or 修改
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostWageSheetAddOrEdit(WageAddOrEditDto dto)
- {
- try
- {
- _result = await _wageSheetRep.Post_WageSheet_AddOrEditAsync(dto);
- if (_result.Code != 0)
- {
- return Ok(JsonView(false, _result.Msg));
- }
- }
- catch (Exception ex)
- {
- return Ok(JsonView(false, ex.Message));
- }
-
- return Ok(JsonView(true, _result.Msg, _result.Data));
- }
- /// <summary>
- /// 计算工资
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> SalaryCalculatorAsync(SalaryCalculatorDto dto)
- {
- Result result = new Result();
- //参数处理
- string ymFormat = "yyyy-MM";
- DateTime yearMonthDt;
- bool yearMonthDttIsValid = DateTime.TryParseExact(dto.yearMonth, ymFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out yearMonthDt);
- if (!yearMonthDttIsValid)
- {
- return Ok(JsonView(false, "年月格式错误!正确时间格式:yyyy-MM "));
- }
- string thisYearMonth = dto.yearMonth;
- string preYearMonth = yearMonthDt.AddMonths(-1).ToString("yyyy-MM");
- //本月工资是否有数据 有数据则不计算
- result = await _wageSheetRep.Get_WageSheet_ListByYearMonthAsync(thisYearMonth);
- if (result.Code == 0 )
- {
- return Ok(JsonView(false, thisYearMonth + " 工资数据已存在,若无人员工资请手动添加!"));
- }
- //获取上个月工资信息
- DateTime startDt = Convert.ToDateTime(yearMonthDt.AddMonths(-1).ToString("yyyy-MM") + "-28");
- DateTime endDt = Convert.ToDateTime(yearMonthDt.ToString("yyyy-MM") + "-27");
- string preWageSheetSql = string.Format(@"Select sys_u1.CnName Name,pm_ws.* From Pm_WageSheet pm_ws
- Left Join Sys_Users sys_u1 On pm_ws.UserId = sys_u1.Id Where pm_ws.IsDel = 0 And YearMonth ='{0}'", preYearMonth);
- List<WageSheetInfos> preWageSheetItems = await _wageSheetRep._sqlSugar.SqlQueryable<WageSheetInfos>(preWageSheetSql).ToListAsync();
- if (preWageSheetItems.Count <= 0)
- {
- return Ok(JsonView(false, preYearMonth + " 工资数据不存在,请手动添加!"));
- }
-
- //获取OA系统内所有用户
- var nameData = await _usersRep.GetUserNameList(1);
- List<UserNameView> userNames = nameData.Data;
- //获取所有打卡数据
- CheckInView checkIn = await _qiYeWeChatApiService.GetCheckin_MonthDataAsync(startDt, endDt); //时间段内所有 打卡数据
- if (checkIn.errcode != 0)
- {
- return Ok(JsonView(false, checkIn.errmsg));
- }
- List<Data> checkInDatas = checkIn.datas;
- //获取所有打卡补卡,审批 数据
- DateTime sp_startDt = startDt.AddDays(-10);
- DateTime sp_centerDt = sp_startDt.AddDays(30);
- DateTime sp_endDt = endDt.AddDays(10);
- List<Sp_Info> sp_Infos = new List<Sp_Info>();
- string redisName = "ApprovalData_" + sp_startDt.Year + "_" + sp_startDt.Month;
- string sp_InfosString = await RedisRepository.RedisFactory
- .CreateRedisRepository()
- .StringGetAsync<string>(redisName);//string 取
- if (string.IsNullOrEmpty(sp_InfosString))
- {
- ApprovalDataView approvalData_1 = await _qiYeWeChatApiService.GetApprovalDataAsync(sp_startDt, sp_centerDt); //时间段内所有 审批数据
- ApprovalDataView approvalData_2 = await _qiYeWeChatApiService.GetApprovalDataAsync(sp_centerDt, sp_endDt); //时间段内所有 审批数据
- if (approvalData_1.errcode != 0)
- {
- result.Msg = "企业微信 获取时间段内审批 Msg:" + approvalData_1.errmsg;
- return Ok(JsonView(false, "企业微信 获取时间段内审批 Msg:" + approvalData_1.errmsg));
- }
- sp_Infos.AddRange(approvalData_1.data);
- if (approvalData_2.errcode != 0)
- {
- return Ok(JsonView(false, "企业微信 获取时间段内审批 Msg:" + approvalData_2.errmsg));
- }
- sp_Infos.AddRange(approvalData_2.data);
- TimeSpan ts = DateTime.Now.AddMinutes(60) - DateTime.Now; //设置redis 过期时间 60分钟
- await RedisRepository
- .RedisFactory
- .CreateRedisRepository()
- .StringSetAsync<string>(redisName, JsonConvert.SerializeObject(sp_Infos), ts);//string 存
- }
- else
- {
- sp_Infos = JsonConvert.DeserializeObject<List<Sp_Info>>(sp_InfosString);
- }
- // 筛选 时间段内(请假时间,补卡时间) /审批类型(打卡补卡,请假)/审核通过的数据
- List<Sp_Info> sp_leave_InfosData = sp_Infos.Where(it => it.sp_status == 2 && it.spname == "请假" && it.leave.start_time_dt >= startDt && it.leave.start_time_dt <= endDt).ToList(); //请假
- List<Sp_Info> sp_reissuecard_InfosData = sp_Infos.Where(it => it.sp_status == 2 && it.spname == "打卡补卡" && it.comm.FillingDt >= startDt && it.comm.FillingDt <= endDt).ToList(); //补卡
-
- List<Pm_WageSheet> wageSheets = new List<Pm_WageSheet>();
- foreach (var item in preWageSheetItems)
- {
- Pm_WageSheet pm_wsInfo = new Pm_WageSheet();
- pm_wsInfo = _mapper.Map<Pm_WageSheet>(item);
- //补贴 金额
- decimal meal_subsidy = 0.00M; // 午餐(午餐10元/天) 补贴 * 计算方式:单日上午请假时长(小时)大于或者等于三小时 没有餐补
- //事假 病假 总金额
- decimal personalLeaveTotal = 0.00M, // 事假 日薪 *计算方式:日平均工资 = 月工资/当月应出勤天数。
- sickLeaveTotal = 0.00M; // 病假 日薪 *计算方式:日平均工资 = 成都市最低工资标准的80%/当月应出勤天数。 短期病假=当月15天内
- //扣款金额
- decimal beLate_deduction = 0.00M, // 迟到 扣款金额 *计算方式:
- // 一个自然月内,不足 10 分钟的迟到/早退,不超过 2 次的部分,不做处罚;3 次及以上,按50元 / 次处罚;
- // 超过 10 分钟(含 10 分钟),不足 60 分钟的迟到/早退,按 50 元/次处罚;
- // 超过 60 分钟(含 60 分钟),不足 3 小时的迟到/早退,且无请假者,按旷工半日处理;超过3 小时的迟到 / 早退,且无请假者,按旷工一日处理。
- early_deduction = 0.00M, // 早退 扣款金额
- absenteeism_deduction = 0.00M, // 旷工 扣款金额 *计算方式:旷工扣发当日工资
- unprinted_deduction = 0.00M, // 未打卡 扣款金额 *计算方式:
- // 试用期员工每月有 2 次 补卡机会,超过 2 次不足 5 次的部分,按 10 元 / 次处罚,5 次及以上的漏卡,按 50 元 / 次处罚;
- // 正式员工每月 3 次以内的补卡,按 10 元 / 次处罚,3 次及以上的漏卡,按 50 元 / 次处罚。
- sickLeave_deduction = 0.00M,
- other_deduction = 0.00M; // 其他 扣款金额
- decimal meal_deduction = 0.00M; // 餐补 扣款金额
- decimal reissuecard_deduction = 0.00M; // 补卡 扣款金额
- //打卡数据
- Data? checkInData = checkInDatas.Where(it => it.base_info.name == item.Name).FirstOrDefault();
- if (checkInData == null) { continue; }
- string acctid = checkInData.base_info.acctid; //用户Id
-
- //当月总计数据
- Summary_Info? summary_Info = checkInData.summary_info;
- if (summary_Info == null ) { continue; }
- int work_days = summary_Info.work_days; //应出勤天数
- int regular_days = summary_Info.regular_days; //正常出勤天数
- meal_subsidy = work_days * 10; //应发放餐补
- #region 计算日工资 正常日薪 事假日薪 病假日薪
- //月 - 应发工资
- decimal amountPayable = pm_wsInfo.Basic + pm_wsInfo.Floats + pm_wsInfo.PostAllowance + pm_wsInfo.GarmentWashSubsidies + pm_wsInfo.CommunicationSubsidies +
- pm_wsInfo.TrafficSubsidies + pm_wsInfo.InformationSecurityFee + pm_wsInfo.OperationBonus + pm_wsInfo.SpecialAllowance + pm_wsInfo.OtherSubsidies + pm_wsInfo.GroupCost;
- // 日薪 = 事假日薪 *计算方式:日平均工资 = 月工资/当月应出勤天数。
- decimal dailyWage = amountPayable / work_days;
- // 病假日薪 *计算方式:日平均工资 = 成都市最低工资标准的80%/当月应出勤天数。 短期病假=当月15天内
- decimal sickLeave_dailywage = _chengDuMinimumWage / work_days;
- //病假 一天扣款
- sickLeave_deduction = dailyWage - sickLeave_dailywage;
- #endregion
- int annualLeaveNum = 0, //年假
- personalLeaveNum = 0, //事假
- sickLeaveNum = 0, //病假
- lieuLeaveNum = 0, //调休假
- marriageLeaveNum = 0, //婚嫁
- maternityLeaveNum = 0, //产假
- paternityLeaveNum = 0, //陪产假
- funeralLeaveNum = 0, //丧假
- reissueCardNum = 0, //补卡 次数
- evectionNum = 0, //出差 次数
- outIngNum = 0, //外出 次数
- outWorkNum = 0, //外勤 次数
- otherLeaveNum = 0; //其他
- #region 假勤 处理 1-请假;2-补卡;3-出差;4-外出;100-外勤;
- List<Sp_Item>? sp_items = checkInData.sp_items.Where(it => it.count != 0).ToList();
- if (sp_items != null && sp_items.Count > 0)
- {
- annualLeaveNum = Fallibilitydispose(sp_items, 1, "年假");
- personalLeaveNum = Fallibilitydispose(sp_items, 1, "事假");
- sickLeaveNum = Fallibilitydispose(sp_items, 1, "病假");
- lieuLeaveNum = Fallibilitydispose(sp_items, 1, "调休假");
- marriageLeaveNum = Fallibilitydispose(sp_items, 1, "婚嫁");
- maternityLeaveNum = Fallibilitydispose(sp_items, 1, "产假");
- paternityLeaveNum = Fallibilitydispose(sp_items, 1, "陪产假");
- funeralLeaveNum = Fallibilitydispose(sp_items, 1, "丧假");
- otherLeaveNum = Fallibilitydispose(sp_items, 1, "其他");
- reissueCardNum = Fallibilitydispose(sp_items, 2, "补卡次数");
- evectionNum = Fallibilitydispose(sp_items, 3, "出差");
- outIngNum = Fallibilitydispose(sp_items, 4, "外出");
- outWorkNum = Fallibilitydispose(sp_items, 3, "外勤");
- }
- #region 请假类型金额/餐补 处理
- List<Sp_Info> sp_leave_item_infosData = sp_leave_InfosData.Where(it => it.spname == "请假" && it.apply_name == item.Name).ToList();
- foreach (Sp_Info sp_item in sp_leave_item_infosData)
- {
- Leave? sp_leave = sp_item.leave;
- if (sp_leave != null)
- {
- //leave_type 1年假;2事假;3病假;4调休假;5婚假;6产假;7陪产假;8其他
- switch (sp_leave.leave_type)
- {
- case 1: //年假
- if (sp_leave.timeunit == 0) //半天
- {
- meal_deduction += 10;
- }
- else if (sp_leave.timeunit == 1) //小时
- {
- if (sp_leave.duration >= 3)
- {
- meal_deduction += 10;
- }
- }
- break;
- case 2: //事假 需调整
- if (sp_leave.timeunit == 0) //半天
- {
- meal_deduction += 10;
- personalLeaveTotal += dailyWage / 2;
- }
- else if (sp_leave.timeunit == 1) //小时
- {
- if (sp_leave.duration >= 3)
- {
- meal_deduction += 10;
- personalLeaveTotal += dailyWage;
- }
- }
- break;
- case 3: //病假 需调整
- if (sp_leave.timeunit == 0) //半天
- {
- meal_deduction += 10;
- sickLeaveTotal += sickLeave_deduction / 2;
- }
- else if (sp_leave.timeunit == 1) //小时
- {
- if (sp_leave.duration >= 3) //7.5小时 一天
- {
- meal_deduction += 10;
- sickLeaveTotal += sickLeave_deduction;
- }
- }
- break;
- case 4: //调休假
- if (sp_leave.timeunit == 0) //半天
- {
- meal_deduction += 10;
- }
- else if (sp_leave.timeunit == 1) //小时
- {
- if (sp_leave.duration >= 3) //7.5小时 一天
- {
- meal_deduction += 10;
- }
- }
- break;
- case 5: //婚假
- if (sp_leave.timeunit == 0) //半天
- {
- meal_deduction += 10;
- }
- else if (sp_leave.timeunit == 1) //小时
- {
- if (sp_leave.duration >= 3) //7.5小时 一天
- {
- meal_deduction += 10;
- }
- }
- break;
- case 6: //产假
- if (sp_leave.timeunit == 0) //半天
- {
- meal_deduction += 10;
- }
- else if (sp_leave.timeunit == 1) //小时
- {
- if (sp_leave.duration >= 3) //7.5小时 一天
- {
- meal_deduction += 10;
- }
- }
- break;
- case 7: //陪产假
- if (sp_leave.timeunit == 0) //半天
- {
- meal_deduction += 10;
- }
- else if (sp_leave.timeunit == 1) //小时
- {
- if (sp_leave.duration >= 3) //7.5小时 一天
- {
- meal_deduction += 10;
- }
- }
- break;
- default:
- break;
- }
- }
- }
- #endregion
- #region 补卡 处理
- if (reissueCardNum == 3)
- {
- reissuecard_deduction += 10;
- }
- else if (reissueCardNum >= 4)
- {
- reissuecard_deduction += 50;
- }
- #endregion
- #endregion
- //打卡异常处理 统计 1-迟到;2-早退;3-缺卡;4-旷工;5-地点异常;6-设备异常;
- int beLateNum = 0, // 1-迟到;
- leaveEarlyNum = 0, // 2-早退;
- dummyDeckNum = 0, // 3-缺卡;
- minerNum = 0, // 4-旷工;
- locationAnomalyNum = 0, // 5-地点异常;
- unitExNum = 0; // 6-设备异常;
- if (summary_Info.except_days > 0)
- {
- List<Exception_Info>? ex_infos = checkInData.exception_infos;
- if (ex_infos != null && ex_infos.Count >= 0)
- {
- beLateNum = ExceptionStatistics(ex_infos, 1);
- leaveEarlyNum = ExceptionStatistics(ex_infos, 2);
- dummyDeckNum = ExceptionStatistics(ex_infos, 3);
- minerNum = ExceptionStatistics(ex_infos, 4);
- locationAnomalyNum = ExceptionStatistics(ex_infos, 5);
- unitExNum = ExceptionStatistics(ex_infos, 6);
- }
- }
- #region 处理当月工资数据
- pm_wsInfo.YearMonth = thisYearMonth;
- pm_wsInfo.StartDate = startDt.ToString("yyyy-MM-dd");
- pm_wsInfo.EndDate = endDt.ToString("yyyy-MM-dd");
- pm_wsInfo.SickLeave = sickLeaveTotal; //病假
- pm_wsInfo.SomethingFalse = personalLeaveTotal; //事假
- pm_wsInfo.LateTo = beLate_deduction; //迟到
- pm_wsInfo.LeaveEarly = early_deduction; //早退
- pm_wsInfo.Absenteeism = absenteeism_deduction; //旷工
- pm_wsInfo.NotPunch = unprinted_deduction; //未打卡
- pm_wsInfo.OtherDeductions = other_deduction; //其他
- pm_wsInfo.Mealsupplement = meal_subsidy - meal_deduction; //餐补
-
- decimal salaryTotal = amountPayable; //应发合计
- //decimal eductionTotal = ;
- decimal actualReleaseTotal = 0.00M; //实发合计
- pm_wsInfo.LastUpdateUserId = dto.UserId;
- pm_wsInfo.LastUpdateDt = DateTime.Now;
- pm_wsInfo.CreateUserId = dto.UserId;
- pm_wsInfo.CreateTime = DateTime.Now;
- #endregion
- wageSheets.Add(pm_wsInfo);
- }
-
-
- return Ok(JsonView(true,"操作成功!", wageSheets));
- }
- /// <summary>
- /// 打卡数据
- /// 假勤数据 统计
- /// </summary>
- /// <param name="datas">数据源</param>
- /// <param name="type">
- /// 1-请假;2-补卡;3-出差;4-外出;100-外勤;
- /// </param>
- /// <param name="subTypeName">
- /// 年假 事假 病假 调休假 婚嫁 产假 陪产假 丧假 补卡次数 出差 外出数 外勤 其他
- /// </param>
- /// <returns></returns>
- private int Fallibilitydispose(List<Sp_Item> datas, int type,string? subTypeName)
- {
- int num = 0;
- Sp_Item _Info = datas.Where(it => it.type == type && it.name == subTypeName).FirstOrDefault();
- if (_Info != null) { num = _Info.count; }
- return num;
- }
- /// <summary>
- /// 打卡数据
- /// 异常数据 统计
- /// </summary>
- /// <returns></returns>
- private int ExceptionStatistics(List<Exception_Info> datas,int type)
- {
- int num = 0;
- Exception_Info _Info = datas.Where(it => it.exception == type).FirstOrDefault();
- if (_Info != null) { num = _Info.count; }
- return num;
- }
- #endregion
- }
- }
|