MyTetra Share
Делитесь знаниями!
Установка категории земельным участкам
Время создания: 31.03.2020 23:15
Раздел: INFO - JOB - rtneo - Работа над задачами - Категоризация
Запись: wwwlir/Tetra/master/base/15856677106159z2lu5h/text.html на raw.githubusercontent.com

import com.groupstp.rtneo.entity.*;

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

import com.groupstp.rtneo.service.*;

import com.groupstp.rtneo.core.bean.*;

import com.groupstp.rtneo.data.*

import com.haulmont.cuba.core.global.ViewRepository;

import com.groupstp.rtneo.core.bean.CategorizationWorker;

import com.groupstp.rtneo.config.*


CategorizationWorker worker = AppBeans.get(CategorizationWorker.NAME)


View view = createView()

_(new Date())

def count = 0

def CommitContext ctx = new CommitContext()

def prevCategory = null

def prevAddress = null

RealEstateCategory category = null

for(int i = 0; i<10; i++){

List<ContragentRealEstate> listCRE = dataManager.load(ContragentRealEstate.class)

.query('select c from rtneo$ContragentRealEstate c where c.category is null and (lower(c.realEstate.address) like \'%%земельный%%\' or lower(c.realEstate.name) like \'%%земельный%%\' and not lower(c.realEstate.address) like \'%%гараж%%\' and lower(c.realEstate.address) like \'%% иркутск%%\') order by c.realEstate.address')

.view("contragentRealEstate-contoller-interface")

.firstResult(i*10)

.maxResults(10)

.list();

for(ContragentRealEstate item : listCRE){

count++

_(item.getId())

if(item.getContragent() == null){

_("Contragent is null")

continue

}

_(item.getRealEstate().getAddress())

if(item.getRealEstate().getAddress().equals(prevAddress)){

_("prev")

category = prevCategory

}else{

prevAddress = item.getRealEstate().getAddress()

RealEstateIndicator indicator = dataManager.load(RealEstateIndicator.class)

.query('select i from rtneo$RealEstateIndicator i where i.contragentRealEstate.id = :cre')

.parameter("cre", item.getId())

.optional()

.orElse(null)

if(indicator != null){

dataManager.remove(indicator)

_("Deleted indicator")

}

category = worker.determineContragentRealEstateCategory(item)

}

prevCategory = category

if(category == null){

_("Category is null")

continue

}

String typeId = null

if(category.getIsLiving() != null && category.getIsLiving()){

typeId = "b3de9722-df73-5dbe-189f-d176ea1507c7"

}else{

typeId = "a633833e-83bc-52b1-0aef-9898739f434f"

}

type = dataManager.load(RealEstateType.class).id(UUID.fromString(typeId)).view("_minimal").one();

// _(category, "json")

// _(type, "json")

item.setCategory(category);

item.setType(type);

// dataManager.commit(item)

ctx.addInstanceToCommit(item)

if(count>=10){

count = 0

dataManager.commit(ctx)

_("commit")

ctx.getCommitInstances().clear();

}

}

}


_(new Date())


def createView(){

ViewRepository vRep = AppBeans.get(ViewRepository.NAME)

View view = vRep.getView(ContragentRealEstate.class, "_local").addProperty("category", vRep.getView(RealEstateCategory.class, "_local")).addProperty("type", vRep.getView(RealEstateType.class, "_local"))

return view;

}


/**

* Логирование

*/

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)}

 
MyTetra Share v.0.59
Яндекс индекс цитирования