Ver Fonte

統購:追加設定各校授權名額架構

jeff há 1 ano atrás
pai
commit
dd787bde44

+ 8 - 3
TEAMModelBI/ClientApp/src/api/index.js

@@ -611,12 +611,17 @@ export default {
     pushNotify(data) {
     pushNotify(data) {
         return post('/coupon/push-notify',data)
         return post('/coupon/push-notify',data)
     },
     },
-    //統購平台 - 縣市名額設定
-    setPurchaseSeats(data) {
-        return post('https://bb-rc.teammodel.net/bbauthapi/set-purchase-seats', data)
+    //統購平台 - 縣市名額設定 ※目前只開放GL站 
+    setPurchaseSeats(data, testflg=false) {
+        let Domain = (testflg) ? 'bb-rc.teammodel.net' : 'bb.teammodel.net';
+        return post(`https://${Domain}/bbauthapi/set-purchase-seats`, data)
     },
     },
     //統購平台 - 取得統購平台列表
     //統購平台 - 取得統購平台列表
     getBBPurchase(data) {
     getBBPurchase(data) {
         return post('/schoolcheck/get-bbpurchase',data)
         return post('/schoolcheck/get-bbpurchase',data)
     },
     },
+    //統購平台 - 取得縣市學校
+    getCsSchoolByGeo(data) {
+        return post('/schoolcheck/get-school-geo', data)
+    },
 }
 }

+ 6 - 0
TEAMModelBI/ClientApp/src/language/lang/zh-cn.js

@@ -603,6 +603,12 @@ const zh_cn = {
         },
         },
         parameterError: '参数错误',
         parameterError: '参数错误',
     },
     },
+    purchase: {
+        purchasePlatform: '统购平台',
+        productManagement: '县市产品名额',
+        prodSeatsInfo: '产品及名额资讯',
+        addNew: '新增',
+    },
     auth:{
     auth:{
         YMPCVCIM: '学情分析模组',
         YMPCVCIM: '学情分析模组',
         IPDYZYLC: '智慧学校管理服务',
         IPDYZYLC: '智慧学校管理服务',

+ 6 - 0
TEAMModelBI/ClientApp/src/language/lang/zh-tw.js

@@ -599,6 +599,12 @@ const zh_tw = {
         },
         },
         parameterError: '參數錯誤',
         parameterError: '參數錯誤',
     },
     },
+    purchase: {
+        purchasePlatform: '統購平台',
+        productManagement: '縣市產品名額',
+        prodSeatsInfo: '產品及名額資訊',
+        addNew: '新增',
+    },
     auth:{
     auth:{
         YMPCVCIM: '學情分析模組',
         YMPCVCIM: '學情分析模組',
         IPDYZYLC: '智慧學校管理服務',
         IPDYZYLC: '智慧學校管理服務',

Diff do ficheiro suprimidas por serem muito extensas
+ 182 - 77
TEAMModelBI/ClientApp/src/view/htcommunity/adminpanel.vue


+ 2 - 2
TEAMModelBI/ClientApp/src/view/product/index.vue

@@ -466,8 +466,8 @@ let columns = ref([
 ])
 ])
 const popoverRef = ref()
 const popoverRef = ref()
 const siteValue = window.location.host === 'localhost:5001' ? 'cn' : window.location.host === 'bi.teammodel.cn' ? 'cn' : window.location.host === 'bitest.teammodel.cn' ? 'cn' : 'international'
 const siteValue = window.location.host === 'localhost:5001' ? 'cn' : window.location.host === 'bi.teammodel.cn' ? 'cn' : window.location.host === 'bitest.teammodel.cn' ? 'cn' : 'international'
-//const optionsData = siteValue === 'cn' ? option_cn : option_gl
-const optionsData = option_gl
+const optionsData = siteValue === 'cn' ? option_cn : option_gl
+//const optionsData = option_gl
 columns.value[0].headerCellRenderer = (props = HeaderCellSlotProps) => {
 columns.value[0].headerCellRenderer = (props = HeaderCellSlotProps) => {
       return (
       return (
         <div class="items-center justify-center">
         <div class="items-center justify-center">

+ 63 - 53
TEAMModelBI/Controllers/BISchool/SchoolController.cs

@@ -2619,73 +2619,83 @@ namespace TEAMModelBI.Controllers.BISchool
             List<object> result = new List<object>();
             List<object> result = new List<object>();
             try
             try
             {
             {
-                //var cosmosClientCsv2 = _azureCosmos.GetCosmosClient(name: "CoreServiceV2"); //CosmosDB CSV2
-                //var storageClientCsv2 = _azureStorage.GetCloudTableClient(name: "CoreServiceV2"); //Storage CSV2
-
-                ////取得TMID基本資料
-                //Dictionary<string, TmidStics> tmidDic = new();
-                //QueryDefinition query =
-                //       new QueryDefinition(@"SELECT c.id, c.name, c.picture, c.mobile, c.mail, c.lang, c.wechat, c.facebook, c.google, c.ding, c.apple, c.educloudtw, c.ts FROM c WHERE (ARRAY_CONTAINS(@key, c.id) OR ARRAY_CONTAINS(@key, c.mobile))")
-                //       .WithParameter("@key", tmids);
-                //await foreach (var item in cosmosClientCsv2
-                //            .GetContainer("Core", "ID2")
-                //            .GetItemQueryStreamIterator(query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("base") }))
-                //{                   
-                //}
-
-                string sql = $"SELECT * FROM c WHERE c.dataType = 'purchase' ";
-
-                var client = _azureCosmos.GetCosmosClient(name: "CoreServiceV2");
-
+                var client = _azureCosmos.GetCosmosClient("CoreServiceV2");
+                string sqlPurchase = $"SELECT * FROM c ";
                 List<PurchaseSeats> purchaseSeatsList = new List<PurchaseSeats>();
                 List<PurchaseSeats> purchaseSeatsList = new List<PurchaseSeats>();
-
-                //await foreach (var item in client.GetContainer("Core", "ID2").GetItemQueryStreamIterator(queryText: sql))
-                //{
-                //    var jsoncs = await JsonDocument.ParseAsync(item.ContentStream);
-                //    if (jsoncs.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
-                //    {
-                //        foreach (var obj in jsoncs.RootElement.GetProperty("Documents").EnumerateArray())
-                //        {
-
-                //        }
-                //    }
-                //}
-                //await foreach (var item in client.GetContainer("Core", "ID2").GetItemQueryIterator<PurchaseSeats>(queryText: sql))
-                await foreach (var item in client.GetContainer("Habb", "Auth").GetItemQueryIterator<PurchaseSeats>(queryText: sql))
+                await foreach (PurchaseSeats item in client.GetContainer("Habb", "Auth").GetItemQueryIterator<PurchaseSeats>(queryText: sqlPurchase, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("purchase") }))
                 {
                 {
                     purchaseSeatsList.Add(item);
                     purchaseSeatsList.Add(item);
                 }
                 }
+                Dictionary<string, List<PurchaseSchoolSeats>> purchaseSchoolSeatsDic = new Dictionary<string, List<PurchaseSchoolSeats>>();
+                string sqlSchool = $"SELECT * FROM c ";
+                await foreach (PurchaseSchoolSeats item in client.GetContainer("Habb", "Auth").GetItemQueryIterator<PurchaseSchoolSeats>(queryText: sqlSchool, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("purchaseSchool") }))
+                {
+                    if(!purchaseSchoolSeatsDic.ContainsKey(item.purchaseId))
+                    {
+                        purchaseSchoolSeatsDic.Add(item.purchaseId, new List<PurchaseSchoolSeats>() { item });
+                    }
+                    else
+                    {
+                        purchaseSchoolSeatsDic[item.purchaseId].Add(item);
+                    }
+                }
 
 
-
-
-                return Ok(purchaseSeatsList);
+                return Ok(new { geo = purchaseSeatsList, school = purchaseSchoolSeatsDic });
             }
             }
             catch (Exception ex)
             catch (Exception ex)
             {
             {
                 return BadRequest();
                 return BadRequest();
             }
             }
         }
         }
-
         /// <summary>
         /// <summary>
-        /// 統購授權 縣市名額
+        /// 取得CoreService縣市所屬學校
         /// </summary>
         /// </summary>
-        public class PurchaseSeats
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        [HttpPost("get-school-geo")]
+        public async Task<IActionResult> GetCsSchoolByGeo(JsonElement jsonElement)
         {
         {
-            public string id { get; set; } //統購縣市名額ID 格式:{countryId}-{provinceId}-{cityId}-{districtId}-{產品代碼}
-            public string countryId { get; set; } //[String]國家代碼
-            public string provinceId { get; set; } //[String]省代碼
-            public string cityId { get; set; } //[String]市代碼
-            public string districtId { get; set; } //[String]區代碼
-            public string geoName { get; set; } //行政區名稱
-            public string prodCode { get; set; } //產品代碼
-            public long startDate { get; set; } //授權起始日期 unixtimestamp
-            public long endDate { get; set; } //授權終止日期 unixtimestamp
-            public int seats { get; set; } //名額數
-            public int number { get; set; } //產品數量、空間數
-            public int used { get; set; } //已領用名額數
-            public object aprule { get; set; } //產品擴充項
-            public List<string> tmids { get; set; } = new(); //已申請的TMID
-            public string dataType { get; set; } //分區鍵:purchase
+            List<CsSchoolBase> result = new List<CsSchoolBase>();
+            try
+            {
+                string err = string.Empty;
+                string countryId = (jsonElement.TryGetProperty("countryId", out JsonElement _countryId)) ? _countryId.GetString() : string.Empty;
+                string provinceId = (jsonElement.TryGetProperty("provinceId", out JsonElement _provinceId)) ? _provinceId.GetString() : string.Empty;
+                string cityId = (jsonElement.TryGetProperty("cityId", out JsonElement _cityId)) ? _cityId.GetString() : string.Empty;
+                string distId = (jsonElement.TryGetProperty("distId", out JsonElement _distId)) ? _distId.GetString() : string.Empty;
+                //輸入項檢驗
+                if (string.IsNullOrWhiteSpace(countryId)) { err = "Invalid countryId."; }
+                else if(countryId.Equals("CN"))
+                {
+                    if (string.IsNullOrWhiteSpace(provinceId)) { err = "Invalid provinceId."; }
+                    else if (string.IsNullOrWhiteSpace(cityId)) { err = "Invalid cityId."; }
+                }
+                else if (countryId.Equals("TW"))
+                {
+                    if (string.IsNullOrWhiteSpace(cityId)) { err = "Invalid cityId."; }
+                }
+                if(!string.IsNullOrWhiteSpace(err)) ///錯誤訊息輸出
+                {
+                    return Ok(new { err = err, data = result });
+                }
+                //取得CS學校
+                var client = _azureCosmos.GetCosmosClient(name:"CoreServiceV2CnRead");
+                string sql = $"SELECT * FROM c WHERE c.countryId = '{countryId}'";
+                if (!string.IsNullOrWhiteSpace(provinceId)) sql += $" AND c.provinceId = '{provinceId}'";
+                if (!string.IsNullOrWhiteSpace(cityId)) sql += $" AND c.cityId = '{cityId}'";
+                if (!string.IsNullOrWhiteSpace(distId)) sql += $" AND c.distId = '{distId}'";
+                await foreach (CsSchoolBase item in client.GetContainer("Core", "School").GetItemQueryIterator<CsSchoolBase>(queryText: sql, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("base") }))
+                {
+                    result.Add(item);
+                }
+
+                return Ok(new { err = err, data = result });
+            }
+            catch (Exception ex)
+            {
+                return BadRequest();
+            }
         }
         }
 
 
         #endregion
         #endregion

+ 14 - 15
TEAMModelBI/Controllers/BITmid/TmidController.cs

@@ -748,7 +748,7 @@ namespace TEAMModelBI.Controllers.BITmid
         private async Task<object> GetTmidUseprodCore(string dateFromStr, string dateToStr, List<string> targets, bool getLoginTime)
         private async Task<object> GetTmidUseprodCore(string dateFromStr, string dateToStr, List<string> targets, bool getLoginTime)
         {
         {
             Dictionary<string, TmidStics> tmidDic = new();
             Dictionary<string, TmidStics> tmidDic = new();
-            HashSet<string> schIds = new HashSet<string>();
+            HashSet<string> schIds = new HashSet<string>(); //生成的TMID所關聯的學校ID列表
             DateTime dateFrom = DateTime.ParseExact(dateFromStr, "yyyy-MM-dd", null);
             DateTime dateFrom = DateTime.ParseExact(dateFromStr, "yyyy-MM-dd", null);
             DateTime dateTo = DateTime.ParseExact(dateToStr, "yyyy-MM-dd", null).Add(new TimeSpan(0, 23, 59, 59));
             DateTime dateTo = DateTime.ParseExact(dateToStr, "yyyy-MM-dd", null).Add(new TimeSpan(0, 23, 59, 59));
             DateTimeOffset dateTimeFrom = new DateTimeOffset(dateFrom, TimeSpan.Zero);
             DateTimeOffset dateTimeFrom = new DateTimeOffset(dateFrom, TimeSpan.Zero);
@@ -908,7 +908,7 @@ namespace TEAMModelBI.Controllers.BITmid
 
 
             //返回值整理
             //返回值整理
             List<TmidIotProdCnt> tmid = new List<TmidIotProdCnt>();
             List<TmidIotProdCnt> tmid = new List<TmidIotProdCnt>();
-            List<TmidIotProdCntGeo> sch = new List<TmidIotProdCntGeo>();
+            List<TmidIotProdCntGeo> sch = new List<TmidIotProdCntGeo>(); //取得的IOT學校統計資訊
             foreach (var item in tmidDic)
             foreach (var item in tmidDic)
             {
             {
                 //TMID
                 //TMID
@@ -1036,20 +1036,19 @@ namespace TEAMModelBI.Controllers.BITmid
                 {
                 {
                     schRow.tLesson += item.tLesson;
                     schRow.tLesson += item.tLesson;
                     schRow.tGreen += item.tGreen;
                     schRow.tGreen += item.tGreen;
+                    //地理位置IOT累加
+                    string countryId = (!string.IsNullOrWhiteSpace(schRow.countryId)) ? schRow.countryId : string.Empty;
+                    string provinceId = (!string.IsNullOrWhiteSpace(schRow.provinceId)) ? schRow.provinceId : string.Empty;
+                    string cityId = (!string.IsNullOrWhiteSpace(schRow.cityId)) ? schRow.cityId : string.Empty;
+                    string distId = (!string.IsNullOrWhiteSpace(schRow.distId)) ? schRow.distId : string.Empty;
+                    string geoid = $"{countryId}-{provinceId}-{cityId}-{distId}";
+                    var geoRow = geo.Where(s => s.id.Equals(geoid)).FirstOrDefault();
+                    if (geoRow != null)
+                    {
+                        geoRow.tLesson += item.tLesson;
+                        geoRow.tGreen += item.tGreen;
+                    }
                 }
                 }
-                //地理位置IOT累加
-                string countryId = (!string.IsNullOrWhiteSpace(schRow.countryId)) ? schRow.countryId : string.Empty;
-                string provinceId = (!string.IsNullOrWhiteSpace(schRow.provinceId)) ? schRow.provinceId : string.Empty;
-                string cityId = (!string.IsNullOrWhiteSpace(schRow.cityId)) ? schRow.cityId : string.Empty;
-                string distId = (!string.IsNullOrWhiteSpace(schRow.distId)) ? schRow.distId : string.Empty;
-                string geoid = $"{countryId}-{provinceId}-{cityId}-{distId}";
-                var geoRow = geo.Where(s => s.id.Equals(geoid)).FirstOrDefault();
-                if (geoRow != null)
-                {
-                    geoRow.tLesson += item.tLesson;
-                    geoRow.tGreen += item.tGreen;
-                }
-
             }
             }
             //總IOT累加
             //總IOT累加
             Dictionary<string, int> iotResult = new Dictionary<string, int>();
             Dictionary<string, int> iotResult = new Dictionary<string, int>();

+ 23 - 0
TEAMModelBI/Models/AssistSchool.cs

@@ -131,6 +131,29 @@ namespace TEAMModelBI.Models
     {
     {
         public string areaId { get; set; }
         public string areaId { get; set; }
     }
     }
+    //CoreService學校基本資料
+    public class CsSchoolBase
+    {
+        public string id { get; set; }
+        public string code { get; set; } //學校教育部代碼
+        public string name { get; set; }
+        public string countryId { get; set; }
+        public string countryName { get; set; }
+        public string provinceId { get; set; }
+        public string provinceName { get; set; }
+        public string cityId { get; set; }
+        public string cityName { get; set; }
+        public string distId { get; set; }
+        public string distName { get; set; }
+        public string address { get; set; }
+        public string source { get; set; }
+        public string shortCode { get; set; } //學校簡碼
+        public string lang { get; set; }
+        public string unitType { get; set; }
+        public string tel { get; set; }
+        public string type { get; set; }
+    }
+
     #region api解析
     #region api解析
     /// <summary>
     /// <summary>
     /// api解析
     /// api解析

+ 41 - 0
TEAMModelBI/Models/Purchase.cs

@@ -0,0 +1,41 @@
+using System.Collections.Generic;
+
+namespace TEAMModelBI.Models
+{
+    /// <summary>
+    /// 統購授權 縣市名額
+    /// </summary>
+    public class PurchaseSeats
+    {
+        public string id { get; set; } //統購縣市名額ID 格式:{countryId}-{provinceId}-{cityId}-{districtId}-{產品代碼}
+        public string countryId { get; set; } //[String]國家代碼
+        public string provinceId { get; set; } //[String]省代碼
+        public string cityId { get; set; } //[String]市代碼
+        public string districtId { get; set; } //[String]區代碼
+        public string geoName { get; set; } //行政區名稱
+        public string prodCode { get; set; } //產品代碼
+        public long startDate { get; set; } //授權起始日期 unixtimestamp
+        public long endDate { get; set; } //授權終止日期 unixtimestamp
+        public int seats { get; set; } //名額數
+        public int number { get; set; } //產品數量、空間數
+        public int used { get; set; } //已領用名額數 (document並無此欄位,各校名額加總累計用)
+        public object aprule { get; set; } //產品擴充項
+        public string dataType { get; set; } //分區鍵:purchase
+    }
+    /// <summary>
+    /// 統購授權 各校名額
+    /// </summary>
+    public class PurchaseSchoolSeats
+    {
+        public string schoolCode { get; set; }
+        public string shortCode { get; set; }
+        public string schoolName { get; set; }
+        public int seats { get; set; }
+        public string id { get; set; } //統購學校名額ID 格式:{countryId}-{provinceId}-{cityId}-{districtId}-{產品代碼}-{學校簡碼}
+        public string purchaseId { get; set; } //統購縣市名額ID 格式:{countryId}-{provinceId}-{cityId}-{districtId}-{產品代碼}
+        public List<string> tmids { get; set; } = new List<string>(); //已申請的TMID
+        public int used { get; set; } //已領用名額數
+        public int ttl { get; set; } = -1;
+        public string dataType { get; set; } //分區鍵:purchaseSchool
+    }
+}