MyTetra Share
Делитесь знаниями!
Исправление дублей номеров начислений
Время создания: 29.09.2020 10:57
Раздел: INFO - JOB - rtneo - Работа над задачами - Исправление начислений
Запись: wwwlir/Tetra/master/base/1601348246rem136g4jk/text.html на raw.githubusercontent.com

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

import com.groupstp.rtneo.entity.*

import com.groupstp.rtneo.service.*

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

import java.util.stream.Collectors;

import java.util.stream.Stream;

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

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

import java.util.function.Function;


ViewRepository vRep = AppBeans.get(ViewRepository.NAME)

CalculationWorker calculationWorker = AppBeans.get(CalculationWorker.NAME)


View viewContragent = vRep.getView(Contragent.class, "contragent-create-contract")

.addProperty("realEstates", vRep.getView(Contragent.class, "contragent-create-contract")

.getProperty("realEstates").getView()

// .addProperty("exportStartDate")

.addProperty("type", vRep.getView(RealEstateType.class, "_minimal")

.addProperty("isLiving")

)

)

View viewContract = vRep.getView(Contract.class, "contract-edit")

.addProperty("contragent",

vRep.getView(Contract.class, "contract-edit").getProperty("contragent").getView().addProperty("notUseReductionFactor"))


HashMap<UUID, Object> contractCache = new HashMap<>()

Function<UUID, Contract> getContract = {e ->

if(contractCache.containsKey(e.getValue('contract_id'))){

e.setValue('contract_id', contractCache.get(e.getValue('contract_id')))

}else{

def ct = dataManager.load(Contract.class).id(e.getValue('contract_id')).view(viewContract).one()

contractCache.put(e.getValue('contract_id'), ct)

e.setValue('contract_id', ct)

}

return e;

}


def accrualGroup = dataManager.loadValues('select a.contragent.id, a.documentNumber, count(distinct a.contractPosition.contract) from rtneo$Accrual a group by a.contragent.id, a.documentNumber having count(distinct a.contractPosition.contract)>1 order by a.documentNumber')

.properties("contragent_id", "documentNumber", "count_contract")

.firstResult(0)

.maxResults(100)

.list()

.stream().map{e->e.getValue('contragent_id')}.distinct().collect(Collectors.toList())


def count = 0

for(def item : accrualGroup){

count++

_(">>>>>>>> Contragent - ${item}")

def contragent = dataManager.load(Contragent.class).id(item).view(viewContragent).one()

def accruals = dataManager.loadValues('select a.documentNumber, a.period, a.contractPosition.contract.id, a.contractPosition.contract.createTs from rtneo$Accrual a where a.contragent.id = :contragent_id order by a.documentNumber')

.properties("documentNumber", "period", "contract_id", "contract_createTs")

.parameter("contragent_id", contragent.getId())

.list()

.stream().map{e-> getContract.apply(e)}.collect(Collectors.toList())

def contractAccrualGroup = accruals.stream().collect(

Collectors.groupingBy({p->p.getValue("documentNumber")},

Collectors.groupingBy({p->p.getValue("period")},

Collectors.mapping({p->p.getValue("contract_id")}, Collectors.toSet()))

)

)

def docNumber

def date

def list = contractAccrualGroup.entrySet().stream().peek{e-> docNumber = e.getKey()}

.flatMap{numberMap -> numberMap.getValue().entrySet().stream()}.peek{e-> date = e.getKey()}

.flatMap{dateMap -> dateMap.getValue().size() > 1 ? dateMap.getValue().stream().sorted{v1, v2 -> -1*v1.getCreateTs().compareTo(v2.getCreateTs())}.skip(1) : Stream.empty()}

.peek{e->_("${docNumber} ${date} ${e.getNumber()} ${e.getCreateTs()}")}

.forEach{contract->

// calculationWorker.calculateAccruals(date, date, contragent, new Date(), contract);

}

contractCache.clear()

}

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