Ver Fonte

快手 查看缺失视频

yumeng há 5 anos atrás
pai
commit
60722634a5

+ 248 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/KuaiShouDefectMaterialController.java

@@ -0,0 +1,248 @@
+package org.jeecg.modules.ctop.controller;
+
+import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.api.vo.Result;
+import org.jeecg.common.aspect.annotation.AutoLog;
+import org.jeecg.common.system.query.QueryGenerator;
+import org.jeecg.common.util.oConvertUtils;
+import org.jeecg.modules.ctop.entity.KuaiShouDefectMaterial;
+import org.jeecg.modules.ctop.service.IKuaiShouDefectMaterialService;
+import org.jeecgframework.poi.excel.ExcelImportUtil;
+import org.jeecgframework.poi.excel.def.NormalExcelConstants;
+import org.jeecgframework.poi.excel.entity.ExportParams;
+import org.jeecgframework.poi.excel.entity.ImportParams;
+import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+import org.springframework.web.multipart.MultipartHttpServletRequest;
+import org.springframework.web.servlet.ModelAndView;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 快手缺失素材
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2020-04-15
+ */
+@Slf4j
+@Api(tags = "快手缺失素材")
+@RestController
+@RequestMapping("/ctop/kuaiShouDefectMaterial")
+public class KuaiShouDefectMaterialController {
+    @Autowired
+    private IKuaiShouDefectMaterialService kuaiShouDefectMaterialService;
+
+    /**
+     * 分页列表查询
+     *
+     * @param kuaiShouDefectMaterial
+     * @param pageNo
+     * @param pageSize
+     * @param req
+     * @return
+     */
+    @AutoLog(value = "快手缺失素材-分页列表查询")
+    @ApiOperation(value = "快手缺失素材-分页列表查询", notes = "快手缺失素材-分页列表查询")
+    @GetMapping(value = "/list")
+    public Result<IPage<KuaiShouDefectMaterial>> queryPageList(KuaiShouDefectMaterial kuaiShouDefectMaterial,
+                                                               @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
+                                                               @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
+                                                               HttpServletRequest req) {
+        Result<IPage<KuaiShouDefectMaterial>> result = new Result<IPage<KuaiShouDefectMaterial>>();
+        QueryWrapper<KuaiShouDefectMaterial> queryWrapper = QueryGenerator.initQueryWrapper(kuaiShouDefectMaterial, req.getParameterMap());
+        Page<KuaiShouDefectMaterial> page = new Page<KuaiShouDefectMaterial>(pageNo, pageSize);
+        IPage<KuaiShouDefectMaterial> pageList = kuaiShouDefectMaterialService.page(page, queryWrapper);
+        result.setSuccess(true);
+        result.setResult(pageList);
+        return result;
+    }
+
+    /**
+     * 添加
+     *
+     * @param kuaiShouDefectMaterial
+     * @return
+     */
+    @AutoLog(value = "快手缺失素材-添加")
+    @ApiOperation(value = "快手缺失素材-添加", notes = "快手缺失素材-添加")
+    @PostMapping(value = "/add")
+    public Result<KuaiShouDefectMaterial> add(@RequestBody KuaiShouDefectMaterial kuaiShouDefectMaterial) {
+        Result<KuaiShouDefectMaterial> result = new Result<KuaiShouDefectMaterial>();
+        try {
+            kuaiShouDefectMaterialService.save(kuaiShouDefectMaterial);
+            result.success("添加成功!");
+        } catch (Exception e) {
+            log.error(e.getMessage(), e);
+            result.error500("操作失败");
+        }
+        return result;
+    }
+
+    /**
+     * 编辑
+     *
+     * @param kuaiShouDefectMaterial
+     * @return
+     */
+    @AutoLog(value = "快手缺失素材-编辑")
+    @ApiOperation(value = "快手缺失素材-编辑", notes = "快手缺失素材-编辑")
+    @PutMapping(value = "/edit")
+    public Result<KuaiShouDefectMaterial> edit(@RequestBody KuaiShouDefectMaterial kuaiShouDefectMaterial) {
+        Result<KuaiShouDefectMaterial> result = new Result<KuaiShouDefectMaterial>();
+        KuaiShouDefectMaterial kuaiShouDefectMaterialEntity = kuaiShouDefectMaterialService.getById(kuaiShouDefectMaterial.getId());
+        if (kuaiShouDefectMaterialEntity == null) {
+            result.error500("未找到对应实体");
+        } else {
+            boolean ok = kuaiShouDefectMaterialService.updateById(kuaiShouDefectMaterial);
+            if (ok) {
+                result.success("修改成功!");
+            }
+        }
+
+        return result;
+    }
+
+    /**
+     * 通过id删除
+     *
+     * @param id
+     * @return
+     */
+    @AutoLog(value = "快手缺失素材-通过id删除")
+    @ApiOperation(value = "快手缺失素材-通过id删除", notes = "快手缺失素材-通过id删除")
+    @DeleteMapping(value = "/delete")
+    public Result<?> delete(@RequestParam(name = "id", required = true) String id) {
+        try {
+            kuaiShouDefectMaterialService.removeById(id);
+        } catch (Exception e) {
+            log.error("删除失败", e.getMessage());
+            return Result.error("删除失败!");
+        }
+        return Result.ok("删除成功!");
+    }
+
+    /**
+     * 批量删除
+     *
+     * @param ids
+     * @return
+     */
+    @AutoLog(value = "快手缺失素材-批量删除")
+    @ApiOperation(value = "快手缺失素材-批量删除", notes = "快手缺失素材-批量删除")
+    @DeleteMapping(value = "/deleteBatch")
+    public Result<KuaiShouDefectMaterial> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
+        Result<KuaiShouDefectMaterial> result = new Result<KuaiShouDefectMaterial>();
+        if (ids == null || "".equals(ids.trim())) {
+            result.error500("参数不识别!");
+        } else {
+            this.kuaiShouDefectMaterialService.removeByIds(Arrays.asList(ids.split(",")));
+            result.success("删除成功!");
+        }
+        return result;
+    }
+
+    /**
+     * 通过id查询
+     *
+     * @param id
+     * @return
+     */
+    @AutoLog(value = "快手缺失素材-通过id查询")
+    @ApiOperation(value = "快手缺失素材-通过id查询", notes = "快手缺失素材-通过id查询")
+    @GetMapping(value = "/queryById")
+    public Result<KuaiShouDefectMaterial> queryById(@RequestParam(name = "id", required = true) String id) {
+        Result<KuaiShouDefectMaterial> result = new Result<KuaiShouDefectMaterial>();
+        KuaiShouDefectMaterial kuaiShouDefectMaterial = kuaiShouDefectMaterialService.getById(id);
+        if (kuaiShouDefectMaterial == null) {
+            result.error500("未找到对应实体");
+        } else {
+            result.setResult(kuaiShouDefectMaterial);
+            result.setSuccess(true);
+        }
+        return result;
+    }
+
+    /**
+     * 导出excel
+     *
+     * @param request
+     * @param response
+     */
+    @RequestMapping(value = "/exportXls")
+    public ModelAndView exportXls(HttpServletRequest request, HttpServletResponse response) {
+        // Step.1 组装查询条件
+        QueryWrapper<KuaiShouDefectMaterial> queryWrapper = null;
+        try {
+            String paramsStr = request.getParameter("paramsStr");
+            if (oConvertUtils.isNotEmpty(paramsStr)) {
+                String deString = URLDecoder.decode(paramsStr, "UTF-8");
+                KuaiShouDefectMaterial kuaiShouDefectMaterial = JSON.parseObject(deString, KuaiShouDefectMaterial.class);
+                queryWrapper = QueryGenerator.initQueryWrapper(kuaiShouDefectMaterial, request.getParameterMap());
+            }
+        } catch (UnsupportedEncodingException e) {
+            e.printStackTrace();
+        }
+
+        //Step.2 AutoPoi 导出Excel
+        ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
+        List<KuaiShouDefectMaterial> pageList = kuaiShouDefectMaterialService.list(queryWrapper);
+        //导出文件名称
+        mv.addObject(NormalExcelConstants.FILE_NAME, "快手缺失素材列表");
+        mv.addObject(NormalExcelConstants.CLASS, KuaiShouDefectMaterial.class);
+        mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("快手缺失素材列表数据", "导出人:Jeecg", "导出信息"));
+        mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
+        return mv;
+    }
+
+    /**
+     * 通过excel导入数据
+     *
+     * @param request
+     * @param response
+     * @return
+     */
+    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
+    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
+        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
+        Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
+        for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
+            MultipartFile file = entity.getValue();
+            ImportParams params = new ImportParams();
+            params.setTitleRows(2);
+            params.setHeadRows(1);
+            params.setNeedSave(true);
+            try {
+                List<KuaiShouDefectMaterial> listKuaiShouDefectMaterials = ExcelImportUtil.importExcel(file.getInputStream(), KuaiShouDefectMaterial.class, params);
+                kuaiShouDefectMaterialService.saveBatch(listKuaiShouDefectMaterials);
+                return Result.ok("文件导入成功!数据行数:" + listKuaiShouDefectMaterials.size());
+            } catch (Exception e) {
+                log.error(e.getMessage(), e);
+                return Result.error("文件导入失败:" + e.getMessage());
+            } finally {
+                try {
+                    file.getInputStream().close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+        return Result.ok("文件导入失败!");
+    }
+
+}

+ 14 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/TestController.java

@@ -30,6 +30,7 @@ import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.util.DateUtils;
 import org.jeecg.modules.ctop.service.ICleanMaterialService;
 import org.jeecg.modules.ctop.service.ICreateInternalService;
+import org.jeecg.modules.ctop.service.IKuaiShouDefectMaterialService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
@@ -858,4 +859,17 @@ public class TestController {
             }
         });
     }
+
+
+    @Autowired
+    private IKuaiShouDefectMaterialService defectVideoService;
+
+    @GetMapping(value = "/getDefectVideo")
+    public void getDefectVideo(String startDate, String endDate) {
+        log.info("开始获取缺失视频数据");
+        defectVideoService.getDefectVideo(startDate, endDate);
+        log.info("获取缺失视频数据结束");
+    }
+
+
 }

+ 92 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/entity/KuaiShouDefectMaterial.java

@@ -0,0 +1,92 @@
+package org.jeecg.modules.ctop.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+import org.jeecgframework.poi.excel.annotation.Excel;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.util.Date;
+
+/**
+ * 快手缺失素材
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2020-04-15
+ */
+@Data
+@TableName("ctop_kuaishou_defect_material")
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@ApiModel(value = "ctop_kuaishou_defect_material对象", description = "快手缺失素材")
+public class KuaiShouDefectMaterial {
+
+    /**
+     * id
+     */
+    @TableId(type = IdType.AUTO)
+    @ApiModelProperty(value = "id")
+    private Integer id;
+    /**
+     * md5
+     */
+    @Excel(name = "md5", width = 15)
+    @ApiModelProperty(value = "md5")
+    private String signature;
+    /**
+     * 花费(元)
+     */
+    @Excel(name = "花费(元)", width = 15)
+    @ApiModelProperty(value = "花费(元)")
+    private java.math.BigDecimal charge;
+    /**
+     * url
+     */
+    @Excel(name = "url", width = 15)
+    @ApiModelProperty(value = "url")
+    private String url;
+    /**
+     * 项目
+     */
+    @Excel(name = "项目", width = 15)
+    @ApiModelProperty(value = "项目")
+    private Long projectId;
+    /**
+     * 开始时间
+     */
+    @Excel(name = "开始时间", width = 15)
+    @ApiModelProperty(value = "开始时间")
+    private String startDate;
+    /**
+     * 结束时间
+     */
+    @Excel(name = "结束时间", width = 15)
+    @ApiModelProperty(value = "结束时间")
+    private String endDate;
+
+    private String accountIds;
+
+    /**
+     * 创建时间
+     */
+    @Excel(name = "创建时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
+    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @ApiModelProperty(value = "创建时间")
+    private Date createTime;
+    /**
+     * 修改时间
+     */
+    @Excel(name = "修改时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
+    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @ApiModelProperty(value = "修改时间")
+    private Date updateTime;
+}

+ 15 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/mapper/KuaiShouDefectMaterialMapper.java

@@ -0,0 +1,15 @@
+package org.jeecg.modules.ctop.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.jeecg.modules.ctop.entity.KuaiShouDefectMaterial;
+
+/**
+ * 快手缺失素材
+ *
+ * @author: jeecg-boot
+ * @date: 2020-04-15
+ * @cersion: V1.0
+ */
+public interface KuaiShouDefectMaterialMapper extends BaseMapper<KuaiShouDefectMaterial> {
+
+}

+ 5 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/mapper/xml/KuaiShouDefectMaterialMapper.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="org.jeecg.modules.ctop.mapper.KuaiShouDefectMaterialMapper">
+
+</mapper>

+ 16 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/IKuaiShouDefectMaterialService.java

@@ -0,0 +1,16 @@
+package org.jeecg.modules.ctop.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import org.jeecg.modules.ctop.entity.KuaiShouDefectMaterial;
+
+/**
+ * 快手缺失素材
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2020-04-15
+ */
+public interface IKuaiShouDefectMaterialService extends IService<KuaiShouDefectMaterial> {
+    void getDefectVideo(String startDate, String endDate);
+
+}

+ 90 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/KuaiShouDefectMaterialServiceImpl.java

@@ -0,0 +1,90 @@
+package org.jeecg.modules.ctop.service.impl;
+
+import cn.com.ctop.common.module.entity.MaterialInfo;
+import cn.com.ctop.common.module.entity.UserAllocation;
+import cn.com.ctop.common.module.service.IMaterialInfoService;
+import cn.com.ctop.common.module.service.IUserAllocationService;
+import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouVideoGet;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouVideoGetService;
+import cn.com.ctop.kuaishou.modules.report.mapper.KuaishouReportDailyCreativeMapper;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import lombok.extern.slf4j.Slf4j;
+import org.jeecg.modules.ctop.entity.KuaiShouDefectMaterial;
+import org.jeecg.modules.ctop.mapper.KuaiShouDefectMaterialMapper;
+import org.jeecg.modules.ctop.service.IKuaiShouDefectMaterialService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+/**
+ * 快手缺失素材
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2020-04-15
+ */
+@Slf4j
+@Service
+public class KuaiShouDefectMaterialServiceImpl extends ServiceImpl<KuaiShouDefectMaterialMapper, KuaiShouDefectMaterial> implements IKuaiShouDefectMaterialService {
+    @Autowired
+    private KuaishouReportDailyCreativeMapper creativeMapper;
+    @Autowired
+    private IMaterialInfoService materialInfoService;
+    @Autowired
+    private IKuaiShouVideoGetService videoGetService;
+    @Autowired
+    private IUserAllocationService userAllocationService;
+
+
+    @Override
+    public void getDefectVideo(String startDate, String endDate) {
+
+        List<JSONObject> list = creativeMapper.selectCodeByDate(startDate, endDate);
+        if (!Check.isNull(list)) {
+            for (int i = 0; i < list.size(); i++) {
+
+                JSONObject codeJson = list.get(i);
+                // charge signature
+                String signature = codeJson.getString("signature");
+                if (!Check.isNull(signature)) {
+                    QueryWrapper<MaterialInfo> materialInfoQueryWrapper = new QueryWrapper<>();
+                    materialInfoQueryWrapper.eq("code", signature);
+                    materialInfoQueryWrapper.last("limit 1");
+                    MaterialInfo materialInfo = materialInfoService.getOne(materialInfoQueryWrapper);
+                    if (!Check.isNull(materialInfo)) {
+                        continue;
+                    }
+                    KuaiShouDefectMaterial defectMaterial = new KuaiShouDefectMaterial();
+                    defectMaterial.setCharge(codeJson.getBigDecimal("charge"));
+                    defectMaterial.setAccountIds(codeJson.getString("accountId"));
+                    defectMaterial.setSignature(signature);
+                    defectMaterial.setStartDate(startDate);
+                    defectMaterial.setEndDate(endDate);
+                    QueryWrapper<KuaiShouVideoGet> videoGetQueryWrapper = new QueryWrapper<>();
+                    videoGetQueryWrapper.eq("signature", signature);
+                    videoGetQueryWrapper.last("limit 1");
+                    KuaiShouVideoGet videoGet = videoGetService.getOne(videoGetQueryWrapper);
+                    if (!Check.isNull(videoGet)) {
+                        continue;
+                    }
+                    defectMaterial.setUrl(videoGet.getUrl());
+                    QueryWrapper<UserAllocation> userAllocationQueryWrapper = new QueryWrapper<>();
+                    userAllocationQueryWrapper.eq("account_id", videoGet.getAccountId());
+                    userAllocationQueryWrapper.last("limit 1");
+                    UserAllocation userAllocation = userAllocationService.getOne(userAllocationQueryWrapper);
+                    if (!Check.isNull(userAllocation)) {
+                        defectMaterial.setProjectId(userAllocation.getProjectId());
+                    }
+                    this.save(defectMaterial);
+
+                }
+            }
+
+        }
+
+    }
+}

+ 5 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/KuaishouReportDailyCreativeMapper.java

@@ -1,11 +1,16 @@
 package cn.com.ctop.kuaishou.modules.report.mapper;
 
 import cn.com.ctop.kuaishou.modules.report.entity.KuaishouReportDailyCreative;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import org.apache.ibatis.annotations.Param;
 
+import java.util.List;
+
 public interface KuaishouReportDailyCreativeMapper extends BaseMapper<KuaishouReportDailyCreative> {
     void loadCreativeDailyReport(@Param("accountId") Long accountId, @Param("localPath") String localPath);
 
     void formatCreativeDailyReportData(@Param("accountId") Long accountId, @Param("statDate") String statDate);
+
+    List<JSONObject> selectCodeByDate(@Param("startDate") String startDate, @Param("endDate") String endDate);
 }

+ 15 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/mapper/xml/KuaishouReportDailyCreativeMapper.xml

@@ -97,4 +97,19 @@
         </if>
     </update>
 
+    <select id="selectCodeByDate" resultType="com.alibaba.fastjson.JSONObject">
+   select
+   GROUP_CONCAT(DISTINCT(account_id)) accountId,
+   sum(charge) charge,
+   signature signature
+   from
+   ctop_kuaishou_report_daily_creative
+   where stat_date &gt;= #{startDate}
+   and stat_date &lt;= #{endDate}
+   and signature is not null
+   group by signature
+
+
+    </select>
+
 </mapper>