|
|||||||
тарифная скрипт
Время создания: 24.09.2020 15:50
Раздел: INFO - JOB - rtneo - Выгрузки
Запись: wwwlir/Tetra/master/base/1600933810brfgqrqtby/text.html на raw.githubusercontent.com
|
|||||||
|
|||||||
import com.groupstp.rtneo.entity.* import com.haulmont.cuba.core.global.* import com.groupstp.rtneo.service.BillService import java.text.SimpleDateFormat import java.util.stream.Collectors import java.text.SimpleDateFormat import java.time.*; import java.time.format.*; import java.util.Calendar; import com.groupstp.rtneo.core.bean.tools.DatePeriodTools; import java.time.temporal.ChronoUnit; DatePeriodTools datePeriodTools = AppBeans.get(DatePeriodTools.class) def loads = dataManager.loadValues('select cre.contragent.id, cre.contragent.personalAccount, cre.contragent.name, cre.realEstate.id, cre.realEstate.address, cre.realEstate.cadastralNumber, cre.share, cre.realEstate.area, cre.calculationAmount, cre.category.name, cre.category.unit.isArea, cre.category.norm, cre.category.ratio, cre.ownType, (select count(r) from rtneo$ContractPosition r where r.contragentRealEstate.id = cre.id and r.contract.accepted = true and r.isFactRecalculation = true), cre.validityFrom, cre.validityTo from rtneo$ContragentRealEstate cre where not cre.category is null and cre.landlord is null and (cre.category.isLiving is null or cre.category.isLiving = false) and not cre.category.id = \'41d35f0c-d5ee-0989-bc34-8ed177744849\' and (cre.excludeFromAccounting is null or cre.excludeFromAccounting = false) and cre.realEstate.id = \'86a317db-5569-281e-2caa-f69865532efd\' order by cre.contragent.id')// and cre.contragent.id = \'8c0e4a28-bc9f-e906-5a02-05d93fdfbf41\' .properties("contragent_id", "personalAccount", "name", "re_id", "address", "cadastralNumber", "share", "area", "calculationAmount", "category_name", "isArea", "norm", "ratio", "owner", "recalc", "from", "to") .firstResult(0) .maxResults(100000) .list() List<HashMap<String, Object>> list = new ArrayList<>() for(def load : loads){ def item = ['contragent_id' : load.getValue("contragent_id"), 'personalAccount' : load.getValue("personalAccount"), 'name' : load.getValue("name"), 're_id' : load.getValue("re_id"), 'address' : load.getValue("address"), 'cadastralNumber' : load.getValue("cadastralNumber"), 'share' : load.getValue("share"), 'area' : load.getValue("area"), 'calculationAmount' : load.getValue("calculationAmount") == null || load.getValue("calculationAmount").compareTo(0) == 0 ? 0 : load.getValue("calculationAmount"), 'category_name' : load.getValue("category_name"), 'isArea' : load.getValue("isArea"), 'norm' : load.getValue("norm"), 'ratio' : load.getValue("ratio"), 'owner' : load.getValue("owner"), 'from' : load.getValue("from"), 'to' : load.getValue("to"), 'recalc' : load.getValue("recalc")] // def res = strBuilder(load.getValue("personalAccount"), load.getValue("name"), load.getValue("address"), load.getValue("cadastralNumber"), load.getValue("share"), load.getValue("area"), load.getValue("calculationAmount"), load.getValue("category_name"), load.getValue("norm"), load.getValue("ratio")) list.add(item) } list.each{_(it)} def groupList = list.stream().collect( Collectors.groupingBy({p->p.get("contragent_id")}, Collectors.groupingBy({p->p.get("re_id")}))) def tariffI = 435.74*1.2 def tariffII = 464.80*1.2 _("|ЛС|Наименование|Адрес|Кадастровый|Категория|Площадь|Р/е|Норматив|Сумма 2019|Объем|Перерасчет|Примечание") for(def i0 : groupList.entrySet()){ for(def i1 : i0.getValue().entrySet()){ def prim = "" def recalc = !(i1.getValue()['recalc'][0].compareTo(0) == 0) def sum = 0.0 def amount = 0 def area = 0 def areaNotIsNull = true def calcAmount = 0
if(i1.getValue()['area'][0] == null){ prim = prim+"area is null, " areaNotIsNull = false // _("|${i1.getValue()['personalAccount'][0]}|${i1.getValue()['name'][0]}|${i1.getValue()['address'][0]}|${i1.getValue()['cadastralNumber'][0]}|${i1.getValue()['category_name'][0]}|${area}|${calcAmount}|${i1.getValue()['norm'][0]}|${sum}|${amount}|${recalc}|${prim}".replaceAll("\\p{Cntrl}", "")) // continue } if(recalc){ def recalcRes = dataManager.loadValues('select a.contractPosition.contract.id, sum(a.amount), sum(a.totalSum) from rtneo$Accrual a where a.contractPosition.contract.accepted = true and a.contractPosition.isFactRecalculation = true and a.period between \'2019-01-01\' and \'2019-12-31\' group by a.contractPosition.contract.id order by a.contractPosition.contract.createTs desc') .properties("contract_id", "amount", "sum") .list() amount = recalcRes[0].getValue("amount") sum = recalcRes[0].getValue("sum")
}else if(areaNotIsNull){ if(i1.getValue()['isArea'][0] && i1.getValue()['owner'][0].compareTo(1)!=0){ amount = i1.getValue().stream().map{e -> e["share"] == null || e["share"].compareTo(0)==0 ? e["area"]*e["norm"] : e["area"]*e["share"]*e["norm"]}.reduce{v1, v2 -> v1.add(v2)}.orElse(0) }else{ if(i1.getValue()['calculationAmount'][0] == 0){ prim = prim+"calculationAmount is null, " amount = i1.getValue().stream().map{e -> e["area"]*e["ratio"]*e["norm"]}.reduce{v1, v2 -> v1.add(v2)}.orElse(0) }else{ amount = i1.getValue().stream().map{e -> e["calculationAmount"]*e["norm"]}.reduce{v1, v2 -> v1.add(v2)}.orElse(0) } } def periodI = amount/2*tariffI def periodII = amount/2*tariffII sum = periodI + periodII
def df = new SimpleDateFormat("yyyy-MM-dd") /** * */ Date startIHalfYear = df.parse('2019-01-01') Date endIHalfYear = df.parse('2019-06-30') Date startIIHalfYear = df.parse('2019-07-01') Date endIIHalfYear = df.parse('2019-12-31')
def from = i1.getValue()['from'][0] def to = i1.getValue()['to'][0]
if(from == null)from = startIHalfYear if(to == null)to = endIIHalfYear
if(from.compareTo(startIHalfYear) == -1){ from = startIHalfYear } if(to.compareTo(endIIHalfYear) == 1){ from = endIIHalfYear }
if(from.compareTo(endIHalfYear) == -1){ def useIDay = getDaysBetween(from, to) } /** * */
Date periodStart = df.parse('2019-01-01') Date periodEnd = df.parse('2019-12-31') Date midYear = df.parse('2019-06-30')
def yearDays = getDaysBetween(periodStart, periodEnd) def from = i1.getValue()['from'][0] def to = i1.getValue()['to'][0] if(from == null)from = periodStart if(to == null)to = periodEnd
def useDay = getDaysBetween(from, to)
_("${yearDays} - ${useDay}")
}
if(areaNotIsNull){ if(i1.getValue()['calculationAmount'][0] == 0){ calcAmount = i1.getValue().stream().map{e -> e["area"]*e["ratio"]}.reduce{v1, v2 -> v1.add(v2)}.orElse(0) }else{ calcAmount = i1.getValue().stream().map{e -> e["calculationAmount"]}.reduce{v1, v2 -> v1.add(v2)}.orElse(0) } area = i1.getValue().stream().map{e -> e["share"] == null || e["share"].compareTo(0)==0 ? e["area"] : e["area"]*e["share"]}.reduce{v1, v2 -> v1.add(v2)}.orElse(0) } sum = sum.setScale(2, BigDecimal.ROUND_DOWN)
_("|${i1.getValue()['personalAccount'][0]}|${i1.getValue()['name'][0]}|${i1.getValue()['address'][0]}|${i1.getValue()['cadastralNumber'][0]}|${i1.getValue()['category_name'][0]}|${area}|${calcAmount}|${i1.getValue()['norm'][0]}|${sum}|${amount}|${recalc}|${prim}".replaceAll("\\p{Cntrl}", "")) }
} //.properties("contragent_id", "personalAccount", "name", "re_id", "address", "cadastralNumber", "share", "area", "calculationAmount", "category_name", "isArea", "norm", "ratio", "owner") private String strBuilder(Object ...items){ StringBuilder b = new StringBuilder() for(def item : items){ b.append(item.toString()).append(" - ") } return b.toString() } public LocalDate convertToLocalDate(Date dateToConvert) { return dateToConvert.toInstant() .atZone(ZoneId.systemDefault()) .toLocalDate(); } private int getDaysBetween(Date one, Date two) { long days = ChronoUnit.DAYS.between(convertToLocalDate(one), convertToLocalDate(two)); if(days>0){ return(days+1); }else{ return(0-days); } } /** * Логирование */ 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)} |
|||||||
Так же в этом разделе:
|
|||||||
|
|||||||
|