1
0
mirror of https://gitee.com/coder-xiaomo/flashsale synced 2025-01-10 11:48:14 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee

抢购3-promoItemPrice拼写错误就整;前端页面;修Bug

This commit is contained in:
程序员小墨 2022-03-05 15:47:04 +08:00
parent e77065df5d
commit bad79611bf
7 changed files with 76 additions and 32 deletions

View File

@ -11,7 +11,7 @@
Target Server Version : 50726
File Encoding : 65001
Date: 05/03/2022 12:39:01
Date: 05/03/2022 15:19:32
*/
SET NAMES utf8mb4;
@ -108,8 +108,9 @@ CREATE TABLE `promo_info` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`promo_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
`start_date` datetime NOT NULL DEFAULT '0000-01-01 00:00:00',
`end_date` datetime NOT NULL DEFAULT '0000-01-01 00:00:00',
`item_id` int(11) NOT NULL DEFAULT 0,
`prome_item_price` decimal(10, 2) NOT NULL DEFAULT 0.00,
`promo_item_price` decimal(10, 2) NOT NULL DEFAULT 0.00,
PRIMARY KEY (`id`) USING BTREE,
INDEX `item_id`(`item_id`) USING BTREE,
CONSTRAINT `promo_info_ibfk_1` FOREIGN KEY (`item_id`) REFERENCES `item_info` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT
@ -118,7 +119,7 @@ CREATE TABLE `promo_info` (
-- ----------------------------
-- Records of promo_info
-- ----------------------------
INSERT INTO `promo_info` VALUES (1, '小米手机抢购活动', '2022-03-05 14:00:00', 1, 1999.00);
INSERT INTO `promo_info` VALUES (1, '小米手机抢购活动', '2022-03-05 14:00:00', '2022-03-05 16:00:00', 5, 1999.00);
-- ----------------------------
-- Table structure for sequence_info

View File

@ -11,6 +11,12 @@
<body class="login">
<div class="content">
<h3 class="form-title">商品详情</h3>
<div id="promoStartDateContainer" class="from-group">
<label style="color: blue;" id="promoStatus" class="control-label"></label>
<div>
<label style="color: red;" class="control-label" id="promoStartDate">
</div>
</div>
<div class="from-group">
<div>
<label class="control-label" id="title">
@ -28,6 +34,12 @@
<label class="control-label" id="price">
</div>
</div>
<div id="promoPriceContainer" class="from-group">
<label class="control-label">秒杀价格</label>
<div>
<label style="color: red;" class="control-label" id="promoPrice">
</div>
</div>
<div class="from-group">
<img id="imgUrl" src="" style="width: 200px; height: auto;"/>
</div>
@ -77,6 +89,7 @@
if (data.status == "success") {
g_itemVO = data.data;
reloadDom();
setInterval(reloadDom, 300);
} else {
alert("获取信息失败,原因为" + data.data.errMsg);
}
@ -122,6 +135,28 @@
$("#price").text(g_itemVO.price);
$("#imgUrl").attr("src", g_itemVO.imgUrl);
$("#sales").text(g_itemVO.sales);
if (g_itemVO.promoStatus == 1) {
// 秒杀活动还未开始
var startTime = g_itemVO.startDate.replace(new RegExp("-", "gm"), "/");
startTime = new Date(startTime).getTime();
var nowTime = Date.parse(new Date());
var delta = (startTime - nowTime) / 1000;
if (delta < 1) {
// 活动开始了
g_itemVO.promoStatus = 2;
reloadDom();
}
$("#promoStartDate").text("秒杀活动将于 " + g_itemVO.startDate + " 开始" +
"倒计时:" + delta + "s");
$("#promoPrice").text(g_itemVO.promoPrice);
$("#createorder").attr("disabled", true);
} else if (g_itemVO.promoStatus == 2) {
$("#promoStartDate").text("秒杀正在进行中");
$("#promoPrice").text(g_itemVO.promoPrice);
$("#createorder").attr("disabled", false);
}
}
</script>
</body>

View File

@ -5,12 +5,15 @@ import com.cxyxiaomo.flashsale.error.BusinessException;
import com.cxyxiaomo.flashsale.response.CommonReturnType;
import com.cxyxiaomo.flashsale.service.ItemService;
import com.cxyxiaomo.flashsale.service.model.ItemModel;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.math.BigDecimal;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.stream.Collectors;
@ -80,7 +83,7 @@ public class ItemController extends BaseController {
// 有正在进行或即将进行的秒杀活动
itemVO.setPromoStatus(itemModel.getPromoModel().getStatus());
itemVO.setPromoId(itemModel.getId());
itemVO.setStartDate(itemModel.getPromoModel().getStartDate());
itemVO.setStartDate(itemModel.getPromoModel().getStartDate().toString(DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss")));
itemVO.setPromoPrice(itemModel.getPromoModel().getPromoPrice());
} else {
itemVO.setPromoStatus(0);

View File

@ -1,7 +1,5 @@
package com.cxyxiaomo.flashsale.controller.viewobject;
import org.joda.time.DateTime;
import java.math.BigDecimal;
public class ItemVO {
@ -37,7 +35,7 @@ public class ItemVO {
private Integer promoId;
// 秒杀活动开始时间
private DateTime startDate;
private String startDate;
public Integer getId() {
return id;
@ -119,11 +117,11 @@ public class ItemVO {
this.promoId = promoId;
}
public DateTime getStartDate() {
public String getStartDate() {
return startDate;
}
public void setStartDate(DateTime startDate) {
public void setStartDate(String startDate) {
this.startDate = startDate;
}
}

View File

@ -52,11 +52,11 @@ public class PromoDO {
/**
*
* This field was generated by MyBatis Generator.
* This field corresponds to the database column promo_info.prome_item_price
* This field corresponds to the database column promo_info.promo_item_price
*
* @mbg.generated Sat Mar 05 12:55:23 CST 2022
*/
private BigDecimal promeItemPrice;
private BigDecimal promoItemPrice;
/**
* This method was generated by MyBatis Generator.
@ -180,25 +180,25 @@ public class PromoDO {
/**
* This method was generated by MyBatis Generator.
* This method returns the value of the database column promo_info.prome_item_price
* This method returns the value of the database column promo_info.promo_item_price
*
* @return the value of promo_info.prome_item_price
* @return the value of promo_info.promo_item_price
*
* @mbg.generated Sat Mar 05 12:55:23 CST 2022
*/
public BigDecimal getPromeItemPrice() {
return promeItemPrice;
public BigDecimal getPromoItemPrice() {
return promoItemPrice;
}
/**
* This method was generated by MyBatis Generator.
* This method sets the value of the database column promo_info.prome_item_price
* This method sets the value of the database column promo_info.promo_item_price
*
* @param promeItemPrice the value for promo_info.prome_item_price
* @param promoItemPrice the value for promo_info.promo_item_price
*
* @mbg.generated Sat Mar 05 12:55:23 CST 2022
*/
public void setPromeItemPrice(BigDecimal promeItemPrice) {
this.promeItemPrice = promeItemPrice;
public void setPromoItemPrice(BigDecimal promoItemPrice) {
this.promoItemPrice = promoItemPrice;
}
}

View File

@ -7,7 +7,9 @@ import com.cxyxiaomo.flashsale.service.model.PromoModel;
import org.joda.time.DateTime;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class PromoServiceImpl implements PromoService {
@Autowired
@ -16,11 +18,15 @@ public class PromoServiceImpl implements PromoService {
@Override
public PromoModel getPromoByItemId(Integer itemId) {
// 获取对应商品的秒杀活动信息
PromoDO promoDO = promoDOMapper.selectByPrimaryKey(itemId);
PromoDO promoDO = promoDOMapper.selectByItemId(itemId);
// Data Object -> Model
PromoModel promoModel = convertFromDataObject(promoDO);
if (promoModel == null) {
return null;
}
// 判断秒杀活动是否即将开始或正在进行
if (promoModel.getStartDate().isAfterNow()) {
promoModel.setStatus(1); // 还未开始
@ -39,6 +45,7 @@ public class PromoServiceImpl implements PromoService {
}
PromoModel promoModel = new PromoModel();
BeanUtils.copyProperties(promoDO, promoModel);
promoModel.setPromoPrice(promoDO.getPromoItemPrice());
promoModel.setStartDate(new DateTime(promoDO.getStartDate()));
promoModel.setEndDate(new DateTime(promoDO.getEndDate()));

View File

@ -12,7 +12,7 @@
<result column="start_date" jdbcType="TIMESTAMP" property="startDate" />
<result column="end_date" jdbcType="TIMESTAMP" property="endDate" />
<result column="item_id" jdbcType="INTEGER" property="itemId" />
<result column="prome_item_price" jdbcType="DECIMAL" property="promeItemPrice" />
<result column="promo_item_price" jdbcType="DECIMAL" property="promoItemPrice" />
</resultMap>
<sql id="Base_Column_List">
<!--
@ -20,7 +20,7 @@
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Sat Mar 05 12:55:23 CST 2022.
-->
id, promo_name, start_date, end_date, item_id, prome_item_price
id, promo_name, start_date, end_date, item_id, promo_item_price
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
<!--
@ -49,10 +49,10 @@
This element was generated on Sat Mar 05 12:55:23 CST 2022.
-->
insert into promo_info (id, promo_name, start_date,
end_date, item_id, prome_item_price
end_date, item_id, promo_item_price
)
values (#{id,jdbcType=INTEGER}, #{promoName,jdbcType=VARCHAR}, #{startDate,jdbcType=TIMESTAMP},
#{endDate,jdbcType=TIMESTAMP}, #{itemId,jdbcType=INTEGER}, #{promeItemPrice,jdbcType=DECIMAL}
#{endDate,jdbcType=TIMESTAMP}, #{itemId,jdbcType=INTEGER}, #{promoItemPrice,jdbcType=DECIMAL}
)
</insert>
<insert id="insertSelective" parameterType="com.cxyxiaomo.flashsale.dataobject.PromoDO">
@ -78,8 +78,8 @@
<if test="itemId != null">
item_id,
</if>
<if test="promeItemPrice != null">
prome_item_price,
<if test="promoItemPrice != null">
promo_item_price,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
@ -98,8 +98,8 @@
<if test="itemId != null">
#{itemId,jdbcType=INTEGER},
</if>
<if test="promeItemPrice != null">
#{promeItemPrice,jdbcType=DECIMAL},
<if test="promoItemPrice != null">
#{promoItemPrice,jdbcType=DECIMAL},
</if>
</trim>
</insert>
@ -123,8 +123,8 @@
<if test="itemId != null">
item_id = #{itemId,jdbcType=INTEGER},
</if>
<if test="promeItemPrice != null">
prome_item_price = #{promeItemPrice,jdbcType=DECIMAL},
<if test="promoItemPrice != null">
promo_item_price = #{promoItemPrice,jdbcType=DECIMAL},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
@ -140,10 +140,10 @@
start_date = #{startDate,jdbcType=TIMESTAMP},
end_date = #{endDate,jdbcType=TIMESTAMP},
item_id = #{itemId,jdbcType=INTEGER},
prome_item_price = #{promeItemPrice,jdbcType=DECIMAL}
promo_item_price = #{promoItemPrice,jdbcType=DECIMAL}
where id = #{id,jdbcType=INTEGER}
</update>
<select id="selectByItemId" resultMap="BaseResultMap">
<select id="selectByItemId" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from promo_info