PersonnelModuleController.cs 97 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349
  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. }