InsPlyIncomeServiceImpl.java 227 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999
  1. package com.ydtech.modules.fnc.service.impl;
  2. import cn.afterturn.easypoi.excel.entity.ExportParams;
  3. import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
  4. import com.alibaba.fastjson.JSON;
  5. import com.alibaba.fastjson.JSONArray;
  6. import com.alipay.api.domain.VehicleIovData;
  7. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  8. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  9. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  10. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  11. import com.github.pagehelper.PageHelper;
  12. import com.github.pagehelper.PageInfo;
  13. import com.ydtech.constants.InsuranceEnum;
  14. import com.ydtech.constants.enums.dict.agreement.ProductsType;
  15. import com.ydtech.core.page.HttpResult;
  16. import com.ydtech.exception.SystemException;
  17. import com.ydtech.modules.admin.model.SysDept;
  18. import com.ydtech.modules.admin.model.SysUser;
  19. import com.ydtech.modules.admin.model.report.financialReceivables.*;
  20. import com.ydtech.modules.admin.service.SysUserService;
  21. import com.ydtech.modules.admin.utils.SliceUpDateUtil;
  22. import com.ydtech.modules.base.controller.BaseController;
  23. import com.ydtech.modules.esm.model.EsmInsCompany;
  24. import com.ydtech.modules.esm.model.EsmInsPackage;
  25. import com.ydtech.modules.esm.service.EsmInsCompanyService;
  26. import com.ydtech.modules.fnc.dao.FncInsAreaCompanyMapper;
  27. import com.ydtech.modules.fnc.dao.InsPlyIncomeMapper;
  28. import com.ydtech.modules.fnc.dto.InsPlyIncomePTCompanyDto;
  29. import com.ydtech.modules.fnc.dto.InsPlyIncomePTDto;
  30. import com.ydtech.modules.fnc.dto.InsuranceHandlingSettlementMonthDto;
  31. import com.ydtech.modules.fnc.dto.PlatformSettlementRecordDto;
  32. import com.ydtech.modules.fnc.entity.*;
  33. import com.ydtech.modules.fnc.service.*;
  34. import com.ydtech.modules.fnc.vo.*;
  35. import com.ydtech.modules.ins.model.vo.res.*;
  36. import com.ydtech.modules.inv.model.dto.*;
  37. import com.ydtech.modules.inv.model.excel.*;
  38. import com.ydtech.modules.inv.utils.CheckInsPlyComeUtils;
  39. import com.ydtech.modules.inv.utils.EasyExcelUtils;
  40. import com.ydtech.modules.inv.utils.ImportObjectUtils;
  41. import com.ydtech.modules.order.entity.BasePageResult;
  42. import com.ydtech.modules.order.entity.InsOrders;
  43. import com.ydtech.modules.order.entity.api.dajia.response.NVHLODR1001Response;
  44. import com.ydtech.modules.order.entity.api.zhongmei.response.SubmitResponse;
  45. import com.ydtech.modules.order.entity.crawler.response.CrawlerVerifyPaymentResponse;
  46. import com.ydtech.modules.order.entity.dto.DrivingInsuranceDto;
  47. import com.ydtech.modules.order.service.InsAreaCompanyService;
  48. import com.ydtech.modules.order.service.InsOrdersService;
  49. import com.ydtech.modules.protocol.entity.constants.PtlApiType;
  50. import com.ydtech.modules.protocol.entity.po.PtlAgreement;
  51. import com.ydtech.modules.protocol.entity.vo.PtlAgreementQueryVo;
  52. import com.ydtech.modules.protocol.service.PtlAgreementService;
  53. import com.ydtech.modules.protocols.entity.po.InsFeeOrderNew;
  54. import com.ydtech.modules.protocols.service.InsFeeOrderNewService;
  55. import com.ydtech.utils.BigDecimalUtils;
  56. import com.ydtech.utils.SnowFlakeUtil;
  57. import com.ydtech.utils.StringOperations;
  58. import com.ydtech.utils.excel.ExcelEasypoiUtils;
  59. import com.ydtech.utils.excel.ExcelStyleUtil;
  60. import lombok.extern.slf4j.Slf4j;
  61. import org.apache.commons.lang3.ObjectUtils;
  62. import org.apache.commons.lang3.StringUtils;
  63. import org.apache.ibatis.annotations.Param;
  64. import org.springframework.beans.BeanUtils;
  65. import org.springframework.beans.factory.annotation.Autowired;
  66. import org.springframework.beans.factory.annotation.Value;
  67. import org.springframework.context.annotation.Lazy;
  68. import org.springframework.stereotype.Service;
  69. import org.springframework.transaction.annotation.Transactional;
  70. import org.springframework.util.CollectionUtils;
  71. import org.springframework.web.multipart.MultipartFile;
  72. import javax.servlet.http.HttpServletRequest;
  73. import javax.servlet.http.HttpServletResponse;
  74. import java.io.IOException;
  75. import java.math.BigDecimal;
  76. import java.math.MathContext;
  77. import java.math.RoundingMode;
  78. import java.nio.file.Files;
  79. import java.nio.file.Path;
  80. import java.nio.file.Paths;
  81. import java.time.LocalDate;
  82. import java.time.LocalDateTime;
  83. import java.time.LocalTime;
  84. import java.time.YearMonth;
  85. import java.time.format.DateTimeFormatter;
  86. import java.util.*;
  87. import java.util.function.BinaryOperator;
  88. import java.util.function.Function;
  89. import java.util.stream.Collectors;
  90. /**
  91. * <p>
  92. * 保司结算手续费 服务实现类
  93. * </p>
  94. *
  95. * @author gws
  96. * @since 2024-01-05
  97. */
  98. @Slf4j
  99. @Service
  100. public class InsPlyIncomeServiceImpl extends ServiceImpl<InsPlyIncomeMapper, InsPlyIncome> implements InsPlyIncomeService {
  101. @Autowired
  102. @Lazy
  103. private InsOrdersService insOrdersService;
  104. @Autowired
  105. private SysUserService sysUserService;
  106. @Autowired
  107. private InsFeeOrderNewService insFeeOrderNewService;
  108. @Autowired
  109. private SettlementDocumentaryFeesService settlementDocumentaryFeesService;
  110. @Autowired
  111. private SettlementDocumentaryLogService settlementDocumentaryLogService;
  112. @Autowired
  113. private PtlAgreementService ptlAgreementService;
  114. @Autowired
  115. private EsmInsCompanyService EsmInsCompanyService;
  116. @Autowired
  117. private ImportAsyncService importAsyncService;
  118. @Autowired
  119. private IncomeTaskRelationshipService incomeTaskRelationshipService;
  120. @Autowired
  121. private SettlementDocumentaryFeesSumService settlementDocumentaryFeesSumService;
  122. @Autowired
  123. private InsPlyIncomeLogService insPlyIncomeLogService;
  124. @Value("${upload.file.path}")
  125. private String uploadPath;
  126. @Value("${upload.file.url}")
  127. private String uploadUrl;
  128. @Autowired
  129. private FncInsAreaCompanyMapper fncInsAreaCompanyMapper;
  130. @Autowired
  131. private InsuranceHandlingSettlementMonthService insuranceHandlingSettlementMonthService;
  132. public HttpResult<BasePageResult<InsPlyIncome>> queryplyIncome(InsPlyIncomeVo insPlyIncomeVo) {
  133. try {
  134. Page<InsOrders> page = new Page<>(insPlyIncomeVo.getPageNum(), insPlyIncomeVo.getPageSize());
  135. PageInfo<List<InsPlyIncome>> pageHelper = null;
  136. PageHelper.startPage(insPlyIncomeVo.getPageNum(), insPlyIncomeVo.getPageSize());
  137. List<InsPlyIncome> list = this.baseMapper.selectByCondition(insPlyIncomeVo);
  138. pageHelper = new PageInfo(list);
  139. BasePageResult<InsPlyIncome> pageResult = new BasePageResult<InsPlyIncome>(insPlyIncomeVo.getPageNum(),
  140. insPlyIncomeVo.getPageSize(), pageHelper.getTotal(), pageHelper.getPages(), list);
  141. return HttpResult.ok(pageResult);
  142. } catch (Exception e) {
  143. e.printStackTrace();
  144. return HttpResult.error("查询异常");
  145. }
  146. }
  147. @Override
  148. public void saveBalanceNew(InsOrders order, InsFeeOrderNew insFeeOrderNew, InsAreaCompany insAreaCompany, String leaderId, String leaderName) {
  149. if (ObjectUtils.isEmpty(order) || ObjectUtils.isEmpty(insFeeOrderNew) || ObjectUtils.isEmpty(insAreaCompany)) {
  150. return;
  151. }
  152. String agreeType = this.judgeAgreeType(insAreaCompany.getAgreementId());
  153. if (StringUtils.isNotEmpty(agreeType)) {
  154. // 判断协议类型 平台 保险
  155. if ("1".equals(agreeType)) {
  156. this.savePinTai(order, insFeeOrderNew, insAreaCompany, leaderId, leaderName); //手续费不分非车不非车 跟单也不分
  157. } else { // 保险 逻辑: 手续费生成一条 跟单费生成一条 非车手续费一条 非车跟单费一条
  158. if (((insFeeOrderNew.getJqSuperviseCostsPremiums() != null && insFeeOrderNew.getJqSuperviseCostsPremiums().compareTo(BigDecimal.ZERO) != 0)) || (insFeeOrderNew.getSySuperviseCostsPremiums() != null && insFeeOrderNew.getSySuperviseCostsPremiums().compareTo(BigDecimal.ZERO) != 0)) { //手续费
  159. this.saveInsuranceProcedures(order, insFeeOrderNew, insAreaCompany, leaderId, leaderName);
  160. }
  161. if (insFeeOrderNew.getJqOtherCostsPremiums() != null && insFeeOrderNew.getJqOtherCostsPremiums().compareTo(BigDecimal.ZERO) != 0) { //跟单费
  162. this.saveOtherAmount(order, insFeeOrderNew, insAreaCompany, leaderId, leaderName);
  163. }
  164. if (insFeeOrderNew.getNoSuperviseCostsPremiums() != null && insFeeOrderNew.getNoSuperviseCostsPremiums().compareTo(BigDecimal.ZERO) != 0) { // 非车手续费
  165. this.saveNoSupervise(order, insFeeOrderNew, insAreaCompany, leaderId, leaderName);
  166. }
  167. if (insFeeOrderNew.getNoOtherCostsPremiums() != null && insFeeOrderNew.getNoOtherCostsPremiums().compareTo(BigDecimal.ZERO) != 0) { // 非车跟单费
  168. this.saveNoOtherAmount(order, insFeeOrderNew, insAreaCompany, leaderId, leaderName);
  169. }
  170. }
  171. }
  172. }
  173. private void saveNoOtherAmount(InsOrders order, InsFeeOrderNew insFeeOrderNew, InsAreaCompany insAreaCompany, String leaderId, String leaderName) {
  174. InsPlyIncome insPlyIncome = new InsPlyIncome();
  175. insPlyIncome.setOrderno(insFeeOrderNew.getInsOrderNo()); // 子订单号
  176. String noPolicyno = this.setNoPolicyno(insAreaCompany);
  177. if (StringUtils.isNotEmpty(noPolicyno)) {
  178. insPlyIncome.setNoPolicyno(noPolicyno); // 非车保单号
  179. }
  180. insPlyIncome.setOtherFeevalue(insFeeOrderNew.getNoOtherCostsPremiums()); //非车跟单费
  181. insPlyIncome.setOtherFeerate(insFeeOrderNew.getNoOtherCostsProportion()); //非车跟单费用比例
  182. //add by hxl 2024-07-31 修改插入结算表中险种信息错误的bug 将大订单中的险种信息改为小订单的险种信息
  183. this.saveRiskCode(insAreaCompany.getProductid(), insPlyIncome);
  184. //this.saveRiskCode(order.getProductid(), insPlyIncome);
  185. insPlyIncome.setPayDate(insAreaCompany.getPayDate());
  186. insPlyIncome.setSignDate(insAreaCompany.getSigningTime());
  187. insPlyIncome.setCompanyId(insAreaCompany.getCompanyId());
  188. insPlyIncome.setAgreementId(insFeeOrderNew.getAgreementId());
  189. insPlyIncome.setLicenseno(order.getLicenseno());
  190. insPlyIncome.setTaxamount(insAreaCompany.getTaxamount());
  191. insPlyIncome.setNoTaxPremium(insFeeOrderNew.getNoNoTaxPremium());
  192. insPlyIncome.setCreateTime(LocalDateTime.now());
  193. insPlyIncome.setDocumentaryFeesStatus("0");
  194. insPlyIncome.setInsuredName(order.getInsuredname());
  195. insPlyIncome.setHandlingFeesStatus("0");
  196. insPlyIncome.setNoNoTaxPremium(insFeeOrderNew.getNoNoTaxPremium());
  197. insPlyIncome.setNoPremium(insFeeOrderNew.getNoPremium());
  198. insPlyIncome.setIsNotCar("1");
  199. insPlyIncome.setIsNotDocumentary("1");
  200. insPlyIncome.setJqStartDate(StringOperations.emptyStringToNull(insAreaCompany.getJqStartDate()));
  201. insPlyIncome.setJqEndDate(StringOperations.emptyStringToNull(insAreaCompany.getJqEndDate()));
  202. insPlyIncome.setSyStartDate(StringOperations.emptyStringToNull(insAreaCompany.getSyStartDate()));
  203. insPlyIncome.setSyEndDate(StringOperations.emptyStringToNull(insAreaCompany.getSyEndDate()));
  204. insPlyIncome.setReceivableAmount(insFeeOrderNew.getNoOtherCostsPremiums());
  205. insPlyIncome.setAllFeeValue(insFeeOrderNew.getNoOtherCostsPremiums());
  206. insPlyIncome.setNoOtherCostsPremium(insFeeOrderNew.getNoOtherCostsPremiums());
  207. insPlyIncome.setNoOtherCostsProportion(insFeeOrderNew.getNoOtherCostsProportion());
  208. insPlyIncome.setLeaderId(leaderId);
  209. insPlyIncome.setLeaderName(leaderName);
  210. this.saveByCompanyId(insFeeOrderNew, insAreaCompany.getCompanyId(), insPlyIncome);
  211. this.getDeptId(insPlyIncome);
  212. baseMapper.insert(insPlyIncome);
  213. InsPlyIncomeLog insPlyIncomeLog = new InsPlyIncomeLog();
  214. insPlyIncomeLog.setIncomeId(insPlyIncome.getId());
  215. BeanUtils.copyProperties(insPlyIncome,insPlyIncomeLog);
  216. insPlyIncomeLog.setId(null);
  217. insPlyIncomeLog.setOperationStatus("1");
  218. insPlyIncomeLogService.saveLog(insPlyIncomeLog); //添加日志
  219. }
  220. private void saveNoSupervise(InsOrders order, InsFeeOrderNew insFeeOrderNew, InsAreaCompany insAreaCompany, String leaderId, String leaderName) {
  221. InsPlyIncome insPlyIncome = new InsPlyIncome();
  222. insPlyIncome.setOrderno(insFeeOrderNew.getInsOrderNo()); // 子订单号
  223. insPlyIncome.setCommissionFeevalue(insFeeOrderNew.getNoSuperviseCostsPremiums());// 非车手续费
  224. insPlyIncome.setCommissionFeerate(insFeeOrderNew.getNoSuperviseCostsProportion());// 非车手续费比例
  225. String noPolicyno = this.setNoPolicyno(insAreaCompany);
  226. if (StringUtils.isNotEmpty(noPolicyno)) {
  227. insPlyIncome.setNoPolicyno(noPolicyno); // 非车保单号
  228. }
  229. // insPlyIncome.setDeptId(insFeeOrderNew.getDeptId());
  230. //add by hxl 2024-07-31 修改插入结算表中险种信息错误的bug 将大订单中的险种信息改为小订单的险种信息
  231. this.saveRiskCode(insAreaCompany.getProductid(), insPlyIncome);
  232. //this.saveRiskCode(order.getProductid(), insPlyIncome);
  233. insPlyIncome.setPayDate(insAreaCompany.getPayDate());
  234. insPlyIncome.setSignDate(insAreaCompany.getSigningTime());
  235. insPlyIncome.setCompanyId(insAreaCompany.getCompanyId());
  236. insPlyIncome.setAgreementId(insFeeOrderNew.getAgreementId());
  237. insPlyIncome.setLicenseno(order.getLicenseno());
  238. insPlyIncome.setTaxamount(insAreaCompany.getTaxamount());
  239. insPlyIncome.setCreateTime(LocalDateTime.now());
  240. insPlyIncome.setDocumentaryFeesStatus("0");
  241. insPlyIncome.setHandlingFeesStatus("0");
  242. insPlyIncome.setIsNotCar("1");
  243. insPlyIncome.setIsNotDocumentary("0");
  244. insPlyIncome.setAllFeeValue(insFeeOrderNew.getNoSuperviseCostsPremiums());
  245. insPlyIncome.setUserId(insFeeOrderNew.getUserId());
  246. insPlyIncome.setInsuredName(order.getInsuredname());
  247. insPlyIncome.setNoPremium(insFeeOrderNew.getNoPremium()); //非车保费
  248. insPlyIncome.setNoNoTaxPremium(insFeeOrderNew.getNoNoTaxPremium()); //非车不含税保费
  249. insPlyIncome.setJqStartDate(StringOperations.emptyStringToNull(insAreaCompany.getJqStartDate()));
  250. insPlyIncome.setJqEndDate(StringOperations.emptyStringToNull(insAreaCompany.getJqEndDate()));
  251. insPlyIncome.setSyStartDate(StringOperations.emptyStringToNull(insAreaCompany.getSyStartDate()));
  252. insPlyIncome.setSyEndDate(StringOperations.emptyStringToNull(insAreaCompany.getSyEndDate()));
  253. insPlyIncome.setNoSuperviseCostsPremiums(insFeeOrderNew.getNoSuperviseCostsPremiums());
  254. insPlyIncome.setNoSuperviseCostsProportion(insFeeOrderNew.getNoSuperviseCostsProportion());
  255. insPlyIncome.setLeaderId(leaderId);
  256. insPlyIncome.setLeaderName(leaderName);
  257. this.getDeptId(insPlyIncome);
  258. this.saveByCompanyId(insFeeOrderNew, insAreaCompany.getCompanyId(), insPlyIncome);
  259. insPlyIncome.setReceivableAmount(insFeeOrderNew.getNoSuperviseCostsPremiums());
  260. baseMapper.insert(insPlyIncome);
  261. InsPlyIncomeLog insPlyIncomeLog = new InsPlyIncomeLog();
  262. insPlyIncomeLog.setIncomeId(insPlyIncome.getId());
  263. BeanUtils.copyProperties(insPlyIncome,insPlyIncomeLog);
  264. insPlyIncomeLog.setId(null);
  265. insPlyIncomeLog.setOperationStatus("1");
  266. insPlyIncomeLogService.saveLog(insPlyIncomeLog); //添加日志
  267. }
  268. private void saveRiskCode(String productid, InsPlyIncome insPlyIncome) {
  269. if (ProductsType.PT_0330.getCode().equals(productid)) {
  270. insPlyIncome.setRiskcode(ProductsType.PT_0330.getDesc());
  271. }
  272. if (ProductsType.PT_034001.getCode().equals(productid)) {
  273. insPlyIncome.setRiskcode(ProductsType.PT_034001.getDesc());
  274. }
  275. if (ProductsType.PT_034002.getCode().equals(productid)) {
  276. insPlyIncome.setRiskcode(ProductsType.PT_034002.getDesc());
  277. }
  278. if (ProductsType.PT_0330034002.getCode().equals(productid)) {
  279. insPlyIncome.setRiskcode(ProductsType.PT_0330034002.getDesc());
  280. }
  281. if (ProductsType.PT_0330034001.getCode().equals(productid)) {
  282. insPlyIncome.setRiskcode(ProductsType.PT_0330034001.getDesc());
  283. }
  284. }
  285. private void saveOtherAmount(InsOrders order, InsFeeOrderNew insFeeOrderNew, InsAreaCompany insAreaCompany, String leaderId, String leaderName) {
  286. BigDecimal otherAmount = this.calculateTotal(insFeeOrderNew.getJqOtherCostsPremiums(), insFeeOrderNew.getSyOtherCostsPremiums(),
  287. null);
  288. BigDecimal otherProportion = this.calculateTotal(insFeeOrderNew.getSyOtherCostsProportion(),
  289. insFeeOrderNew.getJqOtherCostsProportion(), null);
  290. BigDecimal allNoTaxPremium = this.calculateTotal(insFeeOrderNew.getJqNoTaxPremium(), insFeeOrderNew.getSyNoTaxPremium(), null);
  291. //交强不含税保费
  292. BigDecimal allPremium = this.calculateTotal(insFeeOrderNew.getJqPremium(), insFeeOrderNew.getSyPremium(), null);// 总保费
  293. InsPlyIncome insPlyIncome = new InsPlyIncome(insFeeOrderNew.getInsOrderNo(), insAreaCompany.getJqpolicyno(),
  294. insAreaCompany.getSypolicyno(), null, null, null, null, order.getProductid(), insAreaCompany.getPayDate(),
  295. insAreaCompany.getSigningTime(), insAreaCompany.getCompanyId(), null, insFeeOrderNew.getAgreementId(), order.getLicenseno(),
  296. insAreaCompany.getTaxamount(),
  297. allNoTaxPremium, null, otherProportion, null, otherAmount, otherAmount, null, null, LocalDateTime.now(), null, null, null, "0"
  298. , "0", "0", "1");
  299. //add by hxl 2024-07-31 修改插入结算表中险种信息错误的bug 将大订单中的险种信息改为小订单的险种信息
  300. this.saveRiskCode(insAreaCompany.getProductid(), insPlyIncome);
  301. //this.saveRiskCode(order.getProductid(), insPlyIncome);
  302. insPlyIncome.setTaxPremium(allPremium);
  303. insPlyIncome.setJqPremium(insFeeOrderNew.getJqPremium());
  304. insPlyIncome.setSyPremium(insFeeOrderNew.getSyPremium());
  305. insPlyIncome.setJqNoTaxPremium(insFeeOrderNew.getJqNoTaxPremium());
  306. insPlyIncome.setSyNoTaxPremium(insFeeOrderNew.getSyNoTaxPremium());
  307. insPlyIncome.setJqOtherCostsProportion(insFeeOrderNew.getJqOtherCostsProportion()); //交强跟单费比例
  308. insPlyIncome.setSyOtherCostsProportion(insFeeOrderNew.getSyOtherCostsProportion()); //商业跟单费比例
  309. insPlyIncome.setSyOtherCostsPremium(insFeeOrderNew.getSyOtherCostsPremiums());
  310. insPlyIncome.setJqOtherCostsPremium(insFeeOrderNew.getJqOtherCostsPremiums());
  311. insPlyIncome.setJqStartDate(StringOperations.emptyStringToNull(insAreaCompany.getJqStartDate()));
  312. insPlyIncome.setJqEndDate(StringOperations.emptyStringToNull(insAreaCompany.getJqEndDate()));
  313. insPlyIncome.setSyStartDate(StringOperations.emptyStringToNull(insAreaCompany.getSyStartDate()));
  314. insPlyIncome.setSyEndDate(StringOperations.emptyStringToNull(insAreaCompany.getSyEndDate()));
  315. insPlyIncome.setLeaderId(leaderId);
  316. insPlyIncome.setLeaderName(leaderName);
  317. insPlyIncome.setUserId(insFeeOrderNew.getUserId());
  318. insPlyIncome.setInsuredName(order.getInsuredname());
  319. insPlyIncome.setReceivableAmount(otherAmount);
  320. this.getDeptId(insPlyIncome);
  321. this.saveByCompanyId(insFeeOrderNew, insAreaCompany.getCompanyId(), insPlyIncome);
  322. baseMapper.insert(insPlyIncome);
  323. InsPlyIncomeLog insPlyIncomeLog = new InsPlyIncomeLog();
  324. insPlyIncomeLog.setIncomeId(insPlyIncome.getId());
  325. BeanUtils.copyProperties(insPlyIncome,insPlyIncomeLog);
  326. insPlyIncomeLog.setId(null);
  327. insPlyIncomeLog.setOperationStatus("1");
  328. insPlyIncomeLogService.saveLog(insPlyIncomeLog); //添加日志
  329. }
  330. private void saveInsuranceProcedures(InsOrders order, InsFeeOrderNew insFeeOrderNew, InsAreaCompany insAreaCompany, String leaderId, String leaderName) {
  331. // 保险手续费
  332. BigDecimal handlingAmount = this.calculateTotal(insFeeOrderNew.getJqSuperviseCostsPremiums(),
  333. insFeeOrderNew.getSySuperviseCostsPremiums(), null);
  334. BigDecimal handlingProportion = this.calculateTotal(insFeeOrderNew.getJqSuperviseCostsProportion(),
  335. insFeeOrderNew.getSySuperviseCostsProportion(), null);
  336. BigDecimal allNoTaxPremium = this.calculateTotal(insFeeOrderNew.getJqNoTaxPremium(), insFeeOrderNew.getSyNoTaxPremium(), null);
  337. //不含税保费
  338. InsPlyIncome insPlyIncome = new InsPlyIncome(insFeeOrderNew.getInsOrderNo(), insAreaCompany.getJqpolicyno(),
  339. insAreaCompany.getSypolicyno(), null, null, null, null, order.getProductid(), insAreaCompany.getPayDate(),
  340. insAreaCompany.getSigningTime(), insAreaCompany.getCompanyId(), null, insFeeOrderNew.getAgreementId(), order.getLicenseno(),
  341. insAreaCompany.getTaxamount()
  342. , allNoTaxPremium, handlingProportion, null, handlingAmount, null, handlingAmount, null, null, LocalDateTime.now(), null,
  343. null, null, "0", "0", "0", "0");
  344. BigDecimal allTaxPremium = this.calculateTotal(insFeeOrderNew.getJqPremium(), insFeeOrderNew.getSyPremium(), null);
  345. insPlyIncome.setJqPremium(insFeeOrderNew.getJqPremium());
  346. insPlyIncome.setSyPremium(insFeeOrderNew.getSyPremium());
  347. insPlyIncome.setJqNoTaxPremium(insFeeOrderNew.getJqNoTaxPremium());
  348. insPlyIncome.setSyNoTaxPremium(insFeeOrderNew.getSyNoTaxPremium());
  349. insPlyIncome.setJqSuperviseCostsProportion(insFeeOrderNew.getJqSuperviseCostsProportion());
  350. insPlyIncome.setJqSuperviseCostsPremiums(insFeeOrderNew.getJqSuperviseCostsPremiums());
  351. insPlyIncome.setSySuperviseCostsProportion(insFeeOrderNew.getSySuperviseCostsProportion());
  352. insPlyIncome.setSySuperviseCostsPremiums(insFeeOrderNew.getSySuperviseCostsPremiums());
  353. //add by hxl 2024-07-31 修改插入结算表中险种信息错误的bug 将大订单中的险种信息改为小订单的险种信息
  354. this.saveRiskCode(insAreaCompany.getProductid(), insPlyIncome);
  355. //this.saveRiskCode(order.getProductid(), insPlyIncome);
  356. insPlyIncome.setTaxPremium(allTaxPremium);
  357. insPlyIncome.setUserId(insFeeOrderNew.getUserId());
  358. insPlyIncome.setInsuredName(order.getInsuredname());
  359. insPlyIncome.setJqStartDate(StringOperations.emptyStringToNull(insAreaCompany.getJqStartDate()));
  360. insPlyIncome.setJqEndDate(StringOperations.emptyStringToNull(insAreaCompany.getJqEndDate()));
  361. insPlyIncome.setSyStartDate(StringOperations.emptyStringToNull(insAreaCompany.getSyStartDate()));
  362. insPlyIncome.setSyEndDate(StringOperations.emptyStringToNull(insAreaCompany.getSyEndDate()));
  363. insPlyIncome.setReceivableAmount(handlingAmount);
  364. insPlyIncome.setLeaderId(leaderId);
  365. insPlyIncome.setLeaderName(leaderName);
  366. this.saveByCompanyId(insFeeOrderNew, insAreaCompany.getCompanyId(), insPlyIncome);
  367. this.getDeptId(insPlyIncome);
  368. baseMapper.insert(insPlyIncome);
  369. InsPlyIncomeLog insPlyIncomeLog = new InsPlyIncomeLog();
  370. insPlyIncomeLog.setIncomeId(insPlyIncome.getId());
  371. BeanUtils.copyProperties(insPlyIncome,insPlyIncomeLog);
  372. insPlyIncomeLog.setId(null);
  373. insPlyIncomeLog.setOperationStatus("1");
  374. insPlyIncomeLogService.saveLog(insPlyIncomeLog); //添加日志
  375. }
  376. private String setNoPolicyno(InsAreaCompany insAreaCompany) {
  377. if (insAreaCompany.getJypremium() == null || insAreaCompany.getJypremium().compareTo(BigDecimal.ZERO) == 0) { // 非车跟单费
  378. return null;
  379. }
  380. String crossInsurance = insAreaCompany.getCrossInsurance();
  381. if (StringUtils.isEmpty(crossInsurance)) {
  382. return null;
  383. }
  384. JSONArray objects = JSON.parseArray(crossInsurance);
  385. if (objects.isEmpty()) {
  386. return null;
  387. }
  388. if (ObjectUtils.isEmpty(insAreaCompany.getApiType()) || PtlApiType.PTL_API_2.getCode() == insAreaCompany.getApiType()) {
  389. List<CrawlerVerifyPaymentResponse.DrivingInsurancesDTO> drivingInsurancesDTOS = objects.toJavaList(CrawlerVerifyPaymentResponse.DrivingInsurancesDTO.class);
  390. return drivingInsurancesDTOS.get(0).getApplication();
  391. }
  392. // 永诚
  393. if(insAreaCompany.getCompanyId().contains(InsuranceEnum.AICS.getCode())){
  394. List<DrivingInsuranceDto> javaList = objects.toJavaList(DrivingInsuranceDto.class);
  395. return javaList.get(0).getPolicyNumber();
  396. }
  397. // 大家
  398. if(insAreaCompany.getCompanyId().contains(InsuranceEnum.DJPC.getCode())){
  399. List<NVHLODR1001Response.policyInfosDTO> javaList = objects.toJavaList(NVHLODR1001Response.policyInfosDTO.class);
  400. return javaList.get(0).getPlyNo();
  401. }
  402. // 国任
  403. if(insAreaCompany.getCompanyId().contains(InsuranceEnum.XDCX.getCode())){
  404. List<DrivingInsuranceDto> javaList = objects.toJavaList(DrivingInsuranceDto.class);
  405. return javaList.get(0).getPolicyNumber();
  406. }
  407. // 中煤
  408. if(insAreaCompany.getCompanyId().contains(InsuranceEnum.ZMBX.getCode())){
  409. List<SubmitResponse.AccidentNo> javaList = objects.toJavaList(SubmitResponse.AccidentNo.class);
  410. return javaList.get(0).getRideProposalNo();
  411. }
  412. // 紫金
  413. if(insAreaCompany.getCompanyId().contains(InsuranceEnum.ZKIC.getCode())){
  414. List<DrivingInsuranceDto> javaList = objects.toJavaList(DrivingInsuranceDto.class);
  415. return javaList.get(0).getPolicyNumber();
  416. }
  417. return null;
  418. }
  419. private void savePinTai(InsOrders order, InsFeeOrderNew insFeeOrderNew, InsAreaCompany insAreaCompany,String leaderId,String leaderName) {
  420. BigDecimal handlingAmount = this.calculateTotal(insFeeOrderNew.getJqSuperviseCostsPremiums(),
  421. insFeeOrderNew.getSySuperviseCostsPremiums(), insFeeOrderNew.getNoSuperviseCostsPremiums()); //手续费
  422. BigDecimal handlingProportion = this.calculateTotal(insFeeOrderNew.getJqSuperviseCostsProportion(),
  423. insFeeOrderNew.getSySuperviseCostsProportion(), insFeeOrderNew.getNoSuperviseCostsProportion());//手续费比例
  424. BigDecimal otherAmount = this.calculateTotal(insFeeOrderNew.getJqOtherCostsPremiums(), insFeeOrderNew.getSyOtherCostsPremiums(),
  425. insFeeOrderNew.getNoOtherCostsPremiums());//跟单费
  426. BigDecimal otherProportion = this.calculateTotal(insFeeOrderNew.getSyOtherCostsProportion(),
  427. insFeeOrderNew.getJqOtherCostsProportion(), insFeeOrderNew.getNoOtherCostsProportion()); //跟单费比例
  428. // 不含税保费
  429. BigDecimal allNoTaxPremium = this.calculateTotal(insFeeOrderNew.getJqNoTaxPremium(), insFeeOrderNew.getSyNoTaxPremium(),
  430. insFeeOrderNew.getNoNoTaxPremium());
  431. BigDecimal allAmount = this.calculateTotal(otherAmount, handlingAmount, null);
  432. BigDecimal jqReceivableProportion = this.calculateTotal(insFeeOrderNew.getJqSuperviseCostsProportion(),
  433. insFeeOrderNew.getJqOtherCostsProportion(), null);// 交强应收 比例
  434. BigDecimal syReceivableProportion = this.calculateTotal(insFeeOrderNew.getSySuperviseCostsProportion(),
  435. insFeeOrderNew.getSyOtherCostsProportion(), null);//商业应收比例
  436. BigDecimal noReceivableProportion = this.calculateTotal(insFeeOrderNew.getNoSuperviseCostsProportion(),
  437. insFeeOrderNew.getNoOtherCostsProportion(), null);
  438. String noPolicyno = this.setNoPolicyno(insAreaCompany);
  439. InsPlyIncome insPlyIncome = new InsPlyIncome(insFeeOrderNew.getInsOrderNo(), insAreaCompany.getJqpolicyno(),
  440. insAreaCompany.getSypolicyno(),
  441. noPolicyno, null, null, null, order.getProductid(), insAreaCompany.getPayDate(), insAreaCompany.getSigningTime(),
  442. insAreaCompany.getCompanyId(),
  443. null, insFeeOrderNew.getAgreementId(), order.getLicenseno(), insAreaCompany.getTaxamount(), allNoTaxPremium,
  444. handlingProportion,
  445. otherProportion, handlingAmount, otherAmount, allAmount, null, null, LocalDateTime.now(), null, null, null, "0", "0", "0", "0");
  446. insPlyIncome.setJqReceivableProportion(jqReceivableProportion);
  447. insPlyIncome.setSyReceivableProportion(syReceivableProportion);
  448. insPlyIncome.setNoReceivableProportion(noReceivableProportion);
  449. // 应收金额 = 商业手续费+商业跟单 + 交强手续费 +交强跟单费 + 非车手续费 + 非车跟单费 = allAmount
  450. insPlyIncome.setJqSuperviseCostsPremiums(insFeeOrderNew.getJqSuperviseCostsPremiums()); // 交强手续费
  451. insPlyIncome.setSySuperviseCostsPremiums(insFeeOrderNew.getSySuperviseCostsPremiums()); // 商业手续费
  452. insPlyIncome.setNoSuperviseCostsPremiums(insFeeOrderNew.getNoSuperviseCostsPremiums()); // 非车手续费
  453. insPlyIncome.setJqSuperviseCostsProportion(insFeeOrderNew.getJqSuperviseCostsProportion()); //交强手续费 比例
  454. insPlyIncome.setSySuperviseCostsProportion(insFeeOrderNew.getSySuperviseCostsProportion()); // 商业手续费 比例
  455. insPlyIncome.setNoSuperviseCostsProportion(insFeeOrderNew.getNoSuperviseCostsProportion());// 非车手续费 比例
  456. insPlyIncome.setJqOtherCostsProportion(insFeeOrderNew.getJqOtherCostsProportion()); //交强跟单费比例
  457. insPlyIncome.setSyOtherCostsProportion(insFeeOrderNew.getSyOtherCostsProportion()); //商业跟单费比例
  458. insPlyIncome.setNoOtherCostsProportion(insFeeOrderNew.getNoOtherCostsProportion()); //非车跟单费比例
  459. insPlyIncome.setJqPremium(insFeeOrderNew.getJqPremium());
  460. insPlyIncome.setSyPremium(insFeeOrderNew.getSyPremium());
  461. insPlyIncome.setNoPremium(insFeeOrderNew.getNoPremium());
  462. insPlyIncome.setReceivableAmount(allAmount);
  463. insPlyIncome.setJqNoTaxPremium(insFeeOrderNew.getJqNoTaxPremium());
  464. insPlyIncome.setSyNoTaxPremium(insFeeOrderNew.getSyNoTaxPremium());
  465. insPlyIncome.setNoNoTaxPremium(insFeeOrderNew.getNoNoTaxPremium());
  466. insPlyIncome.setUserId(insFeeOrderNew.getUserId());
  467. insPlyIncome.setJqStartDate(StringOperations.emptyStringToNull(insAreaCompany.getJqStartDate()));
  468. insPlyIncome.setJqEndDate(StringOperations.emptyStringToNull(insAreaCompany.getJqEndDate()));
  469. insPlyIncome.setSyStartDate(StringOperations.emptyStringToNull(insAreaCompany.getSyStartDate()));
  470. insPlyIncome.setSyEndDate(StringOperations.emptyStringToNull(insAreaCompany.getSyEndDate()));
  471. insPlyIncome.setLeaderId(leaderId);
  472. insPlyIncome.setLeaderName(leaderName);
  473. this.getDeptId(insPlyIncome);
  474. //add by hxl 2024-07-31 修改插入结算表中险种信息错误的bug 将大订单中的险种信息改为小订单的险种信息
  475. this.saveRiskCode(insAreaCompany.getProductid(), insPlyIncome);
  476. //this.saveRiskCode(order.getProductid(), insPlyIncome);
  477. insPlyIncome.setInsuredName(order.getInsuredname());
  478. this.saveByCompanyId(insFeeOrderNew, insAreaCompany.getCompanyId(), insPlyIncome);
  479. baseMapper.insert(insPlyIncome);
  480. InsPlyIncomeLog insPlyIncomeLog = new InsPlyIncomeLog();
  481. insPlyIncomeLog.setIncomeId(insPlyIncome.getId());
  482. BeanUtils.copyProperties(insPlyIncome,insPlyIncomeLog);
  483. insPlyIncomeLog.setId(null);
  484. insPlyIncomeLog.setOperationStatus("1");
  485. insPlyIncomeLogService.saveLog(insPlyIncomeLog); //添加日志
  486. }
  487. private void getDeptId(InsPlyIncome insPlyIncome) {
  488. PtlAgreement ptlAgreement = ptlAgreementService.getById(insPlyIncome.getAgreementId());
  489. String deptId = ptlAgreement.getDeptId();
  490. insPlyIncome.setDeptId(deptId);
  491. }
  492. private void saveByCompanyId(InsFeeOrderNew insFeeOrderNew, String companyId, InsPlyIncome insPlyIncome) {
  493. PtlAgreement ptlAgreementQueryVo = this.ptlAgreementService.getByAgreementIdNew(insFeeOrderNew.getAgreementId());
  494. if (ObjectUtils.isNotEmpty(ptlAgreementQueryVo)) {
  495. if (StringUtils.isNotEmpty(ptlAgreementQueryVo.getPartnerCompaniesId())) {
  496. // 合作公司id
  497. String partnerCompaniesId = ptlAgreementQueryVo.getPartnerCompaniesId();
  498. insPlyIncome.setPartnerCompaniesId(partnerCompaniesId);
  499. EsmInsCompany esmInsCompany = EsmInsCompanyService.getById(partnerCompaniesId);
  500. String name = esmInsCompany.getNamesimple(); //合作名称
  501. insPlyIncome.setPartnerCompaniesName(name);
  502. insPlyIncome.setPartnerCompaniesId(ptlAgreementQueryVo.getPartnerCompaniesId());
  503. }
  504. if (StringUtils.isNotEmpty(ptlAgreementQueryVo.getInsuranceCompanyId())) {
  505. String insuranceCompanyId = ptlAgreementQueryVo.getInsuranceCompanyId();
  506. EsmInsCompany esmInsCompany = EsmInsCompanyService.getById(insuranceCompanyId);
  507. String name = esmInsCompany.getNamesimple(); //保险公司名称 简称
  508. insPlyIncome.setCompanyName(name);
  509. }
  510. }
  511. }
  512. private BigDecimal calculateTotal(BigDecimal value1, BigDecimal value2, BigDecimal value3) {
  513. BigDecimal total = BigDecimal.ZERO;
  514. if (value1 != null) {
  515. total = total.add(value1);
  516. }
  517. if (value2 != null) {
  518. total = total.add(value2);
  519. }
  520. if (value3 != null) {
  521. total = total.add(value3);
  522. }
  523. return total;
  524. }
  525. private String judgeAgreeType(Long agreementId) {
  526. if (agreementId == null) {
  527. return null;
  528. }
  529. HttpResult<PtlAgreementQueryVo> byAgreementId = ptlAgreementService.getByAgreementId(agreementId.toString());
  530. if (byAgreementId != null && ObjectUtils.isNotEmpty(byAgreementId.getData())) {
  531. PtlAgreement agreement = byAgreementId.getData().getAgreement();
  532. String agreementType = agreement.getAgreementType();
  533. if (StringUtils.isNotEmpty(agreementType)) {
  534. return agreementType;
  535. }
  536. }
  537. return null;
  538. }
  539. public HttpResult<BasePageResult<InsPlyIncome>> queryNew(InsPlyIncomeVo insPlyIncomeVo) {
  540. try {
  541. HashMap<String, Object> params = new HashMap<>();
  542. PageInfo<List<InsPlyIncome>> pageHelper = null;
  543. PageHelper.startPage(insPlyIncomeVo.getPageNum(), insPlyIncomeVo.getPageSize());
  544. params.put("pageNum", insPlyIncomeVo.getPageNum());
  545. params.put("pageSize", insPlyIncomeVo.getPageSize());
  546. params = this.saveParams(insPlyIncomeVo, params);
  547. if (StringUtils.isNotEmpty(insPlyIncomeVo.getIds())) {
  548. params.put("ids", insPlyIncomeVo.getIds().split(","));
  549. }
  550. if (StringUtils.isNotEmpty(insPlyIncomeVo.getId())) {
  551. SettlementDocumentaryFeesEntity settlementDocumentaryFeesEntity =
  552. settlementDocumentaryFeesService.getById(insPlyIncomeVo.getId());
  553. // 通过任务id查询 明细
  554. String taskId = settlementDocumentaryFeesEntity.getTaskId();
  555. List<String> incomeIds = incomeTaskRelationshipService.getByTaskId(taskId);
  556. if (!CollectionUtils.isEmpty(incomeIds)) {
  557. params.put("incomeIds", incomeIds);
  558. params.remove("handlingFeesStatus");
  559. params.remove("id");
  560. }
  561. }
  562. List<InsPlyIncome> list = this.baseMapper.queryNew(params);
  563. pageHelper = new PageInfo(list);
  564. BasePageResult<InsPlyIncome> pageResult = new BasePageResult<InsPlyIncome>(insPlyIncomeVo.getPageNum(),
  565. insPlyIncomeVo.getPageSize(), pageHelper.getTotal(), pageHelper.getPages(), list);
  566. return HttpResult.ok(pageResult);
  567. } catch (Exception e) {
  568. e.printStackTrace();
  569. return HttpResult.error("查询异常");
  570. }
  571. }
  572. @Override
  573. public HashMap<String, Object> totalAmount(List<String> selectIds) {
  574. HashMap<String, Object> params = new HashMap<>();
  575. params.put("selectIds", selectIds);
  576. HashMap<String, Object> resultMap = baseMapper.totalAmount(params);
  577. return resultMap;
  578. }
  579. @Override
  580. @Transactional
  581. public HttpResult<Object> batchPinBalance(InsPlyIncomeVo insPlyIncomeVo) {
  582. LocalDateTime now = LocalDateTime.now();
  583. if (!CollectionUtils.isEmpty(insPlyIncomeVo.getSelectIds())) {
  584. List<String> selectIds = insPlyIncomeVo.getSelectIds();
  585. for (String id : selectIds) {
  586. InsPlyIncome insPlyIncome = new InsPlyIncome();
  587. insPlyIncome.setHandlingFeesStatus("1");
  588. insPlyIncome.setSettlementTime(now);
  589. insPlyIncome.setSettlementUserId(BaseController.getUser().getId());
  590. insPlyIncome.setId(id);
  591. baseMapper.updateById(insPlyIncome);
  592. }
  593. }
  594. SettlementDocumentaryLogEntity settlementDocumentaryLogEntity = new SettlementDocumentaryLogEntity();
  595. settlementDocumentaryLogEntity.setIds(insPlyIncomeVo.getIds());
  596. // settlementDocumentaryLogEntity.setCompanyId(insPlyIncomeVo.getCompanyId());
  597. settlementDocumentaryLogEntity.setAmount(insPlyIncomeVo.getOtherFeevalue()); //跟单费金额
  598. settlementDocumentaryLogEntity.setHandingAmount(insPlyIncomeVo.getCommissionFeevalue()); //手续费金额
  599. settlementDocumentaryLogEntity.setCreateTime(new Date());
  600. settlementDocumentaryLogService.save(settlementDocumentaryLogEntity);
  601. return HttpResult.ok();
  602. }
  603. @Override
  604. public List<InsPlyIncome> totalPinAmount(InsPlyIncomeVo insPlyIncomeVo) {
  605. HashMap<String, Object> params = new HashMap<>();
  606. params = this.saveParams(insPlyIncomeVo, params);
  607. List<InsPlyIncome> result = baseMapper.totalPinAmount(params);
  608. return result;
  609. }
  610. private HashMap<String, Object> saveParams(InsPlyIncomeVo insPlyIncomeVo, HashMap<String, Object> params) {
  611. if (ObjectUtils.isNotEmpty(insPlyIncomeVo.getId())) {
  612. params.put("id", insPlyIncomeVo.getId());
  613. }
  614. if (ObjectUtils.isNotEmpty(insPlyIncomeVo.getStartDate())) {
  615. params.put("startDate", insPlyIncomeVo.getStartDate().toString());
  616. }
  617. if (ObjectUtils.isNotEmpty(insPlyIncomeVo.getEndDate())) {
  618. params.put("endDate", insPlyIncomeVo.getEndDate().toString());
  619. }
  620. if (StringUtils.isNotEmpty(insPlyIncomeVo.getOrderno())) {
  621. params.put("orderno", insPlyIncomeVo.getOrderno());
  622. }
  623. if (StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotDocumentary())) {
  624. params.put("isOther", insPlyIncomeVo.getIsNotDocumentary());
  625. }
  626. if (StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotCar())) {
  627. params.put("isNotCar", insPlyIncomeVo.getIsNotCar());
  628. }
  629. if (StringUtils.isNotEmpty(insPlyIncomeVo.getAgreementType())) {
  630. params.put("agreementType", insPlyIncomeVo.getAgreementType());
  631. }
  632. if (StringUtils.isNotEmpty(insPlyIncomeVo.getLicenseno())) {
  633. params.put("licenseno", insPlyIncomeVo.getLicenseno());
  634. }
  635. if (StringUtils.isNotEmpty(insPlyIncomeVo.getUserId())) {
  636. params.put("userId", insPlyIncomeVo.getUserId());
  637. }
  638. if (StringUtils.isNotEmpty(insPlyIncomeVo.getCompanyId())) {
  639. params.put("companyId", insPlyIncomeVo.getCompanyId());
  640. }
  641. if (StringUtils.isNotEmpty(insPlyIncomeVo.getRiskcode())) {
  642. params.put("riskcode", insPlyIncomeVo.getRiskcode());
  643. }
  644. if (StringUtils.isNotEmpty(insPlyIncomeVo.getPolicyno())) {
  645. params.put("policyno", insPlyIncomeVo.getPolicyno());
  646. }
  647. if (StringUtils.isNotEmpty(insPlyIncomeVo.getSyPolicyno())) {
  648. params.put("syPolicyno", insPlyIncomeVo.getSyPolicyno());
  649. }
  650. if (StringUtils.isNotEmpty(insPlyIncomeVo.getNoPolicyno())) {
  651. params.put("noPolicyno", insPlyIncomeVo.getNoPolicyno());
  652. }
  653. if (insPlyIncomeVo.getCreateTime() != null) {
  654. params.put("createTime", insPlyIncomeVo.getCreateTime().toString());
  655. }
  656. if (insPlyIncomeVo.getSettlementTime() != null) {
  657. params.put("settlementTime", insPlyIncomeVo.getSettlementTime().toString());
  658. }
  659. if (StringUtils.isNotEmpty(insPlyIncomeVo.getHandlingFeesStatus())) {
  660. params.put("handlingFeesStatus", insPlyIncomeVo.getHandlingFeesStatus());
  661. }
  662. if (StringUtils.isNotEmpty(insPlyIncomeVo.getPartnerCompaniesId())) {
  663. params.put("partnerCompaniesId", insPlyIncomeVo.getPartnerCompaniesId());
  664. }
  665. if (StringUtils.isNotEmpty(insPlyIncomeVo.getYear())) {
  666. params.put("year", insPlyIncomeVo.getYear());
  667. }
  668. if (StringUtils.isNotEmpty(insPlyIncomeVo.getMonth())) {
  669. params.put("month", insPlyIncomeVo.getMonth());
  670. }
  671. if (StringUtils.isNotEmpty(insPlyIncomeVo.getDay())) {
  672. params.put("day", insPlyIncomeVo.getDay());
  673. }
  674. if (StringUtils.isNotEmpty(insPlyIncomeVo.getSignDateEnd())) {
  675. params.put("signDateEnd", insPlyIncomeVo.getSignDateEnd());
  676. }
  677. if (StringUtils.isNotEmpty(insPlyIncomeVo.getSignDateStart())) {
  678. params.put("signDateStart", insPlyIncomeVo.getSignDateStart());
  679. }
  680. if (StringUtils.isNotEmpty(insPlyIncomeVo.getCompanyName())) {
  681. params.put("companyName", insPlyIncomeVo.getCompanyName());
  682. }
  683. if (StringUtils.isNotEmpty(insPlyIncomeVo.getInsuredName())) {
  684. params.put("insuredName", insPlyIncomeVo.getInsuredName());
  685. }
  686. if (StringUtils.isNotEmpty(insPlyIncomeVo.getPartnerCompaniesName())) {
  687. params.put("partnerCompaniesName", insPlyIncomeVo.getPartnerCompaniesName());
  688. }
  689. if (StringUtils.isNotEmpty(insPlyIncomeVo.getDockingPerson())) {
  690. params.put("dockingPerson", insPlyIncomeVo.getDockingPerson());
  691. }
  692. if (StringUtils.isNotEmpty(insPlyIncomeVo.getYeartsStart()) && StringUtils.isNotEmpty(insPlyIncomeVo.getYeartsEnd())) {
  693. params.put("yeartsStart", insPlyIncomeVo.getYeartsStart());
  694. params.put("yeartsEnd", insPlyIncomeVo.getYeartsEnd());
  695. }
  696. if (insPlyIncomeVo.getJqStartDate() != null) {
  697. params.put("jqStartDate", insPlyIncomeVo.getJqStartDate());
  698. }
  699. if (insPlyIncomeVo.getJqStartDate() != null) {
  700. params.put("jqEndDate", insPlyIncomeVo.getJqEndDate());
  701. }
  702. if (insPlyIncomeVo.getSyStartDate() != null) {
  703. params.put("syStartDate", insPlyIncomeVo.getSyStartDate());
  704. }
  705. if (insPlyIncomeVo.getSyEndDate() != null) {
  706. params.put("syEndDate", insPlyIncomeVo.getSyEndDate());
  707. }
  708. if (StringUtils.isNotEmpty(insPlyIncomeVo.getProvinceId())) {
  709. params.put("provinceId", insPlyIncomeVo.getProvinceId());
  710. }
  711. if (StringUtils.isNotEmpty(insPlyIncomeVo.getCityId())) {
  712. params.put("cityId", insPlyIncomeVo.getCityId());
  713. }
  714. if (StringUtils.isNotEmpty(insPlyIncomeVo.getCountyId())) {
  715. params.put("countyId", insPlyIncomeVo.getCountyId());
  716. }
  717. if (StringUtils.isNotEmpty(insPlyIncomeVo.getDeptId())) {
  718. params.put("deptId", insPlyIncomeVo.getDeptId());
  719. }
  720. if (StringUtils.isNotEmpty(insPlyIncomeVo.getAllPartnerCompaniesId())) {
  721. params.put("allPartnerCompaniesId", insPlyIncomeVo.getAllPartnerCompaniesId().substring(0, 5));
  722. }
  723. if (StringUtils.isNotEmpty(insPlyIncomeVo.getProvincePartnerCompaniesId())) {
  724. params.put("provincePartnerCompaniesId", insPlyIncomeVo.getProvincePartnerCompaniesId());
  725. }
  726. if (!CollectionUtils.isEmpty(insPlyIncomeVo.getSelectIds())) {
  727. params.put("selectIds", insPlyIncomeVo.getSelectIds());
  728. }
  729. if (!CollectionUtils.isEmpty(insPlyIncomeVo.getPartnerCompaniesIdList())) {
  730. params.put("partnerCompaniesIdList", insPlyIncomeVo.getPartnerCompaniesIdList());
  731. }
  732. if(StringUtils.isNotEmpty(insPlyIncomeVo.getCreateTimeQuery())){
  733. params.put("createTimeQuery", insPlyIncomeVo.getCreateTimeQuery());
  734. }
  735. if(StringUtils.isNotEmpty(insPlyIncomeVo.getSettlementDate())){
  736. params.put("settlementDate", insPlyIncomeVo.getSettlementDate());
  737. }
  738. if(StringUtils.isNotEmpty(insPlyIncomeVo.getIsExternal())){
  739. params.put("isExternal", insPlyIncomeVo.getIsExternal());
  740. }
  741. if(StringUtils.isNotEmpty(insPlyIncomeVo.getCreateTimeEnd())){
  742. params.put("createTimeEnd", insPlyIncomeVo.getCreateTimeEnd());
  743. }
  744. if(StringUtils.isNotEmpty(insPlyIncomeVo.getCreateTimeStart())){
  745. params.put("createTimeStart", insPlyIncomeVo.getCreateTimeStart());
  746. }
  747. if(StringUtils.isNotEmpty(insPlyIncomeVo.getStatus())){
  748. params.put("status", insPlyIncomeVo.getStatus());
  749. }
  750. if(StringUtils.isNotBlank(insPlyIncomeVo.getAddType())){
  751. params.put("addType", insPlyIncomeVo.getAddType());
  752. }
  753. return params;
  754. }
  755. @Override
  756. public HttpResult<BasePageResult<InsPlyIncome>> nonSettlementQuery(InsPlyIncomeVo insPlyIncomeVo) {
  757. try {
  758. HashMap<String, Object> params = new HashMap<>();
  759. PageInfo<List<InsPlyIncome>> pageHelper = null;
  760. PageHelper.startPage(insPlyIncomeVo.getPageNum(), insPlyIncomeVo.getPageSize());
  761. params.put("pageNum", insPlyIncomeVo.getPageNum());
  762. params.put("pageSize", insPlyIncomeVo.getPageSize());
  763. if (StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotCar())) {
  764. params.put("isNotCar", insPlyIncomeVo.getIsNotCar());
  765. }
  766. if (StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotDocumentary())) {
  767. params.put("isOther", insPlyIncomeVo.getIsNotDocumentary());
  768. }
  769. if (StringUtils.isNotEmpty(insPlyIncomeVo.getYear())) {
  770. params.put("year", insPlyIncomeVo.getYear());
  771. }
  772. if (StringUtils.isNotEmpty(insPlyIncomeVo.getMonth())) {
  773. params.put("month", insPlyIncomeVo.getMonth());
  774. }
  775. if (StringUtils.isNotEmpty(insPlyIncomeVo.getDocumentaryFeesStatus())) {
  776. params.put("documentaryFeesStatus", insPlyIncomeVo.getDocumentaryFeesStatus());
  777. }
  778. List<InsPlyIncome> list = this.baseMapper.NonSettlementQuery(params);
  779. pageHelper = new PageInfo(list);
  780. BasePageResult<InsPlyIncome> pageResult = new BasePageResult<InsPlyIncome>(insPlyIncomeVo.getPageNum(),
  781. insPlyIncomeVo.getPageSize(), pageHelper.getTotal(), pageHelper.getPages(), list);
  782. return HttpResult.ok(pageResult);
  783. } catch (Exception e) {
  784. e.printStackTrace();
  785. return HttpResult.error("查询异常");
  786. }
  787. }
  788. @Override
  789. public HttpResult<List<InsPlyIncome>> nonSettldetail(InsPlyIncomeVo insPlyIncomeVo) {
  790. try {
  791. String ids = insPlyIncomeVo.getIds();
  792. ArrayList<InsPlyIncome> resultList = new ArrayList<>();
  793. if (ObjectUtils.isNotEmpty(ids)) {
  794. String[] split = ids.split(",");
  795. for (int i = 0; i < split.length; i++) {
  796. String id = split[i];
  797. resultList.add(this.baseMapper.getById(id));
  798. }
  799. }
  800. return HttpResult.ok(resultList);
  801. } catch (Exception e) {
  802. e.printStackTrace();
  803. return HttpResult.error("查询异常");
  804. }
  805. }
  806. /**
  807. * @param multipartFile
  808. * @return totalAmount 总金额
  809. * totalHandingAmount 总手续费金额
  810. * totalOtherAmount 总跟单费金额
  811. * resultHashMap 返回 ids 已经上面的金额
  812. * resultNoSelect 未匹配的车牌号
  813. */
  814. @Override
  815. public HashMap<String, Object> importData(MultipartFile multipartFile) {
  816. BigDecimal totalAmount = BigDecimal.ZERO;
  817. BigDecimal totalHandingAmount = BigDecimal.ZERO;
  818. BigDecimal totalOtherAmount = BigDecimal.ZERO;
  819. HashMap<String, Object> resultHashMap = new HashMap<>();
  820. HashSet<String> partnerCompaniesIdSet = new HashSet<>();
  821. List<String> ids = new ArrayList<>();
  822. LocalDateTime now = LocalDateTime.now();
  823. ArrayList<HashMap<String, Object>> resultNoSelect = new ArrayList<>();
  824. try {
  825. List<InsPlyIncomeExcelDto> dtoList = ExcelEasypoiUtils.importExcel(multipartFile, InsPlyIncomeExcelDto.class, 0, 1, 1);
  826. for (InsPlyIncomeExcelDto excelItem : dtoList) {
  827. String reason ="";
  828. HashMap<String, Object> objectObjectHashMap = new HashMap<>();
  829. if (StringUtils.isNotEmpty(excelItem.getLicenseno())) {
  830. objectObjectHashMap.put("licenseno", excelItem.getLicenseno());//车牌号
  831. }
  832. if (StringUtils.isNotEmpty(excelItem.getPolicyno())) {
  833. objectObjectHashMap.put("policyno", excelItem.getPolicyno()); //交强保单号
  834. }
  835. if (StringUtils.isNotEmpty(excelItem.getSyPolicyno())) {
  836. objectObjectHashMap.put("syPolicyno", excelItem.getSyPolicyno());//商业保单号
  837. }
  838. if (StringUtils.isNotEmpty(excelItem.getNoPolicyno())) {
  839. objectObjectHashMap.put("noPolicyno", excelItem.getNoPolicyno()); //非车保单号
  840. }
  841. objectObjectHashMap.put("agreementType","1");
  842. InsPlyIncome insPlyIncome = baseMapper.findByLicenseno(objectObjectHashMap);
  843. if (ObjectUtils.isNotEmpty(insPlyIncome)) {
  844. // 如果能查询出来则 修改结算 变成已结算
  845. if(excelItem.getJqReceivableProportion()!=null && excelItem.getJqReceivableProportion().compareTo(BigDecimal.ZERO) !=0 ){
  846. objectObjectHashMap.put("jqReceivableProportion", excelItem.getJqReceivableProportion()); //非车保单号
  847. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(objectObjectHashMap);
  848. if(insPlyIncomes.isEmpty()){
  849. reason="交强应收比例错误!";
  850. }
  851. }
  852. if(excelItem.getSyReceivableProportion()!=null && excelItem.getSyReceivableProportion().compareTo(BigDecimal.ZERO) !=0 ){
  853. objectObjectHashMap.put("syReceivableProportion", excelItem.getSyReceivableProportion()); //非车保单号
  854. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(objectObjectHashMap);
  855. if(insPlyIncomes.isEmpty() && StringUtils.isEmpty(reason)){
  856. reason="商业应收比例错误!";
  857. }
  858. }
  859. if(excelItem.getNoReceivableProportion()!=null && excelItem.getNoReceivableProportion().compareTo(BigDecimal.ZERO) !=0 ){
  860. objectObjectHashMap.put("noReceivableProportion", excelItem.getNoReceivableProportion()); //非车保单号
  861. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(objectObjectHashMap);
  862. if(insPlyIncomes.isEmpty() && StringUtils.isEmpty(reason)){
  863. reason="非车应收比例错误!";
  864. }
  865. }
  866. //判断是否是相同保司机构
  867. partnerCompaniesIdSet.add(insPlyIncome.getPartnerCompaniesId());
  868. if(StringUtils.isNotEmpty(reason)){
  869. objectObjectHashMap.put("reason",reason);
  870. resultNoSelect.add(objectObjectHashMap); // 添加未匹配的车牌号
  871. }else {
  872. ids.add(insPlyIncome.getId());
  873. if (insPlyIncome.getAllFeeValue() != null && insPlyIncome.getAllFeeValue().compareTo(BigDecimal.ZERO) != 0) {
  874. totalAmount = totalAmount.add(insPlyIncome.getAllFeeValue()); //总金额
  875. }
  876. if (insPlyIncome.getCommissionFeevalue() != null && insPlyIncome.getCommissionFeevalue().compareTo(BigDecimal.ZERO) != 0) {
  877. totalHandingAmount = totalHandingAmount.add(insPlyIncome.getCommissionFeevalue()); //总手续费
  878. }
  879. if (insPlyIncome.getOtherFeevalue() != null && insPlyIncome.getOtherFeevalue().compareTo(BigDecimal.ZERO) != 0) {
  880. totalOtherAmount = totalOtherAmount.add(insPlyIncome.getOtherFeevalue()); //总跟单费
  881. }
  882. }
  883. } else {
  884. objectObjectHashMap.put("reason","未查询车辆");
  885. resultNoSelect.add(objectObjectHashMap); // 添加未匹配的车牌号
  886. }
  887. }
  888. // if(partnerCompaniesIdSet.size()>1){
  889. // throw new SystemException("表里有不同保司机构");
  890. // }
  891. resultHashMap.put("totalAmount", totalAmount);
  892. resultHashMap.put("totalHandingAmount", totalHandingAmount);
  893. resultHashMap.put("totalOtherAmount", totalOtherAmount);
  894. resultHashMap.put("resultList", resultNoSelect);
  895. resultHashMap.put("settIdList",ids);
  896. return resultHashMap;
  897. } catch (IOException e) {
  898. throw new SystemException("导入失败!");
  899. }
  900. }
  901. /**
  902. * @param multipartFile
  903. * @return resultList 包含总金额 还有 未匹配表中的数据
  904. */
  905. @Override
  906. public HashMap<String, Object> bxImportData(MultipartFile multipartFile, String isNotCar) {
  907. BigDecimal totalAmount = BigDecimal.ZERO;
  908. HashMap<String, Object> params = new HashMap<>();
  909. ArrayList<HashMap<String, Object>> resultList = new ArrayList<>();
  910. HashMap<String, Object> resultMap = new HashMap<>();
  911. StringBuffer strBuilder = new StringBuffer();
  912. boolean open = true;
  913. String ids = "";
  914. try {
  915. List<InsBxPlyIncomeExcelDto> dtoList = ExcelEasypoiUtils.importExcel(multipartFile, InsBxPlyIncomeExcelDto.class, 0, 1, 1);
  916. Integer i = 0;
  917. if (!CollectionUtils.isEmpty(dtoList)) {
  918. for (InsBxPlyIncomeExcelDto excelItem : dtoList) {
  919. String reason = "";
  920. i = i + 1;
  921. params.clear();
  922. if (StringUtils.isNotEmpty(excelItem.getLicenseno())) {
  923. String licenseno = excelItem.getLicenseno();//车牌号
  924. params.put("licenseno", licenseno);
  925. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  926. if (ObjectUtils.isEmpty(byBxLicenseno)) {
  927. reason = "该数据车牌号有问题";
  928. }
  929. }
  930. if (StringUtils.isNotEmpty(excelItem.getPolicyno())) {
  931. String policyno = excelItem.getPolicyno(); //交强保单号
  932. params.put("policyno", policyno);
  933. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  934. if (ObjectUtils.isEmpty(byBxLicenseno)) {
  935. reason = "该数据交强保单号有问题";
  936. }
  937. }
  938. if (StringUtils.isNotEmpty(excelItem.getSyPolicyno())) {
  939. String syPolicyno = excelItem.getSyPolicyno(); //商业保单号
  940. params.put("syPolicyno", syPolicyno);
  941. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  942. if (ObjectUtils.isEmpty(byBxLicenseno)) {
  943. reason = "该数据商业保单号有问题";
  944. }
  945. }
  946. if (excelItem.getJqSuperviseCostsProportion() != null && excelItem.getJqSuperviseCostsProportion().compareTo(BigDecimal.ZERO) != 0) {
  947. params.put("jqSuperviseCostsProportion", excelItem.getJqSuperviseCostsProportion());
  948. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  949. if (ObjectUtils.isEmpty(byBxLicenseno)) {
  950. reason = "该数据交强手续费比例有问题";
  951. }
  952. }
  953. if (excelItem.getSySuperviseCostsProportion() != null && excelItem.getSySuperviseCostsProportion().compareTo(BigDecimal.ZERO) != 0) {
  954. params.put("sySuperviseCostsProportion", excelItem.getSySuperviseCostsProportion());
  955. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  956. if (ObjectUtils.isEmpty(byBxLicenseno)) {
  957. reason = "该数据商业手续费比例有问题";
  958. }
  959. }
  960. // 只查手续费
  961. params.put("isOther", "0");
  962. params.put("isNotCar", isNotCar);
  963. InsPlyIncome insPlyIncome = baseMapper.findByBxLicenseno(params);
  964. if (ObjectUtils.isNotEmpty(insPlyIncome) && open) {
  965. open = false;
  966. resultMap.put("companyId", insPlyIncome.getCompanyId()); // 保险公司id
  967. resultMap.put("partnerCompaniesId", insPlyIncome.getPartnerCompaniesId()); //合作公司id
  968. resultMap.put("agreementId", insPlyIncome.getAgreementId()); //协议id
  969. }
  970. if (ObjectUtils.isNotEmpty(insPlyIncome)) { // 比配上汇总金额 未匹配则返回到数据当中
  971. strBuilder.append(insPlyIncome.getId()).append(",");
  972. if (insPlyIncome.getCommissionFeevalue() != null && insPlyIncome.getCommissionFeevalue().compareTo(BigDecimal.ZERO) != 0) {
  973. totalAmount = totalAmount.add(insPlyIncome.getCommissionFeevalue()); //添加总手续费
  974. }
  975. } else {
  976. HashMap<String, Object> noMatching = new HashMap<>();
  977. if (StringUtils.isNotEmpty(excelItem.getLicenseno())) {
  978. noMatching.put("licenseno", excelItem.getLicenseno());
  979. }
  980. if (StringUtils.isNotEmpty(excelItem.getPolicyno())) {
  981. noMatching.put("policyno", excelItem.getPolicyno());
  982. }
  983. if (StringUtils.isNotEmpty(excelItem.getSyPolicyno())) {
  984. noMatching.put("syPolicyno", excelItem.getSyPolicyno());
  985. }
  986. resultList.add(noMatching);
  987. }
  988. resultMap.put("reason", reason);
  989. }
  990. }
  991. if (strBuilder.length() > 0) {
  992. ids = strBuilder.deleteCharAt(strBuilder.length() - 1).toString();
  993. }
  994. resultMap.put("ids", ids);
  995. resultMap.put("totalAmount", totalAmount);
  996. resultMap.put("resultList", resultList);
  997. return resultMap;
  998. } catch (IOException e) {
  999. throw new SystemException("导入失败!");
  1000. }
  1001. }
  1002. @Override
  1003. public HashMap<String, Object> bxImportNoData(MultipartFile multipartFile, String isNotCar) {
  1004. BigDecimal totalAmount = BigDecimal.ZERO;
  1005. HashMap<String, Object> params = new HashMap<>();
  1006. HashMap<String, Object> resultMap = new HashMap<>();
  1007. ArrayList<HashMap<String, Object>> resultList = new ArrayList<>();
  1008. StringBuffer strBuilder = new StringBuffer();
  1009. String ids = "";
  1010. try {
  1011. Integer i = 0;
  1012. List<InsBxNoPlyIncomeExcelDto> dtoList = ExcelEasypoiUtils.importExcel(multipartFile, InsBxNoPlyIncomeExcelDto.class, 0, 1, 1);
  1013. if (!CollectionUtils.isEmpty(dtoList)) {
  1014. for (InsBxNoPlyIncomeExcelDto excelItem : dtoList) {
  1015. String reason = "";
  1016. i = i + 1;
  1017. params.clear();
  1018. if (StringUtils.isNotEmpty(excelItem.getLicenseno())) {
  1019. String licenseno = excelItem.getLicenseno();//车牌号
  1020. params.put("licenseno", licenseno);
  1021. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  1022. if (ObjectUtils.isEmpty(byBxLicenseno)) {
  1023. reason = "该数据车牌号有问题";
  1024. }
  1025. }
  1026. if (StringUtils.isNotEmpty(excelItem.getNoPolicyno())) {
  1027. String policyno = excelItem.getNoPolicyno(); //非车保单号
  1028. params.put("NoPolicyno", policyno);
  1029. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  1030. if (ObjectUtils.isEmpty(byBxLicenseno)) {
  1031. reason = "该数据非车保单号有问题";
  1032. }
  1033. }
  1034. if (excelItem.getNoSuperviseCostsProportion() != null && excelItem.getNoSuperviseCostsProportion().compareTo(BigDecimal.ZERO) != 0) {
  1035. params.put("noSuperviseCostsProportion", excelItem.getNoSuperviseCostsProportion());
  1036. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  1037. if (ObjectUtils.isEmpty(byBxLicenseno)) {
  1038. reason = "该数据非车手续费比例有问题";
  1039. }
  1040. }
  1041. // 只查手续费
  1042. params.put("isOther", "0");
  1043. params.put("isNotCar", isNotCar);
  1044. InsPlyIncome insPlyIncome = baseMapper.findByBxLicenseno(params);
  1045. if (i == dtoList.size() && ObjectUtils.isNotEmpty(insPlyIncome)) {
  1046. resultMap.put("companyId", insPlyIncome.getCompanyId()); // 保险公司id
  1047. resultMap.put("partnerCompaniesId", insPlyIncome.getPartnerCompaniesId()); //合作公司id
  1048. resultMap.put("agreementId", insPlyIncome.getAgreementId()); //协议id
  1049. }
  1050. if (ObjectUtils.isNotEmpty(insPlyIncome)) { // 比配上汇总金额 未匹配则返回到数据当中
  1051. strBuilder.append(insPlyIncome.getId()).append(",");
  1052. if (insPlyIncome.getCommissionFeevalue() != null && insPlyIncome.getCommissionFeevalue().compareTo(BigDecimal.ZERO) != 0) {
  1053. totalAmount = totalAmount.add(insPlyIncome.getCommissionFeevalue()); //添加总手续费
  1054. }
  1055. } else {
  1056. HashMap<String, Object> noMatching = new HashMap<>();
  1057. if (StringUtils.isNotEmpty(excelItem.getLicenseno())) {
  1058. noMatching.put("licenseno", excelItem.getLicenseno());
  1059. }
  1060. if (StringUtils.isNotEmpty(excelItem.getNoPolicyno())) {
  1061. noMatching.put("NoPolicyno", excelItem.getNoPolicyno());
  1062. }
  1063. resultList.add(noMatching);
  1064. }
  1065. resultMap.put("reason", reason);
  1066. }
  1067. if (strBuilder.length() > 0) {
  1068. ids = strBuilder.deleteCharAt(strBuilder.length() - 1).toString();
  1069. }
  1070. resultMap.put("ids", ids);
  1071. resultMap.put("totalAmount", totalAmount);
  1072. resultMap.put("resultList", resultList);
  1073. }
  1074. return resultMap;
  1075. } catch (IOException e) {
  1076. throw new SystemException("导入失败!");
  1077. }
  1078. }
  1079. @Override
  1080. public HttpResult bxOtherDetailsExcel(InsPlyIncomeVo insPlyIncomeVo, HttpServletRequest request, HttpServletResponse response) {
  1081. HashMap<String, Object> params = new HashMap<>();
  1082. params = this.saveParams(insPlyIncomeVo, params);
  1083. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(params);
  1084. String filePathName = "";
  1085. List<BxOtherDetailsNorExcel> resultNoList = new ArrayList<>();
  1086. List<BxOtherDetailsExcel> resultList = new ArrayList<>();
  1087. //判断是否是非车 1 是非车
  1088. if ("1".equals(insPlyIncomeVo.getIsNotCar())) {
  1089. filePathName = "非车跟单明细导出";
  1090. ExportParams exportParams = new ExportParams("非车跟单明细", null, ExcelType.HSSF);
  1091. exportParams.setStyle(ExcelStyleUtil.class);
  1092. for (InsPlyIncome item : insPlyIncomes) {
  1093. BxOtherDetailsNorExcel bxOtherDetailsNorExcel = new BxOtherDetailsNorExcel();
  1094. LocalDateTime signDate = item.getSignDate();
  1095. BeanUtils.copyProperties(item, bxOtherDetailsNorExcel);
  1096. bxOtherDetailsNorExcel.setSigndate(signDate);
  1097. resultNoList.add(bxOtherDetailsNorExcel);
  1098. }
  1099. } else {
  1100. filePathName = "车险跟单明细导出";
  1101. ExportParams exportParams = new ExportParams("车险跟单明细", null, ExcelType.HSSF);
  1102. exportParams.setStyle(ExcelStyleUtil.class);
  1103. for (InsPlyIncome item : insPlyIncomes) {
  1104. BxOtherDetailsExcel bxOtherDetailsExcel = new BxOtherDetailsExcel();
  1105. LocalDateTime signDate = item.getSignDate();
  1106. BeanUtils.copyProperties(item, bxOtherDetailsExcel);
  1107. bxOtherDetailsExcel.setSigndate(signDate);
  1108. resultList.add(bxOtherDetailsExcel);
  1109. }
  1110. }
  1111. String uploadPath = this.uploadPath + "/excel/";
  1112. Path path = Paths.get(uploadPath);
  1113. if (!Files.exists(path)) {
  1114. try {
  1115. Files.createDirectories(path);
  1116. } catch (IOException e) {
  1117. e.printStackTrace();
  1118. }
  1119. }
  1120. String fileName = "";
  1121. if ("1".equals(insPlyIncomeVo.getIsNotCar())) {
  1122. fileName = EasyExcelUtils.downExcel(uploadPath, filePathName, BxOtherDetailsNorExcel.class, resultNoList);
  1123. } else {
  1124. fileName = EasyExcelUtils.downExcel(uploadPath, filePathName, BxOtherDetailsExcel.class, resultList);
  1125. }
  1126. return HttpResult.ok("", uploadUrl + "excel/" + fileName);
  1127. }
  1128. /**
  1129. * @param insPlyIncomeVo 传参字段
  1130. * ids 通过ids中的id进行开票分组
  1131. * @return
  1132. */
  1133. @Override
  1134. public HttpResult<List<SettlementDocumentaryFeesEntity>> invicdetail(InsPlyIncomeVo insPlyIncomeVo) {
  1135. HashMap<String, Object> params = new HashMap<>();
  1136. params = this.saveParams(insPlyIncomeVo, params);
  1137. if (StringUtils.isEmpty(insPlyIncomeVo.getIsSettlement())) {
  1138. params.put("isSettlement", "1");
  1139. }
  1140. if (StringUtils.isNotEmpty(insPlyIncomeVo.getSettlementStatus())) {
  1141. params.put("settlementStatus", insPlyIncomeVo.getSettlementStatus());
  1142. }
  1143. if (StringUtils.isNotEmpty(insPlyIncomeVo.getCompletionStatus())) {
  1144. params.put("completionStatus", insPlyIncomeVo.getCompletionStatus());
  1145. }
  1146. List<SettlementDocumentaryFeesEntity> resultList = settlementDocumentaryFeesService.querySettleNew(params);
  1147. if (resultList.size() > 0) {
  1148. return HttpResult.ok(resultList);
  1149. }
  1150. return HttpResult.ok();
  1151. }
  1152. /***
  1153. *
  1154. * @param insPlyIncomeVo
  1155. * @param request
  1156. * @param response
  1157. * @return 保险非车跟单明细导出
  1158. */
  1159. @Override
  1160. public HttpResult bxNoOtherDetailsExcel(InsPlyIncomeVo insPlyIncomeVo, HttpServletRequest request, HttpServletResponse response) {
  1161. HashMap<String, Object> params = new HashMap<>();
  1162. params = this.saveParams(insPlyIncomeVo, params);
  1163. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(params);
  1164. ExportParams exportParams = new ExportParams("保险非车跟单明细导出", null, ExcelType.HSSF);
  1165. exportParams.setStyle(ExcelStyleUtil.class);
  1166. List<BxNoOtherDetailsExcel> resultList = new ArrayList<>();
  1167. for (InsPlyIncome item : insPlyIncomes) {
  1168. BxNoOtherDetailsExcel bxNoOtherDetailsExcel = new BxNoOtherDetailsExcel();
  1169. BeanUtils.copyProperties(item, bxNoOtherDetailsExcel);
  1170. resultList.add(bxNoOtherDetailsExcel);
  1171. }
  1172. String uploadPath = this.uploadPath + "/excel/";
  1173. Path path = Paths.get(uploadPath);
  1174. if (!Files.exists(path)) {
  1175. try {
  1176. Files.createDirectories(path);
  1177. } catch (IOException e) {
  1178. e.printStackTrace();
  1179. }
  1180. }
  1181. String fileName = EasyExcelUtils.downExcel(uploadPath, "保险非车跟单明细导出", BxNoOtherDetailsExcel.class, resultList);
  1182. return HttpResult.ok("", uploadUrl + "excel/" + fileName);
  1183. }
  1184. /**
  1185. * @param insPlyIncomeVo 开票ids
  1186. * @return 返回开票号 开票金额 开票时间
  1187. */
  1188. @Override
  1189. public HttpResult<List<HashMap<String, Object>>> otherSettldetail(InsPlyIncomeVo insPlyIncomeVo) {
  1190. HashMap<String, Object> params = new HashMap<>();
  1191. params = this.saveParams(insPlyIncomeVo, params);
  1192. List<HashMap<String, Object>> resultList = settlementDocumentaryFeesService.getOtherSettldetail(params);
  1193. if (resultList.size() > 0) {
  1194. return HttpResult.ok(resultList);
  1195. }
  1196. return HttpResult.ok();
  1197. }
  1198. @Override
  1199. public InsPlyIncome getEntityById(String id) {
  1200. return baseMapper.getEntityById(id);
  1201. }
  1202. @Override
  1203. @Transactional
  1204. public void updateByEntity(InsPlyIncomeVo insPlyIncomeVo) {
  1205. // 根据协议 如果是含增值税结算 用保费 * 如果是 不含税保费
  1206. InsPlyIncome insPlyIncome = new InsPlyIncome();
  1207. BeanUtils.copyProperties(insPlyIncomeVo, insPlyIncome);
  1208. if(StringUtils.isNotEmpty(insPlyIncomeVo.getSignDate())){
  1209. String signDate = insPlyIncomeVo.getSignDate();
  1210. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
  1211. LocalDate date = LocalDate.parse(signDate, formatter);
  1212. LocalDateTime dateTime = date.atStartOfDay();
  1213. insPlyIncome.setSignDate(dateTime);
  1214. }
  1215. InsPlyIncome byId = baseMapper.getById(insPlyIncomeVo.getId());
  1216. InsPlyIncomeLog insPlyIncomeLog = new InsPlyIncomeLog();
  1217. insPlyIncomeLog.setIncomeId(insPlyIncome.getId());
  1218. BeanUtils.copyProperties(byId,insPlyIncomeLog);
  1219. insPlyIncomeLog.setId(null);
  1220. insPlyIncomeLog.setOperationStatus("2");
  1221. insPlyIncomeLogService.saveLog(insPlyIncomeLog); //添加日志
  1222. this.amountCalculate(insPlyIncomeVo, insPlyIncome);
  1223. String agreementId = insPlyIncomeVo.getAgreementId();
  1224. if(StringUtils.isNotEmpty(agreementId)){
  1225. PtlAgreement byId1 = ptlAgreementService.getById(agreementId);
  1226. if(ObjectUtils.isNotEmpty(byId1)){
  1227. String partnerCompaniesId = byId1.getPartnerCompaniesId();
  1228. String insuranceCompanyId = byId1.getInsuranceCompanyId();
  1229. String insuranceCompany = byId1.getInsuranceCompany();
  1230. if(StringUtils.isNotEmpty(partnerCompaniesId)){
  1231. insPlyIncome.setPartnerCompaniesId(partnerCompaniesId);
  1232. EsmInsCompany esmInsCompany = EsmInsCompanyService.getById(partnerCompaniesId);
  1233. String name = esmInsCompany.getNamesimple(); //合作名称
  1234. insPlyIncome.setPartnerCompaniesName(name);
  1235. }
  1236. insPlyIncome.setCompanyId(insuranceCompanyId);
  1237. insPlyIncome.setCompanyName(insuranceCompany);
  1238. }
  1239. }
  1240. insPlyIncome.setUpdateUserId(BaseController.getUser().getId());
  1241. baseMapper.updateById(insPlyIncome);
  1242. }
  1243. @Override
  1244. public void updateNoHand(InsPlyIncomeVo insPlyIncomeVo) {
  1245. // 根据协议 如果是含增值税结算 用保费 * 如果是 不含税保费
  1246. InsPlyIncome insPlyIncome = baseMapper.getById(insPlyIncomeVo.getId());
  1247. BigDecimal bigDecimal = this.getBigDecimal(insPlyIncome.getNoPremium(), insPlyIncomeVo.getNoSuperviseCostsProportion());
  1248. insPlyIncome.setCommissionFeevalue(bigDecimal);
  1249. insPlyIncome.setCommissionFeerate(insPlyIncomeVo.getNoSuperviseCostsProportion());
  1250. insPlyIncome.setNoSuperviseCostsPremiums(bigDecimal);
  1251. insPlyIncome.setAllFeeValue(bigDecimal);
  1252. insPlyIncome.setUpdateUserId(BaseController.getUser().getId());
  1253. insPlyIncome.setNoSuperviseCostsProportion(insPlyIncomeVo.getNoSuperviseCostsProportion());
  1254. insPlyIncome.setAgreementId(insPlyIncomeVo.getAgreementId());
  1255. insPlyIncome.setAddType(insPlyIncomeVo.getAddType());
  1256. baseMapper.updateById(insPlyIncome);
  1257. InsPlyIncomeLog insPlyIncomeLog = new InsPlyIncomeLog();
  1258. insPlyIncomeLog.setIncomeId(insPlyIncome.getId());
  1259. BeanUtils.copyProperties(insPlyIncome,insPlyIncomeLog);
  1260. insPlyIncomeLog.setId(null);
  1261. insPlyIncomeLog.setOperationStatus("2");
  1262. insPlyIncomeLogService.saveLog(insPlyIncomeLog); //添加日志
  1263. insPlyIncomeVo.setOtherFeevalue(insPlyIncomeVo.getNoSuperviseCostsPremiums());
  1264. insPlyIncomeVo.setCrudStatus("2");
  1265. this.saveLog(insPlyIncomeVo);
  1266. }
  1267. @Override
  1268. public HttpResult<Object> batchPinBalanceNew(InsPlyIncomeVo insPlyIncomeVo) {
  1269. LocalDateTime now = LocalDateTime.now();
  1270. if(!CollectionUtils.isEmpty(insPlyIncomeVo.getSettIdList())){
  1271. for (String id : insPlyIncomeVo.getSettIdList()){
  1272. InsPlyIncome insPlyIncome = baseMapper.getById(id);
  1273. if("1".equals(insPlyIncome.getHandlingFeesStatus())){
  1274. throw new SystemException("有已结算数据");
  1275. }
  1276. insPlyIncome.setSettlementImageId(insPlyIncomeVo.getSettlementImageId());
  1277. insPlyIncome.setSettlementUserId(BaseController.getUser().getId());
  1278. insPlyIncome.setSettlementTime(now);
  1279. insPlyIncome.setId(id);
  1280. insPlyIncome.setHandlingFeesStatus("1");
  1281. baseMapper.updateById(insPlyIncome);
  1282. }
  1283. }
  1284. return HttpResult.ok();
  1285. }
  1286. /**
  1287. * @param insPlyIncomeVo
  1288. * @param insPlyIncome 重新计算金额 通过比例
  1289. * 计算逻辑 交强不含税保费* 交强跟单比例 = 交强跟单金额
  1290. */
  1291. private void amountCalculate(InsPlyIncomeVo insPlyIncomeVo, InsPlyIncome insPlyIncome) {
  1292. if ("1".equals(insPlyIncomeVo.getAgreementType())) { //平台
  1293. // 平台 手续费 +跟单费 = 应收 手续费 = 手续费比例*保费 应收比例=手续费比例 + 跟单比例
  1294. BigDecimal jqSuperviseCostsProportion = initializationBigdecimal(insPlyIncomeVo.getJqSuperviseCostsProportion());//交强手续费比例
  1295. BigDecimal sySuperviseCostsProportion = initializationBigdecimal(insPlyIncomeVo.getSySuperviseCostsProportion()); //商业手续费比例
  1296. BigDecimal noSuperviseCostsProportion = initializationBigdecimal(insPlyIncomeVo.getNoSuperviseCostsProportion()); //非车手续费比例
  1297. BigDecimal jqOtherCostsProportion = initializationBigdecimal(insPlyIncomeVo.getJqOtherCostsProportion()); //交强跟单比例
  1298. BigDecimal syOtherCostsProportion = initializationBigdecimal(insPlyIncomeVo.getSyOtherCostsProportion()); //商业跟单比例
  1299. BigDecimal noOtherCostsProportion = initializationBigdecimal(insPlyIncomeVo.getNoOtherCostsProportion()); //非车跟单比例
  1300. BigDecimal jqPremium = initializationBigdecimal(insPlyIncomeVo.getJqPremium()); //交强保费
  1301. BigDecimal syPremium = initializationBigdecimal(insPlyIncomeVo.getSyPremium()); //商业保费
  1302. BigDecimal noPremium = initializationBigdecimal(insPlyIncomeVo.getNoPremium()); //非车保费
  1303. //手续费比例
  1304. insPlyIncome.setCommissionFeerate(this.calculateTotal(jqSuperviseCostsProportion, sySuperviseCostsProportion,
  1305. noSuperviseCostsProportion)); //手续费比例 = 商业手续费比例 + 交强手续费比例 + 非车手续费比例
  1306. if (jqSuperviseCostsProportion != null && jqPremium != null) {
  1307. insPlyIncome.setJqSuperviseCostsPremiums(algorithmAmount(jqPremium, jqSuperviseCostsProportion)); //交强手续费
  1308. insPlyIncome.setJqSuperviseCostsProportion(jqSuperviseCostsProportion);
  1309. }
  1310. if (sySuperviseCostsProportion != null && syPremium != null) {
  1311. insPlyIncome.setSySuperviseCostsPremiums(algorithmAmount(syPremium, sySuperviseCostsProportion)); //商业手续费
  1312. insPlyIncome.setSySuperviseCostsProportion(sySuperviseCostsProportion);
  1313. }
  1314. if (noSuperviseCostsProportion != null && noPremium != null) {
  1315. insPlyIncome.setNoSuperviseCostsPremiums(algorithmAmount(noPremium, noSuperviseCostsProportion)); //非车手续费
  1316. insPlyIncome.setNoSuperviseCostsProportion(noSuperviseCostsProportion);
  1317. }
  1318. if (jqOtherCostsProportion != null && jqPremium != null) {
  1319. insPlyIncome.setJqOtherCostsPremium(algorithmAmount(jqPremium, jqOtherCostsProportion)); //交强跟单费
  1320. insPlyIncome.setJqOtherCostsProportion(jqOtherCostsProportion);
  1321. }
  1322. if (syOtherCostsProportion != null && syPremium != null) {
  1323. insPlyIncome.setSyOtherCostsPremium(algorithmAmount(syPremium, syOtherCostsProportion)); //商业跟单费
  1324. insPlyIncome.setSyOtherCostsProportion(syOtherCostsProportion);
  1325. }
  1326. if (noOtherCostsProportion != null && noPremium != null) {
  1327. insPlyIncome.setNoOtherCostsPremium(algorithmAmount(noPremium, noOtherCostsProportion)); //非车跟单费
  1328. insPlyIncome.setNoOtherCostsProportion(noOtherCostsProportion);
  1329. }
  1330. insPlyIncome.setCommissionFeevalue(this.calculateTotal(insPlyIncome.getJqSuperviseCostsPremiums(), insPlyIncome.getSySuperviseCostsPremiums(), insPlyIncome.getNoSuperviseCostsPremiums())); //手续费
  1331. insPlyIncome.setCommissionFeerate(this.calculateTotal(jqSuperviseCostsProportion, sySuperviseCostsProportion,
  1332. noSuperviseCostsProportion)); //手续费比例
  1333. insPlyIncome.setOtherFeevalue(this.calculateTotal(insPlyIncome.getJqOtherCostsPremium(), insPlyIncome.getSyOtherCostsPremium(), insPlyIncome.getNoOtherCostsPremium())); //跟单费金额
  1334. insPlyIncome.setOtherFeerate(this.calculateTotal(jqOtherCostsProportion, syOtherCostsProportion, noOtherCostsProportion));
  1335. //跟单费比例
  1336. //应收比例 交强应收比例=交强手续费比例+交强非跟单比例
  1337. insPlyIncome.setJqReceivableProportion(this.calculateTotal(jqSuperviseCostsProportion, jqOtherCostsProportion, null)); //交强应收
  1338. insPlyIncome.setSyReceivableProportion(this.calculateTotal(sySuperviseCostsProportion, syOtherCostsProportion, null)); //商业应收
  1339. insPlyIncome.setNoReceivableProportion(this.calculateTotal(noSuperviseCostsProportion, noOtherCostsProportion, null)); //非车应收
  1340. if(insPlyIncomeVo.getPtCommissionFeevalue()!=null && insPlyIncomeVo.getPtCommissionFeevalue().compareTo(BigDecimal.ZERO) >0){
  1341. insPlyIncome.setCommissionFeevalue(insPlyIncomeVo.getPtCommissionFeevalue());
  1342. }
  1343. if(insPlyIncomeVo.getPtOtherFeevalue()!=null && insPlyIncomeVo.getPtOtherFeevalue().compareTo(BigDecimal.ZERO) >0){
  1344. insPlyIncome.setOtherFeevalue(insPlyIncomeVo.getPtOtherFeevalue());
  1345. }
  1346. insPlyIncome.setAllFeeValue(this.calculateTotal(insPlyIncome.getCommissionFeevalue(), insPlyIncome.getOtherFeevalue(), null)); // 总费用 = 手续费+跟单费
  1347. insPlyIncome.setReceivableAmount(this.calculateTotal(insPlyIncome.getCommissionFeevalue(), insPlyIncome.getOtherFeevalue(), null));
  1348. } else {
  1349. String agreementId = insPlyIncomeVo.getAgreementId();
  1350. BigDecimal jqNoTaxPremium = insPlyIncomeVo.getJqPremium();// 交强手续费 按照思路 交强不含税保费* 交强手续费比例 =交强手续费
  1351. BigDecimal syNoTaxPremium = insPlyIncomeVo.getSyPremium();// 商业手续费 按照思路 商业不含税保费* 商业手续费比例 =商业手续费
  1352. BigDecimal noNoTaxPremium = insPlyIncomeVo.getNoPremium();// 非车手续费 按照思路 非车不含税保费* 非车手续费比例 =非车手续费
  1353. if(StringUtils.isNotEmpty(agreementId)){
  1354. PtlAgreement ptlAgreement = ptlAgreementService.getById(agreementId);
  1355. if(StringUtils.isNotEmpty(ptlAgreement.getWithTax()) && "是".equals(ptlAgreement.getWithTax())){
  1356. if (jqNoTaxPremium != null && insPlyIncomeVo.getJqSuperviseCostsProportion() != null && insPlyIncomeVo.getJqSuperviseCostsProportion().compareTo(BigDecimal.ZERO) != 0) {
  1357. insPlyIncome.setJqSuperviseCostsPremiums(algorithmAmount(jqNoTaxPremium, insPlyIncomeVo.getJqSuperviseCostsProportion()));
  1358. insPlyIncome.setJqSuperviseCostsProportion(insPlyIncomeVo.getJqSuperviseCostsProportion());
  1359. }
  1360. if (syNoTaxPremium != null && insPlyIncomeVo.getSySuperviseCostsProportion() != null && insPlyIncomeVo.getSySuperviseCostsProportion().compareTo(BigDecimal.ZERO) != 0) {
  1361. insPlyIncome.setSySuperviseCostsPremiums(algorithmAmount(syNoTaxPremium, insPlyIncomeVo.getSySuperviseCostsProportion()));
  1362. insPlyIncome.setSySuperviseCostsProportion(insPlyIncomeVo.getSySuperviseCostsProportion());
  1363. }
  1364. if (noNoTaxPremium != null && insPlyIncomeVo.getNoSuperviseCostsProportion() != null && insPlyIncomeVo.getNoSuperviseCostsProportion().compareTo(BigDecimal.ZERO) != 0) {
  1365. insPlyIncome.setNoSuperviseCostsProportion(insPlyIncome.getNoSuperviseCostsProportion());
  1366. insPlyIncome.setNoSuperviseCostsPremiums(algorithmAmount(noNoTaxPremium, insPlyIncomeVo.getNoSuperviseCostsProportion()));
  1367. }
  1368. if (jqNoTaxPremium != null && insPlyIncomeVo.getJqOtherCostsProportion() != null && insPlyIncomeVo.getJqOtherCostsProportion().compareTo(BigDecimal.ZERO) != 0) {
  1369. insPlyIncome.setJqOtherCostsPremium(algorithmAmount(jqNoTaxPremium, insPlyIncomeVo.getJqOtherCostsProportion()));
  1370. insPlyIncome.setJqOtherCostsProportion(insPlyIncomeVo.getJqOtherCostsProportion());
  1371. }
  1372. if (syNoTaxPremium != null && insPlyIncomeVo.getSyOtherCostsProportion() != null && insPlyIncomeVo.getSyOtherCostsProportion().compareTo(BigDecimal.ZERO) != 0) {
  1373. insPlyIncome.setSyOtherCostsProportion(insPlyIncome.getSyOtherCostsProportion());
  1374. insPlyIncome.setSyOtherCostsPremium(algorithmAmount(syNoTaxPremium, insPlyIncomeVo.getSyOtherCostsProportion()));
  1375. }
  1376. if (noNoTaxPremium != null && insPlyIncomeVo.getOtherFeerate() != null && insPlyIncomeVo.getOtherFeerate().compareTo(BigDecimal.ZERO) != 0) {
  1377. insPlyIncome.setNoOtherCostsProportion(insPlyIncome.getOtherFeerate());
  1378. insPlyIncome.setNoOtherCostsPremium(algorithmAmount(noNoTaxPremium, insPlyIncomeVo.getOtherFeerate()));
  1379. }
  1380. }else {
  1381. if (jqNoTaxPremium != null && insPlyIncomeVo.getJqSuperviseCostsProportion() != null && insPlyIncomeVo.getJqSuperviseCostsProportion().compareTo(BigDecimal.ZERO) != 0) {
  1382. insPlyIncome.setJqSuperviseCostsPremiums(getBigDecimal(jqNoTaxPremium, insPlyIncomeVo.getJqSuperviseCostsProportion()));
  1383. insPlyIncome.setJqSuperviseCostsProportion(insPlyIncomeVo.getJqSuperviseCostsProportion());
  1384. }
  1385. if (syNoTaxPremium != null && insPlyIncomeVo.getSySuperviseCostsProportion() != null && insPlyIncomeVo.getSySuperviseCostsProportion().compareTo(BigDecimal.ZERO) != 0) {
  1386. insPlyIncome.setSySuperviseCostsPremiums(getBigDecimal(syNoTaxPremium, insPlyIncomeVo.getSySuperviseCostsProportion()));
  1387. insPlyIncome.setSySuperviseCostsProportion(insPlyIncomeVo.getSySuperviseCostsProportion());
  1388. }
  1389. if (noNoTaxPremium != null && insPlyIncomeVo.getNoSuperviseCostsProportion() != null && insPlyIncomeVo.getNoSuperviseCostsProportion().compareTo(BigDecimal.ZERO) != 0) {
  1390. insPlyIncome.setNoSuperviseCostsProportion(insPlyIncome.getNoSuperviseCostsProportion());
  1391. insPlyIncome.setNoSuperviseCostsPremiums(getBigDecimal(noNoTaxPremium, insPlyIncomeVo.getNoSuperviseCostsProportion()));
  1392. }
  1393. if (jqNoTaxPremium != null && insPlyIncomeVo.getJqOtherCostsProportion() != null && insPlyIncomeVo.getJqOtherCostsProportion().compareTo(BigDecimal.ZERO) != 0) {
  1394. insPlyIncome.setJqOtherCostsPremium(getBigDecimal(jqNoTaxPremium, insPlyIncomeVo.getJqOtherCostsProportion()));
  1395. insPlyIncome.setJqOtherCostsProportion(insPlyIncomeVo.getJqOtherCostsProportion());
  1396. }
  1397. if (syNoTaxPremium != null && insPlyIncomeVo.getSyOtherCostsProportion() != null && insPlyIncomeVo.getSyOtherCostsProportion().compareTo(BigDecimal.ZERO) != 0) {
  1398. insPlyIncome.setSyOtherCostsProportion(insPlyIncome.getSyOtherCostsProportion());
  1399. insPlyIncome.setSyOtherCostsPremium(getBigDecimal(syNoTaxPremium, insPlyIncomeVo.getSyOtherCostsProportion()));
  1400. }
  1401. if (noNoTaxPremium != null && insPlyIncomeVo.getOtherFeerate() != null && insPlyIncomeVo.getOtherFeerate().compareTo(BigDecimal.ZERO) != 0) {
  1402. insPlyIncome.setNoOtherCostsProportion(insPlyIncome.getOtherFeerate());
  1403. insPlyIncome.setNoOtherCostsPremium(getBigDecimal(noNoTaxPremium, insPlyIncomeVo.getOtherFeerate()));
  1404. }
  1405. }
  1406. }
  1407. if ("0".equals(insPlyIncomeVo.getIsNotDocumentary()) && "0".equals(insPlyIncomeVo.getIsNotCar())) { //保险 手续费 =不含税保费* 手续费比例
  1408. insPlyIncome.setCommissionFeevalue(this.calculateTotal(insPlyIncome.getJqSuperviseCostsPremiums(), insPlyIncome.getSySuperviseCostsPremiums(), null)); // 手续费
  1409. insPlyIncome.setCommissionFeerate(this.calculateTotal(insPlyIncome.getJqSuperviseCostsProportion(), insPlyIncome.getSySuperviseCostsProportion(), null));//手续费比例
  1410. insPlyIncome.setAllFeeValue(this.calculateTotal(insPlyIncome.getCommissionFeevalue(), null, null));//总金额
  1411. } else if ("1".equals(insPlyIncomeVo.getIsNotDocumentary()) && "0".equals(insPlyIncomeVo.getIsNotCar())) { //保险跟单费 交强跟单+商业跟单
  1412. insPlyIncome.setOtherFeevalue(this.calculateTotal(insPlyIncome.getJqOtherCostsPremium(), insPlyIncome.getSyOtherCostsPremium(), null));
  1413. insPlyIncome.setOtherFeerate(this.calculateTotal(insPlyIncome.getJqOtherCostsProportion(), insPlyIncome.getSyOtherCostsProportion(), null));
  1414. insPlyIncome.setAllFeeValue(this.calculateTotal(insPlyIncome.getOtherFeevalue(), null, null));//总金额
  1415. }
  1416. if ("0".equals(insPlyIncomeVo.getIsNotDocumentary()) && "1".equals(insPlyIncomeVo.getIsNotCar())) {// 非车
  1417. insPlyIncome.setCommissionFeevalue(this.calculateTotal(insPlyIncome.getNoSuperviseCostsPremiums(), null, null)); // 非车手续费
  1418. insPlyIncome.setCommissionFeerate(this.calculateTotal(insPlyIncome.getNoSuperviseCostsProportion(), null, null)); //非车比例
  1419. insPlyIncome.setAllFeeValue(this.calculateTotal(insPlyIncome.getCommissionFeevalue(), null, null));//总金额
  1420. } else if ("1".equals(insPlyIncomeVo.getIsNotDocumentary()) && "1".equals(insPlyIncomeVo.getIsNotCar())) { //非车跟单
  1421. insPlyIncome.setOtherFeevalue(this.calculateTotal(insPlyIncome.getNoOtherCostsPremium(), null, null)); //非车跟单金额
  1422. insPlyIncome.setOtherFeerate(this.calculateTotal(insPlyIncome.getNoOtherCostsProportion(), null, null)); // 非车跟单比例
  1423. insPlyIncome.setAllFeeValue(this.calculateTotal(insPlyIncome.getOtherFeevalue(), null, null));//总金额
  1424. }
  1425. }
  1426. }
  1427. /**
  1428. * 计算 金额
  1429. *
  1430. * @param taxPremium
  1431. * @param proportion
  1432. * @return
  1433. */
  1434. private static BigDecimal getBigDecimal(BigDecimal taxPremium, BigDecimal proportion) {
  1435. BigDecimal divisor = new BigDecimal("1.06"); // 示例除数
  1436. // 先进行除法,保留5位小数,不进行四舍五入(使用RoundingMode.DOWN)
  1437. BigDecimal dividedAmount = taxPremium.divide(divisor, 5, BigDecimal.ROUND_DOWN);
  1438. // 将比例除以100,假设proportion是一个百分比值
  1439. // 然后进行乘法,并进行舍入到5位小数
  1440. BigDecimal result = dividedAmount.multiply( proportion.divide(new BigDecimal(100))).setScale(5, BigDecimal.ROUND_DOWN);
  1441. return result;
  1442. }
  1443. /**
  1444. * @param value1 保费
  1445. * @param value2 比例
  1446. * @return 费用
  1447. */
  1448. private BigDecimal algorithmAmount(BigDecimal value1, BigDecimal value2) {
  1449. BigDecimal divide = value2.divide(new BigDecimal(100));
  1450. return value1.multiply(divide).setScale(5,BigDecimal.ROUND_DOWN);
  1451. }
  1452. private BigDecimal initializationBigdecimal(BigDecimal value) {
  1453. return value != null ? value : BigDecimal.ZERO;
  1454. }
  1455. private void saveLog(InsPlyIncomeVo insPlyIncomeVo) {
  1456. // 添加记录
  1457. SettlementDocumentaryLogEntity settlementDocumentaryLogEntity = new SettlementDocumentaryLogEntity();
  1458. settlementDocumentaryLogEntity.setCrudStatus(insPlyIncomeVo.getCrudStatus());
  1459. settlementDocumentaryLogEntity.setAmount(insPlyIncomeVo.getOtherFeevalue());
  1460. settlementDocumentaryLogEntity.setSettlementDocumentaryId(insPlyIncomeVo.getId());
  1461. settlementDocumentaryLogEntity.setAmountType("2");
  1462. settlementDocumentaryLogService.save(settlementDocumentaryLogEntity);
  1463. }
  1464. @Override
  1465. @Transactional
  1466. public HttpResult<InsPlyIncome> insertByEntity(InsPlyIncomeVo insPlyIncomeVo) {
  1467. Long id = new SnowFlakeUtil().nextId();
  1468. InsPlyIncome insPlyIncome = new InsPlyIncome();
  1469. insPlyIncomeVo.setOrderno(id.toString());
  1470. String signdateStr = insPlyIncomeVo.getSignDate();
  1471. LocalDateTime localDateTime = this.LocalDatePareLocalDateTime(signdateStr);
  1472. insPlyIncomeVo.setSignDate(null);
  1473. BeanUtils.copyProperties(insPlyIncomeVo, insPlyIncome);
  1474. insPlyIncome.setUserId(BaseController.getUser().getId());
  1475. insPlyIncome.setDocumentaryFeesStatus("0");
  1476. insPlyIncome.setHandlingFeesStatus("0");
  1477. insPlyIncome.setIsNotCar(insPlyIncomeVo.getIsNotCar()); // 是否是非车
  1478. insPlyIncome.setIsNotDocumentary(insPlyIncomeVo.getIsNotDocumentary()); //是否是跟单
  1479. insPlyIncome.setSignDate(localDateTime);
  1480. insPlyIncome.setDeptId(BaseController.getUser().getDeptId());
  1481. insPlyIncome.setCreateTime(LocalDateTime.now());
  1482. insPlyIncome.setOtherFeerate(this.calculateTotal(insPlyIncomeVo.getJqOtherCostsProportion(),insPlyIncomeVo.getSyOtherCostsProportion(),insPlyIncomeVo.getNoOtherCostsProportion()));
  1483. insPlyIncome.setCommissionFeerate(this.calculateTotal(insPlyIncomeVo.getJqSuperviseCostsProportion(),insPlyIncomeVo.getSySuperviseCostsProportion(),insPlyIncomeVo.getNoSuperviseCostsProportion()));
  1484. if (insPlyIncome.getJqPremium() != null && insPlyIncome.getJqPremium().compareTo(BigDecimal.ZERO) != 0 && insPlyIncome.getJqSuperviseCostsProportion() != null && insPlyIncome.getJqSuperviseCostsProportion().compareTo(BigDecimal.ZERO) != 0) {
  1485. insPlyIncome.setJqSuperviseCostsPremiums(getBigDecimal(insPlyIncome.getJqPremium(), insPlyIncomeVo.getJqSuperviseCostsProportion()));
  1486. }
  1487. if (insPlyIncome.getSyPremium() != null && insPlyIncome.getSyPremium().compareTo(BigDecimal.ZERO) != 0 && insPlyIncome.getSySuperviseCostsProportion() != null && insPlyIncome.getSySuperviseCostsProportion().compareTo(BigDecimal.ZERO) != 0) {
  1488. insPlyIncome.setSySuperviseCostsPremiums(getBigDecimal(insPlyIncome.getSyPremium(), insPlyIncomeVo.getSySuperviseCostsProportion()));
  1489. }
  1490. if (insPlyIncome.getNoPremium() != null && insPlyIncome.getNoPremium().compareTo(BigDecimal.ZERO) != 0 && insPlyIncome.getNoSuperviseCostsProportion() != null && insPlyIncome.getNoSuperviseCostsProportion().compareTo(BigDecimal.ZERO) != 0) {
  1491. insPlyIncome.setNoSuperviseCostsPremiums(getBigDecimal(insPlyIncome.getNoPremium(), insPlyIncomeVo.getNoSuperviseCostsProportion()));
  1492. }
  1493. if (insPlyIncome.getJqPremium() != null && insPlyIncome.getJqPremium().compareTo(BigDecimal.ZERO) != 0 && insPlyIncome.getJqOtherCostsProportion() != null && insPlyIncome.getJqOtherCostsProportion().compareTo(BigDecimal.ZERO) != 0) {
  1494. insPlyIncome.setJqOtherCostsPremium(getBigDecimal(insPlyIncome.getJqPremium(), insPlyIncomeVo.getJqOtherCostsProportion()));
  1495. }
  1496. if (insPlyIncome.getSyPremium() != null && insPlyIncome.getSyPremium().compareTo(BigDecimal.ZERO) != 0 && insPlyIncome.getSyOtherCostsProportion() != null && insPlyIncome.getSyOtherCostsProportion().compareTo(BigDecimal.ZERO) != 0) {
  1497. insPlyIncome.setSyOtherCostsPremium(getBigDecimal(insPlyIncome.getSyPremium(), insPlyIncomeVo.getSyOtherCostsProportion()));
  1498. }
  1499. if (insPlyIncome.getNoPremium() != null && insPlyIncome.getNoPremium().compareTo(BigDecimal.ZERO) != 0 && insPlyIncome.getNoOtherCostsProportion() != null && insPlyIncome.getNoOtherCostsProportion().compareTo(BigDecimal.ZERO) != 0) {
  1500. insPlyIncome.setNoOtherCostsPremium(getBigDecimal(insPlyIncome.getNoPremium(), insPlyIncomeVo.getNoOtherCostsProportion()));
  1501. }
  1502. insPlyIncome.setAllFeeValue(this.calculateTotal(insPlyIncome.getCommissionFeevalue(),insPlyIncome.getOtherFeevalue(),null));
  1503. String partnerCompaniesId = insPlyIncome.getPartnerCompaniesId();
  1504. insPlyIncome.setPartnerCompaniesId(partnerCompaniesId);
  1505. EsmInsCompany esmInsCompany = EsmInsCompanyService.getById(partnerCompaniesId);
  1506. String name = esmInsCompany.getNamesimple(); //合作名称
  1507. insPlyIncome.setPartnerCompaniesName(name);
  1508. HashMap<String, Object> params = new HashMap<>();
  1509. params.put("agreeId",insPlyIncomeVo.getAgreeId());
  1510. PtlAgreement ptlAgreement = ptlAgreementService.selectAgreeId(params);
  1511. if (ObjectUtils.isEmpty(ptlAgreement)) {
  1512. return HttpResult.error("协议匹配不上");
  1513. }
  1514. insPlyIncome.setAgreementId(ptlAgreement.getId());
  1515. baseMapper.insert(insPlyIncome);
  1516. InsPlyIncomeLog insPlyIncomeLog = new InsPlyIncomeLog();
  1517. insPlyIncomeLog.setIncomeId(insPlyIncome.getId());
  1518. BeanUtils.copyProperties(insPlyIncome,insPlyIncomeLog);
  1519. insPlyIncomeLog.setId(null);
  1520. insPlyIncomeLog.setOperationStatus("1");
  1521. insPlyIncomeLogService.saveLog(insPlyIncomeLog); //添加日志
  1522. return HttpResult.ok();
  1523. }
  1524. private LocalDateTime LocalDatePareLocalDateTime(String signdateStr) {
  1525. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
  1526. // 将字符串解析为LocalDate
  1527. LocalDate signdate = LocalDate.parse(signdateStr, formatter);
  1528. // 创建一个 LocalTime 对象表示中午12点
  1529. LocalTime noon = LocalTime.of(12, 0);
  1530. // 使用 LocalDate 和 LocalTime 来创建 LocalDateTime
  1531. return LocalDateTime.of(signdate, noon);
  1532. }
  1533. /**
  1534. * 删除id 已开票或者已结算都不可以进行 删除
  1535. * 因为跟单没有关联表 也无法关联到开票表所以只能按照 条件去查询判断 保司机构 id
  1536. * @param insPlyIncomeVo
  1537. * @return
  1538. */
  1539. @Override
  1540. @Transactional
  1541. public HttpResult<InsPlyIncome> deleteById(InsPlyIncomeVo insPlyIncomeVo) {
  1542. HashMap<String, Object> params = new HashMap<>();
  1543. params.put("id",insPlyIncomeVo.getId());
  1544. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(params);
  1545. InsPlyIncome insPlyIncome = insPlyIncomes.get(0);
  1546. if (StringUtils.isNotEmpty(insPlyIncome.getAgreementType()) && "1".equals(insPlyIncome.getAgreementType())) {
  1547. if ("1".equals(insPlyIncome.getHandlingFeesStatus())) {
  1548. throw new SystemException("已结算不可以进行删除");
  1549. }
  1550. } else if (StringUtils.isNotEmpty(insPlyIncome.getAgreementType()) && "2".equals(insPlyIncome.getAgreementType())) {
  1551. if ("0".equals(insPlyIncome.getIsNotDocumentary())) {
  1552. String taskId = insPlyIncome.getTaskId();
  1553. if (StringUtils.isNotEmpty(taskId)) {
  1554. throw new SystemException("已开票不能进行删除");
  1555. }
  1556. } else {
  1557. // 因为跟单没有关联表 也无法关联到开票表所以只能按照 条件去进行判断
  1558. if(StringUtils.isNotEmpty( insPlyIncome.getSettleOtherStatus()) && "1".equals( insPlyIncome.getSettleOtherStatus())){
  1559. throw new SystemException("已经对账不能进行删除");
  1560. }
  1561. }
  1562. }
  1563. InsPlyIncomeLog insPlyIncomeLog = new InsPlyIncomeLog();
  1564. insPlyIncomeLog.setIncomeId(insPlyIncome.getId());
  1565. BeanUtils.copyProperties(insPlyIncome,insPlyIncomeLog);
  1566. insPlyIncomeLog.setId(null);
  1567. insPlyIncomeLog.setOperationStatus("3");
  1568. insPlyIncomeLogService.saveLog(insPlyIncomeLog); //添加日志
  1569. baseMapper.deleteById(insPlyIncomeVo.getId()); //删除 结算 然后删除结算表
  1570. return HttpResult.ok("删除成功");
  1571. }
  1572. @Override
  1573. @Transactional
  1574. public void uodateBalance(InsPlyIncomeVo insPlyIncomeVo) {
  1575. InsPlyIncome insPlyIncome = new InsPlyIncome();
  1576. insPlyIncomeVo.setHandlingFeesStatus("1");
  1577. BeanUtils.copyProperties(insPlyIncomeVo, insPlyIncome);
  1578. insPlyIncome.setSettlementUserId(BaseController.getUser().getId());
  1579. insPlyIncome.setSettlementTime(LocalDateTime.now());
  1580. baseMapper.updateById(insPlyIncome);
  1581. // 生成记录
  1582. SettlementDocumentaryLogEntity settlementDocumentaryLogEntity = new SettlementDocumentaryLogEntity();
  1583. if (StringUtils.isNotEmpty(insPlyIncomeVo.getAgreementType()) && "1".equals(insPlyIncomeVo.getAgreementType())) {
  1584. // 只有平台协议 才会跟单费一笔结算
  1585. settlementDocumentaryLogEntity.setAmount(insPlyIncomeVo.getOtherFeevalue()); // 跟单费金额
  1586. }
  1587. settlementDocumentaryLogEntity.setHandingAmount(insPlyIncomeVo.getCommissionFeevalue()); // 手续费金额
  1588. settlementDocumentaryLogEntity.setSettlementDocumentaryId(insPlyIncomeVo.getId()); // 关联id
  1589. settlementDocumentaryLogEntity.setAmountType("1"); //手续费结算
  1590. settlementDocumentaryLogEntity.setCreateTime(new Date());
  1591. settlementDocumentaryLogService.save(settlementDocumentaryLogEntity);
  1592. }
  1593. @Override
  1594. @Transactional
  1595. public HttpResult<BasePageResult<InsPlyIncome>> totalQuery(InsPlyIncomeVo insPlyIncomeVo) {
  1596. HashMap<String, Object> params = new HashMap<>();
  1597. PageInfo<List<InsPlyIncome>> pageHelper = null;
  1598. if (insPlyIncomeVo.getStartDate() != null) {
  1599. params.put("startDate", insPlyIncomeVo.getStartDate().toString());
  1600. }
  1601. if (insPlyIncomeVo.getEndDate() != null) {
  1602. params.put("endDate", insPlyIncomeVo.getEndDate().toString());
  1603. }
  1604. if (StringUtils.isNotEmpty(insPlyIncomeVo.getYear())) {
  1605. params.put("year", insPlyIncomeVo.getYear());
  1606. }
  1607. if (StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotCar())) {
  1608. params.put("isNotCar", insPlyIncomeVo.getIsNotCar());
  1609. }
  1610. if (StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotDocumentary())) {
  1611. params.put("isOther", insPlyIncomeVo.getIsNotDocumentary());
  1612. }
  1613. if (StringUtils.isNotEmpty(insPlyIncomeVo.getDocumentaryFeesStatus())) {
  1614. params.put("documentaryFeesStatus", insPlyIncomeVo.getDocumentaryFeesStatus());
  1615. }
  1616. if (StringUtils.isNotEmpty(insPlyIncomeVo.getCompanyId())) {
  1617. params.put("companyId", insPlyIncomeVo.getCompanyId());
  1618. }
  1619. params.put("pageNum", insPlyIncomeVo.getPageNum());
  1620. params.put("pageSize", insPlyIncomeVo.getPageSize());
  1621. List<InsPlyIncome> list = this.baseMapper.totalQuery(params);
  1622. pageHelper = new PageInfo(list);
  1623. return HttpResult.ok(new BasePageResult<>(insPlyIncomeVo.getPageNum(), insPlyIncomeVo.getPageSize(), pageHelper.getTotal(),
  1624. pageHelper.getPages(), list));
  1625. }
  1626. /**
  1627. *
  1628. * @param insPlyIncomeVo ids ins_ply_income 这个表的ids incomeIds settlement_documentary_fees 这个表的ids
  1629. * @return
  1630. */
  1631. /**
  1632. * 跟单费结算 有分批结算的情况
  1633. *
  1634. * @param insPlyIncomeVo
  1635. * @return
  1636. */
  1637. @Override
  1638. @Transactional
  1639. public HttpResult batchBalance(InsPlyIncomeVo insPlyIncomeVo) {
  1640. // 分批结算
  1641. SettlementDocumentaryFeesVo settlementDocumentaryFeesVo = new SettlementDocumentaryFeesVo();
  1642. String id = insPlyIncomeVo.getId(); // 开票id
  1643. SettlementDocumentaryFeesEntity settlementDocumentaryFeesServiceById = settlementDocumentaryFeesService.getById(id); //
  1644. BigDecimal allAmount = settlementDocumentaryFeesServiceById.getSettlementAmount();
  1645. HashMap<String, Object> params = new HashMap<>();
  1646. params.put("id", insPlyIncomeVo.getId());
  1647. params.put("handlingFeesStatus", "1");
  1648. SettlementDocumentaryFeesEntity parentSettlementDocumentaryFeesEntity =
  1649. settlementDocumentaryFeesService.getByParentSettlementAmount(params);
  1650. if (ObjectUtils.isNotEmpty(parentSettlementDocumentaryFeesEntity)) { // 多次结算
  1651. BigDecimal totalAmount = parentSettlementDocumentaryFeesEntity.getTotalAmount();
  1652. totalAmount = totalAmount.add(insPlyIncomeVo.getSettlementAmount());
  1653. if (allAmount.compareTo(totalAmount) < 0) {
  1654. return HttpResult.error("结算金额超出开票金额");
  1655. }
  1656. } else {
  1657. if (allAmount.compareTo(insPlyIncomeVo.getSettlementAmount()) < 0) {
  1658. return HttpResult.error("结算金额超出开票金额");
  1659. }
  1660. }
  1661. settlementDocumentaryFeesVo.setInvoiceId(insPlyIncomeVo.getInvoicId()); //开票号
  1662. settlementDocumentaryFeesVo.setSettlementTime(insPlyIncomeVo.getSettlementTime()); //结算时间
  1663. settlementDocumentaryFeesVo.setSettlementStatus("2"); //2为结算状态
  1664. settlementDocumentaryFeesVo.setCompanyId(insPlyIncomeVo.getCompanyId()); // 保险公司id
  1665. settlementDocumentaryFeesVo.setPartnerCompaniesId(insPlyIncomeVo.getPartnerCompaniesId()); //合作公司id
  1666. settlementDocumentaryFeesVo.setUnsettledAmount(insPlyIncomeVo.getInvoicCommissionFeevalue().subtract(insPlyIncomeVo.getSettlementAmount())); //未结算金额
  1667. settlementDocumentaryFeesVo.setIsNotCar(insPlyIncomeVo.getIsNotCar()); // 是否是非车
  1668. settlementDocumentaryFeesVo.setInvoicingMethod(insPlyIncomeVo.getInvoicingMethod()); //开票方式
  1669. settlementDocumentaryFeesVo.setTaxPoints(insPlyIncomeVo.getTaxPoints()); //税点
  1670. settlementDocumentaryFeesVo.setSettlementImageId(insPlyIncomeVo.getSettlementImageId());
  1671. if ("0".equals(insPlyIncomeVo.getInvoicingMethod())) {
  1672. settlementDocumentaryFeesVo.setExpendAmount(insPlyIncomeVo.getSettlementAmount().multiply(BigDecimal.ONE.subtract(insPlyIncomeVo.getTaxPoints().divide(new BigDecimal(100)))));
  1673. } else {
  1674. settlementDocumentaryFeesVo.setExpendAmount(insPlyIncomeVo.getSettlementAmount()); //进账金额
  1675. }
  1676. settlementDocumentaryFeesVo.setSettlementAmount(insPlyIncomeVo.getSettlementAmount()); //进账金额
  1677. settlementDocumentaryFeesVo.setHandlingFeesStatus(insPlyIncomeVo.getHandlingFeesStatus());
  1678. settlementDocumentaryFeesVo.setTotalAmount(insPlyIncomeVo.getInvoicCommissionFeevalue());
  1679. settlementDocumentaryFeesVo.setCreateTime(LocalDateTime.now());
  1680. settlementDocumentaryFeesVo.setParentId(insPlyIncomeVo.getId());
  1681. settlementDocumentaryFeesVo.setAgreementType("2"); //1平台 2 保险
  1682. settlementDocumentaryFeesService.inertSettle(settlementDocumentaryFeesVo);
  1683. return HttpResult.ok();
  1684. }
  1685. @Override
  1686. @Transactional
  1687. public HttpResult<Object> batchSumBalance(InsPlyIncomeVo insPlyIncomeVo) {
  1688. List<InsPlyIncomeVo> multipleSelection = insPlyIncomeVo.getMultipleSelection();
  1689. HashMap<String, Object> params = new HashMap<>();
  1690. Date date = new Date();
  1691. BigDecimal settleMentAmount = BigDecimal.ZERO;
  1692. BigDecimal settleNotMentAmount = BigDecimal.ZERO;
  1693. for (InsPlyIncomeVo item : multipleSelection){
  1694. SettlementDocumentaryFeesEntity settlementDocumentaryFeesVo = new SettlementDocumentaryFeesEntity();
  1695. if(item.getInvoicCommissionFeevalue() ==null || item .getInvoicCommissionFeevalue().compareTo(BigDecimal.ZERO) <=0){
  1696. throw new SystemException("请输入正确金额");
  1697. }
  1698. String id = item.getId();
  1699. SettlementDocumentaryFeesEntity settlementDocumentaryFeesEntity = settlementDocumentaryFeesService.getBaseMapper().selectById(id); // 开票
  1700. BigDecimal invoicedNotSettledAmount = settlementDocumentaryFeesEntity.getInvoicedNotSettledAmount();//未结算金额
  1701. if(item.getInvoicCommissionFeevalue().compareTo(invoicedNotSettledAmount) >0){
  1702. throw new SystemException("结算金额大于未结算金额");
  1703. }
  1704. if(item.getInvoicCommissionFeevalue().compareTo(BigDecimal.ZERO) >0){
  1705. settlementDocumentaryFeesVo.setInvoiceId(settlementDocumentaryFeesEntity.getInvoicId()); //开票号
  1706. settlementDocumentaryFeesVo.setSettlementTime(insPlyIncomeVo.getSettlementTime()); //结算时间
  1707. settlementDocumentaryFeesVo.setSettlementStatus("2"); //2为结算状态
  1708. settlementDocumentaryFeesVo.setCompanyId(settlementDocumentaryFeesEntity.getCompanyId()); // 保险公司id
  1709. settlementDocumentaryFeesVo.setPartnerCompaniesId(settlementDocumentaryFeesEntity.getPartnerCompaniesId()); //合作公司id
  1710. // settlementDocumentaryFeesVo.setUnsettledAmount(insPlyIncomeVo.getInvoicCommissionFeevalue().subtract(insPlyIncomeVo.getSettlementAmount())); //未结算金额
  1711. settlementDocumentaryFeesVo.setIsNotCar(settlementDocumentaryFeesEntity.getIsNotCar()); // 是否是非车
  1712. settlementDocumentaryFeesVo.setInvoicingMethod(settlementDocumentaryFeesEntity.getInvoicingMethod()); //开票方式
  1713. settlementDocumentaryFeesVo.setTaxPoints(settlementDocumentaryFeesEntity.getTaxPoints()); //税点
  1714. settlementDocumentaryFeesVo.setSettlementImageId(insPlyIncomeVo.getSettlementImageId());
  1715. if ("0".equals(insPlyIncomeVo.getInvoicingMethod())) {
  1716. settlementDocumentaryFeesVo.setExpendAmount(item.getInvoicCommissionFeevalue().multiply(BigDecimal.ONE.subtract(insPlyIncomeVo.getTaxPoints().divide(new BigDecimal(100)))));
  1717. } else {
  1718. settlementDocumentaryFeesVo.setExpendAmount(item.getInvoicCommissionFeevalue()); //进账金额
  1719. }
  1720. settlementDocumentaryFeesVo.setSettlementAmount(item.getInvoicCommissionFeevalue()); //进账金额
  1721. settlementDocumentaryFeesVo.setHandlingFeesStatus(settlementDocumentaryFeesEntity.getHandlingFeesStatus());
  1722. settlementDocumentaryFeesVo.setTotalAmount(settlementDocumentaryFeesEntity.getSettlementAmount());
  1723. settlementDocumentaryFeesVo.setCreateTime(LocalDateTime.now());
  1724. settlementDocumentaryFeesVo.setSettlementTime(LocalDate.now());
  1725. settlementDocumentaryFeesVo.setParentId(insPlyIncomeVo.getId());
  1726. settlementDocumentaryFeesVo.setAgreementType("2"); //1平台 2 保险
  1727. settlementDocumentaryFeesVo.setInvoicedSettledAmount(item.getInvoicCommissionFeevalue());
  1728. settlementDocumentaryFeesVo.setInvoicedNotSettledAmount(BigDecimal.ZERO);
  1729. // 生成跟单费结算记录
  1730. SettlementDocumentaryLogEntity settlementDocumentaryLogEntity = new SettlementDocumentaryLogEntity();
  1731. settlementDocumentaryLogEntity.setAmount(item.getInvoicCommissionFeevalue()); // 结算金额
  1732. settlementDocumentaryLogEntity.setSettlementDocumentaryId(settlementDocumentaryFeesEntity.getId()); // 关联id
  1733. settlementDocumentaryLogEntity.setAmountType("2"); //跟单费结算
  1734. settlementDocumentaryLogEntity.setCreateTime(date);
  1735. settlementDocumentaryFeesVo.setSettlementSumId(insPlyIncomeVo.getSettlementSumId());
  1736. settlementDocumentaryFeesService.getBaseMapper().insert(settlementDocumentaryFeesVo);
  1737. settlementDocumentaryLogService.save(settlementDocumentaryLogEntity);
  1738. //修改开票金额
  1739. BigDecimal add = settlementDocumentaryFeesEntity.getInvoicedSettledAmount().add(item.getInvoicCommissionFeevalue());
  1740. settlementDocumentaryFeesEntity.setInvoicedSettledAmount(add);
  1741. BigDecimal subtract = settlementDocumentaryFeesEntity.getSettlementAmount().subtract(add);
  1742. settlementDocumentaryFeesEntity.setInvoicedNotSettledAmount(subtract);
  1743. if (subtract.compareTo(BigDecimal.ZERO) == 0) {
  1744. settlementDocumentaryFeesEntity.setCompletionStatus("2");
  1745. } else if (subtract.compareTo(BigDecimal.ZERO) != 0) {
  1746. settlementDocumentaryFeesEntity.setCompletionStatus("1");
  1747. }
  1748. settlementDocumentaryFeesService.updateById(settlementDocumentaryFeesEntity);
  1749. settleMentAmount = settleMentAmount.add(settlementDocumentaryFeesEntity.getInvoicedSettledAmount());
  1750. settleNotMentAmount = settleNotMentAmount.add(settlementDocumentaryFeesEntity.getInvoicedNotSettledAmount());
  1751. }
  1752. // 更新金额
  1753. SettlementDocumentaryFeesSumEntity settlementDocumentaryFeesSumEntity = settlementDocumentaryFeesSumService.getById(insPlyIncomeVo.getSettlementSumId());
  1754. settlementDocumentaryFeesSumEntity.setInvoicedSettledAmount(settleMentAmount);
  1755. settlementDocumentaryFeesSumEntity.setInvoicedNotSettledAmount(settleNotMentAmount);
  1756. if (settleNotMentAmount.compareTo(BigDecimal.ZERO) == 0) {
  1757. settlementDocumentaryFeesSumEntity.setCompletionStatus("2");
  1758. } else if (settleNotMentAmount.compareTo(BigDecimal.ZERO) != 0) {
  1759. settlementDocumentaryFeesSumEntity.setCompletionStatus("1");
  1760. }
  1761. settlementDocumentaryFeesSumService.updateById(settlementDocumentaryFeesSumEntity);
  1762. }
  1763. return HttpResult.ok();
  1764. }
  1765. /**
  1766. * @param insPlyIncomeVo
  1767. * @return
  1768. */
  1769. @Override
  1770. public List<InsPlyIncome> totalBxAmount(InsPlyIncomeVo insPlyIncomeVo) {
  1771. HashMap<String, Object> params = new HashMap<>();
  1772. params = this.saveParams(insPlyIncomeVo, params);
  1773. params.remove("handlingFeesStatus");
  1774. List<InsPlyIncome> resultList = baseMapper.totalBxAmountNew(params);
  1775. return resultList.stream()
  1776. .sorted(Comparator.comparing(InsPlyIncome::getUnSettledAmount, Comparator.reverseOrder()))
  1777. .collect(Collectors.toList());
  1778. }
  1779. /**
  1780. * @param idList 要开票的数据集合
  1781. * @param resultList 总返回数据
  1782. */
  1783. private void splicingIds(List<InsPlyIncome> idList, List<InsPlyIncome> resultList) {
  1784. // 使用Map来存储agreementId到其id列表的映射
  1785. Map<String, List<String>> idMap = new HashMap<>();
  1786. for (InsPlyIncome idItem : idList) {
  1787. String partnerCompaniesId = idItem.getPartnerCompaniesId();
  1788. idMap.computeIfAbsent(partnerCompaniesId, k -> new ArrayList<>()).add(idItem.getId());
  1789. }
  1790. for (InsPlyIncome resultItem : resultList) {
  1791. List<String> ids = idMap.getOrDefault(resultItem.getPartnerCompaniesId(), Collections.emptyList());
  1792. String idsString = String.join(",", ids);
  1793. resultItem.setIds(idsString);
  1794. }
  1795. }
  1796. /**
  1797. * @param insPlyIncomeVo
  1798. * @return 保险手续费改成多次结算
  1799. */
  1800. @Override
  1801. @Transactional
  1802. public HttpResult<Object> batchInvoicing(InsPlyIncomeVo insPlyIncomeVo) {
  1803. ImportResult importResult = importAsyncService.getById(insPlyIncomeVo.getSelectIds().get(0)); // 查询 任务
  1804. List<String> byTaskId = incomeTaskRelationshipService.getByTaskId(importResult.getId());
  1805. HashMap<String, Object> params = new HashMap<>();
  1806. if (StringUtils.isNotEmpty(importResult.getId())) {
  1807. params.put("companyId", importResult.getCompanyId());
  1808. params.put("partnerCompaniesId", importResult.getPartnerCompaniesId());
  1809. params.put("isOther", "0");
  1810. if (StringUtils.isNotEmpty(importResult.getHandStatus())) {
  1811. if ("0".equals(importResult.getHandStatus())) {
  1812. params.put("isNotCar", "0");
  1813. } else if ("1".equals(importResult.getHandStatus())) {
  1814. params.put("isNotCar", "1");
  1815. }
  1816. }
  1817. if (!CollectionUtils.isEmpty(byTaskId)) {
  1818. params.put("incomeIds", byTaskId);
  1819. }
  1820. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(params);
  1821. if (!CollectionUtils.isEmpty(insPlyIncomes)) {
  1822. if (insPlyIncomeVo != null) { // 确保insPlyIncomeVo不是null
  1823. for (InsPlyIncome item : insPlyIncomes) {
  1824. item.setInvoicTime(LocalDate.now());
  1825. item.setInvoicId(insPlyIncomeVo.getInvoicId());
  1826. item.setHandlingFeesStatus("2");
  1827. if (StringUtils.isNotEmpty(item.getTaskId())) {
  1828. return HttpResult.error("该单据已经开票 ");
  1829. } else {
  1830. item.setTaskId(importResult.getId());
  1831. item.setSettlementTime(LocalDateTime.now());
  1832. baseMapper.updateById(item);
  1833. }
  1834. }
  1835. }
  1836. }
  1837. }
  1838. insPlyIncomeVo.setNoInvoicCommissionFeevalue(importResult.getTotalAmount());
  1839. insPlyIncomeVo.setOtherFeevalue(importResult.getTotalAmount());
  1840. insPlyIncomeVo.setHandlingFeesStatus("0"); // 0手续费 1 跟单费
  1841. insPlyIncomeVo.setIsNotCar(insPlyIncomeVo.getIsNotCar());
  1842. insPlyIncomeVo.setAgreementId(importResult.getAgreementId());
  1843. insPlyIncomeVo.setAgreementType(insPlyIncomeVo.getAgreementType());
  1844. insPlyIncomeVo.setPartnerCompaniesId(importResult.getPartnerCompaniesId());
  1845. insPlyIncomeVo.setSettlementAmount(importResult.getTotalAmount());
  1846. insPlyIncomeVo.setContractId(insPlyIncomeVo.getInvoicId());
  1847. insPlyIncomeVo.setCompanyId(importResult.getCompanyId());
  1848. insPlyIncomeVo.setTaskId(importResult.getId());
  1849. this.batchInvoic(insPlyIncomeVo);
  1850. return HttpResult.ok();
  1851. }
  1852. @Override
  1853. public HttpResult<InsPlyIncome> queryInvoicing(InsPlyIncomeVo insPlyIncomeVo) {
  1854. HashMap<String, Object> params = new HashMap<>();
  1855. params = this.saveParams(insPlyIncomeVo, params);
  1856. InsPlyIncome result = baseMapper.queryInvoicing(params); //总金额
  1857. params.put("handlingFeesStatus", "0");
  1858. InsPlyIncome noResult = baseMapper.queryInvoicing(params); //未结算金额
  1859. result.setReadyCommissionFeevalue(noResult.getCommissionFeevalue());
  1860. return HttpResult.ok(result);
  1861. }
  1862. @Override
  1863. @Transactional
  1864. public HttpResult<Object> batchBxBalance(InsPlyIncomeVo insPlyIncomeVo) {
  1865. if( insPlyIncomeVo.getSettlementAmount() ==null || insPlyIncomeVo.getSettlementAmount().compareTo(BigDecimal.ZERO) <=0){
  1866. throw new SystemException("金额未填写");
  1867. }
  1868. // 表内总金额
  1869. SettlementDocumentaryFeesEntity byIdSettlementDocumentaryFeesEntity =
  1870. settlementDocumentaryFeesService.getById(insPlyIncomeVo.getId());
  1871. BigDecimal invoicAmount = byIdSettlementDocumentaryFeesEntity.getTotalAmount();
  1872. String taskId = byIdSettlementDocumentaryFeesEntity.getTaskId();
  1873. List<String> byTaskId = incomeTaskRelationshipService.getByTaskId(taskId);
  1874. HashMap<String, Object> params = new HashMap<>();
  1875. params.put("id", insPlyIncomeVo.getId());
  1876. params.put("handlingFeesStatus", "0");
  1877. SettlementDocumentaryFeesEntity parentSettlementDocumentaryFeesEntity =
  1878. settlementDocumentaryFeesService.getByParentSettlementAmount(params);
  1879. if (ObjectUtils.isNotEmpty(parentSettlementDocumentaryFeesEntity)) { // 多次结算
  1880. BigDecimal totalAmount = parentSettlementDocumentaryFeesEntity.getTotalAmount();
  1881. totalAmount = totalAmount.add(insPlyIncomeVo.getSettlementAmount());
  1882. if (invoicAmount.compareTo(totalAmount) < 0) {
  1883. return HttpResult.error("结算金额大于开票金额");
  1884. }
  1885. if(totalAmount.compareTo(invoicAmount) ==0){
  1886. HashMap<String, Object> incomeParams = new HashMap<>();
  1887. incomeParams.put("incomeIds", byTaskId);
  1888. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(incomeParams);
  1889. for (InsPlyIncome item : insPlyIncomes) {
  1890. item.setHandlingFeesStatus("1");
  1891. item.setSettlementUserId(BaseController.getUser().getId());
  1892. baseMapper.updateById(item);
  1893. }
  1894. }
  1895. } else {
  1896. if (invoicAmount.compareTo(insPlyIncomeVo.getSettlementAmount()) < 0) {
  1897. return HttpResult.error("结算金额大于开票金额");
  1898. } else if (invoicAmount.compareTo(insPlyIncomeVo.getSettlementAmount()) == 0) {
  1899. HashMap<String, Object> incomeParams = new HashMap<>();
  1900. incomeParams.put("incomeIds", byTaskId);
  1901. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(incomeParams);
  1902. for (InsPlyIncome item : insPlyIncomes) {
  1903. item.setHandlingFeesStatus("1");
  1904. item.setSettlementUserId(BaseController.getUser().getId());
  1905. baseMapper.updateById(item);
  1906. }
  1907. }
  1908. }
  1909. SettlementDocumentaryFeesVo settlementDocumentaryFeesVo = new SettlementDocumentaryFeesVo();
  1910. settlementDocumentaryFeesVo.setInvoiceId(insPlyIncomeVo.getInvoicId()); //开票号
  1911. settlementDocumentaryFeesVo.setSettlementTime(insPlyIncomeVo.getSettlementTime()); //结算时间
  1912. settlementDocumentaryFeesVo.setSettlementStatus("2"); //2为结算状态
  1913. settlementDocumentaryFeesVo.setCompanyId(insPlyIncomeVo.getCompanyId()); // 保险公司id
  1914. settlementDocumentaryFeesVo.setPartnerCompaniesId(insPlyIncomeVo.getPartnerCompaniesId()); //合作公司id
  1915. settlementDocumentaryFeesVo.setIsNotCar(insPlyIncomeVo.getIsNotCar()); // 是否是非车
  1916. settlementDocumentaryFeesVo.setInvoicingMethod(insPlyIncomeVo.getInvoicingMethod()); //开票方式
  1917. settlementDocumentaryFeesVo.setTaxPoints(insPlyIncomeVo.getTaxPoints()); //税点
  1918. settlementDocumentaryFeesVo.setExpendAmount(insPlyIncomeVo.getInvoicCommissionFeevalue().multiply(BigDecimal.ONE.subtract(insPlyIncomeVo.getTaxPoints().divide(new BigDecimal(100)))));
  1919. settlementDocumentaryFeesVo.setTaskId(insPlyIncomeVo.getTaskId());
  1920. settlementDocumentaryFeesVo.setSettlementAmount(insPlyIncomeVo.getSettlementAmount()); //进账金额
  1921. settlementDocumentaryFeesVo.setTotalAmount(insPlyIncomeVo.getInvoicCommissionFeevalue());
  1922. settlementDocumentaryFeesVo.setHandlingFeesStatus("0");
  1923. settlementDocumentaryFeesVo.setParentId(insPlyIncomeVo.getId());
  1924. settlementDocumentaryFeesVo.setPartnerCompaniesId(insPlyIncomeVo.getPartnerCompaniesId());
  1925. settlementDocumentaryFeesVo.setSettlementImageId(insPlyIncomeVo.getSettlementImageId());
  1926. settlementDocumentaryFeesVo.setCreateTime(LocalDateTime.now());
  1927. settlementDocumentaryFeesVo.setAgreementType("2"); //1平台 2 保险
  1928. BigDecimal add = byIdSettlementDocumentaryFeesEntity.getInvoicedSettledAmount().add(insPlyIncomeVo.getSettlementAmount());
  1929. byIdSettlementDocumentaryFeesEntity.setInvoicedSettledAmount(add);
  1930. BigDecimal subtract = byIdSettlementDocumentaryFeesEntity.getTotalAmount().subtract(add);
  1931. byIdSettlementDocumentaryFeesEntity.setInvoicedNotSettledAmount(subtract);
  1932. if (subtract.compareTo(BigDecimal.ZERO) == 0) {
  1933. byIdSettlementDocumentaryFeesEntity.setCompletionStatus("2");
  1934. } else if (subtract.compareTo(BigDecimal.ZERO) != 0) {
  1935. byIdSettlementDocumentaryFeesEntity.setCompletionStatus("1");
  1936. }
  1937. settlementDocumentaryFeesService.updateById(byIdSettlementDocumentaryFeesEntity);
  1938. settlementDocumentaryFeesService.inertSettle(settlementDocumentaryFeesVo);
  1939. List<InsuranceHandlingSettlementMonthEntity> insuranceHandlingList = insPlyIncomeVo.getInsuranceHandlingList();
  1940. ArrayList<InsuranceHandlingSettlementMonthEntity> insuranceHandlingListNew = new ArrayList<>();
  1941. // 判断是否是第一次结算
  1942. InsuranceHandlingSettlementMonthVo insuranceHandlingSettlementMonthVo = new InsuranceHandlingSettlementMonthVo();
  1943. insuranceHandlingSettlementMonthVo.setPartnerCompaniesId(insPlyIncomeVo.getPartnerCompaniesId());
  1944. insuranceHandlingSettlementMonthVo.setTaskId(insPlyIncomeVo.getTaskId());
  1945. List<InsuranceHandlingSettlementMonthDto> insuranceHandlingSettlementMonthDtos = insuranceHandlingSettlementMonthService.getQueryLists(insuranceHandlingSettlementMonthVo);
  1946. // 分批结算
  1947. BigDecimal allsettlementAmount = BigDecimal.ZERO;
  1948. for(InsuranceHandlingSettlementMonthEntity item : insuranceHandlingList){
  1949. String incomeSigningTime = item.getIncomeSigningTime();
  1950. DateTimeFormatter yearMonthFormatter = DateTimeFormatter.ofPattern("yyyy-MM");
  1951. // 尝试解析为LocalDate(这里实际上解析为YearMonth,但使用LocalDate的parse方法,因为它会接受只有年和月的TemporalQuery)
  1952. // 注意:这里直接解析为LocalDate可能会引发异常,因为DateTimeFormatter应该与要解析的Temporal类型精确匹配。
  1953. // 但由于Java的灵活性,以及默认行为(假设日为1),这通常可以工作。
  1954. LocalDate date = YearMonth.parse(incomeSigningTime, yearMonthFormatter).atDay(1);
  1955. // 将LocalDate转换为LocalDateTime,时间为00:00:00
  1956. LocalDateTime localDateTime = date.atStartOfDay();
  1957. item.setIsNotCar(insPlyIncomeVo.getIsNotCar());
  1958. BigDecimal totalAmount = item.getRemainingAmount(); //开票未结算
  1959. BigDecimal settlementAmount = item.getSettlementAmount(); //结算金额
  1960. InsuranceHandlingSettlementMonthEntity byId = insuranceHandlingSettlementMonthService.getById(item.getId());
  1961. if(ObjectUtils.isNotEmpty(byId)){
  1962. allsettlementAmount = this.calculateTotal(byId.getSettlementAmount(),item.getSettlementAmount(),null);
  1963. item.setSettlementAmount(allsettlementAmount);
  1964. }else {
  1965. item.setSettlementAmount(item.getSettlementAmount());
  1966. }
  1967. BigDecimal subtract1 = totalAmount.subtract(settlementAmount);
  1968. item.setRemainingAmount(subtract1);
  1969. item.setCreateTime(LocalDateTime.now());
  1970. item.setPartnerCompaniesId(insPlyIncomeVo.getPartnerCompaniesId());
  1971. item.setSigningTime(localDateTime);
  1972. item.setSettlementDocumentaryFeesId(byIdSettlementDocumentaryFeesEntity.getId());
  1973. insuranceHandlingListNew.add(item);
  1974. }
  1975. if(insuranceHandlingSettlementMonthDtos.size()>0){
  1976. insuranceHandlingSettlementMonthService.updateBatchById(insuranceHandlingListNew);
  1977. }else{
  1978. insuranceHandlingSettlementMonthService.saveBatch(insuranceHandlingListNew);
  1979. }
  1980. return HttpResult.ok();
  1981. }
  1982. @Override
  1983. public HttpResult<InsPlyIncome> querySettInvoicing(InsPlyIncomeVo insPlyIncomeVo) {
  1984. HashMap<String, Object> params = new HashMap<>();
  1985. params = this.saveParams(insPlyIncomeVo, params);
  1986. InsPlyIncome insPlyIncome = baseMapper.queryInvoicing(params); //已经开票
  1987. return HttpResult.ok(insPlyIncome);
  1988. }
  1989. /**
  1990. * @param insPlyIncomeVo
  1991. * @return
  1992. */
  1993. @Override
  1994. public HttpResult<List<InsPlyIncome>> allOtherAmount(InsPlyIncomeVo insPlyIncomeVo) {
  1995. HashMap<String, Object> params = new HashMap<>();
  1996. params = this.saveParams(insPlyIncomeVo, params);
  1997. List<InsPlyIncome> resultList = baseMapper.totalBxAmount(params);
  1998. //总跟单费
  1999. for (InsPlyIncome item : resultList) {
  2000. BigDecimal otherFeevalue = BigDecimal.ZERO; //总跟单金额
  2001. BigDecimal invoicCommissionFeevalue = BigDecimal.ZERO; //已开票跟单费
  2002. BigDecimal readyCommissionFeevalue = BigDecimal.ZERO; // 已开票已结算 跟单费
  2003. BigDecimal noInvoicCommissionFeevalue = BigDecimal.ZERO; //未开票跟单金额
  2004. BigDecimal unSettledAmount = BigDecimal.ZERO; //未结算跟单金额
  2005. BigDecimal expendAmount = BigDecimal.ZERO; //实收金额
  2006. BigDecimal taxesFees = BigDecimal.ZERO; //税费
  2007. BigDecimal taxPoints = BigDecimal.ZERO; //税点
  2008. params.put("partnerCompaniesId", item.getPartnerCompaniesId());
  2009. params.remove("handlingFeesStatus");
  2010. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(params); // 总跟单费
  2011. for (InsPlyIncome all : insPlyIncomes) {
  2012. otherFeevalue = otherFeevalue.add(all.getOtherFeevalue());
  2013. }
  2014. //已开票金额 = 开票未结算+ 开票已结算
  2015. params.put("handlingFeesStatus", "1"); // 开票
  2016. params.put("settlementStatus", "1"); // 开票
  2017. List<SettlementDocumentaryFeesEntity> invoicInsPlyIncomes = settlementDocumentaryFeesService.queryNew(params); //金额总数
  2018. for (SettlementDocumentaryFeesEntity invoicInsPlyIncome : invoicInsPlyIncomes) {
  2019. BigDecimal invoicIcommissionFeevalue = invoicInsPlyIncome.getSettlementAmount();// 已经开票金额
  2020. invoicCommissionFeevalue = invoicCommissionFeevalue.add(invoicIcommissionFeevalue); //开票金额
  2021. }
  2022. params.put("settlementStatus", "2"); // 结算
  2023. List<SettlementDocumentaryFeesEntity> settleInsPlyIncomes = settlementDocumentaryFeesService.queryNew(params); //金额总数
  2024. for (SettlementDocumentaryFeesEntity settleInsPlyIncome : settleInsPlyIncomes) {
  2025. BigDecimal settleIcommissionFeevalue = settleInsPlyIncome.getSettlementAmount();// 已结算金额
  2026. readyCommissionFeevalue = readyCommissionFeevalue.add(settleIcommissionFeevalue); //已结算总
  2027. BigDecimal divide = new BigDecimal(100).subtract(settleInsPlyIncome.getTaxPoints()).divide(new BigDecimal(100));
  2028. expendAmount = expendAmount.add(settleInsPlyIncome.getSettlementAmount().multiply(divide));
  2029. }
  2030. params.put("settlementStatus", 0); //未开票金额
  2031. List<SettlementDocumentaryFeesEntity> noInvoicInsPlyIncomes = settlementDocumentaryFeesService.queryNew(params); //金额总数
  2032. for (SettlementDocumentaryFeesEntity noInvoicInsPlyIncome : noInvoicInsPlyIncomes) {
  2033. BigDecimal noInvoicIcommissionFeevalue = noInvoicInsPlyIncome.getSettlementAmount();// 未开票金额
  2034. noInvoicCommissionFeevalue = noInvoicCommissionFeevalue.add(noInvoicIcommissionFeevalue); //未开票总金额
  2035. }
  2036. noInvoicCommissionFeevalue = otherFeevalue.subtract(invoicCommissionFeevalue);// 未开票
  2037. unSettledAmount = otherFeevalue.subtract(readyCommissionFeevalue); //未结算
  2038. //已开票金额
  2039. item.setOtherFeevalue(otherFeevalue); //总手续费
  2040. item.setAllInvoicCommissionFeevalue(invoicCommissionFeevalue); //总开票金额
  2041. // 开票未结算 = 开票金额 - 已开票已结算
  2042. invoicCommissionFeevalue = invoicCommissionFeevalue.subtract(readyCommissionFeevalue);
  2043. item.setInvoicCommissionFeevalue(invoicCommissionFeevalue); //开票未结算
  2044. item.setReadyCommissionFeevalue(readyCommissionFeevalue); //已开票已结算
  2045. item.setNoInvoicCommissionFeevalue(noInvoicCommissionFeevalue); //未开票金额
  2046. item.setUnSettledAmount(unSettledAmount); // 未结算金额
  2047. // 实收金额 = 结算金额 *1-税点
  2048. taxesFees = readyCommissionFeevalue.subtract(expendAmount);
  2049. item.setExpendAmount(expendAmount);
  2050. item.setTaxesFees(taxesFees);
  2051. }
  2052. if (StringUtils.isNotEmpty(insPlyIncomeVo.getStatus())) {
  2053. if ("0".equals(insPlyIncomeVo.getStatus())) {
  2054. return HttpResult.ok(resultList.stream().filter(insPlyIncome -> insPlyIncome.getAllInvoicCommissionFeevalue().compareTo(insPlyIncome.getReadyCommissionFeevalue()) > 0).sorted(Comparator.comparing(InsPlyIncome::getUnSettledAmount, Comparator.reverseOrder())).collect(Collectors.toList()));
  2055. }else if ("1".equals(insPlyIncomeVo.getStatus())){
  2056. return HttpResult.ok(resultList.stream().filter(insPlyIncome -> insPlyIncome.getAllInvoicCommissionFeevalue().compareTo(insPlyIncome.getReadyCommissionFeevalue()) == 0).sorted(Comparator.comparing(InsPlyIncome::getUnSettledAmount, Comparator.reverseOrder())).collect(Collectors.toList())) ;
  2057. }
  2058. }
  2059. return HttpResult.ok(resultList);
  2060. }
  2061. @Override
  2062. @Transactional
  2063. public HttpResult<Object> batchInvoic(InsPlyIncomeVo insPlyIncomeVo) {
  2064. SettlementDocumentaryFeesVo settlementDocumentaryFeesVo = new SettlementDocumentaryFeesVo(); // 生成跟单费结算表
  2065. if (StringUtils.isNotEmpty(insPlyIncomeVo.getYear())) {
  2066. settlementDocumentaryFeesVo.setTimeFrame(insPlyIncomeVo.getYear());//年度
  2067. }
  2068. if (!CollectionUtils.isEmpty(insPlyIncomeVo.getMultipleSelection())) {
  2069. InsPlyIncomeVo insPlyIncomeVo1 = insPlyIncomeVo.getMultipleSelection().get(0);
  2070. insPlyIncomeVo.setSettlementAmount(insPlyIncomeVo1.getSettlementAmount());
  2071. insPlyIncomeVo.setOtherFeevalue(insPlyIncomeVo1.getAllTotalOtherFeevalue());
  2072. YearMonth yearMonth = YearMonth.parse(insPlyIncomeVo1.getMonthYear());
  2073. LocalDate signingTime = yearMonth.atDay(1);
  2074. settlementDocumentaryFeesVo.setSigningTime(signingTime);
  2075. }
  2076. if (insPlyIncomeVo.getOtherFeevalue().compareTo(BigDecimal.ZERO) == 0) {
  2077. throw new SystemException("总金额为0不允许开票");
  2078. }
  2079. if (insPlyIncomeVo.getNoInvoicCommissionFeevalue().compareTo(BigDecimal.ZERO) == 0) {
  2080. throw new SystemException("未开票金额为0不允许开票");
  2081. }
  2082. if (insPlyIncomeVo.getSettlementAmount() == null || insPlyIncomeVo.getSettlementAmount().compareTo(BigDecimal.ZERO) <= 0) {
  2083. throw new SystemException("开票金额错误不允许开票");
  2084. }
  2085. if (insPlyIncomeVo.getNoInvoicCommissionFeevalue().compareTo(insPlyIncomeVo.getSettlementAmount()) < 0) {
  2086. throw new SystemException("开票金额必须小于未开票金额 不允许开票");
  2087. }
  2088. if (StringUtils.isNotEmpty(insPlyIncomeVo.getYear())) {
  2089. settlementDocumentaryFeesVo.setYear(insPlyIncomeVo.getYear());
  2090. }
  2091. if (StringUtils.isNotEmpty(insPlyIncomeVo.getMonth())) {
  2092. settlementDocumentaryFeesVo.setMonth(insPlyIncomeVo.getMonth());
  2093. }
  2094. if (StringUtils.isNotEmpty(insPlyIncomeVo.getDay())) {
  2095. settlementDocumentaryFeesVo.setDay(insPlyIncomeVo.getDay());
  2096. }
  2097. settlementDocumentaryFeesVo.setCompanyId(insPlyIncomeVo.getCompanyId());// 保险公司id
  2098. settlementDocumentaryFeesVo.setPartnerCompaniesId(insPlyIncomeVo.getPartnerCompaniesId()); //合作公司id
  2099. settlementDocumentaryFeesVo.setAgreementId(insPlyIncomeVo.getAgreementId());
  2100. settlementDocumentaryFeesVo.setTotalAmount(insPlyIncomeVo.getOtherFeevalue()); //其他费用金额
  2101. settlementDocumentaryFeesVo.setUnsettledAmount(insPlyIncomeVo.getNoInvoicCommissionFeevalue().subtract(insPlyIncomeVo.getSettlementAmount())); //未结算
  2102. settlementDocumentaryFeesVo.setSettlementAmount(insPlyIncomeVo.getSettlementAmount());//已经开票
  2103. settlementDocumentaryFeesVo.setCreateTime(LocalDateTime.now());
  2104. settlementDocumentaryFeesVo.setSettlementStatus("1");
  2105. settlementDocumentaryFeesVo.setIsNotCar(insPlyIncomeVo.getIsNotCar());
  2106. if (StringUtils.isNotEmpty(insPlyIncomeVo.getContractId())) {
  2107. settlementDocumentaryFeesVo.setInvoiceId(insPlyIncomeVo.getContractId()); //开票号
  2108. }
  2109. if (StringUtils.isNotEmpty(insPlyIncomeVo.getTaskId())) {
  2110. settlementDocumentaryFeesVo.setTaskId(insPlyIncomeVo.getTaskId());
  2111. }
  2112. settlementDocumentaryFeesVo.setAgreementType("2");
  2113. settlementDocumentaryFeesVo.setHandlingFeesStatus(insPlyIncomeVo.getHandlingFeesStatus());
  2114. settlementDocumentaryFeesVo.setCompletionStatus("0");
  2115. settlementDocumentaryFeesVo.setInvoicedSettledAmount(BigDecimal.ZERO);
  2116. settlementDocumentaryFeesVo.setInvoicedNotSettledAmount(insPlyIncomeVo.getSettlementAmount());
  2117. settlementDocumentaryFeesVo.setInvoicingMethod(insPlyIncomeVo.getInvoicingMethod()); //开票方式
  2118. settlementDocumentaryFeesVo.setTaxPoints(insPlyIncomeVo.getTaxPoints()); //税点
  2119. settlementDocumentaryFeesVo.setIds(insPlyIncomeVo.getIds());
  2120. // 税点支出
  2121. if ("0".equals(insPlyIncomeVo.getInvoicingMethod()) && BigDecimalUtils.nullToZero(insPlyIncomeVo.getTaxPoints()) != null && insPlyIncomeVo.getTaxPoints().compareTo(BigDecimal.ZERO) != 0 && BigDecimalUtils.nullToZero(insPlyIncomeVo.getSettlementAmount()) != null) {
  2122. BigDecimal settlementAmount = insPlyIncomeVo.getSettlementAmount();
  2123. settlementDocumentaryFeesVo.setExpendAmount(settlementAmount.multiply(BigDecimal.ONE.subtract(insPlyIncomeVo.getTaxPoints().divide(new BigDecimal(100)))));
  2124. } else {
  2125. settlementDocumentaryFeesVo.setExpendAmount(insPlyIncomeVo.getSettlementAmount());
  2126. }
  2127. // 跟单生成批次表
  2128. SettlementDocumentaryFeesSumEntity settlementDocumentaryFeesSumEntity = this.saveSumSettlement(insPlyIncomeVo);
  2129. if(ObjectUtils.isNotEmpty(settlementDocumentaryFeesSumEntity)){
  2130. settlementDocumentaryFeesVo.setSettlementSumId(settlementDocumentaryFeesSumEntity.getId());
  2131. }
  2132. return settlementDocumentaryFeesService.inertSettle(settlementDocumentaryFeesVo);
  2133. }
  2134. private SettlementDocumentaryFeesSumEntity saveSumSettlement(InsPlyIncomeVo insPlyIncomeVo) {
  2135. String handlingFeesStatus = insPlyIncomeVo.getHandlingFeesStatus();
  2136. SettlementDocumentaryFeesSumEntity settlementDocumentaryFeesSumEntity = new SettlementDocumentaryFeesSumEntity();
  2137. BigDecimal totalAmount = BigDecimal.ZERO;
  2138. if("1".equals(handlingFeesStatus)){
  2139. List<InsPlyIncomeVo> nowInsPlyIncomeVo = insPlyIncomeVo.getMultipleSelection();
  2140. for (InsPlyIncomeVo item: nowInsPlyIncomeVo ){
  2141. totalAmount = totalAmount.add(item.getSettlementAmount()) ;
  2142. }
  2143. settlementDocumentaryFeesSumEntity.setPartnerCompaniesId(insPlyIncomeVo.getPartnerCompaniesId());
  2144. settlementDocumentaryFeesSumEntity.setCompanyId(insPlyIncomeVo.getCompanyId());
  2145. settlementDocumentaryFeesSumEntity.setCreateTime(new Date());
  2146. settlementDocumentaryFeesSumEntity.setInvoicId(insPlyIncomeVo.getContractId());
  2147. settlementDocumentaryFeesSumEntity.setInvoicingMethod(insPlyIncomeVo.getInvoicingMethod());
  2148. settlementDocumentaryFeesSumEntity.setIsNotCar(insPlyIncomeVo.getIsNotCar());
  2149. settlementDocumentaryFeesSumEntity.setSettlementStatus("1");
  2150. settlementDocumentaryFeesSumEntity.setUserId(BaseController.getUser().getId());
  2151. settlementDocumentaryFeesSumEntity.setInvoicedSettledAmount(BigDecimal.ZERO);
  2152. settlementDocumentaryFeesSumEntity.setCompletionStatus("0");
  2153. settlementDocumentaryFeesSumEntity.setTotalAmount(totalAmount);// 开票总额
  2154. settlementDocumentaryFeesSumEntity.setInvoicedNotSettledAmount(totalAmount);
  2155. settlementDocumentaryFeesSumService.getBaseMapper().insert(settlementDocumentaryFeesSumEntity);
  2156. return settlementDocumentaryFeesSumEntity;
  2157. }
  2158. return settlementDocumentaryFeesSumEntity;
  2159. }
  2160. @Override
  2161. public HttpResult pinHandlingexcel(InsPlyIncomeVo insPlyIncomeVo, HttpServletRequest request, HttpServletResponse response) {
  2162. HashMap<String, Object> params = new HashMap<>();
  2163. params = this.saveParams(insPlyIncomeVo, params);
  2164. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(params);
  2165. ExportParams exportParams = new ExportParams("平台手续费", null, ExcelType.HSSF);
  2166. exportParams.setStyle(ExcelStyleUtil.class);
  2167. List<SettlementFeesExcel> resultList = new ArrayList<>();
  2168. for (InsPlyIncome item : insPlyIncomes) {
  2169. SettlementFeesExcel bxSettlementFeesExcel = new SettlementFeesExcel();
  2170. BeanUtils.copyProperties(item, bxSettlementFeesExcel);
  2171. if ("1".equals(item.getHandlingFeesStatus())) {
  2172. bxSettlementFeesExcel.setHandlingFeesStatus("已结算");
  2173. } else {
  2174. bxSettlementFeesExcel.setHandlingFeesStatus("未结算");
  2175. }
  2176. resultList.add(bxSettlementFeesExcel);
  2177. }
  2178. String uploadPath = this.uploadPath + "/excel/";
  2179. Path path = Paths.get(uploadPath);
  2180. if (!Files.exists(path)) {
  2181. try {
  2182. Files.createDirectories(path);
  2183. } catch (IOException e) {
  2184. e.printStackTrace();
  2185. }
  2186. }
  2187. String fileName = EasyExcelUtils.downExcel(uploadPath, "平台手续费导出", SettlementFeesExcel.class, resultList);
  2188. return HttpResult.ok("", uploadUrl + "excel/" + fileName);
  2189. }
  2190. @Override
  2191. public HttpResult bxHandlingexcel(InsPlyIncomeVo insPlyIncomeVo, HttpServletRequest request, HttpServletResponse response) {
  2192. HashMap<String, Object> params = new HashMap<>();
  2193. params = this.saveParams(insPlyIncomeVo, params);
  2194. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(params);
  2195. String filePathName = "";
  2196. List<BxSettlementFeesNorExcel> resultNoList = new ArrayList<>();
  2197. List<BxSettlementFeesExcel> resultList = new ArrayList<>();
  2198. //判断是否是非车 1 是非车
  2199. if ("1".equals(insPlyIncomeVo.getIsNotCar())) {
  2200. filePathName = "非车手续费导出";
  2201. ExportParams exportParams = new ExportParams("非车手续费", null, ExcelType.HSSF);
  2202. exportParams.setStyle(ExcelStyleUtil.class);
  2203. for (InsPlyIncome item : insPlyIncomes) {
  2204. BxSettlementFeesNorExcel bxSettlementFeesNorExcel = new BxSettlementFeesNorExcel();
  2205. LocalDateTime signDate = item.getSignDate();
  2206. BeanUtils.copyProperties(item, bxSettlementFeesNorExcel);
  2207. bxSettlementFeesNorExcel.setSigndate(signDate);
  2208. if (item.getHandlingFeesStatus().equals("0")) {
  2209. bxSettlementFeesNorExcel.setHandlingFeesStatus("未开票");
  2210. }
  2211. if (item.getHandlingFeesStatus().equals("1")) {
  2212. bxSettlementFeesNorExcel.setHandlingFeesStatus("已开票");
  2213. }
  2214. if (item.getHandlingFeesStatus().equals("2")) {
  2215. bxSettlementFeesNorExcel.setHandlingFeesStatus("已开票未结算");
  2216. }
  2217. resultNoList.add(bxSettlementFeesNorExcel);
  2218. }
  2219. } else {
  2220. filePathName = "车险手续费导出";
  2221. ExportParams exportParams = new ExportParams("车险手续费", null, ExcelType.HSSF);
  2222. exportParams.setStyle(ExcelStyleUtil.class);
  2223. for (InsPlyIncome item : insPlyIncomes) {
  2224. BxSettlementFeesExcel bxSettlementFeesExcel = new BxSettlementFeesExcel();
  2225. LocalDateTime signDate = item.getSignDate();
  2226. BeanUtils.copyProperties(item, bxSettlementFeesExcel);
  2227. bxSettlementFeesExcel.setSigndate(signDate);
  2228. if (item.getHandlingFeesStatus().equals("0")) {
  2229. bxSettlementFeesExcel.setHandlingFeesStatus("未开票");
  2230. }
  2231. if (item.getHandlingFeesStatus().equals("1")) {
  2232. bxSettlementFeesExcel.setHandlingFeesStatus("已开票");
  2233. }
  2234. if (item.getHandlingFeesStatus().equals("2")) {
  2235. bxSettlementFeesExcel.setHandlingFeesStatus("已开票未结算");
  2236. }
  2237. resultList.add(bxSettlementFeesExcel);
  2238. }
  2239. }
  2240. String uploadPath = this.uploadPath + "/excel/";
  2241. Path path = Paths.get(uploadPath);
  2242. if (!Files.exists(path)) {
  2243. try {
  2244. Files.createDirectories(path);
  2245. } catch (IOException e) {
  2246. e.printStackTrace();
  2247. }
  2248. }
  2249. String fileName = "";
  2250. if ("1".equals(insPlyIncomeVo.getIsNotCar())) {
  2251. fileName = EasyExcelUtils.downExcel(uploadPath, filePathName, BxSettlementFeesNorExcel.class, resultNoList);
  2252. } else {
  2253. fileName = EasyExcelUtils.downExcel(uploadPath, filePathName, BxSettlementFeesExcel.class, resultList);
  2254. }
  2255. return HttpResult.ok("", uploadUrl + "excel/" + fileName);
  2256. }
  2257. @Override
  2258. public HttpResult bxOtherExcel(InsPlyIncomeVo insPlyIncomeVo, HttpServletRequest request, HttpServletResponse response) {
  2259. HashMap<String, Object> params = new HashMap<>();
  2260. params = this.saveParams(insPlyIncomeVo, params);
  2261. params.put("agreementType", "2");
  2262. params.put("isOther", "1");
  2263. params.put("isNotCar", "0");
  2264. List<InsPlyIncome> insPlyIncomes = baseMapper.allOtherAmount(params);
  2265. ExportParams exportParams = new ExportParams("跟单费导出", null, ExcelType.HSSF);
  2266. exportParams.setStyle(ExcelStyleUtil.class);
  2267. List<BxOtherExcel> resultList = new ArrayList<>();
  2268. for (InsPlyIncome item : insPlyIncomes) {
  2269. BxOtherExcel bxSettlementFeesExcel = new BxOtherExcel();
  2270. BeanUtils.copyProperties(item, bxSettlementFeesExcel);
  2271. resultList.add(bxSettlementFeesExcel);
  2272. }
  2273. String uploadPath = this.uploadPath + "/excel/";
  2274. Path path = Paths.get(uploadPath);
  2275. if (!Files.exists(path)) {
  2276. try {
  2277. Files.createDirectories(path);
  2278. } catch (IOException e) {
  2279. e.printStackTrace();
  2280. }
  2281. }
  2282. String fileName = EasyExcelUtils.downExcel(uploadPath, "跟单费导出", BxOtherExcel.class, resultList);
  2283. return HttpResult.ok("", uploadUrl + "excel/" + fileName);
  2284. }
  2285. @Override
  2286. public InsPlyIncome bxTotalAmount(InsPlyIncomeVo insPlyIncomeVo) {
  2287. InsPlyIncome insPlyIncome = new InsPlyIncome();
  2288. HashMap<String, Object> params = new HashMap<>();
  2289. params = this.saveParams(insPlyIncomeVo, params);
  2290. BigDecimal sumCommissionFeevalue = BigDecimal.ZERO; //总金额
  2291. BigDecimal sumInvoicCommissionFeevalue = BigDecimal.ZERO; //开票未结算
  2292. BigDecimal sumReadyCommissionFeevalue = BigDecimal.ZERO; // 已开票已结算
  2293. BigDecimal sumNoInvoicCommissionFeevalue = BigDecimal.ZERO; //未开票金额
  2294. BigDecimal sumUnSettledAmount = BigDecimal.ZERO; //未结算金额
  2295. BigDecimal sumAllInvoicCommissionFeevalue = BigDecimal.ZERO; //总开票
  2296. List<InsPlyIncome> resultList = baseMapper.totalBxAmount(params);
  2297. for (InsPlyIncome item : resultList) {
  2298. BigDecimal commissionFeevalue = BigDecimal.ZERO; //总金额
  2299. BigDecimal invoicCommissionFeevalue = BigDecimal.ZERO; //开票未结算
  2300. BigDecimal readyCommissionFeevalue = BigDecimal.ZERO; // 已开票已结算
  2301. BigDecimal noInvoicCommissionFeevalue = BigDecimal.ZERO; //未开票金额
  2302. BigDecimal unSettledAmount; //未结算金额
  2303. params.put("partnerCompaniesId", item.getPartnerCompaniesId());
  2304. params.remove("handlingFeesStatus");
  2305. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(params); //金额总数
  2306. for (InsPlyIncome all : insPlyIncomes) {
  2307. if(ObjectUtils.isNotEmpty(all)){
  2308. commissionFeevalue = commissionFeevalue.add(all.getCommissionFeevalue());
  2309. }
  2310. }
  2311. //已开票金额 = 开票未结算+ 开票已结算
  2312. params.put("handlingFeesStatus", "0"); // 开票
  2313. params.put("settlementStatus", "1"); // 开票
  2314. List<SettlementDocumentaryFeesEntity> invoicInsPlyIncomes = settlementDocumentaryFeesService.queryNew(params); //金额总数
  2315. for (SettlementDocumentaryFeesEntity invoicInsPlyIncome : invoicInsPlyIncomes) {
  2316. BigDecimal invoicIcommissionFeevalue = invoicInsPlyIncome.getSettlementAmount();// 已经开票金额
  2317. invoicCommissionFeevalue = invoicCommissionFeevalue.add(invoicIcommissionFeevalue); //开票金额
  2318. }
  2319. params.put("settlementStatus", "2"); // 结算
  2320. List<SettlementDocumentaryFeesEntity> settleInsPlyIncomes = settlementDocumentaryFeesService.queryNew(params); //金额总数
  2321. for (SettlementDocumentaryFeesEntity settleInsPlyIncome : settleInsPlyIncomes) {
  2322. BigDecimal settleIcommissionFeevalue = settleInsPlyIncome.getSettlementAmount();// 已结算金额
  2323. readyCommissionFeevalue = readyCommissionFeevalue.add(settleIcommissionFeevalue); //已结算总
  2324. }
  2325. params.put("settlementStatus", 0); //未开票金额
  2326. List<SettlementDocumentaryFeesEntity> noInvoicInsPlyIncomes = settlementDocumentaryFeesService.queryNew(params); //金额总数
  2327. for (SettlementDocumentaryFeesEntity noInvoicInsPlyIncome : noInvoicInsPlyIncomes) {
  2328. BigDecimal noInvoicIcommissionFeevalue = noInvoicInsPlyIncome.getSettlementAmount();// 未开票金额
  2329. noInvoicCommissionFeevalue = noInvoicCommissionFeevalue.add(noInvoicIcommissionFeevalue); //未开票总金额
  2330. }
  2331. noInvoicCommissionFeevalue = commissionFeevalue.subtract(invoicCommissionFeevalue);// 未开票
  2332. unSettledAmount = commissionFeevalue.subtract(readyCommissionFeevalue); //未结算
  2333. //已开票金额
  2334. item.setCommissionFeevalue(commissionFeevalue); //总手续费
  2335. item.setAllInvoicCommissionFeevalue(invoicCommissionFeevalue); //总开票金额
  2336. // 开票未结算 = 开票金额 - 已开票已结算
  2337. invoicCommissionFeevalue = invoicCommissionFeevalue.subtract(readyCommissionFeevalue);
  2338. item.setInvoicCommissionFeevalue(invoicCommissionFeevalue); //开票未结算
  2339. item.setReadyCommissionFeevalue(readyCommissionFeevalue); //已开票已结算
  2340. item.setNoInvoicCommissionFeevalue(noInvoicCommissionFeevalue); //未开票金额
  2341. item.setUnSettledAmount(unSettledAmount); // 未结算金额
  2342. sumCommissionFeevalue = sumCommissionFeevalue.add(item.getCommissionFeevalue());
  2343. sumInvoicCommissionFeevalue = sumInvoicCommissionFeevalue.add(item.getInvoicCommissionFeevalue());
  2344. sumReadyCommissionFeevalue = sumReadyCommissionFeevalue.add(item.getReadyCommissionFeevalue());
  2345. sumNoInvoicCommissionFeevalue = sumNoInvoicCommissionFeevalue.add(item.getNoInvoicCommissionFeevalue());
  2346. sumUnSettledAmount = sumUnSettledAmount.add(item.getUnSettledAmount());
  2347. sumAllInvoicCommissionFeevalue = sumAllInvoicCommissionFeevalue.add(item.getAllInvoicCommissionFeevalue());
  2348. }
  2349. if(sumCommissionFeevalue.compareTo(sumReadyCommissionFeevalue) <0){
  2350. sumAllInvoicCommissionFeevalue=sumCommissionFeevalue;
  2351. sumReadyCommissionFeevalue=sumCommissionFeevalue;
  2352. sumNoInvoicCommissionFeevalue =sumCommissionFeevalue.subtract(sumAllInvoicCommissionFeevalue);
  2353. sumUnSettledAmount=sumAllInvoicCommissionFeevalue.subtract(sumReadyCommissionFeevalue);
  2354. }
  2355. insPlyIncome.setCommissionFeevalue(sumCommissionFeevalue);
  2356. insPlyIncome.setInvoicCommissionFeevalue(sumInvoicCommissionFeevalue);
  2357. insPlyIncome.setReadyCommissionFeevalue(sumReadyCommissionFeevalue);
  2358. insPlyIncome.setNoInvoicCommissionFeevalue(sumNoInvoicCommissionFeevalue);
  2359. insPlyIncome.setAllInvoicCommissionFeevalue(sumAllInvoicCommissionFeevalue);
  2360. insPlyIncome.setUnSettledAmount(sumUnSettledAmount);
  2361. return insPlyIncome;
  2362. }
  2363. @Override
  2364. public InsPlyIncome ptTotalAmount(InsPlyIncomeVo insPlyIncomeVo) {
  2365. HashMap<String, Object> params = new HashMap<>();
  2366. params = this.saveParams(insPlyIncomeVo, params);
  2367. InsPlyIncome totalledAmount = baseMapper.ptTotalAmount(params); //总金额
  2368. return totalledAmount;
  2369. }
  2370. @Override
  2371. public HttpResult<List<HashMap<String, Object>>> otherTimeDetail(InsPlyIncomeVo insPlyIncomeVo) {
  2372. HashMap<String, Object> params = new HashMap<>();
  2373. this.saveParams(insPlyIncomeVo, params);
  2374. List<HashMap<String, Object>> resultMap = baseMapper.otherTimeDetail(params);
  2375. Set<String> uniqueYears = new HashSet<>();
  2376. for (Map<String, Object> map : resultMap) {
  2377. // 假设年份是以 "year" 为键的,并且它的值是 String 类型
  2378. String year = String.valueOf(map.get("year"));
  2379. if (year != null) { // 确保年份不是 null
  2380. uniqueYears.add(year);
  2381. }
  2382. }
  2383. this.addMonthYear(uniqueYears, resultMap);
  2384. return HttpResult.ok(resultMap);
  2385. }
  2386. /**
  2387. * uniqueYears 年份间隔 resultMap 返回结果
  2388. *
  2389. * @param uniqueYears
  2390. * @param resultMap 返回一到十二月数据
  2391. */
  2392. private void addMonthYear(Set<String> uniqueYears, List<HashMap<String, Object>> resultMap) {
  2393. // 存储已存在的年份-月份组合,以便快速查找
  2394. Set<String> existingYearMonths = new HashSet<>();
  2395. for (Map<String, Object> entry : resultMap) {
  2396. String monthYear = String.valueOf(entry.get("monthYear"));
  2397. existingYearMonths.add(monthYear);
  2398. }
  2399. // 遍历所有年份和月份,并添加缺失的条目
  2400. for (String year : uniqueYears) {
  2401. for (int month = 1; month <= 12; month++) {
  2402. String strNumber = String.valueOf(month);
  2403. if (strNumber.length() < 2) {
  2404. strNumber = String.format("%02d", Integer.parseInt(strNumber));
  2405. }
  2406. String yearMonth = year + "-" + strNumber;
  2407. if (!existingYearMonths.contains(yearMonth)) {
  2408. // 创建一个新的条目并添加到resultMap中
  2409. HashMap<String, Object> newEntry = new HashMap<>();
  2410. newEntry.put("year", year);
  2411. newEntry.put("monthNumber", strNumber);
  2412. newEntry.put("allTotalOtherFeevalue", 0);
  2413. newEntry.put("invoicCommissionFeevalue", 0);
  2414. newEntry.put("monthYear", yearMonth);
  2415. newEntry.put("noInvoicCommissionFeevalue", 0);
  2416. resultMap.add(newEntry);
  2417. }
  2418. }
  2419. }
  2420. // 使用自定义Comparator对resultMap进行排序
  2421. Collections.sort(resultMap, new Comparator<HashMap<String, Object>>() {
  2422. @Override
  2423. public int compare(HashMap<String, Object> o1, HashMap<String, Object> o2) {
  2424. // 比较 year
  2425. String year1 = String.valueOf(o1.get("year"));
  2426. String year2 = String.valueOf(o2.get("year"));
  2427. int yearComparison = year1.compareTo(year2);
  2428. if (yearComparison != 0) {
  2429. return yearComparison;
  2430. }
  2431. // 如果 year 相同,则比较 monthNumber
  2432. Integer monthNum1 = Integer.parseInt(String.format("%2s", o1.get("monthNumber")).replaceAll(" ", "0"));
  2433. Integer monthNum2 = Integer.parseInt(String.format("%2s", o2.get("monthNumber")).replaceAll(" ", "0"));
  2434. return monthNum1.compareTo(monthNum2);
  2435. }
  2436. });
  2437. }
  2438. @Override
  2439. @Transactional
  2440. public HttpResult<Object> singleInvoic(InsPlyIncomeVo insPlyIncomeVo) {
  2441. // 通过ids 查出跟单非结算单
  2442. SettlementDocumentaryFeesVo settlementDocumentaryFeesVo = new SettlementDocumentaryFeesVo(); // 生成跟单费结算表
  2443. if (!CollectionUtils.isEmpty(insPlyIncomeVo.getMultipleSelection())) {
  2444. SettlementDocumentaryFeesSumEntity settlementDocumentaryFeesSumEntity = this.saveSumSettlement(insPlyIncomeVo);
  2445. for (InsPlyIncomeVo insPlyIncomeVo1 : insPlyIncomeVo.getMultipleSelection()) {
  2446. insPlyIncomeVo.setSettlementAmount(insPlyIncomeVo1.getSettlementAmount());
  2447. insPlyIncomeVo.setOtherFeevalue(insPlyIncomeVo1.getAllTotalOtherFeevalue());
  2448. YearMonth yearMonth = YearMonth.parse(insPlyIncomeVo1.getMonthYear());
  2449. LocalDate signingTime = yearMonth.atDay(1);
  2450. settlementDocumentaryFeesVo.setSigningTime(signingTime);
  2451. if (insPlyIncomeVo.getOtherFeevalue().compareTo(BigDecimal.ZERO) == 0) {
  2452. throw new SystemException("总金额为0不允许开票");
  2453. }
  2454. if (insPlyIncomeVo.getNoInvoicCommissionFeevalue().compareTo(BigDecimal.ZERO) == 0) {
  2455. throw new SystemException("未开票金额为0不允许开票");
  2456. }
  2457. if (insPlyIncomeVo.getSettlementAmount() == null || insPlyIncomeVo.getSettlementAmount().compareTo(BigDecimal.ZERO) <= 0) {
  2458. throw new SystemException("开票金额错误不允许开票");
  2459. }
  2460. if (insPlyIncomeVo.getNoInvoicCommissionFeevalue().compareTo(insPlyIncomeVo.getSettlementAmount()) < 0) {
  2461. throw new SystemException("开票金额必须小于未开票金额 不允许开票");
  2462. }
  2463. if (StringUtils.isNotEmpty(insPlyIncomeVo.getYear())) {
  2464. settlementDocumentaryFeesVo.setTimeFrame(insPlyIncomeVo.getYear());//年度
  2465. }
  2466. if (StringUtils.isNotEmpty(insPlyIncomeVo.getYear())) {
  2467. settlementDocumentaryFeesVo.setYear(insPlyIncomeVo.getYear());
  2468. }
  2469. if (StringUtils.isNotEmpty(insPlyIncomeVo.getMonth())) {
  2470. settlementDocumentaryFeesVo.setMonth(insPlyIncomeVo.getMonth());
  2471. }
  2472. if (StringUtils.isNotEmpty(insPlyIncomeVo.getDay())) {
  2473. settlementDocumentaryFeesVo.setDay(insPlyIncomeVo.getDay());
  2474. }
  2475. settlementDocumentaryFeesVo.setCompletionStatus("0");
  2476. settlementDocumentaryFeesVo.setInvoicedSettledAmount(BigDecimal.ZERO);
  2477. settlementDocumentaryFeesVo.setInvoicedNotSettledAmount(insPlyIncomeVo.getSettlementAmount());
  2478. settlementDocumentaryFeesVo.setCompanyId(insPlyIncomeVo.getCompanyId());// 保险公司id
  2479. settlementDocumentaryFeesVo.setPartnerCompaniesId(insPlyIncomeVo.getPartnerCompaniesId()); //合作公司id
  2480. settlementDocumentaryFeesVo.setTotalAmount(insPlyIncomeVo.getOtherFeevalue()); //其他费用金额
  2481. settlementDocumentaryFeesVo.setUnsettledAmount(insPlyIncomeVo.getNoInvoicCommissionFeevalue().subtract(insPlyIncomeVo.getSettlementAmount())); //未结算
  2482. settlementDocumentaryFeesVo.setSettlementAmount(insPlyIncomeVo.getSettlementAmount());//已经开票
  2483. settlementDocumentaryFeesVo.setCreateTime(LocalDateTime.now());
  2484. settlementDocumentaryFeesVo.setAgreementType("2");
  2485. settlementDocumentaryFeesVo.setIds(insPlyIncomeVo.getIncomeIds());
  2486. settlementDocumentaryFeesVo.setSettlementStatus("1");
  2487. settlementDocumentaryFeesVo.setIsNotCar(insPlyIncomeVo.getIsNotCar());
  2488. if (StringUtils.isNotEmpty(insPlyIncomeVo.getContractId())) {
  2489. settlementDocumentaryFeesVo.setInvoiceId(insPlyIncomeVo.getContractId()); //开票号
  2490. }
  2491. settlementDocumentaryFeesVo.setHandlingFeesStatus(insPlyIncomeVo.getHandlingFeesStatus());
  2492. settlementDocumentaryFeesVo.setInvoicingMethod(insPlyIncomeVo.getInvoicingMethod()); //开票方式
  2493. settlementDocumentaryFeesVo.setTaxPoints(insPlyIncomeVo.getTaxPoints()); //税点
  2494. settlementDocumentaryFeesVo.setIds(insPlyIncomeVo.getIds());
  2495. // settlementDocumentaryFeesVo.setSigningTime(insPlyIncomeVo.getSettlementTime()); //签单日期
  2496. // 税点支出
  2497. if (BigDecimalUtils.nullToZero(insPlyIncomeVo.getTaxPoints()) != null && BigDecimalUtils.nullToZero(insPlyIncomeVo.getSettlementAmount()) != null) {
  2498. BigDecimal settlementAmount = insPlyIncomeVo.getSettlementAmount();
  2499. settlementDocumentaryFeesVo.setExpendAmount(settlementAmount.multiply(BigDecimal.ONE.subtract(insPlyIncomeVo.getTaxPoints().divide(new BigDecimal(100)))));
  2500. }
  2501. if(ObjectUtils.isNotEmpty(settlementDocumentaryFeesSumEntity)){
  2502. settlementDocumentaryFeesVo.setSettlementSumId(settlementDocumentaryFeesSumEntity.getId());
  2503. }
  2504. settlementDocumentaryFeesService.inertSettle(settlementDocumentaryFeesVo);
  2505. }
  2506. }
  2507. return HttpResult.ok();
  2508. }
  2509. @Override
  2510. public void batchUpdate(InsPlyIncomeVo insPlyIncomeVo) {
  2511. HashMap<String, Object> params = new HashMap<>();
  2512. params = this.saveParams(insPlyIncomeVo, params);
  2513. List<InsPlyIncome> list = this.baseMapper.queryNew(params);
  2514. for (InsPlyIncome item : list) {
  2515. item.setContractFileId(insPlyIncomeVo.getContractFileId());
  2516. item.setSettleOtherStatus("1");
  2517. baseMapper.updateById(item);
  2518. }
  2519. }
  2520. @Override
  2521. @Transactional
  2522. public HashMap<String, Object> bxImportOther(MultipartFile multipartFile, String isNotCar) {
  2523. HashMap<String, Object> resultMap = new HashMap<>();
  2524. List<HashMap<String, Object>> resultList = new ArrayList<>();
  2525. HashMap<String, Object> params = new HashMap<>();
  2526. BigDecimal allAmount = BigDecimal.ZERO;
  2527. params.put("isNotCar", isNotCar);
  2528. try {
  2529. List<InsBxOtherExcelDto> dtoList = ExcelEasypoiUtils.importExcel(multipartFile, InsBxOtherExcelDto.class, 0, 1, 1);
  2530. for (InsBxOtherExcelDto item : dtoList) {
  2531. if (StringUtils.isNotEmpty(item.getLicenseno())) {
  2532. params.put("licenseno", item.getLicenseno());
  2533. }
  2534. if (StringUtils.isNotEmpty(item.getPolicyno())) {
  2535. params.put("policyno", item.getPolicyno());
  2536. }
  2537. if (StringUtils.isNotEmpty(item.getSyPolicyno())) {
  2538. params.put("syPolicyno", item.getSyPolicyno());
  2539. }
  2540. params.put("handlingFeesStatus", "0");
  2541. // isOther
  2542. params.put("isOther", "1");
  2543. params.put("isNotCar", "0");
  2544. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  2545. if (item.getJqOtherCostsProportion() == null) {
  2546. item.setJqOtherCostsProportion(BigDecimal.ZERO);
  2547. }
  2548. if (item.getSyOtherCostsProportion() == null) {
  2549. item.setSyOtherCostsProportion(BigDecimal.ZERO);
  2550. }
  2551. if (ObjectUtils.isNotEmpty(byBxLicenseno) && (byBxLicenseno.getJqOtherCostsProportion().compareTo(item.getJqOtherCostsProportion()) != 0 || byBxLicenseno.getSyOtherCostsProportion().compareTo(item.getSyOtherCostsProportion()) != 0)) {
  2552. // InsPlyIncomeLog insPlyIncomeLog = new InsPlyIncomeLog();
  2553. // BeanUtils.copyProperties(byBxLicenseno,insPlyIncomeLog);
  2554. // insPlyIncomeLog.setOperationStatus("2");
  2555. // insPlyIncomeLog.setId(null);
  2556. // insPlyIncomeLog.setIncomeId(byBxLicenseno.getId());
  2557. // insPlyIncomeLogService.saveLog(insPlyIncomeLog); //添加日志
  2558. // 如果比例不相等
  2559. BigDecimal jqOtherCostsProportion = item.getJqOtherCostsProportion();
  2560. BigDecimal syOtherCostsProportion = item.getSyOtherCostsProportion();
  2561. BigDecimal jqOtherAmount = getBigDecimal( byBxLicenseno.getJqPremium(),item.getJqOtherCostsProportion());
  2562. BigDecimal syOtherAmount = getBigDecimal( byBxLicenseno.getSyPremium(),item.getSyOtherCostsProportion());
  2563. // byBxLicenseno.setJqOtherCostsPremium(jqOtherAmount);
  2564. // byBxLicenseno.setSyOtherCostsPremium(syOtherAmount);
  2565. // byBxLicenseno.setJqOtherCostsProportion(jqOtherCostsProportion);
  2566. // byBxLicenseno.setSyOtherCostsProportion(syOtherCostsProportion);
  2567. // byBxLicenseno.setOtherFeevalue(this.calculateTotal(jqOtherAmount, syOtherAmount, null));
  2568. // byBxLicenseno.setOtherFeerate(this.calculateTotal(jqOtherCostsProportion, syOtherCostsProportion, null));
  2569. // byBxLicenseno.setAllFeeValue(this.calculateTotal(jqOtherAmount, syOtherAmount, null));
  2570. // byBxLicenseno.setUpdateUserId(BaseController.getUser().getId());
  2571. // byBxLicenseno.setUpdateUserName(BaseController.getUser().getName());
  2572. // baseMapper.updateById(byBxLicenseno);
  2573. HashMap<String, Object> map = new HashMap<>();
  2574. map.put("licenseno", item.getLicenseno());
  2575. map.put("policyno", item.getPolicyno());
  2576. map.put("syPolicyno", item.getSyPolicyno());
  2577. map.put("jqOtherCostsPremium", jqOtherAmount);
  2578. map.put("syOtherCostsPremium", syOtherAmount);
  2579. map.put("jqOtherCostsProportion", jqOtherCostsProportion);
  2580. map.put("syOtherCostsProportion", syOtherCostsProportion);
  2581. map.put("otherFeevalue", byBxLicenseno.getOtherFeevalue());
  2582. map.put("otherFeerate", byBxLicenseno.getOtherFeerate());
  2583. map.put("id", byBxLicenseno.getId());
  2584. resultList.add(map);
  2585. allAmount = allAmount.add(jqOtherAmount).add(syOtherAmount);
  2586. }
  2587. }
  2588. resultMap.put("allAmount", allAmount);
  2589. resultMap.put("resultList", resultList);
  2590. } catch (IOException e) {
  2591. throw new RuntimeException(e);
  2592. }
  2593. return resultMap;
  2594. }
  2595. @Override
  2596. @Transactional
  2597. public void bxImportOtherConfirm(InsPlyIncomeVo insPlyIncomeVo) {
  2598. if (ObjectUtils.isEmpty(insPlyIncomeVo)) {
  2599. throw new SystemException("请导入文件");
  2600. }
  2601. if (!CollectionUtils.isEmpty(insPlyIncomeVo.getResultList())) {
  2602. for (InsPlyIncome item : insPlyIncomeVo.getResultList()) {
  2603. InsPlyIncomeLog insPlyIncomeLog = new InsPlyIncomeLog();
  2604. BeanUtils.copyProperties(item,insPlyIncomeLog);
  2605. insPlyIncomeLog.setOperationStatus("2");
  2606. insPlyIncomeLog.setId(null);
  2607. insPlyIncomeLog.setIncomeId(item.getId());
  2608. insPlyIncomeLogService.saveLog(insPlyIncomeLog); //添加日志
  2609. item.setOtherFeevalue(this.calculateTotal(item.getJqOtherCostsPremium(), item.getSyOtherCostsPremium(), null));
  2610. item.setOtherFeerate(this.calculateTotal(item.getJqOtherCostsProportion(), item.getSyOtherCostsProportion(), null));
  2611. item.setAllFeeValue(this.calculateTotal(item.getJqOtherCostsPremium(), item.getSyOtherCostsPremium(), null));
  2612. item.setUpdateUserId(BaseController.getUser().getId());
  2613. item.setUpdateUserName(BaseController.getUser().getName());
  2614. baseMapper.updateById(item);
  2615. }
  2616. }
  2617. }
  2618. @Override
  2619. public HashMap<String, Object> ptImportOther(MultipartFile multipartFile) {
  2620. HashMap<String, Object> resultMap = new HashMap<>();
  2621. List<HashMap<String, Object>> resultList = new ArrayList<>();
  2622. BigDecimal allAmount = BigDecimal.ZERO;
  2623. try {
  2624. List<InsPtHandExcelDto> dtoList = ExcelEasypoiUtils.importExcel(multipartFile, InsPtHandExcelDto.class, 0, 1, 1);
  2625. for (InsPtHandExcelDto item : dtoList) {
  2626. HashMap<String, Object> params = new HashMap<>();
  2627. if (StringUtils.isNotEmpty(item.getLicenseno())) {
  2628. params.put("licenseno", item.getLicenseno());
  2629. }
  2630. if (StringUtils.isNotEmpty(item.getPolicyno())) {
  2631. params.put("policyno", item.getPolicyno());
  2632. }
  2633. if (StringUtils.isNotEmpty(item.getSyPolicyno())) {
  2634. params.put("syPolicyno", item.getSyPolicyno());
  2635. }
  2636. if (StringUtils.isNotEmpty(item.getNoPolicyno())) {
  2637. params.put("noPolicyno", item.getNoPolicyno());
  2638. }
  2639. params.put("handlingFeesStatus", "0");
  2640. // isOther
  2641. params.put("isOther", "0");
  2642. params.put("isNotCar", "0");
  2643. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  2644. if (item.getNoOtherCostsProportion() == null) {
  2645. item.setNoOtherCostsProportion(BigDecimal.ZERO);
  2646. }
  2647. if (item.getJqOtherCostsProportion() == null) {
  2648. item.setJqOtherCostsProportion(BigDecimal.ZERO);
  2649. }
  2650. if (item.getSyOtherCostsProportion() == null) {
  2651. item.setSyOtherCostsProportion(BigDecimal.ZERO);
  2652. }
  2653. if (item.getJqSuperviseCostsProportion() == null) {
  2654. item.setJqSuperviseCostsProportion(BigDecimal.ZERO);
  2655. }
  2656. if (item.getSySuperviseCostsProportion() == null) {
  2657. item.setSySuperviseCostsProportion(BigDecimal.ZERO);
  2658. }
  2659. if (item.getNoSuperviseCostsProportion() == null) {
  2660. item.setNoSuperviseCostsProportion(BigDecimal.ZERO);
  2661. }
  2662. if (ObjectUtils.isNotEmpty(byBxLicenseno) && (byBxLicenseno.getJqOtherCostsProportion().compareTo(item.getJqOtherCostsProportion()) != 0 || byBxLicenseno.getSyOtherCostsProportion().compareTo(item.getSyOtherCostsProportion()) != 0|| byBxLicenseno.getNoSuperviseCostsProportion().compareTo(item.getNoSuperviseCostsProportion()) != 0)) {
  2663. InsPlyIncomeLog insPlyIncomeLog = new InsPlyIncomeLog();
  2664. BeanUtils.copyProperties(byBxLicenseno,insPlyIncomeLog);
  2665. insPlyIncomeLog.setOperationStatus("2");
  2666. insPlyIncomeLog.setId(null);
  2667. insPlyIncomeLog.setIncomeId(byBxLicenseno.getId());
  2668. insPlyIncomeLogService.saveLog(insPlyIncomeLog); //添加日志
  2669. // 如果比例不相等
  2670. BigDecimal jqOtherCostsProportion = item.getJqOtherCostsProportion();
  2671. BigDecimal syOtherCostsProportion = item.getSyOtherCostsProportion();
  2672. BigDecimal noOtherCostsProportion = item.getNoOtherCostsProportion();
  2673. BigDecimal jqSuperviseCostsProportion = item.getJqSuperviseCostsProportion();
  2674. BigDecimal sySuperviseCostsProportion = item.getSySuperviseCostsProportion();
  2675. BigDecimal noSuperviseCostsProportion = item.getNoSuperviseCostsProportion();
  2676. BigDecimal jqOtherAmount = algorithmAmount( byBxLicenseno.getJqPremium(),jqOtherCostsProportion);
  2677. BigDecimal syOtherAmount = algorithmAmount( byBxLicenseno.getSyPremium(),syOtherCostsProportion);
  2678. BigDecimal noOtherAmount = algorithmAmount( byBxLicenseno.getNoPremium(),noOtherCostsProportion);
  2679. BigDecimal jqSuperviseCostsAmount = algorithmAmount( byBxLicenseno.getJqPremium(),jqSuperviseCostsProportion);
  2680. BigDecimal sySuperviseCostsAmount = algorithmAmount( byBxLicenseno.getSyPremium(),sySuperviseCostsProportion);
  2681. BigDecimal noSuperviseCostsAmount = algorithmAmount( byBxLicenseno.getNoPremium(),noSuperviseCostsProportion);
  2682. byBxLicenseno.setJqOtherCostsPremium(jqOtherAmount);
  2683. byBxLicenseno.setSyOtherCostsPremium(syOtherAmount);
  2684. byBxLicenseno.setNoOtherCostsPremium(noOtherAmount);
  2685. byBxLicenseno.setJqSuperviseCostsPremiums(jqSuperviseCostsAmount);
  2686. byBxLicenseno.setSySuperviseCostsPremiums(sySuperviseCostsAmount);
  2687. byBxLicenseno.setNoSuperviseCostsPremiums(noSuperviseCostsAmount);
  2688. byBxLicenseno.setJqOtherCostsProportion(jqOtherCostsProportion);
  2689. byBxLicenseno.setSyOtherCostsProportion(syOtherCostsProportion);
  2690. byBxLicenseno.setNoOtherCostsProportion(noOtherCostsProportion);
  2691. byBxLicenseno.setJqSuperviseCostsProportion(jqSuperviseCostsProportion);
  2692. byBxLicenseno.setSySuperviseCostsProportion(sySuperviseCostsProportion);
  2693. byBxLicenseno.setNoSuperviseCostsProportion(noSuperviseCostsProportion);
  2694. byBxLicenseno.setOtherFeevalue(this.calculateTotal(jqOtherAmount, syOtherAmount, noOtherAmount));
  2695. byBxLicenseno.setOtherFeerate(this.calculateTotal(jqOtherCostsProportion, syOtherCostsProportion, noOtherCostsProportion));
  2696. byBxLicenseno.setCommissionFeevalue(this.calculateTotal(jqSuperviseCostsAmount, sySuperviseCostsAmount, noSuperviseCostsAmount));
  2697. byBxLicenseno.setCommissionFeerate(this.calculateTotal(jqSuperviseCostsProportion,sySuperviseCostsProportion,noSuperviseCostsProportion));
  2698. byBxLicenseno.setAllFeeValue(this.calculateTotal(byBxLicenseno.getOtherFeevalue(),byBxLicenseno.getCommissionFeevalue(),null));
  2699. byBxLicenseno.setJqReceivableProportion(this.calculateTotal(jqSuperviseCostsProportion,jqOtherCostsProportion,null));
  2700. byBxLicenseno.setSyReceivableProportion(this.calculateTotal(sySuperviseCostsProportion,syOtherCostsProportion,null));
  2701. byBxLicenseno.setNoReceivableProportion(this.calculateTotal(noSuperviseCostsProportion,noOtherCostsProportion,null));
  2702. byBxLicenseno.setUpdateUserId(BaseController.getUser().getId());
  2703. byBxLicenseno.setUpdateUserName(BaseController.getUser().getName());
  2704. baseMapper.updateById(byBxLicenseno);
  2705. HashMap<String, Object> map = new HashMap<>();
  2706. map.put("licenseno", item.getLicenseno());
  2707. map.put("policyno", item.getPolicyno());
  2708. map.put("syPolicyno", item.getSyPolicyno());
  2709. map.put("noPolicyno", item.getNoPolicyno());
  2710. map.put("jqOtherCostsPremium", jqOtherAmount);
  2711. map.put("syOtherCostsPremium", syOtherAmount);
  2712. map.put("noOtherCostsPremium", noOtherAmount);
  2713. map.put("jqSuperviseCostsPremiums", jqSuperviseCostsAmount);
  2714. map.put("sySuperviseCostsPremiums", sySuperviseCostsAmount);
  2715. map.put("noSuperviseCostsPremiums", noSuperviseCostsAmount);
  2716. map.put("jqOtherCostsProportion", jqOtherCostsProportion);
  2717. map.put("syOtherCostsProportion", syOtherCostsProportion);
  2718. map.put("noOtherCostsProportion", noOtherCostsProportion);
  2719. map.put("jqSuperviseCostsProportion", jqSuperviseCostsProportion);
  2720. map.put("sySuperviseCostsProportion", sySuperviseCostsProportion);
  2721. map.put("noSuperviseCostsProportion", noSuperviseCostsProportion);
  2722. map.put("otherFeevalue", byBxLicenseno.getOtherFeevalue());
  2723. map.put("otherFeerate", byBxLicenseno.getOtherFeerate());
  2724. resultList.add(map);
  2725. allAmount = allAmount.add(jqOtherAmount).add(syOtherAmount).add(noOtherAmount);
  2726. }
  2727. }
  2728. resultMap.put("allAmount", allAmount);
  2729. resultMap.put("resultList", resultList);
  2730. } catch (IOException e) {
  2731. throw new RuntimeException(e);
  2732. }
  2733. return resultMap;
  2734. }
  2735. @Override
  2736. @Transactional
  2737. public HashMap<String, Object> noBxImportOther(MultipartFile multipartFile, String isNotCar) {
  2738. HashMap<String, Object> resultMap = new HashMap<>();
  2739. List<HashMap<String, Object>> resultList = new ArrayList<>();
  2740. HashMap<String, Object> params = new HashMap<>();
  2741. BigDecimal allAmount = BigDecimal.ZERO;
  2742. params.put("isNotCar", isNotCar);
  2743. try {
  2744. List<InsNoBxOtherExcelDto> dtoList = ExcelEasypoiUtils.importExcel(multipartFile, InsNoBxOtherExcelDto.class, 0, 1, 1);
  2745. for (InsNoBxOtherExcelDto item : dtoList) {
  2746. if (StringUtils.isNotEmpty(item.getLicenseno())) {
  2747. params.put("licenseno", item.getLicenseno());
  2748. }
  2749. if (StringUtils.isNotEmpty(item.getNoPolicyno())) {
  2750. params.put("noPolicyno", item.getNoPolicyno());
  2751. }
  2752. params.put("handlingFeesStatus", "0");
  2753. params.put("isNotCar", "1");
  2754. params.put("isOther", "1");
  2755. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  2756. if (ObjectUtils.isNotEmpty(byBxLicenseno) && byBxLicenseno.getNoOtherCostsProportion().compareTo(item.getNoOtherCostsProportion()) != 0) {
  2757. InsPlyIncomeLog insPlyIncomeLog = new InsPlyIncomeLog();
  2758. insPlyIncomeLog.setIncomeId(byBxLicenseno.getId());
  2759. BeanUtils.copyProperties(byBxLicenseno,insPlyIncomeLog);
  2760. insPlyIncomeLog.setOperationStatus("2");
  2761. insPlyIncomeLog.setId(null);
  2762. insPlyIncomeLogService.saveLog(insPlyIncomeLog); //添加日志
  2763. HashMap<String, Object> newMap = new HashMap<>();
  2764. // 如果比例不相等
  2765. BigDecimal noOtherCostsProportion = item.getNoOtherCostsProportion();
  2766. BigDecimal noNoTaxPremium = byBxLicenseno.getNoPremium();
  2767. BigDecimal divisor = new BigDecimal("1.06"); // 最好是使用字符串来避免精度损失
  2768. BigDecimal noOtherAmount = getBigDecimal( noNoTaxPremium,item.getNoOtherCostsProportion());
  2769. // byBxLicenseno.setNoOtherCostsPremium(noOtherAmount);
  2770. // byBxLicenseno.setNoOtherCostsProportion(item.getNoOtherCostsProportion());
  2771. // byBxLicenseno.setAllFeeValue(this.calculateTotal(noOtherAmount, null, null));
  2772. //
  2773. // byBxLicenseno.setOtherFeevalue(this.calculateTotal(noOtherAmount, null, null));
  2774. // byBxLicenseno.setOtherFeerate(this.calculateTotal(noOtherCostsProportion, null, null));
  2775. // baseMapper.updateById(byBxLicenseno);
  2776. newMap.put("licenseno", item.getLicenseno());
  2777. newMap.put("noPolicyno", item.getNoPolicyno());
  2778. newMap.put("noOtherCostsPremium", noOtherAmount);
  2779. newMap.put("noOtherCostsProportion", item.getNoOtherCostsProportion());
  2780. newMap.put("otherFeevalue", byBxLicenseno.getOtherFeevalue());
  2781. newMap.put("otherFeerate", byBxLicenseno.getOtherFeerate());
  2782. newMap.put("id", byBxLicenseno.getId());
  2783. resultList.add(newMap);
  2784. allAmount = allAmount.add(noOtherAmount);
  2785. }
  2786. }
  2787. resultMap.put("allAmount", allAmount);
  2788. resultMap.put("resultList", resultList);
  2789. } catch (IOException e) {
  2790. throw new RuntimeException(e);
  2791. }
  2792. return resultMap;
  2793. }
  2794. @Override
  2795. @Transactional
  2796. public void noBxImportOtherConfirm(InsPlyIncomeVo insPlyIncomeVo) {
  2797. if (ObjectUtils.isEmpty(insPlyIncomeVo)) {
  2798. throw new SystemException("请导入文件");
  2799. }
  2800. if (!CollectionUtils.isEmpty(insPlyIncomeVo.getResultList())) {
  2801. for (InsPlyIncome item : insPlyIncomeVo.getResultList()) {
  2802. InsPlyIncomeLog insPlyIncomeLog = new InsPlyIncomeLog();
  2803. insPlyIncomeLog.setIncomeId(item.getId());
  2804. BeanUtils.copyProperties(item,insPlyIncomeLog);
  2805. insPlyIncomeLog.setOperationStatus("2");
  2806. insPlyIncomeLog.setId(null);
  2807. insPlyIncomeLogService.saveLog(insPlyIncomeLog); //添加日志
  2808. item.setAllFeeValue(this.calculateTotal(item.getNoOtherCostsPremium(), null, null));
  2809. item.setOtherFeevalue(this.calculateTotal(item.getNoOtherCostsPremium(), null, null));
  2810. item.setOtherFeerate(this.calculateTotal(item.getNoOtherCostsProportion(), null, null));
  2811. baseMapper.updateById(item);
  2812. }
  2813. }
  2814. }
  2815. @Override
  2816. public void batchUpdateVoucher(InsPlyIncomeVo insPlyIncomeVo) {
  2817. String s = insPlyIncomeVo.getSelectIds().get(0);
  2818. ImportResult importResult = importAsyncService.getById(s);
  2819. String[] split = importResult.getIds().split(",");
  2820. InsPlyIncome insPlyIncome = new InsPlyIncome();
  2821. for (String id : split) {
  2822. insPlyIncome.setId(id);
  2823. insPlyIncome.setSettlementImageId(insPlyIncomeVo.getSettlementImageId());
  2824. insPlyIncome.setSettleOtherStatus("1");
  2825. baseMapper.updateById(insPlyIncome);
  2826. }
  2827. }
  2828. /**
  2829. * 通过任务id 去查询关联表
  2830. *
  2831. * @param insPlyIncomeVo
  2832. * @return
  2833. */
  2834. @Override
  2835. public HttpResult<Object> reconciliation(InsPlyIncomeVo insPlyIncomeVo) {
  2836. String taskId = insPlyIncomeVo.getTaskId();
  2837. List<String> incomeIdList = incomeTaskRelationshipService.getByTaskId(taskId);
  2838. for (String incomeId : incomeIdList) {
  2839. InsPlyIncome insPlyIncome = baseMapper.getById(incomeId);
  2840. insPlyIncome.setSettleOtherStatus("1");
  2841. insPlyIncome.setSettlementImageId(insPlyIncomeVo.getSettlementImageId());
  2842. baseMapper.updateById(insPlyIncome);
  2843. }
  2844. return HttpResult.ok();
  2845. }
  2846. /**
  2847. * @version
  2848. * @author: hxl
  2849. * @Date: 2024/6/18 10:14
  2850. * @Description: 通过保险公司id和状态查询平台的记录
  2851. */
  2852. @Override
  2853. public List<PlatformSettlementRecordDto> platformSettlementRecord(InsPlyIncomeVo insPlyIncomeVo) {
  2854. // if(insPlyIncomeVo.getPartnerCompaniesId()==null || "".equals(insPlyIncomeVo.getPartnerCompaniesId())){
  2855. // throw new SystemException("合作公司编码(partnerCompaniesId)不能为空");
  2856. // }
  2857. if(insPlyIncomeVo.getHandlingFeesStatus()==null || "".equals(insPlyIncomeVo.getHandlingFeesStatus())){
  2858. throw new SystemException("结算状态 0 未结算 1已结算(handlingFeesStatus)不能为空");
  2859. }
  2860. return baseMapper.platformSettlementRecord(insPlyIncomeVo.getPartnerCompaniesId(),insPlyIncomeVo.getHandlingFeesStatus(),insPlyIncomeVo.getDockingPerson());
  2861. }
  2862. /**
  2863. * @param insPlyIncomeVo
  2864. * @Description: 平台新增
  2865. * @return InsPlyIncome
  2866. */
  2867. @Override
  2868. public HttpResult<InsPlyIncome> ptInsert(InsPlyIncomeVo insPlyIncomeVo) {
  2869. InsPlyIncome insPlyIncome = new InsPlyIncome();
  2870. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
  2871. String agreementId = insPlyIncomeVo.getAgreementId();
  2872. if(StringUtils.isNotEmpty(agreementId)){
  2873. HttpResult<PtlAgreementQueryVo> byAgreementId = ptlAgreementService.getByAgreementId(agreementId);
  2874. if(byAgreementId!=null && ObjectUtils.isNotEmpty(byAgreementId.getData())){
  2875. PtlAgreementQueryVo data = byAgreementId.getData();
  2876. PtlAgreement agreement = data.getAgreement();
  2877. if(ObjectUtils.isNotEmpty(agreement)){
  2878. insPlyIncomeVo.setPartnerCompaniesId(agreement.getPartnerCompaniesId());
  2879. insPlyIncomeVo.setCompanyId(agreement.getInsuranceCompanyId());
  2880. }
  2881. }
  2882. }
  2883. BeanUtils.copyProperties(insPlyIncomeVo, insPlyIncome);
  2884. if (StringUtils.isNotEmpty(insPlyIncome.getPartnerCompaniesId())) {
  2885. // 合作公司id
  2886. String partnerCompaniesId = insPlyIncome.getPartnerCompaniesId();
  2887. insPlyIncome.setPartnerCompaniesId(partnerCompaniesId);
  2888. EsmInsCompany esmInsCompany = EsmInsCompanyService.getById(partnerCompaniesId);
  2889. String name = esmInsCompany.getNamesimple(); //合作名称
  2890. insPlyIncome.setPartnerCompaniesName(name);
  2891. insPlyIncome.setPartnerCompaniesId(insPlyIncome.getPartnerCompaniesId());
  2892. }
  2893. if (StringUtils.isNotEmpty(insPlyIncome.getCompanyId())) {
  2894. String insuranceCompanyId = insPlyIncome.getCompanyId();
  2895. EsmInsCompany esmInsCompany = EsmInsCompanyService.getById(insuranceCompanyId);
  2896. String name = esmInsCompany.getNamesimple(); //保险公司名称 简称
  2897. insPlyIncome.setCompanyName(name);
  2898. }
  2899. // if (insPlyIncome.getJqPremium() != null && insPlyIncome.getJqPremium().compareTo(BigDecimal.ZERO) > 0 && insPlyIncome.getJqSuperviseCostsProportion() != null && insPlyIncome.getJqSuperviseCostsProportion().compareTo(BigDecimal.ZERO) > 0) {
  2900. // insPlyIncome.setJqSuperviseCostsPremiums(this.getBigDecimal(insPlyIncome.getJqPremium(),insPlyIncome.getJqSuperviseCostsProportion()));
  2901. // }
  2902. // if (insPlyIncome.getSyPremium() != null && insPlyIncome.getSyPremium().compareTo(BigDecimal.ZERO) > 0 && insPlyIncome.getSySuperviseCostsProportion() != null && insPlyIncome.getSySuperviseCostsProportion().compareTo(BigDecimal.ZERO) > 0) {
  2903. // insPlyIncome.setSySuperviseCostsPremiums(this.getBigDecimal(insPlyIncome.getSyPremium(),insPlyIncome.getSySuperviseCostsProportion()));
  2904. // }
  2905. // if (insPlyIncome.getNoPremium() != null && insPlyIncome.getNoPremium().compareTo(BigDecimal.ZERO) > 0 && insPlyIncome.getNoSuperviseCostsProportion() != null && insPlyIncome.getNoSuperviseCostsProportion().compareTo(BigDecimal.ZERO) > 0) {
  2906. // insPlyIncome.setNoSuperviseCostsPremiums(this.getBigDecimal(insPlyIncome.getNoPremium(),insPlyIncome.getNoSuperviseCostsProportion()));
  2907. // }
  2908. // if (insPlyIncome.getJqPremium() != null && insPlyIncome.getJqPremium().compareTo(BigDecimal.ZERO) > 0 && insPlyIncome.getJqOtherCostsProportion() != null && insPlyIncome.getJqOtherCostsProportion().compareTo(BigDecimal.ZERO) > 0) {
  2909. // insPlyIncome.setJqOtherCostsPremium(this.getBigDecimal(insPlyIncome.getJqPremium(),insPlyIncome.getJqOtherCostsProportion()));
  2910. // }
  2911. // if (insPlyIncome.getSyPremium() != null && insPlyIncome.getSyPremium().compareTo(BigDecimal.ZERO) > 0 && insPlyIncome.getSyOtherCostsProportion() != null && insPlyIncome.getSyOtherCostsProportion().compareTo(BigDecimal.ZERO) > 0) {
  2912. // insPlyIncome.setSyOtherCostsPremium(this.getBigDecimal(insPlyIncome.getSyPremium(),insPlyIncome.getSyOtherCostsProportion()));
  2913. // }
  2914. // if (insPlyIncome.getNoPremium() != null && insPlyIncome.getNoPremium().compareTo(BigDecimal.ZERO) > 0 && insPlyIncome.getNoOtherCostsProportion() != null && insPlyIncome.getNoOtherCostsProportion().compareTo(BigDecimal.ZERO) > 0) {
  2915. // insPlyIncome.setNoOtherCostsPremium(this.getBigDecimal(insPlyIncome.getNoPremium(),insPlyIncome.getNoOtherCostsProportion()));
  2916. // }
  2917. HashMap<String, Object> params = new HashMap<>();
  2918. params.put("agreeId",insPlyIncomeVo.getAgreeId());
  2919. PtlAgreement ptlAgreement = ptlAgreementService.selectAgreeId(params);
  2920. if (ObjectUtils.isEmpty(ptlAgreement)) {
  2921. return HttpResult.error("协议匹配不上");
  2922. }
  2923. insPlyIncome.setAgreementId(ptlAgreement.getId());
  2924. insPlyIncome.setJqReceivableProportion(this.calculateTotal(insPlyIncome.getJqSuperviseCostsProportion(),insPlyIncome.getNoOtherCostsProportion(),null));
  2925. insPlyIncome.setSyReceivableProportion(this.calculateTotal(insPlyIncome.getSySuperviseCostsProportion(),insPlyIncome.getNoOtherCostsProportion(),null));
  2926. insPlyIncome.setNoReceivableProportion(this.calculateTotal(insPlyIncome.getNoSuperviseCostsProportion(),insPlyIncome.getNoOtherCostsProportion(),null));
  2927. insPlyIncome.setCreateTime(LocalDateTime.now());
  2928. insPlyIncome.setCommissionFeerate(this.calculateTotal(insPlyIncome.getJqSuperviseCostsProportion(),insPlyIncome.getSySuperviseCostsProportion(),insPlyIncome.getNoSuperviseCostsPremiums()));
  2929. insPlyIncome.setCommissionFeevalue(this.calculateTotal(insPlyIncome.getJqSuperviseCostsPremiums(),insPlyIncome.getSySuperviseCostsPremiums(),insPlyIncome.getNoSuperviseCostsPremiums()));
  2930. insPlyIncome.setOtherFeerate(this.calculateTotal(insPlyIncome.getJqOtherCostsProportion(),insPlyIncome.getSyOtherCostsProportion(),insPlyIncome.getNoOtherCostsProportion()));
  2931. insPlyIncome.setOtherFeevalue(this.calculateTotal(insPlyIncome.getJqOtherCostsPremium(),insPlyIncome.getSyOtherCostsPremium(),insPlyIncome.getNoOtherCostsPremium()));
  2932. insPlyIncome.setAllFeeValue(this.calculateTotal(insPlyIncome.getCommissionFeevalue(),insPlyIncome.getOtherFeevalue(),null));
  2933. insPlyIncome.setAgreementType("1");
  2934. insPlyIncome.setHandlingFeesStatus("0");
  2935. insPlyIncome.setCommissionFeevalue(insPlyIncomeVo.getCommissionFeevalue());
  2936. insPlyIncome.setOtherFeevalue(insPlyIncomeVo.getOtherFeevalue());
  2937. insPlyIncome.setIsNotCar("0");
  2938. insPlyIncome.setIsNotDocumentary("0");
  2939. insPlyIncome.setDocumentaryFeesStatus("0");
  2940. insPlyIncome.setAllFeeValue(insPlyIncome.getReceivableAmount());
  2941. if(StringUtils.isNotEmpty(insPlyIncomeVo.getSignDate())){
  2942. LocalDate signDate = LocalDate.parse(insPlyIncomeVo.getSignDate(), formatter);
  2943. insPlyIncome.setSignDate(signDate.atStartOfDay());
  2944. }
  2945. InsPlyIncomeLog insPlyIncomeLog = new InsPlyIncomeLog();
  2946. insPlyIncomeLog.setIncomeId(insPlyIncome.getId());
  2947. insPlyIncome.setId(null);
  2948. BeanUtils.copyProperties(insPlyIncome,insPlyIncomeLog);
  2949. insPlyIncomeLog.setOperationStatus("1");
  2950. insPlyIncomeLogService.saveLog(insPlyIncomeLog); //添加日志
  2951. baseMapper.insert(insPlyIncome);
  2952. return HttpResult.ok();
  2953. }
  2954. /***
  2955. *
  2956. * @param insPlyIncomeVo
  2957. * @return 返回私有 平台 应收 已收 未收
  2958. */
  2959. @Override
  2960. public HttpResult<ArrayList<Map<String,Object>>> totalReceivables(InsPlyIncomeVo insPlyIncomeVo) {
  2961. ArrayList<Map<String,Object>> resultList = new ArrayList<>();
  2962. BigDecimal bxhandAmount = BigDecimal.ZERO; //保险手续费应收
  2963. BigDecimal receivedAmount = BigDecimal.ZERO; //保险手续费应收
  2964. HashMap<String, Object> ptParams = new HashMap<>();
  2965. ptParams.put("agreementType","1");
  2966. InsPlyIncome totalledAmount = baseMapper.ptTotalAmount(ptParams); //应收 未收 已收
  2967. ptParams.clear();
  2968. ptParams.put("commissionFeevalue",totalledAmount.getCommissionFeevalue());
  2969. ptParams.put("noInvoicCommissionFeevalue",totalledAmount.getNoInvoicCommissionFeevalue());
  2970. ptParams.put("readyCommissionFeevalue",totalledAmount.getReadyCommissionFeevalue());
  2971. resultList.add(ptParams);
  2972. //手续费应收
  2973. HashMap<String, Object> privateParams= new HashMap<>();
  2974. privateParams.put("agreementType","2");
  2975. List<InsPlyIncome> bxHandList = baseMapper.queryNew(privateParams);
  2976. for (InsPlyIncome bxhandItem : bxHandList){
  2977. bxhandAmount=bxhandAmount.add(bxhandItem.getAllFeeValue());
  2978. }
  2979. privateParams.clear();
  2980. //已开票金额 = 开票未结算+ 开票已结算
  2981. privateParams.put("settlementStatus", "2"); // 结算
  2982. List<SettlementDocumentaryFeesEntity> invoicInsPlyIncomes = settlementDocumentaryFeesService.queryNew(privateParams); //金额总数
  2983. for (SettlementDocumentaryFeesEntity invoicInsPlyIncome : invoicInsPlyIncomes) {
  2984. receivedAmount =receivedAmount.add(invoicInsPlyIncome.getSettlementAmount());
  2985. }
  2986. if(receivedAmount.compareTo(BigDecimal.ZERO)== 0){
  2987. receivedAmount=bxhandAmount;
  2988. }
  2989. BigDecimal subtract = bxhandAmount.subtract(receivedAmount);
  2990. privateParams.clear();
  2991. privateParams.put("commissionFeevalue",bxhandAmount);
  2992. privateParams.put("noInvoicCommissionFeevalue",receivedAmount);
  2993. privateParams.put("readyCommissionFeevalue",subtract);
  2994. resultList.add(privateParams);
  2995. return HttpResult.ok(resultList);
  2996. }
  2997. /**
  2998. * 根据签单日期月份分组
  2999. * @param insPlyIncomeVo
  3000. * @return 平台 私有 应收 已收
  3001. */
  3002. @Override
  3003. public HttpResult<List<HashMap<String, Object>>> monthTotalReceivables(InsPlyIncomeVo insPlyIncomeVo) {
  3004. HashMap<String, Object> params = new HashMap<>();
  3005. params.put("agreementType", insPlyIncomeVo.getAgreementType());
  3006. if ("1".equals(insPlyIncomeVo.getAgreementType())) { //平台
  3007. params.put("year", insPlyIncomeVo.getYear());
  3008. List<HashMap<String, Object>> ptResultList = baseMapper.ptSumGroupByMonth(params);
  3009. params.put("handlingFeesStatus", "1");
  3010. List<HashMap<String, Object>> ptSettleResultList = baseMapper.ptSumGroupByMonth(params);
  3011. Map<String, BigDecimal> ptMap = new HashMap<>(); // 假设commissionFeevalue是BigDecimal类型
  3012. for (HashMap<String, Object> ptSettleResultListItem : ptSettleResultList) {
  3013. String month = (String) ptSettleResultListItem.get("month");
  3014. if (month == null) {
  3015. // 处理month为null的情况
  3016. continue;
  3017. }
  3018. BigDecimal commissionFeevalue = (BigDecimal) ptSettleResultListItem.get("commissionFeevalue");
  3019. if (commissionFeevalue == null) {
  3020. // 处理commissionFeevalue为null的情况
  3021. continue;
  3022. }
  3023. ptMap.put(month, commissionFeevalue);
  3024. }
  3025. for (HashMap<String, Object> ptResultListItem : ptResultList) {
  3026. BigDecimal bigDecimal1 = ptMap.get(ptResultListItem.get("month"));
  3027. ptResultListItem.put("readyCommissionFeevalue", bigDecimal1);
  3028. BigDecimal commissionFeevalue = new BigDecimal(ptResultListItem.get("commissionFeevalue").toString());
  3029. if (bigDecimal1 !=null && bigDecimal1.compareTo(BigDecimal.ZERO) > 0) {
  3030. BigDecimal subtract = commissionFeevalue.subtract(bigDecimal1);
  3031. ptResultListItem.put("noInvoicCommissionFeevalue", subtract);
  3032. } else {
  3033. ptResultListItem.put("noInvoicCommissionFeevalue", ptResultListItem.get("commissionFeevalue"));
  3034. }
  3035. }
  3036. return HttpResult.ok(ptResultList);
  3037. } else if ("2".equals(insPlyIncomeVo.getAgreementType())) {
  3038. params.put("year", insPlyIncomeVo.getYear());
  3039. List<HashMap<String, Object>> bxResultList = baseMapper.ptSumGroupByMonth(params);
  3040. params.clear();
  3041. params.put("settlementStatus", "2");
  3042. List<HashMap<String, Object>> bxReadyCommissionFeevalue = settlementDocumentaryFeesService.bxSumGroupByMonth(params);
  3043. Map<String, BigDecimal> bxMap = new HashMap<>(); // 假设commissionFeevalue是BigDecimal类型
  3044. for (HashMap<String, Object> bxSettleResultListItem : bxReadyCommissionFeevalue) {
  3045. String month = (String) bxSettleResultListItem.get("month");
  3046. if (month == null) {
  3047. // 处理month为null的情况
  3048. continue;
  3049. }
  3050. BigDecimal commissionFeevalue = (BigDecimal) bxSettleResultListItem.get("commissionFeevalue");
  3051. if (commissionFeevalue == null) {
  3052. // 处理commissionFeevalue为null的情况
  3053. continue;
  3054. }
  3055. bxMap.put(month, commissionFeevalue);
  3056. }
  3057. for (HashMap<String, Object> bxResultListItem : bxResultList) {
  3058. BigDecimal bigDecimal1 = bxMap.get(bxResultListItem.get("month"));
  3059. bxResultListItem.put("readyCommissionFeevalue", bigDecimal1);
  3060. BigDecimal commissionFeevalue = new BigDecimal(bxResultListItem.get("commissionFeevalue").toString());
  3061. if (bigDecimal1 !=null && bigDecimal1.compareTo(BigDecimal.ZERO) > 0) {
  3062. BigDecimal subtract = commissionFeevalue.subtract(bigDecimal1);
  3063. bxResultListItem.put("noInvoicCommissionFeevalue", subtract);
  3064. } else {
  3065. bxResultListItem.put("noInvoicCommissionFeevalue", bxResultListItem.get("commissionFeevalue"));
  3066. }
  3067. }
  3068. return HttpResult.ok(bxResultList);
  3069. }
  3070. return HttpResult.ok();
  3071. }
  3072. /**
  3073. * @version
  3074. * @author: hxl
  3075. * @Date: 2024/8/1 9:28
  3076. * @Description: 查询平台、私有数据
  3077. */
  3078. @Override
  3079. public FinancialReceivablesAllVo queryDateByType(FinancialReceivablesQueryVo financialReceivablesQueryVo) {
  3080. //检查参数
  3081. if(StringUtils.isBlank(financialReceivablesQueryVo.getType())){
  3082. throw new SystemException("应收类型不能为空,1为平台2为私有,默认传1");
  3083. }
  3084. int year =0;
  3085. if(StringUtils.isBlank(financialReceivablesQueryVo.getYear())){
  3086. Calendar cale = Calendar.getInstance();
  3087. year = cale.get(Calendar.YEAR);
  3088. }else{
  3089. year = Integer.parseInt(financialReceivablesQueryVo.getYear());
  3090. }
  3091. List<FinancialReceivablesVo> list = new ArrayList<>();
  3092. if("2".equals(financialReceivablesQueryVo.getType())){
  3093. list.addAll(baseMapper.queryDateByType(financialReceivablesQueryVo)) ;
  3094. }else {
  3095. list.addAll(baseMapper.queryDateByTypePt(financialReceivablesQueryVo)) ;
  3096. }
  3097. financialReceivablesQueryVo.setBeginDate(SliceUpDateUtil.getYearBeginDateStr(year)+" 00:00:00");
  3098. financialReceivablesQueryVo.setEndDate(SliceUpDateUtil.getYearEndDateStr(year)+" 23:59:59");
  3099. //总应收
  3100. financialReceivablesQueryVo.setType("1");
  3101. BigDecimal ptSumAmount = baseMapper.queryDateByTypeSumAmount(financialReceivablesQueryVo);
  3102. financialReceivablesQueryVo.setType("2");
  3103. //总应收
  3104. BigDecimal sySumAmount = baseMapper.queryDateByTypeSumAmount(financialReceivablesQueryVo);
  3105. return new FinancialReceivablesAllVo(ptSumAmount !=null? ptSumAmount.toString(): "0",sySumAmount !=null ? sySumAmount.toString() : "0",year+"",list);
  3106. }
  3107. /**
  3108. * @version
  3109. * @author: whp
  3110. * @Date: 2024/8/7
  3111. * @Description: 私有 车险
  3112. */
  3113. @Override
  3114. public FinancialReceivablesAllVo queryPrivateCar(FinancialReceivablesQueryVo financialReceivablesQueryVo) {
  3115. int year =0;
  3116. if(StringUtils.isBlank(financialReceivablesQueryVo.getYear())){
  3117. Calendar cale = Calendar.getInstance();
  3118. year = cale.get(Calendar.YEAR);
  3119. }else{
  3120. year = Integer.parseInt(financialReceivablesQueryVo.getYear());
  3121. }
  3122. FinancialReceivablesAllVo resultVo = new FinancialReceivablesAllVo();
  3123. // 私有总金额
  3124. financialReceivablesQueryVo.setBeginDate(SliceUpDateUtil.getYearBeginDateStr(year)+" 00:00:00");
  3125. financialReceivablesQueryVo.setEndDate(SliceUpDateUtil.getYearEndDateStr(year)+" 23:59:59");
  3126. // 私有应收
  3127. BigDecimal syAmount = baseMapper.queryDateByTypeSumAmount(financialReceivablesQueryVo);
  3128. if(syAmount!=null){
  3129. resultVo.setSySumAmount(syAmount.toString());
  3130. }
  3131. resultVo.setYear(year+"");
  3132. List<FinancialReceivablesVo> result= baseMapper.queryPrivateCar(financialReceivablesQueryVo);
  3133. resultVo.setList(result);
  3134. return resultVo;
  3135. }
  3136. /**
  3137. * @version
  3138. * @author: hxl
  3139. * @Date: 2024/8/5 9:56
  3140. * @Description: 应收月份统计接口
  3141. */
  3142. @Override
  3143. public FinancialReceivablesAllMonthVo queryDateByTypeByMonth(FinancialReceivablesQueryMonthVo financialReceivablesQueryVo) {
  3144. //检查参数
  3145. if (StringUtils.isBlank(financialReceivablesQueryVo.getType())) {
  3146. throw new SystemException("应收类型不能为空,1为平台2为私有,默认传1");
  3147. }
  3148. //检查参数
  3149. if (StringUtils.isBlank(financialReceivablesQueryVo.getYearAndMonth())) {
  3150. throw new SystemException("月份不能为空");
  3151. }
  3152. String yearAndMonth = financialReceivablesQueryVo.getYearAndMonth();
  3153. int year = Integer.parseInt(yearAndMonth.split("-")[0]);
  3154. int month = Integer.parseInt(yearAndMonth.split("-")[1]);
  3155. financialReceivablesQueryVo.setBeginDate(SliceUpDateUtil.getStartOfMonth(year, month));
  3156. financialReceivablesQueryVo.setEndDate(SliceUpDateUtil.getEndOfMonth(year, month));
  3157. //查询总数
  3158. FinancialReceivablesAllMonthVo vo = baseMapper.queryDateByTypeByMonth(financialReceivablesQueryVo);
  3159. if(vo!= null){
  3160. // 第二层数据
  3161. List<FinancialReceivablesMonthSignleVo> resultData = vo.getList();
  3162. vo.setYearAndMonth(yearAndMonth);
  3163. HashMap<String, BigDecimal> amountMap;
  3164. if ("2".equals(financialReceivablesQueryVo.getType())) {
  3165. amountMap = this.privateSett(resultData, financialReceivablesQueryVo);
  3166. } else {
  3167. amountMap = this.platformSett(resultData, financialReceivablesQueryVo);
  3168. }
  3169. vo.setYisSumAmount(amountMap.get("yishouAmount").toString());
  3170. vo.setYsSumAmount(amountMap.get("yinshouAmount").toString());
  3171. vo.setWsSumAmount(amountMap.get("weishouAmount").toString());
  3172. }
  3173. return vo;
  3174. }
  3175. private HashMap<String, BigDecimal> platformSett(List<FinancialReceivablesMonthSignleVo> resultData, FinancialReceivablesQueryMonthVo financialReceivablesQueryVo) {
  3176. List<BigDecimal> yinShouAmountList = new ArrayList<>();
  3177. List<BigDecimal> yishouAmountList = new ArrayList<>();
  3178. List<BigDecimal> weishouAmountList = new ArrayList<>();
  3179. BigDecimal yinshouAmount = new BigDecimal("0.00");
  3180. BigDecimal yishouAmount = new BigDecimal("0.00");
  3181. BigDecimal weishouAmount = new BigDecimal("0.00");
  3182. HashMap<String, BigDecimal> resultMap = new HashMap<>();
  3183. //平台手续费
  3184. List<FinancialReceivablesMonthVo> handList = baseMapper.queryPlatHanding(financialReceivablesQueryVo);
  3185. List<FinancialReceivablesMonthVo> patherIdList = baseMapper.getPatherId(financialReceivablesQueryVo);
  3186. Map<String, List<FinancialReceivablesMonthVo>> groupedByPartnerCompaniesId = handList.stream()
  3187. .collect(Collectors.groupingBy(FinancialReceivablesMonthVo::getPartnerCompaniesId));
  3188. patherIdList.stream().filter(item -> groupedByPartnerCompaniesId.containsKey(item.getPartnerCompaniesId()))
  3189. .forEach(item ->{
  3190. List<FinancialReceivablesMonthVo> financialReceivablesMonthVosList = groupedByPartnerCompaniesId.get(item.getPartnerCompaniesId());
  3191. FinancialReceivablesMonthSignleVo financialReceivablesMonthSignleVo = new FinancialReceivablesMonthSignleVo();
  3192. List<FinancialReceivablesMonthVo> financialReceivablesMonthVos = financialReceivablesMonthSignleVo.getList();
  3193. financialReceivablesMonthSignleVo.setCompanyName(item.getCompanyName());
  3194. financialReceivablesMonthSignleVo.setAreaName(item.getAreaName());
  3195. financialReceivablesMonthVos.addAll(financialReceivablesMonthVosList);
  3196. resultData.add(financialReceivablesMonthSignleVo);
  3197. financialReceivablesMonthVosList.forEach(financialReceivablesMonthVo ->{
  3198. if("合计".equals(financialReceivablesMonthVo.getIsHand())){
  3199. yinShouAmountList.add(this.stringToBigdecimal(financialReceivablesMonthVo.getCommissionFeevalue()));
  3200. yishouAmountList.add(this.stringToBigdecimal(financialReceivablesMonthVo.getReadyCommissionFeevalue()));
  3201. weishouAmountList.add(this.stringToBigdecimal(financialReceivablesMonthVo.getNoInvoicCommissionFeevalue()));
  3202. }
  3203. });
  3204. });
  3205. yinshouAmount = yinshouAmount.add(yinShouAmountList.stream().reduce(BigDecimal.ZERO, BigDecimal::add));
  3206. yishouAmount = yishouAmount.add(yishouAmountList.stream().reduce(BigDecimal.ZERO, BigDecimal::add));
  3207. weishouAmount = weishouAmount.add(weishouAmountList.stream().reduce(BigDecimal.ZERO, BigDecimal::add));
  3208. resultMap.put("yinshouAmount",yinshouAmount);
  3209. resultMap.put("yishouAmount",yishouAmount);
  3210. resultMap.put("weishouAmount",weishouAmount);
  3211. return resultMap;
  3212. }
  3213. private HashMap<String, BigDecimal> privateSett(List<FinancialReceivablesMonthSignleVo> resultData, FinancialReceivablesQueryMonthVo financialReceivablesQueryVo) {
  3214. List<BigDecimal> yinShouAmountList = new ArrayList<>();
  3215. List<BigDecimal> yishouAmountList = new ArrayList<>();
  3216. List<BigDecimal> weishouAmountList = new ArrayList<>();
  3217. BigDecimal yinshouAmount = new BigDecimal("0.00");
  3218. BigDecimal yishouAmount = new BigDecimal("0.00");
  3219. BigDecimal weishouAmount = new BigDecimal("0.00");
  3220. HashMap<String, BigDecimal> resultMap = new HashMap<>();
  3221. //手续费未接应收
  3222. List<FinancialReceivablesMonthVo> list = baseMapper.queryDateByTypeByMonthList(financialReceivablesQueryVo);
  3223. //跟单统计
  3224. List<FinancialReceivablesMonthVo> otherList = baseMapper.queryDateByTypeByMonthOtherList(financialReceivablesQueryVo);
  3225. Map<String, FinancialReceivablesMonthVo> otherCollect = otherList.stream().collect(Collectors.toMap(FinancialReceivablesMonthVo::getPartnerCompaniesId, Function.identity()));
  3226. // Map<String, FinancialReceivablesMonthVo> commCollect= list.stream().collect(Collectors.toMap(FinancialReceivablesMonthVo::getPartnerCompaniesId, Function.identity()));
  3227. list.forEach(item -> {
  3228. if(otherCollect.containsKey(item.getPartnerCompaniesId())){
  3229. FinancialReceivablesMonthVo otherItem = otherCollect.get(item.getPartnerCompaniesId());
  3230. FinancialReceivablesMonthSignleVo financialReceivablesMonthSignleVo = new FinancialReceivablesMonthSignleVo();
  3231. List<FinancialReceivablesMonthVo> financialReceivablesMonthVos = financialReceivablesMonthSignleVo.getList();
  3232. financialReceivablesMonthSignleVo.setCompanyName(item.getCompanyName());
  3233. financialReceivablesMonthSignleVo.setAreaName(item.getAreaName());
  3234. // 合计信息
  3235. FinancialReceivablesMonthVo financialReceivablesMonthVo = new FinancialReceivablesMonthVo();
  3236. financialReceivablesMonthVo.setCommissionFeevalue(this.calculateTotal(this.stringToBigdecimal(item.getCommissionFeevalue()), new BigDecimal(otherItem.getCommissionFeevalue()), null).toString());
  3237. financialReceivablesMonthVo.setNoInvoicCommissionFeevalue(this.calculateTotal(this.stringToBigdecimal(item.getNoInvoicCommissionFeevalue()), new BigDecimal(otherItem.getNoInvoicCommissionFeevalue()), null).toString());
  3238. financialReceivablesMonthVo.setReadyCommissionFeevalue(this.calculateTotal(this.stringToBigdecimal(item.getReadyCommissionFeevalue()), new BigDecimal(otherItem.getReadyCommissionFeevalue()), null).toString());
  3239. financialReceivablesMonthVo.setSettlementAmount(this.calculateTotal(this.stringToBigdecimal(item.getSettlementAmount()), new BigDecimal(otherItem.getSettlementAmount()), null).toString());
  3240. financialReceivablesMonthVo.setNoSettlementAmount(this.calculateTotal(this.stringToBigdecimal(item.getNoSettlementAmount()), new BigDecimal(otherItem.getNoSettlementAmount()), null).toString());
  3241. financialReceivablesMonthVo.setIsHand("合计");
  3242. financialReceivablesMonthVos.add(otherItem);
  3243. financialReceivablesMonthVos.add(item);
  3244. financialReceivablesMonthVos.add(financialReceivablesMonthVo);
  3245. yishouAmountList.add(this.stringToBigdecimal(financialReceivablesMonthVo.getReadyCommissionFeevalue()));
  3246. yinShouAmountList.add(this.stringToBigdecimal(financialReceivablesMonthVo.getCommissionFeevalue()));
  3247. weishouAmountList.add(this.stringToBigdecimal(financialReceivablesMonthVo.getNoInvoicCommissionFeevalue()));
  3248. resultData.add(financialReceivablesMonthSignleVo);
  3249. }else {
  3250. FinancialReceivablesMonthVo otherItem = new FinancialReceivablesMonthVo() ;
  3251. otherItem.setIsHand("跟单费");
  3252. otherItem.setCommissionFeevalue(BigDecimal.ZERO.toString());
  3253. otherItem.setNoInvoicCommissionFeevalue(BigDecimal.ZERO.toString());
  3254. otherItem.setReadyCommissionFeevalue(BigDecimal.ZERO.toString());
  3255. otherItem.setSettlementAmount(BigDecimal.ZERO.toString());
  3256. otherItem.setNoSettlementAmount(BigDecimal.ZERO.toString());
  3257. FinancialReceivablesMonthSignleVo financialReceivablesMonthSignleVo = new FinancialReceivablesMonthSignleVo();
  3258. List<FinancialReceivablesMonthVo> financialReceivablesMonthVos = financialReceivablesMonthSignleVo.getList();
  3259. financialReceivablesMonthSignleVo.setCompanyName(item.getCompanyName());
  3260. financialReceivablesMonthSignleVo.setAreaName(item.getAreaName());
  3261. // 合计信息
  3262. FinancialReceivablesMonthVo financialReceivablesMonthVo = new FinancialReceivablesMonthVo();
  3263. financialReceivablesMonthVo.setCommissionFeevalue(this.calculateTotal(this.stringToBigdecimal(item.getCommissionFeevalue()), BigDecimal.ZERO, null).toString());
  3264. financialReceivablesMonthVo.setNoInvoicCommissionFeevalue(this.calculateTotal(this.stringToBigdecimal(item.getNoInvoicCommissionFeevalue()), BigDecimal.ZERO, null).toString());
  3265. financialReceivablesMonthVo.setReadyCommissionFeevalue(this.calculateTotal(this.stringToBigdecimal(item.getReadyCommissionFeevalue()), BigDecimal.ZERO, null).toString());
  3266. financialReceivablesMonthVo.setSettlementAmount(this.calculateTotal(this.stringToBigdecimal(item.getSettlementAmount()), BigDecimal.ZERO, null).toString());
  3267. financialReceivablesMonthVo.setNoSettlementAmount(this.calculateTotal(this.stringToBigdecimal(item.getNoSettlementAmount()), BigDecimal.ZERO, null).toString());
  3268. financialReceivablesMonthVo.setIsHand("合计");
  3269. financialReceivablesMonthVos.add(otherItem);
  3270. financialReceivablesMonthVos.add(item);
  3271. financialReceivablesMonthVos.add(financialReceivablesMonthVo);
  3272. yishouAmountList.add(this.stringToBigdecimal(financialReceivablesMonthVo.getReadyCommissionFeevalue()));
  3273. yinShouAmountList.add(this.stringToBigdecimal(financialReceivablesMonthVo.getCommissionFeevalue()));
  3274. weishouAmountList.add(this.stringToBigdecimal(financialReceivablesMonthVo.getNoInvoicCommissionFeevalue()));
  3275. resultData.add(financialReceivablesMonthSignleVo);
  3276. }
  3277. }
  3278. );
  3279. yinshouAmount = yinshouAmount.add(yinShouAmountList.stream().reduce(BigDecimal.ZERO, BigDecimal::add));
  3280. yishouAmount = yishouAmount.add(yishouAmountList.stream().reduce(BigDecimal.ZERO, BigDecimal::add));
  3281. weishouAmount = weishouAmount.add(weishouAmountList.stream().reduce(BigDecimal.ZERO, BigDecimal::add));
  3282. resultMap.put("yinshouAmount",yinshouAmount);
  3283. resultMap.put("yishouAmount",yishouAmount);
  3284. resultMap.put("weishouAmount",weishouAmount);
  3285. return resultMap;
  3286. }
  3287. private BigDecimal stringToBigdecimal(String value) {
  3288. return new BigDecimal(value).setScale(5, RoundingMode.DOWN);
  3289. }
  3290. /**
  3291. * @version
  3292. * @author: hxl
  3293. * @Date: 2024/8/7 11:20
  3294. * @Description: 修正协议变动重新生成数据逻辑
  3295. */
  3296. @Override
  3297. public HttpResult<List<InsPlyIncome>> createData(InsPlyIncomeIdsVo insPlyIncomeIdsVo) {
  3298. if(insPlyIncomeIdsVo.getIds()==null || insPlyIncomeIdsVo.getIds().size()==0){
  3299. throw new SystemException("子订单id不能为空!!");
  3300. }
  3301. List<String> ids = insPlyIncomeIdsVo.getIds();
  3302. List<InsPlyIncome> newList=new ArrayList<>();
  3303. for(String subOrderId:ids){
  3304. //查询子订单对象 com.ydtech.modules.order.entity
  3305. InsAreaCompany insAreaCompany = fncInsAreaCompanyMapper.selectById(subOrderId);
  3306. //大订单对象
  3307. InsOrders order = insOrdersService.existOrder(insAreaCompany.getOrderno());
  3308. SysUser sysUser = sysUserService.getById(order.getUserid());
  3309. //获取该订单的费用
  3310. InsFeeOrderNew insFeeOrderNew = insFeeOrderNewService.getOne(new LambdaQueryWrapper<InsFeeOrderNew>()
  3311. .eq(InsFeeOrderNew::getInsOrderNo, insAreaCompany.getId()));
  3312. saveBalanceNew(order, insFeeOrderNew,insAreaCompany, sysUser.getLeaderId(), sysUser.getLeaderName()) ;
  3313. }
  3314. return HttpResult.ok(newList);
  3315. }
  3316. @Override
  3317. public List<InsuranceHandlingSettlementMonthDto> getInvociAmount(InsuranceHandlingSettlementMonthVo insuranceHandlingSettlementMonthVo) {
  3318. return baseMapper.getInvociAmount(insuranceHandlingSettlementMonthVo);
  3319. }
  3320. /**
  3321. * @version
  3322. * @author: hxl
  3323. * @Date: 2024/9/20 9:58
  3324. * @Description: 平台结算情况统计
  3325. */
  3326. @Override
  3327. public List<InsPlyIncomePTDto> totalPTAmount(InsPlyIncomePTVo insPlyIncomeVo) {
  3328. return baseMapper.totalPTAmount(insPlyIncomeVo);
  3329. }
  3330. /**
  3331. * @version
  3332. * @author: hxl
  3333. * @Date: 2024/9/20 11:01
  3334. * @Description: 通过结算人查询保险公司结算数据
  3335. */
  3336. @Override
  3337. public List<InsPlyIncomePTCompanyDto> findListByDockingPerson(InsPlyIncomeQueryPTVo insPlyIncomeVo) {
  3338. return baseMapper.findListByDockingPerson(insPlyIncomeVo);
  3339. }
  3340. /**
  3341. * @version
  3342. * @author: hxl
  3343. * @Date: 2024/9/21 14:14
  3344. * @Description: 批量导入
  3345. */
  3346. @Override
  3347. public void importDataAddType(MultipartFile file, String type) throws Exception {
  3348. List<InsPlyIncome> list =new ArrayList<InsPlyIncome>();
  3349. //导入验证
  3350. if("1".equals(type)){
  3351. //车险手续费
  3352. List<AddTypeCXSXFExcel> dtoList = ExcelEasypoiUtils.importExcel(file, AddTypeCXSXFExcel.class, 0, 1, 1);
  3353. try{
  3354. list=checkData(type,dtoList,null,null,null,null);
  3355. }catch(SystemException e){
  3356. throw new SystemException(e.getMessage());
  3357. }
  3358. }else if("2".equals(type)){
  3359. //车险跟单
  3360. List<AddTypeCXGDExcel> dtoList = ExcelEasypoiUtils.importExcel(file, AddTypeCXGDExcel.class, 0, 1, 1);
  3361. try{
  3362. list=checkData(type,null,dtoList,null,null,null);
  3363. }catch(SystemException e){
  3364. throw new SystemException(e.getMessage());
  3365. }
  3366. }else if("3".equals(type)){
  3367. //非车手续费
  3368. List<AddTypeFCSXFExcel> dtoList = ExcelEasypoiUtils.importExcel(file, AddTypeFCSXFExcel.class, 0, 1, 1);
  3369. try{
  3370. list=checkData(type,null,null,dtoList,null,null);
  3371. }catch(SystemException e){
  3372. throw new SystemException(e.getMessage());
  3373. }
  3374. }else if("4".equals(type)){
  3375. //非车跟单
  3376. List<AddTypeFCGDExcel> dtoList = ExcelEasypoiUtils.importExcel(file, AddTypeFCGDExcel.class, 0, 1, 1);
  3377. try{
  3378. list=checkData(type,null,null,null,dtoList,null);
  3379. }catch(SystemException e){
  3380. throw new SystemException(e.getMessage());
  3381. }
  3382. }
  3383. else if("5".equals(type)){
  3384. //平台结算
  3385. List<AddTypePTJSExcel> dtoList = ExcelEasypoiUtils.importExcel(file, AddTypePTJSExcel.class, 0, 1, 1);
  3386. try{
  3387. list=checkData(type,null,null,null,null,dtoList);
  3388. }catch(SystemException e){
  3389. throw new SystemException(e.getMessage());
  3390. }
  3391. }
  3392. //批量插入
  3393. if(list!=null && list.size()>0){
  3394. this.saveBatch(list);
  3395. }
  3396. }
  3397. /** 批量修改 手续费金额
  3398. *
  3399. * @param multipartFile
  3400. * @param isNotCar 是否是非车
  3401. * @return
  3402. */
  3403. @Override
  3404. public HashMap<String, Object> insuranceHandlingFeeBathUpdate(MultipartFile multipartFile, String isNotCar) {
  3405. HashMap<String, Object> resultMap = new HashMap<>();
  3406. List<HashMap<String, Object>> resultList = new ArrayList<>();
  3407. HashMap<String, Object> params = new HashMap<>();
  3408. BigDecimal allAmount = BigDecimal.ZERO;
  3409. params.put("isNotCar", isNotCar);
  3410. try {
  3411. List<InsBxPlyIncomeExcelDto> dtoList = ExcelEasypoiUtils.importExcel(multipartFile, InsBxPlyIncomeExcelDto.class, 0, 1, 1);
  3412. for (InsBxPlyIncomeExcelDto item : dtoList) {
  3413. if (StringUtils.isNotEmpty(item.getLicenseno())) {
  3414. params.put("licenseno", item.getLicenseno());
  3415. }
  3416. if (StringUtils.isNotEmpty(item.getPolicyno())) {
  3417. params.put("policyno", item.getPolicyno());
  3418. }
  3419. if (StringUtils.isNotEmpty(item.getSyPolicyno())) {
  3420. params.put("syPolicyno", item.getSyPolicyno());
  3421. }
  3422. params.put("handlingFeesStatus", "0");
  3423. params.put("isOther", "0");
  3424. params.put("isNotCar", "0");
  3425. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  3426. if (item.getJqSuperviseCostsProportion() == null) {
  3427. item.setJqSuperviseCostsProportion(BigDecimal.ZERO);
  3428. }
  3429. if (item.getSySuperviseCostsProportion() == null) {
  3430. item.setSySuperviseCostsProportion(BigDecimal.ZERO);
  3431. }
  3432. if (ObjectUtils.isNotEmpty(byBxLicenseno) && (byBxLicenseno.getJqOtherCostsProportion().compareTo(item.getJqSuperviseCostsProportion()) != 0 || byBxLicenseno.getSySuperviseCostsProportion().compareTo(item.getSySuperviseCostsProportion()) != 0)) {
  3433. // 如果比例不相等
  3434. BigDecimal jqSuperviseCostsProportion = item.getJqSuperviseCostsProportion();
  3435. BigDecimal sySuperviseCostsProportion = item.getSySuperviseCostsProportion();
  3436. BigDecimal jqSupervisePremium = getBigDecimal( byBxLicenseno.getJqPremium(),jqSuperviseCostsProportion);
  3437. BigDecimal sySupervisePremium = getBigDecimal( byBxLicenseno.getSyPremium(),sySuperviseCostsProportion);
  3438. HashMap<String, Object> map = new HashMap<>();
  3439. map.put("licenseno", item.getLicenseno());
  3440. map.put("policyno", item.getPolicyno());
  3441. map.put("syPolicyno", item.getSyPolicyno());
  3442. map.put("jqSuperviseCostsPremiums", jqSupervisePremium);
  3443. map.put("sySuperviseCostsPremiums", sySupervisePremium);
  3444. map.put("jqSuperviseCostsProportion", jqSuperviseCostsProportion);
  3445. map.put("sySuperviseCostsProportion", sySuperviseCostsProportion);
  3446. map.put("id", byBxLicenseno.getId());
  3447. resultList.add(map);
  3448. allAmount = allAmount.add(jqSupervisePremium).add(sySupervisePremium);
  3449. }
  3450. }
  3451. resultMap.put("allAmount", allAmount);
  3452. resultMap.put("resultList", resultList);
  3453. } catch (IOException e) {
  3454. throw new RuntimeException(e);
  3455. }
  3456. return resultMap;
  3457. }
  3458. /**
  3459. * 保险手续费批量修改
  3460. * @param insPlyIncomeVo
  3461. */
  3462. @Override
  3463. @Transactional
  3464. public void insuranceHandlingFeeBathConfirm(InsPlyIncomeVo insPlyIncomeVo) {
  3465. if (ObjectUtils.isEmpty(insPlyIncomeVo)) {
  3466. throw new SystemException("请导入文件");
  3467. }
  3468. if(CollectionUtils.isEmpty(insPlyIncomeVo.getResultList())){
  3469. throw new SystemException("请导入文件");
  3470. }
  3471. ArrayList<InsPlyIncome> batchUpdateItem = new ArrayList<>();
  3472. for (InsPlyIncome item : insPlyIncomeVo.getResultList()) {
  3473. InsPlyIncomeLog insPlyIncomeLog = new InsPlyIncomeLog();
  3474. insPlyIncomeLog.setIncomeId(item.getId());
  3475. BeanUtils.copyProperties(item, insPlyIncomeLog);
  3476. insPlyIncomeLog.setOperationStatus("2");
  3477. insPlyIncomeLog.setId(null);
  3478. insPlyIncomeLogService.saveLog(insPlyIncomeLog); //添加日志
  3479. item.setAllFeeValue(this.calculateTotal(item.getJqSuperviseCostsPremiums(), item.getSySuperviseCostsPremiums(), null));
  3480. item.setCommissionFeevalue(this.calculateTotal(item.getJqSuperviseCostsPremiums(), item.getSySuperviseCostsPremiums(), null));
  3481. item.setCommissionFeerate(this.calculateTotal(item.getJqSuperviseCostsProportion(), item.getSySuperviseCostsProportion(), null));
  3482. batchUpdateItem.add(item);
  3483. // baseMapper.updateById(item);
  3484. }
  3485. this.saveOrUpdateBatch(batchUpdateItem);
  3486. }
  3487. @Override
  3488. public HashMap<String, Object> insuranceHandlingFeeBathNotCarImport(MultipartFile multipartFile, String isNotCar) {
  3489. HashMap<String, Object> resultMap = new HashMap<>();
  3490. List<HashMap<String, Object>> resultList = new ArrayList<>();
  3491. HashMap<String, Object> params = new HashMap<>();
  3492. BigDecimal allAmount = BigDecimal.ZERO;
  3493. params.put("isNotCar", isNotCar);
  3494. try {
  3495. List<InsBxNoPlyIncomeExcelDto> dtoList = ExcelEasypoiUtils.importExcel(multipartFile, InsBxNoPlyIncomeExcelDto.class, 0, 1, 1);
  3496. for (InsBxNoPlyIncomeExcelDto item : dtoList) {
  3497. if (StringUtils.isNotEmpty(item.getLicenseno())) {
  3498. params.put("licenseno", item.getLicenseno());
  3499. }
  3500. if (StringUtils.isNotEmpty(item.getNoPolicyno())) {
  3501. params.put("noPolicyno", item.getNoPolicyno());
  3502. }
  3503. params.put("handlingFeesStatus", "0");
  3504. params.put("isOther", "0");
  3505. params.put("isNotCar", "1");
  3506. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  3507. if (item.getNoSuperviseCostsProportion() == null) {
  3508. item.setNoSuperviseCostsProportion(BigDecimal.ZERO);
  3509. }
  3510. if (ObjectUtils.isNotEmpty(byBxLicenseno) && (byBxLicenseno.getNoSuperviseCostsProportion().compareTo(item.getNoSuperviseCostsProportion()) != 0 )) {
  3511. // 如果比例不相等
  3512. BigDecimal noSuperviseCostsProportion = item.getNoSuperviseCostsProportion();
  3513. BigDecimal noSuperviseCostsPremiums = getBigDecimal(byBxLicenseno.getNoPremium(),noSuperviseCostsProportion);
  3514. HashMap<String, Object> map = new HashMap<>();
  3515. map.put("licenseno", item.getLicenseno());
  3516. map.put("noPolicyno", item.getNoPolicyno());
  3517. map.put("noSuperviseCostsPremiums", noSuperviseCostsPremiums);
  3518. map.put("noSuperviseCostsProportion", noSuperviseCostsProportion);
  3519. map.put("id", byBxLicenseno.getId());
  3520. resultList.add(map);
  3521. allAmount = allAmount.add(noSuperviseCostsPremiums);
  3522. }
  3523. }
  3524. resultMap.put("allAmount", allAmount);
  3525. resultMap.put("resultList", resultList);
  3526. } catch (IOException e) {
  3527. throw new RuntimeException(e);
  3528. }
  3529. return resultMap;
  3530. }
  3531. /**
  3532. * 保险手续费批量修改
  3533. * @param insPlyIncomeVo
  3534. */
  3535. @Override
  3536. @Transactional
  3537. public void insuranceHandlingNotCarFeeBathConfirm(InsPlyIncomeVo insPlyIncomeVo) {
  3538. if (ObjectUtils.isEmpty(insPlyIncomeVo)) {
  3539. throw new SystemException("请导入文件");
  3540. }
  3541. if(CollectionUtils.isEmpty(insPlyIncomeVo.getResultList())){
  3542. throw new SystemException("请导入文件");
  3543. }
  3544. ArrayList<InsPlyIncome> batchUpdateItem = new ArrayList<>();
  3545. for (InsPlyIncome item : insPlyIncomeVo.getResultList()) {
  3546. InsPlyIncomeLog insPlyIncomeLog = new InsPlyIncomeLog();
  3547. insPlyIncomeLog.setIncomeId(item.getId());
  3548. BeanUtils.copyProperties(item, insPlyIncomeLog);
  3549. insPlyIncomeLog.setOperationStatus("2");
  3550. insPlyIncomeLog.setId(null);
  3551. insPlyIncomeLogService.saveLog(insPlyIncomeLog); //添加日志
  3552. item.setAllFeeValue(this.calculateTotal(item.getNoSuperviseCostsPremiums(), null, null));
  3553. item.setCommissionFeevalue(this.calculateTotal(item.getNoSuperviseCostsPremiums(), null, null));
  3554. item.setCommissionFeerate(this.calculateTotal(item.getNoSuperviseCostsProportion(), null, null));
  3555. batchUpdateItem.add(item);
  3556. // baseMapper.updateById(item);
  3557. }
  3558. this.saveOrUpdateBatch(batchUpdateItem);
  3559. }
  3560. public List<InsPlyIncome> checkData(String type,List<AddTypeCXSXFExcel> cxsxfList,List<AddTypeCXGDExcel> cxgdList, List<AddTypeFCSXFExcel> fcsxfList, List<AddTypeFCGDExcel> fcgdList,List<AddTypePTJSExcel> ptjsList) throws SystemException{
  3561. List<InsPlyIncome> list =new ArrayList<InsPlyIncome>();
  3562. if("1".equals(type)){
  3563. int index=1;
  3564. //车险手续费
  3565. if(cxsxfList!=null && cxsxfList.size()>0){
  3566. for(AddTypeCXSXFExcel dto : cxsxfList){
  3567. if(!ImportObjectUtils.allNull(dto)){
  3568. index++;
  3569. Map<String, Object> map = CheckInsPlyComeUtils.checkDataDto1(dto);
  3570. if(!"".equals(map.get("msg"))){
  3571. throw new SystemException("第" + index + "行数据" + map.get("msg").toString());
  3572. }else{
  3573. InsPlyIncome insPlyIncome = (InsPlyIncome)map.get("dto");
  3574. list.add(insPlyIncome);
  3575. }
  3576. }
  3577. }
  3578. }
  3579. }else if("2".equals(type)){
  3580. int index=1;
  3581. //车险跟单
  3582. if(cxgdList!=null && cxgdList.size()>0){
  3583. for(AddTypeCXGDExcel dto : cxgdList){
  3584. if(!ImportObjectUtils.allNull(dto)) {
  3585. index++;
  3586. Map<String, Object> map = CheckInsPlyComeUtils.checkDataDto2(dto);
  3587. if (!"".equals(map.get("msg"))) {
  3588. throw new SystemException("第" + index + "行数据" + map.get("msg").toString());
  3589. } else {
  3590. InsPlyIncome insPlyIncome = (InsPlyIncome) map.get("dto");
  3591. list.add(insPlyIncome);
  3592. }
  3593. }
  3594. }
  3595. }
  3596. }else if("3".equals(type)){
  3597. int index=1;
  3598. if(fcsxfList!=null && fcsxfList.size()>0){
  3599. for(AddTypeFCSXFExcel dto : fcsxfList){
  3600. if(!ImportObjectUtils.allNull(dto)) {
  3601. index++;
  3602. Map<String, Object> map = CheckInsPlyComeUtils.checkDataDto3(dto);
  3603. if (!"".equals(map.get("msg"))) {
  3604. throw new SystemException("第" + index + "行数据" + map.get("msg").toString());
  3605. } else {
  3606. InsPlyIncome insPlyIncome = (InsPlyIncome) map.get("dto");
  3607. list.add(insPlyIncome);
  3608. }
  3609. }
  3610. }
  3611. }
  3612. }else if("4".equals(type)){
  3613. int index=1;
  3614. if(fcgdList!=null && fcgdList.size()>0){
  3615. for(AddTypeFCGDExcel dto : fcgdList){
  3616. if(!ImportObjectUtils.allNull(dto)) {
  3617. index++;
  3618. Map<String, Object> map = CheckInsPlyComeUtils.checkDataDto4(dto);
  3619. if (!"".equals(map.get("msg"))) {
  3620. throw new SystemException("第" + index + "行数据" + map.get("msg").toString());
  3621. } else {
  3622. InsPlyIncome insPlyIncome = (InsPlyIncome) map.get("dto");
  3623. list.add(insPlyIncome);
  3624. }
  3625. }
  3626. }
  3627. }
  3628. }
  3629. else if("5".equals(type)){
  3630. int index=1;
  3631. if(ptjsList!=null && ptjsList.size()>0){
  3632. for(AddTypePTJSExcel dto : ptjsList) {
  3633. if (!ImportObjectUtils.allNull(dto)) {
  3634. index++;
  3635. Map<String, Object> map = CheckInsPlyComeUtils.checkDataDto5(dto);
  3636. if (!"".equals(map.get("msg"))) {
  3637. throw new SystemException("第" + index + "行数据" + map.get("msg").toString());
  3638. } else {
  3639. InsPlyIncome insPlyIncome = (InsPlyIncome) map.get("dto");
  3640. list.add(insPlyIncome);
  3641. }
  3642. }
  3643. }
  3644. }
  3645. }
  3646. return list;
  3647. }
  3648. }