Browse Source

Merge remote-tracking branch 'origin/dev-mysql' into dev-mysql

wangdy 8 years ago
parent
commit
da1294a848

+ 35 - 2
src/main/java/com/uas/platform/b2c/prod/product/common/api/CommonCountController.java

@@ -3,6 +3,9 @@ package com.uas.platform.b2c.prod.product.common.api;
 import com.uas.platform.b2c.prod.product.common.model.CommonCount;
 import com.uas.platform.b2c.prod.product.common.service.CommonCountService;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.repository.query.Param;
+import org.springframework.util.StringUtils;
+import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RestController;
@@ -26,7 +29,37 @@ public class CommonCountController {
      * @return
      */
     @RequestMapping(method = RequestMethod.GET, params = "_status=actived")
-    public List<CommonCount> findActived() {
-        return commonCountService.findByStatus((short) 1, "b2c_index");
+    public List<CommonCount> findActived(@Param("userFor") String usedFor) {
+        usedFor = StringUtils.isEmpty(usedFor) ? "b2c_index" : usedFor;
+        return commonCountService.findByStatus((short) 1, usedFor);
     }
+
+    /**
+     * 根据ID获取计数器
+     * @author suntg
+     * @date 2017年11月7日17:03:28
+     * @return
+     */
+    @RequestMapping(value ="/{id}", method = RequestMethod.GET)
+    public CommonCount findById(@PathVariable("id") Long id) {
+        CommonCount commonCount = commonCountService.findById(id);
+        if(commonCount == null)
+            throw new IllegalArgumentException("参数ID错误,数据不存在");
+        return commonCount;
+    }
+
+    /**
+     * 根据ID获取计数器的结果
+     * @author suntg
+     * @date 2017年11月7日17:03:34
+     * @return
+     */
+    @RequestMapping(value ="/{id}/count", method = RequestMethod.GET)
+    public Long findCountById(@PathVariable("id") Long id) {
+        CommonCount commonCount = commonCountService.findById(id);
+        if(commonCount == null)
+            throw new IllegalArgumentException("参数ID错误,数据不存在");
+        return commonCount.getCount();
+    }
+
 }

+ 7 - 0
src/main/java/com/uas/platform/b2c/prod/product/common/service/CommonCountService.java

@@ -15,4 +15,11 @@ public interface CommonCountService {
      * @return
      */
     List<CommonCount> findByStatus(Short status, String usedFor);
+
+    /**
+     * 根据ID获取计数器内容
+     * @param id
+     * @return
+     */
+    CommonCount findById(Long id);
 }

+ 5 - 0
src/main/java/com/uas/platform/b2c/prod/product/common/service/impl/CommonCountServiceImpl.java

@@ -25,4 +25,9 @@ public class CommonCountServiceImpl implements CommonCountService{
         }
         return commonCounts;
     }
+
+    @Override
+    public CommonCount findById(Long id) {
+        return commonCountDao.findOne(id);
+    }
 }