|
@@ -0,0 +1,147 @@
|
|
|
+package org.jeecg.modules.ctop.controller;
|
|
|
+
|
|
|
+import cn.com.ctop.manage.modules.actor.entity.*;
|
|
|
+import cn.com.ctop.manage.modules.actor.service.IYardPhotoService;
|
|
|
+import cn.com.ctop.manage.modules.actor.service.IYardSchedulerService;
|
|
|
+import cn.com.ctop.manage.modules.actor.service.IYardService;
|
|
|
+import cn.com.ctop.manage.modules.actor.service.IYardVideoService;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.jeecg.common.api.vo.Result;
|
|
|
+import org.jeecg.common.system.query.QueryGenerator;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@Slf4j
|
|
|
+@RequestMapping("/ctop/yard")
|
|
|
+public class YardController {
|
|
|
+ @Autowired
|
|
|
+ private IYardPhotoService yardPhotoService;
|
|
|
+ @Autowired
|
|
|
+ private IYardSchedulerService yardSchedulerService;
|
|
|
+ @Autowired
|
|
|
+ private IYardService yardService;
|
|
|
+ @Autowired
|
|
|
+ private IYardVideoService yardVideoService;
|
|
|
+
|
|
|
+ @ResponseBody
|
|
|
+ @RequestMapping(value = "/detail", method = RequestMethod.GET)
|
|
|
+ public Result<Map<String, Object>> getDetail(@RequestParam(name = "yardId") Long yardId) {
|
|
|
+ Result<Map<String, Object>> result = new Result<>();
|
|
|
+ Yard yard = yardService.getById(yardId);
|
|
|
+ YardPhoto yardPhoto = new YardPhoto();
|
|
|
+ YardVideo yardVideo = new YardVideo();
|
|
|
+ YardScheduler yardScheduler = new YardScheduler();
|
|
|
+ yardPhoto.setYardId(yardId);
|
|
|
+ yardVideo.setYardId(yardId);
|
|
|
+ yardScheduler.setYardId(yardId);
|
|
|
+ QueryWrapper<YardPhoto> yardPhotoQueryWrapper = QueryGenerator.initQueryWrapper(yardPhoto, null);
|
|
|
+ QueryWrapper<YardVideo> yardVideoQueryWrapper = QueryGenerator.initQueryWrapper(yardVideo, null);
|
|
|
+ QueryWrapper<YardScheduler> yardSchedulerQueryWrapper = QueryGenerator.initQueryWrapper(yardScheduler, null);
|
|
|
+ List<YardPhoto> yardPhotoList = yardPhotoService.list(yardPhotoQueryWrapper);
|
|
|
+ List<YardVideo> yardVideoList = yardVideoService.list(yardVideoQueryWrapper);
|
|
|
+ List<YardScheduler> yardSchedulerList = yardSchedulerService.list(yardSchedulerQueryWrapper);
|
|
|
+ Map<String, Object> map = new HashMap<String, Object>();
|
|
|
+ map.put("yard", yard);
|
|
|
+ map.put("yardPhotoList", yardPhotoList);
|
|
|
+ map.put("yardVideoList", yardVideoList);
|
|
|
+ map.put("yardSchedulerList", yardSchedulerList);
|
|
|
+ result.setResult(map);
|
|
|
+ result.setSuccess(true);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping(value = "/add")
|
|
|
+ public Result<Yard> add(@RequestBody Yard yard) {
|
|
|
+ Result<Yard> result = new Result<Yard>();
|
|
|
+ try {
|
|
|
+ yardService.save(yard);
|
|
|
+ if (yard.getImageUrl() != null && yard.getImageUrl().size() > 0) {
|
|
|
+ for (String url : yard.getImageUrl()) {
|
|
|
+ YardPhoto yardPhoto = new YardPhoto();
|
|
|
+ yardPhoto.setYardId(yard.getId());
|
|
|
+ yardPhoto.setPhotoUrl("http:" + url);
|
|
|
+ yardPhotoService.save(yardPhoto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (yard.getVideoUrl() != null && yard.getVideoUrl().size() > 0) {
|
|
|
+ for (String url : yard.getVideoUrl()) {
|
|
|
+ YardVideo yardVideo = new YardVideo();
|
|
|
+ yardVideo.setYardId(yard.getId());
|
|
|
+ yardVideo.setVideoUrl("http:" + url);
|
|
|
+ yardVideoService.save(yardVideo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ result.success("添加成功!");
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+ result.error500("操作失败");
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @PutMapping(value = "/edit")
|
|
|
+ public Result<Yard> edit(@RequestBody Yard yard) {
|
|
|
+ Result<Yard> result = new Result<Yard>();
|
|
|
+
|
|
|
+ Yard yardEntity = yardService.getById(yard.getId());
|
|
|
+ if (yardEntity == null) {
|
|
|
+ result.error500("未找到对应实体");
|
|
|
+ } else {
|
|
|
+ boolean ok = yardService.updateById(yard);
|
|
|
+ YardPhoto yardPhoto = new YardPhoto();
|
|
|
+ yardPhoto.setYardId(yard.getId());
|
|
|
+ QueryWrapper photoQueryWrapper = QueryGenerator.initQueryWrapper(yardPhoto, null);
|
|
|
+ yardPhotoService.remove(photoQueryWrapper);
|
|
|
+
|
|
|
+ YardVideo yardVideo = new YardVideo();
|
|
|
+ yardVideo.setYardId(yard.getId());
|
|
|
+ QueryWrapper videoQueryWrapper = QueryGenerator.initQueryWrapper(yardVideo, null);
|
|
|
+ yardVideoService.remove(videoQueryWrapper);
|
|
|
+ if (yard.getImageUrl() != null && yard.getImageUrl().size() > 0) {
|
|
|
+ for (String url : yard.getImageUrl()) {
|
|
|
+ YardPhoto photo = new YardPhoto();
|
|
|
+ photo.setYardId(yard.getId());
|
|
|
+ photo.setPhotoUrl("http:" + url);
|
|
|
+ yardPhotoService.save(photo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (yard.getVideoUrl() != null && yard.getVideoUrl().size() > 0) {
|
|
|
+ for (String url : yard.getVideoUrl()) {
|
|
|
+ YardVideo video = new YardVideo();
|
|
|
+ video.setYardId(yard.getId());
|
|
|
+ video.setVideoUrl("http:" + url);
|
|
|
+ yardVideoService.save(video);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //TODO 返回false说明什么?
|
|
|
+ if (ok) {
|
|
|
+ result.success("修改成功!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping(value = "/list")
|
|
|
+ public Result<IPage<Yard>> queryPageList(Yard yard,
|
|
|
+ @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
|
|
|
+ @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
|
|
|
+ HttpServletRequest req) {
|
|
|
+ Result<IPage<Yard>> result = new Result<IPage<Yard>>();
|
|
|
+ QueryWrapper<Yard> queryWrapper = QueryGenerator.initQueryWrapper(yard, req.getParameterMap());
|
|
|
+ Page<Yard> page = new Page<Yard>(pageNo, pageSize);
|
|
|
+ IPage<Yard> pageList = yardService.page(page, queryWrapper);
|
|
|
+
|
|
|
+ result.setSuccess(true);
|
|
|
+ result.setResult(pageList);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+}
|