|
|
@@ -0,0 +1,48 @@
|
|
|
+package com.example.cinema.bl;
|
|
|
+
|
|
|
+import com.example.cinema.data.VIPCardMapper;
|
|
|
+import com.example.cinema.form.VIPCardForm;
|
|
|
+import com.example.cinema.po.VIPCard;
|
|
|
+import com.example.cinema.strategy.ChargeStrategy;
|
|
|
+import com.example.cinema.vo.ResponseVO;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by liying on 2019/4/14.
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class VIPServiceImpl implements VIPService {
|
|
|
+ @Autowired
|
|
|
+ VIPCardMapper vipCardMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResponseVO addVIPCard(VIPCardForm vipCardForm, ChargeStrategy chargeStrategy) {
|
|
|
+ VIPCard vipCard=new VIPCard();
|
|
|
+ vipCard.setUserId(vipCardForm.getUserId());
|
|
|
+ if(vipCardForm.getAmount()<VIPCard.price){
|
|
|
+ return ResponseVO.buildFailure("充值金额不足,无法完成");
|
|
|
+ }
|
|
|
+ vipCard.setBalance(chargeStrategy.calculate(vipCardForm.getAmount())-VIPCard.price);
|
|
|
+ try {
|
|
|
+ return ResponseVO.buildSuccess(vipCardMapper.insertOneCard(vipCard));
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return ResponseVO.buildFailure("失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResponseVO getCardById(int id) {
|
|
|
+ VIPCard vipCard=vipCardMapper.selectCardById(id);
|
|
|
+ try {
|
|
|
+ return ResponseVO.buildSuccess(vipCardMapper.selectCardById(id));
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return ResponseVO.buildFailure("失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|