Kaynağa Gözat

商机面板调整1

yusm 5 ay önce
ebeveyn
işleme
d4f1a573f8

+ 15 - 5
fhKeeper/formulahousekeeper/management-crm/src/main/java/com/management/platform/controller/BusinessOpportunityController.java

@@ -12,6 +12,7 @@ import com.management.platform.mapper.*;
 import com.management.platform.service.*;
 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.web.bind.annotation.RequestBody;
@@ -24,6 +25,8 @@ import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.text.SimpleDateFormat;
+import java.time.LocalDate;
+import java.time.format.DateTimeFormatter;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -153,11 +156,11 @@ public class BusinessOpportunityController {
                     value = String.valueOf(aClass.getMethod("getCustomerName").invoke(data));
                 }
                 if(model.equals("expectedTransactionDate")){
-                    Date date = (Date) aClass.getMethod("getExpectedTransactionDate").invoke(data);
+                    LocalDate date = (LocalDate) aClass.getMethod("getExpectedTransactionDate").invoke(data);
                     // 如果日期不为空,格式化日期
                     if (date != null) {
-                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
-                        value = sdf.format(date);
+                        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd");
+                        value = date.format(formatter);
                     } else {
                         value = "";
                 }                }
@@ -268,7 +271,14 @@ public class BusinessOpportunityController {
     public Object claim(BusinessOpportunity bo, HttpServletRequest request) {
         User user = userMapper.selectById(request.getHeader("Token"));
         HttpRespMsg msg = new HttpRespMsg();
-        msg.setMsg("操作成功");
+        String[] strings = bo.getIds().split(",");
+        for (String id : strings) {
+            BusinessOpportunity opportunity = boMapper.selectById(id);
+            if (StringUtils.isEmpty(opportunity.getInchargerId())){
+                msg.setError("商机:"+opportunity.getName()+"未被认领不能转移");
+                return msg;
+            }
+        }
         bOservice.getAndTransfer(bo, user);
         return msg;
     }
@@ -425,7 +435,7 @@ public class BusinessOpportunityController {
 
         List<HashMap<String, Object>> mapList = new ArrayList<>();
         for (Stage stage : stageList) {
-            List<BusinessOpportunity> collect = list.stream().filter(l -> l.getStageId() != null && l.getStageId().equals(stage.getId())).collect(Collectors.toList());
+            List<BusinessOpportunity> collect = list.stream().filter(l -> l.getStageId() != null && l.getStageId().equals(stage.getId())&& l.getSeq()!=null).collect(Collectors.toList());
             collect=collect.stream().sorted(Comparator.comparing(BusinessOpportunity::getSeq)).collect(Collectors.toList());
             HashMap<String, Object> map = new HashMap<>();
             map.put("id", stage.getId());

+ 4 - 3
fhKeeper/formulahousekeeper/management-crm/src/main/java/com/management/platform/entity/BusinessOpportunity.java

@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.annotation.TableId;
 import java.math.BigDecimal;
 import com.baomidou.mybatisplus.annotation.TableField;
 import java.io.Serializable;
+import java.time.LocalDate;
 import java.util.Date;
 import java.util.List;
 
@@ -80,9 +81,9 @@ public class BusinessOpportunity extends Model<BusinessOpportunity> {
      * 预计成交日期
      */
     @TableField("expected_transaction_date")
-    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
-    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
-    private Date expectedTransactionDate;
+    @DateTimeFormat(pattern = "yyyy-MM-dd")
+    @JsonFormat(pattern = "yyyy-MM-dd")
+    private LocalDate expectedTransactionDate;
 
     /**
      * 商机阶段

+ 28 - 14
fhKeeper/formulahousekeeper/management-crm/src/main/java/com/management/platform/service/impl/BusinessOpportunityServiceImpl.java

@@ -40,8 +40,11 @@ import java.math.BigDecimal;
 import java.net.URLEncoder;
 import java.text.SimpleDateFormat;
 import java.time.LocalDate;
+import java.time.LocalDateTime;
 import java.time.ZoneId;
+import java.time.ZonedDateTime;
 import java.util.*;
+import java.util.concurrent.atomic.AtomicInteger;
 import java.util.stream.Collectors;
 
 
@@ -613,32 +616,28 @@ public class BusinessOpportunityServiceImpl extends ServiceImpl<BusinessOpportun
                     }else if(modelName.equals("contactsId")){
                         if(!StringUtils.isEmpty(cell.getStringCellValue())){
                             Optional<Contacts> first = contacts.stream().filter(s -> s.getName().equals(cell.getStringCellValue())).findFirst();
-                            product.setContactsId(first.get().getId());
+                            product.setContactsId(first.map(Contacts::getId).orElse(null));
                         }
                     }else if(modelName.equals("customerId")){
                         if(!StringUtils.isEmpty(cell.getStringCellValue())){
                             Optional<Custom> first = customs.stream().filter(s -> s.getCustomName().equals(cell.getStringCellValue())).findFirst();
-                            product.setCustomerId(first.get().getId());
+                            product.setCustomerId(first.map(Custom::getId).orElse(null));
                         }
                     }else if(modelName.equals("expectedTransactionDate")){
                         if(cell != null && cell.getCellTypeEnum() != CellType.BLANK){
                             if(!org.apache.commons.lang3.StringUtils.isEmpty(cell.getStringCellValue())){
                                 try {
-                                    // 假设 cell 是一个代表 Excel 单元格的对象
-                                    String dateString = cell.getStringCellValue();
+                                    int count = Integer.parseInt(cell.getStringCellValue());
+                                    // Excel中的日期序列号的基准日期是1900年1月1日
+                                    LocalDate baseDate = LocalDate.of(1900, 1, 1);
+                                    LocalDate date = baseDate.plusDays(count - 2);
 
-                                    // 定义日期格式
-                                    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
-
-                                    // 解析字符串为 Date 类型
-                                    Date parsedDate = dateFormat.parse(dateString);
-
-                                    // 设置到对象中
-                                    product.setExpectedTransactionDate(parsedDate);
+                                    // 将 ZonedDateTime 转换为 Date
+                                    product.setExpectedTransactionDate(date);
 
                                 } catch (Exception e) {
-                                    System.out.println("日期时间格式不正确, 应该是yyyy/MM/dd");
-                                    msg.setError("日期时间格式不正确, 应该是yyyy/MM/dd");
+                                    System.out.println("日期时间格式不正确,应该是yyyy/MM/dd" );
+                                    msg.setError("日期时间格式不正确,应该是yyyy/MM/dd");
                                     return msg;
                                 }
                             }
@@ -655,6 +654,21 @@ public class BusinessOpportunityServiceImpl extends ServiceImpl<BusinessOpportun
                 importProductList.add(product);
             }
             if(importProductList.size()>0){
+                List<Integer> stageIds = importProductList.stream().map(BusinessOpportunity::getStageId).filter(Objects::nonNull).distinct().collect(Collectors.toList());
+                for (Integer stageId : stageIds) {
+                    List<BusinessOpportunity> list = bOMapper.selectList(new QueryWrapper<BusinessOpportunity>().eq("stage_id", stageId).eq("is_delete", 0).orderByDesc("seq").last(" limit 1"));
+                    AtomicInteger seq = new AtomicInteger(0); // 使用 AtomicInteger
+                    if (!list.isEmpty()){
+                        seq.set(list.get(0).getSeq());
+                    }
+                    importProductList.forEach(l->{
+                        if (l.getStageId().equals(stageId)){
+                            seq.incrementAndGet();
+                            l.setSeq(seq.get());
+                        }
+                    });
+                }
+
                 if(!saveOrUpdateBatch(importProductList)){
                     msg.setError("验证失败,请检验数据格式是否正确");
                     return msg;

+ 7 - 4
fhKeeper/formulahousekeeper/management-crm/src/main/java/com/management/platform/service/impl/ContactsServiceImpl.java

@@ -744,7 +744,8 @@ public class ContactsServiceImpl extends ServiceImpl<ContactsMapper, Contacts> i
                 Integer contactsId = businessOpportunity.getContactsId();
                 mgs.setData(contactsMapper.selectList(new QueryWrapper<Contacts>()
                         .eq("company_id",user.getCompanyId())
-                        .eq("id",contactsId)));
+                        .eq("id",contactsId)
+                        .eq("is_delete",0)));
             }
         }else if(salesId!=null){
             //要找销售订单对应的客户,然后再找客户对应的联系人
@@ -755,16 +756,18 @@ public class ContactsServiceImpl extends ServiceImpl<ContactsMapper, Contacts> i
                 Integer contactsId = salesOrder.getCustomId();
                 mgs.setData(contactsMapper.selectList(new QueryWrapper<Contacts>()
                         .eq("company_id",user.getCompanyId())
-                        .eq("custom_id",contactsId)));
+                        .eq("custom_id",contactsId)
+                        .eq("is_delete",0)));
             }
 
         }
         else if (customerId!=null){
             mgs.setData(contactsMapper.selectList(new QueryWrapper<Contacts>()
                     .eq("company_id",user.getCompanyId())
-                    .eq("custom_id",customerId)));
+                    .eq("custom_id",customerId)
+                    .eq("is_delete",0)));
         }else
-            mgs.setData(contactsMapper.selectList(new QueryWrapper<Contacts>().eq("company_id",user.getCompanyId())));
+            mgs.setData(contactsMapper.selectList(new QueryWrapper<Contacts>().eq("company_id",user.getCompanyId()).eq("is_delete",0)));
         return mgs;
     }
 

+ 10 - 14
fhKeeper/formulahousekeeper/management-crm/src/main/resources/mapper/BusinessOpportunityMapper.xml

@@ -39,8 +39,7 @@
         (select custom_name from custom where id = customer_id) customerName,
         (select `name` from contacts where id = contacts_id) contactsName,
         (select `name` from `user` where id = incharger_id) inchargerName,
-        (select `name` from `user` where id = creator_id) creatorName,
-        (SELECT sum(total) from business_product WHERE business_id = id) total
+        (select `name` from `user` where id = creator_id) creatorName
         from business_opportunity
         where company_id = #{companyId}
         and is_delete = #{isDelete}
@@ -63,7 +62,7 @@
             and stage_id = #{stageId}
         </if>
         <if test="productId != null ">
-            and id in (select business_id from business_product where product_id = #{productId})
+            and id in (select business_id from business_item_product where product_id = #{productId})
         </if>
         ORDER BY id DESC
         <if test="pageIndex!=null and pageFrom !=null">
@@ -96,7 +95,7 @@
             and stage_id = #{stageId}
         </if>
         <if test="productId != null ">
-            and id in (select business_id from business_product where product_id = #{productId})
+            and id in (select business_id from business_item_product where product_id = #{productId})
         </if>
     </select>
     <select id="selectAllList1" resultType="com.management.platform.entity.BusinessOpportunity">
@@ -106,8 +105,7 @@
         (select custom_name from custom where id = customer_id) customerName,
         (select `name` from contacts where id = contacts_id) contactsName,
         (select `name` from `user` where id = incharger_id) inchargerName,
-        (select `name` from `user` where id = creator_id) creatorName,
-        (SELECT sum(total) from business_product WHERE business_id = id)
+        (select `name` from `user` where id = creator_id) creatorName
         from business_opportunity
         where company_id = #{bo.companyId}
         and is_delete = #{bo.isDelete}
@@ -133,7 +131,7 @@
             and stage_id = #{bo.stageId}
         </if>
         <if test="bo.productId != null ">
-            and id in (select business_id from business_product where product_id = #{bo.productId})
+            and id in (select business_id from business_item_product where product_id = #{bo.productId})
         </if>
         ORDER BY id DESC
         <if test="bo.pageIndex!=null and bo.pageFrom !=null">
@@ -168,7 +166,7 @@
             and stage_id = #{bo.stageId}
         </if>
         <if test="bo.productId != null ">
-            and id in (select business_id from business_product where product_id = #{bo.productId})
+            and id in (select business_id from business_item_product where product_id = #{bo.productId})
         </if>
     </select>
     <select id="selectAllList2" resultType="com.management.platform.entity.BusinessOpportunity">
@@ -178,8 +176,7 @@
         (select custom_name from custom where id = customer_id) customerName,
         (select `name` from contacts where id = contacts_id) contactsName,
         (select `name` from `user` where id = incharger_id) inchargerName,
-        (select `name` from `user` where id = creator_id) creatorName,
-        (SELECT sum(total) from business_product WHERE business_id = id)
+        (select `name` from `user` where id = creator_id) creatorName
         from business_opportunity
         where company_id = #{bo.companyId}
         and is_delete = #{bo.isDelete}
@@ -203,7 +200,7 @@
             and stage_id = #{bo.stageId}
         </if>
         <if test="bo.productId != null ">
-            and id in (select business_id from business_product where product_id =#{bo.productId})
+            and id in (select business_id from business_item_product where product_id =#{bo.productId})
         </if>
         ORDER BY id DESC
         <if test="bo.pageIndex!=null and bo.pageFrom !=null">
@@ -236,7 +233,7 @@
             and stage_id = #{bo.stageId}
         </if>
         <if test="bo.productId != null ">
-            and id in (select business_id from business_product where product_id = #{bo.productId})
+            and id in (select business_id from business_item_product where product_id = #{bo.productId})
         </if>
     </select>
     <select id="selectByIdToInfo" resultType="com.management.platform.entity.BusinessOpportunity">
@@ -245,8 +242,7 @@
                (select custom_name from custom where id = customer_id) customerName,
                (select `name` from contacts where id = contacts_id)    contactsName,
                (select `name` from `user` where id = incharger_id)      inchargerName,
-               (select `name` from `user` where id = creator_id)       creatorName,
-               (SELECT sum(total) from business_product WHERE business_id = id)
+               (select `name` from `user` where id = creator_id)       creatorName
         from business_opportunity
         where id = #{id}
     </select>