Prechádzať zdrojové kódy

添加家族大事件图片、修改家族大事件模块以及app接口

liuhj 4 rokov pred
rodič
commit
049a25fdf4

+ 121 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TbEventsImgController.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.TbEventsImg;
+import com.ruoyi.app.service.ITbEventsImgService;
+import com.ruoyi.common.utils.poi.ExcelUtil;
+import com.ruoyi.common.core.page.TableDataInfo;
+
+/**
+ * 家族大事件图片
+ * 
+ * @author liuhj
+ * @date 2020-10-21
+ */
+@Api(value = "家族大事件图片", tags = "家族大事件图片")
+@RequiredArgsConstructor(onConstructor_ = @Autowired)
+@RestController
+@RequestMapping("/system/img" )
+public class TbEventsImgController extends BaseController {
+
+    private final ITbEventsImgService iTbEventsImgService;
+
+    /**
+     * 查询家族大事件图片列表
+     */
+    @ApiOperation("查询家族大事件图片列表")
+    @PreAuthorize("@ss.hasPermi('system:img:list')")
+    @GetMapping("/list")
+    public TableDataInfo list(TbEventsImg tbEventsImg)
+    {
+        startPage();
+        LambdaQueryWrapper<TbEventsImg> lqw = new LambdaQueryWrapper<TbEventsImg>();
+        if (tbEventsImg.getEventsId() != null){
+            lqw.eq(TbEventsImg::getEventsId ,tbEventsImg.getEventsId());
+        }
+        if (StringUtils.isNotBlank(tbEventsImg.getUrl())){
+            lqw.eq(TbEventsImg::getUrl ,tbEventsImg.getUrl());
+        }
+        List<TbEventsImg> list = iTbEventsImgService.list(lqw);
+        return getDataTable(list);
+    }
+
+    /**
+     * 导出家族大事件图片列表
+     */
+    @ApiOperation("导出家族大事件图片列表")
+    @PreAuthorize("@ss.hasPermi('system:img:export')" )
+    @Log(title = "家族大事件图片" , businessType = BusinessType.EXPORT)
+    @GetMapping("/export" )
+    public AjaxResult export(TbEventsImg tbEventsImg) {
+        LambdaQueryWrapper<TbEventsImg> lqw = new LambdaQueryWrapper<TbEventsImg>(tbEventsImg);
+        List<TbEventsImg> list = iTbEventsImgService.list(lqw);
+        ExcelUtil<TbEventsImg> util = new ExcelUtil<TbEventsImg>(TbEventsImg. 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(iTbEventsImgService.getById(id));
+    }
+
+    /**
+     * 新增家族大事件图片
+     */
+    @ApiOperation("新增家族大事件图片")
+    @PreAuthorize("@ss.hasPermi('system:img:add')" )
+    @Log(title = "家族大事件图片" , businessType = BusinessType.INSERT)
+    @PostMapping
+    public AjaxResult add(@RequestBody TbEventsImg tbEventsImg) {
+        return toAjax(iTbEventsImgService.save(tbEventsImg) ? 1 : 0);
+    }
+
+    /**
+     * 修改家族大事件图片
+     */
+    @ApiOperation("修改家族大事件图片")
+    @PreAuthorize("@ss.hasPermi('system:img:edit')" )
+    @Log(title = "家族大事件图片" , businessType = BusinessType.UPDATE)
+    @PutMapping
+    public AjaxResult edit(@RequestBody TbEventsImg tbEventsImg) {
+        return toAjax(iTbEventsImgService.updateById(tbEventsImg) ? 1 : 0);
+    }
+
+    /**
+     * 删除家族大事件图片
+     */
+    @ApiOperation("删除家族大事件图片")
+    @PreAuthorize("@ss.hasPermi('system:img:remove')" )
+    @Log(title = "家族大事件图片" , businessType = BusinessType.DELETE)
+    @DeleteMapping("/{ids}" )
+    public AjaxResult remove(@PathVariable Long[] ids) {
+        return toAjax(iTbEventsImgService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
+    }
+}

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

@@ -77,7 +77,7 @@ public class TbFamilyEventsController extends BaseController {
     @PreAuthorize("@ss.hasPermi('system:events:query')" )
     @GetMapping(value = "/{id}" )
     public AjaxResult getInfo(@PathVariable("id" ) Long id) {
-        return AjaxResult.success(iTbFamilyEventsService.getById(id));
+        return AjaxResult.success(iTbFamilyEventsService.getFamilyEvents(id));
     }
 
     /**

+ 19 - 2
ruoyi-app/src/main/java/com/ruoyi/app/controller/FamilyEventsController.java

@@ -1,7 +1,10 @@
 package com.ruoyi.app.controller;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.ruoyi.app.domain.TbEventsImg;
 import com.ruoyi.app.domain.TbFamilyEvents;
+import com.ruoyi.app.domain.TbPublishImg;
+import com.ruoyi.app.service.ITbEventsImgService;
 import com.ruoyi.app.service.ITbFamilyEventsService;
 import com.ruoyi.common.annotation.Log;
 import com.ruoyi.common.core.controller.BaseController;
@@ -33,6 +36,9 @@ import java.util.List;
 public class FamilyEventsController extends BaseController {
 
     private final ITbFamilyEventsService iTbFamilyEventsService;
+    @Autowired
+    private ITbEventsImgService eventsImgService;
+
 
     /**
      * 查询家族大事件列表
@@ -53,7 +59,7 @@ public class FamilyEventsController extends BaseController {
     @ApiOperation(value = "家族大事件详细信息", notes = "家族大事件详细信息")
     @GetMapping(value = "/{id}" )
     public AjaxResult detail(@PathVariable("id" ) Long id) {
-        return AjaxResult.success(iTbFamilyEventsService.getById(id));
+        return AjaxResult.success(iTbFamilyEventsService.getFamilyEvents(id));
     }
 
     /**
@@ -63,7 +69,18 @@ public class FamilyEventsController extends BaseController {
     @Log(title = "家族大事件" , businessType = BusinessType.INSERT)
     @PostMapping("/add")
     public AjaxResult add(@RequestBody TbFamilyEvents tbFamilyEvents) {
-        return toAjax(iTbFamilyEventsService.save(tbFamilyEvents) ? 1 : 0);
+        // 插入图片列表
+        List<TbEventsImg> imgList = tbFamilyEvents.getImgList();
+        if (imgList.size() <= 0) {
+            return AjaxResult.success();
+        }
+        imgList.forEach(item -> {
+            item.setEventsId(tbFamilyEvents.getId());
+        });
+        if(eventsImgService.saveBatch(imgList)){
+            return AjaxResult.success();
+        }
+        return AjaxResult.error("发表失败");
     }
 
     /**

+ 52 - 0
ruoyi-system/src/main/java/com/ruoyi/app/domain/TbEventsImg.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-21
+ */
+@Data
+@ApiModel(value = "家族大事件图片")
+@ToString
+@EqualsAndHashCode
+@NoArgsConstructor
+@Accessors(chain = true)
+@TableName("tb_events_img")
+public class TbEventsImg 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 eventsId;
+
+    /** 图片url */
+    @ApiModelProperty(value="图片url")
+    @Excel(name = "图片url")
+    private String url;
+}

+ 9 - 0
ruoyi-system/src/main/java/com/ruoyi/app/domain/TbFamilyEvents.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;
 
 /**
@@ -81,4 +83,11 @@ public class TbFamilyEvents implements Serializable {
     @ApiModelProperty(value = "家族信息")
     @TableField(exist = false)
     private TbFamily family;
+
+    /**
+     * 图片列表
+     */
+    @ApiModelProperty(value="图片列表")
+    @TableField(exist = false)
+    private List<TbEventsImg> imgList;
 }

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

@@ -0,0 +1,14 @@
+package com.ruoyi.app.mapper;
+
+import com.ruoyi.app.domain.TbEventsImg;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * 家族大事件图片
+ *
+ * @author liuhj
+ * @date 2020-10-21
+ */
+public interface TbEventsImgMapper extends BaseMapper<TbEventsImg> {
+
+}

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

@@ -0,0 +1,14 @@
+package com.ruoyi.app.service;
+
+import com.ruoyi.app.domain.TbEventsImg;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+ * 家族大事件图片
+ *
+ * @author liuhj
+ * @date 2020-10-21
+ */
+public interface ITbEventsImgService extends IService<TbEventsImg> {
+
+}

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

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

+ 18 - 0
ruoyi-system/src/main/java/com/ruoyi/app/service/impl/TbEventsImgServiceImpl.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.TbEventsImgMapper;
+import com.ruoyi.app.domain.TbEventsImg;
+import com.ruoyi.app.service.ITbEventsImgService;
+
+/**
+ * 家族大事件图片
+ *
+ * @author liuhj
+ * @date 2020-10-21
+ */
+@Service
+public class TbEventsImgServiceImpl extends ServiceImpl<TbEventsImgMapper, TbEventsImg> implements ITbEventsImgService {
+
+}

+ 43 - 2
ruoyi-system/src/main/java/com/ruoyi/app/service/impl/TbFamilyEventsServiceImpl.java

@@ -1,16 +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.*;
+import com.ruoyi.app.service.ITbEventsImgService;
 import com.ruoyi.app.service.ITbFamilyService;
 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.TbFamilyEventsMapper;
-import com.ruoyi.app.domain.TbFamilyEvents;
 import com.ruoyi.app.service.ITbFamilyEventsService;
 
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -23,6 +24,9 @@ import java.util.List;
 public class TbFamilyEventsServiceImpl extends ServiceImpl<TbFamilyEventsMapper, TbFamilyEvents> implements ITbFamilyEventsService {
     @Autowired
     private ITbFamilyService familyService;
+    @Autowired
+    private ITbEventsImgService eventsImgService;
+
 
 
     @Override
@@ -40,7 +44,44 @@ public class TbFamilyEventsServiceImpl extends ServiceImpl<TbFamilyEventsMapper,
             item.setFamily(family);
         });
 
+        List<Long> ids = new ArrayList<>();
+        list.forEach(item -> {
+            ids.add(item.getId());
+        });
+        List<TbEventsImg> imgList = eventsImgService.list(new LambdaQueryWrapper<TbEventsImg>()
+                .in(TbEventsImg::getEventsId, ids)
+        );
+        list.forEach(item -> {
+            // 加入图片列表
+            List<TbEventsImg> imgs = new ArrayList<>();
+            imgList.forEach(img -> {
+                if (img.getEventsId().equals(item.getId())) {
+                    imgs.add(img);
+                }
+            });
+            item.setImgList(imgs);
+        });
+
         return list;
     }
 
+    /**
+     * 家族大事件详情
+     * @param id
+     * @return
+     */
+    @Override
+    public TbFamilyEvents getFamilyEvents(Long id) {
+        TbFamilyEvents familyEvents = this.getById(id);
+        if (familyEvents != null) {
+            List<TbEventsImg> eventImgs = eventsImgService.list(new LambdaQueryWrapper<TbEventsImg>()
+                    .in(TbEventsImg::getEventsId, id)
+            );
+
+            familyEvents.setImgList(eventImgs);
+        }
+        return familyEvents;
+    }
+
+
 }

+ 14 - 0
ruoyi-system/src/main/resources/mapper/app/TbEventsImgMapper.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.TbEventsImgMapper">
+    
+    <resultMap type="TbEventsImg" id="TbEventsImgResult">
+        <result property="id"    column="id"    />
+        <result property="eventsId"    column="events_id"    />
+        <result property="url"    column="url"    />
+    </resultMap>
+
+
+</mapper>