KuaishouPromoterServiceImpl.java 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027
  1. package com.ruixuan.isc.service.impl;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.google.common.collect.Lists;
  5. import com.monitorjbl.xlsx.StreamingReader;
  6. import com.ruixuan.common.core.domain.AjaxResult;
  7. import com.ruixuan.common.core.domain.entity.SysUser;
  8. import com.ruixuan.common.utils.Check;
  9. import com.ruixuan.common.utils.DateUtils;
  10. import com.ruixuan.common.utils.LoadFileUtil;
  11. import com.ruixuan.common.utils.PageUtils;
  12. import com.ruixuan.common.utils.RedisUtil;
  13. import com.ruixuan.common.utils.Result;
  14. import com.ruixuan.common.utils.file.FileUtil;
  15. import com.ruixuan.common.utils.http.HttpUtil;
  16. import com.ruixuan.data.utils.ExportExcelUtils;
  17. import com.ruixuan.isc.entity.FirstDeliveryValidMaterials;
  18. import com.ruixuan.isc.entity.JYKuaishouPromoter;
  19. import com.ruixuan.isc.entity.KuaishouItemCollectSamples;
  20. import com.ruixuan.isc.entity.KuaishouPromoter;
  21. import com.ruixuan.isc.mapper.FirstDeliveryValidMapper;
  22. import com.ruixuan.isc.mapper.KuaishouPromoterMapper;
  23. import com.ruixuan.isc.service.IKuaishouItemCollectSamplesService;
  24. import com.ruixuan.isc.service.IKuaishouPromoterService;
  25. import com.ruixuan.system.service.ISysDeptService;
  26. import com.ruixuan.system.service.ISysRoleService;
  27. import com.ruixuan.system.service.ISysUserService;
  28. import lombok.extern.slf4j.Slf4j;
  29. import org.apache.commons.io.IOUtils;
  30. import org.apache.poi.ss.usermodel.Row;
  31. import org.apache.poi.ss.usermodel.Sheet;
  32. import org.apache.poi.ss.usermodel.Workbook;
  33. import org.springframework.beans.factory.annotation.Autowired;
  34. import org.springframework.beans.factory.annotation.Value;
  35. import org.springframework.stereotype.Service;
  36. import org.springframework.web.multipart.MultipartFile;
  37. import java.io.File;
  38. import java.io.FileInputStream;
  39. import java.io.InputStream;
  40. import java.util.ArrayList;
  41. import java.util.Arrays;
  42. import java.util.Collections;
  43. import java.util.Date;
  44. import java.util.HashMap;
  45. import java.util.List;
  46. import java.util.Map;
  47. import java.util.UUID;
  48. import java.util.concurrent.ExecutorService;
  49. import java.util.concurrent.Executors;
  50. import java.util.regex.Pattern;
  51. /**
  52. * 快手达人 信息Service业务层处理
  53. *
  54. * @author ruoyi
  55. * @date 2023-02-03
  56. */
  57. @Slf4j
  58. @Service
  59. public class KuaishouPromoterServiceImpl implements IKuaishouPromoterService {
  60. @Value("${promoter.start_ip_path}")
  61. private String startIpPath;
  62. @Value("${promoter.internal_ip_path}")
  63. private String internalIpPath;
  64. @Autowired
  65. private ISysUserService sysUserService;
  66. @Autowired
  67. private KuaishouPromoterMapper kuaishouPromoterMapper;
  68. @Autowired
  69. private FirstDeliveryValidMapper deliveryValidMapper;
  70. @Autowired
  71. private ISysDeptService deptService;
  72. @Autowired
  73. private ISysRoleService roleService;
  74. @Autowired
  75. private RedisUtil redisUtil;
  76. @Autowired
  77. private IKuaishouItemCollectSamplesService kuaishouItemCollectSamplesService;
  78. /**
  79. * 查询快手达人 信息列表
  80. *
  81. * @param kuaishouPromoter 快手达人 信息
  82. * @return 快手达人 信息
  83. */
  84. @Override
  85. public List<KuaishouPromoter> selectKuaishouPromoterList(Long userId, String promoterId, String promoterNickName, String mediaId, String parameter, String orderBy, Long bdUserId) {
  86. String roleKey = sysUserService.getRoleKeyByUserId(userId);
  87. List<Long> userList = new ArrayList<>();
  88. //角色:供应链管理员、招商、招商经理可以看到所有的达人信息
  89. if (roleKey.contains("courtship") || "supplyChainAdmin".equals(roleKey) || "admin".equals(roleKey)) {
  90. if (!Check.isNull(bdUserId)) {
  91. userList.add(bdUserId);
  92. }
  93. } else if ("bdManager".equals(roleKey) || "z".equals(roleKey)) {
  94. // 渠道经理、社群经理 可以看到自己创建的以及自己部门人员的达人信息
  95. if (!Check.isNull(bdUserId)) {
  96. userList.add(bdUserId);
  97. } else {
  98. Long deptId = deptService.getDeptIdByUserId(userId);
  99. userList = deptService.getDeptUserListByDeptId(deptId);
  100. }
  101. } else if ("bd".equals(roleKey)) {
  102. // 渠道可以看到自己创建的达人信息
  103. userList = Arrays.asList(userId);
  104. } else if ("association".equals(roleKey)) {
  105. // 社群可以看到所有社群的达人信息
  106. userList = sysUserService.getUserIdByRoleKey(roleKey);
  107. } else {
  108. return Collections.emptyList();
  109. }
  110. if (Check.isNull(parameter)) {
  111. parameter = "create_time";
  112. } else {
  113. switch (parameter) {
  114. case "avg_video_sales":
  115. parameter = "avgVideoSalesOrder";
  116. break;
  117. case "video_sales":
  118. parameter = "videoSalesOrder";
  119. break;
  120. case "total_sale":
  121. parameter = "totalSaleOrder";
  122. break;
  123. }
  124. }
  125. if (Check.isNull(orderBy)) {
  126. orderBy = "desc";
  127. }
  128. PageUtils.startPage();
  129. List<KuaishouPromoter> list = kuaishouPromoterMapper.selectKuaishouPromoterList(userList, promoterId, promoterNickName, mediaId, parameter, orderBy, bdUserId);
  130. list.forEach(ent -> {
  131. JSONObject follow = kuaishouPromoterMapper.getFollowUpRecordsByUserId(ent.getPromoterId(), ent.getUserId());
  132. ent.setFollowUpRecord(Check.isNull(follow) ? "-" : follow.getString("txt"));
  133. List<JSONObject> promoterLabelList = kuaishouPromoterMapper.getPromoterLabel(ent.getPromoterId(), ent.getUserId());
  134. ent.setLabels(promoterLabelList);
  135. });
  136. return list;
  137. }
  138. @Override
  139. public List<JYKuaishouPromoter> selectKuaishouPromoterList3(Long userId, String promoterId, String promoterNickName, String mediaId, String type, String parameter, String orderBy) {
  140. String roleKey = sysUserService.getRoleKeyByUserId(userId);
  141. List<Long> userList = new ArrayList<>();
  142. //角色:管理员和骄阳管理员可以看到所有的达人信息
  143. Long expertMentorId = null;
  144. Long expertBusinessId = null;
  145. if ("admin".equals(roleKey) || "jy_admnin".equals(roleKey)) {
  146. userList = null;
  147. } else if ("jy_bd_manage".equals(roleKey) || "jy_scissors_manage".equals(roleKey) || "jy_out_operation_manager".equals(roleKey)) {
  148. // 骄阳渠道经理、骄阳剪手经理 可以看到自己创建的以及自己部门人员的达人信息
  149. Long deptId = deptService.getDeptIdByUserId(userId);
  150. userList = deptService.getDeptUserListByDeptId(deptId);
  151. } else if ("jy_bd".equals(roleKey) || "jy_scissors".equals(roleKey) || "jy_out_operation".equals(roleKey)) {
  152. // 骄阳渠道、骄阳-剪手 可以看到自己创建的达人信息
  153. userList = Arrays.asList(userId);
  154. } else if ("jy_expert_mentor".equals(roleKey) || "jy_expert_business".equals(roleKey)) {
  155. if ("jy_expert_mentor".equals(roleKey)) {
  156. expertMentorId = userId;
  157. }
  158. if ("jy_expert_business".equals(roleKey)) {
  159. expertBusinessId = userId;
  160. }
  161. } else {
  162. return Collections.emptyList();
  163. }
  164. if (Check.isNull(parameter)) {
  165. parameter = "create_time";
  166. } else {
  167. switch (parameter) {
  168. case "avg_video_sales":
  169. parameter = "avgVideoSalesOrder";
  170. break;
  171. case "video_sales":
  172. parameter = "videoSalesOrder";
  173. break;
  174. case "total_sale":
  175. parameter = "totalSaleOrder";
  176. break;
  177. }
  178. }
  179. if (Check.isNull(orderBy)) {
  180. orderBy = "desc";
  181. }
  182. PageUtils.startPage();
  183. List<JYKuaishouPromoter> list = kuaishouPromoterMapper.selectKuaishouPromoterList3(userList, promoterId, promoterNickName, mediaId, type, parameter, orderBy, expertMentorId, expertBusinessId);
  184. list.forEach(ent -> {
  185. JSONObject follow = kuaishouPromoterMapper.getFollowUpRecordsByUserId(ent.getPromoterId(), ent.getUserId());
  186. ent.setFollowUpRecord(Check.isNull(follow) ? "-" : follow.getString("txt"));
  187. List<JSONObject> promoterLabelList = kuaishouPromoterMapper.getPromoterLabel(ent.getPromoterId(), ent.getUserId());
  188. ent.setLabels(promoterLabelList);
  189. });
  190. return list;
  191. }
  192. @Override
  193. public List<JSONObject> selectKuaishouPromoterList2(Long userId, String promoterId, String promoterNickName, String status, String parameter, String orderBy) {
  194. if (Check.isNull(parameter)) {
  195. parameter = "promoterId";
  196. } else if ("avgVideoSales".equals(parameter)) {
  197. parameter = "avgVideoSalesOrder";
  198. } else if ("videoSales".equals(parameter)) {
  199. parameter = "videoSalesOrder";
  200. }
  201. if (Check.isNull(orderBy)) {
  202. orderBy = "desc";
  203. }
  204. PageUtils.startPage();
  205. List<JSONObject> list = kuaishouPromoterMapper.selectAllPromoterList(userId, promoterId, promoterNickName, status, parameter, orderBy);
  206. return list;
  207. }
  208. /**
  209. * 查询快手达人 信息
  210. *
  211. * @param id 快手达人 信息主键
  212. * @return 快手达人 信息
  213. */
  214. @Override
  215. public JSONObject selectKuaishouPromoterById(Long id) {
  216. JSONObject data = new JSONObject();
  217. JSONObject result = null;
  218. try {
  219. KuaishouPromoter promoter = kuaishouPromoterMapper.selectKuaishouPromoterById(id);
  220. if (Check.isNotNull(promoter)) {
  221. Thread thread = new Thread() {
  222. @Override
  223. public void run() {
  224. try {
  225. editPromoter(promoter.getId(), promoter.getMediaId(), promoter.getPromoterId(), true);
  226. } catch (Exception e) {
  227. e.printStackTrace();
  228. }
  229. }
  230. };
  231. thread.start();
  232. Long startTime = System.currentTimeMillis();
  233. String content = HttpUtil.httpGetRequest(internalIpPath + "kuaiShou/promoter/getPromoterInfo?promoterId=" + promoter.getPromoterId());
  234. result = JSONObject.parseObject(content);
  235. data.put("promoterInfo", promoter);
  236. data.put("result", result);
  237. //跟进记录
  238. JSONObject followUpRecord = kuaishouPromoterMapper.getFollowUpRecordsByUserId(promoter.getPromoterId(), promoter.getUserId());
  239. data.put("followUpRecord", followUpRecord);
  240. Long followUpRecordId = null;
  241. if (Check.isNotNull(followUpRecord)) {
  242. followUpRecordId = followUpRecord.getLong("id");
  243. }
  244. List<JSONObject> followUpRecordList = kuaishouPromoterMapper.getFollowUpRecordListByPromoterId(promoter.getPromoterId(), followUpRecordId);
  245. data.put("historyFollowUpRecord", followUpRecordList);
  246. //标签
  247. List<JSONObject> promoterLabelList = kuaishouPromoterMapper.getPromoterLabel(promoter.getPromoterId(), promoter.getUserId());
  248. data.put("promoterLabelList", promoterLabelList);
  249. }
  250. } catch (Exception e) {
  251. e.printStackTrace();
  252. log.error("获取达人详情数据异常,{}", result);
  253. }
  254. return data;
  255. }
  256. /**
  257. * 新增快手达人 信息
  258. */
  259. @Override
  260. public JSONObject insertKuaishouPromoter(KuaishouPromoter promoter) {
  261. JSONObject result = new JSONObject();
  262. promoter.setPromoterId(promoter.getPromoterId().trim());
  263. KuaishouPromoter one = kuaishouPromoterMapper.getOneByIdAndPromoterId(promoter.getUserId(), promoter.getPromoterId());
  264. if (Check.isNotNull(one)) {
  265. result.put("code", 500);
  266. result.put("msg", "该数据已存在,请重新输入");
  267. return result;
  268. }
  269. // 如果 达人ID是字母 并且 媒体是快手,说明操作失误,媒体改为抖音
  270. if (!isNumeric(promoter.getPromoterId()) && "2".equals(promoter.getMediaId())) {
  271. promoter.setMediaId("1");
  272. }
  273. // if ("2".equals(promoter.getMediaId())) {
  274. // 快手、抖音 同一达人ID 不能绑定到多个渠道角色用户上
  275. String roleKey = sysUserService.getRoleKeyByUserId(promoter.getUserId());
  276. if (roleKey.contains("bd")) {
  277. List<JSONObject> keys = kuaishouPromoterMapper.getBoundPromoterRoleKey(promoter.getPromoterId());
  278. if (Check.isNotNull(keys)) {
  279. for (JSONObject key : keys) {
  280. String rKey = key.getString("role_key");
  281. if ("bd".equals(rKey) || "bdManager".equals(rKey)) {
  282. result.put("code", 500);
  283. result.put("msg", "该达人已被其他渠道人员绑定,绑定人:" + key.getString("user_name"));
  284. return result;
  285. }
  286. }
  287. }
  288. }
  289. // }
  290. //查询 设置可绑定达人数
  291. Integer count = kuaishouPromoterMapper.getUserPromotersCount(promoter.getUserId(), promoter.getMediaId());
  292. if (Check.isNotNull(count)) {
  293. //查询 已绑定达人数
  294. Integer hCount = kuaishouPromoterMapper.getBoundCount(promoter.getUserId());
  295. if (Check.isNotNull(hCount) && hCount >= count) {
  296. result.put("code", 500);
  297. result.put("msg", "绑定达人数过多,暂无法绑定!");
  298. return result;
  299. }
  300. }
  301. SysUser sysUser = sysUserService.selectUserById(promoter.getUserId());
  302. if (Check.isNotNull(sysUser)) {
  303. promoter.setUserName(sysUser.getNickName());
  304. }
  305. kuaishouPromoterMapper.insertKuaishouPromoter(promoter);
  306. editPromoter(promoter.getId(), promoter.getMediaId(), promoter.getPromoterId(), true);
  307. result.put("code", 200);
  308. result.put("msg", "success");
  309. return result;
  310. }
  311. /**
  312. * 同步更新数据
  313. */
  314. private void editPromoter(Long id, String mediaId, String promoterId, boolean flag) {
  315. try {
  316. if (flag) {
  317. /*缓存标记,每日第一次访问调用该接口,更新达人部分(昵称,省市,粉丝,总销售,头像等)数据*/
  318. String key = DateUtils.getDate() + "_" + id + "_" + promoterId;
  319. String value = (String) redisUtil.get(key);
  320. if (Check.isNotNull(value) && "1".equals(value)) {
  321. return;
  322. }
  323. redisUtil.set(key, "1", 60 * 60 * 24);
  324. }
  325. /*更新达人数据*/
  326. Map<String, Object> param = new HashMap<>();
  327. param.put("promoterId", promoterId);
  328. param.put("mediaId", mediaId);
  329. Long startTime = System.currentTimeMillis();
  330. String content = "";
  331. if ("2".equals(mediaId)) {
  332. content = HttpUtil.httpPostRequest(startIpPath + "promoterInfo/getPromoterId", param, null);
  333. Thread.sleep(3000);
  334. } else {
  335. content = HttpUtil.httpPostRequest(startIpPath + "promoterInfo/getPromoterId", param, null);
  336. Thread.sleep(60000);
  337. }
  338. JSONObject result = JSONObject.parseObject(content);
  339. if (Check.isNotNull(result) && Check.isNotNull(result.getString("promoterNickName"))) {
  340. log.info("--------------------达人更新,【入参】:{},【返回结果】:{}", param, result.toJSONString());
  341. String province = "";
  342. if (Check.isNotNull(result.getString("province"))) {
  343. province = result.getString("province").concat("-").concat(result.getString("city"));
  344. }
  345. KuaishouPromoter kuaishouPromoter = new KuaishouPromoter(
  346. id,
  347. result.getString("promoterNickName"),
  348. province,
  349. result.getString("promoterHeadImgUrl"),
  350. result.getString("fanNum"),
  351. result.getString("avgVideoSales"),
  352. result.getString("videoSales"),
  353. result.getString("totalSale"),
  354. promoterId
  355. );
  356. if ("1".equals(mediaId)) {
  357. String followerincr = result.getString("follower_incr");
  358. if (Check.isNotNull(followerincr) && !"-".equals(followerincr)) {
  359. kuaishouPromoter.setFollowerIncr(result.getLong("follower_incr"));
  360. } else {
  361. kuaishouPromoter.setFollowerIncr(0l);
  362. }
  363. kuaishouPromoter.setLiveCount30(result.getInteger("live_count_30"));
  364. kuaishouPromoter.setLiveAverageUser30(result.getString("live_average_user_30"));
  365. kuaishouPromoter.setAwemeDiggFollowerRation(result.getString("aweme_digg_follower_ration"));
  366. kuaishouPromoter.setAwemeAvgDiggCount30(result.getLong("aweme_avg_digg_count_30"));
  367. }
  368. kuaishouPromoterMapper.updateKuaishouPromoterByPromoterId(kuaishouPromoter);
  369. } else {
  370. log.error("更新达人失败,达人ID:{} 【返回结果】:{}", promoterId, result);
  371. }
  372. } catch (Exception e) {
  373. e.printStackTrace();
  374. log.error("更新达人信息异常", e);
  375. }
  376. }
  377. /**
  378. * 同步更新数据
  379. */
  380. private void editPromoter3(Long id, String mediaId, String promoterId, boolean flag) {
  381. try {
  382. if (flag) {
  383. /*缓存标记,每日第一次访问调用该接口,更新达人部分(昵称,省市,粉丝,总销售,头像等)数据*/
  384. String key = DateUtils.getDate() + "_" + promoterId + "_" + id;
  385. String value = (String) redisUtil.get(key);
  386. if (Check.isNotNull(value) && "1".equals(value)) {
  387. return;
  388. }
  389. redisUtil.set(key, "1", 60 * 60 * 24);
  390. }
  391. /*更新达人数据*/
  392. Map<String, Object> param = new HashMap<>();
  393. param.put("promoterId", promoterId);
  394. param.put("mediaId", mediaId);
  395. Long startTime = System.currentTimeMillis();
  396. String content = HttpUtil.httpPostRequest(startIpPath + "promoterInfo/getPromoterId", param, null);
  397. Thread.sleep(3000);
  398. JSONObject result = JSONObject.parseObject(content);
  399. if (Check.isNotNull(result) && Check.isNotNull(result.getString("promoterNickName"))) {
  400. String province = "";
  401. if (Check.isNotNull(result.getString("province"))) {
  402. province = result.getString("province").concat("-").concat(result.getString("city"));
  403. }
  404. JYKuaishouPromoter kuaishouPromoter = new JYKuaishouPromoter(
  405. id,
  406. result.getString("promoterNickName"),
  407. province,
  408. result.getString("promoterHeadImgUrl"),
  409. result.getString("fanNum"),
  410. result.getString("avgVideoSales"),
  411. result.getString("videoSales"),
  412. result.getString("totalSale"),
  413. promoterId
  414. );
  415. kuaishouPromoterMapper.updateKuaishouPromoterByPromoterId3(kuaishouPromoter);
  416. } else {
  417. log.error("更新达人失败,达人ID:{} 【返回结果】:{}", promoterId, result);
  418. }
  419. } catch (Exception e) {
  420. e.printStackTrace();
  421. log.error("更新达人信息异常", e);
  422. }
  423. }
  424. /**
  425. * 同步更新数据
  426. */
  427. private void editMiaogousiPromoter(Long id, String mediaId, String promoterId, boolean flag) {
  428. try {
  429. if (flag) {
  430. /*缓存标记,每日第一次访问调用该接口,更新达人部分(昵称,省市,粉丝,总销售,头像等)数据*/
  431. String key = DateUtils.getDate() + "mgs_" + promoterId + "_" + id;
  432. String value = (String) redisUtil.get(key);
  433. if (Check.isNotNull(value) && "1".equals(value)) {
  434. return;
  435. }
  436. redisUtil.set(key, "1", 60 * 60 * 24);
  437. }
  438. /*更新达人数据*/
  439. Map<String, Object> param = new HashMap<>();
  440. param.put("promoterId", promoterId);
  441. param.put("mediaId", mediaId);
  442. Long startTime = System.currentTimeMillis();
  443. String content = HttpUtil.httpPostRequest(startIpPath + "promoterInfo/getPromoterId", param, null);
  444. Thread.sleep(3000);
  445. JSONObject result = JSONObject.parseObject(content);
  446. if (Check.isNotNull(result) && Check.isNotNull(result.getString("promoterNickName"))) {
  447. String province = "";
  448. if (Check.isNotNull(result.getString("province"))) {
  449. province = result.getString("province").concat("-").concat(result.getString("city"));
  450. }
  451. KuaishouPromoter kuaishouPromoter = new KuaishouPromoter(
  452. id,
  453. result.getString("promoterNickName"),
  454. province,
  455. result.getString("promoterHeadImgUrl"),
  456. result.getString("fanNum"),
  457. result.getString("avgVideoSales"),
  458. result.getString("videoSales"),
  459. result.getString("totalSale"),
  460. promoterId
  461. );
  462. kuaishouPromoterMapper.updateMiaogousiKuaishouPromoterByPromoterId(kuaishouPromoter);
  463. } else {
  464. log.error("更新达人失败,达人ID:{} 【返回结果】:{}", promoterId, result);
  465. }
  466. } catch (Exception e) {
  467. e.printStackTrace();
  468. log.error("更新达人信息异常", e);
  469. }
  470. }
  471. /**
  472. * 同步更新数据
  473. */
  474. private void editRocketPromoter(Long id, String mediaId, String promoterId, boolean flag) {
  475. try {
  476. if (flag) {
  477. /*缓存标记,每日第一次访问调用该接口,更新达人部分(昵称,省市,粉丝,总销售,头像等)数据*/
  478. String key = DateUtils.getDate() + "rocket_" + promoterId + "_" + id;
  479. String value = (String) redisUtil.get(key);
  480. if (Check.isNotNull(value) && "1".equals(value)) {
  481. return;
  482. }
  483. redisUtil.set(key, "1", 60 * 60 * 24);
  484. }
  485. /*更新达人数据*/
  486. Map<String, Object> param = new HashMap<>();
  487. param.put("promoterId", promoterId);
  488. param.put("mediaId", mediaId);
  489. Long startTime = System.currentTimeMillis();
  490. String content = HttpUtil.httpPostRequest(startIpPath + "promoterInfo/getPromoterId", param, null);
  491. Thread.sleep(3000);
  492. JSONObject result = JSONObject.parseObject(content);
  493. if (Check.isNotNull(result) && Check.isNotNull(result.getString("promoterNickName"))) {
  494. String province = "";
  495. if (Check.isNotNull(result.getString("province"))) {
  496. province = result.getString("province").concat("-").concat(result.getString("city"));
  497. }
  498. KuaishouPromoter kuaishouPromoter = new KuaishouPromoter(
  499. id,
  500. result.getString("promoterNickName"),
  501. province,
  502. result.getString("promoterHeadImgUrl"),
  503. result.getString("fanNum"),
  504. result.getString("avgVideoSales"),
  505. result.getString("videoSales"),
  506. result.getString("totalSale"),
  507. promoterId
  508. );
  509. kuaishouPromoterMapper.updateRocketKuaishouPromoterByPromoterId(kuaishouPromoter);
  510. } else {
  511. log.error("更新达人失败,达人ID:{} 【返回结果】:{}", promoterId, result);
  512. }
  513. } catch (Exception e) {
  514. e.printStackTrace();
  515. log.error("更新达人信息异常", e);
  516. }
  517. }
  518. @Override
  519. public JSONObject insertKuaishouPromoter3(JYKuaishouPromoter promoter) {
  520. JSONObject result = new JSONObject();
  521. promoter.setPromoterId(promoter.getPromoterId().trim());
  522. KuaishouPromoter one = kuaishouPromoterMapper.getOneByIdAndPromoterId3(null, promoter.getPromoterId());
  523. if (Check.isNotNull(one)) {
  524. result.put("code", 500);
  525. result.put("msg", "达人已被绑定,请重新选择 (绑定人:" + one.getUserName() + ")");
  526. return result;
  527. }
  528. SysUser sysUser = sysUserService.selectUserById(promoter.getUserId());
  529. if (Check.isNotNull(sysUser)) {
  530. promoter.setUserName(sysUser.getNickName());
  531. }
  532. if (!Check.isNull(promoter.getExpertBusinessId())) {
  533. SysUser businessUser = sysUserService.selectUserById(promoter.getExpertBusinessId());
  534. if (!Check.isNull(businessUser)) {
  535. promoter.setExpertBusinessName(businessUser.getNickName());
  536. }
  537. }
  538. if (!Check.isNull(promoter.getExpertMentorId())) {
  539. SysUser mentorUser = sysUserService.selectUserById(promoter.getExpertMentorId());
  540. if (!Check.isNull(mentorUser)) {
  541. promoter.setExpertMentorName(mentorUser.getNickName());
  542. }
  543. }
  544. kuaishouPromoterMapper.insertKuaishouPromoter3(promoter);
  545. // editPromoter3(promoter.getId(), promoter.getMediaId(), promoter.getPromoterId(), true);
  546. result.put("code", 200);
  547. result.put("msg", "success");
  548. return result;
  549. }
  550. @Override
  551. public Result supplementInfo() {
  552. List<KuaishouPromoter> list = kuaishouPromoterMapper.getFailInfo();
  553. Thread thread = new Thread() {
  554. @Override
  555. public void run() {
  556. try {
  557. list.forEach(kuaishouPromoter -> editPromoter(kuaishouPromoter.getId(), kuaishouPromoter.getMediaId(), kuaishouPromoter.getPromoterId(), false));
  558. } catch (Exception e) {
  559. e.printStackTrace();
  560. }
  561. }
  562. };
  563. thread.start();
  564. List<String> promoters = new ArrayList<>();
  565. list.forEach(kuaishouPromoter -> promoters.add(kuaishouPromoter.getPromoterId() + "【" + kuaishouPromoter.getMediaId() + "】"));
  566. promoters.add(supplementInfo3());
  567. promoters.add(miaogousiInfo());
  568. promoters.add(rocketInfo());
  569. return Result.success("共计" + list.size() + "条,数据补充中...", promoters);
  570. }
  571. //骄阳补全
  572. public String supplementInfo3() {
  573. List<JYKuaishouPromoter> list = kuaishouPromoterMapper.getFailInfo3();
  574. Thread thread = new Thread() {
  575. @Override
  576. public void run() {
  577. try {
  578. list.forEach(kuaishouPromoter -> editPromoter3(kuaishouPromoter.getId(), kuaishouPromoter.getMediaId(), kuaishouPromoter.getPromoterId(), false));
  579. } catch (Exception e) {
  580. e.printStackTrace();
  581. }
  582. }
  583. };
  584. thread.start();
  585. List<String> promoters = new ArrayList<>();
  586. list.forEach(kuaishouPromoter -> promoters.add(kuaishouPromoter.getPromoterId()));
  587. return "-------------骄阳共计" + list.size() + "条,达人IDS: " + promoters.toString();
  588. }
  589. //miaogousi
  590. public String miaogousiInfo() {
  591. List<JYKuaishouPromoter> list = kuaishouPromoterMapper.getMiaogousiInfoFailInfo();
  592. Thread thread = new Thread() {
  593. @Override
  594. public void run() {
  595. try {
  596. list.forEach(kuaishouPromoter -> editMiaogousiPromoter(kuaishouPromoter.getId(), kuaishouPromoter.getMediaId(), kuaishouPromoter.getPromoterId(), false));
  597. } catch (Exception e) {
  598. e.printStackTrace();
  599. }
  600. }
  601. };
  602. thread.start();
  603. List<String> promoters = new ArrayList<>();
  604. list.forEach(kuaishouPromoter -> promoters.add(kuaishouPromoter.getPromoterId()));
  605. return "-------------miaogousi共计" + list.size() + "条,达人IDS: " + promoters.toString();
  606. }
  607. //rocket
  608. public String rocketInfo() {
  609. List<JYKuaishouPromoter> list = kuaishouPromoterMapper.getRocketFailInfo();
  610. Thread thread = new Thread() {
  611. @Override
  612. public void run() {
  613. try {
  614. list.forEach(kuaishouPromoter -> editRocketPromoter(kuaishouPromoter.getId(), kuaishouPromoter.getMediaId(), kuaishouPromoter.getPromoterId(), false));
  615. } catch (Exception e) {
  616. e.printStackTrace();
  617. }
  618. }
  619. };
  620. thread.start();
  621. List<String> promoters = new ArrayList<>();
  622. list.forEach(kuaishouPromoter -> promoters.add(kuaishouPromoter.getPromoterId()));
  623. return "-------------rocket共计" + list.size() + "条,达人IDS: " + promoters.toString();
  624. }
  625. @Override
  626. public int addFollowUpRecords(JSONObject result) {
  627. return kuaishouPromoterMapper.addFollowUpRecords(result);
  628. }
  629. @Override
  630. public void updateFollowUpRecords(JSONObject result) {
  631. kuaishouPromoterMapper.updateFollowUpRecords(result);
  632. }
  633. @Override
  634. public Result getGongHaiVideoSales(String promoterId) {
  635. Map<String, Object> param = new HashMap<>();
  636. param.put("promoterId", promoterId);
  637. String url = startIpPath + "promoterInfo/updatePromoter";
  638. String content = HttpUtil.httpPostRequest(url, param, null);
  639. if ("0".equals(content)) {
  640. return Result.success();
  641. } else {
  642. log.error("查询达人公海销售额失败,达人ID:{}\nurl:{}", promoterId, url);
  643. return Result.error("失败");
  644. }
  645. }
  646. @Override
  647. public KuaishouPromoter getOnlyPromoterInfoByUserId(String promoterId, Long userId) {
  648. return kuaishouPromoterMapper.getOnlyPromoterInfoByUserId(promoterId, userId);
  649. }
  650. @Override
  651. public JSONObject addPromotersCount(Long userId, Long promotersCount, String mediaId) {
  652. kuaishouPromoterMapper.addPromotersCount(userId, promotersCount, mediaId);
  653. JSONObject result = new JSONObject();
  654. result.put("code", 200);
  655. result.put("msg", "success");
  656. return result;
  657. }
  658. @Override
  659. public String getRuleName(Long ruleId) {
  660. return kuaishouPromoterMapper.getRuleName(ruleId);
  661. }
  662. @Override
  663. public int addRule(String promoterId, Long ruleId, String ruleName) {
  664. return kuaishouPromoterMapper.addRule(promoterId, ruleId, ruleName);
  665. }
  666. @Override
  667. public List<String> selectPromoterIdListByTime(List<Long> userList, Long startDate, Long endDate) {
  668. return kuaishouPromoterMapper.selectPromoterIdListByTime(userList, startDate, endDate);
  669. }
  670. @Override
  671. public Result updatePromoterLabel(JSONObject result) {
  672. String promoterId = result.getString("promoterId");
  673. Long userId = result.getLong("userId");
  674. kuaishouPromoterMapper.deletePromoterLabel(promoterId, userId);
  675. JSONArray ids = result.getJSONArray("ids");
  676. if (Check.isNotNull(ids)) {
  677. List<JSONObject> list = new ArrayList<>();
  678. for (int i = 0; i < ids.size(); i++) {
  679. JSONObject obj = new JSONObject();
  680. Long labelId = ids.getLong(i);
  681. obj.put("promoterId", promoterId);
  682. obj.put("labelId", labelId);
  683. obj.put("userId", userId);
  684. list.add(obj);
  685. }
  686. kuaishouPromoterMapper.insertPromoterLabels(list);
  687. }
  688. return Result.success();
  689. }
  690. /**
  691. * 修改快手达人 信息
  692. *
  693. * @param kuaishouPromoter 快手达人 信息
  694. * @return 结果
  695. */
  696. @Override
  697. public int updateKuaishouPromoter(KuaishouPromoter kuaishouPromoter) {
  698. return kuaishouPromoterMapper.updateKuaishouPromoter(kuaishouPromoter);
  699. }
  700. /**
  701. * 修改快手达人 信息
  702. *
  703. * @param kuaishouPromoter 快手达人 信息
  704. * @return 结果
  705. */
  706. @Override
  707. public int updateKuaishouPromoter3(JYKuaishouPromoter promoter) {
  708. if (!Check.isNull(promoter.getExpertBusinessId())) {
  709. SysUser businessUser = sysUserService.selectUserById(promoter.getExpertBusinessId());
  710. if (!Check.isNull(businessUser)) {
  711. promoter.setExpertBusinessName(businessUser.getNickName());
  712. }
  713. }
  714. if (!Check.isNull(promoter.getExpertMentorId())) {
  715. SysUser mentorUser = sysUserService.selectUserById(promoter.getExpertMentorId());
  716. if (!Check.isNull(mentorUser)) {
  717. promoter.setExpertMentorName(mentorUser.getNickName());
  718. }
  719. }
  720. return kuaishouPromoterMapper.updateKuaishouPromoter3(promoter);
  721. }
  722. /**
  723. * 删除快手达人 信息信息
  724. *
  725. * @param id 快手达人 信息主键 follow_up_records
  726. * @return 结果
  727. */
  728. @Override
  729. public Result deleteKuaishouPromoterById(Long id, Long userId) {
  730. KuaishouPromoter promoter = kuaishouPromoterMapper.selectKuaishouPromoterById(id);
  731. List<KuaishouItemCollectSamples> list = kuaishouItemCollectSamplesService.getListByPromoterId(promoter.getPromoterId(), userId);
  732. for (KuaishouItemCollectSamples item : list) {
  733. if (item.getCollectSampleStatus() != 2 && item.getCollectSampleStatus() != 7) {
  734. return Result.error("该达人还有未完成的领样申请,请在完成后进行解绑!");
  735. }
  736. }
  737. if (Check.isNotNull(promoter)) {
  738. JSONObject record = new JSONObject();
  739. record.put("promoterId", promoter.getPromoterId());
  740. record.put("userId", promoter.getUserId());
  741. record.put("operatorId", userId);
  742. List<JSONObject> roles = sysUserService.getUserRoleByUserId(userId);
  743. if (Check.isNotNull(roles)) {
  744. record.put("roleName", roles.get(0).getString("role_name"));
  745. record.put("roleKey", roles.get(0).getString("role_key"));
  746. }
  747. kuaishouPromoterMapper.insertKuaishouPromoterRecord(record);
  748. }
  749. kuaishouPromoterMapper.deleteKuaishouPromoterById(id);
  750. return Result.success();
  751. }
  752. /**
  753. * 删除快手达人 信息信息
  754. *
  755. * @param id 快手达人 信息主键 follow_up_records
  756. * @return 结果
  757. */
  758. @Override
  759. public Result deleteKuaishouPromoterById3(Long id, Long userId) {
  760. JYKuaishouPromoter promoter = kuaishouPromoterMapper.selectKuaishouPromoterById3(id);
  761. if (Check.isNotNull(promoter)) {
  762. JSONObject record = new JSONObject();
  763. record.put("promoterId", promoter.getPromoterId());
  764. record.put("userId", promoter.getUserId());
  765. record.put("operatorId", userId);
  766. List<JSONObject> roles = sysUserService.getUserRoleByUserId(userId);
  767. if (Check.isNotNull(roles)) {
  768. record.put("roleName", roles.get(0).getString("role_name") + " (解绑骄阳)");
  769. record.put("roleKey", roles.get(0).getString("role_key"));
  770. }
  771. kuaishouPromoterMapper.insertKuaishouPromoterRecord(record);
  772. }
  773. kuaishouPromoterMapper.deleteKuaishouPromoterById3(id);
  774. return Result.success();
  775. }
  776. @Override
  777. public JSONObject selectKuaishouRulePromoterById(Long promoterId) {
  778. return kuaishouPromoterMapper.selectKuaishouRulePromoterById(promoterId);
  779. }
  780. @Override
  781. public List<JSONObject> jyExpertMentorList() {
  782. return kuaishouPromoterMapper.jyExpertMentorList();
  783. }
  784. @Override
  785. public List<JSONObject> jyExpertBusiness() {
  786. return kuaishouPromoterMapper.jyExpertBusiness();
  787. }
  788. @Value("${pcm.local-path}")
  789. private String downloadPath;
  790. @Override
  791. public void importExcelMaterials(MultipartFile file) throws InterruptedException {
  792. ExecutorService executorService = Executors.newFixedThreadPool(8);
  793. long t1 = System.currentTimeMillis();
  794. List<FirstDeliveryValidMaterials> dataList = null;
  795. StringBuffer path = new StringBuffer();
  796. try {
  797. path.append(downloadPath).append(DateUtils.getNowDateStr()).append("/").append(UUID.randomUUID().toString()).append("/");
  798. log.info("-------下载到服务器地址:{}", path.toString());
  799. dataList = this.analysisBIGBIGFile(file, path.toString());
  800. } catch (Exception e) {
  801. e.printStackTrace();
  802. } finally {
  803. LoadFileUtil.delFile(path.toString());
  804. }
  805. if (!Check.isNull(dataList)) {
  806. //根据当前年份和月份,删除旧数据
  807. FirstDeliveryValidMaterials material = dataList.get(0);
  808. deliveryValidMapper.delMaterials(material.getDeliveryYear(), material.getDeliveryMonth());
  809. //插入 数据量大于5Q,分批插入
  810. if (dataList.size() > 5000) {
  811. List<List<FirstDeliveryValidMaterials>> splitList = Lists.newArrayList(Lists.partition(dataList, 5000));
  812. splitList.forEach(materials -> executorService.submit(() -> {
  813. deliveryValidMapper.replaceBatchMaterials(materials);
  814. }));
  815. } else {
  816. deliveryValidMapper.replaceBatchMaterials(dataList);
  817. }
  818. }
  819. executorService.shutdown();
  820. while (true) {
  821. if (executorService.isTerminated()) {
  822. log.info("所有的子线程都结束了!");
  823. //执行宇鹏提供的sql
  824. deliveryValidMapper.replaceEtl();
  825. break;
  826. }
  827. Thread.sleep(1000L);//休眠1秒钟
  828. }
  829. log.info("------共用时" + (System.currentTimeMillis() - t1) / 1000 + "秒");
  830. }
  831. public List<FirstDeliveryValidMaterials> analysisBIGBIGFile(MultipartFile mfile, String path) throws Exception {
  832. InputStream is = null;
  833. String newFileUrl = FileUtil.approvalFile(mfile, path);
  834. List<FirstDeliveryValidMaterials> dataList = null;
  835. try {
  836. File file = new File(newFileUrl);
  837. is = new FileInputStream(file);
  838. Workbook workbook = StreamingReader.builder()
  839. .rowCacheSize(20000)
  840. .bufferSize(4096)
  841. .open(is);
  842. ExportExcelUtils eeu = new ExportExcelUtils();
  843. //最后一列(列数)
  844. int lastCellNum = 0;
  845. // list存储数据集
  846. dataList = new ArrayList<>();
  847. for (Sheet sheet : workbook) {
  848. // sheet.getLastRowNum()获取最后一个非空行的行下标,比如总行数为n,则返回的为n-1
  849. int sumPageNum = (sheet.getLastRowNum() + 1) / 20000 + 1; //计算分片数
  850. for (int i = 1; i <= sumPageNum; i++) { //读取每片范围内的内容
  851. int minRowNum = 20000 * (i - 1) + 1; //计算每片读取的行数范围
  852. int maxRowNum = 20000 * i;
  853. for (Row row : sheet) {
  854. if (lastCellNum == 0) {
  855. lastCellNum = row.getLastCellNum();
  856. }
  857. if (row != null) {
  858. Map<String, Object> columnValueMap = new HashMap<>();
  859. if (row.getRowNum() >= minRowNum && row.getRowNum() <= maxRowNum) {//控制每片读取的行
  860. //每行数据对象,按照顺序从0到(lastCellNum-1)记录
  861. JSONObject cellEntity = new JSONObject();
  862. for (int k = 0; k < lastCellNum; k++) {
  863. cellEntity.put(String.valueOf(k), eeu.getCellValue(row.getCell(k)));
  864. }
  865. FirstDeliveryValidMaterials material = new FirstDeliveryValidMaterials(cellEntity);
  866. if ("走量".equals(material.getOperationLabel())) {
  867. continue;
  868. }
  869. if (!Check.isNull(material.getStatDate())) {
  870. material.setDeliveryYear(material.getStatDate().substring(0, 4));
  871. }
  872. dataList.add(material);
  873. if (row.getRowNum() == maxRowNum) {//读取到每片最大行数限制,跳出,执行数据写入
  874. break;
  875. }
  876. }
  877. }
  878. }
  879. }
  880. }
  881. workbook.close();
  882. } catch (Exception e) {
  883. e.printStackTrace();
  884. } finally {
  885. IOUtils.closeQuietly(is);
  886. }
  887. return dataList;
  888. }
  889. @Override
  890. public AjaxResult getPromoterInfo(String promoterId) {
  891. AjaxResult ajaxResult = null;
  892. try {
  893. KuaishouPromoter promoter = kuaishouPromoterMapper.getOneByIdAndPromoterId(null, promoterId);
  894. JSONObject data = new JSONObject();
  895. if (Check.isNotNull(promoter)) {
  896. Thread thread = new Thread() {
  897. @Override
  898. public void run() {
  899. try {
  900. editPromoter(promoter.getId(), promoter.getMediaId(), promoter.getPromoterId(), true);
  901. } catch (Exception e) {
  902. e.printStackTrace();
  903. }
  904. }
  905. };
  906. thread.start();
  907. Long startTime = System.currentTimeMillis();
  908. String content = HttpUtil.httpGetRequest(internalIpPath + "kuaiShou/promoter/getPromoterVideoInfo?promoterId=" + promoter.getPromoterId());
  909. JSONObject result = JSONObject.parseObject(content);
  910. log.info("获取达人视频销售数据,用时:{}s", (System.currentTimeMillis() - startTime) / 1000);
  911. String start = DateUtils.getSubtractTime(new Date(), 31);
  912. String end = DateUtils.getDate();
  913. JSONObject info = kuaishouPromoterMapper.getNearlyMonthGmv(promoter.getPromoterId(), start, end);
  914. if (Check.isNotNull(info)) {
  915. data.put("orderAmount", info.getString("orderAmount"));
  916. data.put("operationCompletionRate", info.getString("operationCompletionRate"));
  917. }
  918. if (Check.isNotNull(result)) {
  919. data.put("avgVideoSales", result.getString("avgVideoSales"));
  920. data.put("videoSales", result.getString("videoSales"));
  921. }
  922. data.put("promoterId", promoter.getPromoterId());
  923. data.put("promoterUrl", promoter.getPromoterUrl());
  924. }
  925. ajaxResult = new AjaxResult(200, "查询成功", data);
  926. } catch (Exception e) {
  927. e.printStackTrace();
  928. log.error("获取达人详情数据异常");
  929. ajaxResult = new AjaxResult(500, "查询失败");
  930. }
  931. return ajaxResult;
  932. }
  933. @Override
  934. public KuaishouPromoter getOnlyPromoterInfo(String promoterId) {
  935. return kuaishouPromoterMapper.getOneByIdAndPromoterId(null, promoterId);
  936. }
  937. @Override
  938. public List<String> selectPromoterIdList(List<Long> userList, String mediaId) {
  939. return kuaishouPromoterMapper.selectPromoterIdList(userList, mediaId);
  940. }
  941. @Override
  942. public JSONObject getgetMonthPromoterTotal(List<Long> userList, String start, String end, String mediaId) {
  943. return kuaishouPromoterMapper.getgetMonthPromoterTotal(userList, start, end, mediaId);
  944. }
  945. /**
  946. * 判断是否为数字
  947. */
  948. public static boolean isNumeric(String str) {
  949. Pattern pattern = Pattern.compile("[0-9]*");
  950. return pattern.matcher(str).matches();
  951. }
  952. }