派生自 projectDept/qhighschool

胡仁荣
2022-10-31 fe7381d6e8ec1f427408de0297ac7f41533202f6
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
219
220
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 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) {
 
        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")));
    }
 
 
}