基础服务api
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

BatchingService.cs 16 KiB

10 months ago
11 months ago
11 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. using BPA.SAAS.Manage.Application.DataBase.Dtos.Batching;
  2. using BPA.SAAS.Manage.Application.DataBase.Interface;
  3. using BPA.SAAS.Manage.Comm.Const;
  4. using BPA.SAAS.Manage.Comm.Enum;
  5. using BPA.SAAS.Manage.Core.Base;
  6. using BPA.SAAS.Manage.Core.DataBase;
  7. using Swashbuckle.AspNetCore.SwaggerGen;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Text.RegularExpressions;
  13. using System.Threading.Tasks;
  14. namespace BPA.SAAS.Manage.Application.DataBase.Services
  15. {
  16. public class BatchingService: IBatchingService ,ITransient
  17. {
  18. private readonly ISqlSugarClient _db;
  19. public BatchingService(ISqlSugarClient db)
  20. {
  21. _db=db;
  22. }
  23. #region 物料
  24. /// <summary>
  25. /// 分页
  26. /// </summary>
  27. /// <param name="dto"></param>
  28. /// <returns></returns>
  29. public async Task<PageUtil> GetBatchingList(BatchingListQuery dto)
  30. {
  31. #region 查询条件
  32. List<IConditionalModel> conModels = new List<IConditionalModel>();
  33. if (!string.IsNullOrEmpty(dto.Name))//物料名称
  34. {
  35. conModels.Add(new ConditionalModel() { FieldName = "a.Batching_Name", ConditionalType = ConditionalType.Like, FieldValue = dto.Name });
  36. }
  37. if (!string.IsNullOrEmpty(dto.Code))//物料编码
  38. {
  39. conModels.Add(new ConditionalModel() { FieldName = "a.Code", ConditionalType = ConditionalType.Like, FieldValue = dto.Code });
  40. }
  41. if (!string.IsNullOrEmpty(dto.StockUint))//物料单位
  42. {
  43. conModels.Add(new ConditionalModel() { FieldName = "c.Id", ConditionalType = ConditionalType.Equal, FieldValue = dto.StockUint });
  44. }
  45. if (!string.IsNullOrEmpty(dto.Specs))//物料规格
  46. {
  47. conModels.Add(new ConditionalModel() { FieldName = "a.Specs", ConditionalType = ConditionalType.Equal, FieldValue = dto.Specs });
  48. }
  49. if (!string.IsNullOrEmpty(dto.Aittribute))//物料属性
  50. {
  51. conModels.Add(new ConditionalModel() { FieldName = "a.Aittribute", ConditionalType = ConditionalType.Equal, FieldValue = dto.Aittribute.ToString() });
  52. }
  53. if (!string.IsNullOrEmpty(dto.TypeID))//物料类别
  54. {
  55. conModels.Add(new ConditionalModel() { FieldName = "b.Id", ConditionalType = ConditionalType.Equal, FieldValue = dto.TypeID });
  56. }
  57. if (!string.IsNullOrEmpty(dto.Status))
  58. {
  59. conModels.Add(new ConditionalModel() { FieldName = "a.Status", ConditionalType = ConditionalType.Equal, FieldValue = dto.Status });
  60. }
  61. if (dto.Price != null)
  62. {
  63. conModels.Add(new ConditionalModel() { FieldName = "a.Price", ConditionalType = ConditionalType.Equal, FieldValue = dto.Price.ToString() });
  64. }
  65. if (dto.netrecovery != null)
  66. {
  67. conModels.Add(new ConditionalModel() { FieldName = "a.netrecovery", ConditionalType = ConditionalType.Equal, FieldValue = dto.netrecovery.ToString() });
  68. }
  69. #endregion
  70. RefAsync<int> total = 0;
  71. var res =await _db.Queryable<BPA_Batching, BPA_BatchingType, BPA_BatchingUint>((a, b, c) =>
  72. new JoinQueryInfos(JoinType.Inner, a.TypeID == b.Id, JoinType.Inner, a.StockUint == c.Id))
  73. //.Where((a, b, c) => a.IsDeleted == 0 && b.IsDeleted == 0 && c.IsDeleted == 0)
  74. .Where(conModels)
  75. .WhereIF(dto.CreateAt.HasValue, a => SqlFunc.DateIsSame(a.CreateAt, Convert.ToDateTime(dto.CreateAt), DateType.Day))
  76. .OrderBy((a, b, c) => a.CreateAt, OrderByType.Desc)
  77. .Select((a, b, c) => new BatchingListQuery()
  78. {
  79. Id = a.Id,
  80. Name = a.Batching_Name,
  81. Code = a.Code,
  82. StockUint = a.StockUint,
  83. StockUintName = c.Name,
  84. Specs = a.Specs,
  85. Aittribute = a.Aittribute.ToString(),
  86. TypeID = b.Id,
  87. TypeName = b.Name,
  88. CreateAt = a.CreateAt,
  89. Status = a.Status.ToString(),
  90. batchingType = a.Batching_Type,
  91. Price = a.Price,
  92. netrecovery = a.netrecovery,
  93. outstockUint = a.outstockUint,
  94. proportion = a.proportion,
  95. ForeignKeyRe = a.ForeignKeyRe
  96. })
  97. .ToPageListAsync(dto.Current, dto.PageSize, total);
  98. res.ForEach(list =>
  99. {
  100. int total1 = 0;
  101. //var res1 = _db.Queryable<BPA_ProductCode>()
  102. // .Where(a => a.IsDeleted == 0 && a.ProductID == list.Id)
  103. // .OrderBy(a => a.CreateAt, OrderByType.Asc)
  104. // .Select(a => new ProductDetailedDto
  105. // {
  106. // Id = a.Id,
  107. // Code = a.Code,
  108. // PackUnit = a.PackUnit,
  109. // Proportion = a.Proportion
  110. // })
  111. // .ToPageList(dto.Current, dto.PageSize, ref total1);
  112. list.MembersList = null;
  113. });
  114. PageUtil util = new PageUtil()
  115. {
  116. Total = total,
  117. Data = res
  118. };
  119. return util;
  120. }
  121. /// <summary>
  122. /// 添加
  123. /// </summary>
  124. /// <param name="dto"></param>
  125. /// <returns></returns>
  126. public async Task<bool> AddBatching(BatchingInfoDto dto)
  127. {
  128. var productCode = _db.Queryable<BPA_Batching>().Where(x => x.IsDeleted == 0 && x.Code == dto.code).ToList();
  129. if (productCode.Count() > 0)
  130. {
  131. throw Oops.Oh("编码已存在");
  132. }
  133. try
  134. {
  135. BPA_Batching bPA_Product = new BPA_Batching();
  136. bPA_Product.StockUint = dto.StockUint;
  137. bPA_Product.TypeID = dto.TypeID;
  138. bPA_Product.Code = dto.code;
  139. bPA_Product.Batching_Name = dto.Name;
  140. bPA_Product.Specs = dto.specs;
  141. bPA_Product.Status = CommonStatus.ENABLE;
  142. bPA_Product.Aittribute = Convert.ToInt32(dto.Aittribute);
  143. bPA_Product.Batching_Type = dto.batchingType;
  144. bPA_Product.Price = dto.Price;
  145. bPA_Product.netrecovery = dto.netrecovery;
  146. bPA_Product.outstockUint = dto.outstockUint;
  147. bPA_Product.proportion = dto.proportion;
  148. bPA_Product.ForeignKeyRe = dto.ForeignKeyRe;
  149. var res=await _db.Insertable(bPA_Product).CallEntityMethod(m => m.Create()).ExecuteCommandAsync();
  150. return res>0;
  151. }
  152. catch (Exception ex)
  153. {
  154. throw Oops.Oh("添加失败");
  155. }
  156. }
  157. /// <summary>
  158. /// 修改物料信息
  159. /// </summary>
  160. /// <param name="dto"></param>
  161. /// <returns></returns>
  162. public async Task<bool> UpdateBatching(BatchingInfoDto dto)
  163. {
  164. var Code = _db.Queryable<BPA_Batching>().Where(x => x.Id == dto.Id).First();
  165. if (Code.Code != dto.code)
  166. {
  167. throw Oops.Oh("编码已存在");
  168. }
  169. try
  170. {
  171. BPA_Batching bPA_Product = new BPA_Batching();
  172. bPA_Product.StockUint = dto.StockUint;
  173. bPA_Product.TypeID = dto.TypeID;
  174. bPA_Product.Code = dto.code;
  175. bPA_Product.Batching_Name = dto.Name;
  176. bPA_Product.Specs = dto.specs;
  177. bPA_Product.Id = dto.Id;
  178. bPA_Product.Aittribute = Convert.ToInt32(dto.Aittribute);
  179. bPA_Product.Batching_Type = dto.batchingType;
  180. bPA_Product.Price = dto.Price;
  181. bPA_Product.netrecovery = dto.netrecovery;
  182. bPA_Product.outstockUint = dto.outstockUint;
  183. bPA_Product.proportion = dto.proportion;
  184. bPA_Product.ForeignKeyRe = dto.ForeignKeyRe;
  185. if (!string.IsNullOrEmpty(dto.Status))
  186. {
  187. bPA_Product.Status = (CommonStatus)Enum.ToObject(typeof(CommonStatus), int.Parse(dto.Status));
  188. }
  189. var res=await _db.Updateable(bPA_Product).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync();
  190. return res>0;
  191. }
  192. catch (Exception)
  193. {
  194. throw Oops.Oh("更新失败");
  195. }
  196. }
  197. /// <summary>
  198. /// 删除物料信息
  199. /// </summary>
  200. /// <param name="Ids"></param>
  201. /// <returns></returns>
  202. public async Task<bool> BatchDelBatching(List<string> Ids)
  203. {
  204. try
  205. {
  206. // 查询数据库中是否存在未删除的活动信息
  207. var resEntitites = _db.Queryable<BPA_Batching>().In(Ids).ToList();
  208. var res =await _db.Deleteable(resEntitites).ExecuteCommandAsync();
  209. return res>0;
  210. }
  211. catch (Exception)
  212. {
  213. throw Oops.Oh("删除失败");
  214. }
  215. }
  216. /// <summary>
  217. /// 查询所有物料信息
  218. /// </summary>
  219. /// <returns></returns>
  220. public async Task<Dictionary<string, object>> GetBatchingList()
  221. {
  222. var res = await _db.Queryable<BPA_Batching>()
  223. .ToDictionaryAsync(x => x.Id, x => x.Batching_Name);
  224. return res;
  225. }
  226. /// <summary>
  227. /// 查询所有物料信息
  228. /// </summary>
  229. /// <returns></returns>
  230. public async Task<List<BatchingList>> GetBatchingSelectList()
  231. {
  232. var res = await _db.Queryable<BPA_Batching>().Select(x=>new BatchingList() { Id=x.Id,Name=x.Batching_Name})
  233. .ToListAsync();
  234. return res;
  235. }
  236. /// <summary>
  237. /// 更新物料状态
  238. /// </summary>
  239. /// <param name="dto"></param>
  240. /// <returns></returns>
  241. public async Task<bool> UpdateBatchingStatus(BatchingStatusDto dto)
  242. {
  243. try
  244. {
  245. // 查询数据库中是否存在未删除的活动信息
  246. var resEntitites = _db.Queryable<BPA_Batching>().Where(x => x.Id == dto.Id).First();
  247. if (resEntitites != null)
  248. {
  249. resEntitites.Status = (CommonStatus)Enum.ToObject(typeof(CommonStatus), dto.Status);
  250. }
  251. var res =await _db.Updateable(resEntitites).UpdateColumns(x => new { x.Status }).ExecuteCommandAsync();
  252. return res>0;
  253. }
  254. catch (Exception)
  255. {
  256. return false;
  257. }
  258. }
  259. /// <summary>
  260. /// 查询物料信息
  261. /// </summary>
  262. /// <returns></returns>
  263. public async Task<List<BatchingView>> GetByTypeBatching()
  264. {
  265. var item = await _db.Queryable<BPA_Batching, BPA_BatchingType>((a, b) => new JoinQueryInfos(
  266. JoinType.Left, a.TypeID == b.Id
  267. )).Select((a, b) => new BatchingView() { Id = a.Id, Name = a.Batching_Name, TypeName = b.Name }).ToListAsync();
  268. return item;
  269. }
  270. #endregion
  271. #region 物料类型
  272. public async Task<List<dynamic>> GetBatchingTypeList()
  273. {
  274. var res = await _db.Queryable<BPA_BatchingType>().Select<dynamic>(x => new
  275. {
  276. id = x.Id,
  277. name=x.Name
  278. }) .ToListAsync();
  279. return res;
  280. }
  281. public async Task<List<dynamic>> GetBatchingTypeList_alm()
  282. {
  283. var groupId = App.HttpContext.Request.Headers["groupId"].ToString();
  284. if (string.IsNullOrWhiteSpace(groupId)) throw Oops.Oh("加盟商id不能为空");
  285. var res = await _db.Queryable<BPA_BatchingType>().Where(x=>x.GroupId== groupId).Select<dynamic>(x => new
  286. {
  287. id = x.Id,
  288. name = x.Name
  289. }).ToListAsync();
  290. return res;
  291. }
  292. public async Task<bool> AddBatchingType(BatchingTypeDto dto)
  293. {
  294. var productCode = _db.Queryable<BPA_BatchingType>().Where(x => x.Name== dto.Name).ToList();
  295. if (productCode.Count() > 0)
  296. {
  297. throw Oops.Oh("物料类型已存在");
  298. }
  299. try
  300. {
  301. BPA_BatchingType bPA_Product = new BPA_BatchingType();
  302. bPA_Product.Name = dto.Name;
  303. var res = await _db.Insertable(bPA_Product).CallEntityMethod(m => m.Create()).ExecuteCommandAsync();
  304. return res > 0;
  305. }
  306. catch (Exception ex)
  307. {
  308. throw Oops.Oh("添加失败");
  309. }
  310. }
  311. public async Task<bool> BatchTypeDel(string id)
  312. {
  313. try
  314. {
  315. // 查询数据库中是否存在未删除的活动信息
  316. var resEntitites =await _db.Queryable<BPA_Batching>().Where(x=>x.Id== id).FirstAsync();
  317. resEntitites.IsDeleted= 1;
  318. var res = await _db.Updateable(resEntitites).ExecuteCommandAsync();
  319. return res > 0;
  320. }
  321. catch (Exception)
  322. {
  323. throw Oops.Oh("删除失败");
  324. }
  325. }
  326. #endregion
  327. #region 物料单位
  328. public async Task<List<dynamic>> GetBatchingUintList()
  329. {
  330. var res = await _db.Queryable<BPA_BatchingUint>().Select<dynamic>(x => new
  331. {
  332. id = x.Id,
  333. name = x.Name
  334. }).ToListAsync();
  335. return res;
  336. }
  337. public async Task<List<dynamic>> GetBatchingUintList_alm()
  338. {
  339. var groupId = App.HttpContext.Request.Headers["groupId"].ToString();
  340. if(string.IsNullOrWhiteSpace(groupId)) throw Oops.Oh("加盟商id不能为空");
  341. var res = await _db.Queryable<BPA_BatchingUint>().Where(x=>x.GroupId== groupId).Select<dynamic>(x => new
  342. {
  343. id = x.Id,
  344. name = x.Name
  345. }).ToListAsync();
  346. return res;
  347. }
  348. public async Task<bool> AddBatchingUint(BatchingUintDto dto)
  349. {
  350. var productCode = _db.Queryable<BPA_BatchingUint>().Where(x => x.Name == dto.Name).ToList();
  351. if (productCode.Count() > 0)
  352. {
  353. throw Oops.Oh("物料单位已存在");
  354. }
  355. try
  356. {
  357. BPA_BatchingUint bPA_Product = new BPA_BatchingUint();
  358. bPA_Product.Name = dto.Name;
  359. var res = await _db.Insertable(bPA_Product).CallEntityMethod(m => m.Create()).ExecuteCommandAsync();
  360. return res > 0;
  361. }
  362. catch (Exception ex)
  363. {
  364. throw Oops.Oh("添加失败");
  365. }
  366. }
  367. public async Task<bool> BatchingUintDel(string id)
  368. {
  369. try
  370. {
  371. // 查询数据库中是否存在未删除的活动信息
  372. var resEntitites = await _db.Queryable<BPA_BatchingUint>().Where(x => x.Id == id).FirstAsync();
  373. resEntitites.IsDeleted = 1;
  374. var res = await _db.Updateable(resEntitites).ExecuteCommandAsync();
  375. return res > 0;
  376. }
  377. catch (Exception)
  378. {
  379. throw Oops.Oh("删除失败");
  380. }
  381. }
  382. #endregion
  383. }
  384. }