Parcourir la source

文案库提交

zhouzeyu@c-top.com.cn il y a 4 ans
Parent
commit
8855dbb24f

+ 87 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/document/controller/DocumentLibraryController.java

@@ -0,0 +1,87 @@
+package cn.com.ctop.kuaishou.modules.document.controller;
+
+import cn.com.ctop.kuaishou.modules.document.service.DocumentLibraryService;
+import org.jeecg.common.api.vo.Result;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.annotation.Resource;
+import java.util.List;
+
+/**
+ * @Description: 文档库管理
+ * @Author: zzy
+ * @Date: 2021-09-06
+ * @Version: V1.0
+ */
+@RestController
+@RequestMapping("/document/library")
+public class DocumentLibraryController {
+
+    @Resource
+    DocumentLibraryService documentLibraryService;
+
+    /**
+     * 创建文案
+     *
+     * @param
+     * @return
+     */
+    @PostMapping("createdocument")
+    public Result createdocument(MultipartFile file, @RequestParam("accountIds") List<String> accountIds) {
+        return documentLibraryService.createdocument(file, accountIds);
+
+    }
+    /**
+     * 获取文案库列表
+     *
+     * @param
+     * @return
+     */
+    @GetMapping("getDocumentList")
+    public Result getDocumentList(@RequestParam("accountIds") List<String> accountIds,@RequestParam("keywords") String keywords,
+                                  @RequestParam("startDate") String startDate,@RequestParam("endDate") String endDate,
+                                  @RequestParam("status") String status,@RequestParam("pageNumber") int pageNumber,@RequestParam("pageSize") int pageSize) {
+        return documentLibraryService.getDocumentList(accountIds, keywords,startDate,endDate,status,pageNumber,pageSize);
+
+    }
+
+    /**
+     * 编辑文案
+     *
+     * @param
+     * @return
+     */
+    @GetMapping("updateDocument")
+    public Result updateDocument(@RequestParam("accountIds") List<String> accountIds,@RequestParam("copyWriterId") String copyWriterId,@RequestParam("copyWriter") String copyWriter) {
+        return documentLibraryService.updateDocument(accountIds, copyWriterId,copyWriter);
+
+    }
+
+
+    /**
+     * 文案下架
+     *
+     * @param
+     * @return
+     */
+    @GetMapping("updateStatus")
+    public Result updateStatus(@RequestParam("copyWriterId") String copyWriterId,@RequestParam("status") String status) {
+        return documentLibraryService.updateStatus( copyWriterId,status);
+
+    }
+
+
+    /**
+     * 获取被拒创意
+     *
+     * @param
+     * @return
+     */
+    @GetMapping("getRefusedList")
+    public Result getRefusedList(@RequestParam("copyWriterId") String copyWriterId,@RequestParam("pageNumber") int pageNumber,@RequestParam("pageSize") int pageSize) {
+        return documentLibraryService.getRefusedList(copyWriterId,pageNumber,pageSize);
+
+    }
+
+}

+ 18 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/document/entity/DocumentLibraryInfo.java

@@ -0,0 +1,18 @@
+package cn.com.ctop.kuaishou.modules.document.entity;
+
+import lombok.Data;
+
+@Data
+public class DocumentLibraryInfo {
+    private  String id;
+    /*文档id*/
+    private  String copyWriterId;
+    /*文案内容*/
+    private  String copyWriter;
+    /*账户id*/
+    private  String accountId;
+    /*0可投放、1已下架*/
+    private  Integer status;
+    /*文案创建时间*/
+    private  String createTime;
+}

+ 20 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/document/mapper/DocumentLibraryMapper.java

@@ -0,0 +1,20 @@
+package cn.com.ctop.kuaishou.modules.document.mapper;
+
+import cn.com.ctop.kuaishou.modules.document.entity.DocumentLibraryInfo;
+import com.alibaba.fastjson.JSONObject;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+@Mapper
+public interface DocumentLibraryMapper {
+
+    void saveDocumentLibrary(DocumentLibraryInfo documentLibraryInfo);
+
+    List<JSONObject> getDocumentLibraryList(@Param("list") List<String> list, @Param("keywords") String keywords, @Param("startDate") String startDate, @Param("endDate") String endDate, @Param("status") String status);
+
+    void updateStatus(@Param("copyWriterId")String copyWriterId, @Param("status")String status);
+
+    List<JSONObject> getRefusedList(@Param("copyWriterId")String copyWriterId);
+}

+ 51 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/document/mapper/xml/DocumentLibraryMapper.xml

@@ -0,0 +1,51 @@
+<?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="cn.com.ctop.kuaishou.modules.document.mapper.DocumentLibraryMapper">
+
+
+    <insert id="saveDocumentLibrary" parameterType="cn.com.ctop.kuaishou.modules.document.entity.DocumentLibraryInfo">
+        insert into ctop_document_library (copy_writer_id,copy_writer,account_id,status,create_time) values
+        (#{copyWriterId},#{copyWriter},#{accountId},#{status},#{createTime})
+    </insert>
+
+
+    <select id="getDocumentLibraryList" resultType="com.alibaba.fastjson.JSONObject">
+        SELECT t.copy_writer_id as 'copyWriterId',t.copy_writer,t.status,COUNT(t1.id) as 'relatedSize',COUNT(if(t2.status= 42 ,TRUE,NULL)) as 'refusedSize'  from
+        (SELECT DISTINCT copy_writer_id,copy_writer,status,create_time from ctop_document_library
+        <where>
+            <if test="keywords !=null and keywords !=''">
+                and copy_writer like CONCAT('%',CONCAT(#{keywords},'%'))
+            </if>
+            <if test="startDate !=null and startDate !='' and endDate !=null and endDate !=''">
+                and create_time BETWEEN  #{startDate} and #{endDate}
+            </if>
+            <if test='status !=null and status !="" and status !=3'>
+                and status =#{status}
+            </if>
+            <if test="list!=null and list.size() > 0">
+                and account_id in
+                <foreach item="item" collection="list" separator="," open="(" close=")" index="">
+                    #{item}
+                </foreach>
+            </if>
+        </where>
+        ) t
+        LEFT JOIN ctop_document_library_center t1 on t.copy_writer_id=t1.copy_writer_id
+        LEFT JOIN ctop_kuaishou_creative t2 on t1.creative_id=t2.creative_id
+        GROUP BY t.copy_writer_id
+        order by t.create_time desc
+    </select>
+
+
+    <update id="updateStatus" >
+        update  ctop_document_library set status=#{status} where copy_writer_id=#{copyWriterId}
+    </update>
+
+    <select id="getRefusedList" resultType="com.alibaba.fastjson.JSONObject" parameterType="String">
+        SELECT t2.auth_name as 'accountName',t1.unit_id as 'unitId',t1.creative_name as 'creativeName',t1.review_detail as 'reviewDetail' FROM ctop_document_library_center t
+        LEFT JOIN ctop_kuaishou_creative t1 on t.creative_id = t1.creative_id
+        LEFT JOIN ctop_user_allocation t2 on t1.account_id = t2.account_id
+        where t.copy_writer_id =#{copyWriterId} and t1.status=42
+    </select>
+
+</mapper>

+ 26 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/document/service/DocumentLibraryService.java

@@ -0,0 +1,26 @@
+package cn.com.ctop.kuaishou.modules.document.service;
+
+import org.apache.ibatis.annotations.Param;
+import org.jeecg.common.api.vo.Result;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.util.List;
+
+/**
+ * @Description: 文档库管理
+ * @Author: zzy
+ * @Date: 2021-09-06
+ * @Version: V1.0
+ */
+public interface DocumentLibraryService {
+
+    Result createdocument(MultipartFile file, @Param("accountIds") List<String> accountIds);
+
+    Result getDocumentList(List<String> accountIds, String keywords, String startDate, String endDate, String status,int pageNumber,int pageSize);
+
+    Result updateDocument(List<String> accountIds, String copyWriterId,String copyWriter);
+
+    Result updateStatus(String copyWriterId, String status);
+
+    Result getRefusedList(String copyWriterId, int pageNumber, int pageSize);
+}

+ 180 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/document/service/impl/DocumentLibraryServiceImpl.java

@@ -0,0 +1,180 @@
+package cn.com.ctop.kuaishou.modules.document.service.impl;
+
+import cn.com.ctop.kuaishou.modules.document.entity.DocumentLibraryInfo;
+import cn.com.ctop.kuaishou.modules.document.mapper.DocumentLibraryMapper;
+import cn.com.ctop.kuaishou.modules.document.service.DocumentLibraryService;
+import cn.com.ctop.kuaishou.modules.utils.ExcelUtil;
+import com.alibaba.fastjson.JSONObject;
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
+import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.api.vo.Result;
+import org.springframework.stereotype.Service;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.annotation.Resource;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.UUID;
+
+/**
+ * @Description: 文档库管理
+ * @Author: zzy
+ * @Date: 2021-09-06
+ * @Version: V1.0
+ */
+@Service
+@Slf4j
+public class DocumentLibraryServiceImpl implements DocumentLibraryService {
+
+    @Resource
+    DocumentLibraryMapper documentLibraryMapper;
+
+    /**
+     * 创建文案
+     *
+     * @param
+     * @return
+     */
+    @Override
+    public Result createdocument(MultipartFile file, List<String> accountIds) {
+        Result result = new Result();
+        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        List<String> documentList = new ArrayList<>();
+        try {
+            documentList = ExcelUtil.readExcel(file);
+        } catch (Exception e) {
+            log.info("读取excel错误:{}", e.toString());
+        }
+
+        try {
+            if (accountIds != null && !documentList.isEmpty() && !accountIds.isEmpty()) {
+
+                for (String docu : documentList) {
+                    DocumentLibraryInfo documentLibraryInfo = new DocumentLibraryInfo();
+                    documentLibraryInfo.setCopyWriter(docu);
+                    documentLibraryInfo.setCopyWriterId(UUID.randomUUID().toString());
+                    documentLibraryInfo.setCreateTime(formatter.format(new Date()));
+                    documentLibraryInfo.setStatus(0);
+                    for (String accountId : accountIds) {
+                        documentLibraryInfo.setAccountId(accountId);
+                        documentLibraryMapper.saveDocumentLibrary(documentLibraryInfo);
+                    }
+
+                }
+            }
+            result.success("添加成功");
+            return result;
+        } catch (Exception e) {
+            log.info("添加文案失败:{}", e.toString());
+            result.error500("添加失败");
+            return result;
+        }
+
+
+    }
+
+    /**
+     * 获取文案库列表
+     *
+     * @param
+     * @return
+     */
+    @Override
+    public Result getDocumentList(List<String> accountIds, String keywords, String startDate, String endDate, String status, int pageNumber, int pageSize) {
+        Result result = new Result();
+        List<JSONObject> documentLibraryList = new ArrayList<>();
+        try {
+            if (startDate != null && endDate != null) {
+                startDate = startDate + " 00:00:00";
+                endDate = endDate + " 23:59:59";
+            }
+            PageHelper.startPage(pageNumber, pageSize);
+            documentLibraryList = documentLibraryMapper.getDocumentLibraryList(accountIds, keywords, startDate, endDate, status);
+            PageInfo pageInfo = new PageInfo(documentLibraryList);
+            result.setSuccess(true);
+            result.setResult(pageInfo);
+        } catch (Exception e) {
+            result.error500("查询数据错误");
+            log.info("查询数据错误:{}", e.toString());
+        }
+
+        return result;
+    }
+
+    /**
+     * 编辑文案
+     *
+     * @param
+     * @return
+     */
+    @Override
+    public Result updateDocument(List<String> accountIds, String copyWriterId, String copyWriter) {
+        Result result = new Result();
+        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        try {
+            if (accountIds != null && !accountIds.isEmpty()) {
+                DocumentLibraryInfo documentLibraryInfo = new DocumentLibraryInfo();
+                documentLibraryInfo.setCopyWriter(copyWriter);
+                documentLibraryInfo.setCopyWriterId(copyWriterId);
+                documentLibraryInfo.setCreateTime(formatter.format(new Date()));
+                documentLibraryInfo.setStatus(0);
+                for (String accountId : accountIds) {
+                    documentLibraryInfo.setAccountId(accountId);
+                    documentLibraryMapper.saveDocumentLibrary(documentLibraryInfo);
+                }
+            }
+            result.success("添加成功");
+        } catch (Exception e) {
+            log.info("添加文案失败:{}", e.toString());
+            result.error500("添加失败");
+            return result;
+        }
+
+        return result;
+    }
+
+    /**
+     * 文案下架
+     *
+     * @param
+     * @return
+     */
+    @Override
+    public Result updateStatus(String copyWriterId, String status) {
+        Result result = new Result();
+        try {
+            documentLibraryMapper.updateStatus(copyWriterId, status);
+            result.success("下架成功");
+        } catch (Exception e) {
+            log.info("下架失败:{}", e.toString());
+            result.error500("下架失败");
+        }
+        return result;
+    }
+
+    /**
+     * 获取被拒创意
+     *
+     * @param
+     * @return
+     */
+    @Override
+    public Result getRefusedList(String copyWriterId, int pageNumber, int pageSize) {
+        Result result = new Result();
+        List<JSONObject> documentLibraryList = new ArrayList<>();
+        try {
+            PageHelper.startPage(pageNumber, pageSize);
+            documentLibraryList = documentLibraryMapper.getRefusedList(copyWriterId);
+            PageInfo pageInfo = new PageInfo(documentLibraryList);
+            result.setSuccess(true);
+            result.setResult(pageInfo);
+        } catch (Exception e) {
+            result.error500("查询数据错误");
+            log.info("查询数据错误:{}", e.toString());
+        }
+        return result;
+    }
+}

+ 170 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/kuaishou/modules/utils/ExcelUtil.java

@@ -0,0 +1,170 @@
+package cn.com.ctop.kuaishou.modules.utils;
+
+import cn.com.ctop.common.module.utils.Check;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.List;
+
+public class ExcelUtil {
+
+    private final static String xls = "xls";
+    private final static String xlsx = "xlsx";
+    private final static String DATE_FORMAT = "yyyy/MM/dd";
+
+    /**
+     * 读入excel文件,解析后返回
+     *
+     * @param file
+     * @throws IOException
+     */
+    public static List<String> readExcel(MultipartFile file) throws IOException {
+        //检查文件
+        checkFile(file);
+        //获得Workbook工作薄对象
+        Workbook workbook = getWorkBook(file);
+        //创建返回对象,把每行中的值作为一个数组,所有行作为一个集合返回
+//    List<String[]> list = new ArrayList<String[]>();
+        List<String> list = new ArrayList<>();
+        if (workbook != null) {
+            for (int sheetNum = 0; sheetNum < workbook.getNumberOfSheets(); sheetNum++) {
+                //获得当前sheet工作表
+                Sheet sheet = workbook.getSheetAt(sheetNum);
+                if (sheet == null) {
+                    continue;
+                }
+                //获得当前sheet的开始行
+                int firstRowNum = sheet.getFirstRowNum();
+                //获得当前sheet的结束行
+                int lastRowNum = sheet.getLastRowNum();
+                //循环所有行
+                for (int rowNum = firstRowNum; rowNum <= lastRowNum; rowNum++) {
+                    //获得当前行
+                    Row row = sheet.getRow(rowNum);
+                    if (row == null) {
+                        continue;
+                    }
+                    //获得当前行的开始列
+                    int firstCellNum = row.getFirstCellNum();
+                    //获得当前行的列数
+                    int lastCellNum = row.getPhysicalNumberOfCells();
+//          String[] cells = new String[row.getPhysicalNumberOfCells()];
+                    //循环当前行
+                    String cellValue = getCellValue(row.getCell(firstCellNum));
+//                        String cellValue = getCellValue(cell);
+                    if (!Check.isNull(cellValue)) { //只要当前行的第一列
+                        list.add(cellValue);
+                    }
+//                    for(int cellNum = firstCellNum; cellNum <= lastCellNum;cellNum++){
+//                        Cell cell = row.getCell(cellNum);
+////            cells[cellNum] = getCellValue(cell);
+//                        String cellValue = getCellValue(row.getCell(firstCellNum));
+////                        String cellValue = getCellValue(cell);
+//                        if(!Check.isNull(cellValue)){
+//                            list.add(cellValue);
+//                        }
+//                    }
+
+                }
+            }
+            workbook.close();
+        }
+        return list;
+    }
+
+    //校验文件是否合法
+    public static void checkFile(MultipartFile file) throws IOException {
+        //判断文件是否存在
+        if (null == file) {
+            throw new FileNotFoundException("文件不存在!");
+        }
+        //获得文件名
+        String fileName = file.getOriginalFilename();
+        //判断文件是否是excel文件
+        if (!fileName.endsWith(xls) && !fileName.endsWith(xlsx)) {
+            throw new IOException(fileName + "不是excel文件");
+        }
+    }
+
+    public static Workbook getWorkBook(MultipartFile file) {
+        //获得文件名
+        String fileName = file.getOriginalFilename();
+        //创建Workbook工作薄对象,表示整个excel
+        Workbook workbook = null;
+        try {
+            //获取excel文件的io流
+            InputStream is = file.getInputStream();
+            //根据文件后缀名不同(xls和xlsx)获得不同的Workbook实现类对象
+            if (fileName.endsWith(xls)) {
+                //2003
+                workbook = new HSSFWorkbook(is);
+            } else if (fileName.endsWith(xlsx)) {
+                //2007
+                workbook = new XSSFWorkbook(is);
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return workbook;
+    }
+
+    public static String getCellValue(Cell cell) {
+        String cellValue = "";
+        if (cell == null) {
+            return cellValue;
+        }
+        //如果当前单元格内容为日期类型,需要特殊处理
+        String dataFormatString = cell.getCellStyle().getDataFormatString();
+        if ("m/d/yy".equals(dataFormatString)) {
+            cellValue = new SimpleDateFormat(DATE_FORMAT).format(cell.getDateCellValue());
+            return cellValue;
+        }
+        /**
+         *     _NONE(-1),
+         *     NUMERIC(0),
+         *     STRING(1),
+         *     FORMULA(2),
+         *     BLANK(3),
+         *     BOOLEAN(4),
+         *     ERROR(5);
+         */
+
+        CellType cellType = cell.getCellTypeEnum();
+        //把数字当成String来读,避免出现1读成1.0的情况
+        if (cellType == CellType.NUMERIC) {
+            cell.setCellType(CellType.STRING);
+        }
+        //判断数据的类型
+        switch (cell.getCellTypeEnum()) {
+            case NUMERIC: //数字
+                cellValue = String.valueOf(cell.getNumericCellValue());
+                break;
+            case STRING: //字符串
+                cellValue = String.valueOf(cell.getStringCellValue());
+                break;
+            case BOOLEAN: //Boolean
+                cellValue = String.valueOf(cell.getBooleanCellValue());
+                break;
+            case FORMULA: //公式
+                cellValue = String.valueOf(cell.getCellFormula());
+                break;
+            case _NONE: //空值
+                cellValue = "";
+                break;
+            case ERROR: //故障
+                cellValue = "非法字符";
+                break;
+            default:
+                cellValue = "未知类型";
+                break;
+        }
+        return cellValue;
+    }
+}