Guo1B0 vor 10 Monaten
Ursprung
Commit
78a8ee8a6f

+ 80 - 16
fhKeeper/formulahousekeeper/management-crm/src/main/java/com/management/platform/controller/ClueController.java

@@ -1,20 +1,20 @@
 package com.management.platform.controller;
 
 
+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.Clue;
-import com.management.platform.entity.SysDict;
-import com.management.platform.entity.UploadFile;
-import com.management.platform.entity.User;
-import com.management.platform.mapper.ClueMapper;
-import com.management.platform.mapper.SysDictMapper;
-import com.management.platform.mapper.SysFunctionMapper;
-import com.management.platform.mapper.UserMapper;
-import com.management.platform.service.ClueService;
-import com.management.platform.service.SysFunctionService;
-import com.management.platform.service.UserService;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.management.platform.entity.*;
+import com.management.platform.entity.vo.ContactsVo;
+import com.management.platform.mapper.*;
+import com.management.platform.service.*;
 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.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 
@@ -53,6 +53,8 @@ public class ClueController {
 
     @Resource
     private SysDictMapper sysDictMapper;
+    @Autowired
+    private ExcelExportService excelExportService;
 
     @RequestMapping("getAll")
     public Object getAll(HttpServletRequest request) {
@@ -116,7 +118,7 @@ public class ClueController {
 
 
     @RequestMapping("listClue")
-    public Object list(Clue clue, HttpServletRequest request) {
+    public HttpRespMsg list(Clue clue, HttpServletRequest request) {
         User user = userMapper.selectById(request.getHeader("Token"));
         clue.setCompanyId(user.getCompanyId());
         clue.setIsDelete(0);
@@ -182,11 +184,73 @@ public class ClueController {
     public HttpRespMsg importData(MultipartFile multipartFile){
         return clueService.importData(multipartFile);
     }
-
-
+    @Value(value = "${upload.path}")
+    private String path;
+    @Autowired
+    private SysFormMapper sysFormMapper;
+    @Autowired
+    private WxCorpInfoService wxCorpInfoService;
     @RequestMapping("/exportData")
-    public HttpRespMsg exportData(Clue clue) throws Exception {
-        return clueService.exportData(clue);
+    public HttpRespMsg exportData(Clue clue ,HttpServletRequest request) throws Exception {
+        User user = userMapper.selectById(request.getHeader("token"));
+        SysForm sysForm = sysFormMapper.selectOne(new LambdaQueryWrapper<SysForm>().eq(SysForm::getCompanyId, user.getCompanyId()).eq(SysForm::getCode, "Thread").eq(SysForm::getIsCurrent, 1));
+        WxCorpInfo wxCorpInfo = wxCorpInfoService.getOne(new LambdaQueryWrapper<WxCorpInfo>().eq(WxCorpInfo::getCompanyId, user.getCompanyId()));
+        String config = sysForm.getConfig();
+        JSONObject configOb = JSON.parseObject(config);
+        JSONArray configObJSONArray = configOb.getJSONArray("list");
+        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(clue,request);
+        Map<String, Object> msgData = (Map<String, Object>) respMsg.getData();
+        List<Clue> list = (List<Clue>) msgData.get("data");
+
+        for (Clue 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 Clue> 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));
+                }
+                item.add(value);
+            }
+            dataList.add(item);
+        }
+        String fileName="线索表导出_"+ System.currentTimeMillis();
+        return excelExportService.exportGeneralExcelByTitleAndList(wxCorpInfo,fileName,dataList,path);
     }
 
 

+ 51 - 108
fhKeeper/formulahousekeeper/management-crm/src/main/java/com/management/platform/service/impl/ClueServiceImpl.java

@@ -37,6 +37,7 @@ import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.beans.Transient;
 import java.io.*;
+import java.lang.reflect.Field;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.math.BigDecimal;
@@ -398,16 +399,18 @@ public class ClueServiceImpl extends ServiceImpl<ClueMapper, Clue> implements Cl
     @Transactional(rollbackFor = Exception.class)
     public HttpRespMsg importData(MultipartFile multipartFile) {
         HttpRespMsg msg=new HttpRespMsg();
+        if(!multipartFile.getOriginalFilename().endsWith(".xlsx")){
+            msg.setError("文件格式错误,请使用.xlsx格式的Excel文件进行导入");
+            return msg;
+        }
         String fileName = multipartFile.getOriginalFilename();
         File file = new File(fileName == null ? "file" : fileName);
         User user = userMapper.selectById(request.getHeader("token"));
         Integer companyId = user.getCompanyId();
         WxCorpInfo wxCorpInfo = wxCorpInfoService.getOne(new LambdaQueryWrapper<WxCorpInfo>().eq(WxCorpInfo::getCompanyId, companyId));
-//        List<Clue> clueList = clueMapper.selectList(new LambdaQueryWrapper<Clue>().eq(Clue::getCompanyId, companyId));
         List<User> userList = userMapper.selectList(new LambdaQueryWrapper<User>().eq(User::getCompanyId, companyId));
-        List<SysDict> sysDictOfClueSources = sysDictMapper.selectList(new LambdaQueryWrapper<SysDict>().eq(SysDict::getCompanyId, companyId).eq(SysDict::getCode, "ClueSources"));
-        List<SysDict> sysDictOfCustomLevel = sysDictMapper.selectList(new LambdaQueryWrapper<SysDict>().eq(SysDict::getCompanyId, companyId).eq(SysDict::getCode, "CustomLevel"));
-        List<SysDict> sysDictOfCustomIndustry = sysDictMapper.selectList(new LambdaQueryWrapper<SysDict>().eq(SysDict::getCompanyId, companyId).eq(SysDict::getCode, "CustomIndustry"));
+        List<SysDict> sysDictOfProductType = sysDictMapper.selectList(new LambdaQueryWrapper<SysDict>().eq(SysDict::getCompanyId, companyId).eq(SysDict::getCode, "ClueSources"));
+        List<SysDict> sysDictOfProductUnit = sysDictMapper.selectList(new LambdaQueryWrapper<SysDict>().eq(SysDict::getCompanyId, companyId).eq(SysDict::getCode, "ProductUnit"));
         InputStream inputStream = null;
         OutputStream outputStream = null;
         try {
@@ -435,10 +438,28 @@ public class ClueServiceImpl extends ServiceImpl<ClueMapper, Clue> implements Cl
             String config = sysForm.getConfig();
             JSONObject configOb = JSON.parseObject(config);
             JSONArray configObJSONArray = configOb.getJSONArray("list");
-//            List<Clue> importClueList=new ArrayList<>();
+            //可能存在栅格布局的情况需要特殊处理
+            List<String> modelNameList=new ArrayList<>();
+            for (int i = 0; i < configObJSONArray.size(); i++) {
+                JSONObject jsonObject = configObJSONArray.getJSONObject(i);
+                if(jsonObject.getString("type").equals("grid")){
+                    JSONArray columns = jsonObject.getJSONArray("columns");
+                    for (int i1 = 0; i1 < columns.size(); i1++) {
+                        JSONObject columnsJSONObject = columns.getJSONObject(i1);
+                        JSONArray list = columnsJSONObject.getJSONArray("list");
+                        for (int i2 = 0; i2 < list.size(); i2++) {
+                            JSONObject object = list.getJSONObject(i2);
+                            modelNameList.add(object.getString("model"));
+                        }
+                    }
+                }else {
+                    modelNameList.add(jsonObject.getString("model"));
+                }
+            }
+            List<Clue>  importClueList =new ArrayList<>();
             List<String> userNameList=new ArrayList<>();
             HttpRespMsg respMsg=new HttpRespMsg();
-            for (int rowIndex = 0; rowIndex <= rowNum; rowIndex++) {
+            for (int rowIndex = 1; rowIndex <= rowNum; rowIndex++) {
                 XSSFRow row = sheet.getRow(rowIndex);
                 if (row == null) {
                     continue;
@@ -450,20 +471,9 @@ public class ClueServiceImpl extends ServiceImpl<ClueMapper, Clue> implements Cl
                 //获取到当前行的列数据
                 int cellNum = row.getLastCellNum();
                 for (int i = 0; i < cellNum; i++) {
-                    JSONObject item = configObJSONArray.getJSONObject(i);
-                    String modelName = item.getString("model");
+                    String modelName = modelNameList.get(i);
                     XSSFCell cell = row.getCell(i);
-                    if(cell!=null){
-                        switch (item.getString("type")){
-//                            case "time":cell.setCellType(CellType.NUMERIC);
-//                                break;
-                            default:cell.setCellType(CellType.STRING);
-                        }
-                    }
                     if(modelName.equals("inchargerId")){
-                        System.out.println("=====");
-                        System.out.println(modelName);
-                        System.out.println(cell.toString());
                         if(!StringUtils.isEmpty(cell.getStringCellValue())){
                             userNameList.add(cell.getStringCellValue());
                         }
@@ -471,7 +481,7 @@ public class ClueServiceImpl extends ServiceImpl<ClueMapper, Clue> implements Cl
 
                 }
             }
-            System.out.println("参与搜的人员列表"+userNameList + userNameList.size());
+            System.out.println("参与搜的人员列表"+userNameList + userNameList.size());
             if(wxCorpInfo!=null&&wxCorpInfo.getSaasSyncContact()==1&&userNameList.size()>0){
                 respMsg = wxCorpInfoService.getBatchSearchUserInfo(wxCorpInfo, userNameList,null);
                 if(respMsg.code.equals("0")){
@@ -494,7 +504,6 @@ public class ClueServiceImpl extends ServiceImpl<ClueMapper, Clue> implements Cl
                 int cellNum = row.getLastCellNum();
                 Clue clue =new Clue();
                 clue.setCompanyId(companyId);
-                clue.setCreateTime(new Date());
                 clue.setCreateId(user.getId());
                 for (int i = 0; i < cellNum; i++) {
                     JSONObject item = configObJSONArray.getJSONObject(i);
@@ -507,6 +516,7 @@ public class ClueServiceImpl extends ServiceImpl<ClueMapper, Clue> implements Cl
                         switch (item.getString("type")){
 //                            case "time":cell.setCellType(CellType.NUMERIC);
 //                                break;
+                            //默认读取所有数据都是文本格式
                             default:cell.setCellType(CellType.STRING);
                         }
                     }
@@ -520,7 +530,7 @@ public class ClueServiceImpl extends ServiceImpl<ClueMapper, Clue> implements Cl
                             return msg;
                         }
                     }
-                   if(modelName.equals("inchargerId")){
+                  if(modelName.equals("inchargerId")){
                         if(!StringUtils.isEmpty(cell.getStringCellValue())){
                             String userName = cell.getStringCellValue();
                             Optional<User> first;
@@ -537,119 +547,52 @@ public class ClueServiceImpl extends ServiceImpl<ClueMapper, Clue> implements Cl
                                 return msg;
                             }
                         }
-                    }else if(modelName.equals("customLevelId")){
+                    }else if(modelName.equals("clueSourceId")){
                         if(!StringUtils.isEmpty(cell.getStringCellValue())){
-                            Optional<SysDict> first = sysDictOfCustomLevel.stream().filter(s -> s.getName().equals(cell.getStringCellValue())).findFirst();
+                            Optional<SysDict> first = sysDictOfProductType.stream().filter(s -> s.getName().equals(cell.getStringCellValue())).findFirst();
                             if(first.isPresent()){
-                                clue.setCustomerLevelId(first.get().getId());
+                                clue.setClueSourceId(first.get().getId());
                             }else {
-                                throw new Exception("客户级别["+cell.getStringCellValue()+"不存在,请在系统字典中增加");
+                                msg.setError("线索来源["+cell.getStringCellValue()+"]不存在,请在系统字典中增加");
+                                return msg;
                             }
                         }
-                    }else if(modelName.equals("clueSourcesId")){
-                       if(!StringUtils.isEmpty(cell.getStringCellValue())){
-                           Optional<SysDict> first = sysDictOfClueSources.stream().filter(s -> s.getName().equals(cell.getStringCellValue())).findFirst();
-                           if(first.isPresent()){
-                               Integer id = first.get().getId();
-                               clue.setClueSourceId(id);
-                           }else {
-                               throw new Exception("线索来源["+cell.getStringCellValue()+"不存在,请在系统字典中增加");
-                           }
-                       }
-                   }else if(modelName.equals("customIndustryId")){
-                       if(!StringUtils.isEmpty(cell.getStringCellValue())){
-                           Optional<SysDict> first = sysDictOfCustomIndustry.stream().filter(s -> s.getName().equals(cell.getStringCellValue())).findFirst();
-                           if(first.isPresent()){
-                               clue.setCustomerIndustryId(first.get().getId());
-                           }else {
-                               throw new Exception("线索来源["+cell.getStringCellValue()+"不存在,请在系统字典中增加");
-                           }
-                       }
-                   }else {
+                    }else {
                         if(!StringUtils.isEmpty(cell.getStringCellValue())){
-                            Class<Clue> clueClass = Clue.class;
-                            Method method = clueClass.getMethod(setter,String.class);
-                            method.invoke(clue,cell.getStringCellValue());
+                            Class<Clue> ClueClass = Clue.class;
+                            Method method = ClueClass.getMethod(setter,String.class);
+                            method.invoke(cell,cell.getStringCellValue());
                         }
                     }
 
                 }
-                clueMapper.insert(clue);
+                importClueList.add(clue);
+            }
+            if(importClueList.size()>0){
+                if(!saveOrUpdateBatch(importClueList)){
+                    msg.setError("验证失败,请检验数据格式是否正确");
+                    return msg;
+                }
             }
         } catch (IOException | NoSuchMethodException e) {
             e.printStackTrace();
+            msg.setError("验证失败,请检验数据格式是否正确");
         } catch (IllegalAccessException e) {
             e.printStackTrace();
         } catch (InvocationTargetException e) {
             e.printStackTrace();
         } catch (Exception e) {
             e.printStackTrace();
-            msg.setError("验证失败");
+            msg.setError("验证失败,请检验数据格式是否正确");
             return msg;
         }
         return msg;
     }
 
+
     @Override
     public HttpRespMsg exportData(Clue clue) throws Exception {
-        User user = userMapper.selectById(request.getHeader("token"));
-        SysForm sysForm = sysFormMapper.selectOne(new LambdaQueryWrapper<SysForm>().eq(SysForm::getCompanyId, user.getCompanyId()).eq(SysForm::getCode, "Thread").eq(SysForm::getIsCurrent, 1));
-        WxCorpInfo wxCorpInfo = wxCorpInfoService.getOne(new LambdaQueryWrapper<WxCorpInfo>().eq(WxCorpInfo::getCompanyId, user.getCompanyId()));
-        String config = sysForm.getConfig();
-        JSONObject configOb = JSON.parseObject(config);
-        JSONArray configObJSONArray = configOb.getJSONArray("list");
-        List<List<String>> dataList=new ArrayList<>();
-        List<String> titleList=new ArrayList<>();
-        for (int i = 0; i < configObJSONArray.size(); i++) {
-            JSONObject item = configObJSONArray.getJSONObject(i);
-            titleList.add(item.getString("label"));
-        }
-        dataList.add(titleList);
-        List<Clue> list1 = getList(clue);
-        for (Clue clue1 : list1) {
-            List<String> item=new ArrayList<>();
-            for (int i = 0; i < configObJSONArray.size(); i++) {
-                JSONObject target = configObJSONArray.getJSONObject(i);
-                if(target.getString("type").equals("grid")){
-                    JSONArray columns = target.getJSONArray("columns");
-                    for (int i1 = 0; i1 < columns.size(); i1++) {
-                        JSONObject columnsJSONObject = columns.getJSONObject(i1);
-                        JSONArray list = columnsJSONObject.getJSONArray("list");
-                        for (int i2 = 0; i2 < list.size(); i2++) {
-                            JSONObject object = list.getJSONObject(i2);
-                            String model = object.getString("model");
-                            String targetName = model.substring(0, 1).toUpperCase() + model.substring(1);
-                            Class<? extends Clue> aClass = clue1.getClass();
-                            String value = String.valueOf(aClass.getMethod("get" + targetName).invoke(clue1)==null?"":aClass.getMethod("get" + targetName).invoke(clue1));
-                            if(model.equals("inchargerId")){
-                                if(wxCorpInfo!=null&&wxCorpInfo.getSaasSyncContact()==1){
-                                    value = "$userName"+String.valueOf(aClass.getMethod("getInchargerName").invoke(clue1))+"$";
-                                }else {
-                                    value = String.valueOf(aClass.getMethod("getInchargerName").invoke(clue1));
-                                }
-                            }
-                            item.add(value);
-                        }
-                    }
-                }else {
-                    String model = target.getString("model");
-                    String targetName = model.substring(0, 1).toUpperCase() + model.substring(1);
-                    Class<? extends Clue> aClass = clue1.getClass();
-                    String value = String.valueOf(aClass.getMethod("get" + targetName).invoke(clue1)==null?"":aClass.getMethod("get" + targetName).invoke(clue1));
-                    if(model.equals("inchargerId")){
-                        if(wxCorpInfo!=null&&wxCorpInfo.getSaasSyncContact()==1){
-                            value = "$userName"+String.valueOf(aClass.getMethod("getInchargerName").invoke(clue1))+"$";
-                        }else {
-                            value = String.valueOf(aClass.getMethod("getInchargerName").invoke(clue1));
-                        }
-                    }
-                    item.add(value);
-                }
-            }
-            dataList.add(item);
-        }
-        String fileName="线索表导出_"+ System.currentTimeMillis();
-        return excelExportService.exportGeneralExcelByTitleAndList(wxCorpInfo,fileName,dataList,path);
+       return  null;
     }
 
     @Override