Browse Source

新增线索客户导入

anderx 1 year ago
parent
commit
c00c887dcd

+ 20 - 5
src/main/java/com/goafanti/customer/controller/UserClueApiController.java

@@ -8,12 +8,11 @@ import com.goafanti.customer.bo.InputUserClueList;
 import com.goafanti.customer.bo.OutUserClueExcel;
 import com.goafanti.customer.service.UserClueService;
 import org.springframework.beans.factory.annotation.Value;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
+import java.util.List;
 
 @RestController
 @RequestMapping("/api/admin/userClue")
@@ -39,10 +38,26 @@ public class UserClueApiController extends BaseApiController{
 	 * 导出客户线索模版
 	 * @return
 	 */
+	@GetMapping("/import")
+	public Result importUserClue( @RequestParam(value = "file", required = false) MultipartFile file) {
+		NewExcelUtil<OutUserClueExcel> excelUtil=new NewExcelUtil<>(OutUserClueExcel.class);
+		List<OutUserClueExcel> list =null;
+        try {
+            list=excelUtil.importExcel(file.getInputStream(),1);
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+        return new Result().data(userClueService.importUserClue(list));
+	}
+
+	/**
+	 * 导出客户线索模版
+	 * @return
+	 */
 	@GetMapping("/exportTemplate")
 	public Result exportList( ) {
 		NewExcelUtil<OutUserClueExcel> excelUtil=new NewExcelUtil<>(OutUserClueExcel.class);
-		return excelUtil.exportExcel(null,"签单客户统计表",uploadPath);
+		return excelUtil.exportExcel(null,"客户线索模版",uploadPath);
 	}
 
 	/**

+ 5 - 0
src/main/java/com/goafanti/customer/service/UserClueService.java

@@ -2,9 +2,14 @@ package com.goafanti.customer.service;
 
 import com.goafanti.customer.bo.InputUserClueBo;
 import com.goafanti.customer.bo.InputUserClueList;
+import com.goafanti.customer.bo.OutUserClueExcel;
+
+import java.util.List;
 
 public interface UserClueService {
     Object list(InputUserClueList in);
 
     Object add(InputUserClueBo in);
+
+    Object importUserClue(List<OutUserClueExcel> list);
 }

+ 20 - 4
src/main/java/com/goafanti/customer/service/impl/UserClueServiceImpl.java

@@ -9,16 +9,14 @@ import com.goafanti.common.utils.PasswordUtil;
 import com.goafanti.core.mybatis.BaseMybatisDao;
 import com.goafanti.core.mybatis.page.Pagination;
 import com.goafanti.core.shiro.token.TokenManager;
-import com.goafanti.customer.bo.InputAddCustomer;
-import com.goafanti.customer.bo.InputUserClueBo;
-import com.goafanti.customer.bo.InputUserClueList;
-import com.goafanti.customer.bo.OutUserClueList;
+import com.goafanti.customer.bo.*;
 import com.goafanti.customer.service.CustomerService;
 import com.goafanti.customer.service.UserClueService;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
 import java.util.Date;
+import java.util.List;
 import java.util.UUID;
 
 @Service
@@ -129,6 +127,24 @@ public class UserClueServiceImpl extends BaseMybatisDao<UserMapper> implements U
         return 1;
     }
 
+    @Override
+    public Object importUserClue(List<OutUserClueExcel> list) {
+        StringBuilder msg = new StringBuilder();
+        for (OutUserClueExcel outUserClueExcel : list) {
+            InputUserClueBo inUserClueBo = new InputUserClueBo();
+            inUserClueBo.setUserName(outUserClueExcel.getNickname());
+            inUserClueBo.setContactMobile(outUserClueExcel.getContactMobile());
+            inUserClueBo.setContacts(outUserClueExcel.getContacts());
+            try {
+                add(inUserClueBo);
+            }catch (Exception e){
+                msg.append("客户").append(outUserClueExcel.getNickname()).append("新增失败");
+            }
+
+        }
+        return msg.toString();
+    }
+
     private void addUserTransferLog(User user) {
         UserTransferLog u = new UserTransferLog();
         u.setUid(user.getId());