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

DeviceVesionService.cs 17 KiB

11 months ago
11 months ago
11 months ago
10 months ago
11 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
11 months ago
11 months ago
11 months ago
11 months ago
10 months ago
10 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. using BPA.SAAS.Manage.Application.Device.Dtos.DeviceVesion;
  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 BPA.SAAS.Manage.Core.Product;
  8. using Microsoft.AspNetCore.Server.IISIntegration;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. namespace BPA.SAAS.Manage.Application.Device.Services
  15. {
  16. public class DeviceVesionService: IDeviceVesionService, ITransient
  17. {
  18. ISqlSugarClient _db;
  19. public DeviceVesionService(ISqlSugarClient db)
  20. {
  21. _db=db;
  22. }
  23. /// <summary>
  24. /// 分页查询
  25. /// </summary>
  26. /// <param name="inputDto"></param>
  27. /// <returns></returns>
  28. public async Task<PageUtil> GetDeviceVesionPageAsync(DeviceVesionQueryInputDto inputDto)
  29. {
  30. var total = new RefAsync<int>();
  31. var data = await _db.Queryable<BPA_ProductVesion,BPA_Product>((a, b) => new JoinQueryInfos(JoinType.Left, b.Id == a.ProductId))
  32. .WhereIF(!string.IsNullOrWhiteSpace(inputDto.ProductName), (a, b) => b.Name.Contains(inputDto.ProductName))
  33. .WhereIF(!string.IsNullOrWhiteSpace(inputDto.Vesion), (a, b) => a.Vesion.Contains(inputDto.Vesion))
  34. .OrderBy(a => a.CreateAt, OrderByType.Desc)
  35. .Select((a,b)=>new DeviceVesionModel()
  36. {
  37. Id=a.Id.SelectAll(),
  38. ProductName=b.Name,
  39. ProductCode=b.Code,
  40. ProductNumber=a.ProductNumber,
  41. ProductUrl=a.ProductUrl,
  42. })
  43. .ToPageListAsync(inputDto.Current, inputDto.PageSize, total);
  44. return new PageUtil()
  45. {
  46. Data = data,
  47. Total = total
  48. };
  49. }
  50. /// <summary>
  51. /// 新增
  52. /// </summary>
  53. /// <returns></returns>
  54. public async Task<bool> AddDeviceVesionAsync(DeviceVesionBaseDto inputDto)
  55. {
  56. try
  57. {
  58. _db.Ado.BeginTran();
  59. var res = await _db.Insertable(new BPA_ProductVesion
  60. {
  61. Vesion = inputDto.Vesion,
  62. ProductId = inputDto.ProductId,
  63. TemplatePath = inputDto.TemplatePath,
  64. ProductNumber = inputDto.ProductNumber,
  65. ProductUrl = inputDto.ProductUrl,
  66. Status = CommonStatus.ENABLE
  67. }).CallEntityMethod(m => m.Create()).ExecuteReturnEntityAsync();
  68. var Product = _db.Queryable<BPA_Product>().Where(x => x.Id == inputDto.ProductId).First();
  69. #region 添加默认功能和topics
  70. List<BPA_ProductTopics> list = new();
  71. var goodspushtopics = new BPA_ProductTopics()
  72. {
  73. Topics = " /" + Product.Key + "/" + inputDto.Vesion + "/${deviceKey}/defaul/goodspush",
  74. TopicsType = TopicsTypeEnum.SUBSCRIBE,
  75. Description = "商品数据下发",
  76. ProductId = inputDto.ProductId,
  77. ProductVesionId = res.Id,
  78. Name = "商品数据下发",
  79. IsDefault = true
  80. };
  81. var goodspushtopics_reply = new BPA_ProductTopics()
  82. {
  83. Topics = " /" + Product.Key + "/" + inputDto.Vesion + "/${deviceKey}/defaul/goodspush_reply",
  84. TopicsType = TopicsTypeEnum.PUBLISH,
  85. Description = "响应商品数据下发",
  86. ProductId = inputDto.ProductId,
  87. ProductVesionId = res.Id,
  88. Name = "商品数据下发",
  89. IsDefault = true
  90. };
  91. var batchingpushtopics = new BPA_ProductTopics()
  92. {
  93. Topics = " /" + Product.Key + "/" + inputDto.Vesion + "/${deviceKey}/defaul/batvhingpush",
  94. TopicsType = TopicsTypeEnum.PUBLISH,
  95. Description = "物料数据下发",
  96. ProductId = inputDto.ProductId,
  97. ProductVesionId = res.Id,
  98. Name = "物料数据下发",
  99. IsDefault = true
  100. };
  101. var batchingpushtopics_reply = new BPA_ProductTopics()
  102. {
  103. Topics = " /" + Product.Key + "/" + inputDto.Vesion + "/${deviceKey}/defaul/batvhingpush_reply",
  104. TopicsType = TopicsTypeEnum.SUBSCRIBE,
  105. Description = "响应物料数据下发",
  106. ProductId = inputDto.ProductId,
  107. ProductVesionId = res.Id,
  108. Name = "物料数据下发",
  109. IsDefault = true
  110. };
  111. var chnologypushtopics = new BPA_ProductTopics()
  112. {
  113. Topics = " /" + Product.Key + "/" + inputDto.Vesion + "/${deviceKey}/defaul/chnologypush",
  114. TopicsType = TopicsTypeEnum.PUBLISH,
  115. Description = "工艺数据下发",
  116. ProductId = inputDto.ProductId,
  117. ProductVesionId = res.Id,
  118. Name = "工艺数据下发",
  119. IsDefault = true
  120. };
  121. var chnologypushtopics_reply = new BPA_ProductTopics()
  122. {
  123. Topics = " /" + Product.Key + "/" + inputDto.Vesion + "/${deviceKey}/defaul/chnologypush_reply",
  124. TopicsType = TopicsTypeEnum.SUBSCRIBE,
  125. Description = "响应工艺数据下发",
  126. ProductId = inputDto.ProductId,
  127. Name = "工艺数据下发",
  128. ProductVesionId = res.Id,
  129. IsDefault = true
  130. };
  131. list.Add(goodspushtopics);
  132. list.Add(goodspushtopics_reply);
  133. list.Add(batchingpushtopics);
  134. list.Add(batchingpushtopics_reply);
  135. list.Add(chnologypushtopics);
  136. list.Add(chnologypushtopics_reply);
  137. await _db.Insertable(list).CallEntityMethod(m => m.Create()).ExecuteCommandAsync();
  138. List<BPA_ProductFunction> ProductFunctionlist = new();
  139. var goodsProductFunction = new BPA_ProductFunction()
  140. {
  141. Id=Guid.NewGuid().ToString(),
  142. CreateAt= DateTime.Now,
  143. DataType = "",
  144. Type = FunctionTypeEnum.SERVER,
  145. Name = "商品数据下发",
  146. Description = "商品数据下发",
  147. ProductId = inputDto.ProductId,
  148. DeviceVersionKey = res.Id,
  149. IsDefault = true
  150. };
  151. var goodsProductFunction_reply = new BPA_ProductFunction()
  152. {
  153. Id = Guid.NewGuid().ToString(),
  154. CreateAt = DateTime.Now,
  155. DataType = "",
  156. Type = FunctionTypeEnum.SERVER,
  157. Name = "响应商品数据下发",
  158. Description = "响应商品数据下发",
  159. ProductId = inputDto.ProductId,
  160. DeviceVersionKey = res.Id,
  161. IsDefault = true
  162. };
  163. var batchingProductFunction = new BPA_ProductFunction()
  164. {
  165. Id = Guid.NewGuid().ToString(),
  166. CreateAt = DateTime.Now,
  167. DataType = "",
  168. Type = FunctionTypeEnum.SERVER,
  169. Name = "物料数据下发",
  170. Description = "物料数据下发",
  171. ProductId = inputDto.ProductId,
  172. DeviceVersionKey = res.Id,
  173. IsDefault = true
  174. };
  175. var batchingProductFunction_reply = new BPA_ProductFunction()
  176. {
  177. Id = Guid.NewGuid().ToString(),
  178. CreateAt = DateTime.Now,
  179. DataType = "",
  180. Type = FunctionTypeEnum.SERVER,
  181. Name = "响应物料数据下发",
  182. Description = "响应物料数据下发",
  183. ProductId = inputDto.ProductId,
  184. DeviceVersionKey = res.Id,
  185. IsDefault = true
  186. };
  187. var chnologyProductFunction = new BPA_ProductFunction()
  188. {
  189. Id = Guid.NewGuid().ToString(),
  190. CreateAt = DateTime.Now,
  191. DataType = "",
  192. Type = FunctionTypeEnum.SERVER,
  193. Name = "工艺数据下发",
  194. Description = "工艺数据下发",
  195. ProductId = inputDto.ProductId,
  196. DeviceVersionKey = res.Id,
  197. IsDefault = true
  198. };
  199. var chnologyProductFunction_reply = new BPA_ProductFunction()
  200. {
  201. Id = Guid.NewGuid().ToString(),
  202. CreateAt = DateTime.Now,
  203. DataType = "",
  204. Type = FunctionTypeEnum.SERVER,
  205. Name = "响应工艺数据下发",
  206. Description = "响应工艺数据下发",
  207. ProductId = inputDto.ProductId,
  208. DeviceVersionKey = res.Id,
  209. IsDefault = true
  210. };
  211. ProductFunctionlist.Add(goodsProductFunction);
  212. ProductFunctionlist.Add(goodsProductFunction_reply);
  213. ProductFunctionlist.Add(batchingProductFunction);
  214. ProductFunctionlist.Add(batchingProductFunction_reply);
  215. ProductFunctionlist.Add(chnologyProductFunction);
  216. ProductFunctionlist.Add(chnologyProductFunction_reply);
  217. await _db.Insertable(ProductFunctionlist).ExecuteCommandAsync();
  218. List<BPA_ProductFunctionAction> ProductFunctionActionlist = new();
  219. var goodsProductFunctionActionlist = new BPA_ProductFunctionAction()
  220. {
  221. ActionType = "textareaary",
  222. ProductFunctionId = goodsProductFunction.Id,
  223. ActionName = "DataSoure",
  224. ActionValue = "",
  225. IsDefault = true
  226. };
  227. var batchingProductFunctionActionlist = new BPA_ProductFunctionAction()
  228. {
  229. ActionType = "textareaary",
  230. ProductFunctionId = batchingProductFunction.Id,
  231. ActionName = "DataSoure",
  232. ActionValue = "",
  233. IsDefault = true
  234. };
  235. var chnologyProductFunctionActionlist = new BPA_ProductFunctionAction()
  236. {
  237. ActionType = "textareaary",
  238. ProductFunctionId = chnologyProductFunction.Id,
  239. ActionName = "DataSoure",
  240. ActionValue = "",
  241. IsDefault = true
  242. };
  243. var goodsProductFunctionActionlist_reply = new BPA_ProductFunctionAction()
  244. {
  245. ActionType = "textareaary",
  246. ProductFunctionId = goodsProductFunction_reply.Id,
  247. ActionName = "DataSoure",
  248. ActionValue = "",
  249. IsDefault = true
  250. };
  251. var batchingProductFunctionActionlist_reply = new BPA_ProductFunctionAction()
  252. {
  253. ActionType = "textareaary",
  254. ProductFunctionId = batchingProductFunction_reply.Id,
  255. ActionName = "DataSoure",
  256. ActionValue = "",
  257. IsDefault = true
  258. };
  259. var chnologyProductFunctionActionlist_reply = new BPA_ProductFunctionAction()
  260. {
  261. ActionType = "textareaary",
  262. ProductFunctionId = chnologyProductFunction_reply.Id,
  263. ActionName = "DataSoure",
  264. ActionValue = "",
  265. IsDefault = true
  266. };
  267. ProductFunctionActionlist.Add(goodsProductFunctionActionlist);
  268. ProductFunctionActionlist.Add(batchingProductFunctionActionlist);
  269. ProductFunctionActionlist.Add(chnologyProductFunctionActionlist);
  270. ProductFunctionActionlist.Add(goodsProductFunctionActionlist_reply);
  271. ProductFunctionActionlist.Add(batchingProductFunctionActionlist_reply);
  272. ProductFunctionActionlist.Add(chnologyProductFunctionActionlist_reply);
  273. await _db.Insertable(ProductFunctionActionlist).CallEntityMethod(m => m.Create()).ExecuteCommandAsync();
  274. #endregion
  275. _db.Ado.CommitTran();
  276. return res != null;
  277. }
  278. catch (Exception e)
  279. {
  280. _db.Ado.RollbackTran();
  281. throw Oops.Oh("添加失败,失败信息:"+e.Message);
  282. }
  283. }
  284. /// <summary>
  285. /// 删除
  286. /// </summary>
  287. /// <param name="inputList"></param>
  288. /// <returns></returns>
  289. public async Task<bool> DelDeviceVesionAsync(List<string> inputList)
  290. {
  291. try
  292. {
  293. _db.Ado.BeginTran();
  294. var data = await _db.Queryable<BPA_DeviceInfo>().Where(x => inputList.Contains(x.ProductVersionId)).ToListAsync();
  295. if (data.Count > 0)
  296. {
  297. throw Oops.Oh("当前版本已有设备使用,无法删除");
  298. }
  299. var datas = await _db.Queryable<BPA_ProductVesion>()
  300. .Where(x => inputList.Contains(x.Id))
  301. .ToListAsync();
  302. var ProductFunctions = await _db.Queryable<BPA_ProductFunction>()
  303. .Where(x => inputList.Contains(x.DeviceVersionKey))
  304. .ToListAsync();
  305. var ProductTopics = await _db.Queryable<BPA_ProductTopics>()
  306. .Where(x => inputList.Contains(x.ProductVesionId))
  307. .ToListAsync();
  308. _db.Deleteable(ProductTopics).ExecuteCommand();//删除相关topic
  309. _db.Deleteable(ProductFunctions).ExecuteCommand();//删除相关服务和功能
  310. var res=await _db.Deleteable(datas).ExecuteCommandAsync();
  311. _db.Ado.CommitTran();
  312. return res>0;
  313. }
  314. catch (Exception e)
  315. {
  316. _db.Ado.RollbackTran();
  317. throw Oops.Oh("删除失败,失败信息:"+e.Message);
  318. }
  319. }
  320. /// <summary>
  321. /// 修改
  322. /// </summary>
  323. /// <returns></returns>
  324. public async Task<bool> UpdateDeviceVesionAsync(DeviceVesionBaseDto inputDto)
  325. {
  326. var data = await _db.Queryable<BPA_ProductVesion>().Where(x => x.Id == inputDto.Id).FirstAsync();
  327. if (data != null)
  328. {
  329. var res = _db.Updateable<BPA_ProductVesion>().SetColumns(t => t.Vesion == inputDto.Vesion)
  330. .SetColumns(t => t.TemplatePath == inputDto.TemplatePath)
  331. .SetColumns(t => t.ProductNumber == inputDto.ProductNumber)
  332. .SetColumns(t => t.ProductUrl == inputDto.ProductUrl)
  333. .SetColumns(t => t.ProductId == inputDto.ProductId)
  334. .SetColumns(t => t.Status == (CommonStatus)inputDto.Status).Where(t => t.Id == inputDto.Id)
  335. .ExecuteCommandHasChange();
  336. return res;
  337. }
  338. return false;
  339. }
  340. /// <summary>
  341. /// 更新状态
  342. /// </summary>
  343. /// <param name="inputDto"></param>
  344. /// <returns></returns>
  345. public async Task<bool> UpdateDeviceVesionSatatus(DeviceVesionSatatusDto inputDto)
  346. {
  347. var data = await _db.Queryable<BPA_ProductVesion>().Where(x => x.Id == inputDto.Id).FirstAsync();
  348. if (data != null)
  349. {
  350. var res = _db.Updateable<BPA_ProductVesion>()
  351. .SetColumns(t => t.Status == (CommonStatus)inputDto.Status).Where(t => t.Id == inputDto.Id)
  352. .ExecuteCommandHasChange();
  353. return res;
  354. }
  355. return false;
  356. }
  357. /// <summary>
  358. /// 根据产品查询版本
  359. /// </summary>
  360. /// <param name="Code"></param>
  361. /// <returns></returns>
  362. public async Task<List<BPA_ProductVesion>> GetDeviceVesion(string ProductId)
  363. {
  364. var resEntity =await _db.Queryable<BPA_ProductVesion>().Where(a => a.ProductId == ProductId && a.Status==0).Select(a => new BPA_ProductVesion() { Id = a.Id.SelectAll() }).ToListAsync();
  365. return resEntity;
  366. }
  367. /// <summary>
  368. /// 查询版本列表
  369. /// </summary>
  370. /// <returns></returns>
  371. public async Task<List<BPA_ProductVesion>> GetDeviceVesionList()
  372. {
  373. var resEntity =await _db.Queryable<BPA_ProductVesion>()
  374. .Select(a => new BPA_ProductVesion() { Id = a.Id.SelectAll() })
  375. .ToListAsync();
  376. return resEntity;
  377. }
  378. }
  379. }