电子药箱通讯服务端
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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. using RDH.Data.Models;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Xml.Linq;
  8. namespace RDH.Data.BLL
  9. {
  10. public partial class PortableStorageItemBLL : BaseOrclBLL<PortableStorageItem>
  11. {
  12. public PortableStorageItemBLL() : base()
  13. {
  14. AliasTableName = "psi";
  15. }
  16. internal override String TABLE_NAME { get { return "PORTABLE_STORAGE_ITEM"; } }//TB_NAME
  17. internal override string ENTITY_NAME { get { return "PortableStorageItem"; } }
  18. internal override String KEY_COLUMN { get { return "KEY"; } }//KEY_COLUMN
  19. internal override void InitMaps()
  20. {
  21. ColumnPropMaps.Add("KEY", "Key");
  22. ColumnPropMaps.Add("PORTABLE_STORAGE_KEY", "PortableStorageKey");
  23. ColumnPropMaps.Add("MAX_QUANTITY", "MaxQuantity");
  24. ColumnPropMaps.Add("ALART_QUANTITY", "AlartQuantity");
  25. ColumnPropMaps.Add("CURRENT_QUANTITY", "CurrentQuantity");
  26. ColumnPropMaps.Add("ITEM_KEY", "ItemKey");
  27. ColumnPropMaps.Add("CREATE_BY", "CreateBy");
  28. ColumnPropMaps.Add("CREATE_TIME", "CreateTime");
  29. ColumnPropMaps.Add("FLAG", "Flag");
  30. ColumnPropMaps.Add("CLIENT_TIME", "ClientTime");
  31. ColumnPropMaps.Add("SERVER_TIME", "ServerTime");
  32. ColumnPropMaps.Add("EXT01", "Ext01");
  33. ColumnPropMaps.Add("EXT02", "Ext02");
  34. ColumnPropMaps.Add("EXT03", "Ext03");
  35. ColumnPropMaps.Add("EXT04", "Ext04");
  36. ColumnPropMaps.Add("EXT05", "Ext05");
  37. ColumnPropMaps.Add("EXT06", "Ext06");
  38. ColumnPropMaps.Add("EXT07", "Ext07");
  39. ColumnPropMaps.Add("EXT08", "Ext08");
  40. ColumnPropMaps.Add("EXT09", "Ext09");
  41. ColumnPropMaps.Add("EXT10", "Ext10");
  42. }
  43. internal override object GetParam(PortableStorageItem item)
  44. {
  45. return new
  46. {
  47. AlartQuantity = item.AlartQuantity,
  48. CurrentQuantity = item.CurrentQuantity,
  49. MaxQuantity = item.MaxQuantity,
  50. PortableStorageKey = item.PortableStorageKey,
  51. ItemKey = item.ItemKey,
  52. CreateBy = item.CreateBy,
  53. CreateTime = item.CreateTime,
  54. Key = item.Key,
  55. Flag = item.Flag,
  56. ClientTime = item.ClientTime,
  57. ServerTime = item.ServerTime,
  58. Ext01 = item.Ext01,
  59. Ext02 = item.Ext02,
  60. Ext03 = item.Ext03,
  61. Ext04 = item.Ext04,
  62. Ext05 = item.Ext05,
  63. Ext06 = item.Ext06,
  64. Ext07 = item.Ext07,
  65. Ext08 = item.Ext08,
  66. Ext09 = item.Ext09,
  67. Ext10 = item.Ext10,
  68. };
  69. }
  70. public List<PortableStorageItem> ListPortableStorageItemsWithItemLot(Guid? storageKey)
  71. {
  72. #region sqlbuilder
  73. StringBuilder sqlBuilder = new StringBuilder();
  74. sqlBuilder.Append("SELECT ");
  75. foreach (KeyValuePair<String, String> pair in this.ColumnPropMaps)
  76. {
  77. sqlBuilder.AppendFormat("{0}.{1} {2},", this.TABLE_NAME, pair.Key, pair.Value);
  78. }
  79. sqlBuilder.Append("'' spiltor1,");
  80. ItemBLL bllItem = new ItemBLL();
  81. foreach (KeyValuePair<String, String> pair in bllItem.ColumnPropMaps)
  82. {
  83. sqlBuilder.AppendFormat("{0}.{1} {2},", bllItem.TABLE_NAME, pair.Key, pair.Value);
  84. }
  85. sqlBuilder.Append("'' spiltor2,");
  86. PortableStorageItemLotBLL bllLot = new PortableStorageItemLotBLL();
  87. foreach (KeyValuePair<String, String> pair in bllLot.ColumnPropMaps)
  88. {
  89. sqlBuilder.AppendFormat("{0}.{1} {2},", bllLot.TABLE_NAME, pair.Key, pair.Value);
  90. }
  91. sqlBuilder.Append("'' spiltor3,");
  92. ItemLotBLL bllIL = new ItemLotBLL();
  93. foreach (KeyValuePair<String, String> pair in bllIL.ColumnPropMaps)
  94. {
  95. sqlBuilder.AppendFormat("{0}.{1} {2},", bllIL.TABLE_NAME, pair.Key, pair.Value);
  96. }
  97. sqlBuilder.Remove(sqlBuilder.Length - 1, 1);
  98. sqlBuilder.AppendFormat(" FROM {0}"
  99. + " INNER JOIN {2} ON {0}.ITEM_KEY={2}.KEY "
  100. + " LEFT JOIN {1} ON {0}.KEY={1}.PORTABLE_ITEM_KEY"
  101. + " LEFT JOIN {3} ON {3}.KEY={1}.LOT_KEY"
  102. + " WHERE {0}.PORTABLE_STORAGE_KEY=:storageKey",
  103. this.TABLE_NAME, bllLot.TABLE_NAME, bllItem.TABLE_NAME, bllIL.TABLE_NAME);
  104. #endregion
  105. List<PortableStorageItem> listResult = new List<PortableStorageItem>();
  106. SqlMapper.Query<PortableStorageItem, Item, PortableStorageItemLot, ItemLot, PortableStorageItem>(
  107. ConnectionFactory.Current.GetSessionConnection(),
  108. sqlBuilder.ToString(),
  109. (link, i, detail, il) =>
  110. {
  111. PortableStorageItem existItem = listResult.Find(x => x.Key == link.Key);
  112. if (existItem == null)
  113. {
  114. existItem = link;
  115. existItem.Item = i;
  116. listResult.Add(link);
  117. link.ListPortableItemLots = new List<PortableStorageItemLot>();
  118. }
  119. if (detail != null)
  120. {
  121. detail.ItemLot = il;
  122. detail.Item = i;
  123. existItem.ListPortableItemLots.Add(detail);
  124. }
  125. return link;
  126. },
  127. new { storageKey = storageKey.GetValueOrDefault() },
  128. splitOn: "spiltor1,spiltor2,spiltor3");
  129. return listResult;
  130. }
  131. /// <summary>
  132. /// 根据指定的药箱状态获取药箱药品配置
  133. /// </summary>
  134. public IEnumerable<PortableStorageItem> ListPortableStorageItemsByStorage(StorageSpace storage)
  135. {
  136. #region sqlbuilder
  137. StringBuilder sqlBuilder = new StringBuilder();
  138. sqlBuilder.Append("SELECT ");
  139. foreach (KeyValuePair<String, String> pair in this.ColumnPropMaps)
  140. {
  141. sqlBuilder.AppendFormat("psi.{0} {1},", pair.Key, pair.Value);
  142. }
  143. sqlBuilder.Append("'' spiltor1,");
  144. ItemBLL bllItem = new ItemBLL();
  145. foreach (KeyValuePair<String, String> pair in bllItem.ColumnPropMaps)
  146. {
  147. sqlBuilder.AppendFormat("i.{0} {1},", pair.Key, pair.Value);
  148. }
  149. sqlBuilder.Append("'' spiltor2,");
  150. StorageSpacePortableLinkBLL storageSpacePortableLinkBll = new StorageSpacePortableLinkBLL();
  151. foreach (KeyValuePair<String, String> pair in storageSpacePortableLinkBll.ColumnPropMaps)
  152. {
  153. sqlBuilder.AppendFormat("l.{0} {1},", pair.Key, pair.Value);
  154. }
  155. sqlBuilder.Remove(sqlBuilder.Length - 1, 1);
  156. sqlBuilder.AppendFormat(" FROM {0} psi"
  157. + " INNER JOIN {1} i ON psi.ITEM_KEY=i.KEY "
  158. + " INNER JOIN portable_storage ps ON ps.key=psi.portable_storage_key"
  159. + " INNER JOIN storage_space_portable_link l ON l.portable_storage_key=ps.key",
  160. this.TABLE_NAME, bllItem.TABLE_NAME);
  161. sqlBuilder.Append(" WHERE l.STORAGE_SPACE_KEY=:storageKey");
  162. #endregion
  163. return SqlMapper.Query<PortableStorageItem, Item, StorageSpacePortableLink, PortableStorageItem>(
  164. ConnectionFactory.Current.GetSessionConnection(),
  165. sqlBuilder.ToString(),
  166. (psi, i, link) =>
  167. {
  168. psi.Item = i;
  169. psi.StoragePortableLinkInfo = link;
  170. return psi;
  171. },
  172. new { storageKey = storage.Key.GetValueOrDefault() },
  173. splitOn: "spiltor1,spiltor2");
  174. }
  175. /// <summary>
  176. /// 根据指定的药箱状态获取药箱药品配置
  177. /// </summary>
  178. public IEnumerable<PortableStorageItem> ListPortableStorageItemsByPortableState(String state)
  179. {
  180. #region sqlbuilder
  181. StringBuilder sqlBuilder = new StringBuilder();
  182. sqlBuilder.Append("SELECT ");
  183. foreach (KeyValuePair<String, String> pair in this.ColumnPropMaps)
  184. {
  185. sqlBuilder.AppendFormat("psi.{0} {1},", pair.Key, pair.Value);
  186. }
  187. sqlBuilder.Append("'' spiltor1,");
  188. ItemBLL bllItem = new ItemBLL();
  189. foreach (KeyValuePair<String, String> pair in bllItem.ColumnPropMaps)
  190. {
  191. sqlBuilder.AppendFormat("i.{0} {1},", pair.Key, pair.Value);
  192. }
  193. sqlBuilder.Append("'' spiltor2,");
  194. StorageSpacePortableLinkBLL storageSpacePortableLinkBll = new StorageSpacePortableLinkBLL();
  195. foreach (KeyValuePair<String, String> pair in storageSpacePortableLinkBll.ColumnPropMaps)
  196. {
  197. sqlBuilder.AppendFormat("l.{0} {1},", pair.Key, pair.Value);
  198. }
  199. sqlBuilder.Remove(sqlBuilder.Length - 1, 1);
  200. sqlBuilder.AppendFormat(" FROM {0} psi"
  201. + " INNER JOIN {1} i ON psi.ITEM_KEY=i.KEY "
  202. + " INNER JOIN portable_storage ps ON ps.key=psi.portable_storage_key"
  203. + " INNER JOIN storage_space_portable_link l ON l.portable_storage_key=ps.key",
  204. this.TABLE_NAME, bllItem.TABLE_NAME);
  205. if (!String.IsNullOrEmpty(state))
  206. {
  207. sqlBuilder.Append(" WHERE l.ext01=:linkState");
  208. }
  209. #endregion
  210. return SqlMapper.Query<PortableStorageItem, Item, StorageSpacePortableLink, PortableStorageItem>(
  211. ConnectionFactory.Current.GetSessionConnection(),
  212. sqlBuilder.ToString(),
  213. (psi, i, link) =>
  214. {
  215. psi.Item = i;
  216. psi.StoragePortableLinkInfo = link;
  217. return psi;
  218. },
  219. new { linkState = state },
  220. splitOn: "spiltor1,spiltor2");
  221. }
  222. public IEnumerable<PortableStorageItem> ListPortableStorageItemStatistics(DispensingDevice device)
  223. {
  224. StringBuilder sqlBuilder = new StringBuilder();
  225. sqlBuilder.Append("SELECT SUM(psi.max_quantity) MaxQuantity,SUM(psi.current_quantity) CurrentQuantity,"
  226. + " '' spiltor,i.item_common_name ItemCommonName,i.standard Standard,i.use_unit UseUnit,i.manufactory Manufactory,i.pin_yin_name PinYinName"
  227. + " FROM portable_storage_item psi"
  228. + " INNER JOIN item i ON i.key = psi.item_key "
  229. + " INNER JOIN storage_space_portable_link l ON l.portable_storage_key = psi.portable_storage_key"
  230. + " INNER JOIN storage_space s ON s.key = l.storage_space_key ");
  231. if (device != null)
  232. {
  233. sqlBuilder.Append(" WHERE s.device_key=:deviceKey");
  234. }
  235. sqlBuilder.Append(" GROUP BY i.item_common_name, i.standard, i.use_unit, i.manufactory,i.pin_yin_name");
  236. return SqlMapper.Query<PortableStorageItem, Item, PortableStorageItem>(ConnectionFactory.Current.GetSessionConnection(),
  237. sqlBuilder.ToString(),
  238. (psi, i) =>
  239. {
  240. psi.Item = i;
  241. return psi;
  242. },
  243. new { deviceKey = device == null ? default(Guid) : device.Key },
  244. splitOn: "spiltor");
  245. }
  246. public PortableStorageItem GetByStorageAndItem(Guid portableStorageKey, Guid itemKey)
  247. {
  248. return SqlMapper.Query<PortableStorageItem>(
  249. ConnectionFactory.Current.GetSessionConnection(),
  250. BuildBaseSql() + " WHERE PORTABLE_STORAGE_KEY=:storageKey AND ITEM_KEY=:itemKey",
  251. new
  252. {
  253. storageKey = portableStorageKey,
  254. itemKey = itemKey,
  255. }).FirstOrDefault();
  256. }
  257. public PortableStorageItem GetByStorageAndItem(String storageCode, Guid itemKey)
  258. {
  259. SqlBuilder sqlBuilder = new SqlBuilder(this);
  260. StorageSpacePortableLinkBLL storageSpacePortableLinkBLL = new StorageSpacePortableLinkBLL();
  261. TableJoinInfo ssplTable = new TableJoinInfo
  262. {
  263. LeftDal = this,
  264. LeftColumnName = "portable_storage_key",
  265. RightDal = storageSpacePortableLinkBLL,
  266. RightColumnName = "portable_storage_key",
  267. JoinType = TableJoinTypes.Inner,
  268. DonotMapFlag = true,
  269. };
  270. sqlBuilder.AppendSelectionTable(ssplTable);
  271. StorageSpaceBLL storageSpaceBLL = new StorageSpaceBLL();
  272. TableJoinInfo storageTable = new TableJoinInfo
  273. {
  274. LeftDal = storageSpacePortableLinkBLL,
  275. LeftColumnName = "storage_space_key",
  276. RightDal = storageSpaceBLL,
  277. RightColumnName = "key",
  278. JoinType = TableJoinTypes.Inner,
  279. DonotMapFlag = true,
  280. };
  281. sqlBuilder.AppendSelectionTable(storageTable);
  282. sqlBuilder.AppendWherePhrases($"{storageSpaceBLL.AliasTableName}.ext02=:storageCode AND {this.AliasTableName}.ITEM_KEY=:itemKey");
  283. return SqlMapper.Query<PortableStorageItem>(
  284. ConnectionFactory.Current.GetSessionConnection(),
  285. sqlBuilder.ToString(),
  286. new
  287. {
  288. storageCode = storageCode,
  289. itemKey = itemKey,
  290. }).FirstOrDefault();
  291. }
  292. }
  293. }