- Создатель Васильев Антон, отредактировано 12.09.2023
Постановка задачи
Добавить в форму РКК ВнД новый раздел "Инициатор". Раздел должен заполняться информации о текущем пользователе, который создает документ. В разделе должны содержаться следующие поля:
- Инициатор - ФИО текущего пользователя
- Организация - название организации
- Филиал/ГО - вышестоящее подразделение с признаком "обособленное подразделение"
- СП - вышестоящее подразделение с признаком с признаком "самостоятельное подразделение"
- Подразделение - все вышестоящие подразделения в виде иерарахии до обособленого подразделения
- Должность - название должности
- Телефон - внутренний номер
- Табельный номер - табельный номер
Расположение информации в Справочнике организации
Инструмент: Палитра XML
Статус | ГОТОВО |
---|---|
Раздел | Форма |
Комментарий |
Реализация
Результат

Доработать схему
Добавить в схему RkkResourceInternal новые свойства
Схема
<?xml version='1.0' encoding='UTF-8'?> <schemas xmlns="http://www.intertrust.ru/schema/palette/tn-schema"> <schema extends="RkkResource" name="RkkResourceInternal"> <!--...--> <actor name="initiator"/> <actor name="initOrganization"/> <actor name="initBranch"/> <actor name="initDepartment"/> <string name="initHierDepatment"/> <string name="initPost"/> <string name="initPhone"/> <string name="initTabNum"/> <!--...--> <schema> </schemas>
Доработать форму
Добавить раздел инициатор
Форма
Развернуть исходный код
<?xml version='1.0' encoding='UTF-8'?> <ui xmlns="http://www.intertrust.ru/schema/palette/tn-ui"> <form schema-ref="RkkResourceInternal" id="RkkResourceInternalForm" projection="default" showtabs="true"> <appearance widget="tabs"/> <component> <!--...--> <section id="Attributes" name="${ui.form.section.Attributes.name:Реквизиты}"> <component> <!--...--> <section id="initiator" group="true"> <appearance field-layout="horizontal"/> <component> <!-- Раздел слева --> <section id="initiator_left" group="true"> <appearance> <dialog-mode width="49" unit="percent"/> </appearance> <component> <field attribute-ref="initOrganization" name="${ui.form.field.initOrganization.name:Организация:}"> <properties> <read-only> <condition>true</condition> </read-only> </properties> <appearance multiline="true"> <label-style> <style id="tunBorderedField"/> </label-style> </appearance> </field> <field attribute-ref="initBranch" name="${ui.form.field.initBranch.name:Филиал:}"> <properties> <read-only> <condition>true</condition> </read-only> </properties> <appearance multiline="true"> <label-style> <style id="tunBorderedField"/> </label-style> </appearance> </field> <field attribute-ref="initDepartment" name="${ui.form.field.initDepartment.name:СП:}"> <properties> <read-only> <condition>true</condition> </read-only> </properties> <appearance multiline="true"> <label-style> <style id="tunBorderedField"/> </label-style> </appearance> </field> <field attribute-ref="initHierDepatment" name="${ui.form.field.initHierDepatment.name:Подразделение:}"> <properties> <read-only> <condition>true</condition> </read-only> </properties> <appearance multiline="true"> <label-style> <style id="tunBorderedField"/> </label-style> <limit height="3"/> </appearance> </field> </component> </section> <!-- Раздел справа --> <section id="initiator_right" group="true"> <appearance> <label-style width="12" unit="symbol"/> </appearance> <component> <field recalc="true" attribute-ref="initiator" name="${ui.form.field.initiator.name:Инициатор:}"> <properties> <read-only> <condition>true</condition> </read-only> </properties> <appearance> <label-style> <style id="tunBorderedField"/> </label-style> </appearance> </field> <field attribute-ref="wpInitPost" name="${ui.form.field.initPost.name:Должность:}"> <properties> <read-only> <condition>true</condition> </read-only> </properties> <appearance multiline="true"> <label-style> <style id="tunBorderedField"/> </label-style> </appearance> </field> <field attribute-ref="initTabNum" name="${ui.form.field.initTabNum.name:Таб. номер:}"> <properties> <read-only> <condition>true</condition> </read-only> </properties> <appearance multiline="true"> <label-style> <style id="tunBorderedField"/> </label-style> </appearance> </field> <field attribute-ref="initPhone" name="${ui.form.field.initPhone.name:Телефон:}"> <properties> <read-only> <condition>true</condition> </read-only> </properties> <appearance multiline="true"> <label-style> <style id="tunBorderedField"/> </label-style> </appearance> </field> </component> </section> </component> </section> <!--...--> </component> </section> <!--...--> </component> </form> </ui>
Доработать обработчик событий
Добавить в обработчик событий QueryCreate
Обработчик событий
<?xml version='1.0' encoding='UTF-8'?> <schemas xmlns="http://www.intertrust.ru/schema/palette/tn-schema"> <schema extends="RkkResource" name="RkkResourceInternal"> <!--...--> <custom-event-handler lang="JavaScript"><![CDATA[...]]></custom-event-handler> <schema> </schemas>
Код
QueryCreate
Развернуть исходный код
importClass(Packages.ru.intertrust.cmj.rest.tuning.TuningHelper); importClass(Packages.ru.intertrust.cmj.af.so.SOBeard); importClass(Packages.ru.intertrust.cmj.af.so.SOAppointment); importClass(Packages.ru.intertrust.cmj.af.core.AFSession); importClass(Packages.ru.intertrust.cmj.af.core.AFCMDomino); importPackage(Packages.java.lang); importPackage(Packages.java.util); importPackage(Packages.ru.intertrust.cmj.af.so); importClass(Packages.ru.intertrust.cmj.af.utils.DominoUtils); importClass(Packages.ru.intertrust.cmj.af.tuning.impl.AFInstanceContentImpl); importClass(Packages.ru.intertrust.cmj.tunable.object.TunableObjectApplication); importClass(Packages.org.springframework.util.StringUtils); importClass(Packages.ru.intertrust.cmj.af.utils.BeansUtils); importClass(Packages.ru.intertrust.cmj.af.utils.Utils); importClass(Packages.ru.intertrust.cmj.dp.DPApplication); importClass(Packages.ru.intertrust.cmj.af.so.impl.AppointmentHead); importClass(Packages.ru.intertrust.cmj.af.so.SOApplication); function queryCreate(object) { var values = object.tuning().getValues(); var user = AFSession.get().currentUser().getBeard(); //текуший пользователь var org = user.getOrganization().getBeard(); //организация var filial = getParentSeparateUnit(user); //филиал, обособленное подразделение var parentDep = getParentIndependentUnit(user); //самостоятельное подразделение var parentHierarchy = getParentDepartmentHierarchyString(user); //иерархия var post = user.originalData().getPostName(); //должность var tabNum = user.getTabNum(); //табельный номер var phone = AFSession.get().currentUser().getPerson().contactsInfo().getPhoneInternal(); //телефон //запись в поля values.put("initOrganization", TuningHelper.createPropertyValue(org, object.tuning().getSchema().getProperty("initOrg"))); values.put("initBranch", TuningHelper.createPropertyValue(filial, object.tuning().getSchema().getProperty("initBranch"))); values.put("initDepartment", TuningHelper.createPropertyValue(parentDep, object.tuning().getSchema().getProperty("initDepartment"))); values.put("initHierDepatment", TuningHelper.createPropertyValue(parentHierarchy, object.tuning().getSchema().getProperty("initHierDepatment"))); values.put("initiator", TuningHelper.createPropertyValue(user, object.tuning().getSchema().getProperty("initiator"))); values.put("initPost", TuningHelper.createPropertyValue(post, object.tuning().getSchema().getProperty("initPost"))); values.put("initPhone", TuningHelper.createPropertyValue(phone, object.tuning().getSchema().getProperty("initPhone"))); values.put("initTabNum", TuningHelper.createPropertyValue(tabNum, object.tuning().getSchema().getProperty("initTabNum"))); } /** Вычисление вышестоящего Самостоятельного подразделения. Если самостоятельное подразделение не будет вычислено, берется обособленное */ function getParentIndependentUnit(beard) { var parent = getParent(beard); //SOBeard var party = parent.originalData().getParty(); //SOParty if (party instanceof SOUnitStructure) { if (party.isIndependent() || party.isSeparate()) { return parent; } } if (party instanceof SOUnitOrganization) { return parent; } return getParentIndependentUnit(parent); } /** Вычисление вышестоящего Филиала/ГО по признаку Обособленное подразделение. */ function getParentSeparateUnit(beard) { if (beard.originalData().getType().toString().equals("SYS_ROLE")) { var branchFR = beard.originalData().getParty().getHeadOrBranchOffice(); if (branchFR != null) { return branchFR.getBeard(); } } var parent = getParent(beard); //beard.getParent(); //SOBeard var party = parent.originalData().getParty(); //SOParty if (party instanceof SOUnitStructure) { if (party.isSeparate()) { return parent; } } if (party instanceof SOUnitOrganization) { return parent; } return getParentSeparateUnit(parent); } /** Вычисление иерархии подразделений в виде строки */ function getParentDepartmentHierarchyString(beard) { var namesList = new ArrayList(); namesList = getParentDepartmentHierarchy(beard, namesList); //преобразуем в строку var result = ""; for (var i = 0; i < namesList.size(); i++) { var name = namesList.get(i); var shortName = name.length() > 100 ? (org.apache.commons.lang3.StringUtils.left(name, 97) + "...") : name; if (result.equals("")) { result = shortName; } else { result = result + "\n\\" + shortName; } } return result; } /** Вычисление иерархии подразделений до самостоятельного подразделения */ function getParentDepartmentHierarchy(beard, namesList) { var parent = getParent(beard); var party = parent.originalData().getParty(); if (party instanceof SOUnitDepartment) { namesList.add(party.getFullName()); if (party.isSeparate()) { return namesList; } else { return getParentDepartmentHierarchy(parent, namesList); } } else if (party instanceof SOUnitOrganization) { namesList.add(party.getFullName()); return namesList; } else if (party instanceof AppointmentHead) { namesList.add(party.getBeard().originalData().getShortName()); return getParentDepartmentHierarchy(parent, namesList); } return namesList; } /** Получение вышестоящего подразделения/РВЗ */ function getParent(beard) { var parent = beard.getParent(); if (parent != null) { return parent; } var parentDocId = null; var unidArr = beard.getUNID().split(":"); var tnUnid = unidArr[0] + "-TN:" + unidArr[1]; var tunApp = AFSession.get().getApplication(TunableObjectApplication.class); var tnObj = tunApp.getEntityByUNID(tnUnid); if (tnObj != null) { var parentUnit = tnObj.tuning().getValues().get("parentUnit"); if (parentUnit != null && parentUnit.getValues().get("basedocid") != null) { parentDocId = parentUnit.getValues().get("basedocid").getValue(); } } if (parentDocId != null) { var soApp = AFSession.get().getApplication(SOApplication.class); var soObj = soApp.getEntityByUNID(unidArr[0] + ":" + parentDocId); if (soObj != null) { if (soObj instanceof SOParty) { return soObj.getBeard(); } else if (soObj instanceof SOUnitPost && soObj.appointments().getCurrent() != null) { return soObj.appointments().getCurrent().getBeard(); } else { throw ("Ошибка при поиске родительского элемента - soObj " + soObj.getClass().getName()); } } } return null; }