FeeRuleSchemeServiceNewImpl.java 200 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550
  1. package com.ydtech.modules.fee.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.ydtech.constants.enums.dict.agreement.ProductsType;
  4. import com.ydtech.constants.enums.dict.insurance.EnergyType;
  5. import com.ydtech.constants.enums.dict.insurance.NatureOfVehicleUse;
  6. import com.ydtech.constants.enums.dict.insurance.VehicleType;
  7. import com.ydtech.exception.SystemException;
  8. import com.ydtech.modules.admin.model.SysUser;
  9. import com.ydtech.modules.admin.service.SysChannelGroupService;
  10. import com.ydtech.modules.admin.service.SysSwitchConfigService;
  11. import com.ydtech.modules.admin.service.SysUserAccountService;
  12. import com.ydtech.modules.admin.service.SysUserService;
  13. import com.ydtech.modules.esm.model.EsmRetail;
  14. import com.ydtech.modules.esm.model.EsmUserReferrer;
  15. import com.ydtech.modules.esm.service.EsmRetailService;
  16. import com.ydtech.modules.esm.service.EsmUserReferrerService;
  17. import com.ydtech.modules.fee.constants.CostAllocation;
  18. import com.ydtech.modules.fee.dto.po.InsFeeOrderConfig;
  19. import com.ydtech.modules.fee.dto.vo.ReCalcuLateProportion;
  20. import com.ydtech.modules.fee.dto.vo.RetailProportion;
  21. import com.ydtech.modules.fee.dto.vo.RuleAttrMappingVo;
  22. import com.ydtech.modules.fee.service.FeeRuleSchemeNewService;
  23. import com.ydtech.modules.fee.service.FeeRuleSchemeService;
  24. import com.ydtech.modules.fee.service.InsFeeOrderConfigService;
  25. import com.ydtech.modules.fee.service.InsFeeOrderNewHistoryService;
  26. import com.ydtech.modules.ins.model.vo.QuoteRespVo;
  27. import com.ydtech.modules.order.entity.InsAreaCompany;
  28. import com.ydtech.modules.order.entity.InsOrders;
  29. import com.ydtech.modules.order.entity.api.dajia.constants.TypeVehicleMapping;
  30. import com.ydtech.modules.order.entity.vo.ExternalOrderFeeVo;
  31. import com.ydtech.modules.order.entity.vo.FeeOrderNewVo;
  32. import com.ydtech.modules.order.entity.vo.QueryOrderFeeResultVo;
  33. import com.ydtech.modules.order.entity.vo.QueryOrderFeeVo;
  34. import com.ydtech.modules.order.service.InsOrdersService;
  35. import com.ydtech.modules.protocol.entity.po.PtlAgreement;
  36. import com.ydtech.modules.protocol.entity.po.PtlNewCarJudgeRules;
  37. import com.ydtech.modules.protocol.service.PtlAgreementService;
  38. import com.ydtech.modules.protocol.service.PtlNewCarJudgeRulesService;
  39. import com.ydtech.modules.protocols.entity.po.*;
  40. import com.ydtech.modules.protocols.entity.vo.AgreementProductCosts;
  41. import com.ydtech.modules.protocols.service.*;
  42. import com.ydtech.utils.idgen.IdGenerate;
  43. import org.slf4j.Logger;
  44. import org.slf4j.LoggerFactory;
  45. import org.springframework.beans.factory.annotation.Autowired;
  46. import org.springframework.stereotype.Service;
  47. import javax.annotation.Resource;
  48. import java.math.BigDecimal;
  49. import java.math.BigInteger;
  50. import java.math.RoundingMode;
  51. import java.text.DateFormat;
  52. import java.time.LocalDate;
  53. import java.time.LocalDateTime;
  54. import java.time.format.DateTimeFormatter;
  55. import java.util.*;
  56. import java.util.concurrent.atomic.AtomicBoolean;
  57. import java.util.stream.Collectors;
  58. /**
  59. * @author: tz
  60. * @description: 费用接口中相关功能的实现类
  61. * @create: 2024-3-1 11:45:33
  62. */
  63. @Service
  64. public class FeeRuleSchemeServiceNewImpl implements FeeRuleSchemeNewService {
  65. private static final Logger log = LoggerFactory.getLogger("fee");
  66. @Resource
  67. private InsOrdersService insOrdersService;
  68. @Resource
  69. private PtlAgreementProductCostsNewService ptlAgreementProductCostsNewService;
  70. @Resource
  71. private PtlAgreementUndwrtRulesAttrService ptlAgreementUndwrtRulesAttrService;
  72. @Resource
  73. private PtlAgreementProductCostsExportService ptlAgreementProductCostsExportService;
  74. @Resource
  75. private PtlAgreementProductCostsAttrLinkService ptlAgreementProductCostsAttrLinkService;
  76. @Resource
  77. private PtlAgreementUndwrtRulesNewService ptlAgreementUndwrtRulesNewService;
  78. @Resource
  79. private SysUserService sysUserService;
  80. @Resource
  81. private EsmRetailService esmRetailService;
  82. @Resource
  83. private InsFeeOrderNewService insFeeOrderNewService;
  84. @Autowired
  85. private EsmUserReferrerService esmUserReferrerService;
  86. @Autowired
  87. private SysUserAccountService sysUserAccountService;
  88. @Autowired
  89. private PtlNewCarJudgeRulesService ptlNewCarJudgeRulesService;
  90. @Autowired
  91. private PtlAgreementService ptlAgreementService;
  92. @Autowired
  93. private FeeRuleSchemeService feeRuleSchemeService;
  94. @Autowired
  95. private InsFeeOrderConfigService insFeeOrderConfigService;
  96. @Autowired
  97. private SysSwitchConfigService sysSwitchConfigService;
  98. @Autowired
  99. private InsFeeOrderNewHistoryService insFeeOrderNewHistoryService;
  100. @Autowired
  101. private SysChannelGroupService sysChannelGroupService;
  102. @Override
  103. public QueryOrderFeeVo queryFeeOrderInfo(String companyId) {
  104. return null;
  105. }
  106. @Override
  107. public List<QueryOrderFeeResultVo> convertOrderFeeVoData(QueryOrderFeeVo orderFeeVo) {
  108. return null;
  109. }
  110. @Override
  111. public void compareAndUpdateFeeOrderInfo(String insOrderNo, String jqCostsProportionStr, String syCostsProportionStr, String dealUser) {
  112. }
  113. /**
  114. * 校验费用因子
  115. */
  116. @Override
  117. public void verificationCostFactor(QuoteRespVo quoteRespVo, InsAreaCompany insAreaCompany, InsOrders insOrders, StringBuilder logs, boolean isInternalAgreement) {
  118. List<AgreementProductCosts> agreementProductCostsNoMatched =
  119. ptlAgreementProductCostsNewService.costsGetList(insAreaCompany.getAgreementId(), insAreaCompany.getProductid());
  120. List<AgreementProductCosts> agreementProductCosts = new ArrayList<>();
  121. //过滤费用因子 根据使用性质,能源种类,车辆种类过滤
  122. agreementProductCostsNoMatched.forEach(item->{
  123. AtomicBoolean matching = new AtomicBoolean(true);
  124. item.getCostsAttrLinks().forEach(attr->{
  125. //判断能源类型 燃油 新能源
  126. if(attr.getAttrCode().equals("NewEnergy")){
  127. //传入的能源类型
  128. String energyType = EnergyType.isNewEnergy(insOrders.getCarinfo().getString("energyType")) ? "1" : "0";
  129. if(!attr.getMin().equals(energyType)) {
  130. matching.set(false);
  131. }
  132. }
  133. //使用性质 营业 非营业
  134. if(attr.getAttrCode().equals("NatureOfUse")){
  135. String[] split = attr.getMin().split(",");
  136. boolean isPipei = false;
  137. for(int i=0;i<split.length;i++){
  138. if(split[i].equals(TypeVehicleMapping.getByCode(insOrders.getCarinfo().getString("vehicleUse")))){
  139. isPipei = true;
  140. }
  141. }
  142. if(!isPipei){
  143. matching.set(false);
  144. }
  145. }
  146. //车辆种类 客车 货车
  147. if(attr.getAttrCode().equals("CarType")){
  148. if(!attr.getMin().contains(VehicleType.getByCode(insOrders.getCarinfo().getString("cimodelclass")))){
  149. matching.set(false);
  150. }
  151. }
  152. });
  153. if(matching.get()){
  154. agreementProductCosts.add(item);
  155. }
  156. });
  157. // if(agreementProductCosts == null || agreementProductCosts.size() == 0){
  158. // throw new SystemException("协议费用因子为空");
  159. // }
  160. for (int i = 0; i < agreementProductCosts.size(); i++) {
  161. if (agreementProductCosts.get(i).getPriorityLevel() == null) {
  162. agreementProductCosts.get(i).setPriorityLevel(10);
  163. }
  164. }
  165. if (!agreementProductCosts.isEmpty()) {
  166. //按优先级进行排序
  167. Collections.sort(agreementProductCosts, Comparator.comparingInt(AgreementProductCosts::getPriorityLevel));
  168. //遍历费用因子
  169. String costsId = verificationCosts(agreementProductCosts, quoteRespVo, insAreaCompany, insOrders, logs);
  170. if (costsId != null) {
  171. calcCosts(costsId, insAreaCompany, isInternalAgreement);
  172. log.debug("费用因子校验通过,子订单id:" + insAreaCompany.getId() + ",费用id:" + costsId);
  173. }
  174. } else {
  175. logs.append("没有找到该协议的费用信息" + "\n");
  176. }
  177. }
  178. /**
  179. * 校验承保规则
  180. *
  181. * @param insAreaCompany
  182. * @param insOrders
  183. */
  184. @Override
  185. public void verificationRuleFactor(InsAreaCompany insAreaCompany, InsOrders insOrders) {
  186. List<PtlAgreementUndwrtRulesNew> ptlAgreementUndwrtRules =
  187. ptlAgreementUndwrtRulesNewService.rulesList(insAreaCompany.getAgreementId());
  188. verificationRules(ptlAgreementUndwrtRules, insAreaCompany, insOrders);
  189. }
  190. //BigDecimal取两位
  191. private BigDecimal twoPeople(BigDecimal number) {
  192. return number.setScale(2, BigDecimal.ROUND_DOWN);
  193. }
  194. /**
  195. * 重新计算分销和机构比例
  196. *
  197. * @param sumCostsProportion 总入口费用比例
  198. * @param deptProportion 机构管理总比例
  199. * @param retailProportion 默认分销总比例
  200. * @param retailLevel 分销级别
  201. * @return 如果不够减则 返回新的分销比例
  202. */
  203. public ReCalcuLateProportion recalculateProportion(BigDecimal sumCostsProportion,
  204. BigDecimal deptProportion,
  205. BigDecimal retailProportion,
  206. BigDecimal taxRadio,
  207. Integer retailLevel,
  208. PtlAgreementProductCostsExport ptlAgreementProductCostsExport,
  209. RetailProportion originalRetailProportion,
  210. String type,
  211. BigDecimal enterProportion) {
  212. ReCalcuLateProportion reCalcuLateProportion = new ReCalcuLateProportion();
  213. BigDecimal costsProportion = sumCostsProportion.divide(taxRadio, 2, BigDecimal.ROUND_DOWN);
  214. List<InsFeeOrderConfig> list = insFeeOrderConfigService.list();
  215. //总比例 / 比例 / 分销等级
  216. // 不够减扣除比例
  217. Map<String, BigDecimal> notEnoughReduce = list.stream().collect(Collectors.toMap(InsFeeOrderConfig::getKeyword, InsFeeOrderConfig::getVal));
  218. //分销配置的比例
  219. BigDecimal retailProportionConfig = notEnoughReduce.get(CostAllocation.CA_01.getCode());
  220. BigDecimal retailSettingProportion = new BigDecimal(retailProportionConfig.toString());
  221. // 机构配置的比例
  222. BigDecimal deptProportionConfig = notEnoughReduce.get(CostAllocation.CA_02.getCode());
  223. // 代课录单比例
  224. BigDecimal proxyProportionConfig = notEnoughReduce.get(CostAllocation.CA_03.getCode());
  225. BigDecimal deptSettingProportion = new BigDecimal(deptProportionConfig.toString());
  226. //机构比例均分
  227. BigDecimal jqAverageDept = twoPeople(twoPeople(costsProportion.multiply(deptSettingProportion)).divide(new BigDecimal(5)));
  228. //如果不够减的话
  229. if (deptProportion.add(retailProportion).add(enterProportion).compareTo(costsProportion) > 0) {
  230. //分销比例均分
  231. BigDecimal jqAverageRetail = new BigDecimal(0);
  232. if (retailLevel != 0) {
  233. jqAverageRetail = twoPeople(twoPeople(costsProportion.multiply(retailSettingProportion)).divide(new BigDecimal(retailLevel), 2, RoundingMode.DOWN));
  234. }
  235. if (enterProportion.compareTo(BigDecimal.ZERO) == 0) {
  236. reCalcuLateProportion.setProxyProportion(BigDecimal.ZERO);
  237. } else {
  238. // 代客比例
  239. BigDecimal proxyProportion = costsProportion.multiply(proxyProportionConfig);
  240. reCalcuLateProportion.setProxyProportion(twoPeople(proxyProportion));
  241. }
  242. if (retailLevel >= 3) {
  243. reCalcuLateProportion.setRetail_level_3_proportion(jqAverageRetail);
  244. }
  245. if (retailLevel >= 2) {
  246. reCalcuLateProportion.setRetail_level_2_proportion(jqAverageRetail);
  247. }
  248. if (retailLevel >= 1) {
  249. reCalcuLateProportion.setRetail_level_1_proportion(jqAverageRetail);
  250. }
  251. reCalcuLateProportion.setDept_level_1_proportion(jqAverageDept);
  252. reCalcuLateProportion.setDept_level_2_proportion(jqAverageDept);
  253. reCalcuLateProportion.setDept_level_3_proportion(jqAverageDept);
  254. reCalcuLateProportion.setDept_level_4_proportion(jqAverageDept);
  255. reCalcuLateProportion.setDept_level_5_proportion(jqAverageDept);
  256. } else {
  257. if (type.equals("jq")) {
  258. reCalcuLateProportion.setDept_level_1_proportion(ptlAgreementProductCostsExport.getJqExportRadioLevel1());
  259. reCalcuLateProportion.setDept_level_2_proportion(ptlAgreementProductCostsExport.getJqExportRadioLevel2());
  260. reCalcuLateProportion.setDept_level_3_proportion(ptlAgreementProductCostsExport.getJqExportRadioLevel3());
  261. reCalcuLateProportion.setDept_level_4_proportion(ptlAgreementProductCostsExport.getJqExportRadioLevel4());
  262. reCalcuLateProportion.setDept_level_5_proportion(ptlAgreementProductCostsExport.getJqExportRadioLevel5());
  263. reCalcuLateProportion.setRetail_level_1_proportion(originalRetailProportion.getJqRetailLevel1Proportion());
  264. reCalcuLateProportion.setRetail_level_2_proportion(originalRetailProportion.getJqRetailLevel2Proportion());
  265. reCalcuLateProportion.setRetail_level_3_proportion(originalRetailProportion.getJqRetailLevel3Proportion());
  266. } else if (type.equals("sy")) {
  267. reCalcuLateProportion.setDept_level_1_proportion(ptlAgreementProductCostsExport.getSyExportRadioLevel1());
  268. reCalcuLateProportion.setDept_level_2_proportion(ptlAgreementProductCostsExport.getSyExportRadioLevel2());
  269. reCalcuLateProportion.setDept_level_3_proportion(ptlAgreementProductCostsExport.getSyExportRadioLevel3());
  270. reCalcuLateProportion.setDept_level_4_proportion(ptlAgreementProductCostsExport.getSyExportRadioLevel4());
  271. reCalcuLateProportion.setDept_level_5_proportion(ptlAgreementProductCostsExport.getSyExportRadioLevel5());
  272. reCalcuLateProportion.setRetail_level_1_proportion(originalRetailProportion.getSyRetailLevel1Proportion());
  273. reCalcuLateProportion.setRetail_level_2_proportion(originalRetailProportion.getSyRetailLevel2Proportion());
  274. reCalcuLateProportion.setRetail_level_3_proportion(originalRetailProportion.getSyRetailLevel3Proportion());
  275. } else if (type.equals("no")) {
  276. reCalcuLateProportion.setDept_level_1_proportion(ptlAgreementProductCostsExport.getNoCarExportRadioLevel1());
  277. reCalcuLateProportion.setDept_level_2_proportion(ptlAgreementProductCostsExport.getNoCarExportRadioLevel2());
  278. reCalcuLateProportion.setDept_level_3_proportion(ptlAgreementProductCostsExport.getNoCarExportRadioLevel3());
  279. reCalcuLateProportion.setDept_level_4_proportion(ptlAgreementProductCostsExport.getNoCarExportRadioLevel4());
  280. reCalcuLateProportion.setDept_level_5_proportion(ptlAgreementProductCostsExport.getNoCarExportRadioLevel5());
  281. reCalcuLateProportion.setRetail_level_1_proportion(originalRetailProportion.getNoRetailLevel1Proportion());
  282. reCalcuLateProportion.setRetail_level_2_proportion(originalRetailProportion.getNoRetailLevel2Proportion());
  283. reCalcuLateProportion.setRetail_level_3_proportion(originalRetailProportion.getNoRetailLevel3Proportion());
  284. }
  285. // 代课比例
  286. reCalcuLateProportion.setProxyProportion(enterProportion);
  287. }
  288. return reCalcuLateProportion;
  289. }
  290. /**
  291. * 计算费用
  292. *
  293. * @param costsId
  294. * @param insAreaCompany
  295. */
  296. @Override
  297. public void calcCosts(String costsId, InsAreaCompany insAreaCompany, boolean isInternalAgreement) {
  298. //获取协议信息
  299. PtlAgreement ptlAgreement = ptlAgreementService.getById(insAreaCompany.getAgreementId());
  300. InsOrders insOrders = insOrdersService.getById(insAreaCompany.getOrderno());
  301. SysUser sysUser = sysUserService.findByUserId(insOrders.getUserid());
  302. BigDecimal taxRadio = new BigDecimal("1.00");
  303. //如果是外部订单则 不含税
  304. if (ptlAgreement.getWithTax().equals("否") && ptlAgreement.getIsExternal() == 0) {
  305. taxRadio = new BigDecimal("1.06");
  306. }
  307. //税比例 固定1.06
  308. //查找入口与出口费用比例
  309. //入口配置
  310. PtlAgreementProductCostsNew ptlAgreementProductCostsNew = ptlAgreementProductCostsNewService.getById(costsId);
  311. ptlAgreementProductCostsNew.blank();
  312. //出口配置
  313. PtlAgreementProductCostsExport ptlAgreementProductCostsExport =
  314. ptlAgreementProductCostsExportService.getOne(new LambdaQueryWrapper<PtlAgreementProductCostsExport>().eq(PtlAgreementProductCostsExport::getCostsId, costsId));
  315. InsFeeOrderNew insFeeOrderNew = new InsFeeOrderNew();
  316. insFeeOrderNew.setId(IdGenerate.nextId());
  317. insFeeOrderNew.setCostsId(costsId);
  318. insFeeOrderNew.setAgreementId(insAreaCompany.getAgreementId());
  319. //存储部门id与用户id
  320. InsOrders order = insOrdersService.getById(insAreaCompany.getOrderno());
  321. InsFeeOrderNew insFeeOrderNewByCompanyId = insFeeOrderNewService.getInsFeeOrderNewByCompanyId(insAreaCompany.getId());
  322. if (insFeeOrderNewByCompanyId != null) {
  323. insFeeOrderNew.setId(insFeeOrderNewByCompanyId.getId());
  324. }
  325. insFeeOrderNew.setDeptId(order.getDeptid());
  326. insFeeOrderNew.setUserId(order.getUserid());
  327. insFeeOrderNew.setInsOrderNo(insAreaCompany.getId());
  328. insFeeOrderNew.setJqPremium(insAreaCompany.getJqpremium());
  329. insFeeOrderNew.setSyPremium(insAreaCompany.getSypremium());
  330. insFeeOrderNew.setNoPremium(insAreaCompany.getJypremium());
  331. //不含税
  332. BigDecimal bigDecimal = new BigDecimal("1.06");
  333. insFeeOrderNew.setJqNoTaxPremium(insAreaCompany.getJqpremium().divide(bigDecimal, 2));
  334. insFeeOrderNew.setSyNoTaxPremium(insAreaCompany.getSypremium().divide(bigDecimal, 2));
  335. insFeeOrderNew.setNoNoTaxPremium(insAreaCompany.getJypremium().divide(bigDecimal, 2));
  336. //region 计算入口费用
  337. //交强入口信息
  338. FeeOrderNewVo.EntranceFee jqEntranceFee = feeRuleSchemeService.calcEntranceFee(
  339. insFeeOrderNew.getJqPremium(),
  340. new BigDecimal(ptlAgreementProductCostsNew.getJqCarCostsProportion()),
  341. new BigDecimal(ptlAgreementProductCostsNew.getJqCarOtherCostsProportion()),
  342. taxRadio);
  343. insFeeOrderNew.setJqCostsProportion(jqEntranceFee.getTotalProportion());
  344. insFeeOrderNew.setJqSuperviseCostsProportion(jqEntranceFee.getSuperviseCosts());
  345. insFeeOrderNew.setJqSuperviseCostsPremiums(jqEntranceFee.getSuperviseCostsPremiums());
  346. insFeeOrderNew.setJqOtherCostsProportion(jqEntranceFee.getOtherCostsProportion());
  347. insFeeOrderNew.setJqOtherCostsPremiums(jqEntranceFee.getOtherCostsPremiums());
  348. insFeeOrderNew.setJqCostsPremiums(insFeeOrderNew.getJqSuperviseCostsPremiums().add(insFeeOrderNew.getJqOtherCostsPremiums()));
  349. //商业入口信息
  350. FeeOrderNewVo.EntranceFee syEntranceFee = feeRuleSchemeService.calcEntranceFee(insFeeOrderNew.getSyPremium(),
  351. new BigDecimal(ptlAgreementProductCostsNew.getSyCarCostsProportion()) ,
  352. new BigDecimal(ptlAgreementProductCostsNew.getSyCarOtherCostsProportion()), taxRadio);
  353. insFeeOrderNew.setSyCostsProportion(syEntranceFee.getTotalProportion());
  354. insFeeOrderNew.setSySuperviseCostsProportion(syEntranceFee.getSuperviseCosts());
  355. insFeeOrderNew.setSySuperviseCostsPremiums(syEntranceFee.getSuperviseCostsPremiums());
  356. insFeeOrderNew.setSyOtherCostsProportion(syEntranceFee.getOtherCostsProportion());
  357. insFeeOrderNew.setSyOtherCostsPremiums(syEntranceFee.getOtherCostsPremiums());
  358. insFeeOrderNew.setSyCostsPremiums(insFeeOrderNew.getSySuperviseCostsPremiums().add(insFeeOrderNew.getSyOtherCostsPremiums()));
  359. //非车入口信息
  360. FeeOrderNewVo.EntranceFee noEntranceFee = feeRuleSchemeService.calcEntranceFee(insFeeOrderNew.getNoPremium(),
  361. new BigDecimal(ptlAgreementProductCostsNew.getNoCarCostsProportion()),
  362. new BigDecimal(ptlAgreementProductCostsNew.getNoCarOtherCostsProportion()), taxRadio);
  363. insFeeOrderNew.setNoCostsProportion(noEntranceFee.getTotalProportion());
  364. insFeeOrderNew.setNoSuperviseCostsProportion(noEntranceFee.getSuperviseCosts());
  365. insFeeOrderNew.setNoSuperviseCostsPremiums(noEntranceFee.getSuperviseCostsPremiums());
  366. insFeeOrderNew.setNoOtherCostsProportion(noEntranceFee.getOtherCostsProportion());
  367. insFeeOrderNew.setNoOtherCostsPremiums(noEntranceFee.getOtherCostsPremiums());
  368. insFeeOrderNew.setNoCostsPremiums(insFeeOrderNew.getNoSuperviseCostsPremiums().add(insFeeOrderNew.getNoOtherCostsPremiums()));
  369. //endregion
  370. //region 重新计算管理费比例和分销比例
  371. List<EsmRetail> esmRetailList = esmRetailService.selectList(" where t.deptid=? and t.status = '1' ",
  372. new Object[]{sysUser.getDeptId()});
  373. Integer retailLevel = 0;
  374. //默认分销比例设置
  375. RetailProportion retailProportion = new RetailProportion();
  376. if (!Objects.isNull(esmRetailList) && !esmRetailList.isEmpty()) {
  377. retailLevel = Integer.parseInt(esmRetailList.get(0).getRetailtype());
  378. //赋值默认的分销比例
  379. retailProportion.setProportion(esmRetailList.get(0).getDisrate1(), esmRetailList.get(0).getDisrate2(), esmRetailList.get(0).getDisrate3());
  380. }
  381. //获取交强机构管理费总比例
  382. BigDecimal jqDeptProportion = ptlAgreementProductCostsExport.getJqExportRadioLevel1()
  383. .add(ptlAgreementProductCostsExport.getJqExportRadioLevel2())
  384. .add(ptlAgreementProductCostsExport.getJqExportRadioLevel3())
  385. .add(ptlAgreementProductCostsExport.getJqExportRadioLevel4())
  386. .add(ptlAgreementProductCostsExport.getJqExportRadioLevel5());
  387. //获取商业机构管理费总比例
  388. BigDecimal syDeptProportion = ptlAgreementProductCostsExport.getSyExportRadioLevel1()
  389. .add(ptlAgreementProductCostsExport.getSyExportRadioLevel2())
  390. .add(ptlAgreementProductCostsExport.getSyExportRadioLevel3())
  391. .add(ptlAgreementProductCostsExport.getSyExportRadioLevel4())
  392. .add(ptlAgreementProductCostsExport.getSyExportRadioLevel5());
  393. //获取非车机构管理费总比例
  394. BigDecimal noDeptProportion = ptlAgreementProductCostsExport.getNoCarExportRadioLevel1()
  395. .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel2())
  396. .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel3())
  397. .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel4())
  398. .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel5());
  399. //获取交强分销总比例
  400. BigDecimal jqRetailProportion = retailProportion.getJqRetailLevel1Proportion()
  401. .add(retailProportion.getJqRetailLevel2Proportion())
  402. .add(retailProportion.getJqRetailLevel3Proportion());
  403. //获取商业分销总比例
  404. BigDecimal syRetailProportion = retailProportion.getSyRetailLevel1Proportion()
  405. .add(retailProportion.getSyRetailLevel2Proportion())
  406. .add(retailProportion.getSyRetailLevel3Proportion());
  407. //获取非车分销总比例
  408. BigDecimal noRetailProportion = retailProportion.getNoRetailLevel1Proportion()
  409. .add(retailProportion.getNoRetailLevel2Proportion())
  410. .add(retailProportion.getNoRetailLevel3Proportion());
  411. BigDecimal enterProportion = new BigDecimal(BigInteger.ZERO);
  412. // 待客录单订单比例 根据前端传值 判断是否使用待客录单比例
  413. if(!isInternalAgreement){
  414. enterProportion = sysSwitchConfigService.getEnterProportion(insOrders.getDeptid(), insOrders.getEntryStatus());
  415. }
  416. //重新计算比例 入口是否超出支付的比例
  417. ReCalcuLateProportion jqReCalcuLateProportion = recalculateProportion(
  418. new BigDecimal(ptlAgreementProductCostsNew.getJqCostsProportion()),
  419. jqDeptProportion,
  420. jqRetailProportion,
  421. taxRadio,
  422. retailLevel,
  423. ptlAgreementProductCostsExport,
  424. retailProportion,
  425. "jq",
  426. enterProportion
  427. );
  428. ReCalcuLateProportion syReCalcuLateProportion = recalculateProportion(
  429. new BigDecimal(ptlAgreementProductCostsNew.getSyCostsProportion()),
  430. syDeptProportion,
  431. syRetailProportion,
  432. taxRadio,
  433. retailLevel,
  434. ptlAgreementProductCostsExport,
  435. retailProportion,
  436. "sy",
  437. enterProportion
  438. );
  439. ReCalcuLateProportion noReCalcuLateProportion = recalculateProportion(
  440. new BigDecimal(ptlAgreementProductCostsNew.getNoCostsProportion()),
  441. noDeptProportion,
  442. noRetailProportion,
  443. taxRadio,
  444. retailLevel,
  445. ptlAgreementProductCostsExport,
  446. retailProportion,
  447. "no",
  448. enterProportion
  449. );
  450. retailProportion.setProportion(jqReCalcuLateProportion, syReCalcuLateProportion, noReCalcuLateProportion);
  451. // ptlAgreementProductCostsExportService.updateById(ptlAgreementProductCostsExport);
  452. //endregion
  453. //region 计算分销费用
  454. //获取分销比例
  455. //分销总比例
  456. BigDecimal jqRetailRadio = new BigDecimal("0");
  457. BigDecimal syRetailRadio = new BigDecimal("0");
  458. BigDecimal noRetailRadio = new BigDecimal("0");
  459. FeeOrderNewVo.RetailFee retailFeeLevel3 = new FeeOrderNewVo.RetailFee();
  460. FeeOrderNewVo.RetailFee retailFeeLevel2 = new FeeOrderNewVo.RetailFee();
  461. FeeOrderNewVo.RetailFee retailFeeLevel1 = new FeeOrderNewVo.RetailFee();
  462. if (esmRetailList != null && !esmRetailList.isEmpty()) {
  463. EsmRetail esmRetail = esmRetailList.get(0);
  464. //分销等级
  465. insFeeOrderNew.setDistributionStatus(esmRetailList.get(0).getRetailtype());
  466. //用户分销人员id
  467. List<EsmUserReferrer> parents = esmUserReferrerService.findParents(sysUser.getId());
  468. if (esmRetail != null) {
  469. if (Integer.parseInt(esmRetail.getRetailtype()) >= 3) {
  470. insFeeOrderNew.setThirdDetailProportion(retailProportion.getJqRetailLevel3Proportion());
  471. retailFeeLevel3 = feeRuleSchemeService.calcRetail(insFeeOrderNew.getJqPremium(),
  472. insFeeOrderNew.getJqCostsProportion(),
  473. insFeeOrderNew.getSyPremium(),
  474. insFeeOrderNew.getSyCostsProportion().add(insFeeOrderNew.getSyOtherCostsProportion()),
  475. insFeeOrderNew.getNoPremium(),
  476. insFeeOrderNew.getNoCostsProportion().add(insFeeOrderNew.getNoOtherCostsProportion()),
  477. retailProportion.getJqRetailLevel3Proportion(),
  478. retailProportion.getSyRetailLevel3Proportion(),
  479. retailProportion.getNoRetailLevel3Proportion());
  480. insFeeOrderNew.setThirdDetailPremiums(retailFeeLevel3.getTotalRetailPremiums());
  481. if (parents != null && parents.size() > 2) {
  482. insFeeOrderNew.setThreeLevelUserId(parents.get(2).getId());
  483. }
  484. } else {
  485. insFeeOrderNew.setThirdDetailProportion(new BigDecimal(0));
  486. }
  487. if (Integer.parseInt(esmRetail.getRetailtype()) >= 2) {
  488. insFeeOrderNew.setSecondDetailProportion(retailProportion.getJqRetailLevel2Proportion());
  489. retailFeeLevel2 = feeRuleSchemeService.calcRetail(insFeeOrderNew.getJqPremium(),
  490. insFeeOrderNew.getJqCostsProportion(),
  491. insFeeOrderNew.getSyPremium(),
  492. insFeeOrderNew.getSyCostsProportion(),
  493. insFeeOrderNew.getNoPremium(),
  494. insFeeOrderNew.getNoCostsProportion(),
  495. retailProportion.getJqRetailLevel2Proportion(),
  496. retailProportion.getSyRetailLevel2Proportion(),
  497. retailProportion.getNoRetailLevel2Proportion());
  498. insFeeOrderNew.setSecondDetailPremiums(retailFeeLevel2.getTotalRetailPremiums());
  499. if (parents != null && parents.size() > 1) {
  500. insFeeOrderNew.setTwoLevelUserId(parents.get(1).getId());
  501. }
  502. } else {
  503. insFeeOrderNew.setSecondDetailProportion(new BigDecimal(0));
  504. }
  505. if (Integer.parseInt(esmRetail.getRetailtype()) >= 1) {
  506. insFeeOrderNew.setFirstDetailProportion(retailProportion.getJqRetailLevel1Proportion());
  507. retailFeeLevel1 = feeRuleSchemeService.calcRetail(insFeeOrderNew.getJqPremium(),
  508. insFeeOrderNew.getJqCostsProportion(),
  509. insFeeOrderNew.getSyPremium(),
  510. insFeeOrderNew.getSyCostsProportion(),
  511. insFeeOrderNew.getNoPremium(),
  512. insFeeOrderNew.getNoCostsProportion(),
  513. retailProportion.getJqRetailLevel1Proportion(),
  514. retailProportion.getSyRetailLevel1Proportion(),
  515. retailProportion.getNoRetailLevel1Proportion());
  516. insFeeOrderNew.setFirstDetailPremiums(retailFeeLevel1.getTotalRetailPremiums());
  517. if (parents != null && !parents.isEmpty()) {
  518. insFeeOrderNew.setFirstLevelUserId(parents.get(0).getId());
  519. }
  520. } else {
  521. insFeeOrderNew.setFirstDetailProportion(new BigDecimal(0));
  522. }
  523. } else {
  524. insFeeOrderNew.setFirstDetailPremiums(new BigDecimal(0));
  525. insFeeOrderNew.setSecondDetailPremiums(new BigDecimal(0));
  526. insFeeOrderNew.setThirdDetailPremiums(new BigDecimal(0));
  527. }
  528. } else {
  529. insFeeOrderNew.setFirstDetailProportion(new BigDecimal(0));
  530. insFeeOrderNew.setSecondDetailProportion(new BigDecimal(0));
  531. insFeeOrderNew.setThirdDetailProportion(new BigDecimal(0));
  532. }
  533. jqRetailRadio = jqRetailRadio.add(retailFeeLevel1.getJqRetailProportion())
  534. .add(retailFeeLevel2.getJqRetailProportion())
  535. .add(retailFeeLevel3.getJqRetailProportion());
  536. syRetailRadio = syRetailRadio.add(retailFeeLevel1.getSyRetailProportion())
  537. .add(retailFeeLevel2.getSyRetailProportion())
  538. .add(retailFeeLevel3.getSyRetailProportion());
  539. noRetailRadio = noRetailRadio.add(retailFeeLevel1.getNoRetailProportion())
  540. .add(retailFeeLevel2.getNoRetailProportion())
  541. .add(retailFeeLevel3.getNoRetailProportion());
  542. insFeeOrderNew.assignRetail(retailFeeLevel1, retailFeeLevel2, retailFeeLevel3);
  543. //endregion
  544. //region 设置机构管理费
  545. //交强机构管理费
  546. BigDecimal jqDeptRadio =
  547. jqReCalcuLateProportion.getDept_level_1_proportion()
  548. .add(jqReCalcuLateProportion.getDept_level_2_proportion())
  549. .add(jqReCalcuLateProportion.getDept_level_3_proportion())
  550. .add(jqReCalcuLateProportion.getDept_level_4_proportion())
  551. .add(jqReCalcuLateProportion.getDept_level_5_proportion());
  552. FeeOrderNewVo.DeptManagerFee jqDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(
  553. insFeeOrderNew.getJqPremium(),
  554. jqReCalcuLateProportion.getDept_level_1_proportion(),
  555. jqReCalcuLateProportion.getDept_level_2_proportion(),
  556. jqReCalcuLateProportion.getDept_level_3_proportion(),
  557. jqReCalcuLateProportion.getDept_level_4_proportion(),
  558. jqReCalcuLateProportion.getDept_level_5_proportion());
  559. BigDecimal syDeptRadio =
  560. syReCalcuLateProportion.getDept_level_1_proportion()
  561. .add(syReCalcuLateProportion.getDept_level_2_proportion())
  562. .add(syReCalcuLateProportion.getDept_level_3_proportion())
  563. .add(syReCalcuLateProportion.getDept_level_4_proportion())
  564. .add(syReCalcuLateProportion.getDept_level_5_proportion());
  565. FeeOrderNewVo.DeptManagerFee syDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(
  566. insFeeOrderNew.getSyPremium(),
  567. syReCalcuLateProportion.getDept_level_1_proportion(),
  568. syReCalcuLateProportion.getDept_level_2_proportion(),
  569. syReCalcuLateProportion.getDept_level_3_proportion(),
  570. syReCalcuLateProportion.getDept_level_4_proportion(),
  571. syReCalcuLateProportion.getDept_level_5_proportion());
  572. BigDecimal noDeptRadio =
  573. noReCalcuLateProportion.getDept_level_1_proportion()
  574. .add(noReCalcuLateProportion.getDept_level_2_proportion())
  575. .add(noReCalcuLateProportion.getDept_level_3_proportion())
  576. .add(noReCalcuLateProportion.getDept_level_4_proportion())
  577. .add(noReCalcuLateProportion.getDept_level_5_proportion());
  578. FeeOrderNewVo.DeptManagerFee noDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(
  579. insFeeOrderNew.getNoPremium(),
  580. noReCalcuLateProportion.getDept_level_1_proportion(),
  581. noReCalcuLateProportion.getDept_level_2_proportion(),
  582. noReCalcuLateProportion.getDept_level_3_proportion(),
  583. noReCalcuLateProportion.getDept_level_4_proportion(),
  584. noReCalcuLateProportion.getDept_level_5_proportion());
  585. insFeeOrderNew.assignDept(jqDeptManagerFee, syDeptManagerFee, noDeptManagerFee);
  586. //endregion
  587. //region 出口费用
  588. //交强出口手续费比例
  589. FeeOrderNewVo.ExportFee jqExportFee = feeRuleSchemeService.calcExportFee(
  590. insFeeOrderNew.getJqPremium(),
  591. new BigDecimal(ptlAgreementProductCostsNew.getJqCostsExportProportion()),
  592. insFeeOrderNew.getJqCostsProportion(),
  593. jqDeptRadio,
  594. jqRetailRadio,
  595. taxRadio,
  596. jqReCalcuLateProportion.getProxyProportion()
  597. );
  598. //商业出口手续费比例
  599. FeeOrderNewVo.ExportFee syExportFee = feeRuleSchemeService.calcExportFee(
  600. insFeeOrderNew.getSyPremium(),
  601. new BigDecimal(ptlAgreementProductCostsNew.getSyCostsExportProportion()),
  602. insFeeOrderNew.getSyCostsProportion(),
  603. syDeptRadio,
  604. syRetailRadio,
  605. taxRadio,
  606. syReCalcuLateProportion.getProxyProportion()
  607. );
  608. //非车出口手续费比例
  609. FeeOrderNewVo.ExportFee noExportFee = feeRuleSchemeService.calcExportFee(
  610. insFeeOrderNew.getNoPremium(),
  611. new BigDecimal(ptlAgreementProductCostsNew.getNoCostsExportProportion()),
  612. insFeeOrderNew.getNoCostsProportion(),
  613. noDeptRadio,
  614. noRetailRadio,
  615. taxRadio,
  616. noReCalcuLateProportion.getProxyProportion()
  617. );
  618. //出口手续费用
  619. insFeeOrderNew.setJqExportSuperviseCostsPremiums(twoPeople(jqExportFee.getSuperviseCostsPremiums()));
  620. insFeeOrderNew.setSyExportSuperviseCostsPremiums(twoPeople(syExportFee.getSuperviseCostsPremiums()));
  621. insFeeOrderNew.setNoExportSuperviseCostsPremiums(twoPeople(noExportFee.getSuperviseCostsPremiums()));
  622. //出口其他费用比例
  623. insFeeOrderNew.setJqExportOtherCostsProportion(twoPeople(jqExportFee.getOtherCostsProportion()));
  624. insFeeOrderNew.setSyExportOtherCostsProportion(twoPeople(syExportFee.getOtherCostsProportion()));
  625. insFeeOrderNew.setNoExportOtherCostsProportion(twoPeople(noExportFee.getOtherCostsProportion()));
  626. //出口其他费用
  627. insFeeOrderNew.setJqExportOtherCostsPremiums(twoPeople(jqExportFee.getOtherCostsPremiums()));
  628. insFeeOrderNew.setSyExportOtherCostsPremiums(twoPeople(syExportFee.getOtherCostsPremiums()));
  629. insFeeOrderNew.setNoExportOtherCostsPremiums(twoPeople(noExportFee.getOtherCostsPremiums()));
  630. //设置出口手续费比例
  631. insFeeOrderNew.setJqCostsExportProportion(twoPeople(jqExportFee.getSuperviseCosts()));
  632. insFeeOrderNew.setSyCostsExportProportion(twoPeople(syExportFee.getSuperviseCosts()));
  633. insFeeOrderNew.setNoCostsExportProportion(twoPeople(noExportFee.getSuperviseCosts()));
  634. // 外部费用
  635. insFeeOrderNew.setJqExternalProportion(jqExportFee.getExternalProportion());
  636. insFeeOrderNew.setJqExternalPremiums(jqExportFee.getExternalPremiums());
  637. insFeeOrderNew.setSyExternalProportion(syExportFee.getExternalProportion());
  638. insFeeOrderNew.setSyExternalPremiums(syExportFee.getExternalPremiums());
  639. insFeeOrderNew.setNoExternalProportion(noExportFee.getExternalProportion());
  640. insFeeOrderNew.setNoExternalPremiums(noExportFee.getExternalPremiums());
  641. //endregion
  642. //region 计算利润差值
  643. //入口 - 出口 - 机构管理费 1-5级 - 分销费 = 差值
  644. //分销交强费用
  645. //分开算 1 2 3 级
  646. BigDecimal jqFirst = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getJqRetailProportionLevel1().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  647. BigDecimal jqSecond = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getJqRetailProportionLevel2().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  648. BigDecimal jqThird = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getJqRetailProportionLevel3().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  649. BigDecimal jqFenXiao = jqFirst.add(jqSecond).add(jqThird);
  650. //分销商业费用
  651. BigDecimal syFirst = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getSyRetailProportionLevel1().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  652. BigDecimal sySecond = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getSyRetailProportionLevel2().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  653. BigDecimal syThird = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getSyRetailProportionLevel3().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  654. BigDecimal syFenXiao = syFirst.add(sySecond).add(syThird);
  655. //分销非车费用
  656. BigDecimal noFirst = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getNoRetailProportionLevel1().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  657. BigDecimal noSecond = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getNoRetailProportionLevel2().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  658. BigDecimal noThird = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getNoRetailProportionLevel3().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  659. BigDecimal noFenXiao = noFirst.add(noSecond).add(noThird);
  660. BigDecimal jqDifference = jqEntranceFee.getTotalAmount()
  661. .subtract(jqExportFee.getExternalPremiums())
  662. .subtract(
  663. (jqExportFee.getSuperviseCostsPremiums().add(jqExportFee.getOtherCostsPremiums())))
  664. .subtract(
  665. (jqDeptManagerFee.getDeptPremiumsLevelOne().add(jqDeptManagerFee.getDeptPremiumsLevelTwo().add(jqDeptManagerFee.getDeptPremiumsLevelThree()).add(jqDeptManagerFee.getDeptPremiumsLevelFoure()).add(jqDeptManagerFee.getDeptPremiumsLevelFive())))
  666. )
  667. .subtract(jqFenXiao)
  668. .setScale(5, BigDecimal.ROUND_HALF_DOWN);
  669. insFeeOrderNew.setJqProfitMarginPremiums(jqDifference);
  670. BigDecimal syDifference = syEntranceFee.getTotalAmount()
  671. .subtract(syExportFee.getExternalPremiums())
  672. .subtract(
  673. (syExportFee.getSuperviseCostsPremiums().add(syExportFee.getOtherCostsPremiums())))
  674. .subtract(
  675. (syDeptManagerFee.getDeptPremiumsLevelOne().add(syDeptManagerFee.getDeptPremiumsLevelTwo().add(syDeptManagerFee.getDeptPremiumsLevelThree()).add(syDeptManagerFee.getDeptPremiumsLevelFoure()).add(syDeptManagerFee.getDeptPremiumsLevelFive())))
  676. )
  677. .subtract(syFenXiao)
  678. .setScale(5, BigDecimal.ROUND_HALF_DOWN);
  679. insFeeOrderNew.setSyProfitMarginPremiums(syDifference);
  680. BigDecimal noDifference = noEntranceFee.getTotalAmount()
  681. .subtract(noExportFee.getExternalPremiums())
  682. .subtract(
  683. (noExportFee.getSuperviseCostsPremiums().add(noExportFee.getOtherCostsPremiums())))
  684. .subtract(
  685. (noDeptManagerFee.getDeptPremiumsLevelOne().add(noDeptManagerFee.getDeptPremiumsLevelTwo().add(noDeptManagerFee.getDeptPremiumsLevelThree()).add(noDeptManagerFee.getDeptPremiumsLevelFoure()).add(noDeptManagerFee.getDeptPremiumsLevelFive())))
  686. )
  687. .subtract(noFenXiao)
  688. .setScale(5, BigDecimal.ROUND_HALF_DOWN);
  689. insFeeOrderNew.setNoProfitMarginPremiums(noDifference);
  690. //endregion
  691. //region 比例逆推是否等于0
  692. if (!feeRuleSchemeService.calculateProportion(jqEntranceFee, jqDeptManagerFee, jqExportFee, jqRetailRadio, taxRadio, insFeeOrderNew.getJqPremium()))
  693. throw new SystemException("交强比例异常");
  694. if (!feeRuleSchemeService.calculateProportion(syEntranceFee, syDeptManagerFee, syExportFee, syRetailRadio, taxRadio, insFeeOrderNew.getSyPremium()))
  695. throw new SystemException("商业比例异常");
  696. if (!feeRuleSchemeService.calculateProportion(noEntranceFee, noDeptManagerFee, noExportFee, noRetailRadio, taxRadio, insFeeOrderNew.getNoPremium()))
  697. throw new SystemException("非车比例异常");
  698. //endregion
  699. sysChannelGroupService.costCompute(insFeeOrderNew,ptlAgreement,ptlAgreementProductCostsNew,sysUser,insAreaCompany,insOrders);
  700. insFeeOrderNewService.saveOrUpdate(insFeeOrderNew);
  701. }
  702. /**
  703. * 计算费用测试方法 没有数据库保存操作 只带入值进行计算核对
  704. *
  705. * @param costsId
  706. * @param insAreaCompany
  707. */
  708. @Override
  709. public void calcCostsTest(String costsId, InsAreaCompany insAreaCompany) {
  710. // //获取协议信息
  711. // PtlAgreement ptlAgreement = ptlAgreementService.getById(insAreaCompany.getAgreementId());
  712. // BigDecimal taxRadio = new BigDecimal("1.00");
  713. // //如果是外部订单则 不含税
  714. // if (ptlAgreement.getWithTax().equals("否") && ptlAgreement.getIsExternal() == 0) {
  715. // taxRadio = new BigDecimal("1.06");
  716. // }
  717. // //税比例 固定1.06
  718. // //查找入口与出口费用比例
  719. // //入口配置
  720. // PtlAgreementProductCostsNew ptlAgreementProductCostsNew = ptlAgreementProductCostsNewService.getById(costsId);
  721. //
  722. // //出口配置
  723. // PtlAgreementProductCostsExport ptlAgreementProductCostsExport =
  724. // ptlAgreementProductCostsExportService.getOne(new LambdaQueryWrapper<PtlAgreementProductCostsExport>().eq(PtlAgreementProductCostsExport::getCostsId, costsId));
  725. // InsFeeOrderNew insFeeOrderNew = new InsFeeOrderNew();
  726. // insFeeOrderNew.setId(IdGenerate.nextId());
  727. // insFeeOrderNew.setCostsId(costsId);
  728. // insFeeOrderNew.setAgreementId(insAreaCompany.getAgreementId());
  729. //
  730. // //存储部门id与用户id
  731. // InsOrders order = insOrdersService.getById(insAreaCompany.getOrderno());
  732. // InsFeeOrderNew insFeeOrderNewByCompanyId = insFeeOrderNewService.getInsFeeOrderNewByCompanyId(insAreaCompany.getId());
  733. // if (insFeeOrderNewByCompanyId != null) {
  734. // insFeeOrderNew.setId(insFeeOrderNewByCompanyId.getId());
  735. // }
  736. // insFeeOrderNew.setDeptId(order.getDeptid());
  737. // insFeeOrderNew.setUserId(order.getUserid());
  738. // insFeeOrderNew.setInsOrderNo(insAreaCompany.getId());
  739. // insFeeOrderNew.setJqPremium(insAreaCompany.getJqpremium());
  740. // insFeeOrderNew.setSyPremium(insAreaCompany.getSypremium());
  741. // insFeeOrderNew.setNoPremium(insAreaCompany.getJypremium());
  742. // //不含税
  743. // BigDecimal bigDecimal = new BigDecimal("1.06");
  744. // insFeeOrderNew.setJqNoTaxPremium(insAreaCompany.getJqpremium().divide(bigDecimal, 2));
  745. // insFeeOrderNew.setSyNoTaxPremium(insAreaCompany.getSypremium().divide(bigDecimal, 2));
  746. // insFeeOrderNew.setNoNoTaxPremium(insAreaCompany.getJypremium().divide(bigDecimal, 2));
  747. //
  748. // //region 计算入口费用
  749. //
  750. // //交强入口信息
  751. // FeeOrderNewVo.EntranceFee jqEntranceFee = feeRuleSchemeService.calcEntranceFee(insFeeOrderNew.getJqPremium(),
  752. // new BigDecimal(ptlAgreementProductCostsNew.getJqCarCostsProportion()),
  753. // new BigDecimal(ptlAgreementProductCostsNew.getJqCarOtherCostsProportion()), taxRadio);
  754. // insFeeOrderNew.setJqCostsProportion(jqEntranceFee.getTotalProportion());
  755. // insFeeOrderNew.setJqSuperviseCostsProportion(jqEntranceFee.getSuperviseCosts());
  756. // insFeeOrderNew.setJqSuperviseCostsPremiums(jqEntranceFee.getSuperviseCostsPremiums());
  757. // insFeeOrderNew.setJqOtherCostsProportion(jqEntranceFee.getOtherCostsProportion());
  758. // insFeeOrderNew.setJqOtherCostsPremiums(jqEntranceFee.getOtherCostsPremiums());
  759. // insFeeOrderNew.setJqCostsPremiums(insFeeOrderNew.getJqSuperviseCostsPremiums().add(insFeeOrderNew.getJqOtherCostsPremiums()));
  760. //
  761. // //商业入口信息
  762. // FeeOrderNewVo.EntranceFee syEntranceFee = feeRuleSchemeService.calcEntranceFee(insFeeOrderNew.getSyPremium(),
  763. // new BigDecimal(ptlAgreementProductCostsNew.getSyCarCostsProportion()),
  764. // new BigDecimal(ptlAgreementProductCostsNew.getSyCarOtherCostsProportion()), taxRadio);
  765. // insFeeOrderNew.setSyCostsProportion(syEntranceFee.getTotalProportion());
  766. // insFeeOrderNew.setSySuperviseCostsProportion(syEntranceFee.getSuperviseCosts());
  767. // insFeeOrderNew.setSySuperviseCostsPremiums(syEntranceFee.getSuperviseCostsPremiums());
  768. // insFeeOrderNew.setSyOtherCostsProportion(syEntranceFee.getOtherCostsProportion());
  769. // insFeeOrderNew.setSyOtherCostsPremiums(syEntranceFee.getOtherCostsPremiums());
  770. // insFeeOrderNew.setSyCostsPremiums(insFeeOrderNew.getSySuperviseCostsPremiums().add(insFeeOrderNew.getSyOtherCostsPremiums()));
  771. //
  772. // //非车入口信息
  773. // FeeOrderNewVo.EntranceFee noEntranceFee = feeRuleSchemeService.calcEntranceFee(insFeeOrderNew.getNoPremium(),
  774. // new BigDecimal(ptlAgreementProductCostsNew.getNoCarCostsProportion()),
  775. // new BigDecimal(ptlAgreementProductCostsNew.getNoCarOtherCostsProportion()), taxRadio);
  776. // insFeeOrderNew.setNoCostsProportion(noEntranceFee.getTotalProportion());
  777. // insFeeOrderNew.setNoSuperviseCostsProportion(noEntranceFee.getSuperviseCosts());
  778. // insFeeOrderNew.setNoSuperviseCostsPremiums(noEntranceFee.getSuperviseCostsPremiums());
  779. // insFeeOrderNew.setNoOtherCostsProportion(noEntranceFee.getOtherCostsProportion());
  780. // insFeeOrderNew.setNoOtherCostsPremiums(noEntranceFee.getOtherCostsPremiums());
  781. // insFeeOrderNew.setNoCostsPremiums(insFeeOrderNew.getNoSuperviseCostsPremiums().add(insFeeOrderNew.getNoOtherCostsPremiums()));
  782. // //endregion
  783. //
  784. // //region 计算分销费用
  785. // InsOrders insOrders = insOrdersService.getById(insAreaCompany.getOrderno());
  786. // SysUser sysUser = sysUserService.findByUserId(insOrders.getUserid());
  787. //
  788. // //获取分销比例
  789. // List<EsmRetail> esmRetailList = esmRetailService.selectList(" where t.deptid=? and t.status = '1' ",
  790. // new Object[]{sysUser.getDeptId()});
  791. //
  792. // //分销总比例
  793. // BigDecimal retailRadio = new BigDecimal("0");
  794. // if (esmRetailList != null && !esmRetailList.isEmpty()) {
  795. // EsmRetail esmRetail = esmRetailList.get(0);
  796. // //分销等级
  797. // insFeeOrderNew.setDistributionStatus(esmRetailList.get(0).getRetailtype());
  798. // //用户分销人员id
  799. // List<EsmUserReferrer> parents = esmUserReferrerService.findParents(sysUser.getId());
  800. //
  801. // if (esmRetail != null) {
  802. // BigDecimal sumPremium = insFeeOrderNew.getJqPremium().add(insFeeOrderNew.getSyPremium()).add(insFeeOrderNew.getNoPremium());
  803. // if (Integer.parseInt(esmRetail.getRetailtype()) >= 3) {
  804. // insFeeOrderNew.setThirdDetailProportion(new BigDecimal(String.valueOf(esmRetail.getDisrate3())));
  805. // retailRadio = retailRadio.add(insFeeOrderNew.getThirdDetailProportion()).setScale(2, BigDecimal.ROUND_DOWN);
  806. // BigDecimal thirdDetailPremiums = feeRuleSchemeService.calcRetail(insFeeOrderNew.getJqPremium(),
  807. // insFeeOrderNew.getJqCostsProportion().add(insFeeOrderNew.getJqOtherCostsProportion()),
  808. // insFeeOrderNew.getSyPremium(),
  809. // insFeeOrderNew.getSyCostsProportion().add(insFeeOrderNew.getSyOtherCostsProportion()),
  810. // insFeeOrderNew.getNoPremium(),
  811. // insFeeOrderNew.getNoCostsProportion().add(insFeeOrderNew.getNoOtherCostsProportion()),
  812. // insFeeOrderNew.getThirdDetailProportion());
  813. // insFeeOrderNew.setThirdDetailPremiums(thirdDetailPremiums);
  814. // if (parents != null && parents.size() > 2) {
  815. // insFeeOrderNew.setThreeLevelUserId(parents.get(2).getId());
  816. // }
  817. // }else{
  818. // insFeeOrderNew.setThirdDetailProportion(new BigDecimal(0));
  819. // }
  820. // if (Integer.parseInt(esmRetail.getRetailtype()) >= 2) {
  821. // insFeeOrderNew.setSecondDetailProportion(new BigDecimal(String.valueOf(esmRetail.getDisrate2())));
  822. // retailRadio = retailRadio.add(insFeeOrderNew.getSecondDetailProportion()).setScale(2, BigDecimal.ROUND_DOWN);
  823. // BigDecimal secondDetailPremiums = feeRuleSchemeService.calcRetail(insFeeOrderNew.getJqPremium(),
  824. // insFeeOrderNew.getJqCostsProportion().add(insFeeOrderNew.getJqOtherCostsProportion()),
  825. // insFeeOrderNew.getSyPremium(),
  826. // insFeeOrderNew.getSyCostsProportion().add(insFeeOrderNew.getSyOtherCostsProportion()),
  827. // insFeeOrderNew.getNoPremium(),
  828. // insFeeOrderNew.getNoCostsProportion().add(insFeeOrderNew.getNoOtherCostsProportion()),
  829. // insFeeOrderNew.getSecondDetailProportion());
  830. // insFeeOrderNew.setSecondDetailPremiums(secondDetailPremiums);
  831. // if (parents != null && parents.size() > 1) {
  832. // insFeeOrderNew.setTwoLevelUserId(parents.get(1).getId());
  833. // }
  834. // }else{
  835. // insFeeOrderNew.setSecondDetailProportion(new BigDecimal(0));
  836. // }
  837. // if (Integer.parseInt(esmRetail.getRetailtype()) >= 1) {
  838. // insFeeOrderNew.setFirstDetailProportion(new BigDecimal(String.valueOf(esmRetail.getDisrate1())));
  839. // retailRadio = retailRadio.add(insFeeOrderNew.getFirstDetailProportion()).setScale(2, BigDecimal.ROUND_DOWN);
  840. // BigDecimal firstDetailPremiums = feeRuleSchemeService.calcRetail(insFeeOrderNew.getJqPremium(),
  841. // insFeeOrderNew.getJqCostsProportion().add(insFeeOrderNew.getJqOtherCostsProportion()),
  842. // insFeeOrderNew.getSyPremium(),
  843. // insFeeOrderNew.getSyCostsProportion().add(insFeeOrderNew.getSyOtherCostsProportion()),
  844. // insFeeOrderNew.getNoPremium(),
  845. // insFeeOrderNew.getNoCostsProportion().add(insFeeOrderNew.getNoOtherCostsProportion()),
  846. // insFeeOrderNew.getFirstDetailProportion());
  847. // insFeeOrderNew.setFirstDetailPremiums(firstDetailPremiums);
  848. // if (parents != null && parents.size() > 0) {
  849. // insFeeOrderNew.setFirstLevelUserId(parents.get(0).getId());
  850. // }
  851. // }else{
  852. // insFeeOrderNew.setFirstDetailProportion(new BigDecimal(0));
  853. // }
  854. // }else{
  855. // insFeeOrderNew.setFirstDetailPremiums(new BigDecimal(0));
  856. // insFeeOrderNew.setSecondDetailPremiums(new BigDecimal(0));
  857. // insFeeOrderNew.setThirdDetailPremiums(new BigDecimal(0));
  858. // }
  859. // }else{
  860. // insFeeOrderNew.setFirstDetailProportion(new BigDecimal(0));
  861. // insFeeOrderNew.setSecondDetailProportion(new BigDecimal(0));
  862. // insFeeOrderNew.setThirdDetailProportion(new BigDecimal(0));
  863. // }
  864. //
  865. //
  866. // //endregion
  867. //
  868. // //region 设置机构管理费
  869. //
  870. // //交强机构管理费
  871. // BigDecimal jqDeptRadio =
  872. // ptlAgreementProductCostsExport.getJqExportRadioLevel1().add(ptlAgreementProductCostsExport.getJqExportRadioLevel2()).add(ptlAgreementProductCostsExport.getJqExportRadioLevel3()).add(ptlAgreementProductCostsExport.getJqExportRadioLevel4()).add(ptlAgreementProductCostsExport.getJqExportRadioLevel5());
  873. // FeeOrderNewVo.DeptManagerFee jqDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(insFeeOrderNew.getJqPremium(),
  874. // ptlAgreementProductCostsExport.getJqExportRadioLevel1(), ptlAgreementProductCostsExport.getJqExportRadioLevel2(),
  875. // ptlAgreementProductCostsExport.getJqExportRadioLevel3(), ptlAgreementProductCostsExport.getJqExportRadioLevel4(),
  876. // ptlAgreementProductCostsExport.getJqExportRadioLevel5());
  877. // insFeeOrderNew.setJqDeptProportionLevel1(jqDeptManagerFee.getDeptProportionLevelOne());
  878. // insFeeOrderNew.setJqDeptPremiumsLevel1(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelOne()));
  879. // insFeeOrderNew.setJqDeptProportionLevel2(jqDeptManagerFee.getDeptProportionLevelTwo());
  880. // insFeeOrderNew.setJqDeptPremiumsLevel2(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelTwo()));
  881. // insFeeOrderNew.setJqDeptProportionLevel3(jqDeptManagerFee.getDeptProportionLevelThree());
  882. // insFeeOrderNew.setJqDeptPremiumsLevel3(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelThree()));
  883. // insFeeOrderNew.setJqDeptProportionLevel4(jqDeptManagerFee.getDeptProportionLevelFoure());
  884. // insFeeOrderNew.setJqDeptPremiumsLevel4(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelFoure()));
  885. // insFeeOrderNew.setJqDeptProportionLevel5(jqDeptManagerFee.getDeptProportionLevelFive());
  886. // insFeeOrderNew.setJqDeptPremiumsLevel5(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelFive()));
  887. //
  888. // BigDecimal syDeptRadio =
  889. // ptlAgreementProductCostsExport.getSyExportRadioLevel1().add(ptlAgreementProductCostsExport.getSyExportRadioLevel2()).add(ptlAgreementProductCostsExport.getSyExportRadioLevel3()).add(ptlAgreementProductCostsExport.getSyExportRadioLevel4()).add(ptlAgreementProductCostsExport.getSyExportRadioLevel5());
  890. // FeeOrderNewVo.DeptManagerFee syDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(insFeeOrderNew.getSyPremium(),
  891. // ptlAgreementProductCostsExport.getSyExportRadioLevel1(), ptlAgreementProductCostsExport.getSyExportRadioLevel2(),
  892. // ptlAgreementProductCostsExport.getSyExportRadioLevel3(), ptlAgreementProductCostsExport.getSyExportRadioLevel4(),
  893. // ptlAgreementProductCostsExport.getSyExportRadioLevel5());
  894. // insFeeOrderNew.setSyDeptProportionLevel1(syDeptManagerFee.getDeptProportionLevelOne());
  895. // insFeeOrderNew.setSyDeptPremiumsLevel1(twoPeople(syDeptManagerFee.getDeptPremiumsLevelOne()));
  896. // insFeeOrderNew.setSyDeptProportionLevel2(syDeptManagerFee.getDeptProportionLevelTwo());
  897. // insFeeOrderNew.setSyDeptPremiumsLevel2(twoPeople(syDeptManagerFee.getDeptPremiumsLevelTwo()));
  898. // insFeeOrderNew.setSyDeptProportionLevel3(syDeptManagerFee.getDeptProportionLevelThree());
  899. // insFeeOrderNew.setSyDeptPremiumsLevel3(twoPeople(syDeptManagerFee.getDeptPremiumsLevelThree()));
  900. // insFeeOrderNew.setSyDeptProportionLevel4(syDeptManagerFee.getDeptProportionLevelFoure());
  901. // insFeeOrderNew.setSyDeptPremiumsLevel4(twoPeople(syDeptManagerFee.getDeptPremiumsLevelFoure()));
  902. // insFeeOrderNew.setSyDeptProportionLevel5(syDeptManagerFee.getDeptProportionLevelFive());
  903. // insFeeOrderNew.setSyDeptPremiumsLevel5(twoPeople(syDeptManagerFee.getDeptPremiumsLevelFive()));
  904. //
  905. // BigDecimal noDeptRadio =
  906. // ptlAgreementProductCostsExport.getNoCarExportRadioLevel1().add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel2()).add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel3()).add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel4()).add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel5());
  907. // FeeOrderNewVo.DeptManagerFee noDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(insFeeOrderNew.getNoPremium(),
  908. // ptlAgreementProductCostsExport.getNoCarExportRadioLevel1(), ptlAgreementProductCostsExport.getNoCarExportRadioLevel2(),
  909. // ptlAgreementProductCostsExport.getNoCarExportRadioLevel3(), ptlAgreementProductCostsExport.getNoCarExportRadioLevel4(),
  910. // ptlAgreementProductCostsExport.getNoCarExportRadioLevel5());
  911. // insFeeOrderNew.setNoDeptProportionLevel1(noDeptManagerFee.getDeptProportionLevelOne());
  912. // insFeeOrderNew.setNoDeptPremiumsLevel1(twoPeople(noDeptManagerFee.getDeptPremiumsLevelOne()));
  913. // insFeeOrderNew.setNoDeptProportionLevel2(noDeptManagerFee.getDeptProportionLevelTwo());
  914. // insFeeOrderNew.setNoDeptPremiumsLevel2(twoPeople(noDeptManagerFee.getDeptPremiumsLevelTwo()));
  915. // insFeeOrderNew.setNoDeptProportionLevel3(noDeptManagerFee.getDeptProportionLevelThree());
  916. // insFeeOrderNew.setNoDeptPremiumsLevel3(twoPeople(noDeptManagerFee.getDeptPremiumsLevelThree()));
  917. // insFeeOrderNew.setNoDeptProportionLevel4(noDeptManagerFee.getDeptProportionLevelFoure());
  918. // insFeeOrderNew.setNoDeptPremiumsLevel4(twoPeople(noDeptManagerFee.getDeptPremiumsLevelFoure()));
  919. // insFeeOrderNew.setNoDeptProportionLevel5(noDeptManagerFee.getDeptProportionLevelFive());
  920. // insFeeOrderNew.setNoDeptPremiumsLevel5(twoPeople(noDeptManagerFee.getDeptPremiumsLevelFive()));
  921. //
  922. // //endregion
  923. //
  924. // //region 出口费用
  925. //
  926. // //交强出口手续费比例
  927. // FeeOrderNewVo.ExportFee jqExportFee = feeRuleSchemeService.calcExportFee(insFeeOrderNew.getJqPremium(), new BigDecimal(ptlAgreementProductCostsNew.getJqCostsExportProportion()),
  928. // insFeeOrderNew.getJqCostsProportion(), jqDeptRadio, retailRadio, taxRadio);
  929. //
  930. // //商业出口手续费比例
  931. // FeeOrderNewVo.ExportFee syExportFee = feeRuleSchemeService.calcExportFee(insFeeOrderNew.getSyPremium(), new BigDecimal(ptlAgreementProductCostsNew.getSyCostsExportProportion()),
  932. // insFeeOrderNew.getSyCostsProportion(), syDeptRadio, retailRadio, taxRadio);
  933. //
  934. // //非车出口手续费比例
  935. // FeeOrderNewVo.ExportFee noExportFee = feeRuleSchemeService.calcExportFee(insFeeOrderNew.getNoPremium(), new BigDecimal(ptlAgreementProductCostsNew.getNoCostsExportProportion()),
  936. // insFeeOrderNew.getNoCostsProportion(), noDeptRadio, retailRadio, taxRadio);
  937. //
  938. // //出口手续费用
  939. // insFeeOrderNew.setJqExportSuperviseCostsPremiums(twoPeople(jqExportFee.getSuperviseCostsPremiums()));
  940. // insFeeOrderNew.setSyExportSuperviseCostsPremiums(twoPeople(syExportFee.getSuperviseCostsPremiums()));
  941. // insFeeOrderNew.setNoExportSuperviseCostsPremiums(twoPeople(noExportFee.getSuperviseCostsPremiums()));
  942. //
  943. // //出口其他费用比例
  944. // insFeeOrderNew.setJqExportOtherCostsProportion(twoPeople(jqExportFee.getOtherCostsProportion()));
  945. // insFeeOrderNew.setSyExportOtherCostsProportion(twoPeople(syExportFee.getOtherCostsProportion()));
  946. // insFeeOrderNew.setNoExportOtherCostsProportion(twoPeople(noExportFee.getOtherCostsProportion()));
  947. //
  948. // //出口其他费用
  949. // insFeeOrderNew.setJqExportOtherCostsPremiums(twoPeople(jqExportFee.getOtherCostsPremiums()));
  950. // insFeeOrderNew.setSyExportOtherCostsPremiums(twoPeople(syExportFee.getOtherCostsPremiums()));
  951. // insFeeOrderNew.setNoExportOtherCostsPremiums(twoPeople(noExportFee.getOtherCostsPremiums()));
  952. //
  953. // //设置出口手续费比例
  954. // insFeeOrderNew.setJqCostsExportProportion(twoPeople(jqExportFee.getSuperviseCosts()));
  955. // insFeeOrderNew.setSyCostsExportProportion(twoPeople(syExportFee.getSuperviseCosts()));
  956. // insFeeOrderNew.setNoCostsExportProportion(twoPeople(noExportFee.getSuperviseCosts()));
  957. //
  958. // //endregion
  959. //
  960. // //region 计算利润差值
  961. // //入口 - 出口 - 机构管理费 1-5级 - 分销费 = 差值
  962. //
  963. // //分销交强费用
  964. // //分开算 1 2 3 级
  965. // BigDecimal jqFirst = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getFirstDetailProportion().divide(new BigDecimal(100))).setScale(2,BigDecimal.ROUND_DOWN);
  966. // BigDecimal jqSecond = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getSecondDetailProportion().divide(new BigDecimal(100))).setScale(2,BigDecimal.ROUND_DOWN);
  967. // BigDecimal jqThird = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getThirdDetailProportion().divide(new BigDecimal(100))).setScale(2,BigDecimal.ROUND_DOWN);
  968. // BigDecimal jqFenXiao = jqFirst.add(jqSecond).add(jqThird);
  969. // //分销商业费用
  970. // BigDecimal syFirst = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getFirstDetailProportion().divide(new BigDecimal(100))).setScale(2,BigDecimal.ROUND_DOWN);
  971. // BigDecimal sySecond = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getSecondDetailProportion().divide(new BigDecimal(100))).setScale(2,BigDecimal.ROUND_DOWN);
  972. // BigDecimal syThird = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getThirdDetailProportion().divide(new BigDecimal(100))).setScale(2,BigDecimal.ROUND_DOWN);
  973. // BigDecimal syFenXiao = syFirst.add(sySecond).add(syThird);
  974. // //分销非车费用
  975. // BigDecimal noFirst = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getFirstDetailProportion().divide(new BigDecimal(100))).setScale(2,BigDecimal.ROUND_DOWN);
  976. // BigDecimal noSecond = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getSecondDetailProportion().divide(new BigDecimal(100))).setScale(2,BigDecimal.ROUND_DOWN);
  977. // BigDecimal noThird = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getThirdDetailProportion().divide(new BigDecimal(100))).setScale(2,BigDecimal.ROUND_DOWN);
  978. // BigDecimal noFenXiao = noFirst.add(noSecond).add(noThird);
  979. //
  980. //
  981. // BigDecimal jqDifference = jqEntranceFee.getTotalAmount().subtract(
  982. // (jqExportFee.getSuperviseCostsPremiums().add(jqExportFee.getOtherCostsPremiums())))
  983. // .subtract(
  984. // (jqDeptManagerFee.getDeptPremiumsLevelOne().add(jqDeptManagerFee.getDeptPremiumsLevelTwo().add(jqDeptManagerFee.getDeptPremiumsLevelThree()).add(jqDeptManagerFee.getDeptPremiumsLevelFoure()).add(jqDeptManagerFee.getDeptPremiumsLevelFive())))
  985. // )
  986. // .subtract(jqFenXiao).setScale(5, BigDecimal.ROUND_HALF_DOWN);
  987. // insFeeOrderNew.setJqProfitMarginPremiums(jqDifference);
  988. //
  989. // BigDecimal syDifference = syEntranceFee.getTotalAmount().subtract(
  990. // (syExportFee.getSuperviseCostsPremiums().add(syExportFee.getOtherCostsPremiums())))
  991. // .subtract(
  992. // (syDeptManagerFee.getDeptPremiumsLevelOne().add(syDeptManagerFee.getDeptPremiumsLevelTwo().add(syDeptManagerFee.getDeptPremiumsLevelThree()).add(syDeptManagerFee.getDeptPremiumsLevelFoure()).add(syDeptManagerFee.getDeptPremiumsLevelFive())))
  993. // )
  994. // .subtract(syFenXiao).setScale(5, BigDecimal.ROUND_HALF_DOWN);
  995. // insFeeOrderNew.setSyProfitMarginPremiums(syDifference);
  996. //
  997. //
  998. // BigDecimal noDifference = noEntranceFee.getTotalAmount().subtract(
  999. // (noExportFee.getSuperviseCostsPremiums().add(noExportFee.getOtherCostsPremiums())))
  1000. // .subtract(
  1001. // (noDeptManagerFee.getDeptPremiumsLevelOne().add(noDeptManagerFee.getDeptPremiumsLevelTwo().add(noDeptManagerFee.getDeptPremiumsLevelThree()).add(noDeptManagerFee.getDeptPremiumsLevelFoure()).add(noDeptManagerFee.getDeptPremiumsLevelFive())))
  1002. // )
  1003. // .subtract(noFenXiao).setScale(5, BigDecimal.ROUND_HALF_DOWN);
  1004. //
  1005. // insFeeOrderNew.setNoProfitMarginPremiums(noDifference);
  1006. //
  1007. // //endregion
  1008. //
  1009. // //region 比例逆推是否等于0
  1010. //
  1011. // if(!feeRuleSchemeService.calculateProportion(jqEntranceFee,jqDeptManagerFee,jqExportFee,retailRadio,taxRadio,insFeeOrderNew.getJqPremium()))
  1012. // throw new SystemException("交强比例异常");
  1013. //
  1014. // if(!feeRuleSchemeService.calculateProportion(syEntranceFee,syDeptManagerFee,syExportFee,retailRadio,taxRadio,insFeeOrderNew.getSyPremium()))
  1015. // throw new SystemException("商业比例异常");
  1016. //
  1017. // if(!feeRuleSchemeService.calculateProportion(noEntranceFee,noDeptManagerFee,noExportFee,retailRadio,taxRadio,insFeeOrderNew.getNoPremium()))
  1018. // throw new SystemException("非车比例异常");
  1019. //endregion
  1020. // insFeeOrderNewService.saveOrUpdate(insFeeOrderNew);
  1021. }
  1022. @Override
  1023. public void calcCostsExternal(PtlAgreementProductCostsNew ptlAgreementProductCostsNew, InsAreaCompany insAreaCompany) {
  1024. //获取协议信息
  1025. // 外部订单比例
  1026. ptlAgreementProductCostsNew.blank();
  1027. PtlAgreement ptlAgreement = ptlAgreementService.getById(insAreaCompany.getAgreementId());
  1028. InsOrders insOrders = insOrdersService.getById(insAreaCompany.getOrderno());
  1029. SysUser sysUser = sysUserService.findByUserId(insOrders.getUserid());
  1030. BigDecimal enterProportion = sysSwitchConfigService.getEnterProportion(insOrders.getDeptid(), insOrders.getEntryStatus());
  1031. BigDecimal taxRadio = new BigDecimal("1.00");
  1032. //如果是外部订单则 不含税
  1033. if (ptlAgreement.getWithTax().equals("否")) {
  1034. taxRadio = new BigDecimal("1.06");
  1035. }
  1036. //税比例 固定1.06
  1037. //查找入口与出口费用比例
  1038. //出口配置
  1039. PtlAgreementProductCostsExport ptlAgreementProductCostsExport =
  1040. ptlAgreementProductCostsExportService.getOne(new LambdaQueryWrapper<PtlAgreementProductCostsExport>().eq(PtlAgreementProductCostsExport::getCostsId, ptlAgreementProductCostsNew.getId()));
  1041. InsFeeOrderNew insFeeOrderNew = new InsFeeOrderNew();
  1042. insFeeOrderNew.setId(IdGenerate.nextId());
  1043. insFeeOrderNew.setCostsId(ptlAgreementProductCostsNew.getId());
  1044. insFeeOrderNew.setAgreementId(insAreaCompany.getAgreementId());
  1045. //存储部门id与用户id
  1046. InsOrders order = insOrdersService.getById(insAreaCompany.getOrderno());
  1047. InsFeeOrderNew insFeeOrderNewByCompanyId = insFeeOrderNewService.getInsFeeOrderNewByCompanyId(insAreaCompany.getId());
  1048. if (insFeeOrderNewByCompanyId != null) {
  1049. insFeeOrderNew.setId(insFeeOrderNewByCompanyId.getId());
  1050. }
  1051. insFeeOrderNew.setDeptId(order.getDeptid());
  1052. insFeeOrderNew.setUserId(order.getUserid());
  1053. insFeeOrderNew.setInsOrderNo(insAreaCompany.getId());
  1054. insFeeOrderNew.setJqPremium(insAreaCompany.getJqpremium());
  1055. insFeeOrderNew.setSyPremium(insAreaCompany.getSypremium());
  1056. insFeeOrderNew.setNoPremium(insAreaCompany.getJypremium());
  1057. //不含税
  1058. BigDecimal bigDecimal = new BigDecimal("1.06");
  1059. insFeeOrderNew.setJqNoTaxPremium(insAreaCompany.getJqpremium().divide(bigDecimal, 2));
  1060. insFeeOrderNew.setSyNoTaxPremium(insAreaCompany.getSypremium().divide(bigDecimal, 2));
  1061. insFeeOrderNew.setNoNoTaxPremium(insAreaCompany.getJypremium().divide(bigDecimal, 2));
  1062. //region 计算入口费用
  1063. //交强入口信息
  1064. FeeOrderNewVo.EntranceFee jqEntranceFee = feeRuleSchemeService.calcEntranceFee(insFeeOrderNew.getJqPremium(),
  1065. new BigDecimal(ptlAgreementProductCostsNew.getJqCarCostsProportion()),
  1066. new BigDecimal(ptlAgreementProductCostsNew.getJqCarOtherCostsProportion()), taxRadio);
  1067. insFeeOrderNew.setJqCostsProportion(jqEntranceFee.getTotalProportion());
  1068. insFeeOrderNew.setJqSuperviseCostsProportion(jqEntranceFee.getSuperviseCosts());
  1069. insFeeOrderNew.setJqSuperviseCostsPremiums(jqEntranceFee.getSuperviseCostsPremiums());
  1070. insFeeOrderNew.setJqOtherCostsProportion(jqEntranceFee.getOtherCostsProportion());
  1071. insFeeOrderNew.setJqOtherCostsPremiums(jqEntranceFee.getOtherCostsPremiums());
  1072. insFeeOrderNew.setJqCostsPremiums(insFeeOrderNew.getJqSuperviseCostsPremiums().add(insFeeOrderNew.getJqOtherCostsPremiums()));
  1073. //商业入口信息
  1074. FeeOrderNewVo.EntranceFee syEntranceFee = feeRuleSchemeService.calcEntranceFee(insFeeOrderNew.getSyPremium(),
  1075. new BigDecimal(ptlAgreementProductCostsNew.getSyCarCostsProportion()),
  1076. new BigDecimal(ptlAgreementProductCostsNew.getSyCarOtherCostsProportion()), taxRadio);
  1077. insFeeOrderNew.setSyCostsProportion(syEntranceFee.getTotalProportion());
  1078. insFeeOrderNew.setSySuperviseCostsProportion(syEntranceFee.getSuperviseCosts());
  1079. insFeeOrderNew.setSySuperviseCostsPremiums(syEntranceFee.getSuperviseCostsPremiums());
  1080. insFeeOrderNew.setSyOtherCostsProportion(syEntranceFee.getOtherCostsProportion());
  1081. insFeeOrderNew.setSyOtherCostsPremiums(syEntranceFee.getOtherCostsPremiums());
  1082. insFeeOrderNew.setSyCostsPremiums(insFeeOrderNew.getSySuperviseCostsPremiums().add(insFeeOrderNew.getSyOtherCostsPremiums()));
  1083. //非车入口信息
  1084. FeeOrderNewVo.EntranceFee noEntranceFee = feeRuleSchemeService.calcEntranceFee(insFeeOrderNew.getNoPremium(),
  1085. new BigDecimal(ptlAgreementProductCostsNew.getNoCarCostsProportion()),
  1086. new BigDecimal(ptlAgreementProductCostsNew.getNoCarOtherCostsProportion()), taxRadio);
  1087. insFeeOrderNew.setNoCostsProportion(noEntranceFee.getTotalProportion());
  1088. insFeeOrderNew.setNoSuperviseCostsProportion(noEntranceFee.getSuperviseCosts());
  1089. insFeeOrderNew.setNoSuperviseCostsPremiums(noEntranceFee.getSuperviseCostsPremiums());
  1090. insFeeOrderNew.setNoOtherCostsProportion(noEntranceFee.getOtherCostsProportion());
  1091. insFeeOrderNew.setNoOtherCostsPremiums(noEntranceFee.getOtherCostsPremiums());
  1092. insFeeOrderNew.setNoCostsPremiums(insFeeOrderNew.getNoSuperviseCostsPremiums().add(insFeeOrderNew.getNoOtherCostsPremiums()));
  1093. //endregion
  1094. //region 重新计算管理费比例和分销比例
  1095. List<EsmRetail> esmRetailList = esmRetailService.selectList(" where t.deptid=? and t.status = '1' ",
  1096. new Object[]{sysUser.getDeptId()});
  1097. Integer retailLevel = 0;
  1098. //默认分销比例设置
  1099. RetailProportion retailProportion = new RetailProportion();
  1100. if (!Objects.isNull(esmRetailList) && !esmRetailList.isEmpty()) {
  1101. retailLevel = Integer.parseInt(esmRetailList.get(0).getRetailtype());
  1102. //赋值默认的分销比例
  1103. retailProportion.setProportion(esmRetailList.get(0).getDisrate1(), esmRetailList.get(0).getDisrate2(), esmRetailList.get(0).getDisrate3());
  1104. }
  1105. //获取交强机构管理费总比例
  1106. BigDecimal jqDeptProportion = ptlAgreementProductCostsExport.getJqExportRadioLevel1()
  1107. .add(ptlAgreementProductCostsExport.getJqExportRadioLevel2())
  1108. .add(ptlAgreementProductCostsExport.getJqExportRadioLevel3())
  1109. .add(ptlAgreementProductCostsExport.getJqExportRadioLevel4())
  1110. .add(ptlAgreementProductCostsExport.getJqExportRadioLevel5());
  1111. //获取商业机构管理费总比例
  1112. BigDecimal syDeptProportion = ptlAgreementProductCostsExport.getSyExportRadioLevel1()
  1113. .add(ptlAgreementProductCostsExport.getSyExportRadioLevel2())
  1114. .add(ptlAgreementProductCostsExport.getSyExportRadioLevel3())
  1115. .add(ptlAgreementProductCostsExport.getSyExportRadioLevel4())
  1116. .add(ptlAgreementProductCostsExport.getSyExportRadioLevel5());
  1117. //获取非车机构管理费总比例
  1118. BigDecimal noDeptProportion = ptlAgreementProductCostsExport.getNoCarExportRadioLevel1()
  1119. .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel2())
  1120. .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel3())
  1121. .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel4())
  1122. .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel5());
  1123. //获取交强分销总比例
  1124. BigDecimal jqRetailProportion = retailProportion.getJqRetailLevel1Proportion()
  1125. .add(retailProportion.getJqRetailLevel2Proportion())
  1126. .add(retailProportion.getJqRetailLevel3Proportion());
  1127. //获取商业分销总比例
  1128. BigDecimal syRetailProportion = retailProportion.getSyRetailLevel1Proportion()
  1129. .add(retailProportion.getSyRetailLevel2Proportion())
  1130. .add(retailProportion.getSyRetailLevel3Proportion());
  1131. //获取非车分销总比例
  1132. BigDecimal noRetailProportion = retailProportion.getNoRetailLevel1Proportion()
  1133. .add(retailProportion.getNoRetailLevel2Proportion())
  1134. .add(retailProportion.getNoRetailLevel3Proportion());
  1135. //重新计算比例 入口是否超出支付的比例
  1136. ReCalcuLateProportion jqReCalcuLateProportion = recalculateProportion(
  1137. new BigDecimal(ptlAgreementProductCostsNew.getJqCostsProportion()),
  1138. jqDeptProportion,
  1139. jqRetailProportion,
  1140. taxRadio,
  1141. retailLevel,
  1142. ptlAgreementProductCostsExport,
  1143. retailProportion,
  1144. "jq",
  1145. enterProportion
  1146. );
  1147. ReCalcuLateProportion syReCalcuLateProportion = recalculateProportion(
  1148. new BigDecimal(ptlAgreementProductCostsNew.getSyCostsProportion()),
  1149. syDeptProportion,
  1150. syRetailProportion,
  1151. taxRadio,
  1152. retailLevel,
  1153. ptlAgreementProductCostsExport,
  1154. retailProportion,
  1155. "sy",
  1156. enterProportion
  1157. );
  1158. ReCalcuLateProportion noReCalcuLateProportion = recalculateProportion(
  1159. new BigDecimal(ptlAgreementProductCostsNew.getNoCostsProportion()),
  1160. noDeptProportion,
  1161. noRetailProportion,
  1162. taxRadio,
  1163. retailLevel,
  1164. ptlAgreementProductCostsExport,
  1165. retailProportion,
  1166. "no",
  1167. enterProportion
  1168. );
  1169. retailProportion.setProportion(jqReCalcuLateProportion, syReCalcuLateProportion, noReCalcuLateProportion);
  1170. // ptlAgreementProductCostsExportService.updateById(ptlAgreementProductCostsExport);
  1171. //endregion
  1172. //region 计算分销费用
  1173. //分销总比例
  1174. // BigDecimal jqRetailRadio = new BigDecimal("0");
  1175. // BigDecimal syRetailRadio = new BigDecimal("0");
  1176. // BigDecimal noRetailRadio = new BigDecimal("0");
  1177. FeeOrderNewVo.RetailFee retailFeeLevel3 = new FeeOrderNewVo.RetailFee();
  1178. FeeOrderNewVo.RetailFee retailFeeLevel2 = new FeeOrderNewVo.RetailFee();
  1179. FeeOrderNewVo.RetailFee retailFeeLevel1 = new FeeOrderNewVo.RetailFee();
  1180. //分销总比例
  1181. BigDecimal retailRadio = new BigDecimal("0");
  1182. if (esmRetailList != null && !esmRetailList.isEmpty()) {
  1183. EsmRetail esmRetail = esmRetailList.get(0);
  1184. //分销等级
  1185. insFeeOrderNew.setDistributionStatus(esmRetailList.get(0).getRetailtype());
  1186. //用户分销人员id
  1187. List<EsmUserReferrer> parents = esmUserReferrerService.findParents(sysUser.getId());
  1188. if (esmRetail != null) {
  1189. BigDecimal sumPremium = insFeeOrderNew.getJqPremium().add(insFeeOrderNew.getSyPremium()).add(insFeeOrderNew.getNoPremium());
  1190. if (Integer.parseInt(esmRetail.getRetailtype()) >= 3) {
  1191. insFeeOrderNew.setThirdDetailProportion(new BigDecimal(String.valueOf(esmRetail.getDisrate3())));
  1192. retailRadio = retailRadio.add(insFeeOrderNew.getThirdDetailProportion()).setScale(2, BigDecimal.ROUND_DOWN);
  1193. retailFeeLevel3 = feeRuleSchemeService.calcRetail(
  1194. insFeeOrderNew.getJqPremium(),
  1195. insFeeOrderNew.getJqCostsProportion(),
  1196. insFeeOrderNew.getSyPremium(),
  1197. insFeeOrderNew.getSyCostsProportion(),
  1198. insFeeOrderNew.getNoPremium(),
  1199. insFeeOrderNew.getNoCostsProportion(),
  1200. retailProportion.getJqRetailLevel3Proportion(),
  1201. retailProportion.getSyRetailLevel3Proportion(),
  1202. retailProportion.getNoRetailLevel3Proportion());
  1203. insFeeOrderNew.setThirdDetailPremiums(retailFeeLevel3.getTotalRetailPremiums());
  1204. if (parents != null && parents.size() > 2) {
  1205. insFeeOrderNew.setThreeLevelUserId(parents.get(2).getId());
  1206. }
  1207. } else {
  1208. insFeeOrderNew.setThirdDetailProportion(new BigDecimal(0));
  1209. }
  1210. if (Integer.parseInt(esmRetail.getRetailtype()) >= 2) {
  1211. insFeeOrderNew.setSecondDetailProportion(new BigDecimal(String.valueOf(esmRetail.getDisrate2())));
  1212. retailRadio = retailRadio.add(insFeeOrderNew.getSecondDetailProportion()).setScale(2, BigDecimal.ROUND_DOWN);
  1213. retailFeeLevel2 = feeRuleSchemeService.calcRetail(insFeeOrderNew.getJqPremium(),
  1214. insFeeOrderNew.getJqCostsProportion(),
  1215. insFeeOrderNew.getSyPremium(),
  1216. insFeeOrderNew.getSyCostsProportion(),
  1217. insFeeOrderNew.getNoPremium(),
  1218. insFeeOrderNew.getNoCostsProportion(),
  1219. retailProportion.getJqRetailLevel2Proportion(),
  1220. retailProportion.getSyRetailLevel2Proportion(),
  1221. retailProportion.getNoRetailLevel2Proportion());
  1222. insFeeOrderNew.setSecondDetailPremiums(retailFeeLevel2.getTotalRetailPremiums());
  1223. if (parents != null && parents.size() > 1) {
  1224. insFeeOrderNew.setTwoLevelUserId(parents.get(1).getId());
  1225. }
  1226. } else {
  1227. insFeeOrderNew.setSecondDetailProportion(new BigDecimal(0));
  1228. }
  1229. if (Integer.parseInt(esmRetail.getRetailtype()) >= 1) {
  1230. insFeeOrderNew.setFirstDetailProportion(new BigDecimal(String.valueOf(esmRetail.getDisrate1())));
  1231. retailRadio = retailRadio.add(insFeeOrderNew.getFirstDetailProportion()).setScale(2, BigDecimal.ROUND_DOWN);
  1232. retailFeeLevel1 = feeRuleSchemeService.calcRetail(insFeeOrderNew.getJqPremium(),
  1233. insFeeOrderNew.getJqCostsProportion(),
  1234. insFeeOrderNew.getSyPremium(),
  1235. insFeeOrderNew.getSyCostsProportion(),
  1236. insFeeOrderNew.getNoPremium(),
  1237. insFeeOrderNew.getNoCostsProportion(),
  1238. retailProportion.getJqRetailLevel1Proportion(),
  1239. retailProportion.getSyRetailLevel1Proportion(),
  1240. retailProportion.getNoRetailLevel1Proportion());
  1241. insFeeOrderNew.setFirstDetailPremiums(retailFeeLevel1.getTotalRetailPremiums());
  1242. if (parents != null && !parents.isEmpty()) {
  1243. insFeeOrderNew.setFirstLevelUserId(parents.get(0).getId());
  1244. }
  1245. } else {
  1246. insFeeOrderNew.setFirstDetailProportion(new BigDecimal(0));
  1247. }
  1248. } else {
  1249. insFeeOrderNew.setFirstDetailPremiums(new BigDecimal(0));
  1250. insFeeOrderNew.setSecondDetailPremiums(new BigDecimal(0));
  1251. insFeeOrderNew.setThirdDetailPremiums(new BigDecimal(0));
  1252. }
  1253. } else {
  1254. insFeeOrderNew.setFirstDetailProportion(new BigDecimal(0));
  1255. insFeeOrderNew.setSecondDetailProportion(new BigDecimal(0));
  1256. insFeeOrderNew.setThirdDetailProportion(new BigDecimal(0));
  1257. }
  1258. insFeeOrderNew.assignRetail(retailFeeLevel1, retailFeeLevel2, retailFeeLevel3);
  1259. //endregion
  1260. //region 设置机构管理费
  1261. //交强机构管理费
  1262. BigDecimal jqDeptRadio =
  1263. ptlAgreementProductCostsExport.getJqExportRadioLevel1().add(ptlAgreementProductCostsExport.getJqExportRadioLevel2()).add(ptlAgreementProductCostsExport.getJqExportRadioLevel3()).add(ptlAgreementProductCostsExport.getJqExportRadioLevel4()).add(ptlAgreementProductCostsExport.getJqExportRadioLevel5());
  1264. FeeOrderNewVo.DeptManagerFee jqDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(insFeeOrderNew.getJqPremium(),
  1265. ptlAgreementProductCostsExport.getJqExportRadioLevel1(), ptlAgreementProductCostsExport.getJqExportRadioLevel2(),
  1266. ptlAgreementProductCostsExport.getJqExportRadioLevel3(), ptlAgreementProductCostsExport.getJqExportRadioLevel4(),
  1267. ptlAgreementProductCostsExport.getJqExportRadioLevel5());
  1268. insFeeOrderNew.setJqDeptProportionLevel1(jqDeptManagerFee.getDeptProportionLevelOne());
  1269. insFeeOrderNew.setJqDeptPremiumsLevel1(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelOne()));
  1270. insFeeOrderNew.setJqDeptProportionLevel2(jqDeptManagerFee.getDeptProportionLevelTwo());
  1271. insFeeOrderNew.setJqDeptPremiumsLevel2(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelTwo()));
  1272. insFeeOrderNew.setJqDeptProportionLevel3(jqDeptManagerFee.getDeptProportionLevelThree());
  1273. insFeeOrderNew.setJqDeptPremiumsLevel3(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelThree()));
  1274. insFeeOrderNew.setJqDeptProportionLevel4(jqDeptManagerFee.getDeptProportionLevelFoure());
  1275. insFeeOrderNew.setJqDeptPremiumsLevel4(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelFoure()));
  1276. insFeeOrderNew.setJqDeptProportionLevel5(jqDeptManagerFee.getDeptProportionLevelFive());
  1277. insFeeOrderNew.setJqDeptPremiumsLevel5(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelFive()));
  1278. BigDecimal syDeptRadio =
  1279. ptlAgreementProductCostsExport.getSyExportRadioLevel1().add(ptlAgreementProductCostsExport.getSyExportRadioLevel2()).add(ptlAgreementProductCostsExport.getSyExportRadioLevel3()).add(ptlAgreementProductCostsExport.getSyExportRadioLevel4()).add(ptlAgreementProductCostsExport.getSyExportRadioLevel5());
  1280. FeeOrderNewVo.DeptManagerFee syDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(insFeeOrderNew.getSyPremium(),
  1281. ptlAgreementProductCostsExport.getSyExportRadioLevel1(), ptlAgreementProductCostsExport.getSyExportRadioLevel2(),
  1282. ptlAgreementProductCostsExport.getSyExportRadioLevel3(), ptlAgreementProductCostsExport.getSyExportRadioLevel4(),
  1283. ptlAgreementProductCostsExport.getSyExportRadioLevel5());
  1284. insFeeOrderNew.setSyDeptProportionLevel1(syDeptManagerFee.getDeptProportionLevelOne());
  1285. insFeeOrderNew.setSyDeptPremiumsLevel1(twoPeople(syDeptManagerFee.getDeptPremiumsLevelOne()));
  1286. insFeeOrderNew.setSyDeptProportionLevel2(syDeptManagerFee.getDeptProportionLevelTwo());
  1287. insFeeOrderNew.setSyDeptPremiumsLevel2(twoPeople(syDeptManagerFee.getDeptPremiumsLevelTwo()));
  1288. insFeeOrderNew.setSyDeptProportionLevel3(syDeptManagerFee.getDeptProportionLevelThree());
  1289. insFeeOrderNew.setSyDeptPremiumsLevel3(twoPeople(syDeptManagerFee.getDeptPremiumsLevelThree()));
  1290. insFeeOrderNew.setSyDeptProportionLevel4(syDeptManagerFee.getDeptProportionLevelFoure());
  1291. insFeeOrderNew.setSyDeptPremiumsLevel4(twoPeople(syDeptManagerFee.getDeptPremiumsLevelFoure()));
  1292. insFeeOrderNew.setSyDeptProportionLevel5(syDeptManagerFee.getDeptProportionLevelFive());
  1293. insFeeOrderNew.setSyDeptPremiumsLevel5(twoPeople(syDeptManagerFee.getDeptPremiumsLevelFive()));
  1294. BigDecimal noDeptRadio =
  1295. ptlAgreementProductCostsExport.getNoCarExportRadioLevel1().add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel2()).add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel3()).add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel4()).add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel5());
  1296. FeeOrderNewVo.DeptManagerFee noDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(insFeeOrderNew.getNoPremium(),
  1297. ptlAgreementProductCostsExport.getNoCarExportRadioLevel1(), ptlAgreementProductCostsExport.getNoCarExportRadioLevel2(),
  1298. ptlAgreementProductCostsExport.getNoCarExportRadioLevel3(), ptlAgreementProductCostsExport.getNoCarExportRadioLevel4(),
  1299. ptlAgreementProductCostsExport.getNoCarExportRadioLevel5());
  1300. insFeeOrderNew.setNoDeptProportionLevel1(noDeptManagerFee.getDeptProportionLevelOne());
  1301. insFeeOrderNew.setNoDeptPremiumsLevel1(twoPeople(noDeptManagerFee.getDeptPremiumsLevelOne()));
  1302. insFeeOrderNew.setNoDeptProportionLevel2(noDeptManagerFee.getDeptProportionLevelTwo());
  1303. insFeeOrderNew.setNoDeptPremiumsLevel2(twoPeople(noDeptManagerFee.getDeptPremiumsLevelTwo()));
  1304. insFeeOrderNew.setNoDeptProportionLevel3(noDeptManagerFee.getDeptProportionLevelThree());
  1305. insFeeOrderNew.setNoDeptPremiumsLevel3(twoPeople(noDeptManagerFee.getDeptPremiumsLevelThree()));
  1306. insFeeOrderNew.setNoDeptProportionLevel4(noDeptManagerFee.getDeptProportionLevelFoure());
  1307. insFeeOrderNew.setNoDeptPremiumsLevel4(twoPeople(noDeptManagerFee.getDeptPremiumsLevelFoure()));
  1308. insFeeOrderNew.setNoDeptProportionLevel5(noDeptManagerFee.getDeptProportionLevelFive());
  1309. insFeeOrderNew.setNoDeptPremiumsLevel5(twoPeople(noDeptManagerFee.getDeptPremiumsLevelFive()));
  1310. //endregion
  1311. //region 出口费用
  1312. //交强出口手续费比例
  1313. FeeOrderNewVo.ExportFee jqExportFee = feeRuleSchemeService.calcExportFee(insFeeOrderNew.getJqPremium(), new BigDecimal(ptlAgreementProductCostsNew.getJqCostsExportProportion()),
  1314. insFeeOrderNew.getJqCostsProportion(), jqDeptRadio, retailRadio, taxRadio, jqReCalcuLateProportion.getProxyProportion());
  1315. //商业出口手续费比例
  1316. FeeOrderNewVo.ExportFee syExportFee = feeRuleSchemeService.calcExportFee(insFeeOrderNew.getSyPremium(), new BigDecimal(ptlAgreementProductCostsNew.getSyCostsExportProportion()),
  1317. insFeeOrderNew.getSyCostsProportion(), syDeptRadio, retailRadio, taxRadio, syReCalcuLateProportion.getProxyProportion());
  1318. //非车出口手续费比例
  1319. FeeOrderNewVo.ExportFee noExportFee = feeRuleSchemeService.calcExportFee(insFeeOrderNew.getNoPremium(), new BigDecimal(ptlAgreementProductCostsNew.getNoCostsExportProportion()),
  1320. insFeeOrderNew.getNoCostsProportion(), noDeptRadio, retailRadio, taxRadio, noReCalcuLateProportion.getProxyProportion());
  1321. //出口手续费用
  1322. insFeeOrderNew.setJqExportSuperviseCostsPremiums(twoPeople(jqExportFee.getSuperviseCostsPremiums()));
  1323. insFeeOrderNew.setSyExportSuperviseCostsPremiums(twoPeople(syExportFee.getSuperviseCostsPremiums()));
  1324. insFeeOrderNew.setNoExportSuperviseCostsPremiums(twoPeople(noExportFee.getSuperviseCostsPremiums()));
  1325. //出口其他费用比例
  1326. insFeeOrderNew.setJqExportOtherCostsProportion(twoPeople(jqExportFee.getOtherCostsProportion()));
  1327. insFeeOrderNew.setSyExportOtherCostsProportion(twoPeople(syExportFee.getOtherCostsProportion()));
  1328. insFeeOrderNew.setNoExportOtherCostsProportion(twoPeople(noExportFee.getOtherCostsProportion()));
  1329. //出口其他费用
  1330. insFeeOrderNew.setJqExportOtherCostsPremiums(twoPeople(jqExportFee.getOtherCostsPremiums()));
  1331. insFeeOrderNew.setSyExportOtherCostsPremiums(twoPeople(syExportFee.getOtherCostsPremiums()));
  1332. insFeeOrderNew.setNoExportOtherCostsPremiums(twoPeople(noExportFee.getOtherCostsPremiums()));
  1333. //设置出口手续费比例
  1334. insFeeOrderNew.setJqCostsExportProportion(twoPeople(jqExportFee.getSuperviseCosts()));
  1335. insFeeOrderNew.setSyCostsExportProportion(twoPeople(syExportFee.getSuperviseCosts()));
  1336. insFeeOrderNew.setNoCostsExportProportion(twoPeople(noExportFee.getSuperviseCosts()));
  1337. // 外部订单费用
  1338. insFeeOrderNew.setJqExternalProportion(jqExportFee.getExternalProportion());
  1339. insFeeOrderNew.setJqExternalPremiums(jqExportFee.getExternalPremiums());
  1340. insFeeOrderNew.setSyExternalProportion(syExportFee.getExternalProportion());
  1341. insFeeOrderNew.setSyExternalPremiums(syExportFee.getExternalPremiums());
  1342. insFeeOrderNew.setNoExternalProportion(noExportFee.getExternalProportion());
  1343. insFeeOrderNew.setNoExternalPremiums(noExportFee.getExternalPremiums());
  1344. //endregion
  1345. //region 计算利润差值
  1346. //入口 - 出口 - 机构管理费 1-5级 - 分销费 = 差值
  1347. //分销交强费用
  1348. //分开算 1 2 3 级
  1349. BigDecimal jqFirst = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getFirstDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  1350. BigDecimal jqSecond = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getSecondDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  1351. BigDecimal jqThird = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getThirdDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  1352. BigDecimal jqFenXiao = jqFirst.add(jqSecond).add(jqThird);
  1353. //分销商业费用
  1354. BigDecimal syFirst = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getFirstDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  1355. BigDecimal sySecond = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getSecondDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  1356. BigDecimal syThird = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getThirdDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  1357. BigDecimal syFenXiao = syFirst.add(sySecond).add(syThird);
  1358. //分销非车费用
  1359. BigDecimal noFirst = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getFirstDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  1360. BigDecimal noSecond = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getSecondDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  1361. BigDecimal noThird = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getThirdDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  1362. BigDecimal noFenXiao = noFirst.add(noSecond).add(noThird);
  1363. BigDecimal jqDifference = jqEntranceFee.getTotalAmount()
  1364. .subtract(jqExportFee.getExternalPremiums())
  1365. .subtract(
  1366. (jqExportFee.getSuperviseCostsPremiums().add(jqExportFee.getOtherCostsPremiums())))
  1367. .subtract(
  1368. (jqDeptManagerFee.getDeptPremiumsLevelOne().add(jqDeptManagerFee.getDeptPremiumsLevelTwo().add(jqDeptManagerFee.getDeptPremiumsLevelThree()).add(jqDeptManagerFee.getDeptPremiumsLevelFoure()).add(jqDeptManagerFee.getDeptPremiumsLevelFive())))
  1369. )
  1370. .subtract(jqFenXiao).setScale(5, BigDecimal.ROUND_HALF_DOWN);
  1371. insFeeOrderNew.setJqProfitMarginPremiums(jqDifference);
  1372. BigDecimal syDifference = syEntranceFee.getTotalAmount()
  1373. .subtract(syExportFee.getExternalPremiums())
  1374. .subtract(
  1375. (syExportFee.getSuperviseCostsPremiums().add(syExportFee.getOtherCostsPremiums())))
  1376. .subtract(
  1377. (syDeptManagerFee.getDeptPremiumsLevelOne().add(syDeptManagerFee.getDeptPremiumsLevelTwo().add(syDeptManagerFee.getDeptPremiumsLevelThree()).add(syDeptManagerFee.getDeptPremiumsLevelFoure()).add(syDeptManagerFee.getDeptPremiumsLevelFive())))
  1378. )
  1379. .subtract(syFenXiao).setScale(5, BigDecimal.ROUND_HALF_DOWN);
  1380. insFeeOrderNew.setSyProfitMarginPremiums(syDifference);
  1381. BigDecimal noDifference = noEntranceFee.getTotalAmount()
  1382. .subtract(noExportFee.getExternalPremiums())
  1383. .subtract(
  1384. (noExportFee.getSuperviseCostsPremiums().add(noExportFee.getOtherCostsPremiums())))
  1385. .subtract(
  1386. (noDeptManagerFee.getDeptPremiumsLevelOne().add(noDeptManagerFee.getDeptPremiumsLevelTwo().add(noDeptManagerFee.getDeptPremiumsLevelThree()).add(noDeptManagerFee.getDeptPremiumsLevelFoure()).add(noDeptManagerFee.getDeptPremiumsLevelFive())))
  1387. )
  1388. .subtract(noFenXiao).setScale(5, BigDecimal.ROUND_HALF_DOWN);
  1389. insFeeOrderNew.setNoProfitMarginPremiums(noDifference);
  1390. //endregion
  1391. //region 比例逆推是否等于0
  1392. if (!feeRuleSchemeService.calculateProportion(jqEntranceFee, jqDeptManagerFee, jqExportFee, retailRadio, taxRadio, insFeeOrderNew.getJqPremium()))
  1393. throw new SystemException("交强比例异常");
  1394. if (!feeRuleSchemeService.calculateProportion(syEntranceFee, syDeptManagerFee, syExportFee, retailRadio, taxRadio, insFeeOrderNew.getSyPremium()))
  1395. throw new SystemException("商业比例异常");
  1396. if (!feeRuleSchemeService.calculateProportion(noEntranceFee, noDeptManagerFee, noExportFee, retailRadio, taxRadio, insFeeOrderNew.getNoPremium()))
  1397. throw new SystemException("非车比例异常");
  1398. //endregion
  1399. insFeeOrderNewService.saveOrUpdate(insFeeOrderNew);
  1400. }
  1401. @Override
  1402. public ExternalOrderFeeVo calcCostsExternalExportData(PtlAgreement ptlAgreement, PtlAgreementProductCostsNew ptlAgreementProductCostsNew, ExternalOrderFeeVo externalOrderFeeVo) {
  1403. //获取协议信息
  1404. // 外部订单比例
  1405. ptlAgreementProductCostsNew.blank();
  1406. SysUser sysUser = sysUserService.findByUserId(externalOrderFeeVo.getUserId());
  1407. BigDecimal enterProportion = sysSwitchConfigService.getEnterProportion(sysUser.getDeptId(), 3);
  1408. BigDecimal taxRadio = new BigDecimal("1.00");
  1409. //如果是外部订单则 不含税
  1410. if (ptlAgreement.getWithTax().equals("否")) {
  1411. taxRadio = new BigDecimal("1.06");
  1412. }
  1413. //税比例 固定1.06
  1414. //查找入口与出口费用比例
  1415. //出口配置
  1416. PtlAgreementProductCostsExport ptlAgreementProductCostsExport =
  1417. ptlAgreementProductCostsExportService.getOne(new LambdaQueryWrapper<PtlAgreementProductCostsExport>()
  1418. .eq(PtlAgreementProductCostsExport::getCostsId, ptlAgreementProductCostsNew.getId()));
  1419. //不含税
  1420. BigDecimal bigDecimal = new BigDecimal("1.06");
  1421. externalOrderFeeVo.setJqNoTaxPremium(externalOrderFeeVo.getJqPremium().divide(bigDecimal, 2));
  1422. externalOrderFeeVo.setSyNoTaxPremium(externalOrderFeeVo.getSyPremium().divide(bigDecimal, 2));
  1423. externalOrderFeeVo.setNoNoTaxPremium(externalOrderFeeVo.getNoPremium().divide(bigDecimal, 2));
  1424. //region 计算入口费用
  1425. //交强入口信息
  1426. FeeOrderNewVo.EntranceFee jqEntranceFee = feeRuleSchemeService.calcEntranceFee(externalOrderFeeVo.getJqPremium(),
  1427. new BigDecimal(ptlAgreementProductCostsNew.getJqCarCostsProportion()),
  1428. externalOrderFeeVo.getJqRadio(), taxRadio);
  1429. //endregion
  1430. //region 重新计算管理费比例和分销比例
  1431. List<EsmRetail> esmRetailList = esmRetailService.selectList(" where t.deptid=? and t.status = '1' ",
  1432. new Object[]{sysUser.getDeptId()});
  1433. Integer retailLevel = 0;
  1434. //默认分销比例设置
  1435. RetailProportion retailProportion = new RetailProportion();
  1436. if (!Objects.isNull(esmRetailList) && !esmRetailList.isEmpty()) {
  1437. retailLevel = Integer.parseInt(esmRetailList.get(0).getRetailtype());
  1438. //赋值默认的分销比例
  1439. retailProportion.setProportion(esmRetailList.get(0).getDisrate1(), esmRetailList.get(0).getDisrate2(), esmRetailList.get(0).getDisrate3());
  1440. }
  1441. //获取交强机构管理费总比例
  1442. BigDecimal jqDeptProportion = ptlAgreementProductCostsExport.getJqExportRadioLevel1()
  1443. .add(ptlAgreementProductCostsExport.getJqExportRadioLevel2())
  1444. .add(ptlAgreementProductCostsExport.getJqExportRadioLevel3())
  1445. .add(ptlAgreementProductCostsExport.getJqExportRadioLevel4())
  1446. .add(ptlAgreementProductCostsExport.getJqExportRadioLevel5());
  1447. //获取商业机构管理费总比例
  1448. BigDecimal syDeptProportion = ptlAgreementProductCostsExport.getSyExportRadioLevel1()
  1449. .add(ptlAgreementProductCostsExport.getSyExportRadioLevel2())
  1450. .add(ptlAgreementProductCostsExport.getSyExportRadioLevel3())
  1451. .add(ptlAgreementProductCostsExport.getSyExportRadioLevel4())
  1452. .add(ptlAgreementProductCostsExport.getSyExportRadioLevel5());
  1453. //获取非车机构管理费总比例
  1454. BigDecimal noDeptProportion = ptlAgreementProductCostsExport.getNoCarExportRadioLevel1()
  1455. .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel2())
  1456. .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel3())
  1457. .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel4())
  1458. .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel5());
  1459. //获取交强分销总比例
  1460. BigDecimal jqRetailProportion = retailProportion.getJqRetailLevel1Proportion()
  1461. .add(retailProportion.getJqRetailLevel2Proportion())
  1462. .add(retailProportion.getJqRetailLevel3Proportion());
  1463. //获取商业分销总比例
  1464. BigDecimal syRetailProportion = retailProportion.getSyRetailLevel1Proportion()
  1465. .add(retailProportion.getSyRetailLevel2Proportion())
  1466. .add(retailProportion.getSyRetailLevel3Proportion());
  1467. //获取非车分销总比例
  1468. BigDecimal noRetailProportion = retailProportion.getNoRetailLevel1Proportion()
  1469. .add(retailProportion.getNoRetailLevel2Proportion())
  1470. .add(retailProportion.getNoRetailLevel3Proportion());
  1471. //重新计算比例 入口是否超出支付的比例
  1472. ReCalcuLateProportion jqReCalcuLateProportion = recalculateProportion(
  1473. new BigDecimal(ptlAgreementProductCostsNew.getJqCostsProportion()),
  1474. jqDeptProportion,
  1475. jqRetailProportion,
  1476. taxRadio,
  1477. retailLevel,
  1478. ptlAgreementProductCostsExport,
  1479. retailProportion,
  1480. "jq",
  1481. enterProportion
  1482. );
  1483. ReCalcuLateProportion syReCalcuLateProportion = recalculateProportion(
  1484. new BigDecimal(ptlAgreementProductCostsNew.getSyCostsProportion()),
  1485. syDeptProportion,
  1486. syRetailProportion,
  1487. taxRadio,
  1488. retailLevel,
  1489. ptlAgreementProductCostsExport,
  1490. retailProportion,
  1491. "sy",
  1492. enterProportion
  1493. );
  1494. ReCalcuLateProportion noReCalcuLateProportion = recalculateProportion(
  1495. new BigDecimal(ptlAgreementProductCostsNew.getNoCostsProportion()),
  1496. noDeptProportion,
  1497. noRetailProportion,
  1498. taxRadio,
  1499. retailLevel,
  1500. ptlAgreementProductCostsExport,
  1501. retailProportion,
  1502. "no",
  1503. enterProportion
  1504. );
  1505. retailProportion.setProportion(jqReCalcuLateProportion, syReCalcuLateProportion, noReCalcuLateProportion);
  1506. // ptlAgreementProductCostsExportService.updateById(ptlAgreementProductCostsExport);
  1507. //endregion
  1508. //region 计算分销费用
  1509. //分销总比例
  1510. BigDecimal jqRetailRadio = new BigDecimal("0");
  1511. BigDecimal syRetailRadio = new BigDecimal("0");
  1512. BigDecimal noRetailRadio = new BigDecimal("0");
  1513. FeeOrderNewVo.RetailFee retailFeeLevel3 = new FeeOrderNewVo.RetailFee();
  1514. FeeOrderNewVo.RetailFee retailFeeLevel2 = new FeeOrderNewVo.RetailFee();
  1515. FeeOrderNewVo.RetailFee retailFeeLevel1 = new FeeOrderNewVo.RetailFee();
  1516. //分销总比例
  1517. BigDecimal retailRadio = new BigDecimal("0");
  1518. if (esmRetailList != null && !esmRetailList.isEmpty()) {
  1519. EsmRetail esmRetail = esmRetailList.get(0);
  1520. if (esmRetail != null) {
  1521. BigDecimal sumPremium = externalOrderFeeVo.getJqPremium().add(externalOrderFeeVo.getSyPremium()).add(externalOrderFeeVo.getNoPremium());
  1522. if (Integer.parseInt(esmRetail.getRetailtype()) >= 3) {
  1523. retailRadio = retailRadio.add(new BigDecimal(String.valueOf(esmRetail.getDisrate3()))).setScale(2, BigDecimal.ROUND_DOWN);
  1524. retailFeeLevel3 = feeRuleSchemeService.calcRetail(
  1525. externalOrderFeeVo.getJqPremium(),
  1526. externalOrderFeeVo.getJqRadio(),
  1527. externalOrderFeeVo.getSyPremium(),
  1528. externalOrderFeeVo.getSyRadio(),
  1529. externalOrderFeeVo.getNoPremium(),
  1530. externalOrderFeeVo.getNoRadio(),
  1531. retailProportion.getJqRetailLevel3Proportion(),
  1532. retailProportion.getSyRetailLevel3Proportion(),
  1533. retailProportion.getNoRetailLevel3Proportion());
  1534. //三级分销费用 retailFeeLevel3.getTotalRetailPremiums()
  1535. } else {
  1536. //三级分销费用为 空值0
  1537. }
  1538. if (Integer.parseInt(esmRetail.getRetailtype()) >= 2) {
  1539. retailRadio = retailRadio.add(new BigDecimal(String.valueOf(esmRetail.getDisrate2()))).setScale(2, BigDecimal.ROUND_DOWN);
  1540. retailFeeLevel2 = feeRuleSchemeService.calcRetail(
  1541. externalOrderFeeVo.getJqPremium(),
  1542. externalOrderFeeVo.getJqRadio(),
  1543. externalOrderFeeVo.getSyPremium(),
  1544. externalOrderFeeVo.getSyRadio(),
  1545. externalOrderFeeVo.getNoPremium(),
  1546. externalOrderFeeVo.getNoRadio(),
  1547. retailProportion.getJqRetailLevel2Proportion(),
  1548. retailProportion.getSyRetailLevel2Proportion(),
  1549. retailProportion.getNoRetailLevel2Proportion());
  1550. //二级分销费用 retailFeeLevel2.getTotalRetailPremiums()
  1551. } else {
  1552. // 空的
  1553. }
  1554. if (Integer.parseInt(esmRetail.getRetailtype()) >= 1) {
  1555. retailRadio = retailRadio.add(new BigDecimal(String.valueOf(esmRetail.getDisrate1()))).setScale(2, BigDecimal.ROUND_DOWN);
  1556. retailFeeLevel1 = feeRuleSchemeService.calcRetail(
  1557. externalOrderFeeVo.getJqPremium(),
  1558. externalOrderFeeVo.getJqRadio(),
  1559. externalOrderFeeVo.getSyPremium(),
  1560. externalOrderFeeVo.getSyRadio(),
  1561. externalOrderFeeVo.getNoPremium(),
  1562. externalOrderFeeVo.getNoRadio(),
  1563. retailProportion.getJqRetailLevel1Proportion(),
  1564. retailProportion.getSyRetailLevel1Proportion(),
  1565. retailProportion.getNoRetailLevel1Proportion());
  1566. //一级 retailFeeLevel1.getTotalRetailPremiums()
  1567. } else {
  1568. // 空的
  1569. }
  1570. } else {
  1571. //null
  1572. }
  1573. } else {
  1574. // null
  1575. }
  1576. //endregion
  1577. //region 设置机构管理费
  1578. //交强机构管理费
  1579. BigDecimal jqDeptRadio =
  1580. ptlAgreementProductCostsExport.getJqExportRadioLevel1().add(ptlAgreementProductCostsExport.getJqExportRadioLevel2()).add(ptlAgreementProductCostsExport.getJqExportRadioLevel3()).add(ptlAgreementProductCostsExport.getJqExportRadioLevel4()).add(ptlAgreementProductCostsExport.getJqExportRadioLevel5());
  1581. FeeOrderNewVo.DeptManagerFee jqDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(externalOrderFeeVo.getJqPremium(),
  1582. ptlAgreementProductCostsExport.getJqExportRadioLevel1(), ptlAgreementProductCostsExport.getJqExportRadioLevel2(),
  1583. ptlAgreementProductCostsExport.getJqExportRadioLevel3(), ptlAgreementProductCostsExport.getJqExportRadioLevel4(),
  1584. ptlAgreementProductCostsExport.getJqExportRadioLevel5());
  1585. BigDecimal syDeptRadio =
  1586. ptlAgreementProductCostsExport.getSyExportRadioLevel1().add(ptlAgreementProductCostsExport.getSyExportRadioLevel2()).add(ptlAgreementProductCostsExport.getSyExportRadioLevel3()).add(ptlAgreementProductCostsExport.getSyExportRadioLevel4()).add(ptlAgreementProductCostsExport.getSyExportRadioLevel5());
  1587. FeeOrderNewVo.DeptManagerFee syDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(externalOrderFeeVo.getSyPremium(),
  1588. ptlAgreementProductCostsExport.getSyExportRadioLevel1(), ptlAgreementProductCostsExport.getSyExportRadioLevel2(),
  1589. ptlAgreementProductCostsExport.getSyExportRadioLevel3(), ptlAgreementProductCostsExport.getSyExportRadioLevel4(),
  1590. ptlAgreementProductCostsExport.getSyExportRadioLevel5());
  1591. BigDecimal noDeptRadio =
  1592. ptlAgreementProductCostsExport.getNoCarExportRadioLevel1().add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel2()).add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel3()).add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel4()).add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel5());
  1593. FeeOrderNewVo.DeptManagerFee noDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(externalOrderFeeVo.getNoPremium(),
  1594. ptlAgreementProductCostsExport.getNoCarExportRadioLevel1(), ptlAgreementProductCostsExport.getNoCarExportRadioLevel2(),
  1595. ptlAgreementProductCostsExport.getNoCarExportRadioLevel3(), ptlAgreementProductCostsExport.getNoCarExportRadioLevel4(),
  1596. ptlAgreementProductCostsExport.getNoCarExportRadioLevel5());
  1597. //endregion
  1598. //region 出口费用
  1599. //交强出口手续费比例
  1600. FeeOrderNewVo.ExportFee jqExportFee = feeRuleSchemeService.calcExportFee(
  1601. externalOrderFeeVo.getJqPremium(),
  1602. new BigDecimal(ptlAgreementProductCostsNew.getJqCostsExportProportion()),
  1603. externalOrderFeeVo.getJqRadio(),
  1604. jqDeptRadio,
  1605. retailRadio,
  1606. taxRadio,
  1607. jqReCalcuLateProportion.getProxyProportion());
  1608. //商业出口手续费比例
  1609. FeeOrderNewVo.ExportFee syExportFee = feeRuleSchemeService.calcExportFee(
  1610. externalOrderFeeVo.getSyPremium(),
  1611. new BigDecimal(ptlAgreementProductCostsNew.getSyCostsExportProportion()),
  1612. externalOrderFeeVo.getSyRadio(),
  1613. syDeptRadio,
  1614. retailRadio,
  1615. taxRadio,
  1616. syReCalcuLateProportion.getProxyProportion());
  1617. //非车出口手续费比例
  1618. FeeOrderNewVo.ExportFee noExportFee = feeRuleSchemeService.calcExportFee(
  1619. externalOrderFeeVo.getNoPremium(),
  1620. new BigDecimal(ptlAgreementProductCostsNew.getNoCostsExportProportion()),
  1621. externalOrderFeeVo.getNoRadio(),
  1622. noDeptRadio,
  1623. retailRadio,
  1624. taxRadio,
  1625. noReCalcuLateProportion.getProxyProportion());
  1626. externalOrderFeeVo.setJqExportPremium(jqExportFee.getTotalAmount());
  1627. externalOrderFeeVo.setJqExportRadio(jqExportFee.getTotalProportion());
  1628. externalOrderFeeVo.setSyExportPremium(syExportFee.getTotalAmount());
  1629. externalOrderFeeVo.setSyExportRadio(syExportFee.getTotalProportion());
  1630. externalOrderFeeVo.setNoExportPremium(noExportFee.getTotalAmount());
  1631. externalOrderFeeVo.setNoExportRadio(noExportFee.getTotalProportion());
  1632. //endregion
  1633. return externalOrderFeeVo;
  1634. }
  1635. @Override
  1636. public void calcCostsExternalTest(PtlAgreementProductCostsNew ptlAgreementProductCostsNew, InsAreaCompany insAreaCompany) {
  1637. //获取协议信息
  1638. // 外部订单比例
  1639. PtlAgreement ptlAgreement = ptlAgreementService.getById(insAreaCompany.getAgreementId());
  1640. InsOrders insOrders = insOrdersService.getById(insAreaCompany.getOrderno());
  1641. SysUser sysUser = sysUserService.findByUserId(insOrders.getUserid());
  1642. BigDecimal enterProportion = sysSwitchConfigService.getEnterProportion(insOrders.getDeptid(), insOrders.getEntryStatus());
  1643. BigDecimal taxRadio = new BigDecimal("1.00");
  1644. //如果是外部订单则 不含税
  1645. if (ptlAgreement.getWithTax().equals("否")) {
  1646. taxRadio = new BigDecimal("1.06");
  1647. }
  1648. //税比例 固定1.06
  1649. //查找入口与出口费用比例
  1650. //出口配置
  1651. PtlAgreementProductCostsExport ptlAgreementProductCostsExport =
  1652. ptlAgreementProductCostsExportService.getOne(new LambdaQueryWrapper<PtlAgreementProductCostsExport>().eq(PtlAgreementProductCostsExport::getCostsId, ptlAgreementProductCostsNew.getId()));
  1653. InsFeeOrderNew insFeeOrderNew = new InsFeeOrderNew();
  1654. insFeeOrderNew.setId(IdGenerate.nextId());
  1655. insFeeOrderNew.setCostsId(ptlAgreementProductCostsNew.getId());
  1656. insFeeOrderNew.setAgreementId(insAreaCompany.getAgreementId());
  1657. //存储部门id与用户id
  1658. InsOrders order = insOrdersService.getById(insAreaCompany.getOrderno());
  1659. InsFeeOrderNew insFeeOrderNewByCompanyId = insFeeOrderNewService.getInsFeeOrderNewByCompanyId(insAreaCompany.getId());
  1660. if (insFeeOrderNewByCompanyId != null) {
  1661. insFeeOrderNew.setId(insFeeOrderNewByCompanyId.getId());
  1662. }
  1663. insFeeOrderNew.setDeptId(order.getDeptid());
  1664. insFeeOrderNew.setUserId(order.getUserid());
  1665. insFeeOrderNew.setInsOrderNo(insAreaCompany.getId());
  1666. insFeeOrderNew.setJqPremium(insAreaCompany.getJqpremium());
  1667. insFeeOrderNew.setSyPremium(insAreaCompany.getSypremium());
  1668. insFeeOrderNew.setNoPremium(insAreaCompany.getJypremium());
  1669. //不含税
  1670. BigDecimal bigDecimal = new BigDecimal("1.06");
  1671. insFeeOrderNew.setJqNoTaxPremium(insAreaCompany.getJqpremium().divide(bigDecimal, 2));
  1672. insFeeOrderNew.setSyNoTaxPremium(insAreaCompany.getSypremium().divide(bigDecimal, 2));
  1673. insFeeOrderNew.setNoNoTaxPremium(insAreaCompany.getJypremium().divide(bigDecimal, 2));
  1674. //region 计算入口费用
  1675. //交强入口信息
  1676. FeeOrderNewVo.EntranceFee jqEntranceFee = feeRuleSchemeService.calcEntranceFee(insFeeOrderNew.getJqPremium(),
  1677. new BigDecimal(ptlAgreementProductCostsNew.getJqCarCostsProportion()),
  1678. new BigDecimal(ptlAgreementProductCostsNew.getJqCarOtherCostsProportion()), taxRadio);
  1679. insFeeOrderNew.setJqCostsProportion(jqEntranceFee.getTotalProportion());
  1680. insFeeOrderNew.setJqSuperviseCostsProportion(jqEntranceFee.getSuperviseCosts());
  1681. insFeeOrderNew.setJqSuperviseCostsPremiums(jqEntranceFee.getSuperviseCostsPremiums());
  1682. insFeeOrderNew.setJqOtherCostsProportion(jqEntranceFee.getOtherCostsProportion());
  1683. insFeeOrderNew.setJqOtherCostsPremiums(jqEntranceFee.getOtherCostsPremiums());
  1684. insFeeOrderNew.setJqCostsPremiums(insFeeOrderNew.getJqSuperviseCostsPremiums().add(insFeeOrderNew.getJqOtherCostsPremiums()));
  1685. //商业入口信息
  1686. FeeOrderNewVo.EntranceFee syEntranceFee = feeRuleSchemeService.calcEntranceFee(insFeeOrderNew.getSyPremium(),
  1687. new BigDecimal(ptlAgreementProductCostsNew.getSyCarCostsProportion()),
  1688. new BigDecimal(ptlAgreementProductCostsNew.getSyCarOtherCostsProportion()), taxRadio);
  1689. insFeeOrderNew.setSyCostsProportion(syEntranceFee.getTotalProportion());
  1690. insFeeOrderNew.setSySuperviseCostsProportion(syEntranceFee.getSuperviseCosts());
  1691. insFeeOrderNew.setSySuperviseCostsPremiums(syEntranceFee.getSuperviseCostsPremiums());
  1692. insFeeOrderNew.setSyOtherCostsProportion(syEntranceFee.getOtherCostsProportion());
  1693. insFeeOrderNew.setSyOtherCostsPremiums(syEntranceFee.getOtherCostsPremiums());
  1694. insFeeOrderNew.setSyCostsPremiums(insFeeOrderNew.getSySuperviseCostsPremiums().add(insFeeOrderNew.getSyOtherCostsPremiums()));
  1695. //非车入口信息
  1696. FeeOrderNewVo.EntranceFee noEntranceFee = feeRuleSchemeService.calcEntranceFee(insFeeOrderNew.getNoPremium(),
  1697. new BigDecimal(ptlAgreementProductCostsNew.getNoCarCostsProportion()),
  1698. new BigDecimal(ptlAgreementProductCostsNew.getNoCarOtherCostsProportion()), taxRadio);
  1699. insFeeOrderNew.setNoCostsProportion(noEntranceFee.getTotalProportion());
  1700. insFeeOrderNew.setNoSuperviseCostsProportion(noEntranceFee.getSuperviseCosts());
  1701. insFeeOrderNew.setNoSuperviseCostsPremiums(noEntranceFee.getSuperviseCostsPremiums());
  1702. insFeeOrderNew.setNoOtherCostsProportion(noEntranceFee.getOtherCostsProportion());
  1703. insFeeOrderNew.setNoOtherCostsPremiums(noEntranceFee.getOtherCostsPremiums());
  1704. insFeeOrderNew.setNoCostsPremiums(insFeeOrderNew.getNoSuperviseCostsPremiums().add(insFeeOrderNew.getNoOtherCostsPremiums()));
  1705. //endregion
  1706. //region 重新计算管理费比例和分销比例
  1707. List<EsmRetail> esmRetailList = esmRetailService.selectList(" where t.deptid=? and t.status = '1' ",
  1708. new Object[]{sysUser.getDeptId()});
  1709. Integer retailLevel = 0;
  1710. //默认分销比例设置
  1711. RetailProportion retailProportion = new RetailProportion();
  1712. if (!Objects.isNull(esmRetailList) && !esmRetailList.isEmpty()) {
  1713. retailLevel = Integer.parseInt(esmRetailList.get(0).getRetailtype());
  1714. //赋值默认的分销比例
  1715. retailProportion.setProportion(esmRetailList.get(0).getDisrate1(), esmRetailList.get(0).getDisrate2(), esmRetailList.get(0).getDisrate3());
  1716. }
  1717. //获取交强机构管理费总比例
  1718. BigDecimal jqDeptProportion = ptlAgreementProductCostsExport.getJqExportRadioLevel1()
  1719. .add(ptlAgreementProductCostsExport.getJqExportRadioLevel2())
  1720. .add(ptlAgreementProductCostsExport.getJqExportRadioLevel3())
  1721. .add(ptlAgreementProductCostsExport.getJqExportRadioLevel4())
  1722. .add(ptlAgreementProductCostsExport.getJqExportRadioLevel5());
  1723. //获取商业机构管理费总比例
  1724. BigDecimal syDeptProportion = ptlAgreementProductCostsExport.getSyExportRadioLevel1()
  1725. .add(ptlAgreementProductCostsExport.getSyExportRadioLevel2())
  1726. .add(ptlAgreementProductCostsExport.getSyExportRadioLevel3())
  1727. .add(ptlAgreementProductCostsExport.getSyExportRadioLevel4())
  1728. .add(ptlAgreementProductCostsExport.getSyExportRadioLevel5());
  1729. //获取非车机构管理费总比例
  1730. BigDecimal noDeptProportion = ptlAgreementProductCostsExport.getNoCarExportRadioLevel1()
  1731. .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel2())
  1732. .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel3())
  1733. .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel4())
  1734. .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel5());
  1735. //获取交强分销总比例
  1736. BigDecimal jqRetailProportion = retailProportion.getJqRetailLevel1Proportion()
  1737. .add(retailProportion.getJqRetailLevel2Proportion())
  1738. .add(retailProportion.getJqRetailLevel3Proportion());
  1739. //获取商业分销总比例
  1740. BigDecimal syRetailProportion = retailProportion.getSyRetailLevel1Proportion()
  1741. .add(retailProportion.getSyRetailLevel2Proportion())
  1742. .add(retailProportion.getSyRetailLevel3Proportion());
  1743. //获取非车分销总比例
  1744. BigDecimal noRetailProportion = retailProportion.getNoRetailLevel1Proportion()
  1745. .add(retailProportion.getNoRetailLevel2Proportion())
  1746. .add(retailProportion.getNoRetailLevel3Proportion());
  1747. //重新计算比例 入口是否超出支付的比例
  1748. ReCalcuLateProportion jqReCalcuLateProportion = recalculateProportion(
  1749. new BigDecimal(ptlAgreementProductCostsNew.getJqCostsProportion()),
  1750. jqDeptProportion,
  1751. jqRetailProportion,
  1752. taxRadio,
  1753. retailLevel,
  1754. ptlAgreementProductCostsExport,
  1755. retailProportion,
  1756. "jq",
  1757. enterProportion
  1758. );
  1759. ReCalcuLateProportion syReCalcuLateProportion = recalculateProportion(
  1760. new BigDecimal(ptlAgreementProductCostsNew.getSyCostsProportion()),
  1761. syDeptProportion,
  1762. syRetailProportion,
  1763. taxRadio,
  1764. retailLevel,
  1765. ptlAgreementProductCostsExport,
  1766. retailProportion,
  1767. "sy",
  1768. enterProportion
  1769. );
  1770. ReCalcuLateProportion noReCalcuLateProportion = recalculateProportion(
  1771. new BigDecimal(ptlAgreementProductCostsNew.getNoCostsProportion()),
  1772. noDeptProportion,
  1773. noRetailProportion,
  1774. taxRadio,
  1775. retailLevel,
  1776. ptlAgreementProductCostsExport,
  1777. retailProportion,
  1778. "no",
  1779. enterProportion
  1780. );
  1781. retailProportion.setProportion(jqReCalcuLateProportion, syReCalcuLateProportion, noReCalcuLateProportion);
  1782. // ptlAgreementProductCostsExportService.updateById(ptlAgreementProductCostsExport);
  1783. //endregion
  1784. //region 计算分销费用
  1785. //分销总比例
  1786. BigDecimal jqRetailRadio = new BigDecimal("0");
  1787. BigDecimal syRetailRadio = new BigDecimal("0");
  1788. BigDecimal noRetailRadio = new BigDecimal("0");
  1789. FeeOrderNewVo.RetailFee retailFeeLevel3 = new FeeOrderNewVo.RetailFee();
  1790. FeeOrderNewVo.RetailFee retailFeeLevel2 = new FeeOrderNewVo.RetailFee();
  1791. FeeOrderNewVo.RetailFee retailFeeLevel1 = new FeeOrderNewVo.RetailFee();
  1792. //分销总比例
  1793. BigDecimal retailRadio = new BigDecimal("0");
  1794. if (esmRetailList != null && !esmRetailList.isEmpty()) {
  1795. EsmRetail esmRetail = esmRetailList.get(0);
  1796. //分销等级
  1797. insFeeOrderNew.setDistributionStatus(esmRetailList.get(0).getRetailtype());
  1798. //用户分销人员id
  1799. List<EsmUserReferrer> parents = esmUserReferrerService.findParents(sysUser.getId());
  1800. if (esmRetail != null) {
  1801. BigDecimal sumPremium = insFeeOrderNew.getJqPremium().add(insFeeOrderNew.getSyPremium()).add(insFeeOrderNew.getNoPremium());
  1802. if (Integer.parseInt(esmRetail.getRetailtype()) >= 3) {
  1803. insFeeOrderNew.setThirdDetailProportion(new BigDecimal(String.valueOf(esmRetail.getDisrate3())));
  1804. retailRadio = retailRadio.add(insFeeOrderNew.getThirdDetailProportion()).setScale(2, BigDecimal.ROUND_DOWN);
  1805. retailFeeLevel3 = feeRuleSchemeService.calcRetail(
  1806. insFeeOrderNew.getJqPremium(),
  1807. insFeeOrderNew.getJqCostsProportion(),
  1808. insFeeOrderNew.getSyPremium(),
  1809. insFeeOrderNew.getSyCostsProportion(),
  1810. insFeeOrderNew.getNoPremium(),
  1811. insFeeOrderNew.getNoCostsProportion(),
  1812. retailProportion.getJqRetailLevel3Proportion(),
  1813. retailProportion.getSyRetailLevel3Proportion(),
  1814. retailProportion.getNoRetailLevel3Proportion());
  1815. insFeeOrderNew.setThirdDetailPremiums(retailFeeLevel3.getTotalRetailPremiums());
  1816. if (parents != null && parents.size() > 2) {
  1817. insFeeOrderNew.setThreeLevelUserId(parents.get(2).getId());
  1818. }
  1819. } else {
  1820. insFeeOrderNew.setThirdDetailProportion(new BigDecimal(0));
  1821. }
  1822. if (Integer.parseInt(esmRetail.getRetailtype()) >= 2) {
  1823. insFeeOrderNew.setSecondDetailProportion(new BigDecimal(String.valueOf(esmRetail.getDisrate2())));
  1824. retailRadio = retailRadio.add(insFeeOrderNew.getSecondDetailProportion()).setScale(2, BigDecimal.ROUND_DOWN);
  1825. retailFeeLevel2 = feeRuleSchemeService.calcRetail(insFeeOrderNew.getJqPremium(),
  1826. insFeeOrderNew.getJqCostsProportion(),
  1827. insFeeOrderNew.getSyPremium(),
  1828. insFeeOrderNew.getSyCostsProportion(),
  1829. insFeeOrderNew.getNoPremium(),
  1830. insFeeOrderNew.getNoCostsProportion(),
  1831. retailProportion.getJqRetailLevel2Proportion(),
  1832. retailProportion.getSyRetailLevel2Proportion(),
  1833. retailProportion.getNoRetailLevel2Proportion());
  1834. insFeeOrderNew.setSecondDetailPremiums(retailFeeLevel2.getTotalRetailPremiums());
  1835. if (parents != null && parents.size() > 1) {
  1836. insFeeOrderNew.setTwoLevelUserId(parents.get(1).getId());
  1837. }
  1838. } else {
  1839. insFeeOrderNew.setSecondDetailProportion(new BigDecimal(0));
  1840. }
  1841. if (Integer.parseInt(esmRetail.getRetailtype()) >= 1) {
  1842. insFeeOrderNew.setFirstDetailProportion(new BigDecimal(String.valueOf(esmRetail.getDisrate1())));
  1843. retailRadio = retailRadio.add(insFeeOrderNew.getFirstDetailProportion()).setScale(2, BigDecimal.ROUND_DOWN);
  1844. retailFeeLevel1 = feeRuleSchemeService.calcRetail(insFeeOrderNew.getJqPremium(),
  1845. insFeeOrderNew.getJqCostsProportion(),
  1846. insFeeOrderNew.getSyPremium(),
  1847. insFeeOrderNew.getSyCostsProportion(),
  1848. insFeeOrderNew.getNoPremium(),
  1849. insFeeOrderNew.getNoCostsProportion(),
  1850. retailProportion.getJqRetailLevel1Proportion(),
  1851. retailProportion.getSyRetailLevel1Proportion(),
  1852. retailProportion.getNoRetailLevel1Proportion());
  1853. insFeeOrderNew.setFirstDetailPremiums(retailFeeLevel1.getTotalRetailPremiums());
  1854. if (parents != null && !parents.isEmpty()) {
  1855. insFeeOrderNew.setFirstLevelUserId(parents.get(0).getId());
  1856. }
  1857. } else {
  1858. insFeeOrderNew.setFirstDetailProportion(new BigDecimal(0));
  1859. }
  1860. } else {
  1861. insFeeOrderNew.setFirstDetailPremiums(new BigDecimal(0));
  1862. insFeeOrderNew.setSecondDetailPremiums(new BigDecimal(0));
  1863. insFeeOrderNew.setThirdDetailPremiums(new BigDecimal(0));
  1864. }
  1865. } else {
  1866. insFeeOrderNew.setFirstDetailProportion(new BigDecimal(0));
  1867. insFeeOrderNew.setSecondDetailProportion(new BigDecimal(0));
  1868. insFeeOrderNew.setThirdDetailProportion(new BigDecimal(0));
  1869. }
  1870. insFeeOrderNew.assignRetail(retailFeeLevel1, retailFeeLevel2, retailFeeLevel3);
  1871. //endregion
  1872. //region 设置机构管理费
  1873. //交强机构管理费
  1874. BigDecimal jqDeptRadio =
  1875. ptlAgreementProductCostsExport.getJqExportRadioLevel1().add(ptlAgreementProductCostsExport.getJqExportRadioLevel2()).add(ptlAgreementProductCostsExport.getJqExportRadioLevel3()).add(ptlAgreementProductCostsExport.getJqExportRadioLevel4()).add(ptlAgreementProductCostsExport.getJqExportRadioLevel5());
  1876. FeeOrderNewVo.DeptManagerFee jqDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(insFeeOrderNew.getJqPremium(),
  1877. ptlAgreementProductCostsExport.getJqExportRadioLevel1(), ptlAgreementProductCostsExport.getJqExportRadioLevel2(),
  1878. ptlAgreementProductCostsExport.getJqExportRadioLevel3(), ptlAgreementProductCostsExport.getJqExportRadioLevel4(),
  1879. ptlAgreementProductCostsExport.getJqExportRadioLevel5());
  1880. insFeeOrderNew.setJqDeptProportionLevel1(jqDeptManagerFee.getDeptProportionLevelOne());
  1881. insFeeOrderNew.setJqDeptPremiumsLevel1(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelOne()));
  1882. insFeeOrderNew.setJqDeptProportionLevel2(jqDeptManagerFee.getDeptProportionLevelTwo());
  1883. insFeeOrderNew.setJqDeptPremiumsLevel2(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelTwo()));
  1884. insFeeOrderNew.setJqDeptProportionLevel3(jqDeptManagerFee.getDeptProportionLevelThree());
  1885. insFeeOrderNew.setJqDeptPremiumsLevel3(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelThree()));
  1886. insFeeOrderNew.setJqDeptProportionLevel4(jqDeptManagerFee.getDeptProportionLevelFoure());
  1887. insFeeOrderNew.setJqDeptPremiumsLevel4(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelFoure()));
  1888. insFeeOrderNew.setJqDeptProportionLevel5(jqDeptManagerFee.getDeptProportionLevelFive());
  1889. insFeeOrderNew.setJqDeptPremiumsLevel5(twoPeople(jqDeptManagerFee.getDeptPremiumsLevelFive()));
  1890. BigDecimal syDeptRadio =
  1891. ptlAgreementProductCostsExport.getSyExportRadioLevel1().add(ptlAgreementProductCostsExport.getSyExportRadioLevel2()).add(ptlAgreementProductCostsExport.getSyExportRadioLevel3()).add(ptlAgreementProductCostsExport.getSyExportRadioLevel4()).add(ptlAgreementProductCostsExport.getSyExportRadioLevel5());
  1892. FeeOrderNewVo.DeptManagerFee syDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(insFeeOrderNew.getSyPremium(),
  1893. ptlAgreementProductCostsExport.getSyExportRadioLevel1(), ptlAgreementProductCostsExport.getSyExportRadioLevel2(),
  1894. ptlAgreementProductCostsExport.getSyExportRadioLevel3(), ptlAgreementProductCostsExport.getSyExportRadioLevel4(),
  1895. ptlAgreementProductCostsExport.getSyExportRadioLevel5());
  1896. insFeeOrderNew.setSyDeptProportionLevel1(syDeptManagerFee.getDeptProportionLevelOne());
  1897. insFeeOrderNew.setSyDeptPremiumsLevel1(twoPeople(syDeptManagerFee.getDeptPremiumsLevelOne()));
  1898. insFeeOrderNew.setSyDeptProportionLevel2(syDeptManagerFee.getDeptProportionLevelTwo());
  1899. insFeeOrderNew.setSyDeptPremiumsLevel2(twoPeople(syDeptManagerFee.getDeptPremiumsLevelTwo()));
  1900. insFeeOrderNew.setSyDeptProportionLevel3(syDeptManagerFee.getDeptProportionLevelThree());
  1901. insFeeOrderNew.setSyDeptPremiumsLevel3(twoPeople(syDeptManagerFee.getDeptPremiumsLevelThree()));
  1902. insFeeOrderNew.setSyDeptProportionLevel4(syDeptManagerFee.getDeptProportionLevelFoure());
  1903. insFeeOrderNew.setSyDeptPremiumsLevel4(twoPeople(syDeptManagerFee.getDeptPremiumsLevelFoure()));
  1904. insFeeOrderNew.setSyDeptProportionLevel5(syDeptManagerFee.getDeptProportionLevelFive());
  1905. insFeeOrderNew.setSyDeptPremiumsLevel5(twoPeople(syDeptManagerFee.getDeptPremiumsLevelFive()));
  1906. BigDecimal noDeptRadio =
  1907. ptlAgreementProductCostsExport.getNoCarExportRadioLevel1().add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel2()).add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel3()).add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel4()).add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel5());
  1908. FeeOrderNewVo.DeptManagerFee noDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(insFeeOrderNew.getNoPremium(),
  1909. ptlAgreementProductCostsExport.getNoCarExportRadioLevel1(), ptlAgreementProductCostsExport.getNoCarExportRadioLevel2(),
  1910. ptlAgreementProductCostsExport.getNoCarExportRadioLevel3(), ptlAgreementProductCostsExport.getNoCarExportRadioLevel4(),
  1911. ptlAgreementProductCostsExport.getNoCarExportRadioLevel5());
  1912. insFeeOrderNew.setNoDeptProportionLevel1(noDeptManagerFee.getDeptProportionLevelOne());
  1913. insFeeOrderNew.setNoDeptPremiumsLevel1(twoPeople(noDeptManagerFee.getDeptPremiumsLevelOne()));
  1914. insFeeOrderNew.setNoDeptProportionLevel2(noDeptManagerFee.getDeptProportionLevelTwo());
  1915. insFeeOrderNew.setNoDeptPremiumsLevel2(twoPeople(noDeptManagerFee.getDeptPremiumsLevelTwo()));
  1916. insFeeOrderNew.setNoDeptProportionLevel3(noDeptManagerFee.getDeptProportionLevelThree());
  1917. insFeeOrderNew.setNoDeptPremiumsLevel3(twoPeople(noDeptManagerFee.getDeptPremiumsLevelThree()));
  1918. insFeeOrderNew.setNoDeptProportionLevel4(noDeptManagerFee.getDeptProportionLevelFoure());
  1919. insFeeOrderNew.setNoDeptPremiumsLevel4(twoPeople(noDeptManagerFee.getDeptPremiumsLevelFoure()));
  1920. insFeeOrderNew.setNoDeptProportionLevel5(noDeptManagerFee.getDeptProportionLevelFive());
  1921. insFeeOrderNew.setNoDeptPremiumsLevel5(twoPeople(noDeptManagerFee.getDeptPremiumsLevelFive()));
  1922. //endregion
  1923. //region 出口费用
  1924. //交强出口手续费比例
  1925. FeeOrderNewVo.ExportFee jqExportFee = feeRuleSchemeService.calcExportFee(insFeeOrderNew.getJqPremium(), new BigDecimal(ptlAgreementProductCostsNew.getJqCostsExportProportion()),
  1926. insFeeOrderNew.getJqCostsProportion(), jqDeptRadio, retailRadio, taxRadio, jqReCalcuLateProportion.getProxyProportion());
  1927. //商业出口手续费比例
  1928. FeeOrderNewVo.ExportFee syExportFee = feeRuleSchemeService.calcExportFee(insFeeOrderNew.getSyPremium(), new BigDecimal(ptlAgreementProductCostsNew.getSyCostsExportProportion()),
  1929. insFeeOrderNew.getSyCostsProportion(), syDeptRadio, retailRadio, taxRadio, syReCalcuLateProportion.getProxyProportion());
  1930. //非车出口手续费比例
  1931. FeeOrderNewVo.ExportFee noExportFee = feeRuleSchemeService.calcExportFee(insFeeOrderNew.getNoPremium(), new BigDecimal(ptlAgreementProductCostsNew.getNoCostsExportProportion()),
  1932. insFeeOrderNew.getNoCostsProportion(), noDeptRadio, retailRadio, taxRadio, noReCalcuLateProportion.getProxyProportion());
  1933. //出口手续费用
  1934. insFeeOrderNew.setJqExportSuperviseCostsPremiums(twoPeople(jqExportFee.getSuperviseCostsPremiums()));
  1935. insFeeOrderNew.setSyExportSuperviseCostsPremiums(twoPeople(syExportFee.getSuperviseCostsPremiums()));
  1936. insFeeOrderNew.setNoExportSuperviseCostsPremiums(twoPeople(noExportFee.getSuperviseCostsPremiums()));
  1937. //出口其他费用比例
  1938. insFeeOrderNew.setJqExportOtherCostsProportion(twoPeople(jqExportFee.getOtherCostsProportion()));
  1939. insFeeOrderNew.setSyExportOtherCostsProportion(twoPeople(syExportFee.getOtherCostsProportion()));
  1940. insFeeOrderNew.setNoExportOtherCostsProportion(twoPeople(noExportFee.getOtherCostsProportion()));
  1941. //出口其他费用
  1942. insFeeOrderNew.setJqExportOtherCostsPremiums(twoPeople(jqExportFee.getOtherCostsPremiums()));
  1943. insFeeOrderNew.setSyExportOtherCostsPremiums(twoPeople(syExportFee.getOtherCostsPremiums()));
  1944. insFeeOrderNew.setNoExportOtherCostsPremiums(twoPeople(noExportFee.getOtherCostsPremiums()));
  1945. //设置出口手续费比例
  1946. insFeeOrderNew.setJqCostsExportProportion(twoPeople(jqExportFee.getSuperviseCosts()));
  1947. insFeeOrderNew.setSyCostsExportProportion(twoPeople(syExportFee.getSuperviseCosts()));
  1948. insFeeOrderNew.setNoCostsExportProportion(twoPeople(noExportFee.getSuperviseCosts()));
  1949. // 外部订单费用
  1950. insFeeOrderNew.setJqExternalProportion(jqExportFee.getExternalProportion());
  1951. insFeeOrderNew.setJqExternalPremiums(jqExportFee.getExternalPremiums());
  1952. insFeeOrderNew.setSyExternalProportion(syExportFee.getExternalProportion());
  1953. insFeeOrderNew.setSyExternalPremiums(syExportFee.getExternalPremiums());
  1954. insFeeOrderNew.setNoExternalProportion(noExportFee.getExternalProportion());
  1955. insFeeOrderNew.setNoExternalPremiums(noExportFee.getExternalPremiums());
  1956. //endregion
  1957. //region 计算利润差值
  1958. //入口 - 出口 - 机构管理费 1-5级 - 分销费 = 差值
  1959. //分销交强费用
  1960. //分开算 1 2 3 级
  1961. BigDecimal jqFirst = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getFirstDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  1962. BigDecimal jqSecond = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getSecondDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  1963. BigDecimal jqThird = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getThirdDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  1964. BigDecimal jqFenXiao = jqFirst.add(jqSecond).add(jqThird);
  1965. //分销商业费用
  1966. BigDecimal syFirst = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getFirstDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  1967. BigDecimal sySecond = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getSecondDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  1968. BigDecimal syThird = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getThirdDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  1969. BigDecimal syFenXiao = syFirst.add(sySecond).add(syThird);
  1970. //分销非车费用
  1971. BigDecimal noFirst = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getFirstDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  1972. BigDecimal noSecond = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getSecondDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  1973. BigDecimal noThird = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getThirdDetailProportion().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  1974. BigDecimal noFenXiao = noFirst.add(noSecond).add(noThird);
  1975. BigDecimal jqDifference = jqEntranceFee.getTotalAmount()
  1976. .subtract(jqExportFee.getExternalPremiums())
  1977. .subtract(
  1978. (jqExportFee.getSuperviseCostsPremiums().add(jqExportFee.getOtherCostsPremiums())))
  1979. .subtract(
  1980. (jqDeptManagerFee.getDeptPremiumsLevelOne().add(jqDeptManagerFee.getDeptPremiumsLevelTwo().add(jqDeptManagerFee.getDeptPremiumsLevelThree()).add(jqDeptManagerFee.getDeptPremiumsLevelFoure()).add(jqDeptManagerFee.getDeptPremiumsLevelFive())))
  1981. )
  1982. .subtract(jqFenXiao).setScale(5, BigDecimal.ROUND_HALF_DOWN);
  1983. insFeeOrderNew.setJqProfitMarginPremiums(jqDifference);
  1984. BigDecimal syDifference = syEntranceFee.getTotalAmount()
  1985. .subtract(syExportFee.getExternalPremiums())
  1986. .subtract(
  1987. (syExportFee.getSuperviseCostsPremiums().add(syExportFee.getOtherCostsPremiums())))
  1988. .subtract(
  1989. (syDeptManagerFee.getDeptPremiumsLevelOne().add(syDeptManagerFee.getDeptPremiumsLevelTwo().add(syDeptManagerFee.getDeptPremiumsLevelThree()).add(syDeptManagerFee.getDeptPremiumsLevelFoure()).add(syDeptManagerFee.getDeptPremiumsLevelFive())))
  1990. )
  1991. .subtract(syFenXiao).setScale(5, BigDecimal.ROUND_HALF_DOWN);
  1992. insFeeOrderNew.setSyProfitMarginPremiums(syDifference);
  1993. BigDecimal noDifference = noEntranceFee.getTotalAmount()
  1994. .subtract(noExportFee.getExternalPremiums())
  1995. .subtract(
  1996. (noExportFee.getSuperviseCostsPremiums().add(noExportFee.getOtherCostsPremiums())))
  1997. .subtract(
  1998. (noDeptManagerFee.getDeptPremiumsLevelOne().add(noDeptManagerFee.getDeptPremiumsLevelTwo().add(noDeptManagerFee.getDeptPremiumsLevelThree()).add(noDeptManagerFee.getDeptPremiumsLevelFoure()).add(noDeptManagerFee.getDeptPremiumsLevelFive())))
  1999. )
  2000. .subtract(noFenXiao).setScale(5, BigDecimal.ROUND_HALF_DOWN);
  2001. insFeeOrderNew.setNoProfitMarginPremiums(noDifference);
  2002. //endregion
  2003. //region 比例逆推是否等于0
  2004. if (!feeRuleSchemeService.calculateProportion(jqEntranceFee, jqDeptManagerFee, jqExportFee, retailRadio, taxRadio, insFeeOrderNew.getJqPremium()))
  2005. throw new SystemException("交强比例异常");
  2006. if (!feeRuleSchemeService.calculateProportion(syEntranceFee, syDeptManagerFee, syExportFee, retailRadio, taxRadio, insFeeOrderNew.getSyPremium()))
  2007. throw new SystemException("商业比例异常");
  2008. if (!feeRuleSchemeService.calculateProportion(noEntranceFee, noDeptManagerFee, noExportFee, retailRadio, taxRadio, insFeeOrderNew.getNoPremium()))
  2009. throw new SystemException("非车比例异常");
  2010. //endregion
  2011. insFeeOrderNewService.saveOrUpdate(insFeeOrderNew);
  2012. }
  2013. @Override
  2014. public void calcCostsExternalTelemarketing(PtlAgreementProductCostsExport ptlAgreementProductCostsExport, InsAreaCompany insAreaCompany) {
  2015. //获取协议信息
  2016. PtlAgreement ptlAgreement = ptlAgreementService.getById(insAreaCompany.getAgreementId());
  2017. InsOrders insOrders = insOrdersService.getById(insAreaCompany.getOrderno());
  2018. SysUser sysUser = sysUserService.findByUserId(insOrders.getUserid());
  2019. //入口配置
  2020. PtlAgreementProductCostsNew ptlAgreementProductCostsNew = ptlAgreementProductCostsNewService.getById(ptlAgreementProductCostsExport.getCostsId());
  2021. ptlAgreementProductCostsNew.blank();
  2022. BigDecimal taxRadio = new BigDecimal("1.00");
  2023. //如果是外部订单则 不含税
  2024. if (ptlAgreement.getWithTax().equals("否") && ptlAgreement.getIsExternal() == 0) {
  2025. taxRadio = new BigDecimal("1.06");
  2026. }
  2027. InsFeeOrderNew insFeeOrderNew = new InsFeeOrderNew();
  2028. insFeeOrderNew.setId(IdGenerate.nextId());
  2029. insFeeOrderNew.setCostsId(ptlAgreementProductCostsNew.getId());
  2030. insFeeOrderNew.setAgreementId(insAreaCompany.getAgreementId());
  2031. //存储部门id与用户id
  2032. InsOrders order = insOrdersService.getById(insAreaCompany.getOrderno());
  2033. InsFeeOrderNew insFeeOrderNewByCompanyId = insFeeOrderNewService.getInsFeeOrderNewByCompanyId(insAreaCompany.getId());
  2034. if (insFeeOrderNewByCompanyId != null) {
  2035. insFeeOrderNew.setId(insFeeOrderNewByCompanyId.getId());
  2036. }
  2037. insFeeOrderNew.setDeptId(order.getDeptid());
  2038. insFeeOrderNew.setUserId(order.getUserid());
  2039. insFeeOrderNew.setInsOrderNo(insAreaCompany.getId());
  2040. insFeeOrderNew.setJqPremium(insAreaCompany.getJqpremium());
  2041. insFeeOrderNew.setSyPremium(insAreaCompany.getSypremium());
  2042. insFeeOrderNew.setNoPremium(insAreaCompany.getJypremium());
  2043. //不含税
  2044. BigDecimal bigDecimal = new BigDecimal("1.06");
  2045. insFeeOrderNew.setJqNoTaxPremium(insAreaCompany.getJqpremium().divide(bigDecimal, 2));
  2046. insFeeOrderNew.setSyNoTaxPremium(insAreaCompany.getSypremium().divide(bigDecimal, 2));
  2047. insFeeOrderNew.setNoNoTaxPremium(insAreaCompany.getJypremium().divide(bigDecimal, 2));
  2048. //region 计算入口费用
  2049. //交强入口信息
  2050. FeeOrderNewVo.EntranceFee jqEntranceFee = feeRuleSchemeService.calcEntranceFee(
  2051. insFeeOrderNew.getJqPremium(),
  2052. new BigDecimal(ptlAgreementProductCostsNew.getJqCarCostsProportion()),
  2053. new BigDecimal(ptlAgreementProductCostsNew.getJqCarOtherCostsProportion()),
  2054. taxRadio);
  2055. insFeeOrderNew.setJqCostsProportion(jqEntranceFee.getTotalProportion());
  2056. insFeeOrderNew.setJqSuperviseCostsProportion(jqEntranceFee.getSuperviseCosts());
  2057. insFeeOrderNew.setJqSuperviseCostsPremiums(jqEntranceFee.getSuperviseCostsPremiums());
  2058. insFeeOrderNew.setJqOtherCostsProportion(jqEntranceFee.getOtherCostsProportion());
  2059. insFeeOrderNew.setJqOtherCostsPremiums(jqEntranceFee.getOtherCostsPremiums());
  2060. insFeeOrderNew.setJqCostsPremiums(insFeeOrderNew.getJqSuperviseCostsPremiums().add(insFeeOrderNew.getJqOtherCostsPremiums()));
  2061. //商业入口信息
  2062. FeeOrderNewVo.EntranceFee syEntranceFee = feeRuleSchemeService.calcEntranceFee(insFeeOrderNew.getSyPremium(),
  2063. new BigDecimal(ptlAgreementProductCostsNew.getSyCarCostsProportion()),
  2064. new BigDecimal(ptlAgreementProductCostsNew.getSyCarOtherCostsProportion()), taxRadio);
  2065. insFeeOrderNew.setSyCostsProportion(syEntranceFee.getTotalProportion());
  2066. insFeeOrderNew.setSySuperviseCostsProportion(syEntranceFee.getSuperviseCosts());
  2067. insFeeOrderNew.setSySuperviseCostsPremiums(syEntranceFee.getSuperviseCostsPremiums());
  2068. insFeeOrderNew.setSyOtherCostsProportion(syEntranceFee.getOtherCostsProportion());
  2069. insFeeOrderNew.setSyOtherCostsPremiums(syEntranceFee.getOtherCostsPremiums());
  2070. insFeeOrderNew.setSyCostsPremiums(insFeeOrderNew.getSySuperviseCostsPremiums().add(insFeeOrderNew.getSyOtherCostsPremiums()));
  2071. //非车入口信息
  2072. FeeOrderNewVo.EntranceFee noEntranceFee = feeRuleSchemeService.calcEntranceFee(insFeeOrderNew.getNoPremium(),
  2073. new BigDecimal(ptlAgreementProductCostsNew.getNoCarCostsProportion()),
  2074. new BigDecimal(ptlAgreementProductCostsNew.getNoCarOtherCostsProportion()), taxRadio);
  2075. insFeeOrderNew.setNoCostsProportion(noEntranceFee.getTotalProportion());
  2076. insFeeOrderNew.setNoSuperviseCostsProportion(noEntranceFee.getSuperviseCosts());
  2077. insFeeOrderNew.setNoSuperviseCostsPremiums(noEntranceFee.getSuperviseCostsPremiums());
  2078. insFeeOrderNew.setNoOtherCostsProportion(noEntranceFee.getOtherCostsProportion());
  2079. insFeeOrderNew.setNoOtherCostsPremiums(noEntranceFee.getOtherCostsPremiums());
  2080. insFeeOrderNew.setNoCostsPremiums(insFeeOrderNew.getNoSuperviseCostsPremiums().add(insFeeOrderNew.getNoOtherCostsPremiums()));
  2081. //endregion
  2082. //region 重新计算管理费比例和分销比例
  2083. List<EsmRetail> esmRetailList = esmRetailService.selectList(" where t.deptid=? and t.status = '1' ",
  2084. new Object[]{sysUser.getDeptId()});
  2085. Integer retailLevel = 0;
  2086. //默认分销比例设置
  2087. RetailProportion retailProportion = new RetailProportion();
  2088. if (!Objects.isNull(esmRetailList) && !esmRetailList.isEmpty()) {
  2089. retailLevel = Integer.parseInt(esmRetailList.get(0).getRetailtype());
  2090. //赋值默认的分销比例
  2091. retailProportion.setProportion(esmRetailList.get(0).getDisrate1(), esmRetailList.get(0).getDisrate2(), esmRetailList.get(0).getDisrate3());
  2092. }
  2093. //获取交强机构管理费总比例
  2094. BigDecimal jqDeptProportion = ptlAgreementProductCostsExport.getJqExportRadioLevel1()
  2095. .add(ptlAgreementProductCostsExport.getJqExportRadioLevel2())
  2096. .add(ptlAgreementProductCostsExport.getJqExportRadioLevel3())
  2097. .add(ptlAgreementProductCostsExport.getJqExportRadioLevel4())
  2098. .add(ptlAgreementProductCostsExport.getJqExportRadioLevel5());
  2099. //获取商业机构管理费总比例
  2100. BigDecimal syDeptProportion = ptlAgreementProductCostsExport.getSyExportRadioLevel1()
  2101. .add(ptlAgreementProductCostsExport.getSyExportRadioLevel2())
  2102. .add(ptlAgreementProductCostsExport.getSyExportRadioLevel3())
  2103. .add(ptlAgreementProductCostsExport.getSyExportRadioLevel4())
  2104. .add(ptlAgreementProductCostsExport.getSyExportRadioLevel5());
  2105. //获取非车机构管理费总比例
  2106. BigDecimal noDeptProportion = ptlAgreementProductCostsExport.getNoCarExportRadioLevel1()
  2107. .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel2())
  2108. .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel3())
  2109. .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel4())
  2110. .add(ptlAgreementProductCostsExport.getNoCarExportRadioLevel5());
  2111. //获取交强分销总比例
  2112. BigDecimal jqRetailProportion = retailProportion.getJqRetailLevel1Proportion()
  2113. .add(retailProportion.getJqRetailLevel2Proportion())
  2114. .add(retailProportion.getJqRetailLevel3Proportion());
  2115. //获取商业分销总比例
  2116. BigDecimal syRetailProportion = retailProportion.getSyRetailLevel1Proportion()
  2117. .add(retailProportion.getSyRetailLevel2Proportion())
  2118. .add(retailProportion.getSyRetailLevel3Proportion());
  2119. //获取非车分销总比例
  2120. BigDecimal noRetailProportion = retailProportion.getNoRetailLevel1Proportion()
  2121. .add(retailProportion.getNoRetailLevel2Proportion())
  2122. .add(retailProportion.getNoRetailLevel3Proportion());
  2123. // 外部订单比例
  2124. BigDecimal enterProportion = sysSwitchConfigService.getEnterProportion(insOrders.getDeptid(), insOrders.getEntryStatus());
  2125. //重新计算比例 入口是否超出支付的比例
  2126. ReCalcuLateProportion jqReCalcuLateProportion = recalculateProportion(
  2127. new BigDecimal(ptlAgreementProductCostsNew.getJqCostsProportion()),
  2128. jqDeptProportion,
  2129. jqRetailProportion,
  2130. taxRadio,
  2131. retailLevel,
  2132. ptlAgreementProductCostsExport,
  2133. retailProportion,
  2134. "jq",
  2135. enterProportion
  2136. );
  2137. ReCalcuLateProportion syReCalcuLateProportion = recalculateProportion(
  2138. new BigDecimal(ptlAgreementProductCostsNew.getSyCostsProportion()),
  2139. syDeptProportion,
  2140. syRetailProportion,
  2141. taxRadio,
  2142. retailLevel,
  2143. ptlAgreementProductCostsExport,
  2144. retailProportion,
  2145. "sy",
  2146. enterProportion
  2147. );
  2148. ReCalcuLateProportion noReCalcuLateProportion = recalculateProportion(
  2149. new BigDecimal(ptlAgreementProductCostsNew.getNoCostsProportion()),
  2150. noDeptProportion,
  2151. noRetailProportion,
  2152. taxRadio,
  2153. retailLevel,
  2154. ptlAgreementProductCostsExport,
  2155. retailProportion,
  2156. "no",
  2157. enterProportion
  2158. );
  2159. retailProportion.setProportion(jqReCalcuLateProportion, syReCalcuLateProportion, noReCalcuLateProportion);
  2160. //endregion
  2161. //region 计算分销费用
  2162. //获取分销比例
  2163. //分销总比例
  2164. BigDecimal jqRetailRadio = new BigDecimal("0");
  2165. BigDecimal syRetailRadio = new BigDecimal("0");
  2166. BigDecimal noRetailRadio = new BigDecimal("0");
  2167. FeeOrderNewVo.RetailFee retailFeeLevel3 = new FeeOrderNewVo.RetailFee();
  2168. FeeOrderNewVo.RetailFee retailFeeLevel2 = new FeeOrderNewVo.RetailFee();
  2169. FeeOrderNewVo.RetailFee retailFeeLevel1 = new FeeOrderNewVo.RetailFee();
  2170. if (esmRetailList != null && !esmRetailList.isEmpty()) {
  2171. EsmRetail esmRetail = esmRetailList.get(0);
  2172. //分销等级
  2173. insFeeOrderNew.setDistributionStatus(esmRetailList.get(0).getRetailtype());
  2174. //用户分销人员id
  2175. List<EsmUserReferrer> parents = esmUserReferrerService.findParents(sysUser.getId());
  2176. if (esmRetail != null) {
  2177. if (Integer.parseInt(esmRetail.getRetailtype()) >= 3) {
  2178. insFeeOrderNew.setThirdDetailProportion(retailProportion.getJqRetailLevel3Proportion());
  2179. retailFeeLevel3 = feeRuleSchemeService.calcRetail(insFeeOrderNew.getJqPremium(),
  2180. insFeeOrderNew.getJqCostsProportion(),
  2181. insFeeOrderNew.getSyPremium(),
  2182. insFeeOrderNew.getSyCostsProportion().add(insFeeOrderNew.getSyOtherCostsProportion()),
  2183. insFeeOrderNew.getNoPremium(),
  2184. insFeeOrderNew.getNoCostsProportion().add(insFeeOrderNew.getNoOtherCostsProportion()),
  2185. retailProportion.getJqRetailLevel3Proportion(),
  2186. retailProportion.getSyRetailLevel3Proportion(),
  2187. retailProportion.getNoRetailLevel3Proportion());
  2188. insFeeOrderNew.setThirdDetailPremiums(retailFeeLevel3.getTotalRetailPremiums());
  2189. if (parents != null && parents.size() > 2) {
  2190. insFeeOrderNew.setThreeLevelUserId(parents.get(2).getId());
  2191. }
  2192. } else {
  2193. insFeeOrderNew.setThirdDetailProportion(new BigDecimal(0));
  2194. }
  2195. if (Integer.parseInt(esmRetail.getRetailtype()) >= 2) {
  2196. insFeeOrderNew.setSecondDetailProportion(retailProportion.getJqRetailLevel2Proportion());
  2197. retailFeeLevel2 = feeRuleSchemeService.calcRetail(insFeeOrderNew.getJqPremium(),
  2198. insFeeOrderNew.getJqCostsProportion(),
  2199. insFeeOrderNew.getSyPremium(),
  2200. insFeeOrderNew.getSyCostsProportion(),
  2201. insFeeOrderNew.getNoPremium(),
  2202. insFeeOrderNew.getNoCostsProportion(),
  2203. retailProportion.getJqRetailLevel2Proportion(),
  2204. retailProportion.getSyRetailLevel2Proportion(),
  2205. retailProportion.getNoRetailLevel2Proportion());
  2206. insFeeOrderNew.setSecondDetailPremiums(retailFeeLevel2.getTotalRetailPremiums());
  2207. if (parents != null && parents.size() > 1) {
  2208. insFeeOrderNew.setTwoLevelUserId(parents.get(1).getId());
  2209. }
  2210. } else {
  2211. insFeeOrderNew.setSecondDetailProportion(new BigDecimal(0));
  2212. }
  2213. if (Integer.parseInt(esmRetail.getRetailtype()) >= 1) {
  2214. insFeeOrderNew.setFirstDetailProportion(retailProportion.getJqRetailLevel1Proportion());
  2215. retailFeeLevel1 = feeRuleSchemeService.calcRetail(insFeeOrderNew.getJqPremium(),
  2216. insFeeOrderNew.getJqCostsProportion(),
  2217. insFeeOrderNew.getSyPremium(),
  2218. insFeeOrderNew.getSyCostsProportion(),
  2219. insFeeOrderNew.getNoPremium(),
  2220. insFeeOrderNew.getNoCostsProportion(),
  2221. retailProportion.getJqRetailLevel1Proportion(),
  2222. retailProportion.getSyRetailLevel1Proportion(),
  2223. retailProportion.getNoRetailLevel1Proportion());
  2224. insFeeOrderNew.setFirstDetailPremiums(retailFeeLevel1.getTotalRetailPremiums());
  2225. if (parents != null && !parents.isEmpty()) {
  2226. insFeeOrderNew.setFirstLevelUserId(parents.get(0).getId());
  2227. }
  2228. } else {
  2229. insFeeOrderNew.setFirstDetailProportion(new BigDecimal(0));
  2230. }
  2231. } else {
  2232. insFeeOrderNew.setFirstDetailPremiums(new BigDecimal(0));
  2233. insFeeOrderNew.setSecondDetailPremiums(new BigDecimal(0));
  2234. insFeeOrderNew.setThirdDetailPremiums(new BigDecimal(0));
  2235. }
  2236. } else {
  2237. insFeeOrderNew.setFirstDetailProportion(new BigDecimal(0));
  2238. insFeeOrderNew.setSecondDetailProportion(new BigDecimal(0));
  2239. insFeeOrderNew.setThirdDetailProportion(new BigDecimal(0));
  2240. }
  2241. jqRetailRadio = jqRetailRadio.add(retailFeeLevel1.getJqRetailProportion())
  2242. .add(retailFeeLevel2.getJqRetailProportion())
  2243. .add(retailFeeLevel3.getJqRetailProportion());
  2244. syRetailRadio = syRetailRadio.add(retailFeeLevel1.getSyRetailProportion())
  2245. .add(retailFeeLevel2.getSyRetailProportion())
  2246. .add(retailFeeLevel3.getSyRetailProportion());
  2247. noRetailRadio = noRetailRadio.add(retailFeeLevel1.getNoRetailProportion())
  2248. .add(retailFeeLevel2.getNoRetailProportion())
  2249. .add(retailFeeLevel3.getNoRetailProportion());
  2250. insFeeOrderNew.assignRetail(retailFeeLevel1, retailFeeLevel2, retailFeeLevel3);
  2251. //endregion
  2252. //region 设置机构管理费
  2253. //交强机构管理费
  2254. BigDecimal jqDeptRadio =
  2255. jqReCalcuLateProportion.getDept_level_1_proportion()
  2256. .add(jqReCalcuLateProportion.getDept_level_2_proportion())
  2257. .add(jqReCalcuLateProportion.getDept_level_3_proportion())
  2258. .add(jqReCalcuLateProportion.getDept_level_4_proportion())
  2259. .add(jqReCalcuLateProportion.getDept_level_5_proportion());
  2260. FeeOrderNewVo.DeptManagerFee jqDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(
  2261. insFeeOrderNew.getJqPremium(),
  2262. jqReCalcuLateProportion.getDept_level_1_proportion(),
  2263. jqReCalcuLateProportion.getDept_level_2_proportion(),
  2264. jqReCalcuLateProportion.getDept_level_3_proportion(),
  2265. jqReCalcuLateProportion.getDept_level_4_proportion(),
  2266. jqReCalcuLateProportion.getDept_level_5_proportion());
  2267. BigDecimal syDeptRadio =
  2268. syReCalcuLateProportion.getDept_level_1_proportion()
  2269. .add(syReCalcuLateProportion.getDept_level_2_proportion())
  2270. .add(syReCalcuLateProportion.getDept_level_3_proportion())
  2271. .add(syReCalcuLateProportion.getDept_level_4_proportion())
  2272. .add(syReCalcuLateProportion.getDept_level_5_proportion());
  2273. FeeOrderNewVo.DeptManagerFee syDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(
  2274. insFeeOrderNew.getSyPremium(),
  2275. syReCalcuLateProportion.getDept_level_1_proportion(),
  2276. syReCalcuLateProportion.getDept_level_2_proportion(),
  2277. syReCalcuLateProportion.getDept_level_3_proportion(),
  2278. syReCalcuLateProportion.getDept_level_4_proportion(),
  2279. syReCalcuLateProportion.getDept_level_5_proportion());
  2280. BigDecimal noDeptRadio =
  2281. noReCalcuLateProportion.getDept_level_1_proportion()
  2282. .add(noReCalcuLateProportion.getDept_level_2_proportion())
  2283. .add(noReCalcuLateProportion.getDept_level_3_proportion())
  2284. .add(noReCalcuLateProportion.getDept_level_4_proportion())
  2285. .add(noReCalcuLateProportion.getDept_level_5_proportion());
  2286. FeeOrderNewVo.DeptManagerFee noDeptManagerFee = feeRuleSchemeService.calcDeptManagerFee(
  2287. insFeeOrderNew.getNoPremium(),
  2288. noReCalcuLateProportion.getDept_level_1_proportion(),
  2289. noReCalcuLateProportion.getDept_level_2_proportion(),
  2290. noReCalcuLateProportion.getDept_level_3_proportion(),
  2291. noReCalcuLateProportion.getDept_level_4_proportion(),
  2292. noReCalcuLateProportion.getDept_level_5_proportion());
  2293. insFeeOrderNew.assignDept(jqDeptManagerFee, syDeptManagerFee, noDeptManagerFee);
  2294. //endregion
  2295. //region 出口费用
  2296. //交强出口手续费比例
  2297. FeeOrderNewVo.ExportFee jqExportFee = feeRuleSchemeService.calcExportFee(
  2298. insFeeOrderNew.getJqPremium(),
  2299. new BigDecimal(ptlAgreementProductCostsNew.getJqCostsExportProportion()),
  2300. insFeeOrderNew.getJqCostsProportion(),
  2301. jqDeptRadio,
  2302. jqRetailRadio,
  2303. taxRadio,
  2304. jqReCalcuLateProportion.getProxyProportion()
  2305. );
  2306. //商业出口手续费比例
  2307. FeeOrderNewVo.ExportFee syExportFee = feeRuleSchemeService.calcExportFee(
  2308. insFeeOrderNew.getSyPremium(),
  2309. new BigDecimal(ptlAgreementProductCostsNew.getSyCostsExportProportion()),
  2310. insFeeOrderNew.getSyCostsProportion(),
  2311. syDeptRadio,
  2312. syRetailRadio,
  2313. taxRadio,
  2314. syReCalcuLateProportion.getProxyProportion()
  2315. );
  2316. //非车出口手续费比例
  2317. FeeOrderNewVo.ExportFee noExportFee = feeRuleSchemeService.calcExportFee(
  2318. insFeeOrderNew.getNoPremium(),
  2319. new BigDecimal(ptlAgreementProductCostsNew.getNoCostsExportProportion()),
  2320. insFeeOrderNew.getNoCostsProportion(),
  2321. noDeptRadio,
  2322. noRetailRadio,
  2323. taxRadio,
  2324. noReCalcuLateProportion.getProxyProportion()
  2325. );
  2326. //出口手续费用
  2327. insFeeOrderNew.setJqExportSuperviseCostsPremiums(twoPeople(jqExportFee.getSuperviseCostsPremiums()));
  2328. insFeeOrderNew.setSyExportSuperviseCostsPremiums(twoPeople(syExportFee.getSuperviseCostsPremiums()));
  2329. insFeeOrderNew.setNoExportSuperviseCostsPremiums(twoPeople(noExportFee.getSuperviseCostsPremiums()));
  2330. //出口其他费用比例
  2331. insFeeOrderNew.setJqExportOtherCostsProportion(twoPeople(jqExportFee.getOtherCostsProportion()));
  2332. insFeeOrderNew.setSyExportOtherCostsProportion(twoPeople(syExportFee.getOtherCostsProportion()));
  2333. insFeeOrderNew.setNoExportOtherCostsProportion(twoPeople(noExportFee.getOtherCostsProportion()));
  2334. //出口其他费用
  2335. insFeeOrderNew.setJqExportOtherCostsPremiums(twoPeople(jqExportFee.getOtherCostsPremiums()));
  2336. insFeeOrderNew.setSyExportOtherCostsPremiums(twoPeople(syExportFee.getOtherCostsPremiums()));
  2337. insFeeOrderNew.setNoExportOtherCostsPremiums(twoPeople(noExportFee.getOtherCostsPremiums()));
  2338. //设置出口手续费比例
  2339. insFeeOrderNew.setJqCostsExportProportion(twoPeople(jqExportFee.getSuperviseCosts()));
  2340. insFeeOrderNew.setSyCostsExportProportion(twoPeople(syExportFee.getSuperviseCosts()));
  2341. insFeeOrderNew.setNoCostsExportProportion(twoPeople(noExportFee.getSuperviseCosts()));
  2342. // 外部费用
  2343. insFeeOrderNew.setJqExternalProportion(jqExportFee.getExternalProportion());
  2344. insFeeOrderNew.setJqExternalPremiums(jqExportFee.getExternalPremiums());
  2345. insFeeOrderNew.setSyExternalProportion(syExportFee.getExternalProportion());
  2346. insFeeOrderNew.setSyExternalPremiums(syExportFee.getExternalPremiums());
  2347. insFeeOrderNew.setNoExternalProportion(noExportFee.getExternalProportion());
  2348. insFeeOrderNew.setNoExternalPremiums(noExportFee.getExternalPremiums());
  2349. //endregion
  2350. //region 计算利润差值
  2351. //入口 - 出口 - 机构管理费 1-5级 - 分销费 = 差值
  2352. //分销交强费用
  2353. //分开算 1 2 3 级
  2354. BigDecimal jqFirst = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getJqRetailProportionLevel1().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  2355. BigDecimal jqSecond = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getJqRetailProportionLevel2().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  2356. BigDecimal jqThird = insFeeOrderNew.getJqPremium().multiply(insFeeOrderNew.getJqRetailProportionLevel3().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  2357. BigDecimal jqFenXiao = jqFirst.add(jqSecond).add(jqThird);
  2358. //分销商业费用
  2359. BigDecimal syFirst = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getSyRetailProportionLevel1().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  2360. BigDecimal sySecond = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getSyRetailProportionLevel2().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  2361. BigDecimal syThird = insFeeOrderNew.getSyPremium().multiply(insFeeOrderNew.getSyRetailProportionLevel3().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  2362. BigDecimal syFenXiao = syFirst.add(sySecond).add(syThird);
  2363. //分销非车费用
  2364. BigDecimal noFirst = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getNoRetailProportionLevel1().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  2365. BigDecimal noSecond = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getNoRetailProportionLevel2().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  2366. BigDecimal noThird = insFeeOrderNew.getNoPremium().multiply(insFeeOrderNew.getNoRetailProportionLevel3().divide(new BigDecimal(100))).setScale(2, BigDecimal.ROUND_DOWN);
  2367. BigDecimal noFenXiao = noFirst.add(noSecond).add(noThird);
  2368. BigDecimal jqDifference = jqEntranceFee.getTotalAmount()
  2369. .subtract(jqExportFee.getExternalPremiums())
  2370. .subtract(
  2371. (jqExportFee.getSuperviseCostsPremiums().add(jqExportFee.getOtherCostsPremiums())))
  2372. .subtract(
  2373. (jqDeptManagerFee.getDeptPremiumsLevelOne().add(jqDeptManagerFee.getDeptPremiumsLevelTwo().add(jqDeptManagerFee.getDeptPremiumsLevelThree()).add(jqDeptManagerFee.getDeptPremiumsLevelFoure()).add(jqDeptManagerFee.getDeptPremiumsLevelFive())))
  2374. )
  2375. .subtract(jqFenXiao)
  2376. .setScale(5, BigDecimal.ROUND_HALF_DOWN);
  2377. insFeeOrderNew.setJqProfitMarginPremiums(jqDifference);
  2378. BigDecimal syDifference = syEntranceFee.getTotalAmount()
  2379. .subtract(syExportFee.getExternalPremiums())
  2380. .subtract(
  2381. (syExportFee.getSuperviseCostsPremiums().add(syExportFee.getOtherCostsPremiums())))
  2382. .subtract(
  2383. (syDeptManagerFee.getDeptPremiumsLevelOne().add(syDeptManagerFee.getDeptPremiumsLevelTwo().add(syDeptManagerFee.getDeptPremiumsLevelThree()).add(syDeptManagerFee.getDeptPremiumsLevelFoure()).add(syDeptManagerFee.getDeptPremiumsLevelFive())))
  2384. )
  2385. .subtract(syFenXiao)
  2386. .setScale(5, BigDecimal.ROUND_HALF_DOWN);
  2387. insFeeOrderNew.setSyProfitMarginPremiums(syDifference);
  2388. BigDecimal noDifference = noEntranceFee.getTotalAmount()
  2389. .subtract(noExportFee.getExternalPremiums())
  2390. .subtract(
  2391. (noExportFee.getSuperviseCostsPremiums().add(noExportFee.getOtherCostsPremiums())))
  2392. .subtract(
  2393. (noDeptManagerFee.getDeptPremiumsLevelOne().add(noDeptManagerFee.getDeptPremiumsLevelTwo().add(noDeptManagerFee.getDeptPremiumsLevelThree()).add(noDeptManagerFee.getDeptPremiumsLevelFoure()).add(noDeptManagerFee.getDeptPremiumsLevelFive())))
  2394. )
  2395. .subtract(noFenXiao)
  2396. .setScale(5, BigDecimal.ROUND_HALF_DOWN);
  2397. insFeeOrderNew.setNoProfitMarginPremiums(noDifference);
  2398. //endregion
  2399. //region 比例逆推是否等于0
  2400. if (!feeRuleSchemeService.calculateProportion(jqEntranceFee, jqDeptManagerFee, jqExportFee, jqRetailRadio, taxRadio, insFeeOrderNew.getJqPremium()))
  2401. throw new SystemException("交强比例异常");
  2402. if (!feeRuleSchemeService.calculateProportion(syEntranceFee, syDeptManagerFee, syExportFee, syRetailRadio, taxRadio, insFeeOrderNew.getSyPremium()))
  2403. throw new SystemException("商业比例异常");
  2404. if (!feeRuleSchemeService.calculateProportion(noEntranceFee, noDeptManagerFee, noExportFee, noRetailRadio, taxRadio, insFeeOrderNew.getNoPremium()))
  2405. throw new SystemException("非车比例异常");
  2406. //endregion
  2407. insFeeOrderNewHistoryService.saveInsFeeOrderNewHistory(insFeeOrderNew);
  2408. insFeeOrderNewService.saveOrUpdate(insFeeOrderNew);
  2409. }
  2410. /**
  2411. * 判断是否包含非车险
  2412. *
  2413. * @param insAreaCompany
  2414. * @return
  2415. */
  2416. private boolean isContainNonCar(InsAreaCompany insAreaCompany) {
  2417. if (insAreaCompany.getCrossInsurance() != null && insAreaCompany.getJypremium().equals(BigDecimal.ZERO)) {
  2418. return false;
  2419. }
  2420. return true;
  2421. }
  2422. /**
  2423. * 匹配费用因子
  2424. *
  2425. * @param agreementProductCosts
  2426. * @param insAreaCompany
  2427. * @param insOrders
  2428. * @return
  2429. */
  2430. private String verificationCosts(List<AgreementProductCosts> agreementProductCosts, QuoteRespVo quoteRespVo, InsAreaCompany insAreaCompany,
  2431. InsOrders insOrders, StringBuilder logs) {
  2432. //匹配费用因子
  2433. //获取所有费用属性
  2434. List<PtlAgreementUndwrtRulesAttr> undwrtRulesAttrList = ptlAgreementUndwrtRulesAttrService.getUndwrtRulesAttrList();
  2435. //获取新旧车信息
  2436. PtlNewCarJudgeRules carJudgeRule = getCarJudgeRule(insAreaCompany.getCompanyId(), insOrders.getCarinfo().getString("cimodelclass"));
  2437. //获取所有费用属性关联
  2438. List<RuleAttrMappingVo> ruleAttrMappingVoList = RuleAttrMappingVo.getRuleAttrMappingVoList(quoteRespVo, insAreaCompany, insOrders,
  2439. undwrtRulesAttrList, carJudgeRule);
  2440. for (int i = 0; i < agreementProductCosts.size(); i++) {
  2441. //判断是否匹配
  2442. log.debug("费用因子匹配开始:" + agreementProductCosts.get(i).getId());
  2443. log.debug("车牌号:" + insOrders.getLicenseno());
  2444. log.debug("费用因子备注:" + agreementProductCosts.get(i).getCostsDescription());
  2445. logs.append("费用id:" + agreementProductCosts.get(i).getId() + "\n");
  2446. logs.append("费用因子描述:" + agreementProductCosts.get(i).getCostsDescription() + "\n");
  2447. if (judgements(agreementProductCosts.get(i).getCostsAttrLinks(), undwrtRulesAttrList, ruleAttrMappingVoList, logs)) {
  2448. //返回 费用id 如果需要匹配非车的情况 将返回值返回list 后赛选
  2449. return agreementProductCosts.get(i).getId();
  2450. }
  2451. log.debug("当前费用因子匹配结束\n");
  2452. }
  2453. return null;
  2454. // throw new SystemException("费用因子匹配失败");
  2455. }
  2456. private boolean verificationRules(List<PtlAgreementUndwrtRulesNew> ptlAgreementUndwrtRulesNews, InsAreaCompany insAreaCompany,
  2457. InsOrders insOrders) {
  2458. StringBuilder logs = new StringBuilder();
  2459. //匹配承保规则
  2460. //获取所有承保规则属性
  2461. List<PtlAgreementUndwrtRulesAttr> undwrtRulesAttrList = ptlAgreementUndwrtRulesAttrService.getUndwrtRulesAttrList();
  2462. //获取所有费用属性关联
  2463. List<RuleAttrMappingVo> ruleAttrMappingVoList = RuleAttrMappingVo.getRuleAttrMappingVoList(null,insAreaCompany, insOrders,
  2464. undwrtRulesAttrList, getCarJudgeRule(insAreaCompany.getCompanyId(),insOrders.getCarinfo().getString("cimodelclass")));
  2465. for (int i = 0; i < ptlAgreementUndwrtRulesNews.size(); i++) {
  2466. logs.append("触发承保规则:" + ptlAgreementUndwrtRulesNews.get(i).getRuleDescription() + "\n");
  2467. //判断是否匹配
  2468. if (!judgementsRules(ptlAgreementUndwrtRulesNews.get(i).getRulesAttrList(), undwrtRulesAttrList, ruleAttrMappingVoList, logs,insOrders)) {
  2469. throw new SystemException(logs.toString());
  2470. }else{
  2471. //如果没有出现异常则清空匹配消息
  2472. logs.delete(0,logs.length());
  2473. }
  2474. }
  2475. return true;
  2476. }
  2477. /**
  2478. * 费用因子的对比
  2479. *
  2480. * @param ptlAgreementProductCostsAttrLinks 费用因子范围规则
  2481. * @param rulesAttrs 费用因子属性
  2482. * @param ruleAttrMappingVoList 表单提交的值
  2483. * @return
  2484. */
  2485. private boolean judgements(List<PtlAgreementProductCostsAttrLink> ptlAgreementProductCostsAttrLinks,
  2486. List<PtlAgreementUndwrtRulesAttr> rulesAttrs, List<RuleAttrMappingVo> ruleAttrMappingVoList,
  2487. StringBuilder logs) {
  2488. boolean useFlag = true;
  2489. for (PtlAgreementProductCostsAttrLink ptlAgreementProductCostsAttrLink : ptlAgreementProductCostsAttrLinks) {
  2490. //查找规则中的 传值属性
  2491. RuleAttrMappingVo ruleAttrMappingVo = ruleAttrMappingVoList.stream()
  2492. .filter(x -> x.getAttrCode().equals(ptlAgreementProductCostsAttrLink.getAttrCode()))
  2493. .findFirst()
  2494. .orElse(null);
  2495. //如果查找不到 传值属性 直接费用对比失败
  2496. if (ruleAttrMappingVo == null) {
  2497. log.debug("传入的值找不到该属性:" + ptlAgreementProductCostsAttrLink.getAttrCode());
  2498. log.debug("规则匹配失败:" + ptlAgreementProductCostsAttrLink.getAttrCode());
  2499. List<PtlAgreementUndwrtRulesAttr> collect = rulesAttrs.stream()
  2500. .filter(x -> x.getAttrCode().equals(ptlAgreementProductCostsAttrLink.getAttrCode()))
  2501. .collect(Collectors.toList());
  2502. if (!collect.isEmpty()) {
  2503. logs.append("规则匹配失败:" + collect.get(0).getAttrName() + "\n");
  2504. }
  2505. return false;
  2506. }
  2507. //查找 费用因子规则
  2508. PtlAgreementUndwrtRulesAttr ptlAgreementUndwrtRulesAttr = rulesAttrs.stream()
  2509. .filter(x -> x.getAttrCode().equals(ptlAgreementProductCostsAttrLink.getAttrCode()))
  2510. .findFirst()
  2511. .get();
  2512. if(!Objects.isNull(ruleAttrMappingVo.getValue())) {
  2513. useFlag = attrEqual(ptlAgreementProductCostsAttrLink, ptlAgreementUndwrtRulesAttr, ruleAttrMappingVo.getValue());
  2514. }else{
  2515. useFlag = false;
  2516. }
  2517. if (!useFlag) {
  2518. log.debug("检验的值:" + ptlAgreementProductCostsAttrLink.getMin());
  2519. log.debug("传入的值:" + ruleAttrMappingVo.getValue());
  2520. log.debug("规则匹配失败:" + ptlAgreementProductCostsAttrLink.getAttrCode());
  2521. List<PtlAgreementUndwrtRulesAttr> collect = rulesAttrs.stream()
  2522. .filter(x -> x.getAttrCode().equals(ptlAgreementProductCostsAttrLink.getAttrCode()))
  2523. .collect(Collectors.toList());
  2524. if (ptlAgreementProductCostsAttrLink.getMin() != null) {
  2525. logs.append("检验的值:" + ptlAgreementProductCostsAttrLink.getMin() + "\n");
  2526. } else {
  2527. logs.append("检验的值:" + ptlAgreementProductCostsAttrLink.getMax() + "\n");
  2528. }
  2529. logs.append("传入的值:" + ruleAttrMappingVo.getValue() + "\n");
  2530. if (!collect.isEmpty()) {
  2531. logs.append("<span style=\"color:red;\">规则匹配失败:" + collect.get(0).getAttrName() + "</span>\n");
  2532. }
  2533. return false;
  2534. }
  2535. }
  2536. return useFlag;
  2537. }
  2538. /**
  2539. * 承保规则因子的对比
  2540. *
  2541. * @param ptlAgreementUndwrtRulesAttrLinks
  2542. * @param rulesAttrs
  2543. * @param ruleAttrMappingVoList
  2544. * @return
  2545. */
  2546. private boolean judgementsRules(List<PtlAgreementUndwrtRulesAttrLink> ptlAgreementUndwrtRulesAttrLinks,
  2547. List<PtlAgreementUndwrtRulesAttr> rulesAttrs, List<RuleAttrMappingVo> ruleAttrMappingVoList,
  2548. StringBuilder logs,InsOrders insOrders) {
  2549. boolean useFlag = true;
  2550. for (int i = 0; i < ptlAgreementUndwrtRulesAttrLinks.size(); i++) {
  2551. int finalI = i;
  2552. //查找规则中的 传值属性
  2553. RuleAttrMappingVo ruleAttrMappingVo = ruleAttrMappingVoList.stream().filter(x ->
  2554. x.getAttrCode().equals(ptlAgreementUndwrtRulesAttrLinks.get(finalI).getAttrCode())).findFirst().orElse(null);
  2555. //如果查找不到 传值属性 直接费用对比失败
  2556. if (ruleAttrMappingVo == null) {
  2557. return true;
  2558. }
  2559. //查找 费用因子规则
  2560. PtlAgreementUndwrtRulesAttr ptlAgreementUndwrtRulesAttr =
  2561. rulesAttrs.stream().filter(x -> x.getAttrCode().equals(ptlAgreementUndwrtRulesAttrLinks.get(finalI).getAttrCode())).findFirst().get();
  2562. //如果是多选 对value进行转换
  2563. if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("checkbox")) {
  2564. PtlAgreementUndwrtRulesDictLabal ptlAgreementUndwrtRulesDictLabal =
  2565. ptlAgreementUndwrtRulesAttr.getDictLabal().stream().filter(x ->
  2566. x.getName().equals(ruleAttrMappingVo.getValue())).findFirst().orElse(null);
  2567. ruleAttrMappingVo.setValue(ptlAgreementUndwrtRulesDictLabal.getName());
  2568. }
  2569. //如果是单选 并且是 性别的话 转换为code
  2570. if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("radio")) {
  2571. if ("CarOwnersSex".equals(ptlAgreementUndwrtRulesAttr.getAttrCode()) || "ApplicantSex".equals(ptlAgreementUndwrtRulesAttr.getAttrCode()) ||
  2572. "InsuredSex".equals(ptlAgreementUndwrtRulesAttr.getAttrCode())) {
  2573. PtlAgreementUndwrtRulesDictLabal ptlAgreementUndwrtRulesDictLabal =
  2574. ptlAgreementUndwrtRulesAttr.getDictLabal().stream().filter(x ->
  2575. x.getCode().equals(ruleAttrMappingVo.getValue())).findFirst().orElse(null);
  2576. ruleAttrMappingVo.setValue(ptlAgreementUndwrtRulesDictLabal.getCode());
  2577. }
  2578. }
  2579. if(!Objects.isNull(ruleAttrMappingVo.getValue())) {
  2580. useFlag = attrEqual(ptlAgreementUndwrtRulesAttrLinks.get(i), ptlAgreementUndwrtRulesAttr, ruleAttrMappingVo.getValue(),insOrders);
  2581. }else{
  2582. useFlag = false;
  2583. }
  2584. if (useFlag) {
  2585. return true;
  2586. } else {
  2587. logs.append("规则匹配失败:" + ptlAgreementUndwrtRulesAttrLinks.get(i).getAttrCode() + "\n");
  2588. if (ptlAgreementUndwrtRulesAttrLinks.get(i).getMin() != null) {
  2589. logs.append("校验的值:" + ptlAgreementUndwrtRulesAttrLinks.get(i).getMin() + "\n");
  2590. } else {
  2591. logs.append("校验的值:" + ptlAgreementUndwrtRulesAttrLinks.get(i).getMax() + "\n");
  2592. }
  2593. logs.append("传入的值:" + ruleAttrMappingVo.getValue() + "\n");
  2594. }
  2595. }
  2596. return useFlag;
  2597. }
  2598. /**
  2599. * 费用因子的对比 强制非车险
  2600. *
  2601. * @param ptlAgreementProductCostsAttrLinks 费用因子范围规则
  2602. * @param rulesAttrs 费用因子属性
  2603. * @param ruleAttrMappingVoList 表单提交的值
  2604. * @return
  2605. */
  2606. private boolean judgementsIsNoCar(List<PtlAgreementProductCostsAttrLink> ptlAgreementProductCostsAttrLinks,
  2607. List<PtlAgreementUndwrtRulesAttr> rulesAttrs, List<RuleAttrMappingVo> ruleAttrMappingVoList) {
  2608. boolean useFlag = true;
  2609. for (int i = 0; i < ptlAgreementProductCostsAttrLinks.size(); i++) {
  2610. int finalI = i;
  2611. //查找规则中的 传值属性
  2612. RuleAttrMappingVo ruleAttrMappingVo =
  2613. ruleAttrMappingVoList.stream().filter(x -> x.getAttrCode().equals(ptlAgreementProductCostsAttrLinks.get(finalI).getAttrCode())).findFirst().orElse(null);
  2614. //如果是强制非车险
  2615. if (ptlAgreementProductCostsAttrLinks.get(i).getAttrCode().equals("IsNonMotorInsurance"))
  2616. continue;
  2617. //如果查找不到 传值属性 直接费用对比失败
  2618. if (ruleAttrMappingVo == null)
  2619. return false;
  2620. //查找 费用因子规则
  2621. PtlAgreementUndwrtRulesAttr ptlAgreementUndwrtRulesAttr =
  2622. rulesAttrs.stream().filter(x -> x.getAttrCode().equals(ptlAgreementProductCostsAttrLinks.get(finalI).getAttrCode())).findFirst().get();
  2623. //如果是多选 对value进行转换
  2624. if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("checkbox")) {
  2625. PtlAgreementUndwrtRulesDictLabal ptlAgreementUndwrtRulesDictLabal =
  2626. ptlAgreementUndwrtRulesAttr.getDictLabal().stream().filter(x ->
  2627. x.getCode().equals(ruleAttrMappingVo.getValue())).findFirst().orElse(null);
  2628. ruleAttrMappingVo.setValue(ptlAgreementUndwrtRulesDictLabal.getName());
  2629. }
  2630. //如果是单选 并且是 性别的话 转换为code
  2631. if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("radio")) {
  2632. if ("CarOwnersSex".equals(ptlAgreementUndwrtRulesAttr.getAttrCode()) || "ApplicantSex".equals(ptlAgreementUndwrtRulesAttr.getAttrCode()) ||
  2633. "InsuredSex".equals(ptlAgreementUndwrtRulesAttr.getAttrCode())) {
  2634. PtlAgreementUndwrtRulesDictLabal ptlAgreementUndwrtRulesDictLabal =
  2635. ptlAgreementUndwrtRulesAttr.getDictLabal().stream().filter(x ->
  2636. x.getName().equals(ruleAttrMappingVo.getValue())).findFirst().orElse(null);
  2637. ruleAttrMappingVo.setValue(ptlAgreementUndwrtRulesDictLabal.getCode());
  2638. }
  2639. }
  2640. useFlag = attrEqual(ptlAgreementProductCostsAttrLinks.get(i), ptlAgreementUndwrtRulesAttr, ruleAttrMappingVo.getValue());
  2641. if (!useFlag) {
  2642. System.out.printf("规则匹配失败:" + ptlAgreementProductCostsAttrLinks.get(i).getAttrCode());
  2643. return false;
  2644. }
  2645. }
  2646. return useFlag;
  2647. }
  2648. /**
  2649. * 属性比较 返回 是否匹配
  2650. *
  2651. * @param ptlAgreementProductCostsAttrLink
  2652. * @param ptlAgreementUndwrtRulesAttr
  2653. * @param value
  2654. * @return
  2655. */
  2656. private boolean attrEqual(PtlAgreementProductCostsAttrLink ptlAgreementProductCostsAttrLink,
  2657. PtlAgreementUndwrtRulesAttr ptlAgreementUndwrtRulesAttr, String value) {
  2658. if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("checkbox")) {
  2659. return checkBoxEqual(ptlAgreementProductCostsAttrLink, value);
  2660. } else if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("inputNumber")) {
  2661. return inputNumberEqual(ptlAgreementProductCostsAttrLink, value);
  2662. } else if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("input")) {
  2663. //截取身份证号码
  2664. if (ptlAgreementProductCostsAttrLink.getAttrCode().equals("CarOwnersIDNumber") || ptlAgreementProductCostsAttrLink.getAttrCode().equals("ApplicantIDNumber") ||
  2665. ptlAgreementProductCostsAttrLink.getAttrCode().equals("InsuredIDNumber")) {
  2666. value = value.substring(0, ptlAgreementProductCostsAttrLink.getMin().length());
  2667. }
  2668. return inputTextEqual(ptlAgreementProductCostsAttrLink, value);
  2669. } else if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("select")) {
  2670. //截取车牌
  2671. if (ptlAgreementUndwrtRulesAttr.getAttrCode().equals("LicenseNo")) {
  2672. value = value.substring(0, 2);
  2673. }
  2674. return selectEqual(ptlAgreementProductCostsAttrLink, value);
  2675. } else if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("radio")) {
  2676. return radioEqual(ptlAgreementProductCostsAttrLink, value);
  2677. } else if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("datetime")){ // 时间
  2678. return dateTimeEqual(ptlAgreementProductCostsAttrLink, value);
  2679. } else if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("date")){
  2680. return dateEqual(ptlAgreementProductCostsAttrLink, value);
  2681. }
  2682. return false;
  2683. }
  2684. private boolean attrEqual(PtlAgreementUndwrtRulesAttrLink ptlAgreementUndwrtRulesAttrLink,
  2685. PtlAgreementUndwrtRulesAttr ptlAgreementUndwrtRulesAttr, String value,InsOrders insOrders) {
  2686. if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("checkbox")) {
  2687. return checkBoxEqual(ptlAgreementUndwrtRulesAttrLink, value);
  2688. } else if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("inputNumber")) {
  2689. //如果是空字符串 则返回false
  2690. // if(value.equals("")){
  2691. // return false;
  2692. // }
  2693. return inputNumberEqual(ptlAgreementUndwrtRulesAttrLink, value);
  2694. } else if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("input")) {
  2695. //截取身份证号码
  2696. if (ptlAgreementUndwrtRulesAttr.getAttrCode().equals("CarOwnersIDNumber") || ptlAgreementUndwrtRulesAttr.getAttrCode().equals("ApplicantIDNumber") ||
  2697. ptlAgreementUndwrtRulesAttr.getAttrCode().equals("InsuredIDNumber")) {
  2698. value = value.substring(0, ptlAgreementUndwrtRulesAttrLink.getMin().length());
  2699. }
  2700. return inputTextEqual(ptlAgreementUndwrtRulesAttrLink, value);
  2701. } else if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("select")) {
  2702. //截取车牌
  2703. if (ptlAgreementUndwrtRulesAttr.getAttrCode().equals("LicenseNo")) {
  2704. value = value.substring(0, 2);
  2705. }
  2706. return selectEqual(ptlAgreementUndwrtRulesAttrLink, value);
  2707. } else if (ptlAgreementUndwrtRulesAttr.getAttrType().equals("radio")) {
  2708. return radioEqual(ptlAgreementUndwrtRulesAttrLink, value);
  2709. } else if(ptlAgreementUndwrtRulesAttr.getAttrType().equals("datetime")){
  2710. return dateTimeEqual(ptlAgreementUndwrtRulesAttrLink, value, insOrders);
  2711. } else if(ptlAgreementUndwrtRulesAttr.getAttrType().equals("date")){
  2712. return dateEqual(ptlAgreementUndwrtRulesAttrLink,value);
  2713. }
  2714. return false;
  2715. }
  2716. /**
  2717. * 属性为多选判断
  2718. *
  2719. * @param ptlAgreementProductCostsAttrLink
  2720. * @param value
  2721. * @return
  2722. */
  2723. private boolean checkBoxEqual(PtlAgreementProductCostsAttrLink ptlAgreementProductCostsAttrLink, String value) {
  2724. String[] split = ptlAgreementProductCostsAttrLink.getMin().split(",");
  2725. for (String sp : split) {
  2726. if (sp.equals(value)) {
  2727. return true;
  2728. }
  2729. }
  2730. return false;
  2731. }
  2732. private boolean checkBoxEqual(PtlAgreementUndwrtRulesAttrLink ptlAgreementUndwrtRulesAttrLink, String value) {
  2733. if (!ptlAgreementUndwrtRulesAttrLink.getMin().equals(value)) {
  2734. return true;
  2735. }
  2736. return false;
  2737. }
  2738. /**
  2739. * 属性为数值型判断
  2740. *
  2741. * @param ptlAgreementProductCostsAttrLink
  2742. * @param value
  2743. * @return
  2744. */
  2745. private boolean inputNumberEqual(PtlAgreementProductCostsAttrLink ptlAgreementProductCostsAttrLink, String value) {
  2746. double v = Double.parseDouble(value);
  2747. //统一处理数值
  2748. if ("1".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
  2749. if (Double.parseDouble(ptlAgreementProductCostsAttrLink.getMin()) <= v &&
  2750. Double.parseDouble(ptlAgreementProductCostsAttrLink.getMax()) >= v) {
  2751. return true;
  2752. }
  2753. } else if ("2".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
  2754. if (Double.parseDouble(ptlAgreementProductCostsAttrLink.getMin()) > v) {
  2755. return true;
  2756. }
  2757. } else if ("3".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
  2758. if (Double.parseDouble(ptlAgreementProductCostsAttrLink.getMin()) >= v) {
  2759. return true;
  2760. }
  2761. } else if ("4".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
  2762. if (Double.parseDouble(ptlAgreementProductCostsAttrLink.getMax()) < v) {
  2763. return true;
  2764. }
  2765. } else if ("5".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
  2766. if (Double.parseDouble(ptlAgreementProductCostsAttrLink.getMax()) <= v) {
  2767. return true;
  2768. }
  2769. }
  2770. return false;
  2771. }
  2772. private boolean inputNumberEqual(PtlAgreementUndwrtRulesAttrLink ptlAgreementUndwrtRulesAttrLink, String value) {
  2773. double v = Double.parseDouble(value);
  2774. //统一处理数值
  2775. if ("1".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
  2776. if (Double.parseDouble(ptlAgreementUndwrtRulesAttrLink.getMin()) <= v &&
  2777. Double.parseDouble(ptlAgreementUndwrtRulesAttrLink.getMax()) >= v) {
  2778. return false;
  2779. }
  2780. } else if ("2".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
  2781. if (Double.parseDouble(ptlAgreementUndwrtRulesAttrLink.getMin()) > v) {
  2782. return false;
  2783. }
  2784. } else if ("3".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
  2785. if (Double.parseDouble(ptlAgreementUndwrtRulesAttrLink.getMin()) >= v) {
  2786. return false;
  2787. }
  2788. } else if ("4".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
  2789. if (Double.parseDouble(ptlAgreementUndwrtRulesAttrLink.getMax()) < v) {
  2790. return false;
  2791. }
  2792. } else if ("5".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
  2793. if (Double.parseDouble(ptlAgreementUndwrtRulesAttrLink.getMax()) <= v) {
  2794. return false;
  2795. }
  2796. }
  2797. return true;
  2798. }
  2799. /**
  2800. * 属性为输入框判断
  2801. *
  2802. * @param ptlAgreementProductCostsAttrLink
  2803. * @param value
  2804. * @return
  2805. */
  2806. private boolean inputTextEqual(PtlAgreementProductCostsAttrLink ptlAgreementProductCostsAttrLink, String value) {
  2807. //将值进行分割
  2808. String[] split = ptlAgreementProductCostsAttrLink.getMin().split(",");
  2809. AtomicBoolean returnBool = new AtomicBoolean(false);
  2810. List<String> equalsMap = new ArrayList<>();
  2811. //字符型评分
  2812. equalsMap.add("CharacterBasedRating");
  2813. //交强字符型评分
  2814. equalsMap.add("JqCharacterBasedRating");
  2815. //商业字符型评分
  2816. equalsMap.add("SyCharacterBasedRating");
  2817. // 阳光红黄蓝车系
  2818. equalsMap.add("SeriesTypeActualName");
  2819. //equest 等于判断
  2820. if(equalsMap.contains(ptlAgreementProductCostsAttrLink.getAttrCode())){
  2821. boolean b = Arrays.stream(split).anyMatch(value::equals);
  2822. returnBool.set(b);
  2823. }else if((ptlAgreementProductCostsAttrLink.getAttrCode().equals("BrandandModel") || ptlAgreementProductCostsAttrLink.getAttrCode().equals("CarOwnerName")
  2824. || ptlAgreementProductCostsAttrLink.getAttrCode().equals("CarOwnersAddress") || ptlAgreementProductCostsAttrLink.getAttrCode().equals("ApplicantAddress")
  2825. || ptlAgreementProductCostsAttrLink.getAttrCode().equals("InsuredAddress"))
  2826. && ptlAgreementProductCostsAttrLink.getOperator().equals("2")){
  2827. //处理品牌型号 不包含的情况
  2828. boolean anyMatch = Arrays.stream(split)
  2829. .anyMatch(value::contains);
  2830. returnBool.set(!anyMatch);
  2831. }else {
  2832. boolean anyMatch = Arrays.stream(split)
  2833. .anyMatch(value::contains);
  2834. returnBool.set(anyMatch);
  2835. }
  2836. return returnBool.get();
  2837. }
  2838. private boolean inputTextEqual(PtlAgreementUndwrtRulesAttrLink ptlAgreementUndwrtRulesAttrLink, String value) {
  2839. //将值进行分割
  2840. String[] split = ptlAgreementUndwrtRulesAttrLink.getMin().split(",");
  2841. AtomicBoolean returnBool = new AtomicBoolean(false);
  2842. List<String> equalsMap = new ArrayList<>();
  2843. //字符型评分
  2844. equalsMap.add("CharacterBasedRating");
  2845. //交强字符型评分
  2846. equalsMap.add("JqCharacterBasedRating");
  2847. //商业字符型评分
  2848. equalsMap.add("SyCharacterBasedRating");
  2849. // 阳光红黄蓝车系
  2850. equalsMap.add("SeriesTypeActualName");
  2851. //equest 等于判断
  2852. if(equalsMap.contains(ptlAgreementUndwrtRulesAttrLink.getAttrCode())){
  2853. boolean b = Arrays.stream(split).anyMatch(value::equals);
  2854. returnBool.set(b);
  2855. }else if((ptlAgreementUndwrtRulesAttrLink.getAttrCode().equals("BrandandModel") || ptlAgreementUndwrtRulesAttrLink.getAttrCode().equals("CarOwnerName")
  2856. || ptlAgreementUndwrtRulesAttrLink.getAttrCode().equals("CarOwnersAddress") || ptlAgreementUndwrtRulesAttrLink.getAttrCode().equals("ApplicantAddress")
  2857. || ptlAgreementUndwrtRulesAttrLink.getAttrCode().equals("InsuredAddress"))
  2858. && ptlAgreementUndwrtRulesAttrLink.getOperator().equals("2")){
  2859. //处理品牌型号 不包含的情况
  2860. boolean anyMatch = Arrays.stream(split)
  2861. .anyMatch(value::contains);
  2862. returnBool.set(!anyMatch);
  2863. }else {
  2864. boolean anyMatch = Arrays.stream(split)
  2865. .anyMatch(value::contains);
  2866. returnBool.set(anyMatch);
  2867. }
  2868. return !returnBool.get();
  2869. }
  2870. /**
  2871. * 属性为下拉框判断
  2872. *
  2873. * @param ptlAgreementProductCostsAttrLink
  2874. * @param value
  2875. * @return
  2876. */
  2877. private boolean selectEqual(PtlAgreementProductCostsAttrLink ptlAgreementProductCostsAttrLink, String value) {
  2878. // 包含情况
  2879. if (ptlAgreementProductCostsAttrLink.getMin() != null && ptlAgreementProductCostsAttrLink.getMin().contains(value) && ptlAgreementProductCostsAttrLink.getOperator().equals("0")) {
  2880. return true;
  2881. }
  2882. // 不包含的情况
  2883. if (ptlAgreementProductCostsAttrLink.getMin()!= null && !ptlAgreementProductCostsAttrLink.getMin().contains(value) && ptlAgreementProductCostsAttrLink.getOperator().equals("1")) {
  2884. return true;
  2885. }
  2886. return false;
  2887. }
  2888. /**
  2889. * 属性为选择框判断
  2890. *
  2891. * @param ptlAgreementUndwrtRulesAttrLink
  2892. * @param value
  2893. * @return
  2894. */
  2895. private boolean selectEqual(PtlAgreementUndwrtRulesAttrLink ptlAgreementUndwrtRulesAttrLink, String value) {
  2896. if (ptlAgreementUndwrtRulesAttrLink.getMin() == null) {
  2897. return false;
  2898. }
  2899. if (!ptlAgreementUndwrtRulesAttrLink.getMin().contains(value)) {
  2900. return true;
  2901. }
  2902. return false;
  2903. }
  2904. /**
  2905. * 属性为单选框判断
  2906. *
  2907. * @param ptlAgreementProductCostsAttrLink
  2908. * @param value
  2909. * @return
  2910. */
  2911. private boolean radioEqual(PtlAgreementProductCostsAttrLink ptlAgreementProductCostsAttrLink, String value) {
  2912. //新能源判断
  2913. if ("NewEnergy".equals(ptlAgreementProductCostsAttrLink.getAttrCode())) {
  2914. // 是否是新能源车
  2915. boolean newEnergy = EnergyType.isNewEnergy(value);
  2916. if (newEnergy && ptlAgreementProductCostsAttrLink.getMin().equals("1")) {
  2917. return true;
  2918. } else if (!newEnergy && ptlAgreementProductCostsAttrLink.getMin().equals("0")) {
  2919. return true;
  2920. }
  2921. } else if (ptlAgreementProductCostsAttrLink.getMin().contains(value)) {
  2922. return true;
  2923. }
  2924. return false;
  2925. }
  2926. private boolean radioEqual(PtlAgreementUndwrtRulesAttrLink ptlAgreementUndwrtRulesAttrLink, String value) {
  2927. //新能源判断
  2928. if ("NewEnergy".equals(ptlAgreementUndwrtRulesAttrLink.getAttrCode())) {
  2929. // 是否是新能源车
  2930. boolean newEnergy = EnergyType.isNewEnergy(value);
  2931. if (newEnergy && ptlAgreementUndwrtRulesAttrLink.getMin().equals("1")) {
  2932. return false;
  2933. } else if (!newEnergy && ptlAgreementUndwrtRulesAttrLink.getMin().equals("0")) {
  2934. return false;
  2935. }
  2936. } else if (ptlAgreementUndwrtRulesAttrLink.getMin().contains(value)) {
  2937. return false;
  2938. }
  2939. return true;
  2940. }
  2941. public boolean dateTimeEqual(PtlAgreementProductCostsAttrLink ptlAgreementProductCostsAttrLink, String value){
  2942. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  2943. if(Objects.isNull(value) || value.equals("")){
  2944. return false;
  2945. }
  2946. LocalDateTime v = LocalDateTime.parse(value,formatter);
  2947. LocalDateTime min = null,max = null;
  2948. if(!Objects.isNull(ptlAgreementProductCostsAttrLink.getMin())){
  2949. min = LocalDateTime.parse(ptlAgreementProductCostsAttrLink.getMin(),formatter);
  2950. }
  2951. if(!Objects.isNull(ptlAgreementProductCostsAttrLink.getMax())){
  2952. max = LocalDateTime.parse(ptlAgreementProductCostsAttrLink.getMax(),formatter);
  2953. }
  2954. //统一处理数值
  2955. if ("1".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
  2956. if (v.isAfter(min) && v.isBefore(max)) {
  2957. return true;
  2958. }
  2959. } else if ("2".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
  2960. if (v.isBefore(min)) {
  2961. return true;
  2962. }
  2963. } else if ("3".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
  2964. if (v.isBefore(min) || v.isEqual(min)) {
  2965. return true;
  2966. }
  2967. } else if ("4".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
  2968. if (v.isAfter(max)) {
  2969. return true;
  2970. }
  2971. } else if ("5".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
  2972. if (v.isAfter(max) || v.isEqual(max)) {
  2973. return true;
  2974. }
  2975. }
  2976. return false;
  2977. }
  2978. public boolean dateEqual(PtlAgreementProductCostsAttrLink ptlAgreementProductCostsAttrLink, String value){
  2979. // DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
  2980. if(Objects.isNull(value) || value.equals("")){
  2981. return false;
  2982. }
  2983. LocalDateTime v = LocalDate.parse(value).atStartOfDay();
  2984. LocalDateTime min = null,max = null;
  2985. if(!Objects.isNull(ptlAgreementProductCostsAttrLink.getMin())){
  2986. min = LocalDate.parse(ptlAgreementProductCostsAttrLink.getMin()).atStartOfDay();
  2987. }
  2988. if(!Objects.isNull(ptlAgreementProductCostsAttrLink.getMax())){
  2989. max = LocalDate.parse(ptlAgreementProductCostsAttrLink.getMax()).atStartOfDay();
  2990. }
  2991. //统一处理数值
  2992. if ("1".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
  2993. if (v.isAfter(min) && v.isBefore(max)) {
  2994. return true;
  2995. }
  2996. } else if ("2".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
  2997. if (v.isBefore(min)) {
  2998. return true;
  2999. }
  3000. } else if ("3".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
  3001. if (v.isBefore(min) || v.isEqual(min)) {
  3002. return true;
  3003. }
  3004. } else if ("4".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
  3005. if (v.isAfter(max)) {
  3006. return true;
  3007. }
  3008. } else if ("5".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
  3009. if (v.isAfter(max) || v.isEqual(max)) {
  3010. return true;
  3011. }
  3012. }
  3013. return false;
  3014. }
  3015. public boolean dateTimeEqual(PtlAgreementUndwrtRulesAttrLink ptlAgreementUndwrtRulesAttrLink, String value, InsOrders insOrders){
  3016. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  3017. //判断险种 的起保时间
  3018. if(ptlAgreementUndwrtRulesAttrLink.getAttrCode().equals("SyStartTime") || ptlAgreementUndwrtRulesAttrLink.getAttrCode().equals("JqStartTime"))
  3019. {
  3020. if(insOrders.getProductid().equals(ProductsType.PT_0330.getCode()) && ptlAgreementUndwrtRulesAttrLink.getAttrCode().equals("SyStartTime")){
  3021. return true;
  3022. }
  3023. if(insOrders.getProductid().equals(ProductsType.PT_034001.getCode()) && ptlAgreementUndwrtRulesAttrLink.getAttrCode().equals("JqStartTime")){
  3024. return true;
  3025. }
  3026. }
  3027. if(!Objects.isNull(value) && !value.isEmpty()) {
  3028. LocalDateTime v = LocalDateTime.parse(value, formatter);
  3029. LocalDateTime min = null, max = null;
  3030. if (!Objects.isNull(ptlAgreementUndwrtRulesAttrLink.getMin())) {
  3031. min = LocalDateTime.parse(ptlAgreementUndwrtRulesAttrLink.getMin(), formatter);
  3032. }
  3033. if (!Objects.isNull(ptlAgreementUndwrtRulesAttrLink.getMax())) {
  3034. max = LocalDateTime.parse(ptlAgreementUndwrtRulesAttrLink.getMax(), formatter);
  3035. }
  3036. //统一处理数值
  3037. if ("1".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
  3038. if (!v.isAfter(min) && v.isBefore(max)) {
  3039. return true;
  3040. }
  3041. } else if ("2".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
  3042. if (!v.isBefore(min)) {
  3043. return true;
  3044. }
  3045. } else if ("3".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
  3046. if (!v.isBefore(min)) {
  3047. return true;
  3048. }
  3049. } else if ("4".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
  3050. if (!v.isAfter(max)) {
  3051. return true;
  3052. }
  3053. } else if ("5".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
  3054. if (!v.isAfter(max)) {
  3055. return true;
  3056. }
  3057. }
  3058. }
  3059. return false;
  3060. }
  3061. public boolean dateEqual(PtlAgreementUndwrtRulesAttrLink ptlAgreementUndwrtRulesAttrLink, String value){
  3062. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
  3063. if(!Objects.isNull(value) && !value.isEmpty()) {
  3064. LocalDateTime v = LocalDate.parse(value).atStartOfDay();
  3065. LocalDateTime min = null, max = null;
  3066. if (!Objects.isNull(ptlAgreementUndwrtRulesAttrLink.getMin())) {
  3067. min = LocalDate.parse(ptlAgreementUndwrtRulesAttrLink.getMin()).atStartOfDay();
  3068. }
  3069. if (!Objects.isNull(ptlAgreementUndwrtRulesAttrLink.getMax())) {
  3070. max = LocalDate.parse(ptlAgreementUndwrtRulesAttrLink.getMax()).atStartOfDay();
  3071. }
  3072. //统一处理数值
  3073. if ("1".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
  3074. if (!v.isAfter(min) && v.isBefore(max)) {
  3075. return true;
  3076. }
  3077. } else if ("2".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
  3078. if (!v.isBefore(min)) {
  3079. return true;
  3080. }
  3081. } else if ("3".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
  3082. if (!v.isBefore(min)) {
  3083. return true;
  3084. }
  3085. } else if ("4".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
  3086. if (!v.isAfter(max)) {
  3087. return true;
  3088. }
  3089. } else if ("5".equals(ptlAgreementUndwrtRulesAttrLink.getOperator())) {
  3090. if (!v.isAfter(max)) {
  3091. return true;
  3092. }
  3093. }
  3094. }
  3095. return false;
  3096. }
  3097. /**
  3098. * 获取车辆新旧车信息
  3099. *
  3100. * @param companyId
  3101. * @return
  3102. */
  3103. private PtlNewCarJudgeRules getCarJudgeRule(String companyId, String vehicleType) {
  3104. //获取车辆新旧车信息
  3105. List<PtlNewCarJudgeRules> list =
  3106. ptlNewCarJudgeRulesService.list(new LambdaQueryWrapper<PtlNewCarJudgeRules>()
  3107. .eq(PtlNewCarJudgeRules::getCompanyId,companyId)
  3108. .eq(PtlNewCarJudgeRules::getVehicleType,vehicleType));
  3109. if (list.size() > 0) {
  3110. return list.get(0);
  3111. }
  3112. return null;
  3113. }
  3114. }