MyTetra Share
Делитесь знаниями!
CategoryABC
Время создания: 07.10.2020 11:08
Раздел: INFO - JOB - rtneo - Работа над задачами
Запись: wwwlir/Tetra/master/base/15723278387ixshx3xu3/text.html на raw.githubusercontent.com

import com.groupstp.rtneo.entity.*

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

import java.text.SimpleDateFormat

import org.apache.commons.collections.CollectionUtils

import com.groupstp.rtneo.service.*


DataManager dataManager = AppBeans.get(DataManager.NAME)

BillService billService = AppBeans.get(BillService.NAME)


def period = '2020-10-01'

def df1 = new SimpleDateFormat("yyyy-MM-dd")

period = df1.parse(period)


def i = 0;


def contragents = dataManager.load(Contragent.class)

.query('select distinct c.contragent from rtneo$ContragentRealEstate c where (c.type.id = \'a1122505-7e60-19f0-be56-5ec549ab80c8\' or c.type.id = \'a633833e-83bc-52b1-0aef-9898739f434f\') and (not c.contragent.notDoingBusiness = true or c.contragent.notDoingBusiness is null) and c.contragent.category is null order by c.contragent.id')

.view("_local")

.firstResult(i*5000)

.maxResults(5000)

.list();


log.debug(contragents.size())

def a = dataManager.load(ContragentCategory.class).id(UUID.fromString('0c17efe8-8b20-adce-b97e-b8ffdecdf5ba')).one()

def b = dataManager.load(ContragentCategory.class).id(UUID.fromString('a2e512a9-7fa3-6609-04e6-b60ddacc2c70')).one()

def c = dataManager.load(ContragentCategory.class).id(UUID.fromString('745d7724-5dfd-d062-08fb-c15073a69764')).one()


CommitContext ctx = new CommitContext()

def total = contragents.size()

def count = 0


def countA = 0

def countB = 0

def countC = 0

for(def contragent : contragents){

count++

def listAccrualActual = billService.getBillsOnPeriod(contragent.getId(), period);

def sumActual = 0

for(def accrualActual : listAccrualActual){

sumActual += accrualActual.getTotalSum()

}

def cat = c

if(sumActual>19000.00)

cat = a

else if(sumActual>3000.00)

cat = b

contragent = dataManager.reload(contragent, "contragent-edit")

contragent.category = cat

ctx.addInstanceToCommit(contragent)


log.debug("$contragent.personalAccount $contragent.category.name $sumActual")

if(cat == a)

countA++

else if(cat == b)

countB++

else if(cat == c)

countC++

}

log.debug("countA = ${countA}, countB = ${countB}, countC = ${countC}")

//def sums = dataManager.loadValues('select a.contragent, sum(a.sum) from rtneo$Accrual a where a.period=:period and a.realEstate is not null and a.sum is not null and a.sum>0 group by a.contragent order by sum(a.sum) desc')

// .parameter("period", period)

// .properties("contragent", "sum")

// .list();

//

//

//

//log.debug(new Date())

//def total = sums.size()

//def count = 0

//

//CommitContext ctx = new CommitContext()

//for(def sum:sums){

//

// def k = count/total

// def cat = c

// if(k<0.2)

// cat = a

// else if(k<0.5)

// cat = b

// contragent = dataManager.reload(sum.getValue("contragent"), "contragent-edit")

// contragent.category = cat

// ctx.addInstanceToCommit(contragent)

// count++

// printSum = sum.getValue("sum")

// log.debug("$contragent.personalAccount $contragent.category.name $printSum")

// def listAccrualActual = billService.getBillsOnPeriod(contragent.getId(), period);

// def sumActual = 0

// for(def accrualActual : listAccrualActual){

// sumActual += accrualActual.getTotalSum()

// }

// log.debug(sumActual)

//}


if (!CollectionUtils.isEmpty(ctx.getCommitInstances())) {

dataManager.commit(ctx);

}


log.debug(new Date())

return count


Так же в этом разделе:
 
MyTetra Share v.0.58
Яндекс индекс цитирования