demand: 供应商线路管理页面自测bug修改
committer: heyu
This commit is contained in:
parent
b8f1d1b01d
commit
7b91aad79c
@ -1,13 +1,10 @@
|
||||
package com.xdadan.erp.web.emis;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.xdadan.erp.common.annotation.filter.jackson.JacksonFilter;
|
||||
import com.xdadan.erp.common.core.domain.AjaxResult;
|
||||
import com.xdadan.erp.common.core.page.TableDataInfo;
|
||||
import com.xdadan.erp.emis.domain.EmisSupplier;
|
||||
import com.xdadan.erp.emis.domain.EmisWaybill;
|
||||
import com.xdadan.erp.emis.domain.exception.EmisBizError;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -47,7 +44,7 @@ public class EmisTransPlanRuleController extends EmisBaseController {
|
||||
/**
|
||||
* 查询供应商线路规划列表
|
||||
*/
|
||||
// @PreAuthorize("@ss.hasPermi('emis:rule:list')")
|
||||
@PreAuthorize("@ss.hasPermi('emis:emisTransPlanRule:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(EmisTransPlanRule emisTransPlanRule) {
|
||||
startPage();
|
||||
@ -58,7 +55,7 @@ public class EmisTransPlanRuleController extends EmisBaseController {
|
||||
/**
|
||||
* 获取供应商线路规划详细信息
|
||||
*/
|
||||
// @PreAuthorize("@ss.hasPermi('emis:rule:query')")
|
||||
@PreAuthorize("@ss.hasPermi('emis:emisTransPlanRule:query')")
|
||||
@GetMapping(value = "/{id}")
|
||||
public AjaxResult getInfo(@PathVariable("id") Long id) {
|
||||
return AjaxResult.success(emisTransPlanRuleService.selectEmisTransPlanRuleById(id));
|
||||
@ -67,7 +64,7 @@ public class EmisTransPlanRuleController extends EmisBaseController {
|
||||
/**
|
||||
* 新增供应商线路规划
|
||||
*/
|
||||
// @PreAuthorize("@ss.hasPermi('emis:rule:add')")
|
||||
@PreAuthorize("@ss.hasPermi('emis:emisTransPlanRule:add')")
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody EmisTransPlanRule emisTransPlanRule) throws EmisBizError {
|
||||
return toAjax(emisTransPlanRuleService.insertEmisTransPlanRule(emisTransPlanRule));
|
||||
@ -76,7 +73,7 @@ public class EmisTransPlanRuleController extends EmisBaseController {
|
||||
/**
|
||||
* 修改供应商线路规划
|
||||
*/
|
||||
// @PreAuthorize("@ss.hasPermi('emis:rule:edit')")
|
||||
@PreAuthorize("@ss.hasPermi('emis:emisTransPlanRule:edit')")
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody EmisTransPlanRule emisTransPlanRule) throws EmisBizError {
|
||||
return toAjax(emisTransPlanRuleService.updateEmisTransPlanRule(emisTransPlanRule));
|
||||
@ -85,7 +82,7 @@ public class EmisTransPlanRuleController extends EmisBaseController {
|
||||
/**
|
||||
* 删除供应商线路规划
|
||||
*/
|
||||
// @PreAuthorize("@ss.hasPermi('emis:rule:remove')")
|
||||
@PreAuthorize("@ss.hasPermi('emis:emisTransPlanRule:remove')")
|
||||
@DeleteMapping("/{ids}")
|
||||
public AjaxResult remove(@PathVariable Long[] ids) throws EmisBizError {
|
||||
return toAjax(emisTransPlanRuleService.deleteEmisTransPlanRuleByIds(ids));
|
||||
@ -94,8 +91,9 @@ public class EmisTransPlanRuleController extends EmisBaseController {
|
||||
/**
|
||||
* 查询供应商线路规划树结构
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('emis:emisTransPlanRule:tree')")
|
||||
@GetMapping("/tree")
|
||||
public TableDataInfo tree(String lineName) {
|
||||
return getDataTable(emisTransPlanRuleService.selectEmisTransPlanRuleTree(lineName));
|
||||
public TableDataInfo tree(String lineCode) {
|
||||
return getDataTable(emisTransPlanRuleService.selectEmisTransPlanRuleTree(lineCode));
|
||||
}
|
||||
}
|
||||
@ -24,7 +24,10 @@ public class EmisTransPlanRule extends BaseEntity {
|
||||
/** 祖先节点 */
|
||||
private String ancestors;
|
||||
|
||||
/** 线路名称 */
|
||||
/** 线路编码 */
|
||||
private String lineCode;
|
||||
|
||||
/** 线路名称 (仅用于查询结果) */
|
||||
private String lineName;
|
||||
|
||||
/** 运输方式 */
|
||||
|
||||
@ -21,13 +21,21 @@ public interface EmisTransPlanRuleMapper {
|
||||
public EmisTransPlanRule selectEmisTransPlanRuleById(Long id);
|
||||
|
||||
/**
|
||||
* 查询供应商线路规划列表
|
||||
* 查询供应商线路规划列表,过滤根节点
|
||||
*
|
||||
* @param emisTransPlanRule 供应商线路规划
|
||||
* @return 供应商线路规划集合
|
||||
*/
|
||||
public List<EmisTransPlanRule> selectEmisTransPlanRuleList(EmisTransPlanRule emisTransPlanRule);
|
||||
|
||||
/**
|
||||
* 查询供应商线路规划列表,查询包括根节点
|
||||
*
|
||||
* @param emisTransPlanRule 供应商线路规划
|
||||
* @return 供应商线路规划集合
|
||||
*/
|
||||
public List<EmisTransPlanRule> getEmisTransPlanRuleList(EmisTransPlanRule emisTransPlanRule);
|
||||
|
||||
/**
|
||||
* 查询子节点列表
|
||||
*
|
||||
@ -60,14 +68,6 @@ public interface EmisTransPlanRuleMapper {
|
||||
*/
|
||||
public int updateEmisTransPlanRule(EmisTransPlanRule emisTransPlanRule);
|
||||
|
||||
/**
|
||||
* 修改子元素关系
|
||||
*
|
||||
* @param children 子元素
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateEmisTransPlanRuleChildren(List<EmisTransPlanRule> children);
|
||||
|
||||
/**
|
||||
* 删除供应商线路规划
|
||||
*
|
||||
@ -100,13 +100,19 @@ public interface EmisTransPlanRuleMapper {
|
||||
*/
|
||||
public String selectProductTypeNamesByCodes(@Param("productType") String productType);
|
||||
|
||||
List<EmisTransPlanRule> selectEmisTransPlanRuleTree(EmisTransPlanRule emisTransPlanRule);
|
||||
/**
|
||||
* 查询每个供应商编码对应的名称
|
||||
*
|
||||
* @param supplierCodes
|
||||
* @return map
|
||||
*/
|
||||
List<Map<String, String>> selectSupplierInfoByCodes(List<String> supplierCodes);
|
||||
|
||||
/**
|
||||
* 根据条件查询供应商信息
|
||||
* 查询每个产品编码对应的名称
|
||||
*
|
||||
* @param emisTransPlanRule 查询条件
|
||||
* @return 供应商信息列表
|
||||
* @param productTypes
|
||||
* @return map
|
||||
*/
|
||||
List<EmisTransPlanRule> selectSupplierInfoByConditions(EmisTransPlanRule emisTransPlanRule);
|
||||
List<Map<String, String>> selectProductTypeInfoByCodes(List<String> productTypes);
|
||||
}
|
||||
@ -62,10 +62,10 @@ public interface IEmisTransPlanRuleService {
|
||||
/**
|
||||
* 查询供应商线路规划树结构
|
||||
*
|
||||
* @param lineName 线路名称
|
||||
* @param lineCode 线路编码
|
||||
* @return 供应商线路规划树结构
|
||||
*/
|
||||
public List<EmisTransPlanRule> selectEmisTransPlanRuleTree(String lineName);
|
||||
public List<EmisTransPlanRule> selectEmisTransPlanRuleTree(String lineCode);
|
||||
|
||||
/**
|
||||
* 根据条件查询供应商信息
|
||||
|
||||
@ -6,18 +6,22 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.beust.jcommander.internal.Lists;
|
||||
import com.xdadan.erp.emis.domain.enumtype.EmisBizErrorType;
|
||||
import com.xdadan.erp.emis.domain.exception.EmisBizError;
|
||||
import jodd.util.StringUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.xdadan.erp.emis.domain.EmisTransPlanRule;
|
||||
import com.xdadan.erp.emis.domain.EmisTransLine;
|
||||
import com.xdadan.erp.emis.mapper.EmisTransPlanRuleMapper;
|
||||
import com.xdadan.erp.emis.mapper.EmisTransLineMapper;
|
||||
import com.xdadan.erp.emis.service.IEmisTransPlanRuleService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -29,12 +33,15 @@ import org.slf4j.LoggerFactory;
|
||||
* @date 2024-04-22
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class EmisTransPlanRuleServiceImpl implements IEmisTransPlanRuleService {
|
||||
private static final Logger log = LoggerFactory.getLogger(EmisTransPlanRuleServiceImpl.class);
|
||||
|
||||
@Autowired
|
||||
private EmisTransPlanRuleMapper emisTransPlanRuleMapper;
|
||||
|
||||
@Autowired
|
||||
private EmisTransLineMapper emisTransLineMapper;
|
||||
|
||||
/**
|
||||
* 查询供应商线路规划
|
||||
*
|
||||
@ -43,26 +50,50 @@ public class EmisTransPlanRuleServiceImpl implements IEmisTransPlanRuleService {
|
||||
*/
|
||||
@Override
|
||||
public EmisTransPlanRule selectEmisTransPlanRuleById(Long id) {
|
||||
log.info("Start querying supplier route plan, ID={}", id);
|
||||
EmisTransPlanRule rule = emisTransPlanRuleMapper.selectEmisTransPlanRuleById(id);
|
||||
if (rule != null) {
|
||||
setSupplierNames(Collections.singletonList(rule));
|
||||
setProductTypeNames(Collections.singletonList(rule));
|
||||
log.info("Found supplier route plan, ID={}", id);
|
||||
setName(Collections.singletonList(rule));
|
||||
} else {
|
||||
log.warn("Supplier route plan not found, ID={}", id);
|
||||
}
|
||||
return rule;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询供应商线路规划列表
|
||||
*
|
||||
* 查询供应商线路规划列表,过滤根节点
|
||||
*
|
||||
* @param emisTransPlanRule 供应商线路规划
|
||||
* @return 供应商线路规划
|
||||
*/
|
||||
@Override
|
||||
public List<EmisTransPlanRule> selectEmisTransPlanRuleList(EmisTransPlanRule emisTransPlanRule) {
|
||||
log.info("Start querying supplier route plan list, query={}", emisTransPlanRule);
|
||||
List<EmisTransPlanRule> list = emisTransPlanRuleMapper.selectEmisTransPlanRuleList(emisTransPlanRule);
|
||||
log.info("Found supplier route plan list, count={}", list != null ? list.size() : 0);
|
||||
setName(list);
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询供应商线路规划列表,查询包括根节点
|
||||
*
|
||||
* @param emisTransPlanRule 供应商线路规划
|
||||
* @return 供应商线路规划
|
||||
*/
|
||||
public List<EmisTransPlanRule> getEmisTransPlanRuleList(EmisTransPlanRule emisTransPlanRule) {
|
||||
log.info("Start getting supplier route plan list, query={}", emisTransPlanRule);
|
||||
List<EmisTransPlanRule> list = emisTransPlanRuleMapper.getEmisTransPlanRuleList(emisTransPlanRule);
|
||||
log.info("Got supplier route plan list, count={}", list != null ? list.size() : 0);
|
||||
setName(list);
|
||||
return list;
|
||||
}
|
||||
|
||||
private void setName(List<EmisTransPlanRule> list) {
|
||||
setSupplierNames(list);
|
||||
setProductTypeNames(list);
|
||||
return list;
|
||||
setLineName(list);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -70,15 +101,47 @@ public class EmisTransPlanRuleServiceImpl implements IEmisTransPlanRuleService {
|
||||
*/
|
||||
private void setSupplierNames(List<EmisTransPlanRule> rules) {
|
||||
if (rules == null || rules.isEmpty()) {
|
||||
log.info("Setting supplier names: rules list is empty");
|
||||
return;
|
||||
}
|
||||
for (EmisTransPlanRule rule : rules) {
|
||||
if (StringUtils.hasText(rule.getSupplierCode())) {
|
||||
String supplierNames = emisTransPlanRuleMapper.selectSupplierNamesByCodes(rule.getSupplierCode());
|
||||
if(StringUtil.isEmpty(supplierNames)){
|
||||
return;
|
||||
}
|
||||
rule.setSupplierName(supplierNames);
|
||||
// 收集所有需要查询的供应商编码
|
||||
List<String> supplierCodes = rules.stream()
|
||||
.map(EmisTransPlanRule::getSupplierCode)
|
||||
.filter(StringUtils::hasText)
|
||||
.flatMap(code -> Arrays.stream(code.split(",")))
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
log.info("Setting supplier names: code count={}, codes={}", supplierCodes.size(), supplierCodes);
|
||||
|
||||
if (!supplierCodes.isEmpty()) {
|
||||
// 批量查询供应商信息
|
||||
List<Map<String, String>> supplierInfos = emisTransPlanRuleMapper.selectSupplierInfoByCodes(supplierCodes);
|
||||
log.info("Setting supplier names: found supplier info count={}",
|
||||
supplierInfos != null ? supplierInfos.size() : 0);
|
||||
|
||||
if (supplierInfos != null && !supplierInfos.isEmpty()) {
|
||||
// 创建供应商编码到名称的映射
|
||||
Map<String, String> supplierCodeToNameMap = supplierInfos.stream()
|
||||
.collect(Collectors.toMap(
|
||||
info -> info.get("code"),
|
||||
info -> info.get("name"),
|
||||
(existing, replacement) -> existing));
|
||||
|
||||
log.info("Setting supplier names: code to name mapping count={}", supplierCodeToNameMap.size());
|
||||
|
||||
// 设置供应商名称
|
||||
rules.forEach(rule -> {
|
||||
if (StringUtils.hasText(rule.getSupplierCode())) {
|
||||
String names = Arrays.stream(rule.getSupplierCode().split(","))
|
||||
.map(code -> supplierCodeToNameMap.getOrDefault(code, ""))
|
||||
.filter(StringUtils::hasText)
|
||||
.collect(Collectors.joining(","));
|
||||
rule.setSupplierName(names);
|
||||
log.debug("Setting supplier name: id={}, supplierCode={}, supplierName={}",
|
||||
rule.getId(), rule.getSupplierCode(), names);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -88,15 +151,99 @@ public class EmisTransPlanRuleServiceImpl implements IEmisTransPlanRuleService {
|
||||
*/
|
||||
private void setProductTypeNames(List<EmisTransPlanRule> rules) {
|
||||
if (rules == null || rules.isEmpty()) {
|
||||
log.info("Setting product type names: rules list is empty");
|
||||
return;
|
||||
}
|
||||
for (EmisTransPlanRule rule : rules) {
|
||||
if (StringUtils.hasText(rule.getProductType())) {
|
||||
String productTypeNames = emisTransPlanRuleMapper.selectProductTypeNamesByCodes(rule.getProductType());
|
||||
if(StringUtil.isEmpty(productTypeNames)){
|
||||
return;
|
||||
}
|
||||
rule.setProductTypeName(productTypeNames);
|
||||
// 收集所有需要查询的产品类型编码
|
||||
List<String> productTypes = rules.stream()
|
||||
.map(EmisTransPlanRule::getProductType)
|
||||
.filter(StringUtils::hasText)
|
||||
.flatMap(type -> Arrays.stream(type.split(",")))
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
log.info("Setting product type names: code count={}, codes={}", productTypes.size(), productTypes);
|
||||
|
||||
if (!productTypes.isEmpty()) {
|
||||
// 批量查询产品类型信息
|
||||
List<Map<String, String>> productTypeInfos = emisTransPlanRuleMapper
|
||||
.selectProductTypeInfoByCodes(productTypes);
|
||||
log.info("Setting product type names: found product type info count={}",
|
||||
productTypeInfos != null ? productTypeInfos.size() : 0);
|
||||
|
||||
if (productTypeInfos != null && !productTypeInfos.isEmpty()) {
|
||||
// 创建产品类型编码到名称的映射
|
||||
Map<String, String> productTypeToNameMap = productTypeInfos.stream()
|
||||
.collect(Collectors.toMap(
|
||||
info -> info.get("code"),
|
||||
info -> info.get("name"),
|
||||
(existing, replacement) -> existing));
|
||||
|
||||
log.info("Setting product type names: code to name mapping count={}", productTypeToNameMap.size());
|
||||
|
||||
// 设置产品类型名称
|
||||
rules.forEach(rule -> {
|
||||
if (StringUtils.hasText(rule.getProductType())) {
|
||||
String names = Arrays.stream(rule.getProductType().split(","))
|
||||
.map(code -> productTypeToNameMap.getOrDefault(code, ""))
|
||||
.filter(StringUtils::hasText)
|
||||
.collect(Collectors.joining(","));
|
||||
rule.setProductTypeName(names);
|
||||
log.debug("Setting product type name: id={}, productType={}, productTypeName={}",
|
||||
rule.getId(), rule.getProductType(), names);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置线路名称
|
||||
*/
|
||||
private void setLineName(List<EmisTransPlanRule> rules) {
|
||||
if (rules == null || rules.isEmpty()) {
|
||||
log.info("Setting line names: rules list is empty");
|
||||
return;
|
||||
}
|
||||
// 收集所有需要查询的线路编码
|
||||
List<String> lineCodes = rules.stream()
|
||||
.map(EmisTransPlanRule::getLineCode)
|
||||
.filter(StringUtils::hasText)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
log.info("Setting line names: code count={}, codes={}", lineCodes.size(), lineCodes);
|
||||
|
||||
if (!lineCodes.isEmpty()) {
|
||||
// 批量查询线路信息
|
||||
List<EmisTransLine> lines = emisTransLineMapper.selectEmisTransLineList(
|
||||
new EmisTransLine() {
|
||||
{
|
||||
setLineCode(String.join(",", lineCodes));
|
||||
}
|
||||
});
|
||||
|
||||
log.info("Setting line names: found line info count={}", lines != null ? lines.size() : 0);
|
||||
|
||||
if (lines != null && !lines.isEmpty()) {
|
||||
// 创建线路编码到线路名称的映射
|
||||
Map<String, String> lineCodeToNameMap = lines.stream()
|
||||
.collect(Collectors.toMap(
|
||||
EmisTransLine::getLineCode,
|
||||
EmisTransLine::getLineName,
|
||||
(existing, replacement) -> existing));
|
||||
|
||||
log.info("Setting line names: code to name mapping count={}", lineCodeToNameMap.size());
|
||||
|
||||
// 设置线路名称
|
||||
rules.forEach(rule -> {
|
||||
if (StringUtils.hasText(rule.getLineCode())) {
|
||||
String name = lineCodeToNameMap.get(rule.getLineCode());
|
||||
rule.setLineName(name);
|
||||
log.debug("Setting line name: id={}, lineCode={}, lineName={}",
|
||||
rule.getId(), rule.getLineCode(), name);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -110,26 +257,31 @@ public class EmisTransPlanRuleServiceImpl implements IEmisTransPlanRuleService {
|
||||
@Override
|
||||
@Transactional
|
||||
public int insertEmisTransPlanRule(EmisTransPlanRule emisTransPlanRule) throws EmisBizError {
|
||||
log.info("Start inserting supplier route plan, emisTransPlanRule={}", emisTransPlanRule);
|
||||
// 处理父节点
|
||||
if (emisTransPlanRule.getParentId() != null) {
|
||||
EmisTransPlanRule parent = emisTransPlanRuleMapper
|
||||
.selectEmisTransPlanRuleById(emisTransPlanRule.getParentId());
|
||||
if (parent == null) {
|
||||
throw new EmisBizError(EmisBizErrorType.NOT_EXISTS, "父节点不存在");
|
||||
throw new EmisBizError(EmisBizErrorType.NOT_EXISTS, "Parent node does not exist");
|
||||
}
|
||||
// 设置祖先节点
|
||||
String ancestors = parent.getAncestors() == null ? "" : parent.getAncestors();
|
||||
emisTransPlanRule.setAncestors(ancestors + "," + parent.getId());
|
||||
log.debug("Setting ancestors, parentId={}, ancestors={}", parent.getId(), emisTransPlanRule.getAncestors());
|
||||
} else {
|
||||
emisTransPlanRule.setParentId(0L);
|
||||
emisTransPlanRule.setAncestors("0");
|
||||
log.debug("Setting root node, parentId=0, ancestors=0");
|
||||
}
|
||||
|
||||
// 插入当前节点
|
||||
int rows = emisTransPlanRuleMapper.insertEmisTransPlanRule(emisTransPlanRule);
|
||||
log.info("Inserted supplier route plan, affected rows={}, ID={}", rows, emisTransPlanRule.getId());
|
||||
|
||||
// 如果有子节点,递归处理
|
||||
if (emisTransPlanRule.getChildren() != null && !emisTransPlanRule.getChildren().isEmpty()) {
|
||||
log.info("Start processing child nodes, count={}", emisTransPlanRule.getChildren().size());
|
||||
for (EmisTransPlanRule child : emisTransPlanRule.getChildren()) {
|
||||
child.setParentId(emisTransPlanRule.getId());
|
||||
insertEmisTransPlanRule(child);
|
||||
@ -148,27 +300,33 @@ public class EmisTransPlanRuleServiceImpl implements IEmisTransPlanRuleService {
|
||||
@Override
|
||||
@Transactional
|
||||
public int updateEmisTransPlanRule(EmisTransPlanRule emisTransPlanRule) throws EmisBizError {
|
||||
log.info("Start updating supplier route plan, ID={}, emisTransPlanRule={}", emisTransPlanRule.getId(),
|
||||
emisTransPlanRule);
|
||||
if (emisTransPlanRule.getParentId() == null) {
|
||||
return emisTransPlanRuleMapper.updateEmisTransPlanRule(emisTransPlanRule);
|
||||
int rows = emisTransPlanRuleMapper.updateEmisTransPlanRule(emisTransPlanRule);
|
||||
log.info("Updated supplier route plan, affected rows={}", rows);
|
||||
return rows;
|
||||
}
|
||||
// 检查父节点是否存在
|
||||
EmisTransPlanRule parent = emisTransPlanRuleMapper
|
||||
.selectEmisTransPlanRuleById(emisTransPlanRule.getParentId());
|
||||
if (parent == null) {
|
||||
throw new EmisBizError(EmisBizErrorType.NOT_EXISTS, "父节点不存在");
|
||||
throw new EmisBizError(EmisBizErrorType.NOT_EXISTS, "Parent node does not exist");
|
||||
}
|
||||
|
||||
// 检查是否形成循环引用
|
||||
if (parent.getAncestors() != null && parent.getAncestors().contains(emisTransPlanRule.getId().toString())) {
|
||||
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR1, "不能将节点移动到其子节点下");
|
||||
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR1, "Cannot move node under its child node");
|
||||
}
|
||||
|
||||
// 更新祖先节点
|
||||
String ancestors = parent.getAncestors() == null ? "" : parent.getAncestors();
|
||||
emisTransPlanRule.setAncestors(ancestors + "," + parent.getId());
|
||||
log.debug("Updating ancestors, parentId={}, ancestors={}", parent.getId(), emisTransPlanRule.getAncestors());
|
||||
|
||||
// 更新当前节点
|
||||
int rows = emisTransPlanRuleMapper.updateEmisTransPlanRule(emisTransPlanRule);
|
||||
log.info("Updated supplier route plan, affected rows={}", rows);
|
||||
|
||||
// 更新子节点的祖先节点
|
||||
updateChildrenAncestors(emisTransPlanRule);
|
||||
@ -185,13 +343,15 @@ public class EmisTransPlanRuleServiceImpl implements IEmisTransPlanRuleService {
|
||||
@Override
|
||||
@Transactional
|
||||
public int deleteEmisTransPlanRuleByIds(Long[] ids) throws EmisBizError {
|
||||
log.info("Start batch deleting supplier route plans, IDs={}", Arrays.toString(ids));
|
||||
for (Long id : ids) {
|
||||
// 检查是否有子节点
|
||||
if (emisTransPlanRuleMapper.hasChildByEmisTransPlanRuleId(id) > 0) {
|
||||
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR1, "存在子节点,不允许删除");
|
||||
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR1, "Cannot delete node with child nodes");
|
||||
}
|
||||
deleteEmisTransPlanRuleById(id);
|
||||
}
|
||||
log.info("Batch deleted supplier route plans, count={}", ids.length);
|
||||
return ids.length;
|
||||
}
|
||||
|
||||
@ -203,35 +363,34 @@ public class EmisTransPlanRuleServiceImpl implements IEmisTransPlanRuleService {
|
||||
*/
|
||||
@Override
|
||||
public int deleteEmisTransPlanRuleById(Long id) {
|
||||
return emisTransPlanRuleMapper.deleteEmisTransPlanRuleById(id);
|
||||
log.info("Start deleting supplier route plan, ID={}", id);
|
||||
int rows = emisTransPlanRuleMapper.deleteEmisTransPlanRuleById(id);
|
||||
log.info("Deleted supplier route plan, affected rows={}", rows);
|
||||
return rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询供应商线路规划树结构
|
||||
*
|
||||
* @param lineName 线路名称
|
||||
*
|
||||
* @param lineCode 线路编码
|
||||
* @return 供应商线路规划树结构
|
||||
*/
|
||||
@Override
|
||||
public List<EmisTransPlanRule> selectEmisTransPlanRuleTree(String lineName) {
|
||||
List<EmisTransPlanRule> allRules = null;
|
||||
if (StringUtil.isEmpty(lineName)) {
|
||||
allRules = this.selectEmisTransPlanRuleList(new EmisTransPlanRule());
|
||||
return buildTree(allRules);
|
||||
}
|
||||
|
||||
public List<EmisTransPlanRule> selectEmisTransPlanRuleTree(String lineCode) {
|
||||
log.info("Start querying supplier route plan tree, lineCode={}", lineCode);
|
||||
EmisTransPlanRule query = new EmisTransPlanRule();
|
||||
query.setLineName(lineName);
|
||||
allRules = emisTransPlanRuleMapper.selectEmisTransPlanRuleTree(query);
|
||||
setSupplierNames(allRules);
|
||||
setProductTypeNames(allRules);
|
||||
return buildTree(allRules);
|
||||
query.setLineCode(lineCode);
|
||||
List<EmisTransPlanRule> allRules = this.getEmisTransPlanRuleList(query);
|
||||
List<EmisTransPlanRule> tree = buildTree(allRules);
|
||||
log.info("Queried supplier route plan tree, node count={}", tree != null ? tree.size() : 0);
|
||||
return tree;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建树形结构
|
||||
*/
|
||||
private List<EmisTransPlanRule> buildTree(List<EmisTransPlanRule> allRules) {
|
||||
log.debug("Start building tree structure, node count={}", allRules != null ? allRules.size() : 0);
|
||||
if (allRules == null || allRules.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
@ -249,12 +408,15 @@ public class EmisTransPlanRuleServiceImpl implements IEmisTransPlanRuleService {
|
||||
parent.setChildren(new ArrayList<>());
|
||||
}
|
||||
parent.getChildren().add(rule);
|
||||
log.debug("Adding child node, parentId={}, childId={}", parent.getId(), rule.getId());
|
||||
}
|
||||
// 否则,如果 parentId 为 0 或者父节点不在当前查询结果中,则认为是根节点
|
||||
else if (rule.getParentId() == null || rule.getParentId() == 0L || !map.containsKey(rule.getParentId())) {
|
||||
tree.add(rule);
|
||||
log.debug("Adding root node, ID={}", rule.getId());
|
||||
}
|
||||
}
|
||||
log.debug("Built tree structure, root node count={}", tree.size());
|
||||
return tree;
|
||||
}
|
||||
|
||||
@ -263,10 +425,12 @@ public class EmisTransPlanRuleServiceImpl implements IEmisTransPlanRuleService {
|
||||
*/
|
||||
@Transactional
|
||||
public void updateChildrenAncestors(EmisTransPlanRule parent) {
|
||||
log.info("Start updating children's ancestors, parentId={}", parent.getId());
|
||||
// 查询直接子节点
|
||||
EmisTransPlanRule childQuery = new EmisTransPlanRule();
|
||||
childQuery.setParentId(parent.getId());
|
||||
List<EmisTransPlanRule> children = emisTransPlanRuleMapper.selectEmisTransPlanRuleList(childQuery);
|
||||
List<EmisTransPlanRule> children = emisTransPlanRuleMapper.getEmisTransPlanRuleList(childQuery);
|
||||
log.info("Found child nodes, count={}", children != null ? children.size() : 0);
|
||||
|
||||
if (children != null && !children.isEmpty()) {
|
||||
String newAncestors = parent.getAncestors() + "," + parent.getId();
|
||||
@ -274,6 +438,7 @@ public class EmisTransPlanRuleServiceImpl implements IEmisTransPlanRuleService {
|
||||
child.setAncestors(newAncestors);
|
||||
// 更新子节点,包括其祖先信息
|
||||
emisTransPlanRuleMapper.updateEmisTransPlanRule(child);
|
||||
log.debug("Updating child node's ancestors, childId={}, ancestors={}", child.getId(), newAncestors);
|
||||
// 递归更新子节点
|
||||
updateChildrenAncestors(child);
|
||||
}
|
||||
@ -282,10 +447,10 @@ public class EmisTransPlanRuleServiceImpl implements IEmisTransPlanRuleService {
|
||||
|
||||
@Override
|
||||
public List<EmisTransPlanRule> selectSupplierInfoByConditions(EmisTransPlanRule emisTransPlanRule) {
|
||||
log.info("开始根据条件查询供应商信息,查询条件:{}", emisTransPlanRule);
|
||||
log.info("Start querying supplier info by conditions, query={}", emisTransPlanRule);
|
||||
emisTransPlanRule.setStatus("1");
|
||||
List<EmisTransPlanRule> result = this.selectEmisTransPlanRuleList(emisTransPlanRule);
|
||||
log.info("查询完成,共获取{}条记录", result.size());
|
||||
List<EmisTransPlanRule> result = this.getEmisTransPlanRuleList(emisTransPlanRule);
|
||||
log.info("Queried supplier info, count={}", result != null ? result.size() : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@ -8,6 +8,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="id" column="id" />
|
||||
<result property="parentId" column="parent_id" />
|
||||
<result property="ancestors" column="ancestors" />
|
||||
<result property="lineCode" column="line_code" />
|
||||
<result property="lineName" column="line_name" />
|
||||
<result property="transType" column="trans_type" />
|
||||
<result property="productType" column="product_type" />
|
||||
@ -20,7 +21,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectEmisTransPlanRuleVo">
|
||||
select r.id, r.parent_id, r.ancestors, r.line_name, r.trans_type, r.product_type, r.start_site_code,
|
||||
select r.id, r.parent_id, r.ancestors, r.line_code, r.trans_type, r.product_type, r.start_site_code,
|
||||
s1.site_name as start_site_name, r.next_site_code, s2.site_name as next_site_name, r.supplier_code,
|
||||
r.status, r.remark, r.del_flag, r.create_by, r.create_time, r.update_by, r.update_time, r.create_site, r.update_site
|
||||
from emis_trans_plan_rule r
|
||||
@ -33,7 +34,25 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<where>
|
||||
<if test="parentId != null"> and r.parent_id = #{parentId}</if>
|
||||
<if test="ancestors != null and ancestors != ''"> and r.ancestors like concat(#{ancestors}, '%')</if>
|
||||
<if test="lineName != null and lineName != ''"> and r.line_name like concat('%', #{lineName}, '%')</if>
|
||||
<if test="lineCode != null and lineCode != ''"> and r.line_code = #{lineCode}</if>
|
||||
<if test="transType != null and transType != ''"> and ( FIND_IN_SET(#{transType},r.trans_type) )</if>
|
||||
<if test="productType != null and productType != ''"> and ( FIND_IN_SET(#{productType},r.product_type) )</if>
|
||||
<if test="startSiteCode != null and startSiteCode != ''"> and r.start_site_code = #{startSiteCode}</if>
|
||||
<if test="nextSiteCode != null and nextSiteCode != ''"> and r.next_site_code = #{nextSiteCode}</if>
|
||||
<if test="supplierCode != null and supplierCode != ''"> and ( FIND_IN_SET(#{supplierCode},r.supplier_code) )</if>
|
||||
<if test="status != null and status != ''"> and r.status = #{status}</if>
|
||||
and r.del_flag = '0'
|
||||
and LENGTH(r.ancestors) - LENGTH(REPLACE(r.ancestors, ',', '')) > 1
|
||||
</where>
|
||||
order by id desc
|
||||
</select>
|
||||
|
||||
<select id="getEmisTransPlanRuleList" parameterType="EmisTransPlanRule" resultMap="EmisTransPlanRuleResult">
|
||||
<include refid="selectEmisTransPlanRuleVo"/>
|
||||
<where>
|
||||
<if test="parentId != null"> and r.parent_id = #{parentId}</if>
|
||||
<if test="ancestors != null and ancestors != ''"> and r.ancestors like concat(#{ancestors}, '%')</if>
|
||||
<if test="lineCode != null and lineCode != ''"> and r.line_code = #{lineCode}</if>
|
||||
<if test="transType != null and transType != ''"> and ( FIND_IN_SET(#{transType},r.trans_type) )</if>
|
||||
<if test="productType != null and productType != ''"> and ( FIND_IN_SET(#{productType},r.product_type) )</if>
|
||||
<if test="startSiteCode != null and startSiteCode != ''"> and r.start_site_code = #{startSiteCode}</if>
|
||||
@ -42,27 +61,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="status != null and status != ''"> and r.status = #{status}</if>
|
||||
and r.del_flag = '0'
|
||||
</where>
|
||||
order by parent_id, create_time desc
|
||||
</select>
|
||||
|
||||
<select id="selectEmisTransPlanRuleTree" parameterType="EmisTransPlanRule" resultMap="EmisTransPlanRuleResult">
|
||||
<include refid="selectEmisTransPlanRuleVo"/>
|
||||
<where>
|
||||
<if test="parentId != null">and r.parent_id = #{parentId}</if>
|
||||
<if test="ancestors != null and ancestors != ''">and r.ancestors like concat(#{ancestors}, '%')</if>
|
||||
<if test="lineName != null and lineName != ''">and r.line_name =#{lineName}</if>
|
||||
<if test="transType != null and transType != ''">and ( FIND_IN_SET(#{transType},r.trans_type) )</if>
|
||||
<if test="productType != null and productType != ''">and ( FIND_IN_SET(#{productType},r.product_type) )
|
||||
</if>
|
||||
<if test="startSiteCode != null and startSiteCode != ''">and r.start_site_code = #{startSiteCode}</if>
|
||||
<if test="nextSiteCode != null and nextSiteCode != ''">and r.next_site_code = #{nextSiteCode}</if>
|
||||
<if test="supplierCode != null and supplierCode != ''">and ( FIND_IN_SET(#{supplierCode},r.supplier_code)
|
||||
)
|
||||
</if>
|
||||
<if test="status != null and status != ''">and r.status = #{status}</if>
|
||||
and r.del_flag = '0'
|
||||
</where>
|
||||
order by parent_id, create_time desc
|
||||
order by id
|
||||
</select>
|
||||
|
||||
<select id="selectEmisTransPlanRuleById" parameterType="Long" resultMap="EmisTransPlanRuleResult">
|
||||
@ -97,7 +96,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="parentId != null">parent_id,</if>
|
||||
<if test="ancestors != null">ancestors,</if>
|
||||
<if test="lineName != null">line_name,</if>
|
||||
<if test="lineCode != null and lineCode != ''">line_code,</if>
|
||||
<if test="transType != null">trans_type,</if>
|
||||
<if test="productType != null">product_type,</if>
|
||||
<if test="startSiteCode != null">start_site_code,</if>
|
||||
@ -116,7 +115,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="parentId != null">#{parentId},</if>
|
||||
<if test="ancestors != null">#{ancestors},</if>
|
||||
<if test="lineName != null">#{lineName},</if>
|
||||
<if test="lineCode != null and lineCode != ''">#{lineCode},</if>
|
||||
<if test="transType != null">#{transType},</if>
|
||||
<if test="productType != null">#{productType},</if>
|
||||
<if test="startSiteCode != null">#{startSiteCode},</if>
|
||||
@ -139,7 +138,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<if test="parentId != null">parent_id = #{parentId},</if>
|
||||
<if test="ancestors != null">ancestors = #{ancestors},</if>
|
||||
<if test="lineName != null">line_name = #{lineName},</if>
|
||||
<if test="lineCode != null and lineCode != ''">line_code = #{lineCode},</if>
|
||||
<if test="transType != null">trans_type = #{transType},</if>
|
||||
<if test="productType != null">product_type = #{productType},</if>
|
||||
<if test="startSiteCode != null">start_site_code = #{startSiteCode},</if>
|
||||
@ -169,25 +168,24 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<select id="selectSupplierInfoByConditions" resultMap="EmisTransPlanRuleResult">
|
||||
SELECT DISTINCT r.id, r.parent_id, r.ancestors, r.line_name, r.trans_type, r.product_type,
|
||||
r.start_site_code, s1.site_name as start_site_name, r.next_site_code, s2.site_name as next_site_name,
|
||||
r.supplier_code, GROUP_CONCAT(s.name) as supplier_name, r.status, r.remark, r.del_flag,
|
||||
r.create_by, r.create_time, r.update_by, r.update_time, r.create_site, r.update_site
|
||||
FROM emis_trans_plan_rule r
|
||||
LEFT JOIN emis_site s1 ON r.start_site_code = s1.site_code AND s1.del_flag = 0
|
||||
LEFT JOIN emis_site s2 ON r.next_site_code = s2.site_code AND s2.del_flag = 0
|
||||
LEFT JOIN emis_supplier s ON FIND_IN_SET(s.code, r.supplier_code) AND s.del_flag = 0
|
||||
WHERE r.del_flag = 0
|
||||
<if test="transType != null and transType != ''">
|
||||
AND FIND_IN_SET(#{transType}, r.trans_type)
|
||||
</if>
|
||||
<if test="startSiteCode != null and startSiteCode != ''">
|
||||
AND r.start_site_code = #{startSiteCode}
|
||||
</if>
|
||||
<if test="nextSiteCode != null and nextSiteCode != ''">
|
||||
AND r.next_site_code = #{nextSiteCode}
|
||||
</if>
|
||||
AND r.status = '1'
|
||||
<select id="selectSupplierInfoByCodes" resultType="java.util.Map">
|
||||
SELECT code, name
|
||||
FROM emis_supplier
|
||||
WHERE del_flag = '0'
|
||||
AND code IN
|
||||
<foreach collection="list" item="code" open="(" separator="," close=")">
|
||||
#{code}
|
||||
</foreach>
|
||||
</select>
|
||||
|
||||
<select id="selectProductTypeInfoByCodes" resultType="java.util.Map">
|
||||
SELECT prod_code as code, prod_name as name
|
||||
FROM emis_trans_product
|
||||
WHERE del_flag = '0'
|
||||
AND prod_code IN
|
||||
<foreach collection="list" item="code" open="(" separator="," close=")">
|
||||
#{code}
|
||||
</foreach>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue
Block a user