修改车辆结算金额 计算
This commit is contained in:
parent
3fd01866be
commit
7a488e4a10
|
|
@ -90,7 +90,6 @@ public class CarBalanceController {
|
|||
@DecryptAndVerify(decryptedClass = CarPlanOutVoDetailsVo.class)
|
||||
public ServerResponse<List<CarPlanOutVoDetailsVo>> getPayCarDetails(EncryptedReq<CarPlanOutVoDetailsVo> dto) {
|
||||
List<CarPlanOutVoDetailsVo> list = service.getPayCarDetails(dto.getData());
|
||||
;
|
||||
return ServerResponse.createSuccess(list);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ public class CarPlanAuditController {
|
|||
CarNeedPlanExportVo copy = new CarNeedPlanExportVo();
|
||||
BeanUtils.copyProperties(vo, copy);
|
||||
copy.setSubTime(vo.getCreateTime());
|
||||
vo.setXh(num[0]);
|
||||
copy.setXh(num[0]);
|
||||
num[0]++;
|
||||
exportVos.add(copy);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.bonus.gzcar.business.backstage.entity;
|
|||
|
||||
import com.bonus.gzcar.business.system.entity.ParentVo;
|
||||
import lombok.Data;
|
||||
import org.apache.poi.hpsf.Decimal;
|
||||
|
||||
import java.lang.ref.PhantomReference;
|
||||
|
||||
|
|
@ -77,4 +78,10 @@ public class CarBalancePlanVo extends ParentVo {
|
|||
|
||||
private String auditType;
|
||||
|
||||
private String contractId;
|
||||
/**
|
||||
* 重新计算金额
|
||||
*/
|
||||
private Decimal newMoney;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,6 +66,14 @@ public class CarSltApplyDetailsVo {
|
|||
* 实际天数
|
||||
*/
|
||||
private int exeDay;
|
||||
/**
|
||||
* 公里数
|
||||
*/
|
||||
private String gls;
|
||||
/**
|
||||
* 天数
|
||||
*/
|
||||
private int useDay;
|
||||
/**
|
||||
* 实际公里数
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -812,7 +812,7 @@ public class CarBalanceServiceImpl implements CarBalanceService {
|
|||
return BigDecimal.ZERO; // 或者 return null,看业务
|
||||
}
|
||||
try {
|
||||
return new BigDecimal(value.trim()).setScale(2, RoundingMode.HALF_UP);
|
||||
return new BigDecimal(value.trim()).setScale(3, RoundingMode.HALF_UP);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new IllegalArgumentException("非法数字格式:" + value, e);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,13 @@
|
|||
package com.bonus.gzcar.business.config;
|
||||
|
||||
import com.bonus.gzcar.business.backstage.entity.CarNeedPlanVo;
|
||||
import com.bonus.gzcar.business.backstage.entity.*;
|
||||
import com.bonus.gzcar.business.backstage.mapper.CarBalanceMapper;
|
||||
import com.bonus.gzcar.business.backstage.mapper.DispatchCarMapper;
|
||||
import com.bonus.gzcar.business.backstage.mapper.SupDispatchCarMapper;
|
||||
|
||||
import com.bonus.gzcar.business.utils.ListHelpUtil;
|
||||
import com.bonus.gzcar.manager.common.util.StringHelper;
|
||||
import com.bonus.gzcar.manager.webResult.StringUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
|
|
@ -11,7 +15,11 @@ import org.springframework.stereotype.Component;
|
|||
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 数据矫正
|
||||
|
|
@ -24,6 +32,12 @@ public class DataConfigScheduleConfig {
|
|||
@Autowired
|
||||
private SupDispatchCarMapper mapper;
|
||||
|
||||
@Autowired
|
||||
private CarBalanceMapper carBalanceMapper;
|
||||
|
||||
@Autowired
|
||||
private SupDispatchCarMapper supDispatchCarMapper;
|
||||
|
||||
|
||||
|
||||
@Autowired
|
||||
|
|
@ -49,4 +63,220 @@ public class DataConfigScheduleConfig {
|
|||
log.error(e.getMessage(),e);
|
||||
}
|
||||
}
|
||||
|
||||
@Scheduled(cron = "0 0 */6 * * ?")
|
||||
public void updateMoney(){
|
||||
try{
|
||||
List<CarPlanOutVo> list= mapper.getOutPlanList();
|
||||
//单个数据金额
|
||||
|
||||
for (CarPlanOutVo listVo : list) {
|
||||
List<CarSltApplyDetailsVo> detailsList=mapper.getOutDetailsList(listVo);
|
||||
getContractMoney(detailsList,listVo.getPlanType(),listVo);
|
||||
mapper.updateMoney(listVo);
|
||||
}
|
||||
}catch(Exception e){
|
||||
log.error(e.getMessage(),e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 计算金额
|
||||
* @param list
|
||||
* @param planType
|
||||
* @param outVo
|
||||
*/
|
||||
private void getContractMoney(List<CarSltApplyDetailsVo> list, int planType, CarPlanOutVo outVo) {
|
||||
BigDecimal allMoney = new BigDecimal(0);
|
||||
for (CarSltApplyDetailsVo vo : list) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
BigDecimal cost = new BigDecimal(0);
|
||||
vo.setType(planType+"");
|
||||
//合同id
|
||||
if (StringHelper.isEmpty(vo.getContractId())) {
|
||||
vo.setContractId(outVo.getContractId());
|
||||
}
|
||||
if (StringHelper.isEmpty(vo.getSupId())) {
|
||||
vo.setSupId(outVo.getSupId());
|
||||
}
|
||||
//车辆
|
||||
if (planType == 1) {
|
||||
//实际公里数
|
||||
String gls = vo.getGls();
|
||||
String tonType;
|
||||
// 1. 先获取值并做 null 防护,避免 NPE
|
||||
BigDecimal tonValue = Optional.ofNullable(vo.getTon())
|
||||
.map(BigDecimal::new)
|
||||
.orElse(BigDecimal.ZERO);
|
||||
// 2. BigDecimal 必须用 compareTo 比较,不能直接用 < > ==
|
||||
if (tonValue.compareTo(new BigDecimal("2")) < 0) { // tonValue < 2(包含 null/0/1 等)
|
||||
tonType = "1";
|
||||
} else if (tonValue.compareTo(new BigDecimal("5")) < 0) { // 2 ≤ tonValue < 5
|
||||
tonType = "2";
|
||||
} else {
|
||||
tonType = "3";
|
||||
}
|
||||
log.info("车辆派车计算 - 公里数:{}, 吨位:{}, 吨位类型:{}, 合同ID:{}, 供应商ID:{}",
|
||||
gls, vo.getTon(), tonType, vo.getContractId(), vo.getSupId());
|
||||
//获取单公里价格
|
||||
PriceVo priceVo = getMoney(vo.getContractId(), null, vo.getSupId(), gls, tonType);
|
||||
if(priceVo==null){
|
||||
throw new RuntimeException("公里数不在范围内");
|
||||
}
|
||||
sb.append("依据:").append(priceVo.getGlsStart()).append("-").append(priceVo.getGlsEnd());
|
||||
sb.append("公里:").append(priceVo.getPrice()).append("元");
|
||||
vo.setRemark(sb.toString());
|
||||
vo.setPriceId(priceVo.getId());
|
||||
vo.setGlsPrice(toBigDecimal(priceVo.getPrice()));
|
||||
BigDecimal ton = new BigDecimal(vo.getTon());
|
||||
BigDecimal nowGls = new BigDecimal(gls);
|
||||
BigDecimal price = new BigDecimal(priceVo.getPrice());
|
||||
// 公里*每公里*吨位
|
||||
BigDecimal glsMoney = nowGls.multiply(price).multiply(ton);
|
||||
allMoney = allMoney.add(glsMoney);
|
||||
vo.setCost(glsMoney.toString());
|
||||
vo.setGlsMoney(glsMoney);
|
||||
|
||||
} else {
|
||||
//实际天数
|
||||
int day = vo.getUseDay();
|
||||
String inMoneyData=vo.getInMoney();
|
||||
//入场费用
|
||||
if(StringUtils.isEmpty(inMoneyData)){
|
||||
inMoneyData="0";
|
||||
}
|
||||
BigDecimal inMoney = new BigDecimal(inMoneyData);
|
||||
int isOutSet =1;
|
||||
|
||||
log.info("吊车派车计算 - 计划天数:{}, 是否收取进出场费:{}, 合同ID:{}, 车型ID:{}, 供应商ID:{}",
|
||||
day, isOutSet, vo.getContractId(), vo.getModelId(), vo.getSupId());
|
||||
BigDecimal days = new BigDecimal(day);
|
||||
BigDecimal dcMoney = new BigDecimal("0");
|
||||
BigDecimal month = new BigDecimal("30");
|
||||
PriceVo priceVo = getMoney(vo.getContractId(), vo.getModelId(), vo.getSupId(), null, null);
|
||||
if(priceVo==null){
|
||||
throw new RuntimeException("公里数不在范围内");
|
||||
}
|
||||
sb.append("依据:").append(priceVo.getName()).append("-").append(priceVo.getModel());
|
||||
vo.setPriceId(priceVo.getId());
|
||||
vo.setGlsPrice(toBigDecimal(priceVo.getPrice()));
|
||||
int dayToMonth = priceVo.getDayToMonth();
|
||||
if (day >= dayToMonth) {
|
||||
sb.append("、作业天数>=").append(dayToMonth);
|
||||
vo.setDcUnit("元/月/台");
|
||||
vo.setIsDayOrMonth("2");
|
||||
BigDecimal monthPrice = new BigDecimal(priceVo.getMonthPrice());
|
||||
if (day > 60) {
|
||||
vo.setDcPrice(monthPrice.divide(month, RoundingMode.CEILING).toString());
|
||||
dcMoney = monthPrice.divide(month, RoundingMode.CEILING).multiply(days);
|
||||
vo.setDcMoney(dcMoney.toString());
|
||||
allMoney = allMoney.add(dcMoney);
|
||||
cost = cost.add(dcMoney);
|
||||
} else {
|
||||
if(day>30){
|
||||
BigDecimal dayMoney=monthPrice.divide(month, RoundingMode.CEILING);
|
||||
//超过三十天的 但是比60天少的
|
||||
sb.append("、超过三十天的单价:(").append(dayMoney).append("元/天/台)");
|
||||
int lastDay=day-30;
|
||||
BigDecimal lastDays = new BigDecimal(lastDay);
|
||||
//剩余的金额
|
||||
BigDecimal daysMoney= monthPrice.divide(month, RoundingMode.CEILING).multiply(lastDays);
|
||||
vo.setDcPrice(priceVo.getMonthPrice());
|
||||
vo.setDcMoney(priceVo.getMonthPrice());
|
||||
allMoney = allMoney.add(monthPrice);
|
||||
allMoney =allMoney.add(daysMoney);
|
||||
//分别蒋金额计算
|
||||
cost=cost.add(monthPrice);
|
||||
cost= cost.add(daysMoney);
|
||||
}else{
|
||||
vo.setDcPrice(priceVo.getMonthPrice());
|
||||
vo.setDcMoney(priceVo.getMonthPrice());
|
||||
allMoney = allMoney.add(monthPrice);
|
||||
cost = cost.add(monthPrice);
|
||||
|
||||
}
|
||||
}
|
||||
//入场费用添加
|
||||
cost=cost.add(inMoney);
|
||||
allMoney = allMoney.add(inMoney);
|
||||
vo.setCost(cost.toString());
|
||||
} else {
|
||||
sb.append("、作业天数<").append(dayToMonth);
|
||||
vo.setIsDayOrMonth("1");
|
||||
vo.setDcPrice(priceVo.getDayPrice());
|
||||
vo.setDcUnit("元/天/台");
|
||||
BigDecimal dayPrice = new BigDecimal(priceVo.getDayPrice());
|
||||
dcMoney = dayPrice.multiply(days);
|
||||
vo.setDcMoney(dcMoney.toString());
|
||||
allMoney = allMoney.add(dcMoney);
|
||||
cost = cost.add(dcMoney);
|
||||
cost=cost.add(inMoney);
|
||||
allMoney = allMoney.add(inMoney);
|
||||
vo.setCost(cost.toString());
|
||||
}
|
||||
if(!"0".equals(inMoneyData)){
|
||||
sb.append("@");
|
||||
sb.append(priceVo.getName()).append("-").append(priceVo.getModel() + "收取进出场费用");
|
||||
sb.append("、入场费用(").append(inMoneyData).append(")");
|
||||
}
|
||||
vo.setDayPrice(priceVo.getDayPrice());
|
||||
vo.setMonthPrice(priceVo.getMonthPrice());
|
||||
vo.setRemark(sb.toString());
|
||||
}
|
||||
mapper.updatePlanOutDetails(vo);
|
||||
}
|
||||
allMoney = allMoney.setScale(3, BigDecimal.ROUND_HALF_UP);
|
||||
outVo.setMoney(allMoney.toString());
|
||||
}
|
||||
public static BigDecimal toBigDecimal(String value) {
|
||||
if (value == null || value.trim().isEmpty()) {
|
||||
return BigDecimal.ZERO; // 或者 return null,看业务
|
||||
}
|
||||
try {
|
||||
return new BigDecimal(value.trim()).setScale(3, RoundingMode.HALF_UP);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new IllegalArgumentException("非法数字格式:" + value, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算 车辆 公里数价格
|
||||
*
|
||||
* @param gls
|
||||
* @return
|
||||
*/
|
||||
private PriceVo getMoney(String contractId, String modelId, String supId, String gls, String ton) {
|
||||
List<PriceVo> list = supDispatchCarMapper.getContractPriceList(contractId, modelId, supId, ton);
|
||||
if(ListHelpUtil.isEmpty(list)){
|
||||
list = supDispatchCarMapper.getContractPriceList(contractId, modelId, supId, null);
|
||||
}
|
||||
//车辆
|
||||
if (StringHelper.isEmpty(modelId)) {
|
||||
BigDecimal nowGls = new BigDecimal(gls);
|
||||
for (PriceVo priceVo : list) {
|
||||
if(isNumberByRegex(priceVo.getGlsEnd()) && isNumberByRegex(priceVo.getGlsStart())){
|
||||
BigDecimal glsEnd = new BigDecimal(priceVo.getGlsEnd());
|
||||
BigDecimal glsStart = new BigDecimal(priceVo.getGlsStart());
|
||||
if (nowGls.compareTo(glsEnd) <= 0 && nowGls.compareTo(glsStart) >= 0) {
|
||||
return priceVo;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return null;
|
||||
} else {
|
||||
return list.get(0);
|
||||
}
|
||||
}
|
||||
public static boolean isNumberByRegex(String str) {
|
||||
// 先判空/空白串,避免正则匹配空值报错
|
||||
if (str == null || str.trim().isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
// 正则表达式:匹配正负整数、合法小数(小数点后必须有数字)
|
||||
String regex = "^[-+]?[0-9]+(\\.[0-9]+)?$";
|
||||
return str.trim().matches(regex);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue