Guo1B0 10 ماه پیش
والد
کامیت
072c441be2

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

@@ -152,11 +152,11 @@ public class CustomServiceImpl extends ServiceImpl<CustomMapper, Custom> impleme
             actionLog.setUserId(user.getId());
             actionLog.setItemId(custom.getId());
             actionLogMapper.insert(actionLog);
-            if (custom.getCustomName() != null && custom.getCustomName()!="" &&custom.getTelPhone() !="" &&custom.getTelPhone()!=null){
+            if (custom.getCustomName() != null && custom.getCustomName() != "" && custom.getTelPhone() != "" && custom.getTelPhone() != null) {
                 Contacts contacts = contactsMapper.selectOne(new QueryWrapper<Contacts>().eq("name", custom.getCustomName()).eq("phone", custom.getTelPhone()));
-                if (contacts != null){
+                if (contacts != null) {
                     contacts.setCustomId(custom.getId());
-                    contactsMapper.update(contacts,new UpdateWrapper<Contacts>().eq("id",contacts.getId()));
+                    contactsMapper.update(contacts, new UpdateWrapper<Contacts>().eq("id", contacts.getId()));
                 }
             }
         }
@@ -228,40 +228,62 @@ public class CustomServiceImpl extends ServiceImpl<CustomMapper, Custom> impleme
 
     @Autowired
     private SalesOrderMapper salesOrderMapper;
+    @Autowired
+    private StageMapper stageMapper;
+
     @Override
     public HttpRespMsg getInfo(Custom custom, HttpServletRequest request) {
         Custom custom1 = customMapper.getInfo(custom.getId());
 
         // 附件列表
-        custom1.setFiles(uploadFileMapper.selectByInfoList("custom",custom1.getId()));
+        custom1.setFiles(uploadFileMapper.selectByInfoList("custom", custom1.getId()));
         //商机列表
-        custom1.setBusinessOpportunitys(businessOpportunityMapper.selectList(new QueryWrapper<BusinessOpportunity>().eq("customer_id",custom1.getId())));
+        List<BusinessOpportunity> bos = businessOpportunityMapper.selectList(new QueryWrapper<BusinessOpportunity>().eq("customer_id", custom1.getId()));
+        if (bos.size() >0){
+            List<Integer> sIds = bos.stream().map(BusinessOpportunity::getStageId).distinct().collect(Collectors.toList());
+            List<Stage> stages = stageMapper.selectList(new QueryWrapper<Stage>().in("id", sIds));
+            Map<Integer, String> stageValue =  stages.stream()
+                    .collect(Collectors.toMap(Stage::getId, Stage::getName));
+            custom1.setBusinessOpportunitys(bos);
+            for (BusinessOpportunity bo : bos) {
+                bo.setCustomerName(custom1.getCustomName());
+                bo.setStageValue(stageValue.get(bo.getStageId()));
+            }
+            List<String> userIds = bos.stream()
+                    .flatMap(bo -> {
+                        List<String> ids = new ArrayList<>();
+                        ids.add(bo.getInchargerId());
+                        ids.add(bo.getCreatorId());
+                        return ids.stream();
+                    })
+                    .distinct() // 去重
+                    .collect(Collectors.toList());
+            if (userIds.size()>0){
+                List<User> users = userMapper.selectList(new QueryWrapper<User>().in("id", userIds));
+                Map<String, String> userIdToNameMap = users.stream()
+                        .collect(Collectors.toMap(User::getId, User::getName));
+                for (BusinessOpportunity bo : bos) {
+                    bo.setInchargerName(userIdToNameMap.get(bo.getInchargerId()));
+                    bo.setCreatorName(userIdToNameMap.get(bo.getCreatorId()));
+                }
+            }
+        }
+        custom1.setBusinessOpportunitys(bos);
         //操作记录
         List<ActionLog> actionLogs = actionLogMapper.selectByInfoListCustom(custom.getId());
-//        List<String> userIds = actionLogs.stream().map(ActionLog::getUserId).collect(Collectors.toList());
-//        System.out.println(userIds.toString());
-//        List<User> ids = userMapper.selectList(new QueryWrapper<User>().in("id", userIds));
-//        for (ActionLog actionLog : actionLogs) {
-//            for (User id : ids) {
-//                if(actionLog.getUserId().equals(id)){
-//                    actionLog.setUserName(id.getName());
-//                }
-//            }
-//        }
         List<Task> tasks = taskMapper.selectList(new QueryWrapper<Task>().in("custom_id", custom1.getId()));
         custom1.setTasks(tasks);
         custom1.setActionLogs(actionLogs);
         //联系人
-        custom1.setContacts(contactsMapper.selectList((new QueryWrapper<Contacts>().eq("custom_id",custom1.getId()))));
+        custom1.setContacts(contactsMapper.selectList((new QueryWrapper<Contacts>().eq("custom_id", custom1.getId()))));
         //订单
-        custom1.setSalesOrders(salesOrderMapper.selectList((new QueryWrapper<SalesOrder>().eq("custom_id",custom1.getId()))));
+        custom1.setSalesOrders(salesOrderMapper.selectList((new QueryWrapper<SalesOrder>().eq("custom_id", custom1.getId()))));
         HttpRespMsg httpRespMsg = new HttpRespMsg();
         httpRespMsg.setData(custom1);
         return httpRespMsg;
     }
 
 
-
     @Override
     public HttpRespMsg getList(Custom custom, HttpServletRequest request) {
         User user = userMapper.selectById(request.getHeader("Token"));
@@ -269,7 +291,7 @@ public class CustomServiceImpl extends ServiceImpl<CustomMapper, Custom> impleme
         custom.setIsDelete(0);
         custom.setUserId(user.getId());
         custom.setEndTime(custom.getEndTime() + " 23:59:59");
-        custom.setPageIndex((custom.getPageIndex()-1) * custom.getPageFrom() );
+        custom.setPageIndex((custom.getPageIndex() - 1) * custom.getPageFrom());
         boolean isAll = sysFunctionService.hasPriviledge(user.getRoleId(), "查看全部客户");
         boolean isNotAll = sysFunctionService.hasPriviledge(user.getRoleId(), "查看负责部门客户");
         List<Custom> list = new ArrayList<>();
@@ -302,7 +324,7 @@ public class CustomServiceImpl extends ServiceImpl<CustomMapper, Custom> impleme
         custom.setIsDelete(1);
         custom.setUserId(user.getId());
         custom.setEndTime(custom.getEndTime() + " 23:59:59");
-        custom.setPageIndex((custom.getPageIndex()-1) * custom.getPageFrom() );
+        custom.setPageIndex((custom.getPageIndex() - 1) * custom.getPageFrom());
         boolean isAll = sysFunctionService.hasPriviledge(user.getRoleId(), "查看全部客户");
         boolean isNotAll = sysFunctionService.hasPriviledge(user.getRoleId(), "查看负责部门客户");
         List<Custom> list = new ArrayList<>();
@@ -331,6 +353,7 @@ public class CustomServiceImpl extends ServiceImpl<CustomMapper, Custom> impleme
 
     @Value(value = "${upload.file}")
     private String filePath;
+
     @Override
     public Object uploadFile(Custom custom, HttpServletRequest request, MultipartFile file) {
         User user = userMapper.selectById(request.getHeader("token"));
@@ -400,7 +423,7 @@ public class CustomServiceImpl extends ServiceImpl<CustomMapper, Custom> impleme
         try {
             ServletOutputStream os = response.getOutputStream();
             UploadFile uploadFile = uploadFileMapper.selectById(file.getId());
-            if (uploadFile == null ){
+            if (uploadFile == null) {
                 msg.setError("文件未找到");
                 return msg;
             }
@@ -416,7 +439,8 @@ public class CustomServiceImpl extends ServiceImpl<CustomMapper, Custom> impleme
             msg.setError(MessageUtils.message("file.error"));
             e.printStackTrace();
         }
-        return msg;    }
+        return msg;
+    }
 
     @Override
     public Object deleteFile(UploadFile file, HttpServletRequest request) {
@@ -424,7 +448,6 @@ public class CustomServiceImpl extends ServiceImpl<CustomMapper, Custom> impleme
         try {
             UploadFile uploadFile = uploadFileMapper.selectById(file.getId());
             uploadFileMapper.deleteById(uploadFile.getId());
-            String realName = uploadFile.getRealName();
             File file1 = new File(uploadFile.getPath());
             file1.delete();
             msg.setMsg("删除成功");
@@ -432,7 +455,8 @@ public class CustomServiceImpl extends ServiceImpl<CustomMapper, Custom> impleme
             e.printStackTrace();
             msg.setError("删除失败");
         }
-        return msg;    }
+        return msg;
+    }
 
     @Override
     public Object reFileName(UploadFile uploadFile, HttpServletRequest request) {
@@ -447,13 +471,13 @@ public class CustomServiceImpl extends ServiceImpl<CustomMapper, Custom> impleme
         User user = userMapper.selectById(request.getHeader("token"));
         Integer companyId = user.getCompanyId();
         HttpRespMsg msg = new HttpRespMsg();
-        msg.setData(customMapper.selectList(new QueryWrapper<Custom>().eq("company_id",companyId)));
+        msg.setData(customMapper.selectList(new QueryWrapper<Custom>().eq("company_id", companyId)));
         return msg;
     }
 
     @Override
     public Map<String, Object> getDataSummary(Integer companyId, String startDate, String endDate, String userId, List<String> targetUserIds) {
-        return customMapper.getDataSummary(companyId,startDate,endDate,userId,targetUserIds);
+        return customMapper.getDataSummary(companyId, startDate, endDate, userId, targetUserIds);
     }
 
     @Override
@@ -466,13 +490,13 @@ public class CustomServiceImpl extends ServiceImpl<CustomMapper, Custom> impleme
         HttpRespMsg msg = new HttpRespMsg();
         User user = userMapper.selectById(request.getHeader("token"));
         Integer companyId = user.getCompanyId();
-        if (exportType==1){//员工
-            List<UserVO> userVoList=userMapper.getCustomerTotalCount(startDate,endDate,userId,companyId);
-            if (userVoList!=null&&!userVoList.isEmpty()){
+        if (exportType == 1) {//员工
+            List<UserVO> userVoList = userMapper.getCustomerTotalCount(startDate, endDate, userId, companyId);
+            if (userVoList != null && !userVoList.isEmpty()) {
                 for (UserVO userVO : userVoList) {
-                    if (userVO.getCustomertotal()==0){
+                    if (userVO.getCustomertotal() == 0) {
                         userVO.setDealRate((double) 0);
-                    }else {
+                    } else {
                         double v = ((double) userVO.getCustomerDeal() / userVO.getCustomertotal());
                         String formattedValue = String.format("%.2f", v);
                         userVO.setDealRate(Double.parseDouble(formattedValue));
@@ -480,14 +504,14 @@ public class CustomServiceImpl extends ServiceImpl<CustomMapper, Custom> impleme
                 }
             }
             msg.setData(userVoList);
-        }else {
-            List<DepartmentVO> departmentVoList=departmentMapper.getCustomerTotalCount(startDate,endDate,departmentId,companyId);
-            if (departmentVoList!=null&&!departmentVoList.isEmpty()){
+        } else {
+            List<DepartmentVO> departmentVoList = departmentMapper.getCustomerTotalCount(startDate, endDate, departmentId, companyId);
+            if (departmentVoList != null && !departmentVoList.isEmpty()) {
                 for (DepartmentVO departmentVO : departmentVoList) {
-                    if (departmentVO.getCustomertotal()==0){
-                        departmentVO.setDealRate((double)0);
-                    }else {
-                        double v=((double) departmentVO.getCustomerDeal() /departmentVO.getCustomertotal());
+                    if (departmentVO.getCustomertotal() == 0) {
+                        departmentVO.setDealRate((double) 0);
+                    } else {
+                        double v = ((double) departmentVO.getCustomerDeal() / departmentVO.getCustomertotal());
                         String formattedValue = String.format("%.2f", v);
                         departmentVO.setDealRate(Double.parseDouble(formattedValue));
                     }
@@ -505,13 +529,13 @@ public class CustomServiceImpl extends ServiceImpl<CustomMapper, Custom> impleme
         User user = userMapper.selectById(request.getHeader("token"));
         Integer companyId = user.getCompanyId();
 
-        if (exportType==1) {//员工
-            List<UserVO> userVoList=userMapper.getCustomerTransferRate(startDate,endDate,userId,companyId);
-            if (userVoList!=null&&!userVoList.isEmpty()){
+        if (exportType == 1) {//员工
+            List<UserVO> userVoList = userMapper.getCustomerTransferRate(startDate, endDate, userId, companyId);
+            if (userVoList != null && !userVoList.isEmpty()) {
                 for (UserVO userVO : userVoList) {
-                    if (userVO.getNum()==0){
+                    if (userVO.getNum() == 0) {
                         userVO.setDealRate((double) 0);
-                    }else {
+                    } else {
                         double v = (double) userVO.getSaleNum() / userVO.getNum();
                         String formattedValue = String.format("%.2f", v);
                         userVO.setDealRate(Double.parseDouble(formattedValue));
@@ -520,14 +544,13 @@ public class CustomServiceImpl extends ServiceImpl<CustomMapper, Custom> impleme
                 }
             }
             msg.setData(userVoList);
-        }
-        else {//部门
-            List<DepartmentVO> departmentVoList=departmentMapper.getCustomerTransferRate(startDate,endDate,departmentId,companyId);
-            if (departmentVoList!=null&&!departmentVoList.isEmpty()){
+        } else {//部门
+            List<DepartmentVO> departmentVoList = departmentMapper.getCustomerTransferRate(startDate, endDate, departmentId, companyId);
+            if (departmentVoList != null && !departmentVoList.isEmpty()) {
                 for (DepartmentVO departmentVO : departmentVoList) {
-                    if (departmentVO.getNum()==0){
-                        departmentVO.setDealRate((double)0);
-                    }else {
+                    if (departmentVO.getNum() == 0) {
+                        departmentVO.setDealRate((double) 0);
+                    } else {
                         double v = (double) departmentVO.getSaleNum() / departmentVO.getNum();
                         String formattedValue = String.format("%.2f", v);
                         departmentVO.setDealRate(Double.parseDouble(formattedValue));
@@ -544,7 +567,7 @@ public class CustomServiceImpl extends ServiceImpl<CustomMapper, Custom> impleme
 
     @Override
     public HttpRespMsg importData(MultipartFile multipartFile) {
-        HttpRespMsg msg=new HttpRespMsg();
+        HttpRespMsg msg = new HttpRespMsg();
         String fileName = multipartFile.getOriginalFilename();
         File file = new File(fileName == null ? "file" : fileName);
         User user = userMapper.selectById(request.getHeader("token"));
@@ -572,15 +595,15 @@ 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();
+            List<String> userNameList = new ArrayList<>();
+            HttpRespMsg respMsg = new HttpRespMsg();
             for (int rowIndex = 0; rowIndex <= rowNum; rowIndex++) {
                 XSSFRow row = sheet.getRow(rowIndex);
                 if (row == null) {
@@ -596,33 +619,34 @@ public class CustomServiceImpl extends ServiceImpl<CustomMapper, Custom> impleme
                     JSONObject item = configObJSONArray.getJSONObject(i);
                     String modelName = item.getString("model");
                     XSSFCell cell = row.getCell(i);
-                    if(cell!=null){
-                        switch (item.getString("type")){
+                    if (cell != null) {
+                        switch (item.getString("type")) {
 //                            case "time":cell.setCellType(CellType.NUMERIC);
 //                                break;
-                            default:cell.setCellType(CellType.STRING);
+                            default:
+                                cell.setCellType(CellType.STRING);
                         }
                     }
-                    if(modelName.equals("inchargerId")){
+                    if (modelName.equals("inchargerId")) {
                         System.out.println("=====");
                         System.out.println(modelName);
                         System.out.println(cell.toString());
-                        if(!StringUtils.isEmpty(cell.getStringCellValue())){
+                        if (!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);
@@ -635,7 +659,7 @@ public class CustomServiceImpl extends ServiceImpl<CustomMapper, Custom> impleme
                 }
                 //获取到当前行的列数据
                 int cellNum = row.getLastCellNum();
-                Custom custom =new Custom();
+                Custom custom = new Custom();
                 custom.setCompanyId(companyId);
                 custom.setCreateTime(new Date());
                 custom.setCreatorId(user.getId());
@@ -643,47 +667,48 @@ public class CustomServiceImpl extends ServiceImpl<CustomMapper, Custom> impleme
                     JSONObject item = configObJSONArray.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")){
+                    if (cell != null) {
+                        switch (item.getString("type")) {
 
-                            default:cell.setCellType(CellType.STRING);
+                            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")+"值不能为空值");
+                    if (required) {
+                        if (StringUtils.isEmpty(cell.getStringCellValue())) {
+                            msg.setError(item.getString("label") + "值不能为空值");
                             return msg;
                         }
                     }
-                    if(modelName.equals("inchargerId")){
-                        if(!StringUtils.isEmpty(cell.getStringCellValue())){
+                    if (modelName.equals("inchargerId")) {
+                        if (!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());
                             } else {
-                                msg.setError("负责人["+userName+"]在系统中不存在");
+                                msg.setError("负责人[" + userName + "]在系统中不存在");
                                 return msg;
                             }
                         }
-                    }else {
-                        if(!StringUtils.isEmpty(cell.getStringCellValue())){
+                    } else {
+                        if (!StringUtils.isEmpty(cell.getStringCellValue())) {
                             Class<Clue> clueClass = Clue.class;
-                            Method method = clueClass.getMethod(setter,String.class);
-                            method.invoke(custom,cell.getStringCellValue());
+                            Method method = clueClass.getMethod(setter, String.class);
+                            method.invoke(custom, cell.getStringCellValue());
                         }
                     }