This commit is contained in:
linfso 2024-04-29 17:40:33 +08:00
parent 7c81d668d1
commit 3d77fce137
8 changed files with 196 additions and 49 deletions

View File

@ -124,6 +124,7 @@ public class EmisCustomerAddressController extends BaseController
@PostMapping @PostMapping
public AjaxResult add(@RequestBody EmisCustomerAddress emisCustomerAddress) public AjaxResult add(@RequestBody EmisCustomerAddress emisCustomerAddress)
{ {
return toAjax(emisCustomerAddressService.insertEmisCustomerAddress(emisCustomerAddress)); return toAjax(emisCustomerAddressService.insertEmisCustomerAddress(emisCustomerAddress));
} }

View File

@ -11,24 +11,11 @@
package com.xdadan.erp.web.emis; package com.xdadan.erp.web.emis;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid; import javax.validation.Valid;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.lang.Singleton;
import cn.hutool.core.lang.Snowflake;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.xdadan.erp.common.annotation.filter.jackson.JacksonFilter; import com.xdadan.erp.emis.domain.exception.CalcException;
import com.xdadan.erp.common.core.domain.entity.SysUser;
import com.xdadan.erp.common.utils.DBUtil;
import com.xdadan.erp.emis.domain.EmisWaybillAttachment;
import com.xdadan.erp.emis.domain.EmisWaybillCargo;
import com.xdadan.erp.emis.domain.EmisWaybillFeeitem;
import com.xdadan.erp.emis.domain.exception.CalcFeeException;
import com.xdadan.erp.emis.domain.vo.*; import com.xdadan.erp.emis.domain.vo.*;
import com.xdadan.erp.emis.service.*; import com.xdadan.erp.emis.service.*;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -41,7 +28,6 @@ import com.xdadan.erp.common.core.controller.BaseController;
import com.xdadan.erp.common.core.domain.AjaxResult; import com.xdadan.erp.common.core.domain.AjaxResult;
import com.xdadan.erp.common.core.page.TableDataInfo; import com.xdadan.erp.common.core.page.TableDataInfo;
import com.xdadan.erp.common.enums.BusinessType; import com.xdadan.erp.common.enums.BusinessType;
import com.xdadan.erp.common.utils.poi.ExcelUtil;
import com.xdadan.erp.emis.domain.EmisWaybill; import com.xdadan.erp.emis.domain.EmisWaybill;
@ -131,13 +117,18 @@ public class EmisWaybillController extends BaseController
return AjaxResult.success("计算成功", jObjFee); return AjaxResult.success("计算成功", jObjFee);
} }
catch (CalcFeeException ex){ catch(CalcException ex){
ex.printStackTrace(); ex.printStackTrace();
// (E3001)参数不完整 // (E3001)参数不完整
return AjaxResult.error("("+ex.getErrorCode()+")"+ex.getMessage()); return AjaxResult.error("("+ex.getErrorCode()+")"+ex.getMessage());
} }
catch (Exception ex){ catch (Exception ex){
ex.printStackTrace(); ex.printStackTrace();
// 返回子定义异常
if(ex instanceof CalcException ){
return AjaxResult.error("("+((CalcException)ex).getErrorCode()+")"+ex.getMessage());
}
return AjaxResult.error("服务器异常,联系客服"); return AjaxResult.error("服务器异常,联系客服");
} }
} }
@ -153,12 +144,20 @@ public class EmisWaybillController extends BaseController
JSONObject jObjRst = new JSONObject(); JSONObject jObjRst = new JSONObject();
jObjRst.put("settlementWeight", emisWaybillSave.getSettlementWeight()); jObjRst.put("settlementWeight", emisWaybillSave.getSettlementWeight());
jObjRst.put("volumeWeight", emisWaybillSave.getVolumeWeight());
return AjaxResult.success("计算成功", jObjRst); return AjaxResult.success("计算成功", jObjRst);
}catch (Exception ex){
ex.printStackTrace();
return AjaxResult.error(ex.getMessage());
} }
catch (Exception ex){
ex.printStackTrace();
// 返回子定义异常
if(ex instanceof CalcException ){
return AjaxResult.error("("+((CalcException)ex).getErrorCode()+")"+ex.getMessage());
}
return AjaxResult.error("服务器异常,联系客服");
}
} }

View File

@ -1,10 +1,10 @@
package com.xdadan.erp.emis.domain.exception; package com.xdadan.erp.emis.domain.exception;
public class CalcFeeException extends Exception { public class CalcException extends Exception {
private String errorCode; private String errorCode;
public CalcFeeException(String errorCode,String message) { public CalcException(String errorCode, String message) {
super(message); super(message);
this.errorCode = errorCode; this.errorCode = errorCode;
} }

View File

@ -14,6 +14,7 @@ package com.xdadan.erp.emis.service;
import cn.hutool.core.lang.Snowflake; import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xdadan.erp.common.core.domain.entity.SysUser;
import com.xdadan.erp.common.utils.DateUtils; import com.xdadan.erp.common.utils.DateUtils;
import com.xdadan.erp.common.utils.SecurityUtils; import com.xdadan.erp.common.utils.SecurityUtils;
import com.xdadan.erp.emis.domain.*; import com.xdadan.erp.emis.domain.*;
@ -67,10 +68,31 @@ public class EmisBaseService {
@Autowired @Autowired
private EmisQuotePriceMapper emisQuotePriceMapper; private EmisQuotePriceMapper emisQuotePriceMapper;
@Autowired
private EmisQuoteExpressionMapper emisQuoteExpressionMapper;
@Autowired
private EmisCustomerUserMapper emisCustomerUserMapper;
/**
* 获取当前登录用户
* @return
*/
public SysUser getCurrentUser(){
return SecurityUtils.getLoginUser().getUser();
}
/**
* 根据添加的地址增加客户
* @param emisCustomerAddress
* @return
*/
public EmisCustomerUser createCustomerUserByAddress(EmisCustomerAddress emisCustomerAddress){
return null;
}
/** /**
* 获取线路 * 获取线路
* @param code * @param code

View File

@ -11,8 +11,7 @@ package com.xdadan.erp.emis.service;
import java.util.List; import java.util.List;
import com.xdadan.erp.emis.domain.EmisWaybill; import com.xdadan.erp.emis.domain.EmisWaybill;
import com.xdadan.erp.emis.domain.EmisWaybillFeeitem; import com.xdadan.erp.emis.domain.exception.CalcException;
import com.xdadan.erp.emis.domain.exception.CalcFeeException;
import com.xdadan.erp.emis.domain.vo.WaybillOrder; import com.xdadan.erp.emis.domain.vo.WaybillOrder;
/** /**
@ -106,11 +105,11 @@ public interface IEmisWaybillService
//计算运单费用 //计算运单费用
public void calcWaybillFee(EmisWaybill emisWaybill) throws CalcFeeException; public void calcWaybillFee(EmisWaybill emisWaybill) throws CalcException;
// 计算结算重量 // 计算结算重量
public void calcSettledWeight(EmisWaybill emisWaybill) throws Exception; public void calcSettledWeight(EmisWaybill emisWaybill) throws CalcException;
} }

View File

@ -13,6 +13,7 @@ package com.xdadan.erp.emis.service.impl;
import java.util.List; import java.util.List;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.xdadan.erp.emis.service.EmisBaseService;
import org.apache.ibatis.annotations.Update; import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -27,7 +28,7 @@ import com.xdadan.erp.emis.service.IEmisCustomerAddressService;
* @date 2024-03-01 04:47:51 * @date 2024-03-01 04:47:51
*/ */
@Service @Service
public class EmisCustomerAddressServiceImpl implements IEmisCustomerAddressService public class EmisCustomerAddressServiceImpl extends EmisBaseService implements IEmisCustomerAddressService
{ {
@Autowired @Autowired
private EmisCustomerAddressMapper emisCustomerAddressMapper; private EmisCustomerAddressMapper emisCustomerAddressMapper;
@ -65,6 +66,14 @@ public class EmisCustomerAddressServiceImpl implements IEmisCustomerAddressServi
@Override @Override
public int insertEmisCustomerAddress(EmisCustomerAddress emisCustomerAddress) public int insertEmisCustomerAddress(EmisCustomerAddress emisCustomerAddress)
{ {
// 新增地址
emisCustomerAddress.preInsert();
emisCustomerAddress.setUseSiteCode(getCurrentUser().getOwnerSiteCode());
emisCustomerAddress.setUseSite(getCurrentUser().getOwnerSiteName());
// 创建用户
return emisCustomerAddressMapper.insertEmisCustomerAddress(emisCustomerAddress); return emisCustomerAddressMapper.insertEmisCustomerAddress(emisCustomerAddress);
} }
@ -77,6 +86,10 @@ public class EmisCustomerAddressServiceImpl implements IEmisCustomerAddressServi
@Override @Override
public int updateEmisCustomerAddress(EmisCustomerAddress emisCustomerAddress) public int updateEmisCustomerAddress(EmisCustomerAddress emisCustomerAddress)
{ {
emisCustomerAddress.preUpdate();
emisCustomerAddress.setUseSiteCode(getCurrentUser().getOwnerSiteCode());
emisCustomerAddress.setUseSite(getCurrentUser().getOwnerSiteName());
return emisCustomerAddressMapper.updateEmisCustomerAddress(emisCustomerAddress); return emisCustomerAddressMapper.updateEmisCustomerAddress(emisCustomerAddress);
} }

View File

@ -15,20 +15,15 @@ import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.lang.Singleton;
import cn.hutool.core.lang.Snowflake; import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.googlecode.aviator.AviatorEvaluator; import com.googlecode.aviator.AviatorEvaluator;
import com.xdadan.erp.common.utils.DBUtil;
import com.xdadan.erp.common.utils.DateUtils; import com.xdadan.erp.common.utils.DateUtils;
import com.xdadan.erp.common.utils.SecurityUtils; import com.xdadan.erp.common.utils.SecurityUtils;
import com.xdadan.erp.emis.domain.*; import com.xdadan.erp.emis.domain.*;
import com.xdadan.erp.emis.domain.exception.CalcFeeException; import com.xdadan.erp.emis.domain.exception.CalcException;
import com.xdadan.erp.emis.domain.vo.*; import com.xdadan.erp.emis.domain.vo.*;
import com.xdadan.erp.emis.mapper.EmisTransLineMapper; import com.xdadan.erp.emis.mapper.EmisTransLineMapper;
import com.xdadan.erp.emis.service.*; import com.xdadan.erp.emis.service.*;
@ -41,6 +36,8 @@ import com.xdadan.erp.emis.mapper.EmisWaybillMapper;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import static org.apache.commons.lang3.StringUtils.*;
/** /**
* 运单列表Service业务层处理 * 运单列表Service业务层处理
* *
@ -219,13 +216,13 @@ public class EmisWaybillServiceImpl extends EmisBaseService implements IEmisWayb
boolean isNew = true; boolean isNew = true;
EmisWaybill emisWaybillOld = null; EmisWaybill emisWaybillOld = null;
if( !StringUtils.isEmpty(emisWaybillSave.getBillCode()) ){ if( !isEmpty(emisWaybillSave.getBillCode()) ){
emisWaybillOld = this.selectEmisWaybillByBillCode(emisWaybillSave.getBillCode()); emisWaybillOld = this.selectEmisWaybillByBillCode(emisWaybillSave.getBillCode());
if(emisWaybillOld!=null){ if(emisWaybillOld!=null){
isNew=false; isNew=false;
} }
}else{ }else{
if( !StringUtils.isEmpty(emisWaybillSave.getOrderSn()) ){ if( !isEmpty(emisWaybillSave.getOrderSn()) ){
emisWaybillOld = this.selectEmisWaybillByOrderSn(emisWaybillSave.getOrderSn()); emisWaybillOld = this.selectEmisWaybillByOrderSn(emisWaybillSave.getOrderSn());
if(emisWaybillOld!=null){ if(emisWaybillOld!=null){
isNew=false; isNew=false;
@ -291,13 +288,13 @@ public class EmisWaybillServiceImpl extends EmisBaseService implements IEmisWayb
// 子单号拼接 // 子单号拼接
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for(int i=0;i<emisWaybillSave.getParcelQty().intValue();i++){ for(int i=0;i<emisWaybillSave.getParcelQty().intValue();i++){
sb.append(emisWaybillSave.getBillCode()+StringUtils.leftPad(String.valueOf(i),4,"0")+","); sb.append(emisWaybillSave.getBillCode()+ leftPad(String.valueOf(i),4,"0")+",");
} }
emisWaybillSave.setBillCodeSub(sb.toString()); emisWaybillSave.setBillCodeSub(sb.toString());
} }
// 物品名称 // 物品名称
if(StringUtils.isEmpty(emisWaybillSave.getGoodsInfo())){ if(isEmpty(emisWaybillSave.getGoodsInfo())){
if(!CollectionUtils.isEmpty(emisWaybillSave.getCargoList()) ){ if(!CollectionUtils.isEmpty(emisWaybillSave.getCargoList()) ){
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for(EmisWaybillCargo cargo:emisWaybillSave.getCargoList()){ for(EmisWaybillCargo cargo:emisWaybillSave.getCargoList()){
@ -355,19 +352,19 @@ public class EmisWaybillServiceImpl extends EmisBaseService implements IEmisWayb
* @return * @return
*/ */
@Override @Override
public void calcWaybillFee(EmisWaybill emisWaybill) throws CalcFeeException { public void calcWaybillFee(EmisWaybill emisWaybill) throws CalcException {
/** /**
* 计算逻辑,获取表达式进行计算 * 计算逻辑,获取表达式进行计算
*/ */
if(StringUtils.isAnyEmpty(emisWaybill.getProductType(), if(isAnyEmpty(emisWaybill.getProductType(),
emisWaybill.getSendSiteCode(), emisWaybill.getSendSiteCode(),
emisWaybill.getDispatchUnderlingSiteCode(), emisWaybill.getDispatchUnderlingSiteCode(),
emisWaybill.getCalcFeeType() emisWaybill.getCalcFeeType()
) )
){ ){
throw new CalcFeeException("E3001","参数不完整"); throw new CalcException("E3001","参数不完整");
} }
List<EmisQuotePrice> emisQuotePriceList=getValidQuotePriceList(emisWaybill.getProductType(), List<EmisQuotePrice> emisQuotePriceList=getValidQuotePriceList(emisWaybill.getProductType(),
@ -376,7 +373,7 @@ public class EmisWaybillServiceImpl extends EmisBaseService implements IEmisWayb
if(CollectionUtils.isEmpty(emisQuotePriceList)){ if(CollectionUtils.isEmpty(emisQuotePriceList)){
throw new CalcFeeException("E3002","报价未配置"); throw new CalcException("E3002","报价未配置");
} }
// 根据表达式计算费用 // 根据表达式计算费用
@ -412,6 +409,9 @@ public class EmisWaybillServiceImpl extends EmisBaseService implements IEmisWayb
String calcExprStr=calcExp.replaceAll("w",emisWaybill.getSettlementWeight().toString()); String calcExprStr=calcExp.replaceAll("w",emisWaybill.getSettlementWeight().toString());
log.info("计算公式:"+calcExprStr+",重量:"+emisWaybill.getSettlementWeight()); log.info("计算公式:"+calcExprStr+",重量:"+emisWaybill.getSettlementWeight());
double fee = Double.valueOf(AviatorEvaluator.execute(calcExprStr).toString()); double fee = Double.valueOf(AviatorEvaluator.execute(calcExprStr).toString());
fee=WaybillHelper.calcSettledFee(fee,quoteItem.getPriceType());
feeItem.setFee(BigDecimal.valueOf(fee)); feeItem.setFee(BigDecimal.valueOf(fee));
log.info("计算后费用:"+feeItem.getFee()); log.info("计算后费用:"+feeItem.getFee());
totalFee=totalFee+fee; totalFee=totalFee+fee;
@ -460,7 +460,17 @@ public class EmisWaybillServiceImpl extends EmisBaseService implements IEmisWayb
} }
@Override @Override
public void calcSettledWeight(EmisWaybill emisWaybill) throws Exception { public void calcSettledWeight(EmisWaybill emisWaybill) throws CalcException {
if(
StringUtils.isAnyEmpty(emisWaybill.getProductType(),
emisWaybill.getTransLineType(),
emisWaybill.getBillWeight(),
emisWaybill.getTotalVolume()
)
){
throw new CalcException("E2001","参数不完整");
}
double billWeight=emisWaybill.getBillWeight().doubleValue(); double billWeight=emisWaybill.getBillWeight().doubleValue();
double totalVolume=emisWaybill.getTotalVolume().doubleValue(); double totalVolume=emisWaybill.getTotalVolume().doubleValue();
@ -469,10 +479,11 @@ public class EmisWaybillServiceImpl extends EmisBaseService implements IEmisWayb
EmisTransLine emisTransLine= getTransLineByCode(emisWaybill.getTransLineType()); EmisTransLine emisTransLine= getTransLineByCode(emisWaybill.getTransLineType());
double volumeWeight=0.0D; double volumeWeight=0.0D;
if(!StringUtils.isEmpty(emisTransLine.getMeterRate())) { if(!isEmpty(emisTransLine.getMeterRate())) {
volumeWeight=totalVolume * (1000000 / Double.valueOf(emisTransLine.getMeterRate())); volumeWeight=totalVolume * (1000000 / Double.valueOf(emisTransLine.getMeterRate()));
} }
emisWaybill.setVolumeWeight(BigDecimal.valueOf(volumeWeight));
// 两则取大 // 两则取大
double maxWeight = Math.max(billWeight,volumeWeight); double maxWeight = Math.max(billWeight,volumeWeight);

View File

@ -3,6 +3,8 @@ package com.xdadan.erp.emis.utils;
import cn.hutool.core.lang.Snowflake; import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.IdUtil;
import java.math.BigDecimal;
public class WaybillHelper { public class WaybillHelper {
public static String genOrderSn(){ public static String genOrderSn(){
@ -11,13 +13,113 @@ public class WaybillHelper {
return "TAO" + orderId.toString(); return "TAO" + orderId.toString();
} }
// 进位计算 /**
* 小数进位计算
* @param weight
* @param carryType
* @return
*/
public static double calcSettledWeight(double weight,String carryType){ public static double calcSettledWeight(double weight,String carryType){
// 0.1进位 double setteldWeight = 0.0D;
// 0.1进位 小数*10 后抹零+1
if("1".equals(carryType)){ if("1".equals(carryType)){
// setteldWeight=maxWeight int intWeight = (int) Math.floor(weight*10.0D);
double tHasWeight = weight*10.0D - (double)intWeight;
if(tHasWeight == 0.0D){
setteldWeight = weight;
}
else {
setteldWeight = ((double)(intWeight+1)/10.0D);
}
}
// 0.5 进位
else if("2".equals(carryType)){
int intWeight = (int) Math.floor(weight);
double tHasWeight = weight - (double)intWeight;
if(tHasWeight == 0.5D){
setteldWeight=weight;
}
else if(tHasWeight > 0.5D){
setteldWeight=(double)(intWeight+1);
}
// < 0.5D
else {
setteldWeight= (double)intWeight+0.5D;
}
}
// 1 小数进1 ,抹零+1
else if("3".equals(carryType)){
setteldWeight=Math.ceil(weight);
}else{
setteldWeight=weight;
} }
return weight; return setteldWeight;
}
// 费用进位计算
public static double calcSettledFee(double fee,String priceType){
double settledFee = 0.0D;
// 实际价格
if("1".equals(priceType)){
settledFee=fee;
}
// 四舍五入
else if("2".equals(priceType)){
// settledFee= new BigDecimal(fee).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue();
settledFee= Math.round(fee);
}
// 0.2进位
else if("3".equals(priceType)){
int intFee = (int) Math.floor(fee);
double tHasFee = fee - (double)intFee;
if(tHasFee == 0.2D){
settledFee=fee;
}
else if(tHasFee > 0.2D){
settledFee=(double)(intFee+1);
}
// < 0.2D
else {
settledFee= (double)intFee+0.2D;
}
}
// 0.5 进位
else if("4".equals(priceType)){
int intFee = (int) Math.floor(fee);
double tHasFee = fee - (double)intFee;
if(tHasFee == 0.5D){
settledFee=fee;
}
else if(tHasFee > 0.5D){
settledFee=(double)(intFee+1);
}
// < 0.5D
else {
settledFee= (double)intFee+0.5D;
}
}
// 1 小数进1 ,抹零+1
else if("5".equals(priceType)){
settledFee=Math.ceil(fee);
}else{
settledFee = fee;
}
return settledFee;
}
public static void main(String[] args) {
//1: 1.02 1.1 1.11
// 1.02*10 = 10.2 , 1.11*10 = 11.1
// 0.2
// double w=calcSettledWeight(1.005D,"2");
double w=calcSettledFee(1.49D,"2");
System.out.println(w);
} }
} }