Merge pull request 'demand: 批量导入线路/产品类型' (#332) from develop into master

Reviewed-on: http://git.xdadan.loc/tanex/emis-service/pulls/332
This commit is contained in:
heyu 2026-03-24 16:59:18 +08:00
commit 5f0228bee5
4 changed files with 295 additions and 22 deletions

View File

@ -1,11 +1,11 @@
/**
/**
* @Project: emis
* @Title: EmisTransLineController.java
* @author linfso
* @date 2023-12-14 13:02:47
* @Copyright: ShangHai Duta 2022 All rights reserved.
* @version v1.0
* @version v1.0
* @Description: <p> 线路 控制器 </p>
*/
@ -14,12 +14,13 @@ package com.xdadan.erp.web.emis;
import java.util.List;
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.EmisCountry;
import com.xdadan.erp.emis.domain.EmisSite;
import com.xdadan.erp.emis.service.EmisBaseService;
import org.apache.commons.lang3.StringUtils;
import com.xdadan.erp.emis.domain.exception.EmisBizError;
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;
@ -31,7 +32,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;
@ -42,7 +42,7 @@ import com.xdadan.erp.emis.service.IEmisTransLineService;
/**
* 线路Controller
*
*
* @author linfso
* @date 2023-12-14 13:02:47
*/
@ -56,6 +56,39 @@ public class EmisTransLineController extends EmisBaseController
@Autowired
private EmisBaseService emisBaseService;
/**
* Excel草稿方式新增线路
*/
@PreAuthorize("@ss.hasPermi('emis:emisTransLine:draftSubmitTransLine')")
@PostMapping(value = "/draftSubmitTransLine")
public AjaxResult draftSubmitTransLine(@RequestBody EmisTransLine emisTransLine) {
JSONObject jObjOut = new JSONObject();
String result = "success";
String msg = "提交成功";
try {
emisTransLineService.draftSubmitTransLine(emisTransLine);
jObjOut.put("transLineDetail", emisTransLine);
} 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

@ -1,11 +1,11 @@
/**
/**
* @Project: emis
* @Title: EmisTransProductController.java
* @author linfso
* @date 2024-01-09 11:50:34
* @Copyright: ShangHai Duta 2022 All rights reserved.
* @version v1.0
* @version v1.0
* @Description: <p> 运输产品类型 控制器 </p>
*/
@ -15,8 +15,15 @@ import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.xdadan.erp.common.annotation.filter.jackson.JacksonFilter;
import com.xdadan.erp.emis.domain.EmisBrand;
import com.xdadan.erp.emis.domain.EmisCountry;
import com.xdadan.erp.emis.domain.EmisTransLine;
import com.xdadan.erp.emis.domain.enumtype.EmisBizErrorType;
import com.xdadan.erp.emis.domain.exception.EmisBizError;
import org.springframework.beans.factory.annotation.Autowired;
import com.xdadan.erp.common.utils.DictUtils;
import com.xdadan.erp.emis.service.EmisBaseService;
import org.springframework.dao.DuplicateKeyException;
import com.alibaba.fastjson.JSONObject;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
@ -28,7 +35,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;
@ -40,7 +46,7 @@ import com.xdadan.erp.emis.service.IEmisTransProductService;
/**
* 运输产品类型Controller
*
*
* @author linfso
* @date 2024-01-09 11:50:34
*/
@ -51,6 +57,9 @@ public class EmisTransProductController extends EmisBaseController
@Autowired
private IEmisTransProductService emisTransProductService;
@Autowired
private EmisBaseService emisBaseService;
/**
* 查询运输产品类型列表
*/
@ -129,4 +138,103 @@ public class EmisTransProductController extends EmisBaseController
{
return toAjax(emisTransProductService.deleteEmisTransProductByIds(ids));
}
/**
* Excel/草稿方式提交运输产品(名称->code)
*/
@PreAuthorize("@ss.hasPermi('emis:emisTransProduct:draftSubmitProduct')")
@PostMapping(value = "/draftSubmitProduct")
public AjaxResult draftSubmitProduct(@RequestBody EmisTransProduct emisTransProduct)
{
JSONObject jObjOut = new JSONObject();
String result = "success";
String msg = "提交成功";
try {
if (emisTransProduct == null) {
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "参数不能为空");
}
if (StringUtils.isEmpty(emisTransProduct.getProdName())) {
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "产品名称不能为空");
}
if (StringUtils.isEmpty(emisTransProduct.getProdNameEn())) {
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "英文名称不能为空");
}
if (StringUtils.isEmpty(emisTransProduct.getCountry())) {
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "所属国家不能为空");
}
if (StringUtils.isEmpty(emisTransProduct.getTransLineCode())) {
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "所属线路不能为空");
}
if (StringUtils.isEmpty(emisTransProduct.getCarryType())) {
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "取重方式不能为空");
}
if (StringUtils.isEmpty(emisTransProduct.getAgingDesc())) {
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "时效描述不能为空");
}
if (emisTransProduct.getMinAging() == null) {
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "最小时效不能为空");
}
if (emisTransProduct.getMaxAging() == null) {
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "最大时效不能为空");
}
if (emisTransProduct.getStatus() == null) {
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "启用状态不能为空");
}
// country(查询emis_country):name -> code
EmisCountry country = emisBaseService.getCountryByName(emisTransProduct.getCountry());
if (country == null) {
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR,
"国家未找到: " + emisTransProduct.getCountry());
}
emisTransProduct.setCountry(country.getCode());
emisTransProduct.setCountryName(country.getName());
// status(启用状态 0-未启用 1-启用)
if (emisTransProduct.getStatus() != 0 && emisTransProduct.getStatus() != 1) {
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "启用状态不正确: " + emisTransProduct.getStatus());
}
// transLineCode(查询emis_trans_line):name -> code
EmisTransLine transLine = emisBaseService.getTransLineByName(emisTransProduct.getTransLineCode());
if (transLine == null) {
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR,
"线路未找到: " + emisTransProduct.getTransLineCode());
}
emisTransProduct.setTransLineCode(transLine.getLineCode());
emisTransProduct.setTransLine(transLine.getLineName());
// carryType(字典emis_take_weight_method):name -> code
String carryTypeName = emisTransProduct.getCarryType();
String carryTypeCode = DictUtils.getDictValue("emis_take_weight_method", carryTypeName);
if (StringUtils.isEmpty(carryTypeCode)) {
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "取重方式不正确: " + carryTypeName);
}
emisTransProduct.setCarryType(carryTypeCode);
// 仅用于返回展示
emisTransProduct.getParams().put("carryTypeName",
DictUtils.getDictLabel("emis_take_weight_method", carryTypeCode));
emisTransProductService.insertEmisTransProduct(emisTransProduct);
jObjOut.put("productDetail", emisTransProduct);
} 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

@ -11,6 +11,7 @@ package com.xdadan.erp.emis.service;
import java.util.List;
import com.xdadan.erp.emis.domain.EmisTransLine;
import com.xdadan.erp.emis.domain.exception.EmisBizError;
/**
* @ClassName EmisTransLineService
@ -66,4 +67,12 @@ public interface IEmisTransLineService
* @return 结果
*/
public int deleteEmisTransLineById(Long id);
/**
* Excel草稿方式新增线路(带参数校验/转换)
*
* @param emisTransLine 线路
* @return 结果
*/
int draftSubmitTransLine(EmisTransLine emisTransLine) throws EmisBizError;
}

View File

@ -1,10 +1,10 @@
/**
/**
* @Project: emis
* @Title: EmisTransLineServiceImpl.java
* @author linfso
* @date 2023-12-14 13:02:47
* @Copyright: ShangHai Duta 2022 All rights reserved.
* @version v1.0
* @version v1.0
* @Description: <p> 线路 实体类 </p>
*/
@ -13,28 +13,40 @@ package com.xdadan.erp.emis.service.impl;
import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
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.enumtype.EmisBizErrorType;
import com.xdadan.erp.emis.domain.exception.EmisBizError;
import com.xdadan.erp.emis.mapper.EmisBrandMapper;
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.EmisTransLine;
import com.xdadan.erp.emis.mapper.EmisTransLineMapper;
import com.xdadan.erp.emis.service.IEmisTransLineService;
import org.springframework.transaction.annotation.Transactional;
/**
* 线路Service业务层处理
*
*
* @author linfso
* @date 2023-12-14 13:02:47
*/
@Service
public class EmisTransLineServiceImpl implements IEmisTransLineService
public class EmisTransLineServiceImpl extends EmisBaseService implements IEmisTransLineService
{
@Autowired
private EmisTransLineMapper emisTransLineMapper;
@Autowired
private EmisBrandMapper emisBrandMapper;
/**
* 查询线路
*
*
* @param id 线路主键
* @return 线路
*/
@ -46,7 +58,7 @@ public class EmisTransLineServiceImpl implements IEmisTransLineService
/**
* 查询线路列表
*
*
* @param emisTransLine 线路
* @return 线路
*/
@ -58,7 +70,7 @@ public class EmisTransLineServiceImpl implements IEmisTransLineService
/**
* 新增线路
*
*
* @param emisTransLine 线路
* @return 结果
*/
@ -66,7 +78,7 @@ public class EmisTransLineServiceImpl implements IEmisTransLineService
public int insertEmisTransLine(EmisTransLine emisTransLine)
{
// 获取线路编号
QueryWrapper<EmisTransLine> queryWrapper=new QueryWrapper();
QueryWrapper<EmisTransLine> queryWrapper=new QueryWrapper<>();
queryWrapper.eq("country",emisTransLine.getCountry());
Long count = emisTransLineMapper.selectCount(queryWrapper);
String lineCode=emisTransLine.getCountry()+"-"+ StringUtils.leftPad(String.valueOf(count),3,"0");
@ -82,7 +94,7 @@ public class EmisTransLineServiceImpl implements IEmisTransLineService
/**
* 修改线路
*
*
* @param emisTransLine 线路
* @return 结果
*/
@ -95,7 +107,7 @@ public class EmisTransLineServiceImpl implements IEmisTransLineService
/**
* 批量删除线路
*
*
* @param ids 需要删除的线路主键
* @return 结果
*/
@ -107,7 +119,7 @@ public class EmisTransLineServiceImpl implements IEmisTransLineService
/**
* 删除线路信息
*
*
* @param id 线路主键
* @return 结果
*/
@ -117,4 +129,115 @@ public class EmisTransLineServiceImpl implements IEmisTransLineService
return emisTransLineMapper.deleteEmisTransLineById(id);
}
/**
* Excel草稿方式新增线路(带参数校验/转换)
*/
@Override
@Transactional
public int draftSubmitTransLine(EmisTransLine emisTransLine) throws EmisBizError {
checkRequired(emisTransLine);
fillNamesByCodes(emisTransLine);
return insertEmisTransLine(emisTransLine);
}
private static void checkRequired(EmisTransLine emisTransLine) throws EmisBizError {
if (emisTransLine == null) {
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "参数不能为空");
}
if (StringUtil.isBlank(emisTransLine.getLineName())) {
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "线路名称不能为空");
}
if (StringUtil.isBlank(emisTransLine.getFromCountry())) {
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "起始国不能为空");
}
if (StringUtil.isBlank(emisTransLine.getCountry())) {
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "目的国家不能为空");
}
if (StringUtil.isBlank(emisTransLine.getMeterRate())) {
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "计泡方式不能为空");
}
if (StringUtil.isBlank(emisTransLine.getLogoType())) {
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "所属品牌不能为空");
}
if (StringUtil.isBlank(emisTransLine.getTransType())) {
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "运输方式不能为空");
}
if (StringUtil.isBlank(emisTransLine.getApplyScope())) {
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "适用范围不能为空");
}
if (emisTransLine.getStatus() == null) {
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "启用状态不能为空");
}
}
private void fillNamesByCodes(EmisTransLine emisTransLine) throws EmisBizError {
// transType(字典emis_biz_shipping_method)
String transTypeInput = emisTransLine.getTransType();
String transTypeCode = DictUtils.getDictValue("emis_biz_shipping_method", transTypeInput);
if (StringUtils.isBlank(transTypeCode)) {
transTypeCode = transTypeInput;
}
String transTypeName = DictUtils.getDictLabel("emis_biz_shipping_method", transTypeCode);
if (StringUtils.isBlank(transTypeName)) {
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "运输方式不正确: " + transTypeInput);
}
emisTransLine.setTransType(transTypeCode);
emisTransLine.getParams().put("transTypeName", transTypeName);
// fromCountry/country(emis_country)
EmisCountry fromCountry = getCountryByName(emisTransLine.getFromCountry());
if (fromCountry == null) {
fromCountry = getCountryByCode(emisTransLine.getFromCountry());
}
if (fromCountry == null) {
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "起始国未找到: " + emisTransLine.getFromCountry());
}
emisTransLine.setFromCountry(fromCountry.getCode());
emisTransLine.setFromCountryName(fromCountry.getName());
EmisCountry country = getCountryByName(emisTransLine.getCountry());
if (country == null) {
country = getCountryByCode(emisTransLine.getCountry());
}
if (country == null) {
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "目的国家未找到: " + emisTransLine.getCountry());
}
emisTransLine.setCountry(country.getCode());
emisTransLine.setCountryName(country.getName());
// status(启用状态 0-未启用 1-启用)
Integer status = emisTransLine.getStatus();
if (status == null || (status != 0 && status != 1)) {
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "启用状态不正确: " + status);
}
emisTransLine.getParams().put("statusName", status == 1 ? "启用" : "未启用");
// logoType(emis_brand):先按名称转 code 回填;全品牌 → -1
if ("全品牌".equals(emisTransLine.getLogoType()) || "-1".equals(emisTransLine.getLogoType())) {
emisTransLine.setLogoType("-1");
emisTransLine.setLogoTypeName("全品牌");
return;
}
EmisBrand queryByName = new EmisBrand();
queryByName.setName(emisTransLine.getLogoType());
List<EmisBrand> byName = emisBrandMapper.selectEmisBrandList(queryByName);
if (byName != null && !byName.isEmpty()) {
emisTransLine.setLogoType(byName.get(0).getCode());
emisTransLine.setLogoTypeName(byName.get(0).getName());
return;
}
EmisBrand queryByCode = new EmisBrand();
queryByCode.setCode(emisTransLine.getLogoType());
List<EmisBrand> byCode = emisBrandMapper.selectEmisBrandList(queryByCode);
if (byCode != null && !byCode.isEmpty()) {
emisTransLine.setLogoType(byCode.get(0).getCode());
emisTransLine.setLogoTypeName(byCode.get(0).getName());
return;
}
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "品牌未找到: " + emisTransLine.getLogoType());
}
}