Ф381103151348
************************
import com.haulmont.cuba.core.*
import com.haulmont.cuba.core.entity.*;
import com.haulmont.cuba.core.global.*;
import com.groupstp.rtneo.entity.*;
import com.groupstp.rtneo.service.*;
String id = 'aa478307-8e48-0972-5010-1d3c397eb0ca'
ContragentRealEstate cre = dataManager.load(ContragentRealEstate).id(UUID.fromString(id)).view("_local").optional().orElse(null)
def res = checkRR(cre)
_("RETURN - ${res}")
def checkRR(ContragentRealEstate cre){
def item = dataManager.loadValues('select r.contragentRealEstate.ownType, CASE WHEN r.payOwner is null THEN false ELSE r.payOwner END, r.contragentRealEstate.id, r.contragentRealEstate.contragent.personalAccount, r.renterRecord.contragent.personalAccount from rtneo$RealEstateRenter r where r.renterRecord.id = :cre')
.properties("own", "pay", "creId", "contragent", "rContragent")
.parameter("cre", cre.getId())
.optional()
.orElse(null)
if(item == null){
return dataManager.loadValue('select c.contragent.personalAccount from rtneo$ContragentRealEstate c where c.id = :creId', String.class).parameter("creId", cre.getId()).optional().orElse(null)
}
if(item.getValue('pay'))return item.getValue('contragent')
if(item.getValue('own') > 1){
if(item.getValue('pay')){
return item.getValue('contragent')
}else{
return item.getValue('rContragent')
}
}
if(item.getValue('own') == 1)return checkRR(item.getValue('creId').toString())
}
/**
* Логирование
*/
import com.haulmont.cuba.core.app.serialization.EntitySerializationAPI;
import com.groupstp.rtneo.util.JsonUtil;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
private _(Object obj, String... options){
if(obj == null){log("LOG.ERROR: Object is null!!!");return}
if(options.size() == 0){log(obj)}
for(def option : options){
if(option.equals("str")){log(obj)}
if(option.equals("for")){obj.each({_(it)})}
if(option.equals("json")){
EntitySerializationAPI entitySerializationAPI = AppBeans.get(EntitySerializationAPI.NAME)
try{log(entitySerializationAPI.toJson(obj))}
catch(Exception e){log("LOG.ERROR: JSON entity serialization failed")}
}
if(option.equals("objJson")){
JsonUtil jsonUtil = AppBeans.get(JsonUtil.NAME)
try{log.(jsonUtil.toJson(obj))}
catch(Exception e){log("LOG.ERROR: JSON object serialization failed")}
}
if(option.equals("date")){
DateFormat df = new SimpleDateFormat("dd.MM.yyyy");
try{log(df.format(obj))}
catch(Exception e){log("LOG.ERROR: Failed date format")}
}
}
}
private log(Object obj){log.debug(obj)}