Преглед на файлове

获取音柱列表、音乐列表、节目列表接口

zhj преди 2 години
родител
ревизия
85ed471e5e

+ 79 - 0
src/main/java/com/welampiot/controller/BroadcastController.java

@@ -0,0 +1,79 @@
+package com.welampiot.controller;
+
+import com.welampiot.common.BaseResult;
+import com.welampiot.dto.BroadcastDTO;
+import com.welampiot.dto.BroadcastItemDTO;
+import com.welampiot.dto.BroadcastProListDTO;
+import com.welampiot.service.BroadcastService;
+import com.welampiot.utils.ToolUtils;
+import com.welampiot.vo.BroadcastItemVO;
+import com.welampiot.vo.BroadcastProListVO;
+import com.welampiot.vo.BroadcastVO;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.CrossOrigin;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * ClassName: BroadcastController
+ * Package: com.welampiot.controller
+ * Description:
+ *
+ * @Author: zhj_Start
+ * @Create: 2023/4/17 - 11:38
+ * @Version: v1.0
+ */
+@RestController
+@CrossOrigin
+@RequestMapping("/api/broadcast")
+public class BroadcastController {
+    @Autowired
+    private BroadcastService broadcastService;
+
+    @Autowired
+    private ToolUtils toolUtils;
+
+    /**
+     * 获取音柱列表
+     * @param request
+     * @return
+     */
+    @RequestMapping(value = "/devList", method = RequestMethod.POST)
+    public BaseResult<BroadcastDTO> devList(HttpServletRequest request){
+        Integer online = request.getParameter("online") == null ? 0 : Integer.parseInt(request.getParameter("online"));
+        BroadcastDTO dto = new BroadcastDTO();
+        dto.setOnlineState(online);
+        dto.setSectionList(toolUtils.getSectionList(request));
+
+        BroadcastVO vo = broadcastService.getDevListByBroadcastDTO(dto);
+        return BaseResult.success(vo);
+    }
+
+    /**
+     * 获取音乐列表
+     * @param request
+     * @return
+     */
+    @RequestMapping(value = "/proList", method = RequestMethod.POST)
+    public BaseResult<BroadcastProListDTO> proList(HttpServletRequest request){
+        String username = request.getParameter("username") == null ? "" : request.getParameter("username");
+        BroadcastProListVO vo = broadcastService.getProListByDTO(username);
+        return BaseResult.success(vo);
+    }
+
+    /**
+     * 获取节目列表
+     * @param request
+     * @return
+     */
+    @RequestMapping(value = "/itemList", method = RequestMethod.POST)
+    public BaseResult<BroadcastItemDTO> itemList(HttpServletRequest request){
+        String username = request.getParameter("username") == null ? "" : request.getParameter("username");
+        Integer devId = request.getParameter("devId") == null ? 0 : Integer.parseInt(request.getParameter("devId"));
+        BroadcastItemVO vo = broadcastService.getItemListByDTO(username, devId);
+        return BaseResult.success(vo);
+    }
+}

+ 31 - 0
src/main/java/com/welampiot/dao/BroadcastDao.java

@@ -0,0 +1,31 @@
+package com.welampiot.dao;
+
+import com.welampiot.dto.BroadcastDTO;
+import com.welampiot.dto.BroadcastItemDTO;
+import com.welampiot.dto.BroadcastProListDTO;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * ClassName: BroadcastDao
+ * Package: com.welampiot.dao
+ * Description:
+ *
+ * @Author: zhj_Start
+ * @Create: 2023/4/17 - 11:11
+ * @Version: v1.0
+ */
+public interface BroadcastDao {
+    List<BroadcastDTO> getDevListByBroadcastDTO(BroadcastDTO dto);
+
+    Integer getTotalBySectionList(BroadcastDTO dto);
+
+    Integer getOnlineTotalBySectionList(BroadcastDTO dto);
+
+    Integer getUserIdByUserName(@Param("username") String username);
+
+    List<BroadcastProListDTO> getProListByDTO(@Param("userId") Integer userId);
+
+    List<BroadcastItemDTO> getItemListByDTO(@Param("userId") Integer userId, @Param("devId") Integer devId);
+}

+ 80 - 0
src/main/java/com/welampiot/dto/BroadcastDTO.java

@@ -0,0 +1,80 @@
+package com.welampiot.dto;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * ClassName: BroadcastDTO
+ * Package: com.welampiot.dto
+ * Description:
+ *
+ * @Author: zhj_Start
+ * @Create: 2023/4/17 - 10:27
+ * @Version: v1.0
+ */
+@Data
+public class BroadcastDTO implements Serializable {
+    /** 主键 **/
+    private Integer id;
+
+    /** 灯杆id **/
+    private Integer lampPoleId;
+
+    /** 设备地址 **/
+    private String address;
+
+    /** 设备创建时间 **/
+    private String createTime;
+
+    /** 设备在线状态 **/
+    private Integer online;
+
+    /** 设备名称 **/
+    private String name;
+
+    /** 设备音量值 **/
+    private Integer vol;
+
+    /** 当前播放素材id **/
+    private Integer proId;
+
+    /** 播放状态(0 停止,1 播放)**/
+    private Integer isPlay;
+
+    /** 策略id **/
+    private Integer policyId;
+
+    /** 世邦音柱设备密码 **/
+    private String pwd;
+
+    /** 世邦或者先科设备id **/
+    private Integer devId;
+
+    /** 设备类型(0 云之声,1 世邦,2 先科)**/
+    private Integer type;
+
+    /** IP地址 **/
+    private String ipAddr;
+
+    /** 当前播放的节目id **/
+    private Integer itemId;
+
+    /** 安装时间 **/
+    private String installDate;
+
+    /** 过期时间 **/
+    private String expirationDate;
+
+    /** 设别播放素材名 **/
+    private String proName;
+
+    private String lampPoleName;
+
+    private Integer onlineState;
+
+    private List<Integer> sectionList;
+
+    private static final long serialVersionUID = 1L;
+}

+ 103 - 0
src/main/java/com/welampiot/dto/BroadcastItemDTO.java

@@ -0,0 +1,103 @@
+package com.welampiot.dto;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * ClassName: BroadcastItemDTO
+ * Package: com.welampiot.dto
+ * Description:
+ *
+ * @Author: zhj_Start
+ * @Create: 2023/4/17 - 15:05
+ * @Version: v1.0
+ */
+@Data
+public class BroadcastItemDTO implements Serializable {
+    /** 主键 **/
+    private Integer id;
+
+    /** 音柱id,多个用逗号隔开 **/
+    private String broadCastId;
+
+    /** 音乐id **/
+    private Integer proId;
+
+    /** 节目名称 **/
+    private String name;
+
+    /** 用户id **/
+    private Integer userId;
+
+    /** 音乐1 **/
+    private Integer proId1;
+    /** 音乐2 **/
+    private Integer proId2;
+
+    /** 音乐3 **/
+    private Integer proId3;
+
+    /** 音乐4 **/
+    private Integer proId4;
+
+    /** 音乐5 **/
+    private Integer proId5;
+
+    /** 音乐6 **/
+    private Integer proId6;
+
+    /** 音乐7 **/
+    private Integer proId7;
+
+    /** 音乐8 **/
+    private Integer proId8;
+
+    /** 音乐9 **/
+    private Integer proId9;
+
+    /** 音乐10 **/
+    private Integer proId10;
+
+    /** 播放类型(0 顺序播放,1 循环播放,2 随机播放) **/
+    private Integer playType;
+
+    /** 世邦节目id **/
+    private Integer taskId;
+
+    /** 节目类型(0 普通节目,1 策略节目)**/
+    private Integer proType;
+
+    /** 策略类型(0 按日期,1 按星期)**/
+    private Integer policyType;
+
+    /** 创建时间 **/
+    private String createTime;
+
+    /** 节目开关状态 **/
+    private Integer status;
+
+    /** 世邦快速任务返回值 **/
+    private String guid;
+
+    private String number;
+
+    /** 先科节目id **/
+    private Integer xianKeId;
+
+    /** 先科方案id **/
+    private Integer programmeId;
+
+    /** 先科任务id **/
+    private Integer planId;
+
+    private String taskId2;
+
+    /** 威尔西任务id **/
+    private String weiErXiId;
+
+    /** 节目名称 **/
+    private String broadcastStr;
+
+    private static final long serialVersionUID = 1L;
+}

+ 50 - 0
src/main/java/com/welampiot/dto/BroadcastProListDTO.java

@@ -0,0 +1,50 @@
+package com.welampiot.dto;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * ClassName: BroadcastProListDTO
+ * Package: com.welampiot.dto
+ * Description:
+ *
+ * @Author: zhj_Start
+ * @Create: 2023/4/17 - 14:10
+ * @Version: v1.0
+ */
+@Data
+public class BroadcastProListDTO implements Serializable {
+    /** 主键 **/
+    private Integer id;
+
+    /** 节目名称 **/
+    private String name;
+
+    /** 节目文件路径地址 **/
+    private String url;
+
+    /** 创建人员id **/
+    private Integer userId;
+
+    /** 音乐时长 **/
+    private Integer time;
+
+    /** 世邦音柱音乐素材名称 **/
+    private String shiBangName;
+
+    /** 先科音乐素材名称 **/
+    private String xianKeName;
+
+    /** 先科素材id **/
+    private String xianKeId;
+
+    private Integer status;
+
+    private String xinChangShiBangUrl;
+
+    /** 威尔西设备素材id **/
+    private Integer weiErXiId;
+
+    private static final long serialVersionUID = 1L;
+}

+ 23 - 0
src/main/java/com/welampiot/service/BroadcastService.java

@@ -0,0 +1,23 @@
+package com.welampiot.service;
+
+import com.welampiot.dto.BroadcastDTO;
+import com.welampiot.vo.BroadcastItemVO;
+import com.welampiot.vo.BroadcastProListVO;
+import com.welampiot.vo.BroadcastVO;
+
+/**
+ * ClassName: BroadcastService
+ * Package: com.welampiot.service.impl
+ * Description:
+ *
+ * @Author: zhj_Start
+ * @Create: 2023/4/17 - 11:18
+ * @Version: v1.0
+ */
+public interface BroadcastService {
+    BroadcastVO getDevListByBroadcastDTO(BroadcastDTO dto);
+
+    BroadcastProListVO getProListByDTO(String username);
+
+    BroadcastItemVO getItemListByDTO(String username, Integer devId);
+}

+ 131 - 0
src/main/java/com/welampiot/service/impl/BroadcastServiceImpl.java

@@ -0,0 +1,131 @@
+package com.welampiot.service.impl;
+
+import com.welampiot.dao.BroadcastDao;
+import com.welampiot.dto.BroadcastDTO;
+import com.welampiot.dto.BroadcastItemDTO;
+import com.welampiot.dto.BroadcastProListDTO;
+import com.welampiot.service.BroadcastService;
+import com.welampiot.vo.BroadcastItemVO;
+import com.welampiot.vo.BroadcastProListVO;
+import com.welampiot.vo.BroadcastVO;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * ClassName: BroadcastServiceImpl
+ * Package: com.welampiot.service.impl
+ * Description:
+ *
+ * @Author: zhj_Start
+ * @Create: 2023/4/17 - 11:19
+ * @Version: v1.0
+ */
+@Service
+public class BroadcastServiceImpl implements BroadcastService {
+    @Autowired
+    private BroadcastDao broadcastDao;
+
+    @Override
+    public BroadcastVO getDevListByBroadcastDTO(BroadcastDTO dto) {
+        BroadcastVO vo = new BroadcastVO();
+        vo.setTotal(broadcastDao.getTotalBySectionList(dto));
+        vo.setOnlineTotal(broadcastDao.getOnlineTotalBySectionList(dto));
+        List<BroadcastDTO> devList = broadcastDao.getDevListByBroadcastDTO(dto);
+        List<BroadcastDTO> list = new ArrayList<>();
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        devList.forEach(broadcastDTO ->{
+            if (broadcastDTO.getOnline() != null && broadcastDTO.getOnline() == 1){
+                broadcastDTO.setOnline(1);
+            }else {
+                broadcastDTO.setOnline(0);
+            }
+            if (broadcastDTO.getProName() == null){
+                broadcastDTO.setProName("");
+            }
+            if (broadcastDTO.getLampPoleName() == null){
+                broadcastDTO.setLampPoleName("");
+            }
+            if (broadcastDTO.getType() != null && broadcastDTO.getType() == 1){
+                broadcastDTO.setType(1);
+            }else {
+                broadcastDTO.setType(0);
+            }
+            if (broadcastDTO.getIsPlay() != null && broadcastDTO.getIsPlay() == 1){
+                broadcastDTO.setIsPlay(1);
+            }else {
+                broadcastDTO.setIsPlay(0);
+            }
+            if (broadcastDTO.getInstallDate() != null){
+                try {
+                    broadcastDTO.setInstallDate(simpleDateFormat.format(simpleDateFormat.parse(broadcastDTO.getInstallDate())));
+                } catch (ParseException e) {
+                    throw new RuntimeException(e);
+                }
+            }else {
+                broadcastDTO.setInstallDate("");
+            }
+            if (broadcastDTO.getExpirationDate() != null){
+                try {
+                    broadcastDTO.setExpirationDate(simpleDateFormat.format(simpleDateFormat.parse(broadcastDTO.getExpirationDate())));
+                } catch (ParseException e) {
+                    throw new RuntimeException(e);
+                }
+            }else {
+                broadcastDTO.setExpirationDate("");
+            }
+            list.add(broadcastDTO);
+        });
+        vo.setList(list);
+        return vo;
+    }
+
+    @Override
+    public BroadcastProListVO getProListByDTO(String username) {
+        BroadcastProListVO vo = new BroadcastProListVO();
+        Integer userId = broadcastDao.getUserIdByUserName(username);
+        List<BroadcastProListDTO> proList = broadcastDao.getProListByDTO(userId);
+        vo.setList(proList);
+        return vo;
+    }
+
+    @Override
+    public BroadcastItemVO getItemListByDTO(String username, Integer devId) {
+        BroadcastItemVO vo = new BroadcastItemVO();
+        Integer userId = broadcastDao.getUserIdByUserName(username);
+        List<BroadcastItemDTO> itemList = broadcastDao.getItemListByDTO(userId, devId);
+        List<BroadcastItemDTO> list = new ArrayList<>();
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        itemList.forEach(broadcastItemDTO -> {
+            if (broadcastItemDTO.getBroadcastStr() == null){
+                broadcastItemDTO.setBroadcastStr("");
+            }
+            if (broadcastItemDTO.getProType() != null && broadcastItemDTO.getProType() == 1){
+                broadcastItemDTO.setProType(1);
+            }else {
+                broadcastItemDTO.setProType(0);
+            }
+            if (broadcastItemDTO.getStatus() != null && broadcastItemDTO.getStatus() == 1){
+                broadcastItemDTO.setStatus(1);
+            }else {
+                broadcastItemDTO.setStatus(0);
+            }
+            if (broadcastItemDTO.getCreateTime() != null){
+                try {
+                    broadcastItemDTO.setCreateTime(simpleDateFormat.format(simpleDateFormat.parse(broadcastItemDTO.getCreateTime())));
+                } catch (ParseException e) {
+                    throw new RuntimeException(e);
+                }
+            }else {
+                broadcastItemDTO.setCreateTime("");
+            }
+            list.add(broadcastItemDTO);
+        });
+        vo.setList(list);
+        return vo;
+    }
+}

+ 23 - 0
src/main/java/com/welampiot/vo/BroadcastItemVO.java

@@ -0,0 +1,23 @@
+package com.welampiot.vo;
+
+import com.welampiot.dto.BroadcastItemDTO;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * ClassName: BroadcastItemVO
+ * Package: com.welampiot.vo
+ * Description:
+ *
+ * @Author: zhj_Start
+ * @Create: 2023/4/17 - 15:50
+ * @Version: v1.0
+ */
+@Data
+public class BroadcastItemVO implements Serializable {
+    private List<BroadcastItemDTO> list;
+
+    private static final long serialVersionUID = 1L;
+}

+ 32 - 0
src/main/java/com/welampiot/vo/BroadcastProListVO.java

@@ -0,0 +1,32 @@
+package com.welampiot.vo;
+
+import com.welampiot.dto.BroadcastProListDTO;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * ClassName: BroadcastProListVO
+ * Package: com.welampiot.vo
+ * Description:
+ *
+ * @Author: zhj_Start
+ * @Create: 2023/4/17 - 13:53
+ * @Version: v1.0
+ */
+@Data
+public class BroadcastProListVO implements Serializable {
+    /** 音乐id **/
+    private Integer id;
+
+    /** 音乐名称 **/
+    private String name;
+
+    /** 音乐文件地址 **/
+    private String url;
+
+    private List<BroadcastProListDTO> list;
+
+    private static final long serialVersionUID = 1L;
+}

+ 27 - 0
src/main/java/com/welampiot/vo/BroadcastVO.java

@@ -0,0 +1,27 @@
+package com.welampiot.vo;
+
+import com.welampiot.dto.BroadcastDTO;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * ClassName: BroadcastVO
+ * Package: com.welampiot.vo
+ * Description:
+ *
+ * @Author: zhj_Start
+ * @Create: 2023/4/17 - 11:20
+ * @Version: v1.0
+ */
+@Data
+public class BroadcastVO implements Serializable {
+    private Integer total;
+
+    private Integer onlineTotal;
+
+    private List<BroadcastDTO> list;
+
+    private static final long serialVersionUID = 1L;
+}

+ 76 - 0
src/main/resources/mapper/BroadcastMapper.xml

@@ -0,0 +1,76 @@
+<?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.welampiot.dao.BroadcastDao">
+
+    <select id="getDevListByBroadcastDTO" resultType="BroadcastDTO">
+        select b.id,b.name,b.dev_id devId,b.address,b.online,b.vol,bi.name as proName,b.isPlay,
+               lp.name as lampPoleName,b.type,b.install_date installDate,b.expiration_date expirationDate
+        from broadcast b left join broadcast_item bi on bi.broadcastId = b.id
+            left join lamp_pole lp on b.lamp_pole_id = lp.id
+        where b.lamp_pole_id != 0
+        <if test="sectionList != null and !sectionList.isEmpty()">
+            and lp.sectionid in
+            <foreach collection="sectionList" item="dto" open="(" separator="," close=")">
+                #{dto}
+            </foreach>
+        </if>
+        <choose>
+            <when test="onlineState == 0">
+                and b.online = 0
+            </when>
+            <when test="onlineState == 1">
+                and b.online = 1
+            </when>
+        </choose>
+        order by convert(lp.number using gbk) asc,
+                 convert(b.name using gbk) asc,b.id desc
+    </select>
+
+    <select id="getTotalBySectionList" resultType="Integer">
+        select count(b.id) as total from broadcast b
+        left join lamp_pole lp on b.lamp_pole_id = lp.id
+        <if test="sectionList != null and !sectionList.isEmpty()">
+            where lp.sectionid in
+            <foreach collection="sectionList" item="dto" open="(" separator="," close=")">
+                #{dto}
+            </foreach>
+        </if>
+    </select>
+
+    <select id="getOnlineTotalBySectionList" resultType="Integer">
+        select count(b.id) as total from broadcast b
+        left join lamp_pole lp on b.lamp_pole_id = lp.id
+        where b.online = 1
+        <if test="sectionList != null and !sectionList.isEmpty()">
+            and lp.sectionid in
+            <foreach collection="sectionList" item="dto" open="(" separator="," close=")">
+                #{dto}
+            </foreach>
+        </if>
+    </select>
+
+    <select id="getUserIdByUserName" resultType="Integer">
+        select u.id from user u
+        where u.username = #{username}
+    </select>
+
+    <!-- 音乐列表 -->
+    <select id="getProListByDTO" resultType="BroadcastProListDTO">
+        select b.id,b.name,b.url
+        from broadcast_pro_list b
+        where b.userId = #{userId}
+    </select>
+
+    <!-- 节目列表 -->
+    <select id="getItemListByDTO" resultType="BroadcastItemDTO">
+        select b.id,b.name,b.proType,b.broadcastId,b.status,b.createTime,b1.name as broadcastStr
+        from broadcast_item b left join broadcast b1 on b.broadcastId = b1.id
+            left join lamp_pole lp on lp.id = b1.lamp_pole_id
+            left join section s on lp.sectionid = s.id
+        where b.userId = #{userId}
+        <if test="devId != null and devId != 0">
+           and b.broadcastId = #{devId}
+        </if>
+    </select>
+    
+</mapper>