Browse Source

资讯crud与图片上传

qinhouyu 1 year ago
parent
commit
5f7e42bc29

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

@@ -4,10 +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;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -79,7 +76,7 @@ public class InformationController extends BaseController
     @PreAuthorize("@ss.hasPermi('jnb:information:add')")
     @Log(title = "新增资讯", businessType = BusinessType.INSERT)
     @PostMapping
-    public AjaxResult add(@RequestBody InformationVo information)
+    public AjaxResult add(@RequestBody Information information)
     {
         return toAjax(informationService.insertInformationServer(information));
     }
@@ -90,7 +87,7 @@ public class InformationController extends BaseController
     @PreAuthorize("@ss.hasPermi('jnb:information:edit')")
     @Log(title = "修改资讯", businessType = BusinessType.UPDATE)
     @PutMapping
-    public AjaxResult edit(@RequestBody InformationVo information)
+    public AjaxResult edit(@RequestBody Information information)
     {
         return toAjax(informationService.updateInformation(information));
     }

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

@@ -14,5 +14,5 @@ public interface JnbHighServerImgMapper {
 
     int saveJnbHighServerImg(List<JnbHighServerImg> saveList);
 
-    List<String> selectAll(Long serverId);
+    String selectAll(Long serverId);
 }

+ 10 - 4
sooka-jnb/src/main/java/com/sooka/jnb/information/domain/Information.java

@@ -1,11 +1,14 @@
 package com.sooka.jnb.information.domain;
 
+import com.baomidou.mybatisplus.annotation.TableField;
 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 javax.validation.constraints.NotBlank;
+
 /**
  * 资讯
  * 
@@ -22,19 +25,21 @@ public class Information extends BaseEntity
 
     /** 标题 */
     @Excel(name = "标题")
+    @NotBlank(message = "标题不能为空")
     private String titleName;
 
     /** 正文 */
-    @Excel(name = "正文",width = 200)
+    @Excel(name = "正文",width = 100)
+    @NotBlank(message = "正文不能为空")
     private String textDetails;
 
     /** 是否政策推荐 */
     @Excel(name = "是否政策推荐", readConverterExp = "1=是,0=否")
-    private String isGovernment;
+    private Integer isGovernment;
 
     /** 是否置顶 */
     @Excel(name = "是否置顶", readConverterExp = "1=是,0=否")
-    private String isTop;
+    private Integer isTop;
 
     /** 点赞数 */
     @Excel(name = "点赞数")
@@ -46,5 +51,6 @@ public class Information extends BaseEntity
 
     private Integer type;
 
-
+    @TableField(exist = false)
+    private String imgUrlList;
 }

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

@@ -1,48 +0,0 @@
-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;
-
-}

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

@@ -1,8 +1,6 @@
 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;
 

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

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

+ 11 - 19
sooka-jnb/src/main/java/com/sooka/jnb/information/service/impl/InformationServiceImpl.java

@@ -3,15 +3,12 @@ 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;
@@ -35,13 +32,11 @@ public class InformationServiceImpl implements InformationService
     private JnbHighServerImgMapper jnbHighServerImgMapper;
 
     @Override
-    public InformationVo selectInformationById(Long id)
+    public Information selectInformationById(Long id)
     {
         Information information = informationMapper.selectInformationById(id);
-        InformationVo vo = new InformationVo();
-        vo.setImgUrlList(StringUtils.join(jnbHighServerImgMapper.selectAll(id)));
-        BeanUtils.copyProperties(information,vo);
-        return vo;
+        information.setImgUrlList(jnbHighServerImgMapper.selectAll(id));
+        return information;
     }
 
 
@@ -54,22 +49,20 @@ public class InformationServiceImpl implements InformationService
 
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public int insertInformationServer(InformationVo information)
+    public int insertInformationServer(Information entity)
     {
-        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(","));
+            List<String> imgUrlList = Arrays.asList(entity.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.setServerId(entity.getId());
                     serverImg.setImgUrl(a);
                     imgList.add(serverImg);
                 });
@@ -82,22 +75,21 @@ public class InformationServiceImpl implements InformationService
 
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public int updateInformation(InformationVo information)
+    public int updateInformation(Information entity)
     {
-        Information entity = new Information();
-        BeanUtils.copyProperties(information,entity);
+        BeanUtils.copyProperties(entity,entity);
         entity.setUpdateTime(DateUtils.getNowDate());
         entity.setUpdateBy(String.valueOf(SecurityUtils.getUserId()));
         int i = informationMapper.updateInformation(entity);
-        List<String> imgUrlList = Arrays.asList(information.getImgUrlList().split(","));
+        List<String> imgUrlList = Arrays.asList(entity.getImgUrlList().split(","));
             if (!ObjectUtils.isEmpty(imgUrlList)){
                 List<JnbHighServerImg> imgList = new ArrayList<>();
-                jnbHighServerImgMapper.deleteJnbHighServerByServerId(information.getId());
+                jnbHighServerImgMapper.deleteJnbHighServerByServerId(entity.getId());
                 imgUrlList.forEach(a->{
                     JnbHighServerImg serverImg = new JnbHighServerImg();
                     serverImg.setCreateBy(String.valueOf(SecurityUtils.getUserId()));
                     serverImg.setCreateTime(DateUtils.getNowDate());
-                    serverImg.setServerId(information.getId());
+                    serverImg.setServerId(entity.getId());
                     serverImg.setImgUrl(a);
                     imgList.add(serverImg);
                 });

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

@@ -14,15 +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,create_by,create_time,update_by,update_time,del_flag) values
+        insert into jnb_high_server_img (server_id,img_url,create_by,update_by,update_time,create_time) values
         <foreach collection="list" item="item" separator=",">
-            (#{item.serverId},#{item.type},#{item.imgName},#{item.imgUrl},#{item.createBy},#{item.updateBy},#{item.updateTime},#{item.createTime},#{item.delFlag})
+            (#{item.serverId},#{item.imgUrl},#{item.createBy},#{item.updateBy},#{item.updateTime},#{item.createTime})
         </foreach>
     </insert>
     <select id="selectAll" resultType="java.lang.String">
-        select img_url where del_flag = 0
+        select group_concat(img_url) from jnb_high_server_img where del_flag = 0
         <if test="serverId != null and serverId !=''">
-            server_id = #{serverid}
+           and server_id = #{serverid}
         </if>
     </select>
 </mapper>

+ 4 - 28
sooka-jnb/src/main/resources/mapper/information/InformationMapper.xml

@@ -44,6 +44,7 @@
             <if test="type != null and type != ''">and type = #{type}</if>
             <if test="isGovernment != null and isGovernment != ''">and is_government = #{isGovernment}</if>
             <if test="isTop != null and isTop != ''">and is_top = #{isTop}</if>
+            and del_flag = 0
         </where>
     </select>
 
@@ -54,35 +55,10 @@
 
     <insert id="insertInformation" parameterType="Information" useGeneratedKeys="true" keyProperty="id">
         insert into jnb_high_server
-        <trim prefix="(" suffix=")" suffixOverrides=",">
-            <if test="titleName != null">title_name,</if>
-            <if test="textDetails != null">text_details,</if>
-            <if test="type != null">type,</if>
-            <if test="createBy != null">create_by,</if>
-            <if test="createTime != null">create_time,</if>
-            <if test="updateBy != null">update_by,</if>
-            <if test="updateTime != null">update_time,</if>
+        (title_name, text_details, type, create_by, create_time, update_by, update_time, watch_num, like_num, is_top, is_government, del_flag)
+        values
+            (#{titleName}, #{textDetails}, #{type}, #{createBy}, #{createTime}, #{updateBy}, #{updateTime}, #{watchNum}, #{likeNum}, #{isTop}, #{isGovernment}, #{delFlag})
 
-            <if test="watchNum != null">watch_num,</if>
-            <if test="likeNum != null">like_time,</if>
-            <if test="isTop != null">is_top,</if>
-            <if test="isGovernment != null">is_government,</if>
-            <if test="delFlag != null">del_flag</if>
-        </trim>
-        <trim prefix="values (" suffix=")" suffixOverrides=",">
-            <if test="titleName != null">#{titleName},</if>
-            <if test="textDetails != null">#{textDetails},</if>
-            <if test="type != null">#{type},</if>
-            <if test="createBy != null">#{createBy},</if>
-            <if test="createTime != null">#{createTime},</if>
-            <if test="updateBy != null">#{updateBy},</if>
-            <if test="updateTime != null">#{updateTime},</if>
-            <if test="watchNum != null">watch_num,</if>
-            <if test="likeNum != null">like_num,</if>
-            <if test="isTop != null">is_top,</if>
-            <if test="isGovernment != null">is_government,</if>
-            <if test="delFlag != null">del_flag</if>
-        </trim>
     </insert>
 
     <update id="updateInformation" parameterType="Information">