import com.haulmont.cuba.core.global.*
import com.groupstp.rtneo.entity.*
import com.groupstp.rtneo.service.*
import java.text.SimpleDateFormat
import java.util.*
import java.util.stream.*
import com.haulmont.cuba.core.global.ViewRepository;
import java.util.stream.Collectors
import java.util.function.*;
import java.util.function.Predicate
import java.util.Map.Entry
import java.text.SimpleDateFormat;
import groovy.transform.InheritConstructors;
import groovy.transform.Field
import de.diedavids.cuba.runtimediagnose.groovy.*
Predicators.log = log
//GroovyConsoleLogger log = log
_(
"isTWO - Проверка что всего два контрагента с дублями объектов\n"+
"PERS&IND - Один физ и один ИП\n"+
"oneLogin - Только один заходил\n"+
"INDLogin - Заходил ИП-шник\n"+
"samePersonName - Одинаковые имя физ лица и руководителя ИП\n"+
"oneCrePers - Берет физ лиц, и проверяет что у них только один объект\n"+
"PERSNoPyment - Физ лицо Не платил\n"+
"PERSCreateAdmin - Физ лицо, и объект создан admin\n"+
"PERSNoContract - Договора договоров созданных не a.kotvinskiy@groupstp.ru\n"
)
Contragent.mixin ParamsMix
count = 0;
startGroupRealEstate()
//startForGroupContragent()
_(count)
void check(GroupRealEstate group){
AbstractCleaner cleaner = new RemoveNoFilter()
cleaner.log = log
cleaner.dataManager = dataManager
if(checkPredicate(Predicators.instance.analiseGroupRealEstate, group)){
group.getReport()
if(cleaner.clean(group)){
log.debug("***")
count++
}
}
}
void startGroupRealEstate(){
def df = new SimpleDateFormat("dd-MM-yyyy")
UnaryOperator<ContragentRealEstate> fSetCrePeriod = {
e ->
if(e.getValidityFrom() == null)e.setValidityFrom(df.parse('01-01-2000'))
if(e.getValidityTo() == null)e.setValidityTo(df.parse('01-01-2119'))
return e
}
def i = 0
def queryRes = dataManager.load(ContragentRealEstate.class)
.query('select distinct cre from rtneo$EntityesTemporarySet t join rtneo$ContragentRealEstate cre on cre.id = t.entityId where cre.realEstate.cadastralNumber is not null and not cre.realEstate.cadastralNumber = \'Без к/н\' and cre.contragent.name is not null and t.setName = \'doubleCRE_16-03-21_2\' order by cre.realEstate.id, cre.contragent.name')// and cre.realEstate.cadastralNumber = \'38:36:000034:20790\'
.view(getViewCre())
// .firstResult(i*100)
// .maxResults(100)
.list().stream()
.map{e -> fSetCrePeriod.apply(e)}
.collect(Collectors.groupingBy({e->e.getRealEstate()}, Collectors.groupingBy({e->e.getContragent()})))
List<GroupRealEstate> groups = [];
for(def realEstate : queryRes.entrySet()){
Group group = new GroupRealEstate(realEstate.getKey())
//Можно запихать в коллекцию или класс
group.setLog(log)
group.setDataManager(dataManager)
for(def contragent : realEstate.getValue().entrySet()){
for(def item : contragent.getValue()){
group.addCre(contragent.getKey(), item)
}
}
groups.add(group)
}
groups.each{check(it)}
}
void startForGroupContragent(){
def i = 0
def queryRes = dataManager.load(ContragentRealEstate.class)
.query('select distinct re from rtneo$EntityesTemporarySet t join rtneo$ContragentRealEstate cre on cre.id = t.entityId join rtneo$ContragentRealEstate re on re.contragent.id = cre.contragent.id where cre.realEstate.cadastralNumber is not null and not cre.realEstate.cadastralNumber = \'Без к/н\' and cre.contragent.name is not null and t.setName = \'doubleCRE_16-03-21_2\' and cre.realEstate.cadastralNumber = \'38:36:000034:18414\' order by cre.realEstate.id, cre.contragent.name')
.view(getViewCre())
// .firstResult(i*10000)
// .maxResults(10000)
.list().stream()
.collect(Collectors.groupingBy({e->e.getContragent().getName()}, Collectors.groupingBy({e->e.getRealEstate().getCadastralNumber()})))
List<GroupContragent> groups = [];
for(def contragent : queryRes.entrySet()){
GroupContragent group = new GroupContragent(contragent.getKey())
group.setLog(log)
for(def re : contragent.getValue().entrySet()){
for(def item : re.getValue()){
group.addCre(item.getContragent(), item)
}
}
groups.add(group)
}
groups.each{setup(it)}
_(count)
}
def getContract(GroupContragent group){
// return dataManager.loadValue('select count(c) from rtneo$Contract c where c.contragent.id in :contragents and not (c.createdBy = \'a.kotvinskiy@groupstp.ru\' or c.createdBy = \'a.honyakov@groupstp.ru\' or c.createdBy = \'admin\')', int)
return dataManager.loadValue('select count(c) from rtneo$Contract c where c.contragent.id in :contragents', int)
.parameter("contragents", group.getCres().entrySet()
.stream()
.map{e -> e.getKey().getId()}
.collect(Collectors.toList()))
.optional().orElse(0)
}
//GLOBAL CLASS
class GroupMix{}
class ParamsMix{
boolean isLogin;
boolean isPayment;
boolean isContract;
int countCRE;
}
interface Group{
void getReport()
void addCre(Contragent contragent, ContragentRealEstate cre)
}
abstract class AbstractGroup implements Group{
def log;
def dataManager;
void addCre(Contragent contragent, ContragentRealEstate cre){
if(cres.get(contragent) == null){
HashMap props = getProps(contragent)
contragent.isLogin = props.get("login")
contragent.isPayment = props.get("payment")
contragent.countCRE = props.get("cre")
contragent.isContract = props.get("contracts")
cres.put(contragent, [])
}
cres.get(contragent).add(cre)
}
HashMap getProps(Contragent contragent){
def prop = ["login", "payment", "cre", "contracts"]
String q = 'select '+
'(select count(s) from sec$SessionLogEntry s where c.user = s.user), '+
'(select count(p) from rtneo$Payment p where p.inn = c.inn), '+
'(select count(cre) from rtneo$ContragentRealEstate cre where cre.contragent.id = c.id), '+
'(select count(ct) from rtneo$Contract ct where ct.contragent.id = c.id and not ct.createdBy = \'a.kotvinskiy@groupstp.ru\') '+
'from rtneo$Contragent c where c.id = :contragentId'
def values = dataManager.loadValues(q)
.properties(prop)
.parameter("contragentId", contragent.getId()
)
.optional()
.orElse(null)
return prop.stream().collect(Collectors.toMap({e -> e}, {e -> values == null ? 0 : values.getValue(e)}))
}
}
@InheritConstructors
class GroupContragent extends AbstractGroup{
String name;
//Контрагенты с объектами
HashMap<Contragent, List<ContragentRealEstate>> cres = [:];
GroupContragent(String name){
this.name = name
}
void getReport(){
log.debug(name)
for(def cre : cres.entrySet()){
log.debug(" Contragent - ${cre.getKey().getId()}, user - ${cre.getKey().getUser()}")
cre.getValue().each{log.debug(" ${it.getId()} - ${it.getRealEstate().getCadastralNumber()}")}
}
log.debug("===================================================================================")
}
}
@InheritConstructors
class GroupRealEstate extends AbstractGroup{
def df = new SimpleDateFormat("dd-MM-yyyy")
RealEstate realEstate;
HashMap<Contragent, List<ContragentRealEstate>> cres = [:];
GroupRealEstate(RealEstate realEstate){
this.realEstate = realEstate
}
void getReport(){
log.debug(realEstate.getCadastralNumber())
for(def cre : cres.entrySet()){
log.debug(" Contragent(${cre.getKey().getType()}) - ${cre.getKey().getName()}")
log.debug(" [inn - ${cre.getKey().getInn()}; createdBy - ${cre.getKey().getCreatedBy()}; isLogin - ${cre.getKey().isLogin}; headPersonName - ${cre.getKey().headPersonName}]")
log.debug(" [isLogin - ${cre.getKey().isLogin}; isPayment - ${cre.getKey().isPayment}; countCRE - ${cre.getKey().countCRE}; isContract - ${cre.getKey().isContract}]")
for(def item : cre.getValue()){
log.debug(" ContragentRealEstate - ${item.getId()}")
log.debug(" [share - ${item.getShare()}]")
log.debug(" [from - ${item.getValidityFrom() == null ? null : df.format(item.getValidityFrom())}]")
log.debug(" [to - ${item.getValidityTo() == null ? null : df.format(item.getValidityTo())}]")
log.debug(" [own - ${item.getOwnType()}]")
log.debug(" [createdBy - ${item.createdBy}]")
log.debug("")
}
}
log.debug("===================================================================================")
}
}
//@interface LogConsole {
// GroovyConsoleLogger log()
//}
//@LogConsole(log = log)
abstract class AbstractCleaner{
GroovyConsoleLogger log
DataManager dataManager
boolean clean(GroupRealEstate group){
BiPredicate<LinkedHashMap<String, Predicate<Entry<Contragent, List<ContragentRealEstate>>>>, Entry<Contragent, List<ContragentRealEstate>>> applyFilter = {
l, e ->
l.entrySet().stream().map{p -> p.getValue() as Predicate<Entry<Contragent, List<ContragentRealEstate>>>}.allMatch{p -> p.test(e as Entry)}
}
def persMap = group.getCres()
.entrySet()
.stream()
.filter{v -> applyFilter.test(getFilters(group), v)}
.collect(Collectors.toList())
log.debug(persMap)
if(persMap.isEmpty())return false
Stream.of(persMap.stream().findFirst().get())
// persMap.stream()
.peek{v -> v.getKey().contracts.each{log.debug(it)}}
// .peek{v -> v.getKey().contracts.each{dataManager.remove(it)}}
.peek{v -> v.getValue().each{log.debug(it)}}
// .peek{v -> v.getValue().each{dataManager.remove(it)}}
.peek{v -> log.debug(v.getKey())}
// .peek{v -> dataManager.remove(v.getKey())}
.count()
return true
}
abstract def getFilters(GroupRealEstate group);
}
@InheritConstructors
class FirstOldRemover extends AbstractCleaner{
def getFilters(GroupRealEstate group){
LinkedHashMap<String, Predicate<Entry<Contragent, List<ContragentRealEstate>>>> pred = [:]
pred.put("isPayment", {
v ->
!Boolean.TRUE.equals(v.getKey().isPayment)
})
pred.put("CreAdmin", {
v ->
v.getValue().stream().anyMatch{cre -> cre.createdBy.equals("admin")}
})
pred.put("isContract", {
v ->
!Boolean.TRUE.equals(v.getKey().isContract)
})
pred.put("isLogin", {
v ->
!Boolean.TRUE.equals(v.getKey().isLogin)
})
return pred
}
}
@InheritConstructors
class RemoveIndAndPers extends AbstractCleaner{
def getFilters(GroupRealEstate group){
LinkedHashMap<String, Predicate<Entry<Contragent, List<ContragentRealEstate>>>> pred = [:]
pred.put("isPayment", {
v ->
!Boolean.TRUE.equals(v.getKey().isPayment)
})
pred.put("CreAdmin", {
v ->
v.getValue().stream().anyMatch{cre -> cre.createdBy.equals("admin")}
})
pred.put("isContract", {
v ->
!Boolean.TRUE.equals(v.getKey().isContract)
})
pred.put("isLogin", {
v ->
!Boolean.TRUE.equals(v.getKey().isLogin)
})
//Имя ИП и физ лица совпадают
pred.put("isDoubleContragent", {
v ->
group.getCres().entrySet().stream()
.map{it.getKey()}
.filter{!it.id.equals(v.getKey().id)}
// .filter{(v.getKey().headPersonName != null && it.name != null) || (v.getKey().name != null && it.headPersonName != null)}
.anyMatch{((v.getKey().headPersonName != null && it.name != null) && (v.getKey().headPersonName?.toUpperCase().equals(it.name?.toUpperCase()))) ||
((v.getKey().name != null && it.headPersonName != null) && (v.getKey().name?.toUpperCase().equals(it.headPersonName?.toUpperCase())))}
})
return pred
}
}
@InheritConstructors
class RemovePers extends AbstractCleaner{
def getFilters(GroupRealEstate group){
LinkedHashMap<String, Predicate<Entry<Contragent, List<ContragentRealEstate>>>> pred = [:]
pred.put("isPayment", {
v ->
!Boolean.TRUE.equals(v.getKey().isPayment)
})
pred.put("CreAdmin", {
v ->
v.getValue().stream().anyMatch{cre -> cre.createdBy.equals("admin") || cre.createdBy.startsWith("dataminer") || cre.createdBy.startsWith("m.solomatov")}
})
pred.put("isContract", {
v ->
!Boolean.TRUE.equals(v.getKey().isContract)
})
pred.put("isLogin", {
v ->
!Boolean.TRUE.equals(v.getKey().isLogin)
})
//Отрефакторить!!!
//Сравнивает имя физ лица и владельца ИП
// pred.put("isDoublePers", {
// v ->
// group.getCres().entrySet().stream()
// .map{it.getKey()}
// .filter{!it.id.equals(v.getKey().id)}
// .anyMatch{
// (v.getKey().name != null && it.name != null)
// && v.getKey().name.toUpperCase().equals(it.name.toUpperCase())
// }
// })
// //Сравнивает имена
// pred.put("chekForName",{
// v ->
// group.getCres().entrySet().stream()
// .map{it.getKey()}
// .filter{!it.id.equals(v.getKey().id)}
// .filter{it.name != null}
// .map{it.name as String}
// .map{it.toUpperCase().replace("ИП ", "")}
// .anyMatch{v.getKey().name != null && it.equals(v.getKey().name.toUpperCase().replace("ИП ", ""))
// }
// })
//Сравнивает имена с перестановкой
Function<String, List<String>> fStrToList = {t->
if(t == null)return new ArrayList<>()
Stream.of(t.toUpperCase().replace("ИП ", "").replace(" ", " ").split(" "))
.map{it.trim()}
.peek{log.debug(it)}
.collect(Collectors.toList())}
pred.put("chekForName2",{
v ->
group.getCres().entrySet().stream()
.map{it.getKey()}
.filter{!it.id.equals(v.getKey().id)}
.anyMatch{fStrToList.apply(v.getKey().name).retainAll(fStrToList.apply(it.name))
}.equals(false)
})
return pred
}
}
@InheritConstructors
class RemoveNoFilter extends AbstractCleaner{
def getFilters(GroupRealEstate group){
LinkedHashMap<String, Predicate<Entry<Contragent, List<ContragentRealEstate>>>> pred = [:]
return pred
}
}
@Singleton(lazy=true)
class Predicators{
static LinkedHashMap<String, Predicate<GroupContragent>> pred = [:]
static GroovyConsoleLogger log
static{
loadPred()
}
//Загружаем все предикаты в одну коллекцию, при первом обращении
static void loadPred(){
BiPredicate<ContragentRealEstate, ContragentRealEstate> fCrossPeriod = {
v, v1 ->
if(v == null)return false
if(v1 == null)return false
v.validityFrom<v1.validityTo && v.validityTo>v1.validityFrom
}
//Проверка что всего два контрагента с дублями объектов
pred.put("isTWO", {
e-> e.getCres().size() == 2
})
pred.put(">1", {
e-> e.getCres().size() > 1
})
pred.put(">2", {
e-> e.getCres().size() > 2
})
//Один физ и один ИП
pred.put("PERS&IND", {
e-> e.getCres().entrySet()
.stream()
.map{v -> v.getKey().getType()}
.filter{v-> v.equals(ContragentType.PERSONAL) || v.equals(ContragentType.INDIVIDUAL)}
.collect(Collectors.toSet())
.size() > 1
})
pred.put("PERS&ORG", {
e-> e.getCres().entrySet()
.stream()
.map{v -> v.getKey().getType()}
.filter{v-> v.equals(ContragentType.PERSONAL) || v.equals(ContragentType.ORGANISATION)}
.collect(Collectors.toSet())
.size() > 1
})
pred.put("PERS", {
e-> e.getCres().entrySet()
.stream()
.map{v -> v.getKey().getType()}
.filter{v-> v.equals(ContragentType.PERSONAL)}
.collect(Collectors.toList())
.size() > 1
})
//Только один заходил
pred.put("oneLogin", {
e-> e.getCres().entrySet()
.stream()
.filter{v -> v.getKey().isLogin}
.count() == 1
})
//Ни кто не заходил
pred.put("noLogin", {
e-> e.getCres().entrySet()
.stream()
.filter{v -> v.getKey().isLogin}
.count() == 0
})
//Заходил ИП-шник
pred.put("INDLogin", {
e-> e.getCres().entrySet()
.stream()
.map{v -> v.getKey()}
.filter{v -> v.isLogin && v.getType().equals(ContragentType.INDIVIDUAL)}
.count() == 1
})
//Одинаковые имя физ лица и руководителя ИП
pred.put("samePersonName", {
e-> e.getCres().entrySet()
.stream()
.map{v -> v.getKey()}
.map{v -> v.getType().equals(ContragentType.INDIVIDUAL) || v.getType().equals(ContragentType.ORGANISATION) ? v.headPersonName : v.name}
.collect(Collectors.toSet())
.size() == 1
})
pred.put("sameName", {
e-> e.getCres().entrySet()
.stream()
.map{v -> v.getKey()}
.map{v -> v.name}
.collect(Collectors.toSet())
.size() == 1
})
//Берет физ лиц, и проверяет что у них только один объект
pred.put("oneCrePers", {
e-> e.getCres().entrySet()
.stream()
.filter{v -> v.getKey().getType().equals(ContragentType.PERSONAL)}
.allMatch{v -> v.getValue().size() == 1}
})
//Физ лицо Не платил
pred.put("PERSNoPyment", {
e-> e.getCres().entrySet()
.stream()
.filter{v -> v.getKey().getType().equals(ContragentType.PERSONAL)}
.allMatch{v -> !Boolean.TRUE.equals(v.getKey().isPayment)}
})
//Физ лицо, и объект создан admin
pred.put("PERSCreateAdmin", {
e-> e.getCres().entrySet()
.stream()
.filter{v -> v.getKey().getType().equals(ContragentType.PERSONAL)}
.allMatch{v -> v.getValue().stream().anyMatch{cre -> cre.createdBy.equals("admin") || cre.createdBy.startsWith("dataminer") || cre.createdBy.startsWith("m.solomatov")}}
})
//Договора договоров созданных не a.kotvinskiy@groupstp.ru
pred.put("PERSNoContract", {
e-> e.getCres().entrySet()
.stream()
.filter{v -> v.getKey().getType().equals(ContragentType.PERSONAL)}
.allMatch{v -> !Boolean.TRUE.equals(v.getKey().isContract)}
})
pred.put("PERSNoLogin", {
e-> e.getCres().entrySet()
.stream()
.filter{v -> v.getKey().getType().equals(ContragentType.PERSONAL)}
.allMatch{v -> !Boolean.TRUE.equals(v.getKey().isLogin)}
})
//Физ лицо Не платил - Любой
pred.put("PERSNoPymentAny", {
e-> e.getCres().entrySet()
.stream()
.filter{v -> v.getKey().getType().equals(ContragentType.PERSONAL)}
.anyMatch{v -> !Boolean.TRUE.equals(v.getKey().isPayment)}
})
//Физ лицо, и объект создан admin - Любой
pred.put("PERSCreateAdminAny", {
e-> e.getCres().entrySet()
.stream()
.filter{v -> v.getKey().getType().equals(ContragentType.PERSONAL)}
.anyMatch{v -> v.getValue().stream().anyMatch{cre -> cre.createdBy.equals("admin")}}
})
//Договора договоров созданных не a.kotvinskiy@groupstp.ru - Любой
pred.put("PERSNoContractAny", {
e-> e.getCres().entrySet()
.stream()
.filter{v -> v.getKey().getType().equals(ContragentType.PERSONAL)}
.anyMatch{v -> !Boolean.TRUE.equals(v.getKey().isContract)}
})
//Физ лицо не заходил - Любой
pred.put("PERSNoLoginAny", {
e-> e.getCres().entrySet()
.stream()
.filter{v -> v.getKey().getType().equals(ContragentType.PERSONAL)}
.anyMatch{v -> !Boolean.TRUE.equals(v.getKey().isLogin)}
})
//Пересечение периодов
pred.put("crossPeriod", {
e->
def list = e.getCres().entrySet()
.stream()
.map{v -> v.getValue()}
.collect({new ArrayList<>()}, {b, a->b.addAll(a)}, {b, a->b.addAll(a)})
return list.stream()
// .map{v -> fSetCrePeriod.apply(v)}
.anyMatch{v -> list.stream()
// .map{v1 -> fSetCrePeriod.apply(v1)}
.filter{v1 -> !(v.id.equals(v1.id))}
.anyMatch{v1 ->fCrossPeriod.test(v,v1)}
}.equals(true)
})
//Доля более 1
pred.put("share > 1", {
e->
def list = e.getCres().entrySet()
.stream()
.map{v -> v.getValue()}
.collect({new ArrayList<>()}, {b, a->b.addAll(a)}, {b, a->b.addAll(a)})
return list.stream().map{it.share == null ? BigDecimal.ONE : it.share as BigDecimal}.reduce{x, y -> x.add(y)}.orElse(0.0)>1.0
})
pred.put("chekForName",{
List<Contragent> contragents = it.getCres().entrySet()
.stream()
.map{it.getKey()}
.filter{!it.getType().equals(ContragentType.ORGANISATION)}
.collect(Collectors.toList())
return contragents.stream()
.filter{it.name != null}
.map{it.name as String}
.map{it.toUpperCase().replace("ИП ", "")}
.collect(Collectors.toSet()).size() < contragents.size()
})
}
private LinkedHashMap<String, Predicate<GroupContragent>> getFromPred(LinkedList<String> list){
return list.stream()
.collect(Collectors.toMap(
{e -> e},
{e-> pred.get(e)},
{oldValue, newValue -> oldValue},
{new LinkedHashMap<>()}))
}
//Разные отборы, какие предикаты выполнять
LinkedHashMap<String, Predicate<GroupContragent>> getNoneCheckGroupRealEstate(){
LinkedList<String> list = [">1", "crossPeriod", "share > 1"]
return getFromPred(list)
}
LinkedHashMap<String, Predicate<GroupContragent>> getAnaliseGroupRealEstate(){
LinkedList<String> list = [">1", "crossPeriod", "share > 1"]
return getFromPred(list)
}
LinkedHashMap<String, Predicate<GroupContragent>> getRemovedGroupRealEstate(){
LinkedList<String> list = ["isTWO", "PERS", "sameName", "PERSNoPymentAny", "PERSCreateAdminAny", "PERSNoContractAny", "PERSNoLoginAny"]
return getFromPred(list)
}
LinkedHashMap<String, Predicate<GroupContragent>> getRemovedGroupRealEstateOneFilter(){
LinkedList<String> list = ["PERSNoPyment", "PERSCreateAdmin", "PERSNoContract", "PERSNoLogin"]
return getFromPred(list)
}
LinkedHashMap<String, Predicate<GroupContragent>> getRemovedGroupRealEstate_53(){
LinkedList<String> list = ["isTWO", "PERS&ORG", "PERSNoPyment", "PERSCreateAdmin", "PERSNoContract", "PERSNoLogin"]
return getFromPred(list)
}
LinkedHashMap<String, Predicate<GroupContragent>> getRemovedGroupRealEstate_62(){
LinkedList<String> list = ["isTWO", "PERS&IND", "samePersonName", "PERSNoPyment", "PERSCreateAdmin", "PERSNoContract", "PERSNoLogin"]
return getFromPred(list)
}
LinkedHashMap<String, Predicate<GroupContragent>> getRemovedGroupRealEstate_536(){
LinkedList<String> list = ["isTWO", "PERS&IND", "oneLogin", "INDLogin", "samePersonName", "oneCrePers", "PERSNoPyment", "PERSCreateAdmin", "PERSNoContract"]
return getFromPred(list)
}
LinkedHashMap<String, Predicate<GroupContragent>> getDeleteRealEstate(){
return getFromPred([])
}
}
//GLOBAL
//Проверяет что все предикаты возвращают true
boolean checkPredicate(LinkedHashMap<String, Predicate<GroupContragent>> preds, Group group, boolean viewFalse = false){
LinkedList<String> messages = []
boolean match = preds
.entrySet()
.stream()
.allMatch{e->
boolean is = ((Predicate<GroupContragent>)e.getValue()).test(group)
if(is || viewFalse)messages.add("${e.getKey()} - ${is}")
return is
}
if(match)messages.each{log.debug(it)}
return match
}
def getViewCre(){
ViewRepository vRep = AppBeans.get(ViewRepository.NAME)
return vRep.getView(ContragentRealEstate.class, "_local")
.addProperty("contragent", vRep.getView(Contragent.class, "_minimal")
.addProperty("user", vRep.getView(ExtUser.class, "_minimal"))
.addProperty("contracts", vRep.getView(Contract.class, "_minimal"))
.addProperty("name")
.addProperty("type")
.addProperty("inn")
.addProperty("createdBy")
.addProperty("headPersonName"))
.addProperty("realEstate", vRep.getView(RealEstate.class, "_minimal")
.addProperty("cadastralNumber"))
.addProperty("share")
.addProperty("validityFrom")
.addProperty("validityTo")
.addProperty("ownType")
.addProperty("createdBy")
}
/**
* Логирование
*/
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 log2(Object obj){log.debug(obj)}
private log(Object obj){log.result.append("${obj}\n")}