派生自 projectDept/qhighschool

121
EricsHu
2023-03-29 5f8121997d21858ac2cd69af01f6ee4d41290bdc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
package com.qxueyou.scc.controller;
 
import com.fasterxml.jackson.databind.ObjectMapper;
import com.qxueyou.scc.base.model.Result;
import com.qxueyou.scc.base.util.ClientUtils;
import com.qxueyou.scc.base.util.CollectionUtils;
import com.qxueyou.scc.base.util.QBeanUtils;
import com.qxueyou.scc.teach.res.model.Res;
import com.qxueyou.scc.teach.res.model.ResDatas;
import com.qxueyou.scc.teach.res.model.ResDir;
import com.qxueyou.scc.teach.res.service.IResService;
import io.swagger.annotations.Api;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;
 
/**
 * 资源管理控制器
 *
 * @author chenjunliang
 */
@Api(tags = "资源管理接口")
@RestController
@RequestMapping(value = "/teach/res")
public class ResController {
 
    @Autowired
    IResService resService;
 
    /**
     * 资源库层级管理Tree
     */
    @GetMapping(value = "categoryLevel")
    public Result categoryLevel(String parentId) {
 
        List<ResDir> dirs = resService.doGetMyLibChildDirs(parentId);
 
        return new Result(true, "success",
                QBeanUtils.listBean2ListMap(dirs, CollectionUtils.newStringMap("name", "name", "dirId", "id")));
 
    }
 
    /**
     * 资源库根节点
     *
     * @param type    资源库类型
     *                user,个人资源库
     *                class,班级资源库
     * @param ownerId 资源库所属主体id,个人资源库传userId,班级资源库传classId
     */
    @GetMapping(value = "rootDir")
    public Result getRoot(String type, String ownerId) {
        if ("user".equals(type) && StringUtils.isEmpty(ownerId)) {
            ownerId = ClientUtils.getUserId();
//            System.out.println(ownerId);
        }
        ResDir root = resService.doGetRootDir(type, ownerId);
//        System.out.println(root);
        return new Result(true, "success", CollectionUtils.newList(
                QBeanUtils.bean2Map(root, CollectionUtils.newStringMap("name", "name", "dirId", "id"))));
 
    }
 
    /**
     * 资源管理获取 资源列表
     *
     * @param dirId   目录id
     * @param keyword 搜索关键字
     * @param limit   每页显示几条
     * @param pageNum 页码
     * @param type    类型(0,视频。1,音频。2,文档。3,练习。)
     * @return 资源列表数据
     */
    @GetMapping(value = "lstRes")
    public Result lstRes(String dirId, String keyword, Integer limit, Integer pageNum, String type) {
 
        List<Res> resLst = resService.listRes(dirId, keyword, limit, pageNum, type);
 
        List<Map<String, Object>> lst = QBeanUtils.listBean2ListMap(resLst,
                CollectionUtils.newStringMap("resId", "id", "name", "name", "type", "type", "coverPageUrl", "imgPath",
                        "updateTime", "updateTime", "remark", "size", "status", "status"));
 
        return new Result(true, "success",
                CollectionUtils.newObjectMap("resLst", lst, "resCount", resService.listResCount(dirId, keyword, type)));
 
    }
 
    /**
     * 资源管理删除 资源
     *
     * @param id 资源id,英文逗号区分,可传多个
     */
    @GetMapping(value = "deleteFile")
    public Result deleteRes(String fileId) {
        return resService.delete(fileId.split(","));
    }
 
    /**
     * 资源管理 复制资源
     *
     * @param resId 资源id
     * @param dirId 目录id
     * @param type  类型
     */
    @GetMapping(value = "copyRes")
    public Result copyRes(String resId, String dirId, String type) {
        return resService.doCopy(resId, dirId, null);
    }
 
    /**
     * 资源管理 资源的移动
     *
     * @param resId 要移动的资源
     * @param type  目录类型
     * @param dirId 目录id
     */
    @GetMapping(value = "moveRes")
    public Result moveRes(String resId, String type, String dirId) {
        return resService.doMove(resId, dirId, null);
    }
 
    /**
     * 资源管理新增or编辑目录
     *
     * @param dirId     目录id
     * @param name      目录名
     * @param type      (add新增 and edit修改)
     * @param childFlag 是否操作下级
     */
    @GetMapping(value = "addOrUpdateDir")
    public Result addOrUpdateDir(String type, String name, String dirId, boolean childFlag) {
 
        ResDir dir = resService.readDir(dirId);
        String parentDirId = childFlag ? dirId : dir.getParentDirId();
 
        if ("add".equals(type)) {
            return resService.addDir(parentDirId, name);
        } else {
            return resService.updateDir(dirId, name);
        }
    }
 
    /**
     * 资源管理 删除目录
     *
     * @param dirId 目录id
     */
    @GetMapping(value = "deleteDir")
    public Result deleteDir(String dirId) {
        return resService.deleteDir(dirId.split(","));
    }
 
    /**
     * 添加/更新(视频,讲义,音频)
     *
     * @param dirId    资源夹id
     * @param name     名称
     * @param coverUrl 封面Url
     * @param remark:  <p>
     *                 视频啊啊啊
     *                 </p>
     *                 介绍
     * @param fileId   资源id
     * @param id       资源id
     * @param type
     * @return 状态说明(0, 视频 。 1, 音频 。 2, 文档 。 3, 练习 。)
     */
    @PostMapping(value = "addOrUpdateRes")
    public Result addOrUpdateRes(String dirId, String id, String remark, String name, String coverUrl, String type,
                                 String fileId) {
 
        if (StringUtils.isEmpty(id)) {
            return resService.add(dirId, fileId, name, remark, type, coverUrl);
        } else {
            return resService.update(id, name, remark, coverUrl);
        }
    }
 
    /**
     * 批量添加资源
     *
     * @param dirId    节点id
     * @param fileId   文件id
     * @param fileName 文件名称
     * @param fileType 资源类型
     */
    @PostMapping(value = "addOfBatch")
    public Result addOfBatch(String dirId, String type, @RequestParam(value = "datas") String datas) {
        // 转换json到对象
        ObjectMapper mapper = new ObjectMapper();
        try {
            ResDatas resDatas = mapper.readValue(datas, ResDatas.class);
            return resService.addBatchRes(dirId, type, resDatas.getItems());
        } catch (IOException e) {
            e.printStackTrace();
        }
        return new Result(false);
    }
 
    /**
     * 编辑 获取内容
     *
     * @param id 资源id
     */
    @GetMapping(value = "getResDetail")
    public Result getResDetail(String id,HttpServletResponse response) {
        Res res = resService.read(id);
        Result pathResult = resService.readAccessPath(id, null);
        return new Result(true, "success", CollectionUtils.newObjectMap("type", res.getType(), "name", res.getName(),
                "coverUrl", res.getCoverPageUrl(), "remark", res.getRemark(), "fullPath", pathResult.getDataT("path")));
    }
 
}