|
|
@@ -4,15 +4,35 @@ 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;
|
|
|
|
|
|
/**
|
|
|
@@ -27,6 +47,19 @@ import java.util.List;
|
|
|
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{
|
|
|
@@ -44,5 +77,162 @@ public class InsPlyIncomeServiceImpl extends ServiceImpl<InsPlyIncomeMapper, Ins
|
|
|
|
|
|
|
|
|
|
|
|
+ }
|
|
|
+
|
|
|
+ @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);
|
|
|
+
|
|
|
+
|
|
|
+//
|
|
|
}
|
|
|
}
|