diff --git a/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisCountryAreaController.java b/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisCountryAreaController.java index 56600a496..6409aec8c 100644 --- a/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisCountryAreaController.java +++ b/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisCountryAreaController.java @@ -1,11 +1,11 @@ -/** +/** * @Project: emis * @Title: EmisCountryAreaController.java * @author linfso * @date 2023-11-16 16:18:40 * @Copyright: ShangHai Duta 2022 All rights reserved. - * @version v1.0 + * @version v1.0 * @Description:
国家大区表 控制器
*/ @@ -13,8 +13,11 @@ package com.xdadan.erp.web.emis; import java.util.List; import javax.servlet.http.HttpServletResponse; + +import com.alibaba.fastjson.JSONObject; import org.springframework.beans.factory.annotation.Autowired; 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.PostMapping; import org.springframework.web.bind.annotation.PutMapping; @@ -25,19 +28,22 @@ 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; import com.xdadan.erp.common.utils.StringUtils; 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.enumtype.EmisBizErrorType; +import com.xdadan.erp.emis.domain.exception.EmisBizError; import com.xdadan.erp.emis.service.IEmisCountryAreaService; +import com.xdadan.erp.emis.service.EmisBaseService; /** * 国家大区表Controller - * + * * @author linfso * @date 2023-11-16 16:18:40 */ @@ -48,6 +54,9 @@ public class EmisCountryAreaController extends EmisBaseController @Autowired private IEmisCountryAreaService emisCountryAreaService; + @Autowired + private EmisBaseService emisBaseService; + /** * 查询国家大区表列表 */ @@ -115,4 +124,72 @@ public class EmisCountryAreaController extends EmisBaseController { 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); + } } diff --git a/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisRegionController.java b/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisRegionController.java index 2a4f7e4ef..0217568cf 100644 --- a/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisRegionController.java +++ b/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisRegionController.java @@ -1,11 +1,11 @@ -/** +/** * @Project: emis * @Title: EmisRegionController.java * @author linfso * @date 2023-11-16 16:18:40 * @Copyright: ShangHai Duta 2022 All rights reserved. - * @version v1.0 + * @version v1.0 * @Description:四级省市区镇表 控制器
*/ @@ -14,9 +14,14 @@ package com.xdadan.erp.web.emis; import java.util.List; 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.emis.domain.enumtype.EmisBizErrorType; +import com.xdadan.erp.emis.domain.exception.EmisBizError; import com.xdadan.erp.emis.domain.EmisCountry; 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; @@ -28,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; @@ -36,11 +40,13 @@ import com.xdadan.erp.common.utils.StringUtils; import com.xdadan.erp.common.utils.poi.ExcelUtil; 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.IEmisCountryAreaService; /** * 四级省市区镇表Controller - * + * * @author linfso * @date 2023-11-16 16:18:40 */ @@ -51,6 +57,12 @@ public class EmisRegionController extends EmisBaseController @Autowired 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)); } + + /** + * 草稿方式提交四级省市区镇表(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