Browse Source

客户导出修改

yusm 2 days ago
parent
commit
bc2318ea90

+ 88 - 47
fhKeeper/formulahousekeeper/management-crmNew/src/main/java/com/management/platform/controller/CustomController.java

@@ -5,15 +5,19 @@ import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.management.platform.entity.*;
 import com.management.platform.mapper.*;
 import com.management.platform.service.ContactsService;
 import com.management.platform.service.CustomService;
+import com.management.platform.service.WechatUserFollowService;
 import com.management.platform.service.WxCorpInfoService;
 import com.management.platform.service.impl.ExcelExportServiceImpl;
 import com.management.platform.util.HttpRespMsg;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.format.annotation.DateTimeFormat;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
@@ -22,9 +26,12 @@ import org.springframework.web.multipart.MultipartFile;
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 
 /**
  * <p>
@@ -56,6 +63,8 @@ public class CustomController {
     private BusinessOpportunityMapper businessOpportunityMapper;
     @Autowired
     private SalesOrderMapper salesOrderMapper;
+    @Autowired
+    private WechatUserFollowService wechatUserFollowService;
 
 
     @RequestMapping("list")
@@ -134,63 +143,95 @@ public class CustomController {
         List<List<String>> dataList=new ArrayList<>();
         List<String> titleList=new ArrayList<>();
         List<String> modelList=new ArrayList<>();
-        for (int i = 0; i < configObJSONArray.size(); i++) {
-            JSONObject item = configObJSONArray.getJSONObject(i);
-            String type = item.getString("type");
-            if (type.equals("grid")){
-                JSONArray columns = item.getJSONArray("columns");
-                for (int j = 0; j < columns.size(); j++) {
-                    JSONObject columnsJSONObject = columns.getJSONObject(j);
-                    JSONArray listJsonArray = columnsJSONObject.getJSONArray("list");
-                    for (int k = 0; k < listJsonArray.size(); k++) {
-                        JSONObject listJsonArrayJSONObject = listJsonArray.getJSONObject(k);
-                        titleList.add(listJsonArrayJSONObject.getString("label"));
-                        modelList.add(listJsonArrayJSONObject.getString("model"));
-                    }
-                }
-            }
-            else {
-                titleList.add(item.getString("label"));
-                modelList.add(item.getString("model"));
-            }
-        }
-        dataList.add(titleList);
-
         HttpRespMsg respMsg = list(custom,request);
         Map<String, Object> msgData = (Map<String, Object>) respMsg.getData();
         List<Custom> list = (List<Custom>) msgData.get("data");
-
-        for (Custom data : list) {
-            List<String> item=new ArrayList<>();
-            for (int i = 0; i < modelList.size(); i++) {
-
-                String model = modelList.get(i);
-                String targetName = model.substring(0, 1).toUpperCase() + model.substring(1);
-                Class<? extends Custom> aClass = data.getClass();
-                String value = "";
-
-                if(model.equals("inchargerId")){
-                    if(wxCorpInfo!=null&&wxCorpInfo.getSaasSyncContact()==1){
-                        value = "$userName="+String.valueOf(aClass.getMethod("getInchargerName").invoke(data))+"$";
-                    }else {
-                        value = String.valueOf(aClass.getMethod("getInchargerName").invoke(data)).equals("null") ? "" :String.valueOf(aClass.getMethod("getInchargerName").invoke(data));
+        //todo 公司id待定
+        if (user.getCompanyId()!=5807) {
+            for (int i = 0; i < configObJSONArray.size(); i++) {
+                JSONObject item = configObJSONArray.getJSONObject(i);
+                String type = item.getString("type");
+                if (type.equals("grid")) {
+                    JSONArray columns = item.getJSONArray("columns");
+                    for (int j = 0; j < columns.size(); j++) {
+                        JSONObject columnsJSONObject = columns.getJSONObject(j);
+                        JSONArray listJsonArray = columnsJSONObject.getJSONArray("list");
+                        for (int k = 0; k < listJsonArray.size(); k++) {
+                            JSONObject listJsonArrayJSONObject = listJsonArray.getJSONObject(k);
+                            titleList.add(listJsonArrayJSONObject.getString("label"));
+                            modelList.add(listJsonArrayJSONObject.getString("model"));
+                        }
                     }
-                }else {
-                    value= String.valueOf(aClass.getMethod("get" + targetName).invoke(data)==null?"":aClass.getMethod("get" + targetName).invoke(data));
+                } else {
+                    titleList.add(item.getString("label"));
+                    modelList.add(item.getString("model"));
                 }
+            }
+            dataList.add(titleList);
+            for (Custom data : list) {
+                List<String> item = new ArrayList<>();
+                for (int i = 0; i < modelList.size(); i++) {
+
+                    String model = modelList.get(i);
+                    String targetName = model.substring(0, 1).toUpperCase() + model.substring(1);
+                    Class<? extends Custom> aClass = data.getClass();
+                    String value = "";
+
+                    if (model.equals("inchargerId")) {
+                        if (wxCorpInfo != null && wxCorpInfo.getSaasSyncContact() == 1) {
+                            value = "$userName=" + String.valueOf(aClass.getMethod("getInchargerName").invoke(data)) + "$";
+                        } else {
+                            value = String.valueOf(aClass.getMethod("getInchargerName").invoke(data)).equals("null") ? "" : String.valueOf(aClass.getMethod("getInchargerName").invoke(data));
+                        }
+                    } else {
+                        value = String.valueOf(aClass.getMethod("get" + targetName).invoke(data) == null ? "" : aClass.getMethod("get" + targetName).invoke(data));
+                    }
 
-                if(model.equals("clueSourceId")){
-                    value = String.valueOf(null == aClass.getMethod("getClueSourceValue").invoke(data)?"":aClass.getMethod("getClueSourceValue").invoke(data));
+                    if (model.equals("clueSourceId")) {
+                        value = String.valueOf(null == aClass.getMethod("getClueSourceValue").invoke(data) ? "" : aClass.getMethod("getClueSourceValue").invoke(data));
+                    }
+                    if (model.equals("customerLevelId")) {
+                        value = String.valueOf(null == aClass.getMethod("getCustomerLevelValue").invoke(data) ? "" : aClass.getMethod("getCustomerLevelValue").invoke(data));
+                    }
+                    if (model.equals("customerIndustryId")) {
+                        value = String.valueOf(null == aClass.getMethod("getCustomerIndustryValue").invoke(data) ? "" : aClass.getMethod("getCustomerIndustryValue").invoke(data));
+                    }
+                    item.add(value);
                 }
-                if(model.equals("customerLevelId")){
-                    value = String.valueOf(null == aClass.getMethod("getCustomerLevelValue").invoke(data)?"":aClass.getMethod("getCustomerLevelValue").invoke(data));
+                dataList.add(item);
+            }
+        }
+        else {
+            titleList.add("客户名称");
+            titleList.add("负责人");
+            titleList.add("关注日期");
+            titleList.add("关注时间");
+            dataList.add(titleList);
+            List<WechatUserFollow> userFollows = wechatUserFollowService.list(new QueryWrapper<WechatUserFollow>().eq("is_follow", 1).isNotNull("salesman_id"));
+
+            for (Custom data : list) {
+                List<String> item = new ArrayList<>();
+                item.add(data.getCustomName());
+                if (wxCorpInfo != null && wxCorpInfo.getSaasSyncContact() == 1) {
+                    String  value = "$userName=" + data.getInchargerName() + "$";
+                    item.add(value);
+                } else {
+                    String value = data.getInchargerName();
+                    item.add(value);
                 }
-                if(model.equals("customerIndustryId")){
-                    value = String.valueOf(null == aClass.getMethod("getCustomerIndustryValue").invoke(data)?"":aClass.getMethod("getCustomerIndustryValue").invoke(data));
+                Optional<WechatUserFollow> first = userFollows.stream().filter(u -> u.getOpenId() != null && StringUtils.isNotEmpty(data.getCustomName()) && u.getOpenId().equals(data.getCustomName())).findFirst();
+                if (first.isPresent()){
+                    LocalDateTime followTime = first.get().getFollowTime();
+                    DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+                    DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss");
+                    item.add(dateFormatter.format(followTime));
+                    item.add(timeFormatter.format(followTime));
+                }else {
+                    item.add("");
+                    item.add("");
                 }
-                item.add(value);
+                dataList.add(item);
             }
-            dataList.add(item);
         }
         String fileName="客户表导出_"+ System.currentTimeMillis();
         long endTimeSec = System.currentTimeMillis();

+ 5 - 7
fhKeeper/formulahousekeeper/management-crmNew/src/main/java/com/management/platform/controller/WechatCallbackController.java

@@ -1,9 +1,7 @@
 package com.management.platform.controller;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.management.platform.entity.MiniBindUser;
-import com.management.platform.entity.WechatQrcodeScan;
-import com.management.platform.entity.WechatUserFollow;
+import com.management.platform.entity.*;
 import com.management.platform.mapper.WechatQrcodeScanMapper;
 import com.management.platform.mapper.WechatUserFollowMapper;
 import com.management.platform.service.CustomService;
@@ -26,6 +24,7 @@ import java.time.Instant;
 import java.time.LocalDateTime;
 import java.time.ZoneId;
 import java.util.Arrays;
+import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
@@ -198,7 +197,7 @@ public class WechatCallbackController {
                         .eq("openid", scanRecord.getOpenId()).eq("user_id",salesmanId));
 
                 if (miniBindUserList.isEmpty()){
-                    /*int count = customService.count(new QueryWrapper<Custom>().eq("custom_name", openId));
+                    int count = customService.count(new QueryWrapper<Custom>().eq("custom_name", openId));
                     if(count==0) {
                         Custom custom = new Custom();
                         custom.setCustomName(openId);//用户的openId
@@ -213,7 +212,7 @@ public class WechatCallbackController {
                         }
                     }else {
                         log.info("已存在custom_name为"+openId+"的客户");
-                    }*/
+                    }
                     MiniBindUser miniBindUser = new MiniBindUser();
                     miniBindUser.setUserId(salesmanId)
                             .setOpenid(openId)
@@ -221,7 +220,6 @@ public class WechatCallbackController {
                             .setCreateTime(LocalDateTime.now());
                     miniBindUserService.save(miniBindUser);
                     log.info("用户关注服务号销售人员的二维码,绑定销售人员和用户id成功");
-
                 }
             }
         }
@@ -231,7 +229,7 @@ public class WechatCallbackController {
     private void handleUnsubscribe(String openId) {
 
         followMapper.delete(new QueryWrapper<WechatUserFollow>().eq("open_id", openId));
-//      customService.remove(new QueryWrapper<Custom>().eq("custom_name", openId));
+        customService.remove(new QueryWrapper<Custom>().eq("custom_name", openId));
         miniBindUserService.remove(new QueryWrapper<MiniBindUser>().eq("openid", openId));
         log.info("用户取消绑定销售人员成功");