| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027 |
- package com.ruixuan.isc.service.impl;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.google.common.collect.Lists;
- import com.monitorjbl.xlsx.StreamingReader;
- 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.LoadFileUtil;
- import com.ruixuan.common.utils.PageUtils;
- import com.ruixuan.common.utils.RedisUtil;
- import com.ruixuan.common.utils.Result;
- import com.ruixuan.common.utils.file.FileUtil;
- import com.ruixuan.common.utils.http.HttpUtil;
- import com.ruixuan.data.utils.ExportExcelUtils;
- import com.ruixuan.isc.entity.FirstDeliveryValidMaterials;
- import com.ruixuan.isc.entity.JYKuaishouPromoter;
- import com.ruixuan.isc.entity.KuaishouItemCollectSamples;
- import com.ruixuan.isc.entity.KuaishouPromoter;
- import com.ruixuan.isc.mapper.FirstDeliveryValidMapper;
- import com.ruixuan.isc.mapper.KuaishouPromoterMapper;
- import com.ruixuan.isc.service.IKuaishouItemCollectSamplesService;
- 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.apache.commons.io.IOUtils;
- import org.apache.poi.ss.usermodel.Row;
- import org.apache.poi.ss.usermodel.Sheet;
- import org.apache.poi.ss.usermodel.Workbook;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.stereotype.Service;
- import org.springframework.web.multipart.MultipartFile;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.InputStream;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Collections;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.UUID;
- import java.util.concurrent.ExecutorService;
- import java.util.concurrent.Executors;
- import java.util.regex.Pattern;
- /**
- * 快手达人 信息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 FirstDeliveryValidMapper deliveryValidMapper;
- @Autowired
- private ISysDeptService deptService;
- @Autowired
- private ISysRoleService roleService;
- @Autowired
- private RedisUtil redisUtil;
- @Autowired
- private IKuaishouItemCollectSamplesService kuaishouItemCollectSamplesService;
- /**
- * 查询快手达人 信息列表
- *
- * @param kuaishouPromoter 快手达人 信息
- * @return 快手达人 信息
- */
- @Override
- public List<KuaishouPromoter> selectKuaishouPromoterList(Long userId, String promoterId, String promoterNickName, String mediaId, String parameter, String orderBy, Long bdUserId) {
- String roleKey = sysUserService.getRoleKeyByUserId(userId);
- List<Long> userList = new ArrayList<>();
- //角色:供应链管理员、招商、招商经理可以看到所有的达人信息
- if (roleKey.contains("courtship") || "supplyChainAdmin".equals(roleKey) || "admin".equals(roleKey)) {
- if (!Check.isNull(bdUserId)) {
- userList.add(bdUserId);
- }
- } else if ("bdManager".equals(roleKey) || "z".equals(roleKey)) {
- // 渠道经理、社群经理 可以看到自己创建的以及自己部门人员的达人信息
- if (!Check.isNull(bdUserId)) {
- userList.add(bdUserId);
- } else {
- 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();
- }
- if (Check.isNull(parameter)) {
- parameter = "create_time";
- } else {
- switch (parameter) {
- case "avg_video_sales":
- parameter = "avgVideoSalesOrder";
- break;
- case "video_sales":
- parameter = "videoSalesOrder";
- break;
- case "total_sale":
- parameter = "totalSaleOrder";
- break;
- }
- }
- if (Check.isNull(orderBy)) {
- orderBy = "desc";
- }
- PageUtils.startPage();
- List<KuaishouPromoter> list = kuaishouPromoterMapper.selectKuaishouPromoterList(userList, promoterId, promoterNickName, mediaId, parameter, orderBy, bdUserId);
- list.forEach(ent -> {
- JSONObject follow = kuaishouPromoterMapper.getFollowUpRecordsByUserId(ent.getPromoterId(), ent.getUserId());
- ent.setFollowUpRecord(Check.isNull(follow) ? "-" : follow.getString("txt"));
- List<JSONObject> promoterLabelList = kuaishouPromoterMapper.getPromoterLabel(ent.getPromoterId(), ent.getUserId());
- ent.setLabels(promoterLabelList);
- });
- return list;
- }
- @Override
- public List<JYKuaishouPromoter> selectKuaishouPromoterList3(Long userId, String promoterId, String promoterNickName, String mediaId, String type, String parameter, String orderBy) {
- String roleKey = sysUserService.getRoleKeyByUserId(userId);
- List<Long> userList = new ArrayList<>();
- //角色:管理员和骄阳管理员可以看到所有的达人信息
- Long expertMentorId = null;
- Long expertBusinessId = null;
- if ("admin".equals(roleKey) || "jy_admnin".equals(roleKey)) {
- userList = null;
- } else if ("jy_bd_manage".equals(roleKey) || "jy_scissors_manage".equals(roleKey) || "jy_out_operation_manager".equals(roleKey)) {
- // 骄阳渠道经理、骄阳剪手经理 可以看到自己创建的以及自己部门人员的达人信息
- Long deptId = deptService.getDeptIdByUserId(userId);
- userList = deptService.getDeptUserListByDeptId(deptId);
- } else if ("jy_bd".equals(roleKey) || "jy_scissors".equals(roleKey) || "jy_out_operation".equals(roleKey)) {
- // 骄阳渠道、骄阳-剪手 可以看到自己创建的达人信息
- userList = Arrays.asList(userId);
- } else if ("jy_expert_mentor".equals(roleKey) || "jy_expert_business".equals(roleKey)) {
- if ("jy_expert_mentor".equals(roleKey)) {
- expertMentorId = userId;
- }
- if ("jy_expert_business".equals(roleKey)) {
- expertBusinessId = userId;
- }
- } else {
- return Collections.emptyList();
- }
- if (Check.isNull(parameter)) {
- parameter = "create_time";
- } else {
- switch (parameter) {
- case "avg_video_sales":
- parameter = "avgVideoSalesOrder";
- break;
- case "video_sales":
- parameter = "videoSalesOrder";
- break;
- case "total_sale":
- parameter = "totalSaleOrder";
- break;
- }
- }
- if (Check.isNull(orderBy)) {
- orderBy = "desc";
- }
- PageUtils.startPage();
- List<JYKuaishouPromoter> list = kuaishouPromoterMapper.selectKuaishouPromoterList3(userList, promoterId, promoterNickName, mediaId, type, parameter, orderBy, expertMentorId, expertBusinessId);
- list.forEach(ent -> {
- JSONObject follow = kuaishouPromoterMapper.getFollowUpRecordsByUserId(ent.getPromoterId(), ent.getUserId());
- ent.setFollowUpRecord(Check.isNull(follow) ? "-" : follow.getString("txt"));
- List<JSONObject> promoterLabelList = kuaishouPromoterMapper.getPromoterLabel(ent.getPromoterId(), ent.getUserId());
- ent.setLabels(promoterLabelList);
- });
- return list;
- }
- @Override
- public List<JSONObject> selectKuaishouPromoterList2(Long userId, String promoterId, String promoterNickName, String status, String parameter, String orderBy) {
- if (Check.isNull(parameter)) {
- parameter = "promoterId";
- } else if ("avgVideoSales".equals(parameter)) {
- parameter = "avgVideoSalesOrder";
- } else if ("videoSales".equals(parameter)) {
- parameter = "videoSalesOrder";
- }
- if (Check.isNull(orderBy)) {
- orderBy = "desc";
- }
- PageUtils.startPage();
- List<JSONObject> list = kuaishouPromoterMapper.selectAllPromoterList(userId, promoterId, promoterNickName, status, parameter, orderBy);
- 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 {
- editPromoter(promoter.getId(), promoter.getMediaId(), promoter.getPromoterId(), true);
- } 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);
- data.put("promoterInfo", promoter);
- data.put("result", result);
- //跟进记录
- JSONObject followUpRecord = kuaishouPromoterMapper.getFollowUpRecordsByUserId(promoter.getPromoterId(), promoter.getUserId());
- data.put("followUpRecord", followUpRecord);
- Long followUpRecordId = null;
- if (Check.isNotNull(followUpRecord)) {
- followUpRecordId = followUpRecord.getLong("id");
- }
- List<JSONObject> followUpRecordList = kuaishouPromoterMapper.getFollowUpRecordListByPromoterId(promoter.getPromoterId(), followUpRecordId);
- data.put("historyFollowUpRecord", followUpRecordList);
- //标签
- List<JSONObject> promoterLabelList = kuaishouPromoterMapper.getPromoterLabel(promoter.getPromoterId(), promoter.getUserId());
- data.put("promoterLabelList", promoterLabelList);
- }
- } catch (Exception e) {
- e.printStackTrace();
- log.error("获取达人详情数据异常,{}", result);
- }
- return data;
- }
- /**
- * 新增快手达人 信息
- */
- @Override
- public JSONObject insertKuaishouPromoter(KuaishouPromoter promoter) {
- JSONObject result = new JSONObject();
- promoter.setPromoterId(promoter.getPromoterId().trim());
- KuaishouPromoter one = kuaishouPromoterMapper.getOneByIdAndPromoterId(promoter.getUserId(), promoter.getPromoterId());
- if (Check.isNotNull(one)) {
- result.put("code", 500);
- result.put("msg", "该数据已存在,请重新输入");
- return result;
- }
- // 如果 达人ID是字母 并且 媒体是快手,说明操作失误,媒体改为抖音
- if (!isNumeric(promoter.getPromoterId()) && "2".equals(promoter.getMediaId())) {
- promoter.setMediaId("1");
- }
- // if ("2".equals(promoter.getMediaId())) {
- // 快手、抖音 同一达人ID 不能绑定到多个渠道角色用户上
- String roleKey = sysUserService.getRoleKeyByUserId(promoter.getUserId());
- if (roleKey.contains("bd")) {
- List<JSONObject> keys = kuaishouPromoterMapper.getBoundPromoterRoleKey(promoter.getPromoterId());
- if (Check.isNotNull(keys)) {
- for (JSONObject key : keys) {
- String rKey = key.getString("role_key");
- if ("bd".equals(rKey) || "bdManager".equals(rKey)) {
- result.put("code", 500);
- result.put("msg", "该达人已被其他渠道人员绑定,绑定人:" + key.getString("user_name"));
- return result;
- }
- }
- }
- }
- // }
- //查询 设置可绑定达人数
- Integer count = kuaishouPromoterMapper.getUserPromotersCount(promoter.getUserId(), promoter.getMediaId());
- if (Check.isNotNull(count)) {
- //查询 已绑定达人数
- Integer hCount = kuaishouPromoterMapper.getBoundCount(promoter.getUserId());
- if (Check.isNotNull(hCount) && hCount >= count) {
- result.put("code", 500);
- result.put("msg", "绑定达人数过多,暂无法绑定!");
- return result;
- }
- }
- SysUser sysUser = sysUserService.selectUserById(promoter.getUserId());
- if (Check.isNotNull(sysUser)) {
- promoter.setUserName(sysUser.getNickName());
- }
- kuaishouPromoterMapper.insertKuaishouPromoter(promoter);
- editPromoter(promoter.getId(), promoter.getMediaId(), promoter.getPromoterId(), true);
- result.put("code", 200);
- result.put("msg", "success");
- return result;
- }
- /**
- * 同步更新数据
- */
- private void editPromoter(Long id, String mediaId, String promoterId, boolean flag) {
- try {
- if (flag) {
- /*缓存标记,每日第一次访问调用该接口,更新达人部分(昵称,省市,粉丝,总销售,头像等)数据*/
- 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);
- param.put("mediaId", mediaId);
- Long startTime = System.currentTimeMillis();
- String content = "";
- if ("2".equals(mediaId)) {
- content = HttpUtil.httpPostRequest(startIpPath + "promoterInfo/getPromoterId", param, null);
- Thread.sleep(3000);
- } else {
- content = HttpUtil.httpPostRequest(startIpPath + "promoterInfo/getPromoterId", param, null);
- Thread.sleep(60000);
- }
- JSONObject result = JSONObject.parseObject(content);
- if (Check.isNotNull(result) && Check.isNotNull(result.getString("promoterNickName"))) {
- log.info("--------------------达人更新,【入参】:{},【返回结果】:{}", param, result.toJSONString());
- String province = "";
- if (Check.isNotNull(result.getString("province"))) {
- province = result.getString("province").concat("-").concat(result.getString("city"));
- }
- KuaishouPromoter kuaishouPromoter = new KuaishouPromoter(
- id,
- result.getString("promoterNickName"),
- province,
- result.getString("promoterHeadImgUrl"),
- result.getString("fanNum"),
- result.getString("avgVideoSales"),
- result.getString("videoSales"),
- result.getString("totalSale"),
- promoterId
- );
- if ("1".equals(mediaId)) {
- String followerincr = result.getString("follower_incr");
- if (Check.isNotNull(followerincr) && !"-".equals(followerincr)) {
- kuaishouPromoter.setFollowerIncr(result.getLong("follower_incr"));
- } else {
- kuaishouPromoter.setFollowerIncr(0l);
- }
- kuaishouPromoter.setLiveCount30(result.getInteger("live_count_30"));
- kuaishouPromoter.setLiveAverageUser30(result.getString("live_average_user_30"));
- kuaishouPromoter.setAwemeDiggFollowerRation(result.getString("aweme_digg_follower_ration"));
- kuaishouPromoter.setAwemeAvgDiggCount30(result.getLong("aweme_avg_digg_count_30"));
- }
- kuaishouPromoterMapper.updateKuaishouPromoterByPromoterId(kuaishouPromoter);
- } else {
- log.error("更新达人失败,达人ID:{} 【返回结果】:{}", promoterId, result);
- }
- } catch (Exception e) {
- e.printStackTrace();
- log.error("更新达人信息异常", e);
- }
- }
- /**
- * 同步更新数据
- */
- private void editPromoter3(Long id, String mediaId, String promoterId, boolean flag) {
- try {
- if (flag) {
- /*缓存标记,每日第一次访问调用该接口,更新达人部分(昵称,省市,粉丝,总销售,头像等)数据*/
- String key = DateUtils.getDate() + "_" + promoterId + "_" + id;
- 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);
- param.put("mediaId", mediaId);
- Long startTime = System.currentTimeMillis();
- String content = HttpUtil.httpPostRequest(startIpPath + "promoterInfo/getPromoterId", param, null);
- Thread.sleep(3000);
- JSONObject result = JSONObject.parseObject(content);
- if (Check.isNotNull(result) && Check.isNotNull(result.getString("promoterNickName"))) {
- String province = "";
- if (Check.isNotNull(result.getString("province"))) {
- province = result.getString("province").concat("-").concat(result.getString("city"));
- }
- JYKuaishouPromoter kuaishouPromoter = new JYKuaishouPromoter(
- id,
- result.getString("promoterNickName"),
- province,
- result.getString("promoterHeadImgUrl"),
- result.getString("fanNum"),
- result.getString("avgVideoSales"),
- result.getString("videoSales"),
- result.getString("totalSale"),
- promoterId
- );
- kuaishouPromoterMapper.updateKuaishouPromoterByPromoterId3(kuaishouPromoter);
- } else {
- log.error("更新达人失败,达人ID:{} 【返回结果】:{}", promoterId, result);
- }
- } catch (Exception e) {
- e.printStackTrace();
- log.error("更新达人信息异常", e);
- }
- }
- /**
- * 同步更新数据
- */
- private void editMiaogousiPromoter(Long id, String mediaId, String promoterId, boolean flag) {
- try {
- if (flag) {
- /*缓存标记,每日第一次访问调用该接口,更新达人部分(昵称,省市,粉丝,总销售,头像等)数据*/
- String key = DateUtils.getDate() + "mgs_" + promoterId + "_" + id;
- 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);
- param.put("mediaId", mediaId);
- Long startTime = System.currentTimeMillis();
- String content = HttpUtil.httpPostRequest(startIpPath + "promoterInfo/getPromoterId", param, null);
- Thread.sleep(3000);
- JSONObject result = JSONObject.parseObject(content);
- if (Check.isNotNull(result) && Check.isNotNull(result.getString("promoterNickName"))) {
- String province = "";
- if (Check.isNotNull(result.getString("province"))) {
- province = result.getString("province").concat("-").concat(result.getString("city"));
- }
- KuaishouPromoter kuaishouPromoter = new KuaishouPromoter(
- id,
- result.getString("promoterNickName"),
- province,
- result.getString("promoterHeadImgUrl"),
- result.getString("fanNum"),
- result.getString("avgVideoSales"),
- result.getString("videoSales"),
- result.getString("totalSale"),
- promoterId
- );
- kuaishouPromoterMapper.updateMiaogousiKuaishouPromoterByPromoterId(kuaishouPromoter);
- } else {
- log.error("更新达人失败,达人ID:{} 【返回结果】:{}", promoterId, result);
- }
- } catch (Exception e) {
- e.printStackTrace();
- log.error("更新达人信息异常", e);
- }
- }
- /**
- * 同步更新数据
- */
- private void editRocketPromoter(Long id, String mediaId, String promoterId, boolean flag) {
- try {
- if (flag) {
- /*缓存标记,每日第一次访问调用该接口,更新达人部分(昵称,省市,粉丝,总销售,头像等)数据*/
- String key = DateUtils.getDate() + "rocket_" + promoterId + "_" + id;
- 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);
- param.put("mediaId", mediaId);
- Long startTime = System.currentTimeMillis();
- String content = HttpUtil.httpPostRequest(startIpPath + "promoterInfo/getPromoterId", param, null);
- Thread.sleep(3000);
- JSONObject result = JSONObject.parseObject(content);
- if (Check.isNotNull(result) && Check.isNotNull(result.getString("promoterNickName"))) {
- String province = "";
- if (Check.isNotNull(result.getString("province"))) {
- province = result.getString("province").concat("-").concat(result.getString("city"));
- }
- KuaishouPromoter kuaishouPromoter = new KuaishouPromoter(
- id,
- result.getString("promoterNickName"),
- province,
- result.getString("promoterHeadImgUrl"),
- result.getString("fanNum"),
- result.getString("avgVideoSales"),
- result.getString("videoSales"),
- result.getString("totalSale"),
- promoterId
- );
- kuaishouPromoterMapper.updateRocketKuaishouPromoterByPromoterId(kuaishouPromoter);
- } else {
- log.error("更新达人失败,达人ID:{} 【返回结果】:{}", promoterId, result);
- }
- } catch (Exception e) {
- e.printStackTrace();
- log.error("更新达人信息异常", e);
- }
- }
- @Override
- public JSONObject insertKuaishouPromoter3(JYKuaishouPromoter promoter) {
- JSONObject result = new JSONObject();
- promoter.setPromoterId(promoter.getPromoterId().trim());
- KuaishouPromoter one = kuaishouPromoterMapper.getOneByIdAndPromoterId3(null, promoter.getPromoterId());
- if (Check.isNotNull(one)) {
- result.put("code", 500);
- result.put("msg", "达人已被绑定,请重新选择 (绑定人:" + one.getUserName() + ")");
- return result;
- }
- SysUser sysUser = sysUserService.selectUserById(promoter.getUserId());
- if (Check.isNotNull(sysUser)) {
- promoter.setUserName(sysUser.getNickName());
- }
- if (!Check.isNull(promoter.getExpertBusinessId())) {
- SysUser businessUser = sysUserService.selectUserById(promoter.getExpertBusinessId());
- if (!Check.isNull(businessUser)) {
- promoter.setExpertBusinessName(businessUser.getNickName());
- }
- }
- if (!Check.isNull(promoter.getExpertMentorId())) {
- SysUser mentorUser = sysUserService.selectUserById(promoter.getExpertMentorId());
- if (!Check.isNull(mentorUser)) {
- promoter.setExpertMentorName(mentorUser.getNickName());
- }
- }
- kuaishouPromoterMapper.insertKuaishouPromoter3(promoter);
- // editPromoter3(promoter.getId(), promoter.getMediaId(), promoter.getPromoterId(), true);
- result.put("code", 200);
- result.put("msg", "success");
- return result;
- }
- @Override
- public Result supplementInfo() {
- List<KuaishouPromoter> list = kuaishouPromoterMapper.getFailInfo();
- Thread thread = new Thread() {
- @Override
- public void run() {
- try {
- list.forEach(kuaishouPromoter -> editPromoter(kuaishouPromoter.getId(), kuaishouPromoter.getMediaId(), kuaishouPromoter.getPromoterId(), false));
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- };
- thread.start();
- List<String> promoters = new ArrayList<>();
- list.forEach(kuaishouPromoter -> promoters.add(kuaishouPromoter.getPromoterId() + "【" + kuaishouPromoter.getMediaId() + "】"));
- promoters.add(supplementInfo3());
- promoters.add(miaogousiInfo());
- promoters.add(rocketInfo());
- return Result.success("共计" + list.size() + "条,数据补充中...", promoters);
- }
- //骄阳补全
- public String supplementInfo3() {
- List<JYKuaishouPromoter> list = kuaishouPromoterMapper.getFailInfo3();
- Thread thread = new Thread() {
- @Override
- public void run() {
- try {
- list.forEach(kuaishouPromoter -> editPromoter3(kuaishouPromoter.getId(), kuaishouPromoter.getMediaId(), kuaishouPromoter.getPromoterId(), false));
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- };
- thread.start();
- List<String> promoters = new ArrayList<>();
- list.forEach(kuaishouPromoter -> promoters.add(kuaishouPromoter.getPromoterId()));
- return "-------------骄阳共计" + list.size() + "条,达人IDS: " + promoters.toString();
- }
- //miaogousi
- public String miaogousiInfo() {
- List<JYKuaishouPromoter> list = kuaishouPromoterMapper.getMiaogousiInfoFailInfo();
- Thread thread = new Thread() {
- @Override
- public void run() {
- try {
- list.forEach(kuaishouPromoter -> editMiaogousiPromoter(kuaishouPromoter.getId(), kuaishouPromoter.getMediaId(), kuaishouPromoter.getPromoterId(), false));
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- };
- thread.start();
- List<String> promoters = new ArrayList<>();
- list.forEach(kuaishouPromoter -> promoters.add(kuaishouPromoter.getPromoterId()));
- return "-------------miaogousi共计" + list.size() + "条,达人IDS: " + promoters.toString();
- }
- //rocket
- public String rocketInfo() {
- List<JYKuaishouPromoter> list = kuaishouPromoterMapper.getRocketFailInfo();
- Thread thread = new Thread() {
- @Override
- public void run() {
- try {
- list.forEach(kuaishouPromoter -> editRocketPromoter(kuaishouPromoter.getId(), kuaishouPromoter.getMediaId(), kuaishouPromoter.getPromoterId(), false));
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- };
- thread.start();
- List<String> promoters = new ArrayList<>();
- list.forEach(kuaishouPromoter -> promoters.add(kuaishouPromoter.getPromoterId()));
- return "-------------rocket共计" + list.size() + "条,达人IDS: " + promoters.toString();
- }
- @Override
- public int addFollowUpRecords(JSONObject result) {
- return kuaishouPromoterMapper.addFollowUpRecords(result);
- }
- @Override
- public void updateFollowUpRecords(JSONObject result) {
- kuaishouPromoterMapper.updateFollowUpRecords(result);
- }
- @Override
- public Result getGongHaiVideoSales(String promoterId) {
- Map<String, Object> param = new HashMap<>();
- param.put("promoterId", promoterId);
- String url = startIpPath + "promoterInfo/updatePromoter";
- String content = HttpUtil.httpPostRequest(url, param, null);
- if ("0".equals(content)) {
- return Result.success();
- } else {
- log.error("查询达人公海销售额失败,达人ID:{}\nurl:{}", promoterId, url);
- return Result.error("失败");
- }
- }
- @Override
- public KuaishouPromoter getOnlyPromoterInfoByUserId(String promoterId, Long userId) {
- return kuaishouPromoterMapper.getOnlyPromoterInfoByUserId(promoterId, userId);
- }
- @Override
- public JSONObject addPromotersCount(Long userId, Long promotersCount, String mediaId) {
- kuaishouPromoterMapper.addPromotersCount(userId, promotersCount, mediaId);
- JSONObject result = new JSONObject();
- result.put("code", 200);
- result.put("msg", "success");
- return result;
- }
- @Override
- public String getRuleName(Long ruleId) {
- return kuaishouPromoterMapper.getRuleName(ruleId);
- }
- @Override
- public int addRule(String promoterId, Long ruleId, String ruleName) {
- return kuaishouPromoterMapper.addRule(promoterId, ruleId, ruleName);
- }
- @Override
- public List<String> selectPromoterIdListByTime(List<Long> userList, Long startDate, Long endDate) {
- return kuaishouPromoterMapper.selectPromoterIdListByTime(userList, startDate, endDate);
- }
- @Override
- public Result updatePromoterLabel(JSONObject result) {
- String promoterId = result.getString("promoterId");
- Long userId = result.getLong("userId");
- kuaishouPromoterMapper.deletePromoterLabel(promoterId, userId);
- JSONArray ids = result.getJSONArray("ids");
- if (Check.isNotNull(ids)) {
- List<JSONObject> list = new ArrayList<>();
- for (int i = 0; i < ids.size(); i++) {
- JSONObject obj = new JSONObject();
- Long labelId = ids.getLong(i);
- obj.put("promoterId", promoterId);
- obj.put("labelId", labelId);
- obj.put("userId", userId);
- list.add(obj);
- }
- kuaishouPromoterMapper.insertPromoterLabels(list);
- }
- return Result.success();
- }
- /**
- * 修改快手达人 信息
- *
- * @param kuaishouPromoter 快手达人 信息
- * @return 结果
- */
- @Override
- public int updateKuaishouPromoter(KuaishouPromoter kuaishouPromoter) {
- return kuaishouPromoterMapper.updateKuaishouPromoter(kuaishouPromoter);
- }
- /**
- * 修改快手达人 信息
- *
- * @param kuaishouPromoter 快手达人 信息
- * @return 结果
- */
- @Override
- public int updateKuaishouPromoter3(JYKuaishouPromoter promoter) {
- if (!Check.isNull(promoter.getExpertBusinessId())) {
- SysUser businessUser = sysUserService.selectUserById(promoter.getExpertBusinessId());
- if (!Check.isNull(businessUser)) {
- promoter.setExpertBusinessName(businessUser.getNickName());
- }
- }
- if (!Check.isNull(promoter.getExpertMentorId())) {
- SysUser mentorUser = sysUserService.selectUserById(promoter.getExpertMentorId());
- if (!Check.isNull(mentorUser)) {
- promoter.setExpertMentorName(mentorUser.getNickName());
- }
- }
- return kuaishouPromoterMapper.updateKuaishouPromoter3(promoter);
- }
- /**
- * 删除快手达人 信息信息
- *
- * @param id 快手达人 信息主键 follow_up_records
- * @return 结果
- */
- @Override
- public Result deleteKuaishouPromoterById(Long id, Long userId) {
- KuaishouPromoter promoter = kuaishouPromoterMapper.selectKuaishouPromoterById(id);
- List<KuaishouItemCollectSamples> list = kuaishouItemCollectSamplesService.getListByPromoterId(promoter.getPromoterId(), userId);
- for (KuaishouItemCollectSamples item : list) {
- if (item.getCollectSampleStatus() != 2 && item.getCollectSampleStatus() != 7) {
- return Result.error("该达人还有未完成的领样申请,请在完成后进行解绑!");
- }
- }
- if (Check.isNotNull(promoter)) {
- JSONObject record = new JSONObject();
- record.put("promoterId", promoter.getPromoterId());
- record.put("userId", promoter.getUserId());
- record.put("operatorId", userId);
- List<JSONObject> roles = sysUserService.getUserRoleByUserId(userId);
- if (Check.isNotNull(roles)) {
- record.put("roleName", roles.get(0).getString("role_name"));
- record.put("roleKey", roles.get(0).getString("role_key"));
- }
- kuaishouPromoterMapper.insertKuaishouPromoterRecord(record);
- }
- kuaishouPromoterMapper.deleteKuaishouPromoterById(id);
- return Result.success();
- }
- /**
- * 删除快手达人 信息信息
- *
- * @param id 快手达人 信息主键 follow_up_records
- * @return 结果
- */
- @Override
- public Result deleteKuaishouPromoterById3(Long id, Long userId) {
- JYKuaishouPromoter promoter = kuaishouPromoterMapper.selectKuaishouPromoterById3(id);
- if (Check.isNotNull(promoter)) {
- JSONObject record = new JSONObject();
- record.put("promoterId", promoter.getPromoterId());
- record.put("userId", promoter.getUserId());
- record.put("operatorId", userId);
- List<JSONObject> roles = sysUserService.getUserRoleByUserId(userId);
- if (Check.isNotNull(roles)) {
- record.put("roleName", roles.get(0).getString("role_name") + " (解绑骄阳)");
- record.put("roleKey", roles.get(0).getString("role_key"));
- }
- kuaishouPromoterMapper.insertKuaishouPromoterRecord(record);
- }
- kuaishouPromoterMapper.deleteKuaishouPromoterById3(id);
- return Result.success();
- }
- @Override
- public JSONObject selectKuaishouRulePromoterById(Long promoterId) {
- return kuaishouPromoterMapper.selectKuaishouRulePromoterById(promoterId);
- }
- @Override
- public List<JSONObject> jyExpertMentorList() {
- return kuaishouPromoterMapper.jyExpertMentorList();
- }
- @Override
- public List<JSONObject> jyExpertBusiness() {
- return kuaishouPromoterMapper.jyExpertBusiness();
- }
- @Value("${pcm.local-path}")
- private String downloadPath;
- @Override
- public void importExcelMaterials(MultipartFile file) throws InterruptedException {
- ExecutorService executorService = Executors.newFixedThreadPool(8);
- long t1 = System.currentTimeMillis();
- List<FirstDeliveryValidMaterials> dataList = null;
- StringBuffer path = new StringBuffer();
- try {
- path.append(downloadPath).append(DateUtils.getNowDateStr()).append("/").append(UUID.randomUUID().toString()).append("/");
- log.info("-------下载到服务器地址:{}", path.toString());
- dataList = this.analysisBIGBIGFile(file, path.toString());
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- LoadFileUtil.delFile(path.toString());
- }
- if (!Check.isNull(dataList)) {
- //根据当前年份和月份,删除旧数据
- FirstDeliveryValidMaterials material = dataList.get(0);
- deliveryValidMapper.delMaterials(material.getDeliveryYear(), material.getDeliveryMonth());
- //插入 数据量大于5Q,分批插入
- if (dataList.size() > 5000) {
- List<List<FirstDeliveryValidMaterials>> splitList = Lists.newArrayList(Lists.partition(dataList, 5000));
- splitList.forEach(materials -> executorService.submit(() -> {
- deliveryValidMapper.replaceBatchMaterials(materials);
- }));
- } else {
- deliveryValidMapper.replaceBatchMaterials(dataList);
- }
- }
- executorService.shutdown();
- while (true) {
- if (executorService.isTerminated()) {
- log.info("所有的子线程都结束了!");
- //执行宇鹏提供的sql
- deliveryValidMapper.replaceEtl();
- break;
- }
- Thread.sleep(1000L);//休眠1秒钟
- }
- log.info("------共用时" + (System.currentTimeMillis() - t1) / 1000 + "秒");
- }
- public List<FirstDeliveryValidMaterials> analysisBIGBIGFile(MultipartFile mfile, String path) throws Exception {
- InputStream is = null;
- String newFileUrl = FileUtil.approvalFile(mfile, path);
- List<FirstDeliveryValidMaterials> dataList = null;
- try {
- File file = new File(newFileUrl);
- is = new FileInputStream(file);
- Workbook workbook = StreamingReader.builder()
- .rowCacheSize(20000)
- .bufferSize(4096)
- .open(is);
- ExportExcelUtils eeu = new ExportExcelUtils();
- //最后一列(列数)
- int lastCellNum = 0;
- // list存储数据集
- dataList = new ArrayList<>();
- for (Sheet sheet : workbook) {
- // sheet.getLastRowNum()获取最后一个非空行的行下标,比如总行数为n,则返回的为n-1
- int sumPageNum = (sheet.getLastRowNum() + 1) / 20000 + 1; //计算分片数
- for (int i = 1; i <= sumPageNum; i++) { //读取每片范围内的内容
- int minRowNum = 20000 * (i - 1) + 1; //计算每片读取的行数范围
- int maxRowNum = 20000 * i;
- for (Row row : sheet) {
- if (lastCellNum == 0) {
- lastCellNum = row.getLastCellNum();
- }
- if (row != null) {
- Map<String, Object> columnValueMap = new HashMap<>();
- if (row.getRowNum() >= minRowNum && row.getRowNum() <= maxRowNum) {//控制每片读取的行
- //每行数据对象,按照顺序从0到(lastCellNum-1)记录
- JSONObject cellEntity = new JSONObject();
- for (int k = 0; k < lastCellNum; k++) {
- cellEntity.put(String.valueOf(k), eeu.getCellValue(row.getCell(k)));
- }
- FirstDeliveryValidMaterials material = new FirstDeliveryValidMaterials(cellEntity);
- if ("走量".equals(material.getOperationLabel())) {
- continue;
- }
- if (!Check.isNull(material.getStatDate())) {
- material.setDeliveryYear(material.getStatDate().substring(0, 4));
- }
- dataList.add(material);
- if (row.getRowNum() == maxRowNum) {//读取到每片最大行数限制,跳出,执行数据写入
- break;
- }
- }
- }
- }
- }
- }
- workbook.close();
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- IOUtils.closeQuietly(is);
- }
- return dataList;
- }
- @Override
- public AjaxResult getPromoterInfo(String 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.getMediaId(), promoter.getPromoterId(), true);
- } 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(String promoterId) {
- return kuaishouPromoterMapper.getOneByIdAndPromoterId(null, promoterId);
- }
- @Override
- public List<String> selectPromoterIdList(List<Long> userList, String mediaId) {
- return kuaishouPromoterMapper.selectPromoterIdList(userList, mediaId);
- }
- @Override
- public JSONObject getgetMonthPromoterTotal(List<Long> userList, String start, String end, String mediaId) {
- return kuaishouPromoterMapper.getgetMonthPromoterTotal(userList, start, end, mediaId);
- }
- /**
- * 判断是否为数字
- */
- public static boolean isNumeric(String str) {
- Pattern pattern = Pattern.compile("[0-9]*");
- return pattern.matcher(str).matches();
- }
- }
|