FeeRuleSchemeServiceNewImpl.java 199 KB

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