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-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-16 18:03:06 +08:00
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
2024-05-13 10:07:53 +08:00
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
2024-05-28 10:41:40 +08:00
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
import java.time.LocalDateTime;
|
2024-05-29 15:13:59 +08:00
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Objects;
|
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-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-05-24 14:02:15 +08:00
|
|
|
public static final String ADDRESS_BOOK_REDIS_KEY = REDIS_KEY + "addressbook:";
|
|
|
|
|
|
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-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:
|
|
|
|
|
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-30 09:14:30 +08:00
|
|
|
versionsService.saveInfo(model, VersionsType.ADD,model.getAdcd());
|
2024-05-16 14:04:53 +08:00
|
|
|
model.setId(null);
|
2024-05-13 10:07:53 +08:00
|
|
|
|
2024-05-13 14:55:42 +08:00
|
|
|
boolean save = service.save(model);
|
|
|
|
|
|
2024-05-24 14:02:15 +08:00
|
|
|
if (save) {
|
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-24 14:02:15 +08:00
|
|
|
if (StringUtils.isNotBlank(model.getAdcd())) {
|
|
|
|
|
abUdRService.save(new AbUdR(model.getId(), Integer.valueOf(model.getAdcd().replaceFirst("000000", "")), model.getSort(), model.getType()));
|
|
|
|
|
} else {
|
|
|
|
|
// 添加关联关系`
|
|
|
|
|
abUdRService.save(new AbUdR(model.getId(), Integer.valueOf(model.getOrganization()), model.getSort(), model.getType()));
|
|
|
|
|
}
|
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:
|
|
|
|
|
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();
|
|
|
|
|
if (StringUtils.isBlank(adcd)){
|
|
|
|
|
adcd = byId.getAdcd();
|
|
|
|
|
}
|
2024-05-30 11:15:49 +08:00
|
|
|
model.setRole(user.getRole());
|
2024-05-30 09:14:30 +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-24 14:02:15 +08:00
|
|
|
String organization = model.getOrganization();
|
|
|
|
|
if (StringUtils.isNotBlank(model.getAdcd())) {
|
|
|
|
|
organization = model.getAdcd().replaceFirst("000000", "");
|
|
|
|
|
}
|
|
|
|
|
boolean update = abUdRService.lambdaUpdate()
|
|
|
|
|
.set(AbUdR::getSort, model.getSort())
|
|
|
|
|
.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: {
|
|
|
|
|
if (Integer.parseInt(model.getRole()) > Integer.parseInt(user.getRole())){
|
|
|
|
|
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());
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@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-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:
|
|
|
|
|
return ResultJson.error("权限不足");
|
|
|
|
|
case R099:
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return ResultJson.error("权限不足!!");
|
2024-05-13 14:55:42 +08:00
|
|
|
}
|
|
|
|
|
|
2024-05-13 10:07:53 +08:00
|
|
|
AddressBook model = service.getById(id);
|
|
|
|
|
if (Objects.isNull(model)) {
|
|
|
|
|
|
|
|
|
|
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.DEL.getName()));
|
2024-05-30 09:14:30 +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")
|
|
|
|
|
@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-05-28 13:05:31 +08:00
|
|
|
List<AdcdTree> tree = adinfoService.tree(null, null);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<AddressBook> addressBooks = service.lambdaQuery().isNotNull(AddressBook::getAdcd)
|
|
|
|
|
.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-05-28 10:41:40 +08:00
|
|
|
String adcd = t.getAdcd();
|
|
|
|
|
String cityAdnm = t.getAdnm();
|
|
|
|
|
List<AddressBook> books = abMap.get(adcd);
|
2024-05-28 13:05:31 +08:00
|
|
|
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-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-05-13 10:07:53 +08:00
|
|
|
}
|