demand: 供应商线路规划管理页面增删改查基本功能-初版雏形
committer: heyu
This commit is contained in:
parent
71f2159b4d
commit
e5b46b3846
@ -0,0 +1,101 @@
|
||||
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;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.xdadan.erp.emis.domain.EmisTransPlanRule;
|
||||
import com.xdadan.erp.emis.service.IEmisTransPlanRuleService;
|
||||
|
||||
/**
|
||||
* 供应商线路规划Controller
|
||||
*
|
||||
* @author heyu
|
||||
* @date 2024-04-21
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/emis/emisTransPlanRule")
|
||||
public class EmisTransPlanRuleController extends EmisBaseController {
|
||||
@Autowired
|
||||
private IEmisTransPlanRuleService emisTransPlanRuleService;
|
||||
|
||||
@GetMapping("/listSimple")
|
||||
@JacksonFilter(include = {
|
||||
"transType", "productTypeName", "supplierCode", "supplierName"
|
||||
}, value = EmisTransPlanRule.class, type = JacksonFilter.JscksonFilterType.RESPONSE)
|
||||
public TableDataInfo listSimple(EmisTransPlanRule emisTransPlanRule) {
|
||||
startPage();
|
||||
List<EmisTransPlanRule> list = emisTransPlanRuleService.selectSupplierInfoByConditions(emisTransPlanRule);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询供应商线路规划列表
|
||||
*/
|
||||
// @PreAuthorize("@ss.hasPermi('emis:rule:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(EmisTransPlanRule emisTransPlanRule) {
|
||||
startPage();
|
||||
List<EmisTransPlanRule> list = emisTransPlanRuleService.selectEmisTransPlanRuleList(emisTransPlanRule);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取供应商线路规划详细信息
|
||||
*/
|
||||
// @PreAuthorize("@ss.hasPermi('emis:rule:query')")
|
||||
@GetMapping(value = "/{id}")
|
||||
public AjaxResult getInfo(@PathVariable("id") Long id) {
|
||||
return AjaxResult.success(emisTransPlanRuleService.selectEmisTransPlanRuleById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增供应商线路规划
|
||||
*/
|
||||
// @PreAuthorize("@ss.hasPermi('emis:rule:add')")
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody EmisTransPlanRule emisTransPlanRule) throws EmisBizError {
|
||||
return toAjax(emisTransPlanRuleService.insertEmisTransPlanRule(emisTransPlanRule));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改供应商线路规划
|
||||
*/
|
||||
// @PreAuthorize("@ss.hasPermi('emis:rule:edit')")
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody EmisTransPlanRule emisTransPlanRule) throws EmisBizError {
|
||||
return toAjax(emisTransPlanRuleService.updateEmisTransPlanRule(emisTransPlanRule));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除供应商线路规划
|
||||
*/
|
||||
// @PreAuthorize("@ss.hasPermi('emis:rule:remove')")
|
||||
@DeleteMapping("/{ids}")
|
||||
public AjaxResult remove(@PathVariable Long[] ids) throws EmisBizError {
|
||||
return toAjax(emisTransPlanRuleService.deleteEmisTransPlanRuleByIds(ids));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询供应商线路规划树结构
|
||||
*/
|
||||
@GetMapping("/tree")
|
||||
public TableDataInfo tree(String lineName) {
|
||||
return getDataTable(emisTransPlanRuleService.selectEmisTransPlanRuleTree(lineName));
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,62 @@
|
||||
package com.xdadan.erp.emis.domain;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.xdadan.erp.common.core.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 供应商线路规划表对象 emis_trans_plan_rule
|
||||
*
|
||||
* @author heyu
|
||||
* @date 2024-04-22
|
||||
*/
|
||||
@Data
|
||||
public class EmisTransPlanRule extends BaseEntity {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** id */
|
||||
private Long id;
|
||||
|
||||
/** 父id */
|
||||
private Long parentId;
|
||||
|
||||
/** 祖先节点 */
|
||||
private String ancestors;
|
||||
|
||||
/** 线路名称 */
|
||||
private String lineName;
|
||||
|
||||
/** 运输方式 */
|
||||
private String transType;
|
||||
|
||||
/** 产品类型 */
|
||||
private String productType;
|
||||
|
||||
/** 产品类型名称 */
|
||||
private String productTypeName;
|
||||
|
||||
/** 起始网点编码 */
|
||||
private String startSiteCode;
|
||||
|
||||
/** 下一网点编码 */
|
||||
private String nextSiteCode;
|
||||
|
||||
/** 起始网点名称 */
|
||||
private String startSiteName;
|
||||
|
||||
/** 下一网点名称 */
|
||||
private String nextSiteName;
|
||||
|
||||
/** 供应商编码 */
|
||||
private String supplierCode;
|
||||
|
||||
/** 供应商名称 */
|
||||
private String supplierName;
|
||||
|
||||
/** 状态 1-启用 0-不启用 */
|
||||
private String status;
|
||||
|
||||
/** 子节点 */
|
||||
private List<EmisTransPlanRule> children;
|
||||
}
|
||||
@ -0,0 +1,112 @@
|
||||
package com.xdadan.erp.emis.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import com.xdadan.erp.emis.domain.EmisTransPlanRule;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* 供应商线路规划Mapper接口
|
||||
*
|
||||
* @author heyu
|
||||
* @date 2024-04-22
|
||||
*/
|
||||
public interface EmisTransPlanRuleMapper {
|
||||
/**
|
||||
* 查询供应商线路规划
|
||||
*
|
||||
* @param id 供应商线路规划主键
|
||||
* @return 供应商线路规划
|
||||
*/
|
||||
public EmisTransPlanRule selectEmisTransPlanRuleById(Long id);
|
||||
|
||||
/**
|
||||
* 查询供应商线路规划列表
|
||||
*
|
||||
* @param emisTransPlanRule 供应商线路规划
|
||||
* @return 供应商线路规划集合
|
||||
*/
|
||||
public List<EmisTransPlanRule> selectEmisTransPlanRuleList(EmisTransPlanRule emisTransPlanRule);
|
||||
|
||||
/**
|
||||
* 查询子节点列表
|
||||
*
|
||||
* @param id 父节点ID
|
||||
* @return 子节点列表
|
||||
*/
|
||||
public List<EmisTransPlanRule> selectChildrenEmisTransPlanRuleById(Long id);
|
||||
|
||||
/**
|
||||
* 查询是否存在子节点
|
||||
*
|
||||
* @param id 节点ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int hasChildByEmisTransPlanRuleId(Long id);
|
||||
|
||||
/**
|
||||
* 新增供应商线路规划
|
||||
*
|
||||
* @param emisTransPlanRule 供应商线路规划
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertEmisTransPlanRule(EmisTransPlanRule emisTransPlanRule);
|
||||
|
||||
/**
|
||||
* 修改供应商线路规划
|
||||
*
|
||||
* @param emisTransPlanRule 供应商线路规划
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateEmisTransPlanRule(EmisTransPlanRule emisTransPlanRule);
|
||||
|
||||
/**
|
||||
* 修改子元素关系
|
||||
*
|
||||
* @param children 子元素
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateEmisTransPlanRuleChildren(List<EmisTransPlanRule> children);
|
||||
|
||||
/**
|
||||
* 删除供应商线路规划
|
||||
*
|
||||
* @param id 供应商线路规划主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteEmisTransPlanRuleById(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除供应商线路规划
|
||||
*
|
||||
* @param ids 需要删除的数据主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteEmisTransPlanRuleByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 根据供应商编码查询供应商名称(逗号分隔)
|
||||
*
|
||||
* @param supplierCodes 供应商编码(逗号分隔)
|
||||
* @return 供应商名称(逗号分隔)
|
||||
*/
|
||||
public String selectSupplierNamesByCodes(@Param("supplierCodes") String supplierCodes);
|
||||
|
||||
/**
|
||||
* 根据产品类型查询产品名称(逗号分隔)
|
||||
*
|
||||
* @param productType 产品类型编码(逗号分隔)
|
||||
* @return 产品名称(逗号分隔)
|
||||
*/
|
||||
public String selectProductTypeNamesByCodes(@Param("productType") String productType);
|
||||
|
||||
List<EmisTransPlanRule> selectEmisTransPlanRuleTree(EmisTransPlanRule emisTransPlanRule);
|
||||
|
||||
/**
|
||||
* 根据条件查询供应商信息
|
||||
*
|
||||
* @param emisTransPlanRule 查询条件
|
||||
* @return 供应商信息列表
|
||||
*/
|
||||
List<EmisTransPlanRule> selectSupplierInfoByConditions(EmisTransPlanRule emisTransPlanRule);
|
||||
}
|
||||
@ -0,0 +1,77 @@
|
||||
package com.xdadan.erp.emis.service;
|
||||
|
||||
import java.util.List;
|
||||
import com.xdadan.erp.emis.domain.EmisTransPlanRule;
|
||||
import com.xdadan.erp.emis.domain.exception.EmisBizError;
|
||||
|
||||
/**
|
||||
* 供应商线路规划Service接口
|
||||
*
|
||||
* @author heyu
|
||||
* @date 2024-04-22
|
||||
*/
|
||||
public interface IEmisTransPlanRuleService {
|
||||
/**
|
||||
* 查询供应商线路规划
|
||||
*
|
||||
* @param id 供应商线路规划主键
|
||||
* @return 供应商线路规划
|
||||
*/
|
||||
public EmisTransPlanRule selectEmisTransPlanRuleById(Long id);
|
||||
|
||||
/**
|
||||
* 查询供应商线路规划列表
|
||||
*
|
||||
* @param emisTransPlanRule 供应商线路规划
|
||||
* @return 供应商线路规划集合
|
||||
*/
|
||||
public List<EmisTransPlanRule> selectEmisTransPlanRuleList(EmisTransPlanRule emisTransPlanRule);
|
||||
|
||||
/**
|
||||
* 新增供应商线路规划
|
||||
*
|
||||
* @param emisTransPlanRule 供应商线路规划
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertEmisTransPlanRule(EmisTransPlanRule emisTransPlanRule) throws EmisBizError;
|
||||
|
||||
/**
|
||||
* 修改供应商线路规划
|
||||
*
|
||||
* @param emisTransPlanRule 供应商线路规划
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateEmisTransPlanRule(EmisTransPlanRule emisTransPlanRule) throws EmisBizError;
|
||||
|
||||
/**
|
||||
* 批量删除供应商线路规划
|
||||
*
|
||||
* @param ids 需要删除的供应商线路规划主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteEmisTransPlanRuleByIds(Long[] ids) throws EmisBizError;
|
||||
|
||||
/**
|
||||
* 删除供应商线路规划信息
|
||||
*
|
||||
* @param id 供应商线路规划主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteEmisTransPlanRuleById(Long id);
|
||||
|
||||
/**
|
||||
* 查询供应商线路规划树结构
|
||||
*
|
||||
* @param lineName 线路名称
|
||||
* @return 供应商线路规划树结构
|
||||
*/
|
||||
public List<EmisTransPlanRule> selectEmisTransPlanRuleTree(String lineName);
|
||||
|
||||
/**
|
||||
* 根据条件查询供应商信息
|
||||
*
|
||||
* @param emisTransPlanRule 查询条件
|
||||
* @return 供应商信息列表
|
||||
*/
|
||||
List<EmisTransPlanRule> selectSupplierInfoByConditions(EmisTransPlanRule emisTransPlanRule);
|
||||
}
|
||||
@ -0,0 +1,291 @@
|
||||
package com.xdadan.erp.emis.service.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
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 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.mapper.EmisTransPlanRuleMapper;
|
||||
import com.xdadan.erp.emis.service.IEmisTransPlanRuleService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* 供应商线路规划Service业务层处理
|
||||
*
|
||||
* @author heyu
|
||||
* @date 2024-04-22
|
||||
*/
|
||||
@Service
|
||||
public class EmisTransPlanRuleServiceImpl implements IEmisTransPlanRuleService {
|
||||
private static final Logger log = LoggerFactory.getLogger(EmisTransPlanRuleServiceImpl.class);
|
||||
|
||||
@Autowired
|
||||
private EmisTransPlanRuleMapper emisTransPlanRuleMapper;
|
||||
|
||||
/**
|
||||
* 查询供应商线路规划
|
||||
*
|
||||
* @param id 供应商线路规划主键
|
||||
* @return 供应商线路规划
|
||||
*/
|
||||
@Override
|
||||
public EmisTransPlanRule selectEmisTransPlanRuleById(Long id) {
|
||||
EmisTransPlanRule rule = emisTransPlanRuleMapper.selectEmisTransPlanRuleById(id);
|
||||
if (rule != null) {
|
||||
setSupplierNames(Collections.singletonList(rule));
|
||||
setProductTypeNames(Collections.singletonList(rule));
|
||||
}
|
||||
return rule;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询供应商线路规划列表
|
||||
*
|
||||
* @param emisTransPlanRule 供应商线路规划
|
||||
* @return 供应商线路规划
|
||||
*/
|
||||
@Override
|
||||
public List<EmisTransPlanRule> selectEmisTransPlanRuleList(EmisTransPlanRule emisTransPlanRule) {
|
||||
List<EmisTransPlanRule> list = emisTransPlanRuleMapper.selectEmisTransPlanRuleList(emisTransPlanRule);
|
||||
setSupplierNames(list);
|
||||
setProductTypeNames(list);
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置供应商名称
|
||||
*/
|
||||
private void setSupplierNames(List<EmisTransPlanRule> rules) {
|
||||
if (rules == null || rules.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
for (EmisTransPlanRule rule : rules) {
|
||||
if (StringUtils.hasText(rule.getSupplierCode())) {
|
||||
String supplierNames = emisTransPlanRuleMapper.selectSupplierNamesByCodes(rule.getSupplierCode());
|
||||
if(StringUtil.isEmpty(supplierNames)){
|
||||
return;
|
||||
}
|
||||
rule.setSupplierName(supplierNames);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置产品类型名称
|
||||
*/
|
||||
private void setProductTypeNames(List<EmisTransPlanRule> rules) {
|
||||
if (rules == null || rules.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
for (EmisTransPlanRule rule : rules) {
|
||||
if (StringUtils.hasText(rule.getProductType())) {
|
||||
String productTypeNames = emisTransPlanRuleMapper.selectProductTypeNamesByCodes(rule.getProductType());
|
||||
if(StringUtil.isEmpty(productTypeNames)){
|
||||
return;
|
||||
}
|
||||
rule.setProductTypeName(productTypeNames);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增供应商线路规划
|
||||
*
|
||||
* @param emisTransPlanRule 供应商线路规划
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public int insertEmisTransPlanRule(EmisTransPlanRule emisTransPlanRule) throws EmisBizError {
|
||||
// 处理父节点
|
||||
if (emisTransPlanRule.getParentId() != null) {
|
||||
EmisTransPlanRule parent = emisTransPlanRuleMapper
|
||||
.selectEmisTransPlanRuleById(emisTransPlanRule.getParentId());
|
||||
if (parent == null) {
|
||||
throw new EmisBizError(EmisBizErrorType.NOT_EXISTS, "父节点不存在");
|
||||
}
|
||||
// 设置祖先节点
|
||||
String ancestors = parent.getAncestors() == null ? "" : parent.getAncestors();
|
||||
emisTransPlanRule.setAncestors(ancestors + "," + parent.getId());
|
||||
} else {
|
||||
emisTransPlanRule.setParentId(0L);
|
||||
emisTransPlanRule.setAncestors("0");
|
||||
}
|
||||
|
||||
// 插入当前节点
|
||||
int rows = emisTransPlanRuleMapper.insertEmisTransPlanRule(emisTransPlanRule);
|
||||
|
||||
// 如果有子节点,递归处理
|
||||
if (emisTransPlanRule.getChildren() != null && !emisTransPlanRule.getChildren().isEmpty()) {
|
||||
for (EmisTransPlanRule child : emisTransPlanRule.getChildren()) {
|
||||
child.setParentId(emisTransPlanRule.getId());
|
||||
insertEmisTransPlanRule(child);
|
||||
}
|
||||
}
|
||||
|
||||
return rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改供应商线路规划
|
||||
*
|
||||
* @param emisTransPlanRule 供应商线路规划
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public int updateEmisTransPlanRule(EmisTransPlanRule emisTransPlanRule) throws EmisBizError {
|
||||
if (emisTransPlanRule.getParentId() == null) {
|
||||
return emisTransPlanRuleMapper.updateEmisTransPlanRule(emisTransPlanRule);
|
||||
}
|
||||
// 检查父节点是否存在
|
||||
EmisTransPlanRule parent = emisTransPlanRuleMapper
|
||||
.selectEmisTransPlanRuleById(emisTransPlanRule.getParentId());
|
||||
if (parent == null) {
|
||||
throw new EmisBizError(EmisBizErrorType.NOT_EXISTS, "父节点不存在");
|
||||
}
|
||||
|
||||
// 检查是否形成循环引用
|
||||
if (parent.getAncestors() != null && parent.getAncestors().contains(emisTransPlanRule.getId().toString())) {
|
||||
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR1, "不能将节点移动到其子节点下");
|
||||
}
|
||||
|
||||
// 更新祖先节点
|
||||
String ancestors = parent.getAncestors() == null ? "" : parent.getAncestors();
|
||||
emisTransPlanRule.setAncestors(ancestors + "," + parent.getId());
|
||||
|
||||
// 更新当前节点
|
||||
int rows = emisTransPlanRuleMapper.updateEmisTransPlanRule(emisTransPlanRule);
|
||||
|
||||
// 更新子节点的祖先节点
|
||||
updateChildrenAncestors(emisTransPlanRule);
|
||||
|
||||
return rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除供应商线路规划
|
||||
*
|
||||
* @param ids 需要删除的供应商线路规划主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public int deleteEmisTransPlanRuleByIds(Long[] ids) throws EmisBizError {
|
||||
for (Long id : ids) {
|
||||
// 检查是否有子节点
|
||||
if (emisTransPlanRuleMapper.hasChildByEmisTransPlanRuleId(id) > 0) {
|
||||
throw new EmisBizError(EmisBizErrorType.PARAM_ERROR1, "存在子节点,不允许删除");
|
||||
}
|
||||
deleteEmisTransPlanRuleById(id);
|
||||
}
|
||||
return ids.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除供应商线路规划信息
|
||||
*
|
||||
* @param id 供应商线路规划主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteEmisTransPlanRuleById(Long id) {
|
||||
return emisTransPlanRuleMapper.deleteEmisTransPlanRuleById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询供应商线路规划树结构
|
||||
*
|
||||
* @param lineName 线路名称
|
||||
* @return 供应商线路规划树结构
|
||||
*/
|
||||
@Override
|
||||
public List<EmisTransPlanRule> selectEmisTransPlanRuleTree(String lineName) {
|
||||
List<EmisTransPlanRule> allRules = null;
|
||||
if (StringUtil.isEmpty(lineName)) {
|
||||
allRules = this.selectEmisTransPlanRuleList(new EmisTransPlanRule());
|
||||
return buildTree(allRules);
|
||||
}
|
||||
|
||||
EmisTransPlanRule query = new EmisTransPlanRule();
|
||||
query.setLineName(lineName);
|
||||
allRules = emisTransPlanRuleMapper.selectEmisTransPlanRuleTree(query);
|
||||
setSupplierNames(allRules);
|
||||
setProductTypeNames(allRules);
|
||||
return buildTree(allRules);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建树形结构
|
||||
*/
|
||||
private List<EmisTransPlanRule> buildTree(List<EmisTransPlanRule> allRules) {
|
||||
if (allRules == null || allRules.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
// 使用 Map 存储 ID 到节点的映射,方便查找父节点
|
||||
Map<Long, EmisTransPlanRule> map = allRules.stream()
|
||||
.collect(Collectors.toMap(EmisTransPlanRule::getId, rule -> rule));
|
||||
|
||||
List<EmisTransPlanRule> tree = new ArrayList<>();
|
||||
for (EmisTransPlanRule rule : allRules) {
|
||||
EmisTransPlanRule parent = map.get(rule.getParentId());
|
||||
// 如果 parent 不为 null 且在当前查询结果中,则添加到父节点的 children 列表
|
||||
if (parent != null) {
|
||||
if (parent.getChildren() == null) {
|
||||
parent.setChildren(new ArrayList<>());
|
||||
}
|
||||
parent.getChildren().add(rule);
|
||||
}
|
||||
// 否则,如果 parentId 为 0 或者父节点不在当前查询结果中,则认为是根节点
|
||||
else if (rule.getParentId() == null || rule.getParentId() == 0L || !map.containsKey(rule.getParentId())) {
|
||||
tree.add(rule);
|
||||
}
|
||||
}
|
||||
return tree;
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归更新子节点的祖先节点
|
||||
*/
|
||||
@Transactional
|
||||
public void updateChildrenAncestors(EmisTransPlanRule parent) {
|
||||
// 查询直接子节点
|
||||
EmisTransPlanRule childQuery = new EmisTransPlanRule();
|
||||
childQuery.setParentId(parent.getId());
|
||||
List<EmisTransPlanRule> children = emisTransPlanRuleMapper.selectEmisTransPlanRuleList(childQuery);
|
||||
|
||||
if (children != null && !children.isEmpty()) {
|
||||
String newAncestors = parent.getAncestors() + "," + parent.getId();
|
||||
for (EmisTransPlanRule child : children) {
|
||||
child.setAncestors(newAncestors);
|
||||
// 更新子节点,包括其祖先信息
|
||||
emisTransPlanRuleMapper.updateEmisTransPlanRule(child);
|
||||
// 递归更新子节点
|
||||
updateChildrenAncestors(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EmisTransPlanRule> selectSupplierInfoByConditions(EmisTransPlanRule emisTransPlanRule) {
|
||||
log.info("开始根据条件查询供应商信息,查询条件:{}", emisTransPlanRule);
|
||||
emisTransPlanRule.setStatus("1");
|
||||
List<EmisTransPlanRule> result = this.selectEmisTransPlanRuleList(emisTransPlanRule);
|
||||
log.info("查询完成,共获取{}条记录", result.size());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
193
emis-biz/src/main/resources/mapper/EmisTransPlanRuleMapper.xml
Normal file
193
emis-biz/src/main/resources/mapper/EmisTransPlanRuleMapper.xml
Normal file
@ -0,0 +1,193 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.xdadan.erp.emis.mapper.EmisTransPlanRuleMapper">
|
||||
|
||||
<resultMap type="EmisTransPlanRule" id="EmisTransPlanRuleResult" extends="com.xdadan.erp.emis.mapper.EmisBaseMapper.EmisBaseResult">
|
||||
<result property="id" column="id" />
|
||||
<result property="parentId" column="parent_id" />
|
||||
<result property="ancestors" column="ancestors" />
|
||||
<result property="lineName" column="line_name" />
|
||||
<result property="transType" column="trans_type" />
|
||||
<result property="productType" column="product_type" />
|
||||
<result property="startSiteCode" column="start_site_code" />
|
||||
<result property="startSiteName" column="start_site_name" />
|
||||
<result property="nextSiteCode" column="next_site_code" />
|
||||
<result property="nextSiteName" column="next_site_name" />
|
||||
<result property="supplierCode" column="supplier_code" />
|
||||
<result property="status" column="status" />
|
||||
</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,
|
||||
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
|
||||
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
|
||||
</sql>
|
||||
|
||||
<select id="selectEmisTransPlanRuleList" 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 like concat('%', #{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
|
||||
</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
|
||||
</select>
|
||||
|
||||
<select id="selectEmisTransPlanRuleById" parameterType="Long" resultMap="EmisTransPlanRuleResult">
|
||||
<include refid="selectEmisTransPlanRuleVo"/>
|
||||
where r.id = #{id} and r.del_flag = '0'
|
||||
</select>
|
||||
|
||||
<select id="selectChildrenEmisTransPlanRuleById" parameterType="Long" resultMap="EmisTransPlanRuleResult">
|
||||
<include refid="selectEmisTransPlanRuleVo"/>
|
||||
where r.parent_id = #{id} and r.del_flag = '0'
|
||||
</select>
|
||||
|
||||
<select id="hasChildByEmisTransPlanRuleId" parameterType="Long" resultType="Integer">
|
||||
select count(1) from emis_trans_plan_rule
|
||||
where parent_id = #{id} and del_flag = '0'
|
||||
</select>
|
||||
|
||||
<select id="selectSupplierNamesByCodes" parameterType="String" resultType="String">
|
||||
SELECT GROUP_CONCAT(s.name)
|
||||
FROM emis_supplier s
|
||||
WHERE FIND_IN_SET(s.code, #{supplierCodes}) AND s.del_flag = 0
|
||||
</select>
|
||||
|
||||
<select id="selectProductTypeNamesByCodes" parameterType="String" resultType="String">
|
||||
SELECT GROUP_CONCAT(s.prod_name)
|
||||
FROM emis_trans_product s
|
||||
WHERE FIND_IN_SET(s.prod_code, #{productType}) AND s.del_flag = 0
|
||||
</select>
|
||||
|
||||
<insert id="insertEmisTransPlanRule" parameterType="EmisTransPlanRule" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into emis_trans_plan_rule
|
||||
<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="transType != null">trans_type,</if>
|
||||
<if test="productType != null">product_type,</if>
|
||||
<if test="startSiteCode != null">start_site_code,</if>
|
||||
<if test="nextSiteCode != null">next_site_code,</if>
|
||||
<if test="supplierCode != null">supplier_code,</if>
|
||||
<if test="status != null">status,</if>
|
||||
<if test="remark != null">remark,</if>
|
||||
<if test="delFlag != null">del_flag,</if>
|
||||
<if test="createBy != null">create_by,</if>
|
||||
<if test="createTime != null">create_time,</if>
|
||||
<if test="updateBy != null">update_by,</if>
|
||||
<if test="updateTime != null">update_time,</if>
|
||||
<if test="createSite != null">create_site,</if>
|
||||
<if test="updateSite != null">update_site,</if>
|
||||
</trim>
|
||||
<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="transType != null">#{transType},</if>
|
||||
<if test="productType != null">#{productType},</if>
|
||||
<if test="startSiteCode != null">#{startSiteCode},</if>
|
||||
<if test="nextSiteCode != null">#{nextSiteCode},</if>
|
||||
<if test="supplierCode != null">#{supplierCode},</if>
|
||||
<if test="status != null">#{status},</if>
|
||||
<if test="remark != null">#{remark},</if>
|
||||
<if test="delFlag != null">#{delFlag},</if>
|
||||
<if test="createBy != null">#{createBy},</if>
|
||||
<if test="createTime != null">#{createTime},</if>
|
||||
<if test="updateBy != null">#{updateBy},</if>
|
||||
<if test="updateTime != null">#{updateTime},</if>
|
||||
<if test="createSite != null">#{createSite},</if>
|
||||
<if test="updateSite != null">#{updateSite},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateEmisTransPlanRule" parameterType="EmisTransPlanRule">
|
||||
update emis_trans_plan_rule
|
||||
<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="transType != null">trans_type = #{transType},</if>
|
||||
<if test="productType != null">product_type = #{productType},</if>
|
||||
<if test="startSiteCode != null">start_site_code = #{startSiteCode},</if>
|
||||
<if test="nextSiteCode != null">next_site_code = #{nextSiteCode},</if>
|
||||
<if test="supplierCode != null">supplier_code = #{supplierCode},</if>
|
||||
<if test="status != null">status = #{status},</if>
|
||||
<if test="remark != null">remark = #{remark},</if>
|
||||
<if test="delFlag != null">del_flag = #{delFlag},</if>
|
||||
<if test="createBy != null">create_by = #{createBy},</if>
|
||||
<if test="createTime != null">create_time = #{createTime},</if>
|
||||
<if test="updateBy != null">update_by = #{updateBy},</if>
|
||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||
<if test="createSite != null">create_site = #{createSite},</if>
|
||||
<if test="updateSite != null">update_site = #{updateSite},</if>
|
||||
</trim>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<delete id="deleteEmisTransPlanRuleById" parameterType="Long">
|
||||
update emis_trans_plan_rule set del_flag = '1' where id = #{id}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteEmisTransPlanRuleByIds" parameterType="String">
|
||||
update emis_trans_plan_rule set del_flag = '1' where id in
|
||||
<foreach item="id" collection="array" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</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>
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue
Block a user