From 6ee783234a3edfad710fcafb59b3e3435e80aed7 Mon Sep 17 00:00:00 2001 From: aike <17730485278@139.com> Date: Mon, 23 Mar 2026 13:08:35 +0800 Subject: [PATCH] =?UTF-8?q?demand:=20=20=20=20=20tms-=E5=9F=BA=E7=A1=80?= =?UTF-8?q?=E7=AE=A1=E7=90=86-=E7=BD=91=E7=82=B9=E7=AE=A1=E7=90=86-?= =?UTF-8?q?=E6=89=B9=E9=87=8F=E5=AF=BC=E5=85=A5=E7=BD=91=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../erp/web/emis/EmisSiteController.java | 49 ++++- .../erp/emis/service/IEmisSiteService.java | 27 ++- .../service/impl/EmisSiteServiceImpl.java | 201 +++++++++++++++++- 3 files changed, 247 insertions(+), 30 deletions(-) diff --git a/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisSiteController.java b/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisSiteController.java index 824a69120..436a2191e 100644 --- a/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisSiteController.java +++ b/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisSiteController.java @@ -1,11 +1,11 @@ -/** +/** * @Project: emis * @Title: EmisSiteController.java * @author linfso * @date 2023-12-14 13:02:46 * @Copyright: ShangHai Duta 2022 All rights reserved. - * @version v1.0 + * @version v1.0 * @Description:

网点 控制器

*/ @@ -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; @@ -46,7 +43,7 @@ import com.xdadan.erp.emis.service.IEmisSiteService; /** * 网点Controller - * + * * @author linfso * @date 2023-12-14 13:02:46 */ @@ -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); + } /** * 查询网点列表 diff --git a/emis-biz/src/main/java/com/xdadan/erp/emis/service/IEmisSiteService.java b/emis-biz/src/main/java/com/xdadan/erp/emis/service/IEmisSiteService.java index 97eff13f1..91ea514f5 100644 --- a/emis-biz/src/main/java/com/xdadan/erp/emis/service/IEmisSiteService.java +++ b/emis-biz/src/main/java/com/xdadan/erp/emis/service/IEmisSiteService.java @@ -1,10 +1,10 @@ - /** + /** * @Project: emis * @Title: EmisSiteService.java * @author linfso * @date 2023-12-14 13:02:46 * @Copyright: ShangHai Duta 2022 All rights reserved. - * @version v1.0 + * @version v1.0 * @Description:

网点 服务类接口

*/ package com.xdadan.erp.emis.service; @@ -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 @@ -20,18 +21,18 @@ import com.xdadan.erp.emis.domain.EmisSite; * @author linfso * @date 2023-12-14 13:02:46 */ -public interface IEmisSiteService +public interface IEmisSiteService { /** * 主键查询 * @param id - * @return + * @return */ public EmisSite selectEmisSiteById(Long id); /** * 查询网点列表 - * + * * @param emisSite 网点 * @return 网点集合 */ @@ -47,7 +48,7 @@ public interface IEmisSiteService /** * 新增网点 - * + * * @param emisSite 网点 * @return 结果 */ @@ -55,7 +56,7 @@ public interface IEmisSiteService /** * 修改网点 - * + * * @param emisSite 网点 * @return 结果 */ @@ -63,7 +64,7 @@ public interface IEmisSiteService /** * 批量删除网点 - * + * * @param ids 需要删除的网点主键集合 * @return 结果 */ @@ -71,7 +72,7 @@ public interface IEmisSiteService /** * 删除网点信息 - * + * * @param id 网点主键 * @return 结果 */ @@ -91,4 +92,12 @@ public interface IEmisSiteService * @return */ List selectSiteByConditions(EmisSite emisSite); + + /** + * Excel草稿方式新增网点(带参数校验/转换) + * + * @param emisSite 网点 + * @return 结果 + */ + int draftSubmitSite(EmisSite emisSite) throws EmisBizError; } diff --git a/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisSiteServiceImpl.java b/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisSiteServiceImpl.java index 3341ea73d..abf2b512b 100644 --- a/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisSiteServiceImpl.java +++ b/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisSiteServiceImpl.java @@ -1,26 +1,34 @@ - /** + /** * @Project: emis * @Title: EmisSiteServiceImpl.java * @author linfso * @date 2023-12-14 13:02:46 * @Copyright: ShangHai Duta 2022 All rights reserved. - * @version v1.0 + * @version v1.0 * @Description:

网点 实体类

*/ 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; @@ -30,7 +38,7 @@ import org.springframework.transaction.annotation.Transactional; /** * 网点Service业务层处理 - * + * * @author linfso * @date 2023-12-14 13:02:46 */ @@ -47,10 +55,13 @@ public class EmisSiteServiceImpl extends EmisBaseService implements IEmisSiteSer @Autowired private EmisSiteAccountMapper emisSiteAccountMapper; + @Autowired + private EmisBrandMapper emisBrandMapper; + /** * 查询网点 - * + * * @param id 网点主键 * @return 网点 */ @@ -62,7 +73,7 @@ public class EmisSiteServiceImpl extends EmisBaseService implements IEmisSiteSer /** * 查询网点列表 - * + * * @param emisSite 网点 * @return 网点 */ @@ -80,7 +91,7 @@ public class EmisSiteServiceImpl extends EmisBaseService implements IEmisSiteSer /** * 新增网点 - * + * * @param emisSite 网点 * @return 结果 */ @@ -153,7 +164,7 @@ public class EmisSiteServiceImpl extends EmisBaseService implements IEmisSiteSer /** * 修改网点 - * + * * @param emisSite 网点 * @return 结果 */ @@ -165,7 +176,7 @@ public class EmisSiteServiceImpl extends EmisBaseService implements IEmisSiteSer /** * 批量删除网点 - * + * * @param ids 需要删除的网点主键 * @return 结果 */ @@ -177,7 +188,7 @@ public class EmisSiteServiceImpl extends EmisBaseService implements IEmisSiteSer /** * 删除网点信息 - * + * * @param id 网点主键 * @return 结果 */ @@ -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 codeList = new ArrayList<>(); + List 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 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); + } + } + }