瀏覽代碼

客户修改

Guo1B0 10 月之前
父節點
當前提交
6fdc4c1779

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

@@ -570,7 +570,7 @@ public class ClueServiceImpl extends ServiceImpl<ClueMapper, Clue> implements Cl
                         if(!StringUtils.isEmpty(cell.getStringCellValue())){
                             Optional<SysDict> first = sysIndutryId.stream().filter(s -> s.getName().equals(cell.getStringCellValue())).findFirst();
                             if(first.isPresent()){
-                                product.setClueSourceId(first.get().getId());
+                                product.setCustomerIndustryId(first.get().getId());
                             }else {
                                 msg.setError("客户行业["+cell.getStringCellValue()+"]不存在,请在系统字典中增加");
                                 return msg;
@@ -580,7 +580,7 @@ public class ClueServiceImpl extends ServiceImpl<ClueMapper, Clue> implements Cl
                         if(!StringUtils.isEmpty(cell.getStringCellValue())){
                             Optional<SysDict> first = levels.stream().filter(s -> s.getName().equals(cell.getStringCellValue())).findFirst();
                             if(first.isPresent()){
-                                product.setClueSourceId(first.get().getId());
+                                product.setCustomerLevelId(first.get().getId());
                             }else {
                                 msg.setError("客户级别["+cell.getStringCellValue()+"]不存在,请在系统字典中增加");
                                 return msg;
@@ -604,6 +604,14 @@ public class ClueServiceImpl extends ServiceImpl<ClueMapper, Clue> implements Cl
                     msg.setError("验证失败,请检验数据格式是否正确");
                     return msg;
                 }
+                for (Clue bo : importProductList) {
+                    ActionLog actionLog = new ActionLog();
+                    actionLog.setName("新增了商机");
+                    actionLog.setItemId(bo.getId());
+                    actionLog.setCode("clue");
+                    actionLog.setUserId(user.getId());
+                    actionLogMapper.insert(actionLog);
+                }
             }
         } catch (IOException | NoSuchMethodException e) {
             e.printStackTrace();

+ 131 - 64
fhKeeper/formulahousekeeper/management-crm/src/main/java/com/management/platform/service/impl/CustomServiceImpl.java

@@ -624,14 +624,21 @@ public class CustomServiceImpl extends ServiceImpl<CustomMapper, Custom> impleme
 
     @Override
     public HttpRespMsg importData(MultipartFile multipartFile) {
-        HttpRespMsg msg = new HttpRespMsg();
+        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<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> sysSources = sysDictMapper.selectList(new LambdaQueryWrapper<SysDict>().eq(SysDict::getCompanyId, companyId).eq(SysDict::getCode, "ClueSources"));
+        List<SysDict> sysIndutryId = sysDictMapper.selectList(new LambdaQueryWrapper<SysDict>().eq(SysDict::getCompanyId, companyId).eq(SysDict::getCode, "CustomIndustry"));
+        List<SysDict> levels = sysDictMapper.selectList(new LambdaQueryWrapper<SysDict>().eq(SysDict::getCompanyId, companyId).eq(SysDict::getCode, "CustomLevel"));
+
         InputStream inputStream = null;
         OutputStream outputStream = null;
         try {
@@ -652,16 +659,35 @@ public class CustomServiceImpl extends ServiceImpl<CustomMapper, Custom> impleme
             int rowNum = sheet.getLastRowNum();
             //获取当前表单模板 校验规则
             SysForm sysForm = sysFormMapper.selectOne(new LambdaQueryWrapper<SysForm>().eq(SysForm::getCode, "Customer").eq(SysForm::getCompanyId, companyId).eq(SysForm::getIsCurrent, 1));
-            if (sysForm == null) {
+            if(sysForm==null){
                 msg.setError("当前模块未配置自定义模板,需先完成配置");
                 return msg;
             }
             String config = sysForm.getConfig();
             JSONObject configOb = JSON.parseObject(config);
             JSONArray configObJSONArray = configOb.getJSONArray("list");
-            List<String> userNameList = new ArrayList<>();
-            HttpRespMsg respMsg = new HttpRespMsg();
-            for (int rowIndex = 0; rowIndex <= rowNum; rowIndex++) {
+            //可能存在栅格布局的情况需要特殊处理
+            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<Custom> importProductList = new ArrayList<>();
+            List<String> userNameList=new ArrayList<>();
+            HttpRespMsg respMsg=new HttpRespMsg();
+            for (int rowIndex = 1; rowIndex <= rowNum; rowIndex++) {
                 XSSFRow row = sheet.getRow(rowIndex);
                 if (row == null) {
                     continue;
@@ -673,37 +699,25 @@ public class CustomServiceImpl extends ServiceImpl<CustomMapper, Custom> impleme
                 //获取到当前行的列数据
                 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())) {
+                    if(modelName.equals("inchargerId")){
+                        if(!org.springframework.util.StringUtils.isEmpty(cell.getStringCellValue())){
                             userNameList.add(cell.getStringCellValue());
                         }
                     }
 
                 }
             }
-            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")) {
-                    msg.setError("姓名为[" + String.valueOf(respMsg.data) + "]的人员存在重复,请使用工号!");
+            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")){
+                    msg.setError("姓名为["+String.valueOf(respMsg.data)+"]的人员存在重复,请使用工号!");
                     return msg;
                 }
             }
-            List<User> targetUserList = (List<User>) respMsg.data;
+            List<User> targetUserList= (List<User>) respMsg.data;
             //直接忽略空行 从row1开始
             for (int rowIndex = 1; rowIndex <= rowNum; rowIndex++) {
                 XSSFRow row = sheet.getRow(rowIndex);
@@ -716,71 +730,124 @@ public class CustomServiceImpl extends ServiceImpl<CustomMapper, Custom> impleme
                 }
                 //获取到当前行的列数据
                 int cellNum = row.getLastCellNum();
-                Custom custom = new Custom();
-                custom.setCompanyId(companyId);
-                custom.setCreateTime(new Date());
-                custom.setCreatorId(user.getId());
+                Custom product=new Custom();
+                product.setCompanyId(companyId);
+                product.setCreatorId(user.getId());
+                product.setIsDelete(0);
+
+                product.setCreateTime(new Date());
+                JSONArray objects=new JSONArray();
+                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 jsonObject1 = columns.getJSONObject(i1).getJSONArray("list").getJSONObject(0);
+                            objects.add(jsonObject1);
+                        }
+                    }else {
+                        objects.add(jsonObject);
+                    }
+                }
                 for (int i = 0; i < cellNum; i++) {
-                    JSONObject item = configObJSONArray.getJSONObject(i);
+                    JSONObject item = objects.getJSONObject(i);
                     String modelName = item.getString("model");
                     String className = modelName.substring(0, 1).toUpperCase() + modelName.substring(1);
-                    String getter = "get" + className;
-                    String setter = "set" + className;
+                    String getter="get"+className;
+                    String setter="set"+className;
                     XSSFCell cell = row.getCell(i);
-                    if (cell != null) {
-                        switch (item.getString("type")) {
-
-                            default:
-                                cell.setCellType(CellType.STRING);
-                        }
-                    }
-                    //校验当前列是否为必填
-                    JSONObject options = item.getJSONObject("options");
-                    JSONObject rules = options.getJSONObject("rules");
-                    Boolean required = rules.getBoolean("required");
-                    if (required) {
-                        if (StringUtils.isEmpty(cell.getStringCellValue())) {
-                            msg.setError(item.getString("label") + "值不能为空值");
-                            return msg;
+                    if(cell!=null){
+                        switch (item.getString("type")){
+//                            case "time":cell.setCellType(CellType.NUMERIC);
+//                                break;
+                            //默认读取所有数据都是文本格式
+                            default:cell.setCellType(CellType.STRING);
                         }
                     }
-                    if (modelName.equals("inchargerId")) {
-                        if (!StringUtils.isEmpty(cell.getStringCellValue())) {
+                    if(modelName.equals("inchargerId")){
+                        if(!org.springframework.util.StringUtils.isEmpty(cell.getStringCellValue())){
                             String userName = cell.getStringCellValue();
                             Optional<User> first;
-                            if (wxCorpInfo != null && wxCorpInfo.getSaasSyncContact() == 1) {
+                            if(wxCorpInfo!=null&&wxCorpInfo.getSaasSyncContact()==1){
                                 Optional<User> optional = targetUserList.stream().filter(tl -> tl.getName().equals(userName)).findFirst();
-                                first = userList.stream().filter(u -> (u.getJobNumber() != null && u.getJobNumber().equals(userName)) || (optional.isPresent() && u.getCorpwxUserid() != null && u.getCorpwxUserid().equals(optional.get().getCorpwxUserid()))).findFirst();
-                            } else {
-                                first = userList.stream().filter(u -> u.getName().equals(userName) || (u.getJobNumber() != null && u.getJobNumber().equals(userName))).findFirst();
+                                first= userList.stream().filter(u ->(u.getJobNumber()!=null&&u.getJobNumber().equals(userName))||(optional.isPresent()&&u.getCorpwxUserid()!=null&&u.getCorpwxUserid().equals(optional.get().getCorpwxUserid()))).findFirst();
+                            }else {
+                                first= userList.stream().filter(u -> u.getName().equals(userName)||(u.getJobNumber()!=null&&u.getJobNumber().equals(userName))).findFirst();
                             }
                             if (first.isPresent()) {
-                                custom.setInchargerId(first.get().getId());
+                                product.setInchargerId(first.get().getId());
                             } else {
-                                msg.setError("负责人[" + userName + "]在系统中不存在");
+                                msg.setError("负责人["+userName+"]在系统中不存在");
                                 return msg;
                             }
                         }
-                    } else {
-                        if (!StringUtils.isEmpty(cell.getStringCellValue())) {
-                            Class<Clue> clueClass = Clue.class;
-                            Method method = clueClass.getMethod(setter, String.class);
-                            method.invoke(custom, cell.getStringCellValue());
+                    }else if(modelName.equals("customSourceId")){
+                        if(!StringUtils.isEmpty(cell.getStringCellValue())){
+                            Optional<SysDict> first = sysSources.stream().filter(s -> s.getName().equals(cell.getStringCellValue())).findFirst();
+                            if(first.isPresent()){
+                                product.setCustomSourceId(first.get().getId());
+                            }else {
+                                msg.setError("线索来源["+cell.getStringCellValue()+"]不存在,请在系统字典中增加");
+                                return msg;
+                            }
+                        }
+                    }else if(modelName.equals("customerIndustryId")){
+                        if(!StringUtils.isEmpty(cell.getStringCellValue())){
+                            Optional<SysDict> first = sysIndutryId.stream().filter(s -> s.getName().equals(cell.getStringCellValue())).findFirst();
+                            if(first.isPresent()){
+                                product.setCustomerIndustryId(first.get().getId());
+                            }else {
+                                msg.setError("客户行业["+cell.getStringCellValue()+"]不存在,请在系统字典中增加");
+                                return msg;
+                            }
+                        }
+                    }else if(modelName.equals("customerLevelId")){
+                        if(!StringUtils.isEmpty(cell.getStringCellValue())){
+                            Optional<SysDict> first = levels.stream().filter(s -> s.getName().equals(cell.getStringCellValue())).findFirst();
+                            if(first.isPresent()){
+                                product.setCustomerLevelId(first.get().getId());
+                            }else {
+                                msg.setError("客户级别["+cell.getStringCellValue()+"]不存在,请在系统字典中增加");
+                                return msg;
+                            }
+                        }
+                    }else {
+                        String stringCellValue = cell.getStringCellValue();
+                        System.out.println(stringCellValue+"=============");
+                        if(!StringUtils.isEmpty(cell.getStringCellValue())){
+                            Class<Custom> productClass = Custom.class;
+                            Method method = productClass.getMethod(setter,String.class);
+                            method.invoke(product,cell.getStringCellValue());
                         }
                     }
 
                 }
-                customMapper.insert(custom);
+                importProductList.add(product);
+            }
+            if(importProductList.size()>0){
+                if(!saveOrUpdateBatch(importProductList)){
+                    msg.setError("验证失败,请检验数据格式是否正确");
+                    return msg;
+                }
+                for (Custom bo : importProductList) {
+                    ActionLog actionLog = new ActionLog();
+                    actionLog.setName("新增了商机");
+                    actionLog.setItemId(bo.getId());
+                    actionLog.setCode("custom");
+                    actionLog.setUserId(user.getId());
+                    actionLogMapper.insert(actionLog);
+                }
             }
         } 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;