Commit 1af4c042 authored by neo's avatar neo

[DEV] add async js control for gen report data

parent d9b57f27
...@@ -48,8 +48,14 @@ ...@@ -48,8 +48,14 @@
generate: function (projectId, templateId, ifDeleteManualDataSource, period, generator) { generate: function (projectId, templateId, ifDeleteManualDataSource, period, generator) {
return $http.post('/Report/generate/' + projectId + '/' + templateId + '/' + ifDeleteManualDataSource + '/' + period + '?generator=' + generator, {}, apiConfig.createVat({ignoreLoadingBar: true})); return $http.post('/Report/generate/' + projectId + '/' + templateId + '/' + ifDeleteManualDataSource + '/' + period + '?generator=' + generator, {}, apiConfig.createVat({ignoreLoadingBar: true}));
}, },
generateAll: function (projectId, ifDeleteManualDataSource, period, generator) { generateAll: function (projectId, isMergeManualDataSource, period, generator) {
return $http.post('/Report/generateByTotal/' + projectId + '/' + ifDeleteManualDataSource + '/' + period + '?generator=' + generator , {}, apiConfig.createVat({ignoreLoadingBar: true})); return $http.post('/Report/generateByTotal/' + projectId + '/' + isMergeManualDataSource + '/' + period + '?generator=' + generator , {}, apiConfig.createVat({ignoreLoadingBar: true}));
},
getRunningJob: function (projectId, period) {
return $http.get('/Report/getRunningJob/' + projectId+'/'+period, apiConfig.createVat());
},
getJobStatus: function (projectId, period, jobId) {
return $http.get('/Report/getJobStatus/' + projectId+'/'+period+'/'+jobId, apiConfig.createVat());
}, },
getReportData: function (reportId) { getReportData: function (reportId) {
return $http.get('/Report/reportData/' + reportId, apiConfig.createVat()); return $http.get('/Report/reportData/' + reportId, apiConfig.createVat());
......
vatModule.controller('vatCaculateDataController', ['$scope', '$log', '$timeout', '$q', '$translate', 'loginContext', vatModule.controller('vatCaculateDataController', ['$scope', '$log', '$timeout','$interval', '$q', '$translate', 'loginContext',
'apiInterceptor', 'Upload', 'dataImportService', 'SweetAlert', 'vatReductionService', 'vatSessionService', 'uiGridConstants', 'apiInterceptor', 'Upload', 'dataImportService', 'SweetAlert', 'vatReductionService', 'vatSessionService', 'uiGridConstants',
'enums', 'modelConfigurationService', 'vatReportService', 'vatCommonService', 'BSPLService', 'vatOperationLogService', 'enums', 'modelConfigurationService', 'vatReportService', 'vatCommonService', 'BSPLService', 'vatOperationLogService',
'vatWorkflowService', 'vatWorkflowService',
function ($scope, $log, $timeout, $q, $translate, loginContext, apiInterceptor, Upload, dataImportService, SweetAlert, function ($scope, $log, $timeout, $interval, $q, $translate, loginContext, apiInterceptor, Upload, dataImportService, SweetAlert,
vatReductionService, vatSessionService, uiGridConstants, enums, modelConfigurationService, vatReportService, vatCommonService vatReductionService, vatSessionService, uiGridConstants, enums, modelConfigurationService, vatReportService, vatCommonService
, BSPLService, vatOperationLogService, vatWorkflowService) { , BSPLService, vatOperationLogService, vatWorkflowService) {
'use strict'; 'use strict';
...@@ -11,17 +11,16 @@ ...@@ -11,17 +11,16 @@
var taskList = []; var taskList = [];
var fixedRef = []; var fixedRef = [];
$scope.period = vatSessionService.month; $scope.period = vatSessionService.month;
$scope.isMergeManualDataSource = false;
$scope.moduleid = enums.vatModuleEnum.Import_CalculateData; $scope.moduleid = enums.vatModuleEnum.Import_CalculateData;
var initTasks = function () { var initTasks = function () {
var task = function (id, status, name) { var task = function (id, status, name,code) {
this.id = id; this.id = id;
this.name = _.isEmpty(name) ? $translate.instant(id) : name; this.name = _.isEmpty(name) ? $translate.instant(id) : name;
this.status = status; this.status = status;
this.text = $translate.instant(status); this.text = $translate.instant(status);
this.code = code;
}; };
task.prototype.doTask = function () { task.prototype.doTask = function () {
var _this = this; var _this = this;
...@@ -118,12 +117,12 @@ ...@@ -118,12 +117,12 @@
//}, function () { //}, function () {
// taskError(_this); // taskError(_this);
//}); // //});
vatReportService.updateConfig(vatSessionService.project.id, true, vatSessionService.month, // vatReportService.updateConfig(vatSessionService.project.id, true, vatSessionService.month,
vatSessionService.logUser.id ? vatSessionService.logUser.id : "", // vatSessionService.logUser.id ? vatSessionService.logUser.id : "",
$scope.isMergeManualDataSource ).success(function (data) { // $scope.isMergeManualDataSource ).success(function (data) {
var data = {result: true}; // var data = {result: true};
updateProgress(data, _this); // updateProgress(data, _this);
//vatReportService.getTemplateReferences(vatSessionService.month).then(function (refData) { //vatReportService.getTemplateReferences(vatSessionService.month).then(function (refData) {
// if (refData && refData.data) { // if (refData && refData.data) {
// // 初始化resolve列表 // // 初始化resolve列表
...@@ -143,10 +142,10 @@ ...@@ -143,10 +142,10 @@
//}).then(function () { //}).then(function () {
// updateProgress(data, _this); // updateProgress(data, _this);
//}); //});
}).error(function () { // }).error(function () {
//
taskError(_this); // taskError(_this);
}); // });
break; break;
case 'CalculateKeyValue': case 'CalculateKeyValue':
//$q.all().then(function () { //$q.all().then(function () {
...@@ -197,6 +196,7 @@ ...@@ -197,6 +196,7 @@
task.prototype.id = null; task.prototype.id = null;
task.prototype.status = null; task.prototype.status = null;
task.prototype.text = null; task.prototype.text = null;
task.prototype.code =null;
vatReportService.getTemplate(vatSessionService.project.id, constant.serviceType.VAT, vatSessionService.month).then(function (report) { vatReportService.getTemplate(vatSessionService.project.id, constant.serviceType.VAT, vatSessionService.month).then(function (report) {
var result = []; var result = [];
...@@ -212,7 +212,7 @@ ...@@ -212,7 +212,7 @@
name: $translate.instant('GenerateReport'), name: $translate.instant('GenerateReport'),
isReportTask: true, isReportTask: true,
items: _.map(report.data.data, function (x) { items: _.map(report.data.data, function (x) {
return new task(x.templateId, 'unstarted', x.templateName); return new task(x.templateId, 'unstarted', x.templateName, x.templateCode);
}) })
}); });
...@@ -240,11 +240,12 @@ ...@@ -240,11 +240,12 @@
}); });
$scope.tasks = result; $scope.tasks = result;
getInitTaskStatus();
}); });
}; };
function doStartCaculate(isMergeManualDataSource) { function doStartCaculate(isMergeManualDataSource) {
$scope.isMergeManualDataSource = isMergeManualDataSource;
$scope.readonly = true; $scope.readonly = true;
$scope.resolveRef.length = 0; $scope.resolveRef.length = 0;
$scope.resolveRef.push({ $scope.resolveRef.push({
...@@ -276,6 +277,15 @@ ...@@ -276,6 +277,15 @@
// }); // });
} }
function doStartCaculate2(isMergeManualDataSource) {
vatReportService.generateAll(vatSessionService.project.id, isMergeManualDataSource, vatSessionService.month, vatSessionService.logUser.id ? vatSessionService.logUser.id : "").success(function (data) {
if(data && data.result) {
updateTasksStatus(data.result.data);
}).error(function () {
taskError(_this);
});
}
var startCaculate = function () { var startCaculate = function () {
if (vatSessionService.project.projectStatusList[vatSessionService.month] >= constant.ProjectStatusEnum.Generated) { if (vatSessionService.project.projectStatusList[vatSessionService.month] >= constant.ProjectStatusEnum.Generated) {
swal({ swal({
...@@ -326,6 +336,57 @@ ...@@ -326,6 +336,57 @@
} }
}; };
var startCaculate2 = function () {
if (vatSessionService.project.projectStatusList[vatSessionService.month] >= constant.ProjectStatusEnum.Generated) {
swal({
title: "warning!",
text: $translate.instant('IsConfirmReCalcuate').formatObj({status: vatCommonService.getProjectStautsEnumDesc(vatSessionService.project.projectStatusList[vatSessionService.month])}),
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: $translate.instant('Yes'),
cancelButtonText: $translate.instant('No'),
closeOnConfirm: true,
closeOnCancel: true
},
function (isConfirm) {
if (isConfirm) {
vatReportService.hasManualDataSource(vatSessionService.project.id,vatSessionService.month).then(function (hasManual) {
if(hasManual){
swal({
title: "warning!",
text: "是否保留手工数据!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: $translate.instant('Yes'),
cancelButtonText: $translate.instant('No'),
closeOnConfirm: true,
closeOnCancel: true
},
function (isConfirm) {
if (isConfirm) {
doStartCaculate2(true);
}else{
doStartCaculate2(false);
}
});
}else{
doStartCaculate2(false);
}
});
}
else {
swal.close();
}
});
}
else {
doStartCaculate2(false);
}
};
var caculateProgress = function (task) { var caculateProgress = function (task) {
var completedCnt = taskList.filter(function (t) { var completedCnt = taskList.filter(function (t) {
...@@ -464,9 +525,66 @@ ...@@ -464,9 +525,66 @@
logDto.OperationType = enums.vatLogOperationTypeEnum.CalculateData; logDto.OperationType = enums.vatLogOperationTypeEnum.CalculateData;
logDto.UpdateState = status == null ? '' : status; logDto.UpdateState = status == null ? '' : status;
vatOperationLogService.addOperationLog(logDto); vatOperationLogService.addOperationLog(logDto);
}; };
var updateTasksStatus = function(job){
if((job).currentStep == 'UpdateConfig'){
$scope.tasks[0].items[0].status = 'processing';
}else{
$scope.tasks[0].items[0].status = 'completed';
var items = $scope.tasks[1].items;
var currentIndex = 0;
items.forEach(function(item,index){
if((job).currentStep == item.code){
currentIndex = index;
}
});
items.forEach(function(item,index){
if(index < currentIndex){
item.status ='completed';
}else if(index == currentIndex){
if((job).status == 'Error'){
item.status = 'error';
}else if(result.data.status == 'End'){
item.status = 'completed';
if($scope.timer){
$interval.cancel($scope.timer);
}
}else if(result.data.status == 'Begin'){
item.status = 'processing';
}
}
});
}
}
var getInitTaskStatus = function(){
vatReportService.getRunningJob(vatSessionService.project.id,vatSessionService.month).then(function (result) {
if(result.data && result.status == 200){
updateTasksStatus(result.data);
if(result.data.status=='Begin'){
$scope.timer= $interval(function(){
vatReportService.getJobStatus(vatSessionService.project.id,vatSessionService.month,jobId,id).then(function(result){
if(result.data && result.status == 200){
updateTasksStatus(result.data);
}
});
},1000);
}
}else{
$log.debug("not running job");
}
});
}
var
var sendMessage = function (task) { var sendMessage = function (task) {
var msgDto = {}; var msgDto = {};
msgDto.projectId = vatSessionService.project.id; msgDto.projectId = vatSessionService.project.id;
...@@ -494,6 +612,7 @@ ...@@ -494,6 +612,7 @@
$scope.resolveRef = []; $scope.resolveRef = [];
initTasks(); initTasks();
$scope.startCaculate = startCaculate; $scope.startCaculate = startCaculate;
$scope.startCaculate2 = startCaculate2;
})(); })();
} }
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
<div class="vat-caculate-data-title" ng-if="tasks.length > 0"> <div class="vat-caculate-data-title" ng-if="tasks.length > 0">
<!--<span translate="vatCaculateDataDesc"></span>--> <!--<span translate="vatCaculateDataDesc"></span>-->
<button class="btn btn-vat-primary" translate="startCaculateData" ng-disabled="readonly" ng-click="startCaculate()"></button> <button class="btn btn-vat-primary" translate="startCaculateData" ng-disabled="readonly" ng-click="startCaculate()"></button>
<button class="btn btn-vat-primary" translate="startCaculateData" ng-disabled="readonly" ng-click="startCaculate2()"></button>
<span ng-click="showOperateLogPop()"><i class="fa fa-file-excel-o" aria-hidden="true"></i>{{'Remarks' | translate}}</span> <span ng-click="showOperateLogPop()"><i class="fa fa-file-excel-o" aria-hidden="true"></i>{{'Remarks' | translate}}</span>
</div> </div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment