Explorar el Código

会员专属开关

詹子聪 hace 5 años
padre
commit
0ca066343d

+ 25 - 0
src/main/java/com/miekir/shibei/bean/SystemBean.java

@@ -0,0 +1,25 @@
+package com.miekir.shibei.bean;
+
+import javax.persistence.*;
+
+/**
+ * 系统控制类
+ */
+@Entity
+@Table(name = "t_system", schema = "shibei", catalog = "")
+public class SystemBean {
+    /**
+     * 模板Id
+     */
+    @Id
+    @GeneratedValue(strategy= GenerationType.AUTO)
+    @Column(name = "id", nullable = false, insertable = true, updatable = false)
+    public long id;
+
+    /**
+     * 是否有VIP限制,true表示必须要VIP才能使用特殊服务,false表示免费开放中...
+     */
+    @Basic
+    @Column(name = "isVipLimit", nullable = true, insertable = true, updatable = true)
+    public boolean isVipLimit;
+}

+ 15 - 13
src/main/java/com/miekir/shibei/controller/api/JsonController.java

@@ -5,6 +5,7 @@ import com.alibaba.fastjson.parser.Feature;
 import com.alibaba.fastjson.serializer.SerializeConfig;
 import com.miekir.shibei.bean.*;
 import com.miekir.shibei.repository.JsonRepository;
+import com.miekir.shibei.repository.SystemRepository;
 import com.miekir.shibei.repository.UserRepository;
 import com.miekir.shibei.tool.*;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -26,6 +27,9 @@ public class JsonController {
     @Autowired
     private UserRepository userRepository;
 
+    @Autowired
+    private SystemRepository systemRepository;
+
     //private String mLastWeatherDate = "";
     //private WeatherBean mWeatherBean;
     private String mLastYijiDate = "";
@@ -42,7 +46,7 @@ public class JsonController {
         String cityUtf8 = StringTool.getUtf8String(city);
 
         // 根据token查找用户
-        /*User dbUserBean;
+        User dbUserBean;
         try {
             List<User> dbUserList = userRepository.findUserByToken(token);
             if (dbUserList != null && dbUserList.size() == 1) {
@@ -57,15 +61,11 @@ public class JsonController {
             return JSON.toJSONString(weatherBean);
         }
 
-        // todo 以后收费
-        if (!dbUserBean.isVip()) {
+        SystemBean systemBean = systemRepository.findSystemBean();
+        // 以后收费
+        if (systemBean != null && systemBean.isVipLimit && !dbUserBean.isVip()) {
             return "请更新客户端并开通服务后重试";
-        }*/
-//        String currentDate = DateTool.getCurrentDate();
-//        if (!TextUtils.equals(mLastWeatherDate, currentDate) || TextUtils.isEmpty(mWeatherBean.temperatureRange)) {
-//            mWeatherBean = WebTool.getWeatherInfo(weatherBean, city);
-//            mLastWeatherDate = currentDate;
-//        }
+        }
         WebTool.getWeatherInfo(weatherBean, cityUtf8);
 
         return JSON.toJSONString(weatherBean);
@@ -80,7 +80,7 @@ public class JsonController {
         YijiBean yijiBean = new YijiBean();
 
         // 根据token查找用户
-        /*User dbUserBean;
+        User dbUserBean;
         try {
             List<User> dbUserList = userRepository.findUserByToken(token);
             if (dbUserList != null && dbUserList.size() == 1) {
@@ -94,10 +94,12 @@ public class JsonController {
             return JSON.toJSONString(yijiBean);
         }
 
-        // todo 以后收费
-        if (!dbUserBean.isVip()) {
+        SystemBean systemBean = systemRepository.findSystemBean();
+        // 以后收费
+        if (systemBean != null && systemBean.isVipLimit && !dbUserBean.isVip()) {
             return "请更新客户端并开通服务后重试";
-        }*/
+        }
+
         String currentDate = DateTool.getCurrentDate();
         if (!TextUtils.equals(mLastYijiDate, currentDate) || TextUtils.isEmpty(mYijiBean.newDate)) {
             mYijiBean = WebTool.getYijiInfo(yijiBean);

+ 49 - 4
src/main/java/com/miekir/shibei/controller/api/SystemController.java

@@ -1,18 +1,19 @@
 package com.miekir.shibei.controller.api;
 
 import com.alibaba.fastjson.JSON;
-import com.miekir.shibei.bean.Feedback;
-import com.miekir.shibei.bean.ResponseResult;
-import com.miekir.shibei.bean.ResultCode;
-import com.miekir.shibei.bean.UpgradeBean;
+import com.miekir.shibei.bean.*;
 import com.miekir.shibei.repository.FeedbackRepository;
+import com.miekir.shibei.repository.SystemRepository;
 import com.miekir.shibei.repository.UpgradeRepository;
+import com.miekir.shibei.repository.UserRepository;
+import com.miekir.shibei.tool.RequestTool;
 import com.miekir.shibei.tool.email.EmailTool;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpHeaders;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestHeader;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.ResponseBody;
@@ -30,6 +31,12 @@ public class SystemController {
     @Autowired
     UpgradeRepository upgradeRepository;
 
+    @Autowired
+    private UserRepository userRepository;
+
+    @Autowired
+    private SystemRepository systemRepository;
+
     /**
      * 意见反馈
      */
@@ -83,6 +90,44 @@ public class SystemController {
         return entity;
     }
 
+    /**
+     * 查询系统设置
+     */
+    @RequestMapping(value = "/api/getSystemConfig", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
+    @ResponseBody
+    public String getSystemConfig() {
+        ResponseResult<SystemBean> responseResult = new ResponseResult<SystemBean>();
+        SystemBean systemBean = systemRepository.findSystemBean();
+        responseResult.setContent(systemBean);
+        responseResult.setCode(ResultCode.SUCCESS);
+        responseResult.setMessage("获取成功");
+        return JSON.toJSONString(responseResult);
+    }
+
+    /**
+     * 设置API是否为会员专属
+     */
+    @RequestMapping(value = "/api/setApiConfig", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
+    @ResponseBody
+    public String setApiConfig(@RequestHeader HttpHeaders header, boolean isApiVipOnly) {
+        ResponseResult<String> responseResult = new ResponseResult<String>();
+        responseResult.setMessage("设置失败");
+        if (!RequestTool.isRequestAdminValid(header, userRepository)) {
+            return JSON.toJSONString(responseResult);
+        }
+
+        SystemBean systemBean = systemRepository.findSystemBean();
+        if (systemBean == null) {
+            systemBean = new SystemBean();
+        }
+        systemBean.isVipLimit = isApiVipOnly;
+        systemRepository.save(systemBean);
+
+        responseResult.setCode(ResultCode.SUCCESS);
+        responseResult.setMessage("设置成功");
+        return JSON.toJSONString(responseResult);
+    }
+
     /**
      * 查询版本更新信息
      */

+ 21 - 0
src/main/java/com/miekir/shibei/repository/SystemRepository.java

@@ -0,0 +1,21 @@
+package com.miekir.shibei.repository;
+
+import com.miekir.shibei.bean.CouponBean;
+import com.miekir.shibei.bean.SystemBean;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
+import org.springframework.stereotype.Repository;
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ * Created by sjj on 2015/10/24 0024.
+ */
+// 添加注解
+@Repository
+public interface SystemRepository extends JpaRepository<SystemBean, Integer> {
+
+    @Transactional
+    @Query(value = "SELECT * FROM t_system ORDER BY id DESC LIMIT 1", nativeQuery=true)
+    public SystemBean findSystemBean();
+}

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

@@ -14,7 +14,8 @@ import org.springframework.transaction.annotation.Transactional;
 public interface UpgradeRepository extends JpaRepository<UpgradeBean, Integer> {
     // 使用原生SQL语句查找最新一条记录
     @Transactional
-
     @Query(value = "SELECT * FROM t_upgrade ORDER BY id DESC LIMIT 1", nativeQuery=true)
     public UpgradeBean findLatestUpgradeInfo();
+
+
 }