|
@@ -6,12 +6,10 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.metro.constant.UserConstant;
|
|
|
-import com.metro.entity.po.Account;
|
|
|
-import com.metro.entity.po.Area;
|
|
|
-import com.metro.entity.po.Company;
|
|
|
-import com.metro.entity.po.Police;
|
|
|
+import com.metro.entity.po.*;
|
|
|
import com.metro.entity.ro.Police.*;
|
|
|
import com.metro.entity.ro.account.*;
|
|
|
+import com.metro.entity.ro.passrecords.SelectPassreCordsPageListResp;
|
|
|
import com.metro.exception.BusinessException;
|
|
|
import com.metro.mapper.AccountsMapper;
|
|
|
import com.metro.mapper.CompanysMapper;
|
|
@@ -34,6 +32,7 @@ import java.math.BigDecimal;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
+import java.util.stream.Stream;
|
|
|
|
|
|
import static com.metro.service.impl.AccountServiceImpl.getUpdateAccountResp;
|
|
|
|
|
@@ -54,41 +53,30 @@ public class PoliceServiceImpl extends BaseService implements PoliceService {
|
|
|
private CompanysMapper companysMapper;
|
|
|
@Autowired
|
|
|
private AccountsMapper accountsMapper;
|
|
|
-
|
|
|
+ /*
|
|
|
+ * 派出所列表展示
|
|
|
+ * */
|
|
|
@Override
|
|
|
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<>();
|
|
|
+ IPage<SelectPolicePageResp> respPage = new Page<>(req.getPageNum(), req.getPageSize());
|
|
|
+ Page<Police> selectPage = mapper.selectPage(new Page<>(req.getPageNum(), req.getPageSize()), pageWrapper(req));
|
|
|
+ if (CollectionUtils.isEmpty(selectPage.getRecords())) return respPage;
|
|
|
+ Set<String> getCompanyId = selectPage.getRecords().stream().map(Police::getCompanyId).collect(Collectors.toSet());
|
|
|
+ return selectPage.convert(p -> MapperManager.mapper(p, SelectPolicePageResp.class));
|
|
|
|
|
|
- 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,
|
|
|
- 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() + "");
|
|
|
- if (ObjectUtil.isNotEmpty(account)) {
|
|
|
- q.setCreateTime(account.getCreateTime()).setAccount(account.getAccount()).setAddress(account.getAddress()).setPhone(account.getPhone()).setUserName(account.getUserName());
|
|
|
- }
|
|
|
- }
|
|
|
- }));
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/*
|
|
|
* 查询条件
|
|
|
* */
|
|
|
- private LambdaQueryWrapper<Company> pageWrapper(SelectPolicePageReq req) {
|
|
|
- LambdaQueryWrapper<Company> wrapper = new LambdaQueryWrapper<>();
|
|
|
- wrapper.eq(Company::getCompanyId, getAccountInfo().getCompanyId());
|
|
|
- wrapper.like(StringUtils.isNotEmpty(req.getCompanyName()), Company::getBranchName, req.getCompanyName());
|
|
|
+ private LambdaQueryWrapper<Police> pageWrapper(SelectPolicePageReq req) {
|
|
|
+ LambdaQueryWrapper<Police> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(Police::getIsDelete, UserConstant.NOT_DELETE);
|
|
|
+ wrapper.like(com.metro.utils.StringUtils.isNotEmpty(req.getAddress()), Police::getAddress, req.getAddress());
|
|
|
+ wrapper.like(com.metro.utils.StringUtils.isNotEmpty(req.getUserName()), Police::getUserName, req.getUserName());
|
|
|
+ wrapper.like(com.metro.utils.StringUtils.isNotEmpty(req.getPhone()), Police::getPhone, req.getPhone());
|
|
|
+ wrapper.like(com.metro.utils.StringUtils.isNotEmpty(req.getAccount()),Police::getAccount,req.getAccount());
|
|
|
return wrapper;
|
|
|
}
|
|
|
|
|
@@ -117,33 +105,24 @@ public class PoliceServiceImpl extends BaseService implements PoliceService {
|
|
|
* */
|
|
|
@Override
|
|
|
public DetailPoliceResp detail(DetailPoliceReq req) {
|
|
|
- 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("未获取到派出所信息");
|
|
|
- Police police = mapper.selectList(new LambdaQueryWrapper<Police>().eq(Police::getCompanyId, selectOne.getId()).eq(Police::getIsDelete, UserConstant.NOT_DELETE)).stream().findFirst().orElse(null);
|
|
|
- return MapperManager.mapper(police, DetailPoliceResp.class, p -> p.setId(selectOne.getId()).setBranchName(ObjectUtil.isEmpty(selectOne.getBranchName()) ? null : selectOne.getBranchName()));
|
|
|
+ Police police = mapper.selectById(req.getId());
|
|
|
+ return MapperManager.mapper(police, DetailPoliceResp.class);
|
|
|
}
|
|
|
|
|
|
- /*
|
|
|
+ /**
|
|
|
* 修改账号
|
|
|
- * */
|
|
|
+ *
|
|
|
+ * @param req 主键
|
|
|
+ * @return 影响行数
|
|
|
+ */
|
|
|
@Override
|
|
|
- @Transactional
|
|
|
public UpdatePoliceResp update(UpdatePoliceReq req) {
|
|
|
- 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(req.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));
|
|
|
- if (insert == BigDecimal.ZERO.intValue()) throw new BusinessException("修改派出所管理员账号异常!");
|
|
|
- Company selectOne = companysMapper.selectOne(new LambdaQueryWrapper<Company>().eq(Company::getId, req.getId()));
|
|
|
- if (ObjectUtils.isEmpty(selectOne)) throw new BusinessException("没有该派出所");
|
|
|
- List<Company> companies = companysMapper.selectList(new LambdaQueryWrapper<Company>().eq(Company::getCompanyId, selectOne.getCompanyId()));
|
|
|
- long count = companies.stream().filter(p -> !p.getBranchName().equals(selectOne.getBranchName())).filter(p -> p.getBranchName().equals(req.getBranchName())).count();
|
|
|
- if(count != BigDecimal.ZERO.longValue()) 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);
|
|
|
+ Integer id = req.getId();
|
|
|
+ if (!StringUtil.isChinese(req.getUserName())) throw new BusinessException(UserConstant.NOT_CHINESE_USERNAME);
|
|
|
+ Account account = accountsMapper.selectOne(new LambdaQueryWrapper<Account>().eq(Account::getAccount, req.getAccount()).eq(Account::getIsDelete, UserConstant.NOT_DELETE));
|
|
|
+ return new UpdatePoliceResp().setCount(accountsMapper.updateById(MapperManager.mapper(req, Account.class, p -> p.setPassword(MD5UtilNew.string2MD5(req.getPassword()))
|
|
|
+ .setUpdateTime(LocalDateTime.now()).setUpdateId(id))));
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/*
|
|
@@ -152,14 +131,9 @@ public class PoliceServiceImpl extends BaseService implements PoliceService {
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public DeleteAccountResp delete(DeleteAccountReq req) {
|
|
|
- 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("未获取到派出所信息");
|
|
|
- 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("派出所下有用户,不能删除");
|
|
|
- return new DeleteAccountResp().setCount(companysMapper.deleteById(req.getId()));
|
|
|
+ return new DeleteAccountResp().setCount(accountsMapper.updateById(new Account().setId(req.getId())
|
|
|
+ .setIsDelete(UserConstant.DELETE).setUpdateTime(LocalDateTime.now())));
|
|
|
}
|
|
|
-
|
|
|
/**
|
|
|
* 派出所下拉查询(分局、派出所)
|
|
|
*
|