| 
 |||||||
| 
    Дубли 
        
        
		  Время создания: 12.11.2020 03:45		  
		 
		
		 		
		
		 		
		
				  
		    Раздел: INFO - JOB - rtneo - Работа над задачами - Удаление дублей		   
		
		
		 		 
		  Запись: wwwlir/Tetra/master/base/1605123886hvafc6sxda/text.html на raw.githubusercontent.com		  
		 
		
				   | 
 |||||||
| 
    | 
 |||||||
| 
    import com.groupstp.rtneo.entity.* import com.haulmont.cuba.core.global.* import com.haulmont.cuba.core.global.ViewRepository; import com.haulmont.cuba.core.global.View; import com.groupstp.rtneo.core.bean.ContragentWorker; DataManager dataManager = AppBeans.get(DataManager.NAME) ViewRepository vRep = AppBeans.get(ViewRepository.NAME) View viewCre = vRep.getView(ContragentRealEstate.class, "_minimal") viewCre.addProperty("realEstate", vRep.getView(RealEstate.class, "_minimal").addProperty("cadastralNumber")) viewCre.addProperty("contragent", vRep.getView(Contragent.class, "_minimal")) viewCre.addProperty("calculationAmount") viewCre.addProperty("livingArea") View viewContragent = vRep.getView(Contragent.class, "_minimal") viewContragent.addProperty("inn") viewContragent.addProperty("personalAccount") viewContragent.addProperty("type") def createPA = 0 def changeContragent = 0 def deleteContragent = 0 def i = 0 def contragents = dataManager.load(Contragent.class) .query('select c from rtneo$Contragent c where c.personalAccount is null and c.createdBy like \'%dataminer%\' order by c.inn') // .firstResult(i*10) // .maxResults(10) .view(viewContragent) .list(); //_(contragents.size()) //return 0 def previousINN = null def previousName = null for(Contragent contragent : contragents){ log.debug("\n*****************************************************************") log.debug("contragent - ${contragent} is inn - ${contragent.getInn()}") //log.debug(dataManager.loadValue('select count(c) from rtneo$Contragent c where c.inn = :inn', Integer.class).parameter("inn", contragent.getInn()).optional().orElse(0)) if(contragent.getInn() == null){ log.debug(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>...${contragent.getType()}") if(contragent.getType() == ContragentType.PERSONAL){ log.debug("++++++++++++++++++++++++=${contragent.getType()}") log.debug("Нужно сгенерировать ЛС -- (${contragent.getName()})") contragent.setPersonalAccount(generatePersonalNumber(contragent)) log.debug("ЛС -- (${contragent.getPersonalAccount()})") createPA++ dataManager.commit(contragent) continue } } // if(previousINN == contragent.getInn()){ // log.debug("DELETE ${contragent.getId()}") // log.debug("[[[[[[[[[[[[[[[[CONTINUE ${contragent.getInn()}]]]]]]]]]]]]]]]]]]") // continue // } // previousINN = contragent.getInn() 
 log.debug(">>SEARCH CONTRAGENT!<<") def paContragent = dataManager.load(Contragent.class) .query('select c from rtneo$Contragent c where c.inn = :inn and not c.personalAccount is null') .parameter("inn", contragent.getInn()) .view(viewContragent) .optional() .orElse(null) log.debug("paContragent - ${paContragent}") 
 if(paContragent == null){ log.debug("Нужно сгенерировать ЛС -- (${contragent.getName()})") contragent.setPersonalAccount(generatePersonalNumber(contragent)) createPA++ dataManager.commit(contragent) continue }else{ log.debug("===================paContragent found ===================") } 
 
 // def paCres = paContragent.getRealEstates() def paCres = dataManager.load(ContragentRealEstate.class) .query('select c from rtneo$ContragentRealEstate c where c.contragent.id = :id') .parameter("id", paContragent.getId()) .view(viewCre) .list() log.debug("paCres.size() - ${paCres.size()}") 
 // def cres = contragent.getRealEstates() def cres = dataManager.load(ContragentRealEstate.class) .query('select c from rtneo$ContragentRealEstate c where c.contragent.id = :id') .parameter("id", contragent.getId()) .view(viewCre) .list() log.debug("cres.size() - ${cres.size()}") 
 log.debug(">>SEARCH CRE<<") for(ContragentRealEstate cre : cres){ 
 def found = false for(ContragentRealEstate paCre : paCres){ 
 log.debug("${paCre.getRealEstate().getCadastralNumber()}") 
 if(paCre.getRealEstate().getCadastralNumber() == cre.getRealEstate().getCadastralNumber()){ if(paCre.getCalculationAmount() == cre.getLivingArea() || paCre.getLivingArea() == cre.getLivingArea()){ found = true break } } 
 } 
 if(found){ log.debug("found cad - ${cre.getRealEstate().getCadastralNumber()}") }else{ log.debug("no found cad - ${cre.getRealEstate().getCadastralNumber()} need to create!!!") if(cre.getCalculationAmount() == 0 || cre.getCalculationAmount() == null) cre.setCalculationAmount(cre.getLivingArea()) cre.setContragent(paContragent) dataManager.commit(cre) changeContragent++ } 
 } 
 log.debug("DELETE ${contragent.getId()}") dataManager.load(Contract.class) .query('select c from rtneo$Contract c where c.contragent.id = :contragent_id') .parameter("contragent_id", contragent.getId()) .view("_local") .list().each{dataManager.remove(it)} dataManager.remove(contragent) deleteContragent++ } log.debug("Create PA = ${createPA}, changeCREContragent = ${changeContragent}, deleteContragent = ${deleteContragent}") def generatePersonalNumber(Contragent contragent){ ContragentWorker сontragentWorker = AppBeans.get(ContragentWorker.NAME) return сontragentWorker.createAccountNumber(contragent) } /** * Логирование */ 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 log(Object obj){log.debug(obj)}  | 
 |||||||
| 
    
 
 Так же в этом разделе:
  
  
  | 
 |||||||
      
   | 
 |||||||
   
   
  | 
 |||||||
   
  |