Skip to content
Snippets Groups Projects
Commit 6eadc3e7 authored by Gerhard Bachmaier's avatar Gerhard Bachmaier
Browse files

1068744: Gebiet: Automatische Zuordnung von Firmen

parent 36bc5672
No related branches found
No related tags found
No related merge requests found
......@@ -175,6 +175,12 @@
<entityName>LogHistory_entity</entityName>
<fieldName>LogHistoryProvider</fieldName>
</dependency>
<children>
<entityParameter>
<name>tablenames_param</name>
<valueProcess>%aditoprj%/entity/District_entity/entityfields/loghistories/children/tablenames_param/valueProcess.js</valueProcess>
</entityParameter>
</children>
</entityConsumer>
<entityField>
<name>parentFilter</name>
......
import("system.vars");
import("system.result");
import("Context_lib");
var res = [];
res.push({id: vars.get("$field.DISTRICTID"), tableNames: ["DISTRICT"]});
res = JSON.stringify(res);//currently only strings can be passed as param
result.object(res);
\ No newline at end of file
......@@ -8,6 +8,7 @@
<grantDeleteProcess>%aditoprj%/entity/Organisation_entity/grantDeleteProcess.js</grantDeleteProcess>
<contentTitleProcess>%aditoprj%/entity/Organisation_entity/contentTitleProcess.js</contentTitleProcess>
<afterUiInit>%aditoprj%/entity/Organisation_entity/afterUiInit.js</afterUiInit>
<afterSave>%aditoprj%/entity/Organisation_entity/afterSave.js</afterSave>
<initFilterProcess>%aditoprj%/entity/Organisation_entity/initFilterProcess.js</initFilterProcess>
<useFavorites v="true" />
<iconId>VAADIN:BUILDING</iconId>
......
import("system.logging");
import("system.vars");
import("District_lib");
import("system.neon");
if (vars.get("$local.recordstate") == neon.OPERATINGSTATE_NEW)
{
//Assign this new organisation to all according districts with auto assignment is true
//2nd parameter "undefined" means, that the current user is determined in the function
DistrictUtils.assignDistrictOnServer([], undefined, vars.get("$local.entitydata")["CONTACTID"])
}
\ No newline at end of file
......@@ -3,7 +3,6 @@ import("system.text");
import("system.datetime");
import("system.notification");
import("system.translate");
import("system.logging");
import("Contact_lib");
import("KeywordRegistry_basic");
import("system.vars");
......@@ -68,7 +67,7 @@ DistrictUtils.getDataFromDistrict = function (pDistrictId)
*/
DistrictUtils.getDataFromDistrictContact = function (pDistrictContactId)
{
var arrData = newSelect("DISTRICT_ID, ADVISER_CONTACT_ID")
var arrData = newSelect("DISTRICT_ID, ADVISER_CONTACT_ID, CONTACT_ID")
.from("DISTRICTCONTACT")
.where("DISTRICTCONTACT.DISTRICTCONTACTID", pDistrictContactId)
.arrayRow();
......@@ -83,11 +82,13 @@ DistrictUtils.getDataFromDistrictContact = function (pDistrictContactId)
* @param {Array} pArrDistrictIds <p>
* Array of district-IDs.<br>
* @param {String} pUser=currentUser (optional) <p>
* User that will get the notification, <br>
* if null (not undefined!), no notification<br>
* will be created.<br>
* User who will get the notification, <br>
* User who will start the batch job <br>
* @param {String} pContactId (optional) <p>
* Organisation which should be assigned to all <br>
* according districts with auto assignment is true <br>
*/
DistrictUtils.assignDistrictOnServer = function (pArrDistrictIds, pUser)
DistrictUtils.assignDistrictOnServer = function (pArrDistrictIds, pUser, pContactId)
{
//pUser hat folgendes Format: _____USER_bcdfb521-c7d0-4ef1-8916-78e7d3232046
if (pUser === undefined)
......@@ -96,9 +97,10 @@ DistrictUtils.assignDistrictOnServer = function (pArrDistrictIds, pUser)
.setName("assignDistrict_serverProcess")
.setLocalVariables({
arrDistrictIds : pArrDistrictIds.join(";"),
user : pUser || ""
user : pUser || "",
contactId : pContactId || ""
})
.setUser(pUser)
.setUser(pUser);
process.startAsync(processConfig);
}
......@@ -127,7 +129,7 @@ DistrictUtils.assignDistrict = function (pDistrictId, pAppliedFilter, pContactId
//Einlesen von allen bereits existierenden automatischen Zuordnungen,
//die nicht auf Status 'zur Prüfung' stehen
//Nur notwendig, wenn pContactId leer ist. Ansonsten soll ja gezielt ein neuer Datensatz angelegt werden
var arrExistingIds = []
var arrExistingIds = [];
if (!pContactId)
{
arrExistingIds = new SqlBuilder()
......@@ -150,9 +152,8 @@ DistrictUtils.assignDistrict = function (pDistrictId, pAppliedFilter, pContactId
//Aufbereiten des im JSON-Format übergebenen Filters in eine SQL-Condition
var appliedFilterCondition = JSON.parse(pAppliedFilter).filter;
appliedFilterCondition = JSON.stringify(appliedFilterCondition);
logging.log("appliedFilterCondition: " + appliedFilterCondition);
var sqlCondition = db.toFilterCondition(appliedFilterCondition, "Organisation_entity")
logging.log("sqlCondition: " + sqlCondition)
var sqlCondition = db.toFilterCondition(appliedFilterCondition, "Organisation_entity");
//Einlesen der Contact-IDs zu den Firmen, die gemäß Filter diesem Gebiet zugeordnet sind
var arrOrgContactIds = new SqlBuilder()
.selectDistinct("CONTACT.CONTACTID")
......@@ -162,8 +163,8 @@ DistrictUtils.assignDistrict = function (pDistrictId, pAppliedFilter, pContactId
.leftJoin("CLASSIFICATIONSTORAGE", "CLASSIFICATIONSTORAGE.OBJECT_ROWID = CONTACT.CONTACTID")
.whereIfSet(sqlCondition)
.andIfSet("CONTACT.CONTACTID", pContactId)
.arrayColumn();
logging.log("arrOrgContactIds.length: " + arrOrgContactIds.length)
.arrayColumn();
var insertArray = [];
var colsInsert = [
"DISTRICTCONTACTID",
......@@ -191,7 +192,7 @@ DistrictUtils.assignDistrict = function (pDistrictId, pAppliedFilter, pContactId
for (var j=0; j<arrResponsibleIds.length; j++)
{
//Existiert der Firmen-Betreuer-Datensatz bereits?
var found = 'N'
var found = 'N';
for (var k=0; k<arrExistingIds.length; k++)
{
if (arrExistingIds[k][1] == arrOrgContactIds[i] && arrExistingIds[k][2] == arrResponsibleIds[j][0])
......@@ -393,52 +394,6 @@ DistrictUtils.setDistrictContactStatus = function (pArrIds, pStatus)
}
/**
* This function will assign a new organisation to all districts, which
* - have the property "auto assignment"
* - and are part of the regarding filter
* @param {String} pOrganisationId <p>
* Organisation-ID of the new Organisation<br>
* @param {String} pUserLogin <p>
* login,who created the new organistion<br>
* @return <none> <p>
*/
DistrictUtils.assignOrganisationToDistrict = function (pOrganisationId, pUserLogin)
{
//contactid zur organisationid ermitteln
var contactId = ContactUtils.getOrgContactId(pOrganisationId);
//alle Filter ermitteln, die auf auto-assignment gleich true gesetzt sind
var allAutoDistricts = newSelect("DISTRICTID")
.from("DISTRICT")
.where("DISTRICT.DISTRICT_AUTOADD", 1)
.arrayColumn();
//TODO: pUserLogin noch bis zum Schreiben von date_new durchschleusen
logging.log("pUerLogin: " + pUserLogin)
//Variante 1
for (var i=0; i<allAutoDistricts.length; i++)
{
logging.log("allAutoDistricts[i]: " + allAutoDistricts[i]);
//pro District den kompletten Filter ermitteln
var districtData = DistrictUtils.getDataFromDistrict(allAutoDistricts[i]);
var completeFilter = DistrictUtils.getAppliedFilter(districtData[0], districtData[1])
//logging.log("completeFilter: " + completeFilter)
//prüfen, ob die neue contactid im filter enthalten wäre
//und im Erfolgsfall die Daten in der districtcontact anlegen
//TODO: pUserLogin als 4ten Parameter übergeben. Wenn gefüllt, diesen als USER_NEW/EDIT setzen, sonst den sys.user verwenden
var res = DistrictUtils.assignDistrict(allAutoDistricts[i], completeFilter, contactId);
}
//Variante 2: Aufruf des Server-Prozessen mit allen Gebieten mit Auto-Zuordnung gleich true
//Wirft den gleichen Fehler wie Variante 1
//TODO: Aus dem pUserLogin noch die Employee-ID ermitteln
//DistrictUtils.assignDistrictOnServer(allAutoDistricts, pUserLogin);
}
/**
* This function will notificate the district contact that he/she was assigned
*
......@@ -451,15 +406,18 @@ DistrictUtils.notificateNewDistrictContact = function(pDistrictContactId){
//[0]: DISTRICT_ID, [1]: ADVISER_CONTACT_ID, [2]: CONTACT_ID
var arrayDistrictContact = DistrictUtils.getDataFromDistrictContact(pDistrictContactId);
//get corresponding profile information of the systemalias
var user = tools.getUserByAttribute(tools.CONTACTID, arrayDistrictContact[1], tools.PROFILE_DEFAULT);
var userName = user[tools.NAME];
var districtName = DistrictUtils.getDistrictName(arrayDistrictContact[0]);
var organisationName = ContactUtils.getFullTitleByContactId(arrayDistrictContact[2]);
// Benachrichtigung am Ende der Zuordnungen
description = translate.withArguments("You were assigned as new district contact to district %0 and organisation %1.",
[districtName, organisationName])
notification.addNotification(util.getNewUUID(), text.encodeMS(["Organisation", arrayDistrictContact[2]]), null, null, "DistrictAssigned", notification.PRIO_NORMAL, 2, notification.STATE_UNSEEN, [userName], message, description);
//You can only send a notification, if the user is an employee
if (user)
{
var userName = user[tools.NAME];
var districtName = DistrictUtils.getDistrictName(arrayDistrictContact[0]);
var organisationName = ContactUtils.getFullTitleByContactId(arrayDistrictContact[2]);
// Benachrichtigung am Ende der Zuordnungen
description = translate.withArguments("You were assigned as new district contact to district %0 and organisation %1.",
[districtName, organisationName]);
notification.addNotification(util.getNewUUID(), text.encodeMS(["Organisation", arrayDistrictContact[2]]), null, null, "DistrictAssigned", notification.PRIO_NORMAL, 2, notification.STATE_UNSEEN, [userName], message, description);
}
}
......@@ -7,46 +7,79 @@ import("system.vars");
import("system.notification");
import("District_lib");
var i;
var districtData;
var completeFilter;
var res;
var message;
var description;
var newAssigned = 0;
var unchanged = 0;
var invalid = 0;
var startTime = datetime.date();
var user = vars.get("$local.user");
var arrDistrictIds = vars.get("$local.arrDistrictIds").split(";");
var contactId = vars.get("$local.contactId");
//Alle übergebenen Gebiete bearbeiten
for (var i=0; i<arrDistrictIds.length; i++)
// Do the assignment for all transferred districts
if (vars.get("$local.arrDistrictIds").length > 0 && arrDistrictIds.length > 0)
{
//Pro Gebiet den kompletten hierarchieschen Filter aufbauen
var districtData = DistrictUtils.getDataFromDistrict(arrDistrictIds[i]);
var completeFilter = DistrictUtils.getAppliedFilter(districtData[0], districtData[1])
//Automatische Zuordnung
res = DistrictUtils.assignDistrict(arrDistrictIds[i], completeFilter);
newAssigned += res.newAssigned;
unchanged += res.unchanged;
invalid += res.invalid;
var message;
var description;
var newAssigned = 0;
var unchanged = 0;
var invalid = 0;
var startTime = datetime.date();
//Assign all transferred districts
for (i=0; i<arrDistrictIds.length; i++)
{
//Build the complete hierarchical filter for every district
districtData = DistrictUtils.getDataFromDistrict(arrDistrictIds[i]);
completeFilter = DistrictUtils.getAppliedFilter(districtData[0], districtData[1]);
//Automatic assignment
res = DistrictUtils.assignDistrict(arrDistrictIds[i], completeFilter);
newAssigned += res.newAssigned;
unchanged += res.unchanged;
invalid += res.invalid;
}
if (arrDistrictIds.length == 1)
{
var districtName = DistrictUtils.getDistrictName(arrDistrictIds[0]);
message = translate.withArguments("Assignment of district \"%0\" is completed!", [districtName]);
}
else
message = translate.text("Assignment of all selected districts is completed!");
// Notification at the end of the assignment
description = translate.withArguments("%0 companies were newley assigned. \n" +
"%1 companies are no longer assigned (these assignments got the status 'review'). \n" +
"%2 valid assignments were unchanged.\n" +
"The Process took %3 seconds.",
[newAssigned, invalid, unchanged, Math.round((datetime.date() - startTime) / datetime.ONE_SECOND)]);
notification.addNotification(util.getNewUUID(), null, null, null, "DistrictAssigned", notification.PRIO_NORMAL, 2, notification.STATE_UNSEEN, [user], message, description);
}
if (arrDistrictIds.length == 1)
{
var districtName = DistrictUtils.getDistrictName(arrDistrictIds[0]);
message = translate.withArguments("Assignment of district \"%0\" is completed!", [districtName]);
//Assign a new organisation to all according districts with auto assignment is true
//NOTICE: The new organisation must be part of the filter of the district
if (contactId != "")
{
//Get all filters where auto assingment is true
var allAutoDistricts = newSelect("DISTRICTID")
.from("DISTRICT")
.where("DISTRICT.DISTRICT_AUTOADD", 1)
.arrayColumn();
for (i=0; i<allAutoDistricts.length; i++)
{
//Build the complete filter
districtData = DistrictUtils.getDataFromDistrict(allAutoDistricts[i]);
completeFilter = DistrictUtils.getAppliedFilter(districtData[0], districtData[1]);
//Check if the new contactid is part ot this filter
//if so, write data in table districtcontact
res = DistrictUtils.assignDistrict(allAutoDistricts[i], completeFilter, contactId);
}
}
else
message = translate.text("Assignment of all selected districts is completed!");
// Benachrichtigung am Ende der Zuordnungen
description = translate.withArguments("%0 companies were newley assigned. \n" +
"%1 companies are no longer assigned (these assignments got the status 'review'). \n" +
"%2 valid assignments were unchanged.\n" +
"The Process took %3 seconds.",
[newAssigned, invalid, unchanged, Math.round((datetime.date() - startTime) / datetime.ONE_SECOND)])
notification.addNotification(util.getNewUUID(), null, null, null, "DistrictAssigned", notification.PRIO_NORMAL, 2, notification.STATE_UNSEEN, [user], message, description);
\ No newline at end of file
......@@ -17,12 +17,6 @@ if (sqlAction != 'X')
(new LogHistoryExecutor(tableName, userLogin, columns, newvalues, oldvalues, timestamp, sqlAction, id)).execute();
}
//Ticketnummer: 1066031
//if (sqlAction == 'I' && tableName == 'ORGANISATION')
//{
// DistrictUtils.assignOrganisationToDistrict(id, userLogin);
//}
if(sqlAction == 'I' && tableName == 'DISTRICTCONTACT'){
DistrictUtils.notificateNewDistrictContact(id);
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment