From a34bfebcde00cea54ca9d484b7aabe889469a93d Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Thu, 12 Nov 2020 22:29:04 +0300 Subject: [PATCH] first calculation!!! --- .../Calculation/Sections/sectionsList.ts | 2 +- src/client/Containers/Calculation/index.jsx | 29 +++++++++---- src/client/services/CalculationService.ts | 41 ++++++++++++++++++- src/client/services/prepareData.ts | 23 +++++++++-- .../stores/CalculationStore/Effects/action.ts | 10 ++++- src/core/constants/urls.ts | 2 + src/core/types/Calculation/Prepare.ts | 5 --- src/core/types/Calculation/Requests.ts | 7 +++- .../controllers/CalculationController.ts | 17 +------- src/server/routes/calculation.ts | 2 - src/server/routes/proxy.ts | 3 ++ 11 files changed, 102 insertions(+), 39 deletions(-) diff --git a/src/client/Containers/Calculation/Sections/sectionsList.ts b/src/client/Containers/Calculation/Sections/sectionsList.ts index 727e133..cbd4ab5 100644 --- a/src/client/Containers/Calculation/Sections/sectionsList.ts +++ b/src/client/Containers/Calculation/Sections/sectionsList.ts @@ -1603,7 +1603,7 @@ const sections: ISections[] = [ Component: Select, props: { name: 'selectTarif', - valueName: 'Tarif', + valueName: 'tarif', }, }, { diff --git a/src/client/Containers/Calculation/index.jsx b/src/client/Containers/Calculation/index.jsx index 95e4d4d..b951c3e 100644 --- a/src/client/Containers/Calculation/index.jsx +++ b/src/client/Containers/Calculation/index.jsx @@ -26,7 +26,7 @@ const Calculation = () => { }), CalculationService.crmgqlquery({ query: gql` - query($statecode: Int, $currentDate: DateTime, $username: String) { + query($statecode: Int, $currentDate: DateTime) { evo_impairment_group: evo_impairment_groups( statecode: $statecode ) { @@ -73,13 +73,6 @@ const Calculation = () => { evo_name evo_sot_coefficient_typeid } - systemuser(domainname: $username) { - evo_job_titleid - businessunitid - firstname - lastname - fullname - } evo_job_title: evo_job_titles(statecode: $statecode) { evo_id evo_name @@ -90,9 +83,22 @@ const Calculation = () => { variables: { statecode: 0, currentDate, - username: `${DomainName}\\${UserName}`, }, }), + CalculationService.crmgqlquery({ + query: gql` + query($username: String) { + systemuser(domainname: $username) { + evo_job_titleid + businessunitid + firstname + lastname + fullname + } + } + `, + variables: { username: `${DomainName}\\${UserName}` }, + }), CalculationService.getEntities({ queries: [ { @@ -109,10 +115,15 @@ const Calculation = () => { ([ { entities: initialOptions }, { entities: staticEntities }, + { + entities: { systemuser }, + }, { entities: insuranceCompanies }, ]) => { + console.log('Calculation -> staticEntities', staticEntities); calculationStore.applyOptions(initialOptions); calculationStore.applyStaticData(staticEntities); + calculationStore.applyStaticData({ systemuser: [systemuser] }); calculationStore.setTableColumns('tableInsurance')({ options: { ...insuranceCompanies }, }); diff --git a/src/client/services/CalculationService.ts b/src/client/services/CalculationService.ts index d2cc098..667a913 100644 --- a/src/client/services/CalculationService.ts +++ b/src/client/services/CalculationService.ts @@ -1,14 +1,20 @@ import { ApolloClient, gql, HttpLink, InMemoryCache } from '@apollo/client'; import axios from 'axios'; import { API_HOSTNAME } from 'client/common/constants'; -import { CRM_GRAPHQL_PROXY_URL, CRM_GRAPHQL_URL } from 'core/constants/urls'; +import { + CORE_PROXY_URL, + CRM_GRAPHQL_PROXY_URL, + CRM_GRAPHQL_URL, +} from 'core/constants/urls'; import { convertEntityToOption } from 'core/tools/entities'; import { convertJSONToGQLQuery } from 'core/tools/query'; import { IGetEntitiesRequest, IRequestToCRMGQL, + IGetCalculationRequest, } from 'core/types/Calculation/Requests'; import { + IGetCalculationResponse, IGetEntitiesResponse, IGetUserResponse, } from 'core/types/Calculation/Responses'; @@ -49,6 +55,39 @@ class CalculationService { }); }); + static calculate = ( + preparedData: IGetCalculationRequest, + ): Promise => + new Promise((resolve, reject) => { + axios + .post( + String.prototype.concat( + (process.env.NODE_ENV !== 'development' && + `http://${API_HOSTNAME}:3001`) || + '', + '/proxy', + CORE_PROXY_URL, + '/api', + '/v1', + '/calculation', + '/calculate', + ), + { + preparedValues: preparedData.preparedValues, + preparedPayments: { + Rows: preparedData.preparedPayments, + }, + }, + ) + .then(res => { + console.log(res); + resolve(res.data); + }) + .catch(err => { + throw err; + }); + }); + static crmgqlquery = ({ query, toOptions, diff --git a/src/client/services/prepareData.ts b/src/client/services/prepareData.ts index b083a28..191aac8 100644 --- a/src/client/services/prepareData.ts +++ b/src/client/services/prepareData.ts @@ -20,7 +20,15 @@ export const prepareCalculationData = ({ //@ts-ignore let preparedPayments: PreparedPayments = Array.from( { length: values.leasingPeriod }, - () => ({}), + () => ({ + numberPayment: 0, + percentPayment: 0, + sumPayment: 0, + gpsBasePayment: 0, + gpsCostPayment: 0, + tlmBasePayment: 0, + tlmCostPayment: 0, + }), ); const tracker = options.selectTracker?.find(x => x.evo_id === values.tracker); @@ -67,7 +75,16 @@ export const prepareCalculationData = ({ } } - let preparedValues: PreparedValues = {}; + let preparedValues: PreparedValues = { + brandId: '00000000-0000-0000-0000-000000000000', + configurationId: '00000000-0000-0000-0000-000000000000', + firstPaymentAbs: 0, + firstPaymentNdsAbs: 0, + firstPaymentWithNdsAbs: 0, + modelId: '00000000-0000-0000-0000-000000000000', + paymentDateNew: new Date(), + plTypeId: '00000000-0000-0000-0000-000000000000', + }; preparedValues.calcDate = currentDate; preparedValues.calcType = 100000000; @@ -564,7 +581,7 @@ export const prepareCalculationData = ({ preparedValues.cityc = values.townRegistration || values.regionRegistration; - const tarif = options.selectTarif?.find(x => x.evo_id === values.tarif); + const tarif = options.selectTarif?.find(x => x.evo_tarifid === values.tarif); if (tarif) { preparedValues.iRR_MSFO_Plan = (tarif.evo_irr_plan || 0) / 100; } diff --git a/src/client/stores/CalculationStore/Effects/action.ts b/src/client/stores/CalculationStore/Effects/action.ts index 16e9134..63629a9 100644 --- a/src/client/stores/CalculationStore/Effects/action.ts +++ b/src/client/stores/CalculationStore/Effects/action.ts @@ -2,6 +2,7 @@ import { openNotification } from 'client/Elements/Notification'; import CalculationStore from 'client/stores/CalculationStore'; import { TAction } from 'core/types/Calculation/Store/effect'; import { prepareCalculationData } from 'client/services/prepareData'; +import CalculationService from 'client/services/CalculationService'; const actions: TAction = { createLead: () => { @@ -210,7 +211,14 @@ const actions: TAction = { var preparedData = prepareCalculationData({ calculationStore: CalculationStore, }); - console.log('preparedData', preparedData); + + console.log(preparedData); + console.log(CalculationStore.values); + + CalculationService.calculate(preparedData).then(res => { + console.log(res.columns); + console.log(res.postValues); + }); }, }; diff --git a/src/core/constants/urls.ts b/src/core/constants/urls.ts index 0be9aec..5ac1179 100644 --- a/src/core/constants/urls.ts +++ b/src/core/constants/urls.ts @@ -1,3 +1,5 @@ export const API_PORT = 3001; export const CRM_GRAPHQL_URL = 'http://crmgraphql-dev.evoleasing.ru'; export const CRM_GRAPHQL_PROXY_URL = '/crmgraphql'; +export const CORE_URL = 'http://localhost:5000'; +export const CORE_PROXY_URL = '/core'; diff --git a/src/core/types/Calculation/Prepare.ts b/src/core/types/Calculation/Prepare.ts index 62b9e77..8f6ff6c 100644 --- a/src/core/types/Calculation/Prepare.ts +++ b/src/core/types/Calculation/Prepare.ts @@ -1,4 +1,3 @@ -import { CRMEntityNames } from '../Entities/crmEntityNames'; export interface PreparedValues { calcDate?: Date; calcType?: number; @@ -103,7 +102,3 @@ export interface PaymentRow { } export type PreparedPayments = PaymentRow[]; - -export type TPrepareEntities = { - [entityAlias in CRMEntityNames]?: T; -}; diff --git a/src/core/types/Calculation/Requests.ts b/src/core/types/Calculation/Requests.ts index 7520e77..8c9fb21 100644 --- a/src/core/types/Calculation/Requests.ts +++ b/src/core/types/Calculation/Requests.ts @@ -1,6 +1,10 @@ import { ICalculationStore } from 'core/types/Calculation/Store'; import { CRMEntityNames } from 'core/types/Entities/crmEntityNames'; import { TEntityQuery } from '../Entities/query'; +import { + PreparedPayments, + PreparedValues, +} from 'core/types/Calculation/Prepare'; export interface IGetEntitiesRequest { queries: TEntityQuery[]; @@ -13,5 +17,6 @@ export interface IRequestToCRMGQL { } export interface IGetCalculationRequest { - calculationStore: ICalculationStore; + preparedPayments: PreparedPayments; + preparedValues: PreparedValues; } diff --git a/src/server/controllers/CalculationController.ts b/src/server/controllers/CalculationController.ts index 0042bf3..2986369 100644 --- a/src/server/controllers/CalculationController.ts +++ b/src/server/controllers/CalculationController.ts @@ -1,18 +1,3 @@ -import { Response } from 'express'; -import { IGetCalculationResponse } from '../../core/types/Calculation/Responses'; -import { IGetCalculationRequest } from '../../core/types/Calculation/Requests'; - -class CalculationController { - static calculate = async ( - req: { body: IGetCalculationRequest }, - res: Response, - ): Promise => { - /** - * prepare Data - * send to core - * send to client - */ - }; -} +class CalculationController {} export default CalculationController; diff --git a/src/server/routes/calculation.ts b/src/server/routes/calculation.ts index 9cb6ad0..c7329c2 100644 --- a/src/server/routes/calculation.ts +++ b/src/server/routes/calculation.ts @@ -3,6 +3,4 @@ import CalculationController from '../controllers/CalculationController'; const router = Router(); -router.post('/calculate', CalculationController.calculate); - export default router; diff --git a/src/server/routes/proxy.ts b/src/server/routes/proxy.ts index c83d8b6..98b7f5d 100644 --- a/src/server/routes/proxy.ts +++ b/src/server/routes/proxy.ts @@ -3,10 +3,13 @@ import proxy from 'express-http-proxy'; import { CRM_GRAPHQL_PROXY_URL, CRM_GRAPHQL_URL, + CORE_URL, + CORE_PROXY_URL, } from '../../core/constants/urls'; const router = Router(); router.use(CRM_GRAPHQL_PROXY_URL, proxy(CRM_GRAPHQL_URL)); +router.use(CORE_PROXY_URL, proxy(CORE_URL)); export default router;