|
|||||||
Скрипт исправления
Время создания: 06.07.2020 13:47
Раздел: INFO - JOB - rtneo - Работа над задачами - Пролонгация
Запись: wwwlir/Tetra/master/base/1594014428pds07so2ie/text.html на raw.githubusercontent.com
|
|||||||
|
|||||||
import com.haulmont.cuba.core.* import com.haulmont.cuba.core.entity.*; import com.haulmont.cuba.core.global.*; import com.groupstp.rtneo.entity.*; import com.groupstp.rtneo.service.*; import com.groupstp.rtneo.core.bean.tools.*; import com.groupstp.rtneo.core.bean.calculation.*; import java.text.SimpleDateFormat; import com.haulmont.bali.util.ParamsMap; import com.haulmont.cuba.core.global.PersistenceHelper; import org.apache.commons.collections.CollectionUtils import java.util.stream.Collectors import com.haulmont.cuba.security.entity.*; import com.haulmont.cuba.core.global.ViewRepository; import com.haulmont.cuba.core.global.View; /** * */ def res = resDifferencePriceAccrual() checkAndProlongation(res) /** *Main resource data * */ //Начисления где не корректный тариф//не верный запрос def resDifferencePriceAccrual(){ String q = 'select a.id, a.contragent.personalAccount, a.contragent.inn, a.contractPosition.contract.number, a.contractPosition.contract.id, a.documentNumber, a.period, a.price, (select t.tariff from rtneo$Tariff t where t.name = 1 and a.period between t.dateSince and t.dateTill)*1.2, a.totalSum, a.updatedBy, a.contragent.user.login from rtneo$Accrual a where a.period > a.contractPosition.contract.before and (select t.tariff from rtneo$Tariff t where t.name = 1 and a.period between t.dateSince and t.dateTill)*1.2 <> a.price order by a.contragent.personalAccount, a.documentNumber, a.id' return dataManager.loadValues(q) .properties("aId", "pa", "inn", "ctNumber", "cId", "anumber", "aPeriod", "aPrice", "correctPrice", "aTotalSum", "aUpdate", "login") .list() } /** * Methods * */ def checkAndProlongation(def res){ View contractView = getViewContract() SimpleDateFormat df = new SimpleDateFormat("dd.MM.yyyy");
Set<String> pas = res.stream().map{e-> e.getValue('pa')}.collect(Collectors.toSet())
for(String item : pas){ def acc = res.stream().filter{e-> e.getValue('pa') == item}.collect(Collectors.toList()) String inn = acc.get(0).getValue('inn')
if(inn != null && !checkPayment(inn)){
//Проверка, заходил ли пользователь // if(checkLogin(acc.get(0).getValue('login')))continue
def startPeriod = acc.stream().map{a -> a.getValue('aPeriod')}.min{d1, d2 -> d1.compareTo(d2)}.get() def endPeriod = acc.stream().map{a -> a.getValue('aPeriod')}.max{d1, d2 -> d1.compareTo(d2)}.get()
def contractId = acc.get(0).getValue('cId') def contract = dataManager.load(Contract.class).id(contractId).view(contractView).optional().orElse(null) def contragent = contract.getContragent() reProlongation(startPeriod, endPeriod, contragent, contract, new Date()) _("${inn}: ${df.format(startPeriod)} - ${df.format(endPeriod)}") acc.each{_("pa - ${it.getValue('pa')}, ctNumber - ${it.getValue('ctNumber')}, aNumber - ${it.getValue('anumber')}, aPeriod - ${it.getValue('aPeriod')}, aPrice - ${it.getValue('aPrice')}, correctPrice - ${it.getValue('correctPrice')}, aTotalSum - ${it.getValue('aTotalSum')}, aUpdate - ${it.getValue('aUpdate')}")} }
} return null } def getViewContract(){ ViewRepository vRep = AppBeans.get(ViewRepository.NAME) return vRep.getView(Contract.class, "_local") .addProperty("mainContract", vRep.getView(Contract.class, "_local")) .addProperty("contragent", vRep.getView(Contragent.class, "_local")); } def checkPayment(String inn){ return dataManager.getCount(LoadContext.create(Payment.class).setQuery( LoadContext.createQuery('select p from rtneo$Payment p where p.inn = :inn') .setParameter("inn", inn) )) > 0 } def checkLogin(String login){ return dataManager.getCount(LoadContext.create(SessionLogEntry.class).setQuery( LoadContext.createQuery('select s from sec$SessionLogEntry s where s.user.login = :login') .setParameter("login", login) )) > 0 } def reProlongation(Date from, Date to, Contragent contragent, Contract contract, Date dateBill){ CalculationWorkerBean calculationWorker = AppBeans.get(CalculationWorkerBean.class); calculationWorker.calculateAccruals(from, to, contragent, dateBill, contract, false); return true } /** * Логирование */ 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)} |
|||||||
Так же в этом разделе:
|
|||||||
|
|||||||
|