Files
doneit-web/src/app/Rules/despacho.service.ts
T

286 lines
6.9 KiB
TypeScript
Raw Normal View History

2021-07-27 21:19:09 +01:00
import { Injectable } from '@angular/core';
2023-06-23 11:47:20 +01:00
import { customTask, fullTaskList } from '../models/dailyworktask.model';
2021-08-20 17:41:51 +01:00
import { AttachmentList } from '../models/Excludetask';
import { CustomTaskPipe } from '../pipes/custom-task.pipe';
2021-07-27 21:19:09 +01:00
import { ProcessesService } from '../services/processes.service';
import { DespachoStore } from '../store/despacho-store.service';
import { LoaderService } from 'src/app/store/loader.service'
2021-09-02 10:12:18 +01:00
import { SessionStore } from '../store/session.service';
2022-03-28 15:46:07 +01:00
import { PermissionService } from '../services/permission.service';
2021-10-18 13:58:26 +01:00
import { SortService } from '../services/functions/sort.service';
2021-09-30 15:56:04 +01:00
2022-12-29 15:31:54 +01:00
2021-07-27 21:19:09 +01:00
@Injectable({
providedIn: 'root'
})
2021-07-30 22:03:48 +01:00
export class DespachoService {
2021-07-27 21:19:09 +01:00
/**
* @description para terminar o
* 95 - signfica
* 98 - significa
*/
ActionTypeId: 95 | 98
action: "Arquivo" | "Reencaminhar"
2021-08-05 16:59:17 +01:00
actions: {
'Tarefa do Despacho': 'Tarefa de Despacho' | 'Concluir' | 'rexecucao'
}
customTaskPipe = new CustomTaskPipe()
despachoStore = DespachoStore;
2023-01-12 15:27:09 +01:00
loader = this.LoaderService.initialize("DespachoService")
constructor(
2021-07-27 21:19:09 +01:00
private processes: ProcessesService,
public p: PermissionService,
2021-10-18 13:58:26 +01:00
public LoaderService: LoaderService,
private sortService: SortService,
2022-12-29 15:31:54 +01:00
) {}
2021-09-06 12:14:21 +01:00
2021-08-20 17:41:51 +01:00
arquivar(note:string, documents:AttachmentList, serialnumber) {
2021-07-29 15:40:24 +01:00
2021-07-27 21:19:09 +01:00
let body = {
"serialNumber": serialnumber,
"action": "Arquivo",
"ActionTypeId": 95,
"dataFields": {
"ReviewUserComment": note,
},
"AttachmentList" :documents,
}
2021-09-06 12:14:21 +01:00
2021-07-27 21:19:09 +01:00
return this.processes.CompleteTask(body)
}
2021-09-06 12:14:21 +01:00
2021-08-05 16:59:17 +01:00
executado(note:string, documents:any , serialnumber) {
2021-09-06 12:14:21 +01:00
2021-07-27 21:19:09 +01:00
let body = {
"serialNumber": serialnumber,
2021-08-05 16:59:17 +01:00
"action": "Conhecimento",
"ActionTypeId": 104,
2021-07-27 21:19:09 +01:00
"dataFields": {
"ReviewUserComment": note,
},
"AttachmentList" :documents,
}
2021-08-05 16:59:17 +01:00
2021-07-27 21:19:09 +01:00
return this.processes.CompleteTask(body)
}
2021-08-05 16:59:17 +01:00
solicitarParecer({note, documents = [], serialnumber, activityInstanceName}) {
2021-09-06 12:14:21 +01:00
let body;
2021-09-06 14:41:32 +01:00
if(activityInstanceName == 'Concluir Despacho'
|| activityInstanceName == 'Concluir Parecer'
|| activityInstanceName == 'Concluir Deferimento'
|| activityInstanceName == 'Tarefa de Deferimento'
){
2021-09-06 12:14:21 +01:00
body = {
"serialNumber": serialnumber,
"action": "Parecer",
"ActionTypeId": 92,
"dataFields": {
"ReviewUserComment": note,
},
"AttachmentList" :documents,
}
}
else{
body = {
"serialNumber": serialnumber,
"action": "Conhecimento",
"ActionTypeId": 92,
"dataFields": {
"ReviewUserComment": note,
},
"AttachmentList" :documents,
}
2021-08-16 16:46:57 +01:00
}
return this.processes.CompleteTask(body)
2021-08-05 16:59:17 +01:00
}
EfectuarDespacho({note, documents = [], serialnumber, activityInstanceName}) {
2021-09-06 12:14:21 +01:00
let body;
2021-09-06 14:41:32 +01:00
if(activityInstanceName == 'Concluir Despacho'
|| activityInstanceName == 'Concluir Parecer'
|| activityInstanceName == 'Concluir Deferimento'
|| activityInstanceName == 'Tarefa de Deferimento'
){
2021-09-06 12:14:21 +01:00
body = {
"serialNumber": serialnumber,
"action": "Despacho",
"ActionTypeId": 94,
"dataFields": {
"ReviewUserComment": note,
},
"AttachmentList" :documents,
}
2021-08-16 16:46:57 +01:00
}
2021-09-06 12:14:21 +01:00
else{
body = {
"serialNumber": serialnumber,
"action": "Conhecimento",
"ActionTypeId": 94,
"dataFields": {
"ReviewUserComment": note,
},
2022-06-03 16:53:50 +01:00
"AttachmentList" :documents,
2021-09-06 12:14:21 +01:00
}
}
2022-04-28 09:32:27 +01:00
2021-08-16 16:46:57 +01:00
return this.processes.CompleteTask(body)
2021-08-05 16:59:17 +01:00
}
2021-08-20 17:41:51 +01:00
reexecute({note, documents, serialnumber}) {
2021-07-27 21:19:09 +01:00
let body = {
"serialNumber": serialnumber,
2021-08-05 16:59:17 +01:00
"action": "Reexecução",
"ActionTypeId": 100000010,
2021-07-27 21:19:09 +01:00
"dataFields": {
"ReviewUserComment": note,
},
"AttachmentList" :documents,
}
return this.processes.CompleteTask(body)
}
2021-07-30 22:03:48 +01:00
2021-08-16 16:46:57 +01:00
/**
* @description efetuar despacho
*/
CompleteTask({serialNumber, note}) {
2021-08-05 11:47:09 +01:00
const body = {
"serialNumber": serialNumber,
"action": "Despacho",
"ActionTypeId": 94,
"dataFields": {
"ReviewUserComment": note,
2021-08-05 11:47:09 +01:00
},
"AttachmentList" :null,
}
return this.processes.CompleteTask(body)
}
2021-07-27 21:26:31 +01:00
2021-08-16 16:46:57 +01:00
2021-08-06 09:42:34 +01:00
// Finalizar({serialNumber}) {
// const body = {
// "serialNumber": serialNumber,
// "action": "Conhecimento",
// "ActionTypeId": 104,
// "dataFields": {
// "ReviewUserComment": '',
// },
// "AttachmentList" :null,
// }
// }
2021-08-05 16:08:49 +01:00
2021-08-05 11:47:09 +01:00
sendExpedienteToPending(serialnumber) {
2021-07-27 21:26:31 +01:00
return this.processes.SetTaskToPending(serialnumber)
}
2021-08-05 11:47:09 +01:00
/**
* @param body any
* @returns promise
* @description for both profile PR and MDGPR
*/
createDespacho(body: any) {
if(this.p.userRole(['PR'])) {
return this.processes.postDespatchoPr(body)
} else {
return this.processes.postDespatcho(body)
}
}
2021-08-16 16:46:57 +01:00
createParecer(body: any) {
if(this.p.userRole(['PR'])) {
return this.processes.postParecerPr(body)
} else {
return this.processes.postParecer(body)
}
}
2021-08-20 17:41:51 +01:00
generateDiploma({note = '', documents = [], serialnumber}) {
let body = {
"serialNumber": serialnumber,
"action": "Reencaminhar",
"ActionTypeId": 99999839,
"dataFields": {
"ReviewUserComment": note,
},
"AttachmentList" :documents,
}
return this.processes.CompleteTask(body)
}
2021-11-29 14:50:57 +01:00
async getList({updateStore = false}) {
2021-09-06 12:14:21 +01:00
2021-08-27 09:48:51 +01:00
if (this.LoaderService.loading) {
return this.despachoStore.list
}
this.LoaderService.push({})
2022-12-30 14:45:08 +01:00
// this.loader.push()
2021-09-06 12:14:21 +01:00
2021-08-30 10:24:46 +01:00
let result: fullTaskList[] = []
let despachoList: customTask[] = [];
try {
result = await this.processes.GetTasksList("Despacho", false).toPromise();
2021-08-30 10:24:46 +01:00
result = result.filter((data:fullTaskList) => data.workflowInstanceDataFields.Status == "Active")
result.forEach((element, index) => {
2021-09-06 12:14:21 +01:00
2021-08-30 10:24:46 +01:00
let task: customTask = this.customTaskPipe.transform(element);
despachoList.push(task);
2021-09-06 12:14:21 +01:00
2022-12-29 15:31:54 +01:00
})
2021-09-06 12:14:21 +01:00
2021-11-23 16:23:44 +01:00
despachoList = this.sortService.sortDate(despachoList, 'CreateDate')
2022-01-28 15:59:01 +01:00
2021-08-30 10:24:46 +01:00
if(updateStore) {
this.despachoStore.reset(despachoList);
}
2021-09-06 12:14:21 +01:00
} catch (error) {
} finally {
this.LoaderService.pop({})
2022-12-30 14:45:08 +01:00
// this.loader.pop()
2021-08-30 10:24:46 +01:00
return this.despachoStore.list
}
}
2021-09-02 10:12:18 +01:00
async getListPr() {
2022-12-29 15:31:54 +01:00
2022-12-30 14:45:08 +01:00
// this.loader.push()
2022-12-29 15:31:54 +01:00
let result
try {
result = await this.processes.GetTasksList("Despacho do Presidente da República", false).toPromise();
} catch(error) {
2022-12-30 14:45:08 +01:00
// this.loader.pop()
2022-12-29 15:31:54 +01:00
}
2022-12-30 14:45:08 +01:00
// this.loader.pop()
2021-09-02 10:12:18 +01:00
let despachosPr;
2021-10-18 13:58:26 +01:00
let despachos = this.sortService.sortArrayByDate(result);
2022-05-05 16:12:51 +01:00
if(SessionStore.user.Profile != 'PR') {
despachosPr = despachos.reverse().filter(data => data.activityInstanceName == "Tarefa de Despacho");
} else if(SessionStore.user.Profile == 'PR') {
despachosPr = despachos.reverse().filter(data => data.activityInstanceName == "Concluir Despacho");
2021-09-02 10:12:18 +01:00
}
2022-05-05 16:12:51 +01:00
2021-09-02 10:12:18 +01:00
}
2021-07-27 21:19:09 +01:00
}