|
@@ -4,24 +4,26 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
4
|
4
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
5
|
5
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
6
|
6
|
import com.huiju.foyo.common.BaseController;
|
|
7
|
+import com.huiju.foyo.common.CommUtils;
|
7
|
8
|
import com.huiju.foyo.common.ConstantFoyo;
|
8
|
9
|
import com.huiju.foyo.common.ResponseBean;
|
9
|
10
|
import com.huiju.foyo.model.TaCase;
|
|
11
|
+import com.huiju.foyo.model.TaCover;
|
|
12
|
+import com.huiju.foyo.model.TaLikeLog;
|
10
|
13
|
import com.huiju.foyo.service.ITaCaseService;
|
|
14
|
+import com.huiju.foyo.service.ITaCoverService;
|
|
15
|
+import com.huiju.foyo.service.ITaLikeLogService;
|
11
|
16
|
import org.slf4j.Logger;
|
12
|
17
|
import org.slf4j.LoggerFactory;
|
13
|
18
|
import org.springframework.beans.factory.annotation.Autowired;
|
14
|
|
-import org.springframework.web.bind.annotation.PathVariable;
|
15
|
|
-import org.springframework.web.bind.annotation.RequestBody;
|
16
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
17
|
|
-import org.springframework.web.bind.annotation.RequestMethod;
|
18
|
|
-import org.springframework.web.bind.annotation.RequestParam;
|
19
|
|
-import org.springframework.web.bind.annotation.ResponseBody;
|
20
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
19
|
+import org.springframework.web.bind.annotation.*;
|
21
|
20
|
|
|
21
|
+import javax.servlet.http.HttpServletRequest;
|
22
|
22
|
import java.time.LocalDateTime;
|
23
|
23
|
import java.util.Arrays;
|
|
24
|
+import java.util.HashMap;
|
24
|
25
|
import java.util.List;
|
|
26
|
+import java.util.Map;
|
25
|
27
|
|
26
|
28
|
/**
|
27
|
29
|
* <p>
|
|
@@ -40,6 +42,11 @@ public class TaCaseController extends BaseController {
|
40
|
42
|
@Autowired
|
41
|
43
|
public ITaCaseService iTaCaseService;
|
42
|
44
|
|
|
45
|
+ @Autowired
|
|
46
|
+ public ITaLikeLogService iTaLikeLogService;
|
|
47
|
+
|
|
48
|
+ @Autowired
|
|
49
|
+ public ITaCoverService iTaCoverService;
|
43
|
50
|
|
44
|
51
|
/**
|
45
|
52
|
* 分页查询列表
|
|
@@ -202,4 +209,56 @@ public class TaCaseController extends BaseController {
|
202
|
209
|
}
|
203
|
210
|
return responseBean;
|
204
|
211
|
}
|
|
212
|
+
|
|
213
|
+ @GetMapping("/pc/case/{caseId}")
|
|
214
|
+ public ResponseBean get(@PathVariable Integer caseId) {
|
|
215
|
+ TaCase taCase = iTaCaseService.getById(caseId);
|
|
216
|
+ if (null == taCase) {
|
|
217
|
+ return ResponseBean.error("非法的案例或者动态ID");
|
|
218
|
+ }
|
|
219
|
+
|
|
220
|
+ // 封面
|
|
221
|
+ QueryWrapper<TaCover> wrapper = new QueryWrapper<>();
|
|
222
|
+ wrapper.eq("type", taCase.getType());
|
|
223
|
+ wrapper.last("limit 1");
|
|
224
|
+ TaCover taCover = iTaCoverService.getOne(wrapper);
|
|
225
|
+
|
|
226
|
+ // 上一条, 下一条
|
|
227
|
+ List<TaCase> brothers = iTaCaseService.getBrothers(taCase);
|
|
228
|
+
|
|
229
|
+ // 推荐随机获取数据
|
|
230
|
+ QueryWrapper<TaCase> query = new QueryWrapper<>();
|
|
231
|
+ query.eq("ta_case_type_id", taCase.getTaCaseTypeId());
|
|
232
|
+ query.ne("id", caseId);
|
|
233
|
+ query.last("ORDER BY RAND() LIMIT 10");
|
|
234
|
+ List<TaCase> recommends = iTaCaseService.list(query);
|
|
235
|
+
|
|
236
|
+ Map<String, Object> result = new HashMap<String, Object>(){{
|
|
237
|
+ put("current", taCase);
|
|
238
|
+ put("cover", taCover);
|
|
239
|
+ put("brothers", brothers);
|
|
240
|
+ put("recommends", recommends);
|
|
241
|
+ }};
|
|
242
|
+
|
|
243
|
+ return ResponseBean.success(result);
|
|
244
|
+ }
|
|
245
|
+
|
|
246
|
+ @PostMapping("/pc/like/case/{caseId}")
|
|
247
|
+ public ResponseBean postLike(@PathVariable Integer caseId, HttpServletRequest request) {
|
|
248
|
+ String ip = CommUtils.getIpAddr(request);
|
|
249
|
+
|
|
250
|
+ TaCase taCase = iTaCaseService.getById(caseId);
|
|
251
|
+ if (null == taCase) {
|
|
252
|
+ return ResponseBean.error("非法的案例或者动态ID");
|
|
253
|
+ }
|
|
254
|
+
|
|
255
|
+ TaLikeLog taLikeLog = new TaLikeLog();
|
|
256
|
+ taLikeLog.setAgent("ip="+ip);
|
|
257
|
+ taLikeLog.setCreateDate(LocalDateTime.now());
|
|
258
|
+ taLikeLog.setTarget(caseId);
|
|
259
|
+ taLikeLog.setTargetType("case");
|
|
260
|
+
|
|
261
|
+ Integer likeNum = iTaLikeLogService.postCaseLike(taCase, taLikeLog);
|
|
262
|
+ return ResponseBean.success(likeNum);
|
|
263
|
+ }
|
205
|
264
|
}
|