|
@@ -0,0 +1,368 @@
|
|
|
+package cn.com.ctop.kuaishou.modules.label.service.impl;
|
|
|
+
|
|
|
+import cn.com.ctop.common.module.entity.TagInfo;
|
|
|
+import cn.com.ctop.kuaishou.modules.label.entity.LabelStandardInfo;
|
|
|
+import cn.com.ctop.kuaishou.modules.label.entity.MaterialLabelInfo;
|
|
|
+import cn.com.ctop.kuaishou.modules.label.mapper.MaterialLabelMapper;
|
|
|
+import cn.com.ctop.kuaishou.modules.label.service.MaterialLabelService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.jeecg.common.api.vo.Result;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Description: 素材标签
|
|
|
+ * @Author: zzy
|
|
|
+ * @Date: 2021-07-30
|
|
|
+ * @Version: V1.0
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+public class MaterialLabelServiceImpl implements MaterialLabelService {
|
|
|
+
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ MaterialLabelMapper materialLabelMapper;
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 清洗各素材指标入库
|
|
|
+ *
|
|
|
+ * @param
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Result filterMaterial() {
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ Result result = new Result();
|
|
|
+ try {
|
|
|
+ //查询所有素材标签
|
|
|
+ List<String> materiaSignature = materialLabelMapper.getMateriaSignature();
|
|
|
+ if (!materiaSignature.isEmpty()) {
|
|
|
+ materiaSignature.stream().forEach(str -> {
|
|
|
+ if (!str.isEmpty()) {
|
|
|
+ //获取素材产生消耗的最早日期
|
|
|
+ String materialFirstDate = materialLabelMapper.getMaterialFirstDate(str);
|
|
|
+ if (materialFirstDate != null) {
|
|
|
+ //获取30天之后的日期
|
|
|
+ String afterDate = getDateByNumber(materialFirstDate, 30);
|
|
|
+ //获取2天之后的日期
|
|
|
+ String afterDate2 = getDateByNumber(materialFirstDate, 2);
|
|
|
+ //根据日期查询素材各项指标入库
|
|
|
+ LabelStandardInfo labermessage = materialLabelMapper.getLabermessage(str, materialFirstDate, afterDate);
|
|
|
+ if (labermessage != null) {
|
|
|
+ //查询两天内数据
|
|
|
+ LabelStandardInfo labermessageByTwoDays = materialLabelMapper.getLabermessageByTwoDays(str, materialFirstDate, afterDate2);
|
|
|
+ if (labermessageByTwoDays.getActivationTwoDays() != null) {
|
|
|
+ labermessage.setActivationTwoDays(labermessageByTwoDays.getActivationTwoDays());
|
|
|
+ }
|
|
|
+ if (labermessageByTwoDays.getFormCountTwoDays() != null) {
|
|
|
+ labermessage.setFormCountTwoDays(labermessageByTwoDays.getFormCountTwoDays());
|
|
|
+ }
|
|
|
+ labermessage.setSignature(str);
|
|
|
+ labermessage.setChargeDate(materialFirstDate);
|
|
|
+ labermessage.setCreateTime(sdf.format(new Date()));
|
|
|
+ labermessage.setUpdateTime(sdf.format(new Date()));
|
|
|
+ //查询素材标签标准表是否存在此素材
|
|
|
+ LabelStandardInfo materialRecord = materialLabelMapper.getMaterialRecord(str);
|
|
|
+ if (materialRecord != null) {
|
|
|
+ //存在则更新
|
|
|
+ materialLabelMapper.updateMaterialRecord(labermessage);
|
|
|
+ } else {
|
|
|
+ //不存在插入
|
|
|
+ materialLabelMapper.saveLabelMessage(labermessage);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ }
|
|
|
+ result.success("success");
|
|
|
+ } catch (Exception e) {
|
|
|
+ result.error500("error");
|
|
|
+ log.info("清洗标签指标数据错误:{}", e.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据素材指标制定素材标签
|
|
|
+ *
|
|
|
+ * @param
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Result materialSpecificationLabel() {
|
|
|
+ Result result = new Result();
|
|
|
+ Map<String, String> tgaMap = new HashMap<>();
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+
|
|
|
+ try {
|
|
|
+ String date = sdf.format(new Date());
|
|
|
+ //查询所有标签
|
|
|
+ List<TagInfo> tagInfo = materialLabelMapper.getTagInfo();
|
|
|
+ if (!tagInfo.isEmpty()) {
|
|
|
+ tagInfo.stream().forEach(tag -> {
|
|
|
+ tgaMap.put(tag.getTagName(), tag.getTagCode() + ";" + tag.getId());
|
|
|
+ });
|
|
|
+ }
|
|
|
+ //查询素材标签判断标准数据
|
|
|
+ List<LabelStandardInfo> allMaterialData = materialLabelMapper.getAllMaterialData();
|
|
|
+ if (!allMaterialData.isEmpty()) {
|
|
|
+ allMaterialData.stream().forEach(obj -> {
|
|
|
+ //三十天内累计激活数
|
|
|
+ String activationThirtyDays = obj.getActivationThirtyDays();
|
|
|
+ //两天内累计激活数
|
|
|
+ String activationTwoDays = obj.getActivationTwoDays();
|
|
|
+ //30天内表单提交数
|
|
|
+ String formCountThirtyDays = obj.getFormCountThirtyDays();
|
|
|
+ //两天内表单提交数
|
|
|
+ String formCountTwoDays = obj.getFormCountTwoDays();
|
|
|
+ //30天内3s完播率
|
|
|
+ String play3sRatio = obj.getPlay3sRatio();
|
|
|
+ //30天内转化率
|
|
|
+ String conversionRatio = obj.getConversionRatio();
|
|
|
+ //30天内行为率
|
|
|
+ String behaviorRation = obj.getBehaviorRation();
|
|
|
+ //30天内次留率
|
|
|
+ String eventNextDayStayRatio = obj.getEventNextDayStayRatio();
|
|
|
+ //应用下载--合格素材
|
|
|
+ if (activationThirtyDays != null && formCountThirtyDays != null && Integer.parseInt(activationThirtyDays) >= 100 && Integer.parseInt(formCountThirtyDays) == 0) {
|
|
|
+ String[] split = tgaMap.get("应用下载--合格素材").split(";");
|
|
|
+ int count = materialLabelMapper.getDataByCodeAndSignature(obj.getSignature(), split[0]);
|
|
|
+ //次素材没有打此标签
|
|
|
+ if (count == 0) {
|
|
|
+ materialLabelMapper.saveMaterialTag(obj.getSignature(), "应用下载--合格素材", split[0], split[1], "1", date);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //应应用下载--起量快
|
|
|
+ if (activationTwoDays != null && formCountTwoDays != null && Integer.parseInt(activationTwoDays) >= 96 && Integer.parseInt(formCountTwoDays) == 0) {
|
|
|
+ String[] split = tgaMap.get("应用下载--起量快").split(";");
|
|
|
+ int count = materialLabelMapper.getDataByCodeAndSignature(obj.getSignature(), split[0]);
|
|
|
+ //次素材没有打此标签
|
|
|
+ if (count == 0) {
|
|
|
+ materialLabelMapper.saveMaterialTag(obj.getSignature(), "应用下载--起量快", split[0], split[1], "1", date);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //应用下载-高-3s完播率
|
|
|
+ if (activationThirtyDays != null && play3sRatio != null && Integer.parseInt(activationThirtyDays) >= 100 && Double.parseDouble(play3sRatio) > 0.657) {
|
|
|
+ String[] split = tgaMap.get("应用下载-高-3s完播率").split(";");
|
|
|
+ int count = materialLabelMapper.getDataByCodeAndSignature(obj.getSignature(), split[0]);
|
|
|
+ //次素材没有打此标签
|
|
|
+ if (count == 0) {
|
|
|
+ materialLabelMapper.saveMaterialTag(obj.getSignature(), "应用下载-高-3s完播率", split[0], split[1], "1", date);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 应用下载-低-3s完播率
|
|
|
+ if (activationThirtyDays != null && play3sRatio != null && Integer.parseInt(activationThirtyDays) >= 100 && Double.parseDouble(play3sRatio) < 0.132) {
|
|
|
+ String[] split = tgaMap.get("应用下载-低-3s完播率").split(";");
|
|
|
+ int count = materialLabelMapper.getDataByCodeAndSignature(obj.getSignature(), split[0]);
|
|
|
+ //次素材没有打此标签
|
|
|
+ if (count == 0) {
|
|
|
+ materialLabelMapper.saveMaterialTag(obj.getSignature(), "应用下载-低-3s完播率", split[0], split[1], "1", date);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 应用下载-高-转化率
|
|
|
+ if (activationThirtyDays != null && conversionRatio != null && Integer.parseInt(activationThirtyDays) >= 100 && Double.parseDouble(conversionRatio) > 0.366) {
|
|
|
+ String[] split = tgaMap.get("应用下载-高-转化率").split(";");
|
|
|
+ int count = materialLabelMapper.getDataByCodeAndSignature(obj.getSignature(), split[0]);
|
|
|
+ //次素材没有打此标签
|
|
|
+ if (count == 0) {
|
|
|
+ materialLabelMapper.saveMaterialTag(obj.getSignature(), "应用下载-高-转化率", split[0], split[1], "1", date);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 应用下载-低-转化率
|
|
|
+ if (activationThirtyDays != null && conversionRatio != null && Integer.parseInt(activationThirtyDays) >= 100 && Double.parseDouble(conversionRatio) < 0.009) {
|
|
|
+ String[] split = tgaMap.get("应用下载-低-转化率").split(";");
|
|
|
+ int count = materialLabelMapper.getDataByCodeAndSignature(obj.getSignature(), split[0]);
|
|
|
+ //次素材没有打此标签
|
|
|
+ if (count == 0) {
|
|
|
+ materialLabelMapper.saveMaterialTag(obj.getSignature(), "应用下载-低-转化率", split[0], split[1], "1", date);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 应用下载-高-行为率
|
|
|
+ if (activationThirtyDays != null && behaviorRation != null && Integer.parseInt(activationThirtyDays) >= 100 && Double.parseDouble(behaviorRation) > 0.059) {
|
|
|
+ String[] split = tgaMap.get("应用下载-高-行为率").split(";");
|
|
|
+ int count = materialLabelMapper.getDataByCodeAndSignature(obj.getSignature(), split[0]);
|
|
|
+ //次素材没有打此标签
|
|
|
+ if (count == 0) {
|
|
|
+ materialLabelMapper.saveMaterialTag(obj.getSignature(), "应用下载-高-行为率", split[0], split[1], "1", date);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 应用下载-低-行为率
|
|
|
+ if (activationThirtyDays != null && behaviorRation != null && Integer.parseInt(activationThirtyDays) >= 100 && Double.parseDouble(behaviorRation) < 0.003) {
|
|
|
+ String[] split = tgaMap.get("应用下载-低-行为率").split(";");
|
|
|
+ int count = materialLabelMapper.getDataByCodeAndSignature(obj.getSignature(), split[0]);
|
|
|
+ //次素材没有打此标签
|
|
|
+ if (count == 0) {
|
|
|
+ materialLabelMapper.saveMaterialTag(obj.getSignature(), "应用下载-低-行为率", split[0], split[1], "1", date);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 应用下载-高-次留率
|
|
|
+ if (activationThirtyDays != null && eventNextDayStayRatio != null && Integer.parseInt(activationThirtyDays) >= 100 && Double.parseDouble(eventNextDayStayRatio) > 0.453) {
|
|
|
+ String[] split = tgaMap.get("应用下载-高-次留率").split(";");
|
|
|
+ int count = materialLabelMapper.getDataByCodeAndSignature(obj.getSignature(), split[0]);
|
|
|
+ //次素材没有打此标签
|
|
|
+ if (count == 0) {
|
|
|
+ materialLabelMapper.saveMaterialTag(obj.getSignature(), "应用下载-高-次留率", split[0], split[1], "1", date);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 应用下载-低-次留率
|
|
|
+ if (activationThirtyDays != null && eventNextDayStayRatio != null && Integer.parseInt(activationThirtyDays) >= 100 && Double.parseDouble(eventNextDayStayRatio) == 0.000) {
|
|
|
+ String[] split = tgaMap.get("应用下载-低-次留率").split(";");
|
|
|
+ int count = materialLabelMapper.getDataByCodeAndSignature(obj.getSignature(), split[0]);
|
|
|
+ //次素材没有打此标签
|
|
|
+ if (count == 0) {
|
|
|
+ materialLabelMapper.saveMaterialTag(obj.getSignature(), "应用下载-低-次留率", split[0], split[1], "1", date);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // 表单提交--合格素材
|
|
|
+ if (formCountThirtyDays != null && activationThirtyDays != null && Integer.parseInt(formCountThirtyDays) >= 20 && Integer.parseInt(activationThirtyDays) == 0) {
|
|
|
+ String[] split = tgaMap.get("表单提交--合格素材").split(";");
|
|
|
+ int count = materialLabelMapper.getDataByCodeAndSignature(obj.getSignature(), split[0]);
|
|
|
+ //次素材没有打此标签
|
|
|
+ if (count == 0) {
|
|
|
+ materialLabelMapper.saveMaterialTag(obj.getSignature(), "表单提交--合格素材", split[0], split[1], "1", date);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 表单提交--起量快
|
|
|
+ if (formCountTwoDays != null && activationTwoDays != null && Integer.parseInt(formCountTwoDays) >= 30 && Integer.parseInt(activationTwoDays) == 0) {
|
|
|
+ String[] split = tgaMap.get("表单提交--起量快").split(";");
|
|
|
+ int count = materialLabelMapper.getDataByCodeAndSignature(obj.getSignature(), split[0]);
|
|
|
+ //次素材没有打此标签
|
|
|
+ if (count == 0) {
|
|
|
+ materialLabelMapper.saveMaterialTag(obj.getSignature(), "表单提交--起量快", split[0], split[1], "1", date);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 表单提交-低-3s完播率
|
|
|
+ if (formCountThirtyDays != null && play3sRatio != null && Integer.parseInt(formCountThirtyDays) >= 20 && Double.parseDouble(play3sRatio) < 0.157) {
|
|
|
+ String[] split = tgaMap.get("表单提交-低-3s完播率").split(";");
|
|
|
+ int count = materialLabelMapper.getDataByCodeAndSignature(obj.getSignature(), split[0]);
|
|
|
+ //次素材没有打此标签
|
|
|
+ if (count == 0) {
|
|
|
+ materialLabelMapper.saveMaterialTag(obj.getSignature(), "表单提交-低-3s完播率", split[0], split[1], "1", date);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 表单提交-高-3s完播率
|
|
|
+ if (formCountThirtyDays != null && play3sRatio != null && Integer.parseInt(formCountThirtyDays) >= 20 && Double.parseDouble(play3sRatio) > 0.515) {
|
|
|
+ String[] split = tgaMap.get("表单提交-高-3s完播率").split(";");
|
|
|
+ int count = materialLabelMapper.getDataByCodeAndSignature(obj.getSignature(), split[0]);
|
|
|
+ //次素材没有打此标签
|
|
|
+ if (count == 0) {
|
|
|
+ materialLabelMapper.saveMaterialTag(obj.getSignature(), "表单提交-高-3s完播率", split[0], split[1], "1", date);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 表单提交-低-转化率
|
|
|
+ if (formCountThirtyDays != null && conversionRatio != null && Integer.parseInt(formCountThirtyDays) >= 20 && Double.parseDouble(conversionRatio) < 0.017) {
|
|
|
+ String[] split = tgaMap.get("表单提交-低-转化率").split(";");
|
|
|
+ int count = materialLabelMapper.getDataByCodeAndSignature(obj.getSignature(), split[0]);
|
|
|
+ //次素材没有打此标签
|
|
|
+ if (count == 0) {
|
|
|
+ materialLabelMapper.saveMaterialTag(obj.getSignature(), "表单提交-低-转化率", split[0], split[1], "1", date);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // 表单提交-高-转化率
|
|
|
+ if (formCountThirtyDays != null && conversionRatio != null && Integer.parseInt(formCountThirtyDays) >= 20 && Double.parseDouble(conversionRatio) > 0.159) {
|
|
|
+ String[] split = tgaMap.get("表单提交-高-转化率").split(";");
|
|
|
+ int count = materialLabelMapper.getDataByCodeAndSignature(obj.getSignature(), split[0]);
|
|
|
+ //次素材没有打此标签
|
|
|
+ if (count == 0) {
|
|
|
+ materialLabelMapper.saveMaterialTag(obj.getSignature(), "表单提交-高-转化率", split[0], split[1], "1", date);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 表单提交-低-行为率
|
|
|
+ if (formCountThirtyDays != null && behaviorRation != null && Integer.parseInt(formCountThirtyDays) >= 20 && Double.parseDouble(behaviorRation) < 0.004) {
|
|
|
+ String[] split = tgaMap.get("表单提交-低-行为率").split(";");
|
|
|
+ int count = materialLabelMapper.getDataByCodeAndSignature(obj.getSignature(), split[0]);
|
|
|
+ //次素材没有打此标签
|
|
|
+ if (count == 0) {
|
|
|
+ materialLabelMapper.saveMaterialTag(obj.getSignature(), "表单提交-低-行为率", split[0], split[1], "1", date);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 表单提交-高-行为率
|
|
|
+ if (formCountThirtyDays != null && behaviorRation != null && Integer.parseInt(formCountThirtyDays) >= 20 && Double.parseDouble(behaviorRation) > 0.015) {
|
|
|
+ String[] split = tgaMap.get("表单提交-高-行为率").split(";");
|
|
|
+ int count = materialLabelMapper.getDataByCodeAndSignature(obj.getSignature(), split[0]);
|
|
|
+ //次素材没有打此标签
|
|
|
+ if (count == 0) {
|
|
|
+ materialLabelMapper.saveMaterialTag(obj.getSignature(), "表单提交-高-行为率", split[0], split[1], "1", date);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ }
|
|
|
+ result.success("success");
|
|
|
+ } catch (Exception e) {
|
|
|
+ result.error500("error");
|
|
|
+ log.info("素材规定标签失败:{}", e.toString());
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 同步标签到ES
|
|
|
+ *
|
|
|
+ * @param
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Result SynchronousLabel() {
|
|
|
+ Result result = new Result();
|
|
|
+ try {
|
|
|
+ List<MaterialLabelInfo> materialLabelData = materialLabelMapper.getMaterialLabelData(null);
|
|
|
+ if(!materialLabelData.isEmpty()){
|
|
|
+
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ log.info("同步标签至ES失败:{}",e.toString());
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取指定日期number天之后之前的日期
|
|
|
+ *
|
|
|
+ * @param
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String getDateByNumber(String date, int number) {
|
|
|
+ Calendar calc = Calendar.getInstance();
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ String AfterDate = null;
|
|
|
+ try {
|
|
|
+ calc.setTime(sdf.parse(date));
|
|
|
+ calc.add(Calendar.DAY_OF_MONTH, number);
|
|
|
+ AfterDate = sdf.format(calc.getTime());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("获取日期失败:{}", e.toString());
|
|
|
+ }
|
|
|
+ return AfterDate;
|
|
|
+ }
|
|
|
+}
|