Pārlūkot izejas kodu

添加家族园地图片以及app接口

liuhj 4 gadi atpakaļ
vecāks
revīzija
3f61145bbf

+ 1 - 1
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TbFamilyGardenController.java

@@ -78,7 +78,7 @@ public class TbFamilyGardenController extends BaseController {
     @PreAuthorize("@ss.hasPermi('system:garden:query')" )
     @GetMapping(value = "/{id}" )
     public AjaxResult getInfo(@PathVariable("id" ) Long id) {
-        return AjaxResult.success(iTbFamilyGardenService.getById(id));
+        return AjaxResult.success(iTbFamilyGardenService.getFamilyGarden(id));
     }
 
     /**

+ 121 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TbGardenImgController.java

@@ -0,0 +1,121 @@
+package com.ruoyi.web.controller.api;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+
+import java.util.List;
+import java.util.Arrays;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import com.ruoyi.common.utils.StringUtils;
+import lombok.RequiredArgsConstructor;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import com.ruoyi.common.annotation.Log;
+import com.ruoyi.common.core.controller.BaseController;
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.enums.BusinessType;
+import com.ruoyi.app.domain.TbGardenImg;
+import com.ruoyi.app.service.ITbGardenImgService;
+import com.ruoyi.common.utils.poi.ExcelUtil;
+import com.ruoyi.common.core.page.TableDataInfo;
+
+/**
+ * 家族园地图片
+ * 
+ * @author liuhj
+ * @date 2020-10-22
+ */
+@Api(value = "家族园地图片", tags = "家族园地图片")
+@RequiredArgsConstructor(onConstructor_ = @Autowired)
+@RestController
+@RequestMapping("/system/img" )
+public class TbGardenImgController extends BaseController {
+
+    private final ITbGardenImgService iTbGardenImgService;
+
+    /**
+     * 查询家族园地图片列表
+     */
+    @ApiOperation("查询家族园地图片列表")
+    @PreAuthorize("@ss.hasPermi('system:img:list')")
+    @GetMapping("/list")
+    public TableDataInfo list(TbGardenImg tbGardenImg)
+    {
+        startPage();
+        LambdaQueryWrapper<TbGardenImg> lqw = new LambdaQueryWrapper<TbGardenImg>();
+        if (tbGardenImg.getGardenId() != null){
+            lqw.eq(TbGardenImg::getGardenId ,tbGardenImg.getGardenId());
+        }
+        if (StringUtils.isNotBlank(tbGardenImg.getUrl())){
+            lqw.eq(TbGardenImg::getUrl ,tbGardenImg.getUrl());
+        }
+        List<TbGardenImg> list = iTbGardenImgService.list(lqw);
+        return getDataTable(list);
+    }
+
+    /**
+     * 导出家族园地图片列表
+     */
+    @ApiOperation("导出家族园地图片列表")
+    @PreAuthorize("@ss.hasPermi('system:img:export')" )
+    @Log(title = "家族园地图片" , businessType = BusinessType.EXPORT)
+    @GetMapping("/export" )
+    public AjaxResult export(TbGardenImg tbGardenImg) {
+        LambdaQueryWrapper<TbGardenImg> lqw = new LambdaQueryWrapper<TbGardenImg>(tbGardenImg);
+        List<TbGardenImg> list = iTbGardenImgService.list(lqw);
+        ExcelUtil<TbGardenImg> util = new ExcelUtil<TbGardenImg>(TbGardenImg. class);
+        return util.exportExcel(list, "img" );
+    }
+
+    /**
+     * 获取家族园地图片详细信息
+     */
+    @ApiOperation("获取家族园地图片详细信息")
+    @PreAuthorize("@ss.hasPermi('system:img:query')" )
+    @GetMapping(value = "/{id}" )
+    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
+        return AjaxResult.success(iTbGardenImgService.getById(id));
+    }
+
+    /**
+     * 新增家族园地图片
+     */
+    @ApiOperation("新增家族园地图片")
+    @PreAuthorize("@ss.hasPermi('system:img:add')" )
+    @Log(title = "家族园地图片" , businessType = BusinessType.INSERT)
+    @PostMapping
+    public AjaxResult add(@RequestBody TbGardenImg tbGardenImg) {
+        return toAjax(iTbGardenImgService.save(tbGardenImg) ? 1 : 0);
+    }
+
+    /**
+     * 修改家族园地图片
+     */
+    @ApiOperation("修改家族园地图片")
+    @PreAuthorize("@ss.hasPermi('system:img:edit')" )
+    @Log(title = "家族园地图片" , businessType = BusinessType.UPDATE)
+    @PutMapping
+    public AjaxResult edit(@RequestBody TbGardenImg tbGardenImg) {
+        return toAjax(iTbGardenImgService.updateById(tbGardenImg) ? 1 : 0);
+    }
+
+    /**
+     * 删除家族园地图片
+     */
+    @ApiOperation("删除家族园地图片")
+    @PreAuthorize("@ss.hasPermi('system:img:remove')" )
+    @Log(title = "家族园地图片" , businessType = BusinessType.DELETE)
+    @DeleteMapping("/{ids}" )
+    public AjaxResult remove(@PathVariable Long[] ids) {
+        return toAjax(iTbGardenImgService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
+    }
+}

+ 17 - 2
ruoyi-app/src/main/java/com/ruoyi/app/controller/FamilyGardenController.java

@@ -1,8 +1,11 @@
 package com.ruoyi.app.controller;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.ruoyi.app.domain.TbEventsImg;
 import com.ruoyi.app.domain.TbFamilyGarden;
+import com.ruoyi.app.domain.TbGardenImg;
 import com.ruoyi.app.service.ITbFamilyGardenService;
+import com.ruoyi.app.service.ITbGardenImgService;
 import com.ruoyi.common.annotation.Log;
 import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.domain.AjaxResult;
@@ -33,6 +36,8 @@ import java.util.List;
 public class FamilyGardenController extends BaseController {
 
     private final ITbFamilyGardenService iTbFamilyGardenService;
+    @Autowired
+    private ITbGardenImgService gardenImgService;
 
     /**
      * 查询家族园地列表
@@ -53,7 +58,7 @@ public class FamilyGardenController extends BaseController {
     @ApiOperation(value = "家族园地详细信息", notes = "家族园地详细信息")
     @GetMapping(value = "/{id}" )
     public AjaxResult detail(@PathVariable("id" ) Long id) {
-        return AjaxResult.success(iTbFamilyGardenService.getById(id));
+        return AjaxResult.success(iTbFamilyGardenService.getFamilyGarden(id));
     }
 
     /**
@@ -65,7 +70,17 @@ public class FamilyGardenController extends BaseController {
     public AjaxResult add(@RequestBody TbFamilyGarden tbFamilyGarden) {
         Date date = new Date();
         tbFamilyGarden.setCreateTime(date);
-        return toAjax(iTbFamilyGardenService.save(tbFamilyGarden) ? 1 : 0);
+        List<TbGardenImg> imgList = tbFamilyGarden.getImgList();
+        if (imgList.size() <= 0) {
+            return AjaxResult.success();
+        }
+        imgList.forEach(item -> {
+            item.setGardenId(tbFamilyGarden.getId());
+        });
+        if(gardenImgService.saveBatch(imgList)){
+            return AjaxResult.success();
+        }
+        return AjaxResult.error("发表失败");
     }
 
     /**

+ 9 - 0
ruoyi-system/src/main/java/com/ruoyi/app/domain/TbFamilyGarden.java

@@ -16,6 +16,8 @@ import com.baomidou.mybatisplus.annotation.IdType;
 import java.io.Serializable;
 import java.util.Date;
 import java.math.BigDecimal;
+import java.util.List;
+
 import com.ruoyi.common.core.domain.BaseEntity;
 
 /**
@@ -85,4 +87,11 @@ public class TbFamilyGarden implements Serializable {
     @ApiModelProperty(value = "家族信息")
     @TableField(exist = false)
     private TbFamily family;
+
+    /**
+     * 图片列表
+     */
+    @ApiModelProperty(value="图片列表")
+    @TableField(exist = false)
+    private List<TbGardenImg> imgList;
 }

+ 52 - 0
ruoyi-system/src/main/java/com/ruoyi/app/domain/TbGardenImg.java

@@ -0,0 +1,52 @@
+package com.ruoyi.app.domain;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.NoArgsConstructor;
+import lombok.ToString;
+import lombok.experimental.Accessors;
+import com.ruoyi.common.annotation.Excel;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.annotation.IdType;
+import java.io.Serializable;
+import java.util.Date;
+import java.math.BigDecimal;
+import com.ruoyi.common.core.domain.BaseEntity;
+
+/**
+ * 家族园地图片
+ * 
+ * @author liuhj
+ * @date 2020-10-22
+ */
+@Data
+@ApiModel(value = "家族园地图片")
+@ToString
+@EqualsAndHashCode
+@NoArgsConstructor
+@Accessors(chain = true)
+@TableName("tb_garden_img")
+public class TbGardenImg implements Serializable {
+
+    private static final long serialVersionUID=1L;
+
+
+    /** ID */
+    @ApiModelProperty(value="ID")
+    @TableId(value = "id")
+    private Long id;
+
+    /** 园地id */
+    @ApiModelProperty(value="园地id")
+    @Excel(name = "园地id")
+    private Long gardenId;
+
+    /** 园地图片 */
+    @ApiModelProperty(value="园地图片")
+    @Excel(name = "园地图片")
+    private String url;
+}

+ 14 - 0
ruoyi-system/src/main/java/com/ruoyi/app/mapper/TbGardenImgMapper.java

@@ -0,0 +1,14 @@
+package com.ruoyi.app.mapper;
+
+import com.ruoyi.app.domain.TbGardenImg;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * 家族园地图片
+ *
+ * @author liuhj
+ * @date 2020-10-22
+ */
+public interface TbGardenImgMapper extends BaseMapper<TbGardenImg> {
+
+}

+ 2 - 0
ruoyi-system/src/main/java/com/ruoyi/app/service/ITbFamilyGardenService.java

@@ -14,4 +14,6 @@ import java.util.List;
 public interface ITbFamilyGardenService extends IService<TbFamilyGarden> {
     List<TbFamilyGarden> queryList(TbFamilyGarden entity);
 
+    TbFamilyGarden getFamilyGarden(Long id);
+
 }

+ 14 - 0
ruoyi-system/src/main/java/com/ruoyi/app/service/ITbGardenImgService.java

@@ -0,0 +1,14 @@
+package com.ruoyi.app.service;
+
+import com.ruoyi.app.domain.TbGardenImg;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+ * 家族园地图片
+ *
+ * @author liuhj
+ * @date 2020-10-22
+ */
+public interface ITbGardenImgService extends IService<TbGardenImg> {
+
+}

+ 41 - 3
ruoyi-system/src/main/java/com/ruoyi/app/service/impl/TbFamilyGardenServiceImpl.java

@@ -1,17 +1,17 @@
 package com.ruoyi.app.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import com.ruoyi.app.domain.TbFamily;
-import com.ruoyi.app.domain.TbFamilyEvents;
+import com.ruoyi.app.domain.*;
 import com.ruoyi.app.service.ITbFamilyService;
+import com.ruoyi.app.service.ITbGardenImgService;
 import com.ruoyi.common.utils.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.ruoyi.app.mapper.TbFamilyGardenMapper;
-import com.ruoyi.app.domain.TbFamilyGarden;
 import com.ruoyi.app.service.ITbFamilyGardenService;
 
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -24,6 +24,8 @@ import java.util.List;
 public class TbFamilyGardenServiceImpl extends ServiceImpl<TbFamilyGardenMapper, TbFamilyGarden> implements ITbFamilyGardenService {
     @Autowired
     private ITbFamilyService familyService;
+    @Autowired
+    private ITbGardenImgService gardenImgService;
 
 
     @Override
@@ -41,6 +43,42 @@ public class TbFamilyGardenServiceImpl extends ServiceImpl<TbFamilyGardenMapper,
             item.setFamily(family);
         });
 
+        List<Long> ids = new ArrayList<>();
+        list.forEach(item -> {
+            ids.add(item.getId());
+        });
+        List<TbGardenImg> imgList = gardenImgService.list(new LambdaQueryWrapper<TbGardenImg>()
+                .in(TbGardenImg::getGardenId, ids)
+        );
+        list.forEach(item -> {
+            // 加入图片列表
+            List<TbGardenImg> imgs = new ArrayList<>();
+            imgList.forEach(img -> {
+                if (img.getGardenId().equals(item.getId())) {
+                    imgs.add(img);
+                }
+            });
+            item.setImgList(imgs);
+        });
+
         return list;
     }
+
+    /**
+     * 家族园地详情
+     * @param id
+     * @return
+     */
+    @Override
+    public TbFamilyGarden getFamilyGarden(Long id) {
+        TbFamilyGarden familyGarden = this.getById(id);
+        if (familyGarden != null) {
+            List<TbGardenImg> eventImgs = gardenImgService.list(new LambdaQueryWrapper<TbGardenImg>()
+                    .in(TbGardenImg::getGardenId, id)
+            );
+
+            familyGarden.setImgList(eventImgs);
+        }
+        return familyGarden;
+    }
 }

+ 18 - 0
ruoyi-system/src/main/java/com/ruoyi/app/service/impl/TbGardenImgServiceImpl.java

@@ -0,0 +1,18 @@
+package com.ruoyi.app.service.impl;
+
+import org.springframework.stereotype.Service;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.app.mapper.TbGardenImgMapper;
+import com.ruoyi.app.domain.TbGardenImg;
+import com.ruoyi.app.service.ITbGardenImgService;
+
+/**
+ * 家族园地图片
+ *
+ * @author liuhj
+ * @date 2020-10-22
+ */
+@Service
+public class TbGardenImgServiceImpl extends ServiceImpl<TbGardenImgMapper, TbGardenImg> implements ITbGardenImgService {
+
+}

+ 14 - 0
ruoyi-system/src/main/resources/mapper/app/TbGardenImgMapper.xml

@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.ruoyi.app.mapper.TbGardenImgMapper">
+    
+    <resultMap type="TbGardenImg" id="TbGardenImgResult">
+        <result property="id"    column="id"    />
+        <result property="gardenId"    column="garden_id"    />
+        <result property="url"    column="url"    />
+    </resultMap>
+
+
+</mapper>