|
|
@ -1,8 +1,11 @@ |
|
|
|
package com.qs.serve.modules.bms.controller; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.github.pagehelper.PageHelper; |
|
|
|
import com.qs.serve.common.framework.redis.RedisService; |
|
|
|
import com.qs.serve.common.model.annotation.SysLog; |
|
|
|
import com.qs.serve.common.model.consts.RedisCacheKeys; |
|
|
|
import com.qs.serve.common.model.dto.PageVo; |
|
|
|
import com.qs.serve.common.model.dto.R; |
|
|
|
import com.qs.serve.common.model.enums.BizType; |
|
|
@ -53,6 +56,7 @@ public class BmsSupplierController { |
|
|
|
private SysUserService sysUserService; |
|
|
|
private BmsSupplierMapper bmsSupplierMapper; |
|
|
|
private HisUserSupplierService hisUserSupplierService; |
|
|
|
private RedisService redisService; |
|
|
|
|
|
|
|
/** |
|
|
|
* 翻页查询 |
|
|
@ -114,27 +118,24 @@ public class BmsSupplierController { |
|
|
|
*/ |
|
|
|
@GetMapping("/tree") |
|
|
|
@PreAuthorize("hasRole('bms:supplier:query')") |
|
|
|
public R<List<BmsSupplierTreeVo>> getTree(BmsSupplier param){ |
|
|
|
Date d = new Date(); |
|
|
|
List<BmsSupplier> list = bmsSupplierService.selectSupplierList(param); |
|
|
|
Date d2 = new Date(); |
|
|
|
initSupplierList(list); |
|
|
|
Date d3 = new Date(); |
|
|
|
List<BmsSupplierTreeVo> list2 = list.stream().map(supplier->{ |
|
|
|
BmsSupplierTreeVo treeNode = CopierUtil.copy(supplier,new BmsSupplierTreeVo()); |
|
|
|
treeNode.setId(supplier.getId()); |
|
|
|
treeNode.setParentId(supplier.getPid()); |
|
|
|
treeNode.setSort(0); |
|
|
|
return treeNode; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
Date d4 = new Date(); |
|
|
|
list2 = TreeUtil.buildByRecursive(list2,TreeUtil.DEFAULT_PID_STRING); |
|
|
|
Date d5 = new Date(); |
|
|
|
System.out.println("d2-d"+(d2.getTime()-d.getTime())); |
|
|
|
System.out.println("d3-d2"+(d3.getTime()-d2.getTime())); |
|
|
|
System.out.println("d4-d3"+(d4.getTime()-d3.getTime())); |
|
|
|
System.out.println("d5-d4"+(d5.getTime()-d4.getTime())); |
|
|
|
return R.ok(list2); |
|
|
|
public R<?> getTree(BmsSupplier param){ |
|
|
|
String json = redisService.getString(RedisCacheKeys.SUPPLIER_RELATE_TREE); |
|
|
|
if(json==null){ |
|
|
|
List<BmsSupplier> list = bmsSupplierService.selectSupplierList(param); |
|
|
|
initSupplierList(list); |
|
|
|
List<BmsSupplierTreeVo> list2 = list.stream().map(supplier->{ |
|
|
|
BmsSupplierTreeVo treeNode = CopierUtil.copy(supplier,new BmsSupplierTreeVo()); |
|
|
|
treeNode.setId(supplier.getId()); |
|
|
|
treeNode.setParentId(supplier.getPid()); |
|
|
|
treeNode.setSort(0); |
|
|
|
return treeNode; |
|
|
|
}).collect(Collectors.toList()); |
|
|
|
list2 = TreeUtil.buildByRecursive(list2,TreeUtil.DEFAULT_PID_STRING); |
|
|
|
String jsonString = JsonUtil.objectToJson(list2); |
|
|
|
redisService.set(RedisCacheKeys.SUPPLIER_RELATE_TREE,jsonString); |
|
|
|
return R.ok(list2); |
|
|
|
} |
|
|
|
return R.ok(JSONArray.parseArray(json)); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -236,6 +237,7 @@ public class BmsSupplierController { |
|
|
|
initSupplierOtherInfo(supplierIds); |
|
|
|
//清空临时表
|
|
|
|
hisUserSupplierService.cleanTable(); |
|
|
|
redisService.remove(RedisCacheKeys.SUPPLIER_RELATE_TREE); |
|
|
|
return R.ok(); |
|
|
|
} |
|
|
|
|
|
|
@ -268,6 +270,7 @@ public class BmsSupplierController { |
|
|
|
initSupplierOtherInfo(Arrays.asList(supplier.getId())); |
|
|
|
//清空临时表
|
|
|
|
hisUserSupplierService.cleanTable(); |
|
|
|
redisService.remove(RedisCacheKeys.SUPPLIER_RELATE_TREE); |
|
|
|
return R.ok(); |
|
|
|
} |
|
|
|
|
|
|
@ -410,6 +413,7 @@ public class BmsSupplierController { |
|
|
|
return R.error("id不能为空"); |
|
|
|
} |
|
|
|
bmsSupplierService.edit(param); |
|
|
|
redisService.remove(RedisCacheKeys.SUPPLIER_RELATE_TREE); |
|
|
|
return R.ok(); |
|
|
|
} |
|
|
|
|
|
|
@ -428,11 +432,31 @@ public class BmsSupplierController { |
|
|
|
supplier.setPid("0"); |
|
|
|
supplier.setParentCode("0"); |
|
|
|
}else { |
|
|
|
BmsSupplier supplierdb = null; |
|
|
|
List<BmsSupplier> childList = null; |
|
|
|
if(param.getId()!=null){ |
|
|
|
supplierdb = bmsSupplierService.getById(param.getId()); |
|
|
|
childList = bmsSupplierService.listChildByPathIds(supplierdb.getPathIds()); |
|
|
|
} |
|
|
|
BmsSupplier parentNode = bmsSupplierService.getById(param.getPid()); |
|
|
|
supplier.setPid(param.getPid()+""); |
|
|
|
String[] pids = parentNode.getPathIds().split("_"); |
|
|
|
for (String pid : pids) { |
|
|
|
if(pid.equals(supplier.getId())){ |
|
|
|
return R.error("数据出现循环递归,保存失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
supplier.setPathIds(parentNode.getPathIds()+"_"+supplier.getId()); |
|
|
|
supplier.setParentCode(parentNode.getCode()); |
|
|
|
for (BmsSupplier bmsSupplier : childList) { |
|
|
|
BmsSupplier bmsSupplier2 = new BmsSupplier(); |
|
|
|
bmsSupplier2.setPathIds(bmsSupplier.getPathIds().replace(supplierdb.getPathIds(),supplier.getPathIds())); |
|
|
|
bmsSupplier2.setId(bmsSupplier.getId()); |
|
|
|
bmsSupplierService.updateById(bmsSupplier2); |
|
|
|
} |
|
|
|
} |
|
|
|
bmsSupplierService.updateById(supplier); |
|
|
|
redisService.remove(RedisCacheKeys.SUPPLIER_RELATE_TREE); |
|
|
|
return R.ok(); |
|
|
|
} |
|
|
|
|
|
|
@ -448,6 +472,7 @@ public class BmsSupplierController { |
|
|
|
bmsSupplierService.edit(param); |
|
|
|
//清空临时表
|
|
|
|
hisUserSupplierService.cleanTable(); |
|
|
|
redisService.remove(RedisCacheKeys.SUPPLIER_RELATE_TREE); |
|
|
|
return R.ok(); |
|
|
|
} |
|
|
|
|
|
|
@ -466,11 +491,12 @@ public class BmsSupplierController { |
|
|
|
bmsSupplierService.removeById(id); |
|
|
|
//清空临时表
|
|
|
|
hisUserSupplierService.cleanTable(); |
|
|
|
|
|
|
|
redisService.remove(RedisCacheKeys.SUPPLIER_RELATE_TREE); |
|
|
|
return R.ok(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 显示关联 |
|
|
|
* @param list |
|
|
|