PersonnelModuleController.cs 102 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438
  1. using Aspose.Cells;
  2. using FluentValidation;
  3. using Microsoft.AspNetCore.SignalR;
  4. using OASystem.API.OAMethodLib;
  5. using OASystem.API.OAMethodLib.Hub.HubClients;
  6. using OASystem.API.OAMethodLib.Hub.Hubs;
  7. using OASystem.API.OAMethodLib.QiYeWeChatAPI;
  8. using OASystem.API.OAMethodLib.Quartz.Business;
  9. using OASystem.Domain.Dtos.Groups;
  10. using OASystem.Domain.Dtos.PersonnelModule;
  11. using OASystem.Domain.Entities.PersonnelModule;
  12. using OASystem.Domain.ViewModels.PersonnelModule;
  13. using OASystem.Domain.ViewModels.QiYeWeChat;
  14. using OASystem.Infrastructure.Repositories.PersonnelModule;
  15. using System.Collections;
  16. using System.Data;
  17. using System.Diagnostics;
  18. using System.Globalization;
  19. using static OASystem.API.OAMethodLib.JWTHelper;
  20. namespace OASystem.API.Controllers
  21. {
  22. /// <summary>
  23. /// 人事模块
  24. /// </summary>
  25. [Route("api/[controller]/[action]")]
  26. public class PersonnelModuleController : ControllerBase
  27. {
  28. private Result _result;
  29. private readonly IMapper _mapper;
  30. private readonly decimal _chengDuMinimumWage = 2100.00M;
  31. private readonly IQiYeWeChatApiService _qiYeWeChatApiService;
  32. private readonly WageSheetRepository _wageSheetRep;
  33. private readonly UsersRepository _usersRep;
  34. private readonly TaskAllocationRepository _taskAllocationRep;
  35. private readonly SqlSugarClient _sqlSugar;
  36. private readonly IHubContext<ChatHub, IChatClient> _hubContext;
  37. private readonly GoodsRepository _goodsRep;
  38. private string url, path;
  39. /// <summary>
  40. /// 初始化
  41. /// </summary>
  42. /// <param name="qiYeWeChatApiService"></param>
  43. /// <param name="wageSheetRep"></param>
  44. /// <param name="usersRep"></param>
  45. /// <param name="mapper"></param>
  46. /// <param name="taskAllocationRep"></param>
  47. /// <param name="hubContext"></param>
  48. /// <param name="goodsRep"></param>
  49. /// <param name="sqlSugar"></param>
  50. public PersonnelModuleController(
  51. IHubContext<ChatHub, IChatClient> hubContext,
  52. IMapper mapper,
  53. IQiYeWeChatApiService qiYeWeChatApiService,
  54. WageSheetRepository wageSheetRep,
  55. UsersRepository usersRep,
  56. TaskAllocationRepository taskAllocationRep,
  57. GoodsRepository goodsRep,
  58. SqlSugarClient sqlSugar
  59. )
  60. {
  61. _mapper = mapper;
  62. _usersRep = usersRep;
  63. _qiYeWeChatApiService = qiYeWeChatApiService;
  64. _wageSheetRep = wageSheetRep;
  65. _result = new Result();
  66. _sqlSugar = sqlSugar;
  67. url = AppSettingsHelper.Get("ExcelBaseUrl");
  68. path = AppSettingsHelper.Get("ExcelBasePath");
  69. if (!System.IO.Directory.Exists(path))
  70. {
  71. System.IO.Directory.CreateDirectory(path);//不存在就创建文件夹
  72. }
  73. this._taskAllocationRep = taskAllocationRep;
  74. _hubContext = hubContext;
  75. _goodsRep = goodsRep;
  76. }
  77. #region 工资表单
  78. /// <summary>
  79. /// 工资 月列表
  80. /// </summary>
  81. /// <returns></returns>
  82. [HttpPost]
  83. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  84. public async Task<IActionResult> GetWageSheetMonth()
  85. {
  86. string sql = string.Format("Select * From Pm_WageIssueWorkingDay Where IsDel = 0 Order By YearMonth Desc");
  87. var data = await _wageSheetRep._sqlSugar.SqlQueryable<WageSheetMonthView>(sql).ToListAsync();
  88. return Ok(JsonView(true, "查询成功!", data));
  89. }
  90. /// <summary>
  91. /// 工资 工作日信息
  92. /// 查询
  93. /// </summary>
  94. /// <returns></returns>
  95. [HttpPost]
  96. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  97. public async Task<IActionResult> GetWageSheetMonthWorkdays(string startDt, string endDt)
  98. {
  99. //参数处理
  100. var dtFormat = "yyyy-MM-dd";
  101. DateTime startDt1, endDt1;
  102. var startDtIsValid = DateTime.TryParseExact(startDt, dtFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out startDt1);
  103. var endDtIsValid = DateTime.TryParseExact(endDt, dtFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out endDt1);
  104. if (!startDtIsValid) return Ok(JsonView(false, "开始日期格式错误!正确时间格式:yyyy-MM-dd "));
  105. if (!endDtIsValid) return Ok(JsonView(false, "结束格式错误!正确时间格式:yyyy-MM-dd "));
  106. var sql = string.Format(@"Select * From Sys_Calendar
  107. Where Isdel = 0 And Dt between '{0}' And '{1}'", startDt, endDt);
  108. var data = await _wageSheetRep._sqlSugar.SqlQueryable<CalendarInfoView>(sql).ToListAsync();
  109. return Ok(JsonView(true, "查询成功!", data));
  110. }
  111. /// <summary>
  112. /// 工资 工作日信息
  113. /// 编辑
  114. /// </summary>
  115. /// <returns></returns>
  116. [HttpPost]
  117. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  118. public async Task<IActionResult> GetWageSheetMonthWorkdaysAddOrEdit(WageSheetMonthWorkdaysAddOrEditDto dto)
  119. {
  120. //参数处理
  121. string yearFormat = "yyyy-MM";
  122. string dtFormat = "yyyy-MM-dd";
  123. DateTime yearDt, startDt1, endDt1;
  124. bool yearDtIsValid = DateTime.TryParseExact(dto.YearMonth, yearFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out yearDt);
  125. bool startDtIsValid = DateTime.TryParseExact(dto.StartDate, dtFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out startDt1);
  126. bool endDtIsValid = DateTime.TryParseExact(dto.EndDate, dtFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out endDt1);
  127. if (!yearDtIsValid) return Ok(JsonView(false, "年月日期格式错误!正确时间格式:yyyy-MM "));
  128. if (!startDtIsValid) return Ok(JsonView(false, "开始日期格式错误!正确时间格式:yyyy-MM-dd "));
  129. if (!endDtIsValid) return Ok(JsonView(false, "结束格式错误!正确时间格式:yyyy-MM-dd "));
  130. #region 处理数据
  131. Pm_WageIssueWorkingDay pm_WageIssueWorkingDay1 = new Pm_WageIssueWorkingDay();
  132. pm_WageIssueWorkingDay1 = _mapper.Map<Pm_WageIssueWorkingDay>(dto);
  133. List<Sys_Calendar> sys_Calendars = new List<Sys_Calendar>();
  134. sys_Calendars = _mapper.Map<List<Sys_Calendar>>(dto.CalendarInfos);
  135. if (sys_Calendars.Count > 0)
  136. {
  137. sys_Calendars = sys_Calendars.OrderBy(it => it.Dt).ToList();
  138. }
  139. pm_WageIssueWorkingDay1.Workdays = sys_Calendars.Where(it => it.IsWorkDay == true).ToList().Count;
  140. foreach (var item in sys_Calendars)
  141. {
  142. item.Remark = pm_WageIssueWorkingDay1.Remark;
  143. item.CreateUserId = pm_WageIssueWorkingDay1.CreateUserId;
  144. item.CreateTime = pm_WageIssueWorkingDay1.CreateTime;
  145. }
  146. #endregion
  147. var _sqlSugar = _wageSheetRep._sqlSugar;
  148. _sqlSugar.BeginTran();
  149. try
  150. {
  151. List<Sys_Calendar> sys_Calendars_add = new List<Sys_Calendar>();
  152. List<Sys_Calendar> sys_Calendars_update = new List<Sys_Calendar>();
  153. sys_Calendars_add = sys_Calendars.Where(it => it.Id == 0).OrderBy(it => it.Dt).ToList();
  154. sys_Calendars_update = sys_Calendars.Where(it => it.Id != 0).OrderBy(it => it.Dt).ToList();
  155. int add1 = 0;
  156. int upd = 0;
  157. if (sys_Calendars_add.Count > 0)
  158. {
  159. var calendarsAdd = await _sqlSugar.Insertable(sys_Calendars_add).ExecuteReturnIdentityAsync();
  160. if (calendarsAdd < 0)
  161. {
  162. _sqlSugar.RollbackTran();
  163. return Ok(JsonView(false, "工作日/节假日/休息日添加失败!"));
  164. }
  165. }
  166. if (sys_Calendars_update.Count > 0)
  167. {
  168. var calendarsUpdate = await _sqlSugar.Updateable<Sys_Calendar>(sys_Calendars)
  169. .UpdateColumns(it => new { it.Dt, it.IsWorkDay, it.IsHoliDay, it.HoliName })
  170. .WhereColumns(it => it.Id)
  171. .ExecuteCommandAsync();
  172. if (calendarsUpdate < 0)
  173. {
  174. _sqlSugar.RollbackTran();
  175. return Ok(JsonView(false, "工作日/节假日/休息日编辑失败!"));
  176. }
  177. }
  178. var calendarsDatas = await _sqlSugar.Queryable<Sys_Calendar>()
  179. .Where(it => Convert.ToDateTime(it.Dt) >= Convert.ToDateTime(dto.StartDate) && Convert.ToDateTime(it.Dt) <= Convert.ToDateTime(dto.EndDate)).ToListAsync();
  180. if (calendarsDatas.Count < 0)
  181. {
  182. _sqlSugar.RollbackTran();
  183. return Ok(JsonView(false, "日期包暂无工作日/节假日/休息日的信息!"));
  184. }
  185. //月份表是否存在
  186. Pm_WageIssueWorkingDay pm_WageIssueWorkingDay = new Pm_WageIssueWorkingDay()
  187. {
  188. YearMonth = dto.YearMonth,
  189. StartDate = dto.StartDate,
  190. EndDate = dto.EndDate,
  191. Workdays = calendarsDatas.Where(it => it.IsWorkDay == true).ToList().Count
  192. };
  193. string sql = string.Format("Select * From Pm_WageIssueWorkingDay Where Isdel = 0 And YearMonth='{0}'", dto.YearMonth);
  194. var workdsys = await _sqlSugar.SqlQueryable<Pm_WageIssueWorkingDay>(sql).FirstAsync();
  195. pm_WageIssueWorkingDay.CreateUserId = dto.UserId;
  196. pm_WageIssueWorkingDay.IsDel = 0;
  197. if (workdsys == null) //添加
  198. {
  199. int addId = await _sqlSugar.Insertable(pm_WageIssueWorkingDay).ExecuteReturnIdentityAsync();
  200. if (addId < 0)
  201. {
  202. _sqlSugar.RollbackTran();
  203. return Ok(JsonView(false, "工作日设置添加失败!"));
  204. }
  205. }
  206. else //更新
  207. {
  208. int updCount = await _sqlSugar.Updateable(pm_WageIssueWorkingDay)
  209. .IgnoreColumns(z => new { z.CreateUserId, z.CreateTime, z.DeleteUserId, z.DeleteTime, z.IsDel })
  210. .WhereColumns(it => it.YearMonth)
  211. .ExecuteCommandAsync();
  212. if (updCount < 0)
  213. {
  214. _sqlSugar.RollbackTran();
  215. return Ok(JsonView(false, "工作日设置编辑失败!"));
  216. }
  217. }
  218. _sqlSugar.CommitTran();
  219. return Ok(JsonView(true, "操作成功!"));
  220. }
  221. catch (Exception ex)
  222. {
  223. _sqlSugar.RollbackTran();
  224. return Ok(JsonView(false, ex.Message));
  225. }
  226. }
  227. /// <summary>
  228. /// 工资表单 基础数据源
  229. /// </summary>
  230. /// <returns></returns>
  231. [HttpPost]
  232. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  233. public async Task<IActionResult> GetWageSheetBasicsDataSource()
  234. {
  235. string companySql = string.Format("Select * From Sys_Company Where IsDel = 0");
  236. var compnayData = await _wageSheetRep._sqlSugar.SqlQueryable<CompanyNameView>(companySql).ToListAsync();
  237. string depSql = string.Format("Select * From Sys_Department Where IsDel = 0");
  238. var depData = await _wageSheetRep._sqlSugar.SqlQueryable<Domain.ViewModels.System.DepartmentView>(depSql).ToListAsync();
  239. //获取OA系统内所有用户
  240. var nameData = await _usersRep.GetUserNameList(1);
  241. if (nameData.Code != 0)
  242. {
  243. return Ok(JsonView(false, nameData.Msg));
  244. }
  245. var data = new
  246. {
  247. compnayData = compnayData,
  248. depData = depData,
  249. userNames = nameData.Data
  250. };
  251. return Ok(JsonView(true, "查询成功!", data));
  252. }
  253. /// <summary>
  254. /// 获取工资发放月份
  255. /// </summary>
  256. /// <param name="dto"></param>
  257. /// <returns></returns>
  258. [HttpPost]
  259. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  260. public async Task<IActionResult> GetWageYaerMonths(WageYearDto dto)
  261. {
  262. string sql = string.Format(@"Select * From Pm_WageIssueWorkingDay
  263. Where Isdel = 0 And YearMonth Like '%{0}%'
  264. Order By YearMonth Asc", dto.Year);
  265. var data = await _wageSheetRep._sqlSugar.SqlQueryable<WageYearMonthView>(sql).ToListAsync();
  266. return Ok(JsonView(true, "操作成功!", data));
  267. }
  268. /// <summary>
  269. /// 获取工资表单
  270. /// </summary>
  271. /// <param name="dto"></param>
  272. /// <returns></returns>
  273. [HttpPost]
  274. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  275. public async Task<IActionResult> GetWageSheetList(WageSheetListDto dto)
  276. {
  277. //参数处理
  278. string ymFormat = "yyyy-MM";
  279. DateTime yearMonthDt;
  280. bool yearMonthDttIsValid = DateTime.TryParseExact(dto.YearMonth, ymFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out yearMonthDt);
  281. if (!yearMonthDttIsValid)
  282. {
  283. _result.Msg = "年月格式错误!正确时间格式:yyyy-MM ";
  284. return Ok(JsonView(false, _result.Msg));
  285. }
  286. //获取月工资数据
  287. string yearMonth = yearMonthDt.ToString("yyyy-MM");
  288. if (dto.PortType == 1)
  289. {
  290. _result = await _wageSheetRep.Get_WageSheet_ListByYearMonthAsync(yearMonth);
  291. if (_result.Code != 0)
  292. {
  293. return Ok(JsonView(false, _result.Msg));
  294. }
  295. }
  296. else if (dto.PortType == 2)
  297. { }
  298. else if (dto.PortType == 3)
  299. { }
  300. else
  301. {
  302. return Ok(JsonView(false, "请选择正确的端口参数"));
  303. }
  304. return Ok(JsonView(true, _result.Msg, _result.Data));
  305. }
  306. /// <summary>
  307. /// 获取工资 详情
  308. /// </summary>
  309. /// <param name="dto"></param>
  310. /// <returns></returns>
  311. [HttpPost]
  312. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  313. public async Task<IActionResult> GetWageSheetById(WageSheetInfoDto dto)
  314. {
  315. if (dto.PortType == 1)
  316. {
  317. _result = await _wageSheetRep.Get_WageSheet_InfoByIdAsync(dto.Id);
  318. if (_result.Code != 0)
  319. {
  320. return Ok(JsonView(false, _result.Msg));
  321. }
  322. }
  323. else if (dto.PortType == 2)
  324. { }
  325. else if (dto.PortType == 3)
  326. { }
  327. else
  328. {
  329. return Ok(JsonView(false, "请选择正确的端口参数"));
  330. }
  331. return Ok(JsonView(true, _result.Msg, _result.Data));
  332. }
  333. /// <summary>
  334. /// 人事模块 工资表单 删除
  335. /// </summary>
  336. /// <param name="dto"></param>
  337. /// <returns></returns>
  338. [HttpPost]
  339. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  340. public async Task<IActionResult> PostWageSheetDel(WageDelDto dto)
  341. {
  342. try
  343. {
  344. _result = await _wageSheetRep.Post_WageSheet_DelAsync(dto);
  345. if (_result.Code != 0)
  346. {
  347. return Ok(JsonView(false, _result.Msg));
  348. }
  349. }
  350. catch (Exception ex)
  351. {
  352. return Ok(JsonView(false, ex.Message));
  353. }
  354. return Ok(JsonView(true, _result.Msg, _result.Data));
  355. }
  356. /// <summary>
  357. /// 人事模块 工资表单 添加 Or 修改
  358. /// </summary>
  359. /// <param name="dto"></param>
  360. /// <returns></returns>
  361. [HttpPost]
  362. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  363. public async Task<IActionResult> PostWageSheetAddOrEdit(WageAddOrEditDto dto)
  364. {
  365. try
  366. {
  367. Pm_WageSheet pm_WageSheet = new Pm_WageSheet();
  368. pm_WageSheet = _mapper.Map<Pm_WageSheet>(dto);
  369. pm_WageSheet.LastUpdateUserId = dto.CreateUserId;
  370. #region 计算工资
  371. //月工资
  372. decimal salary = pm_WageSheet.Basic + pm_WageSheet.Floats + pm_WageSheet.PostAllowance + pm_WageSheet.InformationSecurityFee + pm_WageSheet.OtherSubsidies;
  373. //扣款合计
  374. decimal totalDeduction = pm_WageSheet.SickLeave + pm_WageSheet.SomethingFalse + pm_WageSheet.LateTo + pm_WageSheet.LeaveEarly + pm_WageSheet.Absenteeism + pm_WageSheet.NotPunch +
  375. pm_WageSheet.ReservedFunds + pm_WageSheet.WithholdingInsurance + pm_WageSheet.OtherDeductions + pm_WageSheet.OtherDeductions;
  376. //实发合计 不含个税
  377. if (pm_WageSheet.RegularDays >= pm_WageSheet.WorkDays)
  378. {
  379. pm_WageSheet.RegularDays = pm_WageSheet.WorkDays;
  380. salary = salary + pm_WageSheet.Mealsupplement + pm_WageSheet.OtherHandle;
  381. }
  382. else
  383. {
  384. if (dto.UserId == 21) //21==张海麟
  385. {
  386. salary = salary + pm_WageSheet.Mealsupplement + pm_WageSheet.OtherHandle;
  387. }
  388. else
  389. {
  390. salary = PayrollComputation.ConvertToDecimal(salary / pm_WageSheet.WorkDays * pm_WageSheet.RegularDays + pm_WageSheet.Mealsupplement + pm_WageSheet.OtherHandle);
  391. }
  392. }
  393. decimal actualTotal = salary - totalDeduction;
  394. pm_WageSheet.Should = salary;
  395. pm_WageSheet.TotalDeductions = totalDeduction;
  396. pm_WageSheet.TotalRealHair = actualTotal - pm_WageSheet.WithholdingTax;
  397. pm_WageSheet.AfterTax = actualTotal - pm_WageSheet.WithholdingTax;
  398. #endregion
  399. _result = await _wageSheetRep.Post_WageSheet_AddOrEditAsync(dto, pm_WageSheet);
  400. if (_result.Code != 0)
  401. {
  402. return Ok(JsonView(false, _result.Msg));
  403. }
  404. }
  405. catch (Exception ex)
  406. {
  407. return Ok(JsonView(false, ex.Message));
  408. }
  409. return Ok(JsonView(true, _result.Msg, _result.Data));
  410. }
  411. /// <summary>
  412. /// 计算工资
  413. /// </summary>
  414. /// <returns></returns>
  415. [HttpPost]
  416. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  417. public async Task<IActionResult> SalaryCalculatorAsync(SalaryCalculatorDto dto)
  418. {
  419. Result result = new Result();
  420. Stopwatch sw = new Stopwatch();
  421. sw.Start();
  422. //参数处理
  423. string ymFormat = "yyyy-MM";
  424. string dtFormat = "yyyy-MM-dd";
  425. DateTime yearMonthDt, startDt, endDt;
  426. bool yearMonthDtIsValid = DateTime.TryParseExact(dto.yearMonth, ymFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out yearMonthDt);
  427. bool startDtIsValid = DateTime.TryParseExact(dto.startDt, dtFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out startDt);
  428. bool endDtIsValid = DateTime.TryParseExact(dto.endDt, dtFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out endDt);
  429. if (!yearMonthDtIsValid) return Ok(JsonView(false, "年月格式错误!正确时间格式:yyyy-MM "));
  430. if (!startDtIsValid) return Ok(JsonView(false, "开始日期格式错误!正确时间格式:yyyy-MM-dd "));
  431. if (!endDtIsValid) return Ok(JsonView(false, "结束格式错误!正确时间格式:yyyy-MM-dd "));
  432. string thisYearMonth = dto.yearMonth;
  433. string preYearMonth = yearMonthDt.AddMonths(-1).ToString("yyyy-MM");
  434. //计算本月工资起止时间 比如是2月的1号-28号,那就是2月1号的零点到3月1号的零点
  435. DateTime thisStartDt = startDt;
  436. DateTime thisEndDt = endDt; //
  437. //本月工资是否有数据 有数据则不计算
  438. result = await _wageSheetRep.Get_WageSheet_ListByYearMonthAsync(thisYearMonth);
  439. if (result.Code == 0)
  440. {
  441. return Ok(JsonView(false, thisYearMonth + " 工资数据已存在,若无人员工资请手动添加!"));
  442. }
  443. //获取上个月工资信息
  444. List<Pm_WageSheet> preWageSheetItems = await _wageSheetRep._sqlSugar.Queryable<Pm_WageSheet>().Where(it => it.IsDel == 0 && it.YearMonth == preYearMonth).ToListAsync();
  445. preWageSheetItems = preWageSheetItems.OrderBy(it => it.UserId).ToList();
  446. if (preWageSheetItems.Count <= 0)
  447. {
  448. return Ok(JsonView(false, thisYearMonth + " 上月工资数据不存在,请手动添加!"));
  449. }
  450. //处理上个月同月同人 多条数据
  451. List<Pm_WageSheet> preWageSheetItems1 = new List<Pm_WageSheet>();
  452. preWageSheetItems1 = preWageSheetItems.GroupBy(it => new { it.YearMonth, it.UserId })
  453. .Select(it => it.FirstOrDefault(item => item.Basic != 0))
  454. .ToList();
  455. //获取OA系统内所有用户
  456. List<UserNameView> userNames = _usersRep._sqlSugar.SqlQueryable<UserNameView>("Select Id,CnName From Sys_Users").ToList();
  457. List<Pm_WageSheet> wageSheets = new List<Pm_WageSheet>();
  458. _result = await PayrollComputation.SalaryCalculatorAsync(preWageSheetItems1, userNames, dto.UserId, thisYearMonth, thisStartDt, thisEndDt);
  459. #region 批量添加
  460. if (_result.Code != 0)
  461. {
  462. return Ok(JsonView(false, _result.Msg));
  463. }
  464. wageSheets = _result.Data;
  465. var add = await _wageSheetRep._sqlSugar.Insertable(wageSheets).ExecuteCommandAsync();
  466. if (add <= 0)
  467. {
  468. return Ok(JsonView(false, "操作失败!"));
  469. }
  470. #endregion
  471. #region 处理返回数据
  472. //List <WageSheetItemInfoView> wageSheetItems = new List<WageSheetItemInfoView>();
  473. //wageSheetItems = _mapper.Map<List<WageSheetItemInfoView>>(wageSheets);
  474. //wageSheetItems = wageSheetItems.Select(it =>
  475. // {
  476. // UserNameView? uName1 = new UserNameView();
  477. // UserNameView? uName2 = new UserNameView();
  478. // uName1 = userNames.Where(it1 => it.UserId == it1.Id).FirstOrDefault();
  479. // if (uName1 != null) it.Name = uName1.CnName;
  480. // uName2 = userNames.Where(it1 => it.LastUpdateUserId == it1.Id).FirstOrDefault();
  481. // if (uName2 != null) it.LastUpdateUserName = uName2.CnName;
  482. // return it; }
  483. // ).ToList();
  484. #endregion
  485. sw.Stop();
  486. return Ok(JsonView(true, "操作成功! 耗时:" + (sw.ElapsedMilliseconds / 1000) + "s"));
  487. }
  488. /// <summary>
  489. /// 计算工资 By YearMonth And UserId
  490. /// </summary>
  491. /// <returns></returns>
  492. [HttpPost]
  493. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  494. public async Task<IActionResult> SalaryCalculatorSingleAsync(SalaryCalculatorSingleDto dto)
  495. {
  496. Result result = new Result();
  497. Stopwatch sw = new Stopwatch();
  498. sw.Start();
  499. //参数处理
  500. string ymFormat = "yyyy-MM";
  501. string ymdFormat = "yyyy-MM-dd";
  502. DateTime yearMonthDt, startDt, endDt;
  503. bool yearMonthDtIsValid = DateTime.TryParseExact(dto.YearMonth, ymFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out yearMonthDt);
  504. bool startDtIsValid = DateTime.TryParseExact(dto.StartDate, ymdFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out startDt);
  505. bool endDtIsValid = DateTime.TryParseExact(dto.EndDate, ymdFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out endDt);
  506. if (!yearMonthDtIsValid) return Ok(JsonView(false, "年月格式错误!正确时间格式:yyyy-MM "));
  507. if (!startDtIsValid) return Ok(JsonView(false, "开始时间格式错误!正确时间格式:yyyy-MM-dd "));
  508. if (!yearMonthDtIsValid) return Ok(JsonView(false, "结束时间格式错误!正确时间格式:yyyy-MM-dd "));
  509. List<Pm_WageSheet> wageSheets = new List<Pm_WageSheet>();
  510. Pm_WageSheet wageSheet = _mapper.Map<Pm_WageSheet>(dto);
  511. Pm_WageSheet wageSheet1 = await _wageSheetRep._sqlSugar.Queryable<Pm_WageSheet>().Where(it => it.UserId == dto.UserId && it.YearMonth == dto.YearMonth && it.StartDate == dto.StartDate && it.EndDate == dto.EndDate).FirstAsync();
  512. if (wageSheet1 != null)
  513. {
  514. wageSheet.Id = wageSheet1.Id;
  515. }
  516. wageSheets.Add(wageSheet);
  517. //获取OA系统内所有用户
  518. List<UserNameView> userNames = _usersRep._sqlSugar.SqlQueryable<UserNameView>("Select Id,CnName From Sys_Users").ToList();
  519. _result = await PayrollComputation.SalaryCalculatorAsync(wageSheets, userNames, dto.UserId, dto.YearMonth, startDt, endDt);
  520. if (_result.Code != 0)
  521. {
  522. return Ok(JsonView(false, _result.Msg));
  523. }
  524. List<Pm_WageSheet> wageSheets1 = new List<Pm_WageSheet>();
  525. wageSheets1 = _result.Data;
  526. #region 处理返回数据
  527. List<WageSheetInfoView> wageSheetItems = new List<WageSheetInfoView>();
  528. wageSheetItems = _mapper.Map<List<WageSheetInfoView>>(wageSheets1);
  529. wageSheetItems = wageSheetItems.Select(it =>
  530. {
  531. UserNameView? uName1 = new UserNameView();
  532. UserNameView? uName2 = new UserNameView();
  533. uName1 = userNames.Where(it1 => it.UserId == it1.Id).FirstOrDefault();
  534. if (uName1 != null) it.Name = uName1.CnName;
  535. uName2 = userNames.Where(it1 => it.LastUpdateUserId == it1.Id).FirstOrDefault();
  536. if (uName2 != null) it.LastUpdateUserName = uName2.CnName;
  537. return it;
  538. }
  539. ).ToList();
  540. #endregion
  541. sw.Stop();
  542. return Ok(JsonView(true, "操作成功!耗时:" + (sw.ElapsedMilliseconds / 1000) + "s", wageSheetItems[0]));
  543. }
  544. /// <summary>
  545. /// 导出工资单
  546. /// </summary>
  547. /// <returns></returns>
  548. [HttpPost]
  549. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  550. public async Task<IActionResult> ExportWageCard(string yearMonth)
  551. {
  552. Result result = new Result();
  553. Stopwatch sw = new Stopwatch();
  554. sw.Start();
  555. //参数处理
  556. string ymFormat = "yyyy-MM";
  557. DateTime yearMonthDt;
  558. bool yearMonthDtIsValid = DateTime.TryParseExact(yearMonth, ymFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out yearMonthDt);
  559. if (!yearMonthDtIsValid) return Ok(JsonView(false, "年月格式错误!正确时间格式:yyyy-MM "));
  560. //公司部门
  561. string sql = string.Format(@"Select row_number() over(order by pm_ws.Id) as Row_Number,
  562. sc.Id as CompanyId,sc.CompanyName,sd.Id as DepId,sd.DepName,
  563. sys_u1.CnName Name,sys_u2.CnName LastUpdateUserName,pm_ws.*
  564. From Pm_WageSheet pm_ws
  565. Left Join Sys_Users sys_u1 On pm_ws.UserId = sys_u1.Id
  566. Left Join Sys_Users sys_u2 On pm_ws.LastUpdateUserId = sys_u2.Id
  567. Left Join Sys_Company sc On sys_u1.companyId = sc.Id
  568. Left Join Sys_Department sd On sys_u1.DepId = sd.Id
  569. Where pm_ws.IsDel = 0 And pm_ws.YearMonth = '{0}'", yearMonth);
  570. var wageSheetList = await _wageSheetRep._sqlSugar.SqlQueryable<ExportWageSheetItemView>(sql).ToListAsync();
  571. if (wageSheetList.Count <= 0)
  572. {
  573. return Ok(JsonView(false, yearMonth + "暂无工资数据!"));
  574. }
  575. decimal SumPrice = 0.00M;
  576. foreach (var item in wageSheetList)
  577. {
  578. SumPrice += item.AfterTax;
  579. }
  580. WorkbookDesigner designer = new WorkbookDesigner();
  581. designer.Workbook = new Workbook(AppSettingsHelper.Get("ExcelBasePath") + "Template/工资详细清单.xlsx");
  582. designer.Workbook.Worksheets[0].Name = yearMonth + " 工资单";
  583. designer.SetDataSource("WageSheet", wageSheetList);
  584. designer.SetDataSource("YearMonth", yearMonth);
  585. designer.SetDataSource("StartEndDt", wageSheetList[0].StartDate + " - " + wageSheetList[0].EndDate);
  586. designer.SetDataSource("WorkDays", wageSheetList[0].WorkDays);
  587. designer.SetDataSource("SumPrice", SumPrice);
  588. designer.SetDataSource("WageSheetTitle", "工资单");//
  589. designer.Process();
  590. string fileName = "WageCard/" + yearMonth + "_工资单_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx";
  591. string path = AppSettingsHelper.Get("ExcelBasePath");
  592. designer.Workbook.Save(path + fileName);
  593. designer = null;
  594. string excelPath = AppSettingsHelper.Get("ExcelFtpPath") + fileName;
  595. string url = AppSettingsHelper.Get("ExcelBaseUrl");
  596. string fileUrl = url + excelPath;
  597. sw.Stop();
  598. return Ok(JsonView(true, "操作成功!耗时:" + (sw.ElapsedMilliseconds / 1000) + "s", new { FileUrl = fileUrl }));
  599. }
  600. /// <summary>
  601. /// 下载个税模板
  602. /// </summary>
  603. /// <returns></returns>
  604. [HttpPost]
  605. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  606. public async Task<IActionResult> WageSheetTaxTemplate()
  607. {
  608. string serverUrl = AppSettingsHelper.Get("WageSheetExcelBaseUrl");
  609. var userData = await _usersRep.GetUserNameList(1);
  610. if (userData.Code == 0)
  611. {
  612. var userNames = userData.Data;
  613. List<string> names = new List<string>();
  614. List<UserNameView> users = new List<UserNameView>();
  615. names.Add("管理员");
  616. names.Add("国交共享号");
  617. names.Add("人事审核号");
  618. names.Add("国交主管号");
  619. List<TaxTemlateViuw> taxs = new List<TaxTemlateViuw>();
  620. users = JsonConvert.DeserializeObject<List<UserNameView>>(JsonConvert.SerializeObject(userNames));
  621. foreach (UserNameView item in users)
  622. {
  623. string uName = item.CnName;
  624. if (!names.Contains(uName))
  625. {
  626. taxs.Add(new TaxTemlateViuw { UserName = item.CnName });
  627. }
  628. }
  629. if (taxs.Count > 0)
  630. {
  631. WorkbookDesigner designer = new WorkbookDesigner();
  632. designer.Workbook = new Workbook(AppSettingsHelper.Get("ExcelBasePath") + "Template/个税导入模板.xlsx");
  633. designer.Workbook.Worksheets[0].Name = "个税模板";
  634. designer.SetDataSource("TaxTemp", taxs);
  635. designer.Process();
  636. string fileName = "WageSheetTaxFile/个税模板" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx";
  637. string path = AppSettingsHelper.Get("ExcelBasePath");
  638. designer.Workbook.Save(path + fileName);
  639. designer = null;
  640. string excelPath = AppSettingsHelper.Get("ExcelFtpPath") + fileName;
  641. string url = AppSettingsHelper.Get("ExcelBaseUrl");
  642. string fileUrl = url + excelPath;
  643. return Ok(JsonView(true, "操作成功!", new { FileUrl = fileUrl }));
  644. }
  645. }
  646. return Ok(JsonView(false, "操作失败!"));
  647. }
  648. /// <summary>
  649. /// 上传个税
  650. /// </summary>
  651. /// <returns></returns>
  652. [HttpPost]
  653. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  654. public async Task<IActionResult> UploadTax(IFormFile file)
  655. {
  656. try
  657. {
  658. var yearMonth = Request.Headers["YearMonth"].ToString();
  659. //string yearMonth = "2023-10";
  660. string ymFormat = "yyyy-MM";
  661. DateTime yearMonthDt;
  662. bool yearMonthDtIsValid = DateTime.TryParseExact(yearMonth, ymFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out yearMonthDt);
  663. if (!yearMonthDtIsValid) return Ok(JsonView(false, "年月格式错误!正确时间格式:yyyy-MM "));
  664. if (file != null)
  665. {
  666. var fileDir = AppSettingsHelper.Get("WageSheetExcelFptPath");
  667. //文件名称
  668. string projectFileName = file.FileName;
  669. //上传的文件的路径
  670. string filePath = "";
  671. if (!Directory.Exists(fileDir))
  672. {
  673. Directory.CreateDirectory(fileDir);
  674. }
  675. //上传的文件的路径
  676. filePath = fileDir + $@"\{projectFileName}";
  677. if (System.IO.File.Exists(filePath))
  678. {
  679. //删除文件
  680. System.IO.File.Delete(filePath);
  681. }
  682. using (FileStream fs = System.IO.File.Create(filePath))
  683. {
  684. file.CopyTo(fs);
  685. fs.Flush();
  686. }
  687. if (System.IO.File.Exists(filePath))
  688. {
  689. Workbook book = new Workbook(filePath);
  690. DataSet dataSet = new DataSet();
  691. if (book.Worksheets.Count > 0)
  692. {
  693. var sheet = book.Worksheets[0];
  694. if (sheet != null)
  695. {
  696. // sheets 中的数据必须存在
  697. if (sheet.Cells.MaxDataRow != -1 && sheet.Cells.MaxDataColumn != -1)
  698. {
  699. // 方法 ExportDataTable 的参数说明
  700. // 要导出的第一个单元格的行号。
  701. // 要导出的第一个单元格的列号。
  702. // 要导入的行数。
  703. // 要导入的列数。
  704. // 指示第一行的数据是否导出到DataTable的列名。
  705. DataTable dataTable = sheet.Cells.ExportDataTable(0, 0, sheet.Cells.MaxDataRow + 1, sheet.Cells.MaxDataColumn + 1, true);
  706. dataSet.Tables.Add(dataTable);
  707. DataTable taxData = dataSet.Tables[0];
  708. //公司部门
  709. string sql = string.Format(@"Select row_number() over(order by pm_ws.Id) as Row_Number,
  710. sc.Id as CompanyId,sc.CompanyName,sd.Id as DepId,sd.DepName,
  711. sys_u1.CnName Name,sys_u2.CnName LastUpdateUserName,pm_ws.*
  712. From Pm_WageSheet pm_ws
  713. Left Join Sys_Users sys_u1 On pm_ws.UserId = sys_u1.Id
  714. Left Join Sys_Users sys_u2 On pm_ws.LastUpdateUserId = sys_u2.Id
  715. Left Join Sys_Company sc On sys_u1.companyId = sc.Id
  716. Left Join Sys_Department sd On sys_u1.DepId = sd.Id
  717. Where pm_ws.IsDel = 0 And pm_ws.YearMonth = '{0}'
  718. Order By UserId Asc ", yearMonth);
  719. var wageSheetList = await _wageSheetRep._sqlSugar.SqlQueryable<WageSheetInfoView>(sql).ToListAsync();
  720. if (wageSheetList.Count <= 0)
  721. {
  722. return Ok(JsonView(false, yearMonth + "工资数据不存在,请先添加工资数据!"));
  723. }
  724. for (int i = 0; i < taxData.Rows.Count; i++)
  725. {
  726. string name = taxData.Rows[i][0].ToString().Trim();
  727. List<WageSheetInfoView> wageSheets = new List<WageSheetInfoView>();
  728. wageSheets = wageSheetList.Where(it => it.Name.Equals(name)).ToList();
  729. if (wageSheets.Count > 0)
  730. {
  731. wageSheetList.Where(it => it.Name.Equals(name))
  732. .Select(it =>
  733. {
  734. //修改 绩效不等于0.00M的数据
  735. //decimal oldTax = it.WithholdingTax;
  736. var newTax = Convert.ToDecimal(taxData.Rows[i][1].ToString());
  737. it.WithholdingTax = newTax;
  738. it.TotalRealHair = it.Should - it.TotalDeductions - newTax;
  739. return it;
  740. })
  741. .ToList();
  742. }
  743. }
  744. List<Pm_WageSheet> wageSheets1 = new List<Pm_WageSheet>();
  745. wageSheets1 = _mapper.Map<List<Pm_WageSheet>>(wageSheetList);
  746. var updateStatus = _wageSheetRep._sqlSugar
  747. .Updateable(wageSheets1)
  748. .UpdateColumns(it => new { it.WithholdingTax, it.TotalRealHair })
  749. .ExecuteCommand();
  750. if (updateStatus < 0)
  751. {
  752. return Ok(JsonView(false, "操作失败!"));
  753. }
  754. if (System.IO.File.Exists(filePath))
  755. {
  756. //删除文件
  757. System.IO.File.Delete(filePath);
  758. }
  759. return Ok(JsonView(true, "操作成功!"));
  760. }
  761. }
  762. else
  763. {
  764. return Ok(JsonView(false, "工作薄没有数据!"));
  765. }
  766. }
  767. }
  768. return Ok(JsonView(true, "上传成功!", projectFileName));
  769. }
  770. else
  771. {
  772. return Ok(JsonView(false, "上传失败!"));
  773. }
  774. }
  775. catch (Exception ex)
  776. {
  777. return Ok(JsonView(false, "程序错误!"));
  778. throw;
  779. }
  780. return Ok(JsonView(true, "操作成功!"));
  781. }
  782. /// <summary>
  783. /// 打卡记录测试
  784. /// </summary>
  785. /// <returns></returns>
  786. [HttpPost]
  787. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  788. public async Task<IActionResult> Test(string startDt, string endDt, int code)
  789. {
  790. UserIdListView userIdListView = await _qiYeWeChatApiService.GetUserIdListAsync();
  791. if (userIdListView.errcode != 0)
  792. {
  793. _result.Msg = "【企业微信】【打卡】【获取员工ID】【Msg】" + userIdListView.errmsg;
  794. return Ok(JsonView(false, _result.Msg));
  795. }
  796. List<string> qyWhchatIdList = new List<string>();
  797. qyWhchatIdList = userIdListView.dept_user.Select(it => it.userid).ToList();
  798. var data = await _qiYeWeChatApiService.GetCheckinDataAsync(qyWhchatIdList, code, Convert.ToDateTime(startDt), Convert.ToDateTime(endDt));
  799. return Ok(JsonView(true, "操作成功!", data.checkindata));
  800. }
  801. /// <summary>
  802. /// 审批详情
  803. /// </summary>
  804. /// <returns></returns>
  805. [HttpPost]
  806. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  807. public async Task<IActionResult> PostApprovalDetailAsync(string spNo)
  808. {
  809. if (string.IsNullOrEmpty(spNo))
  810. {
  811. return Ok(JsonView(false, "审批单号不能为空!!"));
  812. }
  813. var data = await _qiYeWeChatApiService.GetApprovalDetailAsync(spNo);
  814. return Ok(JsonView(true, "操作成功!", data));
  815. }
  816. #endregion
  817. #region 任务单
  818. /// <summary>
  819. /// 任务分配
  820. /// 基础数据源
  821. /// </summary>
  822. /// <returns></returns>
  823. [HttpPost]
  824. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  825. public async Task<IActionResult> PostTaskAllocationInit(TaskAllocationInitDto dto)
  826. {
  827. #region 参数验证
  828. if (dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  829. if (dto.PageId < 1) dto.PageId = 172; //任务指派Id
  830. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  831. #region 页面操作权限验证
  832. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  833. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限!"));
  834. #endregion
  835. #endregion
  836. var _view = await _taskAllocationRep._Init(dto.PortType, dto.UserId);
  837. if (_view.Code == 0)
  838. {
  839. return Ok(JsonView(true, "查询成功!", _view.Data));
  840. }
  841. return Ok(JsonView(false, _view.Msg));
  842. }
  843. /// <summary>
  844. /// 任务分配
  845. /// page
  846. /// </summary>
  847. /// <returns></returns>
  848. [HttpPost]
  849. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  850. public async Task<IActionResult> PostTaskAllocationPage(TaskAllocationPageDto dto)
  851. {
  852. #region 参数验证
  853. if (dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  854. if (dto.PageId < 1) dto.PageId = 172; //任务指派Id
  855. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  856. #region 页面操作权限验证
  857. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  858. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限!"));
  859. #endregion
  860. #endregion
  861. string whereSql = "";
  862. #region 分页参数处理
  863. //类型处理
  864. if (dto.Type == 0) whereSql = "";
  865. else if (dto.Type == 1) //1 由我指派
  866. {
  867. whereSql = string.Format(@" And ta.CreateUserId = {0} Or (Select COUNT(1) As PeopleNumber From Pm_TaskRelevanceUser Where IsDel = 0 And ta.Id = TAId And UserId = {0}) > 0", dto.UserId);
  868. }
  869. else if (dto.Type == 2)// 2 指派给我
  870. {
  871. whereSql = string.Format(@" And (Select COUNT(1) As PeopleNumber From Pm_TaskRelevanceUser Where IsDel = 0 And ta.Id = TAId And UserId = {0}) > 0", dto.UserId);
  872. }
  873. //状态 -1 全部 0 未开始 1 进行中 2 待审核 3 未完成 4 已完成
  874. if (dto.Status == -1) //全部
  875. {
  876. whereSql += "";
  877. }
  878. else
  879. {
  880. whereSql += string.Format(@" And ta.Status = {0} ", dto.Status);
  881. }
  882. //任务名称
  883. if (!string.IsNullOrEmpty(dto.TaskName))
  884. {
  885. whereSql += string.Format(@" And ta.TaskName Like '%{0}%' ", dto.TaskName);
  886. }
  887. #endregion
  888. string pageSql = string.Format(@"Select * From(
  889. Select ROW_NUMBER() OVER(ORDER BY ta.CreateTime Desc) AS RowNumber,
  890. ta.Id,ta.TaskName,ta.TaskPriority,d.DepName,di.TeamName,ta.Status,
  891. ta.PredictBeginTime,ta.PredictEndTime,u.CnName As CreateUserName,ta.CreateTime,
  892. (SELECT STUFF(
  893. (Select ',' + u.CnName From Pm_TaskRelevanceUser tra
  894. Left Join Sys_Users u On tra.UserId = u.Id
  895. Where tra.Isdel = 0 And tra.TAId = ta.Id
  896. FOR XML PATH('')),1,1,'')) As Participant,
  897. (SELECT STUFF(
  898. (Select ',' + u.CnName From Pm_TaskRelevanceUser tra
  899. Left Join Sys_Users u On tra.UserId = u.Id
  900. Where tra.Isdel = 0 And tra.TAId = ta.Id And tra.TaskStatus = 4
  901. FOR XML PATH('')),1,1,'')) As Consummator
  902. From Pm_TaskAllocation ta
  903. Left Join Sys_Department d On ta.DepId = d.Id
  904. Left Join Grp_DelegationInfo di On ta.DiId = di.Id
  905. Left Join Sys_Users u On ta.CreateUserId = u.Id
  906. Where ta.IsDel = 0 {0} ) As temp ", whereSql);
  907. RefAsync<int> total = 0;//REF和OUT不支持异步,想要真的异步这是最优解
  908. var _view = await _taskAllocationRep._sqlSugar.SqlQueryable<TaskListView>(pageSql).ToPageListAsync(dto.PageIndex, dto.PageSize, total);//ToPageAsync
  909. List<int> taskIds = new List<int>();
  910. taskIds = _view.Select(it => it.Id).ToList();
  911. string taskerSql = string.Format(@"Select tau.TAId,tau.Id,tau.UserId,u.CnName As UserName,tau.BeginTime,tau.OverTime,tau.TaskStatus,
  912. tau.Cause,tau.Score,tau.Remark As ScoreRemark,tau.CreateUserId As TaskCreateUserId
  913. From Pm_TaskRelevanceUser tau
  914. Left Join Sys_Users u On tau.UserId = u.Id
  915. Where tau.IsDel = 0");
  916. var taskerData = _taskAllocationRep._sqlSugar.SqlQueryable<TaskerDetailsView>(taskerSql).Where(it => taskIds.Contains(it.TAId)).ToList();
  917. foreach (var item in _view)
  918. {
  919. item.TaskerDetails = taskerData.Where(it => it.TAId == item.Id).ToList();
  920. ////处理任务总状态 And 任务人状态
  921. //var taskerStatusData = taskerData.Where(it => it.TAId == item.Id && it.TaskCreateUserId != dto.UserId && it.UserId == dto.UserId).FirstOrDefault();
  922. //if (taskerStatusData != null)
  923. //{
  924. // item.Status = taskerStatusData.TaskStatus;
  925. //}
  926. }
  927. return Ok(JsonView(true, "查询成功!", _view, total));
  928. }
  929. /// <summary>
  930. /// 任务分配
  931. /// 详情
  932. /// </summary>
  933. /// <returns></returns>
  934. [HttpPost]
  935. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  936. public async Task<IActionResult> PostTaskAllocationDetails(TaskAllocationDetailsDto dto)
  937. {
  938. #region 参数验证
  939. if (dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  940. if (dto.PageId < 1) dto.PageId = 172; //任务指派Id
  941. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  942. #region 页面操作权限验证
  943. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  944. if (pageFunAuthView.CheckAuth == 0) return Ok(JsonView(false, "您没有查看权限!"));
  945. #endregion
  946. #endregion
  947. var _view = await _taskAllocationRep._Details(dto.PortType, dto.Id);
  948. if (_view.Code == 0)
  949. {
  950. return Ok(JsonView(true, "查询成功!", _view.Data));
  951. }
  952. return Ok(JsonView(false, _view.Msg));
  953. }
  954. /// <summary>
  955. /// 任务分配
  956. /// Add Or Edit
  957. /// </summary>
  958. /// <returns></returns>
  959. [HttpPost]
  960. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  961. public async Task<IActionResult> PostTaskAllocationAddOrEdit(TaskAllocationAddOrEditDto dto)
  962. {
  963. #region 参数验证
  964. if (dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  965. if (dto.PageId < 1) dto.PageId = 172; //任务指派Id
  966. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  967. #region 页面操作权限验证
  968. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  969. if (dto.Id == 0)
  970. {
  971. if (pageFunAuthView.AddAuth == 0) return Ok(JsonView(false, "您没有添加权限!"));
  972. }
  973. else if (dto.Id > 0)
  974. {
  975. if (pageFunAuthView.EditAuth == 0) return Ok(JsonView(false, "您没有编辑权限!"));
  976. }
  977. #endregion
  978. #endregion
  979. var _view = await _taskAllocationRep._AddOrEdit(dto);
  980. if (_view.Code == 0)
  981. {
  982. if (dto.Id == 0) //添加提示任务单创建
  983. {
  984. string title = $"[{dto.TaskName}] 任务新建成功!";
  985. string content = $"[{dto.TaskName}] 任务新建成功,请前往任务页面查看详情!";
  986. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.TaskProgressUpdate, title, content, dto.UserIds);
  987. }
  988. return Ok(JsonView(true, "操作成功!"));
  989. }
  990. return Ok(JsonView(false, _view.Msg));
  991. }
  992. /// <summary>
  993. /// 任务分配
  994. /// 状态任务归属人详情
  995. /// </summary>
  996. /// <returns></returns>
  997. [HttpPost]
  998. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  999. public async Task<IActionResult> PostTaskAllocationTaskerDetails(TaskerDetailsDto dto)
  1000. {
  1001. var _view = await _taskAllocationRep._TaskerDetails(dto.Id);
  1002. if (_view.Code == 0)
  1003. {
  1004. return Ok(JsonView(true, "操作成功!", _view.Data));
  1005. }
  1006. return Ok(JsonView(false, _view.Msg));
  1007. }
  1008. /// <summary>
  1009. /// 任务分配
  1010. /// 状态任务归属人设置开始状态
  1011. /// </summary>
  1012. /// <returns></returns>
  1013. [HttpPost]
  1014. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1015. public async Task<IActionResult> PostTaskAllocationSetStartStatus(TaskerStatusDto dto)
  1016. {
  1017. var _view = await _taskAllocationRep._TaskerSetStartStatus(dto.UserId, dto.Id);
  1018. if (_view.Code == 0)
  1019. {
  1020. //发送消息
  1021. var taskData = _taskAllocationRep._sqlSugar.Queryable<Pm_TaskAllocation>().Where(it => it.Id == dto.Id).First();
  1022. if (taskData != null)
  1023. {
  1024. var taskUserIds = _taskAllocationRep._sqlSugar.Queryable<Pm_TaskRelevanceUser>().Where(it => it.TAId == dto.Id).Select(it => it.UserId).ToList();
  1025. if (taskUserIds.Count > 0)
  1026. {
  1027. taskUserIds.Remove(dto.UserId);
  1028. }
  1029. var UserName = _taskAllocationRep._sqlSugar.Queryable<Sys_Users>().Where(it => it.Id == dto.UserId).Select(it => it.CnName).First();
  1030. string title_createUser = $"[{taskData.TaskName}] 进度更新!";
  1031. string conten_createUser = $"[{UserName}] 已开始任务,请注意该工作人员任务进度!";
  1032. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.TaskProgressUpdate, title_createUser, conten_createUser, new List<int>() { taskData.CreateUserId }); //创建人发送消息
  1033. string title = $"[{taskData.TaskName}] 进度更新!";
  1034. string content = $"[{UserName}] 已开始任务.若需查看,请前往任务页面查看详情!";
  1035. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.TaskProgressUpdate, title, content, taskUserIds); //其他人发送消息
  1036. string content1 = $"任务已开始,请在规定时间完成!若需查看,请前往任务页面查看详情!";
  1037. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.TaskProgressUpdate, title, content1, new List<int>() { dto.UserId }); //设置任务人 发送消息
  1038. }
  1039. return Ok(JsonView(true, "操作成功!"));
  1040. }
  1041. return Ok(JsonView(false, _view.Msg));
  1042. }
  1043. /// <summary>
  1044. /// 任务分配
  1045. /// 状态 任务归属人 设置完成状态
  1046. /// </summary>
  1047. /// <returns></returns>
  1048. [HttpPost]
  1049. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1050. public async Task<IActionResult> PostTaskAllocationSetOverStatus(TaskerStatusDto dto)
  1051. {
  1052. var _view = await _taskAllocationRep._TaskerSetOverStatus(dto.UserId, dto.Id);
  1053. if (_view.Code == 0)
  1054. {
  1055. //发送消息
  1056. var taskData = _taskAllocationRep._sqlSugar.Queryable<Pm_TaskAllocation>().Where(it => it.Id == dto.Id).First();
  1057. if (taskData != null)
  1058. {
  1059. var taskUserIds = _taskAllocationRep._sqlSugar.Queryable<Pm_TaskRelevanceUser>().Where(it => it.TAId == dto.Id).Select(it => it.UserId).ToList();
  1060. if (taskUserIds.Count > 0)
  1061. {
  1062. taskUserIds.Remove(dto.UserId);
  1063. }
  1064. var UserName = _taskAllocationRep._sqlSugar.Queryable<Sys_Users>().Where(it => it.Id == dto.UserId).Select(it => it.CnName).First();
  1065. string title_createUser = $"[{taskData.TaskName}] 进度更新!";
  1066. string conten_createUser = $"[{UserName}] 已完成任务,请前往任务页面进行审核操作!";
  1067. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.TaskProgressUpdate, title_createUser, conten_createUser, new List<int>() { taskData.CreateUserId }); //创建人发送消息
  1068. string title = $"[{taskData.TaskName}] 进度更新!";
  1069. string content = $"[{UserName}] 已完成任务,请注意在规定时间内完成任务.若需查看,请前往任务页面查看详情!";
  1070. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.TaskProgressUpdate, title, content, taskUserIds); //其他人发送消息
  1071. string content1 = $"任务已完成,等待任务发布人审核!若需查看,请前往任务页面查看详情!";
  1072. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.TaskProgressUpdate, title, content1, new List<int>() { dto.UserId }); //设置任务人 发送消息
  1073. }
  1074. return Ok(JsonView(true, "操作成功!"));
  1075. }
  1076. return Ok(JsonView(false, _view.Msg));
  1077. }
  1078. /// <summary>
  1079. /// 任务分配
  1080. /// 状态 任务归属人 设置知晓状态
  1081. /// </summary>
  1082. /// <returns></returns>
  1083. [HttpPost]
  1084. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1085. public async Task<IActionResult> PostTaskAllocationSetHaveStatus(TaskAllocationStatusDto dto)
  1086. {
  1087. var _view = await _taskAllocationRep._TaskSetHaveStatus(dto.SubId);
  1088. if (_view.Code == 0)
  1089. {
  1090. //发送消息
  1091. var taskUserData = _taskAllocationRep._sqlSugar.Queryable<Pm_TaskRelevanceUser>().Where(it => it.Id == dto.SubId).First();
  1092. if (taskUserData != null)
  1093. {
  1094. var taskData = _taskAllocationRep._sqlSugar.Queryable<Pm_TaskAllocation>().Where(it => it.Id == taskUserData.TAId).First();
  1095. if (taskData != null)
  1096. {
  1097. var UserName = _taskAllocationRep._sqlSugar.Queryable<Sys_Users>().Where(it => it.Id == taskData.CreateUserId).Select(it => it.CnName).First();
  1098. string title = $"[{taskData.TaskName}] 进度更新!";
  1099. string conten_createUser = $"[{UserName}] 已知晓任务.若需查看,请前往任务页面查看详情!";
  1100. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.TaskProgressUpdate, title, conten_createUser, new List<int>() { taskData.CreateUserId }); //创建人发送消息
  1101. string content = $"请注意任务完成时间!若需查看,请前往任务页面查看详情!";
  1102. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.TaskProgressUpdate, title, content, new List<int>() { taskUserData.UserId }); //设置任务人 发送消息
  1103. }
  1104. }
  1105. return Ok(JsonView(true, "操作成功!"));
  1106. }
  1107. return Ok(JsonView(false, _view.Msg));
  1108. }
  1109. /// <summary>
  1110. /// 任务分配
  1111. /// 任务发布者 单人设置审批状态
  1112. /// </summary>
  1113. /// <returns></returns>
  1114. [HttpPost]
  1115. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1116. public async Task<IActionResult> PostTaskAllocationSetAuditStatus(TaskAllocationStatusDto dto)
  1117. {
  1118. var _view = await _taskAllocationRep._TaskSetAuditStatus(dto.SubId);
  1119. if (_view.Code == 0)
  1120. {
  1121. //发送消息
  1122. var taskUserData = _taskAllocationRep._sqlSugar.Queryable<Pm_TaskRelevanceUser>().Where(it => it.Id == dto.SubId).First();
  1123. if (taskUserData != null)
  1124. {
  1125. var taskData = _taskAllocationRep._sqlSugar.Queryable<Pm_TaskAllocation>().Where(it => it.Id == taskUserData.TAId).First();
  1126. if (taskData != null)
  1127. {
  1128. string title = $"[{taskData.TaskName}] 进度更新!";
  1129. string content = $"任务已完成!若需查看,请前往任务页面查看详情!";
  1130. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.TaskProgressUpdate, title, content, new List<int>() { taskUserData.UserId }); //设置任务人 发送消息
  1131. }
  1132. }
  1133. return Ok(JsonView(true, "操作成功!"));
  1134. }
  1135. return Ok(JsonView(false, _view.Msg));
  1136. }
  1137. /// <summary>
  1138. /// 任务分配
  1139. /// 任务发布者 单人设置未完成状态
  1140. /// </summary>
  1141. /// <returns></returns>
  1142. [HttpPost]
  1143. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1144. public async Task<IActionResult> PostTaskAllocationSetUnFinishedStatus(TaskAllocationSetUnFinishedStatusDto dto)
  1145. {
  1146. var _view = await _taskAllocationRep._TaskSetUnFinishedStatus(dto.SubId, dto.Cause);
  1147. if (_view.Code == 0)
  1148. {
  1149. //发送消息
  1150. var taskUserData = _taskAllocationRep._sqlSugar.Queryable<Pm_TaskRelevanceUser>().Where(it => it.Id == dto.SubId).First();
  1151. if (taskUserData != null)
  1152. {
  1153. var taskData = _taskAllocationRep._sqlSugar.Queryable<Pm_TaskAllocation>().Where(it => it.Id == taskUserData.TAId).First();
  1154. if (taskData != null)
  1155. {
  1156. string title = $"[{taskData.TaskName}] 进度更新!";
  1157. string content = $"任务未完成!若需查看,请前往任务页面查看详情!";
  1158. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.TaskProgressUpdate, title, content, new List<int>() { taskUserData.UserId }); //设置任务人 发送消息
  1159. }
  1160. }
  1161. return Ok(JsonView(true, "操作成功!"));
  1162. }
  1163. return Ok(JsonView(false, _view.Msg));
  1164. }
  1165. ///// <summary>
  1166. ///// 任务分配
  1167. ///// 确认任务是否可操作完成
  1168. ///// </summary>
  1169. ///// <returns></returns>
  1170. //[HttpPost]
  1171. //[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1172. //public async Task<IActionResult> PostTaskAllocationIsConfirmCompletion(TaskAllocationScoreDto dto)
  1173. //{
  1174. // try
  1175. // {
  1176. // #region 参数验证
  1177. // if (dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  1178. // if (dto.PageId < 1) dto.PageId = 172; //任务指派Id
  1179. // PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  1180. // #region 页面操作权限验证
  1181. // pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  1182. // if (pageFunAuthView.EditAuth == 0) return Ok(JsonView(false, "您没有编辑权限!"));
  1183. // #endregion
  1184. // #endregion
  1185. // var _view = await _taskAllocationRep._TaskConfirmCompletion(dto.PortType, dto.Id);
  1186. // if (_view.Code == 0)
  1187. // {
  1188. // return Ok(JsonView(true, "操作成功!"));
  1189. // }
  1190. // return Ok(JsonView(false, _view.Msg));
  1191. // }
  1192. // catch (Exception ex)
  1193. // {
  1194. // return Ok(JsonView(false, ex.Message));
  1195. // }
  1196. //}
  1197. ///// <summary>
  1198. ///// 任务分配
  1199. ///// 任务确认完成
  1200. ///// </summary>
  1201. ///// <returns></returns>
  1202. //[HttpPost]
  1203. //[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1204. //public async Task<IActionResult> PostTaskAllocationConfirmCompletion(TaskAllocationConfirmCompletionDto dto)
  1205. //{
  1206. // try
  1207. // {
  1208. // #region 参数验证
  1209. // if (dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  1210. // if (dto.PageId < 1) dto.PageId = 172; //任务指派Id
  1211. // PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  1212. // #region 页面操作权限验证
  1213. // pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  1214. // if (pageFunAuthView.EditAuth == 0) return Ok(JsonView(false, "您没有编辑权限!"));
  1215. // #endregion
  1216. // #endregion
  1217. // var _view = await _taskAllocationRep._TaskConfirmCompletion(dto.PortType,dto.Id);
  1218. // if (_view.Code == 0)
  1219. // {
  1220. // return Ok(JsonView(true, "操作成功!"));
  1221. // }
  1222. // return Ok(JsonView(false, _view.Msg));
  1223. // }
  1224. // catch (Exception ex)
  1225. // {
  1226. // return Ok(JsonView(false, ex.Message));
  1227. // }
  1228. //}
  1229. /// <summary>
  1230. /// 任务分配
  1231. /// 任务发布者 任务评分
  1232. /// </summary>
  1233. /// <returns></returns>
  1234. [HttpPost]
  1235. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1236. public async Task<IActionResult> PostTaskAllocationScore(TaskAllocationScoreDto dto)
  1237. {
  1238. #region 参数验证
  1239. if (dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  1240. if (dto.PageId < 1) dto.PageId = 172; //任务指派Id
  1241. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  1242. #region 页面操作权限验证
  1243. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  1244. if (pageFunAuthView.EditAuth == 0) return Ok(JsonView(false, "您没有编辑权限!"));
  1245. #endregion
  1246. #endregion
  1247. var _view = await _taskAllocationRep._TaskScore(dto);
  1248. if (_view.Code == 0)
  1249. {
  1250. //发送消息
  1251. var taskUserData = _taskAllocationRep._sqlSugar.Queryable<Pm_TaskRelevanceUser>().Where(it => it.Id == dto.SubId).First();
  1252. if (taskUserData != null)
  1253. {
  1254. var taskData = _taskAllocationRep._sqlSugar.Queryable<Pm_TaskAllocation>().Where(it => it.Id == taskUserData.TAId).First();
  1255. if (taskData != null)
  1256. {
  1257. string title = $"[{taskData.TaskName}] 进度更新!";
  1258. string content = $"任务评分已完成!若需查看,请前往任务页面查看详情!";
  1259. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.TaskProgressUpdate, title, content, new List<int>() { taskUserData.UserId }); //设置任务人 发送消息
  1260. }
  1261. }
  1262. return Ok(JsonView(true, "操作成功!"));
  1263. }
  1264. return Ok(JsonView(false, _view.Msg));
  1265. }
  1266. /// <summary>
  1267. /// 任务分配
  1268. /// 任务发布者 任务终止
  1269. /// </summary>
  1270. /// <returns></returns>
  1271. [HttpPost]
  1272. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1273. public async Task<IActionResult> PostTaskAllocationTermination(TaskAllocationConfirmCompletionDto dto)
  1274. {
  1275. #region 参数验证
  1276. if (dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  1277. if (dto.PageId < 1) dto.PageId = 172; //任务指派Id
  1278. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  1279. #region 页面操作权限验证
  1280. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  1281. if (pageFunAuthView.EditAuth == 0) return Ok(JsonView(false, "您没有编辑权限!"));
  1282. #endregion
  1283. #endregion
  1284. var _view = await _taskAllocationRep._TaskTermination(dto.Id);
  1285. if (_view.Code == 0)
  1286. {
  1287. //发送消息
  1288. var taskData = _taskAllocationRep._sqlSugar.Queryable<Pm_TaskAllocation>().Where(it => it.Id == dto.Id).First();
  1289. if (taskData != null)
  1290. {
  1291. var taskUserIds = _taskAllocationRep._sqlSugar.Queryable<Pm_TaskRelevanceUser>().Where(it => it.Id == dto.Id).Select(it => it.UserId).ToList();
  1292. taskUserIds.Add(taskData.CreateUserId);
  1293. string title = $"[{taskData.TaskName}] 进度更新!";
  1294. string content = $"任务已终止!若需查看,请前往任务页面查看详情!";
  1295. await GeneralMethod.MessageIssueAndNotification(MessageTypeEnum.TaskProgressUpdate, title, content, taskUserIds); //设置任务人 发送消息
  1296. }
  1297. return Ok(JsonView(true, "操作成功!"));
  1298. }
  1299. return Ok(JsonView(false, _view.Msg));
  1300. }
  1301. /// <summary>
  1302. /// 任务分配
  1303. /// 任务发布者 任务删除
  1304. /// </summary>
  1305. /// <returns></returns>
  1306. [HttpPost]
  1307. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1308. public async Task<IActionResult> PostTaskAllocationDel(TaskAllocationConfirmCompletionDto dto)
  1309. {
  1310. #region 参数验证
  1311. if (dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
  1312. if (dto.PageId < 1) dto.PageId = 172; //任务指派Id
  1313. PageFunAuthViewBase pageFunAuthView = new PageFunAuthViewBase();
  1314. #region 页面操作权限验证
  1315. pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(dto.UserId, dto.PageId);
  1316. if (pageFunAuthView.DeleteAuth == 0) return Ok(JsonView(false, "您没有删除权限!"));
  1317. #endregion
  1318. #endregion
  1319. var _view = await _taskAllocationRep._TaskDel(dto.Id);
  1320. if (_view.Code == 0)
  1321. {
  1322. return Ok(JsonView(true, "操作成功!"));
  1323. }
  1324. return Ok(JsonView(false, _view.Msg));
  1325. }
  1326. #endregion
  1327. #region 团组状态通知
  1328. /// <summary>
  1329. /// 测试
  1330. /// </summary>
  1331. /// <param name="dto"></param>
  1332. /// <returns></returns>
  1333. [HttpPost]
  1334. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1335. public async Task<IActionResult> Test_QIYEWX(PostTourClientListDownloadFile dto)
  1336. {
  1337. //List<string> templist = new List<string>() { 234.ToString() };
  1338. //await AppNoticeLibrary.SendUserMsg_GroupStatus_AuditFee(14090, templist, QiyeWeChatEnum.TestChat);
  1339. //await AppNoticeLibrary.SendUserMsg_GroupShare_ToJob(dto.DiId); ;
  1340. //DeleReminderMessage.PostMessageByWebhook();
  1341. //GroupStatus_UserSimplelistView list = await _qiYeWeChatApiService.GroupStatus_GetUserList();
  1342. //创建群聊
  1343. //List<string> userList1 = new List<string>() { "Feint", "amy.zhu@pan-american-intl.com", "judy.zeng@pan-american-intl.com", "FuHongJin" };
  1344. //List<string> userList2 = new List<string>() { "Feint", "ZhaoYaQi", "LiaoWenYa" };
  1345. //List<string> userList3 = new List<string>() { "Feint", "amy.zhu@pan-american-intl.com", "judy.zeng@pan-american-intl.com", "FuHongJin", "ZhaoYaQi", "LiaoWenYa" };
  1346. //GroupStatus_CreateChatView rst1 = await _qiYeWeChatApiService.GroupStatus_CreateChat("团组通知", "Feint", userList1, "CaiWuChat01");
  1347. //GroupStatus_CreateChatView rst2 = await _qiYeWeChatApiService.GroupStatus_CreateChat("OA通知-国交部", "Feint", userList2, "GuoJiaoLeader01");
  1348. //GroupStatus_CreateChatView rst3 = await _qiYeWeChatApiService.GroupStatus_CreateChat("OA通知-团组(公司客户)", "Feint", userList3, "CompanyCRMChat01");
  1349. //推送消息(模板)
  1350. //List<string> userList = new List<string>() { "Feint", "huaju.liu", "johnny.yang@pan-american-intl.com" };
  1351. //List<string> userList = new List<string>() { "Feint", "johnny.yang@pan-american-intl.com" };
  1352. //GroupStatus_CreateChatView rst1 = await _qiYeWeChatApiService.GroupStatus_CreateChat("团组费用提示", "Feint", userList, "GuoJiaoChat01");
  1353. //团组出发
  1354. //AppNoticeLibrary.SendUserMsg_GroupStatus_Create(2358, userList);
  1355. //费用审核
  1356. //AppNoticeLibrary.SendChatMsg_GroupStatus_ApplyFee(dto.DiId, QiyeWeChatEnum.TestChat);
  1357. //费用审核结果通知(通过情况下发送财务群)
  1358. //List<string> userList = new List<string>() { "234" };
  1359. //AppNoticeLibrary.SendUserMsg_GroupStatus_AuditFee(dto.DiId, userList, QiyeWeChatEnum.CaiWuChat02);
  1360. //4、财务付款时:(1)对应版块人员【单独发,状态为已付款才发】
  1361. //AppNoticeLibrary.SendUserMsg_GroupStatus_PayResult(dto.DiId, userList);
  1362. //团组提醒财务群
  1363. //DateTime dtNow = DateTime.Now;
  1364. //List<Grp_DelegationInfo> listSource = _usersRep.Query<Grp_DelegationInfo>(s => s.IsDel == 0 && s.VisitStartDate >= dtNow).Take(3).ToList();
  1365. //List<Grp_DelegationInfo> listAdd7day = _usersRep.Query<Grp_DelegationInfo>(s => s.IsDel == 0 && s.VisitStartDate >= dtNow).Take(3).ToList();
  1366. //List<Grp_DelegationInfo> listAdd3day = new List<Grp_DelegationInfo>() { };
  1367. //AppNoticeLibrary.SendChatMsg_GroupRemindersToCaiwu(listAdd7day, listAdd3day, QiyeWeChatEnum.TestChat);
  1368. //日付申请提醒财务群
  1369. //AppNoticeLibrary.DailyPayReminders_Create_ToCaiwuChat(dto.DiId, QiyeWeChatEnum.CaiWuChat02);
  1370. //日付申请结果推送用户、成功通知财务群
  1371. //AppNoticeLibrary.DailyPayReminder_Audit_ToUser(dto.DiId, userList, QiyeWeChatEnum.TestChat);
  1372. //AppNoticeLibrary.DailyPayReminder_Pay_ToUser(dto.DiId, userList);
  1373. string q = "";
  1374. DeleReminderMessage.PostMessageByWebhook_CRMStatistics();
  1375. return Ok(JsonView(true, "操作成功!"));
  1376. }
  1377. #endregion
  1378. #region 物资进销存
  1379. /// <summary>
  1380. /// 物资进销存
  1381. /// 基础数据类型
  1382. /// </summary>
  1383. /// <returns></returns>
  1384. [HttpGet]
  1385. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1386. public async Task<IActionResult> GoodsInitDataSource()
  1387. {
  1388. return Ok(await _goodsRep.InitDataSource());
  1389. }
  1390. /// <summary>
  1391. /// 物资进销存
  1392. /// 物品 列表
  1393. /// </summary>
  1394. /// <returns></returns>
  1395. [HttpPost]
  1396. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1397. public async Task<IActionResult> GoodsList(GoodsListDto dto)
  1398. {
  1399. if (dto.PortType < 1 || dto.PortType > 3) return Ok(JsonView(false, MsgTips.Port));
  1400. if (dto.PageIndex < 1 || dto.PageSize < 1) return Ok(JsonView(false, MsgTips.PageIndex));
  1401. return Ok(await _goodsRep.GoodsList(dto));
  1402. }
  1403. /// <summary>
  1404. /// 物资进销存
  1405. /// 物品 详情
  1406. /// </summary>
  1407. /// <returns></returns>
  1408. [HttpGet()]
  1409. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1410. public async Task<IActionResult> GoodsInfo(int portType, int id)
  1411. {
  1412. if (portType < 1 || portType > 3) return Ok(JsonView(false, MsgTips.Port));
  1413. if (id < 1) return Ok(JsonView(false, MsgTips.Id));
  1414. return Ok(await _goodsRep.GoodsInfo(portType, id));
  1415. }
  1416. /// <summary>
  1417. /// 物资进销存
  1418. /// 物品 OP(Add OR Edit)
  1419. /// </summary>
  1420. /// <returns></returns>
  1421. [HttpPost]
  1422. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1423. public async Task<IActionResult> GoodsOP(GoodsOpDto dto)
  1424. {
  1425. var currUserInfo = JwtHelper.SerializeJwt(HttpContext.Request.Headers.Authorization);
  1426. if (currUserInfo == null) return Ok(JsonView(false, "请传入token!"));
  1427. var validator = new GoodsOPDTOValidator();
  1428. var validatorRes = await validator.ValidateAsync(dto);
  1429. if (!validatorRes.IsValid)
  1430. {
  1431. var sb = new StringBuilder();
  1432. foreach (var error in validatorRes.Errors) sb.AppendLine(error.ErrorMessage);
  1433. return Ok(JsonView(false, sb.ToString()));
  1434. }
  1435. return Ok(await _goodsRep.GoodsOp(dto, currUserInfo.UserId));
  1436. }
  1437. /// <summary>
  1438. /// 物资进销存
  1439. /// 物品 Del
  1440. /// </summary>
  1441. /// <returns></returns>
  1442. [HttpDelete("{id}")]
  1443. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1444. public async Task<IActionResult> GoodsDel(int id)
  1445. {
  1446. if (id < 1) return Ok(JsonView(false, MsgTips.Id));
  1447. var currUserInfo = JwtHelper.SerializeJwt(HttpContext.Request.Headers.Authorization);
  1448. if (currUserInfo == null) return Ok(JsonView(false, "请传入token!"));
  1449. return Ok(await _goodsRep.GoodsDel(id, currUserInfo.UserId));
  1450. }
  1451. /// <summary>
  1452. /// 物资进销存
  1453. /// 入库 列表
  1454. /// </summary>
  1455. /// <returns></returns>
  1456. [HttpPost]
  1457. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1458. public async Task<IActionResult> GoodsStorageList(GoodsStorageListDto dto)
  1459. {
  1460. if (dto.PortType < 1 || dto.PortType > 3) return Ok(JsonView(false, MsgTips.Port));
  1461. if (dto.PageIndex < 1 || dto.PageSize < 1) return Ok(JsonView(false, MsgTips.PageIndex));
  1462. return Ok(await _goodsRep.GoodsStorageList(dto));
  1463. }
  1464. /// <summary>
  1465. /// 物资进销存
  1466. /// 入库 详情
  1467. /// </summary>
  1468. /// <returns></returns>
  1469. [HttpGet("{id}")]
  1470. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1471. public async Task<IActionResult> GoodsStorageInfo([FromQuery] int portType, int id)
  1472. {
  1473. if (portType < 1 || portType > 3) return Ok(JsonView(false, MsgTips.Port));
  1474. if (id < 1) return Ok(JsonView(false, MsgTips.Id));
  1475. return Ok(await _goodsRep.GoodsStorageInfo(portType, id));
  1476. }
  1477. /// <summary>
  1478. /// 物资进销存
  1479. /// 入库 OP(Add OR Edit)
  1480. /// </summary>
  1481. /// <returns></returns>
  1482. [HttpPost]
  1483. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1484. public async Task<IActionResult> GoodsStorageOp(GoodsStorageOpDto dto)
  1485. {
  1486. var currUserInfo = JwtHelper.SerializeJwt(HttpContext.Request.Headers.Authorization);
  1487. if (currUserInfo == null) return Ok(JsonView(false, "请传入token!"));
  1488. var validator = new GoodsStorageOpDtoValidator();
  1489. var validatorRes = await validator.ValidateAsync(dto);
  1490. if (!validatorRes.IsValid)
  1491. {
  1492. var sb = new StringBuilder();
  1493. foreach (var error in validatorRes.Errors) sb.AppendLine(error.ErrorMessage);
  1494. return Ok(JsonView(false, sb.ToString()));
  1495. }
  1496. return Ok(await _goodsRep.GoodsStorageOp(dto, currUserInfo.UserId));
  1497. }
  1498. /// <summary>
  1499. /// 物资进销存
  1500. /// 入库 Del
  1501. /// </summary>
  1502. /// <returns></returns>
  1503. [HttpDelete("{id}")]
  1504. //[Authorize]
  1505. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1506. public async Task<IActionResult> GoodsStorageDel(int id)
  1507. {
  1508. var currUserInfo = JwtHelper.SerializeJwt(HttpContext.Request.Headers.Authorization);
  1509. if (currUserInfo == null) return Ok(JsonView(false, "请传入token!"));
  1510. if (id < 1) return Ok(JsonView(false, MsgTips.Id));
  1511. return Ok(await _goodsRep.GoodsStorageDel(id, currUserInfo.UserId));
  1512. }
  1513. /// <summary>
  1514. /// 物资进销存
  1515. /// 领用 List
  1516. /// </summary>
  1517. /// <returns></returns>
  1518. [HttpPost]
  1519. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1520. public async Task<IActionResult> GoodsReceiveList(GoodsReceiveListDTO dto)
  1521. {
  1522. //var currUserInfo = JwtHelper.SerializeJwt(HttpContext.Request.Headers.Authorization);
  1523. //if (currUserInfo == null) return Ok(JsonView(false, "请传入token!"));
  1524. if (dto.PortType < 1 || dto.PortType > 3) return Ok(JsonView(false, MsgTips.Port));
  1525. if (dto.PageIndex < 1 || dto.PageSize < 1) return Ok(JsonView(false, MsgTips.PageIndex));
  1526. return Ok(await _goodsRep.GoodsReceiveList(dto));
  1527. }
  1528. /// <summary>
  1529. /// 物资进销存
  1530. /// 领用详情
  1531. /// </summary>
  1532. /// <returns></returns>
  1533. [HttpGet("{id}")]
  1534. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1535. public async Task<IActionResult> GoodsReceiveInfo([FromQuery] int portType, int id)
  1536. {
  1537. if (portType < 1 || portType > 3) return Ok(JsonView(false, MsgTips.Port));
  1538. if (id < 1) return Ok(JsonView(false, MsgTips.Id));
  1539. return Ok(await _goodsRep.GoodsReceiveInfo(portType, id));
  1540. }
  1541. /// <summary>
  1542. /// 物资进销存
  1543. /// 领用 OP
  1544. /// </summary>
  1545. /// <returns></returns>
  1546. [HttpPost]
  1547. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1548. public async Task<IActionResult> GoodsReceiveOP(GoodsReceiveOpDto dto)
  1549. {
  1550. var currUserInfo = JwtHelper.SerializeJwt(HttpContext.Request.Headers.Authorization);
  1551. if (currUserInfo == null) return Ok(JsonView(false, "请传入token!"));
  1552. var validator = new GoodsReceiveOpDtoValidator();
  1553. var validatorRes = await validator.ValidateAsync(dto);
  1554. if (!validatorRes.IsValid)
  1555. {
  1556. var sb = new StringBuilder();
  1557. foreach (var error in validatorRes.Errors) sb.AppendLine(error.ErrorMessage);
  1558. return Ok(JsonView(false, sb.ToString()));
  1559. }
  1560. return Ok(await _goodsRep.GoodsReceiveOp(dto, currUserInfo.UserId));
  1561. }
  1562. /// <summary>
  1563. /// 物资进销存
  1564. /// 领用 审核
  1565. /// </summary>
  1566. /// <param name="dto"></param>
  1567. /// <returns></returns>
  1568. [HttpPost]
  1569. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1570. public async Task<IActionResult> GoodsReceiveAudit(GoodsReceiveAuditDTO dto)
  1571. {
  1572. var currUserInfo = JwtHelper.SerializeJwt(HttpContext.Request.Headers.Authorization);
  1573. if (currUserInfo == null) return Ok(JsonView(false, "请传入token!"));
  1574. var validator = new GoodsReceiveAuditDTOValidator();
  1575. var validatorRes = await validator.ValidateAsync(dto);
  1576. if (!validatorRes.IsValid)
  1577. {
  1578. var sb = new StringBuilder();
  1579. foreach (var error in validatorRes.Errors) sb.AppendLine(error.ErrorMessage);
  1580. return Ok(JsonView(false, sb.ToString()));
  1581. }
  1582. int[] idArray = dto.Label
  1583. .Split(',')
  1584. .Select(x =>
  1585. {
  1586. if (int.TryParse(x, out var id)) return id;
  1587. return id;
  1588. })
  1589. .ToArray();
  1590. return Ok(await _goodsRep.GoodsReceiveAudit(idArray, currUserInfo.UserId, dto.AuditEnum));
  1591. }
  1592. /// <summary>
  1593. /// 物资进销存
  1594. /// 领用 Del
  1595. /// </summary>
  1596. /// <returns></returns>
  1597. [HttpDelete("{id}")]
  1598. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1599. public async Task<IActionResult> GoodsReceiveDel(int id)
  1600. {
  1601. var currUserInfo = JwtHelper.SerializeJwt(HttpContext.Request.Headers.Authorization);
  1602. if (currUserInfo == null) return Ok(JsonView(false, "请传入token!"));
  1603. if (id < 1) return Ok(JsonView(false, MsgTips.Id));
  1604. return Ok(await _goodsRep.GoodsReceiveDel(id, currUserInfo.UserId));
  1605. }
  1606. #endregion
  1607. #region 员工绩效
  1608. /// <summary>
  1609. /// 员工绩效组成结构获取
  1610. /// </summary>
  1611. /// <param name="userid"></param>
  1612. /// <param name="date"></param>
  1613. /// <returns></returns>
  1614. [HttpGet]
  1615. public IActionResult GetPerformanceList(int userid,string date)
  1616. {
  1617. var jw = JsonView(false);
  1618. if (!DateTime.TryParse(date,out DateTime date_Dt))
  1619. {
  1620. jw.Msg = "日期格式有误!";
  1621. return Ok(jw);
  1622. }
  1623. string sql_CTE = $@"-- 定义递归查询的CTE
  1624. WITH PerAssessmentSettingsCTE AS (
  1625. -- 选择指定ID的记录作为起点
  1626. SELECT
  1627. pac.Id,
  1628. pac.Name,
  1629. pac.AssessmentProportion,
  1630. pac.AssessmentStandard,
  1631. pac.ParentId,
  1632. 1 AS Depth
  1633. FROM
  1634. Per_AssessmentSetting pac
  1635. INNER JOIN
  1636. Per_AssessmentContentSetting pacs
  1637. ON
  1638. pac.id = pacs.assessmentSettingid AND pacs.isdel = 0
  1639. WHERE
  1640. pacs.userid = {userid}
  1641. AND
  1642. pac.isdel = 0
  1643. UNION ALL
  1644. -- 递归部分,选择所有子级记录
  1645. SELECT
  1646. ps.Id,
  1647. ps.Name,
  1648. ps.AssessmentProportion,
  1649. ps.AssessmentStandard,
  1650. ps.ParentId,
  1651. CAST(caste.Depth as int) + 1
  1652. FROM
  1653. Per_AssessmentSetting ps
  1654. INNER JOIN PerAssessmentSettingsCTE caste ON ps.Id = caste.ParentId)
  1655. -- 从CTE中选择最终结果
  1656. SELECT * FROM PerAssessmentSettingsCTE
  1657. OPTION (MAXRECURSION 0); -- 允许无限递归 ";
  1658. var result_CTE = _sqlSugar.Ado.SqlQuery<Per_AssessmentSetting>(sql_CTE);
  1659. var ids = result_CTE.Select(x => x.Id);
  1660. var List = _sqlSugar.Queryable<Per_AssessmentSetting>()
  1661. .LeftJoin<Per_AssessmentContentSetting>((a, b) => a.Id == b.AssessmentSettingId && b.IsDel == 0 && b.UserId == userid)
  1662. .LeftJoin<Per_AssessmentScore>((a, b,c) => b.Id == c.AssessmentContentSettingId && c.IsDel == 0 && c.YearMonth.Year == date_Dt.Year && c.YearMonth.Month == date_Dt.Month)
  1663. .Where((a, b) => a.IsDel == 0 && ids.Contains(a.Id))
  1664. .Select((a, b, c) => new TreeNode
  1665. {
  1666. Id = a.Id,
  1667. ContentId = b.Id,
  1668. Name = a.Name,
  1669. ParentId = a.ParentId,
  1670. AssessmentProportion = a.AssessmentProportion, //占比
  1671. AssessmentStandard = a.AssessmentStandard, //描述
  1672. AssessmentProportionChi = b.AssessmentProportionChi, //占比
  1673. UserId = b.UserId,
  1674. JobId = b.JobId,
  1675. AssessmentSettingId = b.AssessmentSettingId,
  1676. Fixed = b.Fixed,
  1677. TargetValue = b.TargetValue,
  1678. AssessmentProportion_Percentage = a.AssessmentProportion * 100,
  1679. HigherUpAssessment = c.HigherUpAssessment,
  1680. HigherUpConfig = c.HigherUpConfig,
  1681. HigherUpUserId = c.HigherUpUserId,
  1682. Score = c.Score,
  1683. ScoreTotal = c.ScoreTotal,
  1684. SelfAssessment = c.SelfAssessment,
  1685. Status = c.Status,
  1686. YearMonth = c.YearMonth,
  1687. })
  1688. .ToList();
  1689. var rootNodeList = List.Where(x => x.ParentId == 0);
  1690. var rootResult = rootNodeList.Select(x => BuildSubTree(x, List));
  1691. jw.Data = rootResult;
  1692. jw.Code = 200;
  1693. jw.Msg = "成功";
  1694. return Ok(jw);
  1695. }
  1696. private TreeNode BuildSubTree(TreeNode parent, List<TreeNode> nodes)
  1697. {
  1698. var children = nodes
  1699. .Where(n => n.ParentId == parent.Id)
  1700. .Select(n => BuildSubTree(n, nodes))
  1701. .ToList();
  1702. parent.Children = children;
  1703. return parent;
  1704. }
  1705. /// <summary>
  1706. /// 绩效项增改
  1707. /// </summary>
  1708. /// <param name="dto"></param>
  1709. /// <returns></returns>
  1710. [HttpPost]
  1711. public async Task<IActionResult> AssessmentSettingOperationAsync(PerAssessmentSettingOperationDto dto)
  1712. {
  1713. var jw = JsonView(false);
  1714. if (!ModelState.IsValid)
  1715. {
  1716. jw.Msg = "参数错误";
  1717. jw.Data = ModelState;
  1718. return Ok(jw);
  1719. }
  1720. try
  1721. {
  1722. if (dto.ParentId != 0)
  1723. {
  1724. var parent = await _sqlSugar.Queryable<Per_AssessmentSetting>().FirstAsync(x=>x.IsDel == 0 && x.Id == dto.ParentId);
  1725. if (parent == null)
  1726. {
  1727. jw.Msg = "父级节点不存在";
  1728. return Ok(jw);
  1729. }
  1730. }
  1731. var entity = new Per_AssessmentSetting
  1732. {
  1733. Name = dto.Name,
  1734. AssessmentProportion = dto.AssessmentProportion,
  1735. AssessmentStandard = dto.AssessmentStandard,
  1736. ParentId = dto.ParentId,
  1737. Id = dto.Id,
  1738. Remark = dto.Remark,
  1739. };
  1740. jw.Code = 200;
  1741. if (dto.Id == 0)
  1742. {
  1743. entity.CreateUserId = dto.CreateId;
  1744. entity.CreateTime = DateTime.Now;
  1745. await _sqlSugar.Insertable(entity).ExecuteCommandAsync();
  1746. jw.Msg = "添加成功!";
  1747. }
  1748. else
  1749. {
  1750. await _sqlSugar.Updateable(entity).ExecuteCommandAsync();
  1751. jw.Msg = "修改成功!";
  1752. }
  1753. }
  1754. catch (Exception ex)
  1755. {
  1756. jw.Msg = "Api error " + ex.Message;
  1757. jw.Code = 400;
  1758. }
  1759. return Ok(jw);
  1760. }
  1761. /// <summary>
  1762. /// 绩效内容增改
  1763. /// </summary>
  1764. /// <param name="dto"></param>
  1765. /// <returns></returns>
  1766. [HttpPost]
  1767. public IActionResult AssessmentSettingOperationContentAsync(AssessmentSettingOperationContenDto dto)
  1768. {
  1769. var jw = JsonView(false, "", "");
  1770. var entity = new Per_AssessmentContentSetting
  1771. {
  1772. AssessmentProportionChi = dto.AssessmentProportionChi,
  1773. AssessmentSettingId = dto.AssessmentSettingId,
  1774. CreateTime = DateTime.Now,
  1775. CreateUserId = dto.CreateUserId,
  1776. Fixed = dto.Fixed,
  1777. Id = dto.Id,
  1778. JobId = dto.JobId,
  1779. TargetValue = dto.TargetValue,
  1780. UserId = dto.UserId,
  1781. Remark = dto.Remark,
  1782. };
  1783. var entity_Fk = _sqlSugar.Queryable<Per_AssessmentSetting>().First(x => x.Id == dto.AssessmentSettingId && x.IsDel == 0);
  1784. if (entity_Fk == null)
  1785. {
  1786. jw.Msg = "考核设置不存在";
  1787. return Ok(jw);
  1788. }
  1789. try
  1790. {
  1791. if (dto.Id == 0)
  1792. {
  1793. //add
  1794. var insertCount = _sqlSugar.Insertable(entity).ExecuteCommand();
  1795. jw.Msg = "添加成功!";
  1796. }
  1797. else
  1798. {
  1799. //update
  1800. var updateCount = _sqlSugar.Updateable(entity).ExecuteCommand();
  1801. jw.Msg = "修改成功!";
  1802. }
  1803. jw.Code = 200;
  1804. }
  1805. catch (Exception ex)
  1806. {
  1807. jw.Msg = "Api error " + ex.Message;
  1808. jw.Code = 400;
  1809. }
  1810. return Ok(jw);
  1811. }
  1812. /// <summary>
  1813. /// 绩效项查询
  1814. /// </summary>
  1815. /// <param name="dto"></param>
  1816. /// <returns></returns>
  1817. [HttpPost]
  1818. public async Task<IActionResult> QueryAssessmentSettingListOffsetAsync(QueryAssessmentSettingListOffsetAsyncDto dto)
  1819. {
  1820. var jw = JsonView(false);
  1821. RefAsync<int> total = 0;//REF和OUT不支持异步,想要真的异步这是最优解
  1822. var entities = await _sqlSugar.Queryable<Per_AssessmentSetting>()
  1823. .Where(x=>x.IsDel == 0)
  1824. .WhereIF(!string.IsNullOrEmpty(dto.SearchValue), e => e.Name.Contains(dto.SearchValue))
  1825. .ToPageListAsync(dto.pageIndex, dto.pageSize, total);
  1826. var DtoResult = entities.Select(e => new
  1827. {
  1828. e.Id,
  1829. Name = e.Name,
  1830. AssessmentProportion = e.AssessmentProportion,
  1831. AssessmentStandard = e.AssessmentStandard,
  1832. ParentId = e.ParentId,
  1833. Remark = e.Remark
  1834. }).ToList();
  1835. jw.Data = new
  1836. {
  1837. total = total.Value,
  1838. dto.pageIndex,
  1839. dto.pageSize,
  1840. List = DtoResult
  1841. };
  1842. jw.Code = 200;
  1843. jw.Msg = "查询成功!";
  1844. return Ok(jw);
  1845. }
  1846. /// <summary>
  1847. /// 绩效分数保存
  1848. /// </summary>
  1849. /// <param name="dto"></param>
  1850. /// <returns></returns>
  1851. [HttpPost]
  1852. public IActionResult SaveUserAssessmen(SaveUserAssessmenDto dto)
  1853. {
  1854. var jw = JsonView(false,"请传入正确的数据!");
  1855. if (dto.Data.Any()) {
  1856. if (!DateTime.TryParse(dto.AssessmenData, out DateTime yearMonth_Dt))
  1857. {
  1858. jw.Data = "月份参数有误!";
  1859. return Ok(jw);
  1860. }
  1861. try
  1862. {
  1863. var ids = dto.Data.Select(x => x.AssessmentContentSettingId).ToList();
  1864. var QueryContent_DB = _sqlSugar.Queryable<Per_AssessmentContentSetting>()
  1865. .InnerJoin<Per_AssessmentSetting>((a, b) => b.IsDel == 0 && a.AssessmentSettingId == b.Id)
  1866. .Where((a, b) => a.IsDel == 0 && ids.Contains(a.Id))
  1867. .Select((a, b) => new
  1868. {
  1869. ContentSettingId = a.Id,
  1870. SettingId = b.Id,
  1871. a.TargetValue,
  1872. b.AssessmentStandard,
  1873. MergeStr = $"【项名称:{b.Name}/目标值:{a.TargetValue}/评估标准:{b.AssessmentStandard}】",
  1874. a.AssessmentProportionChi,
  1875. b.Name
  1876. })
  1877. .ToList()
  1878. .ToDictionary(x => x.ContentSettingId);
  1879. //删除上级未确认数据
  1880. var expressionWhere = Expressionable
  1881. .Create<Per_AssessmentScore>()
  1882. .And(x => x.YearMonth.Year == yearMonth_Dt.Year && x.YearMonth.Month == yearMonth_Dt.Month)
  1883. .And(x => ids.Contains(x.AssessmentContentSettingId))
  1884. .And(x => x.HigherUpConfig == 0)
  1885. .ToExpression();
  1886. _sqlSugar.BeginTran();
  1887. _sqlSugar.Updateable<Per_AssessmentScore>()
  1888. .Where(expressionWhere)
  1889. .SetColumns(x => new Per_AssessmentScore { IsDel = 1, DeleteUserId = dto.CreateUserId, DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") })
  1890. .ExecuteCommand();
  1891. var entityList = new List<Per_AssessmentScore>();
  1892. foreach (var x in dto.Data)
  1893. {
  1894. if (x.HigherUpAssessment > 100 || x.SelfAssessment > 100)
  1895. {
  1896. jw.Msg = QueryContent_DB[x.AssessmentContentSettingId].Name + "项分数不能超过100。";
  1897. return Ok(jw);
  1898. }
  1899. Per_AssessmentScore item = new Per_AssessmentScore
  1900. {
  1901. AssessmentContentSettingId = x.AssessmentContentSettingId,
  1902. CreateTime = DateTime.Now,
  1903. CreateUserId = dto.CreateUserId,
  1904. Details = QueryContent_DB[x.AssessmentContentSettingId].MergeStr,
  1905. HigherUpAssessment = x.HigherUpAssessment,
  1906. HigherUpUserId = x.LeadersId,
  1907. HigherUpConfig = x.HigherUpAssessment > 0 ? 1 : 0,
  1908. SelfAssessment = x.SelfAssessment,
  1909. IsDel = 0,
  1910. Status = x.Status,
  1911. YearMonth = yearMonth_Dt,
  1912. Score = x.SelfAssessment * 0.3M + x.HigherUpAssessment * 0.7M,
  1913. ScoreTotal = (x.SelfAssessment * 0.3M + x.HigherUpAssessment * 0.7M) * QueryContent_DB[x.AssessmentContentSettingId].AssessmentProportionChi,
  1914. };
  1915. entityList.Add(item);
  1916. }
  1917. var influenceRow = _sqlSugar.Insertable(entityList).ExecuteCommand();
  1918. _sqlSugar.CommitTran();
  1919. jw.Code = 200;
  1920. jw.Msg = "保存成功!";
  1921. jw.Data = $"{influenceRow}条数据操作成功!";
  1922. }
  1923. catch (Exception ex)
  1924. {
  1925. _sqlSugar.RollbackTran();
  1926. jw.Code = 500;
  1927. jw.Data = $"API ERROR ({ex.Message})";
  1928. }
  1929. }
  1930. return Ok(jw);
  1931. }
  1932. /// <summary>
  1933. /// 绩效项删除
  1934. /// </summary>
  1935. /// <param name="dto"></param>
  1936. /// <returns></returns>
  1937. [HttpPost]
  1938. public IActionResult DeleteAssessmentSetting(DeleteAssessmentSettingDto dto)
  1939. {
  1940. var jw = JsonView(false, "删除失败!");
  1941. if (!dto.IdArr.Any())
  1942. {
  1943. jw.Msg = "id不能为空!";
  1944. return Ok(jw);
  1945. }
  1946. var rowCount = _sqlSugar.Updateable<Per_AssessmentSetting>()
  1947. .Where(x => dto.IdArr.Contains(x.Id) && x.IsDel == 0)
  1948. .SetColumns(x => new Per_AssessmentSetting
  1949. {
  1950. IsDel = 1,
  1951. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm"),
  1952. DeleteUserId = dto.UserId,
  1953. })
  1954. .ExecuteCommand();
  1955. jw.Code = 200;
  1956. jw.Msg = $"修改成功!,修改数量{rowCount}";
  1957. return Ok(jw);
  1958. }
  1959. /// <summary>
  1960. /// 绩效内容删除
  1961. /// </summary>
  1962. /// <param name="dto"></param>
  1963. /// <returns></returns>
  1964. [HttpPost]
  1965. public IActionResult DeleteAssessmentContentSetting(DeleteAssessmentSettingDto dto)
  1966. {
  1967. var jw = JsonView(false, "删除失败!");
  1968. if (!dto.IdArr.Any())
  1969. {
  1970. jw.Msg = "id不能为空!";
  1971. return Ok(jw);
  1972. }
  1973. var rowCount = _sqlSugar.Updateable<Per_AssessmentContentSetting>()
  1974. .Where(x => dto.IdArr.Contains(x.Id) && x.IsDel == 0)
  1975. .SetColumns(x => new Per_AssessmentContentSetting
  1976. {
  1977. IsDel = 1,
  1978. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm"),
  1979. DeleteUserId = dto.UserId,
  1980. })
  1981. .ExecuteCommand();
  1982. jw.Code = 200;
  1983. jw.Msg = $"修改成功!,修改数量{rowCount}";
  1984. return Ok(jw);
  1985. }
  1986. #endregion
  1987. #region 企微Api测试
  1988. [HttpPost]
  1989. public async Task<IActionResult> GetCheckin_MonthDataAsync(DateTime start, DateTime end)
  1990. {
  1991. var jw = JsonView(false);
  1992. jw.Data = await _qiYeWeChatApiService.GetCheckin_MonthDataAsync1(start,end);
  1993. return Ok(jw);
  1994. }
  1995. [HttpPost]
  1996. public async Task<IActionResult> QueryAssessmentByUser(QueryAssessmentByUser Dto)
  1997. {
  1998. var jw = JsonView(false);
  1999. var user_entity = _sqlSugar.Queryable<Sys_Users>()
  2000. .First(e => e.Id == Dto.UserId && e.IsDel == 0);
  2001. var start_Bool = DateTime.TryParse(Dto.Start, out DateTime start);
  2002. var end_Bool = DateTime.TryParse(Dto.End, out DateTime end);
  2003. if (!start_Bool || !end_Bool)
  2004. {
  2005. jw.Msg = "时间格式不正确!";
  2006. return Ok(jw);
  2007. }
  2008. jw.Msg = "用户企业微信Id未绑定!";
  2009. if (user_entity != null && !string.IsNullOrEmpty(user_entity.QiyeChatUserId))
  2010. {
  2011. var data = await _qiYeWeChatApiService.QueryAssessmentByUser(start, end, new List<string> { user_entity.QiyeChatUserId });
  2012. jw.Data = data;
  2013. jw.Msg = "查询成功!";
  2014. jw.Code = 200;
  2015. }
  2016. return Ok(jw);
  2017. }
  2018. [HttpPost]
  2019. public IActionResult TempTest(QueryAssessmentSettingListOffsetAsyncDto Dto)
  2020. {
  2021. var jw = JsonView(false);
  2022. return Ok(jw);
  2023. }
  2024. #endregion
  2025. }
  2026. }