InsPlyIncomeServiceImpl.java 207 KB

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