|
|||||||
С переносоу у НО контрагента
Время создания: 11.03.2021 11:11
Раздел: INFO - JOB - rtneo - Работа над задачами - Удалить дубли объектов недвижимости
Запись: wwwlir/Tetra/master/base/1615432261c7e9fnq2vb/text.html на raw.githubusercontent.com
|
|||||||
|
|||||||
import com.haulmont.cuba.core.entity.Entity import com.haulmont.cuba.core.global.* import com.groupstp.rtneo.entity.* import com.groupstp.rtneo.service.* import com.groupstp.rtneo.core.bean.* import com.haulmont.cuba.core.* import java.util.stream.Collectors import com.haulmont.cuba.core.global.ViewRepository; import com.haulmont.cuba.core.global.View; import java.util.function.*; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.stream.Collectors def vals = dataManager.loadValues('select re.cadastralNumber, re, cre from rtneo$RealEstate re join rtneo$EntityesTemporarySet t on re.id = t.entityId join rtneo$ContragentRealEstate cre on re.id = cre.realEstate.id where t.setName = \'DoubleREWithoutCRE_11-03-21\' order by re.cadastralNumber') .properties("cad", "re", "cre") // .firstResult(0) // .maxResults(1000) .list().stream().collect(Collectors.groupingBy({p->p.getValue("cad")}, Collectors.groupingBy({p->p.getValue("re")}))) def reSet def cres = [] for(def cad : vals.entrySet()){ CRE c = new CRE() c.cad = cad.getKey()
for(def re : cad.getValue().entrySet()){
if(c.re == null) { c.re = re.getKey() continue }
for(def cre : re.getValue()){ c.cres.add(cre.getValue("cre")) } }
cres.add(c) } ViewRepository vRep = AppBeans.get(ViewRepository.NAME) View creView = vRep.getView(ContragentRealEstate.class, "_minimal").addProperty("realEstate", vRep.getView(RealEstate.class, "_minimal").addProperty("cadastralNumber")) CommitContext ctx = new CommitContext() for(def item : cres){ for(def cre : item.cres){ cre = dataManager.reload(cre, creView) if(cre.getRealEstate().getCadastralNumber().equals(item.cad)){ cre.setRealEstate(dataManager.getReference(RealEstate.class, item.re.getId())) ctx.addInstanceToCommit(cre) } } } dataManager.commit(ctx) class CRE{ def cad, re def cres = [] } /** * Логирование */ 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")} |
|||||||
Так же в этом разделе:
|
|||||||
|
|||||||
|