|
|||||||
Исправление копированием
Время создания: 26.08.2020 20:11
Раздел: INFO - JOB - rtneo - Работа над задачами - Исправительные начисления
Запись: wwwlir/Tetra/master/base/1598443918z8vyjr8z0n/text.html на raw.githubusercontent.com
|
|||||||
|
|||||||
import com.groupstp.rtneo.entity.*; import com.haulmont.cuba.core.entity.*; import com.haulmont.cuba.core.global.*; import com.groupstp.rtneo.service.*; import com.groupstp.rtneo.core.bean.* import java.text.SimpleDateFormat import java.math.RoundingMode; def service = AppBeans.get(CalculationWorker.NAME) SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy") long st = System.currentTimeMillis(); String idEx='e0260229-7731-df21-9cb3-0d2b5f4d6b75' List<String> listExInn = inToFile(idEx) _(listExInn.size()) String q = 'select a.contragent, a.contractPosition.contract.id, a.contractPosition.contract, min(a.period), max(a.period) from rtneo$Accrual a where a.contragent.inn in :innList and a.price = 594.52800 group by a.contragent, a.contractPosition.contract.id' List<KeyValueEntity> contracts = dataManager.loadValues(q) .properties("contragent", "id", "contract", "start", "end") .parameter("innList", listExInn) .maxResults(10) .list(); Date fromDate = format.parse("01.07.2019") Date beforeDate = format.parse("31.12.2019") Date currentDate = format.parse("30.06.2019") for(def item : contracts){ CommitContext ctxRem = new CommitContext() CommitContext ctxCpy = new CommitContext() List<Accrual> accs = dataManager.load(Accrual.class) .query('select a from rtneo$Accrual a where a.contragent.id = :contragent and a.contractPosition.contract.id = :contract and a.period between :start and :end') .view("accrual-copy") .parameter("contragent", item.getValue('contragent').getId()) .parameter("contract", item.getValue('contract').getId()) .parameter("start", item.getValue('start')) .parameter("end", item.getValue('end')) .list() // accs.each{_(it)}
for(Accrual accrual : accs){ Accrual copyAccrual = metadata.getTools().copy(accrual); copyAccrual.setId(UUID.randomUUID()); copyAccrual.setCorrectionNumber(1)
BigDecimal nds; BigDecimal ndsSum; BigDecimal totalSum; BigDecimal price = new BigDecimal(557.76).setScale(2, RoundingMode.HALF_UP); totalSum = price.multiply(copyAccrual.getAmount()).setScale(5, RoundingMode.HALF_UP) nds = totalSum.divide(new BigDecimal(6.0), 5, RoundingMode.HALF_UP); // НДС 20/120 copyAccrual.setPrice(price); copyAccrual.setNdsSum(nds); copyAccrual.setNdsSumBase(nds); copyAccrual.setSum(totalSum); copyAccrual.setTotalSum(totalSum); copyAccrual.setTotalSumBase(totalSum);
_(accrual, "json") _(copyAccrual, "json") _("*****************************") ctxRem.addInstanceToRemove(accrual) ctxCpy.addInstanceToCommit(copyAccrual) } dataManager.commit(ctxRem) dataManager.commit(ctxCpy)
_("${item.getValue('contragent')}, ${item.getValue('contract')}, ${item.getValue('start')}, ${item.getValue('end')}") } _(">> Contragents load = ${System.currentTimeMillis()-st}") /** ******************************************************************************** */ import com.haulmont.cuba.core.entity.FileDescriptor import com.haulmont.cuba.core.app.FileStorageAPI import java.io.InputStream import java.io.InputStreamReader import java.io.ByteArrayOutputStream import org.apache.commons.io.IOUtils import com.opencsv.CSVReader; import org.apache.commons.collections.CollectionUtils import java.util.stream.Collectors; List<String> inToFile(String id){ FileDescriptor fd = dataManager.load(FileDescriptor.class) .id(UuidProvider.fromString(id)) .view(View.MINIMAL) .optional().orElse(null);
if(fd == null){throw new RuntimeException("fileNotFound")}
FileStorageAPI fileStorageAPI=AppBeans.get(FileStorageAPI.NAME); InputStream inputStream=fileStorageAPI.openStream(fd) CSVReader reader = new CSVReader(new InputStreamReader(inputStream, "UTF-8"));
return reader.readAll().stream() .map{e->e[0]}.collect(Collectors.toList()) } /** * Логирование */ 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)} |
|||||||
Так же в этом разделе:
|
|||||||
|
|||||||
|