2024-05-13 10:07:53 +08:00
|
|
|
package com.whdc.controller;
|
|
|
|
|
|
|
|
|
|
|
2024-05-13 14:55:42 +08:00
|
|
|
import cn.dev33.satoken.stp.StpUtil;
|
2024-06-04 17:56:05 +08:00
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
2024-05-16 21:42:45 +08:00
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
2024-05-28 13:05:31 +08:00
|
|
|
import com.whdc.exception.MyException;
|
2024-05-13 10:07:53 +08:00
|
|
|
import com.whdc.model.dto.AddressBootDto;
|
2024-05-29 15:13:59 +08:00
|
|
|
import com.whdc.model.entity.AbUdR;
|
|
|
|
|
import com.whdc.model.entity.AddressBook;
|
|
|
|
|
import com.whdc.model.entity.Organization;
|
|
|
|
|
import com.whdc.model.entity.User;
|
2024-05-13 14:55:42 +08:00
|
|
|
import com.whdc.model.enums.Role;
|
2024-05-13 10:07:53 +08:00
|
|
|
import com.whdc.model.enums.VersionsType;
|
|
|
|
|
import com.whdc.model.group.Insert;
|
|
|
|
|
import com.whdc.model.group.Update;
|
2024-05-28 10:41:40 +08:00
|
|
|
import com.whdc.model.vo.AdcdTree;
|
2024-05-15 14:23:37 +08:00
|
|
|
import com.whdc.model.vo.AddressBookVo;
|
2024-05-28 10:41:40 +08:00
|
|
|
import com.whdc.model.vo.ExcelABVo;
|
2024-05-16 14:37:21 +08:00
|
|
|
import com.whdc.service.*;
|
2024-05-28 10:41:40 +08:00
|
|
|
import com.whdc.utils.ExcelCommon;
|
2024-05-13 10:07:53 +08:00
|
|
|
import com.whdc.utils.ResultJson;
|
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
2024-05-28 13:45:56 +08:00
|
|
|
import io.swagger.annotations.ApiParam;
|
2024-05-13 10:07:53 +08:00
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
2024-05-28 10:41:40 +08:00
|
|
|
import org.apache.commons.compress.utils.Lists;
|
2024-05-14 17:00:57 +08:00
|
|
|
import org.apache.commons.lang3.StringUtils;
|
2024-05-13 10:07:53 +08:00
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2024-05-24 14:02:15 +08:00
|
|
|
import org.springframework.cache.annotation.CacheEvict;
|
2024-05-31 16:20:50 +08:00
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
2024-05-16 18:03:06 +08:00
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
2024-06-04 17:56:05 +08:00
|
|
|
import org.springframework.util.DigestUtils;
|
2024-05-13 10:07:53 +08:00
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
2024-06-04 14:18:15 +08:00
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
2024-05-13 10:07:53 +08:00
|
|
|
|
2024-05-28 10:41:40 +08:00
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
import java.time.LocalDateTime;
|
2024-06-04 17:56:05 +08:00
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
2024-05-28 10:41:40 +08:00
|
|
|
import java.util.stream.Collectors;
|
2024-05-13 10:07:53 +08:00
|
|
|
|
2024-05-24 14:02:15 +08:00
|
|
|
import static com.whdc.model.MyConstant.REDIS_KEY;
|
2024-06-04 15:05:47 +08:00
|
|
|
import static com.whdc.service.impl.AdinfoServiceImpl.TREE_ALL;
|
2024-05-24 14:02:15 +08:00
|
|
|
|
2024-05-13 10:07:53 +08:00
|
|
|
/**
|
|
|
|
|
* @author xusan
|
|
|
|
|
* @date 2024-05-11
|
|
|
|
|
*/
|
|
|
|
|
@Slf4j
|
|
|
|
|
@Api(tags = "通讯录 - Controller")
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/addressbook")
|
2024-05-16 18:03:06 +08:00
|
|
|
@Transactional
|
2024-05-13 10:07:53 +08:00
|
|
|
public class AddressBookController {
|
|
|
|
|
|
2024-06-03 16:33:51 +08:00
|
|
|
public static final String ADDRESS_BOOK_REDIS_KEY = REDIS_KEY + "addressbook";
|
2024-05-24 14:02:15 +08:00
|
|
|
|
2024-05-13 10:07:53 +08:00
|
|
|
@Autowired
|
|
|
|
|
private IAddressBookService service;
|
|
|
|
|
|
2024-05-13 14:55:42 +08:00
|
|
|
@Autowired
|
|
|
|
|
private IUserService userService;
|
|
|
|
|
|
2024-05-28 10:41:40 +08:00
|
|
|
@Autowired
|
|
|
|
|
private IAdinfoService adinfoService;
|
|
|
|
|
|
2024-05-13 10:07:53 +08:00
|
|
|
@Autowired
|
|
|
|
|
private IVersionsService versionsService;
|
|
|
|
|
|
2024-05-14 17:00:57 +08:00
|
|
|
@Autowired
|
|
|
|
|
private IOrganizationService organizationsService;
|
|
|
|
|
|
2024-05-16 14:37:21 +08:00
|
|
|
@Autowired
|
|
|
|
|
private IAbUdRService abUdRService;
|
|
|
|
|
|
2024-05-31 16:20:50 +08:00
|
|
|
@Autowired
|
|
|
|
|
private RedisTemplate redisTemplate;
|
|
|
|
|
|
2024-05-13 10:07:53 +08:00
|
|
|
|
|
|
|
|
// @ApiOperation(value = "查询所有")
|
|
|
|
|
// @PostMapping(value = "find")
|
|
|
|
|
// public ResultJson<AddressBook> find(@RequestBody AddressBook dto) {
|
|
|
|
|
//
|
|
|
|
|
// return ResultJson.ok(service.find(dto));
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "分页查询")
|
|
|
|
|
@PostMapping(value = "page")
|
2024-05-15 14:23:37 +08:00
|
|
|
public ResultJson<AddressBookVo> page(@RequestBody AddressBootDto dto) {
|
2024-05-15 14:15:50 +08:00
|
|
|
dto.setUserId(String.valueOf(StpUtil.getLoginId()));
|
2024-05-16 21:42:45 +08:00
|
|
|
IPage<AddressBookVo> page = service.page(dto);
|
|
|
|
|
|
2024-05-16 22:06:38 +08:00
|
|
|
// return ResultJson.ok(JSON.parseObject(JSON.toJSONString(page).replaceAll("null","")));
|
|
|
|
|
return ResultJson.ok(page);
|
2024-05-13 10:07:53 +08:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "添加")
|
|
|
|
|
@PostMapping(value = "save")
|
2024-05-24 14:02:15 +08:00
|
|
|
@CacheEvict(value = ADDRESS_BOOK_REDIS_KEY, allEntries = true)
|
2024-05-13 10:07:53 +08:00
|
|
|
public ResultJson insert(@RequestBody @Validated(Insert.class) AddressBook model) {
|
2024-05-22 14:35:09 +08:00
|
|
|
User user = userService.getRole(Integer.valueOf(String.valueOf(StpUtil.getLoginId())));
|
2024-05-13 14:55:42 +08:00
|
|
|
|
2024-05-22 14:35:09 +08:00
|
|
|
switch (Objects.requireNonNull(Role.getByName(user.getRole()))) {
|
2024-05-24 14:02:15 +08:00
|
|
|
case R000:
|
|
|
|
|
return ResultJson.error("权限不足");
|
2024-05-13 14:55:42 +08:00
|
|
|
case R001:
|
2024-05-24 14:02:15 +08:00
|
|
|
case R099:
|
2024-05-31 09:20:03 +08:00
|
|
|
if (Integer.parseInt(model.getRole()) > Integer.parseInt(user.getRole())) {
|
|
|
|
|
return ResultJson.error("权限不足!");
|
|
|
|
|
}
|
2024-05-24 14:02:15 +08:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return ResultJson.error("权限不足!!");
|
2024-05-13 14:55:42 +08:00
|
|
|
}
|
2024-05-13 10:07:53 +08:00
|
|
|
|
2024-05-24 14:02:15 +08:00
|
|
|
if (StringUtils.isNotBlank(model.getRole())) {
|
2024-05-23 15:57:38 +08:00
|
|
|
switch (Objects.requireNonNull(Role.getByName(user.getRole()))) {
|
|
|
|
|
case R000:
|
|
|
|
|
case R001:
|
2024-05-24 14:02:15 +08:00
|
|
|
case R099:
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return ResultJson.error("权限不匹配");
|
2024-05-23 15:57:38 +08:00
|
|
|
}
|
2024-05-24 14:02:15 +08:00
|
|
|
if (Integer.parseInt(user.getRole()) < Integer.parseInt(model.getRole())) {
|
2024-05-23 15:57:38 +08:00
|
|
|
return ResultJson.error("权限不足!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-13 10:07:53 +08:00
|
|
|
if (CollectionUtils.isNotEmpty(
|
|
|
|
|
service.lambdaQuery()
|
2024-05-24 14:02:15 +08:00
|
|
|
.eq(AddressBook::getName, String.valueOf(model.getName()).trim())
|
|
|
|
|
.list())
|
|
|
|
|
) {
|
2024-05-13 10:07:53 +08:00
|
|
|
return ResultJson.error("该名称重复");
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-22 10:28:46 +08:00
|
|
|
if (StringUtils.isNotBlank(model.getPhone()) && CollectionUtils.isNotEmpty(
|
|
|
|
|
service.lambdaQuery()
|
2024-05-24 14:02:15 +08:00
|
|
|
.eq(AddressBook::getPhone, model.getPhone().trim())
|
|
|
|
|
.list())
|
|
|
|
|
) {
|
2024-05-22 10:28:46 +08:00
|
|
|
return ResultJson.error("该手机号已存在");
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-13 10:07:53 +08:00
|
|
|
|
2024-05-31 09:20:03 +08:00
|
|
|
model.setId(null);
|
2024-05-13 14:55:42 +08:00
|
|
|
boolean save = service.save(model);
|
|
|
|
|
|
2024-05-31 09:20:03 +08:00
|
|
|
// 添加日志
|
|
|
|
|
String adcd = model.getAdcd();
|
|
|
|
|
versionsService.saveInfo(model, VersionsType.ADD, adcd);
|
|
|
|
|
|
2024-05-24 14:02:15 +08:00
|
|
|
if (save) {
|
2024-05-31 16:20:50 +08:00
|
|
|
redisTemplate.delete(ADDRESS_BOOK_REDIS_KEY + "*");
|
2024-05-14 17:00:57 +08:00
|
|
|
// 没有手机号用名字注册
|
2024-05-16 18:03:06 +08:00
|
|
|
//"省防指".equals(organizationsService.getById(model.getOrganization()).getName())
|
|
|
|
|
// &&
|
2024-05-24 14:02:15 +08:00
|
|
|
if (StringUtils.isBlank(model.getPhone())) {
|
|
|
|
|
if (StringUtils.isNotBlank(model.getTel())) {
|
|
|
|
|
userService.register(model.getTel(), model.getId(), model.getRole());
|
|
|
|
|
} else {
|
|
|
|
|
userService.register(model.getName(), model.getId(), model.getRole());
|
2024-05-22 10:51:42 +08:00
|
|
|
}
|
2024-05-14 17:00:57 +08:00
|
|
|
|
2024-05-24 14:02:15 +08:00
|
|
|
} else {
|
|
|
|
|
userService.register(model.getPhone(), model.getId(), model.getRole());
|
2024-05-14 17:00:57 +08:00
|
|
|
}
|
2024-05-16 14:37:21 +08:00
|
|
|
|
2024-05-31 09:20:03 +08:00
|
|
|
if (StringUtils.isNotBlank(adcd)) {
|
|
|
|
|
List<AbUdR> list = abUdRService.lambdaQuery().eq(AbUdR::getDictId, model.getAdcd())
|
|
|
|
|
.select(AbUdR::getSort)
|
|
|
|
|
.orderByDesc(AbUdR::getSort)
|
|
|
|
|
.list();
|
|
|
|
|
Integer sort = 0;
|
|
|
|
|
if (CollectionUtils.isNotEmpty(list)) {
|
|
|
|
|
AbUdR abUdR = list.get(0);
|
|
|
|
|
sort = abUdR.getSort() + 1;
|
|
|
|
|
}
|
|
|
|
|
abUdRService.save(new AbUdR(model.getId(), adcd.replaceFirst("000000", ""), ++sort, model.getType()));
|
2024-05-24 14:02:15 +08:00
|
|
|
} else {
|
2024-05-31 09:20:03 +08:00
|
|
|
List<AbUdR> list = abUdRService.lambdaQuery().eq(AbUdR::getDictId, model.getOrganization())
|
|
|
|
|
.select(AbUdR::getSort)
|
|
|
|
|
.orderByDesc(AbUdR::getSort)
|
|
|
|
|
.list();
|
|
|
|
|
Integer sort = 0;
|
|
|
|
|
if (CollectionUtils.isNotEmpty(list)) {
|
|
|
|
|
AbUdR abUdR = list.get(0);
|
|
|
|
|
sort = abUdR.getSort() + 1;
|
|
|
|
|
}
|
2024-05-24 14:02:15 +08:00
|
|
|
// 添加关联关系`
|
2024-05-31 09:20:03 +08:00
|
|
|
abUdRService.save(new AbUdR(model.getId(), model.getOrganization(), sort, model.getType()));
|
2024-05-24 14:02:15 +08:00
|
|
|
}
|
2024-05-13 14:55:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ResultJson.ok(save);
|
2024-05-13 10:07:53 +08:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "修改")
|
|
|
|
|
@PostMapping(value = "edit")
|
2024-05-24 14:02:15 +08:00
|
|
|
@CacheEvict(value = ADDRESS_BOOK_REDIS_KEY, allEntries = true)
|
2024-05-13 10:07:53 +08:00
|
|
|
public ResultJson update(@RequestBody @Validated(Update.class) AddressBook model) {
|
|
|
|
|
|
2024-05-16 14:01:42 +08:00
|
|
|
Integer loginId = Integer.valueOf(String.valueOf(StpUtil.getLoginId()));
|
2024-05-22 14:35:09 +08:00
|
|
|
User user = userService.getRole(loginId);
|
2024-05-13 14:55:42 +08:00
|
|
|
|
2024-05-22 14:35:09 +08:00
|
|
|
switch (Objects.requireNonNull(Role.getByName(user.getRole()))) {
|
2024-05-24 14:02:15 +08:00
|
|
|
case R000: {
|
2024-05-13 14:55:42 +08:00
|
|
|
// 不是修改自己
|
2024-05-24 14:02:15 +08:00
|
|
|
if (!model.getId().equals(user.getAbId())) {
|
2024-05-13 14:55:42 +08:00
|
|
|
return ResultJson.error("权限不足");
|
|
|
|
|
}
|
2024-05-24 14:02:15 +08:00
|
|
|
}
|
|
|
|
|
;
|
2024-05-13 14:55:42 +08:00
|
|
|
case R001:
|
2024-05-24 14:02:15 +08:00
|
|
|
case R099:
|
2024-05-31 09:20:03 +08:00
|
|
|
if (Integer.parseInt(model.getRole()) > Integer.parseInt(user.getRole())) {
|
|
|
|
|
return ResultJson.error("权限不足!");
|
|
|
|
|
}
|
2024-05-24 14:02:15 +08:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return ResultJson.error("权限不足!!");
|
2024-05-13 14:55:42 +08:00
|
|
|
}
|
|
|
|
|
|
2024-05-24 14:02:15 +08:00
|
|
|
if (StringUtils.isNotBlank(model.getRole())) {
|
2024-05-23 15:57:38 +08:00
|
|
|
switch (Objects.requireNonNull(Role.getByName(user.getRole()))) {
|
|
|
|
|
case R000:
|
|
|
|
|
case R001:
|
2024-05-24 14:02:15 +08:00
|
|
|
case R099:
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return ResultJson.error("权限不匹配");
|
2024-05-23 15:57:38 +08:00
|
|
|
}
|
2024-05-24 14:02:15 +08:00
|
|
|
if (Integer.parseInt(user.getRole()) < Integer.parseInt(model.getRole())) {
|
2024-05-23 15:57:38 +08:00
|
|
|
return ResultJson.error("权限不足!");
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-13 10:07:53 +08:00
|
|
|
AddressBook byId = service.getById(model.getId());
|
2024-05-24 14:02:15 +08:00
|
|
|
if (Objects.isNull(byId)) {
|
2024-05-13 10:07:53 +08:00
|
|
|
return ResultJson.error("当前数据不存在");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(
|
|
|
|
|
service.lambdaQuery()
|
2024-05-24 14:02:15 +08:00
|
|
|
.eq(AddressBook::getName, String.valueOf(model.getName()).trim())
|
2024-05-13 10:07:53 +08:00
|
|
|
.ne(AddressBook::getId, model.getId())
|
|
|
|
|
.list())
|
2024-05-24 14:02:15 +08:00
|
|
|
) {
|
2024-05-13 10:07:53 +08:00
|
|
|
return ResultJson.error("该名称重复");
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-22 10:28:46 +08:00
|
|
|
if (StringUtils.isNotBlank(model.getPhone()) && CollectionUtils.isNotEmpty(
|
|
|
|
|
service.lambdaQuery()
|
2024-05-24 14:02:15 +08:00
|
|
|
.eq(AddressBook::getPhone, model.getPhone().trim())
|
2024-05-22 10:28:46 +08:00
|
|
|
.ne(AddressBook::getId, model.getId())
|
|
|
|
|
.list())
|
2024-05-24 14:02:15 +08:00
|
|
|
) {
|
2024-05-22 10:28:46 +08:00
|
|
|
return ResultJson.error("该手机号已存在");
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-13 10:07:53 +08:00
|
|
|
// List<Versions> list = versionsService.lambdaQuery()
|
|
|
|
|
// .eq(Versions::getAbId, model.getId())
|
|
|
|
|
// .list();
|
|
|
|
|
// Integer version = 0;
|
|
|
|
|
// if (CollectionUtils.isNotEmpty(list)){
|
|
|
|
|
// version = list
|
|
|
|
|
// .stream().map(Versions::getVersion)
|
|
|
|
|
// .max(Comparator.comparing(Integer::intValue))
|
|
|
|
|
// .get();
|
|
|
|
|
// }else{
|
|
|
|
|
// log.info("当前数据在进行修改但无相关记录;" + model.getId());
|
|
|
|
|
// }
|
|
|
|
|
// // 添加日志
|
|
|
|
|
// versionsService.save(new Versions(null, JSON.toJSONString(model),model.getId(),++version,model.getCreateId(),new Date(), VersionsType.UPDATE.getName()));
|
2024-05-29 15:19:22 +08:00
|
|
|
String adcd = model.getAdcd();
|
2024-05-31 09:20:03 +08:00
|
|
|
if (StringUtils.isBlank(adcd)) {
|
2024-05-29 15:19:22 +08:00
|
|
|
adcd = byId.getAdcd();
|
|
|
|
|
}
|
2024-05-30 11:15:49 +08:00
|
|
|
model.setRole(user.getRole());
|
2024-05-31 09:20:03 +08:00
|
|
|
versionsService.saveInfo(model, VersionsType.UPDATE, adcd);
|
2024-05-16 14:37:21 +08:00
|
|
|
boolean data = service.updateById(model);
|
|
|
|
|
if (data) {
|
2024-05-31 16:20:50 +08:00
|
|
|
|
|
|
|
|
redisTemplate.delete(ADDRESS_BOOK_REDIS_KEY + "*");
|
|
|
|
|
|
|
|
|
|
|
2024-05-24 14:02:15 +08:00
|
|
|
String organization = model.getOrganization();
|
|
|
|
|
if (StringUtils.isNotBlank(model.getAdcd())) {
|
|
|
|
|
organization = model.getAdcd().replaceFirst("000000", "");
|
|
|
|
|
}
|
2024-05-31 09:20:03 +08:00
|
|
|
Integer sort = model.getSort();
|
2024-06-04 17:56:05 +08:00
|
|
|
if (0 != sort) {
|
2024-05-31 09:20:03 +08:00
|
|
|
boolean update = abUdRService.lambdaUpdate()
|
|
|
|
|
.set(AbUdR::getSort, sort)
|
|
|
|
|
.set(AbUdR::getDictId, organization)
|
|
|
|
|
.eq(AbUdR::getAdId, model.getId())
|
|
|
|
|
.update();
|
|
|
|
|
log.info("修改abUdR: " + update);
|
|
|
|
|
}
|
2024-05-22 10:51:42 +08:00
|
|
|
|
|
|
|
|
User one = userService.lambdaQuery().eq(User::getAbId, model.getId()).one();
|
2024-05-24 14:02:15 +08:00
|
|
|
if (Objects.nonNull(one)) {
|
2024-05-22 10:51:42 +08:00
|
|
|
// 没有就创建账号
|
2024-05-24 14:02:15 +08:00
|
|
|
if (StringUtils.isBlank(model.getPhone())) {
|
|
|
|
|
if (StringUtils.isNotBlank(model.getTel())) {
|
2024-05-22 10:51:42 +08:00
|
|
|
if (!one.getUsername().equals(model.getTel())) {
|
|
|
|
|
one.setUsername(model.getTel())
|
|
|
|
|
.updateById();
|
|
|
|
|
}
|
2024-05-24 14:02:15 +08:00
|
|
|
} else {
|
2024-05-22 10:51:42 +08:00
|
|
|
if (!one.getUsername().equals(model.getName())) {
|
|
|
|
|
one.setUsername(model.getName())
|
|
|
|
|
.updateById();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-24 14:02:15 +08:00
|
|
|
} else {
|
2024-05-22 10:51:42 +08:00
|
|
|
if (!one.getUsername().equals(model.getPhone())) {
|
|
|
|
|
one.setUsername(model.getPhone())
|
|
|
|
|
.updateById();
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-24 14:02:15 +08:00
|
|
|
} else {
|
2024-05-22 10:51:42 +08:00
|
|
|
// 没有就创建账号
|
2024-05-24 14:02:15 +08:00
|
|
|
if (StringUtils.isBlank(model.getPhone())) {
|
|
|
|
|
if (StringUtils.isNotBlank(model.getTel())) {
|
|
|
|
|
userService.register(model.getTel(), model.getId(), model.getRole());
|
|
|
|
|
} else {
|
|
|
|
|
userService.register(model.getName(), model.getId(), model.getRole());
|
2024-05-22 10:51:42 +08:00
|
|
|
}
|
|
|
|
|
|
2024-05-24 14:02:15 +08:00
|
|
|
} else {
|
|
|
|
|
userService.register(model.getPhone(), model.getId(), model.getRole());
|
2024-05-22 10:51:42 +08:00
|
|
|
}
|
|
|
|
|
}
|
2024-05-16 14:37:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ResultJson.ok(data);
|
2024-05-13 10:07:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "修改权限")
|
2024-05-13 16:44:01 +08:00
|
|
|
@PostMapping(value = "updateRole")
|
2024-05-30 09:14:30 +08:00
|
|
|
public ResultJson updateRole(@RequestBody @Validated(Update.class) AddressBook model) {
|
2024-05-13 10:07:53 +08:00
|
|
|
|
2024-05-16 14:01:42 +08:00
|
|
|
Integer loginId = Integer.valueOf(String.valueOf(StpUtil.getLoginId()));
|
2024-05-22 14:35:09 +08:00
|
|
|
User user = userService.getRole(loginId);
|
2024-05-13 14:55:42 +08:00
|
|
|
|
2024-05-22 14:35:09 +08:00
|
|
|
switch (Objects.requireNonNull(Role.getByName(user.getRole()))) {
|
2024-05-13 14:55:42 +08:00
|
|
|
case R000:
|
2024-05-24 14:02:15 +08:00
|
|
|
case R001:
|
2024-05-29 16:49:04 +08:00
|
|
|
case R099: {
|
2024-05-31 09:20:03 +08:00
|
|
|
if (Integer.parseInt(model.getRole()) > Integer.parseInt(user.getRole())) {
|
2024-05-29 16:49:04 +08:00
|
|
|
return ResultJson.error("权限不足");
|
|
|
|
|
}
|
2024-05-24 14:02:15 +08:00
|
|
|
break;
|
2024-05-29 16:49:04 +08:00
|
|
|
}
|
2024-05-24 14:02:15 +08:00
|
|
|
default:
|
|
|
|
|
return ResultJson.error("权限不足!!");
|
2024-05-13 14:55:42 +08:00
|
|
|
}
|
|
|
|
|
|
2024-05-30 09:14:30 +08:00
|
|
|
AddressBook byId = service.getById(model.getId());
|
2024-05-24 14:02:15 +08:00
|
|
|
if (Objects.isNull(byId)) {
|
2024-05-13 10:07:53 +08:00
|
|
|
return ResultJson.error("当前数据不存在");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// List<Versions> list = versionsService.lambdaQuery()
|
|
|
|
|
// .eq(Versions::getAbId, model.getId())
|
|
|
|
|
// .list();
|
|
|
|
|
// Integer version = 0;
|
|
|
|
|
// if (CollectionUtils.isNotEmpty(list)){
|
|
|
|
|
// version = list
|
|
|
|
|
// .stream().map(Versions::getVersion)
|
|
|
|
|
// .max(Comparator.comparing(Integer::intValue))
|
|
|
|
|
// .get();
|
|
|
|
|
// }else{
|
|
|
|
|
// log.info("当前数据在进行修改但无相关记录;" + model.getId());
|
|
|
|
|
// }
|
|
|
|
|
// // 添加日志
|
|
|
|
|
// versionsService.save(new Versions(null, JSON.toJSONString(model),model.getId(),++version,model.getCreateId(),new Date(), VersionsType.UPDATE_ROLE.getName()));
|
2024-05-30 09:14:30 +08:00
|
|
|
byId.setOname(model.getOname());
|
|
|
|
|
byId.setRole(model.getRole());
|
2024-05-31 09:20:03 +08:00
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
Thread.sleep(100);
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
}
|
|
|
|
|
versionsService.saveInfo(byId, VersionsType.UPDATE_ROLE, byId.getAdcd());
|
2024-05-13 10:07:53 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// 只修改角色
|
2024-05-13 14:55:42 +08:00
|
|
|
|
2024-05-30 09:14:30 +08:00
|
|
|
boolean update = userService.lambdaUpdate()
|
|
|
|
|
.set(User::getRole, model.getRole())
|
|
|
|
|
.eq(User::getAbId, model.getId())
|
2024-05-13 10:07:53 +08:00
|
|
|
.update();
|
|
|
|
|
return ResultJson.ok(update);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-06-03 14:14:30 +08:00
|
|
|
@ApiOperation(value = "设置白名单")
|
|
|
|
|
@PostMapping(value = "setWhitelists")
|
|
|
|
|
public ResultJson setWhitelists(@RequestBody @Validated(Update.class) AddressBook model) {
|
|
|
|
|
|
|
|
|
|
Integer loginId = Integer.valueOf(String.valueOf(StpUtil.getLoginId()));
|
|
|
|
|
User user = userService.getRole(loginId);
|
|
|
|
|
|
|
|
|
|
switch (Objects.requireNonNull(Role.getByName(user.getRole()))) {
|
|
|
|
|
case R000:
|
|
|
|
|
case R001:
|
|
|
|
|
return ResultJson.error("权限不足");
|
|
|
|
|
case R099: {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
return ResultJson.error("权限不足!!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AddressBook byId = service.getById(model.getId());
|
|
|
|
|
if (Objects.isNull(byId)) {
|
|
|
|
|
return ResultJson.error("当前数据不存在");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
byId.setIsPass(model.getIsPass());
|
|
|
|
|
versionsService.saveInfo(model, VersionsType.WHITE, byId.getAdcd());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boolean update = service.lambdaUpdate()
|
|
|
|
|
.set(AddressBook::getIsPass, model.getIsPass())
|
|
|
|
|
.eq(AddressBook::getId, model.getId())
|
|
|
|
|
.update();
|
2024-06-04 17:56:05 +08:00
|
|
|
if (!update) {
|
2024-06-03 14:14:30 +08:00
|
|
|
throw new MyException("操作数据库失败");
|
|
|
|
|
}
|
|
|
|
|
return ResultJson.ok(update);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-05-13 10:07:53 +08:00
|
|
|
@ApiOperation(value = "删除")
|
|
|
|
|
@GetMapping(value = "del/{id}")
|
2024-05-24 14:02:15 +08:00
|
|
|
@CacheEvict(value = ADDRESS_BOOK_REDIS_KEY, allEntries = true)
|
2024-05-13 10:07:53 +08:00
|
|
|
public ResultJson delete(@PathVariable("id") Integer id) {
|
|
|
|
|
|
2024-05-16 14:01:42 +08:00
|
|
|
Integer loginId = Integer.valueOf(String.valueOf(StpUtil.getLoginId()));
|
2024-05-22 14:35:09 +08:00
|
|
|
User user = userService.getRole(loginId);
|
2024-05-31 09:20:03 +08:00
|
|
|
AddressBook model = service.getById(id);
|
|
|
|
|
|
|
|
|
|
if (Objects.isNull(model)) {
|
|
|
|
|
return ResultJson.error("当前数据不存在");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
User delUser = userService.lambdaQuery()
|
2024-06-04 17:56:05 +08:00
|
|
|
.eq(User::getAbId, model.getId())
|
2024-05-31 09:20:03 +08:00
|
|
|
.one();
|
2024-05-13 14:55:42 +08:00
|
|
|
|
2024-05-22 14:35:09 +08:00
|
|
|
switch (Objects.requireNonNull(Role.getByName(user.getRole()))) {
|
2024-05-13 14:55:42 +08:00
|
|
|
case R000:
|
2024-05-24 14:02:15 +08:00
|
|
|
case R001:
|
|
|
|
|
case R099:
|
2024-05-31 09:20:03 +08:00
|
|
|
if (Integer.parseInt(delUser.getRole()) > Integer.parseInt(user.getRole())) {
|
|
|
|
|
return ResultJson.error("权限不足");
|
|
|
|
|
}
|
2024-05-24 14:02:15 +08:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return ResultJson.error("权限不足!!");
|
2024-05-13 14:55:42 +08:00
|
|
|
}
|
|
|
|
|
|
2024-05-13 10:07:53 +08:00
|
|
|
|
|
|
|
|
// List<Versions> list = versionsService.lambdaQuery()
|
|
|
|
|
// .eq(Versions::getAbId, model.getId())
|
|
|
|
|
// .list();
|
|
|
|
|
// Integer version = 0;
|
|
|
|
|
// if (CollectionUtils.isNotEmpty(list)){
|
|
|
|
|
// version = list
|
|
|
|
|
// .stream().map(Versions::getVersion)
|
|
|
|
|
// .max(Comparator.comparing(Integer::intValue))
|
|
|
|
|
// .get();
|
|
|
|
|
// }else{
|
|
|
|
|
// log.info("当前数据在进行修改但无相关记录;" + model.getId());
|
|
|
|
|
// }
|
|
|
|
|
// // 添加日志
|
|
|
|
|
// versionsService.save(new Versions(null, JSON.toJSONString(model),model.getId(),++version,model.getCreateId(),new Date(), VersionsType.DEL.getName()));
|
2024-05-31 09:20:03 +08:00
|
|
|
versionsService.saveInfo(model, VersionsType.DEL, model.getAdcd());
|
2024-05-13 10:07:53 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
return ResultJson.ok(service.removeById(id));
|
|
|
|
|
}
|
2024-05-16 15:43:45 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "查询详情")
|
|
|
|
|
@GetMapping(value = "get/{id}")
|
|
|
|
|
public ResultJson get(@PathVariable("id") Integer id) {
|
2024-05-16 15:55:48 +08:00
|
|
|
|
2024-05-21 17:17:57 +08:00
|
|
|
AddressBook byId = service.getById(id);
|
2024-05-24 14:02:15 +08:00
|
|
|
if (byId != null) {
|
|
|
|
|
if (StringUtils.isNotBlank(byId.getOrganization())) {
|
2024-05-21 17:17:57 +08:00
|
|
|
Organization byId2 = organizationsService.getById(byId.getOrganization());
|
2024-05-24 14:02:15 +08:00
|
|
|
if (byId2 != null) {
|
2024-05-21 17:17:57 +08:00
|
|
|
byId.setOname(byId2.getName());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ResultJson.ok(byId);
|
2024-05-16 15:43:45 +08:00
|
|
|
}
|
|
|
|
|
|
2024-05-16 15:55:48 +08:00
|
|
|
@ApiOperation(value = "查询用户详情")
|
|
|
|
|
@GetMapping(value = "getByUser/{userId}")
|
|
|
|
|
public ResultJson getByUser(@PathVariable("userId") Integer userId) {
|
|
|
|
|
User byId = userService.getById(userId);
|
2024-05-24 14:02:15 +08:00
|
|
|
if (Objects.isNull(byId)) {
|
2024-05-16 15:55:48 +08:00
|
|
|
return ResultJson.error("该用户不存在");
|
|
|
|
|
}
|
2024-05-16 22:06:38 +08:00
|
|
|
// return ResultJson.ok(JSON.parseObject(JSON.toJSONString(service.getById(byId.getAbId())).replaceAll("null","")));
|
2024-05-21 17:17:57 +08:00
|
|
|
AddressBook byId1 = service.getById(byId.getAbId());
|
2024-05-24 14:02:15 +08:00
|
|
|
if (byId1 != null) {
|
|
|
|
|
if (StringUtils.isNotBlank(byId1.getOrganization())) {
|
2024-05-21 17:17:57 +08:00
|
|
|
Organization byId2 = organizationsService.getById(byId1.getOrganization());
|
2024-05-24 14:02:15 +08:00
|
|
|
if (byId2 != null) {
|
2024-05-21 17:17:57 +08:00
|
|
|
byId1.setOname(byId2.getName());
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-22 14:53:01 +08:00
|
|
|
byId1.setRole(byId.getRole());
|
2024-05-21 17:17:57 +08:00
|
|
|
}
|
|
|
|
|
return ResultJson.ok(byId1);
|
2024-05-16 15:55:48 +08:00
|
|
|
}
|
|
|
|
|
|
2024-05-28 10:41:40 +08:00
|
|
|
|
|
|
|
|
@ApiOperation(value = "通过行政区划下载excel")
|
|
|
|
|
@GetMapping(value = "getExcel/{adnm}")
|
2024-05-28 13:45:56 +08:00
|
|
|
public void getExcel(@PathVariable("adnm")
|
2024-05-31 09:20:03 +08:00
|
|
|
@ApiParam(value = "名称,all: 查询全部")
|
|
|
|
|
String adnm, HttpServletResponse response) {
|
2024-05-28 13:05:31 +08:00
|
|
|
|
|
|
|
|
// 查询全部标识
|
|
|
|
|
if ("all".equals(adnm)) {
|
2024-05-28 13:45:56 +08:00
|
|
|
adnm = "";
|
2024-05-28 13:05:31 +08:00
|
|
|
}
|
2024-05-28 10:41:40 +08:00
|
|
|
|
2024-06-04 15:05:47 +08:00
|
|
|
List<AdcdTree> tree = adinfoService.tree(TREE_ALL, TREE_ALL);
|
2024-05-28 10:41:40 +08:00
|
|
|
|
2024-05-28 13:05:31 +08:00
|
|
|
if (CollectionUtils.isEmpty(tree)) {
|
|
|
|
|
throw new MyException("当前行政区划不存在");
|
2024-05-28 10:41:40 +08:00
|
|
|
}
|
|
|
|
|
|
2024-06-04 17:56:05 +08:00
|
|
|
// List<AddressBook> addressBooks = service.lambdaQuery().isNotNull(AddressBook::getAdcd)
|
|
|
|
|
// .list();
|
|
|
|
|
List<AddressBook> addressBooks = service.lambdaQuery().likeLeft(AddressBook::getAdcd, "000000000")
|
2024-05-28 10:41:40 +08:00
|
|
|
.list();
|
|
|
|
|
|
|
|
|
|
if (CollectionUtils.isEmpty(addressBooks)) {
|
2024-05-28 13:05:31 +08:00
|
|
|
throw new MyException("行政区划责任人为空");
|
2024-05-28 10:41:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Map<String, List<AddressBook>> abMap = addressBooks.stream().collect(Collectors.groupingBy(AddressBook::getAdcd, Collectors.toList()));
|
|
|
|
|
|
|
|
|
|
// 行政区划责任人数据
|
|
|
|
|
List<ExcelABVo> data = Lists.newArrayList();
|
|
|
|
|
|
2024-05-28 13:05:31 +08:00
|
|
|
String finalAdnm = adnm;
|
|
|
|
|
for (int i = 0; i < tree.size(); i++) {
|
|
|
|
|
AdcdTree t = tree.get(i);
|
2024-06-04 17:56:05 +08:00
|
|
|
// String adcd = t.getAdcd();
|
2024-05-28 10:41:40 +08:00
|
|
|
String cityAdnm = t.getAdnm();
|
2024-06-04 17:56:05 +08:00
|
|
|
// List<AddressBook> books = abMap.get(adcd);
|
|
|
|
|
// if (CollectionUtils.isEmpty(books)) {
|
|
|
|
|
// continue;
|
|
|
|
|
// }
|
|
|
|
|
// books.forEach(b -> {
|
|
|
|
|
// if (StringUtils.isNotBlank(finalAdnm)) {
|
|
|
|
|
// if (cityAdnm.equals(finalAdnm)) {
|
|
|
|
|
// data.add(new ExcelABVo(cityAdnm, cityAdnm, b.getName(), b.getPosition(), b.getPhone()));
|
|
|
|
|
// }
|
|
|
|
|
// } else {
|
|
|
|
|
// data.add(new ExcelABVo(cityAdnm, cityAdnm, b.getName(), b.getPosition(), b.getPhone()));
|
|
|
|
|
// }
|
|
|
|
|
// });
|
2024-05-28 10:41:40 +08:00
|
|
|
|
2024-05-28 13:05:31 +08:00
|
|
|
List<AdcdTree> children = t.getChildren();
|
|
|
|
|
if (CollectionUtils.isNotEmpty(children)) {
|
|
|
|
|
for (int i1 = 1; i1 < children.size(); i1++) {
|
|
|
|
|
AdcdTree tc = children.get(i1);
|
|
|
|
|
String tcAdcd = tc.getAdcd();
|
|
|
|
|
String tcCityAdnm = tc.getAdnm();
|
|
|
|
|
List<AddressBook> tcBooks = abMap.get(tcAdcd);
|
|
|
|
|
if (CollectionUtils.isEmpty(tcBooks)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
tcBooks.forEach(b -> {
|
|
|
|
|
if (StringUtils.isNotBlank(finalAdnm)) {
|
|
|
|
|
if (cityAdnm.equals(finalAdnm) || tcCityAdnm.equals(finalAdnm)) {
|
|
|
|
|
data.add(new ExcelABVo(cityAdnm, tcCityAdnm, b.getName(), b.getPosition(), b.getPhone()));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
data.add(new ExcelABVo(cityAdnm, tcCityAdnm, b.getName(), b.getPosition(), b.getPhone()));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-31 09:20:03 +08:00
|
|
|
}
|
2024-05-28 10:41:40 +08:00
|
|
|
|
|
|
|
|
if (CollectionUtils.isEmpty(data)) {
|
2024-05-28 13:05:31 +08:00
|
|
|
throw new MyException("当前行政区划责任人为空");
|
2024-05-28 10:41:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ExcelCommon.exportExcel(data,
|
2024-05-28 13:08:36 +08:00
|
|
|
null, "防汛抗旱通讯录", ExcelABVo.class, "防汛抗旱通讯录_" + adnm + "_" + LocalDateTime.now() + ".xlsx",
|
2024-05-28 10:41:40 +08:00
|
|
|
response);
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-04 14:18:15 +08:00
|
|
|
@ApiOperation(value = "行政区划联系人导入")
|
2024-06-04 17:56:05 +08:00
|
|
|
@PostMapping(value = "uploadExcel")
|
|
|
|
|
public ResultJson uploadExcel(MultipartFile file) {
|
2024-06-04 14:18:15 +08:00
|
|
|
|
|
|
|
|
List<ExcelABVo> appends = ExcelCommon.importExcel(file, 0, 1, ExcelABVo.class);
|
|
|
|
|
|
|
|
|
|
if (CollectionUtils.isEmpty(appends)) {
|
|
|
|
|
throw new MyException("文件为空");
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-04 17:56:05 +08:00
|
|
|
Set<String> set = appends.stream().map(vo -> vo.getName() + "_" + vo.getPhone()).collect(Collectors.toSet());
|
|
|
|
|
if (set.size() != appends.size()){
|
|
|
|
|
throw new MyException("联系人重复");
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-04 15:05:47 +08:00
|
|
|
List<AdcdTree> tree = adinfoService.tree(TREE_ALL, TREE_ALL);
|
2024-06-04 14:18:15 +08:00
|
|
|
|
2024-06-04 17:56:05 +08:00
|
|
|
List<AddressBook> abs = Lists.newArrayList();
|
|
|
|
|
|
|
|
|
|
appends.forEach(vo -> {
|
|
|
|
|
String phone = vo.getPhone();
|
|
|
|
|
String name = vo.getName();
|
|
|
|
|
String position = vo.getPosition();
|
|
|
|
|
String city = vo.getCity();
|
|
|
|
|
String county = vo.getCounty();
|
|
|
|
|
AddressBook e = new AddressBook();
|
|
|
|
|
e.setName(name)
|
|
|
|
|
.setPhone(phone)
|
|
|
|
|
.setAdcd(getAdcd(tree, city, county))
|
|
|
|
|
.setPosition(position);
|
|
|
|
|
abs.add(e);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 原数据删除
|
|
|
|
|
removeAdcd();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!service.saveBatch(abs)) {
|
|
|
|
|
throw new MyException("表格数据新增失败");
|
|
|
|
|
}
|
|
|
|
|
List<User> users = Lists.newArrayList();
|
|
|
|
|
List<AbUdR> abUdRs = Lists.newArrayList();
|
|
|
|
|
|
|
|
|
|
AtomicReference<Integer> sort = new AtomicReference<>(0);
|
|
|
|
|
// 新增关联数据
|
|
|
|
|
abs.forEach(a -> {
|
|
|
|
|
String phone = a.getPhone();
|
|
|
|
|
if (StringUtils.isNotBlank(phone)){
|
|
|
|
|
User user = new User();
|
|
|
|
|
String salt = UUID.randomUUID().toString().replaceAll("-", "");
|
|
|
|
|
user
|
|
|
|
|
.setUsername(phone)
|
|
|
|
|
.setAbId(a.getId())
|
|
|
|
|
.setRole("1")
|
|
|
|
|
.setSalt(salt)
|
|
|
|
|
.setPassword(DigestUtils.md5DigestAsHex((salt + "Fxkh@123456").getBytes()));
|
|
|
|
|
users.add(user);
|
|
|
|
|
}
|
2024-06-04 14:18:15 +08:00
|
|
|
|
2024-06-04 17:56:05 +08:00
|
|
|
AbUdR au = new AbUdR();
|
|
|
|
|
Integer i = sort.get() + 1;
|
|
|
|
|
au.setType("1")
|
|
|
|
|
.setAdId(a.getId())
|
|
|
|
|
.setDictId(a.getAdcd().replaceFirst("000000", ""))
|
|
|
|
|
.setSort(i);
|
|
|
|
|
abUdRs.add(au);
|
|
|
|
|
sort.set(i);
|
2024-06-04 14:18:15 +08:00
|
|
|
});
|
2024-06-04 17:56:05 +08:00
|
|
|
|
|
|
|
|
if (!userService.saveBatch(users)) {
|
|
|
|
|
throw new MyException("用户数据新增失败");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!abUdRService.saveBatch(abUdRs)) {
|
|
|
|
|
throw new MyException("关联数据新增失败");
|
|
|
|
|
}
|
|
|
|
|
return ResultJson.ok("数据新增成功");
|
2024-06-04 14:18:15 +08:00
|
|
|
}
|
|
|
|
|
|
2024-06-04 17:56:05 +08:00
|
|
|
private String getAdcd(List<AdcdTree> tree, String city, String county) {
|
|
|
|
|
for (AdcdTree a : tree) {
|
|
|
|
|
if (a.getAdnm().equals(city)) {
|
|
|
|
|
List<AdcdTree> children = a.getChildren();
|
|
|
|
|
if (a.getAdnm().equals(county)) {
|
|
|
|
|
county = "市本级";
|
|
|
|
|
}
|
|
|
|
|
for (AdcdTree b : children) {
|
|
|
|
|
if (b.getAdnm().equals(county)) {
|
|
|
|
|
return b.getAdcd();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
throw new MyException("当前市行政区划匹配失败");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void removeAdcd() {
|
|
|
|
|
List<AddressBook> addressBooks = service.lambdaQuery().likeLeft(AddressBook::getAdcd, "000000000")
|
|
|
|
|
.list();
|
|
|
|
|
boolean r1 = service.removeBatchByIds(addressBooks);
|
|
|
|
|
if (!r1) {
|
|
|
|
|
throw new MyException("通讯录数据删除失败");
|
|
|
|
|
}
|
|
|
|
|
List<Integer> abIds = addressBooks.stream().map(AddressBook::getId).collect(Collectors.toList());
|
|
|
|
|
LambdaQueryWrapper<AbUdR> aurQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
aurQueryWrapper.in(AbUdR::getAdId, abIds);
|
|
|
|
|
boolean remove1 = abUdRService.remove(aurQueryWrapper);
|
|
|
|
|
if (!remove1) {
|
|
|
|
|
throw new MyException("关联数据删除失败");
|
|
|
|
|
}
|
|
|
|
|
LambdaQueryWrapper<User> userQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
userQueryWrapper.in(User::getAbId, abIds);
|
|
|
|
|
boolean remove2 = userService.remove(userQueryWrapper);
|
|
|
|
|
if (!remove2) {
|
|
|
|
|
throw new MyException("用户账号删除失败");
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-13 10:07:53 +08:00
|
|
|
}
|