InsPlyIncomeServiceImpl.java 99 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819
  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.InsAreaCompany;
  20. import com.ydtech.modules.fnc.entity.InsPlyIncome;
  21. import com.ydtech.modules.fnc.dao.InsPlyIncomeMapper;
  22. import com.ydtech.modules.fnc.entity.SettlementDocumentaryFeesEntity;
  23. import com.ydtech.modules.fnc.entity.SettlementDocumentaryLogEntity;
  24. import com.ydtech.modules.fnc.service.InsPlyIncomeService;
  25. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  26. import com.ydtech.modules.fnc.service.SettlementDocumentaryFeesService;
  27. import com.ydtech.modules.fnc.service.SettlementDocumentaryLogService;
  28. import com.ydtech.modules.fnc.vo.InsPlyIncomeVo;
  29. import com.ydtech.modules.fnc.vo.SettlementDocumentaryFeesVo;
  30. import com.ydtech.modules.ins.model.vo.res.*;
  31. import com.ydtech.modules.inv.model.InvChannelsExternalBillsDetails;
  32. import com.ydtech.modules.inv.model.dto.*;
  33. import com.ydtech.modules.inv.model.excel.InvDisburseExcel;
  34. import com.ydtech.modules.inv.utils.EasyExcelUtils;
  35. import com.ydtech.modules.order.entity.BasePageResult;
  36. import com.ydtech.modules.order.entity.InsOrders;
  37. import com.ydtech.modules.order.service.InsAreaCompanyService;
  38. import com.ydtech.modules.order.service.InsOrdersService;
  39. import com.ydtech.modules.protocol.entity.po.PtlAgreement;
  40. import com.ydtech.modules.protocol.entity.vo.PtlAgreementQueryVo;
  41. import com.ydtech.modules.protocol.service.PtlAgreementService;
  42. import com.ydtech.modules.protocols.entity.po.InsFeeOrderNew;
  43. import com.ydtech.modules.protocols.service.InsFeeOrderNewService;
  44. import com.ydtech.utils.BigDecimalUtils;
  45. import com.ydtech.utils.SnowFlakeUtil;
  46. import com.ydtech.utils.StringOperations;
  47. import com.ydtech.utils.excel.ExcelEasypoiUtils;
  48. import com.ydtech.utils.excel.ExcelStyleUtil;
  49. import com.ydtech.utils.excel.ExcelUtils2;
  50. import lombok.extern.slf4j.Slf4j;
  51. import org.apache.commons.lang3.ObjectUtils;
  52. import org.apache.commons.lang3.StringUtils;
  53. import org.apache.poi.ss.formula.functions.Now;
  54. import org.springframework.beans.BeanUtils;
  55. import org.springframework.beans.factory.annotation.Autowired;
  56. import org.springframework.beans.factory.annotation.Value;
  57. import org.springframework.context.annotation.Lazy;
  58. import org.springframework.stereotype.Service;
  59. import org.springframework.transaction.annotation.Transactional;
  60. import org.springframework.util.CollectionUtils;
  61. import org.springframework.web.multipart.MultipartFile;
  62. import redis.clients.jedis.params.Params;
  63. import javax.servlet.http.HttpServletRequest;
  64. import javax.servlet.http.HttpServletResponse;
  65. import java.awt.image.BandedSampleModel;
  66. import java.io.IOException;
  67. import java.math.BigDecimal;
  68. import java.nio.file.Files;
  69. import java.nio.file.Path;
  70. import java.nio.file.Paths;
  71. import java.time.LocalDate;
  72. import java.time.LocalDateTime;
  73. import java.time.YearMonth;
  74. import java.util.*;
  75. import java.util.concurrent.CompletableFuture;
  76. import java.util.concurrent.ConcurrentHashMap;
  77. import java.util.stream.Collectors;
  78. /**
  79. * <p>
  80. * 保司结算手续费 服务实现类
  81. * </p>
  82. *
  83. * @author gws
  84. * @since 2024-01-05
  85. */
  86. @Slf4j
  87. @Service
  88. public class InsPlyIncomeServiceImpl extends ServiceImpl<InsPlyIncomeMapper, InsPlyIncome> implements InsPlyIncomeService {
  89. @Autowired
  90. @Lazy
  91. private InsOrdersService insOrdersService;
  92. @Autowired
  93. private InsAreaCompanyService insAreaCompanyService;
  94. @Autowired
  95. private InsFeeOrderNewService insFeeOrderNewService;
  96. @Autowired
  97. private SettlementDocumentaryFeesService settlementDocumentaryFeesService;
  98. @Autowired
  99. private SettlementDocumentaryLogService settlementDocumentaryLogService;
  100. @Autowired
  101. private PtlAgreementService ptlAgreementService;
  102. @Autowired
  103. private EsmInsCompanyService EsmInsCompanyService;
  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.getDeptId())){
  550. params.put("deptId",insPlyIncomeVo.getDeptId());
  551. }
  552. if(!CollectionUtils.isEmpty(insPlyIncomeVo.getSelectIds())){
  553. params.put("selectIds",insPlyIncomeVo.getSelectIds());
  554. }
  555. if(!CollectionUtils.isEmpty(insPlyIncomeVo.getPartnerCompaniesIdList())){
  556. params.put("partnerCompaniesIdList",insPlyIncomeVo.getPartnerCompaniesIdList());
  557. }
  558. return params;
  559. }
  560. @Override
  561. public HttpResult<BasePageResult<InsPlyIncome>> nonSettlementQuery(InsPlyIncomeVo insPlyIncomeVo) {
  562. try{
  563. HashMap<String, Object> params = new HashMap<>();
  564. PageInfo<List<InsPlyIncome>> pageHelper = null;
  565. PageHelper.startPage(insPlyIncomeVo.getPageNum(),insPlyIncomeVo.getPageSize());
  566. params.put("pageNum",insPlyIncomeVo.getPageNum());
  567. params.put("pageSize",insPlyIncomeVo.getPageSize());
  568. if(StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotCar())){
  569. params.put("isNotCar",insPlyIncomeVo.getIsNotCar());
  570. }
  571. if(StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotDocumentary())){
  572. params.put("isOther",insPlyIncomeVo.getIsNotDocumentary());
  573. }
  574. if(StringUtils.isNotEmpty(insPlyIncomeVo.getYear())){
  575. params.put("year",insPlyIncomeVo.getYear());
  576. }
  577. if(StringUtils.isNotEmpty(insPlyIncomeVo.getMonth())){
  578. params.put("month",insPlyIncomeVo.getMonth());
  579. }
  580. if(StringUtils.isNotEmpty(insPlyIncomeVo.getDocumentaryFeesStatus())){
  581. params.put("documentaryFeesStatus",insPlyIncomeVo.getDocumentaryFeesStatus());
  582. }
  583. List<InsPlyIncome> list= this.baseMapper.NonSettlementQuery(params);
  584. pageHelper=new PageInfo(list);
  585. BasePageResult<InsPlyIncome> pageResult=new BasePageResult<InsPlyIncome>(insPlyIncomeVo.getPageNum(), insPlyIncomeVo.getPageSize(), pageHelper.getTotal(), pageHelper.getPages(), list);
  586. return HttpResult.ok(pageResult);
  587. }catch (Exception e){
  588. e.printStackTrace();
  589. return HttpResult.error("查询异常");
  590. }
  591. }
  592. @Override
  593. public HttpResult<List<InsPlyIncome>> nonSettldetail(InsPlyIncomeVo insPlyIncomeVo) {
  594. try {
  595. String ids = insPlyIncomeVo.getIds();
  596. ArrayList<InsPlyIncome> resultList = new ArrayList<>();
  597. if (ObjectUtils.isNotEmpty(ids)) {
  598. String[] split = ids.split(",");
  599. for (int i =0; i <split.length ; i++) {
  600. String id = split[i];
  601. resultList.add(this.baseMapper.getById(id));
  602. }
  603. }
  604. return HttpResult.ok(resultList);
  605. } catch (Exception e) {
  606. e.printStackTrace();
  607. return HttpResult.error("查询异常");
  608. }
  609. }
  610. /**
  611. *
  612. * @param multipartFile
  613. * @return totalAmount 总金额
  614. * totalHandingAmount 总手续费金额
  615. * totalOtherAmount 总跟单费金额
  616. * resultHashMap 返回 ids 已经上面的金额
  617. * resultNoSelect 未匹配的车牌号
  618. */
  619. @Override
  620. public HashMap<String, Object> importData(MultipartFile multipartFile) {
  621. BigDecimal totalAmount=BigDecimal.ZERO;
  622. BigDecimal totalHandingAmount=BigDecimal.ZERO;
  623. BigDecimal totalOtherAmount=BigDecimal.ZERO;
  624. HashMap<String, Object> params = new HashMap<>();
  625. HashMap<String, Object> resultHashMap = new HashMap<>();
  626. ArrayList<HashMap<String,Object>> resultNoSelect = new ArrayList<>();
  627. StringBuffer strBuilder = new StringBuffer();
  628. try {
  629. List<InsPlyIncomeExcelDto> dtoList = ExcelEasypoiUtils.importExcel(multipartFile, InsPlyIncomeExcelDto.class, 0, 1, 1);
  630. for (InsPlyIncomeExcelDto excelItem : dtoList) {
  631. params.clear();
  632. if(StringUtils.isNotEmpty(excelItem.getLicenseno())){
  633. params.put("licenseno",excelItem.getLicenseno());//车牌号
  634. }
  635. if(StringUtils.isNotEmpty(excelItem.getPolicyno())){
  636. params.put("policyno",excelItem.getPolicyno()); //交强保单号
  637. }
  638. if(StringUtils.isNotEmpty(excelItem.getSyPolicyno())){
  639. params.put("syPolicyno", excelItem.getSyPolicyno());//商业保单号
  640. }
  641. if(StringUtils.isNotEmpty(excelItem.getNoPolicyno())){
  642. params.put("noPolicyno",excelItem.getNoPolicyno()); //非车保单号
  643. }
  644. InsPlyIncome insPlyIncome=baseMapper.findByLicenseno(params);
  645. if(ObjectUtils.isNotEmpty(insPlyIncome)){
  646. strBuilder.append(insPlyIncome.getId()).append(",");
  647. if(insPlyIncome.getAllFeeValue()!=null && insPlyIncome.getAllFeeValue().compareTo(BigDecimal.ZERO)!=0){
  648. totalAmount = totalAmount.add(insPlyIncome.getAllFeeValue()); //总金额
  649. }
  650. if(insPlyIncome.getCommissionFeevalue()!=null && insPlyIncome.getCommissionFeevalue().compareTo(BigDecimal.ZERO)!=0){
  651. totalHandingAmount=totalHandingAmount.add(insPlyIncome.getCommissionFeevalue()); //总手续费
  652. }
  653. if(insPlyIncome.getOtherFeevalue()!=null && insPlyIncome.getOtherFeevalue().compareTo(BigDecimal.ZERO)!=0){
  654. totalOtherAmount=totalOtherAmount.add(insPlyIncome.getOtherFeevalue()); //总跟单费
  655. }
  656. }else {
  657. resultNoSelect.add(params); // 添加未匹配的车牌号
  658. }
  659. }
  660. if(strBuilder.length() >0){
  661. String ids = strBuilder.deleteCharAt(strBuilder.length() - 1).toString();
  662. resultHashMap.put("ids",ids);
  663. }
  664. resultHashMap.put("totalAmount",totalAmount);
  665. resultHashMap.put("totalHandingAmount",totalHandingAmount);
  666. resultHashMap.put("totalOtherAmount",totalOtherAmount);
  667. resultHashMap.put("resultList",resultNoSelect);
  668. return resultHashMap;
  669. } catch (IOException e) {
  670. throw new SystemException("导入失败!");
  671. }
  672. }
  673. /**
  674. *
  675. * @param multipartFile
  676. * @return resultList 包含总金额 还有 未匹配表中的数据
  677. */
  678. @Override
  679. public HashMap<String, Object> bxImportData(MultipartFile multipartFile,String isNotCar) {
  680. BigDecimal totalAmount=BigDecimal.ZERO;
  681. HashMap<String, Object> params = new HashMap<>();
  682. ArrayList<HashMap<String, Object>> resultList = new ArrayList<>();
  683. HashMap<String, Object> resultMap = new HashMap<>();
  684. StringBuffer strBuilder = new StringBuffer();
  685. boolean open=true;
  686. String ids="";
  687. try {
  688. List<InsBxPlyIncomeExcelDto> dtoList = ExcelEasypoiUtils.importExcel(multipartFile, InsBxPlyIncomeExcelDto.class, 0, 1, 1);
  689. Integer i=0;
  690. if(!CollectionUtils.isEmpty(dtoList)){
  691. for (InsBxPlyIncomeExcelDto excelItem : dtoList) {
  692. String reason ="";
  693. i=i+1;
  694. params.clear();
  695. if(StringUtils.isNotEmpty(excelItem.getLicenseno())){
  696. String licenseno = excelItem.getLicenseno();//车牌号
  697. params.put("licenseno",licenseno);
  698. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  699. if(ObjectUtils.isEmpty(byBxLicenseno)){
  700. reason="该数据车牌号有问题";
  701. }
  702. }
  703. if(StringUtils.isNotEmpty(excelItem.getPolicyno())){
  704. String policyno = excelItem.getPolicyno(); //交强保单号
  705. params.put("policyno",policyno);
  706. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  707. if(ObjectUtils.isEmpty(byBxLicenseno)){
  708. reason="该数据交强保单号有问题";
  709. }
  710. }
  711. if(StringUtils.isNotEmpty(excelItem.getSyPolicyno())){
  712. String syPolicyno = excelItem.getSyPolicyno(); //商业保单号
  713. params.put("syPolicyno",syPolicyno);
  714. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  715. if(ObjectUtils.isEmpty(byBxLicenseno)){
  716. reason="该数据商业保单号有问题";
  717. }
  718. }
  719. if(excelItem.getJqSuperviseCostsPremiums() !=null && excelItem.getJqSuperviseCostsPremiums().compareTo(BigDecimal.ZERO)!=0){
  720. params.put("jqSuperviseCostsPremiums",excelItem.getJqSuperviseCostsPremiums());
  721. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  722. if(ObjectUtils.isEmpty(byBxLicenseno)){
  723. reason="该数据交强手续费金额有问题";
  724. }
  725. }
  726. if(excelItem.getJqSuperviseCostsProportion() !=null && excelItem.getJqSuperviseCostsProportion().compareTo(BigDecimal.ZERO)!=0){
  727. params.put("jqSuperviseCostsProportion",excelItem.getJqSuperviseCostsProportion());
  728. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  729. if(ObjectUtils.isEmpty(byBxLicenseno)){
  730. reason="该数据交强手续费比例有问题";
  731. }
  732. }
  733. if(excelItem.getSySuperviseCostsProportion() !=null && excelItem.getSySuperviseCostsProportion().compareTo(BigDecimal.ZERO)!=0){
  734. params.put("sySuperviseCostsProportion",excelItem.getSySuperviseCostsProportion());
  735. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  736. if(ObjectUtils.isEmpty(byBxLicenseno)){
  737. reason="该数据商业手续费比例有问题";
  738. }
  739. }
  740. if(excelItem.getSySuperviseCostsPremiums() !=null && excelItem.getSySuperviseCostsPremiums().compareTo(BigDecimal.ZERO)!=0){
  741. params.put("sySuperviseCostsPremiums",excelItem.getSySuperviseCostsPremiums());
  742. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  743. if(ObjectUtils.isEmpty(byBxLicenseno)){
  744. reason="该数据商业手续费金额有问题";
  745. }
  746. }
  747. if(excelItem.getJqPremium() !=null && excelItem.getJqPremium().compareTo(BigDecimal.ZERO)!=0){
  748. params.put("jqPremium",excelItem.getJqPremium());
  749. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  750. if(ObjectUtils.isEmpty(byBxLicenseno)){
  751. reason="该数据交强保费有问题";
  752. }
  753. }
  754. if(excelItem.getSyPremium() !=null && excelItem.getSyPremium().compareTo(BigDecimal.ZERO)!=0){
  755. params.put("syPremium",excelItem.getSyPremium());
  756. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  757. if(ObjectUtils.isEmpty(byBxLicenseno)){
  758. reason="该数据商业保费有问题";
  759. }
  760. }
  761. // 只查手续费
  762. params.put("isOther","0");
  763. params.put("isNotCar",isNotCar);
  764. InsPlyIncome insPlyIncome = baseMapper.findByBxLicenseno(params);
  765. if(ObjectUtils.isNotEmpty(insPlyIncome) && open){
  766. open=false;
  767. resultMap.put("companyId",insPlyIncome.getCompanyId()); // 保险公司id
  768. resultMap.put("partnerCompaniesId",insPlyIncome.getPartnerCompaniesId()); //合作公司id
  769. resultMap.put("agreementId",insPlyIncome.getAgreementId()); //协议id
  770. }
  771. if(ObjectUtils.isNotEmpty(insPlyIncome)){ // 比配上汇总金额 未匹配则返回到数据当中
  772. strBuilder.append(insPlyIncome.getId()).append(",");
  773. if( insPlyIncome.getCommissionFeevalue()!=null && insPlyIncome.getCommissionFeevalue().compareTo(BigDecimal.ZERO)!=0){
  774. totalAmount = totalAmount.add(insPlyIncome.getCommissionFeevalue()); //添加总手续费
  775. }
  776. }else {
  777. HashMap<String, Object> noMatching = new HashMap<>();
  778. if(StringUtils.isNotEmpty(excelItem.getLicenseno())){
  779. noMatching.put("licenseno",excelItem.getLicenseno());
  780. }
  781. if(StringUtils.isNotEmpty(excelItem.getPolicyno())){
  782. noMatching.put("policyno",excelItem.getPolicyno());
  783. }
  784. if(StringUtils.isNotEmpty(excelItem.getSyPolicyno())){
  785. noMatching.put("syPolicyno",excelItem.getSyPolicyno());
  786. }
  787. resultList.add(noMatching);
  788. }
  789. resultMap.put("reason",reason);
  790. }
  791. }
  792. if(strBuilder.length() >0){
  793. ids = strBuilder.deleteCharAt(strBuilder.length() - 1).toString();
  794. }
  795. resultMap.put("ids",ids);
  796. resultMap.put("totalAmount",totalAmount);
  797. resultMap.put("resultList",resultList);
  798. return resultMap;
  799. } catch (IOException e) {
  800. throw new SystemException("导入失败!");
  801. }
  802. }
  803. @Override
  804. public HashMap<String, Object> bxImportNoData(MultipartFile multipartFile,String isNotCar) {
  805. BigDecimal totalAmount=BigDecimal.ZERO;
  806. HashMap<String, Object> params = new HashMap<>();
  807. HashMap<String, Object> resultMap = new HashMap<>();
  808. ArrayList<HashMap<String, Object>> resultList = new ArrayList<>();
  809. StringBuffer strBuilder = new StringBuffer();
  810. String ids="";
  811. try {
  812. Integer i=0;
  813. List<InsBxNoPlyIncomeExcelDto> dtoList = ExcelEasypoiUtils.importExcel(multipartFile, InsBxNoPlyIncomeExcelDto.class, 0, 1, 1);
  814. if(!CollectionUtils.isEmpty(dtoList)){
  815. for (InsBxNoPlyIncomeExcelDto excelItem : dtoList) {
  816. String reason ="";
  817. i=i+1;
  818. params.clear();
  819. if(StringUtils.isNotEmpty(excelItem.getLicenseno())){
  820. String licenseno = excelItem.getLicenseno();//车牌号
  821. params.put("licenseno",licenseno);
  822. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  823. if(ObjectUtils.isEmpty(byBxLicenseno)){
  824. reason="该数据车牌号有问题";
  825. }
  826. }
  827. if(StringUtils.isNotEmpty(excelItem.getNoPolicyno())){
  828. String policyno = excelItem.getNoPolicyno(); //非车保单号
  829. params.put("NoPolicyno",policyno);
  830. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  831. if(ObjectUtils.isEmpty(byBxLicenseno)){
  832. reason="该数据非车保单号有问题";
  833. }
  834. }
  835. if(excelItem.getNoPremium() !=null && excelItem.getNoPremium().compareTo(BigDecimal.ZERO)!=0){
  836. params.put("noPolicyno",excelItem.getNoPremium());
  837. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  838. if(ObjectUtils.isEmpty(byBxLicenseno)){
  839. reason="该数据非车保费有问题";
  840. }
  841. }
  842. if( excelItem.getNoSuperviseCostsPremiums() !=null && excelItem.getNoSuperviseCostsPremiums().compareTo(BigDecimal.ZERO)!=0){
  843. params.put("noSuperviseCostsPremiums",excelItem.getNoSuperviseCostsPremiums());
  844. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  845. if(ObjectUtils.isEmpty(byBxLicenseno)){
  846. reason="该数据非车手续费有问题";
  847. }
  848. }
  849. if(excelItem.getNoSuperviseCostsProportion() != null && excelItem.getNoSuperviseCostsProportion().compareTo(BigDecimal.ZERO)!=0){
  850. params.put("noSuperviseCostsProportion",excelItem.getNoSuperviseCostsProportion());
  851. InsPlyIncome byBxLicenseno = baseMapper.findByBxLicenseno(params);
  852. if(ObjectUtils.isEmpty(byBxLicenseno)){
  853. reason="该数据非车手续费比例有问题";
  854. }
  855. }
  856. // 只查手续费
  857. params.put("isOther","0");
  858. params.put("isNotCar",isNotCar);
  859. InsPlyIncome insPlyIncome = baseMapper.findByBxLicenseno(params);
  860. if(i==dtoList.size() && ObjectUtils.isNotEmpty(insPlyIncome)){
  861. resultMap.put("companyId",insPlyIncome.getCompanyId()); // 保险公司id
  862. resultMap.put("partnerCompaniesId",insPlyIncome.getPartnerCompaniesId()); //合作公司id
  863. resultMap.put("agreementId",insPlyIncome.getAgreementId()); //协议id
  864. }
  865. if(ObjectUtils.isNotEmpty(insPlyIncome)){ // 比配上汇总金额 未匹配则返回到数据当中
  866. strBuilder.append(insPlyIncome.getId()).append(",");
  867. if( insPlyIncome.getCommissionFeevalue()!=null && insPlyIncome.getCommissionFeevalue().compareTo(BigDecimal.ZERO)!=0){
  868. totalAmount = totalAmount.add(insPlyIncome.getCommissionFeevalue()); //添加总手续费
  869. }
  870. }else {
  871. HashMap<String, Object> noMatching = new HashMap<>();
  872. if(StringUtils.isNotEmpty(excelItem.getLicenseno())){
  873. noMatching.put("licenseno",excelItem.getLicenseno());
  874. }
  875. if(StringUtils.isNotEmpty(excelItem.getNoPolicyno())){
  876. noMatching.put("NoPolicyno",excelItem.getNoPolicyno());
  877. }
  878. resultList.add(noMatching);
  879. }
  880. resultMap.put("reason",reason);
  881. }
  882. if(strBuilder.length() >0){
  883. ids = strBuilder.deleteCharAt(strBuilder.length() - 1).toString();
  884. }
  885. resultMap.put("ids",ids);
  886. resultMap.put("totalAmount",totalAmount);
  887. resultMap.put("resultList",resultList);
  888. }
  889. return resultMap;
  890. } catch (IOException e) {
  891. throw new SystemException("导入失败!");
  892. }
  893. }
  894. @Override
  895. public HttpResult bxOtherDetailsExcel(InsPlyIncomeVo insPlyIncomeVo, HttpServletRequest request, HttpServletResponse response) {
  896. HashMap<String, Object> params = new HashMap<>();
  897. params =this.saveParams(insPlyIncomeVo,params);
  898. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(params);
  899. ExportParams exportParams = new ExportParams("保险跟单明细导出", null, ExcelType.HSSF);
  900. exportParams.setStyle(ExcelStyleUtil.class);
  901. List<BxOtherDetailsExcel> resultList = new ArrayList<>();
  902. for (InsPlyIncome item :insPlyIncomes){
  903. BxOtherDetailsExcel bxOtherDetailsExcel = new BxOtherDetailsExcel();
  904. BeanUtils.copyProperties(item, bxOtherDetailsExcel);
  905. resultList.add(bxOtherDetailsExcel);
  906. }
  907. String uploadPath = this.uploadPath + "/excel/";
  908. Path path = Paths.get(uploadPath);
  909. if (!Files.exists(path)) {
  910. try {
  911. Files.createDirectories(path);
  912. } catch (IOException e) {
  913. e.printStackTrace();
  914. }
  915. }
  916. String fileName = EasyExcelUtils.downExcel(uploadPath, "保险跟单明细导出", BxOtherDetailsExcel.class, resultList);
  917. return HttpResult.ok("",uploadUrl + "excel/" + fileName);
  918. }
  919. /**
  920. *
  921. * @param insPlyIncomeVo 传参字段
  922. * ids 通过ids中的id进行开票分组
  923. *
  924. * @return
  925. */
  926. @Override
  927. public HttpResult<List<HashMap<String,Object>>> invicdetail(InsPlyIncomeVo insPlyIncomeVo) {
  928. HashMap<String, Object> params = new HashMap<>();
  929. params =this.saveParams(insPlyIncomeVo,params);
  930. if (StringUtils.isEmpty(insPlyIncomeVo.getIsSettlement())){
  931. params.put("isSettlement","1");
  932. }
  933. if(StringUtils.isNotEmpty(insPlyIncomeVo.getSettlementStatus())){
  934. params.put("settlementStatus",insPlyIncomeVo.getSettlementStatus());
  935. }
  936. List<HashMap<String, Object>> resultList = settlementDocumentaryFeesService.getOtherSettldetail(params);
  937. if (resultList.size() > 0) {
  938. return HttpResult.ok(resultList);
  939. }
  940. return HttpResult.ok();
  941. }
  942. /***
  943. *
  944. * @param insPlyIncomeVo
  945. * @param request
  946. * @param response
  947. * @return 保险非车跟单明细导出
  948. */
  949. @Override
  950. public HttpResult bxNoOtherDetailsExcel(InsPlyIncomeVo insPlyIncomeVo, HttpServletRequest request, HttpServletResponse response) {
  951. HashMap<String, Object> params = new HashMap<>();
  952. params =this.saveParams(insPlyIncomeVo,params);
  953. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(params);
  954. ExportParams exportParams = new ExportParams("保险非车跟单明细导出", null, ExcelType.HSSF);
  955. exportParams.setStyle(ExcelStyleUtil.class);
  956. List<BxNoOtherDetailsExcel> resultList = new ArrayList<>();
  957. for (InsPlyIncome item :insPlyIncomes){
  958. BxNoOtherDetailsExcel bxNoOtherDetailsExcel = new BxNoOtherDetailsExcel();
  959. BeanUtils.copyProperties(item, bxNoOtherDetailsExcel);
  960. resultList.add(bxNoOtherDetailsExcel);
  961. }
  962. String uploadPath = this.uploadPath + "/excel/";
  963. Path path = Paths.get(uploadPath);
  964. if (!Files.exists(path)) {
  965. try {
  966. Files.createDirectories(path);
  967. } catch (IOException e) {
  968. e.printStackTrace();
  969. }
  970. }
  971. String fileName = EasyExcelUtils.downExcel(uploadPath, "保险非车跟单明细导出", BxNoOtherDetailsExcel.class, resultList);
  972. return HttpResult.ok("",uploadUrl + "excel/" + fileName);
  973. }
  974. /**
  975. *
  976. * @param insPlyIncomeVo 开票ids
  977. * @return 返回开票号 开票金额 开票时间
  978. */
  979. @Override
  980. public HttpResult<List<HashMap<String, Object>>> otherSettldetail(InsPlyIncomeVo insPlyIncomeVo) {
  981. HashMap<String, Object> params = new HashMap<>();
  982. params =this.saveParams(insPlyIncomeVo,params);
  983. List<HashMap<String, Object>> resultList = settlementDocumentaryFeesService.getOtherSettldetail(params);
  984. if (resultList.size() > 0) {
  985. return HttpResult.ok(resultList);
  986. }
  987. return HttpResult.ok();
  988. }
  989. @Override
  990. public InsPlyIncome getEntityById(String id) {
  991. return baseMapper.getEntityById(id);
  992. }
  993. @Override
  994. @Transactional
  995. public void updateByEntity(InsPlyIncomeVo insPlyIncomeVo) {
  996. // 根据协议 如果是含增值税结算 用保费 * 如果是 不含税保费
  997. InsPlyIncome insPlyIncome = new InsPlyIncome();
  998. BeanUtils.copyProperties(insPlyIncomeVo, insPlyIncome);
  999. this.amountCalculate(insPlyIncomeVo,insPlyIncome);
  1000. baseMapper.updateById(insPlyIncome);
  1001. insPlyIncomeVo.setCrudStatus("2");
  1002. this.saveLog(insPlyIncomeVo);
  1003. }
  1004. /**
  1005. *
  1006. * @param insPlyIncomeVo
  1007. * @param insPlyIncome
  1008. *
  1009. * 重新计算金额 通过比例
  1010. * 计算逻辑 交强不含税保费* 交强跟单比例 = 交强跟单金额
  1011. */
  1012. private void amountCalculate(InsPlyIncomeVo insPlyIncomeVo,InsPlyIncome insPlyIncome) {
  1013. if("1".equals(insPlyIncomeVo.getAgreementType())){ //平台
  1014. // 平台 手续费 +跟单费 = 应收 手续费 = 手续费比例*保费 应收比例=手续费比例 + 跟单比例
  1015. BigDecimal jqSuperviseCostsProportion = initializationBigdecimal(insPlyIncomeVo.getJqSuperviseCostsProportion());//交强手续费比例
  1016. BigDecimal sySuperviseCostsProportion = initializationBigdecimal(insPlyIncomeVo.getSySuperviseCostsProportion()); //商业手续费比例
  1017. BigDecimal noSuperviseCostsProportion = initializationBigdecimal(insPlyIncomeVo.getNoSuperviseCostsProportion()); //非车手续费比例
  1018. BigDecimal jqOtherCostsProportion = initializationBigdecimal(insPlyIncomeVo.getJqOtherCostsProportion()); //交强跟单比例
  1019. BigDecimal syOtherCostsProportion = initializationBigdecimal(insPlyIncomeVo.getSyOtherCostsProportion()); //商业跟单比例
  1020. BigDecimal noOtherCostsProportion = initializationBigdecimal(insPlyIncomeVo.getNoOtherCostsProportion()); //非车跟单比例
  1021. BigDecimal jqPremium = initializationBigdecimal(insPlyIncomeVo.getJqPremium()); //交强保费
  1022. BigDecimal syPremium = initializationBigdecimal(insPlyIncomeVo.getSyPremium()); //商业保费
  1023. BigDecimal noPremium = initializationBigdecimal(insPlyIncomeVo.getNoPremium()); //非车保费
  1024. //手续费比例
  1025. insPlyIncome.setCommissionFeerate(this.calculateTotal(jqSuperviseCostsProportion,sySuperviseCostsProportion,noSuperviseCostsProportion)); //手续费比例 = 商业手续费比例 + 交强手续费比例 + 非车手续费比例
  1026. if(jqSuperviseCostsProportion !=null && jqPremium!=null ){
  1027. insPlyIncome.setJqSuperviseCostsPremiums(this.algorithmAmount(jqPremium,jqSuperviseCostsProportion)); //交强手续费
  1028. }
  1029. if(sySuperviseCostsProportion !=null && syPremium !=null){
  1030. insPlyIncome.setSySuperviseCostsPremiums(this.algorithmAmount(syPremium,sySuperviseCostsProportion)); //商业手续费
  1031. }
  1032. if(noSuperviseCostsProportion !=null && noPremium!=null){
  1033. insPlyIncome.setNoSuperviseCostsPremiums(this.algorithmAmount(noPremium,noSuperviseCostsProportion)); //非车手续费
  1034. }
  1035. if(jqOtherCostsProportion !=null && jqPremium!=null ){
  1036. insPlyIncome.setJqOtherCostsPremium(this.algorithmAmount(jqPremium,jqOtherCostsProportion)); //交强跟单费
  1037. }
  1038. if(syOtherCostsProportion !=null && syPremium !=null ){
  1039. insPlyIncome.setSyOtherCostsPremium(this.algorithmAmount(syPremium,syOtherCostsProportion)); //商业跟单费
  1040. }
  1041. if(noOtherCostsProportion !=null && noPremium !=null){
  1042. insPlyIncome.setNoOtherCostsPremium(this.algorithmAmount(noPremium,noOtherCostsProportion)); //非车跟单费
  1043. }
  1044. insPlyIncome.setCommissionFeevalue(this.calculateTotal(insPlyIncome.getJqSuperviseCostsPremiums(),insPlyIncome.getSySuperviseCostsPremiums(),insPlyIncome.getNoSuperviseCostsPremiums())); //手续费
  1045. insPlyIncome.setCommissionFeerate(this.calculateTotal(jqSuperviseCostsProportion,sySuperviseCostsProportion,noSuperviseCostsProportion)); //手续费比例
  1046. insPlyIncome.setOtherFeevalue(this.calculateTotal(insPlyIncome.getJqOtherCostsPremium(),insPlyIncome.getSyOtherCostsPremium(),insPlyIncome.getNoOtherCostsPremium())); //跟单费金额
  1047. insPlyIncome.setOtherFeerate(this.calculateTotal(jqOtherCostsProportion,syOtherCostsProportion,noOtherCostsProportion)); //跟单费比例
  1048. insPlyIncome.setAllFeeValue(this.calculateTotal(insPlyIncome.getCommissionFeevalue(),insPlyIncome.getOtherFeevalue(),null)); // 总费用 = 手续费+跟单费
  1049. //应收比例 交强应收比例=交强手续费比例+交强非跟单比例
  1050. insPlyIncome.setJqReceivableProportion(this.calculateTotal(jqSuperviseCostsProportion,jqOtherCostsProportion,null)); //交强应收
  1051. insPlyIncome.setSyReceivableProportion(this.calculateTotal(sySuperviseCostsProportion,syOtherCostsProportion,null)); //商业应收
  1052. insPlyIncome.setNoReceivableProportion(this.calculateTotal(noSuperviseCostsProportion,noOtherCostsProportion,null)); //非车应收
  1053. }else {
  1054. BigDecimal jqNoTaxPremium = insPlyIncomeVo.getJqNoTaxPremium();// 交强手续费 按照思路 交强不含税保费* 交强手续费比例 =交强手续费
  1055. BigDecimal syNoTaxPremium = insPlyIncomeVo.getSyNoTaxPremium();// 商业手续费 按照思路 商业不含税保费* 商业手续费比例 =商业手续费
  1056. BigDecimal noNoTaxPremium = insPlyIncomeVo.getNoNoTaxPremium();// 非车手续费 按照思路 非车不含税保费* 非车手续费比例 =非车手续费
  1057. if(insPlyIncomeVo.getJqSuperviseCostsProportion().compareTo(BigDecimal.ZERO) != 0){
  1058. BigDecimal jqhandingFee = jqNoTaxPremium.multiply(insPlyIncomeVo.getJqSuperviseCostsProportion().divide(new BigDecimal(100)));
  1059. insPlyIncome.setJqSuperviseCostsPremiums(jqhandingFee);
  1060. }
  1061. if(insPlyIncomeVo.getSySuperviseCostsProportion().compareTo(BigDecimal.ZERO) != 0){
  1062. BigDecimal syhandingFee = syNoTaxPremium.multiply(insPlyIncomeVo.getSySuperviseCostsProportion().divide(new BigDecimal(100)));
  1063. insPlyIncome.setSySuperviseCostsPremiums(syhandingFee);
  1064. }
  1065. if(insPlyIncomeVo.getNoSuperviseCostsProportion().compareTo(BigDecimal.ZERO) != 0){
  1066. BigDecimal nohandingFee = noNoTaxPremium.multiply(insPlyIncomeVo.getNoSuperviseCostsProportion().divide(new BigDecimal(100)));
  1067. insPlyIncome.setNoSuperviseCostsPremiums(nohandingFee);
  1068. }
  1069. if(insPlyIncomeVo.getJqOtherCostsProportion().compareTo(BigDecimal.ZERO) != 0){
  1070. BigDecimal jqother = jqNoTaxPremium.multiply(insPlyIncomeVo.getJqOtherCostsProportion().divide(new BigDecimal(100)));//交强跟单费 按照思路 交强不含税保费* 交强跟单比例 = 交强跟单金额
  1071. insPlyIncome.setJqOtherCostsPremium(jqother);
  1072. }
  1073. if(insPlyIncomeVo.getSyOtherCostsProportion().compareTo(BigDecimal.ZERO) != 0){
  1074. BigDecimal syother = syNoTaxPremium.multiply(insPlyIncomeVo.getSyOtherCostsProportion().divide(new BigDecimal(100)));//交强跟单费 按照思路 交强不含税保费* 交强跟单比例 = 交强跟单金额
  1075. insPlyIncome.setSyOtherCostsPremium(syother);
  1076. }
  1077. if(insPlyIncomeVo.getNoOtherCostsProportion().compareTo(BigDecimal.ZERO) != 0){
  1078. BigDecimal syother = syNoTaxPremium.multiply(insPlyIncomeVo.getNoOtherCostsProportion().divide(new BigDecimal(100)));//非车跟单费 按照思路 非车不含税保费* 非车跟单比例 = 非车跟单金额
  1079. insPlyIncome.setNoOtherCostsPremium(syother);
  1080. }
  1081. if("0".equals(insPlyIncomeVo.getIsNotDocumentary()) && "0".equals(insPlyIncomeVo.getIsNotCar())){ //保险 手续费 =不含税保费* 手续费比例
  1082. insPlyIncome.setCommissionFeevalue(this.calculateTotal(insPlyIncome.getJqSuperviseCostsPremiums(),insPlyIncome.getSySuperviseCostsPremiums(),null)); // 手续费
  1083. insPlyIncome.setCommissionFeerate(this.calculateTotal(insPlyIncome.getJqSuperviseCostsProportion(),insPlyIncome.getSySuperviseCostsProportion(),null));//手续费比例
  1084. insPlyIncome.setAllFeeValue(this.calculateTotal(insPlyIncome.getCommissionFeevalue(),null,null));//总金额
  1085. }else if ("1".equals(insPlyIncomeVo.getIsNotDocumentary()) && "0".equals(insPlyIncomeVo.getIsNotCar())){ //保险跟单费 交强跟单+商业跟单
  1086. insPlyIncome.setOtherFeevalue(this.calculateTotal(insPlyIncome.getJqOtherCostsPremium(),insPlyIncome.getSyOtherCostsPremium(),null));
  1087. insPlyIncome.setOtherFeerate(this.calculateTotal(insPlyIncome.getJqOtherCostsProportion(),insPlyIncome.getSyOtherCostsProportion(),null));
  1088. insPlyIncome.setAllFeeValue(this.calculateTotal(insPlyIncome.getOtherFeevalue(),null,null));//总金额
  1089. }
  1090. if("0".equals(insPlyIncomeVo.getIsNotDocumentary()) && "1".equals(insPlyIncomeVo.getIsNotCar())){// 非车
  1091. insPlyIncome.setCommissionFeevalue(this.calculateTotal(insPlyIncome.getNoSuperviseCostsPremiums(),null,null)); // 非车手续费
  1092. insPlyIncome.setCommissionFeerate(this.calculateTotal(insPlyIncome.getNoSuperviseCostsProportion(),null,null)); //非车比例
  1093. insPlyIncome.setAllFeeValue(this.calculateTotal(insPlyIncome.getCommissionFeevalue(),null,null));//总金额
  1094. }else if ("1".equals(insPlyIncomeVo.getIsNotDocumentary()) && "1".equals(insPlyIncomeVo.getIsNotCar())){ //非车跟单
  1095. insPlyIncome.setOtherFeevalue(this.calculateTotal(insPlyIncome.getNoOtherCostsPremium(),null,null)); //非车跟单金额
  1096. insPlyIncome.setOtherFeerate(this.calculateTotal(insPlyIncome.getNoOtherCostsProportion(),null,null)); // 非车跟单比例
  1097. insPlyIncome.setAllFeeValue(this.calculateTotal(insPlyIncome.getOtherFeevalue(),null,null));//总金额
  1098. }
  1099. }
  1100. }
  1101. /**
  1102. *
  1103. * @param value1 保费
  1104. * @param value2 比例
  1105. * @return 费用
  1106. */
  1107. private BigDecimal algorithmAmount(BigDecimal value1, BigDecimal value2) {
  1108. return value1.multiply(value2.divide(new BigDecimal(100)));
  1109. }
  1110. private BigDecimal initializationBigdecimal(BigDecimal value) {
  1111. return value != null ? value : BigDecimal.ZERO;
  1112. }
  1113. private void saveLog(InsPlyIncomeVo insPlyIncomeVo) {
  1114. // 添加记录
  1115. SettlementDocumentaryLogEntity settlementDocumentaryLogEntity = new SettlementDocumentaryLogEntity();
  1116. settlementDocumentaryLogEntity.setCrudStatus(insPlyIncomeVo.getCrudStatus());
  1117. settlementDocumentaryLogEntity.setAmount(insPlyIncomeVo.getOtherFeevalue());
  1118. settlementDocumentaryLogEntity.setSettlementDocumentaryId(insPlyIncomeVo.getId());
  1119. settlementDocumentaryLogEntity.setAmountType("2");
  1120. settlementDocumentaryLogService.save(settlementDocumentaryLogEntity);
  1121. }
  1122. @Override
  1123. @Transactional
  1124. public HttpResult<InsPlyIncome> insertByEntity(InsPlyIncomeVo insPlyIncomeVo) {
  1125. Long id = new SnowFlakeUtil().nextId();
  1126. InsPlyIncome insPlyIncome = new InsPlyIncome();
  1127. insPlyIncomeVo.setOrderno(id.toString());
  1128. BeanUtils.copyProperties(insPlyIncomeVo, insPlyIncome);
  1129. insPlyIncome.setUserId(BaseController.getUser().getId());
  1130. insPlyIncome.setDocumentaryFeesStatus("0");
  1131. insPlyIncome.setHandlingFeesStatus("0");
  1132. insPlyIncome.setIsNotCar(insPlyIncomeVo.getIsNotCar()); // 是否是非车
  1133. insPlyIncome.setIsNotDocumentary(insPlyIncomeVo.getIsNotDocumentary()); //是否是跟单
  1134. baseMapper.insert(insPlyIncome);
  1135. // insPlyIncomeVo.setId(insPlyIncome.getId());
  1136. // insPlyIncomeVo.setCrudStatus("1");
  1137. // this.saveLog(insPlyIncomeVo); //添加日志
  1138. //
  1139. // HashMap<String, Object> params = new HashMap<>();
  1140. //
  1141. // if(StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotCar())){
  1142. // params.put("isNotCar",insPlyIncomeVo.getIsNotCar());
  1143. // }
  1144. // params.put("isOther","1");
  1145. // if(StringUtils.isNotEmpty(insPlyIncomeVo.getYear())){
  1146. // params.put("year",insPlyIncomeVo.getYear());
  1147. // }
  1148. // if(StringUtils.isNotEmpty(insPlyIncomeVo.getCompanyId())){
  1149. // params.put("companyId",insPlyIncomeVo.getCompanyId());
  1150. // }
  1151. //
  1152. // List<InsPlyIncome> list= this.baseMapper.NonSettlementQuery(params);
  1153. // if(!CollectionUtils.isEmpty(list)){
  1154. // for (InsPlyIncome item :list){
  1155. // return HttpResult.ok(item.getIds());
  1156. // }
  1157. // }
  1158. return HttpResult.ok();
  1159. }
  1160. @Override
  1161. @Transactional
  1162. public HttpResult<InsPlyIncome> deleteById(InsPlyIncomeVo insPlyIncomeVo) {
  1163. HashMap<String, Object> params = new HashMap<>();
  1164. if(StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotCar())){
  1165. params.put("isNotCar",insPlyIncomeVo.getIsNotCar());
  1166. }
  1167. params.put("isOther","1");
  1168. if(StringUtils.isNotEmpty(insPlyIncomeVo.getYear())){
  1169. params.put("year",insPlyIncomeVo.getYear());
  1170. }
  1171. if(StringUtils.isNotEmpty(insPlyIncomeVo.getCompanyId())){
  1172. params.put("companyId",insPlyIncomeVo.getCompanyId());
  1173. }
  1174. baseMapper.deleteById(insPlyIncomeVo.getId());
  1175. insPlyIncomeVo.setCrudStatus("3");
  1176. this.saveLog(insPlyIncomeVo);
  1177. List<InsPlyIncome> list = this.baseMapper.NonSettlementQuery(params);
  1178. if (!CollectionUtils.isEmpty(list)) {
  1179. for (InsPlyIncome item : list) {
  1180. return HttpResult.ok(item.getIds());
  1181. }
  1182. } else {
  1183. return HttpResult.ok(null);
  1184. }
  1185. return HttpResult.ok("删除成功");
  1186. }
  1187. @Override
  1188. @Transactional
  1189. public void uodateBalance(InsPlyIncomeVo insPlyIncomeVo) {
  1190. InsPlyIncome insPlyIncome = new InsPlyIncome();
  1191. insPlyIncomeVo.setHandlingFeesStatus("1");
  1192. insPlyIncomeVo.setSettlementTime(LocalDate.now());
  1193. BeanUtils.copyProperties(insPlyIncomeVo, insPlyIncome);
  1194. baseMapper.updateById(insPlyIncome);
  1195. // 生成记录
  1196. SettlementDocumentaryLogEntity settlementDocumentaryLogEntity = new SettlementDocumentaryLogEntity();
  1197. if(StringUtils.isNotEmpty(insPlyIncomeVo.getAgreementType()) && "1".equals(insPlyIncomeVo.getAgreementType())){
  1198. // 只有平台协议 才会跟单费一笔结算
  1199. settlementDocumentaryLogEntity.setAmount(insPlyIncomeVo.getOtherFeevalue()); // 跟单费金额
  1200. }
  1201. settlementDocumentaryLogEntity.setHandingAmount(insPlyIncomeVo.getCommissionFeevalue()); // 手续费金额
  1202. settlementDocumentaryLogEntity.setSettlementDocumentaryId(insPlyIncomeVo.getId()); // 关联id
  1203. settlementDocumentaryLogEntity.setAmountType("1"); //手续费结算
  1204. settlementDocumentaryLogEntity.setCreateTime(new Date());
  1205. settlementDocumentaryLogService.save(settlementDocumentaryLogEntity);
  1206. }
  1207. @Override
  1208. @Transactional
  1209. public HttpResult<BasePageResult<InsPlyIncome>> totalQuery(InsPlyIncomeVo insPlyIncomeVo) {
  1210. HashMap<String, Object> params = new HashMap<>();
  1211. PageInfo<List<InsPlyIncome>> pageHelper = null;
  1212. if(insPlyIncomeVo.getStartDate()!=null){
  1213. params.put("startDate",insPlyIncomeVo.getStartDate().toString());
  1214. }
  1215. if(insPlyIncomeVo.getEndDate()!=null){
  1216. params.put("endDate",insPlyIncomeVo.getEndDate().toString());
  1217. }
  1218. if(StringUtils.isNotEmpty(insPlyIncomeVo.getYear())){
  1219. params.put("year",insPlyIncomeVo.getYear());
  1220. }
  1221. if(StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotCar())){
  1222. params.put("isNotCar",insPlyIncomeVo.getIsNotCar());
  1223. }
  1224. if(StringUtils.isNotEmpty(insPlyIncomeVo.getIsNotDocumentary())){
  1225. params.put("isOther",insPlyIncomeVo.getIsNotDocumentary());
  1226. }
  1227. if(StringUtils.isNotEmpty(insPlyIncomeVo.getDocumentaryFeesStatus())){
  1228. params.put("documentaryFeesStatus",insPlyIncomeVo.getDocumentaryFeesStatus());
  1229. }
  1230. if(StringUtils.isNotEmpty(insPlyIncomeVo.getCompanyId())){
  1231. params.put("companyId",insPlyIncomeVo.getCompanyId());
  1232. }
  1233. params.put("pageNum",insPlyIncomeVo.getPageNum());
  1234. params.put("pageSize",insPlyIncomeVo.getPageSize());
  1235. List<InsPlyIncome> list= this.baseMapper.totalQuery(params);
  1236. pageHelper=new PageInfo(list);
  1237. return HttpResult.ok(new BasePageResult<>(insPlyIncomeVo.getPageNum(), insPlyIncomeVo.getPageSize(), pageHelper.getTotal(), pageHelper.getPages(), list));
  1238. }
  1239. /**
  1240. *
  1241. * @param insPlyIncomeVo ids ins_ply_income 这个表的ids incomeIds settlement_documentary_fees 这个表的ids
  1242. * @return
  1243. */
  1244. /**
  1245. * 跟单费结算 有分批结算的情况
  1246. * @param insPlyIncomeVo
  1247. * @return
  1248. */
  1249. @Override
  1250. @Transactional
  1251. public HttpResult batchBalance(InsPlyIncomeVo insPlyIncomeVo) {
  1252. // 通过ids 查出跟单非结算单
  1253. BigDecimal allAmount = BigDecimal.ZERO;
  1254. // 分批结算
  1255. SettlementDocumentaryFeesVo settlementDocumentaryFeesVo = new SettlementDocumentaryFeesVo();
  1256. settlementDocumentaryFeesVo.setInvoiceId(insPlyIncomeVo.getInvoicId()); //开票号
  1257. settlementDocumentaryFeesVo.setSettlementTime(insPlyIncomeVo.getSettlementTime()); //结算时间
  1258. settlementDocumentaryFeesVo.setSettlementStatus("2"); //2为结算状态
  1259. settlementDocumentaryFeesVo.setCompanyId(insPlyIncomeVo.getCompanyId()); // 保险公司id
  1260. settlementDocumentaryFeesVo.setPartnerCompaniesId(insPlyIncomeVo.getPartnerCompaniesId()); //合作公司id
  1261. settlementDocumentaryFeesVo.setUnsettledAmount(insPlyIncomeVo.getInvoicCommissionFeevalue().subtract(insPlyIncomeVo.getSettlementAmount())); //未结算金额
  1262. settlementDocumentaryFeesVo.setIsNotCar(insPlyIncomeVo.getIsNotCar()); // 是否是非车
  1263. settlementDocumentaryFeesVo.setInvoicingMethod(insPlyIncomeVo.getInvoicingMethod()); //开票方式
  1264. settlementDocumentaryFeesVo.setTaxPoints(insPlyIncomeVo.getTaxPoints()); //税点
  1265. // allAmount =insPlyIncomeVo.getInvoicCommissionFeevalue().multiply(BigDecimal.ONE.subtract(insPlyIncomeVo.getTaxPoints().divide(new BigDecimal(100))));
  1266. settlementDocumentaryFeesVo.setExpendAmount(insPlyIncomeVo.getInvoicCommissionFeevalue().multiply(BigDecimal.ONE.subtract(insPlyIncomeVo.getTaxPoints().divide(new BigDecimal(100)))));
  1267. settlementDocumentaryFeesVo.setSettlementAmount(insPlyIncomeVo.getSettlementAmount()); //进账金额
  1268. settlementDocumentaryFeesVo.setHandlingFeesStatus(insPlyIncomeVo.getHandlingFeesStatus());
  1269. settlementDocumentaryFeesVo.setTotalAmount(insPlyIncomeVo.getInvoicCommissionFeevalue());
  1270. settlementDocumentaryFeesVo.setCreateTime(LocalDate.now());
  1271. settlementDocumentaryFeesVo.setParentId(insPlyIncomeVo.getId());
  1272. settlementDocumentaryFeesVo.setAgreementType("2"); //1平台 2 保险
  1273. settlementDocumentaryFeesService.inertSettle(settlementDocumentaryFeesVo);
  1274. return HttpResult.ok();
  1275. }
  1276. /**
  1277. *
  1278. * @param insPlyIncomeVo
  1279. * @return
  1280. */
  1281. @Override
  1282. public List<InsPlyIncome> totalBxAmount(InsPlyIncomeVo insPlyIncomeVo) {
  1283. HashMap<String, Object> params = new HashMap<>();
  1284. params=this.saveParams(insPlyIncomeVo,params);
  1285. params.remove("handlingFeesStatus");
  1286. List<InsPlyIncome> resultList = baseMapper.totalBxAmount(params);
  1287. // 数据库数据太多是 用sql拼接id会丢失 所以只能逻辑拼接
  1288. List<InsPlyIncome> idList=baseMapper.getIncomeIdList(params);
  1289. if(!CollectionUtils.isEmpty(idList) && !CollectionUtils.isEmpty(resultList)){
  1290. this.splicingIds(idList,resultList);
  1291. }
  1292. return resultList;
  1293. }
  1294. /**
  1295. *
  1296. * @param idList 要开票的数据集合
  1297. * @param resultList 总返回数据
  1298. */
  1299. private void splicingIds(List<InsPlyIncome> idList, List<InsPlyIncome> resultList) {
  1300. // 使用Map来存储agreementId到其id列表的映射
  1301. Map<String, List<String>> idMap = new HashMap<>();
  1302. for (InsPlyIncome idItem : idList) {
  1303. String partnerCompaniesId = idItem.getPartnerCompaniesId();
  1304. idMap.computeIfAbsent(partnerCompaniesId, k -> new ArrayList<>()).add(idItem.getId());
  1305. }
  1306. for (InsPlyIncome resultItem : resultList) {
  1307. List<String> ids = idMap.getOrDefault(resultItem.getPartnerCompaniesId(), Collections.emptyList());
  1308. String idsString = String.join(",", ids);
  1309. resultItem.setIds(idsString);
  1310. }
  1311. }
  1312. /**
  1313. *
  1314. * @param insPlyIncomeVo
  1315. * @return 保险手续费改成多次结算
  1316. */
  1317. @Override
  1318. @Transactional
  1319. public HttpResult<Object> batchInvoicing(InsPlyIncomeVo insPlyIncomeVo) {
  1320. // 开票时生成 记录 用来合计已经开票数据
  1321. String ids = insPlyIncomeVo.getIds();
  1322. if(StringUtils.isNotEmpty(ids)){
  1323. String[] split = ids.split(",");
  1324. for (String id : split){
  1325. InsPlyIncome insPlyIncome = baseMapper.selectById(id);
  1326. insPlyIncome.setInvoicTime(LocalDate.now()); //开票时间
  1327. insPlyIncome.setInvoicId(insPlyIncomeVo.getInvoicId()); //开票号
  1328. insPlyIncome.setHandlingFeesStatus("2"); //2为开票
  1329. baseMapper.updateById(insPlyIncome);
  1330. }
  1331. }
  1332. insPlyIncomeVo.setNoInvoicCommissionFeevalue(insPlyIncomeVo.getTotalAmount());
  1333. insPlyIncomeVo.setOtherFeevalue(insPlyIncomeVo.getTotalAmount());
  1334. insPlyIncomeVo.setHandlingFeesStatus("0"); // 0手续费 1 跟单费
  1335. insPlyIncomeVo.setIsNotCar(insPlyIncomeVo.getIsNotCar());
  1336. insPlyIncomeVo.setAgreementId(insPlyIncomeVo.getAgreementId());
  1337. insPlyIncomeVo.setSettlementAmount(insPlyIncomeVo.getTotalAmount());
  1338. insPlyIncomeVo.setContractId(insPlyIncomeVo.getInvoicId());
  1339. this.batchInvoic(insPlyIncomeVo);
  1340. return HttpResult.ok();
  1341. }
  1342. @Override
  1343. public HttpResult<InsPlyIncome> queryInvoicing(InsPlyIncomeVo insPlyIncomeVo) {
  1344. HashMap<String, Object> params = new HashMap<>();
  1345. params = this.saveParams(insPlyIncomeVo, params);
  1346. InsPlyIncome result= baseMapper.queryInvoicing(params); //总金额
  1347. params.put("handlingFeesStatus","0");
  1348. InsPlyIncome noResult= baseMapper.queryInvoicing(params); //未结算金额
  1349. result.setReadyCommissionFeevalue(noResult.getCommissionFeevalue());
  1350. return HttpResult.ok(result);
  1351. }
  1352. @Override
  1353. public HttpResult<Object> batchBxBalance(InsPlyIncomeVo insPlyIncomeVo) {
  1354. if(StringUtils.isNotEmpty(insPlyIncomeVo.getIds())){// 判断 ins_ply_income 是否完全结算完 如果结算完则改为已结算状态
  1355. this.changeHandStatus(insPlyIncomeVo.getIds(),insPlyIncomeVo);
  1356. }
  1357. // 分批结算
  1358. SettlementDocumentaryFeesVo settlementDocumentaryFeesVo = new SettlementDocumentaryFeesVo();
  1359. settlementDocumentaryFeesVo.setInvoiceId(insPlyIncomeVo.getInvoicId()); //开票号
  1360. settlementDocumentaryFeesVo.setSettlementTime(insPlyIncomeVo.getSettlementTime()); //结算时间
  1361. settlementDocumentaryFeesVo.setSettlementStatus("2"); //2为结算状态
  1362. settlementDocumentaryFeesVo.setCompanyId(insPlyIncomeVo.getCompanyId()); // 保险公司id
  1363. settlementDocumentaryFeesVo.setPartnerCompaniesId(insPlyIncomeVo.getPartnerCompaniesId()); //合作公司id
  1364. settlementDocumentaryFeesVo.setIsNotCar(insPlyIncomeVo.getIsNotCar()); // 是否是非车
  1365. settlementDocumentaryFeesVo.setInvoicingMethod(insPlyIncomeVo.getInvoicingMethod()); //开票方式
  1366. settlementDocumentaryFeesVo.setTaxPoints(insPlyIncomeVo.getTaxPoints()); //税点
  1367. settlementDocumentaryFeesVo.setExpendAmount(insPlyIncomeVo.getInvoicCommissionFeevalue().multiply(BigDecimal.ONE.subtract(insPlyIncomeVo.getTaxPoints().divide(new BigDecimal(100)))));
  1368. settlementDocumentaryFeesVo.setSettlementAmount(insPlyIncomeVo.getSettlementAmount()); //进账金额
  1369. settlementDocumentaryFeesVo.setTotalAmount(insPlyIncomeVo.getInvoicCommissionFeevalue());
  1370. settlementDocumentaryFeesVo.setHandlingFeesStatus("0");
  1371. settlementDocumentaryFeesVo.setParentId(insPlyIncomeVo.getId());
  1372. settlementDocumentaryFeesVo.setSettlementImageId(insPlyIncomeVo.getSettlementImageId());
  1373. settlementDocumentaryFeesVo.setCreateTime(LocalDate.now());
  1374. settlementDocumentaryFeesVo.setAgreementType("2"); //1平台 2 保险
  1375. settlementDocumentaryFeesService.inertSettle(settlementDocumentaryFeesVo);
  1376. return HttpResult.ok();
  1377. }
  1378. private void changeHandStatus(String ids, InsPlyIncomeVo insPlyIncomeVo) {
  1379. String[] split = ids.split(",");
  1380. SettlementDocumentaryFeesEntity byId = settlementDocumentaryFeesService.getById(insPlyIncomeVo.getId());
  1381. BigDecimal totalAmount = byId.getTotalAmount(); //开票总金额
  1382. BigDecimal settlementAmount = insPlyIncomeVo.getSettlementAmount(); //本次结算金额
  1383. //多次结算 表中已经结算的金额
  1384. SettlementDocumentaryFeesEntity settlementAmountEntity = settlementDocumentaryFeesService.getByParentSettlementAmount(insPlyIncomeVo.getId());
  1385. if(ObjectUtils.isNotEmpty(settlementAmountEntity)){
  1386. BigDecimal all = settlementAmount.add(settlementAmountEntity.getTotalAmount());
  1387. if(all.equals(totalAmount)){
  1388. baseMapper.updateByIds(split);
  1389. }
  1390. }
  1391. }
  1392. @Override
  1393. public HttpResult<InsPlyIncome> querySettInvoicing(InsPlyIncomeVo insPlyIncomeVo) {
  1394. HashMap<String, Object> params = new HashMap<>();
  1395. params = this.saveParams(insPlyIncomeVo, params);
  1396. InsPlyIncome insPlyIncome = baseMapper.queryInvoicing(params); //已经开票
  1397. return HttpResult.ok(insPlyIncome);
  1398. }
  1399. /**
  1400. *
  1401. * @param insPlyIncomeVo
  1402. * @return
  1403. */
  1404. @Override
  1405. public HttpResult<List<InsPlyIncome>> allOtherAmount(InsPlyIncomeVo insPlyIncomeVo) {
  1406. HashMap<String, Object> params = new HashMap<>();
  1407. params = this.saveParams(insPlyIncomeVo, params);
  1408. List<InsPlyIncome> result = baseMapper.allOtherAmount(params);
  1409. List<HashMap<String, Object>> otherIds = baseMapper.getOtherIds(params);
  1410. List<HashMap<String, Object>> invoicIds = settlementDocumentaryFeesService.getInvoicIds(params);
  1411. // this.splicingOtherIds(result,otherIds,invoicIds );
  1412. return HttpResult.ok(result);
  1413. }
  1414. /**
  1415. *
  1416. * @param result 返回的数据
  1417. * @param otherIds ins_ply_income 跟单费
  1418. * @param invoicIds settlement_documentary_fees 开票ids
  1419. */
  1420. private void splicingOtherIds(List<InsPlyIncome> result, List<HashMap<String, Object>> otherIds, List<HashMap<String, Object>> invoicIds) {
  1421. // 创建两个映射来分别存储companyId到ids和setIncomeIds的映射
  1422. Map<String, List<String>> companyIdToIdsMap = new HashMap<>();
  1423. Map<String, List<String>> companyIdToSetIncomeIdsMap = new HashMap<>();
  1424. // 处理otherIds,填充companyId到ids的映射
  1425. for (HashMap<String, Object> idMap : otherIds) {
  1426. String partnerCompaniesId = (String) idMap.get("partnerCompaniesId");
  1427. String id = idMap.get("id").toString(); // 假设id是一个String,而不是List<String>
  1428. if (partnerCompaniesId != null && id != null) {
  1429. companyIdToIdsMap.computeIfAbsent(partnerCompaniesId, k -> new ArrayList<>()).add(id); // 将id添加到列表中
  1430. }
  1431. }
  1432. // 处理invoicIds,填充companyId到setIncomeIds的映射(假设结构相同)
  1433. for (HashMap<String, Object> idMap : invoicIds) {
  1434. String partnerCompaniesId = (String) idMap.get("partnerCompaniesId");
  1435. String setIncomeId = idMap.get("id").toString(); // 假设这里也是单个id,键名可能不同,例如"setIncomeId"
  1436. if (partnerCompaniesId != null && setIncomeId != null) {
  1437. companyIdToSetIncomeIdsMap.computeIfAbsent(partnerCompaniesId, k -> new ArrayList<>()).add(setIncomeId);
  1438. }
  1439. }
  1440. // 遍历result列表,为每个InsPlyIncome对象设置拼接后的ids和incomeIds
  1441. for (InsPlyIncome resultItem : result) {
  1442. String partnerCompaniesId = resultItem.getPartnerCompaniesId();
  1443. List<String> ids = companyIdToIdsMap.getOrDefault(partnerCompaniesId, Collections.emptyList());
  1444. List<String> setIncomeIds = companyIdToSetIncomeIdsMap.getOrDefault(partnerCompaniesId, Collections.emptyList());
  1445. // 合并ids和setIncomeIds(如果需要,可以先去重),但在此处我们直接拼接
  1446. String idsString = String.join(",", ids);
  1447. String incomeIdsString = String.join(",", setIncomeIds);
  1448. // 设置拼接后的ids和incomeIds到InsPlyIncome对象中
  1449. resultItem.setIds(idsString);
  1450. resultItem.setIncomeIds(incomeIdsString); // 假设InsPlyIncome有这个方法
  1451. }
  1452. }
  1453. @Override
  1454. @Transactional
  1455. public HttpResult<Object> batchInvoic(InsPlyIncomeVo insPlyIncomeVo) {
  1456. // 通过ids 查出跟单非结算单
  1457. String ids = insPlyIncomeVo.getIds();
  1458. // if(StringUtils.isNotEmpty(ids)){
  1459. // String[] split = ids.split(",");
  1460. // for (int i =0; i <split.length ; i++) {
  1461. // String id = split[i];
  1462. // InsPlyIncome insPlyIncome = baseMapper.selectById(id);
  1463. // insPlyIncome.setInvoicId(insPlyIncomeVo.getContractId()); // 开票号
  1464. // insPlyIncome.setContractFileId(insPlyIncomeVo.getContractFileId());
  1465. // insPlyIncome.setVoucherNumber(insPlyIncomeVo.getVoucherNumber());
  1466. // insPlyIncome.setSettlementTime(LocalDate.now());
  1467. // baseMapper.updateById(insPlyIncome);
  1468. // }
  1469. // }
  1470. SettlementDocumentaryFeesVo settlementDocumentaryFeesVo = new SettlementDocumentaryFeesVo(); // 生成跟单费结算表
  1471. if(StringUtils.isNotEmpty(insPlyIncomeVo.getYear())){
  1472. settlementDocumentaryFeesVo.setTimeFrame(insPlyIncomeVo.getYear());//年度
  1473. }
  1474. if(!CollectionUtils.isEmpty(insPlyIncomeVo.getMultipleSelection())){
  1475. InsPlyIncomeVo insPlyIncomeVo1 = insPlyIncomeVo.getMultipleSelection().get(0);
  1476. insPlyIncomeVo.setSettlementAmount(insPlyIncomeVo1.getSettlementAmount());
  1477. insPlyIncomeVo.setOtherFeevalue(insPlyIncomeVo1.getAllTotalOtherFeevalue());
  1478. YearMonth yearMonth = YearMonth.parse(insPlyIncomeVo1.getMonthYear());
  1479. LocalDate signingTime = yearMonth.atDay(1);
  1480. settlementDocumentaryFeesVo.setSigningTime(signingTime);
  1481. }
  1482. if(StringUtils.isNotEmpty(insPlyIncomeVo.getYear())){
  1483. settlementDocumentaryFeesVo.setYear(insPlyIncomeVo.getYear());
  1484. }
  1485. if(StringUtils.isNotEmpty(insPlyIncomeVo.getMonth())){
  1486. settlementDocumentaryFeesVo.setMonth(insPlyIncomeVo.getMonth());
  1487. }
  1488. if(StringUtils.isNotEmpty(insPlyIncomeVo.getDay())){
  1489. settlementDocumentaryFeesVo.setDay(insPlyIncomeVo.getDay());
  1490. }
  1491. settlementDocumentaryFeesVo.setCompanyId(insPlyIncomeVo.getCompanyId());// 保险公司id
  1492. settlementDocumentaryFeesVo.setPartnerCompaniesId(insPlyIncomeVo.getPartnerCompaniesId()); //合作公司id
  1493. settlementDocumentaryFeesVo.setTotalAmount(insPlyIncomeVo.getOtherFeevalue()); //其他费用金额
  1494. settlementDocumentaryFeesVo.setUnsettledAmount(insPlyIncomeVo.getNoInvoicCommissionFeevalue().subtract(insPlyIncomeVo.getSettlementAmount())); //未结算
  1495. settlementDocumentaryFeesVo.setSettlementAmount(insPlyIncomeVo.getSettlementAmount());//已经开票
  1496. settlementDocumentaryFeesVo.setCreateTime(LocalDate.now());
  1497. settlementDocumentaryFeesVo.setIds(insPlyIncomeVo.getIncomeIds());
  1498. settlementDocumentaryFeesVo.setSettlementStatus("1");
  1499. settlementDocumentaryFeesVo.setIsNotCar(insPlyIncomeVo.getIsNotCar());
  1500. if(StringUtils.isNotEmpty(insPlyIncomeVo.getContractId())){
  1501. settlementDocumentaryFeesVo.setInvoiceId(insPlyIncomeVo.getContractId()); //开票号
  1502. }
  1503. settlementDocumentaryFeesVo.setHandlingFeesStatus(insPlyIncomeVo.getHandlingFeesStatus());
  1504. settlementDocumentaryFeesVo.setInvoicingMethod(insPlyIncomeVo.getInvoicingMethod()); //开票方式
  1505. settlementDocumentaryFeesVo.setTaxPoints(insPlyIncomeVo.getTaxPoints()); //税点
  1506. settlementDocumentaryFeesVo.setIds(insPlyIncomeVo.getIds());
  1507. // 税点支出
  1508. if(BigDecimalUtils.nullToZero(insPlyIncomeVo.getTaxPoints()) !=null && insPlyIncomeVo.getTaxPoints().compareTo(BigDecimal.ZERO) != 0 && BigDecimalUtils.nullToZero(insPlyIncomeVo.getSettlementAmount()) !=null){
  1509. BigDecimal settlementAmount = insPlyIncomeVo.getSettlementAmount();
  1510. settlementDocumentaryFeesVo.setExpendAmount(settlementAmount.multiply(BigDecimal.ONE.subtract(insPlyIncomeVo.getTaxPoints().divide(new BigDecimal(100)))));
  1511. }
  1512. return settlementDocumentaryFeesService.inertSettle(settlementDocumentaryFeesVo);
  1513. }
  1514. @Override
  1515. public HttpResult pinHandlingexcel(InsPlyIncomeVo insPlyIncomeVo, HttpServletRequest request, HttpServletResponse response) {
  1516. HashMap<String, Object> params = new HashMap<>();
  1517. params =this.saveParams(insPlyIncomeVo,params);
  1518. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(params);
  1519. ExportParams exportParams = new ExportParams("平台手续费", null, ExcelType.HSSF);
  1520. exportParams.setStyle(ExcelStyleUtil.class);
  1521. List<SettlementFeesExcel> resultList = new ArrayList<>();
  1522. for (InsPlyIncome item :insPlyIncomes){
  1523. SettlementFeesExcel bxSettlementFeesExcel = new SettlementFeesExcel();
  1524. BeanUtils.copyProperties(item, bxSettlementFeesExcel);
  1525. if("1".equals(item.getHandlingFeesStatus())){
  1526. bxSettlementFeesExcel.setHandlingFeesStatus("已结算");
  1527. }else {
  1528. bxSettlementFeesExcel.setHandlingFeesStatus("未结算");
  1529. }
  1530. resultList.add(bxSettlementFeesExcel);
  1531. }
  1532. String uploadPath = this.uploadPath + "/excel/";
  1533. Path path = Paths.get(uploadPath);
  1534. if (!Files.exists(path)) {
  1535. try {
  1536. Files.createDirectories(path);
  1537. } catch (IOException e) {
  1538. e.printStackTrace();
  1539. }
  1540. }
  1541. String fileName = EasyExcelUtils.downExcel(uploadPath, "平台手续费导出", SettlementFeesExcel.class, resultList);
  1542. return HttpResult.ok("",uploadUrl + "excel/" + fileName);
  1543. }
  1544. @Override
  1545. public HttpResult bxHandlingexcel(InsPlyIncomeVo insPlyIncomeVo, HttpServletRequest request, HttpServletResponse response) {
  1546. HashMap<String, Object> params = new HashMap<>();
  1547. params =this.saveParams(insPlyIncomeVo,params);
  1548. List<InsPlyIncome> insPlyIncomes = baseMapper.queryNew(params);
  1549. ExportParams exportParams = new ExportParams("保险手续费", null, ExcelType.HSSF);
  1550. exportParams.setStyle(ExcelStyleUtil.class);
  1551. List<BxSettlementFeesExcel> resultList = new ArrayList<>();
  1552. for (InsPlyIncome item :insPlyIncomes){
  1553. BxSettlementFeesExcel bxSettlementFeesExcel = new BxSettlementFeesExcel();
  1554. LocalDateTime signDate = item.getSignDate();
  1555. BeanUtils.copyProperties(item, bxSettlementFeesExcel);
  1556. resultList.add(bxSettlementFeesExcel);
  1557. }
  1558. String uploadPath = this.uploadPath + "/excel/";
  1559. Path path = Paths.get(uploadPath);
  1560. if (!Files.exists(path)) {
  1561. try {
  1562. Files.createDirectories(path);
  1563. } catch (IOException e) {
  1564. e.printStackTrace();
  1565. }
  1566. }
  1567. String fileName = EasyExcelUtils.downExcel(uploadPath, "保险手续费导出", BxSettlementFeesExcel.class, resultList);
  1568. return HttpResult.ok("",uploadUrl + "excel/" + fileName);
  1569. }
  1570. @Override
  1571. public HttpResult bxOtherExcel(InsPlyIncomeVo insPlyIncomeVo, HttpServletRequest request, HttpServletResponse response) {
  1572. HashMap<String, Object> params = new HashMap<>();
  1573. params =this.saveParams(insPlyIncomeVo,params);
  1574. params.put("agreementType","2");
  1575. params.put("isOther","1");
  1576. params.put("isNotCar","0");
  1577. List<InsPlyIncome> insPlyIncomes = baseMapper.allOtherAmount(params);
  1578. ExportParams exportParams = new ExportParams("跟单费导出", null, ExcelType.HSSF);
  1579. exportParams.setStyle(ExcelStyleUtil.class);
  1580. List<BxOtherExcel> resultList = new ArrayList<>();
  1581. for (InsPlyIncome item :insPlyIncomes){
  1582. BxOtherExcel bxSettlementFeesExcel = new BxOtherExcel();
  1583. BeanUtils.copyProperties(item, bxSettlementFeesExcel);
  1584. resultList.add(bxSettlementFeesExcel);
  1585. }
  1586. String uploadPath = this.uploadPath + "/excel/";
  1587. Path path = Paths.get(uploadPath);
  1588. if (!Files.exists(path)) {
  1589. try {
  1590. Files.createDirectories(path);
  1591. } catch (IOException e) {
  1592. e.printStackTrace();
  1593. }
  1594. }
  1595. String fileName = EasyExcelUtils.downExcel(uploadPath, "跟单费导出", BxOtherExcel.class, resultList);
  1596. return HttpResult.ok("",uploadUrl + "excel/" + fileName);
  1597. }
  1598. @Override
  1599. public InsPlyIncome bxTotalAmount(InsPlyIncomeVo insPlyIncomeVo) {
  1600. HashMap<String, Object> params = new HashMap<>();
  1601. params = this.saveParams(insPlyIncomeVo, params);
  1602. InsPlyIncome totalledAmount =baseMapper.bxTotalAmount(params); //总金额
  1603. return totalledAmount;
  1604. }
  1605. @Override
  1606. public HttpResult<List<HashMap<String,Object>>> otherTimeDetail(InsPlyIncomeVo insPlyIncomeVo) {
  1607. HashMap<String, Object> params = new HashMap<>();
  1608. this.saveParams(insPlyIncomeVo,params);
  1609. List<HashMap<String,Object>> resultMap=baseMapper.otherTimeDetail(params);
  1610. return HttpResult.ok(resultMap);
  1611. }
  1612. @Override
  1613. public HttpResult<Object> singleInvoic(InsPlyIncomeVo insPlyIncomeVo) {
  1614. // 通过ids 查出跟单非结算单
  1615. SettlementDocumentaryFeesVo settlementDocumentaryFeesVo = new SettlementDocumentaryFeesVo(); // 生成跟单费结算表
  1616. if (!CollectionUtils.isEmpty(insPlyIncomeVo.getMultipleSelection())) {
  1617. for (InsPlyIncomeVo insPlyIncomeVo1 : insPlyIncomeVo.getMultipleSelection()) {
  1618. insPlyIncomeVo.setSettlementAmount(insPlyIncomeVo1.getSettlementAmount());
  1619. insPlyIncomeVo.setOtherFeevalue(insPlyIncomeVo1.getAllTotalOtherFeevalue());
  1620. YearMonth yearMonth = YearMonth.parse(insPlyIncomeVo1.getMonthYear());
  1621. LocalDate signingTime = yearMonth.atDay(1);
  1622. settlementDocumentaryFeesVo.setSigningTime(signingTime);
  1623. }
  1624. }
  1625. if (StringUtils.isNotEmpty(insPlyIncomeVo.getYear())) {
  1626. settlementDocumentaryFeesVo.setTimeFrame(insPlyIncomeVo.getYear());//年度
  1627. }
  1628. if (StringUtils.isNotEmpty(insPlyIncomeVo.getYear())) {
  1629. settlementDocumentaryFeesVo.setYear(insPlyIncomeVo.getYear());
  1630. }
  1631. if (StringUtils.isNotEmpty(insPlyIncomeVo.getMonth())) {
  1632. settlementDocumentaryFeesVo.setMonth(insPlyIncomeVo.getMonth());
  1633. }
  1634. if (StringUtils.isNotEmpty(insPlyIncomeVo.getDay())) {
  1635. settlementDocumentaryFeesVo.setDay(insPlyIncomeVo.getDay());
  1636. }
  1637. settlementDocumentaryFeesVo.setCompanyId(insPlyIncomeVo.getCompanyId());// 保险公司id
  1638. settlementDocumentaryFeesVo.setPartnerCompaniesId(insPlyIncomeVo.getPartnerCompaniesId()); //合作公司id
  1639. settlementDocumentaryFeesVo.setTotalAmount(insPlyIncomeVo.getOtherFeevalue()); //其他费用金额
  1640. settlementDocumentaryFeesVo.setUnsettledAmount(insPlyIncomeVo.getNoInvoicCommissionFeevalue().subtract(insPlyIncomeVo.getSettlementAmount())); //未结算
  1641. settlementDocumentaryFeesVo.setSettlementAmount(insPlyIncomeVo.getSettlementAmount());//已经开票
  1642. settlementDocumentaryFeesVo.setCreateTime(LocalDate.now());
  1643. settlementDocumentaryFeesVo.setIds(insPlyIncomeVo.getIncomeIds());
  1644. settlementDocumentaryFeesVo.setSettlementStatus("1");
  1645. settlementDocumentaryFeesVo.setIsNotCar(insPlyIncomeVo.getIsNotCar());
  1646. if (StringUtils.isNotEmpty(insPlyIncomeVo.getContractId())) {
  1647. settlementDocumentaryFeesVo.setInvoiceId(insPlyIncomeVo.getContractId()); //开票号
  1648. }
  1649. settlementDocumentaryFeesVo.setHandlingFeesStatus(insPlyIncomeVo.getHandlingFeesStatus());
  1650. settlementDocumentaryFeesVo.setInvoicingMethod(insPlyIncomeVo.getInvoicingMethod()); //开票方式
  1651. settlementDocumentaryFeesVo.setTaxPoints(insPlyIncomeVo.getTaxPoints()); //税点
  1652. settlementDocumentaryFeesVo.setIds(insPlyIncomeVo.getIds());
  1653. settlementDocumentaryFeesVo.setSigningTime(insPlyIncomeVo.getSettlementTime()); //签单日期
  1654. // 税点支出
  1655. if (BigDecimalUtils.nullToZero(insPlyIncomeVo.getTaxPoints()) != null && BigDecimalUtils.nullToZero(insPlyIncomeVo.getSettlementAmount()) != null) {
  1656. BigDecimal settlementAmount = insPlyIncomeVo.getSettlementAmount();
  1657. settlementDocumentaryFeesVo.setExpendAmount(settlementAmount.multiply(BigDecimal.ONE.subtract(insPlyIncomeVo.getTaxPoints().divide(new BigDecimal(100)))));
  1658. }
  1659. settlementDocumentaryFeesService.inertSettle(settlementDocumentaryFeesVo);
  1660. return HttpResult.ok();
  1661. }
  1662. @Override
  1663. public void batchUpdate(InsPlyIncomeVo insPlyIncomeVo) {
  1664. HashMap<String, Object> params = new HashMap<>();
  1665. params= this.saveParams(insPlyIncomeVo,params);
  1666. List<InsPlyIncome> list= this.baseMapper.queryNew(params);
  1667. for ( InsPlyIncome item : list){
  1668. item.setContractFileId( insPlyIncomeVo.getContractFileId());
  1669. item.setSettleOtherStatus("1");
  1670. baseMapper.updateById(item);
  1671. }
  1672. }
  1673. }