FeeRuleSchemeServiceNewImpl.java 174 KB

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