|
|
@@ -1,5 +1,8 @@
|
|
|
package com.mokamrp.privates.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.aliyun.oss.OSS;
|
|
|
import com.aliyun.oss.model.PutObjectRequest;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
@@ -7,6 +10,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.mokamrp.privates.config.OSSConfiguration;
|
|
|
import com.mokamrp.privates.entity.GetWorkContactEmployeeHandle;
|
|
|
+import com.mokamrp.privates.entity.HubWorkContactEmployeeHandle;
|
|
|
+import com.mokamrp.privates.help.AjaxResult;
|
|
|
import com.mokamrp.privates.mapper.DownfileMapper;
|
|
|
import com.mokamrp.privates.mapper.WorkContactEmployeeMapper;
|
|
|
import com.mokamrp.privates.mapper.pojo.Downfile;
|
|
|
@@ -16,9 +21,19 @@ import com.mokamrp.privates.mapper.vo.WorkContactEmployeeVo;
|
|
|
import com.mokamrp.privates.service.WorkContactEmployeeService;
|
|
|
import com.mokamrp.privates.utils.OssFile;
|
|
|
import com.mokamrp.privates.utils.PageUtil;
|
|
|
+import org.apache.http.HttpEntity;
|
|
|
+import org.apache.http.HttpResponse;
|
|
|
+import org.apache.http.client.methods.HttpPost;
|
|
|
+import org.apache.http.entity.StringEntity;
|
|
|
+import org.apache.http.impl.client.DefaultHttpClient;
|
|
|
+import org.apache.http.message.BasicHeader;
|
|
|
+import org.apache.http.protocol.HTTP;
|
|
|
+import org.apache.http.util.EntityUtils;
|
|
|
import org.apache.ibatis.annotations.Param;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.annotation.Id;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.thymeleaf.expression.Ids;
|
|
|
|
|
|
import java.io.ByteArrayInputStream;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
@@ -50,7 +65,198 @@ public class WorkContactEmployeeServiceImpl extends ServiceImpl<WorkContactEmplo
|
|
|
private WorkContactEmployeeMapper mapperObj;
|
|
|
|
|
|
@Override
|
|
|
+ public Map<String, Object> getCronHubPageList() {
|
|
|
+ List<Map<String,Object>> resList = new ArrayList<Map<String,Object>>();
|
|
|
|
|
|
+ Integer nextId = 0;
|
|
|
+
|
|
|
+ while(true){
|
|
|
+ QueryWrapper<WorkContactEmployeeVo> obj = new QueryWrapper<WorkContactEmployeeVo>();
|
|
|
+ obj.in("a.corp_id",getNovelIds());
|
|
|
+
|
|
|
+ if(!nextId.equals(0)){
|
|
|
+ obj.lt("d.id",nextId);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<WorkContactEmployeeVo> list = mapperObj.getCronHubVoList(obj,100);
|
|
|
+ if(list.size() <=0){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ nextId = synTyperTag(list);
|
|
|
+ if(nextId.equals(0)){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<Integer> getNovelIds(){
|
|
|
+ List<Integer> ids = new ArrayList<Integer>();
|
|
|
+ ids.add(63);
|
|
|
+ ids.add(64);
|
|
|
+ ids.add(65);
|
|
|
+ ids.add(66);
|
|
|
+ return ids;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> getHubPageList(HubWorkContactEmployeeHandle handle) {
|
|
|
+
|
|
|
+ List<Map<String,Object>> resList = new ArrayList<Map<String,Object>>();
|
|
|
+
|
|
|
+ QueryWrapper<WorkContactEmployeeVo> obj = getHubWrapper(handle);
|
|
|
+
|
|
|
+ Integer offset = PageUtil.getOffset(handle.getPage(),handle.getPagesize());
|
|
|
+ List<WorkContactEmployeeVo> list = mapperObj.getHubVoList(obj,offset,handle.getPagesize());
|
|
|
+ Integer total = mapperObj.getHubListTotal(obj);
|
|
|
+ Map<String, Object> resMap = new HashMap<String, Object>();
|
|
|
+
|
|
|
+ resMap.put("list", list);
|
|
|
+ resMap.put("total", total);
|
|
|
+
|
|
|
+ return resMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Integer synTyperTag(List<WorkContactEmployeeVo> list){
|
|
|
+
|
|
|
+ Integer nextId = 0;
|
|
|
+ int j = list.size();
|
|
|
+ JSONArray responseList = new JSONArray();
|
|
|
+ int t;
|
|
|
+ List<Map<String,Object>> resList = new ArrayList<Map<String,Object>>();
|
|
|
+
|
|
|
+ for (int i = 0; i < j; i++) {
|
|
|
+ Map<String, Object> map = new HashMap<String,Object>(); //数据采用的哈希表结构
|
|
|
+ if(list.get(i).getOpenId() == null || list.get(i).getOpenId().isEmpty()){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ map.put("openid", list.get(i).getOpenId());
|
|
|
+ map.put("appid", list.get(i).getAppId());
|
|
|
+ map.put("private_domain", 1);
|
|
|
+ map.put("main_body", list.get(i).getCompanyName());
|
|
|
+ resList.add(map);
|
|
|
+ nextId = list.get(i).getId();
|
|
|
+ }
|
|
|
+
|
|
|
+ HttpPost post = new HttpPost("http://yitian.mokagm.com/v1/external/fans/info");
|
|
|
+ // (2) 使用HttpClient发送get请求,获得返回结果HttpResponse
|
|
|
+ DefaultHttpClient http = new DefaultHttpClient();
|
|
|
+ JSONObject jsobj1 = new JSONObject();
|
|
|
+ post.setHeader("Content-Type", "application/json");
|
|
|
+
|
|
|
+ String json = JSON.toJSONString(resList);
|
|
|
+
|
|
|
+ StringEntity s = new StringEntity(json, "utf-8");
|
|
|
+ s.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
|
|
|
+ post.setEntity(s);
|
|
|
+
|
|
|
+ try {
|
|
|
+ HttpResponse response = http.execute(post);
|
|
|
+ if (response.getStatusLine().getStatusCode() == 200) {
|
|
|
+ HttpEntity resEntity = response.getEntity();
|
|
|
+ String message = EntityUtils.toString(resEntity, "utf-8");
|
|
|
+ JSONObject jsonObject = JSON.parseObject(message);
|
|
|
+ Object resMap;
|
|
|
+ if (jsonObject.get("data") != null) {
|
|
|
+ responseList = jsonObject.getJSONArray("data");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ System.out.println(e.getMessage());
|
|
|
+ return nextId;
|
|
|
+ }
|
|
|
+
|
|
|
+ int resLen = responseList.size();
|
|
|
+ Date d = new Date();
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ String dateString = sdf.format(d);
|
|
|
+ for (int i = 0; i < j; i++) {
|
|
|
+ list.get(i).setPlatform("");
|
|
|
+ for(t=0;t<resLen;t++) {
|
|
|
+ //匹配成功的
|
|
|
+ if(list.get(i).getOpenId() != null && responseList.getJSONObject(t).get("openid").equals(list.get(i).getOpenId())){
|
|
|
+ mapperObj.updateOpenid(
|
|
|
+ list.get(i).getId(),
|
|
|
+ responseList.getJSONObject(t).get("label").toString(),
|
|
|
+ responseList.getJSONObject(t).get("platform").toString(),
|
|
|
+ dateString
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return nextId;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<WorkContactEmployeeVo> getTyperTag(List<WorkContactEmployeeVo> list){
|
|
|
+
|
|
|
+ int j = list.size();
|
|
|
+ int t;
|
|
|
+ JSONArray responseList = new JSONArray();
|
|
|
+ List<Map<String,Object>> resList = new ArrayList<Map<String,Object>>();
|
|
|
+
|
|
|
+ for (int i = 0; i < j; i++) {
|
|
|
+ Map<String, Object> map = new HashMap<String,Object>(); //数据采用的哈希表结构
|
|
|
+ if(list.get(i).getOpenId() == null || list.get(i).getOpenId().isEmpty()){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ map.put("openid", list.get(i).getOpenId());
|
|
|
+ map.put("appid", list.get(i).getAppId());
|
|
|
+ map.put("private_domain", 1);
|
|
|
+ map.put("main_body", list.get(i).getCompanyName());
|
|
|
+ resList.add(map);
|
|
|
+ }
|
|
|
+
|
|
|
+ /*请求typer*/
|
|
|
+ HttpPost post = new HttpPost("http://yitian.mokagm.com/v1/external/fans/info");
|
|
|
+ // (2) 使用HttpClient发送get请求,获得返回结果HttpResponse
|
|
|
+ DefaultHttpClient http = new DefaultHttpClient();
|
|
|
+ JSONObject jsobj1 = new JSONObject();
|
|
|
+ post.setHeader("Content-Type", "application/json");
|
|
|
+
|
|
|
+ String json = JSON.toJSONString(resList);
|
|
|
+
|
|
|
+ StringEntity s = new StringEntity(json, "utf-8");
|
|
|
+ s.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
|
|
|
+ post.setEntity(s);
|
|
|
+
|
|
|
+ try {
|
|
|
+ HttpResponse response = http.execute(post);
|
|
|
+
|
|
|
+ if (response.getStatusLine().getStatusCode() == 200) {
|
|
|
+ HttpEntity resEntity = response.getEntity();
|
|
|
+ String message = EntityUtils.toString(resEntity, "utf-8");
|
|
|
+ JSONObject jsonObject = JSON.parseObject(message);
|
|
|
+ Object resMap;
|
|
|
+ if (jsonObject.get("data") != null) {
|
|
|
+ responseList = jsonObject.getJSONArray("data");
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ System.out.println(e.getMessage());
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ int resLen = responseList.size();
|
|
|
+ for (int i = 0; i < j; i++) {
|
|
|
+ list.get(i).setPlatform("");
|
|
|
+ for(t=0;t<resLen;t++) {
|
|
|
+ //匹配成功的
|
|
|
+ if(list.get(i).getOpenId() != null && responseList.getJSONObject(t).get("openid").equals(list.get(i).getOpenId())){
|
|
|
+ list.get(i).setTyperTag(responseList.getJSONObject(t).get("label").toString());
|
|
|
+ list.get(i).setPlatform(responseList.getJSONObject(t).get("platform").toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public Map<String, Object> getPageList(GetWorkContactEmployeeHandle handle) {
|
|
|
|
|
|
QueryWrapper<WorkContactEmployeeVo> obj = getWrapper(handle);
|
|
|
@@ -101,6 +307,57 @@ public class WorkContactEmployeeServiceImpl extends ServiceImpl<WorkContactEmplo
|
|
|
return vos;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void exportNovel(Downfile downFile, HubWorkContactEmployeeHandle handle) {
|
|
|
+
|
|
|
+ String title = Downfile.NOVEL;
|
|
|
+ List<Object> tempObj;
|
|
|
+ QueryWrapper<WorkContactEmployeeVo> obj = getHubWrapper(handle);
|
|
|
+ Integer total = mapperObj.getHubListTotal(obj);
|
|
|
+ List<WorkContactEmployeeVo> list = mapperObj.getHubVoList(obj,0,total);
|
|
|
+
|
|
|
+ //实现下载
|
|
|
+ List<List<Object>> resList = new ArrayList<List<Object>>();
|
|
|
+ Object[] head = {"id", "客户名称", "状态(1正常 2删除 3拉黑)", "平台", "ghid", "appid","openid", "标签", "客服名称", "所属公司","备注","创建时间"};
|
|
|
+ List<Object> headList = Arrays.asList(head);
|
|
|
+ resList.add(headList);
|
|
|
+
|
|
|
+ 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.getPlatform());
|
|
|
+ this.add(o.getGhId());
|
|
|
+ this.add(o.getAppId());
|
|
|
+ this.add(o.getOpenId());
|
|
|
+ this.add(o.getTyperTag());
|
|
|
+ this.add(o.getEmployeeName());
|
|
|
+ this.add(o.getCompanyName());
|
|
|
+ this.add(o.getRemark());
|
|
|
+ this.add(o.getClientCreatedAt());
|
|
|
+ }
|
|
|
+ };
|
|
|
+ resList.add(tempObj);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ StringBuffer content = OssFile.createCSV(resList);
|
|
|
+
|
|
|
+ /*上传到oss*/
|
|
|
+ Date currentTime = new Date();
|
|
|
+ SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ String bom = new String(new byte[] { (byte) 0xEF, (byte) 0xBB,(byte) 0xBF });
|
|
|
+ String dateString = formatter.format(currentTime);
|
|
|
+ String filePath = OSSConfiguration.DOWN_DIR + dateString + "/" + downFile.getId().toString() + "_" + title;
|
|
|
+ PutObjectRequest putObjectRequest = new PutObjectRequest(ossConfiguration.getBucketName(), filePath, new ByteArrayInputStream((bom+content.toString()).getBytes()));
|
|
|
+ ossClient.putObject(putObjectRequest);
|
|
|
+ downFile.setDownUrl(ossConfiguration.getHost() + filePath);
|
|
|
+ downFile.setStatus(1);
|
|
|
+ downfileMapper.updateById(downFile);
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
public void export(Downfile downFile, GetWorkContactEmployeeHandle handle) {
|
|
|
@@ -174,8 +431,13 @@ public class WorkContactEmployeeServiceImpl extends ServiceImpl<WorkContactEmplo
|
|
|
for (Map<String, Object> tag : tagMapData) {
|
|
|
if (tag.get("employee_id").toString().equals(list.get(i).getEmployeeId().toString())
|
|
|
&& tag.get("contact_id").toString().equals(list.get(i).getContactId().toString()) ) {
|
|
|
- list.get(i).setTagNames(tag.get("tag_names").toString());
|
|
|
- list.get(i).setTagIds(tag.get("tag_ids").toString());
|
|
|
+ if(tag.get("tag_names") != null){
|
|
|
+ list.get(i).setTagNames(tag.get("tag_names").toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ if(tag.get("tag_ids") != null){
|
|
|
+ list.get(i).setTagIds(tag.get("tag_ids").toString());
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -184,6 +446,61 @@ public class WorkContactEmployeeServiceImpl extends ServiceImpl<WorkContactEmplo
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
+ private QueryWrapper<WorkContactEmployeeVo> getHubWrapper(HubWorkContactEmployeeHandle handle) {
|
|
|
+
|
|
|
+ QueryWrapper<WorkContactEmployeeVo> obj = new QueryWrapper<WorkContactEmployeeVo>();
|
|
|
+ Integer gender = handle.getGender();
|
|
|
+ String name = handle.getName();
|
|
|
+ Integer status = handle.getStatus();
|
|
|
+ String startCreatedAt = handle.getStartCreatedAt();
|
|
|
+ String endCreatedAt = handle.getEndCreatedAt();
|
|
|
+ Integer corpId = handle.getCorpId();
|
|
|
+ List<String> ghIds = handle.getGhIds();
|
|
|
+ String platform = handle.getPlatform();
|
|
|
+ List<Integer> employeeId = handle.getEmployeeId();
|
|
|
+ List<Integer> authCorpIds = handle.getAuthCorpIds();
|
|
|
+
|
|
|
+ obj.in("a.corp_id",getNovelIds());
|
|
|
+ obj.in("a.corp_id", authCorpIds);
|
|
|
+
|
|
|
+ if (name != null && !name.equals("")) {
|
|
|
+ obj.like("c.name", name);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (gender != null) {
|
|
|
+ obj.eq("c.gender", gender);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (startCreatedAt != null && !startCreatedAt.isEmpty()) {
|
|
|
+ obj.ge("c.created_at", startCreatedAt);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (status != null) {
|
|
|
+ obj.eq("a.`status`", status);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (endCreatedAt != null && !endCreatedAt.isEmpty()) {
|
|
|
+ obj.le("c.created_at", endCreatedAt);
|
|
|
+ }
|
|
|
+ if (corpId != null) {
|
|
|
+ obj.eq("a.corp_id", corpId);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (employeeId != null && employeeId.size() >= 1) {
|
|
|
+ obj.in("a.employee_id", employeeId);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (platform != null && !platform.equals("")) {
|
|
|
+ obj.like("d.platform", platform);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ghIds != null && ghIds.size() >= 1) {
|
|
|
+ obj.in("d.ghid", ghIds);
|
|
|
+ }
|
|
|
+
|
|
|
+ return obj;
|
|
|
+ }
|
|
|
+
|
|
|
private QueryWrapper<WorkContactEmployeeVo> getWrapper(GetWorkContactEmployeeHandle handle) {
|
|
|
|
|
|
QueryWrapper<WorkContactEmployeeVo> obj = new QueryWrapper<WorkContactEmployeeVo>();
|