diff --git a/admin/app/controllers/settings/costcenter/costcenter.controller.js b/admin/app/controllers/settings/costcenter/costcenter.controller.js index 3dac6dae..3610e611 100644 --- a/admin/app/controllers/settings/costcenter/costcenter.controller.js +++ b/admin/app/controllers/settings/costcenter/costcenter.controller.js @@ -1,7 +1,14 @@ 'use strict'; -app.controller('CostCenterController', function($scope, $translate,$uibModal, CostCenterService,toaster,SweetAlert) { - +app.controller('CostCenterController', function( + $scope, + $window, + $translate, + $uibModal, + CostCenterService, + toaster, + SweetAlert) { + $scope.cur_user = JSON.parse($window.localStorage.getItem("myems_admin_ui_current_user")); $scope.getAllCostCenters = function() { CostCenterService.getAllCostCenters(function (response) { if (angular.isDefined(response.status) && response.status === 200) { @@ -19,7 +26,8 @@ app.controller('CostCenterController', function($scope, $translate,$uibModal, Co windowClass: "animated fadeIn", }); modalInstance.result.then(function(costcenter) { - CostCenterService.addCostCenter(costcenter, function (response) { + let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }; + CostCenterService.addCostCenter(costcenter, headers, function (response) { if (angular.isDefined(response.status) && response.status === 201) { toaster.pop({ type: "success", @@ -59,7 +67,8 @@ app.controller('CostCenterController', function($scope, $translate,$uibModal, Co }); modalInstance.result.then(function (modifiedCostCenter) { - CostCenterService.editCostCenter(modifiedCostCenter, function (response){ + let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }; + CostCenterService.editCostCenter(modifiedCostCenter, headers, function (response){ if(angular.isDefined(response.status) && response.status === 200){ toaster.pop({ type: "success", @@ -96,7 +105,8 @@ app.controller('CostCenterController', function($scope, $translate,$uibModal, Co closeOnCancel: true }, function (isConfirm) { if (isConfirm) { - CostCenterService.deleteCostCenter(costcenter, function (response) { + let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }; + CostCenterService.deleteCostCenter(costcenter, headers, function (response) { if (angular.isDefined(response.status) && response.status === 204) { toaster.pop({ type: "success", diff --git a/admin/app/controllers/settings/costcenter/costcentertariff.controller.js b/admin/app/controllers/settings/costcenter/costcentertariff.controller.js index 242a58f8..67efe1b8 100644 --- a/admin/app/controllers/settings/costcenter/costcentertariff.controller.js +++ b/admin/app/controllers/settings/costcenter/costcentertariff.controller.js @@ -1,11 +1,14 @@ 'use strict'; -app.controller('CostCenterTariffController', function ($scope, $translate, - CostCenterService, - TariffService, - CostCenterTariffService, - toaster) { - +app.controller('CostCenterTariffController', function ( + $scope, + $window, + $translate, + CostCenterService, + TariffService, + CostCenterTariffService, + toaster) { + $scope.cur_user = JSON.parse($window.localStorage.getItem("myems_admin_ui_current_user")); $scope.getAllCostCenters = function () { CostCenterService.getAllCostCenters(function (response) { if (angular.isDefined(response.status) && response.status === 200) { @@ -51,7 +54,8 @@ app.controller('CostCenterTariffController', function ($scope, $translate, $scope.pairTariff = function (dragEl, dropEl) { var tariffid = angular.element('#' + dragEl).scope().tariff.id; var costcenterid = $scope.currentCostCenter.id; - CostCenterTariffService.addPair(costcenterid, tariffid, function (response) { + let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }; + CostCenterTariffService.addPair(costcenterid, tariffid, headers, function (response) { if (angular.isDefined(response.status) && response.status === 201) { toaster.pop({ type: "success", @@ -77,7 +81,8 @@ app.controller('CostCenterTariffController', function ($scope, $translate, } var costcentertariffid = angular.element('#' + dragEl).scope().costcentertariff.id; var costcenterid = $scope.currentCostCenter.id; - CostCenterTariffService.deletePair(costcenterid, costcentertariffid, function (response) { + let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }; + CostCenterTariffService.deletePair(costcenterid, costcentertariffid, headers, function (response) { if (angular.isDefined(response.status) && response.status === 204) { toaster.pop({ type: "success", diff --git a/admin/app/controllers/settings/tariff/flat.controller.js b/admin/app/controllers/settings/tariff/flat.controller.js deleted file mode 100644 index edfe3e16..00000000 --- a/admin/app/controllers/settings/tariff/flat.controller.js +++ /dev/null @@ -1,158 +0,0 @@ -'use strict'; - -app.controller('FlatController', function($scope,$uibModal,$translate, FlatService,toaster,SweetAlert) { - - - $scope.getAllFlats = function() { - FlatService.getAllFlats(function (response) { - if (angular.isDefined(response.status) && response.status === 200) { - $scope.flats = response.data; - } else { - $scope.flats = []; - } - }); - - }; - - $scope.addFlat = function() { - var modalInstance = $uibModal.open({ - templateUrl: 'views/settings/tariff/flat.model.html', - controller: 'ModalAddFlatCtrl', - windowClass: "animated fadeIn", - resolve: { - params:function(){ - return { - flats:angular.copy($scope.flats) - }; - } - } - }); - modalInstance.result.then(function(flat) { - FlatService.addFlat(flat, function(response) { - if (angular.isDefined(response.status) && response.status === 201) { - toaster.pop({ - type: "success", - title: $translate.instant("TOASTER.SUCCESS_TITLE"), - body: $translate.instant("TOASTER.SUCCESS_ADD_BODY", {template: $translate.instant("TOASTER.FLAT")}), - showCloseButton: true, - }); - $scope.getAllFlats(); - } else { - toaster.pop({ - type: "error", - title: $translate.instant("TOASTER.ERROR_ADD_BODY", {template: $translate.instant("TOASTER.FLAT")}), - body: $translate.instant(response.data.description), - showCloseButton: true, - }); - } - }); - }, function() { - - }); - }; - - $scope.editFlat=function(flat){ - var modalInstance = $uibModal.open({ - windowClass: "animated fadeIn", - templateUrl: 'views/settings/tariff/flat.model.html', - controller: 'ModalEditFlatCtrl', - resolve: { - params:function(){ - return { - flat:angular.copy(flat), - flats:angular.copy($scope.flats) - }; - } - } - }); - - modalInstance.result.then(function (modifiedFlat) { - FlatService.editFlat(modifiedFlat, function (response) { - if(angular.isDefined(response.status) && response.status === 200){ - toaster.pop({ - type: "success", - title: $translate.instant("TOASTER.SUCCESS_TITLE"), - body: $translate.instant("TOASTER.SUCCESS_UPDATE_BODY", {template: $translate.instant("TOASTER.FLAT")}), - showCloseButton: true, - }); - $scope.getAllFlats(); - }else{ - toaster.pop({ - type: "error", - title: $translate.instant("TOASTER.ERROR_UPDATE_BODY", {template: $translate.instant("TOASTER.FLAT")}), - body: $translate.instant(response.data.description), - showCloseButton: true, - }); - } - }); - }, function () { - //do nothing; - }); - }; - - $scope.deleteFlat=function(flat){ - SweetAlert.swal({ - title: $translate.instant("SWEET.TITLE"), - text: $translate.instant("SWEET.TEXT"), - type: "warning", - showCancelButton: true, - confirmButtonColor: "#DD6B55", - confirmButtonText: $translate.instant("SWEET.CONFIRM_BUTTON_TEXT"), - cancelButtonText: $translate.instant("SWEET.CANCEL_BUTTON_TEXT"), - closeOnConfirm: true, - closeOnCancel: true }, - function (isConfirm) { - if (isConfirm) { - FlatService.deleteFlat(flat, function (response) { - if (angular.isDefined(response.status) && response.status === 204) { - toaster.pop({ - type: "success", - title: $translate.instant("TOASTER.SUCCESS_TITLE"), - body: $translate.instant("TOASTER.SUCCESS_DELETE_BODY", {template: $translate.instant("TOASTER.FLAT")}), - showCloseButton: true, - }); - $scope.getAllFlats(); - } else { - toaster.pop({ - type: "error", - title: $translate.instant("TOASTER.ERROR_DELETE_BODY", {template: $translate.instant("TOASTER.FLAT")}), - body: $translate.instant(response.data.description), - showCloseButton: true, - }); - } - }); - } - }); - }; - - $scope.getAllFlats(); - - -}); - -app.controller('ModalAddFlatCtrl', function ($scope, $uibModalInstance,params) { - - $scope.operation="添加"; - $scope.flats=params.flats; - $scope.ok = function () { - $uibModalInstance.close($scope.flat); - }; - - $scope.cancel = function () { - $uibModalInstance.dismiss('cancel'); - }; -}); - -app.controller('ModalEditFlatCtrl', function ($scope, $uibModalInstance, params) { - $scope.operation="编辑"; - $scope.flat = params.flat; - $scope.flats=params.flats; - - $scope.ok = function () { - $uibModalInstance.close($scope.flat); - }; - - $scope.cancel = function () { - $uibModalInstance.dismiss('cancel'); - }; -}); \ No newline at end of file diff --git a/admin/app/controllers/settings/tariff/tariff.controller.js b/admin/app/controllers/settings/tariff/tariff.controller.js index 2b43c4f5..88ecd84c 100644 --- a/admin/app/controllers/settings/tariff/tariff.controller.js +++ b/admin/app/controllers/settings/tariff/tariff.controller.js @@ -1,7 +1,17 @@ 'use strict'; -app.controller('TariffController', function($scope,$uibModal,$translate, TARIFF_TYPE, PEAK_TYPE, TariffService, CategoryService, toaster, SweetAlert) { - +app.controller('TariffController', function( + $scope, + $window, + $uibModal, + $translate, + TARIFF_TYPE, + PEAK_TYPE, + TariffService, + CategoryService, + toaster, + SweetAlert) { + $scope.cur_user = JSON.parse($window.localStorage.getItem("myems_admin_ui_current_user")); $scope.getAllCategories = function() { CategoryService.getAllCategories(function (response) { if (angular.isDefined(response.status) && response.status === 200) { @@ -42,7 +52,8 @@ app.controller('TariffController', function($scope,$uibModal,$translate, TARIFF_ } }); modalInstance.result.then(function(tariff) { - TariffService.addTariff(tariff, function (response) { + let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }; + TariffService.addTariff(tariff, headers, function (response) { if (angular.isDefined(response.status) && response.status === 201) { toaster.pop({ type: "success", @@ -82,7 +93,8 @@ app.controller('TariffController', function($scope,$uibModal,$translate, TARIFF_ }); modalInstance.result.then(function(modifiedTariff) { - TariffService.editTariff(modifiedTariff, function (response) { + let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }; + TariffService.editTariff(modifiedTariff, headers, function (response) { if (angular.isDefined(response.status) && response.status === 200) { toaster.pop({ type: "success", @@ -119,7 +131,8 @@ app.controller('TariffController', function($scope,$uibModal,$translate, TARIFF_ }, function(isConfirm) { if (isConfirm) { - TariffService.deleteTariff(tariff, function (response) { + let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token }; + TariffService.deleteTariff(tariff, headers, function (response) { if (angular.isDefined(response.status) && response.status === 204) { toaster.pop({ type: "success", diff --git a/admin/app/services/settings/costcenter/costcenter.service.js b/admin/app/services/settings/costcenter/costcenter.service.js index 6adc79cf..fc307150 100644 --- a/admin/app/services/settings/costcenter/costcenter.service.js +++ b/admin/app/services/settings/costcenter/costcenter.service.js @@ -17,24 +17,24 @@ app.factory('CostCenterService', function($http) { callback(response); }); }, - addCostCenter: function(costcenter, callback) { - $http.post(getAPI()+'costcenters',{data:costcenter}) + addCostCenter: function(costcenter, headers, callback) { + $http.post(getAPI()+'costcenters',{data:costcenter}, {headers}) .then(function (response) { callback(response); }, function (response) { callback(response); }); }, - editCostCenter: function(costcenter, callback) { - $http.put(getAPI()+'costcenters/'+costcenter.id,{data:costcenter}) + editCostCenter: function(costcenter, headers, callback) { + $http.put(getAPI()+'costcenters/'+costcenter.id,{data:costcenter}, {headers}) .then(function (response) { callback(response); }, function (response) { callback(response); }); }, - deleteCostCenter: function(costcenter, callback) { - $http.delete(getAPI()+'costcenters/'+costcenter.id) + deleteCostCenter: function(costcenter, headers, callback) { + $http.delete(getAPI()+'costcenters/'+costcenter.id, {headers}) .then(function (response) { callback(response); }, function (response) { diff --git a/admin/app/services/settings/costcenter/costcentertariff.service.js b/admin/app/services/settings/costcenter/costcentertariff.service.js index 532af9f5..7c121a01 100644 --- a/admin/app/services/settings/costcenter/costcentertariff.service.js +++ b/admin/app/services/settings/costcenter/costcentertariff.service.js @@ -1,8 +1,8 @@ 'use strict'; app.factory('CostCenterTariffService', function($http) { return { - addPair: function(costcenterid,tariffid,callback) { - $http.post(getAPI()+'costcenters/'+costcenterid+'/tariffs',{data:{'tariff_id':tariffid}}) + addPair: function(costcenterid, tariffid, headers, callback ) { + $http.post(getAPI()+'costcenters/'+costcenterid+'/tariffs',{data:{'tariff_id':tariffid}}, {headers}) .then(function (response) { callback(response); }, function (response) { @@ -10,8 +10,8 @@ app.factory('CostCenterTariffService', function($http) { }); }, - deletePair: function(costcenterid,tariffid, callback) { - $http.delete(getAPI()+'costcenters/'+costcenterid+'/tariffs/'+tariffid) + deletePair: function(costcenterid, tariffid, headers, callback) { + $http.delete(getAPI()+'costcenters/'+costcenterid+'/tariffs/'+tariffid, {headers}) .then(function (response) { callback(response); }, function (response) { @@ -19,7 +19,7 @@ app.factory('CostCenterTariffService', function($http) { }); }, getTariffsByCostCenterID: function(id, callback) { - $http.get(getAPI()+'costcenters/'+id+'/tariffs') + $http.get(getAPI()+'costcenters/'+id+'/tariffs') .then(function (response) { callback(response); }, function (response) { diff --git a/admin/app/services/settings/tariff/flat.service.js b/admin/app/services/settings/tariff/flat.service.js deleted file mode 100644 index a853302c..00000000 --- a/admin/app/services/settings/tariff/flat.service.js +++ /dev/null @@ -1,53 +0,0 @@ -'use strict'; -app.factory('FlatService', function($http) { - return { - getAllFlats:function(callback){ - $http.get(getAPI()+'flats') - .then(function (response) { - callback(response); - }, function (response) { - callback(response); - }); - }, - searchFlats: function(query, callback) { - $http.get(getAPI()+'flats', { params: { q: query } }) - .then(function (response) { - callback(response); - }, function (response) { - callback(response); - }); - }, - addFlat: function(flat, callback) { - $http.post(getAPI()+'flats',{data:flat}) - .then(function (response) { - callback(response); - }, function (response) { - callback(response); - }); - }, - editFlat: function(flat, callback) { - $http.put(getAPI()+'flats/'+flat.id,{data:flat}) - .then(function (response) { - callback(response); - }, function (response) { - callback(response); - }); - }, - deleteFlat: function(flat, callback) { - $http.delete(getAPI()+'flats/'+flat.id) - .then(function (response) { - callback(response); - }, function (response) { - callback(response); - }); - }, - getFlat: function(id, callback) { - $http.get(getAPI()+'flats/'+id) - .then(function (response) { - callback(response); - }, function (response) { - callback(response); - }); - } - }; -}); \ No newline at end of file diff --git a/admin/app/services/settings/tariff/tariff.service.js b/admin/app/services/settings/tariff/tariff.service.js index ca4be90f..0848f124 100644 --- a/admin/app/services/settings/tariff/tariff.service.js +++ b/admin/app/services/settings/tariff/tariff.service.js @@ -17,24 +17,24 @@ app.factory('TariffService', function($http) { callback(response); }); }, - addTariff: function(tariff, callback) { - $http.post(getAPI()+'tariffs',{data:tariff}) + addTariff: function(tariff, headers, callback) { + $http.post(getAPI()+'tariffs',{data:tariff}, {headers}) .then(function (response) { callback(response); }, function (response) { callback(response); }); }, - editTariff: function(tariff, callback) { - $http.put(getAPI()+'tariffs/'+tariff.id,{data:tariff}) + editTariff: function(tariff, headers, callback) { + $http.put(getAPI()+'tariffs/'+tariff.id,{data:tariff}, {headers}) .then(function (response) { callback(response); }, function (response) { callback(response); }); }, - deleteTariff: function(tariff, callback) { - $http.delete(getAPI()+'tariffs/'+tariff.id) + deleteTariff: function(tariff, headers, callback) { + $http.delete(getAPI()+'tariffs/'+tariff.id, {headers}) .then(function (response) { callback(response); }, function (response) { diff --git a/admin/views/settings/tariff/flat.model.html b/admin/views/settings/tariff/flat.model.html deleted file mode 100644 index 987ab7da..00000000 --- a/admin/views/settings/tariff/flat.model.html +++ /dev/null @@ -1,19 +0,0 @@ -
- - - -
diff --git a/myems-api/MyEMS.postman_collection.json b/myems-api/MyEMS.postman_collection.json index ed679a2f..07e24531 100644 --- a/myems-api/MyEMS.postman_collection.json +++ b/myems-api/MyEMS.postman_collection.json @@ -1017,7 +1017,18 @@ "name": "POST Creat a Cost Center", "request": { "method": "POST", - "header": [], + "header": [ + { + "key": "User-UUID", + "value": "dcdb67d1-6116-4987-916f-6fc6cf2bc0e4", + "type": "text" + }, + { + "key": "Token", + "value": "dca233ce58b2bf881e862e994f392dd27dd286c6135eff14da111137023b6c5625864300b269048036dcec310d4f61fa89021e5a3462512de2852493227187a0", + "type": "text" + } + ], "body": { "mode": "raw", "raw": "{\"data\":{\"name\":\"动力中心\", \"external_id\":\"21829198980001\"}}" @@ -1038,7 +1049,18 @@ "name": "PUT Update a Cost Center", "request": { "method": "PUT", - "header": [], + "header": [ + { + "key": "User-UUID", + "value": "dcdb67d1-6116-4987-916f-6fc6cf2bc0e4", + "type": "text" + }, + { + "key": "Token", + "value": "dca233ce58b2bf881e862e994f392dd27dd286c6135eff14da111137023b6c5625864300b269048036dcec310d4f61fa89021e5a3462512de2852493227187a0", + "type": "text" + } + ], "body": { "mode": "raw", "raw": "{\"data\":{\"name\":\"动力中心2\", \"external_id\":\"21829198980002\"}}" @@ -1060,28 +1082,50 @@ "name": "DELETE a Cost Center by ID", "request": { "method": "DELETE", - "header": [], + "header": [ + { + "key": "User-UUID", + "value": "dcdb67d1-6116-4987-916f-6fc6cf2bc0e4", + "type": "text" + }, + { + "key": "Token", + "value": "dca233ce58b2bf881e862e994f392dd27dd286c6135eff14da111137023b6c5625864300b269048036dcec310d4f61fa89021e5a3462512de2852493227187a0", + "type": "text" + } + ], "url": { - "raw": "{{base_url}}/costcenters/2", + "raw": "{{base_url}}/costcenters/3", "host": [ "{{base_url}}" ], "path": [ "costcenters", - "2" + "3" ] } }, "response": [] }, { - "name": "POST a Cost Center and Tariff Relation", + "name": "POST Bind Tariff to Cost Center", "request": { "method": "POST", - "header": [], + "header": [ + { + "key": "User-UUID", + "value": "dcdb67d1-6116-4987-916f-6fc6cf2bc0e4", + "type": "text" + }, + { + "key": "Token", + "value": "dca233ce58b2bf881e862e994f392dd27dd286c6135eff14da111137023b6c5625864300b269048036dcec310d4f61fa89021e5a3462512de2852493227187a0", + "type": "text" + } + ], "body": { "mode": "raw", - "raw": "{\"data\":{\"tariff_id\":\"1\"}}" + "raw": "{\"data\":{\"tariff_id\":\"3\"}}" }, "url": { "raw": "{{base_url}}/costcenters/1/tariffs", @@ -1103,16 +1147,35 @@ "method": "GET", "header": [], "url": { - "raw": "" + "raw": "{{base_url}}/costcenters/1/tariffs", + "host": [ + "{{base_url}}" + ], + "path": [ + "costcenters", + "1", + "tariffs" + ] } }, "response": [] }, { - "name": "DELETE a Cost Center and Tariff Relation", + "name": "DELETE Unbind Tariff from Cost Center", "request": { "method": "DELETE", - "header": [], + "header": [ + { + "key": "User-UUID", + "value": "dcdb67d1-6116-4987-916f-6fc6cf2bc0e4", + "type": "text" + }, + { + "key": "Token", + "value": "dca233ce58b2bf881e862e994f392dd27dd286c6135eff14da111137023b6c5625864300b269048036dcec310d4f61fa89021e5a3462512de2852493227187a0", + "type": "text" + } + ], "url": { "raw": "{{base_url}}/costcenters/1/tariffs/3", "host": [ @@ -7475,10 +7538,21 @@ "response": [] }, { - "name": "POST Create a Tariff (block)", + "name": "POST Create a Tariff (Tiered)", "request": { "method": "POST", - "header": [], + "header": [ + { + "key": "User-UUID", + "value": "dcdb67d1-6116-4987-916f-6fc6cf2bc0e4", + "type": "text" + }, + { + "key": "Token", + "value": "dca233ce58b2bf881e862e994f392dd27dd286c6135eff14da111137023b6c5625864300b269048036dcec310d4f61fa89021e5a3462512de2852493227187a0", + "type": "text" + } + ], "body": { "mode": "raw", "raw": "{\"data\":{\"name\":\"new阶梯电价\",\"energy_category\":{\"id\":1}, \"tariff_type\":\"block\", \"unit_of_price\":\"元/千瓦时\", \"valid_from\":\"2020-01-01T00:00:00\", \"valid_through\":\"2021-01-01T00:00:00\", \"block\":[{\"start_amount\":\"0\", \"end_amount\":\"10000\", \"price\":\"0.567\"}, {\"start_amount\":\"10000\", \"end_amount\":\"30000\", \"price\":\"0.678\"}, {\"start_amount\":\"30000\", \"end_amount\":\"100000\", \"price\":\"0.789\"}]}}" @@ -7514,32 +7588,54 @@ "response": [] }, { - "name": "PUT Update a Tariff (block)", + "name": "PUT Update a Tariff (Tiered)", "request": { "method": "PUT", - "header": [], + "header": [ + { + "key": "User-UUID", + "value": "dcdb67d1-6116-4987-916f-6fc6cf2bc0e4", + "type": "text" + }, + { + "key": "Token", + "value": "dca233ce58b2bf881e862e994f392dd27dd286c6135eff14da111137023b6c5625864300b269048036dcec310d4f61fa89021e5a3462512de2852493227187a0", + "type": "text" + } + ], "body": { "mode": "raw", "raw": "{\"data\":{\"name\":\"new阶梯电价\",\"energy_category\":{\"id\":1}, \"tariff_type\":\"block\", \"unit_of_price\":\"元/千瓦时\", \"valid_from\":\"2020-01-01T00:00:00\", \"valid_through\":\"2021-01-01T00:00:00\", \"block\":[{\"start_amount\":\"0\", \"end_amount\":\"20000\", \"price\":\"0.567\"}, {\"start_amount\":\"20000\", \"end_amount\":\"30000\", \"price\":\"0.678\"}, {\"start_amount\":\"30000\", \"end_amount\":\"100000\", \"price\":\"0.789\"}]}}" }, "url": { - "raw": "{{base_url}}/tariffs/18", + "raw": "{{base_url}}/tariffs/17", "host": [ "{{base_url}}" ], "path": [ "tariffs", - "18" + "17" ] } }, "response": [] }, { - "name": "POST Create a Tariff (time of use)", + "name": "POST Create a Tariff (Time of Use)", "request": { "method": "POST", - "header": [], + "header": [ + { + "key": "User-UUID", + "value": "dcdb67d1-6116-4987-916f-6fc6cf2bc0e4", + "type": "text" + }, + { + "key": "Token", + "value": "dca233ce58b2bf881e862e994f392dd27dd286c6135eff14da111137023b6c5625864300b269048036dcec310d4f61fa89021e5a3462512de2852493227187a0", + "type": "text" + } + ], "body": { "mode": "raw", "raw": "{\"data\":{\"name\":\"new2020分时电价1-6\",\"energy_category\":{\"id\":1}, \"tariff_type\":\"timeofuse\", \"unit_of_price\":\"元/千瓦时\", \"valid_from\":\"2020-01-01T00:00:00\", \"valid_through\":\"2020-07-01T00:00:00\", \"timeofuse\":[{\"start_time_of_day\":\"00:00:00\", \"end_time_of_day\":\"05:59:59\", \"peak_type\":\"offpeak\", \"price\":0.345}, {\"start_time_of_day\":\"06:00:00\", \"end_time_of_day\":\"07:59:59\", \"peak_type\":\"midpeak\", \"price\":0.708}, {\"start_time_of_day\":\"08:00:00\", \"end_time_of_day\":\"10:59:59\", \"peak_type\":\"onpeak\", \"price\":1.159}, {\"start_time_of_day\":\"11:00:00\", \"end_time_of_day\":\"17:59:59\", \"peak_type\":\"midpeak\", \"price\":0.708}, {\"start_time_of_day\":\"18:00:00\", \"end_time_of_day\":\"20:59:59\", \"peak_type\":\"onpeak\", \"price\":1.159}, {\"start_time_of_day\":\"21:00:00\", \"end_time_of_day\":\"21:59:59\", \"peak_type\":\"midpeak\", \"price\":0.708}, {\"start_time_of_day\":\"22:00:00\", \"end_time_of_day\":\"23:59:59\", \"peak_type\":\"offpeak\", \"price\":0.345}]}}" @@ -7560,19 +7656,30 @@ "name": "PUT Update a Tariff (time of use)", "request": { "method": "PUT", - "header": [], + "header": [ + { + "key": "User-UUID", + "value": "dcdb67d1-6116-4987-916f-6fc6cf2bc0e4", + "type": "text" + }, + { + "key": "Token", + "value": "dca233ce58b2bf881e862e994f392dd27dd286c6135eff14da111137023b6c5625864300b269048036dcec310d4f61fa89021e5a3462512de2852493227187a0", + "type": "text" + } + ], "body": { "mode": "raw", "raw": "{\"data\":{\"name\":\"new2020分时电价1-6\",\"energy_category\":{\"id\":1}, \"tariff_type\":\"timeofuse\", \"unit_of_price\":\"元/千瓦时\", \"valid_from\":\"2020-01-01T00:00:00\", \"valid_through\":\"2020-07-01T00:00:00\", \"timeofuse\":[{\"start_time_of_day\":\"00:00:00\", \"end_time_of_day\":\"05:59:59\", \"peak_type\":\"offpeak\", \"price\":0.456}, {\"start_time_of_day\":\"06:00:00\", \"end_time_of_day\":\"07:59:59\", \"peak_type\":\"midpeak\", \"price\":0.708}, {\"start_time_of_day\":\"08:00:00\", \"end_time_of_day\":\"10:59:59\", \"peak_type\":\"onpeak\", \"price\":1.159}, {\"start_time_of_day\":\"11:00:00\", \"end_time_of_day\":\"17:59:59\", \"peak_type\":\"midpeak\", \"price\":0.708}, {\"start_time_of_day\":\"18:00:00\", \"end_time_of_day\":\"20:59:59\", \"peak_type\":\"onpeak\", \"price\":1.159}, {\"start_time_of_day\":\"21:00:00\", \"end_time_of_day\":\"21:59:59\", \"peak_type\":\"midpeak\", \"price\":0.708}, {\"start_time_of_day\":\"22:00:00\", \"end_time_of_day\":\"23:59:59\", \"peak_type\":\"offpeak\", \"price\":0.345}]}}" }, "url": { - "raw": "{{base_url}}/tariffs/19", + "raw": "{{base_url}}/tariffs/18", "host": [ "{{base_url}}" ], "path": [ "tariffs", - "19" + "18" ] } }, @@ -7582,15 +7689,26 @@ "name": "DELETE a Tariff", "request": { "method": "DELETE", - "header": [], + "header": [ + { + "key": "User-UUID", + "value": "dcdb67d1-6116-4987-916f-6fc6cf2bc0e4", + "type": "text" + }, + { + "key": "Token", + "value": "dca233ce58b2bf881e862e994f392dd27dd286c6135eff14da111137023b6c5625864300b269048036dcec310d4f61fa89021e5a3462512de2852493227187a0", + "type": "text" + } + ], "url": { - "raw": "{{base_url}}/tariffs/16", + "raw": "{{base_url}}/tariffs/18", "host": [ "{{base_url}}" ], "path": [ "tariffs", - "16" + "18" ] } }, diff --git a/myems-api/README.md b/myems-api/README.md index 2904679d..dfe26621 100644 --- a/myems-api/README.md +++ b/myems-api/README.md @@ -343,20 +343,20 @@ Result * GET All Cost Files ```bash -curl -i -X GET {{base_url}}/costfiles +curl -i -H "User-UUID: dcdb67d1-6116-4987-916f-6fc6cf2bc0e4" -H "Token: GET-TOKEN-AFTER-LOGIN" -X GET {{base_url}}/costfiles ``` * DELETE a Cost File by ID ```bash -curl -i -X DELETE {{base_url}}/costfiles/{id} +curl -i -H "User-UUID: dcdb67d1-6116-4987-916f-6fc6cf2bc0e4" -H "Token: GET-TOKEN-AFTER-LOGIN" -X DELETE {{base_url}}/costfiles/{id} ``` * POST Upload a Cost File (call users login API to get 'User-UUID' and 'Token') ```bash -curl -i -H "User-UUID: dcdb67d1-6116-4987-916f-6fc6cf2bc0e4" -H "Token: GET-TOKEN-AFTER-LOGIN" -H "Content-Type: application/TBD" -X POST -d 'file: (binary)' {{base_url}}/costfiles +curl -i -H "User-UUID: dcdb67d1-6116-4987-916f-6fc6cf2bc0e4" -H "Token: GET-TOKEN-AFTER-LOGIN" -H "Content-Type: application/TBD" -X POST -d 'file: (binary)' {{base_url}}/costfiles ``` * GET Restore a Cost File by ID from database to disk ```bash -curl -i -X GET {{base_url}}/costfiles/{id}/restore +curl -i -H "User-UUID: dcdb67d1-6116-4987-916f-6fc6cf2bc0e4" -H "Token: GET-TOKEN-AFTER-LOGIN" -X GET {{base_url}}/costfiles/{id}/restore ``` ### Data Source diff --git a/myems-api/core/costcenter.py b/myems-api/core/costcenter.py index 78b24a13..84ab1a29 100644 --- a/myems-api/core/costcenter.py +++ b/myems-api/core/costcenter.py @@ -18,6 +18,7 @@ class CostCenterCollection: @staticmethod def on_get(req, resp): + """Handles GET requests""" cnx = mysql.connector.connect(**config.myems_system_db) cursor = cnx.cursor() @@ -41,6 +42,7 @@ class CostCenterCollection: @user_logger def on_post(req, resp): """Handles POST requests""" + access_control(req) try: raw_json = req.stream.read().decode('utf-8') @@ -110,6 +112,7 @@ class CostCenterItem: @staticmethod def on_get(req, resp, id_): + """Handles GET requests""" if not id_.isdigit() or int(id_) <= 0: raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_COST_CENTER_ID') @@ -135,6 +138,8 @@ class CostCenterItem: @staticmethod @user_logger def on_delete(req, resp, id_): + """Handles DELETE requests""" + access_control(req) if not id_.isdigit() or int(id_) <= 0: raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_COST_CENTER_ID') @@ -282,6 +287,7 @@ class CostCenterItem: @user_logger def on_put(req, resp, id_): """Handles PUT requests""" + access_control(req) try: raw_json = req.stream.read().decode('utf-8') except Exception as ex: @@ -376,6 +382,7 @@ class CostCenterTariffCollection: @staticmethod def on_get(req, resp, id_): + """Handles GET requests""" if not id_.isdigit() or int(id_) <= 0: raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_COST_CENTER_ID') @@ -410,6 +417,7 @@ class CostCenterTariffCollection: @user_logger def on_post(req, resp, id_): """Handles POST requests""" + access_control(req) try: raw_json = req.stream.read().decode('utf-8') except Exception as ex: @@ -478,6 +486,8 @@ class CostCenterTariffItem: @staticmethod @user_logger def on_delete(req, resp, id_, tid): + """Handles DELETE requests""" + access_control(req) if not id_.isdigit() or int(id_) <= 0: raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_COST_CENTER_ID') diff --git a/myems-api/core/costfile.py b/myems-api/core/costfile.py index 5ec2852b..b96d87d2 100644 --- a/myems-api/core/costfile.py +++ b/myems-api/core/costfile.py @@ -20,6 +20,7 @@ class CostFileCollection: @staticmethod def on_get(req, resp): + """Handles GET requests""" access_control(req) cnx = mysql.connector.connect(**config.myems_historical_db) cursor = cnx.cursor() @@ -159,6 +160,7 @@ class CostFileItem: @staticmethod def on_get(req, resp, id_): + """Handles GET requests""" access_control(req) if not id_.isdigit() or int(id_) <= 0: raise falcon.HTTPError(falcon.HTTP_400, @@ -194,6 +196,7 @@ class CostFileItem: @staticmethod @user_logger def on_delete(req, resp, id_): + """Handles DELETE requests""" access_control(req) if not id_.isdigit() or int(id_) <= 0: raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', @@ -245,6 +248,7 @@ class CostFileRestore: @staticmethod def on_get(req, resp, id_): + """Handles GET requests""" access_control(req) if not id_.isdigit() or int(id_) <= 0: raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', diff --git a/myems-api/core/tariff.py b/myems-api/core/tariff.py index b24b4080..ac852ac3 100644 --- a/myems-api/core/tariff.py +++ b/myems-api/core/tariff.py @@ -101,6 +101,7 @@ class TariffCollection: @user_logger def on_post(req, resp): """Handles POST requests""" + access_control(req) try: raw_json = req.stream.read().decode('utf-8') except Exception as ex: @@ -232,6 +233,7 @@ class TariffItem: @staticmethod def on_get(req, resp, id_): + """Handles GET requests""" if not id_.isdigit() or int(id_) <= 0: raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_TARIFF_ID') @@ -311,6 +313,8 @@ class TariffItem: @staticmethod @user_logger def on_delete(req, resp, id_): + """Handles DELETE requests""" + access_control(req) if not id_.isdigit() or int(id_) <= 0: raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', description='API.INVALID_TARIFF_ID') @@ -369,6 +373,7 @@ class TariffItem: @user_logger def on_put(req, resp, id_): """Handles PUT requests""" + access_control(req) try: raw_json = req.stream.read().decode('utf-8') except Exception as ex: