InsPlyIncomeServiceImpl.java 108 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016
  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 cn.hutool.core.bean.BeanUtil;
  5. import cn.hutool.core.text.StrBuilder;
  6. import com.alibaba.fastjson.JSONArray;
  7. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  8. import com.fasterxml.jackson.core.JsonProcessingException;
  9. import com.fasterxml.jackson.databind.JsonNode;
  10. import com.fasterxml.jackson.databind.ObjectMapper;
  11. import com.github.pagehelper.PageHelper;
  12. import com.github.pagehelper.PageInfo;
  13. import com.ydtech.constants.enums.dict.agreement.ProductsType;
  14. import com.ydtech.core.page.HttpResult;
  15. import com.ydtech.exception.SystemException;
  16. import com.ydtech.modules.base.controller.BaseController;
  17. import com.ydtech.modules.esm.model.EsmInsCompany;
  18. import com.ydtech.modules.esm.service.EsmInsCompanyService;
  19. import com.ydtech.modules.fnc.entity.*;
  20. import com.ydtech.modules.fnc.dao.InsPlyIncomeMapper;
  21. import com.ydtech.modules.fnc.service.ImportAsyncService;
  22. import com.ydtech.modules.fnc.service.InsPlyIncomeService;
  23. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  24. import com.ydtech.modules.fnc.service.SettlementDocumentaryFeesService;
  25. import com.ydtech.modules.fnc.service.SettlementDocumentaryLogService;
  26. import com.ydtech.modules.fnc.vo.InsPlyIncomeVo;
  27. import com.ydtech.modules.fnc.vo.SettlementDocumentaryFeesVo;
  28. import com.ydtech.modules.ins.model.vo.res.*;
  29. import com.ydtech.modules.inv.model.InvChannelsExternalBillsDetails;
  30. import com.ydtech.modules.inv.model.dto.*;
  31. import com.ydtech.modules.inv.model.excel.InvDisburseExcel;
  32. import com.ydtech.modules.inv.utils.EasyExcelUtils;
  33. import com.ydtech.modules.order.entity.BasePageResult;
  34. import com.ydtech.modules.order.entity.InsOrders;
  35. import com.ydtech.modules.order.service.InsAreaCompanyService;
  36. import com.ydtech.modules.order.service.InsOrdersService;
  37. import com.ydtech.modules.protocol.entity.po.PtlAgreement;
  38. import com.ydtech.modules.protocol.entity.vo.PtlAgreementQueryVo;
  39. import com.ydtech.modules.protocol.service.PtlAgreementService;
  40. import com.ydtech.modules.protocols.entity.po.InsFeeOrderNew;
  41. import com.ydtech.modules.protocols.service.InsFeeOrderNewService;
  42. import com.ydtech.utils.BigDecimalUtils;
  43. import com.ydtech.utils.SnowFlakeUtil;
  44. import com.ydtech.utils.StringOperations;
  45. import com.ydtech.utils.excel.ExcelEasypoiUtils;
  46. import com.ydtech.utils.excel.ExcelStyleUtil;
  47. import com.ydtech.utils.excel.ExcelUtils2;
  48. import lombok.extern.slf4j.Slf4j;
  49. import org.apache.commons.lang3.ObjectUtils;
  50. import org.apache.commons.lang3.StringUtils;
  51. import org.apache.poi.ss.formula.functions.Now;
  52. import org.springframework.beans.BeanUtils;
  53. import org.springframework.beans.factory.annotation.Autowired;
  54. import org.springframework.beans.factory.annotation.Value;
  55. import org.springframework.context.annotation.Lazy;
  56. import org.springframework.stereotype.Service;
  57. import org.springframework.transaction.annotation.Transactional;
  58. import org.springframework.util.CollectionUtils;
  59. import org.springframework.web.multipart.MultipartFile;
  60. import redis.clients.jedis.params.Params;
  61. import javax.servlet.http.HttpServletRequest;
  62. import javax.servlet.http.HttpServletResponse;
  63. import java.awt.image.BandedSampleModel;
  64. import java.io.IOException;
  65. import java.math.BigDecimal;
  66. import java.nio.file.Files;
  67. import java.nio.file.Path;
  68. import java.nio.file.Paths;
  69. import java.time.LocalDate;
  70. import java.time.LocalDateTime;
  71. import java.time.YearMonth;
  72. import java.util.*;
  73. import java.util.concurrent.CompletableFuture;
  74. import java.util.concurrent.ConcurrentHashMap;
  75. import java.util.stream.Collectors;
  76. /**
  77. * <p>
  78. * 保司结算手续费 服务实现类
  79. * </p>
  80. *
  81. * @author gws
  82. * @since 2024-01-05
  83. */
  84. @Slf4j
  85. @Service
  86. public class InsPlyIncomeServiceImpl extends ServiceImpl<InsPlyIncomeMapper, InsPlyIncome> implements InsPlyIncomeService {
  87. @Autowired
  88. @Lazy
  89. private InsOrdersService insOrdersService;
  90. @Autowired
  91. private InsAreaCompanyService insAreaCompanyService;
  92. @Autowired
  93. private InsFeeOrderNewService insFeeOrderNewService;
  94. @Autowired
  95. private SettlementDocumentaryFeesService settlementDocumentaryFeesService;
  96. @Autowired
  97. private SettlementDocumentaryLogService settlementDocumentaryLogService;
  98. @Autowired
  99. private PtlAgreementService ptlAgreementService;
  100. @Autowired
  101. private EsmInsCompanyService EsmInsCompanyService;
  102. @Autowired
  103. private ImportAsyncService importAsyncService;
  104. @Value("${upload.file.path}")
  105. private String uploadPath;
  106. @Value("${upload.file.url}")
  107. private String uploadUrl;
  108. public HttpResult<BasePageResult<InsPlyIncome>> queryplyIncome(InsPlyIncomeVo insPlyIncomeVo){
  109. try{
  110. Page<InsOrders> page = new Page<>(insPlyIncomeVo.getPageNum(), insPlyIncomeVo.getPageSize());
  111. PageInfo<List<InsPlyIncome>> pageHelper = null;
  112. PageHelper.startPage(insPlyIncomeVo.getPageNum(),insPlyIncomeVo.getPageSize());
  113. List<InsPlyIncome> list= this.baseMapper.selectByCondition(insPlyIncomeVo);
  114. pageHelper=new PageInfo(list);
  115. BasePageResult<InsPlyIncome> pageResult=new BasePageResult<InsPlyIncome>(insPlyIncomeVo.getPageNum(), 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. insPlyIncome.setDeptId(insFeeOrderNew.getDeptId());
  158. this.saveRiskCode(order.getProductid(),insPlyIncome);
  159. insPlyIncome.setPayDate(insAreaCompany.getPayDate());
  160. insPlyIncome.setSignDate(insAreaCompany.getSigningTime());
  161. insPlyIncome.setCompanyId(insAreaCompany.getCompanyId());
  162. insPlyIncome.setAgreementId(insFeeOrderNew.getAgreementId());
  163. insPlyIncome.setLicenseno(order.getLicenseno());
  164. insPlyIncome.setTaxamount(insAreaCompany.getTaxamount());
  165. insPlyIncome.setCreateTime(LocalDate.now());
  166. insPlyIncome.setDocumentaryFeesStatus("0");
  167. insPlyIncome.setHandlingFeesStatus("0");
  168. insPlyIncome.setNoNoTaxPremium(insPlyIncome.getNoNoTaxPremium());
  169. insPlyIncome.setNoPremium(insPlyIncome.getNoPremium());
  170. insPlyIncome.setIsNotCar("1");
  171. insPlyIncome.setIsNotDocumentary("1");
  172. insPlyIncome.setJqStartDate(insAreaCompany.getJqStartDate());
  173. insPlyIncome.setJqEndDate(insAreaCompany.getJqEndDate());
  174. insPlyIncome.setSyStartDate(insAreaCompany.getSyStartDate());
  175. insPlyIncome.setSyEndDate(insAreaCompany.getSyEndDate());
  176. insPlyIncome.setAllFeeValue(insFeeOrderNew.getNoOtherCostsPremiums());
  177. this.saveByCompanyId(insFeeOrderNew ,insAreaCompany.getCompanyId(),insPlyIncome);
  178. baseMapper.insert(insPlyIncome);
  179. }
  180. private void saveNoSupervise(InsOrders order, InsFeeOrderNew insFeeOrderNew, InsAreaCompany insAreaCompany) {
  181. InsPlyIncome insPlyIncome = new InsPlyIncome();
  182. insPlyIncome.setOrderno(insFeeOrderNew.getInsOrderNo()); // 子订单号
  183. insPlyIncome.setCommissionFeevalue(insFeeOrderNew.getNoSuperviseCostsPremiums());// 非车手续费
  184. insPlyIncome.setCommissionFeerate(insFeeOrderNew.getNoSuperviseCostsProportion());// 非车手续费比例
  185. String noPolicyno = this.setNoPolicyno(insAreaCompany);
  186. if(StringUtils.isNotEmpty(noPolicyno)){
  187. insPlyIncome.setNoPolicyno(noPolicyno); // 非车保单号
  188. }
  189. insPlyIncome.setDeptId(insFeeOrderNew.getDeptId());
  190. this.saveRiskCode(order.getProductid(),insPlyIncome);
  191. insPlyIncome.setPayDate(insAreaCompany.getPayDate());
  192. insPlyIncome.setSignDate(insAreaCompany.getSigningTime());
  193. insPlyIncome.setCompanyId(insAreaCompany.getCompanyId());
  194. insPlyIncome.setAgreementId(insFeeOrderNew.getAgreementId());
  195. insPlyIncome.setLicenseno(order.getLicenseno());
  196. insPlyIncome.setTaxamount(insAreaCompany.getTaxamount());
  197. insPlyIncome.setCreateTime(LocalDate.now());
  198. insPlyIncome.setDocumentaryFeesStatus("0");
  199. insPlyIncome.setHandlingFeesStatus("0");
  200. insPlyIncome.setIsNotCar("1");
  201. insPlyIncome.setIsNotDocumentary("0");
  202. insPlyIncome.setAllFeeValue(insFeeOrderNew.getNoSuperviseCostsPremiums());
  203. insPlyIncome.setUserId(insFeeOrderNew.getUserId());
  204. insPlyIncome.setInsuredName(order.getInsuredname());
  205. insPlyIncome.setNoPremium(insFeeOrderNew.getNoPremium()); //非车保费
  206. insPlyIncome.setNoNoTaxPremium(insFeeOrderNew.getNoNoTaxPremium()); //非车不含税保费
  207. insPlyIncome.setJqStartDate(insAreaCompany.getJqStartDate());
  208. insPlyIncome.setJqEndDate(insAreaCompany.getJqEndDate());
  209. insPlyIncome.setSyStartDate(insAreaCompany.getSyStartDate());
  210. insPlyIncome.setSyEndDate(insAreaCompany.getSyEndDate());
  211. this.saveByCompanyId(insFeeOrderNew ,insAreaCompany.getCompanyId(),insPlyIncome);
  212. baseMapper.insert(insPlyIncome);
  213. }
  214. private void saveRiskCode(String productid,InsPlyIncome insPlyIncome) {
  215. if(ProductsType.PT_0330.getCode().equals(productid)){
  216. insPlyIncome.setRiskcode(ProductsType.PT_0330.getDesc());
  217. }
  218. if(ProductsType.PT_034001.getCode().equals(productid)){
  219. insPlyIncome.setRiskcode(ProductsType.PT_034001.getDesc());
  220. }
  221. if(ProductsType.PT_034002.getCode().equals(productid)){
  222. insPlyIncome.setRiskcode(ProductsType.PT_034002.getDesc());
  223. }
  224. if(ProductsType.PT_0330034002.getCode().equals(productid)){
  225. insPlyIncome.setRiskcode(ProductsType.PT_0330034002.getDesc());
  226. }
  227. if(ProductsType.PT_0330034001.getCode().equals(productid)){
  228. insPlyIncome.setRiskcode(ProductsType.PT_0330034001.getDesc());
  229. }
  230. }
  231. private void saveOtherAmount(InsOrders order, InsFeeOrderNew insFeeOrderNew, InsAreaCompany insAreaCompany) {
  232. BigDecimal otherAmount = this.calculateTotal(insFeeOrderNew.getJqOtherCostsPremiums(), insFeeOrderNew.getSyOtherCostsPremiums(),null);
  233. BigDecimal otherProportion = this.calculateTotal(insFeeOrderNew.getSyOtherCostsProportion(), insFeeOrderNew.getJqOtherCostsProportion(),null);
  234. BigDecimal allNoTaxPremium = this.calculateTotal(insFeeOrderNew.getJqNoTaxPremium(), insFeeOrderNew.getSyNoTaxPremium(), null); //交强不含税保费
  235. BigDecimal allPremium = this.calculateTotal(insFeeOrderNew.getJqPremium(), insFeeOrderNew.getSyPremium(), null);// 总保费
  236. InsPlyIncome insPlyIncome = new InsPlyIncome(insFeeOrderNew.getInsOrderNo(),insAreaCompany.getJqpolicyno(),insAreaCompany.getSypolicyno(),null,null,insFeeOrderNew.getDeptId(),null,order.getProductid(),insAreaCompany.getPayDate(),insAreaCompany.getSigningTime(),insAreaCompany.getCompanyId(),null,insFeeOrderNew.getAgreementId(),order.getLicenseno(),insAreaCompany.getTaxamount(),
  237. allNoTaxPremium,null,otherProportion,null,otherAmount,otherAmount,null,null,LocalDate.now(),null,null,null,"0","0","0","1");
  238. this.saveRiskCode(order.getProductid(),insPlyIncome);
  239. insPlyIncome.setTaxPremium(allPremium);
  240. insPlyIncome.setJqPremium(insFeeOrderNew.getJqPremium());
  241. insPlyIncome.setSyPremium(insFeeOrderNew.getSyPremium());
  242. insPlyIncome.setJqNoTaxPremium(insFeeOrderNew.getJqNoTaxPremium());
  243. insPlyIncome.setSyNoTaxPremium(insFeeOrderNew.getSyNoTaxPremium());
  244. insPlyIncome.setJqOtherCostsProportion(insFeeOrderNew.getJqOtherCostsProportion()); //交强跟单费比例
  245. insPlyIncome.setSyOtherCostsProportion(insFeeOrderNew.getSyOtherCostsProportion()); //商业跟单费比例
  246. insPlyIncome.setSyOtherCostsPremium(insFeeOrderNew.getSyOtherCostsPremiums());
  247. insPlyIncome.setJqOtherCostsPremium(insFeeOrderNew.getJqOtherCostsPremiums());
  248. insPlyIncome.setJqStartDate(insAreaCompany.getJqStartDate());
  249. insPlyIncome.setJqEndDate(insAreaCompany.getJqEndDate());
  250. insPlyIncome.setSyStartDate(insAreaCompany.getSyStartDate());
  251. insPlyIncome.setSyEndDate(insAreaCompany.getSyEndDate());
  252. insPlyIncome.setUserId(insFeeOrderNew.getUserId());
  253. insPlyIncome.setInsuredName(order.getInsuredname());
  254. this.saveByCompanyId(insFeeOrderNew ,insAreaCompany.getCompanyId(),insPlyIncome);
  255. baseMapper.insert(insPlyIncome);
  256. }
  257. private void saveInsuranceProcedures(InsOrders order, InsFeeOrderNew insFeeOrderNew, InsAreaCompany insAreaCompany) {
  258. // 保险手续费
  259. BigDecimal handlingAmount = this.calculateTotal(insFeeOrderNew.getJqSuperviseCostsPremiums(), insFeeOrderNew.getSySuperviseCostsPremiums(),null);
  260. BigDecimal handlingProportion = this.calculateTotal(insFeeOrderNew.getJqSuperviseCostsProportion(), insFeeOrderNew.getSySuperviseCostsProportion(),null);
  261. BigDecimal allNoTaxPremium = this.calculateTotal(insFeeOrderNew.getJqNoTaxPremium(), insFeeOrderNew.getSyNoTaxPremium(), null);//不含税保费
  262. InsPlyIncome insPlyIncome = new InsPlyIncome(insFeeOrderNew.getInsOrderNo(),insAreaCompany.getJqpolicyno(),insAreaCompany.getSypolicyno(),null,null,insFeeOrderNew.getDeptId(),null,order.getProductid(),insAreaCompany.getPayDate(),insAreaCompany.getSigningTime(),insAreaCompany.getCompanyId(),null,insFeeOrderNew.getAgreementId(),order.getLicenseno(),insAreaCompany.getTaxamount()
  263. ,allNoTaxPremium,handlingProportion,null,handlingAmount,null,handlingAmount,null,null,LocalDate.now(),null,null,null,"0","0","0","0");
  264. BigDecimal allTaxPremium = this.calculateTotal(insFeeOrderNew.getJqPremium(), insFeeOrderNew.getSyPremium(), null);
  265. insPlyIncome.setJqPremium(insFeeOrderNew.getJqPremium());
  266. insPlyIncome.setSyPremium(insFeeOrderNew.getSyPremium());
  267. insPlyIncome.setJqNoTaxPremium(insFeeOrderNew.getJqNoTaxPremium());
  268. insPlyIncome.setSyNoTaxPremium(insFeeOrderNew.getSyNoTaxPremium());
  269. insPlyIncome.setJqSuperviseCostsProportion(insFeeOrderNew.getJqSuperviseCostsProportion());
  270. insPlyIncome.setJqSuperviseCostsPremiums(insFeeOrderNew.getJqSuperviseCostsPremiums());
  271. insPlyIncome.setSySuperviseCostsProportion(insFeeOrderNew.getSySuperviseCostsProportion());
  272. insPlyIncome.setSySuperviseCostsPremiums(insFeeOrderNew.getSySuperviseCostsPremiums());
  273. this.saveRiskCode(order.getProductid(),insPlyIncome);
  274. insPlyIncome.setTaxPremium(allTaxPremium);
  275. insPlyIncome.setUserId(insFeeOrderNew.getUserId());
  276. insPlyIncome.setInsuredName(order.getInsuredname());
  277. insPlyIncome.setJqStartDate(insAreaCompany.getJqStartDate());
  278. insPlyIncome.setJqEndDate(insAreaCompany.getJqEndDate());
  279. insPlyIncome.setSyStartDate(insAreaCompany.getSyStartDate());
  280. insPlyIncome.setSyEndDate(insAreaCompany.getSyEndDate());
  281. this.saveByCompanyId(insFeeOrderNew ,insAreaCompany.getCompanyId(),insPlyIncome);
  282. baseMapper.insert(insPlyIncome);
  283. }
  284. private String setNoPolicyno(com.ydtech.modules.fnc.entity.InsAreaCompany insAreaCompany) {
  285. String crossInsurance = insAreaCompany.getCrossInsurance();
  286. if (StringUtils.isEmpty(crossInsurance)) {
  287. return null;
  288. }
  289. try {
  290. ObjectMapper objJson = new ObjectMapper();
  291. JsonNode jsonArryNode = objJson.readTree(crossInsurance);
  292. if (jsonArryNode.isArray() && jsonArryNode.size() > 0) {
  293. JsonNode firstNode = jsonArryNode.get(0);
  294. JsonNode policyNumberNode = firstNode.get("policyNumber");
  295. if (policyNumberNode != null) {
  296. return policyNumberNode.asText();
  297. } else {
  298. return firstNode.get("policy").asText();
  299. }
  300. }
  301. } catch (IOException e) {
  302. e.printStackTrace(); // 可以打印异常信息
  303. }
  304. return null;
  305. }
  306. private void savePinTai(InsOrders order, InsFeeOrderNew insFeeOrderNew, InsAreaCompany insAreaCompany) {
  307. BigDecimal handlingAmount = this.calculateTotal(insFeeOrderNew.getJqSuperviseCostsPremiums(), insFeeOrderNew.getSySuperviseCostsPremiums(),insFeeOrderNew.getNoSuperviseCostsPremiums()); //手续费
  308. BigDecimal handlingProportion = this.calculateTotal(insFeeOrderNew.getJqSuperviseCostsProportion(), insFeeOrderNew.getSySuperviseCostsProportion(),insFeeOrderNew.getNoSuperviseCostsProportion());//手续费比例
  309. BigDecimal otherAmount = this.calculateTotal(insFeeOrderNew.getJqOtherCostsPremiums(), insFeeOrderNew.getSyOtherCostsPremiums(),insFeeOrderNew.getNoOtherCostsPremiums());//跟单费
  310. BigDecimal otherProportion = this.calculateTotal(insFeeOrderNew.getSyOtherCostsProportion(), insFeeOrderNew.getJqOtherCostsProportion(),insFeeOrderNew.getNoOtherCostsProportion()); //跟单费比例
  311. // 不含税保费
  312. BigDecimal allNoTaxPremium = this.calculateTotal(insFeeOrderNew.getJqNoTaxPremium(), insFeeOrderNew.getSyNoTaxPremium(), insFeeOrderNew.getNoNoTaxPremium());
  313. BigDecimal allAmount = this.calculateTotal(otherAmount, handlingAmount, null);
  314. BigDecimal jqReceivableProportion = this.calculateTotal(insFeeOrderNew.getJqSuperviseCostsProportion(), insFeeOrderNew.getJqOtherCostsProportion(), null);// 交强应收 比例
  315. BigDecimal syReceivableProportion = this.calculateTotal(insFeeOrderNew.getSySuperviseCostsProportion(), insFeeOrderNew.getSyOtherCostsProportion(), null);//商业应收比例
  316. BigDecimal noReceivableProportion = this.calculateTotal(insFeeOrderNew.getNoSuperviseCostsProportion(), insFeeOrderNew.getNoOtherCostsProportion(), null);
  317. String noPolicyno = this.setNoPolicyno(insAreaCompany);
  318. InsPlyIncome insPlyIncome = new InsPlyIncome(insFeeOrderNew.getInsOrderNo(),insAreaCompany.getJqpolicyno(),insAreaCompany.getSypolicyno(),
  319. noPolicyno,null,insFeeOrderNew.getDeptId(), null,order.getProductid(),insAreaCompany.getPayDate(),insAreaCompany.getSigningTime(),insAreaCompany.getCompanyId(),
  320. null,insFeeOrderNew.getAgreementId(),order.getLicenseno(),insAreaCompany.getTaxamount(),allNoTaxPremium,handlingProportion,
  321. otherProportion,handlingAmount,otherAmount,allAmount,null,null,LocalDate.now(),null,null,null,"0","0","0","0");
  322. insPlyIncome.setJqReceivableProportion(jqReceivableProportion);
  323. insPlyIncome.setSyReceivableProportion(syReceivableProportion);
  324. insPlyIncome.setNoReceivableProportion(noReceivableProportion);
  325. // 应收金额 = 商业手续费+商业跟单 + 交强手续费 +交强跟单费 + 非车手续费 + 非车跟单费 = allAmount
  326. insPlyIncome.setJqSuperviseCostsPremiums(insFeeOrderNew.getJqSuperviseCostsPremiums()); // 交强手续费
  327. insPlyIncome.setSySuperviseCostsPremiums(insFeeOrderNew.getSySuperviseCostsPremiums()); // 商业手续费
  328. insPlyIncome.setNoSuperviseCostsPremiums(insFeeOrderNew.getNoSuperviseCostsPremiums()); // 非车手续费
  329. insPlyIncome.setJqSuperviseCostsProportion(insFeeOrderNew.getJqSuperviseCostsProportion()); //交强手续费 比例
  330. insPlyIncome.setSySuperviseCostsProportion(insFeeOrderNew.getSySuperviseCostsProportion()); // 商业手续费 比例
  331. insPlyIncome.setNoSuperviseCostsProportion(insFeeOrderNew.getNoSuperviseCostsProportion());// 非车手续费 比例
  332. insPlyIncome.setJqOtherCostsProportion(insFeeOrderNew.getJqOtherCostsProportion()); //交强跟单费比例
  333. insPlyIncome.setSyOtherCostsProportion(insFeeOrderNew.getSyOtherCostsProportion()); //商业跟单费比例
  334. insPlyIncome.setNoOtherCostsProportion(insFeeOrderNew.getNoOtherCostsProportion()); //非车跟单费比例
  335. insPlyIncome.setJqPremium(insFeeOrderNew.getJqPremium());
  336. insPlyIncome.setSyPremium(insFeeOrderNew.getSyPremium());
  337. insPlyIncome.setNoPremium(insFeeOrderNew.getNoPremium());
  338. insPlyIncome.setJqNoTaxPremium(insFeeOrderNew.getJqNoTaxPremium());
  339. insPlyIncome.setSyNoTaxPremium(insFeeOrderNew.getSyNoTaxPremium());
  340. insPlyIncome.setNoNoTaxPremium(insFeeOrderNew.getNoNoTaxPremium());
  341. insPlyIncome.setUserId(insFeeOrderNew.getUserId());
  342. insPlyIncome.setJqStartDate(StringOperations.emptyStringToNull(insAreaCompany.getJqStartDate()));
  343. insPlyIncome.setJqEndDate(StringOperations.emptyStringToNull(insAreaCompany.getJqEndDate()));
  344. insPlyIncome.setSyStartDate(StringOperations.emptyStringToNull(insAreaCompany.getSyStartDate()));
  345. insPlyIncome.setSyEndDate(StringOperations.emptyStringToNull(insAreaCompany.getSyEndDate()));
  346. this.saveRiskCode(order.getProductid(),insPlyIncome);
  347. insPlyIncome.setInsuredName(order.getInsuredname());
  348. this.saveByCompanyId(insFeeOrderNew ,insAreaCompany.getCompanyId(),insPlyIncome);
  349. baseMapper.insert(insPlyIncome);
  350. }
  351. private void saveByCompanyId(InsFeeOrderNew insFeeOrderNew,String companyId, InsPlyIncome insPlyIncome) {
  352. PtlAgreement ptlAgreementQueryVo = this.ptlAgreementService.getByAgreementIdNew(insFeeOrderNew.getAgreementId());
  353. if(ObjectUtils.isNotEmpty(ptlAgreementQueryVo)){
  354. if(StringUtils.isNotEmpty(ptlAgreementQueryVo.getPartnerCompaniesId())){
  355. // 合作公司id
  356. String partnerCompaniesId = ptlAgreementQueryVo.getPartnerCompaniesId();
  357. insPlyIncome.setPartnerCompaniesId(partnerCompaniesId);
  358. EsmInsCompany esmInsCompany = EsmInsCompanyService.getById(partnerCompaniesId);
  359. String name = esmInsCompany.getNamesimple(); //合作名称
  360. insPlyIncome.setPartnerCompaniesName(name);
  361. insPlyIncome.setPartnerCompaniesId(ptlAgreementQueryVo.getPartnerCompaniesId());
  362. }
  363. if(StringUtils.isNotEmpty(ptlAgreementQueryVo.getInsuranceCompanyId())){
  364. String insuranceCompanyId = ptlAgreementQueryVo.getInsuranceCompanyId();
  365. EsmInsCompany esmInsCompany = EsmInsCompanyService.getById(insuranceCompanyId);
  366. String name = esmInsCompany.getNamesimple(); //保险公司名称 简称
  367. insPlyIncome.setCompanyName(name);
  368. }
  369. }
  370. }
  371. private BigDecimal calculateTotal(BigDecimal value1, BigDecimal value2, BigDecimal value3) {
  372. BigDecimal total = BigDecimal.ZERO;
  373. if (value1 != null) {
  374. total = total.add(value1);
  375. }
  376. if (value2 != null) {
  377. total = total.add(value2);
  378. }
  379. if (value3 != null) {
  380. total = total.add(value3);
  381. }
  382. return total;
  383. }
  384. private String judgeAgreeType(Long agreementId) {
  385. if (agreementId == null) {
  386. return null;
  387. }
  388. HttpResult<PtlAgreementQueryVo> byAgreementId = ptlAgreementService.getByAgreementId(agreementId.toString());
  389. if (byAgreementId != null && ObjectUtils.isNotEmpty(byAgreementId.getData())) {
  390. PtlAgreement agreement = byAgreementId.getData().getAgreement();
  391. String agreementType = agreement.getAgreementType();
  392. if (StringUtils.isNotEmpty(agreementType)) {
  393. return agreementType;
  394. }
  395. }
  396. return null;
  397. }
  398. public HttpResult<BasePageResult<InsPlyIncome>> queryNew(InsPlyIncomeVo insPlyIncomeVo){
  399. try{
  400. HashMap<String, Object> params = new HashMap<>();
  401. PageInfo<List<InsPlyIncome>> pageHelper = null;
  402. PageHelper.startPage(insPlyIncomeVo.getPageNum(),insPlyIncomeVo.getPageSize());
  403. params.put("pageNum",insPlyIncomeVo.getPageNum());
  404. params.put("pageSize",insPlyIncomeVo.getPageSize());
  405. params =this.saveParams(insPlyIncomeVo,params);
  406. if(StringUtils.isNotEmpty(insPlyIncomeVo.getIds())){
  407. params.put("ids",insPlyIncomeVo.getIds().split(","));
  408. }
  409. List<InsPlyIncome> list= this.baseMapper.queryNew(params);
  410. pageHelper=new PageInfo(list);
  411. BasePageResult<InsPlyIncome> pageResult=new BasePageResult<InsPlyIncome>(insPlyIncomeVo.getPageNum(), insPlyIncomeVo.getPageSize(), pageHelper.getTotal(), pageHelper.getPages(), list);
  412. return HttpResult.ok(pageResult);
  413. }catch (Exception e){
  414. e.printStackTrace();
  415. return HttpResult.error("查询异常");
  416. }
  417. }
  418. @Override
  419. public HashMap<String,Object> totalAmount(List<String> selectIds) {
  420. HashMap<String, Object> params = new HashMap<>();
  421. params.put("selectIds",selectIds);
  422. HashMap<String,Object> resultMap =baseMapper.totalAmount(params);
  423. return resultMap;
  424. }
  425. @Override
  426. @Transactional
  427. public HttpResult<Object> batchPinBalance(InsPlyIncomeVo insPlyIncomeVo) {
  428. if(!CollectionUtils.isEmpty(insPlyIncomeVo.getSelectIds())){
  429. List<String> selectIds = insPlyIncomeVo.getSelectIds();
  430. for(String id: selectIds){
  431. InsPlyIncome insPlyIncome = new InsPlyIncome();
  432. insPlyIncome.setHandlingFeesStatus("1");
  433. insPlyIncome.setSettlementTime(LocalDate.now());
  434. insPlyIncome.setId(id);
  435. baseMapper.updateById(insPlyIncome);
  436. }
  437. }
  438. SettlementDocumentaryLogEntity settlementDocumentaryLogEntity = new SettlementDocumentaryLogEntity();
  439. settlementDocumentaryLogEntity.setIds(insPlyIncomeVo.getIds());
  440. // settlementDocumentaryLogEntity.setCompanyId(insPlyIncomeVo.getCompanyId());
  441. settlementDocumentaryLogEntity.setAmount(insPlyIncomeVo.getOtherFeevalue()); //跟单费金额
  442. settlementDocumentaryLogEntity.setHandingAmount(insPlyIncomeVo.getCommissionFeevalue()); //手续费金额
  443. settlementDocumentaryLogEntity.setCreateTime(new Date());
  444. settlementDocumentaryLogService.save(settlementDocumentaryLogEntity);
  445. return HttpResult.ok();
  446. }
  447. @Override
  448. public List<InsPlyIncome> totalPinAmount(InsPlyIncomeVo insPlyIncomeVo) {
  449. HashMap<String, Object> params = new HashMap<>();
  450. params = this.saveParams(insPlyIncomeVo,params);
  451. List<InsPlyIncome> result=baseMapper.totalPinAmount(params);
  452. return result;
  453. }
  454. private HashMap<String, Object> saveParams(InsPlyIncomeVo insPlyIncomeVo, HashMap<String, Object> params) {
  455. if(ObjectUtils.isNotEmpty(insPlyIncomeVo.getStartDate())){
  456. params.put("startDate",insPlyIncomeVo.getStartDate().toString());
  457. }
  458. if(ObjectUtils.isNotEmpty(insPlyIncomeVo.getEndDate())){
  459. params.put("endDate",insPlyIncomeVo.getEndDate().toString());
  460. }
  461. if(StringUtils.isNotEmpty(insPlyIncomeVo.getOrderno())){
  462. params.put("orderno",insPlyIncomeVo.getOrderno());
  463. }
  464. if(StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotDocumentary())){
  465. params.put("isOther",insPlyIncomeVo.getIsNotDocumentary());
  466. }
  467. if(StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotCar())){
  468. params.put("isNotCar",insPlyIncomeVo.getIsNotCar());
  469. }
  470. if(StringUtils.isNotEmpty(insPlyIncomeVo.getAgreementType())){
  471. params.put("agreementType",insPlyIncomeVo.getAgreementType());
  472. }
  473. if(StringUtils.isNotEmpty(insPlyIncomeVo.getLicenseno())){
  474. params.put("licenseno", insPlyIncomeVo.getLicenseno());
  475. }
  476. if(StringUtils.isNotEmpty(insPlyIncomeVo.getUserId())){
  477. params.put("userId",insPlyIncomeVo.getUserId());
  478. }
  479. if(StringUtils.isNotEmpty(insPlyIncomeVo.getCompanyId())){
  480. params.put("companyId",insPlyIncomeVo.getCompanyId());
  481. }
  482. if(StringUtils.isNotEmpty(insPlyIncomeVo.getRiskcode())){
  483. params.put("riskcode",insPlyIncomeVo.getRiskcode());
  484. }
  485. if(StringUtils.isNotEmpty(insPlyIncomeVo.getPolicyno())){
  486. params.put("policyno",insPlyIncomeVo.getPolicyno());
  487. }
  488. if(StringUtils.isNotEmpty(insPlyIncomeVo.getSyPolicyno())){
  489. params.put("syPolicyno",insPlyIncomeVo.getSyPolicyno());
  490. }
  491. if(StringUtils.isNotEmpty(insPlyIncomeVo.getNoPolicyno())){
  492. params.put("noPolicyno",insPlyIncomeVo.getNoPolicyno());
  493. }
  494. if(insPlyIncomeVo.getCreateTime()!=null){
  495. params.put("createTime",insPlyIncomeVo.getCreateTime().toString());
  496. }
  497. if(insPlyIncomeVo.getSettlementTime()!=null){
  498. params.put("settlementTime",insPlyIncomeVo.getSettlementTime().toString());
  499. }
  500. if(StringUtils.isNotEmpty(insPlyIncomeVo.getHandlingFeesStatus())){
  501. params.put("handlingFeesStatus",insPlyIncomeVo.getHandlingFeesStatus());
  502. }
  503. if(StringUtils.isNotEmpty(insPlyIncomeVo.getPartnerCompaniesId())){
  504. params.put("partnerCompaniesId",insPlyIncomeVo.getPartnerCompaniesId());
  505. }
  506. if(StringUtils.isNotEmpty(insPlyIncomeVo.getYear())){
  507. params.put("year",insPlyIncomeVo.getYear());
  508. }
  509. if(StringUtils.isNotEmpty(insPlyIncomeVo.getMonth())){
  510. params.put("month",insPlyIncomeVo.getMonth());
  511. }
  512. if(StringUtils.isNotEmpty(insPlyIncomeVo.getDay())){
  513. params.put("day",insPlyIncomeVo.getDay());
  514. }
  515. if(StringUtils.isNotEmpty(insPlyIncomeVo.getSignDateEnd())){
  516. params.put("signDateEnd",insPlyIncomeVo.getSignDateEnd());
  517. }
  518. if(StringUtils.isNotEmpty(insPlyIncomeVo.getSignDateStart())){
  519. params.put("signDateStart",insPlyIncomeVo.getSignDateStart());
  520. }
  521. if(StringUtils.isNotEmpty(insPlyIncomeVo.getCompanyName())){
  522. params.put("companyName",insPlyIncomeVo.getCompanyName());
  523. }
  524. if(StringUtils.isNotEmpty(insPlyIncomeVo.getInsuredName())){
  525. params.put("insuredName",insPlyIncomeVo.getInsuredName());
  526. }
  527. if(StringUtils.isNotEmpty(insPlyIncomeVo.getPartnerCompaniesName())){
  528. params.put("partnerCompaniesName",insPlyIncomeVo.getPartnerCompaniesName());
  529. }
  530. if(StringUtils.isNotEmpty(insPlyIncomeVo.getDockingPerson())){
  531. params.put("dockingPerson",insPlyIncomeVo.getDockingPerson());
  532. }
  533. if(StringUtils.isNotEmpty(insPlyIncomeVo.getYeartsStart()) && StringUtils.isNotEmpty(insPlyIncomeVo.getYeartsEnd())){
  534. params.put("yeartsStart",insPlyIncomeVo.getYeartsStart());
  535. params.put("yeartsEnd",insPlyIncomeVo.getYeartsEnd());
  536. }
  537. if(insPlyIncomeVo.getJqStartDate() !=null){
  538. params.put("jqStartDate",insPlyIncomeVo.getJqStartDate());
  539. }
  540. if(insPlyIncomeVo.getJqStartDate() !=null){
  541. params.put("jqEndDate",insPlyIncomeVo.getJqEndDate());
  542. }
  543. if(insPlyIncomeVo.getJqStartDate() !=null){
  544. params.put("syStartDate",insPlyIncomeVo.getSyStartDate());
  545. }
  546. if(insPlyIncomeVo.getJqStartDate() !=null){
  547. params.put("syEndDate",insPlyIncomeVo.getSyEndDate());
  548. }
  549. if( StringUtils.isNotEmpty(insPlyIncomeVo.getProvinceId())){
  550. params.put("provinceId",insPlyIncomeVo.getProvinceId());
  551. }
  552. if( StringUtils.isNotEmpty(insPlyIncomeVo.getCityId())){
  553. params.put("cityId",insPlyIncomeVo.getCityId());
  554. }
  555. if( StringUtils.isNotEmpty(insPlyIncomeVo.getCountyId())){
  556. params.put("countyId",insPlyIncomeVo.getCountyId());
  557. }
  558. if( StringUtils.isNotEmpty(insPlyIncomeVo.getDeptId())){
  559. params.put("deptId",insPlyIncomeVo.getDeptId());
  560. }
  561. if( StringUtils.isNotEmpty(insPlyIncomeVo.getAllPartnerCompaniesId())){
  562. params.put("allPartnerCompaniesId",insPlyIncomeVo.getAllPartnerCompaniesId());
  563. }
  564. if( StringUtils.isNotEmpty(insPlyIncomeVo.getProvincePartnerCompaniesId())){
  565. params.put("provincePartnerCompaniesId",insPlyIncomeVo.getProvincePartnerCompaniesId());
  566. }
  567. if(!CollectionUtils.isEmpty(insPlyIncomeVo.getSelectIds())){
  568. params.put("selectIds",insPlyIncomeVo.getSelectIds());
  569. }
  570. if(!CollectionUtils.isEmpty(insPlyIncomeVo.getPartnerCompaniesIdList())){
  571. params.put("partnerCompaniesIdList",insPlyIncomeVo.getPartnerCompaniesIdList());
  572. }
  573. return params;
  574. }
  575. @Override
  576. public HttpResult<BasePageResult<InsPlyIncome>> nonSettlementQuery(InsPlyIncomeVo insPlyIncomeVo) {
  577. try{
  578. HashMap<String, Object> params = new HashMap<>();
  579. PageInfo<List<InsPlyIncome>> pageHelper = null;
  580. PageHelper.startPage(insPlyIncomeVo.getPageNum(),insPlyIncomeVo.getPageSize());
  581. params.put("pageNum",insPlyIncomeVo.getPageNum());
  582. params.put("pageSize",insPlyIncomeVo.getPageSize());
  583. if(StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotCar())){
  584. params.put("isNotCar",insPlyIncomeVo.getIsNotCar());
  585. }
  586. if(StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotDocumentary())){
  587. params.put("isOther",insPlyIncomeVo.getIsNotDocumentary());
  588. }
  589. if(StringUtils.isNotEmpty(insPlyIncomeVo.getYear())){
  590. params.put("year",insPlyIncomeVo.getYear());
  591. }
  592. if(StringUtils.isNotEmpty(insPlyIncomeVo.getMonth())){
  593. params.put("month",insPlyIncomeVo.getMonth());
  594. }
  595. if(StringUtils.isNotEmpty(insPlyIncomeVo.getDocumentaryFeesStatus())){
  596. params.put("documentaryFeesStatus",insPlyIncomeVo.getDocumentaryFeesStatus());
  597. }
  598. List<InsPlyIncome> list= this.baseMapper.NonSettlementQuery(params);
  599. pageHelper=new PageInfo(list);
  600. BasePageResult<InsPlyIncome> pageResult=new BasePageResult<InsPlyIncome>(insPlyIncomeVo.getPageNum(), insPlyIncomeVo.getPageSize(), pageHelper.getTotal(), pageHelper.getPages(), list);
  601. return HttpResult.ok(pageResult);
  602. }catch (Exception e){
  603. e.printStackTrace();
  604. return HttpResult.error("查询异常");
  605. }
  606. }
  607. @Override
  608. public HttpResult<List<InsPlyIncome>> nonSettldetail(InsPlyIncomeVo insPlyIncomeVo) {
  609. try {
  610. String ids = insPlyIncomeVo.getIds();
  611. ArrayList<InsPlyIncome> resultList = new ArrayList<>();
  612. if (ObjectUtils.isNotEmpty(ids)) {
  613. String[] split = ids.split(",");
  614. for (int i =0; i <split.length ; i++) {
  615. String id = split[i];
  616. resultList.add(this.baseMapper.getById(id));
  617. }
  618. }
  619. return HttpResult.ok(resultList);
  620. } catch (Exception e) {
  621. e.printStackTrace();
  622. return HttpResult.error("查询异常");
  623. }
  624. }
  625. /**
  626. *
  627. * @param multipartFile
  628. * @return totalAmount 总金额
  629. * totalHandingAmount 总手续费金额
  630. * totalOtherAmount 总跟单费金额
  631. * resultHashMap 返回 ids 已经上面的金额
  632. * resultNoSelect 未匹配的车牌号
  633. */
  634. @Override
  635. public HashMap<String, Object> importData(MultipartFile multipartFile) {
  636. BigDecimal totalAmount=BigDecimal.ZERO;
  637. BigDecimal totalHandingAmount=BigDecimal.ZERO;
  638. BigDecimal totalOtherAmount=BigDecimal.ZERO;
  639. HashMap<String, Object> params = new HashMap<>();
  640. HashMap<String, Object> resultHashMap = new HashMap<>();
  641. ArrayList<HashMap<String,Object>> resultNoSelect = new ArrayList<>();
  642. try {
  643. List<InsPlyIncomeExcelDto> dtoList = ExcelEasypoiUtils.importExcel(multipartFile, InsPlyIncomeExcelDto.class, 0, 1, 1);
  644. for (InsPlyIncomeExcelDto excelItem : dtoList) {
  645. params.clear();
  646. if(StringUtils.isNotEmpty(excelItem.getLicenseno())){
  647. params.put("licenseno",excelItem.getLicenseno());//车牌号
  648. }
  649. if(StringUtils.isNotEmpty(excelItem.getPolicyno())){
  650. params.put("policyno",excelItem.getPolicyno()); //交强保单号
  651. }
  652. if(StringUtils.isNotEmpty(excelItem.getSyPolicyno())){
  653. params.put("syPolicyno", excelItem.getSyPolicyno());//商业保单号
  654. }
  655. if(StringUtils.isNotEmpty(excelItem.getNoPolicyno())){
  656. params.put("noPolicyno",excelItem.getNoPolicyno()); //非车保单号
  657. }
  658. InsPlyIncome insPlyIncome=baseMapper.findByLicenseno(params);
  659. if(ObjectUtils.isNotEmpty(insPlyIncome)){
  660. if(insPlyIncome.getAllFeeValue()!=null && insPlyIncome.getAllFeeValue().compareTo(BigDecimal.ZERO)!=0){
  661. totalAmount = totalAmount.add(insPlyIncome.getAllFeeValue()); //总金额
  662. }
  663. if(insPlyIncome.getCommissionFeevalue()!=null && insPlyIncome.getCommissionFeevalue().compareTo(BigDecimal.ZERO)!=0){
  664. totalHandingAmount=totalHandingAmount.add(insPlyIncome.getCommissionFeevalue()); //总手续费
  665. }
  666. if(insPlyIncome.getOtherFeevalue()!=null && insPlyIncome.getOtherFeevalue().compareTo(BigDecimal.ZERO)!=0){
  667. totalOtherAmount=totalOtherAmount.add(insPlyIncome.getOtherFeevalue()); //总跟单费
  668. }
  669. }else {
  670. resultNoSelect.add(params); // 添加未匹配的车牌号
  671. }
  672. }
  673. resultHashMap.put("totalAmount",totalAmount);
  674. resultHashMap.put("totalHandingAmount",totalHandingAmount);
  675. resultHashMap.put("totalOtherAmount",totalOtherAmount);
  676. resultHashMap.put("resultList",resultNoSelect);
  677. return resultHashMap;
  678. } catch (IOException e) {
  679. throw new SystemException("导入失败!");
  680. }
  681. }
  682. /**
  683. *
  684. * @param multipartFile
  685. * @return resultList 包含总金额 还有 未匹配表中的数据
  686. */
  687. @Override
  688. public HashMap<String, Object> bxImportData(MultipartFile multipartFile,String isNotCar) {
  689. BigDecimal totalAmount=BigDecimal.ZERO;
  690. HashMap<String, Object> params = new HashMap<>();
  691. ArrayList<HashMap<String, Object>> resultList = new ArrayList<>();
  692. HashMap<String, Object> resultMap = new HashMap<>();
  693. StringBuffer strBuilder = new StringBuffer();
  694. boolean open=true;
  695. String ids="";
  696. try {
  697. List<InsBxPlyIncomeExcelDto> dtoList = ExcelEasypoiUtils.importExcel(multipartFile, InsBxPlyIncomeExcelDto.class, 0, 1, 1);
  698. Integer i=0;
  699. if(!CollectionUtils.isEmpty(dtoList)){
  700. for (InsBxPlyIncomeExcelDto excelItem : dtoList) {
  701. String reason ="";
  702. i=i+1;
  703. params.clear();
  704. if(StringUtils.isNotEmpty(excelItem.getLicenseno())){
  705. String licenseno = excelItem.getLicenseno();//车牌号
  706. params.put("licenseno",licenseno);
  707. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  708. if(ObjectUtils.isEmpty(byBxLicenseno)){
  709. reason="该数据车牌号有问题";
  710. }
  711. }
  712. if(StringUtils.isNotEmpty(excelItem.getPolicyno())){
  713. String policyno = excelItem.getPolicyno(); //交强保单号
  714. params.put("policyno",policyno);
  715. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  716. if(ObjectUtils.isEmpty(byBxLicenseno)){
  717. reason="该数据交强保单号有问题";
  718. }
  719. }
  720. if(StringUtils.isNotEmpty(excelItem.getSyPolicyno())){
  721. String syPolicyno = excelItem.getSyPolicyno(); //商业保单号
  722. params.put("syPolicyno",syPolicyno);
  723. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  724. if(ObjectUtils.isEmpty(byBxLicenseno)){
  725. reason="该数据商业保单号有问题";
  726. }
  727. }
  728. if(excelItem.getJqSuperviseCostsPremiums() !=null && excelItem.getJqSuperviseCostsPremiums().compareTo(BigDecimal.ZERO)!=0){
  729. params.put("jqSuperviseCostsPremiums",excelItem.getJqSuperviseCostsPremiums());
  730. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  731. if(ObjectUtils.isEmpty(byBxLicenseno)){
  732. reason="该数据交强手续费金额有问题";
  733. }
  734. }
  735. if(excelItem.getJqSuperviseCostsProportion() !=null && excelItem.getJqSuperviseCostsProportion().compareTo(BigDecimal.ZERO)!=0){
  736. params.put("jqSuperviseCostsProportion",excelItem.getJqSuperviseCostsProportion());
  737. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  738. if(ObjectUtils.isEmpty(byBxLicenseno)){
  739. reason="该数据交强手续费比例有问题";
  740. }
  741. }
  742. if(excelItem.getSySuperviseCostsProportion() !=null && excelItem.getSySuperviseCostsProportion().compareTo(BigDecimal.ZERO)!=0){
  743. params.put("sySuperviseCostsProportion",excelItem.getSySuperviseCostsProportion());
  744. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  745. if(ObjectUtils.isEmpty(byBxLicenseno)){
  746. reason="该数据商业手续费比例有问题";
  747. }
  748. }
  749. if(excelItem.getSySuperviseCostsPremiums() !=null && excelItem.getSySuperviseCostsPremiums().compareTo(BigDecimal.ZERO)!=0){
  750. params.put("sySuperviseCostsPremiums",excelItem.getSySuperviseCostsPremiums());
  751. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  752. if(ObjectUtils.isEmpty(byBxLicenseno)){
  753. reason="该数据商业手续费金额有问题";
  754. }
  755. }
  756. if(excelItem.getJqPremium() !=null && excelItem.getJqPremium().compareTo(BigDecimal.ZERO)!=0){
  757. params.put("jqPremium",excelItem.getJqPremium());
  758. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  759. if(ObjectUtils.isEmpty(byBxLicenseno)){
  760. reason="该数据交强保费有问题";
  761. }
  762. }
  763. if(excelItem.getSyPremium() !=null && excelItem.getSyPremium().compareTo(BigDecimal.ZERO)!=0){
  764. params.put("syPremium",excelItem.getSyPremium());
  765. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  766. if(ObjectUtils.isEmpty(byBxLicenseno)){
  767. reason="该数据商业保费有问题";
  768. }
  769. }
  770. // 只查手续费
  771. params.put("isOther","0");
  772. params.put("isNotCar",isNotCar);
  773. InsPlyIncome insPlyIncome = baseMapper.findByBxLicenseno(params);
  774. if(ObjectUtils.isNotEmpty(insPlyIncome) && open){
  775. open=false;
  776. resultMap.put("companyId",insPlyIncome.getCompanyId()); // 保险公司id
  777. resultMap.put("partnerCompaniesId",insPlyIncome.getPartnerCompaniesId()); //合作公司id
  778. resultMap.put("agreementId",insPlyIncome.getAgreementId()); //协议id
  779. }
  780. if(ObjectUtils.isNotEmpty(insPlyIncome)){ // 比配上汇总金额 未匹配则返回到数据当中
  781. strBuilder.append(insPlyIncome.getId()).append(",");
  782. if( insPlyIncome.getCommissionFeevalue()!=null && insPlyIncome.getCommissionFeevalue().compareTo(BigDecimal.ZERO)!=0){
  783. totalAmount = totalAmount.add(insPlyIncome.getCommissionFeevalue()); //添加总手续费
  784. }
  785. }else {
  786. HashMap<String, Object> noMatching = new HashMap<>();
  787. if(StringUtils.isNotEmpty(excelItem.getLicenseno())){
  788. noMatching.put("licenseno",excelItem.getLicenseno());
  789. }
  790. if(StringUtils.isNotEmpty(excelItem.getPolicyno())){
  791. noMatching.put("policyno",excelItem.getPolicyno());
  792. }
  793. if(StringUtils.isNotEmpty(excelItem.getSyPolicyno())){
  794. noMatching.put("syPolicyno",excelItem.getSyPolicyno());
  795. }
  796. resultList.add(noMatching);
  797. }
  798. resultMap.put("reason",reason);
  799. }
  800. }
  801. if(strBuilder.length() >0){
  802. ids = strBuilder.deleteCharAt(strBuilder.length() - 1).toString();
  803. }
  804. resultMap.put("ids",ids);
  805. resultMap.put("totalAmount",totalAmount);
  806. resultMap.put("resultList",resultList);
  807. return resultMap;
  808. } catch (IOException e) {
  809. throw new SystemException("导入失败!");
  810. }
  811. }
  812. @Override
  813. public HashMap<String, Object> bxImportNoData(MultipartFile multipartFile,String isNotCar) {
  814. BigDecimal totalAmount=BigDecimal.ZERO;
  815. HashMap<String, Object> params = new HashMap<>();
  816. HashMap<String, Object> resultMap = new HashMap<>();
  817. ArrayList<HashMap<String, Object>> resultList = new ArrayList<>();
  818. StringBuffer strBuilder = new StringBuffer();
  819. String ids="";
  820. try {
  821. Integer i=0;
  822. List<InsBxNoPlyIncomeExcelDto> dtoList = ExcelEasypoiUtils.importExcel(multipartFile, InsBxNoPlyIncomeExcelDto.class, 0, 1, 1);
  823. if(!CollectionUtils.isEmpty(dtoList)){
  824. for (InsBxNoPlyIncomeExcelDto excelItem : dtoList) {
  825. String reason ="";
  826. i=i+1;
  827. params.clear();
  828. if(StringUtils.isNotEmpty(excelItem.getLicenseno())){
  829. String licenseno = excelItem.getLicenseno();//车牌号
  830. params.put("licenseno",licenseno);
  831. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  832. if(ObjectUtils.isEmpty(byBxLicenseno)){
  833. reason="该数据车牌号有问题";
  834. }
  835. }
  836. if(StringUtils.isNotEmpty(excelItem.getNoPolicyno())){
  837. String policyno = excelItem.getNoPolicyno(); //非车保单号
  838. params.put("NoPolicyno",policyno);
  839. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  840. if(ObjectUtils.isEmpty(byBxLicenseno)){
  841. reason="该数据非车保单号有问题";
  842. }
  843. }
  844. if(excelItem.getNoPremium() !=null && excelItem.getNoPremium().compareTo(BigDecimal.ZERO)!=0){
  845. params.put("noPolicyno",excelItem.getNoPremium());
  846. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  847. if(ObjectUtils.isEmpty(byBxLicenseno)){
  848. reason="该数据非车保费有问题";
  849. }
  850. }
  851. if( excelItem.getNoSuperviseCostsPremiums() !=null && excelItem.getNoSuperviseCostsPremiums().compareTo(BigDecimal.ZERO)!=0){
  852. params.put("noSuperviseCostsPremiums",excelItem.getNoSuperviseCostsPremiums());
  853. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  854. if(ObjectUtils.isEmpty(byBxLicenseno)){
  855. reason="该数据非车手续费有问题";
  856. }
  857. }
  858. if(excelItem.getNoSuperviseCostsProportion() != null && excelItem.getNoSuperviseCostsProportion().compareTo(BigDecimal.ZERO)!=0){
  859. params.put("noSuperviseCostsProportion",excelItem.getNoSuperviseCostsProportion());
  860. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  861. if(ObjectUtils.isEmpty(byBxLicenseno)){
  862. reason="该数据非车手续费比例有问题";
  863. }
  864. }
  865. // 只查手续费
  866. params.put("isOther","0");
  867. params.put("isNotCar",isNotCar);
  868. InsPlyIncome insPlyIncome = baseMapper.findByBxLicenseno(params);
  869. if(i==dtoList.size() && ObjectUtils.isNotEmpty(insPlyIncome)){
  870. resultMap.put("companyId",insPlyIncome.getCompanyId()); // 保险公司id
  871. resultMap.put("partnerCompaniesId",insPlyIncome.getPartnerCompaniesId()); //合作公司id
  872. resultMap.put("agreementId",insPlyIncome.getAgreementId()); //协议id
  873. }
  874. if(ObjectUtils.isNotEmpty(insPlyIncome)){ // 比配上汇总金额 未匹配则返回到数据当中
  875. strBuilder.append(insPlyIncome.getId()).append(",");
  876. if( insPlyIncome.getCommissionFeevalue()!=null && insPlyIncome.getCommissionFeevalue().compareTo(BigDecimal.ZERO)!=0){
  877. totalAmount = totalAmount.add(insPlyIncome.getCommissionFeevalue()); //添加总手续费
  878. }
  879. }else {
  880. HashMap<String, Object> noMatching = new HashMap<>();
  881. if(StringUtils.isNotEmpty(excelItem.getLicenseno())){
  882. noMatching.put("licenseno",excelItem.getLicenseno());
  883. }
  884. if(StringUtils.isNotEmpty(excelItem.getNoPolicyno())){
  885. noMatching.put("NoPolicyno",excelItem.getNoPolicyno());
  886. }
  887. resultList.add(noMatching);
  888. }
  889. resultMap.put("reason",reason);
  890. }
  891. if(strBuilder.length() >0){
  892. ids = strBuilder.deleteCharAt(strBuilder.length() - 1).toString();
  893. }
  894. resultMap.put("ids",ids);
  895. resultMap.put("totalAmount",totalAmount);
  896. resultMap.put("resultList",resultList);
  897. }
  898. return resultMap;
  899. } catch (IOException e) {
  900. throw new SystemException("导入失败!");
  901. }
  902. }
  903. @Override
  904. public HttpResult bxOtherDetailsExcel(InsPlyIncomeVo insPlyIncomeVo, HttpServletRequest request, HttpServletResponse response) {
  905. HashMap<String, Object> params = new HashMap<>();
  906. params =this.saveParams(insPlyIncomeVo,params);
  907. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(params);
  908. ExportParams exportParams = new ExportParams("保险跟单明细导出", null, ExcelType.HSSF);
  909. exportParams.setStyle(ExcelStyleUtil.class);
  910. List<BxOtherDetailsExcel> resultList = new ArrayList<>();
  911. for (InsPlyIncome item :insPlyIncomes){
  912. BxOtherDetailsExcel bxOtherDetailsExcel = new BxOtherDetailsExcel();
  913. BeanUtils.copyProperties(item, bxOtherDetailsExcel);
  914. resultList.add(bxOtherDetailsExcel);
  915. }
  916. String uploadPath = this.uploadPath + "/excel/";
  917. Path path = Paths.get(uploadPath);
  918. if (!Files.exists(path)) {
  919. try {
  920. Files.createDirectories(path);
  921. } catch (IOException e) {
  922. e.printStackTrace();
  923. }
  924. }
  925. String fileName = EasyExcelUtils.downExcel(uploadPath, "保险跟单明细导出", BxOtherDetailsExcel.class, resultList);
  926. return HttpResult.ok("",uploadUrl + "excel/" + fileName);
  927. }
  928. /**
  929. *
  930. * @param insPlyIncomeVo 传参字段
  931. * ids 通过ids中的id进行开票分组
  932. *
  933. * @return
  934. */
  935. @Override
  936. public HttpResult<List<HashMap<String,Object>>> invicdetail(InsPlyIncomeVo insPlyIncomeVo) {
  937. HashMap<String, Object> params = new HashMap<>();
  938. params =this.saveParams(insPlyIncomeVo,params);
  939. if (StringUtils.isEmpty(insPlyIncomeVo.getIsSettlement())){
  940. params.put("isSettlement","1");
  941. }
  942. if(StringUtils.isNotEmpty(insPlyIncomeVo.getSettlementStatus())){
  943. params.put("settlementStatus",insPlyIncomeVo.getSettlementStatus());
  944. }
  945. List<HashMap<String, Object>> resultList = settlementDocumentaryFeesService.getOtherSettldetail(params);
  946. if (resultList.size() > 0) {
  947. return HttpResult.ok(resultList);
  948. }
  949. return HttpResult.ok();
  950. }
  951. /***
  952. *
  953. * @param insPlyIncomeVo
  954. * @param request
  955. * @param response
  956. * @return 保险非车跟单明细导出
  957. */
  958. @Override
  959. public HttpResult bxNoOtherDetailsExcel(InsPlyIncomeVo insPlyIncomeVo, HttpServletRequest request, HttpServletResponse response) {
  960. HashMap<String, Object> params = new HashMap<>();
  961. params =this.saveParams(insPlyIncomeVo,params);
  962. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(params);
  963. ExportParams exportParams = new ExportParams("保险非车跟单明细导出", null, ExcelType.HSSF);
  964. exportParams.setStyle(ExcelStyleUtil.class);
  965. List<BxNoOtherDetailsExcel> resultList = new ArrayList<>();
  966. for (InsPlyIncome item :insPlyIncomes){
  967. BxNoOtherDetailsExcel bxNoOtherDetailsExcel = new BxNoOtherDetailsExcel();
  968. BeanUtils.copyProperties(item, bxNoOtherDetailsExcel);
  969. resultList.add(bxNoOtherDetailsExcel);
  970. }
  971. String uploadPath = this.uploadPath + "/excel/";
  972. Path path = Paths.get(uploadPath);
  973. if (!Files.exists(path)) {
  974. try {
  975. Files.createDirectories(path);
  976. } catch (IOException e) {
  977. e.printStackTrace();
  978. }
  979. }
  980. String fileName = EasyExcelUtils.downExcel(uploadPath, "保险非车跟单明细导出", BxNoOtherDetailsExcel.class, resultList);
  981. return HttpResult.ok("",uploadUrl + "excel/" + fileName);
  982. }
  983. /**
  984. *
  985. * @param insPlyIncomeVo 开票ids
  986. * @return 返回开票号 开票金额 开票时间
  987. */
  988. @Override
  989. public HttpResult<List<HashMap<String, Object>>> otherSettldetail(InsPlyIncomeVo insPlyIncomeVo) {
  990. HashMap<String, Object> params = new HashMap<>();
  991. params =this.saveParams(insPlyIncomeVo,params);
  992. List<HashMap<String, Object>> resultList = settlementDocumentaryFeesService.getOtherSettldetail(params);
  993. if (resultList.size() > 0) {
  994. return HttpResult.ok(resultList);
  995. }
  996. return HttpResult.ok();
  997. }
  998. @Override
  999. public InsPlyIncome getEntityById(String id) {
  1000. return baseMapper.getEntityById(id);
  1001. }
  1002. @Override
  1003. @Transactional
  1004. public void updateByEntity(InsPlyIncomeVo insPlyIncomeVo) {
  1005. // 根据协议 如果是含增值税结算 用保费 * 如果是 不含税保费
  1006. InsPlyIncome insPlyIncome = new InsPlyIncome();
  1007. BeanUtils.copyProperties(insPlyIncomeVo, insPlyIncome);
  1008. this.amountCalculate(insPlyIncomeVo,insPlyIncome);
  1009. baseMapper.updateById(insPlyIncome);
  1010. insPlyIncomeVo.setCrudStatus("2");
  1011. this.saveLog(insPlyIncomeVo);
  1012. }
  1013. /**
  1014. *
  1015. * @param insPlyIncomeVo
  1016. * @param insPlyIncome
  1017. *
  1018. * 重新计算金额 通过比例
  1019. * 计算逻辑 交强不含税保费* 交强跟单比例 = 交强跟单金额
  1020. */
  1021. private void amountCalculate(InsPlyIncomeVo insPlyIncomeVo,InsPlyIncome insPlyIncome) {
  1022. if("1".equals(insPlyIncomeVo.getAgreementType())){ //平台
  1023. // 平台 手续费 +跟单费 = 应收 手续费 = 手续费比例*保费 应收比例=手续费比例 + 跟单比例
  1024. BigDecimal jqSuperviseCostsProportion = initializationBigdecimal(insPlyIncomeVo.getJqSuperviseCostsProportion());//交强手续费比例
  1025. BigDecimal sySuperviseCostsProportion = initializationBigdecimal(insPlyIncomeVo.getSySuperviseCostsProportion()); //商业手续费比例
  1026. BigDecimal noSuperviseCostsProportion = initializationBigdecimal(insPlyIncomeVo.getNoSuperviseCostsProportion()); //非车手续费比例
  1027. BigDecimal jqOtherCostsProportion = initializationBigdecimal(insPlyIncomeVo.getJqOtherCostsProportion()); //交强跟单比例
  1028. BigDecimal syOtherCostsProportion = initializationBigdecimal(insPlyIncomeVo.getSyOtherCostsProportion()); //商业跟单比例
  1029. BigDecimal noOtherCostsProportion = initializationBigdecimal(insPlyIncomeVo.getNoOtherCostsProportion()); //非车跟单比例
  1030. BigDecimal jqPremium = initializationBigdecimal(insPlyIncomeVo.getJqPremium()); //交强保费
  1031. BigDecimal syPremium = initializationBigdecimal(insPlyIncomeVo.getSyPremium()); //商业保费
  1032. BigDecimal noPremium = initializationBigdecimal(insPlyIncomeVo.getNoPremium()); //非车保费
  1033. //手续费比例
  1034. insPlyIncome.setCommissionFeerate(this.calculateTotal(jqSuperviseCostsProportion,sySuperviseCostsProportion,noSuperviseCostsProportion)); //手续费比例 = 商业手续费比例 + 交强手续费比例 + 非车手续费比例
  1035. if(jqSuperviseCostsProportion !=null && jqPremium!=null ){
  1036. insPlyIncome.setJqSuperviseCostsPremiums(this.algorithmAmount(jqPremium,jqSuperviseCostsProportion)); //交强手续费
  1037. }
  1038. if(sySuperviseCostsProportion !=null && syPremium !=null){
  1039. insPlyIncome.setSySuperviseCostsPremiums(this.algorithmAmount(syPremium,sySuperviseCostsProportion)); //商业手续费
  1040. }
  1041. if(noSuperviseCostsProportion !=null && noPremium!=null){
  1042. insPlyIncome.setNoSuperviseCostsPremiums(this.algorithmAmount(noPremium,noSuperviseCostsProportion)); //非车手续费
  1043. }
  1044. if(jqOtherCostsProportion !=null && jqPremium!=null ){
  1045. insPlyIncome.setJqOtherCostsPremium(this.algorithmAmount(jqPremium,jqOtherCostsProportion)); //交强跟单费
  1046. }
  1047. if(syOtherCostsProportion !=null && syPremium !=null ){
  1048. insPlyIncome.setSyOtherCostsPremium(this.algorithmAmount(syPremium,syOtherCostsProportion)); //商业跟单费
  1049. }
  1050. if(noOtherCostsProportion !=null && noPremium !=null){
  1051. insPlyIncome.setNoOtherCostsPremium(this.algorithmAmount(noPremium,noOtherCostsProportion)); //非车跟单费
  1052. }
  1053. insPlyIncome.setCommissionFeevalue(this.calculateTotal(insPlyIncome.getJqSuperviseCostsPremiums(),insPlyIncome.getSySuperviseCostsPremiums(),insPlyIncome.getNoSuperviseCostsPremiums())); //手续费
  1054. insPlyIncome.setCommissionFeerate(this.calculateTotal(jqSuperviseCostsProportion,sySuperviseCostsProportion,noSuperviseCostsProportion)); //手续费比例
  1055. insPlyIncome.setOtherFeevalue(this.calculateTotal(insPlyIncome.getJqOtherCostsPremium(),insPlyIncome.getSyOtherCostsPremium(),insPlyIncome.getNoOtherCostsPremium())); //跟单费金额
  1056. insPlyIncome.setOtherFeerate(this.calculateTotal(jqOtherCostsProportion,syOtherCostsProportion,noOtherCostsProportion)); //跟单费比例
  1057. insPlyIncome.setAllFeeValue(this.calculateTotal(insPlyIncome.getCommissionFeevalue(),insPlyIncome.getOtherFeevalue(),null)); // 总费用 = 手续费+跟单费
  1058. //应收比例 交强应收比例=交强手续费比例+交强非跟单比例
  1059. insPlyIncome.setJqReceivableProportion(this.calculateTotal(jqSuperviseCostsProportion,jqOtherCostsProportion,null)); //交强应收
  1060. insPlyIncome.setSyReceivableProportion(this.calculateTotal(sySuperviseCostsProportion,syOtherCostsProportion,null)); //商业应收
  1061. insPlyIncome.setNoReceivableProportion(this.calculateTotal(noSuperviseCostsProportion,noOtherCostsProportion,null)); //非车应收
  1062. }else {
  1063. BigDecimal jqNoTaxPremium = insPlyIncomeVo.getJqNoTaxPremium();// 交强手续费 按照思路 交强不含税保费* 交强手续费比例 =交强手续费
  1064. BigDecimal syNoTaxPremium = insPlyIncomeVo.getSyNoTaxPremium();// 商业手续费 按照思路 商业不含税保费* 商业手续费比例 =商业手续费
  1065. BigDecimal noNoTaxPremium = insPlyIncomeVo.getNoNoTaxPremium();// 非车手续费 按照思路 非车不含税保费* 非车手续费比例 =非车手续费
  1066. if(insPlyIncomeVo.getJqSuperviseCostsProportion().compareTo(BigDecimal.ZERO) != 0){
  1067. BigDecimal jqhandingFee = jqNoTaxPremium.multiply(insPlyIncomeVo.getJqSuperviseCostsProportion().divide(new BigDecimal(100)));
  1068. insPlyIncome.setJqSuperviseCostsPremiums(jqhandingFee);
  1069. }
  1070. if(insPlyIncomeVo.getSySuperviseCostsProportion().compareTo(BigDecimal.ZERO) != 0){
  1071. BigDecimal syhandingFee = syNoTaxPremium.multiply(insPlyIncomeVo.getSySuperviseCostsProportion().divide(new BigDecimal(100)));
  1072. insPlyIncome.setSySuperviseCostsPremiums(syhandingFee);
  1073. }
  1074. if(insPlyIncomeVo.getNoSuperviseCostsProportion().compareTo(BigDecimal.ZERO) != 0){
  1075. BigDecimal nohandingFee = noNoTaxPremium.multiply(insPlyIncomeVo.getNoSuperviseCostsProportion().divide(new BigDecimal(100)));
  1076. insPlyIncome.setNoSuperviseCostsPremiums(nohandingFee);
  1077. }
  1078. if(insPlyIncomeVo.getJqOtherCostsProportion().compareTo(BigDecimal.ZERO) != 0){
  1079. BigDecimal jqother = jqNoTaxPremium.multiply(insPlyIncomeVo.getJqOtherCostsProportion().divide(new BigDecimal(100)));//交强跟单费 按照思路 交强不含税保费* 交强跟单比例 = 交强跟单金额
  1080. insPlyIncome.setJqOtherCostsPremium(jqother);
  1081. }
  1082. if(insPlyIncomeVo.getSyOtherCostsProportion().compareTo(BigDecimal.ZERO) != 0){
  1083. BigDecimal syother = syNoTaxPremium.multiply(insPlyIncomeVo.getSyOtherCostsProportion().divide(new BigDecimal(100)));//交强跟单费 按照思路 交强不含税保费* 交强跟单比例 = 交强跟单金额
  1084. insPlyIncome.setSyOtherCostsPremium(syother);
  1085. }
  1086. if(insPlyIncomeVo.getNoOtherCostsProportion().compareTo(BigDecimal.ZERO) != 0){
  1087. BigDecimal syother = syNoTaxPremium.multiply(insPlyIncomeVo.getNoOtherCostsProportion().divide(new BigDecimal(100)));//非车跟单费 按照思路 非车不含税保费* 非车跟单比例 = 非车跟单金额
  1088. insPlyIncome.setNoOtherCostsPremium(syother);
  1089. }
  1090. if("0".equals(insPlyIncomeVo.getIsNotDocumentary()) && "0".equals(insPlyIncomeVo.getIsNotCar())){ //保险 手续费 =不含税保费* 手续费比例
  1091. insPlyIncome.setCommissionFeevalue(this.calculateTotal(insPlyIncome.getJqSuperviseCostsPremiums(),insPlyIncome.getSySuperviseCostsPremiums(),null)); // 手续费
  1092. insPlyIncome.setCommissionFeerate(this.calculateTotal(insPlyIncome.getJqSuperviseCostsProportion(),insPlyIncome.getSySuperviseCostsProportion(),null));//手续费比例
  1093. insPlyIncome.setAllFeeValue(this.calculateTotal(insPlyIncome.getCommissionFeevalue(),null,null));//总金额
  1094. }else if ("1".equals(insPlyIncomeVo.getIsNotDocumentary()) && "0".equals(insPlyIncomeVo.getIsNotCar())){ //保险跟单费 交强跟单+商业跟单
  1095. insPlyIncome.setOtherFeevalue(this.calculateTotal(insPlyIncome.getJqOtherCostsPremium(),insPlyIncome.getSyOtherCostsPremium(),null));
  1096. insPlyIncome.setOtherFeerate(this.calculateTotal(insPlyIncome.getJqOtherCostsProportion(),insPlyIncome.getSyOtherCostsProportion(),null));
  1097. insPlyIncome.setAllFeeValue(this.calculateTotal(insPlyIncome.getOtherFeevalue(),null,null));//总金额
  1098. }
  1099. if("0".equals(insPlyIncomeVo.getIsNotDocumentary()) && "1".equals(insPlyIncomeVo.getIsNotCar())){// 非车
  1100. insPlyIncome.setCommissionFeevalue(this.calculateTotal(insPlyIncome.getNoSuperviseCostsPremiums(),null,null)); // 非车手续费
  1101. insPlyIncome.setCommissionFeerate(this.calculateTotal(insPlyIncome.getNoSuperviseCostsProportion(),null,null)); //非车比例
  1102. insPlyIncome.setAllFeeValue(this.calculateTotal(insPlyIncome.getCommissionFeevalue(),null,null));//总金额
  1103. }else if ("1".equals(insPlyIncomeVo.getIsNotDocumentary()) && "1".equals(insPlyIncomeVo.getIsNotCar())){ //非车跟单
  1104. insPlyIncome.setOtherFeevalue(this.calculateTotal(insPlyIncome.getNoOtherCostsPremium(),null,null)); //非车跟单金额
  1105. insPlyIncome.setOtherFeerate(this.calculateTotal(insPlyIncome.getNoOtherCostsProportion(),null,null)); // 非车跟单比例
  1106. insPlyIncome.setAllFeeValue(this.calculateTotal(insPlyIncome.getOtherFeevalue(),null,null));//总金额
  1107. }
  1108. }
  1109. }
  1110. /**
  1111. *
  1112. * @param value1 保费
  1113. * @param value2 比例
  1114. * @return 费用
  1115. */
  1116. private BigDecimal algorithmAmount(BigDecimal value1, BigDecimal value2) {
  1117. return value1.multiply(value2.divide(new BigDecimal(100)));
  1118. }
  1119. private BigDecimal initializationBigdecimal(BigDecimal value) {
  1120. return value != null ? value : BigDecimal.ZERO;
  1121. }
  1122. private void saveLog(InsPlyIncomeVo insPlyIncomeVo) {
  1123. // 添加记录
  1124. SettlementDocumentaryLogEntity settlementDocumentaryLogEntity = new SettlementDocumentaryLogEntity();
  1125. settlementDocumentaryLogEntity.setCrudStatus(insPlyIncomeVo.getCrudStatus());
  1126. settlementDocumentaryLogEntity.setAmount(insPlyIncomeVo.getOtherFeevalue());
  1127. settlementDocumentaryLogEntity.setSettlementDocumentaryId(insPlyIncomeVo.getId());
  1128. settlementDocumentaryLogEntity.setAmountType("2");
  1129. settlementDocumentaryLogService.save(settlementDocumentaryLogEntity);
  1130. }
  1131. @Override
  1132. @Transactional
  1133. public HttpResult<InsPlyIncome> insertByEntity(InsPlyIncomeVo insPlyIncomeVo) {
  1134. Long id = new SnowFlakeUtil().nextId();
  1135. InsPlyIncome insPlyIncome = new InsPlyIncome();
  1136. insPlyIncomeVo.setOrderno(id.toString());
  1137. BeanUtils.copyProperties(insPlyIncomeVo, insPlyIncome);
  1138. insPlyIncome.setUserId(BaseController.getUser().getId());
  1139. insPlyIncome.setDocumentaryFeesStatus("0");
  1140. insPlyIncome.setHandlingFeesStatus("0");
  1141. insPlyIncome.setIsNotCar(insPlyIncomeVo.getIsNotCar()); // 是否是非车
  1142. insPlyIncome.setIsNotDocumentary(insPlyIncomeVo.getIsNotDocumentary()); //是否是跟单
  1143. HashMap<String, Object> params = new HashMap<>();
  1144. params.put("companyId",insPlyIncomeVo.getCompanyId());
  1145. params.put("partnerCompaniesId",insPlyIncomeVo.getPartnerCompaniesId());
  1146. PtlAgreement ptlAgreement = ptlAgreementService.selectAgreeId(params);
  1147. if(ObjectUtils.isEmpty(ptlAgreement)){
  1148. return HttpResult.error("协议匹配不上");
  1149. }
  1150. insPlyIncome.setAgreementId(ptlAgreement.getId());
  1151. baseMapper.insert(insPlyIncome);
  1152. insPlyIncomeVo.setId(insPlyIncome.getId());
  1153. insPlyIncomeVo.setCrudStatus("1");
  1154. this.saveLog(insPlyIncomeVo); //添加日志
  1155. // HashMap<String, Object> params = new HashMap<>();
  1156. //
  1157. // if(StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotCar())){
  1158. // params.put("isNotCar",insPlyIncomeVo.getIsNotCar());
  1159. // }
  1160. // params.put("isOther","1");
  1161. // if(StringUtils.isNotEmpty(insPlyIncomeVo.getYear())){
  1162. // params.put("year",insPlyIncomeVo.getYear());
  1163. // }
  1164. // if(StringUtils.isNotEmpty(insPlyIncomeVo.getCompanyId())){
  1165. // params.put("companyId",insPlyIncomeVo.getCompanyId());
  1166. // }
  1167. //
  1168. // List<InsPlyIncome> list= this.baseMapper.NonSettlementQuery(params);
  1169. // if(!CollectionUtils.isEmpty(list)){
  1170. // for (InsPlyIncome item :list){
  1171. // return HttpResult.ok(item.getIds());
  1172. // }
  1173. // }
  1174. return HttpResult.ok();
  1175. }
  1176. @Override
  1177. @Transactional
  1178. public HttpResult<InsPlyIncome> deleteById(InsPlyIncomeVo insPlyIncomeVo) {
  1179. HashMap<String, Object> params = new HashMap<>();
  1180. if(StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotCar())){
  1181. params.put("isNotCar",insPlyIncomeVo.getIsNotCar());
  1182. }
  1183. params.put("isOther","1");
  1184. if(StringUtils.isNotEmpty(insPlyIncomeVo.getYear())){
  1185. params.put("year",insPlyIncomeVo.getYear());
  1186. }
  1187. if(StringUtils.isNotEmpty(insPlyIncomeVo.getCompanyId())){
  1188. params.put("companyId",insPlyIncomeVo.getCompanyId());
  1189. }
  1190. baseMapper.deleteById(insPlyIncomeVo.getId());
  1191. insPlyIncomeVo.setCrudStatus("3");
  1192. this.saveLog(insPlyIncomeVo);
  1193. List<InsPlyIncome> list = this.baseMapper.NonSettlementQuery(params);
  1194. if (!CollectionUtils.isEmpty(list)) {
  1195. for (InsPlyIncome item : list) {
  1196. return HttpResult.ok(item.getIds());
  1197. }
  1198. } else {
  1199. return HttpResult.ok(null);
  1200. }
  1201. return HttpResult.ok("删除成功");
  1202. }
  1203. @Override
  1204. @Transactional
  1205. public void uodateBalance(InsPlyIncomeVo insPlyIncomeVo) {
  1206. InsPlyIncome insPlyIncome = new InsPlyIncome();
  1207. insPlyIncomeVo.setHandlingFeesStatus("1");
  1208. insPlyIncomeVo.setSettlementTime(LocalDate.now());
  1209. BeanUtils.copyProperties(insPlyIncomeVo, insPlyIncome);
  1210. baseMapper.updateById(insPlyIncome);
  1211. // 生成记录
  1212. SettlementDocumentaryLogEntity settlementDocumentaryLogEntity = new SettlementDocumentaryLogEntity();
  1213. if(StringUtils.isNotEmpty(insPlyIncomeVo.getAgreementType()) && "1".equals(insPlyIncomeVo.getAgreementType())){
  1214. // 只有平台协议 才会跟单费一笔结算
  1215. settlementDocumentaryLogEntity.setAmount(insPlyIncomeVo.getOtherFeevalue()); // 跟单费金额
  1216. }
  1217. settlementDocumentaryLogEntity.setHandingAmount(insPlyIncomeVo.getCommissionFeevalue()); // 手续费金额
  1218. settlementDocumentaryLogEntity.setSettlementDocumentaryId(insPlyIncomeVo.getId()); // 关联id
  1219. settlementDocumentaryLogEntity.setAmountType("1"); //手续费结算
  1220. settlementDocumentaryLogEntity.setCreateTime(new Date());
  1221. settlementDocumentaryLogService.save(settlementDocumentaryLogEntity);
  1222. }
  1223. @Override
  1224. @Transactional
  1225. public HttpResult<BasePageResult<InsPlyIncome>> totalQuery(InsPlyIncomeVo insPlyIncomeVo) {
  1226. HashMap<String, Object> params = new HashMap<>();
  1227. PageInfo<List<InsPlyIncome>> pageHelper = null;
  1228. if(insPlyIncomeVo.getStartDate()!=null){
  1229. params.put("startDate",insPlyIncomeVo.getStartDate().toString());
  1230. }
  1231. if(insPlyIncomeVo.getEndDate()!=null){
  1232. params.put("endDate",insPlyIncomeVo.getEndDate().toString());
  1233. }
  1234. if(StringUtils.isNotEmpty(insPlyIncomeVo.getYear())){
  1235. params.put("year",insPlyIncomeVo.getYear());
  1236. }
  1237. if(StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotCar())){
  1238. params.put("isNotCar",insPlyIncomeVo.getIsNotCar());
  1239. }
  1240. if(StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotDocumentary())){
  1241. params.put("isOther",insPlyIncomeVo.getIsNotDocumentary());
  1242. }
  1243. if(StringUtils.isNotEmpty(insPlyIncomeVo.getDocumentaryFeesStatus())){
  1244. params.put("documentaryFeesStatus",insPlyIncomeVo.getDocumentaryFeesStatus());
  1245. }
  1246. if(StringUtils.isNotEmpty(insPlyIncomeVo.getCompanyId())){
  1247. params.put("companyId",insPlyIncomeVo.getCompanyId());
  1248. }
  1249. params.put("pageNum",insPlyIncomeVo.getPageNum());
  1250. params.put("pageSize",insPlyIncomeVo.getPageSize());
  1251. List<InsPlyIncome> list= this.baseMapper.totalQuery(params);
  1252. pageHelper=new PageInfo(list);
  1253. return HttpResult.ok(new BasePageResult<>(insPlyIncomeVo.getPageNum(), insPlyIncomeVo.getPageSize(), pageHelper.getTotal(), pageHelper.getPages(), list));
  1254. }
  1255. /**
  1256. *
  1257. * @param insPlyIncomeVo ids ins_ply_income 这个表的ids incomeIds settlement_documentary_fees 这个表的ids
  1258. * @return
  1259. */
  1260. /**
  1261. * 跟单费结算 有分批结算的情况
  1262. * @param insPlyIncomeVo
  1263. * @return
  1264. */
  1265. @Override
  1266. @Transactional
  1267. public HttpResult batchBalance(InsPlyIncomeVo insPlyIncomeVo) {
  1268. // 通过ids 查出跟单非结算单
  1269. BigDecimal allAmount = BigDecimal.ZERO;
  1270. // 分批结算
  1271. SettlementDocumentaryFeesVo settlementDocumentaryFeesVo = new SettlementDocumentaryFeesVo();
  1272. settlementDocumentaryFeesVo.setInvoiceId(insPlyIncomeVo.getInvoicId()); //开票号
  1273. settlementDocumentaryFeesVo.setSettlementTime(insPlyIncomeVo.getSettlementTime()); //结算时间
  1274. settlementDocumentaryFeesVo.setSettlementStatus("2"); //2为结算状态
  1275. settlementDocumentaryFeesVo.setCompanyId(insPlyIncomeVo.getCompanyId()); // 保险公司id
  1276. settlementDocumentaryFeesVo.setPartnerCompaniesId(insPlyIncomeVo.getPartnerCompaniesId()); //合作公司id
  1277. settlementDocumentaryFeesVo.setUnsettledAmount(insPlyIncomeVo.getInvoicCommissionFeevalue().subtract(insPlyIncomeVo.getSettlementAmount())); //未结算金额
  1278. settlementDocumentaryFeesVo.setIsNotCar(insPlyIncomeVo.getIsNotCar()); // 是否是非车
  1279. settlementDocumentaryFeesVo.setInvoicingMethod(insPlyIncomeVo.getInvoicingMethod()); //开票方式
  1280. settlementDocumentaryFeesVo.setTaxPoints(insPlyIncomeVo.getTaxPoints()); //税点
  1281. if ("0".equals(insPlyIncomeVo.getInvoicingMethod())) {
  1282. settlementDocumentaryFeesVo.setExpendAmount(insPlyIncomeVo.getSettlementAmount().multiply(BigDecimal.ONE.subtract(insPlyIncomeVo.getTaxPoints().divide(new BigDecimal(100)))));
  1283. } else {
  1284. settlementDocumentaryFeesVo.setExpendAmount(insPlyIncomeVo.getSettlementAmount()); //进账金额
  1285. }
  1286. settlementDocumentaryFeesVo.setSettlementAmount(insPlyIncomeVo.getSettlementAmount()); //进账金额
  1287. settlementDocumentaryFeesVo.setHandlingFeesStatus(insPlyIncomeVo.getHandlingFeesStatus());
  1288. settlementDocumentaryFeesVo.setTotalAmount(insPlyIncomeVo.getInvoicCommissionFeevalue());
  1289. settlementDocumentaryFeesVo.setCreateTime(LocalDateTime.now());
  1290. settlementDocumentaryFeesVo.setParentId(insPlyIncomeVo.getId());
  1291. settlementDocumentaryFeesVo.setAgreementType("2"); //1平台 2 保险
  1292. settlementDocumentaryFeesService.inertSettle(settlementDocumentaryFeesVo);
  1293. return HttpResult.ok();
  1294. }
  1295. /**
  1296. *
  1297. * @param insPlyIncomeVo
  1298. * @return
  1299. */
  1300. @Override
  1301. public List<InsPlyIncome> totalBxAmount(InsPlyIncomeVo insPlyIncomeVo) {
  1302. HashMap<String, Object> params = new HashMap<>();
  1303. params=this.saveParams(insPlyIncomeVo,params);
  1304. params.remove("handlingFeesStatus");
  1305. List<InsPlyIncome> resultList = baseMapper.totalBxAmount(params);
  1306. // 数据库数据太多是 用sql拼接id会丢失 所以只能逻辑拼接
  1307. List<InsPlyIncome> idList=baseMapper.getIncomeIdList(params);
  1308. if(!CollectionUtils.isEmpty(idList) && !CollectionUtils.isEmpty(resultList)){
  1309. this.splicingIds(idList,resultList);
  1310. }
  1311. return resultList;
  1312. }
  1313. /**
  1314. *
  1315. * @param idList 要开票的数据集合
  1316. * @param resultList 总返回数据
  1317. */
  1318. private void splicingIds(List<InsPlyIncome> idList, List<InsPlyIncome> resultList) {
  1319. // 使用Map来存储agreementId到其id列表的映射
  1320. Map<String, List<String>> idMap = new HashMap<>();
  1321. for (InsPlyIncome idItem : idList) {
  1322. String partnerCompaniesId = idItem.getPartnerCompaniesId();
  1323. idMap.computeIfAbsent(partnerCompaniesId, k -> new ArrayList<>()).add(idItem.getId());
  1324. }
  1325. for (InsPlyIncome resultItem : resultList) {
  1326. List<String> ids = idMap.getOrDefault(resultItem.getPartnerCompaniesId(), Collections.emptyList());
  1327. String idsString = String.join(",", ids);
  1328. resultItem.setIds(idsString);
  1329. }
  1330. }
  1331. /**
  1332. *
  1333. * @param insPlyIncomeVo
  1334. * @return 保险手续费改成多次结算
  1335. */
  1336. @Override
  1337. @Transactional
  1338. public HttpResult<Object> batchInvoicing(InsPlyIncomeVo insPlyIncomeVo) {
  1339. ImportResult importResult = importAsyncService.getById(insPlyIncomeVo.getSelectIds().get(0)); // 查询 任务
  1340. HashMap<String, Object> params = new HashMap<>();
  1341. if (StringUtils.isNotEmpty(importResult.getId())) {
  1342. params.put("companyId",importResult.getCompanyId());
  1343. params.put("partnerCompaniesId",importResult.getPartnerCompaniesId());
  1344. params.put("isOther","0");
  1345. if (StringUtils.isNotEmpty(importResult.getHandStatus())) {
  1346. if ("0".equals(importResult.getHandStatus())) {
  1347. params.put("isNotCar", "0");
  1348. } else if ("1".equals(importResult.getHandStatus())) {
  1349. params.put("isNotCar", "1");
  1350. }
  1351. }
  1352. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(params);
  1353. if (!CollectionUtils.isEmpty(insPlyIncomes)) {
  1354. if (insPlyIncomeVo != null) { // 确保insPlyIncomeVo不是null
  1355. for (InsPlyIncome item : insPlyIncomes) {
  1356. item.setInvoicTime(LocalDate.now());
  1357. item.setInvoicId(insPlyIncomeVo.getInvoicId());
  1358. item.setHandlingFeesStatus("2");
  1359. if (StringUtils.isNotEmpty(item.getTaskId())) {
  1360. return HttpResult.error("该单据已经开票 ");
  1361. } else {
  1362. item.setTaskId(importResult.getId());
  1363. baseMapper.updateById(item);
  1364. }
  1365. }
  1366. }
  1367. }
  1368. }
  1369. insPlyIncomeVo.setNoInvoicCommissionFeevalue(importResult.getTotalAmount());
  1370. insPlyIncomeVo.setOtherFeevalue(importResult.getTotalAmount());
  1371. insPlyIncomeVo.setHandlingFeesStatus("0"); // 0手续费 1 跟单费
  1372. insPlyIncomeVo.setIsNotCar(insPlyIncomeVo.getIsNotCar());
  1373. insPlyIncomeVo.setAgreementId(importResult.getAgreementId());
  1374. insPlyIncomeVo.setPartnerCompaniesId(importResult.getPartnerCompaniesId());
  1375. insPlyIncomeVo.setSettlementAmount(importResult.getTotalAmount());
  1376. insPlyIncomeVo.setContractId(insPlyIncomeVo.getInvoicId());
  1377. insPlyIncomeVo.setCompanyId(importResult.getCompanyId());
  1378. insPlyIncomeVo.setTaskId(importResult.getId());
  1379. this.batchInvoic(insPlyIncomeVo);
  1380. return HttpResult.ok();
  1381. }
  1382. @Override
  1383. public HttpResult<InsPlyIncome> queryInvoicing(InsPlyIncomeVo insPlyIncomeVo) {
  1384. HashMap<String, Object> params = new HashMap<>();
  1385. params = this.saveParams(insPlyIncomeVo, params);
  1386. InsPlyIncome result= baseMapper.queryInvoicing(params); //总金额
  1387. params.put("handlingFeesStatus","0");
  1388. InsPlyIncome noResult= baseMapper.queryInvoicing(params); //未结算金额
  1389. result.setReadyCommissionFeevalue(noResult.getCommissionFeevalue());
  1390. return HttpResult.ok(result);
  1391. }
  1392. @Override
  1393. public HttpResult<Object> batchBxBalance(InsPlyIncomeVo insPlyIncomeVo) {
  1394. if(StringUtils.isNotEmpty(insPlyIncomeVo.getIds())){// 判断 ins_ply_income 是否完全结算完 如果结算完则改为已结算状态
  1395. this.changeHandStatus(insPlyIncomeVo.getIds(),insPlyIncomeVo);
  1396. }
  1397. // 分批结算
  1398. SettlementDocumentaryFeesVo settlementDocumentaryFeesVo = new SettlementDocumentaryFeesVo();
  1399. settlementDocumentaryFeesVo.setInvoiceId(insPlyIncomeVo.getInvoicId()); //开票号
  1400. settlementDocumentaryFeesVo.setSettlementTime(insPlyIncomeVo.getSettlementTime()); //结算时间
  1401. settlementDocumentaryFeesVo.setSettlementStatus("2"); //2为结算状态
  1402. settlementDocumentaryFeesVo.setCompanyId(insPlyIncomeVo.getCompanyId()); // 保险公司id
  1403. settlementDocumentaryFeesVo.setPartnerCompaniesId(insPlyIncomeVo.getPartnerCompaniesId()); //合作公司id
  1404. settlementDocumentaryFeesVo.setIsNotCar(insPlyIncomeVo.getIsNotCar()); // 是否是非车
  1405. settlementDocumentaryFeesVo.setInvoicingMethod(insPlyIncomeVo.getInvoicingMethod()); //开票方式
  1406. settlementDocumentaryFeesVo.setTaxPoints(insPlyIncomeVo.getTaxPoints()); //税点
  1407. settlementDocumentaryFeesVo.setExpendAmount(insPlyIncomeVo.getInvoicCommissionFeevalue().multiply(BigDecimal.ONE.subtract(insPlyIncomeVo.getTaxPoints().divide(new BigDecimal(100)))));
  1408. settlementDocumentaryFeesVo.setSettlementAmount(insPlyIncomeVo.getSettlementAmount()); //进账金额
  1409. settlementDocumentaryFeesVo.setTotalAmount(insPlyIncomeVo.getInvoicCommissionFeevalue());
  1410. settlementDocumentaryFeesVo.setHandlingFeesStatus("0");
  1411. settlementDocumentaryFeesVo.setParentId(insPlyIncomeVo.getId());
  1412. settlementDocumentaryFeesVo.setSettlementImageId(insPlyIncomeVo.getSettlementImageId());
  1413. settlementDocumentaryFeesVo.setCreateTime(LocalDateTime.now());
  1414. settlementDocumentaryFeesVo.setAgreementType("2"); //1平台 2 保险
  1415. settlementDocumentaryFeesService.inertSettle(settlementDocumentaryFeesVo);
  1416. return HttpResult.ok();
  1417. }
  1418. private void changeHandStatus(String ids, InsPlyIncomeVo insPlyIncomeVo) {
  1419. String[] split = ids.split(",");
  1420. SettlementDocumentaryFeesEntity byId = settlementDocumentaryFeesService.getById(insPlyIncomeVo.getId());
  1421. BigDecimal totalAmount = byId.getTotalAmount(); //开票总金额
  1422. BigDecimal settlementAmount = insPlyIncomeVo.getSettlementAmount(); //本次结算金额
  1423. //多次结算 表中已经结算的金额
  1424. SettlementDocumentaryFeesEntity settlementAmountEntity = settlementDocumentaryFeesService.getByParentSettlementAmount(insPlyIncomeVo.getId());
  1425. if(ObjectUtils.isNotEmpty(settlementAmountEntity)){
  1426. BigDecimal all = settlementAmount.add(settlementAmountEntity.getTotalAmount());
  1427. if(all.equals(totalAmount)){
  1428. baseMapper.updateByIds(split);
  1429. }
  1430. }
  1431. }
  1432. @Override
  1433. public HttpResult<InsPlyIncome> querySettInvoicing(InsPlyIncomeVo insPlyIncomeVo) {
  1434. HashMap<String, Object> params = new HashMap<>();
  1435. params = this.saveParams(insPlyIncomeVo, params);
  1436. InsPlyIncome insPlyIncome = baseMapper.queryInvoicing(params); //已经开票
  1437. return HttpResult.ok(insPlyIncome);
  1438. }
  1439. /**
  1440. *
  1441. * @param insPlyIncomeVo
  1442. * @return
  1443. */
  1444. @Override
  1445. public HttpResult<List<InsPlyIncome>> allOtherAmount(InsPlyIncomeVo insPlyIncomeVo) {
  1446. HashMap<String, Object> params = new HashMap<>();
  1447. params = this.saveParams(insPlyIncomeVo, params);
  1448. List<InsPlyIncome> result = baseMapper.allOtherAmount(params);
  1449. return HttpResult.ok(result);
  1450. }
  1451. @Override
  1452. @Transactional
  1453. public HttpResult<Object> batchInvoic(InsPlyIncomeVo insPlyIncomeVo) {
  1454. SettlementDocumentaryFeesVo settlementDocumentaryFeesVo = new SettlementDocumentaryFeesVo(); // 生成跟单费结算表
  1455. if(StringUtils.isNotEmpty(insPlyIncomeVo.getYear())){
  1456. settlementDocumentaryFeesVo.setTimeFrame(insPlyIncomeVo.getYear());//年度
  1457. }
  1458. if(!CollectionUtils.isEmpty(insPlyIncomeVo.getMultipleSelection())){
  1459. InsPlyIncomeVo insPlyIncomeVo1 = insPlyIncomeVo.getMultipleSelection().get(0);
  1460. insPlyIncomeVo.setSettlementAmount(insPlyIncomeVo1.getSettlementAmount());
  1461. insPlyIncomeVo.setOtherFeevalue(insPlyIncomeVo1.getAllTotalOtherFeevalue());
  1462. YearMonth yearMonth = YearMonth.parse(insPlyIncomeVo1.getMonthYear());
  1463. LocalDate signingTime = yearMonth.atDay(1);
  1464. settlementDocumentaryFeesVo.setSigningTime(signingTime);
  1465. }
  1466. if(StringUtils.isNotEmpty(insPlyIncomeVo.getYear())){
  1467. settlementDocumentaryFeesVo.setYear(insPlyIncomeVo.getYear());
  1468. }
  1469. if(StringUtils.isNotEmpty(insPlyIncomeVo.getMonth())){
  1470. settlementDocumentaryFeesVo.setMonth(insPlyIncomeVo.getMonth());
  1471. }
  1472. if(StringUtils.isNotEmpty(insPlyIncomeVo.getDay())){
  1473. settlementDocumentaryFeesVo.setDay(insPlyIncomeVo.getDay());
  1474. }
  1475. settlementDocumentaryFeesVo.setCompanyId(insPlyIncomeVo.getCompanyId());// 保险公司id
  1476. settlementDocumentaryFeesVo.setPartnerCompaniesId(insPlyIncomeVo.getPartnerCompaniesId()); //合作公司id
  1477. settlementDocumentaryFeesVo.setAgreementId(insPlyIncomeVo.getAgreementId());
  1478. settlementDocumentaryFeesVo.setTotalAmount(insPlyIncomeVo.getOtherFeevalue()); //其他费用金额
  1479. settlementDocumentaryFeesVo.setUnsettledAmount(insPlyIncomeVo.getNoInvoicCommissionFeevalue().subtract(insPlyIncomeVo.getSettlementAmount())); //未结算
  1480. settlementDocumentaryFeesVo.setSettlementAmount(insPlyIncomeVo.getSettlementAmount());//已经开票
  1481. settlementDocumentaryFeesVo.setCreateTime(LocalDateTime.now());
  1482. settlementDocumentaryFeesVo.setSettlementStatus("1");
  1483. settlementDocumentaryFeesVo.setIsNotCar(insPlyIncomeVo.getIsNotCar());
  1484. if(StringUtils.isNotEmpty(insPlyIncomeVo.getContractId())){
  1485. settlementDocumentaryFeesVo.setInvoiceId(insPlyIncomeVo.getContractId()); //开票号
  1486. }
  1487. if(StringUtils.isNotEmpty(insPlyIncomeVo.getTaskId())){
  1488. settlementDocumentaryFeesVo.setTaskId(insPlyIncomeVo.getTaskId());
  1489. }
  1490. settlementDocumentaryFeesVo.setHandlingFeesStatus(insPlyIncomeVo.getHandlingFeesStatus());
  1491. settlementDocumentaryFeesVo.setInvoicingMethod(insPlyIncomeVo.getInvoicingMethod()); //开票方式
  1492. settlementDocumentaryFeesVo.setTaxPoints(insPlyIncomeVo.getTaxPoints()); //税点
  1493. settlementDocumentaryFeesVo.setIds(insPlyIncomeVo.getIds());
  1494. // 税点支出
  1495. if( "0".equals(insPlyIncomeVo.getInvoicingMethod()) && BigDecimalUtils.nullToZero(insPlyIncomeVo.getTaxPoints()) !=null && insPlyIncomeVo.getTaxPoints().compareTo(BigDecimal.ZERO) != 0 && BigDecimalUtils.nullToZero(insPlyIncomeVo.getSettlementAmount()) !=null){
  1496. BigDecimal settlementAmount = insPlyIncomeVo.getSettlementAmount();
  1497. settlementDocumentaryFeesVo.setExpendAmount(settlementAmount.multiply(BigDecimal.ONE.subtract(insPlyIncomeVo.getTaxPoints().divide(new BigDecimal(100)))));
  1498. }else {
  1499. settlementDocumentaryFeesVo.setExpendAmount(insPlyIncomeVo.getSettlementAmount());
  1500. }
  1501. return settlementDocumentaryFeesService.inertSettle(settlementDocumentaryFeesVo);
  1502. }
  1503. @Override
  1504. public HttpResult pinHandlingexcel(InsPlyIncomeVo insPlyIncomeVo, HttpServletRequest request, HttpServletResponse response) {
  1505. HashMap<String, Object> params = new HashMap<>();
  1506. params =this.saveParams(insPlyIncomeVo,params);
  1507. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(params);
  1508. ExportParams exportParams = new ExportParams("平台手续费", null, ExcelType.HSSF);
  1509. exportParams.setStyle(ExcelStyleUtil.class);
  1510. List<SettlementFeesExcel> resultList = new ArrayList<>();
  1511. for (InsPlyIncome item :insPlyIncomes){
  1512. SettlementFeesExcel bxSettlementFeesExcel = new SettlementFeesExcel();
  1513. BeanUtils.copyProperties(item, bxSettlementFeesExcel);
  1514. if("1".equals(item.getHandlingFeesStatus())){
  1515. bxSettlementFeesExcel.setHandlingFeesStatus("已结算");
  1516. }else {
  1517. bxSettlementFeesExcel.setHandlingFeesStatus("未结算");
  1518. }
  1519. resultList.add(bxSettlementFeesExcel);
  1520. }
  1521. String uploadPath = this.uploadPath + "/excel/";
  1522. Path path = Paths.get(uploadPath);
  1523. if (!Files.exists(path)) {
  1524. try {
  1525. Files.createDirectories(path);
  1526. } catch (IOException e) {
  1527. e.printStackTrace();
  1528. }
  1529. }
  1530. String fileName = EasyExcelUtils.downExcel(uploadPath, "平台手续费导出", SettlementFeesExcel.class, resultList);
  1531. return HttpResult.ok("",uploadUrl + "excel/" + fileName);
  1532. }
  1533. @Override
  1534. public HttpResult bxHandlingexcel(InsPlyIncomeVo insPlyIncomeVo, HttpServletRequest request, HttpServletResponse response) {
  1535. HashMap<String, Object> params = new HashMap<>();
  1536. params =this.saveParams(insPlyIncomeVo,params);
  1537. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(params);
  1538. ExportParams exportParams = new ExportParams("保险手续费", null, ExcelType.HSSF);
  1539. exportParams.setStyle(ExcelStyleUtil.class);
  1540. List<BxSettlementFeesExcel> resultList = new ArrayList<>();
  1541. for (InsPlyIncome item :insPlyIncomes){
  1542. BxSettlementFeesExcel bxSettlementFeesExcel = new BxSettlementFeesExcel();
  1543. LocalDateTime signDate = item.getSignDate();
  1544. BeanUtils.copyProperties(item, bxSettlementFeesExcel);
  1545. resultList.add(bxSettlementFeesExcel);
  1546. }
  1547. String uploadPath = this.uploadPath + "/excel/";
  1548. Path path = Paths.get(uploadPath);
  1549. if (!Files.exists(path)) {
  1550. try {
  1551. Files.createDirectories(path);
  1552. } catch (IOException e) {
  1553. e.printStackTrace();
  1554. }
  1555. }
  1556. String fileName = EasyExcelUtils.downExcel(uploadPath, "保险手续费导出", BxSettlementFeesExcel.class, resultList);
  1557. return HttpResult.ok("",uploadUrl + "excel/" + fileName);
  1558. }
  1559. @Override
  1560. public HttpResult bxOtherExcel(InsPlyIncomeVo insPlyIncomeVo, HttpServletRequest request, HttpServletResponse response) {
  1561. HashMap<String, Object> params = new HashMap<>();
  1562. params =this.saveParams(insPlyIncomeVo,params);
  1563. params.put("agreementType","2");
  1564. params.put("isOther","1");
  1565. params.put("isNotCar","0");
  1566. List<InsPlyIncome> insPlyIncomes = baseMapper.allOtherAmount(params);
  1567. ExportParams exportParams = new ExportParams("跟单费导出", null, ExcelType.HSSF);
  1568. exportParams.setStyle(ExcelStyleUtil.class);
  1569. List<BxOtherExcel> resultList = new ArrayList<>();
  1570. for (InsPlyIncome item :insPlyIncomes){
  1571. BxOtherExcel bxSettlementFeesExcel = new BxOtherExcel();
  1572. BeanUtils.copyProperties(item, bxSettlementFeesExcel);
  1573. resultList.add(bxSettlementFeesExcel);
  1574. }
  1575. String uploadPath = this.uploadPath + "/excel/";
  1576. Path path = Paths.get(uploadPath);
  1577. if (!Files.exists(path)) {
  1578. try {
  1579. Files.createDirectories(path);
  1580. } catch (IOException e) {
  1581. e.printStackTrace();
  1582. }
  1583. }
  1584. String fileName = EasyExcelUtils.downExcel(uploadPath, "跟单费导出", BxOtherExcel.class, resultList);
  1585. return HttpResult.ok("",uploadUrl + "excel/" + fileName);
  1586. }
  1587. @Override
  1588. public InsPlyIncome bxTotalAmount(InsPlyIncomeVo insPlyIncomeVo) {
  1589. HashMap<String, Object> params = new HashMap<>();
  1590. params = this.saveParams(insPlyIncomeVo, params);
  1591. InsPlyIncome totalledAmount =baseMapper.bxTotalAmount(params); //总金额
  1592. return totalledAmount;
  1593. }
  1594. @Override
  1595. public InsPlyIncome ptTotalAmount(InsPlyIncomeVo insPlyIncomeVo) {
  1596. HashMap<String, Object> params = new HashMap<>();
  1597. params = this.saveParams(insPlyIncomeVo, params);
  1598. InsPlyIncome totalledAmount =baseMapper.ptTotalAmount(params); //总金额
  1599. return totalledAmount;
  1600. }
  1601. @Override
  1602. public HttpResult<List<HashMap<String,Object>>> otherTimeDetail(InsPlyIncomeVo insPlyIncomeVo) {
  1603. HashMap<String, Object> params = new HashMap<>();
  1604. this.saveParams(insPlyIncomeVo,params);
  1605. List<HashMap<String,Object>> resultMap=baseMapper.otherTimeDetail(params);
  1606. Set<String> uniqueYears = new HashSet<>();
  1607. for (Map<String, Object> map : resultMap) {
  1608. // 假设年份是以 "year" 为键的,并且它的值是 String 类型
  1609. String year = String.valueOf(map.get("year")) ;
  1610. if (year != null) { // 确保年份不是 null
  1611. uniqueYears.add(year);
  1612. }
  1613. }
  1614. this.addMonthYear(uniqueYears,resultMap);
  1615. return HttpResult.ok(resultMap);
  1616. }
  1617. /**
  1618. * uniqueYears 年份间隔 resultMap 返回结果
  1619. * @param uniqueYears
  1620. * @param resultMap 返回一到十二月数据
  1621. */
  1622. private void addMonthYear(Set<String> uniqueYears, List<HashMap<String, Object>> resultMap) {
  1623. // 存储已存在的年份-月份组合,以便快速查找
  1624. Set<String> existingYearMonths = new HashSet<>();
  1625. for (Map<String, Object> entry : resultMap) {
  1626. String year = String.valueOf(entry.get("year")) ;
  1627. int month = (Integer) entry.get("monthNumber");
  1628. existingYearMonths.add(year + "-" + month);
  1629. }
  1630. // 遍历所有年份和月份,并添加缺失的条目
  1631. for (String year : uniqueYears) {
  1632. for (int month = 1; month <= 12; month++) {
  1633. String yearMonth = year + "-" + month;
  1634. if (!existingYearMonths.contains(yearMonth)) {
  1635. // 创建一个新的条目并添加到resultMap中
  1636. HashMap<String, Object> newEntry = new HashMap<>();
  1637. newEntry.put("year", year);
  1638. newEntry.put("monthNumber", month);
  1639. newEntry.put("allTotalOtherFeevalue", 0);
  1640. newEntry.put("invoicCommissionFeevalue", 0);
  1641. newEntry.put("monthYear", yearMonth);
  1642. newEntry.put("noInvoicCommissionFeevalue", 0);
  1643. resultMap.add(newEntry);
  1644. }
  1645. }
  1646. }
  1647. // 使用自定义Comparator对resultMap进行排序
  1648. Collections.sort(resultMap, new Comparator<HashMap<String, Object>>() {
  1649. @Override
  1650. public int compare(HashMap<String, Object> o1, HashMap<String, Object> o2) {
  1651. // 比较 year
  1652. String year1 = String.valueOf(o1.get("year")) ;
  1653. String year2 =String.valueOf(o2.get("year"));
  1654. int yearComparison = year1.compareTo(year2);
  1655. if (yearComparison != 0) {
  1656. return yearComparison;
  1657. }
  1658. // 如果 year 相同,则比较 monthNumber
  1659. Integer monthNum1 = (Integer) o1.get("monthNumber");
  1660. Integer monthNum2 = (Integer) o2.get("monthNumber");
  1661. return monthNum1.compareTo(monthNum2);
  1662. }
  1663. });
  1664. }
  1665. @Override
  1666. public HttpResult<Object> singleInvoic(InsPlyIncomeVo insPlyIncomeVo) {
  1667. // 通过ids 查出跟单非结算单
  1668. SettlementDocumentaryFeesVo settlementDocumentaryFeesVo = new SettlementDocumentaryFeesVo(); // 生成跟单费结算表
  1669. if (!CollectionUtils.isEmpty(insPlyIncomeVo.getMultipleSelection())) {
  1670. for (InsPlyIncomeVo insPlyIncomeVo1 : insPlyIncomeVo.getMultipleSelection()) {
  1671. insPlyIncomeVo.setSettlementAmount(insPlyIncomeVo1.getSettlementAmount());
  1672. insPlyIncomeVo.setOtherFeevalue(insPlyIncomeVo1.getAllTotalOtherFeevalue());
  1673. YearMonth yearMonth = YearMonth.parse(insPlyIncomeVo1.getMonthYear());
  1674. LocalDate signingTime = yearMonth.atDay(1);
  1675. settlementDocumentaryFeesVo.setSigningTime(signingTime);
  1676. }
  1677. }
  1678. if (StringUtils.isNotEmpty(insPlyIncomeVo.getYear())) {
  1679. settlementDocumentaryFeesVo.setTimeFrame(insPlyIncomeVo.getYear());//年度
  1680. }
  1681. if (StringUtils.isNotEmpty(insPlyIncomeVo.getYear())) {
  1682. settlementDocumentaryFeesVo.setYear(insPlyIncomeVo.getYear());
  1683. }
  1684. if (StringUtils.isNotEmpty(insPlyIncomeVo.getMonth())) {
  1685. settlementDocumentaryFeesVo.setMonth(insPlyIncomeVo.getMonth());
  1686. }
  1687. if (StringUtils.isNotEmpty(insPlyIncomeVo.getDay())) {
  1688. settlementDocumentaryFeesVo.setDay(insPlyIncomeVo.getDay());
  1689. }
  1690. settlementDocumentaryFeesVo.setCompanyId(insPlyIncomeVo.getCompanyId());// 保险公司id
  1691. settlementDocumentaryFeesVo.setPartnerCompaniesId(insPlyIncomeVo.getPartnerCompaniesId()); //合作公司id
  1692. settlementDocumentaryFeesVo.setTotalAmount(insPlyIncomeVo.getOtherFeevalue()); //其他费用金额
  1693. settlementDocumentaryFeesVo.setUnsettledAmount(insPlyIncomeVo.getNoInvoicCommissionFeevalue().subtract(insPlyIncomeVo.getSettlementAmount())); //未结算
  1694. settlementDocumentaryFeesVo.setSettlementAmount(insPlyIncomeVo.getSettlementAmount());//已经开票
  1695. settlementDocumentaryFeesVo.setCreateTime(LocalDateTime.now());
  1696. settlementDocumentaryFeesVo.setIds(insPlyIncomeVo.getIncomeIds());
  1697. settlementDocumentaryFeesVo.setSettlementStatus("1");
  1698. settlementDocumentaryFeesVo.setIsNotCar(insPlyIncomeVo.getIsNotCar());
  1699. if (StringUtils.isNotEmpty(insPlyIncomeVo.getContractId())) {
  1700. settlementDocumentaryFeesVo.setInvoiceId(insPlyIncomeVo.getContractId()); //开票号
  1701. }
  1702. settlementDocumentaryFeesVo.setHandlingFeesStatus(insPlyIncomeVo.getHandlingFeesStatus());
  1703. settlementDocumentaryFeesVo.setInvoicingMethod(insPlyIncomeVo.getInvoicingMethod()); //开票方式
  1704. settlementDocumentaryFeesVo.setTaxPoints(insPlyIncomeVo.getTaxPoints()); //税点
  1705. settlementDocumentaryFeesVo.setIds(insPlyIncomeVo.getIds());
  1706. settlementDocumentaryFeesVo.setSigningTime(insPlyIncomeVo.getSettlementTime()); //签单日期
  1707. // 税点支出
  1708. if (BigDecimalUtils.nullToZero(insPlyIncomeVo.getTaxPoints()) != null && BigDecimalUtils.nullToZero(insPlyIncomeVo.getSettlementAmount()) != null) {
  1709. BigDecimal settlementAmount = insPlyIncomeVo.getSettlementAmount();
  1710. settlementDocumentaryFeesVo.setExpendAmount(settlementAmount.multiply(BigDecimal.ONE.subtract(insPlyIncomeVo.getTaxPoints().divide(new BigDecimal(100)))));
  1711. }
  1712. settlementDocumentaryFeesService.inertSettle(settlementDocumentaryFeesVo);
  1713. return HttpResult.ok();
  1714. }
  1715. @Override
  1716. public void batchUpdate(InsPlyIncomeVo insPlyIncomeVo) {
  1717. HashMap<String, Object> params = new HashMap<>();
  1718. params= this.saveParams(insPlyIncomeVo,params);
  1719. List<InsPlyIncome> list= this.baseMapper.queryNew(params);
  1720. for ( InsPlyIncome item : list){
  1721. item.setContractFileId( insPlyIncomeVo.getContractFileId());
  1722. item.setSettleOtherStatus("1");
  1723. baseMapper.updateById(item);
  1724. }
  1725. }
  1726. @Override
  1727. @Transactional
  1728. public HashMap<String, Object> bxImportOther(MultipartFile multipartFile,String isNotCar) {
  1729. HashMap<String, Object> resultMap = new HashMap<>();
  1730. List<HashMap<String,Object>> resultList=new ArrayList<>();
  1731. HashMap<String, Object> params = new HashMap<>();
  1732. BigDecimal allAmount = BigDecimal.ZERO;
  1733. params.put("isNotCar",isNotCar);
  1734. try {
  1735. List<InsBxOtherExcelDto> dtoList = ExcelEasypoiUtils.importExcel(multipartFile, InsBxOtherExcelDto.class, 0, 1, 1);
  1736. for (InsBxOtherExcelDto item : dtoList){
  1737. if(StringUtils.isNotEmpty(item.getLicenseno())){
  1738. params.put("licenseno",item.getLicenseno());
  1739. }
  1740. if(StringUtils.isNotEmpty(item.getPolicyno())){
  1741. params.put("policyno",item.getPolicyno());
  1742. }
  1743. if(StringUtils.isNotEmpty(item.getSyPolicyno())){
  1744. params.put("syPolicyno",item.getSyPolicyno());
  1745. }
  1746. params.put("handlingFeesStatus","0");
  1747. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  1748. if (item.getJqOtherCostsProportion() ==null){
  1749. item.setJqOtherCostsProportion(BigDecimal.ZERO);
  1750. }
  1751. if(item.getSyOtherCostsProportion() == null){
  1752. item.setSyOtherCostsProportion(BigDecimal.ZERO);
  1753. }
  1754. if(byBxLicenseno.getJqOtherCostsProportion().compareTo(item.getJqOtherCostsProportion()) !=0 || byBxLicenseno.getSyOtherCostsProportion().compareTo(item.getSyOtherCostsProportion()) != 0){
  1755. // 如果比例不相等
  1756. BigDecimal jqOtherCostsProportion = item.getJqOtherCostsProportion();
  1757. BigDecimal syOtherCostsProportion = item.getSyOtherCostsProportion();
  1758. BigDecimal jqNoTaxPremium = byBxLicenseno.getJqNoTaxPremium();//交强不含税保费
  1759. BigDecimal syNoTaxPremium = byBxLicenseno.getSyNoTaxPremium();// 商业不含税比例
  1760. BigDecimal jqOtherAmount = jqNoTaxPremium.multiply(item.getJqOtherCostsProportion().divide(new BigDecimal(100))); //交强跟单费用
  1761. BigDecimal syOtherAmount = syNoTaxPremium.multiply(item.getSyOtherCostsProportion().divide(new BigDecimal(100)));
  1762. byBxLicenseno.setJqOtherCostsPremium(jqOtherAmount);
  1763. byBxLicenseno.setSyOtherCostsPremium(syOtherAmount);
  1764. byBxLicenseno.setJqOtherCostsProportion(jqOtherCostsProportion);
  1765. byBxLicenseno.setSyOtherCostsProportion(syOtherCostsProportion);
  1766. byBxLicenseno.setOtherFeevalue(this.calculateTotal(jqOtherAmount,syOtherAmount,null));
  1767. byBxLicenseno.setOtherFeerate(this.calculateTotal(jqOtherCostsProportion,syOtherCostsProportion ,null));
  1768. baseMapper.updateById(byBxLicenseno);
  1769. HashMap<String, Object> map = new HashMap<>();
  1770. map.put("licenseno",item.getLicenseno());
  1771. map.put("policyno",item.getPolicyno());
  1772. map.put("syPolicyno",item.getSyPolicyno());
  1773. map.put("jqOtherCostsPremium",jqOtherAmount);
  1774. map.put("syOtherCostsProportion",syOtherAmount);
  1775. map.put("otherFeevalue",byBxLicenseno.getOtherFeevalue());
  1776. map.put("otherFeerate",byBxLicenseno.getOtherFeerate());
  1777. resultList.add(map);
  1778. allAmount = allAmount.add(jqOtherAmount).add(syOtherAmount);
  1779. }
  1780. }
  1781. resultMap.put("allAmount",allAmount);
  1782. resultMap.put("resultList",resultList);
  1783. } catch (IOException e) {
  1784. throw new RuntimeException(e);
  1785. }
  1786. return resultMap;
  1787. }
  1788. @Override
  1789. @Transactional
  1790. public HashMap<String, Object> noBxImportOther(MultipartFile multipartFile, String isNotCar) {
  1791. HashMap<String, Object> resultMap = new HashMap<>();
  1792. List<HashMap<String,Object>> resultList=new ArrayList<>();
  1793. HashMap<String, Object> params = new HashMap<>();
  1794. BigDecimal allAmount = BigDecimal.ZERO;
  1795. params.put("isNotCar",isNotCar);
  1796. try {
  1797. List<InsNoBxOtherExcelDto> dtoList = ExcelEasypoiUtils.importExcel(multipartFile, InsNoBxOtherExcelDto.class, 0, 1, 1);
  1798. for (InsNoBxOtherExcelDto item : dtoList){
  1799. if(StringUtils.isNotEmpty(item.getLicenseno())){
  1800. params.put("licenseno",item.getLicenseno());
  1801. }
  1802. if(StringUtils.isNotEmpty(item.getNoPolicyno())){
  1803. params.put("noPolicyno",item.getNoPolicyno());
  1804. }
  1805. params.put("handlingFeesStatus","0");
  1806. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  1807. if(byBxLicenseno.getNoOtherCostsProportion().compareTo(item.getNoOtherCostsProportion()) !=0 ){
  1808. // 如果比例不相等
  1809. BigDecimal noOtherCostsProportion = item.getNoOtherCostsProportion();
  1810. BigDecimal noNoTaxPremium = byBxLicenseno.getNoNoTaxPremium();
  1811. BigDecimal noOtherAmount = noNoTaxPremium.multiply(item.getNoOtherCostsProportion().divide(new BigDecimal(100))); //交强跟单费用
  1812. byBxLicenseno.setOtherFeevalue(this.calculateTotal(noOtherAmount,null,null));
  1813. byBxLicenseno.setOtherFeerate(this.calculateTotal(noOtherCostsProportion,null ,null));
  1814. baseMapper.updateById(byBxLicenseno);
  1815. resultMap.put("licenseno",item.getLicenseno());
  1816. resultMap.put("noPolicyno",item.getNoPolicyno());
  1817. resultMap.put("noOtherCostsPremium",noOtherAmount);
  1818. resultMap.put("otherFeevalue",byBxLicenseno.getOtherFeevalue());
  1819. resultMap.put("otherFeerate",byBxLicenseno.getOtherFeerate());
  1820. resultList.add(resultMap);
  1821. allAmount = allAmount.add(noOtherAmount);
  1822. }
  1823. }
  1824. resultMap.put("allAmount",allAmount);
  1825. } catch (IOException e) {
  1826. throw new RuntimeException(e);
  1827. }
  1828. return resultMap;
  1829. }
  1830. @Override
  1831. public void batchUpdateVoucher(InsPlyIncomeVo insPlyIncomeVo) {
  1832. String s = insPlyIncomeVo.getSelectIds().get(0);
  1833. ImportResult importResult = importAsyncService.getById(s);
  1834. String[] split = importResult.getIds().split(",");
  1835. InsPlyIncome insPlyIncome = new InsPlyIncome();
  1836. for (String id :split){
  1837. insPlyIncome.setId(id);
  1838. insPlyIncome.setSettlementImageId(insPlyIncomeVo.getSettlementImageId());
  1839. insPlyIncome.setSettleOtherStatus("1");
  1840. baseMapper.updateById(insPlyIncome);
  1841. }
  1842. }
  1843. }