MyTetra Share
Делитесь знаниями!
Скрипт
Время создания: 21.09.2020 17:25
Раздел: INFO - JOB - rtneo - Работа над задачами - Создание ЛС
Запись: wwwlir/Tetra/master/base/1600680332oewxqd8xye/text.html на raw.githubusercontent.com

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

import com.groupstp.rtneo.entity.*

import java.text.DateFormat;

import java.text.SimpleDateFormat;

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

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

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

ContragentWorker worker = AppBeans.get(ContragentWorker.NAME)


long st = System.currentTimeMillis();


def contragents = dataManager.load(Contragent.class)

.query('select c from rtneo$Contragent c where c.personalAccount is null')

.view("_local")

.list() as List<Contragent>

contragents.sort(new Comparator<Contragent>() {

@Override

int compare(Contragent o1, Contragent o2) {

o1.getId().compareTo(o2.getId())

}

})

def count = 0

for(i=0; i<=50; i++){

def index = 100*i

def chunkContragent = contragents.subList(index, index+1000)

_("chunk ${index}")

CommitContext cctx = new CommitContext()

for(def contragent : chunkContragent){

def number = worker.createAccountNumber(contragent)

_(number)

if(number != null){

contragent.setPersonalAccount(number)

cctx.addInstanceToCommit(contragent)

count++

}else{

_(contragent)

}


}

dataManager.commit(cctx)

}

long end = System.currentTimeMillis();

_(end-st);

_(count)




/**

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

*/

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