|
@@ -1,6 +1,7 @@
|
|
|
package com.om.service.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.collection.ListUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
@@ -28,11 +29,9 @@ import org.springframework.util.DigestUtils;
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.time.LocalDateTime;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.function.Predicate;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -251,12 +250,16 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|
|
|
|
|
|
|
|
String deviceSn = user.getDeviceSn();
|
|
|
+
|
|
|
if (StringUtils.isNotBlank(deviceSn)) {
|
|
|
- Device device = new Device();
|
|
|
- device.setDeviceSn(deviceSn);
|
|
|
- device.setUsername(user.getUsername());
|
|
|
- device.setCreateTime(LocalDateTime.now());
|
|
|
- deviceService.save(device);
|
|
|
+ Device device = deviceService.lambdaQuery()
|
|
|
+ .eq(Device::getDeviceSn, deviceSn)
|
|
|
+ .one();
|
|
|
+ if (!BeanUtil.isEmpty(device)) {
|
|
|
+ device.setUsername(user.getUsername());
|
|
|
+ deviceService.updateById(device);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
this.save(addUser);
|
|
|
List<String> vciSns = user.getVciSn();
|
|
@@ -308,15 +311,14 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|
|
}
|
|
|
|
|
|
//查询 设备表
|
|
|
- List<Device> deviceList = deviceService.lambdaQuery()
|
|
|
+ Device device = deviceService.lambdaQuery()
|
|
|
.eq(Device::getUsername, user.getUsername())
|
|
|
- .list();
|
|
|
- if (!deviceList.isEmpty()) {
|
|
|
- //删除设备
|
|
|
- List<Integer> deviceIds = deviceList.stream().map(c -> c.getId()).collect(Collectors.toList());
|
|
|
- deviceService.removeByIds(deviceIds);
|
|
|
- }
|
|
|
+ .one();
|
|
|
|
|
|
+ if (!BeanUtil.isEmpty(device)) {
|
|
|
+ device.setUsername("");
|
|
|
+ deviceService.updateById(device);
|
|
|
+ }
|
|
|
boolean deleteById = this.removeById(id);
|
|
|
if (deleteById == false) {
|
|
|
return Result.error().message("删除失败");
|
|
@@ -456,12 +458,21 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional
|
|
|
public Result updateUserInfo(UserAddVO user) {
|
|
|
Integer userId = user.getId();
|
|
|
|
|
|
User userById = getById(userId);
|
|
|
|
|
|
+ String password = user.getPassword();
|
|
|
BeanUtil.copyProperties(user, userById);
|
|
|
+ try {
|
|
|
+ password = AesUtil.Encrypt(password);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new BizException("密码加密出错", ResultCode.PASSWORD_ENCRYPT_ERROR);
|
|
|
+ }
|
|
|
+ userById.setPassword(password);
|
|
|
+
|
|
|
/* if (!password.equals(userById.getPassword())){
|
|
|
//密码加密
|
|
|
try {
|
|
@@ -475,35 +486,49 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|
|
|
|
|
}*/
|
|
|
|
|
|
+ String deviceSn = user.getDeviceSn();
|
|
|
+ if (deviceSn != null && !deviceSn.isEmpty()) {
|
|
|
+ Device one = deviceService.lambdaQuery()
|
|
|
+ .eq(Device::getDeviceSn, deviceSn)
|
|
|
+ .one();
|
|
|
+ if (BeanUtil.isEmpty(one)) {
|
|
|
+ throw new BadReqException("该平板设备不存在");
|
|
|
+ }
|
|
|
+ one.setUsername(user.getUsername());
|
|
|
+ deviceService.updateById(one);
|
|
|
+ }
|
|
|
|
|
|
Integer distributorId = userById.getDistributorId();
|
|
|
//根据id查询维修厂
|
|
|
- Distributor distributor = distributorService.getById(distributorId);
|
|
|
- if (BeanUtil.isEmpty(distributor)) {
|
|
|
- throw new BadReqException("该维修厂不存在");
|
|
|
+ if (distributorId != null){
|
|
|
+ Distributor distributor = distributorService.getById(distributorId);
|
|
|
+ if (BeanUtil.isEmpty(distributor)) {
|
|
|
+ throw new BadReqException("该维修厂不存在");
|
|
|
+ }
|
|
|
+ userById.setDistributorName(distributor.getCompany());
|
|
|
+
|
|
|
}
|
|
|
- userById.setDistributorName(distributor.getCompany());
|
|
|
|
|
|
List<String> vciSns = user.getVciSn();
|
|
|
|
|
|
- if (!vciSns.isEmpty()) {
|
|
|
+ if (CollectionUtil.isNotEmpty(vciSns)) {
|
|
|
List<UserVci> userVciList = new ArrayList<>();
|
|
|
int i = 1;
|
|
|
for (String vciSn : vciSns) {
|
|
|
UserVci userVci = new UserVci();
|
|
|
//根据vciSn查询
|
|
|
VciInfo vciInfo = vciInfoService.lambdaQuery()
|
|
|
- .eq(VciInfo::getVciNum, user.getVciSn())
|
|
|
+ .eq(VciInfo::getVciNum, vciSn)
|
|
|
.one();
|
|
|
if (vciInfo == null) {
|
|
|
throw new BadReqException("该VCI设备不存在");
|
|
|
}
|
|
|
//先查询uservci
|
|
|
- UserVci one = userVciService.lambdaQuery()
|
|
|
+ List<UserVci> userVciList1 = userVciService.lambdaQuery()
|
|
|
.eq(UserVci::getVciInfoId, vciInfo.getId())
|
|
|
.eq(UserVci::getUserId, userId)
|
|
|
- .one();
|
|
|
- if (BeanUtil.isEmpty(one)) {
|
|
|
+ .list();
|
|
|
+ if (userVciList1.isEmpty()) {
|
|
|
userVci.setVciInfoId(vciInfo.getId());
|
|
|
userVci.setUserId(userId);
|
|
|
if (i==1){
|
|
@@ -736,5 +761,31 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
|
|
|
return Result.ok();
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public Result resetPassword(Integer id) {
|
|
|
+ User user = this.getById(id);
|
|
|
+ if (BeanUtil.isEmpty(user)) {
|
|
|
+ throw new BadReqException("该用户不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ String encrypt = AesUtil.Encrypt("111111");
|
|
|
+ user.setPassword(encrypt);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new BadReqException("密码加密错误");
|
|
|
+ }
|
|
|
+
|
|
|
+ this.updateById(user);
|
|
|
+ return Result.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<User> listByDevice() {
|
|
|
+ List<User> userList = this.lambdaQuery().list();
|
|
|
+ List<User> collect = userList.stream().filter(user -> StringUtils.isBlank(user.getDeviceSn()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ return collect;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|