瀏覽代碼

图片管理

Wang-Xiao-Ran 1 年之前
父節點
當前提交
5db83315c8

+ 128 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/my/JnbImgController.java

@@ -0,0 +1,128 @@
+package com.ruoyi.web.controller.my;
+
+import java.util.List;
+import javax.servlet.http.HttpServletResponse;
+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.sooka.jnb.my.domain.JnbImg;
+import com.sooka.jnb.my.service.IJnbImgService;
+import com.ruoyi.common.utils.poi.ExcelUtil;
+import com.ruoyi.common.core.page.TableDataInfo;
+
+/**
+ * 图片管理Controller
+ * 
+ * @author LG
+ * @date 2024-03-05
+ */
+@RestController
+@RequestMapping("/my/img")
+public class JnbImgController extends BaseController
+{
+    @Autowired
+    private IJnbImgService jnbImgService;
+
+    /**
+     * 查询图片管理列表
+     */
+    @PreAuthorize("@ss.hasPermi('my:img:list')")
+    @GetMapping("/list")
+    public TableDataInfo list(JnbImg jnbImg)
+    {
+        startPage();
+        List<JnbImg> list = jnbImgService.selectJnbImgList(jnbImg);
+        return getDataTable(list);
+    }
+
+    /**
+     * 导出图片管理列表
+     */
+    @PreAuthorize("@ss.hasPermi('my:img:export')")
+    @Log(title = "图片管理", businessType = BusinessType.EXPORT)
+    @PostMapping("/export")
+    public void export(HttpServletResponse response, JnbImg jnbImg)
+    {
+        List<JnbImg> list = jnbImgService.selectJnbImgList(jnbImg);
+        ExcelUtil<JnbImg> util = new ExcelUtil<JnbImg>(JnbImg.class);
+        util.exportExcel(response, list, "图片管理数据");
+    }
+
+    /**
+     * 获取图片管理详细信息
+     */
+    @PreAuthorize("@ss.hasPermi('my:img:query')")
+    @GetMapping(value = "/{id}")
+    public AjaxResult getInfo(@PathVariable("id") Long id)
+    {
+        return success(jnbImgService.selectJnbImgById(id));
+    }
+
+    /**
+     * 新增图片管理
+     */
+    @PreAuthorize("@ss.hasPermi('my:img:add')")
+    @Log(title = "图片管理", businessType = BusinessType.INSERT)
+    @PostMapping
+    public AjaxResult add(@RequestBody JnbImg jnbImg)
+    {
+        return toAjax(jnbImgService.insertJnbImg(jnbImg));
+    }
+
+    /**
+     * 修改图片管理
+     */
+    @PreAuthorize("@ss.hasPermi('my:img:edit')")
+    @Log(title = "图片管理", businessType = BusinessType.UPDATE)
+    @PutMapping
+    public AjaxResult edit(@RequestBody JnbImg jnbImg)
+    {
+        return toAjax(jnbImgService.updateJnbImg(jnbImg));
+    }
+
+    /**
+     * 删除图片管理
+     */
+    @PreAuthorize("@ss.hasPermi('my:img:remove')")
+    @Log(title = "图片管理", businessType = BusinessType.DELETE)
+	@DeleteMapping("/{ids}")
+    public AjaxResult remove(@PathVariable Long[] ids)
+    {
+        return toAjax(jnbImgService.deleteJnbImgByIds(ids));
+    }
+
+    /**
+     * 查看是否存在封面图片
+     */
+    @GetMapping("/isCover")
+    public AjaxResult isCover(){
+        return AjaxResult.success(jnbImgService.isCover());
+    }
+
+    /**
+     * 获取当前封面图片
+     */
+    @GetMapping("/getCover")
+    public AjaxResult getCover(){
+        return AjaxResult.success("操作成功",jnbImgService.getCover());
+    }
+
+    /**
+     * 获取当前轮播图
+     */
+    @GetMapping("/getCarousel")
+    public AjaxResult getCarousel() {
+        return AjaxResult.success(jnbImgService.getCarousel());
+    }
+}

+ 1 - 1
ruoyi-admin/src/main/java/com/ruoyi/web/controller/my/ScoreController.java

@@ -87,7 +87,7 @@ public class ScoreController extends BaseController {
                 return AjaxResult.error("减少积分失败!");
             }
         } else {
-            return AjaxResult.error("用户积分不足, 减少积分失败!");
+            return AjaxResult.error("用户积分不足!");
         }
     }
 

+ 57 - 0
sooka-jnb/src/main/java/com/sooka/jnb/my/domain/JnbImg.java

@@ -0,0 +1,57 @@
+package com.sooka.jnb.my.domain;
+
+import lombok.Data;
+import org.apache.commons.lang3.builder.ToStringBuilder;
+import org.apache.commons.lang3.builder.ToStringStyle;
+import com.ruoyi.common.annotation.Excel;
+import com.ruoyi.common.core.domain.BaseEntity;
+import org.apache.ibatis.type.Alias;
+
+/**
+ * 图片管理对象 jnb_img
+ *
+ * @author LG
+ * @date 2024-03-05
+ */
+@Data
+@Alias("jnbImg")
+public class JnbImg extends BaseEntity {
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 数据id
+     */
+    private Long id;
+
+    /**
+     * 图片路径
+     */
+    private String imgUrl;
+
+    /**
+     * 图片名称
+     */
+    private String imgName;
+
+    /**
+     * 开关
+     */
+    private String imgSwitch;
+
+    /**
+     * 图片类型:1封面图片;2:轮播图片
+     */
+    private String imgType;
+
+
+    @Override
+    public String toString() {
+        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
+                .append("id", getId())
+                .append("imgUrl", getImgUrl())
+                .append("imgName", getImgName())
+                .append("switch", getImgSwitch())
+                .append("imgType", getImgType())
+                .toString();
+    }
+}

+ 68 - 0
sooka-jnb/src/main/java/com/sooka/jnb/my/mapper/JnbImgMapper.java

@@ -0,0 +1,68 @@
+package com.sooka.jnb.my.mapper;
+
+import java.util.List;
+import java.util.Map;
+
+import com.sooka.jnb.my.domain.JnbImg;
+
+/**
+ * 图片管理Mapper接口
+ *
+ * @author LG
+ * @date 2024-03-05
+ */
+public interface JnbImgMapper {
+    /**
+     * 查询图片管理
+     *
+     * @param id 图片管理主键
+     * @return 图片管理
+     */
+    public JnbImg selectJnbImgById(Long id);
+
+    /**
+     * 查询图片管理列表
+     *
+     * @param jnbImg 图片管理
+     * @return 图片管理集合
+     */
+    public List<JnbImg> selectJnbImgList(JnbImg jnbImg);
+
+    /**
+     * 新增图片管理
+     *
+     * @param jnbImg 图片管理
+     * @return 结果
+     */
+    public int insertJnbImg(JnbImg jnbImg);
+
+    /**
+     * 修改图片管理
+     *
+     * @param jnbImg 图片管理
+     * @return 结果
+     */
+    public int updateJnbImg(JnbImg jnbImg);
+
+    /**
+     * 删除图片管理
+     *
+     * @param id 图片管理主键
+     * @return 结果
+     */
+    public int deleteJnbImgById(Long id);
+
+    /**
+     * 批量删除图片管理
+     *
+     * @param ids 需要删除的数据主键集合
+     * @return 结果
+     */
+    public int deleteJnbImgByIds(Long[] ids);
+
+    Map<String, String> isCover();
+
+    String getCover();
+
+    List<String> getCarousel();
+}

+ 67 - 0
sooka-jnb/src/main/java/com/sooka/jnb/my/service/IJnbImgService.java

@@ -0,0 +1,67 @@
+package com.sooka.jnb.my.service;
+
+import java.util.List;
+
+import com.sooka.jnb.my.domain.JnbImg;
+
+/**
+ * 图片管理Service接口
+ *
+ * @author LG
+ * @date 2024-03-05
+ */
+public interface IJnbImgService {
+    /**
+     * 查询图片管理
+     *
+     * @param id 图片管理主键
+     * @return 图片管理
+     */
+    public JnbImg selectJnbImgById(Long id);
+
+    /**
+     * 查询图片管理列表
+     *
+     * @param jnbImg 图片管理
+     * @return 图片管理集合
+     */
+    public List<JnbImg> selectJnbImgList(JnbImg jnbImg);
+
+    /**
+     * 新增图片管理
+     *
+     * @param jnbImg 图片管理
+     * @return 结果
+     */
+    public int insertJnbImg(JnbImg jnbImg);
+
+    /**
+     * 修改图片管理
+     *
+     * @param jnbImg 图片管理
+     * @return 结果
+     */
+    public int updateJnbImg(JnbImg jnbImg);
+
+    /**
+     * 批量删除图片管理
+     *
+     * @param ids 需要删除的图片管理主键集合
+     * @return 结果
+     */
+    public int deleteJnbImgByIds(Long[] ids);
+
+    /**
+     * 删除图片管理信息
+     *
+     * @param id 图片管理主键
+     * @return 结果
+     */
+    public int deleteJnbImgById(Long id);
+
+    boolean isCover();
+
+    String getCover();
+
+    List<String> getCarousel();
+}

+ 108 - 0
sooka-jnb/src/main/java/com/sooka/jnb/my/service/impl/JnbImgServiceImpl.java

@@ -0,0 +1,108 @@
+package com.sooka.jnb.my.service.impl;
+
+import com.sooka.jnb.my.domain.JnbImg;
+import com.sooka.jnb.my.mapper.JnbImgMapper;
+import com.sooka.jnb.my.service.IJnbImgService;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 图片管理Service业务层处理
+ *
+ * @author LG
+ * @date 2024-03-05
+ */
+@Service
+public class JnbImgServiceImpl implements IJnbImgService {
+    @Resource
+    private JnbImgMapper jnbImgMapper;
+
+    /**
+     * 查询图片管理
+     *
+     * @param id 图片管理主键
+     * @return 图片管理
+     */
+    @Override
+    public JnbImg selectJnbImgById(Long id) {
+        return jnbImgMapper.selectJnbImgById(id);
+    }
+
+    /**
+     * 查询图片管理列表
+     *
+     * @param jnbImg 图片管理
+     * @return 图片管理
+     */
+    @Override
+    public List<JnbImg> selectJnbImgList(JnbImg jnbImg) {
+        return jnbImgMapper.selectJnbImgList(jnbImg);
+    }
+
+    /**
+     * 新增图片管理
+     *
+     * @param jnbImg 图片管理
+     * @return 结果
+     */
+    @Override
+    public int insertJnbImg(JnbImg jnbImg) {
+        return jnbImgMapper.insertJnbImg(jnbImg);
+    }
+
+    /**
+     * 修改图片管理
+     *
+     * @param jnbImg 图片管理
+     * @return 结果
+     */
+    @Override
+    public int updateJnbImg(JnbImg jnbImg) {
+        return jnbImgMapper.updateJnbImg(jnbImg);
+    }
+
+    /**
+     * 批量删除图片管理
+     *
+     * @param ids 需要删除的图片管理主键
+     * @return 结果
+     */
+    @Override
+    public int deleteJnbImgByIds(Long[] ids) {
+        return jnbImgMapper.deleteJnbImgByIds(ids);
+    }
+
+    /**
+     * 删除图片管理信息
+     *
+     * @param id 图片管理主键
+     * @return 结果
+     */
+    @Override
+    public int deleteJnbImgById(Long id) {
+        return jnbImgMapper.deleteJnbImgById(id);
+    }
+
+    @Override
+    public boolean isCover() {
+        Map<String, String> cover = jnbImgMapper.isCover();
+        if ("1".equals(cover.get("isCover"))) {
+            return true;
+        }else{
+            return false;
+        }
+    }
+
+    @Override
+    public String getCover() {
+        return jnbImgMapper.getCover();
+    }
+
+    @Override
+    public List<String> getCarousel() {
+        return jnbImgMapper.getCarousel();
+    }
+}

+ 91 - 0
sooka-jnb/src/main/resources/mapper/my/JnbImgMapper.xml

@@ -0,0 +1,91 @@
+<?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.sooka.jnb.my.mapper.JnbImgMapper">
+
+    <resultMap type="JnbImg" id="JnbImgResult">
+        <result property="id" column="id"/>
+        <result property="imgUrl" column="img_url"/>
+        <result property="imgName" column="img_name"/>
+        <result property="imgSwitch" column="img_switch"/>
+        <result property="imgType" column="img_type"/>
+    </resultMap>
+
+    <sql id="selectJnbImgVo">
+        select id, img_url, img_name, img_switch, img_type
+        from jnb_img
+    </sql>
+
+    <select id="selectJnbImgList" parameterType="JnbImg" resultMap="JnbImgResult">
+        <include refid="selectJnbImgVo"/>
+        <where>
+            <if test="imgUrl != null  and imgUrl != ''">and img_url = #{imgUrl}</if>
+            <if test="imgName != null  and imgName != ''">and img_name like concat('%', #{imgName}, '%')</if>
+            <if test="imgSwitch != null  and imgSwitch != ''">and img_switch = #{imgSwitch}</if>
+            <if test="imgType != null  and imgType != ''">and img_type = #{imgType}</if>
+        </where>
+    </select>
+
+    <select id="selectJnbImgById" parameterType="Long" resultMap="JnbImgResult">
+        <include refid="selectJnbImgVo"/>
+        where id = #{id}
+    </select>
+
+    <insert id="insertJnbImg" parameterType="JnbImg" useGeneratedKeys="true" keyProperty="id">
+        insert into jnb_img
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="imgUrl != null and imgUrl != ''">img_url,</if>
+            <if test="imgName != null and imgName != ''">img_name,</if>
+            <if test="imgSwitch != null and imgSwitch != ''">img_switch,</if>
+            <if test="imgType != null and imgType != ''">img_type,</if>
+        </trim>
+        <trim prefix="values (" suffix=")" suffixOverrides=",">
+            <if test="imgUrl != null and imgUrl != ''">#{imgUrl},</if>
+            <if test="imgName != null and imgName != ''">#{imgName},</if>
+            <if test="imgSwitch != null and imgSwitch != ''">#{imgSwitch},</if>
+            <if test="imgType != null and imgType != ''">#{imgType},</if>
+        </trim>
+    </insert>
+
+    <update id="updateJnbImg" parameterType="JnbImg">
+        update jnb_img
+        <trim prefix="SET" suffixOverrides=",">
+            <if test="imgUrl != null and imgUrl != ''">img_url = #{imgUrl},</if>
+            <if test="imgName != null and imgName != ''">img_name = #{imgName},</if>
+            <if test="imgSwitch != null and imgSwitch != ''">img_switch = #{imgSwitch},</if>
+            <if test="imgType != null and imgType != ''">img_type = #{imgType},</if>
+        </trim>
+        where id = #{id}
+    </update>
+
+    <delete id="deleteJnbImgById" parameterType="Long">
+        delete
+        from jnb_img
+        where id = #{id}
+    </delete>
+
+    <delete id="deleteJnbImgByIds" parameterType="String">
+        delete from jnb_img where id in
+        <foreach item="id" collection="array" open="(" separator="," close=")">
+            #{id}
+        </foreach>
+    </delete>
+
+    <select id="isCover" resultType="map">
+        SELECT
+            CASE WHEN COUNT(*) > 0 THEN '1' ELSE '0' END AS isCover
+        FROM
+            jnb_img
+        WHERE
+            img_type = 1 AND img_switch = 'switch_on'
+    </select>
+
+    <select id="getCover" resultType="string">
+        SELECT img_url FROM jnb_img WHERE img_type = 1 AND img_switch = 'switch_on'
+    </select>
+
+    <select id="getCarousel" resultType="string">
+        SELECT img_url FROM jnb_img WHERE img_type = 2 AND img_switch = 'switch_on'
+    </select>
+</mapper>