|
|
@@ -4,9 +4,12 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.miekir.shibei.bean.db.CouponBean;
|
|
|
import com.miekir.shibei.bean.ResponseResult;
|
|
|
import com.miekir.shibei.bean.ResultCode;
|
|
|
+import com.miekir.shibei.bean.db.SystemBean;
|
|
|
import com.miekir.shibei.repository.CouponRepository;
|
|
|
+import com.miekir.shibei.repository.SystemRepository;
|
|
|
import com.miekir.shibei.repository.UserRepository;
|
|
|
import com.miekir.shibei.tool.RequestTool;
|
|
|
+import com.miekir.shibei.tool.web.FileTool;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
import org.springframework.data.domain.Sort;
|
|
|
@@ -14,7 +17,10 @@ import org.springframework.http.HttpHeaders;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import java.io.File;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.Random;
|
|
|
|
|
|
@Controller
|
|
|
public class CouponController {
|
|
|
@@ -25,6 +31,11 @@ public class CouponController {
|
|
|
@Autowired
|
|
|
private UserRepository userRepository;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private SystemRepository systemRepository;
|
|
|
+
|
|
|
+ private Random mRandom = new Random();
|
|
|
+
|
|
|
/**
|
|
|
* 新增和更新优惠券
|
|
|
*/
|
|
|
@@ -116,26 +127,43 @@ public class CouponController {
|
|
|
@RequestMapping(value = "/api/getCouponList", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
|
|
|
@ResponseBody
|
|
|
public String getCouponList(int pageNum, int pageSize) {
|
|
|
- ResponseResult<List<CouponBean>> responseResult = new ResponseResult<List<CouponBean>>();
|
|
|
+ ResponseResult<List<String>> responseResult = new ResponseResult<List<String>>();
|
|
|
responseResult.setMessage("获取失败");
|
|
|
|
|
|
- // 自带的分页查询
|
|
|
- List<CouponBean> couponBeanList;
|
|
|
- try {
|
|
|
- Sort sort = new Sort(Sort.Direction.DESC,"updateTimeMillis");
|
|
|
- couponBeanList = couponRepository.findAll(new PageRequest(pageNum, pageSize, sort)).getContent();
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
+ // 关闭通道
|
|
|
+ SystemBean systemBean = systemRepository.findSystemBean();
|
|
|
+ if (systemBean != null && systemBean.isVipLimit) {
|
|
|
+ responseResult.setMessage("休息时间到");
|
|
|
return JSON.toJSONString(responseResult);
|
|
|
}
|
|
|
|
|
|
- try {
|
|
|
- responseResult.setContent(couponBeanList);
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
+
|
|
|
+ File photoDir = new File(FileTool.TARGET_DIR_AUTO_IMAGES);
|
|
|
+ String[] nameArray = photoDir.list();
|
|
|
+ if (nameArray == null || nameArray.length == 0) {
|
|
|
+ responseResult.setMessage("没有找到图片");
|
|
|
+ return JSON.toJSONString(responseResult);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> photoUrlList = new ArrayList<String>();
|
|
|
+ int maxPageNum = nameArray.length - pageSize + 1;
|
|
|
+ if (maxPageNum <= 1) {
|
|
|
+ for (String s : nameArray) {
|
|
|
+ photoUrlList.add(String.format(FileTool.FORMATTER_IMAGE_URL, s));
|
|
|
+ }
|
|
|
+
|
|
|
+ responseResult.setContent(photoUrlList);
|
|
|
+ responseResult.setCode(ResultCode.SUCCESS);
|
|
|
+ responseResult.setMessage("获取成功");
|
|
|
return JSON.toJSONString(responseResult);
|
|
|
}
|
|
|
|
|
|
+ int randomPageNum = mRandom.nextInt(maxPageNum);
|
|
|
+ for (int i = 0; i < pageSize; i++) {
|
|
|
+ photoUrlList.add(String.format(FileTool.FORMATTER_IMAGE_URL, nameArray[randomPageNum+i]));
|
|
|
+ }
|
|
|
+
|
|
|
+ responseResult.setContent(photoUrlList);
|
|
|
responseResult.setCode(ResultCode.SUCCESS);
|
|
|
responseResult.setMessage("获取成功");
|
|
|
return JSON.toJSONString(responseResult);
|