浏览代码

浏览次数

詹子聪 5 年之前
父节点
当前提交
b7bf91d595

+ 11 - 11
src/main/java/com/miekir/shibei/bean/db/GoodsBean.java

@@ -89,21 +89,21 @@ public class GoodsBean {
      */
     @Basic
     @Column(name = "dingNum", nullable = true, insertable = true, updatable = true, columnDefinition = "int default 0")
-    public int dingNum;
+    public Integer dingNum = 0;
 
     /**
      * 踩的数量
      */
     @Basic
     @Column(name = "caiNum", nullable = true, insertable = true, updatable = true, columnDefinition = "int default 0")
-    public int caiNum;
+    public Integer caiNum = 0;
 
     /**
      * 好评率 = 赞/(赞+踩)
      */
     @Basic
     @Column(name = "goodComment", nullable = true, insertable = true, updatable = true)
-    public double goodComment;
+    public Double goodComment = 0.0;
 
     /**
      * 烦号信息
@@ -126,7 +126,7 @@ public class GoodsBean {
      */
     @Basic
     @Column(name = "isFavorite", nullable = true, insertable = true, updatable = true)
-    public boolean isFavorite;
+    public Boolean isFavorite = false;
 
     /**
      * 内容的图片链接列表
@@ -142,36 +142,36 @@ public class GoodsBean {
      */
     @Basic
     @Column(name = "createTimeMillis", nullable = true, insertable = true, updatable = true, columnDefinition = "bigint default 0")
-    public long createTimeMillis;
+    public Long createTimeMillis = 0L;
 
     /**
      * 更新时间
      */
     @Basic
     @Column(name = "updateTimeMillis", nullable = true, insertable = true, updatable = true, columnDefinition = "bigint default 0")
-    public long updateTimeMillis;
+    public Long updateTimeMillis = 0L;
 
     @Basic
     @Column(name = "enable", nullable = true, insertable = true, updatable = true)
-    public boolean enable;
+    public Boolean enable = true;
 
     /**
      * 浏览次数
      */
     @Basic
     @Column(name = "seeNum", nullable = true, insertable = true, updatable = true, columnDefinition = "bigint default 0")
-    public Long seeNum;
+    public Long seeNum = 0L;
 
     //columnDefinition = "int default 0"
     /**
-     * 收藏次数
+     * 收藏次数。赋予初始化值0L,那么表里初始化就是0了!
      */
     @Basic
     @Column(name = "favNum", nullable = true, insertable = true, updatable = true, columnDefinition = "bigint default 0")
-    public Long favNum;
+    public Long favNum = 0L;
 
     /**是否是本地写死的数据*/
     @Basic
     @Column(name = "isLocal", nullable = true, insertable = true, updatable = true)
-    public boolean isLocal;
+    public Boolean isLocal = false;
 }

+ 6 - 0
src/main/java/com/miekir/shibei/controller/api/FavController.java

@@ -58,10 +58,16 @@ public class FavController {
             favBean.goodsId = goodsId;
             favRepository.save(favBean);
             responseResult.setContent("收藏成功");
+            if (goodsBean.favNum == null) {
+                goodsBean.favNum = 0L;
+            }
             goodsBean.favNum = goodsBean.favNum+1;
         } else {
             favRepository.delete(favBean);
             responseResult.setContent("取消收藏成功");
+            if (goodsBean.favNum == null) {
+                goodsBean.favNum = 0L;
+            }
             goodsBean.favNum = goodsBean.favNum-1;
         }
 

+ 25 - 0
src/main/java/com/miekir/shibei/controller/api/GoodsController.java

@@ -237,4 +237,29 @@ public class GoodsController {
         responseResult.setMessage("获取成功");
         return JSON.toJSONString(responseResult);
     }
+
+    /**
+     * 查询京东商品
+     */
+    @RequestMapping(value = "/api/seeGoods", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
+    @ResponseBody
+    public String seeGoods(@RequestHeader HttpHeaders header, long goodsId) {
+        ResponseResult<Void> responseResult = new ResponseResult<Void>();
+        responseResult.setMessage("操作失败");
+
+        if (!RequestTool.isRequestValid(header, userRepository)) {
+            responseResult.setMessage("请重新登录");
+            return JSON.toJSONString(responseResult);
+        }
+
+        GoodsBean goodsBean = goodsRepository.findGoodsById(goodsId);
+        if (goodsBean != null) {
+            goodsBean.seeNum = goodsBean.seeNum + 1;
+            goodsRepository.save(goodsBean);
+        }
+
+        responseResult.setCode(ResultCode.SUCCESS);
+        responseResult.setMessage("操作成功");
+        return JSON.toJSONString(responseResult);
+    }
 }

+ 1 - 1
src/main/java/com/miekir/shibei/repository/GoodsRepository.java

@@ -20,7 +20,7 @@ public interface GoodsRepository extends JpaRepository<GoodsBean, Integer> {
     @Transactional
     // @Param注解用于提取参数
     @Query(value="select goodsBean from GoodsBean goodsBean where goodsBean.id=:id")
-    public GoodsBean findGoodsById(@Param("id") Long id);
+    public GoodsBean findGoodsById(@Param("id") long id);
 
     // 使用原生SQL MYSQL 不支持TOP,要用连接符号|连接,否则会被当成字符串常量拼成%?1%
     @Query(value="SELECT * FROM t_goods where title like ?1 limit ?2, ?3", nativeQuery = true)