|
@@ -59,18 +59,25 @@ public class PoliceServiceImpl extends BaseService implements PoliceService {
|
|
|
public IPage<SelectPolicePageResp> page(SelectPolicePageReq req) {
|
|
|
Page<Company> companyPage = companysMapper.selectPage(new Page<>(req.getPageNum(), req.getPageSize()), pageWrapper(req));
|
|
|
if (CollectionUtils.isEmpty(companyPage.getRecords())) return new Page<>();
|
|
|
+
|
|
|
List<Account> accounts = accountsMapper.selectList(new LambdaQueryWrapper<Account>()
|
|
|
.like(StringUtils.isNotEmpty(req.getAddress()), Account::getAddress, req.getAddress())
|
|
|
.like(StringUtils.isNotEmpty(req.getUserName()), Account::getUserName, req.getUserName())
|
|
|
.like(StringUtils.isNotEmpty(req.getPhone()), Account::getPhone, req.getPhone())
|
|
|
- .in(Account::getCompanyId, companyPage.getRecords().stream().map(Company::getCompanyId).collect(Collectors.toSet())));
|
|
|
+ .in(Account::getCompanyId,
|
|
|
+ companysMapper.selectList(new LambdaQueryWrapper<Company>()
|
|
|
+ .in(Company::getCompanyId, companyPage.getRecords().stream().map(Company::getCompanyId).collect(Collectors.toSet())))
|
|
|
+ .stream().map(Company::getId).collect(Collectors.toSet())
|
|
|
+ ));
|
|
|
if (CollectionUtils.isEmpty(accounts)) return new Page<>();
|
|
|
Map<String, Account> collect = accounts.stream().collect(Collectors.toMap(Account::getCompanyId, p -> p, (t1, t2) -> t1));
|
|
|
return companyPage.convert(p -> MapperManager.mapper(p, SelectPolicePageResp.class, q -> {
|
|
|
q.setCompanyName(p.getBranchName()).setId(p.getId());
|
|
|
if (!CollectionUtils.isEmpty(collect)) {
|
|
|
- Account account = collect.get(p.getId()+"");
|
|
|
- q.setCreateTime(account.getCreateTime()).setAddress(account.getAddress()).setPhone(account.getPhone()).setUserName(account.getUserName());
|
|
|
+ Account account = collect.get(p.getId() + "");
|
|
|
+ if (ObjectUtil.isNotEmpty(account)) {
|
|
|
+ q.setCreateTime(account.getCreateTime()).setAddress(account.getAddress()).setPhone(account.getPhone()).setUserName(account.getUserName());
|
|
|
+ }
|
|
|
}
|
|
|
}));
|
|
|
}
|
|
@@ -81,7 +88,7 @@ public class PoliceServiceImpl extends BaseService implements PoliceService {
|
|
|
private LambdaQueryWrapper<Company> pageWrapper(SelectPolicePageReq req) {
|
|
|
LambdaQueryWrapper<Company> wrapper = new LambdaQueryWrapper<>();
|
|
|
wrapper.eq(Company::getCompanyId, getAccountInfo().getCompanyId());
|
|
|
- wrapper.like(Company::getBranchName, req.getCompanyId());
|
|
|
+ wrapper.like(StringUtils.isNotEmpty(req.getCompanyName()), Company::getBranchName, req.getCompanyName());
|
|
|
return wrapper;
|
|
|
}
|
|
|
|
|
@@ -91,16 +98,17 @@ public class PoliceServiceImpl extends BaseService implements PoliceService {
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public InsertPoliceResp add(InsertPoliceReq req) {
|
|
|
- if(getAccountInfo().getType() != 2) throw new BusinessException("非分局管理员不能注册");
|
|
|
+ if (getAccountInfo().getType() != 2) throw new BusinessException("非分局管理员不能注册");
|
|
|
Police account = mapper.selectOne(new LambdaQueryWrapper<Police>().eq(Police::getAccount, req.getAccount()).eq(Police::getIsDelete, UserConstant.NOT_DELETE));
|
|
|
if (ObjectUtil.isNotEmpty(account)) throw new BusinessException(account.getAccount() + "已经存在!不能注册");
|
|
|
- int insert = mapper.insert(MapperManager.mapper(req, Police.class, p -> p.setPassword(MD5UtilNew.string2MD5(req.getPassword())).setType(getAccountInfo().setAreaId(getAccountInfo().getAreaId()).getType() + 1)));
|
|
|
- if (insert == BigDecimal.ZERO.intValue()) throw new BusinessException("创建派出所管理员账号异常!");
|
|
|
List<Company> companies = companysMapper.selectList(new LambdaQueryWrapper<Company>().eq(Company::getCompanyId, getAccountInfo().getCompanyId()).eq(Company::getBranchName, req.getBranchName()));
|
|
|
if (!CollectionUtils.isEmpty(companies)) throw new BusinessException("派出所已经存在,请重新填写派所名");
|
|
|
Company company = companysMapper.selectList(new LambdaQueryWrapper<Company>().eq(Company::getCompanyId, getAccountInfo().getCompanyId()).orderByDesc(Company::getBranchId)).stream().findFirst().orElse(null);
|
|
|
- int insert1 = companysMapper.insert(company.setCompanyId(Integer.valueOf(company.getBranchId()) + 1 + "").setBranchName(req.getBranchName()));
|
|
|
+ int insert1 = companysMapper.insert(company.setBranchId(String.valueOf(Integer.valueOf(company.getBranchId()) + 1)).setCompanyId(getAccountInfo().getCompanyId()).setBranchName(req.getBranchName()));
|
|
|
if (insert1 == BigDecimal.ZERO.intValue()) throw new BusinessException("创建派出所失败!");
|
|
|
+ int insert = mapper.insert(MapperManager.mapper(req, Police.class, p -> p.setPassword(MD5UtilNew.string2MD5(req.getPassword()))
|
|
|
+ .setCreateTime(LocalDateTime.now()).setCompanyId(company.getId() + "").setType(getAccountInfo().setAreaId(getAccountInfo().getAreaId()).getType() + 1)));
|
|
|
+ if (insert == BigDecimal.ZERO.intValue()) throw new BusinessException("创建派出所管理员账号异常!");
|
|
|
return new InsertPoliceResp().setCount(insert + insert1);
|
|
|
}
|
|
|
|
|
@@ -109,9 +117,9 @@ public class PoliceServiceImpl extends BaseService implements PoliceService {
|
|
|
* */
|
|
|
@Override
|
|
|
public DetailPoliceResp detail(DetailPoliceReq req) {
|
|
|
- if(getAccountInfo().getType() != 2) throw new BusinessException("非分局管理员不能修改!");
|
|
|
+ if (getAccountInfo().getType() != 2) throw new BusinessException("非分局管理员不能修改!");
|
|
|
Company selectOne = companysMapper.selectOne(new LambdaQueryWrapper<Company>().eq(Company::getId, req.getId()));
|
|
|
- if(ObjectUtils.isEmpty(selectOne)) throw new BusinessException("未获取到派出所信息");
|
|
|
+ if (ObjectUtils.isEmpty(selectOne)) throw new BusinessException("未获取到派出所信息");
|
|
|
Police police = mapper.selectList(new LambdaQueryWrapper<Police>().eq(Police::getId, selectOne.getId()).eq(Police::getIsDelete, UserConstant.NOT_DELETE)).stream().findFirst().orElse(null);
|
|
|
return MapperManager.mapper(police, DetailPoliceResp.class, p -> p.setBranchName(selectOne.getBranchName()));
|
|
|
}
|
|
@@ -122,17 +130,17 @@ public class PoliceServiceImpl extends BaseService implements PoliceService {
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public UpdatePoliceResp update(UpdatePoliceReq req) {
|
|
|
- if(getAccountInfo().getType() != 2) throw new BusinessException("非分局管理员不能修改!");
|
|
|
+ if (getAccountInfo().getType() != 2) throw new BusinessException("非分局管理员不能修改!");
|
|
|
Police account = mapper.selectOne(new LambdaQueryWrapper<Police>().eq(Police::getAccount, req.getAccount()).eq(Police::getIsDelete, UserConstant.NOT_DELETE));
|
|
|
if (ObjectUtil.isEmpty(account)) throw new BusinessException(account.getAccount() + "不存在!不能修改");
|
|
|
- int insert = mapper.update(MapperManager.mapper(req, Police.class, p -> p.setPassword(MD5UtilNew.string2MD5(req.getPassword())).setUpdateTime(LocalDateTime.now())),new LambdaQueryWrapper<Police>().eq(Police::getAccount,account.getAccount())
|
|
|
- .eq(Police::getIsDelete,UserConstant.NOT_DELETE));
|
|
|
+ int insert = mapper.update(MapperManager.mapper(req, Police.class, p -> p.setPassword(MD5UtilNew.string2MD5(req.getPassword())).setUpdateTime(LocalDateTime.now())), new LambdaQueryWrapper<Police>().eq(Police::getAccount, account.getAccount())
|
|
|
+ .eq(Police::getIsDelete, UserConstant.NOT_DELETE));
|
|
|
if (insert == BigDecimal.ZERO.intValue()) throw new BusinessException("修改派出所管理员账号异常!");
|
|
|
- Company selectOne = companysMapper.selectOne(new LambdaQueryWrapper<Company>().eq(Company::getId, req.getId()).ne(Company::getBranchName,req.getBranchName()));
|
|
|
+ Company selectOne = companysMapper.selectOne(new LambdaQueryWrapper<Company>().eq(Company::getId, req.getId()).ne(Company::getBranchName, req.getBranchName()));
|
|
|
if (ObjectUtils.isEmpty(selectOne)) throw new BusinessException("派出所已经存在,请重新填写派所名");
|
|
|
int insert1 = companysMapper.updateById(new Company().setBranchName(req.getBranchName()).setId(req.getId()));
|
|
|
if (insert1 == BigDecimal.ZERO.intValue()) throw new BusinessException("修改派出所失败!");
|
|
|
- return new UpdatePoliceResp().setCount(insert+insert1);
|
|
|
+ return new UpdatePoliceResp().setCount(insert + insert1);
|
|
|
}
|
|
|
|
|
|
/*
|
|
@@ -141,11 +149,11 @@ public class PoliceServiceImpl extends BaseService implements PoliceService {
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public DeleteAccountResp delete(DeleteAccountReq req) {
|
|
|
- if(getAccountInfo().getType() != 2) throw new BusinessException("非分局管理员不能删除!");
|
|
|
+ if (getAccountInfo().getType() != 2) throw new BusinessException("非分局管理员不能删除!");
|
|
|
Company selectOne = companysMapper.selectOne(new LambdaQueryWrapper<Company>().eq(Company::getId, req.getId()));
|
|
|
- if(ObjectUtils.isEmpty(selectOne)) throw new BusinessException("未获取到派出所信息");
|
|
|
+ if (ObjectUtils.isEmpty(selectOne)) throw new BusinessException("未获取到派出所信息");
|
|
|
List<Police> police = mapper.selectList(new LambdaQueryWrapper<Police>().eq(Police::getId, selectOne.getId()).eq(Police::getIsDelete, UserConstant.NOT_DELETE));
|
|
|
- if(CollectionUtils.isEmpty(police)) throw new BusinessException("派出所下有用户,不能删除");
|
|
|
+ if (CollectionUtils.isEmpty(police)) throw new BusinessException("派出所下有用户,不能删除");
|
|
|
return new DeleteAccountResp().setCount(companysMapper.deleteById(req.getId()));
|
|
|
}
|
|
|
|
|
@@ -161,14 +169,14 @@ public class PoliceServiceImpl extends BaseService implements PoliceService {
|
|
|
if (CollectionUtils.isEmpty(companies)) return Lists.newArrayList();
|
|
|
ArrayList<Company> companyList = companies.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(Company::getCompanyId))), ArrayList::new));
|
|
|
if (!req.getIsQueryBranch()) {
|
|
|
- return companyList.stream().map(p -> MapperManager.mapper(p, SelectPoliceLevelResp.class)).collect(Collectors.toList());
|
|
|
+ return companyList.stream().map(p -> MapperManager.mapper(p, SelectPoliceLevelResp.class, q -> q.setId(p.getCompanyId()).setName(p.getCompanyName()))).collect(Collectors.toList());
|
|
|
}
|
|
|
return companyList.stream().map(p -> MapperManager.mapper(p, SelectPoliceLevelResp.class, q -> {
|
|
|
List<Company> selectList = companysMapper.selectList(new LambdaQueryWrapper<Company>().eq(Company::getCompanyId, p.getCompanyId())
|
|
|
.eq(StringUtils.isNotEmpty(req.getBranchId()), Company::getId, req.getBranchId()));
|
|
|
if (!CollectionUtils.isEmpty(selectList)) {
|
|
|
- q.setBranchList(selectList.stream().map(
|
|
|
- t -> MapperManager.mapper(t, SelectPoliceLevelResp.BranchList.class)
|
|
|
+ q.setId(p.getCompanyId()).setName(p.getCompanyName()).setBranchList(selectList.stream().map(
|
|
|
+ t -> MapperManager.mapper(t, SelectPoliceLevelResp.BranchList.class, m -> m.setId(t.getBranchId()).setName(t.getBranchName()))
|
|
|
).collect(Collectors.toList()));
|
|
|
}
|
|
|
})).collect(Collectors.toList());
|