import com.groupstp.rtneo.entity.*;
import com.haulmont.cuba.core.global.*;
import com.groupstp.rtneo.service.*;
DataManager dataManager = AppBeans.get(DataManager.NAME);
def list = dataManager.loadValues('select cre, cy.containerYard.code, c.number from rtneo$Contract c join c.positions cp join cp.contragentRealEstate cre join cp.containerYards cy where c.contragent.id = \'bd452e2e-f7a0-5deb-a52f-a14c52f29f8e\' order by cre')
.properties("cre", "cyCode", "contract")
.list()
===============================================================
import com.groupstp.rtneo.entity.*;
import com.haulmont.cuba.core.global.*;
import com.groupstp.rtneo.service.*;
DataManager dataManager = AppBeans.get(DataManager.NAME);
def list = dataManager.loadValues('select c.number, cp.contragentRealEstate, cy.contragentRealEstate.realEstate.name, cy.contragentRealEstate.realEstate.address, cy.contragentRealEstate.category.name , cy.containerYard.code from rtneo$Contract c join c.positions cp join cp.containerYards cy where c.contragent.id = \'bd452e2e-f7a0-5deb-a52f-a14c52f29f8e\' order by c.createTs, cp.contragentRealEstate')
.properties("contract", "cp", "realEstateName", "realEstateAddress", "category", "containerYardCode")
.list()
def h = [:]
for(def item : list){
def cy = []
cy.push([
"realEstateName":item.getValue("realEstateName"),
"realEstateAddress":item.getValue("realEstateAddress"),
"category":item.getValue("category"),
"containerYardCode":item.getValue("containerYardCode")])
if(h[item.getValue("contract")] == null){
h[item.getValue("contract")] = [(item.getValue("cp")):cy]
}else{
if(h[item.getValue("contract")][item.getValue("cp")]==null){
h[item.getValue("contract")][item.getValue("cp")] = cy
}else{
h[item.getValue("contract")][item.getValue("cp")] += cy
}
}
}
def currentContract = h["1"];
h.remove("1")
for(def currentCY : currentContract){
log.debug(currentCY)
for(def contracts : h){
log.debug(contracts)
}
}
return h;
==================================================================
import com.groupstp.rtneo.entity.*;
import com.haulmont.cuba.core.global.*;
import com.groupstp.rtneo.service.*;
return getHistory()
def getHistory(){
DataManager dataManager = AppBeans.get(DataManager.NAME);
def cpcy = ''
def list = dataManager.loadValues('select c.number, cp.contragentRealEstate, cy.contragentRealEstate.realEstate.name, cy.contragentRealEstate.realEstate.address, cy.contragentRealEstate.category.name , cy.containerYard.code from rtneo$Contract c join c.positions cp join cp.containerYards cy where c.contragent.id = \'bd452e2e-f7a0-5deb-a52f-a14c52f29f8e\' order by c.createTs, cp.contragentRealEstate')
.properties("contract", "cp", "realEstateName", "realEstateAddress", "category", "containerYardCode")
.list()
def h = [:]
for(def item : list){
def cy = []
cy.push([
"realEstateName":item.getValue("realEstateName"),
"realEstateAddress":item.getValue("realEstateAddress"),
"category":item.getValue("category"),
"containerYardCode":item.getValue("containerYardCode")])
if(h[item.getValue("contract")] == null){
h[item.getValue("contract")] = [(item.getValue("cp").toString()):cy]
}else{
if(h[item.getValue("contract")][item.getValue("cp").toString()]==null){
h[item.getValue("contract")][item.getValue("cp").toString()] = cy
}else{
h[item.getValue("contract")][item.getValue("cp").toString()] += cy
}
}
}
def currentNumberContract = "2"
def currentContract = h[currentNumberContract];
h.remove(currentNumberContract)
def resHistory = []
for(def currentCY : currentContract){
for(def contracts : h){
if(contracts.getValue().get(currentCY.getKey()) != null){
log.debug(contracts.getKey())
// log.debug(currentCY.getValue())
log.debug(contracts.getValue().get(currentCY.getKey()))
log.debug( currentCY.getValue().equals( contracts.getValue().get( currentCY.getKey() ) ) )
if(!currentCY.getValue().equals( contracts.getValue().get( currentCY.getKey() ) )){
def item = contracts.getValue()[currentCY.getKey()]
def pos = [:]
log.debug(item['realEstateName'].get(0))
pos = [
realEstateName:item['realEstateName'].get(0),
cadastralNumber:'',
address:item['realEstateAddress'].get(0),
startFrom:'',
endBefore:'',
containerYardNumber:item["containerYardCode"].get(0),
n:''
]
log.debug("added>> ${pos}")
resHistory.push(pos)
}
}
}
}
return resHistory;
}