fix bug
This commit is contained in:
parent
1ded29e34b
commit
cfaae3c17b
|
|
@ -1,17 +1,29 @@
|
|||
package com.ruoyi.web.controller.app;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ruoyi.common.core.domain.Result;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.system.domain.TbUser;
|
||||
import com.ruoyi.system.domain.TbUserImg;
|
||||
import com.ruoyi.system.domain.TbUserSingle;
|
||||
import com.ruoyi.system.service.ITbUserImgService;
|
||||
import com.ruoyi.system.service.ITbUserService;
|
||||
import com.ruoyi.system.service.ITbUserSingleService;
|
||||
import com.ruoyi.web.service.HxService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Slf4j
|
||||
@Api(tags = "App*用户信息")
|
||||
@RestController
|
||||
@RequestMapping(value = "/app/user")
|
||||
|
|
@ -21,9 +33,67 @@ public class TbUserAppController {
|
|||
@Autowired
|
||||
private ITbUserService tbUserService;
|
||||
|
||||
@Autowired
|
||||
private ITbUserSingleService tbUserSingleService;
|
||||
|
||||
@Autowired
|
||||
private ITbUserImgService tbUserImgService;
|
||||
|
||||
@Autowired
|
||||
private HxService hxService;
|
||||
|
||||
private final static String SZ_URL_PREFIX = "https://www.7799520.com/api/recommend/pc/luck/list?token=&page=";
|
||||
|
||||
@ResponseBody
|
||||
@PostMapping("/draw")
|
||||
@ApiOperation(value = "爬取数据", httpMethod = "POST")
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Result<String> drawData()
|
||||
{
|
||||
for (int i = 1; i< 40; i++){
|
||||
try {
|
||||
Thread.sleep(3000L);
|
||||
log.info("请求的url路径:{}", SZ_URL_PREFIX + i);
|
||||
String result = HttpUtil.get(SZ_URL_PREFIX + i);
|
||||
JSONObject resultJson = JSONObject.parseObject(result);
|
||||
JSONArray resultArray = resultJson.getJSONObject("data").getJSONArray("list");
|
||||
for (int index =0; index < resultArray.size(); index++){
|
||||
JSONObject json = resultArray.getJSONObject(index);
|
||||
TbUser tbUser = new TbUser();
|
||||
tbUser.setId(json.getLong("userid"));
|
||||
tbUser.setMobile("13888888888");
|
||||
tbUser.setPassword("123456");
|
||||
tbUserService.save(tbUser);
|
||||
|
||||
TbUserSingle userSingle = new TbUserSingle();
|
||||
userSingle.setUserId(tbUser.getId());
|
||||
userSingle.setStatus(1);
|
||||
userSingle.setBirthday(DateUtil.parse(json.getString("birthdayyear"),"yyyy"));
|
||||
userSingle.setSex(json.getLong("gender"));
|
||||
userSingle.setCreateTime(new Date());
|
||||
userSingle.setNickName(json.getString("username"));
|
||||
tbUserSingleService.save(userSingle);
|
||||
|
||||
TbUserImg tbUserImg = new TbUserImg();
|
||||
tbUserImg.setUserId(tbUser.getId());
|
||||
tbUserImg.setType(0L);
|
||||
tbUserImg.setImgUrl(json.getString("avatar"));
|
||||
tbUserImgService.save(tbUserImg);
|
||||
|
||||
log.info("用户:{}", tbUser);
|
||||
log.info("单身信息:{}", userSingle);
|
||||
log.info("图片:{}", tbUserImg);
|
||||
}
|
||||
|
||||
}catch (Exception e){
|
||||
log.error("单次请求失败,失败url是:{}", SZ_URL_PREFIX + i);
|
||||
}
|
||||
}
|
||||
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
|
||||
@ResponseBody
|
||||
@PostMapping("/add")
|
||||
@ApiOperation(value = "注册用户", httpMethod = "POST")
|
||||
|
|
|
|||
|
|
@ -122,7 +122,7 @@ public class TbUserSingleAppController {
|
|||
}else {
|
||||
notExcludeSex = recommendReq.getSex();
|
||||
}
|
||||
int randomPageNum = 1 + (int) (6 * Math.random());
|
||||
int randomPageNum = 1 + (int) (18 * Math.random());
|
||||
PageHelper.startPage(randomPageNum, pageSize);
|
||||
List<TbUserSingle> list = tbUserSingleService.lambdaQuery()
|
||||
.ne(ObjectUtil.isNotEmpty(notExcludeSex), TbUserSingle::getSex, notExcludeSex)
|
||||
|
|
|
|||
Loading…
Reference in New Issue