Fonctionnalité #16323
ferméAnalyse / review : code réconciliation custom en 20.03
Description
Bonjour,
Le Maarch Courrier de la SITIV dispose de code custom (effectué par Laurent) dans 2 fichiers du socle commun, avec des modifications concernant la réconciliation (permet d'appliquer automatiquement le statut 'END' au courrier réconcilié).
Les deux fichiers en question sont : rest/index.php et src/app/resource/controllers/ResController.php. Les parties en vert ci dessous ne sont pas présentes par défaut dans l'application :
root@dccourrier-prod:/var/www/html/MaarchCourrier# git diff rest/index.php
diff --git a/rest/index.php b/rest/index.php
index d17f1f4fe3..7562b145bb 100755
--- a/rest/index.php
+++ b/rest/index.php
@@ -392,6 +392,7 @@ $app->delete('/resources/{resId}/circuits/{type}', \Entity\controllers\ListInsta
$app->get('/resources/{resId}/fileInformation', \Resource\controllers\ResController::class . ':getResourceFileInformation');
$app->put('/res/resource/status', \Resource\controllers\ResController::class . ':updateStatus');
+$app->put('/res/resource/statusAfterReconcil', \Resource\controllers\ResController::class . ':updateStatusAfterReconcil');
$app->post('/res/list', \Resource\controllers\ResController::class . ':getList');
$app->put('/res/externalInfos', \Resource\controllers\ResController::class . ':updateExternalInfos');
$app->get('/categories', \Resource\controllers\ResController::class . ':getCategories');
root@dccourrier-prod:/var/www/html/MaarchCourrier# git diff src/app/resource/controllers/ResController.php
diff --git a/src/app/resource/controllers/ResController.php b/src/app/resource/controllers/ResController.php
index 25f54627d7..810d80bf4c 100755
--- a/src/app/resource/controllers/ResController.php
+++ b/src/app/resource/controllers/ResController.php
@@ -423,6 +423,54 @@ class ResController extends ResourceControlController
return $response->withJson(['success' => 'success']);
}
+ public function updateStatusAfterReconcil(Request $request, Response $response)
+ {
+ $data = $request->getParams();
+
+ if (empty($data['status'])) {
+ $data['status'] = 'COU';
+ }
+ if (empty(StatusModel::getById(['id' => $data['status']]))) {
+ return $response->withStatus(400)->withJson(['errors' => _STATUS_NOT_FOUND]);
+ }
+ if (empty($data['historyMessage'])) {
+ $data['historyMessage'] = _UPDATE_STATUS;
+ }
+
+ $check = Validator::arrayType()->notEmpty()->validate($data['chrono']) || Validator::arrayType()->notEmpty()->validate($data['resIdAttach']);
+ $check = $check && Validator::stringType()->notEmpty()->validate($data['status']);
+ $check = $check && Validator::stringType()->notEmpty()->validate($data['historyMessage']);
+ if (!$check) {
+ return $response->withStatus(400)->withJson(['errors' => 'Bad Request']);
+ }
+
+ $identifiers = !empty($data['chrono']) ? $data['chrono'] : $data['resIdAttach'];
+ foreach ($identifiers as $id) {
+ $attachments = AttachmentModel::get([
+ 'select' => ['res_id_master'],
+ 'where' => ['res_id = ?'],
+ 'data' => [$id]
+ ]);
+
+ if (empty($attachments[0]['res_id_master'])) {
+ return $response->withStatus(400)->withJson(['errors' => _DOCUMENT_NOT_FOUND]);
+ }
+
+ ResModel::update(['set' => ['status' => $data['status']], 'where' => ['res_id = ?'], 'data' => [$attachments[0]['res_id_master']]]);
+
+ HistoryController::add([
+ 'tableName' => 'res_letterbox',
+ 'recordId' => $attachments[0]['res_id_master'],
+ 'eventType' => 'UP',
+ 'info' => $data['historyMessage'],
+ 'moduleId' => 'resource',
+ 'eventId' => 'resup',
+ ]);
+ }
Cette fonction est sollicitée dans le cadre de la réconciliation de la ville de Stchamond.
Voici les configurations qui l'utilise :
Capture.xml :
<!-- RECONCIL WITH QRCODE-->
<batch name="RECONCIL_STCHAMOND" directory="/opt/maarch/MaarchCapture/files/" id="{batchname}-{timestamp}-{rand}" lock="0">
<workflow name="RECONCIL_STCHAMOND" debug="true" logMode="Maarch" maarchLogParam="/var/www/html/MaarchCourrier/custom/cs_stchamond/apps/maarch_entreprise/xml/log4php.xml" maarchLoggerName="lo$
<step function="reconcile" module="QRSeparator" name="reconcil">
<input name="ScanSource">/home/maarch-sc/sortant/reconcil/</input>
<input name="qrcodePrefix">false</input>
</step>
<step function="processBatch" module="MaarchWSClient" name="SendToMaarch">
<input name="WSDL">cs_stchamond</input>
<input name="Process">ReconcilWithQrCodeNew</input>
<input name="CatchError">false</input>
<input name="configFile">MaarchWSClient.xml</input>
</step>
</workflow>
</batch>
MaarchWSClient.xml
<process name="ReconcilWithQrCodeNew">
<loop xpath="/Batch/Documents/Document">
<call name="/attachments" method="POST">
<argument type="entity" name="chrono" metadata="chrono"/>
<argument type="entity" name="encodedFile" eval="base64_encode(file_get_contents($Element->path))"/>
<argument type="entity" name="format" attribute="extension"/>
<argument type="entity" name="resIdMaster" metadata="resIdMaster"/>
<argument type="entity" name="originId" metadata="originId"/>
<argument type="entity" name="title" metadata="title"/>
<argument type="entity" name="type" eval="(empty($Element->getMetadata('originId')) ? 'signed_mail' : 'signed_response')"/>
<return>
<id metadata="id" />
</return>
</call>
<call name="/res/resource/statusAfterReconcil" method="PUT">
<argument type="entity" name="resIdAttach" eval="[$Element->getMetadata('id')]"/>
<argument type="entity" name="status">END</argument>
<!--return>
<id metadata="resId" />
</return-->
</call>
</loop>
</process>
J'ai fait le test a stchamond en créant un courrier arrivé avec anbillard, puis en créant un projet de réponse que j'ai signé sur mon poste :
- Avec la recette est en 20.03.18 par défaut :
root@dccourrier-test:/opt/maarch/MaarchCapture/files# cd BRECONCIL_STCHAMOND-1613562748-1893967855
root@dccourrier-test:/opt/maarch/MaarchCapture/files/BRECONCIL_STCHAMOND-1613562748-1893967855# ls
2.pdf 2.png BRECONCIL_STCHAMOND-1613562748-1893967855.xml D1.pdf WRECONCIL_STCHAMOND-1613562748-1893967855.log WRECONCIL_STCHAMOND-1613562748-1893967855.xml
root@dccourrier-test:/opt/maarch/MaarchCapture/files/BRECONCIL_STCHAMOND-1613562748-1893967855# cat WRECONCIL_STCHAMOND-1613562748-1893967855.log
2021-02-17T12:52:28+01:00 [0] Initializing workflow RECONCIL_STCHAMOND
2021-02-17T12:52:28+01:00 [0] (Re)Starting workflow RECONCIL_STCHAMOND
2021-02-17T12:52:28+01:00 [0] Initializing step reconcil
2021-02-17T12:52:28+01:00 [0] Starting step reconcil
2021-02-17T12:52:28+01:00 [0] Init process ...
2021-02-17T12:52:28+01:00 [0] * File n°1: TESTMAARCH.pdf *
2021-02-17T12:52:32+01:00 [0] Document D1 added with source /opt/maarch/MaarchCapture/files//BRECONCIL_STCHAMOND-1613562748-1893967855/2.pdf
2021-02-17T12:52:32+01:00 [0] End of process ...
2021-02-17T12:52:32+01:00 [0] Step completed in 3.355 seconds
2021-02-17T12:52:32+01:00 [0] Saving batch on disk...
2021-02-17T12:52:32+01:00 [0] Batch saved in 0.000 seconds
2021-02-17T12:52:32+01:00 [0] Initializing step SendToMaarch
2021-02-17T12:52:32+01:00 [0] Starting step SendToMaarch
2021-02-17T12:52:32+01:00 [0] return value from web service /attachments id : 4416
2021-02-17T12:52:32+01:00 [2] ERROR No return from web service!
2021-02-17T12:52:32+01:00 [3] ERROR No return from web service!
2021-02-17T12:52:32+01:00 [3] Process error! See previous messages for more information.
-
- Avec la recette est en 20.03.18 avec les modifications (ca fonctionne) :
root@dccourrier-test:/opt/maarch/MaarchCapture/files/BRECONCIL_STCHAMOND-1613562463-440304421# cat WRECONCIL_STCHAMOND-1613562463-440304421.log
2021-02-17T12:47:43+01:00 [0] Initializing workflow RECONCIL_STCHAMOND
2021-02-17T12:47:43+01:00 [0] (Re)Starting workflow RECONCIL_STCHAMOND
2021-02-17T12:47:43+01:00 [0] Initializing step reconcil
2021-02-17T12:47:43+01:00 [0] Starting step reconcil
2021-02-17T12:47:43+01:00 [0] Init process ...
2021-02-17T12:47:43+01:00 [0] * File n°1: TESTMAARCH.pdf *
2021-02-17T12:47:47+01:00 [0] Document D1 added with source /opt/maarch/MaarchCapture/files//BRECONCIL_STCHAMOND-1613562463-440304421/2.pdf
2021-02-17T12:47:47+01:00 [0] End of process ...
2021-02-17T12:47:47+01:00 [0] Step completed in 3.812 seconds
2021-02-17T12:47:47+01:00 [0] Saving batch on disk...
2021-02-17T12:47:47+01:00 [0] Batch saved in 0.000 seconds
2021-02-17T12:47:47+01:00 [0] Initializing step SendToMaarch
2021-02-17T12:47:47+01:00 [0] Starting step SendToMaarch
2021-02-17T12:47:47+01:00 [0] return value from web service /attachments id : 4415
2021-02-17T12:47:48+01:00 [0] Step completed in 0.439 seconds
2021-02-17T12:47:48+01:00 [0] Saving batch on disk...
2021-02-17T12:47:48+01:00 [0] Batch saved in 0.000 seconds
2021-02-17T12:47:48+01:00 [0] No more step to process, end of the workflow.
Fichiers