demand: tms-基础管理-网点管理-批量导入网点

This commit is contained in:
aike 2026-03-23 13:08:35 +08:00
parent db9c580166
commit 6ee783234a
3 changed files with 247 additions and 30 deletions

View File

@ -13,17 +13,15 @@ package com.xdadan.erp.web.emis;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;
import com.alibaba.fastjson.JSONObject;
import com.xdadan.erp.common.annotation.filter.jackson.JacksonFilter;
import com.xdadan.erp.emis.domain.EmisSupplier;
import com.xdadan.erp.emis.service.EmisBaseService;
import com.xdadan.erp.emis.utils.WaybillHelper;
import jodd.util.StringUtil;
import org.apache.commons.compress.utils.Lists;
import com.xdadan.erp.emis.domain.exception.EmisBizError;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
@ -35,7 +33,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xdadan.erp.common.annotation.Log;
import com.xdadan.erp.common.core.controller.BaseController;
import com.xdadan.erp.common.core.domain.AjaxResult;
import com.xdadan.erp.common.core.page.TableDataInfo;
import com.xdadan.erp.common.enums.BusinessType;
@ -57,8 +54,38 @@ public class EmisSiteController extends EmisBaseController
@Autowired
private IEmisSiteService emisSiteService;
@Autowired
private EmisBaseService emisBaseService;
/**
* Excel草稿方式新增网点
*/
@PreAuthorize("@ss.hasPermi('emis:emisSite:draftSubmitSite')")
@PostMapping(value = "/draftSubmitSite")
public AjaxResult draftSubmitSite(@RequestBody EmisSite emisSite) {
JSONObject jObjOut = new JSONObject();
String result = "success";
String msg = "提交成功";
try {
emisSiteService.draftSubmitSite(emisSite);
jObjOut.put("siteDetail", emisSite);
} catch (EmisBizError ex) {
ex.printStackTrace();
result = "fail";
msg = ex.getErrorCode() + ":" + ex.getMessage();
} catch (DuplicateKeyException e) {
e.printStackTrace();
result = "fail";
msg = "数据重复";
} catch (Exception ex) {
result = "fail";
ex.printStackTrace();
msg = "系统异常:" + ex.getMessage();
if (ex instanceof EmisBizError) {
msg = ((EmisBizError) ex).getErrorCode() + ":" + ex.getMessage();
}
}
jObjOut.put("result", result);
jObjOut.put("msg", msg);
return AjaxResult.success("成功", jObjOut);
}
/**
* 查询网点列表

View File

@ -13,6 +13,7 @@ import java.util.List;
import java.util.Map;
import com.xdadan.erp.emis.domain.EmisSite;
import com.xdadan.erp.emis.domain.exception.EmisBizError;
/**
* @ClassName EmisSiteService
@ -91,4 +92,12 @@ public interface IEmisSiteService
* @return
*/
List<EmisSite> selectSiteByConditions(EmisSite emisSite);
/**
* Excel草稿方式新增网点(带参数校验/转换)
*
* @param emisSite 网点
* @return 结果
*/
int draftSubmitSite(EmisSite emisSite) throws EmisBizError;
}

View File

@ -10,17 +10,25 @@
package com.xdadan.erp.emis.service.impl;
import java.util.Collections;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import com.xdadan.erp.common.utils.DictUtils;
import com.xdadan.erp.emis.domain.EmisBrand;
import com.xdadan.erp.emis.domain.EmisCountry;
import com.xdadan.erp.emis.domain.EmisDestination;
import com.xdadan.erp.emis.domain.EmisRegion;
import com.xdadan.erp.emis.domain.EmisSiteAccount;
import com.xdadan.erp.emis.domain.enumtype.EmisBizErrorType;
import com.xdadan.erp.emis.domain.exception.EmisBizError;
import com.xdadan.erp.emis.mapper.EmisBrandMapper;
import com.xdadan.erp.emis.mapper.EmisDestinationMapper;
import com.xdadan.erp.emis.mapper.EmisSiteAccountMapper;
import com.xdadan.erp.emis.service.EmisBaseService;
import jodd.util.StringUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.xdadan.erp.emis.domain.EmisSite;
@ -47,6 +55,9 @@ public class EmisSiteServiceImpl extends EmisBaseService implements IEmisSiteSer
@Autowired
private EmisSiteAccountMapper emisSiteAccountMapper;
@Autowired
private EmisBrandMapper emisBrandMapper;
/**
* 查询网点
@ -199,4 +210,174 @@ public class EmisSiteServiceImpl extends EmisBaseService implements IEmisSiteSer
return emisSiteMapper.selectSiteByConditions(emisSite);
}
/**
* Excel草稿方式新增网点(带参数校验/转换)
*/
@Override
@Transactional
public int draftSubmitSite(EmisSite emisSite) throws EmisBizError {
checkRequired(emisSite);
fillNamesByCodes(emisSite);
return insertEmisSite(emisSite);
}
private static void checkRequired(EmisSite emisSite) throws EmisBizError {
if (emisSite == null) {
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "参数不能为空");
}
if (StringUtil.isBlank(emisSite.getSiteCode())) {
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "站点代码不能为空");
}
if (StringUtil.isBlank(emisSite.getSiteName())) {
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "站点名称不能为空");
}
if (StringUtil.isBlank(emisSite.getSiteType())) {
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "站点类型不能为空");
}
if (StringUtil.isBlank(emisSite.getParentSiteCode())) {
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "父站点代码不能为空");
}
if (StringUtil.isBlank(emisSite.getSuperiorFinanceCenterCode())) {
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "上级财务中心代码不能为空");
}
if (StringUtil.isBlank(emisSite.getScopeType())) {
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "加盟类型不能为空");
}
if (StringUtil.isBlank(emisSite.getCountryCode())) {
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "国家代码不能为空");
}
if (StringUtil.isBlank(emisSite.getSizeCode2())) {
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "站点2字码不能为空");
}
if (StringUtil.isBlank(emisSite.getSizeCode3())) {
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "站点3字码不能为空");
}
}
private void fillNamesByCodes(EmisSite emisSite) throws EmisBizError {
// siteType(字典emis_site_type):name -> code
String siteTypeName = emisSite.getSiteType();
String siteTypeCode = DictUtils.getDictValue("emis_site_type", siteTypeName);
if (StringUtils.isBlank(siteTypeCode)) {
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "站点类型不正确: " + siteTypeName);
}
emisSite.setSiteType(siteTypeCode);
emisSite.getParams().put("siteTypeName", siteTypeName);
// scopeType(字典emis_affiliate_type):name -> code
String scopeTypeName = emisSite.getScopeType();
String scopeTypeCode = DictUtils.getDictValue("emis_affiliate_type", scopeTypeName);
if (StringUtils.isBlank(scopeTypeCode)) {
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "加盟类型不正确: " + scopeTypeName);
}
emisSite.setScopeType(scopeTypeCode);
emisSite.getParams().put("scopeTypeName", scopeTypeName);
// transTypeId(字典emis_biz_shipping_method):name -> code,支持多个用英文逗号分隔
if (StringUtils.isNotBlank(emisSite.getTransTypeId())) {
String[] transTypeNameParts = emisSite.getTransTypeId().split(",");
List<String> codeList = new ArrayList<>();
List<String> labelList = new ArrayList<>();
for (String part : transTypeNameParts) {
String name = part == null ? "" : part.trim();
if (name.isEmpty()) {
continue;
}
String transTypeCode = DictUtils.getDictValue("emis_biz_shipping_method", name);
if (StringUtils.isBlank(transTypeCode)) {
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "运输类型不正确: " + name);
}
codeList.add(transTypeCode);
String label = DictUtils.getDictLabel("emis_biz_shipping_method", transTypeCode);
labelList.add(StringUtils.isNotBlank(label) ? label : name);
}
if (codeList.isEmpty()) {
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "运输类型不能为空");
}
emisSite.setTransTypeId(String.join(",", codeList));
emisSite.setTransTypeName(String.join(",", labelList));
}
// parentSiteCode(查询emis_site):name -> code
String parentSiteName = emisSite.getParentSiteCode();
EmisSite parentSite = getSiteByName(parentSiteName);
if (parentSite == null) {
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "父站点未找到: " + parentSiteName);
}
emisSite.setParentSiteCode(parentSite.getSiteCode());
emisSite.setParentSiteName(parentSite.getSiteName());
// superiorFinanceCenterCode(查询emis_site):name -> code
String financeCenterName = emisSite.getSuperiorFinanceCenterCode();
EmisSite financeCenter = getSiteByName(financeCenterName);
if (financeCenter == null) {
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR,
"上级财务中心未找到: " + financeCenterName);
}
emisSite.setSuperiorFinanceCenterCode(financeCenter.getSiteCode());
emisSite.setSuperiorFinanceCenterName(financeCenter.getSiteName());
// countryCode(查询emis_country):name -> code
String countryName = emisSite.getCountryCode();
EmisCountry country = getCountryByName(countryName);
if (country == null) {
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "国家未找到: " + countryName);
}
emisSite.setCountryCode(country.getCode());
emisSite.setCountryName(country.getName());
// province/city/county(省市区统一查emis_region)
if (StringUtils.isNotBlank(emisSite.getProvince())) {
String provinceName = emisSite.getProvince();
EmisRegion region = getRegionByName(emisSite.getCountryCode(), null, provinceName);
if (region == null) {
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "省份未找到: " + provinceName);
}
emisSite.setProvince(region.getRegionCode());
emisSite.setProvinceName(region.getRegionName());
}
if (StringUtils.isNotBlank(emisSite.getCity())) {
String cityName = emisSite.getCity();
String provinceCode = emisSite.getProvince();
EmisRegion region = getRegionByName(emisSite.getCountryCode(), provinceCode, cityName);
if (region == null) {
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "城市未找到: " + cityName);
}
emisSite.setCity(region.getRegionCode());
emisSite.setCityName(region.getRegionName());
}
if (StringUtils.isNotBlank(emisSite.getCounty())) {
String countyName = emisSite.getCounty();
String cityCode = emisSite.getCity();
EmisRegion region = getRegionByName(emisSite.getCountryCode(), cityCode, countyName);
if (region == null) {
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "区县未找到: " + countyName);
}
emisSite.setCounty(region.getRegionCode());
emisSite.setCountyName(region.getRegionName());
}
// logoType(查询emis_brand):name -> code;如果传的是全品牌,code为-1
if (StringUtils.isNotBlank(emisSite.getLogoType())) {
String logoTypeName = emisSite.getLogoType();
if ("全品牌".equals(logoTypeName) || "-1".equals(logoTypeName)) {
emisSite.setLogoType("-1");
emisSite.setLogoTypeName("全品牌");
return;
}
EmisBrand queryByName = new EmisBrand();
queryByName.setName(logoTypeName);
List<EmisBrand> byName = emisBrandMapper.selectEmisBrandList(queryByName);
if (byName != null && !byName.isEmpty()) {
emisSite.setLogoType(byName.get(0).getCode());
emisSite.setLogoTypeName(byName.get(0).getName());
return;
}
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "品牌未找到: " + logoTypeName);
}
}
}