猿实战17——实现你未必知晓的运费模板

本文是猿实战系列文章的一部分,介绍了如何实现电商系统中的运费模板功能,包括系统默认模板和自定义模板的创建、修改、启用/停用、删除等。详细讲解了后端的管理功能和前端基于Element-UI的列表展示、编辑操作,涉及到数据库设计和关键代码示例。
摘要由CSDN通过智能技术生成

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

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

 

功能概览

 

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

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

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

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

数据库设计

 

基于之前的设计文章猿设计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<MallFreightTemplete>  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<MallFreightTemplete> 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<List<MallFreightTemplete>> findByPage(@RequestBody  QueryMallFreightTemplete queryMallFreightTemplete){
        return mallFreightTempleteService.getMallFreightTempletesByPage(queryMallFreightTemplete);
    }
 
 
    /**
     * 获取默认运费模板
     * @param queryMallFreightTemplete
     * @return
     */
    @RequestMapping("/findDefaultlFreightTemplete")
    public  Result<MallFreightTemplete> findDefaultlFreightTemplete(@RequestBody  QueryMallFreightTemplete queryMallFreightTemplete){
        return mallFreightTempleteService.findDefaultlFreightTemplete(queryMallFreightTemplete);
    }
 
    @RequestMapping("/selectForFreightTemplete")
    public Result<List<AreaSelectedVo>> selectForFreightTemplete(@RequestBody  QueryMallFreightTemplete queryMallFreightTemplete){
       return  mallFreightTempleteService.selectForFreightTemplete(queryMallFreightTemplete);
    }
 
}

 

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

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
 
<mapper namespace="com.pz.basic.mall.dao.freight.MallFreightTempleteDao">
 
<resultMap id="ResultMap" type="MallFreightTemplete">
<id property="templeteId" column="templete_id"/>
<id property="templeteName" column="templete_name"/>
<id property="logisticsCode" column="logistics_code"/>
<id property="logisticsName" column="logistics_name"/>
<id property="templeteType" column="templete_type"/>
<id property="serviceType" column="service_type"/>
<id property="freightType" column="freight_type"/>
<id property="chargeType" column="charge_type"/>
<id property="numMin" column="num_min"/>
<id property="numMax" column="num_max"/>
<id property="fristNumPrice" column="frist_num_price"/>
<id property="nextNumPrice" column="next_num_price"/>
<id property="weightMin" column="weight_min"/>
<id property="weightMax" column="weight_max"/>
<id property="fristWeightPrice" column="frist_weight_price"/>
<id property="nextWeightPrice" column="next_weight_price"/>
<id property="volumeMin" column="volume_min"/>
<id property="volumeMax" column="volume_max"/>
<id property="fristVolumePrice" column="frist_volume_price"/>
<id property="nextVolumePrice" column="next_volume_price"/>
<id property="status" column="status"/>
<id property="createUser" column="create_user"/>
<id property="modifyUser" column="modify_user"/>
<id property="created" column="created"/>
<id property="modified" column="modified"/>
</resultMap>




<sql id="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
      </sql>




<sql id="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>
                <if test="volumeMax != null and volumeMax != ''">
            and  volume_max =  #{volumeMax}
        </if>
                <if test="fristVolumePrice != null and fristVolumePrice != ''">
            and  frist_volume_price =  #{fristVolumePrice}
        </if>
                <if test="nextVolumePrice != null and nextVolumePrice != ''">
            and  next_volume_price =  #{nextVolumePrice}
        </if>
                <if test="status != null and status != ''">
            and  status =  #{status}
        </if>
                <if test="createUser != null and createUser != ''">
            and  create_user =  #{createUser}
        </if>
                <if test="modifyUser != null and modifyUser != ''">
            and  modify_user =  #{modifyUser}
        </if>
                <if test="created != null and created != ''">
            and  created =  #{created}
        </if>
                <if test="modified != null and modified != ''">
            and  modified =  #{modified}
        </if>
            </where>
  </sql>
 
  <select id="selectMallFreightTempleteByQuery" resultMap="ResultMap" parameterType="QueryMallFreightTemplete" >
    select
    <include refid="ALL_TABLE_COLOUM" />
    from mall_freight_templete
    <if test="page != null" >
      <include refid="Query_Where_Clause" />
    </if>
 
  </select>
 
 
    <select id="selectMallFreightTempleteByPage" resultMap="ResultMap" parameterType="QueryMallFreightTemplete" >
        select
        <include refid="ALL_TABLE_COLOUM" />
        from mall_freight_templete
        <if test="page != null" >
            <include refid="Query_Where_Clause" />
        </if>
 
        LIMIT #{startRow},#{pageS
根据提供的引用内容,我无法找到关于Django运费模板的具体信息。但是,我可以为您提供一些关于Django模板的基本知识。 Django模板是一种用于生成动态网页的工具。它允许您将静态HTML与动态数据结合在一起,以便在网页上显示动态内容。在Django中,您可以使用模板来呈现数据,并将其与视图函数中的逻辑进行分离。 在Django中,您可以创建一个模板文件,其中包含HTML和模板语言。模板语言允许您在模板中插入动态数据、循环和条件语句等。您可以使用模板标签和过滤器来处理数据并进行逻辑操作。 要使用Django模板,您需要在视图函数中加载模板,并将数据传递给模板进行渲染。然后,您可以将渲染后的模板发送给客户端以显示在浏览器中。 以下是一个简单的示例,演示如何在Django中使用模板: 1. 创建一个模板文件(例如template.html),其中包含HTML和模板语言: ```html <!DOCTYPE html> <html> <head> <title>My Django Template</title> </head> <body> <h1>Welcome to {{ website_name }}</h1> <p>Today's date is {{ current_date }}</p> </body> </html> ``` 2. 在视图函数中加载模板并将数据传递给模板进行渲染: ```python from django.shortcuts import render from datetime import date def my_view(request): website_name = "My Website" current_date = date.today() return render(request, 'template.html', {'website_name': website_name, 'current_date': current_date}) ``` 3. 在urls.py中配置URL与视图函数的映射关系: ```python from django.urls import path from .views import my_view urlpatterns = [ path('my-view/', my_view, name='my-view'), ] ``` 通过访问`http://localhost:8000/my-view/`,您将看到渲染后的模板页面,其中包含动态数据。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值