基于springboot在线鲜花交易商城源码

springboot2.1 springMVC  mybatis商城系统

技术栈:
后端采用 springboot2.1 springmvc mybaits
前端采用bootstrap jquery thymeleaf html
数据库mysql jdk1.8
开发工具:eclipse idea myeclipse sts等java开发工具

<?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="flowershop.mall.dao.OrderMapper">
    <resultMap id="BaseResultMap" type="flowershop.mall.entity.Order">
        <id column="order_id" jdbcType="BIGINT" property="orderId"/>
        <result column="order_no" jdbcType="VARCHAR" property="orderNo"/>
        <result column="user_id" jdbcType="BIGINT" property="userId"/>
        <result column="total_price" jdbcType="INTEGER" property="totalPrice"/>
        <result column="pay_status" jdbcType="TINYINT" property="payStatus"/>
        <result column="pay_type" jdbcType="TINYINT" property="payType"/>
        <result column="pay_time" jdbcType="TIMESTAMP" property="payTime"/>
        <result column="order_status" jdbcType="TINYINT" property="orderStatus"/>
        <result column="extra_info" jdbcType="VARCHAR" property="extraInfo"/>
        <result column="user_address" jdbcType="VARCHAR" property="userAddress"/>
        <result column="is_deleted" jdbcType="TINYINT" property="isDeleted"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
    </resultMap>
    <sql id="Base_Column_List">
    order_id, order_no, user_id, total_price, pay_status, pay_type, pay_time, order_status,
    extra_info, user_name, user_phone, user_address, is_deleted, create_time, update_time
  </sql>
    <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from `order`
        where order_id = #{orderId,jdbcType=BIGINT}
    </select>
    <select id="selectByOrderNo" parameterType="java.lang.String" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from `order`
        where order_no = #{orderNo,jdbcType=VARCHAR} and is_deleted=0 limit 1
    </select>
    <select id="selectByPrimaryKeys" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from `order`
        where order_id in
        <foreach collection="orderIds" item="item" index="index"
                 open="(" separator="," close=")">#{item}
        </foreach>
    </select>
    <select id="findNewBeeMallOrderList" parameterType="Map" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from `order` as t
        <where>
            <if test="orderNo!=null and orderNo!=''">
                and t.order_no = #{orderNo}
            </if>
            <if test="userId!=null and userId!=''">
                and t.user_id = #{userId}
            </if>
            <if test="payType!=null and payType!=''">
                and t.pay_type = #{payType}
            </if>
            <if test="orderStatus!=null and orderStatus!=''">
                and t.order_status = #{orderStatus}
            </if>
            <if test="isDeleted!=null and isDeleted!=''">
                and t.is_deleted = #{isDeleted}
            </if>
            <if test="startTime != null and startTime.trim() != ''">
                and t.create_time &gt; #{startTime}
            </if>
            <if test="endTime != null and endTime.trim() != ''">
                and t.create_time &lt; #{endTime}
            </if>
        </where>
        order by create_time desc
        <if test="start!=null and limit!=null">
            limit #{start},#{limit}
        </if>
    </select>

    <select id="getTotalNewBeeMallOrders" parameterType="Map" resultType="int">
        select count(*) from `order`
        <where>
            <if test="orderNo!=null and orderNo!=''">
                and order_no = #{orderNo}
            </if>
            <if test="userId!=null and userId!=''">
                and user_id = #{userId}
            </if>
            <if test="payType!=null and payType!=''">
                and pay_type = #{payType}
            </if>
            <if test="orderStatus!=null and orderStatus!=''">
                and order_status = #{orderStatus}
            </if>
            <if test="isDeleted!=null and isDeleted!=''">
                and is_deleted = #{isDeleted}
            </if>
            <if test="startTime != null and startTime.trim() != ''">
                and create_time &gt; #{startTime}
            </if>
            <if test="endTime != null and endTime.trim() != ''">
                and create_time &lt; #{endTime}
            </if>
        </where>
    </select>
    <update id="deleteByPrimaryKey" parameterType="java.lang.Long">
    update `order` set is_deleted=1
    where order_id = #{orderId,jdbcType=BIGINT} and is_deleted=0
  </update>
    <insert id="insert" parameterType="flowershop.mall.entity.Order">
    insert into `order` (order_id, order_no, user_id,
      total_price, pay_status, pay_type, 
      pay_time, order_status, extra_info, 
      user_address,is_deleted, create_time, update_time
      )
    values (#{orderId,jdbcType=BIGINT}, #{orderNo,jdbcType=VARCHAR}, #{userId,jdbcType=BIGINT}, 
      #{totalPrice,jdbcType=INTEGER}, #{payStatus,jdbcType=TINYINT}, #{payType,jdbcType=TINYINT}, 
      #{payTime,jdbcType=TIMESTAMP}, #{orderStatus,jdbcType=TINYINT}, #{extraInfo,jdbcType=VARCHAR}, 
       #{userAddress,jdbcType=VARCHAR},#{isDeleted,jdbcType=TINYINT}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}
      )
  </insert>
    <insert id="insertSelective" useGeneratedKeys="true" keyProperty="orderId"
            parameterType="flowershop.mall.entity.Order">
        insert into `order`
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="orderId != null">
                order_id,
            </if>
            <if test="orderNo != null">
                order_no,
            </if>
            <if test="userId != null">
                user_id,
            </if>
            <if test="totalPrice != null">
                total_price,
            </if>
            <if test="payStatus != null">
                pay_status,
            </if>
            <if test="payType != null">
                pay_type,
            </if>
            <if test="payTime != null">
                pay_time,
            </if>
            <if test="orderStatus != null">
                order_status,
            </if>
            <if test="extraInfo != null">
                extra_info,
            </if>
            <if test="userAddress != null">
                user_address,
            </if>
            <if test="isDeleted != null">
                is_deleted,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="updateTime != null">
                update_time,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="orderId != null">
                #{orderId,jdbcType=BIGINT},
            </if>
            <if test="orderNo != null">
                #{orderNo,jdbcType=VARCHAR},
            </if>
            <if test="userId != null">
                #{userId,jdbcType=BIGINT},
            </if>
            <if test="totalPrice != null">
                #{totalPrice,jdbcType=INTEGER},
            </if>
            <if test="payStatus != null">
                #{payStatus,jdbcType=TINYINT},
            </if>
            <if test="payType != null">
                #{payType,jdbcType=TINYINT},
            </if>
            <if test="payTime != null">
                #{payTime,jdbcType=TIMESTAMP},
            </if>
            <if test="orderStatus != null">
                #{orderStatus,jdbcType=TINYINT},
            </if>
            <if test="extraInfo != null">
                #{extraInfo,jdbcType=VARCHAR},
            </if>
            <if test="userAddress != null">
                #{userAddress,jdbcType=VARCHAR},
            </if>
            <if test="isDeleted != null">
                #{isDeleted,jdbcType=TINYINT},
            </if>
            <if test="createTime != null">
                #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="updateTime != null">
                #{updateTime,jdbcType=TIMESTAMP},
            </if>
        </trim>
    </insert>
    <update id="checkDone">
        update `order`
        set order_status = 2,update_time = now()
        where order_id in
        <foreach collection="orderIds" item="item" index="index"
                 open="(" separator="," close=")">#{item}
        </foreach>
    </update>
    <update id="checkOut">
        update `order`
        set order_status = 3,update_time = now()
        where order_id in
        <foreach collection="orderIds" item="item" index="index"
                 open="(" separator="," close=")">#{item}
        </foreach>
    </update>
    <update id="closeOrder">
        update `order`
        set order_status = #{orderStatus},update_time = now()
        where order_id in
        <foreach collection="orderIds" item="item" index="index"
                 open="(" separator="," close=")">#{item}
        </foreach>
    </update>
    <update id="updateByPrimaryKeySelective" parameterType="flowershop.mall.entity.Order">
        update `order`
        <set>
            <if test="orderNo != null">
                order_no = #{orderNo,jdbcType=VARCHAR},
            </if>
            <if test="userId != null">
                user_id = #{userId,jdbcType=BIGINT},
            </if>
            <if test="totalPrice != null">
                total_price = #{totalPrice,jdbcType=INTEGER},
            </if>
            <if test="payStatus != null">
                pay_status = #{payStatus,jdbcType=TINYINT},
            </if>
            <if test="payType != null">
                pay_type = #{payType,jdbcType=TINYINT},
            </if>
            <if test="payTime != null">
                pay_time = #{payTime,jdbcType=TIMESTAMP},
            </if>
            <if test="orderStatus != null">
                order_status = #{orderStatus,jdbcType=TINYINT},
            </if>
            <if test="extraInfo != null">
                extra_info = #{extraInfo,jdbcType=VARCHAR},
            </if>
            <if test="userAddress != null">
                user_address = #{userAddress,jdbcType=VARCHAR},
            </if>
            <if test="isDeleted != null">
                is_deleted = #{isDeleted,jdbcType=TINYINT},
            </if>
            <if test="createTime != null">
                create_time = #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime,jdbcType=TIMESTAMP},
            </if>
        </set>
        where order_id = #{orderId,jdbcType=BIGINT}
    </update>
    <update id="updateByPrimaryKey" parameterType="flowershop.mall.entity.Order">
    update `order`
    set order_no = #{orderNo,jdbcType=VARCHAR},
      user_id = #{userId,jdbcType=BIGINT},
      total_price = #{totalPrice,jdbcType=INTEGER},
      pay_status = #{payStatus,jdbcType=TINYINT},
      pay_type = #{payType,jdbcType=TINYINT},
      pay_time = #{payTime,jdbcType=TIMESTAMP},
      order_status = #{orderStatus,jdbcType=TINYINT},
      extra_info = #{extraInfo,jdbcType=VARCHAR},
      user_address = #{userAddress,jdbcType=VARCHAR},
      is_deleted = #{isDeleted,jdbcType=TINYINT},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      update_time = #{updateTime,jdbcType=TIMESTAMP}
    where order_id = #{orderId,jdbcType=BIGINT}
  </update>
</mapper>

 

import flowershop.mall.common.ServiceResultEnum;
import flowershop.mall.entity.Goods;
import flowershop.mall.entity.GoodsCategory;
import flowershop.mall.service.CategoryService;
import flowershop.mall.service.GoodsService;
import flowershop.mall.common.Constants;
import flowershop.mall.common.CategoryLevelEnum;
import flowershop.mall.util.PageQueryUtil;
import flowershop.mall.util.Result;
import flowershop.mall.util.ResultGenerator;
import org.springframework.stereotype.Controller;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.thymeleaf.expression.Ids;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * @author 13
 * XXXXXX
 * @email XXXXXX@qq.com
 * @link
 */
@Controller
@RequestMapping("/admin")
public class GoodsController {

    @Resource
    private GoodsService goodsService;
    @Resource
    private CategoryService categoryService;

    @GetMapping("/goods")
    public String goodsPage(HttpServletRequest request) {
        request.setAttribute("path", "newbee_mall_goods");
        return "admin/goods";
    }

    @GetMapping("/goods/edit")
    public String edit(HttpServletRequest request) {
        request.setAttribute("path", "edit");
        //查询所有的一级分类
        List<GoodsCategory> firstLevelCategories = categoryService.selectByLevelAndParentIdsAndNumber(Collections.singletonList(0L), CategoryLevelEnum.LEVEL_ONE.getLevel());
        if (!CollectionUtils.isEmpty(firstLevelCategories)) {
            //查询一级分类列表中第一个实体的所有二级分类
            List<GoodsCategory> secondLevelCategories = categoryService.selectByLevelAndParentIdsAndNumber(Collections.singletonList(firstLevelCategories.get(0).getCategoryId()), CategoryLevelEnum.LEVEL_TWO.getLevel());
            if (!CollectionUtils.isEmpty(secondLevelCategories)) {
                //查询二级分类列表中第一个实体的所有三级分类
                List<GoodsCategory> thirdLevelCategories = categoryService.selectByLevelAndParentIdsAndNumber(Collections.singletonList(secondLevelCategories.get(0).getCategoryId()), CategoryLevelEnum.LEVEL_THREE.getLevel());
                request.setAttribute("firstLevelCategories", firstLevelCategories);
                request.setAttribute("secondLevelCategories", secondLevelCategories);
                request.setAttribute("thirdLevelCategories", thirdLevelCategories);
                request.setAttribute("path", "goods-edit");
                return "admin/goods_edit";
            }
        }
        return "error/error_5xx";
    }

    @GetMapping("/goods/edit/{goodsId}")
    public String edit(HttpServletRequest request, @PathVariable("goodsId") Long goodsId) {
        request.setAttribute("path", "edit");
        Goods goods = goodsService.getNewBeeMallGoodsById(goodsId);
        if (goods == null) {
            return "error/error_400";
        }
        if (goods.getGoodsCategoryId() > 0) {
            if (goods.getGoodsCategoryId() != null || goods.getGoodsCategoryId() > 0) {
                //有分类字段则查询相关分类数据返回给前端以供分类的三级联动显示
                GoodsCategory currentGoodsCategory = categoryService.getGoodsCategoryById(goods.getGoodsCategoryId());
                //商品表中存储的分类id字段为三级分类的id,不为三级分类则是错误数据
                if (currentGoodsCategory != null && currentGoodsCategory.getCategoryLevel() == CategoryLevelEnum.LEVEL_THREE.getLevel()) {
                    //查询所有的一级分类
                    List<GoodsCategory> firstLevelCategories = categoryService.selectByLevelAndParentIdsAndNumber(Collections.singletonList(0L), CategoryLevelEnum.LEVEL_ONE.getLevel());
                    //根据parentId查询当前parentId下所有的三级分类
                    List<GoodsCategory> thirdLevelCategories = categoryService.selectByLevelAndParentIdsAndNumber(Collections.singletonList(currentGoodsCategory.getParentId()), CategoryLevelEnum.LEVEL_THREE.getLevel());
                    //查询当前三级分类的父级二级分类
                    GoodsCategory secondCategory = categoryService.getGoodsCategoryById(currentGoodsCategory.getParentId());
                    if (secondCategory != null) {
                        //根据parentId查询当前parentId下所有的二级分类
                        List<GoodsCategory> secondLevelCategories = categoryService.selectByLevelAndParentIdsAndNumber(Collections.singletonList(secondCategory.getParentId()), CategoryLevelEnum.LEVEL_TWO.getLevel());
                        //查询当前二级分类的父级一级分类
                        GoodsCategory firestCategory = categoryService.getGoodsCategoryById(secondCategory.getParentId());
                        if (firestCategory != null) {
                            //所有分类数据都得到之后放到request对象中供前端读取
                            request.setAttribute("firstLevelCategories", firstLevelCategories);
                            request.setAttribute("secondLevelCategories", secondLevelCategories);
                            request.setAttribute("thirdLevelCategories", thirdLevelCategories);
                            request.setAttribute("firstLevelCategoryId", firestCategory.getCategoryId());
                            request.setAttribute("secondLevelCategoryId", secondCategory.getCategoryId());
                            request.setAttribute("thirdLevelCategoryId", currentGoodsCategory.getCategoryId());
                        }
                    }
                }
            }
        }
        if (goods.getGoodsCategoryId() == 0) {
            //查询所有的一级分类
            List<GoodsCategory> firstLevelCategories = categoryService.selectByLevelAndParentIdsAndNumber(Collections.singletonList(0L), CategoryLevelEnum.LEVEL_ONE.getLevel());
            if (!CollectionUtils.isEmpty(firstLevelCategories)) {
                //查询一级分类列表中第一个实体的所有二级分类
                List<GoodsCategory> secondLevelCategories = categoryService.selectByLevelAndParentIdsAndNumber(Collections.singletonList(firstLevelCategories.get(0).getCategoryId()), CategoryLevelEnum.LEVEL_TWO.getLevel());
                if (!CollectionUtils.isEmpty(secondLevelCategories)) {
                    //查询二级分类列表中第一个实体的所有三级分类
                    List<GoodsCategory> thirdLevelCategories = categoryService.selectByLevelAndParentIdsAndNumber(Collections.singletonList(secondLevelCategories.get(0).getCategoryId()), CategoryLevelEnum.LEVEL_THREE.getLevel());
                    request.setAttribute("firstLevelCategories", firstLevelCategories);
                    request.setAttribute("secondLevelCategories", secondLevelCategories);
                    request.setAttribute("thirdLevelCategories", thirdLevelCategories);
                }
            }
        }
        request.setAttribute("goods", goods);
        request.setAttribute("path", "goods-edit");
        return "admin/goods_edit";
    }

    /**
     * 列表
     */
    @RequestMapping(value = "/goods/list", method = RequestMethod.GET)
    @ResponseBody
    public Result list(@RequestParam Map<String, Object> params) {
        if (StringUtils.isEmpty(params.get("page")) || StringUtils.isEmpty(params.get("limit"))) {
            return ResultGenerator.genFailResult("参数异常!");
        }
        PageQueryUtil pageUtil = new PageQueryUtil(params);
        return ResultGenerator.genSuccessResult(goodsService.getNewBeeMallGoodsPage(pageUtil));
    }

    /**
     * 添加
     */
    @RequestMapping(value = "/goods/save", method = RequestMethod.POST)
    @ResponseBody
    public Result save(@RequestBody Goods goods) {
        if (StringUtils.isEmpty(goods.getGoodsName())
                || StringUtils.isEmpty(goods.getGoodsIntro())
                || StringUtils.isEmpty(goods.getTag())
                || Objects.isNull(goods.getOriginalPrice())
                || Objects.isNull(goods.getGoodsCategoryId())
                || Objects.isNull(goods.getSellingPrice())
                || Objects.isNull(goods.getStockNum())
                || Objects.isNull(goods.getGoodsSellStatus())
                || StringUtils.isEmpty(goods.getGoodsCoverImg())
                || StringUtils.isEmpty(goods.getGoodsDetailContent())) {
            return ResultGenerator.genFailResult("参数异常!");
        }
        String result = goodsService.saveNewBeeMallGoods(goods);
        if (ServiceResultEnum.SUCCESS.getResult().equals(result)) {
            return ResultGenerator.genSuccessResult();
        } else {
            return ResultGenerator.genFailResult(result);
        }
    }

 

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序猿毕业分享网

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值