FeeRuleSchemeServiceNewImpl.java 193 KB

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