Commit 1516a510 by zhiwj

自定义字段:时间

parent e82d074b
......@@ -5,6 +5,7 @@ import com.gic.api.base.commons.ServiceResponse;
import com.gic.store.dto.StoreTmpDTO;
import java.util.List;
import java.util.Map;
/**
* @author zhiwj
......@@ -44,4 +45,6 @@ public interface StoreImportApiService {
// List<StoreTmpDTO> listStoreTmp(Integer enterpriseId, Boolean isSuccess, Boolean isWait);
ServiceResponse<List<List<String>>> listImportTitle(Integer enterpriseId, Integer regionId);
ServiceResponse<Map<Integer, Boolean>> fieldIsDateType(Integer enterpriseId, Integer regionId);
}
......@@ -6,6 +6,7 @@ import com.gic.api.base.commons.Page;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.commons.util.EntityUtil;
import com.gic.commons.util.PageHelperUtils;
import com.gic.store.constant.StoreFieldTypeEnum;
import com.gic.store.dto.StoreExtendDTO;
import com.gic.store.dto.StoreTmpDTO;
import com.gic.store.entity.TabStoreBrand;
......@@ -20,10 +21,7 @@ import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
/**
......@@ -236,4 +234,16 @@ public class StoreImportApiServiceImpl implements StoreImportApiService {
return ServiceResponse.success(list);
}
@Override
public ServiceResponse<Map<Integer, Boolean>> fieldIsDateType(Integer enterpriseId, Integer regionId) {
HashMap<Integer, Boolean> map = new HashMap<>();
List<TabStoreField> fields = storeFieldService.listStoreFieldByRegionId(regionId);
if (CollectionUtils.isNotEmpty(fields)) {
for (int i = 0; i < fields.size(); i++) {
map.put(14 + i, fields.get(i).getStoreFieldType() == StoreFieldTypeEnum.DATE.getCode());
}
}
return ServiceResponse.success(map);
}
}
package com.gic.store.web;
import com.gic.store.constant.Constants;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.ss.usermodel.Cell;
......@@ -9,10 +10,8 @@ import org.apache.poi.xssf.usermodel.*;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* @author zhiwj
......@@ -268,16 +267,17 @@ public class ExcelUtils {
* @param fileType 文件的后缀 例如:xls xlsx
* @return
*/
public static List<Map<Integer, String>> readExcel(int row, String fileType, XSSFWorkbook xssfWorkbook) {
public static List<Map<Integer, String>> readExcel(int row, String fileType, XSSFWorkbook xssfWorkbook, Map<Integer, Boolean> dateTypeMap) {
if (fileType.equals("xlsx")) {
return readXlsx(xssfWorkbook, row);
return readXlsx(xssfWorkbook, row, dateTypeMap);
} else {
return null;
}
}
public static List<Map<Integer, String>> readXlsx(XSSFWorkbook xssfWorkbook, int row) {
public static List<Map<Integer, String>> readXlsx(XSSFWorkbook xssfWorkbook, int row, Map<Integer, Boolean> dateTypeMap) {
List<Map<Integer, String>> result = new ArrayList<Map<Integer, String>>();
SimpleDateFormat format = new SimpleDateFormat(Constants.dateformat);
// XSSFWorkbook xssfWorkbook = new XSSFWorkbook(in);
for (int numSheet = 0; numSheet < 1; numSheet++) {
XSSFSheet xssfSheet = xssfWorkbook.getSheetAt(numSheet);
......@@ -299,10 +299,17 @@ public class ExcelUtils {
if (xssfCell == null) {
map.put(colix, "");
} else {
if (xssfCell.getCellType() != Cell.CELL_TYPE_STRING) {
xssfCell.setCellType(Cell.CELL_TYPE_STRING);
Boolean isDate = dateTypeMap.get(colix);
if (isDate != null && isDate) {
Date date = xssfCell.getDateCellValue();
map.put(colix, format.format(date));
} else {
if (xssfCell.getCellType() != Cell.CELL_TYPE_STRING) {
xssfCell.setCellType(Cell.CELL_TYPE_STRING);
}
map.put(colix, xssfCell.getStringCellValue());
}
map.put(colix, xssfCell.getStringCellValue());
}
}
if (!isEmpty(map, minColix, maxColix)) {
......
......@@ -135,7 +135,8 @@ public class StoreImportController {
if (storeRegion == null) {
return RestResponse.failure(ErrorCode.ERR_5.getCode(), "门店域不存在");
}
List<Map<Integer, String>> data = ExcelUtils.readExcel(6, fileName.substring(fileName.lastIndexOf(".") + 1), workbook);
ServiceResponse<Map<Integer, Boolean>> isDateTypeMap = storeImportApiService.fieldIsDateType(enterpriseId, storeRegion.getRegionId());
List<Map<Integer, String>> data = ExcelUtils.readExcel(6, fileName.substring(fileName.lastIndexOf(".") + 1), workbook, isDateTypeMap.getResult());
ServiceResponse<List<List<String>>> titleServiceResponse = storeImportApiService.listImportTitle(enterpriseId, storeRegion.getRegionId());
List<String> titleList = titleServiceResponse.getResult().get(0);
// todo 这里在测试完成后放开
......@@ -388,24 +389,20 @@ public class StoreImportController {
ServiceResponse<List<ProvinceDTO>> provinceResponse = provincesApiService.selectAllProvince();
ServiceResponse<List<CityDTO>> cityResponse = provincesApiService.selectAllCity();
ServiceResponse<List<CountyDTO>> countyResponse = provincesApiService.selectAllCounty();
if (provinceResponse.isSuccess() && cityResponse.isSuccess() && countyResponse.isSuccess()) {
List<ProvinceDTO> provinceDTOList = provinceResponse.getResult();
long provinceCount = provinceDTOList.stream().filter(e -> StringUtils.equals(e.getProvinceName(), province)).count();
List<CityDTO> cityDTOList = cityResponse.getResult();
long cityCount = cityDTOList.stream().filter(e -> StringUtils.equals(e.getCityName(), city)).count();
List<CountyDTO> countyDTOList = countyResponse.getResult();
long countyCount = countyDTOList.stream().filter(e -> StringUtils.equals(e.getCountyName(), county)).count();
if (countyCount == 0) {
bean.setErrorMessage("输入的区县信息有误");
}
if (cityCount == 0) {
bean.setErrorMessage("输入的市信息有误");
}
if (provinceCount == 0) {
bean.setErrorMessage("输入的省信息有误");
}
} else {
logger.warn("省市区调用服务失败");
List<ProvinceDTO> provinceDTOList = provinceResponse.getResult();
long provinceCount = provinceDTOList.stream().filter(e -> StringUtils.equals(e.getProvinceName(), province)).count();
List<CityDTO> cityDTOList = cityResponse.getResult();
long cityCount = cityDTOList.stream().filter(e -> StringUtils.equals(e.getCityName(), city)).count();
List<CountyDTO> countyDTOList = countyResponse.getResult();
long countyCount = countyDTOList.stream().filter(e -> StringUtils.equals(e.getCountyName(), county)).count();
if (countyCount == 0) {
bean.setErrorMessage("输入的区县信息有误");
}
if (cityCount == 0) {
bean.setErrorMessage("输入的市信息有误");
}
if (provinceCount == 0) {
bean.setErrorMessage("输入的省信息有误");
}
}
// 验证门店详细地址
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment