java实现电商运费计算_猿实战17——实现你未必知晓的运费模板

本文介绍了如何使用Java实现电商系统的运费模板功能,包括系统默认模板和自定义模板的管理,涉及计费方式、数据库设计和前后端实现。通过阅读,你可以了解到如何处理商品的运费计算,以及运费模板的增删改查操作。
摘要由CSDN通过智能技术生成

猿实战是一个原创系列文章,通过实战的方式,采用前后端分离的技术结合SpringMVC Spring Mybatis,手把手教你撸一个完整的电商系统,变身猿人找到工作不是问题。还等什么呢?关注公号,取基础代码,一起实战吧。

上一个章节,猿人君教会了你如何去设计和实现运费的基础数据——管理和维护承运商信息。今天我们一起来学习,如何实现运费计算的支柱模块——运费模板。

功能概览

f08804bc5c39edebeb2207082bb15dd5.png

6271cc83937fa20e37c7aef27e930c11.png

c76fc9842b7a6dc708a38efde4503927.png

4a376d9e7128c2ab53c3020f5d2bf191.png

a0eb1e3ab94b2e6264d7f106553e141c.png

运费模板,的出现是为了解决繁杂的商品运费计算问题,它的功能比较复杂,系统需要提供设置默认运费模板功能,也可以新增运费模板,一般而言,运费模板分为系统默认模板和自定义模板两类。

系统的默认模板用于处理未设置运费模板的商品运费计算。

自定义模板,用于计算设置地区的运费计算,其中计费方式支持按计费类型来支持按重量、体积、数量的计费方式(当运费类型为自定义运费时才支持这一选项)。

在列表页面,系统模板不允许新增和修改操作。

数据库设计

d548d724e5c62f6d2c4f0bb8ce171510.png

f738c78d56193b7e958d3ed366c56d13.png

基于之前的设计文章猿设计14——真电商之运费模板,我们可以快速地整理运费模板的基本信息,并落地为数据库表,如上图所示。

后端功能实现

运费模板的后台管理功能相对传统,提供新增/修改/停用/启用删除/分页列表的功能。

/** * Copyright(c) 2004-2020 pangzi * com.pz.basic.mall.controller.freight.MallFreightTempleteController.java */package com.pz.basic.mall.controller.freight; import com.pz.basic.mall.domain.base.Result;import com.pz.basic.mall.domain.base.enums.DataStatusEnum;import com.pz.basic.mall.domain.freight.MallFreightTemplete;import com.pz.basic.mall.domain.freight.query.QueryMallFreightTemplete;import com.pz.basic.mall.domain.sys.AreaSelectedVo;import com.pz.basic.mall.service.freight.MallFreightTempleteService;import org.springframework.web.bind.annotation.RequestBody;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController; import java.util.List;  /** * * @author pangzi * @date 2020-06-22 20:47:27 * * */@RestController@RequestMapping("/freightTemplete")public class MallFreightTempleteController {
          private MallFreightTempleteService mallFreightTempleteService;       public void setMallFreightTempleteService(MallFreightTempleteService mallFreightTempleteService) {
            this.mallFreightTempleteService = mallFreightTempleteService;    }      /**     * 新增标准运费     * @param mallFreightTemplete     * @return     */    @RequestMapping("/addMallFreightTemplete")    public Result  addMallFreightTemplete(@RequestBody MallFreightTemplete mallFreightTemplete){
            try{
                 return   mallFreightTempleteService.addMallFreightTemplete(mallFreightTemplete);        }catch(Exception e){
                e.printStackTrace();            return new Result(false);        }    }     /**     * 根据ID查找标准运费     * @param id     * @return     */    @RequestMapping("/findMallFreightTempleteById")    public  Result findMallFreightTempleteById(Long id){
            return mallFreightTempleteService.getMallFreightTempleteById(id);    }     /**     * 修改标准运费     * @param mallFreightTemplete     * @return     */    @RequestMapping("/updateMallFreightTemplete")    public Result updateMallFreightTemplete(@RequestBody MallFreightTemplete mallFreightTemplete){
            try{
                return  mallFreightTempleteService.updateMallFreightTempleteById(mallFreightTemplete);        }catch(Exception e){
                e.printStackTrace();            return new Result(false);        }    }     /**     * 启用标准运费     * @param mallFreightTemplete     * @return     */    @RequestMapping("/enableMallFreightTemplete")    public Result enableMallFreightTemplete(@RequestBody MallFreightTemplete mallFreightTemplete){
            try{
                MallFreightTemplete modifiedData =new MallFreightTemplete ();            modifiedData.setTempleteId(mallFreightTemplete.getTempleteId());            modifiedData.setStatus(DataStatusEnum.STATUS_ENABLE.getStatusValue());            return  mallFreightTempleteService.updateMallFreightTempleteById(modifiedData);        }catch(Exception e){
                e.printStackTrace();            return new Result(false);        }    }      /**     * 停用标准运费     * @param mallFreightTemplete     * @return     */    @RequestMapping("/disableMallFreightTemplete")    public Result disableMallFreightTemplete(@RequestBody MallFreightTemplete mallFreightTemplete){
            try{
                MallFreightTemplete modifiedData =new MallFreightTemplete ();            modifiedData.setTempleteId(mallFreightTemplete.getTempleteId());            modifiedData.setStatus(DataStatusEnum.STATUS_DISABLE.getStatusValue());            return  mallFreightTempleteService.updateMallFreightTempleteById(modifiedData);        }catch(Exception e){
                e.printStackTrace();            return new Result(false);        }    }     /**     * 删除标准运费     * @param mallFreightTemplete     * @return     */    @RequestMapping("/deleteMallFreightTemplete")    public Result deleteMallFreightTemplete(@RequestBody MallFreightTemplete mallFreightTemplete){
            try{
                MallFreightTemplete modifiedData =new MallFreightTemplete ();            modifiedData.setTempleteId(mallFreightTemplete.getTempleteId());            modifiedData.setStatus(DataStatusEnum.STATUS_DELETED.getStatusValue());            return  mallFreightTempleteService.updateMallFreightTempleteById(modifiedData);        }catch(Exception e){
                e.printStackTrace();            return new Result(false);        }    }      /**     * 分页返回标准运费列表     * @param queryMallFreightTemplete     * @return     */    @RequestMapping("/findByPage")    public  Result> findByPage(@RequestBody  QueryMallFreightTemplete queryMallFreightTemplete){
            return mallFreightTempleteService.getMallFreightTempletesByPage(queryMallFreightTemplete);    }      /**     * 获取默认运费模板     * @param queryMallFreightTemplete     * @return     */    @RequestMapping("/findDefaultlFreightTemplete")    public  Result findDefaultlFreightTemplete(@RequestBody  QueryMallFreightTemplete queryMallFreightTemplete){
            return mallFreightTempleteService.findDefaultlFreightTemplete(queryMallFreightTemplete);    }     @RequestMapping("/selectForFreightTemplete")    public Result> selectForFreightTemplete(@RequestBody  QueryMallFreightTemplete queryMallFreightTemplete){
           return  mallFreightTempleteService.selectForFreightTemplete(queryMallFreightTemplete);    } }

考虑到很多朋友编写mapper文件比较困难,这个章节的mapper就先给到你吧,不过做人不要太懒了,domain 和dao 以及service的实现,还是自己动手搞一下吧。

<?xml version="1.0" encoding=span >"-//mybatis.org//DTD Mapper 3.0//EN"  "com.pz.basic.mall.dao.freight.MallFreightTempleteDao"> "ResultMap" "templeteId" column="templeteName" column="logisticsCode" column="logisticsName" column="templeteType" column="serviceType" column="freightType" column="chargeType" column="numMin" column="numMax" column="fristNumPrice" column="nextNumPrice" column="weightMin" column="weightMax" column="fristWeightPrice" column="nextWeightPrice" column="volumeMin" column="volumeMax" column="fristVolumePrice" column="nextVolumePrice" column="status" column="createUser" column="modifyUser" column="created" column="modified" column="ALL_TABLE_COLOUM">             templete_id,                 templete_name,                 logistics_code,                 logistics_name,                 templete_type,                 service_type,                 freight_type,                 charge_type,                 num_min,                 num_max,                 frist_num_price,                 next_num_price,                 weight_min,                 weight_max,                 frist_weight_price,                 next_weight_price,                 volume_min,                 volume_max,                 frist_volume_price,                 next_volume_price,                 status,                 create_user,                 modify_user,                 created,                 modified      "Query_Where_Clause" >    <where >          status>-1                <if test="templeteId != null and templeteId != ''">            and  templete_id =  #{templeteId}        if>                <if test="templeteName != null and templeteName != ''">            and  templete_name =  #{templeteName}        if>                <if test="logisticsCode != null and logisticsCode != ''">            and  logistics_code =  #{logisticsCode}        if>                <if test="logisticsName != null and logisticsName != ''">            and  logistics_name =  #{logisticsName}        if>                <if test="templeteType != null and templeteType != ''">            and  templete_type =  #{templeteType}        if>                <if test="serviceType != null and serviceType != ''">            and  service_type =  #{serviceType}        if>                <if test="freightType != null and freightType != ''">            and  freight_type =  #{freightType}        if>                <if test="chargeType != null and chargeType != ''">            and  charge_type =  #{chargeType}        if>                <if test="numMin != null and numMin != ''">            and  num_min =  #{numMin}        if>                <if test="numMax != null and numMax != ''">            and  num_max =  #{numMax}        if>                <if test="fristNumPrice != null and fristNumPrice != ''">            and  frist_num_price =  #{fristNumPrice}        if>                <if test="nextNumPrice != null and nextNumPrice != ''">            and  next_num_price =  #{nextNumPrice}        if>                <if test="weightMin != null and weightMin != ''">            and  weight_min =  #{weightMin}        if>                <if test="weightMax != null and weightMax != ''">            and  weight_max =  #{weightMax}        if>                <if test="fristWeightPrice != null and fristWeightPrice != ''">            and  frist_weight_price =  #{fristWeightPrice}        if>                <if test="nextWeightPrice != null and nextWeightPrice != ''">            and  next_weight_price =  #{nextWeightPrice}        if>                <if test="volumeMin != null and volumeMin != ''">            and  volume_min =  #{volumeMin}        if>                &
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值