chenw 6 лет назад
Родитель
Сommit
378cd2a5d9

+ 47 - 0
bi-server/src/main/java/com/usoftchina/bi/server/controller/dashboard/DashboardFavoriteController.java

@@ -0,0 +1,47 @@
+package com.usoftchina.bi.server.controller.dashboard;
+
+import com.usoftchina.bi.core.base.RepCode;
+import com.usoftchina.bi.core.base.RepEntity;
+import com.usoftchina.bi.server.model.pojo.annotation.CheckToken;
+import com.usoftchina.bi.server.service.dashboard.DashboardFavoriteService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+/**
+ * @Author chenwei
+ * @Date 2019-04-24
+ */
+@Api(description = "看板收藏相关接口")
+@RestController
+@RequestMapping("/dashboard/favorite")
+public class DashboardFavoriteController {
+
+    @Autowired
+    private DashboardFavoriteService dashboardFavoriteService;
+
+    @GetMapping("/list")
+    @CheckToken
+    @ApiOperation(value = "收藏列表", notes = "我的收藏列表", response = RepEntity.class)
+    public RepEntity list(@RequestHeader String token){
+        return new RepEntity(RepCode.success, dashboardFavoriteService.list(token));
+    }
+
+    @PostMapping("/save/{id}")
+    @CheckToken
+    @ApiOperation(value = "加入收藏", notes = "加入我的收藏", response = RepEntity.class)
+    public RepEntity save(@RequestHeader String token, @PathVariable("id") Long dashboardId){
+        dashboardFavoriteService.save(token, dashboardId);
+        return new RepEntity(RepCode.success);
+    }
+
+    @PostMapping("/delete/{id}")
+    @CheckToken
+    @ApiOperation(value = "加入收藏", notes = "加入我的收藏", response = RepEntity.class)
+    public RepEntity delete(@RequestHeader String token, @PathVariable("id") Long dashboardId){
+        dashboardFavoriteService.delete(token, dashboardId);
+        return new RepEntity(RepCode.success);
+    }
+
+}

+ 24 - 0
bi-server/src/main/java/com/usoftchina/bi/server/dao/dashboard/DashboardFavoriteMapper.java

@@ -0,0 +1,24 @@
+package com.usoftchina.bi.server.dao.dashboard;
+
+import org.apache.ibatis.annotations.Insert;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+import java.util.Map;
+
+@Mapper
+@Repository
+public interface DashboardFavoriteMapper {
+
+    @Select("SELECT ID AS id, BD_NAME AS name FROM BI_DASHBOARDS WHERE ID IN (SELECT DASHBOARD_ID FROM BI_DASHBOARDS_FAVORITE WHERE USER_ID = #{userId})")
+    List<Map<String, String>> list(@Param("userId") int userId);
+
+    @Insert("INSERT INTO BI_DASHBOARDS_FAVORITE(USER_ID, DASHBOARD_ID) VALUES()")
+    void insert(@Param("userId") int userId, @Param("dashboardId") int dashboardId);
+
+    @Insert("DELETE FROM BI_DASHBOARDS_FAVORITE WHERE DASHBOARD_ID = #{dashboardId}")
+    void remove(@Param("dashboardId") int dashboardId);
+}

+ 35 - 0
bi-server/src/main/java/com/usoftchina/bi/server/service/dashboard/DashboardFavoriteService.java

@@ -0,0 +1,35 @@
+package com.usoftchina.bi.server.service.dashboard;
+
+import com.usoftchina.bi.core.utils.GetTokenDataUtil;
+import com.usoftchina.bi.server.dao.dashboard.DashboardFavoriteMapper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @Author chenwei
+ * @Date 2019-04-24
+ */
+@Service
+public class DashboardFavoriteService {
+
+    @Autowired
+    private DashboardFavoriteMapper dashboardFavoriteMapper;
+
+    public List<Map<String, String>> list(String token){
+        int userId = Integer.parseInt(GetTokenDataUtil.getTokenData(token).get("id"));
+        return dashboardFavoriteMapper.list(userId);
+    }
+
+    public void save(String token, Long dashboardId){
+        int userId = Integer.parseInt(GetTokenDataUtil.getTokenData(token).get("id"));
+        dashboardFavoriteMapper.insert(userId, dashboardId.intValue());
+    }
+
+    public void delete(String token, Long dashboardId) {
+        dashboardFavoriteMapper.remove(dashboardId.intValue());
+    }
+
+}