|
@@ -6,10 +6,15 @@ import cn.com.ctop.common.module.service.ICtopOauthTokenService;
|
|
|
import cn.com.ctop.common.module.utils.Check;
|
|
|
import cn.com.ctop.common.module.utils.LoadFileUtil;
|
|
|
import cn.com.ctop.kuaishou.modules.ai.entity.KuaishouCrowdPack;
|
|
|
+import cn.com.ctop.kuaishou.modules.ai.entity.KuaishouCrowdPackageRel;
|
|
|
import cn.com.ctop.kuaishou.modules.ai.mapper.KuaishouCrowdPackMapper;
|
|
|
import cn.com.ctop.kuaishou.modules.ai.service.IKuaishouCrowdPackService;
|
|
|
+import cn.com.ctop.kuaishou.modules.ai.service.IKuaishouCrowdPackageRelService;
|
|
|
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
|
|
|
import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouPopulationService;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
@@ -20,8 +25,9 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.UUID;
|
|
|
|
|
@@ -40,12 +46,18 @@ public class KuaishouCrowdPackServiceImpl extends ServiceImpl<KuaishouCrowdPackM
|
|
|
private KuaishouCrowdPackMapper crowdPackMapper;
|
|
|
|
|
|
@Autowired
|
|
|
+ private IKuaishouCrowdPackageRelService relService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
private ICtopOauthTokenService tokenService;
|
|
|
|
|
|
@Autowired
|
|
|
private IKuaishouPopulationService iKuaishouPopulationService;
|
|
|
|
|
|
@Autowired
|
|
|
+ private IKuaishouInterfaceService kuaishouInterfaceService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
UserAllocationMapper userAllocationMapper;
|
|
|
|
|
|
@Value("${zip.local.download-path}")
|
|
@@ -53,18 +65,10 @@ public class KuaishouCrowdPackServiceImpl extends ServiceImpl<KuaishouCrowdPackM
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public Result<Object> queryPageList(JSONObject request) {
|
|
|
- int pageNo = request.getInteger("pageNo");
|
|
|
- int pageSize = request.getInteger("pageSize");
|
|
|
- if (Check.isNull(pageNo)) {
|
|
|
- pageNo = 1;
|
|
|
- }
|
|
|
- if (Check.isNull(pageSize)) {
|
|
|
- pageSize = 10;
|
|
|
- }
|
|
|
- Long total = crowdPackMapper.getTotal(request);
|
|
|
+ public Result<Object> queryPageList(KuaishouCrowdPack kuaishouCrowdPack, Integer pageNo, Integer pageSize) {
|
|
|
+ Long total = crowdPackMapper.getTotal(kuaishouCrowdPack.getStatus(), kuaishouCrowdPack.getAccountName(), kuaishouCrowdPack.getOrientationName());
|
|
|
PageHelper.startPage(pageNo, pageSize, false);
|
|
|
- List<KuaishouCrowdPack> list = crowdPackMapper.queryPageList(request);
|
|
|
+ List<JSONObject> list = crowdPackMapper.queryPageList(kuaishouCrowdPack.getStatus(), kuaishouCrowdPack.getAccountName(), kuaishouCrowdPack.getOrientationName());
|
|
|
PageInfo pageInfo = new PageInfo(list);
|
|
|
pageInfo.setTotal(total);
|
|
|
return Result.ok(pageInfo);
|
|
@@ -75,10 +79,7 @@ public class KuaishouCrowdPackServiceImpl extends ServiceImpl<KuaishouCrowdPackM
|
|
|
StringBuffer path = new StringBuffer();
|
|
|
path.append(downloadPath).append(DateUtils.getNowDate(DateUtils.WEB_FORMAT)).append("/").append(UUID.randomUUID().toString()).append("/");
|
|
|
log.info("-------下载到服务器地址:{}", path.toString());
|
|
|
- String name = url.substring(url.lastIndexOf("/") + 1);
|
|
|
-// String newFileUrl = FilesUtil.writeFiles(path.toString(), url, name);
|
|
|
String newFileUrl = LoadFileUtil.downLoadFromUrl(url, path.toString());
|
|
|
-// String newFileUrl = url;
|
|
|
String md5 = null;
|
|
|
try {
|
|
|
md5 = LoadFileUtil.getMD5(newFileUrl);
|
|
@@ -87,18 +88,94 @@ public class KuaishouCrowdPackServiceImpl extends ServiceImpl<KuaishouCrowdPackM
|
|
|
}
|
|
|
CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
|
|
|
JSONObject jsonObject = iKuaishouPopulationService.updatePopulation(token, type, orientationName, newFileUrl);
|
|
|
- System.out.println("=============返回结果:"+jsonObject);
|
|
|
- if (jsonObject.getInteger("code") == 0) {
|
|
|
- KuaishouCrowdPack crowdPack = JSONObject.toJavaObject(jsonObject, KuaishouCrowdPack.class);
|
|
|
- crowdPack.setSignature(md5);
|
|
|
- crowdPack.setUrl(url);
|
|
|
- this.save(crowdPack);
|
|
|
+ LoadFileUtil.delFile(newFileUrl);
|
|
|
+ if (!Check.isNull(jsonObject)) {
|
|
|
+ if (jsonObject.getInteger("code") == 0) {
|
|
|
+ KuaishouCrowdPack crowdPack = JSONObject.toJavaObject(jsonObject.getJSONObject("data"), KuaishouCrowdPack.class);
|
|
|
+ crowdPack.setSignature(md5);
|
|
|
+ crowdPack.setUrl(url);
|
|
|
+ crowdPack.setMessage(jsonObject.getString("message"));
|
|
|
+ crowdPack.setStatDate(DateUtils.formatDate(new Date()));
|
|
|
+ this.save(crowdPack);
|
|
|
+ } else {
|
|
|
+ KuaishouCrowdPack crowdPack = new KuaishouCrowdPack();
|
|
|
+ crowdPack.setSignature(md5);
|
|
|
+ crowdPack.setUrl(url);
|
|
|
+ crowdPack.setMessage(jsonObject.getString("message"));
|
|
|
+ crowdPack.setStatDate(DateUtils.formatDate(new Date()));
|
|
|
+ this.save(crowdPack);
|
|
|
+ return Result.error(jsonObject.getString("message"));
|
|
|
+ }
|
|
|
}
|
|
|
- return null;
|
|
|
+ return Result.ok("success");
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Result<Object> accountPush(JSONObject request) {
|
|
|
+ JSONArray accountIds = request.getJSONArray("accountIds");
|
|
|
+ List<Long> longs = accountIds.toJavaList(Long.class);
|
|
|
+ Long orientationId = request.getLong("orientationId");
|
|
|
+ Long accountId = request.getLong("accountId");
|
|
|
+ CtopOauthToken token = tokenService.getTokenByAccountId(accountId);
|
|
|
+ QueryWrapper<KuaishouCrowdPack> wrapper = new QueryWrapper<>();
|
|
|
+ wrapper.eq("account_id", accountId);
|
|
|
+ wrapper.eq("orientation_id", orientationId);
|
|
|
+ KuaishouCrowdPack kuaishouCrowdPack = crowdPackMapper.selectOne(wrapper);
|
|
|
+ JSONObject jsonObject = iKuaishouPopulationService.pushAccountsPopulation(token, orientationId, accountIds);
|
|
|
+ if (jsonObject.getInteger("code") == 0) {
|
|
|
+ JSONObject data = jsonObject.getJSONObject("data");
|
|
|
+ if (!Check.isNull(data)) {
|
|
|
+ JSONArray success = data.getJSONArray("success");
|
|
|
+ List<KuaishouCrowdPackageRel> relList = new ArrayList<>();
|
|
|
+ for (Object account : success) {
|
|
|
+ KuaishouCrowdPackageRel rel = new KuaishouCrowdPackageRel();
|
|
|
+ rel.setAccountId((Long) account);
|
|
|
+ rel.setTgtAccountId(accountId);
|
|
|
+ rel.setMessage("OK");
|
|
|
+ rel.setStatDate(DateUtils.formatDate(new Date()));
|
|
|
+ rel.setOrientationId(orientationId);
|
|
|
+ rel.setOrientationName(kuaishouCrowdPack.getOrientationName());
|
|
|
+ relList.add(rel);
|
|
|
+ }
|
|
|
+ JSONArray fail = data.getJSONArray("fail");
|
|
|
+ for (Object account : fail) {
|
|
|
+ KuaishouCrowdPackageRel rel = new KuaishouCrowdPackageRel();
|
|
|
+ rel.setAccountId((Long) account);
|
|
|
+ rel.setTgtAccountId(accountId);
|
|
|
+ rel.setMessage(jsonObject.getString("message"));
|
|
|
+ rel.setStatDate(DateUtils.formatDate(new Date()));
|
|
|
+ rel.setOrientationId(orientationId);
|
|
|
+ rel.setOrientationName(kuaishouCrowdPack.getOrientationName());
|
|
|
+ relList.add(rel);
|
|
|
+ }
|
|
|
+ relService.saveBatch(relList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Result.ok("success");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void crowdListQuery() {
|
|
|
+ List<KuaishouCrowdPack> crowdList = crowdPackMapper.queryListByStatus();
|
|
|
+ for (int i = 0; i <= 7; i++) {
|
|
|
+ for (KuaishouCrowdPack crowdPack : crowdList) {
|
|
|
+ CtopOauthToken token = tokenService.getTokenByAccountId(crowdPack.getAccountId());
|
|
|
+ JSONObject jsonObject = iKuaishouPopulationService.getPopulationList(crowdPack.getAccountId(), token.getAccessToken(), i);
|
|
|
+ if (jsonObject.getInteger("code") == 0) {
|
|
|
+ JSONObject data = jsonObject.getJSONObject("data");
|
|
|
+ if (!Check.isNull(data)) {
|
|
|
+ JSONArray details = data.getJSONArray("details");
|
|
|
+ if (details.size() > 0) {
|
|
|
+ crowdPackMapper.updateBatch(details);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result<Object> queryRel(String type, Long orientationId, Long accountId, Integer pageNo, Integer pageSize) {
|
|
|
return null;
|
|
|
}
|
|
|
}
|