|
|
@@ -8,6 +8,7 @@ import com.miekir.shibei.bean.ResultCode;
|
|
|
import com.miekir.shibei.repository.CouponRepository;
|
|
|
import com.miekir.shibei.repository.UserRepository;
|
|
|
import com.miekir.shibei.tool.RequestTool;
|
|
|
+import com.miekir.shibei.tool.StringTool;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
import org.springframework.data.domain.Sort;
|
|
|
@@ -116,22 +117,62 @@ public class CouponController {
|
|
|
*/
|
|
|
@RequestMapping(value = "/api/getCouponList", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
|
|
|
@ResponseBody
|
|
|
- public String getCouponList(int pageNum, int pageSize) {
|
|
|
+ public String getCouponList(int couponType, int pageNum, int pageSize) {
|
|
|
ResponseResult<List<CouponBean>> responseResult = new ResponseResult<List<CouponBean>>();
|
|
|
responseResult.setMessage("获取失败");
|
|
|
|
|
|
// 自带的分页查询
|
|
|
- List<CouponBean> couponBeanList;
|
|
|
+ List<CouponBean> couponBeanList = null;
|
|
|
+ if (couponType == 0) {
|
|
|
+ // 查全部
|
|
|
+ try {
|
|
|
+ Sort sort = new Sort(Sort.Direction.DESC,"updateTimeMillis");
|
|
|
+ couponBeanList = couponRepository.findAll(new PageRequest(pageNum, pageSize, sort)).getContent();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return JSON.toJSONString(responseResult);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ couponBeanList = couponRepository.getCouponListByType(couponType, pageNum*pageSize, pageSize);
|
|
|
+ }
|
|
|
+
|
|
|
try {
|
|
|
- Sort sort = new Sort(Sort.Direction.DESC,"updateTimeMillis");
|
|
|
- couponBeanList = couponRepository.findAll(new PageRequest(pageNum, pageSize, sort)).getContent();
|
|
|
+ responseResult.setContent(couponBeanList);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
return JSON.toJSONString(responseResult);
|
|
|
}
|
|
|
|
|
|
+ responseResult.setCode(ResultCode.SUCCESS);
|
|
|
+ responseResult.setMessage("获取成功");
|
|
|
+ return JSON.toJSONString(responseResult);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据关键字查询优惠
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/api/getCouponListByKeyword", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
|
|
|
+ @ResponseBody
|
|
|
+ public String getGoodsListByKeyword(String keywords, int pageNum, int pageSize) {
|
|
|
+ String keywordsUtf8 = StringTool.getUtf8String(keywords);
|
|
|
+
|
|
|
+ ResponseResult<List<CouponBean>> responseResult = new ResponseResult<List<CouponBean>>();
|
|
|
+ responseResult.setMessage("获取失败");
|
|
|
+
|
|
|
+ // 自带的分页查询
|
|
|
+ List<CouponBean> goodsBeanList;
|
|
|
try {
|
|
|
- responseResult.setContent(couponBeanList);
|
|
|
+ // 如果pageNum为1,pageSize为20,则查询第1*20条到第1*20+20-1(这里的第几条是从0开始的)
|
|
|
+ // 模糊查询,要拼上%%
|
|
|
+ keywordsUtf8 = "%"+keywordsUtf8+"%";
|
|
|
+ goodsBeanList = couponRepository.getCouponListByKeyword(keywordsUtf8, pageNum*pageSize, pageSize);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return JSON.toJSONString(responseResult);
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ responseResult.setContent(goodsBeanList);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
return JSON.toJSONString(responseResult);
|