根据id查询SuccessKilled并携带秒杀产品对象实体必须修改成[[根据id和userPhone查询SuccessKilled并携带秒杀产品对象实体]]
关于数据库两张表设计上的问题和不足,希望各位仁人志士能给出解决方案.
现在情况是:同一个商品id,不同的手机号,去执行秒杀,在插入秒杀记录表时候报错:Expected one result (or null) to be returned by selectOne(), but found: 2
首先说下:老师表示这么设计的seckill商品表有唯一主键seckill_id,success_killed秒杀记录里面有seckill_id和user_phone两个联合主键.
联合主键设计的愿望实现了:当同一个手机号不能同时一个商品多次,解决了重复秒杀的问题,但是,可有想过这个问题.不同手机号能秒杀多个商品?
这条sql(
queryByIdWithSeckill
)就有问题了,要改成:
/** * 根据id和userPhone查询SuccessKilled并携带秒杀产品对象实体 * * @param seckillId * @return */ SuccessKilled queryByIdWithSeckill(long seckillId, long userPhone);
SELECT
sk.seckill_id,
sk.user_phone,
sk.create_time,
sk.state,
s.seckill_id AS "seckill.seckill_id",
s.name AS "seckill.name",
s.number AS "seckill.number",
s.start_time AS "seckill.start_time",
s.end_time AS "seckill.end_time",
s.create_time AS "seckill.create_time"
FROM success_killed sk RIGHT JOIN seckill s ON sk.seckill_id = s.seckill_id
WHERE sk.seckill_id = 5
and sk.user_phone = 18617151927