Bladeren bron

uniapp资讯接口

qinhouyu 1 jaar geleden
bovenliggende
commit
103b2b18a8

+ 43 - 7
ruoyi-admin/src/main/java/com/ruoyi/web/controller/information/InformationController.java

@@ -3,7 +3,9 @@ package com.ruoyi.web.controller.information;
 import java.util.List;
 import javax.servlet.http.HttpServletResponse;
 
+import com.github.pagehelper.Page;
 import com.sooka.jnb.information.domain.Information;
+import com.sooka.jnb.information.domain.InformationUni;
 import com.sooka.jnb.information.service.InformationService;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -36,6 +38,24 @@ public class InformationController extends BaseController
     private InformationService informationService;
 
     /**
+     * 点赞
+     */
+    @PostMapping("/like")
+    public AjaxResult like(Information information){
+        return toAjax(informationService.likeById(information));
+    }
+
+
+    /**
+     * 浏览
+     */
+    @PostMapping("/watch")
+    public AjaxResult watchById(Information information){
+        return toAjax(informationService.watchById(information));
+    }
+
+
+    /**
      * 查询资讯列表
      */
 //    @PreAuthorize("@ss.hasPermi('jnb:information:list')")
@@ -64,11 +84,9 @@ public class InformationController extends BaseController
      */
 //    @PreAuthorize("@ss.hasPermi('jnb:information:query')")
     @GetMapping("/listWxs")
-    public TableDataInfo listWxs(Information information)
+    public TableDataInfo listWxs(Information information, Integer pageNum,Integer pageSize)
     {
-        startPage();
-        List<Information> list = informationService.selectInformationListWxs(information);
-        return getDataTable(list);
+        return informationService.selectInformationListWxs(information,pageNum,pageSize);
     }
 
 
@@ -94,7 +112,15 @@ public class InformationController extends BaseController
     {
         return success(informationService.selectInformationById(id,type));
     }
-
+    /**
+     * 获取资讯详细信息-小程序
+     */
+//    @PreAuthorize("@ss.hasPermi('jnb:information:query')")
+    @GetMapping(value = "/uniApp/{id}/{type}")
+    public AjaxResult getInfoUniApp(@PathVariable("id") Long id,@PathVariable("type") Integer type)
+    {
+        return success(informationService.selectInformationByIdgetInfoUniApp(id,type));
+    }
     /**
      * 新增资讯
      */
@@ -105,7 +131,12 @@ public class InformationController extends BaseController
     {
         return toAjax(informationService.insertInformationServer(information));
     }
-
+    @Log(title = "新增资讯-小程序", businessType = BusinessType.INSERT)
+    @PostMapping("/uniApp")
+    public AjaxResult adduniApp(@RequestBody InformationUni information)
+    {
+        return toAjax(informationService.insertInformationServerUni(information));
+    }
     /**
      * 修改资讯
      */
@@ -116,7 +147,12 @@ public class InformationController extends BaseController
     {
         return toAjax(informationService.updateInformation(information));
     }
-
+    @Log(title = "修改资讯", businessType = BusinessType.UPDATE)
+    @PutMapping("/uniApp")
+    public AjaxResult editUniApp(@RequestBody InformationUni information)
+    {
+        return toAjax(informationService.updateInformationUni(information));
+    }
     /**
      * 删除资讯
      */

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

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

+ 3 - 0
sooka-jnb/src/main/java/com/sooka/jnb/information/domain/Information.java

@@ -60,4 +60,7 @@ public class Information extends BaseEntity
 
     @TableField(exist = false)
     private String imgUrlList;
+
+    @TableField(exist = false)
+    private String nickName;
 }

+ 56 - 0
sooka-jnb/src/main/java/com/sooka/jnb/information/domain/InformationUni.java

@@ -0,0 +1,56 @@
+package com.sooka.jnb.information.domain;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.ruoyi.common.annotation.Excel;
+import com.ruoyi.common.core.domain.BaseEntity;
+import lombok.Data;
+
+import javax.validation.constraints.NotBlank;
+import java.util.List;
+
+/**
+ * 资讯
+ * 
+ * @author ruoyi
+ * @date 2024-03-01
+ */
+@Data
+public class InformationUni extends BaseEntity
+{
+    private static final long serialVersionUID = 1L;
+
+    /** id */
+    private Long id;
+
+    /** 标题 */
+    @Excel(name = "标题")
+    @NotBlank(message = "标题不能为空")
+    private String titleName;
+
+    /** 正文 */
+    @Excel(name = "正文",width = 100)
+    @NotBlank(message = "正文不能为空")
+    private String textDetails;
+
+    /** 是否政策推荐 */
+    @Excel(name = "是否政策推荐", readConverterExp = "1=是,0=否")
+    private Integer isGovernment;
+
+    /** 是否置顶 */
+    @Excel(name = "是否置顶", readConverterExp = "1=是,0=否")
+    private Integer isTop;
+
+    /** 点赞数 */
+    @Excel(name = "点赞数")
+    private Long likeNum;
+
+    /** 浏览数 */
+    @Excel(name = "浏览数")
+    private Long watchNum;
+
+    private Integer type;
+
+    @TableField(exist = false)
+    private List<String> urls;
+
+}

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

@@ -1,5 +1,6 @@
 package com.sooka.jnb.information.mapper;
 
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.sooka.jnb.information.domain.Information;
 import org.apache.ibatis.annotations.Param;
 
@@ -66,7 +67,7 @@ public interface InformationMapper
      * @param information 按照时间,点赞,浏览 排序
      * @return 结果
      */
-    List<Information> selectInformationListWxs(Information information);
+    List<Information> selectInformationListWxs(@Param("obj") Information information, @Param("pageNum") Integer pageNum, @Param("pageSize") Integer pageSize);
 
     /**
      * 置顶,政策推荐 3个
@@ -74,4 +75,7 @@ public interface InformationMapper
      * @return 结果
      */
     List<Information> selectInformationListWx(Information information);
+
+    int updateInformationLike(Information information);
+    int updateInformationWatch(Information information);
 }

+ 22 - 1
sooka-jnb/src/main/java/com/sooka/jnb/information/service/InformationService.java

@@ -1,6 +1,9 @@
 package com.sooka.jnb.information.service;
 
+import com.github.pagehelper.Page;
+import com.ruoyi.common.core.page.TableDataInfo;
 import com.sooka.jnb.information.domain.Information;
+import com.sooka.jnb.information.domain.InformationUni;
 
 import java.util.List;
 
@@ -20,6 +23,7 @@ public interface InformationService
      * @return 资讯
      */
     public Information selectInformationById(Long id,Integer type);
+    public Information selectInformationByIdgetInfoUniApp(Long id,Integer type);
 
     /**
      * 查询资讯服务列表
@@ -39,6 +43,13 @@ public interface InformationService
      * @return 结果
      */
     public int insertInformationServer(Information information);
+    /**
+     * 新增资讯-小程序
+     *
+     * @param information 资讯
+     * @return 结果
+     */
+    public int insertInformationServerUni(InformationUni information);
 
     /**
      * 修改资讯
@@ -47,6 +58,13 @@ public interface InformationService
      * @return 结果
      */
     public int updateInformation(Information information);
+    /**
+     * 修改资讯-小程序
+     *
+     * @param information 资讯
+     * @return 结果
+     */
+    public int updateInformationUni(InformationUni information);
 
     /**
      * 批量删除资讯
@@ -56,5 +74,8 @@ public interface InformationService
      */
     public int deleteInformationByIds(Long[] ids,Integer type);
 
-    List<Information> selectInformationListWxs(Information information);
+    TableDataInfo selectInformationListWxs(Information information, Integer pageNum, Integer pageSize);
+
+    int likeById(Information information);
+    int watchById(Information information);
 }

+ 91 - 7
sooka-jnb/src/main/java/com/sooka/jnb/information/service/impl/InformationServiceImpl.java

@@ -3,12 +3,16 @@ 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.github.pagehelper.Page;
+import com.ruoyi.common.core.page.TableDataInfo;
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.common.utils.SecurityUtils;
 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.InformationUni;
 import com.sooka.jnb.information.mapper.InformationMapper;
 import com.sooka.jnb.information.service.InformationService;
 import org.springframework.beans.BeanUtils;
@@ -38,7 +42,15 @@ public class InformationServiceImpl implements InformationService
         information.setImgUrlList(jnbHighServerImgMapper.selectAll(id,information.getType()));
         return information;
     }
-
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public Information selectInformationByIdgetInfoUniApp(Long id,Integer type)
+    {
+        Information information = informationMapper.selectInformationById(id,type);
+        information.setUrls(jnbHighServerImgMapper.selectAllList(id,information.getType()));
+        informationMapper.updateInformationWatch(information);
+        return information;
+    }
 
     @Override
     public List<Information> selectInformationList(Information information)
@@ -52,9 +64,28 @@ public class InformationServiceImpl implements InformationService
         return informationMapper.selectInformationListWx(information);
     }
     @Override
-    public List<Information> selectInformationListWxs(Information information)
+    public TableDataInfo selectInformationListWxs(Information information, Integer pageNum, Integer pageSize)
     {
-        return informationMapper.selectInformationListWxs(information);
+//        List<Information> result = informationMapper.selectInformationListWxs(information,pageNum, pageSize);
+        List<Information> toolForAbsenteeism = informationMapper.selectInformationListWxs(information,pageNum, pageSize);
+        TableDataInfo tableDataInfo = new TableDataInfo();
+        tableDataInfo.setRows(toolForAbsenteeism.stream() .skip((long) (pageNum - 1) * pageSize)
+                .limit(pageSize)
+                .collect(Collectors.toList()));
+        tableDataInfo.setTotal(toolForAbsenteeism.size());
+        tableDataInfo.setCode(200);
+        tableDataInfo.setMsg("查询成功");
+        return tableDataInfo;
+    }
+
+    @Override
+    public int likeById(Information information) {
+       return informationMapper.updateInformationLike(information);
+    }
+
+    @Override
+    public int watchById(Information information) {
+       return informationMapper.updateInformationWatch(information);
     }
 
 
@@ -66,8 +97,8 @@ public class InformationServiceImpl implements InformationService
         entity.setCreateBy(String.valueOf(SecurityUtils.getUserId()));
         int i = informationMapper.insertInformation(entity);
         if (i>0){
-            List<String> imgUrlList = Arrays.asList(entity.getImgUrlList().split(","));
-            if (!ObjectUtils.isEmpty(imgUrlList)){
+            if (!ObjectUtils.isEmpty(entity.getImgUrlList())){
+                List<String> imgUrlList = Arrays.asList(entity.getImgUrlList().split(","));
                 List<JnbHighServerImg> imgList = new ArrayList<>();
                 imgUrlList.forEach(a->{
                     JnbHighServerImg serverImg = new JnbHighServerImg();
@@ -87,13 +118,41 @@ public class InformationServiceImpl implements InformationService
 
     @Override
     @Transactional(rollbackFor = Exception.class)
+    public int insertInformationServerUni(InformationUni entity)
+    {
+        entity.setCreateTime(DateUtils.getNowDate());
+        entity.setCreateBy(String.valueOf(SecurityUtils.getUserId()));
+        Information obj = new Information();
+        BeanUtils.copyProperties(entity,obj);
+        int i = informationMapper.insertInformation(obj);
+        if (i>0){
+            if (!ObjectUtils.isEmpty(entity.getUrls())){
+                List<JnbHighServerImg> imgList = new ArrayList<>();
+                entity.getUrls().forEach(a->{
+                    JnbHighServerImg serverImg = new JnbHighServerImg();
+                    serverImg.setCreateBy(String.valueOf(SecurityUtils.getUserId()));
+                    serverImg.setCreateTime(DateUtils.getNowDate());
+                    serverImg.setServerId(entity.getId());
+                    serverImg.setImgUrl(a);
+                    serverImg.setType(entity.getType());
+                    imgList.add(serverImg);
+                });
+                jnbHighServerImgMapper.saveJnbHighServerImg(imgList);
+            }
+        }
+        return i;
+    }
+
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
     public int updateInformation(Information entity)
     {
         entity.setUpdateTime(DateUtils.getNowDate());
         entity.setUpdateBy(String.valueOf(SecurityUtils.getUserId()));
         int i = informationMapper.updateInformation(entity);
-        List<String> imgUrlList = Arrays.asList(entity.getImgUrlList().split(","));
-            if (!ObjectUtils.isEmpty(imgUrlList)){
+        if (!ObjectUtils.isEmpty(entity.getImgUrlList())){
+            List<String> imgUrlList = Arrays.asList(entity.getImgUrlList().split(","));
                 List<JnbHighServerImg> imgList = new ArrayList<>();
                 jnbHighServerImgMapper.deleteJnbHighServerByServerId(entity.getId(),entity.getType());
                 imgUrlList.forEach(a->{
@@ -110,6 +169,31 @@ public class InformationServiceImpl implements InformationService
         return i;
     }
 
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public int updateInformationUni(InformationUni entity)
+    {
+        entity.setUpdateTime(DateUtils.getNowDate());
+        entity.setUpdateBy(String.valueOf(SecurityUtils.getUserId()));
+        Information obj = new Information();
+        BeanUtils.copyProperties(entity,obj);
+        int i = informationMapper.updateInformation(obj);
+        if (!ObjectUtils.isEmpty(entity.getUrls())){
+            List<JnbHighServerImg> imgList = new ArrayList<>();
+            jnbHighServerImgMapper.deleteJnbHighServerByServerId(entity.getId(),entity.getType());
+            entity.getUrls().forEach(a->{
+                JnbHighServerImg serverImg = new JnbHighServerImg();
+                serverImg.setCreateBy(String.valueOf(SecurityUtils.getUserId()));
+                serverImg.setCreateTime(DateUtils.getNowDate());
+                serverImg.setServerId(entity.getId());
+                serverImg.setImgUrl(a);
+                serverImg.setType(entity.getType());
+                imgList.add(serverImg);
+            });
+            jnbHighServerImgMapper.saveJnbHighServerImg(imgList);
+        }
+        return i;
+    }
 
     @Override
     @Transactional(rollbackFor = Exception.class)

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

@@ -28,4 +28,13 @@
             and type = #{type}
         </if>
     </select>
+    <select id="selectAllList" resultType="java.lang.String">
+        select img_url from jnb_high_server_img where del_flag = 0
+        <if test="serverId != null and serverId !=''">
+           and server_id = #{serverId}
+        </if>
+        <if test="type != null and type !=''">
+            and type = #{type}
+        </if>
+    </select>
 </mapper>

+ 39 - 13
sooka-jnb/src/main/resources/mapper/information/InformationMapper.xml

@@ -16,6 +16,7 @@
         <result property="createBy" column="create_by"/>
         <result property="createTime" column="create_time"/>
         <result property="updateBy" column="update_by"/>
+        <result property="nickName" column="nick_name"/>
         <result property="imgUrlList" column="imgUrlList"/>
         <result property="updateTime" column="update_time"/>
         <result property="delFlag" column="del_flag"/>
@@ -84,7 +85,7 @@
         </collection>
     </resultMap>
 
-    <select id="selectInformationListWxs" parameterType="Information" resultMap="InformationResult1">
+    <select id="selectInformationListWxs"  resultMap="InformationResult1">
         SELECT
         a.id,
         a.title_name,
@@ -101,19 +102,17 @@
         a.watch_num,
         i.img_url AS url
         FROM jnb_high_server AS a
-        LEFT JOIN jnb_high_server_img AS i ON a.id = i.server_id AND i.del_flag = 0 AND i.type = #{type}
-        <where>
-            <if test="titleName != null and titleName != ''">AND a.title_name LIKE CONCAT('%', #{titleName}, '%')</if>
-            <if test="type != null and type != ''">AND a.type = #{type}</if>
-            <if test="isGovernment != null and isGovernment != ''">AND a.is_government = #{isGovernment}</if>
-            <if test="isTop != null and isTop != ''">AND a.is_top = #{isTop}</if>
-            AND a.del_flag = 0
-        </where>
+        LEFT JOIN jnb_high_server_img AS i ON a.id = i.server_id AND i.del_flag = 0 AND i.type = #{obj.type}
+        where a.del_flag = 0
+            <if test="obj.titleName != null  and obj.titleName != ''">and a.title_name like concat('%', #{obj.titleName}, '%')</if>
+            <if test="obj.type != null and obj.type != ''">and a.type = #{obj.type}</if>
+            <if test="obj.isGovernment != null and obj.isGovernment != ''">and a.is_government = #{obj.isGovernment}</if>
+            <if test="obj.isTop != null and obj.isTop != ''">and a.is_top = #{obj.isTop}</if>
         <choose>
-            <when test="flag == 'like'">
+            <when test="obj.flag == 'like'">
                 ORDER BY a.like_num DESC
             </when>
-            <when test="flag == 'watch'">
+            <when test="obj.flag == 'watch'">
                 ORDER BY a.watch_num DESC
             </when>
             <otherwise>
@@ -135,8 +134,23 @@
     </select>
 
     <select id="selectInformationById" resultMap="InformationResult">
-        <include refid="selectInformationVo"/>
-        where id = #{id} and type = #{type}
+        select a.id,
+               a.title_name,
+               a.text_details,
+               a.type,
+               a.create_by,
+               a.create_time,
+               a.update_by,
+               a.update_time,
+               a.del_flag,
+               a.is_government,
+               a.is_top,
+               a.like_num,
+               a.watch_num,
+               b.nick_name
+        from jnb_high_server as a
+        left join sys_user as b on b.user_id = a.create_by
+        where a.id = #{id} and a.type = #{type}
     </select>
 
     <insert id="insertInformation" parameterType="Information" useGeneratedKeys="true" keyProperty="id">
@@ -173,6 +187,18 @@
         WHERE id = #{id} and type = #{type}
     </update>
 
+    <update id="updateInformationLike">
+        UPDATE jnb_high_server
+        SET like_num = like_num +1
+        WHERE id = #{id} and type = #{type}
+    </update>
+
+    <update id="updateInformationWatch">
+        UPDATE jnb_high_server
+        SET watch_num = watch_num+1
+        WHERE id = #{id} and type = #{type}
+    </update>
+
     <delete id="deleteInformationByIds" >
         UPDATE jnb_high_server
         SET del_flag = 2