| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- package com.ydtech.modules.fnc.service.impl;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.github.pagehelper.PageHelper;
- import com.github.pagehelper.PageInfo;
- import com.ydtech.core.page.HttpResult;
- import com.ydtech.modules.admin.model.po.SysAmountAuditingEntity;
- import com.ydtech.modules.admin.model.po.SysUserAccountHistory;
- import com.ydtech.modules.fnc.entity.InsPlyIncome;
- import com.ydtech.modules.fnc.dao.InsPlyIncomeMapper;
- import com.ydtech.modules.fnc.entity.SettlementDocumentaryLogEntity;
- import com.ydtech.modules.fnc.service.InsPlyIncomeService;
- import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
- import com.ydtech.modules.fnc.service.SettlementDocumentaryFeesService;
- import com.ydtech.modules.fnc.service.SettlementDocumentaryLogService;
- import com.ydtech.modules.fnc.vo.InsPlyIncomeVo;
- import com.ydtech.modules.fnc.vo.SettlementDocumentaryFeesVo;
- import com.ydtech.modules.order.entity.BasePageResult;
- import com.ydtech.modules.order.entity.InsAreaCompany;
- import com.ydtech.modules.order.entity.InsOrders;
- import com.ydtech.modules.order.service.InsAreaCompanyService;
- import com.ydtech.modules.order.service.InsOrdersService;
- import com.ydtech.modules.protocols.entity.po.InsFeeOrderNew;
- import com.ydtech.modules.protocols.service.InsFeeOrderNewService;
- import org.apache.commons.lang3.ObjectUtils;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.BeanUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import java.math.BigDecimal;
- import java.time.LocalDateTime;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.List;
- /**
- * <p>
- * 保司结算手续费 服务实现类
- * </p>
- *
- * @author gws
- * @since 2024-01-05
- */
- @Service
- public class InsPlyIncomeServiceImpl extends ServiceImpl<InsPlyIncomeMapper, InsPlyIncome> implements InsPlyIncomeService {
- @Autowired
- private InsOrdersService insOrdersService;
- @Autowired
- private InsAreaCompanyService insAreaCompanyService;
- @Autowired
- private InsFeeOrderNewService insFeeOrderNewService;
- @Autowired
- private SettlementDocumentaryFeesService settlementDocumentaryFeesService;
- @Autowired
- private SettlementDocumentaryLogService settlementDocumentaryLogService;
- public HttpResult<BasePageResult<InsPlyIncome>> queryplyIncome(InsPlyIncomeVo insPlyIncomeVo){
- try{
- Page<InsOrders> page = new Page<>(insPlyIncomeVo.getPageNum(), insPlyIncomeVo.getPageSize());
- PageInfo<List<InsPlyIncome>> pageHelper = null;
- PageHelper.startPage(insPlyIncomeVo.getPageNum(),insPlyIncomeVo.getPageSize());
- List<InsPlyIncome> list= this.baseMapper.selectByCondition(insPlyIncomeVo);
- pageHelper=new PageInfo(list);
- BasePageResult<InsPlyIncome> pageResult=new BasePageResult<InsPlyIncome>(insPlyIncomeVo.getPageNum(), insPlyIncomeVo.getPageSize(), pageHelper.getTotal(), pageHelper.getPages(), list);
- return HttpResult.ok(pageResult);
- }catch (Exception e){
- e.printStackTrace();
- return HttpResult.error("查询异常");
- }
- }
- @Override
- public void saveBalance(String companyId, String orderno) {
- InsOrders insOrders = insOrdersService.getById(orderno);
- InsAreaCompany insAreaCompany = insAreaCompanyService.getById(companyId);
- InsFeeOrderNew insFeeOrderNew = insFeeOrderNewService.getInsFeeOrderNewByCompanyId(companyId);
- this.saveBalanc(insFeeOrderNew, insOrders, insAreaCompany);
- }
- private void saveBalanc(InsFeeOrderNew insFeeOrderNew, InsOrders insOrders, InsAreaCompany insAreaCompany) {
- StringBuffer stringBuffer = new StringBuffer();
- InsPlyIncome insPlyIncome = new InsPlyIncome();
- if (ObjectUtils.isNotEmpty(insAreaCompany)) {
- // 使用链式条件判断来减少嵌套
- if (StringUtils.isNotEmpty(insAreaCompany.getJqpolicyno())) {
- stringBuffer.append(insAreaCompany.getJqpolicyno());
- if (StringUtils.isNotEmpty(insAreaCompany.getSypolicyno())) {
- stringBuffer.append(",");
- stringBuffer.append(insAreaCompany.getSypolicyno());
- }
- } else if (StringUtils.isNotEmpty(insAreaCompany.getSypolicyno())) {
- // 如果jqpolicyno为空但sypolicyno不为空,则只添加sypolicyno
- stringBuffer.append(insAreaCompany.getSypolicyno());
- }
- }
- String policyno = stringBuffer.toString(); // 保单号
- insPlyIncome.setOrderno(insOrders.getOrderno());
- insPlyIncome.setPolicyno(policyno);
- insPlyIncome.setDeptId(insFeeOrderNew.getDeptId());
- insPlyIncome.setRiskcode(insOrders.getProductid());
- insPlyIncome.setPayDate(insAreaCompany.getPayDate());
- insPlyIncome.setSignDate(insAreaCompany.getSigningTime());
- insPlyIncome.setCompanyId(insAreaCompany.getCompanyId());
- insPlyIncome.setAgreementId(insFeeOrderNew.getAgreementId());
- insPlyIncome.setLicenseno(insOrders.getLicenseno());
- insPlyIncome.setTaxamount(insAreaCompany.getTaxamount());
- BigDecimal bigDecimal = this.sumAmount(insFeeOrderNew.getJqNoTaxPremium(), insFeeOrderNew.getSyNoTaxPremium(), insFeeOrderNew.getNoNoTaxPremium());
- // 不含保费
- insPlyIncome.setNoTaxPremium(bigDecimal);
- // 手续费比例
- BigDecimal CostsProportion = this.sumAmount(insFeeOrderNew.getJqSuperviseCostsProportion(), insFeeOrderNew.getSySuperviseCostsProportion(), insFeeOrderNew.getNoSuperviseCostsProportion());
- insPlyIncome.setCommissionFeerate(CostsProportion);
- // 其他费用比例
- BigDecimal OtherCostsProportion = this.sumAmount(insFeeOrderNew.getJqOtherCostsProportion(), insFeeOrderNew.getSyOtherCostsProportion(), insFeeOrderNew.getNoOtherCostsProportion());
- insPlyIncome.setOtherFeerate(OtherCostsProportion);
- // 手续费金额
- BigDecimal SuperviseCostsPremiums = this.sumAmount(insFeeOrderNew.getJqSuperviseCostsPremiums(), insFeeOrderNew.getSySuperviseCostsPremiums(), insFeeOrderNew.getNoSuperviseCostsPremiums());
- insPlyIncome.setCommissionFeevalue(SuperviseCostsPremiums);
- // 其他费用金额
- BigDecimal OtherCostsPremiums = this.sumAmount(insFeeOrderNew.getJqOtherCostsPremiums(), insFeeOrderNew.getSyOtherCostsPremiums(), insFeeOrderNew.getNoOtherCostsPremiums());
- insPlyIncome.setOtherFeevalue(OtherCostsPremiums);
- insPlyIncome.setAllFeeValue(SuperviseCostsPremiums.add(OtherCostsPremiums));
- insPlyIncome.setCreateTime(LocalDateTime.now());
- insPlyIncome.setDocumentaryFeesStatus("0");
- insPlyIncome.setHandlingFeesStatus("0");
- baseMapper.insert(insPlyIncome);
- }
- private BigDecimal sumAmount(BigDecimal amount1, BigDecimal amount2, BigDecimal amount3) {
- BigDecimal jqNoTaxPremium = (amount1 != null) ? amount1 : BigDecimal.ZERO;
- BigDecimal syNoTaxPremium = (amount2 != null) ? amount2 : BigDecimal.ZERO;
- BigDecimal noNoTaxPremium = (amount3 != null) ? amount3 : BigDecimal.ZERO;
- return jqNoTaxPremium.add(syNoTaxPremium).add(noNoTaxPremium);
- }
- public HttpResult<BasePageResult<InsPlyIncome>> queryNew(InsPlyIncomeVo insPlyIncomeVo){
- try{
- HashMap<String, Object> params = new HashMap<>();
- PageInfo<List<InsPlyIncome>> pageHelper = null;
- PageHelper.startPage(insPlyIncomeVo.getPageNum(),insPlyIncomeVo.getPageSize());
- params.put("pageNum",insPlyIncomeVo.getPageNum());
- params.put("pageSize",insPlyIncomeVo.getPageSize());
- params.put("startDate",insPlyIncomeVo.getStartDate().toString());
- params.put("endDate",insPlyIncomeVo.getEndDate().toString());
- List<InsPlyIncome> list= this.baseMapper.queryNew(params);
- pageHelper=new PageInfo(list);
- BasePageResult<InsPlyIncome> pageResult=new BasePageResult<InsPlyIncome>(insPlyIncomeVo.getPageNum(), insPlyIncomeVo.getPageSize(), pageHelper.getTotal(), pageHelper.getPages(), list);
- return HttpResult.ok(pageResult);
- }catch (Exception e){
- e.printStackTrace();
- return HttpResult.error("查询异常");
- }
- }
- @Override
- @Transactional
- public void uodateBalance(InsPlyIncomeVo insPlyIncomeVo) {
- InsPlyIncome insPlyIncome = new InsPlyIncome();
- BeanUtils.copyProperties(insPlyIncomeVo, insPlyIncome);
- baseMapper.uopdateByOrderno(insPlyIncome);
- // 生成记录
- SettlementDocumentaryLogEntity settlementDocumentaryLogEntity = new SettlementDocumentaryLogEntity();
- settlementDocumentaryLogEntity.setAmount(insPlyIncomeVo.getCommissionFeevalue()); // 手续费金额
- settlementDocumentaryLogEntity.setSettlementDocumentaryId(insPlyIncomeVo.getOrderno()); // 关联id
- settlementDocumentaryLogEntity.setAmountType("1"); //手续费结算
- settlementDocumentaryLogEntity.setCreateTime(new Date());
- settlementDocumentaryLogService.save(settlementDocumentaryLogEntity);
- }
- @Override
- @Transactional
- public HttpResult<BasePageResult<InsPlyIncome>> totalQuery(InsPlyIncomeVo insPlyIncomeVo) {
- HashMap<String, Object> params = new HashMap<>();
- PageInfo<List<InsPlyIncome>> pageHelper = null;
- params.put("startDate",insPlyIncomeVo.getStartDate().toString());
- params.put("endDate",insPlyIncomeVo.getEndDate().toString());
- // 判断非跟单结算日期是否已经存在
- String resultDate = this.JudgingDate(params);
- if(StringUtils.isNotEmpty(resultDate)){
- return HttpResult.error("该时间段已近有单据做过结算,请结算");
- }
- params.put("pageNum",insPlyIncomeVo.getPageNum());
- params.put("pageSize",insPlyIncomeVo.getPageSize());
- List<InsPlyIncome> list= this.baseMapper.totalQuery(params);
- pageHelper=new PageInfo(list);
- return HttpResult.ok(new BasePageResult<>(insPlyIncomeVo.getPageNum(), insPlyIncomeVo.getPageSize(), pageHelper.getTotal(), pageHelper.getPages(), list));
- }
- private String JudgingDate(HashMap<String, Object> params) {
- if(ObjectUtils.isNotEmpty(params.get("startDate")) && ObjectUtils.isNotEmpty(params.get("endDate")) ){
- String checkResult = settlementDocumentaryFeesService.checkDate(params);
- if(StringUtils.isNotEmpty(checkResult)){
- return checkResult;
- }
- }
- return null;
- }
- @Override
- @Transactional
- public void batchBalance(InsPlyIncomeVo insPlyIncomeVo) {
- // 生成新数据
- SettlementDocumentaryFeesVo settlementDocumentaryFeesVo = new SettlementDocumentaryFeesVo();
- settlementDocumentaryFeesVo.setTotalAmount(insPlyIncomeVo.getTotAmount());
- settlementDocumentaryFeesVo.setTotalOrders(insPlyIncomeVo.getTotalorders());
- settlementDocumentaryFeesVo.setTimeFrame(insPlyIncomeVo.getTimeFrame());
- settlementDocumentaryFeesVo.setCreateTime(LocalDateTime.now());
- settlementDocumentaryFeesVo.setStartTime(insPlyIncomeVo.getStartDate().atStartOfDay());
- settlementDocumentaryFeesVo.setEndTime(insPlyIncomeVo.getEndDate().atStartOfDay());
- settlementDocumentaryFeesVo.setSettlementAmount(insPlyIncomeVo.getSettlementAmount());// 结算金额
- settlementDocumentaryFeesVo.setUnsettledAmount(insPlyIncomeVo.getTotAmount().subtract(insPlyIncomeVo.getSettlementAmount())); //未结算金额
- settlementDocumentaryFeesService.inertSettle(settlementDocumentaryFeesVo);
- //
- }
- }
|