|
|
@ -1,15 +1,23 @@ |
|
|
|
package com.cloud.kicc.system.controller; |
|
|
|
package com.cloud.kicc.system.controller; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.lang.tree.Tree; |
|
|
|
|
|
|
|
import cn.hutool.core.lang.tree.TreeNode; |
|
|
|
|
|
|
|
import cn.hutool.core.lang.tree.TreeNodeConfig; |
|
|
|
|
|
|
|
import cn.hutool.core.lang.tree.TreeUtil; |
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
import com.cloud.kicc.common.core.api.R; |
|
|
|
import com.cloud.kicc.common.core.api.R; |
|
|
|
import com.cloud.kicc.common.core.constant.AppConstants; |
|
|
|
import com.cloud.kicc.common.core.constant.AppConstants; |
|
|
|
import com.cloud.kicc.system.api.entity.Address; |
|
|
|
import com.cloud.kicc.system.api.entity.Address; |
|
|
|
|
|
|
|
import com.cloud.kicc.system.api.entity.Dept; |
|
|
|
|
|
|
|
import com.cloud.kicc.system.api.entity.User; |
|
|
|
import com.cloud.kicc.system.service.AddressService; |
|
|
|
import com.cloud.kicc.system.service.AddressService; |
|
|
|
|
|
|
|
import com.cloud.kicc.system.service.UserService; |
|
|
|
|
|
|
|
import com.sun.org.apache.bcel.internal.generic.NEW; |
|
|
|
import io.swagger.annotations.Api; |
|
|
|
import io.swagger.annotations.Api; |
|
|
|
import io.swagger.annotations.ApiOperation; |
|
|
|
|
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
|
|
|
@ -28,7 +36,7 @@ import java.util.List; |
|
|
|
@RequestMapping(AppConstants.APP_SYSTEM + "/address") |
|
|
|
@RequestMapping(AppConstants.APP_SYSTEM + "/address") |
|
|
|
@Api(value = "app", tags = "地址管理模块") |
|
|
|
@Api(value = "app", tags = "地址管理模块") |
|
|
|
public class AddressController { |
|
|
|
public class AddressController { |
|
|
|
|
|
|
|
private final UserService userService; |
|
|
|
private final AddressService addressService; |
|
|
|
private final AddressService addressService; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -37,7 +45,6 @@ public class AddressController { |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@PostMapping("/add") |
|
|
|
@PostMapping("/add") |
|
|
|
@ApiOperation(value = "新增") |
|
|
|
|
|
|
|
public R add(@RequestBody Address address){ |
|
|
|
public R add(@RequestBody Address address){ |
|
|
|
addressService.save(address); |
|
|
|
addressService.save(address); |
|
|
|
return R.ok(address); |
|
|
|
return R.ok(address); |
|
|
@ -49,21 +56,29 @@ public class AddressController { |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@PutMapping("/update") |
|
|
|
@PutMapping("/update") |
|
|
|
@ApiOperation(value = "修改") |
|
|
|
|
|
|
|
public R update(@RequestBody Address address){ |
|
|
|
public R update(@RequestBody Address address){ |
|
|
|
addressService.updateById(address); |
|
|
|
addressService.updateById(address); |
|
|
|
return R.ok(address); |
|
|
|
new Thread(() -> { |
|
|
|
|
|
|
|
List<User> userList = userService.list(new LambdaQueryWrapper<User>().eq(User::getDeptId, address.getId())); |
|
|
|
|
|
|
|
for (User user : userList) { |
|
|
|
|
|
|
|
user.setDeptName(address.getName()); |
|
|
|
|
|
|
|
userService.updateById(user); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}).start(); |
|
|
|
|
|
|
|
return R.ok(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 删除地址节点 |
|
|
|
* 删除地址节点 |
|
|
|
* @param ids 节点id |
|
|
|
* @param id 节点id |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@ApiOperation(value = "删除") |
|
|
|
@DeleteMapping("/remove/{id}") |
|
|
|
@DeleteMapping("/remove/{ids}") |
|
|
|
public R remove(@PathVariable("id") String id){ |
|
|
|
public R remove(@PathVariable("ids") String[] ids){ |
|
|
|
if(addressService.getMap(Wrappers.<Address>lambdaQuery().eq(Address::getParentId,id))!=null){ |
|
|
|
addressService.removeBatchByIds(Arrays.asList(ids)); |
|
|
|
return R.error("存在下级区域,不允许删除"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
addressService.removeById(id); |
|
|
|
return R.ok(); |
|
|
|
return R.ok(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -72,22 +87,82 @@ public class AddressController { |
|
|
|
* @param id |
|
|
|
* @param id |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@ApiOperation(value = "根据Id列表查询list") |
|
|
|
@GetMapping("/{id:\\w+}") |
|
|
|
@GetMapping("/query/{id}") |
|
|
|
|
|
|
|
public R getById(@PathVariable("id") String id) { |
|
|
|
public R getById(@PathVariable("id") String id) { |
|
|
|
return R.ok(addressService.getById(id)); |
|
|
|
return R.ok(addressService.getById(id)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 查询根据条件 |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
// @GetMapping("/list")
|
|
|
|
|
|
|
|
// public R list(Address address) {
|
|
|
|
|
|
|
|
// List<Address> addressList = addressService.queryList(address);
|
|
|
|
|
|
|
|
// return R.ok(addressList, addressList.size());
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
@GetMapping("/list") |
|
|
|
|
|
|
|
public R list(Address address){ |
|
|
|
|
|
|
|
List<Address> addressList = addressService.list(getQueryWrapper(address)); |
|
|
|
|
|
|
|
//配置
|
|
|
|
|
|
|
|
TreeNodeConfig treeNodeConfig = new TreeNodeConfig(); |
|
|
|
|
|
|
|
treeNodeConfig.setIdKey("code"); |
|
|
|
|
|
|
|
treeNodeConfig.setParentIdKey("parent_id"); |
|
|
|
|
|
|
|
treeNodeConfig.setNameKey("name"); |
|
|
|
|
|
|
|
treeNodeConfig.setWeightKey("sort"); |
|
|
|
|
|
|
|
//最大递归深度
|
|
|
|
|
|
|
|
treeNodeConfig.setDeep(3); |
|
|
|
|
|
|
|
//转换器
|
|
|
|
|
|
|
|
List<Tree<String>> treeNodes = TreeUtil.build(addressList,"0",treeNodeConfig,(treeNode,tree)->{ |
|
|
|
|
|
|
|
tree.setId(treeNode.getCode()); |
|
|
|
|
|
|
|
tree.setParentId(treeNode.getParentId()); |
|
|
|
|
|
|
|
tree.setName(treeNode.getName()); |
|
|
|
|
|
|
|
tree.setWeight(treeNode.getSort()); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
return R.ok(addressList,addressList.size()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 加载地址机构树 |
|
|
|
|
|
|
|
* */ |
|
|
|
|
|
|
|
@GetMapping("/addrTree") |
|
|
|
|
|
|
|
public R addrTree(){ |
|
|
|
|
|
|
|
List<Address> addrList = addressService.list(new LambdaQueryWrapper<Address>().orderByAsc(Address::getSort)); |
|
|
|
|
|
|
|
return R.ok(addressService.buildTree(addrList,"0")); |
|
|
|
|
|
|
|
} |
|
|
|
/** |
|
|
|
/** |
|
|
|
* 根据parentIds列表查询list |
|
|
|
* 根据parentIds列表查询list |
|
|
|
|
|
|
|
* @param parentIds |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@ApiOperation(value = "根据parentId列表查询list") |
|
|
|
@GetMapping("/queryByParentIds/{ids}") |
|
|
|
@GetMapping("/queryByParentId") |
|
|
|
public R queryByParentIds(@PathVariable("ids") String[] parentIds) { |
|
|
|
public R queryByParentId( Address address) { |
|
|
|
if (ObjectUtil.isEmpty(parentIds)) { |
|
|
|
List<Address> addressList = addressService.list(Wrappers.<Address>lambdaQuery().eq(Address::getParentId, address.getParentId())); |
|
|
|
return R.ok(new ArrayList<>(), 0); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
List<Address> addressList = addressService.queryListByParentIds(Arrays.asList(parentIds)); |
|
|
|
return R.ok(addressList, addressList.size()); |
|
|
|
return R.ok(addressList, addressList.size()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private LambdaQueryWrapper<Address> getQueryWrapper(Address address) { |
|
|
|
|
|
|
|
return Wrappers.<Address>lambdaQuery() |
|
|
|
|
|
|
|
.like(StrUtil.isNotBlank(address.getName()), Address::getName,address.getName()) |
|
|
|
|
|
|
|
.eq(StrUtil.isNotBlank(address.getParentId()), Address::getParentId, address.getParentId()) |
|
|
|
|
|
|
|
.between(StrUtil.isNotBlank(address.getBeginTime()) && StrUtil.isNotBlank(address.getEndTime()), Address::getCreateTime, address.getBeginTime(), address.getEndTime()) |
|
|
|
|
|
|
|
.like(StrUtil.isNotBlank(address.getCode()),Address::getCode, address.getCode()) |
|
|
|
|
|
|
|
.orderByAsc(Address::getSort); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// /**
|
|
|
|
|
|
|
|
// * 根据parentIds列表查询list
|
|
|
|
|
|
|
|
// * @return
|
|
|
|
|
|
|
|
// */
|
|
|
|
|
|
|
|
// @ApiOperation(value = "根据parentId列表查询list")
|
|
|
|
|
|
|
|
// @GetMapping("/list")
|
|
|
|
|
|
|
|
// public R queryByParentId( Address address) {
|
|
|
|
|
|
|
|
// List<Address> addressList = addressService.list(Wrappers.<Address>lambdaQuery().eq(Address::getParentId, address.getParentId()));
|
|
|
|
|
|
|
|
// return R.ok(addressList, addressList.size());
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |