elis 2 жил өмнө
parent
commit
18b169f001

+ 84 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/program/dao/HlwPraisesDao.java

@@ -0,0 +1,84 @@
+package com.example.nngkxxdp.program.dao;
+
+
+import com.example.nngkxxdp.program.entity.jsonobj.HlwPraises;
+import org.apache.ibatis.annotations.Param;
+import org.springframework.data.domain.Pageable;
+import java.util.List;
+
+/**
+ * (HlwPraises)表数据库访问层
+ *
+ * @author makejava
+ * @since 2022-11-10 10:17:18
+ */
+public interface HlwPraisesDao {
+
+    /**
+     * 通过ID查询单条数据
+     *
+     * @param id 主键
+     * @return 实例对象
+     */
+    HlwPraises queryById(Integer id);
+
+    /**
+     * 查询指定行数据
+     *
+     * @param hlwPraises 查询条件
+     * @param pageable         分页对象
+     * @return 对象列表
+     */
+    List<HlwPraises> queryAllByLimit(HlwPraises hlwPraises, @Param("pageable") Pageable pageable);
+
+    /**
+     * 统计总行数
+     *
+     * @param hlwPraises 查询条件
+     * @return 总行数
+     */
+    long count(HlwPraises hlwPraises);
+
+    /**
+     * 新增数据
+     *
+     * @param hlwPraises 实例对象
+     * @return 影响行数
+     */
+    int insert(HlwPraises hlwPraises);
+
+    /**
+     * 批量新增数据(MyBatis原生foreach方法)
+     *
+     * @param entities List<HlwPraises> 实例对象列表
+     * @return 影响行数
+     */
+    int insertBatch(@Param("entities") List<HlwPraises> entities);
+
+    /**
+     * 批量新增或按主键更新数据(MyBatis原生foreach方法)
+     *
+     * @param entities List<HlwPraises> 实例对象列表
+     * @return 影响行数
+     * @throws org.springframework.jdbc.BadSqlGrammarException 入参是空List的时候会抛SQL语句错误的异常,请自行校验入参
+     */
+    int insertOrUpdateBatch(@Param("entities") List<HlwPraises> entities);
+
+    /**
+     * 修改数据
+     *
+     * @param hlwPraises 实例对象
+     * @return 影响行数
+     */
+    int update(HlwPraises hlwPraises);
+
+    /**
+     * 通过主键删除数据
+     *
+     * @param id 主键
+     * @return 影响行数
+     */
+    int deleteById(Integer id);
+
+}
+

+ 30 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/program/entity/jsonobj/HlwPraises.java

@@ -0,0 +1,30 @@
+package com.example.nngkxxdp.program.entity.jsonobj;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@NoArgsConstructor
+@Data
+public class HlwPraises {
+    @JsonProperty("id")
+    private Integer id;
+    @JsonProperty("userId")
+    private Integer userId;
+    @JsonProperty("nickName")
+    private String nickName;
+    @JsonProperty("sourceUserImage")
+    private String sourceUserImage;
+    @JsonProperty("praiseTime")
+    private String praiseTime;
+    @JsonProperty("sourceId")
+    private String sourceId;
+    @JsonProperty("sourceType")
+    private Integer sourceType;
+    @JsonProperty("type")
+    private Integer type;
+    @JsonProperty("content")
+    private String content;
+    @JsonProperty("sourceTitle")
+    private String sourceTitle;
+}

+ 17 - 0
nngkxxdp/src/main/java/com/example/nngkxxdp/program/entity/jsonobj/HlwPraisesDTO.java

@@ -0,0 +1,17 @@
+package com.example.nngkxxdp.program.entity.jsonobj;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.util.List;
+
+@NoArgsConstructor
+@Data
+public class HlwPraisesDTO {
+
+    @JsonProperty("dataList")
+    private List<HlwPraises> dataList;
+
+
+}

+ 13 - 9
nngkxxdp/src/main/java/com/example/nngkxxdp/program/service/Impl/HLWIntefaceImpl.java

@@ -8,15 +8,9 @@ import cn.hutool.http.HttpUtil;
 import cn.hutool.json.JSONObject;
 import cn.hutool.json.JSONUtil;
 import com.example.nngkxxdp.program.constant.MiniConstant;
-import com.example.nngkxxdp.program.dao.AppletUserDao;
-import com.example.nngkxxdp.program.dao.HlwCommentsDao;
-import com.example.nngkxxdp.program.dao.HlwFavoritesDao;
-import com.example.nngkxxdp.program.dao.HlwNewsPaperDao;
+import com.example.nngkxxdp.program.dao.*;
 import com.example.nngkxxdp.program.entity.HlwFavorites;
-import com.example.nngkxxdp.program.entity.jsonobj.HlNewsDTO;
-import com.example.nngkxxdp.program.entity.jsonobj.HlNewsPaperDTO;
-import com.example.nngkxxdp.program.entity.jsonobj.HlwCommentsDTO;
-import com.example.nngkxxdp.program.entity.jsonobj.HlwFavoritesDTO;
+import com.example.nngkxxdp.program.entity.jsonobj.*;
 import com.example.nngkxxdp.program.service.HLWIntefaceService;
 import com.example.nngkxxdp.util.SendUtil;
 import lombok.RequiredArgsConstructor;
@@ -36,6 +30,7 @@ public class HLWIntefaceImpl implements HLWIntefaceService {
     private final AppletUserDao appletUserDao;
     private final HlwFavoritesDao hlwFavoritesDao;
     private final HlwCommentsDao hlwCommentsDao;
+    private final HlwPraisesDao hlwPraisesDao;
 
     @Value("${hlw}")
     private String address;
@@ -80,7 +75,16 @@ public class HLWIntefaceImpl implements HLWIntefaceService {
 
     @Override
     public Map<String, Object> praises(String userId) {
-        return null;
+        String userToken = getUserToken(userId);
+        Map<String, Object> requiredParameter = new HashMap<>(5);
+        requiredParameter.put("appId", 4);
+        requiredParameter.put("token", userToken);
+        HlwPraisesDTO data = getJsonObject(MiniConstant.HL_GIVEALIKE, requiredParameter, HlwPraisesDTO.class);
+        if (ObjectUtil.isEmpty(data)&&ObjectUtil.isEmpty(data.getDataList())&&data.getDataList().size()==0){
+            return SendUtil.send(false, "", MiniConstant.RESULT_FAILED);
+        }
+        hlwPraisesDao.insertOrUpdateBatch(data.getDataList());
+        return SendUtil.send(true,"",data.getDataList());
     }
 
     @Transactional

+ 177 - 0
nngkxxdp/src/main/resources/mapper/HlwPraisesDao.xml

@@ -0,0 +1,177 @@
+<?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.example.nngkxxdp.program.dao.HlwPraisesDao">
+
+    <resultMap type="com.example.nngkxxdp.program.entity.jsonobj.HlwPraises" id="HlwPraisesMap">
+        <result property="id" column="id" jdbcType="INTEGER"/>
+        <result property="userId" column="user_id" jdbcType="INTEGER"/>
+        <result property="nickName" column="nick_name" jdbcType="VARCHAR"/>
+        <result property="sourceUserImage" column="source_user_image" jdbcType="VARCHAR"/>
+        <result property="praiseTime" column="praise_time" jdbcType="VARCHAR"/>
+        <result property="sourceId" column="source_id" jdbcType="VARCHAR"/>
+        <result property="sourceType" column="source_type" jdbcType="INTEGER"/>
+        <result property="type" column="type" jdbcType="INTEGER"/>
+        <result property="content" column="content" jdbcType="VARCHAR"/>
+        <result property="sourceTitle" column="source_title" jdbcType="VARCHAR"/>
+    </resultMap>
+
+    <!--查询单个-->
+    <select id="queryById" resultMap="HlwPraisesMap">
+        select
+          id, user_id, nick_name, source_user_image, praise_time, source_id, source_type, type, content, source_title
+        from hlw_praises
+        where id = #{id}
+    </select>
+
+    <!--查询指定行数据-->
+    <select id="queryAllByLimit" resultMap="HlwPraisesMap">
+        select
+          id, user_id, nick_name, source_user_image, praise_time, source_id, source_type, type, content, source_title
+        from hlw_praises
+        <where>
+            <if test="id != null">
+                and id = #{id}
+            </if>
+            <if test="userId != null">
+                and user_id = #{userId}
+            </if>
+            <if test="nickName != null and nickName != ''">
+                and nick_name = #{nickName}
+            </if>
+            <if test="sourceUserImage != null and sourceUserImage != ''">
+                and source_user_image = #{sourceUserImage}
+            </if>
+            <if test="praiseTime != null and praiseTime != ''">
+                and praise_time = #{praiseTime}
+            </if>
+            <if test="sourceId != null and sourceId != ''">
+                and source_id = #{sourceId}
+            </if>
+            <if test="sourceType != null">
+                and source_type = #{sourceType}
+            </if>
+            <if test="type != null">
+                and type = #{type}
+            </if>
+            <if test="content != null and content != ''">
+                and content = #{content}
+            </if>
+            <if test="sourceTitle != null and sourceTitle != ''">
+                and source_title = #{sourceTitle}
+            </if>
+        </where>
+        limit #{pageable.offset}, #{pageable.pageSize}
+    </select>
+
+    <!--统计总行数-->
+    <select id="count" resultType="java.lang.Long">
+        select count(1)
+        from hlw_praises
+        <where>
+            <if test="id != null">
+                and id = #{id}
+            </if>
+            <if test="userId != null">
+                and user_id = #{userId}
+            </if>
+            <if test="nickName != null and nickName != ''">
+                and nick_name = #{nickName}
+            </if>
+            <if test="sourceUserImage != null and sourceUserImage != ''">
+                and source_user_image = #{sourceUserImage}
+            </if>
+            <if test="praiseTime != null and praiseTime != ''">
+                and praise_time = #{praiseTime}
+            </if>
+            <if test="sourceId != null and sourceId != ''">
+                and source_id = #{sourceId}
+            </if>
+            <if test="sourceType != null">
+                and source_type = #{sourceType}
+            </if>
+            <if test="type != null">
+                and type = #{type}
+            </if>
+            <if test="content != null and content != ''">
+                and content = #{content}
+            </if>
+            <if test="sourceTitle != null and sourceTitle != ''">
+                and source_title = #{sourceTitle}
+            </if>
+        </where>
+    </select>
+
+    <!--新增所有列-->
+    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
+        insert into hlw_praises(user_id, nick_name, source_user_image, praise_time, source_id, source_type, type, content, source_title)
+        values (#{userId}, #{nickName}, #{sourceUserImage}, #{praiseTime}, #{sourceId}, #{sourceType}, #{type}, #{content}, #{sourceTitle})
+    </insert>
+
+    <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
+        insert into hlw_praises(user_id, nick_name, source_user_image, praise_time, source_id, source_type, type, content, source_title)
+        values
+        <foreach collection="entities" item="entity" separator=",">
+        (#{entity.userId}, #{entity.nickName}, #{entity.sourceUserImage}, #{entity.praiseTime}, #{entity.sourceId}, #{entity.sourceType}, #{entity.type}, #{entity.content}, #{entity.sourceTitle})
+        </foreach>
+    </insert>
+
+    <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
+        insert into hlw_praises(user_id, nick_name, source_user_image, praise_time, source_id, source_type, type, content, source_title)
+        values
+        <foreach collection="entities" item="entity" separator=",">
+            (#{entity.userId}, #{entity.nickName}, #{entity.sourceUserImage}, #{entity.praiseTime}, #{entity.sourceId}, #{entity.sourceType}, #{entity.type}, #{entity.content}, #{entity.sourceTitle})
+        </foreach>
+        on duplicate key update
+        user_id = values(user_id),
+        nick_name = values(nick_name),
+        source_user_image = values(source_user_image),
+        praise_time = values(praise_time),
+        source_id = values(source_id),
+        source_type = values(source_type),
+        type = values(type),
+        content = values(content),
+        source_title = values(source_title)
+    </insert>
+
+    <!--通过主键修改数据-->
+    <update id="update">
+        update hlw_praises
+        <set>
+            <if test="userId != null">
+                user_id = #{userId},
+            </if>
+            <if test="nickName != null and nickName != ''">
+                nick_name = #{nickName},
+            </if>
+            <if test="sourceUserImage != null and sourceUserImage != ''">
+                source_user_image = #{sourceUserImage},
+            </if>
+            <if test="praiseTime != null and praiseTime != ''">
+                praise_time = #{praiseTime},
+            </if>
+            <if test="sourceId != null and sourceId != ''">
+                source_id = #{sourceId},
+            </if>
+            <if test="sourceType != null">
+                source_type = #{sourceType},
+            </if>
+            <if test="type != null">
+                type = #{type},
+            </if>
+            <if test="content != null and content != ''">
+                content = #{content},
+            </if>
+            <if test="sourceTitle != null and sourceTitle != ''">
+                source_title = #{sourceTitle},
+            </if>
+        </set>
+        where id = #{id}
+    </update>
+
+    <!--通过主键删除-->
+    <delete id="deleteById">
+        delete from hlw_praises where id = #{id}
+    </delete>
+
+</mapper>
+