|
@@ -22,15 +22,17 @@ import com.metro.utils.MD5UtilNew;
|
|
|
import com.metro.utils.MapperManager;
|
|
|
import com.metro.utils.StringUtil;
|
|
|
import io.github.classgraph.utils.Join;
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.assertj.core.util.Lists;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.time.LocalDateTime;
|
|
|
-import java.util.Arrays;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Set;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import static com.metro.service.impl.AccountServiceImpl.getUpdateAccountResp;
|
|
@@ -55,25 +57,31 @@ public class PoliceServiceImpl extends BaseService implements PoliceService {
|
|
|
|
|
|
@Override
|
|
|
public IPage<SelectPolicePageResp> page(SelectPolicePageReq req) {
|
|
|
- IPage<SelectPolicePageResp> respPage = new Page<>(req.getPageNum(), req.getPageSize());
|
|
|
- IPage<Police> selectPage = mapper.selectPage(new Page<>(req.getPageNum(), req.getPageSize()), pageWrapper(req));
|
|
|
- if (org.springframework.util.CollectionUtils.isEmpty(selectPage.getRecords())) return respPage;
|
|
|
- Set<String> deptSet = selectPage.getRecords().stream().map(Police::getCompanyId).collect(Collectors.toSet());
|
|
|
- Map<String, String> companysMap = companysMapper.selectList(new LambdaQueryWrapper<Company>().in(Company::getCompanyId, deptSet)).stream().collect(Collectors.toMap(Company::getCompanyId, Company::getCompanyName, (t1, t2) -> t1));
|
|
|
- return selectPage.convert(p -> MapperManager.mapper(p, SelectPolicePageResp.class, t -> t.setCompanyName(companysMap.get(p.getCompanyId()))));
|
|
|
+ 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())));
|
|
|
+ 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());
|
|
|
+ }
|
|
|
+ }));
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
* 查询条件
|
|
|
* */
|
|
|
- private LambdaQueryWrapper<Police> pageWrapper(SelectPolicePageReq req) {
|
|
|
- LambdaQueryWrapper<Police> wrapper = new LambdaQueryWrapper<>();
|
|
|
- wrapper.like(StringUtils.isNotEmpty(req.getUserName()), Police::getUserName, req.getUserName());
|
|
|
- wrapper.eq(StringUtils.isNotEmpty(req.getPhone()), Police::getPhone, req.getPhone());
|
|
|
- wrapper.eq(Police::getIsDelete, UserConstant.NOT_DELETE);
|
|
|
- wrapper.like(StringUtils.isNotEmpty(req.getAddress()), Police::getAddress, req.getAddress());
|
|
|
- wrapper.eq(StringUtils.isNotEmpty(req.getCompanyId()), Police::getCompanyId, req.getCompanyId());
|
|
|
- wrapper.gt(Police::getType,getAccountInfo().getType());
|
|
|
+ private LambdaQueryWrapper<Company> pageWrapper(SelectPolicePageReq req) {
|
|
|
+ LambdaQueryWrapper<Company> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(Company::getCompanyId, getAccountInfo().getCompanyId());
|
|
|
+ wrapper.like(Company::getBranchName, req.getCompanyId());
|
|
|
return wrapper;
|
|
|
}
|
|
|
|
|
@@ -81,10 +89,19 @@ public class PoliceServiceImpl extends BaseService implements PoliceService {
|
|
|
* 新增
|
|
|
* */
|
|
|
@Override
|
|
|
+ @Transactional
|
|
|
public InsertPoliceResp add(InsertPoliceReq 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.isNotEmpty(account)) throw new BusinessException(account.getAccount() + "已经存在!不能注册");
|
|
|
- return new InsertPoliceResp().setCount(mapper.insert(MapperManager.mapper(req, Police.class, p -> p.setPassword(MD5UtilNew.string2MD5(req.getPassword())).setType(getAccountInfo().getType() + 1))));
|
|
|
+ int insert = mapper.insert(MapperManager.mapper(req, Police.class, p -> p.setPassword(MD5UtilNew.string2MD5(req.getPassword())).setType(getAccountInfo().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()));
|
|
|
+ if (insert1 == BigDecimal.ZERO.intValue()) throw new BusinessException("创建派出所失败!");
|
|
|
+ return new InsertPoliceResp().setCount(insert + insert1);
|
|
|
}
|
|
|
|
|
|
/*
|
|
@@ -92,25 +109,69 @@ public class PoliceServiceImpl extends BaseService implements PoliceService {
|
|
|
* */
|
|
|
@Override
|
|
|
public DetailPoliceResp detail(DetailPoliceReq req) {
|
|
|
- Police Police = mapper.selectById(req.getId());
|
|
|
- return MapperManager.mapper(Police, DetailPoliceResp.class);
|
|
|
+ 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::getId, selectOne.getId()).eq(Police::getIsDelete, UserConstant.NOT_DELETE)).stream().findFirst().orElse(null);
|
|
|
+ return MapperManager.mapper(police, DetailPoliceResp.class, p -> p.setBranchName(selectOne.getBranchName()));
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
* 修改账号
|
|
|
* */
|
|
|
@Override
|
|
|
- public UpdateAccountResp update(UpdateAccountReq req) {
|
|
|
- return getUpdateAccountResp(req, accountsMapper);
|
|
|
+ @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(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));
|
|
|
+ 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()));
|
|
|
+ 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);
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
* 删除账号
|
|
|
* */
|
|
|
@Override
|
|
|
+ @Transactional
|
|
|
public DeleteAccountResp delete(DeleteAccountReq req) {
|
|
|
- return new DeleteAccountResp().setCount(accountsMapper.updateById(new Account().setId(req.getId())
|
|
|
- .setIsDelete(UserConstant.DELETE).setUpdateTime(LocalDateTime.now())));
|
|
|
+ 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()));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 派出所下拉查询(分局、派出所)
|
|
|
+ *
|
|
|
+ * @param req
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<SelectPoliceLevelResp> selectLevel(SelectPoliceLevelReq req) {
|
|
|
+ List<Company> companies = companysMapper.selectList(new LambdaQueryWrapper<Company>().eq(StringUtils.isNotEmpty(req.getCompanyId()), Company::getCompanyId, req.getCompanyId()));
|
|
|
+ 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 -> {
|
|
|
+ List<Company> selectList = companysMapper.selectList(new LambdaQueryWrapper<Company>().eq(Company::getCompanyId, p.getCompanyId())
|
|
|
+ .eq(StringUtils.isNotEmpty(req.getBranchId()), Company::getBranchId, req.getBranchId()));
|
|
|
+ if (!CollectionUtils.isEmpty(selectList)) {
|
|
|
+ q.setBranchList(selectList.stream().map(
|
|
|
+ t -> MapperManager.mapper(t, SelectPoliceLevelResp.BranchList.class)
|
|
|
+ ).collect(Collectors.toList()));
|
|
|
+ }
|
|
|
+ })).collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
}
|