增加分区功能
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package com.ruoyi.price.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
/** Zone under bms_region: prc_zone */
|
||||
@Data
|
||||
public class PrcZone implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Long zoneId;
|
||||
private Long regionId;
|
||||
/** ISO2 country code stored on prc_zone */
|
||||
private String countryCode;
|
||||
private String zoneCode;
|
||||
private String zoneName;
|
||||
private Integer zoneSort;
|
||||
private String remark;
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date createTime;
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date updateTime;
|
||||
/** list display, not a table column */
|
||||
private Integer detailCount;
|
||||
/** list display from bms_region */
|
||||
private String countryNameCn;
|
||||
}
|
||||
+5
-6
@@ -5,16 +5,15 @@ import java.util.Date;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
/** 分区国家 xtd_zonecountry */
|
||||
/** Zone postcode detail prc_zone_detail */
|
||||
@Data
|
||||
public class XtdZoneCountry implements Serializable
|
||||
public class PrcZoneDetail implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Long zcId;
|
||||
private Long zdId;
|
||||
private String countryCode;
|
||||
private String zcDividekind;
|
||||
private Long detailId;
|
||||
private Long zoneId;
|
||||
private String postcode;
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date createTime;
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.ruoyi.price.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* Zone country list row: bms_region + zone aggregates (not a table)
|
||||
*/
|
||||
@Data
|
||||
public class PrcZoneRegion implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Long regionId;
|
||||
private String countryNameCn;
|
||||
private String countryNameEn;
|
||||
private String countryCode2;
|
||||
private String status;
|
||||
private Integer zoneCount;
|
||||
private Integer detailCount;
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package com.ruoyi.price.domain;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
/** 分区区划 xtd_zone_division */
|
||||
@Data
|
||||
public class XtdZoneDivision implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Long zdId;
|
||||
private Long zsId;
|
||||
private Integer zdSort;
|
||||
private String zdCode;
|
||||
private String znName;
|
||||
private String znEname;
|
||||
private String znNote;
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date createTime;
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date updateTime;
|
||||
/** 列表展示,非表字段 */
|
||||
private Integer countryCount;
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package com.ruoyi.price.domain;
|
||||
|
||||
import com.ruoyi.common.core.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/** 分区方案 xtd_zone_scheme */
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class XtdZoneScheme extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Long zsId;
|
||||
private String zsName;
|
||||
/** on / off */
|
||||
private String ssCode;
|
||||
private String pgCode;
|
||||
private Long snId;
|
||||
private String zsNote;
|
||||
private Long tmsId;
|
||||
/** 列表展示,非表字段 */
|
||||
private Integer divisionCount;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.ruoyi.price.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import com.ruoyi.price.domain.PrcZoneDetail;
|
||||
|
||||
public interface PrcZoneDetailMapper
|
||||
{
|
||||
public PrcZoneDetail selectPrcZoneDetailById(Long detailId);
|
||||
|
||||
public List<PrcZoneDetail> selectPrcZoneDetailList(PrcZoneDetail detail);
|
||||
|
||||
public int countByZoneId(Long zoneId);
|
||||
|
||||
public int countByRegionId(Long regionId);
|
||||
|
||||
public int insertPrcZoneDetail(PrcZoneDetail detail);
|
||||
|
||||
public int insertPrcZoneDetailBatch(@Param("list") List<PrcZoneDetail> list);
|
||||
|
||||
public int updatePrcZoneDetail(PrcZoneDetail detail);
|
||||
|
||||
public int deletePrcZoneDetailByIds(Long[] detailIds);
|
||||
|
||||
public int deletePrcZoneDetailByZoneId(Long zoneId);
|
||||
|
||||
public int deletePrcZoneDetailByRegionId(Long regionId);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.ruoyi.price.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.price.domain.PrcZone;
|
||||
import com.ruoyi.price.domain.PrcZoneRegion;
|
||||
|
||||
public interface PrcZoneMapper
|
||||
{
|
||||
public PrcZone selectPrcZoneById(Long zoneId);
|
||||
|
||||
public List<PrcZone> selectPrcZoneList(PrcZone zone);
|
||||
|
||||
public List<PrcZone> selectPrcZoneListByRegionId(Long regionId);
|
||||
|
||||
public List<PrcZoneRegion> selectZoneRegionList(PrcZoneRegion query);
|
||||
|
||||
public PrcZoneRegion selectZoneRegionById(Long regionId);
|
||||
|
||||
public int countByRegionId(Long regionId);
|
||||
|
||||
public int insertPrcZone(PrcZone zone);
|
||||
|
||||
public int updatePrcZone(PrcZone zone);
|
||||
|
||||
public int deletePrcZoneByIds(Long[] zoneIds);
|
||||
|
||||
public int deletePrcZoneByRegionId(Long regionId);
|
||||
|
||||
public int deletePrcZoneByRegionIds(Long[] regionIds);
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package com.ruoyi.price.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.price.domain.XtdZoneCountry;
|
||||
|
||||
/**
|
||||
* 分区国家 数据层
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public interface XtdZoneCountryMapper
|
||||
{
|
||||
public XtdZoneCountry selectXtdZoneCountryById(Long zcId);
|
||||
|
||||
public List<XtdZoneCountry> selectXtdZoneCountryListByZdId(Long zdId);
|
||||
|
||||
public List<XtdZoneCountry> selectXtdZoneCountryList(XtdZoneCountry country);
|
||||
|
||||
public int insertXtdZoneCountry(XtdZoneCountry country);
|
||||
|
||||
public int updateXtdZoneCountry(XtdZoneCountry country);
|
||||
|
||||
public int deleteXtdZoneCountryByIds(Long[] zcIds);
|
||||
|
||||
public int countByZdId(Long zdId);
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package com.ruoyi.price.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.price.domain.XtdZoneDivision;
|
||||
|
||||
/**
|
||||
* 分区区划 数据层
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public interface XtdZoneDivisionMapper
|
||||
{
|
||||
public XtdZoneDivision selectXtdZoneDivisionById(Long zdId);
|
||||
|
||||
public List<XtdZoneDivision> selectXtdZoneDivisionListByZsId(Long zsId);
|
||||
|
||||
public List<XtdZoneDivision> selectXtdZoneDivisionList(XtdZoneDivision division);
|
||||
|
||||
public int insertXtdZoneDivision(XtdZoneDivision division);
|
||||
|
||||
public int updateXtdZoneDivision(XtdZoneDivision division);
|
||||
|
||||
public int deleteXtdZoneDivisionByIds(Long[] zdIds);
|
||||
|
||||
public int countByZsId(Long zsId);
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
package com.ruoyi.price.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.price.domain.XtdZoneScheme;
|
||||
|
||||
/**
|
||||
* 分区方案 数据层
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public interface XtdZoneSchemeMapper
|
||||
{
|
||||
public XtdZoneScheme selectXtdZoneSchemeById(Long zsId);
|
||||
|
||||
public List<XtdZoneScheme> selectXtdZoneSchemeList(XtdZoneScheme scheme);
|
||||
|
||||
public int insertXtdZoneScheme(XtdZoneScheme scheme);
|
||||
|
||||
public int updateXtdZoneScheme(XtdZoneScheme scheme);
|
||||
|
||||
public int deleteXtdZoneSchemeByIds(Long[] zsIds);
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.ruoyi.price.service;
|
||||
|
||||
import java.util.List;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import com.ruoyi.price.domain.PrcZone;
|
||||
import com.ruoyi.price.domain.PrcZoneDetail;
|
||||
import com.ruoyi.price.domain.PrcZoneRegion;
|
||||
|
||||
public interface IPrcZoneService
|
||||
{
|
||||
public PrcZoneRegion selectZoneRegionById(Long regionId);
|
||||
|
||||
public List<PrcZoneRegion> selectZoneRegionList(PrcZoneRegion query);
|
||||
|
||||
/** Delete all zones (and details) for the given bms_region ids */
|
||||
public int deleteZonesByRegionIds(Long[] regionIds);
|
||||
|
||||
public PrcZone selectPrcZoneById(Long zoneId);
|
||||
|
||||
public List<PrcZone> selectPrcZoneList(PrcZone zone);
|
||||
|
||||
public int insertPrcZone(PrcZone zone);
|
||||
|
||||
public int updatePrcZone(PrcZone zone);
|
||||
|
||||
public int deletePrcZoneByIds(Long[] zoneIds);
|
||||
|
||||
public PrcZoneDetail selectPrcZoneDetailById(Long detailId);
|
||||
|
||||
public List<PrcZoneDetail> selectPrcZoneDetailList(PrcZoneDetail detail);
|
||||
|
||||
public int insertPrcZoneDetail(PrcZoneDetail detail);
|
||||
|
||||
public int updatePrcZoneDetail(PrcZoneDetail detail);
|
||||
|
||||
public int deletePrcZoneDetailByIds(Long[] detailIds);
|
||||
|
||||
public String importZoneExcel(MultipartFile file, String operName) throws Exception;
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
package com.ruoyi.price.service;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.price.domain.XtdZoneCountry;
|
||||
import com.ruoyi.price.domain.XtdZoneDivision;
|
||||
import com.ruoyi.price.domain.XtdZoneScheme;
|
||||
|
||||
/**
|
||||
* 分区管理 服务层
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public interface IXtdZoneService
|
||||
{
|
||||
public XtdZoneScheme selectXtdZoneSchemeById(Long zsId);
|
||||
|
||||
public List<XtdZoneScheme> selectXtdZoneSchemeList(XtdZoneScheme scheme);
|
||||
|
||||
public int insertXtdZoneScheme(XtdZoneScheme scheme);
|
||||
|
||||
public int updateXtdZoneScheme(XtdZoneScheme scheme);
|
||||
|
||||
public int deleteXtdZoneSchemeByIds(Long[] zsIds);
|
||||
|
||||
public XtdZoneDivision selectXtdZoneDivisionById(Long zdId);
|
||||
|
||||
public List<XtdZoneDivision> selectXtdZoneDivisionList(XtdZoneDivision division);
|
||||
|
||||
public int insertXtdZoneDivision(XtdZoneDivision division);
|
||||
|
||||
public int updateXtdZoneDivision(XtdZoneDivision division);
|
||||
|
||||
public int deleteXtdZoneDivisionByIds(Long[] zdIds);
|
||||
|
||||
public XtdZoneCountry selectXtdZoneCountryById(Long zcId);
|
||||
|
||||
public List<XtdZoneCountry> selectXtdZoneCountryList(XtdZoneCountry country);
|
||||
|
||||
public int insertXtdZoneCountry(XtdZoneCountry country);
|
||||
|
||||
public int updateXtdZoneCountry(XtdZoneCountry country);
|
||||
|
||||
public int deleteXtdZoneCountryByIds(Long[] zcIds);
|
||||
}
|
||||
+503
@@ -0,0 +1,503 @@
|
||||
package com.ruoyi.price.service.impl;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.DataFormatter;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.ss.usermodel.WorkbookFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.utils.MessageUtils;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.price.domain.PrcZone;
|
||||
import com.ruoyi.price.domain.PrcZoneDetail;
|
||||
import com.ruoyi.price.domain.PrcZoneRegion;
|
||||
import com.ruoyi.price.mapper.PrcZoneDetailMapper;
|
||||
import com.ruoyi.price.mapper.PrcZoneMapper;
|
||||
import com.ruoyi.price.service.IPrcZoneService;
|
||||
import com.ruoyi.system.domain.BmsRegion;
|
||||
import com.ruoyi.system.mapper.BmsRegionMapper;
|
||||
|
||||
/**
|
||||
* Zone management: bms_region -> prc_zone -> postcode detail
|
||||
*/
|
||||
@Service
|
||||
public class PrcZoneServiceImpl implements IPrcZoneService
|
||||
{
|
||||
private static final String SHEET_SUFFIX = "\u5206\u533a";
|
||||
private static final String COL_POSTCODE = "\u90ae\u7f16";
|
||||
private static final String COL_ZONE = "\u5206\u533a";
|
||||
private static final Pattern ZONE_NUM = Pattern.compile("(\\d+)");
|
||||
private static final int BATCH_SIZE = 500;
|
||||
private static final DataFormatter CELL_FMT = new DataFormatter(Locale.ROOT);
|
||||
|
||||
@Autowired
|
||||
private PrcZoneMapper zoneMapper;
|
||||
|
||||
@Autowired
|
||||
private PrcZoneDetailMapper detailMapper;
|
||||
|
||||
@Autowired
|
||||
private BmsRegionMapper regionMapper;
|
||||
|
||||
@Override
|
||||
public PrcZoneRegion selectZoneRegionById(Long regionId)
|
||||
{
|
||||
return zoneMapper.selectZoneRegionById(regionId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PrcZoneRegion> selectZoneRegionList(PrcZoneRegion query)
|
||||
{
|
||||
return zoneMapper.selectZoneRegionList(query);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int deleteZonesByRegionIds(Long[] regionIds)
|
||||
{
|
||||
if (regionIds == null || regionIds.length == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
for (Long regionId : regionIds)
|
||||
{
|
||||
detailMapper.deletePrcZoneDetailByRegionId(regionId);
|
||||
}
|
||||
return zoneMapper.deletePrcZoneByRegionIds(regionIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PrcZone selectPrcZoneById(Long zoneId)
|
||||
{
|
||||
PrcZone zone = zoneMapper.selectPrcZoneById(zoneId);
|
||||
if (zone != null)
|
||||
{
|
||||
zone.setDetailCount(detailMapper.countByZoneId(zoneId));
|
||||
}
|
||||
return zone;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PrcZone> selectPrcZoneList(PrcZone zone)
|
||||
{
|
||||
return zoneMapper.selectPrcZoneList(zone);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int insertPrcZone(PrcZone zone)
|
||||
{
|
||||
if (zone.getRegionId() == null)
|
||||
{
|
||||
throw new ServiceException(MessageUtils.message("price.zone.region.required"));
|
||||
}
|
||||
BmsRegion region = regionMapper.selectRegionById(zone.getRegionId());
|
||||
if (region == null)
|
||||
{
|
||||
throw new ServiceException(MessageUtils.message("price.zone.region.notFound"));
|
||||
}
|
||||
if (StringUtils.isEmpty(zone.getCountryCode()))
|
||||
{
|
||||
zone.setCountryCode(region.getCountryCode2());
|
||||
}
|
||||
else
|
||||
{
|
||||
zone.setCountryCode(zone.getCountryCode().trim().toUpperCase(Locale.ROOT));
|
||||
}
|
||||
if (StringUtils.isEmpty(zone.getCountryCode()))
|
||||
{
|
||||
throw new ServiceException(MessageUtils.message("price.zone.countryCode.empty"));
|
||||
}
|
||||
if (zone.getZoneSort() == null)
|
||||
{
|
||||
zone.setZoneSort(extractZoneSort(zone.getZoneCode()));
|
||||
}
|
||||
if (StringUtils.isEmpty(zone.getZoneName()))
|
||||
{
|
||||
zone.setZoneName(buildZoneName(region.getCountryNameCn(), zone.getZoneCode()));
|
||||
}
|
||||
return zoneMapper.insertPrcZone(zone);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updatePrcZone(PrcZone zone)
|
||||
{
|
||||
if (zone.getRegionId() != null && StringUtils.isEmpty(zone.getCountryCode()))
|
||||
{
|
||||
BmsRegion region = regionMapper.selectRegionById(zone.getRegionId());
|
||||
if (region != null)
|
||||
{
|
||||
zone.setCountryCode(region.getCountryCode2());
|
||||
}
|
||||
}
|
||||
else if (StringUtils.isNotEmpty(zone.getCountryCode()))
|
||||
{
|
||||
zone.setCountryCode(zone.getCountryCode().trim().toUpperCase(Locale.ROOT));
|
||||
}
|
||||
if (zone.getZoneSort() == null && StringUtils.isNotEmpty(zone.getZoneCode()))
|
||||
{
|
||||
zone.setZoneSort(extractZoneSort(zone.getZoneCode()));
|
||||
}
|
||||
return zoneMapper.updatePrcZone(zone);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int deletePrcZoneByIds(Long[] zoneIds)
|
||||
{
|
||||
return zoneMapper.deletePrcZoneByIds(zoneIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PrcZoneDetail selectPrcZoneDetailById(Long detailId)
|
||||
{
|
||||
return detailMapper.selectPrcZoneDetailById(detailId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PrcZoneDetail> selectPrcZoneDetailList(PrcZoneDetail detail)
|
||||
{
|
||||
return detailMapper.selectPrcZoneDetailList(detail);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int insertPrcZoneDetail(PrcZoneDetail detail)
|
||||
{
|
||||
return detailMapper.insertPrcZoneDetail(detail);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updatePrcZoneDetail(PrcZoneDetail detail)
|
||||
{
|
||||
return detailMapper.updatePrcZoneDetail(detail);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deletePrcZoneDetailByIds(Long[] detailIds)
|
||||
{
|
||||
return detailMapper.deletePrcZoneDetailByIds(detailIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public String importZoneExcel(MultipartFile file, String operName) throws Exception
|
||||
{
|
||||
if (file == null || file.isEmpty())
|
||||
{
|
||||
throw new ServiceException(MessageUtils.message("price.zone.import.fileEmpty"));
|
||||
}
|
||||
String filename = file.getOriginalFilename();
|
||||
if (filename == null || !(filename.toLowerCase(Locale.ROOT).endsWith(".xls")
|
||||
|| filename.toLowerCase(Locale.ROOT).endsWith(".xlsx")))
|
||||
{
|
||||
throw new ServiceException(MessageUtils.message("price.zone.import.fileType"));
|
||||
}
|
||||
|
||||
Map<String, BmsRegion> regionByNameCn = loadRegionByNameCn();
|
||||
if (regionByNameCn.isEmpty())
|
||||
{
|
||||
throw new ServiceException(MessageUtils.message("price.zone.import.regionEmpty"));
|
||||
}
|
||||
|
||||
int countryCount = 0;
|
||||
int zoneCount = 0;
|
||||
int detailCount = 0;
|
||||
List<String> importedCountries = new ArrayList<>();
|
||||
List<String> unmatched = new ArrayList<>();
|
||||
|
||||
try (InputStream is = file.getInputStream(); Workbook workbook = WorkbookFactory.create(is))
|
||||
{
|
||||
List<Sheet> zoneSheets = findZoneSheets(workbook);
|
||||
if (zoneSheets.isEmpty())
|
||||
{
|
||||
throw new ServiceException(MessageUtils.message("price.zone.import.noSheet"));
|
||||
}
|
||||
for (Sheet sheet : zoneSheets)
|
||||
{
|
||||
String countryName = parseCountryNameFromSheet(sheet.getSheetName());
|
||||
if (StringUtils.isEmpty(countryName))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
Map<String, List<String>> zonePostcodes = parseZonePostcodes(sheet);
|
||||
if (zonePostcodes.isEmpty())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
BmsRegion region = resolveRegion(countryName, regionByNameCn);
|
||||
if (region == null)
|
||||
{
|
||||
unmatched.add(countryName);
|
||||
continue;
|
||||
}
|
||||
int[] counts = replaceRegionZones(region, zonePostcodes);
|
||||
countryCount += 1;
|
||||
zoneCount += counts[0];
|
||||
detailCount += counts[1];
|
||||
importedCountries.add(region.getCountryNameCn());
|
||||
}
|
||||
}
|
||||
|
||||
if (countryCount == 0)
|
||||
{
|
||||
if (!unmatched.isEmpty())
|
||||
{
|
||||
throw new ServiceException(MessageUtils.message("price.zone.import.regionNotFound",
|
||||
String.join(",", unmatched)));
|
||||
}
|
||||
throw new ServiceException(MessageUtils.message("price.zone.import.noData"));
|
||||
}
|
||||
String msg = MessageUtils.message("price.zone.import.success", countryCount, zoneCount, detailCount,
|
||||
String.join(",", importedCountries));
|
||||
if (!unmatched.isEmpty())
|
||||
{
|
||||
msg = msg + " " + MessageUtils.message("price.zone.import.unmatched", String.join(",", unmatched));
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
private int[] replaceRegionZones(BmsRegion region, Map<String, List<String>> zonePostcodes)
|
||||
{
|
||||
if (StringUtils.isEmpty(region.getCountryCode2()))
|
||||
{
|
||||
throw new ServiceException(MessageUtils.message("price.zone.countryCode.empty"));
|
||||
}
|
||||
Long regionId = region.getRegionId();
|
||||
detailMapper.deletePrcZoneDetailByRegionId(regionId);
|
||||
zoneMapper.deletePrcZoneByRegionId(regionId);
|
||||
|
||||
int zoneInserted = 0;
|
||||
int detailInserted = 0;
|
||||
List<Map.Entry<String, List<String>>> entries = new ArrayList<>(zonePostcodes.entrySet());
|
||||
entries.sort(Comparator.comparingInt(e -> extractZoneSort(e.getKey())));
|
||||
|
||||
String countryName = region.getCountryNameCn();
|
||||
for (Map.Entry<String, List<String>> entry : entries)
|
||||
{
|
||||
String zoneCode = entry.getKey();
|
||||
PrcZone zone = new PrcZone();
|
||||
zone.setRegionId(regionId);
|
||||
zone.setCountryCode(region.getCountryCode2());
|
||||
zone.setZoneCode(zoneCode);
|
||||
zone.setZoneName(buildZoneName(countryName, zoneCode));
|
||||
zone.setZoneSort(extractZoneSort(zoneCode));
|
||||
zoneMapper.insertPrcZone(zone);
|
||||
zoneInserted++;
|
||||
|
||||
Set<String> uniquePostcodes = new LinkedHashSet<>(entry.getValue());
|
||||
List<PrcZoneDetail> batch = new ArrayList<>(BATCH_SIZE);
|
||||
for (String postcode : uniquePostcodes)
|
||||
{
|
||||
PrcZoneDetail detail = new PrcZoneDetail();
|
||||
detail.setZoneId(zone.getZoneId());
|
||||
detail.setPostcode(postcode);
|
||||
batch.add(detail);
|
||||
if (batch.size() >= BATCH_SIZE)
|
||||
{
|
||||
detailMapper.insertPrcZoneDetailBatch(batch);
|
||||
detailInserted += batch.size();
|
||||
batch = new ArrayList<>(BATCH_SIZE);
|
||||
}
|
||||
}
|
||||
if (!batch.isEmpty())
|
||||
{
|
||||
detailMapper.insertPrcZoneDetailBatch(batch);
|
||||
detailInserted += batch.size();
|
||||
}
|
||||
}
|
||||
return new int[] { zoneInserted, detailInserted };
|
||||
}
|
||||
|
||||
private List<Sheet> findZoneSheets(Workbook workbook)
|
||||
{
|
||||
List<Sheet> list = new ArrayList<>();
|
||||
for (int i = 0; i < workbook.getNumberOfSheets(); i++)
|
||||
{
|
||||
Sheet sheet = workbook.getSheetAt(i);
|
||||
if (sheet == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
String name = StringUtils.trim(sheet.getSheetName());
|
||||
if (name != null && name.endsWith(SHEET_SUFFIX) && name.length() > SHEET_SUFFIX.length())
|
||||
{
|
||||
list.add(sheet);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private String parseCountryNameFromSheet(String sheetName)
|
||||
{
|
||||
String name = StringUtils.trim(sheetName);
|
||||
if (name == null || !name.endsWith(SHEET_SUFFIX))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return StringUtils.trim(name.substring(0, name.length() - SHEET_SUFFIX.length()));
|
||||
}
|
||||
|
||||
private Map<String, List<String>> parseZonePostcodes(Sheet sheet)
|
||||
{
|
||||
Map<String, List<String>> map = new LinkedHashMap<>();
|
||||
int postcodeCol = -1;
|
||||
int zoneCol = -1;
|
||||
int headerRow = -1;
|
||||
|
||||
int lastRow = sheet.getLastRowNum();
|
||||
for (int r = 0; r <= Math.min(lastRow, 20); r++)
|
||||
{
|
||||
Row row = sheet.getRow(r);
|
||||
if (row == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
for (int c = 0; c < row.getLastCellNum(); c++)
|
||||
{
|
||||
String val = cellText(row.getCell(c));
|
||||
if (COL_POSTCODE.equals(val))
|
||||
{
|
||||
postcodeCol = c;
|
||||
headerRow = r;
|
||||
}
|
||||
else if (COL_ZONE.equals(val))
|
||||
{
|
||||
zoneCol = c;
|
||||
headerRow = r;
|
||||
}
|
||||
}
|
||||
if (postcodeCol >= 0 && zoneCol >= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (postcodeCol < 0 || zoneCol < 0 || headerRow < 0)
|
||||
{
|
||||
return map;
|
||||
}
|
||||
|
||||
for (int r = headerRow + 1; r <= lastRow; r++)
|
||||
{
|
||||
Row row = sheet.getRow(r);
|
||||
if (row == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
String postcode = cellText(row.getCell(postcodeCol));
|
||||
String zoneCode = cellText(row.getCell(zoneCol));
|
||||
if (StringUtils.isEmpty(postcode) || StringUtils.isEmpty(zoneCode))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (postcode.endsWith(".0") && postcode.matches("\\d+\\.0"))
|
||||
{
|
||||
postcode = postcode.substring(0, postcode.length() - 2);
|
||||
}
|
||||
map.computeIfAbsent(zoneCode, k -> new ArrayList<>()).add(postcode);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
private String cellText(Cell cell)
|
||||
{
|
||||
if (cell == null)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
return StringUtils.trim(CELL_FMT.formatCellValue(cell));
|
||||
}
|
||||
|
||||
private Map<String, BmsRegion> loadRegionByNameCn()
|
||||
{
|
||||
BmsRegion query = new BmsRegion();
|
||||
List<BmsRegion> regions = regionMapper.selectRegionList(query);
|
||||
Map<String, BmsRegion> map = new HashMap<>();
|
||||
if (regions == null)
|
||||
{
|
||||
return map;
|
||||
}
|
||||
for (BmsRegion region : regions)
|
||||
{
|
||||
if (region != null && StringUtils.isNotEmpty(region.getCountryNameCn()))
|
||||
{
|
||||
map.put(region.getCountryNameCn().trim(), region);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
private BmsRegion resolveRegion(String excelName, Map<String, BmsRegion> regionByNameCn)
|
||||
{
|
||||
if (StringUtils.isEmpty(excelName) || regionByNameCn == null || regionByNameCn.isEmpty())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
String name = excelName.trim();
|
||||
BmsRegion exact = regionByNameCn.get(name);
|
||||
if (exact != null)
|
||||
{
|
||||
return exact;
|
||||
}
|
||||
BmsRegion best = null;
|
||||
int bestLen = -1;
|
||||
for (BmsRegion region : regionByNameCn.values())
|
||||
{
|
||||
String cn = region.getCountryNameCn();
|
||||
if (StringUtils.isEmpty(cn))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (name.contains(cn) || cn.contains(name))
|
||||
{
|
||||
if (cn.length() > bestLen)
|
||||
{
|
||||
best = region;
|
||||
bestLen = cn.length();
|
||||
}
|
||||
}
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
private static String buildZoneName(String countryName, String zoneCode)
|
||||
{
|
||||
return (countryName == null ? "" : countryName) + "(" + zoneCode + ")";
|
||||
}
|
||||
|
||||
private static int extractZoneSort(String zoneCode)
|
||||
{
|
||||
if (StringUtils.isEmpty(zoneCode))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
Matcher m = ZONE_NUM.matcher(zoneCode);
|
||||
if (m.find())
|
||||
{
|
||||
try
|
||||
{
|
||||
return Integer.parseInt(m.group(1));
|
||||
}
|
||||
catch (NumberFormatException ignored)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
-161
@@ -1,161 +0,0 @@
|
||||
package com.ruoyi.price.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.utils.MessageUtils;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.price.domain.XtdZoneCountry;
|
||||
import com.ruoyi.price.domain.XtdZoneDivision;
|
||||
import com.ruoyi.price.domain.XtdZoneScheme;
|
||||
import com.ruoyi.price.mapper.XtdZoneCountryMapper;
|
||||
import com.ruoyi.price.mapper.XtdZoneDivisionMapper;
|
||||
import com.ruoyi.price.mapper.XtdZoneSchemeMapper;
|
||||
import com.ruoyi.price.service.IXtdZoneService;
|
||||
|
||||
/**
|
||||
* 分区管理 服务层实现
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Service
|
||||
public class XtdZoneServiceImpl implements IXtdZoneService
|
||||
{
|
||||
@Autowired
|
||||
private XtdZoneSchemeMapper schemeMapper;
|
||||
|
||||
@Autowired
|
||||
private XtdZoneDivisionMapper divisionMapper;
|
||||
|
||||
@Autowired
|
||||
private XtdZoneCountryMapper countryMapper;
|
||||
|
||||
@Override
|
||||
public XtdZoneScheme selectXtdZoneSchemeById(Long zsId)
|
||||
{
|
||||
XtdZoneScheme scheme = schemeMapper.selectXtdZoneSchemeById(zsId);
|
||||
if (scheme != null)
|
||||
{
|
||||
scheme.setDivisionCount(divisionMapper.countByZsId(zsId));
|
||||
}
|
||||
return scheme;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<XtdZoneScheme> selectXtdZoneSchemeList(XtdZoneScheme scheme)
|
||||
{
|
||||
List<XtdZoneScheme> list = schemeMapper.selectXtdZoneSchemeList(scheme);
|
||||
for (XtdZoneScheme item : list)
|
||||
{
|
||||
item.setDivisionCount(divisionMapper.countByZsId(item.getZsId()));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int insertXtdZoneScheme(XtdZoneScheme scheme)
|
||||
{
|
||||
if (StringUtils.isEmpty(scheme.getSsCode()))
|
||||
{
|
||||
scheme.setSsCode("on");
|
||||
}
|
||||
return schemeMapper.insertXtdZoneScheme(scheme);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateXtdZoneScheme(XtdZoneScheme scheme)
|
||||
{
|
||||
return schemeMapper.updateXtdZoneScheme(scheme);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteXtdZoneSchemeByIds(Long[] zsIds)
|
||||
{
|
||||
for (Long zsId : zsIds)
|
||||
{
|
||||
int count = divisionMapper.countByZsId(zsId);
|
||||
if (count > 0)
|
||||
{
|
||||
XtdZoneScheme scheme = schemeMapper.selectXtdZoneSchemeById(zsId);
|
||||
String name = scheme != null ? scheme.getZsName() : String.valueOf(zsId);
|
||||
throw new ServiceException(MessageUtils.message("price.zone.delete.hasDivision", name));
|
||||
}
|
||||
}
|
||||
return schemeMapper.deleteXtdZoneSchemeByIds(zsIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public XtdZoneDivision selectXtdZoneDivisionById(Long zdId)
|
||||
{
|
||||
XtdZoneDivision division = divisionMapper.selectXtdZoneDivisionById(zdId);
|
||||
if (division != null)
|
||||
{
|
||||
division.setCountryCount(countryMapper.countByZdId(zdId));
|
||||
}
|
||||
return division;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<XtdZoneDivision> selectXtdZoneDivisionList(XtdZoneDivision division)
|
||||
{
|
||||
List<XtdZoneDivision> list = divisionMapper.selectXtdZoneDivisionList(division);
|
||||
for (XtdZoneDivision item : list)
|
||||
{
|
||||
item.setCountryCount(countryMapper.countByZdId(item.getZdId()));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int insertXtdZoneDivision(XtdZoneDivision division)
|
||||
{
|
||||
return divisionMapper.insertXtdZoneDivision(division);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateXtdZoneDivision(XtdZoneDivision division)
|
||||
{
|
||||
return divisionMapper.updateXtdZoneDivision(division);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteXtdZoneDivisionByIds(Long[] zdIds)
|
||||
{
|
||||
return divisionMapper.deleteXtdZoneDivisionByIds(zdIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public XtdZoneCountry selectXtdZoneCountryById(Long zcId)
|
||||
{
|
||||
return countryMapper.selectXtdZoneCountryById(zcId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<XtdZoneCountry> selectXtdZoneCountryList(XtdZoneCountry country)
|
||||
{
|
||||
return countryMapper.selectXtdZoneCountryList(country);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int insertXtdZoneCountry(XtdZoneCountry country)
|
||||
{
|
||||
if (StringUtils.isEmpty(country.getZcDividekind()))
|
||||
{
|
||||
country.setZcDividekind("C");
|
||||
}
|
||||
return countryMapper.insertXtdZoneCountry(country);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateXtdZoneCountry(XtdZoneCountry country)
|
||||
{
|
||||
return countryMapper.updateXtdZoneCountry(country);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteXtdZoneCountryByIds(Long[] zcIds)
|
||||
{
|
||||
return countryMapper.deleteXtdZoneCountryByIds(zcIds);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user