Ver código fonte

Excel导入客户名称批量查询开发

anderx 1 ano atrás
pai
commit
f6ca64b37d

+ 4 - 0
src/main/java/com/goafanti/common/dao/UserNamesMapper.java

@@ -1,6 +1,7 @@
 package com.goafanti.common.dao;
 
 import com.goafanti.common.model.UserNames;
+import com.goafanti.customer.bo.InputExcelUser;
 import com.goafanti.customer.bo.UserNamesListBo;
 import com.goafanti.user.bo.InputUserChannel;
 import org.apache.ibatis.annotations.Param;
@@ -63,4 +64,7 @@ public interface UserNamesMapper {
     List<UserNamesListBo> checkUserName( @Param("userName")String userName);
 
 	void insertBatch(List<InputUserChannel> list);
+
+
+    List<UserNamesListBo> selectUserNameList(List<InputExcelUser> list2);
 }

+ 7 - 0
src/main/java/com/goafanti/common/mapper/UserNamesMapper.xml

@@ -152,4 +152,11 @@
 		(#{item.uid,jdbcType=VARCHAR},#{item.userName})
     </foreach>
   </insert>
+  <select id="selectUserNameList" resultType="com.goafanti.customer.bo.UserNamesListBo">
+    select id,uid,aid,name
+    from user_names where name in
+    <foreach item="item" index="index" collection="list" separator="," open="(" close=")">
+        (#{item.name})
+    </foreach>
+  </select>
 </mapper>

+ 38 - 0
src/main/java/com/goafanti/customer/bo/InputExcelUser.java

@@ -0,0 +1,38 @@
+package com.goafanti.customer.bo;
+
+import com.goafanti.common.utils.excel.Excel;
+
+public class InputExcelUser {
+
+    @Excel(name = "客户名称")
+    private String name;
+    @Excel(name = "联系方式")
+    private String phone;
+
+    @Excel(name = "类型",readConverterExp = "0=无,1=已存在")
+    private Integer type;
+
+    public Integer getType() {
+        return type;
+    }
+
+    public void setType(Integer type) {
+        this.type = type;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getPhone() {
+        return phone;
+    }
+
+    public void setPhone(String phone) {
+        this.phone = phone;
+    }
+}

+ 26 - 0
src/main/java/com/goafanti/customer/controller/AdminCustomerApiController.java

@@ -25,7 +25,9 @@ import org.springframework.validation.BindingResult;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
@@ -1586,4 +1588,28 @@ public class AdminCustomerApiController extends BaseApiController{
 	public Result selectUserLastSignExport (InputSelectUserLastSignBo in){
 		return customerService.selectUserLastSignExport(in);
 	}
+
+
+	/**
+	 * 	Excel批量导入
+	 *
+	 * @return
+	 */
+	@RequestMapping(value = "/importExcel" , method = RequestMethod.POST)
+	public Result importExcel(@RequestParam(value = "file", required = false) MultipartFile file) {
+		Result res=new Result();
+		//判断文件是否存在
+		if(null == file){
+			res.getError().add(buildError("文件不存在!","文件不存在!"));
+			return res;
+		}
+		String fileName = file.getOriginalFilename();
+		if (!fileName.matches("^.+\\.(?i)(xls)$") && !fileName.matches("^.+\\.(?i)(xlsx)$")) {
+			res.getError().add(buildError("格式不正确","格式不正确"));
+			return res;
+		}
+//		res.data(rdService.batchList(file));
+		res.data(customerService.importExcel(file));
+		return res;
+	}
 }

+ 3 - 0
src/main/java/com/goafanti/customer/service/CustomerService.java

@@ -10,6 +10,7 @@ import com.goafanti.common.model.User;
 import com.goafanti.core.mybatis.page.Pagination;
 import com.goafanti.customer.bo.*;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.springframework.web.multipart.MultipartFile;
 
 import java.text.ParseException;
 import java.util.Date;
@@ -584,4 +585,6 @@ public interface CustomerService {
 	void updateAdminUserCountByAid(String aid);
 
 	AdminUserCount getAdminUserCount(String aid, String startTime);
+
+    Object importExcel(MultipartFile file);
 }

+ 47 - 1
src/main/java/com/goafanti/customer/service/impl/CustomerServiceImpl.java

@@ -28,6 +28,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.multipart.MultipartFile;
 import org.springframework.web.socket.TextMessage;
 
 import javax.annotation.Resource;
@@ -534,7 +535,9 @@ public class CustomerServiceImpl extends BaseMybatisDao<UserMapper> implements C
 		return selectAUC;
 	}
 
-	private void checkUserName(InputAddCustomer in) {
+
+
+    private void checkUserName(InputAddCustomer in) {
 		if (!userMapper.checkUser("", in.getName(), "", in.getType(), null, null).isEmpty())
 			throw new BusinessException(new Error(ErrorConstants.CUSTOMER_ALREADY_EXIST, in.getName(), ""));
 		String name2=null;
@@ -3046,6 +3049,49 @@ public class CustomerServiceImpl extends BaseMybatisDao<UserMapper> implements C
 		}
 		return param;
 	}
+	@Override
+	public Object importExcel(MultipartFile file) {
+		NewExcelUtil<InputExcelUser> newExcelUtil=new NewExcelUtil<>(InputExcelUser.class);
+		List<InputExcelUser> list = null;
+		try {
+			list = newExcelUtil.importExcel(file.getInputStream(),0);
+		} catch (Exception e) {
+			throw new BusinessException(e.getMessage());
+		}
+		return pushUserName(list);
+	}
+
+	private Object pushUserName(List<InputExcelUser> list) {
+		List<InputExcelUser> res=new ArrayList<>();
+		List<InputExcelUser> list2=new ArrayList<>();
+		int i = 0;
+		for (InputExcelUser e : list) {
+			i++;
+			list2.add(e);
+			if (list2.size()==100||i==list.size()){
+				List<UserNamesListBo> userNamesListBos = userNamesMapper.selectUserNameList(list2);
+				if (!userNamesListBos.isEmpty()){
+					for (InputExcelUser excelUser : list2) {
+						for (UserNamesListBo ex2 : userNamesListBos) {
+							if (ex2.getName().equals(excelUser.getName())){
+								excelUser.setType(1);
+								break;
+							}
+						}
+						if(excelUser.getType()==null){
+							excelUser.setType(0);
+						}
+						if (excelUser.getType()==1){
+							res.add(excelUser);
+						}
 
+					}
+				}
+				list2.clear();
+			}
+
+		}
+		return res;
+	}
 
 }

+ 5 - 5
src/main/resources/props/config_local.properties

@@ -4,13 +4,13 @@ jdbc.driverClassName=com.mysql.jdbc.Driver
 static.host=//static.jishutao.com/1.3.14
 #static.host=//172.16.1.187/1.3.14
 
-#jdbc.url=jdbc\:mysql://localhost:3306/aft20221026?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false
+jdbc.url=jdbc\:mysql://localhost:3306/aft20240430?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false
 #jdbc.url=jdbc\:mysql://localhost:3306/aft?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false
-#jdbc.username=root
-#jdbc.password=123456
-jdbc.url=jdbc:mysql://101.37.32.31:3306/aft?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false
 jdbc.username=root
-jdbc.password=aftdev
+jdbc.password=123456
+#jdbc.url=jdbc:mysql://101.37.32.31:3306/aft?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false
+#jdbc.username=root
+#jdbc.password=aftdev
 jdbc.validationQuery=SELECT 'x'
 jdbc.initialSize=3
 jdbc.maxActive=20