Commit bb2904bb3b39814f3184753877b0d199d5c830f4

Authored by 王言钊
1 parent 7de26c70

增加 活动导入Api接口

src/main/java/com/cnlive/shenhe/api/ShyActivityControllerApi.java 0 → 100644
  1 +package com.cnlive.shenhe.api;
  2 +
  3 +import com.alibaba.fastjson.JSON;
  4 +import com.alibaba.fastjson.JSONObject;
  5 +import com.cnlive.shenhe.bean.ErrorEnum;
  6 +import com.cnlive.shenhe.bean.ResponseBean;
  7 +import com.cnlive.shenhe.entity.ShyActivity;
  8 +import com.cnlive.shenhe.serviceImpl.ShyActivityImpl;
  9 +import org.slf4j.Logger;
  10 +import org.slf4j.LoggerFactory;
  11 +import org.springframework.beans.factory.annotation.Autowired;
  12 +import org.springframework.stereotype.Controller;
  13 +import org.springframework.web.bind.annotation.PostMapping;
  14 +import org.springframework.web.bind.annotation.RequestMapping;
  15 +import org.springframework.web.bind.annotation.ResponseBody;
  16 +
  17 +import java.util.Date;
  18 +
  19 +/**
  20 + * @Author: yan-zhao-wang
  21 + * @DateTime: 2022-06-14 9:18
  22 + * 活动导入Api接口
  23 + */
  24 +@Controller
  25 +@RequestMapping("/api/activity")
  26 +public class ShyActivityControllerApi {
  27 +
  28 + private static Logger logger = LoggerFactory.getLogger(ShyActivityControllerApi.class);
  29 +
  30 + @Autowired
  31 + private ShyActivityImpl shyActivityImpl;
  32 +
  33 + @PostMapping("/import")
  34 + @ResponseBody
  35 + public ResponseBean insterShyActivity(String param) {
  36 + logger.info("活动添加,param====={}", param);
  37 + // 转换JSON对象
  38 + JSONObject json = JSONObject.parseObject(param);
  39 + Integer id = json.getInteger("id");
  40 + String activity = json.getString("activity");
  41 + // 封装对象
  42 + ShyActivity shyActivity = new ShyActivity();
  43 + shyActivity.setId(id);
  44 + shyActivity.setActivity(activity);
  45 + shyActivity.setCreate_time(new Date());
  46 + shyActivity.setUpdate_time(new Date());
  47 + shyActivity.setExempt_from_trial(0);
  48 + logger.info("封装对象为,{}", JSON.toJSON(shyActivity));
  49 + // 根据id查询是否存在
  50 + ShyActivity shyActivityObj = shyActivityImpl.selectById(id);
  51 + // 如果对象不存在,就直接添加
  52 + if (shyActivityObj == null) {
  53 + int result = shyActivityImpl.insertShyActivity(shyActivity);
  54 + if (result > 0) {
  55 + return new ResponseBean(ErrorEnum.SUCCESS.getErrorCode(), "当前活动添加成功");
  56 + }
  57 + return new ResponseBean(ErrorEnum.ERROR.getErrorCode(), "当前活动添加失败,请重试");
  58 + }
  59 + // 如果对象不存在,就直接返回错误码
  60 + return new ResponseBean(ErrorEnum.ERROR.getErrorCode(), "当前活动id已存在,请更换id重试");
  61 + }
  62 +}
src/main/java/com/cnlive/shenhe/controller/LiveController.java
@@ -259,8 +259,8 @@ public class LiveController extends BaseController { @@ -259,8 +259,8 @@ public class LiveController extends BaseController {
259 } 259 }
260 260
261 /** 261 /**
262 - * 打回(审核拒绝)  
263 - * 262 + * 打回(审核通过、拒绝、强制下线)
  263 + * status 3、4、6
264 * @param ids 264 * @param ids
265 * @param msg 265 * @param msg
266 * @param session 266 * @param session
src/main/java/com/cnlive/shenhe/mapper/ShyActivityMapper.java
@@ -9,5 +9,17 @@ import java.util.List; @@ -9,5 +9,17 @@ import java.util.List;
9 public interface ShyActivityMapper extends Mapper<ShyActivity> { 9 public interface ShyActivityMapper extends Mapper<ShyActivity> {
10 10
11 11
  12 + /**
  13 + * 根据免审状态查询
  14 + * @param exempt_from_trial
  15 + * @return
  16 + */
12 List<Integer> selectAllByExempt_from_trial(@Param("exempt_from_trial") Integer exempt_from_trial); 17 List<Integer> selectAllByExempt_from_trial(@Param("exempt_from_trial") Integer exempt_from_trial);
  18 +
  19 + /**
  20 + * 根据id查询是否存在该对象
  21 + * @param id
  22 + * @return
  23 + */
  24 + ShyActivity selectById(@Param("id")Integer id);
13 } 25 }
14 \ No newline at end of file 26 \ No newline at end of file
src/main/java/com/cnlive/shenhe/serviceImpl/ShyActivityImpl.java
@@ -123,5 +123,12 @@ public class ShyActivityImpl { @@ -123,5 +123,12 @@ public class ShyActivityImpl {
123 List<ShyActivity> shyActivities = shyActivityMapper.selectAll(); 123 List<ShyActivity> shyActivities = shyActivityMapper.selectAll();
124 return shyActivities; 124 return shyActivities;
125 } 125 }
  126 + /**
  127 + * 根据id查询单个对象
  128 + */
  129 + public ShyActivity selectById(Integer id){
  130 + ShyActivity shyActivity = shyActivityMapper.selectById(id);
  131 + return shyActivity;
  132 + }
126 133
127 } 134 }
src/main/resources/mapper/ShyActivityMapper.xml
@@ -14,6 +14,9 @@ @@ -14,6 +14,9 @@
14 <select id="selectAllByExempt_from_trial" resultType="java.lang.Integer"> 14 <select id="selectAllByExempt_from_trial" resultType="java.lang.Integer">
15 select id from shy_activity where exempt_from_trial=${exempt_from_trial}; 15 select id from shy_activity where exempt_from_trial=${exempt_from_trial};
16 </select> 16 </select>
  17 + <select id="selectById" resultType="com.cnlive.shenhe.entity.ShyActivity">
  18 + select * from shy_activity where id=${id}
  19 + </select>
17 20
18 21
19 </mapper> 22 </mapper>
20 \ No newline at end of file 23 \ No newline at end of file