Ver código fonte

我的收藏和浏览次数

詹子聪 5 anos atrás
pai
commit
648eea55d4

+ 6 - 6
src/main/java/com/miekir/shibei/bean/db/CouponBean.java

@@ -19,14 +19,14 @@ public class CouponBean {
     @Id
     @GeneratedValue(strategy= GenerationType.AUTO)
     @Column(name = "id", nullable = false, insertable = true, updatable = false)
-    public long id;
+    public Long id;
 
     /**
      * 模板类型
      */
     @Basic
     @Column(name = "couponType", nullable = true, insertable = true, updatable = true)
-    public int couponType;
+    public Integer couponType = 0;
 
     /**
      * 模板名称
@@ -54,26 +54,26 @@ public class CouponBean {
      */
     @Basic
     @Column(name = "actionEnable", nullable = true, insertable = true, updatable = true)
-    public boolean actionEnable;
+    public Boolean actionEnable = true;
 
     /**是否是本地写死的数据*/
     @Basic
     @Column(name = "isLocal", nullable = true, insertable = true, updatable = true)
-    public boolean isLocal;
+    public Boolean isLocal = false;
 
     /**
      * 创建时间
      */
     @Basic
     @Column(name = "createTimeMillis", nullable = true, insertable = true, updatable = true)
-    public long createTimeMillis;
+    public Long createTimeMillis = 0L;
 
     /**
      * 更新时间
      */
     @Basic
     @Column(name = "updateTimeMillis", nullable = true, insertable = true, updatable = true)
-    public long updateTimeMillis;
+    public Long updateTimeMillis = 0L;
 
     /*columnDefinition = "MEDIUMTEXT"可以解决文字太长保存不进去的bug
     @Basic

+ 2 - 2
src/main/java/com/miekir/shibei/bean/db/FavBean.java

@@ -11,11 +11,11 @@ public class FavBean {
     @Id
     @GeneratedValue(strategy= GenerationType.AUTO)
     @Column(name = "id", nullable = false, insertable = true, updatable = false)
-    public long id;
+    public Long id;
 
     @Column(name = "email", nullable = false, insertable = true, updatable = false)
     public String email;
 
     @Column(name = "goodsId", nullable = false, insertable = true, updatable = false, columnDefinition = "bigint default 0")
-    public long goodsId;
+    public Long goodsId = 0L;
 }

+ 3 - 3
src/main/java/com/miekir/shibei/bean/db/Feedback.java

@@ -8,7 +8,7 @@ import javax.persistence.*;
 @Entity
 @Table(name = "t_feedback", schema = "eden", catalog = "")
 public class Feedback {
-    private Integer id;
+    private Long id;
     private String email;
     private String feedback;
     private Long time;
@@ -17,11 +17,11 @@ public class Feedback {
     @Id
     @GeneratedValue(strategy=GenerationType.AUTO)
     @Column(name = "id", nullable = false, insertable = true, updatable = true)
-    public Integer getId() {
+    public Long getId() {
         return id;
     }
 
-    public void setId(Integer id) {
+    public void setId(Long id) {
         this.id = id;
     }
 

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

@@ -27,7 +27,7 @@ public class GoodsBean {
     @Id
     @GeneratedValue(strategy= GenerationType.AUTO)
     @Column(name = "id", nullable = false, insertable = true, updatable = false)
-    public long id;
+    public Long id;
 
     /**
      * 封面图片地址

+ 1 - 1
src/main/java/com/miekir/shibei/bean/db/JsonBean.java

@@ -16,7 +16,7 @@ public class JsonBean {
     @Id
     @GeneratedValue(strategy= GenerationType.AUTO)
     @Column(name = "id", nullable = false, insertable = true, updatable = false)
-    public long id;
+    public Long id;
 
     @Basic
     @Column(name = "email", nullable = true, insertable = true, updatable = true)

+ 1 - 1
src/main/java/com/miekir/shibei/bean/db/MagnetBean.java

@@ -16,7 +16,7 @@ public class MagnetBean implements Serializable {
     @Id
     @GeneratedValue(strategy= GenerationType.AUTO)
     @Column(name = "id", nullable = false, insertable = true, updatable = false)
-    public long id;
+    public Long id;
 
     @Basic
     @Column(columnDefinition = "MEDIUMTEXT", name = "magnet_text", nullable = true, insertable = true, updatable = true)

+ 2 - 2
src/main/java/com/miekir/shibei/bean/db/SystemBean.java

@@ -14,12 +14,12 @@ public class SystemBean {
     @Id
     @GeneratedValue(strategy= GenerationType.AUTO)
     @Column(name = "id", nullable = false, insertable = true, updatable = false)
-    public long id;
+    public Integer id;
 
     /**
      * 是否有VIP限制,true表示必须要VIP才能使用特殊服务,false表示免费开放中...
      */
     @Basic
     @Column(name = "isVipLimit", nullable = true, insertable = true, updatable = true)
-    public boolean isVipLimit;
+    public Boolean isVipLimit = false;
 }

+ 2 - 2
src/main/java/com/miekir/shibei/bean/db/UpgradeBean.java

@@ -12,11 +12,11 @@ public class UpgradeBean {
     @Id
     @GeneratedValue(strategy=GenerationType.AUTO)
     @Column(name = "id", nullable = false, insertable = true, updatable = true)
-    public int id;
+    public Integer id;
 
     @Basic
     @Column(name = "versionCode", nullable = true, insertable = true, updatable = true)
-    public int versionCode;
+    public Integer versionCode = 0;
 
     @Basic
     @Column(name = "versionName", nullable = true, insertable = true, updatable = true)

+ 8 - 8
src/main/java/com/miekir/shibei/bean/db/User.java

@@ -14,24 +14,24 @@ public class User {
     private String autograph;
     private String password;
     private String headIcon;
-    private Integer sex;
+    private Integer sex = 0;
     private String token;
-    private Long registerTimeMillis;
-    private Long lastLoginTimeMillis;
-    private boolean isVip;
+    private Long registerTimeMillis = 0L;
+    private Long lastLoginTimeMillis = 0L;
+    private boolean isVip = false;
     private String deviceId;
     private String lastIp;
-    private Integer themeMode;
+    private Integer themeMode = 0;
     /**当前余额,单位:分*/
-    private long currentMoney;
+    private Long currentMoney = 0L;
     /**历史提现,单位:分*/
-    private long historyCash;
+    private Long historyCash = 0L;
 
     /**提现支付宝账号*/
     private String cashAccount;
 
     /**是否被禁用*/
-    private boolean isLimit;
+    private boolean isLimit = false;
 
     // Id自增
     /*@Id

+ 1 - 1
src/main/java/com/miekir/shibei/controller/api/CouponController.java

@@ -85,7 +85,7 @@ public class CouponController {
      */
     @RequestMapping(value = "/api/deleteCouponById", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
     @ResponseBody
-    public String deleteCoupon(@RequestHeader HttpHeaders header, long couponId) {
+    public String deleteCoupon(@RequestHeader HttpHeaders header, Long couponId) {
         ResponseResult<String> responseResult = new ResponseResult<String>();
         responseResult.setMessage("删除失败");
 

+ 62 - 1
src/main/java/com/miekir/shibei/controller/api/FavController.java

@@ -9,6 +9,8 @@ import com.miekir.shibei.repository.*;
 import com.miekir.shibei.tool.RequestTool;
 import com.miekir.shibei.tool.email.EmailTool;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.data.domain.Sort;
 import org.springframework.http.HttpHeaders;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
@@ -23,6 +25,10 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
 
 @Controller
 public class FavController {
@@ -35,12 +41,15 @@ public class FavController {
     @Autowired
     private FavRepository favRepository;
 
+    @Autowired
+    private SystemRepository systemRepository;
+
     /**
      * 设置API是否为会员专属
      */
     @RequestMapping(value = "/api/favGoods", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
     @ResponseBody
-    public String favGoods(@RequestHeader HttpHeaders header, long goodsId) {
+    public String favGoods(@RequestHeader HttpHeaders header, Long goodsId) {
         ResponseResult<String> responseResult = new ResponseResult<String>();
         responseResult.setMessage("操作失败");
 
@@ -76,4 +85,56 @@ public class FavController {
         responseResult.setCode(ResultCode.SUCCESS);
         return JSON.toJSONString(responseResult);
     }
+
+
+
+    /**
+     * 查询京东商品
+     */
+    @RequestMapping(value = "/api/getMyFavGoods", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
+    @ResponseBody
+    public String getMyFavGoods(@RequestHeader HttpHeaders header, int pageNum, int pageSize) {
+        ResponseResult<List<GoodsBean>> responseResult = new ResponseResult<List<GoodsBean>>();
+        responseResult.setMessage("获取失败");
+
+        if (!RequestTool.isRequestValid(header, userRepository)) {
+            responseResult.setMessage("请重新登录");
+            return JSON.toJSONString(responseResult);
+        }
+
+        // 关闭通道
+        SystemBean systemBean = systemRepository.findSystemBean();
+        if (systemBean != null && systemBean.isVipLimit) {
+            responseResult.setMessage("休息时间到");
+            return JSON.toJSONString(responseResult);
+        }
+
+        String email = header.getFirst("email");
+        // 原生查询出来是List<BigInteger>,要转换成List<Long>才行,或者使用JPQL
+        List<BigInteger> goodsIdList = favRepository.getFavList(email, pageNum*pageSize, pageSize);
+        List<Long> realGoodsIdList = new ArrayList<Long>();
+        if (goodsIdList != null && goodsIdList.size() >0) {
+            for (BigInteger integer : goodsIdList) {
+                realGoodsIdList.add(integer.longValue());
+            }
+        } else {
+            responseResult.setContent(null);
+            responseResult.setCode(ResultCode.SUCCESS);
+            responseResult.setMessage("没有更多数据");
+            return JSON.toJSONString(responseResult);
+        }
+        Iterable<GoodsBean> favGoodsIterator = goodsRepository.findAll(realGoodsIdList);
+        List<GoodsBean> goodsBeanList = new ArrayList<GoodsBean>();
+        if (favGoodsIterator != null) {
+            for (GoodsBean currentBean : favGoodsIterator) {
+                currentBean.isFavorite = true;
+                goodsBeanList.add(currentBean);
+            }
+        }
+        responseResult.setContent(goodsBeanList);
+
+        responseResult.setCode(ResultCode.SUCCESS);
+        responseResult.setMessage("获取成功");
+        return JSON.toJSONString(responseResult);
+    }
 }

+ 10 - 3
src/main/java/com/miekir/shibei/controller/api/GoodsController.java

@@ -86,7 +86,7 @@ public class GoodsController {
      */
     @RequestMapping(value = "/api/deleteGoodsById", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
     @ResponseBody
-    public String deleteGoods(@RequestHeader HttpHeaders header, long goodsId) {
+    public String deleteGoods(@RequestHeader HttpHeaders header, Long goodsId) {
         ResponseResult<String> responseResult = new ResponseResult<String>();
         responseResult.setMessage("删除失败");
 
@@ -203,8 +203,15 @@ public class GoodsController {
             return JSON.toJSONString(responseResult);
         }
 
-        // 自带的分页查询
         List<GoodsBean> goodsBeanList;
+        // 自带的分页查询
+//        try {
+//            Sort sort = new Sort(Sort.Direction.DESC,"updateTimeMillis");
+//            goodsBeanList = goodsRepository.findAll(new PageRequest(pageNum, pageSize, sort)).getContent();
+//        } catch (Exception e) {
+//            e.printStackTrace();
+//            return JSON.toJSONString(responseResult);
+//        }
         try {
             // 如果pageNum为1,pageSize为20,则查询第1*20条到第1*20+20-1(这里的第几条是从0开始的)
             // 模糊查询,要拼上%%
@@ -243,7 +250,7 @@ public class GoodsController {
      */
     @RequestMapping(value = "/api/seeGoods", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
     @ResponseBody
-    public String seeGoods(@RequestHeader HttpHeaders header, long goodsId) {
+    public String seeGoods(@RequestHeader HttpHeaders header, Long goodsId) {
         ResponseResult<Void> responseResult = new ResponseResult<Void>();
         responseResult.setMessage("操作失败");
 

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

@@ -1,6 +1,7 @@
 package com.miekir.shibei.repository;
 
 import com.miekir.shibei.bean.db.FavBean;
+import com.miekir.shibei.bean.db.GoodsBean;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.Modifying;
 import org.springframework.data.jpa.repository.Query;
@@ -8,6 +9,7 @@ import org.springframework.data.repository.query.Param;
 import org.springframework.stereotype.Repository;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.math.BigInteger;
 import java.util.List;
 
 /**
@@ -22,5 +24,9 @@ public interface FavRepository extends JpaRepository<FavBean, Long> {
 
     @Transactional
     @Query(value="select favBean from FavBean favBean where favBean.email=:email and favBean.goodsId=:goodsId")
-    public FavBean findFavByEmailAndGoodsId(@Param("email") String email, @Param("goodsId") long goodsId);
+    public FavBean findFavByEmailAndGoodsId(@Param("email") String email, @Param("goodsId") Long goodsId);
+
+    // 使用原生SQL MYSQL 不支持TOP,要用连接符号|连接,否则会被当成字符串常量拼成%?1%
+    @Query(value="SELECT goodsId FROM t_fav where email = ?1 ORDER BY id DESC limit ?2, ?3", nativeQuery = true)
+    public List<BigInteger> getFavList(String email, int startNum, int pageSize);
 }

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

@@ -7,6 +7,7 @@ import org.springframework.data.repository.query.Param;
 import org.springframework.stereotype.Repository;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.math.BigInteger;
 import java.util.List;
 
 /**
@@ -14,18 +15,20 @@ import java.util.List;
  */
 // 添加注解
 @Repository
-public interface GoodsRepository extends JpaRepository<GoodsBean, Integer> {
+public interface GoodsRepository extends JpaRepository<GoodsBean, Long> {
     // 根据密码Id查询密码记事
     // 说明该方法是事务性操作
     @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)
     public List<GoodsBean> getGoodsListByKeyword(String keywords, int startNum, int pageSize);
 
+//    @Override
+//    List<GoodsBean> findAll();
 
 //    @Transactional
 //    // 根据邮件查询用户所有密码记事