| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550 |
- package com.ydtech.modules.fee.service.impl;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.ydtech.constants.enums.dict.agreement.ProductsType;
- import com.ydtech.constants.enums.dict.insurance.EnergyType;
- import com.ydtech.constants.enums.dict.insurance.NatureOfVehicleUse;
- import com.ydtech.constants.enums.dict.insurance.VehicleType;
- import com.ydtech.exception.SystemException;
- import com.ydtech.modules.admin.model.SysUser;
- import com.ydtech.modules.admin.service.SysChannelGroupService;
- import com.ydtech.modules.admin.service.SysSwitchConfigService;
- import com.ydtech.modules.admin.service.SysUserAccountService;
- import com.ydtech.modules.admin.service.SysUserService;
- import com.ydtech.modules.esm.model.EsmRetail;
- import com.ydtech.modules.esm.model.EsmUserReferrer;
- import com.ydtech.modules.esm.service.EsmRetailService;
- import com.ydtech.modules.esm.service.EsmUserReferrerService;
- import com.ydtech.modules.fee.constants.CostAllocation;
- import com.ydtech.modules.fee.dto.po.InsFeeOrderConfig;
- import com.ydtech.modules.fee.dto.vo.ReCalcuLateProportion;
- import com.ydtech.modules.fee.dto.vo.RetailProportion;
- import com.ydtech.modules.fee.dto.vo.RuleAttrMappingVo;
- import com.ydtech.modules.fee.service.FeeRuleSchemeNewService;
- import com.ydtech.modules.fee.service.FeeRuleSchemeService;
- import com.ydtech.modules.fee.service.InsFeeOrderConfigService;
- import com.ydtech.modules.fee.service.InsFeeOrderNewHistoryService;
- import com.ydtech.modules.ins.model.vo.QuoteRespVo;
- import com.ydtech.modules.order.entity.InsAreaCompany;
- import com.ydtech.modules.order.entity.InsOrders;
- import com.ydtech.modules.order.entity.api.dajia.constants.TypeVehicleMapping;
- import com.ydtech.modules.order.entity.vo.ExternalOrderFeeVo;
- import com.ydtech.modules.order.entity.vo.FeeOrderNewVo;
- import com.ydtech.modules.order.entity.vo.QueryOrderFeeResultVo;
- import com.ydtech.modules.order.entity.vo.QueryOrderFeeVo;
- import com.ydtech.modules.order.service.InsOrdersService;
- import com.ydtech.modules.protocol.entity.po.PtlAgreement;
- import com.ydtech.modules.protocol.entity.po.PtlNewCarJudgeRules;
- import com.ydtech.modules.protocol.service.PtlAgreementService;
- import com.ydtech.modules.protocol.service.PtlNewCarJudgeRulesService;
- import com.ydtech.modules.protocols.entity.po.*;
- import com.ydtech.modules.protocols.entity.vo.AgreementProductCosts;
- import com.ydtech.modules.protocols.service.*;
- import com.ydtech.utils.idgen.IdGenerate;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import javax.annotation.Resource;
- import java.math.BigDecimal;
- import java.math.BigInteger;
- import java.math.RoundingMode;
- import java.text.DateFormat;
- import java.time.LocalDate;
- import java.time.LocalDateTime;
- import java.time.format.DateTimeFormatter;
- import java.util.*;
- import java.util.concurrent.atomic.AtomicBoolean;
- import java.util.stream.Collectors;
- /**
- * @author: tz
- * @description: 费用接口中相关功能的实现类
- * @create: 2024-3-1 11:45:33
- */
- @Service
- public class FeeRuleSchemeServiceNewImpl implements FeeRuleSchemeNewService {
- private static final Logger log = LoggerFactory.getLogger("fee");
- @Resource
- private InsOrdersService insOrdersService;
- @Resource
- private PtlAgreementProductCostsNewService ptlAgreementProductCostsNewService;
- @Resource
- private PtlAgreementUndwrtRulesAttrService ptlAgreementUndwrtRulesAttrService;
- @Resource
- private PtlAgreementProductCostsExportService ptlAgreementProductCostsExportService;
- @Resource
- private PtlAgreementProductCostsAttrLinkService ptlAgreementProductCostsAttrLinkService;
- @Resource
- private PtlAgreementUndwrtRulesNewService ptlAgreementUndwrtRulesNewService;
- @Resource
- private SysUserService sysUserService;
- @Resource
- private EsmRetailService esmRetailService;
- @Resource
- private InsFeeOrderNewService insFeeOrderNewService;
- @Autowired
- private EsmUserReferrerService esmUserReferrerService;
- @Autowired
- private SysUserAccountService sysUserAccountService;
- @Autowired
- private PtlNewCarJudgeRulesService ptlNewCarJudgeRulesService;
- @Autowired
- private PtlAgreementService ptlAgreementService;
- @Autowired
- private FeeRuleSchemeService feeRuleSchemeService;
- @Autowired
- private InsFeeOrderConfigService insFeeOrderConfigService;
- @Autowired
- private SysSwitchConfigService sysSwitchConfigService;
- @Autowired
- private InsFeeOrderNewHistoryService insFeeOrderNewHistoryService;
- @Autowired
- private SysChannelGroupService sysChannelGroupService;
- @Override
- public QueryOrderFeeVo queryFeeOrderInfo(String companyId) {
- return null;
- }
- @Override
- public List<QueryOrderFeeResultVo> convertOrderFeeVoData(QueryOrderFeeVo orderFeeVo) {
- return null;
- }
- @Override
- public void compareAndUpdateFeeOrderInfo(String insOrderNo, String jqCostsProportionStr, String syCostsProportionStr, String dealUser) {
- }
- /**
- * 校验费用因子
- */
- @Override
- public void verificationCostFactor(QuoteRespVo quoteRespVo, InsAreaCompany insAreaCompany, InsOrders insOrders, StringBuilder logs, boolean isInternalAgreement) {
- List<AgreementProductCosts> agreementProductCostsNoMatched =
- ptlAgreementProductCostsNewService.costsGetList(insAreaCompany.getAgreementId(), insAreaCompany.getProductid());
- List<AgreementProductCosts> agreementProductCosts = new ArrayList<>();
- //过滤费用因子 根据使用性质,能源种类,车辆种类过滤
- agreementProductCostsNoMatched.forEach(item->{
- AtomicBoolean matching = new AtomicBoolean(true);
- item.getCostsAttrLinks().forEach(attr->{
- //判断能源类型 燃油 新能源
- if(attr.getAttrCode().equals("NewEnergy")){
- //传入的能源类型
- String energyType = EnergyType.isNewEnergy(insOrders.getCarinfo().getString("energyType")) ? "1" : "0";
- if(!attr.getMin().equals(energyType)) {
- matching.set(false);
- }
- }
- //使用性质 营业 非营业
- if(attr.getAttrCode().equals("NatureOfUse")){
- String[] split = attr.getMin().split(",");
- boolean isPipei = false;
- for(int i=0;i<split.length;i++){
- if(split[i].equals(TypeVehicleMapping.getByCode(insOrders.getCarinfo().getString("vehicleUse")))){
- isPipei = true;
- }
- }
- if(!isPipei){
- matching.set(false);
- }
- }
- //车辆种类 客车 货车
- if(attr.getAttrCode().equals("CarType")){
- if(!attr.getMin().contains(VehicleType.getByCode(insOrders.getCarinfo().getString("cimodelclass")))){
- matching.set(false);
- }
- }
- });
- if(matching.get()){
- agreementProductCosts.add(item);
- }
- });
- // if(agreementProductCosts == null || agreementProductCosts.size() == 0){
- // throw new SystemException("协议费用因子为空");
- // }
- for (int i = 0; i < agreementProductCosts.size(); i++) {
- if (agreementProductCosts.get(i).getPriorityLevel() == null) {
- agreementProductCosts.get(i).setPriorityLevel(10);
- }
- }
- if (!agreementProductCosts.isEmpty()) {
- //按优先级进行排序
- Collections.sort(agreementProductCosts, Comparator.comparingInt(AgreementProductCosts::getPriorityLevel));
- //遍历费用因子
- String costsId = verificationCosts(agreementProductCosts, quoteRespVo, insAreaCompany, insOrders, logs);
- if (costsId != null) {
- calcCosts(costsId, insAreaCompany, isInternalAgreement);
- log.debug("费用因子校验通过,子订单id:" + insAreaCompany.getId() + ",费用id:" + costsId);
- }
- } else {
- logs.append("没有找到该协议的费用信息" + "\n");
- }
- }
- /**
- * 校验承保规则
- *
- * @param insAreaCompany
- * @param insOrders
- */
- @Override
- public void verificationRuleFactor(InsAreaCompany insAreaCompany, InsOrders insOrders) {
- List<PtlAgreementUndwrtRulesNew> ptlAgreementUndwrtRules =
- ptlAgreementUndwrtRulesNewService.rulesList(insAreaCompany.getAgreementId());
- verificationRules(ptlAgreementUndwrtRules, insAreaCompany, insOrders);
- }
- //BigDecimal取两位
- private BigDecimal twoPeople(BigDecimal number) {
- return number.setScale(2, BigDecimal.ROUND_DOWN);
- }
- /**
- * 重新计算分销和机构比例
- *
- * @param sumCostsProportion 总入口费用比例
- * @param deptProportion 机构管理总比例
- * @param retailProportion 默认分销总比例
- * @param retailLevel 分销级别
- * @return 如果不够减则 返回新的分销比例
- */
- public ReCalcuLateProportion recalculateProportion(BigDecimal sumCostsProportion,
- BigDecimal deptProportion,
- BigDecimal retailProportion,
- BigDecimal taxRadio,
- Integer retailLevel,
- PtlAgreementProductCostsExport ptlAgreementProductCostsExport,
- RetailProportion originalRetailProportion,
- String type,
- BigDecimal enterProportion) {
- ReCalcuLateProportion reCalcuLateProportion = new ReCalcuLateProportion();
- BigDecimal costsProportion = sumCostsProportion.divide(taxRadio, 2, BigDecimal.ROUND_DOWN);
- List<InsFeeOrderConfig> list = insFeeOrderConfigService.list();
- //总比例 / 比例 / 分销等级
- // 不够减扣除比例
- Map<String, BigDecimal> notEnoughReduce = list.stream().collect(Collectors.toMap(InsFeeOrderConfig::getKeyword, InsFeeOrderConfig::getVal));
- //分销配置的比例
- BigDecimal retailProportionConfig = notEnoughReduce.get(CostAllocation.CA_01.getCode());
- BigDecimal retailSettingProportion = new BigDecimal(retailProportionConfig.toString());
- // 机构配置的比例
- BigDecimal deptProportionConfig = notEnoughReduce.get(CostAllocation.CA_02.getCode());
- // 代课录单比例
- BigDecimal proxyProportionConfig = notEnoughReduce.get(CostAllocation.CA_03.getCode());
- BigDecimal deptSettingProportion = new BigDecimal(deptProportionConfig.toString());
- //机构比例均分
- BigDecimal jqAverageDept = twoPeople(twoPeople(costsProportion.multiply(deptSettingProportion)).divide(new BigDecimal(5)));
- //如果不够减的话
- if (deptProportion.add(retailProportion).add(enterProportion).compareTo(costsProportion) > 0) {
- //分销比例均分
- BigDecimal jqAverageRetail = new BigDecimal(0);
- if (retailLevel != 0) {
- jqAverageRetail = twoPeople(twoPeople(costsProportion.multiply(retailSettingProportion)).divide(new BigDecimal(retailLevel), 2, RoundingMode.DOWN));
- }
- if (enterProportion.compareTo(BigDecimal.ZERO) == 0) {
- reCalcuLateProportion.setProxyProportion(BigDecimal.ZERO);
- } else {
- // 代客比例
- BigDecimal proxyProportion = costsProportion.multiply(proxyProportionConfig);
- reCalcuLateProportion.setProxyProportion(twoPeople(proxyProportion));
- }
- if (retailLevel >= 3) {
- reCalcuLateProportion.setRetail_level_3_proportion(jqAverageRetail);
- }
- if (retailLevel >= 2) {
- reCalcuLateProportion.setRetail_level_2_proportion(jqAverageRetail);
- }
- if (retailLevel >= 1) {
- reCalcuLateProportion.setRetail_level_1_proportion(jqAverageRetail);
- }
- reCalcuLateProportion.setDept_level_1_proportion(jqAverageDept);
- reCalcuLateProportion.setDept_level_2_proportion(jqAverageDept);
- reCalcuLateProportion.setDept_level_3_proportion(jqAverageDept);
- reCalcuLateProportion.setDept_level_4_proportion(jqAverageDept);
- reCalcuLateProportion.setDept_level_5_proportion(jqAverageDept);
- } else {
- if (type.equals("jq")) {
- reCalcuLateProportion.setDept_level_1_proportion(ptlAgreementProductCostsExport.getJqExportRadioLevel1());
- reCalcuLateProportion.setDept_level_2_proportion(ptlAgreementProductCostsExport.getJqExportRadioLevel2());
- reCalcuLateProportion.setDept_level_3_proportion(ptlAgreementProductCostsExport.getJqExportRadioLevel3());
- reCalcuLateProportion.setDept_level_4_proportion(ptlAgreementProductCostsExport.getJqExportRadioLevel4());
- reCalcuLateProportion.setDept_level_5_proportion(ptlAgreementProductCostsExport.getJqExportRadioLevel5());
- reCalcuLateProportion.setRetail_level_1_proportion(originalRetailProportion.getJqRetailLevel1Proportion());
- reCalcuLateProportion.setRetail_level_2_proportion(originalRetailProportion.getJqRetailLevel2Proportion());
- reCalcuLateProportion.setRetail_level_3_proportion(originalRetailProportion.getJqRetailLevel3Proportion());
- } else if (type.equals("sy")) {
- reCalcuLateProportion.setDept_level_1_proportion(ptlAgreementProductCostsExport.getSyExportRadioLevel1());
- reCalcuLateProportion.setDept_level_2_proportion(ptlAgreementProductCostsExport.getSyExportRadioLevel2());
- reCalcuLateProportion.setDept_level_3_proportion(ptlAgreementProductCostsExport.getSyExportRadioLevel3());
- reCalcuLateProportion.setDept_level_4_proportion(ptlAgreementProductCostsExport.getSyExportRadioLevel4());
- reCalcuLateProportion.setDept_level_5_proportion(ptlAgreementProductCostsExport.getSyExportRadioLevel5());
- reCalcuLateProportion.setRetail_level_1_proportion(originalRetailProportion.getSyRetailLevel1Proportion());
- reCalcuLateProportion.setRetail_level_2_proportion(originalRetailProportion.getSyRetailLevel2Proportion());
- reCalcuLateProportion.setRetail_level_3_proportion(originalRetailProportion.getSyRetailLevel3Proportion());
- } else if (type.equals("no")) {
- reCalcuLateProportion.setDept_level_1_proportion(ptlAgreementProductCostsExport.getNoCarExportRadioLevel1());
- reCalcuLateProportion.setDept_level_2_proportion(ptlAgreementProductCostsExport.getNoCarExportRadioLevel2());
- reCalcuLateProportion.setDept_level_3_proportion(ptlAgreementProductCostsExport.getNoCarExportRadioLevel3());
- reCalcuLateProportion.setDept_level_4_proportion(ptlAgreementProductCostsExport.getNoCarExportRadioLevel4());
- reCalcuLateProportion.setDept_level_5_proportion(ptlAgreementProductCostsExport.getNoCarExportRadioLevel5());
- reCalcuLateProportion.setRetail_level_1_proportion(originalRetailProportion.getNoRetailLevel1Proportion());
- reCalcuLateProportion.setRetail_level_2_proportion(originalRetailProportion.getNoRetailLevel2Proportion());
- reCalcuLateProportion.setRetail_level_3_proportion(originalRetailProportion.getNoRetailLevel3Proportion());
- }
- // 代课比例
- reCalcuLateProportion.setProxyProportion(enterProportion);
- }
- return reCalcuLateProportion;
- }
- /**
- * 计算费用
- *
- * @param costsId
- * @param insAreaCompany
- */
- @Override
- public void calcCosts(String costsId, InsAreaCompany insAreaCompany, boolean isInternalAgreement) {
- //获取协议信息
- PtlAgreement ptlAgreement = ptlAgreementService.getById(insAreaCompany.getAgreementId());
- InsOrders insOrders = insOrdersService.getById(insAreaCompany.getOrderno());
- SysUser sysUser = sysUserService.findByUserId(insOrders.getUserid());
- BigDecimal taxRadio = new BigDecimal("1.00");
- //如果是外部订单则 不含税
- if (ptlAgreement.getWithTax().equals("否") && ptlAgreement.getIsExternal() == 0) {
- taxRadio = new BigDecimal("1.06");
- }
- //税比例 固定1.06
- //查找入口与出口费用比例
- //入口配置
- PtlAgreementProductCostsNew ptlAgreementProductCostsNew = ptlAgreementProductCostsNewService.getById(costsId);
- ptlAgreementProductCostsNew.blank();
- //出口配置
- PtlAgreementProductCostsExport ptlAgreementProductCostsExport =
- ptlAgreementProductCostsExportService.getOne(new LambdaQueryWrapper<PtlAgreementProductCostsExport>().eq(PtlAgreementProductCostsExport::getCostsId, costsId));
- InsFeeOrderNew insFeeOrderNew = new InsFeeOrderNew();
- insFeeOrderNew.setId(IdGenerate.nextId());
- insFeeOrderNew.setCostsId(costsId);
- insFeeOrderNew.setAgreementId(insAreaCompany.getAgreementId());
- //存储部门id与用户id
- InsOrders order = insOrdersService.getById(insAreaCompany.getOrderno());
- InsFeeOrderNew insFeeOrderNewByCompanyId = insFeeOrderNewService.getInsFeeOrderNewByCompanyId(insAreaCompany.getId());
- if (insFeeOrderNewByCompanyId != null) {
- insFeeOrderNew.setId(insFeeOrderNewByCompanyId.getId());
- }
- insFeeOrderNew.setDeptId(order.getDeptid());
- insFeeOrderNew.setUserId(order.getUserid());
- insFeeOrderNew.setInsOrderNo(insAreaCompany.getId());
- insFeeOrderNew.setJqPremium(insAreaCompany.getJqpremium());
- insFeeOrderNew.setSyPremium(insAreaCompany.getSypremium());
- insFeeOrderNew.setNoPremium(insAreaCompany.getJypremium());
- //不含税
- BigDecimal bigDecimal = new BigDecimal("1.06");
- insFeeOrderNew.setJqNoTaxPremium(insAreaCompany.getJqpremium().divide(bigDecimal, 2));
- insFeeOrderNew.setSyNoTaxPremium(insAreaCompany.getSypremium().divide(bigDecimal, 2));
- insFeeOrderNew.setNoNoTaxPremium(insAreaCompany.getJypremium().divide(bigDecimal, 2));
- //region 计算入口费用
- //交强入口信息
- FeeOrderNewVo.EntranceFee jqEntranceFee = feeRuleSchemeService.calcEntranceFee(
- insFeeOrderNew.getJqPremium(),
- new BigDecimal(ptlAgreementProductCostsNew.getJqCarCostsProportion()),
- new BigDecimal(ptlAgreementProductCostsNew.getJqCarOtherCostsProportion()),
- taxRadio);
- insFeeOrderNew.setJqCostsProportion(jqEntranceFee.getTotalProportion());
- insFeeOrderNew.setJqSuperviseCostsProportion(jqEntranceFee.getSuperviseCosts());
- insFeeOrderNew.setJqSuperviseCostsPremiums(jqEntranceFee.getSuperviseCostsPremiums());
- insFeeOrderNew.setJqOtherCostsProportion(jqEntranceFee.getOtherCostsProportion());
- insFeeOrderNew.setJqOtherCostsPremiums(jqEntranceFee.getOtherCostsPremiums());
- insFeeOrderNew.setJqCostsPremiums(insFeeOrderNew.getJqSuperviseCostsPremiums().add(insFeeOrderNew.getJqOtherCostsPremiums()));
- //商业入口信息
- FeeOrderNewVo.EntranceFee syEntranceFee = feeRuleSchemeService.calcEntranceFee(insFeeOrderNew.getSyPremium(),
- new BigDecimal(ptlAgreementProductCostsNew.getSyCarCostsProportion()) ,
- new BigDecimal(ptlAgreementProductCostsNew.getSyCarOtherCostsProportion()), taxRadio);
- insFeeOrderNew.setSyCostsProportion(syEntranceFee.getTotalProportion());
- insFeeOrderNew.setSySuperviseCostsProportion(syEntranceFee.getSuperviseCosts());
- insFeeOrderNew.setSySuperviseCostsPremiums(syEntranceFee.getSuperviseCostsPremiums());
- insFeeOrderNew.setSyOtherCostsProportion(syEntranceFee.getOtherCostsProportion());
- insFeeOrderNew.setSyOtherCostsPremiums(syEntranceFee.getOtherCostsPremiums());
- insFeeOrderNew.setSyCostsPremiums(insFeeOrderNew.getSySuperviseCostsPremiums().add(insFeeOrderNew.getSyOtherCostsPremiums()));
- //非车入口信息
- FeeOrderNewVo.EntranceFee noEntranceFee = feeRuleSchemeService.calcEntranceFee(insFeeOrderNew.getNoPremium(),
- new BigDecimal(ptlAgreementProductCostsNew.getNoCarCostsProportion()),
- new BigDecimal(ptlAgreementProductCostsNew.getNoCarOtherCostsProportion()), taxRadio);
- insFeeOrderNew.setNoCostsProportion(noEntranceFee.getTotalProportion());
- insFeeOrderNew.setNoSuperviseCostsProportion(noEntranceFee.getSuperviseCosts());
- insFeeOrderNew.setNoSuperviseCostsPremiums(noEntranceFee.getSuperviseCostsPremiums());
- insFeeOrderNew.setNoOtherCostsProportion(noEntranceFee.getOtherCostsProportion());
- insFeeOrderNew.setNoOtherCostsPremiums(noEntranceFee.getOtherCostsPremiums());
- insFeeOrderNew.setNoCostsPremiums(insFeeOrderNew.getNoSuperviseCostsPremiums().add(insFeeOrderNew.getNoOtherCostsPremiums()));
- //endregion
- //region 重新计算管理费比例和分销比例
- List<EsmRetail> esmRetailList = esmRetailService.selectList(" where t.deptid=? and t.status = '1' ",
- new Object[]{sysUser.getDeptId()});
- Integer retailLevel = 0;
- //默认分销比例设置
- RetailProportion retailProportion = new RetailProportion();
- if (!Objects.isNull(esmRetailList) && !esmRetailList.isEmpty()) {
- retailLevel = Integer.parseInt(esmRetailList.get(0).getRetailtype());
- //赋值默认的分销比例
- retailProportion.setProportion(esmRetailList.get(0).getDisrate1(), esmRetailList.get(0).getDisrate2(), esmRetailList.get(0).getDisrate3());
- }
- //获取交强机构管理费总比例
- BigDecimal jqDeptProportion = ptlAgreementProductCostsExport.getJqExportRadioLevel1()
- .add(ptlAgreementProductCostsExport.getJqExportRadioLevel2())
- .add(ptlAgreementProductCostsExport.getJqExportRadioLevel3())
- .add(ptlAgreementProductCostsExport.getJqExportRadioLevel4())
- .add(ptlAgreementProductCostsExport.getJqExportRadioLevel5());
- //获取商业机构管理费总比例
- BigDecimal syDeptProportion = ptlAgreementProductCostsExport.getSyExportRadioLevel1()
- .add(ptlAgreementProductCostsExport.getSyExportRadioLevel2())
- .add(ptlAgreementProductCostsExport.getSyExportRadioLevel3())
- .add(ptlAgreementProductCostsExport.getSyExportRadioLevel4())
- .add(ptlAgreementProductCostsExport.getSyExportRadioLevel5());
- //获取非车机构管理费总比例
- BigDecimal noDeptProportion = ptlAgreementProductCostsExport.getNoCarExportRadioLevel1()
- .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel2())
- .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel3())
- .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel4())
- .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel5());
- //获取交强分销总比例
- BigDecimal jqRetailProportion = retailProportion.getJqRetailLevel1Proportion()
- .add(retailProportion.getJqRetailLevel2Proportion())
- .add(retailProportion.getJqRetailLevel3Proportion());
- //获取商业分销总比例
- BigDecimal syRetailProportion = retailProportion.getSyRetailLevel1Proportion()
- .add(retailProportion.getSyRetailLevel2Proportion())
- .add(retailProportion.getSyRetailLevel3Proportion());
- //获取非车分销总比例
- BigDecimal noRetailProportion = retailProportion.getNoRetailLevel1Proportion()
- .add(retailProportion.getNoRetailLevel2Proportion())
- .add(retailProportion.getNoRetailLevel3Proportion());
- BigDecimal enterProportion = new BigDecimal(BigInteger.ZERO);
-
- // 待客录单订单比例 根据前端传值 判断是否使用待客录单比例
- if(!isInternalAgreement){
- enterProportion = sysSwitchConfigService.getEnterProportion(insOrders.getDeptid(), insOrders.getEntryStatus());
- }
-
- //重新计算比例 入口是否超出支付的比例
- ReCalcuLateProportion jqReCalcuLateProportion = recalculateProportion(
- new BigDecimal(ptlAgreementProductCostsNew.getJqCostsProportion()),
- jqDeptProportion,
- jqRetailProportion,
- taxRadio,
- retailLevel,
- ptlAgreementProductCostsExport,
- retailProportion,
- "jq",
- enterProportion
- );
- ReCalcuLateProportion syReCalcuLateProportion = recalculateProportion(
- new BigDecimal(ptlAgreementProductCostsNew.getSyCostsProportion()),
- syDeptProportion,
- syRetailProportion,
- taxRadio,
- retailLevel,
- ptlAgreementProductCostsExport,
- retailProportion,
- "sy",
- enterProportion
- );
- ReCalcuLateProportion noReCalcuLateProportion = recalculateProportion(
- new BigDecimal(ptlAgreementProductCostsNew.getNoCostsProportion()),
- noDeptProportion,
- noRetailProportion,
- taxRadio,
- retailLevel,
- ptlAgreementProductCostsExport,
- retailProportion,
- "no",
- enterProportion
- );
- retailProportion.setProportion(jqReCalcuLateProportion, syReCalcuLateProportion, noReCalcuLateProportion);
- // ptlAgreementProductCostsExportService.updateById(ptlAgreementProductCostsExport);
- //endregion
- //region 计算分销费用
- //获取分销比例
- //分销总比例
- BigDecimal jqRetailRadio = new BigDecimal("0");
- BigDecimal syRetailRadio = new BigDecimal("0");
- BigDecimal noRetailRadio = new BigDecimal("0");
- FeeOrderNewVo.RetailFee retailFeeLevel3 = new FeeOrderNewVo.RetailFee();
- FeeOrderNewVo.RetailFee retailFeeLevel2 = new FeeOrderNewVo.RetailFee();
- FeeOrderNewVo.RetailFee retailFeeLevel1 = new FeeOrderNewVo.RetailFee();
- if (esmRetailList != null && !esmRetailList.isEmpty()) {
- EsmRetail esmRetail = esmRetailList.get(0);
- //分销等级
- insFeeOrderNew.setDistributionStatus(esmRetailList.get(0).getRetailtype());
- //用户分销人员id
- List<EsmUserReferrer> parents = esmUserReferrerService.findParents(sysUser.getId());
- if (esmRetail != null) {
- if (Integer.parseInt(esmRetail.getRetailtype()) >= 3) {
- insFeeOrderNew.setThirdDetailProportion(retailProportion.getJqRetailLevel3Proportion());
- retailFeeLevel3 = feeRuleSchemeService.calcRetail(insFeeOrderNew.getJqPremium(),
- insFeeOrderNew.getJqCostsProportion(),
- insFeeOrderNew.getSyPremium(),
- insFeeOrderNew.getSyCostsProportion().add(insFeeOrderNew.getSyOtherCostsProportion()),
- insFeeOrderNew.getNoPremium(),
- insFeeOrderNew.getNoCostsProportion().add(insFeeOrderNew.getNoOtherCostsProportion()),
- retailProportion.getJqRetailLevel3Proportion(),
- retailProportion.getSyRetailLevel3Proportion(),
- retailProportion.getNoRetailLevel3Proportion());
- insFeeOrderNew.setThirdDetailPremiums(retailFeeLevel3.getTotalRetailPremiums());
- if (parents != null && parents.size() > 2) {
- insFeeOrderNew.setThreeLevelUserId(parents.get(2).getId());
- }
- } else {
- insFeeOrderNew.setThirdDetailProportion(new BigDecimal(0));
- }
- if (Integer.parseInt(esmRetail.getRetailtype()) >= 2) {
- insFeeOrderNew.setSecondDetailProportion(retailProportion.getJqRetailLevel2Proportion());
- retailFeeLevel2 = feeRuleSchemeService.calcRetail(insFeeOrderNew.getJqPremium(),
- insFeeOrderNew.getJqCostsProportion(),
- insFeeOrderNew.getSyPremium(),
- insFeeOrderNew.getSyCostsProportion(),
- insFeeOrderNew.getNoPremium(),
- insFeeOrderNew.getNoCostsProportion(),
- retailProportion.getJqRetailLevel2Proportion(),
- retailProportion.getSyRetailLevel2Proportion(),
- retailProportion.getNoRetailLevel2Proportion());
- insFeeOrderNew.setSecondDetailPremiums(retailFeeLevel2.getTotalRetailPremiums());
- if (parents != null && parents.size() > 1) {
- insFeeOrderNew.setTwoLevelUserId(parents.get(1).getId());
- }
- } else {
- insFeeOrderNew.setSecondDetailProportion(new BigDecimal(0));
- }
- if (Integer.parseInt(esmRetail.getRetailtype()) >= 1) {
- insFeeOrderNew.setFirstDetailProportion(retailProportion.getJqRetailLevel1Proportion());
- retailFeeLevel1 = feeRuleSchemeService.calcRetail(insFeeOrderNew.getJqPremium(),
- insFeeOrderNew.getJqCostsProportion(),
- insFeeOrderNew.getSyPremium(),
- insFeeOrderNew.getSyCostsProportion(),
- insFeeOrderNew.getNoPremium(),
- insFeeOrderNew.getNoCostsProportion(),
- retailProportion.getJqRetailLevel1Proportion(),
- retailProportion.getSyRetailLevel1Proportion(),
- retailProportion.getNoRetailLevel1Proportion());
- insFeeOrderNew.setFirstDetailPremiums(retailFeeLevel1.getTotalRetailPremiums());
- if (parents != null && !parents.isEmpty()) {
- insFeeOrderNew.setFirstLevelUserId(parents.get(0).getId());
- }
- } else {
- insFeeOrderNew.setFirstDetailProportion(new BigDecimal(0));
- }
- } else {
- insFeeOrderNew.setFirstDetailPremiums(new BigDecimal(0));
- insFeeOrderNew.setSecondDetailPremiums(new BigDecimal(0));
- insFeeOrderNew.setThirdDetailPremiums(new BigDecimal(0));
- }
- } else {
- insFeeOrderNew.setFirstDetailProportion(new BigDecimal(0));
- insFeeOrderNew.setSecondDetailProportion(new BigDecimal(0));
- insFeeOrderNew.setThirdDetailProportion(new BigDecimal(0));
- }
- jqRetailRadio = jqRetailRadio.add(retailFeeLevel1.getJqRetailProportion())
- .add(retailFeeLevel2.getJqRetailProportion())
- .add(retailFeeLevel3.getJqRetailProportion());
- syRetailRadio = syRetailRadio.add(retailFeeLevel1.getSyRetailProportion())
- .add(retailFeeLevel2.getSyRetailProportion())
- .add(retailFeeLevel3.getSyRetailProportion());
- noRetailRadio = noRetailRadio.add(retailFeeLevel1.getNoRetailProportion())
- .add(retailFeeLevel2.getNoRetailProportion())
- .add(retailFeeLevel3.getNoRetailProportion());
- insFeeOrderNew.assignRetail(retailFeeLevel1, retailFeeLevel2, retailFeeLevel3);
- //endregion
- //region 设置机构管理费
- //交强机构管理费
- BigDecimal jqDeptRadio =
- jqReCalcuLateProportion.getDept_level_1_proportion()
- .add(jqReCalcuLateProportion.getDept_level_2_proportion())
- .add(jqReCalcuLateProportion.getDept_level_3_proportion())
- .add(jqReCalcuLateProportion.getDept_level_4_proportion())
- .add(jqReCalcuLateProportion.getDept_level_5_proportion());
- FeeOrderNewVo.DeptManagerFee jqDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(
- insFeeOrderNew.getJqPremium(),
- jqReCalcuLateProportion.getDept_level_1_proportion(),
- jqReCalcuLateProportion.getDept_level_2_proportion(),
- jqReCalcuLateProportion.getDept_level_3_proportion(),
- jqReCalcuLateProportion.getDept_level_4_proportion(),
- jqReCalcuLateProportion.getDept_level_5_proportion());
- BigDecimal syDeptRadio =
- syReCalcuLateProportion.getDept_level_1_proportion()
- .add(syReCalcuLateProportion.getDept_level_2_proportion())
- .add(syReCalcuLateProportion.getDept_level_3_proportion())
- .add(syReCalcuLateProportion.getDept_level_4_proportion())
- .add(syReCalcuLateProportion.getDept_level_5_proportion());
- FeeOrderNewVo.DeptManagerFee syDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(
- insFeeOrderNew.getSyPremium(),
- syReCalcuLateProportion.getDept_level_1_proportion(),
- syReCalcuLateProportion.getDept_level_2_proportion(),
- syReCalcuLateProportion.getDept_level_3_proportion(),
- syReCalcuLateProportion.getDept_level_4_proportion(),
- syReCalcuLateProportion.getDept_level_5_proportion());
- BigDecimal noDeptRadio =
- noReCalcuLateProportion.getDept_level_1_proportion()
- .add(noReCalcuLateProportion.getDept_level_2_proportion())
- .add(noReCalcuLateProportion.getDept_level_3_proportion())
- .add(noReCalcuLateProportion.getDept_level_4_proportion())
- .add(noReCalcuLateProportion.getDept_level_5_proportion());
- FeeOrderNewVo.DeptManagerFee noDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(
- insFeeOrderNew.getNoPremium(),
- noReCalcuLateProportion.getDept_level_1_proportion(),
- noReCalcuLateProportion.getDept_level_2_proportion(),
- noReCalcuLateProportion.getDept_level_3_proportion(),
- noReCalcuLateProportion.getDept_level_4_proportion(),
- noReCalcuLateProportion.getDept_level_5_proportion());
- insFeeOrderNew.assignDept(jqDeptManagerFee, syDeptManagerFee, noDeptManagerFee);
- //endregion
- //region 出口费用
- //交强出口手续费比例
- FeeOrderNewVo.ExportFee jqExportFee = feeRuleSchemeService.calcExportFee(
- insFeeOrderNew.getJqPremium(),
- new BigDecimal(ptlAgreementProductCostsNew.getJqCostsExportProportion()),
- insFeeOrderNew.getJqCostsProportion(),
- jqDeptRadio,
- jqRetailRadio,
- taxRadio,
- jqReCalcuLateProportion.getProxyProportion()
- );
- //商业出口手续费比例
- FeeOrderNewVo.ExportFee syExportFee = feeRuleSchemeService.calcExportFee(
- insFeeOrderNew.getSyPremium(),
- new BigDecimal(ptlAgreementProductCostsNew.getSyCostsExportProportion()),
- insFeeOrderNew.getSyCostsProportion(),
- syDeptRadio,
- syRetailRadio,
- taxRadio,
- syReCalcuLateProportion.getProxyProportion()
- );
- //非车出口手续费比例
- FeeOrderNewVo.ExportFee noExportFee = feeRuleSchemeService.calcExportFee(
- insFeeOrderNew.getNoPremium(),
- new BigDecimal(ptlAgreementProductCostsNew.getNoCostsExportProportion()),
- insFeeOrderNew.getNoCostsProportion(),
- noDeptRadio,
- noRetailRadio,
- taxRadio,
- noReCalcuLateProportion.getProxyProportion()
- );
- //出口手续费用
- insFeeOrderNew.setJqExportSuperviseCostsPremiums(twoPeople(jqExportFee.getSuperviseCostsPremiums()));
- insFeeOrderNew.setSyExportSuperviseCostsPremiums(twoPeople(syExportFee.getSuperviseCostsPremiums()));
- insFeeOrderNew.setNoExportSuperviseCostsPremiums(twoPeople(noExportFee.getSuperviseCostsPremiums()));
- //出口其他费用比例
- insFeeOrderNew.setJqExportOtherCostsProportion(twoPeople(jqExportFee.getOtherCostsProportion()));
- insFeeOrderNew.setSyExportOtherCostsProportion(twoPeople(syExportFee.getOtherCostsProportion()));
- insFeeOrderNew.setNoExportOtherCostsProportion(twoPeople(noExportFee.getOtherCostsProportion()));
- //出口其他费用
- insFeeOrderNew.setJqExportOtherCostsPremiums(twoPeople(jqExportFee.getOtherCostsPremiums()));
- insFeeOrderNew.setSyExportOtherCostsPremiums(twoPeople(syExportFee.getOtherCostsPremiums()));
- insFeeOrderNew.setNoExportOtherCostsPremiums(twoPeople(noExportFee.getOtherCostsPremiums()));
- //设置出口手续费比例
- insFeeOrderNew.setJqCostsExportProportion(twoPeople(jqExportFee.getSuperviseCosts()));
- insFeeOrderNew.setSyCostsExportProportion(twoPeople(syExportFee.getSuperviseCosts()));
- insFeeOrderNew.setNoCostsExportProportion(twoPeople(noExportFee.getSuperviseCosts()));
- // 外部费用
- insFeeOrderNew.setJqExternalProportion(jqExportFee.getExternalProportion());
- insFeeOrderNew.setJqExternalPremiums(jqExportFee.getExternalPremiums());
- insFeeOrderNew.setSyExternalProportion(syExportFee.getExternalProportion());
- insFeeOrderNew.setSyExternalPremiums(syExportFee.getExternalPremiums());
- insFeeOrderNew.setNoExternalProportion(noExportFee.getExternalProportion());
- insFeeOrderNew.setNoExternalPremiums(noExportFee.getExternalPremiums());
- //endregion
- //region 计算利润差值
- //入口 - 出口 - 机构管理费 1-5级 - 分销费 = 差值
- //分销交强费用
- //分开算 1 2 3 级
- BigDecimal jqFirst = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getJqRetailProportionLevel1().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
- BigDecimal jqSecond = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getJqRetailProportionLevel2().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
- BigDecimal jqThird = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getJqRetailProportionLevel3().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
- BigDecimal jqFenXiao = jqFirst.add(jqSecond).add(jqThird);
- //分销商业费用
- BigDecimal syFirst = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getSyRetailProportionLevel1().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
- BigDecimal sySecond = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getSyRetailProportionLevel2().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
- BigDecimal syThird = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getSyRetailProportionLevel3().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
- BigDecimal syFenXiao = syFirst.add(sySecond).add(syThird);
- //分销非车费用
- BigDecimal noFirst = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getNoRetailProportionLevel1().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
- BigDecimal noSecond = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getNoRetailProportionLevel2().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
- BigDecimal noThird = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getNoRetailProportionLevel3().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
- BigDecimal noFenXiao = noFirst.add(noSecond).add(noThird);
- BigDecimal jqDifference = jqEntranceFee.getTotalAmount()
- .subtract(jqExportFee.getExternalPremiums())
- .subtract(
- (jqExportFee.getSuperviseCostsPremiums().add(jqExportFee.getOtherCostsPremiums())))
- .subtract(
- (jqDeptManagerFee.getDeptPremiumsLevelOne().add(jqDeptManagerFee.getDeptPremiumsLevelTwo().add(jqDeptManagerFee.getDeptPremiumsLevelThree()).add(jqDeptManagerFee.getDeptPremiumsLevelFoure()).add(jqDeptManagerFee.getDeptPremiumsLevelFive())))
- )
- .subtract(jqFenXiao)
- .setScale(5, BigDecimal.ROUND_HALF_DOWN);
- insFeeOrderNew.setJqProfitMarginPremiums(jqDifference);
- BigDecimal syDifference = syEntranceFee.getTotalAmount()
- .subtract(syExportFee.getExternalPremiums())
- .subtract(
- (syExportFee.getSuperviseCostsPremiums().add(syExportFee.getOtherCostsPremiums())))
- .subtract(
- (syDeptManagerFee.getDeptPremiumsLevelOne().add(syDeptManagerFee.getDeptPremiumsLevelTwo().add(syDeptManagerFee.getDeptPremiumsLevelThree()).add(syDeptManagerFee.getDeptPremiumsLevelFoure()).add(syDeptManagerFee.getDeptPremiumsLevelFive())))
- )
- .subtract(syFenXiao)
- .setScale(5, BigDecimal.ROUND_HALF_DOWN);
- insFeeOrderNew.setSyProfitMarginPremiums(syDifference);
- BigDecimal noDifference = noEntranceFee.getTotalAmount()
- .subtract(noExportFee.getExternalPremiums())
- .subtract(
- (noExportFee.getSuperviseCostsPremiums().add(noExportFee.getOtherCostsPremiums())))
- .subtract(
- (noDeptManagerFee.getDeptPremiumsLevelOne().add(noDeptManagerFee.getDeptPremiumsLevelTwo().add(noDeptManagerFee.getDeptPremiumsLevelThree()).add(noDeptManagerFee.getDeptPremiumsLevelFoure()).add(noDeptManagerFee.getDeptPremiumsLevelFive())))
- )
- .subtract(noFenXiao)
- .setScale(5, BigDecimal.ROUND_HALF_DOWN);
- insFeeOrderNew.setNoProfitMarginPremiums(noDifference);
- //endregion
- //region 比例逆推是否等于0
- if (!feeRuleSchemeService.calculateProportion(jqEntranceFee, jqDeptManagerFee, jqExportFee, jqRetailRadio, taxRadio, insFeeOrderNew.getJqPremium()))
- throw new SystemException("交强比例异常");
- if (!feeRuleSchemeService.calculateProportion(syEntranceFee, syDeptManagerFee, syExportFee, syRetailRadio, taxRadio, insFeeOrderNew.getSyPremium()))
- throw new SystemException("商业比例异常");
- if (!feeRuleSchemeService.calculateProportion(noEntranceFee, noDeptManagerFee, noExportFee, noRetailRadio, taxRadio, insFeeOrderNew.getNoPremium()))
- throw new SystemException("非车比例异常");
- //endregion
- sysChannelGroupService.costCompute(insFeeOrderNew,ptlAgreement,ptlAgreementProductCostsNew,sysUser,insAreaCompany,insOrders);
- insFeeOrderNewService.saveOrUpdate(insFeeOrderNew);
- }
- /**
- * 计算费用测试方法 没有数据库保存操作 只带入值进行计算核对
- *
- * @param costsId
- * @param insAreaCompany
- */
- @Override
- public void calcCostsTest(String costsId, InsAreaCompany insAreaCompany) {
- // //获取协议信息
- // PtlAgreement ptlAgreement = ptlAgreementService.getById(insAreaCompany.getAgreementId());
- // BigDecimal taxRadio = new BigDecimal("1.00");
- // //如果是外部订单则 不含税
- // if (ptlAgreement.getWithTax().equals("否") && ptlAgreement.getIsExternal() == 0) {
- // taxRadio = new BigDecimal("1.06");
- // }
- // //税比例 固定1.06
- // //查找入口与出口费用比例
- // //入口配置
- // PtlAgreementProductCostsNew ptlAgreementProductCostsNew = ptlAgreementProductCostsNewService.getById(costsId);
- //
- // //出口配置
- // PtlAgreementProductCostsExport ptlAgreementProductCostsExport =
- // ptlAgreementProductCostsExportService.getOne(new LambdaQueryWrapper<PtlAgreementProductCostsExport>().eq(PtlAgreementProductCostsExport::getCostsId, costsId));
- // InsFeeOrderNew insFeeOrderNew = new InsFeeOrderNew();
- // insFeeOrderNew.setId(IdGenerate.nextId());
- // insFeeOrderNew.setCostsId(costsId);
- // insFeeOrderNew.setAgreementId(insAreaCompany.getAgreementId());
- //
- // //存储部门id与用户id
- // InsOrders order = insOrdersService.getById(insAreaCompany.getOrderno());
- // InsFeeOrderNew insFeeOrderNewByCompanyId = insFeeOrderNewService.getInsFeeOrderNewByCompanyId(insAreaCompany.getId());
- // if (insFeeOrderNewByCompanyId != null) {
- // insFeeOrderNew.setId(insFeeOrderNewByCompanyId.getId());
- // }
- // insFeeOrderNew.setDeptId(order.getDeptid());
- // insFeeOrderNew.setUserId(order.getUserid());
- // insFeeOrderNew.setInsOrderNo(insAreaCompany.getId());
- // insFeeOrderNew.setJqPremium(insAreaCompany.getJqpremium());
- // insFeeOrderNew.setSyPremium(insAreaCompany.getSypremium());
- // insFeeOrderNew.setNoPremium(insAreaCompany.getJypremium());
- // //不含税
- // BigDecimal bigDecimal = new BigDecimal("1.06");
- // insFeeOrderNew.setJqNoTaxPremium(insAreaCompany.getJqpremium().divide(bigDecimal, 2));
- // insFeeOrderNew.setSyNoTaxPremium(insAreaCompany.getSypremium().divide(bigDecimal, 2));
- // insFeeOrderNew.setNoNoTaxPremium(insAreaCompany.getJypremium().divide(bigDecimal, 2));
- //
- // //region 计算入口费用
- //
- // //交强入口信息
- // FeeOrderNewVo.EntranceFee jqEntranceFee = feeRuleSchemeService.calcEntranceFee(insFeeOrderNew.getJqPremium(),
- // new BigDecimal(ptlAgreementProductCostsNew.getJqCarCostsProportion()),
- // new BigDecimal(ptlAgreementProductCostsNew.getJqCarOtherCostsProportion()), taxRadio);
- // insFeeOrderNew.setJqCostsProportion(jqEntranceFee.getTotalProportion());
- // insFeeOrderNew.setJqSuperviseCostsProportion(jqEntranceFee.getSuperviseCosts());
- // insFeeOrderNew.setJqSuperviseCostsPremiums(jqEntranceFee.getSuperviseCostsPremiums());
- // insFeeOrderNew.setJqOtherCostsProportion(jqEntranceFee.getOtherCostsProportion());
- // insFeeOrderNew.setJqOtherCostsPremiums(jqEntranceFee.getOtherCostsPremiums());
- // insFeeOrderNew.setJqCostsPremiums(insFeeOrderNew.getJqSuperviseCostsPremiums().add(insFeeOrderNew.getJqOtherCostsPremiums()));
- //
- // //商业入口信息
- // FeeOrderNewVo.EntranceFee syEntranceFee = feeRuleSchemeService.calcEntranceFee(insFeeOrderNew.getSyPremium(),
- // new BigDecimal(ptlAgreementProductCostsNew.getSyCarCostsProportion()),
- // new BigDecimal(ptlAgreementProductCostsNew.getSyCarOtherCostsProportion()), taxRadio);
- // insFeeOrderNew.setSyCostsProportion(syEntranceFee.getTotalProportion());
- // insFeeOrderNew.setSySuperviseCostsProportion(syEntranceFee.getSuperviseCosts());
- // insFeeOrderNew.setSySuperviseCostsPremiums(syEntranceFee.getSuperviseCostsPremiums());
- // insFeeOrderNew.setSyOtherCostsProportion(syEntranceFee.getOtherCostsProportion());
- // insFeeOrderNew.setSyOtherCostsPremiums(syEntranceFee.getOtherCostsPremiums());
- // insFeeOrderNew.setSyCostsPremiums(insFeeOrderNew.getSySuperviseCostsPremiums().add(insFeeOrderNew.getSyOtherCostsPremiums()));
- //
- // //非车入口信息
- // FeeOrderNewVo.EntranceFee noEntranceFee = feeRuleSchemeService.calcEntranceFee(insFeeOrderNew.getNoPremium(),
- // new BigDecimal(ptlAgreementProductCostsNew.getNoCarCostsProportion()),
- // new BigDecimal(ptlAgreementProductCostsNew.getNoCarOtherCostsProportion()), taxRadio);
- // insFeeOrderNew.setNoCostsProportion(noEntranceFee.getTotalProportion());
- // insFeeOrderNew.setNoSuperviseCostsProportion(noEntranceFee.getSuperviseCosts());
- // insFeeOrderNew.setNoSuperviseCostsPremiums(noEntranceFee.getSuperviseCostsPremiums());
- // insFeeOrderNew.setNoOtherCostsProportion(noEntranceFee.getOtherCostsProportion());
- // insFeeOrderNew.setNoOtherCostsPremiums(noEntranceFee.getOtherCostsPremiums());
- // insFeeOrderNew.setNoCostsPremiums(insFeeOrderNew.getNoSuperviseCostsPremiums().add(insFeeOrderNew.getNoOtherCostsPremiums()));
- // //endregion
- //
- // //region 计算分销费用
- // InsOrders insOrders = insOrdersService.getById(insAreaCompany.getOrderno());
- // SysUser sysUser = sysUserService.findByUserId(insOrders.getUserid());
- //
- // //获取分销比例
- // List<EsmRetail> esmRetailList = esmRetailService.selectList(" where t.deptid=? and t.status = '1' ",
- // new Object[]{sysUser.getDeptId()});
- //
- // //分销总比例
- // BigDecimal retailRadio = new BigDecimal("0");
- // if (esmRetailList != null && !esmRetailList.isEmpty()) {
- // EsmRetail esmRetail = esmRetailList.get(0);
- // //分销等级
- // insFeeOrderNew.setDistributionStatus(esmRetailList.get(0).getRetailtype());
- // //用户分销人员id
- // List<EsmUserReferrer> parents = esmUserReferrerService.findParents(sysUser.getId());
- //
- // if (esmRetail != null) {
- // BigDecimal sumPremium = insFeeOrderNew.getJqPremium().add(insFeeOrderNew.getSyPremium()).add(insFeeOrderNew.getNoPremium());
- // if (Integer.parseInt(esmRetail.getRetailtype()) >= 3) {
- // insFeeOrderNew.setThirdDetailProportion(new BigDecimal(String.valueOf(esmRetail.getDisrate3())));
- // retailRadio = retailRadio.add(insFeeOrderNew.getThirdDetailProportion()).setScale(2, BigDecimal.ROUND_DOWN);
- // BigDecimal thirdDetailPremiums = feeRuleSchemeService.calcRetail(insFeeOrderNew.getJqPremium(),
- // insFeeOrderNew.getJqCostsProportion().add(insFeeOrderNew.getJqOtherCostsProportion()),
- // insFeeOrderNew.getSyPremium(),
- // insFeeOrderNew.getSyCostsProportion().add(insFeeOrderNew.getSyOtherCostsProportion()),
- // insFeeOrderNew.getNoPremium(),
- // insFeeOrderNew.getNoCostsProportion().add(insFeeOrderNew.getNoOtherCostsProportion()),
- // insFeeOrderNew.getThirdDetailProportion());
- // insFeeOrderNew.setThirdDetailPremiums(thirdDetailPremiums);
- // if (parents != null && parents.size() > 2) {
- // insFeeOrderNew.setThreeLevelUserId(parents.get(2).getId());
- // }
- // }else{
- // insFeeOrderNew.setThirdDetailProportion(new BigDecimal(0));
- // }
- // if (Integer.parseInt(esmRetail.getRetailtype()) >= 2) {
- // insFeeOrderNew.setSecondDetailProportion(new BigDecimal(String.valueOf(esmRetail.getDisrate2())));
- // retailRadio = retailRadio.add(insFeeOrderNew.getSecondDetailProportion()).setScale(2, BigDecimal.ROUND_DOWN);
- // BigDecimal secondDetailPremiums = feeRuleSchemeService.calcRetail(insFeeOrderNew.getJqPremium(),
- // insFeeOrderNew.getJqCostsProportion().add(insFeeOrderNew.getJqOtherCostsProportion()),
- // insFeeOrderNew.getSyPremium(),
- // insFeeOrderNew.getSyCostsProportion().add(insFeeOrderNew.getSyOtherCostsProportion()),
- // insFeeOrderNew.getNoPremium(),
- // insFeeOrderNew.getNoCostsProportion().add(insFeeOrderNew.getNoOtherCostsProportion()),
- // insFeeOrderNew.getSecondDetailProportion());
- // insFeeOrderNew.setSecondDetailPremiums(secondDetailPremiums);
- // if (parents != null && parents.size() > 1) {
- // insFeeOrderNew.setTwoLevelUserId(parents.get(1).getId());
- // }
- // }else{
- // insFeeOrderNew.setSecondDetailProportion(new BigDecimal(0));
- // }
- // if (Integer.parseInt(esmRetail.getRetailtype()) >= 1) {
- // insFeeOrderNew.setFirstDetailProportion(new BigDecimal(String.valueOf(esmRetail.getDisrate1())));
- // retailRadio = retailRadio.add(insFeeOrderNew.getFirstDetailProportion()).setScale(2, BigDecimal.ROUND_DOWN);
- // BigDecimal firstDetailPremiums = feeRuleSchemeService.calcRetail(insFeeOrderNew.getJqPremium(),
- // insFeeOrderNew.getJqCostsProportion().add(insFeeOrderNew.getJqOtherCostsProportion()),
- // insFeeOrderNew.getSyPremium(),
- // insFeeOrderNew.getSyCostsProportion().add(insFeeOrderNew.getSyOtherCostsProportion()),
- // insFeeOrderNew.getNoPremium(),
- // insFeeOrderNew.getNoCostsProportion().add(insFeeOrderNew.getNoOtherCostsProportion()),
- // insFeeOrderNew.getFirstDetailProportion());
- // insFeeOrderNew.setFirstDetailPremiums(firstDetailPremiums);
- // if (parents != null && parents.size() > 0) {
- // insFeeOrderNew.setFirstLevelUserId(parents.get(0).getId());
- // }
- // }else{
- // insFeeOrderNew.setFirstDetailProportion(new BigDecimal(0));
- // }
- // }else{
- // insFeeOrderNew.setFirstDetailPremiums(new BigDecimal(0));
- // insFeeOrderNew.setSecondDetailPremiums(new BigDecimal(0));
- // insFeeOrderNew.setThirdDetailPremiums(new BigDecimal(0));
- // }
- // }else{
- // insFeeOrderNew.setFirstDetailProportion(new BigDecimal(0));
- // insFeeOrderNew.setSecondDetailProportion(new BigDecimal(0));
- // insFeeOrderNew.setThirdDetailProportion(new BigDecimal(0));
- // }
- //
- //
- // //endregion
- //
- // //region 设置机构管理费
- //
- // //交强机构管理费
- // BigDecimal jqDeptRadio =
- // ptlAgreementProductCostsExport.getJqExportRadioLevel1().add(ptlAgreementProductCostsExport.getJqExportRadioLevel2()).add(ptlAgreementProductCostsExport.getJqExportRadioLevel3()).add(ptlAgreementProductCostsExport.getJqExportRadioLevel4()).add(ptlAgreementProductCostsExport.getJqExportRadioLevel5());
- // FeeOrderNewVo.DeptManagerFee jqDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(insFeeOrderNew.getJqPremium(),
- // ptlAgreementProductCostsExport.getJqExportRadioLevel1(), ptlAgreementProductCostsExport.getJqExportRadioLevel2(),
- // ptlAgreementProductCostsExport.getJqExportRadioLevel3(), ptlAgreementProductCostsExport.getJqExportRadioLevel4(),
- // ptlAgreementProductCostsExport.getJqExportRadioLevel5());
- // insFeeOrderNew.setJqDeptProportionLevel1(jqDeptManagerFee.getDeptProportionLevelOne());
- // insFeeOrderNew.setJqDeptPremiumsLevel1(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelOne()));
- // insFeeOrderNew.setJqDeptProportionLevel2(jqDeptManagerFee.getDeptProportionLevelTwo());
- // insFeeOrderNew.setJqDeptPremiumsLevel2(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelTwo()));
- // insFeeOrderNew.setJqDeptProportionLevel3(jqDeptManagerFee.getDeptProportionLevelThree());
- // insFeeOrderNew.setJqDeptPremiumsLevel3(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelThree()));
- // insFeeOrderNew.setJqDeptProportionLevel4(jqDeptManagerFee.getDeptProportionLevelFoure());
- // insFeeOrderNew.setJqDeptPremiumsLevel4(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelFoure()));
- // insFeeOrderNew.setJqDeptProportionLevel5(jqDeptManagerFee.getDeptProportionLevelFive());
- // insFeeOrderNew.setJqDeptPremiumsLevel5(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelFive()));
- //
- // BigDecimal syDeptRadio =
- // ptlAgreementProductCostsExport.getSyExportRadioLevel1().add(ptlAgreementProductCostsExport.getSyExportRadioLevel2()).add(ptlAgreementProductCostsExport.getSyExportRadioLevel3()).add(ptlAgreementProductCostsExport.getSyExportRadioLevel4()).add(ptlAgreementProductCostsExport.getSyExportRadioLevel5());
- // FeeOrderNewVo.DeptManagerFee syDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(insFeeOrderNew.getSyPremium(),
- // ptlAgreementProductCostsExport.getSyExportRadioLevel1(), ptlAgreementProductCostsExport.getSyExportRadioLevel2(),
- // ptlAgreementProductCostsExport.getSyExportRadioLevel3(), ptlAgreementProductCostsExport.getSyExportRadioLevel4(),
- // ptlAgreementProductCostsExport.getSyExportRadioLevel5());
- // insFeeOrderNew.setSyDeptProportionLevel1(syDeptManagerFee.getDeptProportionLevelOne());
- // insFeeOrderNew.setSyDeptPremiumsLevel1(twoPeople(syDeptManagerFee.getDeptPremiumsLevelOne()));
- // insFeeOrderNew.setSyDeptProportionLevel2(syDeptManagerFee.getDeptProportionLevelTwo());
- // insFeeOrderNew.setSyDeptPremiumsLevel2(twoPeople(syDeptManagerFee.getDeptPremiumsLevelTwo()));
- // insFeeOrderNew.setSyDeptProportionLevel3(syDeptManagerFee.getDeptProportionLevelThree());
- // insFeeOrderNew.setSyDeptPremiumsLevel3(twoPeople(syDeptManagerFee.getDeptPremiumsLevelThree()));
- // insFeeOrderNew.setSyDeptProportionLevel4(syDeptManagerFee.getDeptProportionLevelFoure());
- // insFeeOrderNew.setSyDeptPremiumsLevel4(twoPeople(syDeptManagerFee.getDeptPremiumsLevelFoure()));
- // insFeeOrderNew.setSyDeptProportionLevel5(syDeptManagerFee.getDeptProportionLevelFive());
- // insFeeOrderNew.setSyDeptPremiumsLevel5(twoPeople(syDeptManagerFee.getDeptPremiumsLevelFive()));
- //
- // BigDecimal noDeptRadio =
- // ptlAgreementProductCostsExport.getNoCarExportRadioLevel1().add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel2()).add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel3()).add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel4()).add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel5());
- // FeeOrderNewVo.DeptManagerFee noDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(insFeeOrderNew.getNoPremium(),
- // ptlAgreementProductCostsExport.getNoCarExportRadioLevel1(), ptlAgreementProductCostsExport.getNoCarExportRadioLevel2(),
- // ptlAgreementProductCostsExport.getNoCarExportRadioLevel3(), ptlAgreementProductCostsExport.getNoCarExportRadioLevel4(),
- // ptlAgreementProductCostsExport.getNoCarExportRadioLevel5());
- // insFeeOrderNew.setNoDeptProportionLevel1(noDeptManagerFee.getDeptProportionLevelOne());
- // insFeeOrderNew.setNoDeptPremiumsLevel1(twoPeople(noDeptManagerFee.getDeptPremiumsLevelOne()));
- // insFeeOrderNew.setNoDeptProportionLevel2(noDeptManagerFee.getDeptProportionLevelTwo());
- // insFeeOrderNew.setNoDeptPremiumsLevel2(twoPeople(noDeptManagerFee.getDeptPremiumsLevelTwo()));
- // insFeeOrderNew.setNoDeptProportionLevel3(noDeptManagerFee.getDeptProportionLevelThree());
- // insFeeOrderNew.setNoDeptPremiumsLevel3(twoPeople(noDeptManagerFee.getDeptPremiumsLevelThree()));
- // insFeeOrderNew.setNoDeptProportionLevel4(noDeptManagerFee.getDeptProportionLevelFoure());
- // insFeeOrderNew.setNoDeptPremiumsLevel4(twoPeople(noDeptManagerFee.getDeptPremiumsLevelFoure()));
- // insFeeOrderNew.setNoDeptProportionLevel5(noDeptManagerFee.getDeptProportionLevelFive());
- // insFeeOrderNew.setNoDeptPremiumsLevel5(twoPeople(noDeptManagerFee.getDeptPremiumsLevelFive()));
- //
- // //endregion
- //
- // //region 出口费用
- //
- // //交强出口手续费比例
- // FeeOrderNewVo.ExportFee jqExportFee = feeRuleSchemeService.calcExportFee(insFeeOrderNew.getJqPremium(), new BigDecimal(ptlAgreementProductCostsNew.getJqCostsExportProportion()),
- // insFeeOrderNew.getJqCostsProportion(), jqDeptRadio, retailRadio, taxRadio);
- //
- // //商业出口手续费比例
- // FeeOrderNewVo.ExportFee syExportFee = feeRuleSchemeService.calcExportFee(insFeeOrderNew.getSyPremium(), new BigDecimal(ptlAgreementProductCostsNew.getSyCostsExportProportion()),
- // insFeeOrderNew.getSyCostsProportion(), syDeptRadio, retailRadio, taxRadio);
- //
- // //非车出口手续费比例
- // FeeOrderNewVo.ExportFee noExportFee = feeRuleSchemeService.calcExportFee(insFeeOrderNew.getNoPremium(), new BigDecimal(ptlAgreementProductCostsNew.getNoCostsExportProportion()),
- // insFeeOrderNew.getNoCostsProportion(), noDeptRadio, retailRadio, taxRadio);
- //
- // //出口手续费用
- // insFeeOrderNew.setJqExportSuperviseCostsPremiums(twoPeople(jqExportFee.getSuperviseCostsPremiums()));
- // insFeeOrderNew.setSyExportSuperviseCostsPremiums(twoPeople(syExportFee.getSuperviseCostsPremiums()));
- // insFeeOrderNew.setNoExportSuperviseCostsPremiums(twoPeople(noExportFee.getSuperviseCostsPremiums()));
- //
- // //出口其他费用比例
- // insFeeOrderNew.setJqExportOtherCostsProportion(twoPeople(jqExportFee.getOtherCostsProportion()));
- // insFeeOrderNew.setSyExportOtherCostsProportion(twoPeople(syExportFee.getOtherCostsProportion()));
- // insFeeOrderNew.setNoExportOtherCostsProportion(twoPeople(noExportFee.getOtherCostsProportion()));
- //
- // //出口其他费用
- // insFeeOrderNew.setJqExportOtherCostsPremiums(twoPeople(jqExportFee.getOtherCostsPremiums()));
- // insFeeOrderNew.setSyExportOtherCostsPremiums(twoPeople(syExportFee.getOtherCostsPremiums()));
- // insFeeOrderNew.setNoExportOtherCostsPremiums(twoPeople(noExportFee.getOtherCostsPremiums()));
- //
- // //设置出口手续费比例
- // insFeeOrderNew.setJqCostsExportProportion(twoPeople(jqExportFee.getSuperviseCosts()));
- // insFeeOrderNew.setSyCostsExportProportion(twoPeople(syExportFee.getSuperviseCosts()));
- // insFeeOrderNew.setNoCostsExportProportion(twoPeople(noExportFee.getSuperviseCosts()));
- //
- // //endregion
- //
- // //region 计算利润差值
- // //入口 - 出口 - 机构管理费 1-5级 - 分销费 = 差值
- //
- // //分销交强费用
- // //分开算 1 2 3 级
- // BigDecimal jqFirst = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getFirstDetailProportion().divide(new BigDecimal(100))).setScale(2,BigDecimal.ROUND_DOWN);
- // BigDecimal jqSecond = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getSecondDetailProportion().divide(new BigDecimal(100))).setScale(2,BigDecimal.ROUND_DOWN);
- // BigDecimal jqThird = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getThirdDetailProportion().divide(new BigDecimal(100))).setScale(2,BigDecimal.ROUND_DOWN);
- // BigDecimal jqFenXiao = jqFirst.add(jqSecond).add(jqThird);
- // //分销商业费用
- // BigDecimal syFirst = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getFirstDetailProportion().divide(new BigDecimal(100))).setScale(2,BigDecimal.ROUND_DOWN);
- // BigDecimal sySecond = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getSecondDetailProportion().divide(new BigDecimal(100))).setScale(2,BigDecimal.ROUND_DOWN);
- // BigDecimal syThird = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getThirdDetailProportion().divide(new BigDecimal(100))).setScale(2,BigDecimal.ROUND_DOWN);
- // BigDecimal syFenXiao = syFirst.add(sySecond).add(syThird);
- // //分销非车费用
- // BigDecimal noFirst = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getFirstDetailProportion().divide(new BigDecimal(100))).setScale(2,BigDecimal.ROUND_DOWN);
- // BigDecimal noSecond = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getSecondDetailProportion().divide(new BigDecimal(100))).setScale(2,BigDecimal.ROUND_DOWN);
- // BigDecimal noThird = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getThirdDetailProportion().divide(new BigDecimal(100))).setScale(2,BigDecimal.ROUND_DOWN);
- // BigDecimal noFenXiao = noFirst.add(noSecond).add(noThird);
- //
- //
- // BigDecimal jqDifference = jqEntranceFee.getTotalAmount().subtract(
- // (jqExportFee.getSuperviseCostsPremiums().add(jqExportFee.getOtherCostsPremiums())))
- // .subtract(
- // (jqDeptManagerFee.getDeptPremiumsLevelOne().add(jqDeptManagerFee.getDeptPremiumsLevelTwo().add(jqDeptManagerFee.getDeptPremiumsLevelThree()).add(jqDeptManagerFee.getDeptPremiumsLevelFoure()).add(jqDeptManagerFee.getDeptPremiumsLevelFive())))
- // )
- // .subtract(jqFenXiao).setScale(5, BigDecimal.ROUND_HALF_DOWN);
- // insFeeOrderNew.setJqProfitMarginPremiums(jqDifference);
- //
- // BigDecimal syDifference = syEntranceFee.getTotalAmount().subtract(
- // (syExportFee.getSuperviseCostsPremiums().add(syExportFee.getOtherCostsPremiums())))
- // .subtract(
- // (syDeptManagerFee.getDeptPremiumsLevelOne().add(syDeptManagerFee.getDeptPremiumsLevelTwo().add(syDeptManagerFee.getDeptPremiumsLevelThree()).add(syDeptManagerFee.getDeptPremiumsLevelFoure()).add(syDeptManagerFee.getDeptPremiumsLevelFive())))
- // )
- // .subtract(syFenXiao).setScale(5, BigDecimal.ROUND_HALF_DOWN);
- // insFeeOrderNew.setSyProfitMarginPremiums(syDifference);
- //
- //
- // BigDecimal noDifference = noEntranceFee.getTotalAmount().subtract(
- // (noExportFee.getSuperviseCostsPremiums().add(noExportFee.getOtherCostsPremiums())))
- // .subtract(
- // (noDeptManagerFee.getDeptPremiumsLevelOne().add(noDeptManagerFee.getDeptPremiumsLevelTwo().add(noDeptManagerFee.getDeptPremiumsLevelThree()).add(noDeptManagerFee.getDeptPremiumsLevelFoure()).add(noDeptManagerFee.getDeptPremiumsLevelFive())))
- // )
- // .subtract(noFenXiao).setScale(5, BigDecimal.ROUND_HALF_DOWN);
- //
- // insFeeOrderNew.setNoProfitMarginPremiums(noDifference);
- //
- // //endregion
- //
- // //region 比例逆推是否等于0
- //
- // if(!feeRuleSchemeService.calculateProportion(jqEntranceFee,jqDeptManagerFee,jqExportFee,retailRadio,taxRadio,insFeeOrderNew.getJqPremium()))
- // throw new SystemException("交强比例异常");
- //
- // if(!feeRuleSchemeService.calculateProportion(syEntranceFee,syDeptManagerFee,syExportFee,retailRadio,taxRadio,insFeeOrderNew.getSyPremium()))
- // throw new SystemException("商业比例异常");
- //
- // if(!feeRuleSchemeService.calculateProportion(noEntranceFee,noDeptManagerFee,noExportFee,retailRadio,taxRadio,insFeeOrderNew.getNoPremium()))
- // throw new SystemException("非车比例异常");
- //endregion
- // insFeeOrderNewService.saveOrUpdate(insFeeOrderNew);
- }
- @Override
- public void calcCostsExternal(PtlAgreementProductCostsNew ptlAgreementProductCostsNew, InsAreaCompany insAreaCompany) {
- //获取协议信息
- // 外部订单比例
- ptlAgreementProductCostsNew.blank();
- PtlAgreement ptlAgreement = ptlAgreementService.getById(insAreaCompany.getAgreementId());
- InsOrders insOrders = insOrdersService.getById(insAreaCompany.getOrderno());
- SysUser sysUser = sysUserService.findByUserId(insOrders.getUserid());
- BigDecimal enterProportion = sysSwitchConfigService.getEnterProportion(insOrders.getDeptid(), insOrders.getEntryStatus());
- BigDecimal taxRadio = new BigDecimal("1.00");
- //如果是外部订单则 不含税
- if (ptlAgreement.getWithTax().equals("否")) {
- taxRadio = new BigDecimal("1.06");
- }
- //税比例 固定1.06
- //查找入口与出口费用比例
- //出口配置
- PtlAgreementProductCostsExport ptlAgreementProductCostsExport =
- ptlAgreementProductCostsExportService.getOne(new LambdaQueryWrapper<PtlAgreementProductCostsExport>().eq(PtlAgreementProductCostsExport::getCostsId, ptlAgreementProductCostsNew.getId()));
- InsFeeOrderNew insFeeOrderNew = new InsFeeOrderNew();
- insFeeOrderNew.setId(IdGenerate.nextId());
- insFeeOrderNew.setCostsId(ptlAgreementProductCostsNew.getId());
- insFeeOrderNew.setAgreementId(insAreaCompany.getAgreementId());
- //存储部门id与用户id
- InsOrders order = insOrdersService.getById(insAreaCompany.getOrderno());
- InsFeeOrderNew insFeeOrderNewByCompanyId = insFeeOrderNewService.getInsFeeOrderNewByCompanyId(insAreaCompany.getId());
- if (insFeeOrderNewByCompanyId != null) {
- insFeeOrderNew.setId(insFeeOrderNewByCompanyId.getId());
- }
- insFeeOrderNew.setDeptId(order.getDeptid());
- insFeeOrderNew.setUserId(order.getUserid());
- insFeeOrderNew.setInsOrderNo(insAreaCompany.getId());
- insFeeOrderNew.setJqPremium(insAreaCompany.getJqpremium());
- insFeeOrderNew.setSyPremium(insAreaCompany.getSypremium());
- insFeeOrderNew.setNoPremium(insAreaCompany.getJypremium());
- //不含税
- BigDecimal bigDecimal = new BigDecimal("1.06");
- insFeeOrderNew.setJqNoTaxPremium(insAreaCompany.getJqpremium().divide(bigDecimal, 2));
- insFeeOrderNew.setSyNoTaxPremium(insAreaCompany.getSypremium().divide(bigDecimal, 2));
- insFeeOrderNew.setNoNoTaxPremium(insAreaCompany.getJypremium().divide(bigDecimal, 2));
- //region 计算入口费用
- //交强入口信息
- FeeOrderNewVo.EntranceFee jqEntranceFee = feeRuleSchemeService.calcEntranceFee(insFeeOrderNew.getJqPremium(),
- new BigDecimal(ptlAgreementProductCostsNew.getJqCarCostsProportion()),
- new BigDecimal(ptlAgreementProductCostsNew.getJqCarOtherCostsProportion()), taxRadio);
- insFeeOrderNew.setJqCostsProportion(jqEntranceFee.getTotalProportion());
- insFeeOrderNew.setJqSuperviseCostsProportion(jqEntranceFee.getSuperviseCosts());
- insFeeOrderNew.setJqSuperviseCostsPremiums(jqEntranceFee.getSuperviseCostsPremiums());
- insFeeOrderNew.setJqOtherCostsProportion(jqEntranceFee.getOtherCostsProportion());
- insFeeOrderNew.setJqOtherCostsPremiums(jqEntranceFee.getOtherCostsPremiums());
- insFeeOrderNew.setJqCostsPremiums(insFeeOrderNew.getJqSuperviseCostsPremiums().add(insFeeOrderNew.getJqOtherCostsPremiums()));
- //商业入口信息
- FeeOrderNewVo.EntranceFee syEntranceFee = feeRuleSchemeService.calcEntranceFee(insFeeOrderNew.getSyPremium(),
- new BigDecimal(ptlAgreementProductCostsNew.getSyCarCostsProportion()),
- new BigDecimal(ptlAgreementProductCostsNew.getSyCarOtherCostsProportion()), taxRadio);
- insFeeOrderNew.setSyCostsProportion(syEntranceFee.getTotalProportion());
- insFeeOrderNew.setSySuperviseCostsProportion(syEntranceFee.getSuperviseCosts());
- insFeeOrderNew.setSySuperviseCostsPremiums(syEntranceFee.getSuperviseCostsPremiums());
- insFeeOrderNew.setSyOtherCostsProportion(syEntranceFee.getOtherCostsProportion());
- insFeeOrderNew.setSyOtherCostsPremiums(syEntranceFee.getOtherCostsPremiums());
- insFeeOrderNew.setSyCostsPremiums(insFeeOrderNew.getSySuperviseCostsPremiums().add(insFeeOrderNew.getSyOtherCostsPremiums()));
- //非车入口信息
- FeeOrderNewVo.EntranceFee noEntranceFee = feeRuleSchemeService.calcEntranceFee(insFeeOrderNew.getNoPremium(),
- new BigDecimal(ptlAgreementProductCostsNew.getNoCarCostsProportion()),
- new BigDecimal(ptlAgreementProductCostsNew.getNoCarOtherCostsProportion()), taxRadio);
- insFeeOrderNew.setNoCostsProportion(noEntranceFee.getTotalProportion());
- insFeeOrderNew.setNoSuperviseCostsProportion(noEntranceFee.getSuperviseCosts());
- insFeeOrderNew.setNoSuperviseCostsPremiums(noEntranceFee.getSuperviseCostsPremiums());
- insFeeOrderNew.setNoOtherCostsProportion(noEntranceFee.getOtherCostsProportion());
- insFeeOrderNew.setNoOtherCostsPremiums(noEntranceFee.getOtherCostsPremiums());
- insFeeOrderNew.setNoCostsPremiums(insFeeOrderNew.getNoSuperviseCostsPremiums().add(insFeeOrderNew.getNoOtherCostsPremiums()));
- //endregion
- //region 重新计算管理费比例和分销比例
- List<EsmRetail> esmRetailList = esmRetailService.selectList(" where t.deptid=? and t.status = '1' ",
- new Object[]{sysUser.getDeptId()});
- Integer retailLevel = 0;
- //默认分销比例设置
- RetailProportion retailProportion = new RetailProportion();
- if (!Objects.isNull(esmRetailList) && !esmRetailList.isEmpty()) {
- retailLevel = Integer.parseInt(esmRetailList.get(0).getRetailtype());
- //赋值默认的分销比例
- retailProportion.setProportion(esmRetailList.get(0).getDisrate1(), esmRetailList.get(0).getDisrate2(), esmRetailList.get(0).getDisrate3());
- }
- //获取交强机构管理费总比例
- BigDecimal jqDeptProportion = ptlAgreementProductCostsExport.getJqExportRadioLevel1()
- .add(ptlAgreementProductCostsExport.getJqExportRadioLevel2())
- .add(ptlAgreementProductCostsExport.getJqExportRadioLevel3())
- .add(ptlAgreementProductCostsExport.getJqExportRadioLevel4())
- .add(ptlAgreementProductCostsExport.getJqExportRadioLevel5());
- //获取商业机构管理费总比例
- BigDecimal syDeptProportion = ptlAgreementProductCostsExport.getSyExportRadioLevel1()
- .add(ptlAgreementProductCostsExport.getSyExportRadioLevel2())
- .add(ptlAgreementProductCostsExport.getSyExportRadioLevel3())
- .add(ptlAgreementProductCostsExport.getSyExportRadioLevel4())
- .add(ptlAgreementProductCostsExport.getSyExportRadioLevel5());
- //获取非车机构管理费总比例
- BigDecimal noDeptProportion = ptlAgreementProductCostsExport.getNoCarExportRadioLevel1()
- .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel2())
- .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel3())
- .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel4())
- .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel5());
- //获取交强分销总比例
- BigDecimal jqRetailProportion = retailProportion.getJqRetailLevel1Proportion()
- .add(retailProportion.getJqRetailLevel2Proportion())
- .add(retailProportion.getJqRetailLevel3Proportion());
- //获取商业分销总比例
- BigDecimal syRetailProportion = retailProportion.getSyRetailLevel1Proportion()
- .add(retailProportion.getSyRetailLevel2Proportion())
- .add(retailProportion.getSyRetailLevel3Proportion());
- //获取非车分销总比例
- BigDecimal noRetailProportion = retailProportion.getNoRetailLevel1Proportion()
- .add(retailProportion.getNoRetailLevel2Proportion())
- .add(retailProportion.getNoRetailLevel3Proportion());
- //重新计算比例 入口是否超出支付的比例
- ReCalcuLateProportion jqReCalcuLateProportion = recalculateProportion(
- new BigDecimal(ptlAgreementProductCostsNew.getJqCostsProportion()),
- jqDeptProportion,
- jqRetailProportion,
- taxRadio,
- retailLevel,
- ptlAgreementProductCostsExport,
- retailProportion,
- "jq",
- enterProportion
- );
- ReCalcuLateProportion syReCalcuLateProportion = recalculateProportion(
- new BigDecimal(ptlAgreementProductCostsNew.getSyCostsProportion()),
- syDeptProportion,
- syRetailProportion,
- taxRadio,
- retailLevel,
- ptlAgreementProductCostsExport,
- retailProportion,
- "sy",
- enterProportion
- );
- ReCalcuLateProportion noReCalcuLateProportion = recalculateProportion(
- new BigDecimal(ptlAgreementProductCostsNew.getNoCostsProportion()),
- noDeptProportion,
- noRetailProportion,
- taxRadio,
- retailLevel,
- ptlAgreementProductCostsExport,
- retailProportion,
- "no",
- enterProportion
- );
- retailProportion.setProportion(jqReCalcuLateProportion, syReCalcuLateProportion, noReCalcuLateProportion);
- // ptlAgreementProductCostsExportService.updateById(ptlAgreementProductCostsExport);
- //endregion
- //region 计算分销费用
- //分销总比例
- // BigDecimal jqRetailRadio = new BigDecimal("0");
- // BigDecimal syRetailRadio = new BigDecimal("0");
- // BigDecimal noRetailRadio = new BigDecimal("0");
- FeeOrderNewVo.RetailFee retailFeeLevel3 = new FeeOrderNewVo.RetailFee();
- FeeOrderNewVo.RetailFee retailFeeLevel2 = new FeeOrderNewVo.RetailFee();
- FeeOrderNewVo.RetailFee retailFeeLevel1 = new FeeOrderNewVo.RetailFee();
- //分销总比例
- BigDecimal retailRadio = new BigDecimal("0");
- if (esmRetailList != null && !esmRetailList.isEmpty()) {
- EsmRetail esmRetail = esmRetailList.get(0);
- //分销等级
- insFeeOrderNew.setDistributionStatus(esmRetailList.get(0).getRetailtype());
- //用户分销人员id
- List<EsmUserReferrer> parents = esmUserReferrerService.findParents(sysUser.getId());
- if (esmRetail != null) {
- BigDecimal sumPremium = insFeeOrderNew.getJqPremium().add(insFeeOrderNew.getSyPremium()).add(insFeeOrderNew.getNoPremium());
- if (Integer.parseInt(esmRetail.getRetailtype()) >= 3) {
- insFeeOrderNew.setThirdDetailProportion(new BigDecimal(String.valueOf(esmRetail.getDisrate3())));
- retailRadio = retailRadio.add(insFeeOrderNew.getThirdDetailProportion()).setScale(2, BigDecimal.ROUND_DOWN);
- retailFeeLevel3 = feeRuleSchemeService.calcRetail(
- insFeeOrderNew.getJqPremium(),
- insFeeOrderNew.getJqCostsProportion(),
- insFeeOrderNew.getSyPremium(),
- insFeeOrderNew.getSyCostsProportion(),
- insFeeOrderNew.getNoPremium(),
- insFeeOrderNew.getNoCostsProportion(),
- retailProportion.getJqRetailLevel3Proportion(),
- retailProportion.getSyRetailLevel3Proportion(),
- retailProportion.getNoRetailLevel3Proportion());
- insFeeOrderNew.setThirdDetailPremiums(retailFeeLevel3.getTotalRetailPremiums());
- if (parents != null && parents.size() > 2) {
- insFeeOrderNew.setThreeLevelUserId(parents.get(2).getId());
- }
- } else {
- insFeeOrderNew.setThirdDetailProportion(new BigDecimal(0));
- }
- if (Integer.parseInt(esmRetail.getRetailtype()) >= 2) {
- insFeeOrderNew.setSecondDetailProportion(new BigDecimal(String.valueOf(esmRetail.getDisrate2())));
- retailRadio = retailRadio.add(insFeeOrderNew.getSecondDetailProportion()).setScale(2, BigDecimal.ROUND_DOWN);
- retailFeeLevel2 = feeRuleSchemeService.calcRetail(insFeeOrderNew.getJqPremium(),
- insFeeOrderNew.getJqCostsProportion(),
- insFeeOrderNew.getSyPremium(),
- insFeeOrderNew.getSyCostsProportion(),
- insFeeOrderNew.getNoPremium(),
- insFeeOrderNew.getNoCostsProportion(),
- retailProportion.getJqRetailLevel2Proportion(),
- retailProportion.getSyRetailLevel2Proportion(),
- retailProportion.getNoRetailLevel2Proportion());
- insFeeOrderNew.setSecondDetailPremiums(retailFeeLevel2.getTotalRetailPremiums());
- if (parents != null && parents.size() > 1) {
- insFeeOrderNew.setTwoLevelUserId(parents.get(1).getId());
- }
- } else {
- insFeeOrderNew.setSecondDetailProportion(new BigDecimal(0));
- }
- if (Integer.parseInt(esmRetail.getRetailtype()) >= 1) {
- insFeeOrderNew.setFirstDetailProportion(new BigDecimal(String.valueOf(esmRetail.getDisrate1())));
- retailRadio = retailRadio.add(insFeeOrderNew.getFirstDetailProportion()).setScale(2, BigDecimal.ROUND_DOWN);
- retailFeeLevel1 = feeRuleSchemeService.calcRetail(insFeeOrderNew.getJqPremium(),
- insFeeOrderNew.getJqCostsProportion(),
- insFeeOrderNew.getSyPremium(),
- insFeeOrderNew.getSyCostsProportion(),
- insFeeOrderNew.getNoPremium(),
- insFeeOrderNew.getNoCostsProportion(),
- retailProportion.getJqRetailLevel1Proportion(),
- retailProportion.getSyRetailLevel1Proportion(),
- retailProportion.getNoRetailLevel1Proportion());
- insFeeOrderNew.setFirstDetailPremiums(retailFeeLevel1.getTotalRetailPremiums());
- if (parents != null && !parents.isEmpty()) {
- insFeeOrderNew.setFirstLevelUserId(parents.get(0).getId());
- }
- } else {
- insFeeOrderNew.setFirstDetailProportion(new BigDecimal(0));
- }
- } else {
- insFeeOrderNew.setFirstDetailPremiums(new BigDecimal(0));
- insFeeOrderNew.setSecondDetailPremiums(new BigDecimal(0));
- insFeeOrderNew.setThirdDetailPremiums(new BigDecimal(0));
- }
- } else {
- insFeeOrderNew.setFirstDetailProportion(new BigDecimal(0));
- insFeeOrderNew.setSecondDetailProportion(new BigDecimal(0));
- insFeeOrderNew.setThirdDetailProportion(new BigDecimal(0));
- }
- insFeeOrderNew.assignRetail(retailFeeLevel1, retailFeeLevel2, retailFeeLevel3);
- //endregion
- //region 设置机构管理费
- //交强机构管理费
- BigDecimal jqDeptRadio =
- ptlAgreementProductCostsExport.getJqExportRadioLevel1().add(ptlAgreementProductCostsExport.getJqExportRadioLevel2()).add(ptlAgreementProductCostsExport.getJqExportRadioLevel3()).add(ptlAgreementProductCostsExport.getJqExportRadioLevel4()).add(ptlAgreementProductCostsExport.getJqExportRadioLevel5());
- FeeOrderNewVo.DeptManagerFee jqDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(insFeeOrderNew.getJqPremium(),
- ptlAgreementProductCostsExport.getJqExportRadioLevel1(), ptlAgreementProductCostsExport.getJqExportRadioLevel2(),
- ptlAgreementProductCostsExport.getJqExportRadioLevel3(), ptlAgreementProductCostsExport.getJqExportRadioLevel4(),
- ptlAgreementProductCostsExport.getJqExportRadioLevel5());
- insFeeOrderNew.setJqDeptProportionLevel1(jqDeptManagerFee.getDeptProportionLevelOne());
- insFeeOrderNew.setJqDeptPremiumsLevel1(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelOne()));
- insFeeOrderNew.setJqDeptProportionLevel2(jqDeptManagerFee.getDeptProportionLevelTwo());
- insFeeOrderNew.setJqDeptPremiumsLevel2(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelTwo()));
- insFeeOrderNew.setJqDeptProportionLevel3(jqDeptManagerFee.getDeptProportionLevelThree());
- insFeeOrderNew.setJqDeptPremiumsLevel3(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelThree()));
- insFeeOrderNew.setJqDeptProportionLevel4(jqDeptManagerFee.getDeptProportionLevelFoure());
- insFeeOrderNew.setJqDeptPremiumsLevel4(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelFoure()));
- insFeeOrderNew.setJqDeptProportionLevel5(jqDeptManagerFee.getDeptProportionLevelFive());
- insFeeOrderNew.setJqDeptPremiumsLevel5(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelFive()));
- BigDecimal syDeptRadio =
- ptlAgreementProductCostsExport.getSyExportRadioLevel1().add(ptlAgreementProductCostsExport.getSyExportRadioLevel2()).add(ptlAgreementProductCostsExport.getSyExportRadioLevel3()).add(ptlAgreementProductCostsExport.getSyExportRadioLevel4()).add(ptlAgreementProductCostsExport.getSyExportRadioLevel5());
- FeeOrderNewVo.DeptManagerFee syDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(insFeeOrderNew.getSyPremium(),
- ptlAgreementProductCostsExport.getSyExportRadioLevel1(), ptlAgreementProductCostsExport.getSyExportRadioLevel2(),
- ptlAgreementProductCostsExport.getSyExportRadioLevel3(), ptlAgreementProductCostsExport.getSyExportRadioLevel4(),
- ptlAgreementProductCostsExport.getSyExportRadioLevel5());
- insFeeOrderNew.setSyDeptProportionLevel1(syDeptManagerFee.getDeptProportionLevelOne());
- insFeeOrderNew.setSyDeptPremiumsLevel1(twoPeople(syDeptManagerFee.getDeptPremiumsLevelOne()));
- insFeeOrderNew.setSyDeptProportionLevel2(syDeptManagerFee.getDeptProportionLevelTwo());
- insFeeOrderNew.setSyDeptPremiumsLevel2(twoPeople(syDeptManagerFee.getDeptPremiumsLevelTwo()));
- insFeeOrderNew.setSyDeptProportionLevel3(syDeptManagerFee.getDeptProportionLevelThree());
- insFeeOrderNew.setSyDeptPremiumsLevel3(twoPeople(syDeptManagerFee.getDeptPremiumsLevelThree()));
- insFeeOrderNew.setSyDeptProportionLevel4(syDeptManagerFee.getDeptProportionLevelFoure());
- insFeeOrderNew.setSyDeptPremiumsLevel4(twoPeople(syDeptManagerFee.getDeptPremiumsLevelFoure()));
- insFeeOrderNew.setSyDeptProportionLevel5(syDeptManagerFee.getDeptProportionLevelFive());
- insFeeOrderNew.setSyDeptPremiumsLevel5(twoPeople(syDeptManagerFee.getDeptPremiumsLevelFive()));
- BigDecimal noDeptRadio =
- ptlAgreementProductCostsExport.getNoCarExportRadioLevel1().add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel2()).add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel3()).add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel4()).add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel5());
- FeeOrderNewVo.DeptManagerFee noDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(insFeeOrderNew.getNoPremium(),
- ptlAgreementProductCostsExport.getNoCarExportRadioLevel1(), ptlAgreementProductCostsExport.getNoCarExportRadioLevel2(),
- ptlAgreementProductCostsExport.getNoCarExportRadioLevel3(), ptlAgreementProductCostsExport.getNoCarExportRadioLevel4(),
- ptlAgreementProductCostsExport.getNoCarExportRadioLevel5());
- insFeeOrderNew.setNoDeptProportionLevel1(noDeptManagerFee.getDeptProportionLevelOne());
- insFeeOrderNew.setNoDeptPremiumsLevel1(twoPeople(noDeptManagerFee.getDeptPremiumsLevelOne()));
- insFeeOrderNew.setNoDeptProportionLevel2(noDeptManagerFee.getDeptProportionLevelTwo());
- insFeeOrderNew.setNoDeptPremiumsLevel2(twoPeople(noDeptManagerFee.getDeptPremiumsLevelTwo()));
- insFeeOrderNew.setNoDeptProportionLevel3(noDeptManagerFee.getDeptProportionLevelThree());
- insFeeOrderNew.setNoDeptPremiumsLevel3(twoPeople(noDeptManagerFee.getDeptPremiumsLevelThree()));
- insFeeOrderNew.setNoDeptProportionLevel4(noDeptManagerFee.getDeptProportionLevelFoure());
- insFeeOrderNew.setNoDeptPremiumsLevel4(twoPeople(noDeptManagerFee.getDeptPremiumsLevelFoure()));
- insFeeOrderNew.setNoDeptProportionLevel5(noDeptManagerFee.getDeptProportionLevelFive());
- insFeeOrderNew.setNoDeptPremiumsLevel5(twoPeople(noDeptManagerFee.getDeptPremiumsLevelFive()));
- //endregion
- //region 出口费用
- //交强出口手续费比例
- FeeOrderNewVo.ExportFee jqExportFee = feeRuleSchemeService.calcExportFee(insFeeOrderNew.getJqPremium(), new BigDecimal(ptlAgreementProductCostsNew.getJqCostsExportProportion()),
- insFeeOrderNew.getJqCostsProportion(), jqDeptRadio, retailRadio, taxRadio, jqReCalcuLateProportion.getProxyProportion());
- //商业出口手续费比例
- FeeOrderNewVo.ExportFee syExportFee = feeRuleSchemeService.calcExportFee(insFeeOrderNew.getSyPremium(), new BigDecimal(ptlAgreementProductCostsNew.getSyCostsExportProportion()),
- insFeeOrderNew.getSyCostsProportion(), syDeptRadio, retailRadio, taxRadio, syReCalcuLateProportion.getProxyProportion());
- //非车出口手续费比例
- FeeOrderNewVo.ExportFee noExportFee = feeRuleSchemeService.calcExportFee(insFeeOrderNew.getNoPremium(), new BigDecimal(ptlAgreementProductCostsNew.getNoCostsExportProportion()),
- insFeeOrderNew.getNoCostsProportion(), noDeptRadio, retailRadio, taxRadio, noReCalcuLateProportion.getProxyProportion());
- //出口手续费用
- insFeeOrderNew.setJqExportSuperviseCostsPremiums(twoPeople(jqExportFee.getSuperviseCostsPremiums()));
- insFeeOrderNew.setSyExportSuperviseCostsPremiums(twoPeople(syExportFee.getSuperviseCostsPremiums()));
- insFeeOrderNew.setNoExportSuperviseCostsPremiums(twoPeople(noExportFee.getSuperviseCostsPremiums()));
- //出口其他费用比例
- insFeeOrderNew.setJqExportOtherCostsProportion(twoPeople(jqExportFee.getOtherCostsProportion()));
- insFeeOrderNew.setSyExportOtherCostsProportion(twoPeople(syExportFee.getOtherCostsProportion()));
- insFeeOrderNew.setNoExportOtherCostsProportion(twoPeople(noExportFee.getOtherCostsProportion()));
- //出口其他费用
- insFeeOrderNew.setJqExportOtherCostsPremiums(twoPeople(jqExportFee.getOtherCostsPremiums()));
- insFeeOrderNew.setSyExportOtherCostsPremiums(twoPeople(syExportFee.getOtherCostsPremiums()));
- insFeeOrderNew.setNoExportOtherCostsPremiums(twoPeople(noExportFee.getOtherCostsPremiums()));
- //设置出口手续费比例
- insFeeOrderNew.setJqCostsExportProportion(twoPeople(jqExportFee.getSuperviseCosts()));
- insFeeOrderNew.setSyCostsExportProportion(twoPeople(syExportFee.getSuperviseCosts()));
- insFeeOrderNew.setNoCostsExportProportion(twoPeople(noExportFee.getSuperviseCosts()));
- // 外部订单费用
- insFeeOrderNew.setJqExternalProportion(jqExportFee.getExternalProportion());
- insFeeOrderNew.setJqExternalPremiums(jqExportFee.getExternalPremiums());
- insFeeOrderNew.setSyExternalProportion(syExportFee.getExternalProportion());
- insFeeOrderNew.setSyExternalPremiums(syExportFee.getExternalPremiums());
- insFeeOrderNew.setNoExternalProportion(noExportFee.getExternalProportion());
- insFeeOrderNew.setNoExternalPremiums(noExportFee.getExternalPremiums());
- //endregion
- //region 计算利润差值
- //入口 - 出口 - 机构管理费 1-5级 - 分销费 = 差值
- //分销交强费用
- //分开算 1 2 3 级
- BigDecimal jqFirst = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getFirstDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
- BigDecimal jqSecond = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getSecondDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
- BigDecimal jqThird = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getThirdDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
- BigDecimal jqFenXiao = jqFirst.add(jqSecond).add(jqThird);
- //分销商业费用
- BigDecimal syFirst = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getFirstDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
- BigDecimal sySecond = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getSecondDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
- BigDecimal syThird = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getThirdDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
- BigDecimal syFenXiao = syFirst.add(sySecond).add(syThird);
- //分销非车费用
- BigDecimal noFirst = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getFirstDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
- BigDecimal noSecond = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getSecondDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
- BigDecimal noThird = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getThirdDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
- BigDecimal noFenXiao = noFirst.add(noSecond).add(noThird);
- BigDecimal jqDifference = jqEntranceFee.getTotalAmount()
- .subtract(jqExportFee.getExternalPremiums())
- .subtract(
- (jqExportFee.getSuperviseCostsPremiums().add(jqExportFee.getOtherCostsPremiums())))
- .subtract(
- (jqDeptManagerFee.getDeptPremiumsLevelOne().add(jqDeptManagerFee.getDeptPremiumsLevelTwo().add(jqDeptManagerFee.getDeptPremiumsLevelThree()).add(jqDeptManagerFee.getDeptPremiumsLevelFoure()).add(jqDeptManagerFee.getDeptPremiumsLevelFive())))
- )
- .subtract(jqFenXiao).setScale(5, BigDecimal.ROUND_HALF_DOWN);
- insFeeOrderNew.setJqProfitMarginPremiums(jqDifference);
- BigDecimal syDifference = syEntranceFee.getTotalAmount()
- .subtract(syExportFee.getExternalPremiums())
- .subtract(
- (syExportFee.getSuperviseCostsPremiums().add(syExportFee.getOtherCostsPremiums())))
- .subtract(
- (syDeptManagerFee.getDeptPremiumsLevelOne().add(syDeptManagerFee.getDeptPremiumsLevelTwo().add(syDeptManagerFee.getDeptPremiumsLevelThree()).add(syDeptManagerFee.getDeptPremiumsLevelFoure()).add(syDeptManagerFee.getDeptPremiumsLevelFive())))
- )
- .subtract(syFenXiao).setScale(5, BigDecimal.ROUND_HALF_DOWN);
- insFeeOrderNew.setSyProfitMarginPremiums(syDifference);
- BigDecimal noDifference = noEntranceFee.getTotalAmount()
- .subtract(noExportFee.getExternalPremiums())
- .subtract(
- (noExportFee.getSuperviseCostsPremiums().add(noExportFee.getOtherCostsPremiums())))
- .subtract(
- (noDeptManagerFee.getDeptPremiumsLevelOne().add(noDeptManagerFee.getDeptPremiumsLevelTwo().add(noDeptManagerFee.getDeptPremiumsLevelThree()).add(noDeptManagerFee.getDeptPremiumsLevelFoure()).add(noDeptManagerFee.getDeptPremiumsLevelFive())))
- )
- .subtract(noFenXiao).setScale(5, BigDecimal.ROUND_HALF_DOWN);
- insFeeOrderNew.setNoProfitMarginPremiums(noDifference);
- //endregion
- //region 比例逆推是否等于0
- if (!feeRuleSchemeService.calculateProportion(jqEntranceFee, jqDeptManagerFee, jqExportFee, retailRadio, taxRadio, insFeeOrderNew.getJqPremium()))
- throw new SystemException("交强比例异常");
- if (!feeRuleSchemeService.calculateProportion(syEntranceFee, syDeptManagerFee, syExportFee, retailRadio, taxRadio, insFeeOrderNew.getSyPremium()))
- throw new SystemException("商业比例异常");
- if (!feeRuleSchemeService.calculateProportion(noEntranceFee, noDeptManagerFee, noExportFee, retailRadio, taxRadio, insFeeOrderNew.getNoPremium()))
- throw new SystemException("非车比例异常");
- //endregion
- insFeeOrderNewService.saveOrUpdate(insFeeOrderNew);
- }
- @Override
- public ExternalOrderFeeVo calcCostsExternalExportData(PtlAgreement ptlAgreement, PtlAgreementProductCostsNew ptlAgreementProductCostsNew, ExternalOrderFeeVo externalOrderFeeVo) {
- //获取协议信息
- // 外部订单比例
- ptlAgreementProductCostsNew.blank();
- SysUser sysUser = sysUserService.findByUserId(externalOrderFeeVo.getUserId());
- BigDecimal enterProportion = sysSwitchConfigService.getEnterProportion(sysUser.getDeptId(), 3);
- BigDecimal taxRadio = new BigDecimal("1.00");
- //如果是外部订单则 不含税
- if (ptlAgreement.getWithTax().equals("否")) {
- taxRadio = new BigDecimal("1.06");
- }
- //税比例 固定1.06
- //查找入口与出口费用比例
- //出口配置
- PtlAgreementProductCostsExport ptlAgreementProductCostsExport =
- ptlAgreementProductCostsExportService.getOne(new LambdaQueryWrapper<PtlAgreementProductCostsExport>()
- .eq(PtlAgreementProductCostsExport::getCostsId, ptlAgreementProductCostsNew.getId()));
- //不含税
- BigDecimal bigDecimal = new BigDecimal("1.06");
- externalOrderFeeVo.setJqNoTaxPremium(externalOrderFeeVo.getJqPremium().divide(bigDecimal, 2));
- externalOrderFeeVo.setSyNoTaxPremium(externalOrderFeeVo.getSyPremium().divide(bigDecimal, 2));
- externalOrderFeeVo.setNoNoTaxPremium(externalOrderFeeVo.getNoPremium().divide(bigDecimal, 2));
- //region 计算入口费用
- //交强入口信息
- FeeOrderNewVo.EntranceFee jqEntranceFee = feeRuleSchemeService.calcEntranceFee(externalOrderFeeVo.getJqPremium(),
- new BigDecimal(ptlAgreementProductCostsNew.getJqCarCostsProportion()),
- externalOrderFeeVo.getJqRadio(), taxRadio);
- //endregion
- //region 重新计算管理费比例和分销比例
- List<EsmRetail> esmRetailList = esmRetailService.selectList(" where t.deptid=? and t.status = '1' ",
- new Object[]{sysUser.getDeptId()});
- Integer retailLevel = 0;
- //默认分销比例设置
- RetailProportion retailProportion = new RetailProportion();
- if (!Objects.isNull(esmRetailList) && !esmRetailList.isEmpty()) {
- retailLevel = Integer.parseInt(esmRetailList.get(0).getRetailtype());
- //赋值默认的分销比例
- retailProportion.setProportion(esmRetailList.get(0).getDisrate1(), esmRetailList.get(0).getDisrate2(), esmRetailList.get(0).getDisrate3());
- }
- //获取交强机构管理费总比例
- BigDecimal jqDeptProportion = ptlAgreementProductCostsExport.getJqExportRadioLevel1()
- .add(ptlAgreementProductCostsExport.getJqExportRadioLevel2())
- .add(ptlAgreementProductCostsExport.getJqExportRadioLevel3())
- .add(ptlAgreementProductCostsExport.getJqExportRadioLevel4())
- .add(ptlAgreementProductCostsExport.getJqExportRadioLevel5());
- //获取商业机构管理费总比例
- BigDecimal syDeptProportion = ptlAgreementProductCostsExport.getSyExportRadioLevel1()
- .add(ptlAgreementProductCostsExport.getSyExportRadioLevel2())
- .add(ptlAgreementProductCostsExport.getSyExportRadioLevel3())
- .add(ptlAgreementProductCostsExport.getSyExportRadioLevel4())
- .add(ptlAgreementProductCostsExport.getSyExportRadioLevel5());
- //获取非车机构管理费总比例
- BigDecimal noDeptProportion = ptlAgreementProductCostsExport.getNoCarExportRadioLevel1()
- .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel2())
- .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel3())
- .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel4())
- .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel5());
- //获取交强分销总比例
- BigDecimal jqRetailProportion = retailProportion.getJqRetailLevel1Proportion()
- .add(retailProportion.getJqRetailLevel2Proportion())
- .add(retailProportion.getJqRetailLevel3Proportion());
- //获取商业分销总比例
- BigDecimal syRetailProportion = retailProportion.getSyRetailLevel1Proportion()
- .add(retailProportion.getSyRetailLevel2Proportion())
- .add(retailProportion.getSyRetailLevel3Proportion());
- //获取非车分销总比例
- BigDecimal noRetailProportion = retailProportion.getNoRetailLevel1Proportion()
- .add(retailProportion.getNoRetailLevel2Proportion())
- .add(retailProportion.getNoRetailLevel3Proportion());
- //重新计算比例 入口是否超出支付的比例
- ReCalcuLateProportion jqReCalcuLateProportion = recalculateProportion(
- new BigDecimal(ptlAgreementProductCostsNew.getJqCostsProportion()),
- jqDeptProportion,
- jqRetailProportion,
- taxRadio,
- retailLevel,
- ptlAgreementProductCostsExport,
- retailProportion,
- "jq",
- enterProportion
- );
- ReCalcuLateProportion syReCalcuLateProportion = recalculateProportion(
- new BigDecimal(ptlAgreementProductCostsNew.getSyCostsProportion()),
- syDeptProportion,
- syRetailProportion,
- taxRadio,
- retailLevel,
- ptlAgreementProductCostsExport,
- retailProportion,
- "sy",
- enterProportion
- );
- ReCalcuLateProportion noReCalcuLateProportion = recalculateProportion(
- new BigDecimal(ptlAgreementProductCostsNew.getNoCostsProportion()),
- noDeptProportion,
- noRetailProportion,
- taxRadio,
- retailLevel,
- ptlAgreementProductCostsExport,
- retailProportion,
- "no",
- enterProportion
- );
- retailProportion.setProportion(jqReCalcuLateProportion, syReCalcuLateProportion, noReCalcuLateProportion);
- // ptlAgreementProductCostsExportService.updateById(ptlAgreementProductCostsExport);
- //endregion
- //region 计算分销费用
- //分销总比例
- BigDecimal jqRetailRadio = new BigDecimal("0");
- BigDecimal syRetailRadio = new BigDecimal("0");
- BigDecimal noRetailRadio = new BigDecimal("0");
- FeeOrderNewVo.RetailFee retailFeeLevel3 = new FeeOrderNewVo.RetailFee();
- FeeOrderNewVo.RetailFee retailFeeLevel2 = new FeeOrderNewVo.RetailFee();
- FeeOrderNewVo.RetailFee retailFeeLevel1 = new FeeOrderNewVo.RetailFee();
- //分销总比例
- BigDecimal retailRadio = new BigDecimal("0");
- if (esmRetailList != null && !esmRetailList.isEmpty()) {
- EsmRetail esmRetail = esmRetailList.get(0);
- if (esmRetail != null) {
- BigDecimal sumPremium = externalOrderFeeVo.getJqPremium().add(externalOrderFeeVo.getSyPremium()).add(externalOrderFeeVo.getNoPremium());
- if (Integer.parseInt(esmRetail.getRetailtype()) >= 3) {
- retailRadio = retailRadio.add(new BigDecimal(String.valueOf(esmRetail.getDisrate3()))).setScale(2, BigDecimal.ROUND_DOWN);
- retailFeeLevel3 = feeRuleSchemeService.calcRetail(
- externalOrderFeeVo.getJqPremium(),
- externalOrderFeeVo.getJqRadio(),
- externalOrderFeeVo.getSyPremium(),
- externalOrderFeeVo.getSyRadio(),
- externalOrderFeeVo.getNoPremium(),
- externalOrderFeeVo.getNoRadio(),
- retailProportion.getJqRetailLevel3Proportion(),
- retailProportion.getSyRetailLevel3Proportion(),
- retailProportion.getNoRetailLevel3Proportion());
- //三级分销费用 retailFeeLevel3.getTotalRetailPremiums()
- } else {
- //三级分销费用为 空值0
- }
- if (Integer.parseInt(esmRetail.getRetailtype()) >= 2) {
- retailRadio = retailRadio.add(new BigDecimal(String.valueOf(esmRetail.getDisrate2()))).setScale(2, BigDecimal.ROUND_DOWN);
- retailFeeLevel2 = feeRuleSchemeService.calcRetail(
- externalOrderFeeVo.getJqPremium(),
- externalOrderFeeVo.getJqRadio(),
- externalOrderFeeVo.getSyPremium(),
- externalOrderFeeVo.getSyRadio(),
- externalOrderFeeVo.getNoPremium(),
- externalOrderFeeVo.getNoRadio(),
- retailProportion.getJqRetailLevel2Proportion(),
- retailProportion.getSyRetailLevel2Proportion(),
- retailProportion.getNoRetailLevel2Proportion());
- //二级分销费用 retailFeeLevel2.getTotalRetailPremiums()
- } else {
- // 空的
- }
- if (Integer.parseInt(esmRetail.getRetailtype()) >= 1) {
- retailRadio = retailRadio.add(new BigDecimal(String.valueOf(esmRetail.getDisrate1()))).setScale(2, BigDecimal.ROUND_DOWN);
- retailFeeLevel1 = feeRuleSchemeService.calcRetail(
- externalOrderFeeVo.getJqPremium(),
- externalOrderFeeVo.getJqRadio(),
- externalOrderFeeVo.getSyPremium(),
- externalOrderFeeVo.getSyRadio(),
- externalOrderFeeVo.getNoPremium(),
- externalOrderFeeVo.getNoRadio(),
- retailProportion.getJqRetailLevel1Proportion(),
- retailProportion.getSyRetailLevel1Proportion(),
- retailProportion.getNoRetailLevel1Proportion());
- //一级 retailFeeLevel1.getTotalRetailPremiums()
- } else {
- // 空的
- }
- } else {
- //null
- }
- } else {
- // null
- }
- //endregion
- //region 设置机构管理费
- //交强机构管理费
- BigDecimal jqDeptRadio =
- ptlAgreementProductCostsExport.getJqExportRadioLevel1().add(ptlAgreementProductCostsExport.getJqExportRadioLevel2()).add(ptlAgreementProductCostsExport.getJqExportRadioLevel3()).add(ptlAgreementProductCostsExport.getJqExportRadioLevel4()).add(ptlAgreementProductCostsExport.getJqExportRadioLevel5());
- FeeOrderNewVo.DeptManagerFee jqDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(externalOrderFeeVo.getJqPremium(),
- ptlAgreementProductCostsExport.getJqExportRadioLevel1(), ptlAgreementProductCostsExport.getJqExportRadioLevel2(),
- ptlAgreementProductCostsExport.getJqExportRadioLevel3(), ptlAgreementProductCostsExport.getJqExportRadioLevel4(),
- ptlAgreementProductCostsExport.getJqExportRadioLevel5());
- BigDecimal syDeptRadio =
- ptlAgreementProductCostsExport.getSyExportRadioLevel1().add(ptlAgreementProductCostsExport.getSyExportRadioLevel2()).add(ptlAgreementProductCostsExport.getSyExportRadioLevel3()).add(ptlAgreementProductCostsExport.getSyExportRadioLevel4()).add(ptlAgreementProductCostsExport.getSyExportRadioLevel5());
- FeeOrderNewVo.DeptManagerFee syDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(externalOrderFeeVo.getSyPremium(),
- ptlAgreementProductCostsExport.getSyExportRadioLevel1(), ptlAgreementProductCostsExport.getSyExportRadioLevel2(),
- ptlAgreementProductCostsExport.getSyExportRadioLevel3(), ptlAgreementProductCostsExport.getSyExportRadioLevel4(),
- ptlAgreementProductCostsExport.getSyExportRadioLevel5());
- BigDecimal noDeptRadio =
- ptlAgreementProductCostsExport.getNoCarExportRadioLevel1().add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel2()).add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel3()).add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel4()).add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel5());
- FeeOrderNewVo.DeptManagerFee noDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(externalOrderFeeVo.getNoPremium(),
- ptlAgreementProductCostsExport.getNoCarExportRadioLevel1(), ptlAgreementProductCostsExport.getNoCarExportRadioLevel2(),
- ptlAgreementProductCostsExport.getNoCarExportRadioLevel3(), ptlAgreementProductCostsExport.getNoCarExportRadioLevel4(),
- ptlAgreementProductCostsExport.getNoCarExportRadioLevel5());
- //endregion
- //region 出口费用
- //交强出口手续费比例
- FeeOrderNewVo.ExportFee jqExportFee = feeRuleSchemeService.calcExportFee(
- externalOrderFeeVo.getJqPremium(),
- new BigDecimal(ptlAgreementProductCostsNew.getJqCostsExportProportion()),
- externalOrderFeeVo.getJqRadio(),
- jqDeptRadio,
- retailRadio,
- taxRadio,
- jqReCalcuLateProportion.getProxyProportion());
- //商业出口手续费比例
- FeeOrderNewVo.ExportFee syExportFee = feeRuleSchemeService.calcExportFee(
- externalOrderFeeVo.getSyPremium(),
- new BigDecimal(ptlAgreementProductCostsNew.getSyCostsExportProportion()),
- externalOrderFeeVo.getSyRadio(),
- syDeptRadio,
- retailRadio,
- taxRadio,
- syReCalcuLateProportion.getProxyProportion());
- //非车出口手续费比例
- FeeOrderNewVo.ExportFee noExportFee = feeRuleSchemeService.calcExportFee(
- externalOrderFeeVo.getNoPremium(),
- new BigDecimal(ptlAgreementProductCostsNew.getNoCostsExportProportion()),
- externalOrderFeeVo.getNoRadio(),
- noDeptRadio,
- retailRadio,
- taxRadio,
- noReCalcuLateProportion.getProxyProportion());
- externalOrderFeeVo.setJqExportPremium(jqExportFee.getTotalAmount());
- externalOrderFeeVo.setJqExportRadio(jqExportFee.getTotalProportion());
- externalOrderFeeVo.setSyExportPremium(syExportFee.getTotalAmount());
- externalOrderFeeVo.setSyExportRadio(syExportFee.getTotalProportion());
- externalOrderFeeVo.setNoExportPremium(noExportFee.getTotalAmount());
- externalOrderFeeVo.setNoExportRadio(noExportFee.getTotalProportion());
- //endregion
- return externalOrderFeeVo;
- }
- @Override
- public void calcCostsExternalTest(PtlAgreementProductCostsNew ptlAgreementProductCostsNew, InsAreaCompany insAreaCompany) {
- //获取协议信息
- // 外部订单比例
- PtlAgreement ptlAgreement = ptlAgreementService.getById(insAreaCompany.getAgreementId());
- InsOrders insOrders = insOrdersService.getById(insAreaCompany.getOrderno());
- SysUser sysUser = sysUserService.findByUserId(insOrders.getUserid());
- BigDecimal enterProportion = sysSwitchConfigService.getEnterProportion(insOrders.getDeptid(), insOrders.getEntryStatus());
- BigDecimal taxRadio = new BigDecimal("1.00");
- //如果是外部订单则 不含税
- if (ptlAgreement.getWithTax().equals("否")) {
- taxRadio = new BigDecimal("1.06");
- }
- //税比例 固定1.06
- //查找入口与出口费用比例
- //出口配置
- PtlAgreementProductCostsExport ptlAgreementProductCostsExport =
- ptlAgreementProductCostsExportService.getOne(new LambdaQueryWrapper<PtlAgreementProductCostsExport>().eq(PtlAgreementProductCostsExport::getCostsId, ptlAgreementProductCostsNew.getId()));
- InsFeeOrderNew insFeeOrderNew = new InsFeeOrderNew();
- insFeeOrderNew.setId(IdGenerate.nextId());
- insFeeOrderNew.setCostsId(ptlAgreementProductCostsNew.getId());
- insFeeOrderNew.setAgreementId(insAreaCompany.getAgreementId());
- //存储部门id与用户id
- InsOrders order = insOrdersService.getById(insAreaCompany.getOrderno());
- InsFeeOrderNew insFeeOrderNewByCompanyId = insFeeOrderNewService.getInsFeeOrderNewByCompanyId(insAreaCompany.getId());
- if (insFeeOrderNewByCompanyId != null) {
- insFeeOrderNew.setId(insFeeOrderNewByCompanyId.getId());
- }
- insFeeOrderNew.setDeptId(order.getDeptid());
- insFeeOrderNew.setUserId(order.getUserid());
- insFeeOrderNew.setInsOrderNo(insAreaCompany.getId());
- insFeeOrderNew.setJqPremium(insAreaCompany.getJqpremium());
- insFeeOrderNew.setSyPremium(insAreaCompany.getSypremium());
- insFeeOrderNew.setNoPremium(insAreaCompany.getJypremium());
- //不含税
- BigDecimal bigDecimal = new BigDecimal("1.06");
- insFeeOrderNew.setJqNoTaxPremium(insAreaCompany.getJqpremium().divide(bigDecimal, 2));
- insFeeOrderNew.setSyNoTaxPremium(insAreaCompany.getSypremium().divide(bigDecimal, 2));
- insFeeOrderNew.setNoNoTaxPremium(insAreaCompany.getJypremium().divide(bigDecimal, 2));
- //region 计算入口费用
- //交强入口信息
- FeeOrderNewVo.EntranceFee jqEntranceFee = feeRuleSchemeService.calcEntranceFee(insFeeOrderNew.getJqPremium(),
- new BigDecimal(ptlAgreementProductCostsNew.getJqCarCostsProportion()),
- new BigDecimal(ptlAgreementProductCostsNew.getJqCarOtherCostsProportion()), taxRadio);
- insFeeOrderNew.setJqCostsProportion(jqEntranceFee.getTotalProportion());
- insFeeOrderNew.setJqSuperviseCostsProportion(jqEntranceFee.getSuperviseCosts());
- insFeeOrderNew.setJqSuperviseCostsPremiums(jqEntranceFee.getSuperviseCostsPremiums());
- insFeeOrderNew.setJqOtherCostsProportion(jqEntranceFee.getOtherCostsProportion());
- insFeeOrderNew.setJqOtherCostsPremiums(jqEntranceFee.getOtherCostsPremiums());
- insFeeOrderNew.setJqCostsPremiums(insFeeOrderNew.getJqSuperviseCostsPremiums().add(insFeeOrderNew.getJqOtherCostsPremiums()));
- //商业入口信息
- FeeOrderNewVo.EntranceFee syEntranceFee = feeRuleSchemeService.calcEntranceFee(insFeeOrderNew.getSyPremium(),
- new BigDecimal(ptlAgreementProductCostsNew.getSyCarCostsProportion()),
- new BigDecimal(ptlAgreementProductCostsNew.getSyCarOtherCostsProportion()), taxRadio);
- insFeeOrderNew.setSyCostsProportion(syEntranceFee.getTotalProportion());
- insFeeOrderNew.setSySuperviseCostsProportion(syEntranceFee.getSuperviseCosts());
- insFeeOrderNew.setSySuperviseCostsPremiums(syEntranceFee.getSuperviseCostsPremiums());
- insFeeOrderNew.setSyOtherCostsProportion(syEntranceFee.getOtherCostsProportion());
- insFeeOrderNew.setSyOtherCostsPremiums(syEntranceFee.getOtherCostsPremiums());
- insFeeOrderNew.setSyCostsPremiums(insFeeOrderNew.getSySuperviseCostsPremiums().add(insFeeOrderNew.getSyOtherCostsPremiums()));
- //非车入口信息
- FeeOrderNewVo.EntranceFee noEntranceFee = feeRuleSchemeService.calcEntranceFee(insFeeOrderNew.getNoPremium(),
- new BigDecimal(ptlAgreementProductCostsNew.getNoCarCostsProportion()),
- new BigDecimal(ptlAgreementProductCostsNew.getNoCarOtherCostsProportion()), taxRadio);
- insFeeOrderNew.setNoCostsProportion(noEntranceFee.getTotalProportion());
- insFeeOrderNew.setNoSuperviseCostsProportion(noEntranceFee.getSuperviseCosts());
- insFeeOrderNew.setNoSuperviseCostsPremiums(noEntranceFee.getSuperviseCostsPremiums());
- insFeeOrderNew.setNoOtherCostsProportion(noEntranceFee.getOtherCostsProportion());
- insFeeOrderNew.setNoOtherCostsPremiums(noEntranceFee.getOtherCostsPremiums());
- insFeeOrderNew.setNoCostsPremiums(insFeeOrderNew.getNoSuperviseCostsPremiums().add(insFeeOrderNew.getNoOtherCostsPremiums()));
- //endregion
- //region 重新计算管理费比例和分销比例
- List<EsmRetail> esmRetailList = esmRetailService.selectList(" where t.deptid=? and t.status = '1' ",
- new Object[]{sysUser.getDeptId()});
- Integer retailLevel = 0;
- //默认分销比例设置
- RetailProportion retailProportion = new RetailProportion();
- if (!Objects.isNull(esmRetailList) && !esmRetailList.isEmpty()) {
- retailLevel = Integer.parseInt(esmRetailList.get(0).getRetailtype());
- //赋值默认的分销比例
- retailProportion.setProportion(esmRetailList.get(0).getDisrate1(), esmRetailList.get(0).getDisrate2(), esmRetailList.get(0).getDisrate3());
- }
- //获取交强机构管理费总比例
- BigDecimal jqDeptProportion = ptlAgreementProductCostsExport.getJqExportRadioLevel1()
- .add(ptlAgreementProductCostsExport.getJqExportRadioLevel2())
- .add(ptlAgreementProductCostsExport.getJqExportRadioLevel3())
- .add(ptlAgreementProductCostsExport.getJqExportRadioLevel4())
- .add(ptlAgreementProductCostsExport.getJqExportRadioLevel5());
- //获取商业机构管理费总比例
- BigDecimal syDeptProportion = ptlAgreementProductCostsExport.getSyExportRadioLevel1()
- .add(ptlAgreementProductCostsExport.getSyExportRadioLevel2())
- .add(ptlAgreementProductCostsExport.getSyExportRadioLevel3())
- .add(ptlAgreementProductCostsExport.getSyExportRadioLevel4())
- .add(ptlAgreementProductCostsExport.getSyExportRadioLevel5());
- //获取非车机构管理费总比例
- BigDecimal noDeptProportion = ptlAgreementProductCostsExport.getNoCarExportRadioLevel1()
- .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel2())
- .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel3())
- .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel4())
- .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel5());
- //获取交强分销总比例
- BigDecimal jqRetailProportion = retailProportion.getJqRetailLevel1Proportion()
- .add(retailProportion.getJqRetailLevel2Proportion())
- .add(retailProportion.getJqRetailLevel3Proportion());
- //获取商业分销总比例
- BigDecimal syRetailProportion = retailProportion.getSyRetailLevel1Proportion()
- .add(retailProportion.getSyRetailLevel2Proportion())
- .add(retailProportion.getSyRetailLevel3Proportion());
- //获取非车分销总比例
- BigDecimal noRetailProportion = retailProportion.getNoRetailLevel1Proportion()
- .add(retailProportion.getNoRetailLevel2Proportion())
- .add(retailProportion.getNoRetailLevel3Proportion());
- //重新计算比例 入口是否超出支付的比例
- ReCalcuLateProportion jqReCalcuLateProportion = recalculateProportion(
- new BigDecimal(ptlAgreementProductCostsNew.getJqCostsProportion()),
- jqDeptProportion,
- jqRetailProportion,
- taxRadio,
- retailLevel,
- ptlAgreementProductCostsExport,
- retailProportion,
- "jq",
- enterProportion
- );
- ReCalcuLateProportion syReCalcuLateProportion = recalculateProportion(
- new BigDecimal(ptlAgreementProductCostsNew.getSyCostsProportion()),
- syDeptProportion,
- syRetailProportion,
- taxRadio,
- retailLevel,
- ptlAgreementProductCostsExport,
- retailProportion,
- "sy",
- enterProportion
- );
- ReCalcuLateProportion noReCalcuLateProportion = recalculateProportion(
- new BigDecimal(ptlAgreementProductCostsNew.getNoCostsProportion()),
- noDeptProportion,
- noRetailProportion,
- taxRadio,
- retailLevel,
- ptlAgreementProductCostsExport,
- retailProportion,
- "no",
- enterProportion
- );
- retailProportion.setProportion(jqReCalcuLateProportion, syReCalcuLateProportion, noReCalcuLateProportion);
- // ptlAgreementProductCostsExportService.updateById(ptlAgreementProductCostsExport);
- //endregion
- //region 计算分销费用
- //分销总比例
- BigDecimal jqRetailRadio = new BigDecimal("0");
- BigDecimal syRetailRadio = new BigDecimal("0");
- BigDecimal noRetailRadio = new BigDecimal("0");
- FeeOrderNewVo.RetailFee retailFeeLevel3 = new FeeOrderNewVo.RetailFee();
- FeeOrderNewVo.RetailFee retailFeeLevel2 = new FeeOrderNewVo.RetailFee();
- FeeOrderNewVo.RetailFee retailFeeLevel1 = new FeeOrderNewVo.RetailFee();
- //分销总比例
- BigDecimal retailRadio = new BigDecimal("0");
- if (esmRetailList != null && !esmRetailList.isEmpty()) {
- EsmRetail esmRetail = esmRetailList.get(0);
- //分销等级
- insFeeOrderNew.setDistributionStatus(esmRetailList.get(0).getRetailtype());
- //用户分销人员id
- List<EsmUserReferrer> parents = esmUserReferrerService.findParents(sysUser.getId());
- if (esmRetail != null) {
- BigDecimal sumPremium = insFeeOrderNew.getJqPremium().add(insFeeOrderNew.getSyPremium()).add(insFeeOrderNew.getNoPremium());
- if (Integer.parseInt(esmRetail.getRetailtype()) >= 3) {
- insFeeOrderNew.setThirdDetailProportion(new BigDecimal(String.valueOf(esmRetail.getDisrate3())));
- retailRadio = retailRadio.add(insFeeOrderNew.getThirdDetailProportion()).setScale(2, BigDecimal.ROUND_DOWN);
- retailFeeLevel3 = feeRuleSchemeService.calcRetail(
- insFeeOrderNew.getJqPremium(),
- insFeeOrderNew.getJqCostsProportion(),
- insFeeOrderNew.getSyPremium(),
- insFeeOrderNew.getSyCostsProportion(),
- insFeeOrderNew.getNoPremium(),
- insFeeOrderNew.getNoCostsProportion(),
- retailProportion.getJqRetailLevel3Proportion(),
- retailProportion.getSyRetailLevel3Proportion(),
- retailProportion.getNoRetailLevel3Proportion());
- insFeeOrderNew.setThirdDetailPremiums(retailFeeLevel3.getTotalRetailPremiums());
- if (parents != null && parents.size() > 2) {
- insFeeOrderNew.setThreeLevelUserId(parents.get(2).getId());
- }
- } else {
- insFeeOrderNew.setThirdDetailProportion(new BigDecimal(0));
- }
- if (Integer.parseInt(esmRetail.getRetailtype()) >= 2) {
- insFeeOrderNew.setSecondDetailProportion(new BigDecimal(String.valueOf(esmRetail.getDisrate2())));
- retailRadio = retailRadio.add(insFeeOrderNew.getSecondDetailProportion()).setScale(2, BigDecimal.ROUND_DOWN);
- retailFeeLevel2 = feeRuleSchemeService.calcRetail(insFeeOrderNew.getJqPremium(),
- insFeeOrderNew.getJqCostsProportion(),
- insFeeOrderNew.getSyPremium(),
- insFeeOrderNew.getSyCostsProportion(),
- insFeeOrderNew.getNoPremium(),
- insFeeOrderNew.getNoCostsProportion(),
- retailProportion.getJqRetailLevel2Proportion(),
- retailProportion.getSyRetailLevel2Proportion(),
- retailProportion.getNoRetailLevel2Proportion());
- insFeeOrderNew.setSecondDetailPremiums(retailFeeLevel2.getTotalRetailPremiums());
- if (parents != null && parents.size() > 1) {
- insFeeOrderNew.setTwoLevelUserId(parents.get(1).getId());
- }
- } else {
- insFeeOrderNew.setSecondDetailProportion(new BigDecimal(0));
- }
- if (Integer.parseInt(esmRetail.getRetailtype()) >= 1) {
- insFeeOrderNew.setFirstDetailProportion(new BigDecimal(String.valueOf(esmRetail.getDisrate1())));
- retailRadio = retailRadio.add(insFeeOrderNew.getFirstDetailProportion()).setScale(2, BigDecimal.ROUND_DOWN);
- retailFeeLevel1 = feeRuleSchemeService.calcRetail(insFeeOrderNew.getJqPremium(),
- insFeeOrderNew.getJqCostsProportion(),
- insFeeOrderNew.getSyPremium(),
- insFeeOrderNew.getSyCostsProportion(),
- insFeeOrderNew.getNoPremium(),
- insFeeOrderNew.getNoCostsProportion(),
- retailProportion.getJqRetailLevel1Proportion(),
- retailProportion.getSyRetailLevel1Proportion(),
- retailProportion.getNoRetailLevel1Proportion());
- insFeeOrderNew.setFirstDetailPremiums(retailFeeLevel1.getTotalRetailPremiums());
- if (parents != null && !parents.isEmpty()) {
- insFeeOrderNew.setFirstLevelUserId(parents.get(0).getId());
- }
- } else {
- insFeeOrderNew.setFirstDetailProportion(new BigDecimal(0));
- }
- } else {
- insFeeOrderNew.setFirstDetailPremiums(new BigDecimal(0));
- insFeeOrderNew.setSecondDetailPremiums(new BigDecimal(0));
- insFeeOrderNew.setThirdDetailPremiums(new BigDecimal(0));
- }
- } else {
- insFeeOrderNew.setFirstDetailProportion(new BigDecimal(0));
- insFeeOrderNew.setSecondDetailProportion(new BigDecimal(0));
- insFeeOrderNew.setThirdDetailProportion(new BigDecimal(0));
- }
- insFeeOrderNew.assignRetail(retailFeeLevel1, retailFeeLevel2, retailFeeLevel3);
- //endregion
- //region 设置机构管理费
- //交强机构管理费
- BigDecimal jqDeptRadio =
- ptlAgreementProductCostsExport.getJqExportRadioLevel1().add(ptlAgreementProductCostsExport.getJqExportRadioLevel2()).add(ptlAgreementProductCostsExport.getJqExportRadioLevel3()).add(ptlAgreementProductCostsExport.getJqExportRadioLevel4()).add(ptlAgreementProductCostsExport.getJqExportRadioLevel5());
- FeeOrderNewVo.DeptManagerFee jqDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(insFeeOrderNew.getJqPremium(),
- ptlAgreementProductCostsExport.getJqExportRadioLevel1(), ptlAgreementProductCostsExport.getJqExportRadioLevel2(),
- ptlAgreementProductCostsExport.getJqExportRadioLevel3(), ptlAgreementProductCostsExport.getJqExportRadioLevel4(),
- ptlAgreementProductCostsExport.getJqExportRadioLevel5());
- insFeeOrderNew.setJqDeptProportionLevel1(jqDeptManagerFee.getDeptProportionLevelOne());
- insFeeOrderNew.setJqDeptPremiumsLevel1(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelOne()));
- insFeeOrderNew.setJqDeptProportionLevel2(jqDeptManagerFee.getDeptProportionLevelTwo());
- insFeeOrderNew.setJqDeptPremiumsLevel2(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelTwo()));
- insFeeOrderNew.setJqDeptProportionLevel3(jqDeptManagerFee.getDeptProportionLevelThree());
- insFeeOrderNew.setJqDeptPremiumsLevel3(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelThree()));
- insFeeOrderNew.setJqDeptProportionLevel4(jqDeptManagerFee.getDeptProportionLevelFoure());
- insFeeOrderNew.setJqDeptPremiumsLevel4(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelFoure()));
- insFeeOrderNew.setJqDeptProportionLevel5(jqDeptManagerFee.getDeptProportionLevelFive());
- insFeeOrderNew.setJqDeptPremiumsLevel5(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelFive()));
- BigDecimal syDeptRadio =
- ptlAgreementProductCostsExport.getSyExportRadioLevel1().add(ptlAgreementProductCostsExport.getSyExportRadioLevel2()).add(ptlAgreementProductCostsExport.getSyExportRadioLevel3()).add(ptlAgreementProductCostsExport.getSyExportRadioLevel4()).add(ptlAgreementProductCostsExport.getSyExportRadioLevel5());
- FeeOrderNewVo.DeptManagerFee syDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(insFeeOrderNew.getSyPremium(),
- ptlAgreementProductCostsExport.getSyExportRadioLevel1(), ptlAgreementProductCostsExport.getSyExportRadioLevel2(),
- ptlAgreementProductCostsExport.getSyExportRadioLevel3(), ptlAgreementProductCostsExport.getSyExportRadioLevel4(),
- ptlAgreementProductCostsExport.getSyExportRadioLevel5());
- insFeeOrderNew.setSyDeptProportionLevel1(syDeptManagerFee.getDeptProportionLevelOne());
- insFeeOrderNew.setSyDeptPremiumsLevel1(twoPeople(syDeptManagerFee.getDeptPremiumsLevelOne()));
- insFeeOrderNew.setSyDeptProportionLevel2(syDeptManagerFee.getDeptProportionLevelTwo());
- insFeeOrderNew.setSyDeptPremiumsLevel2(twoPeople(syDeptManagerFee.getDeptPremiumsLevelTwo()));
- insFeeOrderNew.setSyDeptProportionLevel3(syDeptManagerFee.getDeptProportionLevelThree());
- insFeeOrderNew.setSyDeptPremiumsLevel3(twoPeople(syDeptManagerFee.getDeptPremiumsLevelThree()));
- insFeeOrderNew.setSyDeptProportionLevel4(syDeptManagerFee.getDeptProportionLevelFoure());
- insFeeOrderNew.setSyDeptPremiumsLevel4(twoPeople(syDeptManagerFee.getDeptPremiumsLevelFoure()));
- insFeeOrderNew.setSyDeptProportionLevel5(syDeptManagerFee.getDeptProportionLevelFive());
- insFeeOrderNew.setSyDeptPremiumsLevel5(twoPeople(syDeptManagerFee.getDeptPremiumsLevelFive()));
- BigDecimal noDeptRadio =
- ptlAgreementProductCostsExport.getNoCarExportRadioLevel1().add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel2()).add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel3()).add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel4()).add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel5());
- FeeOrderNewVo.DeptManagerFee noDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(insFeeOrderNew.getNoPremium(),
- ptlAgreementProductCostsExport.getNoCarExportRadioLevel1(), ptlAgreementProductCostsExport.getNoCarExportRadioLevel2(),
- ptlAgreementProductCostsExport.getNoCarExportRadioLevel3(), ptlAgreementProductCostsExport.getNoCarExportRadioLevel4(),
- ptlAgreementProductCostsExport.getNoCarExportRadioLevel5());
- insFeeOrderNew.setNoDeptProportionLevel1(noDeptManagerFee.getDeptProportionLevelOne());
- insFeeOrderNew.setNoDeptPremiumsLevel1(twoPeople(noDeptManagerFee.getDeptPremiumsLevelOne()));
- insFeeOrderNew.setNoDeptProportionLevel2(noDeptManagerFee.getDeptProportionLevelTwo());
- insFeeOrderNew.setNoDeptPremiumsLevel2(twoPeople(noDeptManagerFee.getDeptPremiumsLevelTwo()));
- insFeeOrderNew.setNoDeptProportionLevel3(noDeptManagerFee.getDeptProportionLevelThree());
- insFeeOrderNew.setNoDeptPremiumsLevel3(twoPeople(noDeptManagerFee.getDeptPremiumsLevelThree()));
- insFeeOrderNew.setNoDeptProportionLevel4(noDeptManagerFee.getDeptProportionLevelFoure());
- insFeeOrderNew.setNoDeptPremiumsLevel4(twoPeople(noDeptManagerFee.getDeptPremiumsLevelFoure()));
- insFeeOrderNew.setNoDeptProportionLevel5(noDeptManagerFee.getDeptProportionLevelFive());
- insFeeOrderNew.setNoDeptPremiumsLevel5(twoPeople(noDeptManagerFee.getDeptPremiumsLevelFive()));
- //endregion
- //region 出口费用
- //交强出口手续费比例
- FeeOrderNewVo.ExportFee jqExportFee = feeRuleSchemeService.calcExportFee(insFeeOrderNew.getJqPremium(), new BigDecimal(ptlAgreementProductCostsNew.getJqCostsExportProportion()),
- insFeeOrderNew.getJqCostsProportion(), jqDeptRadio, retailRadio, taxRadio, jqReCalcuLateProportion.getProxyProportion());
- //商业出口手续费比例
- FeeOrderNewVo.ExportFee syExportFee = feeRuleSchemeService.calcExportFee(insFeeOrderNew.getSyPremium(), new BigDecimal(ptlAgreementProductCostsNew.getSyCostsExportProportion()),
- insFeeOrderNew.getSyCostsProportion(), syDeptRadio, retailRadio, taxRadio, syReCalcuLateProportion.getProxyProportion());
- //非车出口手续费比例
- FeeOrderNewVo.ExportFee noExportFee = feeRuleSchemeService.calcExportFee(insFeeOrderNew.getNoPremium(), new BigDecimal(ptlAgreementProductCostsNew.getNoCostsExportProportion()),
- insFeeOrderNew.getNoCostsProportion(), noDeptRadio, retailRadio, taxRadio, noReCalcuLateProportion.getProxyProportion());
- //出口手续费用
- insFeeOrderNew.setJqExportSuperviseCostsPremiums(twoPeople(jqExportFee.getSuperviseCostsPremiums()));
- insFeeOrderNew.setSyExportSuperviseCostsPremiums(twoPeople(syExportFee.getSuperviseCostsPremiums()));
- insFeeOrderNew.setNoExportSuperviseCostsPremiums(twoPeople(noExportFee.getSuperviseCostsPremiums()));
- //出口其他费用比例
- insFeeOrderNew.setJqExportOtherCostsProportion(twoPeople(jqExportFee.getOtherCostsProportion()));
- insFeeOrderNew.setSyExportOtherCostsProportion(twoPeople(syExportFee.getOtherCostsProportion()));
- insFeeOrderNew.setNoExportOtherCostsProportion(twoPeople(noExportFee.getOtherCostsProportion()));
- //出口其他费用
- insFeeOrderNew.setJqExportOtherCostsPremiums(twoPeople(jqExportFee.getOtherCostsPremiums()));
- insFeeOrderNew.setSyExportOtherCostsPremiums(twoPeople(syExportFee.getOtherCostsPremiums()));
- insFeeOrderNew.setNoExportOtherCostsPremiums(twoPeople(noExportFee.getOtherCostsPremiums()));
- //设置出口手续费比例
- insFeeOrderNew.setJqCostsExportProportion(twoPeople(jqExportFee.getSuperviseCosts()));
- insFeeOrderNew.setSyCostsExportProportion(twoPeople(syExportFee.getSuperviseCosts()));
- insFeeOrderNew.setNoCostsExportProportion(twoPeople(noExportFee.getSuperviseCosts()));
- // 外部订单费用
- insFeeOrderNew.setJqExternalProportion(jqExportFee.getExternalProportion());
- insFeeOrderNew.setJqExternalPremiums(jqExportFee.getExternalPremiums());
- insFeeOrderNew.setSyExternalProportion(syExportFee.getExternalProportion());
- insFeeOrderNew.setSyExternalPremiums(syExportFee.getExternalPremiums());
- insFeeOrderNew.setNoExternalProportion(noExportFee.getExternalProportion());
- insFeeOrderNew.setNoExternalPremiums(noExportFee.getExternalPremiums());
- //endregion
- //region 计算利润差值
- //入口 - 出口 - 机构管理费 1-5级 - 分销费 = 差值
- //分销交强费用
- //分开算 1 2 3 级
- BigDecimal jqFirst = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getFirstDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
- BigDecimal jqSecond = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getSecondDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
- BigDecimal jqThird = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getThirdDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
- BigDecimal jqFenXiao = jqFirst.add(jqSecond).add(jqThird);
- //分销商业费用
- BigDecimal syFirst = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getFirstDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
- BigDecimal sySecond = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getSecondDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
- BigDecimal syThird = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getThirdDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
- BigDecimal syFenXiao = syFirst.add(sySecond).add(syThird);
- //分销非车费用
- BigDecimal noFirst = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getFirstDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
- BigDecimal noSecond = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getSecondDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
- BigDecimal noThird = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getThirdDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
- BigDecimal noFenXiao = noFirst.add(noSecond).add(noThird);
- BigDecimal jqDifference = jqEntranceFee.getTotalAmount()
- .subtract(jqExportFee.getExternalPremiums())
- .subtract(
- (jqExportFee.getSuperviseCostsPremiums().add(jqExportFee.getOtherCostsPremiums())))
- .subtract(
- (jqDeptManagerFee.getDeptPremiumsLevelOne().add(jqDeptManagerFee.getDeptPremiumsLevelTwo().add(jqDeptManagerFee.getDeptPremiumsLevelThree()).add(jqDeptManagerFee.getDeptPremiumsLevelFoure()).add(jqDeptManagerFee.getDeptPremiumsLevelFive())))
- )
- .subtract(jqFenXiao).setScale(5, BigDecimal.ROUND_HALF_DOWN);
- insFeeOrderNew.setJqProfitMarginPremiums(jqDifference);
- BigDecimal syDifference = syEntranceFee.getTotalAmount()
- .subtract(syExportFee.getExternalPremiums())
- .subtract(
- (syExportFee.getSuperviseCostsPremiums().add(syExportFee.getOtherCostsPremiums())))
- .subtract(
- (syDeptManagerFee.getDeptPremiumsLevelOne().add(syDeptManagerFee.getDeptPremiumsLevelTwo().add(syDeptManagerFee.getDeptPremiumsLevelThree()).add(syDeptManagerFee.getDeptPremiumsLevelFoure()).add(syDeptManagerFee.getDeptPremiumsLevelFive())))
- )
- .subtract(syFenXiao).setScale(5, BigDecimal.ROUND_HALF_DOWN);
- insFeeOrderNew.setSyProfitMarginPremiums(syDifference);
- BigDecimal noDifference = noEntranceFee.getTotalAmount()
- .subtract(noExportFee.getExternalPremiums())
- .subtract(
- (noExportFee.getSuperviseCostsPremiums().add(noExportFee.getOtherCostsPremiums())))
- .subtract(
- (noDeptManagerFee.getDeptPremiumsLevelOne().add(noDeptManagerFee.getDeptPremiumsLevelTwo().add(noDeptManagerFee.getDeptPremiumsLevelThree()).add(noDeptManagerFee.getDeptPremiumsLevelFoure()).add(noDeptManagerFee.getDeptPremiumsLevelFive())))
- )
- .subtract(noFenXiao).setScale(5, BigDecimal.ROUND_HALF_DOWN);
- insFeeOrderNew.setNoProfitMarginPremiums(noDifference);
- //endregion
- //region 比例逆推是否等于0
- if (!feeRuleSchemeService.calculateProportion(jqEntranceFee, jqDeptManagerFee, jqExportFee, retailRadio, taxRadio, insFeeOrderNew.getJqPremium()))
- throw new SystemException("交强比例异常");
- if (!feeRuleSchemeService.calculateProportion(syEntranceFee, syDeptManagerFee, syExportFee, retailRadio, taxRadio, insFeeOrderNew.getSyPremium()))
- throw new SystemException("商业比例异常");
- if (!feeRuleSchemeService.calculateProportion(noEntranceFee, noDeptManagerFee, noExportFee, retailRadio, taxRadio, insFeeOrderNew.getNoPremium()))
- throw new SystemException("非车比例异常");
- //endregion
- insFeeOrderNewService.saveOrUpdate(insFeeOrderNew);
- }
- @Override
- public void calcCostsExternalTelemarketing(PtlAgreementProductCostsExport ptlAgreementProductCostsExport, InsAreaCompany insAreaCompany) {
- //获取协议信息
- PtlAgreement ptlAgreement = ptlAgreementService.getById(insAreaCompany.getAgreementId());
- InsOrders insOrders = insOrdersService.getById(insAreaCompany.getOrderno());
- SysUser sysUser = sysUserService.findByUserId(insOrders.getUserid());
- //入口配置
- PtlAgreementProductCostsNew ptlAgreementProductCostsNew = ptlAgreementProductCostsNewService.getById(ptlAgreementProductCostsExport.getCostsId());
- ptlAgreementProductCostsNew.blank();
- BigDecimal taxRadio = new BigDecimal("1.00");
- //如果是外部订单则 不含税
- if (ptlAgreement.getWithTax().equals("否") && ptlAgreement.getIsExternal() == 0) {
- taxRadio = new BigDecimal("1.06");
- }
- InsFeeOrderNew insFeeOrderNew = new InsFeeOrderNew();
- insFeeOrderNew.setId(IdGenerate.nextId());
- insFeeOrderNew.setCostsId(ptlAgreementProductCostsNew.getId());
- insFeeOrderNew.setAgreementId(insAreaCompany.getAgreementId());
- //存储部门id与用户id
- InsOrders order = insOrdersService.getById(insAreaCompany.getOrderno());
- InsFeeOrderNew insFeeOrderNewByCompanyId = insFeeOrderNewService.getInsFeeOrderNewByCompanyId(insAreaCompany.getId());
- if (insFeeOrderNewByCompanyId != null) {
- insFeeOrderNew.setId(insFeeOrderNewByCompanyId.getId());
- }
- insFeeOrderNew.setDeptId(order.getDeptid());
- insFeeOrderNew.setUserId(order.getUserid());
- insFeeOrderNew.setInsOrderNo(insAreaCompany.getId());
- insFeeOrderNew.setJqPremium(insAreaCompany.getJqpremium());
- insFeeOrderNew.setSyPremium(insAreaCompany.getSypremium());
- insFeeOrderNew.setNoPremium(insAreaCompany.getJypremium());
- //不含税
- BigDecimal bigDecimal = new BigDecimal("1.06");
- insFeeOrderNew.setJqNoTaxPremium(insAreaCompany.getJqpremium().divide(bigDecimal, 2));
- insFeeOrderNew.setSyNoTaxPremium(insAreaCompany.getSypremium().divide(bigDecimal, 2));
- insFeeOrderNew.setNoNoTaxPremium(insAreaCompany.getJypremium().divide(bigDecimal, 2));
- //region 计算入口费用
- //交强入口信息
- FeeOrderNewVo.EntranceFee jqEntranceFee = feeRuleSchemeService.calcEntranceFee(
- insFeeOrderNew.getJqPremium(),
- new BigDecimal(ptlAgreementProductCostsNew.getJqCarCostsProportion()),
- new BigDecimal(ptlAgreementProductCostsNew.getJqCarOtherCostsProportion()),
- taxRadio);
- insFeeOrderNew.setJqCostsProportion(jqEntranceFee.getTotalProportion());
- insFeeOrderNew.setJqSuperviseCostsProportion(jqEntranceFee.getSuperviseCosts());
- insFeeOrderNew.setJqSuperviseCostsPremiums(jqEntranceFee.getSuperviseCostsPremiums());
- insFeeOrderNew.setJqOtherCostsProportion(jqEntranceFee.getOtherCostsProportion());
- insFeeOrderNew.setJqOtherCostsPremiums(jqEntranceFee.getOtherCostsPremiums());
- insFeeOrderNew.setJqCostsPremiums(insFeeOrderNew.getJqSuperviseCostsPremiums().add(insFeeOrderNew.getJqOtherCostsPremiums()));
- //商业入口信息
- FeeOrderNewVo.EntranceFee syEntranceFee = feeRuleSchemeService.calcEntranceFee(insFeeOrderNew.getSyPremium(),
- new BigDecimal(ptlAgreementProductCostsNew.getSyCarCostsProportion()),
- new BigDecimal(ptlAgreementProductCostsNew.getSyCarOtherCostsProportion()), taxRadio);
- insFeeOrderNew.setSyCostsProportion(syEntranceFee.getTotalProportion());
- insFeeOrderNew.setSySuperviseCostsProportion(syEntranceFee.getSuperviseCosts());
- insFeeOrderNew.setSySuperviseCostsPremiums(syEntranceFee.getSuperviseCostsPremiums());
- insFeeOrderNew.setSyOtherCostsProportion(syEntranceFee.getOtherCostsProportion());
- insFeeOrderNew.setSyOtherCostsPremiums(syEntranceFee.getOtherCostsPremiums());
- insFeeOrderNew.setSyCostsPremiums(insFeeOrderNew.getSySuperviseCostsPremiums().add(insFeeOrderNew.getSyOtherCostsPremiums()));
- //非车入口信息
- FeeOrderNewVo.EntranceFee noEntranceFee = feeRuleSchemeService.calcEntranceFee(insFeeOrderNew.getNoPremium(),
- new BigDecimal(ptlAgreementProductCostsNew.getNoCarCostsProportion()),
- new BigDecimal(ptlAgreementProductCostsNew.getNoCarOtherCostsProportion()), taxRadio);
- insFeeOrderNew.setNoCostsProportion(noEntranceFee.getTotalProportion());
- insFeeOrderNew.setNoSuperviseCostsProportion(noEntranceFee.getSuperviseCosts());
- insFeeOrderNew.setNoSuperviseCostsPremiums(noEntranceFee.getSuperviseCostsPremiums());
- insFeeOrderNew.setNoOtherCostsProportion(noEntranceFee.getOtherCostsProportion());
- insFeeOrderNew.setNoOtherCostsPremiums(noEntranceFee.getOtherCostsPremiums());
- insFeeOrderNew.setNoCostsPremiums(insFeeOrderNew.getNoSuperviseCostsPremiums().add(insFeeOrderNew.getNoOtherCostsPremiums()));
- //endregion
- //region 重新计算管理费比例和分销比例
- List<EsmRetail> esmRetailList = esmRetailService.selectList(" where t.deptid=? and t.status = '1' ",
- new Object[]{sysUser.getDeptId()});
- Integer retailLevel = 0;
- //默认分销比例设置
- RetailProportion retailProportion = new RetailProportion();
- if (!Objects.isNull(esmRetailList) && !esmRetailList.isEmpty()) {
- retailLevel = Integer.parseInt(esmRetailList.get(0).getRetailtype());
- //赋值默认的分销比例
- retailProportion.setProportion(esmRetailList.get(0).getDisrate1(), esmRetailList.get(0).getDisrate2(), esmRetailList.get(0).getDisrate3());
- }
- //获取交强机构管理费总比例
- BigDecimal jqDeptProportion = ptlAgreementProductCostsExport.getJqExportRadioLevel1()
- .add(ptlAgreementProductCostsExport.getJqExportRadioLevel2())
- .add(ptlAgreementProductCostsExport.getJqExportRadioLevel3())
- .add(ptlAgreementProductCostsExport.getJqExportRadioLevel4())
- .add(ptlAgreementProductCostsExport.getJqExportRadioLevel5());
- //获取商业机构管理费总比例
- BigDecimal syDeptProportion = ptlAgreementProductCostsExport.getSyExportRadioLevel1()
- .add(ptlAgreementProductCostsExport.getSyExportRadioLevel2())
- .add(ptlAgreementProductCostsExport.getSyExportRadioLevel3())
- .add(ptlAgreementProductCostsExport.getSyExportRadioLevel4())
- .add(ptlAgreementProductCostsExport.getSyExportRadioLevel5());
- //获取非车机构管理费总比例
- BigDecimal noDeptProportion = ptlAgreementProductCostsExport.getNoCarExportRadioLevel1()
- .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel2())
- .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel3())
- .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel4())
- .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel5());
- //获取交强分销总比例
- BigDecimal jqRetailProportion = retailProportion.getJqRetailLevel1Proportion()
- .add(retailProportion.getJqRetailLevel2Proportion())
- .add(retailProportion.getJqRetailLevel3Proportion());
- //获取商业分销总比例
- BigDecimal syRetailProportion = retailProportion.getSyRetailLevel1Proportion()
- .add(retailProportion.getSyRetailLevel2Proportion())
- .add(retailProportion.getSyRetailLevel3Proportion());
- //获取非车分销总比例
- BigDecimal noRetailProportion = retailProportion.getNoRetailLevel1Proportion()
- .add(retailProportion.getNoRetailLevel2Proportion())
- .add(retailProportion.getNoRetailLevel3Proportion());
- // 外部订单比例
- BigDecimal enterProportion = sysSwitchConfigService.getEnterProportion(insOrders.getDeptid(), insOrders.getEntryStatus());
- //重新计算比例 入口是否超出支付的比例
- ReCalcuLateProportion jqReCalcuLateProportion = recalculateProportion(
- new BigDecimal(ptlAgreementProductCostsNew.getJqCostsProportion()),
- jqDeptProportion,
- jqRetailProportion,
- taxRadio,
- retailLevel,
- ptlAgreementProductCostsExport,
- retailProportion,
- "jq",
- enterProportion
- );
- ReCalcuLateProportion syReCalcuLateProportion = recalculateProportion(
- new BigDecimal(ptlAgreementProductCostsNew.getSyCostsProportion()),
- syDeptProportion,
- syRetailProportion,
- taxRadio,
- retailLevel,
- ptlAgreementProductCostsExport,
- retailProportion,
- "sy",
- enterProportion
- );
- ReCalcuLateProportion noReCalcuLateProportion = recalculateProportion(
- new BigDecimal(ptlAgreementProductCostsNew.getNoCostsProportion()),
- noDeptProportion,
- noRetailProportion,
- taxRadio,
- retailLevel,
- ptlAgreementProductCostsExport,
- retailProportion,
- "no",
- enterProportion
- );
- retailProportion.setProportion(jqReCalcuLateProportion, syReCalcuLateProportion, noReCalcuLateProportion);
- //endregion
- //region 计算分销费用
- //获取分销比例
- //分销总比例
- BigDecimal jqRetailRadio = new BigDecimal("0");
- BigDecimal syRetailRadio = new BigDecimal("0");
- BigDecimal noRetailRadio = new BigDecimal("0");
- FeeOrderNewVo.RetailFee retailFeeLevel3 = new FeeOrderNewVo.RetailFee();
- FeeOrderNewVo.RetailFee retailFeeLevel2 = new FeeOrderNewVo.RetailFee();
- FeeOrderNewVo.RetailFee retailFeeLevel1 = new FeeOrderNewVo.RetailFee();
- if (esmRetailList != null && !esmRetailList.isEmpty()) {
- EsmRetail esmRetail = esmRetailList.get(0);
- //分销等级
- insFeeOrderNew.setDistributionStatus(esmRetailList.get(0).getRetailtype());
- //用户分销人员id
- List<EsmUserReferrer> parents = esmUserReferrerService.findParents(sysUser.getId());
- if (esmRetail != null) {
- if (Integer.parseInt(esmRetail.getRetailtype()) >= 3) {
- insFeeOrderNew.setThirdDetailProportion(retailProportion.getJqRetailLevel3Proportion());
- retailFeeLevel3 = feeRuleSchemeService.calcRetail(insFeeOrderNew.getJqPremium(),
- insFeeOrderNew.getJqCostsProportion(),
- insFeeOrderNew.getSyPremium(),
- insFeeOrderNew.getSyCostsProportion().add(insFeeOrderNew.getSyOtherCostsProportion()),
- insFeeOrderNew.getNoPremium(),
- insFeeOrderNew.getNoCostsProportion().add(insFeeOrderNew.getNoOtherCostsProportion()),
- retailProportion.getJqRetailLevel3Proportion(),
- retailProportion.getSyRetailLevel3Proportion(),
- retailProportion.getNoRetailLevel3Proportion());
- insFeeOrderNew.setThirdDetailPremiums(retailFeeLevel3.getTotalRetailPremiums());
- if (parents != null && parents.size() > 2) {
- insFeeOrderNew.setThreeLevelUserId(parents.get(2).getId());
- }
- } else {
- insFeeOrderNew.setThirdDetailProportion(new BigDecimal(0));
- }
- if (Integer.parseInt(esmRetail.getRetailtype()) >= 2) {
- insFeeOrderNew.setSecondDetailProportion(retailProportion.getJqRetailLevel2Proportion());
- retailFeeLevel2 = feeRuleSchemeService.calcRetail(insFeeOrderNew.getJqPremium(),
- insFeeOrderNew.getJqCostsProportion(),
- insFeeOrderNew.getSyPremium(),
- insFeeOrderNew.getSyCostsProportion(),
- insFeeOrderNew.getNoPremium(),
- insFeeOrderNew.getNoCostsProportion(),
- retailProportion.getJqRetailLevel2Proportion(),
- retailProportion.getSyRetailLevel2Proportion(),
- retailProportion.getNoRetailLevel2Proportion());
- insFeeOrderNew.setSecondDetailPremiums(retailFeeLevel2.getTotalRetailPremiums());
- if (parents != null && parents.size() > 1) {
- insFeeOrderNew.setTwoLevelUserId(parents.get(1).getId());
- }
- } else {
- insFeeOrderNew.setSecondDetailProportion(new BigDecimal(0));
- }
- if (Integer.parseInt(esmRetail.getRetailtype()) >= 1) {
- insFeeOrderNew.setFirstDetailProportion(retailProportion.getJqRetailLevel1Proportion());
- retailFeeLevel1 = feeRuleSchemeService.calcRetail(insFeeOrderNew.getJqPremium(),
- insFeeOrderNew.getJqCostsProportion(),
- insFeeOrderNew.getSyPremium(),
- insFeeOrderNew.getSyCostsProportion(),
- insFeeOrderNew.getNoPremium(),
- insFeeOrderNew.getNoCostsProportion(),
- retailProportion.getJqRetailLevel1Proportion(),
- retailProportion.getSyRetailLevel1Proportion(),
- retailProportion.getNoRetailLevel1Proportion());
- insFeeOrderNew.setFirstDetailPremiums(retailFeeLevel1.getTotalRetailPremiums());
- if (parents != null && !parents.isEmpty()) {
- insFeeOrderNew.setFirstLevelUserId(parents.get(0).getId());
- }
- } else {
- insFeeOrderNew.setFirstDetailProportion(new BigDecimal(0));
- }
- } else {
- insFeeOrderNew.setFirstDetailPremiums(new BigDecimal(0));
- insFeeOrderNew.setSecondDetailPremiums(new BigDecimal(0));
- insFeeOrderNew.setThirdDetailPremiums(new BigDecimal(0));
- }
- } else {
- insFeeOrderNew.setFirstDetailProportion(new BigDecimal(0));
- insFeeOrderNew.setSecondDetailProportion(new BigDecimal(0));
- insFeeOrderNew.setThirdDetailProportion(new BigDecimal(0));
- }
- jqRetailRadio = jqRetailRadio.add(retailFeeLevel1.getJqRetailProportion())
- .add(retailFeeLevel2.getJqRetailProportion())
- .add(retailFeeLevel3.getJqRetailProportion());
- syRetailRadio = syRetailRadio.add(retailFeeLevel1.getSyRetailProportion())
- .add(retailFeeLevel2.getSyRetailProportion())
- .add(retailFeeLevel3.getSyRetailProportion());
- noRetailRadio = noRetailRadio.add(retailFeeLevel1.getNoRetailProportion())
- .add(retailFeeLevel2.getNoRetailProportion())
- .add(retailFeeLevel3.getNoRetailProportion());
- insFeeOrderNew.assignRetail(retailFeeLevel1, retailFeeLevel2, retailFeeLevel3);
- //endregion
- //region 设置机构管理费
- //交强机构管理费
- BigDecimal jqDeptRadio =
- jqReCalcuLateProportion.getDept_level_1_proportion()
- .add(jqReCalcuLateProportion.getDept_level_2_proportion())
- .add(jqReCalcuLateProportion.getDept_level_3_proportion())
- .add(jqReCalcuLateProportion.getDept_level_4_proportion())
- .add(jqReCalcuLateProportion.getDept_level_5_proportion());
- FeeOrderNewVo.DeptManagerFee jqDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(
- insFeeOrderNew.getJqPremium(),
- jqReCalcuLateProportion.getDept_level_1_proportion(),
- jqReCalcuLateProportion.getDept_level_2_proportion(),
- jqReCalcuLateProportion.getDept_level_3_proportion(),
- jqReCalcuLateProportion.getDept_level_4_proportion(),
- jqReCalcuLateProportion.getDept_level_5_proportion());
- BigDecimal syDeptRadio =
- syReCalcuLateProportion.getDept_level_1_proportion()
- .add(syReCalcuLateProportion.getDept_level_2_proportion())
- .add(syReCalcuLateProportion.getDept_level_3_proportion())
- .add(syReCalcuLateProportion.getDept_level_4_proportion())
- .add(syReCalcuLateProportion.getDept_level_5_proportion());
- FeeOrderNewVo.DeptManagerFee syDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(
- insFeeOrderNew.getSyPremium(),
- syReCalcuLateProportion.getDept_level_1_proportion(),
- syReCalcuLateProportion.getDept_level_2_proportion(),
- syReCalcuLateProportion.getDept_level_3_proportion(),
- syReCalcuLateProportion.getDept_level_4_proportion(),
- syReCalcuLateProportion.getDept_level_5_proportion());
- BigDecimal noDeptRadio =
- noReCalcuLateProportion.getDept_level_1_proportion()
- .add(noReCalcuLateProportion.getDept_level_2_proportion())
- .add(noReCalcuLateProportion.getDept_level_3_proportion())
- .add(noReCalcuLateProportion.getDept_level_4_proportion())
- .add(noReCalcuLateProportion.getDept_level_5_proportion());
- FeeOrderNewVo.DeptManagerFee noDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(
- insFeeOrderNew.getNoPremium(),
- noReCalcuLateProportion.getDept_level_1_proportion(),
- noReCalcuLateProportion.getDept_level_2_proportion(),
- noReCalcuLateProportion.getDept_level_3_proportion(),
- noReCalcuLateProportion.getDept_level_4_proportion(),
- noReCalcuLateProportion.getDept_level_5_proportion());
- insFeeOrderNew.assignDept(jqDeptManagerFee, syDeptManagerFee, noDeptManagerFee);
- //endregion
- //region 出口费用
- //交强出口手续费比例
- FeeOrderNewVo.ExportFee jqExportFee = feeRuleSchemeService.calcExportFee(
- insFeeOrderNew.getJqPremium(),
- new BigDecimal(ptlAgreementProductCostsNew.getJqCostsExportProportion()),
- insFeeOrderNew.getJqCostsProportion(),
- jqDeptRadio,
- jqRetailRadio,
- taxRadio,
- jqReCalcuLateProportion.getProxyProportion()
- );
- //商业出口手续费比例
- FeeOrderNewVo.ExportFee syExportFee = feeRuleSchemeService.calcExportFee(
- insFeeOrderNew.getSyPremium(),
- new BigDecimal(ptlAgreementProductCostsNew.getSyCostsExportProportion()),
- insFeeOrderNew.getSyCostsProportion(),
- syDeptRadio,
- syRetailRadio,
- taxRadio,
- syReCalcuLateProportion.getProxyProportion()
- );
- //非车出口手续费比例
- FeeOrderNewVo.ExportFee noExportFee = feeRuleSchemeService.calcExportFee(
- insFeeOrderNew.getNoPremium(),
- new BigDecimal(ptlAgreementProductCostsNew.getNoCostsExportProportion()),
- insFeeOrderNew.getNoCostsProportion(),
- noDeptRadio,
- noRetailRadio,
- taxRadio,
- noReCalcuLateProportion.getProxyProportion()
- );
- //出口手续费用
- insFeeOrderNew.setJqExportSuperviseCostsPremiums(twoPeople(jqExportFee.getSuperviseCostsPremiums()));
- insFeeOrderNew.setSyExportSuperviseCostsPremiums(twoPeople(syExportFee.getSuperviseCostsPremiums()));
- insFeeOrderNew.setNoExportSuperviseCostsPremiums(twoPeople(noExportFee.getSuperviseCostsPremiums()));
- //出口其他费用比例
- insFeeOrderNew.setJqExportOtherCostsProportion(twoPeople(jqExportFee.getOtherCostsProportion()));
- insFeeOrderNew.setSyExportOtherCostsProportion(twoPeople(syExportFee.getOtherCostsProportion()));
- insFeeOrderNew.setNoExportOtherCostsProportion(twoPeople(noExportFee.getOtherCostsProportion()));
- //出口其他费用
- insFeeOrderNew.setJqExportOtherCostsPremiums(twoPeople(jqExportFee.getOtherCostsPremiums()));
- insFeeOrderNew.setSyExportOtherCostsPremiums(twoPeople(syExportFee.getOtherCostsPremiums()));
- insFeeOrderNew.setNoExportOtherCostsPremiums(twoPeople(noExportFee.getOtherCostsPremiums()));
- //设置出口手续费比例
- insFeeOrderNew.setJqCostsExportProportion(twoPeople(jqExportFee.getSuperviseCosts()));
- insFeeOrderNew.setSyCostsExportProportion(twoPeople(syExportFee.getSuperviseCosts()));
- insFeeOrderNew.setNoCostsExportProportion(twoPeople(noExportFee.getSuperviseCosts()));
- // 外部费用
- insFeeOrderNew.setJqExternalProportion(jqExportFee.getExternalProportion());
- insFeeOrderNew.setJqExternalPremiums(jqExportFee.getExternalPremiums());
- insFeeOrderNew.setSyExternalProportion(syExportFee.getExternalProportion());
- insFeeOrderNew.setSyExternalPremiums(syExportFee.getExternalPremiums());
- insFeeOrderNew.setNoExternalProportion(noExportFee.getExternalProportion());
- insFeeOrderNew.setNoExternalPremiums(noExportFee.getExternalPremiums());
- //endregion
- //region 计算利润差值
- //入口 - 出口 - 机构管理费 1-5级 - 分销费 = 差值
- //分销交强费用
- //分开算 1 2 3 级
- BigDecimal jqFirst = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getJqRetailProportionLevel1().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
- BigDecimal jqSecond = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getJqRetailProportionLevel2().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
- BigDecimal jqThird = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getJqRetailProportionLevel3().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
- BigDecimal jqFenXiao = jqFirst.add(jqSecond).add(jqThird);
- //分销商业费用
- BigDecimal syFirst = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getSyRetailProportionLevel1().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
- BigDecimal sySecond = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getSyRetailProportionLevel2().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
- BigDecimal syThird = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getSyRetailProportionLevel3().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
- BigDecimal syFenXiao = syFirst.add(sySecond).add(syThird);
- //分销非车费用
- BigDecimal noFirst = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getNoRetailProportionLevel1().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
- BigDecimal noSecond = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getNoRetailProportionLevel2().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
- BigDecimal noThird = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getNoRetailProportionLevel3().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
- BigDecimal noFenXiao = noFirst.add(noSecond).add(noThird);
- BigDecimal jqDifference = jqEntranceFee.getTotalAmount()
- .subtract(jqExportFee.getExternalPremiums())
- .subtract(
- (jqExportFee.getSuperviseCostsPremiums().add(jqExportFee.getOtherCostsPremiums())))
- .subtract(
- (jqDeptManagerFee.getDeptPremiumsLevelOne().add(jqDeptManagerFee.getDeptPremiumsLevelTwo().add(jqDeptManagerFee.getDeptPremiumsLevelThree()).add(jqDeptManagerFee.getDeptPremiumsLevelFoure()).add(jqDeptManagerFee.getDeptPremiumsLevelFive())))
- )
- .subtract(jqFenXiao)
- .setScale(5, BigDecimal.ROUND_HALF_DOWN);
- insFeeOrderNew.setJqProfitMarginPremiums(jqDifference);
- BigDecimal syDifference = syEntranceFee.getTotalAmount()
- .subtract(syExportFee.getExternalPremiums())
- .subtract(
- (syExportFee.getSuperviseCostsPremiums().add(syExportFee.getOtherCostsPremiums())))
- .subtract(
- (syDeptManagerFee.getDeptPremiumsLevelOne().add(syDeptManagerFee.getDeptPremiumsLevelTwo().add(syDeptManagerFee.getDeptPremiumsLevelThree()).add(syDeptManagerFee.getDeptPremiumsLevelFoure()).add(syDeptManagerFee.getDeptPremiumsLevelFive())))
- )
- .subtract(syFenXiao)
- .setScale(5, BigDecimal.ROUND_HALF_DOWN);
- insFeeOrderNew.setSyProfitMarginPremiums(syDifference);
- BigDecimal noDifference = noEntranceFee.getTotalAmount()
- .subtract(noExportFee.getExternalPremiums())
- .subtract(
- (noExportFee.getSuperviseCostsPremiums().add(noExportFee.getOtherCostsPremiums())))
- .subtract(
- (noDeptManagerFee.getDeptPremiumsLevelOne().add(noDeptManagerFee.getDeptPremiumsLevelTwo().add(noDeptManagerFee.getDeptPremiumsLevelThree()).add(noDeptManagerFee.getDeptPremiumsLevelFoure()).add(noDeptManagerFee.getDeptPremiumsLevelFive())))
- )
- .subtract(noFenXiao)
- .setScale(5, BigDecimal.ROUND_HALF_DOWN);
- insFeeOrderNew.setNoProfitMarginPremiums(noDifference);
- //endregion
- //region 比例逆推是否等于0
- if (!feeRuleSchemeService.calculateProportion(jqEntranceFee, jqDeptManagerFee, jqExportFee, jqRetailRadio, taxRadio, insFeeOrderNew.getJqPremium()))
- throw new SystemException("交强比例异常");
- if (!feeRuleSchemeService.calculateProportion(syEntranceFee, syDeptManagerFee, syExportFee, syRetailRadio, taxRadio, insFeeOrderNew.getSyPremium()))
- throw new SystemException("商业比例异常");
- if (!feeRuleSchemeService.calculateProportion(noEntranceFee, noDeptManagerFee, noExportFee, noRetailRadio, taxRadio, insFeeOrderNew.getNoPremium()))
- throw new SystemException("非车比例异常");
- //endregion
- insFeeOrderNewHistoryService.saveInsFeeOrderNewHistory(insFeeOrderNew);
- insFeeOrderNewService.saveOrUpdate(insFeeOrderNew);
- }
- /**
- * 判断是否包含非车险
- *
- * @param insAreaCompany
- * @return
- */
- private boolean isContainNonCar(InsAreaCompany insAreaCompany) {
- if (insAreaCompany.getCrossInsurance() != null && insAreaCompany.getJypremium().equals(BigDecimal.ZERO)) {
- return false;
- }
- return true;
- }
- /**
- * 匹配费用因子
- *
- * @param agreementProductCosts
- * @param insAreaCompany
- * @param insOrders
- * @return
- */
- private String verificationCosts(List<AgreementProductCosts> agreementProductCosts, QuoteRespVo quoteRespVo, InsAreaCompany insAreaCompany,
- InsOrders insOrders, StringBuilder logs) {
- //匹配费用因子
- //获取所有费用属性
- List<PtlAgreementUndwrtRulesAttr> undwrtRulesAttrList = ptlAgreementUndwrtRulesAttrService.getUndwrtRulesAttrList();
- //获取新旧车信息
- PtlNewCarJudgeRules carJudgeRule = getCarJudgeRule(insAreaCompany.getCompanyId(), insOrders.getCarinfo().getString("cimodelclass"));
- //获取所有费用属性关联
- List<RuleAttrMappingVo> ruleAttrMappingVoList = RuleAttrMappingVo.getRuleAttrMappingVoList(quoteRespVo, insAreaCompany, insOrders,
- undwrtRulesAttrList, carJudgeRule);
- for (int i = 0; i < agreementProductCosts.size(); i++) {
- //判断是否匹配
- log.debug("费用因子匹配开始:" + agreementProductCosts.get(i).getId());
- log.debug("车牌号:" + insOrders.getLicenseno());
- log.debug("费用因子备注:" + agreementProductCosts.get(i).getCostsDescription());
- logs.append("费用id:" + agreementProductCosts.get(i).getId() + "\n");
- logs.append("费用因子描述:" + agreementProductCosts.get(i).getCostsDescription() + "\n");
- if (judgements(agreementProductCosts.get(i).getCostsAttrLinks(), undwrtRulesAttrList, ruleAttrMappingVoList, logs)) {
- //返回 费用id 如果需要匹配非车的情况 将返回值返回list 后赛选
- return agreementProductCosts.get(i).getId();
- }
- log.debug("当前费用因子匹配结束\n");
- }
- return null;
- // throw new SystemException("费用因子匹配失败");
- }
- private boolean verificationRules(List<PtlAgreementUndwrtRulesNew> ptlAgreementUndwrtRulesNews, InsAreaCompany insAreaCompany,
- InsOrders insOrders) {
- StringBuilder logs = new StringBuilder();
- //匹配承保规则
- //获取所有承保规则属性
- List<PtlAgreementUndwrtRulesAttr> undwrtRulesAttrList = ptlAgreementUndwrtRulesAttrService.getUndwrtRulesAttrList();
- //获取所有费用属性关联
- List<RuleAttrMappingVo> ruleAttrMappingVoList = RuleAttrMappingVo.getRuleAttrMappingVoList(null,insAreaCompany, insOrders,
- undwrtRulesAttrList, getCarJudgeRule(insAreaCompany.getCompanyId(),insOrders.getCarinfo().getString("cimodelclass")));
- for (int i = 0; i < ptlAgreementUndwrtRulesNews.size(); i++) {
- logs.append("触发承保规则:" + ptlAgreementUndwrtRulesNews.get(i).getRuleDescription() + "\n");
- //判断是否匹配
- if (!judgementsRules(ptlAgreementUndwrtRulesNews.get(i).getRulesAttrList(), undwrtRulesAttrList, ruleAttrMappingVoList, logs,insOrders)) {
- throw new SystemException(logs.toString());
- }else{
- //如果没有出现异常则清空匹配消息
- logs.delete(0,logs.length());
- }
- }
- return true;
- }
- /**
- * 费用因子的对比
- *
- * @param ptlAgreementProductCostsAttrLinks 费用因子范围规则
- * @param rulesAttrs 费用因子属性
- * @param ruleAttrMappingVoList 表单提交的值
- * @return
- */
- private boolean judgements(List<PtlAgreementProductCostsAttrLink> ptlAgreementProductCostsAttrLinks,
- List<PtlAgreementUndwrtRulesAttr> rulesAttrs, List<RuleAttrMappingVo> ruleAttrMappingVoList,
- StringBuilder logs) {
- boolean useFlag = true;
- for (PtlAgreementProductCostsAttrLink ptlAgreementProductCostsAttrLink : ptlAgreementProductCostsAttrLinks) {
- //查找规则中的 传值属性
- RuleAttrMappingVo ruleAttrMappingVo = ruleAttrMappingVoList.stream()
- .filter(x -> x.getAttrCode().equals(ptlAgreementProductCostsAttrLink.getAttrCode()))
- .findFirst()
- .orElse(null);
- //如果查找不到 传值属性 直接费用对比失败
- if (ruleAttrMappingVo == null) {
- log.debug("传入的值找不到该属性:" + ptlAgreementProductCostsAttrLink.getAttrCode());
- log.debug("规则匹配失败:" + ptlAgreementProductCostsAttrLink.getAttrCode());
- List<PtlAgreementUndwrtRulesAttr> collect = rulesAttrs.stream()
- .filter(x -> x.getAttrCode().equals(ptlAgreementProductCostsAttrLink.getAttrCode()))
- .collect(Collectors.toList());
- if (!collect.isEmpty()) {
- logs.append("规则匹配失败:" + collect.get(0).getAttrName() + "\n");
- }
- return false;
- }
- //查找 费用因子规则
- PtlAgreementUndwrtRulesAttr ptlAgreementUndwrtRulesAttr = rulesAttrs.stream()
- .filter(x -> x.getAttrCode().equals(ptlAgreementProductCostsAttrLink.getAttrCode()))
- .findFirst()
- .get();
- if(!Objects.isNull(ruleAttrMappingVo.getValue())) {
- useFlag = attrEqual(ptlAgreementProductCostsAttrLink, ptlAgreementUndwrtRulesAttr, ruleAttrMappingVo.getValue());
- }else{
- useFlag = false;
- }
- if (!useFlag) {
- log.debug("检验的值:" + ptlAgreementProductCostsAttrLink.getMin());
- log.debug("传入的值:" + ruleAttrMappingVo.getValue());
- log.debug("规则匹配失败:" + ptlAgreementProductCostsAttrLink.getAttrCode());
- List<PtlAgreementUndwrtRulesAttr> collect = rulesAttrs.stream()
- .filter(x -> x.getAttrCode().equals(ptlAgreementProductCostsAttrLink.getAttrCode()))
- .collect(Collectors.toList());
- if (ptlAgreementProductCostsAttrLink.getMin() != null) {
- logs.append("检验的值:" + ptlAgreementProductCostsAttrLink.getMin() + "\n");
- } else {
- logs.append("检验的值:" + ptlAgreementProductCostsAttrLink.getMax() + "\n");
- }
- logs.append("传入的值:" + ruleAttrMappingVo.getValue() + "\n");
- if (!collect.isEmpty()) {
- logs.append("<span style=\"color:red;\">规则匹配失败:" + collect.get(0).getAttrName() + "</span>\n");
- }
- return false;
- }
- }
- return useFlag;
- }
- /**
- * 承保规则因子的对比
- *
- * @param ptlAgreementUndwrtRulesAttrLinks
- * @param rulesAttrs
- * @param ruleAttrMappingVoList
- * @return
- */
- private boolean judgementsRules(List<PtlAgreementUndwrtRulesAttrLink> ptlAgreementUndwrtRulesAttrLinks,
- List<PtlAgreementUndwrtRulesAttr> rulesAttrs, List<RuleAttrMappingVo> ruleAttrMappingVoList,
- StringBuilder logs,InsOrders insOrders) {
- boolean useFlag = true;
- for (int i = 0; i < ptlAgreementUndwrtRulesAttrLinks.size(); i++) {
- int finalI = i;
- //查找规则中的 传值属性
- RuleAttrMappingVo ruleAttrMappingVo = ruleAttrMappingVoList.stream().filter(x ->
- x.getAttrCode().equals(ptlAgreementUndwrtRulesAttrLinks.get(finalI).getAttrCode())).findFirst().orElse(null);
- //如果查找不到 传值属性 直接费用对比失败
- if (ruleAttrMappingVo == null) {
- return true;
- }
- //查找 费用因子规则
- PtlAgreementUndwrtRulesAttr ptlAgreementUndwrtRulesAttr =
- rulesAttrs.stream().filter(x -> x.getAttrCode().equals(ptlAgreementUndwrtRulesAttrLinks.get(finalI).getAttrCode())).findFirst().get();
- //如果是多选 对value进行转换
- if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("checkbox")) {
- PtlAgreementUndwrtRulesDictLabal ptlAgreementUndwrtRulesDictLabal =
- ptlAgreementUndwrtRulesAttr.getDictLabal().stream().filter(x ->
- x.getName().equals(ruleAttrMappingVo.getValue())).findFirst().orElse(null);
- ruleAttrMappingVo.setValue(ptlAgreementUndwrtRulesDictLabal.getName());
- }
- //如果是单选 并且是 性别的话 转换为code
- if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("radio")) {
- if ("CarOwnersSex".equals(ptlAgreementUndwrtRulesAttr.getAttrCode()) || "ApplicantSex".equals(ptlAgreementUndwrtRulesAttr.getAttrCode()) ||
- "InsuredSex".equals(ptlAgreementUndwrtRulesAttr.getAttrCode())) {
- PtlAgreementUndwrtRulesDictLabal ptlAgreementUndwrtRulesDictLabal =
- ptlAgreementUndwrtRulesAttr.getDictLabal().stream().filter(x ->
- x.getCode().equals(ruleAttrMappingVo.getValue())).findFirst().orElse(null);
- ruleAttrMappingVo.setValue(ptlAgreementUndwrtRulesDictLabal.getCode());
- }
- }
- if(!Objects.isNull(ruleAttrMappingVo.getValue())) {
- useFlag = attrEqual(ptlAgreementUndwrtRulesAttrLinks.get(i), ptlAgreementUndwrtRulesAttr, ruleAttrMappingVo.getValue(),insOrders);
- }else{
- useFlag = false;
- }
- if (useFlag) {
- return true;
- } else {
- logs.append("规则匹配失败:" + ptlAgreementUndwrtRulesAttrLinks.get(i).getAttrCode() + "\n");
- if (ptlAgreementUndwrtRulesAttrLinks.get(i).getMin() != null) {
- logs.append("校验的值:" + ptlAgreementUndwrtRulesAttrLinks.get(i).getMin() + "\n");
- } else {
- logs.append("校验的值:" + ptlAgreementUndwrtRulesAttrLinks.get(i).getMax() + "\n");
- }
- logs.append("传入的值:" + ruleAttrMappingVo.getValue() + "\n");
- }
- }
- return useFlag;
- }
- /**
- * 费用因子的对比 强制非车险
- *
- * @param ptlAgreementProductCostsAttrLinks 费用因子范围规则
- * @param rulesAttrs 费用因子属性
- * @param ruleAttrMappingVoList 表单提交的值
- * @return
- */
- private boolean judgementsIsNoCar(List<PtlAgreementProductCostsAttrLink> ptlAgreementProductCostsAttrLinks,
- List<PtlAgreementUndwrtRulesAttr> rulesAttrs, List<RuleAttrMappingVo> ruleAttrMappingVoList) {
- boolean useFlag = true;
- for (int i = 0; i < ptlAgreementProductCostsAttrLinks.size(); i++) {
- int finalI = i;
- //查找规则中的 传值属性
- RuleAttrMappingVo ruleAttrMappingVo =
- ruleAttrMappingVoList.stream().filter(x -> x.getAttrCode().equals(ptlAgreementProductCostsAttrLinks.get(finalI).getAttrCode())).findFirst().orElse(null);
- //如果是强制非车险
- if (ptlAgreementProductCostsAttrLinks.get(i).getAttrCode().equals("IsNonMotorInsurance"))
- continue;
- //如果查找不到 传值属性 直接费用对比失败
- if (ruleAttrMappingVo == null)
- return false;
- //查找 费用因子规则
- PtlAgreementUndwrtRulesAttr ptlAgreementUndwrtRulesAttr =
- rulesAttrs.stream().filter(x -> x.getAttrCode().equals(ptlAgreementProductCostsAttrLinks.get(finalI).getAttrCode())).findFirst().get();
- //如果是多选 对value进行转换
- if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("checkbox")) {
- PtlAgreementUndwrtRulesDictLabal ptlAgreementUndwrtRulesDictLabal =
- ptlAgreementUndwrtRulesAttr.getDictLabal().stream().filter(x ->
- x.getCode().equals(ruleAttrMappingVo.getValue())).findFirst().orElse(null);
- ruleAttrMappingVo.setValue(ptlAgreementUndwrtRulesDictLabal.getName());
- }
- //如果是单选 并且是 性别的话 转换为code
- if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("radio")) {
- if ("CarOwnersSex".equals(ptlAgreementUndwrtRulesAttr.getAttrCode()) || "ApplicantSex".equals(ptlAgreementUndwrtRulesAttr.getAttrCode()) ||
- "InsuredSex".equals(ptlAgreementUndwrtRulesAttr.getAttrCode())) {
- PtlAgreementUndwrtRulesDictLabal ptlAgreementUndwrtRulesDictLabal =
- ptlAgreementUndwrtRulesAttr.getDictLabal().stream().filter(x ->
- x.getName().equals(ruleAttrMappingVo.getValue())).findFirst().orElse(null);
- ruleAttrMappingVo.setValue(ptlAgreementUndwrtRulesDictLabal.getCode());
- }
- }
- useFlag = attrEqual(ptlAgreementProductCostsAttrLinks.get(i), ptlAgreementUndwrtRulesAttr, ruleAttrMappingVo.getValue());
- if (!useFlag) {
- System.out.printf("规则匹配失败:" + ptlAgreementProductCostsAttrLinks.get(i).getAttrCode());
- return false;
- }
- }
- return useFlag;
- }
- /**
- * 属性比较 返回 是否匹配
- *
- * @param ptlAgreementProductCostsAttrLink
- * @param ptlAgreementUndwrtRulesAttr
- * @param value
- * @return
- */
- private boolean attrEqual(PtlAgreementProductCostsAttrLink ptlAgreementProductCostsAttrLink,
- PtlAgreementUndwrtRulesAttr ptlAgreementUndwrtRulesAttr, String value) {
- if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("checkbox")) {
- return checkBoxEqual(ptlAgreementProductCostsAttrLink, value);
- } else if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("inputNumber")) {
- return inputNumberEqual(ptlAgreementProductCostsAttrLink, value);
- } else if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("input")) {
- //截取身份证号码
- if (ptlAgreementProductCostsAttrLink.getAttrCode().equals("CarOwnersIDNumber") || ptlAgreementProductCostsAttrLink.getAttrCode().equals("ApplicantIDNumber") ||
- ptlAgreementProductCostsAttrLink.getAttrCode().equals("InsuredIDNumber")) {
- value = value.substring(0, ptlAgreementProductCostsAttrLink.getMin().length());
- }
- return inputTextEqual(ptlAgreementProductCostsAttrLink, value);
- } else if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("select")) {
- //截取车牌
- if (ptlAgreementUndwrtRulesAttr.getAttrCode().equals("LicenseNo")) {
- value = value.substring(0, 2);
- }
- return selectEqual(ptlAgreementProductCostsAttrLink, value);
- } else if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("radio")) {
- return radioEqual(ptlAgreementProductCostsAttrLink, value);
- } else if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("datetime")){ // 时间
- return dateTimeEqual(ptlAgreementProductCostsAttrLink, value);
- } else if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("date")){
- return dateEqual(ptlAgreementProductCostsAttrLink, value);
- }
- return false;
- }
- private boolean attrEqual(PtlAgreementUndwrtRulesAttrLink ptlAgreementUndwrtRulesAttrLink,
- PtlAgreementUndwrtRulesAttr ptlAgreementUndwrtRulesAttr, String value,InsOrders insOrders) {
- if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("checkbox")) {
- return checkBoxEqual(ptlAgreementUndwrtRulesAttrLink, value);
- } else if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("inputNumber")) {
- //如果是空字符串 则返回false
- // if(value.equals("")){
- // return false;
- // }
- return inputNumberEqual(ptlAgreementUndwrtRulesAttrLink, value);
- } else if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("input")) {
- //截取身份证号码
- if (ptlAgreementUndwrtRulesAttr.getAttrCode().equals("CarOwnersIDNumber") || ptlAgreementUndwrtRulesAttr.getAttrCode().equals("ApplicantIDNumber") ||
- ptlAgreementUndwrtRulesAttr.getAttrCode().equals("InsuredIDNumber")) {
- value = value.substring(0, ptlAgreementUndwrtRulesAttrLink.getMin().length());
- }
- return inputTextEqual(ptlAgreementUndwrtRulesAttrLink, value);
- } else if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("select")) {
- //截取车牌
- if (ptlAgreementUndwrtRulesAttr.getAttrCode().equals("LicenseNo")) {
- value = value.substring(0, 2);
- }
- return selectEqual(ptlAgreementUndwrtRulesAttrLink, value);
- } else if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("radio")) {
- return radioEqual(ptlAgreementUndwrtRulesAttrLink, value);
- } else if(ptlAgreementUndwrtRulesAttr.getAttrType().equals("datetime")){
- return dateTimeEqual(ptlAgreementUndwrtRulesAttrLink, value, insOrders);
- } else if(ptlAgreementUndwrtRulesAttr.getAttrType().equals("date")){
- return dateEqual(ptlAgreementUndwrtRulesAttrLink,value);
- }
- return false;
- }
- /**
- * 属性为多选判断
- *
- * @param ptlAgreementProductCostsAttrLink
- * @param value
- * @return
- */
- private boolean checkBoxEqual(PtlAgreementProductCostsAttrLink ptlAgreementProductCostsAttrLink, String value) {
- String[] split = ptlAgreementProductCostsAttrLink.getMin().split(",");
- for (String sp : split) {
- if (sp.equals(value)) {
- return true;
- }
- }
- return false;
- }
- private boolean checkBoxEqual(PtlAgreementUndwrtRulesAttrLink ptlAgreementUndwrtRulesAttrLink, String value) {
- if (!ptlAgreementUndwrtRulesAttrLink.getMin().equals(value)) {
- return true;
- }
- return false;
- }
- /**
- * 属性为数值型判断
- *
- * @param ptlAgreementProductCostsAttrLink
- * @param value
- * @return
- */
- private boolean inputNumberEqual(PtlAgreementProductCostsAttrLink ptlAgreementProductCostsAttrLink, String value) {
- double v = Double.parseDouble(value);
- //统一处理数值
- if ("1".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
- if (Double.parseDouble(ptlAgreementProductCostsAttrLink.getMin()) <= v &&
- Double.parseDouble(ptlAgreementProductCostsAttrLink.getMax()) >= v) {
- return true;
- }
- } else if ("2".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
- if (Double.parseDouble(ptlAgreementProductCostsAttrLink.getMin()) > v) {
- return true;
- }
- } else if ("3".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
- if (Double.parseDouble(ptlAgreementProductCostsAttrLink.getMin()) >= v) {
- return true;
- }
- } else if ("4".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
- if (Double.parseDouble(ptlAgreementProductCostsAttrLink.getMax()) < v) {
- return true;
- }
- } else if ("5".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
- if (Double.parseDouble(ptlAgreementProductCostsAttrLink.getMax()) <= v) {
- return true;
- }
- }
- return false;
- }
- private boolean inputNumberEqual(PtlAgreementUndwrtRulesAttrLink ptlAgreementUndwrtRulesAttrLink, String value) {
- double v = Double.parseDouble(value);
- //统一处理数值
- if ("1".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
- if (Double.parseDouble(ptlAgreementUndwrtRulesAttrLink.getMin()) <= v &&
- Double.parseDouble(ptlAgreementUndwrtRulesAttrLink.getMax()) >= v) {
- return false;
- }
- } else if ("2".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
- if (Double.parseDouble(ptlAgreementUndwrtRulesAttrLink.getMin()) > v) {
- return false;
- }
- } else if ("3".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
- if (Double.parseDouble(ptlAgreementUndwrtRulesAttrLink.getMin()) >= v) {
- return false;
- }
- } else if ("4".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
- if (Double.parseDouble(ptlAgreementUndwrtRulesAttrLink.getMax()) < v) {
- return false;
- }
- } else if ("5".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
- if (Double.parseDouble(ptlAgreementUndwrtRulesAttrLink.getMax()) <= v) {
- return false;
- }
- }
- return true;
- }
- /**
- * 属性为输入框判断
- *
- * @param ptlAgreementProductCostsAttrLink
- * @param value
- * @return
- */
- private boolean inputTextEqual(PtlAgreementProductCostsAttrLink ptlAgreementProductCostsAttrLink, String value) {
- //将值进行分割
- String[] split = ptlAgreementProductCostsAttrLink.getMin().split(",");
- AtomicBoolean returnBool = new AtomicBoolean(false);
- List<String> equalsMap = new ArrayList<>();
- //字符型评分
- equalsMap.add("CharacterBasedRating");
- //交强字符型评分
- equalsMap.add("JqCharacterBasedRating");
- //商业字符型评分
- equalsMap.add("SyCharacterBasedRating");
- // 阳光红黄蓝车系
- equalsMap.add("SeriesTypeActualName");
- //equest 等于判断
- if(equalsMap.contains(ptlAgreementProductCostsAttrLink.getAttrCode())){
- boolean b = Arrays.stream(split).anyMatch(value::equals);
- returnBool.set(b);
- }else if((ptlAgreementProductCostsAttrLink.getAttrCode().equals("BrandandModel") || ptlAgreementProductCostsAttrLink.getAttrCode().equals("CarOwnerName")
- || ptlAgreementProductCostsAttrLink.getAttrCode().equals("CarOwnersAddress") || ptlAgreementProductCostsAttrLink.getAttrCode().equals("ApplicantAddress")
- || ptlAgreementProductCostsAttrLink.getAttrCode().equals("InsuredAddress"))
- && ptlAgreementProductCostsAttrLink.getOperator().equals("2")){
- //处理品牌型号 不包含的情况
- boolean anyMatch = Arrays.stream(split)
- .anyMatch(value::contains);
- returnBool.set(!anyMatch);
- }else {
- boolean anyMatch = Arrays.stream(split)
- .anyMatch(value::contains);
- returnBool.set(anyMatch);
- }
- return returnBool.get();
- }
- private boolean inputTextEqual(PtlAgreementUndwrtRulesAttrLink ptlAgreementUndwrtRulesAttrLink, String value) {
- //将值进行分割
- String[] split = ptlAgreementUndwrtRulesAttrLink.getMin().split(",");
- AtomicBoolean returnBool = new AtomicBoolean(false);
- List<String> equalsMap = new ArrayList<>();
- //字符型评分
- equalsMap.add("CharacterBasedRating");
- //交强字符型评分
- equalsMap.add("JqCharacterBasedRating");
- //商业字符型评分
- equalsMap.add("SyCharacterBasedRating");
- // 阳光红黄蓝车系
- equalsMap.add("SeriesTypeActualName");
- //equest 等于判断
- if(equalsMap.contains(ptlAgreementUndwrtRulesAttrLink.getAttrCode())){
- boolean b = Arrays.stream(split).anyMatch(value::equals);
- returnBool.set(b);
- }else if((ptlAgreementUndwrtRulesAttrLink.getAttrCode().equals("BrandandModel") || ptlAgreementUndwrtRulesAttrLink.getAttrCode().equals("CarOwnerName")
- || ptlAgreementUndwrtRulesAttrLink.getAttrCode().equals("CarOwnersAddress") || ptlAgreementUndwrtRulesAttrLink.getAttrCode().equals("ApplicantAddress")
- || ptlAgreementUndwrtRulesAttrLink.getAttrCode().equals("InsuredAddress"))
- && ptlAgreementUndwrtRulesAttrLink.getOperator().equals("2")){
- //处理品牌型号 不包含的情况
- boolean anyMatch = Arrays.stream(split)
- .anyMatch(value::contains);
- returnBool.set(!anyMatch);
- }else {
- boolean anyMatch = Arrays.stream(split)
- .anyMatch(value::contains);
- returnBool.set(anyMatch);
- }
- return !returnBool.get();
- }
- /**
- * 属性为下拉框判断
- *
- * @param ptlAgreementProductCostsAttrLink
- * @param value
- * @return
- */
- private boolean selectEqual(PtlAgreementProductCostsAttrLink ptlAgreementProductCostsAttrLink, String value) {
- // 包含情况
- if (ptlAgreementProductCostsAttrLink.getMin() != null && ptlAgreementProductCostsAttrLink.getMin().contains(value) && ptlAgreementProductCostsAttrLink.getOperator().equals("0")) {
- return true;
- }
- // 不包含的情况
- if (ptlAgreementProductCostsAttrLink.getMin()!= null && !ptlAgreementProductCostsAttrLink.getMin().contains(value) && ptlAgreementProductCostsAttrLink.getOperator().equals("1")) {
- return true;
- }
- return false;
- }
- /**
- * 属性为选择框判断
- *
- * @param ptlAgreementUndwrtRulesAttrLink
- * @param value
- * @return
- */
- private boolean selectEqual(PtlAgreementUndwrtRulesAttrLink ptlAgreementUndwrtRulesAttrLink, String value) {
- if (ptlAgreementUndwrtRulesAttrLink.getMin() == null) {
- return false;
- }
- if (!ptlAgreementUndwrtRulesAttrLink.getMin().contains(value)) {
- return true;
- }
- return false;
- }
- /**
- * 属性为单选框判断
- *
- * @param ptlAgreementProductCostsAttrLink
- * @param value
- * @return
- */
- private boolean radioEqual(PtlAgreementProductCostsAttrLink ptlAgreementProductCostsAttrLink, String value) {
- //新能源判断
- if ("NewEnergy".equals(ptlAgreementProductCostsAttrLink.getAttrCode())) {
- // 是否是新能源车
- boolean newEnergy = EnergyType.isNewEnergy(value);
- if (newEnergy && ptlAgreementProductCostsAttrLink.getMin().equals("1")) {
- return true;
- } else if (!newEnergy && ptlAgreementProductCostsAttrLink.getMin().equals("0")) {
- return true;
- }
- } else if (ptlAgreementProductCostsAttrLink.getMin().contains(value)) {
- return true;
- }
- return false;
- }
- private boolean radioEqual(PtlAgreementUndwrtRulesAttrLink ptlAgreementUndwrtRulesAttrLink, String value) {
- //新能源判断
- if ("NewEnergy".equals(ptlAgreementUndwrtRulesAttrLink.getAttrCode())) {
- // 是否是新能源车
- boolean newEnergy = EnergyType.isNewEnergy(value);
- if (newEnergy && ptlAgreementUndwrtRulesAttrLink.getMin().equals("1")) {
- return false;
- } else if (!newEnergy && ptlAgreementUndwrtRulesAttrLink.getMin().equals("0")) {
- return false;
- }
- } else if (ptlAgreementUndwrtRulesAttrLink.getMin().contains(value)) {
- return false;
- }
- return true;
- }
- public boolean dateTimeEqual(PtlAgreementProductCostsAttrLink ptlAgreementProductCostsAttrLink, String value){
- DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
- if(Objects.isNull(value) || value.equals("")){
- return false;
- }
- LocalDateTime v = LocalDateTime.parse(value,formatter);
- LocalDateTime min = null,max = null;
- if(!Objects.isNull(ptlAgreementProductCostsAttrLink.getMin())){
- min = LocalDateTime.parse(ptlAgreementProductCostsAttrLink.getMin(),formatter);
- }
- if(!Objects.isNull(ptlAgreementProductCostsAttrLink.getMax())){
- max = LocalDateTime.parse(ptlAgreementProductCostsAttrLink.getMax(),formatter);
- }
- //统一处理数值
- if ("1".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
- if (v.isAfter(min) && v.isBefore(max)) {
- return true;
- }
- } else if ("2".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
- if (v.isBefore(min)) {
- return true;
- }
- } else if ("3".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
- if (v.isBefore(min) || v.isEqual(min)) {
- return true;
- }
- } else if ("4".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
- if (v.isAfter(max)) {
- return true;
- }
- } else if ("5".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
- if (v.isAfter(max) || v.isEqual(max)) {
- return true;
- }
- }
- return false;
- }
- public boolean dateEqual(PtlAgreementProductCostsAttrLink ptlAgreementProductCostsAttrLink, String value){
- // DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
- if(Objects.isNull(value) || value.equals("")){
- return false;
- }
- LocalDateTime v = LocalDate.parse(value).atStartOfDay();
- LocalDateTime min = null,max = null;
- if(!Objects.isNull(ptlAgreementProductCostsAttrLink.getMin())){
- min = LocalDate.parse(ptlAgreementProductCostsAttrLink.getMin()).atStartOfDay();
- }
- if(!Objects.isNull(ptlAgreementProductCostsAttrLink.getMax())){
- max = LocalDate.parse(ptlAgreementProductCostsAttrLink.getMax()).atStartOfDay();
- }
- //统一处理数值
- if ("1".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
- if (v.isAfter(min) && v.isBefore(max)) {
- return true;
- }
- } else if ("2".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
- if (v.isBefore(min)) {
- return true;
- }
- } else if ("3".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
- if (v.isBefore(min) || v.isEqual(min)) {
- return true;
- }
- } else if ("4".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
- if (v.isAfter(max)) {
- return true;
- }
- } else if ("5".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
- if (v.isAfter(max) || v.isEqual(max)) {
- return true;
- }
- }
- return false;
- }
- public boolean dateTimeEqual(PtlAgreementUndwrtRulesAttrLink ptlAgreementUndwrtRulesAttrLink, String value, InsOrders insOrders){
- DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
- //判断险种 的起保时间
- if(ptlAgreementUndwrtRulesAttrLink.getAttrCode().equals("SyStartTime") || ptlAgreementUndwrtRulesAttrLink.getAttrCode().equals("JqStartTime"))
- {
- if(insOrders.getProductid().equals(ProductsType.PT_0330.getCode()) && ptlAgreementUndwrtRulesAttrLink.getAttrCode().equals("SyStartTime")){
- return true;
- }
- if(insOrders.getProductid().equals(ProductsType.PT_034001.getCode()) && ptlAgreementUndwrtRulesAttrLink.getAttrCode().equals("JqStartTime")){
- return true;
- }
- }
- if(!Objects.isNull(value) && !value.isEmpty()) {
- LocalDateTime v = LocalDateTime.parse(value, formatter);
- LocalDateTime min = null, max = null;
- if (!Objects.isNull(ptlAgreementUndwrtRulesAttrLink.getMin())) {
- min = LocalDateTime.parse(ptlAgreementUndwrtRulesAttrLink.getMin(), formatter);
- }
- if (!Objects.isNull(ptlAgreementUndwrtRulesAttrLink.getMax())) {
- max = LocalDateTime.parse(ptlAgreementUndwrtRulesAttrLink.getMax(), formatter);
- }
- //统一处理数值
- if ("1".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
- if (!v.isAfter(min) && v.isBefore(max)) {
- return true;
- }
- } else if ("2".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
- if (!v.isBefore(min)) {
- return true;
- }
- } else if ("3".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
- if (!v.isBefore(min)) {
- return true;
- }
- } else if ("4".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
- if (!v.isAfter(max)) {
- return true;
- }
- } else if ("5".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
- if (!v.isAfter(max)) {
- return true;
- }
- }
- }
- return false;
- }
- public boolean dateEqual(PtlAgreementUndwrtRulesAttrLink ptlAgreementUndwrtRulesAttrLink, String value){
- DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
- if(!Objects.isNull(value) && !value.isEmpty()) {
- LocalDateTime v = LocalDate.parse(value).atStartOfDay();
- LocalDateTime min = null, max = null;
- if (!Objects.isNull(ptlAgreementUndwrtRulesAttrLink.getMin())) {
- min = LocalDate.parse(ptlAgreementUndwrtRulesAttrLink.getMin()).atStartOfDay();
- }
- if (!Objects.isNull(ptlAgreementUndwrtRulesAttrLink.getMax())) {
- max = LocalDate.parse(ptlAgreementUndwrtRulesAttrLink.getMax()).atStartOfDay();
- }
- //统一处理数值
- if ("1".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
- if (!v.isAfter(min) && v.isBefore(max)) {
- return true;
- }
- } else if ("2".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
- if (!v.isBefore(min)) {
- return true;
- }
- } else if ("3".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
- if (!v.isBefore(min)) {
- return true;
- }
- } else if ("4".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
- if (!v.isAfter(max)) {
- return true;
- }
- } else if ("5".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
- if (!v.isAfter(max)) {
- return true;
- }
- }
- }
- return false;
- }
- /**
- * 获取车辆新旧车信息
- *
- * @param companyId
- * @return
- */
- private PtlNewCarJudgeRules getCarJudgeRule(String companyId, String vehicleType) {
- //获取车辆新旧车信息
- List<PtlNewCarJudgeRules> list =
- ptlNewCarJudgeRulesService.list(new LambdaQueryWrapper<PtlNewCarJudgeRules>()
- .eq(PtlNewCarJudgeRules::getCompanyId,companyId)
- .eq(PtlNewCarJudgeRules::getVehicleType,vehicleType));
- if (list.size() > 0) {
- return list.get(0);
- }
- return null;
- }
- }
|