FeeRuleSchemeServiceNewImpl.java 194 KB

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