Parcourir la source

[新增]发布优惠活动接口

liying il y a 7 ans
Parent
commit
42815e23bf

+ 18 - 0
src/main/java/com/example/cinema/bl/ActivityService.java

@@ -0,0 +1,18 @@
+package com.example.cinema.bl;
+
+import com.example.cinema.vo.ActivityForm;
+import com.example.cinema.vo.ResponseVO;
+
+/**
+ * Created by liying on 2019/4/20.
+ */
+public interface ActivityService {
+    
+    ResponseVO publishActivity(ActivityForm activityForm);
+
+    ResponseVO getActivities();
+
+
+
+
+}

+ 56 - 0
src/main/java/com/example/cinema/blImpl/ActivityServiceImpl.java

@@ -0,0 +1,56 @@
+package com.example.cinema.blImpl;
+
+import com.example.cinema.bl.ActivityService;
+import com.example.cinema.bl.CouponService;
+import com.example.cinema.data.ActivityMapper;
+import com.example.cinema.po.Activity;
+import com.example.cinema.po.Coupon;
+import com.example.cinema.vo.ActivityForm;
+import com.example.cinema.vo.ResponseVO;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ * Created by liying on 2019/4/20.
+ */
+@Service
+public class ActivityServiceImpl implements ActivityService {
+
+    @Autowired
+    ActivityMapper activityMapper;
+    @Autowired
+    CouponService couponService;
+
+    @Override
+    @Transactional
+    public ResponseVO publishActivity(ActivityForm activityForm) {
+        try {
+            ResponseVO vo = couponService.addCoupon(activityForm.getCouponForm());
+            Coupon coupon = (Coupon) vo.getContent();
+            Activity activity = new Activity();
+            activity.setName(activityForm.getName());
+            activity.setDescription(activityForm.getName());
+            activity.setStartTime(activityForm.getStartTime());
+            activity.setEndTime(activityForm.getEndTime());
+            activity.setCouponId(coupon.getId());
+            activityMapper.insertActivity(activity);
+            activityMapper.insertActivityAndMovie(activity.getId(), activityForm.getMovieList());
+            return ResponseVO.buildSuccess(activityMapper.selectById(activity.getId()));
+        } catch (Exception e) {
+            e.printStackTrace();
+            return ResponseVO.buildFailure("失败");
+        }
+    }
+
+    @Override
+    public ResponseVO getActivities() {
+        try {
+            return ResponseVO.buildSuccess(activityMapper.selectActivities());
+        } catch (Exception e) {
+            e.printStackTrace();
+            return ResponseVO.buildFailure("失败");
+        }
+    }
+
+}

+ 9 - 3
src/main/java/com/example/cinema/blImpl/TicketServiceImpl.java

@@ -31,6 +31,8 @@ public class TicketServiceImpl implements TicketService {
     CouponMapper couponMapper;
     @Autowired
     HallMapper hallmapper;
+    @Autowired
+    ActivityMapper activityMapper;
 
     @Override
     @Transactional
@@ -67,6 +69,7 @@ public class TicketServiceImpl implements TicketService {
             if (couponId != 0) {
                 couponMapper.deleteCouponUser(couponId, tickets.get(0).getUserId());
             }
+
             return ResponseVO.buildSuccess(tickets.stream().map(ticket -> ticket.getVO()).collect(Collectors.toList()));
         } catch (Exception e) {
             e.printStackTrace();
@@ -78,13 +81,16 @@ public class TicketServiceImpl implements TicketService {
     public ResponseVO getBySchedule(int scheduleId) {
         try {
             List<Ticket> tickets = ticketMapper.selectTicketsBySchedule(scheduleId);
-            ScheduleItem scheduleForm=scheduleMapper.selectScheduleById(scheduleId);
-            HallVO hall=hallmapper.selectHallById(scheduleForm.getHallId());
+            ScheduleItem schedule=scheduleMapper.selectScheduleById(scheduleId);
+            HallVO hall=hallmapper.selectHallById(schedule.getHallId());
             int[][] seats=new int[hall.getRow()][hall.getColumn()];
             tickets.stream().forEach(ticket -> {
                 seats[ticket.getRowIndex()][ticket.getColumnIndex()]=1;
             });
-            return ResponseVO.buildSuccess(seats);
+            ScheduleWithSeatVO scheduleWithSeatVO=new ScheduleWithSeatVO();
+            scheduleWithSeatVO.setScheduleItem(schedule);
+            scheduleWithSeatVO.setSeats(seats);
+            return ResponseVO.buildSuccess(scheduleWithSeatVO);
         } catch (Exception e) {
             e.printStackTrace();
             return ResponseVO.buildFailure("失败");

+ 30 - 0
src/main/java/com/example/cinema/controller/ActivityController.java

@@ -0,0 +1,30 @@
+package com.example.cinema.controller;
+
+import com.example.cinema.bl.ActivityService;
+import com.example.cinema.vo.ActivityForm;
+import com.example.cinema.vo.ResponseVO;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+
+/**
+ * Created by liying on 2019/4/20.
+ */
+@RestController
+@RequestMapping("/activity")
+public class ActivityController {
+
+    @Autowired
+    ActivityService activityService;
+
+    @PostMapping("/publish")
+    public ResponseVO publishActivity(@RequestBody ActivityForm activityForm){
+        return activityService.publishActivity(activityForm);
+    }
+    @GetMapping("/get")
+    public ResponseVO getActivities(){
+        return activityService.getActivities();
+    }
+
+
+}

+ 0 - 1
src/main/java/com/example/cinema/controller/CouponController.java

@@ -25,5 +25,4 @@ public class CouponController {
 
 
 
-
 }

+ 27 - 0
src/main/java/com/example/cinema/data/ActivityMapper.java

@@ -0,0 +1,27 @@
+package com.example.cinema.data;
+
+import com.example.cinema.po.Activity;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * Created by liying on 2019/4/20.
+ */
+@Mapper
+public interface ActivityMapper {
+
+    int insertActivity(Activity activity);
+
+    int insertActivityAndMovie(@Param("activityId") int activityId,@Param("movieId") List<Integer> movieId);
+
+    List<Activity> selectActivities();
+
+    List<Activity> selectActivitiesByMovie(int movieId);
+
+    Activity selectById(int id);
+
+
+
+}

+ 93 - 0
src/main/java/com/example/cinema/data/ActivityMapper.xml

@@ -0,0 +1,93 @@
+<?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="com.example.cinema.data.ActivityMapper">
+    <insert id="insertActivity" parameterType="com.example.cinema.po.Activity"
+            useGeneratedKeys="true" keyProperty="id">
+        insert into activity(description,name,coupon_id,start_time,end_time)
+        values(#{description},#{name},#{couponId},#{startTime},#{endTime})
+    </insert>
+    <insert id="insertActivityAndMovie">
+        insert into activity_movie(activity_id,movie_id) values
+        <foreach collection="movieId" item="item" index="index"
+                 separator=",">
+            (#{activityId},#{item})
+        </foreach>
+    </insert>
+    <select id="selectById" resultMap="Activity">
+        select
+            *
+        from
+            activity a
+        inner join
+            activity_movie am
+        on
+            a.id=am.activity_id
+        inner join
+            movie m
+        on
+            am.movie_id=m.id
+        WHERE a.id=#{id}
+    </select>
+
+    <select id="selectActivities" resultMap="Activity">
+        select
+            *
+        from
+            activity a
+        inner join
+            activity_movie am
+        on
+            a.id=am.activity_id
+        inner join
+            movie m
+        on
+            am.movie_id=m.id
+
+    </select>
+
+    <select id="selectActivitiesByMovie" resultMap="Activity">
+        select
+        *
+        from
+        activity a
+        inner join
+        activity_movie am
+        on
+        a.id=am.activity_id
+        inner join
+        movie m
+        on
+        am.movie_id=m.id
+
+        where a.start_time &lt; Now() and a.end_time &gt; Now() and am.movie_id=#{movieId}
+
+    </select>
+
+
+    <resultMap id="Activity" type="com.example.cinema.vo.ActivityVO">
+        <result column="description" property="description"></result>
+        <result column="id" property="id"></result>
+        <result column="name" property="name"></result>
+        <result column="start_time" property="startTime"></result>
+        <result column="end_time" property="endTime"></result>
+        <association property="coupon" column="coupon_id" select="com.example.cinema.data.CouponMapper.selectById">
+        </association>
+        <collection property="movieList" ofType="com.example.cinema.vo.MovieVO">
+            <id column="id" property="id"></id>
+            <result column="poster_url" property="posterUrl"></result>
+            <result column="screen_writer" property="screenWriter"></result>
+            <result column="start_date" property="startDate"></result>
+            <result column="end_date" property="endDate"></result>
+            <result column="name" property="name"></result>
+            <result column="director" property="director"></result>
+            <result column="type" property="type"></result>
+            <result column="country" property="country"></result>
+            <result column="language" property="language"></result>
+            <result column="length" property="length"></result>
+            <result column="description" property="description"></result>
+            <result column="status" property="status"></result>
+            <result column="starring" property="starring"></result>
+        </collection>
+    </resultMap>
+
+</mapper>

+ 88 - 0
src/main/java/com/example/cinema/po/Activity.java

@@ -0,0 +1,88 @@
+package com.example.cinema.po;
+
+import com.example.cinema.vo.CouponForm;
+import com.example.cinema.vo.MovieForm;
+
+import java.sql.Timestamp;
+import java.util.List;
+
+/**
+ * Created by liying on 2019/4/20.
+ */
+public class Activity {
+
+    private int id;
+    /**
+     * 优惠活动名称
+     */
+    private String name;
+    /**
+     * 优惠活动描述
+     */
+    private String description;
+    /**
+     * 优惠活动开始时间
+     */
+    private Timestamp startTime;
+    /**
+     * 优惠活动截止时间
+     */
+    private Timestamp endTime;
+    /**
+     * 优惠券id
+     */
+    private int couponId;
+
+    public Activity() {
+
+    }
+
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public int getCouponId() {
+        return couponId;
+    }
+
+    public void setCouponId(int couponId) {
+        this.couponId = couponId;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    public Timestamp getStartTime() {
+        return startTime;
+    }
+
+    public void setStartTime(Timestamp startTime) {
+        this.startTime = startTime;
+    }
+
+    public Timestamp getEndTime() {
+        return endTime;
+    }
+
+    public void setEndTime(Timestamp endTime) {
+        this.endTime = endTime;
+    }
+
+}

+ 87 - 0
src/main/java/com/example/cinema/vo/ActivityForm.java

@@ -0,0 +1,87 @@
+package com.example.cinema.vo;
+
+import java.sql.Timestamp;
+import java.util.List;
+
+/**
+ * Created by liying on 2019/4/20.
+ */
+public class ActivityForm {
+    /**
+     * 优惠活动名称
+     */
+    private String name;
+    /**
+     * 优惠活动描述
+     */
+    private String description;
+    /**
+     * 优惠活动开始时间
+     */
+    private Timestamp startTime;
+    /**
+     * 优惠活动截止时间
+     */
+    private Timestamp endTime;
+    /**
+     * 优惠电影列表
+     */
+    private List<Integer> movieList;
+    /**
+     * 优惠券规格
+     */
+    private CouponForm couponForm;
+
+
+    public ActivityForm() {
+
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    public Timestamp getStartTime() {
+        return startTime;
+    }
+
+    public void setStartTime(Timestamp startTime) {
+        this.startTime = startTime;
+    }
+
+    public Timestamp getEndTime() {
+        return endTime;
+    }
+
+    public void setEndTime(Timestamp endTime) {
+        this.endTime = endTime;
+    }
+
+    public List<Integer> getMovieList() {
+        return movieList;
+    }
+
+    public void setMovieList(List<Integer> movieList) {
+        this.movieList = movieList;
+    }
+
+    public CouponForm getCouponForm() {
+        return couponForm;
+    }
+
+    public void setCouponForm(CouponForm couponForm) {
+        this.couponForm = couponForm;
+    }
+}

+ 99 - 0
src/main/java/com/example/cinema/vo/ActivityVO.java

@@ -0,0 +1,99 @@
+package com.example.cinema.vo;
+
+import com.example.cinema.po.Coupon;
+
+import java.sql.Timestamp;
+import java.util.List;
+
+/**
+ * Created by liying on 2019/4/20.
+ */
+public class ActivityVO {
+
+    private int id;
+    /**
+     * 优惠活动名称
+     */
+    private String name;
+    /**
+     * 优惠活动描述
+     */
+    private String description;
+    /**
+     * 优惠活动开始时间
+     */
+    private Timestamp startTime;
+    /**
+     * 优惠活动截止时间
+     */
+    private Timestamp endTime;
+    /**
+     * 优惠电影列表
+     */
+    private List<MovieVO> movieList;
+    /**
+     * 优惠券规格
+     */
+    private Coupon coupon;
+
+
+    public ActivityVO() {
+
+    }
+
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    public Timestamp getStartTime() {
+        return startTime;
+    }
+
+    public void setStartTime(Timestamp startTime) {
+        this.startTime = startTime;
+    }
+
+    public Timestamp getEndTime() {
+        return endTime;
+    }
+
+    public void setEndTime(Timestamp endTime) {
+        this.endTime = endTime;
+    }
+
+    public List<MovieVO> getMovieList() {
+        return movieList;
+    }
+
+    public void setMovieList(List<MovieVO> movieList) {
+        this.movieList = movieList;
+    }
+
+    public Coupon getCoupon() {
+        return coupon;
+    }
+
+    public void setCoupon(Coupon coupon) {
+        this.coupon = coupon;
+    }
+}

+ 31 - 0
src/main/java/com/example/cinema/vo/ScheduleWithSeatVO.java

@@ -0,0 +1,31 @@
+package com.example.cinema.vo;
+
+/**
+ * Created by liying on 2019/4/21.
+ */
+public class ScheduleWithSeatVO {
+    /**
+     * 排片
+     */
+    private ScheduleItem  scheduleItem;
+    /**
+     * 座位
+     */
+    private int[][] seats;
+
+    public ScheduleItem getScheduleItem() {
+        return scheduleItem;
+    }
+
+    public void setScheduleItem(ScheduleItem scheduleItem) {
+        this.scheduleItem = scheduleItem;
+    }
+
+    public int[][] getSeats() {
+        return seats;
+    }
+
+    public void setSeats(int[][] seats) {
+        this.seats = seats;
+    }
+}