diff --git a/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisCustomerAddressController.java b/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisCustomerAddressController.java index bf8c8a9d8..c5d69dbc3 100644 --- a/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisCustomerAddressController.java +++ b/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisCustomerAddressController.java @@ -124,6 +124,7 @@ public class EmisCustomerAddressController extends BaseController @PostMapping public AjaxResult add(@RequestBody EmisCustomerAddress emisCustomerAddress) { + return toAjax(emisCustomerAddressService.insertEmisCustomerAddress(emisCustomerAddress)); } diff --git a/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisWaybillController.java b/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisWaybillController.java index 3b203f37f..471a23f16 100644 --- a/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisWaybillController.java +++ b/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisWaybillController.java @@ -11,24 +11,11 @@ package com.xdadan.erp.web.emis; -import java.util.ArrayList; import java.util.List; -import javax.servlet.http.HttpServletResponse; 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.xdadan.erp.common.annotation.filter.jackson.JacksonFilter; -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.exception.CalcException; import com.xdadan.erp.emis.domain.vo.*; import com.xdadan.erp.emis.service.*; 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.page.TableDataInfo; import com.xdadan.erp.common.enums.BusinessType; -import com.xdadan.erp.common.utils.poi.ExcelUtil; import com.xdadan.erp.emis.domain.EmisWaybill; @@ -131,13 +117,18 @@ public class EmisWaybillController extends BaseController return AjaxResult.success("计算成功", jObjFee); } - catch (CalcFeeException ex){ + catch(CalcException ex){ ex.printStackTrace(); // (E3001)参数不完整 return AjaxResult.error("("+ex.getErrorCode()+")"+ex.getMessage()); } catch (Exception ex){ ex.printStackTrace(); + // 返回子定义异常 + if(ex instanceof CalcException ){ + return AjaxResult.error("("+((CalcException)ex).getErrorCode()+")"+ex.getMessage()); + } + return AjaxResult.error("服务器异常,联系客服"); } } @@ -153,12 +144,20 @@ public class EmisWaybillController extends BaseController JSONObject jObjRst = new JSONObject(); jObjRst.put("settlementWeight", emisWaybillSave.getSettlementWeight()); - + jObjRst.put("volumeWeight", emisWaybillSave.getVolumeWeight()); 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("服务器异常,联系客服"); + } + + } diff --git a/emis-biz/src/main/java/com/xdadan/erp/emis/domain/exception/CalcFeeException.java b/emis-biz/src/main/java/com/xdadan/erp/emis/domain/exception/CalcException.java similarity index 65% rename from emis-biz/src/main/java/com/xdadan/erp/emis/domain/exception/CalcFeeException.java rename to emis-biz/src/main/java/com/xdadan/erp/emis/domain/exception/CalcException.java index b4c7af0b5..9d5aeb360 100644 --- a/emis-biz/src/main/java/com/xdadan/erp/emis/domain/exception/CalcFeeException.java +++ b/emis-biz/src/main/java/com/xdadan/erp/emis/domain/exception/CalcException.java @@ -1,10 +1,10 @@ package com.xdadan.erp.emis.domain.exception; -public class CalcFeeException extends Exception { +public class CalcException extends Exception { private String errorCode; - public CalcFeeException(String errorCode,String message) { + public CalcException(String errorCode, String message) { super(message); this.errorCode = errorCode; } diff --git a/emis-biz/src/main/java/com/xdadan/erp/emis/service/EmisBaseService.java b/emis-biz/src/main/java/com/xdadan/erp/emis/service/EmisBaseService.java index 9d07efc05..6713e2f6c 100644 --- a/emis-biz/src/main/java/com/xdadan/erp/emis/service/EmisBaseService.java +++ b/emis-biz/src/main/java/com/xdadan/erp/emis/service/EmisBaseService.java @@ -14,6 +14,7 @@ package com.xdadan.erp.emis.service; import cn.hutool.core.lang.Snowflake; import cn.hutool.core.util.IdUtil; 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.SecurityUtils; import com.xdadan.erp.emis.domain.*; @@ -67,10 +68,31 @@ public class EmisBaseService { @Autowired 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 diff --git a/emis-biz/src/main/java/com/xdadan/erp/emis/service/IEmisWaybillService.java b/emis-biz/src/main/java/com/xdadan/erp/emis/service/IEmisWaybillService.java index f3aa658f6..39b77bcdd 100644 --- a/emis-biz/src/main/java/com/xdadan/erp/emis/service/IEmisWaybillService.java +++ b/emis-biz/src/main/java/com/xdadan/erp/emis/service/IEmisWaybillService.java @@ -11,8 +11,7 @@ package com.xdadan.erp.emis.service; import java.util.List; import com.xdadan.erp.emis.domain.EmisWaybill; -import com.xdadan.erp.emis.domain.EmisWaybillFeeitem; -import com.xdadan.erp.emis.domain.exception.CalcFeeException; +import com.xdadan.erp.emis.domain.exception.CalcException; 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; } diff --git a/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisCustomerAddressServiceImpl.java b/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisCustomerAddressServiceImpl.java index 6c44bdad9..a652204c4 100644 --- a/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisCustomerAddressServiceImpl.java +++ b/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisCustomerAddressServiceImpl.java @@ -13,6 +13,7 @@ package com.xdadan.erp.emis.service.impl; import java.util.List; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; +import com.xdadan.erp.emis.service.EmisBaseService; import org.apache.ibatis.annotations.Update; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -27,7 +28,7 @@ import com.xdadan.erp.emis.service.IEmisCustomerAddressService; * @date 2024-03-01 04:47:51 */ @Service -public class EmisCustomerAddressServiceImpl implements IEmisCustomerAddressService +public class EmisCustomerAddressServiceImpl extends EmisBaseService implements IEmisCustomerAddressService { @Autowired private EmisCustomerAddressMapper emisCustomerAddressMapper; @@ -65,6 +66,14 @@ public class EmisCustomerAddressServiceImpl implements IEmisCustomerAddressServi @Override public int insertEmisCustomerAddress(EmisCustomerAddress emisCustomerAddress) { + // 新增地址 + emisCustomerAddress.preInsert(); + emisCustomerAddress.setUseSiteCode(getCurrentUser().getOwnerSiteCode()); + emisCustomerAddress.setUseSite(getCurrentUser().getOwnerSiteName()); + + // 创建用户 + + return emisCustomerAddressMapper.insertEmisCustomerAddress(emisCustomerAddress); } @@ -77,6 +86,10 @@ public class EmisCustomerAddressServiceImpl implements IEmisCustomerAddressServi @Override public int updateEmisCustomerAddress(EmisCustomerAddress emisCustomerAddress) { + emisCustomerAddress.preUpdate(); + emisCustomerAddress.setUseSiteCode(getCurrentUser().getOwnerSiteCode()); + emisCustomerAddress.setUseSite(getCurrentUser().getOwnerSiteName()); + return emisCustomerAddressMapper.updateEmisCustomerAddress(emisCustomerAddress); } diff --git a/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisWaybillServiceImpl.java b/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisWaybillServiceImpl.java index 53c239a4c..df8cc2505 100644 --- a/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisWaybillServiceImpl.java +++ b/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisWaybillServiceImpl.java @@ -15,20 +15,15 @@ import java.util.ArrayList; import java.util.Date; 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.lang.Singleton; import cn.hutool.core.lang.Snowflake; import cn.hutool.core.util.IdUtil; import com.alibaba.fastjson.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 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.SecurityUtils; 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.mapper.EmisTransLineMapper; 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.util.CollectionUtils; +import static org.apache.commons.lang3.StringUtils.*; + /** * 运单列表Service业务层处理 * @@ -219,13 +216,13 @@ public class EmisWaybillServiceImpl extends EmisBaseService implements IEmisWayb boolean isNew = true; EmisWaybill emisWaybillOld = null; - if( !StringUtils.isEmpty(emisWaybillSave.getBillCode()) ){ + if( !isEmpty(emisWaybillSave.getBillCode()) ){ emisWaybillOld = this.selectEmisWaybillByBillCode(emisWaybillSave.getBillCode()); if(emisWaybillOld!=null){ isNew=false; } }else{ - if( !StringUtils.isEmpty(emisWaybillSave.getOrderSn()) ){ + if( !isEmpty(emisWaybillSave.getOrderSn()) ){ emisWaybillOld = this.selectEmisWaybillByOrderSn(emisWaybillSave.getOrderSn()); if(emisWaybillOld!=null){ isNew=false; @@ -291,13 +288,13 @@ public class EmisWaybillServiceImpl extends EmisBaseService implements IEmisWayb // 子单号拼接 StringBuilder sb = new StringBuilder(); for(int i=0;i emisQuotePriceList=getValidQuotePriceList(emisWaybill.getProductType(), @@ -376,7 +373,7 @@ public class EmisWaybillServiceImpl extends EmisBaseService implements IEmisWayb 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()); log.info("计算公式:"+calcExprStr+",重量:"+emisWaybill.getSettlementWeight()); double fee = Double.valueOf(AviatorEvaluator.execute(calcExprStr).toString()); + + fee=WaybillHelper.calcSettledFee(fee,quoteItem.getPriceType()); + feeItem.setFee(BigDecimal.valueOf(fee)); log.info("计算后费用:"+feeItem.getFee()); totalFee=totalFee+fee; @@ -460,7 +460,17 @@ public class EmisWaybillServiceImpl extends EmisBaseService implements IEmisWayb } @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 totalVolume=emisWaybill.getTotalVolume().doubleValue(); @@ -469,10 +479,11 @@ public class EmisWaybillServiceImpl extends EmisBaseService implements IEmisWayb EmisTransLine emisTransLine= getTransLineByCode(emisWaybill.getTransLineType()); double volumeWeight=0.0D; - if(!StringUtils.isEmpty(emisTransLine.getMeterRate())) { + if(!isEmpty(emisTransLine.getMeterRate())) { volumeWeight=totalVolume * (1000000 / Double.valueOf(emisTransLine.getMeterRate())); } + emisWaybill.setVolumeWeight(BigDecimal.valueOf(volumeWeight)); // 两则取大 double maxWeight = Math.max(billWeight,volumeWeight); diff --git a/emis-biz/src/main/java/com/xdadan/erp/emis/utils/WaybillHelper.java b/emis-biz/src/main/java/com/xdadan/erp/emis/utils/WaybillHelper.java index 0f7911fd4..aa501edec 100644 --- a/emis-biz/src/main/java/com/xdadan/erp/emis/utils/WaybillHelper.java +++ b/emis-biz/src/main/java/com/xdadan/erp/emis/utils/WaybillHelper.java @@ -3,6 +3,8 @@ package com.xdadan.erp.emis.utils; import cn.hutool.core.lang.Snowflake; import cn.hutool.core.util.IdUtil; +import java.math.BigDecimal; + public class WaybillHelper { public static String genOrderSn(){ @@ -11,13 +13,113 @@ public class WaybillHelper { return "TAO" + orderId.toString(); } - // 进位计算 + /** + * 小数进位计算 + * @param weight + * @param carryType + * @return + */ public static double calcSettledWeight(double weight,String carryType){ - // 0.1进位 + double setteldWeight = 0.0D; + // 0.1进位 小数*10 后抹零+1 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); } }