mirror of
https://gitee.com/coder-xiaomo/flashsale
synced 2025-09-12 23:11:38 +08:00
交易下单4-获取用户登录信息;Price拼写错误改正
This commit is contained in:
@@ -1,14 +1,16 @@
|
||||
package com.cxyxiaomo.flashsale.controller;
|
||||
|
||||
import com.cxyxiaomo.flashsale.error.BusinessException;
|
||||
import com.cxyxiaomo.flashsale.error.EmBusinessError;
|
||||
import com.cxyxiaomo.flashsale.response.CommonReturnType;
|
||||
import com.cxyxiaomo.flashsale.service.OrderService;
|
||||
import com.cxyxiaomo.flashsale.service.model.OrderModel;
|
||||
import com.cxyxiaomo.flashsale.service.model.UserModel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
@Controller("/order")
|
||||
@RequestMapping("/order")
|
||||
@@ -18,10 +20,23 @@ public class OrderController extends BaseController {
|
||||
@Autowired
|
||||
private OrderService orderService;
|
||||
|
||||
@Autowired
|
||||
private HttpServletRequest httpServletRequest;
|
||||
|
||||
// 封装下单请求
|
||||
@RequestMapping(value = "/createorder", method = {RequestMethod.POST}, consumes = {CONTENT_TYPE_FORMED})
|
||||
@ResponseBody
|
||||
public CommonReturnType createOrder(@RequestParam(name = "itemId") Integer itemId,
|
||||
@RequestParam(name = "amount") Integer amount) throws BusinessException {
|
||||
OrderModel orderModel = orderService.createOrder(null, itemId, amount);
|
||||
// 获取用户登陆状态
|
||||
Boolean isLogin = (Boolean) httpServletRequest.getSession().getAttribute("IS_LOGIN");
|
||||
if (isLogin == null || !isLogin.booleanValue()) {
|
||||
throw new BusinessException(EmBusinessError.USER_NOT_LOGIN, "用户还未登录,不能下单");
|
||||
}
|
||||
// 获取用户的登录信息
|
||||
UserModel userModel = (UserModel) httpServletRequest.getSession().getAttribute("LOGIN_USER");
|
||||
|
||||
OrderModel orderModel = orderService.createOrder(userModel.getId(), itemId, amount);
|
||||
|
||||
return CommonReturnType.create(null);
|
||||
}
|
||||
|
@@ -33,11 +33,11 @@ public class OrderDO {
|
||||
/**
|
||||
*
|
||||
* This field was generated by MyBatis Generator.
|
||||
* This field corresponds to the database column order_info.item_pirce
|
||||
* This field corresponds to the database column order_info.item_price
|
||||
*
|
||||
* @mbg.generated Thu Mar 03 22:04:45 CST 2022
|
||||
*/
|
||||
private BigDecimal itemPirce;
|
||||
private BigDecimal itemPrice;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -131,26 +131,26 @@ public class OrderDO {
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method returns the value of the database column order_info.item_pirce
|
||||
* This method returns the value of the database column order_info.item_price
|
||||
*
|
||||
* @return the value of order_info.item_pirce
|
||||
* @return the value of order_info.item_price
|
||||
*
|
||||
* @mbg.generated Thu Mar 03 22:04:45 CST 2022
|
||||
*/
|
||||
public BigDecimal getItemPirce() {
|
||||
return itemPirce;
|
||||
public BigDecimal getItemPrice() {
|
||||
return itemPrice;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method was generated by MyBatis Generator.
|
||||
* This method sets the value of the database column order_info.item_pirce
|
||||
* This method sets the value of the database column order_info.item_price
|
||||
*
|
||||
* @param itemPirce the value for order_info.item_pirce
|
||||
* @param itemPrice the value for order_info.item_price
|
||||
*
|
||||
* @mbg.generated Thu Mar 03 22:04:45 CST 2022
|
||||
*/
|
||||
public void setItemPirce(BigDecimal itemPirce) {
|
||||
this.itemPirce = itemPirce;
|
||||
public void setItemPrice(BigDecimal itemPrice) {
|
||||
this.itemPrice = itemPrice;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -8,6 +8,7 @@ public enum EmBusinessError implements CommonError {
|
||||
// 20000开头为用户信息相关错误定义
|
||||
USER_NOT_EXIST(20001, "用户不存在"),
|
||||
USER_LOGIN_FAILED(20002, "用户手机号或密码不正确"),
|
||||
USER_NOT_LOGIN(20003, "用户还未登录"),
|
||||
|
||||
// 30000开头为交易信息错误定义
|
||||
STOCK_NOT_ENOUGH(30001, "库存不足");
|
||||
|
@@ -10,7 +10,7 @@
|
||||
<id column="id" jdbcType="VARCHAR" property="id" />
|
||||
<result column="user_id" jdbcType="INTEGER" property="userId" />
|
||||
<result column="item_id" jdbcType="INTEGER" property="itemId" />
|
||||
<result column="item_pirce" jdbcType="DECIMAL" property="itemPirce" />
|
||||
<result column="item_price" jdbcType="DECIMAL" property="itemPrice" />
|
||||
<result column="amount" jdbcType="INTEGER" property="amount" />
|
||||
<result column="order_price" jdbcType="DECIMAL" property="orderPrice" />
|
||||
</resultMap>
|
||||
@@ -20,7 +20,7 @@
|
||||
This element is automatically generated by MyBatis Generator, do not modify.
|
||||
This element was generated on Thu Mar 03 22:04:45 CST 2022.
|
||||
-->
|
||||
id, user_id, item_id, item_pirce, amount, order_price
|
||||
id, user_id, item_id, item_price, amount, order_price
|
||||
</sql>
|
||||
<select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
|
||||
<!--
|
||||
@@ -49,10 +49,10 @@
|
||||
This element was generated on Thu Mar 03 22:04:45 CST 2022.
|
||||
-->
|
||||
insert into order_info (id, user_id, item_id,
|
||||
item_pirce, amount, order_price
|
||||
item_price, amount, order_price
|
||||
)
|
||||
values (#{id,jdbcType=VARCHAR}, #{userId,jdbcType=INTEGER}, #{itemId,jdbcType=INTEGER},
|
||||
#{itemPirce,jdbcType=DECIMAL}, #{amount,jdbcType=INTEGER}, #{orderPrice,jdbcType=DECIMAL}
|
||||
#{itemPrice,jdbcType=DECIMAL}, #{amount,jdbcType=INTEGER}, #{orderPrice,jdbcType=DECIMAL}
|
||||
)
|
||||
</insert>
|
||||
<insert id="insertSelective" parameterType="com.cxyxiaomo.flashsale.dataobject.OrderDO">
|
||||
@@ -72,8 +72,8 @@
|
||||
<if test="itemId != null">
|
||||
item_id,
|
||||
</if>
|
||||
<if test="itemPirce != null">
|
||||
item_pirce,
|
||||
<if test="itemPrice != null">
|
||||
item_price,
|
||||
</if>
|
||||
<if test="amount != null">
|
||||
amount,
|
||||
@@ -92,8 +92,8 @@
|
||||
<if test="itemId != null">
|
||||
#{itemId,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="itemPirce != null">
|
||||
#{itemPirce,jdbcType=DECIMAL},
|
||||
<if test="itemPrice != null">
|
||||
#{itemPrice,jdbcType=DECIMAL},
|
||||
</if>
|
||||
<if test="amount != null">
|
||||
#{amount,jdbcType=INTEGER},
|
||||
@@ -117,8 +117,8 @@
|
||||
<if test="itemId != null">
|
||||
item_id = #{itemId,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="itemPirce != null">
|
||||
item_pirce = #{itemPirce,jdbcType=DECIMAL},
|
||||
<if test="itemPrice != null">
|
||||
item_price = #{itemPrice,jdbcType=DECIMAL},
|
||||
</if>
|
||||
<if test="amount != null">
|
||||
amount = #{amount,jdbcType=INTEGER},
|
||||
@@ -138,7 +138,7 @@
|
||||
update order_info
|
||||
set user_id = #{userId,jdbcType=INTEGER},
|
||||
item_id = #{itemId,jdbcType=INTEGER},
|
||||
item_pirce = #{itemPirce,jdbcType=DECIMAL},
|
||||
item_price = #{itemPrice,jdbcType=DECIMAL},
|
||||
amount = #{amount,jdbcType=INTEGER},
|
||||
order_price = #{orderPrice,jdbcType=DECIMAL}
|
||||
where id = #{id,jdbcType=VARCHAR}
|
||||
|
Reference in New Issue
Block a user