InsPlyIncomeServiceImpl.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. package com.ydtech.modules.fnc.service.impl;
  2. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  3. import com.github.pagehelper.PageHelper;
  4. import com.github.pagehelper.PageInfo;
  5. import com.ydtech.core.page.HttpResult;
  6. import com.ydtech.modules.admin.model.po.SysAmountAuditingEntity;
  7. import com.ydtech.modules.admin.model.po.SysUserAccountHistory;
  8. import com.ydtech.modules.fnc.entity.InsPlyIncome;
  9. import com.ydtech.modules.fnc.dao.InsPlyIncomeMapper;
  10. import com.ydtech.modules.fnc.entity.SettlementDocumentaryLogEntity;
  11. import com.ydtech.modules.fnc.service.InsPlyIncomeService;
  12. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  13. import com.ydtech.modules.fnc.service.SettlementDocumentaryFeesService;
  14. import com.ydtech.modules.fnc.service.SettlementDocumentaryLogService;
  15. import com.ydtech.modules.fnc.vo.InsPlyIncomeVo;
  16. import com.ydtech.modules.fnc.vo.SettlementDocumentaryFeesVo;
  17. import com.ydtech.modules.order.entity.BasePageResult;
  18. import com.ydtech.modules.order.entity.InsAreaCompany;
  19. import com.ydtech.modules.order.entity.InsOrders;
  20. import com.ydtech.modules.order.service.InsAreaCompanyService;
  21. import com.ydtech.modules.order.service.InsOrdersService;
  22. import com.ydtech.modules.protocols.entity.po.InsFeeOrderNew;
  23. import com.ydtech.modules.protocols.service.InsFeeOrderNewService;
  24. import org.apache.commons.lang3.ObjectUtils;
  25. import org.apache.commons.lang3.StringUtils;
  26. import org.springframework.beans.BeanUtils;
  27. import org.springframework.beans.factory.annotation.Autowired;
  28. import org.springframework.stereotype.Service;
  29. import org.springframework.transaction.annotation.Transactional;
  30. import java.math.BigDecimal;
  31. import java.time.LocalDateTime;
  32. import java.util.Date;
  33. import java.util.HashMap;
  34. import java.util.List;
  35. /**
  36. * <p>
  37. * 保司结算手续费 服务实现类
  38. * </p>
  39. *
  40. * @author gws
  41. * @since 2024-01-05
  42. */
  43. @Service
  44. public class InsPlyIncomeServiceImpl extends ServiceImpl<InsPlyIncomeMapper, InsPlyIncome> implements InsPlyIncomeService {
  45. @Autowired
  46. private InsOrdersService insOrdersService;
  47. @Autowired
  48. private InsAreaCompanyService insAreaCompanyService;
  49. @Autowired
  50. private InsFeeOrderNewService insFeeOrderNewService;
  51. @Autowired
  52. private SettlementDocumentaryFeesService settlementDocumentaryFeesService;
  53. @Autowired
  54. private SettlementDocumentaryLogService settlementDocumentaryLogService;
  55. public HttpResult<BasePageResult<InsPlyIncome>> queryplyIncome(InsPlyIncomeVo insPlyIncomeVo){
  56. try{
  57. Page<InsOrders> page = new Page<>(insPlyIncomeVo.getPageNum(), insPlyIncomeVo.getPageSize());
  58. PageInfo<List<InsPlyIncome>> pageHelper = null;
  59. PageHelper.startPage(insPlyIncomeVo.getPageNum(),insPlyIncomeVo.getPageSize());
  60. List<InsPlyIncome> list= this.baseMapper.selectByCondition(insPlyIncomeVo);
  61. pageHelper=new PageInfo(list);
  62. BasePageResult<InsPlyIncome> pageResult=new BasePageResult<InsPlyIncome>(insPlyIncomeVo.getPageNum(), insPlyIncomeVo.getPageSize(), pageHelper.getTotal(), pageHelper.getPages(), list);
  63. return HttpResult.ok(pageResult);
  64. }catch (Exception e){
  65. e.printStackTrace();
  66. return HttpResult.error("查询异常");
  67. }
  68. }
  69. @Override
  70. public void saveBalance(String companyId, String orderno) {
  71. InsOrders insOrders = insOrdersService.getById(orderno);
  72. InsAreaCompany insAreaCompany = insAreaCompanyService.getById(companyId);
  73. InsFeeOrderNew insFeeOrderNew = insFeeOrderNewService.getInsFeeOrderNewByCompanyId(companyId);
  74. this.saveBalanc(insFeeOrderNew, insOrders, insAreaCompany);
  75. }
  76. private void saveBalanc(InsFeeOrderNew insFeeOrderNew, InsOrders insOrders, InsAreaCompany insAreaCompany) {
  77. StringBuffer stringBuffer = new StringBuffer();
  78. InsPlyIncome insPlyIncome = new InsPlyIncome();
  79. if (ObjectUtils.isNotEmpty(insAreaCompany)) {
  80. // 使用链式条件判断来减少嵌套
  81. if (StringUtils.isNotEmpty(insAreaCompany.getJqpolicyno())) {
  82. stringBuffer.append(insAreaCompany.getJqpolicyno());
  83. if (StringUtils.isNotEmpty(insAreaCompany.getSypolicyno())) {
  84. stringBuffer.append(",");
  85. stringBuffer.append(insAreaCompany.getSypolicyno());
  86. }
  87. } else if (StringUtils.isNotEmpty(insAreaCompany.getSypolicyno())) {
  88. // 如果jqpolicyno为空但sypolicyno不为空,则只添加sypolicyno
  89. stringBuffer.append(insAreaCompany.getSypolicyno());
  90. }
  91. }
  92. String policyno = stringBuffer.toString(); // 保单号
  93. insPlyIncome.setOrderno(insOrders.getOrderno());
  94. insPlyIncome.setPolicyno(policyno);
  95. insPlyIncome.setDeptId(insFeeOrderNew.getDeptId());
  96. insPlyIncome.setRiskcode(insOrders.getProductid());
  97. insPlyIncome.setPayDate(insAreaCompany.getPayDate());
  98. insPlyIncome.setSignDate(insAreaCompany.getSigningTime());
  99. insPlyIncome.setCompanyId(insAreaCompany.getCompanyId());
  100. insPlyIncome.setAgreementId(insFeeOrderNew.getAgreementId());
  101. insPlyIncome.setLicenseno(insOrders.getLicenseno());
  102. insPlyIncome.setTaxamount(insAreaCompany.getTaxamount());
  103. BigDecimal bigDecimal = this.sumAmount(insFeeOrderNew.getJqNoTaxPremium(), insFeeOrderNew.getSyNoTaxPremium(), insFeeOrderNew.getNoNoTaxPremium());
  104. // 不含保费
  105. insPlyIncome.setNoTaxPremium(bigDecimal);
  106. // 手续费比例
  107. BigDecimal CostsProportion = this.sumAmount(insFeeOrderNew.getJqSuperviseCostsProportion(), insFeeOrderNew.getSySuperviseCostsProportion(), insFeeOrderNew.getNoSuperviseCostsProportion());
  108. insPlyIncome.setCommissionFeerate(CostsProportion);
  109. // 其他费用比例
  110. BigDecimal OtherCostsProportion = this.sumAmount(insFeeOrderNew.getJqOtherCostsProportion(), insFeeOrderNew.getSyOtherCostsProportion(), insFeeOrderNew.getNoOtherCostsProportion());
  111. insPlyIncome.setOtherFeerate(OtherCostsProportion);
  112. // 手续费金额
  113. BigDecimal SuperviseCostsPremiums = this.sumAmount(insFeeOrderNew.getJqSuperviseCostsPremiums(), insFeeOrderNew.getSySuperviseCostsPremiums(), insFeeOrderNew.getNoSuperviseCostsPremiums());
  114. insPlyIncome.setCommissionFeevalue(SuperviseCostsPremiums);
  115. // 其他费用金额
  116. BigDecimal OtherCostsPremiums = this.sumAmount(insFeeOrderNew.getJqOtherCostsPremiums(), insFeeOrderNew.getSyOtherCostsPremiums(), insFeeOrderNew.getNoOtherCostsPremiums());
  117. insPlyIncome.setOtherFeevalue(OtherCostsPremiums);
  118. insPlyIncome.setAllFeeValue(SuperviseCostsPremiums.add(OtherCostsPremiums));
  119. insPlyIncome.setCreateTime(LocalDateTime.now());
  120. insPlyIncome.setDocumentaryFeesStatus("0");
  121. insPlyIncome.setHandlingFeesStatus("0");
  122. baseMapper.insert(insPlyIncome);
  123. }
  124. private BigDecimal sumAmount(BigDecimal amount1, BigDecimal amount2, BigDecimal amount3) {
  125. BigDecimal jqNoTaxPremium = (amount1 != null) ? amount1 : BigDecimal.ZERO;
  126. BigDecimal syNoTaxPremium = (amount2 != null) ? amount2 : BigDecimal.ZERO;
  127. BigDecimal noNoTaxPremium = (amount3 != null) ? amount3 : BigDecimal.ZERO;
  128. return jqNoTaxPremium.add(syNoTaxPremium).add(noNoTaxPremium);
  129. }
  130. public HttpResult<BasePageResult<InsPlyIncome>> queryNew(InsPlyIncomeVo insPlyIncomeVo){
  131. try{
  132. HashMap<String, Object> params = new HashMap<>();
  133. PageInfo<List<InsPlyIncome>> pageHelper = null;
  134. PageHelper.startPage(insPlyIncomeVo.getPageNum(),insPlyIncomeVo.getPageSize());
  135. params.put("pageNum",insPlyIncomeVo.getPageNum());
  136. params.put("pageSize",insPlyIncomeVo.getPageSize());
  137. params.put("startDate",insPlyIncomeVo.getStartDate().toString());
  138. params.put("endDate",insPlyIncomeVo.getEndDate().toString());
  139. List<InsPlyIncome> list= this.baseMapper.queryNew(params);
  140. pageHelper=new PageInfo(list);
  141. BasePageResult<InsPlyIncome> pageResult=new BasePageResult<InsPlyIncome>(insPlyIncomeVo.getPageNum(), insPlyIncomeVo.getPageSize(), pageHelper.getTotal(), pageHelper.getPages(), list);
  142. return HttpResult.ok(pageResult);
  143. }catch (Exception e){
  144. e.printStackTrace();
  145. return HttpResult.error("查询异常");
  146. }
  147. }
  148. @Override
  149. @Transactional
  150. public void uodateBalance(InsPlyIncomeVo insPlyIncomeVo) {
  151. InsPlyIncome insPlyIncome = new InsPlyIncome();
  152. BeanUtils.copyProperties(insPlyIncomeVo, insPlyIncome);
  153. baseMapper.uopdateByOrderno(insPlyIncome);
  154. // 生成记录
  155. SettlementDocumentaryLogEntity settlementDocumentaryLogEntity = new SettlementDocumentaryLogEntity();
  156. settlementDocumentaryLogEntity.setAmount(insPlyIncomeVo.getCommissionFeevalue()); // 手续费金额
  157. settlementDocumentaryLogEntity.setSettlementDocumentaryId(insPlyIncomeVo.getOrderno()); // 关联id
  158. settlementDocumentaryLogEntity.setAmountType("1"); //手续费结算
  159. settlementDocumentaryLogEntity.setCreateTime(new Date());
  160. settlementDocumentaryLogService.save(settlementDocumentaryLogEntity);
  161. }
  162. @Override
  163. @Transactional
  164. public HttpResult<BasePageResult<InsPlyIncome>> totalQuery(InsPlyIncomeVo insPlyIncomeVo) {
  165. HashMap<String, Object> params = new HashMap<>();
  166. PageInfo<List<InsPlyIncome>> pageHelper = null;
  167. params.put("startDate",insPlyIncomeVo.getStartDate().toString());
  168. params.put("endDate",insPlyIncomeVo.getEndDate().toString());
  169. // 判断非跟单结算日期是否已经存在
  170. String resultDate = this.JudgingDate(params);
  171. if(StringUtils.isNotEmpty(resultDate)){
  172. return HttpResult.error("该时间段已近有单据做过结算,请结算");
  173. }
  174. params.put("pageNum",insPlyIncomeVo.getPageNum());
  175. params.put("pageSize",insPlyIncomeVo.getPageSize());
  176. List<InsPlyIncome> list= this.baseMapper.totalQuery(params);
  177. pageHelper=new PageInfo(list);
  178. return HttpResult.ok(new BasePageResult<>(insPlyIncomeVo.getPageNum(), insPlyIncomeVo.getPageSize(), pageHelper.getTotal(), pageHelper.getPages(), list));
  179. }
  180. private String JudgingDate(HashMap<String, Object> params) {
  181. if(ObjectUtils.isNotEmpty(params.get("startDate")) && ObjectUtils.isNotEmpty(params.get("endDate")) ){
  182. String checkResult = settlementDocumentaryFeesService.checkDate(params);
  183. if(StringUtils.isNotEmpty(checkResult)){
  184. return checkResult;
  185. }
  186. }
  187. return null;
  188. }
  189. @Override
  190. @Transactional
  191. public void batchBalance(InsPlyIncomeVo insPlyIncomeVo) {
  192. // 生成新数据
  193. SettlementDocumentaryFeesVo settlementDocumentaryFeesVo = new SettlementDocumentaryFeesVo();
  194. settlementDocumentaryFeesVo.setTotalAmount(insPlyIncomeVo.getTotAmount());
  195. settlementDocumentaryFeesVo.setTotalOrders(insPlyIncomeVo.getTotalorders());
  196. settlementDocumentaryFeesVo.setTimeFrame(insPlyIncomeVo.getTimeFrame());
  197. settlementDocumentaryFeesVo.setCreateTime(LocalDateTime.now());
  198. settlementDocumentaryFeesVo.setStartTime(insPlyIncomeVo.getStartDate().atStartOfDay());
  199. settlementDocumentaryFeesVo.setEndTime(insPlyIncomeVo.getEndDate().atStartOfDay());
  200. settlementDocumentaryFeesVo.setSettlementAmount(insPlyIncomeVo.getSettlementAmount());// 结算金额
  201. settlementDocumentaryFeesVo.setUnsettledAmount(insPlyIncomeVo.getTotAmount().subtract(insPlyIncomeVo.getSettlementAmount())); //未结算金额
  202. settlementDocumentaryFeesService.inertSettle(settlementDocumentaryFeesVo);
  203. //
  204. }
  205. }