115 lines
3.5 KiB
JavaScript
115 lines
3.5 KiB
JavaScript
|
module.exports = Self => {
|
||
|
Self.remoteMethodCtx('save', {
|
||
|
description: 'Save sign',
|
||
|
accessType: 'WRITE',
|
||
|
accepts:
|
||
|
[
|
||
|
{
|
||
|
singContent: 'String',
|
||
|
required: true,
|
||
|
description: 'The sign content'
|
||
|
}, {
|
||
|
tickets: 'Array',
|
||
|
required: true,
|
||
|
description: 'The tickets'
|
||
|
}, {
|
||
|
signedTime: 'Date',
|
||
|
required: true,
|
||
|
description: 'The signed time'
|
||
|
}, {
|
||
|
addressFk: 'Number',
|
||
|
required: true,
|
||
|
description: 'The address fk'
|
||
|
}
|
||
|
],
|
||
|
returns: {
|
||
|
type: 'Object',
|
||
|
root: true
|
||
|
},
|
||
|
http: {
|
||
|
path: `/save-sign`,
|
||
|
verb: 'POST'
|
||
|
}
|
||
|
});
|
||
|
|
||
|
Self.save = async(ctx, signContent, tickets, signedTime, addressFk) => {
|
||
|
const userId = ctx.req.accessToken.userId;
|
||
|
console.log('userId: ', userId);
|
||
|
|
||
|
return {0: 'OK'};
|
||
|
};
|
||
|
};
|
||
|
|
||
|
/** ----------------------------------------------------------------------------------------------
|
||
|
|
||
|
public function execute()
|
||
|
{
|
||
|
$signContent = $this->signObject->Sign;
|
||
|
$tickets = $this->signObject->Tickets;
|
||
|
$dated = $this->signObject->signedTime;
|
||
|
$adressFK = $this->signObject->addressFk;
|
||
|
|
||
|
$this->conn->beginTransaction();
|
||
|
try {
|
||
|
|
||
|
if (property_exists($this->signObject, "Location") && !is_null($this->signObject->Location)) {
|
||
|
$this->setLocation($this->signObject->Location, $tickets);
|
||
|
|
||
|
}
|
||
|
|
||
|
$id = null;
|
||
|
$image = null;
|
||
|
$dmsDir = $this->conn->fetchColumn("SELECT dmsDir FROM hedera.config");
|
||
|
|
||
|
foreach ($tickets as $t) {
|
||
|
|
||
|
$call = "SELECT alertLevel FROM vn.ticketState WHERE ticketFk = ?";
|
||
|
$params = array($t);
|
||
|
$result = $this->conn->fetchAll($call, $params);
|
||
|
|
||
|
$alertLevel = 0;
|
||
|
|
||
|
foreach ($result as $row) {
|
||
|
$alertLevel = $row['alertLevel'];
|
||
|
}
|
||
|
|
||
|
if ($alertLevel >= 2) {
|
||
|
|
||
|
if (!$this->gestdocExist($t)) {
|
||
|
|
||
|
$id = $this->createGestdoc($t);
|
||
|
$hashDir = substr(md5($id), 0, 3);
|
||
|
$dir = "$dmsDir/$hashDir";
|
||
|
if (!file_exists($dir)) {
|
||
|
mkdir($dir, 0775);
|
||
|
}
|
||
|
$file = "$id.png";
|
||
|
$image = "$dir/$file";
|
||
|
}
|
||
|
|
||
|
if ($image != null) {
|
||
|
if (!file_exists($dir)) {
|
||
|
$this->dmsRecover($t, $signContent);
|
||
|
} else {
|
||
|
file_put_contents($image, base64_decode($signContent));
|
||
|
}
|
||
|
} else {
|
||
|
$this->dmsRecover($t, $signContent);
|
||
|
}
|
||
|
|
||
|
if ($id != null && strlen($file) > 0) {
|
||
|
$this->ticketGestdoc($t, $id);
|
||
|
$this->updateGestdoc($file, $id);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$this->conn->commit();
|
||
|
return 'OK';
|
||
|
} catch (\Exception $e) {
|
||
|
$this->conn->rollback();
|
||
|
return 'ERROR';
|
||
|
}
|
||
|
}
|
||
|
/** ---------------------------------------------------------------------------------------------- */
|