Pārlūkot izejas kodu

资讯crud与图片上传

qinhouyu 1 gadu atpakaļ
vecāks
revīzija
75f7fe6dd6

+ 3 - 2
ruoyi-admin/src/main/java/com/ruoyi/web/controller/information/InformationController.java

@@ -4,6 +4,7 @@ import java.util.List;
 import javax.servlet.http.HttpServletResponse;
 
 import com.sooka.jnb.information.domain.Information;
+import com.sooka.jnb.information.domain.InformationVo;
 import com.sooka.jnb.information.service.InformationService;
 import io.swagger.models.auth.In;
 import org.springframework.cglib.transform.impl.InterceptFieldFilter;
@@ -78,7 +79,7 @@ public class InformationController extends BaseController
     @PreAuthorize("@ss.hasPermi('jnb:information:add')")
     @Log(title = "新增资讯", businessType = BusinessType.INSERT)
     @PostMapping
-    public AjaxResult add(@RequestBody Information information)
+    public AjaxResult add(@RequestBody InformationVo information)
     {
         return toAjax(informationService.insertInformationServer(information));
     }
@@ -89,7 +90,7 @@ public class InformationController extends BaseController
     @PreAuthorize("@ss.hasPermi('jnb:information:edit')")
     @Log(title = "修改资讯", businessType = BusinessType.UPDATE)
     @PutMapping
-    public AjaxResult edit(@RequestBody Information information)
+    public AjaxResult edit(@RequestBody InformationVo information)
     {
         return toAjax(informationService.updateInformation(information));
     }

+ 1 - 1
ruoyi-admin/src/main/resources/application.yml

@@ -22,7 +22,7 @@ fileServer:
 # 开发环境配置
 server:
   # 服务器的HTTP端口,默认为8080
-  port: 8080
+  port: 40000
   servlet:
     # 应用的访问路径
     context-path: /

+ 0 - 10
sooka-jnb/src/main/java/com/sooka/jnb/highServer/domain/JnbHighServerImg.java

@@ -33,10 +33,6 @@ public class JnbHighServerImg {
      */
     private Long serverId;
 
-    /**
-     * 图片
-     */
-    private String imgName;
 
     /**
      * url
@@ -44,12 +40,6 @@ public class JnbHighServerImg {
     private String imgUrl;
 
     /**
-     * $column.columnComment
-     */
-    @Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()")
-    private Integer type;
-
-    /**
      * 创建人
      */
     @TableField(value = "create_by", fill = FieldFill.INSERT)

+ 2 - 0
sooka-jnb/src/main/java/com/sooka/jnb/highServer/mapper/JnbHighServerImgMapper.java

@@ -13,4 +13,6 @@ public interface JnbHighServerImgMapper {
     public int deleteJnbHighServerByServerId(@Param("serverId") Long serverId);
 
     int saveJnbHighServerImg(List<JnbHighServerImg> saveList);
+
+    List<String> selectAll(Long serverId);
 }

+ 48 - 0
sooka-jnb/src/main/java/com/sooka/jnb/information/domain/InformationVo.java

@@ -0,0 +1,48 @@
+package com.sooka.jnb.information.domain;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.ruoyi.common.annotation.Excel;
+import com.ruoyi.common.core.domain.BaseEntity;
+import com.sooka.jnb.highServer.domain.JnbHighServerImg;
+import lombok.Data;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 资讯
+ * 
+ * @author ruoyi
+ * @date 2024-03-01
+ */
+@Data
+public class InformationVo extends BaseEntity
+{
+    private static final long serialVersionUID = 1L;
+
+    /** id */
+    private Long id;
+
+    /** 标题 */
+    private String titleName;
+
+    /** 正文 */
+    private String textDetails;
+
+    /** 是否政策推荐 */
+    private String isGovernment;
+
+    /** 是否置顶 */
+    private String isTop;
+
+    /** 点赞数 */
+    private Long likeNum;
+
+    /** 浏览数 */
+    private Long watchNum;
+
+    private Integer type;
+
+     private String imgUrlList;
+
+}

+ 1 - 0
sooka-jnb/src/main/java/com/sooka/jnb/information/mapper/InformationMapper.java

@@ -1,6 +1,7 @@
 package com.sooka.jnb.information.mapper;
 
 import com.sooka.jnb.information.domain.Information;
+import com.sooka.jnb.information.domain.InformationVo;
 import com.sooka.jnb.information.service.InformationService;
 
 import java.util.List;

+ 4 - 3
sooka-jnb/src/main/java/com/sooka/jnb/information/service/InformationService.java

@@ -1,6 +1,7 @@
 package com.sooka.jnb.information.service;
 
 import com.sooka.jnb.information.domain.Information;
+import com.sooka.jnb.information.domain.InformationVo;
 
 import java.util.List;
 
@@ -19,7 +20,7 @@ public interface InformationService
      * @param id 资讯主键
      * @return 资讯
      */
-    public Information selectInformationById(Long id);
+    public InformationVo selectInformationById(Long id);
 
     /**
      * 查询资讯服务列表
@@ -35,7 +36,7 @@ public interface InformationService
      * @param information 资讯
      * @return 结果
      */
-    public int insertInformationServer(Information information);
+    public int insertInformationServer(InformationVo information);
 
     /**
      * 修改资讯
@@ -43,7 +44,7 @@ public interface InformationService
      * @param information 资讯
      * @return 结果
      */
-    public int updateInformation(Information information);
+    public int updateInformation(InformationVo information);
 
     /**
      * 批量删除资讯

+ 77 - 10
sooka-jnb/src/main/java/com/sooka/jnb/information/service/impl/InformationServiceImpl.java

@@ -1,12 +1,24 @@
 package com.sooka.jnb.information.service.impl;
 
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
+import java.util.stream.Collectors;
+
 import com.ruoyi.common.utils.DateUtils;
+import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.common.utils.StringUtils;
+import com.sooka.jnb.highServer.domain.JnbHighServerImg;
+import com.sooka.jnb.highServer.mapper.JnbHighServerImgMapper;
 import com.sooka.jnb.information.domain.Information;
+import com.sooka.jnb.information.domain.InformationVo;
 import com.sooka.jnb.information.mapper.InformationMapper;
 import com.sooka.jnb.information.service.InformationService;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.ObjectUtils;
 
 /**
  * 高频服务Service业务层处理
@@ -19,11 +31,17 @@ public class InformationServiceImpl implements InformationService
 {
     @Autowired
     private InformationMapper informationMapper;
+    @Autowired
+    private JnbHighServerImgMapper jnbHighServerImgMapper;
 
     @Override
-    public Information selectInformationById(Long id)
+    public InformationVo selectInformationById(Long id)
     {
-        return informationMapper.selectInformationById(id);
+        Information information = informationMapper.selectInformationById(id);
+        InformationVo vo = new InformationVo();
+        vo.setImgUrlList(StringUtils.join(jnbHighServerImgMapper.selectAll(id)));
+        BeanUtils.copyProperties(information,vo);
+        return vo;
     }
 
 
@@ -35,30 +53,79 @@ public class InformationServiceImpl implements InformationService
 
 
     @Override
-    public int insertInformationServer(Information information)
+    @Transactional(rollbackFor = Exception.class)
+    public int insertInformationServer(InformationVo information)
     {
-        information.setCreateTime(DateUtils.getNowDate());
-        return informationMapper.insertInformation(information);
+        Information entity = new Information();
+        BeanUtils.copyProperties(information,entity);
+        entity.setCreateTime(DateUtils.getNowDate());
+        entity.setCreateBy(String.valueOf(SecurityUtils.getUserId()));
+        int i = informationMapper.insertInformation(entity);
+        if (i>0){
+            List<String> imgUrlList = Arrays.asList(information.getImgUrlList().split(","));
+            if (!ObjectUtils.isEmpty(imgUrlList)){
+                List<JnbHighServerImg> imgList = new ArrayList<>();
+                imgUrlList.forEach(a->{
+                    JnbHighServerImg serverImg = new JnbHighServerImg();
+                    serverImg.setCreateBy(String.valueOf(SecurityUtils.getUserId()));
+                    serverImg.setCreateTime(DateUtils.getNowDate());
+                    serverImg.setServerId(information.getId());
+                    serverImg.setImgUrl(a);
+                    imgList.add(serverImg);
+                });
+                jnbHighServerImgMapper.saveJnbHighServerImg(imgList);
+            }
+        }
+        return i;
     }
 
 
     @Override
-    public int updateInformation(Information information)
+    @Transactional(rollbackFor = Exception.class)
+    public int updateInformation(InformationVo information)
     {
-        information.setUpdateTime(DateUtils.getNowDate());
-        return informationMapper.updateInformation(information);
+        Information entity = new Information();
+        BeanUtils.copyProperties(information,entity);
+        entity.setUpdateTime(DateUtils.getNowDate());
+        entity.setUpdateBy(String.valueOf(SecurityUtils.getUserId()));
+        int i = informationMapper.updateInformation(entity);
+        List<String> imgUrlList = Arrays.asList(information.getImgUrlList().split(","));
+            if (!ObjectUtils.isEmpty(imgUrlList)){
+                List<JnbHighServerImg> imgList = new ArrayList<>();
+                jnbHighServerImgMapper.deleteJnbHighServerByServerId(information.getId());
+                imgUrlList.forEach(a->{
+                    JnbHighServerImg serverImg = new JnbHighServerImg();
+                    serverImg.setCreateBy(String.valueOf(SecurityUtils.getUserId()));
+                    serverImg.setCreateTime(DateUtils.getNowDate());
+                    serverImg.setServerId(information.getId());
+                    serverImg.setImgUrl(a);
+                    imgList.add(serverImg);
+                });
+                jnbHighServerImgMapper.saveJnbHighServerImg(imgList);
+            }
+        return i;
     }
 
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public int deleteInformationByIds(Long[] ids)
     {
-        return informationMapper.deleteInformationByIds(ids);
+        int i = informationMapper.deleteInformationByIds(ids);
+        if (i>0){
+            jnbHighServerImgMapper.deleteJnbHighServerByServerIds(ids);
+        }
+        return i;
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public int deleteInformationById(Long id)
     {
-        return informationMapper.deleteInformationById(id);
+        int i = informationMapper.deleteInformationById(id);
+        if (i>0){
+            jnbHighServerImgMapper.deleteJnbHighServerByServerId(id);
+        }
+        return i;
     }
 }

+ 8 - 2
sooka-jnb/src/main/resources/mapper/highServer/JnbHighServerImgMapper.xml

@@ -14,9 +14,15 @@
         update jnb_high_server_img set del_flag = 1 where server_id = #{serverId}
     </delete>
     <insert id="saveJnbHighServerImg" parameterType="java.lang.Integer">
-        insert into jnb_high_server_img (server_id,type,img_name,img_url) values
+        insert into jnb_high_server_img (server_id,type,img_name,img_url,create_by,create_time,update_by,update_time,del_flag) values
         <foreach collection="list" item="item" separator=",">
-            (#{item.serverId},#{item.type},#{item.imgName},#{item.imgUrl})
+            (#{item.serverId},#{item.type},#{item.imgName},#{item.imgUrl},#{item.createBy},#{item.updateBy},#{item.updateTime},#{item.createTime},#{item.delFlag})
         </foreach>
     </insert>
+    <select id="selectAll" resultType="java.lang.String">
+        select img_url where del_flag = 0
+        <if test="serverId != null and serverId !=''">
+            server_id = #{serverid}
+        </if>
+    </select>
 </mapper>