Просмотр исходного кода

fix(字段大小写映射)
feat(客户联系下载到阿里云)
feat(下载记录列表)

gengyang 5 лет назад
Родитель
Сommit
f62f49f02e

+ 7 - 0
pom.xml

@@ -105,6 +105,13 @@
       <artifactId>mybatis-ehcache</artifactId>
       <artifactId>mybatis-ehcache</artifactId>
       <version>1.1.0</version>
       <version>1.1.0</version>
     </dependency>
     </dependency>
+
+    <dependency>
+      <groupId>com.aliyun.oss</groupId>
+      <artifactId>aliyun-sdk-oss</artifactId>
+      <version>3.8.0</version>
+    </dependency>
+
   </dependencies>
   </dependencies>
   <build>
   <build>
     <resources>
     <resources>

+ 83 - 0
src/main/java/com/mokamrp/privates/config/OSSConfiguration.java

@@ -0,0 +1,83 @@
+package com.mokamrp.privates.config;
+
+import com.aliyun.oss.OSS;
+import com.aliyun.oss.OSSClientBuilder;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Component;
+
+@Configuration
+@Component
+public class OSSConfiguration {
+
+    public static final String DOWN_DIR = "mochat/down/";
+
+    private volatile static OSS ossClient;
+
+    private volatile static OSSClientBuilder ossClientBuilder;
+
+    private static String endpoint;
+
+    private static String accessKeyId;
+
+    private static String accessKeySecret;
+
+    @Value("${aliyun.bucketName}")
+    private String bucketName;
+
+    public String getHost() {
+        return host;
+    }
+
+    public void setHost(String host) {
+        this.host = host;
+    }
+
+    @Value("${aliyun.host}")
+    private String host;
+
+    @Value("${aliyun.endpoint}")
+    public void setEndpoint(String endpoint) {
+        OSSConfiguration.endpoint = endpoint;
+    }
+
+    @Value("${aliyun.accessKeyId}")
+    public void setAccessKeyId(String accessKeyId) {
+        OSSConfiguration.accessKeyId = accessKeyId;
+    }
+
+    @Value("${aliyun.accessKeySecret}")
+    public void setAccessKeySecret(String accessKeySecret) {
+        OSSConfiguration.accessKeySecret = accessKeySecret;
+    }
+
+    public String getBucketName() {
+        return bucketName;
+    }
+
+    @Bean
+    @Scope("prototype")
+    public static OSS initOSSClient() {
+        if (ossClient == null) {
+            synchronized (OSSConfiguration.class) {
+                if (ossClient == null) {
+                    ossClient = initOSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
+                }
+            }
+        }
+        return ossClient;
+    }
+
+    public static OSSClientBuilder initOSSClientBuilder() {
+        if (ossClientBuilder == null) {
+            synchronized (OSSConfiguration.class) {
+                if (ossClientBuilder == null) {
+                    ossClientBuilder = new OSSClientBuilder();
+                }
+            }
+        }
+        return ossClientBuilder;
+    }
+}

+ 20 - 0
src/main/java/com/mokamrp/privates/controller/DownfileController.java

@@ -0,0 +1,20 @@
+package com.mokamrp.privates.controller;
+
+import com.mokamrp.privates.mapper.pojo.Downfile;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * <p>
+ *  前端控制器
+ * </p>
+ *
+ * @author gy
+ * @since 2021-04-22
+ */
+@RestController
+@RequestMapping("/downfile")
+public class DownfileController extends BaseController<Downfile> {
+
+}
+

+ 38 - 1
src/main/java/com/mokamrp/privates/controller/WorkContactEmployeeController.java

@@ -4,22 +4,31 @@ package com.mokamrp.privates.controller;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.JSONObject;
+import com.aliyun.oss.OSS;
+import com.aliyun.oss.model.PutObjectRequest;
 import com.baomidou.mybatisplus.mapper.EntityWrapper;
 import com.baomidou.mybatisplus.mapper.EntityWrapper;
 import com.baomidou.mybatisplus.plugins.Page;
 import com.baomidou.mybatisplus.plugins.Page;
+import com.mokamrp.privates.config.OSSConfiguration;
 import com.mokamrp.privates.help.AjaxResult;
 import com.mokamrp.privates.help.AjaxResult;
 import com.mokamrp.privates.mapper.pojo.WorkContactEmployee;
 import com.mokamrp.privates.mapper.pojo.WorkContactEmployee;
 import com.mokamrp.privates.mapper.vo.WorkContactEmployeeVo;
 import com.mokamrp.privates.mapper.vo.WorkContactEmployeeVo;
 import com.mokamrp.privates.service.WorkContactEmployeeService;
 import com.mokamrp.privates.service.WorkContactEmployeeService;
+import com.mokamrp.privates.utils.OssFile;
 import io.netty.handler.codec.json.JsonObjectDecoder;
 import io.netty.handler.codec.json.JsonObjectDecoder;
+import lombok.extern.flogger.Flogger;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Param;
+import org.apache.xerces.xs.datatypes.ObjectList;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.EnableAsync;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.stereotype.Controller;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.ResponseBody;
 import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.RestController;
 
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletRequest;
 import javax.validation.constraints.Max;
 import javax.validation.constraints.Max;
+import java.io.ByteArrayInputStream;
 import java.util.*;
 import java.util.*;
 
 
 
 
@@ -31,13 +40,20 @@ import java.util.*;
  * @author gengyang
  * @author gengyang
  * @since 2021-04-17
  * @since 2021-04-17
  */
  */
-@Controller
+@RestController
 @RequestMapping("/workContactEmployee")
 @RequestMapping("/workContactEmployee")
+@EnableAsync
 public class WorkContactEmployeeController {
 public class WorkContactEmployeeController {
 
 
     @Autowired
     @Autowired
     private WorkContactEmployeeService WorkContactEmployeeService;
     private WorkContactEmployeeService WorkContactEmployeeService;
 
 
+    @Autowired
+    private OSS ossClient;
+
+    @Autowired
+    private OSSConfiguration ossConfiguration;
+
     @RequestMapping("/index")
     @RequestMapping("/index")
     @ResponseBody
     @ResponseBody
     public Object getList(
     public Object getList(
@@ -58,4 +74,25 @@ public class WorkContactEmployeeController {
 
 
     }
     }
 
 
+    @RequestMapping("/export")
+    @ResponseBody
+    public Object export(
+            Integer gender, Integer status,String name,
+            Integer start_deleted_at, Integer end_deleted_at,
+            Integer start_created_at, Integer end_created_at,
+            Integer group_id, Integer corp_id,@RequestParam List employee_id, @RequestParam List tag_id , Integer channel_code_id
+    ){
+
+        System.out.println("============>"+Thread.currentThread().getName());
+
+        WorkContactEmployeeService.export(gender, status,name,
+                start_deleted_at, end_deleted_at,
+                start_created_at, end_created_at,
+                group_id, corp_id, employee_id, tag_id, channel_code_id);//所有
+
+        return AjaxResult.success("正在异步生成请稍后");
+
+    }
+
+
 }
 }

+ 8 - 4
src/main/java/com/mokamrp/privates/controller/WorkContactRoomController.java

@@ -1,16 +1,20 @@
 package com.mokamrp.privates.controller;
 package com.mokamrp.privates.controller;
 
 
+import com.alibaba.fastjson.JSONObject;
+import com.mokamrp.privates.constant.HttpStatus;
+import com.mokamrp.privates.entity.AddHandle;
 import com.mokamrp.privates.entity.IndexHandle;
 import com.mokamrp.privates.entity.IndexHandle;
+import com.mokamrp.privates.entity.WorkRoomBandTagHandle;
 import com.mokamrp.privates.help.AjaxResult;
 import com.mokamrp.privates.help.AjaxResult;
 import com.mokamrp.privates.mapper.pojo.WorkContactRoom;
 import com.mokamrp.privates.mapper.pojo.WorkContactRoom;
 import com.mokamrp.privates.service.WorkContactRoomService;
 import com.mokamrp.privates.service.WorkContactRoomService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.BindingResult;
 import org.springframework.validation.BindingResult;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
+
 import javax.validation.Valid;
 import javax.validation.Valid;
+import java.lang.reflect.Array;
+import java.util.Arrays;
 import java.util.Map;
 import java.util.Map;
 
 
 /**
 /**

+ 16 - 0
src/main/java/com/mokamrp/privates/mapper/DownfileMapper.java

@@ -0,0 +1,16 @@
+package com.mokamrp.privates.mapper;
+
+import com.mokamrp.privates.mapper.pojo.Downfile;
+import com.baomidou.mybatisplus.mapper.BaseMapper;
+
+/**
+ * <p>
+ *  Mapper 接口
+ * </p>
+ *
+ * @author gy
+ * @since 2021-04-22
+ */
+public interface DownfileMapper extends BaseMapper<Downfile> {
+
+}

+ 25 - 0
src/main/java/com/mokamrp/privates/mapper/DownfileMapper.xml

@@ -0,0 +1,25 @@
+<?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="com.mokamrp.privates.mapper.DownfileMapper">
+
+    <!-- 开启二级缓存 -->
+    <cache type="org.mybatis.caches.ehcache.LoggingEhcache"/>
+
+    <!-- 通用查询映射结果 -->
+    <resultMap id="BaseResultMap" type="com.mokamrp.privates.mapper.pojo.Downfile">
+        <id column="id" property="id" />
+        <result column="title" property="title" />
+        <result column="auth_name" property="authName" />
+        <result column="createtime" property="createtime" />
+        <result column="down_url" property="downUrl" />
+        <result column="msg" property="msg" />
+        <result column="filter_json" property="filterJson" />
+        <result column="status" property="status" />
+    </resultMap>
+
+    <!-- 通用查询结果列 -->
+    <sql id="Base_Column_List">
+        id, title, auth_name, createtime, down_url, msg, filter_json, status
+    </sql>
+
+</mapper>

+ 2 - 0
src/main/java/com/mokamrp/privates/mapper/WorkContactEmployeeMapper.java

@@ -20,5 +20,7 @@ import java.util.List;
  */
  */
 public interface WorkContactEmployeeMapper extends BaseMapper<WorkContactEmployee> {
 public interface WorkContactEmployeeMapper extends BaseMapper<WorkContactEmployee> {
     List<WorkContactEmployeeVo> getVoList(Page<WorkContactEmployeeVo> page, @Param("ew") EntityWrapper<WorkContactEmployee> queryWrapper);
     List<WorkContactEmployeeVo> getVoList(Page<WorkContactEmployeeVo> page, @Param("ew") EntityWrapper<WorkContactEmployee> queryWrapper);
+    List<WorkContactEmployeeVo> getAllVoList(@Param("ew") EntityWrapper<WorkContactEmployee> queryWrapper);
+
     Integer getVoListTotal(@Param("ew") EntityWrapper<WorkContactEmployee> queryWrapper);
     Integer getVoListTotal(@Param("ew") EntityWrapper<WorkContactEmployee> queryWrapper);
 }
 }

+ 26 - 1
src/main/java/com/mokamrp/privates/mapper/WorkContactEmployeeMapper.xml

@@ -37,7 +37,32 @@
             c.gender AS client_gender ,
             c.gender AS client_gender ,
             a.`status` AS client_status ,
             a.`status` AS client_status ,
             a.channel_code_id as channel_code_id,
             a.channel_code_id as channel_code_id,
-            c.deleted_at AS client_deleted_at ,
+            a.deleted_at AS client_deleted_at ,
+            c.created_at AS client_created_at ,
+            c.unionid AS client_unionid ,
+            e.`name` AS employee_name,
+            p.`name` as company_name,
+            l.`name` as channel_code_name,
+            a.state,
+            a.remark
+        FROM
+            mc_work_contact_employee AS a
+            LEFT JOIN mc_work_employee AS e ON a.employee_id = e.id
+            LEFT JOIN mc_work_contact AS c ON a.contact_id = c.id
+            LEFT JOIN mc_corp AS p ON p.id = a.corp_id
+            LEFT JOIN mc_channel_code AS l ON l.id = a.channel_code_id
+        where 1=1 ${ew.sqlSegment}
+
+    </select>
+
+    <select id="getAllVoList"  resultType="com.mokamrp.privates.mapper.vo.WorkContactEmployeeVo">
+        SELECT
+            a.id,
+            c.`name` AS client_name ,
+            c.gender AS client_gender ,
+            a.`status` AS client_status ,
+            a.channel_code_id as channel_code_id,
+            a.deleted_at AS client_deleted_at ,
             c.created_at AS client_created_at ,
             c.created_at AS client_created_at ,
             c.unionid AS client_unionid ,
             c.unionid AS client_unionid ,
             e.`name` AS employee_name,
             e.`name` AS employee_name,

+ 140 - 0
src/main/java/com/mokamrp/privates/mapper/pojo/Downfile.java

@@ -0,0 +1,140 @@
+package com.mokamrp.privates.mapper.pojo;
+
+import com.baomidou.mybatisplus.enums.IdType;
+import com.baomidou.mybatisplus.annotations.TableId;
+import com.baomidou.mybatisplus.annotations.TableId;
+import com.baomidou.mybatisplus.enums.IdType;
+import com.baomidou.mybatisplus.activerecord.Model;
+import com.baomidou.mybatisplus.annotations.TableName;
+import org.apache.tomcat.util.bcel.Const;
+
+import java.io.Serializable;
+
+/**
+ * <p>
+ * 
+ * </p>
+ *
+ * @author gy
+ * @since 2021-04-22
+ */
+@TableName("private_downfile")
+public class Downfile extends Model<Downfile> {
+
+
+    public static final String WORK_CONTACT_EMPLOYEE = "客服信息下载.csv";
+
+    private static final long serialVersionUID = 1L;
+
+    @TableId(value = "id", type = IdType.AUTO)
+    private Integer id;
+    /**
+     * 名称
+     */
+    private String title;
+    /**
+     * 下载人名称
+     */
+    private String authName;
+    /**
+     * 创建时间
+     */
+    private Integer createtime;
+    /**
+     * 下载链接
+     */
+    private String downUrl;
+    /**
+     * 提示
+     */
+    private String msg;
+    private String filterJson;
+    /**
+     * 1-完成
+     */
+    private Integer status;
+
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public String getTitle() {
+        return title;
+    }
+
+    public void setTitle(String title) {
+        this.title = title;
+    }
+
+    public String getAuthName() {
+        return authName;
+    }
+
+    public void setAuthName(String authName) {
+        this.authName = authName;
+    }
+
+    public Integer getCreatetime() {
+        return createtime;
+    }
+
+    public void setCreatetime(Integer createtime) {
+        this.createtime = createtime;
+    }
+
+    public String getDownUrl() {
+        return downUrl;
+    }
+
+    public void setDownUrl(String downUrl) {
+        this.downUrl = downUrl;
+    }
+
+    public String getMsg() {
+        return msg;
+    }
+
+    public void setMsg(String msg) {
+        this.msg = msg;
+    }
+
+    public String getFilterJson() {
+        return filterJson;
+    }
+
+    public void setFilterJson(String filterJson) {
+        this.filterJson = filterJson;
+    }
+
+    public Integer getStatus() {
+        return status;
+    }
+
+    public void setStatus(Integer status) {
+        this.status = status;
+    }
+
+    @Override
+    protected Serializable pkVal() {
+        return this.id;
+    }
+
+    @Override
+    public String toString() {
+        return "Downfile{" +
+        ", id=" + id +
+        ", title=" + title +
+        ", authName=" + authName +
+        ", createtime=" + createtime +
+        ", downUrl=" + downUrl +
+        ", msg=" + msg +
+        ", filterJson=" + filterJson +
+        ", status=" + status +
+        "}";
+    }
+}

+ 57 - 58
src/main/java/com/mokamrp/privates/mapper/vo/WorkContactEmployeeVo.java

@@ -19,104 +19,96 @@ import java.util.Date;
 public class WorkContactEmployeeVo{
 public class WorkContactEmployeeVo{
 
 
     private Integer id;
     private Integer id;
-    private String client_name;
-    private Integer client_status;
-    private Integer channel_code_id;
-    private Date client_deleted_at;
-    private Date client_created_at;
-    private Integer client_unionid;
-    private String employee_name;
-    private String company_name;
-    private String channel_code_name;
-    private String state;
+    private String clientName;
+    private Integer clientStatus;
+    private Integer channelCodeId;
+    private Date clientDeletedAt;
+    private Date clientCreatedAt;
+    private Integer clientUnionid;
+    private String employeeName;
+    private String companyName;
+    private String channelCodeName;
+    private String tate;
     private String remark;
     private String remark;
 
 
-    public Integer getId() {
-        return id;
-    }
-
-    public void setId(Integer id) {
-        this.id = id;
-    }
-
-    public String getClient_name() {
-        return client_name;
+    public String getClientName() {
+        return clientName;
     }
     }
 
 
-    public void setClient_name(String client_name) {
-        this.client_name = client_name;
+    public void setClientName(String clientName) {
+        this.clientName = clientName;
     }
     }
 
 
-    public Integer getClient_status() {
-        return client_status;
+    public Integer getClientStatus() {
+        return clientStatus;
     }
     }
 
 
-    public void setClient_status(Integer client_status) {
-        this.client_status = client_status;
+    public void setClientStatus(Integer clientStatus) {
+        this.clientStatus = clientStatus;
     }
     }
 
 
-    public Integer getChannel_code_id() {
-        return channel_code_id;
+    public Integer getChannelCodeId() {
+        return channelCodeId;
     }
     }
 
 
-    public void setChannel_code_id(Integer channel_code_id) {
-        this.channel_code_id = channel_code_id;
+    public void setChannelCodeId(Integer channelCodeId) {
+        this.channelCodeId = channelCodeId;
     }
     }
 
 
-    public Date getClient_deleted_at() {
-        return client_deleted_at;
+    public Date getClientDeletedAt() {
+        return clientDeletedAt;
     }
     }
 
 
-    public void setClient_deleted_at(Date client_deleted_at) {
-        this.client_deleted_at = client_deleted_at;
+    public void setClientDeletedAt(Date clientDeletedAt) {
+        this.clientDeletedAt = clientDeletedAt;
     }
     }
 
 
-    public Date getClient_created_at() {
-        return client_created_at;
+    public Date getClientCreatedAt() {
+        return clientCreatedAt;
     }
     }
 
 
-    public void setClient_created_at(Date client_created_at) {
-        this.client_created_at = client_created_at;
+    public void setClientCreatedAt(Date clientCreatedAt) {
+        this.clientCreatedAt = clientCreatedAt;
     }
     }
 
 
-    public Integer getClient_unionid() {
-        return client_unionid;
+    public Integer getClientUnionid() {
+        return clientUnionid;
     }
     }
 
 
-    public void setClient_unionid(Integer client_unionid) {
-        this.client_unionid = client_unionid;
+    public void setClientUnionid(Integer clientUnionid) {
+        this.clientUnionid = clientUnionid;
     }
     }
 
 
-    public String getEmployee_name() {
-        return employee_name;
+    public String getEmployeeName() {
+        return employeeName;
     }
     }
 
 
-    public void setEmployee_name(String employee_name) {
-        this.employee_name = employee_name;
+    public void setEmployeeName(String employeeName) {
+        this.employeeName = employeeName;
     }
     }
 
 
-    public String getCompany_name() {
-        return company_name;
+    public String getCompanyName() {
+        return companyName;
     }
     }
 
 
-    public void setCompany_name(String company_name) {
-        this.company_name = company_name;
+    public void setCompanyName(String companyName) {
+        this.companyName = companyName;
     }
     }
 
 
-    public String getChannel_code_name() {
-        return channel_code_name;
+    public String getChannelCodeName() {
+        return channelCodeName;
     }
     }
 
 
-    public void setChannel_code_name(String channel_code_name) {
-        this.channel_code_name = channel_code_name;
+    public void setChannelCodeName(String channelCodeName) {
+        this.channelCodeName = channelCodeName;
     }
     }
 
 
-    public String getState() {
-        return state;
+    public String getTate() {
+        return tate;
     }
     }
 
 
-    public void setState(String state) {
-        this.state = state;
+    public void setTate(String tate) {
+        this.tate = tate;
     }
     }
 
 
     public String getRemark() {
     public String getRemark() {
@@ -127,5 +119,12 @@ public class WorkContactEmployeeVo{
         this.remark = remark;
         this.remark = remark;
     }
     }
 
 
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
 
 
 }
 }

+ 16 - 0
src/main/java/com/mokamrp/privates/service/DownfileService.java

@@ -0,0 +1,16 @@
+package com.mokamrp.privates.service;
+
+import com.mokamrp.privates.mapper.pojo.Downfile;
+import com.baomidou.mybatisplus.service.IService;
+
+/**
+ * <p>
+ *  服务类
+ * </p>
+ *
+ * @author gy
+ * @since 2021-04-22
+ */
+public interface DownfileService extends IService<Downfile> {
+
+}

+ 5 - 0
src/main/java/com/mokamrp/privates/service/WorkContactEmployeeService.java

@@ -29,4 +29,9 @@ public interface WorkContactEmployeeService extends IService<WorkContactEmployee
                                     Integer group_id,
                                     Integer group_id,
                                     Integer corp_id, List employee_id,List tag_id , Integer channel_code_id);
                                     Integer corp_id, List employee_id,List tag_id , Integer channel_code_id);
 
 
+    void export(Integer gender, Integer status, String name,
+                                    Integer start_deleted_at, Integer end_deleted_at,
+                                    Integer start_created_at, Integer end_created_at,
+                                    Integer group_id,
+                                    Integer corp_id, List employee_id,List tag_id , Integer channel_code_id);
 }
 }

+ 20 - 0
src/main/java/com/mokamrp/privates/service/impl/DownfileServiceImpl.java

@@ -0,0 +1,20 @@
+package com.mokamrp.privates.service.impl;
+
+import com.mokamrp.privates.mapper.pojo.Downfile;
+import com.mokamrp.privates.mapper.DownfileMapper;
+import com.mokamrp.privates.service.DownfileService;
+import com.baomidou.mybatisplus.service.impl.ServiceImpl;
+import org.springframework.stereotype.Service;
+
+/**
+ * <p>
+ *  服务实现类
+ * </p>
+ *
+ * @author gy
+ * @since 2021-04-22
+ */
+@Service
+public class DownfileServiceImpl extends ServiceImpl<DownfileMapper, Downfile> implements DownfileService {
+
+}

+ 126 - 4
src/main/java/com/mokamrp/privates/service/impl/WorkContactEmployeeServiceImpl.java

@@ -1,20 +1,28 @@
 package com.mokamrp.privates.service.impl;
 package com.mokamrp.privates.service.impl;
 
 
+import com.aliyun.oss.OSS;
+import com.aliyun.oss.model.PutObjectRequest;
 import com.baomidou.mybatisplus.mapper.EntityWrapper;
 import com.baomidou.mybatisplus.mapper.EntityWrapper;
 import com.baomidou.mybatisplus.plugins.Page;
 import com.baomidou.mybatisplus.plugins.Page;
+import com.mokamrp.privates.config.OSSConfiguration;
 import com.mokamrp.privates.mapper.CorpMapper;
 import com.mokamrp.privates.mapper.CorpMapper;
+import com.mokamrp.privates.mapper.DownfileMapper;
+import com.mokamrp.privates.mapper.pojo.Downfile;
 import com.mokamrp.privates.mapper.pojo.WorkContactEmployee;
 import com.mokamrp.privates.mapper.pojo.WorkContactEmployee;
 import com.mokamrp.privates.mapper.WorkContactEmployeeMapper;
 import com.mokamrp.privates.mapper.WorkContactEmployeeMapper;
 import com.mokamrp.privates.mapper.vo.WorkContactEmployeeVo;
 import com.mokamrp.privates.mapper.vo.WorkContactEmployeeVo;
 import com.mokamrp.privates.service.WorkContactEmployeeService;
 import com.mokamrp.privates.service.WorkContactEmployeeService;
 import com.baomidou.mybatisplus.service.impl.ServiceImpl;
 import com.baomidou.mybatisplus.service.impl.ServiceImpl;
+import com.mokamrp.privates.utils.OssFile;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Param;
+import org.apache.tomcat.util.bcel.Const;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.io.ByteArrayInputStream;
+import java.text.SimpleDateFormat;
+import java.util.*;
 
 
 /**
 /**
  * <p>
  * <p>
@@ -29,6 +37,15 @@ public class WorkContactEmployeeServiceImpl extends ServiceImpl<WorkContactEmplo
 
 
 
 
     @Autowired
     @Autowired
+    private OSS ossClient;
+
+    @Autowired
+    private DownfileMapper downfileMapper;
+
+    @Autowired
+    private OSSConfiguration ossConfiguration;
+
+    @Autowired
     private WorkContactEmployeeMapper mapperObj  ;
     private WorkContactEmployeeMapper mapperObj  ;
 
 
     @Override
     @Override
@@ -92,4 +109,109 @@ public class WorkContactEmployeeServiceImpl extends ServiceImpl<WorkContactEmplo
         return resMap;
         return resMap;
     }
     }
 
 
-}
+    @Async
+    @Override
+    public void export(Integer gender, Integer status, String name,
+                                           Integer start_deleted_at, Integer end_deleted_at,
+                                           Integer start_created_at, Integer end_created_at,
+                                           Integer group_id,
+                                           Integer corp_id, List employee_id, List tag_id , Integer channel_code_id){
+
+        EntityWrapper<WorkContactEmployee> obj = new EntityWrapper<WorkContactEmployee>();
+
+        if(name != ""){
+            obj.like("c.name",name);
+        }
+
+        if(gender != null){
+            obj.eq("c.gender",gender);
+        }
+
+        if(status != null) {
+            obj.eq("a.`status`", status);
+        }
+
+        if(channel_code_id != null) {
+            obj.eq("a.channel_code_id", channel_code_id);
+        }
+
+        if(start_deleted_at != null) {
+            obj.ge("c.deleted_at", start_deleted_at);
+        }
+
+        if(end_created_at != null) {
+            obj.le("c.deleted_at", end_deleted_at);
+        }
+
+        if(start_created_at != null) {
+            obj.ge("c.created_at", start_created_at);
+        }
+
+        if(end_created_at != null) {
+            obj.le("c.created_at", end_created_at);
+        }
+        if(corp_id != null) {
+            obj.eq("a.corp_id", corp_id);
+        }
+        if(employee_id !=null) {
+            obj.in("a.employee_id", employee_id);
+        }
+
+        List<WorkContactEmployeeVo> list = mapperObj.getAllVoList(obj);
+
+        //实现下载
+        List<List<Object>> resList = new ArrayList<List<Object>>();
+        Object[] head = { "id", "客户昵称", "状态","渠道码id","渠道名称","客户删除时间","客户创建时间","unionid","客服名称","公司名称" };
+        List<Object> headList = Arrays.asList(head);
+        resList.add(headList);
+
+        List<Object> tempObj;
+        if(list.size() >=1){
+            for (WorkContactEmployeeVo o: list){
+                tempObj = new ArrayList<Object>() {//这个大括号 就相当于我们  new 接口
+                    {//这个大括号 就是 构造代码块 会在构造函数前 调用
+                        this.add(o.getId());
+                        this.add(o.getClientName());
+                        this.add(o.getClientStatus());
+                        this.add(o.getChannelCodeId());
+                        this.add(o.getChannelCodeName());
+                        this.add(o.getClientDeletedAt());
+                        this.add(o.getClientCreatedAt());
+                        this.add(o.getClientUnionid());
+                        this.add(o.getEmployeeName());
+                        this.add(o.getCompanyName());
+                    }
+                };
+                resList.add(tempObj);
+
+            }
+        }
+
+        StringBuffer content = OssFile.createCSV(resList);
+
+
+        /*上传到oss*/
+        Downfile file = new Downfile();
+
+        Date currentTime = new Date();
+        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
+        String dateString = formatter.format(currentTime);
+
+
+        String filePath = OSSConfiguration.DOWN_DIR+dateString+"/"+Downfile.WORK_CONTACT_EMPLOYEE;
+
+        file.setTitle(Downfile.WORK_CONTACT_EMPLOYEE);
+        file.setDownUrl(ossConfiguration.getHost()+filePath);
+        file.setStatus(1);
+        System.out.println(ossConfiguration.getHost()+filePath);
+
+        PutObjectRequest putObjectRequest = new PutObjectRequest(ossConfiguration.getBucketName(), filePath, new ByteArrayInputStream(content.toString().getBytes()));
+        ossClient.putObject(putObjectRequest);
+
+
+        downfileMapper.insert(file);
+
+        return;
+    }
+
+}

+ 72 - 0
src/main/java/com/mokamrp/privates/utils/OssFile.java

@@ -0,0 +1,72 @@
+package com.mokamrp.privates.utils;
+
+import com.mokamrp.privates.utils.spring.SpringUtils;
+import org.springframework.context.MessageSource;
+import org.springframework.context.i18n.LocaleContextHolder;
+
+import java.io.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * 将list<map>转成csv模式
+ *
+ * @author gy
+ */
+public class OssFile
+{
+
+    public static StringBuffer createCSV(List<List<Object>> list) {
+
+        StringBuffer sb = new StringBuffer();
+        StringBuffer temp = new StringBuffer();
+
+        try {
+            for (List<Object> row : list) {
+                temp = new StringBuffer();
+                for (Object data : row) {
+                    temp.append("\"").append(data).append("\",");
+                }
+                temp.append("\n");
+                sb.append(temp);
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+
+        }
+        return sb;
+    }
+
+         // 表格头
+        /*
+         Object[] head = { "客户姓名", "证件类型", "日期", };
+         List<Object> headList = Arrays.asList(head);
+
+         //数据
+         List<List<Object>> dataList = new ArrayList<List<Object>>();
+         List<Object> rowList = null;
+         for (int i = 0; i < 100; i++) {
+                 rowList = new ArrayList<Object>();
+                 rowList.add("张三" + i);
+                 rowList.add("263834194" + i);
+                 rowList.add(new Date());
+                 dataList.add(rowList);
+             }
+
+         File csvFile = null;
+         BufferedReader csvWtriter = null;
+         */
+
+
+         private static StringBuffer writeRow(List<Object> row) {
+             StringBuffer sb = new StringBuffer();
+             for (Object data : row) {
+                 sb.append("\"").append(data).append("\",");
+             }
+
+             return sb;
+        }
+}

+ 9 - 0
src/main/resources/application.properties

@@ -12,6 +12,7 @@ spring.datasource.min-idle=5
 spring.datasource.initial-size=5
 spring.datasource.initial-size=5
 
 
 mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
 mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
+mybatis-plus.configuration.map-underscore-to-camel-case=true
 
 
 spring.redis.host=r-uf633f3f27aa2174pd.redis.rds.aliyuncs.com
 spring.redis.host=r-uf633f3f27aa2174pd.redis.rds.aliyuncs.com
 spring.redis.port=6379
 spring.redis.port=6379
@@ -23,6 +24,14 @@ spring.redis.jedis.pool.max-idle=8
 spring.redis.jedis.pool.max-active=20
 spring.redis.jedis.pool.max-active=20
 spring.redis.jedis.pool.max-wait=-1ms
 spring.redis.jedis.pool.max-wait=-1ms
 
 
+#阿里云oss配置(增加一个cdn地址配置)
+aliyun.host=https://mini-short-video-test.oss-cn-hangzhou.aliyuncs.com/
+aliyun.endpoint=https://oss-cn-hangzhou.aliyuncs.com
+aliyun.accessKeyId=LTAI4FnmkS1SNFkaKb4YZ1ga
+aliyun.accessKeySecret=irLfHOni7ffLU3yAf3LsKEXwQLfrNc
+aliyun.bucketName=mini-short-video-test
+spring.servlet.multipart.max-request-size=10MB
+spring.servlet.multipart.max-file-size=10MB
 
 
 xxl.sso.server=http://localhost:8888/sso
 xxl.sso.server=http://localhost:8888/sso
 xxl.sso.logout.path=/logout
 xxl.sso.logout.path=/logout