demand: 批量导入片区/省市区

This commit is contained in:
aike 2026-03-26 15:17:35 +08:00
parent 3c576e6d52
commit 326a913b4c
2 changed files with 193 additions and 8 deletions

View File

@ -13,8 +13,11 @@ package com.xdadan.erp.web.emis;
import java.util.List; import java.util.List;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.PutMapping;
@ -25,15 +28,18 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import com.xdadan.erp.common.annotation.Log; 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.domain.AjaxResult;
import com.xdadan.erp.common.core.page.TableDataInfo; import com.xdadan.erp.common.core.page.TableDataInfo;
import com.xdadan.erp.common.enums.BusinessType; import com.xdadan.erp.common.enums.BusinessType;
import com.xdadan.erp.common.utils.StringUtils; import com.xdadan.erp.common.utils.StringUtils;
import com.xdadan.erp.common.utils.poi.ExcelUtil; import com.xdadan.erp.common.utils.poi.ExcelUtil;
import com.xdadan.erp.emis.domain.EmisCountry;
import com.xdadan.erp.emis.domain.EmisCountryArea; import com.xdadan.erp.emis.domain.EmisCountryArea;
import com.xdadan.erp.emis.domain.enumtype.EmisBizErrorType;
import com.xdadan.erp.emis.domain.exception.EmisBizError;
import com.xdadan.erp.emis.service.IEmisCountryAreaService; import com.xdadan.erp.emis.service.IEmisCountryAreaService;
import com.xdadan.erp.emis.service.EmisBaseService;
/** /**
* 国家大区表Controller * 国家大区表Controller
@ -48,6 +54,9 @@ public class EmisCountryAreaController extends EmisBaseController
@Autowired @Autowired
private IEmisCountryAreaService emisCountryAreaService; private IEmisCountryAreaService emisCountryAreaService;
@Autowired
private EmisBaseService emisBaseService;
/** /**
* 查询国家大区表列表 * 查询国家大区表列表
*/ */
@ -115,4 +124,72 @@ public class EmisCountryAreaController extends EmisBaseController
{ {
return toAjax(emisCountryAreaService.deleteEmisCountryAreaByIds(ids)); return toAjax(emisCountryAreaService.deleteEmisCountryAreaByIds(ids));
} }
/**
* Excel草稿方式提交国家大区(名称->code)
*/
@PreAuthorize("@ss.hasPermi('emis:emisCountryArea:draftSubmitCountryArea')")
@PostMapping(value = "/draftSubmitCountryArea")
public AjaxResult draftSubmitCountryArea(@RequestBody EmisCountryArea emisCountryArea)
{
JSONObject jObjOut = new JSONObject();
String result = "success";
String msg = "提交成功";
try
{
if (emisCountryArea == null)
{
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "参数不能为空");
}
if (StringUtils.isEmpty(emisCountryArea.getName()))
{
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "区域名称不能为空");
}
if (StringUtils.isEmpty(emisCountryArea.getNameEn()))
{
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "英文名称不能为空");
}
if (StringUtils.isEmpty(emisCountryArea.getCountryCode()))
{
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "国家不能为空");
}
// countryCode(查询emis_country):前端传的是国家名称 -> 转code回填到同字段
EmisCountry country = emisBaseService.getCountryByName(emisCountryArea.getCountryCode());
if (country == null)
{
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "国家未找到: " + emisCountryArea.getCountryCode());
}
emisCountryArea.setCountryCode(country.getCode());
emisCountryArea.setCountryName(country.getName());
emisCountryAreaService.insertEmisCountryArea(emisCountryArea);
jObjOut.put("countryAreaDetail", emisCountryArea);
}
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

@ -14,9 +14,14 @@ package com.xdadan.erp.web.emis;
import java.util.List; import java.util.List;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import com.alibaba.fastjson.JSONObject;
import com.xdadan.erp.emis.domain.EmisCountryArea;
import com.xdadan.erp.common.annotation.filter.jackson.JacksonFilter; import com.xdadan.erp.common.annotation.filter.jackson.JacksonFilter;
import com.xdadan.erp.emis.domain.enumtype.EmisBizErrorType;
import com.xdadan.erp.emis.domain.exception.EmisBizError;
import com.xdadan.erp.emis.domain.EmisCountry; import com.xdadan.erp.emis.domain.EmisCountry;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
@ -28,7 +33,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import com.xdadan.erp.common.annotation.Log; 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.domain.AjaxResult;
import com.xdadan.erp.common.core.page.TableDataInfo; import com.xdadan.erp.common.core.page.TableDataInfo;
import com.xdadan.erp.common.enums.BusinessType; import com.xdadan.erp.common.enums.BusinessType;
@ -36,7 +40,9 @@ import com.xdadan.erp.common.utils.StringUtils;
import com.xdadan.erp.common.utils.poi.ExcelUtil; import com.xdadan.erp.common.utils.poi.ExcelUtil;
import com.xdadan.erp.emis.domain.EmisRegion; import com.xdadan.erp.emis.domain.EmisRegion;
import com.xdadan.erp.emis.service.EmisBaseService;
import com.xdadan.erp.emis.service.IEmisRegionService; import com.xdadan.erp.emis.service.IEmisRegionService;
import com.xdadan.erp.emis.service.IEmisCountryAreaService;
/** /**
* 四级省市区镇表Controller * 四级省市区镇表Controller
@ -51,6 +57,12 @@ public class EmisRegionController extends EmisBaseController
@Autowired @Autowired
private IEmisRegionService emisRegionService; private IEmisRegionService emisRegionService;
@Autowired
private EmisBaseService emisBaseService;
@Autowired
private IEmisCountryAreaService emisCountryAreaService;
/** /**
* 查询四级省市区镇表列表 * 查询四级省市区镇表列表
*/ */
@ -136,4 +148,100 @@ public class EmisRegionController extends EmisBaseController
{ {
return toAjax(emisRegionService.deleteEmisRegionByIds(ids)); return toAjax(emisRegionService.deleteEmisRegionByIds(ids));
} }
/**
* 草稿方式提交四级省市区镇表(name->code)
*/
@PreAuthorize("@ss.hasPermi('emis:emisRegion:draftSubmitRegion')")
@PostMapping(value = "/draftSubmitRegion")
public AjaxResult draftSubmitRegion(@RequestBody EmisRegion emisRegion)
{
JSONObject jObjOut = new JSONObject();
String result = "success";
String msg = "提交成功";
try
{
if (emisRegion == null)
{
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "参数不能为空");
}
if (StringUtils.isEmpty(emisRegion.getRegionCode()))
{
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "区域代码不能为空");
}
if (StringUtils.isEmpty(emisRegion.getRegionName()))
{
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "区域名称不能为空");
}
if (StringUtils.isEmpty(emisRegion.getCountryCode()))
{
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "国家代码不能为空");
}
// countryCode(查询emis_country):前端传国家名称 -> 转为国家 code
EmisCountry country = emisBaseService.getCountryByName(emisRegion.getCountryCode());
if (country == null)
{
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "国家未找到: " + emisRegion.getCountryCode());
}
emisRegion.setCountryCode(country.getCode());
// sendAreaName/areaName(查询emis_country_area):前端传 name -> 转为对应 id(Long)
if (StringUtils.isNotBlank(emisRegion.getSendAreaName()))
{
String sendAreaName = emisRegion.getSendAreaName();
EmisCountryArea sendAreaQuery = new EmisCountryArea();
sendAreaQuery.setCountryCode(emisRegion.getCountryCode());
sendAreaQuery.setName(sendAreaName);
List<EmisCountryArea> sendAreaList = emisCountryAreaService.selectEmisCountryAreaList(sendAreaQuery);
if (sendAreaList == null || sendAreaList.isEmpty())
{
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "寄件片区未找到: " + sendAreaName);
}
emisRegion.setSendAreaId(sendAreaList.get(0).getId());
}
if (StringUtils.isNotBlank(emisRegion.getAreaName()))
{
String areaName = emisRegion.getAreaName();
EmisCountryArea areaQuery = new EmisCountryArea();
areaQuery.setCountryCode(emisRegion.getCountryCode());
areaQuery.setName(areaName);
List<EmisCountryArea> areaList = emisCountryAreaService.selectEmisCountryAreaList(areaQuery);
if (areaList == null || areaList.isEmpty())
{
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "服务片区未找到: " + areaName);
}
emisRegion.setAreaId(areaList.get(0).getId());
}
emisRegionService.insertEmisRegion(emisRegion);
jObjOut.put("regionDetail", emisRegion);
}
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);
}
} }