Browse Source

客户查询修改

anderx 1 year ago
parent
commit
6fb87a5da8

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

@@ -66,5 +66,5 @@ public interface UserNamesMapper {
 	void insertBatch(List<InputUserChannel> list);
 
 
-    List<UserNamesListBo> selectUserNameList(List<InputExcelUser> list2);
+    List<InputExcelUser> selectUserNameList(List<InputExcelUser> list2);
 }

+ 3 - 3
src/main/java/com/goafanti/common/mapper/UserMapperExt.xml

@@ -1528,9 +1528,9 @@
 
     <select id="selectPrivateCustomerByName" parameterType="java.lang.String" resultType="com.goafanti.customer.bo.CustomerSimpleBo">
 		select b.id,b.nickname as name from
-			(select uid from user_lock_release  where type = 0  and status = 0 and aid = #{aid} group by uid) a
-		inner join user b on a.uid = b.id
-			where b.status = 0 and b.channel =0  and new_channel=0 and b.nickname like concat('%',#{name},'%')
+			 user b
+			where b.status = 0 and b.channel =0  and new_channel=0 and b.share_type=0
+			  and b.nickname like concat('%',#{name},'%')
     </select>
 
     <select id="selectSignedCustomerByName"  resultType="com.goafanti.customer.bo.CustomerSimpleBo">

+ 5 - 3
src/main/java/com/goafanti/common/mapper/UserNamesMapper.xml

@@ -152,9 +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
+  <select id="selectUserNameList" resultType="com.goafanti.customer.bo.InputExcelUser">
+    select a.name,b.share_type as  status,c.name aname
+    from user_names a left join user b on a.uid=b.id
+    left join admin c on b.aid =c.id
+    where a.name in
     <foreach item="item" index="index" collection="list" separator="," open="(" close=")">
         (#{item.name})
     </foreach>

+ 127 - 0
src/main/java/com/goafanti/common/utils/excel/NewExcelUtil.java

@@ -1126,7 +1126,134 @@ public class NewExcelUtil<T> {
 	{
 		return importExcel(StringUtils.EMPTY, is, titleNum);
 	}
+//
+	public List<T> importExcelSet( InputStream is, int titleNum) throws Exception {
+		this.type = Excel.Type.IMPORT;
+		this.wb = WorkbookFactory.create(is);
+		List<T> list = new ArrayList<T>();
+		Iterator<Sheet> sheetIterator = wb.sheetIterator();
+		while (sheetIterator.hasNext()) {
+			Sheet sheet = sheetIterator.next();
+			if (sheet == null) {
+				throw new IOException("文件sheet不存在");
+			}
+			boolean isXSSFWorkbook = !(wb instanceof HSSFWorkbook);
+			Map<String, PictureData> pictures;
+			if (isXSSFWorkbook) {
+				pictures = getSheetPictures07((XSSFSheet) sheet, (XSSFWorkbook) wb);
+			} else {
+				pictures = getSheetPictures03((HSSFSheet) sheet, (HSSFWorkbook) wb);
+			}
+			// 获取最后一个非空行的行下标,比如总行数为n,则返回的为n-1
+			int rows = sheet.getLastRowNum();
+
+			if (rows > 0) {
+				// 定义一个map用于存放excel列的序号和field.
+				Map<String, Integer> cellMap = new HashMap<String, Integer>();
+				// 获取表头
+				Row heard = sheet.getRow(titleNum);
+				for (int i = 0; i < heard.getPhysicalNumberOfCells(); i++) {
+					Cell cell = heard.getCell(i);
+					if (StringUtils.isNotNull(cell)) {
+						String value = this.getCellValue(heard, i).toString();
+						cellMap.put(value, i);
+					} else {
+						cellMap.put(null, i);
+					}
+				}
+				// 有数据时才处理 得到类的所有field.
+				List<Object[]> fields = this.getFields();
+				Map<Integer, Object[]> fieldsMap = new HashMap<Integer, Object[]>();
+				for (Object[] objects : fields) {
+					Excel attr = (Excel) objects[1];
+					Integer column = cellMap.get(attr.name());
+					if (column != null) {
+						fieldsMap.put(column, objects);
+					}
+				}
+				int errorCount = 0;
+				try {
+					for (int i = titleNum + 1; i <= rows; i++) {
+						errorCount = i + 1;
+						// 从第2行开始取数据,默认第一行是表头.
+						Row row = sheet.getRow(i);
+						// 判断当前行是否是空行
+						if (isRowEmpty(row)) {
+							continue;
+						}
+						T entity = null;
+						for (Map.Entry<Integer, Object[]> entry : fieldsMap.entrySet()) {
+							Object val = this.getCellValue(row, entry.getKey());
+
+							// 如果不存在实例则新建.
+							entity = (entity == null ? clazz.newInstance() : entity);
+							// 从map中得到对应列的field.
+							Field field = (Field) entry.getValue()[0];
+							Excel attr = (Excel) entry.getValue()[1];
+							// 取得类型,并根据对象类型设置值.
+							Class<?> fieldType = field.getType();
+							if (String.class == fieldType) {
+								String s = Convert.toStr(val);
+								if (StringUtils.endsWith(s, ".0")) {
+									val = StringUtils.substringBefore(s, ".0");
+								} else {
+									String dateFormat = field.getAnnotation(Excel.class).dateFormat();
+									if (StringUtils.isNotEmpty(dateFormat)) {
+										val = parseDateToStr(dateFormat, val);
+									} else {
+										val = Convert.toStr(val);
+									}
+								}
+							} else if ((Integer.TYPE == fieldType || Integer.class == fieldType) && StringUtils.isNumeric(Convert.toStr(val))) {
+								val = Convert.toInt(val);
+							} else if ((Long.TYPE == fieldType || Long.class == fieldType) && StringUtils.isNumeric(Convert.toStr(val))) {
+								val = Convert.toLong(val);
+							} else if (Double.TYPE == fieldType || Double.class == fieldType) {
+								val = Convert.toDouble(val);
+							} else if (Float.TYPE == fieldType || Float.class == fieldType) {
+								val = Convert.toFloat(val);
+							} else if (BigDecimal.class == fieldType) {
+								val = Convert.toBigDecimal(val);
+							} else if (Date.class == fieldType) {
+								if (val instanceof String) {
+									val = DateUtils.parseDate((String) val);
+								} else if (val instanceof Double) {
+									val = DateUtil.getJavaDate((Double) val);
+								}
+							} else if (Boolean.TYPE == fieldType || Boolean.class == fieldType) {
+								val = Convert.toBool(val, false);
+							}
+							if (StringUtils.isNotNull(fieldType)) {
+								String propertyName = field.getName();
+								if (StringUtils.isNotEmpty(attr.targetAttr())) {
+									propertyName = field.getName() + "." + attr.targetAttr();
+								} else if (StringUtils.isNotEmpty(attr.readConverterExp())) {
+									val = reverseByExp(Convert.toStr(val), attr.readConverterExp(), attr.separator());
+								} else if (!attr.handler().equals(ExcelHandlerAdapter.class)) {
+									val = dataFormatHandlerAdapter(val, attr);
+								} else if (ColumnType.IMAGE == attr.cellType() && StringUtils.isNotEmpty((CharSequence) pictures)) {
+									PictureData image = pictures.get(row.getRowNum() + "_" + entry.getKey());
+									if (image == null) {
+										val = "";
+									} else {
+										byte[] data = image.getData();
+										val = FileUtils.writeImportBytes(data);
+									}
+								}
+								ReflectUtils.invokeSetter(entity, propertyName, val);
+							}
+						}
 
+						list.add(entity);
+					}
+				} catch (Exception e) {
+					throw new BusinessException(String.format("表格第%s行内容错误,请检查修改后再上传。", errorCount));
+				}
+			}
+
+		}
+			return list;
+	}
 
 	/**
 	 * 对excel表单指定表格索引名转换成list

+ 18 - 7
src/main/java/com/goafanti/customer/bo/InputExcelUser.java

@@ -4,14 +4,17 @@ import com.goafanti.common.utils.excel.Excel;
 
 public class InputExcelUser {
 
-    @Excel(name = "客户名称")
+    @Excel(name = "企业名称")
     private String name;
-    @Excel(name = "联系方式")
-    private String phone;
 
     @Excel(name = "类型",readConverterExp = "0=无,1=已存在")
     private Integer type;
 
+    @Excel(name = "状态",readConverterExp = "0=私有,1=公共,2=签单")
+    private Integer status;
+    @Excel(name = "营销员")
+    private String aname;
+
     public Integer getType() {
         return type;
     }
@@ -28,11 +31,19 @@ public class InputExcelUser {
         this.name = name;
     }
 
-    public String getPhone() {
-        return phone;
+    public Integer getStatus() {
+        return status;
+    }
+
+    public void setStatus(Integer status) {
+        this.status = status;
+    }
+
+    public String getAname() {
+        return aname;
     }
 
-    public void setPhone(String phone) {
-        this.phone = phone;
+    public void setAname(String aname) {
+        this.aname = aname;
     }
 }

+ 10 - 6
src/main/java/com/goafanti/customer/service/impl/CustomerServiceImpl.java

@@ -3106,7 +3106,7 @@ public class CustomerServiceImpl extends BaseMybatisDao<UserMapper> implements C
 		NewExcelUtil<InputExcelUser> newExcelUtil=new NewExcelUtil<>(InputExcelUser.class);
 		List<InputExcelUser> list = null;
 		try {
-			list = newExcelUtil.importExcel(file.getInputStream(),0);
+			list = newExcelUtil.importExcelSet(file.getInputStream(),1);
 		} catch (Exception e) {
 			throw new BusinessException(e.getMessage());
 		}
@@ -3128,13 +3128,17 @@ public class CustomerServiceImpl extends BaseMybatisDao<UserMapper> implements C
 			i++;
 			list2.add(e);
 			if (list2.size()==100||i==list.size()){
-				List<UserNamesListBo> userNamesListBos = userNamesMapper.selectUserNameList(list2);
+				List<InputExcelUser> 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 (!userNamesListBos.isEmpty()){
+							for (InputExcelUser ex2 : userNamesListBos) {
+								if (ex2.getName()!=null&&excelUser!=null&&excelUser.getName()!=null){
+									if (ex2.getName().equals(excelUser.getName())){
+										excelUser.setType(1);
+										break;
+									}
+								}
 							}
 						}
 						if(excelUser.getType()==null){