MyTetra Share
Делитесь знаниями!
Тест метода отображения актуальных начислений
Время создания: 06.06.2020 11:24
Раздел: INFO - JOB - rtneo - Рефакторинг
Запись: wwwlir/Tetra/master/base/159141386147nzxlr7e4/text.html на raw.githubusercontent.com

import java.util.*

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

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

import com.groupstp.rtneo.entity.*

import java.text.SimpleDateFormat


Contragent contragent = dataManager.load(Contragent.class)

.query('select c from rtneo$Contragent c where c.personalAccount = :pa')

.parameter("pa", "ААА3812525543")

.view("_minimal")

.one()


long st = System.currentTimeMillis();

_(getContragentBills(contragent.getId()))

long end = System.currentTimeMillis();

_(end-st);


public List<Accrual> getContragentBills(UUID contragentID) {

String sqlQuery = 'select e from rtneo$Accrual e where 1=0';

List<Accrual> accruals = new ArrayList<Accrual>();

List<Contract> contracts = dataManager.load(Contract.class)

.query('select e from rtneo$Contract e where e.contragent.id = :contragent and e.accepted =true order by e.createTs desc')

// .query("select e from rtneo$Contract e where e.contragent.id = :contragent and e.accepted ='true' order by e.date desc")

.parameter("contragent", contragentID)

.view("contract-edit")

.list();

if (contracts.size() > 0) {

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

Contract lastContract = null;

for (Contract contract : contracts) {

if (lastContract == null) {

lastContract = contract;

sqlQuery = 'cast(a.contractPosition.contract.id text)=\'' + contract.getId().toString() + '\' ';

} else {

if (contract.getFrom().before(lastContract.getFrom())) {

sqlQuery = sqlQuery + ' or (cast(a.contractPosition.contract.id text)=\'' + contract.getId().toString() + '\' and a.period < \'' + sdf.format(lastContract.getFrom()) + '\' )';

lastContract = contract;

}

}

}

sqlQuery = 'select a from rtneo$Accrual a where a.contragent.id = :contragentID and (' + sqlQuery + ') order by a.period';

// List<RealEstateRenter> payOwnerList = dataManager.load(RealEstateRenter.class)

// .query("select s from rtneo$RealEstateRenter s where s.contragent.id = :contragentID and s.payOwner='true'")

// .parameter("contragentID", contragentID)

// .view("realEstateRenter-changeQueryControl")

// .list();


log.debug(sqlQuery)

accruals = dataManager.load(Accrual.class)

.query(sqlQuery)

.parameter("contragentID", contragentID)

.view("accrual-full")

.list();


// for (int h = 0; h < payOwnerList.size(); h++) {

// for (int y = 0; y < accruals.size(); y++) {

// try {

// if (payOwnerList.get(h).getRenterRecord().getId().equals(accruals.get(y).getContractPosition().getContragentRealEstate().getId())) {

// accruals.remove(y);

// y = y - 1;

// }

// } catch (Exception e) {

// }

// }

// }

}

return accruals;

}

public List<Accrual> getContragentBillsLight(UUID contragentID) {

String sqlQuery = 'select e from rtneo$Accrual e where 1=0';

List<Accrual> accruals = new ArrayList<Accrual>();

List<Contract> contracts = dataManager.load(Contract.class)

.query('select e from rtneo$Contract e where e.contragent.id = :contragent and e.accepted =true order by e.createTs desc')

// .query("select e from rtneo$Contract e where e.contragent.id = :contragent and e.accepted ='true' order by e.date desc")

.parameter("contragent", contragentID)

.view("contract-edit")

.list();

if (contracts.size() > 0) {

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

Contract lastContract = null;

for (Contract contract : contracts) {

if (lastContract == null) {

lastContract = contract;

sqlQuery = 'cast(a.contractPosition.contract.id text)=\'' + contract.getId().toString() + '\' ';

} else {

if (contract.getFrom().before(lastContract.getFrom())) {

sqlQuery = sqlQuery + ' or (cast(a.contractPosition.contract.id text)=\'' + contract.getId().toString() + '\' and a.period < \'' + sdf.format(lastContract.getFrom()) + '\' )';

lastContract = contract;

}

}

}

sqlQuery = 'select a from rtneo$Accrual a where a.contragent.id = :contragentID and (' + sqlQuery + ') order by a.period';

// List<RealEstateRenter> payOwnerList = dataManager.load(RealEstateRenter.class)

// .query("select s from rtneo$RealEstateRenter s where s.contragent.id = :contragentID and s.payOwner='true'")

// .parameter("contragentID", contragentID)

// .view("realEstateRenter-changeQueryControl")

// .list();


log.debug(sqlQuery)

accruals = dataManager.load(Accrual.class)

.query(sqlQuery)

.parameter("contragentID", contragentID)

.view("accrual-full")

.list();


// for (int h = 0; h < payOwnerList.size(); h++) {

// for (int y = 0; y < accruals.size(); y++) {

// try {

// if (payOwnerList.get(h).getRenterRecord().getId().equals(accruals.get(y).getContractPosition().getContragentRealEstate().getId())) {

// accruals.remove(y);

// y = y - 1;

// }

// } catch (Exception e) {

// }

// }

// }

}

return accruals;

}

/**

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

*/

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