PersonnelModuleController.cs 97 KB

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