MyTetra Share
Делитесь знаниями!
Устноавка категории
Время создания: 16.03.2020 15:59
Раздел: INFO - JOB - rtneo - Работа над задачами - Категоризация
Запись: wwwlir/Tetra/master/base/1584345540pfzsq5g8g9/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()


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

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

.query('select e from rtneo$ContragentRealEstate e where e.createTs>\'2020-07-01\' and e.type is null and not lower(e.realEstate.name) like lower(\'%%гараж%%\') order by e.id')

.view("contragentRealEstate-contoller-interface")

.maxResults(5)

.list();

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

// .query('select c from rtneo$ContragentRealEstate c where c.id = :id')

// .parameter("id", UUID.fromString("799c5467-5c1b-c469-8a62-b0a362ba63f1"))

// .view("contragentRealEstate-contoller-interface")

// .maxResults(5)

// .list();


def count = 0

def countTotal = 0

def countCategory = 0

def CommitContext ctx = new CommitContext()


for(ContragentRealEstate item : listCRE){

count++

countTotal++

// _(item.getId())

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

_("Contragent is null")

continue

}

// _(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")

}

RealEstateCategory category = worker.determineContragentRealEstateCategory(item)

if(category == null){

_("${item} - Category is null")

continue

}else{

countCategory++

_("${item} - ${category.getName()}")

}

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();

}

}

_("${countTotal} - ${countCategory}")


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
Яндекс индекс цитирования