|
@@ -1,6 +1,7 @@
|
|
|
package com.metro.service.impl;
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.alibaba.excel.util.CollectionUtils;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
@@ -12,13 +13,15 @@ import com.metro.entity.ro.account.*;
|
|
|
import com.metro.exception.BusinessException;
|
|
|
import com.metro.mapper.AccountsMapper;
|
|
|
import com.metro.mapper.AreaMapper;
|
|
|
+import com.metro.security.JWTUtils;
|
|
|
import com.metro.service.AccountService;
|
|
|
import com.metro.utils.*;
|
|
|
import io.github.classgraph.utils.Join;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.commons.lang3.time.DateUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.util.CollectionUtils;
|
|
|
+import org.springframework.util.DigestUtils;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.servlet.ServletOutputStream;
|
|
@@ -28,14 +31,8 @@ import java.io.FileInputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.time.LocalDateTime;
|
|
|
-import java.time.LocalTime;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Set;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
-import java.util.stream.IntStream;
|
|
|
-import java.util.stream.Stream;
|
|
|
|
|
|
/**
|
|
|
* @ClassName: AccountServiceImpl
|
|
@@ -66,10 +63,10 @@ public class AccountServiceImpl implements AccountService {
|
|
|
if (CollectionUtils.isEmpty(selectPage.getRecords())) return respPage;
|
|
|
Set<Integer> areaIdSet = selectPage.getRecords().stream().map(Account::getAreaId).collect(Collectors.toSet());
|
|
|
Map<Integer, String> areaMap = areaMapper.selectList(new LambdaQueryWrapper<Area>().in(Area::getId, areaIdSet)).stream().collect(Collectors.toMap(Area::getId, p ->
|
|
|
- Join.join("-", areaMapper.selectList(new LambdaQueryWrapper<Area>().eq(Area::getId, StringUtils.split(p.getDistrictSqe(), "."))).stream().map(Area::getName).collect(Collectors.toList()))
|
|
|
+ Join.join("-", areaMapper.selectList(new LambdaQueryWrapper<Area>().in(Area::getId, StringUtils.split(p.getDistrictSqe(), ","))).stream().map(Area::getName).collect(Collectors.toList()))
|
|
|
));
|
|
|
Map<Integer, String> areaSqeMap = areaMapper.selectList(new LambdaQueryWrapper<Area>().in(Area::getId, areaIdSet)).stream().collect(Collectors.toMap(Area::getId, Area::getDistrictSqe, (t1, t2) -> t1));
|
|
|
- return selectPage.convert(p -> MapperManager.mapper(p, SelectAccountPageResp.class, q -> q.setAreaSqe(areaSqeMap.get(p.getAreaId())).setAreaDesc(areaMap.get(p.getAreaId()))));
|
|
|
+ return selectPage.convert(p -> MapperManager.mapper(p, SelectAccountPageResp.class, q -> q.setAreaDesc(areaMap.get(p.getAreaId()))));
|
|
|
}
|
|
|
|
|
|
// page wrapper 查询条件
|
|
@@ -78,11 +75,12 @@ public class AccountServiceImpl implements AccountService {
|
|
|
wrapper.like(StringUtils.isNotEmpty(req.getUserName()), Account::getUserName, req.getUserName());
|
|
|
wrapper.eq(StringUtils.isNotEmpty(req.getPhone()), Account::getPhone, req.getPhone());
|
|
|
wrapper.eq(Account::getIsDelete, UserConstant.NOT_DELETE);
|
|
|
+ wrapper.ge(Account::getType, req.getType());
|
|
|
return wrapper;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 注册账号
|
|
|
+ * 添加账号
|
|
|
*
|
|
|
* @param req 账号信息
|
|
|
* @return 影响行数
|
|
@@ -127,10 +125,32 @@ public class AccountServiceImpl implements AccountService {
|
|
|
* @return 账号详情
|
|
|
*/
|
|
|
@Override
|
|
|
- public DetailAccountResp detail(DeleteAccountReq req) {
|
|
|
+ public DetailAccountResp detail(DetailAccountReq req) {
|
|
|
Account account = accountsMapper.selectById(req.getId());
|
|
|
Area area = areaMapper.selectById(account.getAreaId());
|
|
|
- return MapperManager.mapper(account, DetailAccountResp.class, p -> p.setAreaSqe(area.getDistrictSqe()));
|
|
|
+ String[] split = area.getDistrictSqe().trim().split(",");
|
|
|
+ String areaId = null;
|
|
|
+ String cityId = null;
|
|
|
+ String proviceId = null;
|
|
|
+ List<String> strings = Arrays.asList(split);
|
|
|
+ // .11.150.1275.
|
|
|
+ for (int i = 0; i < strings.size(); i++) {
|
|
|
+ if (i == 0) {
|
|
|
+ proviceId = strings.get(i);
|
|
|
+ } else if (i == 1) {
|
|
|
+ cityId = strings.get(i);
|
|
|
+ } else if (i == 2) {
|
|
|
+ areaId = strings.get(i);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String finalAreaId = areaId;
|
|
|
+ String finalCityId = cityId;
|
|
|
+ String finalProviceId = proviceId;
|
|
|
+ return MapperManager.mapper(account, DetailAccountResp.class, p -> {
|
|
|
+ p.setAreaId(finalAreaId);
|
|
|
+ p.setCityId(finalCityId);
|
|
|
+ p.setProviceId(finalProviceId);
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -146,7 +166,7 @@ public class AccountServiceImpl implements AccountService {
|
|
|
Account account = accountsMapper.selectOne(new LambdaQueryWrapper<Account>().eq(Account::getAccount, req.getAccount()).eq(Account::getIsDelete, UserConstant.NOT_DELETE));
|
|
|
if (ObjectUtil.isEmpty(account)) throw new BusinessException(account.getAccount() + "不存在!不能修改");
|
|
|
return new UpdateAccountResp().setCount(accountsMapper.updateById(MapperManager.mapper(req, Account.class, p -> p.setPassword(MD5UtilNew.string2MD5(req.getPassword()))
|
|
|
- .setUpdateTime(LocalDateTime.now()).setType(1))));
|
|
|
+ .setUpdateTime(LocalDateTime.now()).setType(1).setUpdateId(req.getUpdateId()))));
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -157,7 +177,9 @@ public class AccountServiceImpl implements AccountService {
|
|
|
*/
|
|
|
@Override
|
|
|
public BaseResponse<String> uploadPhoto(MultipartFile file) {
|
|
|
+
|
|
|
return FileUtils.uploadPhoto(file);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -174,7 +196,14 @@ public class AccountServiceImpl implements AccountService {
|
|
|
if (!fileBase.exists()) throw new BusinessException("文件不存在");
|
|
|
ServletOutputStream outputStream = response.getOutputStream();
|
|
|
FileInputStream inputStream = new FileInputStream(fileBase);
|
|
|
- inputStream.transferTo(outputStream);
|
|
|
+ //读取写出
|
|
|
+ int len = 0;
|
|
|
+ byte[] buffer = new byte[1024];
|
|
|
+ while ((len = inputStream.read(buffer)) != -1) {
|
|
|
+ outputStream.write(buffer, 0, len);
|
|
|
+ outputStream.flush();
|
|
|
+ }
|
|
|
+
|
|
|
outputStream.close();
|
|
|
inputStream.close();
|
|
|
} catch (IOException e) {
|
|
@@ -200,4 +229,43 @@ public class AccountServiceImpl implements AccountService {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 登录
|
|
|
+ *
|
|
|
+ * @param req 账号密码
|
|
|
+ * @return 是否成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public LoginAccountResp login(LoginAccountReq req) {
|
|
|
+ Account account = accountsMapper.selectOne(new LambdaQueryWrapper<Account>().eq(Account::getAccount, req.getAccount()).eq(Account::getIsDelete, UserConstant.NOT_DELETE));
|
|
|
+ if (ObjectUtil.isEmpty(account)) throw new BusinessException("账号不存在!请先注册");
|
|
|
+ if (!MD5UtilNew.convertMD5(MD5UtilNew.convertMD5(req.getPassword())).equals(req.getPassword()))
|
|
|
+ throw new BusinessException("密码不对!请重新输入");
|
|
|
+ return MapperManager.mapper(account, LoginAccountResp.class, p -> p.setToken(JWTUtils.sign(account.getId().toString(), account.getPassword(), DateUtils.addDays(new Date(), 1))));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 退出登录
|
|
|
+ *
|
|
|
+ * @return 是否成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean exit(Long userId) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取用户信息
|
|
|
+ *
|
|
|
+ * @return 是否成功
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public LoginAccountResp getUserInfo(Long userId) {
|
|
|
+ Account account = accountsMapper.selectOne(new LambdaQueryWrapper<Account>().eq(Account::getId, userId).eq(Account::getIsDelete, UserConstant.NOT_DELETE));
|
|
|
+ if (ObjectUtil.isEmpty(account)) throw new BusinessException("获取用户信息失败");
|
|
|
+ return MapperManager.mapper(account, LoginAccountResp.class);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
+
|