InsPlyIncomeServiceImpl.java 155 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751
  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.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  7. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  8. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  9. import com.github.pagehelper.PageHelper;
  10. import com.github.pagehelper.PageInfo;
  11. import com.ydtech.constants.InsuranceEnum;
  12. import com.ydtech.constants.enums.dict.agreement.ProductsType;
  13. import com.ydtech.core.page.HttpResult;
  14. import com.ydtech.exception.SystemException;
  15. import com.ydtech.modules.base.controller.BaseController;
  16. import com.ydtech.modules.esm.model.EsmInsCompany;
  17. import com.ydtech.modules.esm.service.EsmInsCompanyService;
  18. import com.ydtech.modules.fnc.dao.InsPlyIncomeMapper;
  19. import com.ydtech.modules.fnc.dto.PlatformSettlementRecordDto;
  20. import com.ydtech.modules.fnc.entity.*;
  21. import com.ydtech.modules.fnc.service.*;
  22. import com.ydtech.modules.fnc.vo.InsPlyIncomeVo;
  23. import com.ydtech.modules.fnc.vo.SettlementDocumentaryFeesVo;
  24. import com.ydtech.modules.ins.model.vo.res.*;
  25. import com.ydtech.modules.inv.model.dto.*;
  26. import com.ydtech.modules.inv.utils.EasyExcelUtils;
  27. import com.ydtech.modules.order.entity.BasePageResult;
  28. import com.ydtech.modules.order.entity.InsOrders;
  29. import com.ydtech.modules.order.entity.api.dajia.response.NVHLODR1001Response;
  30. import com.ydtech.modules.order.entity.api.zhongmei.response.SubmitResponse;
  31. import com.ydtech.modules.order.entity.crawler.response.CrawlerVerifyPaymentResponse;
  32. import com.ydtech.modules.order.entity.dto.DrivingInsuranceDto;
  33. import com.ydtech.modules.order.service.InsAreaCompanyService;
  34. import com.ydtech.modules.order.service.InsOrdersService;
  35. import com.ydtech.modules.protocol.entity.constants.PtlApiType;
  36. import com.ydtech.modules.protocol.entity.po.PtlAgreement;
  37. import com.ydtech.modules.protocol.entity.vo.PtlAgreementQueryVo;
  38. import com.ydtech.modules.protocol.service.PtlAgreementService;
  39. import com.ydtech.modules.protocols.entity.po.InsFeeOrderNew;
  40. import com.ydtech.modules.protocols.service.InsFeeOrderNewService;
  41. import com.ydtech.utils.BigDecimalUtils;
  42. import com.ydtech.utils.SnowFlakeUtil;
  43. import com.ydtech.utils.StringOperations;
  44. import com.ydtech.utils.excel.ExcelEasypoiUtils;
  45. import com.ydtech.utils.excel.ExcelStyleUtil;
  46. import lombok.extern.slf4j.Slf4j;
  47. import org.apache.commons.lang3.ObjectUtils;
  48. import org.apache.commons.lang3.StringUtils;
  49. import org.springframework.beans.BeanUtils;
  50. import org.springframework.beans.factory.annotation.Autowired;
  51. import org.springframework.beans.factory.annotation.Value;
  52. import org.springframework.context.annotation.Lazy;
  53. import org.springframework.stereotype.Service;
  54. import org.springframework.transaction.annotation.Transactional;
  55. import org.springframework.util.CollectionUtils;
  56. import org.springframework.web.multipart.MultipartFile;
  57. import javax.servlet.http.HttpServletRequest;
  58. import javax.servlet.http.HttpServletResponse;
  59. import java.io.IOException;
  60. import java.math.BigDecimal;
  61. import java.math.RoundingMode;
  62. import java.nio.file.Files;
  63. import java.nio.file.Path;
  64. import java.nio.file.Paths;
  65. import java.time.LocalDate;
  66. import java.time.LocalDateTime;
  67. import java.time.LocalTime;
  68. import java.time.YearMonth;
  69. import java.time.format.DateTimeFormatter;
  70. import java.util.*;
  71. /**
  72. * <p>
  73. * 保司结算手续费 服务实现类
  74. * </p>
  75. *
  76. * @author gws
  77. * @since 2024-01-05
  78. */
  79. @Slf4j
  80. @Service
  81. public class InsPlyIncomeServiceImpl extends ServiceImpl<InsPlyIncomeMapper, InsPlyIncome> implements InsPlyIncomeService {
  82. @Autowired
  83. @Lazy
  84. private InsOrdersService insOrdersService;
  85. @Autowired
  86. private InsAreaCompanyService insAreaCompanyService;
  87. @Autowired
  88. private InsFeeOrderNewService insFeeOrderNewService;
  89. @Autowired
  90. private SettlementDocumentaryFeesService settlementDocumentaryFeesService;
  91. @Autowired
  92. private SettlementDocumentaryLogService settlementDocumentaryLogService;
  93. @Autowired
  94. private PtlAgreementService ptlAgreementService;
  95. @Autowired
  96. private EsmInsCompanyService EsmInsCompanyService;
  97. @Autowired
  98. private ImportAsyncService importAsyncService;
  99. @Autowired
  100. private IncomeTaskRelationshipService incomeTaskRelationshipService;
  101. @Autowired
  102. private SettlementDocumentaryFeesSumService settlementDocumentaryFeesSumService;
  103. @Value("${upload.file.path}")
  104. private String uploadPath;
  105. @Value("${upload.file.url}")
  106. private String uploadUrl;
  107. public HttpResult<BasePageResult<InsPlyIncome>> queryplyIncome(InsPlyIncomeVo insPlyIncomeVo) {
  108. try {
  109. Page<InsOrders> page = new Page<>(insPlyIncomeVo.getPageNum(), insPlyIncomeVo.getPageSize());
  110. PageInfo<List<InsPlyIncome>> pageHelper = null;
  111. PageHelper.startPage(insPlyIncomeVo.getPageNum(), insPlyIncomeVo.getPageSize());
  112. List<InsPlyIncome> list = this.baseMapper.selectByCondition(insPlyIncomeVo);
  113. pageHelper = new PageInfo(list);
  114. BasePageResult<InsPlyIncome> pageResult = new BasePageResult<InsPlyIncome>(insPlyIncomeVo.getPageNum(),
  115. insPlyIncomeVo.getPageSize(), pageHelper.getTotal(), pageHelper.getPages(), list);
  116. return HttpResult.ok(pageResult);
  117. } catch (Exception e) {
  118. e.printStackTrace();
  119. return HttpResult.error("查询异常");
  120. }
  121. }
  122. @Override
  123. public void saveBalanceNew(InsOrders order, InsFeeOrderNew insFeeOrderNew, InsAreaCompany insAreaCompany) {
  124. if (ObjectUtils.isEmpty(order) || ObjectUtils.isEmpty(insFeeOrderNew) || ObjectUtils.isEmpty(insAreaCompany)) {
  125. return;
  126. }
  127. String agreeType = this.judgeAgreeType(insAreaCompany.getAgreementId());
  128. if (StringUtils.isNotEmpty(agreeType)) {
  129. // 判断协议类型 平台 保险
  130. if ("1".equals(agreeType)) {
  131. this.savePinTai(order, insFeeOrderNew, insAreaCompany); //手续费不分非车不非车 跟单也不分
  132. } else { // 保险 逻辑: 手续费生成一条 跟单费生成一条 非车手续费一条 非车跟单费一条
  133. if (((insFeeOrderNew.getJqSuperviseCostsPremiums() != null && insFeeOrderNew.getJqSuperviseCostsPremiums().compareTo(BigDecimal.ZERO) != 0)) || (insFeeOrderNew.getSySuperviseCostsPremiums() != null && insFeeOrderNew.getSySuperviseCostsPremiums().compareTo(BigDecimal.ZERO) != 0)) { //手续费
  134. this.saveInsuranceProcedures(order, insFeeOrderNew, insAreaCompany);
  135. }
  136. if (insFeeOrderNew.getJqOtherCostsPremiums() != null && insFeeOrderNew.getJqOtherCostsPremiums().compareTo(BigDecimal.ZERO) != 0) { //跟单费
  137. this.saveOtherAmount(order, insFeeOrderNew, insAreaCompany);
  138. }
  139. if (insFeeOrderNew.getNoSuperviseCostsPremiums() != null && insFeeOrderNew.getNoSuperviseCostsPremiums().compareTo(BigDecimal.ZERO) != 0) { // 非车手续费
  140. this.saveNoSupervise(order, insFeeOrderNew, insAreaCompany);
  141. }
  142. if (insFeeOrderNew.getNoOtherCostsPremiums() != null && insFeeOrderNew.getNoOtherCostsPremiums().compareTo(BigDecimal.ZERO) != 0) { // 非车跟单费
  143. this.saveNoOtherAmount(order, insFeeOrderNew, insAreaCompany);
  144. }
  145. }
  146. }
  147. }
  148. private void saveNoOtherAmount(InsOrders order, InsFeeOrderNew insFeeOrderNew, InsAreaCompany insAreaCompany) {
  149. InsPlyIncome insPlyIncome = new InsPlyIncome();
  150. insPlyIncome.setOrderno(insFeeOrderNew.getInsOrderNo()); // 子订单号
  151. String noPolicyno = this.setNoPolicyno(insAreaCompany);
  152. if (StringUtils.isNotEmpty(noPolicyno)) {
  153. insPlyIncome.setNoPolicyno(noPolicyno); // 非车保单号
  154. }
  155. insPlyIncome.setOtherFeevalue(insFeeOrderNew.getNoOtherCostsPremiums()); //非车跟单费
  156. insPlyIncome.setOtherFeerate(insFeeOrderNew.getNoOtherCostsProportion()); //非车跟单费用比例
  157. this.saveRiskCode(order.getProductid(), insPlyIncome);
  158. insPlyIncome.setPayDate(insAreaCompany.getPayDate());
  159. insPlyIncome.setSignDate(insAreaCompany.getSigningTime());
  160. insPlyIncome.setCompanyId(insAreaCompany.getCompanyId());
  161. insPlyIncome.setAgreementId(insFeeOrderNew.getAgreementId());
  162. insPlyIncome.setLicenseno(order.getLicenseno());
  163. insPlyIncome.setTaxamount(insAreaCompany.getTaxamount());
  164. insPlyIncome.setNoTaxPremium(insFeeOrderNew.getNoNoTaxPremium());
  165. insPlyIncome.setCreateTime(LocalDate.now());
  166. insPlyIncome.setDocumentaryFeesStatus("0");
  167. insPlyIncome.setInsuredName(order.getInsuredname());
  168. insPlyIncome.setHandlingFeesStatus("0");
  169. insPlyIncome.setNoNoTaxPremium(insFeeOrderNew.getNoNoTaxPremium());
  170. insPlyIncome.setNoPremium(insFeeOrderNew.getNoPremium());
  171. insPlyIncome.setIsNotCar("1");
  172. insPlyIncome.setIsNotDocumentary("1");
  173. insPlyIncome.setJqStartDate(StringOperations.emptyStringToNull(insAreaCompany.getJqStartDate()));
  174. insPlyIncome.setJqEndDate(StringOperations.emptyStringToNull(insAreaCompany.getJqEndDate()));
  175. insPlyIncome.setSyStartDate(StringOperations.emptyStringToNull(insAreaCompany.getSyStartDate()));
  176. insPlyIncome.setSyEndDate(StringOperations.emptyStringToNull(insAreaCompany.getSyEndDate()));
  177. insPlyIncome.setAllFeeValue(insFeeOrderNew.getNoOtherCostsPremiums());
  178. insPlyIncome.setNoOtherCostsPremium(insFeeOrderNew.getNoOtherCostsPremiums());
  179. insPlyIncome.setNoOtherCostsProportion(insFeeOrderNew.getNoOtherCostsProportion());
  180. this.saveByCompanyId(insFeeOrderNew, insAreaCompany.getCompanyId(), insPlyIncome);
  181. this.getDeptId(insPlyIncome);
  182. baseMapper.insert(insPlyIncome);
  183. }
  184. private void saveNoSupervise(InsOrders order, InsFeeOrderNew insFeeOrderNew, InsAreaCompany insAreaCompany) {
  185. InsPlyIncome insPlyIncome = new InsPlyIncome();
  186. insPlyIncome.setOrderno(insFeeOrderNew.getInsOrderNo()); // 子订单号
  187. insPlyIncome.setCommissionFeevalue(insFeeOrderNew.getNoSuperviseCostsPremiums());// 非车手续费
  188. insPlyIncome.setCommissionFeerate(insFeeOrderNew.getNoSuperviseCostsProportion());// 非车手续费比例
  189. String noPolicyno = this.setNoPolicyno(insAreaCompany);
  190. if (StringUtils.isNotEmpty(noPolicyno)) {
  191. insPlyIncome.setNoPolicyno(noPolicyno); // 非车保单号
  192. }
  193. // insPlyIncome.setDeptId(insFeeOrderNew.getDeptId());
  194. this.saveRiskCode(order.getProductid(), insPlyIncome);
  195. insPlyIncome.setPayDate(insAreaCompany.getPayDate());
  196. insPlyIncome.setSignDate(insAreaCompany.getSigningTime());
  197. insPlyIncome.setCompanyId(insAreaCompany.getCompanyId());
  198. insPlyIncome.setAgreementId(insFeeOrderNew.getAgreementId());
  199. insPlyIncome.setLicenseno(order.getLicenseno());
  200. insPlyIncome.setTaxamount(insAreaCompany.getTaxamount());
  201. insPlyIncome.setCreateTime(LocalDate.now());
  202. insPlyIncome.setDocumentaryFeesStatus("0");
  203. insPlyIncome.setHandlingFeesStatus("0");
  204. insPlyIncome.setIsNotCar("1");
  205. insPlyIncome.setIsNotDocumentary("0");
  206. insPlyIncome.setAllFeeValue(insFeeOrderNew.getNoSuperviseCostsPremiums());
  207. insPlyIncome.setUserId(insFeeOrderNew.getUserId());
  208. insPlyIncome.setInsuredName(order.getInsuredname());
  209. insPlyIncome.setNoPremium(insFeeOrderNew.getNoPremium()); //非车保费
  210. insPlyIncome.setNoNoTaxPremium(insFeeOrderNew.getNoNoTaxPremium()); //非车不含税保费
  211. insPlyIncome.setJqStartDate(StringOperations.emptyStringToNull(insAreaCompany.getJqStartDate()));
  212. insPlyIncome.setJqEndDate(StringOperations.emptyStringToNull(insAreaCompany.getJqEndDate()));
  213. insPlyIncome.setSyStartDate(StringOperations.emptyStringToNull(insAreaCompany.getSyStartDate()));
  214. insPlyIncome.setSyEndDate(StringOperations.emptyStringToNull(insAreaCompany.getSyEndDate()));
  215. insPlyIncome.setNoSuperviseCostsPremiums(insFeeOrderNew.getNoSuperviseCostsPremiums());
  216. insPlyIncome.setNoSuperviseCostsProportion(insFeeOrderNew.getNoSuperviseCostsProportion());
  217. this.getDeptId(insPlyIncome);
  218. this.saveByCompanyId(insFeeOrderNew, insAreaCompany.getCompanyId(), insPlyIncome);
  219. baseMapper.insert(insPlyIncome);
  220. }
  221. private void saveRiskCode(String productid, InsPlyIncome insPlyIncome) {
  222. if (ProductsType.PT_0330.getCode().equals(productid)) {
  223. insPlyIncome.setRiskcode(ProductsType.PT_0330.getDesc());
  224. }
  225. if (ProductsType.PT_034001.getCode().equals(productid)) {
  226. insPlyIncome.setRiskcode(ProductsType.PT_034001.getDesc());
  227. }
  228. if (ProductsType.PT_034002.getCode().equals(productid)) {
  229. insPlyIncome.setRiskcode(ProductsType.PT_034002.getDesc());
  230. }
  231. if (ProductsType.PT_0330034002.getCode().equals(productid)) {
  232. insPlyIncome.setRiskcode(ProductsType.PT_0330034002.getDesc());
  233. }
  234. if (ProductsType.PT_0330034001.getCode().equals(productid)) {
  235. insPlyIncome.setRiskcode(ProductsType.PT_0330034001.getDesc());
  236. }
  237. }
  238. private void saveOtherAmount(InsOrders order, InsFeeOrderNew insFeeOrderNew, InsAreaCompany insAreaCompany) {
  239. BigDecimal otherAmount = this.calculateTotal(insFeeOrderNew.getJqOtherCostsPremiums(), insFeeOrderNew.getSyOtherCostsPremiums(),
  240. null);
  241. BigDecimal otherProportion = this.calculateTotal(insFeeOrderNew.getSyOtherCostsProportion(),
  242. insFeeOrderNew.getJqOtherCostsProportion(), null);
  243. BigDecimal allNoTaxPremium = this.calculateTotal(insFeeOrderNew.getJqNoTaxPremium(), insFeeOrderNew.getSyNoTaxPremium(), null);
  244. //交强不含税保费
  245. BigDecimal allPremium = this.calculateTotal(insFeeOrderNew.getJqPremium(), insFeeOrderNew.getSyPremium(), null);// 总保费
  246. InsPlyIncome insPlyIncome = new InsPlyIncome(insFeeOrderNew.getInsOrderNo(), insAreaCompany.getJqpolicyno(),
  247. insAreaCompany.getSypolicyno(), null, null, null, null, order.getProductid(), insAreaCompany.getPayDate(),
  248. insAreaCompany.getSigningTime(), insAreaCompany.getCompanyId(), null, insFeeOrderNew.getAgreementId(), order.getLicenseno(),
  249. insAreaCompany.getTaxamount(),
  250. allNoTaxPremium, null, otherProportion, null, otherAmount, otherAmount, null, null, LocalDate.now(), null, null, null, "0"
  251. , "0", "0", "1");
  252. this.saveRiskCode(order.getProductid(), insPlyIncome);
  253. insPlyIncome.setTaxPremium(allPremium);
  254. insPlyIncome.setJqPremium(insFeeOrderNew.getJqPremium());
  255. insPlyIncome.setSyPremium(insFeeOrderNew.getSyPremium());
  256. insPlyIncome.setJqNoTaxPremium(insFeeOrderNew.getJqNoTaxPremium());
  257. insPlyIncome.setSyNoTaxPremium(insFeeOrderNew.getSyNoTaxPremium());
  258. insPlyIncome.setJqOtherCostsProportion(insFeeOrderNew.getJqOtherCostsProportion()); //交强跟单费比例
  259. insPlyIncome.setSyOtherCostsProportion(insFeeOrderNew.getSyOtherCostsProportion()); //商业跟单费比例
  260. insPlyIncome.setSyOtherCostsPremium(insFeeOrderNew.getSyOtherCostsPremiums());
  261. insPlyIncome.setJqOtherCostsPremium(insFeeOrderNew.getJqOtherCostsPremiums());
  262. insPlyIncome.setJqStartDate(StringOperations.emptyStringToNull(insAreaCompany.getJqStartDate()));
  263. insPlyIncome.setJqEndDate(StringOperations.emptyStringToNull(insAreaCompany.getJqEndDate()));
  264. insPlyIncome.setSyStartDate(StringOperations.emptyStringToNull(insAreaCompany.getSyStartDate()));
  265. insPlyIncome.setSyEndDate(StringOperations.emptyStringToNull(insAreaCompany.getSyEndDate()));
  266. insPlyIncome.setUserId(insFeeOrderNew.getUserId());
  267. insPlyIncome.setInsuredName(order.getInsuredname());
  268. this.getDeptId(insPlyIncome);
  269. this.saveByCompanyId(insFeeOrderNew, insAreaCompany.getCompanyId(), insPlyIncome);
  270. baseMapper.insert(insPlyIncome);
  271. }
  272. private void saveInsuranceProcedures(InsOrders order, InsFeeOrderNew insFeeOrderNew, InsAreaCompany insAreaCompany) {
  273. // 保险手续费
  274. BigDecimal handlingAmount = this.calculateTotal(insFeeOrderNew.getJqSuperviseCostsPremiums(),
  275. insFeeOrderNew.getSySuperviseCostsPremiums(), null);
  276. BigDecimal handlingProportion = this.calculateTotal(insFeeOrderNew.getJqSuperviseCostsProportion(),
  277. insFeeOrderNew.getSySuperviseCostsProportion(), null);
  278. BigDecimal allNoTaxPremium = this.calculateTotal(insFeeOrderNew.getJqNoTaxPremium(), insFeeOrderNew.getSyNoTaxPremium(), null);
  279. //不含税保费
  280. InsPlyIncome insPlyIncome = new InsPlyIncome(insFeeOrderNew.getInsOrderNo(), insAreaCompany.getJqpolicyno(),
  281. insAreaCompany.getSypolicyno(), null, null, null, null, order.getProductid(), insAreaCompany.getPayDate(),
  282. insAreaCompany.getSigningTime(), insAreaCompany.getCompanyId(), null, insFeeOrderNew.getAgreementId(), order.getLicenseno(),
  283. insAreaCompany.getTaxamount()
  284. , allNoTaxPremium, handlingProportion, null, handlingAmount, null, handlingAmount, null, null, LocalDate.now(), null,
  285. null, null, "0", "0", "0", "0");
  286. BigDecimal allTaxPremium = this.calculateTotal(insFeeOrderNew.getJqPremium(), insFeeOrderNew.getSyPremium(), null);
  287. insPlyIncome.setJqPremium(insFeeOrderNew.getJqPremium());
  288. insPlyIncome.setSyPremium(insFeeOrderNew.getSyPremium());
  289. insPlyIncome.setJqNoTaxPremium(insFeeOrderNew.getJqNoTaxPremium());
  290. insPlyIncome.setSyNoTaxPremium(insFeeOrderNew.getSyNoTaxPremium());
  291. insPlyIncome.setJqSuperviseCostsProportion(insFeeOrderNew.getJqSuperviseCostsProportion());
  292. insPlyIncome.setJqSuperviseCostsPremiums(insFeeOrderNew.getJqSuperviseCostsPremiums());
  293. insPlyIncome.setSySuperviseCostsProportion(insFeeOrderNew.getSySuperviseCostsProportion());
  294. insPlyIncome.setSySuperviseCostsPremiums(insFeeOrderNew.getSySuperviseCostsPremiums());
  295. this.saveRiskCode(order.getProductid(), insPlyIncome);
  296. insPlyIncome.setTaxPremium(allTaxPremium);
  297. insPlyIncome.setUserId(insFeeOrderNew.getUserId());
  298. insPlyIncome.setInsuredName(order.getInsuredname());
  299. insPlyIncome.setJqStartDate(StringOperations.emptyStringToNull(insAreaCompany.getJqStartDate()));
  300. insPlyIncome.setJqEndDate(StringOperations.emptyStringToNull(insAreaCompany.getJqEndDate()));
  301. insPlyIncome.setSyStartDate(StringOperations.emptyStringToNull(insAreaCompany.getSyStartDate()));
  302. insPlyIncome.setSyEndDate(StringOperations.emptyStringToNull(insAreaCompany.getSyEndDate()));
  303. this.saveByCompanyId(insFeeOrderNew, insAreaCompany.getCompanyId(), insPlyIncome);
  304. this.getDeptId(insPlyIncome);
  305. baseMapper.insert(insPlyIncome);
  306. }
  307. private String setNoPolicyno(com.ydtech.modules.fnc.entity.InsAreaCompany insAreaCompany) {
  308. if (insAreaCompany.getJypremium() == null || insAreaCompany.getJypremium().compareTo(BigDecimal.ZERO) == 0) { // 非车跟单费
  309. return null;
  310. }
  311. String crossInsurance = insAreaCompany.getCrossInsurance();
  312. if (StringUtils.isEmpty(crossInsurance)) {
  313. return null;
  314. }
  315. JSONArray objects = JSON.parseArray(crossInsurance);
  316. if (objects.isEmpty()) {
  317. return null;
  318. }
  319. if (ObjectUtils.isEmpty(insAreaCompany.getApiType()) || PtlApiType.PTL_API_2.getCode() == insAreaCompany.getApiType()) {
  320. List<CrawlerVerifyPaymentResponse.DrivingInsurancesDTO> drivingInsurancesDTOS = objects.toJavaList(CrawlerVerifyPaymentResponse.DrivingInsurancesDTO.class);
  321. return drivingInsurancesDTOS.get(0).getApplication();
  322. }
  323. // 永诚
  324. if(insAreaCompany.getCompanyId().contains(InsuranceEnum.AICS.getCode())){
  325. List<DrivingInsuranceDto> javaList = objects.toJavaList(DrivingInsuranceDto.class);
  326. return javaList.get(0).getPolicyNumber();
  327. }
  328. // 大家
  329. if(insAreaCompany.getCompanyId().contains(InsuranceEnum.DJPC.getCode())){
  330. List<NVHLODR1001Response.policyInfosDTO> javaList = objects.toJavaList(NVHLODR1001Response.policyInfosDTO.class);
  331. return javaList.get(0).getPlyNo();
  332. }
  333. // 国任
  334. if(insAreaCompany.getCompanyId().contains(InsuranceEnum.XDCX.getCode())){
  335. List<DrivingInsuranceDto> javaList = objects.toJavaList(DrivingInsuranceDto.class);
  336. return javaList.get(0).getPolicyNumber();
  337. }
  338. // 中煤
  339. if(insAreaCompany.getCompanyId().contains(InsuranceEnum.ZMBX.getCode())){
  340. List<SubmitResponse.AccidentNo> javaList = objects.toJavaList(SubmitResponse.AccidentNo.class);
  341. return javaList.get(0).getRideProposalNo();
  342. }
  343. // 紫金
  344. if(insAreaCompany.getCompanyId().contains(InsuranceEnum.ZKIC.getCode())){
  345. List<DrivingInsuranceDto> javaList = objects.toJavaList(DrivingInsuranceDto.class);
  346. return javaList.get(0).getPolicyNumber();
  347. }
  348. return null;
  349. }
  350. private void savePinTai(InsOrders order, InsFeeOrderNew insFeeOrderNew, InsAreaCompany insAreaCompany) {
  351. BigDecimal handlingAmount = this.calculateTotal(insFeeOrderNew.getJqSuperviseCostsPremiums(),
  352. insFeeOrderNew.getSySuperviseCostsPremiums(), insFeeOrderNew.getNoSuperviseCostsPremiums()); //手续费
  353. BigDecimal handlingProportion = this.calculateTotal(insFeeOrderNew.getJqSuperviseCostsProportion(),
  354. insFeeOrderNew.getSySuperviseCostsProportion(), insFeeOrderNew.getNoSuperviseCostsProportion());//手续费比例
  355. BigDecimal otherAmount = this.calculateTotal(insFeeOrderNew.getJqOtherCostsPremiums(), insFeeOrderNew.getSyOtherCostsPremiums(),
  356. insFeeOrderNew.getNoOtherCostsPremiums());//跟单费
  357. BigDecimal otherProportion = this.calculateTotal(insFeeOrderNew.getSyOtherCostsProportion(),
  358. insFeeOrderNew.getJqOtherCostsProportion(), insFeeOrderNew.getNoOtherCostsProportion()); //跟单费比例
  359. // 不含税保费
  360. BigDecimal allNoTaxPremium = this.calculateTotal(insFeeOrderNew.getJqNoTaxPremium(), insFeeOrderNew.getSyNoTaxPremium(),
  361. insFeeOrderNew.getNoNoTaxPremium());
  362. BigDecimal allAmount = this.calculateTotal(otherAmount, handlingAmount, null);
  363. BigDecimal jqReceivableProportion = this.calculateTotal(insFeeOrderNew.getJqSuperviseCostsProportion(),
  364. insFeeOrderNew.getJqOtherCostsProportion(), null);// 交强应收 比例
  365. BigDecimal syReceivableProportion = this.calculateTotal(insFeeOrderNew.getSySuperviseCostsProportion(),
  366. insFeeOrderNew.getSyOtherCostsProportion(), null);//商业应收比例
  367. BigDecimal noReceivableProportion = this.calculateTotal(insFeeOrderNew.getNoSuperviseCostsProportion(),
  368. insFeeOrderNew.getNoOtherCostsProportion(), null);
  369. String noPolicyno = this.setNoPolicyno(insAreaCompany);
  370. InsPlyIncome insPlyIncome = new InsPlyIncome(insFeeOrderNew.getInsOrderNo(), insAreaCompany.getJqpolicyno(),
  371. insAreaCompany.getSypolicyno(),
  372. noPolicyno, null, null, null, order.getProductid(), insAreaCompany.getPayDate(), insAreaCompany.getSigningTime(),
  373. insAreaCompany.getCompanyId(),
  374. null, insFeeOrderNew.getAgreementId(), order.getLicenseno(), insAreaCompany.getTaxamount(), allNoTaxPremium,
  375. handlingProportion,
  376. otherProportion, handlingAmount, otherAmount, allAmount, null, null, LocalDate.now(), null, null, null, "0", "0", "0", "0");
  377. insPlyIncome.setJqReceivableProportion(jqReceivableProportion);
  378. insPlyIncome.setSyReceivableProportion(syReceivableProportion);
  379. insPlyIncome.setNoReceivableProportion(noReceivableProportion);
  380. // 应收金额 = 商业手续费+商业跟单 + 交强手续费 +交强跟单费 + 非车手续费 + 非车跟单费 = allAmount
  381. insPlyIncome.setJqSuperviseCostsPremiums(insFeeOrderNew.getJqSuperviseCostsPremiums()); // 交强手续费
  382. insPlyIncome.setSySuperviseCostsPremiums(insFeeOrderNew.getSySuperviseCostsPremiums()); // 商业手续费
  383. insPlyIncome.setNoSuperviseCostsPremiums(insFeeOrderNew.getNoSuperviseCostsPremiums()); // 非车手续费
  384. insPlyIncome.setJqSuperviseCostsProportion(insFeeOrderNew.getJqSuperviseCostsProportion()); //交强手续费 比例
  385. insPlyIncome.setSySuperviseCostsProportion(insFeeOrderNew.getSySuperviseCostsProportion()); // 商业手续费 比例
  386. insPlyIncome.setNoSuperviseCostsProportion(insFeeOrderNew.getNoSuperviseCostsProportion());// 非车手续费 比例
  387. insPlyIncome.setJqOtherCostsProportion(insFeeOrderNew.getJqOtherCostsProportion()); //交强跟单费比例
  388. insPlyIncome.setSyOtherCostsProportion(insFeeOrderNew.getSyOtherCostsProportion()); //商业跟单费比例
  389. insPlyIncome.setNoOtherCostsProportion(insFeeOrderNew.getNoOtherCostsProportion()); //非车跟单费比例
  390. insPlyIncome.setJqPremium(insFeeOrderNew.getJqPremium());
  391. insPlyIncome.setSyPremium(insFeeOrderNew.getSyPremium());
  392. insPlyIncome.setNoPremium(insFeeOrderNew.getNoPremium());
  393. insPlyIncome.setReceivableAmount(allAmount);
  394. insPlyIncome.setJqNoTaxPremium(insFeeOrderNew.getJqNoTaxPremium());
  395. insPlyIncome.setSyNoTaxPremium(insFeeOrderNew.getSyNoTaxPremium());
  396. insPlyIncome.setNoNoTaxPremium(insFeeOrderNew.getNoNoTaxPremium());
  397. insPlyIncome.setUserId(insFeeOrderNew.getUserId());
  398. insPlyIncome.setJqStartDate(StringOperations.emptyStringToNull(insAreaCompany.getJqStartDate()));
  399. insPlyIncome.setJqEndDate(StringOperations.emptyStringToNull(insAreaCompany.getJqEndDate()));
  400. insPlyIncome.setSyStartDate(StringOperations.emptyStringToNull(insAreaCompany.getSyStartDate()));
  401. insPlyIncome.setSyEndDate(StringOperations.emptyStringToNull(insAreaCompany.getSyEndDate()));
  402. this.getDeptId(insPlyIncome);
  403. this.saveRiskCode(order.getProductid(), insPlyIncome);
  404. insPlyIncome.setInsuredName(order.getInsuredname());
  405. this.saveByCompanyId(insFeeOrderNew, insAreaCompany.getCompanyId(), insPlyIncome);
  406. baseMapper.insert(insPlyIncome);
  407. }
  408. private void getDeptId(InsPlyIncome insPlyIncome) {
  409. PtlAgreement ptlAgreement = ptlAgreementService.getById(insPlyIncome.getAgreementId());
  410. String deptId = ptlAgreement.getDeptId();
  411. insPlyIncome.setDeptId(deptId);
  412. }
  413. private void saveByCompanyId(InsFeeOrderNew insFeeOrderNew, String companyId, InsPlyIncome insPlyIncome) {
  414. PtlAgreement ptlAgreementQueryVo = this.ptlAgreementService.getByAgreementIdNew(insFeeOrderNew.getAgreementId());
  415. if (ObjectUtils.isNotEmpty(ptlAgreementQueryVo)) {
  416. if (StringUtils.isNotEmpty(ptlAgreementQueryVo.getPartnerCompaniesId())) {
  417. // 合作公司id
  418. String partnerCompaniesId = ptlAgreementQueryVo.getPartnerCompaniesId();
  419. insPlyIncome.setPartnerCompaniesId(partnerCompaniesId);
  420. EsmInsCompany esmInsCompany = EsmInsCompanyService.getById(partnerCompaniesId);
  421. String name = esmInsCompany.getNamesimple(); //合作名称
  422. insPlyIncome.setPartnerCompaniesName(name);
  423. insPlyIncome.setPartnerCompaniesId(ptlAgreementQueryVo.getPartnerCompaniesId());
  424. }
  425. if (StringUtils.isNotEmpty(ptlAgreementQueryVo.getInsuranceCompanyId())) {
  426. String insuranceCompanyId = ptlAgreementQueryVo.getInsuranceCompanyId();
  427. EsmInsCompany esmInsCompany = EsmInsCompanyService.getById(insuranceCompanyId);
  428. String name = esmInsCompany.getNamesimple(); //保险公司名称 简称
  429. insPlyIncome.setCompanyName(name);
  430. }
  431. }
  432. }
  433. private BigDecimal calculateTotal(BigDecimal value1, BigDecimal value2, BigDecimal value3) {
  434. BigDecimal total = BigDecimal.ZERO;
  435. if (value1 != null) {
  436. total = total.add(value1);
  437. }
  438. if (value2 != null) {
  439. total = total.add(value2);
  440. }
  441. if (value3 != null) {
  442. total = total.add(value3);
  443. }
  444. return total;
  445. }
  446. private String judgeAgreeType(Long agreementId) {
  447. if (agreementId == null) {
  448. return null;
  449. }
  450. HttpResult<PtlAgreementQueryVo> byAgreementId = ptlAgreementService.getByAgreementId(agreementId.toString());
  451. if (byAgreementId != null && ObjectUtils.isNotEmpty(byAgreementId.getData())) {
  452. PtlAgreement agreement = byAgreementId.getData().getAgreement();
  453. String agreementType = agreement.getAgreementType();
  454. if (StringUtils.isNotEmpty(agreementType)) {
  455. return agreementType;
  456. }
  457. }
  458. return null;
  459. }
  460. public HttpResult<BasePageResult<InsPlyIncome>> queryNew(InsPlyIncomeVo insPlyIncomeVo) {
  461. try {
  462. HashMap<String, Object> params = new HashMap<>();
  463. PageInfo<List<InsPlyIncome>> pageHelper = null;
  464. PageHelper.startPage(insPlyIncomeVo.getPageNum(), insPlyIncomeVo.getPageSize());
  465. params.put("pageNum", insPlyIncomeVo.getPageNum());
  466. params.put("pageSize", insPlyIncomeVo.getPageSize());
  467. params = this.saveParams(insPlyIncomeVo, params);
  468. if (StringUtils.isNotEmpty(insPlyIncomeVo.getIds())) {
  469. params.put("ids", insPlyIncomeVo.getIds().split(","));
  470. }
  471. if (StringUtils.isNotEmpty(insPlyIncomeVo.getId())) {
  472. SettlementDocumentaryFeesEntity settlementDocumentaryFeesEntity =
  473. settlementDocumentaryFeesService.getById(insPlyIncomeVo.getId());
  474. // 通过任务id查询 明细
  475. String taskId = settlementDocumentaryFeesEntity.getTaskId();
  476. List<String> incomeIds = incomeTaskRelationshipService.getByTaskId(taskId);
  477. if (!CollectionUtils.isEmpty(incomeIds)) {
  478. params.put("incomeIds", incomeIds);
  479. params.remove("handlingFeesStatus");
  480. params.remove("id");
  481. }
  482. }
  483. List<InsPlyIncome> list = this.baseMapper.queryNew(params);
  484. pageHelper = new PageInfo(list);
  485. BasePageResult<InsPlyIncome> pageResult = new BasePageResult<InsPlyIncome>(insPlyIncomeVo.getPageNum(),
  486. insPlyIncomeVo.getPageSize(), pageHelper.getTotal(), pageHelper.getPages(), list);
  487. return HttpResult.ok(pageResult);
  488. } catch (Exception e) {
  489. e.printStackTrace();
  490. return HttpResult.error("查询异常");
  491. }
  492. }
  493. @Override
  494. public HashMap<String, Object> totalAmount(List<String> selectIds) {
  495. HashMap<String, Object> params = new HashMap<>();
  496. params.put("selectIds", selectIds);
  497. HashMap<String, Object> resultMap = baseMapper.totalAmount(params);
  498. return resultMap;
  499. }
  500. @Override
  501. @Transactional
  502. public HttpResult<Object> batchPinBalance(InsPlyIncomeVo insPlyIncomeVo) {
  503. if (!CollectionUtils.isEmpty(insPlyIncomeVo.getSelectIds())) {
  504. List<String> selectIds = insPlyIncomeVo.getSelectIds();
  505. for (String id : selectIds) {
  506. InsPlyIncome insPlyIncome = new InsPlyIncome();
  507. insPlyIncome.setHandlingFeesStatus("1");
  508. insPlyIncome.setSettlementTime(LocalDate.now());
  509. insPlyIncome.setId(id);
  510. baseMapper.updateById(insPlyIncome);
  511. }
  512. }
  513. SettlementDocumentaryLogEntity settlementDocumentaryLogEntity = new SettlementDocumentaryLogEntity();
  514. settlementDocumentaryLogEntity.setIds(insPlyIncomeVo.getIds());
  515. // settlementDocumentaryLogEntity.setCompanyId(insPlyIncomeVo.getCompanyId());
  516. settlementDocumentaryLogEntity.setAmount(insPlyIncomeVo.getOtherFeevalue()); //跟单费金额
  517. settlementDocumentaryLogEntity.setHandingAmount(insPlyIncomeVo.getCommissionFeevalue()); //手续费金额
  518. settlementDocumentaryLogEntity.setCreateTime(new Date());
  519. settlementDocumentaryLogService.save(settlementDocumentaryLogEntity);
  520. return HttpResult.ok();
  521. }
  522. @Override
  523. public List<InsPlyIncome> totalPinAmount(InsPlyIncomeVo insPlyIncomeVo) {
  524. HashMap<String, Object> params = new HashMap<>();
  525. params = this.saveParams(insPlyIncomeVo, params);
  526. List<InsPlyIncome> result = baseMapper.totalPinAmount(params);
  527. return result;
  528. }
  529. private HashMap<String, Object> saveParams(InsPlyIncomeVo insPlyIncomeVo, HashMap<String, Object> params) {
  530. if (ObjectUtils.isNotEmpty(insPlyIncomeVo.getId())) {
  531. params.put("id", insPlyIncomeVo.getId());
  532. }
  533. if (ObjectUtils.isNotEmpty(insPlyIncomeVo.getStartDate())) {
  534. params.put("startDate", insPlyIncomeVo.getStartDate().toString());
  535. }
  536. if (ObjectUtils.isNotEmpty(insPlyIncomeVo.getEndDate())) {
  537. params.put("endDate", insPlyIncomeVo.getEndDate().toString());
  538. }
  539. if (StringUtils.isNotEmpty(insPlyIncomeVo.getOrderno())) {
  540. params.put("orderno", insPlyIncomeVo.getOrderno());
  541. }
  542. if (StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotDocumentary())) {
  543. params.put("isOther", insPlyIncomeVo.getIsNotDocumentary());
  544. }
  545. if (StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotCar())) {
  546. params.put("isNotCar", insPlyIncomeVo.getIsNotCar());
  547. }
  548. if (StringUtils.isNotEmpty(insPlyIncomeVo.getAgreementType())) {
  549. params.put("agreementType", insPlyIncomeVo.getAgreementType());
  550. }
  551. if (StringUtils.isNotEmpty(insPlyIncomeVo.getLicenseno())) {
  552. params.put("licenseno", insPlyIncomeVo.getLicenseno());
  553. }
  554. if (StringUtils.isNotEmpty(insPlyIncomeVo.getUserId())) {
  555. params.put("userId", insPlyIncomeVo.getUserId());
  556. }
  557. if (StringUtils.isNotEmpty(insPlyIncomeVo.getCompanyId())) {
  558. params.put("companyId", insPlyIncomeVo.getCompanyId());
  559. }
  560. if (StringUtils.isNotEmpty(insPlyIncomeVo.getRiskcode())) {
  561. params.put("riskcode", insPlyIncomeVo.getRiskcode());
  562. }
  563. if (StringUtils.isNotEmpty(insPlyIncomeVo.getPolicyno())) {
  564. params.put("policyno", insPlyIncomeVo.getPolicyno());
  565. }
  566. if (StringUtils.isNotEmpty(insPlyIncomeVo.getSyPolicyno())) {
  567. params.put("syPolicyno", insPlyIncomeVo.getSyPolicyno());
  568. }
  569. if (StringUtils.isNotEmpty(insPlyIncomeVo.getNoPolicyno())) {
  570. params.put("noPolicyno", insPlyIncomeVo.getNoPolicyno());
  571. }
  572. if (insPlyIncomeVo.getCreateTime() != null) {
  573. params.put("createTime", insPlyIncomeVo.getCreateTime().toString());
  574. }
  575. if (insPlyIncomeVo.getSettlementTime() != null) {
  576. params.put("settlementTime", insPlyIncomeVo.getSettlementTime().toString());
  577. }
  578. if (StringUtils.isNotEmpty(insPlyIncomeVo.getHandlingFeesStatus())) {
  579. params.put("handlingFeesStatus", insPlyIncomeVo.getHandlingFeesStatus());
  580. }
  581. if (StringUtils.isNotEmpty(insPlyIncomeVo.getPartnerCompaniesId())) {
  582. params.put("partnerCompaniesId", insPlyIncomeVo.getPartnerCompaniesId());
  583. }
  584. if (StringUtils.isNotEmpty(insPlyIncomeVo.getYear())) {
  585. params.put("year", insPlyIncomeVo.getYear());
  586. }
  587. if (StringUtils.isNotEmpty(insPlyIncomeVo.getMonth())) {
  588. params.put("month", insPlyIncomeVo.getMonth());
  589. }
  590. if (StringUtils.isNotEmpty(insPlyIncomeVo.getDay())) {
  591. params.put("day", insPlyIncomeVo.getDay());
  592. }
  593. if (StringUtils.isNotEmpty(insPlyIncomeVo.getSignDateEnd())) {
  594. params.put("signDateEnd", insPlyIncomeVo.getSignDateEnd());
  595. }
  596. if (StringUtils.isNotEmpty(insPlyIncomeVo.getSignDateStart())) {
  597. params.put("signDateStart", insPlyIncomeVo.getSignDateStart());
  598. }
  599. if (StringUtils.isNotEmpty(insPlyIncomeVo.getCompanyName())) {
  600. params.put("companyName", insPlyIncomeVo.getCompanyName());
  601. }
  602. if (StringUtils.isNotEmpty(insPlyIncomeVo.getInsuredName())) {
  603. params.put("insuredName", insPlyIncomeVo.getInsuredName());
  604. }
  605. if (StringUtils.isNotEmpty(insPlyIncomeVo.getPartnerCompaniesName())) {
  606. params.put("partnerCompaniesName", insPlyIncomeVo.getPartnerCompaniesName());
  607. }
  608. if (StringUtils.isNotEmpty(insPlyIncomeVo.getDockingPerson())) {
  609. params.put("dockingPerson", insPlyIncomeVo.getDockingPerson());
  610. }
  611. if (StringUtils.isNotEmpty(insPlyIncomeVo.getYeartsStart()) && StringUtils.isNotEmpty(insPlyIncomeVo.getYeartsEnd())) {
  612. params.put("yeartsStart", insPlyIncomeVo.getYeartsStart());
  613. params.put("yeartsEnd", insPlyIncomeVo.getYeartsEnd());
  614. }
  615. if (insPlyIncomeVo.getJqStartDate() != null) {
  616. params.put("jqStartDate", insPlyIncomeVo.getJqStartDate());
  617. }
  618. if (insPlyIncomeVo.getJqStartDate() != null) {
  619. params.put("jqEndDate", insPlyIncomeVo.getJqEndDate());
  620. }
  621. if (insPlyIncomeVo.getSyStartDate() != null) {
  622. params.put("syStartDate", insPlyIncomeVo.getSyStartDate());
  623. }
  624. if (insPlyIncomeVo.getSyEndDate() != null) {
  625. params.put("syEndDate", insPlyIncomeVo.getSyEndDate());
  626. }
  627. if (StringUtils.isNotEmpty(insPlyIncomeVo.getProvinceId())) {
  628. params.put("provinceId", insPlyIncomeVo.getProvinceId());
  629. }
  630. if (StringUtils.isNotEmpty(insPlyIncomeVo.getCityId())) {
  631. params.put("cityId", insPlyIncomeVo.getCityId());
  632. }
  633. if (StringUtils.isNotEmpty(insPlyIncomeVo.getCountyId())) {
  634. params.put("countyId", insPlyIncomeVo.getCountyId());
  635. }
  636. if (StringUtils.isNotEmpty(insPlyIncomeVo.getDeptId())) {
  637. params.put("deptId", insPlyIncomeVo.getDeptId());
  638. }
  639. if (StringUtils.isNotEmpty(insPlyIncomeVo.getAllPartnerCompaniesId())) {
  640. params.put("allPartnerCompaniesId", insPlyIncomeVo.getAllPartnerCompaniesId().substring(0, 5));
  641. }
  642. if (StringUtils.isNotEmpty(insPlyIncomeVo.getProvincePartnerCompaniesId())) {
  643. params.put("provincePartnerCompaniesId", insPlyIncomeVo.getProvincePartnerCompaniesId());
  644. }
  645. if (!CollectionUtils.isEmpty(insPlyIncomeVo.getSelectIds())) {
  646. params.put("selectIds", insPlyIncomeVo.getSelectIds());
  647. }
  648. if (!CollectionUtils.isEmpty(insPlyIncomeVo.getPartnerCompaniesIdList())) {
  649. params.put("partnerCompaniesIdList", insPlyIncomeVo.getPartnerCompaniesIdList());
  650. }
  651. if(StringUtils.isNotEmpty(insPlyIncomeVo.getCreateTimeQuery())){
  652. params.put("createTimeQuery", insPlyIncomeVo.getCreateTimeQuery());
  653. }
  654. return params;
  655. }
  656. @Override
  657. public HttpResult<BasePageResult<InsPlyIncome>> nonSettlementQuery(InsPlyIncomeVo insPlyIncomeVo) {
  658. try {
  659. HashMap<String, Object> params = new HashMap<>();
  660. PageInfo<List<InsPlyIncome>> pageHelper = null;
  661. PageHelper.startPage(insPlyIncomeVo.getPageNum(), insPlyIncomeVo.getPageSize());
  662. params.put("pageNum", insPlyIncomeVo.getPageNum());
  663. params.put("pageSize", insPlyIncomeVo.getPageSize());
  664. if (StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotCar())) {
  665. params.put("isNotCar", insPlyIncomeVo.getIsNotCar());
  666. }
  667. if (StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotDocumentary())) {
  668. params.put("isOther", insPlyIncomeVo.getIsNotDocumentary());
  669. }
  670. if (StringUtils.isNotEmpty(insPlyIncomeVo.getYear())) {
  671. params.put("year", insPlyIncomeVo.getYear());
  672. }
  673. if (StringUtils.isNotEmpty(insPlyIncomeVo.getMonth())) {
  674. params.put("month", insPlyIncomeVo.getMonth());
  675. }
  676. if (StringUtils.isNotEmpty(insPlyIncomeVo.getDocumentaryFeesStatus())) {
  677. params.put("documentaryFeesStatus", insPlyIncomeVo.getDocumentaryFeesStatus());
  678. }
  679. List<InsPlyIncome> list = this.baseMapper.NonSettlementQuery(params);
  680. pageHelper = new PageInfo(list);
  681. BasePageResult<InsPlyIncome> pageResult = new BasePageResult<InsPlyIncome>(insPlyIncomeVo.getPageNum(),
  682. insPlyIncomeVo.getPageSize(), pageHelper.getTotal(), pageHelper.getPages(), list);
  683. return HttpResult.ok(pageResult);
  684. } catch (Exception e) {
  685. e.printStackTrace();
  686. return HttpResult.error("查询异常");
  687. }
  688. }
  689. @Override
  690. public HttpResult<List<InsPlyIncome>> nonSettldetail(InsPlyIncomeVo insPlyIncomeVo) {
  691. try {
  692. String ids = insPlyIncomeVo.getIds();
  693. ArrayList<InsPlyIncome> resultList = new ArrayList<>();
  694. if (ObjectUtils.isNotEmpty(ids)) {
  695. String[] split = ids.split(",");
  696. for (int i = 0; i < split.length; i++) {
  697. String id = split[i];
  698. resultList.add(this.baseMapper.getById(id));
  699. }
  700. }
  701. return HttpResult.ok(resultList);
  702. } catch (Exception e) {
  703. e.printStackTrace();
  704. return HttpResult.error("查询异常");
  705. }
  706. }
  707. /**
  708. * @param multipartFile
  709. * @return totalAmount 总金额
  710. * totalHandingAmount 总手续费金额
  711. * totalOtherAmount 总跟单费金额
  712. * resultHashMap 返回 ids 已经上面的金额
  713. * resultNoSelect 未匹配的车牌号
  714. */
  715. @Override
  716. public HashMap<String, Object> importData(MultipartFile multipartFile) {
  717. BigDecimal totalAmount = BigDecimal.ZERO;
  718. BigDecimal totalHandingAmount = BigDecimal.ZERO;
  719. BigDecimal totalOtherAmount = BigDecimal.ZERO;
  720. HashMap<String, Object> params = new HashMap<>();
  721. HashMap<String, Object> resultHashMap = new HashMap<>();
  722. ArrayList<HashMap<String, Object>> resultNoSelect = new ArrayList<>();
  723. try {
  724. List<InsPlyIncomeExcelDto> dtoList = ExcelEasypoiUtils.importExcel(multipartFile, InsPlyIncomeExcelDto.class, 0, 1, 1);
  725. for (InsPlyIncomeExcelDto excelItem : dtoList) {
  726. HashMap<String, Object> objectObjectHashMap = new HashMap<>();
  727. if (StringUtils.isNotEmpty(excelItem.getLicenseno())) {
  728. objectObjectHashMap.put("licenseno", excelItem.getLicenseno());//车牌号
  729. }
  730. if (StringUtils.isNotEmpty(excelItem.getPolicyno())) {
  731. objectObjectHashMap.put("policyno", excelItem.getPolicyno()); //交强保单号
  732. }
  733. if (StringUtils.isNotEmpty(excelItem.getSyPolicyno())) {
  734. objectObjectHashMap.put("syPolicyno", excelItem.getSyPolicyno());//商业保单号
  735. }
  736. if (StringUtils.isNotEmpty(excelItem.getNoPolicyno())) {
  737. objectObjectHashMap.put("noPolicyno", excelItem.getNoPolicyno()); //非车保单号
  738. }
  739. InsPlyIncome insPlyIncome = baseMapper.findByLicenseno(objectObjectHashMap);
  740. if (ObjectUtils.isNotEmpty(insPlyIncome)) {
  741. if (insPlyIncome.getAllFeeValue() != null && insPlyIncome.getAllFeeValue().compareTo(BigDecimal.ZERO) != 0) {
  742. totalAmount = totalAmount.add(insPlyIncome.getAllFeeValue()); //总金额
  743. }
  744. if (insPlyIncome.getCommissionFeevalue() != null && insPlyIncome.getCommissionFeevalue().compareTo(BigDecimal.ZERO) != 0) {
  745. totalHandingAmount = totalHandingAmount.add(insPlyIncome.getCommissionFeevalue()); //总手续费
  746. }
  747. if (insPlyIncome.getOtherFeevalue() != null && insPlyIncome.getOtherFeevalue().compareTo(BigDecimal.ZERO) != 0) {
  748. totalOtherAmount = totalOtherAmount.add(insPlyIncome.getOtherFeevalue()); //总跟单费
  749. }
  750. } else {
  751. resultNoSelect.add(objectObjectHashMap); // 添加未匹配的车牌号
  752. }
  753. }
  754. resultHashMap.put("totalAmount", totalAmount);
  755. resultHashMap.put("totalHandingAmount", totalHandingAmount);
  756. resultHashMap.put("totalOtherAmount", totalOtherAmount);
  757. resultHashMap.put("resultList", resultNoSelect);
  758. return resultHashMap;
  759. } catch (IOException e) {
  760. throw new SystemException("导入失败!");
  761. }
  762. }
  763. /**
  764. * @param multipartFile
  765. * @return resultList 包含总金额 还有 未匹配表中的数据
  766. */
  767. @Override
  768. public HashMap<String, Object> bxImportData(MultipartFile multipartFile, String isNotCar) {
  769. BigDecimal totalAmount = BigDecimal.ZERO;
  770. HashMap<String, Object> params = new HashMap<>();
  771. ArrayList<HashMap<String, Object>> resultList = new ArrayList<>();
  772. HashMap<String, Object> resultMap = new HashMap<>();
  773. StringBuffer strBuilder = new StringBuffer();
  774. boolean open = true;
  775. String ids = "";
  776. try {
  777. List<InsBxPlyIncomeExcelDto> dtoList = ExcelEasypoiUtils.importExcel(multipartFile, InsBxPlyIncomeExcelDto.class, 0, 1, 1);
  778. Integer i = 0;
  779. if (!CollectionUtils.isEmpty(dtoList)) {
  780. for (InsBxPlyIncomeExcelDto excelItem : dtoList) {
  781. String reason = "";
  782. i = i + 1;
  783. params.clear();
  784. if (StringUtils.isNotEmpty(excelItem.getLicenseno())) {
  785. String licenseno = excelItem.getLicenseno();//车牌号
  786. params.put("licenseno", licenseno);
  787. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  788. if (ObjectUtils.isEmpty(byBxLicenseno)) {
  789. reason = "该数据车牌号有问题";
  790. }
  791. }
  792. if (StringUtils.isNotEmpty(excelItem.getPolicyno())) {
  793. String policyno = excelItem.getPolicyno(); //交强保单号
  794. params.put("policyno", policyno);
  795. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  796. if (ObjectUtils.isEmpty(byBxLicenseno)) {
  797. reason = "该数据交强保单号有问题";
  798. }
  799. }
  800. if (StringUtils.isNotEmpty(excelItem.getSyPolicyno())) {
  801. String syPolicyno = excelItem.getSyPolicyno(); //商业保单号
  802. params.put("syPolicyno", syPolicyno);
  803. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  804. if (ObjectUtils.isEmpty(byBxLicenseno)) {
  805. reason = "该数据商业保单号有问题";
  806. }
  807. }
  808. if (excelItem.getJqSuperviseCostsPremiums() != null && excelItem.getJqSuperviseCostsPremiums().compareTo(BigDecimal.ZERO) != 0) {
  809. params.put("jqSuperviseCostsPremiums", excelItem.getJqSuperviseCostsPremiums());
  810. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  811. if (ObjectUtils.isEmpty(byBxLicenseno)) {
  812. reason = "该数据交强手续费金额有问题";
  813. }
  814. }
  815. if (excelItem.getJqSuperviseCostsProportion() != null && excelItem.getJqSuperviseCostsProportion().compareTo(BigDecimal.ZERO) != 0) {
  816. params.put("jqSuperviseCostsProportion", excelItem.getJqSuperviseCostsProportion());
  817. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  818. if (ObjectUtils.isEmpty(byBxLicenseno)) {
  819. reason = "该数据交强手续费比例有问题";
  820. }
  821. }
  822. if (excelItem.getSySuperviseCostsProportion() != null && excelItem.getSySuperviseCostsProportion().compareTo(BigDecimal.ZERO) != 0) {
  823. params.put("sySuperviseCostsProportion", excelItem.getSySuperviseCostsProportion());
  824. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  825. if (ObjectUtils.isEmpty(byBxLicenseno)) {
  826. reason = "该数据商业手续费比例有问题";
  827. }
  828. }
  829. if (excelItem.getSySuperviseCostsPremiums() != null && excelItem.getSySuperviseCostsPremiums().compareTo(BigDecimal.ZERO) != 0) {
  830. params.put("sySuperviseCostsPremiums", excelItem.getSySuperviseCostsPremiums());
  831. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  832. if (ObjectUtils.isEmpty(byBxLicenseno)) {
  833. reason = "该数据商业手续费金额有问题";
  834. }
  835. }
  836. if (excelItem.getJqPremium() != null && excelItem.getJqPremium().compareTo(BigDecimal.ZERO) != 0) {
  837. params.put("jqPremium", excelItem.getJqPremium());
  838. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  839. if (ObjectUtils.isEmpty(byBxLicenseno)) {
  840. reason = "该数据交强保费有问题";
  841. }
  842. }
  843. if (excelItem.getSyPremium() != null && excelItem.getSyPremium().compareTo(BigDecimal.ZERO) != 0) {
  844. params.put("syPremium", excelItem.getSyPremium());
  845. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  846. if (ObjectUtils.isEmpty(byBxLicenseno)) {
  847. reason = "该数据商业保费有问题";
  848. }
  849. }
  850. // 只查手续费
  851. params.put("isOther", "0");
  852. params.put("isNotCar", isNotCar);
  853. InsPlyIncome insPlyIncome = baseMapper.findByBxLicenseno(params);
  854. if (ObjectUtils.isNotEmpty(insPlyIncome) && open) {
  855. open = false;
  856. resultMap.put("companyId", insPlyIncome.getCompanyId()); // 保险公司id
  857. resultMap.put("partnerCompaniesId", insPlyIncome.getPartnerCompaniesId()); //合作公司id
  858. resultMap.put("agreementId", insPlyIncome.getAgreementId()); //协议id
  859. }
  860. if (ObjectUtils.isNotEmpty(insPlyIncome)) { // 比配上汇总金额 未匹配则返回到数据当中
  861. strBuilder.append(insPlyIncome.getId()).append(",");
  862. if (insPlyIncome.getCommissionFeevalue() != null && insPlyIncome.getCommissionFeevalue().compareTo(BigDecimal.ZERO) != 0) {
  863. totalAmount = totalAmount.add(insPlyIncome.getCommissionFeevalue()); //添加总手续费
  864. }
  865. } else {
  866. HashMap<String, Object> noMatching = new HashMap<>();
  867. if (StringUtils.isNotEmpty(excelItem.getLicenseno())) {
  868. noMatching.put("licenseno", excelItem.getLicenseno());
  869. }
  870. if (StringUtils.isNotEmpty(excelItem.getPolicyno())) {
  871. noMatching.put("policyno", excelItem.getPolicyno());
  872. }
  873. if (StringUtils.isNotEmpty(excelItem.getSyPolicyno())) {
  874. noMatching.put("syPolicyno", excelItem.getSyPolicyno());
  875. }
  876. resultList.add(noMatching);
  877. }
  878. resultMap.put("reason", reason);
  879. }
  880. }
  881. if (strBuilder.length() > 0) {
  882. ids = strBuilder.deleteCharAt(strBuilder.length() - 1).toString();
  883. }
  884. resultMap.put("ids", ids);
  885. resultMap.put("totalAmount", totalAmount);
  886. resultMap.put("resultList", resultList);
  887. return resultMap;
  888. } catch (IOException e) {
  889. throw new SystemException("导入失败!");
  890. }
  891. }
  892. @Override
  893. public HashMap<String, Object> bxImportNoData(MultipartFile multipartFile, String isNotCar) {
  894. BigDecimal totalAmount = BigDecimal.ZERO;
  895. HashMap<String, Object> params = new HashMap<>();
  896. HashMap<String, Object> resultMap = new HashMap<>();
  897. ArrayList<HashMap<String, Object>> resultList = new ArrayList<>();
  898. StringBuffer strBuilder = new StringBuffer();
  899. String ids = "";
  900. try {
  901. Integer i = 0;
  902. List<InsBxNoPlyIncomeExcelDto> dtoList = ExcelEasypoiUtils.importExcel(multipartFile, InsBxNoPlyIncomeExcelDto.class, 0, 1, 1);
  903. if (!CollectionUtils.isEmpty(dtoList)) {
  904. for (InsBxNoPlyIncomeExcelDto excelItem : dtoList) {
  905. String reason = "";
  906. i = i + 1;
  907. params.clear();
  908. if (StringUtils.isNotEmpty(excelItem.getLicenseno())) {
  909. String licenseno = excelItem.getLicenseno();//车牌号
  910. params.put("licenseno", licenseno);
  911. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  912. if (ObjectUtils.isEmpty(byBxLicenseno)) {
  913. reason = "该数据车牌号有问题";
  914. }
  915. }
  916. if (StringUtils.isNotEmpty(excelItem.getNoPolicyno())) {
  917. String policyno = excelItem.getNoPolicyno(); //非车保单号
  918. params.put("NoPolicyno", policyno);
  919. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  920. if (ObjectUtils.isEmpty(byBxLicenseno)) {
  921. reason = "该数据非车保单号有问题";
  922. }
  923. }
  924. if (excelItem.getNoPremium() != null && excelItem.getNoPremium().compareTo(BigDecimal.ZERO) != 0) {
  925. params.put("noPolicyno", excelItem.getNoPremium());
  926. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  927. if (ObjectUtils.isEmpty(byBxLicenseno)) {
  928. reason = "该数据非车保费有问题";
  929. }
  930. }
  931. if (excelItem.getNoSuperviseCostsPremiums() != null && excelItem.getNoSuperviseCostsPremiums().compareTo(BigDecimal.ZERO) != 0) {
  932. params.put("noSuperviseCostsPremiums", excelItem.getNoSuperviseCostsPremiums());
  933. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  934. if (ObjectUtils.isEmpty(byBxLicenseno)) {
  935. reason = "该数据非车手续费有问题";
  936. }
  937. }
  938. if (excelItem.getNoSuperviseCostsProportion() != null && excelItem.getNoSuperviseCostsProportion().compareTo(BigDecimal.ZERO) != 0) {
  939. params.put("noSuperviseCostsProportion", excelItem.getNoSuperviseCostsProportion());
  940. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  941. if (ObjectUtils.isEmpty(byBxLicenseno)) {
  942. reason = "该数据非车手续费比例有问题";
  943. }
  944. }
  945. // 只查手续费
  946. params.put("isOther", "0");
  947. params.put("isNotCar", isNotCar);
  948. InsPlyIncome insPlyIncome = baseMapper.findByBxLicenseno(params);
  949. if (i == dtoList.size() && ObjectUtils.isNotEmpty(insPlyIncome)) {
  950. resultMap.put("companyId", insPlyIncome.getCompanyId()); // 保险公司id
  951. resultMap.put("partnerCompaniesId", insPlyIncome.getPartnerCompaniesId()); //合作公司id
  952. resultMap.put("agreementId", insPlyIncome.getAgreementId()); //协议id
  953. }
  954. if (ObjectUtils.isNotEmpty(insPlyIncome)) { // 比配上汇总金额 未匹配则返回到数据当中
  955. strBuilder.append(insPlyIncome.getId()).append(",");
  956. if (insPlyIncome.getCommissionFeevalue() != null && insPlyIncome.getCommissionFeevalue().compareTo(BigDecimal.ZERO) != 0) {
  957. totalAmount = totalAmount.add(insPlyIncome.getCommissionFeevalue()); //添加总手续费
  958. }
  959. } else {
  960. HashMap<String, Object> noMatching = new HashMap<>();
  961. if (StringUtils.isNotEmpty(excelItem.getLicenseno())) {
  962. noMatching.put("licenseno", excelItem.getLicenseno());
  963. }
  964. if (StringUtils.isNotEmpty(excelItem.getNoPolicyno())) {
  965. noMatching.put("NoPolicyno", excelItem.getNoPolicyno());
  966. }
  967. resultList.add(noMatching);
  968. }
  969. resultMap.put("reason", reason);
  970. }
  971. if (strBuilder.length() > 0) {
  972. ids = strBuilder.deleteCharAt(strBuilder.length() - 1).toString();
  973. }
  974. resultMap.put("ids", ids);
  975. resultMap.put("totalAmount", totalAmount);
  976. resultMap.put("resultList", resultList);
  977. }
  978. return resultMap;
  979. } catch (IOException e) {
  980. throw new SystemException("导入失败!");
  981. }
  982. }
  983. @Override
  984. public HttpResult bxOtherDetailsExcel(InsPlyIncomeVo insPlyIncomeVo, HttpServletRequest request, HttpServletResponse response) {
  985. HashMap<String, Object> params = new HashMap<>();
  986. params = this.saveParams(insPlyIncomeVo, params);
  987. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(params);
  988. String filePathName = "";
  989. List<BxOtherDetailsNorExcel> resultNoList = new ArrayList<>();
  990. List<BxOtherDetailsExcel> resultList = new ArrayList<>();
  991. //判断是否是非车 1 是非车
  992. if ("1".equals(insPlyIncomeVo.getIsNotCar())) {
  993. filePathName = "非车跟单明细导出";
  994. ExportParams exportParams = new ExportParams("非车跟单明细", null, ExcelType.HSSF);
  995. exportParams.setStyle(ExcelStyleUtil.class);
  996. for (InsPlyIncome item : insPlyIncomes) {
  997. BxOtherDetailsNorExcel bxOtherDetailsNorExcel = new BxOtherDetailsNorExcel();
  998. LocalDateTime signDate = item.getSignDate();
  999. BeanUtils.copyProperties(item, bxOtherDetailsNorExcel);
  1000. bxOtherDetailsNorExcel.setSigndate(signDate);
  1001. resultNoList.add(bxOtherDetailsNorExcel);
  1002. }
  1003. } else {
  1004. filePathName = "车险跟单明细导出";
  1005. ExportParams exportParams = new ExportParams("车险跟单明细", null, ExcelType.HSSF);
  1006. exportParams.setStyle(ExcelStyleUtil.class);
  1007. for (InsPlyIncome item : insPlyIncomes) {
  1008. BxOtherDetailsExcel bxOtherDetailsExcel = new BxOtherDetailsExcel();
  1009. LocalDateTime signDate = item.getSignDate();
  1010. BeanUtils.copyProperties(item, bxOtherDetailsExcel);
  1011. bxOtherDetailsExcel.setSigndate(signDate);
  1012. resultList.add(bxOtherDetailsExcel);
  1013. }
  1014. }
  1015. String uploadPath = this.uploadPath + "/excel/";
  1016. Path path = Paths.get(uploadPath);
  1017. if (!Files.exists(path)) {
  1018. try {
  1019. Files.createDirectories(path);
  1020. } catch (IOException e) {
  1021. e.printStackTrace();
  1022. }
  1023. }
  1024. String fileName = "";
  1025. if ("1".equals(insPlyIncomeVo.getIsNotCar())) {
  1026. fileName = EasyExcelUtils.downExcel(uploadPath, filePathName, BxOtherDetailsNorExcel.class, resultNoList);
  1027. } else {
  1028. fileName = EasyExcelUtils.downExcel(uploadPath, filePathName, BxOtherDetailsExcel.class, resultList);
  1029. }
  1030. return HttpResult.ok("", uploadUrl + "excel/" + fileName);
  1031. }
  1032. /**
  1033. * @param insPlyIncomeVo 传参字段
  1034. * ids 通过ids中的id进行开票分组
  1035. * @return
  1036. */
  1037. @Override
  1038. public HttpResult<List<SettlementDocumentaryFeesEntity>> invicdetail(InsPlyIncomeVo insPlyIncomeVo) {
  1039. HashMap<String, Object> params = new HashMap<>();
  1040. params = this.saveParams(insPlyIncomeVo, params);
  1041. if (StringUtils.isEmpty(insPlyIncomeVo.getIsSettlement())) {
  1042. params.put("isSettlement", "1");
  1043. }
  1044. if (StringUtils.isNotEmpty(insPlyIncomeVo.getSettlementStatus())) {
  1045. params.put("settlementStatus", insPlyIncomeVo.getSettlementStatus());
  1046. }
  1047. if (StringUtils.isNotEmpty(insPlyIncomeVo.getCompletionStatus())) {
  1048. params.put("completionStatus", insPlyIncomeVo.getCompletionStatus());
  1049. }
  1050. List<SettlementDocumentaryFeesEntity> resultList = settlementDocumentaryFeesService.querySettleNew(params);
  1051. if (resultList.size() > 0) {
  1052. return HttpResult.ok(resultList);
  1053. }
  1054. return HttpResult.ok();
  1055. }
  1056. /***
  1057. *
  1058. * @param insPlyIncomeVo
  1059. * @param request
  1060. * @param response
  1061. * @return 保险非车跟单明细导出
  1062. */
  1063. @Override
  1064. public HttpResult bxNoOtherDetailsExcel(InsPlyIncomeVo insPlyIncomeVo, HttpServletRequest request, HttpServletResponse response) {
  1065. HashMap<String, Object> params = new HashMap<>();
  1066. params = this.saveParams(insPlyIncomeVo, params);
  1067. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(params);
  1068. ExportParams exportParams = new ExportParams("保险非车跟单明细导出", null, ExcelType.HSSF);
  1069. exportParams.setStyle(ExcelStyleUtil.class);
  1070. List<BxNoOtherDetailsExcel> resultList = new ArrayList<>();
  1071. for (InsPlyIncome item : insPlyIncomes) {
  1072. BxNoOtherDetailsExcel bxNoOtherDetailsExcel = new BxNoOtherDetailsExcel();
  1073. BeanUtils.copyProperties(item, bxNoOtherDetailsExcel);
  1074. resultList.add(bxNoOtherDetailsExcel);
  1075. }
  1076. String uploadPath = this.uploadPath + "/excel/";
  1077. Path path = Paths.get(uploadPath);
  1078. if (!Files.exists(path)) {
  1079. try {
  1080. Files.createDirectories(path);
  1081. } catch (IOException e) {
  1082. e.printStackTrace();
  1083. }
  1084. }
  1085. String fileName = EasyExcelUtils.downExcel(uploadPath, "保险非车跟单明细导出", BxNoOtherDetailsExcel.class, resultList);
  1086. return HttpResult.ok("", uploadUrl + "excel/" + fileName);
  1087. }
  1088. /**
  1089. * @param insPlyIncomeVo 开票ids
  1090. * @return 返回开票号 开票金额 开票时间
  1091. */
  1092. @Override
  1093. public HttpResult<List<HashMap<String, Object>>> otherSettldetail(InsPlyIncomeVo insPlyIncomeVo) {
  1094. HashMap<String, Object> params = new HashMap<>();
  1095. params = this.saveParams(insPlyIncomeVo, params);
  1096. List<HashMap<String, Object>> resultList = settlementDocumentaryFeesService.getOtherSettldetail(params);
  1097. if (resultList.size() > 0) {
  1098. return HttpResult.ok(resultList);
  1099. }
  1100. return HttpResult.ok();
  1101. }
  1102. @Override
  1103. public InsPlyIncome getEntityById(String id) {
  1104. return baseMapper.getEntityById(id);
  1105. }
  1106. @Override
  1107. @Transactional
  1108. public void updateByEntity(InsPlyIncomeVo insPlyIncomeVo) {
  1109. // 根据协议 如果是含增值税结算 用保费 * 如果是 不含税保费
  1110. InsPlyIncome insPlyIncome = new InsPlyIncome();
  1111. BeanUtils.copyProperties(insPlyIncomeVo, insPlyIncome);
  1112. this.amountCalculate(insPlyIncomeVo, insPlyIncome);
  1113. insPlyIncome.setUpdateUserId(BaseController.getUser().getId());
  1114. baseMapper.updateById(insPlyIncome);
  1115. insPlyIncomeVo.setCrudStatus("2");
  1116. this.saveLog(insPlyIncomeVo);
  1117. }
  1118. @Override
  1119. public void updateNoHand(InsPlyIncomeVo insPlyIncomeVo) {
  1120. // 根据协议 如果是含增值税结算 用保费 * 如果是 不含税保费
  1121. InsPlyIncome insPlyIncome = new InsPlyIncome();
  1122. BeanUtils.copyProperties(insPlyIncomeVo, insPlyIncome);
  1123. insPlyIncome.setCommissionFeevalue(insPlyIncomeVo.getNoSuperviseCostsPremiums());
  1124. insPlyIncome.setCommissionFeerate(insPlyIncomeVo.getNoSuperviseCostsProportion());
  1125. insPlyIncome.setUpdateUserId(BaseController.getUser().getId());
  1126. baseMapper.updateById(insPlyIncome);
  1127. insPlyIncomeVo.setOtherFeevalue(insPlyIncomeVo.getNoSuperviseCostsPremiums());
  1128. insPlyIncomeVo.setCrudStatus("2");
  1129. this.saveLog(insPlyIncomeVo);
  1130. }
  1131. /**
  1132. * @param insPlyIncomeVo
  1133. * @param insPlyIncome 重新计算金额 通过比例
  1134. * 计算逻辑 交强不含税保费* 交强跟单比例 = 交强跟单金额
  1135. */
  1136. private void amountCalculate(InsPlyIncomeVo insPlyIncomeVo, InsPlyIncome insPlyIncome) {
  1137. if ("1".equals(insPlyIncomeVo.getAgreementType())) { //平台
  1138. // 平台 手续费 +跟单费 = 应收 手续费 = 手续费比例*保费 应收比例=手续费比例 + 跟单比例
  1139. BigDecimal jqSuperviseCostsProportion = initializationBigdecimal(insPlyIncomeVo.getJqSuperviseCostsProportion());//交强手续费比例
  1140. BigDecimal sySuperviseCostsProportion = initializationBigdecimal(insPlyIncomeVo.getSySuperviseCostsProportion()); //商业手续费比例
  1141. BigDecimal noSuperviseCostsProportion = initializationBigdecimal(insPlyIncomeVo.getNoSuperviseCostsProportion()); //非车手续费比例
  1142. BigDecimal jqOtherCostsProportion = initializationBigdecimal(insPlyIncomeVo.getJqOtherCostsProportion()); //交强跟单比例
  1143. BigDecimal syOtherCostsProportion = initializationBigdecimal(insPlyIncomeVo.getSyOtherCostsProportion()); //商业跟单比例
  1144. BigDecimal noOtherCostsProportion = initializationBigdecimal(insPlyIncomeVo.getNoOtherCostsProportion()); //非车跟单比例
  1145. BigDecimal jqPremium = initializationBigdecimal(insPlyIncomeVo.getJqPremium()); //交强保费
  1146. BigDecimal syPremium = initializationBigdecimal(insPlyIncomeVo.getSyPremium()); //商业保费
  1147. BigDecimal noPremium = initializationBigdecimal(insPlyIncomeVo.getNoPremium()); //非车保费
  1148. //手续费比例
  1149. insPlyIncome.setCommissionFeerate(this.calculateTotal(jqSuperviseCostsProportion, sySuperviseCostsProportion,
  1150. noSuperviseCostsProportion)); //手续费比例 = 商业手续费比例 + 交强手续费比例 + 非车手续费比例
  1151. if (jqSuperviseCostsProportion != null && jqPremium != null) {
  1152. insPlyIncome.setJqSuperviseCostsPremiums(algorithmAmount(jqPremium, jqSuperviseCostsProportion)); //交强手续费
  1153. insPlyIncome.setJqSuperviseCostsProportion(jqSuperviseCostsProportion);
  1154. }
  1155. if (sySuperviseCostsProportion != null && syPremium != null) {
  1156. insPlyIncome.setSySuperviseCostsPremiums(algorithmAmount(syPremium, sySuperviseCostsProportion)); //商业手续费
  1157. insPlyIncome.setSySuperviseCostsProportion(sySuperviseCostsProportion);
  1158. }
  1159. if (noSuperviseCostsProportion != null && noPremium != null) {
  1160. insPlyIncome.setNoSuperviseCostsPremiums(algorithmAmount(noPremium, noSuperviseCostsProportion)); //非车手续费
  1161. insPlyIncome.setNoSuperviseCostsProportion(noSuperviseCostsProportion);
  1162. }
  1163. if (jqOtherCostsProportion != null && jqPremium != null) {
  1164. insPlyIncome.setJqOtherCostsPremium(algorithmAmount(jqPremium, jqOtherCostsProportion)); //交强跟单费
  1165. insPlyIncome.setJqOtherCostsProportion(jqOtherCostsProportion);
  1166. }
  1167. if (syOtherCostsProportion != null && syPremium != null) {
  1168. insPlyIncome.setSyOtherCostsPremium(algorithmAmount(syPremium, syOtherCostsProportion)); //商业跟单费
  1169. insPlyIncome.setSyOtherCostsProportion(syOtherCostsProportion);
  1170. }
  1171. if (noOtherCostsProportion != null && noPremium != null) {
  1172. insPlyIncome.setNoOtherCostsPremium(algorithmAmount(noPremium, noOtherCostsProportion)); //非车跟单费
  1173. insPlyIncome.setNoOtherCostsProportion(noOtherCostsProportion);
  1174. }
  1175. insPlyIncome.setCommissionFeevalue(this.calculateTotal(insPlyIncome.getJqSuperviseCostsPremiums(), insPlyIncome.getSySuperviseCostsPremiums(), insPlyIncome.getNoSuperviseCostsPremiums())); //手续费
  1176. insPlyIncome.setCommissionFeerate(this.calculateTotal(jqSuperviseCostsProportion, sySuperviseCostsProportion,
  1177. noSuperviseCostsProportion)); //手续费比例
  1178. insPlyIncome.setOtherFeevalue(this.calculateTotal(insPlyIncome.getJqOtherCostsPremium(), insPlyIncome.getSyOtherCostsPremium(), insPlyIncome.getNoOtherCostsPremium())); //跟单费金额
  1179. insPlyIncome.setOtherFeerate(this.calculateTotal(jqOtherCostsProportion, syOtherCostsProportion, noOtherCostsProportion));
  1180. //跟单费比例
  1181. insPlyIncome.setAllFeeValue(this.calculateTotal(insPlyIncome.getCommissionFeevalue(), insPlyIncome.getOtherFeevalue(), null)); // 总费用 = 手续费+跟单费
  1182. //应收比例 交强应收比例=交强手续费比例+交强非跟单比例
  1183. insPlyIncome.setJqReceivableProportion(this.calculateTotal(jqSuperviseCostsProportion, jqOtherCostsProportion, null)); //交强应收
  1184. insPlyIncome.setSyReceivableProportion(this.calculateTotal(sySuperviseCostsProportion, syOtherCostsProportion, null)); //商业应收
  1185. insPlyIncome.setNoReceivableProportion(this.calculateTotal(noSuperviseCostsProportion, noOtherCostsProportion, null)); //非车应收
  1186. } else {
  1187. BigDecimal divisor = new BigDecimal("1.06"); // 最好是使用字符串来避免精度损失
  1188. BigDecimal jqNoTaxPremium = insPlyIncomeVo.getJqPremium();// 交强手续费 按照思路 交强不含税保费* 交强手续费比例 =交强手续费
  1189. BigDecimal syNoTaxPremium = insPlyIncomeVo.getSyPremium();// 商业手续费 按照思路 商业不含税保费* 商业手续费比例 =商业手续费
  1190. BigDecimal noNoTaxPremium = insPlyIncomeVo.getNoPremium();// 非车手续费 按照思路 非车不含税保费* 非车手续费比例 =非车手续费
  1191. if (jqNoTaxPremium != null && insPlyIncomeVo.getJqSuperviseCostsProportion() != null && insPlyIncomeVo.getJqSuperviseCostsProportion().compareTo(BigDecimal.ZERO) != 0) {
  1192. insPlyIncome.setJqSuperviseCostsPremiums(getBigDecimal(jqNoTaxPremium, insPlyIncomeVo.getJqSuperviseCostsProportion()));
  1193. insPlyIncome.setJqSuperviseCostsProportion(insPlyIncomeVo.getJqSuperviseCostsProportion());
  1194. }
  1195. if (syNoTaxPremium != null && insPlyIncomeVo.getSySuperviseCostsProportion() != null && insPlyIncomeVo.getSySuperviseCostsProportion().compareTo(BigDecimal.ZERO) != 0) {
  1196. insPlyIncome.setSySuperviseCostsPremiums(getBigDecimal(syNoTaxPremium, insPlyIncomeVo.getSySuperviseCostsProportion()));
  1197. insPlyIncome.setSySuperviseCostsProportion(insPlyIncomeVo.getSySuperviseCostsProportion());
  1198. }
  1199. if (noNoTaxPremium != null && insPlyIncomeVo.getNoSuperviseCostsProportion() != null && insPlyIncomeVo.getNoSuperviseCostsProportion().compareTo(BigDecimal.ZERO) != 0) {
  1200. insPlyIncome.setNoSuperviseCostsProportion(insPlyIncome.getNoSuperviseCostsProportion());
  1201. insPlyIncome.setNoSuperviseCostsPremiums(getBigDecimal(noNoTaxPremium, insPlyIncomeVo.getNoSuperviseCostsProportion()));
  1202. }
  1203. if (jqNoTaxPremium != null && insPlyIncomeVo.getJqOtherCostsProportion() != null && insPlyIncomeVo.getJqOtherCostsProportion().compareTo(BigDecimal.ZERO) != 0) {
  1204. insPlyIncome.setJqOtherCostsPremium(getBigDecimal(jqNoTaxPremium, insPlyIncomeVo.getJqOtherCostsProportion()));
  1205. insPlyIncome.setJqOtherCostsProportion(insPlyIncomeVo.getJqOtherCostsProportion());
  1206. }
  1207. if (syNoTaxPremium != null && insPlyIncomeVo.getSyOtherCostsProportion() != null && insPlyIncomeVo.getSyOtherCostsProportion().compareTo(BigDecimal.ZERO) != 0) {
  1208. insPlyIncome.setSyOtherCostsProportion(insPlyIncome.getSyOtherCostsProportion());
  1209. insPlyIncome.setSyOtherCostsPremium(getBigDecimal(syNoTaxPremium, insPlyIncomeVo.getSyOtherCostsProportion()));
  1210. }
  1211. if (noNoTaxPremium != null && insPlyIncomeVo.getOtherFeerate() != null && insPlyIncomeVo.getOtherFeerate().compareTo(BigDecimal.ZERO) != 0) {
  1212. insPlyIncome.setNoOtherCostsProportion(insPlyIncome.getOtherFeerate());
  1213. insPlyIncome.setNoOtherCostsPremium(getBigDecimal(noNoTaxPremium, insPlyIncomeVo.getOtherFeerate()));
  1214. }
  1215. if ("0".equals(insPlyIncomeVo.getIsNotDocumentary()) && "0".equals(insPlyIncomeVo.getIsNotCar())) { //保险 手续费 =不含税保费* 手续费比例
  1216. insPlyIncome.setCommissionFeevalue(this.calculateTotal(insPlyIncome.getJqSuperviseCostsPremiums(), insPlyIncome.getSySuperviseCostsPremiums(), null)); // 手续费
  1217. insPlyIncome.setCommissionFeerate(this.calculateTotal(insPlyIncome.getJqSuperviseCostsProportion(), insPlyIncome.getSySuperviseCostsProportion(), null));//手续费比例
  1218. insPlyIncome.setAllFeeValue(this.calculateTotal(insPlyIncome.getCommissionFeevalue(), null, null));//总金额
  1219. } else if ("1".equals(insPlyIncomeVo.getIsNotDocumentary()) && "0".equals(insPlyIncomeVo.getIsNotCar())) { //保险跟单费 交强跟单+商业跟单
  1220. insPlyIncome.setOtherFeevalue(this.calculateTotal(insPlyIncome.getJqOtherCostsPremium(), insPlyIncome.getSyOtherCostsPremium(), null));
  1221. insPlyIncome.setOtherFeerate(this.calculateTotal(insPlyIncome.getJqOtherCostsProportion(), insPlyIncome.getSyOtherCostsProportion(), null));
  1222. insPlyIncome.setAllFeeValue(this.calculateTotal(insPlyIncome.getOtherFeevalue(), null, null));//总金额
  1223. }
  1224. if ("0".equals(insPlyIncomeVo.getIsNotDocumentary()) && "1".equals(insPlyIncomeVo.getIsNotCar())) {// 非车
  1225. insPlyIncome.setCommissionFeevalue(this.calculateTotal(insPlyIncome.getNoSuperviseCostsPremiums(), null, null)); // 非车手续费
  1226. insPlyIncome.setCommissionFeerate(this.calculateTotal(insPlyIncome.getNoSuperviseCostsProportion(), null, null)); //非车比例
  1227. insPlyIncome.setAllFeeValue(this.calculateTotal(insPlyIncome.getCommissionFeevalue(), null, null));//总金额
  1228. } else if ("1".equals(insPlyIncomeVo.getIsNotDocumentary()) && "1".equals(insPlyIncomeVo.getIsNotCar())) { //非车跟单
  1229. insPlyIncome.setOtherFeevalue(this.calculateTotal(insPlyIncome.getNoOtherCostsPremium(), null, null)); //非车跟单金额
  1230. insPlyIncome.setOtherFeerate(this.calculateTotal(insPlyIncome.getNoOtherCostsProportion(), null, null)); // 非车跟单比例
  1231. insPlyIncome.setAllFeeValue(this.calculateTotal(insPlyIncome.getOtherFeevalue(), null, null));//总金额
  1232. }
  1233. }
  1234. }
  1235. /**
  1236. * 计算 金额
  1237. *
  1238. * @param jqNoTaxPremium
  1239. * @param proportion
  1240. * @return
  1241. */
  1242. private static BigDecimal getBigDecimal(BigDecimal jqNoTaxPremium, BigDecimal proportion) {
  1243. BigDecimal divisor = new BigDecimal("1.06"); // 示例除数
  1244. // 先进行除法,保留5位小数,不进行四舍五入(使用RoundingMode.DOWN)
  1245. BigDecimal dividedAmount = jqNoTaxPremium.divide(divisor, 5, RoundingMode.DOWN);
  1246. // 将比例除以100,假设proportion是一个百分比值
  1247. BigDecimal scaledProportion = proportion.divide(new BigDecimal(100));
  1248. // 然后进行乘法,并进行舍入到5位小数
  1249. BigDecimal result = dividedAmount.multiply(scaledProportion).setScale(5, RoundingMode.DOWN);
  1250. return result;
  1251. }
  1252. /**
  1253. * @param value1 保费
  1254. * @param value2 比例
  1255. * @return 费用
  1256. */
  1257. private BigDecimal algorithmAmount(BigDecimal value1, BigDecimal value2) {
  1258. BigDecimal divide = value2.divide(new BigDecimal(100),5,RoundingMode.DOWN);
  1259. return value1.multiply(divide);
  1260. }
  1261. private BigDecimal initializationBigdecimal(BigDecimal value) {
  1262. return value != null ? value : BigDecimal.ZERO;
  1263. }
  1264. private void saveLog(InsPlyIncomeVo insPlyIncomeVo) {
  1265. // 添加记录
  1266. SettlementDocumentaryLogEntity settlementDocumentaryLogEntity = new SettlementDocumentaryLogEntity();
  1267. settlementDocumentaryLogEntity.setCrudStatus(insPlyIncomeVo.getCrudStatus());
  1268. settlementDocumentaryLogEntity.setAmount(insPlyIncomeVo.getOtherFeevalue());
  1269. settlementDocumentaryLogEntity.setSettlementDocumentaryId(insPlyIncomeVo.getId());
  1270. settlementDocumentaryLogEntity.setAmountType("2");
  1271. settlementDocumentaryLogService.save(settlementDocumentaryLogEntity);
  1272. }
  1273. @Override
  1274. @Transactional
  1275. public HttpResult<InsPlyIncome> insertByEntity(InsPlyIncomeVo insPlyIncomeVo) {
  1276. Long id = new SnowFlakeUtil().nextId();
  1277. InsPlyIncome insPlyIncome = new InsPlyIncome();
  1278. insPlyIncomeVo.setOrderno(id.toString());
  1279. String signdateStr = insPlyIncomeVo.getSignDate();
  1280. LocalDateTime localDateTime = this.LocalDatePareLocalDateTime(signdateStr);
  1281. insPlyIncomeVo.setSignDate(null);
  1282. BeanUtils.copyProperties(insPlyIncomeVo, insPlyIncome);
  1283. insPlyIncome.setUserId(BaseController.getUser().getId());
  1284. insPlyIncome.setDocumentaryFeesStatus("0");
  1285. insPlyIncome.setHandlingFeesStatus("0");
  1286. insPlyIncome.setIsNotCar(insPlyIncomeVo.getIsNotCar()); // 是否是非车
  1287. insPlyIncome.setIsNotDocumentary(insPlyIncomeVo.getIsNotDocumentary()); //是否是跟单
  1288. insPlyIncome.setSignDate(localDateTime);
  1289. insPlyIncome.setDeptId(BaseController.getUser().getDeptId());
  1290. insPlyIncome.setCreateTime(LocalDate.now());
  1291. insPlyIncome.setOtherFeerate(this.calculateTotal(insPlyIncomeVo.getJqOtherCostsProportion(),insPlyIncomeVo.getSyOtherCostsProportion(),insPlyIncomeVo.getNoOtherCostsProportion()));
  1292. insPlyIncome.setCommissionFeerate(this.calculateTotal(insPlyIncomeVo.getJqSuperviseCostsProportion(),insPlyIncomeVo.getSySuperviseCostsProportion(),insPlyIncomeVo.getNoSuperviseCostsProportion()));
  1293. if (insPlyIncome.getJqPremium() != null && insPlyIncome.getJqPremium().compareTo(BigDecimal.ZERO) != 0 && insPlyIncome.getJqSuperviseCostsProportion() != null && insPlyIncome.getJqSuperviseCostsProportion().compareTo(BigDecimal.ZERO) != 0) {
  1294. insPlyIncome.setJqSuperviseCostsPremiums(getBigDecimal(insPlyIncome.getJqPremium(), insPlyIncomeVo.getJqSuperviseCostsProportion()));
  1295. }
  1296. if (insPlyIncome.getSyPremium() != null && insPlyIncome.getSyPremium().compareTo(BigDecimal.ZERO) != 0 && insPlyIncome.getSySuperviseCostsProportion() != null && insPlyIncome.getSySuperviseCostsProportion().compareTo(BigDecimal.ZERO) != 0) {
  1297. insPlyIncome.setSySuperviseCostsPremiums(getBigDecimal(insPlyIncome.getSyPremium(), insPlyIncomeVo.getSySuperviseCostsProportion()));
  1298. }
  1299. if (insPlyIncome.getNoPremium() != null && insPlyIncome.getNoPremium().compareTo(BigDecimal.ZERO) != 0 && insPlyIncome.getNoSuperviseCostsProportion() != null && insPlyIncome.getNoSuperviseCostsProportion().compareTo(BigDecimal.ZERO) != 0) {
  1300. insPlyIncome.setNoSuperviseCostsPremiums(getBigDecimal(insPlyIncome.getNoPremium(), insPlyIncomeVo.getNoSuperviseCostsProportion()));
  1301. }
  1302. if (insPlyIncome.getJqPremium() != null && insPlyIncome.getJqPremium().compareTo(BigDecimal.ZERO) != 0 && insPlyIncome.getJqOtherCostsProportion() != null && insPlyIncome.getJqOtherCostsProportion().compareTo(BigDecimal.ZERO) != 0) {
  1303. insPlyIncome.setJqOtherCostsPremium(getBigDecimal(insPlyIncome.getJqPremium(), insPlyIncomeVo.getJqOtherCostsProportion()));
  1304. }
  1305. if (insPlyIncome.getSyPremium() != null && insPlyIncome.getSyPremium().compareTo(BigDecimal.ZERO) != 0 && insPlyIncome.getSyOtherCostsProportion() != null && insPlyIncome.getSyOtherCostsProportion().compareTo(BigDecimal.ZERO) != 0) {
  1306. insPlyIncome.setSyOtherCostsPremium(getBigDecimal(insPlyIncome.getSyPremium(), insPlyIncomeVo.getSyOtherCostsProportion()));
  1307. }
  1308. if (insPlyIncome.getNoPremium() != null && insPlyIncome.getNoPremium().compareTo(BigDecimal.ZERO) != 0 && insPlyIncome.getNoOtherCostsProportion() != null && insPlyIncome.getNoOtherCostsProportion().compareTo(BigDecimal.ZERO) != 0) {
  1309. insPlyIncome.setNoOtherCostsPremium(getBigDecimal(insPlyIncome.getNoPremium(), insPlyIncomeVo.getNoOtherCostsProportion()));
  1310. }
  1311. insPlyIncome.setAllFeeValue(this.calculateTotal(insPlyIncome.getCommissionFeevalue(),insPlyIncome.getOtherFeevalue(),null));
  1312. String partnerCompaniesId = insPlyIncome.getPartnerCompaniesId();
  1313. insPlyIncome.setPartnerCompaniesId(partnerCompaniesId);
  1314. EsmInsCompany esmInsCompany = EsmInsCompanyService.getById(partnerCompaniesId);
  1315. String name = esmInsCompany.getNamesimple(); //合作名称
  1316. insPlyIncome.setPartnerCompaniesName(name);
  1317. HashMap<String, Object> params = new HashMap<>();
  1318. params.put("agreeId",insPlyIncomeVo.getAgreeId());
  1319. PtlAgreement ptlAgreement = ptlAgreementService.selectAgreeId(params);
  1320. if (ObjectUtils.isEmpty(ptlAgreement)) {
  1321. return HttpResult.error("协议匹配不上");
  1322. }
  1323. insPlyIncome.setAgreementId(ptlAgreement.getId());
  1324. baseMapper.insert(insPlyIncome);
  1325. insPlyIncomeVo.setId(insPlyIncome.getId());
  1326. insPlyIncomeVo.setCrudStatus("1");
  1327. this.saveLog(insPlyIncomeVo); //添加日志
  1328. return HttpResult.ok();
  1329. }
  1330. private LocalDateTime LocalDatePareLocalDateTime(String signdateStr) {
  1331. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
  1332. // 将字符串解析为LocalDate
  1333. LocalDate signdate = LocalDate.parse(signdateStr, formatter);
  1334. // 创建一个 LocalTime 对象表示中午12点
  1335. LocalTime noon = LocalTime.of(12, 0);
  1336. // 使用 LocalDate 和 LocalTime 来创建 LocalDateTime
  1337. return LocalDateTime.of(signdate, noon);
  1338. }
  1339. /**
  1340. * 删除id 已开票或者已结算都不可以进行 删除
  1341. * 因为跟单没有关联表 也无法关联到开票表所以只能按照 条件去查询判断 保司机构 id
  1342. * @param insPlyIncomeVo
  1343. * @return
  1344. */
  1345. @Override
  1346. @Transactional
  1347. public HttpResult<InsPlyIncome> deleteById(InsPlyIncomeVo insPlyIncomeVo) {
  1348. HashMap<String, Object> params = new HashMap<>();
  1349. params.put("id",insPlyIncomeVo.getId());
  1350. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(params);
  1351. InsPlyIncome insPlyIncome = insPlyIncomes.get(0);
  1352. if (StringUtils.isNotEmpty(insPlyIncome.getAgreementType()) && "1".equals(insPlyIncome.getAgreementType())) {
  1353. if ("1".equals(insPlyIncome.getHandlingFeesStatus())) {
  1354. throw new SystemException("已结算不可以进行删除");
  1355. }
  1356. } else if (StringUtils.isNotEmpty(insPlyIncome.getAgreementType()) && "2".equals(insPlyIncome.getAgreementType())) {
  1357. if ("0".equals(insPlyIncome.getIsNotDocumentary())) {
  1358. String taskId = insPlyIncome.getTaskId();
  1359. if (StringUtils.isNotEmpty(taskId)) {
  1360. throw new SystemException("已开票不能进行删除");
  1361. }
  1362. } else {
  1363. // 因为跟单没有关联表 也无法关联到开票表所以只能按照 条件去进行判断
  1364. String partnerCompaniesId = insPlyIncome.getPartnerCompaniesId(); // 保司机构id
  1365. if (StringUtils.isEmpty(partnerCompaniesId)) {
  1366. throw new SystemException("该单据没有保司机构id");
  1367. }
  1368. LambdaQueryWrapper<SettlementDocumentaryFeesEntity> queryWrapper = new LambdaQueryWrapper<>();
  1369. queryWrapper.eq(SettlementDocumentaryFeesEntity::getPartnerCompaniesId, partnerCompaniesId)
  1370. .eq(SettlementDocumentaryFeesEntity::getSettlementStatus, "2");
  1371. List<SettlementDocumentaryFeesEntity> settlementDocumentaryFeesEntities = settlementDocumentaryFeesService.getBaseMapper().selectList(queryWrapper);
  1372. if (settlementDocumentaryFeesEntities.size() > 0) {
  1373. throw new SystemException("已开票不能进行删除");
  1374. }
  1375. }
  1376. }
  1377. baseMapper.deleteById(insPlyIncomeVo.getId()); //删除 结算 然后删除结算表
  1378. return HttpResult.ok("删除成功");
  1379. }
  1380. @Override
  1381. @Transactional
  1382. public void uodateBalance(InsPlyIncomeVo insPlyIncomeVo) {
  1383. InsPlyIncome insPlyIncome = new InsPlyIncome();
  1384. insPlyIncomeVo.setHandlingFeesStatus("1");
  1385. insPlyIncomeVo.setSettlementTime(LocalDate.now()); //结算日期
  1386. BeanUtils.copyProperties(insPlyIncomeVo, insPlyIncome);
  1387. insPlyIncome.setSettlementUserId(BaseController.getUser().getId());
  1388. baseMapper.updateById(insPlyIncome);
  1389. // 生成记录
  1390. SettlementDocumentaryLogEntity settlementDocumentaryLogEntity = new SettlementDocumentaryLogEntity();
  1391. if (StringUtils.isNotEmpty(insPlyIncomeVo.getAgreementType()) && "1".equals(insPlyIncomeVo.getAgreementType())) {
  1392. // 只有平台协议 才会跟单费一笔结算
  1393. settlementDocumentaryLogEntity.setAmount(insPlyIncomeVo.getOtherFeevalue()); // 跟单费金额
  1394. }
  1395. settlementDocumentaryLogEntity.setHandingAmount(insPlyIncomeVo.getCommissionFeevalue()); // 手续费金额
  1396. settlementDocumentaryLogEntity.setSettlementDocumentaryId(insPlyIncomeVo.getId()); // 关联id
  1397. settlementDocumentaryLogEntity.setAmountType("1"); //手续费结算
  1398. settlementDocumentaryLogEntity.setCreateTime(new Date());
  1399. settlementDocumentaryLogService.save(settlementDocumentaryLogEntity);
  1400. }
  1401. @Override
  1402. @Transactional
  1403. public HttpResult<BasePageResult<InsPlyIncome>> totalQuery(InsPlyIncomeVo insPlyIncomeVo) {
  1404. HashMap<String, Object> params = new HashMap<>();
  1405. PageInfo<List<InsPlyIncome>> pageHelper = null;
  1406. if (insPlyIncomeVo.getStartDate() != null) {
  1407. params.put("startDate", insPlyIncomeVo.getStartDate().toString());
  1408. }
  1409. if (insPlyIncomeVo.getEndDate() != null) {
  1410. params.put("endDate", insPlyIncomeVo.getEndDate().toString());
  1411. }
  1412. if (StringUtils.isNotEmpty(insPlyIncomeVo.getYear())) {
  1413. params.put("year", insPlyIncomeVo.getYear());
  1414. }
  1415. if (StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotCar())) {
  1416. params.put("isNotCar", insPlyIncomeVo.getIsNotCar());
  1417. }
  1418. if (StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotDocumentary())) {
  1419. params.put("isOther", insPlyIncomeVo.getIsNotDocumentary());
  1420. }
  1421. if (StringUtils.isNotEmpty(insPlyIncomeVo.getDocumentaryFeesStatus())) {
  1422. params.put("documentaryFeesStatus", insPlyIncomeVo.getDocumentaryFeesStatus());
  1423. }
  1424. if (StringUtils.isNotEmpty(insPlyIncomeVo.getCompanyId())) {
  1425. params.put("companyId", insPlyIncomeVo.getCompanyId());
  1426. }
  1427. params.put("pageNum", insPlyIncomeVo.getPageNum());
  1428. params.put("pageSize", insPlyIncomeVo.getPageSize());
  1429. List<InsPlyIncome> list = this.baseMapper.totalQuery(params);
  1430. pageHelper = new PageInfo(list);
  1431. return HttpResult.ok(new BasePageResult<>(insPlyIncomeVo.getPageNum(), insPlyIncomeVo.getPageSize(), pageHelper.getTotal(),
  1432. pageHelper.getPages(), list));
  1433. }
  1434. /**
  1435. *
  1436. * @param insPlyIncomeVo ids ins_ply_income 这个表的ids incomeIds settlement_documentary_fees 这个表的ids
  1437. * @return
  1438. */
  1439. /**
  1440. * 跟单费结算 有分批结算的情况
  1441. *
  1442. * @param insPlyIncomeVo
  1443. * @return
  1444. */
  1445. @Override
  1446. @Transactional
  1447. public HttpResult batchBalance(InsPlyIncomeVo insPlyIncomeVo) {
  1448. // 分批结算
  1449. SettlementDocumentaryFeesVo settlementDocumentaryFeesVo = new SettlementDocumentaryFeesVo();
  1450. String id = insPlyIncomeVo.getId(); // 开票id
  1451. SettlementDocumentaryFeesEntity settlementDocumentaryFeesServiceById = settlementDocumentaryFeesService.getById(id); //
  1452. BigDecimal allAmount = settlementDocumentaryFeesServiceById.getSettlementAmount();
  1453. HashMap<String, Object> params = new HashMap<>();
  1454. params.put("id", insPlyIncomeVo.getId());
  1455. params.put("handlingFeesStatus", "1");
  1456. SettlementDocumentaryFeesEntity parentSettlementDocumentaryFeesEntity =
  1457. settlementDocumentaryFeesService.getByParentSettlementAmount(params);
  1458. if (ObjectUtils.isNotEmpty(parentSettlementDocumentaryFeesEntity)) { // 多次结算
  1459. BigDecimal totalAmount = parentSettlementDocumentaryFeesEntity.getTotalAmount();
  1460. totalAmount = totalAmount.add(insPlyIncomeVo.getSettlementAmount());
  1461. if (allAmount.compareTo(totalAmount) < 0) {
  1462. return HttpResult.error("结算金额超出开票金额");
  1463. }
  1464. } else {
  1465. if (allAmount.compareTo(insPlyIncomeVo.getSettlementAmount()) < 0) {
  1466. return HttpResult.error("结算金额超出开票金额");
  1467. }
  1468. }
  1469. settlementDocumentaryFeesVo.setInvoiceId(insPlyIncomeVo.getInvoicId()); //开票号
  1470. settlementDocumentaryFeesVo.setSettlementTime(insPlyIncomeVo.getSettlementTime()); //结算时间
  1471. settlementDocumentaryFeesVo.setSettlementStatus("2"); //2为结算状态
  1472. settlementDocumentaryFeesVo.setCompanyId(insPlyIncomeVo.getCompanyId()); // 保险公司id
  1473. settlementDocumentaryFeesVo.setPartnerCompaniesId(insPlyIncomeVo.getPartnerCompaniesId()); //合作公司id
  1474. settlementDocumentaryFeesVo.setUnsettledAmount(insPlyIncomeVo.getInvoicCommissionFeevalue().subtract(insPlyIncomeVo.getSettlementAmount())); //未结算金额
  1475. settlementDocumentaryFeesVo.setIsNotCar(insPlyIncomeVo.getIsNotCar()); // 是否是非车
  1476. settlementDocumentaryFeesVo.setInvoicingMethod(insPlyIncomeVo.getInvoicingMethod()); //开票方式
  1477. settlementDocumentaryFeesVo.setTaxPoints(insPlyIncomeVo.getTaxPoints()); //税点
  1478. settlementDocumentaryFeesVo.setSettlementImageId(insPlyIncomeVo.getSettlementImageId());
  1479. if ("0".equals(insPlyIncomeVo.getInvoicingMethod())) {
  1480. settlementDocumentaryFeesVo.setExpendAmount(insPlyIncomeVo.getSettlementAmount().multiply(BigDecimal.ONE.subtract(insPlyIncomeVo.getTaxPoints().divide(new BigDecimal(100)))));
  1481. } else {
  1482. settlementDocumentaryFeesVo.setExpendAmount(insPlyIncomeVo.getSettlementAmount()); //进账金额
  1483. }
  1484. settlementDocumentaryFeesVo.setSettlementAmount(insPlyIncomeVo.getSettlementAmount()); //进账金额
  1485. settlementDocumentaryFeesVo.setHandlingFeesStatus(insPlyIncomeVo.getHandlingFeesStatus());
  1486. settlementDocumentaryFeesVo.setTotalAmount(insPlyIncomeVo.getInvoicCommissionFeevalue());
  1487. settlementDocumentaryFeesVo.setCreateTime(LocalDateTime.now());
  1488. settlementDocumentaryFeesVo.setParentId(insPlyIncomeVo.getId());
  1489. settlementDocumentaryFeesVo.setAgreementType("2"); //1平台 2 保险
  1490. settlementDocumentaryFeesService.inertSettle(settlementDocumentaryFeesVo);
  1491. return HttpResult.ok();
  1492. }
  1493. @Override
  1494. @Transactional
  1495. public HttpResult<Object> batchSumBalance(InsPlyIncomeVo insPlyIncomeVo) {
  1496. List<InsPlyIncomeVo> multipleSelection = insPlyIncomeVo.getMultipleSelection();
  1497. HashMap<String, Object> params = new HashMap<>();
  1498. BigDecimal settleMentAmount = BigDecimal.ZERO;
  1499. BigDecimal settleNotMentAmount = BigDecimal.ZERO;
  1500. for (InsPlyIncomeVo item : multipleSelection){
  1501. SettlementDocumentaryFeesEntity settlementDocumentaryFeesVo = new SettlementDocumentaryFeesEntity();
  1502. if(item.getInvoicCommissionFeevalue() ==null || item .getSettlementAmount().compareTo(BigDecimal.ZERO) <0){
  1503. throw new SystemException("请输入正确金额");
  1504. }
  1505. String id = item.getId();
  1506. SettlementDocumentaryFeesEntity settlementDocumentaryFeesEntity = settlementDocumentaryFeesService.getBaseMapper().selectById(id); // 开票
  1507. BigDecimal invoicedNotSettledAmount = settlementDocumentaryFeesEntity.getInvoicedNotSettledAmount();//未结算金额
  1508. if(item.getInvoicCommissionFeevalue().compareTo(invoicedNotSettledAmount) >0){
  1509. throw new SystemException("结算金额大于未结算金额");
  1510. }
  1511. if(item.getInvoicCommissionFeevalue().compareTo(BigDecimal.ZERO) >0){
  1512. settlementDocumentaryFeesVo.setInvoiceId(settlementDocumentaryFeesEntity.getInvoicId()); //开票号
  1513. settlementDocumentaryFeesVo.setSettlementTime(insPlyIncomeVo.getSettlementTime()); //结算时间
  1514. settlementDocumentaryFeesVo.setSettlementStatus("2"); //2为结算状态
  1515. settlementDocumentaryFeesVo.setCompanyId(settlementDocumentaryFeesEntity.getCompanyId()); // 保险公司id
  1516. settlementDocumentaryFeesVo.setPartnerCompaniesId(settlementDocumentaryFeesEntity.getPartnerCompaniesId()); //合作公司id
  1517. // settlementDocumentaryFeesVo.setUnsettledAmount(insPlyIncomeVo.getInvoicCommissionFeevalue().subtract(insPlyIncomeVo.getSettlementAmount())); //未结算金额
  1518. settlementDocumentaryFeesVo.setIsNotCar(settlementDocumentaryFeesEntity.getIsNotCar()); // 是否是非车
  1519. settlementDocumentaryFeesVo.setInvoicingMethod(settlementDocumentaryFeesEntity.getInvoicingMethod()); //开票方式
  1520. settlementDocumentaryFeesVo.setTaxPoints(settlementDocumentaryFeesEntity.getTaxPoints()); //税点
  1521. settlementDocumentaryFeesVo.setSettlementImageId(insPlyIncomeVo.getSettlementImageId());
  1522. if ("0".equals(insPlyIncomeVo.getInvoicingMethod())) {
  1523. settlementDocumentaryFeesVo.setExpendAmount(item.getInvoicCommissionFeevalue().multiply(BigDecimal.ONE.subtract(insPlyIncomeVo.getTaxPoints().divide(new BigDecimal(100)))));
  1524. } else {
  1525. settlementDocumentaryFeesVo.setExpendAmount(item.getInvoicCommissionFeevalue()); //进账金额
  1526. }
  1527. settlementDocumentaryFeesVo.setSettlementAmount(item.getInvoicCommissionFeevalue()); //进账金额
  1528. settlementDocumentaryFeesVo.setHandlingFeesStatus(settlementDocumentaryFeesEntity.getHandlingFeesStatus());
  1529. settlementDocumentaryFeesVo.setTotalAmount(settlementDocumentaryFeesEntity.getSettlementAmount());
  1530. settlementDocumentaryFeesVo.setCreateTime(LocalDateTime.now());
  1531. settlementDocumentaryFeesVo.setSettlementTime(LocalDate.now());
  1532. settlementDocumentaryFeesVo.setParentId(insPlyIncomeVo.getId());
  1533. settlementDocumentaryFeesVo.setAgreementType("2"); //1平台 2 保险
  1534. settlementDocumentaryFeesVo.setInvoicedSettledAmount(item.getInvoicCommissionFeevalue());
  1535. settlementDocumentaryFeesVo.setInvoicedNotSettledAmount(BigDecimal.ZERO);
  1536. // 生成跟单费结算记录
  1537. SettlementDocumentaryLogEntity settlementDocumentaryLogEntity = new SettlementDocumentaryLogEntity();
  1538. settlementDocumentaryLogEntity.setAmount(item.getInvoicCommissionFeevalue()); // 结算金额
  1539. settlementDocumentaryLogEntity.setSettlementDocumentaryId(settlementDocumentaryFeesEntity.getId()); // 关联id
  1540. settlementDocumentaryLogEntity.setAmountType("2"); //跟单费结算
  1541. settlementDocumentaryLogEntity.setCreateTime(new Date());
  1542. settlementDocumentaryFeesVo.setSettlementSumId(insPlyIncomeVo.getSettlementSumId());
  1543. settlementDocumentaryFeesService.getBaseMapper().insert(settlementDocumentaryFeesVo);
  1544. settlementDocumentaryLogService.save(settlementDocumentaryLogEntity);
  1545. //修改开票金额
  1546. BigDecimal add = settlementDocumentaryFeesEntity.getInvoicedSettledAmount().add(item.getInvoicCommissionFeevalue());
  1547. settlementDocumentaryFeesEntity.setInvoicedSettledAmount(add);
  1548. BigDecimal subtract = settlementDocumentaryFeesEntity.getSettlementAmount().subtract(add);
  1549. settlementDocumentaryFeesEntity.setInvoicedNotSettledAmount(subtract);
  1550. if (subtract.compareTo(BigDecimal.ZERO) == 0) {
  1551. settlementDocumentaryFeesEntity.setCompletionStatus("2");
  1552. } else if (subtract.compareTo(BigDecimal.ZERO) != 0) {
  1553. settlementDocumentaryFeesEntity.setCompletionStatus("1");
  1554. }
  1555. settlementDocumentaryFeesService.updateById(settlementDocumentaryFeesEntity);
  1556. settleMentAmount = settleMentAmount.add(settlementDocumentaryFeesEntity.getInvoicedSettledAmount());
  1557. settleNotMentAmount = settleNotMentAmount.add(settlementDocumentaryFeesEntity.getInvoicedNotSettledAmount());
  1558. }
  1559. // 更新金额
  1560. SettlementDocumentaryFeesSumEntity settlementDocumentaryFeesSumEntity = settlementDocumentaryFeesSumService.getById(insPlyIncomeVo.getSettlementSumId());
  1561. settlementDocumentaryFeesSumEntity.setInvoicedSettledAmount(settleMentAmount);
  1562. settlementDocumentaryFeesSumEntity.setInvoicedNotSettledAmount(settleNotMentAmount);
  1563. if (settleNotMentAmount.compareTo(BigDecimal.ZERO) == 0) {
  1564. settlementDocumentaryFeesSumEntity.setCompletionStatus("2");
  1565. } else if (settleNotMentAmount.compareTo(BigDecimal.ZERO) != 0) {
  1566. settlementDocumentaryFeesSumEntity.setCompletionStatus("1");
  1567. }
  1568. settlementDocumentaryFeesSumService.updateById(settlementDocumentaryFeesSumEntity);
  1569. }
  1570. return HttpResult.ok();
  1571. }
  1572. /**
  1573. * @param insPlyIncomeVo
  1574. * @return
  1575. */
  1576. @Override
  1577. public List<InsPlyIncome> totalBxAmount(InsPlyIncomeVo insPlyIncomeVo) {
  1578. HashMap<String, Object> params = new HashMap<>();
  1579. params = this.saveParams(insPlyIncomeVo, params);
  1580. params.remove("handlingFeesStatus");
  1581. List<InsPlyIncome> resultList = baseMapper.totalBxAmount(params);
  1582. for (InsPlyIncome item : resultList) {
  1583. BigDecimal commissionFeevalue = BigDecimal.ZERO; //总金额
  1584. BigDecimal invoicCommissionFeevalue = BigDecimal.ZERO; //开票未结算
  1585. BigDecimal readyCommissionFeevalue = BigDecimal.ZERO; // 已开票已结算
  1586. BigDecimal noInvoicCommissionFeevalue = BigDecimal.ZERO; //未开票金额
  1587. BigDecimal unSettledAmount; //未结算金额
  1588. params.put("partnerCompaniesId", item.getPartnerCompaniesId());
  1589. params.remove("handlingFeesStatus");
  1590. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(params); //金额总数
  1591. for (InsPlyIncome all : insPlyIncomes) {
  1592. commissionFeevalue = commissionFeevalue.add(all.getCommissionFeevalue());
  1593. }
  1594. //已开票金额 = 开票未结算+ 开票已结算
  1595. params.put("handlingFeesStatus", "0"); // 开票
  1596. params.put("settlementStatus", "1"); // 开票
  1597. List<SettlementDocumentaryFeesEntity> invoicInsPlyIncomes = settlementDocumentaryFeesService.queryNew(params); //金额总数
  1598. for (SettlementDocumentaryFeesEntity invoicInsPlyIncome : invoicInsPlyIncomes) {
  1599. BigDecimal invoicIcommissionFeevalue = invoicInsPlyIncome.getSettlementAmount();// 已经开票金额
  1600. invoicCommissionFeevalue = invoicCommissionFeevalue.add(invoicIcommissionFeevalue); //开票金额
  1601. }
  1602. params.put("settlementStatus", "2"); // 结算
  1603. List<SettlementDocumentaryFeesEntity> settleInsPlyIncomes = settlementDocumentaryFeesService.queryNew(params); //金额总数
  1604. for (SettlementDocumentaryFeesEntity settleInsPlyIncome : settleInsPlyIncomes) {
  1605. BigDecimal settleIcommissionFeevalue = settleInsPlyIncome.getSettlementAmount();// 已结算金额
  1606. readyCommissionFeevalue = readyCommissionFeevalue.add(settleIcommissionFeevalue); //已结算总
  1607. }
  1608. params.put("settlementStatus", 0); //未开票金额
  1609. List<SettlementDocumentaryFeesEntity> noInvoicInsPlyIncomes = settlementDocumentaryFeesService.queryNew(params); //金额总数
  1610. for (SettlementDocumentaryFeesEntity noInvoicInsPlyIncome : noInvoicInsPlyIncomes) {
  1611. BigDecimal noInvoicIcommissionFeevalue = noInvoicInsPlyIncome.getSettlementAmount();// 未开票金额
  1612. noInvoicCommissionFeevalue = noInvoicCommissionFeevalue.add(noInvoicIcommissionFeevalue); //未开票总金额
  1613. }
  1614. noInvoicCommissionFeevalue = commissionFeevalue.subtract(invoicCommissionFeevalue);// 未开票
  1615. unSettledAmount = commissionFeevalue.subtract(readyCommissionFeevalue); //未结算
  1616. //已开票金额
  1617. item.setCommissionFeevalue(commissionFeevalue); //总手续费
  1618. item.setAllInvoicCommissionFeevalue(invoicCommissionFeevalue); //总开票金额
  1619. // 开票未结算 = 开票金额 - 已开票已结算
  1620. invoicCommissionFeevalue = invoicCommissionFeevalue.subtract(readyCommissionFeevalue);
  1621. item.setInvoicCommissionFeevalue(invoicCommissionFeevalue); //开票未结算
  1622. item.setReadyCommissionFeevalue(readyCommissionFeevalue); //已开票已结算
  1623. item.setNoInvoicCommissionFeevalue(noInvoicCommissionFeevalue); //未开票金额
  1624. item.setUnSettledAmount(unSettledAmount); // 未结算金额
  1625. }
  1626. return resultList;
  1627. }
  1628. /**
  1629. * @param idList 要开票的数据集合
  1630. * @param resultList 总返回数据
  1631. */
  1632. private void splicingIds(List<InsPlyIncome> idList, List<InsPlyIncome> resultList) {
  1633. // 使用Map来存储agreementId到其id列表的映射
  1634. Map<String, List<String>> idMap = new HashMap<>();
  1635. for (InsPlyIncome idItem : idList) {
  1636. String partnerCompaniesId = idItem.getPartnerCompaniesId();
  1637. idMap.computeIfAbsent(partnerCompaniesId, k -> new ArrayList<>()).add(idItem.getId());
  1638. }
  1639. for (InsPlyIncome resultItem : resultList) {
  1640. List<String> ids = idMap.getOrDefault(resultItem.getPartnerCompaniesId(), Collections.emptyList());
  1641. String idsString = String.join(",", ids);
  1642. resultItem.setIds(idsString);
  1643. }
  1644. }
  1645. /**
  1646. * @param insPlyIncomeVo
  1647. * @return 保险手续费改成多次结算
  1648. */
  1649. @Override
  1650. @Transactional
  1651. public HttpResult<Object> batchInvoicing(InsPlyIncomeVo insPlyIncomeVo) {
  1652. ImportResult importResult = importAsyncService.getById(insPlyIncomeVo.getSelectIds().get(0)); // 查询 任务
  1653. List<String> byTaskId = incomeTaskRelationshipService.getByTaskId(importResult.getId());
  1654. HashMap<String, Object> params = new HashMap<>();
  1655. if (StringUtils.isNotEmpty(importResult.getId())) {
  1656. params.put("companyId", importResult.getCompanyId());
  1657. params.put("partnerCompaniesId", importResult.getPartnerCompaniesId());
  1658. params.put("isOther", "0");
  1659. if (StringUtils.isNotEmpty(importResult.getHandStatus())) {
  1660. if ("0".equals(importResult.getHandStatus())) {
  1661. params.put("isNotCar", "0");
  1662. } else if ("1".equals(importResult.getHandStatus())) {
  1663. params.put("isNotCar", "1");
  1664. }
  1665. }
  1666. if (!CollectionUtils.isEmpty(byTaskId)) {
  1667. params.put("incomeIds", byTaskId);
  1668. }
  1669. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(params);
  1670. if (!CollectionUtils.isEmpty(insPlyIncomes)) {
  1671. if (insPlyIncomeVo != null) { // 确保insPlyIncomeVo不是null
  1672. for (InsPlyIncome item : insPlyIncomes) {
  1673. item.setInvoicTime(LocalDate.now());
  1674. item.setInvoicId(insPlyIncomeVo.getInvoicId());
  1675. item.setHandlingFeesStatus("2");
  1676. if (StringUtils.isNotEmpty(item.getTaskId())) {
  1677. return HttpResult.error("该单据已经开票 ");
  1678. } else {
  1679. item.setTaskId(importResult.getId());
  1680. item.setSettlementTime(LocalDate.now());
  1681. item.setSettlementUserId(BaseController.getUser().getName());
  1682. baseMapper.updateById(item);
  1683. }
  1684. }
  1685. }
  1686. }
  1687. }
  1688. insPlyIncomeVo.setNoInvoicCommissionFeevalue(importResult.getTotalAmount());
  1689. insPlyIncomeVo.setOtherFeevalue(importResult.getTotalAmount());
  1690. insPlyIncomeVo.setHandlingFeesStatus("0"); // 0手续费 1 跟单费
  1691. insPlyIncomeVo.setIsNotCar(insPlyIncomeVo.getIsNotCar());
  1692. insPlyIncomeVo.setAgreementId(importResult.getAgreementId());
  1693. insPlyIncomeVo.setAgreementType(insPlyIncomeVo.getAgreementType());
  1694. insPlyIncomeVo.setPartnerCompaniesId(importResult.getPartnerCompaniesId());
  1695. insPlyIncomeVo.setSettlementAmount(importResult.getTotalAmount());
  1696. insPlyIncomeVo.setContractId(insPlyIncomeVo.getInvoicId());
  1697. insPlyIncomeVo.setCompanyId(importResult.getCompanyId());
  1698. insPlyIncomeVo.setTaskId(importResult.getId());
  1699. this.batchInvoic(insPlyIncomeVo);
  1700. return HttpResult.ok();
  1701. }
  1702. @Override
  1703. public HttpResult<InsPlyIncome> queryInvoicing(InsPlyIncomeVo insPlyIncomeVo) {
  1704. HashMap<String, Object> params = new HashMap<>();
  1705. params = this.saveParams(insPlyIncomeVo, params);
  1706. InsPlyIncome result = baseMapper.queryInvoicing(params); //总金额
  1707. params.put("handlingFeesStatus", "0");
  1708. InsPlyIncome noResult = baseMapper.queryInvoicing(params); //未结算金额
  1709. result.setReadyCommissionFeevalue(noResult.getCommissionFeevalue());
  1710. return HttpResult.ok(result);
  1711. }
  1712. @Override
  1713. @Transactional
  1714. public HttpResult<Object> batchBxBalance(InsPlyIncomeVo insPlyIncomeVo) {
  1715. // 表内总金额
  1716. SettlementDocumentaryFeesEntity byIdSettlementDocumentaryFeesEntity =
  1717. settlementDocumentaryFeesService.getById(insPlyIncomeVo.getId());
  1718. BigDecimal invoicAmount = byIdSettlementDocumentaryFeesEntity.getTotalAmount();
  1719. String taskId = byIdSettlementDocumentaryFeesEntity.getTaskId();
  1720. List<String> byTaskId = incomeTaskRelationshipService.getByTaskId(taskId);
  1721. HashMap<String, Object> params = new HashMap<>();
  1722. params.put("id", insPlyIncomeVo.getId());
  1723. params.put("handlingFeesStatus", "0");
  1724. SettlementDocumentaryFeesEntity parentSettlementDocumentaryFeesEntity =
  1725. settlementDocumentaryFeesService.getByParentSettlementAmount(params);
  1726. if (ObjectUtils.isNotEmpty(parentSettlementDocumentaryFeesEntity)) { // 多次结算
  1727. BigDecimal totalAmount = parentSettlementDocumentaryFeesEntity.getTotalAmount();
  1728. totalAmount = totalAmount.add(insPlyIncomeVo.getSettlementAmount());
  1729. if (invoicAmount.compareTo(totalAmount) < 0) {
  1730. return HttpResult.error("结算金额大于开票金额");
  1731. }
  1732. } else {
  1733. if (invoicAmount.compareTo(insPlyIncomeVo.getSettlementAmount()) < 0) {
  1734. return HttpResult.error("结算金额大于开票金额");
  1735. } else if (invoicAmount.compareTo(insPlyIncomeVo.getSettlementAmount()) == 0) {
  1736. HashMap<String, Object> incomeParams = new HashMap<>();
  1737. incomeParams.put("incomeIds", byTaskId);
  1738. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(incomeParams);
  1739. for (InsPlyIncome item : insPlyIncomes) {
  1740. item.setHandlingFeesStatus("1");
  1741. baseMapper.updateById(item);
  1742. }
  1743. }
  1744. }
  1745. // 分批结算
  1746. SettlementDocumentaryFeesVo settlementDocumentaryFeesVo = new SettlementDocumentaryFeesVo();
  1747. settlementDocumentaryFeesVo.setInvoiceId(insPlyIncomeVo.getInvoicId()); //开票号
  1748. settlementDocumentaryFeesVo.setSettlementTime(insPlyIncomeVo.getSettlementTime()); //结算时间
  1749. settlementDocumentaryFeesVo.setSettlementStatus("2"); //2为结算状态
  1750. settlementDocumentaryFeesVo.setCompanyId(insPlyIncomeVo.getCompanyId()); // 保险公司id
  1751. settlementDocumentaryFeesVo.setPartnerCompaniesId(insPlyIncomeVo.getPartnerCompaniesId()); //合作公司id
  1752. settlementDocumentaryFeesVo.setIsNotCar(insPlyIncomeVo.getIsNotCar()); // 是否是非车
  1753. settlementDocumentaryFeesVo.setInvoicingMethod(insPlyIncomeVo.getInvoicingMethod()); //开票方式
  1754. settlementDocumentaryFeesVo.setTaxPoints(insPlyIncomeVo.getTaxPoints()); //税点
  1755. settlementDocumentaryFeesVo.setExpendAmount(insPlyIncomeVo.getInvoicCommissionFeevalue().multiply(BigDecimal.ONE.subtract(insPlyIncomeVo.getTaxPoints().divide(new BigDecimal(100)))));
  1756. settlementDocumentaryFeesVo.setSettlementAmount(insPlyIncomeVo.getSettlementAmount()); //进账金额
  1757. settlementDocumentaryFeesVo.setTotalAmount(insPlyIncomeVo.getInvoicCommissionFeevalue());
  1758. settlementDocumentaryFeesVo.setHandlingFeesStatus("0");
  1759. settlementDocumentaryFeesVo.setParentId(insPlyIncomeVo.getId());
  1760. settlementDocumentaryFeesVo.setPartnerCompaniesId(insPlyIncomeVo.getPartnerCompaniesId());
  1761. settlementDocumentaryFeesVo.setSettlementImageId(insPlyIncomeVo.getSettlementImageId());
  1762. settlementDocumentaryFeesVo.setCreateTime(LocalDateTime.now());
  1763. settlementDocumentaryFeesVo.setAgreementType("2"); //1平台 2 保险
  1764. BigDecimal add = byIdSettlementDocumentaryFeesEntity.getInvoicedSettledAmount().add(insPlyIncomeVo.getSettlementAmount());
  1765. byIdSettlementDocumentaryFeesEntity.setInvoicedSettledAmount(add);
  1766. BigDecimal subtract = byIdSettlementDocumentaryFeesEntity.getTotalAmount().subtract(add);
  1767. byIdSettlementDocumentaryFeesEntity.setInvoicedNotSettledAmount(subtract);
  1768. if (subtract.compareTo(BigDecimal.ZERO) == 0) {
  1769. byIdSettlementDocumentaryFeesEntity.setCompletionStatus("2");
  1770. } else if (subtract.compareTo(BigDecimal.ZERO) != 0) {
  1771. byIdSettlementDocumentaryFeesEntity.setCompletionStatus("1");
  1772. }
  1773. settlementDocumentaryFeesService.updateById(byIdSettlementDocumentaryFeesEntity);
  1774. settlementDocumentaryFeesService.inertSettle(settlementDocumentaryFeesVo);
  1775. return HttpResult.ok();
  1776. }
  1777. @Override
  1778. public HttpResult<InsPlyIncome> querySettInvoicing(InsPlyIncomeVo insPlyIncomeVo) {
  1779. HashMap<String, Object> params = new HashMap<>();
  1780. params = this.saveParams(insPlyIncomeVo, params);
  1781. InsPlyIncome insPlyIncome = baseMapper.queryInvoicing(params); //已经开票
  1782. return HttpResult.ok(insPlyIncome);
  1783. }
  1784. /**
  1785. * @param insPlyIncomeVo
  1786. * @return
  1787. */
  1788. @Override
  1789. public HttpResult<List<InsPlyIncome>> allOtherAmount(InsPlyIncomeVo insPlyIncomeVo) {
  1790. HashMap<String, Object> params = new HashMap<>();
  1791. params = this.saveParams(insPlyIncomeVo, params);
  1792. List<InsPlyIncome> resultList = baseMapper.totalBxAmount(params);
  1793. //总跟单费
  1794. for (InsPlyIncome item : resultList) {
  1795. BigDecimal otherFeevalue = BigDecimal.ZERO; //总跟单金额
  1796. BigDecimal invoicCommissionFeevalue = BigDecimal.ZERO; //已开票跟单费
  1797. BigDecimal readyCommissionFeevalue = BigDecimal.ZERO; // 已开票已结算 跟单费
  1798. BigDecimal noInvoicCommissionFeevalue = BigDecimal.ZERO; //未开票跟单金额
  1799. BigDecimal unSettledAmount = BigDecimal.ZERO; //未结算跟单金额
  1800. BigDecimal expendAmount = BigDecimal.ZERO; //实收金额
  1801. BigDecimal taxesFees = BigDecimal.ZERO; //税费
  1802. BigDecimal taxPoints = BigDecimal.ZERO; //税点
  1803. params.put("partnerCompaniesId", item.getPartnerCompaniesId());
  1804. params.remove("handlingFeesStatus");
  1805. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(params); // 总跟单费
  1806. for (InsPlyIncome all : insPlyIncomes) {
  1807. otherFeevalue = otherFeevalue.add(all.getOtherFeevalue());
  1808. }
  1809. //已开票金额 = 开票未结算+ 开票已结算
  1810. params.put("handlingFeesStatus", "1"); // 开票
  1811. params.put("settlementStatus", "1"); // 开票
  1812. List<SettlementDocumentaryFeesEntity> invoicInsPlyIncomes = settlementDocumentaryFeesService.queryNew(params); //金额总数
  1813. for (SettlementDocumentaryFeesEntity invoicInsPlyIncome : invoicInsPlyIncomes) {
  1814. BigDecimal invoicIcommissionFeevalue = invoicInsPlyIncome.getSettlementAmount();// 已经开票金额
  1815. invoicCommissionFeevalue = invoicCommissionFeevalue.add(invoicIcommissionFeevalue); //开票金额
  1816. }
  1817. params.put("settlementStatus", "2"); // 结算
  1818. List<SettlementDocumentaryFeesEntity> settleInsPlyIncomes = settlementDocumentaryFeesService.queryNew(params); //金额总数
  1819. for (SettlementDocumentaryFeesEntity settleInsPlyIncome : settleInsPlyIncomes) {
  1820. BigDecimal settleIcommissionFeevalue = settleInsPlyIncome.getSettlementAmount();// 已结算金额
  1821. readyCommissionFeevalue = readyCommissionFeevalue.add(settleIcommissionFeevalue); //已结算总
  1822. BigDecimal divide = new BigDecimal(100).subtract(settleInsPlyIncome.getTaxPoints()).divide(new BigDecimal(100));
  1823. expendAmount = expendAmount.add(settleInsPlyIncome.getSettlementAmount().multiply(divide));
  1824. }
  1825. params.put("settlementStatus", 0); //未开票金额
  1826. List<SettlementDocumentaryFeesEntity> noInvoicInsPlyIncomes = settlementDocumentaryFeesService.queryNew(params); //金额总数
  1827. for (SettlementDocumentaryFeesEntity noInvoicInsPlyIncome : noInvoicInsPlyIncomes) {
  1828. BigDecimal noInvoicIcommissionFeevalue = noInvoicInsPlyIncome.getSettlementAmount();// 未开票金额
  1829. noInvoicCommissionFeevalue = noInvoicCommissionFeevalue.add(noInvoicIcommissionFeevalue); //未开票总金额
  1830. }
  1831. noInvoicCommissionFeevalue = otherFeevalue.subtract(invoicCommissionFeevalue);// 未开票
  1832. unSettledAmount = otherFeevalue.subtract(readyCommissionFeevalue); //未结算
  1833. //已开票金额
  1834. item.setOtherFeevalue(otherFeevalue); //总手续费
  1835. item.setAllInvoicCommissionFeevalue(invoicCommissionFeevalue); //总开票金额
  1836. // 开票未结算 = 开票金额 - 已开票已结算
  1837. invoicCommissionFeevalue = invoicCommissionFeevalue.subtract(readyCommissionFeevalue);
  1838. item.setInvoicCommissionFeevalue(invoicCommissionFeevalue); //开票未结算
  1839. item.setReadyCommissionFeevalue(readyCommissionFeevalue); //已开票已结算
  1840. item.setNoInvoicCommissionFeevalue(noInvoicCommissionFeevalue); //未开票金额
  1841. item.setUnSettledAmount(unSettledAmount); // 未结算金额
  1842. // 实收金额 = 结算金额 *1-税点
  1843. taxesFees = readyCommissionFeevalue.subtract(expendAmount);
  1844. item.setExpendAmount(expendAmount);
  1845. item.setTaxesFees(taxesFees);
  1846. }
  1847. return HttpResult.ok(resultList);
  1848. }
  1849. @Override
  1850. @Transactional
  1851. public HttpResult<Object> batchInvoic(InsPlyIncomeVo insPlyIncomeVo) {
  1852. SettlementDocumentaryFeesVo settlementDocumentaryFeesVo = new SettlementDocumentaryFeesVo(); // 生成跟单费结算表
  1853. if (StringUtils.isNotEmpty(insPlyIncomeVo.getYear())) {
  1854. settlementDocumentaryFeesVo.setTimeFrame(insPlyIncomeVo.getYear());//年度
  1855. }
  1856. if (!CollectionUtils.isEmpty(insPlyIncomeVo.getMultipleSelection())) {
  1857. InsPlyIncomeVo insPlyIncomeVo1 = insPlyIncomeVo.getMultipleSelection().get(0);
  1858. insPlyIncomeVo.setSettlementAmount(insPlyIncomeVo1.getSettlementAmount());
  1859. insPlyIncomeVo.setOtherFeevalue(insPlyIncomeVo1.getAllTotalOtherFeevalue());
  1860. YearMonth yearMonth = YearMonth.parse(insPlyIncomeVo1.getMonthYear());
  1861. LocalDate signingTime = yearMonth.atDay(1);
  1862. settlementDocumentaryFeesVo.setSigningTime(signingTime);
  1863. }
  1864. if (insPlyIncomeVo.getOtherFeevalue().compareTo(BigDecimal.ZERO) == 0) {
  1865. throw new SystemException("总金额为0不允许开票");
  1866. }
  1867. if (insPlyIncomeVo.getNoInvoicCommissionFeevalue().compareTo(BigDecimal.ZERO) == 0) {
  1868. throw new SystemException("未开票金额为0不允许开票");
  1869. }
  1870. if (insPlyIncomeVo.getSettlementAmount() == null || insPlyIncomeVo.getSettlementAmount().compareTo(BigDecimal.ZERO) <= 0) {
  1871. throw new SystemException("开票金额错误不允许开票");
  1872. }
  1873. if (insPlyIncomeVo.getNoInvoicCommissionFeevalue().compareTo(insPlyIncomeVo.getSettlementAmount()) < 0) {
  1874. throw new SystemException("开票金额必须小于未开票金额 不允许开票");
  1875. }
  1876. if (StringUtils.isNotEmpty(insPlyIncomeVo.getYear())) {
  1877. settlementDocumentaryFeesVo.setYear(insPlyIncomeVo.getYear());
  1878. }
  1879. if (StringUtils.isNotEmpty(insPlyIncomeVo.getMonth())) {
  1880. settlementDocumentaryFeesVo.setMonth(insPlyIncomeVo.getMonth());
  1881. }
  1882. if (StringUtils.isNotEmpty(insPlyIncomeVo.getDay())) {
  1883. settlementDocumentaryFeesVo.setDay(insPlyIncomeVo.getDay());
  1884. }
  1885. settlementDocumentaryFeesVo.setCompanyId(insPlyIncomeVo.getCompanyId());// 保险公司id
  1886. settlementDocumentaryFeesVo.setPartnerCompaniesId(insPlyIncomeVo.getPartnerCompaniesId()); //合作公司id
  1887. settlementDocumentaryFeesVo.setAgreementId(insPlyIncomeVo.getAgreementId());
  1888. settlementDocumentaryFeesVo.setTotalAmount(insPlyIncomeVo.getOtherFeevalue()); //其他费用金额
  1889. settlementDocumentaryFeesVo.setUnsettledAmount(insPlyIncomeVo.getNoInvoicCommissionFeevalue().subtract(insPlyIncomeVo.getSettlementAmount())); //未结算
  1890. settlementDocumentaryFeesVo.setSettlementAmount(insPlyIncomeVo.getSettlementAmount());//已经开票
  1891. settlementDocumentaryFeesVo.setCreateTime(LocalDateTime.now());
  1892. settlementDocumentaryFeesVo.setSettlementStatus("1");
  1893. settlementDocumentaryFeesVo.setIsNotCar(insPlyIncomeVo.getIsNotCar());
  1894. if (StringUtils.isNotEmpty(insPlyIncomeVo.getContractId())) {
  1895. settlementDocumentaryFeesVo.setInvoiceId(insPlyIncomeVo.getContractId()); //开票号
  1896. }
  1897. if (StringUtils.isNotEmpty(insPlyIncomeVo.getTaskId())) {
  1898. settlementDocumentaryFeesVo.setTaskId(insPlyIncomeVo.getTaskId());
  1899. }
  1900. settlementDocumentaryFeesVo.setAgreementType("2");
  1901. settlementDocumentaryFeesVo.setHandlingFeesStatus(insPlyIncomeVo.getHandlingFeesStatus());
  1902. settlementDocumentaryFeesVo.setCompletionStatus("0");
  1903. settlementDocumentaryFeesVo.setInvoicedSettledAmount(BigDecimal.ZERO);
  1904. settlementDocumentaryFeesVo.setInvoicedNotSettledAmount(insPlyIncomeVo.getSettlementAmount());
  1905. settlementDocumentaryFeesVo.setInvoicingMethod(insPlyIncomeVo.getInvoicingMethod()); //开票方式
  1906. settlementDocumentaryFeesVo.setTaxPoints(insPlyIncomeVo.getTaxPoints()); //税点
  1907. settlementDocumentaryFeesVo.setIds(insPlyIncomeVo.getIds());
  1908. // 税点支出
  1909. if ("0".equals(insPlyIncomeVo.getInvoicingMethod()) && BigDecimalUtils.nullToZero(insPlyIncomeVo.getTaxPoints()) != null && insPlyIncomeVo.getTaxPoints().compareTo(BigDecimal.ZERO) != 0 && BigDecimalUtils.nullToZero(insPlyIncomeVo.getSettlementAmount()) != null) {
  1910. BigDecimal settlementAmount = insPlyIncomeVo.getSettlementAmount();
  1911. settlementDocumentaryFeesVo.setExpendAmount(settlementAmount.multiply(BigDecimal.ONE.subtract(insPlyIncomeVo.getTaxPoints().divide(new BigDecimal(100)))));
  1912. } else {
  1913. settlementDocumentaryFeesVo.setExpendAmount(insPlyIncomeVo.getSettlementAmount());
  1914. }
  1915. // 跟单生成批次表
  1916. SettlementDocumentaryFeesSumEntity settlementDocumentaryFeesSumEntity = this.saveSumSettlement(insPlyIncomeVo);
  1917. if(ObjectUtils.isNotEmpty(settlementDocumentaryFeesSumEntity)){
  1918. settlementDocumentaryFeesVo.setSettlementSumId(settlementDocumentaryFeesSumEntity.getId());
  1919. }
  1920. return settlementDocumentaryFeesService.inertSettle(settlementDocumentaryFeesVo);
  1921. }
  1922. private SettlementDocumentaryFeesSumEntity saveSumSettlement(InsPlyIncomeVo insPlyIncomeVo) {
  1923. String handlingFeesStatus = insPlyIncomeVo.getHandlingFeesStatus();
  1924. SettlementDocumentaryFeesSumEntity settlementDocumentaryFeesSumEntity = new SettlementDocumentaryFeesSumEntity();
  1925. BigDecimal totalAmount = BigDecimal.ZERO;
  1926. if("1".equals(handlingFeesStatus)){
  1927. List<InsPlyIncomeVo> nowInsPlyIncomeVo = insPlyIncomeVo.getMultipleSelection();
  1928. for (InsPlyIncomeVo item: nowInsPlyIncomeVo ){
  1929. totalAmount = totalAmount.add(item.getSettlementAmount()) ;
  1930. }
  1931. settlementDocumentaryFeesSumEntity.setPartnerCompaniesId(insPlyIncomeVo.getPartnerCompaniesId());
  1932. settlementDocumentaryFeesSumEntity.setCompanyId(insPlyIncomeVo.getCompanyId());
  1933. settlementDocumentaryFeesSumEntity.setCreateTime(new Date());
  1934. settlementDocumentaryFeesSumEntity.setInvoicId(insPlyIncomeVo.getContractId());
  1935. settlementDocumentaryFeesSumEntity.setInvoicingMethod(insPlyIncomeVo.getInvoicingMethod());
  1936. settlementDocumentaryFeesSumEntity.setIsNotCar(insPlyIncomeVo.getIsNotCar());
  1937. settlementDocumentaryFeesSumEntity.setSettlementStatus("1");
  1938. settlementDocumentaryFeesSumEntity.setUserId(BaseController.getUser().getId());
  1939. settlementDocumentaryFeesSumEntity.setInvoicedSettledAmount(BigDecimal.ZERO);
  1940. settlementDocumentaryFeesSumEntity.setCompletionStatus("0");
  1941. settlementDocumentaryFeesSumEntity.setTotalAmount(totalAmount);// 开票总额
  1942. settlementDocumentaryFeesSumEntity.setInvoicedNotSettledAmount(totalAmount);
  1943. settlementDocumentaryFeesSumService.getBaseMapper().insert(settlementDocumentaryFeesSumEntity);
  1944. return settlementDocumentaryFeesSumEntity;
  1945. }
  1946. return settlementDocumentaryFeesSumEntity;
  1947. }
  1948. @Override
  1949. public HttpResult pinHandlingexcel(InsPlyIncomeVo insPlyIncomeVo, HttpServletRequest request, HttpServletResponse response) {
  1950. HashMap<String, Object> params = new HashMap<>();
  1951. params = this.saveParams(insPlyIncomeVo, params);
  1952. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(params);
  1953. ExportParams exportParams = new ExportParams("平台手续费", null, ExcelType.HSSF);
  1954. exportParams.setStyle(ExcelStyleUtil.class);
  1955. List<SettlementFeesExcel> resultList = new ArrayList<>();
  1956. for (InsPlyIncome item : insPlyIncomes) {
  1957. SettlementFeesExcel bxSettlementFeesExcel = new SettlementFeesExcel();
  1958. BeanUtils.copyProperties(item, bxSettlementFeesExcel);
  1959. if ("1".equals(item.getHandlingFeesStatus())) {
  1960. bxSettlementFeesExcel.setHandlingFeesStatus("已结算");
  1961. } else {
  1962. bxSettlementFeesExcel.setHandlingFeesStatus("未结算");
  1963. }
  1964. resultList.add(bxSettlementFeesExcel);
  1965. }
  1966. String uploadPath = this.uploadPath + "/excel/";
  1967. Path path = Paths.get(uploadPath);
  1968. if (!Files.exists(path)) {
  1969. try {
  1970. Files.createDirectories(path);
  1971. } catch (IOException e) {
  1972. e.printStackTrace();
  1973. }
  1974. }
  1975. String fileName = EasyExcelUtils.downExcel(uploadPath, "平台手续费导出", SettlementFeesExcel.class, resultList);
  1976. return HttpResult.ok("", uploadUrl + "excel/" + fileName);
  1977. }
  1978. @Override
  1979. public HttpResult bxHandlingexcel(InsPlyIncomeVo insPlyIncomeVo, HttpServletRequest request, HttpServletResponse response) {
  1980. HashMap<String, Object> params = new HashMap<>();
  1981. params = this.saveParams(insPlyIncomeVo, params);
  1982. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(params);
  1983. String filePathName = "";
  1984. List<BxSettlementFeesNorExcel> resultNoList = new ArrayList<>();
  1985. List<BxSettlementFeesExcel> resultList = new ArrayList<>();
  1986. //判断是否是非车 1 是非车
  1987. if ("1".equals(insPlyIncomeVo.getIsNotCar())) {
  1988. filePathName = "非车手续费导出";
  1989. ExportParams exportParams = new ExportParams("非车手续费", null, ExcelType.HSSF);
  1990. exportParams.setStyle(ExcelStyleUtil.class);
  1991. for (InsPlyIncome item : insPlyIncomes) {
  1992. BxSettlementFeesNorExcel bxSettlementFeesNorExcel = new BxSettlementFeesNorExcel();
  1993. LocalDateTime signDate = item.getSignDate();
  1994. BeanUtils.copyProperties(item, bxSettlementFeesNorExcel);
  1995. bxSettlementFeesNorExcel.setSigndate(signDate);
  1996. resultNoList.add(bxSettlementFeesNorExcel);
  1997. }
  1998. } else {
  1999. filePathName = "车险手续费导出";
  2000. ExportParams exportParams = new ExportParams("车险手续费", null, ExcelType.HSSF);
  2001. exportParams.setStyle(ExcelStyleUtil.class);
  2002. for (InsPlyIncome item : insPlyIncomes) {
  2003. BxSettlementFeesExcel bxSettlementFeesExcel = new BxSettlementFeesExcel();
  2004. LocalDateTime signDate = item.getSignDate();
  2005. BeanUtils.copyProperties(item, bxSettlementFeesExcel);
  2006. bxSettlementFeesExcel.setSigndate(signDate);
  2007. resultList.add(bxSettlementFeesExcel);
  2008. }
  2009. }
  2010. String uploadPath = this.uploadPath + "/excel/";
  2011. Path path = Paths.get(uploadPath);
  2012. if (!Files.exists(path)) {
  2013. try {
  2014. Files.createDirectories(path);
  2015. } catch (IOException e) {
  2016. e.printStackTrace();
  2017. }
  2018. }
  2019. String fileName = "";
  2020. if ("1".equals(insPlyIncomeVo.getIsNotCar())) {
  2021. fileName = EasyExcelUtils.downExcel(uploadPath, filePathName, BxSettlementFeesNorExcel.class, resultNoList);
  2022. } else {
  2023. fileName = EasyExcelUtils.downExcel(uploadPath, filePathName, BxSettlementFeesExcel.class, resultList);
  2024. }
  2025. return HttpResult.ok("", uploadUrl + "excel/" + fileName);
  2026. }
  2027. @Override
  2028. public HttpResult bxOtherExcel(InsPlyIncomeVo insPlyIncomeVo, HttpServletRequest request, HttpServletResponse response) {
  2029. HashMap<String, Object> params = new HashMap<>();
  2030. params = this.saveParams(insPlyIncomeVo, params);
  2031. params.put("agreementType", "2");
  2032. params.put("isOther", "1");
  2033. params.put("isNotCar", "0");
  2034. List<InsPlyIncome> insPlyIncomes = baseMapper.allOtherAmount(params);
  2035. ExportParams exportParams = new ExportParams("跟单费导出", null, ExcelType.HSSF);
  2036. exportParams.setStyle(ExcelStyleUtil.class);
  2037. List<BxOtherExcel> resultList = new ArrayList<>();
  2038. for (InsPlyIncome item : insPlyIncomes) {
  2039. BxOtherExcel bxSettlementFeesExcel = new BxOtherExcel();
  2040. BeanUtils.copyProperties(item, bxSettlementFeesExcel);
  2041. resultList.add(bxSettlementFeesExcel);
  2042. }
  2043. String uploadPath = this.uploadPath + "/excel/";
  2044. Path path = Paths.get(uploadPath);
  2045. if (!Files.exists(path)) {
  2046. try {
  2047. Files.createDirectories(path);
  2048. } catch (IOException e) {
  2049. e.printStackTrace();
  2050. }
  2051. }
  2052. String fileName = EasyExcelUtils.downExcel(uploadPath, "跟单费导出", BxOtherExcel.class, resultList);
  2053. return HttpResult.ok("", uploadUrl + "excel/" + fileName);
  2054. }
  2055. @Override
  2056. public InsPlyIncome bxTotalAmount(InsPlyIncomeVo insPlyIncomeVo) {
  2057. InsPlyIncome insPlyIncome = new InsPlyIncome();
  2058. HashMap<String, Object> params = new HashMap<>();
  2059. params = this.saveParams(insPlyIncomeVo, params);
  2060. BigDecimal sumCommissionFeevalue = BigDecimal.ZERO; //总金额
  2061. BigDecimal sumInvoicCommissionFeevalue = BigDecimal.ZERO; //开票未结算
  2062. BigDecimal sumReadyCommissionFeevalue = BigDecimal.ZERO; // 已开票已结算
  2063. BigDecimal sumNoInvoicCommissionFeevalue = BigDecimal.ZERO; //未开票金额
  2064. BigDecimal sumUnSettledAmount = BigDecimal.ZERO; //未结算金额
  2065. BigDecimal sumAllInvoicCommissionFeevalue = BigDecimal.ZERO; //总开票
  2066. List<InsPlyIncome> resultList = baseMapper.totalBxAmount(params);
  2067. for (InsPlyIncome item : resultList) {
  2068. BigDecimal commissionFeevalue = BigDecimal.ZERO; //总金额
  2069. BigDecimal invoicCommissionFeevalue = BigDecimal.ZERO; //开票未结算
  2070. BigDecimal readyCommissionFeevalue = BigDecimal.ZERO; // 已开票已结算
  2071. BigDecimal noInvoicCommissionFeevalue = BigDecimal.ZERO; //未开票金额
  2072. BigDecimal unSettledAmount; //未结算金额
  2073. params.put("partnerCompaniesId", item.getPartnerCompaniesId());
  2074. params.remove("handlingFeesStatus");
  2075. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(params); //金额总数
  2076. for (InsPlyIncome all : insPlyIncomes) {
  2077. commissionFeevalue = commissionFeevalue.add(all.getCommissionFeevalue());
  2078. }
  2079. //已开票金额 = 开票未结算+ 开票已结算
  2080. params.put("handlingFeesStatus", "0"); // 开票
  2081. params.put("settlementStatus", "1"); // 开票
  2082. List<SettlementDocumentaryFeesEntity> invoicInsPlyIncomes = settlementDocumentaryFeesService.queryNew(params); //金额总数
  2083. for (SettlementDocumentaryFeesEntity invoicInsPlyIncome : invoicInsPlyIncomes) {
  2084. BigDecimal invoicIcommissionFeevalue = invoicInsPlyIncome.getSettlementAmount();// 已经开票金额
  2085. invoicCommissionFeevalue = invoicCommissionFeevalue.add(invoicIcommissionFeevalue); //开票金额
  2086. }
  2087. params.put("settlementStatus", "2"); // 结算
  2088. List<SettlementDocumentaryFeesEntity> settleInsPlyIncomes = settlementDocumentaryFeesService.queryNew(params); //金额总数
  2089. for (SettlementDocumentaryFeesEntity settleInsPlyIncome : settleInsPlyIncomes) {
  2090. BigDecimal settleIcommissionFeevalue = settleInsPlyIncome.getSettlementAmount();// 已结算金额
  2091. readyCommissionFeevalue = readyCommissionFeevalue.add(settleIcommissionFeevalue); //已结算总
  2092. }
  2093. params.put("settlementStatus", 0); //未开票金额
  2094. List<SettlementDocumentaryFeesEntity> noInvoicInsPlyIncomes = settlementDocumentaryFeesService.queryNew(params); //金额总数
  2095. for (SettlementDocumentaryFeesEntity noInvoicInsPlyIncome : noInvoicInsPlyIncomes) {
  2096. BigDecimal noInvoicIcommissionFeevalue = noInvoicInsPlyIncome.getSettlementAmount();// 未开票金额
  2097. noInvoicCommissionFeevalue = noInvoicCommissionFeevalue.add(noInvoicIcommissionFeevalue); //未开票总金额
  2098. }
  2099. noInvoicCommissionFeevalue = commissionFeevalue.subtract(invoicCommissionFeevalue);// 未开票
  2100. unSettledAmount = commissionFeevalue.subtract(readyCommissionFeevalue); //未结算
  2101. //已开票金额
  2102. item.setCommissionFeevalue(commissionFeevalue); //总手续费
  2103. item.setAllInvoicCommissionFeevalue(invoicCommissionFeevalue); //总开票金额
  2104. // 开票未结算 = 开票金额 - 已开票已结算
  2105. invoicCommissionFeevalue = invoicCommissionFeevalue.subtract(readyCommissionFeevalue);
  2106. item.setInvoicCommissionFeevalue(invoicCommissionFeevalue); //开票未结算
  2107. item.setReadyCommissionFeevalue(readyCommissionFeevalue); //已开票已结算
  2108. item.setNoInvoicCommissionFeevalue(noInvoicCommissionFeevalue); //未开票金额
  2109. item.setUnSettledAmount(unSettledAmount); // 未结算金额
  2110. sumCommissionFeevalue = sumCommissionFeevalue.add(item.getCommissionFeevalue());
  2111. sumInvoicCommissionFeevalue = sumInvoicCommissionFeevalue.add(item.getInvoicCommissionFeevalue());
  2112. sumReadyCommissionFeevalue = sumReadyCommissionFeevalue.add(item.getReadyCommissionFeevalue());
  2113. sumNoInvoicCommissionFeevalue = sumNoInvoicCommissionFeevalue.add(item.getNoInvoicCommissionFeevalue());
  2114. sumUnSettledAmount = sumUnSettledAmount.add(item.getUnSettledAmount());
  2115. sumAllInvoicCommissionFeevalue = sumAllInvoicCommissionFeevalue.add(item.getAllInvoicCommissionFeevalue());
  2116. }
  2117. insPlyIncome.setCommissionFeevalue(sumCommissionFeevalue);
  2118. insPlyIncome.setInvoicCommissionFeevalue(sumInvoicCommissionFeevalue);
  2119. insPlyIncome.setReadyCommissionFeevalue(sumReadyCommissionFeevalue);
  2120. insPlyIncome.setNoInvoicCommissionFeevalue(sumNoInvoicCommissionFeevalue);
  2121. insPlyIncome.setAllInvoicCommissionFeevalue(sumAllInvoicCommissionFeevalue);
  2122. insPlyIncome.setUnSettledAmount(sumUnSettledAmount);
  2123. return insPlyIncome;
  2124. }
  2125. @Override
  2126. public InsPlyIncome ptTotalAmount(InsPlyIncomeVo insPlyIncomeVo) {
  2127. HashMap<String, Object> params = new HashMap<>();
  2128. params = this.saveParams(insPlyIncomeVo, params);
  2129. InsPlyIncome totalledAmount = baseMapper.ptTotalAmount(params); //总金额
  2130. return totalledAmount;
  2131. }
  2132. @Override
  2133. public HttpResult<List<HashMap<String, Object>>> otherTimeDetail(InsPlyIncomeVo insPlyIncomeVo) {
  2134. HashMap<String, Object> params = new HashMap<>();
  2135. this.saveParams(insPlyIncomeVo, params);
  2136. List<HashMap<String, Object>> resultMap = baseMapper.otherTimeDetail(params);
  2137. Set<String> uniqueYears = new HashSet<>();
  2138. for (Map<String, Object> map : resultMap) {
  2139. // 假设年份是以 "year" 为键的,并且它的值是 String 类型
  2140. String year = String.valueOf(map.get("year"));
  2141. if (year != null) { // 确保年份不是 null
  2142. uniqueYears.add(year);
  2143. }
  2144. }
  2145. this.addMonthYear(uniqueYears, resultMap);
  2146. return HttpResult.ok(resultMap);
  2147. }
  2148. /**
  2149. * uniqueYears 年份间隔 resultMap 返回结果
  2150. *
  2151. * @param uniqueYears
  2152. * @param resultMap 返回一到十二月数据
  2153. */
  2154. private void addMonthYear(Set<String> uniqueYears, List<HashMap<String, Object>> resultMap) {
  2155. // 存储已存在的年份-月份组合,以便快速查找
  2156. Set<String> existingYearMonths = new HashSet<>();
  2157. for (Map<String, Object> entry : resultMap) {
  2158. String monthYear = String.valueOf(entry.get("monthYear"));
  2159. existingYearMonths.add(monthYear);
  2160. }
  2161. // 遍历所有年份和月份,并添加缺失的条目
  2162. for (String year : uniqueYears) {
  2163. for (int month = 1; month <= 12; month++) {
  2164. String strNumber = String.valueOf(month);
  2165. if (strNumber.length() < 2) {
  2166. strNumber = String.format("%02d", Integer.parseInt(strNumber));
  2167. }
  2168. String yearMonth = year + "-" + strNumber;
  2169. if (!existingYearMonths.contains(yearMonth)) {
  2170. // 创建一个新的条目并添加到resultMap中
  2171. HashMap<String, Object> newEntry = new HashMap<>();
  2172. newEntry.put("year", year);
  2173. newEntry.put("monthNumber", strNumber);
  2174. newEntry.put("allTotalOtherFeevalue", 0);
  2175. newEntry.put("invoicCommissionFeevalue", 0);
  2176. newEntry.put("monthYear", yearMonth);
  2177. newEntry.put("noInvoicCommissionFeevalue", 0);
  2178. resultMap.add(newEntry);
  2179. }
  2180. }
  2181. }
  2182. // 使用自定义Comparator对resultMap进行排序
  2183. Collections.sort(resultMap, new Comparator<HashMap<String, Object>>() {
  2184. @Override
  2185. public int compare(HashMap<String, Object> o1, HashMap<String, Object> o2) {
  2186. // 比较 year
  2187. String year1 = String.valueOf(o1.get("year"));
  2188. String year2 = String.valueOf(o2.get("year"));
  2189. int yearComparison = year1.compareTo(year2);
  2190. if (yearComparison != 0) {
  2191. return yearComparison;
  2192. }
  2193. // 如果 year 相同,则比较 monthNumber
  2194. Integer monthNum1 = Integer.parseInt(String.format("%2s", o1.get("monthNumber")).replaceAll(" ", "0"));
  2195. Integer monthNum2 = Integer.parseInt(String.format("%2s", o2.get("monthNumber")).replaceAll(" ", "0"));
  2196. return monthNum1.compareTo(monthNum2);
  2197. }
  2198. });
  2199. }
  2200. @Override
  2201. @Transactional
  2202. public HttpResult<Object> singleInvoic(InsPlyIncomeVo insPlyIncomeVo) {
  2203. // 通过ids 查出跟单非结算单
  2204. SettlementDocumentaryFeesVo settlementDocumentaryFeesVo = new SettlementDocumentaryFeesVo(); // 生成跟单费结算表
  2205. if (!CollectionUtils.isEmpty(insPlyIncomeVo.getMultipleSelection())) {
  2206. SettlementDocumentaryFeesSumEntity settlementDocumentaryFeesSumEntity = this.saveSumSettlement(insPlyIncomeVo);
  2207. for (InsPlyIncomeVo insPlyIncomeVo1 : insPlyIncomeVo.getMultipleSelection()) {
  2208. insPlyIncomeVo.setSettlementAmount(insPlyIncomeVo1.getSettlementAmount());
  2209. insPlyIncomeVo.setOtherFeevalue(insPlyIncomeVo1.getAllTotalOtherFeevalue());
  2210. YearMonth yearMonth = YearMonth.parse(insPlyIncomeVo1.getMonthYear());
  2211. LocalDate signingTime = yearMonth.atDay(1);
  2212. settlementDocumentaryFeesVo.setSigningTime(signingTime);
  2213. if (insPlyIncomeVo.getOtherFeevalue().compareTo(BigDecimal.ZERO) == 0) {
  2214. throw new SystemException("总金额为0不允许开票");
  2215. }
  2216. if (insPlyIncomeVo.getNoInvoicCommissionFeevalue().compareTo(BigDecimal.ZERO) == 0) {
  2217. throw new SystemException("未开票金额为0不允许开票");
  2218. }
  2219. if (insPlyIncomeVo.getSettlementAmount() == null || insPlyIncomeVo.getSettlementAmount().compareTo(BigDecimal.ZERO) <= 0) {
  2220. throw new SystemException("开票金额错误不允许开票");
  2221. }
  2222. if (insPlyIncomeVo.getNoInvoicCommissionFeevalue().compareTo(insPlyIncomeVo.getSettlementAmount()) < 0) {
  2223. throw new SystemException("开票金额必须小于未开票金额 不允许开票");
  2224. }
  2225. if (StringUtils.isNotEmpty(insPlyIncomeVo.getYear())) {
  2226. settlementDocumentaryFeesVo.setTimeFrame(insPlyIncomeVo.getYear());//年度
  2227. }
  2228. if (StringUtils.isNotEmpty(insPlyIncomeVo.getYear())) {
  2229. settlementDocumentaryFeesVo.setYear(insPlyIncomeVo.getYear());
  2230. }
  2231. if (StringUtils.isNotEmpty(insPlyIncomeVo.getMonth())) {
  2232. settlementDocumentaryFeesVo.setMonth(insPlyIncomeVo.getMonth());
  2233. }
  2234. if (StringUtils.isNotEmpty(insPlyIncomeVo.getDay())) {
  2235. settlementDocumentaryFeesVo.setDay(insPlyIncomeVo.getDay());
  2236. }
  2237. settlementDocumentaryFeesVo.setCompletionStatus("0");
  2238. settlementDocumentaryFeesVo.setInvoicedSettledAmount(BigDecimal.ZERO);
  2239. settlementDocumentaryFeesVo.setInvoicedNotSettledAmount(insPlyIncomeVo.getSettlementAmount());
  2240. settlementDocumentaryFeesVo.setCompanyId(insPlyIncomeVo.getCompanyId());// 保险公司id
  2241. settlementDocumentaryFeesVo.setPartnerCompaniesId(insPlyIncomeVo.getPartnerCompaniesId()); //合作公司id
  2242. settlementDocumentaryFeesVo.setTotalAmount(insPlyIncomeVo.getOtherFeevalue()); //其他费用金额
  2243. settlementDocumentaryFeesVo.setUnsettledAmount(insPlyIncomeVo.getNoInvoicCommissionFeevalue().subtract(insPlyIncomeVo.getSettlementAmount())); //未结算
  2244. settlementDocumentaryFeesVo.setSettlementAmount(insPlyIncomeVo.getSettlementAmount());//已经开票
  2245. settlementDocumentaryFeesVo.setCreateTime(LocalDateTime.now());
  2246. settlementDocumentaryFeesVo.setAgreementType("2");
  2247. settlementDocumentaryFeesVo.setIds(insPlyIncomeVo.getIncomeIds());
  2248. settlementDocumentaryFeesVo.setSettlementStatus("1");
  2249. settlementDocumentaryFeesVo.setIsNotCar(insPlyIncomeVo.getIsNotCar());
  2250. if (StringUtils.isNotEmpty(insPlyIncomeVo.getContractId())) {
  2251. settlementDocumentaryFeesVo.setInvoiceId(insPlyIncomeVo.getContractId()); //开票号
  2252. }
  2253. settlementDocumentaryFeesVo.setHandlingFeesStatus(insPlyIncomeVo.getHandlingFeesStatus());
  2254. settlementDocumentaryFeesVo.setInvoicingMethod(insPlyIncomeVo.getInvoicingMethod()); //开票方式
  2255. settlementDocumentaryFeesVo.setTaxPoints(insPlyIncomeVo.getTaxPoints()); //税点
  2256. settlementDocumentaryFeesVo.setIds(insPlyIncomeVo.getIds());
  2257. // settlementDocumentaryFeesVo.setSigningTime(insPlyIncomeVo.getSettlementTime()); //签单日期
  2258. // 税点支出
  2259. if (BigDecimalUtils.nullToZero(insPlyIncomeVo.getTaxPoints()) != null && BigDecimalUtils.nullToZero(insPlyIncomeVo.getSettlementAmount()) != null) {
  2260. BigDecimal settlementAmount = insPlyIncomeVo.getSettlementAmount();
  2261. settlementDocumentaryFeesVo.setExpendAmount(settlementAmount.multiply(BigDecimal.ONE.subtract(insPlyIncomeVo.getTaxPoints().divide(new BigDecimal(100)))));
  2262. }
  2263. if(ObjectUtils.isNotEmpty(settlementDocumentaryFeesSumEntity)){
  2264. settlementDocumentaryFeesVo.setSettlementSumId(settlementDocumentaryFeesSumEntity.getId());
  2265. }
  2266. settlementDocumentaryFeesService.inertSettle(settlementDocumentaryFeesVo);
  2267. }
  2268. }
  2269. return HttpResult.ok();
  2270. }
  2271. @Override
  2272. public void batchUpdate(InsPlyIncomeVo insPlyIncomeVo) {
  2273. HashMap<String, Object> params = new HashMap<>();
  2274. params = this.saveParams(insPlyIncomeVo, params);
  2275. List<InsPlyIncome> list = this.baseMapper.queryNew(params);
  2276. for (InsPlyIncome item : list) {
  2277. item.setContractFileId(insPlyIncomeVo.getContractFileId());
  2278. item.setSettleOtherStatus("1");
  2279. baseMapper.updateById(item);
  2280. }
  2281. }
  2282. @Override
  2283. @Transactional
  2284. public HashMap<String, Object> bxImportOther(MultipartFile multipartFile, String isNotCar) {
  2285. HashMap<String, Object> resultMap = new HashMap<>();
  2286. List<HashMap<String, Object>> resultList = new ArrayList<>();
  2287. HashMap<String, Object> params = new HashMap<>();
  2288. BigDecimal allAmount = BigDecimal.ZERO;
  2289. params.put("isNotCar", isNotCar);
  2290. try {
  2291. List<InsBxOtherExcelDto> dtoList = ExcelEasypoiUtils.importExcel(multipartFile, InsBxOtherExcelDto.class, 0, 1, 1);
  2292. for (InsBxOtherExcelDto item : dtoList) {
  2293. if (StringUtils.isNotEmpty(item.getLicenseno())) {
  2294. params.put("licenseno", item.getLicenseno());
  2295. }
  2296. if (StringUtils.isNotEmpty(item.getPolicyno())) {
  2297. params.put("policyno", item.getPolicyno());
  2298. }
  2299. if (StringUtils.isNotEmpty(item.getSyPolicyno())) {
  2300. params.put("syPolicyno", item.getSyPolicyno());
  2301. }
  2302. params.put("handlingFeesStatus", "0");
  2303. // isOther
  2304. params.put("isOther", "1");
  2305. params.put("isNotCar", "0");
  2306. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  2307. if (item.getJqOtherCostsProportion() == null) {
  2308. item.setJqOtherCostsProportion(BigDecimal.ZERO);
  2309. }
  2310. if (item.getSyOtherCostsProportion() == null) {
  2311. item.setSyOtherCostsProportion(BigDecimal.ZERO);
  2312. }
  2313. if (byBxLicenseno.getJqOtherCostsProportion().compareTo(item.getJqOtherCostsProportion()) != 0 || byBxLicenseno.getSyOtherCostsProportion().compareTo(item.getSyOtherCostsProportion()) != 0) {
  2314. // 如果比例不相等
  2315. BigDecimal jqOtherCostsProportion = item.getJqOtherCostsProportion();
  2316. BigDecimal syOtherCostsProportion = item.getSyOtherCostsProportion();
  2317. BigDecimal divisor = new BigDecimal("1.06"); // 最好是使用字符串来避免精度损失
  2318. // 计算交强保费和商业保费(四舍五入到5位小数)
  2319. BigDecimal jqNoTaxPremium = byBxLicenseno.getJqPremium().divide(divisor, 5, RoundingMode.DOWN); // 交强保费 / 1.06
  2320. BigDecimal syNoTaxPremium = byBxLicenseno.getSyPremium().divide(divisor, 5, RoundingMode.DOWN); // 商业保费 / 1.06
  2321. // 计算交强跟单费用和商业跟单费用(不进行四舍五入,而是截断到5位小数)
  2322. BigDecimal jqOtherAmount = jqNoTaxPremium.multiply(item.getJqOtherCostsProportion().divide(new BigDecimal(100))).setScale(5, RoundingMode.DOWN);
  2323. // 交强跟单费用
  2324. BigDecimal syOtherAmount = syNoTaxPremium.multiply(item.getSyOtherCostsProportion().divide(new BigDecimal(100))).setScale(5, RoundingMode.DOWN);
  2325. byBxLicenseno.setJqOtherCostsPremium(jqOtherAmount);
  2326. byBxLicenseno.setSyOtherCostsPremium(syOtherAmount);
  2327. byBxLicenseno.setJqOtherCostsProportion(jqOtherCostsProportion);
  2328. byBxLicenseno.setSyOtherCostsProportion(syOtherCostsProportion);
  2329. byBxLicenseno.setOtherFeevalue(this.calculateTotal(jqOtherAmount, syOtherAmount, null));
  2330. byBxLicenseno.setOtherFeerate(this.calculateTotal(jqOtherCostsProportion, syOtherCostsProportion, null));
  2331. byBxLicenseno.setAllFeeValue(this.calculateTotal(jqOtherAmount, syOtherAmount, null));
  2332. byBxLicenseno.setUpdateUserId(BaseController.getUser().getId());
  2333. byBxLicenseno.setUpdateUserName(BaseController.getUser().getName());
  2334. baseMapper.updateById(byBxLicenseno);
  2335. HashMap<String, Object> map = new HashMap<>();
  2336. map.put("licenseno", item.getLicenseno());
  2337. map.put("policyno", item.getPolicyno());
  2338. map.put("syPolicyno", item.getSyPolicyno());
  2339. map.put("jqOtherCostsPremium", jqOtherAmount);
  2340. map.put("syOtherCostsPremium", syOtherAmount);
  2341. map.put("otherFeevalue", byBxLicenseno.getOtherFeevalue());
  2342. map.put("otherFeerate", byBxLicenseno.getOtherFeerate());
  2343. resultList.add(map);
  2344. allAmount = allAmount.add(jqOtherAmount).add(syOtherAmount);
  2345. }
  2346. }
  2347. resultMap.put("allAmount", allAmount);
  2348. resultMap.put("resultList", resultList);
  2349. } catch (IOException e) {
  2350. throw new RuntimeException(e);
  2351. }
  2352. return resultMap;
  2353. }
  2354. @Override
  2355. @Transactional
  2356. public HashMap<String, Object> noBxImportOther(MultipartFile multipartFile, String isNotCar) {
  2357. HashMap<String, Object> resultMap = new HashMap<>();
  2358. List<HashMap<String, Object>> resultList = new ArrayList<>();
  2359. HashMap<String, Object> params = new HashMap<>();
  2360. BigDecimal allAmount = BigDecimal.ZERO;
  2361. params.put("isNotCar", isNotCar);
  2362. try {
  2363. List<InsNoBxOtherExcelDto> dtoList = ExcelEasypoiUtils.importExcel(multipartFile, InsNoBxOtherExcelDto.class, 0, 1, 1);
  2364. for (InsNoBxOtherExcelDto item : dtoList) {
  2365. if (StringUtils.isNotEmpty(item.getLicenseno())) {
  2366. params.put("licenseno", item.getLicenseno());
  2367. }
  2368. if (StringUtils.isNotEmpty(item.getNoPolicyno())) {
  2369. params.put("noPolicyno", item.getNoPolicyno());
  2370. }
  2371. params.put("handlingFeesStatus", "0");
  2372. params.put("isNotCar", "1");
  2373. params.put("isOther", "1");
  2374. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  2375. if (byBxLicenseno.getNoOtherCostsProportion().compareTo(item.getNoOtherCostsProportion()) != 0) {
  2376. HashMap<String, Object> newMap = new HashMap<>();
  2377. // 如果比例不相等
  2378. BigDecimal noOtherCostsProportion = item.getNoOtherCostsProportion();
  2379. BigDecimal noNoTaxPremium = byBxLicenseno.getNoPremium();
  2380. BigDecimal divisor = new BigDecimal("1.06"); // 最好是使用字符串来避免精度损失
  2381. BigDecimal noPremium = noNoTaxPremium.divide(divisor, 5, RoundingMode.DOWN);//交强保费 / 1.06
  2382. BigDecimal noOtherAmount = noPremium.multiply(item.getNoOtherCostsProportion().divide(new BigDecimal(100))).setScale(5, RoundingMode.DOWN); //交强跟单费用
  2383. byBxLicenseno.setNoOtherCostsPremium(noOtherAmount);
  2384. byBxLicenseno.setNoOtherCostsProportion(item.getNoOtherCostsProportion());
  2385. byBxLicenseno.setAllFeeValue(this.calculateTotal(noOtherAmount, null, null));
  2386. byBxLicenseno.setOtherFeevalue(this.calculateTotal(noOtherAmount, null, null));
  2387. byBxLicenseno.setOtherFeerate(this.calculateTotal(noOtherCostsProportion, null, null));
  2388. baseMapper.updateById(byBxLicenseno);
  2389. newMap.put("licenseno", item.getLicenseno());
  2390. newMap.put("noPolicyno", item.getNoPolicyno());
  2391. newMap.put("noOtherCostsPremium", noOtherAmount);
  2392. newMap.put("otherFeevalue", byBxLicenseno.getOtherFeevalue());
  2393. newMap.put("otherFeerate", byBxLicenseno.getOtherFeerate());
  2394. resultList.add(newMap);
  2395. allAmount = allAmount.add(noOtherAmount);
  2396. }
  2397. }
  2398. resultMap.put("allAmount", allAmount);
  2399. resultMap.put("resultList", resultList);
  2400. } catch (IOException e) {
  2401. throw new RuntimeException(e);
  2402. }
  2403. return resultMap;
  2404. }
  2405. @Override
  2406. public void batchUpdateVoucher(InsPlyIncomeVo insPlyIncomeVo) {
  2407. String s = insPlyIncomeVo.getSelectIds().get(0);
  2408. ImportResult importResult = importAsyncService.getById(s);
  2409. String[] split = importResult.getIds().split(",");
  2410. InsPlyIncome insPlyIncome = new InsPlyIncome();
  2411. for (String id : split) {
  2412. insPlyIncome.setId(id);
  2413. insPlyIncome.setSettlementImageId(insPlyIncomeVo.getSettlementImageId());
  2414. insPlyIncome.setSettleOtherStatus("1");
  2415. baseMapper.updateById(insPlyIncome);
  2416. }
  2417. }
  2418. /**
  2419. * 通过任务id 去查询关联表
  2420. *
  2421. * @param insPlyIncomeVo
  2422. * @return
  2423. */
  2424. @Override
  2425. public HttpResult<Object> reconciliation(InsPlyIncomeVo insPlyIncomeVo) {
  2426. String taskId = insPlyIncomeVo.getTaskId();
  2427. List<String> incomeIdList = incomeTaskRelationshipService.getByTaskId(taskId);
  2428. for (String incomeId : incomeIdList) {
  2429. InsPlyIncome insPlyIncome = baseMapper.getById(incomeId);
  2430. insPlyIncome.setSettleOtherStatus("1");
  2431. insPlyIncome.setSettlementImageId(insPlyIncomeVo.getSettlementImageId());
  2432. baseMapper.updateById(insPlyIncome);
  2433. }
  2434. return HttpResult.ok();
  2435. }
  2436. /**
  2437. * @version
  2438. * @author: hxl
  2439. * @Date: 2024/6/18 10:14
  2440. * @Description: 通过保险公司id和状态查询平台的记录
  2441. */
  2442. @Override
  2443. public List<PlatformSettlementRecordDto> platformSettlementRecord(InsPlyIncomeVo insPlyIncomeVo) {
  2444. if(insPlyIncomeVo.getPartnerCompaniesId()==null || "".equals(insPlyIncomeVo.getPartnerCompaniesId())){
  2445. throw new SystemException("合作公司编码(partnerCompaniesId)不能为空");
  2446. }
  2447. if(insPlyIncomeVo.getHandlingFeesStatus()==null || "".equals(insPlyIncomeVo.getHandlingFeesStatus())){
  2448. throw new SystemException("结算状态 0 未结算 1已结算(handlingFeesStatus)不能为空");
  2449. }
  2450. return baseMapper.platformSettlementRecord(insPlyIncomeVo.getPartnerCompaniesId(),insPlyIncomeVo.getHandlingFeesStatus());
  2451. }
  2452. /**
  2453. * @param insPlyIncomeVo
  2454. * @Description: 平台新增
  2455. * @return InsPlyIncome
  2456. */
  2457. @Override
  2458. public HttpResult<InsPlyIncome> ptInsert(InsPlyIncomeVo insPlyIncomeVo) {
  2459. InsPlyIncome insPlyIncome = new InsPlyIncome();
  2460. DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
  2461. String agreementId = insPlyIncomeVo.getAgreementId();
  2462. if(StringUtils.isNotEmpty(agreementId)){
  2463. HttpResult<PtlAgreementQueryVo> byAgreementId = ptlAgreementService.getByAgreementId(agreementId);
  2464. if(byAgreementId!=null && ObjectUtils.isNotEmpty(byAgreementId.getData())){
  2465. PtlAgreementQueryVo data = byAgreementId.getData();
  2466. PtlAgreement agreement = data.getAgreement();
  2467. if(ObjectUtils.isNotEmpty(agreement)){
  2468. insPlyIncomeVo.setPartnerCompaniesId(agreement.getPartnerCompaniesId());
  2469. insPlyIncomeVo.setCompanyId(agreement.getInsuranceCompanyId());
  2470. }
  2471. }
  2472. }
  2473. BeanUtils.copyProperties(insPlyIncomeVo, insPlyIncome);
  2474. if (StringUtils.isNotEmpty(insPlyIncome.getPartnerCompaniesId())) {
  2475. // 合作公司id
  2476. String partnerCompaniesId = insPlyIncome.getPartnerCompaniesId();
  2477. insPlyIncome.setPartnerCompaniesId(partnerCompaniesId);
  2478. EsmInsCompany esmInsCompany = EsmInsCompanyService.getById(partnerCompaniesId);
  2479. String name = esmInsCompany.getNamesimple(); //合作名称
  2480. insPlyIncome.setPartnerCompaniesName(name);
  2481. insPlyIncome.setPartnerCompaniesId(insPlyIncome.getPartnerCompaniesId());
  2482. }
  2483. if (StringUtils.isNotEmpty(insPlyIncome.getCompanyId())) {
  2484. String insuranceCompanyId = insPlyIncome.getCompanyId();
  2485. EsmInsCompany esmInsCompany = EsmInsCompanyService.getById(insuranceCompanyId);
  2486. String name = esmInsCompany.getNamesimple(); //保险公司名称 简称
  2487. insPlyIncome.setCompanyName(name);
  2488. }
  2489. insPlyIncome.setCreateTime(LocalDate.now());
  2490. insPlyIncome.setAgreementType("1");
  2491. insPlyIncome.setHandlingFeesStatus("0");
  2492. insPlyIncome.setIsNotCar("0");
  2493. insPlyIncome.setIsNotDocumentary("0");
  2494. insPlyIncome.setDocumentaryFeesStatus("0");
  2495. insPlyIncome.setAllFeeValue(insPlyIncome.getReceivableAmount());
  2496. if(StringUtils.isNotEmpty(insPlyIncomeVo.getSignDate())){
  2497. insPlyIncome.setSignDate(LocalDateTime.parse(insPlyIncomeVo.getSignDate(), formatter));
  2498. }
  2499. baseMapper.insert(insPlyIncome);
  2500. return HttpResult.ok();
  2501. }
  2502. }