|
- using DataVApi.Order;
- using DataVApi.Order.Dto;
- using DataVApi.Order.RequestModel;
- using DataVAPI.Model;
- using DataVAPI.ModelDataBus;
- using DataVAPI.ServerDB.MongoDB;
- using Microsoft.AspNetCore.Mvc;
- using NPOI.Util;
- using System.Collections.Generic;
-
- namespace DataVAPI.Controllers
- {
- /// <summary>
- /// 订单接口:统计订单或者营业额
- /// </summary>
- public class OrderController : BaseController
- {
- string st = System.Reflection.MethodBase.GetCurrentMethod().Name;
- OrderProvider orderProvider = new OrderProvider();
- MongoDbHelper<DeviceTable> mg = new MongoDbHelper<DeviceTable>(DataBus.connStr, DataBus.dbName);
- /// <summary>
- /// 全部数据
- /// </summary>
- [HttpPost]
- public JsonMsg<object> GetAllOrderDataState(FullScreenInput auth)
- {
- st = System.Reflection.MethodBase.GetCurrentMethod().Name;
- try
- {
- object retdata = orderProvider.GetAllOrderDataState(auth);
- return JsonMsg<object>.OK(retdata, st);
- }
- catch (System.Exception ex)
- {
- return JsonMsg<object>.Error(null, st, ex.Message);
- }
- }
- /// <summary>
- /// 店铺id 或者 设备id查询全部数据
- /// </summary>
- /// <param name="auth"></param>
- /// <returns></returns>
- [HttpGet]
- public JsonMsg<object> GetAllOrderDataState(int? OrgId, int? DeviceId)
- {
- st = System.Reflection.MethodBase.GetCurrentMethod().Name;
- try
- {
- FullScreenInput fullScreen = new FullScreenInput();
- if (OrgId.HasValue) fullScreen.OrgId = OrgId;
- if (DeviceId.HasValue) fullScreen.DeviceId = DeviceId;
- object retdata = orderProvider.GetAllOrderDataState(fullScreen);
- return JsonMsg<object>.OK(retdata, st);
- }
- catch (System.Exception ex)
- {
- return JsonMsg<object>.Error(null, st, ex.Message);
- }
- }
-
- /// <summary>
- /// 折线图
- /// </summary>
- [HttpPost]
- public JsonMsg<object> OrderLine(FullScreenInput auth)
- {
- st = System.Reflection.MethodBase.GetCurrentMethod().Name;
- try
- {
- object retdata = orderProvider.OrderLine(auth);
- return JsonMsg<object>.OK(retdata, st);
- }
- catch (System.Exception ex)
- {
- return JsonMsg<object>.Error(null, st, ex.Message);
- }
- }
-
- /// <summary>
- /// 折线图
- /// </summary>
- [HttpGet]
- public JsonMsg<object> OrderLine(int Count)
- {
- st = System.Reflection.MethodBase.GetCurrentMethod().Name;
- try
- {
- FullScreenBasic fullScreen = new FullScreenBasic();
- fullScreen.Count = Count;
- object retdata = orderProvider.OrderLine(fullScreen);
- return JsonMsg<object>.OK(retdata, st);
- }
- catch (System.Exception ex)
- {
- return JsonMsg<object>.Error(null, st, ex.Message);
- }
- }
-
- /// <summary>
- /// 区域销售
- /// </summary>
- [HttpPost]
- public JsonMsg<object> GetLocSale()
- {
- st = System.Reflection.MethodBase.GetCurrentMethod().Name;
- try
- {
- object retdata = orderProvider.GetLocSale();
- return JsonMsg<object>.OK(retdata, st);
- }
- catch (System.Exception ex)
- {
- return JsonMsg<object>.Error(null, st, ex.Message);
- }
- }
-
- /// <summary>
- /// 下单数量
- /// </summary>
- [HttpPost]
- public JsonMsg<object> OrderNumber(FullScreenBasic input)
- {
- st = System.Reflection.MethodBase.GetCurrentMethod().Name;
- try
- {
- object retdata = orderProvider.OrderNumber(input);
- return JsonMsg<object>.OK(retdata, st);
- }
- catch (System.Exception ex)
- {
- return JsonMsg<object>.Error(null, st, ex.Message);
- }
- }
-
- /// <summary>
- /// 下单数量
- /// </summary>
- [HttpGet]
- public JsonMsg<object> OrderNumber(int? OrgId, int? DeviceId)
- {
- st = System.Reflection.MethodBase.GetCurrentMethod().Name;
- try
- {
- FullScreenBasic fullScreen = new FullScreenBasic();
- if (OrgId.HasValue) fullScreen.OrgId = OrgId;
- if (DeviceId.HasValue) fullScreen.DeviceId = DeviceId;
- object retdata = orderProvider.OrderNumber(fullScreen);
- return JsonMsg<object>.OK(retdata, st);
- }
- catch (System.Exception ex)
- {
- return JsonMsg<object>.Error(null, st, ex.Message);
- }
- }
-
- /// <summary>
- /// 获取店铺集合
- /// </summary>
- /// <returns></returns>
- [HttpGet]
- public JsonMsg<object> StoreList()
- {
- st = System.Reflection.MethodBase.GetCurrentMethod().Name;
- try
- {
- object retdata = orderProvider.StoreList();
- return JsonMsg<object>.OK(retdata, st);
- }
- catch (System.Exception ex)
- {
- return JsonMsg<object>.Error(null, st, ex.Message);
- }
- }
-
- /// <summary>
- /// 查询组织好的店铺信息
- /// </summary>
- /// <returns></returns>
- [HttpGet]
- public JsonMsg<object> StoreListIOT()
- {
- st = System.Reflection.MethodBase.GetCurrentMethod().Name;
- try
- {
-
- List<DeviceTable> _dev = mg.QueryAllTime(null, null, System.DateTime.MinValue, System.DateTime.MinValue);
- Dictionary<int, List<StoreListDto>> retdata = orderProvider.StoreList();
- List<object> list = new List<object>();
-
- foreach (var item in retdata)
- {
- int i = 0;
- string namesy = string.Empty;
- string devid = string.Empty;
- string devname = string.Empty;
-
- int ClientId = item.Key;
- List<object> aly_data = new List<object>();
- if (retdata.ContainsKey(ClientId))//查询店铺下面所有设备集合
- {
- List<DeviceTable> devices = _dev?.FindAll(par => par.ClientId == ClientId.ToString());
- item.Value?.ForEach(p =>
- {
- #region 查询设备阿里云连接
- DeviceTable dev = devices?.Find(x =>
- {
- List<string> retudata = new List<string>();
- if (x.DeviceId != null)
- {
-
- string[] vs;
- if (x.DeviceId.Contains(" ")) vs = x.DeviceId.Split(" ");
- else if (x.DeviceId.Contains(",")) vs = x.DeviceId.Split(",");
- else { vs = new string[1]; vs[0] = x.DeviceId; }
- retudata = Arrays.AsList(vs);
- }
- if (retudata == null || retudata.Count <= 0 || !retudata.Contains(p.DeviceID.ToString()))
- return false;
- else
- return true;
- });
- #endregion
- if (i == 0) {
- devid = p.DeviceID.ToString();
- devname=p.DeviceName.ToString();
- namesy = dev != null ? dev.devicename : "空";
- i++;
- }
- aly_data.Add( new
- {
- ClientId = p.ClientId.ToString(),
- ClientName = p.ClientName,
- DeviceID = p.DeviceID.ToString(),
- DeviceName = p.DeviceName,
- DeviceTypeKey = p.DeviceTypeKey,
- AlyName = dev != null ? dev.devicename : "空",
- });
- });
- }
- object _data = new
- {
- Name = item.Value?[0]?.ClientName,
- ClientId = item.Value?[0]?.ClientId.ToString(),
- DeviceList= aly_data,
- FirstName = namesy,
- FirstDeviceID= devid,
- FirstDeviceName= devname
- };
- list.Add(_data);
- }
- return JsonMsg<object>.OK(list, st);
- }
- catch (System.Exception ex)
- {
- return JsonMsg<object>.Error(null, st, ex.Message);
- }
- }
-
- /// <summary>
- /// 根据客户端ID查询设备信息
- /// </summary>
- /// <returns></returns>
- [HttpGet]
- public JsonMsg<List<object>> StoreListClientId(int ClientId)
- {
- st = System.Reflection.MethodBase.GetCurrentMethod().Name;
- try
- {
- List<DeviceTable> _dev = mg.QueryAllTime(null, null, System.DateTime.MinValue, System.DateTime.MinValue);
- Dictionary<int, List<StoreListDto>> retdata = orderProvider.StoreList();
-
- List<object> list = new List<object>();
- if (retdata.ContainsKey(ClientId))
- {
- List<DeviceTable> devices= _dev?.FindAll(par => par.ClientId == ClientId.ToString());
- List<StoreListDto> listdto = retdata[ClientId];
- listdto?.ForEach(p =>
- {
- DeviceTable dev= devices?.Find(x =>
- {
- List<string> retudata = new List<string>();
- if (x.DeviceId != null)
- {
-
- string[] vs;
- if (x.DeviceId.Contains(" ")) vs = x.DeviceId.Split(" ");
- else if (x.DeviceId.Contains(",")) vs = x.DeviceId.Split(",");
- else { vs = new string[1];vs[0]= x.DeviceId ; }
- retudata =Arrays.AsList(vs);
- }
- if (retudata == null || retudata.Count <= 0 || !retudata.Contains(p.DeviceID.ToString()))
- return false;
- else
- return true;
- });
- object obj = new
- {
- ClientId= p.ClientId.ToString(),
- ClientName= p.ClientName,
- DeviceID= p.DeviceID.ToString(),
- DeviceName= p.DeviceName,
- DeviceTypeKey = p.DeviceTypeKey,
- AlyName= dev!=null?dev.devicename: "空",
- };
- list.Add(obj);
- });
- }
- return JsonMsg<List<object>>.OK(list, st);
- }
- catch (System.Exception ex)
- {
- return JsonMsg<List<object>>.Error(null, st, ex.Message);
- }
- }
- }
- }
|