import com.groupstp.rtneo.entity.*;
import com.haulmont.cuba.core.entity.*;
import com.haulmont.cuba.core.global.*;
import com.groupstp.rtneo.service.*;
import com.groupstp.rtneo.core.bean.*;
import java.text.SimpleDateFormat;
import com.haulmont.cuba.core.global.ViewRepository;
SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy")
ViewRepository vRep = AppBeans.get(ViewRepository.NAME)
View renterView = getRenterView(vRep)
View creView = getCREView(vRep)
def inn = '3808096980'
def contragent = dataManager.load(Contragent.class).query('select c from rtneo$Contragent c where c.inn = :inn').parameter("inn", inn).one()
def inns = ['3808230890', '3849079510', '3810031323', '3801060504', '3825004185',
'3814001520', '3830905900', '3837001661', '3816005640',
'3819011201', '3820007055', '3821010406', '8506008175']
def cres = dataManager.load(ContragentRealEstate.class)
.query('select cre from rtneo$ContragentRealEstate cre join rtneo$Contragent c on cre.contragent.id = c.id where c.inn in :inns')
.parameter("inns", inns)
.view(creView)
.list()
_(contragent)
cres.each{_(it)}
CommitContext ctx = new CommitContext()
_(df.parse('30-12-2020').compareTo(df.parse('31-12-2020')))
for(def cre : cres){
//Не переносим объекты которые не действительны в 21 году
if(cre.getValidityTo() != null && cre.getValidityTo().compareTo(df.parse('31-12-2020')) <= 0)continue
def new_cre = metadata.getTools().copy(cre)
new_cre.setId(UUID.randomUUID())
new_cre.setValidityFrom(df.parse('01-01-2021'))
new_cre.setContragent(contragent)
new_cre.setCheckProcessing(false)
cre.setValidityTo(df.parse('31-12-2020'))
ctx.addInstanceToCommit(new_cre)
ctx.addInstanceToCommit(cre)
_(new_cre, "json")
for(def cy : cre.getContainerYards()){
def new_cy = metadata.getTools().copy(cy)
new_cy.setId(UUID.randomUUID())
new_cy.setContragentRealEstate(new_cre)
_(new_cy)
ctx.addInstanceToCommit(new_cy)
}
def renters = dataManager.load(RealEstateRenter.class)
.query('select r from rtneo$RealEstateRenter r where r.contragentRealEstate.id = :creId')
.parameter("creId", cre.getId())
.view(renterView)
.list()
_("renters ${renters.size()}")
for(def renter : renters){
//Функционал копирования арендаторов не тестировался
if(renter.getRenterRecord().getValidityTo() != null && renter.getRenterRecord().getValidityTo().compareTo(df.parse('31-12-2020')) <= 0)continue
def new_rent = metadata.getTools().copy(renter)
new_rent.setId(UUID.randomUUID())
new_rent.setContragentRealEstate(new_cre)
new_rent.setContragent(contragent)
def new_rrecord = metadata.getTools().copy(renter.getRenterRecord())
new_rrecord.setId(UUID.randomUUID())
new_rrecord.setValidityFrom(df.parse('01-01-2021'))
renter.getRenterRecord().setValidityTo(df.parse('31-12-2020'))
new_rent.setRenterRecord(new_rrecord)
// ctx.addInstanceToCommit(new_rrecord)
// ctx.addInstanceToCommit(new_rent)
_("RENTER -------------------------------- ${new_rent}")
}
// break
}
_(ctx.getCommitInstances())
dataManager.commit(ctx)
View getRenterView(ViewRepository vRep){
return vRep.getView(RealEstateRenter.class, "_local")
.addProperty("contragentRealEstate", vRep.getView(ContragentRealEstate.class, "_local"))
.addProperty("contractFile", vRep.getView(FileDescriptor.class, "_local"))
.addProperty("category", vRep.getView(RealEstateCategory.class, "_local"))
}
View getCREView(ViewRepository vRep){
return vRep.getView(ContragentRealEstate.class, "_local")
.addProperty("containerYards", vRep.getView(RealEstateContainerYard.class, "_local")
.addProperty("containerYard", vRep.getView(ContainerYard.class, "_base"))
)
.addProperty("type", vRep.getView(RealEstateType.class, "_base"))
.addProperty("wasteGenerationProjects", vRep.getView(WasteGenerationProject.class, "_base"))
.addProperty("rentContract", vRep.getView(ContragentFile.class, "_base"))
.addProperty("landlord", vRep.getView(Contragent.class, "_base"))
.addProperty("realEstate", vRep.getView(RealEstate.class, "_base"))
.addProperty("category", vRep.getView(RealEstateCategory.class, "_base"))
.addProperty("apartments", vRep.getView(RealEstateApartment.class, "_base"))
}
/**
* Логирование
*/
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")}