Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 

317 linhas
12 KiB

  1. using DataVApi.Order;
  2. using DataVApi.Order.Dto;
  3. using DataVApi.Order.RequestModel;
  4. using DataVAPI.Model;
  5. using DataVAPI.ModelDataBus;
  6. using DataVAPI.ServerDB.MongoDB;
  7. using Microsoft.AspNetCore.Mvc;
  8. using NPOI.Util;
  9. using System.Collections.Generic;
  10. namespace DataVAPI.Controllers
  11. {
  12. /// <summary>
  13. /// 订单接口:统计订单或者营业额
  14. /// </summary>
  15. public class OrderController : BaseController
  16. {
  17. string st = System.Reflection.MethodBase.GetCurrentMethod().Name;
  18. OrderProvider orderProvider = new OrderProvider();
  19. MongoDbHelper<DeviceTable> mg = new MongoDbHelper<DeviceTable>(DataBus.connStr, DataBus.dbName);
  20. /// <summary>
  21. /// 全部数据
  22. /// </summary>
  23. [HttpPost]
  24. public JsonMsg<object> GetAllOrderDataState(FullScreenInput auth)
  25. {
  26. st = System.Reflection.MethodBase.GetCurrentMethod().Name;
  27. try
  28. {
  29. object retdata = orderProvider.GetAllOrderDataState(auth);
  30. return JsonMsg<object>.OK(retdata, st);
  31. }
  32. catch (System.Exception ex)
  33. {
  34. return JsonMsg<object>.Error(null, st, ex.Message);
  35. }
  36. }
  37. /// <summary>
  38. /// 店铺id 或者 设备id查询全部数据
  39. /// </summary>
  40. /// <param name="auth"></param>
  41. /// <returns></returns>
  42. [HttpGet]
  43. public JsonMsg<object> GetAllOrderDataState(int? OrgId, int? DeviceId)
  44. {
  45. st = System.Reflection.MethodBase.GetCurrentMethod().Name;
  46. try
  47. {
  48. FullScreenInput fullScreen = new FullScreenInput();
  49. if (OrgId.HasValue) fullScreen.OrgId = OrgId;
  50. if (DeviceId.HasValue) fullScreen.DeviceId = DeviceId;
  51. object retdata = orderProvider.GetAllOrderDataState(fullScreen);
  52. return JsonMsg<object>.OK(retdata, st);
  53. }
  54. catch (System.Exception ex)
  55. {
  56. return JsonMsg<object>.Error(null, st, ex.Message);
  57. }
  58. }
  59. /// <summary>
  60. /// 折线图
  61. /// </summary>
  62. [HttpPost]
  63. public JsonMsg<object> OrderLine(FullScreenInput auth)
  64. {
  65. st = System.Reflection.MethodBase.GetCurrentMethod().Name;
  66. try
  67. {
  68. object retdata = orderProvider.OrderLine(auth);
  69. return JsonMsg<object>.OK(retdata, st);
  70. }
  71. catch (System.Exception ex)
  72. {
  73. return JsonMsg<object>.Error(null, st, ex.Message);
  74. }
  75. }
  76. /// <summary>
  77. /// 折线图
  78. /// </summary>
  79. [HttpGet]
  80. public JsonMsg<object> OrderLine(int Count)
  81. {
  82. st = System.Reflection.MethodBase.GetCurrentMethod().Name;
  83. try
  84. {
  85. FullScreenBasic fullScreen = new FullScreenBasic();
  86. fullScreen.Count = Count;
  87. object retdata = orderProvider.OrderLine(fullScreen);
  88. return JsonMsg<object>.OK(retdata, st);
  89. }
  90. catch (System.Exception ex)
  91. {
  92. return JsonMsg<object>.Error(null, st, ex.Message);
  93. }
  94. }
  95. /// <summary>
  96. /// 区域销售
  97. /// </summary>
  98. [HttpPost]
  99. public JsonMsg<object> GetLocSale()
  100. {
  101. st = System.Reflection.MethodBase.GetCurrentMethod().Name;
  102. try
  103. {
  104. object retdata = orderProvider.GetLocSale();
  105. return JsonMsg<object>.OK(retdata, st);
  106. }
  107. catch (System.Exception ex)
  108. {
  109. return JsonMsg<object>.Error(null, st, ex.Message);
  110. }
  111. }
  112. /// <summary>
  113. /// 下单数量
  114. /// </summary>
  115. [HttpPost]
  116. public JsonMsg<object> OrderNumber(FullScreenBasic input)
  117. {
  118. st = System.Reflection.MethodBase.GetCurrentMethod().Name;
  119. try
  120. {
  121. object retdata = orderProvider.OrderNumber(input);
  122. return JsonMsg<object>.OK(retdata, st);
  123. }
  124. catch (System.Exception ex)
  125. {
  126. return JsonMsg<object>.Error(null, st, ex.Message);
  127. }
  128. }
  129. /// <summary>
  130. /// 下单数量
  131. /// </summary>
  132. [HttpGet]
  133. public JsonMsg<object> OrderNumber(int? OrgId, int? DeviceId)
  134. {
  135. st = System.Reflection.MethodBase.GetCurrentMethod().Name;
  136. try
  137. {
  138. FullScreenBasic fullScreen = new FullScreenBasic();
  139. if (OrgId.HasValue) fullScreen.OrgId = OrgId;
  140. if (DeviceId.HasValue) fullScreen.DeviceId = DeviceId;
  141. object retdata = orderProvider.OrderNumber(fullScreen);
  142. return JsonMsg<object>.OK(retdata, st);
  143. }
  144. catch (System.Exception ex)
  145. {
  146. return JsonMsg<object>.Error(null, st, ex.Message);
  147. }
  148. }
  149. /// <summary>
  150. /// 获取店铺集合
  151. /// </summary>
  152. /// <returns></returns>
  153. [HttpGet]
  154. public JsonMsg<object> StoreList()
  155. {
  156. st = System.Reflection.MethodBase.GetCurrentMethod().Name;
  157. try
  158. {
  159. object retdata = orderProvider.StoreList();
  160. return JsonMsg<object>.OK(retdata, st);
  161. }
  162. catch (System.Exception ex)
  163. {
  164. return JsonMsg<object>.Error(null, st, ex.Message);
  165. }
  166. }
  167. /// <summary>
  168. /// 查询组织好的店铺信息
  169. /// </summary>
  170. /// <returns></returns>
  171. [HttpGet]
  172. public JsonMsg<object> StoreListIOT()
  173. {
  174. st = System.Reflection.MethodBase.GetCurrentMethod().Name;
  175. try
  176. {
  177. List<DeviceTable> _dev = mg.QueryAllTime(null, null, System.DateTime.MinValue, System.DateTime.MinValue);
  178. Dictionary<int, List<StoreListDto>> retdata = orderProvider.StoreList();
  179. List<object> list = new List<object>();
  180. foreach (var item in retdata)
  181. {
  182. int i = 0;
  183. string namesy = string.Empty;
  184. string devid = string.Empty;
  185. string devname = string.Empty;
  186. int ClientId = item.Key;
  187. List<object> aly_data = new List<object>();
  188. if (retdata.ContainsKey(ClientId))//查询店铺下面所有设备集合
  189. {
  190. List<DeviceTable> devices = _dev?.FindAll(par => par.ClientId == ClientId.ToString());
  191. item.Value?.ForEach(p =>
  192. {
  193. #region 查询设备阿里云连接
  194. DeviceTable dev = devices?.Find(x =>
  195. {
  196. List<string> retudata = new List<string>();
  197. if (x.DeviceId != null)
  198. {
  199. string[] vs;
  200. if (x.DeviceId.Contains(" ")) vs = x.DeviceId.Split(" ");
  201. else if (x.DeviceId.Contains(",")) vs = x.DeviceId.Split(",");
  202. else { vs = new string[1]; vs[0] = x.DeviceId; }
  203. retudata = Arrays.AsList(vs);
  204. }
  205. if (retudata == null || retudata.Count <= 0 || !retudata.Contains(p.DeviceID.ToString()))
  206. return false;
  207. else
  208. return true;
  209. });
  210. #endregion
  211. if (i == 0) {
  212. devid = p.DeviceID.ToString();
  213. devname=p.DeviceName.ToString();
  214. namesy = dev != null ? dev.devicename : "空";
  215. i++;
  216. }
  217. aly_data.Add( new
  218. {
  219. ClientId = p.ClientId.ToString(),
  220. ClientName = p.ClientName,
  221. DeviceID = p.DeviceID.ToString(),
  222. DeviceName = p.DeviceName,
  223. DeviceTypeKey = p.DeviceTypeKey,
  224. AlyName = dev != null ? dev.devicename : "空",
  225. });
  226. });
  227. }
  228. object _data = new
  229. {
  230. Name = item.Value?[0]?.ClientName,
  231. ClientId = item.Value?[0]?.ClientId.ToString(),
  232. DeviceList= aly_data,
  233. FirstName = namesy,
  234. FirstDeviceID= devid,
  235. FirstDeviceName= devname
  236. };
  237. list.Add(_data);
  238. }
  239. return JsonMsg<object>.OK(list, st);
  240. }
  241. catch (System.Exception ex)
  242. {
  243. return JsonMsg<object>.Error(null, st, ex.Message);
  244. }
  245. }
  246. /// <summary>
  247. /// 根据客户端ID查询设备信息
  248. /// </summary>
  249. /// <returns></returns>
  250. [HttpGet]
  251. public JsonMsg<List<object>> StoreListClientId(int ClientId)
  252. {
  253. st = System.Reflection.MethodBase.GetCurrentMethod().Name;
  254. try
  255. {
  256. List<DeviceTable> _dev = mg.QueryAllTime(null, null, System.DateTime.MinValue, System.DateTime.MinValue);
  257. Dictionary<int, List<StoreListDto>> retdata = orderProvider.StoreList();
  258. List<object> list = new List<object>();
  259. if (retdata.ContainsKey(ClientId))
  260. {
  261. List<DeviceTable> devices= _dev?.FindAll(par => par.ClientId == ClientId.ToString());
  262. List<StoreListDto> listdto = retdata[ClientId];
  263. listdto?.ForEach(p =>
  264. {
  265. DeviceTable dev= devices?.Find(x =>
  266. {
  267. List<string> retudata = new List<string>();
  268. if (x.DeviceId != null)
  269. {
  270. string[] vs;
  271. if (x.DeviceId.Contains(" ")) vs = x.DeviceId.Split(" ");
  272. else if (x.DeviceId.Contains(",")) vs = x.DeviceId.Split(",");
  273. else { vs = new string[1];vs[0]= x.DeviceId ; }
  274. retudata =Arrays.AsList(vs);
  275. }
  276. if (retudata == null || retudata.Count <= 0 || !retudata.Contains(p.DeviceID.ToString()))
  277. return false;
  278. else
  279. return true;
  280. });
  281. object obj = new
  282. {
  283. ClientId= p.ClientId.ToString(),
  284. ClientName= p.ClientName,
  285. DeviceID= p.DeviceID.ToString(),
  286. DeviceName= p.DeviceName,
  287. DeviceTypeKey = p.DeviceTypeKey,
  288. AlyName= dev!=null?dev.devicename: "空",
  289. };
  290. list.Add(obj);
  291. });
  292. }
  293. return JsonMsg<List<object>>.OK(list, st);
  294. }
  295. catch (System.Exception ex)
  296. {
  297. return JsonMsg<List<object>>.Error(null, st, ex.Message);
  298. }
  299. }
  300. }
  301. }