demand: 批量导入目的地/国家
This commit is contained in:
parent
38653e1a00
commit
3c576e6d52
@ -16,10 +16,14 @@ import java.util.Arrays;
|
|||||||
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.common.annotation.filter.jackson.JacksonFilter;
|
import com.xdadan.erp.common.annotation.filter.jackson.JacksonFilter;
|
||||||
import com.xdadan.erp.emis.domain.EmisSite;
|
import com.xdadan.erp.emis.domain.EmisContinent;
|
||||||
import com.xdadan.erp.emis.domain.exception.EmisBizError;
|
import com.xdadan.erp.emis.domain.exception.EmisBizError;
|
||||||
|
import com.xdadan.erp.emis.domain.enumtype.EmisBizErrorType;
|
||||||
|
import com.xdadan.erp.emis.service.EmisBaseService;
|
||||||
import com.xdadan.erp.emis.utils.WaybillHelper;
|
import com.xdadan.erp.emis.utils.WaybillHelper;
|
||||||
|
import com.xdadan.erp.emis.service.IEmisContinentService;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.dao.DuplicateKeyException;
|
import org.springframework.dao.DuplicateKeyException;
|
||||||
@ -34,7 +38,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;
|
||||||
@ -56,6 +59,12 @@ public class EmisCountryController extends EmisBaseController
|
|||||||
@Autowired
|
@Autowired
|
||||||
private IEmisCountryService emisCountryService;
|
private IEmisCountryService emisCountryService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IEmisContinentService emisContinentService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private EmisBaseService emisBaseService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询国家列表
|
* 查询国家列表
|
||||||
*/
|
*/
|
||||||
@ -154,7 +163,104 @@ public class EmisCountryController extends EmisBaseController
|
|||||||
return toAjax(emisCountryService.deleteEmisCountryByIds(ids));
|
return toAjax(emisCountryService.deleteEmisCountryByIds(ids));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Excel草稿方式提交国家(name->code)
|
||||||
|
*/
|
||||||
|
@PreAuthorize("@ss.hasPermi('emis:emisCountry:draftSubmitCountry')")
|
||||||
|
@PostMapping(value = "/draftSubmitCountry")
|
||||||
|
public AjaxResult draftSubmitCountry(@RequestBody EmisCountry emisCountry)
|
||||||
|
{
|
||||||
|
JSONObject jObjOut = new JSONObject();
|
||||||
|
String result = "success";
|
||||||
|
String msg = "提交成功";
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (emisCountry == null)
|
||||||
|
{
|
||||||
|
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "参数不能为空");
|
||||||
|
}
|
||||||
|
if (StringUtils.isEmpty(emisCountry.getName()))
|
||||||
|
{
|
||||||
|
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "国家名称不能为空");
|
||||||
|
}
|
||||||
|
if (StringUtils.isEmpty(emisCountry.getNameEn()))
|
||||||
|
{
|
||||||
|
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "英文名称不能为空");
|
||||||
|
}
|
||||||
|
if (StringUtils.isEmpty(emisCountry.getCode()))
|
||||||
|
{
|
||||||
|
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "国家代码不能为空");
|
||||||
|
}
|
||||||
|
if (StringUtils.isEmpty(emisCountry.getContinentId()))
|
||||||
|
{
|
||||||
|
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "continentId不能为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
// continentId(查询emis_continent):支持多个名称用逗号分隔,统一转换为逗号分隔code
|
||||||
|
String[] continentParts = emisCountry.getContinentId().split(",");
|
||||||
|
List<String> continentCodeList = new ArrayList<>();
|
||||||
|
for (String part : continentParts)
|
||||||
|
{
|
||||||
|
String continentNameOrCode = part == null ? "" : part.trim();
|
||||||
|
if (StringUtils.isEmpty(continentNameOrCode))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
EmisContinent continentQuery = new EmisContinent();
|
||||||
|
continentQuery.setName(continentNameOrCode);
|
||||||
|
java.util.List<EmisContinent> continentList = emisContinentService.selectEmisContinentList(continentQuery);
|
||||||
|
if (continentList == null || continentList.isEmpty())
|
||||||
|
{
|
||||||
|
// 兼容:如果本身传的就是code
|
||||||
|
continentQuery = new EmisContinent();
|
||||||
|
continentQuery.setCode(continentNameOrCode);
|
||||||
|
continentList = emisContinentService.selectEmisContinentList(continentQuery);
|
||||||
|
}
|
||||||
|
if (continentList == null || continentList.isEmpty())
|
||||||
|
{
|
||||||
|
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR,
|
||||||
|
"continent未找到: " + continentNameOrCode);
|
||||||
|
}
|
||||||
|
continentCodeList.add(String.valueOf(continentList.get(0).getId()));
|
||||||
|
}
|
||||||
|
if (continentCodeList.isEmpty())
|
||||||
|
{
|
||||||
|
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "continentId不能为空");
|
||||||
|
}
|
||||||
|
emisCountry.setContinentId(String.join(",", continentCodeList));
|
||||||
|
|
||||||
|
emisCountryService.insertEmisCountry(emisCountry);
|
||||||
|
jObjOut.put("countryDetail", emisCountry);
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
// main 方法保留占位,避免生成无用变量告警
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
List<Integer> list = new ArrayList<Integer>();
|
System.out.println(new ArrayList<Integer>().size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,10 +14,15 @@ 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.common.annotation.filter.jackson.JacksonFilter;
|
import com.xdadan.erp.common.annotation.filter.jackson.JacksonFilter;
|
||||||
import com.xdadan.erp.emis.domain.EmisCountry;
|
import com.xdadan.erp.emis.domain.EmisCountry;
|
||||||
|
import com.xdadan.erp.emis.domain.EmisSite;
|
||||||
|
import com.xdadan.erp.emis.domain.enumtype.EmisBizErrorType;
|
||||||
|
import com.xdadan.erp.emis.domain.exception.EmisBizError;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
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;
|
||||||
@ -29,7 +34,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;
|
||||||
@ -37,6 +41,7 @@ import com.xdadan.erp.common.utils.poi.ExcelUtil;
|
|||||||
|
|
||||||
import com.xdadan.erp.emis.domain.EmisDestination;
|
import com.xdadan.erp.emis.domain.EmisDestination;
|
||||||
import com.xdadan.erp.emis.service.IEmisDestinationService;
|
import com.xdadan.erp.emis.service.IEmisDestinationService;
|
||||||
|
import com.xdadan.erp.emis.service.EmisBaseService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 目的地Controller
|
* 目的地Controller
|
||||||
@ -51,6 +56,9 @@ public class EmisDestinationController extends EmisBaseController
|
|||||||
@Autowired
|
@Autowired
|
||||||
private IEmisDestinationService emisDestinationService;
|
private IEmisDestinationService emisDestinationService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private EmisBaseService emisBaseService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询目的地列表
|
* 查询目的地列表
|
||||||
*/
|
*/
|
||||||
@ -184,4 +192,124 @@ public class EmisDestinationController extends EmisBaseController
|
|||||||
{
|
{
|
||||||
return toAjax(emisDestinationService.deleteEmisDestinationByIds(ids));
|
return toAjax(emisDestinationService.deleteEmisDestinationByIds(ids));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Excel/草稿方式提交目的地(名称->code)
|
||||||
|
*/
|
||||||
|
@PreAuthorize("@ss.hasPermi('emis:emisDestination:draftSubmitDestination')")
|
||||||
|
@PostMapping(value = "/draftSubmitDestination")
|
||||||
|
public AjaxResult draftSubmitDestination(@RequestBody EmisDestination emisDestination)
|
||||||
|
{
|
||||||
|
JSONObject jObjOut = new JSONObject();
|
||||||
|
String result = "success";
|
||||||
|
String msg = "提交成功";
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (emisDestination == null)
|
||||||
|
{
|
||||||
|
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "参数不能为空");
|
||||||
|
}
|
||||||
|
if (StringUtils.isEmpty(emisDestination.getDestName()))
|
||||||
|
{
|
||||||
|
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "目的地名称不能为空");
|
||||||
|
}
|
||||||
|
if (StringUtils.isEmpty(emisDestination.getDestCode()))
|
||||||
|
{
|
||||||
|
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "目的地编码不能为空");
|
||||||
|
}
|
||||||
|
if (StringUtils.isEmpty(emisDestination.getCountry()))
|
||||||
|
{
|
||||||
|
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "国家不能为空");
|
||||||
|
}
|
||||||
|
if (StringUtils.isEmpty(emisDestination.getSiteCode()))
|
||||||
|
{
|
||||||
|
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "网点代码不能为空");
|
||||||
|
}
|
||||||
|
if (emisDestination.getStatus() == null)
|
||||||
|
{
|
||||||
|
// 尝试从 params 里取(兼容前端传“启用/未启用”)
|
||||||
|
Object raw = emisDestination.getParams() != null ? emisDestination.getParams().get("status") : null;
|
||||||
|
if (raw == null)
|
||||||
|
{
|
||||||
|
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "启用状态不能为空");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// country(查询emis_country):前端传国家名称 -> 转为国家代码写回country
|
||||||
|
EmisCountry country = emisBaseService.getCountryByName(emisDestination.getCountry());
|
||||||
|
if (country == null)
|
||||||
|
{
|
||||||
|
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR,
|
||||||
|
"国家未找到: " + emisDestination.getCountry());
|
||||||
|
}
|
||||||
|
emisDestination.setCountry(country.getCode());
|
||||||
|
emisDestination.setCountryName(country.getName());
|
||||||
|
|
||||||
|
// status(启用状态 0-未启用 1-启用)
|
||||||
|
Integer status = emisDestination.getStatus();
|
||||||
|
if (status == null && emisDestination.getParams() != null)
|
||||||
|
{
|
||||||
|
Object raw = emisDestination.getParams().get("status");
|
||||||
|
if (raw != null)
|
||||||
|
{
|
||||||
|
String s = String.valueOf(raw).trim();
|
||||||
|
if ("启用".equals(s) || "1".equals(s))
|
||||||
|
{
|
||||||
|
status = 1;
|
||||||
|
}
|
||||||
|
else if ("未启用".equals(s) || "0".equals(s))
|
||||||
|
{
|
||||||
|
status = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (status == null)
|
||||||
|
{
|
||||||
|
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "启用状态不正确/不能为空");
|
||||||
|
}
|
||||||
|
if (status != 0 && status != 1)
|
||||||
|
{
|
||||||
|
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR, "启用状态不正确: " + status);
|
||||||
|
}
|
||||||
|
emisDestination.setStatus(status);
|
||||||
|
|
||||||
|
// siteCode(查询emis_site):前端传网点名称 -> 转为网点代码写回siteCode
|
||||||
|
EmisSite site = emisBaseService.getSiteByName(emisDestination.getSiteCode());
|
||||||
|
if (site == null)
|
||||||
|
{
|
||||||
|
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR,
|
||||||
|
"网点未找到: " + emisDestination.getSiteCode());
|
||||||
|
}
|
||||||
|
emisDestination.setSiteCode(site.getSiteCode());
|
||||||
|
emisDestination.setSiteName(site.getSiteName());
|
||||||
|
|
||||||
|
emisDestinationService.insertEmisDestination(emisDestination);
|
||||||
|
jObjOut.put("destDetail", emisDestination);
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user