GoodsRepository.cs 86 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169
  1. using Aspose.Cells;
  2. using Aspose.Cells.Drawing;
  3. using Aspose.Words.Drawing;
  4. using AutoMapper;
  5. using EyeSoft.IO;
  6. using EyeSoft.Reflection;
  7. using EyeSoft.Runtime.InteropServices;
  8. using Newtonsoft.Json;
  9. using NPOI.OpenXmlFormats.Vml;
  10. using NPOI.SS.UserModel;
  11. using NPOI.Util;
  12. using OASystem.Domain;
  13. using OASystem.Domain.Dtos.PersonnelModule;
  14. using OASystem.Domain.Entities.Groups;
  15. using OASystem.Domain.Entities.PersonnelModule;
  16. using OASystem.Domain.ViewModels.PersonnelModule;
  17. using OASystem.Domain.ViewModels.SmallFun;
  18. using OASystem.Infrastructure.Tools;
  19. using System.Collections.Specialized;
  20. using System.Drawing;
  21. using System.IO;
  22. using System.Security.Policy;
  23. namespace OASystem.Infrastructure.Repositories.PersonnelModule
  24. {
  25. /// <summary>
  26. /// 物品进销存
  27. /// 仓储
  28. /// </summary>
  29. public class GoodsRepository : BaseRepository<Pm_GoodsInfo, GoodsInfoView>
  30. {
  31. private readonly IMapper _mapper;
  32. private JsonView _jv;
  33. private string _url;
  34. private string _excelPath;
  35. public GoodsRepository(SqlSugarClient sqlSugar, IMapper mapper) : base(sqlSugar)
  36. {
  37. _mapper = mapper;
  38. _jv = new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = "操作失败!" };
  39. _url = AppSettingsHelper.Get("ExcelBaseUrl");
  40. _excelPath = $"{AppSettingsHelper.Get("ExcelBasePath")}";
  41. if (!Directory.Exists(_excelPath))
  42. {
  43. Directory.CreateDirectory(_excelPath);
  44. }
  45. }
  46. /// <summary>
  47. /// 基础数据
  48. /// </summary>
  49. /// <returns></returns>
  50. public async Task<JsonView> InitDataSource()
  51. {
  52. var typeData = await _sqlSugar.Queryable<GoodsTypeView>()
  53. .Includes(x => x.SubTypeItems.Where(z => z.IsDel == 0)
  54. //.Select(z => new {
  55. // z.Id,
  56. // z.STid,
  57. // z.Name
  58. //})
  59. .ToList())
  60. .Where(x => x.IsDel == 0 &&
  61. x.Remark.Equals("GoodsType"))
  62. //.Select(x => new {
  63. // x.Id,
  64. // x.Name,
  65. // x.SubTypeItems
  66. //})
  67. .ToListAsync();
  68. var groupData = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  69. .Where(x => x.IsDel == 0)
  70. .Select(x => new
  71. {
  72. id = x.Id,
  73. groupName = x.TeamName
  74. })
  75. .OrderByDescending(x => x.id)
  76. .ToListAsync();
  77. groupData.Insert(0, new { id = 0, groupName = "其他物资(公司内部物资)" });
  78. groupData.Insert(0, new { id = -1, groupName = "拜访客户所使用的物资" });
  79. groupData.Insert(0, new { id = -2, groupName = "库存调整" });
  80. var userData = await _sqlSugar.Queryable<Sys_Users>()
  81. .Where(x => x.IsDel == 0)
  82. .Select(x => new
  83. {
  84. x.Id,
  85. UserName = x.CnName,
  86. })
  87. .ToListAsync();
  88. //库存状态
  89. var stockStatus = new List<dynamic>() {
  90. new { Value = -1, Text = "全部" },
  91. new { Value = 0, Text = "待确认" },
  92. new { Value = 1, Text = "部分确认" },
  93. new { Value = 2, Text = "已确认" },
  94. new { Value = 3, Text = "已拒绝" },
  95. };
  96. //领用出库状态
  97. var receiveStatus = new List<dynamic>() {
  98. new { Value = -1, Text = "全部" },
  99. new { Value = GoodsAuditEnum.Pending, Text = GoodsAuditEnum.Pending.GetEnumDescription() },
  100. new { Value = GoodsAuditEnum.Approved, Text = GoodsAuditEnum.Approved.GetEnumDescription() },
  101. new { Value = GoodsAuditEnum.UnApproved, Text = GoodsAuditEnum.UnApproved.GetEnumDescription() },
  102. new { Value = GoodsAuditEnum.OutPending, Text = GoodsAuditEnum.OutPending.GetEnumDescription() },
  103. new { Value = GoodsAuditEnum.OutConfirming, Text = GoodsAuditEnum.OutConfirming.GetEnumDescription() },
  104. new { Value = GoodsAuditEnum.OutConfirmed, Text = GoodsAuditEnum.OutConfirmed.GetEnumDescription() },
  105. new { Value = GoodsAuditEnum.OutRejected, Text = GoodsAuditEnum.OutRejected.GetEnumDescription() },
  106. };
  107. _jv.Code = StatusCodes.Status200OK;
  108. _jv.Data = new { goodsTypeData = typeData, stockStatus = stockStatus, receiveStatus = receiveStatus, groupNameData = groupData, userNameData = userData };
  109. _jv.Msg = $"操作成功";
  110. return _jv;
  111. }
  112. /// <summary>
  113. /// 物品列表
  114. /// </summary>
  115. /// <param name="dto"></param>
  116. /// <returns></returns>
  117. public async Task<JsonView> GoodsList(GoodsListDto dto)
  118. {
  119. var ids = new List<int>();
  120. if (!string.IsNullOrEmpty(dto.TypeIds))
  121. {
  122. var strArray = dto.TypeIds.Split(',');
  123. foreach (var str in strArray)
  124. {
  125. if (int.TryParse(str, out int id))
  126. {
  127. ids.Add(id);
  128. }
  129. }
  130. }
  131. var auditEnums = new List<GoodsAuditEnum>() {
  132. GoodsAuditEnum.Pending,
  133. GoodsAuditEnum.OutPending,
  134. GoodsAuditEnum.OutConfirming
  135. };
  136. RefAsync<int> total = 0;
  137. var data = await _sqlSugar.Queryable<GoodsListView>()
  138. //.Includes(glv => glv.Receives.Where(z1 => z1.IsDel == 0 && z1.AuditStatus == GoodsAuditEnum.Pending).ToList())
  139. .Includes(glv => glv.Receives.Where(z1 => z1.IsDel == 0 && auditEnums.Contains(z1.AuditStatus)).ToList())
  140. .Includes(glv => glv.TypeData)
  141. .Includes(glv => glv.UserData)
  142. .LeftJoin<Sys_SetData>((glv, sd) => glv.Type == sd.Id)
  143. .LeftJoin<Sys_Users>((glv, sd, u) => glv.LastUpdateUserId == u.Id)
  144. .Where(glv => glv.IsDel == 0)
  145. .WhereIF(ids.Count > 0, glv => ids.Contains(glv.Type))
  146. .WhereIF(!string.IsNullOrEmpty(dto.GoodsName), glv => glv.Name.Contains(dto.GoodsName))
  147. .OrderByDescending(glv => glv.LastUpdateTime)
  148. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  149. var view = data.Select(x => new
  150. {
  151. x.Id,
  152. x.Name,
  153. x.Type,
  154. TypeName = x.TypeData?.Name ?? string.Empty,
  155. LastUpdateUserName = x.UserData?.CnName ?? string.Empty,
  156. x.LastUpdateTime,
  157. StockQuantity = x.StockQuantity - x.WaitAuditQuantity,
  158. x.Unit,
  159. x.StockQuantityLabel,
  160. x.Remark
  161. }).ToList();
  162. _jv.Code = StatusCodes.Status200OK;
  163. _jv.Data = view;
  164. _jv.Count = total;
  165. _jv.Msg = $"操作成功";
  166. return _jv;
  167. }
  168. /// <summary>
  169. /// 物品Info
  170. /// </summary>
  171. /// <param name="portType"></param>
  172. /// <param name="id"></param>
  173. /// <returns></returns>
  174. public async Task<JsonView> GoodsInfo(int portType, int id)
  175. {
  176. var data = await _sqlSugar.Queryable<Pm_GoodsInfo>()
  177. .LeftJoin<Sys_SetData>((gi, sd) => gi.Type == sd.Id)
  178. .LeftJoin<Sys_Users>((gi, sd, u1) => gi.LastUpdateUserId == u1.Id)
  179. .LeftJoin<Sys_Users>((gi, sd, u1, u2) => gi.CreateUserId == u2.Id)
  180. .Where((gi, sd, u1, u2) => gi.IsDel == 0 && gi.Id == id)
  181. .Select((gi, sd, u1, u2) => new
  182. {
  183. gi.Id,
  184. gi.Name,
  185. ParentType = sd.STid,
  186. gi.Type,
  187. TypeName = sd.Name,
  188. gi.SQ_Total,
  189. gi.OQ_Total,
  190. gi.PriceTotal,
  191. gi.StockQuantity,
  192. gi.Unit,
  193. gi.Remark,
  194. LastUpdateUserName = u1.CnName,
  195. gi.LastUpdateTime,
  196. CreateUserName = u2.CnName,
  197. gi.CreateTime,
  198. })
  199. .FirstAsync();
  200. _jv.Code = StatusCodes.Status200OK;
  201. _jv.Data = data;
  202. _jv.Msg = $"操作成功";
  203. return _jv;
  204. }
  205. /// <summary>
  206. /// 物品 OP(Create Or Edit)
  207. /// </summary>
  208. /// <param name="dto"></param>
  209. /// <param name="currUserId"></param>
  210. /// <returns></returns>
  211. public async Task<JsonView> GoodsOp(GoodsOpDto dto, int currUserId)
  212. {
  213. var info = new Pm_GoodsInfo()
  214. {
  215. Id = dto.Id,
  216. Name = dto.Name,
  217. Type = dto.Type,
  218. SQ_Total = 0,
  219. OQ_Total = 0,
  220. PriceTotal = 0,
  221. StockQuantity = 0,
  222. Unit = dto.Unit,
  223. Remark = dto.Remark,
  224. LastUpdateUserId = currUserId,
  225. LastUpdateTime = DateTime.Now,
  226. CreateUserId = currUserId
  227. };
  228. if (dto.Id > 0) //Edit
  229. {
  230. var upd = await _sqlSugar.Updateable(info)
  231. .UpdateColumns(x => new
  232. {
  233. x.Name,
  234. x.Type,
  235. x.Unit,
  236. x.Remark,
  237. x.LastUpdateUserId,
  238. x.LastUpdateTime,
  239. })
  240. .ExecuteCommandAsync();
  241. if (upd > 0)
  242. {
  243. _jv.Msg = $"修改成功!";
  244. _jv.Code = StatusCodes.Status200OK;
  245. return _jv;
  246. }
  247. }
  248. else if (dto.Id < 1) //添加
  249. {
  250. var selectInfo = await _sqlSugar.Queryable<Pm_GoodsInfo>().FirstAsync(x => x.Name.Equals(info.Name));
  251. if (selectInfo != null)
  252. {
  253. _jv.Msg = $"“{info.Name}”该物品已存在,请勿重新添加!";
  254. return _jv;
  255. }
  256. var add = await _sqlSugar.Insertable(info).ExecuteCommandAsync();
  257. if (add > 0)
  258. {
  259. _jv.Msg = $"添加成功!";
  260. _jv.Code = StatusCodes.Status200OK;
  261. return _jv;
  262. }
  263. }
  264. return _jv;
  265. }
  266. /// <summary>
  267. /// 物品 Del
  268. /// </summary>
  269. /// <param name="id"></param>
  270. /// <param name="currUserId"></param>
  271. /// <returns></returns>
  272. public async Task<JsonView> GoodsDel(int id, int currUserId)
  273. {
  274. _sqlSugar.BeginTran();
  275. var goods = await _sqlSugar.Updateable<Pm_GoodsInfo>()
  276. .SetColumns(x => new Pm_GoodsInfo()
  277. {
  278. IsDel = 1,
  279. DeleteUserId = currUserId,
  280. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  281. })
  282. .Where(x => x.Id == id)
  283. .ExecuteCommandAsync();
  284. if (goods < 1)
  285. {
  286. _sqlSugar.RollbackTran();
  287. _jv.Msg = $"操作失败";
  288. return _jv;
  289. }
  290. var goodsStorage = await _sqlSugar.Updateable<Pm_GoodsStorage>()
  291. .SetColumns(x => new Pm_GoodsStorage()
  292. {
  293. IsDel = 1,
  294. DeleteUserId = currUserId,
  295. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  296. })
  297. .Where(x => x.Id == id)
  298. .ExecuteCommandAsync();
  299. var goodsReceive = await _sqlSugar.Updateable<Pm_GoodsReceive>()
  300. .SetColumns(x => new Pm_GoodsReceive()
  301. {
  302. IsDel = 1,
  303. DeleteUserId = currUserId,
  304. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
  305. })
  306. .Where(x => x.Id == id)
  307. .ExecuteCommandAsync();
  308. _sqlSugar.CommitTran();
  309. _jv.Code = StatusCodes.Status200OK;
  310. _jv.Msg = $"操作成功!";
  311. return _jv;
  312. }
  313. /// <summary>
  314. /// 物品入库列表(带审核)
  315. /// </summary>
  316. /// <param name="dto"></param>
  317. /// <returns></returns>
  318. public async Task<JsonView> GoodsStorageList(GoodsStorageListDto dto)
  319. {
  320. string reqAuditLabel = dto.AuditLabel;
  321. var auditLabel = Array.Empty<int>();
  322. int userId = dto.CurrUserId;
  323. if (!string.IsNullOrEmpty(reqAuditLabel))
  324. {
  325. if (!reqAuditLabel.Contains("-1"))
  326. {
  327. auditLabel = reqAuditLabel
  328. .Split(',')
  329. .Select(x =>
  330. {
  331. if (int.TryParse(x, out var id)) return id;
  332. return id;
  333. })
  334. .ToArray();
  335. }
  336. }
  337. RefAsync<int> total = 0;
  338. var data = await _sqlSugar.Queryable<Pm_GoodsStorage>()
  339. .LeftJoin<Pm_GoodsInfo>((gs, gi) => gs.GoodsId == gi.Id)
  340. .LeftJoin<Sys_Users>((gs, gi, u) => gs.CreateUserId == u.Id)
  341. .LeftJoin<Sys_Users>((gs, gi, u, u1) => gs.StorageUserId == u1.Id)
  342. .Where((gs, gi, u, u1) => gs.IsDel == 0)
  343. .WhereIF(dto.GoodsId > 0, (gs, gi, u, u1) => gs.GoodsId == dto.GoodsId)
  344. .WhereIF(auditLabel.Length > 0, (gs, gi, u, u1) => auditLabel.Contains((int)gs.ConfirmStatus))
  345. .WhereIF(!string.IsNullOrEmpty(dto.GoodsName), (gs, gi, u, u1) => gi.Name.Contains(dto.GoodsName))
  346. .WhereIF(!string.IsNullOrEmpty(dto.BatchNo), (gs, gi, u, u1) => gs.BatchNo.Contains(dto.BatchNo))
  347. .Select((gs, gi, u, u1) => new GoodsStorageListView()
  348. {
  349. Id = gs.Id,
  350. GoodsId = gs.GoodsId,
  351. BatchNo = gs.BatchNo,
  352. GoodsName = gi.Name,
  353. Quantity = gs.Quantity,
  354. UnitPrice = gs.UnitPrice,
  355. TotalPrice = gs.TotalPrice,
  356. SupplierName = gs.SupplierName,
  357. SupplierTel = gs.SupplierTel,
  358. SupplierAddress = gs.SupplierAddress,
  359. SupplierSource = gs.SupplierSource,
  360. StorageUserName = u1.CnName,
  361. StorageTime = gs.StorageTime,
  362. CreateUserName = u.CnName,
  363. ConfirmStatus = gs.ConfirmStatus,
  364. StatusDesc = gs.StatusDesc,
  365. CreateTime = gs.CreateTime,
  366. Remark = gs.Remark
  367. })
  368. .OrderByDescending(gs => gs.CreateTime)
  369. .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  370. var auditList = GoodsStorageConfirmAuditDep(1);
  371. var hrAuditPer = false;
  372. var finAuditPer = false;
  373. var hrAuditInfo = auditList.FirstOrDefault(x => x.AuditDep == GoodsAuditDepEnum.Hr);
  374. var finAuditInfo = auditList.FirstOrDefault(x => x.AuditDep == GoodsAuditDepEnum.Financial);
  375. if (hrAuditInfo != null)
  376. {
  377. if (hrAuditInfo.AuditorIds.Any(x => x == userId))
  378. {
  379. hrAuditPer = true;
  380. }
  381. }
  382. if (finAuditInfo != null)
  383. {
  384. if (finAuditInfo.AuditorIds.Any(x => x == userId))
  385. {
  386. finAuditPer = true;
  387. }
  388. }
  389. foreach (var item in data)
  390. {
  391. item.AuditPers = new GoodsStorageAuditPerView[] {
  392. new (){ AuditPer = hrAuditPer, AuditDep = GoodsAuditDepEnum.Hr, ButtonText = GoodsAuditDepEnum.Hr.GetEnumDescription()},
  393. new (){ AuditPer = finAuditPer, AuditDep = GoodsAuditDepEnum.Financial, ButtonText = GoodsAuditDepEnum.Financial.GetEnumDescription()}
  394. };
  395. }
  396. _jv.Code = StatusCodes.Status200OK;
  397. _jv.Data = data;
  398. _jv.Count = total;
  399. _jv.Msg = $"操作成功";
  400. return _jv;
  401. }
  402. /// <summary>
  403. /// 物品入库详情
  404. /// </summary>
  405. /// <param name="id"></param>
  406. /// <returns></returns>
  407. public async Task<JsonView> GoodsStorageInfo(int portType, int id)
  408. {
  409. var data = await _sqlSugar.Queryable<Pm_GoodsStorage>()
  410. .LeftJoin<Pm_GoodsInfo>((gs, gi) => gs.GoodsId == gi.Id)
  411. .LeftJoin<Sys_Users>((gs, gi, u) => gs.CreateUserId == u.Id)
  412. .LeftJoin<Sys_Users>((gs, gi, u, u1) => gs.StorageUserId == u1.Id)
  413. .Where((gs, gi, u, u1) => gs.IsDel == 0)
  414. .WhereIF(id > 0, (gs, gi, u, u1) => gs.Id == id)
  415. .Select((gs, gi, u, u1) => new
  416. {
  417. gs.Id,
  418. gs.GoodsId,
  419. GoodsName = gi.Name,
  420. gs.Quantity,
  421. gs.UnitPrice,
  422. gs.TotalPrice,
  423. gs.SupplierName,
  424. gs.SupplierTel,
  425. gs.SupplierAddress,
  426. gs.SupplierSource,
  427. gs.ReceiveQuantity,
  428. gs.StorageUserId,
  429. StorageUser = u1.CnName,
  430. gs.StorageTime,
  431. CreateUserName = u.CnName,
  432. gs.CreateUserId,
  433. gs.CreateTime,
  434. gs.Remark,
  435. //gs.IsInConfirm
  436. })
  437. .FirstAsync();
  438. _jv.Msg = $"操作成功!";
  439. _jv.Code = StatusCodes.Status200OK;
  440. _jv.Data = data;
  441. return _jv;
  442. }
  443. /// <summary>
  444. /// 物品入库 操作(Create Or Edit)
  445. /// </summary>
  446. /// <param name="dto"></param>
  447. /// <param name="currUserId"></param>
  448. /// <returns></returns>
  449. public async Task<JsonView> GoodsStorageOp(GoodsStorageOpDto dto, int currUserId)
  450. {
  451. var info = _mapper.Map<Pm_GoodsStorage>(dto);
  452. info.CreateUserId = currUserId;
  453. info.BatchNo = DateTime.Now.ToString("yyyyMMddHHmmssfff");
  454. _sqlSugar.BeginTran();
  455. if (info.Id > 0) //修改
  456. {
  457. var selectInfo = await _sqlSugar.Queryable<Pm_GoodsStorage>()
  458. .Where(x => x.Id == dto.Id)
  459. .FirstAsync();
  460. var auditStatus = selectInfo.ConfirmStatus;
  461. if (auditStatus == GoodsConfirmEnum.Confirmed || auditStatus == GoodsConfirmEnum.PartConfirmed)
  462. {
  463. _sqlSugar.RollbackTran();
  464. _jv.Msg = $"该条入库信息已确认或部分确认审核,不可更改!如若更改请取消已确认或部分确认审核状态!";
  465. return _jv;
  466. }
  467. var storageEdit = await _sqlSugar.Updateable(info)
  468. .UpdateColumns(x => new
  469. {
  470. x.Quantity,
  471. x.UnitPrice,
  472. x.TotalPrice,
  473. x.SupplierName,
  474. x.SupplierTel,
  475. x.SupplierAddress,
  476. x.SupplierSource,
  477. x.StorageUserId,
  478. x.StorageTime
  479. })
  480. .Where(x => x.Id == dto.Id)
  481. .ExecuteCommandAsync();
  482. if (storageEdit < 1)
  483. {
  484. _sqlSugar.RollbackTran();
  485. _jv.Msg = $"修改失败!";
  486. return _jv;
  487. }
  488. }
  489. else if (info.Id < 1) //添加
  490. {
  491. info.ConfirmStatus = GoodsConfirmEnum.WaitConfirm;
  492. var storageAddId = await _sqlSugar.Insertable(info).ExecuteReturnIdentityAsync();
  493. if (storageAddId < 1)
  494. {
  495. _sqlSugar.RollbackTran();
  496. _jv.Msg = $"添加失败!";
  497. return _jv;
  498. }
  499. //入库确认默认状态
  500. List<Pm_GoodsAudit> auditInfos = GoodsStorageConfirm(1, storageAddId, info.CreateUserId);
  501. if (auditInfos.Any())
  502. {
  503. await _sqlSugar.Insertable(auditInfos).ExecuteCommandAsync();
  504. }
  505. }
  506. _sqlSugar.CommitTran();
  507. _jv.Msg = $"操作成功!";
  508. _jv.Code = StatusCodes.Status200OK;
  509. return _jv;
  510. }
  511. /// <summary>
  512. /// 物品入库 确认操作-默认审核部门
  513. /// </summary>
  514. /// <param name="auditType">
  515. /// 审核类型
  516. /// 1.入库 2.出库
  517. /// </param>
  518. /// <param name="dataId">dataId</param>
  519. /// <param name="currUserId">审核人</param>
  520. /// <returns></returns>
  521. public List<Pm_GoodsAudit> GoodsStorageConfirm(int auditType,int dataId,int currUserId)
  522. {
  523. var goodsAuditList = new List<Pm_GoodsAudit>();
  524. goodsAuditList.Add(new Pm_GoodsAudit(auditType, GoodsAuditDepEnum.Hr, dataId, GoodsConfirmEnum.WaitConfirm, currUserId));
  525. goodsAuditList.Add(new Pm_GoodsAudit(auditType, GoodsAuditDepEnum.Financial, dataId, GoodsConfirmEnum.WaitConfirm, currUserId));
  526. return goodsAuditList;
  527. }
  528. /// <summary>
  529. /// 物品入库 确认操作
  530. /// </summary>
  531. /// <param name="dto"></param>
  532. /// <returns></returns>
  533. public async Task<JsonView> GoodsStorageConfirmStatusChange(GoodsStorageConfirmDto dto,int currUserId)
  534. {
  535. int gsId = dto.Id;
  536. var auditDep = dto.AuditDep;
  537. if (gsId < 1)
  538. {
  539. _jv.Msg = string.Format("{0}",MsgTips.Id);
  540. return _jv;
  541. }
  542. if (currUserId < 1)
  543. {
  544. _jv.Msg = string.Format("{0}", MsgTips.UserId);
  545. return _jv;
  546. }
  547. //验证审核部门
  548. (bool auditPer, GoodsAuditDepEnum goodsAuditDep) = GoodsAuditDep(currUserId, auditDep, 1);
  549. if (!auditPer)
  550. {
  551. _jv.Msg = string.Format("未分配入库确认权限!");
  552. return _jv;
  553. }
  554. //入库确认 更改审核状态
  555. _sqlSugar.BeginTran();
  556. var info = await _sqlSugar.Queryable<Pm_GoodsStorage>().Where(x =>x.IsDel == 0 && x.Id == gsId).FirstAsync();
  557. if (info == null)
  558. {
  559. _jv.Msg = string.Format("入库信息不存在!");
  560. return _jv;
  561. }
  562. var preChangeStatus = info.ConfirmStatus;
  563. if (preChangeStatus == dto.ConfirmStatus)
  564. {
  565. _jv.Msg = string.Format("“{0}”已操作,请勿重复该操作!", dto.ConfirmStatus.GetEnumDescription());
  566. return _jv;
  567. }
  568. var preInfos = await _sqlSugar.Queryable<Pm_GoodsAudit>().Where(x => x.IsDel == 0 && x.DataId == gsId).ToListAsync();
  569. var auditInfo = preInfos.FirstOrDefault(x => x.Dep == goodsAuditDep);
  570. if (auditInfo != null)
  571. {
  572. //移除部门审核状态
  573. preInfos.Remove(auditInfo);
  574. auditInfo.AuditStatus = dto.ConfirmStatus;
  575. auditInfo.AuditUserId = currUserId;
  576. auditInfo.AuditTime = DateTime.Now;
  577. var updStatus = await _sqlSugar.Updateable(auditInfo)
  578. .UpdateColumns(x => new {x.AuditStatus, x.AuditUserId, x.AuditTime })
  579. .ExecuteCommandAsync();
  580. if (updStatus < 1)
  581. {
  582. _sqlSugar.RollbackTran();
  583. _jv.Msg = string.Format("入库确认失败!");
  584. return _jv;
  585. }
  586. }
  587. else
  588. {
  589. auditInfo = new Pm_GoodsAudit(1, goodsAuditDep, gsId, dto.ConfirmStatus, currUserId, currUserId);
  590. var addStatus = await _sqlSugar.Insertable(auditInfo).ExecuteCommandAsync();
  591. if (addStatus < 1)
  592. {
  593. _sqlSugar.RollbackTran();
  594. _jv.Msg = string.Format("入库确认失败!");
  595. return _jv;
  596. }
  597. }
  598. preInfos.Add(auditInfo);
  599. //入库确认 更改入库状态及扣或增加除库存数、金额
  600. var confirmStatus = GoodsConfirmEnum.WaitConfirm;
  601. if (preInfos.Where(x => x.AuditStatus == GoodsConfirmEnum.Confirmed).Count() >= 2)
  602. {
  603. confirmStatus = GoodsConfirmEnum.Confirmed;
  604. }else if (preInfos.Where(x => x.AuditStatus == GoodsConfirmEnum.Confirmed).Count() >= 1)
  605. {
  606. confirmStatus = GoodsConfirmEnum.PartConfirmed;
  607. }
  608. else if (preInfos.Where(x => x.AuditStatus == GoodsConfirmEnum.UnApproved).Count() > 0)
  609. {
  610. confirmStatus = GoodsConfirmEnum.UnApproved;
  611. }
  612. else if (preInfos.Where(x => x.AuditStatus == GoodsConfirmEnum.PartConfirmed).Count() > 0)
  613. {
  614. confirmStatus = GoodsConfirmEnum.PartConfirmed;
  615. }
  616. //入库状态描述
  617. var statusDesc = new StringBuilder();
  618. foreach (var preInfo in preInfos)
  619. {
  620. string depName = preInfo.Dep.GetEnumDescription(),
  621. auditStatus = preInfo.AuditStatus.GetEnumDescription(),
  622. auditUserName = preInfo.AuditUserId > 0 ? _sqlSugar.Queryable<Sys_Users>().First(x => x.Id == preInfo.AuditUserId)?.CnName ?? "-" : "-",
  623. auditTime = preInfo.AuditUserId > 0 ? preInfo.AuditTime.ToString("yyyy-MM-dd HH:mm:ss") : "-";
  624. statusDesc.Append(string.Format("{0}:状态:{1} 审核人:{2} 审核时间:{3};<br/>", depName, auditStatus, auditUserName, auditTime));
  625. }
  626. //更改入库状态及描述
  627. info.ConfirmStatus = confirmStatus;
  628. info.StatusDesc = statusDesc.ToString();
  629. var goodsStorageUpd = await _sqlSugar.Updateable(info)
  630. .UpdateColumns(x => new
  631. {
  632. x.ConfirmStatus,
  633. x.StatusDesc,
  634. })
  635. .Where(x => x.Id == info.Id)
  636. .ExecuteCommandAsync();
  637. if (goodsStorageUpd < 1)
  638. {
  639. _sqlSugar.RollbackTran();
  640. _jv.Msg = $"入库确认状态更改失败!";
  641. return _jv;
  642. }
  643. //入库审核通过数量、金额
  644. decimal auditQuantity = info.Quantity,
  645. auditTotalPrice = info.TotalPrice;
  646. var goodsInfo = await _sqlSugar.Queryable<Pm_GoodsInfo>().FirstAsync(x => x.Id == info.GoodsId);
  647. goodsInfo.LastUpdateUserId = currUserId;
  648. goodsInfo.LastUpdateTime = DateTime.Now;
  649. if (confirmStatus == GoodsConfirmEnum.Confirmed) // 确认状态
  650. {
  651. //更改后的状态和更改前的状态不一致时 更改库存数、金额
  652. if (preChangeStatus != confirmStatus) //
  653. {
  654. goodsInfo.SQ_Total += auditQuantity;
  655. goodsInfo.StockQuantity += auditQuantity;
  656. goodsInfo.PriceTotal += auditTotalPrice;
  657. }
  658. }
  659. else //其他状态 拒绝、部分确认、等待确认
  660. {
  661. //更改前状态为确认状态时,减库存数、金额
  662. if (preChangeStatus == GoodsConfirmEnum.Confirmed)
  663. {
  664. goodsInfo.SQ_Total -= auditQuantity;
  665. goodsInfo.StockQuantity -= auditQuantity;
  666. goodsInfo.PriceTotal -= auditTotalPrice;
  667. }
  668. }
  669. var goodsUpd = await _sqlSugar.Updateable(goodsInfo)
  670. .UpdateColumns(x => new
  671. {
  672. x.SQ_Total,
  673. x.StockQuantity,
  674. x.PriceTotal,
  675. x.LastUpdateUserId,
  676. x.LastUpdateTime,
  677. })
  678. .Where(x => x.Id == info.GoodsId)
  679. .ExecuteCommandAsync();
  680. if (goodsUpd > 0)
  681. {
  682. _sqlSugar.CommitTran();
  683. _jv.Msg = $"操作成功!";
  684. _jv.Code = StatusCodes.Status200OK;
  685. return _jv;
  686. }
  687. _sqlSugar.RollbackTran();
  688. _jv.Msg = $"操作失败!";
  689. return _jv;
  690. }
  691. /// <summary>
  692. /// 获取物品审核部门
  693. /// </summary>
  694. /// <param name="userId"> userId </param>
  695. /// <param name="auditDepEnum"> 审核部门枚举 </param>
  696. /// <param name="auditType">
  697. /// 指定审核类型(入库/出库)
  698. /// 1:入库审核
  699. /// 2:出库审核
  700. /// </param>
  701. /// <returns></returns>
  702. public (bool, GoodsAuditDepEnum) GoodsAuditDep(int userId,GoodsAuditDepEnum auditDepEnum,int auditType = 1)
  703. {
  704. if (userId < 1) return (false, GoodsAuditDepEnum.Hr);
  705. var auditList = GoodsStorageConfirmAuditDep(1);
  706. if (auditType == 1)
  707. {
  708. if (auditList.Any(x => x.AuditDep == auditDepEnum && x.AuditorIds.Contains(userId)))
  709. {
  710. return (true, auditDepEnum);
  711. }
  712. }
  713. return (false, GoodsAuditDepEnum.Hr);
  714. }
  715. /// <summary>
  716. /// 物品审核部门列表
  717. /// </summary>
  718. /// <param name="auditType">
  719. /// 指定审核类型(入库/出库)
  720. /// 1:入库审核
  721. /// 2:出库审核
  722. /// </param>
  723. /// <returns></returns>
  724. public List<GoodsAuditDepView> GoodsStorageConfirmAuditDep(int auditType=1)
  725. {
  726. var auditList = new List<GoodsAuditDepView>();
  727. var hrAuditorIds = new GoodsAuditDepView()
  728. {
  729. AuditDep = GoodsAuditDepEnum.Hr,
  730. AuditorIds = new int[] {
  731. 343, // 陈湘
  732. 374, // 罗颖
  733. 208, // 雷怡
  734. }
  735. };
  736. var finAuditorIds = new GoodsAuditDepView()
  737. {
  738. AuditDep = GoodsAuditDepEnum.Financial,
  739. AuditorIds = new int[] {
  740. 187, // 曾艳 、
  741. 281, // 伏虹瑾
  742. 208, // 雷怡
  743. }
  744. };
  745. if (auditType == 1)//入库
  746. {
  747. hrAuditorIds.AuditorIds = new int[] {
  748. //343, // 陈湘
  749. 374, // 罗颖
  750. 208, // 雷怡
  751. };
  752. auditList.Add(hrAuditorIds);
  753. auditList.Add(finAuditorIds);
  754. }
  755. else if (auditType == 2) //出库
  756. {
  757. auditList.Add(hrAuditorIds);
  758. auditList.Add(finAuditorIds);
  759. }
  760. return auditList;
  761. }
  762. /// <summary>
  763. /// 物品入库 Del
  764. /// </summary>
  765. /// <param name="id"></param>
  766. /// <returns></returns>
  767. public async Task<JsonView> GoodsStorageDel(int id, int userId)
  768. {
  769. var storageInfo = await _sqlSugar
  770. .Queryable<Pm_GoodsStorage>()
  771. .Where(x => x.Id == id)
  772. .FirstAsync();
  773. if (storageInfo == null) return _jv;
  774. var auditStatus = storageInfo.ConfirmStatus;
  775. if (auditStatus == GoodsConfirmEnum.Confirmed || auditStatus == GoodsConfirmEnum.PartConfirmed)
  776. {
  777. _sqlSugar.RollbackTran();
  778. _jv.Msg = $"该条入库信息已确认或部分确认审核,不可删除!如若删除请取消已确认或部分确认审核状态!";
  779. return _jv;
  780. }
  781. decimal delAgoQuantity = storageInfo.Quantity,
  782. delAgoTotalPrice = storageInfo.TotalPrice;
  783. var goodsId = storageInfo.GoodsId;
  784. _sqlSugar.BeginTran();
  785. var storageDel = await _sqlSugar.Updateable<Pm_GoodsStorage>()
  786. .SetColumns(x => new Pm_GoodsStorage
  787. {
  788. DeleteUserId = userId,
  789. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  790. IsDel = 1
  791. })
  792. .Where(x => x.Id == id)
  793. .ExecuteCommandAsync();
  794. if (storageDel < 1)
  795. {
  796. _sqlSugar.RollbackTran();
  797. _jv.Msg = $"操作失败!";
  798. return _jv;
  799. }
  800. var goodsInfo = await _sqlSugar.Queryable<Pm_GoodsInfo>().FirstAsync(x => x.Id == goodsId);
  801. goodsInfo.SQ_Total = goodsInfo.SQ_Total - delAgoQuantity;
  802. goodsInfo.StockQuantity = goodsInfo.StockQuantity - delAgoQuantity;
  803. goodsInfo.PriceTotal = goodsInfo.PriceTotal - delAgoTotalPrice;
  804. goodsInfo.LastUpdateUserId = userId;
  805. goodsInfo.LastUpdateTime = DateTime.Now;
  806. var goodsEdit = await _sqlSugar.Updateable(goodsInfo)
  807. .UpdateColumns(x => new
  808. {
  809. x.SQ_Total,
  810. x.StockQuantity,
  811. x.PriceTotal,
  812. x.LastUpdateUserId,
  813. x.LastUpdateTime,
  814. })
  815. .Where(x => x.Id == goodsId)
  816. .ExecuteCommandAsync();
  817. if (goodsEdit > 0)
  818. {
  819. _sqlSugar.CommitTran();
  820. _jv.Msg = $"操作成功!";
  821. _jv.Code = StatusCodes.Status200OK;
  822. return _jv;
  823. }
  824. _sqlSugar.RollbackTran();
  825. _jv.Msg = $"操作失败!";
  826. return _jv;
  827. }
  828. /// <summary>
  829. /// 物品入库
  830. /// excelDownload
  831. /// </summary>
  832. /// <param name="dto"></param>
  833. /// <returns></returns>
  834. public async Task<JsonView> GoodsStorageExcelDownload()
  835. {
  836. var fileName = $"物资入库{Guid.NewGuid()}.xlsx";
  837. var excelTempPath = $"{_excelPath}Template/物资入库Temp.xlsx";
  838. if (!File.Exists(excelTempPath))
  839. {
  840. _jv.Code = StatusCodes.Status204NoContent;
  841. _jv.Msg = $"该模板文件不存在!";
  842. return _jv;
  843. }
  844. _url = $"{_url}Office/Excel/GoodsFiles/";
  845. _excelPath = $"{_excelPath}GoodsFiles";
  846. if (!Directory.Exists(_excelPath))
  847. {
  848. Directory.CreateDirectory(_excelPath);
  849. }
  850. //入库记录
  851. var storageData = await _sqlSugar.Queryable<Pm_GoodsStorage>()
  852. .LeftJoin<Sys_Users>((gs, su) => gs.StorageUserId == su.Id)
  853. .Where((gs, su) => gs.IsDel == 0)
  854. .Select((gs, su) => new
  855. {
  856. gs.GoodsId,
  857. gs.Quantity,
  858. su.CnName,
  859. gs.StorageTime
  860. })
  861. .ToListAsync();
  862. //出库记录
  863. var receiveData = await _sqlSugar.Queryable<Pm_GoodsReceive>()
  864. .LeftJoin<Sys_Users>((gr, su) => gr.CreateUserId == su.Id)
  865. .Where((gr, su) => gr.IsDel == 0)
  866. .Select((gr, su) => new
  867. {
  868. gr.GoodsId,
  869. gr.Quantity,
  870. su.CnName,
  871. gr.CreateTime,
  872. gr.Reason
  873. })
  874. .ToListAsync();
  875. var data = await _sqlSugar.Queryable<Pm_GoodsInfo>()
  876. .Where(gi => gi.IsDel == 0)
  877. .Select(gi => new GoodsStorageExcelDownloadView
  878. {
  879. Id = gi.Id,
  880. Name = gi.Name,
  881. SQ_Total = gi.SQ_Total,
  882. OQ_Total = gi.OQ_Total,
  883. StockQuantity = gi.StockQuantity,
  884. Unit = gi.Unit
  885. })
  886. .ToListAsync();
  887. foreach (var item in data)
  888. {
  889. var storageData1 = storageData.Where(x => x.GoodsId == item.Id).ToList();
  890. if (storageData1.Any())
  891. {
  892. item.SQ_Total1 = storageData1.Sum(x => x.Quantity);
  893. item.SQ_Total -= item.SQ_Total1;
  894. item.StorageLabel = string.Join("\r\n", storageData1.Select(x => "数量:【" + x.Quantity.ToString("#0.00") + "】 入库人:【" + x.CnName + "】 入库时间:【" + x.StorageTime + "】").ToList());
  895. }
  896. var receiveData1 = receiveData.Where(x => x.GoodsId == item.Id).ToList();
  897. if (receiveData1.Any())
  898. {
  899. item.ReceiveLabel = string.Join("\r\n", receiveData1.Select(x => "数量:【" + x.Quantity.ToString("#0.00") + "】 申请人:【" + x.CnName + "】 申请时间:【" + x.CreateTime.ToString("yyyy-MM-dd HH:mm:ss") + "】 原因:【" + x.Reason + "】").ToList());
  900. }
  901. }
  902. //载入模板
  903. WorkbookDesigner designer = new WorkbookDesigner();
  904. designer.Workbook = new Workbook(excelTempPath);
  905. designer.SetDataSource("Export", data);
  906. designer.Process();
  907. #region 渲染Cell批注
  908. var sheet = designer.Workbook.Worksheets[0];
  909. for (int i = 0; i < data.Count; i++)
  910. {
  911. string storageComment = $"C{i + 2}",
  912. receiveComment = $"D{i + 2}",
  913. storageCommentText = data[i].StorageLabel,
  914. receiveCommentText = data[i].ReceiveLabel;
  915. if (!string.IsNullOrEmpty(storageCommentText))
  916. {
  917. int storageIndex = sheet.Comments.Add(storageComment);
  918. Aspose.Cells.Comment comment = sheet.Comments[storageIndex];
  919. comment.Note = storageCommentText;
  920. comment.Width = 500;
  921. comment.Height = 200;
  922. //comment.Font.Color = Color.Red;
  923. }
  924. if (!string.IsNullOrEmpty(receiveCommentText))
  925. {
  926. int receiveIndex = sheet.Comments.Add(receiveComment);
  927. Aspose.Cells.Comment comment = sheet.Comments[receiveIndex];
  928. comment.Note = receiveCommentText;
  929. comment.Width = 800;
  930. comment.Height = 200;
  931. //comment.Font.Color = Color.Red;
  932. }
  933. }
  934. #endregion
  935. string serverPath = $"{_url}{fileName}";
  936. designer.Workbook.Save($"{_excelPath}/{fileName}");
  937. _jv.Code = StatusCodes.Status200OK;
  938. _jv.Data = new { url = serverPath };
  939. _jv.Msg = $"操作成功";
  940. return _jv;
  941. }
  942. /// <summary>
  943. /// 物品领用列表
  944. /// </summary>
  945. /// <param name="dto"></param>
  946. /// <returns></returns>
  947. public async Task<JsonView> GoodsReceiveList(GoodsReceiveListDTO dto)
  948. {
  949. //参数处理
  950. int[] typeLabel = Array.Empty<int>(),
  951. userLabel = Array.Empty<int>(),
  952. auditLabel = Array.Empty<int>(),
  953. groupLabel = Array.Empty<int>();
  954. int currUserId = dto.CurrUserId;
  955. if (!string.IsNullOrEmpty(dto.TypeLabel))
  956. {
  957. typeLabel = dto.TypeLabel
  958. .Split(',')
  959. .Select(x =>
  960. {
  961. if (int.TryParse(x, out var id)) return id;
  962. return id;
  963. })
  964. .ToArray();
  965. }
  966. if (!string.IsNullOrEmpty(dto.UserLabel))
  967. {
  968. userLabel = dto.UserLabel
  969. .Split(',')
  970. .Select(x =>
  971. {
  972. if (int.TryParse(x, out var id)) return id;
  973. return id;
  974. })
  975. .ToArray();
  976. }
  977. if (!string.IsNullOrEmpty(dto.AuditLabel))
  978. {
  979. auditLabel = dto.AuditLabel
  980. .Split(',')
  981. .Select(x =>
  982. {
  983. if (int.TryParse(x, out var id)) return id;
  984. return id;
  985. })
  986. .ToArray();
  987. if (auditLabel.Any(x => x == -1))
  988. {
  989. auditLabel = auditLabel.Where(x => x != -1).ToArray();
  990. }
  991. }
  992. if (!string.IsNullOrEmpty(dto.GroupLabel))
  993. {
  994. groupLabel = dto.GroupLabel
  995. .Split(',')
  996. .Select(x =>
  997. {
  998. if (int.TryParse(x, out var id)) return id;
  999. return id;
  1000. })
  1001. .ToArray();
  1002. }
  1003. //物品ID和物品名称只能传一个
  1004. if (dto.GoodsId > 0) dto.GoodsName = string.Empty;
  1005. if (!string.IsNullOrEmpty(dto.GoodsName)) dto.GoodsId = 0;
  1006. var beginBool = DateTime.TryParse(!string.IsNullOrEmpty(dto.BeginDt) ? $"{dto.BeginDt} 00:00:00" : string.Empty, out var begin);
  1007. var endBool = DateTime.TryParse(!string.IsNullOrEmpty(dto.EndDt) ? $"{dto.EndDt} 00:00:00" : string.Empty, out var end);
  1008. RefAsync<int> total = 0;
  1009. var data = _sqlSugar.Queryable<Pm_GoodsReceive>()
  1010. .LeftJoin<Pm_GoodsInfo>((gr, gi) => gr.GoodsId == gi.Id)
  1011. .LeftJoin<Sys_SetData>((gr, gi, sd) => gi.Type == sd.Id)
  1012. .LeftJoin<Sys_Users>((gr, gi, sd, u1) => gr.AuditUserId == u1.Id)
  1013. .LeftJoin<Sys_Users>((gr, gi, sd, u1, u2) => gr.CreateUserId == u2.Id)
  1014. .LeftJoin<Grp_DelegationInfo>((gr, gi, sd, u1, u2, di) => gr.GroupId == di.Id)
  1015. .Where((gr, gi, sd, u1, u2, di) => gr.IsDel == 0)
  1016. .WhereIF(dto.GoodsId > 0, (gr, gi, sd, u1, u2, di) => gr.GoodsId == dto.GoodsId)
  1017. .WhereIF(!string.IsNullOrEmpty(dto.GoodsName), (gr, gi, sd, u1, u2, di) => gi.Name.Contains(dto.GoodsName))
  1018. .WhereIF(auditLabel.Length > 0, (gr, gi, sd, u1, u2, di) => auditLabel.Contains((int)gr.AuditStatus))
  1019. .WhereIF(typeLabel.Length > 0, (gr, gi, sd, u1, u2, di) => typeLabel.Contains(gi.Type))
  1020. .WhereIF(userLabel.Length > 0, (gr, gi, sd, u1, u2, di) => userLabel.Contains(gr.CreateUserId))
  1021. .WhereIF(groupLabel.Length > 0, (gr, gi, sd, u1, u2, di) => groupLabel.Contains(gr.GroupId))
  1022. .WhereIF(beginBool && endBool, (gr, gi, sd, u1, u2, di) => gr.CreateTime >= begin && gr.CreateTime <= end)
  1023. .Select((gr, gi, sd, u1, u2, di) => new GoodsReceiveListMobileView
  1024. {
  1025. Id = gr.Id,
  1026. GroupId = gr.GroupId,
  1027. GroupName = di.TeamName,
  1028. GoodsId = gr.GoodsId,
  1029. GoodsName = gi.Name,
  1030. GoodsType = sd.Name,
  1031. Quantity = gr.Quantity,
  1032. Unit = gi.Unit,
  1033. Reason = gr.Reason,
  1034. Remark = gr.Remark,
  1035. AuditStatus = gr.AuditStatus,
  1036. StatusDesc = gr.StatusDesc,
  1037. AuditUserId = gr.AuditUserId,
  1038. AuditUserName = u1.CnName,
  1039. AuditTime = gr.AuditTime,
  1040. CreateUserName = u2.CnName,
  1041. CreateTime = gr.CreateTime
  1042. })
  1043. .OrderByDescending(gr => gr.CreateTime);
  1044. //excel导出
  1045. if (dto.IsExcelDownload)
  1046. {
  1047. var fileName = $"物资领用{Guid.NewGuid()}.xlsx";
  1048. var excelTempPath = $"{_excelPath}Template/物资领用Temp.xlsx";
  1049. if (!File.Exists(excelTempPath))
  1050. {
  1051. _jv.Code = StatusCodes.Status204NoContent;
  1052. _jv.Msg = $"该模板文件不存在!";
  1053. return _jv;
  1054. }
  1055. _url = $"{_url}Office/Excel/GoodsFiles/";
  1056. _excelPath = $"{_excelPath}GoodsFiles";
  1057. if (!Directory.Exists(_excelPath))
  1058. {
  1059. Directory.CreateDirectory(_excelPath);
  1060. }
  1061. //载入模板
  1062. WorkbookDesigner designer = new WorkbookDesigner();
  1063. designer.Workbook = new Workbook(excelTempPath);
  1064. var tableData = await data.ToListAsync();
  1065. designer.SetDataSource("Export", tableData);
  1066. designer.Process();
  1067. string serverPath = $"{_url}{fileName}";
  1068. designer.Workbook.Save($"{_excelPath}/{fileName}");
  1069. _jv.Code = StatusCodes.Status200OK;
  1070. _jv.Data = new { url = serverPath };
  1071. _jv.Msg = $"操作成功";
  1072. return _jv;
  1073. }
  1074. //返回分页数据
  1075. var view = await data.ToPageListAsync(dto.PageIndex, dto.PageSize, total);
  1076. //财务人事审核权限处理
  1077. var auditList = GoodsStorageConfirmAuditDep(2);
  1078. bool hrAuditPer = false,
  1079. finAuditPer = false;
  1080. var hrAuditInfo = auditList.FirstOrDefault(x => x.AuditDep == GoodsAuditDepEnum.Hr);
  1081. var finAuditInfo = auditList.FirstOrDefault(x => x.AuditDep == GoodsAuditDepEnum.Financial);
  1082. if (hrAuditInfo != null)
  1083. {
  1084. if (hrAuditInfo.AuditorIds.Any(x => x == currUserId))
  1085. {
  1086. hrAuditPer = true;
  1087. }
  1088. }
  1089. if (finAuditInfo != null)
  1090. {
  1091. if (finAuditInfo.AuditorIds.Any(x => x == currUserId))
  1092. {
  1093. finAuditPer = true;
  1094. }
  1095. }
  1096. foreach (var item in view)
  1097. {
  1098. item.AuditPers = new GoodsStorageAuditPerView[] {
  1099. new (){ AuditPer = hrAuditPer, AuditDep = GoodsAuditDepEnum.Hr, ButtonText = GoodsAuditDepEnum.Hr.GetEnumDescription()},
  1100. new (){ AuditPer = finAuditPer, AuditDep = GoodsAuditDepEnum.Financial, ButtonText = GoodsAuditDepEnum.Financial.GetEnumDescription()}
  1101. };
  1102. }
  1103. if (dto.PortType == 2 || dto.PortType == 3)
  1104. {
  1105. _jv.Data = view;
  1106. }
  1107. else if (dto.PortType == 1)
  1108. {
  1109. var view1 = _mapper.Map<List<GoodsReceiveListView>>(view);
  1110. _jv.Data = view1;
  1111. }
  1112. _jv.Code = StatusCodes.Status200OK;
  1113. _jv.Count = total;
  1114. _jv.Msg = $"操作成功";
  1115. return _jv;
  1116. }
  1117. /// <summary>
  1118. /// 物品领用详情
  1119. /// </summary>
  1120. /// <param name="portType"></param>
  1121. /// <param name="id"></param>
  1122. /// <returns></returns>
  1123. public async Task<JsonView> GoodsReceiveInfo(int portType, int id)
  1124. {
  1125. var data = await _sqlSugar.Queryable<Pm_GoodsReceive>()
  1126. .LeftJoin<Pm_GoodsInfo>((gr, gi) => gr.GoodsId == gi.Id)
  1127. .LeftJoin<Sys_Users>((gr, gi, u1) => gr.AuditUserId == u1.Id)
  1128. .LeftJoin<Sys_Users>((gr, gi, u1, u2) => gr.CreateUserId == u2.Id)
  1129. .LeftJoin<Grp_DelegationInfo>((gr, gi, u1, u2,di) => gr.GroupId == di.Id)
  1130. .Where((gr, gi, u1, u2, di) => gr.IsDel == 0)
  1131. .WhereIF(id > 0, (gr, gi, u1, u2, di) => gr.Id == id)
  1132. .Select((gr, gi, u1, u2, di) => new GoodsReceiveInfoMobileView
  1133. {
  1134. Id = gr.Id,
  1135. GroupId = gr.GroupId,
  1136. GroupName = di.TeamName,
  1137. GoodsId = gr.GoodsId,
  1138. GoodsName = gi.Name,
  1139. Quantity = gr.Quantity,
  1140. Reason = gr.Reason,
  1141. Remark = gr.Remark,
  1142. GoodsStorageInfo = gr.GoodsStorageInfo,
  1143. AuditStatus = gr.AuditStatus,
  1144. AuditUserId = gr.AuditUserId,
  1145. AuditUserName = u1.CnName,
  1146. AuditTime = gr.AuditTime,
  1147. CreateUserName = u2.CnName,
  1148. CreateTime = gr.CreateTime
  1149. })
  1150. .FirstAsync();
  1151. if (!string.IsNullOrEmpty(data.GoodsStorageInfo))
  1152. {
  1153. var subData = new List<dynamic>();
  1154. try
  1155. {
  1156. var subData1 = JsonConvert.DeserializeObject<List<GoodsReceiveLinkStorageView>>(data.GoodsStorageInfo);
  1157. if (subData1.Count > 0)
  1158. {
  1159. string goodsStorageInfoStr = string.Empty;
  1160. var storageIds = subData1.Select(x => x.StorageId).ToList();
  1161. var storages = await _sqlSugar.Queryable<Pm_GoodsStorage>().Where(x => x.IsDel == 0 && storageIds.Contains(x.Id)).ToListAsync();
  1162. foreach (var item in subData1)
  1163. {
  1164. var storageInfo = storages.Find(x => x.Id == item.StorageId);
  1165. if (storageInfo != null)
  1166. {
  1167. subData.Add(new
  1168. {
  1169. StorageId = item.StorageId,
  1170. BatchNo = storageInfo.BatchNo,
  1171. RecsiveQuantity = item.Quantity
  1172. });
  1173. goodsStorageInfoStr += $"物品名称:{data.GoodsName} 批次号:{storageInfo.BatchNo} 领用数量:{item.Quantity} \r\n";
  1174. }
  1175. }
  1176. data.QuantityInfos = subData;
  1177. data.GoodsStorageInfoStr = goodsStorageInfoStr;
  1178. }
  1179. }
  1180. catch (Exception e)
  1181. {
  1182. Console.WriteLine(e);
  1183. }
  1184. }
  1185. _jv.Code = StatusCodes.Status200OK;
  1186. _jv.Msg = $"操作成功";
  1187. if (portType == 2 || portType == 3) //移动端
  1188. {
  1189. _jv.Data = data;
  1190. }
  1191. else if (portType == 1) //pc端
  1192. {
  1193. _jv.Data = _mapper.Map<GoodsReceiveInfoView>(data);
  1194. }
  1195. return _jv;
  1196. }
  1197. /// <summary>
  1198. /// 物品领用 OP(Add Or Edit)
  1199. /// </summary>
  1200. /// <param name="dto"></param>
  1201. /// <param name="currUserId"></param>
  1202. /// <returns></returns>
  1203. public async Task<JsonView> GoodsReceiveOp(GoodsReceiveOpDto dto, int currUserId)
  1204. {
  1205. var info = _mapper.Map<Pm_GoodsReceive>(dto);
  1206. info.CreateUserId = currUserId;
  1207. var auditEnums = new List<GoodsAuditEnum>() {
  1208. GoodsAuditEnum.Approved, // 1
  1209. GoodsAuditEnum.UnApproved, // 2
  1210. GoodsAuditEnum.OutConfirmed,// 5
  1211. GoodsAuditEnum.OutRejected // 6
  1212. };
  1213. _sqlSugar.BeginTran();
  1214. //物品现有库存
  1215. var stockQuantity = _sqlSugar.Queryable<Pm_GoodsInfo>().First(x => x.Id == info.GoodsId)?.StockQuantity;
  1216. //待审核 该物品数量
  1217. var waitAuditQuantity = await _sqlSugar.Queryable<Pm_GoodsReceive>().Where(x => x.IsDel == 0 &&
  1218. x.GoodsId == dto.GoodsId &&
  1219. !auditEnums.Contains(x.AuditStatus)
  1220. ).SumAsync(x => x.Quantity);
  1221. if (info.Id > 0) //修改
  1222. {
  1223. //审核验证
  1224. var selectInfo = await _sqlSugar.Queryable<Pm_GoodsReceive>().FirstAsync(x => x.Id == info.Id);
  1225. if (auditEnums.Contains(selectInfo.AuditStatus))
  1226. {
  1227. _sqlSugar.RollbackTran();
  1228. _jv.Msg = $"该条数据已执行操作({selectInfo.AuditStatus.GetEnumDescription()}),不可更改!";
  1229. return _jv;
  1230. }
  1231. //物品数量验证
  1232. var editAfterQuantity = waitAuditQuantity - selectInfo.Quantity + info.Quantity;
  1233. if (editAfterQuantity > stockQuantity)
  1234. {
  1235. _sqlSugar.RollbackTran();
  1236. _jv.Msg = $"该物品现有库存不足,不可更改!请联系采购人员购买!";
  1237. return _jv;
  1238. }
  1239. var edit = await _sqlSugar.Updateable(info)
  1240. .UpdateColumns(x => new
  1241. {
  1242. x.GroupId,
  1243. x.Quantity,
  1244. x.Reason,
  1245. x.Remark,
  1246. })
  1247. .Where(x => x.Id == info.Id)
  1248. .ExecuteCommandAsync();
  1249. if (edit > 0)
  1250. {
  1251. _sqlSugar.CommitTran();
  1252. _jv.Msg = $"操作成功!";
  1253. _jv.Code = StatusCodes.Status200OK;
  1254. return _jv;
  1255. }
  1256. }
  1257. else if (info.Id < 1) //添加
  1258. {
  1259. //物品数量验证
  1260. decimal addAgoQuantity = waitAuditQuantity + info.Quantity;
  1261. if (addAgoQuantity > stockQuantity)
  1262. {
  1263. _sqlSugar.RollbackTran();
  1264. _jv.Msg = $"该物品现有库存不足,不可更改!请联系采购人员购买!";
  1265. return _jv;
  1266. }
  1267. var add = await _sqlSugar.Insertable(info).ExecuteReturnIdentityAsync();
  1268. if (add < 1)
  1269. {
  1270. _sqlSugar.RollbackTran();
  1271. _jv.Msg = $"添加失败!";
  1272. _jv.Code = StatusCodes.Status400BadRequest;
  1273. return _jv;
  1274. }
  1275. //出库确认默认审核状态
  1276. var goodsAuditList = new List<Pm_GoodsAudit>() {
  1277. new Pm_GoodsAudit(2, GoodsAuditDepEnum.Hr, add, GoodsConfirmEnum.WaitConfirm, currUserId),
  1278. new Pm_GoodsAudit(2, GoodsAuditDepEnum.Financial, add, GoodsConfirmEnum.WaitConfirm, currUserId)
  1279. };
  1280. if (goodsAuditList.Any())
  1281. {
  1282. await _sqlSugar.Insertable(goodsAuditList).ExecuteCommandAsync();
  1283. }
  1284. _sqlSugar.CommitTran();
  1285. _jv.Msg = $"操作成功!";
  1286. _jv.Code = StatusCodes.Status200OK;
  1287. return _jv;
  1288. }
  1289. _sqlSugar.RollbackTran();
  1290. return _jv;
  1291. }
  1292. /// <summary>
  1293. /// 物品领用 Audit
  1294. /// </summary>
  1295. /// <param name="idArray"></param>
  1296. /// <param name="userId"></param>
  1297. /// <param name="auditEnum"></param>
  1298. /// <returns></returns>
  1299. public async Task<JsonView> GoodsReceiveAudit(int[] idArray, int userId, GoodsAuditEnum auditEnum)
  1300. {
  1301. if (idArray.Length < 1) return _jv;
  1302. var auditEnums = new List<GoodsAuditEnum>() {
  1303. GoodsAuditEnum.Pending,
  1304. GoodsAuditEnum.Approved,
  1305. GoodsAuditEnum.UnApproved,
  1306. GoodsAuditEnum.OutPending,
  1307. GoodsAuditEnum.OutConfirmed,
  1308. GoodsAuditEnum.OutRejected,
  1309. };
  1310. if (!auditEnums.Contains(auditEnum))
  1311. {
  1312. _jv.Msg = $"出库确认状态超出可用范围!";
  1313. return _jv;
  1314. }
  1315. int receiveId = idArray[0];
  1316. //验证审核部门 审核状态 大于等于 OutPending 时 验证
  1317. var auditDep = GoodsAuditDepEnum.Hr;
  1318. if (auditEnum >= GoodsAuditEnum.OutPending)
  1319. {
  1320. var auditList = GoodsStorageConfirmAuditDep(2);
  1321. var auditDepInfo = auditList.Find(x => x.AuditorIds.Contains(userId));
  1322. if (auditDepInfo == null)
  1323. {
  1324. _jv.Msg = string.Format("未分配出库确认权限!");
  1325. return _jv;
  1326. }
  1327. auditDep = auditDepInfo.AuditDep;
  1328. }
  1329. var currUserName = _sqlSugar.Queryable<Sys_Users>().First(x => x.Id == userId)?.CnName ?? "-";
  1330. _sqlSugar.BeginTran();
  1331. var receiveInfo = await _sqlSugar
  1332. .Queryable<Pm_GoodsReceive>()
  1333. //.Where(x => x.IsDel == 0 && idArray.Contains(x.Id))
  1334. .Where(x => x.IsDel == 0 && receiveId == x.Id )
  1335. .FirstAsync();
  1336. if (receiveInfo == null)
  1337. {
  1338. _sqlSugar.RollbackTran();
  1339. _jv.Msg = $"当前领用信息不存在!";
  1340. return _jv;
  1341. }
  1342. //审核前状态
  1343. var preChangeStatus = receiveInfo.AuditStatus;
  1344. //状态验证
  1345. //if (preChangeStatus == auditEnum)
  1346. //{
  1347. // _sqlSugar.RollbackTran();
  1348. // _jv.Msg = $"该条数据状态已设置,不可重复设置!";
  1349. // return _jv;
  1350. //}
  1351. switch (auditEnum)
  1352. {
  1353. case GoodsAuditEnum.Pending: //领用待确认(取消确认、取消拒绝)
  1354. _jv = await GoodsReceivePending(preChangeStatus, receiveId, userId, currUserName, auditEnum);
  1355. break;
  1356. case GoodsAuditEnum.Approved: //领用确认
  1357. _jv = await GoodsReceiveApproved(preChangeStatus, receiveId, userId, currUserName, auditEnum);
  1358. break;
  1359. case GoodsAuditEnum.UnApproved: //领用拒绝
  1360. _jv = await GoodsReceiveUnApproved(preChangeStatus, receiveId, userId, currUserName, auditEnum);
  1361. break;
  1362. case GoodsAuditEnum.OutPending: //出库待确认(取消出库确认、取消出库拒绝)
  1363. _jv = await GoodsReceiveOutPending(preChangeStatus, receiveInfo, userId, auditDep, auditEnum);
  1364. break;
  1365. case GoodsAuditEnum.OutConfirmed: //出库确认
  1366. _jv = await GoodsReceiveOutConfirming(receiveInfo, userId, auditDep, auditEnum);
  1367. //TODO:出库成功 并且是团组相关物资 向团组其他款项添加信息
  1368. break;
  1369. case GoodsAuditEnum.OutRejected: //出库拒绝
  1370. _jv = await GoodsReceiveOutConfirming(receiveInfo, userId, auditDep, auditEnum);
  1371. break;
  1372. }
  1373. if (_jv.Code == StatusCodes.Status200OK)
  1374. {
  1375. _sqlSugar.CommitTran();
  1376. _jv.Msg = $"操作成功!";
  1377. return _jv;
  1378. }
  1379. _sqlSugar.RollbackTran();
  1380. return _jv;
  1381. }
  1382. /// <summary>
  1383. /// 物品领用状态 - 领用待确认(取消确认、取消拒绝)
  1384. /// </summary>
  1385. /// <param name="preChangeStatus">更改前状态</param>
  1386. /// <param name="receiveId"></param>
  1387. /// <param name="userId"></param>
  1388. /// <param name="userName"></param>
  1389. /// <param name="auditEnum"></param>
  1390. /// <returns></returns>
  1391. public async Task<JsonView> GoodsReceivePending(GoodsAuditEnum preChangeStatus,int receiveId, int userId, string userName, GoodsAuditEnum auditEnum)
  1392. {
  1393. _jv.Code = StatusCodes.Status400BadRequest;
  1394. //领用待确认 操作范围
  1395. var audirEnumPers = new List<GoodsAuditEnum>() {
  1396. GoodsAuditEnum.Approved,
  1397. GoodsAuditEnum.UnApproved
  1398. };
  1399. if (!audirEnumPers.Contains(preChangeStatus))
  1400. {
  1401. _jv.Msg = $"{GoodsAuditEnum.Approved.GetEnumDescription()}、{GoodsAuditEnum.UnApproved.GetEnumDescription()},状态下可取消操作!";
  1402. return _jv;
  1403. }
  1404. var currUserOpDt = DateTime.Now;
  1405. var currUserOpTime = currUserOpDt.ToString("yyyy-MM-dd HH:mm:ss");
  1406. var statusDesc = string.Format(@"领用确认:状态:{0} 审核人:{1} 审核时间:{2};<br/>人事部确认:状态:待确认 审核人:- 审核时间:-;<br/>财务部确认:状态:待确认 审核人:- 审核时间:-;", auditEnum.GetEnumDescription(), userName, currUserOpTime);
  1407. auditEnum = GoodsAuditEnum.Pending;
  1408. var changeStatus = await _sqlSugar
  1409. .Updateable<Pm_GoodsReceive>()
  1410. .SetColumns(x => new Pm_GoodsReceive()
  1411. {
  1412. AuditStatus = auditEnum,
  1413. AuditUserId = userId,
  1414. AuditTime = currUserOpDt,
  1415. StatusDesc = statusDesc
  1416. })
  1417. .Where(x => x.Id == receiveId)
  1418. .ExecuteCommandAsync();
  1419. if (changeStatus > 0)
  1420. {
  1421. _jv.Code = StatusCodes.Status200OK;
  1422. }
  1423. return _jv;
  1424. }
  1425. /// <summary>
  1426. /// 物品领用状态 - 领用确认
  1427. /// </summary>
  1428. /// <param name="preChangeStatus">更改前状态</param>
  1429. /// <param name="receiveId"></param>
  1430. /// <param name="userId"></param>
  1431. /// <param name="userName"></param>
  1432. /// <param name="auditEnum"></param>
  1433. /// <returns></returns>
  1434. public async Task<JsonView> GoodsReceiveApproved(GoodsAuditEnum preChangeStatus, int receiveId, int userId,string userName, GoodsAuditEnum auditEnum)
  1435. {
  1436. _jv.Code = StatusCodes.Status400BadRequest;
  1437. if (preChangeStatus != GoodsAuditEnum.Pending)
  1438. {
  1439. _jv.Msg = $"{GoodsAuditEnum.Pending.GetEnumDescription()},状态下可取消操作!";
  1440. return _jv;
  1441. }
  1442. var currUserOpDt = DateTime.Now;
  1443. var currUserOpTime = currUserOpDt.ToString("yyyy-MM-dd HH:mm:ss");
  1444. var statusDesc = string.Format(@"领用确认:状态:{0} 审核人:{1} 审核时间:{2};<br/>人事部确认:状态:待确认 审核人:- 审核时间:-;<br/>财务部确认:状态:待确认 审核人:- 审核时间:-;", auditEnum.GetEnumDescription(), userName, currUserOpTime);
  1445. auditEnum = GoodsAuditEnum.OutPending;
  1446. var changeStatus = await _sqlSugar
  1447. .Updateable<Pm_GoodsReceive>()
  1448. .SetColumns(x => new Pm_GoodsReceive()
  1449. {
  1450. AuditStatus = auditEnum,
  1451. AuditUserId = userId,
  1452. AuditTime = currUserOpDt,
  1453. StatusDesc = statusDesc
  1454. })
  1455. .Where(x => x.Id == receiveId)
  1456. .ExecuteCommandAsync();
  1457. if (changeStatus > 0)
  1458. {
  1459. _jv.Code = StatusCodes.Status200OK;
  1460. }
  1461. return _jv;
  1462. }
  1463. /// <summary>
  1464. /// 物品领用状态 - 领用拒绝
  1465. /// </summary>
  1466. /// <param name="preChangeStatus">更改前状态</param>
  1467. /// <param name="receiveId"></param>
  1468. /// <param name="userId"></param>
  1469. /// <param name="userName"></param>
  1470. /// <param name="auditEnum"></param>
  1471. /// <returns></returns>
  1472. public async Task<JsonView> GoodsReceiveUnApproved(GoodsAuditEnum preChangeStatus, int receiveId, int userId, string userName, GoodsAuditEnum auditEnum)
  1473. {
  1474. _jv.Code = StatusCodes.Status400BadRequest;
  1475. if (preChangeStatus != GoodsAuditEnum.Pending)
  1476. {
  1477. _jv.Msg = $"{GoodsAuditEnum.Pending.GetEnumDescription()},状态下可取消操作!";
  1478. return _jv;
  1479. }
  1480. auditEnum = GoodsAuditEnum.UnApproved;
  1481. var currUserOpDt = DateTime.Now;
  1482. var currUserOpTime = currUserOpDt.ToString("yyyy-MM-dd HH:mm:ss");
  1483. var statusDesc = string.Format(@"领用确认:状态:{0} 审核人:{1} 审核时间:{2};<br/>人事部确认:状态:待确认 审核人:- 审核时间:-;<br/>财务部认:状态:待确认 审核人:- 审核时间:-;<br/>", auditEnum.GetEnumDescription(), userName, currUserOpTime);
  1484. var changeStatus = await _sqlSugar
  1485. .Updateable<Pm_GoodsReceive>()
  1486. .SetColumns(x => new Pm_GoodsReceive()
  1487. {
  1488. AuditStatus = auditEnum,
  1489. AuditUserId = userId,
  1490. AuditTime = currUserOpDt,
  1491. StatusDesc = statusDesc
  1492. })
  1493. .Where(x => x.Id == receiveId)
  1494. .ExecuteCommandAsync();
  1495. if (changeStatus > 0)
  1496. {
  1497. _jv.Code = StatusCodes.Status200OK;
  1498. }
  1499. return _jv;
  1500. }
  1501. /// <summary>
  1502. /// 物品领用状态 - 出库待确认(出库确认、出库拒绝)
  1503. /// </summary>
  1504. /// <param name="preChangeStatus">更改前状态</param>
  1505. /// <param name="receiveId"></param>
  1506. /// <param name="userId"></param>
  1507. /// <param name="userName"></param>
  1508. /// <param name="auditEnum"></param>
  1509. /// <returns></returns>
  1510. public async Task<JsonView> GoodsReceiveOutPending(GoodsAuditEnum preChangeStatus, Pm_GoodsReceive receiveInfo, int userId, GoodsAuditDepEnum depEnum, GoodsAuditEnum auditEnum)
  1511. {
  1512. _jv.Code = StatusCodes.Status400BadRequest;
  1513. //出库待确认 操作范围
  1514. var audirEnumPers = new List<GoodsAuditEnum>() {
  1515. GoodsAuditEnum.OutConfirmed,
  1516. GoodsAuditEnum.OutRejected
  1517. };
  1518. if (!audirEnumPers.Contains(preChangeStatus))
  1519. {
  1520. _jv.Msg = $"{GoodsAuditEnum.OutConfirmed.GetEnumDescription()}、{GoodsAuditEnum.OutRejected.GetEnumDescription()},状态下可取消操作!";
  1521. return _jv;
  1522. }
  1523. var currUserOpDt = DateTime.Now;
  1524. var currUserOpTime = currUserOpDt.ToString("yyyy-MM-dd HH:mm:ss");
  1525. var auditInfos = await _sqlSugar.Queryable<Pm_GoodsAudit>()
  1526. .Where(x => x.IsDel == 0 && x.DataId == receiveInfo.Id && x.Type == 2)
  1527. .ToListAsync();
  1528. auditEnum = GoodsAuditEnum.OutPending;
  1529. var auditStatus = GoodsConfirmEnum.WaitConfirm;
  1530. var auditInfo = auditInfos.Find(x => x.Dep == depEnum);
  1531. if (auditInfo == null)
  1532. {
  1533. auditInfo = new Pm_GoodsAudit(2, depEnum, receiveInfo.Id, auditStatus, userId);
  1534. var addStatus = await _sqlSugar.Insertable(auditInfo).ExecuteCommandAsync();
  1535. if (addStatus < 1)
  1536. {
  1537. _jv.Msg = $"出库确认取消操作失败!";
  1538. return _jv;
  1539. }
  1540. auditInfos.Add(auditInfo);
  1541. }
  1542. else
  1543. {
  1544. //移除旧数据
  1545. auditInfos.Remove(auditInfo);
  1546. auditInfo.AuditStatus = auditStatus;
  1547. auditInfo.AuditUserId = userId;
  1548. auditInfo.AuditTime = currUserOpDt;
  1549. var updStatus = await _sqlSugar.Updateable<Pm_GoodsAudit>()
  1550. .SetColumns(x => new Pm_GoodsAudit()
  1551. {
  1552. AuditStatus = auditStatus,
  1553. AuditUserId = userId,
  1554. AuditTime = currUserOpDt
  1555. })
  1556. .Where(x => x.Id == auditInfo.Id)
  1557. .ExecuteCommandAsync();
  1558. if (updStatus < 1)
  1559. {
  1560. _jv.Msg = $"出库确认操作失败!";
  1561. return _jv;
  1562. }
  1563. //添加更新后的数据
  1564. auditInfos.Add(auditInfo);
  1565. }
  1566. //处理状态描述
  1567. StringBuilder statusDesc = new StringBuilder();
  1568. var receiveUserName = _sqlSugar.Queryable<Sys_Users>().First(x => x.Id == receiveInfo.AuditUserId)?.CnName ?? "-";
  1569. string receiveStatusDesc = string.Format("{0}:状态:{1} 审核人:{2} 审核时间:{3};<br/>",
  1570. "领用确认", GoodsAuditEnum.Approved.GetEnumDescription(), receiveUserName, receiveInfo.AuditTime.ToString("yyyy-MM-dd HH:mm:ss"));
  1571. statusDesc.Append(receiveStatusDesc);
  1572. foreach (var auditInf in auditInfos)
  1573. {
  1574. string userName = _sqlSugar.Queryable<Sys_Users>().First(x => x.Id == auditInf.AuditUserId)?.CnName ?? "-";
  1575. string userOpTime = !userName.Equals("-") ? auditInf.AuditTime.ToString("yyyy-MM-dd HH:mm:ss") : "-";
  1576. string auditInfStatusDesc = string.Format("{0}:状态:{1} 审核人:{2} 审核时间:{3};<br/>",
  1577. auditInf.Dep.GetEnumDescription(), auditInf.AuditStatus.GetEnumDescription(), userName, currUserOpTime);
  1578. statusDesc.Append(auditInfStatusDesc);
  1579. }
  1580. //批次库存信息
  1581. string goodsStorageInfo = receiveInfo.GoodsStorageInfo;
  1582. //出库确认取消是单独处理
  1583. if (preChangeStatus == GoodsAuditEnum.OutConfirming)
  1584. {
  1585. if (auditInfos.Where(x => x.AuditStatus == GoodsConfirmEnum.Confirmed).Count() == 1)
  1586. {
  1587. auditEnum = GoodsAuditEnum.OutConfirming;
  1588. }
  1589. //2.1 更改库存
  1590. var goodsInfo = await _sqlSugar.Queryable<Pm_GoodsInfo>().Where(x => x.Id == receiveInfo.GoodsId).FirstAsync();
  1591. goodsInfo.StockQuantity -= receiveInfo.Quantity;
  1592. goodsInfo.OQ_Total += receiveInfo.Quantity;
  1593. goodsInfo.LastUpdateTime = DateTime.Now;
  1594. goodsInfo.LastUpdateUserId = userId;
  1595. var editGoods = await _sqlSugar
  1596. .Updateable(goodsInfo)
  1597. .UpdateColumns(x => new
  1598. {
  1599. x.StockQuantity,
  1600. x.OQ_Total,
  1601. x.LastUpdateUserId,
  1602. x.LastUpdateTime,
  1603. })
  1604. .Where(x => x.Id == receiveInfo.GoodsId)
  1605. .ExecuteCommandAsync();
  1606. if (editGoods < 1)
  1607. {
  1608. _jv.Msg = $"库存更新失败!";
  1609. return _jv;
  1610. }
  1611. //2.2 入库批次关联领用人 更改批次库存
  1612. var goodsStorages = await _sqlSugar
  1613. .Queryable<Pm_GoodsStorage>()
  1614. .Where(x => x.IsDel == 0 &&
  1615. x.GoodsId == receiveInfo.GoodsId &&
  1616. (x.Quantity - x.ReceiveQuantity) > 0
  1617. )
  1618. .OrderBy(x => x.CreateTime)
  1619. .ToListAsync();
  1620. var goodsReceiveInfos = new List<GoodsReceiveLinkStorageView>();
  1621. var batchStorageInfos = new List<Pm_GoodsStorage>();
  1622. var receiveQuantity = 0.00M; //领用总数量
  1623. foreach (var storage in goodsStorages)
  1624. {
  1625. if (receiveInfo.Quantity == receiveQuantity) break;
  1626. var thisBatchSurplusQuantity = storage.Quantity - storage.ReceiveQuantity;
  1627. if (thisBatchSurplusQuantity <= 0.00M) continue;
  1628. var thisBatchReceiveQuantity = 0.00M; //此批次领用数量
  1629. const decimal unit = 0.50M;
  1630. while (receiveQuantity < receiveInfo.Quantity)
  1631. {
  1632. if (thisBatchSurplusQuantity == thisBatchReceiveQuantity) break;
  1633. thisBatchReceiveQuantity += unit;
  1634. receiveQuantity += unit;
  1635. }
  1636. goodsReceiveInfos.Add(new GoodsReceiveLinkStorageView
  1637. {
  1638. StorageId = storage.Id,
  1639. Quantity = thisBatchReceiveQuantity
  1640. });
  1641. storage.ReceiveQuantity += thisBatchReceiveQuantity;
  1642. var storageUpd = storage;
  1643. //storageUpd.ReceiveQuantity += thisBatchReceiveQuantity;
  1644. batchStorageInfos.Add(storageUpd);
  1645. }
  1646. //2.2.1 更改批次库存
  1647. if (goodsReceiveInfos.Count > 0)
  1648. {
  1649. var edit1 = await _sqlSugar.Updateable(batchStorageInfos)
  1650. .UpdateColumns(x => x.ReceiveQuantity)
  1651. .WhereColumns(x => x.Id)
  1652. .ExecuteCommandAsync();
  1653. if (edit1 < 1)
  1654. {
  1655. _jv.Msg = $"批次库存更新失败!";
  1656. return _jv;
  1657. }
  1658. }
  1659. //2.2.2 添加入库批次关联领用人
  1660. if (goodsReceiveInfos.Count > 0)
  1661. {
  1662. goodsStorageInfo = JsonConvert.SerializeObject(goodsReceiveInfos);
  1663. }
  1664. }
  1665. var statusDesc1 = statusDesc.ToString();
  1666. var changeStatus = await _sqlSugar
  1667. .Updateable<Pm_GoodsReceive>()
  1668. .SetColumns(x => new Pm_GoodsReceive()
  1669. {
  1670. AuditStatus = auditEnum,
  1671. StatusDesc = statusDesc1,
  1672. GoodsStorageInfo= goodsStorageInfo
  1673. })
  1674. .Where(x => x.Id == receiveInfo.Id)
  1675. .ExecuteCommandAsync();
  1676. if (changeStatus > 0)
  1677. {
  1678. _jv.Code = StatusCodes.Status200OK;
  1679. }
  1680. return _jv;
  1681. }
  1682. /// <summary>
  1683. /// 物品领用状态 - 出库确认中、出库确认完成、出库确认拒绝
  1684. /// </summary>
  1685. /// <param name="receiveInfo"></param>
  1686. /// <param name="userId"></param>
  1687. /// <param name="depEnum"></param>
  1688. /// <param name="auditEnum"></param>
  1689. /// <returns></returns>
  1690. public async Task<JsonView> GoodsReceiveOutConfirming(Pm_GoodsReceive receiveInfo, int userId, GoodsAuditDepEnum depEnum,GoodsAuditEnum auditEnum)
  1691. {
  1692. _jv.Code = StatusCodes.Status400BadRequest;
  1693. //更改前状态
  1694. var preChangeStatus = receiveInfo.AuditStatus;
  1695. if (preChangeStatus < GoodsAuditEnum.OutPending)
  1696. {
  1697. _jv.Msg = $"领用确认执行成功!才可执行出库确认或出库拒绝操作!";
  1698. return _jv;
  1699. }
  1700. var currUserOpDt = DateTime.Now;
  1701. var currUserOpTime = currUserOpDt.ToString("yyyy-MM-dd HH:mm:ss");
  1702. var auditInfos = await _sqlSugar.Queryable<Pm_GoodsAudit>()
  1703. .Where(x => x.IsDel == 0 && x.DataId == receiveInfo.Id && x.Type == 2)
  1704. .ToListAsync();
  1705. var auditStatus = GoodsConfirmEnum.WaitConfirm;
  1706. if (auditEnum == GoodsAuditEnum.OutRejected) auditStatus = GoodsConfirmEnum.UnApproved;
  1707. else if (auditEnum == GoodsAuditEnum.OutConfirmed) auditStatus = GoodsConfirmEnum.Confirmed;
  1708. var auditInfo = auditInfos.Find(x => x.Dep == depEnum);
  1709. if (auditInfo == null)
  1710. {
  1711. auditInfo = new Pm_GoodsAudit(2, depEnum, receiveInfo.Id, auditStatus, userId);
  1712. var addStatus = await _sqlSugar.Insertable(auditInfo).ExecuteCommandAsync();
  1713. if (addStatus < 1)
  1714. {
  1715. _jv.Msg = $"出库确认操作失败!";
  1716. return _jv;
  1717. }
  1718. auditInfos.Add(auditInfo);
  1719. }
  1720. else
  1721. {
  1722. //移除旧数据
  1723. auditInfos.Remove(auditInfo);
  1724. auditInfo.AuditStatus = auditStatus;
  1725. auditInfo.AuditUserId = userId;
  1726. auditInfo.AuditTime = currUserOpDt;
  1727. var updStatus = await _sqlSugar.Updateable<Pm_GoodsAudit>()
  1728. .SetColumns(x => new Pm_GoodsAudit()
  1729. {
  1730. AuditStatus = auditStatus,
  1731. AuditUserId = userId,
  1732. AuditTime = currUserOpDt
  1733. })
  1734. .Where(x => x.Id == auditInfo.Id)
  1735. .ExecuteCommandAsync();
  1736. if (updStatus < 1)
  1737. {
  1738. _jv.Msg = $"出库确认操作失败!";
  1739. return _jv;
  1740. }
  1741. //添加更新后的数据
  1742. auditInfos.Add(auditInfo);
  1743. }
  1744. //处理状态描述
  1745. StringBuilder statusDesc= new StringBuilder();
  1746. var receiveUserName = _sqlSugar.Queryable<Sys_Users>().First(x => x.Id == receiveInfo.AuditUserId)?.CnName ?? "-";
  1747. string receiveStatusDesc = string.Format("{0}:状态:{1} 审核人:{2} 审核时间:{3};<br/>",
  1748. "领用确认", GoodsAuditEnum.Approved.GetEnumDescription(), receiveUserName, receiveInfo.AuditTime.ToString("yyyy-MM-dd HH:mm:ss"));
  1749. statusDesc.Append(receiveStatusDesc);
  1750. foreach (var auditInf in auditInfos)
  1751. {
  1752. string userName = _sqlSugar.Queryable<Sys_Users>().First(x => x.Id == auditInf.AuditUserId)?.CnName ?? "-";
  1753. string userOpTime = !userName.Equals("-") ? auditInf.AuditTime.ToString("yyyy-MM-dd HH:mm:ss") : "-";
  1754. string auditInfStatusDesc = string.Format("{0}:状态:{1} 审核人:{2} 审核时间:{3};<br/>",
  1755. auditInf.Dep.GetEnumDescription(), auditInf.AuditStatus.GetEnumDescription(), userName, currUserOpTime);
  1756. statusDesc.Append(auditInfStatusDesc);
  1757. }
  1758. if (preChangeStatus == auditEnum)
  1759. {
  1760. _jv.Msg = $"此操作已执行,不可重复操作!";
  1761. return _jv;
  1762. }
  1763. //批次库存信息
  1764. string goodsStorageInfo = receiveInfo.GoodsStorageInfo;
  1765. //更改领用状态及库存
  1766. if (auditInfos.Any(x => x.AuditStatus == GoodsConfirmEnum.UnApproved))
  1767. {
  1768. //出库确认拒绝
  1769. auditEnum = GoodsAuditEnum.OutRejected;
  1770. }
  1771. else if (auditInfos.Where(x => x.AuditStatus == GoodsConfirmEnum.Confirmed).Count() == 2)
  1772. {
  1773. //1.出库确认完成
  1774. auditEnum = GoodsAuditEnum.OutConfirmed;
  1775. //2.更改前的状态为出库确认中 且 更改后的状态为出库确认完成 执行库存减操作
  1776. if (preChangeStatus == GoodsAuditEnum.OutConfirming || preChangeStatus == GoodsAuditEnum.OutRejected)
  1777. {
  1778. //2.1 更改库存
  1779. var goodsInfo = await _sqlSugar.Queryable<Pm_GoodsInfo>().Where(x => x.Id == receiveInfo.GoodsId).FirstAsync();
  1780. goodsInfo.StockQuantity -= receiveInfo.Quantity;
  1781. goodsInfo.OQ_Total += receiveInfo.Quantity;
  1782. goodsInfo.LastUpdateTime = DateTime.Now;
  1783. goodsInfo.LastUpdateUserId = userId;
  1784. var editGoods = await _sqlSugar
  1785. .Updateable(goodsInfo)
  1786. .UpdateColumns(x => new
  1787. {
  1788. x.StockQuantity,
  1789. x.OQ_Total,
  1790. x.LastUpdateUserId,
  1791. x.LastUpdateTime,
  1792. })
  1793. .Where(x => x.Id == receiveInfo.GoodsId)
  1794. .ExecuteCommandAsync();
  1795. if (editGoods < 1)
  1796. {
  1797. _jv.Msg = $"库存更新失败!";
  1798. return _jv;
  1799. }
  1800. //2.2 入库批次关联领用人 更改批次库存
  1801. var goodsStorages = await _sqlSugar
  1802. .Queryable<Pm_GoodsStorage>()
  1803. .Where(x => x.IsDel == 0 &&
  1804. x.GoodsId == receiveInfo.GoodsId &&
  1805. (x.Quantity - x.ReceiveQuantity) > 0
  1806. )
  1807. .OrderBy(x => x.CreateTime)
  1808. .ToListAsync();
  1809. var goodsReceiveInfos = new List<GoodsReceiveLinkStorageView>();
  1810. var batchStorageInfos = new List<Pm_GoodsStorage>();
  1811. var receiveQuantity = 0.00M; //领用总数量
  1812. foreach (var storage in goodsStorages)
  1813. {
  1814. if (receiveInfo.Quantity == receiveQuantity) break;
  1815. var thisBatchSurplusQuantity = storage.Quantity - storage.ReceiveQuantity;
  1816. if (thisBatchSurplusQuantity <= 0.00M) continue;
  1817. var thisBatchReceiveQuantity = 0.00M; //此批次领用数量
  1818. const decimal unit = 0.50M;
  1819. while (receiveQuantity < receiveInfo.Quantity)
  1820. {
  1821. if (thisBatchSurplusQuantity == thisBatchReceiveQuantity) break;
  1822. thisBatchReceiveQuantity += unit;
  1823. receiveQuantity += unit;
  1824. }
  1825. goodsReceiveInfos.Add(new GoodsReceiveLinkStorageView
  1826. {
  1827. StorageId = storage.Id,
  1828. Quantity = thisBatchReceiveQuantity
  1829. });
  1830. storage.ReceiveQuantity += thisBatchReceiveQuantity;
  1831. var storageUpd = storage;
  1832. //storageUpd.ReceiveQuantity += thisBatchReceiveQuantity;
  1833. batchStorageInfos.Add(storageUpd);
  1834. }
  1835. //2.2.1 更改批次库存
  1836. if (goodsReceiveInfos.Count > 0)
  1837. {
  1838. var edit1 = await _sqlSugar.Updateable(batchStorageInfos)
  1839. .UpdateColumns(x => x.ReceiveQuantity)
  1840. .WhereColumns(x => x.Id)
  1841. .ExecuteCommandAsync();
  1842. if (edit1 < 1)
  1843. {
  1844. _jv.Msg = $"批次库存更新失败!";
  1845. return _jv;
  1846. }
  1847. }
  1848. //2.2.2 添加入库批次关联领用人
  1849. if (goodsReceiveInfos.Count > 0)
  1850. {
  1851. goodsStorageInfo = JsonConvert.SerializeObject(goodsReceiveInfos);
  1852. }
  1853. }
  1854. }
  1855. else if (auditInfos.Where(x => x.AuditStatus == GoodsConfirmEnum.Confirmed).Count() == 1)
  1856. {
  1857. //出库确认中
  1858. auditEnum = GoodsAuditEnum.OutConfirming;
  1859. if (preChangeStatus == GoodsAuditEnum.OutConfirmed)
  1860. {
  1861. var goodsStorageInfo1 = receiveInfo.GoodsStorageInfo;
  1862. if (!string.IsNullOrEmpty(goodsStorageInfo))
  1863. {
  1864. var goodsStorageInfos = JsonConvert.DeserializeObject<List<GoodsReceiveLinkStorageView>>(goodsStorageInfo);
  1865. if (goodsStorageInfos.Any())
  1866. {
  1867. foreach (var item in goodsStorageInfos)
  1868. {
  1869. var newStorageInfo = await _sqlSugar.Queryable<Pm_GoodsStorage>()
  1870. .Where(x => x.IsDel == 0 && x.Id == item.StorageId)
  1871. .FirstAsync();
  1872. if (newStorageInfo == null) continue;
  1873. var newEdit = await _sqlSugar.Updateable(newStorageInfo)
  1874. .ReSetValue(x => x.ReceiveQuantity = x.ReceiveQuantity - item.Quantity)
  1875. .ExecuteCommandAsync();
  1876. if (newEdit < 1)
  1877. {
  1878. _jv.Msg = $"批次领用库存更新失败!";
  1879. return _jv;
  1880. }
  1881. }
  1882. }
  1883. }
  1884. }
  1885. }
  1886. else
  1887. {
  1888. auditEnum = GoodsAuditEnum.OutPending;
  1889. }
  1890. var statusDesc1 =statusDesc.ToString();
  1891. var changeStatus = await _sqlSugar
  1892. .Updateable<Pm_GoodsReceive>()
  1893. .SetColumns(x => new Pm_GoodsReceive()
  1894. {
  1895. AuditStatus = auditEnum,
  1896. StatusDesc = statusDesc1,
  1897. GoodsStorageInfo = goodsStorageInfo,
  1898. })
  1899. .Where(x => x.Id == receiveInfo.Id)
  1900. .ExecuteCommandAsync();
  1901. if (changeStatus > 0)
  1902. {
  1903. _jv.Code = StatusCodes.Status200OK;
  1904. }
  1905. return _jv;
  1906. }
  1907. /// <summary>
  1908. /// 物品领用 Del
  1909. /// </summary>
  1910. /// <param name="id"></param>
  1911. /// <param name="currUserId"></param>
  1912. /// <returns></returns>
  1913. public async Task<JsonView> GoodsReceiveDel(int id, int currUserId)
  1914. {
  1915. var receiveInfo = await _sqlSugar
  1916. .Queryable<Pm_GoodsReceive>()
  1917. .Where(x => x.IsDel == 0 && x.Id == id)
  1918. .FirstAsync();
  1919. if (receiveInfo.AuditStatus >= GoodsAuditEnum.Approved)
  1920. {
  1921. _jv.Msg = $"该条数据已进入审批流程,不可删除!";
  1922. return _jv;
  1923. }
  1924. var edit = await _sqlSugar
  1925. .Updateable<Pm_GoodsReceive>()
  1926. .SetColumns(x => new Pm_GoodsReceive()
  1927. {
  1928. IsDel = 1,
  1929. DeleteUserId = currUserId,
  1930. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  1931. })
  1932. .Where(x => x.Id == id)
  1933. .ExecuteCommandAsync();
  1934. if (edit > 0)
  1935. {
  1936. _jv.Msg = $"操作成功!";
  1937. _jv.Code = StatusCodes.Status200OK;
  1938. return _jv;
  1939. }
  1940. return _jv;
  1941. }
  1942. }
  1943. }