123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281 |
- package com.ruixuan.isc.service.impl;
- import com.alibaba.fastjson.JSONObject;
- import com.ruixuan.common.core.domain.AjaxResult;
- import com.ruixuan.common.core.domain.entity.SysUser;
- import com.ruixuan.common.utils.Check;
- import com.ruixuan.common.utils.DateUtils;
- import com.ruixuan.common.utils.PageUtils;
- import com.ruixuan.common.utils.RedisUtil;
- import com.ruixuan.common.utils.http.HttpUtil;
- import com.ruixuan.isc.entity.KuaishouPromoter;
- import com.ruixuan.isc.mapper.KuaishouPromoterMapper;
- import com.ruixuan.isc.service.IKuaishouPromoterService;
- import com.ruixuan.system.service.ISysDeptService;
- import com.ruixuan.system.service.ISysRoleService;
- import com.ruixuan.system.service.ISysUserService;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.stereotype.Service;
- import java.util.Arrays;
- import java.util.Collections;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- /**
- * 快手达人 信息Service业务层处理
- *
- * @author ruoyi
- * @date 2023-02-03
- */
- @Slf4j
- @Service
- public class KuaishouPromoterServiceImpl implements IKuaishouPromoterService {
- @Value("${promoter.start_ip_path}")
- private String startIpPath;
- @Value("${promoter.internal_ip_path}")
- private String internalIpPath;
- @Autowired
- private ISysUserService sysUserService;
- @Autowired
- private KuaishouPromoterMapper kuaishouPromoterMapper;
- @Autowired
- private ISysDeptService deptService;
- @Autowired
- private ISysRoleService roleService;
- @Autowired
- private RedisUtil redisUtil;
- /**
- * 查询快手达人 信息列表
- *
- * @param kuaishouPromoter 快手达人 信息
- * @return 快手达人 信息
- */
- @Override
- public List<KuaishouPromoter> selectKuaishouPromoterList(Long userId, Long promoterId, String promoterNickName) {
- String roleKey = sysUserService.getRoleKeyByUserId(userId + "");
- List<Long> userList = null;
- //角色:供应链管理员、招商、招商经理可以看到所有的达人信息
- if (roleKey.contains("courtship") || "supplyChainAdmin".equals(roleKey) || "admin".equals(roleKey)) {
- } else if ("bdManager".equals(roleKey) || "associationManager".equals(roleKey)) {
- // 渠道经理、社群经理 可以看到自己创建的以及自己部门人员的达人信息
- Long deptId = deptService.getDeptIdByUserId(userId);
- userList = deptService.getDeptUserListByDeptId(deptId);
- } else if ("bd".equals(roleKey)) {
- // 渠道可以看到自己创建的达人信息
- userList = Arrays.asList(userId);
- } else if ("association".equals(roleKey)) {
- // 社群可以看到所有社群的达人信息
- userList = sysUserService.getUserIdByRoleKey(roleKey);
- } else {
- return Collections.emptyList();
- }
- PageUtils.startPage();
- List<KuaishouPromoter> list = kuaishouPromoterMapper.selectKuaishouPromoterList(userList, promoterId, promoterNickName);
- return list;
- }
- /**
- * 查询快手达人 信息
- *
- * @param id 快手达人 信息主键
- * @return 快手达人 信息
- */
- @Override
- public JSONObject selectKuaishouPromoterById(Long id) {
- JSONObject data = new JSONObject();
- JSONObject result = null;
- try {
- KuaishouPromoter promoter = kuaishouPromoterMapper.selectKuaishouPromoterById(id);
- if (Check.isNotNull(promoter)) {
- Thread thread = new Thread() {
- @Override
- public void run() {
- try {
- // demo:PromoterId:1424128656
- editPromoter(promoter.getId(), promoter.getPromoterId());
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- };
- thread.start();
- Long startTime = System.currentTimeMillis();
- String content = HttpUtil.httpGetRequest(internalIpPath + "kuaiShou/promoter/getPromoterInfo?promoterId=" + promoter.getPromoterId());
- result = JSONObject.parseObject(content);
- log.info("获取达人详情数据,用时:{}s", (System.currentTimeMillis() - startTime) / 1000);
- data.put("promoterInfo", promoter);
- data.put("result", result);
- }
- } catch (Exception e) {
- e.printStackTrace();
- log.error("获取达人详情数据异常,{}", result);
- }
- return data;
- }
- /**
- * 新增快手达人 信息
- *
- * @param kuaishouPromoter 快手达人 信息
- */
- @Override
- public int insertKuaishouPromoter(KuaishouPromoter promoter) {
- KuaishouPromoter one = kuaishouPromoterMapper.getOneByIdAndPromoterId(promoter.getUserId(), promoter.getPromoterId());
- if (Check.isNotNull(one)) {
- return 0;
- }
- SysUser sysUser = sysUserService.selectUserById(promoter.getUserId());
- if (Check.isNotNull(sysUser)) {
- promoter.setUserName(sysUser.getNickName());
- }
- int i = kuaishouPromoterMapper.insertKuaishouPromoter(promoter);
- // demoPromoterId:1424128656
- editPromoter(promoter.getId(), promoter.getPromoterId());
- return i;
- }
- /**
- * 同步更新数据
- */
- private void editPromoter(Long id, Long promoterId) {
- try {
- /*缓存标记,每日第一次访问调用该接口,更新达人部分(昵称,省市,粉丝,总销售,头像等)数据*/
- String key = DateUtils.getDate() + "_" + id + "_" + promoterId;
- String value = (String) redisUtil.get(key);
- if (Check.isNotNull(value) && "1".equals(value)) {
- return;
- }
- redisUtil.set(key, "1", 60 * 60 * 24);
- /*更新达人数据*/
- Map<String, Object> param = new HashMap<>();
- param.put("promoterId", promoterId);
- Long startTime = System.currentTimeMillis();
- String content = HttpUtil.httpPostRequest(startIpPath + "promoterInfo/getPromoterId", param, null);
- JSONObject result = JSONObject.parseObject(content);
- log.info("更新达人信息,用时:{}s,返回结果:{}", (System.currentTimeMillis() - startTime) / 1000, result);
- if (Check.isNotNull(result)) {
- KuaishouPromoter kuaishouPromoter = new KuaishouPromoter(
- id, result.getString("promoterNickName"),
- result.getString("province").concat("-").concat(result.getString("city")),
- result.getString("promoterHeadImgUrl"),
- result.getString("fanNum"),
- result.getString("avgVideoSales"),
- result.getString("videoSales"),
- result.getString("totalSale")
- );
- kuaishouPromoterMapper.updateKuaishouPromoter(kuaishouPromoter);
- }
- } catch (Exception e) {
- e.printStackTrace();
- log.error("更新达人信息异常", e);
- }
- }
- /**
- * 修改快手达人 信息
- *
- * @param kuaishouPromoter 快手达人 信息
- * @return 结果
- */
- @Override
- public int updateKuaishouPromoter(KuaishouPromoter kuaishouPromoter) {
- return kuaishouPromoterMapper.updateKuaishouPromoter(kuaishouPromoter);
- }
- /**
- * 删除快手达人 信息信息
- *
- * @param id 快手达人 信息主键
- * @return 结果
- */
- @Override
- public int deleteKuaishouPromoterById(Long id, Long userId) {
- KuaishouPromoter promoter = kuaishouPromoterMapper.selectKuaishouPromoterById(id);
- if (Check.isNotNull(promoter)) {
- JSONObject record = new JSONObject();
- record.put("promoterId", promoter.getPromoterId());
- record.put("userId", promoter.getUserId());
- record.put("operatorId", userId);
- kuaishouPromoterMapper.insertKuaishouPromoterRecord(record);
- }
- return kuaishouPromoterMapper.deleteKuaishouPromoterById(id);
- }
- @Override
- public AjaxResult getPromoterInfo(Long promoterId) {
- AjaxResult ajaxResult = null;
- try {
- KuaishouPromoter promoter = kuaishouPromoterMapper.getOneByIdAndPromoterId(null, promoterId);
- JSONObject data = new JSONObject();
- if (Check.isNotNull(promoter)) {
- Thread thread = new Thread() {
- @Override
- public void run() {
- try {
- editPromoter(promoter.getId(), promoter.getPromoterId());
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- };
- thread.start();
- Long startTime = System.currentTimeMillis();
- String content = HttpUtil.httpGetRequest(internalIpPath + "kuaiShou/promoter/getPromoterVideoInfo?promoterId=" + promoter.getPromoterId());
- JSONObject result = JSONObject.parseObject(content);
- log.info("获取达人视频销售数据,用时:{}s", (System.currentTimeMillis() - startTime) / 1000);
- String start = DateUtils.getSubtractTime(new Date(), 31);
- String end = DateUtils.getDate();
- JSONObject info = kuaishouPromoterMapper.getNearlyMonthGmv(promoter.getPromoterId(), start, end);
- if (Check.isNotNull(info)) {
- data.put("orderAmount", info.getString("orderAmount"));
- data.put("operationCompletionRate", info.getString("operationCompletionRate"));
- }
- if (Check.isNotNull(result)) {
- data.put("avgVideoSales", result.getString("avgVideoSales"));
- data.put("videoSales", result.getString("videoSales"));
- }
- data.put("promoterId", promoter.getPromoterId());
- data.put("promoterUrl", promoter.getPromoterUrl());
- }
- ajaxResult = new AjaxResult(200, "查询成功", data);
- } catch (Exception e) {
- e.printStackTrace();
- log.error("获取达人详情数据异常");
- ajaxResult = new AjaxResult(500, "查询失败");
- }
- return ajaxResult;
- }
- @Override
- public KuaishouPromoter getOnlyPromoterInfo(Long promoterId) {
- return kuaishouPromoterMapper.getOneByIdAndPromoterId(null, promoterId);
- }
- @Override
- public List<Long> selectPromoterIdList(List<Long> userList) {
- return kuaishouPromoterMapper.selectPromoterIdList(userList);
- }
- @Override
- public JSONObject getgetMonthPromoterTotal(List<Long> userList, String start, String end) {
- return kuaishouPromoterMapper.getgetMonthPromoterTotal(userList, start, end);
- }
- }
|