init: 导入项目

This commit is contained in:
fengjun
2024-07-02 11:40:01 +08:00
commit 4c8e6701f2
7158 changed files with 1199718 additions and 0 deletions

62
feeCalc/pom.xml Normal file
View File

@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>AG_ONE</artifactId>
<groupId>com.ag.jngh</groupId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>feeCalc</artifactId>
<dependencies>
<dependency>
<groupId>com.ag.jngh</groupId>
<artifactId>commonapi</artifactId>
<version>1.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>anji-jsonGroup</groupId>
<artifactId>anji-jsonArtifact</artifactId>
<version>1.2</version>
</dependency>
<!-- 测试用, 将来移除-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
</dependency>
<!--<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.12</version>
<scope>compile</scope>
</dependency>-->
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>2.7.6</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.11</version>
</dependency>
</dependencies>
<build>
<finalName>feeCalc</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@@ -0,0 +1,12 @@
package com.ag.account;
/**
* @description: dubbo 入口
* @author: WangN
* @create: 2019-08-13
*/
public class Provider {
public static void main(String[] args) {
//com.alibaba.dubbo.container.Main.main(args);
}
}

View File

@@ -0,0 +1,56 @@
package com.ag.account.dao;
import com.ag.base.IBaseRepository;
import com.ag.entity.fee.AccountPoints;
import com.ag.entity.fee.BaseChargingItem;
import com.ag.util.StrUtil;
import org.springframework.stereotype.Repository;
import javax.annotation.Resource;
import java.util.List;
/**
* Created by Administrator on 2017/5/15 0015.
*/
@Repository
public class AccountPointsCalcDao {
@Resource(name="baseRepositoryImpl")
private IBaseRepository<AccountPoints> pointRepo;
@Resource(name="baseRepositoryImpl")
private IBaseRepository<BaseChargingItem> itemRepo;
public int delete(AccountPoints delAP) {
return pointRepo.delete(delAP, "POINT_CODE");
}
public int[] save(List<AccountPoints> accountPoints) {
return pointRepo.saveAll(accountPoints);
}
public List<AccountPoints> findByPointId(AccountPoints point) {
return pointRepo.findByEntity(point, AccountPoints.class);
}
public int save(AccountPoints point){
return pointRepo.save(point);
}
public List<BaseChargingItem> findInItemId(String items, String tenancyId) {
BaseChargingItem entity = new BaseChargingItem();
entity.setTenancyId(tenancyId);
String sql = itemRepo.getSelectByEntity(entity, false);
sql = StrUtil.join(sql, " and ID in(", items, ")");
return itemRepo.list(sql, BaseChargingItem.class);
}
public List<BaseChargingItem> findAll(String tenancyId){
BaseChargingItem entity = new BaseChargingItem();
entity.setTenancyId(tenancyId);
return itemRepo.findByEntity(entity, BaseChargingItem.class);
}
public List<AccountPoints> findAll(AccountPoints point) {
return pointRepo.findByEntity(point, AccountPoints.class, true);
}
}

View File

@@ -0,0 +1,166 @@
package com.ag.account.dao;
import com.ag.base.IBaseRepository;
import com.ag.entity.account.vo.BizVO;
import com.ag.entity.fee.*;
import com.ag.entity.fee.vo.ContractItemVO;
import com.ag.entity.fee.vo.ContractVO;
import com.ag.entity.fee.vo.TariffVO;
import com.ag.util.StrUtil;
import com.ag.util.TimeUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
/**
* Created by Administrator on 2017/5/16 0016.
*/
@Repository
public class BizContractsDao {
@Resource(name="baseRepositoryImpl")
private IBaseRepository<String> strRepo;
@Resource(name="baseRepositoryImpl")
private IBaseRepository<Tariff> tariffRepo;
@Resource(name="baseRepositoryImpl")
private IBaseRepository<TariffVO> tariffVORepo;
@Resource(name="baseRepositoryImpl")
private IBaseRepository<TariffRitem> ritemRepo;
@Resource(name="baseRepositoryImpl")
private IBaseRepository<ContractItem> contrItemRepo;
@Resource(name="baseRepositoryImpl")
private IBaseRepository<ContractVO> contractVORepo;
@Resource(name="baseRepositoryImpl")
private IBaseRepository<Contract> contractRepo;
@Resource(name="baseRepositoryImpl")
private IBaseRepository<ContractItemVO> contrItemVORepo;
@Resource(name="baseRepositoryImpl")
private IBaseRepository<TariffMultistep> stepORepo;
@Resource(name="baseRepositoryImpl")
private IBaseRepository<ItemProperties> itemPropertiesRepo;
/**
* 查询默认合同号
*/
public String findDefaultContractId(BizVO bizVO) {
String sql = "select ID from C_CONTRACT where IS_DEFAULT=1 and TENANCY_ID=?";
if (bizVO.getBizTime() == null){
bizVO.setBizTime(new Date());
}
sql = StrUtil.join(sql, " and EFFECTIVE_DATE<=", TimeUtil.toOrclDate(bizVO.getBizTime()));
sql = StrUtil.join(sql, " and EXPIRED_DATE>=", TimeUtil.toOrclDate(bizVO.getBizTime()));
List<String> lst = strRepo.listSingleColumn(sql, String.class, bizVO.getTenancyId());
if(CollectionUtils.isEmpty(lst)){
return null;
}else{
return lst.get(0);
}
}
public ContractVO findContractVOById(String defaultContractId, BizVO billVO) {
Contract contract = new Contract();
contract.setId(defaultContractId);
contract.setTenancyId(billVO.getTenancyId());
String sql = contractRepo.getSelectByEntity(contract, false);
return contractVORepo.get(sql, ContractVO.class);
}
/**
* 合同号 + 费目编号 = 查找所有合同费目
* @param defaultContractId
* @param billVO
* @return
*/
public List<ContractItemVO> findItemByContract(String defaultContractId, BizVO billVO) {
ContractItem ci = new ContractItem();
ci.setTenancyId(billVO.getTenancyId());
ci.setContractId(defaultContractId);
ci.setLifeStatus(1);
ci.setDelFlag(0);
String sql = contrItemRepo.getSelectByEntity(ci, false);
sql = StrUtil.join(sql, " and ITEM_ID in (", billVO.getItemIds(),")");
//System.out.println(sql);
return contrItemVORepo.list(sql, ContractItemVO.class);
}
/**
* 合同号 + 费目编号 = 查找所有费率
* @param defaultContractId
* @param billVO
* @return
*/
public List<TariffVO> findTariffByContract(String defaultContractId, BizVO billVO) {
Tariff tariff = new Tariff();
tariff.setTenancyId(billVO.getTenancyId());
tariff.setContractId(defaultContractId);
tariff.setDelFlag(0);
//tariff.setConfirmStatus(1);
String sql = tariffRepo.getSelectByEntity(tariff, false);
sql = StrUtil.join(sql, " and CHARGING_ID in (", billVO.getItemIds(),")");
//sql = StrUtil.join(sql, " and EXISTS (SELECT 1 FROM C_TARIFF_RULE WHERE id=FILTER_ID)");
return tariffVORepo.list(sql, TariffVO.class);
}
/**
* 合同号 + 费目编号 = 查找所有费率条件
* @param defaultContractId
* @param billVO
* @return
*/
public List<TariffRitem> findRitemByTariff(String defaultContractId, BizVO billVO) {
String sql = StringUtils.join("select a.* from C_TARIFF_RITEM a, C_TARIFF b ",
" where a.RULE_ID = b.ID and b.CONTRACT_ID=? and b.CHARGING_ID in(",
billVO.getItemIds(),") and b.DEL_FLAG=0");
if (!StrUtil.isEmpty(billVO.getTenancyId())){
sql = StrUtil.join(sql, " and b.TENANCY_ID='", billVO.getTenancyId(),"'");
}
return ritemRepo.list(sql, TariffRitem.class, defaultContractId);
}
public List<ItemProperties> findPropertiesByItems(BizVO billVO) {
ItemProperties properties = new ItemProperties();
properties.setTenancyId(billVO.getTenancyId());
String sql = itemPropertiesRepo.getSelectByEntity(properties, false);
sql = StrUtil.join(sql, " and ITEM_ID in (", billVO.getItemIds(),")");
return itemPropertiesRepo.list(sql, ItemProperties.class);
}
public List<TariffMultistep> findStepByTariff(String defaultContractId, BizVO billVO) {
String sql = StringUtils.join("select a.* from C_TARIFF_MULTISTEP a, C_TARIFF b ",
" where a.TARIFF_ID = b.ID and b.CONTRACT_ID=? and b.CHARGING_ID in(", billVO.getItemIds(),
") and b.DEL_FLAG=0");
if (!StrUtil.isEmpty(billVO.getTenancyId())){
sql = StrUtil.join(sql, " and b.TENANCY_ID='", billVO.getTenancyId(),"'");
}
return stepORepo.list(sql, TariffMultistep.class, defaultContractId);
}
public List<TariffMultistep> findCustomStepByTariff(String defaultContractId, BizVO billVO) {
String sql = StringUtils.join("select * from C_TARIFF_MULTISTEP ",
" where TARIFF_ID in (select ID from C_TARIFF " ,
" where TENANCY_ID=? and CONTRACT_ID=? and CHARGING_ID in (", billVO.getItemIds(),
") and CUSTOMERS like '%", billVO.getShipperCode() , "%' and RATE_TYPE=1) and TENANCY_ID=?");
return stepORepo.list(sql, TariffMultistep.class, billVO.getTenancyId(), defaultContractId,
billVO.getTenancyId());
}
public ContractVO findContractId(String defaultContractId, BizVO bizVO) {
//String sql = "select id from C_Contract where id in ('"+defaultContractId+"') and TENANCY_ID=?";
Contract contract = new Contract();
contract.setTenancyId(bizVO.getTenancyId());
String sql = contractRepo.getSelectByEntity(contract, true);
sql = StrUtil.join(sql, " and id in (", defaultContractId, ")");
sql = StrUtil.join(sql, " and EFFECTIVE_DATE<=", TimeUtil.toOrclDate(bizVO.getBizTime()));
sql = StrUtil.join(sql, " and EXPIRED_DATE>=", TimeUtil.toOrclDate(bizVO.getBizTime()));
return contractVORepo.get(sql, ContractVO.class);
}
}

View File

@@ -0,0 +1,293 @@
package com.ag.account.detail;
import com.ag.account.feeUtil.FormulaUtil;
import com.ag.account.feeUtil.NotesUtil;
import com.ag.account.feeUtil.ReductionUtil;
import com.ag.entity.account.FeeDetail;
import com.ag.entity.account.vo.BizVO;
import com.ag.entity.fee.BaseChargingItem;
import com.ag.entity.fee.ContractItem;
import com.ag.entity.fee.face.ICondition;
import com.ag.entity.fee.face.SourceProperty;
import com.ag.entity.fee.vo.TariffVO;
import com.ag.util.StrUtil;
import com.ag.util.TimeUtil;
import com.ag.util.UUIDUtil;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeanUtils;
import java.util.Date;
/**
* Created by Administrator on 2017/6/19 0019.
*/
public abstract class AccountDetail {
protected final Log logger = LogFactory.getLog(AccountDetail.class);
/******************************* start ***********************************/
public void getFeeDetail(BizVO bizVO, SourceProperty source) {
calcBefore(bizVO, source);
createFeeDetails(bizVO, source);
calcByTariff(source);
if (source.getPayDetail() != null){
bizVO.getDetails().add(source.getPayDetail());
calcByUnit(bizVO, source, source.getPayDetail());//计算公式
calcByDiscount(bizVO, source, source.getPayDetail());//优惠减免
}
if (source.getReceiveDetail() != null){
bizVO.getDetails().add(source.getReceiveDetail());
calcByUnit(bizVO, source, source.getReceiveDetail());//计算公式
calcByDiscount(bizVO, source, source.getReceiveDetail());//优惠减免
}
convertCurrentRatio(source);
}
/**
* 费率转换
* 应收应付不同币种,费率维护按应收维护,应付金额=应收金额/兑换比例
* 如果property里存在兑换比例属性CURRENCY_RATIO以property兑换比例为准
* @param source
*/
private void convertCurrentRatio(SourceProperty source) {
if (source.getPayDetail() == null || source.getReceiveDetail() == null){
return;
}
if (source.getContractItem().getPayCurrency() == null || source.getContractItem().getReceiveCurrency() == null){
return;
}
if (source.getContractItem().getPayCurrency().equals( source.getContractItem().getReceiveCurrency())){
return;
}
Double ratio = 0d;
if (source.getContractItem().getCurrencyRatio() != null){
ratio = source.getContractItem().getCurrencyRatio();
}
if (source.getProperty().get(ICondition.CURRENCY_RATIO) != null){
ratio = source.getProperty().getDouble(ICondition.CURRENCY_RATIO);
}
if (ratio == 0d){
return;
}
FeeDetail pay = source.getPayDetail();
pay.setCurrency(source.getContractItem().getPayCurrency());
pay.setStRate(pay.getStRate() / ratio);
pay.setActualRate(pay.getActualRate() / ratio);
pay.setStMoney(pay.getStMoney() / ratio);
pay.setFinalMoney(pay.getFinalMoney() / ratio);
}
/**
* 按费率规则修改计费明细
*/
private void calcByTariff(SourceProperty source) {
ContractItem contractItem = source.getContractItem();
JSONObject json = source.getProperty();
TariffVO tariffVO = source.getTariffVO();
if (!StrUtil.isEmpty(tariffVO.getReceiveCode())){
if (source.getReceiveDetail() == null){
FeeDetail detail = new FeeDetail();
BeanUtils.copyProperties(source.getPayDetail(), detail);
detail.setId(UUIDUtil.getUUID());
detail.setPayReceiveType("0");
source.setReceiveDetail(detail);
}
source.getReceiveDetail().setClientCode(json.getString(tariffVO.getReceiveCode()));
}/*else {
source.setReceiveDetail(null);
}*/
if (!StrUtil.isEmpty(tariffVO.getPayCode())){
if (source.getPayDetail() == null){
FeeDetail detail = new FeeDetail();
BeanUtils.copyProperties(source.getReceiveDetail(), detail);
detail.setId(UUIDUtil.getUUID());
detail.setPayReceiveType("1");
source.setPayDetail(detail);
}
source.getPayDetail().setClientCode(json.getString(tariffVO.getPayCode()));
} /*else {
source.setPayDetail(null);
}*/
if (tariffVO.getPayRate() != null && source.getPayDetail() != null){
source.getPayDetail().setStRate(tariffVO.getPayRate());
source.getPayDetail().setActualRate(tariffVO.getPayRate());
setMoney(source.getPayDetail(), contractItem);
}
if (tariffVO.getReceiveRate() != null && source.getReceiveDetail() != null){
source.getReceiveDetail().setStRate(tariffVO.getReceiveRate());
source.getReceiveDetail().setActualRate(tariffVO.getReceiveRate());
setMoney(source.getReceiveDetail(), contractItem);
}
if (!StrUtil.isEmpty(tariffVO.getPayCurrency()) && source.getPayDetail() != null){
source.getPayDetail().setCurrency(tariffVO.getPayCurrency());
}
if (!StrUtil.isEmpty(tariffVO.getReceiveCurrency()) && source.getReceiveDetail() != null){
source.getReceiveDetail().setCurrency(tariffVO.getReceiveCurrency());
}
if (!StrUtil.isEmpty(tariffVO.getPayMan()) && source.getPayDetail() != null){
source.getPayDetail().setClientCode(tariffVO.getPayMan());
}
if (!StrUtil.isEmpty(tariffVO.getReceiveMan()) && source.getReceiveDetail() != null){
source.getReceiveDetail().setClientCode(tariffVO.getReceiveMan());
}
}
/**
* 计费前数据处理
*/
protected void calcBefore(BizVO bizVO, SourceProperty property){
}
/***
* 按计费单位算金额
*/
protected void calcByUnit(BizVO bizVO, SourceProperty property, FeeDetail detail){
}
/**
* 优惠减免
*/
protected void calcByDiscount(BizVO bizVO, SourceProperty source, FeeDetail detail) {
ReductionUtil.calcByDiscount(source.getProperty(), detail);
}
protected void createFeeDetails(BizVO bizVO, SourceProperty source) {
ContractItem contractItem = source.getContractItem();
TariffVO tariffVO = source.getTariffVO();
JSONObject property = source.getProperty();
FeeDetail fee = new FeeDetail();
fee.setTenancyId(bizVO.getTenancyId());
fee.setBussinessCode(source.getBizId());
fee.setJobFinishDate(TimeUtil.getTimestamp(source.getBizTime()));
fee.setJobCategoryCode(source.getBizType());
fee.setContractId(contractItem.getContractId());
fee.setFeeGroupId(contractItem.getCategoryId());
fee.setFeeListId(contractItem.getItemId());
fee.setCurrency(StrUtil.isEmpty(contractItem.getCurrency()) ? ICondition.DEFAULT_CURRENCY : contractItem.getCurrency());
fee.setInvoiceType(contractItem.getInvoiceType());
fee.setUnitId(contractItem.getUnit());
fee.setEnabled(contractItem.getEnabled());
fee.setSourceItemCode(contractItem.getSourceItemCode());
BaseChargingItem baseItem = bizVO.getItemMap().get(contractItem.getItemId());
fee.setOriginalItemName(baseItem.getDescription());
fee.setItemCode(baseItem.getItemCode());
//fee.setAuditFlag(0);
fee.setCreatedBy(bizVO.getReqSource().getOperMan());
fee.setCreatedOn(new Date());
fee.setUpdatedBy(bizVO.getReqSource().getOperMan());
fee.setUpdatedOn(new Date());
//fee.setCancelFlag(0);
//fee.setSettleStatus(0);
fee.setStRate(tariffVO.getRate());//标准费率
fee.setActualRate(fee.getStRate());//执行费率
FormulaUtil.execute(source, contractItem, fee);//获取表达式费率(更新执行费率)
fee.setQuantity(getQuantity(property, contractItem));//数量,默认1d
fee.setDiscount(getDiscount(property));//折扣,默认100d
fee.setSettleDays(getSettleDays(bizVO));//结算天,默认1
setMoney(fee, contractItem);
if (!StrUtil.isEmpty(tariffVO.getCurrency())){
fee.setCurrency(tariffVO.getCurrency());
}
fee.setTariffNote(tariffVO.getNotes());
NotesUtil.setFeeByTariffScription(fee, source);
//应收费用明细
if (!StrUtil.isEmpty(contractItem.getReceiveCode())){
fee.setId(UUIDUtil.getUUID());
fee.setPayReceiveType("0");
if (StrUtil.isEmpty(contractItem.getReceiveMan())) {
fee.setClientCode(getReckoner(property, contractItem.getReceiveCode()));
}else {
fee.setClientCode(contractItem.getReceiveMan());
}
if (!StrUtil.isEmpty(contractItem.getReceiveCurrency())) {
fee.setCurrency(contractItem.getReceiveCurrency());
}
source.setReceiveDetail(fee);
}
//应付费用明细
if (!StrUtil.isEmpty(contractItem.getPayCode())){
FeeDetail payDetail = new FeeDetail();
BeanUtils.copyProperties(fee, payDetail);
payDetail.setId(UUIDUtil.getUUID());
payDetail.setPayReceiveType("1");
if (StrUtil.isEmpty(contractItem.getPayMan())) {
payDetail.setClientCode(getReckoner(property, contractItem.getPayCode()));
}else {
payDetail.setClientCode(contractItem.getPayMan());
}
if (!StrUtil.isEmpty(contractItem.getPayCurrency())) {
fee.setCurrency(contractItem.getPayCurrency());
}
source.setPayDetail(payDetail);
}
}
protected String getReckoner(JSONObject property, String ownerCode) {
return property.getString(ownerCode);
}
protected void setMoney(FeeDetail fee, ContractItem contractItem) {
fee.setCalcMoney(fee.getActualRate() * fee.getQuantity()* fee.getDiscount()* fee.getSettleDays() / 100);
fee.setStMoney(fee.getStRate() * fee.getQuantity() * fee.getDiscount() * fee.getSettleDays() / 100);
fee.setFinalMoney(fee.getCalcMoney());
if (contractItem.getAmountFormat() == null){
return;
}
if (contractItem.getFormatUnit() == null){
contractItem.setFormatUnit(0);
}
//进整
if (contractItem.getAmountFormat() == 0) {
fee.setCalcMoney(Math.ceil(fee.getCalcMoney()));
}
//四舍五入
if (contractItem.getAmountFormat() == 1) {
//元
if (contractItem.getFormatUnit() == 0) {
fee.setCalcMoney((double) Math.round(fee.getCalcMoney()));
}
//角
if (contractItem.getFormatUnit() == 1) {
fee.setCalcMoney((double) Math.round(fee.getCalcMoney() * 10) / 10);
}
//分
if (contractItem.getFormatUnit() == 2) {
fee.setCalcMoney((double) Math.round(fee.getCalcMoney() * 100) / 100);
}
}
//去小数
if (contractItem.getAmountFormat() == 2) {
fee.setCalcMoney(Math.floor(fee.getCalcMoney()));
}
fee.setFinalMoney(fee.getCalcMoney());
}
protected Double getQuantity(JSONObject property, ContractItem contractItem){
return 1d;
}
protected Double getDiscount(JSONObject property) {
return 100d;
}
protected Integer getSettleDays(BizVO bizVO){
return 1;
}
}

View File

@@ -0,0 +1,40 @@
package com.ag.account.detail;
import com.ag.account.detail.AccountDetail;
import com.ag.account.detail.impl.*;
import com.ag.entity.fee.vo.ContractItemVO;
import org.springframework.util.Assert;
/**
* Created by Administrator on 2017/6/1 0001.
*/
public class CalcManager {
//计价单位0=(拼)箱 4=票 5=箱*天 6=吨*天
// 9=阶梯包干价 14=计费吨 18=阶梯单价
public static AccountDetail getInstance(ContractItemVO vo){
Assert.notNull(vo.getUnit(), "计费单位不能为空!费目编号:"+vo.getItemId());
if("0".equals(vo.getUnit())){
return new CntrShipDetail();
}
if("4".equals(vo.getUnit())){
return new BillShipDetail();
}
if("5".equals(vo.getUnit())){
return new CntrStoreDetail();
}
if("6".equals(vo.getUnit())){
return new BulkStoreDetail();
}
if("9".equals(vo.getUnit())){
return new StepSumDetail();
}
if("14".equals(vo.getUnit())){
return new BulkShipDetail();
}
if ("18".equals(vo.getUnit())){
return new StepRateDetail();
}
return null;
}
}

View File

@@ -0,0 +1,12 @@
package com.ag.account.detail.impl;
import com.ag.account.detail.AccountDetail;
/**
* 按票计费
*/
public class BillShipDetail extends AccountDetail {
}

View File

@@ -0,0 +1,27 @@
package com.ag.account.detail.impl;
import com.ag.account.detail.AccountDetail;
import com.ag.account.feeUtil.BulkTonUtil;
import com.ag.entity.fee.ContractItem;
import com.ag.entity.fee.face.ICondition;
import com.alibaba.fastjson.JSONObject;
import org.springframework.util.Assert;
/**
* 计费吨
*/
public class BulkShipDetail extends AccountDetail {
/**
* 计价单位=计费吨,子类获取数量属性的方法重写
* @param property
* @param contractItem
* @return
*/
protected Double getQuantity(JSONObject property, ContractItem contractItem){
Assert.notNull(property.get(ICondition.weight), "重量不允许为空");
Double ton = BulkTonUtil.calcTon(property, contractItem);
return BulkTonUtil.roundTon(ton, contractItem);
}
}

View File

@@ -0,0 +1,123 @@
package com.ag.account.detail.impl;
import cn.hutool.core.util.ObjectUtil;
import com.ag.account.detail.AccountDetail;
import com.ag.account.feeUtil.BulkTonUtil;
import com.ag.account.feeUtil.MultiStepUtil;
import com.ag.account.feeUtil.ReductionUtil;
import com.ag.entity.account.FeeDetail;
import com.ag.entity.account.vo.BizVO;
import com.ag.entity.fee.ContractItem;
import com.ag.entity.fee.face.ICondition;
import com.ag.entity.fee.face.SourceProperty;
import com.ag.util.StrUtil;
import com.ag.util.TimeUtil;
import com.alibaba.fastjson.JSONObject;
import org.springframework.util.Assert;
import java.util.Date;
import java.util.List;
import java.util.Objects;
/**
* 计费吨*天
*/
public class BulkStoreDetail extends AccountDetail {
/**
* 计价单位=计费吨,子类获取数量属性的方法重写
* @param property
* @param contractItem
* @return
*/
protected Double getQuantity(JSONObject property, ContractItem contractItem){
Assert.notNull(property.get(ICondition.weight), "重量不允许为空");
Double ton = BulkTonUtil.calcTon(property, contractItem);
return BulkTonUtil.roundTon(ton, contractItem);
}
/**
* 重写优惠减免
*/
@Override
protected void calcByDiscount(BizVO bizVO, SourceProperty source, FeeDetail detail) {
ReductionUtil.calcByDerateDay(source, detail);//减免天后的金额
//ReductionUtil.calcByDiscount(source.getProperty(), detail);//优惠金额和折扣
}
@Override
protected void calcBefore(BizVO bizVO, SourceProperty source){
JSONObject popMap = source.getProperty();
if (!StrUtil.isEmpty(ICondition.TIME_ON)) {
bizVO.setStartDate(TimeUtil.getTimestamp(popMap.getString(ICondition.TIME_ON)));
}
if (!StrUtil.isEmpty(ICondition.TIME_END)) {
bizVO.setEndDate(TimeUtil.getTimestamp(popMap.getString(ICondition.TIME_END)));
}
}
/**
* 重写结算天
*/
@Override
protected Integer getSettleDays(BizVO bizVO){
return TimeUtil.compareDaysLimit(bizVO.getStartDate(), bizVO.getEndDate(), true) + 1;
}
/**
* 按吨*天计费
*/
@Override
protected void calcByUnit(BizVO bizVO, SourceProperty source, FeeDetail detail){
detail.setSettleTimeOn(bizVO.getStartDate());
detail.setSettleTimeEnd(bizVO.getEndDate());
detail.setCalcDays(detail.getSettleDays());//计费天
ContractItem contractItem = source.getContractItem();
//是否按阶梯生成费率明细 !=2 合计金额(单条明细),
if (!ObjectUtil.equal(contractItem.getByagent(), 2)) {
MultiStepUtil.calcAmount(source.getTariffVO(), detail);//计算堆存金额
detail.setStMoney(detail.getCalcMoney());//标准金额
detail.setFinalMoney(detail.getCalcMoney());//最终金额
return;
}
//是否按阶梯生成费率明细 =2 阶梯金额(多条明细)
List<FeeDetail> feeDetails = MultiStepUtil.calcAmountForList(source.getTariffVO(), detail);
/**
* 根据入场时间 -- 最近结算日期,计算已结算金额。
*/
JSONObject popMap = source.getProperty();
if (!StrUtil.isEmpty(popMap.getString(ICondition.LAST_ACCOUNT_ON))) {
Date lastAccountOn = TimeUtil.getTimestamp(popMap.getString(ICondition.LAST_ACCOUNT_ON));
bizVO.setEndDate(lastAccountOn);
//入场时间 》= 最后结算日期,不需要计算已结算金额。
if (getSettleDays(bizVO) <= 1){
bizVO.setEndDate(TimeUtil.getTimestamp(popMap.getString(ICondition.TIME_END)));
} else {
detail.setSettleTimeEnd(lastAccountOn);
detail.setSettleDays(getSettleDays(bizVO));//已结算计费天
detail.setCalcDays(detail.getSettleDays());//已结算计费天
List<FeeDetail> accountDetails = MultiStepUtil.calcAmountForList(source.getTariffVO(), detail);
for (FeeDetail account : accountDetails) {
account.setCalcMoney(-account.getCalcMoney());
account.setCalcDays(-account.getCalcDays());
}
for (FeeDetail target : feeDetails){
for (FeeDetail accountDetail : accountDetails){
if (Objects.equals(target.getActualRate(), accountDetail.getActualRate())){
target.setCalcMoney(target.getCalcMoney() + accountDetail.getCalcMoney());
target.setCalcDays(target.getCalcDays() + accountDetail.getCalcDays());
break;
}
}
}
}
}
bizVO.getDetails().remove(detail);
bizVO.getDetails().addAll(feeDetails);
for (FeeDetail detail1 : feeDetails){
detail1.setStMoney(detail1.getCalcMoney());//标准金额
detail1.setFinalMoney(detail1.getCalcMoney());//最终金额
}
}
}

View File

@@ -0,0 +1,26 @@
package com.ag.account.detail.impl;
import com.ag.account.detail.AccountDetail;
import com.ag.entity.fee.ContractItem;
import com.ag.entity.fee.face.ICondition;
import com.ag.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
/**
* 箱(拼箱数量=0.1
*/
public class CntrShipDetail extends AccountDetail {
@Override
protected Double getQuantity(JSONObject property, ContractItem contractItem){
double quantity = 1d;
if (!StrUtil.isEmpty(property.getString(ICondition.QUANTITY))){
quantity = Double.valueOf(property.getString(ICondition.QUANTITY));
}
if (quantity <= 0){
quantity = 1d;
}
return quantity;
}
}

View File

@@ -0,0 +1,61 @@
package com.ag.account.detail.impl;
import com.ag.account.detail.AccountDetail;
import com.ag.account.feeUtil.MultiStepUtil;
import com.ag.account.feeUtil.ReductionUtil;
import com.ag.entity.account.FeeDetail;
import com.ag.entity.account.vo.BizVO;
import com.ag.entity.fee.face.ICondition;
import com.ag.entity.fee.face.SourceProperty;
import com.ag.util.StrUtil;
import com.ag.util.TimeUtil;
import com.alibaba.fastjson.JSONObject;
/**
* 箱*天
* Created by Administrator on 2017/6/23 0023.
*/
public class CntrStoreDetail extends AccountDetail {
@Override
protected void calcBefore(BizVO bizVO, SourceProperty source){
JSONObject popMap = source.getProperty();
if (!StrUtil.isEmpty(ICondition.TIME_ON)) {
bizVO.setStartDate(TimeUtil.getTimestamp(popMap.getString(ICondition.TIME_ON)));
}
if (!StrUtil.isEmpty(ICondition.TIME_END)) {
bizVO.setEndDate(TimeUtil.getTimestamp(popMap.getString(ICondition.TIME_END)));
}
}
/**
* 重写结算天
*/
@Override
protected Integer getSettleDays(BizVO bizVO){
return TimeUtil.compareDaysLimit(bizVO.getStartDate(), bizVO.getEndDate(), true) + 1;
}
/**
* 按堆存天计费
*/
@Override
protected void calcByUnit(BizVO bizVO, SourceProperty source, FeeDetail detail){
detail.setSettleTimeOn(bizVO.getStartDate());
detail.setSettleTimeEnd(bizVO.getEndDate());
detail.setCalcDays(detail.getSettleDays());//计费天
MultiStepUtil.calcAmount(source.getTariffVO(), detail);//计算堆存金额
detail.setStMoney(detail.getCalcMoney());//标准金额
detail.setFinalMoney(detail.getCalcMoney());//最终金额
}
/**
* 重写优惠减免
*/
@Override
protected void calcByDiscount(BizVO bizVO, SourceProperty source, FeeDetail detail) {
ReductionUtil.calcByDerateDay(source, detail);//减免天后的金额
ReductionUtil.calcByDiscount(source.getProperty(), detail);//优惠金额和折扣
}
}

View File

@@ -0,0 +1,36 @@
package com.ag.account.detail.impl;
import com.ag.account.detail.AccountDetail;
import com.ag.account.feeUtil.CarStepUtil;
import com.ag.entity.account.FeeDetail;
import com.ag.entity.account.vo.BizVO;
import com.ag.entity.fee.ContractItem;
import com.ag.entity.fee.face.ICondition;
import com.ag.entity.fee.face.SourceProperty;
import com.alibaba.fastjson.JSONObject;
import org.springframework.util.Assert;
/**
* 阶梯单价
*/
public class StepRateDetail extends AccountDetail {
protected void calcBefore(BizVO bizVO, SourceProperty property){
Assert.notNull(property.getProperty().containsKey(ICondition.QUANTITY), "计价单位为数量时请求参数中QUANTITY不允许为空!");
}
@Override
protected Double getQuantity(JSONObject property, ContractItem contractItem){
return property.getDouble(ICondition.QUANTITY);
}
@Override
protected void calcByUnit(BizVO bizVO, SourceProperty source, FeeDetail detail){
CarStepUtil.calcAmount(source.getTariffVO(), detail);
detail.setStRate(detail.getCalcMoney());
detail.setActualRate(detail.getStRate());
detail.setCalcMoney(detail.getStRate() * detail.getQuantity());
detail.setStMoney(detail.getCalcMoney());//标准金额
detail.setFinalMoney(detail.getCalcMoney());//最终金额
}
}

View File

@@ -0,0 +1,23 @@
package com.ag.account.detail.impl;
import com.ag.account.detail.AccountDetail;
import com.ag.account.feeUtil.CarStepUtil;
import com.ag.entity.account.FeeDetail;
import com.ag.entity.account.vo.BizVO;
import com.ag.entity.fee.face.SourceProperty;
/**
* 阶梯包干价
* Created by Administrator on 2017-09-07.
*/
public class StepSumDetail extends AccountDetail {
@Override
protected void calcByUnit(BizVO bizVO, SourceProperty source, FeeDetail detail){
CarStepUtil.calcAmount(source.getTariffVO(), detail);
detail.setStMoney(detail.getCalcMoney());//标准金额
detail.setFinalMoney(detail.getCalcMoney());//最终金额
}
}

View File

@@ -0,0 +1,161 @@
package com.ag.account.feeUtil;
import com.ag.entity.fee.ContractItem;
import com.ag.entity.fee.face.IBulkTon;
import com.ag.entity.fee.face.ICondition;
import com.alibaba.fastjson.JSONObject;
/**
* Created by Administrator on 2018-03-17.
*/
public class BulkTonUtil {
/**
* 计算计费吨
* @param bulkTon
* @param itemVO
*/
public static void calcTon(IBulkTon bulkTon, ContractItem itemVO){
double weight = bulkTon.getWeight() == null ? 0 : bulkTon.getWeight() / 1000;
double volume = bulkTon.getVolume() == null ? 0 : bulkTon.getVolume();
//如果费率中的体积吨金额不为空将在detail中替换体积吨换算率重写rateamount等。
if (itemVO.getTonsStere() == null){
itemVO.setTonsStere(1d);
}
volume = volume * itemVO.getTonsStere();
//择大计费 0=计费吨1=重量吨2=体积吨
//无选择按计费吨
if(itemVO.getByton() == null || itemVO.getByton() == 0){
itemVO.setByton(0);
if (weight > volume){
bulkTon.setTon(weight);
}else {
bulkTon.setTon(volume);
}
}
if (itemVO.getByton() == 1){
bulkTon.setTon(weight);
}
if (itemVO.getByton() == 2){
bulkTon.setTon(volume);
}
//最小计费吨判断
if (itemVO.getMinTon() != null){
if (bulkTon.getTon() < itemVO.getMinTon()){
bulkTon.setTon(itemVO.getMinTon());
}
}
/*double volTon = volume * itemVO.getTonsStere();
if (weight > volTon){
bulkTon.setTon(weight);
}else {
bulkTon.setTon(volTon);
}
if (bulkTon.getTon() < 1){
bulkTon.setTon(1d);
}*/
}
public static Double calcTon(JSONObject json, ContractItem itemVO){
double target = 0d;
double weight = !json.containsKey(ICondition.weight) ? 0 : json.getDouble(ICondition.weight);
double volume = !json.containsKey(ICondition.volume) ? 0 : json.getDouble(ICondition.volume);
//如果费率中的体积吨金额不为空将在detail中替换体积吨换算率重写rateamount等。
if (itemVO.getTonsStere() == null){
itemVO.setTonsStere(1d);
}
volume = volume * itemVO.getTonsStere();
//择大计费 0=计费吨1=重量吨2=体积吨
if (weight > volume){
target = weight;
}else {
target = volume;
}
if (itemVO.getByton() == null){
itemVO.setByton(1);
}
if (itemVO.getByton() == 1 && weight > 0d){
target = weight;
}
if (itemVO.getByton() == 2 && volume > 0d){
target = volume;
}
//最小计费吨判断
if (itemVO.getMinTon() != null){
if (target < itemVO.getMinTon()){
target = itemVO.getMinTon();
}
}
return target;
}
/**
* 计费吨取整方式
* @param contractItem
*/
public static Double roundTon(Double ton, ContractItem contractItem) {
if (contractItem.getIsFormat() == null){
return ton;
}
//进整
if (contractItem.getIsFormat() == 0){
return Math.ceil(ton);
}
//四舍五入
if (contractItem.getIsFormat() == 1){
return (double)Math.round(ton);
}
//去小数
if (contractItem.getIsFormat() == 2){
return Math.floor(ton);
}
return null;
}
public static void roundTon(IBulkTon bulkTon, ContractItem contractItem) {
if (contractItem.getIsFormat() == null){
return;
}
//进整
if (contractItem.getIsFormat() == 0){
bulkTon.setTon(Math.ceil(bulkTon.getTon()));
}
//四舍五入
if (contractItem.getIsFormat() == 1){
bulkTon.setTon((double)Math.round(bulkTon.getTon()));
}
//去小数
if (contractItem.getIsFormat() == 2){
bulkTon.setTon(Math.floor(bulkTon.getTon()));
}
}
/**
* 吊箱超重取整方式
* @param bulkTon
* @param contractItem
*/
public static void roundOverTon(IBulkTon bulkTon, ContractItem contractItem) {
if (contractItem.getIsFormat() == null){
return;
}
if (bulkTon.getOverWeight() > 0 && bulkTon.getOverWeight() <= 0.5 && contractItem.getMinTon() != null){
bulkTon.setOverWeight(1.0);
}
//进整
if (contractItem.getIsFormat() == 0){
bulkTon.setOverWeight(Math.ceil(bulkTon.getOverWeight()));
}
//四舍五入
if (contractItem.getIsFormat() == 1){
bulkTon.setOverWeight((double)Math.round(bulkTon.getOverWeight()));
}
//去小数
if (contractItem.getIsFormat() == 2){
bulkTon.setOverWeight(Math.floor(bulkTon.getOverWeight()));
}
}
}

View File

@@ -0,0 +1,66 @@
package com.ag.account.feeUtil;
import cn.hutool.core.convert.Convert;
import com.ag.entity.account.FeeDetail;
import com.ag.entity.fee.TariffMultistep;
import com.ag.entity.fee.vo.TariffVO;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import java.util.List;
/**
* Created by Administrator on 2017-09-07.
*/
public class CarStepUtil {
/*public static void calcAmount(IFeeItemPrice cntrProperty, AccountsDetails account) {
TariffVO tariff = null;
if (cntrProperty.getCustomTariff() != null) {
tariff = cntrProperty.getCustomTariff();
} else if(cntrProperty.getBaseTariff() != null) {
tariff = cntrProperty.getBaseTariff();
}
if (tariff == null) {
return;
}
getAmount(account, tariff);
}*/
/**
* 阶梯费率算法
* @param feeDetail
* @param tariff
* @return
*/
public static void calcAmount(TariffVO tariff, FeeDetail feeDetail) {
feeDetail.setCalcMoney(null);//清空计费金额
List<TariffMultistep> stepList = tariff.getStepList();
Integer quantity = Convert.toInt(feeDetail.getQuantity());
//没有阶梯费率
if (CollectionUtils.isEmpty(stepList)){
feeDetail.setCalcMoney(quantity * tariff.getRate());
return;
}
//最大包干阶梯费率
TariffMultistep maxStep = null;
for (TariffMultistep step : stepList){
//赋值拖运包干公里数最大值4公里或20公里
if (maxStep == null || step.getStepRate() > maxStep.getStepRate()){
maxStep = step;
}
//公里数在阶梯范围内
if (quantity >= step.getStartVal() && quantity <= step.getEndVal()){
feeDetail.setCalcMoney(step.getStepRate());
return;
}
}
//超出阶梯费率范围(>20公里
if (feeDetail.getCalcMoney() == null){
//超出最大公里数部分
Assert.notNull(maxStep, "阶梯费率数据维护有误,请检查!");
double amount = (feeDetail.getQuantity() - maxStep.getEndVal()) * tariff.getRate();
feeDetail.setCalcMoney(amount + maxStep.getStepRate());
}
}
}

View File

@@ -0,0 +1,40 @@
package com.ag.account.feeUtil;
import cn.hutool.core.bean.BeanUtil;
import com.ag.entity.account.FeeDetail;
import com.ag.entity.account.vo.BizVO;
import com.ag.entity.fee.ContractItem;
import com.ag.entity.fee.face.SourceProperty;
import com.ag.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ql.util.express.DefaultContext;
import com.ql.util.express.ExpressRunner;
import java.math.BigDecimal;
/**
* Created by yangxh on 2022/1/5.
*/
public class FormulaUtil {
public static void execute(SourceProperty source, ContractItem citem, FeeDetail fee){
String formula = citem.getFormula();
if (StrUtil.isEmpty(formula) || StrUtil.isEmpty(formula.trim())){
return;
}
ExpressRunner runner = new ExpressRunner();
DefaultContext<String, Object> context = new DefaultContext<>();
context.putAll(source.getProperty());
context.put("RATE", fee.getActualRate());
Object res = null;
try {
res = runner.execute(formula, context, null, false, false);
} catch (Exception e) {
throw new RuntimeException("执行自定义表达式异常!"+citem.getFormula());
}
if(res != null) {
fee.setActualRate(Double.valueOf(res.toString()));
}
}
}

View File

@@ -0,0 +1,165 @@
package com.ag.account.feeUtil;
import com.ag.entity.account.FeeDetail;
import com.ag.entity.fee.TariffMultistep;
import com.ag.entity.fee.vo.TariffVO;
import com.ag.util.UUIDUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
/**
* Created by Administrator on 2017/6/27 0027.
* 堆存类阶梯算法,不要试图修改
*/
public class MultiStepUtil {
/*public static void calcAmount(SourceProperty source, FeeDetail account) {
TariffVO tariff = source.getTariffVO();
*//*if (cntrProperty.getCustomTariff() != null) {
tariff = cntrProperty.getCustomTariff();
} else if(cntrProperty.getBaseTariff() != null) {
tariff = cntrProperty.getBaseTariff();
}*//*
if (tariff == null) {
return;
}
//account.setDwellDays(cntrProperty.getDwellDays());
getAmount(tariff, account);
}*/
/**
* 阶梯费率算法
*
* @param tariff 费率
* @param feeDetail 目标
*/
public static void calcAmount(TariffVO tariff, FeeDetail feeDetail) {
//double days = cntrProperty.getDwellDays();
List<TariffMultistep> stepList = tariff.getStepList();
//没有阶梯费率
if (CollectionUtils.isEmpty(stepList)) {
//费率 * 堆存天 * 计费吨
feeDetail.setCalcMoney(tariff.getRate() * feeDetail.getSettleDays() * feeDetail.getQuantity());
return;
}
double amount = 0d;
feeDetail.setDerateDays(0);
for (TariffMultistep step : stepList) {
//减免天(阶梯费率=0
if (step.getStepRate() == 0) {
//account.setDerateDays(step.getEndVal() - step.getStartVal() + 1);
feeDetail.setDerateDays(step.getEndVal());
}
if (feeDetail.getDerateDays() > feeDetail.getSettleDays()) {
feeDetail.setDerateDays(feeDetail.getSettleDays());
}
if (feeDetail.getSettleDays() >= step.getEndVal()) {
amount += step.getStepRate() * (step.getEndVal() - step.getStartVal() + 1);
continue;
}
if (feeDetail.getSettleDays() >= step.getStartVal() && feeDetail.getSettleDays() <= step.getEndVal()) {
//account.setDwellDays(account.getDwellDays() - step.getStartVal() + 1);
int overDay = feeDetail.getSettleDays() - step.getStartVal() + 1;
amount += step.getStepRate() * overDay;
}
}
feeDetail.setCalcMoney(amount * feeDetail.getQuantity());
feeDetail.setCalcDays(feeDetail.getSettleDays() - feeDetail.getDerateDays());
if (feeDetail.getCalcDays() < 0){
feeDetail.setCalcDays(0);
}
//account.setDwellDays(account.getSettleDays() - account.getDerateDays());
}
public static List<FeeDetail> calcAmountForList(TariffVO tariff, FeeDetail feeDetail) {
List<FeeDetail> feeDetails = new ArrayList<>();
List<TariffMultistep> stepList = tariff.getStepList();
//没有阶梯费率
if (CollectionUtils.isEmpty(stepList)) {
//费率 * 堆存天 * 计费吨
feeDetail.setCalcMoney(tariff.getRate() * feeDetail.getSettleDays() * feeDetail.getQuantity());
feeDetails.add(feeDetail);
return feeDetails;
} else {
stepList.sort(Comparator.comparing(TariffMultistep::getStartVal));
}
//满N天费率上调M元无上限算法 (阶梯费率延伸)
List<TariffMultistep> steps = tariff.getStepList();
TariffMultistep realLast = steps.get(steps.size() - 1);
if (realLast.getEachDay() != null && realLast.getAddRate() != null) {
while (true) {
if (addStepObj(tariff, feeDetail)) {
break;
}
}
}
feeDetail.setDerateDays(0);//默认减免天
for (TariffMultistep step : stepList) {
//减免天(阶梯费率=0
if (step.getStepRate() == 0) {
//account.setDerateDays(step.getEndVal() - step.getStartVal() + 1);
feeDetail.setDerateDays(step.getEndVal());//更新减免天
}
//first堆存天 《= 减免天
if (feeDetail.getSettleDays() <= feeDetail.getDerateDays()) {
feeDetail.setDerateDays(feeDetail.getSettleDays());//更新减免天
}
//second堆存天 》= 阶梯费率上限
if (feeDetail.getSettleDays() >= step.getEndVal()) {
//amount += step.getStepRate() * (step.getEndVal() - step.getStartVal() + 1);
FeeDetail newDetail = new FeeDetail();
BeanUtils.copyProperties(feeDetail, newDetail);
newDetail.setId(UUIDUtil.getUUID());
newDetail.setActualRate(step.getStepRate());
newDetail.setCalcDays(step.getEndVal() - step.getStartVal() + 1);
feeDetails.add(newDetail);
continue;
}
//last堆存天在阶梯费率范围内的
if (feeDetail.getSettleDays() >= step.getStartVal() && feeDetail.getSettleDays() <= step.getEndVal()) {
int calcDay = feeDetail.getSettleDays() - step.getStartVal() + 1;
//amount += step.getStepRate() * calcDay;
FeeDetail newDetail = new FeeDetail();
BeanUtils.copyProperties(feeDetail, newDetail);
newDetail.setId(UUIDUtil.getUUID());
newDetail.setActualRate(step.getStepRate());
newDetail.setCalcDays(calcDay);
feeDetails.add(newDetail);
}
}
//feeDetail.setCalcMoney(amount * feeDetail.getQuantity());
//feeDetail.setCalcDays(feeDetail.getSettleDays() - feeDetail.getDerateDays());
//account.setDwellDays(account.getSettleDays() - account.getDerateDays());
for (FeeDetail newDetail : feeDetails) {
newDetail.setStRate(newDetail.getActualRate());
newDetail.setCalcMoney(newDetail.getActualRate() * newDetail.getCalcDays() * feeDetail.getQuantity());
}
return feeDetails;
}
private static boolean addStepObj(TariffVO tariff, FeeDetail feeDetail) {
List<TariffMultistep> steps = tariff.getStepList();
TariffMultistep last = steps.get(steps.size() - 1);
if (last.getEndVal() >= feeDetail.getSettleDays()) {
return true;
}
TariffMultistep next = new TariffMultistep();
next.setStartVal(last.getStartVal() + last.getEachDay());
next.setEndVal(last.getEndVal() + last.getEachDay());
next.setStepRate(last.getStepRate() + last.getAddRate());
next.setEachDay(last.getEachDay());
next.setAddRate(last.getAddRate());
steps.add(next);
return false;
}
}

View File

@@ -0,0 +1,143 @@
package com.ag.account.feeUtil;
import com.ag.entity.account.FeeDetail;
import com.ag.entity.fee.ItemProperties;
import com.ag.entity.fee.TariffRitem;
import com.ag.entity.fee.face.ICondition;
import com.ag.entity.fee.face.IRuleCondition;
import com.ag.entity.fee.face.SourceProperty;
import com.ag.entity.fee.vo.ContractItemVO;
import com.ag.entity.fee.vo.TariffVO;
import com.ag.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import java.util.List;
/**
* Created by Administrator on 2017-12-01.
*/
public class NotesUtil {
/*public static String setDataProperty(IProperty property){
String msg = "";
if (!StrUtil.isEmpty(property.getTradeId())){
msg = StrUtil.join(msg, "内外贸=",property.getTradeId());
}
if (!StrUtil.isEmpty(property.getiEId())){
msg = StrUtil.join(msg, ",进出口标记=",property.getiEId());
}
if (!StrUtil.isEmpty(property.getCntrSize())){
msg = StrUtil.join(msg, ",箱尺寸=",property.getCntrSize());
}
if (!StrUtil.isEmpty(property.geteFId())){
msg = StrUtil.join(msg, ",空重标记=",property.geteFId());
}
if (!StrUtil.isEmpty(property.getCntrType())){
msg = StrUtil.join(msg, ",货物属性=",property.getCntrType());
}
if (!StrUtil.isEmpty(property.getWorkWay())){
msg = StrUtil.join(msg, ",作业类型=",property.getWorkWay());
}
if (!StrUtil.isEmpty(property.getFeiAddress())){
msg = StrUtil.join(msg, ",计费区域=",property.getFeiAddress());
}
if (!StrUtil.isEmpty(property.getCarProperty())){
msg = StrUtil.join(msg, ",车辆性质=",property.getCarProperty());
}
if (!StrUtil.isEmpty(property.getPol())){
msg = StrUtil.join(msg, ",装货港=",property.getPol());
}
if (!StrUtil.isEmpty(property.getPod())){
msg = StrUtil.join(msg, ",卸货港=",property.getPod());
}
if (!StrUtil.isEmpty(property.getService())){
msg = StrUtil.join(msg, ",进口航线=", property.getService());
}
if (!StrUtil.isEmpty(property.getOservice())){
msg = StrUtil.join(msg, ",出口航线=", property.getOservice());
}
if (!StrUtil.isEmpty(property.getCntrOperatorCod())){
msg = StrUtil.join(msg, ",驳船公司=", property.getCntrOperatorCod());
}
if (!StrUtil.isEmpty(property.getsAdress())){
msg = StrUtil.join(msg, ",送货地址=", property.getsAdress());
}
if (!StrUtil.isEmpty(property.getColineCod())){
msg = StrUtil.join(msg, ",合作船公司=", property.getColineCod());
}
if (!StrUtil.isEmpty(property.getSettelType())){
msg = StrUtil.join(msg, ",货主结算类型=", property.getSettelType());
}
if (!StrUtil.isEmpty(property.getTransit())){
msg = StrUtil.join(msg, ",贸易方式=", property.getTransit());
}
if (!StrUtil.isEmpty(property.getShipConsignCod())){
msg = StrUtil.join(msg, ",货主=", property.getShipConsignCod());
}
if (!StrUtil.isEmpty(property.getGoodsNotes())){
msg = StrUtil.join(msg, ",货物名称=", property.getGoodsNotes());
}
if (!StrUtil.isEmpty(property.getiEICustomer())){
msg = StrUtil.join(msg, ",进口货主=", property.getiEICustomer());
}
if (!StrUtil.isEmpty(property.getVainRun())){
msg = StrUtil.join(msg, ",是否空跑=", property.getVainRun());
}
if (!StrUtil.isEmpty(property.getPtType())){
msg = StrUtil.join(msg, ",派车方式=", property.getPtType());
}
if(!StrUtil.isEmpty(property.getIsJk())){
msg = StrUtil.join(msg, ",是否借靠=", property.getIsJk());
}
if (property.getMainFlag() != null){
msg = StrUtil.join(msg, ",主单标志=", property.getMainFlag());
}
if (property.getSplitId() != null){
msg = StrUtil.join(msg, ",是否夹柜=", property.getSplitId());
}
return msg;
}*/
public static void setFeeByTariffScription(FeeDetail detail, SourceProperty source) {
TariffVO tariffVO = source.getTariffVO();
List<TariffRitem> ritemList = tariffVO.getRitemList();
List<ItemProperties> properties = ((ContractItemVO) source.getContractItem()).getItemProperties();
JSONObject property = source.getProperty();
String description = "";
for (ItemProperties itemProp : properties){
for (IRuleCondition ritem : ritemList) {
if (ICondition.RATE.equals(ritem.getKeyName())) {
continue;
}
if (itemProp.getPropertyCode().equals(ritem.getKeyName())){
description = StrUtil.join(description, getProperyDescription(ritem.getKeyName(), property));
// description = StrUtil.join(description, property.getString(ritem.getKeyName()), ",");
break;
}
}
}
detail.setTariffDescription(description);
}
private static String getProperyDescription(String keyName, JSONObject property){
if (StrUtil.isEmpty(property.getString(keyName))){
return "";
}
if ("V_C_SIZE_DATA_FEE".equals(keyName)){
return property.getString(keyName)+"'";
}
if ("E_F_IDCODE".equals(keyName)){
return property.getString(keyName);
}
if ("TRANS_FLAG_FEE".equals(keyName)){
return property.getString(keyName);
}
if ("TAKEOVER_PROXY_FEE".equals(keyName)){
return property.getString(keyName);
}
return property.getString(keyName)+",";
}
}

View File

@@ -0,0 +1,135 @@
package com.ag.account.feeUtil;
import com.ag.entity.account.FeeDetail;
import com.ag.entity.fee.TariffMultistep;
import com.ag.entity.fee.face.ICondition;
import com.ag.entity.fee.face.SourceProperty;
import com.ag.entity.fee.vo.TariffVO;
import com.ag.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.BeanUtils;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
/**
* Created by yangxh on 2019/8/21.
*/
public class ReductionUtil {
/**
* 金额打折
*/
public static void calcByDiscount(JSONObject json, FeeDetail detail){
//减免金额
if (!StrUtil.isEmpty(json.getString(ICondition.DERATE_MONEY)) && json.getDouble(ICondition.DERATE_MONEY) > 0){
detail.setDerateMoney(json.getDouble(ICondition.DERATE_MONEY));
detail.setFinalMoney(detail.getCalcMoney() - json.getDouble(ICondition.DERATE_MONEY));
detail.setDiscount(detail.getCalcMoney() / detail.getStMoney() * 100);//最终折扣
}
//折扣
if (!StrUtil.isEmpty(json.getString(ICondition.DISCOUNT)) && json.getDouble(ICondition.DISCOUNT) > 0){
detail.setDiscount(json.getDouble(ICondition.DISCOUNT));
detail.setFinalMoney(detail.getCalcMoney() * json.getDouble(ICondition.DISCOUNT) / 100);
detail.setDiscount(detail.getFinalMoney() / detail.getStMoney() * 100);//最终折扣
}
if (detail.getActualRate() >= 0 && detail.getFinalMoney() < 0){
detail.setFinalMoney(0d);
}
/*if (detail.getActualMoney() < 0){
detail.setActualMoney(0d);
}*/
}
/**
* 重置减免天数
*/
public static void calcByDerateDay(SourceProperty source, FeeDetail detail){
JSONObject json = source.getProperty();
if (StrUtil.isEmpty(json.getString(ICondition.DERATE_TYPE))){
return;
}
if (StrUtil.isEmpty(json.getString(ICondition.DERATE_DAY))){
return;
}
if (json.getInteger(ICondition.DERATE_DAY) < 0){
return;
}
//获取标准阶梯费率
TariffVO tariffVO = source.getTariffVO();
List<TariffMultistep> stepList = tariffVO.getStepList();
//减免类型(前免)
if (json.getInteger(ICondition.DERATE_TYPE) == 0){
//创建新费率
TariffVO derateTariff = new TariffVO();
source.setDerateTariff(derateTariff);
BeanUtils.copyProperties(tariffVO, derateTariff);
//构建前免天后的阶梯
List<TariffMultistep> stepListNew = new ArrayList<>();
derateTariff.setStepList(stepListNew);
TariffMultistep stepNewFirst = new TariffMultistep();
stepNewFirst.setStartVal(1);
stepNewFirst.setEndVal(json.getInteger(ICondition.DERATE_DAY));
stepNewFirst.setStepRate(0d);
stepListNew.add(stepNewFirst);
//无阶梯费率
if (CollectionUtils.isEmpty(stepList)){
TariffMultistep stepNewSecond = new TariffMultistep();
stepNewSecond.setStartVal(json.getInteger(ICondition.DERATE_DAY) + 1);
stepNewSecond.setEndVal(9999);
stepNewFirst.setStepRate(tariffVO.getRate());
stepListNew.add(stepNewSecond);
}
stepList.sort(Comparator.comparingInt(TariffMultistep::getStartVal));
double minPrice = 0d;//最小阶梯金额
for (TariffMultistep step : stepList){
if (step.getStepRate() > 0){
minPrice = step.getStepRate();
break;
}
}
//循环标准阶梯
for (TariffMultistep step : stepList){
//开始天大于减免天, 加入新阶梯
if (step.getStartVal() > json.getInteger(ICondition.DERATE_DAY)){
TariffMultistep stepNew = new TariffMultistep();
BeanUtils.copyProperties(step, stepNew);
stepListNew.add(stepNew);
continue;
}
//结束天小于等于减免天, 跳过
if (step.getEndVal() <= json.getInteger(ICondition.DERATE_DAY)){
continue;
}
//剩下的是免费天在开始天与结束天之间的
TariffMultistep stepNew = new TariffMultistep();
BeanUtils.copyProperties(step, stepNew);
stepNew.setStartVal(json.getInteger(ICondition.DERATE_DAY) + 1);
if (stepNew.getStepRate() == 0d){
stepNew.setStepRate(minPrice);
}
stepListNew.add(stepNew);
}
MultiStepUtil.calcAmount(derateTariff, detail);
detail.setDerateDays(json.getInteger(ICondition.DERATE_DAY));//重置减免天
}
//减免类型(后免)
if (json.getInteger(ICondition.DERATE_TYPE) == 2){
Integer settleDays = detail.getSettleDays();
detail.setSettleDays(detail.getSettleDays() - json.getInteger(ICondition.DERATE_DAY));//后免要计算的天数
MultiStepUtil.calcAmount(tariffVO, detail);
detail.setDerateDays(detail.getDerateDays() + json.getInteger(ICondition.DERATE_DAY));//重置减免天
detail.setSettleDays(settleDays);//还原堆存天
}
detail.setCalcDays(detail.getSettleDays() - detail.getDerateDays());
detail.setDiscount(detail.getFinalMoney() / detail.getStMoney() * 100);//最终折扣
}
}

View File

@@ -0,0 +1,146 @@
package com.ag.account.feeUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.ag.entity.fee.Tariff;
import com.ag.entity.fee.TariffRitem;
import com.ag.entity.fee.face.ICondition;
import com.ag.entity.fee.face.IRuleCondition;
import com.ag.entity.fee.face.SourceProperty;
import com.ag.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import org.springframework.util.CollectionUtils;
import java.util.List;
import java.util.Map;
/**
* Created by Administrator on 2017/5/26 0026.
*/
public class RuleUtil {
/**
* 费率有效期检查有效返回true无效返回false
* @return
*/
public static boolean checkValidity(Tariff tariff, String bizTime){
if (tariff.getEffectiveDate() == null || tariff.getExpiredDate() == null){
return true;
}
//失效日期+1天
DateTime endDate = DateUtil.offsetDay(tariff.getExpiredDate(), 1);
DateTime bizDate = DateUtil.parseDate(bizTime);
return DateUtil.isIn(bizDate, tariff.getEffectiveDate(), endDate);
}
/*public static void main(String[] args) {
String bizTime = "2020-12-01 00:00:00";
TariffVO vo = new TariffVO();
vo.setEffectiveDate(TimeUtil.getTimestamp("2020-11-01"));
vo.setExpiredDate(TimeUtil.getTimestamp("2020-11-30"));
System.out.println(RuleUtil.checkValidity(vo, bizTime));
}*/
public static boolean compareRule(SourceProperty reqData, List<TariffRitem> conditionLst, Map<String, Integer> eqMap) {
if (CollectionUtils.isEmpty(conditionLst)) {
return false;
}
JSONObject property = reqData.getProperty();
//如果有扩展需要传递条件对象type否则可传递type的比较属性
for (IRuleCondition condition : conditionLst) {
//过滤金额条件
if (ICondition.RATE.equals(condition.getKeyName())){
continue;
}
//*匹配所有,不校验
if (ObjectUtil.equal(condition.getCompareVal(), "*")){
continue;
}
//非查找项,不需要进行值比较
if(eqMap.containsKey(condition.getKeyName()) && eqMap.get(condition.getKeyName()) == 1){
continue;
}
//数据源不包含费率key, 此费率条件不满足
if (!property.containsKey(condition.getKeyName())){
return false;
}
String propertyVal = property.getString(condition.getKeyName());
if (!compare(condition, propertyVal)) {
return false;
}
}
return true;
}
/**
* 通用比较方法
* @param condition
* @param typeVal
* @return
*/
private static boolean compare(IRuleCondition condition, String typeVal) {
if(StrUtil.isEmpty(typeVal)){
return false;
}
if ("=".equals(condition.getOperChar())) {
if (StrUtil.join(",",condition.getCompareVal(), ",").contains(StrUtil.join(",",typeVal, ","))) {
return true;
}
}
if ("!=".equals(condition.getOperChar())) {
if (!StrUtil.join(",",condition.getCompareVal(), ",").contains(StrUtil.join(",",typeVal, ","))) {
return true;
}
}
if ("CONTAINS".equals(condition.getOperChar())){
return compareContains(condition, typeVal);
}
if ("NO CONTAINS".equals(condition.getOperChar())){
return !compareContains(condition, typeVal);
}
if ("PREFIX".equals(condition.getOperChar())){
return comparePrefix(condition, typeVal);
}
if ("NO PREFIX".equals(condition.getOperChar())){
return !comparePrefix(condition, typeVal);
}
return false;
}
private static boolean comparePrefix(IRuleCondition condition, String typeVal) {
String condtionVal = condition.getCompareVal() + ",";
String[] arrs = condtionVal.split(",");
for (String val : arrs){
if (StrUtil.isEmpty(val)){
continue;
}
if (typeVal.indexOf(val) == 0){
return true;
}
}
return false;
}
private static boolean compareContains(IRuleCondition condition, String typeVal){
String condtionVal = condition.getCompareVal() + ",";
String[] arrs = condtionVal.split(",");
for (String val : arrs){
if (StrUtil.isEmpty(val)){
continue;
}
if (typeVal.contains(val)){
return true;
}
}
return false;
}
}

View File

@@ -0,0 +1,115 @@
package com.ag.account.feeUtil;
import cn.hutool.core.util.ObjectUtil;
import com.ag.entity.fee.ItemProperties;
import com.ag.entity.fee.TariffRitem;
import com.ag.entity.fee.face.IRuleCondition;
import com.ag.entity.fee.face.SourceProperty;
import com.ag.entity.fee.vo.TariffVO;
import com.ag.util.StrUtil;
import java.util.List;
import java.util.Map;
/**
* Created by Administrator on 2017/5/26 0026.
*/
public class TariffUtil {
/**
* 如果存在多个满足箱属性条件的费率匹配最符合规则的一个1、条件数量2、按显示顺序取优先级
*/
public static void compareNum(SourceProperty reqData, List<TariffVO> fits, Map<String, Integer> eqMap, List<ItemProperties> orderList) {
for(TariffVO tariff : fits){
//有费率有效期,直接选中退出
if (tariff.getExpiredDate() != null && tariff.getEffectiveDate() != null){
replaceTariff(tariff, reqData, eqMap, orderList);
break;
}
//首次进入
if (reqData.getCriteriaNum() == null){
replaceTariff(tariff, reqData, eqMap, orderList);
continue;
}
//当前费率的条件数量 > 存储条件数量,则用此费率替换存储费率
if(accountCriteriaNum(tariff, eqMap) > reqData.getCriteriaNum()){
replaceTariff(tariff, reqData, eqMap, orderList);
continue;
}
//当前费率的条件数量 < 存储条件数量,忽略不计
if(accountCriteriaNum(tariff, eqMap) < reqData.getCriteriaNum()){
continue;
}
/*
* 当前费率的条件数量 = 存储条件数量,进入
* 按显示顺序重新编号有key赋1无key赋0最后拼接取拼接串最大值
*/
String tariffSort = joinOrder(tariff, orderList);
if (tariffSort.compareTo(reqData.getSort()) == 1){
replaceTariff(tariff, reqData, eqMap, orderList);
}
}
}
private static void replaceTariff(TariffVO tariff, SourceProperty reqData, Map<String, Integer> eqMap, List<ItemProperties> orderList) {
/*ruleType.setTariffId(tariff.getId());
ruleType.setPrice(tariff.getRate());*/
reqData.setCriteriaNum(accountCriteriaNum(tariff, eqMap));
reqData.setSort(joinOrder(tariff, orderList));
//替换费率
reqData.setTariffVO(tariff);
}
/*private static void comparePrice(TariffVO tariff, SourceProperty ruleType, Map<String, Integer> eqMap) {
if (ruleType.getTariffVO().getRate() > tariff.getRate()){
return;
}
replaceTariff(tariff, ruleType, eqMap, orderMap);
}*/
public static void clear(SourceProperty ruleType){
ruleType.setCriteriaNum(null);
ruleType.setSort(null);
//替换费率
ruleType.setTariffVO(null);
ruleType.setPayDetail(null);
ruleType.setReceiveDetail(null);
}
//条件数量只统计查找列
private static int accountCriteriaNum(TariffVO tariff, Map<String, Integer> eqMap){
List<TariffRitem> rules = tariff.getRitemList();
int num = 0;
for (IRuleCondition rule : rules){
if(!ObjectUtil.equal(rule.getCompareVal(),"*") && ObjectUtil.equal(eqMap.get(rule.getKeyName()), 0)){
num ++;
}
}
return num;
}
private static String joinOrder(TariffVO tariff, List<ItemProperties> orderList){
List<TariffRitem> rules = tariff.getRitemList();
String order = "";
for (ItemProperties prop : orderList){
boolean found = false;
for (TariffRitem ritem : rules){
if (ObjectUtil.equal(prop.getPropertyCode(), ritem.getKeyName())){
//该要素存在于费率条件中
order = StrUtil.join(order, "1");
found = true;
break;
}
}
//该要素不存在于费率条件中
if (!found){
order = StrUtil.join(order, "0");
}
}
return order;
}
}

View File

@@ -0,0 +1,86 @@
package com.ag.account.service;
import com.ag.account.dao.AccountPointsCalcDao;
import com.ag.base.SqlUtil;
import com.ag.entity.account.vo.BizVO;
import com.ag.entity.fee.AccountPoints;
import com.ag.entity.fee.BaseChargingItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by Administrator on 2017/5/15 0015.
*/
@Service
public class AccountPointsCalcService {
@Autowired
private AccountPointsCalcDao apDao;
/**
* 通过计费点找费目编号
* @param bizVO
* @param accountPointId
*/
void getFeeItems(BizVO bizVO, String accountPointId){
AccountPoints point = new AccountPoints();
point.setTenancyId(bizVO.getTenancyId());
point.setPointCode(accountPointId);
List<AccountPoints> pointLst = apDao.findByPointId(point);
bizVO.setPointLst(pointLst);
Assert.notEmpty(pointLst, "计费事件无费目!");
String items = new SqlUtil<AccountPoints>().getAddInIds(pointLst, "itemId");
bizVO.setItemIds(items);
}
void findBaseItemList(BizVO bizVO){
List<BaseChargingItem> items = apDao.findInItemId(bizVO.getItemIds(), bizVO.getTenancyId());
Map<String, BaseChargingItem> map = new HashMap<>();
for (BaseChargingItem item : items){
map.put(item.getId(), item);
}
bizVO.setItemMap(map);
}
/**
* 获取所有计费点费目
* @param bizVO
*/
void putAllPonits(BizVO bizVO){
AccountPoints point = new AccountPoints();
point.setTenancyId(bizVO.getTenancyId());
List<AccountPoints> ponits = apDao.findAll(point);
Map<String, List<AccountPoints>> map = new HashMap<>();
for (AccountPoints apt : ponits){
if (map.containsKey(apt.getPointCode())){
map.get(apt.getPointCode()).add(apt);
}else {
List<AccountPoints> apts = new ArrayList<>();
apts.add(apt);
map.put(apt.getPointCode(), apts);
}
}
bizVO.setPointLst(ponits);
bizVO.setAllPonitsMap(map);
//bizVO.setItemList(apDao.findAll(bizVO.getTenancyId()));
}
/**
* 费目编号为空,查询计费点
* @param bizVO
* @return
*/
private List<AccountPoints> findFeeAccount(BizVO bizVO){
//final String accountPointId = "BusinessFeeAccount";
AccountPoints point = new AccountPoints();
point.setTenancyId(bizVO.getTenancyId());
point.setPointCode(bizVO.getAccountPointId());
return apDao.findByPointId(point);
}
}

View File

@@ -0,0 +1,200 @@
package com.ag.account.service;
import com.ag.account.dao.BizContractsDao;
import com.ag.base.SqlUtil;
import com.ag.entity.account.vo.BizVO;
import com.ag.entity.fee.AccountPoints;
import com.ag.entity.fee.ItemProperties;
import com.ag.entity.fee.TariffMultistep;
import com.ag.entity.fee.TariffRitem;
import com.ag.entity.fee.vo.ContractItemVO;
import com.ag.entity.fee.vo.ContractVO;
import com.ag.entity.fee.vo.TariffVO;
import com.ag.util.StrUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* 将合同对象下的所有对象组装到合同对象
* Created by Administrator on 2017/6/13 0013.
*/
@Service
public class BizContractsService {
@Autowired
private BizContractsDao bizContractsDao;
/**
* 设置默认合同
* @param bizVO
* @return
*/
private String setDefaultContract(BizVO bizVO) {
if (bizVO.getDefaultContractVo() != null){
return bizVO.getDefaultContractVo().getId();
}
//费目id集合
String ids = new SqlUtil<AccountPoints>().getAddInIds(bizVO.getPointLst(), "itemId");
bizVO.setItemIds(ids);
String defaultContractId = bizContractsDao.findDefaultContractId(bizVO);
//查找标准合同费目费率everything
bizVO.setDefaultContractVo(getContractVO(defaultContractId, bizVO));
return defaultContractId;
}
/**
* 客户合同号找合同对象
* 存在则返回,不存在查询并加入合同列表
*/
public ContractVO getContractVO(String defaultContractId, BizVO bizVO){
//货主默认合同号为空
if (StrUtil.isEmpty(defaultContractId)){
return null;
}
if ("[]".equals(defaultContractId)){
return null;
}
if (bizVO.getBizTime() == null){
bizVO.setBizTime(new Date());
}
//wb数组处理客户合同格式["6bb8cac321de49979bd0f9c97bc9d449","1ab8a85990a34d1c95773b9b664fcf49"]
if (defaultContractId.contains("[")) {
defaultContractId = defaultContractId.replace("[","").replace("]","").replace("\"","'");
}else {
defaultContractId = "'" + defaultContractId + "'";
}
ContractVO contractId = bizContractsDao.findContractId(defaultContractId, bizVO);
if (contractId == null){
return null;
}
defaultContractId = contractId.getId();
List<ContractVO> appendContractVO = bizVO.getAppendContractVO();
for (ContractVO append : appendContractVO){
if (append.getId().equals(defaultContractId)){
return append;
}
}
//查找标准合同费目费率everything
ContractVO contractVO = findContractVO(defaultContractId, bizVO);
appendContractVO.add(contractVO);
return contractVO;
}
/**
* 查找标准合同费目费率everything实现
* @param defaultContractId
* @param bizVO
* @return
*/
public ContractVO findContractVO(String defaultContractId, BizVO bizVO) {
//long sum = 0l;
//long on = System.currentTimeMillis();
//合同
ContractVO contrVO = bizContractsDao.findContractVOById(defaultContractId, bizVO);
//合同费目
List<ContractItemVO> items = bizContractsDao.findItemByContract(defaultContractId, bizVO);
//费率
List<TariffVO> tariffs = bizContractsDao.findTariffByContract(defaultContractId, bizVO);
//费率条件
List<TariffRitem> ritems = bizContractsDao.findRitemByTariff(defaultContractId, bizVO);
//阶梯费率
List<TariffMultistep> steps = bizContractsDao.findStepByTariff(defaultContractId, bizVO);
//费目属性
List<ItemProperties> properties = bizContractsDao.findPropertiesByItems(bizVO);
/*List<TariffVO> customTariffs = bizContractsDao.findCustomTariffByContract(defaultContractId, bizVO);
List<TariffRitem> customRitems = bizContractsDao.findCustomRitemByTariff(defaultContractId, bizVO);
List<TariffMultistep> customSteps = bizContractsDao.findCustomStepByTariff(defaultContractId, bizVO);*/
//计免条件
/*List<ContractItemRuleVO> rules = bizContractsDao.findRuleByContract(defaultContractId, bizVO);
List<ContractItemRuleCondition> conditions = bizContractsDao.findConditionByContract(defaultContractId, bizVO);*/
//long end = System.currentTimeMillis();
//sum = end - on;
//System.out.println("费率查询时间:"+sum);
//on = System.currentTimeMillis();
contrVO.setItemLst(items);
//完善非客户费率
mergeTariffVO(tariffs, ritems);
mergeTariffStep(tariffs, steps);
//完善客户费率
/*mergeTariffVO(customTariffs, customRitems);
mergeTariffStep(customTariffs, customSteps);*/
//计费免费规则
//mergeRuleConditionVO(rules, conditions);
//赋值驳船费率
mergeItemTariffVO(items, tariffs);
mergeItemProperties(items, properties);
//赋值驳船(客户)费率
//mergeItemTariffVO(items, customTariffs, 2);
//费目绑定计免费规则
//mergeItemRuleVO(items, rules);
//end = System.currentTimeMillis();
// sum = end - on;
//System.out.println("费率合并时间:"+sum);
//赋值合同费目名称
//mergeItemName(items, bizVO.getItemList());
return contrVO;
}
private void mergeItemProperties(List<ContractItemVO> items, List<ItemProperties> properties) {
for (ContractItemVO vo : items){
List<ItemProperties> pros = new ArrayList<>();
vo.setItemProperties(pros);
for (ItemProperties property : properties){
if (vo.getItemId().equals(property.getItemId())){
pros.add(property);
}
}
pros.sort((a, b) -> a.getDispOrder() - b.getDispOrder());
}
}
private void mergeItemTariffVO(List<ContractItemVO> items, List<TariffVO> tariffs) {
if(CollectionUtils.isEmpty(tariffs)){
return;
}
for(ContractItemVO item : items){
List<TariffVO> groupTariffs = new ArrayList<>();
item.setTariffLst(groupTariffs);
for(TariffVO tariff : tariffs){
if(tariff.getChargingId().equals(item.getItemId())){
groupTariffs.add(tariff);
}
}
}
}
private void mergeTariffVO(List<TariffVO> tarLst, List<TariffRitem> ritemLst) {
for (TariffVO vo : tarLst) {
List<TariffRitem> ritems = new ArrayList<>();
vo.setRitemList(ritems);
for (TariffRitem ritem : ritemLst) {
if (vo.getId().equals(ritem.getRuleId())) {
ritems.add(ritem);
}
}
}
}
private void mergeTariffStep(List<TariffVO> tariffs, List<TariffMultistep> stepLst) {
for (TariffVO vo : tariffs) {
List<TariffMultistep> steps = new ArrayList<>();
vo.setStepList(steps);
for (TariffMultistep step : stepLst) {
if (vo.getId().equals(step.getTariffId())) {
steps.add(step);
}
}
}
}
}

View File

@@ -0,0 +1,207 @@
package com.ag.account.service;
import cn.hutool.core.util.ObjectUtil;
import com.ag.account.detail.AccountDetail;
import com.ag.account.detail.CalcManager;
import com.ag.account.feeUtil.RuleUtil;
import com.ag.account.feeUtil.TariffUtil;
import com.ag.base.DefaultBussniessImpl;
import com.ag.entity.account.FeeDetail;
import com.ag.entity.account.vo.BizVO;
import com.ag.entity.fee.BaseChargingItem;
import com.ag.entity.fee.ItemProperties;
import com.ag.entity.fee.TariffRitem;
import com.ag.entity.fee.face.IFeeBase;
import com.ag.entity.fee.face.ReqSource;
import com.ag.entity.fee.face.SourceProperty;
import com.ag.entity.fee.vo.ContractItemVO;
import com.ag.entity.fee.vo.ContractVO;
import com.ag.entity.fee.vo.SourceAndFeeDetail;
import com.ag.entity.fee.vo.TariffVO;
import com.ag.util.StrUtil;
import com.alibaba.fastjson.JSON;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* Created by yangxh on 2019/8/1.
*/
@Controller
public class FeeController implements IFeeBase {
private Log log = LogFactory.getLog(FeeController.class);
@Autowired
private BizContractsService contractsService;
@Autowired
private AccountPointsCalcService pointService;
@Autowired
private DefaultBussniessImpl<FeeDetail> ctcDao;
/*@Autowired
private RedisTemplate redisTemplate;*/
/**
* 返回每个数据源对象生成的费用明细
* @param reqStr
* @return List<SourceAndFeeDetail>
*/
@Override
public String callbackSource(String reqStr){
log.error("**************"+reqStr);
BizVO bizVO = execute(reqStr);
/*Object clientType = redisTemplate.opsForValue().get("KVBUFF_"+ICondition.C_CLIENT_TYPE);
System.out.println(JSON.toJSONString(clientType));
List<KvBean> list = SerializeUtil.unserializeForList((byte[])clientType);
System.out.println("redis==="+JSON.toJSONString(list));*/
List<SourceAndFeeDetail> sourceAndFees = new ArrayList<>();
List<SourceProperty> sources = bizVO.getReqSource().getSourceProperties();
for (SourceProperty source : sources){
SourceAndFeeDetail sourceAndFee = new SourceAndFeeDetail();
SourceProperty target = new SourceProperty();
target.setBizId(source.getBizId());
target.setBizTime(source.getBizTime());
target.setBizType(source.getBizType());
target.setProperty(source.getProperty());
target.setSpare(source.getSpare());
target.setBackTariffs(source.getBackTariffs());
sourceAndFee.setSource(target);
sourceAndFees.add(sourceAndFee);
}
List<FeeDetail> allDetails = bizVO.getDetails();
for (SourceAndFeeDetail sourceAndFee : sourceAndFees){
List<FeeDetail> targets = new ArrayList<>();
sourceAndFee.setFeeDetails(targets);
for (FeeDetail detail : allDetails) {
if (sourceAndFee.getSource().getBizId().equals(detail.getBussinessCode())){
targets.add(detail);
}
}
}
return JSON.toJSONString(sourceAndFees);
}
@Override
public String callback(String reqStr){
log.error("source **************"+reqStr);
BizVO bizVO = execute(reqStr);
log.error("result **************");
log.error(JSON.toJSONString(bizVO.getDetails()));
return JSON.toJSONString(bizVO.getDetails());
}
@Override
@Transactional
public void call(String reqStr) {
BizVO bizVO = execute(reqStr);
ctcDao.saveAll(bizVO.getDetails());
}
private BizVO execute(String reqStr){
ReqSource reqSource = JSON.parseObject(reqStr, ReqSource.class);
BizVO bizVO = new BizVO();
bizVO.setReqSource(reqSource);
//通过计费事件编号—>所有计费费目,合同编号->所有合同费目=》该合同下满足的计费费目及所有属性
init(bizVO);
List<ContractItemVO> itemLst = bizVO.getDefaultContractVo().getItemLst();
List<SourceProperty> properties = reqSource.getSourceProperties();
//数据源
for (SourceProperty property : properties) {
log.error("数据源对象:"+ JSON.toJSONString(property)+"===============");
//费目
for (ContractItemVO item : itemLst) {
TariffUtil.clear(property);
Map<String, Integer> eqMap = item.getItemProperties().stream()
.collect(Collectors.toMap(ItemProperties::getPropertyCode, ItemProperties::getIsShowOperator));
//去除显示要素,并按顺序要素重新排序
List<ItemProperties> orderList = item.getItemProperties().stream().filter(x-> ObjectUtil.equal(0, x.getIsShowOperator()))
.sorted(Comparator.comparing(ItemProperties::getDispOrder)).collect(Collectors.toList());
List<TariffVO> tariffLst = item.getTariffLst();
if (CollectionUtils.isEmpty(tariffLst)){
log.error("合同号["+item.getContractId()+"]费目编号["+item.getItemId()+"]未找到费率");
continue;
}
List<TariffVO> fits = new ArrayList<>();
//费率
for (TariffVO tariffVO : tariffLst) {
/*if (tariffVO.getId().equals("b30f40b9222d48629ec2d3ba1216969b")
&& property.getBizId().equals("56bdf298-4925-4ff8-8f8a-56b6ca18e3e6")
){
System.out.println(JSON.toJSONString(tariffVO));
}*/
//费率有效期检查有效返回true无效返回false, 失效日期+1
if (!RuleUtil.checkValidity(tariffVO, property.getBizTime())){
continue;
}
List<TariffRitem> ritemList = tariffVO.getRitemList();
if (RuleUtil.compareRule(property, ritemList, eqMap)) {
fits.add(tariffVO);
}
}
if (!CollectionUtils.isEmpty(fits)) {
//logger.info("满足条件的费率信息:" + fits.size());
//logger.info(JSON.toJSONString(fits));
//合同费率筛选
TariffUtil.compareNum(property, fits, eqMap, orderList);
//保存合同费目
property.setContractItem(item);
//返回费率
property.getBackTariffs().add(property.getTariffVO());
Map<String, BaseChargingItem> itemMap = bizVO.getItemMap();
log.error("合同费目信息::"+itemMap.get(property.getContractItem().getItemId()).getDescription());
//log.error("费率信息::"+JSON.toJSONString(property.getTariffVO()));
log.error("费率金额::"+property.getTariffVO().getRate());
AccountDetail detail = CalcManager.getInstance(item);
if(detail != null){
detail.getFeeDetail(bizVO, property);
}
}
}
log.error("======================================end");
}
return bizVO;
}
private void init(BizVO bizVO){
ReqSource reqSource = bizVO.getReqSource();
bizVO.setTenancyId(reqSource.getTenancyId());
if (!StrUtil.isEmpty(reqSource.getAccountPointCode())){
pointService.getFeeItems(bizVO, reqSource.getAccountPointCode());
}
if (!StrUtil.isEmpty(reqSource.getItemId())) {
String itemIds = "'"+subRightString(reqSource.getItemId(), ",").replace(",", "','")+"'";
bizVO.setItemIds(itemIds);
}
if (!StrUtil.isEmpty(reqSource.getContractId())){
ContractVO contractVO = contractsService.findContractVO(reqSource.getContractId(), bizVO);
bizVO.setDefaultContractVo(contractVO);
}
//按费目编号查询基础费目
pointService.findBaseItemList(bizVO);
}
public static String subRightString(String str, String rightFlag) {
if (StrUtil.isEmpty(str)){
return "";
}
if (!str.contains(rightFlag)) {
return str;
}
return str.substring(0, str.lastIndexOf(rightFlag));
}
}

View File

@@ -0,0 +1,81 @@
package com.ag.test;
import com.ag.account.service.FeeController;
import com.ag.entity.fee.face.ICondition;
import com.ag.entity.fee.face.ReqSource;
import com.ag.entity.fee.face.SourceProperty;
import com.ag.util.TimeUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import java.util.ArrayList;
import java.util.List;
/**
* Created by yangxh on 2020/12/19.
*/
public class LocalTestByBulkStore {
private static final String bizType = "store";
private static final String itemIds = "002";
private static final String contractId = "38d0362f69824db8b9c9853e72dec930";
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring/dubbo-provider.xml");
FeeController fee = context.getBean(FeeController.class);
ReqSource reqSource = new ReqSource();
LocalTestByBulkStore.generateData(reqSource);
//LocalTestData.generateDataByStore(reqSource);
// String req = "{\"accountPointCode\":\"08\",\"contractId\":\"67e28d2715684d6e8db0eb77f86cc567\",\"operMan\":\"admin\",\"sourceProperties\":[{\"bizId\":\"A8165E60D2BF462D942DE97E3BA58911\",\"bizTime\":\"2019-10-17 15:49:49\",\"bizType\":\"08\",\"property\":{\"V_C_TYPE_DATA_FEE\":\"HC\",\"LIN_ID\":\"IRNL\",\"timeOn\":\"2019-09-19 00:00:00\",\"timeEnd\":\"2019-10-16 00:00:00\",\"derateType\":\"1\",\"I_E_ID\":\"1\",\"V_C_SIZE_DATA_FEE\":\"40\",\"derateDay\":\"10\",\"V_C_CLIENT_DATA_YYR_FEE\":\"IRNL\"},\"spare\":{}}],\"tenancyId\":\"010102\"}\n";
// String str = fee.callback(req);
String str = fee.callback(JSON.toJSONString(reqSource));
System.out.println(str);
}
/**
* 箱*天 阶梯费率计算(重箱堆存费)
* @param reqSource
*/
public static void generateData(ReqSource reqSource) {
List<SourceProperty> sources = new ArrayList<>();
String bizId01 = "8f548bf59afa4440b86636c10ba31";
SourceProperty store01 = new SourceProperty();
sources.add(store01);
store01.setBizId(bizId01);
store01.setBizTime(TimeUtil.getDateTime());
store01.setBizType(bizType);
JSONObject storeMap01 = new JSONObject();
storeMap01.put(ICondition.TIME_ON, "2019-08-01 00:00:00");
storeMap01.put(ICondition.TIME_END, "2019-08-13 00:00:00");
storeMap01.put(ICondition.weight, 800);
storeMap01.put("CARGO_CODE", "HB");
storeMap01.put("TRADE_ID", "1");
storeMap01.put("STORAGE_FLAG", "0");
storeMap01.put("COV_ID", "1");
store01.setProperty(storeMap01);
String bizId02 = "8f548bf59afa33";
SourceProperty store02 = new SourceProperty();
sources.add(store02);
store02.setBizId(bizId02);
store02.setBizTime(TimeUtil.getDateTime());
store02.setBizType(bizType);
JSONObject storeMap02 = new JSONObject();
storeMap02.put(ICondition.TIME_ON, "2019-08-02 00:00:00");
storeMap02.put(ICondition.TIME_END, "2019-08-14 00:00:00");
storeMap02.put(ICondition.weight, 600);
storeMap02.put("CARGO_CODE", "HB");
storeMap02.put("TRADE_ID", "1");
storeMap02.put("STORAGE_FLAG", "0");
storeMap02.put("COV_ID", "0");
store02.setProperty(storeMap02);
reqSource.setSourceProperties(sources);
//reqSource.setTenancyId("QHD");
reqSource.setOperMan("admin");
reqSource.setContractId(contractId);
reqSource.setItemId(itemIds);
}
}

View File

@@ -0,0 +1,85 @@
package com.ag.test;
import com.ag.account.service.FeeController;
import com.ag.entity.fee.face.ICondition;
import com.ag.entity.fee.face.ReqSource;
import com.ag.entity.fee.face.SourceProperty;
import com.ag.util.TimeUtil;
import com.alibaba.fastjson.JSONObject;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import java.util.ArrayList;
import java.util.List;
/**
* Created by yangxh on 2019/8/27.
*/
public class LocalTestByCntrStore {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:META-INF/spring/dubbo-provider.xml");
FeeController fee = context.getBean(FeeController.class);
ReqSource reqSource = new ReqSource();
LocalTestByCntrStore.generateData(reqSource);
//LocalTestData.generateDataByStore(reqSource);
String req = "{\"accountPointCode\":\"08\",\"contractId\":\"67e28d2715684d6e8db0eb77f86cc567\",\"operMan\":\"admin\",\"sourceProperties\":[{\"bizId\":\"A8165E60D2BF462D942DE97E3BA58911\",\"bizTime\":\"2019-10-17 15:49:49\",\"bizType\":\"08\",\"property\":{\"V_C_TYPE_DATA_FEE\":\"HC\",\"LIN_ID\":\"IRNL\",\"timeOn\":\"2019-09-19 00:00:00\",\"timeEnd\":\"2019-10-16 00:00:00\",\"derateType\":\"1\",\"I_E_ID\":\"1\",\"V_C_SIZE_DATA_FEE\":\"40\",\"derateDay\":\"10\",\"V_C_CLIENT_DATA_YYR_FEE\":\"IRNL\"},\"spare\":{}}],\"tenancyId\":\"010102\"}\n";
String str = fee.callback(req);
//String str = fee.callback(JSON.toJSONString(reqSource));
//System.out.println(str);
}
/**
* 箱*天 阶梯费率计算(重箱堆存费)
* @param reqSource
*/
public static void generateData(ReqSource reqSource) {
List<SourceProperty> sources = new ArrayList<>();
//箱1
String bizId = "789456rt";
SourceProperty cntr = new SourceProperty();
sources.add(cntr);
cntr.setBizId(bizId);
cntr.setBizTime(TimeUtil.getDateTime());
cntr.setBizType("08");
JSONObject cntrMap = new JSONObject();
cntrMap.put("V_C_TYPE_DATA_FEE", "HD");
cntrMap.put("V_C_SIZE_DATA_FEE", "40");
cntrMap.put("I_E_ID", "1");
cntrMap.put("V_C_CLIENT_DATA_YYR_FEE", "IRNL");
cntrMap.put(ICondition.TIME_ON, "2019-08-01 00:00:00");
cntrMap.put(ICondition.TIME_END, "2019-08-13 00:00:00");
cntrMap.put(ICondition.LIN_ID, "IRNL");
cntrMap.put(ICondition.CAR_AGE, "货代code");
cntr.setProperty(cntrMap);
//箱2
String bizId2 = "9654321gg";
SourceProperty cntr2 = new SourceProperty();
sources.add(cntr2);
cntr2.setBizId(bizId2);
cntr2.setBizTime(TimeUtil.getDateTime());
cntr2.setBizType("08");
JSONObject cntrMap2 = new JSONObject();
cntrMap2.put("V_C_TYPE_DATA_FEE", "HD");
cntrMap2.put("V_C_SIZE_DATA_FEE", "40");
cntrMap2.put("I_E_ID", "0");
cntrMap2.put("V_C_CLIENT_DATA_YYR_FEE", "IRNL");
//cntrMap2.put("EIR_APPLY_TYPE", "03");
cntrMap2.put(ICondition.TIME_ON, "2019-08-01 00:00:00");
cntrMap2.put(ICondition.TIME_END, "2019-08-20 00:00:00");
cntrMap2.put(ICondition.LIN_ID, "IRNL");
cntrMap2.put(ICondition.CAR_AGE, "货代code");
cntrMap2.put(ICondition.DERATE_TYPE, "2");
cntrMap2.put(ICondition.DERATE_DAY, "10");
cntrMap2.put(ICondition.DERATE_MONEY, "200");
cntr2.setProperty(cntrMap2);
reqSource.setSourceProperties(sources);
reqSource.setTenancyId("01");
reqSource.setOperMan("admin");
reqSource.setContractId("67e28d2715684d6e8db0eb77f86cc567");
//reqSource.setItemId("8f548bf59afa4440b86636c10ba31547");
reqSource.setAccountPointCode("08");
}
}

View File

@@ -0,0 +1,98 @@
package com.ag.test;
import com.ag.account.service.FeeController;
import com.ag.entity.fee.face.ICondition;
import com.ag.entity.fee.face.ReqSource;
import com.ag.entity.fee.face.SourceProperty;
import com.ag.util.TimeUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import java.util.ArrayList;
import java.util.List;
/**
* Created by yangxh on 2019/8/24.
*/
public class LocalTestByProxy {
private static final String bizType = "MACH";
private static final String contractId = "ccb1deff1086449d87106a6478f34ca4";
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring/dubbo-provider.xml");
FeeController fee = context.getBean(FeeController.class);
ReqSource reqSource = new ReqSource();
LocalTestByProxy.generateData(reqSource);
//String req = "{\"accountPointCode\":\"02\",\"contractId\":\"67e28d2715684d6e8db0eb77f86cc567\",\"operMan\":\"王楠\",\"sourceProperties\":[{\"bizId\":\"72372405-69ff-47a3-af0e-541e4d062427\",\"bizTime\":\"2019-08-29 10:19:44\",\"bizType\":\"02\",\"property\":{\"BILL_CALC\":\"1\",\"I_E_ID\":\"0\"},\"spare\":{}},{\"bizId\":\"72372405-69ff-47a3-af0e-541e4d062427\",\"bizTime\":\"2019-08-29 10:19:44\",\"bizType\":\"02\",\"property\":{\"MAIN_CNTR\":\"1\",\"quantity\":\"2\",\"I_E_ID\":\"0\",\"V_V_C_SIZE_DATA_FEE_FEE\":\"20\"},\"spare\":{}}],\"tenancyId\":\"01\"}";
//String str = fee.callback(req);
String str = fee.callback(JSON.toJSONString(reqSource));
//fee.call(JSON.toJSONString(reqSource));
}
/**
* 箱,票,拼箱比例费用计算(代理费)
* @param reqSource
*/
public static void generateData(ReqSource reqSource){
List<SourceProperty> sources = new ArrayList<>();
//包干航次
String mainId = "8f548bf59afa4440b86636c10ba";
SourceProperty bill = new SourceProperty();
sources.add(bill);
bill.setBizId(mainId);
bill.setBizTime(TimeUtil.getDateTime());
bill.setBizType(bizType);
JSONObject billMap = new JSONObject();
//billMap.put("TAKEOVER_PROXY_FEE", "包干代理费");
//billMap.put(ICondition.LIN_ID, "营运人code");
//billMap.put(ICondition.CAR_AGE, "货代code");
billMap.put(ICondition.weight, "1000.435");
billMap.put("TRADE_ID", "1");
bill.setProperty(billMap);
//箱1
/*String bizId = "8f548bf59afa4440b86636c10ba31547";
SourceProperty cntr = new SourceProperty();
sources.add(cntr);
cntr.setBizId(bizId);
cntr.setBizTime(TimeUtil.getDateTime());
cntr.setBizType(bizType);
JSONObject cntrMap = new JSONObject();
cntrMap.put("V_C_SIZE_DATA_FEE", "20");
cntrMap.put("E_F_IDCODE", "E");
cntrMap.put(ICondition.QUANTITY, "8");
cntrMap.put(ICondition.LIN_ID, "营运人CODE");
cntrMap.put(ICondition.CAR_AGE, "货代code");
cntr.setProperty(cntrMap);
//箱2
String bizId2 = "8f548bf59afa4440b86636c10ba31";
SourceProperty cntr2 = new SourceProperty();
sources.add(cntr2);
cntr2.setBizId(bizId2);
cntr2.setBizTime(TimeUtil.getDateTime());
cntr2.setBizType(bizType);
JSONObject cntrMap2 = new JSONObject();
cntrMap2.put("V_C_SIZE_DATA_FEE", "20");
cntrMap2.put("E_F_IDCODE", "F");
cntrMap2.put("TRANS_FLAG_FEE", "中转");
cntrMap2.put(ICondition.QUANTITY, "50");
cntrMap2.put(ICondition.LIN_ID, "营运人code");
cntrMap2.put(ICondition.CAR_AGE, "货代code");
cntr2.setProperty(cntrMap2);*/
reqSource.setSourceProperties(sources);
reqSource.setTenancyId("QHD");
reqSource.setOperMan("admin");
reqSource.setContractId(contractId);
//reqSource.setItemId("8f548bf59afa4440b86636c10ba31547");
reqSource.setAccountPointCode(bizType);
}
}

View File

@@ -0,0 +1,102 @@
package com.ag.test;
import com.ag.account.service.FeeController;
import com.ag.entity.fee.face.ICondition;
import com.ag.entity.fee.face.ReqSource;
import com.ag.entity.fee.face.SourceProperty;
import com.ag.util.TimeUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import java.util.ArrayList;
import java.util.List;
/**
* Created by yangxh on 2019/8/24.
*/
public class LocalTestByShip {
private static final String bizType = "MACH";
private static final String contractId = "ccb1deff1086449d87106a6478f34ca4";
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring/dubbo-provider.xml");
FeeController fee = context.getBean(FeeController.class);
ReqSource reqSource = new ReqSource();
LocalTestByShip.generateData(reqSource);
//String req = "{\"accountPointCode\":\"02\",\"contractId\":\"67e28d2715684d6e8db0eb77f86cc567\",\"operMan\":\"王楠\",\"sourceProperties\":[{\"bizId\":\"72372405-69ff-47a3-af0e-541e4d062427\",\"bizTime\":\"2019-08-29 10:19:44\",\"bizType\":\"02\",\"property\":{\"BILL_CALC\":\"1\",\"I_E_ID\":\"0\"},\"spare\":{}},{\"bizId\":\"72372405-69ff-47a3-af0e-541e4d062427\",\"bizTime\":\"2019-08-29 10:19:44\",\"bizType\":\"02\",\"property\":{\"MAIN_CNTR\":\"1\",\"quantity\":\"2\",\"I_E_ID\":\"0\",\"V_V_C_SIZE_DATA_FEE_FEE\":\"20\"},\"spare\":{}}],\"tenancyId\":\"01\"}";
//String str = fee.callback(req);
String str = fee.callback(JSON.toJSONString(reqSource));
System.out.println(str);
//fee.call(JSON.toJSONString(reqSource));
}
/**
* 箱,票,拼箱比例费用计算(类舱单费)
* @param reqSource
*/
public static void generateData(ReqSource reqSource){
List<SourceProperty> sources = new ArrayList<>();
//票
/*String mainId = "8f548bf59afa4440b86636c10ba";
SourceProperty bill = new SourceProperty();
sources.add(bill);
bill.setBizId(mainId);
bill.setBizTime(TimeUtil.getDateTime());
bill.setBizType(bizType);
JSONObject billMap = new JSONObject();
billMap.put("BILL_CALC", "1");
billMap.put(ICondition.LIN_ID, "营运人code");
billMap.put(ICondition.CAR_AGE, "车队code");
bill.setProperty(billMap);*/
//箱1
String bizId = "8f548bf59afa4440b86636c10ba31547";
SourceProperty cntr = new SourceProperty();
sources.add(cntr);
cntr.setBizId(bizId);
cntr.setBizTime(TimeUtil.getDateTime());
cntr.setBizType(bizType);
JSONObject cntrMap = new JSONObject();
cntrMap.put("V_C_TYPE_DATA_FEE", "FR");
cntrMap.put("V_C_SIZE_DATA_FEE", "20");
cntrMap.put("CARGO_KIND_CODE", "E");
cntrMap.put("I_E_ID", "I");
cntrMap.put("BILL_TYPE", "C");
cntrMap.put("MAIN_CNTR", "1");
cntrMap.put("TRANS_TYPE", "11");
cntrMap.put("TRADE_ID", "2");
cntrMap.put("TYPE", "2");
cntrMap.put(ICondition.LIN_ID, "营运人CODE");
cntrMap.put(ICondition.CAR_AGE, "车队code");
cntr.setProperty(cntrMap);
String json =
"{\"contractId\":\"38d0362f69824db8b9c9853e72dec930\",\"itemId\":\"001\",\"operMan\":\"admin\",\"sourceProperties\":[{\"property\":{\"C_CARGO_NAM\":\"HB\",\"TRADE_ID\":\"1\"},\"spare\":{}}]}";
//箱2
String bizId2 = "8f548bf59afa4440b86636c10ba31";
SourceProperty cntr2 = new SourceProperty();
sources.add(cntr2);
cntr2.setBizId(bizId2);
cntr2.setBizTime(TimeUtil.getDateTime());
cntr2.setBizType(bizType);
JSONObject cntrMap2 = new JSONObject();
cntrMap2.put(ICondition.weight, 800);
cntrMap2.put("CARGO_CODE", "HB");
cntrMap2.put("TRADE_ID", "2");
cntr2.setProperty(cntrMap2);
reqSource.setSourceProperties(sources);
reqSource.setTenancyId("default");
reqSource.setOperMan("admin");
reqSource.setContractId(contractId);
//reqSource.setItemId(itemIds);
reqSource.setAccountPointCode(bizType);
}
}

View File

@@ -0,0 +1,57 @@
package com.ag.test;
import com.ag.entity.fee.face.IFeeBase;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Created by yangxh on 2019/8/21.
*/
//@Service
public class MainModuleCall {
private Log log = LogFactory.getLog(MainModuleCall.class);
@Autowired
private ApplicationContext ioc;
private final String feeBeanName = "feeController";
private final String mainParams = "mainParams";
/**
* 返回费用明细list
* @return List<com.ag.entity.account.FeeDetail>
*/
public String execute(JSONObject object, HttpServletResponse response, HttpServletRequest request){
IFeeBase feeBase = (IFeeBase) ioc.getBean(feeBeanName);
String source = object.getString(mainParams);
log.error("callback source value============");
log.error(source);
String result = feeBase.callback(source);
log.error("callback result value============");
log.error(result);
return result;
}
/**
* 返回请求的数据源+费用明细list
* @return List<com.ag.entity.fee.vo.SourceAndFeeDetail>
* SourceProperty + FeeDetail
*/
public String callbackSource(JSONObject object, HttpServletResponse response, HttpServletRequest request){
IFeeBase feeBase = (IFeeBase) ioc.getBean(feeBeanName);
String source = object.getString(mainParams);
log.error("callbackSource source value============");
log.error(source);
String result = feeBase.callbackSource(source);
log.error("callbackSource result value============");
log.error(result);
return result;
}
}

View File

@@ -0,0 +1,15 @@
jdbc.driverClassName=com.mysql.jdbc.Driver
########\u6B63\u5F0F\u73AF\u5883
#main.url=jdbc:mysql://122.5.19.222:3909/ag_devmysql?autoReconnect=true&serverTimezone=GMT%2B8&useSSL=false
#main.username=root
#main.password=agmysqlroot
main.url=jdbc:mysql://192.168.1.188:3306/ag_devmysql?autoReconnect=true&serverTimezone=GMT%2B8&useSSL=false
main.username=root
main.password=agmysqlroot
########\u516C\u53F8\u5916\u7F51
#main.url=jdbc:oracle:thin:@122.5.19.222:61522:orcl
#main.username=AG_QHD_IMTOS
#main.password=AGSOFT

View File

@@ -0,0 +1,24 @@
log4j.rootLogger=info, Console, feeInfo, feeError
#Console
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=%d [%t] %-5p [%c] - %m%n
log4j.appender.feeInfo=org.apache.log4j.RollingFileAppender
log4j.appender.feeInfo.File=log/feeInfo.log
#log4j.appender.feeInfo.DatePattern = '_'yyyy-MM-dd'.log'
log4j.appender.feeInfo.MaxFileSize=5MB
log4j.appender.feeInfo.Append=true
log4j.appender.feeInfo.Threshold=info
log4j.appender.feeInfo.layout=org.apache.log4j.PatternLayout
log4j.appender.feeInfo.layout.ConversionPattern=[%p][%d{yyyy-MM-dd HH\:mm\:ss}][%c]%m%n
log4j.appender.feeError=org.apache.log4j.DailyRollingFileAppender
log4j.appender.feeError.File=log/feeError.log
log4j.appender.feeError.DatePattern = '_'yyyy-MM-dd'.log'
#log4j.appender.Fp.MaxFileSize=10MB
log4j.appender.feeError.Append=true
log4j.appender.feeError.Threshold=error
log4j.appender.feeError.layout=org.apache.log4j.PatternLayout
log4j.appender.feeError.layout.ConversionPattern=[%p][%d{yyyy-MM-dd HH\:mm\:ss}][%c]%m%n

View File

@@ -0,0 +1,13 @@
#<23><><EFBFBD>ʵ<EFBFBD>ַ
redis.host=127.0.0.1
#<23><><EFBFBD>ʶ˿<CAB6>
redis.port=6379
<><EFBFBD><E2A3AC><EFBFBD>û<EFBFBD><C3BB>password<72><64><EFBFBD>˴<EFBFBD><CBB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>
redis.pass=
redis.dbIndex=0
redis.maxIdle=300
redis.maxActive=600
redis.maxWait=10000
redis.testOnBorrow=true
redis.testWhileIdle=true

View File

@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<!--jar读外部文件正式环境
<context:property-placeholder location="file:${user.dir}/config/datasource.properties" />-->
<!--源码读内部文件(本地使用)-->
<context:property-placeholder location="classpath:datasource.properties" />
<!--dubbo 服务提供者应用名称 -->
<!-- 子容器扫描指定的包路径尽量与父容器不重复否则会将父容器中已存在的bean包含进来如果出现重名bean会导致子容器加载失败 -->
<!--<context:component-scan base-package="com.ag.account,com.ag.test"/>-->
<!--以下注释为计费独立测试 -->
<context:component-scan base-package="com.ag"/>
<bean id="dataSource" class="com.zaxxer.hikari.HikariDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="jdbcUrl" value="${main.url}"/>
<property name="username" value="${main.username}"/>
<property name="password" value="${main.password}"/>
<!-- 等待连接池分配连接的最大时长毫秒超过这个时长还没可用的连接则发生SQLException 缺省:30秒
<property name="connectionTimeout" value="30" />-->
<!-- 一个连接idle状态的最大时长毫秒超时则被释放retired缺省:10分钟 -->
<property name="idleTimeout" value="10"/>
<!-- 一个连接的生命时长毫秒超时而且没被使用则被释放retired缺省:30分钟建议设置比数据库超时时长少30秒参考MySQL wait_timeout参数show variables like '%timeout%';
<property name="maxLifetime" value="${maxLifetime}" /> -->
<!-- 连接池中允许的最大连接数。缺省值10推荐的公式((core_count * 2) + effective_spindle_count) -->
<property name="maximumPoolSize" value="5"/>
<property name="dataSourceProperties">
<props>
<prop key="remarksReporting">true</prop>
</props>
</property>
</bean>
<bean id="jdbcTemplateBusiness" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"/>
</bean>
<!--<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<tx:annotation-driven proxy-target-class="true"/>-->
<!--<import resource="classpath*:/spring-redis.xml" />-->
</beans>