Browse Source

添加个人详情图片

Alex 4 years ago
parent
commit
a0d37fa2c4

+ 126 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TbProfileImgController.java

@@ -0,0 +1,126 @@
+package com.ruoyi.web.controller.api;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.ruoyi.app.domain.TbProfileImg;
+import com.ruoyi.app.service.ITbProfileImgService;
+import com.ruoyi.common.annotation.Log;
+import com.ruoyi.common.core.controller.BaseController;
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.core.page.TableDataInfo;
+import com.ruoyi.common.enums.BusinessType;
+import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.common.utils.poi.ExcelUtil;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiOperation;
+import lombok.RequiredArgsConstructor;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * 个人详情图片
+ * 
+ * @author Alex
+ * @date 2020-11-05
+ */
+@Api(value = "个人详情图片", tags = "个人详情图片")
+@RequiredArgsConstructor(onConstructor_ = @Autowired)
+@RestController
+@RequestMapping("/system/profile/img" )
+public class TbProfileImgController extends BaseController {
+
+    private final ITbProfileImgService profileImgService;
+
+    /**
+     * 查询个人详情图片列表
+     */
+    @ApiOperation("查询个人详情图片分页列表")
+    @PreAuthorize("@ss.hasPermi('system:profile:img:list')")
+    @GetMapping("/list")
+    public TableDataInfo list(TbProfileImg tbProfileImg)
+    {
+        startPage();
+        LambdaQueryWrapper<TbProfileImg> lqw = new LambdaQueryWrapper<TbProfileImg>();
+        if (tbProfileImg.getProfileId() != null){
+            lqw.eq(TbProfileImg::getProfileId ,tbProfileImg.getProfileId());
+        }
+        if (StringUtils.isNotBlank(tbProfileImg.getUrl())){
+            lqw.eq(TbProfileImg::getUrl ,tbProfileImg.getUrl());
+        }
+        List<TbProfileImg> list = profileImgService.list(lqw);
+        return getDataTable(list);
+    }
+
+    /**
+     * 获取个人详情图片详细信息
+     */
+    @ApiOperation("获取个人详情图片详细信息")
+    @PreAuthorize("@ss.hasPermi('system:profile:img:query')" )
+    @GetMapping(value = "/{id}" )
+    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
+        return AjaxResult.success(profileImgService.getById(id));
+    }
+
+    /**
+     * 新增个人详情图片
+     */
+    @ApiOperation("新增个人详情图片")
+    @PreAuthorize("@ss.hasPermi('system:profile:img:add')" )
+    @Log(title = "个人详情图片" , businessType = BusinessType.INSERT)
+    @PostMapping
+    public AjaxResult add(@RequestBody TbProfileImg tbProfileImg) {
+        return toAjax(profileImgService.save(tbProfileImg) ? 1 : 0);
+    }
+
+    /**
+     * 修改个人详情图片
+     */
+    @ApiOperation("修改个人详情图片")
+    @PreAuthorize("@ss.hasPermi('system:profile:img:edit')" )
+    @Log(title = "个人详情图片" , businessType = BusinessType.UPDATE)
+    @PutMapping
+    public AjaxResult edit(@RequestBody TbProfileImg tbProfileImg) {
+        return toAjax(profileImgService.updateById(tbProfileImg) ? 1 : 0);
+    }
+
+    /**
+     * 删除个人详情图片
+     */
+    @ApiOperation("删除多张个人详情图片")
+    @PreAuthorize("@ss.hasPermi('system:profile:img:remove')" )
+    @Log(title = "个人详情图片" , businessType = BusinessType.DELETE)
+    @DeleteMapping("/{ids}" )
+    public AjaxResult remove(@PathVariable Long[] ids) {
+        return toAjax(profileImgService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
+    }
+
+    @ApiOperation("删除单张个人详情 图片")
+    @PreAuthorize("@ss.hasPermi('system:profile:img:remove')" )
+    @Log(title = "个人详情图片" , businessType = BusinessType.DELETE)
+    @ApiImplicitParam(name = "id", value = "图片id",paramType="Long")
+    @GetMapping("/delImg")
+    public AjaxResult delImg(Long id) {
+        if (id == null){
+            return AjaxResult.error("id不能为空");
+        }
+        return toAjax(profileImgService.removeById(id) ? 1 : 0);
+    }
+
+    @ApiOperation("获取个人详情 图片列表")
+    @PreAuthorize("@ss.hasPermi('system:profile:img:list')")
+    @ApiImplicitParam(name = "profileId", value = "详情id",paramType="Long")
+    @GetMapping("/getByProfileId/{profileId}")
+    public AjaxResult listImg(Long profileId) {
+        if (profileId == null){
+            return AjaxResult.error("详情Id不能为空");
+        }
+        List<TbProfileImg> list = profileImgService.list(new LambdaQueryWrapper<TbProfileImg>()
+                .eq(TbProfileImg::getProfileId, profileId)
+        );
+        return AjaxResult.success(list);
+    }
+}

+ 54 - 3
ruoyi-app/src/main/java/com/ruoyi/app/controller/MyProfileController.java

@@ -5,8 +5,12 @@ import com.ruoyi.app.annotation.LoginAppUser;
 import com.ruoyi.app.controller.base.AppBaseController;
 import com.ruoyi.app.domain.TbAppUser;
 import com.ruoyi.app.domain.TbMyProfile;
+import com.ruoyi.app.domain.TbProfileImg;
+import com.ruoyi.app.domain.TbPublishImg;
 import com.ruoyi.app.domain.vo.AppMemberVo;
 import com.ruoyi.app.service.ITbMyProfileService;
+import com.ruoyi.app.service.ITbProfileImgService;
+import com.ruoyi.app.service.ITbPublishImgService;
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.utils.StringUtils;
 import io.swagger.annotations.Api;
@@ -32,6 +36,7 @@ import java.util.List;
 public class MyProfileController extends AppBaseController {
 
     private final ITbMyProfileService profileService;
+    private final ITbProfileImgService profileImgService;
 
     @ApiOperation("个人详情列表")
     @ApiImplicitParam(name = "appUserId", value = "会员ID",paramType="Long")
@@ -61,13 +66,24 @@ public class MyProfileController extends AppBaseController {
         if (profile.getId() == null) {
             profile.setCreateBy(user.getUserId());
             profile.setCreateTime(date);
-            return toAjax(profileService.save(profile) ? 1 : 0);
         } else {
             // 修改
             profile.setUpdateBy(user.getUserId());
             profile.setUpdateTime(date);
-            return toAjax(profileService.updateById(profile) ? 1 : 0);
         }
+
+        if (profile.getImgList().size() > 0) {
+            //先删除,在重新添加图片
+            profileImgService.remove(new LambdaQueryWrapper<TbProfileImg>()
+                    .eq(TbProfileImg::getProfileId, profile.getId())
+            );
+            List<TbProfileImg> imgList = profile.getImgList();
+            imgList.forEach(item -> {
+                item.setProfileId(profile.getId());
+            });
+            profileImgService.saveBatch(imgList);
+        }
+        return toAjax(profileService.saveOrUpdate(profile) ? 1 : 0);
     }
 
     @ApiOperation("获取个人详情")
@@ -77,7 +93,18 @@ public class MyProfileController extends AppBaseController {
         if (id == null){
             return AjaxResult.error("id不能为空");
         }
-        return AjaxResult.success(profileService.getById(id));
+        TbMyProfile profile = profileService.getById(id);
+        if (profile == null) {
+            return AjaxResult.success();
+        }
+        // 图片列表
+        List<TbProfileImg> imgList = profileImgService.list(new LambdaQueryWrapper<TbProfileImg>()
+            .eq(TbProfileImg::getProfileId, profile.getId())
+        );
+        if (imgList.size() > 0) {
+            profile.setImgList(imgList);
+        }
+        return AjaxResult.success(profile);
     }
 
     @ApiOperation("删除个人详情")
@@ -89,4 +116,28 @@ public class MyProfileController extends AppBaseController {
         }
         return toAjax(profileService.removeById(id) ? 1 : 0);
     }
+
+    @ApiOperation("删除个人详情 图片")
+    @ApiImplicitParam(name = "id", value = "图片id",paramType="Long")
+    @GetMapping("/delImg")
+    public AjaxResult delImg(Long id) {
+        if (id == null){
+            return AjaxResult.error("id不能为空");
+        }
+        return toAjax(profileImgService.removeById(id) ? 1 : 0);
+    }
+
+    @ApiOperation("获取个人详情 图片列表")
+    @ApiImplicitParam(name = "profileId", value = "详情id",paramType="Long")
+    @GetMapping("/profileId")
+    public AjaxResult listImg(Long profileId) {
+        if (profileId == null){
+            return AjaxResult.error("详情Id不能为空");
+        }
+        List<TbProfileImg> list = profileImgService.list(new LambdaQueryWrapper<TbProfileImg>()
+            .eq(TbProfileImg::getProfileId, profileId)
+        );
+        return AjaxResult.success(list);
+    }
+
 }

+ 6 - 0
ruoyi-system/src/main/java/com/ruoyi/app/domain/TbMyProfile.java

@@ -15,6 +15,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;
 
 /**
@@ -72,4 +74,8 @@ public class TbMyProfile implements Serializable {
     @ApiModelProperty(value="备注")
     @Excel(name = "备注")
     private String remark;
+
+    /** 图片列表 */
+    @ApiModelProperty(value="图片列表")
+    private List<TbProfileImg> imgList;
 }

+ 48 - 0
ruoyi-system/src/main/java/com/ruoyi/app/domain/TbProfileImg.java

@@ -0,0 +1,48 @@
+package com.ruoyi.app.domain;
+
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.ruoyi.common.annotation.Excel;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.NoArgsConstructor;
+import lombok.ToString;
+import lombok.experimental.Accessors;
+
+import java.io.Serializable;
+
+/**
+ * 个人详情图片
+ * 
+ * @author Alex
+ * @date 2020-11-05
+ */
+@Data
+@ApiModel(value = "个人详情图片")
+@ToString
+@EqualsAndHashCode
+@NoArgsConstructor
+@Accessors(chain = true)
+@TableName("tb_profile_img")
+public class TbProfileImg 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 profileId;
+
+    /** 图片 */
+    @ApiModelProperty(value="图片")
+    @Excel(name = "图片")
+    private String url;
+}

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

@@ -0,0 +1,14 @@
+package com.ruoyi.app.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.ruoyi.app.domain.TbProfileImg;
+
+/**
+ * 个人详情图片
+ *
+ * @author Alex
+ * @date 2020-11-05
+ */
+public interface TbProfileImgMapper extends BaseMapper<TbProfileImg> {
+
+}

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

@@ -0,0 +1,14 @@
+package com.ruoyi.app.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.ruoyi.app.domain.TbProfileImg;
+
+/**
+ * 个人详情图片
+ *
+ * @author Alex
+ * @date 2020-11-05
+ */
+public interface ITbProfileImgService extends IService<TbProfileImg> {
+
+}

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

@@ -0,0 +1,18 @@
+package com.ruoyi.app.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.app.domain.TbProfileImg;
+import com.ruoyi.app.mapper.TbProfileImgMapper;
+import com.ruoyi.app.service.ITbProfileImgService;
+import org.springframework.stereotype.Service;
+
+/**
+ * 个人详情图片
+ *
+ * @author Alex
+ * @date 2020-11-05
+ */
+@Service
+public class TbProfileImgServiceImpl extends ServiceImpl<TbProfileImgMapper, TbProfileImg> implements ITbProfileImgService {
+
+}

+ 13 - 0
ruoyi-system/src/main/resources/mapper/app/TbProfileImgMapper.xml

@@ -0,0 +1,13 @@
+<?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.TbProfileImgMapper">
+    
+    <resultMap type="TbProfileImg" id="TbProfileImgResult">
+        <result property="id"    column="id"    />
+        <result property="profileId"    column="profile_id"    />
+        <result property="url"    column="url"    />
+    </resultMap>
+
+</mapper>