MyTetra Share
Делитесь знаниями!
removeDuplicatesCREandContragent.groovy
Время создания: 09.12.2019 16:00
Раздел: INFO - JOB - CUBA - GroovyScripts
Запись: wwwlir/Tetra/master/base/157587840474khrar35r/text.html на raw.githubusercontent.com

import com.groupstp.rtneo.entity.*

import com.haulmont.cuba.core.global.*


DataManager dataManager = AppBeans.get(DataManager.NAME)


ViewRepository vRep = AppBeans.get(ViewRepository.NAME)


View realEstateView = vRep.getView(RealEstate.class, '_base');

realEstateView.addProperty("contragents");


View contragentRealEstateView = vRep.getView(ContragentRealEstate.class, '_base');

contragentRealEstateView.addProperty("contragent");

contragentRealEstateView.addProperty("livingArea");


def startDate = Date.parse( 'yyyy-MM-dd', '2019-11-10')


def reList = dataManager.load(RealEstate.class)

.query('select distinct re from rtneo$RealEstate re join re.contragents c where c.createTs >:dateStart and c.createdBy like \'%dataminer%\' and c.contragent.name like \'%ИРКУТСКАЯ ОБЛАСТНАЯ ИНФЕКЦИОННАЯ КЛИНИЧЕСКАЯ БОЛЬНИЦА%\' order by re.cadastralNumber, re.createTs asc')

.parameter('dateStart', startDate)

.view(realEstateView)

.list()


log.debug('Всего ' + reList.size() + ' объектов')

def count = 0;

def previousINN = null

def previousName = null

for(def re:reList)

{

def creInRe = re.contragents

// def previousName = null

def previousLivingArea = null

// def previousINN = null

log.debug('re: ' + re.cadastralNumber + ', всего creInRe: ' + creInRe.size())

for(def cre:creInRe)

{

def reloadedCRE = null

try

{


reloadedCRE = dataManager.load(ContragentRealEstate.class)

.id(cre.id)

.view(contragentRealEstateView)

.one()

}

catch (e)

{}

if(reloadedCRE != null)

{

def contragent = reloadedCRE.contragent

def area = reloadedCRE.livingArea==null?reloadedCRE.calculationAmount:reloadedCRE.livingArea

log.debug('re: ' + re.cadastralNumber + ', cre: ' + reloadedCRE.id + ', ' + contragent.name)

log.debug(">> ${contragent.name}=${previousName} AND ${reloadedCRE.livingArea}=${previousLivingArea} AND ${contragent.inn}=${previousINN} <<")

if(contragent.name.equals(previousName) && area == previousLivingArea && contragent.inn == previousINN)

{

count++

//log.debug('будет удален contragent: ' + contragent.id + ', ' + contragent.name + ', cre ' + reloadedCRE.id)

try

{

//dataManager.remove(contragent)

log.debug('удален contragent: ' + contragent.id + ', ' + contragent.name + ', cre ' + reloadedCRE.id)

}

catch(def ex)

{

log.debug('не удалось удалить contragent: ' + contragent.id + ', ' + contragent.name)

}

}

log.debug("--------------------${area}")

previousName = contragent.name

previousLivingArea = area

previousINN = contragent.inn

}

}

}

log.debug("count is ${count}")

Так же в этом разделе:
 
MyTetra Share v.0.65
Яндекс индекс цитирования