PersonnelModuleController.cs 97 KB

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