基础服务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.
 
 

226 lines
9.0 KiB

  1. using BPA.SAAS.Manage.Application.Device.Dtos.DeviceTechnology;
  2. using BPA.SAAS.Manage.Application.Device.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.Device;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Text.RegularExpressions;
  12. using System.Threading.Tasks;
  13. namespace BPA.SAAS.Manage.Application.Device.Services
  14. {
  15. public class DeviceTechnologyService: IDeviceTechnologyService, ITransient
  16. {
  17. ISqlSugarClient _db;
  18. public DeviceTechnologyService(ISqlSugarClient db)
  19. {
  20. _db = db;
  21. }
  22. #region 工艺基础信息
  23. /// <summary>
  24. /// 获取工艺基础信息列表
  25. /// </summary>
  26. /// <param name="inputDto"></param>
  27. /// <returns></returns>
  28. public async Task<PageUtil> GetDeviceTechnologyPage(DeviceTechnologyPageBase inputDto)
  29. {
  30. RefAsync<int> total = 0;
  31. var res = await _db.Queryable<BPA_DeviceTechnology, BPA_DeviceVesion>((x, b) => new JoinQueryInfos(JoinType.Left, b.Id == x.DeviceVersionKey))
  32. .OrderBy((x, b) => x.CreateAt, OrderByType.Desc)
  33. .WhereIF(!string.IsNullOrWhiteSpace(inputDto.Name), (x, b) => x.Name.Contains(inputDto.Name))
  34. .WhereIF(inputDto.Status != null, (x, b) => x.Status == inputDto.Status)
  35. .Select((x, b) => new
  36. {
  37. Name = x.Name,
  38. Status = x.Status,
  39. x.Id,
  40. x.GroupId,
  41. x.ForeignKeyRe,
  42. x.DeviceVersionKey,
  43. DeviceTypeKey = b.DeviceTypeKey,
  44. Vesion = b.Vesion
  45. })
  46. .ToPageListAsync(inputDto.Current, inputDto.PageSize, total);
  47. return new PageUtil()
  48. {
  49. Data = res,
  50. Total = total
  51. };
  52. }
  53. /// <summary>
  54. /// 查询所有工艺信息
  55. /// </summary>
  56. /// <returns></returns>
  57. public async Task<List<DeviceTechnologyDto>> GetDeviceTechnology()
  58. {
  59. var res =await _db.Queryable<BPA_DeviceTechnology>().Where(x => x.Status == 0)
  60. .OrderBy(i => i.CreateAt, OrderByType.Desc)
  61. .Select(x => new DeviceTechnologyDto()
  62. {
  63. Id = x.Id,
  64. Name = x.Name,
  65. IsBatch = SqlFunc.Subqueryable<BPA_DeviceTechnologyAction>().Where(p => p.DevicetechnologyId == x.Id).Any()
  66. })
  67. .ToListAsync();
  68. return res;
  69. }
  70. /// <summary>
  71. /// 添加工艺
  72. /// </summary>
  73. /// <param name="inputDto"></param>
  74. /// <returns></returns>
  75. public async Task<bool> AddDeviceTechnology(DeviceTechnologyBaseDto inputDto)
  76. {
  77. var data = _db.Queryable<BPA_DeviceTechnology>()
  78. .Where(a => a.Name == inputDto.Name).ToList();
  79. if (data.Count > 0)
  80. {
  81. throw Oops.Oh("工艺名称已存在");
  82. }
  83. else
  84. {
  85. var res =await _db.Insertable(new BPA_DeviceTechnology()
  86. {
  87. Id = Guid.NewGuid().ToString(),
  88. Name = inputDto.Name,
  89. Status = CommonStatus.ENABLE,
  90. CreateAt = DateTime.Now,
  91. IsDeleted = 0,
  92. ForeignKeyRe = inputDto.ForeignKeyRe,
  93. DeviceVersionKey = inputDto.DeviceVersionKey
  94. }).CallEntityMethod(m => m.Create()).ExecuteCommandAsync();
  95. return res > 0;
  96. }
  97. }
  98. /// <summary>
  99. /// 修改工艺
  100. /// </summary>
  101. /// <param name="inputDto"></param>
  102. /// <returns></returns>
  103. public async Task<bool> UpdateDeviceTechnology(DeviceTechnologyBaseDto inputDto)
  104. {
  105. var check = _db.Queryable<BPA_DeviceTechnology>().Any(a => a.Id != inputDto.Id && a.Name == inputDto.Name);
  106. if (check) throw Oops.Oh("工艺名称已存在");
  107. var data = _db.Queryable<BPA_DeviceTechnology>().Where(a => a.Id == inputDto.Id).First();
  108. data.Name = inputDto.Name;
  109. data.DeviceVersionKey = inputDto.DeviceVersionKey;
  110. data.ForeignKeyRe = inputDto.ForeignKeyRe;
  111. var res =await _db.Updateable(data).ExecuteCommandAsync();
  112. return res > 0;
  113. }
  114. /// <summary>
  115. /// 删除配方工艺
  116. /// </summary>
  117. /// <param name="ids"></param>
  118. /// <returns></returns>
  119. public async Task<bool> DeleteDeviceTechnology(List<string> ids)
  120. {
  121. var resEntity = _db.Queryable<BPA_DeviceTechnology>().Where(x => ids.Contains(x.Id)).ToList();
  122. foreach (var item in resEntity)
  123. {
  124. item.IsDeleted = 1;
  125. }
  126. var res =await _db.Updateable(resEntity).ExecuteCommandAsync();
  127. return res > 0;
  128. }
  129. #endregion
  130. #region 工艺模型
  131. /// <summary>
  132. /// 根据工艺id查询工艺模型
  133. /// </summary>
  134. /// <returns></returns>
  135. public async Task<List<BPA_DeviceTechnologyAction>> GetTechnologyActionList(string devicetechnologyId)
  136. {
  137. var res = await _db.Queryable<BPA_DeviceTechnologyAction>().Where(x => x.IsDeleted == 0 && x.DevicetechnologyId == devicetechnologyId )
  138. .OrderBy(i => i.Sort, OrderByType.Asc)
  139. .ToListAsync();
  140. return res;
  141. }
  142. /// <summary>
  143. /// 查询所有工艺模型
  144. /// </summary>
  145. /// <returns></returns>
  146. public async Task<List<BPA_DeviceTechnologyAction>> GetTechnologyActionList()
  147. {
  148. var res = await _db.Queryable<BPA_DeviceTechnologyAction>().Where(x => x.IsDeleted == 0)
  149. .OrderBy(i => i.Sort, OrderByType.Asc)
  150. .ToListAsync();
  151. return res;
  152. }
  153. /// <summary>
  154. /// 添加工艺模型
  155. /// </summary>
  156. /// <param name="inputDto"></param>
  157. /// <returns></returns>
  158. public async Task<bool> AddDeviceTechnologyAction(DeviceTechnologyActionBaseDto inputDto)
  159. {
  160. var check = _db.Queryable<BPA_DeviceTechnologyAction>()
  161. .Any(a => a.DevicetechnologyId == inputDto.DevicetechnologyId && a.IsDeleted == 0 && a.ActionName == inputDto.ActionName && a.ActionType == inputDto.ActionType);
  162. if (check)
  163. {
  164. throw Oops.Oh("工艺流程动作已存在");
  165. }
  166. else
  167. {
  168. var res = await _db.Insertable(new BPA_DeviceTechnologyAction()
  169. {
  170. DevicetechnologyId = inputDto.DevicetechnologyId,
  171. ActionName = inputDto.ActionName,
  172. ActionType = inputDto.ActionType,
  173. ActionValue = inputDto.ActionValue,
  174. Unit = inputDto.Unit,
  175. IsBatch = true,//inputDto.IsBatch,
  176. IsDeleted = 0,
  177. Sort = inputDto.Sort,
  178. }).CallEntityMethod(m => m.Create()).ExecuteCommandAsync(); ;
  179. return res > 0;
  180. }
  181. }
  182. /// <summary>
  183. /// 修改工艺模型
  184. /// </summary>
  185. /// <param name="inputDto"></param>
  186. /// <returns></returns>
  187. public async Task<bool> UpdateBomTechnology(DeviceTechnologyActionBaseDto inputDto)
  188. {
  189. var check = _db.Queryable<BPA_DeviceTechnologyAction>().Any(a => a.DevicetechnologyId == inputDto.DevicetechnologyId && a.ActionName == inputDto.ActionName && a.ActionType == inputDto.ActionType && a.Id != inputDto.Id);
  190. if (check) throw Oops.Oh("工艺流程动作已存在");
  191. var data = _db.Queryable<BPA_DeviceTechnologyAction>().Where(a => a.Id == inputDto.Id).First();
  192. if (data == null) throw Oops.Oh("工艺流程动作不存在");
  193. data.ActionName = inputDto.ActionName;
  194. data.ActionType = inputDto.ActionType;
  195. data.ActionValue = inputDto.ActionValue;
  196. data.Unit = inputDto.Unit;
  197. data.IsBatch = inputDto.IsBatch;
  198. data.Sort = inputDto.Sort;
  199. var res = await _db.Updateable(data).ExecuteCommandAsync();
  200. return res > 0;
  201. }
  202. /// <summary>
  203. /// 删除工艺模型
  204. /// </summary>
  205. /// <param name="ids"></param>
  206. /// <returns></returns>
  207. public async Task<bool> DeleteTechnologyAction(List<string> ids)
  208. {
  209. var resEntity = _db.Queryable<BPA_DeviceTechnologyAction>().Where(x => ids.Contains(x.Id)).ToList();
  210. foreach (var item in resEntity)
  211. {
  212. item.IsDeleted = 1;
  213. }
  214. var res = await _db.Updateable(resEntity).ExecuteCommandAsync();
  215. return res > 0;
  216. }
  217. #endregion
  218. }
  219. }